Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 4757) +++ META-INF/MANIFEST.MF (working copy) @@ -68,8 +68,13 @@ org.eclipse.papyrus.validation;bundle-version="0.8.0", org.eclipse.papyrus.extendedtypes;bundle-version="0.8.0";visibility:=reexport, org.eclipse.papyrus.service.edit;bundle-version="0.8.0";visibility:=reexport, +<<<<<<< .mine + org.eclipse.papyrus.navigation;bundle-version="0.8.0", + org.eclipse.papyrus.decoration;bundle-version="0.8.0" +======= org.eclipse.papyrus.navigation;bundle-version="0.8.0";visibility:=reexport, org.eclipse.papyrus.navigation.uml;bundle-version="0.8.0" +>>>>>>> .r4757 Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.) Ant-Version: Apache Ant 1.7.0 Bundle-ActivationPolicy: lazy Index: META-INF/MANIFEST.MF.mine =================================================================== --- META-INF/MANIFEST.MF.mine (revision 0) +++ META-INF/MANIFEST.MF.mine (revision 0) @@ -0,0 +1,77 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.diagram.common;singleton:=true +Bundle-Version: 0.8.0.qualifier +Bundle-ClassPath: . +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Export-Package: org.eclipse.papyrus.diagram.common, + org.eclipse.papyrus.diagram.common.actions, + org.eclipse.papyrus.diagram.common.actions.handlers, + org.eclipse.papyrus.diagram.common.command.wrappers, + org.eclipse.papyrus.diagram.common.commands, + org.eclipse.papyrus.diagram.common.dialogs, + org.eclipse.papyrus.diagram.common.directedit, + org.eclipse.papyrus.diagram.common.draw2d, + org.eclipse.papyrus.diagram.common.draw2d.anchors, + org.eclipse.papyrus.diagram.common.editparts, + org.eclipse.papyrus.diagram.common.editpolicies, + org.eclipse.papyrus.diagram.common.figure.edge, + org.eclipse.papyrus.diagram.common.figure.layout, + org.eclipse.papyrus.diagram.common.figure.node, + org.eclipse.papyrus.diagram.common.handlers, + org.eclipse.papyrus.diagram.common.helper, + org.eclipse.papyrus.diagram.common.ids, + org.eclipse.papyrus.diagram.common.layout, + org.eclipse.papyrus.diagram.common.listeners, + org.eclipse.papyrus.diagram.common.locator, + org.eclipse.papyrus.diagram.common.parser, + org.eclipse.papyrus.diagram.common.parser.assist, + org.eclipse.papyrus.diagram.common.parser.custom, + org.eclipse.papyrus.diagram.common.parser.lookup, + org.eclipse.papyrus.diagram.common.parser.packageimport, + org.eclipse.papyrus.diagram.common.parser.stereotype, + org.eclipse.papyrus.diagram.common.parser.structural, + org.eclipse.papyrus.diagram.common.part, + org.eclipse.papyrus.diagram.common.preferences, + org.eclipse.papyrus.diagram.common.providers, + org.eclipse.papyrus.diagram.common.providers.assistant, + org.eclipse.papyrus.diagram.common.resourceupdate, + org.eclipse.papyrus.diagram.common.service, + org.eclipse.papyrus.diagram.common.service.palette, + org.eclipse.papyrus.diagram.common.sheet, + org.eclipse.papyrus.diagram.common.ui.dialogs, + org.eclipse.papyrus.diagram.common.ui.helper, + org.eclipse.papyrus.diagram.common.ui.hyperlinkshell, + org.eclipse.papyrus.diagram.common.util +Require-Bundle: org.eclipse.uml2.uml.edit;visibility:=reexport, + org.eclipse.papyrus.core;bundle-version="0.8.0";visibility:=reexport, + 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="0.8.0", + org.eclipse.papyrus.umlutils;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.2.0", + org.eclipse.papyrus.wizards;bundle-version="0.8.0", + org.eclipse.papyrus.log;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.ui.toolbox;bundle-version="0.8.0", + org.eclipse.core.databinding;bundle-version="1.2.0", + org.eclipse.papyrus.editor;bundle-version="0.8.0", + org.eclipse.gmf.runtime.diagram.ui.render;bundle-version="1.3.0", + org.eclipse.papyrus.pastemanager;bundle-version="0.8.0", + org.eclipse.ui, + org.eclipse.papyrus.core.adaptor.gmf;bundle-version="0.8.0", + org.eclipse.papyrus.preferences;bundle-version="0.8.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.validation;bundle-version="0.8.0", + org.eclipse.papyrus.extendedtypes;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.service.edit;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.navigation;bundle-version="0.8.0", + org.eclipse.papyrus.decoration;bundle-version="0.8.0" +Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.) +Ant-Version: Apache Ant 1.7.0 +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-Activator: org.eclipse.papyrus.diagram.common.Activator Index: META-INF/MANIFEST.MF.r4629 =================================================================== --- META-INF/MANIFEST.MF.r4629 (revision 0) +++ META-INF/MANIFEST.MF.r4629 (revision 0) @@ -0,0 +1,76 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.diagram.common;singleton:=true +Bundle-Version: 0.8.0.qualifier +Bundle-ClassPath: . +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Export-Package: org.eclipse.papyrus.diagram.common, + org.eclipse.papyrus.diagram.common.actions, + org.eclipse.papyrus.diagram.common.actions.handlers, + org.eclipse.papyrus.diagram.common.command.wrappers, + org.eclipse.papyrus.diagram.common.commands, + org.eclipse.papyrus.diagram.common.dialogs, + org.eclipse.papyrus.diagram.common.directedit, + org.eclipse.papyrus.diagram.common.draw2d, + org.eclipse.papyrus.diagram.common.draw2d.anchors, + org.eclipse.papyrus.diagram.common.editparts, + org.eclipse.papyrus.diagram.common.editpolicies, + org.eclipse.papyrus.diagram.common.figure.edge, + org.eclipse.papyrus.diagram.common.figure.layout, + org.eclipse.papyrus.diagram.common.figure.node, + org.eclipse.papyrus.diagram.common.handlers, + org.eclipse.papyrus.diagram.common.helper, + org.eclipse.papyrus.diagram.common.ids, + org.eclipse.papyrus.diagram.common.layout, + org.eclipse.papyrus.diagram.common.listeners, + org.eclipse.papyrus.diagram.common.locator, + org.eclipse.papyrus.diagram.common.parser, + org.eclipse.papyrus.diagram.common.parser.assist, + org.eclipse.papyrus.diagram.common.parser.custom, + org.eclipse.papyrus.diagram.common.parser.lookup, + org.eclipse.papyrus.diagram.common.parser.packageimport, + org.eclipse.papyrus.diagram.common.parser.stereotype, + org.eclipse.papyrus.diagram.common.parser.structural, + org.eclipse.papyrus.diagram.common.part, + org.eclipse.papyrus.diagram.common.preferences, + org.eclipse.papyrus.diagram.common.providers, + org.eclipse.papyrus.diagram.common.providers.assistant, + org.eclipse.papyrus.diagram.common.resourceupdate, + org.eclipse.papyrus.diagram.common.service, + org.eclipse.papyrus.diagram.common.service.palette, + org.eclipse.papyrus.diagram.common.sheet, + org.eclipse.papyrus.diagram.common.ui.dialogs, + org.eclipse.papyrus.diagram.common.ui.helper, + org.eclipse.papyrus.diagram.common.ui.hyperlinkshell, + org.eclipse.papyrus.diagram.common.util +Require-Bundle: org.eclipse.uml2.uml.edit;visibility:=reexport, + org.eclipse.papyrus.core;bundle-version="0.8.0";visibility:=reexport, + 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="0.8.0", + org.eclipse.papyrus.umlutils;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.2.0", + org.eclipse.papyrus.wizards;bundle-version="0.8.0", + org.eclipse.papyrus.log;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.ui.toolbox;bundle-version="0.8.0", + org.eclipse.core.databinding;bundle-version="1.2.0", + org.eclipse.papyrus.editor;bundle-version="0.8.0", + org.eclipse.gmf.runtime.diagram.ui.render;bundle-version="1.3.0", + org.eclipse.papyrus.pastemanager;bundle-version="0.8.0", + org.eclipse.ui, + org.eclipse.papyrus.core.adaptor.gmf;bundle-version="0.8.0", + org.eclipse.papyrus.preferences;bundle-version="0.8.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.validation;bundle-version="0.8.0", + org.eclipse.papyrus.extendedtypes;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.service.edit;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.navigation;bundle-version="0.8.0" +Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.) +Ant-Version: Apache Ant 1.7.0 +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-Activator: org.eclipse.papyrus.diagram.common.Activator Index: META-INF/MANIFEST.MF.r4757 =================================================================== --- META-INF/MANIFEST.MF.r4757 (revision 0) +++ META-INF/MANIFEST.MF.r4757 (revision 0) @@ -0,0 +1,77 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName +Bundle-SymbolicName: org.eclipse.papyrus.diagram.common;singleton:=true +Bundle-Version: 0.8.0.qualifier +Bundle-ClassPath: . +Bundle-Vendor: %providerName +Bundle-Localization: plugin +Export-Package: org.eclipse.papyrus.diagram.common, + org.eclipse.papyrus.diagram.common.actions, + org.eclipse.papyrus.diagram.common.actions.handlers, + org.eclipse.papyrus.diagram.common.command.wrappers, + org.eclipse.papyrus.diagram.common.commands, + org.eclipse.papyrus.diagram.common.dialogs, + org.eclipse.papyrus.diagram.common.directedit, + org.eclipse.papyrus.diagram.common.draw2d, + org.eclipse.papyrus.diagram.common.draw2d.anchors, + org.eclipse.papyrus.diagram.common.editparts, + org.eclipse.papyrus.diagram.common.editpolicies, + org.eclipse.papyrus.diagram.common.figure.edge, + org.eclipse.papyrus.diagram.common.figure.layout, + org.eclipse.papyrus.diagram.common.figure.node, + org.eclipse.papyrus.diagram.common.handlers, + org.eclipse.papyrus.diagram.common.helper, + org.eclipse.papyrus.diagram.common.ids, + org.eclipse.papyrus.diagram.common.layout, + org.eclipse.papyrus.diagram.common.listeners, + org.eclipse.papyrus.diagram.common.locator, + org.eclipse.papyrus.diagram.common.parser, + org.eclipse.papyrus.diagram.common.parser.assist, + org.eclipse.papyrus.diagram.common.parser.custom, + org.eclipse.papyrus.diagram.common.parser.lookup, + org.eclipse.papyrus.diagram.common.parser.packageimport, + org.eclipse.papyrus.diagram.common.parser.stereotype, + org.eclipse.papyrus.diagram.common.parser.structural, + org.eclipse.papyrus.diagram.common.part, + org.eclipse.papyrus.diagram.common.preferences, + org.eclipse.papyrus.diagram.common.providers, + org.eclipse.papyrus.diagram.common.providers.assistant, + org.eclipse.papyrus.diagram.common.resourceupdate, + org.eclipse.papyrus.diagram.common.service, + org.eclipse.papyrus.diagram.common.service.palette, + org.eclipse.papyrus.diagram.common.sheet, + org.eclipse.papyrus.diagram.common.ui.dialogs, + org.eclipse.papyrus.diagram.common.ui.helper, + org.eclipse.papyrus.diagram.common.ui.hyperlinkshell, + org.eclipse.papyrus.diagram.common.util +Require-Bundle: org.eclipse.uml2.uml.edit;visibility:=reexport, + org.eclipse.papyrus.core;bundle-version="0.8.0";visibility:=reexport, + 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="0.8.0", + org.eclipse.papyrus.umlutils;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.2.0", + org.eclipse.papyrus.wizards;bundle-version="0.8.0", + org.eclipse.papyrus.log;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.ui.toolbox;bundle-version="0.8.0", + org.eclipse.core.databinding;bundle-version="1.2.0", + org.eclipse.papyrus.editor;bundle-version="0.8.0", + org.eclipse.gmf.runtime.diagram.ui.render;bundle-version="1.3.0", + org.eclipse.papyrus.pastemanager;bundle-version="0.8.0", + org.eclipse.ui, + org.eclipse.papyrus.core.adaptor.gmf;bundle-version="0.8.0", + org.eclipse.papyrus.preferences;bundle-version="0.8.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.validation;bundle-version="0.8.0", + org.eclipse.papyrus.extendedtypes;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.service.edit;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.navigation;bundle-version="0.8.0";visibility:=reexport, + org.eclipse.papyrus.navigation.uml;bundle-version="0.8.0" +Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.) +Ant-Version: Apache Ant 1.7.0 +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-Activator: org.eclipse.papyrus.diagram.common.Activator Index: src/org/eclipse/papyrus/diagram/common/editparts/CompositeEditPart.java =================================================================== --- src/org/eclipse/papyrus/diagram/common/editparts/CompositeEditPart.java (revision 0) +++ src/org/eclipse/papyrus/diagram/common/editparts/CompositeEditPart.java (revision 0) @@ -0,0 +1,92 @@ +package org.eclipse.papyrus.diagram.common.editparts; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart; +import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.FillStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.runtime.notation.datatype.GradientData; +import org.eclipse.papyrus.diagram.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.papyrus.umlutils.ui.helper.ShadowFigureHelper; +import org.eclipse.swt.graphics.Color; + +/** + * this uml edit part can refresh shadow and gradient. + */ +public abstract class CompositeEditPart extends AbstractBorderedShapeEditPart { + + + public CompositeEditPart(View view) { + super(view); + } + + @Override + protected NodeFigure createMainFigure() { + return createNodeFigure(); + } + + public abstract IPapyrusNodeFigure getPrimaryShape(); + + @Override + public boolean supportsGradient() { + return true; + } + + @Override + protected void handleNotificationEvent(Notification event) { + super.handleNotificationEvent(event); + + // set the figure active when the feature of the of a class is true + if(resolveSemanticElement() != null) { + refreshShadow(); + + } + } + + @Override + protected void refreshVisuals() { + super.refreshVisuals(); + refreshShadow(); + } + + @Override + protected void setTransparency(int transp) { + getPrimaryShape().setTransparency(transp); + } + + /** + * sets the back ground color of this edit part + */ + @Override + protected void setBackgroundColor(Color color) { + getPrimaryShape().setBackgroundColor(color); + getPrimaryShape().setIsUsingGradient(false); + getPrimaryShape().setGradientData(-1, -1, 0); + } + + /** + * Override to set the gradient data to the correct figure + */ + @Override + protected void setGradient(GradientData gradient) { + IPapyrusNodeFigure fig = getPrimaryShape(); + FillStyle style = (FillStyle)getPrimaryView().getStyle(NotationPackage.Literals.FILL_STYLE); + if(gradient != null) { + fig.setIsUsingGradient(true);; + fig.setGradientData(style.getFillColor(), gradient.getGradientColor1(), gradient.getGradientStyle()); + } else { + fig.setIsUsingGradient(false); + } + } + + @Override + protected void setForegroundColor(Color color) { + getPrimaryShape().setForegroundColor(color); + } + + protected void refreshShadow() { + getPrimaryShape().setShadow(ShadowFigureHelper.getShadowFigureValue((View)getModel())); + } + +} Index: src/org/eclipse/papyrus/diagram/common/editparts/DeploymentNodeEditPart.java =================================================================== --- src/org/eclipse/papyrus/diagram/common/editparts/DeploymentNodeEditPart.java (revision 0) +++ src/org/eclipse/papyrus/diagram/common/editparts/DeploymentNodeEditPart.java (revision 0) @@ -0,0 +1,73 @@ +package org.eclipse.papyrus.diagram.common.editparts; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart; +import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure; +import org.eclipse.gmf.runtime.notation.FillStyle; +import org.eclipse.gmf.runtime.notation.NotationPackage; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.gmf.runtime.notation.datatype.GradientData; +import org.eclipse.papyrus.diagram.common.figure.node.IPapyrusNodeFigure; +import org.eclipse.swt.graphics.Color; + + +public abstract class DeploymentNodeEditPart extends AbstractBorderedShapeEditPart implements IPapyrusEditPart { + + + public DeploymentNodeEditPart(View view) { + super(view); + } + + @Override + protected NodeFigure createMainFigure() { + return createNodeFigure(); + } + + public abstract IPapyrusNodeFigure getPrimaryShape(); + + @Override + public boolean supportsGradient() { + return true; + } + + @Override + protected void handleNotificationEvent(Notification event) { + super.handleNotificationEvent(event); + } + + @Override + protected void setTransparency(int transp) { + getPrimaryShape().setTransparency(transp); + } + + /** + * sets the back ground color of this edit part + */ + @Override + protected void setBackgroundColor(Color color) { + getPrimaryShape().setBackgroundColor(color); + getPrimaryShape().setIsUsingGradient(false); + getPrimaryShape().setGradientData(-1, -1, 0); + } + + /** + * Override to set the gradient data to the correct figure + */ + @Override + protected void setGradient(GradientData gradient) { + IPapyrusNodeFigure fig = getPrimaryShape(); + FillStyle style = (FillStyle)getPrimaryView().getStyle(NotationPackage.Literals.FILL_STYLE); + if(gradient != null) { + fig.setIsUsingGradient(true);; + fig.setGradientData(style.getFillColor(), gradient.getGradientColor1(), gradient.getGradientStyle()); + } else { + fig.setIsUsingGradient(false); + } + } + + @Override + protected void setForegroundColor(Color color) { + getPrimaryShape().setForegroundColor(color); + } + +} Index: src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java =================================================================== --- src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java (revision 4757) +++ src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java (working copy) @@ -9,232 +9,98 @@ * * Contributors: * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation - * Patrick Tessier (CEA LIST)-modification * *****************************************************************************/ package org.eclipse.papyrus.diagram.common.editpolicies; -import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import org.eclipse.emf.ecore.EObject; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; import org.eclipse.gef.commands.UnexecutableCommand; -import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; -import org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPolicy; import org.eclipse.gmf.runtime.notation.Diagram; import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil; -import org.eclipse.papyrus.core.editorsfactory.IPageIconsRegistry; -import org.eclipse.papyrus.core.editorsfactory.PageIconsRegistry; import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor; -import org.eclipse.papyrus.core.services.ServiceException; -import org.eclipse.papyrus.core.utils.EditorUtils; -import org.eclipse.papyrus.diagram.common.dialogs.DiagramNavigationDialog; -import org.eclipse.papyrus.diagram.common.helper.AbstractHyperLinkHelper; -import org.eclipse.papyrus.diagram.common.helper.DiagramHyperLinkHelper; -import org.eclipse.papyrus.diagram.common.helper.DocumentHyperLinkHelper; -import org.eclipse.papyrus.diagram.common.helper.HyperlinkHelperFactory; -import org.eclipse.papyrus.diagram.common.helper.WebHyperLinkHelper; -import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.AdvancedHLManager; -import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkDiagram; -import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkManagerShell; -import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperlinkObject; import org.eclipse.papyrus.navigation.ExistingNavigableElement; import org.eclipse.papyrus.navigation.NavigableElement; import org.eclipse.papyrus.navigation.NavigationHelper; -import org.eclipse.papyrus.navigation.preference.INavigationPreferenceConstant; -import org.eclipse.papyrus.preferences.Activator; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.Package; /** * This class is used to open a new diagram when the double click is detected. It is dependent of * papyrus environment */ -public class NavigationEditPolicy extends OpenEditPolicy { - - public static final String NAVIGATION_POLICY = "NavigationEditPolicy"; - +public class NavigationEditPolicy extends DecorationEditPolicy { + + public static final String NAVIGATION_POLICY = "navigationEditPolicy"; + public NavigationEditPolicy() { + setDecorators(Collections.singletonMap(NAVIGATION_POLICY, new NavigationDecorator(new DecoratorTarget()))); } - /** - * - * @param element a UML element - * @return the top package of the given element - */ - public static Package topPackage(Element element) { - if(element.getOwner() == null) { - return (Package)element; - } else { - return topPackage(element.getOwner()); - } - } - /** - * - * @param request - * @return get the command to open a new diagram - */ protected Command getOpenCommand(Request request) { - final IGraphicalEditPart gep; - - //in order to obtain the list of default diagram we need to fin the edit part that refers to default diagram - - //if this a label of a compartment, the good editpart is the parent - if((IGraphicalEditPart)getHost() instanceof CompartmentEditPart ){ - gep=(IGraphicalEditPart)getHost().getParent(); - } - else{ - - gep=(IGraphicalEditPart)getHost(); - } - final EObject semanticElement=gep.resolveSemanticElement(); + IGraphicalEditPart gep = (IGraphicalEditPart)getHost(); - //navigable element by using heuristic - List navElements=null; + List navElements = NavigationHelper.getInstance().getAllNavigableElements(gep.resolveSemanticElement()); - //defaultHyperlinks - final ArrayList defaultHyperLinkObject=new ArrayList(); - final ArrayList hyperLinkObjectList; - //Diagrams that will be found by using heuristic HashMap> existingDiagrams = new HashMap>(); + HashMap> possibleCreations = new HashMap>(); - - if(semanticElement==null){ - return UnexecutableCommand.INSTANCE; - } - //initialition of code to extract hyperlinks, in the future to do with extension points - ArrayList hyperLinkHelpers= new ArrayList(); - hyperLinkHelpers.add(new DiagramHyperLinkHelper()); - hyperLinkHelpers.add(new DocumentHyperLinkHelper()); - hyperLinkHelpers.add(new WebHyperLinkHelper()); - - final HyperlinkHelperFactory hyperlinkHelperFactory= new HyperlinkHelperFactory(hyperLinkHelpers); + for(NavigableElement navElement : navElements) { + final EObject element = navElement.getElement(); + if(navElement instanceof ExistingNavigableElement) { + List associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null); - try{ - //fill the list of default hyperlinks - hyperLinkObjectList = (ArrayList)hyperlinkHelperFactory.getAllreferenced(gep.getNotationView()); - - Iterator iterator= hyperLinkObjectList.iterator(); - while(iterator.hasNext()) { - HyperlinkObject hyperlinkObject = (HyperlinkObject)iterator.next(); - if( hyperlinkObject.getIsDefault()){ - - defaultHyperLinkObject.add(hyperlinkObject); + // ignore the current diagram + associatedDiagrams.remove(gep.getNotationView().getDiagram()); + if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) { + existingDiagrams.put(navElement, associatedDiagrams); } - } - //fill navigation by using heuristics - navElements = NavigationHelper.getInstance().getAllNavigableElements(semanticElement); - HashMap> possibleCreations = new HashMap>(); - - //test which kind of navigation by consulting preference - String navigationKind=Activator.getDefault().getPreferenceStore().getString(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DOUBLECLICK_KIND); - - //no naviagation - if(navigationKind.equals(INavigationPreferenceConstant.NO_NAVIGATION)){ - //do nothing - return UnexecutableCommand.INSTANCE; - } - - //navigation by using heuristic - //add list of diagram navigables by using heuristic - if(navigationKind.equals(INavigationPreferenceConstant.EXPLICIT_IMPLICIT_NAVIGATION)){ - for(NavigableElement navElement : navElements) { - final EObject element = navElement.getElement(); - if(navElement instanceof ExistingNavigableElement) { - List associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null); - - // ignore the current diagram - associatedDiagrams.remove(gep.getNotationView().getDiagram()); - if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) { - existingDiagrams.put(navElement, associatedDiagrams); - } - } + List possibleCommandDescs = new LinkedList(); + for(final CreationCommandDescriptor desc : getCreationCommandRegistry().getCommandDescriptors()) { + if(desc.getCondition() == null || desc.getCondition().create(element)) { + possibleCommandDescs.add(desc); } - - Iterator> iter=existingDiagrams.values().iterator(); - while(iter.hasNext()) { - List list = (List)iter.next(); - Iterator iterDiagram=list.iterator(); - while(iterDiagram.hasNext()) { - Diagram diagram = (Diagram)iterDiagram.next(); - HyperLinkDiagram hyperLinkDiagram= new HyperLinkDiagram(); - hyperLinkDiagram.setDiagram(diagram); - hyperLinkDiagram.setTooltipText(diagram.getName()+" (found by heuristic)"); - //look for if a hyperlink already exists - HyperlinkObject foundHyperlink=null; - for(int i=0; i1){ - //open a dialog to choose a diagram - DiagramNavigationDialog diagramNavigationDialog= new DiagramNavigationDialog(new Shell(),defaultHyperLinkObject); - diagramNavigationDialog.open(); - final ArrayList hList=diagramNavigationDialog.getSelectedHyperlinks(); - Command command= new Command() { - @Override - public void execute() { - super.execute(); + } - Iterator iter= hList.iterator(); - while(iter.hasNext()) { - HyperlinkObject hyperlinkObject = (HyperlinkObject)iter.next(); - hyperlinkObject.executeSelectPressed(); - } - } - }; - return command; - + if(!existingDiagrams.isEmpty()) { + NavigationOpenDiagramDialog dialog = new NavigationOpenDiagramDialog(Display.getCurrent().getActiveShell(), existingDiagrams); + int result = dialog.open(); + if(result == Window.OK) { + return new ICommandProxy(dialog.getCommand()); } - + } else { + NavigationCreateDiagramDialog dialog = new NavigationCreateDiagramDialog(Display.getCurrent().getActiveShell(), possibleCreations); + int result = dialog.open(); + if(result == Window.OK) { + return new ICommandProxy(dialog.getCommand()); + } } - catch (Exception e) { - org.eclipse.papyrus.diagram.common.Activator.log.error("Impossible to load hyperlinks", e); - } + return UnexecutableCommand.INSTANCE; } + public Command getCommand(Request request) { + if (RequestConstants.REQ_OPEN.equals(request.getType())) + return getOpenCommand(request); + return super.getCommand(request); + } +<<<<<<< .mine + public boolean understandsRequest(Request request) { + if (RequestConstants.REQ_OPEN.equals(request.getType())) + return true; + return super.understandsRequest(request); + } +======= /** * Return the EditorRegistry for nested editor descriptors. Subclass should implements this * method in order to return the registry associated to the extension point namespace. @@ -251,5 +117,21 @@ return new PageIconsRegistry(); } } +>>>>>>> .r4757 +<<<<<<< .mine + public EditPart getTargetEditPart(Request request) { + + if (understandsRequest(request)) + return getHost(); + + return null; + } + + private static ICreationCommandRegistry getCreationCommandRegistry() { + return CreationCommandRegistry.getInstance(org.eclipse.papyrus.core.Activator.PLUGIN_ID); + } + +======= +>>>>>>> .r4757 } Index: src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.mine =================================================================== --- src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.mine (revision 0) +++ src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.mine (revision 0) @@ -0,0 +1,128 @@ +/***************************************************************************** + * Copyright (c) 2010 Atos Origin. + * + * + * 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: + * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation + * + *****************************************************************************/ +package org.eclipse.papyrus.diagram.common.editpolicies; + +import java.util.Collections; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DecorationEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil; +import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor; +import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry; +import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry; +import org.eclipse.papyrus.diagram.common.dialogs.NavigationCreateDiagramDialog; +import org.eclipse.papyrus.diagram.common.dialogs.NavigationOpenDiagramDialog; +import org.eclipse.papyrus.diagram.common.providers.NavigationDecorator; +import org.eclipse.papyrus.navigation.ExistingNavigableElement; +import org.eclipse.papyrus.navigation.NavigableElement; +import org.eclipse.papyrus.navigation.NavigationHelper; +import org.eclipse.swt.widgets.Display; + +/** + * This class is used to open a new diagram when the double click is detected. It is dependent of + * papyrus environment + */ +public class NavigationEditPolicy extends DecorationEditPolicy { + + public static final String NAVIGATION_POLICY = "navigationEditPolicy"; + + public NavigationEditPolicy() { + setDecorators(Collections.singletonMap(NAVIGATION_POLICY, new NavigationDecorator(new DecoratorTarget()))); + } + + protected Command getOpenCommand(Request request) { + IGraphicalEditPart gep = (IGraphicalEditPart)getHost(); + + List navElements = NavigationHelper.getInstance().getAllNavigableElements(gep.resolveSemanticElement()); + + HashMap> existingDiagrams = new HashMap>(); + HashMap> possibleCreations = new HashMap>(); + + for(NavigableElement navElement : navElements) { + final EObject element = navElement.getElement(); + if(navElement instanceof ExistingNavigableElement) { + List associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null); + + // ignore the current diagram + associatedDiagrams.remove(gep.getNotationView().getDiagram()); + if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) { + existingDiagrams.put(navElement, associatedDiagrams); + } + } + + List possibleCommandDescs = new LinkedList(); + for(final CreationCommandDescriptor desc : getCreationCommandRegistry().getCommandDescriptors()) { + if(desc.getCondition() == null || desc.getCondition().create(element)) { + possibleCommandDescs.add(desc); + } + } + if(!possibleCommandDescs.isEmpty()) { + possibleCreations.put(navElement, possibleCommandDescs); + } + } + + if(!existingDiagrams.isEmpty()) { + NavigationOpenDiagramDialog dialog = new NavigationOpenDiagramDialog(Display.getCurrent().getActiveShell(), existingDiagrams); + int result = dialog.open(); + if(result == Window.OK) { + return new ICommandProxy(dialog.getCommand()); + } + } else { + NavigationCreateDiagramDialog dialog = new NavigationCreateDiagramDialog(Display.getCurrent().getActiveShell(), possibleCreations); + int result = dialog.open(); + if(result == Window.OK) { + return new ICommandProxy(dialog.getCommand()); + } + } + + return UnexecutableCommand.INSTANCE; + } + + public Command getCommand(Request request) { + if (RequestConstants.REQ_OPEN.equals(request.getType())) + return getOpenCommand(request); + return super.getCommand(request); + } + + public boolean understandsRequest(Request request) { + if (RequestConstants.REQ_OPEN.equals(request.getType())) + return true; + return super.understandsRequest(request); + } + + public EditPart getTargetEditPart(Request request) { + + if (understandsRequest(request)) + return getHost(); + + return null; + } + + private static ICreationCommandRegistry getCreationCommandRegistry() { + return CreationCommandRegistry.getInstance(org.eclipse.papyrus.core.Activator.PLUGIN_ID); + } + +} Index: src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.r4630 =================================================================== --- src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.r4630 (revision 0) +++ src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.r4630 (revision 0) @@ -0,0 +1,277 @@ +/***************************************************************************** + * Copyright (c) 2010 Atos Origin. + * + * + * 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: + * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation + * Patrick Tessier (CEA LIST)-modification + * + *****************************************************************************/ +package org.eclipse.papyrus.diagram.common.editpolicies; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DecorationEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPolicy; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil; +import org.eclipse.papyrus.core.editorsfactory.IPageIconsRegistry; +import org.eclipse.papyrus.core.editorsfactory.PageIconsRegistry; +import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor; +import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry; +import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry; +import org.eclipse.papyrus.core.services.ServiceException; +import org.eclipse.papyrus.core.utils.EditorUtils; +import org.eclipse.papyrus.diagram.common.dialogs.DiagramNavigationDialog; +import org.eclipse.papyrus.diagram.common.dialogs.NavigationCreateDiagramDialog; +import org.eclipse.papyrus.diagram.common.dialogs.NavigationOpenDiagramDialog; +import org.eclipse.papyrus.diagram.common.helper.AbstractHyperLinkHelper; +import org.eclipse.papyrus.diagram.common.helper.DiagramHyperLinkHelper; +import org.eclipse.papyrus.diagram.common.helper.DocumentHyperLinkHelper; +import org.eclipse.papyrus.diagram.common.helper.HyperlinkHelperFactory; +import org.eclipse.papyrus.diagram.common.helper.WebHyperLinkHelper; +import org.eclipse.papyrus.diagram.common.providers.NavigationDecorator; +import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.AdvancedHLManager; +import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkDiagram; +import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkManagerShell; +import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperlinkObject; +import org.eclipse.papyrus.navigation.ExistingNavigableElement; +import org.eclipse.papyrus.navigation.NavigableElement; +import org.eclipse.papyrus.navigation.NavigationHelper; +import org.eclipse.papyrus.navigation.preference.INavigationPreferenceConstant; +import org.eclipse.papyrus.preferences.Activator; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Package; + +/** + * This class is used to open a new diagram when the double click is detected. It is dependent of + * papyrus environment + */ +public class NavigationEditPolicy extends OpenEditPolicy { + + public static final String NAVIGATION_POLICY = "NavigationEditPolicy"; + + public NavigationEditPolicy() { + } + + /** + * + * @param element a UML element + * @return the top package of the given element + */ + public static Package topPackage(Element element) { + if(element.getOwner() == null) { + return (Package)element; + } else { + return topPackage(element.getOwner()); + } + } + /** + * + * @param request + * @return get the command to open a new diagram + */ + protected Command getOpenCommand(Request request) { + final IGraphicalEditPart gep; + + //in order to obtain the list of default diagram we need to fin the edit part that refers to default diagram + + //if this a label of a compartment, the good editpart is the parent + if((IGraphicalEditPart)getHost() instanceof CompartmentEditPart ){ + gep=(IGraphicalEditPart)getHost().getParent(); + } + else{ + + gep=(IGraphicalEditPart)getHost(); + } + final EObject semanticElement=gep.resolveSemanticElement(); + + //navigable element by using heuristic + List navElements=null; + + //defaultHyperlinks + final ArrayList defaultHyperLinkObject=new ArrayList(); + final ArrayList hyperLinkObjectList; + //Diagrams that will be found by using heuristic + HashMap> existingDiagrams = new HashMap>(); + + + if(semanticElement==null){ + return UnexecutableCommand.INSTANCE; + } + //initialition of code to extract hyperlinks, in the future to do with extension points + ArrayList hyperLinkHelpers= new ArrayList(); + hyperLinkHelpers.add(new DiagramHyperLinkHelper()); + hyperLinkHelpers.add(new DocumentHyperLinkHelper()); + hyperLinkHelpers.add(new WebHyperLinkHelper()); + + final HyperlinkHelperFactory hyperlinkHelperFactory= new HyperlinkHelperFactory(hyperLinkHelpers); + + try{ + //fill the list of default hyperlinks + hyperLinkObjectList = (ArrayList)hyperlinkHelperFactory.getAllreferenced(gep.getNotationView()); + + Iterator iterator= hyperLinkObjectList.iterator(); + while(iterator.hasNext()) { + HyperlinkObject hyperlinkObject = (HyperlinkObject)iterator.next(); + if( hyperlinkObject.getIsDefault()){ + + defaultHyperLinkObject.add(hyperlinkObject); + } + + } + + //fill navigation by using heuristics + navElements = NavigationHelper.getInstance().getAllNavigableElements(semanticElement); + HashMap> possibleCreations = new HashMap>(); + + //test which kind of navigation by consulting preference + String navigationKind=Activator.getDefault().getPreferenceStore().getString(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DOUBLECLICK_KIND); + + //no naviagation + if(navigationKind.equals(INavigationPreferenceConstant.NO_NAVIGATION)){ + //do nothing + return UnexecutableCommand.INSTANCE; + } + + //navigation by using heuristic + //add list of diagram navigables by using heuristic + if(navigationKind.equals(INavigationPreferenceConstant.EXPLICIT_IMPLICIT_NAVIGATION)){ + for(NavigableElement navElement : navElements) { + final EObject element = navElement.getElement(); + if(navElement instanceof ExistingNavigableElement) { + List associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null); + + // ignore the current diagram + associatedDiagrams.remove(gep.getNotationView().getDiagram()); + if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) { + existingDiagrams.put(navElement, associatedDiagrams); + } + } + } + + Iterator> iter=existingDiagrams.values().iterator(); + while(iter.hasNext()) { + List list = (List)iter.next(); + Iterator iterDiagram=list.iterator(); + while(iterDiagram.hasNext()) { + Diagram diagram = (Diagram)iterDiagram.next(); + HyperLinkDiagram hyperLinkDiagram= new HyperLinkDiagram(); + hyperLinkDiagram.setDiagram(diagram); + hyperLinkDiagram.setTooltipText(diagram.getName()+" (found by heuristic)"); + //look for if a hyperlink already exists + HyperlinkObject foundHyperlink=null; + for(int i=0; i1){ + //open a dialog to choose a diagram + DiagramNavigationDialog diagramNavigationDialog= new DiagramNavigationDialog(new Shell(),defaultHyperLinkObject); + diagramNavigationDialog.open(); + final ArrayList hList=diagramNavigationDialog.getSelectedHyperlinks(); + Command command= new Command() { + @Override + public void execute() { + super.execute(); + + Iterator iter= hList.iterator(); + while(iter.hasNext()) { + HyperlinkObject hyperlinkObject = (HyperlinkObject)iter.next(); + hyperlinkObject.executeSelectPressed(); + } + } + }; + return command; + + } + + } + catch (Exception e) { + org.eclipse.papyrus.diagram.common.Activator.log.error("Impossible to load hyperlinks", e); + } + return UnexecutableCommand.INSTANCE; + } + + + /** + * Return the EditorRegistry for nested editor descriptors. Subclass should implements this + * method in order to return the registry associated to the extension point namespace. + * + * @return the EditorRegistry for nested editor descriptors + * + * @generated NOT + */ + protected IPageIconsRegistry createEditorRegistry() { + try { + return EditorUtils.getServiceRegistry().getService(IPageIconsRegistry.class); + } catch (ServiceException e) { + // Return an empty registry always providing null; + return new PageIconsRegistry(); + } + } + + + + + private static ICreationCommandRegistry getCreationCommandRegistry() { + return CreationCommandRegistry.getInstance(org.eclipse.papyrus.core.Activator.PLUGIN_ID); + } + + + +} Index: src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.r4757 =================================================================== --- src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.r4757 (revision 0) +++ src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.r4757 (revision 0) @@ -0,0 +1,255 @@ +/***************************************************************************** + * Copyright (c) 2010 Atos Origin. + * + * + * 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: + * Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation + * Patrick Tessier (CEA LIST)-modification + * + *****************************************************************************/ +package org.eclipse.papyrus.diagram.common.editpolicies; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPolicy; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil; +import org.eclipse.papyrus.core.editorsfactory.IPageIconsRegistry; +import org.eclipse.papyrus.core.editorsfactory.PageIconsRegistry; +import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor; +import org.eclipse.papyrus.core.services.ServiceException; +import org.eclipse.papyrus.core.utils.EditorUtils; +import org.eclipse.papyrus.diagram.common.dialogs.DiagramNavigationDialog; +import org.eclipse.papyrus.diagram.common.helper.AbstractHyperLinkHelper; +import org.eclipse.papyrus.diagram.common.helper.DiagramHyperLinkHelper; +import org.eclipse.papyrus.diagram.common.helper.DocumentHyperLinkHelper; +import org.eclipse.papyrus.diagram.common.helper.HyperlinkHelperFactory; +import org.eclipse.papyrus.diagram.common.helper.WebHyperLinkHelper; +import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.AdvancedHLManager; +import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkDiagram; +import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkManagerShell; +import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperlinkObject; +import org.eclipse.papyrus.navigation.ExistingNavigableElement; +import org.eclipse.papyrus.navigation.NavigableElement; +import org.eclipse.papyrus.navigation.NavigationHelper; +import org.eclipse.papyrus.navigation.preference.INavigationPreferenceConstant; +import org.eclipse.papyrus.preferences.Activator; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Package; + +/** + * This class is used to open a new diagram when the double click is detected. It is dependent of + * papyrus environment + */ +public class NavigationEditPolicy extends OpenEditPolicy { + + public static final String NAVIGATION_POLICY = "NavigationEditPolicy"; + + public NavigationEditPolicy() { + } + + /** + * + * @param element a UML element + * @return the top package of the given element + */ + public static Package topPackage(Element element) { + if(element.getOwner() == null) { + return (Package)element; + } else { + return topPackage(element.getOwner()); + } + } + /** + * + * @param request + * @return get the command to open a new diagram + */ + protected Command getOpenCommand(Request request) { + final IGraphicalEditPart gep; + + //in order to obtain the list of default diagram we need to fin the edit part that refers to default diagram + + //if this a label of a compartment, the good editpart is the parent + if((IGraphicalEditPart)getHost() instanceof CompartmentEditPart ){ + gep=(IGraphicalEditPart)getHost().getParent(); + } + else{ + + gep=(IGraphicalEditPart)getHost(); + } + final EObject semanticElement=gep.resolveSemanticElement(); + + //navigable element by using heuristic + List navElements=null; + + //defaultHyperlinks + final ArrayList defaultHyperLinkObject=new ArrayList(); + final ArrayList hyperLinkObjectList; + //Diagrams that will be found by using heuristic + HashMap> existingDiagrams = new HashMap>(); + + + if(semanticElement==null){ + return UnexecutableCommand.INSTANCE; + } + //initialition of code to extract hyperlinks, in the future to do with extension points + ArrayList hyperLinkHelpers= new ArrayList(); + hyperLinkHelpers.add(new DiagramHyperLinkHelper()); + hyperLinkHelpers.add(new DocumentHyperLinkHelper()); + hyperLinkHelpers.add(new WebHyperLinkHelper()); + + final HyperlinkHelperFactory hyperlinkHelperFactory= new HyperlinkHelperFactory(hyperLinkHelpers); + + try{ + //fill the list of default hyperlinks + hyperLinkObjectList = (ArrayList)hyperlinkHelperFactory.getAllreferenced(gep.getNotationView()); + + Iterator iterator= hyperLinkObjectList.iterator(); + while(iterator.hasNext()) { + HyperlinkObject hyperlinkObject = (HyperlinkObject)iterator.next(); + if( hyperlinkObject.getIsDefault()){ + + defaultHyperLinkObject.add(hyperlinkObject); + } + + } + + //fill navigation by using heuristics + navElements = NavigationHelper.getInstance().getAllNavigableElements(semanticElement); + HashMap> possibleCreations = new HashMap>(); + + //test which kind of navigation by consulting preference + String navigationKind=Activator.getDefault().getPreferenceStore().getString(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DOUBLECLICK_KIND); + + //no naviagation + if(navigationKind.equals(INavigationPreferenceConstant.NO_NAVIGATION)){ + //do nothing + return UnexecutableCommand.INSTANCE; + } + + //navigation by using heuristic + //add list of diagram navigables by using heuristic + if(navigationKind.equals(INavigationPreferenceConstant.EXPLICIT_IMPLICIT_NAVIGATION)){ + for(NavigableElement navElement : navElements) { + final EObject element = navElement.getElement(); + if(navElement instanceof ExistingNavigableElement) { + List associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null); + + // ignore the current diagram + associatedDiagrams.remove(gep.getNotationView().getDiagram()); + if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) { + existingDiagrams.put(navElement, associatedDiagrams); + } + } + } + + Iterator> iter=existingDiagrams.values().iterator(); + while(iter.hasNext()) { + List list = (List)iter.next(); + Iterator iterDiagram=list.iterator(); + while(iterDiagram.hasNext()) { + Diagram diagram = (Diagram)iterDiagram.next(); + HyperLinkDiagram hyperLinkDiagram= new HyperLinkDiagram(); + hyperLinkDiagram.setDiagram(diagram); + hyperLinkDiagram.setTooltipText(diagram.getName()+" (found by heuristic)"); + //look for if a hyperlink already exists + HyperlinkObject foundHyperlink=null; + for(int i=0; i1){ + //open a dialog to choose a diagram + DiagramNavigationDialog diagramNavigationDialog= new DiagramNavigationDialog(new Shell(),defaultHyperLinkObject); + diagramNavigationDialog.open(); + final ArrayList hList=diagramNavigationDialog.getSelectedHyperlinks(); + Command command= new Command() { + @Override + public void execute() { + super.execute(); + + Iterator iter= hList.iterator(); + while(iter.hasNext()) { + HyperlinkObject hyperlinkObject = (HyperlinkObject)iter.next(); + hyperlinkObject.executeSelectPressed(); + } + } + }; + return command; + + } + + } + catch (Exception e) { + org.eclipse.papyrus.diagram.common.Activator.log.error("Impossible to load hyperlinks", e); + } + return UnexecutableCommand.INSTANCE; + } + + + /** + * Return the EditorRegistry for nested editor descriptors. Subclass should implements this + * method in order to return the registry associated to the extension point namespace. + * + * @return the EditorRegistry for nested editor descriptors + * + * @generated NOT + */ + protected IPageIconsRegistry createEditorRegistry() { + try { + return EditorUtils.getServiceRegistry().getService(IPageIconsRegistry.class); + } catch (ServiceException e) { + // Return an empty registry always providing null; + return new PageIconsRegistry(); + } + } + +} Index: src/org/eclipse/papyrus/diagram/common/providers/DiagramDecorationAdapter.java =================================================================== --- src/org/eclipse/papyrus/diagram/common/providers/DiagramDecorationAdapter.java (revision 0) +++ src/org/eclipse/papyrus/diagram/common/providers/DiagramDecorationAdapter.java (revision 0) @@ -0,0 +1,295 @@ +/***************************************************************************** + * Copyright (c) 2011 CEA LIST. + * + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Amine EL KOUHEN (CEA LIST/LIFL) - Amine.Elkouhen@cea.fr + *****************************************************************************/ +package org.eclipse.papyrus.diagram.common.providers; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget.Direction; +import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.decoration.util.Decoration.PreferedPosition; +import org.eclipse.swt.graphics.Image; + + +// TODO: Auto-generated Javadoc +/** + * The Class DiagramDecorationAdapter. + */ +public class DiagramDecorationAdapter { + + /** The decorator target. */ + protected IDecoratorTarget decoratorTarget; + + + /** The decoration. */ + protected IDecoration decoration; + + + /** The decoration image. */ + protected Image decorationImage; + + + + /** + * Instantiates a new diagram decoration adapter. + * + * @param decoratorTarget the decorator target + */ + public DiagramDecorationAdapter(IDecoratorTarget decoratorTarget) { + this.decoratorTarget = decoratorTarget; + } + + /** + * Gets the decoration. + * + * @return the decoration + */ + public IDecoration getDecoration() { + return this.decoration; + } + + /** + * Gets the decorator target. + * + * @return the decorator target + */ + public IDecoratorTarget getDecoratorTarget() { + return this.decoratorTarget; + } + + /** + * Removes the decoration. + */ + public void removeDecoration() { + if(getDecoration() == null || getDecoratorTarget() == null) { + return; + } + removeDecoration(getDecoratorTarget(), getDecoration()); + + } + + /** + * Removes the decoration. + * + * @param decoration the decoration + */ + public void removeDecoration(IDecoration decoration) { + if(decoration == null || getDecoratorTarget() == null) { + return; + } + removeDecoration(getDecoratorTarget(), decoration); + + } + + /** + * Sets the decoration. + * + * @param image the image + * @param position the position + * @param percentageFromSource the percentage from source + * @param margin the margin + * @param isVolatile the is volatile + * @return the i decoration + */ + public IDecoration setDecoration(Image image, PreferedPosition position, int percentageFromSource, int margin, boolean isVolatile) { + this.decoration = getDecoration(getDecoratorTarget(), image, position, percentageFromSource, margin, isVolatile); + this.decorationImage = image; + return getDecoration(); + } + + /** + * Sets the decoration. + * + * @param figure the figure + * @param position the position + * @param percentageFromSource the percentage from source + * @param margin the margin + * @param isVolatile the is volatile + * @return the i decoration + */ + public IDecoration setDecoration(IFigure figure, PreferedPosition position, int percentageFromSource, int margin, boolean isVolatile) { + this.decoration = getDecoration(getDecoratorTarget(), figure, position, percentageFromSource, margin, isVolatile); + return getDecoration(); + } + + /** + * Sets the decorator target. + * + * @param decoratorTarget the new decorator target + */ + public void setDecoratorTarget(IDecoratorTarget decoratorTarget) { + this.decoratorTarget = decoratorTarget; + } + + /** + * Gets the decoration image. + * + * @return the decoration image + */ + public Image getDecorationImage() { + return decorationImage; + } + + /** + * Gets the tool tip. + * + * @param message the message + * @return the tool tip + */ + public Label getToolTip(String message) { + return new Label(message, getDecorationImage()); + } + + /** + * Sets the decoration. + * + * @param idecoration the idecoration + * @param percentageFromSource the percentage from source + * @param margin the margin + * @param isVolatile the is volatile + * @return the i decoration + */ + public IDecoration setDecoration(org.eclipse.papyrus.decoration.util.IDecoration idecoration, int percentageFromSource, int margin, boolean isVolatile) { + + this.decorationImage = (idecoration.getDecorationImage() != null) ? idecoration.getDecorationImage().createImage() : null; + this.decoration = getDecoration(getDecoratorTarget(), getDecorationImage(), idecoration.getPosition(), percentageFromSource, margin, isVolatile); + + return getDecoration(); + } + + /** + * Removes the decoration. + * + * @param decoratorTarget the decorator target + * @param Decoration the decoration + */ + public void removeDecoration(IDecoratorTarget decoratorTarget, org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration Decoration) { + if(Decoration instanceof IFigure) { + ((IFigure)Decoration).getParent().remove((IFigure)Decoration); + } + GraphicalEditPart ownerEditPart = (GraphicalEditPart)decoratorTarget.getAdapter(GraphicalEditPart.class); + ownerEditPart.getViewer().getVisualPartMap().remove(Decoration); + + } + + /** + * Gets the decoration. + * + * @param decoratorTarget the decorator target + * @param image the image + * @param position the position + * @param percentageFromSource the percentage from source + * @param margin the margin + * @param isVolatile the is volatile + * @return the decoration + */ + public org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration getDecoration(IDecoratorTarget decoratorTarget, Image image, PreferedPosition position, int percentageFromSource, int margin, boolean isVolatile) { + View view = (View)decoratorTarget.getAdapter(View.class); + org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration decoration = null; + if(view == null || view.eResource() == null || image == null) { + return decoration; + } + EditPart editPart = (EditPart)decoratorTarget.getAdapter(EditPart.class); + if(editPart == null || editPart.getViewer() == null) { + return decoration; + } + if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { + if(view instanceof Edge) { + decoration = decoratorTarget.addConnectionDecoration(image, percentageFromSource, isVolatile); + } else { + if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { + margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart)editPart).getFigure()).DPtoLP(margin); + } + decoration = decoratorTarget.addShapeDecoration(image, getDirection(position), margin, isVolatile); + } + + } + return decoration; + } + + /** + * Gets the direction. + * + * @param position the position + * @return the direction + */ + private Direction getDirection(PreferedPosition position) { + + switch(position) { + + case NORTH_WEST: + return IDecoratorTarget.Direction.NORTH_WEST; + case NORTH: + return IDecoratorTarget.Direction.NORTH; + case NORTH_EAST: + return IDecoratorTarget.Direction.NORTH_EAST; + case EAST: + return IDecoratorTarget.Direction.EAST; + case SOUTH_EAST: + return IDecoratorTarget.Direction.SOUTH_EAST; + case SOUTH: + return IDecoratorTarget.Direction.SOUTH; + case SOUTH_WEST: + return IDecoratorTarget.Direction.SOUTH_WEST; + case WEST: + return IDecoratorTarget.Direction.WEST; + case CENTER: + return IDecoratorTarget.Direction.CENTER; + default: + return IDecoratorTarget.Direction.NORTH_EAST; + + } + } + + /** + * Gets the decoration. + * + * @param decoratorTarget the decorator target + * @param figure the figure + * @param position the position + * @param percentageFromSource the percentage from source + * @param margin the margin + * @param isVolatile the is volatile + * @return the decoration + */ + public org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration getDecoration(IDecoratorTarget decoratorTarget, IFigure figure, PreferedPosition position, int percentageFromSource, int margin, boolean isVolatile) { + + View view = (View)decoratorTarget.getAdapter(View.class); + org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration decoration = null; + if(view == null || view.eResource() == null || figure == null) { + return decoration; + } + EditPart editPart = (EditPart)decoratorTarget.getAdapter(EditPart.class); + if(editPart == null || editPart.getViewer() == null) { + return decoration; + } + if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { + if(view instanceof Edge) { + decoration = decoratorTarget.addConnectionDecoration(figure, percentageFromSource, isVolatile); + } else { + if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { + margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart)editPart).getFigure()).DPtoLP(margin); + } + decoration = decoratorTarget.addShapeDecoration(figure, getDirection(position), margin, isVolatile); + } + + } + return decoration; + } + +} Index: src/org/eclipse/papyrus/diagram/common/providers/ValidationDecoratorProvider.java =================================================================== --- src/org/eclipse/papyrus/diagram/common/providers/ValidationDecoratorProvider.java (revision 4757) +++ src/org/eclipse/papyrus/diagram/common/providers/ValidationDecoratorProvider.java (working copy) @@ -11,43 +11,37 @@ * Ansgar Radermacher (CEA LIST) - added support for EMF validation * bug fix and re-factoring (separating common class) * specific version for Papyrus + * Amine EL KOUHEN (CEA LIST) - Added decoration Service */ - package org.eclipse.papyrus.diagram.common.providers; +package org.eclipse.papyrus.diagram.common.providers; import static org.eclipse.papyrus.core.Activator.log; import java.util.HashMap; import java.util.Map; +import java.util.Observable; +import java.util.Observer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.draw2d.FlowLayout; import org.eclipse.draw2d.Label; -import org.eclipse.emf.common.util.BasicEList; -import org.eclipse.emf.common.util.EList; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.EValidator; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.util.TransactionUtil; -import org.eclipse.emf.workspace.util.WorkspaceSynchronizer; import org.eclipse.gef.EditPart; import org.eclipse.gmf.runtime.common.core.service.AbstractProvider; import org.eclipse.gmf.runtime.common.core.service.IOperation; -import org.eclipse.gmf.runtime.common.ui.resources.FileChangeManager; -import org.eclipse.gmf.runtime.common.ui.resources.IFileObserver; import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; +import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator; +import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider; import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget; import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil; import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.diagram.common.util.CrossReferencerUtil; -import org.eclipse.papyrus.validation.ValidationUtils; -import org.eclipse.swt.graphics.Image; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.papyrus.core.services.ServicesRegistry; +import org.eclipse.papyrus.decoration.DecorationService; +import org.eclipse.papyrus.diagram.common.util.ServiceUtilsForGMF; import org.eclipse.ui.ISharedImages; import org.eclipse.ui.PlatformUI; @@ -56,32 +50,24 @@ */ public abstract class ValidationDecoratorProvider extends AbstractProvider implements IDecoratorProvider { - protected static final String KEY = "validationStatus"; //$NON-NLS-1$ - - /** - * generic marker for GMF validation (currently not used) - */ - private static final String MARKER_TYPE = "org.eclipse.papyrus.diagram.common.diagnostic"; //$NON-NLS-1$ + protected static final String KEY = "validationStatus"; //$NON-NLS-1$ - /** - * global map of fileObserver par editing domain - */ - private static Map fileObservers = new HashMap(); + private static Map allDecorators = new HashMap(); - private static Map allDecorators = new HashMap (); - /** * Refined by generated class + * * @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider#createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget) - * + * * @param decoratorTarget */ - public abstract void createDecorators (IDecoratorTarget decoratorTarget); + public abstract void createDecorators(IDecoratorTarget decoratorTarget); /** * Refined by generated class + * * @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation) - * + * * @param operation * @return */ @@ -89,6 +75,7 @@ /** * Refresh the decorators of a specific view + * * @param view */ public static void refreshDecorators(View view) { @@ -100,7 +87,7 @@ */ private static void refreshDecorators(String viewId, final TransactionalEditingDomain domain) { final IDecorator decorator = viewId != null ? allDecorators.get(viewId) : null; - if (decorator == null || domain == null) { + if(decorator == null || domain == null) { return; } PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { @@ -120,7 +107,7 @@ }); } - public static class StatusDecorator extends AbstractDecorator { + public static class StatusDecorator extends AbstractDecorator implements Observer { /** * The ID of the view @@ -133,12 +120,29 @@ private TransactionalEditingDomain editingDomain; /** + * Decoration Service + */ + private DecorationService decorationService; + + /** + * Diagram Decorator + */ + private final DiagramDecorationAdapter diagramDecorationAdapter; + + /** * @generated */ public StatusDecorator(IDecoratorTarget decoratorTarget) { super(decoratorTarget); + diagramDecorationAdapter = new DiagramDecorationAdapter(decoratorTarget); try { final View view = (View)getDecoratorTarget().getAdapter(View.class); + EditPart editPart = (EditPart)getDecoratorTarget().getAdapter(EditPart.class); + IDiagramEditDomain domain = (IDiagramEditDomain)editPart.getViewer().getEditDomain(); + ServicesRegistry serviceRegistry = ServiceUtilsForGMF.getInstance().getServiceRegistry(domain); + decorationService = serviceRegistry.getService(DecorationService.class); + //Register As an Decoration service customer + decorationService.addListener(this); TransactionUtil.getEditingDomain(view).runExclusive(new Runnable() { public void run() { @@ -157,6 +161,7 @@ * @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator#refresh() */ public void refresh() { + removeDecoration(); View view = (View)getDecoratorTarget().getAdapter(View.class); if(view == null || view.eResource() == null) { @@ -166,114 +171,47 @@ if(editPart == null || editPart.getViewer() == null) { return; } - - // query for all the validation markers of the current resource - String elementId = ViewUtil.getIdStr(view); - if(elementId == null) { - return; - } - int severity = IMarker.SEVERITY_INFO; - IMarker foundMarker = null; - IResource gmfResource = WorkspaceSynchronizer.getFile(view.eResource()); - if(gmfResource == null || !gmfResource.exists()) { - return; - } - IResource emfResource = null; - if(view.getElement() != null) { - emfResource = WorkspaceSynchronizer.getFile(view.getElement().eResource()); - // allow emfResource being empty, since there might be gmf views without an EObject behind; - } - - IMarker[] gmfMarkers = null; - IMarker[] emfMarkers = new IMarker[0]; - try { - gmfMarkers = gmfResource.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE); - if(emfResource != null) { - emfMarkers = emfResource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); - } - } catch (CoreException e) { - log.error("Validation markers refresh failure", e); //$NON-NLS-1$ - } - if(gmfMarkers == null) { - // indicates an exception, findMarkers returns an empty array, if there are no markers - return; - } - Label toolTip = null; - // look for GMF markers - for(int i = 0; i < gmfMarkers.length + emfMarkers.length; i++) { - IMarker marker; - boolean markerIsForMe = false; - if(i < gmfMarkers.length) { - // get marker from GMF list - marker = gmfMarkers[i]; - String attribute = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); //$NON-NLS-1$ - markerIsForMe = attribute.equals(elementId); - } else { - // get marker from EMF list - marker = emfMarkers[i - gmfMarkers.length]; - EObject eObjectOfMarker = ValidationUtils.eObjectFromMarkerOrMap(marker, null, editingDomain); - markerIsForMe = (eObjectOfMarker == view.getElement()); - } - if(markerIsForMe) { - int nextSeverity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); - Image nextImage = getImage(nextSeverity); - if(foundMarker == null) { - foundMarker = marker; - toolTip = new Label(marker.getAttribute(IMarker.MESSAGE, ""), //$NON-NLS-1$ - nextImage); - } else { - if(toolTip.getChildren().isEmpty()) { - Label comositeLabel = new Label(); - FlowLayout fl = new FlowLayout(false); - fl.setMinorSpacing(0); - comositeLabel.setLayoutManager(fl); - comositeLabel.add(toolTip); - toolTip = comositeLabel; - } - toolTip.add(new Label(marker.getAttribute(IMarker.MESSAGE, ""), //$NON-NLS-1$ - nextImage)); - } - severity = (nextSeverity > severity) ? nextSeverity : severity; - } - } - if(foundMarker == null) { - return; - } - // add decoration + IDecoration deco = null; + org.eclipse.papyrus.decoration.util.IDecoration decoration = null; if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { + decoration = decorationService.getDecoration(view.getElement(), false); + decoration.setDecorationImage(getImageDescriptor(decoration.getSeverity())); if(view instanceof Edge) { - setDecoration(getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true)); + /* Test *///decoration.setDecorationImage(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/obj16/Device.gif")); + deco = diagramDecorationAdapter.setDecoration(decoration, 50, 0, true); } else { int margin = -1; if(editPart instanceof org.eclipse.gef.GraphicalEditPart) { margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart)editPart).getFigure()).DPtoLP(margin); } - setDecoration(getDecoratorTarget().addShapeDecoration(getImage(severity), IDecoratorTarget.Direction.NORTH_EAST, margin, true)); + deco = diagramDecorationAdapter.setDecoration(decoration, 0, margin, true); } + } + + + if(deco != null) { + setDecoration(deco); + String message = decoration.getMessage(); + Label toolTip = diagramDecorationAdapter.getToolTip(message); getDecoration().setToolTip(toolTip); } } - - /** - * Get the image for a given severity - * @param severity - * @return - */ - private Image getImage(int severity) { - String imageName = ISharedImages.IMG_OBJS_ERROR_TSK; + private ImageDescriptor getImageDescriptor(int severity) { + + ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); + ImageDescriptor overlay = null; switch(severity) { - case IMarker.SEVERITY_ERROR: - imageName = ISharedImages.IMG_OBJS_ERROR_TSK; + case 2://Error + overlay = sharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_ERROR_TSK); break; - case IMarker.SEVERITY_WARNING: - imageName = ISharedImages.IMG_OBJS_WARN_TSK; + case 1://Warning + overlay = sharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_WARN_TSK); break; - default: - imageName = ISharedImages.IMG_OBJS_INFO_TSK; } - return PlatformUI.getWorkbench().getSharedImages().getImage(imageName); + + return overlay; } /** @@ -287,29 +225,15 @@ // add self to global decorators registry IDecorator decorator = allDecorators.get(viewId); - if (decorator == null) { + if(decorator == null) { allDecorators.put(viewId, this); } - - // stop listening to changes in resources if there are no more decorators - MarkerObserver fileObserver = fileObservers.get(editingDomain); - if (fileObserver == null) { - fileObserver = new MarkerObserver(editingDomain); - fileObservers.put(editingDomain, fileObserver); - FileChangeManager.getInstance().addFileObserver(fileObserver); - } - // start listening to changes in resources - View view = (View) getDecoratorTarget().getAdapter(View.class); - if(view != null) { - if (!fileObserver.views.contains(view)) { - fileObserver.views.add(view); - } - } } /** * deactivate the decorators of this view */ + @Override public void deactivate() { if(viewId == null) { return; @@ -317,129 +241,20 @@ // remove self from global decorators registry allDecorators.remove(viewId); - + View view = (View)getDecoratorTarget().getAdapter(View.class); - if ((view == null) || (editingDomain == null)) { + if((view == null) || (editingDomain == null)) { // should not happen super.deactivate(); return; } - - // stop listening to changes in resources if there are no more decorators - MarkerObserver fileObserver = fileObservers.get(editingDomain); - if (fileObserver != null) { - fileObserver.views.remove(view); - if (fileObserver.views.isEmpty()) { - // no more views registered for the listener => remove observer - FileChangeManager.getInstance().removeFileObserver(fileObserver); - fileObservers.remove(editingDomain); - } - } - super.deactivate(); } - } - /** - * @generated - */ - static class MarkerObserver implements IFileObserver { - - /** - * store editing domain - */ - private TransactionalEditingDomain domain; - - /** - * store a list of all views for which the observer is responsible - */ - private EList views = new BasicEList(); - - /** - * Constructor. - * - * @param domain - */ - private MarkerObserver(TransactionalEditingDomain domain) { - this.domain = domain; + //Refresh when the decoration service add a decoration + public void update(Observable o, Object arg) { + refresh(); } - - /** - * handle changes of file name - */ - public void handleFileRenamed(IFile oldFile, IFile file) { - } - - public void handleFileMoved(IFile oldFile, IFile file) { - } - - public void handleFileDeleted(IFile file) { - } - - public void handleFileChanged(IFile file) { - } - - /** - * A marker has been added, treat as change - */ - public void handleMarkerAdded(IMarker marker) { - handleMarkerChanged(marker); - } - - /** - * A marker has been deleted. Need to treat separately from change, since old values are not stored in - * marker, but in attribute map - */ - public void handleMarkerDeleted(IMarker marker, @SuppressWarnings("rawtypes") Map attributes) { - String viewId = (String)attributes.get(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID); - if(viewId != null) { - refreshDecorators(viewId, domain); - } else { - // no viewID => assume EMF validation marker - EObject eObjectFromMarker = ValidationUtils.eObjectFromMarkerOrMap(null, attributes, domain); - - if(eObjectFromMarker != null) { - // loop over all views that reference the eObject from the marker - for(View view : CrossReferencerUtil.getCrossReferencingViews(eObjectFromMarker, null)) { - refreshDecorators(view); - } - } - } - } - - /** - * A marker has changed - */ - public void handleMarkerChanged(IMarker marker) { - try { - if(getType(marker).equals(MARKER_TYPE)) { - String viewId = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); //$NON-NLS-1$ - refreshDecorators(viewId, domain); - } else if(marker.isSubtypeOf((EValidator.MARKER))) { - EObject eObjectFromMarker = ValidationUtils.eObjectFromMarkerOrMap(marker, null, domain); - - if(eObjectFromMarker != null) { - // loop over all views that reference the eObject from the marker - for(View view : CrossReferencerUtil.getCrossReferencingViews(eObjectFromMarker, null)) { - refreshDecorators(view); - } - } - } - } catch (CoreException e) { - // only reason: marker does not exist (ignore, should not happen) - } - } - - /** - * Return the type of a marker - */ - private String getType(IMarker marker) { - try { - return marker.getType(); - } catch (CoreException e) { - log.error("Validation marker refresh failure", e); //$NON-NLS-1$ - return ""; //$NON-NLS-1$ - } - } } + }