Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Wouters2014-03-14 13:51:50 +0000
committerLaurent Wouters2014-03-14 13:54:22 +0000
commitf515b310417b386c79d9fbd2500c5373a7179aa7 (patch)
tree1785439bb2467282b35964ab71c18f8e2fffff38 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common
parent832ceab5e78772d2b483348f620de7b47a4c091f (diff)
downloadorg.eclipse.papyrus-f515b310417b386c79d9fbd2500c5373a7179aa7.tar.gz
org.eclipse.papyrus-f515b310417b386c79d9fbd2500c5373a7179aa7.tar.xz
org.eclipse.papyrus-f515b310417b386c79d9fbd2500c5373a7179aa7.zip
399860: Papyrus shall enable to customize the creation policy of views
https://bugs.eclipse.org/bugs/show_bug.cgi?id=399860 Signed-off-by: Laurent Wouters <laurent.wouters@cea.fr>
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF208
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/CreateBehavioredClassifierDiagramCommand.java311
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/SupplementCommand.java228
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java986
-rwxr-xr-xplugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/FilteringPaletteProvider.java306
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/LocalPaletteProvider.java8
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PapyrusPaletteService.java43
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PluginPaletteProvider.java38
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteApplicator.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLDefinitionPaletteFactory.java)108
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteDefinitionProfileInspector.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLRequiredProfileFactory.java)44
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteDefinitionVisitor.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AbstractXMLDefinitionPaletteFactory.java)17
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteDefinitionWalker.java (renamed from plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLDefinitionPaletteParser.java)73
12 files changed, 1337 insertions, 1033 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
index 0c971a7afbb..9f3ec2a2f01 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
@@ -1,105 +1,107 @@
-Manifest-Version: 1.0
-Export-Package: org.eclipse.papyrus.uml.diagram.common,
- org.eclipse.papyrus.uml.diagram.common.actions,
- org.eclipse.papyrus.uml.diagram.common.actions.handlers,
- org.eclipse.papyrus.uml.diagram.common.command.wrappers,
- org.eclipse.papyrus.uml.diagram.common.commands,
- org.eclipse.papyrus.uml.diagram.common.dialogs,
- org.eclipse.papyrus.uml.diagram.common.directedit,
- org.eclipse.papyrus.uml.diagram.common.dragtracker,
- org.eclipse.papyrus.uml.diagram.common.draw2d,
- org.eclipse.papyrus.uml.diagram.common.draw2d.anchors,
- org.eclipse.papyrus.uml.diagram.common.editparts,
- org.eclipse.papyrus.uml.diagram.common.editpolicies,
- org.eclipse.papyrus.uml.diagram.common.figure.edge,
- org.eclipse.papyrus.uml.diagram.common.figure.layout,
- org.eclipse.papyrus.uml.diagram.common.figure.node,
- org.eclipse.papyrus.uml.diagram.common.handlers,
- org.eclipse.papyrus.uml.diagram.common.helper,
- org.eclipse.papyrus.uml.diagram.common.ids,
- org.eclipse.papyrus.uml.diagram.common.layout,
- org.eclipse.papyrus.uml.diagram.common.listeners,
- org.eclipse.papyrus.uml.diagram.common.locator,
- org.eclipse.papyrus.uml.diagram.common.parser,
- org.eclipse.papyrus.uml.diagram.common.parser.assist,
- org.eclipse.papyrus.uml.diagram.common.parser.custom,
- org.eclipse.papyrus.uml.diagram.common.parser.lookup,
- org.eclipse.papyrus.uml.diagram.common.parser.packageimport,
- org.eclipse.papyrus.uml.diagram.common.parser.stereotype,
- org.eclipse.papyrus.uml.diagram.common.parser.structural,
- org.eclipse.papyrus.uml.diagram.common.part,
- org.eclipse.papyrus.uml.diagram.common.preferences,
- org.eclipse.papyrus.uml.diagram.common.providers,
- org.eclipse.papyrus.uml.diagram.common.providers.assistant,
- org.eclipse.papyrus.uml.diagram.common.resourceupdate,
- org.eclipse.papyrus.uml.diagram.common.service,
- org.eclipse.papyrus.uml.diagram.common.service.palette,
- org.eclipse.papyrus.uml.diagram.common.sheet,
- org.eclipse.papyrus.uml.diagram.common.ui.dialogs,
- org.eclipse.papyrus.uml.diagram.common.ui.helper,
- org.eclipse.papyrus.uml.diagram.common.util,
- org.eclipse.papyrus.uml.diagram.common.util.functions,
- org.eclipse.papyrus.uml.diagram.common.util.predicates
-Bundle-ActivationPolicy: lazy
-Bundle-ClassPath: .
-Bundle-Name: %pluginName
-Bundle-Localization: plugin
-Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
+Manifest-Version: 1.0
+Export-Package: org.eclipse.papyrus.uml.diagram.common,
+ org.eclipse.papyrus.uml.diagram.common.actions,
+ org.eclipse.papyrus.uml.diagram.common.actions.handlers,
+ org.eclipse.papyrus.uml.diagram.common.command.wrappers,
+ org.eclipse.papyrus.uml.diagram.common.commands,
+ org.eclipse.papyrus.uml.diagram.common.dialogs,
+ org.eclipse.papyrus.uml.diagram.common.directedit,
+ org.eclipse.papyrus.uml.diagram.common.dragtracker,
+ org.eclipse.papyrus.uml.diagram.common.draw2d,
+ org.eclipse.papyrus.uml.diagram.common.draw2d.anchors,
+ org.eclipse.papyrus.uml.diagram.common.editparts,
+ org.eclipse.papyrus.uml.diagram.common.editpolicies,
+ org.eclipse.papyrus.uml.diagram.common.figure.edge,
+ org.eclipse.papyrus.uml.diagram.common.figure.layout,
+ org.eclipse.papyrus.uml.diagram.common.figure.node,
+ org.eclipse.papyrus.uml.diagram.common.handlers,
+ org.eclipse.papyrus.uml.diagram.common.helper,
+ org.eclipse.papyrus.uml.diagram.common.ids,
+ org.eclipse.papyrus.uml.diagram.common.layout,
+ org.eclipse.papyrus.uml.diagram.common.listeners,
+ org.eclipse.papyrus.uml.diagram.common.locator,
+ org.eclipse.papyrus.uml.diagram.common.parser,
+ org.eclipse.papyrus.uml.diagram.common.parser.assist,
+ org.eclipse.papyrus.uml.diagram.common.parser.custom,
+ org.eclipse.papyrus.uml.diagram.common.parser.lookup,
+ org.eclipse.papyrus.uml.diagram.common.parser.packageimport,
+ org.eclipse.papyrus.uml.diagram.common.parser.stereotype,
+ org.eclipse.papyrus.uml.diagram.common.parser.structural,
+ org.eclipse.papyrus.uml.diagram.common.part,
+ org.eclipse.papyrus.uml.diagram.common.preferences,
+ org.eclipse.papyrus.uml.diagram.common.providers,
+ org.eclipse.papyrus.uml.diagram.common.providers.assistant,
+ org.eclipse.papyrus.uml.diagram.common.resourceupdate,
+ org.eclipse.papyrus.uml.diagram.common.service,
+ org.eclipse.papyrus.uml.diagram.common.service.palette,
+ org.eclipse.papyrus.uml.diagram.common.sheet,
+ org.eclipse.papyrus.uml.diagram.common.ui.dialogs,
+ org.eclipse.papyrus.uml.diagram.common.ui.helper,
+ org.eclipse.papyrus.uml.diagram.common.util,
+ org.eclipse.papyrus.uml.diagram.common.util.functions,
+ org.eclipse.papyrus.uml.diagram.common.util.predicates
+Bundle-ActivationPolicy: lazy
+Bundle-ClassPath: .
+Bundle-Name: %pluginName
+Bundle-Localization: plugin
+Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.diagram.ui.resources.editor,
- org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.1.0",
- org.eclipse.papyrus.extensionpoints.editors;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.tools.utils;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.2.0",
- org.eclipse.papyrus.uml.diagram.wizards;bundle-version="1.0.0",
- org.eclipse.papyrus.editor;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.diagram.ui.render;bundle-version="1.3.0",
- org.eclipse.ui,
- org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.diagram.ui.actions,
- org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="1.4.0",
- org.eclipse.core.expressions,
- org.eclipse.papyrus.infra.extendedtypes;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.navigation;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.diagram.navigation;bundle-version="1.0.0",
- org.eclipse.gmf.runtime.diagram.ui.printing,
- org.eclipse.gmf.runtime.diagram.ui.providers.ide,
- org.eclipse.papyrus.infra.services.decoration;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.resourceloading;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
- com.google.guava;bundle-version="11.0.0",
- org.eclipse.papyrus.uml.profile;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.0.0",
- org.eclipse.papyrus.uml.appearance;bundle-version="1.0.0",
- org.eclipse.uml2.uml.edit;bundle-version="4.0.0",
- org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
- org.eclipse.ui.ide;bundle-version="3.8.0",
- org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
- org.eclipse.jface,
- org.eclipse.papyrus.infra.emf.readonly;bundle-version="1.0.0",
- org.eclipse.papyrus.infra.services.localizer;bundle-version="1.0.0",
- org.apache.batik.dom.svg;bundle-version="[1.6.0,1.7.0)",
- org.w3c.dom.svg,
- org.apache.batik.css;bundle-version="[1.6.0,1.7.0)",
- org.apache.batik.util;bundle-version="[1.6.0,1.7.0)",
- org.apache.batik.dom;bundle-version="[1.6.0,1.7.0)",
- org.eclipse.core.databinding;bundle-version="1.4.1",
+Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.diagram.ui.resources.editor,
+ org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.1.0",
+ org.eclipse.papyrus.extensionpoints.editors;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.tools.utils;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.2.0",
+ org.eclipse.papyrus.uml.diagram.wizards;bundle-version="1.0.0",
+ org.eclipse.papyrus.editor;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.diagram.ui.render;bundle-version="1.3.0",
+ org.eclipse.ui,
+ org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.diagram.ui.actions,
+ org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="1.4.0",
+ org.eclipse.core.expressions,
+ org.eclipse.papyrus.infra.extendedtypes;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.edit;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.navigation;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.diagram.navigation;bundle-version="1.0.0",
+ org.eclipse.gmf.runtime.diagram.ui.printing,
+ org.eclipse.gmf.runtime.diagram.ui.providers.ide,
+ org.eclipse.papyrus.infra.services.decoration;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.resourceloading;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.tools;bundle-version="1.0.0",
+ com.google.guava;bundle-version="11.0.0",
+ org.eclipse.papyrus.uml.profile;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.0.0",
+ org.eclipse.papyrus.uml.appearance;bundle-version="1.0.0",
+ org.eclipse.uml2.uml.edit;bundle-version="4.0.0",
+ org.eclipse.papyrus.infra.core.log;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="1.0.0",
+ org.eclipse.ui.ide;bundle-version="3.8.0",
+ org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.widgets;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="1.0.0",
+ org.eclipse.jface,
+ org.eclipse.papyrus.infra.emf.readonly;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.services.localizer;bundle-version="1.0.0",
+ org.apache.batik.dom.svg;bundle-version="[1.6.0,1.7.0)",
+ org.w3c.dom.svg,
+ org.apache.batik.css;bundle-version="[1.6.0,1.7.0)",
+ org.apache.batik.util;bundle-version="[1.6.0,1.7.0)",
+ org.apache.batik.dom;bundle-version="[1.6.0,1.7.0)",
+ org.eclipse.core.databinding;bundle-version="1.4.1",
org.eclipse.gmf.tooling.runtime,
- org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0"
-Bundle-Vendor: %providerName
-Ant-Version: Apache Ant 1.7.0
-Bundle-Version: 1.0.0.qualifier
-Eclipse-BuddyPolicy: dependent
-Bundle-ManifestVersion: 2
-Bundle-Activator: org.eclipse.papyrus.uml.diagram.common.Activator
-Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.common;singleton:
- =true
-
+ org.eclipse.papyrus.emf.facet.custom.ui;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.core.pluginexplorer;bundle-version="1.0.0",
+ org.eclipse.papyrus.infra.viewpoints.policy;bundle-version="1.0.0"
+Bundle-Vendor: %providerName
+Ant-Version: Apache Ant 1.7.0
+Bundle-Version: 1.0.0.qualifier
+Eclipse-BuddyPolicy: dependent
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.eclipse.papyrus.uml.diagram.common.Activator
+Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.common;singleton:
+ =true
+
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/CreateBehavioredClassifierDiagramCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/CreateBehavioredClassifierDiagramCommand.java
index 892c01f65c7..9acd6744dd8 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/CreateBehavioredClassifierDiagramCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/CreateBehavioredClassifierDiagramCommand.java
@@ -1,168 +1,143 @@
-/*******************************************************************************
- * Copyright (c) 2010 AtosOrigin.
- * 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:
- * AtosOrigin - initial API and implementation
- *******************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.commands;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.papyrus.infra.gmfdiag.common.AbstractPapyrusGmfCreateDiagramCommandHandler;
-import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
-import org.eclipse.uml2.uml.Behavior;
-import org.eclipse.uml2.uml.BehavioredClassifier;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.UMLFactory;
-
-/**
- * Define a command to create a new Behavioral Diagram. This command is used by
- * all UI (toolbar, outline, creation wizards) to create a new Behavioral
- * Diagram. This class should be extended by behavioral diagram only.
- */
-public abstract class CreateBehavioredClassifierDiagramCommand extends AbstractPapyrusGmfCreateDiagramCommandHandler {
-
- private Behavior behavior = null;
-
- private String name = ""; //$NON-NLS-1$
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void initializeDiagram(EObject diagram) {
- if(diagram instanceof Diagram) {
- Diagram diag = (Diagram)diagram;
- if(behavior != null) {
- diag.setElement(behavior);
- createBehaviorView(diag);
- }
- diag.setName(getName());
- }
-
- }
-
- /**
- * Create the associated behavior
- *
- * @return
- */
- protected Behavior createBehavior() {
- Behavior newBehavior = (Behavior)UMLFactory.eINSTANCE.create(getBehaviorEClass());
-
- return newBehavior;
- }
-
- /**
- * Get the kind of behavior associated to the diagram
- *
- * @return the EClass of the behavior supposed to own the diagram.
- */
- protected abstract EClass getBehaviorEClass();
-
- /**
- * {@inheritDoc}
- */
- protected void initializeModel(EObject owner) {
-
- if(owner.eClass() == getBehaviorEClass()) {
- behavior = (Behavior)owner;
-
- } else {
- behavior = (Behavior)UMLFactory.eINSTANCE.create(getBehaviorEClass());
-
- if(owner instanceof BehavioredClassifier) {
- BehavioredClassifier behaviorClassifier = (BehavioredClassifier)owner;
- behaviorClassifier.getOwnedBehaviors().add(behavior);
-
- } else if(owner instanceof Package) {
- org.eclipse.uml2.uml.Package pack = (org.eclipse.uml2.uml.Package)owner;
- pack.getPackagedElements().add(behavior);
-
- }
- behavior.setName(NamedElementUtil.getName(behavior));
- }
- }
-
- private void createBehaviorView(Diagram diagram) {
- ViewService.getInstance().createView(Node.class, new EObjectAdapter(behavior), diagram, null, ViewUtil.APPEND, true, getPreferenceHint());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Diagram createDiagram(Resource diagramResource, EObject owner, String name) {
- Diagram diagram = null;
- if(owner instanceof org.eclipse.uml2.uml.Package) {
- diagram = ViewService.createDiagram(owner, getDiagramNotationID(), getPreferenceHint());
- } else if(owner instanceof BehavioredClassifier) {
- diagram = ViewService.createDiagram(((BehavioredClassifier)owner).getNearestPackage(), getDiagramNotationID(), getPreferenceHint());
- }
- // create diagram
- if(diagram != null) {
- setName(name);
-
- initializeModel(owner);
- initializeDiagram(diagram);
- diagramResource.getContents().add(diagram);
- }
- return diagram;
- }
-
- /**
- * Set the name of the diagram and its containing element
- *
- * @param newName
- */
- protected void setName(String newName) {
- if(newName == null || newName.equals(name)) {
- return;
- }
- name = newName;
- }
-
- protected String getName() {
- return name;
- }
-
- // @Override
- // protected void runAsTransaction(DiResourceSet diResourceSet, EObject
- // container, String name) {
- // if(name == null && container instanceof NamedElement) {
- // setName(((NamedElement)container).getName());
- // if(!"".equals(getName())) {
- // // initialize name with activity's name
- // name = openDiagramNameDialog(getName());
- // if(name == null) {
- // // operation canceled
- // return;
- // }
- // }
- // }
- // super.runAsTransaction(diResourceSet, container,
- // getDefaultDiagramName());
- // }
-
- /**
- * Check if the creation of this diagram is strongly attached to its parent
- * or if it can be reassigned after creation.
- *
- * @return true if parent can be reassigned
- */
- public boolean isParentReassignable() {
- // Behavioral diagrams describe their parent behavior and only this one.
- // They can not be moved to another parent.
- return false;
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2010 AtosOrigin.
+ * 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:
+ * AtosOrigin - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.commands;
+
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.papyrus.infra.gmfdiag.common.AbstractPapyrusGmfCreateDiagramCommandHandler;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.papyrus.uml.tools.utils.NamedElementUtil;
+import org.eclipse.uml2.uml.Behavior;
+import org.eclipse.uml2.uml.BehavioredClassifier;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.UMLFactory;
+
+/**
+ * Define a command to create a new Behavioral Diagram. This command is used by
+ * all UI (toolbar, outline, creation wizards) to create a new Behavioral
+ * Diagram. This class should be extended by behavioral diagram only.
+ */
+public abstract class CreateBehavioredClassifierDiagramCommand extends AbstractPapyrusGmfCreateDiagramCommandHandler {
+
+ private Behavior behavior = null;
+
+ private String name = ""; //$NON-NLS-1$
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void initializeDiagram(EObject diagram) {
+ if(diagram instanceof Diagram) {
+ Diagram diag = (Diagram)diagram;
+ if(behavior != null) {
+ diag.setElement(behavior);
+ createBehaviorView(diag);
+ }
+ diag.setName(getName());
+ }
+
+ }
+
+ /**
+ * Create the associated behavior
+ *
+ * @return
+ */
+ protected Behavior createBehavior() {
+ Behavior newBehavior = (Behavior)UMLFactory.eINSTANCE.create(getBehaviorEClass());
+
+ return newBehavior;
+ }
+
+ /**
+ * Get the kind of behavior associated to the diagram
+ *
+ * @return the EClass of the behavior supposed to own the diagram.
+ */
+ protected abstract EClass getBehaviorEClass();
+
+ /**
+ * {@inheritDoc}
+ */
+ protected void initializeModel(EObject owner) {
+
+ if(owner.eClass() == getBehaviorEClass()) {
+ behavior = (Behavior)owner;
+
+ } else {
+ behavior = (Behavior)UMLFactory.eINSTANCE.create(getBehaviorEClass());
+
+ if(owner instanceof BehavioredClassifier) {
+ BehavioredClassifier behaviorClassifier = (BehavioredClassifier)owner;
+ behaviorClassifier.getOwnedBehaviors().add(behavior);
+
+ } else if(owner instanceof Package) {
+ org.eclipse.uml2.uml.Package pack = (org.eclipse.uml2.uml.Package)owner;
+ pack.getPackagedElements().add(behavior);
+
+ }
+ behavior.setName(NamedElementUtil.getName(behavior));
+ }
+ }
+
+ private void createBehaviorView(Diagram diagram) {
+ ViewService.getInstance().createView(Node.class, new EObjectAdapter(behavior), diagram, null, ViewUtil.APPEND, true, getPreferenceHint());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Diagram doCreateDiagram(Resource diagramResource, EObject owner, EObject element, ViewPrototype prototype, String name) {
+ Diagram diagram = null;
+ if(element instanceof org.eclipse.uml2.uml.Package) {
+ diagram = ViewService.createDiagram(element, getDiagramNotationID(), getPreferenceHint());
+ } else if(element instanceof BehavioredClassifier) {
+ diagram = ViewService.createDiagram(((BehavioredClassifier)element).getNearestPackage(), getDiagramNotationID(), getPreferenceHint());
+ }
+ // create diagram
+ if(diagram != null) {
+ setName(name);
+ diagram.setElement(element);
+ DiagramUtils.setOwner(diagram, owner);
+ if (!prototype.isNatural())
+ DiagramUtils.setPrototype(diagram, prototype);
+ initializeModel(element);
+ initializeDiagram(diagram);
+ diagramResource.getContents().add(diagram);
+ }
+ return diagram;
+ }
+
+ /**
+ * Set the name of the diagram and its containing element
+ *
+ * @param newName
+ */
+ protected void setName(String newName) {
+ if(newName == null || newName.equals(name)) {
+ return;
+ }
+ name = newName;
+ }
+
+ protected String getName() {
+ return name;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/SupplementCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/SupplementCommand.java
index 475d61a2eb0..bb59b7aa757 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/SupplementCommand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/SupplementCommand.java
@@ -1,112 +1,116 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.commands;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
-
-/**
- * This class is used to supplement a gmf connection command.
- *
- * @author Patrick Tessier
- */
-public abstract class SupplementCommand {
-
- private EObject container;
-
- private final EObject source;
-
- private final EObject target;
-
- /**
- * the supplement command has the same parameter as connection create
- * command of gmf command
- *
- * @param container
- * the container of the link
- * @param source
- * the source of the link
- *
- * @param target
- * the target of the link
- */
- public SupplementCommand(EObject container, EObject source, EObject target) {
- super();
- this.container = container;
- this.source = source;
- this.target = target;
- }
-
- /**
- * this is the same fucntionnality as {@link IUndoableOperation}
- *
- * @return true if the command ca be executed
- */
- // @unused
- public abstract boolean canExecute();
-
- /**
- * Creates the request to configure the new element.
- *
- * @see EditElementCommand
- * @return the request
- */
- // @unused
- protected abstract ConfigureRequest createConfigureRequest(ConfigureRequest request);
-
- /**
- * this is the method tat realize the execution of the command
- *
- * @param newElement
- * the new element ro configure
- * @return the new element
- */
- public abstract EObject doDefaultElementCreation(TransactionalEditingDomain domain, EObject newElement);
-
- /**
- * use to obtain the container of the link
- *
- * @return the container of the link
- */
- public EObject getContainer() {
- return container;
- }
-
- /**
- * use to obtain the source of the link
- *
- * @return the source of the link
- */
- public EObject getSource() {
- return source;
- }
-
- /**
- * use to obtain the target of the link
- *
- * @return the target of the link
- */
- public EObject getTarget() {
- return target;
- }
-
- /**
- * use to set the container of the link
- */
- // @unused
- public void setContainer(EObject container) {
- this.container = container;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.commands;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.notation.Diagram;
+
+/**
+ * This class is used to supplement a gmf connection command.
+ *
+ * @author Patrick Tessier
+ */
+public abstract class SupplementCommand {
+
+ private EObject container;
+
+ private final EObject source;
+
+ private final EObject target;
+
+ protected final Diagram diagram;
+
+ /**
+ * the supplement command has the same parameter as connection create
+ * command of gmf command
+ *
+ * @param container
+ * the container of the link
+ * @param source
+ * the source of the link
+ *
+ * @param target
+ * the target of the link
+ */
+ public SupplementCommand(EObject container, EObject source, EObject target, Diagram diagram) {
+ super();
+ this.container = container;
+ this.source = source;
+ this.target = target;
+ this.diagram = diagram;
+ }
+
+ /**
+ * this is the same fucntionnality as {@link IUndoableOperation}
+ *
+ * @return true if the command ca be executed
+ */
+ // @unused
+ public abstract boolean canExecute();
+
+ /**
+ * Creates the request to configure the new element.
+ *
+ * @see EditElementCommand
+ * @return the request
+ */
+ // @unused
+ protected abstract ConfigureRequest createConfigureRequest(ConfigureRequest request);
+
+ /**
+ * this is the method tat realize the execution of the command
+ *
+ * @param newElement
+ * the new element ro configure
+ * @return the new element
+ */
+ public abstract EObject doDefaultElementCreation(TransactionalEditingDomain domain, EObject newElement);
+
+ /**
+ * use to obtain the container of the link
+ *
+ * @return the container of the link
+ */
+ public EObject getContainer() {
+ return container;
+ }
+
+ /**
+ * use to obtain the source of the link
+ *
+ * @return the source of the link
+ */
+ public EObject getSource() {
+ return source;
+ }
+
+ /**
+ * use to obtain the target of the link
+ *
+ * @return the target of the link
+ */
+ public EObject getTarget() {
+ return target;
+ }
+
+ /**
+ * use to set the container of the link
+ */
+ // @unused
+ public void setContainer(EObject container) {
+ this.container = container;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java
index 0038328f8ca..eb1a09af05b 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/part/PaletteUtil.java
@@ -1,498 +1,510 @@
-/*****************************************************************************
- * Copyright (c) 2009 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:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.uml.diagram.common.part;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.Tool;
-import org.eclipse.gef.palette.PaletteContainer;
-import org.eclipse.gef.palette.PaletteEntry;
-import org.eclipse.gef.palette.PaletteRoot;
-import org.eclipse.gef.palette.ToolEntry;
-import org.eclipse.gmf.runtime.common.core.service.IProvider;
-import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
-import org.eclipse.gmf.runtime.diagram.ui.internal.services.palette.ContributeToPaletteOperation;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
-import org.eclipse.gmf.runtime.diagram.ui.services.palette.IPaletteProvider;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.emf.type.core.SpecializationType;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.papyrus.infra.core.utils.PapyrusTrace;
-import org.eclipse.papyrus.uml.diagram.common.Activator;
-import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeConnectionTool;
-import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeCreationTool;
-import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
-import org.eclipse.papyrus.uml.diagram.common.service.IProfileDependantPaletteProvider;
-import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
-import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ProviderDescriptor;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction;
-import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IMemento;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Profile;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * Utility class for palette.
- */
-public class PaletteUtil {
-
- /**
- * Returns the parent container by its ID
- *
- * @param entry
- * the palette container for which parent container is looked
- * @param parentID
- * the id of the parent container
- * @return the parent
- */
- public static PaletteContainer getContainerByID(PaletteContainer container, String parentID) {
- // check this element is the searched parent;
- if(parentID.equals(container.getId())) {
- return container;
- }
-
- // element is not the parent. Look its children
- Iterator<PaletteContainer> it = getDirectChildContainers(container).iterator();
- while(it.hasNext()) {
- PaletteContainer tmp = getContainerByID(it.next(), parentID);
- if(tmp != null) {
- return tmp;
- }
- }
- return null;
- }
-
- /**
- * Returns the type of metaclasses created by the toolentry
- *
- * @param entry
- * the entry for which metaclass created is searched
- * @return the type of metaclasses created by the toolentry or <code>null</code>.
- */
- public static EClass getToolMetaclass(ToolEntry entry) {
- Tool tool = entry.createTool();
- List<IElementType> types = null;
- if(tool instanceof AspectUnspecifiedTypeCreationTool) {
- types = ((AspectUnspecifiedTypeCreationTool)tool).getElementTypes();
- } else if(tool instanceof AspectUnspecifiedTypeConnectionTool) {
- types = ((AspectUnspecifiedTypeConnectionTool)tool).getElementTypes();
- }
- if(types != null && types.size() > 0) {
- IElementType type = types.get(0);
-
- if(type instanceof SpecializationType) {
- type = ((SpecializationType)type).getSpecializedTypes()[0];
- }
- return type.getEClass();
- }
- return null;
- }
-
- /**
- * Returns the parent container by its ID
- *
- * @param entry
- * the palette entry for which parent container is looked
- * @param parentID
- * the id of the parent container
- * @return the parent
- */
- public static PaletteContainer getContainerByID(PaletteEntry entry, String parentID) {
- // retrieve the root
- PaletteContainer root = getRoot(entry);
- return getContainerByID(root, parentID);
- }
-
- /**
- * Return the child containers directly contained by the specified container
- *
- * @param container
- * the container to look in.
- * @return the list of directly contained elements
- */
- @SuppressWarnings("unchecked")
- public static List<PaletteContainer> getDirectChildContainers(PaletteContainer container) {
- List<PaletteContainer> containers = new ArrayList<PaletteContainer>();
- Iterator<PaletteEntry> it = container.getChildren().iterator();
- while(it.hasNext()) {
- PaletteEntry entry = it.next();
- if(entry instanceof PaletteContainer) {
- containers.add((PaletteContainer)entry);
- }
- }
- return containers;
- }
-
- /**
- * Retrieves the root element for the given container
- *
- * @param container
- * the container for which the root is searched
- * @return the root of the container
- */
- public static PaletteContainer getRoot(PaletteContainer container) {
- // if container has a parent, returns it.
- if(container.getParent() != null) {
- return getRoot(container.getParent());
- }
- // else, root element is the container itself.
- return container;
- }
-
- /**
- * Retrieves the root element for the given palette entry
- *
- * @param container
- * the container for which the root is searched
- * @return the root of the container
- */
- public static PaletteContainer getRoot(PaletteEntry entry) {
- return getRoot(entry.getParent());
- }
-
- /**
- * Default constructor. Should never be used, as method are static in this
- * class.
- */
- // @unused
- private PaletteUtil() {
-
- }
-
- /**
- * return tool entries for the given {@link PaletteContainer} and its
- * sub-containers
- *
- * @param container
- * the container that contains the ToolEntries
- * @return the list of tool entries or an empty list
- */
- public static List<ToolEntry> getAllToolEntries(PaletteContainer container) {
- final List<ToolEntry> entries = new ArrayList<ToolEntry>();
- Iterator<PaletteEntry> it = container.getChildren().iterator();
- while(it.hasNext()) {
- PaletteEntry entry = it.next();
- if(entry instanceof ToolEntry) {
- entries.add((ToolEntry)entry);
- }
- if(entry instanceof PaletteContainer) {
- entries.addAll(getAllToolEntries((PaletteContainer)entry));
- }
- }
- return entries;
- }
-
- /**
- * Looks for the memento with the correct id from the root momento
- *
- * @param rootMemento
- * the root memento from which the memento is searched
- * @param id
- * the id of the memento to search
- * @return the memento with the given ID or <code>null</code> if no memento
- * was found
- */
- // @unused
- public static IMemento getMemento(IMemento rootMemento, String id) {
- IMemento memento = null;
- memento = rootMemento.getChild(id);
- return memento;
- }
-
- /**
- * Return all entries from a palette
- *
- * @param paletteRoot
- * the root from which tools are retrieved
- * @return the list of entries
- */
- public static List<PaletteEntry> getAllEntries(PaletteContainer container) {
- List<PaletteEntry> elements = new ArrayList<PaletteEntry>();
- for(Object object : container.getChildren()) {
- if(object instanceof PaletteContainer) {
- elements.add((PaletteContainer)object);
- elements.addAll(getAllEntries((PaletteContainer)object));
- } else if(object instanceof ToolEntry) {
- elements.add((ToolEntry)object);
- }
- }
- return elements;
- }
-
- /**
- * Returns all available entries for the given editor ID
- *
- * @param editorID
- * the editor to be contributed
- * @param priority
- * the priority max for the entries
- * @return the set of available entries
- */
- public static Set<? extends PaletteEntry> getAvailableEntries(IEditorPart part, ProviderPriority priority) {
- Set<? extends PaletteEntry> entries = new HashSet<PaletteEntry>();
-
- // retrieve all provider for the given editor ID
- PaletteRoot root = new PaletteRoot();
- List<? extends PapyrusPaletteService.ProviderDescriptor> providers = (List<? extends ProviderDescriptor>)PapyrusPaletteService.getInstance().getProviders();
- ContributeToPaletteOperation operation = new ContributeToPaletteOperation(part, part.getEditorInput(), root, new HashMap<Object, Object>());
-
- // generate for each provider, according to priority
- @SuppressWarnings("unchecked")
- List<PapyrusPaletteService.ProviderDescriptor> providerList = (List<PapyrusPaletteService.ProviderDescriptor>)PapyrusPaletteService.getInstance().getProviders();
- for(PapyrusPaletteService.ProviderDescriptor descriptor : providerList) {
- int compare = descriptor.getPriority().compareTo(priority);
- if(compare < 0) {
- if(descriptor.providesWithVisibility(operation)) {
- ((IPaletteProvider)descriptor.getProvider()).contributeToPalette(part, part.getEditorInput(), root, new HashMap<Object, Object>());
- }
- }
- }
- return entries;
- }
-
- /**
- * Returns all available entries for the given editor ID
- *
- * @param editorID
- * the editor to be contributed
- * @param priority
- * the priority max for the entries
- * @return the set of available entries
- */
- public static Map<String, PaletteEntry> getAvailableEntriesSet(IEditorPart part, ProviderPriority priority) {
- Map<String, PaletteEntry> entries = new HashMap<String, PaletteEntry>();
-
- // retrieve all provider for the given editor ID
- PaletteRoot root = new PaletteRoot();
- List<? extends PapyrusPaletteService.ProviderDescriptor> providers = (List<? extends ProviderDescriptor>)PapyrusPaletteService.getInstance().getProviders();
- ContributeToPaletteOperation operation = new ContributeToPaletteOperation(part, part.getEditorInput(), root, entries);
-
- // generate for each provider, according to priority
- @SuppressWarnings("unchecked")
- List<PapyrusPaletteService.ProviderDescriptor> providerList = (List<PapyrusPaletteService.ProviderDescriptor>)PapyrusPaletteService.getInstance().getProviders();
- for(PapyrusPaletteService.ProviderDescriptor descriptor : providerList) {
- int compare = descriptor.getPriority().compareTo(priority);
- if(compare <= 0) {
- if(descriptor.providesWithVisibility(operation)) {
- ((IPaletteProvider)descriptor.getProvider()).contributeToPalette(part, part.getEditorInput(), root, entries);
- }
- }
- }
- return entries;
- }
-
- /**
- * Returns the list of stereotypes String from a serialize string form
- *
- * @param serializedForm
- * the serialized form of the list of stereotypes
- * @return the list of stereotypes String from a serialize string form
- */
- public static List<String> getStereotypeListFromString(String serializedForm) {
- StringTokenizer tokenizer = new StringTokenizer(serializedForm, ",");
- List<String> list = new ArrayList<String>();
- while(tokenizer.hasMoreElements()) {
- list.add(tokenizer.nextToken().trim());
- }
- return list;
- }
-
- /**
- * Returns the list of stereotypes String under a serialized form
- *
- * @param list
- * the list of stereotypes to serialize
- * @return the list of stereotypes String under a serialized form
- */
- public static String getSerializedStereotypeList(Collection<String> stereotypes) {
- return convertToCommaSeparatedRepresentation(stereotypes);
- }
-
- /**
- * Returns the name of the profile from the given stereotype qualified Name
- *
- * @param stereotypeName
- * the name of the stereotype to parse
- * @return the qualified name of the profile from the given stereotype
- * qualified Name
- */
- public static String findProfileNameFromStereotypeName(String stereotypeName) {
- return stereotypeName.substring(0, stereotypeName.lastIndexOf(NamedElement.SEPARATOR));
- }
-
- /**
- * Returns the list of profile Qualified Names String under a serialized
- * form
- *
- * @param list
- * the list of profiles to serialize
- * @return the list of profiles String under a serialized form
- */
- public static String getSerializedProfileList(Collection<String> profiles) {
- return convertToCommaSeparatedRepresentation(profiles);
- }
-
- public static String convertToCommaSeparatedRepresentation(Collection objects) {
- return convertToFlatRepresentation(objects, ",");
- }
+/*****************************************************************************
+ * Copyright (c) 2009 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.part;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.Tool;
+import org.eclipse.gef.palette.PaletteContainer;
+import org.eclipse.gef.palette.PaletteEntry;
+import org.eclipse.gef.palette.PaletteRoot;
+import org.eclipse.gef.palette.ToolEntry;
+import org.eclipse.gmf.runtime.common.core.service.IProvider;
+import org.eclipse.gmf.runtime.common.core.service.ProviderPriority;
+import org.eclipse.gmf.runtime.diagram.ui.internal.services.palette.ContributeToPaletteOperation;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
+import org.eclipse.gmf.runtime.diagram.ui.services.palette.IPaletteProvider;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.SpecializationType;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.core.utils.PapyrusTrace;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeConnectionTool;
+import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeCreationTool;
+import org.eclipse.papyrus.uml.diagram.common.service.IPapyrusPaletteConstant;
+import org.eclipse.papyrus.uml.diagram.common.service.IProfileDependantPaletteProvider;
+import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
+import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService.ProviderDescriptor;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.AspectToolService;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectAction;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IAspectActionProvider;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IPostAction;
+import org.eclipse.papyrus.uml.diagram.common.service.palette.IPreAction;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Profile;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Utility class for palette.
+ */
+public class PaletteUtil {
+
+ /**
+ * Returns the parent container by its ID
+ *
+ * @param entry
+ * the palette container for which parent container is looked
+ * @param parentID
+ * the id of the parent container
+ * @return the parent
+ */
+ public static PaletteContainer getContainerByID(PaletteContainer container, String parentID) {
+ // check this element is the searched parent;
+ if(parentID.equals(container.getId())) {
+ return container;
+ }
+
+ // element is not the parent. Look its children
+ Iterator<PaletteContainer> it = getDirectChildContainers(container).iterator();
+ while(it.hasNext()) {
+ PaletteContainer tmp = getContainerByID(it.next(), parentID);
+ if(tmp != null) {
+ return tmp;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the type of metaclasses created by the toolentry
+ *
+ * @param entry
+ * the entry for which metaclass created is searched
+ * @return the type of metaclasses created by the toolentry or <code>null</code>.
+ */
+ public static EClass getToolMetaclass(ToolEntry entry) {
+ Tool tool = entry.createTool();
+ List<IElementType> types = null;
+ if(tool instanceof AspectUnspecifiedTypeCreationTool) {
+ types = ((AspectUnspecifiedTypeCreationTool)tool).getElementTypes();
+ } else if(tool instanceof AspectUnspecifiedTypeConnectionTool) {
+ types = ((AspectUnspecifiedTypeConnectionTool)tool).getElementTypes();
+ }
+ if(types != null && types.size() > 0) {
+ IElementType type = types.get(0);
+
+ if(type instanceof SpecializationType) {
+ type = ((SpecializationType)type).getSpecializedTypes()[0];
+ }
+ return type.getEClass();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the parent container by its ID
+ *
+ * @param entry
+ * the palette entry for which parent container is looked
+ * @param parentID
+ * the id of the parent container
+ * @return the parent
+ */
+ public static PaletteContainer getContainerByID(PaletteEntry entry, String parentID) {
+ // retrieve the root
+ PaletteContainer root = getRoot(entry);
+ return getContainerByID(root, parentID);
+ }
+
+ /**
+ * Return the child containers directly contained by the specified container
+ *
+ * @param container
+ * the container to look in.
+ * @return the list of directly contained elements
+ */
+ @SuppressWarnings("unchecked")
+ public static List<PaletteContainer> getDirectChildContainers(PaletteContainer container) {
+ List<PaletteContainer> containers = new ArrayList<PaletteContainer>();
+ Iterator<PaletteEntry> it = container.getChildren().iterator();
+ while(it.hasNext()) {
+ PaletteEntry entry = it.next();
+ if(entry instanceof PaletteContainer) {
+ containers.add((PaletteContainer)entry);
+ }
+ }
+ return containers;
+ }
+
+ /**
+ * Retrieves the root element for the given container
+ *
+ * @param container
+ * the container for which the root is searched
+ * @return the root of the container
+ */
+ public static PaletteContainer getRoot(PaletteContainer container) {
+ // if container has a parent, returns it.
+ if(container.getParent() != null) {
+ return getRoot(container.getParent());
+ }
+ // else, root element is the container itself.
+ return container;
+ }
+
+ /**
+ * Retrieves the root element for the given palette entry
+ *
+ * @param container
+ * the container for which the root is searched
+ * @return the root of the container
+ */
+ public static PaletteContainer getRoot(PaletteEntry entry) {
+ return getRoot(entry.getParent());
+ }
+
+ /**
+ * Default constructor. Should never be used, as method are static in this
+ * class.
+ */
+ // @unused
+ private PaletteUtil() {
+
+ }
+
+ /**
+ * return tool entries for the given {@link PaletteContainer} and its
+ * sub-containers
+ *
+ * @param container
+ * the container that contains the ToolEntries
+ * @return the list of tool entries or an empty list
+ */
+ public static List<ToolEntry> getAllToolEntries(PaletteContainer container) {
+ final List<ToolEntry> entries = new ArrayList<ToolEntry>();
+ Iterator<PaletteEntry> it = container.getChildren().iterator();
+ while(it.hasNext()) {
+ PaletteEntry entry = it.next();
+ if(entry instanceof ToolEntry) {
+ entries.add((ToolEntry)entry);
+ }
+ if(entry instanceof PaletteContainer) {
+ entries.addAll(getAllToolEntries((PaletteContainer)entry));
+ }
+ }
+ return entries;
+ }
+
+ /**
+ * Looks for the memento with the correct id from the root momento
+ *
+ * @param rootMemento
+ * the root memento from which the memento is searched
+ * @param id
+ * the id of the memento to search
+ * @return the memento with the given ID or <code>null</code> if no memento
+ * was found
+ */
+ // @unused
+ public static IMemento getMemento(IMemento rootMemento, String id) {
+ IMemento memento = null;
+ memento = rootMemento.getChild(id);
+ return memento;
+ }
+
+ /**
+ * Return all entries from a palette
+ *
+ * @param paletteRoot
+ * the root from which tools are retrieved
+ * @return the list of entries
+ */
+ public static List<PaletteEntry> getAllEntries(PaletteContainer container) {
+ List<PaletteEntry> elements = new ArrayList<PaletteEntry>();
+ for(Object object : container.getChildren()) {
+ if(object instanceof PaletteContainer) {
+ elements.add((PaletteContainer)object);
+ elements.addAll(getAllEntries((PaletteContainer)object));
+ } else if(object instanceof ToolEntry) {
+ elements.add((ToolEntry)object);
+ }
+ }
+ return elements;
+ }
+
+ /**
+ * Returns all available entries for the given editor ID
+ *
+ * @param editorID
+ * the editor to be contributed
+ * @param priority
+ * the priority max for the entries
+ * @return the set of available entries
+ */
+ public static Set<? extends PaletteEntry> getAvailableEntries(IEditorPart part, ProviderPriority priority) {
+ Set<? extends PaletteEntry> entries = new HashSet<PaletteEntry>();
+
+ // retrieve all provider for the given editor ID
+ PaletteRoot root = new PaletteRoot();
+ List<? extends PapyrusPaletteService.ProviderDescriptor> providers = (List<? extends ProviderDescriptor>)PapyrusPaletteService.getInstance().getProviders();
+ ContributeToPaletteOperation operation = new ContributeToPaletteOperation(part, part.getEditorInput(), root, new HashMap<Object, Object>());
+
+ // generate for each provider, according to priority
+ @SuppressWarnings("unchecked")
+ List<PapyrusPaletteService.ProviderDescriptor> providerList = (List<PapyrusPaletteService.ProviderDescriptor>)PapyrusPaletteService.getInstance().getProviders();
+ for(PapyrusPaletteService.ProviderDescriptor descriptor : providerList) {
+ int compare = descriptor.getPriority().compareTo(priority);
+ if(compare < 0) {
+ if(descriptor.providesWithVisibility(operation)) {
+ ((IPaletteProvider)descriptor.getProvider()).contributeToPalette(part, part.getEditorInput(), root, new HashMap<Object, Object>());
+ }
+ }
+ }
+ return entries;
+ }
+
+ /**
+ * Returns all available entries for the given editor ID
+ *
+ * @param editorID
+ * the editor to be contributed
+ * @param priority
+ * the priority max for the entries
+ * @return the set of available entries
+ */
+ public static Map<String, PaletteEntry> getAvailableEntriesSet(IEditorPart part, ProviderPriority priority) {
+ Map<String, PaletteEntry> entries = new HashMap<String, PaletteEntry>();
+
+ // retrieve all provider for the given editor ID
+ PaletteRoot root = new PaletteRoot();
+ List<? extends PapyrusPaletteService.ProviderDescriptor> providers = (List<? extends ProviderDescriptor>)PapyrusPaletteService.getInstance().getProviders();
+ ContributeToPaletteOperation operation = new ContributeToPaletteOperation(part, part.getEditorInput(), root, entries);
+
+ // generate for each provider, according to priority
+ @SuppressWarnings("unchecked")
+ List<PapyrusPaletteService.ProviderDescriptor> providerList = (List<PapyrusPaletteService.ProviderDescriptor>)PapyrusPaletteService.getInstance().getProviders();
+ for(PapyrusPaletteService.ProviderDescriptor descriptor : providerList) {
+ int compare = descriptor.getPriority().compareTo(priority);
+ if(compare <= 0) {
+ if(descriptor.providesWithVisibility(operation)) {
+ ((IPaletteProvider)descriptor.getProvider()).contributeToPalette(part, part.getEditorInput(), root, entries);
+ }
+ }
+ }
+ return entries;
+ }
+
+ /**
+ * Returns the list of stereotypes String from a serialize string form
+ *
+ * @param serializedForm
+ * the serialized form of the list of stereotypes
+ * @return the list of stereotypes String from a serialize string form
+ */
+ public static List<String> getStereotypeListFromString(String serializedForm) {
+ StringTokenizer tokenizer = new StringTokenizer(serializedForm, ",");
+ List<String> list = new ArrayList<String>();
+ while(tokenizer.hasMoreElements()) {
+ list.add(tokenizer.nextToken().trim());
+ }
+ return list;
+ }
+
+ /**
+ * Returns the list of stereotypes String under a serialized form
+ *
+ * @param list
+ * the list of stereotypes to serialize
+ * @return the list of stereotypes String under a serialized form
+ */
+ public static String getSerializedStereotypeList(Collection<String> stereotypes) {
+ return convertToCommaSeparatedRepresentation(stereotypes);
+ }
+
+ /**
+ * Returns the name of the profile from the given stereotype qualified Name
+ *
+ * @param stereotypeName
+ * the name of the stereotype to parse
+ * @return the qualified name of the profile from the given stereotype
+ * qualified Name
+ */
+ public static String findProfileNameFromStereotypeName(String stereotypeName) {
+ return stereotypeName.substring(0, stereotypeName.lastIndexOf(NamedElement.SEPARATOR));
+ }
+
+ /**
+ * Returns the list of profile Qualified Names String under a serialized
+ * form
+ *
+ * @param list
+ * the list of profiles to serialize
+ * @return the list of profiles String under a serialized form
+ */
+ public static String getSerializedProfileList(Collection<String> profiles) {
+ return convertToCommaSeparatedRepresentation(profiles);
+ }
+
+ public static String convertToCommaSeparatedRepresentation(Collection objects) {
+ return convertToFlatRepresentation(objects, ",");
+ }
+
+ public static String convertToFlatRepresentation(Collection objects, String separator) {
+ StringBuilder buffer = new StringBuilder();
+ Iterator it = objects.iterator();
+ while(it.hasNext()) {
+ buffer.append(it.next());
+ if(it.hasNext()) {
+ buffer.append(separator);
+ }
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Returns the list of profiles String from a serialize string form
+ *
+ * @param serializedForm
+ * the serialized form of the list of stereotypes
+ * @return the list of profiles String from a serialize string form
+ */
+ public static Set<String> getProfileSetFromString(String serializedForm) {
+ StringTokenizer tokenizer = new StringTokenizer(serializedForm, ",");
+ Set<String> list = new HashSet<String>();
+ while(tokenizer.hasMoreElements()) {
+ list.add(tokenizer.nextToken());
+ }
+ return list;
+ }
+
+ /**
+ * returns <code>true</code> if the descriptor have all necessary profiles
+ *
+ * @param part
+ * the editor part for which the palette is shown
+ * @param papyrusProviderDesc
+ * the current provider descriptor to test
+ * @return <code>true</code> if all required profile are present
+ */
+ public static boolean areRequiredProfileApplied(IEditorPart part, PapyrusPaletteService.ProviderDescriptor papyrusProviderDesc) {
+ if(!(part instanceof DiagramEditorWithFlyOutPalette)) {
+ PapyrusTrace.log(IStatus.WARNING, "trying to check a papyrus palette descriptor outside papyrus framework");
+ return false;
+ }
+ if(papyrusProviderDesc instanceof PapyrusPaletteService.LocalProviderDescriptor) {
+ IPaletteDescription description = ((PapyrusPaletteService.LocalProviderDescriptor)papyrusProviderDesc).getDescription();
+ // checks the presence of required profile
+ Diagram diagram = ((DiagramEditorWithFlyOutPalette)part).getDiagram();
+ EObject element = diagram.getElement();
+ if(element instanceof Element) {
+ org.eclipse.uml2.uml.Package package_ = ((Element)element).getNearestPackage();
+ List<Profile> appliedProfiles = package_.getAllAppliedProfiles();
+ List<String> appliedProfilesNames = new ArrayList<String>();
+ for(Profile profile : appliedProfiles) {
+ appliedProfilesNames.add(profile.getQualifiedName());
+ }
+
+ // compare to the list of profiles used by the palette
+ Map<String, String> properties = description.getProperties();
+ if(description != null) {
+ String requiredProfilesList = properties.get(IPapyrusPaletteConstant.PROFILE_LIST);
+ if(requiredProfilesList != null) {
+ // parse requiredProfile string (profile1QN, profile2QN,
+ // etc.)
+ Set<String> requiredProfiles = PaletteUtil.getProfileSetFromString(requiredProfilesList);
+ for(String requiredProfileName : requiredProfiles) {
+ if(!appliedProfilesNames.contains(requiredProfileName)) {
+ return false;
+ }
+ }
+ }
+ }
+ }
+ } else {
+ IProvider provider = papyrusProviderDesc.getProvider();
+ if(provider instanceof IProfileDependantPaletteProvider) {
+ Diagram diagram = ((DiagramEditorWithFlyOutPalette)part).getDiagram();
+ return areRequiredProfileApplied(diagram, (IProfileDependantPaletteProvider)provider);
+ }
+ }
+ // by default, returns true if the descriptor is not a local descriptor,
+ // as they do not use
+ // profile
+ return true;
+ }
- public static String convertToFlatRepresentation(Collection objects, String separator) {
- StringBuilder buffer = new StringBuilder();
- Iterator it = objects.iterator();
- while(it.hasNext()) {
- buffer.append(it.next());
- if(it.hasNext()) {
- buffer.append(separator);
- }
- }
- return buffer.toString();
- }
-
- /**
- * Returns the list of profiles String from a serialize string form
- *
- * @param serializedForm
- * the serialized form of the list of stereotypes
- * @return the list of profiles String from a serialize string form
- */
- public static Set<String> getProfileSetFromString(String serializedForm) {
- StringTokenizer tokenizer = new StringTokenizer(serializedForm, ",");
- Set<String> list = new HashSet<String>();
- while(tokenizer.hasMoreElements()) {
- list.add(tokenizer.nextToken());
- }
- return list;
- }
-
/**
* returns <code>true</code> if the descriptor have all necessary profiles
- *
- * @param part
- * the editor part for which the palette is shown
- * @param papyrusProviderDesc
- * the current provider descriptor to test
+ * @param diagram The diagram being provided palette elements
+ * @param provider The profile-dependent palette provider
* @return <code>true</code> if all required profile are present
*/
- public static boolean areRequiredProfileApplied(IEditorPart part, PapyrusPaletteService.ProviderDescriptor papyrusProviderDesc) {
- if(!(part instanceof DiagramEditorWithFlyOutPalette)) {
- PapyrusTrace.log(IStatus.WARNING, "trying to check a papyrus palette descriptor outside papyrus framework");
- return false;
- }
- if(papyrusProviderDesc instanceof PapyrusPaletteService.LocalProviderDescriptor) {
- IPaletteDescription description = ((PapyrusPaletteService.LocalProviderDescriptor)papyrusProviderDesc).getDescription();
- // checks the presence of required profile
- Diagram diagram = ((DiagramEditorWithFlyOutPalette)part).getDiagram();
- EObject element = diagram.getElement();
- if(element instanceof Element) {
- org.eclipse.uml2.uml.Package package_ = ((Element)element).getNearestPackage();
- List<Profile> appliedProfiles = package_.getAllAppliedProfiles();
- List<String> appliedProfilesNames = new ArrayList<String>();
- for(Profile profile : appliedProfiles) {
- appliedProfilesNames.add(profile.getQualifiedName());
- }
-
- // compare to the list of profiles used by the palette
- Map<String, String> properties = description.getProperties();
- if(description != null) {
- String requiredProfilesList = properties.get(IPapyrusPaletteConstant.PROFILE_LIST);
- if(requiredProfilesList != null) {
- // parse requiredProfile string (profile1QN, profile2QN,
- // etc.)
- Set<String> requiredProfiles = PaletteUtil.getProfileSetFromString(requiredProfilesList);
- for(String requiredProfileName : requiredProfiles) {
- if(!appliedProfilesNames.contains(requiredProfileName)) {
- return false;
- }
- }
- }
- }
+ public static boolean areRequiredProfileApplied(Diagram diagram, IProfileDependantPaletteProvider provider) {
+ EObject element = diagram.getElement();
+ if(element instanceof Element) {
+ org.eclipse.uml2.uml.Package package_ = ((Element)element).getNearestPackage();
+ if (package_ == null)
+ return false;
+ List<Profile> appliedProfiles = package_.getAllAppliedProfiles();
+ List<String> appliedProfilesNames = new ArrayList<String>();
+ for(Profile profile : appliedProfiles) {
+ appliedProfilesNames.add(profile.getQualifiedName());
}
- } else {
- IProvider provider = papyrusProviderDesc.getProvider();
- if(provider instanceof IProfileDependantPaletteProvider) {
- Diagram diagram = ((DiagramEditorWithFlyOutPalette)part).getDiagram();
- EObject element = diagram.getElement();
- if(element instanceof Element) {
- org.eclipse.uml2.uml.Package package_ = ((Element)element).getNearestPackage();
- List<Profile> appliedProfiles = package_.getAllAppliedProfiles();
- List<String> appliedProfilesNames = new ArrayList<String>();
- for(Profile profile : appliedProfiles) {
- appliedProfilesNames.add(profile.getQualifiedName());
- }
- // not null also
- Collection<String> requiredProfiles = ((IProfileDependantPaletteProvider)provider).getRequiredProfiles();
- for(String requiredProfileName : requiredProfiles) {
- if(!appliedProfilesNames.contains(requiredProfileName)) {
- return false;
- }
- }
+ // not null also
+ Collection<String> requiredProfiles = ((IProfileDependantPaletteProvider)provider).getRequiredProfiles();
+ for(String requiredProfileName : requiredProfiles) {
+ if(!appliedProfilesNames.contains(requiredProfileName)) {
+ return false;
}
- return true;
}
}
- // by default, returns true if the descriptor is not a local descriptor,
- // as they do not use
- // profile
return true;
}
-
- public static void initAspectActions(NodeList aspectActionNodes, List<IPostAction> postActions, List<IPreAction> preActions) {
- for(int i = 0; i < aspectActionNodes.getLength(); i++) {
- Node childNode = aspectActionNodes.item(i);
- String childName = childNode.getNodeName();
- if(IPapyrusPaletteConstant.POST_ACTION.equals(childName)) {
- // node is a post action => retrieve the id of the factory in charge of this configuration
- IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
- if(provider != null) {
- IAspectAction action = provider.createAction(childNode);
- if (action instanceof IPostAction) {
- postActions.add((IPostAction)action);
- }
- } else {
- Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
- }
- } else if(IPapyrusPaletteConstant.PRE_ACTION.equals(childName)) {
- // node is a pre action => retrieve the id of the factory in charge of this configuration
- IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
- if(provider != null) {
- IAspectAction action = provider.createAction(childNode);
- if (action instanceof IPreAction) {
- preActions.add((IPreAction)action);
- }
- } else {
- Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
- }
- }
- }
- }
-
-}
+
+ public static void initAspectActions(NodeList aspectActionNodes, List<IPostAction> postActions, List<IPreAction> preActions) {
+ for(int i = 0; i < aspectActionNodes.getLength(); i++) {
+ Node childNode = aspectActionNodes.item(i);
+ String childName = childNode.getNodeName();
+ if(IPapyrusPaletteConstant.POST_ACTION.equals(childName)) {
+ // node is a post action => retrieve the id of the factory in charge of this configuration
+ IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
+ if(provider != null) {
+ IAspectAction action = provider.createAction(childNode);
+ if (action instanceof IPostAction) {
+ postActions.add((IPostAction)action);
+ }
+ } else {
+ Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
+ }
+ } else if(IPapyrusPaletteConstant.PRE_ACTION.equals(childName)) {
+ // node is a pre action => retrieve the id of the factory in charge of this configuration
+ IAspectActionProvider provider = AspectToolService.getInstance().getProvider(AspectToolService.getProviderId(childNode));
+ if(provider != null) {
+ IAspectAction action = provider.createAction(childNode);
+ if (action instanceof IPreAction) {
+ preActions.add((IPreAction)action);
+ }
+ } else {
+ Activator.log.error("impossible to find factory with id: " + AspectToolService.getProviderId(childNode), null);
+ }
+ }
+ }
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/FilteringPaletteProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/FilteringPaletteProvider.java
new file mode 100755
index 00000000000..a99beb955cb
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/FilteringPaletteProvider.java
@@ -0,0 +1,306 @@
+/*****************************************************************************
+ * 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.uml.diagram.common.service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.URIConverter;
+import org.eclipse.gef.palette.PaletteRoot;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
+import org.eclipse.gmf.runtime.diagram.ui.providers.DefaultPaletteProvider;
+import org.eclipse.gmf.runtime.diagram.ui.services.palette.IPaletteProvider;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusDiagram;
+import org.eclipse.papyrus.infra.viewpoints.policy.Activator;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.ui.IEditorPart;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Represents a palette provider which filters it content based on the use cases
+ * @author Laurent Wouters
+ */
+public class FilteringPaletteProvider implements IPaletteProvider {
+
+ /**
+ * Provider of a policy-enforced custom palette
+ *
+ * @author Laurent Wouters
+ */
+ private static class CustomPaletteProvider extends LocalPaletteProvider {
+ /**
+ * Sets the palette at the given uri as the contribution
+ *
+ * @param uri
+ * URI of a custom palette
+ */
+ public void setContributions(String uri) {
+ readXMLDocument(uri);
+ }
+
+ public NodeList getContributions() {
+ return contributions;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.service.LocalPaletteProvider#getXmlFile(java.lang.String)
+ */
+ @Override
+ public InputStream getXmlFile(String path) throws IOException {
+ return URIConverter.INSTANCE.createInputStream(URI.createURI(path));
+ }
+ }
+
+ /**
+ * Retrieve all elements of a palette contribution
+ *
+ */
+ private static class WalkerPaletteContribution implements IPapyrusPaletteConstant {
+
+ /**
+ * Retrieve all elements ID of the palette contributions
+ *
+ * @param contributions
+ * the palette contributions
+ * @return the list of palette nodes ID
+ */
+ public static List<String> getAllPaletteNodesID(NodeList contributions) {
+ List<String> paletteNodesID = new ArrayList<String>();
+ for(int i = 0; i < contributions.getLength(); i++) {
+ Node node = contributions.item(i);
+ if(PALETTE_DEFINITION.equals(node.getNodeName())) {
+ paletteNodesID.addAll(walkDefinition(node));
+ }
+ }
+ return paletteNodesID;
+ }
+
+ /**
+ * Parse the given node, assuming its type is a palette definition
+ *
+ * @param paletteDefinitionNode
+ * the node to parse
+ * @return the list of palette nodes ID
+ */
+ private static List<String> walkDefinition(Node paletteDefinitionNode) {
+ List<String> paletteNodesID = new ArrayList<String>();
+ NodeList nodes = paletteDefinitionNode.getChildNodes();
+ for(int i = 0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ if(CONTENT.equals(node.getNodeName())) {
+ paletteNodesID.addAll(walkContentNode(node));
+ }
+ }
+ return paletteNodesID;
+ }
+
+ /**
+ * Parse the contents of a palette definition
+ *
+ * @param paletteContentNode
+ * the node to parse
+ * @return the list of palette nodes ID
+ */
+ private static List<String> walkContentNode(Node paletteContentNode) {
+ List<String> paletteNodesID = new ArrayList<String>();
+ NodeList nodes = paletteContentNode.getChildNodes();
+ for(int i = 0; i < nodes.getLength(); i++) {
+ Node node = nodes.item(i);
+ String name = node.getNodeName();
+ String nodeID = null;
+ if(DRAWER.equals(name)) {
+ nodeID = node.getAttributes().getNamedItem(ID).getNodeValue();
+ paletteNodesID.add(nodeID);
+ if(node.getChildNodes().getLength() > 0) {
+ paletteNodesID.addAll(walkContentNode(node));
+ }
+ } else if(STACK.equals(name)) {
+ nodeID = node.getAttributes().getNamedItem(ID).getNodeValue();
+ paletteNodesID.add(nodeID);
+ if(node.getChildNodes().getLength() > 0) {
+ paletteNodesID.addAll(walkContentNode(node));
+ }
+ } else if(SEPARATOR.equals(name)) {
+ nodeID = node.getAttributes().getNamedItem(ID).getNodeValue();
+ paletteNodesID.add(nodeID);
+ if(node.getChildNodes().getLength() > 0) {
+ paletteNodesID.addAll(walkContentNode(node));
+ }
+ } else if(TOOL.equals(name)) {
+ nodeID = node.getAttributes().getNamedItem(ID).getNodeValue();
+ paletteNodesID.add(nodeID);
+ if(node.getChildNodes().getLength() > 0) {
+ paletteNodesID.addAll(walkContentNode(node));
+ }
+ } else if(ASPECT_TOOL.equals(name)) {
+ nodeID = node.getAttributes().getNamedItem(ID).getNodeValue();
+ paletteNodesID.add(nodeID);
+ if(node.getChildNodes().getLength() > 0) {
+ paletteNodesID.addAll(walkContentNode(node));
+ }
+ }
+ }
+ return paletteNodesID;
+ }
+ }
+
+ /**
+ * The original palette provider to delegate to
+ */
+ private DefaultPaletteProvider proxied;
+ /**
+ * The root configuration element for this palette provider
+ */
+ private IConfigurationElement config;
+ /**
+ * The view to which the palette will be provided
+ */
+ private Diagram diagram;
+ /**
+ * The exception to the filtering scheme.
+ * Palette entry IDs in this array are always allowed, regardless of the current configuration.
+ */
+ private String[] exceptions;
+
+ private NodeList contributions;
+
+ /**
+ * Initializes the provider
+ * @param proxied The original provider
+ * @param exceptions Entry IDs that should never be filtered
+ */
+ public FilteringPaletteProvider(DefaultPaletteProvider proxied, String[] exceptions) {
+ this.proxied = proxied;
+ this.exceptions = exceptions.clone();
+ }
+
+ /**
+ * Determines whether a palette element with the given entry ID should be exposed to the user
+ * @param entryID A palette element entry ID
+ * @return <code>true</code> if the element should be exposed
+ */
+ public boolean shouldExpose(String entryID) {
+ for (int i=0; i!=exceptions.length; i++)
+ if (entryID.startsWith(exceptions[i]))
+ return true;
+ return PolicyChecker.getCurrent().isInPalette(diagram, entryID);
+ }
+
+ /**
+ * Clear the contributions of the proxied palette provider.
+ * This is necessary because the actual contributions depends on the diagram's properties.
+ */
+ private void clearContributions() {
+ // this is going to be dirty ...
+ try {
+ Field field = proxied.getClass().getDeclaredField("contributions");
+ field.setAccessible(true);
+ List<?> list = (List<?>)field.get(proxied);
+ list.clear();
+ }
+ catch (Exception e) {
+ Activator.getDefault().getPapyrusLog().error("Failed to setup the filtering palette's configuration", e);
+ }
+ }
+
+ /**
+ * Retrieves the URI of the policy-enforced custom palette, if any
+ *
+ * @return The policy-enforced custom palette's URI
+ */
+ private String getCustomPalette() {
+ ViewPrototype proto = ViewPrototype.get(diagram);
+ PapyrusDiagram pd = (PapyrusDiagram) proto.getConfiguration();
+ if (pd == null)
+ return null;
+ return pd.getCustomPalette();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.diagram.ui.services.palette.IPaletteProvider#contributeToPalette(org.eclipse.ui.IEditorPart, java.lang.Object, org.eclipse.gef.palette.PaletteRoot, java.util.Map)
+ */
+ public void contributeToPalette(IEditorPart editor, Object content, PaletteRoot root, Map predefinedEntries) {
+ // the view needs to be known now because the actual filtering is called within setContributions
+ diagram = ((DiagramEditor)editor).getDiagram();
+
+ // Setting up the actual contribution
+ clearContributions();
+ proxied.setContributions(config);
+ // delegate the call to the proxied provider which is now ready
+ proxied.contributeToPalette(editor, content, root, predefinedEntries);
+
+ // retrieves the custom palette
+ String paletteURI = getCustomPalette();
+ if (paletteURI != null && !paletteURI.isEmpty()) {
+ CustomPaletteProvider provider = new CustomPaletteProvider();
+ provider.setContributions(paletteURI);
+ contributions = provider.getContributions();
+ List<String> nodesID = WalkerPaletteContribution.getAllPaletteNodesID(contributions);
+
+ // verify if the elements (nodes) from the custom palette already contributed
+ if (!isCustomPaletteContributed(predefinedEntries, nodesID)) {
+ provider.contributeToPalette(editor, content, root, predefinedEntries);
+ }
+ }
+ }
+
+ /**
+ * Verify if the elements (nodes) from the custom palette already contributed
+ *
+ * @param predefinedEntries
+ * the Predefined Entries already added
+ * @param nodesID
+ * the list of elements (nodes) ID from the custom palette
+ * @return true or false
+ */
+ public boolean isCustomPaletteContributed(Map predefinedEntries, List<String> nodesID) {
+ for (String nodeID : nodesID ) {
+ if (!predefinedEntries.containsKey(nodeID)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.diagram.ui.services.palette.IPaletteProvider#setContributions(org.eclipse.core.runtime.IConfigurationElement)
+ */
+ public void setContributions(IConfigurationElement configElement) { config = configElement; }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation)
+ */
+ public boolean provides(IOperation operation) { return proxied.provides(operation); }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.common.core.service.IProvider#addProviderChangeListener(org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener)
+ */
+ public void addProviderChangeListener(IProviderChangeListener listener) { proxied.addProviderChangeListener(listener); }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.gmf.runtime.common.core.service.IProvider#removeProviderChangeListener(org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener)
+ */
+ public void removeProviderChangeListener(IProviderChangeListener listener) { proxied.removeProviderChangeListener(listener); }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/LocalPaletteProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/LocalPaletteProvider.java
index 5126b349a45..a7389275633 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/LocalPaletteProvider.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/LocalPaletteProvider.java
@@ -26,6 +26,7 @@ import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.gmf.runtime.diagram.ui.services.palette.IPaletteProvider;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.part.IPaletteDescription;
@@ -45,9 +46,6 @@ public class LocalPaletteProvider extends AbstractProvider implements IPalettePr
*/
protected NodeList contributions = null;
- /** parser used for the xml file */
- protected XMLDefinitionPaletteParser parser;
-
/**
* {@inheritDoc}
*/
@@ -56,12 +54,12 @@ public class LocalPaletteProvider extends AbstractProvider implements IPalettePr
if(contributions ==null) {
return;
}
- parser = new XMLDefinitionPaletteParser(new XMLDefinitionPaletteFactory(root, predefinedEntries));
+ XMLPaletteDefinitionWalker walker = new XMLPaletteDefinitionWalker(new XMLPaletteApplicator(((DiagramEditor) editor).getDiagram(), root, predefinedEntries));
for(int i = 0; i < contributions.getLength(); i++) {
Node node = contributions.item(i);
if(PALETTE_DEFINITION.equals(node.getNodeName())) {
- parser.parsePaletteDefinition(node);
+ walker.walk(node);
}
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PapyrusPaletteService.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PapyrusPaletteService.java
index ff6b681f8ba..0a68ed39006 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PapyrusPaletteService.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PapyrusPaletteService.java
@@ -38,10 +38,12 @@ import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChang
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.palette.PaletteContainer;
+import org.eclipse.gef.palette.PaletteDrawer;
import org.eclipse.gef.palette.PaletteEntry;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PaletteSeparator;
@@ -58,10 +60,16 @@ import org.eclipse.gmf.runtime.common.ui.services.util.ActivityFilterProviderDes
import org.eclipse.gmf.runtime.common.ui.util.ActivityUtil;
import org.eclipse.gmf.runtime.diagram.ui.internal.DiagramUIPlugin;
import org.eclipse.gmf.runtime.diagram.ui.internal.services.palette.ContributeToPaletteOperation;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditorWithFlyOutPalette;
+import org.eclipse.gmf.runtime.diagram.ui.providers.DefaultPaletteProvider;
import org.eclipse.gmf.runtime.diagram.ui.services.palette.IPaletteProvider;
import org.eclipse.gmf.runtime.diagram.ui.services.palette.PaletteService;
import org.eclipse.gmf.runtime.diagram.ui.services.palette.SelectionToolEx;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.viewpoints.configuration.PapyrusDiagram;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.Messages;
import org.eclipse.papyrus.uml.diagram.common.part.IPaletteDescription;
@@ -70,6 +78,7 @@ import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPalettePreferences;
import org.eclipse.papyrus.uml.diagram.common.service.XMLPaletteProviderConfiguration.EditorDescriptor;
import org.eclipse.ui.IEditorPart;
import org.osgi.framework.Bundle;
+import org.w3c.dom.NodeList;
/**
* Service that contributes to the palette of a given editor with a given
@@ -279,14 +288,16 @@ public class PapyrusPaletteService extends PaletteService implements IPalettePro
@Override
public IProvider getProvider() {
if(provider == null) {
- IProvider newProvider = super.getProvider();
- if(provider instanceof IPaletteProvider) {
- IPaletteProvider defaultProvider = (IPaletteProvider)newProvider;
- defaultProvider.setContributions(getElement());
+ super.getProvider();
+ if (provider instanceof DefaultPaletteProvider) {
+ IPaletteProvider filtering = new FilteringPaletteProvider((DefaultPaletteProvider) provider, new String[] { GROUP_STANDARD, SEPARATOR_STANDARD, TOOL_SELECTION });
+ filtering.setContributions(getElement());
+ provider = filtering;
+ } else if (provider instanceof IPaletteProvider) {
+ ((IPaletteProvider)provider).setContributions(getElement());
}
- return newProvider;
}
- return super.getProvider();
+ return provider;
}
}
@@ -867,9 +878,27 @@ public class PapyrusPaletteService extends PaletteService implements IPalettePro
} catch (Exception e) {
Activator.getDefault().logError("Error in PapyrusPaletteService::createPalette()", e); //$NON-NLS-1$
}
+
+ Diagram diagram = ((DiagramEditor)editor).getDiagram();
+ for (Object o : root.getChildren()) {
+ if (o instanceof PaletteDrawer) {
+ PaletteDrawer drawer = (PaletteDrawer)o;
+ boolean isVisible = PolicyChecker.getCurrent().isInPalette(diagram, drawer.getId());
+ drawer.setVisible(isVisible);
+ if (isVisible) {
+ for (Object x : drawer.getChildren()) {
+ if (x instanceof PaletteEntry) {
+ PaletteEntry entry = (PaletteEntry)x;
+ entry.setVisible(PolicyChecker.getCurrent().isInPalette(diagram, entry.getId()));
+ }
+ }
+ }
+ }
+ }
return root;
}
-
+
+
/**
* {@inheritDoc}
*/
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PluginPaletteProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PluginPaletteProvider.java
index 8f11d0c7dbf..651e5980ee3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PluginPaletteProvider.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/PluginPaletteProvider.java
@@ -13,19 +13,16 @@
package org.eclipse.papyrus.uml.diagram.common.service;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.papyrus.infra.core.pluginexplorer.Plugin;
+import org.eclipse.papyrus.infra.core.pluginexplorer.PluginEntry;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.osgi.framework.Bundle;
import org.w3c.dom.Node;
@@ -60,28 +57,9 @@ public class PluginPaletteProvider extends LocalPaletteProvider implements IProf
// try to read it in a plugin...
Bundle bundle = Platform.getBundle(getProviderID());
if(bundle != null && bundle.getEntry(path)!=null) {
- URL urlFile = bundle.getEntry(path);
- urlFile = FileLocator.resolve(urlFile);
- urlFile = FileLocator.toFileURL(urlFile);
- if("file".equals(urlFile.getProtocol())) { //$NON-NLS-1$
- return new FileInputStream(urlFile.getFile());
- } else if("jar".equals(urlFile.getProtocol())) { //$NON-NLS-1$
- String filePath = urlFile.getPath();
- if(filePath.startsWith("file:")) {
- // strip off the file: and the !/
- int jarPathEndIndex = filePath.indexOf("!/");
- if(jarPathEndIndex < 0) {
- Activator.log.error("Impossible to find the jar path end", null);
- return null;
- }
- String jarPath = filePath.substring("file:".length(), jarPathEndIndex);
- ZipFile zipFile = new ZipFile(jarPath);
- filePath = filePath.substring(jarPathEndIndex + 2, filePath.length());
- ZipEntry entry = zipFile.getEntry(filePath);
- return zipFile.getInputStream(entry);
- // return new File(filePath);
- }
- }
+ Plugin plugin = new Plugin(bundle);
+ PluginEntry entry = plugin.getEntry(path);
+ return entry.getInputStream();
}
return null;
}
@@ -112,11 +90,13 @@ public class PluginPaletteProvider extends LocalPaletteProvider implements IProf
// parse the content of the file to discover the required
// profiles
// using safe computation
- XMLDefinitionPaletteParser profileParser = new XMLDefinitionPaletteParser(new XMLRequiredProfileFactory(requiredProfiles));
+ XMLPaletteDefinitionProfileInspector inspector = new XMLPaletteDefinitionProfileInspector();
+ XMLPaletteDefinitionWalker walker = new XMLPaletteDefinitionWalker(inspector);
for(int i = 0; i < contributions.getLength(); i++) {
Node node = contributions.item(i);
if(PALETTE_DEFINITION.equals(node.getNodeName())) {
- profileParser.parsePaletteDefinition(node);
+ walker.walk(node);
+ requiredProfiles.addAll(inspector.getRequiredProfiles());
}
}
} catch (Throwable e) {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLDefinitionPaletteFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteApplicator.java
index 01aa3267423..ed9b858fac0 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLDefinitionPaletteFactory.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteApplicator.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Laurent Wouters (CEA LIST) laurent.wouters@cea.fr - Refactoring
*
*****************************************************************************/
@@ -26,7 +27,9 @@ import org.eclipse.gef.palette.PaletteEntry;
import org.eclipse.gef.palette.PaletteRoot;
import org.eclipse.gef.palette.PaletteSeparator;
import org.eclipse.gef.palette.PaletteStack;
+import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.infra.viewpoints.policy.PolicyChecker;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.w3c.dom.Node;
@@ -34,40 +37,47 @@ import org.w3c.dom.Node;
* Standard implementation of the palette factory. This one should be use to
* provide palette content
*/
-public class XMLDefinitionPaletteFactory extends AbstractXMLDefinitionPaletteFactory implements IPapyrusPaletteConstant {
-
- /** palette root for the palette to be built */
- protected PaletteRoot root;
-
- /** map of predefined entries */
- protected Map<String, PaletteEntry> predefinedEntries;
+public class XMLPaletteApplicator implements XMLPaletteDefinitionVisitor, IPapyrusPaletteConstant {
/**
+ * The diagram owning which palette is to be filled
+ */
+ private Diagram diagram;
+
+ /**
+ * Target palette to be filled
+ */
+ private PaletteRoot target;
+
+ /**
+ * Map of predefined entries
+ */
+ private Map<String, PaletteEntry> predefinedEntries;
+
+ /**
* Creates a new XMLDefinitionPaletteFactory
*
- * @param root
- * the palette root to fill
- * @param predefinedEntries
- * existing predefined entries
+ * @param diagram The diagram to provide for
+ * @param target The root of the palette to provide for
+ * @param predefinedEntries existing predefined entries
*/
- public XMLDefinitionPaletteFactory(PaletteRoot root, Map<String, PaletteEntry> predefinedEntries) {
- this.root = root;
+ public XMLPaletteApplicator(Diagram diagram, PaletteRoot target, Map<String, PaletteEntry> predefinedEntries) {
+ this.diagram = diagram;
+ this.target = target;
this.predefinedEntries = predefinedEntries;
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseContentNode(Node node) {
+ public void onContent(Node node) {
// nothing to do here
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseDrawerNode(Node node) {
+ public void onDrawer(Node node) {
String id = node.getAttributes().getNamedItem(ID).getNodeValue();
PaletteEntry entry = predefinedEntries.get(id);
if(entry == null) {
@@ -82,7 +92,7 @@ public class XMLDefinitionPaletteFactory extends AbstractXMLDefinitionPaletteFac
}
predefinedEntries.put(id, entry);
}
- appendPaletteEntry(root, predefinedEntries, computePath(node), entry);
+ appendPaletteEntry(computePath(node), entry);
}
/**
@@ -105,23 +115,21 @@ public class XMLDefinitionPaletteFactory extends AbstractXMLDefinitionPaletteFac
/**
* {@inheritDoc}
*/
- @Override
- public void traverseSeparatorNode(Node node) {
+ public void onSeparator(Node node) {
String id = node.getAttributes().getNamedItem(ID).getNodeValue();
PaletteEntry entry = predefinedEntries.get(id);
if(entry == null) {
entry = new PaletteSeparator(id);
predefinedEntries.put(id, entry);
}
- appendPaletteEntry(root, predefinedEntries, computePath(node), entry);
+ appendPaletteEntry(computePath(node), entry);
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseStackNode(Node node) {
+ public void onStack(Node node) {
String id = node.getAttributes().getNamedItem(ID).getNodeValue();
PaletteEntry entry = predefinedEntries.get(id);
if(entry == null) {
@@ -130,24 +138,23 @@ public class XMLDefinitionPaletteFactory extends AbstractXMLDefinitionPaletteFac
entry.setId(id);
predefinedEntries.put(id, entry);
}
- appendPaletteEntry(root, predefinedEntries, computePath(node), entry);
+ appendPaletteEntry(computePath(node), entry);
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseToolEntryNode(Node node) {
+ public void onToolEntry(Node node) {
String id = node.getAttributes().getNamedItem(ID).getNodeValue();
PaletteEntry entry = predefinedEntries.get(id);
- appendPaletteEntry(root, predefinedEntries, computePath(node), entry);
+ if (PolicyChecker.getCurrent().isInPalette(diagram, id))
+ appendPaletteEntry(computePath(node), entry);
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseAspectToolEntryNode(Node node) {
+ public void onAspectToolEntry(Node node) {
final String id = node.getAttributes().getNamedItem(ID).getNodeValue();
final String refToolID = node.getAttributes().getNamedItem(REF_TOOL_ID).getNodeValue();
@@ -189,24 +196,21 @@ public class XMLDefinitionPaletteFactory extends AbstractXMLDefinitionPaletteFac
CombinedTemplateCreationEntry realEntry = new AspectCreationEntry(name, desc, id, iconDesc, entry, properties);
predefinedEntries.put(id, realEntry);
- appendPaletteEntry(root, predefinedEntries, computePath(node), realEntry);
+ if (PolicyChecker.getCurrent().isInPalette(diagram, id))
+ appendPaletteEntry(computePath(node), realEntry);
}
/**
* Appends the given palette entry to the appropriate location in either a
* predefined palette entry or the palette root.
*
- * @param root
- * @param predefinedEntries
- * map of predefined palette entries where the key is the palette
- * entry id and the value is the palette entry
* @param path
* @param paletteEntry
*/
- private static void appendPaletteEntry(PaletteRoot root, Map predefinedEntries, String path, PaletteEntry paletteEntry) {
- PaletteEntry fEntry = findPaletteEntry(root, path);
+ private void appendPaletteEntry(String path, PaletteEntry paletteEntry) {
+ PaletteEntry fEntry = findPaletteEntry(path);
if(fEntry == null) {
- fEntry = findPredefinedEntry(predefinedEntries, path);
+ fEntry = findPredefinedEntry(path);
}
if(fEntry == null) {
Activator.log.error("Invalid palette entry path: " + path, null);
@@ -222,33 +226,32 @@ public class XMLDefinitionPaletteFactory extends AbstractXMLDefinitionPaletteFac
}
/**
- * Finds a palette container starting from the given root and using the
- * given path
+ * Finds a palette container using the given path
*
- * @param root
- * @param aPath
+ * @param path
* @return the container or <code>null</code> if not found
*/
- private static PaletteEntry findPaletteEntry(PaletteEntry root, String aPath) {
- StringTokenizer tokens = new StringTokenizer(aPath, "/"); //$NON-NLS-1$
+ private PaletteEntry findPaletteEntry(String path) {
+ PaletteEntry current = target;
+ StringTokenizer tokens = new StringTokenizer(path, "/"); //$NON-NLS-1$
while(tokens.hasMoreElements()) {
- if(root instanceof PaletteContainer)
- root = findChildPaletteEntry((PaletteContainer)root, tokens.nextToken());
+ if(current instanceof PaletteContainer)
+ current = findChildPaletteEntry((PaletteContainer)current, tokens.nextToken());
else
return null;
}
- return root;
+ return current;
}
/**
* Finds a palette entry starting from the given container and using the
* given path
*
- * @param root
- * @param path
+ * @param container
+ * @param childId
* @return the entry or <code>null</code> if not found
*/
- private static PaletteEntry findChildPaletteEntry(PaletteContainer container, String childId) {
+ private PaletteEntry findChildPaletteEntry(PaletteContainer container, String childId) {
Iterator entries = container.getChildren().iterator();
while(entries.hasNext()) {
PaletteEntry entry = (PaletteEntry)entries.next();
@@ -262,14 +265,11 @@ public class XMLDefinitionPaletteFactory extends AbstractXMLDefinitionPaletteFac
* Searches the predefined entries for a palette entry given the full path
* as it was predefined.
*
- * @param predefinedEntries
- * map of predefined palette entries where the key is the palette
- * entry id and the value is the palette entry
* @param path
* the path to the palette entry starting as it was predefined
* @return the palette entry if one exists; null otherwise.
*/
- private static PaletteEntry findPredefinedEntry(Map predefinedEntries, String path) {
+ private PaletteEntry findPredefinedEntry(String path) {
StringTokenizer tokens = new StringTokenizer(path, "/"); //$NON-NLS-1$
PaletteEntry root = (PaletteEntry)predefinedEntries.get(tokens.nextToken());
@@ -289,7 +289,7 @@ public class XMLDefinitionPaletteFactory extends AbstractXMLDefinitionPaletteFac
* @param separator
* @param entry
*/
- private static void appendTo(PaletteSeparator separator, PaletteEntry entry) {
+ private void appendTo(PaletteSeparator separator, PaletteEntry entry) {
List children = separator.getParent().getChildren();
int index = children.indexOf(separator);
for(index++; index < children.size(); index++) {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLRequiredProfileFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteDefinitionProfileInspector.java
index 4e0940c594f..7877b17dc50 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLRequiredProfileFactory.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteDefinitionProfileInspector.java
@@ -8,10 +8,13 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Laurent Wouters (CEA LIST) laurent.wouters@cea.fr - Refactoring
+ *
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.service;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import org.eclipse.papyrus.uml.diagram.common.Activator;
@@ -24,67 +27,66 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
- * Factory that collects all required profiles for the given palette
+ * Visitor of an XML palette definition that keeps track of the required profiles
*/
-public class XMLRequiredProfileFactory extends AbstractXMLDefinitionPaletteFactory implements IPapyrusPaletteConstant {
+public class XMLPaletteDefinitionProfileInspector implements XMLPaletteDefinitionVisitor, IPapyrusPaletteConstant {
- final protected Collection<String> requiredProfiles;
+ final private Collection<String> requiredProfiles;
/**
- * Creates a new XMLRequiredProfileFactory.
- *
- * @param requiredProfiles
- * list of required profiles to complete
+ * Gets the profiles required for the palette
+ * @return A collection of the required profiles
*/
- public XMLRequiredProfileFactory(Collection<String> requiredProfiles) {
- this.requiredProfiles = requiredProfiles;
+ public Collection<String> getRequiredProfiles() {
+ return requiredProfiles;
+ }
+
+ /**
+ * Initializes the inspector
+ */
+ public XMLPaletteDefinitionProfileInspector() {
+ this.requiredProfiles = new HashSet<String>();
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseContentNode(Node node) {
+ public void onContent(Node node) {
// nothing specific here
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseDrawerNode(Node node) {
+ public void onDrawer(Node node) {
// nothing specific here
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseToolEntryNode(Node node) {
+ public void onToolEntry(Node node) {
// nothing specific here
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseStackNode(Node node) {
+ public void onStack(Node node) {
// nothing specific here
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseSeparatorNode(Node node) {
+ public void onSeparator(Node node) {
// nothing specific here
}
/**
* {@inheritDoc}
*/
- @Override
- public void traverseAspectToolEntryNode(Node node) {
+ public void onAspectToolEntry(Node node) {
if(node.getChildNodes().getLength() > 0) {
NodeList children = node.getChildNodes();
for(int i = 0; i < children.getLength(); i++) {
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AbstractXMLDefinitionPaletteFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteDefinitionVisitor.java
index 9b0e4e7daa9..b023dba89e6 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/AbstractXMLDefinitionPaletteFactory.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteDefinitionVisitor.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Laurent Wouters (CEA LIST) laurent.wouters@cea.fr - Refactoring
*
*****************************************************************************/
@@ -16,9 +17,9 @@ package org.eclipse.papyrus.uml.diagram.common.service;
import org.w3c.dom.Node;
/**
- * Basic factory to create elements from the xml definition of the palette
+ * Represents a handler of events fired when walking through the XML definition of a palette
*/
-public abstract class AbstractXMLDefinitionPaletteFactory {
+public interface XMLPaletteDefinitionVisitor {
/**
* action when visiting a content node
@@ -26,7 +27,7 @@ public abstract class AbstractXMLDefinitionPaletteFactory {
* @param node
* the node to visit
*/
- public abstract void traverseContentNode(Node node);
+ void onContent(Node node);
/**
* action when visiting a drawer node
@@ -34,7 +35,7 @@ public abstract class AbstractXMLDefinitionPaletteFactory {
* @param node
* the node to visit
*/
- public abstract void traverseDrawerNode(Node node);
+ void onDrawer(Node node);
/**
* action when visiting a drawer node
@@ -42,7 +43,7 @@ public abstract class AbstractXMLDefinitionPaletteFactory {
* @param node
* the node to visit
*/
- public abstract void traverseToolEntryNode(Node node);
+ void onToolEntry(Node node);
/**
* action when visiting a drawer node
@@ -50,7 +51,7 @@ public abstract class AbstractXMLDefinitionPaletteFactory {
* @param node
* the node to visit
*/
- public abstract void traverseStackNode(Node node);
+ void onStack(Node node);
/**
* action when visiting a drawer node
@@ -58,7 +59,7 @@ public abstract class AbstractXMLDefinitionPaletteFactory {
* @param node
* the node to visit
*/
- public abstract void traverseSeparatorNode(Node node);
+ void onSeparator(Node node);
/**
* action when visiting a aspect tool node
@@ -66,6 +67,6 @@ public abstract class AbstractXMLDefinitionPaletteFactory {
* @param node
* the node to visit
*/
- public abstract void traverseAspectToolEntryNode(Node node);
+ void onAspectToolEntry(Node node);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLDefinitionPaletteParser.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteDefinitionWalker.java
index 3719c37bdda..eb43e98ca8a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLDefinitionPaletteParser.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/XMLPaletteDefinitionWalker.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ * Laurent Wouters (CEA LIST) laurent.wouters@cea.fr - Refactoring
*
*****************************************************************************/
@@ -17,22 +18,22 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
- * Parser for the local definition of palettes.
+ * Walks through the XML definition of a palette and fires events on nodes
*/
-public class XMLDefinitionPaletteParser implements IPapyrusPaletteConstant {
+public class XMLPaletteDefinitionWalker implements IPapyrusPaletteConstant {
- /** factory used to create elements from the parsed xml file */
- final protected AbstractXMLDefinitionPaletteFactory factory;
+ /**
+ * The handler for the walking events
+ */
+ final private XMLPaletteDefinitionVisitor handler;
/**
- * Create a new XMLDefinitionPaletteParser
+ * Initializes this walker
*
- * @param factory
- * the factory used to create elements from the parsing of the
- * xml file
+ * @param handler The handler to be used for the walking events
*/
- public XMLDefinitionPaletteParser(AbstractXMLDefinitionPaletteFactory factory) {
- this.factory = factory;
+ public XMLPaletteDefinitionWalker(XMLPaletteDefinitionVisitor handler) {
+ this.handler = handler;
}
/**
@@ -41,13 +42,13 @@ public class XMLDefinitionPaletteParser implements IPapyrusPaletteConstant {
* @param node
* the node to parse
*/
- public void parsePaletteDefinition(Node paletteDefinitionNode) {
+ public void walk(Node paletteDefinitionNode) {
NodeList nodes = paletteDefinitionNode.getChildNodes();
for(int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if(CONTENT.equals(node.getNodeName())) {
- factory.traverseContentNode(node);
- parsePaletteContent(node);
+ handler.onContent(node);
+ walkContentNode(node);
}
}
}
@@ -57,24 +58,22 @@ public class XMLDefinitionPaletteParser implements IPapyrusPaletteConstant {
*
* @param node
* the node to parse
- * @param root
- * the palette root to fill
*/
- public void parsePaletteContent(Node paletteContentNode) {
+ private void walkContentNode(Node paletteContentNode) {
NodeList nodes = paletteContentNode.getChildNodes();
for(int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
String name = node.getNodeName();
if(DRAWER.equals(name)) {
- parserDrawerNode(node);
+ walkDrawerNode(node);
} else if(STACK.equals(name)) {
- parserStackNode(node);
+ walkStackNode(node);
} else if(SEPARATOR.equals(name)) {
- parseSeparatorNode(node);
+ walkSeparatorNode(node);
} else if(TOOL.equals(name)) {
- parseToolNode(node);
+ walkToolNode(node);
} else if(ASPECT_TOOL.equals(name)) {
- parseAspectToolNode(node);
+ walkAspectToolNode(node);
}
}
@@ -86,8 +85,8 @@ public class XMLDefinitionPaletteParser implements IPapyrusPaletteConstant {
* @param node
* the node to parse
*/
- public void parseAspectToolNode(Node node) {
- factory.traverseAspectToolEntryNode(node);
+ private void walkAspectToolNode(Node node) {
+ handler.onAspectToolEntry(node);
}
/**
@@ -96,12 +95,11 @@ public class XMLDefinitionPaletteParser implements IPapyrusPaletteConstant {
* @param node
* the node to parse
*/
- public void parserDrawerNode(Node node) {
- factory.traverseDrawerNode(node);
+ private void walkDrawerNode(Node node) {
+ handler.onDrawer(node);
if(node.getChildNodes().getLength() > 0) {
- parsePaletteContent(node);
+ walkContentNode(node);
}
- // return entry;
}
/**
@@ -110,11 +108,10 @@ public class XMLDefinitionPaletteParser implements IPapyrusPaletteConstant {
* @param node
* the node to parse
*/
- public void parserStackNode(Node node) {
- factory.traverseStackNode(node);
-
+ private void walkStackNode(Node node) {
+ handler.onStack(node);
if(node.getChildNodes().getLength() > 0) {
- parsePaletteContent(node);
+ walkContentNode(node);
}
}
@@ -124,11 +121,10 @@ public class XMLDefinitionPaletteParser implements IPapyrusPaletteConstant {
* @param node
* the node to parse
*/
- public void parseToolNode(Node node) {
- factory.traverseToolEntryNode(node);
-
+ private void walkToolNode(Node node) {
+ handler.onToolEntry(node);
if(node.getChildNodes().getLength() > 0) {
- parsePaletteContent(node);
+ walkContentNode(node);
}
}
@@ -138,11 +134,10 @@ public class XMLDefinitionPaletteParser implements IPapyrusPaletteConstant {
* @param node
* the node to parse
*/
- public void parseSeparatorNode(Node node) {
- factory.traverseSeparatorNode(node);
-
+ private void walkSeparatorNode(Node node) {
+ handler.onSeparator(node);
if(node.getChildNodes().getLength() > 0) {
- parsePaletteContent(node);
+ walkContentNode(node);
}
}

Back to the top