diff options
author | cletavernie | 2012-02-02 09:19:17 +0000 |
---|---|---|
committer | cletavernie | 2012-02-02 09:19:17 +0000 |
commit | 73ab7f2bd884aaa7c2c51b43dba16e31f5f8f8c1 (patch) | |
tree | 86bad34ecd8a26d620b473bdb404f017e5deb8fd | |
parent | 64e8562685f47c54173e54920986420e0762cefe (diff) | |
download | org.eclipse.papyrus-73ab7f2bd884aaa7c2c51b43dba16e31f5f8f8c1.tar.gz org.eclipse.papyrus-73ab7f2bd884aaa7c2c51b43dba16e31f5f8f8c1.tar.xz org.eclipse.papyrus-73ab7f2bd884aaa7c2c51b43dba16e31f5f8f8c1.zip |
365281: [Property view] The constraints should be able to handle a global selection
https://bugs.eclipse.org/bugs/show_bug.cgi?id=365281
4 files changed, 26 insertions, 33 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AbstractConstraint.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AbstractConstraint.java index 10a29f39841..47d6eb6a0e1 100644 --- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AbstractConstraint.java +++ b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AbstractConstraint.java @@ -216,4 +216,14 @@ public abstract class AbstractConstraint implements Constraint { return false;
}
+ /**
+ * Tests if this constraint matches the given object
+ *
+ * @param selection
+ * The object to be tested against this constraint
+ * @return
+ * True if this constraint matches the given object
+ */
+ protected abstract boolean match(Object selection);
+
}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/CompoundConstraint.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/CompoundConstraint.java index 0673f809168..d3f4ed344a4 100644 --- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/CompoundConstraint.java +++ b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/CompoundConstraint.java @@ -14,6 +14,8 @@ package org.eclipse.papyrus.infra.constraints.constraints; import java.util.LinkedList;
import java.util.List;
+import org.eclipse.jface.viewers.IStructuredSelection;
+
/**
* A Composite constraint. It matches a given selection if and only if
* all its sub constraints match this selection.
@@ -39,7 +41,8 @@ public class CompoundConstraint extends AbstractConstraint { * A Composite Constraints matches a selection if and only if
* all its inner constraints match it
*/
- public boolean match(Object selection) {
+ @Override
+ public boolean match(IStructuredSelection selection) {
for(Constraint constraint : constraints) {
if(!constraint.match(selection)) {
return false;
@@ -49,6 +52,12 @@ public class CompoundConstraint extends AbstractConstraint { }
@Override
+ protected boolean match(Object selection) {
+ //Unused: we override AbstractConstraint#match(IStructuredSelection)
+ return false;
+ }
+
+ @Override
public boolean overrides(Constraint constraint) {
if(constraints.size() == 0) {
return false;
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/Constraint.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/Constraint.java index 11c5a18fcc1..f5d3de6619c 100644 --- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/Constraint.java +++ b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/Constraint.java @@ -35,16 +35,6 @@ public interface Constraint { public void setConstraintDescriptor(ConstraintDescriptor descriptor);
/**
- * Tests if this constraint matches the given object
- *
- * @param selection
- * The object to be tested against this constraint
- * @return
- * True if this constraint matches the given object
- */
- public boolean match(Object selection);
-
- /**
* Tests if this constraint matches the given selection
*
* @param selection
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/DefaultConstraintEngine.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/DefaultConstraintEngine.java index 9edbb8a8e13..e8f05ca9df0 100644 --- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/DefaultConstraintEngine.java +++ b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/DefaultConstraintEngine.java @@ -12,7 +12,6 @@ package org.eclipse.papyrus.infra.constraints.runtime;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -58,28 +57,13 @@ public abstract class DefaultConstraintEngine<E extends DisplayUnit> implements private Set<Constraint> match(final IStructuredSelection selection) {
Set<Constraint> matchedConstraints = new LinkedHashSet<Constraint>();
+ if(selection.isEmpty()) {
+ return matchedConstraints;
+ }
+
for(Constraint c : constraints) {
- int elementMultiplicity = c.getDescriptor().getDisplay().getElementMultiplicity();
- int selectionSize = selection.size();
- if(elementMultiplicity == 1) {
- if(selectionSize == 1) {
- if(c.match(selection.getFirstElement())) {
- matchedConstraints.add(c);
- }
- }
- } else if(elementMultiplicity == selectionSize || elementMultiplicity < 0) {
- boolean allMatch = true;
- Iterator<?> selectionIterator = selection.iterator();
- while(selectionIterator.hasNext()) {
- Object selectedItem = selectionIterator.next();
- if(!c.match(selectedItem)) {
- allMatch = false;
- break;
- }
- }
- if(allMatch) {
- matchedConstraints.add(c);
- }
+ if(c.match(selection)) {
+ matchedConstraints.add(c);
}
}
|