Commit e199adae authored by Markus Krug's avatar Markus Krug
Browse files

nappiUI can now acces onlie repos and download jars if required

parent 5655cb95
Pipeline #3758 passed with stage
in 2 minutes and 19 seconds
......@@ -5,7 +5,8 @@ Bundle-SymbolicName: de.uniwue.mk.athen.nappi.ui
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
de.uniwue.mkrug.kall.typesystemUtil;bundle-version="1.0.7"
de.uniwue.mkrug.kall.typesystemUtil;bundle-version="1.0.7",
de.uniwue.mk.kall.athen.appDelegation
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Export-Package: de.uniwue.mk.athen.nappi.ui.components
......
......@@ -14,6 +14,10 @@ public interface INappiToolbarListener {
public void connectorModeChanged(boolean inConnectorMode);
public Composite getDrawingArea();
public void accessOnlineRepository();
public void downloadRemoteJars();
}
package de.uniwue.mk.athen.nappi.ui.components;
import java.awt.Polygon;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
......@@ -40,6 +45,7 @@ import de.uniwue.mk.athen.nappi.ui.model.NappiUIAnalysisEngine;
import de.uniwue.mk.athen.nappi.ui.model.NappiUIDocumentReader;
import de.uniwue.mk.athen.nappi.ui.model.NappiUIDocumentWriter;
import de.uniwue.mk.athen.nappi.ui.model.NappiUIPipeline;
import de.uniwue.mk.kall.athen.appDelegation.util.ApplicationUtil;
import de.uniwue.mk.nappi.core.ServiceIntegrationUtil;
import de.uniwue.mk.nappi.core.struct.NappiPipelineConfiguration;
import de.uniwue.mk.nappi.serviceprovider.aeservice.IAnalysisEngineService;
......@@ -368,7 +374,7 @@ public class NappiDrawingComposite extends Canvas implements INappiToolbarListen
// clear the object
analysisEngines = new HashMap<>();
// read local engines
// read local engines and nothing more !!
if (localRepos != null) {
for (String localPath : localRepos) {
......@@ -382,31 +388,12 @@ public class NappiDrawingComposite extends Canvas implements INappiToolbarListen
}
}
// also add online repo entries
if (onlineRepos != null) {
for (String onlinePath : onlineRepos) {
//URLConnection openConnection = new URL(onlinePath).openConnection();
System.out.println(onlinePath);
Map<IAnalysisEngineService, String> enginesInPath = ServiceIntegrationUtil
.getAllAnalysisEnginesRecursively(onlinePath);
// add those that are not yet present
for (IAnalysisEngineService service : enginesInPath.keySet()) {
if (!analysisEngines.containsKey(service))
analysisEngines.put(service, enginesInPath.get(service));
}
}
}
}
}
public void setOnlineRepos(String[] onlineRepos) {
this.onlineRepos = onlineRepos;
updateNappiEngines();
}
......@@ -439,4 +426,105 @@ public class NappiDrawingComposite extends Canvas implements INappiToolbarListen
}
// access all remote jars
@Override
public void accessOnlineRepository() {
// also add online repo entries
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
List<URL> urLsOfRemoteJars = new ArrayList<>();
for (String onlinePath : onlineRepos) {
urLsOfRemoteJars.addAll(ServiceIntegrationUtil.getURLsOfRemoteJars(onlinePath));
}
monitor.beginTask("Acessing online repository...", urLsOfRemoteJars.size());
for (URL url : urLsOfRemoteJars) {
monitor.subTask("Access " + url.toString());
Map<IAnalysisEngineService, String> enginesInURL = ServiceIntegrationUtil
.deriveAnalysisEnginesFromOnlineRepo(url.toString());
for (IAnalysisEngineService service : enginesInURL.keySet()) {
monitor.subTask("Found service: " + service.getCanonicalEngineName());
if (!analysisEngines.containsKey(service)) {
analysisEngines.put(service, enginesInURL.get(service));
}
}
monitor.worked(1);
}
monitor.done();
} catch (IOException e) {
e.printStackTrace();
}
}
};
ProgressMonitorDialog pmDia = new ProgressMonitorDialog(getShell());
try {
pmDia.run(true, false, runnable);
} catch (InvocationTargetException | InterruptedException e) {
MessageDialog.openError(getShell(), "Processing aborted",
"An exception occured during processing:\\n" + e.getMessage());
e.printStackTrace();
}
}
@Override
public void downloadRemoteJars() {
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
List<URL> urLsOfRemoteJars = new ArrayList<>();
for (String onlinePath : onlineRepos) {
urLsOfRemoteJars.addAll(ServiceIntegrationUtil.getURLsOfRemoteJars(onlinePath));
}
monitor.beginTask("Download online repository Jars...", urLsOfRemoteJars.size());
for (URL url : urLsOfRemoteJars) {
monitor.subTask("Download: " + url.toString());
File localNappiRepository = ApplicationUtil.getLocalNappiRepository();
if (localNappiRepository != null) {
String[] split = url.getFile().split("\\/");
String file = split[split.length - 1];
FileUtils.copyURLToFile(url, new File(localNappiRepository.getAbsolutePath() + "/" + file));
}
monitor.worked(1);
}
monitor.done();
} catch (IOException e) {
e.printStackTrace();
}
}
};
ProgressMonitorDialog pmDia = new ProgressMonitorDialog(getShell());
try {
pmDia.run(true, false, runnable);
} catch (InvocationTargetException | InterruptedException e) {
MessageDialog.openError(getShell(), "Processing aborted",
"An exception occured during processing:\\n" + e.getMessage());
e.printStackTrace();
}
}
}
......@@ -63,6 +63,33 @@ public class NappiToolbarComposite extends Composite {
});
});
//add dummys
// ToolItem itemDummy1 = new ToolItem(toolBar, SWT.PUSH);
// itemDummy1.getControl().setVisible(false);
ToolItem itemAccessOnlineReposiroty = new ToolItem(toolBar, SWT.PUSH);
itemAccessOnlineReposiroty.setText("Access online repository");
itemAccessOnlineReposiroty.addListener(SWT.Selection, (Event e) -> {
toolbarListener.stream().forEach((INappiToolbarListener listener) -> {
listener.accessOnlineRepository();
deselectToolbarCheckItems();
});
});
ToolItem itemDownloadRemoteJars = new ToolItem(toolBar, SWT.PUSH);
itemDownloadRemoteJars.setText("Download Remote Jars");
itemDownloadRemoteJars.addListener(SWT.Selection, (Event e) -> {
toolbarListener.stream().forEach((INappiToolbarListener listener) -> {
listener.downloadRemoteJars();
deselectToolbarCheckItems();
});
});
toolBar.pack();
......
package de.uniwue.mk.athen.nappi.ui.components;
import org.apache.uima.resource.metadata.ConfigurationParameter;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TextCellEditor;
public class NappiUIEngineEditingSupport extends EditingSupport {
private TableViewer viewer;
private TextCellEditor editor;
public NappiUIEngineEditingSupport(TableViewer viewer) {
super(viewer);
this.viewer = viewer;
this.editor = new TextCellEditor(viewer.getTable());
}
@Override
protected CellEditor getCellEditor(Object element) {
return editor;
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
if (element instanceof ConfigurationParameter) {
ConfigurationParameter param = (ConfigurationParameter) element;
//TODO ccess the value of param
return param;
}
return null;
}
@Override
protected void setValue(Object element, Object value) {
//TODO fix
// if (element instanceof OWLAnnotation) {
// OWLAnnotation anno = (OWLAnnotation) element;
// String annoType = anno.getProperty().getIRI().getFragment();
// if (anno.getValue() instanceof OWLLiteral && ontology != null && classToEdit != null) {
//
// // delete the anno
// OWLUtil.deleteAnnotationFromOntology(anno, classToEdit, ontology);
//
// // creae a new one
// OWLAnnotation createdAnno = OWLUtil.createAnnotation(annoType, (String) value, ontology);
// OWLUtil.addAnnotationToEntity(createdAnno, classToEdit, ontology);
// viewer.setInput(OWLUtil.getAnnotationsOnEntity(classToEdit, ontology));
//
// }
// }
}
}
......@@ -43,6 +43,7 @@ import de.uniwue.mk.nappi.serviceprovider.aeservice.IAnalysisEngineService;
public class NappiUIEngineParameterDialog extends Dialog {
public static final String ENGINE_METADATA = "ENGINE_METADATA";
private Label labelComponentName;
private Text textComponentName;
private TableViewer viewerParams;
......@@ -131,11 +132,9 @@ public class NappiUIEngineParameterDialog extends Dialog {
if (accordingElement == null)
return;
engineDesc = null;
System.out.println(accordingElement.getCanonicalEngineName());
try {
engineDesc = NappiUtil.createAnalysisEngineDescription(accordingElement.getCanonicalEngineName(), engines, null);
} catch (InvalidXMLException | ResourceInitializationException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
......@@ -143,6 +142,8 @@ public class NappiUIEngineParameterDialog extends Dialog {
ConfigurationParameterDeclarations configurationParameterDeclarations = engineDesc.getAnalysisEngineMetaData().getConfigurationParameterDeclarations();
viewerParams.setInput(configurationParameterDeclarations.getConfigurationParameters());
viewerParams.refresh();
viewerParams.setData(ENGINE_METADATA,engineDesc.getAnalysisEngineMetaData().getConfigurationParameterSettings());
}
}
......@@ -187,6 +188,7 @@ public class NappiUIEngineParameterDialog extends Dialog {
});
TableViewerColumn colDefault = createTableViewerColumn("Paramvalue", 120, 0);
colDefault.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
......
......@@ -9,15 +9,17 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import de.uniwue.mk.kall.athen.appDelegation.util.ApplicationUtil;
public class NappiUIMainDialog extends Dialog {
private NappiToolbarComposite toolbar;
private NappiDrawingComposite drawingComposite;
private String[] localRepos;
private String[] onlineRepos;
public NappiUIMainDialog(Shell parentShell,String[] localRepositories,String[] onlineReposiores) {
public NappiUIMainDialog(Shell parentShell, String[] localRepositories, String[] onlineReposiores) {
super(parentShell);
this.localRepos = localRepositories;
this.onlineRepos = onlineReposiores;
......@@ -40,10 +42,10 @@ public class NappiUIMainDialog extends Dialog {
GridData gdDrawing = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
gdToolbar.horizontalSpan = 4;
drawingComposite.setLayoutData(gdDrawing);
drawingComposite.setLocalRepos(localRepos);
drawingComposite.setLocalRepos(new String[] { ApplicationUtil.getLocalNappiRepository().getAbsolutePath() });
drawingComposite.setOnlineRepos(onlineRepos);
//assure that the drawing composite listens to the toolbar
// assure that the drawing composite listens to the toolbar
toolbar.addToolbarListener(drawingComposite);
return container;
......
......@@ -404,4 +404,16 @@ public class ApplicationUtil {
}
return tempFile;
}
public static File getLocalNappiRepository() {
String wsPref = getFromPreferences(ApplicationPreferences.WORKSPACE, "nope");
if (wsPref.equals("nope"))
return null;
File file = new File(wsPref + "/" + NAPPI_EXTERNAL_REPO_FOLDER);
if (file.exists())
return file;
return null;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment