Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 224585
Collapse All | Expand All

(-)src/org/eclipse/emf/ecoretools/diagram/edit/parts/EClassOperationsEditPart.java (-4 / +19 lines)
Lines 14-24 Link Here
14
14
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
16
16
17
import org.eclipse.draw2d.FlowLayout;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.emf.common.notify.Notification;
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.ecore.EcorePackage;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.CompartmentChildCreationEditPolicy;
19
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassOperationsCanonicalEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassOperationsCanonicalEditPolicy;
20
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassOperationsItemSemanticEditPolicy;
23
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassOperationsItemSemanticEditPolicy;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.EcoreCreationEditPolicy;
24
import org.eclipse.emf.ecoretools.diagram.edit.policies.ReorderingCompartmentEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.part.Messages;
25
import org.eclipse.emf.ecoretools.diagram.part.Messages;
23
import org.eclipse.gef.EditPolicy;
26
import org.eclipse.gef.EditPolicy;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
Lines 60-83 Link Here
60
	}
63
	}
61
64
62
	/**
65
	/**
63
	 * @generated
66
	 * @generated NOT
64
	 */
67
	 */
65
	public IFigure createFigure() {
68
	public IFigure createFigure() {
66
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
69
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
70
		FlowLayout layout = new FlowLayout();
71
		layout.setMajorSpacing(getMapMode().DPtoLP(0));
72
		layout.setMinorSpacing(getMapMode().DPtoLP(0));
73
		layout.setHorizontal(false);
74
		result.getContentPane().setLayoutManager(layout);
67
		result.setTitleVisibility(false);
75
		result.setTitleVisibility(false);
68
		return result;
76
		return result;
69
	}
77
	}
70
78
71
	/**
79
	/**
72
	 * @generated
80
	 * @generated NOT
73
	 */
81
	 */
74
	protected void createDefaultEditPolicies() {
82
	protected void createDefaultEditPolicies() {
75
		super.createDefaultEditPolicies();
83
		super.createDefaultEditPolicies();
76
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
84
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
77
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EClassOperationsItemSemanticEditPolicy());
85
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EClassOperationsItemSemanticEditPolicy());
78
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new EcoreCreationEditPolicy());
86
87
		// Use a custom Policy to create child elements and initialize their
88
		// initial position
89
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentChildCreationEditPolicy());
90
79
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
91
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
80
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EClassOperationsCanonicalEditPolicy());
92
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EClassOperationsCanonicalEditPolicy());
93
94
		// Add a policy used to reorder children
95
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new ReorderingCompartmentEditPolicy(EcorePackage.Literals.ECLASS__EOPERATIONS));
81
	}
96
	}
82
97
83
	/**
98
	/**
(-)src/org/eclipse/emf/ecoretools/diagram/edit/parts/EClassAttributesEditPart.java (-4 / +19 lines)
Lines 14-24 Link Here
14
14
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
16
16
17
import org.eclipse.draw2d.FlowLayout;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.emf.common.notify.Notification;
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.ecore.EcorePackage;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.CompartmentChildCreationEditPolicy;
19
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassAttributesCanonicalEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassAttributesCanonicalEditPolicy;
20
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassAttributesItemSemanticEditPolicy;
23
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassAttributesItemSemanticEditPolicy;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.EcoreCreationEditPolicy;
24
import org.eclipse.emf.ecoretools.diagram.edit.policies.ReorderingCompartmentEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.part.Messages;
25
import org.eclipse.emf.ecoretools.diagram.part.Messages;
23
import org.eclipse.gef.EditPolicy;
26
import org.eclipse.gef.EditPolicy;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
Lines 60-83 Link Here
60
	}
63
	}
61
64
62
	/**
65
	/**
63
	 * @generated
66
	 * @generated NOT
64
	 */
67
	 */
65
	public IFigure createFigure() {
68
	public IFigure createFigure() {
66
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
69
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
70
		FlowLayout layout = new FlowLayout();
71
		layout.setMajorSpacing(getMapMode().DPtoLP(0));
72
		layout.setMinorSpacing(getMapMode().DPtoLP(0));
73
		layout.setHorizontal(false);
74
		result.getContentPane().setLayoutManager(layout);
67
		result.setTitleVisibility(false);
75
		result.setTitleVisibility(false);
68
		return result;
76
		return result;
69
	}
77
	}
70
78
71
	/**
79
	/**
72
	 * @generated
80
	 * @generated NOT
73
	 */
81
	 */
74
	protected void createDefaultEditPolicies() {
82
	protected void createDefaultEditPolicies() {
75
		super.createDefaultEditPolicies();
83
		super.createDefaultEditPolicies();
76
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
84
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
77
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EClassAttributesItemSemanticEditPolicy());
85
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EClassAttributesItemSemanticEditPolicy());
78
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new EcoreCreationEditPolicy());
86
87
		// Use a custom Policy to create child elements and initialize their
88
		// initial position
89
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentChildCreationEditPolicy());
90
79
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
91
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
80
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EClassAttributesCanonicalEditPolicy());
92
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EClassAttributesCanonicalEditPolicy());
93
94
		// Add a policy used to reorder children
95
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new ReorderingCompartmentEditPolicy(EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES));
81
	}
96
	}
82
97
83
	/**
98
	/**
(-)src/org/eclipse/emf/ecoretools/diagram/edit/parts/EAnnotationDetailsEditPart.java (-4 / +19 lines)
Lines 14-27 Link Here
14
14
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
16
16
17
import org.eclipse.draw2d.FlowLayout;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.emf.common.notify.Notification;
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.ecore.EcorePackage;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.CompartmentChildCreationEditPolicy;
19
import org.eclipse.emf.ecoretools.diagram.edit.policies.EAnnotationDetailsCanonicalEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.edit.policies.EAnnotationDetailsCanonicalEditPolicy;
20
import org.eclipse.emf.ecoretools.diagram.edit.policies.EAnnotationDetailsItemSemanticEditPolicy;
23
import org.eclipse.emf.ecoretools.diagram.edit.policies.EAnnotationDetailsItemSemanticEditPolicy;
24
import org.eclipse.emf.ecoretools.diagram.edit.policies.ReorderingCompartmentEditPolicy;
21
import org.eclipse.emf.ecoretools.diagram.part.Messages;
25
import org.eclipse.emf.ecoretools.diagram.part.Messages;
22
import org.eclipse.gef.EditPolicy;
26
import org.eclipse.gef.EditPolicy;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
25
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
Lines 60-83 Link Here
60
	}
63
	}
61
64
62
	/**
65
	/**
63
	 * @generated
66
	 * @generated NOT
64
	 */
67
	 */
65
	public IFigure createFigure() {
68
	public IFigure createFigure() {
66
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
69
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
70
		FlowLayout layout = new FlowLayout();
71
		layout.setMajorSpacing(getMapMode().DPtoLP(0));
72
		layout.setMinorSpacing(getMapMode().DPtoLP(0));
73
		layout.setHorizontal(false);
74
		result.getContentPane().setLayoutManager(layout);
67
		result.setTitleVisibility(false);
75
		result.setTitleVisibility(false);
68
		return result;
76
		return result;
69
	}
77
	}
70
78
71
	/**
79
	/**
72
	 * @generated
80
	 * @generated NOT
73
	 */
81
	 */
74
	protected void createDefaultEditPolicies() {
82
	protected void createDefaultEditPolicies() {
75
		super.createDefaultEditPolicies();
83
		super.createDefaultEditPolicies();
76
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
84
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
77
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EAnnotationDetailsItemSemanticEditPolicy());
85
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EAnnotationDetailsItemSemanticEditPolicy());
78
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
86
87
		// Use a custom Policy to create child elements and initialize their
88
		// initial position
89
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentChildCreationEditPolicy());
90
79
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
91
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
80
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EAnnotationDetailsCanonicalEditPolicy());
92
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EAnnotationDetailsCanonicalEditPolicy());
93
94
		// Add a policy used to reorder children
95
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new ReorderingCompartmentEditPolicy(EcorePackage.Literals.EANNOTATION__DETAILS));
81
	}
96
	}
82
97
83
	/**
98
	/**
(-)src/org/eclipse/emf/ecoretools/diagram/edit/parts/EEnumLiterals2EditPart.java (-4 / +19 lines)
Lines 14-27 Link Here
14
14
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
16
16
17
import org.eclipse.draw2d.FlowLayout;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.emf.common.notify.Notification;
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.ecore.EcorePackage;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.CompartmentChildCreationEditPolicy;
19
import org.eclipse.emf.ecoretools.diagram.edit.policies.EEnumLiterals2CanonicalEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.edit.policies.EEnumLiterals2CanonicalEditPolicy;
20
import org.eclipse.emf.ecoretools.diagram.edit.policies.EEnumLiterals2ItemSemanticEditPolicy;
23
import org.eclipse.emf.ecoretools.diagram.edit.policies.EEnumLiterals2ItemSemanticEditPolicy;
24
import org.eclipse.emf.ecoretools.diagram.edit.policies.ReorderingCompartmentEditPolicy;
21
import org.eclipse.emf.ecoretools.diagram.part.Messages;
25
import org.eclipse.emf.ecoretools.diagram.part.Messages;
22
import org.eclipse.gef.EditPolicy;
26
import org.eclipse.gef.EditPolicy;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
25
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
Lines 60-83 Link Here
60
	}
63
	}
61
64
62
	/**
65
	/**
63
	 * @generated
66
	 * @generated NOT
64
	 */
67
	 */
65
	public IFigure createFigure() {
68
	public IFigure createFigure() {
66
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
69
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
70
		FlowLayout layout = new FlowLayout();
71
		layout.setMajorSpacing(getMapMode().DPtoLP(0));
72
		layout.setMinorSpacing(getMapMode().DPtoLP(0));
73
		layout.setHorizontal(false);
74
		result.getContentPane().setLayoutManager(layout);
67
		result.setTitleVisibility(false);
75
		result.setTitleVisibility(false);
68
		return result;
76
		return result;
69
	}
77
	}
70
78
71
	/**
79
	/**
72
	 * @generated
80
	 * @generated NOT
73
	 */
81
	 */
74
	protected void createDefaultEditPolicies() {
82
	protected void createDefaultEditPolicies() {
75
		super.createDefaultEditPolicies();
83
		super.createDefaultEditPolicies();
76
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
84
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
77
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EEnumLiterals2ItemSemanticEditPolicy());
85
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EEnumLiterals2ItemSemanticEditPolicy());
78
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
86
87
		// Use a custom Policy to create child elements and initialize their
88
		// initial position
89
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentChildCreationEditPolicy());
90
79
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
91
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
80
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EEnumLiterals2CanonicalEditPolicy());
92
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EEnumLiterals2CanonicalEditPolicy());
93
94
		// Add a policy used to reorder children
95
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new ReorderingCompartmentEditPolicy(EcorePackage.Literals.EENUM__ELITERALS));
81
	}
96
	}
82
97
83
	/**
98
	/**
(-)src/org/eclipse/emf/ecoretools/diagram/edit/parts/EClassOperations2EditPart.java (-4 / +19 lines)
Lines 14-24 Link Here
14
14
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
16
16
17
import org.eclipse.draw2d.FlowLayout;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.emf.common.notify.Notification;
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.ecore.EcorePackage;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.CompartmentChildCreationEditPolicy;
19
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassOperations2CanonicalEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassOperations2CanonicalEditPolicy;
20
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassOperations2ItemSemanticEditPolicy;
23
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassOperations2ItemSemanticEditPolicy;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.EcoreCreationEditPolicy;
24
import org.eclipse.emf.ecoretools.diagram.edit.policies.ReorderingCompartmentEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.part.Messages;
25
import org.eclipse.emf.ecoretools.diagram.part.Messages;
23
import org.eclipse.gef.EditPolicy;
26
import org.eclipse.gef.EditPolicy;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
Lines 60-83 Link Here
60
	}
63
	}
61
64
62
	/**
65
	/**
63
	 * @generated
66
	 * @generated NOT
64
	 */
67
	 */
65
	public IFigure createFigure() {
68
	public IFigure createFigure() {
66
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
69
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
70
		FlowLayout layout = new FlowLayout();
71
		layout.setMajorSpacing(getMapMode().DPtoLP(0));
72
		layout.setMinorSpacing(getMapMode().DPtoLP(0));
73
		layout.setHorizontal(false);
74
		result.getContentPane().setLayoutManager(layout);
67
		result.setTitleVisibility(false);
75
		result.setTitleVisibility(false);
68
		return result;
76
		return result;
69
	}
77
	}
70
78
71
	/**
79
	/**
72
	 * @generated
80
	 * @generated NOT
73
	 */
81
	 */
74
	protected void createDefaultEditPolicies() {
82
	protected void createDefaultEditPolicies() {
75
		super.createDefaultEditPolicies();
83
		super.createDefaultEditPolicies();
76
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
84
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
77
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EClassOperations2ItemSemanticEditPolicy());
85
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EClassOperations2ItemSemanticEditPolicy());
78
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new EcoreCreationEditPolicy());
86
87
		// Use a custom Policy to create child elements and initialize their
88
		// initial position
89
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentChildCreationEditPolicy());
90
79
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
91
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
80
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EClassOperations2CanonicalEditPolicy());
92
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EClassOperations2CanonicalEditPolicy());
93
94
		// Add a policy used to reorder children
95
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new ReorderingCompartmentEditPolicy(EcorePackage.Literals.ECLASS__EOPERATIONS));
81
	}
96
	}
82
97
83
	/**
98
	/**
(-)src/org/eclipse/emf/ecoretools/diagram/edit/parts/EEnumLiteralsEditPart.java (-4 / +19 lines)
Lines 14-27 Link Here
14
14
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
16
16
17
import org.eclipse.draw2d.FlowLayout;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.emf.common.notify.Notification;
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.ecore.EcorePackage;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.CompartmentChildCreationEditPolicy;
19
import org.eclipse.emf.ecoretools.diagram.edit.policies.EEnumLiteralsCanonicalEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.edit.policies.EEnumLiteralsCanonicalEditPolicy;
20
import org.eclipse.emf.ecoretools.diagram.edit.policies.EEnumLiteralsItemSemanticEditPolicy;
23
import org.eclipse.emf.ecoretools.diagram.edit.policies.EEnumLiteralsItemSemanticEditPolicy;
24
import org.eclipse.emf.ecoretools.diagram.edit.policies.ReorderingCompartmentEditPolicy;
21
import org.eclipse.emf.ecoretools.diagram.part.Messages;
25
import org.eclipse.emf.ecoretools.diagram.part.Messages;
22
import org.eclipse.gef.EditPolicy;
26
import org.eclipse.gef.EditPolicy;
27
import org.eclipse.gef.Request;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
24
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
25
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
26
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
31
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableCompartmentEditPolicy;
Lines 60-83 Link Here
60
	}
64
	}
61
65
62
	/**
66
	/**
63
	 * @generated
67
	 * @generated NOT
64
	 */
68
	 */
65
	public IFigure createFigure() {
69
	public IFigure createFigure() {
66
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
70
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
71
		FlowLayout layout = new FlowLayout();
72
		layout.setMajorSpacing(getMapMode().DPtoLP(0));
73
		layout.setMinorSpacing(getMapMode().DPtoLP(0));
74
		layout.setHorizontal(false);
75
		result.getContentPane().setLayoutManager(layout);
67
		result.setTitleVisibility(false);
76
		result.setTitleVisibility(false);
68
		return result;
77
		return result;
69
	}
78
	}
70
79
71
	/**
80
	/**
72
	 * @generated
81
	 * @generated NOT
73
	 */
82
	 */
74
	protected void createDefaultEditPolicies() {
83
	protected void createDefaultEditPolicies() {
75
		super.createDefaultEditPolicies();
84
		super.createDefaultEditPolicies();
76
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
85
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
77
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EEnumLiteralsItemSemanticEditPolicy());
86
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EEnumLiteralsItemSemanticEditPolicy());
78
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
87
		
88
		// Use a custom Policy to create child elements and initialize their initial position
89
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentChildCreationEditPolicy());
90
		
79
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
91
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
80
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EEnumLiteralsCanonicalEditPolicy());
92
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EEnumLiteralsCanonicalEditPolicy());
93
		
94
		// Add a policy used to reorder children
95
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new ReorderingCompartmentEditPolicy(EcorePackage.Literals.EENUM__ELITERALS));
81
	}
96
	}
82
97
83
	/**
98
	/**
(-)src/org/eclipse/emf/ecoretools/diagram/edit/parts/EClassAttributes2EditPart.java (-4 / +19 lines)
Lines 14-24 Link Here
14
14
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
15
package org.eclipse.emf.ecoretools.diagram.edit.parts;
16
16
17
import org.eclipse.draw2d.FlowLayout;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.emf.common.notify.Notification;
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.ecore.EcorePackage;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.CompartmentChildCreationEditPolicy;
19
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassAttributes2CanonicalEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassAttributes2CanonicalEditPolicy;
20
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassAttributes2ItemSemanticEditPolicy;
23
import org.eclipse.emf.ecoretools.diagram.edit.policies.EClassAttributes2ItemSemanticEditPolicy;
21
import org.eclipse.emf.ecoretools.diagram.edit.policies.EcoreCreationEditPolicy;
24
import org.eclipse.emf.ecoretools.diagram.edit.policies.ReorderingCompartmentEditPolicy;
22
import org.eclipse.emf.ecoretools.diagram.part.Messages;
25
import org.eclipse.emf.ecoretools.diagram.part.Messages;
23
import org.eclipse.gef.EditPolicy;
26
import org.eclipse.gef.EditPolicy;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
Lines 60-83 Link Here
60
	}
63
	}
61
64
62
	/**
65
	/**
63
	 * @generated
66
	 * @generated NOT
64
	 */
67
	 */
65
	public IFigure createFigure() {
68
	public IFigure createFigure() {
66
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
69
		ResizableCompartmentFigure result = (ResizableCompartmentFigure) super.createFigure();
70
		FlowLayout layout = new FlowLayout();
71
		layout.setMajorSpacing(getMapMode().DPtoLP(0));
72
		layout.setMinorSpacing(getMapMode().DPtoLP(0));
73
		layout.setHorizontal(false);
74
		result.getContentPane().setLayoutManager(layout);
67
		result.setTitleVisibility(false);
75
		result.setTitleVisibility(false);
68
		return result;
76
		return result;
69
	}
77
	}
70
78
71
	/**
79
	/**
72
	 * @generated
80
	 * @generated NOT
73
	 */
81
	 */
74
	protected void createDefaultEditPolicies() {
82
	protected void createDefaultEditPolicies() {
75
		super.createDefaultEditPolicies();
83
		super.createDefaultEditPolicies();
76
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
84
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ResizableCompartmentEditPolicy());
77
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EClassAttributes2ItemSemanticEditPolicy());
85
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new EClassAttributes2ItemSemanticEditPolicy());
78
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new EcoreCreationEditPolicy());
86
87
		// Use a custom Policy to create child elements and initialize their
88
		// initial position
89
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CompartmentChildCreationEditPolicy());
90
79
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
91
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
80
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EClassAttributes2CanonicalEditPolicy());
92
		installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new EClassAttributes2CanonicalEditPolicy());
93
94
		// Add a policy used to reorder children
95
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new ReorderingCompartmentEditPolicy(EcorePackage.Literals.ECLASS__ESTRUCTURAL_FEATURES));
81
	}
96
	}
82
97
83
	/**
98
	/**
(-)custom-src/org/eclipse/emf/ecoretools/diagram/edit/policies/CompartmentChildCreationEditPolicy.java (+134 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008 Anyware Technologies and others
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Anyware Technologies - initial API and implementation
11
 */
12
package org.eclipse.emf.ecoretools.diagram.edit.policies;
13
14
import java.util.List;
15
16
import org.eclipse.draw2d.FlowLayout;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.geometry.Point;
19
import org.eclipse.draw2d.geometry.Rectangle;
20
import org.eclipse.draw2d.geometry.Transposer;
21
import org.eclipse.emf.ecoretools.diagram.edit.commands.CompartmentChildCreateCommand;
22
import org.eclipse.emf.transaction.TransactionalEditingDomain;
23
import org.eclipse.gef.EditPart;
24
import org.eclipse.gef.Request;
25
import org.eclipse.gef.commands.Command;
26
import org.eclipse.gef.requests.DropRequest;
27
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
32
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
33
import org.eclipse.gmf.runtime.notation.View;
34
35
/**
36
 * A CreationEditPolicy that could be used in addition with a FlowLayout to
37
 * support child ordering at creation
38
 * 
39
 * Creation : 28 mar. 2008
40
 * 
41
 * @author <a href="mailto:jacques.lescot@anyware-tech.com">Jacques LESCOT</a>
42
 */
43
public class CompartmentChildCreationEditPolicy extends EcoreCreationEditPolicy {
44
45
	/**
46
	 * @see org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy#getCreateCommand(org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest)
47
	 */
48
	protected Command getCreateCommand(CreateViewRequest request) {
49
		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
50
		CompositeTransactionalCommand cc = new CompositeTransactionalCommand(editingDomain, DiagramUIMessages.AddCommand_Label);
51
52
		for (CreateViewRequest.ViewDescriptor descriptor : (List<CreateViewRequest.ViewDescriptor>) request.getViewDescriptors()) {
53
			cc.compose(new CompartmentChildCreateCommand(editingDomain, descriptor, (View) (getHost().getModel()), getFeedbackIndexFor(request)));
54
		}
55
		return new ICommandProxy(cc.reduce());
56
	}
57
58
	protected int getFeedbackIndexFor(Request request) {
59
		List<EditPart> children = (List<EditPart>) getHost().getChildren();
60
		if (children.isEmpty())
61
			return -1;
62
63
		Transposer transposer = new Transposer();
64
		transposer.setEnabled(!isHorizontal());
65
66
		Point p = transposer.t(getLocationFromRequest(request));
67
		// EcoreDiagramEditorPlugin.getInstance().getLog().log(new
68
		// Status(IStatus.INFO, EcoreDiagramEditorPlugin.ID, p.toString()));
69
70
		// Current row bottom, initialize to below the bottom.
71
		int rowBottom = Integer.MIN_VALUE;
72
		int candidate = -1;
73
		// When the request is created outside the Compartment, the element is
74
		// added at the end of the list (this is the case when the element is
75
		// created from the parent header accelerator
76
		if (transposer.t(getAbsoluteBounds(((GraphicalEditPart) getHost()))).contains(p)) {
77
			for (int i = 0; i < children.size(); i++) {
78
				EditPart child = children.get(i);
79
				Rectangle rect = transposer.t(getAbsoluteBounds(((GraphicalEditPart) child)));
80
				if (rect.y > rowBottom) {
81
					// We are in a new row, so if we don't have a candidate but
82
					// yet are within the previous row, then the current entry
83
					// becomes the candidate. This is because we know we must be
84
					// to the right of center of the last Figure in the previous
85
					// row, so this Figure (which is at the start of a new row)
86
					// is the candidate.
87
					if (p.y <= rowBottom) {
88
						if (candidate == -1) {
89
							candidate = i;
90
						}
91
						break;
92
					} else {
93
						// Mouse's Y is outside the row, so reset the candidate
94
						candidate = -1;
95
					}
96
				}
97
				rowBottom = Math.max(rowBottom, rect.bottom());
98
				if (candidate == -1) {
99
					// See if we have a possible candidate. It is a candidate if
100
					// the cursor is left of the center of this candidate.
101
					if (p.x <= rect.x + (rect.width / 2)) {
102
						candidate = i;
103
					}
104
				}
105
				if (candidate != -1) {
106
					// We have a candidate, see if the rowBottom has grown to
107
					// include the mouse Y.
108
					if (p.y <= rowBottom) {
109
						// Now we have determined that the cursor.Y is above the
110
						// bottom of the current row of figures. Stop now, to
111
						// prevent the next row from being searched
112
						break;
113
					}
114
				}
115
			}
116
		}
117
		return candidate;
118
	}
119
120
	protected boolean isHorizontal() {
121
		IFigure figure = ((GraphicalEditPart) getHost()).getContentPane();
122
		return ((FlowLayout) figure.getLayoutManager()).isHorizontal();
123
	}
124
125
	private Point getLocationFromRequest(Request request) {
126
		return ((DropRequest) request).getLocation();
127
	}
128
129
	private Rectangle getAbsoluteBounds(GraphicalEditPart ep) {
130
		Rectangle bounds = ep.getFigure().getBounds().getCopy();
131
		ep.getFigure().translateToAbsolute(bounds);
132
		return bounds;
133
	}
134
}
(-)custom-src/org/eclipse/emf/ecoretools/diagram/edit/commands/CompartmentChildCreateCommand.java (+55 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008, 2009 Anyware Technologies and others
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Anyware Technologies - initial API and implementation
11
 */
12
package org.eclipse.emf.ecoretools.diagram.edit.commands;
13
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.runtime.Assert;
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.emf.transaction.TransactionalEditingDomain;
19
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
20
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
21
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
22
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
23
import org.eclipse.gmf.runtime.notation.View;
24
25
/**
26
 * Command used to add a child element at a specified position
27
 * (it should be installed in a Compartment using a List layout).
28
 * 
29
 * Creation : 28 mar. 2008
30
 * 
31
 * @author <a href="mailto:jacques.lescot@anyware-tech.com">Jacques LESCOT</a>
32
 */
33
public class CompartmentChildCreateCommand extends CreateCommand {
34
35
	private int index;
36
37
	public CompartmentChildCreateCommand(TransactionalEditingDomain editingDomain, ViewDescriptor viewDescriptor, View containerView, int index) {
38
		super(editingDomain, viewDescriptor, containerView);
39
		this.index = index;
40
	}
41
42
	/**
43
	 * @see org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
44
	 */
45
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
46
47
		View view = ViewService.getInstance().createView(viewDescriptor.getViewKind(), viewDescriptor.getElementAdapter(), containerView, viewDescriptor.getSemanticHint(), index,
48
				viewDescriptor.isPersisted(), viewDescriptor.getPreferencesHint());
49
		Assert.isNotNull(view, "failed to create a view"); //$NON-NLS-1$
50
		viewDescriptor.setView(view);
51
52
		return CommandResult.newOKCommandResult(viewDescriptor);
53
	}
54
55
}
(-)custom-src/org/eclipse/emf/ecoretools/diagram/edit/commands/CompartmentReorderEObjectCommand.java (+100 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008, 2009 Anyware Technologies and others
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Anyware Technologies - initial API and implementation
11
 */
12
package org.eclipse.emf.ecoretools.diagram.edit.commands;
13
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.core.runtime.IAdaptable;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.emf.common.util.EList;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.transaction.TransactionalEditingDomain;
20
import org.eclipse.gef.EditPart;
21
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
22
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
23
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
24
import org.eclipse.gmf.runtime.notation.View;
25
26
/**
27
 * Command used to reorder an element both in the domain model and graphically
28
 * (it should be installed in a Compartment using a List layout).
29
 * 
30
 * Creation : 11 mar. 2008
31
 * 
32
 * @author <a href="mailto:jacques.lescot@anyware-tech.com">Jacques LESCOT</a>
33
 */
34
public class CompartmentReorderEObjectCommand extends AbstractTransactionalCommand {
35
36
	// The child EditPart to move
37
	EditPart childEditPart = null;
38
39
	// The EditPart that should be after the moved one when the command is done
40
	EditPart afterEditPart = null;
41
42
	// The list of elements in which reposition will take place (domain model
43
	// side).
44
	private EList<EObject> elements;
45
46
	/**
47
	 * Constructs a runtime instance of
48
	 * <code>CompartmentReorderEObjectCommand</code>.
49
	 * 
50
	 * @param editingDomain
51
	 *            the editing domain through which model changes are made
52
	 * @param label
53
	 *            label for command
54
	 * @param elements
55
	 *            the list of elements in which reposition will take place
56
	 * @param childEditPart
57
	 *            the child being moved
58
	 * @param afterEditPart
59
	 *            <code>null</code> or the EditPart that should be after (or to
60
	 *            the right of) the child being moved
61
	 */
62
	public CompartmentReorderEObjectCommand(TransactionalEditingDomain editingDomain, String label, EList<EObject> elements, EditPart childEditPart, EditPart afterEditPart) {
63
64
		super(editingDomain, label, getWorkspaceFiles(((View) childEditPart.getModel()).getElement()));
65
66
		this.elements = elements;
67
		this.childEditPart = childEditPart;
68
		this.afterEditPart = afterEditPart;
69
	}
70
71
	/**
72
	 * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
73
	 *      org.eclipse.core.runtime.IAdaptable)
74
	 */
75
	protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
76
		CommandResult commandResult = null;
77
		try {
78
			View movedView = (View) childEditPart.getModel();
79
			EObject movedElement = movedView.getElement();
80
81
			View afterView = afterEditPart == null ? null : (View) afterEditPart.getModel();
82
			EObject afterElement = afterView == null ? null : afterView.getElement();
83
84
			// 1. Reorder the movedElement in the domain model
85
			int newSemanticPosition = afterElement == null ? elements.size() - 1 : elements.indexOf(afterElement) > elements.indexOf(movedElement) ? elements.indexOf(afterElement) - 1 : elements
86
					.indexOf(afterElement);
87
			elements.move(newSemanticPosition, movedElement);
88
89
			// 2. And then reorder the movedElement graphically
90
			EList<?> views = ((View) movedView.eContainer()).getChildren();
91
			int newViewPosition = afterView == null ? views.size() - 1 : views.indexOf(afterView) > views.indexOf(movedView) ? views.indexOf(afterView) - 1 : views.indexOf(afterView);
92
			ViewUtil.repositionChildAt((View) childEditPart.getParent().getModel(), (View) childEditPart.getModel(), newViewPosition);
93
94
		} catch (RuntimeException exp) {
95
			commandResult = CommandResult.newErrorCommandResult(exp);
96
		}
97
		return (commandResult == null) ? CommandResult.newOKCommandResult() : commandResult;
98
	}
99
100
}
(-)custom-src/org/eclipse/emf/ecoretools/diagram/edit/policies/ReorderingCompartmentEditPolicy.java (+146 lines)
Added Link Here
1
/**
2
 * Copyright (c) 2008, 2009 Anyware Technologies and others
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Anyware Technologies - initial API and implementation
11
 */
12
package org.eclipse.emf.ecoretools.diagram.edit.policies;
13
14
import org.eclipse.emf.common.util.EList;
15
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EStructuralFeature;
17
import org.eclipse.emf.ecoretools.diagram.edit.commands.CompartmentReorderEObjectCommand;
18
import org.eclipse.emf.ecoretools.diagram.part.EcoreVisualIDRegistry;
19
import org.eclipse.emf.transaction.TransactionalEditingDomain;
20
import org.eclipse.gef.EditPart;
21
import org.eclipse.gef.EditPolicy;
22
import org.eclipse.gef.Request;
23
import org.eclipse.gef.commands.Command;
24
import org.eclipse.gef.commands.UnexecutableCommand;
25
import org.eclipse.gef.requests.CreateRequest;
26
import org.eclipse.gmf.runtime.diagram.core.commands.AddCommand;
27
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableEditPolicyEx;
30
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
31
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
32
import org.eclipse.gmf.runtime.notation.View;
33
34
/**
35
 * A LayoutEditPolicy that could be used in addition with a FlowLayout to
36
 * support child reordering
37
 * 
38
 * Creation : 11 mar. 2008
39
 * 
40
 * @author <a href="mailto:jacques.lescot@anyware-tech.com">Jacques LESCOT</a>
41
 */
