From 95c96ffc3c226f2e01f3625b1146e5ac014c4751 Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Thu, 12 Apr 2018 08:30:37 +0000 Subject: [PATCH] GREEN (with minor adaptations) --- .../fortiss/tooling/base/ui/editor/.ratings | 4 +-- .../editor/ConstraintBasedProcessEditor.java | 35 ++++++++++--------- .../ConstraintBasedProcessEditorHelper.java | 32 +++++++---------- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/.ratings b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/.ratings index aec98fe09..e707eee7b 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/.ratings +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/.ratings @@ -1,8 +1,8 @@ AdvancedTreeViewerEditorBase.java 3bb67c52886069379765289885df3b23790b88c9 GREEN AllocationDiagramEditorBase.java 3c03b9220f1c342ded673d6d1b2fd2c01b57fba6 GREEN CommonDiagramEditorBase.java 438babd95dd7a185bd32246cb8180b00bb53f18a GREEN -ConstraintBasedProcessEditor.java 5b065b9e417a142c6b0a37ad75b9a41c513743e4 YELLOW -ConstraintBasedProcessEditorHelper.java 8c1e6cd5ae787199a9f0b2130302dcda5d61e347 GREEN +ConstraintBasedProcessEditor.java 2b565588008fc9fdd6472e5d9035e69d4682840c GREEN +ConstraintBasedProcessEditorHelper.java 68402c6733552a9d5923eae2f697ac7ce0874744 GREEN DiagramEditorBase.java 3d2bb40e18548ebca0dfdd78f094598e5ee298d1 GREEN DiagramKeyHandler.java 8b64048b966e6e8cacfa7fb78edebef2a4981fc4 GREEN FormsEditorBase.java 50934d36124dea9b16ac45fe3621d878afb48bc7 GREEN diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditor.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditor.java index 02863e93a..06891ab7f 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditor.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditor.java @@ -100,6 +100,7 @@ import org.fortiss.tooling.kernel.ui.service.IActionService; import org.fortiss.tooling.kernel.ui.service.IConstraintUIService; import org.fortiss.tooling.kernel.ui.service.IContextMenuService; +// TODO Refactor this huge class and provide a dedicated perspective (see #3189) /** * Editor for {@link IConstraintBasedProcess}s. * @@ -108,6 +109,9 @@ import org.fortiss.tooling.kernel.ui.service.IContextMenuService; public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> extends EditorBase<CBP> implements ContextMenuContextProvider, ISelectionProvider { + /** Width of columns to display constraints. */ + private static final int COLUMN_WIDTH = 1300; + /** {@inheritDoc} */ @Override public void addPartPropertyListener(IPropertyChangeListener listener) { @@ -126,7 +130,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e /** Selection of the tree. */ private ISelection selection; - /** */ + /** List of parent nodes. */ private List<TreeStructureNode> parentList; /** Adapter for refreshing content. */ @@ -226,10 +230,9 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e } else if(parentElement instanceof ConstraintConfiguration) { List<Object> types = new ArrayList<Object>(); - Set<Class<? extends IConstraint>> availableCstrs = - IConstraintUIService.getInstance().getAllConstraints(); - availableCstrs.removeAll(IConstraintUIService.getInstance() - .getAlwaysActivatedConstraints()); + final IConstraintUIService cuis = IConstraintUIService.getInstance(); + Set<Class<? extends IConstraint>> availableCstrs = cuis.getAllConstraints(); + availableCstrs.removeAll(cuis.getAlwaysActivatedConstraints()); EList<ConstraintConfiguration> configs = editedObject.getConfigurations(); if(configs.size() > 1) { @@ -246,9 +249,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e types.add(refs); } - Set<Class<? extends IConstraint>> availableConstraints = - IConstraintUIService.getInstance().getAllConstraints(); - IConstraintUIService cuis = IConstraintUIService.getInstance(); + Set<Class<? extends IConstraint>> availableConstraints = cuis.getAllConstraints(); // Collecting the groups in the array list List<String> groupName = new ArrayList<String>(); @@ -311,10 +312,10 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e } /** This constraint map contains the name and the description of all of the constraints */ - HashMap<String, String> constraintMap = new HashMap<String, String>(); + private HashMap<String, String> constraintMap = new HashMap<String, String>(); /** This HashMap contains the groups and the the grouped constraints (as a HashMap) */ - HashMap<String, HashMap<String, String>> groupNameAndConstraints = + private HashMap<String, HashMap<String, String>> groupNameAndConstraints = new HashMap<String, HashMap<String, String>>(); /** Text labels for the tree of configurations. */ @@ -459,8 +460,9 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e List<ConstraintConfiguration> activeConfigs = getActiveConfigurationsTransitively(config, null); - // If the selected constraint is in the active constraints list - if(activeConfigs.get(0) != null) { + // If the set of active constraints is not empty, and the selected + // constraint is in the active constraints list + if(!activeConfigs.isEmpty() && activeConfigs.get(0) != null) { // get all active constraints of the first configuration which // is selected using activeConfigs.get(0) EList<String> activeConstraints = @@ -508,7 +510,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e treeViewer = new ConfigTree(parent); TreeColumn column = new TreeColumn(treeViewer.getTree(), SWT.LEFT); column.setText("Constraint configurations"); - column.setWidth(1300); + column.setWidth(COLUMN_WIDTH); TreeViewerColumn onlyViewerColumn = new TreeViewerColumn(treeViewer, column); onlyViewerColumn.setLabelProvider(new BoldColumnLabelProvider()); @@ -580,6 +582,7 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e Object parent2 = provider.getParent(parent); ConstraintConfiguration config = ((ConstraintConfiguration)parent2); + final Display display = Display.getCurrent(); if(config.getName().equalsIgnoreCase(editedObject.getCurrentObjective().getName())) { for(ConstraintInstance instance : constraintInstances) { for(String constraintName : editedObject.getCurrentObjective() @@ -589,15 +592,15 @@ public class ConstraintBasedProcessEditor<CBP extends IConstraintBasedProcess> e IConstraintInstanceStatus status = IConstraintUIService.getInstance().getStatus(instance); if(status instanceof SuccessConstraintInstanceStatus) { - return Display.getCurrent().getSystemColor(SWT.COLOR_GREEN); + return display.getSystemColor(SWT.COLOR_GREEN); } else if(status instanceof FailedConstraintInstanceStatus) { - return Display.getCurrent().getSystemColor(SWT.COLOR_RED); + return display.getSystemColor(SWT.COLOR_RED); } } } } } - return Display.getCurrent().getSystemColor(SWT.COLOR_WHITE); + return display.getSystemColor(SWT.COLOR_WHITE); } /** diff --git a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditorHelper.java b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditorHelper.java index 9450763e8..651e909b9 100644 --- a/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditorHelper.java +++ b/org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/editor/ConstraintBasedProcessEditorHelper.java @@ -27,8 +27,8 @@ import org.eclipse.swt.widgets.Display; import org.fortiss.tooling.base.model.element.ConstraintConfiguration; import org.fortiss.tooling.kernel.extension.IConstraint; +// TODO Refactor together with ConstraintBasedProcessEditor and provide a dedicated perspective (see #3189) /** - * * This class is a helper class that provides, 1) the colors for the constraint groups, * 2) manage the references between the constraint configurations and * 3) manages the tree manipulation that is used to visualize the constraintsGroups, @@ -40,14 +40,15 @@ import org.fortiss.tooling.kernel.extension.IConstraint; public class ConstraintBasedProcessEditorHelper { /** Color Array for at least seven groups. */ - static int[] colorArray = {SWT.COLOR_DARK_GREEN, SWT.COLOR_DARK_BLUE, SWT.COLOR_DARK_YELLOW, - SWT.COLOR_BLACK, SWT.COLOR_DARK_RED, SWT.COLOR_GREEN, SWT.COLOR_CYAN}; + private static int[] colorArray = {SWT.COLOR_DARK_GREEN, SWT.COLOR_DARK_BLUE, + SWT.COLOR_DARK_YELLOW, SWT.COLOR_BLACK, SWT.COLOR_DARK_RED, SWT.COLOR_GREEN, + SWT.COLOR_CYAN}; /** Counter for the colorArray */ - public static int colorCtr = 0; + private static int colorCtr = 0; /** Reference to a constraint configuration. */ - public static class WithContextualConfiguration { + private static class WithContextualConfiguration { /** Contextual constraint configuration. */ ConstraintConfiguration config; @@ -62,7 +63,7 @@ public class ConstraintBasedProcessEditorHelper { public static class ConstraintWithContextualConfiguration extends WithContextualConfiguration { /** Constraint. */ - Class<? extends IConstraint> cstr; + /* package */Class<? extends IConstraint> cstr; /** Constructor. */ public ConstraintWithContextualConfiguration(Class<? extends IConstraint> cstr, @@ -80,7 +81,7 @@ public class ConstraintBasedProcessEditorHelper { WithContextualConfiguration { /** Constraint. */ - public ConstraintConfiguration target; + /* package */ConstraintConfiguration target; /** Constructor. */ public ConfigurationRefWithContextualConfiguration(ConstraintConfiguration configRef, @@ -120,10 +121,10 @@ public class ConstraintBasedProcessEditorHelper { public static class TreeStructureNode { /** Parent object variable. */ - public Object parent; + /* package */Object parent; /** Data object variable. */ - public Object data; + /* package */Object data; /** Constructor. */ public TreeStructureNode(Object parent, Object children) { @@ -160,7 +161,7 @@ public class ConstraintBasedProcessEditorHelper { public static class NormalFontStyler extends Styler { /** Counter to keep track of currently used color in color array. */ - public int colorIndex = 0; + private int colorIndex = 0; /** Constructor. */ public NormalFontStyler() { @@ -210,14 +211,7 @@ public class ConstraintBasedProcessEditorHelper { * is the size of the constraints groups */ public static void adjustColorIndex(int groupSize) { - int colorIndex = ConstraintBasedProcessEditorHelper.colorCtr; - - if(colorIndex != colorIndex - 1) { - if(groupSize == colorIndex + 1) { - ConstraintBasedProcessEditorHelper.colorCtr = 0; - } else { - ConstraintBasedProcessEditorHelper.colorCtr++; - } - } + colorCtr++; + colorCtr %= groupSize; } } -- GitLab