diff options
author | Henrik Rentz-Reichert | 2014-08-19 15:05:22 +0000 |
---|---|---|
committer | Henrik Rentz-Reichert | 2014-08-19 15:05:22 +0000 |
commit | 22e6576e0ebd7a671d75f332244d120059207850 (patch) | |
tree | a6079fd94bb56a0d884d0d338a88f7e1c9e3711e /plugins | |
parent | 396108661a6b8932854723d72678481a10e0a9c3 (diff) | |
download | org.eclipse.etrice-22e6576e0ebd7a671d75f332244d120059207850.tar.gz org.eclipse.etrice-22e6576e0ebd7a671d75f332244d120059207850.tar.xz org.eclipse.etrice-22e6576e0ebd7a671d75f332244d120059207850.zip |
[ui.*] split off ui.behavior.fsm from ui.behavior
The major part of the editor code is general and contained in ui.behavior.fsm.
The dialogs are created by dependency injection and a factory.
Change-Id: I5460dbdd8a99a060ca3cc084c93bf42a6cecbca3
Diffstat (limited to 'plugins')
77 files changed, 2465 insertions, 1573 deletions
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/.classpath b/plugins/org.eclipse.etrice.ui.behavior.fsm/.classpath new file mode 100644 index 000000000..ad32c83a7 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/.gitignore b/plugins/org.eclipse.etrice.ui.behavior.fsm/.gitignore new file mode 100644 index 000000000..ba077a403 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/.gitignore @@ -0,0 +1 @@ +bin diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/.project b/plugins/org.eclipse.etrice.ui.behavior.fsm/.project new file mode 100644 index 000000000..cf04191bc --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.etrice.ui.behavior.fsm</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.etrice.ui.behavior.fsm/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..c537b6306 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF new file mode 100644 index 000000000..c9431932d --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/META-INF/MANIFEST.MF @@ -0,0 +1,29 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Abstract FSM Diagram Editor +Bundle-SymbolicName: org.eclipse.etrice.ui.behavior.fsm +Bundle-Version: 0.5.0.qualifier +Bundle-Activator: org.eclipse.etrice.ui.behavior.fsm.Activator +Bundle-Vendor: eTrice (Incubation) +Require-Bundle: org.eclipse.etrice.core.common.ui;bundle-version="0.5.0", + org.eclipse.etrice.ui.common.base;bundle-version="0.0.5", + org.eclipse.etrice.ui.common;bundle-version="0.5.0", + org.eclipse.etrice.ui.behavior.fsm;bundle-version="0.5.0", + org.eclipse.etrice.core.fsm;bundle-version="0.5.0", + org.eclipse.etrice.core.fsm.ui;bundle-version="0.5.0", + org.eclipse.graphiti;bundle-version="0.8.0", + org.eclipse.graphiti.ui;bundle-version="0.8.0", + org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100", + org.eclipse.core.databinding;bundle-version="1.3.100", + org.eclipse.gef;bundle-version="3.6.1", + org.eclipse.emf.transaction;bundle-version="1.4.0", + org.eclipse.xtext.ui;bundle-version="2.1.1", + org.eclipse.xtext.ui.shared;bundle-version="2.1.1", + org.eclipse.etrice.abstractexec.behavior;bundle-version="0.5.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.etrice.ui.behavior.fsm.commands, + org.eclipse.etrice.ui.behavior.fsm.dialogs, + org.eclipse.etrice.ui.behavior.fsm.editor, + org.eclipse.etrice.ui.behavior.fsm.provider, + org.eclipse.etrice.ui.behavior.fsm.support diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/about.html b/plugins/org.eclipse.etrice.ui.behavior.fsm/about.html new file mode 100644 index 000000000..c258ef55d --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 5, 2006</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/build.properties b/plugins/org.eclipse.etrice.ui.behavior.fsm/build.properties new file mode 100644 index 000000000..c6baffa00 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + icons/ diff --git a/plugins/org.eclipse.etrice.ui.behavior/icons/quickfix/error_tsk.gif b/plugins/org.eclipse.etrice.ui.behavior.fsm/icons/quickfix/error_tsk.gif Binary files differindex 197b295e1..197b295e1 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/icons/quickfix/error_tsk.gif +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/icons/quickfix/error_tsk.gif diff --git a/plugins/org.eclipse.etrice.ui.behavior/icons/quickfix/info_tsk.gif b/plugins/org.eclipse.etrice.ui.behavior.fsm/icons/quickfix/info_tsk.gif Binary files differindex 2da001e3e..2da001e3e 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/icons/quickfix/info_tsk.gif +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/icons/quickfix/info_tsk.gif diff --git a/plugins/org.eclipse.etrice.ui.behavior/icons/quickfix/warn_tsk.gif b/plugins/org.eclipse.etrice.ui.behavior.fsm/icons/quickfix/warn_tsk.gif Binary files differindex 14009e997..14009e997 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/icons/quickfix/warn_tsk.gif +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/icons/quickfix/warn_tsk.gif diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/Activator.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/Activator.java new file mode 100644 index 000000000..5caa70211 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/Activator.java @@ -0,0 +1,74 @@ +package org.eclipse.etrice.ui.behavior.fsm; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.etrice.ui.behavior.fsm"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path + * the path + * @return the image descriptor + */ + public static Image getImage(String path) { + Image img = getDefault().getImageRegistry().get(path); + if (img==null) { + ImageDescriptor desc = imageDescriptorFromPlugin(PLUGIN_ID, path); + if (desc==null) + System.err.println("image not found: "+path); + else { + getDefault().getImageRegistry().put(path, desc); + img = getDefault().getImageRegistry().get(path); + } + } + return img; + } + +} diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/PopulateDiagramCommand.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/PopulateDiagramCommand.java index 4fd693f59..165cfaaf7 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/PopulateDiagramCommand.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/PopulateDiagramCommand.java @@ -10,29 +10,33 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.commands; +package org.eclipse.etrice.ui.behavior.fsm.commands; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.ui.behavior.support.ContextSwitcher; -import org.eclipse.etrice.ui.behavior.support.SupportUtil; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; +import org.eclipse.etrice.ui.behavior.fsm.support.ContextSwitcher; +import org.eclipse.etrice.ui.behavior.fsm.support.FSMSupportUtil; import org.eclipse.graphiti.dt.IDiagramTypeProvider; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.mm.pictograms.Diagram; import org.eclipse.graphiti.ui.services.GraphitiUi; +import com.google.inject.Injector; + public class PopulateDiagramCommand extends RecordingCommand { - private ActorClass ac; + private ModelComponent ac; private Diagram diagram; private IFeatureProvider fp; + private Injector injector; - public PopulateDiagramCommand(Diagram diag, ActorClass ac, TransactionalEditingDomain domain) { + public PopulateDiagramCommand(Diagram diag, ModelComponent ac, Injector injector, TransactionalEditingDomain domain) { super(domain); this.diagram = diag; this.ac = ac; + this.injector = injector; IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, "org.eclipse.etrice.ui.behavior.diagramTypeProvider"); //$NON-NLS-1$ fp = dtp.getFeatureProvider(); @@ -44,10 +48,10 @@ public class PopulateDiagramCommand extends RecordingCommand { fp.link(diagram, ac); // we use a temporary structure to create the whole tree - StateGraphContext tree = StateGraphContext.createContextTree(ac); + StateGraphContext tree = StateGraphContext.createContextTree(ac, injector); //System.out.println(tree); - SupportUtil.getInstance().addStateGraph(tree, diagram, fp); + FSMSupportUtil.getInstance().addStateGraph(tree, diagram, fp); ContextSwitcher.switchTop(diagram); } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/StateGraphContext.java index 657a72d61..def037b21 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/commands/StateGraphContext.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/commands/StateGraphContext.java @@ -1,23 +1,25 @@ -package org.eclipse.etrice.ui.behavior.commands; +package org.eclipse.etrice.ui.behavior.fsm.commands; import java.util.ArrayList; import java.util.HashMap; import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.fsm.fSM.ChoicePoint; +import org.eclipse.etrice.core.fsm.fSM.FSMFactory; import org.eclipse.etrice.core.fsm.fSM.InitialTransition; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.RefinedState; -import org.eclipse.etrice.core.fsm.fSM.FSMFactory; import org.eclipse.etrice.core.fsm.fSM.SimpleState; import org.eclipse.etrice.core.fsm.fSM.State; import org.eclipse.etrice.core.fsm.fSM.StateGraph; import org.eclipse.etrice.core.fsm.fSM.StateGraphItem; import org.eclipse.etrice.core.fsm.fSM.TrPoint; import org.eclipse.etrice.core.fsm.fSM.Transition; -import org.eclipse.etrice.ui.behavior.support.DefaultPositionProvider; -import org.eclipse.etrice.ui.behavior.support.IPositionProvider; -import org.eclipse.etrice.ui.behavior.support.SupportUtil; +import org.eclipse.etrice.ui.behavior.fsm.support.DefaultPositionProvider; +import org.eclipse.etrice.ui.behavior.fsm.support.FSMSupportUtil; +import org.eclipse.etrice.ui.behavior.fsm.support.IPositionProvider; + +import com.google.inject.Injector; public class StateGraphContext { private ArrayList<StateGraphContext> children = new ArrayList<StateGraphContext>(); @@ -30,7 +32,7 @@ public class StateGraphContext { private IPositionProvider positionProvider; private HashMap<StateGraphItem, StateGraphContext> obj2ctx; - public static StateGraphContext createContextTree(ActorClass ac) { + public static StateGraphContext createContextTree(ModelComponent ac, Injector injector) { // the top level state graph is always the one of our actor class if (ac.getStateMachine()==null || ac.getStateMachine().eIsProxy()) { @@ -38,18 +40,18 @@ public class StateGraphContext { } // base classes in reverse order - ArrayList<ActorClass> classes = new ArrayList<ActorClass>(); + ArrayList<ModelComponent> classes = new ArrayList<ModelComponent>(); { - ActorClass a = ac; + ModelComponent a = ac; while (a!=null) { classes.add(0, a); - a = a.getActorBase(); + a = a.getBase(); } } // build and merge contexts from base classes to derived classes StateGraphContext tree = null; - for (ActorClass cls : classes) { + for (ModelComponent cls : classes) { if (cls.getStateMachine()!=null) { if (tree==null) tree = new StateGraphContext(cls.getStateMachine(), new HashMap<StateGraphItem, StateGraphContext>()); @@ -58,7 +60,7 @@ public class StateGraphContext { } } - tree.positionProvider = new DefaultPositionProvider(ac); + tree.positionProvider = new DefaultPositionProvider(ac, injector); makePositionsAvailableToChildrenContexts(tree); return tree; @@ -139,7 +141,7 @@ public class StateGraphContext { obj2ctx.put(refined, this); // merge sub contexts - if (SupportUtil.getInstance().getRoomHelpers().hasDirectSubStructure(base)) { + if (FSMSupportUtil.getInstance().getFSMHelpers().hasDirectSubStructure(base)) { StateGraphContext basesub = null; for (StateGraphContext bs : ctx.getChildren()) { if (bs.getParentState()==base) { @@ -148,7 +150,7 @@ public class StateGraphContext { } } if (basesub!=null) { - if (SupportUtil.getInstance().getRoomHelpers().hasDirectSubStructure(refined)) { + if (FSMSupportUtil.getInstance().getFSMHelpers().hasDirectSubStructure(refined)) { basesub.merge(refined.getSubgraph()); } } @@ -156,7 +158,7 @@ public class StateGraphContext { assert(false): "context not found"; } } - else if (SupportUtil.getInstance().getRoomHelpers().hasDirectSubStructure(refined)) { + else if (FSMSupportUtil.getInstance().getFSMHelpers().hasDirectSubStructure(refined)) { StateGraphContext sub = new StateGraphContext(refined.getSubgraph(), obj2ctx); ctx.getChildren().add(sub); } @@ -238,22 +240,22 @@ public class StateGraphContext { } private String getText(StateGraph sg) { - ActorClass ac = getActorClass(sg); + ModelComponent ac = getModelComponent(sg); EObject parent = sg.eContainer(); - String item = parent instanceof ActorClass? "diagram" : (parent.eClass().getName()+" "+((State)parent).getName()); - return "state graph of "+item+" of "+(ac==null? "?":ac.getName()); + String item = parent instanceof ModelComponent? "diagram" : (parent.eClass().getName()+" "+((State)parent).getName()); + return "state graph of "+item+" of "+(ac==null? "?":ac.getComponentName()); } private String getText(StateGraphItem item) { - ActorClass ac = getActorClass(item); - return item.eClass().getName()+" "+item.getName()+" of "+(ac==null? "?":ac.getName()); + ModelComponent ac = getModelComponent(item); + return item.eClass().getName()+" "+item.getName()+" of "+(ac==null? "?":ac.getComponentName()); } - private ActorClass getActorClass(EObject obj) { + private ModelComponent getModelComponent(EObject obj) { EObject parent = obj.eContainer(); while (parent!=null) { - if (parent instanceof ActorClass) - return (ActorClass) parent; + if (parent instanceof ModelComponent) + return (ModelComponent) parent; parent = parent.eContainer(); } return null; diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/AbstractMemberAwarePropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/AbstractMemberAwarePropertyDialog.java index dde29018b..4ba378e26 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/AbstractMemberAwarePropertyDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/AbstractMemberAwarePropertyDialog.java @@ -10,17 +10,11 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.dialogs; +package org.eclipse.etrice.ui.behavior.fsm.dialogs; import java.util.HashSet; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.core.room.Attribute; -import org.eclipse.etrice.core.room.Operation; -import org.eclipse.etrice.core.room.Port; -import org.eclipse.etrice.ui.behavior.dialogs.PortMessageSelectionDialog.MsgItemPair; -import org.eclipse.etrice.ui.behavior.dialogs.PortMessageSelectionDialog.OperationItemPair; -import org.eclipse.etrice.ui.behavior.support.SupportUtil; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.ui.common.base.dialogs.AbstractPropertyDialog; import org.eclipse.jface.window.Window; import org.eclipse.swt.SWT; @@ -36,6 +30,8 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import com.google.inject.Inject; + /** * @author Henrik Rentz-Reichert * @@ -68,10 +64,13 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty } } + @Inject + protected IFSMDialogFactory dialogFactory; + private Text lastTextField = null; private Button members; private Button messages; - private ActorClass ac; + private ModelComponent mc; private LastTextListener listener = new LastTextListener(); private HashSet<Control> memberAware = new HashSet<Control>(); private HashSet<Control> messageAware = new HashSet<Control>(); @@ -82,16 +81,16 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty * @param title * @param ac */ - public AbstractMemberAwarePropertyDialog(Shell shell, String title, ActorClass ac) { + public AbstractMemberAwarePropertyDialog(Shell shell, String title, ModelComponent ac) { super(shell, title); - this.ac = ac; + this.mc = ac; } /** * @return the ac */ - public ActorClass getActorClass() { - return ac; + public ModelComponent getModelComponent() { + return mc; } /** @@ -148,41 +147,17 @@ public abstract class AbstractMemberAwarePropertyDialog extends AbstractProperty } protected void handleMembersPressed() { - MemberSelectionDialog dlg = new MemberSelectionDialog(getShell(), ac); + ISelectionDialog dlg = dialogFactory.createMemberSelectionDialog(getShell(), mc); if (dlg.open()==Window.OK) { - Object selected = dlg.getSelected(); - if (selected instanceof Attribute) - insertText(((Attribute)selected).getName()); - else if (selected instanceof Operation) { - String typedArgumentList = SupportUtil.getInstance().getRoomNameProvider().getTypedArgumentList((Operation) selected); - insertText(((Operation)selected).getName()+typedArgumentList); - } + insertText(dlg.getSelected()); } } protected void handleMessagesPressed() { boolean receiveOnly = recvOnly.contains(lastTextField); - PortMessageSelectionDialog dlg = new PortMessageSelectionDialog(getShell(), ac, receiveOnly); + ISelectionDialog dlg = dialogFactory.createMessageSelectionDialog(getShell(), mc, receiveOnly); if (dlg.open()==Window.OK) { - if (dlg.getMethodItemPair()!=null) { - if (dlg.getMethodItemPair() instanceof MsgItemPair) { - MsgItemPair pair = (MsgItemPair) dlg.getMethodItemPair(); - if (pair.out) { - String data = pair.msg.getData()!=null? pair.msg.getData().getName() : ""; - String index = ""; - if (pair.item instanceof Port && ((Port)pair.item).getMultiplicity()!=1) - index = "[idx]"; - insertText(pair.item.getName()+index+"."+pair.msg.getName()+"("+data+")"); - } - else - insertText(pair.item.getName()+"."+pair.msg.getName()); - } - if (dlg.getMethodItemPair() instanceof OperationItemPair) { - OperationItemPair pair = (OperationItemPair) dlg.getMethodItemPair(); - String arglist = SupportUtil.getInstance().getRoomNameProvider().getArguments(pair.op); - insertText(pair.item.getName()+"."+pair.op.getName()+arglist); - } - } + insertText(dlg.getSelected()); } } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/DetailCodeToString.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/DetailCodeToString.java index 122e10a07..7ffd82e89 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/DetailCodeToString.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/DetailCodeToString.java @@ -1,4 +1,4 @@ -package org.eclipse.etrice.ui.behavior.dialogs; +package org.eclipse.etrice.ui.behavior.fsm.dialogs; import org.eclipse.core.databinding.conversion.Converter; import org.eclipse.etrice.core.fsm.fSM.DetailCode; diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/IChoicePointPropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/IChoicePointPropertyDialog.java new file mode 100644 index 000000000..3a60af30c --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/IChoicePointPropertyDialog.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.dialogs; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface IChoicePointPropertyDialog { + int open(); +} diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/IFSMDialogFactory.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/IFSMDialogFactory.java new file mode 100644 index 000000000..3489d8606 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/IFSMDialogFactory.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.dialogs; + +import org.eclipse.etrice.core.fsm.fSM.ChoicePoint; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; +import org.eclipse.etrice.core.fsm.fSM.State; +import org.eclipse.etrice.core.fsm.fSM.TrPoint; +import org.eclipse.etrice.core.fsm.fSM.Transition; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface IFSMDialogFactory { + + ISelectionDialog createMemberSelectionDialog(Shell shell, ModelComponent mc); + ISelectionDialog createMessageSelectionDialog(Shell shell, ModelComponent mc, boolean receiveOnly); + IStatePropertyDialog createStatePropertyDialog(Shell shell, ModelComponent mc, State s, boolean edit); + IChoicePointPropertyDialog createChoicePointPropertyDialog(Shell shell, ChoicePoint cp); + ITransitionPropertyDialog createTransitionPropertyDialog(Shell shell, ModelComponent mc, Transition trans); + ITrPointPropertyDialog createTrPointPropertyDialog(Shell shell, TrPoint tp, boolean subtp); +} diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/ISelectionDialog.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/ISelectionDialog.java new file mode 100644 index 000000000..2709aeaf3 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/ISelectionDialog.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.dialogs; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface ISelectionDialog { + + String getSelected(); + int open(); +} diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/IStatePropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/IStatePropertyDialog.java new file mode 100644 index 000000000..d8db022af --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/IStatePropertyDialog.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.dialogs; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface IStatePropertyDialog { + int open(); +} diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/ITrPointPropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/ITrPointPropertyDialog.java new file mode 100644 index 000000000..5224db913 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/ITrPointPropertyDialog.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.dialogs; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface ITrPointPropertyDialog { + int open(); +} diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/ITransitionPropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/ITransitionPropertyDialog.java new file mode 100644 index 000000000..dcb9582b2 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/ITransitionPropertyDialog.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.dialogs; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface ITransitionPropertyDialog { + int open(); +} diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/QuickFixDialog.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/QuickFixDialog.java index 73222e371..0fe4b4952 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/QuickFixDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/QuickFixDialog.java @@ -10,14 +10,14 @@ * Sebastian Davids <sdavids@gmx.de> - Fix for bug 19346 - Dialog * font should be activated and used by other components. *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.dialogs; +package org.eclipse.etrice.ui.behavior.fsm.dialogs; import java.util.Arrays; import java.util.HashMap; import java.util.List; import org.eclipse.emf.common.util.Diagnostic; -import org.eclipse.etrice.ui.behavior.Activator; +import org.eclipse.etrice.ui.behavior.fsm.Activator; import org.eclipse.etrice.ui.common.base.quickfix.IssueResolution; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -95,12 +95,14 @@ public class QuickFixDialog extends SelectionDialog { createResolutionList(contents); createLabel(contents, DESCRIPTION_AREA_LABEL); - createDescritionArea(contents); + createDescriptionArea(contents); issueList.setInput(this); resolutionsList.setInput(this); - issueList.setSelection( - new StructuredSelection(issueList.getElementAt(0)), true); + if (!issueResolutionsMap.isEmpty()) { + issueList.setSelection( + new StructuredSelection(issueList.getElementAt(0)), true); + } return contents; } @@ -120,7 +122,10 @@ public class QuickFixDialog extends SelectionDialog { @Override public Object[] getElements(Object inputElement) { - return issueResolutionsMap.keySet().toArray(); + if (issueResolutionsMap==null || issueResolutionsMap.keySet()==null) + return new Object[] {}; + else + return issueResolutionsMap.keySet().toArray(); } @Override @@ -137,20 +142,25 @@ public class QuickFixDialog extends SelectionDialog { @Override public String getText(Object element) { - return ((FeatureBasedDiagnostic) element).getMessage(); + if (element instanceof FeatureBasedDiagnostic) { + return ((FeatureBasedDiagnostic) element).getMessage(); + } + return ""; } @Override public Image getImage(Object element) { - switch (((Diagnostic) element).getSeverity()) { - case Diagnostic.ERROR: - return Activator.getImage(ERROR_IMAGE); - - case Diagnostic.WARNING: - return Activator.getImage(WARNING_IMAGE); - - case Diagnostic.INFO: - return Activator.getImage(INFO_IMAGE); + if (element instanceof Diagnostic) { + switch (((Diagnostic) element).getSeverity()) { + case Diagnostic.ERROR: + return Activator.getImage(ERROR_IMAGE); + + case Diagnostic.WARNING: + return Activator.getImage(WARNING_IMAGE); + + case Diagnostic.INFO: + return Activator.getImage(INFO_IMAGE); + } } return null; } @@ -257,7 +267,7 @@ public class QuickFixDialog extends SelectionDialog { return label; } - private Text createDescritionArea(Composite composite) { + private Text createDescriptionArea(Composite composite) { Text text = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); GridData gd = new GridData(GridData.FILL, GridData.BEGINNING, true, false); gd.heightHint = 60; diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StringToDetailCode.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/StringToDetailCode.java index a89f576e7..79cf9822c 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StringToDetailCode.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/dialogs/StringToDetailCode.java @@ -1,4 +1,4 @@ -package org.eclipse.etrice.ui.behavior.dialogs; +package org.eclipse.etrice.ui.behavior.fsm.dialogs; import org.eclipse.core.databinding.conversion.Converter; import org.eclipse.etrice.core.fsm.fSM.DetailCode; diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMEditor.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMEditor.java new file mode 100644 index 000000000..c632c5228 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/AbstractFSMEditor.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.editor; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.transaction.RecordingCommand; +import org.eclipse.etrice.ui.behavior.fsm.support.ContextSwitcher; +import org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase; + +/** + * @author Henrik Rentz-Reichert + * + */ +public abstract class AbstractFSMEditor extends DiagramEditorBase { + + protected DiagnosingModelObserver diagnosingModelObserver; + + /** + * @param textEditorClass + */ + public AbstractFSMEditor(Object textEditorClass) { + super(textEditorClass); + } + + public DiagnosingModelObserver getDiagnosingModelObserver() { + return diagnosingModelObserver; + } + + @Override + public void initializeGraphicalViewer() { + // Start observing the Room Model for rendering Markers + diagnosingModelObserver = new DiagnosingModelObserver(); + diagnosingModelObserver.observeModel(getModel()); + + super.initializeGraphicalViewer(); + + Command cmd = new RecordingCommand(getEditingDomain()) { + @Override + protected void doExecute() { + ContextSwitcher.switchTop(getDiagramTypeProvider().getDiagram()); + } + }; + getEditingDomain().getCommandStack().execute(cmd); + getEditingDomain().getCommandStack().flush(); + } + +} diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DecoratorUtil.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/DecoratorUtil.java index fc5c7ce0a..123d62c81 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DecoratorUtil.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/DecoratorUtil.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.markers; +package org.eclipse.etrice.ui.behavior.fsm.editor; import java.util.ArrayList; import java.util.HashMap; diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DiagnosingModelObserver.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/DiagnosingModelObserver.java index e41b75f56..326456da0 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/markers/DiagnosingModelObserver.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/editor/DiagnosingModelObserver.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.markers; +package org.eclipse.etrice.ui.behavior.fsm.editor; import java.util.ArrayList; import java.util.HashMap; @@ -23,7 +23,6 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.emf.ecore.util.Diagnostician; import org.eclipse.emf.ecore.util.EContentAdapter; -import org.eclipse.etrice.core.room.RoomModel; import org.eclipse.etrice.core.fsm.fSM.StateGraph; import org.eclipse.etrice.core.fsm.fSM.Trigger; import org.eclipse.xtext.validation.FeatureBasedDiagnostic; @@ -47,7 +46,7 @@ public class DiagnosingModelObserver extends EContentAdapter { /** * The {@link RoomModel} being observed. */ - private RoomModel roomModel; + private EObject mdel; public DiagnosingModelObserver() { elementDiagnosticMap = new HashMap<EObject, ArrayList<Diagnostic>>(); @@ -56,13 +55,13 @@ public class DiagnosingModelObserver extends EContentAdapter { /** * Starts listening to changes of the given {@link RoomModel}. * - * @param roomModel + * @param model * @author jayant */ - public void observeRoomModel(RoomModel roomModel) { + public void observeModel(EObject model) { // Start observing the room model - this.roomModel = roomModel; - setTarget(roomModel); + this.mdel = model; + setTarget(model); // Validate and Populate HashMap for rendering markers initially. updateElementDiagonosticMap(); @@ -74,7 +73,7 @@ public class DiagnosingModelObserver extends EContentAdapter { * @author jayant */ public void removeObserver() { - unsetTarget(roomModel); + unsetTarget(mdel); } /** @@ -109,7 +108,7 @@ public class DiagnosingModelObserver extends EContentAdapter { elementDiagnosticMap.clear(); // Perform Model Validation and get the diagnostic - Diagnostic diagnostics = Diagnostician.INSTANCE.validate(roomModel); + Diagnostic diagnostics = Diagnostician.INSTANCE.validate(mdel); // A local HashMap for ensuring uniqueness of diagnostics HashMap<EObject, HashSet<String>> uniqueEnsurer = new HashMap<EObject, HashSet<String>>(); diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/ImageProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/ImageProvider.java index fb8134d8e..7db6971b0 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/ImageProvider.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/ImageProvider.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior; +package org.eclipse.etrice.ui.behavior.fsm.provider; import org.eclipse.graphiti.ui.platform.AbstractImageProvider; diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/InjectingBehaviorProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/InjectingBehaviorProvider.java new file mode 100644 index 000000000..9d2fc4d31 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/InjectingBehaviorProvider.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.provider; + +import org.eclipse.graphiti.dt.IDiagramTypeProvider; +import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider; + +import com.google.inject.Injector; + +/** + * @author Henrik Rentz-Reichert + * + */ +public class InjectingBehaviorProvider extends DefaultToolBehaviorProvider { + + private Injector injector; + + /** + * @param diagramTypeProvider + */ + public InjectingBehaviorProvider(IDiagramTypeProvider diagramTypeProvider, Injector injector) { + super(diagramTypeProvider); + this.injector = injector; + } + + /** + * @return the Guice injector + */ + public Injector getInjector() { + return injector; + } + +} diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/InjectingFeatureProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/InjectingFeatureProvider.java new file mode 100644 index 000000000..bbc90fa9d --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/provider/InjectingFeatureProvider.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.provider; + +import org.eclipse.graphiti.dt.IDiagramTypeProvider; +import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; + +import com.google.inject.Injector; + +/** + * @author Henrik Rentz-Reichert + * + */ +public class InjectingFeatureProvider extends DefaultFeatureProvider { + + private Injector injector; + + /** + * @param dtp + */ + public InjectingFeatureProvider(IDiagramTypeProvider dtp, Injector injector) { + super(dtp); + this.injector = injector; + } + + /** + * @return the Guice injector + */ + public Injector getInjector() { + return injector; + } + +} diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ChoicePointSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/ChoicePointSupport.java index daeefc45e..013a0d9c6 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ChoicePointSupport.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/ChoicePointSupport.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.ArrayList; @@ -19,12 +19,15 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.etrice.core.fsm.fSM.ChoicePoint; import org.eclipse.etrice.core.fsm.fSM.FSMFactory; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.StateGraph; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.ui.behavior.ImageProvider; -import org.eclipse.etrice.ui.behavior.dialogs.ChoicePointPropertyDialog; -import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; -import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IChoicePointPropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory; +import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMEditor; +import org.eclipse.etrice.ui.behavior.fsm.editor.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.provider.ImageProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingBehaviorProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingFeatureProvider; import org.eclipse.etrice.ui.common.base.support.ChangeAwareCreateFeature; import org.eclipse.etrice.ui.common.base.support.ChangeAwareCustomFeature; import org.eclipse.etrice.ui.common.base.support.CommonSupportUtil; @@ -75,18 +78,18 @@ import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.IGaService; import org.eclipse.graphiti.services.IPeCreateService; import org.eclipse.graphiti.tb.ContextButtonEntry; -import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider; import org.eclipse.graphiti.tb.IContextButtonPadData; import org.eclipse.graphiti.tb.IDecorator; import org.eclipse.graphiti.tb.IToolBehaviorProvider; import org.eclipse.graphiti.tb.ImageDecorator; -import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; import org.eclipse.graphiti.util.ColorConstant; import org.eclipse.graphiti.util.IColorConstant; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import com.google.inject.Injector; + public class ChoicePointSupport { public static final int ITEM_SIZE = (int) (StateGraphSupport.MARGIN*0.625); @@ -97,12 +100,12 @@ public class ChoicePointSupport { protected static final IColorConstant BRIGHT_COLOR = new ColorConstant(255, 255, 255); protected static final String PROP_KIND = "item-kind"; - private static class FeatureProvider extends DefaultFeatureProvider { + private static class FeatureProvider extends InjectingFeatureProvider { private static class CreateFeature extends ChangeAwareCreateFeature { - public CreateFeature(IFeatureProvider fp, String name, String description) { - super(fp, name, description); + public CreateFeature(IFeatureProvider fp, Injector injector, String name, String description) { + super(fp, injector, name, description); } @Override @@ -115,20 +118,21 @@ public class ChoicePointSupport { ContainerShape targetContainer = context.getTargetContainer(); StateGraph sg = (StateGraph) targetContainer.getLink().getBusinessObjects().get(0); - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), sg); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), sg); if (inherited) { - sg = SupportUtil.getInstance().insertRefinedState(sg, ac, targetContainer, getFeatureProvider()); + sg = FSMSupportUtil.getInstance().insertRefinedState(sg, ac, targetContainer, getFeatureProvider()); } // create choice point and add it ChoicePoint cp = FSMFactory.eINSTANCE.createChoicePoint(); - cp.setName(SupportUtil.getInstance().getRoomUtil().getUniqueChoicePointName(sg)); + cp.setName(FSMSupportUtil.getInstance().getFSMUtil().getUniqueChoicePointName(sg)); sg.getChPoints().add(cp); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - ChoicePointPropertyDialog dlg = new ChoicePointPropertyDialog(shell, cp); + IFSMDialogFactory factory = getInjector().getInstance(IFSMDialogFactory.class); + IChoicePointPropertyDialog dlg = factory.createChoicePointPropertyDialog(shell, cp); if (dlg.open()==Window.OK) { // do the add addGraphicalRepresentation(context, cp); @@ -176,7 +180,7 @@ public class ChoicePointSupport { public PictogramElement add(IAddContext context) { ChoicePoint cp = (ChoicePoint) context.getNewObject(); ContainerShape sgShape = context.getTargetContainer(); - boolean inherited = SupportUtil.getInstance().isInherited(cp, sgShape); + boolean inherited = FSMSupportUtil.getInstance().isInherited(cp, sgShape); // CONTAINER SHAPE WITH RECTANGLE IPeCreateService peCreateService = Graphiti.getPeCreateService(); @@ -244,7 +248,7 @@ public class ChoicePointSupport { ChoicePoint cp = (ChoicePoint) bo; ContainerShape acShape = context.getTargetContainer(); - if (SupportUtil.getInstance().isInherited(cp, acShape)) + if (FSMSupportUtil.getInstance().isInherited(cp, acShape)) return false; return true; @@ -261,8 +265,8 @@ public class ChoicePointSupport { private String name; private String description; - public PropertyFeature(IFeatureProvider fp) { - super(fp); + public PropertyFeature(IFeatureProvider fp, Injector injector) { + super(fp, injector); this.name = "Edit Choice Point"; this.description = "Edit Choice Point"; } @@ -283,7 +287,7 @@ public class ChoicePointSupport { if (pes != null && pes.length == 1 && pes[0] instanceof ContainerShape) { Object bo = getBusinessObjectForPictogramElement(pes[0]); if (bo instanceof ChoicePoint) { - return !SupportUtil.getInstance().isInherited(getDiagram(), (ChoicePoint)bo); + return !FSMSupportUtil.getInstance().isInherited(getDiagram(), (ChoicePoint)bo); } } return false; @@ -295,7 +299,8 @@ public class ChoicePointSupport { ChoicePoint cp = (ChoicePoint) getBusinessObjectForPictogramElement(pe); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - ChoicePointPropertyDialog dlg = new ChoicePointPropertyDialog(shell, cp); + IFSMDialogFactory factory = getInjector().getInstance(IFSMDialogFactory.class); + IChoicePointPropertyDialog dlg = factory.createChoicePointPropertyDialog(shell, cp); if (dlg.open()==Window.OK){ updateFigure(cp, pe, manageColor(DARK_COLOR), manageColor(BRIGHT_COLOR)); @@ -366,7 +371,7 @@ public class ChoicePointSupport { } ChoicePoint cp = (ChoicePoint) bo; - boolean inherited = SupportUtil.getInstance().isInherited(cp, (ContainerShape)containerShape.eContainer()); + boolean inherited = FSMSupportUtil.getInstance().isInherited(cp, (ContainerShape)containerShape.eContainer()); Color dark = manageColor(inherited? INHERITED_COLOR:DARK_COLOR); updateFigure(cp, containerShape, dark, manageColor(BRIGHT_COLOR)); @@ -398,7 +403,7 @@ public class ChoicePointSupport { if (bo instanceof ChoicePoint) { ChoicePoint cp = (ChoicePoint) bo; - return !SupportUtil.getInstance().isInherited(getDiagram(), cp); + return !FSMSupportUtil.getInstance().isInherited(getDiagram(), cp); } return false; } @@ -413,15 +418,15 @@ public class ChoicePointSupport { protected IFeatureProvider fp; - protected FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) { - super(dtp); + protected FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + super(dtp, injector); this.fp = fp; } @Override public ICreateFeature[] getCreateFeatures() { return new ICreateFeature[] { - new CreateFeature(fp, "Choice Point", "Create Choice Point") + new CreateFeature(fp, getInjector(), "Choice Point", "Create Choice Point") }; } @@ -442,7 +447,7 @@ public class ChoicePointSupport { @Override public ICustomFeature[] getCustomFeatures(ICustomContext context) { - return new ICustomFeature[] { new PropertyFeature(fp) }; + return new ICustomFeature[] { new PropertyFeature(fp, getInjector()) }; } @Override @@ -500,10 +505,10 @@ public class ChoicePointSupport { } - private class BehaviorProvider extends DefaultToolBehaviorProvider { + private class BehaviorProvider extends InjectingBehaviorProvider { - public BehaviorProvider(IDiagramTypeProvider dtp) { - super(dtp); + public BehaviorProvider(IDiagramTypeProvider dtp, Injector injector) { + super(dtp, injector); } @Override @@ -525,7 +530,7 @@ public class ChoicePointSupport { @Override public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) { - return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider()); + return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider(), getInjector()); } @Override @@ -589,7 +594,7 @@ public class ChoicePointSupport { .getBusinessObjectForLinkedPictogramElement(pe); // Get Diagnostics associated with the business object - ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider() + ArrayList<Diagnostic> diagnostics = ((AbstractFSMEditor) getDiagramTypeProvider() .getDiagramBehavior().getDiagramContainer()) .getDiagnosingModelObserver().getElementDiagonsticMap() .get(bo); @@ -617,9 +622,9 @@ public class ChoicePointSupport { private FeatureProvider pfp; private BehaviorProvider tbp; - public ChoicePointSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) { - pfp = new FeatureProvider(dtp,fp); - tbp = new BehaviorProvider(dtp); + public ChoicePointSupport(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + pfp = new FeatureProvider(dtp, fp, injector); + tbp = new BehaviorProvider(dtp, injector); } public IFeatureProvider getFeatureProvider() { diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/Constants.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/Constants.java index d163ed32d..a7d17712c 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/Constants.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/Constants.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; public interface Constants { diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ContextSwitcher.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/ContextSwitcher.java index 479185b2f..211e74efe 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/ContextSwitcher.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/ContextSwitcher.java @@ -1,11 +1,11 @@ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.ArrayList; import java.util.Iterator; import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.room.ActorClass; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.RefinedState; import org.eclipse.etrice.core.fsm.fSM.State; import org.eclipse.etrice.core.fsm.fSM.StateGraph; @@ -22,10 +22,10 @@ public class ContextSwitcher { public static void goUp(Diagram diagram, StateGraph sg) { // if the container is a state we can go up, else we are already on top if (sg.eContainer() instanceof State) { - ActorClass ac = SupportUtil.getInstance().getActorClass(diagram); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(diagram); StateGraph parent = getVirtualParent(sg, ac); - if (parent.eContainer() instanceof ActorClass) + if (parent.eContainer() instanceof ModelComponent) ContextSwitcher.switchTop(diagram); else ContextSwitcher.switchTo(diagram, parent); @@ -37,15 +37,15 @@ public class ContextSwitcher { * @param ac * @return */ - private static StateGraph getVirtualParent(StateGraph sg, ActorClass ac) { + private static StateGraph getVirtualParent(StateGraph sg, ModelComponent ac) { State s = (State) sg.eContainer(); // try to find a RefinedState pointing to the parent of s if (s.eContainer().eContainer() instanceof State) { - ArrayList<ActorClass> hierarchy = new ArrayList<ActorClass>(); + ArrayList<ModelComponent> hierarchy = new ArrayList<ModelComponent>(); do { hierarchy.add(0, ac); - ac = ac.getActorBase(); + ac = ac.getBase(); } while (ac!=null); @@ -55,7 +55,7 @@ public class ContextSwitcher { } // follow the target chain as long as the refined state resides in the top level - while (s instanceof RefinedState && s.eContainer().eContainer() instanceof ActorClass) + while (s instanceof RefinedState && s.eContainer().eContainer() instanceof ModelComponent) s = ((RefinedState)s).getTarget(); return (StateGraph) s.eContainer(); @@ -66,8 +66,8 @@ public class ContextSwitcher { * @param s * @return */ - private static RefinedState getTargetingState(Iterator<ActorClass> acit, State s) { - ActorClass ac = acit.next(); + private static RefinedState getTargetingState(Iterator<ModelComponent> acit, State s) { + ModelComponent ac = acit.next(); TreeIterator<EObject> it = ac.getStateMachine().eAllContents(); while (it.hasNext()) { EObject next = it.next(); @@ -85,8 +85,8 @@ public class ContextSwitcher { public static void switchTop(Diagram diagram) { EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram); - if (bo instanceof ActorClass) { - switchTo(diagram, ((ActorClass) bo).getStateMachine()); + if (bo instanceof ModelComponent) { + switchTo(diagram, ((ModelComponent) bo).getStateMachine()); } } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/DefaultPositionProvider.java index 8b908eec9..36a072fdb 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DefaultPositionProvider.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/DefaultPositionProvider.java @@ -10,24 +10,24 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.naming.RoomNameProvider; -import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.fsm.fSM.ChoicePoint; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.State; import org.eclipse.etrice.core.fsm.fSM.StateGraph; import org.eclipse.etrice.core.fsm.fSM.StateGraphItem; import org.eclipse.etrice.core.fsm.fSM.StateGraphNode; import org.eclipse.etrice.core.fsm.fSM.TrPoint; import org.eclipse.etrice.core.fsm.fSM.Transition; -import org.eclipse.etrice.ui.behavior.DiagramAccess; -import org.eclipse.etrice.ui.behavior.commands.StateGraphContext; +import org.eclipse.etrice.core.fsm.naming.FSMNameProvider; +import org.eclipse.etrice.ui.behavior.fsm.commands.StateGraphContext; +import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase; import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; import org.eclipse.graphiti.mm.algorithms.Text; import org.eclipse.graphiti.mm.algorithms.styles.Point; @@ -40,6 +40,8 @@ import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.ILinkService; +import com.google.inject.Injector; + /** * @author Henrik Rentz-Reichert (initial contribution) * @@ -60,8 +62,8 @@ public class DefaultPositionProvider implements IPositionProvider { private double scaleY; private int posX, posY; - public DefaultPositionProvider(ActorClass ac) { - mapPositions(ac.getActorBase()); + public DefaultPositionProvider(ModelComponent mc, Injector injector) { + mapPositions(mc.getBase(), injector); } /* (non-Javadoc) @@ -80,7 +82,7 @@ public class DefaultPositionProvider implements IPositionProvider { } public PosAndSize getPosition(StateGraphNode node) { - Position pos = obj2pos.get(SupportUtil.getInstance().getRoomNameProvider().getFullPath(node)); + Position pos = obj2pos.get(FSMSupportUtil.getInstance().getFSMNameProvider().getFullPath(node)); if (pos==null) return null; @@ -99,7 +101,7 @@ public class DefaultPositionProvider implements IPositionProvider { EObject container = graph.eContainer(); String path = "#init"; if(container instanceof StateGraphNode) - path = SupportUtil.getInstance().getRoomNameProvider().getFullPath((StateGraphNode)container) + path; + path = FSMSupportUtil.getInstance().getFSMNameProvider().getFullPath((StateGraphNode)container) + path; Position pos = obj2pos.get(path); if (pos==null) @@ -118,7 +120,7 @@ public class DefaultPositionProvider implements IPositionProvider { public List<Pos> getPoints(Transition trans) { ArrayList<Pos> result = new ArrayList<Pos>(); - ArrayList<Position> list = trans2points.get(SupportUtil.getInstance().getRoomNameProvider().getFullPath(trans)); + ArrayList<Position> list = trans2points.get(FSMSupportUtil.getInstance().getFSMNameProvider().getFullPath(trans)); if (list!=null) { int i = 0; for (Position p : list) { @@ -189,19 +191,20 @@ public class DefaultPositionProvider implements IPositionProvider { * * Positions are relative to the invisible rectangle. They are transformed to the border rectangle and normalized. * - * @param ac + * @param mc * @param obj2pos */ - private void mapPositions(ActorClass ac) { - if (ac==null) + private void mapPositions(ModelComponent mc, Injector injector) { + if (mc==null) return; - Diagram diagram = new DiagramAccess().getDiagram(ac); + DiagramAccessBase diagramAccess = injector.getInstance(DiagramAccessBase.class); + Diagram diagram = diagramAccess.getDiagram(mc); if (diagram==null) return; - StateGraphContext tree = StateGraphContext.createContextTree(SupportUtil.getInstance().getActorClass(diagram)); - RoomNameProvider roomNameProvider = SupportUtil.getInstance().getRoomNameProvider(); + StateGraphContext tree = StateGraphContext.createContextTree(FSMSupportUtil.getInstance().getModelComponent(diagram), injector); + FSMNameProvider roomNameProvider = FSMSupportUtil.getInstance().getFSMNameProvider(); ILinkService linkService = Graphiti.getLinkService(); for (Shape sgShape : diagram.getChildren()) { @@ -283,7 +286,7 @@ public class DefaultPositionProvider implements IPositionProvider { } // recursion - mapPositions(ac.getActorBase()); + mapPositions(mc.getBase(), injector); } private int getMargin(StateGraphNode node) { @@ -303,7 +306,7 @@ public class DefaultPositionProvider implements IPositionProvider { EObject container = graph.eContainer(); String path = "#init"; if(container instanceof StateGraphNode) - path = SupportUtil.getInstance().getRoomNameProvider().getFullPath((StateGraphNode)container) + path; + path = FSMSupportUtil.getInstance().getFSMNameProvider().getFullPath((StateGraphNode)container) + path; return initialPointObj.get(path); } @@ -312,6 +315,6 @@ public class DefaultPositionProvider implements IPositionProvider { */ @Override public PosAndSize getGraphPosAndSize(StateGraph sg) { - return sg2sz.get(SupportUtil.getInstance().getRoomNameProvider().getFullPath(sg)); + return sg2sz.get(FSMSupportUtil.getInstance().getFSMNameProvider().getFullPath(sg)); } } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DiagramUpdateFeature.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/DiagramUpdateFeature.java index cb22bd891..bcc4d7a58 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/DiagramUpdateFeature.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/DiagramUpdateFeature.java @@ -10,13 +10,14 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.ArrayList; -import org.eclipse.etrice.core.room.ActorClass; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.StateGraph; -import org.eclipse.etrice.ui.behavior.commands.StateGraphContext; +import org.eclipse.etrice.ui.behavior.fsm.commands.StateGraphContext; +import org.eclipse.etrice.ui.behavior.fsm.support.StateGraphUpdateContext; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.IReason; import org.eclipse.graphiti.features.IRemoveFeature; @@ -32,6 +33,8 @@ import org.eclipse.graphiti.mm.pictograms.ContainerShape; import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.platform.IDiagramBehavior; +import com.google.inject.Injector; + /** * @author Henrik Rentz-Reichert (initial contribution) * @@ -39,12 +42,14 @@ import org.eclipse.graphiti.platform.IDiagramBehavior; public class DiagramUpdateFeature extends AbstractUpdateFeature { private ArrayList<Shape> usedShapes = new ArrayList<Shape>(); + private Injector injector; /** * @param fp */ - public DiagramUpdateFeature(IFeatureProvider fp) { + public DiagramUpdateFeature(IFeatureProvider fp, Injector injector) { super(fp); + this.injector = injector; } /* (non-Javadoc) @@ -60,8 +65,8 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature { */ @Override public IReason updateNeeded(IUpdateContext context) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); - StateGraphContext tree = StateGraphContext.createContextTree(ac); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); + StateGraphContext tree = StateGraphContext.createContextTree(ac, injector); usedShapes.clear(); @@ -104,8 +109,8 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature { */ @Override public boolean update(IUpdateContext context) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); - StateGraphContext tree = StateGraphContext.createContextTree(ac); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); + StateGraphContext tree = StateGraphContext.createContextTree(ac, injector); usedShapes.clear(); @@ -206,7 +211,7 @@ public class DiagramUpdateFeature extends AbstractUpdateFeature { ContainerShape cont = findStateGraphContainer(sg); if (cont==null) { // create - cont = SupportUtil.getInstance().addStateGraph(ctx, getDiagram(), getFeatureProvider()); + cont = FSMSupportUtil.getInstance().addStateGraph(ctx, getDiagram(), getFeatureProvider()); changed = true; usedShapes.add(cont); } diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/FSMSupportUtil.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/FSMSupportUtil.java new file mode 100644 index 000000000..c9e625113 --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/FSMSupportUtil.java @@ -0,0 +1,958 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.support; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.ResourceSet; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.etrice.core.fsm.fSM.ChoicePoint; +import org.eclipse.etrice.core.fsm.fSM.ChoicepointTerminal; +import org.eclipse.etrice.core.fsm.fSM.EntryPoint; +import org.eclipse.etrice.core.fsm.fSM.ExitPoint; +import org.eclipse.etrice.core.fsm.fSM.FSMFactory; +import org.eclipse.etrice.core.fsm.fSM.InitialTransition; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; +import org.eclipse.etrice.core.fsm.fSM.NonInitialTransition; +import org.eclipse.etrice.core.fsm.fSM.RefinedState; +import org.eclipse.etrice.core.fsm.fSM.State; +import org.eclipse.etrice.core.fsm.fSM.StateGraph; +import org.eclipse.etrice.core.fsm.fSM.StateGraphItem; +import org.eclipse.etrice.core.fsm.fSM.StateGraphNode; +import org.eclipse.etrice.core.fsm.fSM.StateTerminal; +import org.eclipse.etrice.core.fsm.fSM.SubStateTrPointTerminal; +import org.eclipse.etrice.core.fsm.fSM.TrPoint; +import org.eclipse.etrice.core.fsm.fSM.TrPointTerminal; +import org.eclipse.etrice.core.fsm.fSM.Transition; +import org.eclipse.etrice.core.fsm.fSM.TransitionTerminal; +import org.eclipse.etrice.core.fsm.naming.FSMNameProvider; +import org.eclipse.etrice.core.fsm.ui.FSMUiModule; +import org.eclipse.etrice.core.fsm.util.FSMHelpers; +import org.eclipse.etrice.core.fsm.util.FSMUtil; +import org.eclipse.etrice.core.fsm.validation.FSMValidationUtil; +import org.eclipse.etrice.ui.behavior.fsm.commands.StateGraphContext; +import org.eclipse.etrice.ui.behavior.fsm.support.ContextSwitcher; +import org.eclipse.etrice.ui.behavior.fsm.support.IPositionProvider; +import org.eclipse.etrice.ui.behavior.fsm.support.IPositionProvider.Pos; +import org.eclipse.etrice.ui.behavior.fsm.support.IPositionProvider.PosAndSize; +import org.eclipse.etrice.ui.common.base.support.CommonSupportUtil; +import org.eclipse.graphiti.datatypes.ILocation; +import org.eclipse.graphiti.features.IFeatureProvider; +import org.eclipse.graphiti.features.context.impl.AddConnectionContext; +import org.eclipse.graphiti.features.context.impl.AddContext; +import org.eclipse.graphiti.features.context.impl.LayoutContext; +import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; +import org.eclipse.graphiti.mm.algorithms.styles.Point; +import org.eclipse.graphiti.mm.pictograms.Anchor; +import org.eclipse.graphiti.mm.pictograms.Connection; +import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; +import org.eclipse.graphiti.mm.pictograms.ContainerShape; +import org.eclipse.graphiti.mm.pictograms.Diagram; +import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; +import org.eclipse.graphiti.mm.pictograms.PictogramElement; +import org.eclipse.graphiti.mm.pictograms.Shape; +import org.eclipse.graphiti.services.Graphiti; +import org.eclipse.graphiti.services.IGaService; +import org.eclipse.graphiti.services.ILinkService; + +import com.google.inject.Inject; +import com.google.inject.Injector; + +/** + * @author Henrik Rentz-Reichert + * + */ +public class FSMSupportUtil { + + private static final String INITIAL = "init"; + private static final String STATE = "state:"; + private static final String TP = "tp:"; + private static final String CP = "cp:"; + private static final String SEP = "."; + private static FSMSupportUtil instance = null; + + /** + * @return the instance + */ + public static FSMSupportUtil getInstance() { + if (instance==null) { + // this class has members that have to be filled by the FSMUi injector + Injector injector = FSMUiModule.getInjector(); + instance = injector.getInstance(FSMSupportUtil.class); + } + return instance; + } + + @Inject + private FSMHelpers fsmHelpers; + @Inject + private FSMValidationUtil fsmValidationUtil; + @Inject + private FSMNameProvider fsmNameProvider; + @Inject + private FSMUtil fsmUtil; + + /** + * @return the roomHelpers + */ + public FSMHelpers getFSMHelpers() { + return fsmHelpers; + } + + /** + * @return the validationUtil + */ + public FSMValidationUtil getFSMValidationUtil() { + return fsmValidationUtil; + } + + /** + * @return the roomUtil + */ + public FSMUtil getFSMUtil() { + return fsmUtil; + } + + /** + * @return the roomNameProvider + */ + public FSMNameProvider getFSMNameProvider() { + return fsmNameProvider; + } + + public EObject getOwnObject(EObject obj, ResourceSet rs) { + URI uri = EcoreUtil.getURI(obj); + EObject own = rs.getEObject(uri, true); + assert(own!=null): "own object must exist"; + return own; + } + + public boolean isInherited(StateGraphItem item, ContainerShape cs) { + EObject container = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(cs); + if (container instanceof StateGraph) { + StateGraph sg = (StateGraph) container; + return item.eContainer()!=sg; + } + else if (container instanceof State) { + assert(item instanceof EntryPoint || item instanceof ExitPoint): "this MUST be an entry or exit point"; + + // have to check whether the State is inherited + State s = (State) container; + ContainerShape sCont = cs.getContainer(); + EObject cls = sCont.getLink().getBusinessObjects().get(0); + return s.eContainer()!=cls; + } + + return false; + } + + public boolean isInherited(Diagram diag, EObject obj) { + return fsmHelpers.getModelComponent(obj)!=getModelComponent(diag); + } + + public boolean showAsInherited(Diagram diag, State obj) { + + if (obj instanceof RefinedState) + return true; + + return fsmHelpers.getModelComponent(obj)!=getModelComponent(diag); + } + + public Diagram getDiagram(GraphicsAlgorithm ga) { + if (ga.eContainer() instanceof GraphicsAlgorithm) + return getDiagram((GraphicsAlgorithm)ga.eContainer()); + return getDiagram(ga.getPictogramElement()); + } + + /** + * @param pictogramElement + * @return + */ + public Diagram getDiagram(PictogramElement pe) { + while (pe.eContainer()!=null) { + if (pe.eContainer() instanceof Diagram) + return (Diagram) pe.eContainer(); + pe = (PictogramElement) pe.eContainer(); + } + return null; + } + + public ModelComponent getModelComponent(Diagram diag) { + EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diag); + if (bo instanceof ModelComponent) + return (ModelComponent) bo; + return null; + } + + /** + * @param sg + * @param ac + * @param targetContainer + * @param fp + * @return + */ + public StateGraph insertRefinedState(StateGraph sg, ModelComponent ac, ContainerShape targetContainer, + IFeatureProvider fp) { + sg = getSubGraphOfRefinedStateFor((State) sg.eContainer(), ac); + fp.link(targetContainer, sg); + return sg; + } + + /** + * @param sg + * @param ac + * @param targetContainer + */ + public void undoInsertRefinedState(StateGraph sg, ModelComponent ac, + ContainerShape targetContainer, IFeatureProvider fp) { + RefinedState rs = (RefinedState) sg.eContainer(); + fp.link(targetContainer, rs.getTarget().getSubgraph()); + + if (!(fsmHelpers.hasDetailCode(rs.getEntryCode()) || fsmHelpers.hasDetailCode(rs.getExitCode()))) { + ac.getStateMachine().getStates().remove(rs); + } + } + + /** + * @param s + * @param ac + * @return + */ + public StateGraph getSubGraphOfRefinedStateFor(State s, ModelComponent ac) { + RefinedState rs = getRefinedStateFor(s, ac); + + if (rs.getSubgraph()==null) + rs.setSubgraph(FSMFactory.eINSTANCE.createStateGraph()); + + return rs.getSubgraph(); + } + + public RefinedState getRefinedStateFor(State s, ModelComponent ac) { + HashMap<State, RefinedState> target2rs = new HashMap<State, RefinedState>(); + for (State st : ac.getStateMachine().getStates()) { + if (st instanceof RefinedState) + target2rs.put(((RefinedState) st).getTarget(), (RefinedState) st); + } + + RefinedState rs = null; + + // do we already have a RefinedState pointing to s? + if (target2rs.containsKey(s)) { + rs = target2rs.get(s); + } + else { + // we have to create one and place it in the best fitting context + StateGraph sg = null; + State parent = s; + while (parent.eContainer().eContainer() instanceof State) { + parent = (State) s.eContainer().eContainer(); + if (target2rs.containsKey(parent)) { + RefinedState bestFitting = target2rs.get(parent); + if (bestFitting.getSubgraph()==null) + bestFitting.setSubgraph(FSMFactory.eINSTANCE.createStateGraph()); + sg = bestFitting.getSubgraph(); + break; + } + } + + if (sg==null) + sg = ac.getStateMachine(); + + rs = FSMFactory.eINSTANCE.createRefinedState(); + rs.setTarget(s); + sg.getStates().add(rs); + } + return rs; + } + + /** + * @param state + * @param diagram + * @return + */ + public State getTargettingState(State state, Diagram diagram) { + ModelComponent ac = getModelComponent(diagram); + return fsmHelpers.getTargettingState(state, ac); + } + + /** + * This method exploits the fact that the immediate children of the diagram are + * associated with the state graphs. + * + * @param shape + * @return the container shape that is associated with the state graph of the diagram + */ + public ContainerShape getStateGraphContainer(ContainerShape shape) { + while (shape!=null) { + ContainerShape parent = shape.getContainer(); + if (parent instanceof Diagram) + return shape; + shape = parent; + } + return null; + } + + public StateGraph getStateGraph(ContainerShape cs, IFeatureProvider fp) { + ContainerShape shape = getStateGraphContainer(cs); + Object bo = fp.getBusinessObjectForPictogramElement(shape); + if (bo instanceof StateGraph) + return (StateGraph) bo; + else + assert(false): "state graph expected"; + + return null; + } + + public TransitionTerminal getTransitionTerminal(Anchor anchor, IFeatureProvider fp) { + if (anchor != null) { + Object obj = fp.getBusinessObjectForPictogramElement(anchor.getParent()); + if (obj instanceof TrPoint) { + Object parent = fp.getBusinessObjectForPictogramElement((ContainerShape) anchor.getParent().eContainer()); + if (parent instanceof State) { + State state = (parent instanceof RefinedState)? ((RefinedState)parent).getTarget() : (State)parent; + SubStateTrPointTerminal sstpt = FSMFactory.eINSTANCE.createSubStateTrPointTerminal(); + sstpt.setState(state); + sstpt.setTrPoint((TrPoint) obj); + return sstpt; + } + else { + TrPointTerminal tpt = FSMFactory.eINSTANCE.createTrPointTerminal(); + tpt.setTrPoint((TrPoint) obj); + return tpt; + } + } + else if (obj instanceof State) { + State state = (obj instanceof RefinedState)? ((RefinedState)obj).getTarget() : (State)obj; + StateTerminal st = FSMFactory.eINSTANCE.createStateTerminal(); + st.setState(state); + return st; + } + else if (obj instanceof ChoicePoint) { + ChoicepointTerminal ct = FSMFactory.eINSTANCE.createChoicepointTerminal(); + ct.setCp((ChoicePoint) obj); + return ct; + } + } + return null; + } + + public boolean isInitialPoint(Anchor anchor, IFeatureProvider fp) { + if (anchor!=null) { + Object obj = fp.getBusinessObjectForPictogramElement(anchor.getParent()); + if (obj instanceof StateGraph) { + Object parent = fp.getBusinessObjectForPictogramElement((ContainerShape) anchor.getParent().eContainer()); + if (parent instanceof StateGraph) + return true; + } + } + return false; + } + + public boolean canConnect(Anchor asrc, Anchor atgt, ContainerShape cs, IFeatureProvider fp) { + return canConnect(asrc, atgt, null, cs, fp); + } + + public boolean canConnect(Anchor asrc, Anchor atgt, Transition trans, + ContainerShape cs, IFeatureProvider fp) { + TransitionTerminal src = getTransitionTerminal(asrc, fp); + TransitionTerminal tgt = getTransitionTerminal(atgt, fp); + + if (src==null && !isInitialPoint(asrc, fp)) + return false; + if (tgt==null) + return false; + + StateGraph sg = getStateGraph(cs, fp); + if (sg==null) + return false; + + return fsmValidationUtil.isConnectable(src, tgt, trans, sg).isOk(); + } + + /** + * @param s the state whose sub structure should be deleted + * @param ac the ModelComponent + * @param diagram the current diagram + * @param fp the feature provider + */ + public void deleteSubStructureRecursive(State s, ModelComponent ac, + Diagram diagram, IFeatureProvider fp) { + if (fsmHelpers.hasSubStructure(s, ac)) { + StateGraph subgraph = s.getSubgraph(); + + // depth first + for (State st : subgraph.getStates()) { + deleteSubStructureRecursive(st, ac, diagram, fp); + } + + ContainerShape subShape = ContextSwitcher.getContext(diagram, subgraph); + CommonSupportUtil.deleteConnectionsRecursive(subShape, fp); + EcoreUtil.delete(subShape, true); + } + } + + public List<State> getStates(ContainerShape shape, IFeatureProvider fp) { + return getStates(shape, fp, null, null); + } + + private List<State> getStates(ContainerShape shape, IFeatureProvider fp, Map<String, Anchor> item2anchor, List<Shape> stateShapes) { + List<State> items = new ArrayList<State>(); + for (Shape ch : shape.getChildren()) { + Object bo = fp.getBusinessObjectForPictogramElement(ch); + if (bo instanceof State) { + items.add((State)bo); + if (item2anchor!=null) + item2anchor.put(getKey((State)bo), ch.getAnchors().get(0)); + if (stateShapes!=null) + stateShapes.add(ch); + } + } + return items; + } + + public List<ChoicePoint> getChoicePoints(ContainerShape shape, IFeatureProvider fp) { + return getChoicePoints(shape, fp, null, null); + } + + private List<ChoicePoint> getChoicePoints(ContainerShape shape, IFeatureProvider fp, Map<String, Anchor> item2anchor, + List<Shape> cpShapes) { + List<ChoicePoint> items = new ArrayList<ChoicePoint>(); + for (Shape ch : shape.getChildren()) { + Object bo = fp.getBusinessObjectForPictogramElement(ch); + if (bo instanceof ChoicePoint) { + items.add((ChoicePoint)bo); + if (item2anchor!=null) + item2anchor.put(getKey((ChoicePoint)bo), ch.getAnchors().get(0)); + if (cpShapes!=null) + cpShapes.add(ch); + } + } + return items; + } + + public List<TrPoint> getTrPoints(StateGraph sg, ContainerShape shape, IFeatureProvider fp) { + return getTrPoints(sg, shape, fp, null, null); + } + + private List<TrPoint> getTrPoints(StateGraph sg, ContainerShape shape, IFeatureProvider fp, + Map<String, Anchor> item2anchor, List<Shape> tpShapes) { + List<TrPoint> items = new ArrayList<TrPoint>(); + for (Shape ch : shape.getChildren()) { + Object bo = fp.getBusinessObjectForPictogramElement(ch); + if (bo instanceof TrPoint) { + items.add((TrPoint)bo); + if (item2anchor!=null) + item2anchor.put(getKey((TrPoint)bo), ch.getAnchors().get(0)); + if (tpShapes!=null) + tpShapes.add(ch); + } + } + return items; + } + + /** + * @param diagram + * @param fp + * @return + */ + public List<Transition> getTransitions(Diagram diagram, IFeatureProvider fp) { + List<Transition> transitions = new ArrayList<Transition>(); + for (Connection conn : diagram.getConnections()) { + Object bo = fp.getBusinessObjectForPictogramElement(conn); + if (bo instanceof Transition) + transitions.add((Transition) bo); + } + return transitions; + } + + private Map<Transition, Connection> getTransitionsMap(ContainerShape sgShape, IFeatureProvider fp) { + Diagram diagram = (Diagram) sgShape.eContainer(); + Map<Transition, Connection> transitions = new HashMap<Transition, Connection>(); + for (Connection conn : diagram.getConnections()) { + Object bo = fp.getBusinessObjectForPictogramElement(conn); + + // we only collect connections that have a starting point contained in our sgShape + if (bo instanceof Transition && EcoreUtil.isAncestor(sgShape, conn.getStart())) + transitions.put((Transition) bo, conn); + } + return transitions; + } + + /** + * @param sgShape + * @param node2anchor + */ + private void getSubTpAnchors(ContainerShape sgShape, HashMap<String, Anchor> node2anchor) { + for (Shape childShape : sgShape.getChildren()) { + EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(childShape); + if (bo instanceof State) + getAnchors((State) bo, childShape, node2anchor); + } + } + + public ContainerShape addStateGraph(StateGraphContext ctx, Diagram diagram, IFeatureProvider fp) { + AddContext addContext = new AddContext(); + addContext.setNewObject(ctx.getStateGraph()); + addContext.setTargetContainer(diagram); + PosAndSize graphPosAndSize = ctx.getPositionProvider().getGraphPosAndSize(ctx.getStateGraph()); + if (graphPosAndSize!=null) { + addContext.setX(graphPosAndSize.getX()); + addContext.setY(graphPosAndSize.getY()); + addContext.setWidth(graphPosAndSize.getWidth()); + addContext.setHeight(graphPosAndSize.getHeight()); + } + else { + addContext.setX(StateGraphSupport.MARGIN); + addContext.setY(StateGraphSupport.MARGIN); + } + + ContainerShape sgShape = (ContainerShape) fp.addIfPossible(addContext); + if (sgShape==null) + return null; + + final HashMap<String, Anchor> node2anchor = new HashMap<String, Anchor>(); + + GraphicsAlgorithm borderRect = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0); + ctx.getPositionProvider().setScale(borderRect.getWidth(), borderRect.getHeight()); + ctx.getPositionProvider().setPosition(sgShape.getGraphicsAlgorithm().getX(), sgShape.getGraphicsAlgorithm().getY()); + + addInitialPointIff(ctx, ctx.getPositionProvider(), sgShape, fp, node2anchor); + addStateGraphNodes(ctx.getTrPoints(), ctx.getPositionProvider(), sgShape, fp, node2anchor); + addStateGraphNodes(ctx.getStates(), ctx.getPositionProvider(), sgShape, fp, node2anchor); + addStateGraphNodes(ctx.getChPoints(), ctx.getPositionProvider(), sgShape, fp, node2anchor); + + for (StateGraphContext sub : ctx.getChildren()) { + addStateGraph(sub, diagram, fp); + } + + getSubTpAnchors(sgShape, node2anchor); + + addTransitions(ctx.getTransitions(), ctx.getPositionProvider(), sgShape, fp, node2anchor); + + return sgShape; + } + + private void addInitialPointIff(StateGraphContext ctx, IPositionProvider positionProvider, ContainerShape sgShape, + IFeatureProvider fp, HashMap<String, Anchor> node2anchor) { + + // model + StateGraph sg = ctx.getInitialPoint(); + if(sg==null) + // (super class) diagram + sg = positionProvider.getInitialPoint(ctx.getStateGraph()); + if(sg==null) + return; + + PosAndSize pos = positionProvider.getPosition(sg); + AddContext addContext = new AddContext(); + addContext.setNewObject(sg); + addContext.setTargetContainer(sgShape); + if(pos != null){ + addContext.setX(pos.getX()); + addContext.setY(pos.getY()); + if (pos.getWidth()>0 && pos.getHeight()>0) { + addContext.setWidth(pos.getWidth()); + addContext.setHeight(pos.getHeight()); + } + } else { + addContext.setX(3*StateGraphSupport.MARGIN); + addContext.setY(3*StateGraphSupport.MARGIN); + } + + ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext); + assert(pe!=null): "initial point should have been created"; + assert(!pe.getAnchors().isEmpty()): "initial point should have an anchor"; + node2anchor.put(INITIAL, pe.getAnchors().get(0)); + } + + public void updateStateGraph(StateGraph sg, StateGraphContext ctx, ContainerShape sgShape, + IFeatureProvider fp) { + + HashMap<String, Anchor> node2anchor = new HashMap<String, Anchor>(); + + GraphicsAlgorithm borderRect = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0); + ctx.getPositionProvider().setScale(borderRect.getWidth(), borderRect.getHeight()); + ctx.getPositionProvider().setPosition(sgShape.getGraphicsAlgorithm().getX(), sgShape.getGraphicsAlgorithm().getY()); + + // states + { + ArrayList<Shape> shapes = new ArrayList<Shape>(); + List<State> present = getStates(sgShape, fp, node2anchor, shapes); + checkDuplicates(present); + List<State> expected = ctx.getStates(); + List<State> toAdd = new ArrayList<State>(); + List<State> toUpdate = new ArrayList<State>(); + for (State item : expected) { + if (present.contains(item)) + toUpdate.add(item); + else + toAdd.add(item); + } + addStateGraphNodes(toAdd, ctx.getPositionProvider(), sgShape, fp, node2anchor); + updateStateGraphNodes(toUpdate, shapes, ctx.getPositionProvider(), fp); + } + + // transition points + { + ArrayList<Shape> shapes = new ArrayList<Shape>(); + List<TrPoint> present = getTrPoints(sg, sgShape, fp, node2anchor, shapes); + checkDuplicates(present); + List<TrPoint> expected = ctx.getTrPoints(); + List<TrPoint> toAdd = new ArrayList<TrPoint>(); + List<TrPoint> toUpdate = new ArrayList<TrPoint>(); + for (TrPoint item : expected) { + if (present.contains(item)) + toUpdate.add(item); + else + toAdd.add(item); + } + addStateGraphNodes(toAdd, ctx.getPositionProvider(), sgShape, fp, node2anchor); + updateStateGraphNodes(toUpdate, shapes, ctx.getPositionProvider(), fp); + } + + // choice points + { + ArrayList<Shape> shapes = new ArrayList<Shape>(); + List<ChoicePoint> present = getChoicePoints(sgShape, fp, node2anchor, shapes); + checkDuplicates(present); + List<ChoicePoint> expected = ctx.getChPoints(); + List<ChoicePoint> toAdd = new ArrayList<ChoicePoint>(); + List<ChoicePoint> toUpdate = new ArrayList<ChoicePoint>(); + for (ChoicePoint item : expected) { + if (present.contains(item)) + toUpdate.add(item); + else + toAdd.add(item); + } + addStateGraphNodes(toAdd, ctx.getPositionProvider(), sgShape, fp, node2anchor); + updateStateGraphNodes(toUpdate, shapes, ctx.getPositionProvider(), fp); + } + + getSubTpAnchors(sgShape, node2anchor); + + // initial point + { + // exists in this diagram ? + Shape present = null; + for (Shape ch : sgShape.getChildren()) { + Object bo = fp.getBusinessObjectForPictogramElement(ch); + if (bo instanceof StateGraph) + present = ch; + } + if(present != null) + node2anchor.put(INITIAL, present.getAnchors().get(0)); + // exists in model ? + StateGraph expected = ctx.getInitialPoint(); + if(expected == null) + // exists in (super class) diagram ? + expected = ctx.getPositionProvider().getInitialPoint(ctx.getStateGraph()); + if(expected != null && present == null) + addInitialPointIff(ctx, ctx.getPositionProvider(), sgShape, fp, node2anchor); + else + updateInitialPoint(present, ctx.getPositionProvider(), fp); + } + + // transitions + { + // get transitions that belong to our state graph + // (for other connections we might not have the node anchors yet) + Map<Transition, Connection> present = getTransitionsMap(sgShape, fp); + List<Transition> expected = ctx.getTransitions(); + List<Transition> toAdd = new ArrayList<Transition>(); + for (Transition trans : expected) + if (!present.containsKey(trans)) + toAdd.add(trans); + + addTransitions(toAdd, ctx.getPositionProvider(), sgShape, fp, node2anchor); + updateTransitions(present, ctx.getPositionProvider(), sgShape, fp, node2anchor); + } + } + + /** + * @param items + */ + private void checkDuplicates(List<? extends StateGraphItem> items) { + for (StateGraphItem item : items) { + if (items.indexOf(item)!=items.lastIndexOf(item)) { + Assert.isTrue( + items.indexOf(item)==items.lastIndexOf(item), + "multiple occurrences of "+fsmNameProvider.getFullPath(item)); + } + } + } + + private void addTransitions(List<Transition> transitions, IPositionProvider positionProvider, ContainerShape sgShape, + IFeatureProvider fp, HashMap<String, Anchor> node2anchor) { + + for (Transition trans : transitions) { + String from = (trans instanceof InitialTransition)? INITIAL:getKey(((NonInitialTransition)trans).getFrom()); + String to = getKey(trans.getTo()); + Anchor src = node2anchor.get(from); + Anchor dst = node2anchor.get(to); + + assert(src!=null && dst!=null): "transition endpoints must be present"; + + AddConnectionContext context = new AddConnectionContext(src, dst); + context.setNewObject(trans); + PictogramElement pe = fp.addIfPossible(context); + if (pe instanceof FreeFormConnection) { + FreeFormConnection conn = (FreeFormConnection) pe; + + // JH: workaround for correct bend points of inherited self transition + conn.getBendpoints().clear(); + + List<Pos> points = positionProvider.getPoints(trans); + if (points!=null && !points.isEmpty()) { + Iterator<Pos> it = points.iterator(); + + // first is label position + Pos pos = it.next(); + ConnectionDecorator cd = conn.getConnectionDecorators().get(1); + Graphiti.getGaService().setLocation(cd.getGraphicsAlgorithm(), pos.getX(), pos.getY()); + + // remaining are bend points + while (it.hasNext()) { + pos = it.next(); + Point pt = Graphiti.getGaService().createPoint(pos.getX(), pos.getY()); + conn.getBendpoints().add(pt); + } + } + else if (src==dst) { + ILocation begin = Graphiti.getPeService().getLocationRelativeToDiagram(conn.getStart()); + Point pt = Graphiti.getGaService().createPoint(begin.getX(), begin.getY()+StateGraphSupport.MARGIN*3); + conn.getBendpoints().add(pt); + } + } + } + } + + private void addStateGraphNodes(List<? extends StateGraphNode> nodes, IPositionProvider positionProvider, ContainerShape sgShape, + IFeatureProvider fp, HashMap<String, Anchor> node2anchor) { + + List<PosAndSize> positions = positionProvider.getPositions(nodes); + + int idx = 0; + for (StateGraphNode node : nodes) { + addStateGraphNode(node, sgShape, positions.get(idx), fp, node2anchor); + ++idx; + } + } + + private void addStateGraphNode(StateGraphNode tp, ContainerShape sgShape, PosAndSize pos, + IFeatureProvider fp, HashMap<String, Anchor> node2anchor) { + AddContext addContext = new AddContext(); + addContext.setNewObject(tp); + addContext.setTargetContainer(sgShape); + addContext.setX(pos.getX()); + addContext.setY(pos.getY()); + if (pos.getWidth()>0 && pos.getHeight()>0) { + addContext.setWidth(pos.getWidth()); + addContext.setHeight(pos.getHeight()); + } + + ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext); + assert(pe!=null): tp.eClass().getName()+" should have been created"; + assert(!pe.getAnchors().isEmpty()): tp.eClass().getName()+" should have an anchor"; + node2anchor.put(getKey(tp), pe.getAnchors().get(0)); + } + + private void updateInitialPoint(Shape shape, IPositionProvider positionProvider, IFeatureProvider fp) { + if (shape==null) + return; + + StateGraph sg = (StateGraph) fp.getBusinessObjectForPictogramElement(shape); + PosAndSize ps = positionProvider.getPosition(sg); + if (ps==null) + return; + + // relocate and resize the invisible rectangle + GraphicsAlgorithm ga = shape.getGraphicsAlgorithm(); + + Graphiti.getLayoutService().setLocationAndSize( + ga, + ps.getX(), + ps.getY(), + ps.getWidth(), + ps.getHeight() + ); + + // have to call the layout to adjust the visible border + LayoutContext lc = new LayoutContext(shape); + fp.layoutIfPossible(lc); + } + + private void updateStateGraphNodes(List<? extends StateGraphNode> nodes, List<Shape> shapes, + IPositionProvider positionProvider, IFeatureProvider fp) { + + ILinkService linkService = Graphiti.getLinkService(); + IGaService gaService = Graphiti.getGaService(); + + for (StateGraphNode node : nodes) { + PosAndSize ps = positionProvider.getPosition(node); + if (ps==null) + continue; + + // TODO: sub-optimal since quadratic effort - use combined list for nodes and shapes or similar solution + for (Shape shape : shapes) { + EObject bo = linkService.getBusinessObjectForLinkedPictogramElement(shape); + if (bo==node) { + // relocate and resize the invisible rectangle + GraphicsAlgorithm ga = shape.getGraphicsAlgorithm(); + // System.out.println(RoomNameProvider.getFullPath(node)+": "+ga.getX()+" "+ga.getY()+" "+ga.getWidth()+" "+ga.getHeight()); + // System.out.println(" -> "+ps.getX()+" "+ps.getY()+" "+ps.getWidth()+" "+ps.getHeight()); + + int margin = 0; + if (node instanceof State) + margin = StateSupport.MARGIN; + else if (node instanceof TrPoint) + margin = TrPointSupport.MARGIN; + + gaService.setLocationAndSize( + ga, + ps.getX()-margin, + ps.getY()-margin, + ps.getWidth()+2*margin, + ps.getHeight()+2*margin + ); + + // have to call the layout to adjust the visible border + LayoutContext lc = new LayoutContext(shape); + fp.layoutIfPossible(lc); + break; + } + } + } + } + + private void updateTransitions(Map<Transition, Connection> transitions, IPositionProvider positionProvider, ContainerShape sgShape, + IFeatureProvider fp, HashMap<String, Anchor> node2anchor) { + + for(Entry<Transition, Connection> e: transitions.entrySet()){ + Transition trans = e.getKey(); + Connection conn = e.getValue(); + + String from = (trans instanceof InitialTransition)? INITIAL:getKey(((NonInitialTransition)trans).getFrom()); + String to = getKey(trans.getTo()); + Anchor newSrc = node2anchor.get(from); + Anchor newDst = node2anchor.get(to); + + assert(newSrc!=null && newDst!=null): "transition endpoints must be present"; + + if(conn.getStart()!=newSrc) + conn.setStart(newSrc); + if(conn.getEnd()!=newDst) + conn.setEnd(newDst); + + List<Pos> points = positionProvider.getPoints(trans); + Iterator<Pos> it = points.iterator(); + if (points==null || points.isEmpty()) + continue; + + // first is label position + Pos pos = it.next(); + ConnectionDecorator cd = conn.getConnectionDecorators().get(1); + Graphiti.getGaService().setLocation(cd.getGraphicsAlgorithm(), pos.getX(), pos.getY()); + + if (conn instanceof FreeFormConnection) { + FreeFormConnection fconn = (FreeFormConnection) conn; + + // remaining are bend points + fconn.getBendpoints().clear(); + List<Point> bendpoints = new ArrayList<Point>(); + while (it.hasNext()) { + pos = it.next(); + Point pt = Graphiti.getGaService().createPoint(pos.getX(), pos.getY()); + bendpoints.add(pt); + } + fconn.getBendpoints().addAll(bendpoints); + } + } + } + + private void getAnchors(State state, PictogramElement stateShape, final HashMap<String, Anchor> node2anchor) { + + if (stateShape instanceof ContainerShape) { + node2anchor.put(getKey(state), ((ContainerShape)stateShape).getAnchors().get(0)); + for (Shape child : ((ContainerShape) stateShape).getChildren()) { + if (child instanceof ContainerShape) { + ContainerShape childShape = (ContainerShape) child; + if (!childShape.getAnchors().isEmpty()) { + if (!childShape.getLink().getBusinessObjects().isEmpty()) { + EObject obj = childShape.getLink().getBusinessObjects().get(0); + if (obj instanceof EntryPoint || obj instanceof ExitPoint) { + node2anchor.put(getKey(obj, true), childShape.getAnchors().get(0)); + } + } + } + } + } + } + } + + private String getKey(EObject obj) { + return getKey(obj, false); + } + + private String getKey(EObject obj, boolean subTp) { + if (obj instanceof TrPoint) { + TrPoint tp = (TrPoint) obj; + if (!subTp) + return TP+tp.getName(); + else { + if (tp.eContainer().eContainer() instanceof State) { + State s = (State) tp.eContainer().eContainer(); + return TP+tp.getName()+SEP+s.getName(); + } + else { + assert(false): "State expected"; + } + } + } + else if (obj instanceof State) { + return STATE+((State)obj).getName(); + } + else if (obj instanceof ChoicePoint) { + return CP+((ChoicePoint)obj).getName(); + } + else if (obj instanceof TransitionTerminal) { + TransitionTerminal tt = (TransitionTerminal) obj; + if (tt instanceof ChoicepointTerminal) { + return CP+((ChoicepointTerminal)tt).getCp().getName(); + } + else if (tt instanceof StateTerminal) { + return STATE+((StateTerminal)tt).getState().getName(); + } + else if (tt instanceof SubStateTrPointTerminal) { + SubStateTrPointTerminal sstt = (SubStateTrPointTerminal) tt; + return TP+sstt.getTrPoint().getName()+SEP+sstt.getState().getName(); + } + else if (tt instanceof TrPointTerminal) { + return TP+((TrPointTerminal)tt).getTrPoint().getName(); + } + else { + assert(false): "unexpected sub type"; + } + } + assert(false): "unexpected type"; + return null; + } + +} diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/IBehaviorQuickfixProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/IBehaviorQuickfixProvider.java new file mode 100644 index 000000000..112a054ad --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/IBehaviorQuickfixProvider.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.fsm.support; + +import java.util.List; + +import org.eclipse.etrice.ui.common.base.quickfix.IssueResolution; +import org.eclipse.xtext.validation.FeatureBasedDiagnostic; + +/** + * @author Henrik Rentz-Reichert + * + */ +public interface IBehaviorQuickfixProvider { + + /** + * @param issue to resolve + * @return a list of proposed resolutions + */ + List<IssueResolution> getResolutions(FeatureBasedDiagnostic issue); + +} diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/IPositionProvider.java index a8878c6af..329d9b700 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/IPositionProvider.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/IPositionProvider.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.List; diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/InitialPointSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/InitialPointSupport.java index 0fc70dad4..87046a66b 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/InitialPointSupport.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/InitialPointSupport.java @@ -10,14 +10,16 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.fsm.fSM.InitialTransition; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.StateGraph; import org.eclipse.etrice.core.fsm.fSM.Transition; -import org.eclipse.etrice.ui.behavior.ImageProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.ImageProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingBehaviorProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingFeatureProvider; import org.eclipse.etrice.ui.common.base.support.CommonSupportUtil; import org.eclipse.etrice.ui.common.base.support.DeleteWithoutConfirmFeature; import org.eclipse.etrice.ui.common.base.support.NoResizeFeature; @@ -58,13 +60,13 @@ import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.IGaService; import org.eclipse.graphiti.services.IPeCreateService; import org.eclipse.graphiti.tb.ContextButtonEntry; -import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider; import org.eclipse.graphiti.tb.IContextButtonPadData; import org.eclipse.graphiti.tb.IToolBehaviorProvider; -import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; import org.eclipse.graphiti.util.ColorConstant; import org.eclipse.graphiti.util.IColorConstant; +import com.google.inject.Injector; + public class InitialPointSupport { public static final int ITEM_SIZE = StateGraphSupport.MARGIN/2; @@ -75,7 +77,7 @@ public class InitialPointSupport { protected static final IColorConstant BRIGHT_COLOR = new ColorConstant(255, 255, 255); protected static final String PROP_KIND = "item-kind"; - private static class FeatureProvider extends DefaultFeatureProvider { + private static class FeatureProvider extends InjectingFeatureProvider { private static class CreateFeature extends AbstractCreateFeature { @@ -93,10 +95,10 @@ public class InitialPointSupport { ContainerShape targetContainer = context.getTargetContainer(); StateGraph sg = (StateGraph) targetContainer.getLink().getBusinessObjects().get(0); - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), sg); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), sg); if (inherited) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); - sg = SupportUtil.getInstance().insertRefinedState(sg, ac, targetContainer, getFeatureProvider()); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); + sg = FSMSupportUtil.getInstance().insertRefinedState(sg, ac, targetContainer, getFeatureProvider()); } // We don't create anything here since in the model the initial point is @@ -119,7 +121,7 @@ public class InitialPointSupport { ContainerShape parent = context.getTargetContainer().getContainer(); if (! (parent instanceof StateGraph)) { StateGraph sg = (StateGraph) obj; - for (Transition t : SupportUtil.getInstance().getRoomHelpers().getAllTransitions(sg)) { + for (Transition t : FSMSupportUtil.getInstance().getFSMHelpers().getAllTransitions(sg)) { if (t instanceof InitialTransition) return false; } @@ -155,7 +157,7 @@ public class InitialPointSupport { ContainerShape sgShape = context.getTargetContainer(); StateGraph sg = (StateGraph) context.getNewObject(); - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), sg); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), sg); // CONTAINER SHAPE WITH RECTANGLE IPeCreateService peCreateService = Graphiti.getPeCreateService(); @@ -215,7 +217,7 @@ public class InitialPointSupport { if (canMove) { Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement()); if (bo instanceof StateGraph) { - return !SupportUtil.getInstance().isInherited(getDiagram(), (StateGraph)bo); + return !FSMSupportUtil.getInstance().isInherited(getDiagram(), (StateGraph)bo); } return false; } @@ -233,7 +235,7 @@ public class InitialPointSupport { public boolean canRemove(IRemoveContext context) { Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement()); if (bo instanceof StateGraph) { - return !SupportUtil.getInstance().isInherited(getDiagram(), (StateGraph) bo); + return !FSMSupportUtil.getInstance().isInherited(getDiagram(), (StateGraph) bo); } return false; } @@ -263,8 +265,8 @@ public class InitialPointSupport { protected IFeatureProvider fp; - protected FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) { - super(dtp); + protected FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + super(dtp, injector); this.fp = fp; } @@ -328,10 +330,10 @@ public class InitialPointSupport { } - private class BehaviorProvider extends DefaultToolBehaviorProvider { + private class BehaviorProvider extends InjectingBehaviorProvider { - public BehaviorProvider(IDiagramTypeProvider dtp) { - super(dtp); + public BehaviorProvider(IDiagramTypeProvider dtp, Injector injector) { + super(dtp, injector); } @Override @@ -387,9 +389,9 @@ public class InitialPointSupport { private FeatureProvider pfp; private BehaviorProvider tbp; - public InitialPointSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) { - pfp = new FeatureProvider(dtp,fp); - tbp = new BehaviorProvider(dtp); + public InitialPointSupport(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + pfp = new FeatureProvider(dtp, fp, injector); + tbp = new BehaviorProvider(dtp, injector); } public IFeatureProvider getFeatureProvider() { diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/QuickFixFeature.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/QuickFixFeature.java index 2bd97fd97..6aab477b0 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/QuickFixFeature.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/QuickFixFeature.java @@ -10,30 +10,35 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.eclipse.emf.common.util.Diagnostic; -import org.eclipse.etrice.ui.behavior.ImageProvider; -import org.eclipse.etrice.ui.behavior.dialogs.QuickFixDialog; -import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; -import org.eclipse.etrice.ui.behavior.quickfix.BehaviorQuickfixProvider; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.QuickFixDialog; +import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMEditor; +import org.eclipse.etrice.ui.behavior.fsm.provider.ImageProvider; import org.eclipse.etrice.ui.common.base.quickfix.IssueResolution; import org.eclipse.etrice.ui.common.base.support.ChangeAwareCustomFeature; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.ICustomContext; +import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; +import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.xtext.validation.FeatureBasedDiagnostic; +import com.google.inject.Injector; + public class QuickFixFeature extends ChangeAwareCustomFeature { - public QuickFixFeature(IFeatureProvider fp) { - super(fp); + private HashMap<FeatureBasedDiagnostic, List<IssueResolution>> issueResolutionsMap; + + public QuickFixFeature(IFeatureProvider fp, Injector injector) { + super(fp, injector); } @Override @@ -53,30 +58,22 @@ public class QuickFixFeature extends ChangeAwareCustomFeature { @Override public boolean canExecute(ICustomContext context) { - return true; - } + Object bo = getBusinessObject(context); + computeResolutions(bo); + + return !issueResolutionsMap.isEmpty(); + } + @Override public boolean doExecute(ICustomContext context) { // Get the issue Resolutions Map - Object bo = getBusinessObjectForPictogramElement(context - .getPictogramElements()[0]); - ArrayList<Diagnostic> issues = ((BehaviorEditor) getDiagramBehavior() - .getDiagramContainer()).getDiagnosingModelObserver() - .getElementDiagonsticMap().get(bo); - - HashMap<FeatureBasedDiagnostic, List<IssueResolution>> issueResolutionsMap = new HashMap<FeatureBasedDiagnostic, List<IssueResolution>>(); - BehaviorQuickfixProvider behaviorQuickfixProvider = new BehaviorQuickfixProvider(); - for (Diagnostic issue : issues) { - issueResolutionsMap.put((FeatureBasedDiagnostic) issue, - behaviorQuickfixProvider - .getResolutions((FeatureBasedDiagnostic) issue)); - } - + Object bo = getBusinessObject(context); + computeResolutions(bo); + // Create & Open the Quick Fix Dialog - Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() - .getShell(); + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); QuickFixDialog dlg = new QuickFixDialog(shell, issueResolutionsMap); if (dlg.open() == Window.OK) { @@ -88,4 +85,34 @@ public class QuickFixFeature extends ChangeAwareCustomFeature { return false; } + + private Object getBusinessObject(ICustomContext context) { + PictogramElement[] pes = context.getPictogramElements(); + if (pes != null && pes.length == 1) { + PictogramElement pe = pes[0]; + if (pe instanceof ConnectionDecorator) + pe = (PictogramElement) pe.eContainer(); + + return getBusinessObjectForPictogramElement(pe); + } + return null; + } + + private void computeResolutions(Object bo) { + if (issueResolutionsMap==null) { + ArrayList<Diagnostic> issues = ((AbstractFSMEditor) getDiagramBehavior() + .getDiagramContainer()).getDiagnosingModelObserver() + .getElementDiagonsticMap().get(bo); + + issueResolutionsMap = new HashMap<FeatureBasedDiagnostic, List<IssueResolution>>(); + IBehaviorQuickfixProvider behaviorQuickfixProvider = getInjector().getInstance(IBehaviorQuickfixProvider.class); + for (Diagnostic issue : issues) { + if (((FeatureBasedDiagnostic) issue).getIssueCode()!=null) { + issueResolutionsMap.put((FeatureBasedDiagnostic) issue, + behaviorQuickfixProvider + .getResolutions((FeatureBasedDiagnostic) issue)); + } + } + } + } }
\ No newline at end of file diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphSupport.java index 10092511f..937d612b7 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphSupport.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.ArrayList; import java.util.List; @@ -23,9 +23,11 @@ import org.eclipse.etrice.core.fsm.fSM.State; import org.eclipse.etrice.core.fsm.fSM.StateGraph; import org.eclipse.etrice.core.fsm.fSM.TrPoint; import org.eclipse.etrice.core.fsm.fSM.Transition; -import org.eclipse.etrice.ui.behavior.commands.StateGraphContext; -import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; -import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.commands.StateGraphContext; +import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMEditor; +import org.eclipse.etrice.ui.behavior.fsm.editor.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingBehaviorProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingFeatureProvider; import org.eclipse.etrice.ui.common.base.support.DeleteWithoutConfirmFeature; import org.eclipse.graphiti.dt.IDiagramTypeProvider; import org.eclipse.graphiti.features.IAddFeature; @@ -65,14 +67,14 @@ import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.IGaService; import org.eclipse.graphiti.services.IPeCreateService; -import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider; import org.eclipse.graphiti.tb.IDecorator; import org.eclipse.graphiti.tb.IToolBehaviorProvider; import org.eclipse.graphiti.tb.ImageDecorator; -import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; import org.eclipse.graphiti.util.ColorConstant; import org.eclipse.graphiti.util.IColorConstant; +import com.google.inject.Injector; + public class StateGraphSupport { public static final int MARGIN = 40; @@ -84,7 +86,7 @@ public class StateGraphSupport { private static final IColorConstant LINE_COLOR = new ColorConstant(0, 0, 0); private static final IColorConstant BACKGROUND = new ColorConstant(255, 255, 255); - private static class FeatureProvider extends DefaultFeatureProvider { + private static class FeatureProvider extends InjectingFeatureProvider { private class AddFeature extends AbstractAddFeature { @@ -151,7 +153,7 @@ public class StateGraphSupport { { Shape labelShape = peCreateService.createShape(containerShape, false); Text label = gaService.createDefaultText(getDiagram(), labelShape, - SupportUtil.getInstance().getRoomNameProvider().getStateGraphLabel(sg)); + FSMSupportUtil.getInstance().getFSMNameProvider().getStateGraphLabel(sg)); label.setForeground(manageColor(LINE_COLOR)); label.setBackground(manageColor(LINE_COLOR)); label.setHorizontalAlignment(Orientation.ALIGNMENT_RIGHT); @@ -316,7 +318,7 @@ public class StateGraphSupport { // check for states added in model not present in diagram (including inherited) { List<State> expectedStates = ctx.getStates(); - List<State> presentStates = SupportUtil.getInstance().getStates(shape, fp); + List<State> presentStates = FSMSupportUtil.getInstance().getStates(shape, fp); for (State state : expectedStates) { if (!presentStates.contains(state)) ++missing; @@ -329,7 +331,7 @@ public class StateGraphSupport { { missing = 0; List<TrPoint> expectedTrPoints = ctx.getTrPoints(); - List<TrPoint> presentTrPoints = SupportUtil.getInstance().getTrPoints(sg, shape, fp); + List<TrPoint> presentTrPoints = FSMSupportUtil.getInstance().getTrPoints(sg, shape, fp); for (TrPoint tp : expectedTrPoints) { if (!presentTrPoints.contains(tp)) ++missing; @@ -342,7 +344,7 @@ public class StateGraphSupport { { missing = 0; List<ChoicePoint> expectedCPs = ctx.getChPoints(); - List<ChoicePoint> presentCPs = SupportUtil.getInstance().getChoicePoints(shape, fp); + List<ChoicePoint> presentCPs = FSMSupportUtil.getInstance().getChoicePoints(shape, fp); for (ChoicePoint cp : expectedCPs) { if (!presentCPs.contains(cp)) ++missing; @@ -355,7 +357,7 @@ public class StateGraphSupport { { missing = 0; List<Transition> expectedTrans = ctx.getTransitions(); - List<Transition> presentTrans = SupportUtil.getInstance().getTransitions(getDiagram(), fp); + List<Transition> presentTrans = FSMSupportUtil.getInstance().getTransitions(getDiagram(), fp); for (Transition trans : expectedTrans) { if (!presentTrans.contains(trans)) ++missing; @@ -370,7 +372,7 @@ public class StateGraphSupport { Shape labelShape = shape.getChildren().get(0); GraphicsAlgorithm ga = labelShape.getGraphicsAlgorithm(); if (ga instanceof Text) - if (!SupportUtil.getInstance().getRoomNameProvider().getStateGraphLabel(sg).equals(((Text)ga).getValue())) + if (!FSMSupportUtil.getInstance().getFSMNameProvider().getStateGraphLabel(sg).equals(((Text)ga).getValue())) reason += "state graph label changed\n"; } @@ -402,14 +404,14 @@ public class StateGraphSupport { if (context instanceof StateGraphUpdateContext) { StateGraphContext ctx = ((StateGraphUpdateContext)context).getContext(); - SupportUtil.getInstance().updateStateGraph(sg, ctx, sgShape, fp); + FSMSupportUtil.getInstance().updateStateGraph(sg, ctx, sgShape, fp); } if (!sgShape.getChildren().isEmpty()) { Shape labelShape = sgShape.getChildren().get(0); GraphicsAlgorithm ga = labelShape.getGraphicsAlgorithm(); if (ga instanceof Text) - ((Text)ga).setValue(SupportUtil.getInstance().getRoomNameProvider().getStateGraphLabel(sg)); + ((Text)ga).setValue(FSMSupportUtil.getInstance().getFSMNameProvider().getStateGraphLabel(sg)); } return true; @@ -525,8 +527,8 @@ public class StateGraphSupport { private IFeatureProvider fp; - public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) { - super(dtp); + public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + super(dtp, injector); this.fp = fp; } @@ -572,22 +574,22 @@ public class StateGraphSupport { // Provide quick fix feature only for those edit parts which have // errors, warnings or infos. - ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider() + ArrayList<Diagnostic> diagnostics = ((AbstractFSMEditor) getDiagramTypeProvider() .getDiagramBehavior().getDiagramContainer()) .getDiagnosingModelObserver().getElementDiagonsticMap() .get(bo); if (diagnostics != null) - result.add(new QuickFixFeature(fp)); + result.add(new QuickFixFeature(fp, getInjector())); ICustomFeature features[] = new ICustomFeature[result.size()]; return result.toArray(features); } } - private class BehaviorProvider extends DefaultToolBehaviorProvider { + private class BehaviorProvider extends InjectingBehaviorProvider { - public BehaviorProvider(IDiagramTypeProvider dtp) { - super(dtp); + public BehaviorProvider(IDiagramTypeProvider dtp, Injector injector) { + super(dtp, injector); } @Override @@ -630,7 +632,7 @@ public class StateGraphSupport { .getBusinessObjectForLinkedPictogramElement(pe); // Get Diagnostics associated with the business object - ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider() + ArrayList<Diagnostic> diagnostics = ((AbstractFSMEditor) getDiagramTypeProvider() .getDiagramBehavior().getDiagramContainer()) .getDiagnosingModelObserver().getElementDiagonsticMap() .get(bo); @@ -658,9 +660,9 @@ public class StateGraphSupport { private FeatureProvider afp; private BehaviorProvider tbp; - public StateGraphSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) { - afp = new FeatureProvider(dtp, fp); - tbp = new BehaviorProvider(dtp); + public StateGraphSupport(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + afp = new FeatureProvider(dtp, fp, injector); + tbp = new BehaviorProvider(dtp, injector); } public IFeatureProvider getFeatureProvider() { diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphUpdateContext.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphUpdateContext.java index 5ec44abaa..82c766c07 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphUpdateContext.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateGraphUpdateContext.java @@ -10,9 +10,9 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; -import org.eclipse.etrice.ui.behavior.commands.StateGraphContext; +import org.eclipse.etrice.ui.behavior.fsm.commands.StateGraphContext; import org.eclipse.graphiti.features.context.impl.UpdateContext; import org.eclipse.graphiti.mm.pictograms.PictogramElement; diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java index 4d6131e74..a6342661b 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.ArrayList; @@ -18,16 +18,19 @@ import org.eclipse.emf.common.util.Diagnostic; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.etrice.core.fsm.fSM.FSMFactory; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.RefinedState; import org.eclipse.etrice.core.fsm.fSM.SimpleState; import org.eclipse.etrice.core.fsm.fSM.State; import org.eclipse.etrice.core.fsm.fSM.StateGraph; import org.eclipse.etrice.core.fsm.fSM.TrPoint; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.ui.behavior.ImageProvider; -import org.eclipse.etrice.ui.behavior.dialogs.StatePropertyDialog; -import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; -import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IStatePropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMEditor; +import org.eclipse.etrice.ui.behavior.fsm.editor.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.provider.ImageProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingBehaviorProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingFeatureProvider; import org.eclipse.etrice.ui.common.base.support.ChangeAwareCreateFeature; import org.eclipse.etrice.ui.common.base.support.ChangeAwareCustomFeature; import org.eclipse.etrice.ui.common.base.support.CommonSupportUtil; @@ -86,12 +89,10 @@ import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.IGaService; import org.eclipse.graphiti.services.IPeCreateService; import org.eclipse.graphiti.tb.ContextButtonEntry; -import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider; import org.eclipse.graphiti.tb.IContextButtonPadData; import org.eclipse.graphiti.tb.IDecorator; import org.eclipse.graphiti.tb.IToolBehaviorProvider; import org.eclipse.graphiti.tb.ImageDecorator; -import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; import org.eclipse.graphiti.ui.services.GraphitiUi; import org.eclipse.graphiti.util.ColorConstant; import org.eclipse.graphiti.util.IColorConstant; @@ -99,6 +100,8 @@ import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import com.google.inject.Injector; + public class StateSupport { private static final int LINE_WIDTH = 1; @@ -116,12 +119,12 @@ public class StateSupport { private static final IColorConstant BACKGROUND = new ColorConstant(200, 200, 200); private static final IColorConstant INHERITED_BACKGROUND = new ColorConstant(230, 230, 230); - private static class FeatureProvider extends DefaultFeatureProvider { + private static class FeatureProvider extends InjectingFeatureProvider { private class CreateFeature extends ChangeAwareCreateFeature { - public CreateFeature(IFeatureProvider fp) { - super(fp, "State", "create State"); + public CreateFeature(IFeatureProvider fp, Injector injector) { + super(fp, injector, "State", "create State"); } @Override @@ -145,21 +148,22 @@ public class StateSupport { public Object[] doCreate(ICreateContext context) { ContainerShape targetContainer = context.getTargetContainer(); - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); StateGraph sg = (StateGraph) targetContainer.getLink().getBusinessObjects().get(0); - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), sg); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), sg); if (inherited) { - sg = SupportUtil.getInstance().insertRefinedState(sg, ac, targetContainer, getFeatureProvider()); + sg = FSMSupportUtil.getInstance().insertRefinedState(sg, ac, targetContainer, getFeatureProvider()); } // create new State and add it SimpleState s = FSMFactory.eINSTANCE.createSimpleState(); - s.setName(SupportUtil.getInstance().getRoomUtil().getUniqueStateName(sg)); + s.setName(FSMSupportUtil.getInstance().getFSMUtil().getUniqueStateName(sg)); sg.getStates().add(s); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - StatePropertyDialog dlg = new StatePropertyDialog(shell, ac, s, true); + IFSMDialogFactory factory = getInjector().getInstance(IFSMDialogFactory.class); + IStatePropertyDialog dlg = factory.createStatePropertyDialog(shell, ac, s, true); if (dlg.open()==Window.OK) { addGraphicalRepresentation(context, s); @@ -222,7 +226,7 @@ public class StateSupport { else y += height/2; - boolean showInherited = SupportUtil.getInstance().showAsInherited(getDiagram(), s); + boolean showInherited = FSMSupportUtil.getInstance().showAsInherited(getDiagram(), s); Color lineColor = manageColor(showInherited?INHERITED_COLOR:LINE_COLOR); Color bgColor = manageColor(showInherited?INHERITED_BACKGROUND:BACKGROUND); IGaService gaService = Graphiti.getGaService(); @@ -304,7 +308,7 @@ public class StateSupport { while (!borderGA.getGraphicsAlgorithmChildren().isEmpty()) { EcoreUtil.delete(borderGA.getGraphicsAlgorithmChildren().get(0), true); } - Color lineColor = manageColor(SupportUtil.getInstance().showAsInherited(getDiagram(), s)?INHERITED_COLOR:LINE_COLOR); + Color lineColor = manageColor(FSMSupportUtil.getInstance().showAsInherited(getDiagram(), s)?INHERITED_COLOR:LINE_COLOR); addHints(s, (RoundedRectangle) borderGA, lineColor); } @@ -326,9 +330,8 @@ public class StateSupport { private boolean editable; - public PropertyFeature(IFeatureProvider fp, boolean editable) { - super(fp); - + public PropertyFeature(IFeatureProvider fp, Injector injector, boolean editable) { + super(fp, injector); this.editable = editable; } @@ -356,11 +359,12 @@ public class StateSupport { @Override public boolean doExecute(ICustomContext context) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); State s = (State) getBusinessObjectForPictogramElement(context.getPictogramElements()[0]); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - StatePropertyDialog dlg = new StatePropertyDialog(shell, ac, s, editable); + IFSMDialogFactory factory = getInjector().getInstance(IFSMDialogFactory.class); + IStatePropertyDialog dlg = factory.createStatePropertyDialog(shell, ac, s, editable); if (dlg.open()==Window.OK){ updateFigure(s, context); adjustSubgraphLabels(s, ac); @@ -371,19 +375,19 @@ public class StateSupport { return false; } - private void adjustSubgraphLabels(State s, ActorClass ac) { + private void adjustSubgraphLabels(State s, ModelComponent ac) { if (s instanceof RefinedState) // the name hasn't changed, nothing to do return; - if (SupportUtil.getInstance().getRoomHelpers().hasDirectSubStructure(s)) { + if (FSMSupportUtil.getInstance().getFSMHelpers().hasDirectSubStructure(s)) { // update the path text in the sub graph ContainerShape subShape = ContextSwitcher.getContext(getDiagram(), s.getSubgraph()); if (subShape!=null && !subShape.getChildren().isEmpty()) { Shape labelShape = subShape.getChildren().get(0); GraphicsAlgorithm ga = labelShape.getGraphicsAlgorithm(); if (ga instanceof Text) - ((Text)ga).setValue(SupportUtil.getInstance().getRoomNameProvider().getStateGraphLabel(s.getSubgraph())); + ((Text)ga).setValue(FSMSupportUtil.getInstance().getFSMNameProvider().getStateGraphLabel(s.getSubgraph())); } if (s.getSubgraph()!=null) for (State sub : s.getSubgraph().getStates()) { @@ -401,7 +405,7 @@ public class StateSupport { EcoreUtil.delete(invisibleRect.getGraphicsAlgorithmChildren().get(0), true); } - boolean showInherite = SupportUtil.getInstance().showAsInherited(getDiagram(), s); + boolean showInherite = FSMSupportUtil.getInstance().showAsInherited(getDiagram(), s); Color lineColor = manageColor(showInherite?INHERITED_COLOR:LINE_COLOR); Color bgColor = manageColor(showInherite?INHERITED_BACKGROUND:BACKGROUND); createFigure(s, invisibleRect, lineColor, bgColor); @@ -436,11 +440,11 @@ public class StateSupport { PictogramElement pe = context.getPictogramElements()[0]; Object bo = getBusinessObjectForPictogramElement(pe); if (bo instanceof State) { -// State targetting = SupportUtil.getTargettingState((State) bo, getDiagram()); +// State targetting = FSMSupportUtil.getTargettingState((State) bo, getDiagram()); // if (targetting.getSubgraph()!=null) // return true; - if (SupportUtil.getInstance().getRoomHelpers().hasSubStructure((State) bo, - SupportUtil.getInstance().getActorClass(getDiagram()))) + if (FSMSupportUtil.getInstance().getFSMHelpers().hasSubStructure((State) bo, + FSMSupportUtil.getInstance().getModelComponent(getDiagram()))) return true; } return false; @@ -452,9 +456,9 @@ public class StateSupport { ContainerShape container = (ContainerShape)context.getPictogramElements()[0]; Object bo = getBusinessObjectForPictogramElement(container); if (bo instanceof State) { - //State targetting = SupportUtil.getTargettingState((State) bo, getDiagram()); + //State targetting = FSMSupportUtil.getTargettingState((State) bo, getDiagram()); State hasSub = (State) bo; - while (!SupportUtil.getInstance().getRoomHelpers().hasDirectSubStructure(hasSub)) { + while (!FSMSupportUtil.getInstance().getFSMHelpers().hasDirectSubStructure(hasSub)) { if (hasSub instanceof RefinedState) hasSub = ((RefinedState) hasSub).getTarget(); else @@ -494,9 +498,9 @@ public class StateSupport { PictogramElement pe = context.getPictogramElements()[0]; Object bo = getBusinessObjectForPictogramElement(pe); if (bo instanceof State) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); - boolean isBaseClassState = SupportUtil.getInstance().getRoomHelpers().getActorClass((State) bo)!=ac; - return isBaseClassState || !SupportUtil.getInstance().getRoomHelpers().hasSubStructure((State) bo, ac); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); + boolean isBaseClassState = FSMSupportUtil.getInstance().getFSMHelpers().getModelComponent((State) bo)!=ac; + return isBaseClassState || !FSMSupportUtil.getInstance().getFSMHelpers().hasSubStructure((State) bo, ac); } return false; } @@ -512,9 +516,9 @@ public class StateSupport { StateGraph newSG = null; - boolean isBaseClassState = SupportUtil.getInstance().getRoomHelpers().getActorClass(s)!=SupportUtil.getInstance().getActorClass(getDiagram()); + boolean isBaseClassState = FSMSupportUtil.getInstance().getFSMHelpers().getModelComponent(s)!=FSMSupportUtil.getInstance().getModelComponent(getDiagram()); if (isBaseClassState) { - newSG = SupportUtil.getInstance().getSubGraphOfRefinedStateFor(s, SupportUtil.getInstance().getActorClass(getDiagram())); + newSG = FSMSupportUtil.getInstance().getSubGraphOfRefinedStateFor(s, FSMSupportUtil.getInstance().getModelComponent(getDiagram())); s = (State) newSG.eContainer(); // replace old business object with new refined state @@ -563,8 +567,8 @@ public class StateSupport { PictogramElement pe = context.getPictogramElements()[0]; Object bo = getBusinessObjectForPictogramElement(pe); if (bo instanceof State) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); - boolean isBaseClassState = SupportUtil.getInstance().getRoomHelpers().getActorClass((State) bo)!=ac; + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); + boolean isBaseClassState = FSMSupportUtil.getInstance().getFSMHelpers().getModelComponent((State) bo)!=ac; return isBaseClassState; } return false; @@ -577,7 +581,7 @@ public class StateSupport { ContainerShape container = (ContainerShape)context.getPictogramElements()[0]; Object bo = getBusinessObjectForPictogramElement(container); State s = (State) bo; - RefinedState rs = SupportUtil.getInstance().getRefinedStateFor(s, SupportUtil.getInstance().getActorClass(getDiagram())); + RefinedState rs = FSMSupportUtil.getInstance().getRefinedStateFor(s, FSMSupportUtil.getInstance().getModelComponent(getDiagram())); // replace old business object with new refined state link(container, rs); @@ -615,17 +619,17 @@ public class StateSupport { return Reason.createTrueReason("State deleted from model"); } State s = (State) bo; - ActorClass mainAc = SupportUtil.getInstance().getActorClass(getDiagram()); + ModelComponent mainAc = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); // check if state still owned/inherited { - ActorClass ac = SupportUtil.getInstance().getRoomHelpers().getActorClass(s); - ActorClass tmp = mainAc; + ModelComponent ac = FSMSupportUtil.getInstance().getFSMHelpers().getModelComponent(s); + ModelComponent tmp = mainAc; boolean found = false; do { if (tmp==ac) found = true; - tmp = tmp.getActorBase(); + tmp = tmp.getBase(); } while (!found && tmp!=null); @@ -635,7 +639,7 @@ public class StateSupport { // check sub structure hint { - boolean hasSubStruct = SupportUtil.getInstance().getRoomHelpers().hasSubStructure(s, mainAc); + boolean hasSubStruct = FSMSupportUtil.getInstance().getFSMHelpers().hasSubStructure(s, mainAc); GraphicsAlgorithm invisibleRect = containerShape.getGraphicsAlgorithm(); if (!invisibleRect.getGraphicsAlgorithmChildren().isEmpty()) { GraphicsAlgorithm borderRect = invisibleRect.getGraphicsAlgorithmChildren().get(0); @@ -717,7 +721,7 @@ public class StateSupport { // TODOHRR: also check coordinates (no overlap with state graph boundaries) - return !SupportUtil.getInstance().isInherited(getDiagram(), s); + return !FSMSupportUtil.getInstance().isInherited(getDiagram(), s); } } @@ -740,7 +744,7 @@ public class StateSupport { if (bo instanceof State) { State s = (State) bo; - if (SupportUtil.getInstance().isInherited(getDiagram(), s)) + if (FSMSupportUtil.getInstance().isInherited(getDiagram(), s)) return false; int width = context.getWidth()-MARGIN; @@ -814,7 +818,7 @@ public class StateSupport { Object bo = getBusinessObjectForPictogramElement(context.getPictogramElement()); if (bo instanceof State) { State state = (State) bo; - return !SupportUtil.getInstance().isInherited(getDiagram(), state); + return !FSMSupportUtil.getInstance().isInherited(getDiagram(), state); } return false; } @@ -832,8 +836,8 @@ public class StateSupport { State s = (State) getBusinessObjectForPictogramElement(context.getPictogramElement()); IFeatureProvider fp = getFeatureProvider(); Diagram diagram = getDiagram(); - ActorClass ac = SupportUtil.getInstance().getRoomHelpers().getActorClass(s); - SupportUtil.getInstance().deleteSubStructureRecursive(s, ac, diagram, fp); + ModelComponent ac = FSMSupportUtil.getInstance().getFSMHelpers().getModelComponent(s); + FSMSupportUtil.getInstance().deleteSubStructureRecursive(s, ac, diagram, fp); ContainerShape container = (ContainerShape) context.getPictogramElement(); CommonSupportUtil.deleteConnectionsRecursive(container, fp); @@ -842,8 +846,8 @@ public class StateSupport { private IFeatureProvider fp; - public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) { - super(dtp); + public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + super(dtp, injector); this.fp = fp; } @@ -866,7 +870,7 @@ public class StateSupport { @Override public ICreateFeature[] getCreateFeatures() { - return new ICreateFeature[] { new CreateFeature(fp) }; + return new ICreateFeature[] { new CreateFeature(fp, getInjector()) }; } @Override @@ -914,14 +918,14 @@ public class StateSupport { if (bo instanceof State) { State s = (State) bo; - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagramTypeProvider().getDiagram()); - //boolean inherited = SupportUtil.isInherited(getDiagramTypeProvider().getDiagram(), s); - boolean editable = SupportUtil.getInstance().getRoomHelpers().getActorClass(s)==ac; - result.add(new PropertyFeature(fp, editable)); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagramTypeProvider().getDiagram()); + //boolean inherited = FSMSupportUtil.isInherited(getDiagramTypeProvider().getDiagram(), s); + boolean editable = FSMSupportUtil.getInstance().getFSMHelpers().getModelComponent(s)==ac; + result.add(new PropertyFeature(fp, getInjector(), editable)); if (!editable) result.add(new CreateRefinedStateFeature(fp)); - if (SupportUtil.getInstance().getRoomHelpers().hasSubStructure(s, ac)) + if (FSMSupportUtil.getInstance().getFSMHelpers().hasSubStructure(s, ac)) result.add(new GoDownFeature(fp)); else result.add(new CreateSubGraphFeature(fp)); @@ -929,22 +933,22 @@ public class StateSupport { // Provide quick fix feature only for those edit parts which have // errors, warnings or infos. - ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider() + ArrayList<Diagnostic> diagnostics = ((AbstractFSMEditor) getDiagramTypeProvider() .getDiagramBehavior().getDiagramContainer()) .getDiagnosingModelObserver().getElementDiagonsticMap() .get(bo); if (diagnostics != null) - result.add(new QuickFixFeature(fp)); + result.add(new QuickFixFeature(fp, getInjector())); ICustomFeature features[] = new ICustomFeature[result.size()]; return result.toArray(features); } } - private class BehaviorProvider extends DefaultToolBehaviorProvider { + private class BehaviorProvider extends InjectingBehaviorProvider { - public BehaviorProvider(IDiagramTypeProvider dtp) { - super(dtp); + public BehaviorProvider(IDiagramTypeProvider dtp, Injector injector) { + super(dtp, injector); } @Override @@ -970,11 +974,11 @@ public class StateSupport { EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); if (bo instanceof State) { - ActorClass ac = SupportUtil.getInstance().getActorClass(SupportUtil.getInstance().getDiagram(pe)); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(FSMSupportUtil.getInstance().getDiagram(pe)); State s = (State) bo; - if (!SupportUtil.getInstance().getRoomHelpers().hasSubStructure(s, ac)) { - boolean editable = SupportUtil.getInstance().getRoomHelpers().getActorClass(s)==ac; - return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider(), editable); + if (!FSMSupportUtil.getInstance().getFSMHelpers().hasSubStructure(s, ac)) { + boolean editable = FSMSupportUtil.getInstance().getFSMHelpers().getModelComponent(s)==ac; + return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider(), getInjector(), editable); } } return new FeatureProvider.GoDownFeature(getDiagramTypeProvider().getFeatureProvider()); @@ -993,9 +997,9 @@ public class StateSupport { { String entry = ""; if (s instanceof RefinedState) - entry += SupportUtil.getInstance().getRoomHelpers().getBaseEntryCode((RefinedState) s); - if (SupportUtil.getInstance().getRoomHelpers().hasDetailCode(s.getEntryCode())) - entry += SupportUtil.getInstance().getRoomHelpers().getDetailCode(s.getEntryCode()); + entry += FSMSupportUtil.getInstance().getFSMHelpers().getBaseEntryCode((RefinedState) s); + if (FSMSupportUtil.getInstance().getFSMHelpers().hasDetailCode(s.getEntryCode())) + entry += FSMSupportUtil.getInstance().getFSMHelpers().getDetailCode(s.getEntryCode()); if (!entry.isEmpty()) label += "entry:\n"+entry; @@ -1003,10 +1007,10 @@ public class StateSupport { { String exit = ""; - if (SupportUtil.getInstance().getRoomHelpers().hasDetailCode(s.getExitCode())) - exit += SupportUtil.getInstance().getRoomHelpers().getDetailCode(s.getExitCode()); + if (FSMSupportUtil.getInstance().getFSMHelpers().hasDetailCode(s.getExitCode())) + exit += FSMSupportUtil.getInstance().getFSMHelpers().getDetailCode(s.getExitCode()); if (s instanceof RefinedState) - exit += SupportUtil.getInstance().getRoomHelpers().getBaseExitCode((RefinedState) s); + exit += FSMSupportUtil.getInstance().getFSMHelpers().getBaseExitCode((RefinedState) s); if (!exit.isEmpty()) { if (!label.isEmpty()) @@ -1017,10 +1021,10 @@ public class StateSupport { { String doCode = ""; - if (SupportUtil.getInstance().getRoomHelpers().hasDetailCode(s.getDoCode())) - doCode += "do:\n"+SupportUtil.getInstance().getRoomHelpers().getDetailCode(s.getDoCode()); + if (FSMSupportUtil.getInstance().getFSMHelpers().hasDetailCode(s.getDoCode())) + doCode += "do:\n"+FSMSupportUtil.getInstance().getFSMHelpers().getDetailCode(s.getDoCode()); if (s instanceof RefinedState) - doCode += SupportUtil.getInstance().getRoomHelpers().getBaseDoCode((RefinedState) s); + doCode += FSMSupportUtil.getInstance().getFSMHelpers().getBaseDoCode((RefinedState) s); if (!doCode.isEmpty()) { if (!label.isEmpty()) @@ -1086,7 +1090,7 @@ public class StateSupport { .getBusinessObjectForLinkedPictogramElement(pe); // Get Diagnostics associated with the business object - ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider() + ArrayList<Diagnostic> diagnostics = ((AbstractFSMEditor) getDiagramTypeProvider() .getDiagramBehavior().getDiagramContainer()) .getDiagnosingModelObserver().getElementDiagonsticMap() .get(bo); @@ -1114,9 +1118,9 @@ public class StateSupport { private FeatureProvider pfp; private BehaviorProvider tbp; - public StateSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) { - pfp = new FeatureProvider(dtp,fp); - tbp = new BehaviorProvider(dtp); + public StateSupport(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + pfp = new FeatureProvider(dtp,fp, injector); + tbp = new BehaviorProvider(dtp, injector); } public IFeatureProvider getFeatureProvider() { @@ -1141,8 +1145,8 @@ public class StateSupport { hint.setLineWidth(LINE_WIDTH); gaService.setLocationAndSize(hint, x, y, 15, 8); - ActorClass ac = SupportUtil.getInstance().getActorClass(SupportUtil.getInstance().getDiagram(border)); - if (!SupportUtil.getInstance().getRoomHelpers().hasSubStructure(s, ac)) { + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(FSMSupportUtil.getInstance().getDiagram(border)); + if (!FSMSupportUtil.getInstance().getFSMHelpers().hasSubStructure(s, ac)) { hint.setLineVisible(false); } } @@ -1171,33 +1175,33 @@ public class StateSupport { doHint.setLineWidth(LINE_WIDTH); gaService.setLocation(doHint, x, y); - if (!SupportUtil.getInstance().getRoomHelpers().hasEntryCode(s, true)) { + if (!FSMSupportUtil.getInstance().getFSMHelpers().hasEntryCode(s, true)) { entryHint.setLineVisible(false); } - if (!SupportUtil.getInstance().getRoomHelpers().hasExitCode(s, true)) { + if (!FSMSupportUtil.getInstance().getFSMHelpers().hasExitCode(s, true)) { exitHint.setLineVisible(false); } - if (!SupportUtil.getInstance().getRoomHelpers().hasDoCode(s, true)) { + if (!FSMSupportUtil.getInstance().getFSMHelpers().hasDoCode(s, true)) { doHint.setLineVisible(false); } } } protected static void updateHints(State s, GraphicsAlgorithm border) { - ActorClass ac = SupportUtil.getInstance().getActorClass(SupportUtil.getInstance().getDiagram(border)); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(FSMSupportUtil.getInstance().getDiagram(border)); // sub structure GraphicsAlgorithm hint = border.getGraphicsAlgorithmChildren().get(0); - hint.setLineVisible(SupportUtil.getInstance().getRoomHelpers().hasSubStructure(s, ac)); + hint.setLineVisible(FSMSupportUtil.getInstance().getFSMHelpers().hasSubStructure(s, ac)); // entry and exit code hint = border.getGraphicsAlgorithmChildren().get(1); - hint.setLineVisible(SupportUtil.getInstance().getRoomHelpers().hasEntryCode(s, true)); + hint.setLineVisible(FSMSupportUtil.getInstance().getFSMHelpers().hasEntryCode(s, true)); hint = border.getGraphicsAlgorithmChildren().get(2); - hint.setLineVisible(SupportUtil.getInstance().getRoomHelpers().hasExitCode(s, true)); + hint.setLineVisible(FSMSupportUtil.getInstance().getFSMHelpers().hasExitCode(s, true)); hint = border.getGraphicsAlgorithmChildren().get(3); - hint.setLineVisible(SupportUtil.getInstance().getRoomHelpers().hasDoCode(s, true)); + hint.setLineVisible(FSMSupportUtil.getInstance().getFSMHelpers().hasDoCode(s, true)); } } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/TrPointSupport.java index 720634275..8560d5a75 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/TrPointSupport.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.ArrayList; import java.util.List; @@ -21,15 +21,18 @@ import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.etrice.core.fsm.fSM.EntryPoint; import org.eclipse.etrice.core.fsm.fSM.ExitPoint; import org.eclipse.etrice.core.fsm.fSM.FSMFactory; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.State; import org.eclipse.etrice.core.fsm.fSM.StateGraph; import org.eclipse.etrice.core.fsm.fSM.TrPoint; import org.eclipse.etrice.core.fsm.fSM.TransitionPoint; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.ui.behavior.ImageProvider; -import org.eclipse.etrice.ui.behavior.dialogs.TrPointPropertyDialog; -import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; -import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.ITrPointPropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMEditor; +import org.eclipse.etrice.ui.behavior.fsm.editor.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.provider.ImageProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingBehaviorProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingFeatureProvider; import org.eclipse.etrice.ui.common.base.support.ChangeAwareCreateFeature; import org.eclipse.etrice.ui.common.base.support.ChangeAwareCustomFeature; import org.eclipse.etrice.ui.common.base.support.CommonSupportUtil; @@ -85,18 +88,18 @@ import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.IGaService; import org.eclipse.graphiti.services.IPeCreateService; import org.eclipse.graphiti.tb.ContextButtonEntry; -import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider; import org.eclipse.graphiti.tb.IContextButtonPadData; import org.eclipse.graphiti.tb.IDecorator; import org.eclipse.graphiti.tb.IToolBehaviorProvider; import org.eclipse.graphiti.tb.ImageDecorator; -import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; import org.eclipse.graphiti.util.ColorConstant; import org.eclipse.graphiti.util.IColorConstant; import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +import com.google.inject.Injector; + public class TrPointSupport { public static final int ITEM_SIZE = StateGraphSupport.MARGIN/2; @@ -112,14 +115,14 @@ public class TrPointSupport { enum Type { TRANS_POINT, ENTRY_POINT, EXIT_POINT } - private static class FeatureProvider extends DefaultFeatureProvider { + private static class FeatureProvider extends InjectingFeatureProvider { private static class CreateFeature extends ChangeAwareCreateFeature { protected Type type; - - public CreateFeature(IFeatureProvider fp, Type type, String name, String description) { - super(fp, name, description); + + public CreateFeature(IFeatureProvider fp, Injector injector, Type type, String name, String description) { + super(fp, injector, name, description); this.type = type; } @@ -139,11 +142,11 @@ public class TrPointSupport { @Override public Object[] doCreate(ICreateContext context) { ContainerShape targetContainer = context.getTargetContainer(); - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); StateGraph sg = (StateGraph) targetContainer.getLink().getBusinessObjects().get(0); - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), sg); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), sg); if (inherited) { - sg = SupportUtil.getInstance().insertRefinedState(sg, ac, targetContainer, getFeatureProvider()); + sg = FSMSupportUtil.getInstance().insertRefinedState(sg, ac, targetContainer, getFeatureProvider()); } // create transition point @@ -159,11 +162,12 @@ public class TrPointSupport { tp = FSMFactory.eINSTANCE.createTransitionPoint(); break; } - tp.setName(SupportUtil.getInstance().getRoomUtil().getUniqueTrPointName(sg)); + tp.setName(FSMSupportUtil.getInstance().getFSMUtil().getUniqueTrPointName(sg)); sg.getTrPoints().add(tp); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - TrPointPropertyDialog dlg = new TrPointPropertyDialog(shell, tp, false); + IFSMDialogFactory factory = getInjector().getInstance(IFSMDialogFactory.class); + ITrPointPropertyDialog dlg = factory.createTrPointPropertyDialog(shell, tp, false); if (dlg.open()==Window.OK) { // do the add addGraphicalRepresentation(context, tp); @@ -182,7 +186,7 @@ public class TrPointSupport { EObject obj = context.getTargetContainer().getLink().getBusinessObjects().get(0); if (obj instanceof StateGraph) { StateGraph sg = (StateGraph) obj; - if (sg.eContainer() instanceof ActorClass) + if (sg.eContainer() instanceof ModelComponent) if (type!=Type.TRANS_POINT) return false; return isValidPosition(context, context, StateGraphSupport.MARGIN); @@ -220,7 +224,7 @@ public class TrPointSupport { ContainerShape parentShape = context.getTargetContainer(); Object bo = getBusinessObjectForPictogramElement(parentShape); boolean subtp = (bo instanceof State); - boolean inherited = subtp?SupportUtil.getInstance().isInherited(getDiagram(), (State)bo):SupportUtil.getInstance().isInherited(tp, parentShape); + boolean inherited = subtp?FSMSupportUtil.getInstance().isInherited(getDiagram(), (State)bo):FSMSupportUtil.getInstance().isInherited(tp, parentShape); int margin = subtp?MARGIN_SMALL:MARGIN; int size = subtp?ITEM_SIZE_SMALL:ITEM_SIZE; @@ -337,8 +341,8 @@ public class TrPointSupport { elements = Graphiti.getLinkService().getPictogramElements(getDiagram(), s); } if (elements.isEmpty()) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); - s = SupportUtil.getInstance().getRoomHelpers().getTargettingState(s, ac); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); + s = FSMSupportUtil.getInstance().getFSMHelpers().getTargettingState(s, ac); assert(s!=null): "a refined state should point to our parent state"; elements = Graphiti.getLinkService().getPictogramElements(getDiagram(), s); } @@ -378,7 +382,7 @@ public class TrPointSupport { if (bo instanceof TrPoint) { TrPoint tp = (TrPoint) bo; - if (SupportUtil.getInstance().isInherited(getDiagram(), tp)) + if (FSMSupportUtil.getInstance().isInherited(getDiagram(), tp)) return false; if (isSubTP(context.getPictogramElement())) @@ -500,8 +504,8 @@ public class TrPointSupport { private String name; private String description; - public PropertyFeature(IFeatureProvider fp) { - super(fp); + public PropertyFeature(IFeatureProvider fp, Injector injector) { + super(fp, injector); this.name = "Edit Transition Point"; this.description = "Edit Transition Point"; } @@ -522,7 +526,7 @@ public class TrPointSupport { if (pes != null && pes.length == 1 && pes[0] instanceof ContainerShape) { Object bo = getBusinessObjectForPictogramElement(pes[0]); if (bo instanceof TrPoint) { - return !SupportUtil.getInstance().isInherited(getDiagram(), (TrPoint) bo); + return !FSMSupportUtil.getInstance().isInherited(getDiagram(), (TrPoint) bo); } } return false; @@ -535,7 +539,8 @@ public class TrPointSupport { boolean subtp = isSubTP(pe); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - TrPointPropertyDialog dlg = new TrPointPropertyDialog(shell, tp, subtp); + IFSMDialogFactory factory = getInjector().getInstance(IFSMDialogFactory.class); + ITrPointPropertyDialog dlg = factory.createTrPointPropertyDialog(shell, tp, subtp); if (dlg.open()==Window.OK){ String kind = getItemKind(tp); Graphiti.getPeService().setPropertyValue(pe, PROP_KIND, kind); @@ -617,7 +622,7 @@ public class TrPointSupport { } TrPoint tp = (TrPoint) bo; - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), tp); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), tp); Color dark = manageColor(inherited? INHERITED_COLOR:DARK_COLOR); updateTrPointFigure(tp, containerShape, dark, manageColor(BRIGHT_COLOR)); @@ -652,10 +657,10 @@ public class TrPointSupport { ContainerShape containerShape = (ContainerShape) context.getPictogramElement(); TrPoint tp = (TrPoint) getBusinessObjectForPictogramElement(containerShape); - if (SupportUtil.getInstance().isInherited(getDiagram(), tp)) + if (FSMSupportUtil.getInstance().isInherited(getDiagram(), tp)) return false; - if (SupportUtil.getInstance().getValidationUtil().isConnectedOutside(tp)) + if (FSMSupportUtil.getInstance().getFSMValidationUtil().isConnectedOutside(tp)) return false; return true; @@ -691,17 +696,17 @@ public class TrPointSupport { protected IFeatureProvider fp; - protected FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) { - super(dtp); + protected FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + super(dtp, injector); this.fp = fp; } @Override public ICreateFeature[] getCreateFeatures() { return new ICreateFeature[] { - new CreateFeature(fp, Type.TRANS_POINT, "Transition Point", "Create Transition Point"), - new CreateFeature(fp, Type.ENTRY_POINT, "Entry Point", "Create Entry Point"), - new CreateFeature(fp, Type.EXIT_POINT, "Exit Point", "Create Exit Point") + new CreateFeature(fp, getInjector(), Type.TRANS_POINT, "Transition Point", "Create Transition Point"), + new CreateFeature(fp, getInjector(), Type.ENTRY_POINT, "Entry Point", "Create Entry Point"), + new CreateFeature(fp, getInjector(), Type.EXIT_POINT, "Exit Point", "Create Exit Point") }; } @@ -727,16 +732,16 @@ public class TrPointSupport { ArrayList<ICustomFeature> result = new ArrayList<ICustomFeature>(); - result.add(new PropertyFeature(fp)); + result.add(new PropertyFeature(fp, getInjector())); // Provide quick fix feature only for those edit parts which have // errors, warnings or infos. - ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider() + ArrayList<Diagnostic> diagnostics = ((AbstractFSMEditor) getDiagramTypeProvider() .getDiagramBehavior().getDiagramContainer()) .getDiagnosingModelObserver().getElementDiagonsticMap() .get(bo); if (diagnostics != null) - result.add(new QuickFixFeature(fp)); + result.add(new QuickFixFeature(fp, getInjector())); ICustomFeature features[] = new ICustomFeature[result.size()]; return result.toArray(features); @@ -922,10 +927,10 @@ public class TrPointSupport { } - private class BehaviorProvider extends DefaultToolBehaviorProvider { + private class BehaviorProvider extends InjectingBehaviorProvider { - public BehaviorProvider(IDiagramTypeProvider dtp) { - super(dtp); + public BehaviorProvider(IDiagramTypeProvider dtp, Injector injector) { + super(dtp, injector); } @Override @@ -947,7 +952,7 @@ public class TrPointSupport { @Override public ICustomFeature getDoubleClickFeature(IDoubleClickContext context) { - return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider()); + return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider(), getInjector()); } @Override @@ -999,7 +1004,7 @@ public class TrPointSupport { .getBusinessObjectForLinkedPictogramElement(pe); // Get Diagnostics associated with the business object - ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider() + ArrayList<Diagnostic> diagnostics = ((AbstractFSMEditor) getDiagramTypeProvider() .getDiagramBehavior().getDiagramContainer()) .getDiagnosingModelObserver().getElementDiagonsticMap() .get(bo); @@ -1027,9 +1032,9 @@ public class TrPointSupport { private FeatureProvider pfp; private BehaviorProvider tbp; - public TrPointSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) { - pfp = new FeatureProvider(dtp,fp); - tbp = new BehaviorProvider(dtp); + public TrPointSupport(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + pfp = new FeatureProvider(dtp, fp, injector); + tbp = new BehaviorProvider(dtp, injector); } public IFeatureProvider getFeatureProvider() { diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/TransitionSupport.java index 2b81e521c..43b39d175 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java +++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/TransitionSupport.java @@ -10,7 +10,7 @@ * *******************************************************************************/ -package org.eclipse.etrice.ui.behavior.support; +package org.eclipse.etrice.ui.behavior.fsm.support; import java.util.ArrayList; @@ -25,6 +25,7 @@ import org.eclipse.etrice.core.fsm.fSM.EntryPoint; import org.eclipse.etrice.core.fsm.fSM.FSMFactory; import org.eclipse.etrice.core.fsm.fSM.GuardedTransition; import org.eclipse.etrice.core.fsm.fSM.InitialTransition; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.NonInitialTransition; import org.eclipse.etrice.core.fsm.fSM.RefinedTransition; import org.eclipse.etrice.core.fsm.fSM.StateGraph; @@ -33,11 +34,13 @@ import org.eclipse.etrice.core.fsm.fSM.TrPointTerminal; import org.eclipse.etrice.core.fsm.fSM.Transition; import org.eclipse.etrice.core.fsm.fSM.TransitionTerminal; import org.eclipse.etrice.core.fsm.fSM.TriggeredTransition; -import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.ui.behavior.ImageProvider; -import org.eclipse.etrice.ui.behavior.dialogs.TransitionPropertyDialog; -import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; -import org.eclipse.etrice.ui.behavior.markers.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.ITransitionPropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMEditor; +import org.eclipse.etrice.ui.behavior.fsm.editor.DecoratorUtil; +import org.eclipse.etrice.ui.behavior.fsm.provider.ImageProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingBehaviorProvider; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingFeatureProvider; import org.eclipse.etrice.ui.common.base.UIBaseActivator; import org.eclipse.etrice.ui.common.base.preferences.UIBasePreferenceConstants; import org.eclipse.etrice.ui.common.base.support.CantRemoveFeature; @@ -88,11 +91,9 @@ import org.eclipse.graphiti.mm.pictograms.PictogramElement; import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.services.IGaService; import org.eclipse.graphiti.services.IPeCreateService; -import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider; import org.eclipse.graphiti.tb.IDecorator; import org.eclipse.graphiti.tb.IToolBehaviorProvider; import org.eclipse.graphiti.tb.ImageDecorator; -import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; import org.eclipse.graphiti.util.ColorConstant; import org.eclipse.graphiti.util.IColorConstant; import org.eclipse.jface.dialogs.MessageDialog; @@ -101,6 +102,9 @@ import org.eclipse.jface.window.Window; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.eclipse.xtext.util.Strings; +import org.eclipse.xtext.xbase.lib.Pair; + +import com.google.inject.Injector; public class TransitionSupport { @@ -111,12 +115,12 @@ public class TransitionSupport { private static final String newLine = Strings.newLine(); private static final int newLineLength = Strings.newLine().length(); - static class FeatureProvider extends DefaultFeatureProvider { + static class FeatureProvider extends InjectingFeatureProvider { private class CreateFeature extends ChangeAwareCreateConnectionFeature { - - public CreateFeature(IFeatureProvider fp) { - super(fp, "Transition", "create Transition"); + + public CreateFeature(IFeatureProvider fp, Injector injector) { + super(fp, injector, "Transition", "create Transition"); } @Override @@ -126,31 +130,31 @@ public class TransitionSupport { @Override public boolean canCreate(ICreateConnectionContext context) { - return SupportUtil.getInstance().canConnect( + return FSMSupportUtil.getInstance().canConnect( context.getSourceAnchor(), context.getTargetAnchor(), (ContainerShape)context.getSourcePictogramElement().eContainer(), fp); } public boolean canStartConnection(ICreateConnectionContext context) { - TransitionTerminal src = SupportUtil.getInstance().getTransitionTerminal(context.getSourceAnchor(), fp); - if (src==null && !SupportUtil.getInstance().isInitialPoint(context.getSourceAnchor(), fp)) + TransitionTerminal src = FSMSupportUtil.getInstance().getTransitionTerminal(context.getSourceAnchor(), fp); + if (src==null && !FSMSupportUtil.getInstance().isInitialPoint(context.getSourceAnchor(), fp)) return false; - StateGraph sg = SupportUtil.getInstance().getStateGraph((ContainerShape) context.getSourcePictogramElement().eContainer(), fp); + StateGraph sg = FSMSupportUtil.getInstance().getStateGraph((ContainerShape) context.getSourcePictogramElement().eContainer(), fp); if (sg==null) return false; - return SupportUtil.getInstance().getValidationUtil().isConnectable(src, sg).isOk(); + return FSMSupportUtil.getInstance().getFSMValidationUtil().isConnectable(src, sg).isOk(); } @Override public Connection doCreate(ICreateConnectionContext context) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); + ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); - TransitionTerminal src = SupportUtil.getInstance().getTransitionTerminal(context.getSourceAnchor(), fp); - TransitionTerminal dst = SupportUtil.getInstance().getTransitionTerminal(context.getTargetAnchor(), fp); - StateGraph sg = SupportUtil.getInstance().getStateGraph((ContainerShape) context.getSourcePictogramElement().eContainer(), fp); + TransitionTerminal src = FSMSupportUtil.getInstance().getTransitionTerminal(context.getSourceAnchor(), fp); + TransitionTerminal dst = FSMSupportUtil.getInstance().getTransitionTerminal(context.getTargetAnchor(), fp); + StateGraph sg = FSMSupportUtil.getInstance().getStateGraph((ContainerShape) context.getSourcePictogramElement().eContainer(), fp); if (dst!=null && sg!=null) { // TODOHRR-B transition dialog @@ -171,7 +175,7 @@ public class TransitionSupport { } else if (src instanceof ChoicepointTerminal) { boolean dfltBranch = true; - for (Transition tr : SupportUtil.getInstance().getRoomHelpers().getAllTransitions(sg)) { + for (Transition tr : FSMSupportUtil.getInstance().getFSMHelpers().getAllTransitions(sg)) { if (tr instanceof ContinuationTransition) { TransitionTerminal from = ((ContinuationTransition) tr).getFrom(); if (from instanceof ChoicepointTerminal) { @@ -193,7 +197,7 @@ public class TransitionSupport { } else { NonInitialTransition t = null; - switch (ac.getCommType()) { + switch (mc.getCommType()) { case DATA_DRIVEN: t = FSMFactory.eINSTANCE.createGuardedTransition(); break; @@ -239,22 +243,23 @@ public class TransitionSupport { } if (trans instanceof InitialTransition) { - trans.setName(SupportUtil.getInstance().getRoomUtil().getUniqueInitialTransitionName(sg)); + trans.setName(FSMSupportUtil.getInstance().getFSMUtil().getUniqueInitialTransitionName(sg)); } else { - trans.setName(SupportUtil.getInstance().getRoomUtil().getUniqueTransitionName(sg)); + trans.setName(FSMSupportUtil.getInstance().getFSMUtil().getUniqueTransitionName(sg)); } - ContainerShape targetContainer = SupportUtil.getInstance().getStateGraphContainer((ContainerShape) context.getSourcePictogramElement().eContainer()); - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), sg); + ContainerShape targetContainer = FSMSupportUtil.getInstance().getStateGraphContainer((ContainerShape) context.getSourcePictogramElement().eContainer()); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), sg); if (inherited) { - sg = SupportUtil.getInstance().insertRefinedState(sg, ac, targetContainer, getFeatureProvider()); + sg = FSMSupportUtil.getInstance().insertRefinedState(sg, mc, targetContainer, getFeatureProvider()); } sg.getTransitions().add(trans); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - TransitionPropertyDialog dlg = new TransitionPropertyDialog(shell, SupportUtil.getInstance().getActorClass(getDiagram()), trans); + IFSMDialogFactory factory = getInjector().getInstance(IFSMDialogFactory.class); + ITransitionPropertyDialog dlg = factory.createTransitionPropertyDialog(shell, FSMSupportUtil.getInstance().getModelComponent(getDiagram()), trans); if (dlg.open()==Window.OK) { AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor()); addContext.setNewObject(trans); @@ -291,7 +296,7 @@ public class TransitionSupport { Object bo = getBusinessObjectForPictogramElement(container); if (!(bo instanceof StateGraph)) container = container.getContainer(); - boolean inherited = SupportUtil.getInstance().isInherited(trans, container); + boolean inherited = FSMSupportUtil.getInstance().isInherited(trans, container); IPeCreateService peCreateService = Graphiti.getPeCreateService(); FreeFormConnection connection = peCreateService.createFreeFormConnection(getDiagram()); @@ -313,7 +318,7 @@ public class TransitionSupport { ConnectionDecorator cd = peCreateService .createConnectionDecorator(connection, false, 1.0, true); - Color fillColor = SupportUtil.getInstance().getRoomHelpers().hasDetailCode(trans.getAction())? + Color fillColor = FSMSupportUtil.getInstance().getFSMHelpers().hasDetailCode(trans.getAction())? lineColor:manageColor(FILL_COLOR); createArrow(cd, lineColor, fillColor); @@ -370,7 +375,7 @@ public class TransitionSupport { return false; Transition trans = (Transition) getBusinessObjectForPictogramElement(context.getConnection()); - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), trans); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), trans); if (inherited) return false; @@ -381,21 +386,21 @@ public class TransitionSupport { else tgt = context.getNewAnchor(); - return SupportUtil.getInstance().canConnect(src, tgt, trans, (ContainerShape) context.getTargetPictogramElement().eContainer(), fp); + return FSMSupportUtil.getInstance().canConnect(src, tgt, trans, (ContainerShape) context.getTargetPictogramElement().eContainer(), fp); } @Override public void postReconnect(IReconnectionContext context) { super.postReconnect(context); - TransitionTerminal src = SupportUtil.getInstance().getTransitionTerminal(context.getConnection().getStart(), fp); - TransitionTerminal dst = SupportUtil.getInstance().getTransitionTerminal(context.getConnection().getEnd(), fp); - StateGraph sg = SupportUtil.getInstance().getStateGraph((ContainerShape) context.getTargetPictogramElement().eContainer(), fp); + TransitionTerminal src = FSMSupportUtil.getInstance().getTransitionTerminal(context.getConnection().getStart(), fp); + TransitionTerminal dst = FSMSupportUtil.getInstance().getTransitionTerminal(context.getConnection().getEnd(), fp); + StateGraph sg = FSMSupportUtil.getInstance().getStateGraph((ContainerShape) context.getTargetPictogramElement().eContainer(), fp); // in the following we set source and target of the connection regardless of whether they have changed // if the type of the transition changed we create a new one and open the property dialog - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); + ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); Transition orig = (Transition) getBusinessObjectForPictogramElement(context.getConnection()); Transition trans = null; if (src==null) { @@ -416,7 +421,7 @@ public class TransitionSupport { NonInitialTransition t = null; if (context.getReconnectType().equals(ReconnectionContext.RECONNECT_SOURCE)) { boolean dfltBranch = true; - for (Transition tr : SupportUtil.getInstance().getRoomHelpers().getAllTransitions(sg)) { + for (Transition tr : FSMSupportUtil.getInstance().getFSMHelpers().getAllTransitions(sg)) { if (tr instanceof ContinuationTransition) { TransitionTerminal from = ((ContinuationTransition) tr).getFrom(); if (from instanceof ChoicepointTerminal) { @@ -436,7 +441,7 @@ public class TransitionSupport { trans = t; } else { - NonInitialTransition t = ac.getCommType()==ComponentCommunicationType.DATA_DRIVEN? + NonInitialTransition t = mc.getCommType()==ComponentCommunicationType.DATA_DRIVEN? ((orig instanceof GuardedTransition)? (GuardedTransition)orig : FSMFactory.eINSTANCE.createGuardedTransition() ) @@ -465,7 +470,8 @@ public class TransitionSupport { sg.getTransitions().add(trans); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - TransitionPropertyDialog dlg = new TransitionPropertyDialog(shell, ac, trans); + IFSMDialogFactory factory = getInjector().getInstance(IFSMDialogFactory.class); + ITransitionPropertyDialog dlg = factory.createTransitionPropertyDialog(shell, mc, trans); if (dlg.open()!=Window.OK) { sg.getTransitions().add(orig); sg.getTransitions().remove(trans); @@ -480,7 +486,7 @@ public class TransitionSupport { } doneChanges = true; - Color fillColor = SupportUtil.getInstance().getRoomHelpers().hasDetailCode(trans.getAction())? + Color fillColor = FSMSupportUtil.getInstance().getFSMHelpers().hasDetailCode(trans.getAction())? manageColor(LINE_COLOR):manageColor(FILL_COLOR); updateLabel(trans, context.getConnection(), fillColor); } @@ -522,10 +528,10 @@ public class TransitionSupport { if (conn.getConnectionDecorators().size()>=2) { ConnectionDecorator cd = conn.getConnectionDecorators().get(0); if (cd.getGraphicsAlgorithm() instanceof Polygon) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), t); + ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), t); Color lineColor = inherited? manageColor(INHERITED_COLOR):manageColor(LINE_COLOR); - String code = SupportUtil.getInstance().getRoomHelpers().getAllActionCode(t, ac); + String code = FSMSupportUtil.getInstance().getFSMHelpers().getAllActionCode(t, mc); boolean hasActionCode = code!=null && !code.isEmpty(); Color fillColor = hasActionCode? lineColor : manageColor(FILL_COLOR); if (!equal(cd.getGraphicsAlgorithm().getBackground(), fillColor)) @@ -565,12 +571,12 @@ public class TransitionSupport { boolean updated = false; if (bo instanceof Transition) { - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); + ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); Transition trans = (Transition) bo; Connection conn = (Connection)context.getPictogramElement(); - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), trans); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), trans); Color lineColor = inherited? manageColor(INHERITED_COLOR):manageColor(LINE_COLOR); - String code = SupportUtil.getInstance().getRoomHelpers().getAllActionCode(trans, ac); + String code = FSMSupportUtil.getInstance().getFSMHelpers().getAllActionCode(trans, mc); boolean hasActionCode = code!=null && !code.isEmpty(); Color fillColor = hasActionCode? lineColor : manageColor(FILL_COLOR); updateLabel(trans, conn, fillColor); @@ -587,9 +593,8 @@ public class TransitionSupport { private boolean editable; - public PropertyFeature(IFeatureProvider fp, boolean editable) { - super(fp); - + public PropertyFeature(IFeatureProvider fp, Injector injector, boolean editable) { + super(fp, injector); this.editable = editable; } @@ -603,38 +608,41 @@ public class TransitionSupport { return editable? "Edit Transition Properties" : "View Transition Properties"; } - @Override - public boolean canExecute(ICustomContext context) { + private Pair<Connection, Transition> getTransition(ICustomContext context) { PictogramElement[] pes = context.getPictogramElements(); if (pes != null && pes.length == 1) { PictogramElement pe = pes[0]; if (pe instanceof ConnectionDecorator) pe = (PictogramElement) pe.eContainer(); if (!(pe instanceof Connection)) - return false; + return null; Object bo = getBusinessObjectForPictogramElement(pe); if (bo instanceof Transition) { - return true; + return new Pair<Connection, Transition>((Connection) pe, (Transition) bo); } } - return false; + return null; + } + + @Override + public boolean canExecute(ICustomContext context) { + return getTransition(context)!=null; } @Override public boolean doExecute(ICustomContext context) { - PictogramElement pe = context.getPictogramElements()[0]; - if (pe instanceof ConnectionDecorator) - pe = (PictogramElement) pe.eContainer(); - Transition trans = (Transition) getBusinessObjectForPictogramElement(pe); - Connection conn = (Connection) pe; + Pair<Connection, Transition> pair = getTransition(context); + Transition trans = pair.getValue(); + Connection conn = pair.getKey(); Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - TransitionPropertyDialog dlg = new TransitionPropertyDialog(shell, SupportUtil.getInstance().getActorClass(getDiagram()), trans); + IFSMDialogFactory factory = getInjector().getInstance(IFSMDialogFactory.class); + ITransitionPropertyDialog dlg = factory.createTransitionPropertyDialog(shell, FSMSupportUtil.getInstance().getModelComponent(getDiagram()), trans); if (dlg.open()==Window.OK){ - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), trans); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), trans); Color lineColor = inherited? manageColor(INHERITED_COLOR):manageColor(LINE_COLOR); - Color fillColor = SupportUtil.getInstance().getRoomHelpers().hasDetailCode(trans.getAction())? + Color fillColor = FSMSupportUtil.getInstance().getFSMHelpers().hasDetailCode(trans.getAction())? lineColor:manageColor(FILL_COLOR); updateLabel(trans, conn, fillColor); @@ -688,13 +696,13 @@ public class TransitionSupport { if (pe instanceof ConnectionDecorator) pe = (PictogramElement) pe.eContainer(); Transition trans = (Transition) getBusinessObjectForPictogramElement(pe); - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagram()); - if (ac.getStateMachine()==null) - ac.setStateMachine(FSMFactory.eINSTANCE.createStateGraph()); + ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagram()); + if (mc.getStateMachine()==null) + mc.setStateMachine(FSMFactory.eINSTANCE.createStateGraph()); RefinedTransition rt = FSMFactory.eINSTANCE.createRefinedTransition(); rt.setTarget(trans); - ac.getStateMachine().getRefinedTransitions().add(rt); + mc.getStateMachine().getRefinedTransitions().add(rt); // the connection pe is still linked to the former transition that was refined! ICustomFeature[] features = getFeatureProvider().getCustomFeatures(context); @@ -724,7 +732,7 @@ public class TransitionSupport { Object bo = getBusinessObjectForPictogramElement(pe); if (bo instanceof Transition) { - boolean inherited = SupportUtil.getInstance().isInherited(getDiagram(), (Transition) bo); + boolean inherited = FSMSupportUtil.getInstance().isInherited(getDiagram(), (Transition) bo); if (inherited) return false; @@ -736,14 +744,14 @@ public class TransitionSupport { private IFeatureProvider fp; - public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) { - super(dtp); + public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + super(dtp, injector); this.fp = fp; } @Override public ICreateConnectionFeature[] getCreateConnectionFeatures() { - return new ICreateConnectionFeature[] { new CreateFeature(fp) }; + return new ICreateConnectionFeature[] { new CreateFeature(fp, getInjector()) }; } @Override @@ -782,20 +790,20 @@ public class TransitionSupport { if (bo instanceof Transition) { Transition trans = (Transition) bo; - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagramTypeProvider().getDiagram()); - boolean editable = SupportUtil.getInstance().getRoomHelpers().getActorClass(trans)==ac; + ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagramTypeProvider().getDiagram()); + boolean editable = FSMSupportUtil.getInstance().getFSMHelpers().getModelComponent(trans)==mc; // let's check whether we already refined this transition if (!editable) - if (ac.getStateMachine()!=null) - for (RefinedTransition rt : ac.getStateMachine().getRefinedTransitions()) { + if (mc.getStateMachine()!=null) + for (RefinedTransition rt : mc.getStateMachine().getRefinedTransitions()) { if (rt.getTarget()==trans) { editable = true; break; } } - result.add(new PropertyFeature(fp, editable)); + result.add(new PropertyFeature(fp, getInjector(), editable)); if (!editable) result.add(new RefineTransitionFeature(fp)); @@ -803,12 +811,12 @@ public class TransitionSupport { // Provide quick fix feature only for those edit parts which have // errors, warnings or infos. - ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider() + ArrayList<Diagnostic> diagnostics = ((AbstractFSMEditor) getDiagramTypeProvider() .getDiagramBehavior().getDiagramContainer()) .getDiagnosingModelObserver().getElementDiagonsticMap() .get(bo); if (diagnostics != null) - result.add(new QuickFixFeature(fp)); + result.add(new QuickFixFeature(fp, getInjector())); ICustomFeature features[] = new ICustomFeature[result.size()]; return result.toArray(features); @@ -835,7 +843,7 @@ public class TransitionSupport { IPreferenceStore store = UIBaseActivator.getDefault().getPreferenceStore(); int MAX_LINE_LENGTH = store.getInt(UIBasePreferenceConstants.MAX_LABEL_LINE_LENGTH); int MAX_LINES = store.getInt(UIBasePreferenceConstants.MAX_LABEL_LINES); - String label = SupportUtil.getInstance().getRoomNameProvider().getTransitionLabelName(trans); + String label = FSMSupportUtil.getInstance().getFSMNameProvider().getTransitionLabelName(trans); StringBuilder result = new StringBuilder(); int i = 0; for (; i+MAX_LINE_LENGTH<label.length(); i+=MAX_LINE_LENGTH) { @@ -850,10 +858,10 @@ public class TransitionSupport { } } - class BehaviorProvider extends DefaultToolBehaviorProvider { + class BehaviorProvider extends InjectingBehaviorProvider { - public BehaviorProvider(IDiagramTypeProvider dtp) { - super(dtp); + public BehaviorProvider(IDiagramTypeProvider dtp, Injector injector) { + super(dtp, injector); } @Override @@ -864,9 +872,9 @@ public class TransitionSupport { Object bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); if (bo instanceof Transition) { Transition trans = (Transition) bo; - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagramTypeProvider().getDiagram()); - boolean editable = SupportUtil.getInstance().getRoomHelpers().getActorClass(trans)==ac; - return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider(), editable); + ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagramTypeProvider().getDiagram()); + boolean editable = FSMSupportUtil.getInstance().getFSMHelpers().getModelComponent(trans)==mc; + return new FeatureProvider.PropertyFeature(getDiagramTypeProvider().getFeatureProvider(), getInjector(), editable); } return null; @@ -882,9 +890,9 @@ public class TransitionSupport { EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(pe); if (bo instanceof Transition) { Transition tr = (Transition) bo; - String label = SupportUtil.getInstance().getRoomNameProvider().getTransitionLabelName(tr); - ActorClass ac = SupportUtil.getInstance().getActorClass(getDiagramTypeProvider().getDiagram()); - String code = SupportUtil.getInstance().getRoomHelpers().getAllActionCode(tr, ac); + String label = FSMSupportUtil.getInstance().getFSMNameProvider().getTransitionLabelName(tr); + ModelComponent mc = FSMSupportUtil.getInstance().getModelComponent(getDiagramTypeProvider().getDiagram()); + String code = FSMSupportUtil.getInstance().getFSMHelpers().getAllActionCode(tr, mc); if (code!=null && !code.isEmpty()) { if (label.length()>0) label += "\n"; @@ -912,7 +920,7 @@ public class TransitionSupport { (PictogramElement) pe.eContainer()); // Get Diagnostics associated with the business object - ArrayList<Diagnostic> diagnostics = ((BehaviorEditor) getDiagramTypeProvider() + ArrayList<Diagnostic> diagnostics = ((AbstractFSMEditor) getDiagramTypeProvider() .getDiagramBehavior().getDiagramContainer()) .getDiagnosingModelObserver().getElementDiagonsticMap() .get(bo); @@ -941,9 +949,9 @@ public class TransitionSupport { private FeatureProvider pfp; private BehaviorProvider tbp; - public TransitionSupport(IDiagramTypeProvider dtp, IFeatureProvider fp) { - pfp = new FeatureProvider(dtp,fp); - tbp = new BehaviorProvider(dtp); + public TransitionSupport(IDiagramTypeProvider dtp, IFeatureProvider fp, Injector injector) { + pfp = new FeatureProvider(dtp,fp, injector); + tbp = new BehaviorProvider(dtp, injector); } public IFeatureProvider getFeatureProvider() { diff --git a/plugins/org.eclipse.etrice.ui.behavior/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.behavior/META-INF/MANIFEST.MF index b91a7141e..ab06305fe 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.etrice.ui.behavior/META-INF/MANIFEST.MF @@ -8,7 +8,9 @@ Require-Bundle: org.eclipse.etrice.core.room.ui;bundle-version="0.5.0", org.eclipse.etrice.core.common.ui;bundle-version="0.5.0", org.eclipse.etrice.ui.common.base;bundle-version="0.0.5", org.eclipse.etrice.ui.common;bundle-version="0.5.0", + org.eclipse.etrice.ui.behavior.fsm;bundle-version="0.5.0", org.eclipse.etrice.core.fsm;bundle-version="0.5.0", + org.eclipse.etrice.core.fsm.ui;bundle-version="0.5.0", org.eclipse.graphiti;bundle-version="0.8.0", org.eclipse.graphiti.ui;bundle-version="0.8.0", org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100", diff --git a/plugins/org.eclipse.etrice.ui.behavior/about.html b/plugins/org.eclipse.etrice.ui.behavior/about.html new file mode 100644 index 000000000..c258ef55d --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> +<title>About</title> +</head> +<body lang="EN-US"> +<h2>About This Content</h2> + +<p>June 5, 2006</p> +<h3>License</h3> + +<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>. +For purposes of the EPL, "Program" will mean the Content.</p> + +<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p> + +</body> +</html>
\ No newline at end of file diff --git a/plugins/org.eclipse.etrice.ui.behavior/plugin.xml b/plugins/org.eclipse.etrice.ui.behavior/plugin.xml index 50446ae5b..654136e44 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/plugin.xml +++ b/plugins/org.eclipse.etrice.ui.behavior/plugin.xml @@ -19,7 +19,7 @@ id="org.eclipse.etrice.ui.behavior.diagramType"> </diagramType> <imageProvider - id="org.eclipse.etrice.ui.behavior.ImageProvider"> + id="org.eclipse.etrice.ui.behavior.fsm.provider.ImageProvider"> </imageProvider> </diagramTypeProvider> </extension> @@ -43,8 +43,8 @@ <extension point="org.eclipse.graphiti.ui.imageProviders"> <imageProvider - class="org.eclipse.etrice.ui.behavior.ImageProvider" - id="org.eclipse.etrice.ui.behavior.ImageProvider"> + class="org.eclipse.etrice.ui.behavior.fsm.provider.ImageProvider" + id="org.eclipse.etrice.ui.behavior.fsm.provider.ImageProvider"> </imageProvider> </extension> diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/Activator.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/Activator.java index 13c8d7bf3..9811eac05 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/Activator.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/Activator.java @@ -15,8 +15,12 @@ package org.eclipse.etrice.ui.behavior; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.xtext.ui.shared.SharedStateModule; import org.osgi.framework.BundleContext; +import com.google.inject.Guice; +import com.google.inject.Injector; + /** * The activator class controls the plug-in life cycle */ @@ -28,6 +32,8 @@ public class Activator extends AbstractUIPlugin { // The shared instance private static Activator plugin; + private Injector injector; + /** * The constructor */ @@ -48,6 +54,7 @@ public class Activator extends AbstractUIPlugin { * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext context) throws Exception { + injector = null; plugin = null; super.stop(context); } @@ -83,4 +90,10 @@ public class Activator extends AbstractUIPlugin { return img; } + public Injector getInjector() { + if (injector==null) { + injector = Guice.createInjector(new BehaviorModule(), new SharedStateModule()); + } + return injector; + } } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/BehaviorModule.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/BehaviorModule.java new file mode 100644 index 000000000..5a771b1ed --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/BehaviorModule.java @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior; + +import org.eclipse.etrice.ui.behavior.dialogs.FSMDialogFactory; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory; +import org.eclipse.etrice.ui.behavior.fsm.support.IBehaviorQuickfixProvider; +import org.eclipse.etrice.ui.behavior.quickfix.BehaviorQuickfixProvider; +import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase; +import org.eclipse.xtext.ui.resource.IResourceSetProvider; +import org.eclipse.xtext.ui.resource.XtextResourceSetProvider; + +import com.google.inject.Binder; +import com.google.inject.Module; + +/** + * @author Henrik Rentz-Reichert + * + */ +public class BehaviorModule implements Module { + + /* (non-Javadoc) + * @see com.google.inject.Module#configure(com.google.inject.Binder) + */ + @Override + public void configure(Binder binder) { + binder.bind(IFSMDialogFactory.class).to(FSMDialogFactory.class); + binder.bind(DiagramAccessBase.class).to(DiagramAccess.class); + binder.bind(IBehaviorQuickfixProvider.class).to(BehaviorQuickfixProvider.class); + binder.bind(IResourceSetProvider.class).to(XtextResourceSetProvider.class); + } + +} diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramAccess.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramAccess.java index 28bf94d3e..f88d11073 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramAccess.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramAccess.java @@ -15,11 +15,12 @@ package org.eclipse.etrice.ui.behavior; import org.eclipse.emf.common.command.Command; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.room.RoomModel; -import org.eclipse.etrice.ui.behavior.commands.PopulateDiagramCommand; import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; -import org.eclipse.etrice.ui.behavior.support.DiagramUpdateFeature; +import org.eclipse.etrice.ui.behavior.fsm.commands.PopulateDiagramCommand; +import org.eclipse.etrice.ui.behavior.fsm.support.DiagramUpdateFeature; import org.eclipse.etrice.ui.common.base.commands.UpdateCommand; import org.eclipse.etrice.ui.common.base.support.DiagramAccessBase; import org.eclipse.graphiti.dt.IDiagramTypeProvider; @@ -29,6 +30,19 @@ import org.eclipse.graphiti.ui.services.GraphitiUi; public class DiagramAccess extends DiagramAccessBase { + public DiagramAccess() { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.common.base.support.DiagramAccessBase#injectMembers() + */ + @Override + protected void injectMembers() { + Activator activator = Activator.getDefault(); + activator.getInjector().injectMembers(this); + } + /* (non-Javadoc) * @see org.eclipse.etrice.ui.common.DiagramAccessBase#getDiagramName(org.eclipse.etrice.core.room.StructureClass) */ @@ -75,8 +89,8 @@ public class DiagramAccess extends DiagramAccessBase { */ @Override protected Command getInitialCommand(EObject rootObject, Diagram diagram, TransactionalEditingDomain editingDomain) { - if (rootObject instanceof ActorClass) { - return new PopulateDiagramCommand(diagram, (ActorClass) rootObject, editingDomain); + if (rootObject instanceof ModelComponent) { + return new PopulateDiagramCommand(diagram, (ModelComponent) rootObject, Activator.getDefault().getInjector(), editingDomain); } return null; } @@ -88,7 +102,7 @@ public class DiagramAccess extends DiagramAccessBase { protected Command getUpdateCommand(Diagram diagram, TransactionalEditingDomain editingDomain) { IDiagramTypeProvider dtp = GraphitiUi.getExtensionManager().createDiagramTypeProvider(diagram, DiagramTypeProvider.PROVIDER_ID); //$NON-NLS-1$ IFeatureProvider featureProvider = dtp.getFeatureProvider(); - UpdateCommand cmd = new UpdateCommand(diagram, editingDomain, new DiagramUpdateFeature(featureProvider)); + UpdateCommand cmd = new UpdateCommand(diagram, editingDomain, new DiagramUpdateFeature(featureProvider, Activator.getDefault().getInjector())); if (cmd.updateNeeded()) return cmd; diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramTypeProvider.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramTypeProvider.java index 1148f426e..9b5e4eac1 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramTypeProvider.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/DiagramTypeProvider.java @@ -15,6 +15,8 @@ package org.eclipse.etrice.ui.behavior; import org.eclipse.graphiti.dt.AbstractDiagramTypeProvider; import org.eclipse.graphiti.tb.IToolBehaviorProvider; +import com.google.inject.Injector; + public class DiagramTypeProvider extends AbstractDiagramTypeProvider { public static final String PROVIDER_ID = "org.eclipse.etrice.ui.behavior.diagramTypeProvider"; @@ -26,7 +28,8 @@ public class DiagramTypeProvider extends AbstractDiagramTypeProvider { public DiagramTypeProvider() { super(); - dispatcher = new ProviderDispatcher(this); + Injector injector = Activator.getDefault().getInjector(); + dispatcher = new ProviderDispatcher(this, injector); setFeatureProvider(dispatcher.getFeatureProvider()); } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/ProviderDispatcher.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/ProviderDispatcher.java index f3d405992..f59c3ac4f 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/ProviderDispatcher.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/ProviderDispatcher.java @@ -24,13 +24,14 @@ import org.eclipse.etrice.core.fsm.fSM.TrPoint; import org.eclipse.etrice.core.fsm.fSM.Transition; import org.eclipse.etrice.core.fsm.fSM.util.FSMSwitch; import org.eclipse.etrice.core.naming.RoomFragmentProvider; -import org.eclipse.etrice.ui.behavior.support.ChoicePointSupport; -import org.eclipse.etrice.ui.behavior.support.DiagramUpdateFeature; -import org.eclipse.etrice.ui.behavior.support.InitialPointSupport; -import org.eclipse.etrice.ui.behavior.support.StateGraphSupport; -import org.eclipse.etrice.ui.behavior.support.StateSupport; -import org.eclipse.etrice.ui.behavior.support.TrPointSupport; -import org.eclipse.etrice.ui.behavior.support.TransitionSupport; +import org.eclipse.etrice.ui.behavior.fsm.provider.InjectingFeatureProvider; +import org.eclipse.etrice.ui.behavior.fsm.support.ChoicePointSupport; +import org.eclipse.etrice.ui.behavior.fsm.support.DiagramUpdateFeature; +import org.eclipse.etrice.ui.behavior.fsm.support.InitialPointSupport; +import org.eclipse.etrice.ui.behavior.fsm.support.StateGraphSupport; +import org.eclipse.etrice.ui.behavior.fsm.support.StateSupport; +import org.eclipse.etrice.ui.behavior.fsm.support.TrPointSupport; +import org.eclipse.etrice.ui.behavior.fsm.support.TransitionSupport; import org.eclipse.etrice.ui.common.base.support.CantDeleteFeature; import org.eclipse.etrice.ui.common.base.support.CantRemoveFeature; import org.eclipse.etrice.ui.common.base.support.RemoveBendpointsFeature; @@ -72,9 +73,10 @@ import org.eclipse.graphiti.tb.IDecorator; import org.eclipse.graphiti.tb.IShapeSelectionInfo; import org.eclipse.graphiti.tb.IToolBehaviorProvider; import org.eclipse.graphiti.tb.ShapeSelectionInfoImpl; -import org.eclipse.graphiti.ui.features.DefaultFeatureProvider; import org.eclipse.graphiti.util.IColorConstant; +import com.google.inject.Injector; + public class ProviderDispatcher { private class FeatureProviderSwitch extends FSMSwitch<IFeatureProvider> { @@ -228,10 +230,10 @@ public class ProviderDispatcher { } - private class DispatchingFeatureProvider extends DefaultFeatureProvider { + private class DispatchingFeatureProvider extends InjectingFeatureProvider { - public DispatchingFeatureProvider(IDiagramTypeProvider dtp) { - super(dtp); + public DispatchingFeatureProvider(IDiagramTypeProvider dtp, Injector injector) { + super(dtp, injector); } @Override @@ -284,7 +286,7 @@ public class ProviderDispatcher { @Override public IUpdateFeature getUpdateFeature(IUpdateContext context) { if (context.getPictogramElement() instanceof Diagram) - return new DiagramUpdateFeature(this); + return new DiagramUpdateFeature(this, getInjector()); IFeatureProvider fp = getFeatureProvider(context); if (fp!=null) @@ -500,17 +502,17 @@ public class ProviderDispatcher { private DispatchingToolBehaviorProvider dispatchingBP; - public ProviderDispatcher(IDiagramTypeProvider dtp) { + public ProviderDispatcher(IDiagramTypeProvider dtp, Injector injector) { // create those first before using them - dispatchingFP = new DispatchingFeatureProvider(dtp); + dispatchingFP = new DispatchingFeatureProvider(dtp, injector); dispatchingBP = new DispatchingToolBehaviorProvider(dtp); - stateGraphSupport = new StateGraphSupport(dtp, dispatchingFP); - trPointSupport = new TrPointSupport(dtp, dispatchingFP); - initialPointSupport = new InitialPointSupport(dtp, dispatchingFP); - choicePointSupport = new ChoicePointSupport(dtp, dispatchingFP); - stateSupport = new StateSupport(dtp, dispatchingFP); - transitionSupport = new TransitionSupport(dtp, dispatchingFP); + stateGraphSupport = new StateGraphSupport(dtp, dispatchingFP, injector); + trPointSupport = new TrPointSupport(dtp, dispatchingFP, injector); + initialPointSupport = new InitialPointSupport(dtp, dispatchingFP, injector); + choicePointSupport = new ChoicePointSupport(dtp, dispatchingFP, injector); + stateSupport = new StateSupport(dtp, dispatchingFP, injector); + transitionSupport = new TransitionSupport(dtp, dispatchingFP, injector); featureSwitch = new FeatureProviderSwitch(); behaviorSwitch = new ToolBehaviorProviderSwitch(); diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/ChoicePointPropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/ChoicePointPropertyDialog.java index 7b833399a..e8188e3e3 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/ChoicePointPropertyDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/ChoicePointPropertyDialog.java @@ -9,6 +9,7 @@ import org.eclipse.etrice.core.fsm.fSM.ChoicePoint; import org.eclipse.etrice.core.fsm.fSM.FSMPackage; import org.eclipse.etrice.core.fsm.validation.FSMValidationUtil.Result; import org.eclipse.etrice.ui.behavior.Activator; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IChoicePointPropertyDialog; import org.eclipse.etrice.ui.behavior.support.SupportUtil; import org.eclipse.etrice.ui.common.base.dialogs.AbstractPropertyDialog; import org.eclipse.swt.graphics.Image; @@ -17,7 +18,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.IManagedForm; -public class ChoicePointPropertyDialog extends AbstractPropertyDialog { +public class ChoicePointPropertyDialog extends AbstractPropertyDialog implements IChoicePointPropertyDialog { class NameValidator implements IValidator { @@ -26,7 +27,7 @@ public class ChoicePointPropertyDialog extends AbstractPropertyDialog { if (value instanceof String) { String name = (String) value; - Result result = SupportUtil.getInstance().getValidationUtil().isUniqueName(cp, name); + Result result = SupportUtil.getInstance().getFSMValidationUtil().isUniqueName(cp, name); if (!result.isOk()) return ValidationStatus.error(result.getMsg()); } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/FSMDialogFactory.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/FSMDialogFactory.java new file mode 100644 index 000000000..cdded25fd --- /dev/null +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/FSMDialogFactory.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2014 protos software gmbh (http://www.protos.de). + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * CONTRIBUTORS: + * Henrik Rentz-Reichert (initial contribution) + * + *******************************************************************************/ + +package org.eclipse.etrice.ui.behavior.dialogs; + +import org.eclipse.etrice.core.fsm.fSM.ChoicePoint; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; +import org.eclipse.etrice.core.fsm.fSM.State; +import org.eclipse.etrice.core.fsm.fSM.TrPoint; +import org.eclipse.etrice.core.fsm.fSM.Transition; +import org.eclipse.etrice.core.room.ActorClass; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IChoicePointPropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.ISelectionDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IStatePropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.ITrPointPropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.ITransitionPropertyDialog; +import org.eclipse.swt.widgets.Shell; + +/** + * @author Henrik Rentz-Reichert + * + */ +public class FSMDialogFactory implements IFSMDialogFactory { + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory#createMemberSelectionDialog(org.eclipse.swt.widgets.Shell, org.eclipse.etrice.core.fsm.fSM.ModelComponent) + */ + @Override + public ISelectionDialog createMemberSelectionDialog(Shell shell, ModelComponent mc) { + return new MemberSelectionDialog(shell, (ActorClass) mc); + } + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory#createMessageSelectionDialog(org.eclipse.swt.widgets.Shell, org.eclipse.etrice.core.fsm.fSM.ModelComponent, boolean) + */ + @Override + public ISelectionDialog createMessageSelectionDialog(Shell shell, ModelComponent mc, boolean receiveOnly) { + return new PortMessageSelectionDialog(shell, (ActorClass) mc, receiveOnly); + } + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory#createStatePropertyDialog(org.eclipse.swt.widgets.Shell, org.eclipse.etrice.core.fsm.fSM.ModelComponent, org.eclipse.etrice.core.fsm.fSM.State, boolean) + */ + @Override + public IStatePropertyDialog createStatePropertyDialog(Shell shell, ModelComponent mc, State s, boolean edit) { + return new StatePropertyDialog(shell, (ActorClass) mc, s, edit); + } + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory#createChoicePointPropertyDialog(org.eclipse.swt.widgets.Shell, org.eclipse.etrice.core.fsm.fSM.ChoicePoint) + */ + @Override + public IChoicePointPropertyDialog createChoicePointPropertyDialog(Shell shell, ChoicePoint cp) { + return new ChoicePointPropertyDialog(shell, cp); + } + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory#createTransitionPropertyDialog(org.eclipse.swt.widgets.Shell, org.eclipse.etrice.core.fsm.fSM.ModelComponent, org.eclipse.etrice.core.fsm.fSM.Transition) + */ + @Override + public ITransitionPropertyDialog createTransitionPropertyDialog(Shell shell, ModelComponent mc, Transition trans) { + return new TransitionPropertyDialog(shell, (ActorClass) mc, trans); + } + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.behavior.fsm.dialogs.IFSMDialogFactory#createTrPointPropertyDialog(org.eclipse.swt.widgets.Shell, org.eclipse.etrice.core.fsm.fSM.TrPoint, boolean) + */ + @Override + public ITrPointPropertyDialog createTrPointPropertyDialog(Shell shell, TrPoint tp, boolean subtp) { + return new TrPointPropertyDialog(shell, tp, subtp); + } + +} diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/MemberSelectionDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/MemberSelectionDialog.java index b3fd204e7..aa2bdab26 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/MemberSelectionDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/MemberSelectionDialog.java @@ -19,6 +19,7 @@ import org.eclipse.etrice.core.room.Operation; import org.eclipse.etrice.core.room.StandardOperation; import org.eclipse.etrice.core.ui.RoomUiModule; import org.eclipse.etrice.ui.behavior.Activator; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.ISelectionDialog; import org.eclipse.etrice.ui.behavior.support.SupportUtil; import org.eclipse.jface.layout.TableColumnLayout; import org.eclipse.jface.viewers.ColumnWeightData; @@ -52,7 +53,7 @@ import com.google.inject.Injector; * @author Henrik Rentz-Reichert * */ -public class MemberSelectionDialog extends FormDialog { +public class MemberSelectionDialog extends FormDialog implements ISelectionDialog { private class MemberContentProvider implements IStructuredContentProvider { @@ -123,7 +124,7 @@ public class MemberSelectionDialog extends FormDialog { @Inject ILabelProvider labelProvider; - private Object selected; + private String text; /** * @param shell @@ -200,13 +201,20 @@ public class MemberSelectionDialog extends FormDialog { protected void okPressed() { ISelection selection = viewer.getSelection(); if (selection instanceof IStructuredSelection) { - selected = ((IStructuredSelection) selection).getFirstElement(); + Object selected = ((IStructuredSelection) selection).getFirstElement(); + if (selected instanceof Attribute) { + text = ((Attribute)selected).getName(); + } + else if (selected instanceof Operation) { + String typedArgumentList = SupportUtil.getInstance().getRoomNameProvider().getTypedArgumentList((Operation) selected); + text = ((Operation)selected).getName()+typedArgumentList; + } } super.okPressed(); } - public Object getSelected() { - return selected; + public String getSelected() { + return text; } } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/PortMessageSelectionDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/PortMessageSelectionDialog.java index cf6dac703..a7c61a867 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/PortMessageSelectionDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/PortMessageSelectionDialog.java @@ -20,11 +20,13 @@ import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.room.CommunicationType; import org.eclipse.etrice.core.room.InterfaceItem; import org.eclipse.etrice.core.room.Message; +import org.eclipse.etrice.core.room.Port; import org.eclipse.etrice.core.room.PortClass; import org.eclipse.etrice.core.room.PortOperation; import org.eclipse.etrice.core.room.util.RoomHelpers; import org.eclipse.etrice.core.ui.RoomUiModule; import org.eclipse.etrice.ui.behavior.Activator; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.ISelectionDialog; import org.eclipse.etrice.ui.behavior.support.SupportUtil; import org.eclipse.jface.layout.TreeColumnLayout; import org.eclipse.jface.viewers.ColumnWeightData; @@ -59,9 +61,9 @@ import com.google.inject.Injector; * @author Henrik Rentz-Reichert * */ -public class PortMessageSelectionDialog extends FormDialog { +public class PortMessageSelectionDialog extends FormDialog implements ISelectionDialog { - public static class MethodItemPair { + private static class MethodItemPair { InterfaceItem item; public MethodItemPair(InterfaceItem item) { @@ -70,7 +72,7 @@ public class PortMessageSelectionDialog extends FormDialog { } } - public static class MsgItemPair extends MethodItemPair { + private static class MsgItemPair extends MethodItemPair { Message msg; boolean out; @@ -81,7 +83,7 @@ public class PortMessageSelectionDialog extends FormDialog { } } - public static class OperationItemPair extends MethodItemPair { + private static class OperationItemPair extends MethodItemPair { PortOperation op; public OperationItemPair(InterfaceItem item, PortOperation op) { @@ -248,7 +250,7 @@ public class PortMessageSelectionDialog extends FormDialog { private ActorClass ac; private boolean recvOnly; private TreeViewer viewer; - private MethodItemPair selected = null; + private String selected = null; @Inject ILabelProvider labelProvider; @@ -328,14 +330,28 @@ public class PortMessageSelectionDialog extends FormDialog { ISelection selection = viewer.getSelection(); if (selection instanceof IStructuredSelection) { Object element = ((IStructuredSelection) selection).getFirstElement(); - if (element instanceof MethodItemPair) { - selected = (MethodItemPair) element; + if (element instanceof MsgItemPair) { + MsgItemPair pair = (MsgItemPair) element; + if (pair.out) { + String data = pair.msg.getData()!=null? pair.msg.getData().getName() : ""; + String index = ""; + if (pair.item instanceof Port && ((Port)pair.item).getMultiplicity()!=1) + index = "[idx]"; + selected = pair.item.getName()+index+"."+pair.msg.getName()+"("+data+")"; + } + else + selected = pair.item.getName()+"."+pair.msg.getName(); + } + if (element instanceof OperationItemPair) { + OperationItemPair pair = (OperationItemPair) element; + String arglist = SupportUtil.getInstance().getRoomNameProvider().getArguments(pair.op); + selected = pair.item.getName()+"."+pair.op.getName()+arglist; } } super.okPressed(); } - public MethodItemPair getMethodItemPair() { + public String getSelected() { return selected; } } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java index 74dc332b5..8286d4d85 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java @@ -16,6 +16,11 @@ import org.eclipse.etrice.core.fsm.validation.FSMValidationUtil.Result; import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.room.util.RoomHelpers; import org.eclipse.etrice.ui.behavior.Activator; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.AbstractMemberAwarePropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.DetailCodeToString; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.IStatePropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.QuickFixDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.StringToDetailCode; import org.eclipse.etrice.ui.behavior.support.SupportUtil; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.graphics.Image; @@ -25,7 +30,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.IManagedForm; -public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog { +public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog implements IStatePropertyDialog { class NameValidator implements IValidator { @@ -34,7 +39,7 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog { if (value instanceof String) { String name = (String) value; - Result result = SupportUtil.getInstance().getValidationUtil().isUniqueName(state, name); + Result result = SupportUtil.getInstance().getFSMValidationUtil().isUniqueName(state, name); if (!result.isOk()) return ValidationStatus.error(result.getMsg()); } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TrPointPropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TrPointPropertyDialog.java index ec3e2f706..81fdea93f 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TrPointPropertyDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TrPointPropertyDialog.java @@ -10,6 +10,7 @@ import org.eclipse.etrice.core.fsm.fSM.TrPoint; import org.eclipse.etrice.core.fsm.fSM.TransitionPoint; import org.eclipse.etrice.core.fsm.validation.FSMValidationUtil.Result; import org.eclipse.etrice.ui.behavior.Activator; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.ITrPointPropertyDialog; import org.eclipse.etrice.ui.behavior.support.SupportUtil; import org.eclipse.etrice.ui.common.base.dialogs.AbstractPropertyDialog; import org.eclipse.swt.graphics.Image; @@ -18,16 +19,16 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.IManagedForm; -public class TrPointPropertyDialog extends AbstractPropertyDialog { +public class TrPointPropertyDialog extends AbstractPropertyDialog implements ITrPointPropertyDialog { - class NameValidator implements IValidator { + protected class NameValidator implements IValidator { @Override public IStatus validate(Object value) { if (value instanceof String) { String name = (String) value; - Result result = SupportUtil.getInstance().getValidationUtil().isUniqueName(tp, name); + Result result = SupportUtil.getInstance().getFSMValidationUtil().isUniqueName(tp, name); if (!result.isOk()) return ValidationStatus.error(result.getMsg()); } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java index a69ebdeec..270972264 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java @@ -21,6 +21,7 @@ import org.eclipse.etrice.core.fsm.fSM.RefinedTransition; import org.eclipse.etrice.core.fsm.fSM.Transition; import org.eclipse.etrice.core.fsm.fSM.Trigger; import org.eclipse.etrice.core.fsm.fSM.TriggeredTransition; +import org.eclipse.etrice.core.fsm.util.FSMHelpers; import org.eclipse.etrice.core.fsm.validation.FSMValidationUtil.Result; import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.room.CommunicationType; @@ -29,6 +30,10 @@ import org.eclipse.etrice.core.room.Message; import org.eclipse.etrice.core.room.ProtocolClass; import org.eclipse.etrice.core.room.util.RoomHelpers; import org.eclipse.etrice.ui.behavior.Activator; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.AbstractMemberAwarePropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.DetailCodeToString; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.ITransitionPropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.dialogs.StringToDetailCode; import org.eclipse.etrice.ui.behavior.support.SupportUtil; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -60,14 +65,21 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.ui.forms.IManagedForm; import org.eclipse.ui.forms.widgets.FormToolkit; -public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog { +public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog implements ITransitionPropertyDialog { - private class TriggerContentProvider implements IStructuredContentProvider { + protected static class TriggerContentProvider implements IStructuredContentProvider { + + private Transition trans; + @Override public void dispose() {} @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput instanceof Transition) { + trans = (Transition) newInput; + } + } @Override public Object[] getElements(Object inputElement) { @@ -79,20 +91,20 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog } - private class TriggerLabelProvider extends LabelProvider implements + protected static class TriggerLabelProvider extends LabelProvider implements IBaseLabelProvider { @Override public String getText(Object element) { if (element instanceof Trigger) { Trigger trig = (Trigger) element; - return SupportUtil.getInstance().getRoomNameProvider().getTriggerLabel(trig); + return SupportUtil.getInstance().getFSMNameProvider().getTriggerLabel(trig); } return super.getText(element); } } - private class MessageFromInterfaceContentProvider implements IStructuredContentProvider { + protected static class MessageFromInterfaceContentProvider implements IStructuredContentProvider { private Trigger currentTrigger = null; @Override @@ -102,6 +114,8 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (newInput instanceof Trigger) currentTrigger = (Trigger) newInput; + else + currentTrigger = null; } @Override @@ -118,34 +132,41 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog } - private class MessageFromInterfaceLabelProvider extends LabelProvider implements + protected static class MessageFromInterfaceLabelProvider extends LabelProvider implements IBaseLabelProvider { @Override public String getText(Object element) { if (element instanceof MessageFromIf) { MessageFromIf mif = (MessageFromIf) element; - return SupportUtil.getInstance().getRoomNameProvider().getMsgFromIfLabel(mif); + return SupportUtil.getInstance().getFSMNameProvider().getMsgFromIfLabel(mif); } return super.getText(element); } } - private class NameValidator implements IValidator { + protected static class NameValidator implements IValidator { + + private Transition trans; + public NameValidator(Transition trans) { + this.trans = trans; + } + @Override public IStatus validate(Object value) { if (value instanceof String) { String name = (String) value; - Result result = SupportUtil.getInstance().getValidationUtil().isUniqueName(trans, name); + Result result = SupportUtil.getInstance().getFSMValidationUtil().isUniqueName(trans, name); if (!result.isOk()) return ValidationStatus.error(result.getMsg()); } return Status.OK_STATUS; } } - private class GuardValidator implements IValidator { + + protected static class GuardValidator implements IValidator { private String text; @@ -161,7 +182,7 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog return ValidationStatus.error(text); } else if (value instanceof DetailCode) { - if (SupportUtil.getInstance().getRoomHelpers().getDetailCode((DetailCode)value).trim().isEmpty()) + if (SupportUtil.getInstance().getFSMHelpers().getDetailCode((DetailCode)value).trim().isEmpty()) return ValidationStatus.error(text); } return Status.OK_STATUS; @@ -192,6 +213,8 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog super(shell, "Edit Transition", ac); this.trans = trans; + Activator.getDefault().getInjector().injectMembers(this); + m2s = new DetailCodeToString(); m2s_null_empty = new DetailCodeToString(true); s2m = new StringToDetailCode(); @@ -209,8 +232,8 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog refined = null; if (inherited) { - if (getActorClass().getStateMachine()!=null) - for (RefinedTransition rt : getActorClass().getStateMachine().getRefinedTransitions()) { + if (getModelComponent().getStateMachine()!=null) + for (RefinedTransition rt : getModelComponent().getStateMachine().getRefinedTransitions()) { if (rt.getTarget()==trans) { refined = rt; break; @@ -231,7 +254,7 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog protected void createContent(IManagedForm mform, Composite body, DataBindingContext bindingContext) { if (!(trans instanceof InitialTransition)) { - NameValidator nv = new NameValidator(); + NameValidator nv = new NameValidator(trans); if (inherited) { createFixedText(body, "&Name:", trans.getName(), false); @@ -271,7 +294,7 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog } } - RoomHelpers roomHelpers = SupportUtil.getInstance().getRoomHelpers(); + FSMHelpers roomHelpers = SupportUtil.getInstance().getFSMHelpers(); if (trans instanceof GuardedTransition) { if (inherited) { @@ -310,7 +333,7 @@ public class TransitionPropertyDialog extends AbstractMemberAwarePropertyDialog } { - String code = roomHelpers.getInheritedActionCode(trans, getActorClass()); + String code = roomHelpers.getInheritedActionCode(trans, getModelComponent()); if (code!=null){ Text baseActionCode = createFixedText(body, "Base Action Code:", code, true); setTextSelectionAndFocus(baseActionCode, codeSelectionString); diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java index 2081340de..a5d4c7c69 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorEditor.java @@ -19,18 +19,20 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.etrice.core.fsm.fSM.FSMFactory; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.RefinedState; import org.eclipse.etrice.core.fsm.fSM.State; import org.eclipse.etrice.core.fsm.fSM.StateGraph; +import org.eclipse.etrice.core.fsm.util.FSMHelpers; import org.eclipse.etrice.core.room.ActorClass; -import org.eclipse.etrice.core.room.RoomModel; import org.eclipse.etrice.core.room.StructureClass; -import org.eclipse.etrice.core.room.util.RoomHelpers; +import org.eclipse.etrice.core.ui.editor.RoomEditor; import org.eclipse.etrice.ui.behavior.Activator; -import org.eclipse.etrice.ui.behavior.markers.DiagnosingModelObserver; -import org.eclipse.etrice.ui.behavior.support.ContextSwitcher; +import org.eclipse.etrice.ui.behavior.fsm.editor.AbstractFSMEditor; +import org.eclipse.etrice.ui.behavior.fsm.support.ContextSwitcher; +import org.eclipse.etrice.ui.behavior.fsm.support.FSMSupportUtil; import org.eclipse.etrice.ui.behavior.support.SupportUtil; -import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor; +import org.eclipse.etrice.ui.common.commands.ChangeDiagramInputJob; import org.eclipse.graphiti.dt.IDiagramTypeProvider; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.IUpdateContext; @@ -38,22 +40,19 @@ import org.eclipse.graphiti.features.context.impl.UpdateContext; import org.eclipse.graphiti.mm.pictograms.Diagram; import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.services.Graphiti; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.graphics.Image; import com.google.common.base.Function; -public class BehaviorEditor extends RoomDiagramEditor { +public class BehaviorEditor extends AbstractFSMEditor { public static final String BEHAVIOR_EDITOR_ID = "org.eclipse.etrice.ui.behavior.editor.BehaviorEditor"; - private DiagnosingModelObserver diagnosingModelObserver; + private boolean showLostDiagramInputDialog = true; public BehaviorEditor() { - super(); - } - - public DiagnosingModelObserver getDiagnosingModelObserver() { - return diagnosingModelObserver; + super(RoomEditor.class); } @Override @@ -62,24 +61,6 @@ public class BehaviorEditor extends RoomDiagramEditor { } @Override - public void initializeGraphicalViewer() { - // Start observing the Room Model for rendering Markers - diagnosingModelObserver = new DiagnosingModelObserver(); - diagnosingModelObserver.observeRoomModel((RoomModel)getActorClass().eResource().getContents().get(0)); - - super.initializeGraphicalViewer(); - - Command cmd = new RecordingCommand(getEditingDomain()) { - @Override - protected void doExecute() { - ContextSwitcher.switchTop(getDiagramTypeProvider().getDiagram()); - } - }; - getEditingDomain().getCommandStack().execute(cmd); - getEditingDomain().getCommandStack().flush(); - } - - @Override public void dispose() { // Stop observing the Room Model diagnosingModelObserver.removeObserver(); @@ -137,7 +118,7 @@ public class BehaviorEditor extends RoomDiagramEditor { */ protected void removeUnusedRefinedStates() { Diagram diagram = getDiagramTypeProvider().getDiagram(); - ActorClass ac = SupportUtil.getInstance().getActorClass(diagram); + ModelComponent ac = FSMSupportUtil.getInstance().getModelComponent(diagram); if (ac.getStateMachine()!=null) { ArrayList<RefinedState> toBeRemoved = new ArrayList<RefinedState>(); @@ -157,7 +138,7 @@ public class BehaviorEditor extends RoomDiagramEditor { * @return */ private boolean isUnused(RefinedState s) { - RoomHelpers roomHelpers = SupportUtil.getInstance().getRoomHelpers(); + FSMHelpers roomHelpers = SupportUtil.getInstance().getFSMHelpers(); if (roomHelpers.hasDirectSubStructure(s)) return false; if (roomHelpers.hasDetailCode(s.getEntryCode())) @@ -170,7 +151,7 @@ public class BehaviorEditor extends RoomDiagramEditor { protected void removeEmptySubgraphs() { Diagram diagram = getDiagramTypeProvider().getDiagram(); - RoomHelpers roomHelpers = SupportUtil.getInstance().getRoomHelpers(); + FSMHelpers roomHelpers = SupportUtil.getInstance().getFSMHelpers(); // if our current context is an empty state graph we go one level up StateGraph current = ContextSwitcher.getCurrentStateGraph(diagram); @@ -208,13 +189,13 @@ public class BehaviorEditor extends RoomDiagramEditor { } protected void rebaseRefinedStates() { - ActorClass ac = getActorClass(); + ModelComponent ac = getModelComponent(); if (ac.getStateMachine()==null) return; - Function<RefinedState, String> nameProvider = SupportUtil.getInstance().getRoomNameProvider().getRefinedStateNameProvider(); - Map<RefinedState, RefinedState> rs2parent = SupportUtil.getInstance().getRoomHelpers().getRefinedStatesToRelocate(ac, nameProvider); + Function<RefinedState, String> nameProvider = SupportUtil.getInstance().getFSMNameProvider().getRefinedStateNameProvider(); + Map<RefinedState, RefinedState> rs2parent = SupportUtil.getInstance().getFSMHelpers().getRefinedStatesToRelocate(ac, nameProvider); // move all to the new context for (RefinedState rs : rs2parent.keySet()) { @@ -235,8 +216,33 @@ public class BehaviorEditor extends RoomDiagramEditor { diagramTypeProvider.getDiagramBehavior().refresh(); } - @Override protected StructureClass getStructureClass() { - return getActorClass(); + return (StructureClass) getModelComponent(); + } + + + protected void handleMissingDiagramBo(Diagram diagram){ + if(!showLostDiagramInputDialog) + return; + + // show only once + showLostDiagramInputDialog = false; + MessageDialog dialog = new MessageDialog(getGraphicalControl().getShell(), + "Diagram out-dated", null, + "Diagram input lost. Cannot find ROOM file or class for "+diagram.getName() +"\n\n" + + "Please ensure that no whitespace or special characters are contained in any related path, file or project", + MessageDialog.ERROR, new String[] { "OK", "Reconnect Diagram" }, 0); + int result = dialog.open(); + + if(result == 1) + new ChangeDiagramInputJob("Change input for "+diagram.getName(), this).schedule(); + } + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase#getModel() + */ + @Override + public EObject getModel() { + return getActorClass().eContainer(); } } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorExporter.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorExporter.java index d78dcd056..135abdd1f 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorExporter.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/editor/BehaviorExporter.java @@ -14,11 +14,11 @@ package org.eclipse.etrice.ui.behavior.editor; import java.io.File; -import org.eclipse.etrice.core.room.ActorClass; +import org.eclipse.etrice.core.fsm.fSM.ModelComponent; import org.eclipse.etrice.core.fsm.fSM.State; import org.eclipse.etrice.core.fsm.fSM.StateGraph; import org.eclipse.etrice.ui.behavior.DiagramAccess; -import org.eclipse.etrice.ui.behavior.support.SupportUtil; +import org.eclipse.etrice.ui.behavior.fsm.support.FSMSupportUtil; import org.eclipse.etrice.ui.common.base.editor.DiagramExporter; import org.eclipse.ui.PlatformUI; @@ -26,7 +26,7 @@ public class BehaviorExporter { private static final String SUFFIX = "_behavior"; - public static void export(ActorClass ac, String folder) { + public static void export(ModelComponent ac, String folder) { DiagramAccess da = new DiagramAccess(); boolean wasOpen = false; @@ -37,10 +37,10 @@ public class BehaviorExporter { editor = (BehaviorEditor) da.openDiagramEditor(ac); if (editor!=null) { - String filename = folder+File.separatorChar+ac.getName()+SUFFIX; + String filename = folder+File.separatorChar+ac.getComponentName()+SUFFIX; DiagramExporter.export(editor, filename); - exportSubGraphsRecursively(ac.getStateMachine(), editor, folder+File.separatorChar+ac.getName()); + exportSubGraphsRecursively(ac.getStateMachine(), editor, folder+File.separatorChar+ac.getComponentName()); if (!wasOpen) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editor, false); @@ -52,9 +52,9 @@ public class BehaviorExporter { return; for (State state : sg.getStates()) { - if (SupportUtil.getInstance().getRoomHelpers().hasDirectSubStructure(state)) { + if (FSMSupportUtil.getInstance().getFSMHelpers().hasDirectSubStructure(state)) { if (editor.showStateGraph(state.getSubgraph())) { - String filename = basename+"_"+SupportUtil.getInstance().getRoomNameProvider().getStatePathName(state)+SUFFIX; + String filename = basename+"_"+FSMSupportUtil.getInstance().getFSMNameProvider().getStatePathName(state)+SUFFIX; DiagramExporter.export(editor, filename); } diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/quickfix/BehaviorQuickfixProvider.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/quickfix/BehaviorQuickfixProvider.java index 946741daf..d7512003e 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/quickfix/BehaviorQuickfixProvider.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/quickfix/BehaviorQuickfixProvider.java @@ -33,6 +33,7 @@ import org.eclipse.etrice.core.room.Message; import org.eclipse.etrice.ui.behavior.dialogs.StatePropertyDialog; import org.eclipse.etrice.ui.behavior.dialogs.StatePropertyDialog.Where; import org.eclipse.etrice.ui.behavior.dialogs.TransitionPropertyDialog; +import org.eclipse.etrice.ui.behavior.fsm.support.IBehaviorQuickfixProvider; import org.eclipse.etrice.ui.behavior.support.SupportUtil; import org.eclipse.etrice.ui.common.base.quickfix.AbstractQuickfixProvider; import org.eclipse.etrice.ui.common.base.quickfix.IDiagramModification; @@ -60,7 +61,7 @@ import org.eclipse.xtext.validation.FeatureBasedDiagnostic; * @author jayant * */ -public class BehaviorQuickfixProvider extends AbstractQuickfixProvider { +public class BehaviorQuickfixProvider extends AbstractQuickfixProvider implements IBehaviorQuickfixProvider { private static final String ADD_IMG = "icons/quickfix/add.gif"; private static final String SUB_IMG = "icons/quickfix/add.gif"; @@ -113,7 +114,7 @@ public class BehaviorQuickfixProvider extends AbstractQuickfixProvider { // trigger and add it to the state graph TriggeredTransition trans = FSMFactory.eINSTANCE .createTriggeredTransition(); - trans.setName(SupportUtil.getInstance().getRoomUtil() + trans.setName(SupportUtil.getInstance().getFSMUtil() .getUniqueTransitionName((StateGraph) state .eContainer())); Trigger tri = FSMFactory.eINSTANCE diff --git a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java index e7a30caaa..f4bea3ecb 100644 --- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java +++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/SupportUtil.java @@ -8,64 +8,14 @@ package org.eclipse.etrice.ui.behavior.support; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.util.EcoreUtil; -import org.eclipse.etrice.core.fsm.fSM.ChoicePoint; -import org.eclipse.etrice.core.fsm.fSM.ChoicepointTerminal; -import org.eclipse.etrice.core.fsm.fSM.EntryPoint; -import org.eclipse.etrice.core.fsm.fSM.ExitPoint; -import org.eclipse.etrice.core.fsm.fSM.FSMFactory; -import org.eclipse.etrice.core.fsm.fSM.InitialTransition; -import org.eclipse.etrice.core.fsm.fSM.NonInitialTransition; -import org.eclipse.etrice.core.fsm.fSM.RefinedState; -import org.eclipse.etrice.core.fsm.fSM.State; -import org.eclipse.etrice.core.fsm.fSM.StateGraph; -import org.eclipse.etrice.core.fsm.fSM.StateGraphItem; -import org.eclipse.etrice.core.fsm.fSM.StateGraphNode; -import org.eclipse.etrice.core.fsm.fSM.StateTerminal; -import org.eclipse.etrice.core.fsm.fSM.SubStateTrPointTerminal; -import org.eclipse.etrice.core.fsm.fSM.TrPoint; -import org.eclipse.etrice.core.fsm.fSM.TrPointTerminal; -import org.eclipse.etrice.core.fsm.fSM.Transition; -import org.eclipse.etrice.core.fsm.fSM.TransitionTerminal; import org.eclipse.etrice.core.naming.RoomNameProvider; import org.eclipse.etrice.core.room.ActorClass; import org.eclipse.etrice.core.room.util.RoomHelpers; -import org.eclipse.etrice.core.room.util.RoomUtil; import org.eclipse.etrice.core.ui.RoomUiModule; -import org.eclipse.etrice.core.validation.ValidationUtil; -import org.eclipse.etrice.ui.behavior.commands.StateGraphContext; -import org.eclipse.etrice.ui.behavior.support.IPositionProvider.Pos; -import org.eclipse.etrice.ui.behavior.support.IPositionProvider.PosAndSize; -import org.eclipse.etrice.ui.common.base.support.CommonSupportUtil; -import org.eclipse.graphiti.datatypes.ILocation; -import org.eclipse.graphiti.features.IFeatureProvider; -import org.eclipse.graphiti.features.context.impl.AddConnectionContext; -import org.eclipse.graphiti.features.context.impl.AddContext; -import org.eclipse.graphiti.features.context.impl.LayoutContext; -import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; -import org.eclipse.graphiti.mm.algorithms.styles.Point; -import org.eclipse.graphiti.mm.pictograms.Anchor; -import org.eclipse.graphiti.mm.pictograms.Connection; -import org.eclipse.graphiti.mm.pictograms.ConnectionDecorator; -import org.eclipse.graphiti.mm.pictograms.ContainerShape; +import org.eclipse.etrice.ui.behavior.fsm.support.FSMSupportUtil; import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.graphiti.mm.pictograms.FreeFormConnection; -import org.eclipse.graphiti.mm.pictograms.PictogramElement; -import org.eclipse.graphiti.mm.pictograms.Shape; import org.eclipse.graphiti.services.Graphiti; -import org.eclipse.graphiti.services.IGaService; -import org.eclipse.graphiti.services.ILinkService; import com.google.inject.Inject; import com.google.inject.Injector; @@ -74,17 +24,10 @@ import com.google.inject.Injector; * @author Henrik Rentz-Reichert - Initial contribution and API * */ -public class SupportUtil { - - private static final String INITIAL = "init"; - private static final String STATE = "state:"; - private static final String TP = "tp:"; - private static final String CP = "cp:"; - private static final String SEP = "."; +public class SupportUtil extends FSMSupportUtil { private static SupportUtil instance = null; - - + /** * @return the instance */ @@ -99,97 +42,16 @@ public class SupportUtil { @Inject private RoomHelpers roomHelpers; @Inject - private ValidationUtil validationUtil; - @Inject private RoomNameProvider roomNameProvider; - @Inject - private RoomUtil roomUtil; - /** - * @return the roomHelpers - */ public RoomHelpers getRoomHelpers() { return roomHelpers; } - - /** - * @return the validationUtil - */ - public ValidationUtil getValidationUtil() { - return validationUtil; - } - /** - * @return the roomUtil - */ - public RoomUtil getRoomUtil() { - return roomUtil; - } - - /** - * @return the roomNameProvider - */ public RoomNameProvider getRoomNameProvider() { return roomNameProvider; } - - public EObject getOwnObject(EObject obj, ResourceSet rs) { - URI uri = EcoreUtil.getURI(obj); - EObject own = rs.getEObject(uri, true); - assert(own!=null): "own object must exist"; - return own; - } - - public boolean isInherited(StateGraphItem item, ContainerShape cs) { - EObject container = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(cs); - if (container instanceof StateGraph) { - StateGraph sg = (StateGraph) container; - return item.eContainer()!=sg; - } - else if (container instanceof State) { - assert(item instanceof EntryPoint || item instanceof ExitPoint): "this MUST be an entry or exit point"; - - // have to check whether the State is inherited - State s = (State) container; - ContainerShape sCont = cs.getContainer(); - EObject cls = sCont.getLink().getBusinessObjects().get(0); - return s.eContainer()!=cls; - } - - return false; - } - - public boolean isInherited(Diagram diag, EObject obj) { - return roomHelpers.getActorClass(obj)!=getActorClass(diag); - } - - public boolean showAsInherited(Diagram diag, State obj) { - - if (obj instanceof RefinedState) - return true; - - return roomHelpers.getActorClass(obj)!=getActorClass(diag); - } - - public Diagram getDiagram(GraphicsAlgorithm ga) { - if (ga.eContainer() instanceof GraphicsAlgorithm) - return getDiagram((GraphicsAlgorithm)ga.eContainer()); - return getDiagram(ga.getPictogramElement()); - } - /** - * @param pictogramElement - * @return - */ - public Diagram getDiagram(PictogramElement pe) { - while (pe.eContainer()!=null) { - if (pe.eContainer() instanceof Diagram) - return (Diagram) pe.eContainer(); - pe = (PictogramElement) pe.eContainer(); - } - return null; - } - public ActorClass getActorClass(Diagram diag) { EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diag); if (bo instanceof ActorClass) @@ -197,752 +59,4 @@ public class SupportUtil { return null; } - /** - * @param sg - * @param ac - * @param targetContainer - * @param fp - * @return - */ - public StateGraph insertRefinedState(StateGraph sg, ActorClass ac, ContainerShape targetContainer, IFeatureProvider fp) { - sg = getSubGraphOfRefinedStateFor((State) sg.eContainer(), ac); - fp.link(targetContainer, sg); - return sg; - } - - /** - * @param sg - * @param ac - * @param targetContainer - */ - public void undoInsertRefinedState(StateGraph sg, ActorClass ac, - ContainerShape targetContainer, IFeatureProvider fp) { - RefinedState rs = (RefinedState) sg.eContainer(); - fp.link(targetContainer, rs.getTarget().getSubgraph()); - - if (!(roomHelpers.hasDetailCode(rs.getEntryCode()) || roomHelpers.hasDetailCode(rs.getExitCode()))) { - ac.getStateMachine().getStates().remove(rs); - } - } - - /** - * @param s - * @param ac - * @return - */ - public StateGraph getSubGraphOfRefinedStateFor(State s, ActorClass ac) { - RefinedState rs = getRefinedStateFor(s, ac); - - if (rs.getSubgraph()==null) - rs.setSubgraph(FSMFactory.eINSTANCE.createStateGraph()); - - return rs.getSubgraph(); - } - - public RefinedState getRefinedStateFor(State s, ActorClass ac) { - HashMap<State, RefinedState> target2rs = new HashMap<State, RefinedState>(); - for (State st : ac.getStateMachine().getStates()) { - if (st instanceof RefinedState) - target2rs.put(((RefinedState) st).getTarget(), (RefinedState) st); - } - - RefinedState rs = null; - - // do we already have a RefinedState pointing to s? - if (target2rs.containsKey(s)) { - rs = target2rs.get(s); - } - else { - // we have to create one and place it in the best fitting context - StateGraph sg = null; - State parent = s; - while (parent.eContainer().eContainer() instanceof State) { - parent = (State) s.eContainer().eContainer(); - if (target2rs.containsKey(parent)) { - RefinedState bestFitting = target2rs.get(parent); - if (bestFitting.getSubgraph()==null) - bestFitting.setSubgraph(FSMFactory.eINSTANCE.createStateGraph()); - sg = bestFitting.getSubgraph(); - break; - } - } - - if (sg==null) - sg = ac.getStateMachine(); - - rs = FSMFactory.eINSTANCE.createRefinedState(); - rs.setTarget(s); - sg.getStates().add(rs); - } - return rs; - } - - /** - * @param state - * @param diagram - * @return - */ - public State getTargettingState(State state, Diagram diagram) { - ActorClass ac = getActorClass(diagram); - return roomHelpers.getTargettingState(state, ac); - } - - /** - * This method exploits the fact that the immediate children of the diagram are - * associated with the state graphs. - * - * @param shape - * @return the container shape that is associated with the state graph of the diagram - */ - public ContainerShape getStateGraphContainer(ContainerShape shape) { - while (shape!=null) { - ContainerShape parent = shape.getContainer(); - if (parent instanceof Diagram) - return shape; - shape = parent; - } - return null; - } - - public StateGraph getStateGraph(ContainerShape cs, IFeatureProvider fp) { - ContainerShape shape = getStateGraphContainer(cs); - Object bo = fp.getBusinessObjectForPictogramElement(shape); - if (bo instanceof StateGraph) - return (StateGraph) bo; - else - assert(false): "state graph expected"; - - return null; - } - - public TransitionTerminal getTransitionTerminal(Anchor anchor, IFeatureProvider fp) { - if (anchor != null) { - Object obj = fp.getBusinessObjectForPictogramElement(anchor.getParent()); - if (obj instanceof TrPoint) { - Object parent = fp.getBusinessObjectForPictogramElement((ContainerShape) anchor.getParent().eContainer()); - if (parent instanceof State) { - State state = (parent instanceof RefinedState)? ((RefinedState)parent).getTarget() : (State)parent; - SubStateTrPointTerminal sstpt = FSMFactory.eINSTANCE.createSubStateTrPointTerminal(); - sstpt.setState(state); - sstpt.setTrPoint((TrPoint) obj); - return sstpt; - } - else { - TrPointTerminal tpt = FSMFactory.eINSTANCE.createTrPointTerminal(); - tpt.setTrPoint((TrPoint) obj); - return tpt; - } - } - else if (obj instanceof State) { - State state = (obj instanceof RefinedState)? ((RefinedState)obj).getTarget() : (State)obj; - StateTerminal st = FSMFactory.eINSTANCE.createStateTerminal(); - st.setState(state); - return st; - } - else if (obj instanceof ChoicePoint) { - ChoicepointTerminal ct = FSMFactory.eINSTANCE.createChoicepointTerminal(); - ct.setCp((ChoicePoint) obj); - return ct; - } - } - return null; - } - - public boolean isInitialPoint(Anchor anchor, IFeatureProvider fp) { - if (anchor!=null) { - Object obj = fp.getBusinessObjectForPictogramElement(anchor.getParent()); - if (obj instanceof StateGraph) { - Object parent = fp.getBusinessObjectForPictogramElement((ContainerShape) anchor.getParent().eContainer()); - if (parent instanceof StateGraph) - return true; - } - } - return false; - } - - public boolean canConnect(Anchor asrc, Anchor atgt, ContainerShape cs, IFeatureProvider fp) { - return canConnect(asrc, atgt, null, cs, fp); - } - - public boolean canConnect(Anchor asrc, Anchor atgt, Transition trans, ContainerShape cs, IFeatureProvider fp) { - TransitionTerminal src = getTransitionTerminal(asrc, fp); - TransitionTerminal tgt = getTransitionTerminal(atgt, fp); - - if (src==null && !isInitialPoint(asrc, fp)) - return false; - if (tgt==null) - return false; - - StateGraph sg = getStateGraph(cs, fp); - if (sg==null) - return false; - - return validationUtil.isConnectable(src, tgt, trans, sg).isOk(); - } - - /** - * @param s the state whose sub structure should be deleted - * @param ac the ActorClass - * @param diagram the current diagram - * @param fp the feature provider - */ - public void deleteSubStructureRecursive(State s, ActorClass ac, Diagram diagram, IFeatureProvider fp) { - if (roomHelpers.hasSubStructure(s, ac)) { - StateGraph subgraph = s.getSubgraph(); - - // depth first - for (State st : subgraph.getStates()) { - deleteSubStructureRecursive(st, ac, diagram, fp); - } - - ContainerShape subShape = ContextSwitcher.getContext(diagram, subgraph); - CommonSupportUtil.deleteConnectionsRecursive(subShape, fp); - EcoreUtil.delete(subShape, true); - } - } - - public List<State> getStates(ContainerShape shape, IFeatureProvider fp) { - return getStates(shape, fp, null, null); - } - - private List<State> getStates(ContainerShape shape, IFeatureProvider fp, Map<String, Anchor> item2anchor, List<Shape> stateShapes) { - List<State> items = new ArrayList<State>(); - for (Shape ch : shape.getChildren()) { - Object bo = fp.getBusinessObjectForPictogramElement(ch); - if (bo instanceof State) { - items.add((State)bo); - if (item2anchor!=null) - item2anchor.put(getKey((State)bo), ch.getAnchors().get(0)); - if (stateShapes!=null) - stateShapes.add(ch); - } - } - return items; - } - - public List<ChoicePoint> getChoicePoints(ContainerShape shape, IFeatureProvider fp) { - return getChoicePoints(shape, fp, null, null); - } - - private List<ChoicePoint> getChoicePoints(ContainerShape shape, IFeatureProvider fp, Map<String, Anchor> item2anchor, List<Shape> cpShapes) { - List<ChoicePoint> items = new ArrayList<ChoicePoint>(); - for (Shape ch : shape.getChildren()) { - Object bo = fp.getBusinessObjectForPictogramElement(ch); - if (bo instanceof ChoicePoint) { - items.add((ChoicePoint)bo); - if (item2anchor!=null) - item2anchor.put(getKey((ChoicePoint)bo), ch.getAnchors().get(0)); - if (cpShapes!=null) - cpShapes.add(ch); - } - } - return items; - } - - public List<TrPoint> getTrPoints(StateGraph sg, ContainerShape shape, IFeatureProvider fp) { - return getTrPoints(sg, shape, fp, null, null); - } - - private List<TrPoint> getTrPoints(StateGraph sg, ContainerShape shape, IFeatureProvider fp, Map<String, Anchor> item2anchor, List<Shape> tpShapes) { - List<TrPoint> items = new ArrayList<TrPoint>(); - for (Shape ch : shape.getChildren()) { - Object bo = fp.getBusinessObjectForPictogramElement(ch); - if (bo instanceof TrPoint) { - items.add((TrPoint)bo); - if (item2anchor!=null) - item2anchor.put(getKey((TrPoint)bo), ch.getAnchors().get(0)); - if (tpShapes!=null) - tpShapes.add(ch); - } - } - return items; - } - - /** - * @param diagram - * @param fp - * @return - */ - public List<Transition> getTransitions(Diagram diagram, IFeatureProvider fp) { - List<Transition> transitions = new ArrayList<Transition>(); - for (Connection conn : diagram.getConnections()) { - Object bo = fp.getBusinessObjectForPictogramElement(conn); - if (bo instanceof Transition) - transitions.add((Transition) bo); - } - return transitions; - } - - private Map<Transition, Connection> getTransitionsMap(ContainerShape sgShape, IFeatureProvider fp) { - Diagram diagram = (Diagram) sgShape.eContainer(); - Map<Transition, Connection> transitions = new HashMap<Transition, Connection>(); - for (Connection conn : diagram.getConnections()) { - Object bo = fp.getBusinessObjectForPictogramElement(conn); - - // we only collect connections that have a starting point contained in our sgShape - if (bo instanceof Transition && EcoreUtil.isAncestor(sgShape, conn.getStart())) - transitions.put((Transition) bo, conn); - } - return transitions; - } - - /** - * @param sgShape - * @param node2anchor - */ - private void getSubTpAnchors(ContainerShape sgShape, HashMap<String, Anchor> node2anchor) { - for (Shape childShape : sgShape.getChildren()) { - EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(childShape); - if (bo instanceof State) - getAnchors((State) bo, childShape, node2anchor); - } - } - - public ContainerShape addStateGraph(StateGraphContext ctx, Diagram diagram, IFeatureProvider fp) { - AddContext addContext = new AddContext(); - addContext.setNewObject(ctx.getStateGraph()); - addContext.setTargetContainer(diagram); - PosAndSize graphPosAndSize = ctx.getPositionProvider().getGraphPosAndSize(ctx.getStateGraph()); - if (graphPosAndSize!=null) { - addContext.setX(graphPosAndSize.getX()); - addContext.setY(graphPosAndSize.getY()); - addContext.setWidth(graphPosAndSize.getWidth()); - addContext.setHeight(graphPosAndSize.getHeight()); - } - else { - addContext.setX(StateGraphSupport.MARGIN); - addContext.setY(StateGraphSupport.MARGIN); - } - - ContainerShape sgShape = (ContainerShape) fp.addIfPossible(addContext); - if (sgShape==null) - return null; - - final HashMap<String, Anchor> node2anchor = new HashMap<String, Anchor>(); - - GraphicsAlgorithm borderRect = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0); - ctx.getPositionProvider().setScale(borderRect.getWidth(), borderRect.getHeight()); - ctx.getPositionProvider().setPosition(sgShape.getGraphicsAlgorithm().getX(), sgShape.getGraphicsAlgorithm().getY()); - - addInitialPointIff(ctx, ctx.getPositionProvider(), sgShape, fp, node2anchor); - addStateGraphNodes(ctx.getTrPoints(), ctx.getPositionProvider(), sgShape, fp, node2anchor); - addStateGraphNodes(ctx.getStates(), ctx.getPositionProvider(), sgShape, fp, node2anchor); - addStateGraphNodes(ctx.getChPoints(), ctx.getPositionProvider(), sgShape, fp, node2anchor); - - for (StateGraphContext sub : ctx.getChildren()) { - addStateGraph(sub, diagram, fp); - } - - getSubTpAnchors(sgShape, node2anchor); - - addTransitions(ctx.getTransitions(), ctx.getPositionProvider(), sgShape, fp, node2anchor); - - return sgShape; - } - - private void addInitialPointIff(StateGraphContext ctx, IPositionProvider positionProvider, ContainerShape sgShape, IFeatureProvider fp, - HashMap<String, Anchor> node2anchor) { - - // model - StateGraph sg = ctx.getInitialPoint(); - if(sg==null) - // (super class) diagram - sg = positionProvider.getInitialPoint(ctx.getStateGraph()); - if(sg==null) - return; - - PosAndSize pos = positionProvider.getPosition(sg); - AddContext addContext = new AddContext(); - addContext.setNewObject(sg); - addContext.setTargetContainer(sgShape); - if(pos != null){ - addContext.setX(pos.getX()); - addContext.setY(pos.getY()); - if (pos.getWidth()>0 && pos.getHeight()>0) { - addContext.setWidth(pos.getWidth()); - addContext.setHeight(pos.getHeight()); - } - } else { - addContext.setX(3*StateGraphSupport.MARGIN); - addContext.setY(3*StateGraphSupport.MARGIN); - } - - ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext); - assert(pe!=null): "initial point should have been created"; - assert(!pe.getAnchors().isEmpty()): "initial point should have an anchor"; - node2anchor.put(INITIAL, pe.getAnchors().get(0)); - } - - public void updateStateGraph(StateGraph sg, StateGraphContext ctx, ContainerShape sgShape, IFeatureProvider fp) { - - HashMap<String, Anchor> node2anchor = new HashMap<String, Anchor>(); - - GraphicsAlgorithm borderRect = sgShape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0); - ctx.getPositionProvider().setScale(borderRect.getWidth(), borderRect.getHeight()); - ctx.getPositionProvider().setPosition(sgShape.getGraphicsAlgorithm().getX(), sgShape.getGraphicsAlgorithm().getY()); - - // states - { - ArrayList<Shape> shapes = new ArrayList<Shape>(); - List<State> present = getStates(sgShape, fp, node2anchor, shapes); - checkDuplicates(present); - List<State> expected = ctx.getStates(); - List<State> toAdd = new ArrayList<State>(); - List<State> toUpdate = new ArrayList<State>(); - for (State item : expected) { - if (present.contains(item)) - toUpdate.add(item); - else - toAdd.add(item); - } - addStateGraphNodes(toAdd, ctx.getPositionProvider(), sgShape, fp, node2anchor); - updateStateGraphNodes(toUpdate, shapes, ctx.getPositionProvider(), fp); - } - - // transition points - { - ArrayList<Shape> shapes = new ArrayList<Shape>(); - List<TrPoint> present = getTrPoints(sg, sgShape, fp, node2anchor, shapes); - checkDuplicates(present); - List<TrPoint> expected = ctx.getTrPoints(); - List<TrPoint> toAdd = new ArrayList<TrPoint>(); - List<TrPoint> toUpdate = new ArrayList<TrPoint>(); - for (TrPoint item : expected) { - if (present.contains(item)) - toUpdate.add(item); - else - toAdd.add(item); - } - addStateGraphNodes(toAdd, ctx.getPositionProvider(), sgShape, fp, node2anchor); - updateStateGraphNodes(toUpdate, shapes, ctx.getPositionProvider(), fp); - } - - // choice points - { - ArrayList<Shape> shapes = new ArrayList<Shape>(); - List<ChoicePoint> present = getChoicePoints(sgShape, fp, node2anchor, shapes); - checkDuplicates(present); - List<ChoicePoint> expected = ctx.getChPoints(); - List<ChoicePoint> toAdd = new ArrayList<ChoicePoint>(); - List<ChoicePoint> toUpdate = new ArrayList<ChoicePoint>(); - for (ChoicePoint item : expected) { - if (present.contains(item)) - toUpdate.add(item); - else - toAdd.add(item); - } - addStateGraphNodes(toAdd, ctx.getPositionProvider(), sgShape, fp, node2anchor); - updateStateGraphNodes(toUpdate, shapes, ctx.getPositionProvider(), fp); - } - - getSubTpAnchors(sgShape, node2anchor); - - // initial point - { - // exists in this diagram ? - Shape present = null; - for (Shape ch : sgShape.getChildren()) { - Object bo = fp.getBusinessObjectForPictogramElement(ch); - if (bo instanceof StateGraph) - present = ch; - } - if(present != null) - node2anchor.put(INITIAL, present.getAnchors().get(0)); - // exists in model ? - StateGraph expected = ctx.getInitialPoint(); - if(expected == null) - // exists in (super class) diagram ? - expected = ctx.getPositionProvider().getInitialPoint(ctx.getStateGraph()); - if(expected != null && present == null) - addInitialPointIff(ctx, ctx.getPositionProvider(), sgShape, fp, node2anchor); - else - updateInitialPoint(present, ctx.getPositionProvider(), fp); - } - - // transitions - { - // get transitions that belong to our state graph - // (for other connections we might not have the node anchors yet) - Map<Transition, Connection> present = getTransitionsMap(sgShape, fp); - List<Transition> expected = ctx.getTransitions(); - List<Transition> toAdd = new ArrayList<Transition>(); - for (Transition trans : expected) - if (!present.containsKey(trans)) - toAdd.add(trans); - - addTransitions(toAdd, ctx.getPositionProvider(), sgShape, fp, node2anchor); - updateTransitions(present, ctx.getPositionProvider(), sgShape, fp, node2anchor); - } - } - - /** - * @param items - */ - private void checkDuplicates(List<? extends StateGraphItem> items) { - for (StateGraphItem item : items) { - if (items.indexOf(item)!=items.lastIndexOf(item)) { - Assert.isTrue( - items.indexOf(item)==items.lastIndexOf(item), - "multiple occurrences of "+roomNameProvider.getFullPath(item)); - } - } - } - - private void addTransitions(List<Transition> transitions, IPositionProvider positionProvider, ContainerShape sgShape, IFeatureProvider fp, - HashMap<String, Anchor> node2anchor) { - - for (Transition trans : transitions) { - String from = (trans instanceof InitialTransition)? INITIAL:getKey(((NonInitialTransition)trans).getFrom()); - String to = getKey(trans.getTo()); - Anchor src = node2anchor.get(from); - Anchor dst = node2anchor.get(to); - - assert(src!=null && dst!=null): "transition endpoints must be present"; - - AddConnectionContext context = new AddConnectionContext(src, dst); - context.setNewObject(trans); - PictogramElement pe = fp.addIfPossible(context); - if (pe instanceof FreeFormConnection) { - FreeFormConnection conn = (FreeFormConnection) pe; - - // JH: workaround for correct bend points of inherited self transition - conn.getBendpoints().clear(); - - List<Pos> points = positionProvider.getPoints(trans); - if (points!=null && !points.isEmpty()) { - Iterator<Pos> it = points.iterator(); - - // first is label position - Pos pos = it.next(); - ConnectionDecorator cd = conn.getConnectionDecorators().get(1); - Graphiti.getGaService().setLocation(cd.getGraphicsAlgorithm(), pos.getX(), pos.getY()); - - // remaining are bend points - while (it.hasNext()) { - pos = it.next(); - Point pt = Graphiti.getGaService().createPoint(pos.getX(), pos.getY()); - conn.getBendpoints().add(pt); - } - } - else if (src==dst) { - ILocation begin = Graphiti.getPeService().getLocationRelativeToDiagram(conn.getStart()); - Point pt = Graphiti.getGaService().createPoint(begin.getX(), begin.getY()+StateGraphSupport.MARGIN*3); - conn.getBendpoints().add(pt); - } - } - } - } - - private void addStateGraphNodes(List<? extends StateGraphNode> nodes, IPositionProvider positionProvider, ContainerShape sgShape, IFeatureProvider fp, - HashMap<String, Anchor> node2anchor) { - - List<PosAndSize> positions = positionProvider.getPositions(nodes); - - int idx = 0; - for (StateGraphNode node : nodes) { - addStateGraphNode(node, sgShape, positions.get(idx), fp, node2anchor); - ++idx; - } - } - - private void addStateGraphNode(StateGraphNode tp, ContainerShape sgShape, - PosAndSize pos, IFeatureProvider fp, HashMap<String, Anchor> node2anchor) { - AddContext addContext = new AddContext(); - addContext.setNewObject(tp); - addContext.setTargetContainer(sgShape); - addContext.setX(pos.getX()); - addContext.setY(pos.getY()); - if (pos.getWidth()>0 && pos.getHeight()>0) { - addContext.setWidth(pos.getWidth()); - addContext.setHeight(pos.getHeight()); - } - - ContainerShape pe = (ContainerShape) fp.addIfPossible(addContext); - assert(pe!=null): tp.eClass().getName()+" should have been created"; - assert(!pe.getAnchors().isEmpty()): tp.eClass().getName()+" should have an anchor"; - node2anchor.put(getKey(tp), pe.getAnchors().get(0)); - } - - private void updateInitialPoint(Shape shape, - IPositionProvider positionProvider, IFeatureProvider fp) { - if (shape==null) - return; - - StateGraph sg = (StateGraph) fp.getBusinessObjectForPictogramElement(shape); - PosAndSize ps = positionProvider.getPosition(sg); - if (ps==null) - return; - - // relocate and resize the invisible rectangle - GraphicsAlgorithm ga = shape.getGraphicsAlgorithm(); - - Graphiti.getLayoutService().setLocationAndSize( - ga, - ps.getX(), - ps.getY(), - ps.getWidth(), - ps.getHeight() - ); - - // have to call the layout to adjust the visible border - LayoutContext lc = new LayoutContext(shape); - fp.layoutIfPossible(lc); - } - - private void updateStateGraphNodes(List<? extends StateGraphNode> nodes, List<Shape> shapes, IPositionProvider positionProvider, IFeatureProvider fp) { - - ILinkService linkService = Graphiti.getLinkService(); - IGaService gaService = Graphiti.getGaService(); - - for (StateGraphNode node : nodes) { - PosAndSize ps = positionProvider.getPosition(node); - if (ps==null) - continue; - - // TODO: sub-optimal since quadratic effort - use combined list for nodes and shapes or similar solution - for (Shape shape : shapes) { - EObject bo = linkService.getBusinessObjectForLinkedPictogramElement(shape); - if (bo==node) { - // relocate and resize the invisible rectangle - GraphicsAlgorithm ga = shape.getGraphicsAlgorithm(); -// System.out.println(RoomNameProvider.getFullPath(node)+": "+ga.getX()+" "+ga.getY()+" "+ga.getWidth()+" "+ga.getHeight()); -// System.out.println(" -> "+ps.getX()+" "+ps.getY()+" "+ps.getWidth()+" "+ps.getHeight()); - - int margin = 0; - if (node instanceof State) - margin = StateSupport.MARGIN; - else if (node instanceof TrPoint) - margin = TrPointSupport.MARGIN; - - gaService.setLocationAndSize( - ga, - ps.getX()-margin, - ps.getY()-margin, - ps.getWidth()+2*margin, - ps.getHeight()+2*margin - ); - - // have to call the layout to adjust the visible border - LayoutContext lc = new LayoutContext(shape); - fp.layoutIfPossible(lc); - break; - } - } - } - } - - private void updateTransitions(Map<Transition, Connection> transitions, IPositionProvider positionProvider, ContainerShape sgShape, - IFeatureProvider fp, HashMap<String, Anchor> node2anchor) { - - for(Entry<Transition, Connection> e: transitions.entrySet()){ - Transition trans = e.getKey(); - Connection conn = e.getValue(); - - String from = (trans instanceof InitialTransition)? INITIAL:getKey(((NonInitialTransition)trans).getFrom()); - String to = getKey(trans.getTo()); - Anchor newSrc = node2anchor.get(from); - Anchor newDst = node2anchor.get(to); - - assert(newSrc!=null && newDst!=null): "transition endpoints must be present"; - - if(conn.getStart()!=newSrc) - conn.setStart(newSrc); - if(conn.getEnd()!=newDst) - conn.setEnd(newDst); - - List<Pos> points = positionProvider.getPoints(trans); - Iterator<Pos> it = points.iterator(); - if (points==null || points.isEmpty()) - continue; - - // first is label position - Pos pos = it.next(); - ConnectionDecorator cd = conn.getConnectionDecorators().get(1); - Graphiti.getGaService().setLocation(cd.getGraphicsAlgorithm(), pos.getX(), pos.getY()); - - if (conn instanceof FreeFormConnection) { - FreeFormConnection fconn = (FreeFormConnection) conn; - - // remaining are bend points - fconn.getBendpoints().clear(); - List<Point> bendpoints = new ArrayList<Point>(); - while (it.hasNext()) { - pos = it.next(); - Point pt = Graphiti.getGaService().createPoint(pos.getX(), pos.getY()); - bendpoints.add(pt); - } - fconn.getBendpoints().addAll(bendpoints); - } - } - } - - private void getAnchors(State state, PictogramElement stateShape, - final HashMap<String, Anchor> node2anchor) { - - if (stateShape instanceof ContainerShape) { - node2anchor.put(getKey(state), ((ContainerShape)stateShape).getAnchors().get(0)); - for (Shape child : ((ContainerShape) stateShape).getChildren()) { - if (child instanceof ContainerShape) { - ContainerShape childShape = (ContainerShape) child; - if (!childShape.getAnchors().isEmpty()) { - if (!childShape.getLink().getBusinessObjects().isEmpty()) { - EObject obj = childShape.getLink().getBusinessObjects().get(0); - if (obj instanceof EntryPoint || obj instanceof ExitPoint) { - node2anchor.put(getKey(obj, true), childShape.getAnchors().get(0)); - } - } - } - } - } - } - } - - private String getKey(EObject obj) { - return getKey(obj, false); - } - - private String getKey(EObject obj, boolean subTp) { - if (obj instanceof TrPoint) { - TrPoint tp = (TrPoint) obj; - if (!subTp) - return TP+tp.getName(); - else { - if (tp.eContainer().eContainer() instanceof State) { - State s = (State) tp.eContainer().eContainer(); - return TP+tp.getName()+SEP+s.getName(); - } - else { - assert(false): "State expected"; - } - } - } - else if (obj instanceof State) { - return STATE+((State)obj).getName(); - } - else if (obj instanceof ChoicePoint) { - return CP+((ChoicePoint)obj).getName(); - } - else if (obj instanceof TransitionTerminal) { - TransitionTerminal tt = (TransitionTerminal) obj; - if (tt instanceof ChoicepointTerminal) { - return CP+((ChoicepointTerminal)tt).getCp().getName(); - } - else if (tt instanceof StateTerminal) { - return STATE+((StateTerminal)tt).getState().getName(); - } - else if (tt instanceof SubStateTrPointTerminal) { - SubStateTrPointTerminal sstt = (SubStateTrPointTerminal) tt; - return TP+sstt.getTrPoint().getName()+SEP+sstt.getState().getName(); - } - else if (tt instanceof TrPointTerminal) { - return TP+((TrPointTerminal)tt).getTrPoint().getName(); - } - else { - assert(false): "unexpected sub type"; - } - } - assert(false): "unexpected type"; - return null; - } - } diff --git a/plugins/org.eclipse.etrice.ui.commands/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.commands/META-INF/MANIFEST.MF index 8b74f1fed..b303eb71e 100644 --- a/plugins/org.eclipse.etrice.ui.commands/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.etrice.ui.commands/META-INF/MANIFEST.MF @@ -10,6 +10,7 @@ Require-Bundle: org.eclipse.etrice.core.fsm;bundle-version="0.5.0", org.eclipse.etrice.ui.common;bundle-version="0.5.0", org.eclipse.etrice.ui.common.base;bundle-version="0.5.0", org.eclipse.etrice.ui.structure;bundle-version="0.5.0", + org.eclipse.etrice.ui.behavior.fsm;bundle-version="0.5.0", org.eclipse.etrice.ui.behavior;bundle-version="0.5.0", org.eclipse.graphiti;bundle-version="0.8.0", org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100", diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java index 5465a5dba..59778920e 100644 --- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java +++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/DiagramEditorBase.java @@ -71,13 +71,15 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU protected ModificationTrackingEnabler mte = new ModificationTrackingEnabler(); protected URI inputUri; - protected Object textEditorClass; + private Object textEditorClass; private SaveOnFocusLostListener saveOnFocusListener; private SuperClassListener superClassListener; - public DiagramEditorBase() { + public DiagramEditorBase(Object textEditorClass) { + this.textEditorClass = textEditorClass; + Injector injector = FSMUiModule.getInjector(); injector.injectMembers(this); @@ -169,18 +171,21 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU */ @Override public void setFocus() { - super.setFocus(); - boolean dirtyAlready = isDirty(); // inside this call auto refresh will happen if (and turn the editor dirty) super.setFocus(); - if(superClassListener.isChangeInSuperClass()) + if (superClassListener.isChangeInSuperClass()) superClassChanged(); if (!dirtyAlready && isDirty()) doSave(null); + + Diagram diagram = getDiagramTypeProvider().getDiagram(); + EObject diagramBo = diagram.getLink().getBusinessObjects().iterator().next(); + if(diagramBo == null || diagramBo.eIsProxy()) + handleMissingDiagramBo(diagram); } public ModelComponent getModelComponent() { @@ -297,7 +302,9 @@ public abstract class DiagramEditorBase extends DiagramEditor implements IInputU return null; } + protected abstract void handleMissingDiagramBo(Diagram diagram); protected abstract void superClassChanged(); + protected abstract EObject getModel(); public URI getInputUri() { return inputUri; diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCreateConnectionFeature.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCreateConnectionFeature.java index 1434692a9..03d67e7f2 100644 --- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCreateConnectionFeature.java +++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCreateConnectionFeature.java @@ -23,14 +23,21 @@ import org.eclipse.graphiti.features.impl.AbstractCreateConnectionFeature; import org.eclipse.graphiti.features.impl.AbstractCreateFeature; import org.eclipse.graphiti.mm.pictograms.Connection; +import com.google.inject.Injector; + public abstract class ChangeAwareCreateConnectionFeature extends AbstractCreateConnectionFeature { boolean hasDoneChanges; + private Injector injector; + + public ChangeAwareCreateConnectionFeature(IFeatureProvider fp, String name, String description) { + this(fp, null, name, description); + } - public ChangeAwareCreateConnectionFeature(IFeatureProvider fp, String name, - String description) { + public ChangeAwareCreateConnectionFeature(IFeatureProvider fp, Injector injector, String name, String description) { super(fp, name, description); + this.injector = injector; this.hasDoneChanges = false; } @@ -73,4 +80,12 @@ public abstract class ChangeAwareCreateConnectionFeature extends protected EObject getContainerModelObject(ICreateConnectionContext context){ return (EObject) getBusinessObjectForPictogramElement(getDiagram()); } + + + /** + * @return the Guice injector + */ + public Injector getInjector() { + return injector; + } } diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCreateFeature.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCreateFeature.java index ded7e2f07..c35e6257f 100644 --- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCreateFeature.java +++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCreateFeature.java @@ -20,13 +20,20 @@ import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.ICreateContext; import org.eclipse.graphiti.features.impl.AbstractCreateFeature; +import com.google.inject.Injector; + public abstract class ChangeAwareCreateFeature extends AbstractCreateFeature { + private Injector injector; boolean hasDoneChanges; - public ChangeAwareCreateFeature(IFeatureProvider fp, String name, - String description) { + public ChangeAwareCreateFeature(IFeatureProvider fp, String name, String description) { + this(fp, null, name, description); + } + + public ChangeAwareCreateFeature(IFeatureProvider fp, Injector injector, String name, String description) { super(fp, name, description); + this.injector = injector; this.hasDoneChanges = false; } @@ -68,4 +75,11 @@ public abstract class ChangeAwareCreateFeature extends AbstractCreateFeature { protected EObject getContainerModelObject(ICreateContext context){ return (EObject) getBusinessObjectForPictogramElement(getDiagram()); } + + /** + * @return the Guice injector + */ + public Injector getInjector() { + return injector; + } } diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCustomFeature.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCustomFeature.java index 93ea40741..b984da0b5 100644 --- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCustomFeature.java +++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/ChangeAwareCustomFeature.java @@ -20,12 +20,20 @@ import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.features.context.ICustomContext; import org.eclipse.graphiti.features.custom.AbstractCustomFeature; +import com.google.inject.Injector; + public abstract class ChangeAwareCustomFeature extends AbstractCustomFeature { + private Injector injector; boolean hasDoneChanges; public ChangeAwareCustomFeature(IFeatureProvider fp) { + this(fp, null); + } + + public ChangeAwareCustomFeature(IFeatureProvider fp, Injector injector) { super(fp); + this.injector = injector; this.hasDoneChanges = false; } @@ -61,4 +69,11 @@ public abstract class ChangeAwareCustomFeature extends AbstractCustomFeature { protected EObject getContainerModelObject(ICustomContext context){ return (EObject) getBusinessObjectForPictogramElement(getDiagram()); } + + /** + * @return the Guice injector + */ + public Injector getInjector() { + return injector; + } } diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java index c04b94b84..42ef42770 100644 --- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java +++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/support/DiagramAccessBase.java @@ -31,7 +31,6 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl; import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.etrice.core.common.ui.linking.GlobalNonPlatformURIEditorOpener; -import org.eclipse.etrice.core.fsm.ui.FSMUiModule; import org.eclipse.etrice.ui.common.base.UIBaseActivator; import org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase; import org.eclipse.etrice.ui.common.base.preferences.UIBasePreferenceConstants; @@ -46,7 +45,6 @@ import org.eclipse.xtext.resource.XtextResourceSet; import org.eclipse.xtext.ui.resource.IResourceSetProvider; import com.google.inject.Inject; -import com.google.inject.Injector; /** * @author Henrik Rentz-Reichert @@ -64,9 +62,7 @@ public abstract class DiagramAccessBase { */ public DiagramAccessBase() { super(); - - Injector injector = FSMUiModule.getInjector(); - injector.injectMembers(this); + injectMembers(); } public Diagram getDiagram(EObject rootObject) { @@ -248,4 +244,6 @@ public abstract class DiagramAccessBase { abstract protected String getEditorId(); abstract protected Command getInitialCommand(EObject rootObject, Diagram diagram, TransactionalEditingDomain editingDomain); abstract protected Command getUpdateCommand(Diagram diagram, TransactionalEditingDomain editingDomain); + abstract protected void injectMembers(); + }
\ No newline at end of file diff --git a/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF index 610871e3f..77d86a4e4 100644 --- a/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.etrice.ui.common/META-INF/MANIFEST.MF @@ -25,7 +25,6 @@ Require-Bundle: org.eclipse.etrice.core.fsm;bundle-version="0.5.0", org.eclipse.emf.workspace;bundle-version="1.5.0" Export-Package: org.eclipse.etrice.ui.common, org.eclipse.etrice.ui.common.commands, - org.eclipse.etrice.ui.common.editor, org.eclipse.etrice.ui.common.preferences Bundle-Activator: org.eclipse.etrice.ui.common.Activator Bundle-ActivationPolicy: lazy diff --git a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java b/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java deleted file mode 100644 index 8c04e66ae..000000000 --- a/plugins/org.eclipse.etrice.ui.common/src/org/eclipse/etrice/ui/common/editor/RoomDiagramEditor.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011 protos software gmbh (http://www.protos.de). - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - *******************************************************************************/ - -package org.eclipse.etrice.ui.common.editor; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.etrice.core.room.StructureClass; -import org.eclipse.etrice.core.ui.editor.RoomEditor; -import org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase; -import org.eclipse.etrice.ui.common.commands.ChangeDiagramInputJob; -import org.eclipse.graphiti.mm.pictograms.Diagram; -import org.eclipse.jface.dialogs.MessageDialog; - -/** - * description - * - * @author Henrik Rentz-Reichert initial contribution and API - * - */ -public abstract class RoomDiagramEditor extends DiagramEditorBase { - - private boolean showLostDiagramInputDialog = true; - - public RoomDiagramEditor() { - super(); - textEditorClass = RoomEditor.class; - } - - /* (non-Javadoc) - * @see org.eclipse.graphiti.ui.internal.editor.DiagramEditorInternal#setFocus() - */ - @Override - public void setFocus() { - super.setFocus(); - - Diagram diagram = getDiagramTypeProvider().getDiagram(); - EObject diagramBo = diagram.getLink().getBusinessObjects().iterator().next(); - if(diagramBo == null || diagramBo.eIsProxy()) - handleMissingDiagramBo(diagram); - } - - protected void handleMissingDiagramBo(Diagram diagram){ - if(!showLostDiagramInputDialog) - return; - - // show only once - showLostDiagramInputDialog = false; - MessageDialog dialog = new MessageDialog(getGraphicalControl().getShell(), - "Diagram out-dated", null, - "Diagram input lost. Cannot find ROOM file or class for "+diagram.getName() +"\n\n" - + "Please ensure that no whitespace or special characters are contained in any related path, file or project", - MessageDialog.ERROR, new String[] { "OK", "Reconnect Diagram" }, 0); - int result = dialog.open(); - - if(result == 1) - new ChangeDiagramInputJob("Change input for "+diagram.getName(), this).schedule(); - } - - protected abstract StructureClass getStructureClass(); - -} diff --git a/plugins/org.eclipse.etrice.ui.layout/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.ui.layout/META-INF/MANIFEST.MF index ae3a7ac9d..344bcdf73 100644 --- a/plugins/org.eclipse.etrice.ui.layout/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.etrice.ui.layout/META-INF/MANIFEST.MF @@ -18,6 +18,7 @@ Require-Bundle: org.eclipse.graphiti;bundle-version="0.8.1", de.cau.cs.kieler.kiml.ui;bundle-version="0.7.1", de.cau.cs.kieler.kiml.graphiti;bundle-version="0.2.0", org.eclipse.etrice.ui.behavior;bundle-version="0.5.0", + org.eclipse.etrice.ui.behavior.fsm;bundle-version="0.5.0", org.eclipse.etrice.ui.structure;bundle-version="0.5.0", org.eclipse.etrice.ui.common;bundle-version="0.5.0", org.eclipse.etrice.ui.common.base;bundle-version="0.5.0", diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorDiagramLayoutManager.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorDiagramLayoutManager.java index de64b87a7..c4485fa1a 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorDiagramLayoutManager.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorDiagramLayoutManager.java @@ -18,7 +18,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.etrice.core.fsm.fSM.StateGraph; import org.eclipse.etrice.core.fsm.fSM.TrPoint; import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; -import org.eclipse.etrice.ui.behavior.support.StateSupport; +import org.eclipse.etrice.ui.behavior.fsm.support.StateSupport; import org.eclipse.graphiti.mm.pictograms.Anchor; import org.eclipse.graphiti.mm.pictograms.Diagram; import org.eclipse.graphiti.mm.pictograms.PictogramElement; diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java index 488445ffb..78825d3ac 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/BehaviorLayoutCommand.java @@ -16,7 +16,7 @@ package org.eclipse.etrice.ui.layout; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.etrice.core.fsm.fSM.State; -import org.eclipse.etrice.ui.behavior.support.TrPointSupport; +import org.eclipse.etrice.ui.behavior.fsm.support.TrPointSupport; import org.eclipse.graphiti.features.IFeatureProvider; import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; import org.eclipse.graphiti.mm.algorithms.Text; diff --git a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java index 43aeedd2d..f77557283 100644 --- a/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java +++ b/plugins/org.eclipse.etrice.ui.layout/src/org/eclipse/etrice/ui/layout/ETriceDiagramLayoutManager.java @@ -23,7 +23,6 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.etrice.ui.behavior.editor.BehaviorEditor; import org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase; -import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor; import org.eclipse.gef.EditPart; import org.eclipse.graphiti.mm.algorithms.AbstractText; import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; @@ -204,7 +203,7 @@ public abstract class ETriceDiagramLayoutManager extends mapping.setProperty(KimlGraphitiUtil.STATIC_CONFIG, new VolatileLayoutConfig()); - if (workbenchPart instanceof RoomDiagramEditor) { + if (workbenchPart instanceof DiagramEditorBase) { mapping.setProperty(KimlGraphitiUtil.DIAGRAM_EDITOR, (DiagramEditorBase) workbenchPart); } diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java index 10c60ff80..b5f3a3a92 100644 --- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java +++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/DiagramAccess.java @@ -25,9 +25,16 @@ import org.eclipse.graphiti.mm.pictograms.Diagram; import org.eclipse.graphiti.ui.services.GraphitiUi; import org.eclipse.etrice.core.room.RoomModel; import org.eclipse.etrice.core.room.StructureClass; +import org.eclipse.etrice.core.ui.RoomUiModule; + +import com.google.inject.Injector; public class DiagramAccess extends DiagramAccessBase { + public DiagramAccess() { + super(); + } + public String getDiagramName(EObject rootObject) { if (rootObject instanceof StructureClass) { StructureClass sc = (StructureClass) rootObject; @@ -72,4 +79,13 @@ public class DiagramAccess extends DiagramAccessBase { return null; } + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.common.base.support.DiagramAccessBase#injectMembers() + */ + @Override + protected void injectMembers() { + Injector injector = RoomUiModule.getInjector(); + injector.injectMembers(this); + } } diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java index 04d3802a9..1a6845065 100644 --- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java +++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/editor/StructureEditor.java @@ -14,8 +14,10 @@ package org.eclipse.etrice.ui.structure.editor; import org.eclipse.emf.ecore.EObject; import org.eclipse.etrice.core.room.StructureClass; +import org.eclipse.etrice.core.ui.editor.RoomEditor; import org.eclipse.etrice.ui.common.base.editor.CustomDiagramBehavior; -import org.eclipse.etrice.ui.common.editor.RoomDiagramEditor; +import org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase; +import org.eclipse.etrice.ui.common.commands.ChangeDiagramInputJob; import org.eclipse.etrice.ui.structure.Activator; import org.eclipse.etrice.ui.structure.support.context.PositionUpdateContext; import org.eclipse.etrice.ui.structure.support.provider.SuperDiagramPositionProvider; @@ -26,15 +28,17 @@ import org.eclipse.graphiti.mm.pictograms.Diagram; import org.eclipse.graphiti.services.Graphiti; import org.eclipse.graphiti.ui.editor.DefaultRefreshBehavior; import org.eclipse.graphiti.ui.editor.DiagramBehavior; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.graphics.Image; -public class StructureEditor extends RoomDiagramEditor { +public class StructureEditor extends DiagramEditorBase { public static final String STRUCTURE_EDITOR_ID = "org.eclipse.etrice.ui.structure.editor.StructureEditor"; + private boolean showLostDiagramInputDialog = true; public StructureEditor() { - super(); + super(RoomEditor.class); } @Override @@ -45,7 +49,6 @@ public class StructureEditor extends RoomDiagramEditor { /** * @return the actor class of this editor */ - @Override public StructureClass getStructureClass() { Diagram diagram = getDiagramTypeProvider().getDiagram(); EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram); @@ -76,5 +79,28 @@ public class StructureEditor extends RoomDiagramEditor { }; } - + protected void handleMissingDiagramBo(Diagram diagram){ + if(!showLostDiagramInputDialog) + return; + + // show only once + showLostDiagramInputDialog = false; + MessageDialog dialog = new MessageDialog(getGraphicalControl().getShell(), + "Diagram out-dated", null, + "Diagram input lost. Cannot find ROOM file or class for "+diagram.getName() +"\n\n" + + "Please ensure that no whitespace or special characters are contained in any related path, file or project", + MessageDialog.ERROR, new String[] { "OK", "Reconnect Diagram" }, 0); + int result = dialog.open(); + + if(result == 1) + new ChangeDiagramInputJob("Change input for "+diagram.getName(), this).schedule(); + } + + /* (non-Javadoc) + * @see org.eclipse.etrice.ui.common.base.editor.DiagramEditorBase#getModel() + */ + @Override + protected EObject getModel() { + return getStructureClass().eContainer(); + } } |