View | Details | Raw Unified | Return to bug 325610 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (+5 lines)
Lines 68-75 Link Here
68
 org.eclipse.papyrus.validation;bundle-version="0.8.0",
68
 org.eclipse.papyrus.validation;bundle-version="0.8.0",
69
 org.eclipse.papyrus.extendedtypes;bundle-version="0.8.0";visibility:=reexport,
69
 org.eclipse.papyrus.extendedtypes;bundle-version="0.8.0";visibility:=reexport,
70
 org.eclipse.papyrus.service.edit;bundle-version="0.8.0";visibility:=reexport,
70
 org.eclipse.papyrus.service.edit;bundle-version="0.8.0";visibility:=reexport,
71
<<<<<<< .mine
72
 org.eclipse.papyrus.navigation;bundle-version="0.8.0",
73
 org.eclipse.papyrus.decoration;bundle-version="0.8.0"
74
=======
71
 org.eclipse.papyrus.navigation;bundle-version="0.8.0";visibility:=reexport,
75
 org.eclipse.papyrus.navigation;bundle-version="0.8.0";visibility:=reexport,
72
 org.eclipse.papyrus.navigation.uml;bundle-version="0.8.0"
76
 org.eclipse.papyrus.navigation.uml;bundle-version="0.8.0"
77
>>>>>>> .r4757
73
Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
78
Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
74
Ant-Version: Apache Ant 1.7.0
79
Ant-Version: Apache Ant 1.7.0
75
Bundle-ActivationPolicy: lazy
80
Bundle-ActivationPolicy: lazy
(-)META-INF/MANIFEST.MF.mine (+77 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.papyrus.diagram.common;singleton:=true
5
Bundle-Version: 0.8.0.qualifier
6
Bundle-ClassPath: .
7
Bundle-Vendor: %providerName
8
Bundle-Localization: plugin
9
Export-Package: org.eclipse.papyrus.diagram.common,
10
 org.eclipse.papyrus.diagram.common.actions,
11
 org.eclipse.papyrus.diagram.common.actions.handlers,
12
 org.eclipse.papyrus.diagram.common.command.wrappers,
13
 org.eclipse.papyrus.diagram.common.commands,
14
 org.eclipse.papyrus.diagram.common.dialogs,
15
 org.eclipse.papyrus.diagram.common.directedit,
16
 org.eclipse.papyrus.diagram.common.draw2d,
17
 org.eclipse.papyrus.diagram.common.draw2d.anchors,
18
 org.eclipse.papyrus.diagram.common.editparts,
19
 org.eclipse.papyrus.diagram.common.editpolicies,
20
 org.eclipse.papyrus.diagram.common.figure.edge,
21
 org.eclipse.papyrus.diagram.common.figure.layout,
22
 org.eclipse.papyrus.diagram.common.figure.node,
23
 org.eclipse.papyrus.diagram.common.handlers,
24
 org.eclipse.papyrus.diagram.common.helper,
25
 org.eclipse.papyrus.diagram.common.ids,
26
 org.eclipse.papyrus.diagram.common.layout,
27
 org.eclipse.papyrus.diagram.common.listeners,
28
 org.eclipse.papyrus.diagram.common.locator,
29
 org.eclipse.papyrus.diagram.common.parser,
30
 org.eclipse.papyrus.diagram.common.parser.assist,
31
 org.eclipse.papyrus.diagram.common.parser.custom,
32
 org.eclipse.papyrus.diagram.common.parser.lookup,
33
 org.eclipse.papyrus.diagram.common.parser.packageimport,
34
 org.eclipse.papyrus.diagram.common.parser.stereotype,
35
 org.eclipse.papyrus.diagram.common.parser.structural,
36
 org.eclipse.papyrus.diagram.common.part,
37
 org.eclipse.papyrus.diagram.common.preferences,
38
 org.eclipse.papyrus.diagram.common.providers,
39
 org.eclipse.papyrus.diagram.common.providers.assistant,
40
 org.eclipse.papyrus.diagram.common.resourceupdate,
41
 org.eclipse.papyrus.diagram.common.service,
42
 org.eclipse.papyrus.diagram.common.service.palette,
43
 org.eclipse.papyrus.diagram.common.sheet,
44
 org.eclipse.papyrus.diagram.common.ui.dialogs,
45
 org.eclipse.papyrus.diagram.common.ui.helper,
46
 org.eclipse.papyrus.diagram.common.ui.hyperlinkshell,
47
 org.eclipse.papyrus.diagram.common.util
48
Require-Bundle: org.eclipse.uml2.uml.edit;visibility:=reexport,
49
 org.eclipse.papyrus.core;bundle-version="0.8.0";visibility:=reexport,
50
 org.eclipse.gmf.runtime.diagram.ui.resources.editor,
51
 org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.1.0",
52
 org.eclipse.papyrus.extensionpoints.editors;bundle-version="0.8.0",
53
 org.eclipse.papyrus.umlutils;bundle-version="0.8.0";visibility:=reexport,
54
 org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.2.0",
55
 org.eclipse.papyrus.wizards;bundle-version="0.8.0",
56
 org.eclipse.papyrus.log;bundle-version="0.8.0";visibility:=reexport,
57
 org.eclipse.papyrus.ui.toolbox;bundle-version="0.8.0",
58
 org.eclipse.core.databinding;bundle-version="1.2.0",
59
 org.eclipse.papyrus.editor;bundle-version="0.8.0",
60
 org.eclipse.gmf.runtime.diagram.ui.render;bundle-version="1.3.0",
61
 org.eclipse.papyrus.pastemanager;bundle-version="0.8.0",
62
 org.eclipse.ui,
63
 org.eclipse.papyrus.core.adaptor.gmf;bundle-version="0.8.0",
64
 org.eclipse.papyrus.preferences;bundle-version="0.8.0",
65
 org.eclipse.gmf.runtime.diagram.ui.actions,
66
 org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="1.4.0",
67
 org.eclipse.core.expressions,
68
 org.eclipse.papyrus.validation;bundle-version="0.8.0",
69
 org.eclipse.papyrus.extendedtypes;bundle-version="0.8.0";visibility:=reexport,
70
 org.eclipse.papyrus.service.edit;bundle-version="0.8.0";visibility:=reexport,
71
 org.eclipse.papyrus.navigation;bundle-version="0.8.0",
72
 org.eclipse.papyrus.decoration;bundle-version="0.8.0"
73
Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
74
Ant-Version: Apache Ant 1.7.0
75
Bundle-ActivationPolicy: lazy
76
Bundle-RequiredExecutionEnvironment: J2SE-1.5
77
Bundle-Activator: org.eclipse.papyrus.diagram.common.Activator
(-)META-INF/MANIFEST.MF.r4629 (+76 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.papyrus.diagram.common;singleton:=true
5
Bundle-Version: 0.8.0.qualifier
6
Bundle-ClassPath: .
7
Bundle-Vendor: %providerName
8
Bundle-Localization: plugin
9
Export-Package: org.eclipse.papyrus.diagram.common,
10
 org.eclipse.papyrus.diagram.common.actions,
11
 org.eclipse.papyrus.diagram.common.actions.handlers,
12
 org.eclipse.papyrus.diagram.common.command.wrappers,
13
 org.eclipse.papyrus.diagram.common.commands,
14
 org.eclipse.papyrus.diagram.common.dialogs,
15
 org.eclipse.papyrus.diagram.common.directedit,
16
 org.eclipse.papyrus.diagram.common.draw2d,
17
 org.eclipse.papyrus.diagram.common.draw2d.anchors,
18
 org.eclipse.papyrus.diagram.common.editparts,
19
 org.eclipse.papyrus.diagram.common.editpolicies,
20
 org.eclipse.papyrus.diagram.common.figure.edge,
21
 org.eclipse.papyrus.diagram.common.figure.layout,
22
 org.eclipse.papyrus.diagram.common.figure.node,
23
 org.eclipse.papyrus.diagram.common.handlers,
24
 org.eclipse.papyrus.diagram.common.helper,
25
 org.eclipse.papyrus.diagram.common.ids,
26
 org.eclipse.papyrus.diagram.common.layout,
27
 org.eclipse.papyrus.diagram.common.listeners,
28
 org.eclipse.papyrus.diagram.common.locator,
29
 org.eclipse.papyrus.diagram.common.parser,
30
 org.eclipse.papyrus.diagram.common.parser.assist,
31
 org.eclipse.papyrus.diagram.common.parser.custom,
32
 org.eclipse.papyrus.diagram.common.parser.lookup,
33
 org.eclipse.papyrus.diagram.common.parser.packageimport,
34
 org.eclipse.papyrus.diagram.common.parser.stereotype,
35
 org.eclipse.papyrus.diagram.common.parser.structural,
36
 org.eclipse.papyrus.diagram.common.part,
37
 org.eclipse.papyrus.diagram.common.preferences,
38
 org.eclipse.papyrus.diagram.common.providers,
39
 org.eclipse.papyrus.diagram.common.providers.assistant,
40
 org.eclipse.papyrus.diagram.common.resourceupdate,
41
 org.eclipse.papyrus.diagram.common.service,
42
 org.eclipse.papyrus.diagram.common.service.palette,
43
 org.eclipse.papyrus.diagram.common.sheet,
44
 org.eclipse.papyrus.diagram.common.ui.dialogs,
45
 org.eclipse.papyrus.diagram.common.ui.helper,
46
 org.eclipse.papyrus.diagram.common.ui.hyperlinkshell,
47
 org.eclipse.papyrus.diagram.common.util
48
Require-Bundle: org.eclipse.uml2.uml.edit;visibility:=reexport,
49
 org.eclipse.papyrus.core;bundle-version="0.8.0";visibility:=reexport,
50
 org.eclipse.gmf.runtime.diagram.ui.resources.editor,
51
 org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.1.0",
52
 org.eclipse.papyrus.extensionpoints.editors;bundle-version="0.8.0",
53
 org.eclipse.papyrus.umlutils;bundle-version="0.8.0";visibility:=reexport,
54
 org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.2.0",
55
 org.eclipse.papyrus.wizards;bundle-version="0.8.0",
56
 org.eclipse.papyrus.log;bundle-version="0.8.0";visibility:=reexport,
57
 org.eclipse.papyrus.ui.toolbox;bundle-version="0.8.0",
58
 org.eclipse.core.databinding;bundle-version="1.2.0",
59
 org.eclipse.papyrus.editor;bundle-version="0.8.0",
60
 org.eclipse.gmf.runtime.diagram.ui.render;bundle-version="1.3.0",
61
 org.eclipse.papyrus.pastemanager;bundle-version="0.8.0",
62
 org.eclipse.ui,
63
 org.eclipse.papyrus.core.adaptor.gmf;bundle-version="0.8.0",
64
 org.eclipse.papyrus.preferences;bundle-version="0.8.0",
65
 org.eclipse.gmf.runtime.diagram.ui.actions,
66
 org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="1.4.0",
67
 org.eclipse.core.expressions,
68
 org.eclipse.papyrus.validation;bundle-version="0.8.0",
69
 org.eclipse.papyrus.extendedtypes;bundle-version="0.8.0";visibility:=reexport,
70
 org.eclipse.papyrus.service.edit;bundle-version="0.8.0";visibility:=reexport,
71
 org.eclipse.papyrus.navigation;bundle-version="0.8.0"
72
Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
73
Ant-Version: Apache Ant 1.7.0
74
Bundle-ActivationPolicy: lazy
75
Bundle-RequiredExecutionEnvironment: J2SE-1.5
76
Bundle-Activator: org.eclipse.papyrus.diagram.common.Activator
(-)META-INF/MANIFEST.MF.r4757 (+77 lines)
Line 0 Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.papyrus.diagram.common;singleton:=true
5
Bundle-Version: 0.8.0.qualifier
6
Bundle-ClassPath: .
7
Bundle-Vendor: %providerName
8
Bundle-Localization: plugin
9
Export-Package: org.eclipse.papyrus.diagram.common,
10
 org.eclipse.papyrus.diagram.common.actions,
11
 org.eclipse.papyrus.diagram.common.actions.handlers,
12
 org.eclipse.papyrus.diagram.common.command.wrappers,
13
 org.eclipse.papyrus.diagram.common.commands,
14
 org.eclipse.papyrus.diagram.common.dialogs,
15
 org.eclipse.papyrus.diagram.common.directedit,
16
 org.eclipse.papyrus.diagram.common.draw2d,
17
 org.eclipse.papyrus.diagram.common.draw2d.anchors,
18
 org.eclipse.papyrus.diagram.common.editparts,
19
 org.eclipse.papyrus.diagram.common.editpolicies,
20
 org.eclipse.papyrus.diagram.common.figure.edge,
21
 org.eclipse.papyrus.diagram.common.figure.layout,
22
 org.eclipse.papyrus.diagram.common.figure.node,
23
 org.eclipse.papyrus.diagram.common.handlers,
24
 org.eclipse.papyrus.diagram.common.helper,
25
 org.eclipse.papyrus.diagram.common.ids,
26
 org.eclipse.papyrus.diagram.common.layout,
27
 org.eclipse.papyrus.diagram.common.listeners,
28
 org.eclipse.papyrus.diagram.common.locator,
29
 org.eclipse.papyrus.diagram.common.parser,
30
 org.eclipse.papyrus.diagram.common.parser.assist,
31
 org.eclipse.papyrus.diagram.common.parser.custom,
32
 org.eclipse.papyrus.diagram.common.parser.lookup,
33
 org.eclipse.papyrus.diagram.common.parser.packageimport,
34
 org.eclipse.papyrus.diagram.common.parser.stereotype,
35
 org.eclipse.papyrus.diagram.common.parser.structural,
36
 org.eclipse.papyrus.diagram.common.part,
37
 org.eclipse.papyrus.diagram.common.preferences,
38
 org.eclipse.papyrus.diagram.common.providers,
39
 org.eclipse.papyrus.diagram.common.providers.assistant,
40
 org.eclipse.papyrus.diagram.common.resourceupdate,
41
 org.eclipse.papyrus.diagram.common.service,
42
 org.eclipse.papyrus.diagram.common.service.palette,
43
 org.eclipse.papyrus.diagram.common.sheet,
44
 org.eclipse.papyrus.diagram.common.ui.dialogs,
45
 org.eclipse.papyrus.diagram.common.ui.helper,
46
 org.eclipse.papyrus.diagram.common.ui.hyperlinkshell,
47
 org.eclipse.papyrus.diagram.common.util
48
Require-Bundle: org.eclipse.uml2.uml.edit;visibility:=reexport,
49
 org.eclipse.papyrus.core;bundle-version="0.8.0";visibility:=reexport,
50
 org.eclipse.gmf.runtime.diagram.ui.resources.editor,
51
 org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.1.0",
52
 org.eclipse.papyrus.extensionpoints.editors;bundle-version="0.8.0",
53
 org.eclipse.papyrus.umlutils;bundle-version="0.8.0";visibility:=reexport,
54
 org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="1.2.0",
55
 org.eclipse.papyrus.wizards;bundle-version="0.8.0",
56
 org.eclipse.papyrus.log;bundle-version="0.8.0";visibility:=reexport,
57
 org.eclipse.papyrus.ui.toolbox;bundle-version="0.8.0",
58
 org.eclipse.core.databinding;bundle-version="1.2.0",
59
 org.eclipse.papyrus.editor;bundle-version="0.8.0",
60
 org.eclipse.gmf.runtime.diagram.ui.render;bundle-version="1.3.0",
61
 org.eclipse.papyrus.pastemanager;bundle-version="0.8.0",
62
 org.eclipse.ui,
63
 org.eclipse.papyrus.core.adaptor.gmf;bundle-version="0.8.0",
64
 org.eclipse.papyrus.preferences;bundle-version="0.8.0",
65
 org.eclipse.gmf.runtime.diagram.ui.actions,
66
 org.eclipse.gmf.runtime.draw2d.ui.render;bundle-version="1.4.0",
67
 org.eclipse.core.expressions,
68
 org.eclipse.papyrus.validation;bundle-version="0.8.0",
69
 org.eclipse.papyrus.extendedtypes;bundle-version="0.8.0";visibility:=reexport,
70
 org.eclipse.papyrus.service.edit;bundle-version="0.8.0";visibility:=reexport,
71
 org.eclipse.papyrus.navigation;bundle-version="0.8.0";visibility:=reexport,
72
 org.eclipse.papyrus.navigation.uml;bundle-version="0.8.0"
73
Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.)
74
Ant-Version: Apache Ant 1.7.0
75
Bundle-ActivationPolicy: lazy
76
Bundle-RequiredExecutionEnvironment: J2SE-1.5
77
Bundle-Activator: org.eclipse.papyrus.diagram.common.Activator
(-)src/org/eclipse/papyrus/diagram/common/editparts/CompositeEditPart.java (+92 lines)
Line 0 Link Here
1
package org.eclipse.papyrus.diagram.common.editparts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart;
5
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
6
import org.eclipse.gmf.runtime.notation.FillStyle;
7
import org.eclipse.gmf.runtime.notation.NotationPackage;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.gmf.runtime.notation.datatype.GradientData;
10
import org.eclipse.papyrus.diagram.common.figure.node.IPapyrusNodeFigure;
11
import org.eclipse.papyrus.umlutils.ui.helper.ShadowFigureHelper;
12
import org.eclipse.swt.graphics.Color;
13
14
/**
15
 * this uml edit part can refresh shadow and gradient.
16
 */
17
public abstract class CompositeEditPart extends AbstractBorderedShapeEditPart {
18
19
20
	public CompositeEditPart(View view) {
21
		super(view);
22
	}
23
24
	@Override
25
	protected NodeFigure createMainFigure() {
26
		return createNodeFigure();
27
	}
28
29
	public abstract IPapyrusNodeFigure getPrimaryShape();
30
31
	@Override
32
	public boolean supportsGradient() {
33
		return true;
34
	}
35
36
	@Override
37
	protected void handleNotificationEvent(Notification event) {
38
		super.handleNotificationEvent(event);
39
40
		// set the figure active when the feature of the of a class is true
41
		if(resolveSemanticElement() != null) {
42
			refreshShadow();
43
44
		}
45
	}
46
47
	@Override
48
	protected void refreshVisuals() {
49
		super.refreshVisuals();
50
		refreshShadow();
51
	}
52
53
	@Override
54
	protected void setTransparency(int transp) {
55
		getPrimaryShape().setTransparency(transp);
56
	}
57
58
	/**
59
	 * sets the back ground color of this edit part
60
	 */
61
	@Override
62
	protected void setBackgroundColor(Color color) {
63
		getPrimaryShape().setBackgroundColor(color);
64
		getPrimaryShape().setIsUsingGradient(false);
65
		getPrimaryShape().setGradientData(-1, -1, 0);
66
	}
67
68
	/**
69
	 * Override to set the gradient data to the correct figure
70
	 */
71
	@Override
72
	protected void setGradient(GradientData gradient) {
73
		IPapyrusNodeFigure fig = getPrimaryShape();
74
		FillStyle style = (FillStyle)getPrimaryView().getStyle(NotationPackage.Literals.FILL_STYLE);
75
		if(gradient != null) {
76
			fig.setIsUsingGradient(true);;
77
			fig.setGradientData(style.getFillColor(), gradient.getGradientColor1(), gradient.getGradientStyle());
78
		} else {
79
			fig.setIsUsingGradient(false);
80
		}
81
	}
82
83
	@Override
84
	protected void setForegroundColor(Color color) {
85
		getPrimaryShape().setForegroundColor(color);
86
	}
87
88
	protected void refreshShadow() {
89
		getPrimaryShape().setShadow(ShadowFigureHelper.getShadowFigureValue((View)getModel()));
90
	}
91
92
}
(-)src/org/eclipse/papyrus/diagram/common/editparts/DeploymentNodeEditPart.java (+73 lines)
Line 0 Link Here
1
package org.eclipse.papyrus.diagram.common.editparts;
2
3
import org.eclipse.emf.common.notify.Notification;
4
import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart;
5
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
6
import org.eclipse.gmf.runtime.notation.FillStyle;
7
import org.eclipse.gmf.runtime.notation.NotationPackage;
8
import org.eclipse.gmf.runtime.notation.View;
9
import org.eclipse.gmf.runtime.notation.datatype.GradientData;
10
import org.eclipse.papyrus.diagram.common.figure.node.IPapyrusNodeFigure;
11
import org.eclipse.swt.graphics.Color;
12
13
14
public abstract class DeploymentNodeEditPart extends AbstractBorderedShapeEditPart implements IPapyrusEditPart {
15
16
17
	public DeploymentNodeEditPart(View view) {
18
		super(view);
19
	}
20
21
	@Override
22
	protected NodeFigure createMainFigure() {
23
		return createNodeFigure();
24
	}
25
26
	public abstract IPapyrusNodeFigure getPrimaryShape();
27
28
	@Override
29
	public boolean supportsGradient() {
30
		return true;
31
	}
32
33
	@Override
34
	protected void handleNotificationEvent(Notification event) {
35
		super.handleNotificationEvent(event);
36
	}
37
38
	@Override
39
	protected void setTransparency(int transp) {
40
		getPrimaryShape().setTransparency(transp);
41
	}
42
43
	/**
44
	 * sets the back ground color of this edit part
45
	 */
46
	@Override
47
	protected void setBackgroundColor(Color color) {
48
		getPrimaryShape().setBackgroundColor(color);
49
		getPrimaryShape().setIsUsingGradient(false);
50
		getPrimaryShape().setGradientData(-1, -1, 0);
51
	}
52
53
	/**
54
	 * Override to set the gradient data to the correct figure
55
	 */
56
	@Override
57
	protected void setGradient(GradientData gradient) {
58
		IPapyrusNodeFigure fig = getPrimaryShape();
59
		FillStyle style = (FillStyle)getPrimaryView().getStyle(NotationPackage.Literals.FILL_STYLE);
60
		if(gradient != null) {
61
			fig.setIsUsingGradient(true);;
62
			fig.setGradientData(style.getFillColor(), gradient.getGradientColor1(), gradient.getGradientStyle());
63
		} else {
64
			fig.setIsUsingGradient(false);
65
		}
66
	}
67
68
	@Override
69
	protected void setForegroundColor(Color color) {
70
		getPrimaryShape().setForegroundColor(color);
71
	}
72
73
}
(-)src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java (-181 / +63 lines)
Lines 9-240 Link Here
9
 *
9
 *
10
 * Contributors:
10
 * Contributors:
11
 *  Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
11
 *  Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
12
 *  Patrick Tessier (CEA LIST)-modification
13
 *
12
 *
14
 *****************************************************************************/
13
 *****************************************************************************/
15
package org.eclipse.papyrus.diagram.common.editpolicies;
14
package org.eclipse.papyrus.diagram.common.editpolicies;
16
15
17
import java.util.ArrayList;
18
import java.util.HashMap;
16
import java.util.HashMap;
19
import java.util.Iterator;
20
import java.util.List;
17
import java.util.List;
21
18
22
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.gef.Request;
20
import org.eclipse.gef.Request;
24
import org.eclipse.gef.commands.Command;
21
import org.eclipse.gef.commands.Command;
25
import org.eclipse.gef.commands.UnexecutableCommand;
22
import org.eclipse.gef.commands.UnexecutableCommand;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPolicy;
30
import org.eclipse.gmf.runtime.notation.Diagram;
24
import org.eclipse.gmf.runtime.notation.Diagram;
31
import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil;
25
import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil;
32
import org.eclipse.papyrus.core.editorsfactory.IPageIconsRegistry;
33
import org.eclipse.papyrus.core.editorsfactory.PageIconsRegistry;
34
import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
26
import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
35
import org.eclipse.papyrus.core.services.ServiceException;
36
import org.eclipse.papyrus.core.utils.EditorUtils;
37
import org.eclipse.papyrus.diagram.common.dialogs.DiagramNavigationDialog;
38
import org.eclipse.papyrus.diagram.common.helper.AbstractHyperLinkHelper;
39
import org.eclipse.papyrus.diagram.common.helper.DiagramHyperLinkHelper;
40
import org.eclipse.papyrus.diagram.common.helper.DocumentHyperLinkHelper;
41
import org.eclipse.papyrus.diagram.common.helper.HyperlinkHelperFactory;
42
import org.eclipse.papyrus.diagram.common.helper.WebHyperLinkHelper;
43
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.AdvancedHLManager;
44
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkDiagram;
45
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkManagerShell;
46
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperlinkObject;
47
import org.eclipse.papyrus.navigation.ExistingNavigableElement;
27
import org.eclipse.papyrus.navigation.ExistingNavigableElement;
48
import org.eclipse.papyrus.navigation.NavigableElement;
28
import org.eclipse.papyrus.navigation.NavigableElement;
49
import org.eclipse.papyrus.navigation.NavigationHelper;
29
import org.eclipse.papyrus.navigation.NavigationHelper;
50
import org.eclipse.papyrus.navigation.preference.INavigationPreferenceConstant;
51
import org.eclipse.papyrus.preferences.Activator;
52
import org.eclipse.swt.widgets.Shell;
53
import org.eclipse.uml2.uml.Element;
54
import org.eclipse.uml2.uml.Package;
55
30
56
/**
31
/**
57
 * This class is used to open a new diagram when the double click is detected. It is dependent of
32
 * This class is used to open a new diagram when the double click is detected. It is dependent of
58
 * papyrus environment
33
 * papyrus environment
59
 */
34
 */
60
public class NavigationEditPolicy extends OpenEditPolicy {
35
public class NavigationEditPolicy extends DecorationEditPolicy {
61
36
	
62
	public static final String NAVIGATION_POLICY = "NavigationEditPolicy";
37
	public static final String NAVIGATION_POLICY = "navigationEditPolicy";
63
38
	
64
	public NavigationEditPolicy() {
39
	public NavigationEditPolicy() {
40
		setDecorators(Collections.singletonMap(NAVIGATION_POLICY, new NavigationDecorator(new DecoratorTarget())));
65
	}
41
	}
66
42
67
	/** 
68
	 * 
69
	 * @param element a UML element
70
	 * @return the top package of the given element
71
	 */
72
	public static Package topPackage(Element element) {
73
		if(element.getOwner() == null) {
74
			return (Package)element;
75
		} else {
76
			return topPackage(element.getOwner());
77
		}
78
	}
79
	/**
80
	 * 
81
	 * @param request
82
	 * @return get the command to open a new diagram
83
	 */
84
	protected Command getOpenCommand(Request request) {
43
	protected Command getOpenCommand(Request request) {
85
		final IGraphicalEditPart gep;
44
		IGraphicalEditPart gep = (IGraphicalEditPart)getHost();
86
		
87
		//in order to obtain the list of default diagram we need to fin the edit part that refers to default diagram
88
	
89
		//if this a label of a compartment, the good editpart is the parent 
90
		if((IGraphicalEditPart)getHost() instanceof CompartmentEditPart ){
91
			gep=(IGraphicalEditPart)getHost().getParent();
92
		}
93
		else{
94
			
95
			gep=(IGraphicalEditPart)getHost();
96
		}
97
		final EObject semanticElement=gep.resolveSemanticElement();
98
45
99
		//navigable element by using heuristic
46
		List<NavigableElement> navElements = NavigationHelper.getInstance().getAllNavigableElements(gep.resolveSemanticElement());
100
		List<NavigableElement> navElements=null;
101
47
102
		//defaultHyperlinks
103
		final ArrayList<HyperlinkObject> defaultHyperLinkObject=new ArrayList<HyperlinkObject>();
104
		final ArrayList<HyperlinkObject> hyperLinkObjectList;
105
		//Diagrams that will be found by using heuristic
106
		HashMap<NavigableElement, List<Diagram>> existingDiagrams = new HashMap<NavigableElement, List<Diagram>>();
48
		HashMap<NavigableElement, List<Diagram>> existingDiagrams = new HashMap<NavigableElement, List<Diagram>>();
49
		HashMap<NavigableElement, List<CreationCommandDescriptor>> possibleCreations = new HashMap<NavigableElement, List<CreationCommandDescriptor>>();
107
50
108
		
51
		for(NavigableElement navElement : navElements) {
109
		if(semanticElement==null){
52
			final EObject element = navElement.getElement();
110
			return UnexecutableCommand.INSTANCE;
53
			if(navElement instanceof ExistingNavigableElement) {
111
		}
54
				List<Diagram> associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null);
112
		//initialition of code to extract hyperlinks, in the future to do with extension points
113
		ArrayList<AbstractHyperLinkHelper>  hyperLinkHelpers= new ArrayList<AbstractHyperLinkHelper>();
114
		hyperLinkHelpers.add(new DiagramHyperLinkHelper());
115
		hyperLinkHelpers.add(new DocumentHyperLinkHelper());
116
		hyperLinkHelpers.add(new WebHyperLinkHelper());
117
		
118
		final HyperlinkHelperFactory hyperlinkHelperFactory= new HyperlinkHelperFactory(hyperLinkHelpers);
119
55
120
		try{
56
				// ignore the current diagram
121
			//fill the list of default hyperlinks
57
				associatedDiagrams.remove(gep.getNotationView().getDiagram());
122
			hyperLinkObjectList = (ArrayList<HyperlinkObject>)hyperlinkHelperFactory.getAllreferenced(gep.getNotationView());
58
				if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) {
123
59
					existingDiagrams.put(navElement, associatedDiagrams);
124
			Iterator<HyperlinkObject> iterator= hyperLinkObjectList.iterator();
125
			while(iterator.hasNext()) {
126
				HyperlinkObject hyperlinkObject = (HyperlinkObject)iterator.next();
127
				if( hyperlinkObject.getIsDefault()){
128
129
					defaultHyperLinkObject.add(hyperlinkObject);
130
				}
60
				}
131
132
			}
61
			}
133
62
134
			//fill navigation by using heuristics
63
			List<CreationCommandDescriptor> possibleCommandDescs = new LinkedList<CreationCommandDescriptor>();
135
			navElements = NavigationHelper.getInstance().getAllNavigableElements(semanticElement);
64
			for(final CreationCommandDescriptor desc : getCreationCommandRegistry().getCommandDescriptors()) {
136
			HashMap<NavigableElement, List<CreationCommandDescriptor>> possibleCreations = new HashMap<NavigableElement, List<CreationCommandDescriptor>>();
65
				if(desc.getCondition() == null || desc.getCondition().create(element)) {
137
66
					possibleCommandDescs.add(desc);
138
			//test which kind of navigation by consulting preference
139
			String navigationKind=Activator.getDefault().getPreferenceStore().getString(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DOUBLECLICK_KIND);
140
141
			//no naviagation
142
			if(navigationKind.equals(INavigationPreferenceConstant.NO_NAVIGATION)){
143
				//do nothing
144
				return UnexecutableCommand.INSTANCE;
145
			}
146
147
			//navigation by using heuristic
148
			//add list of diagram navigables by using heuristic
149
			if(navigationKind.equals(INavigationPreferenceConstant.EXPLICIT_IMPLICIT_NAVIGATION)){
150
				for(NavigableElement navElement : navElements) {
151
					final EObject element = navElement.getElement();
152
					if(navElement instanceof ExistingNavigableElement) {
153
						List<Diagram> associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null);
154
155
						// ignore the current diagram
156
						associatedDiagrams.remove(gep.getNotationView().getDiagram());
157
						if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) {
158
							existingDiagrams.put(navElement, associatedDiagrams);
159
						}
160
					}
161
				}
67
				}
162
163
				Iterator<List<Diagram>> iter=existingDiagrams.values().iterator();
164
				while(iter.hasNext()) {
165
					List<Diagram> list = (List<Diagram>)iter.next();
166
					Iterator<Diagram> iterDiagram=list.iterator();
167
					while(iterDiagram.hasNext()) {
168
						Diagram diagram = (Diagram)iterDiagram.next();
169
						HyperLinkDiagram hyperLinkDiagram= new HyperLinkDiagram(); 
170
						hyperLinkDiagram.setDiagram(diagram);
171
						hyperLinkDiagram.setTooltipText(diagram.getName()+" (found by heuristic)");
172
						//look for if a hyperlink already exists
173
						HyperlinkObject foundHyperlink=null;
174
						for(int i=0; i<defaultHyperLinkObject.size()&&foundHyperlink==null;i++){
175
							if (defaultHyperLinkObject.get(i).getObject().equals(diagram)){
176
								foundHyperlink=defaultHyperLinkObject.get(i);
177
							}
178
						}
179
						//the diagram was not into the list of existing default hyperlink
180
						if( foundHyperlink==null){
181
							defaultHyperLinkObject.add(hyperLinkDiagram);
182
						}
183
					}
184
				}
185
			}	
186
			if(defaultHyperLinkObject.size()==0){
187
				Command command= new Command() {
188
					@Override
189
					public void execute() {
190
						HyperLinkManagerShell	hyperLinkManagerShell = new AdvancedHLManager(createEditorRegistry(),((GraphicalEditPart)getHost()).getEditingDomain(),	(Element)gep.getNotationView().getElement(),gep.getNotationView(),topPackage((Element)semanticElement),hyperlinkHelperFactory);
191
						hyperLinkManagerShell.setInput(hyperLinkObjectList);
192
						hyperLinkManagerShell.open();
193
					}
194
				};
195
				return command;
196
			}
68
			}
197
			if(defaultHyperLinkObject.size()==1){
69
			if(!possibleCommandDescs.isEmpty()) {
198
				// open the diagram
70
				possibleCreations.put(navElement, possibleCommandDescs);
199
				Command command= new Command() {
200
					@Override
201
					public void execute() {
202
						super.execute();
203
						defaultHyperLinkObject.get(0).executeSelectPressed();
204
					}
205
				};
206
				return command;
207
208
			}
71
			}
209
			if(defaultHyperLinkObject.size()>1){
72
		}
210
				//open a dialog to choose a diagram
211
				DiagramNavigationDialog diagramNavigationDialog= new DiagramNavigationDialog(new Shell(),defaultHyperLinkObject);
212
				diagramNavigationDialog.open();
213
				final ArrayList<HyperlinkObject> hList=diagramNavigationDialog.getSelectedHyperlinks();
214
				Command command= new Command() {
215
					@Override
216
					public void execute() {
217
						super.execute();
218
73
219
						Iterator<HyperlinkObject> iter= hList.iterator();
74
		if(!existingDiagrams.isEmpty()) {
220
						while(iter.hasNext()) {
75
			NavigationOpenDiagramDialog dialog = new NavigationOpenDiagramDialog(Display.getCurrent().getActiveShell(), existingDiagrams);
221
							HyperlinkObject hyperlinkObject = (HyperlinkObject)iter.next();
76
			int result = dialog.open();
222
							hyperlinkObject.executeSelectPressed();
77
			if(result == Window.OK) {
223
						}
78
				return new ICommandProxy(dialog.getCommand());
224
					}
225
				};
226
				return command;
227
228
			}
79
			}
229
80
		} else {
81
			NavigationCreateDiagramDialog dialog = new NavigationCreateDiagramDialog(Display.getCurrent().getActiveShell(), possibleCreations);
82
			int result = dialog.open();
83
			if(result == Window.OK) {
84
				return new ICommandProxy(dialog.getCommand());
85
			}
230
		}
86
		}
231
		catch (Exception e) {
87
232
			org.eclipse.papyrus.diagram.common.Activator.log.error("Impossible to load hyperlinks", e);
233
		}
234
		return UnexecutableCommand.INSTANCE;
88
		return UnexecutableCommand.INSTANCE;
235
	}
89
	}
236
90
91
    public Command getCommand(Request request) {
92
        if (RequestConstants.REQ_OPEN.equals(request.getType()))
93
            return getOpenCommand(request);
94
        return super.getCommand(request);
95
    }
237
96
97
<<<<<<< .mine
98
    public boolean understandsRequest(Request request) {
99
        if (RequestConstants.REQ_OPEN.equals(request.getType()))
100
            return true;
101
        return super.understandsRequest(request);
102
    }
103
=======
238
	/**
104
	/**
239
	 * Return the EditorRegistry for nested editor descriptors. Subclass should implements this
105
	 * Return the EditorRegistry for nested editor descriptors. Subclass should implements this
240
	 * method in order to return the registry associated to the extension point namespace.
106
	 * method in order to return the registry associated to the extension point namespace.
Lines 251-255 Link Here
251
			return new PageIconsRegistry();
117
			return new PageIconsRegistry();
252
		}
118
		}
253
	}
119
	}
120
>>>>>>> .r4757
254
121
122
<<<<<<< .mine
123
    public EditPart getTargetEditPart(Request request) {
124
125
        if (understandsRequest(request))
126
            return getHost();
127
128
        return null;
129
    }
130
131
	private static ICreationCommandRegistry getCreationCommandRegistry() {
132
		return CreationCommandRegistry.getInstance(org.eclipse.papyrus.core.Activator.PLUGIN_ID);
133
	}
134
135
=======
136
>>>>>>> .r4757
255
}
137
}
(-)src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.mine (+128 lines)
Line 0 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2010 Atos Origin.
3
 *
4
 *    
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *  Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.diagram.common.editpolicies;
15
16
import java.util.Collections;
17
import java.util.HashMap;
18
import java.util.LinkedList;
19
import java.util.List;
20
21
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.gef.EditPart;
23
import org.eclipse.gef.Request;
24
import org.eclipse.gef.commands.Command;
25
import org.eclipse.gef.commands.UnexecutableCommand;
26
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DecorationEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
30
import org.eclipse.gmf.runtime.notation.Diagram;
31
import org.eclipse.jface.window.Window;
32
import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil;
33
import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
34
import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry;
35
import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry;
36
import org.eclipse.papyrus.diagram.common.dialogs.NavigationCreateDiagramDialog;
37
import org.eclipse.papyrus.diagram.common.dialogs.NavigationOpenDiagramDialog;
38
import org.eclipse.papyrus.diagram.common.providers.NavigationDecorator;
39
import org.eclipse.papyrus.navigation.ExistingNavigableElement;
40
import org.eclipse.papyrus.navigation.NavigableElement;
41
import org.eclipse.papyrus.navigation.NavigationHelper;
42
import org.eclipse.swt.widgets.Display;
43
44
/**
45
 * This class is used to open a new diagram when the double click is detected. It is dependent of
46
 * papyrus environment
47
 */
48
public class NavigationEditPolicy extends DecorationEditPolicy {
49
	
50
	public static final String NAVIGATION_POLICY = "navigationEditPolicy";
51
	
52
	public NavigationEditPolicy() {
53
		setDecorators(Collections.singletonMap(NAVIGATION_POLICY, new NavigationDecorator(new DecoratorTarget())));
54
	}
55
56
	protected Command getOpenCommand(Request request) {
57
		IGraphicalEditPart gep = (IGraphicalEditPart)getHost();
58
59
		List<NavigableElement> navElements = NavigationHelper.getInstance().getAllNavigableElements(gep.resolveSemanticElement());
60
61
		HashMap<NavigableElement, List<Diagram>> existingDiagrams = new HashMap<NavigableElement, List<Diagram>>();
62
		HashMap<NavigableElement, List<CreationCommandDescriptor>> possibleCreations = new HashMap<NavigableElement, List<CreationCommandDescriptor>>();
63
64
		for(NavigableElement navElement : navElements) {
65
			final EObject element = navElement.getElement();
66
			if(navElement instanceof ExistingNavigableElement) {
67
				List<Diagram> associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null);
68
69
				// ignore the current diagram
70
				associatedDiagrams.remove(gep.getNotationView().getDiagram());
71
				if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) {
72
					existingDiagrams.put(navElement, associatedDiagrams);
73
				}
74
			}
75
76
			List<CreationCommandDescriptor> possibleCommandDescs = new LinkedList<CreationCommandDescriptor>();
77
			for(final CreationCommandDescriptor desc : getCreationCommandRegistry().getCommandDescriptors()) {
78
				if(desc.getCondition() == null || desc.getCondition().create(element)) {
79
					possibleCommandDescs.add(desc);
80
				}
81
			}
82
			if(!possibleCommandDescs.isEmpty()) {
83
				possibleCreations.put(navElement, possibleCommandDescs);
84
			}
85
		}
86
87
		if(!existingDiagrams.isEmpty()) {
88
			NavigationOpenDiagramDialog dialog = new NavigationOpenDiagramDialog(Display.getCurrent().getActiveShell(), existingDiagrams);
89
			int result = dialog.open();
90
			if(result == Window.OK) {
91
				return new ICommandProxy(dialog.getCommand());
92
			}
93
		} else {
94
			NavigationCreateDiagramDialog dialog = new NavigationCreateDiagramDialog(Display.getCurrent().getActiveShell(), possibleCreations);
95
			int result = dialog.open();
96
			if(result == Window.OK) {
97
				return new ICommandProxy(dialog.getCommand());
98
			}
99
		}
100
101
		return UnexecutableCommand.INSTANCE;
102
	}
103
104
    public Command getCommand(Request request) {
105
        if (RequestConstants.REQ_OPEN.equals(request.getType()))
106
            return getOpenCommand(request);
107
        return super.getCommand(request);
108
    }
109
110
    public boolean understandsRequest(Request request) {
111
        if (RequestConstants.REQ_OPEN.equals(request.getType()))
112
            return true;
113
        return super.understandsRequest(request);
114
    }
115
116
    public EditPart getTargetEditPart(Request request) {
117
118
        if (understandsRequest(request))
119
            return getHost();
120
121
        return null;
122
    }
123
124
	private static ICreationCommandRegistry getCreationCommandRegistry() {
125
		return CreationCommandRegistry.getInstance(org.eclipse.papyrus.core.Activator.PLUGIN_ID);
126
	}
127
128
}
(-)src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.r4630 (+277 lines)
Line 0 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2010 Atos Origin.
3
 *
4
 *    
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *  Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
12
 *  Patrick Tessier (CEA LIST)-modification
13
 *
14
 *****************************************************************************/
15
package org.eclipse.papyrus.diagram.common.editpolicies;
16
17
import java.util.ArrayList;
18
import java.util.Collections;
19
import java.util.HashMap;
20
import java.util.Iterator;
21
import java.util.LinkedList;
22
import java.util.List;
23
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.gef.EditPart;
26
import org.eclipse.gef.Request;
27
import org.eclipse.gef.commands.Command;
28
import org.eclipse.gef.commands.UnexecutableCommand;
29
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
30
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
31
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
32
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
33
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DecorationEditPolicy;
34
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPolicy;
35
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
36
import org.eclipse.gmf.runtime.notation.Diagram;
37
import org.eclipse.jface.window.Window;
38
import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil;
39
import org.eclipse.papyrus.core.editorsfactory.IPageIconsRegistry;
40
import org.eclipse.papyrus.core.editorsfactory.PageIconsRegistry;
41
import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
42
import org.eclipse.papyrus.core.extension.commands.CreationCommandRegistry;
43
import org.eclipse.papyrus.core.extension.commands.ICreationCommandRegistry;
44
import org.eclipse.papyrus.core.services.ServiceException;
45
import org.eclipse.papyrus.core.utils.EditorUtils;
46
import org.eclipse.papyrus.diagram.common.dialogs.DiagramNavigationDialog;
47
import org.eclipse.papyrus.diagram.common.dialogs.NavigationCreateDiagramDialog;
48
import org.eclipse.papyrus.diagram.common.dialogs.NavigationOpenDiagramDialog;
49
import org.eclipse.papyrus.diagram.common.helper.AbstractHyperLinkHelper;
50
import org.eclipse.papyrus.diagram.common.helper.DiagramHyperLinkHelper;
51
import org.eclipse.papyrus.diagram.common.helper.DocumentHyperLinkHelper;
52
import org.eclipse.papyrus.diagram.common.helper.HyperlinkHelperFactory;
53
import org.eclipse.papyrus.diagram.common.helper.WebHyperLinkHelper;
54
import org.eclipse.papyrus.diagram.common.providers.NavigationDecorator;
55
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.AdvancedHLManager;
56
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkDiagram;
57
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkManagerShell;
58
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperlinkObject;
59
import org.eclipse.papyrus.navigation.ExistingNavigableElement;
60
import org.eclipse.papyrus.navigation.NavigableElement;
61
import org.eclipse.papyrus.navigation.NavigationHelper;
62
import org.eclipse.papyrus.navigation.preference.INavigationPreferenceConstant;
63
import org.eclipse.papyrus.preferences.Activator;
64
import org.eclipse.swt.widgets.Display;
65
import org.eclipse.swt.widgets.Shell;
66
import org.eclipse.uml2.uml.Element;
67
import org.eclipse.uml2.uml.Package;
68
69
/**
70
 * This class is used to open a new diagram when the double click is detected. It is dependent of
71
 * papyrus environment
72
 */
73
public class NavigationEditPolicy extends OpenEditPolicy {
74
75
	public static final String NAVIGATION_POLICY = "NavigationEditPolicy";
76
77
	public NavigationEditPolicy() {
78
	}
79
80
	/** 
81
	 * 
82
	 * @param element a UML element
83
	 * @return the top package of the given element
84
	 */
85
	public static Package topPackage(Element element) {
86
		if(element.getOwner() == null) {
87
			return (Package)element;
88
		} else {
89
			return topPackage(element.getOwner());
90
		}
91
	}
92
	/**
93
	 * 
94
	 * @param request
95
	 * @return get the command to open a new diagram
96
	 */
97
	protected Command getOpenCommand(Request request) {
98
		final IGraphicalEditPart gep;
99
		
100
		//in order to obtain the list of default diagram we need to fin the edit part that refers to default diagram
101
	
102
		//if this a label of a compartment, the good editpart is the parent 
103
		if((IGraphicalEditPart)getHost() instanceof CompartmentEditPart ){
104
			gep=(IGraphicalEditPart)getHost().getParent();
105
		}
106
		else{
107
			
108
			gep=(IGraphicalEditPart)getHost();
109
		}
110
		final EObject semanticElement=gep.resolveSemanticElement();
111
112
		//navigable element by using heuristic
113
		List<NavigableElement> navElements=null;
114
115
		//defaultHyperlinks
116
		final ArrayList<HyperlinkObject> defaultHyperLinkObject=new ArrayList<HyperlinkObject>();
117
		final ArrayList<HyperlinkObject> hyperLinkObjectList;
118
		//Diagrams that will be found by using heuristic
119
		HashMap<NavigableElement, List<Diagram>> existingDiagrams = new HashMap<NavigableElement, List<Diagram>>();
120
121
		
122
		if(semanticElement==null){
123
			return UnexecutableCommand.INSTANCE;
124
		}
125
		//initialition of code to extract hyperlinks, in the future to do with extension points
126
		ArrayList<AbstractHyperLinkHelper>  hyperLinkHelpers= new ArrayList<AbstractHyperLinkHelper>();
127
		hyperLinkHelpers.add(new DiagramHyperLinkHelper());
128
		hyperLinkHelpers.add(new DocumentHyperLinkHelper());
129
		hyperLinkHelpers.add(new WebHyperLinkHelper());
130
		
131
		final HyperlinkHelperFactory hyperlinkHelperFactory= new HyperlinkHelperFactory(hyperLinkHelpers);
132
133
		try{
134
			//fill the list of default hyperlinks
135
			hyperLinkObjectList = (ArrayList<HyperlinkObject>)hyperlinkHelperFactory.getAllreferenced(gep.getNotationView());
136
137
			Iterator<HyperlinkObject> iterator= hyperLinkObjectList.iterator();
138
			while(iterator.hasNext()) {
139
				HyperlinkObject hyperlinkObject = (HyperlinkObject)iterator.next();
140
				if( hyperlinkObject.getIsDefault()){
141
142
					defaultHyperLinkObject.add(hyperlinkObject);
143
				}
144
145
			}
146
147
			//fill navigation by using heuristics
148
			navElements = NavigationHelper.getInstance().getAllNavigableElements(semanticElement);
149
			HashMap<NavigableElement, List<CreationCommandDescriptor>> possibleCreations = new HashMap<NavigableElement, List<CreationCommandDescriptor>>();
150
151
			//test which kind of navigation by consulting preference
152
			String navigationKind=Activator.getDefault().getPreferenceStore().getString(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DOUBLECLICK_KIND);
153
154
			//no naviagation
155
			if(navigationKind.equals(INavigationPreferenceConstant.NO_NAVIGATION)){
156
				//do nothing
157
				return UnexecutableCommand.INSTANCE;
158
			}
159
160
			//navigation by using heuristic
161
			//add list of diagram navigables by using heuristic
162
			if(navigationKind.equals(INavigationPreferenceConstant.EXPLICIT_IMPLICIT_NAVIGATION)){
163
				for(NavigableElement navElement : navElements) {
164
					final EObject element = navElement.getElement();
165
					if(navElement instanceof ExistingNavigableElement) {
166
						List<Diagram> associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null);
167
168
						// ignore the current diagram
169
						associatedDiagrams.remove(gep.getNotationView().getDiagram());
170
						if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) {
171
							existingDiagrams.put(navElement, associatedDiagrams);
172
						}
173
					}
174
				}
175
176
				Iterator<List<Diagram>> iter=existingDiagrams.values().iterator();
177
				while(iter.hasNext()) {
178
					List<Diagram> list = (List<Diagram>)iter.next();
179
					Iterator<Diagram> iterDiagram=list.iterator();
180
					while(iterDiagram.hasNext()) {
181
						Diagram diagram = (Diagram)iterDiagram.next();
182
						HyperLinkDiagram hyperLinkDiagram= new HyperLinkDiagram(); 
183
						hyperLinkDiagram.setDiagram(diagram);
184
						hyperLinkDiagram.setTooltipText(diagram.getName()+" (found by heuristic)");
185
						//look for if a hyperlink already exists
186
						HyperlinkObject foundHyperlink=null;
187
						for(int i=0; i<defaultHyperLinkObject.size()&&foundHyperlink==null;i++){
188
							if (defaultHyperLinkObject.get(i).getObject().equals(diagram)){
189
								foundHyperlink=defaultHyperLinkObject.get(i);
190
							}
191
						}
192
						//the diagram was not into the list of existing default hyperlink
193
						if( foundHyperlink==null){
194
							defaultHyperLinkObject.add(hyperLinkDiagram);
195
						}
196
					}
197
				}
198
			}	
199
			if(defaultHyperLinkObject.size()==0){
200
				Command command= new Command() {
201
					@Override
202
					public void execute() {
203
						HyperLinkManagerShell	hyperLinkManagerShell = new AdvancedHLManager(createEditorRegistry(),((GraphicalEditPart)getHost()).getEditingDomain(),	(Element)gep.getNotationView().getElement(),gep.getNotationView(),topPackage((Element)semanticElement),hyperlinkHelperFactory);
204
						hyperLinkManagerShell.setInput(hyperLinkObjectList);
205
						hyperLinkManagerShell.open();
206
					}
207
				};
208
				return command;
209
			}
210
			if(defaultHyperLinkObject.size()==1){
211
				// open the diagram
212
				Command command= new Command() {
213
					@Override
214
					public void execute() {
215
						super.execute();
216
						defaultHyperLinkObject.get(0).executeSelectPressed();
217
					}
218
				};
219
				return command;
220
221
			}
222
			if(defaultHyperLinkObject.size()>1){
223
				//open a dialog to choose a diagram
224
				DiagramNavigationDialog diagramNavigationDialog= new DiagramNavigationDialog(new Shell(),defaultHyperLinkObject);
225
				diagramNavigationDialog.open();
226
				final ArrayList<HyperlinkObject> hList=diagramNavigationDialog.getSelectedHyperlinks();
227
				Command command= new Command() {
228
					@Override
229
					public void execute() {
230
						super.execute();
231
232
						Iterator<HyperlinkObject> iter= hList.iterator();
233
						while(iter.hasNext()) {
234
							HyperlinkObject hyperlinkObject = (HyperlinkObject)iter.next();
235
							hyperlinkObject.executeSelectPressed();
236
						}
237
					}
238
				};
239
				return command;
240
241
			}
242
243
		}
244
		catch (Exception e) {
245
			org.eclipse.papyrus.diagram.common.Activator.log.error("Impossible to load hyperlinks", e);
246
		}
247
		return UnexecutableCommand.INSTANCE;
248
	}
249
250
251
	/**
252
	 * Return the EditorRegistry for nested editor descriptors. Subclass should implements this
253
	 * method in order to return the registry associated to the extension point namespace.
254
	 * 
255
	 * @return the EditorRegistry for nested editor descriptors
256
	 * 
257
	 * @generated NOT
258
	 */
259
	protected IPageIconsRegistry createEditorRegistry() {
260
		try {
261
			return EditorUtils.getServiceRegistry().getService(IPageIconsRegistry.class);
262
		} catch (ServiceException e) {
263
			// Return an empty registry always providing null;
264
			return new PageIconsRegistry();
265
		}
266
	}
267
	
268
269
	
270
271
	private static ICreationCommandRegistry getCreationCommandRegistry() {
272
		return CreationCommandRegistry.getInstance(org.eclipse.papyrus.core.Activator.PLUGIN_ID);
273
	}
274
275
276
277
}
(-)src/org/eclipse/papyrus/diagram/common/editpolicies/NavigationEditPolicy.java.r4757 (+255 lines)
Line 0 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2010 Atos Origin.
3
 *
4
 *    
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *  Mathieu Velten (Atos Origin) mathieu.velten@atosorigin.com - Initial API and implementation
12
 *  Patrick Tessier (CEA LIST)-modification
13
 *
14
 *****************************************************************************/
15
package org.eclipse.papyrus.diagram.common.editpolicies;
16
17
import java.util.ArrayList;
18
import java.util.HashMap;
19
import java.util.Iterator;
20
import java.util.List;
21
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.gef.Request;
24
import org.eclipse.gef.commands.Command;
25
import org.eclipse.gef.commands.UnexecutableCommand;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPolicy;
30
import org.eclipse.gmf.runtime.notation.Diagram;
31
import org.eclipse.papyrus.core.adaptor.gmf.DiagramsUtil;
32
import org.eclipse.papyrus.core.editorsfactory.IPageIconsRegistry;
33
import org.eclipse.papyrus.core.editorsfactory.PageIconsRegistry;
34
import org.eclipse.papyrus.core.extension.commands.CreationCommandDescriptor;
35
import org.eclipse.papyrus.core.services.ServiceException;
36
import org.eclipse.papyrus.core.utils.EditorUtils;
37
import org.eclipse.papyrus.diagram.common.dialogs.DiagramNavigationDialog;
38
import org.eclipse.papyrus.diagram.common.helper.AbstractHyperLinkHelper;
39
import org.eclipse.papyrus.diagram.common.helper.DiagramHyperLinkHelper;
40
import org.eclipse.papyrus.diagram.common.helper.DocumentHyperLinkHelper;
41
import org.eclipse.papyrus.diagram.common.helper.HyperlinkHelperFactory;
42
import org.eclipse.papyrus.diagram.common.helper.WebHyperLinkHelper;
43
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.AdvancedHLManager;
44
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkDiagram;
45
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperLinkManagerShell;
46
import org.eclipse.papyrus.diagram.common.ui.hyperlinkshell.HyperlinkObject;
47
import org.eclipse.papyrus.navigation.ExistingNavigableElement;
48
import org.eclipse.papyrus.navigation.NavigableElement;
49
import org.eclipse.papyrus.navigation.NavigationHelper;
50
import org.eclipse.papyrus.navigation.preference.INavigationPreferenceConstant;
51
import org.eclipse.papyrus.preferences.Activator;
52
import org.eclipse.swt.widgets.Shell;
53
import org.eclipse.uml2.uml.Element;
54
import org.eclipse.uml2.uml.Package;
55
56
/**
57
 * This class is used to open a new diagram when the double click is detected. It is dependent of
58
 * papyrus environment
59
 */
60
public class NavigationEditPolicy extends OpenEditPolicy {
61
62
	public static final String NAVIGATION_POLICY = "NavigationEditPolicy";
63
64
	public NavigationEditPolicy() {
65
	}
66
67
	/** 
68
	 * 
69
	 * @param element a UML element
70
	 * @return the top package of the given element
71
	 */
72
	public static Package topPackage(Element element) {
73
		if(element.getOwner() == null) {
74
			return (Package)element;
75
		} else {
76
			return topPackage(element.getOwner());
77
		}
78
	}
79
	/**
80
	 * 
81
	 * @param request
82
	 * @return get the command to open a new diagram
83
	 */
84
	protected Command getOpenCommand(Request request) {
85
		final IGraphicalEditPart gep;
86
		
87
		//in order to obtain the list of default diagram we need to fin the edit part that refers to default diagram
88
	
89
		//if this a label of a compartment, the good editpart is the parent 
90
		if((IGraphicalEditPart)getHost() instanceof CompartmentEditPart ){
91
			gep=(IGraphicalEditPart)getHost().getParent();
92
		}
93
		else{
94
			
95
			gep=(IGraphicalEditPart)getHost();
96
		}
97
		final EObject semanticElement=gep.resolveSemanticElement();
98
99
		//navigable element by using heuristic
100
		List<NavigableElement> navElements=null;
101
102
		//defaultHyperlinks
103
		final ArrayList<HyperlinkObject> defaultHyperLinkObject=new ArrayList<HyperlinkObject>();
104
		final ArrayList<HyperlinkObject> hyperLinkObjectList;
105
		//Diagrams that will be found by using heuristic
106
		HashMap<NavigableElement, List<Diagram>> existingDiagrams = new HashMap<NavigableElement, List<Diagram>>();
107
108
		
109
		if(semanticElement==null){
110
			return UnexecutableCommand.INSTANCE;
111
		}
112
		//initialition of code to extract hyperlinks, in the future to do with extension points
113
		ArrayList<AbstractHyperLinkHelper>  hyperLinkHelpers= new ArrayList<AbstractHyperLinkHelper>();
114
		hyperLinkHelpers.add(new DiagramHyperLinkHelper());
115
		hyperLinkHelpers.add(new DocumentHyperLinkHelper());
116
		hyperLinkHelpers.add(new WebHyperLinkHelper());
117
		
118
		final HyperlinkHelperFactory hyperlinkHelperFactory= new HyperlinkHelperFactory(hyperLinkHelpers);
119
120
		try{
121
			//fill the list of default hyperlinks
122
			hyperLinkObjectList = (ArrayList<HyperlinkObject>)hyperlinkHelperFactory.getAllreferenced(gep.getNotationView());
123
124
			Iterator<HyperlinkObject> iterator= hyperLinkObjectList.iterator();
125
			while(iterator.hasNext()) {
126
				HyperlinkObject hyperlinkObject = (HyperlinkObject)iterator.next();
127
				if( hyperlinkObject.getIsDefault()){
128
129
					defaultHyperLinkObject.add(hyperlinkObject);
130
				}
131
132
			}
133
134
			//fill navigation by using heuristics
135
			navElements = NavigationHelper.getInstance().getAllNavigableElements(semanticElement);
136
			HashMap<NavigableElement, List<CreationCommandDescriptor>> possibleCreations = new HashMap<NavigableElement, List<CreationCommandDescriptor>>();
137
138
			//test which kind of navigation by consulting preference
139
			String navigationKind=Activator.getDefault().getPreferenceStore().getString(INavigationPreferenceConstant.PAPYRUS_NAVIGATION_DOUBLECLICK_KIND);
140
141
			//no naviagation
142
			if(navigationKind.equals(INavigationPreferenceConstant.NO_NAVIGATION)){
143
				//do nothing
144
				return UnexecutableCommand.INSTANCE;
145
			}
146
147
			//navigation by using heuristic
148
			//add list of diagram navigables by using heuristic
149
			if(navigationKind.equals(INavigationPreferenceConstant.EXPLICIT_IMPLICIT_NAVIGATION)){
150
				for(NavigableElement navElement : navElements) {
151
					final EObject element = navElement.getElement();
152
					if(navElement instanceof ExistingNavigableElement) {
153
						List<Diagram> associatedDiagrams = DiagramsUtil.getAssociatedDiagrams(element, null);
154
155
						// ignore the current diagram
156
						associatedDiagrams.remove(gep.getNotationView().getDiagram());
157
						if(associatedDiagrams != null && !associatedDiagrams.isEmpty()) {
158
							existingDiagrams.put(navElement, associatedDiagrams);
159
						}
160
					}
161
				}
162
163
				Iterator<List<Diagram>> iter=existingDiagrams.values().iterator();
164
				while(iter.hasNext()) {
165
					List<Diagram> list = (List<Diagram>)iter.next();
166
					Iterator<Diagram> iterDiagram=list.iterator();
167
					while(iterDiagram.hasNext()) {
168
						Diagram diagram = (Diagram)iterDiagram.next();
169
						HyperLinkDiagram hyperLinkDiagram= new HyperLinkDiagram(); 
170
						hyperLinkDiagram.setDiagram(diagram);
171
						hyperLinkDiagram.setTooltipText(diagram.getName()+" (found by heuristic)");
172
						//look for if a hyperlink already exists
173
						HyperlinkObject foundHyperlink=null;
174
						for(int i=0; i<defaultHyperLinkObject.size()&&foundHyperlink==null;i++){
175
							if (defaultHyperLinkObject.get(i).getObject().equals(diagram)){
176
								foundHyperlink=defaultHyperLinkObject.get(i);
177
							}
178
						}
179
						//the diagram was not into the list of existing default hyperlink
180
						if( foundHyperlink==null){
181
							defaultHyperLinkObject.add(hyperLinkDiagram);
182
						}
183
					}
184
				}
185
			}	
186
			if(defaultHyperLinkObject.size()==0){
187
				Command command= new Command() {
188
					@Override
189
					public void execute() {
190
						HyperLinkManagerShell	hyperLinkManagerShell = new AdvancedHLManager(createEditorRegistry(),((GraphicalEditPart)getHost()).getEditingDomain(),	(Element)gep.getNotationView().getElement(),gep.getNotationView(),topPackage((Element)semanticElement),hyperlinkHelperFactory);
191
						hyperLinkManagerShell.setInput(hyperLinkObjectList);
192
						hyperLinkManagerShell.open();
193
					}
194
				};
195
				return command;
196
			}
197
			if(defaultHyperLinkObject.size()==1){
198
				// open the diagram
199
				Command command= new Command() {
200
					@Override
201
					public void execute() {
202
						super.execute();
203
						defaultHyperLinkObject.get(0).executeSelectPressed();
204
					}
205
				};
206
				return command;
207
208
			}
209
			if(defaultHyperLinkObject.size()>1){
210
				//open a dialog to choose a diagram
211
				DiagramNavigationDialog diagramNavigationDialog= new DiagramNavigationDialog(new Shell(),defaultHyperLinkObject);
212
				diagramNavigationDialog.open();
213
				final ArrayList<HyperlinkObject> hList=diagramNavigationDialog.getSelectedHyperlinks();
214
				Command command= new Command() {
215
					@Override
216
					public void execute() {
217
						super.execute();
218
219
						Iterator<HyperlinkObject> iter= hList.iterator();
220
						while(iter.hasNext()) {
221
							HyperlinkObject hyperlinkObject = (HyperlinkObject)iter.next();
222
							hyperlinkObject.executeSelectPressed();
223
						}
224
					}
225
				};
226
				return command;
227
228
			}
229
230
		}
231
		catch (Exception e) {
232
			org.eclipse.papyrus.diagram.common.Activator.log.error("Impossible to load hyperlinks", e);
233
		}
234
		return UnexecutableCommand.INSTANCE;
235
	}
236
237
238
	/**
239
	 * Return the EditorRegistry for nested editor descriptors. Subclass should implements this
240
	 * method in order to return the registry associated to the extension point namespace.
241
	 * 
242
	 * @return the EditorRegistry for nested editor descriptors
243
	 * 
244
	 * @generated NOT
245
	 */
246
	protected IPageIconsRegistry createEditorRegistry() {
247
		try {
248
			return EditorUtils.getServiceRegistry().getService(IPageIconsRegistry.class);
249
		} catch (ServiceException e) {
250
			// Return an empty registry always providing null;
251
			return new PageIconsRegistry();
252
		}
253
	}
254
255
}
(-)src/org/eclipse/papyrus/diagram/common/providers/DiagramDecorationAdapter.java (+295 lines)
Line 0 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
3
 *
4
 *    
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *	Amine EL KOUHEN (CEA LIST/LIFL) - Amine.Elkouhen@cea.fr 
12
 *****************************************************************************/
13
package org.eclipse.papyrus.diagram.common.providers;
14
15
import org.eclipse.draw2d.IFigure;
16
import org.eclipse.draw2d.Label;
17
import org.eclipse.gef.EditPart;
18
import org.eclipse.gef.GraphicalEditPart;
19
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration;
20
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
21
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget.Direction;
22
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
23
import org.eclipse.gmf.runtime.notation.Edge;
24
import org.eclipse.gmf.runtime.notation.View;
25
import org.eclipse.papyrus.decoration.util.Decoration.PreferedPosition;
26
import org.eclipse.swt.graphics.Image;
27
28
29
// TODO: Auto-generated Javadoc
30
/**
31
 * The Class DiagramDecorationAdapter.
32
 */
33
public class DiagramDecorationAdapter {
34
35
	/** The decorator target. */
36
	protected IDecoratorTarget decoratorTarget;
37
38
39
	/** The decoration. */
40
	protected IDecoration decoration;
41
42
43
	/** The decoration image. */
44
	protected Image decorationImage;
45
46
47
48
	/**
49
	 * Instantiates a new diagram decoration adapter.
50
	 *
51
	 * @param decoratorTarget the decorator target
52
	 */
53
	public DiagramDecorationAdapter(IDecoratorTarget decoratorTarget) {
54
		this.decoratorTarget = decoratorTarget;
55
	}
56
57
	/**
58
	 * Gets the decoration.
59
	 *
60
	 * @return the decoration
61
	 */
62
	public IDecoration getDecoration() {
63
		return this.decoration;
64
	}
65
66
	/**
67
	 * Gets the decorator target.
68
	 *
69
	 * @return the decorator target
70
	 */
71
	public IDecoratorTarget getDecoratorTarget() {
72
		return this.decoratorTarget;
73
	}
74
75
	/**
76
	 * Removes the decoration.
77
	 */
78
	public void removeDecoration() {
79
		if(getDecoration() == null || getDecoratorTarget() == null) {
80
			return;
81
		}
82
		removeDecoration(getDecoratorTarget(), getDecoration());
83
84
	}
85
86
	/**
87
	 * Removes the decoration.
88
	 *
89
	 * @param decoration the decoration
90
	 */
91
	public void removeDecoration(IDecoration decoration) {
92
		if(decoration == null || getDecoratorTarget() == null) {
93
			return;
94
		}
95
		removeDecoration(getDecoratorTarget(), decoration);
96
97
	}
98
99
	/**
100
	 * Sets the decoration.
101
	 *
102
	 * @param image the image
103
	 * @param position the position
104
	 * @param percentageFromSource the percentage from source
105
	 * @param margin the margin
106
	 * @param isVolatile the is volatile
107
	 * @return the i decoration
108
	 */
109
	public IDecoration setDecoration(Image image, PreferedPosition position, int percentageFromSource, int margin, boolean isVolatile) {
110
		this.decoration = getDecoration(getDecoratorTarget(), image, position, percentageFromSource, margin, isVolatile);
111
		this.decorationImage = image;
112
		return getDecoration();
113
	}
114
115
	/**
116
	 * Sets the decoration.
117
	 *
118
	 * @param figure the figure
119
	 * @param position the position
120
	 * @param percentageFromSource the percentage from source
121
	 * @param margin the margin
122
	 * @param isVolatile the is volatile
123
	 * @return the i decoration
124
	 */
125
	public IDecoration setDecoration(IFigure figure, PreferedPosition position, int percentageFromSource, int margin, boolean isVolatile) {
126
		this.decoration = getDecoration(getDecoratorTarget(), figure, position, percentageFromSource, margin, isVolatile);
127
		return getDecoration();
128
	}
129
130
	/**
131
	 * Sets the decorator target.
132
	 *
133
	 * @param decoratorTarget the new decorator target
134
	 */
135
	public void setDecoratorTarget(IDecoratorTarget decoratorTarget) {
136
		this.decoratorTarget = decoratorTarget;
137
	}
138
139
	/**
140
	 * Gets the decoration image.
141
	 *
142
	 * @return the decoration image
143
	 */
144
	public Image getDecorationImage() {
145
		return decorationImage;
146
	}
147
148
	/**
149
	 * Gets the tool tip.
150
	 *
151
	 * @param message the message
152
	 * @return the tool tip
153
	 */
154
	public Label getToolTip(String message) {
155
		return new Label(message, getDecorationImage());
156
	}
157
158
	/**
159
	 * Sets the decoration.
160
	 *
161
	 * @param idecoration the idecoration
162
	 * @param percentageFromSource the percentage from source
163
	 * @param margin the margin
164
	 * @param isVolatile the is volatile
165
	 * @return the i decoration
166
	 */
167
	public IDecoration setDecoration(org.eclipse.papyrus.decoration.util.IDecoration idecoration, int percentageFromSource, int margin, boolean isVolatile) {
168
169
		this.decorationImage = (idecoration.getDecorationImage() != null) ? idecoration.getDecorationImage().createImage() : null;
170
		this.decoration = getDecoration(getDecoratorTarget(), getDecorationImage(), idecoration.getPosition(), percentageFromSource, margin, isVolatile);
171
172
		return getDecoration();
173
	}
174
175
	/**
176
	 * Removes the decoration.
177
	 *
178
	 * @param decoratorTarget the decorator target
179
	 * @param Decoration the decoration
180
	 */
181
	public void removeDecoration(IDecoratorTarget decoratorTarget, org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration Decoration) {
182
		if(Decoration instanceof IFigure) {
183
			((IFigure)Decoration).getParent().remove((IFigure)Decoration);
184
		}
185
		GraphicalEditPart ownerEditPart = (GraphicalEditPart)decoratorTarget.getAdapter(GraphicalEditPart.class);
186
		ownerEditPart.getViewer().getVisualPartMap().remove(Decoration);
187
188
	}
189
190
	/**
191
	 * Gets the decoration.
192
	 *
193
	 * @param decoratorTarget the decorator target
194
	 * @param image the image
195
	 * @param position the position
196
	 * @param percentageFromSource the percentage from source
197
	 * @param margin the margin
198
	 * @param isVolatile the is volatile
199
	 * @return the decoration
200
	 */
201
	public org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration getDecoration(IDecoratorTarget decoratorTarget, Image image, PreferedPosition position, int percentageFromSource, int margin, boolean isVolatile) {
202
		View view = (View)decoratorTarget.getAdapter(View.class);
203
		org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration decoration = null;
204
		if(view == null || view.eResource() == null || image == null) {
205
			return decoration;
206
		}
207
		EditPart editPart = (EditPart)decoratorTarget.getAdapter(EditPart.class);
208
		if(editPart == null || editPart.getViewer() == null) {
209
			return decoration;
210
		}
211
		if(editPart instanceof org.eclipse.gef.GraphicalEditPart) {
212
			if(view instanceof Edge) {
213
				decoration = decoratorTarget.addConnectionDecoration(image, percentageFromSource, isVolatile);
214
			} else {
215
				if(editPart instanceof org.eclipse.gef.GraphicalEditPart) {
216
					margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart)editPart).getFigure()).DPtoLP(margin);
217
				}
218
				decoration = decoratorTarget.addShapeDecoration(image, getDirection(position), margin, isVolatile);
219
			}
