diff options
author | mgolubev | 2014-05-26 09:02:47 +0000 |
---|---|---|
committer | mgolubev | 2014-05-27 15:29:52 +0000 |
commit | 7fe69f73e5bc462406cc3f3f627cec98f76928c8 (patch) | |
tree | 66b4832a4023d395e6082ffd4c0964c645b5e9ce /extraplugins | |
parent | a558e1e89ffcaad4ead52967b18fb7e5c86e6c97 (diff) | |
download | org.eclipse.papyrus-7fe69f73e5bc462406cc3f3f627cec98f76928c8.tar.gz org.eclipse.papyrus-7fe69f73e5bc462406cc3f3f627cec98f76928c8.tar.xz org.eclipse.papyrus-7fe69f73e5bc462406cc3f3f627cec98f76928c8.zip |
Diagram Versions: reconcilers framework introduced to allow automatic
conevertions of diagrams between Papyrus versions
+ XXXViewProvider updated to setup "current" diagram version for new
diagrams
+ XXXViewProvider generator updated to generate above
+ 4x Migration of RobotML diagrams using new framework
+ repackaged to oep.infra.gmfdiag.common
with respect to comments at https://git.eclipse.org/r/#/c/26412/
Change-Id: I40f22852cdd988f904a1b926263c5a18e85ee292
Signed-off-by: mgolubev <golubev@montages.com>
Diffstat (limited to 'extraplugins')
6 files changed, 316 insertions, 0 deletions
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/plugin.xml b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/plugin.xml index f1673ab4e63..f851808ece4 100644 --- a/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/plugin.xml +++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/plugin.xml @@ -10,6 +10,26 @@ id="robotML"
label="RobotML">
</diagramCategory>
+ <editorDiagram
+ actionBarContributorId="org.eclipse.papyrus.uml.diagram.common.part.UMLDiagramActionBarContributor"
+ factoryClass="org.eclipse.papyrus.robotml.diagram.common.factory.RobotMLArchitecture2CompositeDiagramFactory"
+ icon="icons/robotml_16x16.png">
+ </editorDiagram>
+ <editorDiagram
+ actionBarContributorId="org.eclipse.papyrus.uml.diagram.common.part.UMLDiagramActionBarContributor"
+ factoryClass="org.eclipse.papyrus.robotml.diagram.common.factory.RobotMLComponent2CompositeDiagramFactory"
+ icon="icons/robotml_16x16.png">
+ </editorDiagram>
+ <editorDiagram
+ actionBarContributorId="org.eclipse.papyrus.uml.diagram.common.part.UMLDiagramActionBarContributor"
+ factoryClass="org.eclipse.papyrus.robotml.diagram.common.factory.RobotMLDatatype2ClassDiagramFactory"
+ icon="icons/robotml_16x16.png">
+ </editorDiagram>
+ <editorDiagram
+ actionBarContributorId="org.eclipse.papyrus.uml.diagram.common.part.UMLDiagramActionBarContributor"
+ factoryClass="org.eclipse.papyrus.robotml.diagram.common.factory.RobotMLInterface2ClassDiagramFactory"
+ icon="icons/robotml_16x16.png">
+ </editorDiagram>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
@@ -141,4 +161,31 @@ <Priority name="Low"/>
</editpolicyProvider>
</extension>
+<extension
+ point="org.eclipse.papyrus.infra.gmfdiag.common.diagramReconciler">
+ <diagramReconciler
+ diagramType="componentdef"
+ reconcilerClass="org.eclipse.papyrus.robotml.diagram.common.migration.RobotMLReconciler"
+ source="0.9.0"
+ target="1.0.0">
+ </diagramReconciler>
+ <diagramReconciler
+ diagramType="DatatypeDef"
+ reconcilerClass="org.eclipse.papyrus.robotml.diagram.common.migration.RobotMLReconciler"
+ source="0.9.0"
+ target="1.0.0">
+ </diagramReconciler>
+ <diagramReconciler
+ diagramType="architecture"
+ reconcilerClass="org.eclipse.papyrus.robotml.diagram.common.migration.RobotMLReconciler"
+ source="0.9.0"
+ target="1.0.0">
+ </diagramReconciler>
+ <diagramReconciler
+ diagramType="InterfaceDef"
+ reconcilerClass="org.eclipse.papyrus.robotml.diagram.common.migration.RobotMLReconciler"
+ source="0.9.0"
+ target="1.0.0">
+ </diagramReconciler>
+</extension>
</plugin>
diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLArchitecture2CompositeDiagramFactory.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLArchitecture2CompositeDiagramFactory.java new file mode 100644 index 00000000000..cad3d555f6f --- /dev/null +++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLArchitecture2CompositeDiagramFactory.java @@ -0,0 +1,24 @@ +package org.eclipse.papyrus.robotml.diagram.common.factory; + +import org.eclipse.papyrus.infra.gmfdiag.common.GmfEditorFactory; +import org.eclipse.papyrus.robotml.diagram.common.migration.RobotMLReconciler; +import org.eclipse.papyrus.uml.diagram.composite.UmlCompositeDiagramForMultiEditor; + +/** + * This class is part of the migration of the RobotML diagrams, which, + * since Papyrus 1.0 should be opened by the corresponding UML diagram editors, + * in this particular case, {@link UmlCompositeDiagramForMultiEditor} + * <p/> + * This class registers the corresponding UML editor to the robot-ML type and allows the migration framework to proceed. + * <p/> + * The other component of the process is {@link RobotMLReconciler} which actually performs migration. + */ +public class RobotMLArchitecture2CompositeDiagramFactory extends GmfEditorFactory { + + public static final String OLD_ROBOT_ML_TYPE = "architecture"; + + public RobotMLArchitecture2CompositeDiagramFactory() { + super(UmlCompositeDiagramForMultiEditor.class, OLD_ROBOT_ML_TYPE); + } + +} diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLComponent2CompositeDiagramFactory.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLComponent2CompositeDiagramFactory.java new file mode 100644 index 00000000000..25883214ac2 --- /dev/null +++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLComponent2CompositeDiagramFactory.java @@ -0,0 +1,25 @@ +package org.eclipse.papyrus.robotml.diagram.common.factory; + +import org.eclipse.papyrus.infra.gmfdiag.common.GmfEditorFactory; +import org.eclipse.papyrus.robotml.diagram.common.migration.RobotMLReconciler; +import org.eclipse.papyrus.uml.diagram.composite.UmlCompositeDiagramForMultiEditor; + + +/** + * This class is part of the migration of the RobotML diagrams, which, + * since Papyrus 1.0 should be opened by the corresponding UML diagram editors, + * in this particular case, {@link UmlCompositeDiagramForMultiEditor} + * <p/> + * This class registers the corresponding UML editor to the robot-ML type and allows the migration framework to proceed. + * <p/> + * The other component of the process is {@link RobotMLReconciler} which actually performs migration. + */ +public class RobotMLComponent2CompositeDiagramFactory extends GmfEditorFactory { + + public static final String OLD_ROBOT_ML_TYPE = "componentdef"; + + public RobotMLComponent2CompositeDiagramFactory() { + super(UmlCompositeDiagramForMultiEditor.class, OLD_ROBOT_ML_TYPE); + } + +} diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLDatatype2ClassDiagramFactory.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLDatatype2ClassDiagramFactory.java new file mode 100644 index 00000000000..f34b0b28126 --- /dev/null +++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLDatatype2ClassDiagramFactory.java @@ -0,0 +1,25 @@ +package org.eclipse.papyrus.robotml.diagram.common.factory; + +import org.eclipse.papyrus.infra.gmfdiag.common.GmfEditorFactory; +import org.eclipse.papyrus.robotml.diagram.common.migration.RobotMLReconciler; +import org.eclipse.papyrus.uml.diagram.clazz.UmlClassDiagramForMultiEditor; + + +/** + * This class is part of the migration of the RobotML diagrams, which, + * since Papyrus 1.0 should be opened by the corresponding UML diagram editors, + * in this particular case, {@link UmlClassDiagramForMultiEditor} + * <p/> + * This class registers the corresponding UML editor to the robot-ML type and allows the migration framework to proceed. + * <p/> + * The other component of the process is {@link RobotMLReconciler} which actually performs migration. + */ +public class RobotMLDatatype2ClassDiagramFactory extends GmfEditorFactory { + + public static final String OLD_ROBOT_ML_TYPE = "DatatypeDef"; + + public RobotMLDatatype2ClassDiagramFactory() { + super(UmlClassDiagramForMultiEditor.class, OLD_ROBOT_ML_TYPE); + } + +} diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLInterface2ClassDiagramFactory.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLInterface2ClassDiagramFactory.java new file mode 100644 index 00000000000..47e8a66026d --- /dev/null +++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/factory/RobotMLInterface2ClassDiagramFactory.java @@ -0,0 +1,24 @@ +package org.eclipse.papyrus.robotml.diagram.common.factory; + +import org.eclipse.papyrus.infra.gmfdiag.common.GmfEditorFactory; +import org.eclipse.papyrus.robotml.diagram.common.migration.RobotMLReconciler; +import org.eclipse.papyrus.uml.diagram.clazz.UmlClassDiagramForMultiEditor; + +/** + * This class is part of the migration of the RobotML diagrams, which, + * since Papyrus 1.0 should be opened by the corresponding UML diagram editors, + * in this particular case, {@link UmlClassDiagramForMultiEditor} + * <p/> + * This class registers the corresponding UML editor to the robot-ML type and allows the migration framework to proceed. + * <p/> + * The other component of the process is {@link RobotMLReconciler} which actually performs migration. + */ +public class RobotMLInterface2ClassDiagramFactory extends GmfEditorFactory { + + public static final String OLD_ROBOT_ML_TYPE = "InterfaceDef"; + + public RobotMLInterface2ClassDiagramFactory() { + super(UmlClassDiagramForMultiEditor.class, OLD_ROBOT_ML_TYPE); + } + +} diff --git a/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/migration/RobotMLReconciler.java b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/migration/RobotMLReconciler.java new file mode 100644 index 00000000000..08b9424e5c6 --- /dev/null +++ b/extraplugins/robotml/org.eclipse.papyrus.robotml.diagram.common/src/org/eclipse/papyrus/robotml/diagram/common/migration/RobotMLReconciler.java @@ -0,0 +1,171 @@ +package org.eclipse.papyrus.robotml.diagram.common.migration; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.gmf.runtime.common.core.command.AbstractCommand; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.infra.gmfdiag.common.reconciler.DiagramReconciler; +import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils; +import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker; +import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype; +import org.eclipse.papyrus.robotml.diagram.common.factory.RobotMLArchitecture2CompositeDiagramFactory; +import org.eclipse.papyrus.robotml.diagram.common.factory.RobotMLComponent2CompositeDiagramFactory; +import org.eclipse.papyrus.robotml.diagram.common.factory.RobotMLDatatype2ClassDiagramFactory; +import org.eclipse.papyrus.robotml.diagram.common.factory.RobotMLInterface2ClassDiagramFactory; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ModelEditPart; +import org.eclipse.papyrus.uml.diagram.composite.edit.parts.CompositeStructureDiagramEditPart; + + +public class RobotMLReconciler extends DiagramReconciler { + + private static final String OLD_ARCHITECTURE_TYPE = RobotMLArchitecture2CompositeDiagramFactory.OLD_ROBOT_ML_TYPE; + + private static final String OLD_COMPONENT_TYPE = RobotMLComponent2CompositeDiagramFactory.OLD_ROBOT_ML_TYPE; + + private static final String OLD_INTERFACE_TYPE = RobotMLInterface2ClassDiagramFactory.OLD_ROBOT_ML_TYPE; + + private static final String OLD_DATATYPE_TYPE = RobotMLDatatype2ClassDiagramFactory.OLD_ROBOT_ML_TYPE; + + private static final String NEW_CLASS_DIAGRAM = ModelEditPart.MODEL_ID; + + private static final String NEW_COMPOSITE_DIAGRAM = CompositeStructureDiagramEditPart.MODEL_ID; + + private static final MigrationData ARCHITECTURE = new MigrationData(OLD_ARCHITECTURE_TYPE, NEW_COMPOSITE_DIAGRAM, "RobotML Architecture"); + + private static final MigrationData COMPONENT = new MigrationData(OLD_COMPONENT_TYPE, NEW_COMPOSITE_DIAGRAM, "RobotML Component"); + + private static final MigrationData INTERFACE = new MigrationData(OLD_INTERFACE_TYPE, NEW_CLASS_DIAGRAM, "RobotML Interface"); + + private static final MigrationData DATATYPE = new MigrationData(OLD_DATATYPE_TYPE, NEW_CLASS_DIAGRAM, "RobotML Datatype"); + + /** + * Original code in {@link MigrateDiagramsHandler} uses {@link String#equalsIgnoreCase(String)}. + * <p/> + * So the keys in this map are old types toLoserCase. + */ + private static final Map<String, MigrationData> ourMigrations; + + static { + ourMigrations = new HashMap<String, MigrationData>(); + for(MigrationData next : new MigrationData[]{ ARCHITECTURE, COMPONENT, INTERFACE, DATATYPE }) { + ourMigrations.put(safeToLowerCase(next.getOldType()), next); + } + } + + @Override + public ICommand getReconcileCommand(Diagram diagram) { + MigrationData data = findMigration(diagram); + return data == null ? null : new RobotMLReconcileCommand(diagram, data); + } + + /** + * Ignores case + */ + private MigrationData findMigration(Diagram diagram) { + return ourMigrations.get(safeToLowerCase(diagram.getType())); + } + + private static String safeToLowerCase(String text) { + return text == null ? null : text.toLowerCase(); + } + + private static class RobotMLReconcileCommand extends AbstractCommand { + + private final Diagram myDiagram; + + private final MigrationData myMigrationData; + + public RobotMLReconcileCommand(Diagram diagram, MigrationData data) { + super("Migrate old RobotML diagram"); + myDiagram = diagram; + myMigrationData = data; + } + + @Override + protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { + DiagramUtils.setPrototype(myDiagram, myMigrationData.getPrototype()); + DiagramUtils.setOwner(myDiagram, myDiagram.getElement()); + myDiagram.setType(myMigrationData.getNewType()); + + return CommandResult.newOKCommandResult(); + } + + @Override + public boolean canUndo() { + return false; + } + + @Override + public boolean canRedo() { + return false; + } + + @Override + protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { + throw new ExecutionException("Should not be called, canRedo false"); + } + + @Override + protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { + throw new ExecutionException("Should not be called, canUndo false"); + } + + } + + /** + * Encapsulates migration scheme from given old RobotML, new UML diagram type and given prototype. + * <p/> + * Instances of this class are considered invalid if the prototype is not known. + */ + private static class MigrationData { + + private ViewPrototype myCachedPrototype; + + private final String myNewType; + + private final String myOldType; + + private final String myPrototypeLabel; + + public MigrationData(String oldType, String newType, String prototypeLabel) { + myOldType = oldType; + myNewType = newType; + myPrototypeLabel = prototypeLabel; + } + + public String getPrototypeLabel() { + return myPrototypeLabel; + } + + public String getOldType() { + return myOldType; + } + + public String getNewType() { + return myNewType; + } + + public ViewPrototype getPrototype() { + if(myCachedPrototype == null) { + myCachedPrototype = findPrototype(myPrototypeLabel); + } + return myCachedPrototype; + } + + private static ViewPrototype findPrototype(String label) { + for(ViewPrototype proto : PolicyChecker.getCurrent().getAllPrototypes()) { + if(proto.getLabel().contains(label)) { + return proto; + } + } + return null; + } + + } +} |