Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-03-05 00:57:20 -0500
committerHenrik Rentz-Reichert2011-03-05 00:57:20 -0500
commitf92aed461a3efdb9697c766fd6f8112d6c2bd052 (patch)
tree15bf7776020257234d11b314705a5cf4dacbd77e
parentdfb09a10a0806647b0058174422a0bf6d69589e3 (diff)
downloadorg.eclipse.etrice-f92aed461a3efdb9697c766fd6f8112d6c2bd052.tar.gz
org.eclipse.etrice-f92aed461a3efdb9697c766fd6f8112d6c2bd052.tar.xz
org.eclipse.etrice-f92aed461a3efdb9697c766fd6f8112d6c2bd052.zip
unique names and their validation
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/naming/RoomNameProvider.java172
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java95
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java17
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TrPointPropertyDialog.java18
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/TransitionPropertyDialog.java13
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java38
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java11
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java9
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java7
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java1
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java41
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java42
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java25
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java27
-rw-r--r--plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java13
15 files changed, 364 insertions, 165 deletions
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/naming/RoomNameProvider.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/naming/RoomNameProvider.java
index 4cfd64e8d..4c49e81cd 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/naming/RoomNameProvider.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/naming/RoomNameProvider.java
@@ -16,6 +16,8 @@ package org.eclipse.etrice.core.naming;
import java.util.HashSet;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.ActorContainerRef;
import org.eclipse.etrice.core.room.ActorRef;
import org.eclipse.etrice.core.room.BaseState;
@@ -24,16 +26,22 @@ import org.eclipse.etrice.core.room.ChoicePoint;
import org.eclipse.etrice.core.room.ChoicepointTerminal;
import org.eclipse.etrice.core.room.ContinuationTransition;
import org.eclipse.etrice.core.room.InitialTransition;
+import org.eclipse.etrice.core.room.LogicalSystem;
import org.eclipse.etrice.core.room.MessageFromIf;
import org.eclipse.etrice.core.room.NonInitialTransition;
+import org.eclipse.etrice.core.room.Port;
import org.eclipse.etrice.core.room.RefinedState;
import org.eclipse.etrice.core.room.RoomClass;
import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.SAPRef;
+import org.eclipse.etrice.core.room.SPPRef;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StateGraphItem;
import org.eclipse.etrice.core.room.StateTerminal;
+import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.room.SubStateTrPointTerminal;
+import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.core.room.SubSystemRef;
import org.eclipse.etrice.core.room.TrPoint;
import org.eclipse.etrice.core.room.TrPointTerminal;
@@ -214,9 +222,7 @@ public class RoomNameProvider {
public static String getUniqueTransitionName(StateGraph sg) {
HashSet<String> names = new HashSet<String>();
- for (Transition t : sg.getTransitions()) {
- names.add(t.getName());
- }
+ collectTransitionNames(sg, null, names);
for (int i = 0; i < 1000; i++) {
String name = "tr"+i;
@@ -229,9 +235,7 @@ public class RoomNameProvider {
public static String getUniqueChoicePointName(StateGraph sg) {
HashSet<String> names = new HashSet<String>();
- for (ChoicePoint t : sg.getChPoints()) {
- names.add(t.getName());
- }
+ collectChoicepointNames(sg, null, names);
for (int i = 0; i < 1000; i++) {
String name = "cp"+i;
@@ -244,9 +248,7 @@ public class RoomNameProvider {
public static String getUniqueTrPointName(StateGraph sg) {
HashSet<String> names = new HashSet<String>();
- for (TrPoint tp : sg.getTrPoints()) {
- names.add(tp.getName());
- }
+ collectTrPointNames(sg, null, names);
for (int i = 0; i < 1000; i++) {
String name = "tp"+i;
@@ -259,10 +261,8 @@ public class RoomNameProvider {
public static String getUniqueStateName(StateGraph sg) {
HashSet<String> names = new HashSet<String>();
- for (State s : sg.getStates()) {
- if (s instanceof BaseState)
- names.add(s.getName());
- }
+
+ collectStateNames(sg, null, names);
for (int i = 0; i < 1000; i++) {
String name = "state"+i;
@@ -273,6 +273,82 @@ public class RoomNameProvider {
return "not_unique";
}
+ /**
+ * @param sg
+ * @param skip
+ * @param names
+ */
+ public static void collectStateNames(StateGraph sg, State skip, HashSet<String> names) {
+ for (State s : sg.getStates()) {
+ if (s!=skip)
+ names.add(s.getName());
+ }
+
+ // add base state context
+ if (sg.eContainer() instanceof RefinedState) {
+ RefinedState rs = (RefinedState) sg.eContainer();
+ if (rs.getBase().getSubgraph()!=null)
+ collectStateNames(rs.getBase().getSubgraph(), skip, names);
+ }
+ }
+
+ /**
+ * @param sg
+ * @param skip
+ * @param names
+ */
+ public static void collectTransitionNames(StateGraph sg, Transition skip, HashSet<String> names) {
+ for (Transition s : sg.getTransitions()) {
+ if (s!=skip)
+ names.add(s.getName());
+ }
+
+ // add base state context
+ if (sg.eContainer() instanceof RefinedState) {
+ RefinedState rs = (RefinedState) sg.eContainer();
+ if (rs.getBase().getSubgraph()!=null)
+ collectTransitionNames(rs.getBase().getSubgraph(), skip, names);
+ }
+ }
+
+ /**
+ * @param sg
+ * @param skip
+ * @param names
+ */
+ public static void collectChoicepointNames(StateGraph sg, ChoicePoint skip, HashSet<String> names) {
+ for (ChoicePoint cp : sg.getChPoints()) {
+ if (cp!=skip)
+ names.add(cp.getName());
+ }
+
+ // add base state context
+ if (sg.eContainer() instanceof RefinedState) {
+ RefinedState rs = (RefinedState) sg.eContainer();
+ if (rs.getBase().getSubgraph()!=null)
+ collectChoicepointNames(rs.getBase().getSubgraph(), skip, names);
+ }
+ }
+
+ /**
+ * @param sg
+ * @param skip
+ * @param names
+ */
+ public static void collectTrPointNames(StateGraph sg, TrPoint skip, HashSet<String> names) {
+ for (TrPoint tp : sg.getTrPoints()) {
+ if (tp!=skip)
+ names.add(tp.getName());
+ }
+
+ // add base state context
+ if (sg.eContainer() instanceof RefinedState) {
+ RefinedState rs = (RefinedState) sg.eContainer();
+ if (rs.getBase().getSubgraph()!=null)
+ collectTrPointNames(rs.getBase().getSubgraph(), skip, names);
+ }
+ }
+
public static String getRefLabelName(ActorContainerRef acr) {
String className = "<unknown>";
if (acr instanceof ActorRef) {
@@ -361,4 +437,74 @@ public class RoomNameProvider {
else
return "/"+s.getName();
}
+
+ /**
+ * @param sc
+ * @return
+ */
+ public static String getUniqueActorContainerRefName(StructureClass sc) {
+ HashSet<String> names = new HashSet<String>();
+ if (sc instanceof ActorContainerClass) {
+ for (ActorRef ar : ((ActorContainerClass) sc).getActorRefs()) {
+ names.add(ar.getName());
+ }
+ }
+ else if (sc instanceof LogicalSystem) {
+ for (SubSystemRef ar : ((LogicalSystem) sc).getSubSystems()) {
+ names.add(ar.getName());
+ }
+ }
+
+ for (int i = 0; i < 1000; i++) {
+ String name = "ref"+i;
+ if (!names.contains(name))
+ return name;
+ }
+
+ return "not_unique";
+ }
+
+ /**
+ * @param acc
+ * @return
+ */
+ public static String getUniqueInterfaceItemName(String prefix, ActorContainerClass acc) {
+ HashSet<String> names = new HashSet<String>();
+ if (acc instanceof ActorClass) {
+ ActorClass ac = (ActorClass) acc;
+ do {
+ for (Port p : ac.getIfPorts()) {
+ names.add(p.getName());
+ }
+ for (Port p : ac.getIntPorts()) {
+ names.add(p.getName());
+ }
+ for (SAPRef sap : ac.getStrSAPs()) {
+ names.add(sap.getName());
+ }
+ for (SPPRef spp : ac.getIfSPPs()) {
+ names.add(spp.getName());
+ }
+
+ ac = ac.getBase();
+ }
+ while (ac!=null);
+ }
+ else if (acc instanceof SubSystemClass) {
+ for (Port p : ((SubSystemClass) acc).getRelayPorts()) {
+ names.add(p.getName());
+ }
+ for (SPPRef spp : ((SubSystemClass) acc).getIfSPPs()) {
+ names.add(spp.getName());
+ }
+ }
+
+ for (int i = 0; i < 1000; i++) {
+ String name = prefix+i;
+ if (!names.contains(name))
+ return name;
+ }
+
+ return "not_unique";
+ }
}
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java
index f68599cd7..fbc6f7c86 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/validation/ValidationUtil.java
@@ -13,13 +13,16 @@
package org.eclipse.etrice.core.validation;
import java.util.ArrayList;
+import java.util.HashSet;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.ActorContainerRef;
import org.eclipse.etrice.core.room.ActorRef;
import org.eclipse.etrice.core.room.Binding;
import org.eclipse.etrice.core.room.BindingEndPoint;
+import org.eclipse.etrice.core.room.ChoicePoint;
import org.eclipse.etrice.core.room.DataClass;
import org.eclipse.etrice.core.room.EntryPoint;
import org.eclipse.etrice.core.room.ExitPoint;
@@ -38,6 +41,7 @@ import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.room.SubStateTrPointTerminal;
+import org.eclipse.etrice.core.room.SubSystemClass;
import org.eclipse.etrice.core.room.TrPoint;
import org.eclipse.etrice.core.room.TrPointTerminal;
import org.eclipse.etrice.core.room.Transition;
@@ -568,24 +572,103 @@ public class ValidationUtil {
}
public static Result isUniqueName(InterfaceItem item) {
+ return isUniqueName(item, item.getName());
+ }
+
+ public static Result isUniqueName(InterfaceItem item, String name) {
+ if (name.isEmpty())
+ return Result.error("name must not be empty");
+
if (item.eContainer() instanceof ActorClass) {
ArrayList<InterfaceItem> all = new ArrayList<InterfaceItem>();
ActorClass ac = (ActorClass) item.eContainer();
- while (ac.getBase()!=null) {
- ac = ac.getBase();
+ do {
all.addAll(ac.getIfPorts());
all.addAll(ac.getIntPorts());
all.addAll(ac.getIfSPPs());
all.addAll(ac.getStrSAPs());
+
+ ac = ac.getBase();
}
+ while (ac!=null);
+
for (InterfaceItem ii : all) {
- if (ii!=item && ii.getName().equals(item.getName())) {
- return Result.error("name already used in base class "+((ActorClass)ii.eContainer()).getName());
+ if (ii!=item && ii.getName().equals(name)) {
+ if (ii.eContainer()!=item.eContainer())
+ return Result.error("name already used in base class "+((ActorClass)ii.eContainer()).getName());
+ else
+ return Result.error("name already used");
}
}
}
- // else
- // we don't have to check SubSystemClasses since this is done by xtext (standard namespace)
+ else if (item.eContainer() instanceof SubSystemClass) {
+ SubSystemClass ssc = (SubSystemClass) item.eContainer();
+ ArrayList<InterfaceItem> all = new ArrayList<InterfaceItem>();
+ all.addAll(ssc.getIfSPPs());
+ all.addAll(ssc.getRelayPorts());
+
+ for (InterfaceItem ii : all) {
+ if (ii!=item && ii.getName().equals(name)) {
+ return Result.error("name already used");
+ }
+ }
+ }
+
+ return Result.ok();
+ }
+
+ public static Result isUniqueName(State s, String name) {
+ if (name.isEmpty())
+ return Result.error("name must not be empty");
+
+ StateGraph sg = (StateGraph) s.eContainer();
+ HashSet<String> names = new HashSet<String>();
+ RoomNameProvider.collectStateNames(sg, s, names);
+
+ if (names.contains(name))
+ return Result.error("name already used");
+
+ return Result.ok();
+ }
+
+ public static Result isUniqueName(Transition t, String name) {
+ if (name.isEmpty())
+ return Result.error("name must not be empty");
+
+ StateGraph sg = (StateGraph) t.eContainer();
+ HashSet<String> names = new HashSet<String>();
+ RoomNameProvider.collectTransitionNames(sg, t, names);
+
+ if (names.contains(name))
+ return Result.error("name already used");
+
+ return Result.ok();
+ }
+
+ public static Result isUniqueName(TrPoint t, String name) {
+ if (name.isEmpty())
+ return Result.error("name must not be empty");
+
+ StateGraph sg = (StateGraph) t.eContainer();
+ HashSet<String> names = new HashSet<String>();
+ RoomNameProvider.collectTrPointNames(sg, t, names);
+
+ if (names.contains(name))
+ return Result.error("name already used");
+
+ return Result.ok();
+ }
+
+ public static Result isUniqueName(ChoicePoint t, String name) {
+ if (name.isEmpty())
+ return Result.error("name must not be empty");
+
+ StateGraph sg = (StateGraph) t.eContainer();
+ HashSet<String> names = new HashSet<String>();
+ RoomNameProvider.collectChoicepointNames(sg, t, names);
+
+ if (names.contains(name))
+ return Result.error("name already used");
return Result.ok();
}
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 18cba4381..ebcea8839 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
@@ -8,7 +8,8 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.etrice.core.room.BaseState;
import org.eclipse.etrice.core.room.RoomPackage;
import org.eclipse.etrice.core.room.State;
-import org.eclipse.etrice.core.room.StateGraph;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.core.validation.ValidationUtil.Result;
import org.eclipse.etrice.ui.behavior.Activator;
import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
import org.eclipse.swt.SWT;
@@ -28,25 +29,19 @@ public class StatePropertyDialog extends AbstractPropertyDialog {
if (value instanceof String) {
String name = (String) value;
- if (name.isEmpty())
- return ValidationStatus.error("name must not be empty");
-
- for (State s : sg.getStates()) {
- if (s!=state && s.getName()!=null && s.getName().equals(name))
- return ValidationStatus.error("name already used");
- }
+ Result result = ValidationUtil.isUniqueName(state, name);
+ if (!result.isOk())
+ return ValidationStatus.error(result.getMsg());
}
return Status.OK_STATUS;
}
}
private State state;
- private StateGraph sg;
- public StatePropertyDialog(Shell shell, State s, StateGraph sg) {
+ public StatePropertyDialog(Shell shell, State s) {
super(shell, "Edit State");
this.state = s;
- this.sg = sg;
}
@Override
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 32e1e1bbb..b1c431568 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
@@ -6,9 +6,10 @@ import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.etrice.core.room.RoomPackage;
-import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.TrPoint;
import org.eclipse.etrice.core.room.TransitionPoint;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.core.validation.ValidationUtil.Result;
import org.eclipse.etrice.ui.behavior.Activator;
import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
import org.eclipse.swt.graphics.Image;
@@ -26,25 +27,18 @@ public class TrPointPropertyDialog extends AbstractPropertyDialog {
if (value instanceof String) {
String name = (String) value;
- if (name.isEmpty())
- return ValidationStatus.error("name must not be empty");
-
- for (TrPoint t : sg.getTrPoints()) {
- if (t!=tp && t.getName()!=null && t.getName().equals(name))
- return ValidationStatus.error("name already used");
- }
+ Result result = ValidationUtil.isUniqueName(tp, name);
+ if (!result.isOk())
+ return ValidationStatus.error(result.getMsg());
}
return Status.OK_STATUS;
}
}
- private StateGraph sg;
private TrPoint tp;
- public TrPointPropertyDialog(Shell shell, TrPoint tp, StateGraph sg,
- boolean subtp) {
+ public TrPointPropertyDialog(Shell shell, TrPoint tp, boolean subtp) {
super(shell, "Edit Transition Point");
- this.sg = sg;
this.tp = tp;
}
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 c49b1fbac..0810824bb 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
@@ -29,6 +29,8 @@ import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.Transition;
import org.eclipse.etrice.core.room.Trigger;
import org.eclipse.etrice.core.room.TriggeredTransition;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.core.validation.ValidationUtil.Result;
import org.eclipse.etrice.ui.behavior.Activator;
import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
@@ -137,13 +139,9 @@ public class TransitionPropertyDialog extends AbstractPropertyDialog {
if (value instanceof String) {
String name = (String) value;
- if (name.isEmpty())
- return ValidationStatus.error("name must not be empty");
-
- for (Transition t : sg.getTransitions()) {
- if (t!=trans && t.getName()!=null && t.getName().equals(name))
- return ValidationStatus.error("name already used");
- }
+ Result result = ValidationUtil.isUniqueName(trans, name);
+ if (!result.isOk())
+ return ValidationStatus.error(result.getMsg());
}
return Status.OK_STATUS;
}
@@ -214,6 +212,7 @@ public class TransitionPropertyDialog extends AbstractPropertyDialog {
createDecorator(name, "invalid name");
+ name.selectAll();
name.setFocus();
}
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/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
index 7f0af4bf9..8f7c32e5f 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateGraphSupport.java
@@ -23,6 +23,7 @@ import org.eclipse.etrice.core.room.StructureClass;
import org.eclipse.etrice.core.room.TrPoint;
import org.eclipse.graphiti.dt.IDiagramTypeProvider;
import org.eclipse.graphiti.features.IAddFeature;
+import org.eclipse.graphiti.features.IDeleteFeature;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.ILayoutFeature;
import org.eclipse.graphiti.features.IReason;
@@ -31,6 +32,7 @@ import org.eclipse.graphiti.features.IResizeShapeFeature;
import org.eclipse.graphiti.features.IUpdateFeature;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.context.ICustomContext;
+import org.eclipse.graphiti.features.context.IDeleteContext;
import org.eclipse.graphiti.features.context.IDoubleClickContext;
import org.eclipse.graphiti.features.context.ILayoutContext;
import org.eclipse.graphiti.features.context.IRemoveContext;
@@ -42,6 +44,7 @@ import org.eclipse.graphiti.features.custom.ICustomFeature;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.features.impl.AbstractLayoutFeature;
import org.eclipse.graphiti.features.impl.AbstractUpdateFeature;
+import org.eclipse.graphiti.features.impl.DefaultRemoveFeature;
import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
import org.eclipse.graphiti.features.impl.Reason;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
@@ -59,6 +62,7 @@ import org.eclipse.graphiti.services.IGaService;
import org.eclipse.graphiti.services.IPeCreateService;
import org.eclipse.graphiti.tb.DefaultToolBehaviorProvider;
import org.eclipse.graphiti.tb.IToolBehaviorProvider;
+import org.eclipse.graphiti.ui.features.DefaultDeleteFeature;
import org.eclipse.graphiti.ui.features.DefaultFeatureProvider;
import org.eclipse.graphiti.util.ColorConstant;
import org.eclipse.graphiti.util.IColorConstant;
@@ -385,6 +389,30 @@ public class StateGraphSupport {
}
}
+ private class RemoveFeature extends DefaultRemoveFeature {
+
+ public RemoveFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canRemove(IRemoveContext context) {
+ return false;
+ }
+ }
+
+ private class DeleteFeature extends DefaultDeleteFeature {
+
+ public DeleteFeature(IFeatureProvider fp) {
+ super(fp);
+ }
+
+ @Override
+ public boolean canDelete(IDeleteContext context) {
+ return false;
+ }
+ }
+
private IFeatureProvider fp;
public FeatureProvider(IDiagramTypeProvider dtp, IFeatureProvider fp) {
@@ -414,6 +442,16 @@ public class StateGraphSupport {
}
@Override
+ public IRemoveFeature getRemoveFeature(IRemoveContext context) {
+ return new RemoveFeature(fp);
+ }
+
+ @Override
+ public IDeleteFeature getDeleteFeature(IDeleteContext context) {
+ return new DeleteFeature(fp);
+ }
+
+ @Override
public ICustomFeature[] getCustomFeatures(ICustomContext context) {
return new ICustomFeature[] { new GoUpFeature(fp) };
}
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/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java
index 358d9adf7..0f7fb95a4 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/StateSupport.java
@@ -145,15 +145,15 @@ public class StateSupport {
// create new State
BaseState s = RoomFactory.eINSTANCE.createBaseState();
s.setName(RoomNameProvider.getUniqueStateName(sg));
+
+ sg.getStates().add(s);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- StatePropertyDialog dlg = new StatePropertyDialog(shell, s, sg);
+ StatePropertyDialog dlg = new StatePropertyDialog(shell, s);
if (dlg.open()!=Window.OK)
// find a method to abort creation
//throw new RuntimeException();
return EMPTY;
-
- sg.getStates().add(s);
addGraphicalRepresentation(context, s);
@@ -324,10 +324,9 @@ public class StateSupport {
@Override
public void execute(ICustomContext context) {
State s = (State) getBusinessObjectForPictogramElement(context.getPictogramElements()[0]);
+
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- StateGraph sg = (StateGraph)s.eContainer();
-
- StatePropertyDialog dlg = new StatePropertyDialog(shell, s, sg);
+ StatePropertyDialog dlg = new StatePropertyDialog(shell, s);
if (dlg.open()!=Window.OK)
// TODOHRR: introduce a method to revert changes
//throw new RuntimeException();
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/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java
index c562234a7..76a84720c 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TrPointSupport.java
@@ -147,18 +147,18 @@ public class TrPointSupport {
}
StateGraph sg = (StateGraph) context.getTargetContainer().getLink().getBusinessObjects().get(0);
tp.setName(RoomNameProvider.getUniqueTrPointName(sg));
+
+ sg.getTrPoints().add(tp);
// TODOHRR-B add property dialog
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- TrPointPropertyDialog dlg = new TrPointPropertyDialog(shell, tp, sg, false);
+ TrPointPropertyDialog dlg = new TrPointPropertyDialog(shell, tp, false);
if (dlg.open()!=Window.OK)
// find a method to abort creation
//throw new RuntimeException();
return EMPTY;
doneChanges = true;
-
- sg.getTrPoints().add(tp);
// do the add
addGraphicalRepresentation(context, tp);
@@ -487,11 +487,10 @@ public class TrPointSupport {
public void execute(ICustomContext context) {
PictogramElement pe = context.getPictogramElements()[0];
TrPoint tp = (TrPoint) getBusinessObjectForPictogramElement(pe);
- StateGraph sg = (StateGraph)tp.eContainer();
boolean subtp = isSubTP(pe);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- TrPointPropertyDialog dlg = new TrPointPropertyDialog(shell, tp, sg, subtp);
+ TrPointPropertyDialog dlg = new TrPointPropertyDialog(shell, tp, subtp);
if (dlg.open()!=Window.OK)
// TODOHRR: introduce a method to revert changes, does hasDoneChanges=false roll back changes?
//throw new RuntimeException();
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/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java
index fd22555d2..0a297fd25 100644
--- a/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/support/TransitionSupport.java
@@ -184,9 +184,10 @@ public class TransitionSupport {
trans.setName("init");
}
else {
- String name = RoomNameProvider.getUniqueTransitionName(sg);
- trans.setName(name);
+ trans.setName(RoomNameProvider.getUniqueTransitionName(sg));
}
+
+ sg.getTransitions().add(trans);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
TransitionPropertyDialog dlg = new TransitionPropertyDialog(shell, sg, trans);
@@ -194,8 +195,6 @@ public class TransitionSupport {
// find a method to abort creation
//throw new RuntimeException();
return null;
-
- sg.getTransitions().add(trans);
AddConnectionContext addContext = new AddConnectionContext(context.getSourceAnchor(), context.getTargetAnchor());
addContext.setNewObject(trans);
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
index 2e732ac98..ffdadf0cf 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/ActorContainerRefPropertyDialog.java
@@ -151,6 +151,7 @@ public class ActorContainerRefPropertyDialog extends AbstractPropertyDialog {
refClass.setEnabled(false);
}
+ name.selectAll();
name.setFocus();
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java
index a58d040f9..8cceaf3e3 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/PortPropertyDialog.java
@@ -21,6 +21,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.core.validation.ValidationUtil.Result;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
@@ -54,45 +55,12 @@ public class PortPropertyDialog extends AbstractPropertyDialog {
if (value instanceof String) {
String name = (String) value;
- if (name.isEmpty())
- return ValidationStatus.error("name must not be empty");
-
- // TODOHRR: check valid identifier
- // TODOHRR: use ValidationUtil
-
- if (acc instanceof ActorClass) {
- if (nameExists((ActorClass) acc, name))
- return ValidationStatus.error("name already exists");
- }
- else if (acc instanceof SubSystemClass) {
- SubSystemClass ssc = (SubSystemClass) acc;
- for (Port p : ssc.getRelayPorts()) {
- if (p!=port && p.getName().equals(name))
- return ValidationStatus.error("name already exists");
- }
- }
- else {
- assert(false): "unexpected type";
- }
- return Status.OK_STATUS;
+ Result result = ValidationUtil.isUniqueName(port, name);
+ if (!result.isOk())
+ return ValidationStatus.error(result.getMsg());
}
return Status.OK_STATUS;
}
-
- private boolean nameExists(ActorClass ac, String name) {
- for (Port p : ac.getIfPorts()) {
- if (p!=port && p.getName().equals(name))
- return true;
- }
- for (Port p : ac.getIntPorts()) {
- if (p!=port && p.getName().equals(name))
- return true;
- }
- if (ac.getBase()!=null)
- return nameExists(ac.getBase(), name);
-
- return false;
- }
}
class ProtocolValidator implements IValidator {
@@ -222,6 +190,7 @@ public class PortPropertyDialog extends AbstractPropertyDialog {
createDecorator(protocol, "no protocol selected");
createDecorator(multi, "multiplicity must be greater 1");
+ name.selectAll();
name.setFocus();
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java
index fd4fbe80a..5bafab1f4 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/dialogs/SPPPropertyDialog.java
@@ -20,22 +20,21 @@ import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.etrice.core.validation.ValidationUtil;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.forms.IManagedForm;
-
-import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.ProtocolClass;
import org.eclipse.etrice.core.room.RoomModel;
import org.eclipse.etrice.core.room.RoomPackage;
import org.eclipse.etrice.core.room.SPPRef;
+import org.eclipse.etrice.core.validation.ValidationUtil;
+import org.eclipse.etrice.core.validation.ValidationUtil.Result;
import org.eclipse.etrice.ui.common.dialogs.AbstractPropertyDialog;
import org.eclipse.etrice.ui.structure.Activator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.IManagedForm;
public class SPPPropertyDialog extends AbstractPropertyDialog {
@@ -46,32 +45,14 @@ public class SPPPropertyDialog extends AbstractPropertyDialog {
if (value instanceof String) {
String name = (String) value;
- if (name.isEmpty())
- return ValidationStatus.error("name must not be empty");
-
- // TODOHRR: check valid identifier
- // TODOHRR: use ValidationUtil
-
- if (nameExists(acc, name))
- return ValidationStatus.error("name already exists");
+ Result result = ValidationUtil.isUniqueName(spp, name);
+ if (!result.isOk())
+ return ValidationStatus.error(result.getMsg());
return Status.OK_STATUS;
}
return Status.OK_STATUS;
}
-
- private boolean nameExists(ActorContainerClass ac, String name) {
- for (SPPRef s : ac.getIfSPPs()) {
- if (s!=spp && s.getName().equals(name))
- return true;
- }
-
- if (ac instanceof ActorClass)
- if (((ActorClass)ac).getBase()!=null)
- return nameExists(((ActorClass)ac).getBase(), name);
-
- return false;
- }
}
class ProtocolValidator implements IValidator {
@@ -137,6 +118,7 @@ public class SPPPropertyDialog extends AbstractPropertyDialog {
createDecorator(name, "invalid name");
createDecorator(protocol, "no protocol selected");
+ name.selectAll();
name.setFocus();
}
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
index d6de4efc5..cce8510e2 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
@@ -143,14 +143,6 @@ public class ActorContainerRefSupport {
// create ActorRef
ActorRef ar = RoomFactory.eINSTANCE.createActorRef();
- ar.setName("");
-
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- ActorContainerRefPropertyDialog dlg = new ActorContainerRefPropertyDialog(shell, ar, sc, true);
- if (dlg.open()!=Window.OK)
- // find a method to abort creation
- //throw new RuntimeException();
- return EMPTY;
acc.getActorRefs().add(ar);
newRef = ar;
@@ -161,19 +153,20 @@ public class ActorContainerRefSupport {
// create ActorRef
SubSystemRef ssr = RoomFactory.eINSTANCE.createSubSystemRef();
- ssr.setName("");
-
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- ActorContainerRefPropertyDialog dlg = new ActorContainerRefPropertyDialog(shell, ssr, sc, true);
- if (dlg.open()!=Window.OK)
- // find a method to abort creation
- //throw new RuntimeException();
- return EMPTY;
sys.getSubSystems().add(ssr);
newRef = ssr;
}
+ newRef.setName(RoomNameProvider.getUniqueActorContainerRefName(sc));
+
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ ActorContainerRefPropertyDialog dlg = new ActorContainerRefPropertyDialog(shell, newRef, sc, true);
+ if (dlg.open()!=Window.OK)
+ // find a method to abort creation
+ //throw new RuntimeException();
+ return EMPTY;
+
addGraphicalRepresentation(context, newRef);
// return newly created business object(s)
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java
index 223d1c03a..06d8e422b 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/PortSupport.java
@@ -49,6 +49,7 @@ import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.InterfaceItem;
@@ -76,20 +77,11 @@ public class PortSupport extends InterfaceItemSupport {
@Override
public Object[] create(ICreateContext context) {
- // create Port
+ ActorContainerClass acc = (ActorContainerClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
+
+ // create Port
Port port = RoomFactory.eINSTANCE.createPort();
- port.setName("");
-
- ActorContainerClass acc = (ActorContainerClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
-
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- PortPropertyDialog dlg = new PortPropertyDialog(shell, port, acc, true, false, internal);
- if (dlg.open()!=Window.OK)
- // find a method to abort creation
- //throw new RuntimeException();
- return EMPTY;
-
- doneChanges = true;
+ port.setName(RoomNameProvider.getUniqueInterfaceItemName("p", acc));
if (acc instanceof ActorClass) {
ActorClass ac = (ActorClass) acc;
@@ -106,6 +98,15 @@ public class PortSupport extends InterfaceItemSupport {
assert(false): "ActorClass or SubSystemClass expected";
}
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ PortPropertyDialog dlg = new PortPropertyDialog(shell, port, acc, true, false, internal);
+ if (dlg.open()!=Window.OK)
+ // find a method to abort creation
+ //throw new RuntimeException();
+ return EMPTY;
+
+ doneChanges = true;
+
// do the add
addGraphicalRepresentation(context, port);
diff --git a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java
index 487c7fcb1..766230855 100644
--- a/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java
+++ b/plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/SPPSupport.java
@@ -53,6 +53,7 @@ import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
import org.eclipse.etrice.core.room.ActorContainerClass;
import org.eclipse.etrice.core.room.InterfaceItem;
import org.eclipse.etrice.core.room.RoomFactory;
@@ -77,11 +78,13 @@ public class SPPSupport extends InterfaceItemSupport {
@Override
public Object[] create(ICreateContext context) {
- // create SPP
+ ActorContainerClass acc = (ActorContainerClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
+
+ // create SPP
SPPRef spp = RoomFactory.eINSTANCE.createSPPRef();
- spp.setName("");
-
- ActorContainerClass acc = (ActorContainerClass) context.getTargetContainer().getLink().getBusinessObjects().get(0);
+ spp.setName(RoomNameProvider.getUniqueInterfaceItemName("spp", acc));
+
+ acc.getIfSPPs().add(spp);
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
SPPPropertyDialog dlg = new SPPPropertyDialog(shell, spp, acc, true, false);
@@ -91,8 +94,6 @@ public class SPPSupport extends InterfaceItemSupport {
return EMPTY;
doneChanges = true;
-
- acc.getIfSPPs().add(spp);
// do the add
addGraphicalRepresentation(context, spp);

Back to the top