Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra')
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/Activator.java66
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AbstractConstraint.java268
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AttachedToResourceConstraint.java56
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/CompoundConstraint.java120
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/Constraint.java76
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/EMFInstanceOfConstraint.java117
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/EMFQueryConstraint.java83
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/HasEAnnotationConstraint.java55
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaInstanceOf.java46
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaQuery.java39
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaQueryConstraint.java63
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/TrueConstraint.java32
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintEngine.java61
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintEngineListener.java30
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintFactory.java91
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintsChangedEvent.java43
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintsManager.java113
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/DefaultConstraintEngine.java226
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/util/ClassLoader.java84
19 files changed, 0 insertions, 1669 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/Activator.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/Activator.java
deleted file mode 100644
index 99012a4c38e..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/Activator.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011, 2016 CEA LIST, Christian W. Damus, and others.
- *
- * 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
- * Christian W. Damus - bug 485220
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.constraints;
-
-import org.eclipse.core.runtime.Plugin;
-import org.eclipse.papyrus.infra.core.log.LogHelper;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends Plugin {
-
- /**
- * The plug-in ID
- */
- public static final String PLUGIN_ID = "org.eclipse.papyrus.infra.constraints"; //$NON-NLS-1$
-
- // The shared instance
- private static Activator plugin;
-
- /**
- * The plug-in's logger
- */
- public static LogHelper log;
-
- /**
- * The constructor
- */
- public Activator() {
- }
-
- @Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- log = new LogHelper(this);
- }
-
- @Override
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
-}
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
deleted file mode 100644
index 4578330de51..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AbstractConstraint.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2016 CEA LIST, Christian W. Damus, and others.
- *
- * 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
- * Christian W. Damus - bug 485220
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.constraints.constraints;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.papyrus.infra.constraints.Activator;
-import org.eclipse.papyrus.infra.constraints.ConfigProperty;
-import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
-import org.eclipse.papyrus.infra.constraints.DisplayUnit;
-import org.eclipse.papyrus.infra.constraints.ReferenceProperty;
-import org.eclipse.papyrus.infra.constraints.SimpleConstraint;
-import org.eclipse.papyrus.infra.constraints.ValueProperty;
-
-/**
- * An abstract implementation for the Constraint interface.
- *
- * @author Camille Letavernier
- *
- */
-public abstract class AbstractConstraint implements Constraint {
-
- /**
- * The descriptor used to instantiate this constraint.
- * Contains some attributes for this constraint
- */
- protected ConstraintDescriptor descriptor;
-
- /**
- * The display unit (Section or View) associated to this constraint
- */
- protected DisplayUnit display;
-
- @Override
- public final void setConstraintDescriptor(ConstraintDescriptor descriptor) {
- this.descriptor = descriptor;
- display = getDisplay(descriptor);
- if (descriptor instanceof SimpleConstraint) {
- setDescriptor((SimpleConstraint) descriptor);
- }
- }
-
- private DisplayUnit getDisplay(ConstraintDescriptor descriptor) {
- if (descriptor.getDisplay() == null) {
- if (descriptor.eContainer() instanceof ConstraintDescriptor) {
- return getDisplay((ConstraintDescriptor) descriptor.eContainer());
- }
- }
- return descriptor.getDisplay();
- }
-
- @Override
- public DisplayUnit getDisplayUnit() {
- return display;
- }
-
- /**
- * A constraint for a Single element (Exactly one) overrides
- * the same constraint for a multiple element (One or more)
- */
- @Override
- public boolean overrides(Constraint constraint) {
- if (equivalent(constraint)) {
- if (getDisplayUnit().getElementMultiplicity() == 1) {
- if (constraint.getDisplayUnit().getElementMultiplicity() != 1) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /**
- * Tests if two constraints are equivalent.
- * Two constraints are equivalent if they have the same parameters.
- * Two equivalent constraints may have different Display units, with
- * different multiplicities.
- *
- * @param constraint
- * @return
- * True if this object is equivalent to the given constraint
- */
- protected abstract boolean equivalent(Constraint constraint);
-
- @Override
- public ConstraintDescriptor getDescriptor() {
- return descriptor;
- }
-
- /**
- * Returns the ConfigProperty corresponding to the given propertyName
- *
- * @param propertyName
- * The name of the property to retrieve
- * @return
- * The ConfigProperty corresponding to the given propertyName
- */
- protected ConfigProperty getProperty(String propertyName) {
- if (descriptor == null || !(descriptor instanceof SimpleConstraint)) {
- Activator.log.warn("The constraint descriptor has not been set for this constraint : " + this); //$NON-NLS-1$
- } else {
- for (ConfigProperty property : ((SimpleConstraint) descriptor).getProperties()) {
- if (property.getName().equals(propertyName)) {
- return property;
- }
- }
- }
-
- Activator.log.warn("The property " + propertyName + " has not been set for constraint " + descriptor.getName()); //$NON-NLS-1$ //$NON-NLS-2$
-
- return null;
- }
-
- /**
- * Tests whether a value is available for the requested property
- *
- * @param propertyName
- * @return
- * True if the property exists in the constraint descriptor
- */
- protected boolean hasProperty(String propertyName) {
- if (descriptor == null || !(descriptor instanceof SimpleConstraint)) {
- Activator.log.warn("The constraint descriptor has not been set for this constraint : " + this); //$NON-NLS-1$
- } else {
- for (ConfigProperty property : ((SimpleConstraint) descriptor).getProperties()) {
- if (property.getName().equals(propertyName)) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- /**
- * Returns the value associated to the given property
- *
- * @param propertyName
- * The name of the property for which we want to retrieve the value
- * The name must correspond to a valid ValueProperty
- * @return
- * The value associated to the given property
- *
- * @see #getReferenceValue(String)
- */
- protected String getValue(String propertyName) {
- ConfigProperty property = getProperty(propertyName);
-
- if (property instanceof ValueProperty) {
- return ((ValueProperty) property).getValue();
- }
-
- Activator.log.warn("The property " + propertyName + " is not a ValueProperty (Constraint " + descriptor.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- return null;
- }
-
- /**
- * Returns the value associated to the given property
- *
- * @param propertyName
- * The name of the property for which we want to retrieve the value
- * The name must correspond to a valid ReferenceProperty
- * @return
- * The value associated to the given property
- *
- * @see #getValue(String)
- */
- protected Object getReferenceValue(String propertyName) {
- ConfigProperty property = getProperty(propertyName);
- if (property instanceof ReferenceProperty) {
- return ((ReferenceProperty) property).getValue();
- }
-
- Activator.log.warn("The property " + propertyName + " is not a ReferenceProperty (Constraint " + descriptor.getName() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- return null;
- }
-
- /**
- * Sets the Constraint Descriptor for this constraint.
- * The constraint descriptor may contain some parameters to configure this
- * constraint.
- * Implementors may override.
- *
- * @param descriptor
- * The constraint descriptor to be associated to this constraint
- *
- * @see #setConstraintDescriptor(ConstraintDescriptor)
- */
- protected void setDescriptor(SimpleConstraint descriptor) {
- // Implementors may override
- }
-
- /**
- * {@inheritDoc}
- *
- * The default implementation matches a selection iff the constraint matches
- * each object of the selection.
- */
- @Override
- public boolean match(Collection<?> selection) {
- if (selection.isEmpty()) {
- return false;
- }
-
-
- int elementMultiplicity;
-
- elementMultiplicity = display.getElementMultiplicity();
-
- int selectionSize = selection.size();
- if (elementMultiplicity == 1) {
- if (selectionSize == 1) {
- if (match(first(selection))) {
- return true;
- }
- }
- } else if (elementMultiplicity == selectionSize || elementMultiplicity < 0) {
- Iterator<?> selectionIterator = selection.iterator();
- while (selectionIterator.hasNext()) {
- Object selectedItem = selectionIterator.next();
- if (!match(selectedItem)) {
- return false;
- }
- }
-
- return true;
- }
-
- return false;
- }
-
- protected Object first(Collection<?> collection) {
- return (collection instanceof List<?>)
- ? ((List<?>) collection).get(0)
- : collection.iterator().next();
- }
-
- /**
- * Tests if this constraint matches the given object
- * This methods only needs to be implemented when you don't
- * override {@link AbstractConstraint#match(IStructuredSelection)}
- *
- * @param selection
- * The object to be tested against this constraint
- * @return
- * True if this constraint matches the given object
- *
- * @see {@link #match(IStructuredSelection)}
- */
- protected abstract boolean match(Object selection);
-
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AttachedToResourceConstraint.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AttachedToResourceConstraint.java
deleted file mode 100644
index 5859aac77fd..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/AttachedToResourceConstraint.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST and others.
- *
- * 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.constraints.constraints;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-
-/**
- * A properties view constraint that matches objects that are attached to some resource.
- */
-public class AttachedToResourceConstraint extends AbstractConstraint {
-
- /**
- * Initializes me.
- */
- public AttachedToResourceConstraint() {
- super();
- }
-
- @Override
- protected boolean match(Object selection) {
- boolean result = false;
-
- EObject object = EMFHelper.getEObject(selection);
-
- if (object != null) {
- result = object.eResource() != null;
- }
-
- return result;
- }
-
- @Override
- protected boolean equivalent(Constraint constraint) {
- if (this == constraint) {
- return true;
- }
- return constraint instanceof AttachedToResourceConstraint;
- }
-
- @Override
- public String toString() {
- return "AttachedToResourceConstraint"; //$NON-NLS-1$
- }
-}
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
deleted file mode 100644
index 7ffe3b2024a..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/CompoundConstraint.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2016 CEA LIST, Christian W. Damus, and others.
- *
- * 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
- * Christian W. Damus - bug 485220
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.constraints.constraints;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-
-/**
- * A Composite constraint. It matches a given selection if and only if
- * all its sub constraints match this selection.
- *
- * @author Camille Letavernier
- */
-public class CompoundConstraint extends AbstractConstraint {
-
- /**
- * Adds a sub-constraint to this constraint
- *
- * @param subConstraint
- * The sub-constraint to be added
- */
- public void addConstraint(Constraint subConstraint) {
- if (subConstraint == null) {
- throw new IllegalArgumentException("The subConstraint shall not be null");
- }
- constraints.add(subConstraint);
- }
-
- /**
- * A Composite Constraints matches a selection if and only if
- * all its inner constraints match it
- */
- @Override
- public boolean match(Collection<?> selection) {
- for (Constraint constraint : constraints) {
- if (!constraint.match(selection)) {
- return false;
- }
- }
- return true;
- }
-
- @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;
- }
-
- if (constraints.size() == 1) {
- return constraints.get(0).overrides(constraint);
- }
-
- // A Composite overrides another Composite if at least one sub-constraint overrides another one,
- // and each sub-constraint is at least equal to another one
- if (constraint instanceof CompoundConstraint) {
- boolean atLeastOneOverride = false;
- for (Constraint subConstraint : constraints) {
- boolean equalsOrOverride = false;
- for (Constraint otherSubConstraint : ((CompoundConstraint) constraint).constraints) {
- if (subConstraint.overrides(otherSubConstraint)) {
- atLeastOneOverride = true;
- break;
- }
- if (subConstraint.equals(otherSubConstraint)) {
- equalsOrOverride = true;
- }
- }
-
- if (!equalsOrOverride) {
- return false;
- }
- }
-
- if (atLeastOneOverride) {
- return true;
- }
- } else { // At least one of our constraints must override or be equal to the other constraint
- for (Constraint c : constraints) {
- if (c.overrides(constraint) || c.equals(constraint)) {
- // TODO : The equals() method is not defined for most constraint implementations.
- // We may actually need an "isEquivalent" method, defined in the Constraint Interface
- return true;
- }
- }
- }
-
- return false;
- }
-
- @Override
- public String toString() {
- return constraints.toString();
- }
-
- private List<Constraint> constraints = new LinkedList<Constraint>();
-
- @Override
- protected boolean equivalent(Constraint constraint) {
- 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
deleted file mode 100644
index b33919d3065..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/Constraint.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2016 CEA LIST, Christian W. Damus, and others.
- *
- * 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
- * Christian W. Damus - bug 485220
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.constraints.constraints;
-
-import java.util.Collection;
-
-import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
-import org.eclipse.papyrus.infra.constraints.DisplayUnit;
-
-/**
- * An interface representing a Constraint. A Constraint is used to test if a selection
- * is matching a pre-configured property view.
- *
- * @author Camille Letavernier
- *
- */
-public interface Constraint {
-
- /**
- * Sets the Constraint Descriptor for this constraint.
- * The constraint descriptor may contain some parameters to configure this
- * constraint
- *
- * @param descriptor
- * The constraint descriptor to be associated to this constraint
- */
- public void setConstraintDescriptor(ConstraintDescriptor descriptor);
-
- /**
- * Tests if this constraint matches the given selection
- *
- * @param selection
- * The selection to be tested against this constraint
- * @return
- * True if this constraint matches the given selection
- */
- public boolean match(Collection<?> selection);
-
- /**
- * Returns the view associated to this constraint, or null if the constraint is associated to another
- * kind of display unit (e.g. a section)
- *
- * @return
- * The view associated to this constraint
- */
- public DisplayUnit getDisplayUnit();
-
- /**
- * Tests if this constraint should override the given constraint. If true,
- * the other constraint's display unit won't be displayed. A constraint should
- * never override itself, and you should ensure that there are no loops in the
- * constraint overriding graph. If such a loops occurs, nothing will be displayed
- *
- * @param constraint
- * The tested constraint
- * @return
- * True if this constraint overrides the given constraint
- */
- public boolean overrides(Constraint constraint);
-
- /**
- * @return the constraint descriptor associated to this constraint
- */
- public ConstraintDescriptor getDescriptor();
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/EMFInstanceOfConstraint.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/EMFInstanceOfConstraint.java
deleted file mode 100644
index 1f83c5e1f16..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/EMFInstanceOfConstraint.java
+++ /dev/null
@@ -1,117 +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.infra.constraints.constraints;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.papyrus.infra.constraints.Activator;
-import org.eclipse.papyrus.infra.constraints.SimpleConstraint;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-
-/**
- * A constraint testing if a Selection is an EObject, instance of the given
- * EClass. The EClass is identified by its nsURI and name.
- *
- * @author Camille Letavernier
- *
- */
-public class EMFInstanceOfConstraint extends AbstractConstraint {
-
- private String className;
-
- private String nsUri;
-
- private EPackage metamodel;
-
- @Override
- protected void setDescriptor(SimpleConstraint descriptor) {
- className = getValue("className"); //$NON-NLS-1$
- nsUri = getValue("nsUri"); //$NON-NLS-1$
- metamodel = EPackage.Registry.INSTANCE.getEPackage(nsUri);
- if (metamodel == null) {
- Activator.log.warn("Metamodel with nsUri " + nsUri + " not found"); //$NON-NLS-1$ //$NON-NLS-2$
- }
- }
-
- /**
- * A class constraint overrides its superclass constraints
- * e.g. : instanceOf(Class) overrides instanceOf(Classifier)
- */
- @Override
- public boolean overrides(Constraint otherConstraint) {
- if (!(otherConstraint instanceof EMFInstanceOfConstraint)) {
- return false;
- }
-
- EMFInstanceOfConstraint constraint = (EMFInstanceOfConstraint) otherConstraint;
- EClass thisClass = EMFHelper.getEClass(nsUri, className);
- EClass otherClass = EMFHelper.getEClass(constraint.nsUri, constraint.className);
- boolean result = (!equals(constraint)) && EMFHelper.isSubclass(thisClass, otherClass) && thisClass != otherClass;
-
- return result || super.overrides(constraint);
- }
-
- @Override
- public boolean match(Object selection) {
- if (className == null || nsUri == null) {
- return false;
- }
-
- EObject selectedItem = EMFHelper.getEObject(selection);
-
- if (selectedItem != null) {
- if (metamodel == null) { // This may be a dynamic, local (non-registered) EPackage
- return EMFHelper.isInstance(selectedItem, className, nsUri);
- } else {
- return EMFHelper.isInstance(selectedItem, className, metamodel);
- }
- }
-
- return false;
- }
-
- @Override
- public String toString() {
- return "EMFInstanceOfConstraint (" + nsUri + "/" + className + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Override
- protected boolean equivalent(Constraint constraint) {
- if (this == constraint) {
- return true;
- }
- if (constraint == null) {
- return false;
- }
- if (!(constraint instanceof EMFInstanceOfConstraint)) {
- return false;
- }
- EMFInstanceOfConstraint other = (EMFInstanceOfConstraint) constraint;
- if (className == null) {
- if (other.className != null) {
- return false;
- }
- } else if (!className.equals(other.className)) {
- return false;
- }
- if (nsUri == null) {
- if (other.nsUri != null) {
- return false;
- }
- } else if (!nsUri.equals(other.nsUri)) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/EMFQueryConstraint.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/EMFQueryConstraint.java
deleted file mode 100644
index 9cbcdf097a3..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/EMFQueryConstraint.java
+++ /dev/null
@@ -1,83 +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.infra.constraints.constraints;
-
-
-/**
- * A constraint applying an EMF Query on a selection. The Query should return
- * a Boolean.
- *
- * @author Camille Letavernier
- */
-public class EMFQueryConstraint extends AbstractConstraint {
-
- @Override
- protected boolean equivalent(Constraint constraint) {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- protected boolean match(Object selection) {
- // TODO Auto-generated method stub
- return false;
- }
-
- // private OCLModelQuery query;
- //
- // @Override
- // protected void setDescriptor(SimpleConstraint descriptor) {
- // ConfigProperty property = getProperty("query"); //$NON-NLS-1$
- // if(property instanceof ReferenceProperty) {
- // query = (OCLModelQuery)getReferenceValue("query"); //$NON-NLS-1$
- // } else {
- // String queryExpression = ((ValueProperty)property).getValue();
- // query = QueryFactory.eINSTANCE.createOCLModelQuery();
- // query.setQuery(queryExpression);
- // query.setReturnType(EcorePackage.eINSTANCE.getEBoolean());
- // query.getScope().add(EcorePackage.eINSTANCE.getEObject());
- // throw new UnsupportedOperationException();
- // }
- // }
- //
- // public boolean match(Object selection) {
- // if(query == null) {
- // return false;
- // }
- //
- // EObject selectedItem = EMFHelper.getEObject(selection);
- //
- // if(selectedItem != null) {
- // try {
- // ModelQuerySetCatalog catalog = ModelQuerySetCatalog.getSingleton();
- // AbstractModelQuery abstractQuery = catalog.getModelQueryImpl(query);
- // ModelQueryResult result = abstractQuery.evaluate(selectedItem);
- // Object value = result.getValue();
- // return value == null ? false : (Boolean)value;
- // } catch (Exception ex) {
- // Activator.log.error(ex);
- // }
- //
- // }
- // return false;
- // }
- //
- // @Override
- // protected boolean equivalent(Constraint constraint) {
- // if(constraint != null && constraint instanceof EMFQueryConstraint) {
- // EMFQueryConstraint other = (EMFQueryConstraint)constraint;
- // return other.query.equals(query);
- // }
- // return false;
- // }
-
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/HasEAnnotationConstraint.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/HasEAnnotationConstraint.java
deleted file mode 100644
index 1fc5cdb74d5..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/HasEAnnotationConstraint.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2013 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.infra.constraints.constraints;
-
-import org.eclipse.emf.ecore.EModelElement;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.constraints.SimpleConstraint;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-
-/**
- * A Constraint to test whether the selected EObject has a specific EAnnotation
- *
- * @author Camille Letavernier
- *
- */
-public class HasEAnnotationConstraint extends AbstractConstraint {
-
- protected String annotationName;
-
- @Override
- protected boolean equivalent(Constraint constraint) {
- if (constraint instanceof HasEAnnotationConstraint) {
- HasEAnnotationConstraint other = (HasEAnnotationConstraint) constraint;
- return annotationName.equals(other.annotationName);
- }
- return false;
- }
-
- @Override
- protected void setDescriptor(SimpleConstraint descriptor) {
- super.setDescriptor(descriptor);
- this.annotationName = getValue("annotationName");
- }
-
- @Override
- protected boolean match(Object selection) {
- EObject eObject = EMFHelper.getEObject(selection);
- if (eObject instanceof EModelElement) {
- EModelElement modelElement = (EModelElement) eObject;
- return modelElement.getEAnnotation(annotationName) != null;
- }
-
- return false;
- }
-
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaInstanceOf.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaInstanceOf.java
deleted file mode 100644
index e2f8bfc998d..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaInstanceOf.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 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.infra.constraints.constraints;
-
-import org.eclipse.papyrus.infra.constraints.SimpleConstraint;
-import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
-
-/**
- * A Constraint to test if an object is an instance of a given
- * Java class
- *
- * @author Camille Letavernier
- */
-public class JavaInstanceOf extends AbstractConstraint {
-
- private Class<?> clazz;
-
- @Override
- public void setDescriptor(SimpleConstraint descriptor) {
- clazz = ClassLoaderHelper.loadClass(getValue("class")); //$NON-NLS-1$
- }
-
- @Override
- public boolean match(Object selection) {
- if (clazz == null) {
- return false;
- }
-
- return clazz.isInstance(selection);
- }
-
- @Override
- protected boolean equivalent(Constraint constraint) {
- return false; // TODO
- }
-
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaQuery.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaQuery.java
deleted file mode 100644
index 7cb1e3de6b7..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaQuery.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2012 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.infra.constraints.constraints;
-
-/**
- * Represents a Java Query
- */
-public interface JavaQuery {
-
- /**
- * Tests whether the query matches a given object
- *
- * @param selection
- * @return
- */
- public boolean match(Object selection);
-
- /**
- * A Java query which is always false
- *
- * @author Camille Letavernier
- *
- */
- public class FalseQuery implements JavaQuery {
-
- public boolean match(Object selection) {
- return false;
- }
- }
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaQueryConstraint.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaQueryConstraint.java
deleted file mode 100644
index dfcbb0a57c6..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/JavaQueryConstraint.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2014 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- /*****************************************************************************/
-package org.eclipse.papyrus.infra.constraints.constraints;
-
-import org.eclipse.papyrus.infra.constraints.Activator;
-import org.eclipse.papyrus.infra.constraints.SimpleConstraint;
-import org.eclipse.papyrus.infra.constraints.constraints.JavaQuery.FalseQuery;
-import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
-
-/**
- * This constraint allows to define a Java Query (without parameters) without
- * defining it in an environment file.
- *
- * The constraint takes one parameter ("className"), which defines the
- * qualified name of the Java class used to implement the constraint.
- *
- * The Java class must implement the {@link JavaQuery} interface
- *
- * @author Camille Letavernier
- */
-public class JavaQueryConstraint extends AbstractConstraint {
-
- /**
- * The Java Class property
- */
- public final static String QUERY_CLASS_NAME_PROPERTY = "className"; //$NON-NLS-1$
-
- private JavaQuery query = new FalseQuery();
-
- @Override
- protected void setDescriptor(SimpleConstraint descriptor) {
- String queryClassName = getValue(QUERY_CLASS_NAME_PROPERTY);
- query = ClassLoaderHelper.newInstance(queryClassName, JavaQuery.class);
- if (query == null) {
- Activator.log.warn("Cannot load the JavaQuery for this constraint : " + descriptor.getName());
- }
- }
-
- @Override
- public boolean match(Object selection) {
- return query.match(selection);
- }
-
- @Override
- protected boolean equivalent(Constraint constraint) {
- if (constraint instanceof JavaQueryConstraint) {
- return ((JavaQueryConstraint) constraint).query.getClass().equals(query.getClass());
- }
- return false;
- }
-
-
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/TrueConstraint.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/TrueConstraint.java
deleted file mode 100644
index 2ff3e337236..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/constraints/TrueConstraint.java
+++ /dev/null
@@ -1,32 +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.infra.constraints.constraints;
-
-/**
- * A Constraint always returning true.
- *
- * @author Camille Letavernier
- */
-public class TrueConstraint extends AbstractConstraint {
-
- @Override
- public boolean match(Object selection) {
- return true;
- }
-
- @Override
- protected boolean equivalent(Constraint constraint) {
- // return constraint != null && constraint instanceof TrueConstraint;
- return false; // TrueConstraint is always true ; it shouldn't override another "always true" constraint
- }
-
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintEngine.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintEngine.java
deleted file mode 100644
index 2db2ad3dc2e..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintEngine.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2014 CEA LIST and others.
- *
- * 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
- * Christian W. Damus (CEA) - bug 417409
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.constraints.runtime;
-
-import java.util.Collection;
-import java.util.Set;
-
-import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
-import org.eclipse.papyrus.infra.constraints.DisplayUnit;
-
-/**
- * An interface representing a Constraint Engine.
- * The Constraint Engine is responsible for retrieving the DisplayUnits
- * to display for a given ISelection.
- *
- * @author Camille Letavernier
- * @param <E>
- * The type of DisplayUnit managed by this Constraint Engine
- */
-public interface ConstraintEngine<E extends DisplayUnit> {
-
- /**
- * Returns the DisplayUnits matching the given selection
- *
- * @param a
- * plastic "selection" of objects, which may be a {@link Collection} of
- * some kind, something convertible to a collection (like a JFace {@code IStructuredSelection}),
- * or just a single object
- *
- * @return the display units applicable to the selection
- */
- public Set<E> getDisplayUnits(Object selection);
-
- /**
- * Adds a constraint descriptor to this engine
- *
- * @param descriptor
- */
- public void addConstraint(ConstraintDescriptor descriptor);
-
- /**
- * Indicate that the available constraints might have changed
- * Refreshes the Constraint Engine
- */
- public void refresh();
-
- void addConstraintEngineListener(ConstraintEngineListener listener);
-
- void removeConstraintEngineListener(ConstraintEngineListener listener);
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintEngineListener.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintEngineListener.java
deleted file mode 100644
index 208b50e409f..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintEngineListener.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2014 CEA and others.
- *
- * 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:
- * Christian W. Damus (CEA) - Initial API and implementation
- *
- */
-package org.eclipse.papyrus.infra.constraints.runtime;
-
-import java.util.EventListener;
-
-
-/**
- * Protocol for notifications of changes in the constraint listener that may affect its clients.
- */
-public interface ConstraintEngineListener extends EventListener {
-
- /**
- * Notifies listeners that the engine's constraints have changed, so any remembered calculation results may need to be recomputed.
- *
- * @param event
- * the notification object
- */
- void constraintsChanged(ConstraintsChangedEvent event);
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintFactory.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintFactory.java
deleted file mode 100644
index 76552abbb34..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintFactory.java
+++ /dev/null
@@ -1,91 +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.infra.constraints.runtime;
-
-import org.eclipse.papyrus.infra.constraints.Activator;
-import org.eclipse.papyrus.infra.constraints.CompositeConstraint;
-import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
-import org.eclipse.papyrus.infra.constraints.SimpleConstraint;
-import org.eclipse.papyrus.infra.constraints.constraints.CompoundConstraint;
-import org.eclipse.papyrus.infra.constraints.constraints.Constraint;
-import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
-
-
-/**
- * A Singleton class for creating {@link Constraint}s from a {@link ConstraintDescriptor}
- *
- * @author Camille Letavernier
- */
-public class ConstraintFactory {
-
- private ConstraintFactory() {
-
- }
-
- /**
- * @return the singleton instance
- */
- public static ConstraintFactory getInstance() {
- return instance;
- }
-
- /**
- * Creates a new Constraint from the given ConstraintDescriptor
- *
- * @param model
- * The ConstraintDescriptor describing the Constraint
- * @return
- * The new constraint instance
- */
- public Constraint createFromModel(ConstraintDescriptor model) {
- Constraint constraint = null;
- if (model instanceof CompositeConstraint) {
- CompoundConstraint cConstraint = new CompoundConstraint();
- cConstraint.setConstraintDescriptor(model);
- for (SimpleConstraint descriptor : ((CompositeConstraint) model).getConstraints()) {
- Constraint subConstraint = loadConstraint(descriptor);
-
- // One of the subConstraint is invalid : we stop building the constraint
- if (subConstraint == null) {
- Activator.log.warn("Cannot load constraint " + model.getName()); //$NON-NLS-1$
- return null;
- }
-
- cConstraint.addConstraint(subConstraint);
- }
-
- constraint = cConstraint;
- } else {
- constraint = loadConstraint((SimpleConstraint) model);
- }
- return constraint;
- }
-
- private Constraint loadConstraint(SimpleConstraint model) {
- Constraint constraint = null;
-
- if (model.getConstraintType() != null) {
- String className = model.getConstraintType().getConstraintClass();
- constraint = ClassLoaderHelper.newInstance(className, Constraint.class);
- }
-
- if (constraint == null) {
- Activator.log.warn("Cannot load constraint " + model.getName()); //$NON-NLS-1$
- return null;
- }
-
- constraint.setConstraintDescriptor(model);
- return constraint;
- }
-
- private static ConstraintFactory instance = new ConstraintFactory();
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintsChangedEvent.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintsChangedEvent.java
deleted file mode 100644
index c6d7776db3b..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintsChangedEvent.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2014 CEA and others.
- *
- * 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:
- * Christian W. Damus (CEA) - Initial API and implementation
- *
- */
-package org.eclipse.papyrus.infra.constraints.runtime;
-
-import java.util.EventObject;
-
-
-/**
- * Notification object for the {@linkplain ConstraintEngineListener#constraintsChanged(ConstraintsChangedEvent) constraints-changed event}.
- */
-public class ConstraintsChangedEvent extends EventObject {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Initializes me with my originating constraint engine.
- *
- * @param source
- * my source
- */
- public ConstraintsChangedEvent(ConstraintEngine<?> source) {
- super(source);
- }
-
- /**
- * Queries the constraint engine that generated this event.
- *
- * @return the source constraint engine
- */
- public ConstraintEngine<?> getConstraintEngine() {
- return (ConstraintEngine<?>) getSource();
- }
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintsManager.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintsManager.java
deleted file mode 100644
index 3818f7dd270..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/ConstraintsManager.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 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.infra.constraints.runtime;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.papyrus.infra.constraints.Activator;
-import org.eclipse.papyrus.infra.constraints.environment.ConstraintEnvironment;
-import org.eclipse.papyrus.infra.constraints.environment.ConstraintType;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-
-/**
- * A singleton instance to manage constraints.
- * The available constraints can be loaded from an extension point, or
- * dynamically
- *
- * @author Camille Letavernier
- *
- */
-public class ConstraintsManager {
-
- /**
- * The Constraints extension point ID
- */
- public final static String EXTENSION_ID = Activator.PLUGIN_ID + ".ConstraintEnvironment"; //$NON-NLS-1$
-
- private ResourceSet resourceSet;
-
- private final Set<ConstraintEnvironment> environments;
-
- private ConstraintsManager() {
- environments = new HashSet<ConstraintEnvironment>();
- resourceSet = new ResourceSetImpl();
- loadExtensionPoint();
- }
-
- private void loadExtensionPoint() {
- IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
-
- for (IConfigurationElement e : config) {
- final String environmentResource = e.getAttribute("environmentModel"); //$NON-NLS-1$
- URI uri = URI.createPlatformPluginURI(e.getContributor().getName() + "/" + environmentResource, true); //$NON-NLS-1$
- try {
- addEnvironment(uri);
- } catch (IOException ex) {
- Activator.log.error("The plugin " + e.getContributor() + " contributed an invalid extension for " + EXTENSION_ID, ex); //$NON-NLS-1$//$NON-NLS-2$
- }
- }
- }
-
- /**
- * Adds a constraint environment model, which should be loaded at
- * the given URI. The root element should be a {@link ConstraintEnvironment}
- *
- * @param uri
- * The location of the model to load. Its root element should be a {@link ConstraintEnvironment}
- * @throws IOException
- * If the model cannot be loaded
- */
- public void addEnvironment(URI uri) throws IOException {
- EObject model = EMFHelper.loadEMFModel(resourceSet, uri);
- if (model instanceof ConstraintEnvironment) {
- addEnvironment((ConstraintEnvironment) model);
- }
- }
-
- /**
- * Adds a constraint environment model to the manager
- *
- * @param environment
- * The {@link ConstraintEnvironment} to add to the manager
- */
- public void addEnvironment(ConstraintEnvironment environment) {
- environments.add(environment);
- }
-
- /**
- * The singleton instance of {@link ConstraintsManager}
- */
- public static final ConstraintsManager instance = new ConstraintsManager();
-
- /**
- * Returns all {@link ConstraintType}s contained in the {@link ConstraintEnvironment} managed by this singleton
- *
- * @return
- * All known {@link ConstraintType}s
- */
- public Collection<ConstraintType> getConstraintTypes() {
- Collection<ConstraintType> constraintTypes = new HashSet<ConstraintType>();
- for (ConstraintEnvironment environment : environments) {
- constraintTypes.addAll(environment.getConstraintTypes());
- }
- return constraintTypes;
- }
-}
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
deleted file mode 100644
index 2b6704379d8..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/runtime/DefaultConstraintEngine.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2016 CEA LIST, Christian W. Damus, and others.
- *
- * 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
- * Christian W. Damus (CEA) - bug 417409
- * Christian W. Damus - bug 485220
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.constraints.runtime;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.StreamSupport;
-
-import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.papyrus.infra.constraints.Activator;
-import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor;
-import org.eclipse.papyrus.infra.constraints.DisplayUnit;
-import org.eclipse.papyrus.infra.constraints.constraints.Constraint;
-
-/**
- * The default, generic implementation for ConstraintEngine
- *
- * @author Camille Letavernier
- * @param <E>
- * The type of DisplayUnit managed by this Constraint Engine
- */
-public abstract class DefaultConstraintEngine<E extends DisplayUnit> implements ConstraintEngine<E> {
-
- // Pattern for names of methods that convert an object to a collection
- private static final Pattern CONVERTER_PATTERN = Pattern.compile("(?:to|as)(?:Collection|List|Set)"); //$NON-NLS-1$
-
- private static final Method NO_CONVERTER = Object.class.getMethods()[0];
-
- private final ListenerList listeners = new ListenerList(ListenerList.IDENTITY);
-
- /**
- * The constraints instantiated by this Engine
- */
- protected final Set<Constraint> constraints = new LinkedHashSet<Constraint>();
-
- private final Class<? extends E> displayUnitType;
-
- private final Map<Class<?>, Method> collectionConverters = new HashMap<>();
-
- protected DefaultConstraintEngine(Class<? extends E> displayUnitType) {
- super();
-
- this.displayUnitType = displayUnitType;
- }
-
- @Override
- public abstract void refresh();
-
- @Override
- public synchronized void addConstraint(ConstraintDescriptor descriptor) {
- Constraint constraint = ConstraintFactory.getInstance().createFromModel(descriptor);
- if (constraint != null) {
- constraints.add(constraint);
- }
- }
-
- @Override
- public synchronized Set<E> getDisplayUnits(final Object selection) {
- Collection<?> collection = asCollection(selection);
-
- Set<Constraint> matchedConstraints = match(collection);
-
- return getDisplayUnits(matchedConstraints);
- }
-
- private Set<Constraint> match(final Collection<?> selection) {
- Set<Constraint> matchedConstraints = new LinkedHashSet<Constraint>();
-
- if (selection.isEmpty()) {
- return matchedConstraints;
- }
-
- for (Constraint c : constraints) {
- try {
- if (c.match(selection)) {
- matchedConstraints.add(c);
- }
- } catch (Throwable ex) {
- String errorMessage = String.format("An error occurred when executing the matching constraint %s. This constraint will be ignored", c.getDescriptor().getName());
- Activator.log.error(errorMessage, ex);
- }
-
- }
-
- // String logValue;
- //
- // logValue = "Filtered Constraints : "; //$NON-NLS-1$
- // for(Constraint constraint : matchedConstraints) {
- // logValue += constraint.getDescriptor().getName() + ", ";
- // }
- // Activator.log.warn(logValue);
-
- resolveConstraintConflicts(matchedConstraints);
-
- // logValue = "Filtered Constraints : "; //$NON-NLS-1$
- // for(Constraint constraint : matchedConstraints) {
- // logValue += 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<E> getDisplayUnits(final Set<Constraint> matchedConstraints) {
- Set<E> displayUnits = new LinkedHashSet<E>();
- for (Constraint c : matchedConstraints) {
- displayUnits.add(displayUnitType.cast(c.getDescriptor().getDisplay()));
- }
- return displayUnits;
- }
-
- @Override
- public void addConstraintEngineListener(ConstraintEngineListener listener) {
- listeners.add(listener);
- }
-
- @Override
- public void removeConstraintEngineListener(ConstraintEngineListener listener) {
- listeners.remove(listener);
- }
-
- protected void fireConstraintsChanged() {
- if (!listeners.isEmpty()) {
- Object[] toNotify = listeners.getListeners();
- ConstraintsChangedEvent event = new ConstraintsChangedEvent(this);
- for (int i = 0; i < toNotify.length; i++) {
- try {
- ((ConstraintEngineListener) toNotify[i]).constraintsChanged(event);
- } catch (Exception e) {
- Activator.log.error("Uncaught exception in constraints-changed listener.", e); //$NON-NLS-1$
- }
- }
- }
- }
-
- private Collection<?> asCollection(Object object) {
- Collection<?> result;
-
- if (object == null) {
- result = Collections.EMPTY_LIST;
- } else if (object instanceof Collection<?>) {
- result = (Collection<?>) object;
- } else if (object instanceof Iterable<?>) {
- result = StreamSupport.stream(((Iterable<?>) object).spliterator(), false).collect(Collectors.toList());
- } else {
- Method converter = getToCollectionMethod(object);
- if (converter != null) {
- try {
- result = (Collection<?>) converter.invoke(object);
- } catch (Exception e) {
- // Converter not valid. Fine. Don't try it again
- rejectConverter(object);
- result = Collections.EMPTY_LIST;
- }
- } else {
- result = Collections.singletonList(object);
- }
- }
-
- return result;
- }
-
- private Method getToCollectionMethod(Object object) {
- Class<?> key = object.getClass();
- Method result = collectionConverters.computeIfAbsent(key, owner -> {
- for (Method next : owner.getMethods()) {
- if (((next.getModifiers() & Modifier.STATIC) == 0)
- && Collection.class.isAssignableFrom(next.getReturnType())
- && (next.getParameterCount() == 0)
- && CONVERTER_PATTERN.matcher(next.getName()).matches()) {
- return next;
- }
- }
- return NO_CONVERTER;
- });
-
- return (result == NO_CONVERTER) ? null : result;
- }
-
- private void rejectConverter(Object object) {
- collectionConverters.put(object.getClass(), NO_CONVERTER);
- }
-}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/util/ClassLoader.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/util/ClassLoader.java
deleted file mode 100644
index a5cdbea5d96..00000000000
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/util/ClassLoader.java
+++ /dev/null
@@ -1,84 +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.infra.constraints.util;
-
-import org.eclipse.papyrus.infra.constraints.Activator;
-
-/**
- * A Helper class for Class Loading.
- *
- * @author Camille Letavernier
- */
-public class ClassLoader {
-
- /**
- * Loads the class matching the given className. Exceptions are caught and sent
- * to the Logger.
- *
- * @param className
- * The qualified name of the Class to load.
- * @return
- * The loaded Class, or null if an error occured
- */
- public Class<?> loadClass(String className) {
- try {
- Class<?> clazz = Activator.getDefault().getBundle().loadClass(className);
- return clazz;
- } catch (ClassNotFoundException ex) {
- Activator.log.error("Cannot load class " + className, ex); //$NON-NLS-1$
- } catch (ClassCastException ex) {
- Activator.log.error("Cannot load class " + className, ex); //$NON-NLS-1$
- } catch (NullPointerException ex) {
- Activator.log.error("Cannot load class " + className, ex); //$NON-NLS-1$
- }
-
- return null;
- }
-
- /**
- * Returns a new Instance of the given class
- *
- * @param className
- * The qualified name of the Class to instantiate
- * @return
- * A new instance of the given class, or null if the class couldn't be
- * instantiated
- */
- public Object newInstance(String className) {
- return newInstance(loadClass(className));
- }
-
- /**
- * Returns a new Instance of the given class
- *
- * @param theClass
- * The Class to instantiate
- * @return
- * A new instance of the given class, or null if the class couldn't be
- * instantiated
- */
- public <T extends Object> T newInstance(Class<T> theClass) {
- if (theClass == null) {
- return null;
- }
-
- try {
- return theClass.newInstance();
- } catch (IllegalAccessException ex) {
- Activator.log.error(ex);
- } catch (InstantiationException ex) {
- Activator.log.error(ex);
- }
-
- return null;
- }
-}

Back to the top