42
public class ReorderingCompartmentEditPolicy extends org.eclipse.gef.editpolicies.FlowLayoutEditPolicy {
43
44
	// The domain model list that contains the element to reorder
45
	private EStructuralFeature feature = null;
46
47
	/**
48
	 * @param feature
49
	 *            The EStructutalFeature containing elements to reorder
50
	 */
51
	public ReorderingCompartmentEditPolicy(EStructuralFeature feature) {
52
		super();
53
		this.feature = feature;
54
	}
55
56
	/**
57
	 * @see org.eclipse.gef.editpolicies.OrderedLayoutEditPolicy#createAddCommand(org.eclipse.gef.EditPart,
58
	 *      org.eclipse.gef.EditPart)
59
	 */
60
	protected Command createAddCommand(EditPart child, EditPart after) {
61
		View viewToMove = (View) child.getModel();
62
		if (viewToMove != null) {
63
			View newParentView = (View) getHost().getModel();
64
			if (newParentView != null) {
65
				// We check if the move/add is possible at notational level
66
				if (EcoreVisualIDRegistry.canCreateNode(newParentView, EcoreVisualIDRegistry.getVisualID(viewToMove.getType()))) {
67
					int index = getHost().getChildren().indexOf(after);
68
					TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
69
					AddCommand command = new AddCommand(editingDomain, new EObjectAdapter(newParentView), new EObjectAdapter(viewToMove), index);
70
					return new ICommandProxy(command);
71
				}
72
			}
73
		}
74
		return UnexecutableCommand.INSTANCE;
75
76
	}
77
78
	/**
79
	 * @see org.eclipse.gef.editpolicies.OrderedLayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart)
80
	 */
81
	protected EditPolicy createChildEditPolicy(EditPart child) {
82
		ResizableEditPolicyEx policy = new ResizableEditPolicyEx();
83
		policy.setResizeDirections(0);
84
		return policy;
85
	}
86
87
	/**
88
	 * @see org.eclipse.gef.editpolicies.OrderedLayoutEditPolicy#createMoveChildCommand(org.eclipse.gef.EditPart,
89
	 *      org.eclipse.gef.EditPart)
90
	 */
91
	protected Command createMoveChildCommand(EditPart child, EditPart after) {
92
		int newIndex;
93
		int moveOffset;
94
95
		int childIndex = getHost().getChildren().indexOf(child);
96
		int afterIndex = getHost().getChildren().indexOf(after);
97
98
		if (afterIndex == -1) {
99
			// Move the child to the last position
100
			newIndex = getHost().getChildren().size() - 1;
101
			moveOffset = newIndex - childIndex;
102
		} else {
103
			newIndex = afterIndex;
104
			moveOffset = afterIndex - childIndex;
105
			if (childIndex <= afterIndex) {
106
				newIndex--;
107
				moveOffset--;
108
			}
109
		}
110
111
		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
112
		CompartmentReorderEObjectCommand command = new CompartmentReorderEObjectCommand(editingDomain, "", (EList<EObject>) ((View) child.getParent().getModel()).getElement().eGet(feature), child,
113
				after);
114
115
		return new ICommandProxy(command);
116
	}
117
118
	/**
119
	 * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest)
120
	 */
121
	protected Command getCreateCommand(CreateRequest request) {
122
		return null;
123
	}
124
125
	/**
126
	 * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getDeleteDependantCommand(org.eclipse.gef.Request)
127
	 */
128
	protected Command getDeleteDependantCommand(Request request) {
129
		return null;
130
	}
131
132
	/**
133
	 * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getOrphanChildrenCommand(org.eclipse.gef.Request)
134
	 */
135
	protected Command getOrphanChildrenCommand(Request request) {
136
		return null;
137
	}
138
139
	@Override
140
	public void eraseTargetFeedback(Request request) {
141
		// Need to handle case of REQ_DROP request's type to erase feedback
142
		if (RequestConstants.REQ_DROP.equals(request.getType()))
143
			eraseLayoutTargetFeedback(request);
144
		super.eraseTargetFeedback(request);
145
	}
146
}

Return to bug 224585