Added context menu entry to convert ATDB -> AMXMI. Some refactoring.
Change-Id: If267d022ea53252f631d133fcbced31c980094c5
Signed-off-by: Raphael Weber <raphael.weber@vector.com>
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/META-INF/MANIFEST.MF b/plugins/org.eclipse.app4mc.amalthea.import.atdb/META-INF/MANIFEST.MF
index ce86065..49e0175 100644
--- a/plugins/org.eclipse.app4mc.amalthea.import.atdb/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/META-INF/MANIFEST.MF
@@ -1,15 +1,21 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: APP4MC Amalthea ATDB Importer
+Bundle-Name: Amalthea import from ATDB
Bundle-SymbolicName: org.eclipse.app4mc.amalthea.import.atdb;singleton:=true
Bundle-Version: 1.0.0.qualifier
-Require-Bundle: org.eclipse.ui,
+Require-Bundle: org.eclipse.app4mc.atdb,
+ org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ui.ide,
org.eclipse.core.resources,
org.eclipse.app4mc.amalthea.model,
- org.eclipse.app4mc.atdb
+ org.eclipse.e4.core.di.annotations;bundle-version="1.6.500",
+ org.eclipse.e4.ui.model.workbench;bundle-version="2.1.600",
+ org.eclipse.e4.ui.services
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Eclipse APP4MC
+Bundle-ClassPath: .
Automatic-Module-Name: org.eclipse.app4mc.amalthea.import.atdb
+Import-Package: javax.annotation;version="1.0.0";resolution:=optional,
+ javax.inject;version="1.0.0"
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/build.properties b/plugins/org.eclipse.app4mc.amalthea.import.atdb/build.properties
index 0d3d3a7..7a30ec9 100644
--- a/plugins/org.eclipse.app4mc.amalthea.import.atdb/build.properties
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/build.properties
@@ -1,6 +1,13 @@
source.. = src/
output.. = bin/
-bin.includes = plugin.xml,\
- META-INF/,\
+bin.includes = META-INF/,\
.,\
- icons/
+ plugin.xml,\
+ icons/,\
+ epl-2.0.html,\
+ about.html,\
+ fragment.e4xmi
+src.includes = icons/,\
+ epl-2.0.html,\
+ about.html
+source.. = src/
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/fragment.e4xmi b/plugins/org.eclipse.app4mc.amalthea.import.atdb/fragment.e4xmi
new file mode 100644
index 0000000..1bea1e2
--- /dev/null
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/fragment.e4xmi
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="ASCII"?>
+<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:commands="http://www.eclipse.org/ui/2010/UIModel/application/commands" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmlns:ui="http://www.eclipse.org/ui/2010/UIModel/application/ui" xmi:id="_kNQTgPveEemV94f90rg5AA">
+ <fragments xsi:type="fragment:StringModelFragment" xmi:id="_HHdwaGLfEeqq6oTLXqviDw" featurename="commands" parentElementId="xpath:/">
+ <elements xsi:type="commands:Command" xmi:id="_TYRzQguBEeqhKa4w8VmKPQ" elementId="org.eclipse.app4mc.amalthea.import.atdb.command.importatdb" commandName="ATDB -> AMALTHEA Model" description="Imports an ATDB into a new or existing AMALTHEA model"/>
+ </fragments>
+ <fragments xsi:type="fragment:StringModelFragment" xmi:id="_lhFoMGUAEeqhKa4w8VmKPQ" featurename="menuContributions" parentElementId="xpath:/">
+ <elements xsi:type="menu:MenuContribution" xmi:id="_oU4lgGUAEeqhKa4w8VmKPQ" elementId="org.eclipse.app4mc.amalthea.import.atdb.menucontribution.0" positionInParent="after=additions" parentId="popup">
+ <children xsi:type="menu:HandledMenuItem" xmi:id="_ZT3LcGUCEeqhKa4w8VmKPQ" elementId="org.eclipse.app4mc.amalthea.import.atdb.atdb2amxmi" label="ATDB -> AMALTHEA Model" command="_TYRzQguBEeqhKa4w8VmKPQ">
+ <visibleWhen xsi:type="ui:ImperativeExpression" xmi:id="_Rim5oISTEeqespAHWo70QQ" contributionURI="bundleclass://org.eclipse.app4mc.amalthea.import.atdb/org.eclipse.app4mc.amalthea._import.atdb.handler.ATDBAndOptionalAMXMIExpression"/>
+ </children>
+ </elements>
+ </fragments>
+ <fragments xsi:type="fragment:StringModelFragment" xmi:id="_F8tJgGUCEeqhKa4w8VmKPQ" featurename="handlers" parentElementId="xpath:/">
+ <elements xsi:type="commands:Handler" xmi:id="_HfIlkGUCEeqhKa4w8VmKPQ" elementId="org.eclipse.app4mc.amalthea.import.atdb.handler.atdbImport" contributionURI="bundleclass://org.eclipse.app4mc.amalthea.import.atdb/org.eclipse.app4mc.amalthea._import.atdb.handler.ATDB2AMXMIImport" command="_TYRzQguBEeqhKa4w8VmKPQ"/>
+ </fragments>
+</fragment:ModelFragments>
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/plugin.xml b/plugins/org.eclipse.app4mc.amalthea.import.atdb/plugin.xml
index e66c6d1..b40cb1e 100644
--- a/plugins/org.eclipse.app4mc.amalthea.import.atdb/plugin.xml
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/plugin.xml
@@ -2,19 +2,21 @@
<?eclipse version="3.4"?>
<plugin>
- <extension
- point="org.eclipse.ui.importWizards">
+ <extension point="org.eclipse.ui.importWizards">
<wizard
- category="org.eclipse.app4mc.amalthea.import.amalthea"
+ category="org.eclipse.app4mc.amalthea.import"
class="org.eclipse.app4mc.amalthea._import.atdb.wizard.ImportWizard"
icon="icons/amalthea.gif"
id="org.eclipse.app4mc.amalthea.import.atdb.wizard"
name="From AMALTHEA Trace DB">
+ <description>Import ATDB into a new or existing AMALTHEA model</description>
+ <selection class="org.eclipse.core.resources.IResource" />
</wizard>
- <category
- id="org.eclipse.app4mc.amalthea.import.amalthea"
- name="AMALTHEA">
- </category>
+ <category id="org.eclipse.app4mc.amalthea.import" name="AMALTHEA" />
+ </extension>
+
+ <extension id="org.eclipse.app4mc.amalthea.import.atdb.ui.fragment" point="org.eclipse.e4.workbench.model">
+ <fragment uri="fragment.e4xmi" />
</extension>
</plugin>
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/ImportTransformation.java b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/ImportTransformation.java
index c9d1306..ecfa5c8 100644
--- a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/ImportTransformation.java
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/ImportTransformation.java
@@ -90,7 +90,7 @@
// runnables
final SubMonitor runConvMonitor = subMon.split(1);
- double freqInHz = HardwareUtil.getModulesFromHwModel(ProcessingUnit.class, model).stream()
+ final double freqInHz = HardwareUtil.getModulesFromHwModel(ProcessingUnit.class, model).stream()
.mapToLong(HardwareUtil::getFrequencyOfModuleInHz).average().orElse(0);
final IRunnableWithProgress runnableConverter = new RunnableConverter(model, con,
this.extractRunnableRuntimes, this.extractLabelsAndAccesses, freqInHz);
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/RunnableConverter.java b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/RunnableConverter.java
index 512d362..044aa4d 100644
--- a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/RunnableConverter.java
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/RunnableConverter.java
@@ -39,6 +39,7 @@
import org.eclipse.app4mc.atdb.ATDBConnection;
import org.eclipse.app4mc.atdb.MetricAggregation;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.util.EcoreUtil;
public class RunnableConverter extends AConverter {
@@ -85,7 +86,7 @@
});
}
// runtimes
- if (this.extractRuntimes && timeBase != null) {
+ if (this.extractRuntimes && timeBase != null && this.frequency.getValue() >= 1) {
double runningTimeAvg = -1;
double runningTimeStDev = -1;
try {
@@ -136,6 +137,9 @@
la.setAccess(LabelAccessEnum.WRITE);
});
}
+ if (ag.getItems().isEmpty()) {
+ EcoreUtil.delete(ag);
+ }
}
progressMonitor.worked(1);
} catch (SQLException e) {
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/handler/ATDB2AMXMIImport.java b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/handler/ATDB2AMXMIImport.java
new file mode 100644
index 0000000..579a711
--- /dev/null
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/handler/ATDB2AMXMIImport.java
@@ -0,0 +1,56 @@
+/**
+ ********************************************************************************
+ * Copyright (c) 2020 Eclipse APP4MC contributors.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ ********************************************************************************
+ */
+
+package org.eclipse.app4mc.amalthea._import.atdb.handler;
+
+import java.util.List;
+
+import javax.inject.Named;
+
+import org.eclipse.app4mc.amalthea._import.atdb.wizard.ImportWizard;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbenchWindow;
+
+public class ATDB2AMXMIImport {
+
+ @Execute
+ public void execute(final @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, final IWorkbenchWindow runnableContext) {
+ final List<?> selectionList = selection.toList();
+ final String atdbSource = selectionList.stream().filter(IFile.class::isInstance).map(IFile.class::cast)
+ .filter(f -> f.getFileExtension().equalsIgnoreCase("atdb")).map(f -> f.getLocation().toString())
+ .findFirst().orElseThrow(() -> new IllegalArgumentException("Selection does not contain an *.atdb file!"));
+ final IFile amxmiTarget = selectionList.stream().filter(IFile.class::isInstance).map(IFile.class::cast)
+ .filter(f -> f.getFileExtension().equalsIgnoreCase("amxmi")).findFirst().orElseGet(() -> {
+ // use the file name of the atdb
+ final int from = Math.max(atdbSource.lastIndexOf('/'), atdbSource.lastIndexOf('\\'));
+ final int to = atdbSource.lastIndexOf(".atdb"); //$NON-NLS-1$
+ final String name = atdbSource.substring(from + 1, to);
+ return selectionList.stream().filter(IFile.class::isInstance).map(IFile.class::cast)
+ .filter(f -> f.getFileExtension().equalsIgnoreCase("atdb")).map(f -> f.getParent())
+ .map(c -> c.getProject().getFile(name + ".amxmi"))
+ .findFirst().orElseThrow(() -> new IllegalArgumentException("Selected *.atdb file is not part of a Eclipse workspace!"));
+ });
+ if (atdbSource.length() == 0) {
+ return;
+ }
+ if (runnableContext == null) {
+ return;
+ }
+
+ ImportWizard.importAndOpenInIDE(atdbSource, amxmiTarget, true, true, true, runnableContext);
+ }
+
+}
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/handler/ATDBAndOptionalAMXMIExpression.java b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/handler/ATDBAndOptionalAMXMIExpression.java
new file mode 100644
index 0000000..31890bf
--- /dev/null
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/handler/ATDBAndOptionalAMXMIExpression.java
@@ -0,0 +1,43 @@
+/**
+ ********************************************************************************
+ * Copyright (c) 2020 Eclipse APP4MC contributors.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ ********************************************************************************
+ */
+
+package org.eclipse.app4mc.amalthea._import.atdb.handler;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.inject.Named;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.e4.core.di.annotations.Evaluate;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+public class ATDBAndOptionalAMXMIExpression {
+
+ @Evaluate
+ public boolean evaluate(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection) {
+ if (selection != null && selection.size() >= 1 && selection.size() <= 2) {
+ final List<String> extensions = Stream.of(selection.toArray()).filter(IFile.class::isInstance)
+ .map(IFile.class::cast).map(IFile::getFileExtension).collect(Collectors.toList());
+ if (extensions.size() == selection.size() && extensions.contains("atdb") &&
+ (selection.size() == 1 || extensions.contains("amxmi"))) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/wizard/ImportPage.java b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/wizard/ImportPage.java
index 626f82c..d6bf39e 100644
--- a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/wizard/ImportPage.java
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/wizard/ImportPage.java
@@ -16,10 +16,9 @@
package org.eclipse.app4mc.amalthea._import.atdb.wizard;
import java.io.File;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.swt.SWT;
@@ -173,8 +172,8 @@
@Override
protected void updateWidgetEnablements() {
if (this.handleExistingGroup != null) {
- String target = getTarget();
- if (target.length() > 1 && Files.exists(Paths.get(target))) {
+ final IFile target = getAMXMITarget();
+ if (target != null && target.exists()) {
this.handleExistingGroup.setVisible(true);
} else {
this.handleExistingGroup.setVisible(false);
@@ -183,21 +182,21 @@
super.updateWidgetEnablements();
}
- String getSource() {
+ String getATDBSource() {
return this.sourceNameField.getText();
}
- String getTarget() {
- final String source = getSource();
+ IFile getAMXMITarget() {
+ final String source = getATDBSource();
final IContainer target = getTargetContainer();
if (target == null || source.length() == 0) {
- return "";
+ return null;
}
// get the file name of the atdb
final int from = Math.max(source.lastIndexOf('/'), source.lastIndexOf('\\'));
final int to = source.lastIndexOf(".atdb"); //$NON-NLS-1$
final String name = source.substring(from + 1, to);
- return target.getLocation() + "/" + name + ".amxmi"; //$NON-NLS-1$
+ return target.getFile(target.getProjectRelativePath().append(name).addFileExtension("amxmi"));
}
IContainer getTargetContainer() {
diff --git a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/wizard/ImportWizard.java b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/wizard/ImportWizard.java
index c18e04a..5351c92 100644
--- a/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/wizard/ImportWizard.java
+++ b/plugins/org.eclipse.app4mc.amalthea.import.atdb/src/org/eclipse/app4mc/amalthea/_import/atdb/wizard/ImportWizard.java
@@ -19,13 +19,13 @@
import java.util.List;
import org.eclipse.app4mc.amalthea._import.atdb.ImportTransformation;
-import org.eclipse.core.resources.IContainer;
+import org.eclipse.app4mc.amalthea._import.atdb.handler.ATDB2AMXMIImport;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -66,30 +66,36 @@
@Override
public boolean performFinish() {
- final String source = this.mainPage.getSource();
- final String target = this.mainPage.getTarget();
- final IContainer targetContainer = this.mainPage.getTargetContainer();
+ final String atdbSource = this.mainPage.getATDBSource();
+ final IFile amxmiTarget = this.mainPage.getAMXMITarget();
final boolean extractLabelsAndAccesses = this.mainPage.isExtractLabelsAndAccesses();
final boolean extractRunnableRuntimes = this.mainPage.isExtractRunnableRuntimes();
final boolean overwriteExisting = this.mainPage.isOverwriteExisting();
+ return importAndOpenInIDE(atdbSource, amxmiTarget, extractLabelsAndAccesses, extractRunnableRuntimes, overwriteExisting, getContainer());
+ }
+
+ public static boolean importAndOpenInIDE(final String atdbSource, final IFile amxmiTarget,
+ final boolean extractLabelsAndAccesses, final boolean extractRunnableRuntimes, final boolean overwriteExisting,
+ final IRunnableContext runnableContext) {
final WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
protected void execute(final IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException, CoreException {
- final IRunnableWithProgress transformer = new ImportTransformation(source, target, extractLabelsAndAccesses,
- extractRunnableRuntimes, overwriteExisting);
+ final IRunnableWithProgress transformer = new ImportTransformation(atdbSource, amxmiTarget.getLocation().toString(),
+ extractLabelsAndAccesses, extractRunnableRuntimes, overwriteExisting);
transformer.run(progressMonitor);
// refresh workspace
- targetContainer.refreshLocal(1, progressMonitor);
+ amxmiTarget.refreshLocal(1, progressMonitor);
progressMonitor.done();
}
};
try {
- getContainer().run(true, true, operation);
+ runnableContext.run(true, true, operation);
} catch (InvocationTargetException e1) {
- Platform.getLog(getClass()).log(new Status(Status.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), e1.getLocalizedMessage(), e1));
+ Platform.getLog(ATDB2AMXMIImport.class).log(new Status(Status.ERROR,
+ FrameworkUtil.getBundle(ATDB2AMXMIImport.class).getSymbolicName(), e1.getLocalizedMessage(), e1));
return false;
} catch (InterruptedException e2) {
Thread.currentThread().interrupt();
@@ -97,14 +103,13 @@
}
// open new amxmi file in editor
- final IProject project = targetContainer.getProject();
- final IFile file = project.getFile(target.substring(target.lastIndexOf('/') + 1));
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
- IDE.openEditor(page, file);
+ IDE.openEditor(page, amxmiTarget);
}
catch (final PartInitException e) {
- Platform.getLog(getClass()).log(new Status(Status.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), e.getLocalizedMessage(), e));
+ Platform.getLog(ATDB2AMXMIImport.class).log(new Status(Status.ERROR,
+ FrameworkUtil.getBundle(ATDB2AMXMIImport.class).getSymbolicName(), e.getLocalizedMessage(), e));
return false;
}
diff --git a/plugins/org.eclipse.app4mc.atdb.import.amalthea/plugin.xml b/plugins/org.eclipse.app4mc.atdb.import.amalthea/plugin.xml
index cad3bd2..5b13db0 100644
--- a/plugins/org.eclipse.app4mc.atdb.import.amalthea/plugin.xml
+++ b/plugins/org.eclipse.app4mc.atdb.import.amalthea/plugin.xml
@@ -15,12 +15,8 @@
<category id="org.eclipse.app4mc.atdb.import" name="AMALTHEA Trace DB" />
</extension>
- <extension
- id="org.eclipse.app4mc.visualization.ui.fragment"
- point="org.eclipse.e4.workbench.model">
- <fragment
- uri="fragment.e4xmi">
- </fragment>
+ <extension id="org.eclipse.app4mc.atdb.import.amalthea.ui.fragment" point="org.eclipse.e4.workbench.model">
+ <fragment uri="fragment.e4xmi" />
</extension>
</plugin>
diff --git a/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/handler/AMXMI2ATDBImport.java b/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/handler/AMXMI2ATDBImport.java
index 556ac20..3ed1d25 100644
--- a/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/handler/AMXMI2ATDBImport.java
+++ b/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/handler/AMXMI2ATDBImport.java
@@ -1,3 +1,16 @@
+/**
+ ********************************************************************************
+ * Copyright (c) 2020 Eclipse APP4MC contributors.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ ********************************************************************************
+ */
+
package org.eclipse.app4mc.atdb._import.amalthea.handler;
import java.util.List;
@@ -5,7 +18,6 @@
import javax.inject.Named;
import org.eclipse.app4mc.atdb._import.amalthea.wizard.ImportWizard;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.services.IServiceConstants;
@@ -18,14 +30,19 @@
public void execute(final @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, final IWorkbenchWindow runnableContext) {
final List<?> selectionList = selection.toList();
final String amxmiSource = selectionList.stream().filter(IFile.class::isInstance).map(IFile.class::cast)
- .filter(f -> f.getFileExtension().equalsIgnoreCase("amxmi")).map(f -> f.getLocation().toOSString())
+ .filter(f -> f.getFileExtension().equalsIgnoreCase("amxmi")).map(f -> f.getLocation().toString())
.findFirst().orElseThrow(() -> new IllegalArgumentException("Selection does not contain an *.amxmi file!"));
final String atdbSource = selectionList.stream().filter(IFile.class::isInstance).map(IFile.class::cast)
- .filter(f -> f.getFileExtension().equalsIgnoreCase("atdb")).map(f -> f.getLocation().toOSString())
+ .filter(f -> f.getFileExtension().equalsIgnoreCase("atdb")).map(f -> f.getLocation().toString())
.findFirst().orElseThrow(() -> new IllegalArgumentException("Selection does not contain an *.atdb file!"));
- final IContainer targetContainer = selectionList.stream().filter(IFile.class::isInstance).map(IFile.class::cast)
- .filter(f -> f.getFileExtension().equalsIgnoreCase("amxmi")).map(f -> f.getParent())
- .findFirst().orElseThrow(() -> new IllegalArgumentException("Selected *.amxmi file is not part of a Eclipse workspace!"));
+ final IFile atdbTarget = selectionList.stream().filter(IFile.class::isInstance).map(IFile.class::cast)
+ .filter(f -> f.getFileExtension().equalsIgnoreCase("amxmi")).map(f -> f.getParent()).map(c -> {
+ // use the file name of the amxmi
+ final int from = Math.max(amxmiSource.lastIndexOf('/'), amxmiSource.lastIndexOf('\\'));
+ final int to = amxmiSource.lastIndexOf(".amxmi"); //$NON-NLS-1$
+ final String name = amxmiSource.substring(from + 1, to);
+ return c.getProject().getFile(name + ".atdb");
+ }).findFirst().orElseThrow(() -> new IllegalArgumentException("Selected *.amxmi file is not part of a Eclipse workspace!"));
if (amxmiSource.length() == 0 || atdbSource.length() == 0) {
return;
}
@@ -33,7 +50,7 @@
return;
}
- ImportWizard.importAndOpenInIDE(amxmiSource, atdbSource, targetContainer, true, runnableContext);
+ ImportWizard.importAndOpenInIDE(amxmiSource, atdbSource, atdbTarget, true, runnableContext);
}
}
diff --git a/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/handler/AmaltheaModelAndATDBElementExpression.java b/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/handler/AmaltheaModelAndATDBElementExpression.java
index 1c1637e..de9ab92 100644
--- a/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/handler/AmaltheaModelAndATDBElementExpression.java
+++ b/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/handler/AmaltheaModelAndATDBElementExpression.java
@@ -1,3 +1,16 @@
+/**
+ ********************************************************************************
+ * Copyright (c) 2020 Eclipse APP4MC contributors.
+ *
+ * This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License 2.0
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ ********************************************************************************
+ */
+
package org.eclipse.app4mc.atdb._import.amalthea.handler;
import java.util.List;
diff --git a/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/wizard/ImportWizard.java b/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/wizard/ImportWizard.java
index 23b3ea6..7d454f0 100644
--- a/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/wizard/ImportWizard.java
+++ b/plugins/org.eclipse.app4mc.atdb.import.amalthea/src/org/eclipse/app4mc/atdb/_import/amalthea/wizard/ImportWizard.java
@@ -20,9 +20,7 @@
import org.eclipse.app4mc.atdb._import.amalthea.ImportTransformation;
import org.eclipse.app4mc.atdb._import.amalthea.handler.AMXMI2ATDBImport;
-import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
@@ -70,26 +68,25 @@
public boolean performFinish() {
final String amxmiSource = this.mainPage.getAMXMISource();
final String atdbSource = this.mainPage.getATDBSource();
- final IContainer target = this.mainPage.getTargetContainer();
- return importAndOpenInIDE(amxmiSource, atdbSource, target, this.mainPage.isUpdateExistingATDB(), getContainer());
- }
-
- public static boolean importAndOpenInIDE(final String amxmiSource, final String atdbSource, final IContainer target, final boolean copySource,
- final IRunnableContext runnableContext) {
// get the file name of the amxmi
final int from = Math.max(amxmiSource.lastIndexOf('/'), amxmiSource.lastIndexOf('\\'));
final int to = amxmiSource.lastIndexOf(".amxmi"); //$NON-NLS-1$
final String name = amxmiSource.substring(from + 1, to);
- final String targetATDB = target.getLocation() + "/" + name + ".atdb"; //$NON-NLS-1$
+ final IFile targetATDB = this.mainPage.getTargetContainer().getFile(this.mainPage.getTargetContainer().getLocation().append(name).addFileExtension("atdb"));
+ return importAndOpenInIDE(amxmiSource, atdbSource, targetATDB, this.mainPage.isUpdateExistingATDB(), getContainer());
+ }
+
+ public static boolean importAndOpenInIDE(final String amxmiSource, final String atdbSource, final IFile atdbTarget, final boolean copySource,
+ final IRunnableContext runnableContext) {
final WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
@Override
protected void execute(final IProgressMonitor progressMonitor) throws InvocationTargetException, InterruptedException, CoreException {
- final IRunnableWithProgress transformer = new ImportTransformation(amxmiSource, atdbSource, targetATDB, copySource);
+ final IRunnableWithProgress transformer = new ImportTransformation(amxmiSource, atdbSource, atdbTarget.getLocation().toString(), copySource);
transformer.run(progressMonitor);
// refresh workspace
- target.refreshLocal(1, progressMonitor);
+ atdbTarget.refreshLocal(1, progressMonitor);
progressMonitor.done();
}
};
@@ -106,13 +103,13 @@
}
// open new/updated atdb file in viewer
- final IProject project = target.getProject();
- final IFile file = project.getFile(targetATDB.substring(targetATDB.lastIndexOf('/') + 1));
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
try {
- IDE.openEditor(page, file);
+ IDE.openEditor(page, atdbTarget);
}
catch (final PartInitException e) {
+ Platform.getLog(AMXMI2ATDBImport.class).log(new Status(Status.ERROR,
+ FrameworkUtil.getBundle(AMXMI2ATDBImport.class).getSymbolicName(), e.getLocalizedMessage(), e));
return false;
}