Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2018-03-09 09:38:25 -0500
committerHenrik Rentz-Reichert2018-03-09 09:38:25 -0500
commita6684100057877c4f02190d3e84a9ca856c0deb9 (patch)
treeec3539bf0af1681f723908d4bcd0de0c4e9ac25d
parent374e54fd5d173e5d6ca9e89f82fa8a3ab557aa01 (diff)
downloadorg.eclipse.etrice-a6684100057877c4f02190d3e84a9ca856c0deb9.tar.gz
org.eclipse.etrice-a6684100057877c4f02190d3e84a9ca856c0deb9.tar.xz
org.eclipse.etrice-a6684100057877c4f02190d3e84a9ca856c0deb9.zip
Bug 532243 - Empty RefinedStates cause problems
* added validation in StatePropertyDialog * added general model validation * rolling back canceled action "Refine and edit state" Change-Id: Ic9c000852d114bbeb038a039db43bf0bca96dc3a
-rw-r--r--plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java34
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java5
-rw-r--r--plugins/org.eclipse.etrice.ui.behavior/src/org/eclipse/etrice/ui/behavior/dialogs/StatePropertyDialog.java70
3 files changed, 83 insertions, 26 deletions
diff --git a/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java b/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java
index f9aaedca7..fca7e9f1d 100644
--- a/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java
+++ b/plugins/org.eclipse.etrice.core.fsm/src/org/eclipse/etrice/core/fsm/validation/FSMJavaValidator.java
@@ -26,6 +26,7 @@ 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.core.fsm.services.FSMGrammarAccess;
+import org.eclipse.etrice.core.fsm.util.FSMHelpers;
import org.eclipse.etrice.core.fsm.validation.FSMValidationUtilXtend.Result;
import org.eclipse.xtext.AbstractRule;
import org.eclipse.xtext.RuleCall;
@@ -48,7 +49,10 @@ public class FSMJavaValidator extends org.eclipse.etrice.core.fsm.validation.Abs
public static final String PLAIN_STRING_DETAILCODE = "RoomJavaValidator.PlainStringDetailCode";
@Inject
- private FSMValidationUtil ValidationUtil;
+ private FSMValidationUtil validationUtil;
+
+ @Inject
+ private FSMHelpers fsmHelpers;
@Inject
FSMGrammarAccess grammar;
@@ -73,36 +77,48 @@ public class FSMJavaValidator extends org.eclipse.etrice.core.fsm.validation.Abs
}
@Check
+ public void checkRefinedStateNotEmpty(RefinedState rs) {
+ if (rs.getSubgraph()==null) {
+ boolean entryEmpty = fsmHelpers.getDetailCode(rs.getEntryCode()).trim().isEmpty();
+ boolean exitEmpty = fsmHelpers.getDetailCode(rs.getExitCode()).trim().isEmpty();
+ boolean doEmpty = fsmHelpers.getDetailCode(rs.getDoCode()).trim().isEmpty();
+ if (entryEmpty && exitEmpty && doEmpty) {
+ error("Refined state must not be empty (needs to have at least one action code or a subgraph).", FSMPackage.Literals.STATE__ENTRY_CODE);
+ }
+ }
+ }
+
+ @Check
public void checkStateNameUnique(SimpleState s) {
-// Result result = ValidationUtil.isUniqueName(s, s.getName());
+// Result result = validationUtil.isUniqueName(s, s.getName());
// if (!result.isOk())
// error(result.getMsg(), FSMPackage.Literals.SIMPLE_STATE__NAME);
}
@Check
public void checkTrPoint(TrPoint tp) {
- Result result = ValidationUtil.isValid(tp);
+ Result result = validationUtil.isValid(tp);
if (!result.isOk())
error(result);
}
@Check
public void checkChoicePoint(ChoicePoint cp) {
-// if (!ValidationUtil.isUniqueName(cp, cp.getName()).isOk())
+// if (!validationUtil.isUniqueName(cp, cp.getName()).isOk())
// error("name is not unique", FSMPackage.Literals.CHOICE_POINT__NAME);
}
@Check
public void checkTransition(Transition trans) {
- Result result = ValidationUtil.checkTransition(trans);
+ Result result = validationUtil.checkTransition(trans);
if (!result.isOk())
error(result);
if (trans instanceof InitialTransition) {
- result = ValidationUtil.isConnectable(null, trans.getTo(), trans, (StateGraph)trans.eContainer());
+ result = validationUtil.isConnectable(null, trans.getTo(), trans, (StateGraph)trans.eContainer());
}
else {
- result = ValidationUtil.isConnectable(((NonInitialTransition)trans).getFrom(), trans.getTo(), trans, (StateGraph)trans.eContainer());
+ result = validationUtil.isConnectable(((NonInitialTransition)trans).getFrom(), trans.getTo(), trans, (StateGraph)trans.eContainer());
}
if (!result.isOk())
error(result);
@@ -112,11 +128,11 @@ public class FSMJavaValidator extends org.eclipse.etrice.core.fsm.validation.Abs
@Check
public void checkState(org.eclipse.etrice.core.fsm.fSM.State state) {
- Result result = ValidationUtil.checkState(state);
+ Result result = validationUtil.checkState(state);
if (!result.isOk())
error(result);
- ArrayList<Result> res = ValidationUtil.uniqueOriginTriggers(state);
+ ArrayList<Result> res = validationUtil.uniqueOriginTriggers(state);
for (Result r : res) {
error(r);
}
diff --git a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java
index 5de5a6031..ebd6c7cfc 100644
--- a/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java
+++ b/plugins/org.eclipse.etrice.ui.behavior.fsm/src/org/eclipse/etrice/ui/behavior/fsm/support/StateSupport.java
@@ -599,6 +599,11 @@ public class StateSupport {
for (ICustomFeature cf : features) {
if (cf instanceof PropertyFeature) {
cf.execute(context);
+ if (!cf.hasDoneChanges()) {
+ // roll back
+ link(container, s);
+ EcoreUtil.remove(rs);
+ }
break;
}
}
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 15cf7211d..25689df7e 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
@@ -5,6 +5,7 @@ import static org.eclipse.etrice.core.fsm.fSM.FSMPackage.Literals.STATE__ENTRY_C
import static org.eclipse.etrice.core.ui.util.UIExpressionUtil.getExpressionProvider;
import java.util.EnumSet;
+import java.util.List;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.validation.IValidator;
@@ -30,6 +31,7 @@ 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.etrice.ui.common.base.dialogs.MultiValidator2;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
@@ -41,7 +43,7 @@ import org.eclipse.ui.forms.IManagedForm;
public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog implements IStatePropertyDialog {
- class NameValidator implements IValidator {
+ private class NameValidator implements IValidator {
@Override
public IStatus validate(Object value) {
@@ -55,6 +57,36 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
return Status.OK_STATUS;
}
}
+
+ private class NonEmptyRefinedStateValidator extends MultiValidator2 {
+
+ public NonEmptyRefinedStateValidator(DataBindingContext bindingContext, int nActionCodes) {
+ super(bindingContext, nActionCodes);
+ }
+
+ @Override
+ public IStatus validate(List<Object> values) {
+ if (state instanceof RefinedState) {
+ RefinedState rs = (RefinedState) state;
+ if (rs.getSubgraph()==null) {
+ RoomHelpers roomHelpers = SupportUtil.getInstance().getRoomHelpers();
+ boolean allEmpty = true;
+ for (Object value : values) {
+ String actionCode = roomHelpers.getDetailCode((DetailCode) value);
+ if (!actionCode.trim().isEmpty()) {
+ allEmpty = false;
+ break;
+ }
+ }
+ if (allEmpty) {
+ return ValidationStatus.error("Not all action codes must be empty if the refined state has no subgraph.");
+ }
+ }
+ }
+ return ValidationStatus.ok();
+ }
+
+ }
private State state;
private boolean inherited;
@@ -116,6 +148,11 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
StringToDetailCode s2m = new StringToDetailCode();
RoomHelpers roomHelpers = SupportUtil.getInstance().getRoomHelpers();
+ ActorClass ac = roomHelpers.getActorClass(state);
+ boolean hasDoCode = ac.getCommType()!=ComponentCommunicationType.EVENT_DRIVEN;
+
+ int nActionCodes = hasDoCode ? 3 : 2;
+ NonEmptyRefinedStateValidator nonEmptyValidator = new NonEmptyRefinedStateValidator(bindingContext, nActionCodes);
if (inherited) {
String code = roomHelpers.getDetailCode(state.getEntryCode());
@@ -142,8 +179,8 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
}
}
- createActionCodeEditor(body, "&Entry Code:", state.getEntryCode(),
- FSMPackage.eINSTANCE.getState_EntryCode(), s2m, m2s, getExpressionProvider(state, STATE__ENTRY_CODE));
+ createActionCodeEditor(body, "&Entry Code:", state.getEntryCode(), FSMPackage.eINSTANCE.getState_EntryCode(), nonEmptyValidator, s2m,
+ m2s, getExpressionProvider(state, STATE__ENTRY_CODE));
}
if (inherited) {
@@ -156,8 +193,8 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
entry.setLayoutData(gd);
}
else {
- createActionCodeEditor(body, "E&xit Code:", state.getExitCode(),
- FSMPackage.eINSTANCE.getState_ExitCode(), s2m, m2s, getExpressionProvider(state, STATE__ENTRY_CODE));
+ createActionCodeEditor(body, "E&xit Code:", state.getExitCode(), FSMPackage.eINSTANCE.getState_ExitCode(), nonEmptyValidator, s2m,
+ m2s, getExpressionProvider(state, STATE__ENTRY_CODE));
if (state instanceof RefinedState)
{
@@ -169,10 +206,9 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
}
}
- ActorClass ac = roomHelpers.getActorClass(state);
- if (ac.getCommType()!=ComponentCommunicationType.EVENT_DRIVEN)
- createActionCodeEditor(body, "&Do Code:", state.getDoCode(),
- FSMPackage.eINSTANCE.getState_DoCode(), s2m, m2s, getExpressionProvider(state, STATE__DO_CODE));
+ if (hasDoCode)
+ createActionCodeEditor(body, "&Do Code:", state.getDoCode(), FSMPackage.eINSTANCE.getState_DoCode(), nonEmptyValidator, s2m,
+ m2s, getExpressionProvider(state, STATE__DO_CODE));
createMembersAndMessagesButtons(body);
@@ -191,7 +227,6 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
* {@link #state} and binds it with the model.
*
* @author jayant
- *
* @param parent
* the {@link Composite} which will hold the editor
* @param label
@@ -200,20 +235,20 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
* the {@link DetailCode} object to be represented
* @param feat
* the {@link EStructuralFeature} associated with the code
+ * @param multiValidator
* @param s2m
* a String to Model converter
* @param m2s
* a Model to string converter
- *
* @return the constructed instance of {@link IActionCodeEditor}
*/
- private void createActionCodeEditor(Composite parent, String label,
- DetailCode detailCode, EStructuralFeature feat,
- StringToDetailCode s2m, DetailCodeToString m2s, IDetailExpressionProvider detailExpr) {
-
+ private void createActionCodeEditor(Composite parent, String label, DetailCode detailCode, EStructuralFeature feat,
+ MultiValidator2 multiValidator, StringToDetailCode s2m, DetailCodeToString m2s,
+ IDetailExpressionProvider detailExpr) {
+
IActionCodeEditor entry = super.createActionCodeEditor(parent, label,
- detailCode, state, feat, s2m, m2s, detailExpr);
-
+ detailCode, state, feat, null, multiValidator, s2m, m2s, true, true, false, detailExpr);
+
Control control;
if (entry != null)
control = entry.getControl();
@@ -225,6 +260,7 @@ public class StatePropertyDialog extends AbstractMemberAwarePropertyDialog imple
configureMemberAwareness(textEntry, true, true);
control = textEntry;
}
+ createDecorator(control, "invalid text");
//set layout for the created control
GridData gd = new GridData(GridData.FILL_BOTH);

Back to the top