Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-01-26 09:16:46 +0000
committercletavernie2012-01-26 09:16:46 +0000
commit870f81ac1645fbf39bea85fb1c3c0d54306c047c (patch)
treedbf02a1897d4f2ea3ede24f7216c58224418ba67 /plugins/views
parentfaee939e0d1b98db7056004f8858844aaae8cbba (diff)
downloadorg.eclipse.papyrus-870f81ac1645fbf39bea85fb1c3c0d54306c047c.tar.gz
org.eclipse.papyrus-870f81ac1645fbf39bea85fb1c3c0d54306c047c.tar.xz
org.eclipse.papyrus-870f81ac1645fbf39bea85fb1c3c0d54306c047c.zip
351802: [Constraints] The Property View constraints model should be more generic
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351802
Diffstat (limited to 'plugins/views')
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/ConfigurationManager.java2
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/DefaultViewConstraintEngine.java145
-rw-r--r--plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/ViewConstraintEngineImpl.java50
3 files changed, 51 insertions, 146 deletions
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/ConfigurationManager.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/ConfigurationManager.java
index f12b4d02e38..6c7989a3bf3 100644
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/ConfigurationManager.java
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/ConfigurationManager.java
@@ -98,7 +98,7 @@ public class ConfigurationManager {
public final static ConfigurationManager instance = new ConfigurationManager();
private ConfigurationManager() {
- constraintEngine = new DefaultViewConstraintEngine();
+ constraintEngine = new ViewConstraintEngineImpl();
enabledContexts = new HashSet<Context>();
root = RootFactory.eINSTANCE.createPropertiesRoot();
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/DefaultViewConstraintEngine.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/DefaultViewConstraintEngine.java
deleted file mode 100644
index 372ebcf5f8a..00000000000
--- a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/DefaultViewConstraintEngine.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.views.properties.runtime;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
-import org.eclipse.papyrus.infra.constraints.constraints.Constraint;
-import org.eclipse.papyrus.infra.constraints.runtime.ConstraintFactory;
-import org.eclipse.papyrus.views.properties.contexts.Context;
-import org.eclipse.papyrus.views.properties.contexts.View;
-
-/**
- * The default implementation for ConstraintEngine
- *
- * @author Camille Letavernier
- */
-public class DefaultViewConstraintEngine implements ViewConstraintEngine {
-
- private final Set<Constraint> constraints = new LinkedHashSet<Constraint>();
-
- public void refresh() {
- constraints.clear();
- Collection<Context> contexts = ConfigurationManager.instance.getEnabledContexts();
- for(Context context : contexts) {
- addContext(context);
- }
- }
-
-
- public Set<View> getDisplayUnits(ISelection forSelection) {
- return getViews(forSelection);
- }
-
- public void addConstraint(ConstraintDescriptor descriptor) {
- Constraint constraint = ConstraintFactory.getInstance().createFromModel(descriptor);
- if(constraint != null) {
- constraints.add(constraint);
- }
- }
-
- public void addContext(final Context context) {
- for(View view : context.getViews()) {
- for(ConstraintDescriptor descriptor : view.getConstraints()) {
- addConstraint(descriptor);
- }
- }
- }
-
- public Set<View> getViews(final ISelection forSelection) {
- Set<View> result = new HashSet<View>();
-
- IStructuredSelection selection;
- if(forSelection instanceof IStructuredSelection) {
- selection = (IStructuredSelection)forSelection;
- } else {
- return result;
- }
-
- Set<Constraint> matchedConstraints = match(selection);
-
- return getViews(matchedConstraints);
- }
-
- private Set<Constraint> match(final IStructuredSelection selection) {
- Set<Constraint> matchedConstraints = new LinkedHashSet<Constraint>();
-
- if(selection.isEmpty()) {
- return matchedConstraints;
- }
-
- for(Constraint c : constraints) {
- if(c.match(selection)) {
- matchedConstraints.add(c);
- }
- }
-
- // System.out.println(selection);
-
- // String logValue;
- //
- // logValue = "Filtered Constraints : "; //$NON-NLS-1$
- // for(Constraint constraint : matchedConstraints) {
- // Context context = ((View)constraint.getDescriptor().getDisplay()).getContext();
- // logValue += context.getName() + "::" + constraint.getDescriptor().getName() + ", ";
- // }
- // Activator.log.warn(logValue);
-
- resolveConstraintConflicts(matchedConstraints);
-
- // logValue = "Filtered Constraints : "; //$NON-NLS-1$
- // for(Constraint constraint : matchedConstraints) {
- // Context context = ((View)constraint.getDescriptor().getDisplay()).getContext();
- // logValue += context.getName() + "::" + constraint.getDescriptor().getName() + ", ";
- // }
- // Activator.log.warn(logValue);
-
-
-
- return matchedConstraints;
- }
-
- private void resolveConstraintConflicts(final Set<Constraint> matchedConstraints) {
- Set<Constraint> constraintsSet = new HashSet<Constraint>(matchedConstraints);
- for(Constraint c : constraintsSet) {
- for(Constraint c2 : constraintsSet) {
- if(c == c2) {
- continue;
- }
-
- if(c.getDescriptor().getOverriddenConstraints().contains(c2.getDescriptor())) {
- matchedConstraints.remove(c2);
- continue;
- }
-
- if(c2.getDescriptor().isOverrideable() && c.overrides(c2)) {
- matchedConstraints.remove(c2);
- continue;
- }
- }
- }
- }
-
- private Set<View> getViews(final Set<Constraint> matchedConstraints) {
- Set<View> views = new LinkedHashSet<View>();
- for(Constraint c : matchedConstraints) {
- views.add((View)c.getDisplayUnit());
- }
- return views;
- }
-}
diff --git a/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/ViewConstraintEngineImpl.java b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/ViewConstraintEngineImpl.java
new file mode 100644
index 00000000000..0da14628b8f
--- /dev/null
+++ b/plugins/views/properties/org.eclipse.papyrus.views.properties/src/org/eclipse/papyrus/views/properties/runtime/ViewConstraintEngineImpl.java
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.views.properties.runtime;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
+import org.eclipse.papyrus.infra.constraints.runtime.DefaultConstraintEngine;
+import org.eclipse.papyrus.views.properties.contexts.Context;
+import org.eclipse.papyrus.views.properties.contexts.View;
+
+/**
+ * The implementation for ViewConstraintEngine
+ *
+ * @author Camille Letavernier
+ */
+public class ViewConstraintEngineImpl extends DefaultConstraintEngine<View> implements ViewConstraintEngine {
+
+ @Override
+ public void refresh() {
+ constraints.clear();
+ Collection<Context> contexts = ConfigurationManager.instance.getEnabledContexts();
+ for(Context context : contexts) {
+ addContext(context);
+ }
+ }
+
+ public void addContext(final Context context) {
+ for(View view : context.getViews()) {
+ for(ConstraintDescriptor descriptor : view.getConstraints()) {
+ addConstraint(descriptor);
+ }
+ }
+ }
+
+ public Set<View> getViews(final ISelection forSelection) {
+ return getDisplayUnits(forSelection);
+ }
+}

Back to the top