diff options
Diffstat (limited to 'plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints')
14 files changed, 955 insertions, 1665 deletions
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/IViewTypeHelper.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/IViewTypeHelper.java index a0f26353408..57eaaee3d2a 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/IViewTypeHelper.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/IViewTypeHelper.java @@ -1,60 +1,60 @@ -/*****************************************************************************
- * 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:
- * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.viewpoints.policy;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView;
-
-
-/**
- * Represents a helper for the handling of view creation commands
- *
- * @author Laurent Wouters
- */
-public interface IViewTypeHelper {
- /**
- * Determines whether the given type of view is supported by this helper
- *
- * @return <code>true</code> if the type of view is supported by this helper
- */
- boolean isSupported(EClass type);
-
- /**
- * Determines whether the given object represents a view that is supported by this helper
- *
- * @param view
- * The object to enquire
- * @return <code>true</code> if the object represents a view supported by this helper
- */
- boolean isSupported(EObject view);
-
- /**
- * Gets the prototype for the given configuration element
- *
- * @param configuration
- * A view configuration element
- * @return The associated prototype
- */
- ViewPrototype getPrototypeFor(PapyrusView configuration);
-
- /**
- * Gets the prototype of the given view
- *
- * @param view
- * The view
- * @return The prototype of the given view
- */
- ViewPrototype getPrototypeOf(EObject view);
-}
+/***************************************************************************** + * 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: + * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.viewpoints.policy; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind; + + +/** + * Represents a helper for the handling of view creation commands + * + * @author Laurent Wouters + */ +public interface IViewTypeHelper { + /** + * Determines whether the given type of view is supported by this helper + * + * @return <code>true</code> if the type of view is supported by this helper + */ + boolean isSupported(EClass type); + + /** + * Determines whether the given object represents a view that is supported by this helper + * + * @param view + * The object to enquire + * @return <code>true</code> if the object represents a view supported by this helper + */ + boolean isSupported(EObject view); + + /** + * Gets the prototype for the given configuration element + * + * @param configuration + * A view configuration element + * @return The associated prototype + */ + ViewPrototype getPrototypeFor(PapyrusRepresentationKind configuration); + + /** + * Gets the prototype of the given view + * + * @param view + * The view + * @return The prototype of the given view + */ + ViewPrototype getPrototypeOf(EObject view); +} diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java index 303335964be..2b4d148b5cf 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelAddData.java @@ -1,202 +1,202 @@ -/*****************************************************************************
- * 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:
- * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.viewpoints.policy;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.papyrus.infra.viewpoints.configuration.PathElement;
-
-/**
- * Represents the set of data related to the insertion of a new model element in a view
- *
- * @author Laurent Wouters
- */
-public class ModelAddData {
- private boolean permit;
- private List<EReference> path;
- private EObject undoOrigin;
- private EReference undoReference;
- private EObject undoValuePrevious;
- private EObject undoValueNext;
-
- /**
- * Determines whether the insertion is permitted
- *
- * @return <code>true</code> if it is permitted
- */
- public boolean isPermitted() {
- return permit;
- }
-
- /**
- * Determines whether an insertion path for the new element has been defined
- *
- * @return <code>true</code> if an insertion path has been defined
- */
- public boolean isPathDefined() {
- return (path != null);
- }
-
- /**
- * Initializes this set of data without an insertion path
- *
- * @param permit
- * Is the insertion permitted?
- */
- public ModelAddData(boolean permit) {
- this.permit = permit;
- }
-
- /**
- * Initializes this set of data
- *
- * @param permit
- * Is the insertion permitted?
- * @param insertionPath
- * The insertion path
- */
- public ModelAddData(boolean permit, EList<PathElement> insertionPath) {
- this.permit = permit;
- if (insertionPath != null && !insertionPath.isEmpty()) {
- this.path = new ArrayList<EReference>(insertionPath.size());
- for (int i = 0; i != insertionPath.size(); i++) {
- path.add(insertionPath.get(i).getFeature());
- }
- }
- }
-
- /**
- * Execute the insertion represented by this object on the given origin object
- *
- * @param origin
- * The origin object
- * @param target
- * The object to insert
- * @return <code>true</code> if the insertion was successful
- */
- public boolean execute(EObject origin, EObject target) {
- EObject current = origin;
- int index = 0;
- while (index < path.size() - 1) {
- current = buildPathStep(current, path.get(index));
- if (current == null) {
- return false;
- }
- index++;
- }
- EReference feature = path.get(path.size() - 1);
- if (feature.isMany()) {
- EList list = (EList) current.eGet(feature);
- list.add(target);
- setUndo(current, feature, null, target);
- } else {
- setUndo(current, feature, (EObject) current.eGet(feature), target);
- current.eSet(feature, target);
- }
- return true;
- }
-
- /**
- * Undo the effect of a previous execute
- */
- public void undoExecute() {
- if (undoReference.isMany()) {
- ((EList) undoOrigin.eGet(undoReference)).remove(undoValueNext);
- } else {
- undoOrigin.eSet(undoReference, undoValuePrevious);
- }
- }
-
- /**
- * Re-execute the insertion represented by this object
- */
- public void redoExecute() {
- if (undoReference.isMany()) {
- ((EList) undoOrigin.eGet(undoReference)).add(undoValueNext);
- } else {
- undoOrigin.eSet(undoReference, undoValueNext);
- }
- }
-
- /**
- * Executes a step in the insertion path
- *
- * @param current
- * The current object
- * @param feature
- * The feature to resolve on the object
- * @return The resolved object at this step that is now contained in current.feature
- */
- private EObject buildPathStep(EObject current, EReference feature) {
- Object value = current.eGet(feature);
- if (value == null) {
- // Try to create an instance of the type
- EClass type = feature.getEReferenceType();
- if (type.isAbstract())
- {
- return null; // Too bad, we can't fix this
- }
- EObject inst = EcoreUtil.create(type);
- current.eSet(feature, inst);
- setUndo(current, feature, null, inst);
- return inst;
- } else if (value instanceof EList) {
- EList list = (EList) value;
- // If we got at least one element, return the first one
- if (!list.isEmpty()) {
- return (EObject) list.get(0);
- }
- // We have to create one
- EClass type = feature.getEReferenceType();
- if (type.isAbstract())
- {
- return null; // Too bad, we can't fix this
- }
- EObject inst = EcoreUtil.create(type);
- list.add(inst);
- setUndo(current, feature, null, inst);
- return inst;
- } else {
- return (EObject) value;
- }
- }
-
- /**
- * Sets up the undo data if necessary
- *
- * @param origin
- * The modified object
- * @param feature
- * The modified feature
- * @param previous
- * The previous value
- * @param next
- * The target value
- */
- private void setUndo(EObject origin, EReference feature, EObject previous, EObject next) {
- if (undoReference == null) {
- return;
- }
- undoOrigin = origin;
- undoReference = feature;
- undoValuePrevious = previous;
- undoValueNext = next;
- }
-}
+/***************************************************************************** + * 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: + * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.viewpoints.policy; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.papyrus.infra.gmfdiag.representation.PathElement; + +/** + * Represents the set of data related to the insertion of a new model element in a view + * + * @author Laurent Wouters + */ +public class ModelAddData { + private boolean permit; + private List<EReference> path; + private EObject undoOrigin; + private EReference undoReference; + private EObject undoValuePrevious; + private EObject undoValueNext; + + /** + * Determines whether the insertion is permitted + * + * @return <code>true</code> if it is permitted + */ + public boolean isPermitted() { + return permit; + } + + /** + * Determines whether an insertion path for the new element has been defined + * + * @return <code>true</code> if an insertion path has been defined + */ + public boolean isPathDefined() { + return (path != null); + } + + /** + * Initializes this set of data without an insertion path + * + * @param permit + * Is the insertion permitted? + */ + public ModelAddData(boolean permit) { + this.permit = permit; + } + + /** + * Initializes this set of data + * + * @param permit + * Is the insertion permitted? + * @param insertionPath + * The insertion path + */ + public ModelAddData(boolean permit, EList<PathElement> insertionPath) { + this.permit = permit; + if (insertionPath != null && !insertionPath.isEmpty()) { + this.path = new ArrayList<EReference>(insertionPath.size()); + for (int i = 0; i != insertionPath.size(); i++) { + path.add(insertionPath.get(i).getFeature()); + } + } + } + + /** + * Execute the insertion represented by this object on the given origin object + * + * @param origin + * The origin object + * @param target + * The object to insert + * @return <code>true</code> if the insertion was successful + */ + public boolean execute(EObject origin, EObject target) { + EObject current = origin; + int index = 0; + while (index < path.size() - 1) { + current = buildPathStep(current, path.get(index)); + if (current == null) { + return false; + } + index++; + } + EReference feature = path.get(path.size() - 1); + if (feature.isMany()) { + EList list = (EList) current.eGet(feature); + list.add(target); + setUndo(current, feature, null, target); + } else { + setUndo(current, feature, (EObject) current.eGet(feature), target); + current.eSet(feature, target); + } + return true; + } + + /** + * Undo the effect of a previous execute + */ + public void undoExecute() { + if (undoReference.isMany()) { + ((EList) undoOrigin.eGet(undoReference)).remove(undoValueNext); + } else { + undoOrigin.eSet(undoReference, undoValuePrevious); + } + } + + /** + * Re-execute the insertion represented by this object + */ + public void redoExecute() { + if (undoReference.isMany()) { + ((EList) undoOrigin.eGet(undoReference)).add(undoValueNext); + } else { + undoOrigin.eSet(undoReference, undoValueNext); + } + } + + /** + * Executes a step in the insertion path + * + * @param current + * The current object + * @param feature + * The feature to resolve on the object + * @return The resolved object at this step that is now contained in current.feature + */ + private EObject buildPathStep(EObject current, EReference feature) { + Object value = current.eGet(feature); + if (value == null) { + // Try to create an instance of the type + EClass type = feature.getEReferenceType(); + if (type.isAbstract()) + { + return null; // Too bad, we can't fix this + } + EObject inst = EcoreUtil.create(type); + current.eSet(feature, inst); + setUndo(current, feature, null, inst); + return inst; + } else if (value instanceof EList) { + EList list = (EList) value; + // If we got at least one element, return the first one + if (!list.isEmpty()) { + return (EObject) list.get(0); + } + // We have to create one + EClass type = feature.getEReferenceType(); + if (type.isAbstract()) + { + return null; // Too bad, we can't fix this + } + EObject inst = EcoreUtil.create(type); + list.add(inst); + setUndo(current, feature, null, inst); + return inst; + } else { + return (EObject) value; + } + } + + /** + * Sets up the undo data if necessary + * + * @param origin + * The modified object + * @param feature + * The modified feature + * @param previous + * The previous value + * @param next + * The target value + */ + private void setUndo(EObject origin, EReference feature, EObject previous, EObject next) { + if (undoReference == null) { + return; + } + undoOrigin = origin; + undoReference = feature; + undoValuePrevious = previous; + undoValueNext = next; + } +} diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java index a6f1fb08f0d..1558d2f64a3 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ModelRuleConstraintEngine.java @@ -28,7 +28,7 @@ import org.eclipse.papyrus.infra.constraints.constraints.Constraint; import org.eclipse.papyrus.infra.constraints.runtime.ConstraintEngine; import org.eclipse.papyrus.infra.constraints.runtime.ConstraintFactory; import org.eclipse.papyrus.infra.constraints.runtime.DefaultConstraintEngine; -import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule; +import org.eclipse.papyrus.infra.architecture.representation.ModelRule; /** * {@link ConstraintEngine} for viewpoint {@link ModelRule} diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java index cc3cc99dba0..e80bc997e8e 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/PolicyChecker.java @@ -17,69 +17,39 @@ package org.eclipse.papyrus.infra.viewpoints.policy; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.ResourceSet; -import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; -import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.gmf.runtime.emf.type.core.IElementType; import org.eclipse.gmf.runtime.notation.Diagram; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.papyrus.infra.core.pluginexplorer.Plugin; -import org.eclipse.papyrus.infra.core.pluginexplorer.PluginEntry; -import org.eclipse.papyrus.infra.viewpoints.configuration.AssistantRule; -import org.eclipse.papyrus.infra.viewpoints.configuration.ChildRule; -import org.eclipse.papyrus.infra.viewpoints.configuration.ModelAutoCreate; -import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule; -import org.eclipse.papyrus.infra.viewpoints.configuration.OwningRule; -import org.eclipse.papyrus.infra.viewpoints.configuration.PaletteRule; -import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusConfiguration; -import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusDiagram; -import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView; -import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusViewpoint; -import org.eclipse.papyrus.infra.viewpoints.iso42010.ArchitectureViewpoint; -import org.eclipse.papyrus.infra.viewpoints.iso42010.ModelKind; -import org.eclipse.papyrus.infra.viewpoints.iso42010.Stakeholder; -import org.eclipse.papyrus.infra.viewpoints.policy.listener.PolicyCheckerNotifier; +import org.eclipse.papyrus.infra.core.architecture.RepresentationKind; +import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureContext; +import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureViewpoint; +import org.eclipse.papyrus.infra.architecture.representation.ModelAutoCreate; +import org.eclipse.papyrus.infra.architecture.representation.ModelRule; +import org.eclipse.papyrus.infra.architecture.representation.OwningRule; +import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind; +import org.eclipse.papyrus.infra.architecture.ArchitectureDomainManager; +import org.eclipse.papyrus.infra.architecture.ArchitectureDescriptionUtils; +import org.eclipse.papyrus.infra.core.resource.ModelSet; +import org.eclipse.papyrus.infra.gmfdiag.representation.AssistantRule; +import org.eclipse.papyrus.infra.gmfdiag.representation.ChildRule; +import org.eclipse.papyrus.infra.gmfdiag.representation.PaletteRule; +import org.eclipse.papyrus.infra.gmfdiag.representation.PapyrusDiagram; /** - * The <code>PolicyChecker</code> enforces the viewpoints configuration as a policy in the user interface + * The <code>PolicyChecker</code> enforces the viewpoints description as a policy in the user interface * * @author Laurent Wouters */ public class PolicyChecker { /** - * ID of the extension point defining the configurations - */ - private static final String EXTENSION_ID = "org.eclipse.papyrus.infra.viewpoints.policy.custom"; - /** - * The cache of loaded configurations - */ - private static final Map<String, PapyrusConfiguration> CONFIGURATIONS_CACHE = new HashMap<String, PapyrusConfiguration>(); - /** - * The resource set for our configuration cache. Use a single resource set for loading configurations so that configurations - * for dynamic profiles don't cause the UML metamodel and all of its dependencies to be loaded repeatedly - */ - private static final ResourceSet CONFIGURATIONS_RESOURCE_SET = new ResourceSetImpl(); - /** - * The default built-in configuration - */ - private static final PapyrusConfiguration CONFIG_BUILTIN_DEFAULT = loadDefaultConfiguration("builtin/default.configuration"); - /** * Default result when the current policy cannot determine whether an element can be added to a view */ private static final boolean DEFAULT_POLICY_UNKNOWN_CHILD = false; @@ -87,8 +57,6 @@ public class PolicyChecker { * Default result when the current policy cannot determine whether a palette item should be exposed */ private static final boolean DEFAULT_POLICY_UNKNWON_PALETTE = true; - - /** * Policy check result allowing an action */ @@ -102,379 +70,65 @@ public class PolicyChecker { */ private static final int RESULT_DENY = -1; - /** - * Loads a built-in configuration - * - * @param name - * The name of the configuration - * @return The loaded configuration - */ - private static PapyrusConfiguration loadDefaultConfiguration(String name) { - Plugin me = new Plugin(Activator.getDefault().getBundle()); - PluginEntry entry = me.getEntry(name); - return loadConfigurationFrom(entry.getLogicalPath()); + public static PolicyChecker getFor(EObject object) { + if (object.eResource() != null) + return getFor(object.eResource()); + else + return getFor(ArchitectureDomainManager.getInstance().getDefaultArchitectureContext()); } - - /** - * Loads a viewpoints configuration from the given location. - * - * @param location - * The location from where to load the configuration - * @return The loaded configuration, or <code>null</code> if the operation failed - */ - public static PapyrusConfiguration loadConfigurationFrom(String location) { - if (location == null) { - return null; - } - if (location.isEmpty()) { - return null; - } - URI uri = null; - if (location.startsWith("platform:/")) { - uri = URI.createURI(location); - } else { - uri = URI.createFileURI(location); - } - location = uri.toString(); - PapyrusConfiguration config = CONFIGURATIONS_CACHE.get(location); - if (config != null) { - return config; - } - Resource res = CONFIGURATIONS_RESOURCE_SET.getResource(uri, true); - EList<EObject> contents = res.getContents(); - if (contents.size() > 0) { - config = (PapyrusConfiguration) contents.get(0); - CONFIGURATIONS_CACHE.put(location, config); - } - return config; + + public static PolicyChecker getFor(Resource resource) { + if (resource.getResourceSet() != null) + return getFor(resource.getResourceSet()); + else + return getFor(ArchitectureDomainManager.getInstance().getDefaultArchitectureContext()); } - /** - * Gets the default configuration - * - * @return The default configuration - */ - public static PapyrusConfiguration getDefaultConfiguration() { - return CONFIG_BUILTIN_DEFAULT; + public static PolicyChecker getFor(ResourceSet resourceSet) { + if (resourceSet instanceof ModelSet) + return getFor((ModelSet) resourceSet); + else + return getFor(ArchitectureDomainManager.getInstance().getDefaultArchitectureContext()); } - - private static Map<String, Collection<String>> CONTRIBUTIONS_DEFINITON = null; - private static Map<PapyrusConfiguration, Collection<PapyrusConfiguration>> CONTRIBUTIONS_CACHE = null; - - /** - * Gets the viewpoints contributing to the given viewpoint - * - * @param viewpoint - * A viewpoint - * @return A collection of the other viewpoints contributing to the given one - */ - private static Collection<PapyrusViewpoint> getContributionsTo(PapyrusViewpoint viewpoint) { - Collection<PapyrusViewpoint> result = new ArrayList<PapyrusViewpoint>(); - Collection<PapyrusConfiguration> contributions = getContributionsTo((PapyrusConfiguration) viewpoint.eContainer()); - for (PapyrusConfiguration contrib : contributions) { - for (ArchitectureViewpoint vp : contrib.getViewpoints()) { - if (vp instanceof PapyrusViewpoint && vp.getName().equals(viewpoint.getName())) { - result.add((PapyrusViewpoint) vp); - } - } - } - return result; + public static PolicyChecker getFor(ModelSet modelSet) { + Collection<MergedArchitectureViewpoint> viewpoints = new ArchitectureDescriptionUtils(modelSet).getArchitectureViewpoints(); + return getFor(viewpoints); } - - /** - * Gets the configurations contributing to the given configuration - * - * @param config - * A configuration - * @return A collection of the contributing configurations - */ - private static Collection<PapyrusConfiguration> getContributionsTo(PapyrusConfiguration config) { - if (CONTRIBUTIONS_CACHE == null) { - loadContributions(); - } - Collection<PapyrusConfiguration> result = CONTRIBUTIONS_CACHE.get(config); - if (result != null) { - return result; - } - result = new ArrayList<PapyrusConfiguration>(); - CONTRIBUTIONS_CACHE.put(config, result); - for (Map.Entry<String, PapyrusConfiguration> entry : CONFIGURATIONS_CACHE.entrySet()) { - if (entry.getValue() == config) { - Collection<String> contribURIs = CONTRIBUTIONS_DEFINITON.get(entry.getKey()); - if (contribURIs != null) { - for (String uri : contribURIs) { - result.add(loadConfigurationFrom(uri)); - } - } - return result; - } - } - return result; + + public static PolicyChecker getFor(MergedArchitectureContext context) { + return new PolicyChecker(context.getViewpoints()); } - /** - * Loads the viewpoints contribution data from the extension points - */ - private static void loadContributions() { - CONTRIBUTIONS_DEFINITON = new HashMap<String, Collection<String>>(); - CONTRIBUTIONS_CACHE = new HashMap<PapyrusConfiguration, Collection<PapyrusConfiguration>>(); - - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint point = registry.getExtensionPoint(EXTENSION_ID); - IExtension[] extensions = point.getExtensions(); - - for (int i = 0; i != extensions.length; i++) { - String plugin = extensions[i].getContributor().getName(); - IConfigurationElement[] elements = extensions[i].getConfigurationElements(); - for (int j = 0; j != elements.length; j++) { - if (elements[j].getName().equals("contribution")) { - String uriOriginal = getCanonicalURI(plugin, elements[j].getAttribute("original")); - String uriContrib = getCanonicalURI(plugin, elements[j].getAttribute("file")); - Collection<String> list = CONTRIBUTIONS_DEFINITON.get(uriOriginal); - if (list == null) { - list = new ArrayList<String>(); - CONTRIBUTIONS_DEFINITON.put(uriOriginal, list); - } - list.add(uriContrib); - } - } - } + public static PolicyChecker getFor(Collection<MergedArchitectureViewpoint> viewpoints) { + return new PolicyChecker(viewpoints); } /** - * Gets the canonical (absolute) URI from a potentially plugin-relative URI - * - * @param plugin - * The container plugin - * @param uri - * The URI to canonicalize - * @return The canonical (absolute) URI - */ - private static String getCanonicalURI(String plugin, String uri) { - if (uri.startsWith(PreferenceConstants.P_CONF_PATH_SCHEME_PLUGIN_VALUE)) { - return uri; - } - return PreferenceConstants.P_CONF_PATH_SCHEME_PLUGIN_VALUE + plugin + "/" + uri; - } - - - /** - * Gets the preference store for the viewpoints-related preferences - * - * @return The preference store for the viewpoints-related preferences - */ - public static IPreferenceStore getPreferences() { - return Activator.getDefault().getPreferenceStore(); - } - - - /** - * The current (global) instance - */ - private static PolicyChecker currentPolicyChecker; - - /** - * Gets the policy checker currently enforcing the viewpoints configuration - * - * @return The current policy checker - */ - public static synchronized PolicyChecker getCurrent() { - if (currentPolicyChecker == null) { - currentPolicyChecker = new PolicyChecker(); - PolicyCheckerNotifier.getInstance().fire(currentPolicyChecker); - } - return currentPolicyChecker; - } - - /** - * Sets the policy checker currently enforcing the viewpoints configuration - * - * @param pc - * The new policy checker - */ - public static void setCurrent(PolicyChecker pc) { - currentPolicyChecker = pc; - PolicyCheckerNotifier.getInstance().fire(pc); - } - - - /** - * The checker's configuration - */ - private PapyrusConfiguration configuration; - - /** - * Force only one type of view per model element - */ - private boolean oneViewPerElem; - - /** - * The current stakeholder - */ - private Stakeholder selectedStakeholder; - - /** - * The current viewpoint - */ - private PapyrusViewpoint selectedViewpoint; - - /** - * The cache of applicable viewpoints, with all contributing configurations taken into account - */ - private Collection<PapyrusViewpoint> applicableViewpoints; - - /** * The current profile helper */ private IProfileHelper profileHelper; /** - * Gets the configuration enforced by this object - * - * @return The configuration - */ - public PapyrusConfiguration getConfiguration() { - return configuration; - } - - /** - * Gets the stakeholder represented by this object - * - * @return The stakeholder + * The architecture viewpoints */ - public Stakeholder getStakeholder() { - return selectedStakeholder; - } + private Collection<MergedArchitectureViewpoint> viewpoints; /** * Gets the viewpoint enforced by this object * * @return The enforced viewpoint */ - public PapyrusViewpoint getViewpoint() { - return selectedViewpoint; + public Collection<MergedArchitectureViewpoint> getViewpoints() { + return viewpoints; } /** * Initializes this instance from the current preferences */ - private PolicyChecker() { - IPreferenceStore store = getPreferences(); - String prefType = store.getString(PreferenceConstants.P_CONF_TYPE); - String prefForce = store.getString(PreferenceConstants.P_FORCE_MULTIPLICITY); - String prefViewpoint = store.getString(PreferenceConstants.P_VIEWPOINT); - - this.profileHelper = ProfileUtils.getProfileHelper(); - this.oneViewPerElem = "true".equals(prefForce); - if (PreferenceConstants.P_CONF_TYPE_DEFAULT_VALUE.equals(prefType)) { - this.configuration = CONFIG_BUILTIN_DEFAULT; - } else if (PreferenceConstants.P_CONF_TYPE_EXTENSION_VALUE.equals(prefType)) { - WeightedConfiguration wc = WeightedConfiguration.getTopConfiguration(); - this.configuration = (wc != null ? wc.getConfiguration() : null); - } else { - String scheme = store.getString(PreferenceConstants.P_CONF_PATH_SCHEME); - String path = store.getString(PreferenceConstants.P_CONF_PATH); - if (PreferenceConstants.P_CONF_PATH_SCHEME_WORKSPACE_VALUE.equals(scheme)) { - path = PreferenceConstants.P_CONF_PATH_SCHEME_WORKSPACE_VALUE + path; - } - this.configuration = loadConfigurationFrom(path); - } - if (this.configuration == null) { - this.configuration = CONFIG_BUILTIN_DEFAULT; - } - - if (prefViewpoint != null && !prefViewpoint.isEmpty()) { - for (Stakeholder stakeholder : this.configuration.getStakeholders()) { - for (ArchitectureViewpoint vp : stakeholder.getViewpoints()) { - if (prefViewpoint.equals(vp.getName())) { - this.selectedStakeholder = stakeholder; - this.selectedViewpoint = (PapyrusViewpoint) vp; - buildApplicableViewpoints(); - return; - } - } - } - } - this.selectedStakeholder = this.configuration.getDefaultStakeholder(); - this.selectedViewpoint = (PapyrusViewpoint) this.selectedStakeholder.getViewpoints().get(0); - buildApplicableViewpoints(); - } - - /** - * Initializes this policy checker with the default configuration and viewpoint - * - * @param oneViewPerElem - * Force only one type of view per model element - */ - public PolicyChecker(boolean oneViewPerElem) { - this.configuration = CONFIG_BUILTIN_DEFAULT; - this.oneViewPerElem = oneViewPerElem; - this.selectedStakeholder = this.configuration.getDefaultStakeholder(); - this.selectedViewpoint = (PapyrusViewpoint) this.selectedStakeholder.getViewpoints().get(0); + private PolicyChecker(Collection<MergedArchitectureViewpoint> viewpoints) { this.profileHelper = ProfileUtils.getProfileHelper(); - buildApplicableViewpoints(); - } - - /** - * Initializes this policy checker with the given configuration and viewpoint - * - * @param config - * The configuration to enforce - * @param viewpoint - * The viewpoint to enforce - * @param oneViewPerElem - * Force only one type of view per model element - */ - public PolicyChecker(PapyrusConfiguration config, PapyrusViewpoint viewpoint, boolean oneViewPerElem) { - this.configuration = config; - this.oneViewPerElem = oneViewPerElem; - this.selectedViewpoint = viewpoint; - this.profileHelper = ProfileUtils.getProfileHelper(); - buildApplicableViewpoints(); - for (Stakeholder stakeholder : configuration.getStakeholders()) { - if (stakeholder.getViewpoints().contains(viewpoint)) { - this.selectedStakeholder = stakeholder; - return; - } - } - } - - - /** - * Builds the <code>applicableViewpoints</code> member from the selected viewpoint. - */ - private void buildApplicableViewpoints() { - applicableViewpoints = new ArrayList<PapyrusViewpoint>(); - buildApplicableViewpoints(selectedViewpoint); - } - - /** - * Builds the <code>applicableViewpoints</code> member from the given viewpoint by adding it, - * as well as its parents and its and all its contributions, recursively - * - * @param vp - * the viewpoint to add - */ - private void buildApplicableViewpoints(PapyrusViewpoint vp) { - // Guard against cycles, redundant contributions, contributions having the - // same parent, and other ways of repeating the processing of any viewpoint - if (!applicableViewpoints.contains(vp)) { - // This viewpoint - applicableViewpoints.add(vp); - - // Its contributions, recursively. Process these first because they - // are more likely to be more pertinent to the selected stakeholder - // than the inherited viewpoint(s) - for (PapyrusViewpoint contrib : getContributionsTo(vp)) { - buildApplicableViewpoints(contrib); - } - - // Its parents, recursively - if ((vp.getParent() != null) && !vp.getParent().eIsProxy()) { - buildApplicableViewpoints(vp.getParent()); - } - } + this.viewpoints = viewpoints; } /** @@ -492,13 +146,13 @@ public class PolicyChecker { if (prototype == null) { return false; } - if (!matchesProfiles(prototype.configuration, profileHelper.getAppliedProfiles(owner))) { + if (!matchesProfiles(prototype.representationKind, profileHelper.getAppliedProfiles(owner))) { return false; } - if (!matchesProfiles(prototype.configuration, profileHelper.getAppliedProfiles(element))) { + if (!matchesProfiles(prototype.representationKind, profileHelper.getAppliedProfiles(element))) { return false; } - if (!matchesCreationRoot(prototype.configuration, element, profileHelper.getAppliedStereotypes(element), prototype.getViewCountOn(element))) { + if (!matchesCreationRoot(prototype.representationKind, element, profileHelper.getAppliedStereotypes(element), prototype.getViewCountOn(element))) { return false; } return true; @@ -522,7 +176,7 @@ public class PolicyChecker { return new ModelAddData(false); } - PapyrusDiagram config = (PapyrusDiagram) prototype.configuration; + PapyrusDiagram config = (PapyrusDiagram) prototype.representationKind; Collection<EClass> stereotypes = profileHelper.getAppliedStereotypes(child); while (config != null) { for (ChildRule rule : config.getChildRules()) { @@ -554,7 +208,7 @@ public class PolicyChecker { return new ModelAddData(false); } - PapyrusDiagram config = (PapyrusDiagram) prototype.configuration; + PapyrusDiagram config = (PapyrusDiagram) prototype.representationKind; while (config != null) { for (ChildRule rule : config.getChildRules()) { int result = allows(rule, parentType, childType, new ArrayList<EClass>(0)); @@ -583,7 +237,7 @@ public class PolicyChecker { return false; } - PapyrusDiagram config = (PapyrusDiagram) prototype.configuration; + PapyrusDiagram config = (PapyrusDiagram) prototype.representationKind; while (config != null) { for (PaletteRule rule : config.getPaletteRules()) { int result = allows(rule, entryID); @@ -612,7 +266,7 @@ public class PolicyChecker { return false; } - PapyrusDiagram config = (PapyrusDiagram) prototype.configuration; + PapyrusDiagram config = (PapyrusDiagram) prototype.representationKind; while (config != null) { for (AssistantRule rule : config.getAssistantRules()) { int result = allows(rule, elementType); @@ -626,17 +280,16 @@ public class PolicyChecker { } /** - * Determines whether the given view configuration element is part of the current viewpoint + * Determines whether the given view description element is part of the current viewpoint * * @param config - * A view configuration element + * A view description element * @return <code>true</code> if the element is part of the current viewpoint */ - public boolean isInViewpoint(PapyrusView config) { - for (PapyrusViewpoint viewpoint : applicableViewpoints) { - for (ModelKind kind : viewpoint.getModelKinds()) { - PapyrusView view = (PapyrusView) kind; - if (EcoreUtil.equals(view, config)) { + public boolean isInViewpoint(PapyrusRepresentationKind kind) { + for (MergedArchitectureViewpoint viewpoint : getViewpoints()) { + for (RepresentationKind aKind : viewpoint.getRepresentationKinds()) { + if (aKind.getQualifiedName().equals(kind.getQualifiedName())) { return true; } } @@ -651,9 +304,9 @@ public class PolicyChecker { */ public Collection<ViewPrototype> getAllPrototypes() { Collection<ViewPrototype> result = new ArrayList<ViewPrototype>(); - for (PapyrusViewpoint viewpoint : applicableViewpoints) { - for (ModelKind kind : viewpoint.getModelKinds()) { - PapyrusView view = (PapyrusView) kind; + for (MergedArchitectureViewpoint viewpoint : getViewpoints()) { + for (RepresentationKind kind : viewpoint.getRepresentationKinds()) { + PapyrusRepresentationKind view = (PapyrusRepresentationKind) kind; ViewPrototype proto = ViewPrototype.get(view); if (proto != null) { result.add(proto); @@ -671,12 +324,12 @@ public class PolicyChecker { * @return A list of the prototypes that can be instantiated */ public Collection<ViewPrototype> getPrototypesFor(EObject element) { - Collection<ViewPrototype> result = new ArrayList<ViewPrototype>(); + Collection<ViewPrototype> result = new LinkedHashSet<ViewPrototype>(); Collection<EPackage> profiles = profileHelper.getAppliedProfiles(element); Collection<EClass> stereotypes = profileHelper.getAppliedStereotypes(element); - for (PapyrusViewpoint viewpoint : applicableViewpoints) { - for (ModelKind kind : viewpoint.getModelKinds()) { - PapyrusView view = (PapyrusView) kind; + for (MergedArchitectureViewpoint viewpoint : getViewpoints()) { + for (RepresentationKind kind : viewpoint.getRepresentationKinds()) { + PapyrusRepresentationKind view = (PapyrusRepresentationKind) kind; if (!matchesProfiles(view, profiles)) { continue; } @@ -719,12 +372,12 @@ public class PolicyChecker { public OwningRule getOwningRuleFor(ViewPrototype prototype, EObject owner) { Collection<EClass> stereotypes = profileHelper.getAppliedStereotypes(owner); int count = prototype.getOwnedViewCount(owner); - OwningRule rule = matchesCreationOwner(prototype.configuration, owner, stereotypes, count); + OwningRule rule = matchesCreationOwner(prototype.representationKind, owner, stereotypes, count); return rule; } /** - * Tries to match a view configuration from the given info + * Tries to match a view description from the given info * * @param implem * The implementation ID @@ -734,10 +387,10 @@ public class PolicyChecker { * The root element * @return The matching view, or <code>null</code> if none was found */ - protected PapyrusView getViewFrom(String implem, EObject owner, EObject root) { - for (PapyrusViewpoint viewpoint : applicableViewpoints) { - for (ModelKind kind : viewpoint.getModelKinds()) { - PapyrusView view = (PapyrusView) kind; + protected PapyrusRepresentationKind getRepresentationKindFrom(String implem, EObject owner, EObject root) { + for (MergedArchitectureViewpoint viewpoint : getViewpoints()) { + for (RepresentationKind kind : viewpoint.getRepresentationKinds()) { + PapyrusRepresentationKind view = (PapyrusRepresentationKind) kind; if (matches(view, implem, owner, root)) { return view; } @@ -747,22 +400,19 @@ public class PolicyChecker { } /** - * Tries to match a view configuration with the given info + * Tries to match a view description with the given info * * @param view - * A view configuration + * A view description * @param implem * The implementation ID * @param owner * The owner * @param root * The root element - * @return <code>true</code> if the configuration matches + * @return <code>true</code> if the description matches */ - private boolean matches(PapyrusView view, String implem, EObject owner, EObject root) { - if (!ViewPrototype.isNatural(view)) { - return false; - } + private boolean matches(PapyrusRepresentationKind view, String implem, EObject owner, EObject root) { if (!view.getImplementationID().equals(implem)) { return false; } @@ -794,10 +444,10 @@ public class PolicyChecker { * The applied profiles * @return <code>true</code> if the prototype is matching */ - private boolean matchesProfiles(PapyrusView view, Collection<EPackage> profiles) { - PapyrusView current = view; + private boolean matchesProfiles(PapyrusRepresentationKind view, Collection<EPackage> profiles) { + PapyrusRepresentationKind current = view; while (current != null) { - for (EPackage profile : view.getProfiles()) { + for (EPackage profile : view.getLanguage().getProfiles()) { if (!profiles.contains(profile)) { return false; } @@ -818,8 +468,8 @@ public class PolicyChecker { * The stereotypes applied on the owning element * @return <code>true</code> if the prototype is matching */ - private boolean matchesExistingOwner(PapyrusView view, EObject owner, Collection<EClass> stereotypes) { - PapyrusView current = view; + private boolean matchesExistingOwner(PapyrusRepresentationKind view, EObject owner, Collection<EClass> stereotypes) { + PapyrusRepresentationKind current = view; while (current != null) { for (OwningRule rule : current.getOwningRules()) { int result = allows(rule, owner, stereotypes); @@ -848,8 +498,8 @@ public class PolicyChecker { * The current cardinality for the owning element * @return The matching rule that allows the owner */ - private OwningRule matchesCreationOwner(PapyrusView view, EObject owner, Collection<EClass> stereotypes, int count) { - PapyrusView current = view; + private OwningRule matchesCreationOwner(PapyrusRepresentationKind view, EObject owner, Collection<EClass> stereotypes, int count) { + PapyrusRepresentationKind current = view; while (current != null) { for (OwningRule rule : current.getOwningRules()) { int allow = allows(rule, owner, stereotypes); @@ -882,8 +532,8 @@ public class PolicyChecker { * The stereotypes applied on the root element * @return <code>true</code> if the prototype is matching */ - private boolean matchesExistingRoot(PapyrusView view, EObject root, Collection<EClass> stereotypes) { - PapyrusView current = view; + private boolean matchesExistingRoot(PapyrusRepresentationKind view, EObject root, Collection<EClass> stereotypes) { + PapyrusRepresentationKind current = view; while (current != null) { for (ModelRule rule : current.getModelRules()) { int result = allows(rule, root, stereotypes); @@ -912,8 +562,8 @@ public class PolicyChecker { * The current cardinality for the root element * @return <code>true</code> if the prototype is matching */ - private boolean matchesCreationRoot(PapyrusView view, EObject root, Collection<EClass> stereotypes, int count) { - PapyrusView current = view; + private boolean matchesCreationRoot(PapyrusRepresentationKind view, EObject root, Collection<EClass> stereotypes, int count) { + PapyrusRepresentationKind current = view; while (current != null) { for (ModelRule rule : current.getModelRules()) { int allow = allows(rule, root, stereotypes); @@ -923,7 +573,7 @@ public class PolicyChecker { if (allow == RESULT_UNKNOWN) { continue; } - int multiplicity = (oneViewPerElem ? 1 : rule.getMultiplicity()); + int multiplicity = rule.getMultiplicity(); if (multiplicity == -1 || count < multiplicity) { return true; } diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java index 8e1cb3a40bb..849c8032c97 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ProfileUtils.java @@ -1,87 +1,87 @@ -/*****************************************************************************
- * 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:
- * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.viewpoints.policy;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EPackage;
-
-
-/**
- * Helper class for the ProfileHelper extension point
- *
- * @author Laurent Wouters
- */
-class ProfileUtils {
- /**
- * ID of the extension point
- */
- private static final String EXTENSION_ID = "org.eclipse.papyrus.infra.viewpoints.policy.profilehelper";
-
- /**
- * Gets a instance of the <code>IProfileHelper</code> interface
- *
- * @return an instance of <code>IProfileHelper</code>
- */
- public static IProfileHelper getProfileHelper() {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint point = registry.getExtensionPoint(EXTENSION_ID);
- IExtension[] extensions = point.getExtensions();
-
- for (int i = 0; i != extensions.length; i++) {
- IConfigurationElement[] elements = extensions[i].getConfigurationElements();
- for (int j = 0; j != elements.length; j++) {
- try {
- IProfileHelper instance = (IProfileHelper) elements[j].createExecutableExtension("class");
- if (instance != null) {
- return instance;
- }
- } catch (CoreException e) {
- }
- }
- }
- return new DefaultProfileHelper();
- }
-
- /**
- * Represents a default implementation of the profile helper
- *
- * @author Laurent Wouters
- */
- private static class DefaultProfileHelper implements IProfileHelper {
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.IProfileHelper#getAppliedProfiles(org.eclipse.emf.ecore.EObject)
- */
- public Collection<EPackage> getAppliedProfiles(EObject model) {
- return new ArrayList<EPackage>(0);
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.IProfileHelper#getAppliedStereotypes(org.eclipse.emf.ecore.EObject)
- */
- public Collection<EClass> getAppliedStereotypes(EObject object) {
- return new ArrayList<EClass>(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: + * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.infra.viewpoints.policy; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; + + +/** + * Helper class for the ProfileHelper extension point + * + * @author Laurent Wouters + */ +public class ProfileUtils { + /** + * ID of the extension point + */ + private static final String EXTENSION_ID = "org.eclipse.papyrus.infra.viewpoints.policy.profilehelper"; + + /** + * Gets a instance of the <code>IProfileHelper</code> interface + * + * @return an instance of <code>IProfileHelper</code> + */ + public static IProfileHelper getProfileHelper() { + IExtensionRegistry registry = Platform.getExtensionRegistry(); + IExtensionPoint point = registry.getExtensionPoint(EXTENSION_ID); + IExtension[] extensions = point.getExtensions(); + + for (int i = 0; i != extensions.length; i++) { + IConfigurationElement[] elements = extensions[i].getConfigurationElements(); + for (int j = 0; j != elements.length; j++) { + try { + IProfileHelper instance = (IProfileHelper) elements[j].createExecutableExtension("class"); + if (instance != null) { + return instance; + } + } catch (CoreException e) { + } + } + } + return new DefaultProfileHelper(); + } + + /** + * Represents a default implementation of the profile helper + * + * @author Laurent Wouters + */ + private static class DefaultProfileHelper implements IProfileHelper { + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.IProfileHelper#getAppliedProfiles(org.eclipse.emf.ecore.EObject) + */ + public Collection<EPackage> getAppliedProfiles(EObject model) { + return new ArrayList<EPackage>(0); + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.IProfileHelper#getAppliedStereotypes(org.eclipse.emf.ecore.EObject) + */ + public Collection<EClass> getAppliedStereotypes(EObject object) { + return new ArrayList<EClass>(0); + } + } +} diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java index dc4275b5656..34a249dcabd 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/RuleConstraintManager.java @@ -17,7 +17,7 @@ import java.util.List; import org.eclipse.emf.ecore.EObject; import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor; -import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule; +import org.eclipse.papyrus.infra.architecture.representation.ModelRule; /** * Manager for the rule constraints diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/UnavailableViewPrototype.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/UnavailableViewPrototype.java index 9689ea5ad15..10666f9ce20 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/UnavailableViewPrototype.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/UnavailableViewPrototype.java @@ -1,154 +1,133 @@ -/*****************************************************************************
- * Copyright (c) 2013, 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:
- * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 474467
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.viewpoints.policy;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.viewpoints.configuration.Category;
-
-
-/**
- * Represents a view prototype that is not available in the current viewpoints configuration
- *
- * @author Laurent Wouters
- */
-public class UnavailableViewPrototype extends ViewPrototype {
-
- private String name;
-
- private String icon;
-
- /**
- * Constructor.
- */
- protected UnavailableViewPrototype(String name, String icon) {
- super(null);
- this.name = name;
- this.icon = icon;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#isNatural()
- */
- @Override
- public boolean isNatural() {
- return true;
- }
-
- @Override
- public boolean isUnavailable() {
- return true;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getImplementation()
- */
- @Override
- public String getImplementation() {
- return "PapyrusUnavailableView";
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getLabel()
- */
- @Override
- public String getLabel() {
- return "Unavailable " + name;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getQualifiedName()
- */
- @Override
- public String getQualifiedName() {
- return "Default Papyrus Viewpoint :: " + getLabel();
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getIconURI()
- */
- @Override
- public String getIconURI() {
- return "platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/Unavailable" + icon + ".gif";
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#isOwnerReassignable()
- */
- @Override
- public boolean isOwnerReassignable() {
- return false;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#instantiateOn(org.eclipse.emf.ecore.EObject)
- */
- @Override
- public boolean instantiateOn(EObject owner) {
- return false;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#instantiateOn(org.eclipse.emf.ecore.EObject, java.lang.String)
- */
- @Override
- public boolean instantiateOn(EObject owner, String name) {
- return false;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getCommandChangeOwner(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
- */
- @Override
- public Command getCommandChangeOwner(EObject view, EObject target) {
- return null;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getCommandChangeRoot(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
- */
- @Override
- public Command getCommandChangeRoot(EObject view, EObject target) {
- return null;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getOwnerOf(org.eclipse.emf.ecore.EObject)
- */
- @Override
- public EObject getOwnerOf(EObject view) {
- return null;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getRootOf(org.eclipse.emf.ecore.EObject)
- */
- @Override
- public EObject getRootOf(EObject view) {
- return null;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getCategories()
- *
- * @return
- */
- @Override
- public Collection<Category> getCategories() {
- return Collections.emptyList();
- }
-}
+/***************************************************************************** + * Copyright (c) 2013, 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: + * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation + * Christian W. Damus - bug 474467 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.viewpoints.policy; + +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.ecore.EObject; + + +/** + * Represents a view prototype that is not available in the current viewpoints configuration + * + * @author Laurent Wouters + */ +public class UnavailableViewPrototype extends ViewPrototype { + + private String name; + + private String icon; + + /** + * Constructor. + */ + protected UnavailableViewPrototype(String name, String icon) { + super(null); + this.name = name; + this.icon = icon; + } + + @Override + public boolean isUnavailable() { + return true; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getImplementation() + */ + @Override + public String getImplementation() { + return "PapyrusUnavailableView"; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getLabel() + */ + @Override + public String getLabel() { + return "Unavailable " + name; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getQualifiedName() + */ + @Override + public String getQualifiedName() { + return "Default Papyrus Viewpoint :: " + getLabel(); + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getIconURI() + */ + @Override + public String getIconURI() { + return "platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/Unavailable" + icon + ".gif"; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#isOwnerReassignable() + */ + @Override + public boolean isOwnerReassignable() { + return false; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#instantiateOn(org.eclipse.emf.ecore.EObject) + */ + @Override + public boolean instantiateOn(EObject owner) { + return false; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#instantiateOn(org.eclipse.emf.ecore.EObject, java.lang.String) + */ + @Override + public boolean instantiateOn(EObject owner, String name) { + return false; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getCommandChangeOwner(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject) + */ + @Override + public Command getCommandChangeOwner(EObject view, EObject target) { + return null; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getCommandChangeRoot(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject) + */ + @Override + public Command getCommandChangeRoot(EObject view, EObject target) { + return null; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getOwnerOf(org.eclipse.emf.ecore.EObject) + */ + @Override + public EObject getOwnerOf(EObject view) { + return null; + } + + /** + * @see org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype#getRootOf(org.eclipse.emf.ecore.EObject) + */ + @Override + public EObject getRootOf(EObject view) { + return null; + } + +} diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java index 69b0ace8d67..e450ba96a87 100644 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototype.java @@ -32,13 +32,12 @@ import org.eclipse.emf.common.command.Command; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.papyrus.infra.viewpoints.configuration.Category; -import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule; -import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusDiagram; -import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusSyncTable; -import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusTable; -import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusView; -import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusViewpoint; +import org.eclipse.papyrus.infra.core.architecture.ArchitectureDescriptionLanguage; +import org.eclipse.papyrus.infra.architecture.representation.ModelRule; +import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind; +import org.eclipse.papyrus.infra.gmfdiag.representation.PapyrusDiagram; +import org.eclipse.papyrus.infra.nattable.representation.PapyrusSyncTable; +import org.eclipse.papyrus.infra.nattable.representation.PapyrusTable; import org.eclipse.swt.graphics.Image; @@ -53,16 +52,6 @@ public abstract class ViewPrototype { */ public static final ViewPrototype UNAVAILABLE_VIEW = new UnavailableViewPrototype("View", "View"); /** - * Singleton for unavailable views (diagrams) - */ - public static final ViewPrototype UNAVAILABLE_DIAGRAM = new UnavailableViewPrototype("Diagram", "Diagram"); - - /** - * Singleton for unavailable views (tables) - */ - public static final ViewPrototype UNAVAILABLE_TABLE = new UnavailableViewPrototype("Table", "Table"); - - /** * ID of the extension point for Papyrus diagrams */ protected static final String EXTENSION_ID = "org.eclipse.papyrus.infra.viewpoints.policy.viewType"; @@ -99,17 +88,6 @@ public abstract class ViewPrototype { } /** - * Determines whether the given configuration element applies on a natural view - * - * @param config - * The configuration element - * @return <code>true</code> if the configuration applies on a natural view - */ - public static boolean isNatural(PapyrusView config) { - return config.getName() == null && config.getIcon() == null; - } - - /** * Determines whether the given object is a supported view object * * @param object @@ -126,30 +104,22 @@ public abstract class ViewPrototype { } /** - * Gets the prototype for the given configuration element + * Gets the prototype for the given representationKind element * * @param config - * The configuration element + * The representationKind element * @return The prototype */ - public static ViewPrototype get(PapyrusView config) { + public static ViewPrototype get(PapyrusRepresentationKind representationKind) { for (IViewTypeHelper helper : HELPERS) { - if (helper.isSupported(config.eClass())) { - ViewPrototype proto = helper.getPrototypeFor(config); + if (helper.isSupported(representationKind.eClass())) { + ViewPrototype proto = helper.getPrototypeFor(representationKind); if (proto != null) { return proto; } } } - if (config instanceof PapyrusDiagram) { - return UNAVAILABLE_DIAGRAM; - } else if (config instanceof PapyrusTable) { - return UNAVAILABLE_TABLE; - } else if (config instanceof PapyrusSyncTable) { - return UNAVAILABLE_TABLE; - } else { - return UNAVAILABLE_VIEW; - } + return UNAVAILABLE_VIEW; } /** @@ -182,10 +152,10 @@ public abstract class ViewPrototype { * The root element * @return The prototype */ - public static ViewPrototype get(String implem, EObject owner, EObject root) { - PapyrusView view = PolicyChecker.getCurrent().getViewFrom(implem, owner, root); + public static ViewPrototype get(PolicyChecker policy, String implem, EObject owner, EObject root) { + PapyrusRepresentationKind view = policy.getRepresentationKindFrom(implem, owner, root); if (view == null) { - // The given implementation has been inhibited by the current viewpoint configuration + // The given implementation has been inhibited by the current viewpoint representationKind return UNAVAILABLE_VIEW; } return get(view); @@ -193,36 +163,27 @@ public abstract class ViewPrototype { /** - * The configuration element of this view + * The representation kind of this view */ - protected final PapyrusView configuration; + protected final PapyrusRepresentationKind representationKind; /** * Constructor. * - * @param configuration - * The configuration element - */ - protected ViewPrototype(PapyrusView configuration) { - this.configuration = configuration; - } - - /** - * Gets the configuration element for this view prototype - * - * @return The configuration element + * @param representationKind + * The representation kind element */ - public PapyrusView getConfiguration() { - return configuration; + protected ViewPrototype(PapyrusRepresentationKind representationKind) { + this.representationKind = representationKind; } /** - * Gets whether the represented view is the raw implementation + * Gets the representation kind for this view prototype * - * @return <code>true</code> if this is a natural view + * @return The representation kind */ - public boolean isNatural() { - return isNatural(configuration); + public PapyrusRepresentationKind getRepresentationKind() { + return representationKind; } /** @@ -242,7 +203,7 @@ public abstract class ViewPrototype { * @return The implementation ID */ public String getImplementation() { - return configuration.getImplementationID(); + return representationKind.getImplementationID(); } /** @@ -251,7 +212,7 @@ public abstract class ViewPrototype { * @return The label */ public String getLabel() { - return configuration.getName(); + return representationKind.getName(); } /** @@ -263,7 +224,7 @@ public abstract class ViewPrototype { StringBuilder builder = new StringBuilder(getLabel()); builder.append(" for "); boolean first = true; - for (ModelRule rule : configuration.getModelRules()) { + for (ModelRule rule : representationKind.getModelRules()) { if (rule.getStereotypes() != null && rule.getStereotypes().size() > 0) { for (EClass stereotype : rule.getStereotypes()) { if (!first) { @@ -291,8 +252,8 @@ public abstract class ViewPrototype { * @return The qualified name */ public String getQualifiedName() { - PapyrusViewpoint vp = (PapyrusViewpoint) configuration.eContainer(); - return vp.getName() + " :: " + getLabel(); + ArchitectureDescriptionLanguage lang = (ArchitectureDescriptionLanguage) representationKind.eContainer(); + return lang.getName() + " :: " + getLabel(); } /** @@ -301,7 +262,7 @@ public abstract class ViewPrototype { * @return The icon's URI */ public String getIconURI() { - return configuration.getIcon(); + return representationKind.getIcon(); } /** @@ -329,15 +290,6 @@ public abstract class ViewPrototype { } /** - * Gets the categories of this view prototype - * - * @return The prototype's categories - */ - public Collection<Category> getCategories() { - return configuration.getCategories(); - } - - /** * Determines whether the instances of this prototype can change owners * * @return <code>true</code> if the owner is reassignable @@ -410,7 +362,7 @@ public abstract class ViewPrototype { * @author Laurent Wouters */ public static class Comp implements Comparator<ViewPrototype> { - private static final Map<Class<? extends PapyrusView>, Integer> priorities = new HashMap<Class<? extends PapyrusView>, Integer>(); + private static final Map<Class<? extends PapyrusRepresentationKind>, Integer> priorities = new HashMap<Class<? extends PapyrusRepresentationKind>, Integer>(); { priorities.put(PapyrusDiagram.class, 1); priorities.put(PapyrusTable.class, 2); @@ -418,8 +370,8 @@ public abstract class ViewPrototype { } private static Integer getPriority(ViewPrototype proto) { - for (Map.Entry<Class<? extends PapyrusView>, Integer> entry : priorities.entrySet()) { - if (entry.getKey().isAssignableFrom(proto.configuration.getClass())) { + for (Map.Entry<Class<? extends PapyrusRepresentationKind>, Integer> entry : priorities.entrySet()) { + if (entry.getKey().isAssignableFrom(proto.representationKind.getClass())) { return entry.getValue(); } } diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototypeContentProvider.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototypeContentProvider.java index 6a90c6e5358..c0384d26743 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototypeContentProvider.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewPrototypeContentProvider.java @@ -1,301 +1,258 @@ -/*****************************************************************************
- * Copyright (c) 2014, 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:
- * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 485220
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.viewpoints.policy;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EPackage;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.resource.ImageRegistry;
-import org.eclipse.jface.resource.JFaceResources;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.infra.viewpoints.configuration.Category;
-import org.eclipse.papyrus.infra.viewpoints.configuration.ModelRule;
-import org.eclipse.papyrus.infra.viewpoints.configuration.OwningRule;
-import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusViewpoint;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Content provider of ViewPrototypes
- *
- * @author Laurent Wouters
- *
- */
-public class ViewPrototypeContentProvider implements ITreeContentProvider {
-
- private static ImageDescriptor loadImage(String uri) {
- URL url = null;
- try {
- url = new URL(uri);
- } catch (MalformedURLException e) {
- }
- return ImageDescriptor.createFromURL(url);
- }
-
- public static class LP extends LabelProvider {
- private static final String IMG_CATEGORY = "imageCategory"; //$NON-NLS-1$
- private static final String IMG_VIEWPOINT = "imageViewpoint"; //$NON-NLS-1$
- private static final String IMG_PROFILE = "imageProfile"; //$NON-NLS-1$
- private static final String IMG_MODEL = "imageModel"; //$NON-NLS-1$
- private static final String IMG_OWNER = "imageOwner"; //$NON-NLS-1$
-
- private ImageRegistry images = new ImageRegistry(JFaceResources.getResources());
-
- {
- images.put(IMG_CATEGORY, loadImage("platform:/plugin/org.eclipse.papyrus.infra.viewpoints.configuration.edit/icons/full/obj16/PapyrusView.png"));
- images.put(IMG_VIEWPOINT, loadImage("platform:/plugin/org.eclipse.papyrus.infra.viewpoints.configuration.edit/icons/full/obj16/PapyrusViewpoint.png"));
- images.put(IMG_PROFILE, loadImage("platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/Profile.gif"));
- images.put(IMG_MODEL, loadImage("platform:/plugin/org.eclipse.papyrus.infra.viewpoints.configuration.edit/icons/full/obj16/ModelRule.png"));
- images.put(IMG_OWNER, loadImage("platform:/plugin/org.eclipse.papyrus.infra.viewpoints.configuration.edit/icons/full/obj16/OwningRule.png"));
- }
-
- @Override
- public void dispose() {
- super.dispose();
-
- images.dispose();
- }
-
- @Override
- public String getText(Object element) {
- if (element instanceof Category) {
- return "Category " + ((Category) element).getName();
- }
- if (element instanceof ViewPrototype) {
- return ((ViewPrototype) element).getLabel();
- }
- if (element instanceof PapyrusViewpoint) {
- return "Available in viewpoint: " + ((PapyrusViewpoint) element).getName();
- }
- if (element instanceof EPackage) {
- return "Required profile: " + ((EPackage) element).getNsURI();
- }
- if (element instanceof ModelRule) {
- return getText((ModelRule) element);
- }
- if (element instanceof OwningRule) {
- return getText((OwningRule) element);
- }
- return element.toString();
- }
-
- private String getText(ModelRule rule) {
- StringBuilder builder = new StringBuilder("Possible root: ");
- boolean first = true;
- for (EClass ste : rule.getStereotypes()) {
- if (!first) {
- builder.append(", ");
- }
- builder.append("<<");
- builder.append(ste.getEPackage().getNsPrefix());
- builder.append("::");
- builder.append(ste.getName());
- builder.append(">>");
- first = false;
- }
- if (rule.getElement() != null) {
- if (!first) {
- builder.append(" ");
- }
- builder.append(rule.getElement().getEPackage().getNsPrefix());
- builder.append("::");
- builder.append(rule.getElement().getName());
- }
- return builder.toString();
- }
-
- private String getText(OwningRule rule) {
- StringBuilder builder = new StringBuilder("Possible owner: ");
- boolean first = true;
- for (EClass ste : rule.getStereotypes()) {
- if (!first) {
- builder.append(", ");
- }
- builder.append("<<");
- builder.append(ste.getEPackage().getNsPrefix());
- builder.append("::");
- builder.append(ste.getName());
- builder.append(">>");
- first = false;
- }
- if (rule.getElement() != null) {
- if (!first) {
- builder.append(" ");
- }
- builder.append(rule.getElement().getEPackage().getNsPrefix());
- builder.append("::");
- builder.append(rule.getElement().getName());
- }
- return builder.toString();
- }
-
- @Override
- public Image getImage(Object element) {
- if (element instanceof Category) {
- return images.get(IMG_CATEGORY);
- }
- if (element instanceof ViewPrototype) {
- return ((ViewPrototype) element).getIcon();
- }
- if (element instanceof PapyrusViewpoint) {
- return images.get(IMG_VIEWPOINT);
- }
- if (element instanceof EPackage) {
- return images.get(IMG_PROFILE);
- }
- if (element instanceof ModelRule) {
- return images.get(IMG_MODEL);
- }
- if (element instanceof OwningRule) {
- return images.get(IMG_OWNER);
- }
- return null;
- }
- }
-
- /**
- * The root of all views
- */
- public static final Object treeRoot = new Object();
-
- /**
- * The views
- */
- private Map<Category, List<ViewPrototype>> views;
-
- /**
- * The categories
- */
- private List<Category> categories;
-
- /**
- * Creates the provider
- *
- * @param views
- * The views to provide
- */
- public ViewPrototypeContentProvider() {
- this.views = new HashMap<Category, List<ViewPrototype>>();
- this.categories = new ArrayList<Category>();
- for (ViewPrototype view : PolicyChecker.getCurrent().getAllPrototypes()) {
- for (Category category : view.getCategories()) {
- if (!categories.contains(category)) {
- categories.add(category);
- views.put(category, new ArrayList<ViewPrototype>());
- }
- views.get(category).add(view);
- }
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- */
- public void dispose() {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- */
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
- */
- public Object[] getElements(Object inputElement) {
- return categories.toArray();
- }
-
-
- private Object[] getChildren(ViewPrototype view) {
- if (view.getConfiguration() == null) {
- return new String[0];
- }
- List<Object> data = new ArrayList<Object>();
- data.add(view.getConfiguration().eContainer());
- data.addAll(view.getConfiguration().getProfiles());
- data.addAll(view.getConfiguration().getModelRules());
- data.addAll(view.getConfiguration().getOwningRules());
- return data.toArray();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- */
- public Object[] getChildren(Object element) {
- if (element == treeRoot) {
- return categories.toArray();
- }
- if (element instanceof Category) {
- List<ViewPrototype> protos = new ArrayList<ViewPrototype>(views.get(element));
- Collections.sort(protos, new ViewPrototype.Comp());
- return protos.toArray();
- }
- if (element instanceof ViewPrototype) {
- return getChildren((ViewPrototype) element);
- }
- return new Object[0];
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- */
- public Object getParent(Object element) {
- if (element == treeRoot) {
- return null;
- }
- if (element instanceof Category) {
- return treeRoot;
- }
- return null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- */
- public boolean hasChildren(Object element) {
- if (element == treeRoot) {
- return true;
- }
- if (element instanceof Category) {
- return true;
- }
- if (element instanceof ViewPrototype) {
- return true;
- }
- return false;
- }
-}
+/***************************************************************************** + * Copyright (c) 2014, 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: + * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation + * Christian W. Damus - bug 485220 + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.viewpoints.policy; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.papyrus.infra.core.architecture.RepresentationKind; +import org.eclipse.papyrus.infra.core.architecture.merged.MergedArchitectureViewpoint; +import org.eclipse.papyrus.infra.architecture.representation.ModelRule; +import org.eclipse.papyrus.infra.architecture.representation.OwningRule; +import org.eclipse.swt.graphics.Image; + +/** + * Content provider of ViewPrototypes + * + * @author Laurent Wouters + * + */ +public class ViewPrototypeContentProvider implements ITreeContentProvider { + + private static ImageDescriptor loadImage(String uri) { + URL url = null; + try { + url = new URL(uri); + } catch (MalformedURLException e) { + } + return ImageDescriptor.createFromURL(url); + } + + public static class LP extends LabelProvider { + private static final String IMG_VIEWPOINT = "imageViewpoint"; //$NON-NLS-1$ + private static final String IMG_PROFILE = "imageProfile"; //$NON-NLS-1$ + private static final String IMG_MODEL = "imageModel"; //$NON-NLS-1$ + private static final String IMG_OWNER = "imageOwner"; //$NON-NLS-1$ + + private ImageRegistry images = new ImageRegistry(JFaceResources.getResources()); + + { + images.put(IMG_VIEWPOINT, loadImage("platform:/plugin/org.eclipse.papyrus.infra.core.architecture.edit/icons/full/obj16/MergedArchitectureViewpoint.gif")); + images.put(IMG_PROFILE, loadImage("platform:/plugin/org.eclipse.papyrus.infra.viewpoints.policy/icons/Profile.gif")); + images.put(IMG_MODEL, loadImage("platform:/plugin/org.eclipse.papyrus.infra.core.architecture.edit/icons/full/obj16/ModelRule.gif")); + images.put(IMG_OWNER, loadImage("platform:/plugin/org.eclipse.papyrus.infra.core.architecture.edit/icons/full/obj16/OwningRule.gif")); + } + + @Override + public void dispose() { + super.dispose(); + + images.dispose(); + } + + @Override + public String getText(Object element) { + if (element instanceof MergedArchitectureViewpoint) { + return "Viewpoint " + ((MergedArchitectureViewpoint) element).getName(); + } + if (element instanceof ViewPrototype) { + return ((ViewPrototype) element).getLabel(); + } + if (element instanceof EPackage) { + return "Required profile: " + ((EPackage) element).getNsURI(); + } + if (element instanceof ModelRule) { + return getText((ModelRule) element); + } + if (element instanceof OwningRule) { + return getText((OwningRule) element); + } + return element.toString(); + } + + private String getText(ModelRule rule) { + StringBuilder builder = new StringBuilder("Possible root: "); + boolean first = true; + for (EClass ste : rule.getStereotypes()) { + if (!first) { + builder.append(", "); + } + builder.append("<<"); + builder.append(ste.getEPackage().getNsPrefix()); + builder.append("::"); + builder.append(ste.getName()); + builder.append(">>"); + first = false; + } + if (rule.getElement() != null) { + if (!first) { + builder.append(" "); + } + builder.append(rule.getElement().getEPackage().getNsPrefix()); + builder.append("::"); + builder.append(rule.getElement().getName()); + } + return builder.toString(); + } + + private String getText(OwningRule rule) { + StringBuilder builder = new StringBuilder("Possible owner: "); + boolean first = true; + for (EClass ste : rule.getStereotypes()) { + if (!first) { + builder.append(", "); + } + builder.append("<<"); + builder.append(ste.getEPackage().getNsPrefix()); + builder.append("::"); + builder.append(ste.getName()); + builder.append(">>"); + first = false; + } + if (rule.getElement() != null) { + if (!first) { + builder.append(" "); + } + builder.append(rule.getElement().getEPackage().getNsPrefix()); + builder.append("::"); + builder.append(rule.getElement().getName()); + } + return builder.toString(); + } + + @Override + public Image getImage(Object element) { + if (element instanceof MergedArchitectureViewpoint) { + return images.get(IMG_VIEWPOINT); + } + if (element instanceof ViewPrototype) { + return ((ViewPrototype) element).getIcon(); + } + if (element instanceof EPackage) { + return images.get(IMG_PROFILE); + } + if (element instanceof ModelRule) { + return images.get(IMG_MODEL); + } + if (element instanceof OwningRule) { + return images.get(IMG_OWNER); + } + return null; + } + } + + + /** + * Creates the provider + * + * @param views + * The views to provide + */ + public ViewPrototypeContentProvider() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object inputElement) { + return (Object[])inputElement; + } + + + private Object[] getChildren(ViewPrototype view) { + if (view.getRepresentationKind() == null) { + return new String[0]; + } + List<Object> data = new ArrayList<Object>(); + data.add(view.getRepresentationKind().eContainer()); + data.addAll(view.getRepresentationKind().getLanguage().getProfiles()); + data.addAll(view.getRepresentationKind().getModelRules()); + data.addAll(view.getRepresentationKind().getOwningRules()); + return data.toArray(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + public Object[] getChildren(Object element) { + if (element instanceof MergedArchitectureViewpoint) { + MergedArchitectureViewpoint viewpoint = (MergedArchitectureViewpoint)element; + List<ViewPrototype> protos = new ArrayList<ViewPrototype>(); + for (RepresentationKind kind : viewpoint.getRepresentationKinds()) { + protos.add(ViewPrototype.get(kind)); + } + Collections.sort(protos, new ViewPrototype.Comp()); + return protos.toArray(); + } + if (element instanceof ViewPrototype) { + return getChildren((ViewPrototype) element); + } + return new Object[0]; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + public Object getParent(Object element) { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + public boolean hasChildren(Object element) { + if (element instanceof MergedArchitectureViewpoint) { + return true; + } + if (element instanceof ViewPrototype) { + return true; + } + return false; + } +} diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java index 8c2cfa094e2..7f78549c621 100755 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java +++ b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/ViewpointExplorer.java @@ -1,91 +1,91 @@ -/*****************************************************************************
- * 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:
- * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.viewpoints.policy;
-
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerSorter;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.part.ViewPart;
-
-/**
- * Eclipse view for the user to explore the current viewpoint
- *
- * @author Laurent Wouters
- *
- */
-public class ViewpointExplorer extends ViewPart {
-
- private TreeViewer tree;
-
- public ViewpointExplorer() {
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
- */
- @Override
- public void createPartControl(Composite parent) {
- GridLayout gridLayout = new GridLayout();
- gridLayout.numColumns = 1;
- parent.setLayout(gridLayout);
-
- Composite inner = new Composite(parent, SWT.NONE);
- inner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.FILL_VERTICAL));
- inner.setLayout(new FillLayout());
-
- tree = new TreeViewer(inner, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
- tree.setLabelProvider(new ViewPrototypeContentProvider.LP());
- tree.setSorter(getViewerSorter());
- tree.setContentProvider(new ViewPrototypeContentProvider());
- tree.setInput(ViewPrototypeContentProvider.treeRoot);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
- */
- @Override
- public void setFocus() {
-
- }
-
-
- /**
- * Gets the viewer sorter for this dialog
- *
- * @return A viewer sorter
- */
- private ViewerSorter getViewerSorter() {
- return new ViewerSorter() {
- @Override
- public int compare(Viewer viewer, Object e1, Object e2) {
- if (e1 instanceof ViewPrototype) {
- ViewPrototype b1 = (ViewPrototype) e1;
- ViewPrototype b2 = (ViewPrototype) e2;
- return b1.getFullLabel().compareTo(b2.getFullLabel());
- }
- return super.compare(viewer, e1, e2);
- }
- };
- }
-}
+/***************************************************************************** + * 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: + * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.infra.viewpoints.policy; + +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.ViewPart; + +/** + * Eclipse view for the user to explore the current viewpoint + * + * @author Laurent Wouters + * + */ +public class ViewpointExplorer extends ViewPart { + + private TreeViewer tree; + + public ViewpointExplorer() { + + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) + */ + @Override + public void createPartControl(Composite parent) { + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 1; + parent.setLayout(gridLayout); + + Composite inner = new Composite(parent, SWT.NONE); + inner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.FILL_VERTICAL)); + inner.setLayout(new FillLayout()); + + tree = new TreeViewer(inner, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + tree.setLabelProvider(new ViewPrototypeContentProvider.LP()); + tree.setSorter(getViewerSorter()); + tree.setContentProvider(new ViewPrototypeContentProvider()); + //tree.setInput(ViewPrototypeContentProvider.treeRoot); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.WorkbenchPart#setFocus() + */ + @Override + public void setFocus() { + + } + + + /** + * Gets the viewer sorter for this dialog + * + * @return A viewer sorter + */ + private ViewerSorter getViewerSorter() { + return new ViewerSorter() { + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + if (e1 instanceof ViewPrototype) { + ViewPrototype b1 = (ViewPrototype) e1; + ViewPrototype b2 = (ViewPrototype) e2; + return b1.getFullLabel().compareTo(b2.getFullLabel()); + } + return super.compare(viewer, e1, e2); + } + }; + } +} diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/WeightedConfiguration.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/WeightedConfiguration.java deleted file mode 100755 index 253099990e8..00000000000 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/WeightedConfiguration.java +++ /dev/null @@ -1,128 +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:
- * Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.viewpoints.policy;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.IExtensionRegistry;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusConfiguration;
-
-
-/**
- * Represents a Papyrus viewpoints configuration associated to a priority
- *
- * @author Laurent Wouters
- */
-public class WeightedConfiguration {
- /**
- * ID of the extension point defining the configurations
- */
- private static final String EXTENSION_ID = "org.eclipse.papyrus.infra.viewpoints.policy.custom";
-
- private String uri;
- private int priority;
- private PapyrusConfiguration config;
-
- /**
- * Gets the URI of the is configuration
- *
- * @return The configuration's URI
- */
- public String getURI() {
- return uri;
- }
-
- /**
- * Gets the Papyrus configuration represented by this object
- *
- * @return A Papyrus Configuration
- */
- public PapyrusConfiguration getConfiguration() {
- if (this.config == null) {
- this.config = PolicyChecker.loadConfigurationFrom(uri);
- }
- return this.config;
- }
-
- /**
- * Initializes the configuration from the given configuration element
- *
- * @param config
- * The extension point configuration element
- */
- private WeightedConfiguration(String plugin, IConfigurationElement config) {
- this.uri = config.getAttribute("file");
- if (!this.uri.startsWith(PreferenceConstants.P_CONF_PATH_SCHEME_PLUGIN_VALUE)) {
- this.uri = PreferenceConstants.P_CONF_PATH_SCHEME_PLUGIN_VALUE + plugin + "/" + this.uri;
- }
- try {
- this.priority = Integer.parseInt(config.getAttribute("priority"));
- } catch (NumberFormatException ex) {
- }
- }
-
-
- /**
- * Represents a comparator for weighted configurations
- *
- * @author Laurent Wouters
- */
- private static class Comparator implements java.util.Comparator<WeightedConfiguration>, Serializable {
- /**
- * Serial version
- */
- private static final long serialVersionUID = 9025582514350440832L;
-
- /**
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- public int compare(WeightedConfiguration o1, WeightedConfiguration o2) {
- return (o2.priority - o1.priority);
- }
- }
-
- /**
- * Gets the configuration with the top priority
- *
- * @return The appropriate configuration, or <code>null</code> if none was found
- */
- public static WeightedConfiguration getTopConfiguration() {
- IExtensionRegistry registry = Platform.getExtensionRegistry();
- IExtensionPoint point = registry.getExtensionPoint(EXTENSION_ID);
- IExtension[] extensions = point.getExtensions();
-
- List<WeightedConfiguration> configs = new ArrayList<WeightedConfiguration>();
- for (int i = 0; i != extensions.length; i++) {
- String plugin = extensions[i].getContributor().getName();
- IConfigurationElement[] elements = extensions[i].getConfigurationElements();
- for (int j = 0; j != elements.length; j++) {
- if (elements[j].getName().equals("configuration")) {
- configs.add(new WeightedConfiguration(plugin, elements[j]));
- }
- }
- }
- Collections.sort(configs, new Comparator());
- if (configs.size() == 0) {
- return null;
- }
- return configs.get(0);
- }
-}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/listener/IPolicyCheckerListener.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/listener/IPolicyCheckerListener.java deleted file mode 100644 index 676d0117247..00000000000 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/listener/IPolicyCheckerListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2015 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.viewpoints.policy.listener;
-
-import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
-
-/**
- * @since 1.2
- */
-public interface IPolicyCheckerListener {
-
- void policyCheckerChanged(PolicyChecker policyChecker);
-
-}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/listener/IPolicyCheckerListenerExtensionPoint.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/listener/IPolicyCheckerListenerExtensionPoint.java deleted file mode 100644 index 23391c4df46..00000000000 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/listener/IPolicyCheckerListenerExtensionPoint.java +++ /dev/null @@ -1,28 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2015 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.viewpoints.policy.listener;
-
-import org.eclipse.papyrus.infra.viewpoints.policy.Activator;
-
-/**
- * @since 1.2
- */
-public interface IPolicyCheckerListenerExtensionPoint {
-
-
- /** ID of the extension point */
- public final static String EXTENSION_POINT_ID = Activator.PLUGIN_ID + ".policycheckerlistener";
-
- public static final String LISTENER_CLASS = "listenerClass";
-}
diff --git a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/listener/PolicyCheckerNotifier.java b/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/listener/PolicyCheckerNotifier.java deleted file mode 100644 index bf9c372d65a..00000000000 --- a/plugins/infra/viewpoints/org.eclipse.papyrus.infra.viewpoints.policy/src/org/eclipse/papyrus/infra/viewpoints/policy/listener/PolicyCheckerNotifier.java +++ /dev/null @@ -1,67 +0,0 @@ -/*****************************************************************************
- * Copyright (c) 2015 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.viewpoints.policy.listener;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.papyrus.infra.viewpoints.policy.Activator;
-import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
-
-/**
- * @since 1.2
- */
-public class PolicyCheckerNotifier {
-
- private static PolicyCheckerNotifier notifier;
-
- private static List<IPolicyCheckerListener> listeners;
-
-
- public static synchronized PolicyCheckerNotifier getInstance() {
- if (notifier == null) {
- notifier = new PolicyCheckerNotifier();
- listeners = new ArrayList<IPolicyCheckerListener>();
- notifier.init();
- }
- return notifier;
- }
-
- public void clearListeners() {
- listeners.clear();
- }
-
- public void fire(PolicyChecker policyChecker) {
- for (IPolicyCheckerListener policyCheckerListener : listeners) {
- policyCheckerListener.policyCheckerChanged(policyChecker);
- }
- }
-
- void init() {
- IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(IPolicyCheckerListenerExtensionPoint.EXTENSION_POINT_ID);
- for (IConfigurationElement configurationElement : elements) {
- try {
- Object listenerClass = configurationElement.createExecutableExtension(IPolicyCheckerListenerExtensionPoint.LISTENER_CLASS);
- if (listenerClass instanceof IPolicyCheckerListener) {
- listeners.add((IPolicyCheckerListener) listenerClass);
- }
- } catch (CoreException e) {
- Activator.log.error(e);
- }
- }
- }
-}
|