220
221
		}
222
		return decoration;
223
	}
224
225
	/**
226
	 * Gets the direction.
227
	 *
228
	 * @param position the position
229
	 * @return the direction
230
	 */
231
	private Direction getDirection(PreferedPosition position) {
232
233
		switch(position) {
234
235
		case NORTH_WEST:
236
			return IDecoratorTarget.Direction.NORTH_WEST;
237
		case NORTH:
238
			return IDecoratorTarget.Direction.NORTH;
239
		case NORTH_EAST:
240
			return IDecoratorTarget.Direction.NORTH_EAST;
241
		case EAST:
242
			return IDecoratorTarget.Direction.EAST;
243
		case SOUTH_EAST:
244
			return IDecoratorTarget.Direction.SOUTH_EAST;
245
		case SOUTH:
246
			return IDecoratorTarget.Direction.SOUTH;
247
		case SOUTH_WEST:
248
			return IDecoratorTarget.Direction.SOUTH_WEST;
249
		case WEST:
250
			return IDecoratorTarget.Direction.WEST;
251
		case CENTER:
252
			return IDecoratorTarget.Direction.CENTER;
253
		default:
254
			return IDecoratorTarget.Direction.NORTH_EAST;
255
256
		}
257
	}
258
259
	/**
260
	 * Gets the decoration.
261
	 *
262
	 * @param decoratorTarget the decorator target
263
	 * @param figure the figure
264
	 * @param position the position
265
	 * @param percentageFromSource the percentage from source
266
	 * @param margin the margin
267
	 * @param isVolatile the is volatile
268
	 * @return the decoration
269
	 */
270
	public org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration getDecoration(IDecoratorTarget decoratorTarget, IFigure figure, PreferedPosition position, int percentageFromSource, int margin, boolean isVolatile) {
271
272
		View view = (View)decoratorTarget.getAdapter(View.class);
273
		org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration decoration = null;
274
		if(view == null || view.eResource() == null || figure == null) {
275
			return decoration;
276
		}
277
		EditPart editPart = (EditPart)decoratorTarget.getAdapter(EditPart.class);
278
		if(editPart == null || editPart.getViewer() == null) {
279
			return decoration;
280
		}
281
		if(editPart instanceof org.eclipse.gef.GraphicalEditPart) {
282
			if(view instanceof Edge) {
283
				decoration = decoratorTarget.addConnectionDecoration(figure, percentageFromSource, isVolatile);
284
			} else {
285
				if(editPart instanceof org.eclipse.gef.GraphicalEditPart) {
286
					margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart)editPart).getFigure()).DPtoLP(margin);
287
				}
288
				decoration = decoratorTarget.addShapeDecoration(figure, getDirection(position), margin, isVolatile);
289
			}
290
291
		}
292
		return decoration;
293
	}
294
295
}
(-)src/org/eclipse/papyrus/diagram/common/providers/ValidationDecoratorProvider.java (-255 / +70 lines)
Lines 11-53 Link Here
11
 *    Ansgar Radermacher (CEA LIST) - added support for EMF validation
11
 *    Ansgar Radermacher (CEA LIST) - added support for EMF validation
12
 *    	bug fix and re-factoring (separating common class)
12
 *    	bug fix and re-factoring (separating common class)
13
 *      specific version for Papyrus
13
 *      specific version for Papyrus
14
 *      Amine EL KOUHEN (CEA LIST) - Added decoration Service
14
 */
15
 */
15
 package org.eclipse.papyrus.diagram.common.providers;
16
package org.eclipse.papyrus.diagram.common.providers;
16
17
17
import static org.eclipse.papyrus.core.Activator.log;
18
import static org.eclipse.papyrus.core.Activator.log;
18
19
19
import java.util.HashMap;
20
import java.util.HashMap;
20
import java.util.Map;
21
import java.util.Map;
22
import java.util.Observable;
23
import java.util.Observer;
21
24
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.core.resources.IMarker;
24
import org.eclipse.core.resources.IResource;
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.draw2d.FlowLayout;
27
import org.eclipse.draw2d.Label;
25
import org.eclipse.draw2d.Label;
28
import org.eclipse.emf.common.util.BasicEList;
29
import org.eclipse.emf.common.util.EList;
30
import org.eclipse.emf.ecore.EObject;
31
import org.eclipse.emf.ecore.EValidator;
32
import org.eclipse.emf.transaction.TransactionalEditingDomain;
26
import org.eclipse.emf.transaction.TransactionalEditingDomain;
33
import org.eclipse.emf.transaction.util.TransactionUtil;
27
import org.eclipse.emf.transaction.util.TransactionUtil;
34
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
35
import org.eclipse.gef.EditPart;
28
import org.eclipse.gef.EditPart;
36
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
29
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
37
import org.eclipse.gmf.runtime.common.core.service.IOperation;
30
import org.eclipse.gmf.runtime.common.core.service.IOperation;
38
import org.eclipse.gmf.runtime.common.ui.resources.FileChangeManager;
39
import org.eclipse.gmf.runtime.common.ui.resources.IFileObserver;
40
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
31
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
32
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramEditDomain;
41
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator;
33
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.AbstractDecorator;
34
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration;
42
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator;
35
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator;
43
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
36
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
44
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
37
import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
45
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
38
import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
46
import org.eclipse.gmf.runtime.notation.Edge;
39
import org.eclipse.gmf.runtime.notation.Edge;
47
import org.eclipse.gmf.runtime.notation.View;
40
import org.eclipse.gmf.runtime.notation.View;
48
import org.eclipse.papyrus.diagram.common.util.CrossReferencerUtil;
41
import org.eclipse.jface.resource.ImageDescriptor;
49
import org.eclipse.papyrus.validation.ValidationUtils;
42
import org.eclipse.papyrus.core.services.ServicesRegistry;
50
import org.eclipse.swt.graphics.Image;
43
import org.eclipse.papyrus.decoration.DecorationService;
44
import org.eclipse.papyrus.diagram.common.util.ServiceUtilsForGMF;
51
import org.eclipse.ui.ISharedImages;
45
import org.eclipse.ui.ISharedImages;
52
import org.eclipse.ui.PlatformUI;
46
import org.eclipse.ui.PlatformUI;
53
47
Lines 56-87 Link Here
56
 */
50
 */
57
public abstract class ValidationDecoratorProvider extends AbstractProvider implements IDecoratorProvider {
51
public abstract class ValidationDecoratorProvider extends AbstractProvider implements IDecoratorProvider {
58
52
59
	protected static final String KEY = "validationStatus";  //$NON-NLS-1$
53
	protected static final String KEY = "validationStatus"; //$NON-NLS-1$
60
	
61
	/**
62
	 * generic marker for GMF validation (currently not used)
63
	 */
64
	private static final String MARKER_TYPE = "org.eclipse.papyrus.diagram.common.diagnostic"; //$NON-NLS-1$
65
54
66
	/**
55
	private static Map<String, IDecorator> allDecorators = new HashMap<String, IDecorator>();
67
	 * global map of fileObserver par editing domain
68
	 */
69
	private static Map<TransactionalEditingDomain, MarkerObserver> fileObservers = new HashMap<TransactionalEditingDomain, MarkerObserver>();
70
56
71
	private static Map<String, IDecorator> allDecorators = new HashMap<String, IDecorator> ();
72
73
	/**
57
	/**
74
	 * Refined by generated class
58
	 * Refined by generated class
59
	 * 
75
	 * @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider#createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget)
60
	 * @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider#createDecorators(org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget)
76
	 *
61
	 * 
77
	 * @param decoratorTarget
62
	 * @param decoratorTarget
78
	 */
63
	 */
79
	public abstract void createDecorators (IDecoratorTarget decoratorTarget);
64
	public abstract void createDecorators(IDecoratorTarget decoratorTarget);
80
65
81
	/**
66
	/**
82
	 * Refined by generated class
67
	 * Refined by generated class
68
	 * 
83
	 * @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation)
69
	 * @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(org.eclipse.gmf.runtime.common.core.service.IOperation)
84
	 *
70
	 * 
85
	 * @param operation
71
	 * @param operation
86
	 * @return
72
	 * @return
87
	 */
73
	 */
Lines 89-94 Link Here
89
75
90
	/**
76
	/**
91
	 * Refresh the decorators of a specific view
77
	 * Refresh the decorators of a specific view
78
	 * 
92
	 * @param view
79
	 * @param view
93
	 */
80
	 */
94
	public static void refreshDecorators(View view) {
81
	public static void refreshDecorators(View view) {
Lines 100-106 Link Here
100
	 */
87
	 */
101
	private static void refreshDecorators(String viewId, final TransactionalEditingDomain domain) {
88
	private static void refreshDecorators(String viewId, final TransactionalEditingDomain domain) {
102
		final IDecorator decorator = viewId != null ? allDecorators.get(viewId) : null;
89
		final IDecorator decorator = viewId != null ? allDecorators.get(viewId) : null;
103
		if (decorator == null || domain == null) {
90
		if(decorator == null || domain == null) {
104
			return;
91
			return;
105
		}
92
		}
106
		PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
93
		PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
Lines 120-126 Link Here
120
		});
107
		});
121
	}
108
	}
122
109
123
	public static class StatusDecorator extends AbstractDecorator {
110
	public static class StatusDecorator extends AbstractDecorator implements Observer {
124
111
125
		/**
112
		/**
126
		 * The ID of the view
113
		 * The ID of the view
Lines 133-144 Link Here
133
		private TransactionalEditingDomain editingDomain;
120
		private TransactionalEditingDomain editingDomain;
134
121
135
		/**
122
		/**
123
		 * Decoration Service
124
		 */
125
		private DecorationService decorationService;
126
127
		/**
128
		 * Diagram Decorator
129
		 */
130
		private final DiagramDecorationAdapter diagramDecorationAdapter;
131
132
		/**
136
		 * @generated
133
		 * @generated
137
		 */
134
		 */
138
		public StatusDecorator(IDecoratorTarget decoratorTarget) {
135
		public StatusDecorator(IDecoratorTarget decoratorTarget) {
139
			super(decoratorTarget);
136
			super(decoratorTarget);
137
			diagramDecorationAdapter = new DiagramDecorationAdapter(decoratorTarget);
140
			try {
138
			try {
141
				final View view = (View)getDecoratorTarget().getAdapter(View.class);
139
				final View view = (View)getDecoratorTarget().getAdapter(View.class);
140
				EditPart editPart = (EditPart)getDecoratorTarget().getAdapter(EditPart.class);
141
				IDiagramEditDomain domain = (IDiagramEditDomain)editPart.getViewer().getEditDomain();
142
				ServicesRegistry serviceRegistry = ServiceUtilsForGMF.getInstance().getServiceRegistry(domain);
143
				decorationService = serviceRegistry.getService(DecorationService.class);
144
				//Register As an Decoration service customer
145
				decorationService.addListener(this);
142
				TransactionUtil.getEditingDomain(view).runExclusive(new Runnable() {
146
				TransactionUtil.getEditingDomain(view).runExclusive(new Runnable() {
143
147
144
					public void run() {
148
					public void run() {
Lines 157-162 Link Here
157
		 * @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator#refresh()
161
		 * @see org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecorator#refresh()
158
		 */
162
		 */
159
		public void refresh() {
163
		public void refresh() {
164
160
			removeDecoration();
165
			removeDecoration();
161
			View view = (View)getDecoratorTarget().getAdapter(View.class);
166
			View view = (View)getDecoratorTarget().getAdapter(View.class);
162
			if(view == null || view.eResource() == null) {
167
			if(view == null || view.eResource() == null) {
Lines 166-279 Link Here
166
			if(editPart == null || editPart.getViewer() == null) {
171
			if(editPart == null || editPart.getViewer() == null) {
167
				return;
172
				return;
168
			}
173
			}
169
170
			// query for all the validation markers of the current resource
171
			String elementId = ViewUtil.getIdStr(view);
172
			if(elementId == null) {
173
				return;
174
			}
175
			int severity = IMarker.SEVERITY_INFO;
176
			IMarker foundMarker = null;
177
			IResource gmfResource = WorkspaceSynchronizer.getFile(view.eResource());
178
			if(gmfResource == null || !gmfResource.exists()) {
179
				return;
180
			}
181
			IResource emfResource = null;
182
			if(view.getElement() != null) {
183
				emfResource = WorkspaceSynchronizer.getFile(view.getElement().eResource());
184
				// allow emfResource being empty, since there might be gmf views without an EObject behind;
185
			}
186
187
			IMarker[] gmfMarkers = null;
188
			IMarker[] emfMarkers = new IMarker[0];
189
			try {
190
				gmfMarkers = gmfResource.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE);
191
				if(emfResource != null) {
192
					emfMarkers = emfResource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
193
				}
194
			} catch (CoreException e) {
195
				log.error("Validation markers refresh failure", e); //$NON-NLS-1$
196
			}
197
			if(gmfMarkers == null) {
198
				// indicates an exception, findMarkers returns an empty array, if there are no markers
199
				return;
200
			}
201
			Label toolTip = null;
202
			// look for GMF markers
203
			for(int i = 0; i < gmfMarkers.length + emfMarkers.length; i++) {
204
				IMarker marker;
205
				boolean markerIsForMe = false;
206
				if(i < gmfMarkers.length) {
207
					// get marker from GMF list
208
					marker = gmfMarkers[i];
209
					String attribute = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); //$NON-NLS-1$
210
					markerIsForMe = attribute.equals(elementId);
211
				} else {
212
					// get marker from EMF list
213
					marker = emfMarkers[i - gmfMarkers.length];
214
					EObject eObjectOfMarker = ValidationUtils.eObjectFromMarkerOrMap(marker, null, editingDomain);
215
					markerIsForMe = (eObjectOfMarker == view.getElement());
216
				}
217
				if(markerIsForMe) {
218
					int nextSeverity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
219
					Image nextImage = getImage(nextSeverity);
220
					if(foundMarker == null) {
221
						foundMarker = marker;
222
						toolTip = new Label(marker.getAttribute(IMarker.MESSAGE, ""), //$NON-NLS-1$
223
						nextImage);
224
					} else {
225
						if(toolTip.getChildren().isEmpty()) {
226
							Label comositeLabel = new Label();
227
							FlowLayout fl = new FlowLayout(false);
228
							fl.setMinorSpacing(0);
229
							comositeLabel.setLayoutManager(fl);
230
							comositeLabel.add(toolTip);
231
							toolTip = comositeLabel;
232
						}
233
						toolTip.add(new Label(marker.getAttribute(IMarker.MESSAGE, ""), //$NON-NLS-1$
234
						nextImage));
235
					}
236
					severity = (nextSeverity > severity) ? nextSeverity : severity;
237
				}
238
			}
239
			if(foundMarker == null) {
240
				return;
241
			}
242
243
			// add decoration
174
			// add decoration
175
			IDecoration deco = null;
176
			org.eclipse.papyrus.decoration.util.IDecoration decoration = null;
244
			if(editPart instanceof org.eclipse.gef.GraphicalEditPart) {
177
			if(editPart instanceof org.eclipse.gef.GraphicalEditPart) {
178
				decoration = decorationService.getDecoration(view.getElement(), false);
179
				decoration.setDecorationImage(getImageDescriptor(decoration.getSeverity()));
245
				if(view instanceof Edge) {
180
				if(view instanceof Edge) {
246
					setDecoration(getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true));
181
					/* Test *///decoration.setDecorationImage(Activator.imageDescriptorFromPlugin(Activator.ID, "icons/obj16/Device.gif"));
182
					deco = diagramDecorationAdapter.setDecoration(decoration, 50, 0, true);
247
				} else {
183
				} else {
248
					int margin = -1;
184
					int margin = -1;
249
					if(editPart instanceof org.eclipse.gef.GraphicalEditPart) {
185
					if(editPart instanceof org.eclipse.gef.GraphicalEditPart) {
250
						margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart)editPart).getFigure()).DPtoLP(margin);
186
						margin = MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart)editPart).getFigure()).DPtoLP(margin);
251
					}
187
					}
252
					setDecoration(getDecoratorTarget().addShapeDecoration(getImage(severity), IDecoratorTarget.Direction.NORTH_EAST, margin, true));
188
					deco = diagramDecorationAdapter.setDecoration(decoration, 0, margin, true);
253
				}
189
				}
190
			}
191
192
193
			if(deco != null) {
194
				setDecoration(deco);
195
				String message = decoration.getMessage();
196
				Label toolTip = diagramDecorationAdapter.getToolTip(message);
254
				getDecoration().setToolTip(toolTip);
197
				getDecoration().setToolTip(toolTip);
255
			}
198
			}
256
		}
199
		}
257
200
258
		
201
		private ImageDescriptor getImageDescriptor(int severity) {
259
		/**
202
260
		 * Get the image for a given severity
203
			ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
261
		 * @param severity
204
			ImageDescriptor overlay = null;
262
		 * @return
263
		 */
264
		private Image getImage(int severity) {
265
			String imageName = ISharedImages.IMG_OBJS_ERROR_TSK;
266
			switch(severity) {
205
			switch(severity) {
267
			case IMarker.SEVERITY_ERROR:
206
			case 2://Error
268
				imageName = ISharedImages.IMG_OBJS_ERROR_TSK;
207
				overlay = sharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_ERROR_TSK);
269
				break;
208
				break;
270
			case IMarker.SEVERITY_WARNING:
209
			case 1://Warning
271
				imageName = ISharedImages.IMG_OBJS_WARN_TSK;
210
				overlay = sharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_WARN_TSK);
272
				break;
211
				break;
273
			default:
274
				imageName = ISharedImages.IMG_OBJS_INFO_TSK;
275
			}
212
			}
276
			return PlatformUI.getWorkbench().getSharedImages().getImage(imageName);
213
214
			return overlay;
277
		}
215
		}
278
216
279
		/**
217
		/**
Lines 287-315 Link Here
287
225
288
			// add self to global decorators registry
226
			// add self to global decorators registry
289
			IDecorator decorator = allDecorators.get(viewId);
227
			IDecorator decorator = allDecorators.get(viewId);
290
			if (decorator == null) {
228
			if(decorator == null) {
291
				allDecorators.put(viewId, this);
229
				allDecorators.put(viewId, this);
292
			}
230
			}
293
		
294
			// stop listening to changes in resources if there are no more decorators
295
			MarkerObserver fileObserver = fileObservers.get(editingDomain);
296
			if (fileObserver == null) {
297
				fileObserver = new MarkerObserver(editingDomain);
298
				fileObservers.put(editingDomain, fileObserver);
299
				FileChangeManager.getInstance().addFileObserver(fileObserver);
300
			}
301
			// start listening to changes in resources
302
			View view = (View) getDecoratorTarget().getAdapter(View.class);
303
			if(view != null) {
304
				if (!fileObserver.views.contains(view)) {
305
					fileObserver.views.add(view); 
306
				}
307
			}
308
		}
231
		}
309
232
310
		/**
233
		/**
311
		 * deactivate the decorators of this view
234
		 * deactivate the decorators of this view
312
		 */
235
		 */
236
		@Override
313
		public void deactivate() {
237
		public void deactivate() {
314
			if(viewId == null) {
238
			if(viewId == null) {
315
				return;
239
				return;
Lines 317-445 Link Here
317
241
318
			// remove self from global decorators registry
242
			// remove self from global decorators registry
319
			allDecorators.remove(viewId);
243
			allDecorators.remove(viewId);
320
			
244
321
			View view = (View)getDecoratorTarget().getAdapter(View.class);
245
			View view = (View)getDecoratorTarget().getAdapter(View.class);
322
			if ((view == null) || (editingDomain == null)) {
246
			if((view == null) || (editingDomain == null)) {
323
				// should not happen
247
				// should not happen
324
				super.deactivate();
248
				super.deactivate();
325
				return;
249
				return;
326
			}
250
			}
327
328
			// stop listening to changes in resources if there are no more decorators
329
			MarkerObserver fileObserver = fileObservers.get(editingDomain);
330
			if (fileObserver != null) {
331
				fileObserver.views.remove(view);
332
				if (fileObserver.views.isEmpty()) {
333
					// no more views registered for the listener => remove observer
334
					FileChangeManager.getInstance().removeFileObserver(fileObserver);
335
					fileObservers.remove(editingDomain);
336
				}
337
			}
338
339
			super.deactivate();
251
			super.deactivate();
340
		}
252
		}
341
	}
342
253
343
	/**
254
		//Refresh when the decoration service add a decoration
344
	 * @generated
255
		public void update(Observable o, Object arg) {
345
	 */
256
			refresh();
346
	static class MarkerObserver implements IFileObserver {
347
348
		/**
349
		 * store editing domain
350
		 */
351
		private TransactionalEditingDomain domain;
352
353
		/**
354
		 * store a list of all views for which the observer is responsible
355
		 */
356
		private EList<View> views = new BasicEList<View>();
357
	
358
		/**
359
		 * Constructor.
360
		 *
361
		 * @param domain
362
		 */
363
		private MarkerObserver(TransactionalEditingDomain domain) {
364
			this.domain = domain;
365
		}
257
		}
366
367
		/**
368
		 * handle changes of file name
369
		 */
370
		public void handleFileRenamed(IFile oldFile, IFile file) {
371
		}
372
373
		public void handleFileMoved(IFile oldFile, IFile file) {
374
		}
375
376
		public void handleFileDeleted(IFile file) {
377
		}
378
379
		public void handleFileChanged(IFile file) {
380
		}
381
382
		/**
383
		 * A marker has been added, treat as change
384
		 */
385
		public void handleMarkerAdded(IMarker marker) {
386
			handleMarkerChanged(marker);
387
		}
388
389
		/**
390
		 * A marker has been deleted. Need to treat separately from change, since old values are not stored in
391
		 * marker, but in attribute map
392
		 */
393
		public void handleMarkerDeleted(IMarker marker, @SuppressWarnings("rawtypes") Map attributes) {
394
			String viewId = (String)attributes.get(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID);
395
			if(viewId != null) {
396
				refreshDecorators(viewId, domain);
397
			} else {
398
				// no viewID => assume EMF validation marker
399
				EObject eObjectFromMarker = ValidationUtils.eObjectFromMarkerOrMap(null, attributes, domain);
400
401
				if(eObjectFromMarker != null) {
402
					// loop over all views that reference the eObject from the marker
403
					for(View view : CrossReferencerUtil.getCrossReferencingViews(eObjectFromMarker, null)) {
404
						refreshDecorators(view);
405
					}
406
				}
407
			}
408
		}
409
410
		/**
411
		 * A marker has changed
412
		 */
413
		public void handleMarkerChanged(IMarker marker) {
414
			try {
415
				if(getType(marker).equals(MARKER_TYPE)) {
416
					String viewId = marker.getAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); //$NON-NLS-1$
417
					refreshDecorators(viewId, domain);
418
				} else if(marker.isSubtypeOf((EValidator.MARKER))) {
419
					EObject eObjectFromMarker = ValidationUtils.eObjectFromMarkerOrMap(marker, null, domain);
420
421
					if(eObjectFromMarker != null) {
422
						// loop over all views that reference the eObject from the marker
423
						for(View view : CrossReferencerUtil.getCrossReferencingViews(eObjectFromMarker, null)) {
424
							refreshDecorators(view);
425
						}
426
					}
427
				}
428
			} catch (CoreException e) {
429
				// only reason: marker does not exist (ignore, should not happen)
430
			}
431
		}
432
433
		/**
434
		 * Return the type of a marker
435
		 */
436
		private String getType(IMarker marker) {
437
			try {
438
				return marker.getType();
439
			} catch (CoreException e) {
440
				log.error("Validation marker refresh failure", e); //$NON-NLS-1$
441
				return ""; //$NON-NLS-1$
442
			}
443
		}
444
	}
258
	}
259
445
}
260
}

Return to bug 325610