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 297816 | Differences between
and this patch

Collapse All | Expand All

(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen (+7 lines)
Lines 39-44 Link Here
39
    <affixedNodes href="UML.ReusableParts.idgen#shape_uml_port_as_affixed"/>
39
    <affixedNodes href="UML.ReusableParts.idgen#shape_uml_port_as_affixed"/>
40
    <borderedNodeFigure href="UML.ReusableParts.idgen#org.eclipse.papyrus.gmf.diagram.common.figure.SelectableBorderedNodeFigure"/>
40
    <borderedNodeFigure href="UML.ReusableParts.idgen#org.eclipse.papyrus.gmf.diagram.common.figure.SelectableBorderedNodeFigure"/>
41
  </customNodes>
41
  </customNodes>
42
  <customNodes xsi:type="idgen:CustomClassifierNode" id="shape_sysml_constraintblockproperty_as_composite" label="ConstraintBlockPropertyComposite" editPart="org.eclipse.papyrus.sysml.diagram.common.edit.part.ConstraintBlockPropertyCompositeEditPart" semanticType="org.eclipse.papyrus.sysml.PartProperty" altSemanticTypes="org.eclipse.papyrus.sysml.ReferenceProperty" tag="[#runtime-defined]" compartments="compartment_sysml_blockproperty_structure" visibleCompartments="compartment_sysml_blockproperty_structure">
43
    <labels href="UML.ReusableParts.idgen#label_uml_property_label"/>
44
    <affixedNodes href="#shape_sysml_flowport_as_affixed"/>
45
    <affixedNodes href="UML.ReusableParts.idgen#shape_uml_port_as_affixed"/>
46
    <borderedNodeFigure href="UML.ReusableParts.idgen#org.eclipse.papyrus.gmf.diagram.common.figure.SelectableBorderedNodeFigure"/>
47
  </customNodes>
42
  <customNodes xsi:type="idgen:CustomClassifierNode" id="shape_sysml_dimension_as_classifier" label="Dimension" semanticType="org.eclipse.papyrus.sysml.Dimension" tag="dimension" labels="label_sysml_dimension_name"/>
48
  <customNodes xsi:type="idgen:CustomClassifierNode" id="shape_sysml_dimension_as_classifier" label="Dimension" semanticType="org.eclipse.papyrus.sysml.Dimension" tag="dimension" labels="label_sysml_dimension_name"/>
43
  <customNodes xsi:type="idgen:CustomClassifierNode" id="shape_sysml_constraintblock_as_classifier" label="ConstraintBlock" semanticType="org.eclipse.papyrus.sysml.ConstraintBlock" tag="constraint" labels="label_sysml_constraintblock_name" compartments="compartment_sysml_parameter_as_list compartment_sysml_constraint_as_list" visibleCompartments="compartment_sysml_parameter_as_list compartment_sysml_constraint_as_list"/>
49
  <customNodes xsi:type="idgen:CustomClassifierNode" id="shape_sysml_constraintblock_as_classifier" label="ConstraintBlock" semanticType="org.eclipse.papyrus.sysml.ConstraintBlock" tag="constraint" labels="label_sysml_constraintblock_name" compartments="compartment_sysml_parameter_as_list compartment_sysml_constraint_as_list" visibleCompartments="compartment_sysml_parameter_as_list compartment_sysml_constraint_as_list"/>
44
  <customNodes xsi:type="idgen:CustomClassifierNode" id="shape_sysml_flowspecification_as_classifier" label="FlowSpecification" semanticType="org.eclipse.papyrus.sysml.FlowSpecification" tag="flowSpecification" labels="label_sysml_flowspecification_name" compartments="compartment_sysml_flowproperty_as_list" visibleCompartments="compartment_sysml_flowproperty_as_list"/>
50
  <customNodes xsi:type="idgen:CustomClassifierNode" id="shape_sysml_flowspecification_as_classifier" label="FlowSpecification" semanticType="org.eclipse.papyrus.sysml.FlowSpecification" tag="flowSpecification" labels="label_sysml_flowspecification_name" compartments="compartment_sysml_flowproperty_as_list" visibleCompartments="compartment_sysml_flowproperty_as_list"/>
Lines 117-122 Link Here
117
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.part.FlowPropertyChildLabelEditPart"/>
123
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.part.FlowPropertyChildLabelEditPart"/>
118
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.part.FlowPortChildLabelEditPart"/>
124
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.part.FlowPortChildLabelEditPart"/>
119
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyCompositeEditPart"/>
125
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyCompositeEditPart"/>
126
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.part.ConstraintBlockPropertyCompositeEditPart"/>
120
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.part.AssociationEditPart"/>
127
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.part.AssociationEditPart"/>
121
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.figure.AssociationFigure"/>
128
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.figure.AssociationFigure"/>
122
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.policy.ConstraintParameterCompartmentSemanticEditPolicy"/>
129
  <javaClasses qualifiedName="org.eclipse.papyrus.sysml.diagram.common.edit.policy.ConstraintParameterCompartmentSemanticEditPolicy"/>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/commands/ConstraintExtendedDirectEditionDialog.java (+16 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.common.commands;
2
3
import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
4
import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
5
import org.eclipse.swt.widgets.Shell;
6
7
public class ConstraintExtendedDirectEditionDialog extends ExtendedDirectEditionDialog {
8
9
	public ConstraintExtendedDirectEditionDialog(Shell parentShell,
10
			Object object, String initialValue,
11
			IDirectEditorConfiguration configuration) {
12
		super(parentShell, object, initialValue, configuration);
13
		this.title = "Edit Constraint specification";
14
	}
15
16
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/commands/CreateConstraintPropertyWithTypeConfigureCommandFactory.java (+154 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.common.commands;
15
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.transaction.RecordingCommand;
21
import org.eclipse.emf.transaction.TransactionalEditingDomain;
22
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
23
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
24
import org.eclipse.gmf.runtime.common.core.command.ICommand;
25
import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
27
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
28
import org.eclipse.jface.dialogs.Dialog;
29
import org.eclipse.jface.window.Window;
30
import org.eclipse.papyrus.extensionpoints.editors.Activator;
31
import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
32
import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
33
import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
34
import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
35
import org.eclipse.papyrus.infra.services.edit.commands.AbstractConfigureCommandFactory;
36
import org.eclipse.papyrus.infra.services.edit.commands.ConfigureFeatureCommandFactory;
37
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
38
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
39
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
40
import org.eclipse.papyrus.infra.services.edit.utils.GMFCommandUtils;
41
import org.eclipse.papyrus.sysml.diagram.common.dialogs.CreateOrSelectConstraintPropertyTypeDialog;
42
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
43
import org.eclipse.swt.widgets.Display;
44
import org.eclipse.swt.widgets.Shell;
45
import org.eclipse.ui.PlatformUI;
46
import org.eclipse.uml2.uml.Package;
47
import org.eclipse.uml2.uml.Property;
48
import org.eclipse.uml2.uml.Type;
49
import org.eclipse.uml2.uml.UMLPackage;
50
51
/**
52
 * This command factory provides a command that enable Part type to be selected or created during creation.
53
 */
54
public class CreateConstraintPropertyWithTypeConfigureCommandFactory extends AbstractConfigureCommandFactory {
55
56
	/**
57
	 * {@inheritDoc}
58
	 */
59
	public ICommand create(ConfigureRequest request) {
60
61
		ICommand configureCommand = null;
62
63
		Shell shell = Display.getDefault().getActiveShell();
64
		// Start dialog to identify the new part type
65
		Property part = (Property)request.getElementToConfigure();
66
		Package partPkg = part.getNearestPackage();
67
68
		CreateOrSelectConstraintPropertyTypeDialog dialog = new CreateOrSelectConstraintPropertyTypeDialog(shell, partPkg);
69
		dialog.open();
70
		if(dialog.getReturnCode() == CreateOrSelectConstraintPropertyTypeDialog.OK) {
71
72
			final ICommand typeCreationCommand = dialog.getNewTypeCreateCommand();
73
			final Type partType = (Type)dialog.getExistingType();
74
75
			// Abort if type creation command exists but is not executable
76
			if((typeCreationCommand != null) && (!typeCreationCommand.canExecute())) {
77
				return cancelCommand(request);
78
			} else {
79
				configureCommand = CompositeCommand.compose(configureCommand, typeCreationCommand);
80
			}
81
82
			// Create the configure command that will set the constraint property type
83
			ICommand setTypeCommand = new ConfigureElementCommand(request) {
84
85
				@Override
86
				protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
87
88
					Property part = (Property)getElementToEdit();
89
					if(partType != null) {
90
						part.setType(partType);
91
					} else {
92
						Type newType = (Type)GMFCommandUtils.getCommandEObjectResult(typeCreationCommand);
93
						createConstraintBlockConstraint(newType, monitor, info);
94
						part.setType(newType);
95
					}
96
					return CommandResult.newOKCommandResult(part);
97
				}
98
99
				private void createConstraintBlockConstraint(Type newType, IProgressMonitor monitor, IAdaptable info)  throws ExecutionException {
100
					// Create the constraint attached to the ConstraintBlock
101
					IElementEditService commandService = ElementEditServiceUtils.getCommandProvider(newType);
102
					if(commandService != null) {
103
						CreateElementRequest createTypeRequest = new CreateElementRequest(newType, UMLElementTypes.CONSTRAINT);
104
						createTypeRequest.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, 
105
								new ConfigureFeatureCommandFactory(UMLPackage.eINSTANCE.getNamedElement_Name(), newType.getName() + "Specification"));
106
						ICommand newConstraintCreateCommand = commandService.getEditCommand(createTypeRequest);
107
						if (newConstraintCreateCommand.canExecute()) {
108
							newConstraintCreateCommand.execute(monitor, info);
109
							Object newObject = newConstraintCreateCommand.getCommandResult().getReturnValue();
110
							// Create the constraint specification
111
							if (newObject instanceof EObject) {
112
								final EObject newElement = (EObject)newObject;
113
								final IDirectEditorConfiguration configuration = initExtendedEditorConfiguration(newElement);
114
								Dialog dialog = new ConstraintExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), newElement, configuration.getTextToEdit(newElement), configuration);
115
								final Dialog finalDialog = dialog;
116
								if(Window.OK == dialog.open()) {
117
									TransactionalEditingDomain domain = getEditingDomain();
118
									RecordingCommand command = new RecordingCommand(domain, "Edit Constraint specification") {
119
										@Override
120
										protected void doExecute() {
121
											configuration.postEditAction(newElement, ((ILabelEditorDialog)finalDialog).getValue());
122
										}
123
									};
124
									domain.getCommandStack().execute(command);
125
								}
126
							}
127
128
						}
129
					}
130
				}
131
			};
132
133
			configureCommand = CompositeCommand.compose(configureCommand, setTypeCommand);
134
			return configureCommand;
135
		}
136
137
		return cancelCommand(request);
138
	}
139
	
140
	/**
141
	 * Initializes the extended editor configuration
142
	 */
143
	protected IDirectEditorConfiguration initExtendedEditorConfiguration(EObject element) {
144
		IDirectEditorConfiguration configuration;
145
		final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + element.eClass().getInstanceClassName());
146
		if(languagePreferred != null && !languagePreferred.equals("")) {
147
			configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, element.eClass().getInstanceClassName());
148
		} else {
149
			configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, element.eClass().getInstanceClassName());
150
		}
151
		return configuration;
152
	}
153
154
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/dialogs/CreateOrSelectConstraintPropertyTypeDialog.java (+122 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.common.dialogs;
15
16
import org.eclipse.papyrus.sysml.constraints.ConstraintsPackage;
17
import org.eclipse.papyrus.sysml.diagram.common.messages.Messages;
18
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
19
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
20
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.uml2.uml.NamedElement;
22
import org.eclipse.uml2.uml.UMLPackage;
23
24
/**
25
 * Dialog for initialization of Part (Property) type (the type is either selected or created).
26
 */
27
public class CreateOrSelectConstraintPropertyTypeDialog extends CreateOrSelectTypeDialog {
28
29
	/** Constructor */
30
	public CreateOrSelectConstraintPropertyTypeDialog(Shell shell, NamedElement owner) {
31
		super(shell, owner, SysMLElementTypes.CONSTRAINT_BLOCK, UMLPackage.eINSTANCE.getTypedElement_Type(), ConstraintsPackage.eINSTANCE.getConstraintBlock(), UMLElementTypes.PACKAGE, UMLPackage.eINSTANCE.getPackage_PackagedElement(), null);
32
	}
33
34
	/**
35
	 * {@inheritDoc}
36
	 */
37
	@Override
38
	protected String getDialogTitle() {
39
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_DialogTitle;
40
	}
41
42
	/**
43
	 * {@inheritDoc}
44
	 */
45
	@Override
46
	protected String getSelectionSectionTitle() {
47
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_SelectionSectionTitle;
48
	}
49
50
	/**
51
	 * {@inheritDoc}
52
	 */
53
	@Override
54
	protected String getSelectionSectionRadioLabel() {
55
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_SelectionSectionRadioLabel;
56
	}
57
58
	/**
59
	 * {@inheritDoc}
60
	 */
61
	@Override
62
	protected String getCreationSectionTitle() {
63
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_CreationSectionTitle;
64
	}
65
66
	/**
67
	 * {@inheritDoc}
68
	 */
69
	@Override
70
	protected String getCreationSectionRadioLabel() {
71
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_CreationSectionRadioLabel;
72
	}
73
74
	/**
75
	 * {@inheritDoc}
76
	 */
77
	@Override
78
	protected String getNewTypeNameLabel() {
79
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_NewTypeNameLabel;
80
	}
81
82
	/**
83
	 * {@inheritDoc}
84
	 */
85
	@Override
86
	protected String getNewTypeContainerNameLabel() {
87
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_NewTypeContainerNameLabel;
88
	}
89
90
	/**
91
	 * {@inheritDoc}
92
	 */
93
	@Override
94
	protected String getNewTypeContainerDialogTitle() {
95
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_SelectNewTypeContainerDialogTitle;
96
	}
97
98
	/**
99
	 * {@inheritDoc}
100
	 */
101
	@Override
102
	protected String getNewTypeContainerDialogMessage() {
103
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_SelectNewTypeContainerDialogMessage;
104
	}
105
106
	/**
107
	 * {@inheritDoc}
108
	 */
109
	@Override
110
	protected String getTypeDialogTitle() {
111
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_SelectTypeDialogTitle;
112
	}
113
114
	/**
115
	 * {@inheritDoc}
116
	 */
117
	@Override
118
	protected String getTypeDialogMessage() {
119
		return Messages.CreateOrSelectConstraintPropertyTypeDialog_SelectTypeDialogMessage;
120
	}
121
	
122
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/edit/part/ConstraintBlockPropertyCompositeEditPart.java (+222 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011-2012 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.common.edit.part;
15
16
import java.util.List;
17
18
import org.eclipse.draw2d.IFigure;
19
import org.eclipse.draw2d.PositionConstants;
20
import org.eclipse.emf.common.notify.Notification;
21
import org.eclipse.emf.ecore.EObject;
22
import org.eclipse.gef.EditPart;
23
import org.eclipse.gef.EditPolicy;
24
import org.eclipse.gef.Request;
25
import org.eclipse.gef.commands.Command;
26
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
27
import org.eclipse.gef.requests.CreateRequest;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
30
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
31
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy;
32
import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
33
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
34
import org.eclipse.gmf.runtime.notation.View;
35
import org.eclipse.papyrus.gmf.diagram.common.figure.SelectableBorderedNodeFigure;
36
import org.eclipse.papyrus.sysml.diagram.common.edit.policy.BlockPropertyCompositeSemanticEditPolicy;
37
import org.eclipse.papyrus.sysml.diagram.common.figure.ConstraintBlockPropertyCompositeFigure;
38
import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementEditPart;
39
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintNodeLabelEditPart;
40
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintParameterAffixedNodeEditPart;
41
import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedNodeEditPart;
42
import org.eclipse.papyrus.uml.diagram.common.edit.part.PropertyNodeLabelEditPart;
43
import org.eclipse.papyrus.uml.diagram.common.edit.policy.EncapsulatedClassifierResizableShapeEditPolicy;
44
import org.eclipse.papyrus.uml.diagram.common.edit.policy.StructuredClassifierCreationEditPolicy;
45
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy;
46
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy;
47
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeNodeLabelDisplayEditPolicy;
48
import org.eclipse.papyrus.uml.diagram.common.editpolicies.BorderItemResizableEditPolicy;
49
import org.eclipse.papyrus.uml.diagram.common.editpolicies.QualifiedNameDisplayEditPolicy;
50
import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy;
51
import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideRelatedContentsEditPolicy;
52
import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure;
53
import org.eclipse.papyrus.uml.diagram.common.locator.ConstraintParameterPositionLocator;
54
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
55
import org.eclipse.uml2.uml.Property;
56
import org.eclipse.uml2.uml.UMLPackage;
57
58
public class ConstraintBlockPropertyCompositeEditPart extends AbstractElementEditPart {
59
60
	public ConstraintBlockPropertyCompositeEditPart(View view) {
61
		super(view);
62
	}
63
64
	@Override
65
	protected void createDefaultEditPolicies() {
66
		super.createDefaultEditPolicies();
67
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new BlockPropertyCompositeSemanticEditPolicy());
68
		installEditPolicy(ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY, new ShowHideCompartmentEditPolicy());
69
		installEditPolicy(ShowHideRelatedContentsEditPolicy.SHOW_HIDE_RELATED_CONTENTS_POLICY, new ShowHideRelatedContentsEditPolicy());
70
		installEditPolicy(QualifiedNameDisplayEditPolicy.QUALIFIED_NAME_POLICY, new QualifiedNameDisplayEditPolicy());
71
		installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeNodeLabelDisplayEditPolicy());
72
		installEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE, new AffixedNodeAlignmentEditPolicy());
73
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new StructuredClassifierCreationEditPolicy());
74
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new EncapsulatedClassifierResizableShapeEditPolicy());
75
	}
76
77
	@Override
78
	protected LayoutEditPolicy createLayoutEditPolicy() {
79
		org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy lep = new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy() {
80
81
			@Override
82
			protected EditPolicy createChildEditPolicy(EditPart child) {
83
				if(child instanceof IBorderItemEditPart) {
84
					return new BorderItemResizableEditPolicy();
85
				}
86
87
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
88
				if(result == null) {
89
					result = new NonResizableEditPolicy();
90
				}
91
				return result;
92
			}
93
94
			@Override
95
			protected Command getMoveChildrenCommand(Request request) {
96
				return null;
97
			}
98
99
			@Override
100
			protected Command getCreateCommand(CreateRequest request) {
101
				return null;
102
			}
103
		};
104
		return lep;
105
	}
106
107
	@Override
108
	protected boolean addFixedChild(EditPart childEditPart) {
109
110
		if(childEditPart instanceof PropertyNodeLabelEditPart) {
111
			((PropertyNodeLabelEditPart)childEditPart).setLabel(getPrimaryShape().getNameLabel());
112
			return true;
113
		}
114
		if(childEditPart instanceof ConstraintNodeLabelEditPart) {
115
			((ConstraintNodeLabelEditPart)childEditPart).setLabel((((ConstraintBlockPropertyCompositeFigure)getPrimaryShape()).getConstraintLabel()));
116
			return true;
117
		}
118
119
		if(childEditPart instanceof ConstraintParameterAffixedNodeEditPart) {
120
			IBorderItemLocator locator = new ConstraintParameterPositionLocator(getMainFigure(), PositionConstants.NONE);
121
			getBorderedFigure().getBorderItemContainer().add(((ConstraintParameterAffixedNodeEditPart)childEditPart).getFigure(), locator);
122
			return true;
123
		}
124
125
		return false;
126
	}
127
128
	@Override
129
	protected boolean removeFixedChild(EditPart childEditPart) {
130
131
		if(childEditPart instanceof PropertyNodeLabelEditPart) {
132
			return true;
133
		}
134
135
		if(childEditPart instanceof FlowPortAffixedNodeEditPart) {
136
			getBorderedFigure().getBorderItemContainer().remove(((FlowPortAffixedNodeEditPart)childEditPart).getFigure());
137
			return true;
138
		}
139
		if(childEditPart instanceof PortAffixedNodeEditPart) {
140
			getBorderedFigure().getBorderItemContainer().remove(((PortAffixedNodeEditPart)childEditPart).getFigure());
141
			return true;
142
		}
143
144
		return false;
145
	}
146
147
	@Override
148
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
149
		if(editPart instanceof IBorderItemEditPart) {
150
			return getBorderedFigure().getBorderItemContainer();
151
		}
152
153
		return getContentPane();
154
	}
155
156
	@Override
157
	protected NodeFigure createNodeFigure() {
158
		return new SelectableBorderedNodeFigure(createMainFigure());
159
	}
160
161
	@Override
162
	protected IFigure createNodeShape() {
163
		primaryShape = new ConstraintBlockPropertyCompositeFigure();
164
		return primaryShape;
165
	}
166
167
168
	@Override
169
	public NodeNamedElementFigure getPrimaryShape() {
170
		return (NodeNamedElementFigure)primaryShape;
171
	}
172
173
	@Override
174
	public EditPart getPrimaryChildEditPart() {
175
		return getChildBySemanticHint(UMLGraphicalTypes.LABEL_UML_PROPERTY_LABEL_ID);
176
	}
177
178
	@SuppressWarnings("rawtypes")
179
	@Override
180
	protected void refreshVisuals() {
181
		super.refreshVisuals();
182
		List children = getChildren();
183
		for (Object editPart : children) {
184
			if (editPart instanceof EditPart) {
185
				((EditPart) editPart).refresh();
186
			}
187
		}
188
	}
189
	
190
	/**
191
	 * <pre>
192
	 * 
193
	 * {@inheritDoc}
194
	 * </pre>
195
	 */
196
	@Override
197
	protected void handleNotificationEvent(Notification event) {
198
199
		// A visual refresh may also be needed when the following properties are changing : aggregation, type, or the related association.
200
		if(resolveSemanticElement() != null) {
201
			EObject element = resolveSemanticElement();
202
			
203
			if((element != null) && (element.equals(event.getNotifier())) && (element instanceof Property)) {
204
205
				if(UMLPackage.eINSTANCE.getProperty_Aggregation().equals(event.getFeature())) {
206
					refreshVisuals();
207
				}
208
209
				if(UMLPackage.eINSTANCE.getTypedElement_Type().equals(event.getFeature())) {
210
					refreshVisuals();
211
				}
212
213
				if(UMLPackage.eINSTANCE.getProperty_Association().equals(event.getFeature())) {
214
					refreshVisuals();
215
				}
216
			}
217
		}
218
		super.handleNotificationEvent(event);
219
		refresh();
220
	}
221
222
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/edit/policy/BlockPropertyStructureCompartmentSemanticEditPolicy.java (+6 lines)
Lines 23-28 Link Here
23
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.CompartmentSemanticEditPolicy;
23
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.CompartmentSemanticEditPolicy;
24
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
24
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
25
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateActorPartWithTypeConfigureCommandFactory;
25
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateActorPartWithTypeConfigureCommandFactory;
26
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateConstraintPropertyWithTypeConfigureCommandFactory;
26
import org.eclipse.papyrus.sysml.diagram.common.commands.CreatePartWithTypeConfigureCommandFactory;
27
import org.eclipse.papyrus.sysml.diagram.common.commands.CreatePartWithTypeConfigureCommandFactory;
27
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateReferenceWithTypeConfigureCommandFactory;
28
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateReferenceWithTypeConfigureCommandFactory;
28
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateValueWithTypeConfigureCommandFactory;
29
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateValueWithTypeConfigureCommandFactory;
Lines 72-77 Link Here
72
				if(UMLElementTypes.PROPERTY == req.getElementType()) {
73
				if(UMLElementTypes.PROPERTY == req.getElementType()) {
73
					req.setContainer(type);
74
					req.setContainer(type);
74
				}
75
				}
76
77
				if(SysMLElementTypes.CONSTRAINT_PROPERTY == req.getElementType()) {
78
					req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateConstraintPropertyWithTypeConfigureCommandFactory());
79
				}
80
75
				
81
				
76
			} else if ((UMLElementTypes.PROPERTY == req.getElementType()) || (Arrays.asList(req.getElementType().getAllSuperTypes()).contains(UMLElementTypes.PROPERTY))) { 
82
			} else if ((UMLElementTypes.PROPERTY == req.getElementType()) || (Arrays.asList(req.getElementType().getAllSuperTypes()).contains(UMLElementTypes.PROPERTY))) { 
77
				// Forbid Property::qualifier creation
83
				// Forbid Property::qualifier creation
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/edit/policy/PartCompartmentSemanticEditPolicy.java (+5 lines)
Lines 17-22 Link Here
17
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
17
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
18
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.CompartmentSemanticEditPolicy;
18
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.CompartmentSemanticEditPolicy;
19
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
19
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
20
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateConstraintPropertyWithTypeConfigureCommandFactory;
20
import org.eclipse.papyrus.sysml.diagram.common.commands.CreatePartWithTypeConfigureCommandFactory;
21
import org.eclipse.papyrus.sysml.diagram.common.commands.CreatePartWithTypeConfigureCommandFactory;
21
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
22
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
22
23
Lines 35-40 Link Here
35
			req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreatePartWithTypeConfigureCommandFactory());
36
			req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreatePartWithTypeConfigureCommandFactory());
36
		}
37
		}
37
38
39
		if(SysMLElementTypes.CONSTRAINT_PROPERTY == req.getElementType()) {
40
			req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateConstraintPropertyWithTypeConfigureCommandFactory());
41
		}
42
38
		return super.getCreateCommand(req);
43
		return super.getCreateCommand(req);
39
	}
44
	}
40
}
45
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/edit/policy/PropertyCompartmentSemanticEditPolicy.java (-1 / +5 lines)
Lines 18-23 Link Here
18
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.CompartmentSemanticEditPolicy;
18
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.CompartmentSemanticEditPolicy;
19
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
19
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
20
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateActorPartWithTypeConfigureCommandFactory;
20
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateActorPartWithTypeConfigureCommandFactory;
21
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateConstraintPropertyWithTypeConfigureCommandFactory;
21
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateFlowPortWithFlowSpecificationConfigureCommandFactory;
22
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateFlowPortWithFlowSpecificationConfigureCommandFactory;
22
import org.eclipse.papyrus.sysml.diagram.common.commands.CreatePartWithTypeConfigureCommandFactory;
23
import org.eclipse.papyrus.sysml.diagram.common.commands.CreatePartWithTypeConfigureCommandFactory;
23
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateReferenceWithTypeConfigureCommandFactory;
24
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateReferenceWithTypeConfigureCommandFactory;
Lines 50-56 Link Here
50
		if(SysMLElementTypes.FLOW_PORT_NA == req.getElementType()) {
51
		if(SysMLElementTypes.FLOW_PORT_NA == req.getElementType()) {
51
			req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateFlowPortWithFlowSpecificationConfigureCommandFactory());
52
			req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateFlowPortWithFlowSpecificationConfigureCommandFactory());
52
		}
53
		}
53
		
54
		if(SysMLElementTypes.CONSTRAINT_PROPERTY == req.getElementType()) {
55
			req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateConstraintPropertyWithTypeConfigureCommandFactory());
56
		}
57
54
		return super.getCreateCommand(req);
58
		return super.getCreateCommand(req);
55
	}
59
	}
56
}
60
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/edit/policy/StructureCompartmentSemanticEditPolicy.java (+5 lines)
Lines 18-23 Link Here
18
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.CompartmentSemanticEditPolicy;
18
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.CompartmentSemanticEditPolicy;
19
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
19
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
20
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateActorPartWithTypeConfigureCommandFactory;
20
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateActorPartWithTypeConfigureCommandFactory;
21
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateConstraintPropertyWithTypeConfigureCommandFactory;
21
import org.eclipse.papyrus.sysml.diagram.common.commands.CreatePartWithTypeConfigureCommandFactory;
22
import org.eclipse.papyrus.sysml.diagram.common.commands.CreatePartWithTypeConfigureCommandFactory;
22
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateReferenceWithTypeConfigureCommandFactory;
23
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateReferenceWithTypeConfigureCommandFactory;
23
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateValueWithTypeConfigureCommandFactory;
24
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateValueWithTypeConfigureCommandFactory;
Lines 50-55 Link Here
50
			req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateValueWithTypeConfigureCommandFactory());
51
			req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateValueWithTypeConfigureCommandFactory());
51
		}
52
		}
52
53
54
		if(SysMLElementTypes.CONSTRAINT_PROPERTY == req.getElementType()) {
55
			req.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateConstraintPropertyWithTypeConfigureCommandFactory());
56
		}
57
53
		return super.getCreateCommand(req);
58
		return super.getCreateCommand(req);
54
	}
59
	}
55
}
60
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/messages/Messages.java (+22 lines)
Lines 61-66 Link Here
61
61
62
	public static String CreateOrSelectBlockPropertyTypeDialog_SelectNewTypeContainerDialogMessage;
62
	public static String CreateOrSelectBlockPropertyTypeDialog_SelectNewTypeContainerDialogMessage;
63
63
64
	public static String CreateOrSelectConstraintPropertyTypeDialog_DialogTitle;
65
66
	public static String CreateOrSelectConstraintPropertyTypeDialog_SelectionSectionTitle;
67
68
	public static String CreateOrSelectConstraintPropertyTypeDialog_SelectionSectionRadioLabel;
69
70
	public static String CreateOrSelectConstraintPropertyTypeDialog_CreationSectionTitle;
71
72
	public static String CreateOrSelectConstraintPropertyTypeDialog_CreationSectionRadioLabel;
73
74
	public static String CreateOrSelectConstraintPropertyTypeDialog_NewTypeNameLabel;
75
76
	public static String CreateOrSelectConstraintPropertyTypeDialog_NewTypeContainerNameLabel;
77
78
	public static String CreateOrSelectConstraintPropertyTypeDialog_SelectTypeDialogTitle;
79
80
	public static String CreateOrSelectConstraintPropertyTypeDialog_SelectTypeDialogMessage;
81
82
	public static String CreateOrSelectConstraintPropertyTypeDialog_SelectNewTypeContainerDialogTitle;
83
84
	public static String CreateOrSelectConstraintPropertyTypeDialog_SelectNewTypeContainerDialogMessage;
85
64
	public static String CreateOrSelectActorPartTypeDialog_DialogTitle;
86
	public static String CreateOrSelectActorPartTypeDialog_DialogTitle;
65
87
66
	public static String CreateOrSelectActorPartTypeDialog_SelectionSectionTitle;
88
	public static String CreateOrSelectActorPartTypeDialog_SelectionSectionTitle;
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-sysml/org/eclipse/papyrus/sysml/diagram/common/messages/messages.properties (+16 lines)
Lines 29-34 Link Here
29
CreateOrSelectBlockPropertyTypeDialog_SelectNewTypeContainerDialogTitle=Type container selection
29
CreateOrSelectBlockPropertyTypeDialog_SelectNewTypeContainerDialogTitle=Type container selection
30
CreateOrSelectBlockPropertyTypeDialog_SelectNewTypeContainerDialogMessage=Select the container for the new Block
30
CreateOrSelectBlockPropertyTypeDialog_SelectNewTypeContainerDialogMessage=Select the container for the new Block
31
31
32
CreateOrSelectConstraintPropertyTypeDialog_DialogTitle=ConstraintProperty type initialization
33
CreateOrSelectConstraintPropertyTypeDialog_SelectionSectionTitle=Select an existing type (ConstraintBlock)
34
CreateOrSelectConstraintPropertyTypeDialog_SelectionSectionRadioLabel=ConstraintBlock (type) selection mode
35
36
CreateOrSelectConstraintPropertyTypeDialog_CreationSectionTitle=Create a new type (ConstraintBlock)
37
CreateOrSelectConstraintPropertyTypeDialog_CreationSectionRadioLabel=ConstraintBlock (type) creation mode
38
CreateOrSelectConstraintPropertyTypeDialog_NewTypeNameLabel=Select new ConstraintBlock name
39
CreateOrSelectConstraintPropertyTypeDialog_NewTypeContainerNameLabel=Select new ConstraintBlock container
40
41
CreateOrSelectConstraintPropertyTypeDialog_SelectTypeDialogTitle=Type selection
42
CreateOrSelectConstraintPropertyTypeDialog_SelectTypeDialogMessage=Select a ConstraintBlock to use as new element type
43
44
CreateOrSelectConstraintPropertyTypeDialog_SelectNewTypeContainerDialogTitle=Type container selection
45
CreateOrSelectConstraintPropertyTypeDialog_SelectNewTypeContainerDialogMessage=Select the container for the new ConstraintBlock
46
47
32
CreateOrSelectActorPartTypeDialog_DialogTitle=ActorPart type initialization
48
CreateOrSelectActorPartTypeDialog_DialogTitle=ActorPart type initialization
33
CreateOrSelectActorPartTypeDialog_SelectionSectionTitle=Select an existing type (Actor)
49
CreateOrSelectActorPartTypeDialog_SelectionSectionTitle=Select an existing type (Actor)
34
CreateOrSelectActorPartTypeDialog_SelectionSectionRadioLabel=Actor (type) selection mode
50
CreateOrSelectActorPartTypeDialog_SelectionSectionRadioLabel=Actor (type) selection mode
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/edit/part/ConstraintNodeLabelEditPart.java (+70 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.uml.diagram.common.edit.part;
15
16
import org.eclipse.draw2d.IFigure;
17
import org.eclipse.emf.common.notify.Notification;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
20
import org.eclipse.gmf.runtime.notation.View;
21
import org.eclipse.papyrus.uml.tools.utils.ValueSpecificationUtil;
22
import org.eclipse.uml2.uml.Constraint;
23
24
/**
25
 * Abstract non-diagram specific edit part for node label representing {@link Constraint}.
26
 * This class is adapted from edit parts generated by GMF Tooling.
27
 */
28
public class ConstraintNodeLabelEditPart extends AbstractElementNodeLabelEditPart {
29
30
	protected static final String LEFT_BRACE = "{";
31
	protected static final String RIGHT_BRACE = "}";
32
33
	public ConstraintNodeLabelEditPart(View view) {
34
		super(view);
35
	}
36
37
	/**
38
	 * {@inheritDoc}
39
	 */
40
	public String getLabelRole() {
41
		return "Label"; //$NON-NLS-1$
42
	}
43
44
	/**
45
	 * {@inheritDoc}
46
	 */
47
	public String getIconPathRole() {
48
		return ""; //$NON-NLS-1$
49
	}
50
	
51
	@Override
52
	protected void refreshVisuals() {
53
		super.refreshVisuals();
54
		IFigure figure = getFigure();
55
		if (figure instanceof WrappingLabel) {
56
			EObject resolveSemanticElement = resolveSemanticElement();
57
			if (resolveSemanticElement instanceof Constraint) {
58
				String specificationValue = ValueSpecificationUtil.getSpecificationValue(((Constraint) resolveSemanticElement).getSpecification());
59
				specificationValue = (specificationValue == null ? "" : specificationValue);
60
				((WrappingLabel) figure).setText(LEFT_BRACE + specificationValue + RIGHT_BRACE);
61
			}
62
		}
63
	}
64
	
65
	@Override
66
	protected void handleNotificationEvent(Notification event) {
67
		// do nothing else refresh
68
		refresh();
69
	}
70
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-gen/org/eclipse/papyrus/sysml/diagram/common/factory/ConstraintBlockPropertyCompositeClassifierViewFactory.java (+83 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.common.factory; 
2
3
import java.util.ArrayList;
4
import java.util.List;
5
6
import org.eclipse.core.runtime.IAdaptable;
7
import org.eclipse.emf.common.util.EList;
8
import org.eclipse.emf.ecore.EObject;
9
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
10
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.papyrus.gmf.diagram.common.factory.ShapeViewFactory;
13
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
14
import org.eclipse.papyrus.sysml.constraints.ConstraintBlock;
15
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
16
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
17
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
18
import org.eclipse.uml2.uml.Class;
19
import org.eclipse.uml2.uml.Constraint;
20
import org.eclipse.uml2.uml.Property;
21
import org.eclipse.uml2.uml.Type;
22
import org.eclipse.uml2.uml.util.UMLUtil;
23
24
public class ConstraintBlockPropertyCompositeClassifierViewFactory extends ShapeViewFactory {
25
26
	/**
27
	 * Creates ConstraintBlockPropertyComposite view and add Label and Compartment nodes
28
	 */
29
	@Override
30
	protected void decorateView(View containerView, View view, IAdaptable element, String semanticHint, int index, boolean persisted) {
31
32
		getViewService().createNode(element, view, UMLGraphicalTypes.LABEL_UML_PROPERTY_LABEL_ID, ViewUtil.APPEND, persisted, getPreferencesHint());
33
		getViewService().createNode(element, view, SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID, ViewUtil.APPEND, persisted, getPreferencesHint());	
34
		
35
		if (element != null) {
36
			 EObject newElement = EMFHelper.getEObject(element);
37
			 if (newElement instanceof Property && UMLUtil.getStereotypeApplication((Property)newElement, ConstraintProperty.class) != null) {
38
				Property constraintProperty = (Property) newElement;
39
				
40
				ViewService.createNode(view, getConstraint(constraintProperty), UMLGraphicalTypes.SHAPE_UML_CONSTRAINT_AS_LABEL_ID, getPreferencesHint());
41
42
				
43
				List<Property> constraintParameters = getConstraintParameters(constraintProperty);
44
				for (Property constraintParameter : constraintParameters) {
45
					ViewService.createNode(view, constraintParameter, UMLGraphicalTypes.SHAPE_UML_PROPERTY_AS_AFFIXED_ID, getPreferencesHint());
46
				}
47
			}
48
		}
49
		
50
		// this action needs to be done after the compartments creation
51
		super.decorateView(containerView, view, element, semanticHint, index, persisted);
52
	}
53
	
54
	private List<Property> getConstraintParameters(Property constraintProperty) {
55
		List<Property> constraintParameters = new ArrayList<Property>();
56
		Type type = constraintProperty.getType();
57
		if (type instanceof Class && UMLUtil.getStereotypeApplication(type, ConstraintBlock.class) != null) { // instanceof ensure type is not null
58
			Class constraintBlock = (Class)type;
59
			EList<Property> ownedAttributes = constraintBlock.getOwnedAttributes();
60
			for (Property property : ownedAttributes) {
61
				if (property.getAppliedStereotypes().isEmpty()) {
62
					constraintParameters.add(property);							
63
				}
64
			}
65
		}
66
		return constraintParameters;
67
	}
68
	
69
	private Constraint getConstraint(Property constraintProperty) {
70
		Type type = constraintProperty.getType();
71
		if (type instanceof Class && UMLUtil.getStereotypeApplication(type, ConstraintBlock.class) != null) { // instanceof ensure type is not null
72
			Class constraintBlock = (Class)type;
73
			EList<Constraint> ownedRules = constraintBlock.getOwnedRules();
74
			for (Constraint constraint : ownedRules) {
75
				return constraint;
76
			}
77
		}
78
		return null;
79
	}
80
81
	// Start of user code preferences	
82
	// End of user code
83
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-gen/org/eclipse/papyrus/sysml/diagram/common/figure/ConstraintBlockPropertyCompositeFigure.java (+49 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.common.figure; 
2
3
import org.eclipse.draw2d.PositionConstants;
4
import org.eclipse.draw2d.text.FlowPage;
5
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
6
import org.eclipse.papyrus.uml.diagram.common.figure.node.PapyrusRoundedNodeFigure;
7
8
public class ConstraintBlockPropertyCompositeFigure extends PapyrusRoundedNodeFigure {
9
10
	protected WrappingLabel constraintLabel;
11
12
	/** main flow page */
13
	protected FlowPage page;
14
15
	public ConstraintBlockPropertyCompositeFigure() {
16
		super();
17
		corner = 50;
18
		
19
		nameLabel = new WrappingLabel();
20
		nameLabel.setOpaque(false);
21
		nameLabel.setAlignment(PositionConstants.MIDDLE);
22
		add(nameLabel);
23
24
25
		constraintLabel = new WrappingLabel();
26
		constraintLabel.setAlignment(PositionConstants.RIGHT);
27
		add(constraintLabel);
28
	}
29
	
30
	/**
31
	 * 
32
	 * @see org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeNamedElementFigure#getNameLabel()
33
	 * 
34
	 * @return
35
	 */
36
	public WrappingLabel getNameLabel() {
37
		return nameLabel;
38
	}
39
	
40
	/**
41
	 * 
42
	 * @return the textflow of the constraint that contain the string of the
43
	 *         specification
44
	 */
45
	public WrappingLabel getConstraintLabel() {
46
		return constraintLabel;
47
	}
48
49
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-gen/org/eclipse/papyrus/sysml/diagram/common/figure/SysMLDiagramFrameFigure.java (+151 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2013 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
 *****************************************************************************/
11
package org.eclipse.papyrus.sysml.diagram.common.figure;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
16
import org.eclipse.draw2d.Graphics;
17
import org.eclipse.draw2d.IFigure;
18
import org.eclipse.draw2d.MarginBorder;
19
import org.eclipse.draw2d.OrderedLayout;
20
import org.eclipse.draw2d.RectangleFigure;
21
import org.eclipse.draw2d.ToolbarLayout;
22
import org.eclipse.draw2d.geometry.Dimension;
23
import org.eclipse.draw2d.geometry.Rectangle;
24
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
25
import org.eclipse.papyrus.uml.diagram.common.draw2d.InteractionFigure;
26
import org.eclipse.papyrus.uml.diagram.common.draw2d.LeftToolbarLayout;
27
import org.eclipse.papyrus.uml.diagram.common.figure.node.AutomaticCompartmentLayoutManager;
28
import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure;
29
30
public class SysMLDiagramFrameFigure extends NodeNamedElementFigure {
31
32
	private WrappingLabel frameLabel;
33
34
	private RectangleFigure frameLabelContainerFigure;
35
36
	private RectangleFigure structureCompartmentFigure;
37
38
39
	public SysMLDiagramFrameFigure() {
40
		super();
41
		createContents();
42
	}
43
44
	protected void createContents() {
45
		add(createInteractionFigureHeader());
46
		add(createStructureCompartmentFigures());
47
		setLayoutManager(new SysMLLayoutLayoutManager());
48
	}
49
50
	protected RectangleFigure createInteractionFigureHeader() {
51
		if (this.frameLabel == null) {
52
			this.frameLabel = new WrappingLabel() {
53
	
54
				@Override
55
				public Dimension getPreferredSize(final int wHint, final int hHint) {
56
					final Dimension preferredSize = super.getPreferredSize(wHint, hHint);
57
					if(preferredSize.width == 0) {
58
						return preferredSize;
59
					}
60
					return new Dimension(preferredSize.width + 2, preferredSize.height + 2);
61
				}
62
			};
63
		}
64
65
		final InteractionFigure interactionFigure = new InteractionFigure();
66
		interactionFigure.setBorder(new MarginBorder(3, 3, 3, 3));
67
		interactionFigure.setLayoutManager(new LeftToolbarLayout());
68
		interactionFigure.add(frameLabel);
69
		
70
		frameLabelContainerFigure = new RectangleFigure();
71
		frameLabelContainerFigure.setOutline(false);
72
		frameLabelContainerFigure.setFill(false);
73
		frameLabelContainerFigure.setLayoutManager(new ToolbarLayout(false));
74
		frameLabelContainerFigure.setLineStyle(Graphics.LINE_DASHDOTDOT);
75
		frameLabelContainerFigure.add(interactionFigure, OrderedLayout.ALIGN_CENTER);
76
		return frameLabelContainerFigure;
77
	}
78
79
	@Override
80
	public WrappingLabel getNameLabel() {
81
		if (frameLabel == null) {
82
			createInteractionFigureHeader();
83
		}
84
		return frameLabel;
85
	}
86
87
	public RectangleFigure getLabelContainer() {
88
		return frameLabelContainerFigure;
89
	}
90
91
	public IFigure getStructureCompartmentFigure() {
92
		if (structureCompartmentFigure == null) {
93
			createStructureCompartmentFigures();
94
		}
95
		return structureCompartmentFigure;
96
	}
97
	
98
	public IFigure createStructureCompartmentFigures() {
99
		structureCompartmentFigure = new RectangleFigure();
100
		structureCompartmentFigure.setFill(false);
101
		
102
		return structureCompartmentFigure;
103
	}
104
	
105
	/**
106
	 * this is the layout manager in charge to place element in the enumeration
107
	 * 
108
	 */
109
	private class SysMLLayoutLayoutManager extends AutomaticCompartmentLayoutManager {
110
111
		/**
112
		 * 
113
		 * {@inheritDoc}
114
		 */
115
		public void layout(final IFigure container) {
116
			List<IFigure> figuresToRemove = new ArrayList<IFigure>();
117
			for(int i = 0; i < container.getChildren().size(); i++) {
118
				IFigure currentCompartment = (IFigure)container.getChildren().get(i);
119
				// this is a visible compartment
120
				if(currentCompartment == structureCompartmentFigure) {
121
					Rectangle bound = new Rectangle(currentCompartment.getBounds());
122
					currentCompartment.invalidate();
123
					Dimension pref = currentCompartment.getPreferredSize();
124
					currentCompartment.invalidate();
125
					Dimension prefConstraint = currentCompartment.getPreferredSize(container.getBounds().width - 40, -1);
126
					if(pref.width < prefConstraint.width) {
127
						bound.setSize(pref);
128
					} else {
129
						bound.setSize(prefConstraint);
130
					}
131
					int offset = 24;
132
					bound.x = container.getBounds().x;
133
					bound.y = container.getBounds().y + offset;
134
					bound.width = container.getBounds().width;
135
					bound.height = container.getBounds().height - offset; 
136
					currentCompartment.setBounds(bound);
137
				} else if (currentCompartment == frameLabelContainerFigure) {
138
					Rectangle boundLabel = new Rectangle(frameLabelContainerFigure.getBounds());
139
					boundLabel.setSize(frameLabelContainerFigure.getPreferredSize());
140
					frameLabelContainerFigure.setBounds(boundLabel);
141
				} else {
142
					// remove other figure
143
					figuresToRemove.add(currentCompartment);
144
				}
145
			}
146
			for (IFigure iFigure : figuresToRemove) {
147
				container.getChildren().remove(iFigure);
148
			}
149
		}
150
	}
151
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-gen/org/eclipse/papyrus/sysml/diagram/common/utils/SysMLGraphicalTypes.java (+2 lines)
Lines 25-30 Link Here
25
25
26
	public static final String SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID = "shape_sysml_blockproperty_as_composite"; //$NON-NLS-1$
26
	public static final String SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID = "shape_sysml_blockproperty_as_composite"; //$NON-NLS-1$
27
27
28
	public static final String SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID = "shape_sysml_constraintblockproperty_as_composite"; //$NON-NLS-1$
29
28
	public static final String SHAPE_SYSML_DIMENSION_AS_CLASSIFIER_ID = "shape_sysml_dimension_as_classifier"; //$NON-NLS-1$
30
	public static final String SHAPE_SYSML_DIMENSION_AS_CLASSIFIER_ID = "shape_sysml_dimension_as_classifier"; //$NON-NLS-1$
29
31
30
	public static final String SHAPE_SYSML_CONSTRAINTBLOCK_AS_CLASSIFIER_ID = "shape_sysml_constraintblock_as_classifier"; //$NON-NLS-1$
32
	public static final String SHAPE_SYSML_CONSTRAINTBLOCK_AS_CLASSIFIER_ID = "shape_sysml_constraintblock_as_classifier"; //$NON-NLS-1$
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-gen/org/eclipse/papyrus/uml/diagram/common/edit/part/ConnectorEditPart.java (-27 / +13 lines)
Lines 17-24 Link Here
17
import org.eclipse.gef.EditPart;
17
import org.eclipse.gef.EditPart;
18
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
18
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
19
import org.eclipse.gmf.runtime.notation.View;
19
import org.eclipse.gmf.runtime.notation.View;
20
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultSemanticEditPolicy;
20
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy;
21
import org.eclipse.papyrus.sysml.blocks.BindingConnector;
22
import org.eclipse.papyrus.sysml.blocks.BlocksPackage;
21
import org.eclipse.papyrus.uml.diagram.common.figure.ConnectorEdgeFigure;
23
import org.eclipse.papyrus.uml.diagram.common.figure.ConnectorEdgeFigure;
24
import org.eclipse.papyrus.uml.tools.utils.UMLUtil;
25
import org.eclipse.uml2.uml.Connector;
26
import org.eclipse.uml2.uml.Element;
22
27
23
public class ConnectorEditPart extends AbstractElementLinkEditPart {
28
public class ConnectorEditPart extends AbstractElementLinkEditPart {
24
29
Lines 91-123 Link Here
91
		return (ConnectorEdgeFigure)getFigure();
96
		return (ConnectorEdgeFigure)getFigure();
92
	}
97
	}
93
98
94
	/**
95
	 * {@inheritDoc}
96
	 */
97
	@Override
99
	@Override
98
	protected void refreshLineType() {
100
	protected void refreshLineWidth() {
99
		// Start of user code custom line type
101
		if (org.eclipse.uml2.uml.util.UMLUtil.getStereotypeApplication((Element)resolveSemanticElement(), BindingConnector.class) != null) {
100
		super.refreshLineType();
102
			setLineWidth(2);
101
		// End of user code
103
		}
104
		else {
105
			setLineWidth(1);
106
		}
102
	}
107
	}
103
108
104
	/**
105
	 * {@inheritDoc}
106
	 */
107
	@Override
108
	protected void refreshArrowSource() {
109
		// Start of user code custom source decoration
110
		super.refreshArrowSource();
111
		// End of user code
112
	}
113
114
	/**
115
	 * {@inheritDoc}
116
	 */
117
	@Override
118
	protected void refreshArrowTarget() {
119
		// Start of user code custom target decoration
120
		super.refreshArrowTarget();
121
		// End of user code
122
	}
123
}
109
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-gen/org/eclipse/papyrus/uml/diagram/common/edit/part/ConstraintParameterAffixedNodeEditPart.java (+201 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.uml.diagram.common.edit.part;
15
16
import java.util.Collections;
17
import java.util.List;
18
19
import org.eclipse.draw2d.IFigure;
20
import org.eclipse.draw2d.LayoutListener;
21
import org.eclipse.emf.common.notify.Notification;
22
import org.eclipse.gef.EditPart;
23
import org.eclipse.gef.EditPolicy;
24
import org.eclipse.gef.GraphicalEditPart;
25
import org.eclipse.gef.Request;
26
import org.eclipse.gef.commands.Command;
27
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
28
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
29
import org.eclipse.gef.handles.MoveHandle;
30
import org.eclipse.gef.requests.CreateRequest;
31
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
32
import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
33
import org.eclipse.gmf.runtime.notation.NotationPackage;
34
import org.eclipse.gmf.runtime.notation.View;
35
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.ExternalLabelPrimaryDragRoleEditPolicy;
36
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
37
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeIconlDisplayEditPolicy;
38
import org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy;
39
import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideLabelEditPolicy;
40
import org.eclipse.papyrus.uml.diagram.common.figure.node.AffixedNamedElementFigure;
41
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusUMLElementFigure;
42
import org.eclipse.papyrus.uml.diagram.common.locator.ExternalLabelPositionLocator;
43
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
44
45
public class ConstraintParameterAffixedNodeEditPart extends AbstractElementBorderEditPart {
46
47
	private LayoutListener.Stub layoutInitializationListener;
48
49
	public ConstraintParameterAffixedNodeEditPart(View view) {
50
		super(view);
51
	}
52
53
54
	@Override
55
	protected EditPart createChild(Object model) {
56
		return super.createChild(model);
57
	}
58
59
60
	protected void createDefaultEditPolicies() {
61
		super.createDefaultEditPolicies();
62
		installEditPolicy(AppliedStereotypeLabelDisplayEditPolicy.STEREOTYPE_LABEL_POLICY, new AppliedStereotypeIconlDisplayEditPolicy() {
63
64
			/**
65
			 * <pre>
66
			 * {@inheritDoc}
67
			 * 
68
			 * This modifies the edit policy in order to call refreshVisuals() whenever the stereotype image to show is null.
69
			 * (required to show the Port default image correctly).
70
			 * </pre>
71
			 */
72
			@Override
73
			protected void refreshStereotypeDisplay() {
74
				if(getHost() instanceof IPapyrusEditPart) {
75
					IFigure figure = ((IPapyrusEditPart)getHost()).getPrimaryShape();
76
77
					if((figure instanceof IPapyrusUMLElementFigure) && (stereotypeIconToDisplay() != null)) {
78
						((IPapyrusUMLElementFigure)figure).setStereotypeDisplay(null, stereotypeIconToDisplay());
79
					} else {
80
						refreshVisuals();
81
					}
82
				}
83
			}
84
85
		});
86
87
		installEditPolicy(ShowHideLabelEditPolicy.SHOW_HIDE_LABEL_ROLE, new ShowHideLabelEditPolicy());
88
	}
89
90
	@Override
91
	protected LayoutEditPolicy createLayoutEditPolicy() {
92
		org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy lep = new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy() {
93
94
			protected EditPolicy createChildEditPolicy(EditPart child) {
95
				if(child instanceof IBorderItemEditPart) { // External labels
96
					return new ExternalLabelPrimaryDragRoleEditPolicy() {
97
98
						@SuppressWarnings("rawtypes")
99
						protected List createSelectionHandles() {
100
							MoveHandle mh = new MoveHandle((GraphicalEditPart)getHost());
101
							mh.setBorder(null);
102
							return Collections.singletonList(mh);
103
						}
104
					};
105
				}
106
107
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
108
				if(result == null) {
109
					result = new NonResizableEditPolicy();
110
				}
111
				return result;
112
			}
113
114
			protected Command getMoveChildrenCommand(Request request) {
115
				return null;
116
			}
117
118
			protected Command getCreateCommand(CreateRequest request) {
119
				return null;
120
			}
121
		};
122
		return lep;
123
	}
124
125
	@Override
126
	protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) {
127
		IBorderItemLocator locator = new ExternalLabelPositionLocator(getMainFigure());
128
		borderItemContainer.add(borderItemEditPart.getFigure(), locator);
129
		return;
130
	}
131
132
	@Override
133
	public EditPart getPrimaryChildEditPart() {
134
		return getChildBySemanticHint(UMLGraphicalTypes.AFFIXEDLABEL_UML_PORT_LABEL_ID);
135
	}
136
137
	/**
138
	 * <pre>
139
	 * Calls the figure refresh when a change event is detected on 
140
	 * UMLPackage.eINSTANCE.getProperty_Aggregation().
141
	 * 
142
	 * {@inheritDoc}
143
	 * </pre>
144
	 */
145
	@Override
146
	protected void handleNotificationEvent(Notification event) {
147
148
		// When the constraint parameter position changes, its position on parent side may change and requires a visual refresh.
149
		Object feature = event.getFeature();
150
		if(NotationPackage.eINSTANCE.getSize_Width().equals(feature) || NotationPackage.eINSTANCE.getSize_Height().equals(feature) || NotationPackage.eINSTANCE.getLocation_X().equals(feature) || NotationPackage.eINSTANCE.getLocation_Y().equals(feature)) {
151
			refreshVisuals();
152
		}
153
154
		super.handleNotificationEvent(event);
155
	}
156
157
	/**
158
	 * {@inheritDoc}
159
	 */
160
	@Override
161
	protected IFigure createNodeShape() {
162
		return primaryShape = new AffixedNamedElementFigure();
163
	}
164
165
	/**
166
	 * {@inheritDoc}
167
	 */
168
	@Override
169
	public AffixedNamedElementFigure getPrimaryShape() {
170
		return (AffixedNamedElementFigure)primaryShape;
171
	}
172
173
	/**
174
	 * <pre>
175
	 * A post layout listener is added during activate and remove the first time the layout occurs.
176
	 * This is required in order to be able to find the side of this border item on its parent when opening the model.
177
	 * Without this, the locator is unable to guess the parent side because the parent constraint is not set yet.
178
	 * 
179
	 * Once the initialization is done, the listener become useless and can be removed.
180
	 * 
181
	 * {@inheritDoc}
182
	 * </pre>
183
	 */
184
	@Override
185
	public void activate() {
186
187
		layoutInitializationListener = new LayoutListener.Stub() {
188
189
			@Override
190
			public void postLayout(IFigure container) {
191
				refreshVisuals();
192
				//getBorderedFigure().getBorderItemContainer().removeLayoutListener(layoutInitializationListener);
193
				layoutInitializationListener = null;
194
			}
195
		};
196
		getBorderedFigure().getBorderItemContainer().addLayoutListener(layoutInitializationListener);
197
198
		super.activate();
199
	}
200
201
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-gen/org/eclipse/papyrus/uml/diagram/common/factory/ConstraintPropertyAffixedNodeViewFactory.java (+19 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.uml.diagram.common.factory;
15
16
17
18
public class ConstraintPropertyAffixedNodeViewFactory extends PortAffixedNodeViewFactory {
19
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-gen/org/eclipse/papyrus/uml/diagram/common/utils/UMLGraphicalTypes.java (+2 lines)
Lines 33-38 Link Here
33
33
34
	public static final String SHAPE_UML_PORT_AS_AFFIXED_ID = "shape_uml_port_as_affixed"; //$NON-NLS-1$
34
	public static final String SHAPE_UML_PORT_AS_AFFIXED_ID = "shape_uml_port_as_affixed"; //$NON-NLS-1$
35
35
36
	public static final String SHAPE_UML_PROPERTY_AS_AFFIXED_ID = "shape_uml_property_as_affixed"; //$NON-NLS-1$
37
36
	/** Custom label nodes */
38
	/** Custom label nodes */
37
	public static final String SHAPE_UML_CONSTRAINT_AS_LABEL_ID = "shape_uml_constraint_as_label"; //$NON-NLS-1$
39
	public static final String SHAPE_UML_CONSTRAINT_AS_LABEL_ID = "shape_uml_constraint_as_label"; //$NON-NLS-1$
38
40
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/.classpath (-2 / +2 lines)
Lines 1-8 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="src" path="custom-src"/>
5
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
3
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
6
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="src" path="src"/>
6
	<classpathentry kind="src" path="src-gen"/>
7
	<classpathentry kind="output" path="bin"/>
7
	<classpathentry kind="output" path="bin"/>
8
</classpath>
8
</classpath>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/.options (-7 lines)
Lines 1-7 Link Here
1
# Tracing options for the org.eclipse.papyrus.sysml.diagram.parametric plug-in
2
3
# Common issues
4
org.eclipse.papyrus.sysml.diagram.parametric/debug=false
5
6
# Visual IDs
7
org.eclipse.papyrus.sysml.diagram.parametric/debug/visualID=false
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/.settings/Parametric.gmfgen.prefs (-8 lines)
Lines 1-8 Link Here
1
#Fri Apr 22 15:21:30 CEST 2011
2
dynamic_figure_templates=platform\:/resource/org.eclipse.papyrus.def/dynamic-templates3.5/codegen
3
eclipse.preferences.version=1
4
generate_rcp=false
5
ignore_gmfgen_validation=true
6
ignore_mapmodel_validation=true
7
use_map_mode=true
8
use_runtime_figures=true
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/.settings/org.eclipse.jdt.core.prefs (-1 lines)
Lines 1-4 Link Here
1
#Tue Dec 01 16:58:52 CET 2009
2
eclipse.preferences.version=1
1
eclipse.preferences.version=1
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/.svnignore (-1 lines)
Line 1 Link Here
1
bin
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/META-INF/MANIFEST.MF (-69 / +51 lines)
Lines 1-69 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
Export-Package: org.eclipse.papyrus.sysml.diagram.parametric,
2
Require-Bundle: org.eclipse.ui,
3
 org.eclipse.papyrus.sysml.diagram.parametric.edit.commands,
3
 org.eclipse.core.runtime,
4
 org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers,
4
 org.eclipse.papyrus.sysml;bundle-version="0.10.1",
5
 org.eclipse.papyrus.sysml.diagram.parametric.edit.parts,
5
 org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="0.10.1",
6
 org.eclipse.papyrus.sysml.diagram.parametric.edit.policies,
6
 org.eclipse.emf.common.ui;bundle-version="2.5.0",
7
 org.eclipse.papyrus.sysml.diagram.parametric.navigator,
7
 org.eclipse.gmf.runtime.diagram.ui.resources.editor;bundle-version="1.2.0",
8
 org.eclipse.papyrus.sysml.diagram.parametric.parsers,
8
 org.eclipse.papyrus.uml.diagram.composite;bundle-version="0.10.1",
9
 org.eclipse.papyrus.sysml.diagram.parametric.part,
9
 org.eclipse.gmf.runtime.diagram.ui.providers;bundle-version="1.3.0",
10
 org.eclipse.papyrus.sysml.diagram.parametric.preferences,
10
 org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="0.10.1",
11
 org.eclipse.papyrus.sysml.diagram.parametric.providers,
11
 org.eclipse.core.expressions,
12
 org.eclipse.papyrus.sysml.diagram.parametric.sheet
12
 org.eclipse.papyrus.sysml.service.types;bundle-version="0.10.1",
13
Bundle-ActivationPolicy: lazy
13
 org.eclipse.papyrus.uml.service.types;bundle-version="0.10.1",
14
Bundle-ClassPath: .
14
 org.eclipse.papyrus.infra.widgets;bundle-version="0.10.1",
15
Bundle-Name: %pluginName
15
 org.eclipse.gmf.runtime.diagram.core;bundle-version="1.4.1",
16
Bundle-Localization: plugin
16
 org.eclipse.gmf.runtime.diagram.ui;bundle-version="1.5.0",
17
Bundle-RequiredExecutionEnvironment: J2SE-1.5
17
 org.eclipse.papyrus.uml.tools;bundle-version="0.10.1",
18
Require-Bundle: org.eclipse.ui,
18
 org.eclipse.papyrus.infra.core.log;bundle-version="0.10.1",
19
 org.eclipse.core.runtime,
19
 org.eclipse.papyrus.infra.core;bundle-version="0.10.1",
20
 org.eclipse.core.resources,
20
 org.eclipse.papyrus.infra.core.sasheditor;bundle-version="0.10.1",
21
 org.eclipse.core.expressions,
21
 org.eclipse.papyrus.infra.services.edit;bundle-version="0.10.1",
22
 org.eclipse.jface,
22
 org.eclipse.papyrus.infra.gmfdiag.navigation;bundle-version="0.10.1",
23
 org.eclipse.ui.ide,
23
 org.eclipse.ui.ide;bundle-version="3.8.0",
24
 org.eclipse.ui.views,
24
 org.eclipse.papyrus.uml.tools.utils;bundle-version="0.10.1",
25
 org.eclipse.ui.navigator,
25
 org.eclipse.papyrus.infra.emf;bundle-version="0.10.1",
26
 org.eclipse.ui.navigator.resources,
26
 org.eclipse.uml2.uml;bundle-version="4.0.0",
27
 org.eclipse.emf.ecore,
27
 org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.2.0",
28
 org.eclipse.emf.ecore.xmi,
28
 org.eclipse.papyrus.infra.gmfdiag.commands;bundle-version="0.10.1",
29
 org.eclipse.emf.edit.ui,
29
 org.eclipse.papyrus.infra.services.labelprovider;bundle-version="0.10.1",
30
 org.eclipse.gmf.runtime.emf.core,
30
 org.eclipse.gmf.tooling.runtime;bundle-version="3.1.0",
31
 org.eclipse.gmf.runtime.emf.commands.core,
31
 org.eclipse.papyrus.sysml.diagram.internalblock;bundle-version="0.10.1",
32
 org.eclipse.gmf.runtime.emf.ui.properties,
32
 org.eclipse.papyrus.uml.diagram.common;bundle-version="0.10.1",
33
 org.eclipse.gmf.runtime.diagram.ui,
33
 org.eclipse.papyrus.sysml.diagram.common;bundle-version="0.10.1"
34
 org.eclipse.gmf.runtime.diagram.ui.properties,
34
Bundle-ManifestVersion: 2
35
 org.eclipse.gmf.runtime.diagram.ui.providers,
35
Bundle-ActivationPolicy: lazy
36
 org.eclipse.gmf.runtime.diagram.ui.providers.ide,
36
Bundle-Name: %pluginName
37
 org.eclipse.gmf.runtime.diagram.ui.render,
37
Bundle-Localization: plugin
38
 org.eclipse.gmf.runtime.diagram.ui.resources.editor,
38
Bundle-SymbolicName: org.eclipse.papyrus.sysml.diagram.parametric;singleton:=true
39
 org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide,
39
Bundle-Version: 0.10.1.qualifier
40
 org.eclipse.draw2d;visibility:=reexport,
40
Bundle-Vendor: %providerName
41
 org.eclipse.papyrus.sysml;bundle-version="0.10.1";visibility:=reexport,
41
Bundle-Activator: org.eclipse.papyrus.sysml.diagram.parametric.Activator
42
 org.eclipse.papyrus.sysml.edit;bundle-version="0.10.1";visibility:=reexport,
42
Bundle-RequiredExecutionEnvironment: J2SE-1.5
43
 org.eclipse.emf.ecore;visibility:=reexport,
43
Export-Package: org.eclipse.papyrus.sysml.diagram.parametric,
44
 org.eclipse.emf.ecore.edit;visibility:=reexport,
44
 org.eclipse.papyrus.sysml.diagram.parametric.edit.part,
45
 org.eclipse.uml2.uml;visibility:=reexport,
45
 org.eclipse.papyrus.sysml.diagram.parametric.edit.policy,
46
 org.eclipse.uml2.uml.edit;visibility:=reexport,
46
 org.eclipse.papyrus.sysml.diagram.parametric.factory,
47
 org.eclipse.papyrus.resource;bundle-version="0.10.1";visibility:=reexport,
47
 org.eclipse.papyrus.sysml.diagram.parametric.figures,
48
 org.eclipse.papyrus.resource.edit;bundle-version="0.10.1";visibility:=reexport,
48
 org.eclipse.papyrus.sysml.diagram.parametric.part,
49
 org.eclipse.gef,
49
 org.eclipse.papyrus.sysml.diagram.parametric.preferences,
50
 org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="0.10.1",
50
 org.eclipse.papyrus.sysml.diagram.parametric.provider,
51
 org.eclipse.papyrus.extensionpoints.editors;bundle-version="0.10.1",
51
 org.eclipse.papyrus.sysml.diagram.parametric.utils
52
 org.eclipse.papyrus.uml.diagram.common;bundle-version="0.10.1",
53
 org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="0.10.1",
54
 org.eclipse.papyrus.uml.standard;bundle-version="0.10.1";visibility:=reexport,
55
 org.eclipse.papyrus.uml.standard.edit;bundle-version="0.10.1";visibility:=reexport,
56
 org.eclipse.gmf.runtime.draw2d.ui;visibility:=reexport,
57
 org.eclipse.papyrus.parsers;bundle-version="0.10.1",
58
 org.eclipse.ocl.ecore;visibility:=reexport,
59
 org.eclipse.emf.validation;visibility:=reexport,
60
 org.eclipse.papyrus.infra.emf.appearance;bundle-version="0.10.1"
61
Bundle-Vendor: %providerName
62
Eclipse-LazyStart: true
63
Bundle-Version: 0.10.1.qualifier
64
Bundle-ManifestVersion: 2
65
Bundle-Activator: org.eclipse.papyrus.sysml.diagram.parametric.part.Sy
66
 smlDiagramEditorPlugin
67
Bundle-SymbolicName: org.eclipse.papyrus.sysml.diagram.parametric;sing
68
 leton:=true
69
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/about.html (-28 / +28 lines)
Lines 1-28 Link Here
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
5
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
6
<title>About</title>
6
<title>About</title>
7
</head>
7
</head>
8
<body lang="EN-US">
8
<body lang="EN-US">
9
<h2>About This Content</h2>
9
<h2>About This Content</h2>
10
 
10
 
11
<p>December 15, 2009</p>	
11
<p>June 5, 2007</p>	
12
<h3>License</h3>
12
<h3>License</h3>
13
13
14
<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;).  Unless otherwise 
14
<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;).  Unless otherwise 
15
indicated below, the Content is provided to you under the terms and conditions of the
15
indicated below, the Content is provided to you under the terms and conditions of the
16
Eclipse Public License Version 1.0 (&quot;EPL&quot;).  A copy of the EPL is available 
16
Eclipse Public License Version 1.0 (&quot;EPL&quot;).  A copy of the EPL is available 
17
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
17
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
18
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
18
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
19
19
20
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is 
20
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is 
21
being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
21
being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
22
apply to your use of any object code in the Content.  Check the Redistributor's license that was 
22
apply to your use of any object code in the Content.  Check the Redistributor's license that was 
23
provided with the Content.  If no such license exists, contact the Redistributor.  Unless otherwise
23
provided with the Content.  If no such license exists, contact the Redistributor.  Unless otherwise
24
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
24
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
25
and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
25
and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
26
26
27
</body>
27
</body>
28
</html>
28
</html>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/build.properties (-12 / +4 lines)
Lines 1-15 Link Here
1
#
1
source.. = src/,\
2
#Mon Sep 12 09:30:14 CEST 2011
2
           src-gen/
3
output.. = bin/
3
bin.includes = META-INF/,\
4
bin.includes = META-INF/,\
4
               .,\
5
               .,\
5
               plugin.xml,\
6
               messages.properties,\
7
               icons/,\
8
               plugin.properties,\
6
               plugin.properties,\
9
               .options,\
7
               plugin.xml
10
               about.html
11
output..=bin/
12
jars.compile.order=.
13
src.includes = about.html
14
source..=src/,custom-src/
15
bin..=bin/
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/CreateParametricDiagramCommand.java (-136 lines)
Lines 1-136 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric;
15
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.emf.common.util.URI;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.resource.Resource;
20
import org.eclipse.emf.transaction.TransactionalEditingDomain;
21
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
22
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
23
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
24
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
25
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
26
import org.eclipse.gmf.runtime.notation.Diagram;
27
import org.eclipse.gmf.runtime.notation.Node;
28
import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
29
import org.eclipse.papyrus.infra.gmfdiag.common.AbstractPapyrusGmfCreateDiagramCommandHandler;
30
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
32
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
33
import org.eclipse.papyrus.sysml.util.SysmlResource;
34
import org.eclipse.papyrus.uml.tools.utils.PackageUtil;
35
import org.eclipse.uml2.uml.Class;
36
import org.eclipse.uml2.uml.Element;
37
import org.eclipse.uml2.uml.Model;
38
import org.eclipse.uml2.uml.Profile;
39
40
public class CreateParametricDiagramCommand extends AbstractPapyrusGmfCreateDiagramCommandHandler {
41
42
	/** the Block containing the diagram */
43
	private Class selectedElement = null;
44
45
	@Override
46
	protected String getDiagramNotationID() {
47
		return ParametricEditPart.MODEL_ID;
48
	}
49
50
	@Override
51
	protected PreferencesHint getPreferenceHint() {
52
		return SysmlDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
53
	}
54
55
	@Override
56
	protected String getDefaultDiagramName() {
57
		return "ParametricDiagram";
58
	}
59
60
	//	@Override
61
	//	protected EObject createRootElement() {
62
	//		return UMLFactory.eINSTANCE.createModel();
63
	//	}
64
	//
65
	//	@Override
66
	//	protected void initializeModel(EObject owner) {
67
	//		EObject eObject = getSelectedElement();
68
	//		if(eObject == null) {
69
	//			eObject = owner;
70
	//		}
71
	//
72
	//		if(eObject instanceof Class) {
73
	//			this.selectedElement = (Class)eObject;
74
	//		}
75
	//	}
76
77
	@Override
78
	protected void initializeDiagram(EObject diagram) {
79
		if(diagram instanceof Diagram) {
80
			Diagram diag = (Diagram)diagram;
81
			// test if the selected class is a block
82
			if(selectedElement != null && selectedElement.getAppliedStereotype(SysmlResource.BLOCK_ID) != null) {
83
				// YT : Not sure to understand why the selected element is tested to be a Block instead of Block || BlockConstraint
84
				diag.setElement(selectedElement);
85
				createParametricGraph(selectedElement, diag);
86
			}
87
		}
88
	}
89
90
	@Override
91
	protected Diagram createDiagram(Resource diagramResource, EObject owner, String name) {
92
		Diagram diagram = null;
93
94
		// FIXME : Dead code below, owner cannot be a Model due to ParametricDiagramCondition 
95
		// which restricts possible owner to Class only (Block or ConstraintBlock).
96
		if(owner instanceof Model) {
97
			Model model = (Model)owner;
98
99
			if((model.getAppliedProfile(SysmlResource.SYSML_ID, true) == null) || (model.getAppliedProfile(SysmlResource.BLOCKS_ID, true) == null)) {
100
				// Retrieve SysML profile and apply with sub-profiles
101
				Profile sysml = (Profile)PackageUtil.loadPackage(URI.createURI(SysmlResource.SYSML_PROFILE_URI), model.eResource().getResourceSet());
102
				PackageUtil.applyProfile(model, sysml, true);
103
			}
104
105
			Class ownedClass = model.createOwnedClass("Parametric", false);
106
			ownedClass.applyStereotype(ownedClass.getApplicableStereotype(SysmlResource.BLOCK_ID));
107
			diagram = super.createDiagram(diagramResource, ownedClass, name);
108
109
		} else if(owner instanceof Class) {
110
			diagram = super.createDiagram(diagramResource, owner, name);
111
		}
112
		return diagram;
113
	}
114
115
	/**
116
	 * Complete a Parametric diagram with required graphical elements.
117
	 * 
118
	 * @param element
119
	 *        the element to which the diagram is associated
120
	 * @param diagram
121
	 *        the diagram to complete
122
	 */
123
	private void createParametricGraph(Element element, Diagram diagram) {
124
		/*
125
		 * This method implementation allow you to create graphical nodes if required. You may
126
		 * delete it if not necessary.
127
		 */
128
		TransactionalEditingDomain editingdomain = EditorUtils.getTransactionalEditingDomain();
129
		IAdaptable elementAdapter = new EObjectAdapter(element);
130
		ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class, null, ViewUtil.APPEND, true, SysmlDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
131
132
		CreateCommand nodeCreationCommand = new CreateCommand(editingdomain, descriptor, diagram);
133
134
		editingdomain.getCommandStack().execute(new GMFtoEMFCommandWrapper(nodeCreationCommand));
135
	}
136
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/CreateParametricDiagramWithNavigationHandler.java (-25 lines)
Lines 1-25 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 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.sysml.diagram.parametric;
15
16
import org.eclipse.papyrus.infra.gmfdiag.navigation.CreateDiagramWithNavigationHandler;
17
18
19
public class CreateParametricDiagramWithNavigationHandler extends CreateDiagramWithNavigationHandler {
20
21
	public CreateParametricDiagramWithNavigationHandler() {
22
		super(new CreateParametricDiagramCommand(), new ParametricDiagramCondition());
23
	}
24
25
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/ParametricDiagramCondition.java (-40 lines)
Lines 1-40 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric;
15
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.papyrus.infra.core.extension.commands.PerspectiveContextDependence;
18
import org.eclipse.papyrus.sysml.util.SysmlResource;
19
import org.eclipse.uml2.uml.Class;
20
21
/**
22
 * ParametricDiagramCondition to set conditions for the diagram creation
23
 */
24
public class ParametricDiagramCondition extends PerspectiveContextDependence {
25
26
	/**
27
	 * {@inheritDoc}
28
	 */
29
	public boolean create(EObject selectedElement) {
30
		if(super.create(selectedElement)) {
31
			if(selectedElement instanceof org.eclipse.uml2.uml.Class) {
32
				Class clazz = (org.eclipse.uml2.uml.Class)selectedElement;
33
				if(clazz.getAppliedStereotype(SysmlResource.BLOCK_ID) != null || clazz.getAppliedStereotype(SysmlResource.CONSTRAINT_BLOCK_ID) != null) {
34
					return true;
35
				}
36
			}
37
		}
38
		return false;
39
	}
40
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/ParametricDiagramEditorFactory.java (-27 lines)
Lines 1-27 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric;
15
16
import org.eclipse.papyrus.infra.gmfdiag.common.GmfEditorFactory;
17
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
18
19
public class ParametricDiagramEditorFactory extends GmfEditorFactory {
20
21
	/**
22
	 * Instantiates a new use case diagram editor factory.
23
	 */
24
	public ParametricDiagramEditorFactory() {
25
		super(ParametricDiagramForMultiEditor.class, ParametricEditPart.MODEL_ID);
26
	}
27
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/ParametricDiagramForMultiEditor.java (-114 lines)
Lines 1-114 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.emf.common.ui.URIEditorInput;
18
import org.eclipse.emf.ecore.util.EcoreUtil;
19
import org.eclipse.gmf.runtime.notation.Diagram;
20
import org.eclipse.jface.dialogs.ErrorDialog;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.papyrus.infra.core.editor.BackboneException;
23
import org.eclipse.papyrus.infra.core.services.ServiceException;
24
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
25
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditor;
26
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Shell;
29
import org.eclipse.ui.IEditorInput;
30
import org.eclipse.ui.IEditorSite;
31
import org.eclipse.ui.PartInitException;
32
33
public class ParametricDiagramForMultiEditor extends SysmlDiagramEditor {
34
35
	/**
36
	 * The location of diagram icon in the plug-in
37
	 */
38
	private static final String DIAG_IMG_PATH = "icons/obj16/Diagram_Parametric.gif";
39
40
	/**
41
	 * The image descriptor of the diagram icon
42
	 */
43
	private static final ImageDescriptor DIAG_IMG_DESC = SysmlDiagramEditorPlugin.getBundledImageDescriptor(ParametricDiagramForMultiEditor.DIAG_IMG_PATH);
44
45
	/** The editor splitter. */
46
	private Composite splitter;
47
48
	/**
49
	 * Constructor for SashSystem v2. Context and required objects are retrieved
50
	 * from the ServiceRegistry.
51
	 * 
52
	 * @throws BackboneException
53
	 * @throws ServiceException
54
	 * 
55
	 */
56
	public ParametricDiagramForMultiEditor(ServicesRegistry servicesRegistry, Diagram diagram) throws ServiceException {
57
		super(servicesRegistry, diagram);
58
	}
59
60
	/**
61
	 * {@inheritDoc}
62
	 */
63
	@Override
64
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
65
		super.init(site, input);
66
		setPartName(getDiagram().getName());
67
		setTitleImage(DIAG_IMG_DESC.createImage());
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	@Override
74
	public void setInput(IEditorInput input) {
75
		try {
76
			// Provide an URI with fragment in order to reuse the same Resource
77
			// and set the diagram to the fragment.
78
			URIEditorInput uriInput = new URIEditorInput(EcoreUtil.getURI(getDiagram()));
79
			doSetInput(uriInput, true);
80
		} catch (CoreException x) {
81
			String title = "Problem opening";
82
			String msg = "Cannot open input element:";
83
			Shell shell = getSite().getShell();
84
			ErrorDialog.openError(shell, title, msg, x.getStatus());
85
		}
86
	}
87
88
	/**
89
	 * {@inheritDoc}
90
	 */
91
	@Override
92
	protected void createGraphicalViewer(Composite parent) {
93
		splitter = parent;
94
		super.createGraphicalViewer(parent);
95
	}
96
97
	/**
98
	 * {@inheritDoc}
99
	 */
100
	@Override
101
	public void setFocus() {
102
		splitter.setFocus();
103
		super.setFocus();
104
	}
105
106
	/**
107
	 * {@inheritDoc}
108
	 */
109
	@Override
110
	public String getEditingDomainID() {
111
		return "org.eclipse.papyrus.sysml.diagram.parametric.EditingDomain";
112
	}
113
114
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/actions/RestoreRelatedLinksAction.java (-83 lines)
Lines 1-83 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Obeo.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Obeo - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.papyrus.sysml.diagram.parametric.actions;
12
13
import java.util.List;
14
15
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.gef.commands.CompoundCommand;
17
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
18
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
19
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramCommandStack;
20
import org.eclipse.gmf.runtime.notation.Diagram;
21
import org.eclipse.gmf.runtime.notation.View;
22
import org.eclipse.papyrus.sysml.diagram.parametric.command.RestoreRelatedLinksCommand;
23
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
24
import org.eclipse.papyrus.uml.diagram.common.actions.AbstractAction;
25
26
/**
27
 * Restore related links to selected element
28
 * 
29
 * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
30
 */
31
public class RestoreRelatedLinksAction extends AbstractAction {
32
33
	public static String ID = "papyrus.restoreRelatedLinksAction";
34
35
	public RestoreRelatedLinksAction() {
36
		setId(ID);
37
		setText("Restore Related Elements");
38
		setToolTipText("Restore Related Elements");
39
		// setImageDescriptor(Plugin.getBundledImageDescriptor("icons/*.gif"));
40
	}
41
42
	/**
43
	 * @return
44
	 */
45
	protected String getDiagramNotationID() {
46
		return ParametricEditPart.MODEL_ID;
47
	}
48
49
	/**
50
	 * @see org.eclipse.jface.action.Action#isEnabled()
51
	 */
52
	@Override
53
	public boolean isEnabled() {
54
		Diagram currentDiagram = getCurrentDiagram();
55
		if(currentDiagram != null) {
56
			return (!getSelection().isEmpty() && getDiagramNotationID().equals(currentDiagram.getType()));
57
		}
58
		return false;
59
	}
60
61
	/**
62
	 * @see org.eclipse.jface.action.Action#run()
63
	 */
64
	@Override
65
	public void run() {
66
		List<View> selection = getSelection();
67
68
		if(selection.isEmpty()) {
69
			return;
70
		}
71
72
		if(false == getHost() instanceof DiagramEditPart) {
73
			return;
74
		}
75
		DiagramEditPart diagramEditPart = (DiagramEditPart)getHost();
76
77
		final DiagramCommandStack commandStack = getHost().getDiagramEditDomain().getDiagramCommandStack();
78
		CompoundCommand cmd = new CompoundCommand("Restore Related Links");
79
		cmd.add(new ICommandProxy(new RestoreRelatedLinksCommand(diagramEditPart, selection)));
80
		commandStack.execute(cmd, new NullProgressMonitor());
81
	}
82
83
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/command/CreateConstraintPropertyCommand.java (-16 lines)
Lines 1-16 Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.command;
2
3
import java.util.List;
4
5
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateOrSelectElementCommand;
6
import org.eclipse.swt.widgets.Shell;
7
8
9
public class CreateConstraintPropertyCommand extends CreateOrSelectElementCommand {
10
11
	public CreateConstraintPropertyCommand(Shell parentShell, List content) {
12
		super(parentShell, content);
13
		// TODO Auto-generated constructor stub
14
	}
15
16
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/command/CreateParameterViewCommand.java (-123 lines)
Lines 1-123 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.command;
15
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.gef.EditPart;
18
import org.eclipse.gef.commands.Command;
19
import org.eclipse.gef.commands.CompoundCommand;
20
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
21
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
22
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
23
import org.eclipse.papyrus.sysml.diagram.parametric.edit.commands.Property2CreateCommand;
24
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
25
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
26
27
public class CreateParameterViewCommand extends Command {
28
29
	/** The compartment which graphically contains the Constraint to create */
30
	private ConstraintPropertyEditPart compartment = null;
31
32
	/** The command to create the Constraint element */
33
	private ICommandProxy elementCreationCommand = null;
34
35
	/** The command to create corresponding views (constraint view and link view) */
36
	private CompoundCommand viewsCreationCommand = null;
37
38
	/** The type of local condition to create */
39
	private IHintedType type;
40
41
	public CreateParameterViewCommand() {
42
		super();
43
	}
44
45
	public CreateParameterViewCommand(String label) {
46
		super(label);
47
	}
48
49
	/**
50
	 * Constructor a new action to create the local condition and corresponding views.
51
	 * 
52
	 * @param conditionType
53
	 *        the type of the local condition : precondition (Constraint_3011) or postcondition
54
	 *        (Constraint_3012)
55
	 * @param graphicalParent
56
	 *        the parent edit part which graphically contains the condition
57
	 * @param containerAction
58
	 *        the action which owns the local condition to create
59
	 * @param actionPart
60
	 *        the part of the action owning the condition
61
	 */
62
	public CreateParameterViewCommand(IHintedType conditionType, ConstraintPropertyEditPart graphicalParent, EObject containerAction, EditPart actionPart) {
63
		elementCreationCommand = getElementCreationCommand(containerAction, conditionType);
64
		compartment = graphicalParent;
65
		type = conditionType;
66
	}
67
68
	/**
69
	 * Get the Command to create the constraint element
70
	 * 
71
	 * @param containerAction
72
	 *        the action which owns the local condition to create
73
	 * @param conditionType
74
	 *        the type of the local condition : precondition (Constraint_3011) or postcondition
75
	 *        (Constraint_3012)
76
	 * @return the command to create model element or null
77
	 */
78
	private static ICommandProxy getElementCreationCommand(EObject containerAction, IHintedType conditionType) {
79
		CreateElementRequest createElementReq = new CreateElementRequest(containerAction, conditionType);
80
		if(SysmlElementTypes.Property_3002.equals(conditionType)) {
81
			Property2CreateCommand cmd = new Property2CreateCommand(createElementReq);
82
			return new ICommandProxy(cmd);
83
		} else {
84
			return null;
85
		}
86
	}
87
88
	@Override
89
	public boolean canExecute() {
90
		return elementCreationCommand != null && elementCreationCommand.canExecute();
91
	}
92
93
	/**
94
	 * Execute the command : create the model element, then the corresponding views
95
	 * 
96
	 * @see org.eclipse.gef.commands.Command#execute()
97
	 */
98
	@Override
99
	public void execute() {
100
		super.execute();
101
		//		Object property = null;
102
		//		if (elementCreationCommand != null) {
103
		//			 elementCreationCommand.execute();
104
		//			 property = elementCreationCommand.getICommand().getCommandResult().getReturnValue();
105
		//		}
106
	}
107
108
	/**
109
	 * Undo model and views creation
110
	 * 
111
	 * @see org.eclipse.gef.commands.Command#undo()
112
	 */
113
	@Override
114
	public void undo() {
115
		if(viewsCreationCommand != null) {
116
			viewsCreationCommand.undo();
117
		}
118
		if(elementCreationCommand != null) {
119
			elementCreationCommand.undo();
120
		}
121
	}
122
123
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/command/RestoreRelatedLinksCommand.java (-335 lines)
Lines 1-335 Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Obeo.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     Obeo - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.papyrus.sysml.diagram.parametric.command;
12
13
import java.util.Collection;
14
import java.util.HashMap;
15
import java.util.Iterator;
16
import java.util.LinkedList;
17
import java.util.List;
18
import java.util.Map;
19
20
import org.eclipse.core.commands.ExecutionException;
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.IProgressMonitor;
23
import org.eclipse.emf.common.util.EList;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.gef.EditPart;
26
import org.eclipse.gef.commands.Command;
27
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
28
import org.eclipse.gmf.runtime.diagram.core.commands.SetPropertyCommand;
29
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
30
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
31
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
32
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
33
import org.eclipse.gmf.runtime.diagram.ui.internal.properties.Properties;
34
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
35
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
36
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
37
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
38
import org.eclipse.gmf.runtime.notation.Diagram;
39
import org.eclipse.gmf.runtime.notation.Edge;
40
import org.eclipse.gmf.runtime.notation.View;
41
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
42
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramUpdater;
43
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlLinkDescriptor;
44
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
45
import org.eclipse.papyrus.uml.diagram.common.util.CommandUtil;
46
47
/**
48
 * Restore related links to selected element
49
 * 
50
 * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a>
51
 */
52
// Inspired from EcoreTools source code
53
public class RestoreRelatedLinksCommand extends AbstractTransactionalCommand {
54
55
	protected List<?> adapters;
56
57
	protected Diagram diagram;
58
59
	protected DiagramEditPart host;
60
61
	public RestoreRelatedLinksCommand(DiagramEditPart diagramEditPart, List<?> selection) {
62
		super(diagramEditPart.getEditingDomain(), "Restore related links", null);
63
		this.host = diagramEditPart;
64
		this.diagram = host.getDiagramView();
65
		this.adapters = selection;
66
	}
67
68
	private void cleanAdd(Collection<SysmlLinkDescriptor> result, View view, List<?> descriptors) {
69
		for(Object object : descriptors) {
70
			if(false == object instanceof SysmlLinkDescriptor) {
71
				continue;
72
			}
73
			SysmlLinkDescriptor descriptor = (SysmlLinkDescriptor)object;
74
			if(cleanContains(result, descriptor)) {
75
				continue;
76
			}
77
			// check owner
78
			if(!isOwner(view, descriptor)) {
79
				continue;
80
			}
81
			result.add(descriptor);
82
		}
83
	}
84
85
	/**
86
	 * Detect if similar descriptor already exist in given collection.
87
	 * 
88
	 * @param collection
89
	 *        the collection of unique ingoing and outgoing links descriptors
90
	 * @param sysmlLinkDescriptor
91
	 *        the descriptor to search
92
	 * @return true if already exist
93
	 */
94
	private boolean cleanContains(Collection<? extends SysmlLinkDescriptor> collection, SysmlLinkDescriptor sysmlLinkDescriptor) {
95
		for(Object object : collection) {
96
			if(object instanceof SysmlLinkDescriptor) {
97
				SysmlLinkDescriptor descriptor = (SysmlLinkDescriptor)object;
98
				if(descriptor.getModelElement() == sysmlLinkDescriptor.getModelElement() && descriptor.getSource() == sysmlLinkDescriptor.getSource() && descriptor.getDestination() == sysmlLinkDescriptor.getDestination() && descriptor.getVisualID() == sysmlLinkDescriptor.getVisualID()) {
99
					return true;
100
				}
101
			}
102
		}
103
104
		return false;
105
	}
106
107
	/**
108
	 * Collects all related links for view
109
	 * 
110
	 * @param view
111
	 * @param domain2NotationMap
112
	 * 
113
	 * @return linkdescriptors
114
	 */
115
	protected Collection<? extends SysmlLinkDescriptor> collectPartRelatedLinks(View view, Map<EObject, View> domain2NotationMap) {
116
		Collection<SysmlLinkDescriptor> result = new LinkedList<SysmlLinkDescriptor>();
117
		if(!domain2NotationMap.containsKey(view.getElement())) {
118
			// We must prevent duplicate descriptors
119
			List<?> outgoingDescriptors = SysmlDiagramUpdater.getOutgoingLinks(view);
120
			cleanAdd(result, view, outgoingDescriptors);
121
122
			List<?> incomingDescriptors = SysmlDiagramUpdater.getIncomingLinks(view);
123
			cleanAdd(result, view, incomingDescriptors);
124
		}
125
		if(!domain2NotationMap.containsKey(view.getElement()) || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
126
			domain2NotationMap.put(view.getElement(), view);
127
		}
128
		return result;
129
	}
130
131
	/**
132
	 * Create related links corresponding to linkDescriptions
133
	 * 
134
	 * @param linkDescriptors
135
	 * @param domain2NotationMap
136
	 */
137
	protected void createRelatedLinks(Collection<? extends SysmlLinkDescriptor> linkDescriptors, Map<EObject, View> domain2NotationMap) {
138
		// map diagram
139
		mapModel(diagram, domain2NotationMap);
140
141
		for(SysmlLinkDescriptor nextLinkDescriptor : linkDescriptors) {
142
			EditPart sourceEditPart = getEditPart(nextLinkDescriptor.getSource(), domain2NotationMap);
143
			EditPart targetEditPart = getEditPart(nextLinkDescriptor.getDestination(), domain2NotationMap);
144
145
			// If the parts are still null...
146
			if(sourceEditPart == null || targetEditPart == null) {
147
				continue;
148
			}
149
			CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(nextLinkDescriptor.getSemanticAdapter(), null, ViewUtil.APPEND, false, host.getDiagramPreferencesHint());
150
			CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
151
			ccr.setType(RequestConstants.REQ_CONNECTION_START);
152
			ccr.setSourceEditPart(sourceEditPart);
153
			sourceEditPart.getCommand(ccr);
154
			ccr.setTargetEditPart(targetEditPart);
155
			ccr.setType(RequestConstants.REQ_CONNECTION_END);
156
			Command cmd = targetEditPart.getCommand(ccr);
157
			if(cmd != null && cmd.canExecute()) {
158
				CommandUtil.executeCommand(cmd, host);
159
			}
160
		}
161
162
	}
163
164
	/**
165
	 * 
166
	 * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
167
	 *      org.eclipse.core.runtime.IAdaptable)
168
	 */
169
	@Override
170
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
171
		// To register all EditPart in the global visualIDRegistry
172
		host().refresh();
173
174
		for(Object object : adapters) {
175
			if(object instanceof IAdaptable) {
176
				IAdaptable ad = (IAdaptable)object;
177
				View view = (View)ad.getAdapter(View.class);
178
				if(view != null) {
179
					refreshRelatedLinks(view);
180
				}
181
			} else if(object instanceof View) {
182
				refreshRelatedLinks((View)object);
183
			}
184
185
		}
186
187
		return CommandResult.newOKCommandResult();
188
	}
189
190
	/**
191
	 * Retrieves editpart corresponding to domainModelElement
192
	 * 
193
	 * @param domainModelElement
194
	 * @param domain2NotationMap
195
	 */
196
	protected EditPart getEditPart(EObject domainModelElement, Map<? extends EObject, ? extends View> domain2NotationMap) {
197
		View view = domain2NotationMap.get(domainModelElement);
198
		if(view != null) {
199
			return (EditPart)host.getViewer().getEditPartRegistry().get(view);
200
		}
201
		return null;
202
	}
203
204
	/**
205
	 * Get linkdescriptors of the related links for graphicalEditPart
206
	 * 
207
	 * @param graphicalEditPart
208
	 * @param domain2NotationMap
209
	 * 
210
	 * @return linkDescritors
211
	 */
212
	protected Collection<? extends SysmlLinkDescriptor> getLinkDescriptorToProcess(View notationView, Map<EObject, View> domain2NotationMap) {
213
		// Collect all related link from semantic model
214
		Collection<? extends SysmlLinkDescriptor> linkDescriptors = collectPartRelatedLinks(notationView, domain2NotationMap);
215
216
		// Collect all related link from graphical model
217
		Collection<Edge> existingLinks = new LinkedList<Edge>();
218
		for(Object edge : notationView.getTargetEdges()) {
219
			if(edge instanceof Edge && false == existingLinks.contains(edge)) {
220
				existingLinks.add((Edge)edge);
221
			}
222
		}
223
		for(Object edge : notationView.getSourceEdges()) {
224
			if(edge instanceof Edge && false == existingLinks.contains(edge)) {
225
				existingLinks.add((Edge)edge);
226
			}
227
		}
228
229
		// Set all existing related link visible
230
		setViewVisible(existingLinks);
231
232
		// Remove already existing links
233
		for(Iterator<Edge> linksIterator = existingLinks.iterator(); linksIterator.hasNext();) {
234
			Edge nextDiagramLink = linksIterator.next();
235
			int diagramLinkVisualID = SysmlVisualIDRegistry.getVisualID(nextDiagramLink);
236
			if(diagramLinkVisualID == -1) {
237
				if(nextDiagramLink.getSource() != null && nextDiagramLink.getTarget() != null) {
238
					linksIterator.remove();
239
				}
240
				continue;
241
			}
242
			EObject diagramLinkObject = nextDiagramLink.getElement();
243
			EObject diagramLinkSrc = nextDiagramLink.getSource().getElement();
244
			EObject diagramLinkDst = nextDiagramLink.getTarget().getElement();
245
			for(Iterator<? extends SysmlLinkDescriptor> LinkDescriptorsIterator = linkDescriptors.iterator(); LinkDescriptorsIterator.hasNext();) {
246
				SysmlLinkDescriptor nextLinkDescriptor = LinkDescriptorsIterator.next();
247
				if(diagramLinkObject == nextLinkDescriptor.getModelElement() && diagramLinkSrc == nextLinkDescriptor.getSource() && diagramLinkDst == nextLinkDescriptor.getDestination() && diagramLinkVisualID == nextLinkDescriptor.getVisualID()) {
248
					linksIterator.remove();
249
					LinkDescriptorsIterator.remove();
250
				}
251
			}
252
		}
253
		return linkDescriptors;
254
	}
255
256
	/**
257
	 * @return <code>(IGraphicalEditPart)host()</code>.
258
	 */
259
	protected final IGraphicalEditPart host() {
260
		return host;
261
	}
262
263
	private boolean isOwner(View view, SysmlLinkDescriptor descriptor) {
264
		EObject source = descriptor.getSource();
265
		EObject dest = descriptor.getDestination();
266
		if(source != null && source.equals(view.getElement())) {
267
			return true;
268
		}
269
		if(dest != null && dest.equals(view.getElement())) {
270
			return true;
271
		}
272
		return false;
273
	}
274
275
	/**
276
	 * Maps view
277
	 * 
278
	 * @param view
279
	 * @param domain2NotationMap
280
	 */
281
	protected void mapModel(View view, Map<EObject, View> domain2NotationMap) {
282
		if(!ParametricEditPart.MODEL_ID.equals(SysmlVisualIDRegistry.getModelID(view))) {
283
			return;
284
		}
285
286
		// register the view if its type allows incoming or outgoing links
287
		if(!SysmlDiagramUpdater.getOutgoingLinks(view).isEmpty() || !SysmlDiagramUpdater.getIncomingLinks(view).isEmpty()) {
288
			if(!domain2NotationMap.containsKey(view.getElement()) || view.getEAnnotation("Shortcut") == null) {
289
				domain2NotationMap.put(view.getElement(), view);
290
			}
291
		}
292
293
		@SuppressWarnings("unchecked")
294
		EList<View> children = view.getChildren();
295
		for(View child : children) {
296
			mapModel(child, domain2NotationMap);
297
		}
298
		@SuppressWarnings("unchecked")
299
		EList<View> sourceEdges = view.getSourceEdges();
300
		for(View edge : sourceEdges) {
301
			mapModel(edge, domain2NotationMap);
302
		}
303
	}
304
305
	/**
306
	 * Refresh related links for graphicalEditPart
307
	 * 
308
	 * @param graphicalEditPart
309
	 */
310
	protected void refreshRelatedLinks(View notationView) {
311
		Map<EObject, View> domain2NotationMap = new HashMap<EObject, View>();
312
313
		// Create related links
314
		Collection<? extends SysmlLinkDescriptor> linkDescriptors = getLinkDescriptorToProcess(notationView, domain2NotationMap);
315
		createRelatedLinks(linkDescriptors, domain2NotationMap);
316
	}
317
318
	/**
319
	 * Set view visible
320
	 * 
321
	 * @param part
322
	 * @param views
323
	 */
324
	protected void setViewVisible(Collection<? extends View> views) {
325
		for(View view : views) {
326
			if(view.isVisible()) {
327
				continue;
328
			}
329
			SetPropertyCommand cmd = new SetPropertyCommand(host.getEditingDomain(), "Restore related linksCommand show view", new EObjectAdapter(view), Properties.ID_ISVISIBLE, Boolean.TRUE);
330
			if(cmd != null && cmd.canExecute()) {
331
				CommandUtil.executeCommand(new ICommandProxy(cmd), host);
332
			}
333
		}
334
	}
335
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/CreateParameterEditPolicy.java (-56 lines)
Lines 1-56 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import org.eclipse.gef.EditPart;
17
import org.eclipse.gef.Request;
18
import org.eclipse.gef.RequestConstants;
19
import org.eclipse.gef.commands.Command;
20
import org.eclipse.gef.commands.UnexecutableCommand;
21
import org.eclipse.gef.editpolicies.AbstractEditPolicy;
22
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateUnspecifiedTypeRequest;
23
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
24
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
25
26
/**
27
 * Custom CreateParameterEditPolicy.
28
 */
29
public class CreateParameterEditPolicy extends AbstractEditPolicy {
30
31
	public CreateParameterEditPolicy() {
32
		super();
33
	}
34
35
	@Override
36
	public Command getCommand(Request request) {
37
		if(RequestConstants.REQ_CREATE.equals(request.getType()) && request instanceof CreateUnspecifiedTypeRequest) {
38
			CreateUnspecifiedTypeRequest creationRequest = (CreateUnspecifiedTypeRequest)request;
39
			EditPart parentEditPart = getHost();
40
			if(parentEditPart instanceof ConstraintPropertyEditPart) {
41
				//ConstraintPropertyEditPart compartementPart = (ConstraintPropertyEditPart) parentEditPart;
42
				//EObject action = ViewUtil.resolveSemanticElement((View) getHost().getModel());
43
				for(Object obj : creationRequest.getElementTypes()) {
44
					if(SysmlElementTypes.Property_3002.equals(obj)) {
45
						// do nothing or display WarningAndLinkDialog
46
						return UnexecutableCommand.INSTANCE;
47
						//						return new CreateParameterViewCommand((IHintedType) SysmlElementTypes.Property_3002,
48
						//								compartementPart, action, getHost());
49
					}
50
				}
51
			}
52
		}
53
		return super.getCommand(request);
54
	}
55
56
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/CustomDiagramDragDropEditPolicy.java (-258 lines)
Lines 1-258 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import java.util.Collection;
17
import java.util.HashSet;
18
import java.util.List;
19
import java.util.Set;
20
21
import org.eclipse.emf.ecore.EClass;
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.gef.commands.Command;
24
import org.eclipse.gef.commands.UnexecutableCommand;
25
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
26
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
29
import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
30
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
31
import org.eclipse.gmf.runtime.notation.View;
32
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
33
import org.eclipse.papyrus.sysml.constraints.ConstraintsPackage;
34
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
35
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
36
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart;
37
import org.eclipse.papyrus.sysml.diagram.parametric.helper.ConnectorLinkMappingHelper;
38
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
39
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
40
import org.eclipse.papyrus.sysml.diagram.parametric.utils.PropertyLinkedToClassifier;
41
import org.eclipse.papyrus.uml.diagram.common.editpolicies.OldCommonDiagramDragDropEditPolicy;
42
import org.eclipse.uml2.uml.Classifier;
43
import org.eclipse.uml2.uml.ConnectableElement;
44
import org.eclipse.uml2.uml.ConnectorEnd;
45
import org.eclipse.uml2.uml.Element;
46
import org.eclipse.uml2.uml.Property;
47
48
/**
49
 * This class is used to execute the drag and drop from the outline. It can manage the drop of nodes
50
 * and binary links. To manage specific drop the method
51
 * CommonDiagramDragDropEditPolicy.getSpecificDropCommand has to be implemented
52
 */
53
public class CustomDiagramDragDropEditPolicy extends OldCommonDiagramDragDropEditPolicy {
54
55
	/** The container view where the drop is done */
56
	private View containerView;
57
58
	/**
59
	 * Instantiates a new custom diagram drag drop edit policy with the right link mapping helper.
60
	 */
61
	public CustomDiagramDragDropEditPolicy() {
62
		super(ConnectorLinkMappingHelper.getInstance());
63
	}
64
65
	/**
66
	 * {@inheritDoc}
67
	 */
68
	@Override
69
	protected Set<Integer> getDroppableElementVisualId() {
70
		Set<Integer> droppableElementsVisualId = new HashSet<Integer>();
71
		droppableElementsVisualId.add(ConnectorEditPart.VISUAL_ID);
72
		droppableElementsVisualId.add(ConstraintPropertyEditPart.VISUAL_ID);
73
		droppableElementsVisualId.add(PropertyEditPart.VISUAL_ID);
74
		return droppableElementsVisualId;
75
	}
76
77
	/**
78
	 * {@inheritDoc}
79
	 */
80
	@Override
81
	public IElementType getUMLElementType(int elementID) {
82
		return SysmlElementTypes.getElementType(elementID);
83
	}
84
85
	/**
86
	 * {@inheritDoc}
87
	 */
88
	@Override
89
	public int getNodeVisualID(View containerView, EObject domainElement) {
90
		this.containerView = containerView;
91
		if(domainElement instanceof Element) {
92
			EObject e = getApplication(domainElement);
93
			if(e != null) {
94
				if(e instanceof ConstraintProperty) {
95
					return ConstraintPropertyEditPart.VISUAL_ID;
96
				}
97
				// others cases for stereotyped elements
98
			}
99
		}
100
		return SysmlVisualIDRegistry.getNodeVisualID(containerView, domainElement);
101
	}
102
103
	/**
104
	 * {@inheritDoc}
105
	 */
106
	@Override
107
	public int getLinkWithClassVisualID(EObject domainElement) {
108
		return SysmlVisualIDRegistry.getLinkWithClassVisualID(domainElement);
109
	}
110
111
	/**
112
	 * {@inheritDoc}
113
	 */
114
	@Override
115
	protected Command getSpecificDropCommand(DropObjectsRequest dropRequest, Element semanticLink, int nodeVISUALID, int linkVISUALID) {
116
		if(nodeVISUALID != -1) {
117
			switch(nodeVISUALID) {
118
			case ConstraintPropertyEditPart.VISUAL_ID:
119
				return dropConstraintProperty(dropRequest, semanticLink, nodeVISUALID);
120
			case PropertyEditPart.VISUAL_ID:
121
				return dropProperty(dropRequest, semanticLink, nodeVISUALID);
122
			default:
123
				return super.getSpecificDropCommand(dropRequest, semanticLink, nodeVISUALID, linkVISUALID);
124
			}
125
		} else if(linkVISUALID != -1) {
126
			switch(linkVISUALID) {
127
			case ConnectorEditPart.VISUAL_ID:
128
				return dropConnector(dropRequest, semanticLink, linkVISUALID);
129
			default:
130
				return super.getSpecificDropCommand(dropRequest, semanticLink, nodeVISUALID, linkVISUALID);
131
			}
132
		} else {
133
			return UnexecutableCommand.INSTANCE;
134
		}
135
	}
136
137
	/**
138
	 * Specific drop action for connector.
139
	 * 
140
	 * @param dropRequest
141
	 *        the drop request
142
	 * @param semanticLink
143
	 *        the semantic link
144
	 * @param linkVISUALID
145
	 *        the link visual Sid
146
	 * 
147
	 * @return the command for connector
148
	 */
149
	protected Command dropConnector(DropObjectsRequest dropRequest, Element semanticLink, int linkVISUALID) {
150
		Collection<?> sources = ConnectorLinkMappingHelper.getInstance().getSource(semanticLink);
151
		Collection<?> targets = ConnectorLinkMappingHelper.getInstance().getTarget(semanticLink);
152
		if(sources.size() == 1 && targets.size() == 1) {
153
			ConnectorEnd sourceConnector = (ConnectorEnd)sources.toArray()[0];
154
			ConnectorEnd targetConnector = (ConnectorEnd)targets.toArray()[0];
155
			ConnectableElement source = sourceConnector.getRole();
156
			ConnectableElement target = targetConnector.getRole();
157
			return new ICommandProxy(dropBinaryLink(new CompositeCommand("drop Connector"), source, target, linkVISUALID, dropRequest.getLocation(), semanticLink));
158
		} else {
159
			return UnexecutableCommand.INSTANCE;
160
		}
161
	}
162
163
	/**
164
	 * Specific drop for constraint property.
165
	 * 
166
	 * @param dropRequest
167
	 *        the drop request
168
	 * @param semanticElement
169
	 *        the semantic link
170
	 * @param nodeVISUALID
171
	 *        the node visual id
172
	 * 
173
	 * @return the default drop node command for Constraint Property object
174
	 */
175
	private Command dropConstraintProperty(DropObjectsRequest dropRequest, Element semanticElement, int nodeVISUALID) {
176
		CompositeCommand cc = new CompositeCommand("Drop");
177
		EObject droppedObject = getApplication(semanticElement);
178
		if(droppedObject != null) {
179
			cc = getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), droppedObject);
180
			return new ICommandProxy(cc);
181
		}
182
		return UnexecutableCommand.INSTANCE;
183
	}
184
185
	/**
186
	 * Specific drop for property. Check if the property is linked to the classifier we want to
187
	 * drag&drop on
188
	 * 
189
	 * @param dropRequest
190
	 *        the drop request
191
	 * @param semanticElement
192
	 *        the semantic element
193
	 * @param nodeVISUALID
194
	 *        the node visual id
195
	 * 
196
	 * @return the command
197
	 */
198
	private Command dropProperty(DropObjectsRequest dropRequest, Element semanticElement, int nodeVISUALID) {
199
		EObject eObject = containerView.getElement();
200
		if(eObject instanceof Classifier) {
201
			PropertyLinkedToClassifier propertyLinkedToClassifier = new PropertyLinkedToClassifier((Classifier)eObject, (Property)semanticElement);
202
			if(propertyLinkedToClassifier.isLinkedToClassifier()) {
203
				CompositeCommand cc = new CompositeCommand("Drop");
204
				cc = getDefaultDropNodeCommand(nodeVISUALID, dropRequest.getLocation(), semanticElement);
205
				return new ICommandProxy(cc);
206
			}
207
		}
208
		return UnexecutableCommand.INSTANCE;
209
	}
210
211
	/**
212
	 * {@inheritDoc}
213
	 */
214
	@Override
215
	protected boolean isEditPartTypeSuitableForEClass(Class<? extends GraphicalEditPart> editPartClass, EClass eClass) {
216
		// avoid selecting a label instead of the activity node
217
		return !LabelEditPart.class.isAssignableFrom(editPartClass);
218
	}
219
220
	/**
221
	 * Gets stereotype application element for a specified domain element.
222
	 * 
223
	 * @param domainElement
224
	 *        the domain element
225
	 * 
226
	 * @return the stereotype application object
227
	 */
228
	private EObject getApplication(EObject domainElement) {
229
		if(getStereotypeAvailable(domainElement) != null && domainElement instanceof Element) {
230
			Element element = (Element)domainElement;
231
			List<EObject> applications = element.getStereotypeApplications();
232
			for(EObject eObject : applications) {
233
				if(getStereotypeAvailable(domainElement).equals(eObject.eClass())) {
234
					return eObject;
235
				}
236
			}
237
		}
238
		return null;
239
	}
240
241
	/**
242
	 * Gets the available stereotype EClass for a specified EObject
243
	 * 
244
	 * @param eObject
245
	 *        the e object
246
	 * 
247
	 * @return the stereotype available
248
	 */
249
	private EClass getStereotypeAvailable(EObject eObject) {
250
		if(eObject instanceof Property) {
251
			return ConstraintsPackage.Literals.CONSTRAINT_PROPERTY;
252
		}
253
		return null;
254
	}
255
256
257
258
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/NoDeleteFromDiagramEditPolicy.java (-52 lines)
Lines 1-52 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
 *   Atos Origin - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import org.eclipse.gef.EditPolicy;
17
import org.eclipse.gef.Request;
18
import org.eclipse.gef.commands.Command;
19
import org.eclipse.gef.commands.UnexecutableCommand;
20
import org.eclipse.gef.editpolicies.AbstractEditPolicy;
21
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
22
23
/**
24
 * This edit policy disables the graphical deletion of a diagram element.
25
 */
26
public class NoDeleteFromDiagramEditPolicy extends AbstractEditPolicy {
27
28
	/**
29
	 * Returns true when the request is a graphical delete
30
	 * 
31
	 * @see org.eclipse.gef.EditPolicy#understandsRequest(Request)
32
	 */
33
	@Override
34
	public boolean understandsRequest(Request req) {
35
		return RequestConstants.REQ_DELETE.equals(req.getType());
36
	}
37
38
	/**
39
	 * Returns an unexecutable command for graphical delete.
40
	 * 
41
	 * @see org.eclipse.gef.EditPolicy#getCommand(Request)
42
	 */
43
	@Override
44
	public Command getCommand(Request request) {
45
		if(RequestConstants.REQ_DELETE.equals(request.getType())) {
46
			return UnexecutableCommand.INSTANCE;
47
		} else if(EditPolicy.DIRECT_EDIT_ROLE.equals(request.getType())) {
48
			return UnexecutableCommand.INSTANCE;
49
		}
50
		return super.getCommand(request);
51
	}
52
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/NoDeleteFromModelEditPolicy.java (-61 lines)
Lines 1-61 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
 *   Atos Origin - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import org.eclipse.gef.Request;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gef.commands.UnexecutableCommand;
19
import org.eclipse.gef.editpolicies.AbstractEditPolicy;
20
import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
21
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
22
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
23
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
24
25
/**
26
 * This edit policy disables the graphical deletion of a diagram element.
27
 */
28
public class NoDeleteFromModelEditPolicy extends AbstractEditPolicy {
29
30
	/**
31
	 * Returns true when the request is a graphical delete
32
	 * 
33
	 * @see org.eclipse.gef.EditPolicy#understandsRequest(Request)
34
	 */
35
	@Override
36
	public boolean understandsRequest(Request req) {
37
		if(RequestConstants.REQ_SEMANTIC_WRAPPER.equals(req.getType()) && req instanceof EditCommandRequestWrapper) {
38
			IEditCommandRequest wrappedRequest = ((EditCommandRequestWrapper)req).getEditCommandRequest();
39
			if(wrappedRequest instanceof DestroyElementRequest) {
40
				return true;
41
			}
42
		}
43
		return false;
44
	}
45
46
	/**
47
	 * Returns an unexecutable command for graphical delete.
48
	 * 
49
	 * @see org.eclipse.gef.EditPolicy#getCommand(Request)
50
	 */
51
	@Override
52
	public Command getCommand(Request request) {
53
		if(RequestConstants.REQ_SEMANTIC_WRAPPER.equals(request.getType()) && request instanceof EditCommandRequestWrapper) {
54
			IEditCommandRequest wrappedRequest = ((EditCommandRequestWrapper)request).getEditCommandRequest();
55
			if(wrappedRequest instanceof DestroyElementRequest) {
56
				return UnexecutableCommand.INSTANCE;
57
			}
58
		}
59
		return super.getCommand(request);
60
	}
61
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/figures/CenteredWrappedLabel.java (-34 lines)
Lines 1-34 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *   Atos Origin - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.figures;
15
16
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
17
18
/**
19
 * This class is a {@link WrappingLabel}, which default behavior is set differently :
20
 * 
21
 * The text is centered and automatically wraps on several lines.
22
 */
23
public class CenteredWrappedLabel extends WrappingLabel {
24
25
	/**
26
	 * Construct an empty wrapping label with customized alignment.
27
	 */
28
	public CenteredWrappedLabel() {
29
		super();
30
		setTextJustification(WrappingLabel.CENTER);
31
		setAlignment(WrappingLabel.CENTER);
32
		setTextWrap(true);
33
	}
34
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/helper/ConnectorLinkMappingHelper.java (-90 lines)
Lines 1-90 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.helper;
15
16
import java.util.Collection;
17
import java.util.Collections;
18
19
import org.eclipse.emf.common.util.EList;
20
import org.eclipse.papyrus.uml.diagram.common.helper.ILinkMappingHelper;
21
import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper;
22
import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper.CommonSourceUMLSwitch;
23
import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper.CommonTargetUMLSwitch;
24
import org.eclipse.uml2.uml.ConnectorEnd;
25
import org.eclipse.uml2.uml.Element;
26
27
/**
28
 * Specialization of the link mapping helper for the Connector
29
 * 
30
 * @author eperico
31
 */
32
public class ConnectorLinkMappingHelper implements ILinkMappingHelper {
33
34
	/**
35
	 * SingletonHolder is loaded at the first execution of getInstance() method
36
	 */
37
	private static class SingletonHolder {
38
39
		private final static ConnectorLinkMappingHelper instance = new ConnectorLinkMappingHelper();
40
	}
41
42
	/**
43
	 * Gets the single instance of ConnectorLinkMappingHelper.
44
	 * 
45
	 * @return single instance of ConnectorLinkMappingHelper
46
	 */
47
	public static ConnectorLinkMappingHelper getInstance() {
48
		return SingletonHolder.instance;
49
	}
50
51
	/**
52
	 * private constructor
53
	 */
54
	private ConnectorLinkMappingHelper() {
55
		// do nothing
56
	}
57
58
	/**
59
	 * {@inheritDoc}
60
	 */
61
	public Collection<?> getSource(Element link) {
62
		return LinkMappingHelper.getSource(link, new CommonSourceUMLSwitch() {
63
64
			public java.util.Collection<?> caseConnector(org.eclipse.uml2.uml.Connector object) {
65
				EList<ConnectorEnd> ends = object.getEnds();
66
				if(ends != null && !ends.isEmpty()) {
67
					return Collections.singleton(object.getEnds().get(0));
68
				}
69
				return Collections.emptyList();
70
			};
71
		});
72
	}
73
74
	/**
75
	 * {@inheritDoc}
76
	 */
77
	public Collection<?> getTarget(Element link) {
78
		return LinkMappingHelper.getTarget(link, new CommonTargetUMLSwitch() {
79
80
			public java.util.Collection<?> caseConnector(org.eclipse.uml2.uml.Connector object) {
81
				EList<ConnectorEnd> ends = object.getEnds();
82
				if(ends != null && !ends.isEmpty() && ends.size() > 0) {
83
					return Collections.singleton(object.getEnds().get(1));
84
				}
85
				return Collections.emptyList();
86
			};
87
		});
88
	}
89
90
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/helper/ModelValidationHelper.java (-150 lines)
Lines 1-150 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.helper;
15
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.emf.validation.EMFEventType;
18
import org.eclipse.emf.validation.IValidationContext;
19
import org.eclipse.papyrus.resource.Resource;
20
import org.eclipse.papyrus.resource.util.ResourceUtil;
21
import org.eclipse.papyrus.sysml.blocks.BlocksFactory;
22
import org.eclipse.papyrus.sysml.blocks.NestedConnectorEnd;
23
import org.eclipse.papyrus.sysml.diagram.parametric.utils.PropertyLinkedToClassifier;
24
import org.eclipse.uml2.uml.Classifier;
25
import org.eclipse.uml2.uml.ConnectableElement;
26
import org.eclipse.uml2.uml.Connector;
27
import org.eclipse.uml2.uml.ConnectorEnd;
28
import org.eclipse.uml2.uml.Element;
29
import org.eclipse.uml2.uml.Property;
30
import org.eclipse.uml2.uml.Stereotype;
31
import org.eclipse.uml2.uml.UMLPackage;
32
33
/**
34
 * The Class ModelValidationHelper
35
 */
36
public class ModelValidationHelper {
37
38
	private static final String NESTED_CONNECTOR_END_STEREOTYPE = "SysML::Blocks::NestedConnectorEnd";
39
40
	/**
41
	 * Validate connector end.
42
	 * 
43
	 * @param connector
44
	 * @param ctx
45
	 * @return the status
46
	 */
47
	public static IStatus validateConnector(Connector connector, IValidationContext ctx) {
48
		if((EMFEventType.ADD.equals(ctx.getEventType()) || EMFEventType.ADD_MANY.equals(ctx.getEventType())) && UMLPackage.eINSTANCE.getConnector_End().equals(ctx.getFeature())) {
49
			// do nothing
50
		}
51
		return ctx.createSuccessStatus();
52
	}
53
54
	/**
55
	 * Validate property.
56
	 * 
57
	 * @param property
58
	 * @param ctx
59
	 * @return the status
60
	 */
61
	public static IStatus validateProperty(Property property, IValidationContext ctx) {
62
		// TODO this validator will manage connectorEnd update when source/target property is moved into and IBD
63
		if((EMFEventType.MOVE.equals(ctx.getEventType())) || (EMFEventType.SET.equals(ctx.getEventType()))) {
64
			// only update if property is linked to connector end
65
			for(ConnectorEnd end : property.getEnds()) {
66
				if(end.getOwner() != null && end.getOwner() instanceof Connector) {
67
					Element owner = ((Connector)end.getOwner()).getOwner();
68
					if(owner instanceof Classifier) {
69
						PropertyLinkedToClassifier link = new PropertyLinkedToClassifier((Classifier)owner, property);
70
						if(link.isLinkedWithMultiLevelPath()) {
71
							createNestedConnectorEnd(end);
72
						} else {
73
							Stereotype appliedStereotype = end.getAppliedStereotype(NESTED_CONNECTOR_END_STEREOTYPE);
74
							if(appliedStereotype != null) {
75
								end.unapplyStereotype(appliedStereotype);
76
							}
77
						}
78
					}
79
				}
80
			}
81
		}
82
		return ctx.createSuccessStatus();
83
	}
84
85
	/**
86
	 * Validate connector end.
87
	 * 
88
	 * @param connectorEnd
89
	 * @param ctx
90
	 * @return the status
91
	 */
92
	public static IStatus validateConnectorEnd(ConnectorEnd connectorEnd, IValidationContext ctx) {
93
		if((EMFEventType.SET.equals(ctx.getEventType())) && UMLPackage.eINSTANCE.getConnectorEnd_Role().equals(ctx.getFeature())) {
94
			ConnectableElement connectableElement = connectorEnd.getRole();
95
			Element connector = connectorEnd.getOwner();
96
			if(connector != null && connector.getOwner() instanceof Classifier) {
97
				Classifier owner = (Classifier)connector.getOwner();
98
				PropertyLinkedToClassifier link = new PropertyLinkedToClassifier((Classifier)owner, (Property)connectableElement);
99
				if(link.isLinkedWithMultiLevelPath()) {
100
					// create a nested connector end
101
					NestedConnectorEnd end = createNestedConnectorEnd(connectorEnd);
102
					if(!link.getAvailableRoutes().isEmpty()) {
103
						end.getPropertyPath().addAll(link.getAvailableRoutes().get(0).getProperties());
104
					}
105
				} else {
106
					Stereotype appliedStereotype = connectorEnd.getAppliedStereotype(NESTED_CONNECTOR_END_STEREOTYPE);
107
					if(appliedStereotype != null) {
108
						connectorEnd.unapplyStereotype(appliedStereotype);
109
					}
110
				}
111
			}
112
		}
113
		return ctx.createSuccessStatus();
114
	}
115
116
	/**
117
	 * Validate nested connector end.
118
	 * 
119
	 * @param connectorEnd
120
	 * @param ctx
121
	 * @return the status
122
	 */
123
	public static IStatus validateNestedConnectorEnd(NestedConnectorEnd connectorEnd, IValidationContext ctx) {
124
		// TODO setBase_ConnectorEnd should be set to null when connector is deleted, fix problem
125
		// with delete from model command
126
		// there are dangling references after this command
127
		// if (EMFEventType.SET.equals(ctx.getEventType())) {
128
		// ResourceUtil.getResource(connectorEnd).getEobjects().remove(connectorEnd);
129
		// }
130
		return ctx.createSuccessStatus();
131
	}
132
133
	/**
134
	 * Creates the nested connector end for a connector end
135
	 * 
136
	 * @param connectorEnd
137
	 *        the connector end
138
	 * @return the nested connector end
139
	 */
140
	private static NestedConnectorEnd createNestedConnectorEnd(ConnectorEnd connectorEnd) {
141
		NestedConnectorEnd nested = BlocksFactory.eINSTANCE.createNestedConnectorEnd();
142
		Resource res = ResourceUtil.getResource(connectorEnd);
143
		if(res != null) {
144
			res.getEobjects().add(nested);
145
			nested.setBase_ConnectorEnd(connectorEnd);
146
		}
147
		return nested;
148
	}
149
150
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/helper/SelfCompartmentNotificationHelper.java (-223 lines)
Lines 1-223 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *   Atos Origin - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.helper;
15
16
import java.util.ArrayList;
17
import java.util.HashSet;
18
import java.util.Iterator;
19
import java.util.List;
20
import java.util.Set;
21
22
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.emf.common.notify.Notification;
24
import org.eclipse.emf.common.notify.Notifier;
25
import org.eclipse.emf.ecore.EObject;
26
import org.eclipse.emf.ecore.EStructuralFeature;
27
import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand;
28
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
29
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
30
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
31
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
32
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
33
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
34
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
35
import org.eclipse.gmf.runtime.notation.Edge;
36
import org.eclipse.gmf.runtime.notation.Node;
37
import org.eclipse.gmf.runtime.notation.View;
38
import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
39
import org.eclipse.papyrus.infra.core.utils.EditorUtils;
40
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
41
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
42
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
43
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
44
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
45
import org.eclipse.papyrus.uml.diagram.common.helper.NotificationHelper;
46
import org.eclipse.papyrus.uml.diagram.common.providers.UIAdapterImpl;
47
import org.eclipse.uml2.uml.Property;
48
import org.eclipse.uml2.uml.UMLPackage;
49
50
/**
51
 * SelfCompartmentNotificationHelper is a particular NotificationHelper which manages the editparts
52
 * drawn in a particular compartment for a particular feature. It automatically add or remove
53
 * appropriate parts when model is modified, so that all contained elements are represented once.
54
 */
55
public class SelfCompartmentNotificationHelper extends NotificationHelper {
56
57
	/** The UI adapter that listens model update */
58
	private UIAdapter adapter = new UIAdapter();
59
60
	/** The compartment part. */
61
	private final ConstraintPropertyEditPart compartmentPart;
62
63
	/** The child feature. */
64
	private final EStructuralFeature childFeature;
65
66
	/** The child type. */
67
	private final IHintedType childType;
68
69
	private static CompositeTransactionalCommand command;
70
71
	/**
72
	 * Instantiates a new self compartment notification helper.
73
	 * 
74
	 * @param compartmentPart
75
	 *        the compartment part
76
	 * @param childFeature
77
	 *        the child feature
78
	 * @param childType
79
	 *        the child type
80
	 */
81
	public SelfCompartmentNotificationHelper(final ConstraintPropertyEditPart compartmentPart, final EStructuralFeature childFeature, final IHintedType childType) {
82
		this.compartmentPart = compartmentPart;
83
		this.childFeature = childFeature;
84
		this.childType = childType;
85
		this.setModelListener(adapter);
86
	}
87
88
	/**
89
	 * private class UIAdapter.
90
	 */
91
	private class UIAdapter extends UIAdapterImpl {
92
93
		@Override
94
		protected void safeNotifyChanged(Notification msg) {
95
			if(UMLPackage.eINSTANCE.getTypedElement_Type().equals(msg.getFeature())) {
96
				// listen type once it's set
97
				listenObject((Notifier)msg.getNewValue());
98
				updatePropertiesParts(compartmentPart, childFeature, childType);
99
			} else if(UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute().equals(msg.getFeature())) {
100
				updatePropertiesParts(compartmentPart, childFeature, childType);
101
			}
102
		}
103
	}
104
105
	/**
106
	 * Update children edit parts so that each child is represented once
107
	 * 
108
	 * @param compartmentPart
109
	 *        the compartment part containing children
110
	 * @param childFeature
111
	 *        the feature containing children
112
	 * @param childType
113
	 *        the children's IHintedType represented as Node
114
	 */
115
	// TODO refactor this method
116
	public static void updatePropertiesParts(ConstraintPropertyEditPart compartmentPart, EStructuralFeature childFeature, IHintedType childType) {
117
		if(compartmentPart == null || childFeature == null || childType == null) {
118
			return;
119
		}
120
		command = new CompositeTransactionalCommand(EditorUtils.getTransactionalEditingDomain(), "update children");
121
		command.setTransactionNestingEnabled(false);
122
		if(compartmentPart.getModel() instanceof View) {
123
			View compartmentView = (View)compartmentPart.getModel();
124
			EObject containerObject = compartmentView.getElement();
125
			if(containerObject instanceof ConstraintProperty) {
126
				Property baseProperty = ((ConstraintProperty)containerObject).getBase_Property();
127
				if(baseProperty != null && baseProperty.getType() != null) {
128
					Object untypedOwnedObjects = baseProperty.getType().eGet(childFeature);
129
					if(untypedOwnedObjects instanceof List<?>) {
130
						List<?> ownedEObjectChildren = (List<?>)untypedOwnedObjects;
131
						Set<EObject> drawnEObjectChildren = new HashSet<EObject>(ownedEObjectChildren.size());
132
133
						// list children already drawn and remove old children
134
						for(Iterator<?> iterator = compartmentView.getPersistedChildren().iterator(); iterator.hasNext();) {
135
							EObject childView = (EObject)iterator.next();
136
							if(childView instanceof View && ((View)childView).getElement() != null) {
137
								EObject child = ((View)childView).getElement();
138
								switch(SysmlVisualIDRegistry.getVisualID((View)childView)) {
139
140
								case Property2EditPart.VISUAL_ID:
141
									// property already drawn
142
									if(ownedEObjectChildren.contains(child)) {
143
										drawnEObjectChildren.add(child);
144
									} else {
145
										// delete old connectors
146
										deleteConnectorsViews(command, (View)childView);
147
										// remove remaining property if any
148
										iterator.remove();
149
									}
150
									break;
151
152
								case ConstraintPropertyEditPart.VISUAL_ID:
153
									// property doesn't exist in the model, remove the view
154
									iterator.remove();
155
									break;
156
157
								default:
158
									break;
159
								}
160
							}
161
						}
162
						// draw remaining children
163
						List<Object> childrenToDraw = new ArrayList<Object>(ownedEObjectChildren);
164
						childrenToDraw.removeAll(drawnEObjectChildren);
165
						for(Object child : childrenToDraw) {
166
							if(child instanceof EObject) {
167
								IAdaptable adapter = new EObjectAdapter((EObject)child);
168
								ViewDescriptor descriptor = new ViewDescriptor(adapter, Node.class, childType.getSemanticHint(), ViewUtil.APPEND, true, compartmentPart.getDiagramPreferencesHint());
169
								CreateCommand nodeCreationCommand = new CreateCommand(compartmentPart.getEditingDomain(), descriptor, compartmentView);
170
								command.add(nodeCreationCommand);
171
							}
172
						}
173
					}
174
				} else {
175
					// constraint property type is set to null, remove old children
176
					for(Iterator<?> iterator = compartmentView.getPersistedChildren().iterator(); iterator.hasNext();) {
177
						EObject childView = (EObject)iterator.next();
178
						if((childView instanceof View) && SysmlVisualIDRegistry.getVisualID((View)childView) == Property2EditPart.VISUAL_ID) {
179
							// delete old connectors
180
							deleteConnectorsViews(command, (View)childView);
181
							// delete parameter view
182
							iterator.remove();
183
						}
184
					}
185
				}
186
				// execute transactional command
187
				execute();
188
			}
189
		}
190
	}
191
192
	/**
193
	 * Execute command.
194
	 */
195
	private static void execute() {
196
		if(!command.isEmpty()) {
197
			command.getEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(command));
198
		}
199
	}
200
201
	/**
202
	 * Delete source and target connectors of the deleted parameter view
203
	 * 
204
	 * @param cmd
205
	 *        the cmd
206
	 * @param propertyView
207
	 *        the property view
208
	 */
209
	private static void deleteConnectorsViews(ICompositeCommand cmd, View propertyView) {
210
		for(Iterator<?> it = propertyView.getTargetEdges().iterator(); it.hasNext();) {
211
			Edge incomingLink = (Edge)it.next();
212
			if(SysmlVisualIDRegistry.getVisualID(incomingLink) == ConnectorEditPart.VISUAL_ID) {
213
				cmd.add(new DeleteCommand(incomingLink));
214
			}
215
		}
216
		for(Iterator<?> it = propertyView.getSourceEdges().iterator(); it.hasNext();) {
217
			Edge outgoingLink = (Edge)it.next();
218
			if(SysmlVisualIDRegistry.getVisualID(outgoingLink) == ConnectorEditPart.VISUAL_ID) {
219
				cmd.add(new DeleteCommand(outgoingLink));
220
			}
221
		}
222
	}
223
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/locator/ParameterPositionLocator.java (-82 lines)
Lines 1-82 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.locator;
15
16
import org.eclipse.draw2d.IFigure;
17
import org.eclipse.draw2d.geometry.Dimension;
18
import org.eclipse.draw2d.geometry.Point;
19
import org.eclipse.draw2d.geometry.Rectangle;
20
import org.eclipse.papyrus.uml.diagram.common.locator.AdvancedBorderItemLocator;
21
22
/**
23
 * The Class ParameterPositionLocator that manages position of property on constraint property
24
 */
25
public class ParameterPositionLocator extends AdvancedBorderItemLocator {
26
27
	/** Constructor **/
28
	public ParameterPositionLocator(IFigure parentFigure) {
29
		super(parentFigure);
30
	}
31
32
	/** Constructor **/
33
	public ParameterPositionLocator(IFigure borderItem, IFigure parentFigure, Rectangle constraint) {
34
		super(borderItem, parentFigure, constraint);
35
	}
36
37
	/** Constructor **/
38
	public ParameterPositionLocator(IFigure parentFigure, int preferredSide) {
39
		super(parentFigure, preferredSide);
40
	}
41
42
	/**
43
	 * {@inheritDoc}
44
	 */
45
	@Override
46
	public Rectangle getValidLocation(Rectangle proposedLocation, IFigure borderItem) {
47
		Rectangle realLocation = new Rectangle(proposedLocation);
48
		realLocation.width = Math.max(realLocation.width, realLocation.height);
49
		realLocation.height = realLocation.width;
50
		int side = findClosestSideOfParent(proposedLocation, getParentBorder());
51
		Point newTopLeft = locateOnBorder(realLocation.getTopLeft(), side, 0, borderItem);
52
		realLocation.setLocation(newTopLeft);
53
		return realLocation;
54
	}
55
56
	/**
57
	 * Re-arrange the location of the border item.
58
	 * 
59
	 * @see org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator#relocate(org.eclipse.draw2d.IFigure)
60
	 * 
61
	 * @param borderItem
62
	 */
63
	@Override
64
	public void relocate(IFigure borderItem) {
65
		// reset bounds of borderItem
66
		Dimension size = getSize(borderItem);
67
		Rectangle rectSuggested = getConstraint().getCopy();
68
		if(rectSuggested.getTopLeft().x == 0 && rectSuggested.getTopLeft().y == 0) {
69
			rectSuggested.setLocation(getPreferredLocation(borderItem));
70
		} else {
71
			// recovered constraint must be translated with the parent location to be absolute
72
			rectSuggested.setLocation(rectSuggested.getLocation().translate(getParentBorder().getTopLeft()));
73
		}
74
		rectSuggested.setSize(size);
75
		Rectangle validLocation = getValidLocation(rectSuggested, borderItem);
76
		// the constraint is not reset, but the item bounds are
77
		borderItem.setBounds(validLocation);
78
		// ensure the side property is correctly set
79
		setCurrentSideOfParent(findClosestSideOfParent(borderItem.getBounds(), getParentBorder()));
80
	}
81
82
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/parsers/ConnectorLabelParser.java (-136 lines)
Lines 1-136 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.parsers;
15
16
import java.text.FieldPosition;
17
import java.util.ArrayList;
18
import java.util.List;
19
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.emf.common.notify.Notification;
22
import org.eclipse.emf.ecore.EAttribute;
23
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.EStructuralFeature;
25
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
26
import org.eclipse.uml2.uml.Connector;
27
import org.eclipse.uml2.uml.Element;
28
import org.eclipse.uml2.uml.UMLPackage;
29
30
/**
31
 * A specific parser for displaying a connector. This parser refreshes the text
32
 * displayed for the connector.
33
 */
34
public class ConnectorLabelParser extends MessageFormatParser implements ISemanticParser {
35
36
	/** The String format for displaying a parameter with its type */
37
	private static final String TYPED_PARAMETER_FORMAT = "%s: %s";
38
39
	/** The String format for displaying a parameter with no type */
40
	private static final String UNTYPED_PARAMETER_FORMAT = "%s";
41
42
	public ConnectorLabelParser(EAttribute[] features, EAttribute[] editableFeatures) {
43
		super(features, editableFeatures);
44
	}
45
46
	public ConnectorLabelParser(EAttribute[] features) {
47
		super(features);
48
	}
49
50
	public ConnectorLabelParser() {
51
		super(new EAttribute[]{ UMLPackage.eINSTANCE.getNamedElement_Name() });
52
	}
53
54
	protected EStructuralFeature getEStructuralFeature(Object notification) {
55
		EStructuralFeature featureImpl = null;
56
		if(notification instanceof Notification) {
57
			Object feature = ((Notification)notification).getFeature();
58
			if(feature instanceof EStructuralFeature) {
59
				featureImpl = (EStructuralFeature)feature;
60
			}
61
		}
62
		return featureImpl;
63
	}
64
65
	/**
66
	 * {@inheritDoc}
67
	 */
68
	public boolean isAffectingEvent(Object event, int flags) {
69
		EStructuralFeature feature = getEStructuralFeature(event);
70
		return isValidFeature(feature);
71
72
	}
73
74
	/**
75
	 * {@inheritDoc}
76
	 */
77
	public String getPrintString(IAdaptable element, int flags) {
78
		Object obj = element.getAdapter(EObject.class);
79
		Connector connector = (Connector)obj;
80
		String name = connector.getName();
81
		if(name == null) {
82
			name = " ";
83
		}
84
		if(connector.getType() != null) {
85
			String type = connector.getType().getName();
86
			if(type == null) {
87
				type = "";
88
			}
89
			return String.format(TYPED_PARAMETER_FORMAT, name, type);
90
		} else {
91
			return String.format(UNTYPED_PARAMETER_FORMAT, name);
92
		}
93
	}
94
95
	/**
96
	 * {@inheritDoc}
97
	 */
98
	public boolean areSemanticElementsAffected(EObject listener, Object notification) {
99
		EStructuralFeature feature = getEStructuralFeature(notification);
100
		return isValidFeature(feature);
101
	}
102
103
	/**
104
	 * {@inheritDoc}
105
	 */
106
	public List<?> getSemanticElementsBeingParsed(EObject element) {
107
		List<Element> semanticElementsBeingParsed = new ArrayList<Element>();
108
		Connector connector = (Connector)element;
109
		semanticElementsBeingParsed.add(connector);
110
		if(connector.getType() != null) {
111
			semanticElementsBeingParsed.add(connector.getType());
112
		}
113
		return semanticElementsBeingParsed;
114
	}
115
116
	/**
117
	 * Determines if the given feature has to be taken into account in this parser
118
	 * 
119
	 * @param feature
120
	 *        the feature to test
121
	 * @return true if is valid, false otherwise
122
	 */
123
	private boolean isValidFeature(EStructuralFeature feature) {
124
		return UMLPackage.eINSTANCE.getNamedElement_Name().equals(feature) || UMLPackage.eINSTANCE.getConnector_Type().equals(feature);
125
	}
126
127
	/**
128
	 * {@inheritDoc}
129
	 */
130
	@Override
131
	public String getEditString(IAdaptable adapter, int flags) {
132
		EObject element = (EObject)adapter.getAdapter(EObject.class);
133
		return getEditorProcessor().format(getEditableValues(element), new StringBuffer(), new FieldPosition(0)).toString();
134
	}
135
136
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/parsers/ConstraintLabelParser.java (-182 lines)
Lines 1-182 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.parsers;
15
16
import java.util.ArrayList;
17
import java.util.List;
18
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.emf.common.notify.Notification;
21
import org.eclipse.emf.ecore.EAttribute;
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.emf.ecore.EStructuralFeature;
24
import org.eclipse.emf.transaction.TransactionalEditingDomain;
25
import org.eclipse.emf.transaction.util.TransactionUtil;
26
import org.eclipse.gmf.runtime.common.core.command.ICommand;
27
import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
28
import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
29
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
30
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
31
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
32
import org.eclipse.papyrus.uml.diagram.common.commands.SetValueSpecificationValueCommand;
33
import org.eclipse.papyrus.uml.tools.utils.ValueSpecificationUtil;
34
import org.eclipse.uml2.uml.Element;
35
import org.eclipse.uml2.uml.Property;
36
import org.eclipse.uml2.uml.UMLPackage;
37
import org.eclipse.uml2.uml.ValueSpecification;
38
39
/**
40
 * The Class ConstraintLabelParser that manages constraint label of a constraintProperty
41
 */
42
public class ConstraintLabelParser extends MessageFormatParser implements ISemanticParser {
43
44
	/** The String format for displaying a ConstraintProperty with no type */
45
	private static final String CONSTRAINT_LABEL__FORMAT = "{%s}";
46
47
	public ConstraintLabelParser(EAttribute[] features, EAttribute[] editableFeatures) {
48
		super(features, editableFeatures);
49
	}
50
51
	public ConstraintLabelParser(EAttribute[] features) {
52
		super(features);
53
	}
54
55
	public ConstraintLabelParser() {
56
		super(new EAttribute[]{ UMLPackage.eINSTANCE.getNamedElement_Name() });
57
	}
58
59
	/**
60
	 * Gets the e structural feature.
61
	 * 
62
	 * @param notification
63
	 *        the notification
64
	 * @return the e structural feature
65
	 */
66
	protected EStructuralFeature getEStructuralFeature(Object notification) {
67
		EStructuralFeature featureImpl = null;
68
		if(notification instanceof Notification) {
69
			Object feature = ((Notification)notification).getFeature();
70
			if(feature instanceof EStructuralFeature) {
71
				featureImpl = (EStructuralFeature)feature;
72
			}
73
		}
74
		return featureImpl;
75
	}
76
77
	/**
78
	 * {@inheritDoc}
79
	 */
80
	public boolean isAffectingEvent(Object event, int flags) {
81
		EStructuralFeature feature = getEStructuralFeature(event);
82
		return isValidFeature(feature);
83
	}
84
85
	/**
86
	 * {@inheritDoc}
87
	 */
88
	public String getPrintString(IAdaptable element, int flags) {
89
		String result = "";
90
		Object obj = element.getAdapter(EObject.class);
91
		if(obj instanceof ConstraintProperty) {
92
			Property property = ((ConstraintProperty)obj).getBase_Property();
93
			if(property != null) {
94
				// manage constraint
95
				if(property.getDefaultValue() != null) {
96
					ValueSpecification valueSpecification = property.getDefaultValue();
97
					String specificationValue = ValueSpecificationUtil.getSpecificationValue(valueSpecification);
98
					if(specificationValue != null && specificationValue.length() > 0) {
99
						result = String.format(CONSTRAINT_LABEL__FORMAT, specificationValue);
100
					}
101
				}
102
			}
103
		}
104
		return result;
105
	}
106
107
	/**
108
	 * {@inheritDoc}
109
	 */
110
	public boolean areSemanticElementsAffected(EObject listener, Object notification) {
111
		EStructuralFeature feature = getEStructuralFeature(notification);
112
		return isValidFeature(feature);
113
	}
114
115
	/**
116
	 * {@inheritDoc}
117
	 */
118
	public List<?> getSemanticElementsBeingParsed(EObject element) {
119
		List<Element> semanticElementsBeingParsed = new ArrayList<Element>();
120
		if(element instanceof ConstraintProperty) {
121
			Property property = ((ConstraintProperty)element).getBase_Property();
122
			if(property != null) {
123
				semanticElementsBeingParsed.add(property);
124
				if(property.getDefaultValue() != null) {
125
					semanticElementsBeingParsed.add(property.getDefaultValue());
126
				}
127
			}
128
		}
129
		return semanticElementsBeingParsed;
130
	}
131
132
	/**
133
	 * Determines if the given feature has to be taken into account in this parser
134
	 * 
135
	 * @param feature
136
	 *        the feature to test
137
	 * @return true if is valid, false otherwise
138
	 */
139
	private boolean isValidFeature(EStructuralFeature feature) {
140
		return UMLPackage.eINSTANCE.getProperty_DefaultValue().equals(feature) || UMLPackage.eINSTANCE.getProperty_DefaultValue().equals(feature);
141
	}
142
143
	/**
144
	 * {@inheritDoc}
145
	 */
146
	@Override
147
	public String getEditString(IAdaptable adapter, int flags) {
148
		String result = "";
149
		EObject element = (EObject)adapter.getAdapter(EObject.class);
150
		if(element instanceof ConstraintProperty) {
151
			element = ((ConstraintProperty)element).getBase_Property();
152
			if(element instanceof Property) {
153
				ValueSpecification defaultValue = ((Property)element).getDefaultValue();
154
				result = ValueSpecificationUtil.getSpecificationValue(defaultValue);
155
			}
156
		}
157
		return result;
158
	}
159
160
	/**
161
	 * {@inheritDoc}
162
	 */
163
	@Override
164
	public ICommand getParseCommand(IAdaptable adapter, String newString, int flags) {
165
		Object obj = adapter.getAdapter(EObject.class);
166
		TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(obj);
167
168
		if(editingDomain != null && obj instanceof ConstraintProperty) {
169
			obj = ((ConstraintProperty)obj).getBase_Property();
170
			if(obj instanceof Property) {
171
				ValueSpecification valueSpec = ((Property)obj).getDefaultValue();
172
				if(valueSpec != null) {
173
					CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Set Values");
174
					command.compose(new CommandProxy(new SetValueSpecificationValueCommand(valueSpec, newString)));
175
					return command;
176
				}
177
			}
178
		}
179
		return UnexecutableCommand.INSTANCE;
180
	}
181
182
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/parsers/ConstraintPropertyLabelParser.java (-230 lines)
Lines 1-230 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.parsers;
15
16
import java.text.FieldPosition;
17
import java.util.ArrayList;
18
import java.util.List;
19
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.emf.common.notify.Notification;
22
import org.eclipse.emf.common.util.EList;
23
import org.eclipse.emf.ecore.EAttribute;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.emf.transaction.TransactionalEditingDomain;
27
import org.eclipse.emf.transaction.util.TransactionUtil;
28
import org.eclipse.gmf.runtime.common.core.command.ICommand;
29
import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
30
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
31
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
32
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
33
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
34
import org.eclipse.papyrus.uml.tools.utils.ValueSpecificationUtil;
35
import org.eclipse.uml2.uml.Element;
36
import org.eclipse.uml2.uml.InstanceValue;
37
import org.eclipse.uml2.uml.Property;
38
import org.eclipse.uml2.uml.UMLPackage;
39
import org.eclipse.uml2.uml.ValueSpecification;
40
41
/**
42
 * A specific parser for displaying a ConstraintProperty label. This parser refreshes the text
43
 * displayed for the ConstraintProperty.
44
 */
45
public class ConstraintPropertyLabelParser extends MessageFormatParser implements ISemanticParser {
46
47
	/** The String format for displaying a ConstraintProperty with no type */
48
	private static final String UNTYPED_PARAMETER_FORMAT = "%s";
49
50
	/** The String format for displaying a ConstraintProperty with its type */
51
	private static final String TYPED_PARAMETER_FORMAT = "%s: %s";
52
53
	/** The String format for displaying a ConstraintProperty with multiplicity */
54
	private static final String MULTIPLICITY_PARAMETER_FORMAT = "%s [%s..%s]";
55
56
	/** The String format for displaying a ConstraintProperty with default value */
57
	private static final String DEFAULT_VALUE_PARAMETER_FORMAT = "%s= %s";
58
59
	/** The String format for displaying a ConstraintProperty with attribute */
60
	private static final String MODIFIER_PARAMETER_FORMAT = "%s{%s}";
61
62
	public ConstraintPropertyLabelParser(EAttribute[] features, EAttribute[] editableFeatures) {
63
		super(features, editableFeatures);
64
	}
65
66
	public ConstraintPropertyLabelParser(EAttribute[] features) {
67
		super(features);
68
	}
69
70
	public ConstraintPropertyLabelParser() {
71
		super(new EAttribute[]{ UMLPackage.eINSTANCE.getNamedElement_Name() });
72
	}
73
74
	protected EStructuralFeature getEStructuralFeature(Object notification) {
75
		EStructuralFeature featureImpl = null;
76
		if(notification instanceof Notification) {
77
			Object feature = ((Notification)notification).getFeature();
78
			if(feature instanceof EStructuralFeature) {
79
				featureImpl = (EStructuralFeature)feature;
80
			}
81
		}
82
		return featureImpl;
83
	}
84
85
	/**
86
	 * {@inheritDoc}
87
	 */
88
	public boolean isAffectingEvent(Object event, int flags) {
89
		EStructuralFeature feature = getEStructuralFeature(event);
90
		return isValidFeature(feature);
91
	}
92
93
	/**
94
	 * {@inheritDoc}
95
	 */
96
	public String getPrintString(IAdaptable element, int flags) {
97
		String result = "";
98
		Object obj = element.getAdapter(EObject.class);
99
		Property property = null;
100
		if(obj instanceof ConstraintProperty) {
101
			property = ((ConstraintProperty)obj).getBase_Property();
102
		}
103
		if(property != null) {
104
			String name = property.isDerived() ? "/ " + property.getName() : property.getName();
105
			result = String.format(UNTYPED_PARAMETER_FORMAT, name);
106
			// manage type
107
			if(property.getType() != null) {
108
				String type = property.getType().getName();
109
				result = String.format(TYPED_PARAMETER_FORMAT, name, type);
110
			}
111
			// manage multiplicity
112
			if(property.getLower() != 1 || property.getUpper() != 1) {
113
				result = String.format(MULTIPLICITY_PARAMETER_FORMAT, result, ValueSpecificationUtil.getSpecificationValue(property.getLowerValue()), ValueSpecificationUtil.getSpecificationValue(property.getUpperValue()));
114
			}
115
			// manage initial values
116
			if(property.getDefaultValue() != null) {
117
				ValueSpecification valueSpecification = property.getDefaultValue();
118
				if(valueSpecification instanceof InstanceValue && property.getType().equals(valueSpecification.getType())) {
119
					result = String.format(DEFAULT_VALUE_PARAMETER_FORMAT, result, ValueSpecificationUtil.getSpecificationValue(valueSpecification));
120
				}
121
			}
122
			// manage modifier
123
			StringBuffer sb = new StringBuffer();
124
			if(property.isReadOnly()) {
125
				sb.append(sb.length() == 0 ? "readOnly" : ", readOnly");
126
			}
127
			if(property.isOrdered()) {
128
				sb.append(sb.length() == 0 ? "ordered" : ", ordered");
129
			}
130
			if(property.isUnique()) {
131
				sb.append(sb.length() == 0 ? "unique" : ", unique");
132
			}
133
			if(property.isDerivedUnion()) {
134
				sb.append(sb.length() == 0 ? "union" : ", union");
135
			}
136
			EList<Property> redefinedProperties = property.getRedefinedProperties();
137
			if(redefinedProperties != null && !redefinedProperties.isEmpty()) {
138
				for(Property p : redefinedProperties) {
139
					sb.append(sb.length() == 0 ? p.getName() : ", redefines " + p.getName());
140
				}
141
			}
142
			if(sb.length() != 0) {
143
				result = String.format(MODIFIER_PARAMETER_FORMAT, result, sb.toString());
144
			}
145
		}
146
		return result;
147
	}
148
149
	/**
150
	 * {@inheritDoc}
151
	 */
152
	public boolean areSemanticElementsAffected(EObject listener, Object notification) {
153
		EStructuralFeature feature = getEStructuralFeature(notification);
154
		return isValidFeature(feature);
155
	}
156
157
	/**
158
	 * {@inheritDoc}
159
	 */
160
	public List<?> getSemanticElementsBeingParsed(EObject element) {
161
		List<Element> semanticElementsBeingParsed = new ArrayList<Element>();
162
		Property property = null;
163
		if(element instanceof ConstraintProperty) {
164
			property = ((ConstraintProperty)element).getBase_Property();
165
		}
166
		if(property != null) {
167
			semanticElementsBeingParsed.add(property);
168
			if(property.getType() != null) {
169
				semanticElementsBeingParsed.add(property.getType());
170
			}
171
			if(property.getLowerValue() != null) {
172
				semanticElementsBeingParsed.add(property.getLowerValue());
173
			}
174
			if(property.getUpperValue() != null) {
175
				semanticElementsBeingParsed.add(property.getUpperValue());
176
			}
177
			if(property.getDefaultValue() != null) {
178
				semanticElementsBeingParsed.add(property.getDefaultValue());
179
			}
180
		}
181
		return semanticElementsBeingParsed;
182
	}
183
184
	/**
185
	 * Determines if the given feature has to be taken into account in this parser
186
	 * 
187
	 * @param feature
188
	 *        the feature to test
189
	 * @return true if is valid, false otherwise
190
	 */
191
	private boolean isValidFeature(EStructuralFeature feature) {
192
		return UMLPackage.eINSTANCE.getNamedElement_Name().equals(feature) || UMLPackage.eINSTANCE.getTypedElement_Type().equals(feature) || UMLPackage.eINSTANCE.getInstanceValue_Instance().equals(feature) || UMLPackage.eINSTANCE.getMultiplicityElement_IsOrdered().equals(feature) || UMLPackage.eINSTANCE.getMultiplicityElement_IsUnique().equals(feature) || UMLPackage.eINSTANCE.getMultiplicityElement_LowerValue().equals(feature) || UMLPackage.eINSTANCE.getMultiplicityElement_UpperValue().equals(feature) || UMLPackage.eINSTANCE.getStructuralFeature_IsReadOnly().equals(feature) || UMLPackage.eINSTANCE.getFeature_IsStatic().equals(feature) || UMLPackage.eINSTANCE.getProperty_IsDerived().equals(feature) || UMLPackage.eINSTANCE.getProperty_IsDerivedUnion().equals(feature) || UMLPackage.eINSTANCE.getProperty_RedefinedProperty().equals(feature);
193
	}
194
195
	/**
196
	 * {@inheritDoc}
197
	 */
198
	@Override
199
	public String getEditString(IAdaptable adapter, int flags) {
200
		EObject element = (EObject)adapter.getAdapter(EObject.class);
201
		if(element instanceof ConstraintProperty) {
202
			element = ((ConstraintProperty)element).getBase_Property();
203
		}
204
		return getEditorProcessor().format(getEditableValues(element), new StringBuffer(), new FieldPosition(0)).toString();
205
	}
206
207
	/**
208
	 * {@inheritDoc}
209
	 */
210
	@Override
211
	protected ICommand getParseCommand(IAdaptable adapter, Object[] values, int flags) {
212
		if(values == null || validateNewValues(values).getCode() != IParserEditStatus.EDITABLE) {
213
			return UnexecutableCommand.INSTANCE;
214
		}
215
		EObject element = (EObject)adapter.getAdapter(EObject.class);
216
		if(element instanceof ConstraintProperty) {
217
			element = ((ConstraintProperty)element).getBase_Property();
218
		}
219
		TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(element);
220
		if(editingDomain == null) {
221
			return UnexecutableCommand.INSTANCE;
222
		}
223
		CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Set Values"); //$NON-NLS-1$
224
		for(int i = 0; i < values.length; i++) {
225
			command.compose(getModificationCommand(element, editableFeatures[i], values[i]));
226
		}
227
		return command;
228
	}
229
230
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/parsers/PropertyLabelParser.java (-223 lines)
Lines 1-223 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.parsers;
15
16
import java.text.FieldPosition;
17
import java.util.ArrayList;
18
import java.util.List;
19
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.emf.common.notify.Notification;
22
import org.eclipse.emf.common.util.EList;
23
import org.eclipse.emf.ecore.EAttribute;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
27
import org.eclipse.gmf.runtime.notation.Node;
28
import org.eclipse.papyrus.sysml.diagram.parametric.utils.PropertyLinkedToClassifierNode;
29
import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
30
import org.eclipse.papyrus.uml.tools.utils.ValueSpecificationUtil;
31
import org.eclipse.uml2.uml.Classifier;
32
import org.eclipse.uml2.uml.Element;
33
import org.eclipse.uml2.uml.Property;
34
import org.eclipse.uml2.uml.UMLPackage;
35
import org.eclipse.uml2.uml.ValueSpecification;
36
37
/**
38
 * A specific parser for displaying an property. This parser refreshes the text displayed for the
39
 * Property.
40
 */
41
public class PropertyLabelParser extends MessageFormatParser implements ISemanticParser {
42
43
	/** The String format for displaying a ConstraintProperty with no type */
44
	private static final String UNTYPED_PARAMETER_FORMAT = "%s";
45
46
	/** The String format for displaying a ConstraintProperty with its type */
47
	private static final String TYPED_PARAMETER_FORMAT = "%s: %s";
48
49
	/** The String format for displaying a ConstraintProperty with multiplicity */
50
	private static final String MULTIPLICITY_PARAMETER_FORMAT = "%s [%s..%s]";
51
52
	/** The String format for displaying a ConstraintProperty with default value */
53
	private static final String DEFAULT_VALUE_PARAMETER_FORMAT = "%s= %s";
54
55
	/** The String format for displaying a ConstraintProperty with attribute */
56
	private static final String MODIFIER_PARAMETER_FORMAT = "%s{%s}";
57
58
	/** Class to compute property name depth */
59
	PropertyLinkedToClassifierNode propertyLinkedToClassifier;
60
61
	/** The classifier, container view of the property */
62
	private Classifier classifier;
63
64
	public PropertyLabelParser(EAttribute[] features, EAttribute[] editableFeatures) {
65
		super(features, editableFeatures);
66
	}
67
68
	public PropertyLabelParser(EAttribute[] features) {
69
		super(features);
70
	}
71
72
	public PropertyLabelParser() {
73
		super(new EAttribute[]{ UMLPackage.eINSTANCE.getNamedElement_Name() });
74
	}
75
76
	protected EStructuralFeature getEStructuralFeature(Object notification) {
77
		EStructuralFeature featureImpl = null;
78
		if(notification instanceof Notification) {
79
			Object feature = ((Notification)notification).getFeature();
80
			if(feature instanceof EStructuralFeature) {
81
				featureImpl = (EStructuralFeature)feature;
82
			}
83
		}
84
		return featureImpl;
85
	}
86
87
	/**
88
	 * {@inheritDoc}
89
	 */
90
	public boolean isAffectingEvent(Object event, int flags) {
91
		EStructuralFeature feature = getEStructuralFeature(event);
92
		return isValidFeature(feature);
93
	}
94
95
	/**
96
	 * {@inheritDoc}
97
	 */
98
	public String getPrintString(IAdaptable element, int flags) {
99
		String result = "";
100
		Property property = null;
101
		Object adapter = element.getAdapter(EObject.class);
102
		if(adapter instanceof Property) {
103
			property = (Property)adapter;
104
			String name = property.isDerived() ? "/ " + property.getName() : property.getName();
105
			result = String.format(UNTYPED_PARAMETER_FORMAT, name);
106
			// Perform property depth to set the name
107
			for(Object obj : DiagramEditPartsUtil.getEObjectViews(property)) {
108
				if(obj instanceof Node && classifier != null) {
109
					propertyLinkedToClassifier = new PropertyLinkedToClassifierNode(classifier, property, (Node)obj);
110
					propertyLinkedToClassifier.refresh();
111
					name = propertyLinkedToClassifier.getName();
112
					result = String.format(UNTYPED_PARAMETER_FORMAT, name);
113
				}
114
			}
115
			// manage type
116
			if(property.getType() != null) {
117
				String type = property.getType().getName();
118
				result = String.format(TYPED_PARAMETER_FORMAT, name, type);
119
			}
120
			// manage multiplicity
121
			if(property.getLower() != 1 || property.getUpper() != 1) {
122
				result = String.format(MULTIPLICITY_PARAMETER_FORMAT, result, ValueSpecificationUtil.getSpecificationValue(property.getLowerValue()), ValueSpecificationUtil.getSpecificationValue(property.getUpperValue()));
123
			}
124
			// manage initial values
125
			if(property.getDefaultValue() != null) {
126
				ValueSpecification valueSpecification = property.getDefaultValue();
127
				String specificationValue = ValueSpecificationUtil.getSpecificationValue(valueSpecification);
128
				if(specificationValue != null && specificationValue.length() > 0) {
129
					result = String.format(DEFAULT_VALUE_PARAMETER_FORMAT, result, ValueSpecificationUtil.getSpecificationValue(valueSpecification));
130
				}
131
			}
132
			// manage modifier
133
			StringBuffer sb = new StringBuffer();
134
			if(property.isReadOnly()) {
135
				sb.append(sb.length() == 0 ? "readOnly" : ", readOnly");
136
			}
137
			if(property.isOrdered()) {
138
				sb.append(sb.length() == 0 ? "ordered" : ", ordered");
139
			}
140
			if(property.isUnique()) {
141
				sb.append(sb.length() == 0 ? "unique" : ", unique");
142
			}
143
			if(property.isDerivedUnion()) {
144
				sb.append(sb.length() == 0 ? "union" : ", union");
145
			}
146
			EList<Property> redefinedProperties = property.getRedefinedProperties();
147
			if(redefinedProperties != null && !redefinedProperties.isEmpty()) {
148
				for(Property p : redefinedProperties) {
149
					sb.append(sb.length() == 0 ? p.getName() : ", redefines " + p.getName());
150
				}
151
			}
152
			if(sb.length() != 0) {
153
				result = String.format(MODIFIER_PARAMETER_FORMAT, result, sb.toString());
154
			}
155
		}
156
		return result;
157
	}
158
159
	/**
160
	 * {@inheritDoc}
161
	 */
162
	public boolean areSemanticElementsAffected(EObject listener, Object notification) {
163
		EStructuralFeature feature = getEStructuralFeature(notification);
164
		return isValidFeature(feature);
165
	}
166
167
	/**
168
	 * {@inheritDoc}
169
	 */
170
	public List<?> getSemanticElementsBeingParsed(EObject element) {
171
		List<Element> semanticElementsBeingParsed = new ArrayList<Element>();
172
		Property property = null;
173
		if(element instanceof Property) {
174
			property = (Property)element;
175
			semanticElementsBeingParsed.add(property);
176
			if(property.getType() != null) {
177
				semanticElementsBeingParsed.add(property.getType());
178
			}
179
			if(property.getLowerValue() != null) {
180
				semanticElementsBeingParsed.add(property.getLowerValue());
181
			}
182
			if(property.getUpperValue() != null) {
183
				semanticElementsBeingParsed.add(property.getUpperValue());
184
			}
185
			if(property.getDefaultValue() != null) {
186
				semanticElementsBeingParsed.add(property.getDefaultValue());
187
			}
188
		}
189
		return semanticElementsBeingParsed;
190
	}
191
192
	/**
193
	 * Determines if the given feature has to be taken into account in this parser
194
	 * 
195
	 * @param feature
196
	 *        the feature to test
197
	 * @return true if is valid, false otherwise
198
	 */
199
	private boolean isValidFeature(EStructuralFeature feature) {
200
		return UMLPackage.eINSTANCE.getNamedElement_Name().equals(feature) || UMLPackage.eINSTANCE.getTypedElement_Type().equals(feature) || UMLPackage.eINSTANCE.getConnector_Type().equals(feature) || UMLPackage.eINSTANCE.getInstanceValue_Instance().equals(feature) || UMLPackage.eINSTANCE.getMultiplicityElement_IsOrdered().equals(feature) || UMLPackage.eINSTANCE.getMultiplicityElement_IsUnique().equals(feature) || UMLPackage.eINSTANCE.getMultiplicityElement_LowerValue().equals(feature) || UMLPackage.eINSTANCE.getMultiplicityElement_UpperValue().equals(feature) || UMLPackage.eINSTANCE.getStructuralFeature_IsReadOnly().equals(feature) || UMLPackage.eINSTANCE.getFeature_IsStatic().equals(feature) || UMLPackage.eINSTANCE.getProperty_IsDerived().equals(feature) || UMLPackage.eINSTANCE.getProperty_IsDerivedUnion().equals(feature) || UMLPackage.eINSTANCE.getProperty_RedefinedProperty().equals(feature);
201
	}
202
203
	/**
204
	 * {@inheritDoc}
205
	 */
206
	@Override
207
	public String getEditString(IAdaptable adapter, int flags) {
208
		EObject element = (EObject)adapter.getAdapter(EObject.class);
209
		return getEditorProcessor().format(getEditableValues(element), new StringBuffer(), new FieldPosition(0)).toString();
210
	}
211
212
	/**
213
	 * Sets the block that is linked to the current property
214
	 * 
215
	 * @param element
216
	 */
217
	public void setBlock(EObject element) {
218
		if(element instanceof Classifier) {
219
			this.classifier = (Classifier)element;
220
		}
221
	}
222
223
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/providers/CustomEditPolicyProvider.java (-81 lines)
Lines 1-81 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
 *  Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import org.eclipse.gef.EditPart;
17
import org.eclipse.gmf.runtime.common.core.service.IOperation;
18
import org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener;
19
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
20
import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
21
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
22
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
23
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
24
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
25
import org.eclipse.papyrus.uml.diagram.common.editpolicies.HyperLinkPopupBarEditPolicy;
26
import org.eclipse.papyrus.uml.diagram.common.editpolicies.NavigationEditPolicy;
27
28
/**
29
 * this is an editpolicy provider in charge to install navigation policies
30
 * 
31
 * @author Patrick Tessier
32
 */
33
public class CustomEditPolicyProvider implements IEditPolicyProvider {
34
35
	/**
36
	 * 
37
	 * {@inheritDoc}
38
	 */
39
	public void addProviderChangeListener(IProviderChangeListener listener) {
40
41
	}
42
43
	/**
44
	 * 
45
	 * {@inheritDoc}
46
	 */
47
	public void createEditPolicies(EditPart editPart) {
48
		editPart.installEditPolicy(NavigationEditPolicy.NAVIGATION_POLICY, new NavigationEditPolicy());
49
		if( editPart instanceof IPrimaryEditPart){
50
			editPart.installEditPolicy(EditPolicyRoles.POPUPBAR_ROLE, new HyperLinkPopupBarEditPolicy());
51
		}
52
	}
53
54
	/**
55
	 * 
56
	 * {@inheritDoc}
57
	 */
58
	public boolean provides(IOperation operation) {
59
		CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation)operation;
60
		if(!(epOperation.getEditPart() instanceof GraphicalEditPart)) {
61
			return false;
62
		}
63
		GraphicalEditPart gep = (GraphicalEditPart)epOperation.getEditPart();
64
		String diagramType = gep.getNotationView().getDiagram().getType();
65
		if(ParametricEditPart.MODEL_ID.equals(diagramType)) {
66
			return true;
67
		}
68
69
70
		return false;
71
	}
72
73
	/**
74
	 * 
75
	 * {@inheritDoc}
76
	 */
77
	public void removeProviderChangeListener(IProviderChangeListener listener) {
78
79
	}
80
81
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/providers/ParametricDiagramContributionItemProvider.java (-39 lines)
Lines 1-39 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider;
17
import org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor;
18
import org.eclipse.jface.action.IAction;
19
import org.eclipse.papyrus.sysml.diagram.parametric.actions.RestoreRelatedLinksAction;
20
21
22
/**
23
 * The Class uses to contribute item for specific actions
24
 */
25
public class ParametricDiagramContributionItemProvider extends AbstractContributionItemProvider {
26
27
	/**
28
	 * @see org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.AbstractContributionItemProvider#createAction(java.lang.String,
29
	 *      org.eclipse.gmf.runtime.common.ui.util.IWorkbenchPartDescriptor)
30
	 */
31
	@Override
32
	protected IAction createAction(String actionId, IWorkbenchPartDescriptor partDescriptor) {
33
		if(actionId.equals(RestoreRelatedLinksAction.ID)) {
34
			return new RestoreRelatedLinksAction();
35
		}
36
		return super.createAction(actionId, partDescriptor);
37
	}
38
39
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/providers/ParametricDiagramContributionPolicyClass.java (-46 lines)
Lines 1-46 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 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
 *   Atos Origin - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import org.eclipse.core.runtime.IConfigurationElement;
17
import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.IPopupMenuContributionPolicy;
18
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
19
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
20
import org.eclipse.jface.viewers.ISelection;
21
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
22
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
23
import org.eclipse.ui.IEditorPart;
24
import org.eclipse.ui.PlatformUI;
25
26
/**
27
 * Reduce the scope of the Menu contribution of the Parametric Diagram.
28
 * implements {@link IPopupMenuContributionPolicy}
29
 * 
30
 * @author arthur daussy
31
 */
32
public class ParametricDiagramContributionPolicyClass implements IPopupMenuContributionPolicy {
33
34
	public boolean appliesTo(ISelection selection, IConfigurationElement configuration) {
35
		IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
36
		if(editorPart instanceof IMultiDiagramEditor) {
37
			editorPart = ((IMultiDiagramEditor)editorPart).getActiveEditor();
38
			if(editorPart instanceof DiagramEditor) {
39
				DiagramEditPart host = ((DiagramEditor)editorPart).getDiagramEditPart();
40
				return ParametricEditPart.MODEL_ID.equals(host.getDiagramView().getType());
41
			}
42
		}
43
		return false;
44
	}
45
46
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/texteditor/ConstraintPropertyConfiguration.java (-133 lines)
Lines 1-133 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.texteditor;
15
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.jface.dialogs.IInputValidator;
18
import org.eclipse.jface.text.source.SourceViewerConfiguration;
19
import org.eclipse.papyrus.extensionpoints.editors.configuration.DefaultDirectEditorConfiguration;
20
import org.eclipse.papyrus.parsers.modelgenerator.PropertyGenerator;
21
import org.eclipse.papyrus.parsers.texteditor.CompletionFilterSourceViewerConfiguration.ICompletionFilter;
22
import org.eclipse.papyrus.parsers.texteditor.propertylabel.IContext;
23
import org.eclipse.papyrus.parsers.texteditor.propertylabel.PropertyConfigurationForUML;
24
import org.eclipse.papyrus.parsers.texteditor.propertylabel.PropertyLabelSourceViewerConfiguration;
25
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
26
import org.eclipse.papyrus.uml.tools.utils.PropertyUtil;
27
import org.eclipse.uml2.uml.Element;
28
import org.eclipse.uml2.uml.Property;
29
30
/**
31
 * Configuration Class for the direct edition of a SysML constraint property
32
 */
33
public class ConstraintPropertyConfiguration extends DefaultDirectEditorConfiguration {
34
35
	/** configuration of the source viewer */
36
	final private PropertyLabelSourceViewerConfiguration configuration;
37
38
	/**
39
	 * Creates a new PropertyConfiguration to filter values.
40
	 */
41
	public ConstraintPropertyConfiguration() {
42
		configuration = new PropertyLabelSourceViewerConfiguration(new ICompletionFilter() {
43
44
			public boolean filter(int context, EObject e) {
45
				switch(context) {
46
				case IContext.AFTER_COLON:
47
					if(e instanceof Element) {
48
						if(((Element)e).getAppliedStereotype("SysML::Constraints::ConstraintBlock") != null) {
49
							return false;
50
						}
51
					}
52
53
					return true;
54
				default:
55
					return false;
56
				}
57
			}
58
		});
59
	}
60
61
	/**
62
	 * {@inheritDoc}
63
	 */
64
	public SourceViewerConfiguration getSourceViewerConfiguration() {
65
		return configuration;
66
	}
67
68
	/**
69
	 * {@inheritDoc}
70
	 */
71
	public String getTextToEdit(Object editedObject) {
72
		if(editedObject instanceof ConstraintProperty) {
73
			Property property = ((ConstraintProperty)editedObject).getBase_Property();
74
			return PropertyUtil.getLabel(property);
75
		}
76
		return "not a Constraint Property";
77
	}
78
79
	/**
80
	 * {@inheritDoc}
81
	 */
82
	@Override
83
	public Object preEditAction(Object objectToEdit) {
84
		if(objectToEdit instanceof ConstraintProperty) {
85
			Property property = ((ConstraintProperty)objectToEdit).getBase_Property();
86
			configuration.setProperty(property);
87
		}
88
		return super.preEditAction(objectToEdit);
89
	}
90
91
	/**
92
	 * {@inheritDoc}
93
	 */
94
	public Object postEditAction(Object editedObject, String text) {
95
		if(editedObject instanceof ConstraintProperty) {
96
			Property property = ((ConstraintProperty)editedObject).getBase_Property();
97
			PropertyGenerator generator = new PropertyGenerator(property);
98
			generator.parseAndModifyProperty(text);
99
		}
100
		return null;
101
	}
102
103
	/**
104
	 * {@inheritDoc}
105
	 */
106
	@Override
107
	public IInputValidator getInputValidator() {
108
		return new IInputValidator() {
109
110
			public String isValid(String newText) {
111
				if(getObjectToEdit() instanceof ConstraintProperty) {
112
					Property property = ((ConstraintProperty)getObjectToEdit()).getBase_Property();
113
					PropertyGenerator generator = new PropertyGenerator(property);
114
					return generator.parseAndValidateProperty(newText);
115
				}
116
				return null;
117
			}
118
		};
119
	}
120
121
	/**
122
	 * {@inheritDoc}
123
	 */
124
	@Override
125
	public Selection getTextSelection(String value, Object editedObject) {
126
		if(editedObject instanceof ConstraintProperty) {
127
			Property property = ((ConstraintProperty)editedObject).getBase_Property();
128
			return new PropertyConfigurationForUML().getTextSelection(value, property);
129
		}
130
		return super.getTextSelection(value, editedObject);
131
	}
132
133
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/utils/PropertyLinkedToClassifier.java (-152 lines)
Lines 1-152 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Thibault Landre (Atos Origin) thibault.landre@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.utils;
15
16
import java.util.LinkedList;
17
import java.util.List;
18
19
import org.eclipse.emf.common.util.EList;
20
import org.eclipse.uml2.uml.Classifier;
21
import org.eclipse.uml2.uml.Port;
22
import org.eclipse.uml2.uml.Property;
23
import org.eclipse.uml2.uml.Type;
24
25
/**
26
 * PropertyLinkedToClassifier checks if a specified property is linked to a classifier
27
 */
28
public class PropertyLinkedToClassifier {
29
30
	/** The classifier. */
31
	private final Classifier classifier;
32
33
	/** The property. */
34
	private final Property property;
35
36
	/** The list routes. */
37
	private List<Route> routes;
38
39
	/**
40
	 * Instantiates a new property linked to classifier.
41
	 * 
42
	 * @param classifier
43
	 * @param property
44
	 */
45
	public PropertyLinkedToClassifier(Classifier classifier, Property property) {
46
		this.classifier = classifier;
47
		this.property = property;
48
		this.routes = new LinkedList<Route>();
49
		refresh();
50
	}
51
52
	/**
53
	 * Checks if the property is linked to classifier.
54
	 * 
55
	 * @return true, if is linked to classifier
56
	 */
57
	public boolean isLinkedToClassifier() {
58
		return !routes.isEmpty();
59
	}
60
61
	/**
62
	 * Checks if the property is linked to classifier with a multi-level path of accessible property from the classifier
63
	 * 
64
	 * @return true, if is linked to classifier with a multi-level path
65
	 */
66
	public boolean isLinkedWithMultiLevelPath() {
67
		boolean result = false;
68
		if(!routes.isEmpty()) {
69
			for(Route r : routes) {
70
				result |= r.getRouteDepth() > 1;
71
			}
72
		}
73
		return result;
74
	}
75
76
	/**
77
	 * Gets the available routes.
78
	 * 
79
	 * @return the available routes
80
	 */
81
	public List<Route> getAvailableRoutes() {
82
		return routes;
83
	}
84
85
	/**
86
	 * Gets the property.
87
	 * 
88
	 * @return the property
89
	 */
90
	protected Property getProperty() {
91
		return property;
92
	}
93
94
	/**
95
	 * Gets the number available route.
96
	 * 
97
	 * @return the number available route
98
	 */
99
	public int getNumberAvailableRoute() {
100
		return routes.size();
101
	}
102
103
	/**
104
	 * Refresh link to classifier.
105
	 * 
106
	 * @param classifierParent
107
	 * @param propertyToFind
108
	 * @param route
109
	 */
110
	private void refreshLinkToClassifier(Classifier classifierParent, final Property propertyToFind, final Route route) {
111
		EList<Property> classifierParentAttributes = classifierParent.getAllAttributes();
112
		// If the property is contained by the classifier
113
		if(classifierParentAttributes.contains(propertyToFind)) {
114
			route.addSegment(propertyToFind);
115
			routes.add(route);
116
		} else {
117
			for(Property attribute : classifierParentAttributes) {
118
				if(!(attribute instanceof Port)) {
119
					Type attributeType = attribute.getType();
120
					// stop loop
121
					if(route.getProperties().contains(attribute)) {
122
						// Launch a warning ? an error ?
123
						break;
124
					}
125
					if(attributeType instanceof Classifier) {
126
						Route newRoute = new Route(new LinkedList<Property>(route.getProperties()));
127
						newRoute.addSegment(attribute);
128
						refreshLinkToClassifier((Classifier)attributeType, propertyToFind, newRoute);
129
					}
130
				}
131
			}
132
		}
133
	}
134
135
	/**
136
	 * Checks for several routes.
137
	 * 
138
	 * @return true, if successful
139
	 */
140
	public boolean hasSeveralRoutes() {
141
		return routes.size() > 1;
142
	}
143
144
	/**
145
	 * Refresh.
146
	 */
147
	public void refresh() {
148
		routes.clear();
149
		refreshLinkToClassifier(classifier, property, new Route());
150
	}
151
152
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/utils/PropertyLinkedToClassifierNode.java (-234 lines)
Lines 1-234 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Thibault Landre (Atos Origin) thibault.landre@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.utils;
15
16
import java.util.HashMap;
17
import java.util.LinkedList;
18
import java.util.List;
19
import java.util.Map;
20
21
import org.eclipse.emf.ecore.EAnnotation;
22
import org.eclipse.emf.ecore.EcoreFactory;
23
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateOrSelectElementCommand.LabelProvider;
24
import org.eclipse.gmf.runtime.notation.Node;
25
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
26
import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.ui.IWorkbench;
29
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
30
import org.eclipse.uml2.uml.Classifier;
31
import org.eclipse.uml2.uml.Property;
32
33
public class PropertyLinkedToClassifierNode extends PropertyLinkedToClassifier {
34
35
	public static final String PROPERTY_ROUTE_URL_SOURCE = "http://www.eclipse.org/papyrus/propertyRoute";
36
37
	public static final String SELECTED_ROUTE_KEY = "selectedRoute";
38
39
	private Node graphNode;
40
41
	public PropertyLinkedToClassifierNode(Classifier classifier, Property property, Node graphNode) {
42
		super(classifier, property);
43
		this.graphNode = graphNode;
44
	}
45
46
	/**
47
	 * 
48
	 * @return
49
	 */
50
	public String getName() {
51
		String lName = "";
52
		if(getAvailableRoutes().isEmpty()) {
53
			lName = getProperty().getName();
54
		} else if(!hasSeveralRoutes()) {
55
			lName = getAvailableRoutes().get(0).getName();
56
		} else {
57
			lName = getSelectedRoute();
58
		}
59
		return lName;
60
	}
61
62
	private String getSelectedRoute() {
63
		String result = "";
64
		if("".equals(getRootingProperty(graphNode))) {
65
			LinkedList<Route> filteredAvailableRoute = filterAvailableRoute(getAvailableRoutes());
66
			if(filteredAvailableRoute.size() == 1) {
67
				result = filteredAvailableRoute.getFirst().getName();
68
			} else if(!filteredAvailableRoute.isEmpty()) {
69
				// doesn't display dialog box, only get the first route
70
				//result = getUserSelectionRoute(filteredAvailableRoute);
71
				result = filteredAvailableRoute.getFirst().getName();
72
			}
73
		} else {
74
			String oldRouteSelectedValue = getRootingProperty(graphNode);
75
			Map<String, Route> routeNameAndRoute = getRouteNameAndRoute(getAvailableRoutes());
76
			if(routeNameAndRoute.containsKey(oldRouteSelectedValue)) {
77
				result = oldRouteSelectedValue;
78
			} else {
79
				result = calculateNewRoute(oldRouteSelectedValue);
80
			}
81
		}
82
		return result;
83
	}
84
85
	private String getUserSelectionRoute(LinkedList<Route> filteredAvailableRoute) {
86
		IWorkbench workBench = SysmlDiagramEditorPlugin.getInstance().getWorkbench();
87
		Shell shell = workBench.getActiveWorkbenchWindow().getShell();
88
		ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, new LabelProvider() {
89
90
			@Override
91
			public String getText(Object element) {
92
				if(element instanceof Route) {
93
					return ((Route)element).getName();
94
				}
95
				return super.getText(element);
96
			}
97
		});
98
		dialog.setTitle("Routing selection");
99
		dialog.setMessage("Select the route of the property (* = any string, ? = any char):");
100
		dialog.setElements(filteredAvailableRoute.toArray());
101
		dialog.setHelpAvailable(false);
102
		dialog.setMultipleSelection(false);
103
		dialog.open();
104
105
		String result = "";
106
		if(dialog.getResult() != null) {
107
			result = ((Route)dialog.getFirstResult()).getName();
108
		} else {
109
			result = filteredAvailableRoute.getFirst().getName();
110
		}
111
		return result;
112
	}
113
114
	/**
115
	 * Filter the available route for accessing a property. Remove from the list the property that
116
	 * are already displayed in the diagram.
117
	 * 
118
	 * @param availableRoutes
119
	 *        the availableRoutes for this property
120
	 * @return the availableRoutes for this property that are not already displayed in the diagram
121
	 */
122
	private LinkedList<Route> filterAvailableRoute(List<Route> availableRoutes) {
123
		Map<String, Route> routeNameAndRoute = getRouteNameAndRoute(availableRoutes);
124
		for(Object view : DiagramEditPartsUtil.getEObjectViews(getProperty())) {
125
			if(view instanceof Node) {
126
				String routeNamedSaved = getRootingProperty((Node)view);
127
				if(routeNameAndRoute.containsKey(routeNamedSaved)) {
128
					routeNameAndRoute.remove(routeNamedSaved);
129
				}
130
			}
131
		}
132
		return new LinkedList<Route>(routeNameAndRoute.values());
133
	}
134
135
	/**
136
	 * Return a map containing the routes and their associated names from a list of routes
137
	 * 
138
	 * @param routes
139
	 *        the list of routes
140
	 * @return the map with key the route, and value the name of the route.
141
	 */
142
	private Map<String, Route> getRouteNameAndRoute(List<Route> routes) {
143
		Map<String, Route> routeAndName = new HashMap<String, Route>();
144
		for(Route route : routes) {
145
			routeAndName.put(route.getName(), route);
146
		}
147
		return routeAndName;
148
	}
149
150
	private String calculateNewRoute(String oldRouteSelectedValue) {
151
		List<String> availableSpecificRoute = new LinkedList<String>();
152
		// If the length of the availableRoutes is bigger than the length of the old route, it means
153
		// that the property
154
		// is dragged/dropped to a parent container of its current container
155
		if(getAvailableRoutes().get(0).getName().length() > oldRouteSelectedValue.length()) {
156
			for(Route route : getAvailableRoutes()) {
157
158
				if(route.getName().indexOf(oldRouteSelectedValue) > 0) {
159
					availableSpecificRoute.add(route.getName());
160
				}
161
			}
162
			// If a unique route is present in the list, it means that there is only a route
163
			// possible
164
			if(availableSpecificRoute.size() == 1) {
165
				return availableSpecificRoute.get(0);
166
			} else {
167
				// Otherwise it means there is several routes possible. We need to check the name of
168
				// the
169
				// container
170
			}
171
		}
172
		// Otherwise the element is dragged/dropped to a child container of its current container
173
		else {
174
			for(Route route : getAvailableRoutes()) {
175
				if(oldRouteSelectedValue.indexOf(route.getName()) > 0) {
176
					availableSpecificRoute.add(route.getName());
177
				}
178
			}
179
			if(availableSpecificRoute.size() == 1) {
180
				return availableSpecificRoute.get(0);
181
			}
182
		}
183
		return "";
184
	}
185
186
	/**
187
	 * Creates the rooting property into an eAnnotation
188
	 * 
189
	 * @param node
190
	 * @param name
191
	 */
192
	public void createRootingProperty(Node node, String name) {
193
		if("".equals(getRootingProperty(node))) {
194
			EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
195
			annotation.setSource(PROPERTY_ROUTE_URL_SOURCE);
196
			node.getEAnnotations().add(annotation);
197
198
			annotation.getDetails().put(SELECTED_ROUTE_KEY, name);
199
		}
200
	}
201
202
	/**
203
	 * Checks if the specified name is an existing route.
204
	 * 
205
	 * @param name
206
	 * @return true if it is an existing route
207
	 */
208
	public boolean isExistingRoute(String name) {
209
		boolean result = false;
210
		for(Route r : getAvailableRoutes()) {
211
			result |= r.getName().equals(name);
212
		}
213
		return result;
214
	}
215
216
	/**
217
	 * Gets the rooting property.
218
	 * 
219
	 * @param node
220
	 *        the node
221
	 * @param key
222
	 *        the key
223
	 * @return the rooting property
224
	 */
225
	private String getRootingProperty(Node node) {
226
		String value = "";
227
		EAnnotation eAnnotation = node.getEAnnotation(PROPERTY_ROUTE_URL_SOURCE);
228
		if(eAnnotation != null) {
229
			value = eAnnotation.getDetails().get(SELECTED_ROUTE_KEY);
230
		}
231
		return value;
232
	}
233
234
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/custom-src/org/eclipse/papyrus/sysml/diagram/parametric/utils/Route.java (-102 lines)
Lines 1-102 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Thibault Landre (Atos Origin) thibault.landre@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.utils;
15
16
import java.util.LinkedList;
17
18
import org.eclipse.uml2.uml.Property;
19
20
/**
21
 * A class to described a route to access a property from a classifier. This class contains an
22
 * ordered list of the property contained in the route and a string representing the name of the
23
 * route.
24
 */
25
public class Route {
26
27
	/** The properties list. */
28
	private LinkedList<Property> propertyList;
29
30
	/** The name of the route */
31
	private String name;
32
33
	/**
34
	 * Instantiates a new route.
35
	 */
36
	public Route() {
37
		this(new LinkedList<Property>());
38
	}
39
40
	/**
41
	 * Instantiates a new route.
42
	 * 
43
	 * @param propertyList
44
	 */
45
	public Route(LinkedList<Property> propertyList) {
46
		assert propertyList != null;
47
		this.propertyList = propertyList;
48
		this.name = "";
49
	}
50
51
	/**
52
	 * Adds a property to the list
53
	 * 
54
	 * @param property
55
	 */
56
	protected void addSegment(Property property) {
57
		propertyList.add(property);
58
	}
59
60
	/**
61
	 * Calculate the name of the route. The name is composed of the name of each property which
62
	 * makes up the route separated by coma.
63
	 */
64
	private void calculateName() {
65
		name = "";
66
		for(Property property : propertyList) {
67
			if(name.length() == 0) {
68
				name = property.getName();
69
			} else {
70
				name = name + "." + property.getName();
71
			}
72
		}
73
	}
74
75
	/**
76
	 * Gets the name.
77
	 * 
78
	 * @return the name
79
	 */
80
	public String getName() {
81
		calculateName();
82
		return name;
83
	}
84
85
	/**
86
	 * Gets the properties.
87
	 * 
88
	 * @return the properties
89
	 */
90
	public LinkedList<Property> getProperties() {
91
		return propertyList;
92
	}
93
94
	/**
95
	 * Gets the route depth.
96
	 * 
97
	 * @return the route depth
98
	 */
99
	public int getRouteDepth() {
100
		return propertyList.size();
101
	}
102
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/messages.properties (-133 lines)
Added Link Here
1
#/*****************************************************************************
2
# * Copyright (c) 2009 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
# *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
# *
13
#  *****************************************************************************/
14
# TODO: manually put keys and values
15
SysMLCreationWizardTitle=New SysML Diagram
16
SysMLCreationWizard_DiagramModelFilePageTitle=Create SysML Diagram
17
SysMLCreationWizard_DiagramModelFilePageDescription=Select file that will contain diagram model.
18
SysMLCreationWizard_DomainModelFilePageTitle=Create SysML Domain Model
19
SysMLCreationWizard_DomainModelFilePageDescription=Select file that will contain domain model.
20
SysMLCreationWizardOpenEditorError=Error opening diagram editor
21
SysMLCreationWizardCreationError=Creation Problems
22
SysMLCreationWizardPageExtensionError=File name should have {0} extension.
23
SysMLDiagramEditorUtil_OpenModelResourceErrorDialogTitle=Error
24
SysMLDiagramEditorUtil_OpenModelResourceErrorDialogMessage=Failed to load model file {0}
25
SysMLDiagramEditorUtil_CreateDiagramProgressTask=Creating diagram and model files
26
SysMLDiagramEditorUtil_CreateDiagramCommandLabel=Creating diagram and model
27
SysMLDocumentProvider_isModifiable=Updating cache failed
28
SysMLDocumentProvider_handleElementContentChanged=Failed to refresh hierarchy for changed resource
29
SysMLDocumentProvider_IncorrectInputError={1}
30
SysMLDocumentProvider_NoDiagramInResourceError=Diagram is not present in resource
31
SysMLDocumentProvider_DiagramLoadingError=Error loading diagram
32
SysMLDocumentProvider_UnsynchronizedFileSaveError=The file has been changed on the file system
33
SysMLDocumentProvider_SaveDiagramTask=Saving diagram
34
SysMLDocumentProvider_SaveNextResourceTask=Saving {0}
35
SysMLDocumentProvider_SaveAsOperation=Saving {0} diagram as
36
InitDiagramFile_ResourceErrorDialogTitle=Error
37
InitDiagramFile_ResourceErrorDialogMessage=Model file loading failed
38
InitDiagramFile_WizardTitle=Initialize new {0} diagram file
39
InitDiagramFile_OpenModelFileDialogTitle=Select domain model
40
SysMLNewDiagramFileWizard_CreationPageName=Initialize new diagram file
41
SysMLNewDiagramFileWizard_CreationPageTitle=Diagram file
42
SysMLNewDiagramFileWizard_CreationPageDescription=Create new diagram based on {0} model content
43
SysMLNewDiagramFileWizard_RootSelectionPageName=Select diagram root element
44
SysMLNewDiagramFileWizard_RootSelectionPageTitle=Diagram root element
45
SysMLNewDiagramFileWizard_RootSelectionPageDescription=Select semantic model element to be depicted on diagram
46
SysMLNewDiagramFileWizard_RootSelectionPageSelectionTitle=Select diagram root element:
47
SysMLNewDiagramFileWizard_RootSelectionPageNoSelectionMessage=Diagram root element is not selected
48
SysMLNewDiagramFileWizard_RootSelectionPageInvalidSelectionMessage=Invalid diagram root element is selected
49
SysMLNewDiagramFileWizard_InitDiagramCommand=Initializing diagram contents
50
SysMLNewDiagramFileWizard_IncorrectRootError=Incorrect model object stored as a root resource object
51
SysMLDiagramEditor_SavingDeletedFile=The original file "{0}" has been deleted.
52
SysMLDiagramEditor_SaveAsErrorTitle=Problem During Save As...
53
SysMLDiagramEditor_SaveAsErrorMessage=Save could not be completed. Target file is already open in another editor.
54
SysMLDiagramEditor_SaveErrorTitle=Save Problems
55
SysMLDiagramEditor_SaveErrorMessage=Could not save file.
56
SysMLElementChooserDialog_SelectModelElementTitle=Select model element
57
ModelElementSelectionPageMessage=Select model element:
58
ValidateActionMessage=Validate
59
Sysml1Group_title=sysml
60
ConstraintBlock1CreationTool_title=ConstraintBlock
61
ConstraintBlock1CreationTool_desc=Create new ConstraintBlock
62
ConstraintProperty2CreationTool_title=ConstraintProperty
63
ConstraintProperty2CreationTool_desc=Create new ConstraintProperty
64
65
CommandName_OpenDiagram=Open Diagram
66
NavigatorActionProvider_OpenDiagramActionName=Open Diagram
67
SysMLModelingAssistantProviderTitle=Select domain model element
68
SysMLModelingAssistantProviderMessage=Available domain model elements:
69
SysmlCreationWizardTitle=New Parametric Diagram
70
SysmlCreationWizard_DiagramModelFilePageTitle=Create Parametric Diagram
71
SysmlCreationWizard_DiagramModelFilePageDescription=Select file that will contain diagram model.
72
SysmlCreationWizard_DomainModelFilePageTitle=Create Parametric Domain Model
73
SysmlCreationWizard_DomainModelFilePageDescription=Select file that will contain domain model.
74
SysmlCreationWizardOpenEditorError=Error opening diagram editor
75
SysmlCreationWizardCreationError=Creation Problems
76
SysmlCreationWizardPageExtensionError=File name should have {0} extension.
77
SysmlDiagramEditorUtil_OpenModelResourceErrorDialogTitle=Error
78
SysmlDiagramEditorUtil_OpenModelResourceErrorDialogMessage=Failed to load model file {0}
79
SysmlDiagramEditorUtil_CreateDiagramProgressTask=Creating diagram and model files
80
SysmlDiagramEditorUtil_CreateDiagramCommandLabel=Creating diagram and model
81
SysmlDocumentProvider_isModifiable=Updating cache failed
82
SysmlDocumentProvider_handleElementContentChanged=Failed to refresh hierarchy for changed resource
83
SysmlDocumentProvider_IncorrectInputError={1}
84
SysmlDocumentProvider_NoDiagramInResourceError=Diagram is not present in resource
85
SysmlDocumentProvider_DiagramLoadingError=Error loading diagram
86
SysmlDocumentProvider_UnsynchronizedFileSaveError=The file has been changed on the file system
87
SysmlDocumentProvider_SaveDiagramTask=Saving diagram
88
SysmlDocumentProvider_SaveNextResourceTask=Saving {0}
89
SysmlDocumentProvider_SaveAsOperation=Saving {0} diagram as
90
SysmlNewDiagramFileWizard_CreationPageName=Initialize new diagram file
91
SysmlNewDiagramFileWizard_CreationPageTitle=Diagram file
92
SysmlNewDiagramFileWizard_CreationPageDescription=Create new diagram based on {0} model content
93
SysmlNewDiagramFileWizard_RootSelectionPageName=Select diagram root element
94
SysmlNewDiagramFileWizard_RootSelectionPageTitle=Diagram root element
95
SysmlNewDiagramFileWizard_RootSelectionPageDescription=Select semantic model element to be depicted on diagram
96
SysmlNewDiagramFileWizard_RootSelectionPageSelectionTitle=Select diagram root element:
97
SysmlNewDiagramFileWizard_RootSelectionPageNoSelectionMessage=Diagram root element is not selected
98
SysmlNewDiagramFileWizard_RootSelectionPageInvalidSelectionMessage=Invalid diagram root element is selected
99
SysmlNewDiagramFileWizard_InitDiagramCommand=Initializing diagram contents
100
SysmlNewDiagramFileWizard_IncorrectRootError=Incorrect model object stored as a root resource object
101
SysmlDiagramEditor_SavingDeletedFile=The original file "{0}" has been deleted.
102
SysmlDiagramEditor_SaveAsErrorTitle=Problem During Save As...
103
SysmlDiagramEditor_SaveAsErrorMessage=Save could not be completed. Target file is already open in another editor.
104
SysmlDiagramEditor_SaveErrorTitle=Save Problems
105
SysmlDiagramEditor_SaveErrorMessage=Could not save file.
106
SysmlElementChooserDialog_SelectModelElementTitle=Select model element
107
SysmlModelingAssistantProviderTitle=Select domain model element
108
SysmlModelingAssistantProviderMessage=Available domain model elements:
109
ConstraintProperty1CreationTool_title=ConstraintProperty
110
ConstraintProperty1CreationTool_desc=Create new ConstraintProperty
111
Property2CreationTool_title=Property
112
Property2CreationTool_desc=Create new Property
113
AbstractParser_UnexpectedValueType=Value of type {0} is expected
114
AbstractParser_WrongStringConversion=String value does not convert to {0} value
115
AbstractParser_UnknownLiteral=Unknown literal: {0}
116
MessageFormatParser_InvalidInputError=Invalid input at {0}
117
Parametric1Group_title=Parametric
118
Connector3CreationTool_title=Connector
119
Connector3CreationTool_desc=Create new Connector
120
NavigatorGroupName_Resource_1000_links=links
121
NavigatorGroupName_Property_2005_incominglinks=incoming links
122
NavigatorGroupName_Property_2005_outgoinglinks=outgoing links
123
NavigatorGroupName_Property_3002_incominglinks=incoming links
124
NavigatorGroupName_Property_3002_outgoinglinks=outgoing links
125
NavigatorGroupName_Connector_4001_target=target
126
NavigatorGroupName_Connector_4001_source=source
127
createParametric1Group_title=Parametric
128
createConstraintProperty1CreationTool_title=ConstraintProperty
129
createConstraintProperty1CreationTool_desc=Create new ConstraintProperty
130
createProperty2CreationTool_title=Property
131
createProperty2CreationTool_desc=Create new Property
132
createConnector3CreationTool_title=Connector
133
createConnector3CreationTool_desc=Create new Connector
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/model/Parametric.gmfgen (-559 lines)
Lines 1-559 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<xmi:XMI xmi:version="2.0"
3
    xmlns:xmi="http://www.omg.org/XMI"
4
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
    xmlns:gmfgen="http://www.eclipse.org/gmf/2009/GenModel"
6
    xmlns:papyrusgmfgenextension="http://www.eclipse.org/papyrus/2009/papyrusgmfgenextension">
7
  <gmfgen:GenEditorGenerator
8
      packageNamePrefix="org.eclipse.papyrus.sysml.diagram.parametric"
9
      modelID="Parametric"
10
      dynamicTemplates="true"
11
      templateDirectory="/org.eclipse.papyrus.def/dynamic-templates3.5/codegen">
12
    <audits>
13
      <categories
14
          id="org.eclipse.uml2.uml.util.UMLValidator.validate"
15
          name="validateSysMLModel"
16
          description="Validate the SysML model"
17
          path="/0/@audits/@categories.0"/>
18
      <categories
19
          id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement"
20
          name="validateConnectorElement"
21
          description="validate a connector checking that its children are consistent"
22
          path="/0/@audits/@categories.0 /0/@audits/@categories.1"
23
          audits="/0/@audits/@rules.0 /0/@audits/@rules.1 /0/@audits/@rules.2 /0/@audits/@rules.3"/>
24
      <rules
25
          name="validateConnector"
26
          description="The NestedConnectorEnd stereotype of UML ConnectorEnd extends a UML ConnectorEnd so that the connected property"
27
          id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateConnector"
28
          rule="/0/@expressionProviders/@providers.0/@expressions.0"
29
          message="NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector."
30
          severity="WARNING"
31
          useInLiveMode="true"
32
          category="/0/@audits/@categories.1">
33
        <target
34
            xsi:type="gmfgen:GenDomainElementTarget"
35
            contextSelector="/0/@audits/@clientContexts.0">
36
          <element
37
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/Connector"/>
38
        </target>
39
      </rules>
40
      <rules
41
          name="validateProperty"
42
          description="When you move a property, check that its incoming or outgoings connector get consistent connectorEnd"
43
          id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateProperty"
44
          rule="/0/@expressionProviders/@providers.0/@expressions.1"
45
          message="NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector."
46
          severity="WARNING"
47
          useInLiveMode="true"
48
          category="/0/@audits/@categories.1">
49
        <target
50
            xsi:type="gmfgen:GenDomainElementTarget"
51
            contextSelector="/0/@audits/@clientContexts.0">
52
          <element
53
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/Property"/>
54
        </target>
55
      </rules>
56
      <rules
57
          name="validateConnectorEnd"
58
          description="The NestedConnectorEnd stereotype of UML ConnectorEnd extends a UML ConnectorEnd so that the connected property"
59
          id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateConnectorEnd"
60
          rule="/0/@expressionProviders/@providers.0/@expressions.2"
61
          message="NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector."
62
          severity="WARNING"
63
          useInLiveMode="true"
64
          category="/0/@audits/@categories.1">
65
        <target
66
            xsi:type="gmfgen:GenDomainElementTarget"
67
            contextSelector="/0/@audits/@clientContexts.0">
68
          <element
69
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/ConnectorEnd"/>
70
        </target>
71
      </rules>
72
      <rules
73
          name="validateNestedConnectorEnd"
74
          description="The NestedConnectorEnd stereotype of UML ConnectorEnd extends a UML ConnectorEnd so that the connected property"
75
          id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateNestedConnectorEnd"
76
          rule="/0/@expressionProviders/@providers.0/@expressions.3"
77
          message="NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector."
78
          severity="WARNING"
79
          useInLiveMode="true"
80
          category="/0/@audits/@categories.1">
81
        <target
82
            xsi:type="gmfgen:GenDomainElementTarget"
83
            contextSelector="/0/@audits/@clientContexts.0">
84
          <element
85
              href="../../org.eclipse.papyrus.sysml/model/sysml.genmodel#//sysml/blocks/NestedConnectorEnd"/>
86
        </target>
87
      </rules>
88
      <clientContexts
89
          ruleTargets="/0/@audits/@rules.0/@target /0/@audits/@rules.1/@target /0/@audits/@rules.2/@target /0/@audits/@rules.3/@target"/>
90
    </audits>
91
    <diagram
92
        visualID="1000"
93
        editPartClassName="ParametricEditPart"
94
        itemSemanticEditPolicyClassName="ParametricItemSemanticEditPolicy"
95
        canonicalEditPolicyClassName="ParametricCanonicalEditPolicy"
96
        iconProviderPriority="Low"
97
        validationProviderPriority="Low">
98
      <diagramRunTimeClass
99
          href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Diagram"/>
100
      <elementType
101
          xsi:type="gmfgen:MetamodelType"
102
          editHelperClassName="ResourceEditHelper"/>
103
      <viewmap
104
          xsi:type="gmfgen:FigureViewmap"
105
          figureQualifiedClassName="org.eclipse.draw2d.FreeformLayer"/>
106
      <behaviour
107
          xsi:type="gmfgen:CustomBehaviour"
108
          key="EditPolicyRoles.DRAG_DROP_ROLE"
109
          editPolicyQualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.CustomDiagramDragDropEditPolicy"/>
110
      <domainDiagramElement
111
          href="../../../plugin/org.eclipse.papyrus.infra.core.resource/model/resource.genmodel#//resource/Resource"/>
112
      <childNodes
113
          xsi:type="gmfgen:GenChildSideAffixedNode"
114
          visualID="3002"
115
          editPartClassName="Property2EditPart"
116
          itemSemanticEditPolicyClassName="Property2ItemSemanticEditPolicy"
117
          notationViewFactoryClassName="PropertyViewFactory"
118
          canonicalEditPolicyClassName="Property2CanonicalEditPolicy"
119
          graphicalNodeEditPolicyClassName="Property2GraphicalNodeEditPolicy"
120
          createCommandClassName="Property2CreateCommand"
121
          containers="/0/@diagram/@topLevelNodes.0">
122
        <diagramRunTimeClass
123
            href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Node"/>
124
        <elementType
125
            xsi:type="gmfgen:MetamodelType"
126
            editHelperClassName="PropertyEditHelper"/>
127
        <viewmap
128
            xsi:type="gmfgen:InnerClassViewmap"
129
            className="ParameterDescriptor"
130
            classBody="&#xA;/**&#xA; * @generated&#xA; */&#xA;public class ParameterDescriptor extends org.eclipse.draw2d.RectangleFigure {&#xA;&#xA;&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;public ParameterDescriptor() {&#xA;&#x9;&#x9;&#x9;&#x9;this.setLineWidth(1);&#xA;this.setPreferredSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(16)&#xA;, getMapMode().DPtoLP(16)&#xA;));&#xA;&#x9;}&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private boolean myUseLocalCoordinates = false;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;protected boolean useLocalCoordinates() {&#xA;&#x9;&#x9;return myUseLocalCoordinates;&#xA;&#x9;}&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;protected void setUseLocalCoordinates(boolean useLocalCoordinates) {&#xA;&#x9;&#x9;myUseLocalCoordinates = useLocalCoordinates;&#xA;&#x9;}&#xA;&#xA;&#xA;&#xA;&#xA;&#xA;}&#xA;&#xA;">
131
          <attributes
132
              xsi:type="gmfgen:DefaultSizeAttributes"
133
              width="16"
134
              height="16"/>
135
        </viewmap>
136
        <behaviour
137
            xsi:type="gmfgen:OpenDiagramBehaviour"/>
138
        <behaviour
139
            xsi:type="gmfgen:CustomBehaviour"
140
            key="RequestConstants.REQ_DELETE"
141
            editPolicyQualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromDiagramEditPolicy"/>
142
        <behaviour
143
            xsi:type="gmfgen:CustomBehaviour"
144
            key="RequestConstants.REQ_SEMANTIC_WRAPPER"
145
            editPolicyQualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromModelEditPolicy"/>
146
        <modelFacet>
147
          <metaClass
148
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/Property"/>
149
          <containmentMetaFeature
150
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/StructuredClassifier/ownedAttribute"/>
151
          <childMetaFeature
152
              href="../../org.eclipse.papyrus.sysml/model/sysml.genmodel#//sysml/constraints/ConstraintProperty/base_Property"/>
153
        </modelFacet>
154
        <labels
155
            xsi:type="gmfgen:GenExternalNodeLabel"
156
            visualID="5003"
157
            editPartClassName="PropertyName2EditPart"
158
            itemSemanticEditPolicyClassName="PropertyName2ItemSemanticEditPolicy"
159
            notationViewFactoryClassName="PropertyNameViewFactory">
160
          <diagramRunTimeClass
161
              href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Node"/>
162
          <viewmap
163
              xsi:type="gmfgen:FigureViewmap"
164
              figureQualifiedClassName="org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel"/>
165
          <behaviour
166
              xsi:type="gmfgen:CustomBehaviour"
167
              key="RequestConstants.REQ_DELETE"
168
              editPolicyQualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromDiagramEditPolicy"/>
169
          <behaviour
170
              xsi:type="gmfgen:CustomBehaviour"
171
              key="RequestConstants.REQ_SEMANTIC_WRAPPER"
172
              editPolicyQualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromModelEditPolicy"/>
173
          <modelFacet
174
              xsi:type="gmfgen:FeatureLabelModelFacet"
175
              parser="/0/@labelParsers/@implementations.1">
176
            <metaFeatures
177
                href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/>
178
          </modelFacet>
179
        </labels>
180
      </childNodes>
181
      <topLevelNodes
182
          visualID="2003"
183
          editPartClassName="ConstraintPropertyEditPart"
184
          itemSemanticEditPolicyClassName="ConstraintPropertyItemSemanticEditPolicy"
185
          notationViewFactoryClassName="ConstraintPropertyViewFactory"
186
          canonicalEditPolicyClassName="ConstraintPropertyCanonicalEditPolicy"
187
          childNodes="/0/@diagram/@childNodes.0"
188
          graphicalNodeEditPolicyClassName="ConstraintPropertyGraphicalNodeEditPolicy"
189
          createCommandClassName="ConstraintPropertyCreateCommand">
190
        <diagramRunTimeClass
191
            href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Node"/>
192
        <elementType
193
            xsi:type="gmfgen:MetamodelType"
194
            editHelperClassName="ConstraintPropertyEditHelper"/>
195
        <viewmap
196
            xsi:type="gmfgen:InnerClassViewmap"
197
            className="ConstraintPropertyFigureDescriptor"
198
            classBody="&#xA;/**&#xA; * @generated&#xA; */&#xA;public class ConstraintPropertyFigureDescriptor extends org.eclipse.draw2d.RoundedRectangle {&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel fConstraintPropertyFigureLabel; &#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel fConstraintLabel; &#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;public ConstraintPropertyFigureDescriptor() {&#xA;&#x9;&#x9;&#xA;&#x9;org.eclipse.draw2d.GridLayout layoutThis = new org.eclipse.draw2d.GridLayout();&#xA;&#x9;layoutThis.numColumns = 1;&#xA;&#x9;layoutThis.makeColumnsEqualWidth = true;&#xA;&#x9;this.setLayoutManager(layoutThis);&#xA;&#xA;&#x9;&#x9;this.setCornerDimensions(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(25)&#xA;, getMapMode().DPtoLP(25)&#xA;));&#xA;this.setLineWidth(1);&#xA;this.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(200)&#xA;, getMapMode().DPtoLP(120)&#xA;));&#xA;&#x9;&#x9;createContents();&#xA;&#x9;}&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private void createContents(){&#xA;&#xA;&#xA;fConstraintPropertyFigureLabel = new org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel();&#xA;&#xA;&#xA;&#xA;&#xA;org.eclipse.draw2d.GridData constraintFConstraintPropertyFigureLabel = new org.eclipse.draw2d.GridData();&#xA;constraintFConstraintPropertyFigureLabel.verticalAlignment = org.eclipse.draw2d.GridData.END;&#xA;constraintFConstraintPropertyFigureLabel.horizontalAlignment = org.eclipse.draw2d.GridData.CENTER;&#xA;constraintFConstraintPropertyFigureLabel.horizontalIndent = 0;&#xA;constraintFConstraintPropertyFigureLabel.horizontalSpan = 1;&#xA;constraintFConstraintPropertyFigureLabel.verticalSpan = 1;&#xA;constraintFConstraintPropertyFigureLabel.grabExcessHorizontalSpace = true;&#xA;constraintFConstraintPropertyFigureLabel.grabExcessVerticalSpace = true;&#xA;this.add(fConstraintPropertyFigureLabel, constraintFConstraintPropertyFigureLabel);&#xA;&#xA;&#xA;&#xA;&#xA;fConstraintLabel = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel();&#xA;&#xA;&#xA;&#xA;&#xA;org.eclipse.draw2d.GridData constraintFConstraintLabel = new org.eclipse.draw2d.GridData();&#xA;constraintFConstraintLabel.verticalAlignment = org.eclipse.draw2d.GridData.BEGINNING;&#xA;constraintFConstraintLabel.horizontalAlignment = org.eclipse.draw2d.GridData.END;&#xA;constraintFConstraintLabel.horizontalIndent = 0;&#xA;constraintFConstraintLabel.horizontalSpan = 1;&#xA;constraintFConstraintLabel.verticalSpan = 1;&#xA;constraintFConstraintLabel.grabExcessHorizontalSpace = true;&#xA;constraintFConstraintLabel.grabExcessVerticalSpace = true;&#xA;this.add(fConstraintLabel, constraintFConstraintLabel);&#xA;&#xA;&#xA;&#xA;&#x9;}&#xA;&#xA;&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private boolean myUseLocalCoordinates = false;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;protected boolean useLocalCoordinates() {&#xA;&#x9;&#x9;return myUseLocalCoordinates;&#xA;&#x9;}&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;protected void setUseLocalCoordinates(boolean useLocalCoordinates) {&#xA;&#x9;&#x9;myUseLocalCoordinates = useLocalCoordinates;&#xA;&#x9;}&#xA;&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;public org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel getConstraintPropertyFigureLabel() {&#xA;&#x9;&#x9;return fConstraintPropertyFigureLabel;&#xA;&#x9;}&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;public org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel getConstraintLabel() {&#xA;&#x9;&#x9;return fConstraintLabel;&#xA;&#x9;}&#xA;&#xA;&#xA;}&#xA;&#xA;"/>
199
        <behaviour
200
            xsi:type="gmfgen:CustomBehaviour"
201
            key="RequestConstants.REQ_CREATE"
202
            editPolicyQualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.CreateParameterEditPolicy"/>
203
        <modelFacet>
204
          <metaClass
205
              href="../../org.eclipse.papyrus.sysml/model/sysml.genmodel#//sysml/constraints/ConstraintProperty"/>
206
          <containmentMetaFeature
207
              href="../../../plugin/org.eclipse.papyrus.infra.core.resource/model/resource.genmodel#//resource/Resource/eobjects"/>
208
          <childMetaFeature
209
              href="../../../plugin/org.eclipse.papyrus.infra.core.resource/model/resource.genmodel#//resource/Resource/eobjects"/>
210
        </modelFacet>
211
        <labels
212
            visualID="5001"
213
            editPartClassName="ConstraintPropertyNameEditPart"
214
            itemSemanticEditPolicyClassName="ConstraintPropertyNameItemSemanticEditPolicy"
215
            notationViewFactoryClassName="ConstraintPropertyLabelViewFactory"
216
            elementIcon="true">
217
          <diagramRunTimeClass
218
              href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Node"/>
219
          <viewmap
220
              xsi:type="gmfgen:ParentAssignedViewmap"
221
              getterName="getConstraintPropertyFigureLabel"
222
              figureQualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel"/>
223
          <modelFacet
224
              parser="/0/@labelParsers/@implementations.3"/>
225
        </labels>
226
        <labels
227
            visualID="5004"
228
            editPartClassName="ConstraintLabelEditPart"
229
            itemSemanticEditPolicyClassName="ConstraintLabelItemSemanticEditPolicy"
230
            notationViewFactoryClassName="ConstraintPropertyLabelViewFactory"
231
            elementIcon="true">
232
          <diagramRunTimeClass
233
              href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Node"/>
234
          <viewmap
235
              xsi:type="gmfgen:ParentAssignedViewmap"
236
              getterName="getConstraintLabel"
237
              figureQualifiedClassName="org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel"/>
238
          <behaviour
239
              xsi:type="gmfgen:CustomBehaviour"
240
              key="RequestConstants.REQ_SEMANTIC_WRAPPER"
241
              editPolicyQualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromModelEditPolicy"/>
242
          <modelFacet
243
              parser="/0/@labelParsers/@implementations.4"/>
244
        </labels>
245
      </topLevelNodes>
246
      <topLevelNodes
247
          visualID="2005"
248
          editPartClassName="PropertyEditPart"
249
          itemSemanticEditPolicyClassName="PropertyItemSemanticEditPolicy"
250
          notationViewFactoryClassName="PropertyViewFactory"
251
          canonicalEditPolicyClassName="PropertyCanonicalEditPolicy"
252
          graphicalNodeEditPolicyClassName="PropertyGraphicalNodeEditPolicy"
253
          createCommandClassName="PropertyCreateCommand">
254
        <diagramRunTimeClass
255
            href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Node"/>
256
        <elementType
257
            xsi:type="gmfgen:SpecializationType"
258
            metamodelType="/0/@diagram/@childNodes.0/@elementType"/>
259
        <viewmap
260
            xsi:type="gmfgen:InnerClassViewmap"
261
            className="PropertyFigure"
262
            classBody="&#xA;/**&#xA; * @generated&#xA; */&#xA;public class PropertyFigure extends org.eclipse.draw2d.RectangleFigure {&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel fPropertyFigureLabel; &#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;public PropertyFigure() {&#xA;&#x9;&#x9;&#xA;&#x9;org.eclipse.papyrus.uml.diagram.common.draw2d.CenterLayout layoutThis = new org.eclipse.papyrus.uml.diagram.common.draw2d.CenterLayout();&#xA;&#xA;&#xA;&#x9;this.setLayoutManager(layoutThis);&#xA;&#xA;&#x9;&#x9;this.setLineWidth(1);&#xA;this.setMinimumSize(new org.eclipse.draw2d.geometry.Dimension(getMapMode().DPtoLP(100)&#xA;, getMapMode().DPtoLP(40)&#xA;));&#xA;&#x9;&#x9;createContents();&#xA;&#x9;}&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private void createContents(){&#xA;&#xA;&#xA;fPropertyFigureLabel = new org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel();&#xA;&#xA;&#xA;&#xA;this.add(fPropertyFigureLabel);&#xA;&#xA;&#xA;&#x9;}&#xA;&#xA;&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private boolean myUseLocalCoordinates = false;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;protected boolean useLocalCoordinates() {&#xA;&#x9;&#x9;return myUseLocalCoordinates;&#xA;&#x9;}&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;protected void setUseLocalCoordinates(boolean useLocalCoordinates) {&#xA;&#x9;&#x9;myUseLocalCoordinates = useLocalCoordinates;&#xA;&#x9;}&#xA;&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;public org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel getPropertyFigureLabel() {&#xA;&#x9;&#x9;return fPropertyFigureLabel;&#xA;&#x9;}&#xA;&#xA;&#xA;}&#xA;&#xA;"/>
263
        <modelFacet>
264
          <metaClass
265
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/Property"/>
266
          <containmentMetaFeature
267
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/StructuredClassifier/ownedAttribute"/>
268
          <childMetaFeature
269
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/StructuredClassifier/ownedAttribute"/>
270
        </modelFacet>
271
        <labels
272
            visualID="5002"
273
            editPartClassName="PropertyNameEditPart"
274
            itemSemanticEditPolicyClassName="PropertyNameItemSemanticEditPolicy"
275
            notationViewFactoryClassName="PropertyNameViewFactory"
276
            elementIcon="true">
277
          <diagramRunTimeClass
278
              href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Node"/>
279
          <viewmap
280
              xsi:type="gmfgen:ParentAssignedViewmap"
281
              getterName="getPropertyFigureLabel"
282
              figureQualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel"/>
283
          <modelFacet
284
              xsi:type="gmfgen:FeatureLabelModelFacet"
285
              parser="/0/@labelParsers/@implementations.1">
286
            <metaFeatures
287
                href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/>
288
          </modelFacet>
289
        </labels>
290
      </topLevelNodes>
291
      <links
292
          visualID="4001"
293
          editPartClassName="ConnectorEditPart"
294
          itemSemanticEditPolicyClassName="ConnectorItemSemanticEditPolicy"
295
          notationViewFactoryClassName="ConnectorViewFactory"
296
          createCommandClassName="ConnectorCreateCommand"
297
          reorientCommandClassName="ConnectorReorientCommand">
298
        <diagramRunTimeClass
299
            href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Edge"/>
300
        <elementType
301
            xsi:type="gmfgen:MetamodelType"
302
            editHelperClassName="ConnectorEditHelper"/>
303
        <viewmap
304
            xsi:type="gmfgen:InnerClassViewmap"
305
            className="ConnectorFigure"
306
            classBody="&#xA;/**&#xA; * @generated&#xA; */&#xA;public class ConnectorFigure extends org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx {&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel fConnectorLabel; &#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;public ConnectorFigure() {&#xA;&#x9;&#x9;this.setLineWidth(1);&#xA;&#xA;&#x9;&#x9;createContents();&#xA;&#x9;}&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;private void createContents(){&#xA;&#xA;&#xA;fConnectorLabel = new org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel();&#xA;fConnectorLabel.setText(&quot;&quot;);&#xA;&#xA;this.add(fConnectorLabel);&#xA;&#xA;&#xA;&#x9;}&#xA;&#xA;&#xA;&#x9;/**&#xA;&#x9; * @generated&#xA;&#x9; */&#xA;&#x9;public org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel getConnectorLabel() {&#xA;&#x9;&#x9;return fConnectorLabel;&#xA;&#x9;}&#xA;&#xA;&#xA;}&#xA;&#xA;"/>
307
        <modelFacet
308
            xsi:type="gmfgen:TypeLinkModelFacet">
309
          <metaClass
310
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/Connector"/>
311
          <containmentMetaFeature
312
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/StructuredClassifier/ownedConnector"/>
313
          <childMetaFeature
314
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/StructuredClassifier/ownedConnector"/>
315
          <sourceMetaFeature
316
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/ConnectorEnd/role"/>
317
          <targetMetaFeature
318
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/ConnectorEnd/role"/>
319
        </modelFacet>
320
        <labels
321
            visualID="6001"
322
            editPartClassName="ConnectorNameEditPart"
323
            itemSemanticEditPolicyClassName="ConnectorNameItemSemanticEditPolicy"
324
            notationViewFactoryClassName="ConnectorNameViewFactory"
325
            elementIcon="true">
326
          <diagramRunTimeClass
327
              href="../../../plugin/org.eclipse.gmf.runtime.notation/model/notation.genmodel#//notation/Node"/>
328
          <viewmap
329
              xsi:type="gmfgen:ParentAssignedViewmap"
330
              getterName="getConnectorLabel"
331
              figureQualifiedClassName="org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel">
332
            <attributes
333
                xsi:type="gmfgen:LabelOffsetAttributes"
334
                y="40"/>
335
          </viewmap>
336
          <modelFacet
337
              xsi:type="gmfgen:FeatureLabelModelFacet"
338
              parser="/0/@labelParsers/@implementations.2">
339
            <metaFeatures
340
                href="../../../plugin/org.eclipse.uml2.uml/model/UML.genmodel#//uml/NamedElement/name"/>
341
          </modelFacet>
342
        </labels>
343
      </links>
344
      <palette>
345
        <groups
346
            title="Parametric"
347
            largeIconPath="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif"
348
            smallIconPath="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif">
349
          <entries
350
              xsi:type="gmfgen:ToolEntry"
351
              title="ConstraintProperty"
352
              description="Create new ConstraintProperty"
353
              largeIconPath="platform:/plugin/org.eclipse.papyrus.sysml.edit/icons/full/obj16/ConstraintProperty.gif"
354
              smallIconPath="platform:/plugin/org.eclipse.papyrus.sysml.edit/icons/full/obj16/ConstraintProperty.gif"
355
              genNodes="/0/@diagram/@topLevelNodes.0"/>
356
          <entries
357
              xsi:type="gmfgen:ToolEntry"
358
              title="Property"
359
              description="Create new Property"
360
              largeIconPath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif"
361
              smallIconPath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif"
362
              genNodes="/0/@diagram/@childNodes.0 /0/@diagram/@topLevelNodes.1"/>
363
          <entries
364
              xsi:type="gmfgen:ToolEntry"
365
              title="Connector"
366
              description="Create new Connector"
367
              smallIconPath="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Connector.gif"
368
              genLinks="/0/@diagram/@links.0"/>
369
        </groups>
370
      </palette>
371
      <preferencePages
372
          xsi:type="gmfgen:GenStandardPreferencePage"
373
          iD="org.eclipse.papyrus.sysml.diagram.general"
374
          name="Sysml Diagram">
375
        <children
376
            xsi:type="gmfgen:GenStandardPreferencePage"
377
            iD="org.eclipse.papyrus.sysml.diagram.appearance"
378
            name="Appearance"
379
            kind="Appearance"/>
380
        <children
381
            xsi:type="gmfgen:GenStandardPreferencePage"
382
            iD="org.eclipse.papyrus.sysml.diagram.connections"
383
            name="Connections"
384
            kind="Connections"/>
385
        <children
386
            xsi:type="gmfgen:GenStandardPreferencePage"
387
            iD="org.eclipse.papyrus.sysml.diagram.printing"
388
            name="Printing"
389
            kind="Printing"/>
390
        <children
391
            xsi:type="gmfgen:GenStandardPreferencePage"
392
            iD="org.eclipse.papyrus.sysml.diagram.rulersAndGrid"
393
            name="Rulers And Grid"
394
            kind="RulersAndGrid"/>
395
      </preferencePages>
396
    </diagram>
397
    <plugin
398
        iD="org.eclipse.papyrus.sysml.diagram.parametric"
399
        name="Sysml Parametric diagram Plugin"
400
        provider="Eclipse.org"
401
        version="0.9.0.qualifier">
402
      <requiredPlugins>org.eclipse.draw2d</requiredPlugins>
403
      <requiredPlugins>org.eclipse.gmf.runtime.draw2d.ui</requiredPlugins>
404
    </plugin>
405
    <editor/>
406
    <navigator>
407
      <childReferences
408
          child="/0/@diagram"/>
409
      <childReferences
410
          parent="/0/@diagram/@topLevelNodes.0"
411
          child="/0/@diagram/@childNodes.0"/>
412
      <childReferences
413
          parent="/0/@diagram"
414
          child="/0/@diagram/@topLevelNodes.0"/>
415
      <childReferences
416
          parent="/0/@diagram"
417
          child="/0/@diagram/@topLevelNodes.1"/>
418
      <childReferences
419
          parent="/0/@diagram"
420
          child="/0/@diagram/@links.0"
421
          groupName="links"
422
          groupIcon="icons/linksNavigatorGroup.gif"/>
423
      <childReferences
424
          parent="/0/@diagram/@links.0"
425
          child="/0/@diagram/@topLevelNodes.1"
426
          referenceType="out_target"
427
          groupName="target"
428
          groupIcon="icons/linkTargetNavigatorGroup.gif"/>
429
      <childReferences
430
          parent="/0/@diagram/@topLevelNodes.1"
431
          child="/0/@diagram/@links.0"
432
          referenceType="in_source"
433
          groupName="incoming links"
434
          groupIcon="icons/incomingLinksNavigatorGroup.gif"/>
435
      <childReferences
436
          parent="/0/@diagram/@links.0"
437
          child="/0/@diagram/@childNodes.0"
438
          referenceType="out_target"
439
          groupName="target"
440
          groupIcon="icons/linkTargetNavigatorGroup.gif"/>
441
      <childReferences
442
          parent="/0/@diagram/@childNodes.0"
443
          child="/0/@diagram/@links.0"
444
          referenceType="in_source"
445
          groupName="incoming links"
446
          groupIcon="icons/incomingLinksNavigatorGroup.gif"/>
447
      <childReferences
448
          parent="/0/@diagram/@links.0"
449
          child="/0/@diagram/@topLevelNodes.1"
450
          referenceType="in_source"
451
          groupName="source"
452
          groupIcon="icons/linkSourceNavigatorGroup.gif"/>
453
      <childReferences
454
          parent="/0/@diagram/@topLevelNodes.1"
455
          child="/0/@diagram/@links.0"
456
          referenceType="out_target"
457
          groupName="outgoing links"
458
          groupIcon="icons/outgoingLinksNavigatorGroup.gif"/>
459
      <childReferences
460
          parent="/0/@diagram/@links.0"
461
          child="/0/@diagram/@childNodes.0"
462
          referenceType="in_source"
463
          groupName="source"
464
          groupIcon="icons/linkSourceNavigatorGroup.gif"/>
465
      <childReferences
466
          parent="/0/@diagram/@childNodes.0"
467
          child="/0/@diagram/@links.0"
468
          referenceType="out_target"
469
          groupName="outgoing links"
470
          groupIcon="icons/outgoingLinksNavigatorGroup.gif"/>
471
    </navigator>
472
    <diagramUpdater/>
473
    <propertySheet>
474
      <tabs
475
          xsi:type="gmfgen:GenStandardPropertyTab"
476
          iD="appearance"/>
477
      <tabs
478
          xsi:type="gmfgen:GenStandardPropertyTab"
479
          iD="diagram"/>
480
      <tabs
481
          xsi:type="gmfgen:GenCustomPropertyTab"
482
          iD="domain"
483
          label="Core">
484
        <filter
485
            xsi:type="gmfgen:TypeTabFilter">
486
          <types>org.eclipse.gmf.runtime.notation.View</types>
487
          <types>org.eclipse.gef.EditPart</types>
488
          <generatedTypes>abstractNavigatorItem</generatedTypes>
489
        </filter>
490
      </tabs>
491
    </propertySheet>
492
    <domainGenModel
493
        href="../../org.eclipse.papyrus.sysml/model/sysml.genmodel#/"/>
494
    <expressionProviders>
495
      <providers
496
          xsi:type="gmfgen:GenJavaExpressionProvider"
497
          injectExpressionBody="true">
498
        <expressions
499
            xsi:type="gmfgen:GenConstraint"
500
            body="return ModelValidationHelper.validateConnector(context, ctx);"/>
501
        <expressions
502
            xsi:type="gmfgen:GenConstraint"
503
            body="return ModelValidationHelper.validateProperty(context, ctx);"/>
504
        <expressions
505
            xsi:type="gmfgen:GenConstraint"
506
            body="return ModelValidationHelper.validateConnectorEnd(context, ctx);"/>
507
        <expressions
508
            xsi:type="gmfgen:GenConstraint"
509
            body="return ModelValidationHelper.validateNestedConnectorEnd(context, ctx);"/>
510
      </providers>
511
    </expressionProviders>
512
    <labelParsers
513
        extensibleViaService="true">
514
      <implementations
515
          xsi:type="gmfgen:PredefinedParser"/>
516
      <implementations
517
          xsi:type="gmfgen:CustomParser"
518
          uses="/0/@diagram/@topLevelNodes.1/@labels.0/@modelFacet /0/@diagram/@childNodes.0/@labels.0/@modelFacet"
519
          qualifiedName="org.eclipse.papyrus.sysml.diagram.parametric.parsers.PropertyLabelParser"/>
520
      <implementations
521
          xsi:type="gmfgen:CustomParser"
522
          uses="/0/@diagram/@links.0/@labels.0/@modelFacet"
523
          qualifiedName="org.eclipse.papyrus.sysml.diagram.parametric.parsers.ConnectorLabelParser"/>
524
      <implementations
525
          xsi:type="gmfgen:CustomParser"
526
          uses="/0/@diagram/@topLevelNodes.0/@labels.0/@modelFacet"
527
          qualifiedName="org.eclipse.papyrus.sysml.diagram.parametric.parsers.ConstraintPropertyLabelParser"/>
528
      <implementations
529
          xsi:type="gmfgen:CustomParser"
530
          uses="/0/@diagram/@topLevelNodes.0/@labels.1/@modelFacet"
531
          qualifiedName="org.eclipse.papyrus.sysml.diagram.parametric.parsers.ConstraintLabelParser"/>
532
    </labelParsers>
533
    <contextMenus
534
        context="/0/@diagram">
535
      <items
536
          xsi:type="gmfgen:LoadResourceAction"/>
537
    </contextMenus>
538
  </gmfgen:GenEditorGenerator>
539
  <papyrusgmfgenextension:PapyrusExtensionRootNode>
540
    <extensionNodes
541
        xsi:type="papyrusgmfgenextension:SpecificLocator"
542
        comment="Affixed Parameter locator"
543
        classpath="org.eclipse.papyrus.sysml.diagram.parametric.locator.ParameterPositionLocator"
544
        genChildSideAffixedNode="/0/@diagram/@childNodes.0"/>
545
    <extensionNodes
546
        xsi:type="papyrusgmfgenextension:LabelVisibilityPreference"
547
        comment="HiddenName"
548
        role="Name"
549
        iconPathRole="platform:/plugin/org.eclipse.papyrus.uml.diagram.common/icons/label_role/name.png"
550
        linkLabels="/0/@diagram/@links.0/@labels.0"
551
        visibleByDefault="false"/>
552
    <extensionNodes
553
        xsi:type="papyrusgmfgenextension:ExtendedGenView"
554
        comment=""
555
        genView="/0/@diagram/@links.0"
556
        name="ExtendedUMLLinks"
557
        superOwnedEditPart="org.eclipse.papyrus.uml.diagram.common.editparts.UMLConnectionNodeEditPart"/>
558
  </papyrusgmfgenextension:PapyrusExtensionRootNode>
559
</xmi:XMI>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/model/Parametric.gmfgraph (-147 lines)
Lines 1-147 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<gmfgraph:Canvas xmi:version="2.0"
3
    xmlns:xmi="http://www.omg.org/XMI"
4
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
    xmlns:gmfgraph="http://www.eclipse.org/gmf/2006/GraphicalDefinition" name="sysml">
6
  <figures
7
      name="Default">
8
    <descriptors
9
        name="ConstraintPropertyFigureDescriptor">
10
      <actualFigure
11
          xsi:type="gmfgraph:RoundedRectangle"
12
          name="ConstraintPropertyFigure"
13
          cornerWidth="25"
14
          cornerHeight="25">
15
        <layout
16
            xsi:type="gmfgraph:GridLayout"/>
17
        <minimumSize
18
            dx="200"
19
            dy="120"/>
20
        <children
21
            xsi:type="gmfgraph:CustomFigure"
22
            name="ConstraintPropertyFigureLabel"
23
            qualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel">
24
          <layoutData
25
              xsi:type="gmfgraph:GridLayoutData"
26
              grabExcessHorizontalSpace="true"
27
              grabExcessVerticalSpace="true"
28
              verticalAlignment="END"/>
29
        </children>
30
        <children
31
            xsi:type="gmfgraph:CustomFigure"
32
            name="ConstraintLabel"
33
            qualifiedClassName="org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel">
34
          <layoutData
35
              xsi:type="gmfgraph:GridLayoutData"
36
              grabExcessHorizontalSpace="true"
37
              grabExcessVerticalSpace="true"
38
              verticalAlignment="BEGINNING"
39
              horizontalAlignment="END"/>
40
        </children>
41
      </actualFigure>
42
      <accessors
43
          accessor="getConstraintPropertyFigureLabel"
44
          figure="//@figures.0/@descriptors.0/@actualFigure/@children.0"/>
45
      <accessors
46
          accessor="getConstraintLabel"
47
          figure="//@figures.0/@descriptors.0/@actualFigure/@children.1"/>
48
    </descriptors>
49
    <descriptors
50
        name="PropertyFigure">
51
      <actualFigure
52
          xsi:type="gmfgraph:Rectangle"
53
          name="PropertyFigure">
54
        <layout
55
            xsi:type="gmfgraph:CustomLayout"
56
            qualifiedClassName="org.eclipse.papyrus.uml.diagram.common.draw2d.CenterLayout"/>
57
        <minimumSize
58
            dx="100"
59
            dy="40"/>
60
        <children
61
            xsi:type="gmfgraph:CustomFigure"
62
            name="PropertyFigureLabel"
63
            qualifiedClassName="org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel"/>
64
      </actualFigure>
65
      <accessors
66
          accessor="getPropertyFigureLabel"
67
          figure="//@figures.0/@descriptors.1/@actualFigure/@children.0"/>
68
    </descriptors>
69
    <descriptors
70
        name="ParameterDescriptor">
71
      <actualFigure
72
          xsi:type="gmfgraph:Rectangle"
73
          name="ParameterRectangle">
74
        <preferredSize
75
            dx="16"
76
            dy="16"/>
77
      </actualFigure>
78
    </descriptors>
79
    <descriptors
80
        name="ParameterLabelFigure">
81
      <actualFigure
82
          xsi:type="gmfgraph:Label"
83
          name="ParameterLabel"/>
84
    </descriptors>
85
    <descriptors
86
        name="ConnectorFigure">
87
      <actualFigure
88
          xsi:type="gmfgraph:PolylineConnection"
89
          name="ConnectorPolylineConnection">
90
        <children
91
            xsi:type="gmfgraph:Label"
92
            name="ConnectorLabel"/>
93
      </actualFigure>
94
      <accessors
95
          accessor="getConnectorLabel"
96
          figure="//@figures.0/@descriptors.4/@actualFigure/@children.0"/>
97
    </descriptors>
98
  </figures>
99
  <nodes
100
      name="NodeConstraintProperty"
101
      figure="ConstraintPropertyFigureDescriptor"/>
102
  <nodes
103
      name="NodeProperty"
104
      figure="PropertyFigure"/>
105
  <nodes
106
      name="ParameterNode"
107
      figure="ParameterDescriptor"
108
      affixedParentSide="NSEW"/>
109
  <connections
110
      name="ConnectorConnection"
111
      figure="ConnectorFigure"/>
112
  <labels
113
      name="Property"
114
      figure="PropertyFigure"
115
      accessor="//@figures.0/@descriptors.1/@accessors.0">
116
    <facets
117
        xsi:type="gmfgraph:AlignmentFacet"
118
        alignment="CENTER"/>
119
  </labels>
120
  <labels
121
      name="ConstraintProperty"
122
      figure="ConstraintPropertyFigureDescriptor"
123
      accessor="//@figures.0/@descriptors.0/@accessors.0">
124
    <facets
125
        xsi:type="gmfgraph:AlignmentFacet"
126
        alignment="CENTER"/>
127
  </labels>
128
  <labels
129
      name="ParameterLabel"
130
      figure="ParameterLabelFigure"
131
      elementIcon="false">
132
    <facets
133
        xsi:type="gmfgraph:AlignmentFacet"/>
134
  </labels>
135
  <labels
136
      name="ConnectorDiagramLabel"
137
      figure="ConnectorFigure"
138
      accessor="//@figures.0/@descriptors.4/@accessors.0"/>
139
  <labels
140
      name="ConstraintLabel"
141
      figure="ConstraintPropertyFigureDescriptor"
142
      accessor="//@figures.0/@descriptors.0/@accessors.1">
143
    <facets
144
        xsi:type="gmfgraph:AlignmentFacet"
145
        alignment="END"/>
146
  </labels>
147
</gmfgraph:Canvas>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/model/Parametric.gmfmap (-182 lines)
Lines 1-182 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<gmfmap:Mapping xmi:version="2.0"
3
    xmlns:xmi="http://www.omg.org/XMI"
4
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
6
    xmlns:gmfmap="http://www.eclipse.org/gmf/2008/mappings"
7
    xmlns:gmftool="http://www.eclipse.org/gmf/2005/ToolDefinition">
8
  <nodes>
9
    <containmentFeature
10
        href="../../../plugin/org.eclipse.papyrus.infra.core.resource/model/resource.ecore#//Resource/eobjects"/>
11
    <ownedChild>
12
      <domainMetaElement
13
          href="../../org.eclipse.papyrus.sysml.converted/model/sysml.ecore#//constraints/ConstraintProperty"/>
14
      <labelMappings>
15
        <diagramLabel
16
            href="Parametric.gmfgraph#ConstraintProperty"/>
17
      </labelMappings>
18
      <labelMappings>
19
        <diagramLabel
20
            href="Parametric.gmfgraph#ConstraintLabel"/>
21
      </labelMappings>
22
      <tool
23
          xsi:type="gmftool:CreationTool"
24
          href="Parametric.gmftool#//@palette/@tools.0/@tools.0"/>
25
      <diagramNode
26
          href="Parametric.gmfgraph#NodeConstraintProperty"/>
27
      <children
28
          referencedChild="//@nodes.0/@ownedChild/@children.0/@ownedChild">
29
        <containmentFeature
30
            href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//StructuredClassifier/ownedAttribute"/>
31
        <childrenFeature
32
            href="../../org.eclipse.papyrus.sysml.converted/model/sysml.ecore#//constraints/ConstraintProperty/base_Property"/>
33
        <ownedChild
34
            relatedDiagrams="//@diagram">
35
          <domainMetaElement
36
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//Property"/>
37
          <labelMappings
38
              xsi:type="gmfmap:FeatureLabelMapping">
39
            <diagramLabel
40
                href="Parametric.gmfgraph#ParameterLabel"/>
41
            <features
42
                href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//NamedElement/name"/>
43
          </labelMappings>
44
          <tool
45
              xsi:type="gmftool:CreationTool"
46
              href="Parametric.gmftool#//@palette/@tools.0/@tools.1"/>
47
          <diagramNode
48
              href="Parametric.gmfgraph#ParameterNode"/>
49
        </ownedChild>
50
      </children>
51
    </ownedChild>
52
  </nodes>
53
  <nodes>
54
    <containmentFeature
55
        href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//StructuredClassifier/ownedAttribute"/>
56
    <ownedChild>
57
      <domainMetaElement
58
          href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//Property"/>
59
      <labelMappings
60
          xsi:type="gmfmap:FeatureLabelMapping">
61
        <diagramLabel
62
            href="Parametric.gmfgraph#Property"/>
63
        <features
64
            href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//NamedElement/name"/>
65
      </labelMappings>
66
      <tool
67
          xsi:type="gmftool:CreationTool"
68
          href="Parametric.gmftool#//@palette/@tools.0/@tools.1"/>
69
      <diagramNode
70
          href="Parametric.gmfgraph#NodeProperty"/>
71
    </ownedChild>
72
  </nodes>
73
  <links
74
      relatedDiagrams="//@diagram">
75
    <domainMetaElement
76
        href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//Connector"/>
77
    <labelMappings
78
        xsi:type="gmfmap:FeatureLabelMapping">
79
      <diagramLabel
80
          href="Parametric.gmfgraph#ConnectorDiagramLabel"/>
81
      <features
82
          href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//NamedElement/name"/>
83
    </labelMappings>
84
    <containmentFeature
85
        href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//StructuredClassifier/ownedConnector"/>
86
    <tool
87
        xsi:type="gmftool:CreationTool"
88
        href="Parametric.gmftool#//@palette/@tools.0/@tools.2"/>
89
    <diagramLink
90
        href="Parametric.gmfgraph#ConnectorConnection"/>
91
    <sourceMetaFeature
92
        xsi:type="ecore:EReference"
93
        href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//ConnectorEnd/role"/>
94
    <linkMetaFeature
95
        xsi:type="ecore:EReference"
96
        href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//ConnectorEnd/role"/>
97
  </links>
98
  <diagram>
99
    <diagramCanvas
100
        href="Parametric.gmfgraph#sysml"/>
101
    <domainModel
102
        href="../../org.eclipse.papyrus.sysml.converted/model/sysml.ecore#//blocks"/>
103
    <domainMetaElement
104
        href="../../../plugin/org.eclipse.papyrus.infra.core.resource/model/resource.ecore#//Resource"/>
105
    <palette
106
        href="Parametric.gmftool#//@palette"/>
107
  </diagram>
108
  <audits
109
      id="org.eclipse.uml2.uml.util.UMLValidator.validate"
110
      name="validateSysMLModel"
111
      description="Validate the SysML model">
112
    <childContainers
113
        id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement"
114
        name="validateConnectorElement"
115
        description="validate a connector checking that its children are consistent">
116
      <audits
117
          name="validateConnector"
118
          description="The NestedConnectorEnd stereotype of UML ConnectorEnd extends a UML ConnectorEnd so that the connected property"
119
          id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateConnector"
120
          severity="WARNING"
121
          useInLiveMode="true"
122
          message="NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector.">
123
        <rule
124
            body="return ModelValidationHelper.validateConnector(context, ctx);"
125
            language="java"/>
126
        <target
127
            xsi:type="gmfmap:DomainElementTarget">
128
          <element
129
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//Connector"/>
130
        </target>
131
      </audits>
132
      <audits
133
          name="validateProperty"
134
          description="When you move a property, check that its incoming or outgoings connector get consistent connectorEnd"
135
          id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateProperty"
136
          severity="WARNING"
137
          useInLiveMode="true"
138
          message="NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector.">
139
        <rule
140
            body="return ModelValidationHelper.validateProperty(context, ctx);"
141
            language="java"/>
142
        <target
143
            xsi:type="gmfmap:DomainElementTarget">
144
          <element
145
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//Property"/>
146
        </target>
147
      </audits>
148
      <audits
149
          name="validateConnectorEnd"
150
          description="The NestedConnectorEnd stereotype of UML ConnectorEnd extends a UML ConnectorEnd so that the connected property"
151
          id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateConnectorEnd"
152
          severity="WARNING"
153
          useInLiveMode="true"
154
          message="NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector.">
155
        <rule
156
            body="return ModelValidationHelper.validateConnectorEnd(context, ctx);"
157
            language="java"/>
158
        <target
159
            xsi:type="gmfmap:DomainElementTarget">
160
          <element
161
              href="../../../plugin/org.eclipse.uml2.uml/model/UML.ecore#//ConnectorEnd"/>
162
        </target>
163
      </audits>
164
      <audits
165
          name="validateNestedConnectorEnd"
166
          description="The NestedConnectorEnd stereotype of UML ConnectorEnd extends a UML ConnectorEnd so that the connected property"
167
          id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateNestedConnectorEnd"
168
          severity="WARNING"
169
          useInLiveMode="true"
170
          message="NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector.">
171
        <rule
172
            body="return ModelValidationHelper.validateNestedConnectorEnd(context, ctx);"
173
            language="java"/>
174
        <target
175
            xsi:type="gmfmap:DomainElementTarget">
176
          <element
177
              href="../../org.eclipse.papyrus.sysml.converted/model/sysml.ecore#//blocks/NestedConnectorEnd"/>
178
        </target>
179
      </audits>
180
    </childContainers>
181
  </audits>
182
</gmfmap:Mapping>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/model/Parametric.gmftool (-56 lines)
Lines 1-56 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<gmftool:ToolRegistry xmi:version="2.0"
3
    xmlns:xmi="http://www.omg.org/XMI"
4
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
    xmlns:gmftool="http://www.eclipse.org/gmf/2005/ToolDefinition">
6
  <palette
7
      title="sysmlPalette">
8
    <tools
9
        xsi:type="gmftool:ToolGroup"
10
        title="Parametric">
11
      <smallIcon
12
          xsi:type="gmftool:BundleImage"
13
          path="/icons/group.gif"
14
          bundle="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui"/>
15
      <largeIcon
16
          xsi:type="gmftool:BundleImage"
17
          path="/icons/group.gif"
18
          bundle="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui"/>
19
      <tools
20
          xsi:type="gmftool:CreationTool"
21
          title="ConstraintProperty"
22
          description="Create new ConstraintProperty">
23
        <smallIcon
24
            xsi:type="gmftool:BundleImage"
25
            path="/icons/full/obj16/ConstraintProperty.gif"
26
            bundle="platform:/plugin/org.eclipse.papyrus.sysml.edit"/>
27
        <largeIcon
28
            xsi:type="gmftool:BundleImage"
29
            path="/icons/full/obj16/ConstraintProperty.gif"
30
            bundle="platform:/plugin/org.eclipse.papyrus.sysml.edit"/>
31
      </tools>
32
      <tools
33
          xsi:type="gmftool:CreationTool"
34
          title="Property"
35
          description="Create new Property">
36
        <smallIcon
37
            xsi:type="gmftool:BundleImage"
38
            path="/icons/full/obj16/Property.gif"
39
            bundle="platform:/plugin/org.eclipse.uml2.uml.edit"/>
40
        <largeIcon
41
            xsi:type="gmftool:BundleImage"
42
            path="/icons/full/obj16/Property.gif"
43
            bundle="platform:/plugin/org.eclipse.uml2.uml.edit"/>
44
      </tools>
45
      <tools
46
          xsi:type="gmftool:CreationTool"
47
          title="Connector"
48
          description="Create new Connector">
49
        <smallIcon
50
            xsi:type="gmftool:BundleImage"
51
            path="/icons/full/obj16/Connector.gif"
52
            bundle="platform:/plugin/org.eclipse.uml2.uml.edit"/>
53
      </tools>
54
    </tools>
55
  </palette>
56
</gmftool:ToolRegistry>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/model/Parametric.trace (-36 lines)
Lines 1-36 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<trace:TraceModel xmi:version="2.0"
3
    xmlns:xmi="http://www.omg.org/XMI"
4
    xmlns:trace="http://www.eclipse.org/gmf/2006/Trace">
5
  <nodeTraces
6
      visualID="2003"
7
      queryText="(let _eClass_:ecore::EClass = modelFacet.metaClass.ecoreClass in _eClass_.ePackage.nsURI = 'http://www.eclipse.org/papyrus/0.7.0/SysML/Constraints' and _eClass_.name = 'ConstraintProperty') and (let _containmentMF_:ecore::EStructuralFeature = modelFacet.containmentMetaFeature.ecoreFeature in (let _eClass_:ecore::EClass = _containmentMF_.eContainingClass in _eClass_.ePackage.nsURI = 'http://www.eclipse.org/papyurs/0.7.0/Resource' and _eClass_.name = 'Resource') and _containmentMF_.name = 'eobjects')">
8
    <nodeLabelTraces
9
        visualID="5001"
10
        queryText="true"/>
11
    <nodeLabelTraces
12
        visualID="5004"
13
        queryText="true"/>
14
  </nodeTraces>
15
  <nodeTraces
16
      visualID="2005"
17
      queryText="(let _eClass_:ecore::EClass = modelFacet.metaClass.ecoreClass in _eClass_.ePackage.nsURI = 'http://www.eclipse.org/uml2/3.0.0/UML' and _eClass_.name = 'Property') and (let _containmentMF_:ecore::EStructuralFeature = modelFacet.containmentMetaFeature.ecoreFeature in (let _eClass_:ecore::EClass = _containmentMF_.eContainingClass in _eClass_.ePackage.nsURI = 'http://www.eclipse.org/uml2/3.0.0/UML' and _eClass_.name = 'StructuredClassifier') and _containmentMF_.name = 'ownedAttribute')">
18
    <nodeLabelTraces
19
        visualID="5002"
20
        queryText="true"/>
21
  </nodeTraces>
22
  <childNodeTraces
23
      visualID="3002"
24
      queryText="(let _eClass_:ecore::EClass = modelFacet.metaClass.ecoreClass in _eClass_.ePackage.nsURI = 'http://www.eclipse.org/uml2/3.0.0/UML' and _eClass_.name = 'Property') and (let _containmentMF_:ecore::EStructuralFeature = modelFacet.containmentMetaFeature.ecoreFeature in (let _eClass_:ecore::EClass = _containmentMF_.eContainingClass in _eClass_.ePackage.nsURI = 'http://www.eclipse.org/uml2/3.0.0/UML' and _eClass_.name = 'StructuredClassifier') and _containmentMF_.name = 'ownedAttribute') and ( let _childMF_:ecore::EStructuralFeature = modelFacet.childMetaFeature.ecoreFeature in (let _eClass_:ecore::EClass = _childMF_.eContainingClass in _eClass_.ePackage.nsURI = 'http://www.eclipse.org/papyrus/0.7.0/SysML/Constraints' and _eClass_.name = 'ConstraintProperty') and _childMF_.name = 'base_Property')">
25
    <nodeLabelTraces
26
        visualID="5003"
27
        queryText="true"/>
28
  </childNodeTraces>
29
  <linkTraces
30
      visualID="4001"
31
      queryText="modelFacet.oclIsKindOf(gmfgen::TypeLinkModelFacet) and (let _eClass_:ecore::EClass = modelFacet.oclAsType(gmfgen::TypeLinkModelFacet).metaClass.ecoreClass in _eClass_.ePackage.nsURI = 'http://www.eclipse.org/uml2/3.0.0/UML' and _eClass_.name = 'Connector')">
32
    <linkLabelTraces
33
        visualID="6001"
34
        queryText="true"/>
35
  </linkTraces>
36
</trace:TraceModel>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/model/SysML.Parametric.idgen (+124 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<idgen:Diagram xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gmfgen="http://www.eclipse.org/gmf/2009/GenModel" xmlns:idgen="http://www.eclipse.org/papyrus/0.7.0/idgen" name="Parametric" type="Parametric" icon="icons/obj16/Diagram_Parametric.gif" label="SysML Parametric Diagram" language="sysml" javaPackagePrefix="org.eclipse.papyrus.sysml.diagram.parametric" javaClassPrefix="ParametricDiagram" createCommandLabel="Create a new Parametric Diagram">
3
  <diagramEditPart name="Diagram edit part">
4
    <behaviors javaClassQualifiedName="org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy" key="DuplicatePasteEditPolicy.PASTE_ROLE"/>
5
    <behaviors javaClassQualifiedName="org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomDragDropEditPolicy" key="EditPolicyRoles.DRAG_DROP_ROLE"/>
6
    <behaviors javaClassQualifiedName="org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultXYLayoutEditPolicy" key="EditPolicy.LAYOUT_ROLE"/>
7
    <behaviors name="" javaClassQualifiedName="org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultCreationEditPolicy" key="EditPolicyRoles.CREATION_ROLE"/>
8
    <behaviors javaClassQualifiedName="org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultContainerNodeEditPolicy" key="EditPolicy.GRAPHICAL_NODE_ROLE"/>
9
  </diagramEditPart>
10
  <inheritedDiagrams name="CompositeDiagram" viewProviderClassQualifiedName="" editPartProviderClassQualifiedName="" dndEditPolicyClassQualifiedName="org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy">
11
    <genInheritedEditor href="../../org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen#CompositeStructure"/>
12
    <genNodes>
13
      <genNode xsi:type="gmfgen:GenTopLevelNode" href="../../org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen#/0/@diagram/@topLevelNodes.48"/>
14
      <semanticType href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#org.eclipse.papyrus.uml.Constraint"/>
15
    </genNodes>
16
    <genNodes generatePreferencePage="false" generateTool="false">
17
      <genNode xsi:type="gmfgen:GenChildNode" href="../../org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen#/0/@diagram/@childNodes.27"/>
18
      <semanticType href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#org.eclipse.papyrus.uml.Comment"/>
19
    </genNodes>
20
    <genNodes>
21
      <genNode xsi:type="gmfgen:GenTopLevelNode" href="../../org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen#/0/@diagram/@topLevelNodes.43"/>
22
      <semanticType href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#org.eclipse.papyrus.uml.Comment"/>
23
    </genNodes>
24
    <genNodes generatePreferencePage="false" generateTool="false">
25
      <genNode xsi:type="gmfgen:GenChildNode" href="../../org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen#/0/@diagram/@childNodes.32"/>
26
      <semanticType href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#org.eclipse.papyrus.uml.Constraint"/>
27
    </genNodes>
28
    <genLinks>
29
      <genLink href="../../org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen#/0/@diagram/@links.1"/>
30
    </genLinks>
31
    <genLinks>
32
      <genLink href="../../org.eclipse.papyrus.uml.diagram.composite/model/compositediagram.gmfgen#/0/@diagram/@links.2"/>
33
    </genLinks>
34
  </inheritedDiagrams>
35
  <customJavaClasses name="" customEditPolicyProvider="org.eclipse.papyrus.sysml.diagram.internalblock.CustomEditPolicyProvider" customPreferenceInitializer="org.eclipse.papyrus.sysml.diagram.parametric.preferences.CustomPreferenceInitializer"/>
36
  <usedCustomNodes href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_block_as_composite"/>
37
  <usedCustomNodes href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_blockproperty_as_composite"/>
38
  <usedCustomNodes href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_flowport_as_affixed"/>
39
  <usedCustomNodes href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#shape_uml_port_as_affixed"/>
40
  <usedCustomEdges href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#link_uml_connector"/>
41
  <usedCustomEdges href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#link_uml_dependency"/>
42
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#label_sysml_block_name"/>
43
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#affixedlabel_sysml_flowport_label"/>
44
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#affixedlabel_uml_appliedstereotype"/>
45
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#affixedlabel_uml_port_label"/>
46
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#compartment_sysml_structure"/>
47
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#compartment_sysml_blockproperty_structure"/>
48
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#label_uml_property_label"/>
49
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#linklabel_uml_appliedstereotype"/>
50
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#linklabel_uml_connector_label"/>
51
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#linklabel_uml_connector_source_multiplicity"/>
52
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#linklabel_uml_connector_target_multiplicity"/>
53
  <usedCustomDecorations href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#linklabel_uml_namedelement_name"/>
54
  <diagramConfig>
55
    <contains xsi:type="idgen:GraphicalTypeDiagramRef">
56
      <contains>
57
        <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_block_as_composite"/>
58
        <contains>
59
          <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_flowport_as_affixed"/>
60
        </contains>
61
        <contains>
62
          <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#shape_uml_port_as_affixed"/>
63
        </contains>
64
        <contains>
65
          <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#compartment_sysml_structure"/>
66
        </contains>
67
        <contains>
68
          <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_blockproperty_as_composite"/>
69
          <contains>
70
            <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_flowport_as_affixed"/>
71
          </contains>
72
          <contains>
73
            <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#shape_uml_port_as_affixed"/>
74
          </contains>
75
          <contains>
76
            <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#compartment_sysml_blockproperty_structure"/>
77
            <contains>
78
              <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_blockproperty_as_composite"/>
79
            </contains>
80
          </contains>
81
        </contains>
82
        <contains>
83
          <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_constraintblockproperty_as_composite"/>
84
          <contains>
85
            <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#shape_uml_property_as_label"/>
86
          </contains>
87
          <contains>
88
            <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#compartment_sysml_blockproperty_structure"/>
89
            <contains>
90
              <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_constraintblockproperty_as_composite"/>
91
            </contains>
92
            <contains>
93
              <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#label_uml_property_label"/>
94
            </contains>
95
          </contains>
96
        </contains>
97
      </contains>
98
      <contains>
99
        <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#link_uml_dependency"/>
100
      </contains>
101
      <contains>
102
        <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/UML.ReusableParts.idgen#link_uml_connector"/>
103
      </contains>
104
    </contains>
105
    <contains>
106
      <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#compartment_sysml_structure"/>
107
      <contains>
108
        <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_blockproperty_as_composite"/>
109
      </contains>
110
      <contains>
111
        <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_constraintblockproperty_as_composite"/>
112
      </contains>
113
    </contains>
114
    <contains>
115
      <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#compartment_sysml_blockproperty_structure"/>
116
      <contains>
117
        <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_blockproperty_as_composite"/>
118
      </contains>
119
      <contains>
120
        <ref href="../../org.eclipse.papyrus.sysml.diagram.common/model/SysML.ReusableParts.idgen#shape_sysml_constraintblockproperty_as_composite"/>
121
      </contains>
122
    </contains>
123
  </diagramConfig>
124
</idgen:Diagram>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/palettes/parametric.palette.xml (+41 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
<paletteDefinition>
3
	<content>
4
		<drawer id="parametric.drawer.nodes" name="Nodes" iconpath="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif">
5
			<aspectTool description="Create a new ConstraintProperty" id="parametric.tool.constraintblockpropertycomposite"
6
				name="ConstraintProperty" refToolId="parametric.tool.constraintblockpropertycomposite">
7
			</aspectTool>
8
			<aspectTool description="Create a new ConstraintParameter" id="parametric.tool.parameter"
9
				name="ConstraintParameter" refToolId="parametric.tool.parameter">
10
			</aspectTool>
11
			<aspectTool description="Create a new Part" id="parametric.tool.blockpropertycomposite"
12
				name="Part" refToolId="parametric.tool.blockpropertycomposite">
13
			</aspectTool>
14
			<aspectTool description="Create a new Reference" id="parametric.tool.reference"
15
				name="Reference" refToolId="parametric.tool.reference">
16
			</aspectTool>
17
			<aspectTool description="Create a new Value" id="parametric.tool.value"
18
				name="Value" refToolId="parametric.tool.value">
19
			</aspectTool>
20
		</drawer>
21
		<drawer id="parametric.drawer.edges" name="Edges" iconpath="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif">
22
			<aspectTool description="Create a new BindingConnector" id="parametric.tool.connector"
23
				name="BindingConnector" refToolId="parametric.tool.connector">
24
			</aspectTool>
25
		</drawer>
26
		<drawer id="parametric.drawer.others" name="Others" iconpath="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif">
27
			<aspectTool description="Create a new Dependency" id="parametric.tool.dependency"
28
				name="Dependency" refToolId="parametric.tool.dependency">
29
			</aspectTool>
30
			<aspectTool description="Create a new Comment" id="parametric.tool.comment"
31
				name="Comment" refToolId="parametric.tool.comment">
32
			</aspectTool>
33
			<aspectTool description="Create a new Constraint" id="parametric.tool.constraint"
34
				name="Constraint" refToolId="parametric.tool.constraint">
35
			</aspectTool>
36
			<aspectTool description="Create a new CommentAnnotatedElement" id="parametric.tool.commentannotatedelement"
37
				name="CommentAnnotatedElement" refToolId="parametric.tool.comment_constraint_link">
38
			</aspectTool>			
39
		</drawer>
40
	</content>
41
</paletteDefinition>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.properties (-58 / +11 lines)
Lines 1-59 Link Here
1
#/*****************************************************************************
1
#################################################################################
2
#* Copyright (c) 2009 Atos Origin.
2
# Copyright (c) 2010 CEA LIST.
3
# *
3
# All rights reserved. This program and the accompanying materials
4
# *    
4
# are made available under the terms of the Eclipse Public License v1.0
5
# * All rights reserved. This program and the accompanying materials
5
# which accompanies this distribution, and is available at
6
# * are made available under the terms of the Eclipse Public License v1.0
6
# http://www.eclipse.org/legal/epl-v10.html
7
# * which accompanies this distribution, and is available at
7
#
8
# * http://www.eclipse.org/legal/epl-v10.html
8
# Contributors:
9
# *
9
#     Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - initial API and implementation
10
# * Contributors:
10
##################################################################################
11
# *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
11
pluginName=SysML Parametric Diagram
12
# *
13
#  *****************************************************************************/
14
pluginName=Papyrus Paramatric Diagram for SysML (Incubation)
15
providerName=Eclipse Modeling Project
12
providerName=Eclipse Modeling Project
16
17
editorName=SysML Diagram Editing
18
context.description=SysML Diagram Editing
19
context.name=In SysML Diagram Editor
20
newWizardName=SysML Diagram
21
newWizardDesc=Creates SysML diagram.
22
23
initDiagramActionLabel=Initialize sysml_diagram diagram file
24
25
26
navigatorContentName=*.sysml_diagram diagram contents
27
domainNavigatorContentName=*.sysml model contents
28
update.diagram.name=Update SysML diagram
29
update.diagram.description=Perform SysML diagram update
30
31
32
# Property Sheet
33
tab.appearance=Appearance
34
tab.diagram=Rulers & Grid
35
tab.domain=Core
36
37
# Preferences
38
prefpage.org.eclipse.papyrus.sysml.diagram.general=SysML Diagram
39
prefpage.org.eclipse.papyrus.sysml.diagram.appearance=Appearance
40
prefpage.org.eclipse.papyrus.sysml.diagram.connections=Connections
41
prefpage.org.eclipse.papyrus.sysml.diagram.printing=Printing
42
prefpage.org.eclipse.papyrus.sysml.diagram.rulersAndGrid=Rulers And Grid
43
44
45
# Providers
46
metatype.name.Resource_1000=Undefined
47
metatype.name.ConstraintProperty_2001=ConstraintProperty
48
metatype.name.ConstraintBlock_2002=ConstraintBlock
49
50
# Commands and menu actions
51
cmdcategory.name=SysML Editor Commands
52
cmdcategory.desc=SysML Editor Commands
53
54
metatype.name.ConstraintProperty_2003=ConstraintProperty
55
metatype.name.ConstraintBlock_2004=ConstraintBlock
56
metatype.name.Property_2004=Property
57
metatype.name.Property_2005=Property
58
metatype.name.Property_3002=Property
59
metatype.name.Connector_4001=Connector
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/plugin.xml (-830 / +554 lines)
Lines 1-838 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
2
<?eclipse version="3.4"?>
3
<plugin>
3
<plugin>
4
	<extension point="org.eclipse.gmf.runtime.common.ui.services.action.contributionItemProviders">
5
      <contributionItemProvider checkPluginLoaded="false" class="org.eclipse.papyrus.sysml.diagram.parametric.providers.ParametricDiagramContributionItemProvider">
6
      <Priority name="Low"/>
7
         <popupContribution class="org.eclipse.gmf.runtime.diagram.ui.providers.DiagramContextMenuProvider">
8
            <popupStructuredContributionCriteria objectClass="org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart" policyClass="org.eclipse.papyrus.sysml.diagram.parametric.providers.ParametricDiagramContributionPolicyClass"/> 
9
            <popupAction id="papyrus.restoreRelatedLinksAction" path="/navigateMenu/additions"/>
10
         </popupContribution>
11
      </contributionItemProvider>
12
   </extension>
13
   
14
   
15
      
16
   <extension point="org.eclipse.ui.contexts" id="ui-context">
17
      <?gmfgen generated="true"?>
18
      <context
19
         description="%context.description"
20
         id="org.eclipse.papyrus.sysml.diagram.parametric.ui.diagramContext"
21
         name="%context.name"
22
         parentId="org.eclipse.gmf.runtime.diagram.ui.diagramContext">
23
      </context>
24
   </extension>
25
4
26
   
5
<!-- Diagram declaration -->
27
   <extension point="org.eclipse.ui.popupMenus" id="init-diagram-action">
6
<extension point="org.eclipse.papyrus.infra.core.papyrusDiagram">
28
      <?gmfgen generated="false"?>
7
	<creationCommand
29
       <!-- FIX Bug 314257-->
8
		creationCommandClass="org.eclipse.papyrus.sysml.diagram.parametric.ParametricDiagramCreateCommand"
30
      <!--objectContribution
9
		icon="icons/obj16/Diagram_Parametric.png"
31
            id="org.eclipse.papyrus.sysml.diagram.parametric.InitDiagram"
10
		id="org.eclipse.papyrus.sysml.diagram.parametric.CreateCommand"
32
            nameFilter="*.sysml"
11
		language="sysml"
33
            objectClass="org.eclipse.core.resources.IFile">
12
		label="SysML Parametric Diagram"/>
34
         <action
13
	<editorDiagram
35
               label="%initDiagramActionLabel"
14
		actionBarContributorId="org.eclipse.papyrus.uml.diagram.common.part.UMLDiagramActionBarContributor"
36
               class="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlInitDiagramFileAction"
15
		factoryClass="org.eclipse.papyrus.sysml.diagram.parametric.ParametricDiagramEditorFactory"
37
               menubarPath="additions"
16
		icon="icons/obj16/Diagram_Parametric.png" />
38
               enablesFor="1"
39
               id="org.eclipse.papyrus.sysml.diagram.parametric.InitDiagramAction">
40
         </action>
41
      </objectContribution-->
42
   </extension>
43
	
44
   
45
   <extension
46
		id="Sysml Plugin.palettedefinition"
47
		name="Sysml Plugin Predefined Entries"
48
		point="org.eclipse.gmf.runtime.diagram.ui.paletteProviders"> 
49
		
50
		<paletteProvider class="org.eclipse.gmf.runtime.diagram.ui.providers.DefaultPaletteProvider">
51
			<Priority name="Lowest"/>
52
      		<contribution
53
            	factoryClass="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlPaletteFactory">
54
     			<predefinedEntry id="standardGroup/noteStack/noteTool" remove="true"/> 
55
				<predefinedEntry id="standardGroup/noteStack/textTool" remove="true"/> 
56
				<predefinedEntry id="standardGroup/noteStack/noteattachmentTool" remove="true"/>
57
					<entry
58
       defineOnly="true"
59
       description="Create new Property"
60
       id="createProperty2CreationTool"
61
       kind="tool"
62
       label="Property"
63
       large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif"
64
       path=""
65
       small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif">
66
 	</entry>
67
	<entry
68
       defineOnly="true"
69
       description="Create new ConstraintProperty"
70
       id="createConstraintProperty1CreationTool"
71
       kind="tool"
72
       label="ConstraintProperty"
73
       large_icon="platform:/plugin/org.eclipse.papyrus.sysml.edit/icons/full/obj16/ConstraintProperty.gif"
74
       path=""
75
       small_icon="platform:/plugin/org.eclipse.papyrus.sysml.edit/icons/full/obj16/ConstraintProperty.gif">
76
 	</entry>
77
 <entry
78
       defineOnly="true"
79
       description="Create new Connector"
80
       id="createConnector3CreationTool"
81
       kind="tool"
82
       label="Connector"
83
       large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Connector.gif"
84
       small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Connector.gif">
85
 </entry>
86
87
			</contribution>
88
		</paletteProvider>	
89
			
90
	</extension>
91
	
92
		<extension
93
		id="Sysml Plugin.standard"
94
		name="Sysml Plugin Standard Palette"
95
		point="org.eclipse.gmf.runtime.diagram.ui.paletteProviders"> 
96
		
97
		<paletteProvider class="org.eclipse.gmf.runtime.diagram.ui.providers.DefaultPaletteProvider">
98
			<Priority name="Low"/>
99
      		<contribution
100
            	factoryClass="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlPaletteFactory">
101
     			<predefinedEntry id="standardGroup/noteStack/noteTool" remove="true"/> 
102
				<predefinedEntry id="standardGroup/noteStack/textTool" remove="true"/> 
103
				<predefinedEntry id="standardGroup/noteStack/noteattachmentTool" remove="true"/>
104
					<entry
105
       description=""
106
       id="createSysml1Group"
107
       kind="drawer"
108
       label="Parametric Diagram"
109
       large_icon="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif"
110
       path="/"
111
       small_icon="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif">
112
 	</entry>
113
 	 
114
 	 	<predefinedEntry
115
          id="createProperty2CreationTool"
116
          path="/createSysml1Group">
117
    </predefinedEntry>
118
 	<predefinedEntry
119
          id="createConstraintProperty1CreationTool"
120
          path="/createSysml1Group">
121
    </predefinedEntry>
122
  <predefinedEntry
123
        id="createConnector3CreationTool"
124
        path="/createSysml1Group">
125
  </predefinedEntry>
126
127
128
			</contribution>
129
			<editor id="org.eclipse.papyrus.sysml.diagram.parametric"/>
130
		</paletteProvider>	
131
			
132
	</extension>
133
   							
134
   <extension point="org.eclipse.ui.preferencePages" id="prefpages">
135
      <?gmfgen generated="true"?>
136
      <page
137
            id="org.eclipse.papyrus.infra.gmfdiag.preferences.diagrams.Parametric"
138
            name="Parametric Diagram"
139
            category="org.eclipse.papyrus.infra.gmfdiag.preferences.diagrams"
140
            class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.DiagramGeneralPreferencePage">
141
      </page>
142
      
143
144
145
      <page
146
            id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.DiagramPrintingPreferencePage"
147
            name="%prefpage.org.eclipse.papyrus.sysml.diagram.printing"
148
            category="org.eclipse.papyrus.infra.gmfdiag.preferences.diagrams.Parametric"
149
            class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.DiagramPrintingPreferencePage">
150
      </page>
151
152
      <page
153
            id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.DiagramRulersAndGridPreferencePage"
154
            name="%prefpage.org.eclipse.papyrus.sysml.diagram.rulersAndGrid"
155
            category="org.eclipse.papyrus.infra.gmfdiag.preferences.diagrams.Parametric"
156
            class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.DiagramRulersAndGridPreferencePage">
157
      </page>
158
159
   </extension>
160
161
   <extension point="org.eclipse.ui.views.properties.tabbed.propertyContributor" id="prop-contrib">
162
      <?gmfgen generated="true"?>
163
      <propertyContributor
164
            contributorId="org.eclipse.papyrus.sysml.diagram.parametric"
165
            labelProvider="org.eclipse.papyrus.sysml.diagram.parametric.sheet.SysmlSheetLabelProvider">
166
         <propertyCategory category="domain"/>
167
         <propertyCategory category="visual"/>
168
         <propertyCategory category="extra"/>
169
      </propertyContributor>
170
   </extension>
171
172
   <extension point="org.eclipse.ui.views.properties.tabbed.propertyTabs" id="proptabs">
173
      <?gmfgen generated="true"?>   
174
      <propertyTabs contributorId="org.eclipse.papyrus.sysml.diagram.parametric">
175
         <propertyTab
176
             category="visual"
177
             id="property.tab.AppearancePropertySection"
178
             label="%tab.appearance"/>
179
          <propertyTab
180
             category="visual"
181
             id="property.tab.DiagramPropertySection"
182
             label="%tab.diagram"/>
183
          <propertyTab
184
             category="domain"
185
             id="property.tab.domain"
186
             label="%tab.domain"/>
187
      </propertyTabs>
188
   </extension>
189
190
   <extension point="org.eclipse.ui.views.properties.tabbed.propertySections" id="propsections">
191
      <?gmfgen generated="true"?>   
192
      <propertySections contributorId="org.eclipse.papyrus.sysml.diagram.parametric">
193
         <propertySection id="property.section.ConnectorAppearancePropertySection" 
194
            filter="org.eclipse.gmf.runtime.diagram.ui.properties.filters.ConnectionEditPartPropertySectionFilter" 
195
            class="org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.ConnectionAppearancePropertySection" 
196
            tab="property.tab.AppearancePropertySection">
197
         </propertySection>
198
         <propertySection id="property.section.ShapeColorAndFontPropertySection" 
199
            filter="org.eclipse.gmf.runtime.diagram.ui.properties.filters.ShapeEditPartPropertySectionFilter" 
200
            class="org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.ShapeColorsAndFontsPropertySection" 
201
            tab="property.tab.AppearancePropertySection">
202
         </propertySection> 
203
         <propertySection id="property.section.DiagramColorsAndFontsPropertySection" 
204
            filter="org.eclipse.gmf.runtime.diagram.ui.properties.filters.DiagramEditPartPropertySectionFilter" 
205
            class="org.eclipse.gmf.runtime.diagram.ui.properties.sections.appearance.DiagramColorsAndFontsPropertySection" 
206
            tab="property.tab.AppearancePropertySection">
207
         </propertySection>     
208
         <propertySection id="property.section.RulerGridPropertySection" 
209
            filter="org.eclipse.gmf.runtime.diagram.ui.properties.filters.DiagramEditPartPropertySectionFilter" 
210
            class="org.eclipse.gmf.runtime.diagram.ui.properties.sections.grid.RulerGridPropertySection" 
211
            tab="property.tab.DiagramPropertySection">
212
         </propertySection>     
213
         <propertySection
214
            id="property.section.domain" 
215
            tab="property.tab.domain"
216
            class="org.eclipse.papyrus.sysml.diagram.parametric.sheet.SysmlPropertySection">
217
            <input type="org.eclipse.gmf.runtime.notation.View"/>
218
            <input type="org.eclipse.gef.EditPart"/>
219
            <input type="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlAbstractNavigatorItem"/>
220
         </propertySection>
221
      </propertySections>
222
   </extension>
223
224
225
<?gmfgen generated="true"?>
226
227
	<extension point="org.eclipse.core.runtime.preferences">
228
		<?gmfgen generated="true"?>
229
		<initializer class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.DiagramPreferenceInitializer"/>
230
	</extension>
231
232
   <extension point="org.eclipse.gmf.runtime.diagram.core.viewProviders" id="view-provider">
233
      <?gmfgen generated="true"?>
234
      <viewProvider class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlViewProvider">
235
         <Priority name="Lowest"/>
236
         <context viewClass="org.eclipse.gmf.runtime.notation.Diagram" semanticHints="Parametric"/>
237
         <context viewClass="org.eclipse.gmf.runtime.notation.Node" semanticHints="2003,2005,3002"/>
238
         <context viewClass="org.eclipse.gmf.runtime.notation.Edge" semanticHints="4001"/>
239
      </viewProvider>
240
   </extension>
241
242
   <extension point="org.eclipse.gmf.runtime.diagram.ui.editpartProviders" id="ep-provider">
243
      <?gmfgen generated="true"?>
244
      <editpartProvider class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlEditPartProvider">
245
         <Priority name="Lowest"/>
246
         <object class="org.eclipse.gmf.runtime.notation.Diagram" id="generated-diagram">
247
            <method name="getType()" value="Parametric"/>
248
         </object>
249
         <object class="org.eclipse.gmf.runtime.notation.Node" id="generated-nodes">
250
            <method name="getType()" value="2003,2005,3002"/>
251
         </object>
252
         <object class="org.eclipse.gmf.runtime.notation.Edge" id="generated-links">
253
            <method name="getType()" value="4001"/>
254
         </object>
255
         <object class="org.eclipse.gmf.runtime.notation.Node" id="generated-labels">
256
            <method name="getType()" value="5001,5004,5002,5003"/>
257
         </object>
258
         <object class="org.eclipse.gmf.runtime.notation.Node" id="generated-compartments">
259
            <method name="getType()" value=""/>
260
         </object>
261
         <context views="generated-diagram,generated-nodes,generated-links,generated-labels,generated-compartments"/>
262
      </editpartProvider>
263
   </extension>
264
265
   <extension point="org.eclipse.gmf.runtime.emf.ui.modelingAssistantProviders" id="modelassist-provider">
266
      <?gmfgen generated="true"?>
267
      <modelingAssistantProvider class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlModelingAssistantProvider">
268
         <Priority name="Lowest"/>
269
         <object class="org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart" id="Resource_1000"/>
270
         <object class="org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart" id="ConstraintProperty_2003"/>
271
         <object class="org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart" id="Property_2005"/>
272
         <context elements="Resource_1000,ConstraintProperty_2003,Property_2005"/>
273
      </modelingAssistantProvider>
274
   </extension>
275
276
   <extension point="org.eclipse.gmf.runtime.common.ui.services.iconProviders" id="icon-provider">
277
      <?gmfgen generated="true"?>
278
      <IconProvider class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlIconProvider">
279
         <Priority name="Low"/>
280
      </IconProvider>
281
   </extension>
282
283
   <extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypes" id="element-types">
284
      <?gmfgen generated="true"?>
285
      <metamodel nsURI="http://www.eclipse.org/papyurs/0.7.0/Resource">
286
         <metamodelType
287
               id="org.eclipse.papyrus.sysml.diagram.parametric.Resource_1000"
288
               name="%metatype.name.Resource_1000"
289
               kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"
290
               eclass="Resource"
291
               edithelper="org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers.ResourceEditHelper">
292
            <param name="semanticHint" value="1000"/>
293
         </metamodelType>
294
      </metamodel>
295
      <metamodel nsURI="http://www.eclipse.org/papyrus/0.7.0/SysML/Constraints">
296
         <metamodelType
297
               id="org.eclipse.papyrus.sysml.diagram.parametric.ConstraintProperty_2003"
298
               name="%metatype.name.ConstraintProperty_2003"
299
               kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"
300
               eclass="ConstraintProperty"
301
               edithelper="org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers.ConstraintPropertyEditHelper">
302
            <param name="semanticHint" value="2003"/>
303
         </metamodelType>
304
      </metamodel>
305
      <metamodel nsURI="http://www.eclipse.org/uml2/3.0.0/UML">
306
         <specializationType
307
               id="org.eclipse.papyrus.sysml.diagram.parametric.Property_2005"
308
               name="%metatype.name.Property_2005"
309
               kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType">
310
            <specializes id="org.eclipse.papyrus.sysml.diagram.parametric.Property_3002"/>
311
            <param name="semanticHint" value="2005"/>
312
         </specializationType>
313
      </metamodel>
314
      <metamodel nsURI="http://www.eclipse.org/uml2/3.0.0/UML">
315
         <metamodelType
316
               id="org.eclipse.papyrus.sysml.diagram.parametric.Property_3002"
317
               name="%metatype.name.Property_3002"
318
               kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"
319
               eclass="Property"
320
               edithelper="org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers.PropertyEditHelper">
321
            <param name="semanticHint" value="3002"/>
322
         </metamodelType>
323
      </metamodel>
324
      <metamodel nsURI="http://www.eclipse.org/uml2/3.0.0/UML">
325
         <metamodelType
326
               id="org.eclipse.papyrus.sysml.diagram.parametric.Connector_4001"
327
               name="%metatype.name.Connector_4001"
328
               kind="org.eclipse.gmf.runtime.emf.type.core.IHintedType"
329
               eclass="Connector"
330
               edithelper="org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers.ConnectorEditHelper">
331
            <param name="semanticHint" value="4001"/>
332
         </metamodelType>
333
      </metamodel>
334
   </extension>
335
336
   <extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings" id="element-types-bindings">
337
      <?gmfgen generated="true"?>
338
      <clientContext id="org.eclipse.papyrus.sysml.diagram.parametric.TypeContext">
339
         <enablement>
340
            <test
341
               property="org.eclipse.gmf.runtime.emf.core.editingDomain"
342
               value="org.eclipse.papyrus.sysml.diagram.parametric.EditingDomain"/>
343
         </enablement>
344
      </clientContext> 
345
      <binding context="org.eclipse.papyrus.sysml.diagram.parametric.TypeContext">
346
         <elementType ref="org.eclipse.papyrus.sysml.diagram.parametric.Resource_1000"/>
347
         <elementType ref="org.eclipse.papyrus.sysml.diagram.parametric.ConstraintProperty_2003"/>
348
         <elementType ref="org.eclipse.papyrus.sysml.diagram.parametric.Property_2005"/>
349
         <elementType ref="org.eclipse.papyrus.sysml.diagram.parametric.Property_3002"/>
350
         <elementType ref="org.eclipse.papyrus.sysml.diagram.parametric.Connector_4001"/>
351
         <advice ref="org.eclipse.gmf.runtime.diagram.core.advice.notationDepdendents"/>
352
      </binding>
353
   </extension>
354
	   <extension point="org.eclipse.core.expressions.propertyTesters" id="navigator-proptest.isURIEditorInput">
355
      <?gmfgen generated="true"?>
356
       <propertyTester
357
           id="org.eclipse.papyrus.sysml.diagram.parametric.URIEditorInputPropertyTester"
358
           type="org.eclipse.emf.common.ui.URIEditorInput"
359
           namespace="org.eclipse.papyrus.sysml.diagram.parametric"
360
           properties="isURIEditorInput"
361
           class="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlUriEditorInputTester">
362
       </propertyTester>
363
   </extension>
364
365
	   <extension point="org.eclipse.ui.navigator.viewer" id="navigator-viewbinding">
366
      <?gmfgen generated="true"?>
367
      <viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
368
         <includes>
369
            <contentExtension pattern="org.eclipse.papyrus.sysml.diagram.parametric.resourceContent"/>
370
			<contentExtension pattern="org.eclipse.papyrus.sysml.diagram.parametric.domainResourceContent"/>
371
            <contentExtension pattern="org.eclipse.papyrus.sysml.diagram.parametric.navigatorLinkHelper"/>
372
         </includes>
373
      </viewerContentBinding>
374
      <viewerActionBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
375
         <includes>
376
            <actionExtension pattern="org.eclipse.papyrus.sysml.diagram.parametric.navigatorActionProvider"/>
377
         </includes>
378
      </viewerActionBinding>
379
   </extension>
380
381
   <extension point="org.eclipse.ui.navigator.navigatorContent" id="navigator-content">
382
      <?gmfgen generated="true"?>
383
      <navigatorContent
384
            id="org.eclipse.papyrus.sysml.diagram.parametric.resourceContent" 
385
            name="%navigatorContentName" 
386
            priority="normal" 
387
            contentProvider="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorContentProvider" 
388
            labelProvider="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorLabelProvider"
389
            icon="icons/obj16/ResourceDiagramFile.gif"
390
            activeByDefault="true">
391
         <triggerPoints>
392
            <or>
393
	           <and>
394
    	          <instanceof value="org.eclipse.core.resources.IFile"/>
395
        	      <test property="org.eclipse.core.resources.extension" value="sysml_diagram"/>
396
               </and>
397
               <instanceof value="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlAbstractNavigatorItem"/>
398
            </or>
399
         </triggerPoints>
400
         <possibleChildren>
401
            <or>
402
         	   <instanceof value="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlAbstractNavigatorItem"/>
403
            </or>
404
         </possibleChildren>
405
         <commonSorter 
406
               id="org.eclipse.papyrus.sysml.diagram.parametric.navigatorSorter" 
407
               class="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorSorter">
408
            <parentExpression>
409
               <or>
410
	              <and>
411
    	             <instanceof value="org.eclipse.core.resources.IFile"/>
412
        	         <test property="org.eclipse.core.resources.extension" value="sysml_diagram"/>
413
                  </and>
414
                  <instanceof value="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlAbstractNavigatorItem"/>
415
               </or>
416
            </parentExpression>
417
         </commonSorter>
418
      </navigatorContent>
419
      <navigatorContent
420
            id="org.eclipse.papyrus.sysml.diagram.parametric.domainResourceContent" 
421
            name="%domainNavigatorContentName" 
422
            priority="normal" 
423
            contentProvider="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorContentProvider" 
424
            labelProvider="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorLabelProvider"
425
            icon="icons/obj16/ResourceDiagramFile.gif"
426
            activeByDefault="true">
427
         <triggerPoints>
428
            <or>
429
	           <and>
430
    	          <instanceof value="org.eclipse.core.resources.IFile"/>
431
        	      <test property="org.eclipse.core.resources.extension" value="sysml"/>
432
               </and>
433
               <instanceof value="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorItem"/>
434
            </or>
435
         </triggerPoints>
436
         <possibleChildren>
437
            <instanceof value="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorItem"/>
438
         </possibleChildren>
439
      </navigatorContent>
440
      <actionProvider
441
            id="org.eclipse.papyrus.sysml.diagram.parametric.navigatorActionProvider"
442
            class="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorActionProvider">
443
         <enablement>
444
            <or>
445
               <instanceof value="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlAbstractNavigatorItem"/>
446
            </or>
447
         </enablement>
448
      </actionProvider>
449
   </extension>
450
   
451
	   <extension point="org.eclipse.ui.navigator.linkHelper" id="navigator-linkhelper">
452
      <?gmfgen generated="true"?>
453
      <linkHelper
454
            id="org.eclipse.papyrus.sysml.diagram.parametric.navigatorLinkHelper"
455
            class="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorLinkHelper">
456
         <editorInputEnablement>
457
            <and>
458
               <instanceof value="org.eclipse.emf.common.ui.URIEditorInput"/>
459
               <test property="org.eclipse.papyrus.sysml.diagram.parametric.isURIEditorInput"/>
460
            </and>
461
         </editorInputEnablement>
462
         <selectionEnablement>
463
            <instanceof value="org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlAbstractNavigatorItem"/>
464
         </selectionEnablement>
465
      </linkHelper>
466
   </extension>
467
   <extension point="org.eclipse.ui.commands" id="update-cmd">
468
      <?gmfgen generated="true"?>
469
      <command
470
         categoryId="org.eclipse.ui.category.edit"
471
         defaultHandler="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramUpdateCommand"
472
         description="%update.diagram.description"
473
         id="org.eclipse.papyrus.sysml.diagram.parametric.updateDiagram"
474
         name="%update.diagram.name"/>
475
   </extension>
476
   
477
   <extension point="org.eclipse.ui.bindings" id="update-cmd-binding">
478
      <?gmfgen generated="true"?>
479
      <key 
480
         commandId="org.eclipse.papyrus.sysml.diagram.parametric.updateDiagram"
481
         contextId="org.eclipse.papyrus.sysml.diagram.parametric.ui.diagramContext"
482
         schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
483
         sequence="F5"/>
484
   </extension>
485
486
   <extension point="org.eclipse.ui.menus" id="context-menus">
487
      <?gmfgen generated="true"?>
488
      <!-- menuContribution locationURI="menu:org.eclipse.ui.main.menu?after=">
489
      </menuContribution>
490
      <menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar?after=">
491
      </menuContribution -->
492
      <menuContribution locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu">
493
         <command commandId="org.eclipse.papyrus.sysml.diagram.parametric.LoadResourceAction">
494
            <visibleWhen>
495
               <and>
496
                  <with variable="activePartId"><equals value="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorID"/></with>
497
                  <with variable="selection"><iterate ifEmpty="false"> 
498
                     <instanceof value="org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart"/>
499
                  </iterate></with>
500
               </and>
501
            </visibleWhen>
502
         </command>
503
      </menuContribution>
504
      
505
      
506
	<menuContribution locationURI="menu:org.eclipse.papyrus.ui.menu">
507
		<menu id="org.eclipse.papyrus.uml.diagram.ui.menu.diagrams"
508
			label="Diagrams">
509
			<command commandId="org.eclipse.papyrus.sysml.diagram.parametric.CreateParametricDiagramCommand"
510
				icon="icons/obj16/Diagram_Parametric.gif"
511
				label="Create a new Parametric Diagram"
512
				style="push"
513
				tooltip="Create a new Parametric Diagram">
514
				<visibleWhen>
515
					<reference definitionId="org.eclipse.papyrus.sysml.diagram.common.IsPapyrusActiveWithSysML"/>
516
				</visibleWhen>
517
			</command>
518
		</menu>
519
	</menuContribution>
520
	
521
	<menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar">
522
		<toolbar id="org.eclipse.papyrus.uml.diagram.ui.toolbar">
523
			<command commandId="org.eclipse.papyrus.sysml.diagram.parametric.CreateParametricDiagramCommand"
524
				icon="icons/obj16/Diagram_Parametric.gif"
525
				label="Create a new Parametric Diagram"
526
				style="push"
527
				tooltip="Create a new Parametric Diagram">
528
				<visibleWhen>
529
					<reference definitionId="org.eclipse.papyrus.sysml.diagram.common.IsPapyrusActiveWithSysML"/>
530
				</visibleWhen>
531
			</command>
532
		</toolbar>
533
	</menuContribution>
534
535
	<menuContribution
536
		locationURI="popup:org.eclipse.papyrus.views.modelexplorer.popupmenu.creatediagram">
537
	    <command commandId="org.eclipse.papyrus.sysml.diagram.parametric.CreateParametricDiagramCommand"
538
			icon="icons/obj16/Diagram_Parametric.gif"
539
			label="Create a new Parametric Diagram"
540
			style="push"
541
			tooltip="Create a new Parametric Diagram">
542
	       <visibleWhen>
543
				<reference definitionId="org.eclipse.papyrus.sysml.diagram.common.IsPapyrusActiveWithSysML"/>
544
	       </visibleWhen>
545
	    </command>
546
	</menuContribution>
547
548
</extension>
17
</extension>
549
18
550
   <extension point="org.eclipse.ui.commands" id="menu-commands">
19
<!-- Diagram creation command and handler -->
551
      <?gmfgen generated="true"?>
20
<extension point="org.eclipse.ui.commands">
552
      <category id="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorID" name="%cmdcategory.name" description="%cmdcategory.desc"/>
21
	<command id="org.eclipse.papyrus.sysml.diagram.parametric.CreateCommand"
553
      <command id="org.eclipse.papyrus.sysml.diagram.parametric.LoadResourceAction"
22
		name="Create a new Parametric Diagram"
554
         name="Load Resource"
23
		description="Create a new Parametric Diagram"
555
         categoryId="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorID"
24
		categoryId="org.eclipse.papyrus.editor.category"/>
556
         defaultHandler="org.eclipse.papyrus.sysml.diagram.parametric.part.LoadResourceAction"/>
25
</extension>
557
   </extension>
558
  
559
   <extension point="org.eclipse.ui.commands">
560
		<command description="Create a new Parametric Diagram"
561
			categoryId="org.eclipse.papyrus.editor.category"
562
			id="org.eclipse.papyrus.sysml.diagram.parametric.CreateParametricDiagramCommand"
563
			name="Create Parametric Diagram">
564
		</command>
565
	</extension>
566
	
567
	<extension point="org.eclipse.ui.handlers">
568
		<handler class="org.eclipse.papyrus.sysml.diagram.parametric.CreateParametricDiagramWithNavigationHandler"
569
			commandId="org.eclipse.papyrus.sysml.diagram.parametric.CreateParametricDiagramCommand">
570
			<activeWhen>
571
					<with variable="activeEditorId">
572
						<equals value="org.eclipse.papyrus.infra.core.papyrusEditor"></equals>
573
					</with>
574
			</activeWhen>
575
		</handler>
576
	</extension>
577
	
578
	
579
   <extension
580
         point="org.eclipse.papyrus.infra.core.papyrusDiagram">
581
      <editorDiagram
582
            factoryClass="org.eclipse.papyrus.sysml.diagram.parametric.ParametricDiagramEditorFactory"
583
            icon="icons/obj16/Diagram_Parametric.gif">
584
      </editorDiagram>
585
      <creationCommand
586
            creationCommandClass="org.eclipse.papyrus.sysml.diagram.parametric.CreateParametricDiagramCommand"
587
            creationCondition="org.eclipse.papyrus.sysml.diagram.parametric.ParametricDiagramCondition"
588
            icon="icons/obj16/Diagram_Parametric.gif"
589
            id="org.eclipse.papyrus.sysml.diagram.parametric.CreateParametricDiagramCommand"
590
            language="sysml"
591
            label="SysML Parametric Diagram">
592
      </creationCommand>
593
   </extension>
594
<extension point="org.eclipse.gmf.runtime.common.ui.services.parserProviders" id="parser-provider">
595
      <?gmfgen generated="true"?>
596
      <ParserProvider class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlParserProvider">
597
         <Priority name="Lowest"/>
598
      </ParserProvider>
599
   </extension>
600
26
601
<extension point="org.eclipse.ui.preferencePages">
27
<extension point="org.eclipse.ui.handlers">
602
28
	<handler
603
29
		class="org.eclipse.papyrus.sysml.diagram.parametric.CreateParametricDiagramWithNavigationHandler"
604
		
30
		commandId="org.eclipse.papyrus.sysml.diagram.parametric.CreateCommand">
605
	<?gmfgen generated="true"?>
31
		<activeWhen>
606
	<page  	category="org.eclipse.papyrus.infra.gmfdiag.preferences.diagrams.Parametric"
32
			<with variable="activeEditorId">
607
			class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.ConstraintPropertyPreferencePage"
33
				<equals value="org.eclipse.papyrus.infra.core.papyrusEditor" />
608
            id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.ConstraintPropertyPreferencePage"
34
			</with>
609
            name="ConstraintProperty Node" />
35
		</activeWhen>
36
	</handler>
37
</extension>
38
39
<!-- Diagram creation command registration in menu and toolbar -->
40
<extension point="org.eclipse.ui.menus">
41
42
	<menuContribution locationURI="menu:org.eclipse.papyrus.ui.menu">
43
	<menu id="org.eclipse.papyrus.uml.diagram.ui.menu.diagrams" label="Diagrams">
44
		<command commandId="org.eclipse.papyrus.sysml.diagram.parametric.CreateCommand"
45
			icon="icons/obj16/Diagram_Parametric.png" label="Create a new Parametric Diagram"
46
			style="push" tooltip="Create a new Parametric Diagram">
47
			<visibleWhen>
48
				<reference definitionId="org.eclipse.papyrus.sysml.diagram.common.IsPapyrusActiveWithSysML"/>
49
			</visibleWhen>
50
					
51
		</command>
52
	</menu>
53
	</menuContribution>
610
	
54
	
611
		
55
	<menuContribution locationURI="toolbar:org.eclipse.ui.main.toolbar">
612
	<?gmfgen generated="true"?>
56
	<toolbar id="org.eclipse.papyrus.uml.diagram.ui.toolbar">
613
	<page  	category="org.eclipse.papyrus.infra.gmfdiag.preferences.diagrams.Parametric"
57
		<command commandId="org.eclipse.papyrus.sysml.diagram.parametric.CreateCommand"
614
			class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.PropertyPreferencePage"
58
			icon="icons/obj16/Diagram_Parametric.png" label="Create a new Parametric Diagram"
615
            id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.PropertyPreferencePage"
59
			style="push" tooltip="Create a new Parametric Diagram">
616
            name="Property Node" />
60
			<visibleWhen>
61
				<reference definitionId="org.eclipse.papyrus.sysml.diagram.common.IsPapyrusActiveWithSysML"/>
62
			</visibleWhen>
63
				
64
		</command>
65
	</toolbar>
66
	</menuContribution>
617
	
67
	
618
68
	<menuContribution locationURI="popup:org.eclipse.papyrus.views.modelexplorer.popupmenu.creatediagram">
619
69
		<command commandId="org.eclipse.papyrus.sysml.diagram.parametric.CreateCommand"
620
		
70
			icon="icons/obj16/Diagram_Parametric.png"
621
71
			label="Create a new Parametric Diagram"
622
	<?gmfgen generated="true"?>
72
			style="push"
623
	<page  	category="org.eclipse.papyrus.infra.gmfdiag.preferences.diagrams.Parametric"
73
			tooltip="Create a new Parametric Diagram">
624
			class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.ConnectorPreferencePage"
74
			<visibleWhen>
625
            id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.ConnectorPreferencePage"
75
				<reference definitionId="org.eclipse.papyrus.sysml.diagram.common.IsPapyrusActiveWithSysML"/>
626
            name="Connector Link" />
76
			</visibleWhen>
627
		
77
			
628
78
		</command>
629
</extension>
79
	</menuContribution>
630
<extension
80
		
631
      point="org.eclipse.papyrus.extensionpoints.editors.DirectEditor">
81
</extension>
632
   <DirectEditor
633
         contributor="Eclipse.org"
634
         editorConfiguration="org.eclipse.papyrus.sysml.diagram.parametric.texteditor.ConstraintPropertyConfiguration"
635
         icon="platform:/plugin/org.eclipse.papyrus.sysml/icons/constraints/ConstraintProperty.gif"
636
         language="Papyrus SysML"
637
         objectToEdit="org.eclipse.papyrus.sysml.constraints.ConstraintProperty">
638
      <simpleeditor
639
            editorConfiguration="org.eclipse.papyrus.sysml.diagram.parametric.texteditor.ConstraintPropertyConfiguration">
640
      </simpleeditor>
641
   </DirectEditor>
642
</extension>
643
644
<extension point="org.eclipse.emf.validation.constraintProviders">
645
      <?gmfgen generated="true"?>
646
            <category id="org.eclipse.uml2.uml.util.UMLValidator.validate" mandatory="false" name="validateSysMLModel">
647
         <![CDATA[Validate the SysML model]]>
648
      </category>
649
      <category id="org.eclipse.uml2.uml.util.UMLValidator.validate/org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement" mandatory="false" name="validateConnectorElement">
650
         <![CDATA[validate a connector checking that its children are consistent]]>
651
      </category>
652
      <constraintProvider cache="true">
653
         <package namespaceUri="http://www.eclipse.org/uml2/3.0.0/UML"/>
654
         <package namespaceUri="http://www.eclipse.org/papyrus/0.7.0/SysML/Blocks"/>
655
               <constraints categories="org.eclipse.uml2.uml.util.UMLValidator.validate">
656
                  </constraints>
657
         <constraints categories="org.eclipse.uml2.uml.util.UMLValidator.validate/org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement">
658
                  <constraint id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateConnector"
659
            lang="Java" class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlValidationProvider$Adapter1"
660
            name="validateConnector"
661
            mode="Live"
662
            severity="WARNING" statusCode="200">
663
            
664
            <description><![CDATA[The NestedConnectorEnd stereotype of UML ConnectorEnd extends a UML ConnectorEnd so that the connected property]]></description>
665
            <message><![CDATA[NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector.]]></message>
666
            <target class="uml.Connector"/>
667
         </constraint>
668
                  <constraint id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateProperty"
669
            lang="Java" class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlValidationProvider$Adapter2"
670
            name="validateProperty"
671
            mode="Live"
672
            severity="WARNING" statusCode="200">
673
            
674
            <description><![CDATA[When you move a property, check that its incoming or outgoings connector get consistent connectorEnd]]></description>
675
            <message><![CDATA[NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector.]]></message>
676
            <target class="uml.Property"/>
677
         </constraint>
678
                  <constraint id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateConnectorEnd"
679
            lang="Java" class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlValidationProvider$Adapter3"
680
            name="validateConnectorEnd"
681
            mode="Live"
682
            severity="WARNING" statusCode="200">
683
            
684
            <description><![CDATA[The NestedConnectorEnd stereotype of UML ConnectorEnd extends a UML ConnectorEnd so that the connected property]]></description>
685
            <message><![CDATA[NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector.]]></message>
686
            <target class="uml.ConnectorEnd"/>
687
         </constraint>
688
                  <constraint id="org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateNestedConnectorEnd"
689
            lang="Java" class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlValidationProvider$Adapter4"
690
            name="validateNestedConnectorEnd"
691
            mode="Live"
692
            severity="WARNING" statusCode="200">
693
            
694
            <description><![CDATA[The NestedConnectorEnd stereotype of UML ConnectorEnd extends a UML ConnectorEnd so that the connected property]]></description>
695
            <message><![CDATA[NestedConnectorEnd is used for connected property identified by a multi-level path of accessible properties from the block that owns the connector.]]></message>
696
            <target class="sysml.blocks.NestedConnectorEnd"/>
697
         </constraint>
698
                  </constraints>
699
      </constraintProvider>
700
   </extension>
701
82
702
<extension point="org.eclipse.emf.validation.constraintBindings">
83
<!-- Palette tool definition (defines tools possibly used by the palette(s)) -->
703
      <?gmfgen generated="true"?>
84
<extension point="org.eclipse.gmf.runtime.diagram.ui.paletteProviders"
704
      <clientContext default="false" id="org.eclipse.papyrus.sysml.diagram.parametricDefaultCtx">
85
	name="SYSML_Parametric_Predefined_Entries"
705
         <selector class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlValidationProvider$DefaultCtx"/>
86
	id="org.eclipse.papyrus.sysml.diagram.blockdefinition.palettedefinition"> 
706
      </clientContext>
87
		
707
      <binding context="org.eclipse.papyrus.sysml.diagram.parametricDefaultCtx">
88
	<paletteProvider class="org.eclipse.gmf.runtime.diagram.ui.providers.DefaultPaletteProvider">
708
                  <constraint ref="org.eclipse.papyrus.sysml.diagram.parametric.org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateConnector"/>
89
	<Priority name="Lowest"/> <!-- Lower priority than Palette tool declaration -->
709
                  <constraint ref="org.eclipse.papyrus.sysml.diagram.parametric.org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateProperty"/>
90
	
710
                  <constraint ref="org.eclipse.papyrus.sysml.diagram.parametric.org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateConnectorEnd"/>
91
	<!-- SysML Parametric Diagram specific tool definition -->
711
                  <constraint ref="org.eclipse.papyrus.sysml.diagram.parametric.org.eclipse.uml2.uml.util.UMLValidator.validateConnectorElement_validateNestedConnectorEnd"/>
92
	<contribution
712
               </binding>
93
		factoryClass="org.eclipse.papyrus.sysml.diagram.parametric.factory.DiagramPaletteFactory">
713
94
			
714
   </extension>
95
		<!-- parametric.tool.constraintblockpropertycomposite -->
715
<extension
96
		<entry
716
      point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
97
			defineOnly="true"
717
   <editpolicyProvider
98
			description="Create a ConstraintBlockProperty"
718
         class="org.eclipse.papyrus.sysml.diagram.parametric.providers.CustomEditPolicyProvider">
99
			id="parametric.tool.constraintblockpropertycomposite"
719
      <Priority
100
			kind="tool"
720
            name="Lowest">
101
			label="ConstraintProperty"
721
      </Priority>
102
			large_icon="platform:/plugin/org.eclipse.papyrus.sysml/icons/blocks/Block.gif"
722
   </editpolicyProvider>
103
			small_icon="platform:/plugin/org.eclipse.papyrus.sysml/icons/blocks/Block.gif">
723
</extension>
104
		</entry>
724
<extension point="org.eclipse.gmf.runtime.common.ui.services.markerNavigationProviders" id="markers-navigation">
105
	
725
      <?gmfgen generated="true"?>
106
		<!-- parametric.tool.parameter -->
726
      <MarkerNavigationProvider class="org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlMarkerNavigationProvider">
107
		<entry
727
         <MarkerType name="org.eclipse.papyrus.sysml.diagram.parametric.diagnostic"/>
108
			defineOnly="true"
728
         <Priority name="Lowest"/>
109
			description="Create a Parameter"
729
      </MarkerNavigationProvider>
110
			id="parametric.tool.parameter"
730
   </extension>
111
			kind="tool"
731
112
			label="ConstraintParameter"
732
<extension id="diagnostic" name="Sysml Parametric diagram Plugin problems" point="org.eclipse.core.resources.markers">
113
			large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Port.gif"
733
      <?gmfgen generated="true"?>
114
			small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Port.gif">
734
      <super type="org.eclipse.core.resources.problemmarker"/>
115
		</entry>
735
      <super type="org.eclipse.gmf.runtime.common.ui.services.marker"/>
116
		
736
      <persistent value="true"/>
117
		<!-- parametric.tool.blockpropertycomposite -->
737
   </extension><extension
118
		<entry
738
		id="Sysml Parametric diagram Plugin.palettedefinition"
119
			defineOnly="true"
739
		name="Sysml Parametric diagram Plugin Predefined Entries"
120
			description="Create a Part"
740
		point="org.eclipse.gmf.runtime.diagram.ui.paletteProviders"> 
121
			id="parametric.tool.blockpropertycomposite"
741
		
122
			kind="tool"
742
		<?gmfgen generated="true"?>	
123
			label="Part"
743
		<paletteProvider class="org.eclipse.gmf.runtime.diagram.ui.providers.DefaultPaletteProvider">
124
			large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif"
744
			<Priority name="Lowest"/>
125
			small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif">
745
      		<contribution
126
		</entry>
746
            	factoryClass="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlPaletteFactory">
127
		
747
     			<predefinedEntry id="standardGroup/noteStack/noteTool" remove="true"/> 
128
		<!-- parametric.tool.reference -->
748
				<predefinedEntry id="standardGroup/noteStack/textTool" remove="true"/> 
129
		<entry
749
				<predefinedEntry id="standardGroup/noteStack/noteattachmentTool" remove="true"/>
130
			defineOnly="true"
750
					<entry
131
			description="Create a Reference"
751
       defineOnly="true"
132
			id="parametric.tool.reference"
752
       description="Create new ConstraintProperty"
133
			kind="tool"
753
       id="createConstraintProperty1CreationTool"
134
			label="Reference"
754
       kind="tool"
135
			large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif"
755
       label="ConstraintProperty"
136
			small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif">
756
       large_icon="platform:/plugin/org.eclipse.papyrus.sysml.edit/icons/full/obj16/ConstraintProperty.gif"
137
		</entry>
757
       path=""
138
					
758
       small_icon="platform:/plugin/org.eclipse.papyrus.sysml.edit/icons/full/obj16/ConstraintProperty.gif">
139
		<!-- parametric.tool.value -->
759
 	</entry>
140
		<entry
760
	<entry
141
			defineOnly="true"
761
       defineOnly="true"
142
			description="Create a Value"
762
       description="Create new Property"
143
			id="parametric.tool.value"
763
       id="createProperty2CreationTool"
144
			kind="tool"
764
       kind="tool"
145
			label="Value"
765
       label="Property"
146
			large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif"
766
       large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif"
147
			small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif">
767
       path=""
148
		</entry>
768
       small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Property.gif">
149
					
769
 	</entry>
150
		<!-- Start of user code Custom node button entry
770
	<entry
151
		-->
771
       defineOnly="true"
152
		
772
       description="Create new Connector"
153
		<!-- End of user code  -->
773
       id="createConnector3CreationTool"
154
		
774
       kind="tool"
155
			
775
       label="Connector"
156
		<!-- parametric.tool.connector -->
776
       large_icon=""
157
		<entry
777
       path=""
158
			defineOnly="true"
778
       small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Connector.gif">
159
			description="Create a Connector"
779
 	</entry>
160
			id="parametric.tool.connector"
780
161
			kind="tool"
781
			</contribution>
162
			label="Connector"
782
		</paletteProvider>	
163
			large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Connector.gif"
783
			
164
			small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Connector.gif">
784
	</extension>
165
		</entry>
785
166
			
786
<extension
167
		<!-- parametric.tool.dependency -->
787
		id="Sysml Parametric diagram Plugin.standard"
168
		<entry
788
		name="Sysml Parametric diagram Plugin Standard Palette"
169
			defineOnly="true"
789
		point="org.eclipse.gmf.runtime.diagram.ui.paletteProviders"> 
170
			description="Create a Dependency"
790
		
171
			id="parametric.tool.dependency"
791
		<?gmfgen generated="true"?>	
172
			kind="tool"
792
		<paletteProvider class="org.eclipse.gmf.runtime.diagram.ui.providers.DefaultPaletteProvider">
173
			label="Dependency"
793
			<Priority name="Low"/>
174
			large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Dependency.gif"
794
      		<contribution
175
			small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Dependency.gif">
795
            	factoryClass="org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlPaletteFactory">
176
		</entry>
796
     			<predefinedEntry id="standardGroup/noteStack/noteTool" remove="true"/> 
177
		<!-- Start of user code Custom edge button entry -->
797
				<predefinedEntry id="standardGroup/noteStack/textTool" remove="true"/> 
178
		<!-- parametric.tool.comment -->
798
				<predefinedEntry id="standardGroup/noteStack/noteattachmentTool" remove="true"/>
179
		<entry 
799
					<entry
180
			defineOnly="true"
800
       description=""
181
			description="Create a Comment"
801
       id="createParametric1Group"
182
			id="parametric.tool.comment"
802
       kind="drawer"
183
			kind="tool" 
803
       label="Parametric"
184
			label="Comment"
804
       large_icon="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif"
185
			large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Comment.gif"
805
       path="/"
186
			small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Comment.gif">
806
       small_icon="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif">
187
		</entry>
807
       <expand
188
		
808
              force="true">
189
		<!-- internalblock.tool.constraint -->
809
       </expand>
190
		<entry defineOnly="true"
810
 	</entry>
191
			description="Create a Constraint"
811
 	 
192
			id="parametric.tool.constraint"
812
 	 	<predefinedEntry
193
			kind="tool"
813
          id="createConstraintProperty1CreationTool"
194
			label="Constraint"
814
          path="/createParametric1Group">
195
			large_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Constraint.gif"
815
    </predefinedEntry>
196
			small_icon="platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/Constraint.gif">
816
 	<predefinedEntry
197
		</entry>
817
          id="createProperty2CreationTool"
818
          path="/createParametric1Group">
819
    </predefinedEntry>
820
 	<predefinedEntry
821
          id="createConnector3CreationTool"
822
          path="/createParametric1Group">
823
    </predefinedEntry>
824
825
826
			</contribution>
827
			<editor id="org.eclipse.papyrus.sysml.diagram.parametric"/>
828
		</paletteProvider>	
829
			
830
	</extension>
831
832
<extension point="org.eclipse.ui.handlers" id="menu-handlers">
833
      <?gmfgen generated="true"?>
834
   </extension>
835
836
198
837
   <!-- optionally, specify keybindings -->
199
		<entry
838
</plugin>
200
			defineOnly="true"
201
			description="Create a Comment / Constraint link"
202
			id="parametric.tool.comment_constraint_link"
203
			kind="tool"
204
			label="Comment / Constraint link"
205
			large_icon="icons/obj16/Link.gif"
206
			small_icon="icons/obj16/Link.gif">
207
		</entry>
208
			
209
		<!-- End of user code  -->
210
			
211
	</contribution>
212
	
213
	<!-- Specify diagram this palette tools relate to -->				
214
	<editor id="org.eclipse.papyrus.sysml.diagram.parametric"/>
215
	
216
	</paletteProvider>	
217
</extension>
218
219
<!-- Palette tool declaration (declares the real palette containment) -->
220
<extension point="org.eclipse.papyrus.uml.diagram.common.paletteDefinition"
221
	name="SYSML_Parametric">
222
	
223
	<paletteDefinition ID="SYSML_Parametric"
224
		class="org.eclipse.papyrus.uml.diagram.common.service.PluginPaletteProvider"
225
		name="SYSML_Parametric" icon="platform:/plugin/org.eclipse.gmf.runtime.diagram.ui/icons/group.gif" 
226
		path="palettes/parametric.palette.xml"
227
		provider="CEA LIST">
228
		<Priority name="Low"/>
229
		
230
		<!-- Specify diagram this palette tools relate to -->						
231
		<editor id="org.eclipse.papyrus.sysml.diagram.parametric"/>
232
	</paletteDefinition>
233
</extension>
234
235
236
<!-- Diagram view providers declaration -->
237
<extension point="org.eclipse.gmf.runtime.diagram.core.viewProviders">
238
	<!-- Diagram view provider -->
239
	<viewProvider class="org.eclipse.papyrus.sysml.diagram.parametric.provider.ParametricDiagramViewProvider">
240
		<Priority name="Low"/>
241
		<context viewClass="org.eclipse.gmf.runtime.notation.Diagram" semanticHints="Parametric"/>
242
	</viewProvider>
243
	
244
	<!-- Custom graphical types view provider -->
245
	<viewProvider class="org.eclipse.papyrus.sysml.diagram.parametric.provider.CustomViewProvider">
246
		<Priority name="Medium"/>
247
		<context viewClass="org.eclipse.gmf.runtime.notation.Node" semanticHints="UML::Property, UML::Port, SysML::ReferenceProperty, SysML::FlowPort, SysML::FlowPort_Out, SysML::Block, SysML::FlowPort_In, SysML::FlowPort_InOut, SysML::PartProperty, SysML::ConstraintProperty"/>
248
		<context viewClass="org.eclipse.gmf.runtime.notation.Node" semanticHints="shape_sysml_flowport_as_affixed, shape_uml_port_as_affixed, shape_sysml_block_as_composite, shape_sysml_blockproperty_as_composite, shape_sysml_constraintblockproperty_as_composite"/>
249
		<context viewClass="org.eclipse.gmf.runtime.notation.Edge" semanticHints="UML::Connector, UML::Dependency"/>
250
		<context viewClass="org.eclipse.gmf.runtime.notation.Edge" semanticHints="link_uml_dependency, link_uml_connector"/>
251
		
252
		<!-- Additional descriptors provided in case the semantic hint is is not provided -->	
253
		
254
		<!-- "uml.Class" -->
255
		<object id="uml.Class" class="org.eclipse.gmf.runtime.emf.core.util.IProxyEObject(org.eclipse.gmf.runtime.emf.core)">
256
			<method name="getProxyClassID()" value="uml.Class"/>
257
		</object>
258
		<context viewClass="org.eclipse.gmf.runtime.notation.Node" semanticHints="uml.Class"/>			
259
		
260
		<!-- "uml.Port" -->
261
		<object id="uml.Port" class="org.eclipse.gmf.runtime.emf.core.util.IProxyEObject(org.eclipse.gmf.runtime.emf.core)">
262
			<method name="getProxyClassID()" value="uml.Port"/>
263
		</object>
264
		<context viewClass="org.eclipse.gmf.runtime.notation.Node" semanticHints="uml.Port"/>			
265
		
266
		<!-- "uml.Property" -->
267
		<object id="uml.Property" class="org.eclipse.gmf.runtime.emf.core.util.IProxyEObject(org.eclipse.gmf.runtime.emf.core)">
268
			<method name="getProxyClassID()" value="uml.Property"/>
269
		</object>
270
		<context viewClass="org.eclipse.gmf.runtime.notation.Node" semanticHints="uml.Property"/>			
271
		
272
		<!-- "uml.Connector" -->
273
		<object id="uml.Connector" class="org.eclipse.gmf.runtime.emf.core.util.IProxyEObject(org.eclipse.gmf.runtime.emf.core)">
274
			<method name="getProxyClassID()" value="uml.Connector"/>
275
		</object>
276
		<context viewClass="org.eclipse.gmf.runtime.notation.Edge" semanticHints="uml.Connector"/>			
277
		
278
		<!-- "uml.Dependency" -->
279
		<object id="uml.Dependency" class="org.eclipse.gmf.runtime.emf.core.util.IProxyEObject(org.eclipse.gmf.runtime.emf.core)">
280
			<method name="getProxyClassID()" value="uml.Dependency"/>
281
		</object>
282
		<context viewClass="org.eclipse.gmf.runtime.notation.Edge" semanticHints="uml.Dependency"/>			
283
		<object id="elementtype.node"
284
          class="org.eclipse.papyrus.gmf.diagram.common.commands.ISemanticHintAdapter(org.eclipse.papyrus.sysml.diagram.common)">
285
       
286
     		<method
287
           		name="getSemanticHint()"
288
           		value="UML::Property, SysML::ActorPartProperty, SysML::ValueProperty, SysML::ReferenceProperty, SysML::FlowPort_In, UML::Port, SysML::FlowPort_Out, SysML::PartProperty, SysML::FlowPort_InOut, SysML::FlowPort, SysML::Block, SysML::FlowPort_NA">
289
     		</method>
290
  		</object>
291
  		<context
292
        	elements="elementtype.node"
293
        	viewClass="org.eclipse.gmf.runtime.notation.Node">
294
  		</context>
295
  		<object id="elementtype.edge"
296
        	class="org.eclipse.papyrus.gmf.diagram.common.commands.ISemanticHintAdapter(org.eclipse.papyrus.sysml.diagram.common)">
297
    	 	<method
298
        		name="getSemanticHint()"
299
           		value="UML::Dependency, UML::Connector">
300
     		</method>
301
	  	</object>
302
	  	<context
303
	        elements="elementtype.edge"
304
	        viewClass="org.eclipse.gmf.runtime.notation.Edge">
305
	  	</context>			
306
		
307
	</viewProvider>	
308
309
	<!-- ViewProvider for inherited elements (from CompositeDiagram ViewProvider) -->
310
	<viewProvider class="org.eclipse.papyrus.sysml.diagram.parametric.provider.InheritedCompositeDiagramViewProvider">
311
		<Priority name="Low"></Priority>
312
		
313
		<!-- Load the ViewProvider on following SemanticHint related to IElementType(s) used in the palette (also used for legacy elements) -->
314
		<context viewClass="org.eclipse.gmf.runtime.notation.Node" semanticHints="UML::Comment, UML::Constraint"></context>
315
		
316
		<!-- 
317
			"2109" = COMMENT
318
			"3097" = COMMENT_CN
319
			"2114" = CONSTRAINT								
320
			"3120" = CONSTRAINT_CN
321
		  -->			
322
		<context viewClass="org.eclipse.gmf.runtime.notation.Node" semanticHints="2109, 3097, 2114, 3120"></context>
323
		
324
		<!-- 
325
			"4002" = COMMENT_ANNOTATED_ELEMENT
326
			"4003" = CONSTRAINT_CONSTRAINED_ELEMENT
327
		  -->
328
		<context viewClass="org.eclipse.gmf.runtime.notation.Edge" semanticHints="4002, 4003"></context>
329
        
330
		<!-- Additional descriptors provided in case the semantic hint is is not provided -->	
331
		
332
        <!-- "uml.Comment" -->
333
		<object id="uml.Comment" class="org.eclipse.gmf.runtime.emf.core.util.IProxyEObject(org.eclipse.gmf.runtime.emf.core)">
334
			<method name="getProxyClassID()" value="uml.Comment"></method>
335
		</object>
336
337
        <!-- "uml.Constraint" -->
338
		<object id="uml.Constraint" class="org.eclipse.gmf.runtime.emf.core.util.IProxyEObject(org.eclipse.gmf.runtime.emf.core)">
339
			<method name="getProxyClassID()" value="uml.Constraint"></method>
340
		</object>
341
342
		<!-- Additional activation contexts for nodes semantic objects -->
343
		<context viewClass="org.eclipse.gmf.runtime.notation.Node" elements="uml.Comment, uml.Constraint"></context>
344
			
345
	</viewProvider>
346
</extension>
347
348
<!-- Diagram edit part providers declaration -->
349
<extension point="org.eclipse.gmf.runtime.diagram.ui.editpartProviders">	
350
	<!-- Diagram edit part provider -->
351
	<editpartProvider class="org.eclipse.papyrus.sysml.diagram.parametric.provider.ParametricDiagramEditPartProvider">
352
		<Priority name="Low"/>
353
		<object 
354
			id="org.eclipse.papyrus.sysml.diagram.parametric.Diagram"
355
			class="org.eclipse.gmf.runtime.notation.Diagram">
356
			<method name="getType()" value="Parametric"/>
357
		</object>
358
		<context views="org.eclipse.papyrus.sysml.diagram.parametric.Diagram"/>	
359
	</editpartProvider>
360
	
361
	<!-- Custom graphical types edit part provider -->
362
	<editpartProvider class="org.eclipse.papyrus.sysml.diagram.parametric.provider.CustomEditPartProvider">
363
		<Priority name="Medium"/>
364
	
365
		<object
366
			class="org.eclipse.gmf.runtime.notation.Node(org.eclipse.gmf.runtime.notation)"
367
			id="org.eclipse.papyrus.sysml.diagram.parametric.CustomNodeGraphicalTypes">
368
			<method name="getType()" value="shape_sysml_flowport_as_affixed, shape_uml_port_as_affixed, shape_sysml_block_as_composite, shape_sysml_blockproperty_as_composite, shape_sysml_constraintblockproperty_as_composite"/>
369
		</object>
370
		
371
		<object
372
			class="org.eclipse.gmf.runtime.notation.Node(org.eclipse.gmf.runtime.notation)"
373
			id="org.eclipse.papyrus.sysml.diagram.parametric.CustomGraphicalTypes_Decorations">
374
			<method name="getType()" value="linklabel_uml_connector_source_multiplicity, compartment_sysml_blockproperty_structure, linklabel_uml_connector_target_multiplicity, affixedlabel_sysml_flowport_label, compartment_sysml_structure, affixedlabel_uml_port_label, label_sysml_block_name, linklabel_uml_appliedstereotype, linklabel_uml_namedelement_name, linklabel_uml_connector_label, label_uml_property_label, shape_uml_constraint_as_label, affixedlabel_uml_appliedstereotype"/>
375
		</object>
376
		
377
		<context views="org.eclipse.papyrus.sysml.diagram.parametric.CustomNodeGraphicalTypes"/>
378
		<context views="org.eclipse.papyrus.sysml.diagram.parametric.CustomGraphicalTypes_Decorations"/>
379
	
380
		<object
381
			class="org.eclipse.gmf.runtime.notation.Edge(org.eclipse.gmf.runtime.notation)"
382
			id="org.eclipse.papyrus.sysml.diagram.parametric.CustomEdgeGraphicalTypes">
383
			<method name="getType()" value="link_uml_dependency, link_uml_connector"/>
384
		</object>
385
		
386
		<context views="org.eclipse.papyrus.sysml.diagram.parametric.CustomEdgeGraphicalTypes"/>
387
		
388
	</editpartProvider>
389
	
390
	<!-- EditPartProvider for inherited elements (from CompositeDiagram) -->
391
	<editpartProvider class="org.eclipse.papyrus.sysml.diagram.parametric.provider.InheritedCompositeDiagramEditPartProvider">
392
		<Priority name="Low"></Priority>
393
		
394
		<!-- 
395
			The semantic hints given here are used in case the provider is not already loaded.
396
			As soon as the provider is loaded its provides method is used.
397
			"2109" = COMMENT
398
			"5192" = COMMENT_LABEL_BODY_HINT
399
			"3097" = COMMENT_CN
400
			"5150" = COMMENT_CN_LABEL_BODY_HINT
401
			"2114" = CONSTRAINT
402
			"5197" = CONSTRAINT_LABEL_NAME_HINT
403
			"6039" = CONSTRAINT_LABEL_SPECIFICATION_HINT
404
			"3120" = CONSTRAINT_CN
405
			"6048" = CONSTRAINT_CN_LABEL_NAME_HINT
406
			"6049" = CONSTRAINT_CN_LABEL_SPECIFICATION_HINT
407
		 -->			
408
		<object id="COMMENT" class="org.eclipse.gmf.runtime.notation.Node">
409
			<method name="getType()" value="2109, 5192"></method>
410
		</object>
411
		<object id="COMMENT_CN" class="org.eclipse.gmf.runtime.notation.Node">
412
			<method name="getType()" value="3097, 5150"></method>
413
		</object>
414
		<object id="CONSTRAINT" class="org.eclipse.gmf.runtime.notation.Node">
415
			<method name="getType()" value="2114, 5197, 6039"></method>
416
		</object>
417
		<object id="CONSTRAINT_CN" class="org.eclipse.gmf.runtime.notation.Node">
418
			<method name="getType()" value="3120, 6048, 6049"></method>
419
		</object>
420
421
		<!-- 	
422
			"4002" = COMMENT_ANNOTATED_ELEMENT
423
			"4003" = CONSTRAINT_CONSTRAINED_ELEMENT
424
		  -->
425
		<object id="COMMENT_ANNOTATED_ELEMENT" class="org.eclipse.gmf.runtime.notation.Edge">
426
			<method name="getType()" value="4002"></method>
427
		</object>
428
		<object id="CONSTRAINT_CONSTRAINED_ELEMENT" class="org.eclipse.gmf.runtime.notation.Edge">
429
			<method name="getType()" value="4003"></method>
430
		</object>
431
432
		<context views="COMMENT, COMMENT_CN, CONSTRAINT, CONSTRAINT_CN"></context>
433
		<context views="COMMENT_ANNOTATED_ELEMENT, CONSTRAINT_CONSTRAINED_ELEMENT"></context>
434
		
435
	</editpartProvider>
436
	
437
</extension>
438
439
<!-- Diagram edit policy provider -->	
440
<extension
441
	point="org.eclipse.gmf.runtime.diagram.ui.editpolicyProviders">
442
	<editpolicyProvider
443
		class="org.eclipse.papyrus.sysml.diagram.parametric.provider.CustomEditPolicyProvider">
444
		<Priority name="Low"/>
445
	</editpolicyProvider>
446
</extension>
447
448
<!-- Preference pages declaration -->
449
<extension point="org.eclipse.ui.preferencePages" id="prefpages">
450
451
	<!-- Diagram Preference pages declaration -->
452
	<page
453
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
454
		name="Parametric Diagram"
455
		category="org.eclipse.papyrus.infra.gmfdiag.preferences.diagrams"
456
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.ParametricDiagramGeneralPreferencePage">
457
	</page>
458
459
	<!-- Element Preference pages declaration -->
460
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
461
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.ConstraintPreferencePage"
462
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.ConstraintPreferencePage"
463
		name="Constraint">
464
	</page>
465
	
466
	
467
	
468
	
469
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
470
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.CommentPreferencePage"
471
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.CommentPreferencePage"
472
		name="Comment">
473
	</page>
474
	
475
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
476
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.CommentAnnotatedElementPreferencePage"
477
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.CommentAnnotatedElementPreferencePage"
478
		name="CommentAnnotatedElement">
479
	</page>
480
	
481
	
482
483
484
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
485
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.BlockCompositePreferencePage"
486
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.BlockCompositePreferencePage"
487
		name="BlockComposite">
488
	</page>
489
		
490
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
491
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.CustomBlockPropertyCompositePreferencePage"
492
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.CustomBlockPropertyCompositePreferencePage"
493
		name="BlockPropertyComposite">
494
	</page>
495
		
496
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
497
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.CustomConstraintPropertyCompositePreferencePage"
498
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.CustomConstraintPropertyCompositePreferencePage"
499
		name="ConstraintPropertyComposite">
500
	</page>
501
		
502
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
503
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.FlowPortPreferencePage"
504
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.FlowPortPreferencePage"
505
		name="FlowPort">
506
	</page>
507
		
508
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
509
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.PortPreferencePage"
510
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.PortPreferencePage"
511
		name="Port">
512
	</page>
513
		
514
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
515
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.ConnectorPreferencePage"
516
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.ConnectorPreferencePage"
517
		name="Connector">
518
	</page>
519
		
520
	<page  	category="org.eclipse.papyrus.sysml.diagram.parametric.preferences"
521
		class="org.eclipse.papyrus.sysml.diagram.parametric.preferences.DependencyPreferencePage"
522
		id="org.eclipse.papyrus.sysml.diagram.parametric.preferences.DependencyPreferencePage"
523
		name="Dependency">
524
	</page>
525
		
526
527
</extension>
528
529
<!-- // Start of user code custom extensions 
530
  -->
531
<!-- Parser provider declaration -->
532
<extension point="org.eclipse.gmf.runtime.common.ui.services.parserProviders">
533
	<ParserProvider class="org.eclipse.papyrus.sysml.diagram.parametric.provider.ParserProvider">
534
		<Priority name="Low"></Priority>
535
	</ParserProvider>
536
</extension>
537
538
	<!-- Diagram specific advices -->
539
<extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypes">
540
	<metamodel nsURI="http://www.eclipse.org/uml2/4.0.0/UML">
541
		<!-- specific advices (pop up on creation) -->		
542
		<adviceBinding id="org.eclipse.papyrus.sysml.service.types.helper.ConstraintParameterEditHelperAdvice" 
543
			class="org.eclipse.papyrus.sysml.service.types.helper.ConstraintParameterEditHelperAdvice" 
544
			inheritance="none" 
545
			typeId="org.eclipse.papyrus.uml.Property"/>
546
	</metamodel>
547
</extension>
548
549
<!-- UML ElementType bindings to Papyrus shared IClientContext -->
550
<extension point="org.eclipse.gmf.runtime.emf.type.core.elementTypeBindings">
551
552
	<!-- Bindings declaration to shared IClientContext -->
553
	<binding context="org.eclipse.papyrus.infra.services.edit.TypeContext">	
554
		<elementType ref="org.eclipse.papyrus.sysml.service.types.helper.ConstraintParameterEditHelperAdvice"/>
555
	</binding>
556
		
557
</extension>
558
  
559
<!-- // End of user code 
560
  -->
561
562
</plugin>
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/ParametricDiagramCreateCommand.java (+168 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric;
2
3
import org.eclipse.core.commands.ExecutionException;
4
import org.eclipse.core.runtime.NullProgressMonitor;
5
import org.eclipse.emf.ecore.EObject;
6
import org.eclipse.emf.ecore.resource.Resource;
7
import org.eclipse.gmf.runtime.common.core.command.ICommand;
8
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
9
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
10
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
11
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
12
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
13
import org.eclipse.gmf.runtime.notation.Bounds;
14
import org.eclipse.gmf.runtime.notation.Diagram;
15
import org.eclipse.gmf.runtime.notation.Node;
16
import org.eclipse.gmf.runtime.notation.View;
17
import org.eclipse.papyrus.infra.gmfdiag.common.AbstractPapyrusGmfCreateDiagramCommandHandler;
18
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
19
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
20
import org.eclipse.papyrus.infra.services.edit.utils.GMFCommandUtils;
21
import org.eclipse.papyrus.sysml.blocks.Block;
22
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
23
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
24
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
25
import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
26
import org.eclipse.papyrus.uml.diagram.composite.part.UMLDiagramEditorPlugin;
27
import org.eclipse.uml2.uml.Element;
28
import org.eclipse.uml2.uml.Package;
29
import org.eclipse.uml2.uml.util.UMLUtil;
30
31
// Start of user code custom imports
32
//  End of user code
33
34
public class ParametricDiagramCreateCommand extends AbstractPapyrusGmfCreateDiagramCommandHandler {
35
36
	/**
37
	 * {@inheritDoc}
38
	 */
39
	@Override
40
	protected String getDefaultDiagramName() {
41
		return "NewParametricDiagram"; //$NON-NLS-1$
42
	}
43
44
	/**
45
	 * {@inheritDoc}
46
	 */
47
	@Override
48
	protected String getDiagramNotationID() {
49
		return ElementTypes.DIAGRAM_ID;
50
	}
51
52
	/**
53
	 * {@inheritDoc}
54
	 */
55
	@Override
56
	protected PreferencesHint getPreferenceHint() {
57
		return Activator.DIAGRAM_PREFERENCES_HINT;
58
	}
59
60
	/**
61
	 * {@inheritDoc}
62
	 */
63
	@Override
64
	protected Diagram createDiagram(Resource diagramResource, EObject owner, String name) {
65
		// Start of user code Custom diagram creation
66
		Diagram diagram = null;
67
68
		if(owner instanceof org.eclipse.uml2.uml.Class) {
69
			org.eclipse.uml2.uml.Class cOwner = (org.eclipse.uml2.uml.Class)owner;
70
			Block block = UMLUtil.getStereotypeApplication(cOwner, Block.class);
71
72
			if(block != null) {
73
				canvasDomainElement = (EObject)owner;
74
				Package owningPackage = ((Element)owner).getNearestPackage();
75
				diagram = super.createDiagram(diagramResource, owningPackage, name);
76
			}
77
78
		} else if(owner instanceof Package) {
79
80
			try {
81
				canvasDomainElement = null;
82
83
				IEditCommandRequest request = new CreateElementRequest((Package)owner, SysMLElementTypes.BLOCK);
84
				IElementEditService commandService = ElementEditServiceUtils.getCommandProvider(owner);
85
				if(commandService == null) {
86
					return null;
87
				}
88
89
				ICommand createElementCommand = commandService.getEditCommand(request);
90
				if((createElementCommand != null) && (createElementCommand.canExecute())) {
91
					createElementCommand.execute(new NullProgressMonitor(), null);
92
					EObject block = GMFCommandUtils.getCommandEObjectResult(createElementCommand);
93
					canvasDomainElement = block;
94
					diagram = super.createDiagram(diagramResource, (Package)owner, name);
95
				}
96
97
			} catch (ExecutionException e) {
98
				e.printStackTrace();
99
			}
100
101
		}
102
103
		return diagram;
104
		// End of user code
105
	}
106
107
	// Start of user code Custom creation command
108
	/** Domain Element referenced by canvas if it differs from {@link Package} */
109
	protected EObject canvasDomainElement = null;
110
111
	/** Default margin for the display of Domain Element referenced by canvas */
112
	protected static int DEFAULT_MARGIN = 20;
113
114
	/** Default height for the display of Domain Element referenced by canvas */
115
	protected static int DEFAULT_HEIGHT = 600;
116
117
	/** Default width for the display of Domain Element referenced by canvas */
118
	protected static int DEFAULT_WIDTH = 1000;
119
120
	/**
121
	 * Initialize the diagram. The diagram is attached to the element selected on creation.
122
	 * Possible element types are: Block.
123
	 */
124
	@Override
125
	protected void initializeDiagram(EObject diagram) {
126
		if(diagram instanceof Diagram) {
127
			Diagram currentDiagram = (Diagram)diagram;
128
			if(canvasDomainElement != null) {
129
				currentDiagram.setElement(canvasDomainElement);
130
				initializeDiagramContent(currentDiagram);
131
			}
132
		}
133
	}
134
135
	/**
136
	 * Initialize the diagram with the canvas domain element shown.
137
	 * 
138
	 * @param diagram
139
	 *        the diagram to initialize
140
	 */
141
	protected void initializeDiagramContent(Diagram diagram) {
142
143
		// Create a view for the canvasDomainElement in the new diagram
144
		View view =
145
			ViewService.getInstance().createNode(new SemanticAdapter(canvasDomainElement, null), diagram, SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID, ViewUtil.APPEND, true, UMLDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
146
		view.setElement(diagram.getElement());
147
148
		// Update the view position and size (should adapt to canvas current size)
149
		Bounds viewBounds = (Bounds)((Node)view).getLayoutConstraint();
150
		viewBounds.setX(DEFAULT_MARGIN);
151
		viewBounds.setY(DEFAULT_MARGIN);
152
		viewBounds.setHeight(DEFAULT_HEIGHT);
153
		viewBounds.setWidth(DEFAULT_WIDTH);
154
	}
155
156
	/**
157
	 * {@inheritDoc}
158
	 * 
159
	 * @generated NOT
160
	 */
161
	@Override
162
	public boolean isParentReassignable() {
163
		// Bug 374626: [Model Explorer] Moving an IBD from a block to another block shall be forbidden 
164
		return false;
165
	}
166
 	
167
 	// End of user code
168
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/ParametricDiagramEditorFactory.java (+12 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric;
2
3
import org.eclipse.papyrus.infra.gmfdiag.common.GmfEditorFactory;
4
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
5
6
public class ParametricDiagramEditorFactory extends GmfEditorFactory {
7
8
	public ParametricDiagramEditorFactory() {
9
		super(ParametricDiagramForMultiEditor.class, ElementTypes.DIAGRAM_ID);
10
	}
11
12
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/ParametricDiagramForMultiEditor.java (+103 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric;
2
3
import org.eclipse.core.runtime.CoreException;
4
import org.eclipse.emf.common.ui.URIEditorInput;
5
import org.eclipse.emf.ecore.util.EcoreUtil;
6
import org.eclipse.gmf.runtime.notation.Diagram;
7
import org.eclipse.jface.dialogs.ErrorDialog;
8
import org.eclipse.jface.resource.ImageDescriptor;
9
import org.eclipse.papyrus.infra.core.editor.BackboneException;
10
import org.eclipse.papyrus.infra.core.services.ServiceException;
11
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
12
import org.eclipse.papyrus.sysml.diagram.parametric.part.ParametricDiagramEditor;
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.Shell;
15
import org.eclipse.ui.IEditorInput;
16
import org.eclipse.ui.IEditorSite;
17
import org.eclipse.ui.PartInitException;
18
19
/**
20
 * An editor to be used in multitabs editor. This editor extends the original UML Diagram.
21
 * 
22
 */
23
public class ParametricDiagramForMultiEditor extends ParametricDiagramEditor {
24
25
	/**
26
	 * The location of diagram icon in the plug-in
27
	 */
28
	private static final String DIAG_IMG_PATH = "icons/obj16/Diagram_Parametric.png";
29
30
	/**
31
	 * The image descriptor of the diagram icon
32
	 */
33
	private static final ImageDescriptor DIAG_IMG_DESC = Activator.getBundledImageDescriptor(ParametricDiagramForMultiEditor.DIAG_IMG_PATH);
34
35
	/** The editor splitter. */
36
	private Composite splitter;
37
38
	/**
39
	 * Constructor for SashSystem v2. Context and required objects are retrieved from the
40
	 * ServiceRegistry.
41
	 * 
42
	 * @throws BackboneException
43
	 * @throws ServiceException
44
	 * 
45
	 */
46
	public ParametricDiagramForMultiEditor(ServicesRegistry servicesRegistry, Diagram diagram) throws BackboneException, ServiceException {
47
		super(servicesRegistry, diagram);
48
	}
49
50
	/**
51
	 * {@inheritDoc}
52
	 */
53
	@Override
54
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
55
		super.init(site, input);
56
		setPartName(getDiagram().getName());
57
		setTitleImage(DIAG_IMG_DESC.createImage());
58
	}
59
60
	/**
61
	 * {@inheritDoc}
62
	 */
63
	@Override
64
	public void setInput(IEditorInput input) {
65
		try {
66
			// Provide an URI with fragment in order to reuse the same Resource
67
			// and set the diagram to the fragment.
68
			URIEditorInput uriInput = new URIEditorInput(EcoreUtil.getURI(getDiagram()));
69
			doSetInput(uriInput, true);
70
		} catch (CoreException x) {
71
			String title = "Problem opening";
72
			String msg = "Cannot open input element:";
73
			Shell shell = getSite().getShell();
74
			ErrorDialog.openError(shell, title, msg, x.getStatus());
75
		}
76
	}
77
78
	/**
79
	 * {@inheritDoc}
80
	 */
81
	@Override
82
	protected void createGraphicalViewer(Composite parent) {
83
		splitter = parent;
84
		super.createGraphicalViewer(parent);
85
	}
86
87
	/**
88
	 * {@inheritDoc}
89
	 */
90
	@Override
91
	public void setFocus() {
92
		splitter.setFocus();
93
		super.setFocus();
94
	}
95
96
	/**
97
	 * {@inheritDoc}
98
	 */
99
	@Override
100
	public String getEditingDomainID() {
101
		return "org.eclipse.papyrus.sysml.diagram.parametric.EditingDomain";
102
	}
103
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/ParametricDiagramEditPart.java (+31 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.part;
2
3
import org.eclipse.gef.EditPolicy;
4
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
5
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
6
import org.eclipse.gmf.runtime.notation.View;
7
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultContainerNodeEditPolicy;
8
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultCreationEditPolicy;
9
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultXYLayoutEditPolicy;
10
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomDragDropEditPolicy;
11
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policy.DiagramSemanticEditPolicy;
12
import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomParametricSemanticPolicy;
13
import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy;
14
15
public class ParametricDiagramEditPart extends DiagramEditPart {
16
17
	public ParametricDiagramEditPart(View view) {
18
		super(view);
19
	}
20
21
	protected void createDefaultEditPolicies() {
22
		super.createDefaultEditPolicies();
23
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new DiagramSemanticEditPolicy());			
24
		installEditPolicy(DuplicatePasteEditPolicy.PASTE_ROLE, new DuplicatePasteEditPolicy());
25
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDragDropEditPolicy());
26
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new DefaultXYLayoutEditPolicy());
27
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new DefaultCreationEditPolicy());
28
		installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new DefaultContainerNodeEditPolicy());
29
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());			
30
	}
31
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/edit/policy/DiagramSemanticEditPolicy.java (+43 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policy;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gef.commands.UnexecutableCommand;
5
import org.eclipse.gef.requests.ReconnectRequest;
6
// Start of user code custom imports	
7
// End of user code
8
import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomDefaultSemanticEditPolicy;
9
10
public class DiagramSemanticEditPolicy extends CustomDefaultSemanticEditPolicy {
11
12
	/**
13
	 * {@inheritDoc}
14
	 */
15
	@Override
16
	protected Command getReorientRelationshipSourceCommand(ReconnectRequest request) {
17
		return UnexecutableCommand.INSTANCE;
18
	}
19
20
	/**
21
	 * {@inheritDoc}
22
	 */
23
	@Override
24
	protected Command getReorientRelationshipTargetCommand(ReconnectRequest request) {
25
		return UnexecutableCommand.INSTANCE;
26
	}
27
28
	/**
29
	 * {@inheritDoc}
30
	 */
31
	@Override
32
	protected Command getReorientRefRelationshipSourceCommand(ReconnectRequest request) {
33
		return UnexecutableCommand.INSTANCE;
34
	}
35
36
	/**
37
	 * {@inheritDoc}
38
	 */
39
	@Override
40
	protected Command getReorientRefRelationshipTargetCommand(ReconnectRequest request) {
41
		return UnexecutableCommand.INSTANCE;
42
	}	
43
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/edit/policy/ParametricDiagramDragDropEditPolicy.java (+38 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policy;
2
3
import org.eclipse.emf.ecore.EObject;
4
import org.eclipse.gmf.runtime.notation.View;
5
import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry;
6
import org.eclipse.papyrus.sysml.diagram.parametric.provider.GraphicalTypeRegistry;
7
import org.eclipse.papyrus.uml.diagram.composite.custom.edit.policies.CustomDiagramDragDropEditPolicy;
8
9
/** Customization of the DND edit policy for the Parametric Diagram */
10
public class ParametricDiagramDragDropEditPolicy extends CustomDiagramDragDropEditPolicy {
11
12
	/** Local graphical type registry */
13
	protected IGraphicalTypeRegistry registry = new GraphicalTypeRegistry();
14
15
	/**
16
	 * {@inheritDoc}
17
	 */
18
	@Override
19
	public int getNodeVisualID(View containerView, EObject domainElement) {
20
		String domainType = registry.getNodeGraphicalType(domainElement, containerView.getType());
21
		if (IGraphicalTypeRegistry.UNDEFINED_TYPE.equals(domainType)) {
22
			return -1; // undefined
23
		}
24
		return new Integer(domainType);
25
	}
26
	
27
	/**
28
	 * {@inheritDoc}
29
	 */
30
	@Override
31
	public int getLinkWithClassVisualID(EObject domainElement) {
32
		String domainType = registry.getEdgeGraphicalType(domainElement);
33
		if (IGraphicalTypeRegistry.UNDEFINED_TYPE.equals(domainType)) {
34
			return -1; // undefined
35
		}
36
		return new Integer(domainType);
37
	}
38
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/factory/DiagramPaletteFactory.java (+62 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.factory; 
2
3
import java.util.Arrays;
4
import java.util.HashMap;
5
6
import org.eclipse.gef.Tool;
7
import org.eclipse.gmf.runtime.diagram.ui.services.palette.PaletteFactory;
8
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
9
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.ElementTypes;
10
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
11
import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeConnectionTool;
12
import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeCreationTool;
13
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
14
15
@SuppressWarnings("serial")
16
public class DiagramPaletteFactory extends PaletteFactory.Adapter {
17
18
	private static HashMap<String, IElementType[]> nodesToolIdTypesMap = new HashMap<String, IElementType[]>() {
19
20
		{
21
			put("parametric.tool.blockcomposite", new IElementType[]{ SysMLElementTypes.BLOCK });	
22
			put("parametric.tool.blockpropertycomposite", new IElementType[]{ SysMLElementTypes.PART_PROPERTY });	
23
			put("parametric.tool.reference", new IElementType[]{ SysMLElementTypes.REFERENCE_PROPERTY });	
24
			put("parametric.tool.value", new IElementType[]{ SysMLElementTypes.VALUE_PROPERTY });	
25
			put("parametric.tool.constraintblockpropertycomposite", new IElementType[]{ SysMLElementTypes.CONSTRAINT_PROPERTY });	
26
			put("parametric.tool.flowport", new IElementType[]{ SysMLElementTypes.FLOW_PORT });	
27
			put("parametric.tool.port", new IElementType[]{ UMLElementTypes.PORT });	
28
			put("parametric.tool.parameter", new IElementType[]{ UMLElementTypes.PROPERTY });	
29
			//Start of user code Custom nodes
30
			put("parametric.tool.constraint", new IElementType[]{ UMLElementTypes.CONSTRAINT });
31
			put("parametric.tool.comment", new IElementType[]{ UMLElementTypes.COMMENT });				
32
			//End of user code
33
		}
34
	};
35
36
	private static HashMap<String, IElementType[]> edgesToolIdTypesMap = new HashMap<String, IElementType[]>() {
37
38
		{
39
			put("parametric.tool.connector", new IElementType[]{ UMLElementTypes.CONNECTOR });	
40
			put("parametric.tool.dependency", new IElementType[]{ UMLElementTypes.DEPENDENCY });	
41
			//Start of user code Custom edges
42
			put("parametric.tool.comment_constraint_link", new IElementType[]{ ElementTypes.COMMENT_ANNOTATED_ELEMENT, ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT });	
43
			//End of user code
44
		}
45
	};
46
47
	public Tool createTool(String toolId) {
48
49
		IElementType[] types;
50
		  
51
		types = nodesToolIdTypesMap.get(toolId);
52
		if(types != null) {
53
			return new AspectUnspecifiedTypeCreationTool(Arrays.asList(types));
54
		}
55
56
		types = edgesToolIdTypesMap.get(toolId);
57
		if(types != null) {
58
			return new AspectUnspecifiedTypeConnectionTool(Arrays.asList(types));
59
		}
60
		return null;
61
	}
62
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/factory/DiagramPaletteFactory.java.lost (+18 lines)
Added Link Here
1
2
Tue Jun 25 16:58:16 CEST 2013
3
================================================================================
4
Start of user code Custom nodes
5
				
6
			//End of user code
7
Start of user code Custom edges
8
				
9
			//End of user code
10
11
Tue Jun 25 17:00:48 CEST 2013
12
================================================================================
13
Start of user code Custom nodes
14
				
15
			//End of user code
16
Start of user code Custom edges
17
				
18
			//End of user code
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/factory/ParametricDiagramViewFactory.java (+18 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.factory;
2
3
import org.eclipse.gmf.runtime.diagram.ui.view.factories.DiagramViewFactory;
4
import org.eclipse.gmf.runtime.notation.MeasurementUnit;
5
6
public class ParametricDiagramViewFactory extends DiagramViewFactory {
7
8
	// Start of user code Custom view Factory field
9
	// End of user code
10
11
	/**
12
	 * {@inheritDoc}
13
	 */
14
	@Override
15
	protected MeasurementUnit getMeasurementUnit() {
16
		return MeasurementUnit.PIXEL_LITERAL;
17
	}
18
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/part/ParametricDiagramEditor.java (+51 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.part;
2
3
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
4
import org.eclipse.gmf.runtime.notation.Diagram;
5
import org.eclipse.papyrus.infra.core.services.ServiceException;
6
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
7
import org.eclipse.papyrus.sysml.diagram.parametric.Activator;
8
9
/**
10
 * @generated
11
 */
12
public class ParametricDiagramEditor extends org.eclipse.papyrus.uml.diagram.composite.part.UMLDiagramEditor {
13
14
	/** context used when trying to find services */
15
  public static final String ID = "org.eclipse.papyrus.sysml.diagram.parametric.part.ParametricDiagramEditorID"; //$NON-NLS-1$
16
17
  /**
18
   * {@inheritDoc}
19
   */
20
  @Override
21
  public String getContextID() {
22
    return CONTEXT_ID;
23
  }
24
25
  /**
26
	 * @throws org.eclipse.papyrus.infra.core.services.ServiceException 
27
 * @generated
28
	 */
29
	public ParametricDiagramEditor(ServicesRegistry servicesRegistry, Diagram diagram) throws ServiceException, org.eclipse.papyrus.infra.core.services.ServiceException {
30
    super(servicesRegistry, diagram);
31
  }
32
	
33
  // Start of user code Custom Editor Methods
34
	// End of user code
35
36
	/**
37
	 * @generated
38
	 */
39
	@Override
40
  public String getContributorId() {
41
    return Activator.PLUGIN_ID;
42
  }
43
44
	/**
45
	 * @generated
46
	 */
47
	@Override
48
  protected PreferencesHint getPreferencesHint() {
49
    return Activator.DIAGRAM_PREFERENCES_HINT;
50
  }
51
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/BlockCompositePreferencePage.java (+83 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences; 
2
3
import java.util.Collections;
4
import java.util.LinkedHashMap;
5
import java.util.Map;
6
7
import org.eclipse.jface.preference.IPreferenceStore;
8
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
9
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
10
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
11
12
public class BlockCompositePreferencePage extends ParametricDiagramNodePreferencePage {
13
14
	/** Constant key to access preferences */
15
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_" +  SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID; //$NON-NLS-1$
16
17
	/** The compartments default visibility for preferences */ 
18
	public static final Map<String, Boolean> compartmentDefaultVisibilityMap;
19
20
	/** The compartment titles default visibility for preferences */ 
21
	public static final Map<String, Boolean> compartmentTitleDefaultVisibilityMap;
22
		
23
	/** Static attribute initialization */
24
	static {
25
		compartmentDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
26
		compartmentDefaultVisibilityMap.put("structure", Boolean.TRUE); //$NON-NLS-1$	
27
		
28
		compartmentTitleDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
29
		compartmentTitleDefaultVisibilityMap.put("structure", Boolean.TRUE); //$NON-NLS-1$
30
		
31
		
32
		// Start of user code custom static initializations
33
 		// End of user code
34
 		
35
 		Collections.unmodifiableMap(compartmentDefaultVisibilityMap);
36
 		Collections.unmodifiableMap(compartmentTitleDefaultVisibilityMap);
37
	}
38
	
39
	/** Constructor */
40
	public BlockCompositePreferencePage() {
41
		super();
42
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_" +  SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID); //$NON-NLS-1$
43
	}
44
	
45
	/** Default preferences initializer */
46
	public static void initDefaults(IPreferenceStore store) {
47
		// Start of user code custom default initializations
48
		// End of user code
49
		
50
		// Initialize default visibility for compartments in preference page.
51
		for(String compartmentName : compartmentDefaultVisibilityMap.keySet()) {
52
			String showCompartmentKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, compartmentName, PreferenceConstantHelper.COMPARTMENT_VISIBILITY);
53
			store.setDefault(showCompartmentKey, compartmentDefaultVisibilityMap.get(compartmentName));
54
		}
55
56
		// Initialize default title visibility for compartments in preference page.
57
		for(String compartmentName : compartmentTitleDefaultVisibilityMap.keySet()) {
58
			String showCompartmentTitleKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, compartmentName, PreferenceConstantHelper.COMPARTMENT_NAME_VISIBILITY);
59
			store.setDefault(showCompartmentTitleKey, compartmentTitleDefaultVisibilityMap.get(compartmentName));
60
		}
61
	}
62
63
	/**
64
	 * {@inheritDoc}
65
	 */
66
	@Override
67
	protected void initializeCompartmentNamesList() {
68
		for(String name : compartmentDefaultVisibilityMap.keySet()) {
69
			this.compartmentNamesList.add(name);
70
		}
71
	}
72
73
	/**
74
	 * {@inheritDoc}
75
	 */
76
	@Override
77
	protected void initializeCompartmentTitlesList() {
78
		for(String name : compartmentTitleDefaultVisibilityMap.keySet()) {
79
			this.compartmentTitlesList.add(name);
80
		}
81
	}
82
	
83
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/CommentAnnotatedElementPreferencePage.java (+30 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
2
3
import org.eclipse.jface.preference.IPreferenceStore;
4
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
5
6
public class CommentAnnotatedElementPreferencePage extends ParametricDiagramLinkPreferencePage {
7
8
	/** Constant key to access preferences */
9
	protected static String prefKey = ElementTypes.DIAGRAM_ID + "_CommentAnnotatedElement";  //$NON-NLS-1$
10
11
		
12
	/** Default constructor */
13
	public CommentAnnotatedElementPreferencePage() {
14
		super();
15
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_CommentAnnotatedElement"); //$NON-NLS-1$
16
	}
17
	
18
	/**
19
	 * Initialize defaults using a specified {@link IPreferenceStore}
20
	 * 
21
	 * @param store
22
	 *        the preference store.
23
	 */	
24
	public static void initDefaults(IPreferenceStore store) {
25
		// Start of user code custom default initializations
26
 		// End of user code
27
 		
28
	}
29
	
30
}	
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/CommentPreferencePage.java (+31 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
2
3
import org.eclipse.jface.preference.IPreferenceStore;
4
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
5
6
public class CommentPreferencePage extends ParametricDiagramNodePreferencePage {
7
8
	/** Constant key to access preferences */
9
	protected static String prefKey = ElementTypes.DIAGRAM_ID + "_Comment"; //$NON-NLS-1$
10
11
	
12
	/** Default constructor */	
13
	public CommentPreferencePage() {
14
		super();
15
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_Comment"); //$NON-NLS-1$
16
	}
17
	
18
	/**
19
	 * Initialize defaults using a specified {@link IPreferenceStore}
20
	 * 
21
	 * @param store
22
	 *        the preference store.
23
	 */
24
	public static void initDefaults(IPreferenceStore store) {
25
		// Start of user code custom default initializations
26
 		// End of user code
27
		
28
	}
29
30
	
31
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ConnectorPreferencePage.java (+61 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences; 
2
3
import java.util.Collections;
4
import java.util.LinkedHashMap;
5
import java.util.Map;
6
7
import org.eclipse.jface.preference.IPreferenceStore;
8
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
9
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
10
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
11
12
public class ConnectorPreferencePage extends ParametricDiagramLinkPreferencePage {
13
14
	/** Constant key to access preferences */
15
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_" +  UMLGraphicalTypes.LINK_UML_CONNECTOR_ID; //$NON-NLS-1$
16
17
	/** The labels default visibility for preferences */
18
	public static final Map<String, Boolean> labelDefaultVisibilityMap;
19
	
20
	/** Static attribute initialization */
21
	static {
22
		labelDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
23
		labelDefaultVisibilityMap.put("Stereotype", Boolean.TRUE); //$NON-NLS-1$	
24
		labelDefaultVisibilityMap.put("Name", Boolean.TRUE); //$NON-NLS-1$	
25
		labelDefaultVisibilityMap.put("SourceMultiplicity", Boolean.TRUE); //$NON-NLS-1$	
26
		labelDefaultVisibilityMap.put("TargetMultiplicity", Boolean.TRUE); //$NON-NLS-1$	
27
		
28
		// Start of user code custom static initializations
29
 		// End of user code
30
31
		Collections.unmodifiableMap(labelDefaultVisibilityMap);		
32
	}	
33
	
34
	/** Constructor */	
35
	public ConnectorPreferencePage() {
36
		super();
37
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_" +  UMLGraphicalTypes.LINK_UML_CONNECTOR_ID); //$NON-NLS-1$
38
	}
39
40
	/** Default preferences initializer */	
41
	public static void initDefaults(IPreferenceStore store) {
42
		// Start of user code custom default initializations		
43
		// End of user code
44
		
45
		// Initialize default visibility for labels in preference page.
46
		for(String labelName : labelDefaultVisibilityMap.keySet()) {
47
			String showLabelKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, labelName, PreferenceConstantHelper.LABEL_VISIBILITY);
48
			store.setDefault(showLabelKey, labelDefaultVisibilityMap.get(labelName));
49
		}
50
	}
51
	
52
	/**
53
	 * {@inheritDoc}
54
	 */
55
	@Override
56
	protected void initializeLabelsList() {
57
		for(String name : labelDefaultVisibilityMap.keySet()) {
58
			this.labelsList.add(name);
59
		}
60
	}
61
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ConstraintConstrainedElementPreferencePage.java (+30 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
2
3
import org.eclipse.jface.preference.IPreferenceStore;
4
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
5
6
public class ConstraintConstrainedElementPreferencePage extends ParametricDiagramLinkPreferencePage {
7
8
	/** Constant key to access preferences */
9
	protected static String prefKey = ElementTypes.DIAGRAM_ID + "_ConstraintConstrainedElement";  //$NON-NLS-1$
10
11
		
12
	/** Default constructor */
13
	public ConstraintConstrainedElementPreferencePage() {
14
		super();
15
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_ConstraintConstrainedElement"); //$NON-NLS-1$
16
	}
17
	
18
	/**
19
	 * Initialize defaults using a specified {@link IPreferenceStore}
20
	 * 
21
	 * @param store
22
	 *        the preference store.
23
	 */	
24
	public static void initDefaults(IPreferenceStore store) {
25
		// Start of user code custom default initializations
26
 		// End of user code
27
 		
28
	}
29
	
30
}	
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ConstraintPreferencePage.java (+31 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
2
3
import org.eclipse.jface.preference.IPreferenceStore;
4
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
5
6
public class ConstraintPreferencePage extends ParametricDiagramNodePreferencePage {
7
8
	/** Constant key to access preferences */
9
	protected static String prefKey = ElementTypes.DIAGRAM_ID + "_Constraint"; //$NON-NLS-1$
10
11
	
12
	/** Default constructor */	
13
	public ConstraintPreferencePage() {
14
		super();
15
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_Constraint"); //$NON-NLS-1$
16
	}
17
	
18
	/**
19
	 * Initialize defaults using a specified {@link IPreferenceStore}
20
	 * 
21
	 * @param store
22
	 *        the preference store.
23
	 */
24
	public static void initDefaults(IPreferenceStore store) {
25
		// Start of user code custom default initializations
26
 		// End of user code
27
		
28
	}
29
30
	
31
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/DependencyPreferencePage.java (+59 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences; 
2
3
import java.util.Collections;
4
import java.util.LinkedHashMap;
5
import java.util.Map;
6
7
import org.eclipse.jface.preference.IPreferenceStore;
8
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
9
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
10
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
11
12
public class DependencyPreferencePage extends ParametricDiagramLinkPreferencePage {
13
14
	/** Constant key to access preferences */
15
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_" +  UMLGraphicalTypes.LINK_UML_DEPENDENCY_ID; //$NON-NLS-1$
16
17
	/** The labels default visibility for preferences */
18
	public static final Map<String, Boolean> labelDefaultVisibilityMap;
19
	
20
	/** Static attribute initialization */
21
	static {
22
		labelDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
23
		labelDefaultVisibilityMap.put("Stereotype", Boolean.TRUE); //$NON-NLS-1$	
24
		labelDefaultVisibilityMap.put("Name", Boolean.TRUE); //$NON-NLS-1$	
25
		
26
		// Start of user code custom static initializations
27
 		// End of user code
28
29
		Collections.unmodifiableMap(labelDefaultVisibilityMap);		
30
	}	
31
	
32
	/** Constructor */	
33
	public DependencyPreferencePage() {
34
		super();
35
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_" +  UMLGraphicalTypes.LINK_UML_DEPENDENCY_ID); //$NON-NLS-1$
36
	}
37
38
	/** Default preferences initializer */	
39
	public static void initDefaults(IPreferenceStore store) {
40
		// Start of user code custom default initializations		
41
		// End of user code
42
		
43
		// Initialize default visibility for labels in preference page.
44
		for(String labelName : labelDefaultVisibilityMap.keySet()) {
45
			String showLabelKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, labelName, PreferenceConstantHelper.LABEL_VISIBILITY);
46
			store.setDefault(showLabelKey, labelDefaultVisibilityMap.get(labelName));
47
		}
48
	}
49
	
50
	/**
51
	 * {@inheritDoc}
52
	 */
53
	@Override
54
	protected void initializeLabelsList() {
55
		for(String name : labelDefaultVisibilityMap.keySet()) {
56
			this.labelsList.add(name);
57
		}
58
	}
59
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/FlowPortPreferencePage.java (+60 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences; 
2
3
import java.util.Collections;
4
import java.util.LinkedHashMap;
5
import java.util.Map;
6
7
import org.eclipse.jface.preference.IPreferenceStore;
8
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
9
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
10
11
public class FlowPortPreferencePage extends ParametricDiagramNodePreferencePage {
12
13
	/** Constant key to access preferences */
14
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_shape_sysml_flowport_as_affixed"; //$NON-NLS-1$
15
16
	/** The labels default visibility for preferences */
17
	public static final Map<String, Boolean> labelDefaultVisibilityMap;
18
	
19
	/** Static attribute initialization */
20
	static {
21
		labelDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
22
		labelDefaultVisibilityMap.put("FlowPortAffixedLabel", Boolean.TRUE); //$NON-NLS-1$	
23
		labelDefaultVisibilityMap.put("AppliedStereotypeAffixedLabel", Boolean.TRUE); //$NON-NLS-1$	
24
		
25
		// Start of user code custom static initializations
26
 		// End of user code
27
28
		Collections.unmodifiableMap(labelDefaultVisibilityMap);		
29
	}	
30
	
31
	/** Constructor */	
32
	public FlowPortPreferencePage() {
33
		super();
34
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_shape_sysml_flowport_as_affixed"); //$NON-NLS-1$
35
	}
36
37
	/** Default preferences initializer */	
38
	public static void initDefaults(IPreferenceStore store) {
39
		// Start of user code custom default initializations
40
 		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.WIDTH), 20);
41
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.HEIGHT), 20);
42
		// End of user code
43
		
44
		// Initialize default visibility for labels in preference page.
45
		for(String labelName : labelDefaultVisibilityMap.keySet()) {
46
			String showLabelKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, labelName, PreferenceConstantHelper.LABEL_VISIBILITY);
47
			store.setDefault(showLabelKey, labelDefaultVisibilityMap.get(labelName));
48
		}
49
	}
50
	
51
	/**
52
	 * {@inheritDoc}
53
	 */
54
	@Override
55
	protected void initializeLabelsList() {
56
		for(String name : labelDefaultVisibilityMap.keySet()) {
57
			this.labelsList.add(name);
58
		}
59
	}
60
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ParametricDiagramGeneralPreferencePage.java (+11 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
2
3
import org.eclipse.papyrus.infra.gmfdiag.preferences.pages.DiagramPreferencePage;
4
import org.eclipse.papyrus.sysml.diagram.parametric.Activator;
5
6
public class ParametricDiagramGeneralPreferencePage extends DiagramPreferencePage {
7
8
	public ParametricDiagramGeneralPreferencePage() {
9
		setPreferenceStore(Activator.getInstance().getPreferenceStore());
10
	}
11
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ParametricDiagramLinkPreferencePage.java (+60 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
import java.util.TreeMap;
7
8
import org.eclipse.papyrus.infra.gmfdiag.preferences.pages.AbstractPapyrusLinkPreferencePage;
9
import org.eclipse.papyrus.infra.gmfdiag.preferences.ui.OrderedLabelGroup;
10
import org.eclipse.papyrus.sysml.diagram.parametric.Activator;
11
import org.eclipse.swt.widgets.Composite;
12
13
public class ParametricDiagramLinkPreferencePage extends AbstractPapyrusLinkPreferencePage {
14
15
	/** The list of label names for this link */
16
	protected List<String> labelsList;
17
	
18
	/** Constructor */
19
	public ParametricDiagramLinkPreferencePage() {
20
		labelsList = new ArrayList<String>();
21
		initializeLabelsList();
22
		Collections.unmodifiableList(labelsList);
23
	}
24
	
25
	/**
26
	 * {@inheritDoc}
27
	 */
28
	@Override
29
	protected void createPageContents(Composite parent) {
30
		super.createPageContents(parent);
31
32
		// Add label visibility group
33
		if(!labelsList.isEmpty()) {
34
			OrderedLabelGroup compartmentGroup = new OrderedLabelGroup(parent, getPreferenceKey(), this, labelsList);
35
			addAbstractGroup(compartmentGroup);
36
		}
37
38
	}
39
	
40
	/**
41
	 * {@inheritDoc}
42
	 */	
43
	@Override
44
	protected String getBundleId() {
45
		return Activator.PLUGIN_ID;
46
	}
47
	
48
	/** Initialize the list containing names of labels. */
49
	protected void initializeLabelsList() {
50
		//  Implemented by subclasses.
51
	}
52
	
53
	/**
54
	 * {@inheritDoc}
55
	 */
56
	@Override
57
	protected final TreeMap<String, String> getLabelRole() {
58
		return new TreeMap<String, String>();
59
	}
60
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ParametricDiagramNodePreferencePage.java (+106 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
2
3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.List;
6
import java.util.TreeMap;
7
8
import org.eclipse.papyrus.infra.gmfdiag.preferences.pages.AbstractPapyrusNodePreferencePage;
9
import org.eclipse.papyrus.infra.gmfdiag.preferences.ui.OrderedCompartmentGroup;
10
import org.eclipse.papyrus.infra.gmfdiag.preferences.ui.OrderedLabelGroup;
11
import org.eclipse.papyrus.sysml.diagram.parametric.Activator;
12
import org.eclipse.swt.widgets.Composite;
13
14
public class ParametricDiagramNodePreferencePage extends AbstractPapyrusNodePreferencePage {
15
16
	/** The list owning the names of compartments */
17
	protected List<String> compartmentNamesList;
18
	
19
	/** The list owning the names of compartment that have a title */
20
	protected List<String> compartmentTitlesList;
21
22
	/** The list of label names for this node */
23
	protected List<String> labelsList;
24
	
25
	/** Constructor */
26
	public ParametricDiagramNodePreferencePage() {
27
		this.labelsList = new ArrayList<String>();
28
		this.compartmentNamesList = new ArrayList<String>();
29
		this.compartmentTitlesList = new ArrayList<String>();
30
31
		initializeLabelsList();
32
		initializeCompartmentNamesList();
33
		initializeCompartmentTitlesList();
34
35
		Collections.unmodifiableList(labelsList);
36
		Collections.unmodifiableList(compartmentNamesList);
37
		Collections.unmodifiableList(compartmentTitlesList);
38
	}
39
	
40
	/**
41
	 * {@inheritDoc}
42
	 */
43
	@Override
44
	protected void createPageContents(Composite parent) {
45
		super.createPageContents(parent);
46
		
47
		// Add compartments visibility group
48
		if(!compartmentNamesList.isEmpty()) {
49
			OrderedCompartmentGroup compartmentGroup = new OrderedCompartmentGroup(parent, getPreferenceKey(), this, compartmentNamesList, compartmentTitlesList, getPreferenceStore());
50
			addAbstractGroup(compartmentGroup);
51
		}
52
53
		// Add label visibility group
54
		if(!labelsList.isEmpty()) {
55
			OrderedLabelGroup compartmentGroup = new OrderedLabelGroup(parent, getPreferenceKey(), this, labelsList);
56
			addAbstractGroup(compartmentGroup);
57
		}
58
	}
59
	
60
	/**
61
	 * {@inheritDoc}
62
	 */
63
	@Override
64
	protected String getBundleId() {
65
		return Activator.PLUGIN_ID;
66
	}
67
68
	/** Initialize the list containing names of labels. */
69
	protected void initializeLabelsList() {
70
		//  Implemented by subclasses.
71
	}
72
73
	/** Initialize the list containing the names of compartments. */
74
	protected void initializeCompartmentNamesList() {
75
		//  Implemented by subclasses.
76
	}
77
	
78
	/** Initialize the list containing the names of compartment that have titles. */
79
	protected void initializeCompartmentTitlesList() {
80
		//  Implemented by subclasses.
81
	}
82
83
	/**
84
	 * {@inheritDoc}
85
	 */
86
	@Override
87
	protected final TreeMap<String, String> getLabelRole() {
88
		return new TreeMap<String, String>();
89
	}
90
91
	/**
92
	 * {@inheritDoc}
93
	 */
94
	@Override
95
	protected final TreeMap<String, Boolean> getCompartmentTitleVisibilityPreferences() {
96
		return new TreeMap<String, Boolean>();
97
	}
98
	
99
	/**
100
	 * {@inheritDoc}
101
	 */
102
	@Override
103
	protected final void initializeCompartmentsList() {
104
		compartmentsList = Collections.emptyList();
105
	}
106
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ParametricDiagramPreferenceInitializer.java (+28 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
2
3
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
4
import org.eclipse.jface.preference.IPreferenceStore;
5
import org.eclipse.papyrus.sysml.diagram.parametric.Activator;
6
7
public class ParametricDiagramPreferenceInitializer extends AbstractPreferenceInitializer {
8
9
	protected IPreferenceStore getPreferenceStore() {
10
		return Activator.getInstance().getPreferenceStore();
11
	}
12
13
	@Override
14
	public void initializeDefaultPreferences() {
15
		IPreferenceStore store = getPreferenceStore();
16
		
17
		org.eclipse.papyrus.sysml.diagram.parametric.preferences.ConstraintPreferencePage.initDefaults(store);			
18
		org.eclipse.papyrus.sysml.diagram.parametric.preferences.CommentPreferencePage.initDefaults(store);			
19
		org.eclipse.papyrus.sysml.diagram.parametric.preferences.CommentAnnotatedElementPreferencePage.initDefaults(store);
20
		BlockCompositePreferencePage.initDefaults(store);
21
		BlockPropertyCompositePreferencePage.initDefaults(store);
22
		FlowPortPreferencePage.initDefaults(store);
23
		PortPreferencePage.initDefaults(store);
24
		ConnectorPreferencePage.initDefaults(store);
25
		DependencyPreferencePage.initDefaults(store);
26
		
27
	}
28
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/preferences/PortPreferencePage.java (+60 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.preferences; 
2
3
import java.util.Collections;
4
import java.util.LinkedHashMap;
5
import java.util.Map;
6
7
import org.eclipse.jface.preference.IPreferenceStore;
8
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
9
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
10
11
public class PortPreferencePage extends ParametricDiagramNodePreferencePage {
12
13
	/** Constant key to access preferences */
14
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_shape_uml_port_as_affixed"; //$NON-NLS-1$
15
16
	/** The labels default visibility for preferences */
17
	public static final Map<String, Boolean> labelDefaultVisibilityMap;
18
	
19
	/** Static attribute initialization */
20
	static {
21
		labelDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
22
		labelDefaultVisibilityMap.put("PortAffixedLabel", Boolean.TRUE); //$NON-NLS-1$	
23
		labelDefaultVisibilityMap.put("AppliedStereotypeAffixedLabel", Boolean.TRUE); //$NON-NLS-1$	
24
		
25
		// Start of user code custom static initializations
26
 		// End of user code
27
28
		Collections.unmodifiableMap(labelDefaultVisibilityMap);		
29
	}	
30
	
31
	/** Constructor */	
32
	public PortPreferencePage() {
33
		super();
34
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_shape_uml_port_as_affixed"); //$NON-NLS-1$
35
	}
36
37
	/** Default preferences initializer */	
38
	public static void initDefaults(IPreferenceStore store) {
39
		// Start of user code custom default initializations
40
 		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.WIDTH), 20);
41
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.HEIGHT), 20);
42
		// End of user code
43
		
44
		// Initialize default visibility for labels in preference page.
45
		for(String labelName : labelDefaultVisibilityMap.keySet()) {
46
			String showLabelKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, labelName, PreferenceConstantHelper.LABEL_VISIBILITY);
47
			store.setDefault(showLabelKey, labelDefaultVisibilityMap.get(labelName));
48
		}
49
	}
50
	
51
	/**
52
	 * {@inheritDoc}
53
	 */
54
	@Override
55
	protected void initializeLabelsList() {
56
		for(String name : labelDefaultVisibilityMap.keySet()) {
57
			this.labelsList.add(name);
58
		}
59
	}
60
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomEditPartProvider.java (+120 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider; 
2
3
import java.util.HashMap;
4
import java.util.Map;
5
6
import org.eclipse.gmf.runtime.common.core.service.IOperation;
7
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation;
8
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
9
import org.eclipse.gmf.runtime.notation.Edge;
10
import org.eclipse.gmf.runtime.notation.Node;
11
import org.eclipse.gmf.runtime.notation.View;
12
import org.eclipse.papyrus.gmf.diagram.common.provider.CustomAbstractEditPartProvider;
13
import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyStructureCompartmentEditPart;
14
import org.eclipse.papyrus.sysml.diagram.common.edit.part.FlowPortAffixedLabelNameEditPart;
15
import org.eclipse.papyrus.sysml.diagram.common.edit.part.FlowPortAffixedNodeEditPart;
16
import org.eclipse.papyrus.sysml.diagram.common.edit.part.StructureCompartmentEditPart;
17
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
18
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomBlockCompositeEditPartTN;
19
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomBlockLabelNameEditPart;
20
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomBlockPropertyCompositeEditPart;
21
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintBlockPropertyCompositeEditPart;
22
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomConstraintParameterAffixedNodeEditPart;
23
import org.eclipse.papyrus.uml.diagram.common.edit.part.AppliedStereotypeAffixedLabelEditPart;
24
import org.eclipse.papyrus.uml.diagram.common.edit.part.AppliedStereotypeLinkLabelEditPart;
25
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConnectorEditPart;
26
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConnectorLinkLabelEditPart;
27
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConnectorLinkLabelSourceMultiplicityEditPart;
28
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConnectorLinkLabelTargetMultiplicityEditPart;
29
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintNodeLabelEditPart;
30
import org.eclipse.papyrus.uml.diagram.common.edit.part.DependencyEditPart;
31
import org.eclipse.papyrus.uml.diagram.common.edit.part.NamedElementLinkLabelNameEditPart;
32
import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedLabelNameEditPart;
33
import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedNodeEditPart;
34
import org.eclipse.papyrus.uml.diagram.common.edit.part.PropertyNodeLabelEditPart;
35
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
36
37
public class CustomEditPartProvider extends CustomAbstractEditPartProvider {
38
39
	/** Map containing node view types supported by this provider */
40
	protected Map<String, Class<?>> nodeMap = new HashMap<String, Class<?>>();
41
42
	/** Map containing edge view types supported by this provider */
43
	protected Map<String, Class<?>> edgeMap = new HashMap<String, Class<?>>();
44
45
	/** Default constructor */
46
	public CustomEditPartProvider() {
47
		super();
48
49
		diagramType = ElementTypes.DIAGRAM_ID;
50
51
		// Nodes
52
		nodeMap.put(SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID, CustomConstraintBlockPropertyCompositeEditPart.class);	
53
		nodeMap.put(SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID, CustomBlockPropertyCompositeEditPart.class);	
54
		nodeMap.put(SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID, CustomBlockCompositeEditPartTN.class);	
55
		nodeMap.put(SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID, FlowPortAffixedNodeEditPart.class);	
56
		nodeMap.put(UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID, PortAffixedNodeEditPart.class);	
57
		nodeMap.put(UMLGraphicalTypes.SHAPE_UML_PROPERTY_AS_AFFIXED_ID, CustomConstraintParameterAffixedNodeEditPart.class);
58
		
59
		// Decorations
60
		nodeMap.put(SysMLGraphicalTypes.AFFIXEDLABEL_SYSML_FLOWPORT_LABEL_ID, FlowPortAffixedLabelNameEditPart.class);	
61
		nodeMap.put(SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID, BlockPropertyStructureCompartmentEditPart.class);	
62
		nodeMap.put(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID, StructureCompartmentEditPart.class);	
63
		nodeMap.put(SysMLGraphicalTypes.LABEL_SYSML_BLOCK_NAME_ID, CustomBlockLabelNameEditPart.class); // TODO : change for multi FlowText 
64
		nodeMap.put(UMLGraphicalTypes.AFFIXEDLABEL_UML_APPLIEDSTEREOTYPE_ID, AppliedStereotypeAffixedLabelEditPart.class);	
65
		nodeMap.put(UMLGraphicalTypes.AFFIXEDLABEL_UML_PORT_LABEL_ID, PortAffixedLabelNameEditPart.class);	
66
		nodeMap.put(UMLGraphicalTypes.LABEL_UML_PROPERTY_LABEL_ID, PropertyNodeLabelEditPart.class);	
67
		nodeMap.put(UMLGraphicalTypes.SHAPE_UML_CONSTRAINT_AS_LABEL_ID, ConstraintNodeLabelEditPart.class);	
68
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_APPLIEDSTEREOTYPE_ID, AppliedStereotypeLinkLabelEditPart.class);	
69
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_LABEL_ID, ConnectorLinkLabelEditPart.class);	
70
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_SOURCE_MULTIPLICITY_ID, ConnectorLinkLabelSourceMultiplicityEditPart.class);	
71
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_TARGET_MULTIPLICITY_ID, ConnectorLinkLabelTargetMultiplicityEditPart.class);	
72
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_NAMEDELEMENT_NAME_ID, NamedElementLinkLabelNameEditPart.class);	
73
74
		
75
		// Edges
76
		edgeMap.put(UMLGraphicalTypes.LINK_UML_CONNECTOR_ID, ConnectorEditPart.class);	
77
		edgeMap.put(UMLGraphicalTypes.LINK_UML_DEPENDENCY_ID, DependencyEditPart.class);	
78
	}
79
80
	/**
81
	 * {@inheritDoc}
82
	 */
83
	@Override
84
	public boolean provides(IOperation operation) {
85
		if(operation instanceof CreateGraphicEditPartOperation) {
86
			View newView = ((IEditPartOperation)operation).getView();
87
			if (newView == null) {
88
				return false;
89
			}
90
			
91
			String graphicalType = newView.getType();
92
93
			if((newView instanceof Node) && (!nodeMap.containsKey(graphicalType))) {
94
				return false;
95
			}
96
			
97
			if((newView instanceof Edge) && (!edgeMap.containsKey(graphicalType))) {
98
				return false;
99
			}
100
		}
101
102
		return super.provides(operation);
103
	}
104
105
	/**
106
	 * {@inheritDoc}
107
	 */
108
	@Override
109
	protected Class<?> getNodeEditPartClass(View view) {
110
		return nodeMap.get(view.getType());
111
	}
112
	
113
	/**
114
	 * {@inheritDoc}
115
	 */
116
	@Override
117
	protected Class<?> getEdgeEditPartClass(View view) {
118
		return edgeMap.get(view.getType());
119
	}
120
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomGraphicalTypeRegistry.java (+224 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider; 
2
3
import org.eclipse.emf.ecore.EObject;
4
import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
5
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
6
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
7
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
8
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
9
		
10
public class CustomGraphicalTypeRegistry extends GraphicalTypeRegistry {
11
12
	/** Default constructor */
13
	public CustomGraphicalTypeRegistry() {
14
		
15
		super();
16
		
17
		// Nodes
18
		knownNodes.add(SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID);	
19
		knownNodes.add(SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID);	
20
		knownNodes.add(SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID);	
21
		knownNodes.add(SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID);	
22
		knownNodes.add(UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID);	
23
		knownNodes.add(UMLGraphicalTypes.SHAPE_UML_PROPERTY_AS_AFFIXED_ID);	
24
		// Decorations
25
		knownNodes.add(SysMLGraphicalTypes.AFFIXEDLABEL_SYSML_FLOWPORT_LABEL_ID);	
26
		knownNodes.add(SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID);	
27
		knownNodes.add(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID);	
28
		knownNodes.add(SysMLGraphicalTypes.LABEL_SYSML_BLOCK_NAME_ID);	
29
		knownNodes.add(UMLGraphicalTypes.AFFIXEDLABEL_UML_APPLIEDSTEREOTYPE_ID);	
30
		knownNodes.add(UMLGraphicalTypes.AFFIXEDLABEL_UML_PORT_LABEL_ID);	
31
		knownNodes.add(UMLGraphicalTypes.LABEL_UML_PROPERTY_LABEL_ID);	
32
		knownNodes.add(UMLGraphicalTypes.SHAPE_UML_CONSTRAINT_AS_LABEL_ID);	
33
		knownNodes.add(UMLGraphicalTypes.LINKLABEL_UML_APPLIEDSTEREOTYPE_ID);	
34
		knownNodes.add(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_LABEL_ID);	
35
		knownNodes.add(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_SOURCE_MULTIPLICITY_ID);	
36
		knownNodes.add(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_TARGET_MULTIPLICITY_ID);	
37
		knownNodes.add(UMLGraphicalTypes.LINKLABEL_UML_NAMEDELEMENT_NAME_ID);	
38
	
39
		// Edges
40
		knownEdges.add(UMLGraphicalTypes.LINK_UML_CONNECTOR_ID);
41
		knownEdges.add(UMLGraphicalTypes.LINK_UML_DEPENDENCY_ID);
42
	}
43
	
44
	/**
45
	 * {@inheritDoc}
46
	 */
47
	@Override
48
	public String getNodeGraphicalType(EObject domainElement, String containerType) {
49
		// Start of user code getNodeGraphicalType(EObject domainElement, String containerType)	
50
		// End of user code
51
	
52
		if(((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(domainElement)) {
53
			if (ElementTypes.DIAGRAM_ID.equals(containerType)) {
54
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID;
55
			}	
56
			return UNDEFINED_TYPE;
57
		}
58
		if(((ISpecializationType)SysMLElementTypes.CONSTRAINT_PROPERTY).getMatcher().matches(domainElement)) {
59
			if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(domainElement)) {
60
				return SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID;
61
			}	
62
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
63
				return SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID;
64
			}	
65
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
66
				return SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID;
67
			}		
68
			return UNDEFINED_TYPE;
69
		}		
70
71
		if(((ISpecializationType)SysMLElementTypes.PART_PROPERTY).getMatcher().matches(domainElement)) {
72
			if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) {
73
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
74
			}	
75
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
76
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
77
			}	
78
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
79
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
80
			}	
81
			return UNDEFINED_TYPE;
82
		}		
83
		if(((ISpecializationType)SysMLElementTypes.REFERENCE_PROPERTY).getMatcher().matches(domainElement)) {
84
			if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) {
85
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
86
			}	
87
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
88
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
89
			}	
90
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
91
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
92
			}	
93
			return UNDEFINED_TYPE;
94
		}
95
		if(((ISpecializationType)SysMLElementTypes.VALUE_PROPERTY).getMatcher().matches(domainElement)) {
96
			if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) {
97
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
98
			}	
99
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
100
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
101
			}	
102
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
103
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
104
			}	
105
			return UNDEFINED_TYPE;
106
		}
107
		// Order is important for Part/Reference/ConstraintProperty which are also Property
108
		if(UMLElementTypes.PROPERTY.getEClass().isInstance(domainElement)) {
109
			if (SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID.equals(containerType)) {
110
				return UMLGraphicalTypes.SHAPE_UML_PROPERTY_AS_AFFIXED_ID;
111
			}	
112
			return UNDEFINED_TYPE;
113
114
		}		
115
116
		return super.getNodeGraphicalType(domainElement, containerType);
117
	}	
118
	
119
	/**
120
	 * {@inheritDoc}
121
	 */
122
	public String getNodeGraphicalType(String proposedType, String containerType) {
123
		// Start of user code getNodeGraphicalType(String proposedType, String containerType)
124
		// End of user code
125
	
126
		if(SysMLElementTypes.BLOCK.getSemanticHint().equals(proposedType)) {
127
			if (ElementTypes.DIAGRAM_ID.equals(containerType)) {
128
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID;
129
			}	
130
			return UNDEFINED_TYPE;
131
		}		
132
		
133
		if(UMLElementTypes.PROPERTY.getSemanticHint().equals(proposedType)) {	
134
			if (SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID.equals(containerType)) {
135
				return UMLGraphicalTypes.SHAPE_UML_PROPERTY_AS_AFFIXED_ID;
136
			}	
137
			return UNDEFINED_TYPE;
138
		}	
139
		
140
		if(SysMLElementTypes.CONSTRAINT_PROPERTY.getSemanticHint().equals(proposedType)) {
141
			if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) {
142
				return SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID;
143
			}	
144
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
145
				return SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID;
146
			}	
147
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
148
				return SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID;
149
			}	
150
			return UNDEFINED_TYPE;
151
		}		
152
153
		if(SysMLElementTypes.PART_PROPERTY.getSemanticHint().equals(proposedType)) {
154
			if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) {
155
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
156
			}	
157
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
158
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
159
			}	
160
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
161
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
162
			}	
163
			return UNDEFINED_TYPE;
164
		}		
165
		if(SysMLElementTypes.REFERENCE_PROPERTY.getSemanticHint().equals(proposedType)) {
166
			if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) {
167
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
168
			}	
169
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
170
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
171
			}	
172
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
173
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
174
			}	
175
			return UNDEFINED_TYPE;
176
		}		
177
		if(SysMLElementTypes.VALUE_PROPERTY.getSemanticHint().equals(proposedType)) {
178
			if (SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID.equals(containerType)) {
179
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
180
			}	
181
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
182
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
183
			}	
184
			if (SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
185
				return SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID;
186
			}	
187
			return UNDEFINED_TYPE;
188
		}		
189
		return super.getNodeGraphicalType(proposedType, containerType);
190
	}	
191
	
192
	/**
193
	 * {@inheritDoc}
194
	 */
195
	@Override
196
	public String getEdgeGraphicalType(EObject domainElement) {
197
		// Start of user code getEdgeGraphicalType(EObject domainElement)	
198
		// End of user code
199
	
200
		if(UMLElementTypes.CONNECTOR.getEClass().isInstance(domainElement)) {
201
			return UMLGraphicalTypes.LINK_UML_CONNECTOR_ID;
202
		}		
203
		if(UMLElementTypes.DEPENDENCY.getEClass().isInstance(domainElement)) {
204
			return UMLGraphicalTypes.LINK_UML_DEPENDENCY_ID;
205
		}		
206
		return super.getEdgeGraphicalType(domainElement);
207
	}	
208
	
209
	/**
210
	 * {@inheritDoc}
211
	 */
212
	public String getEdgeGraphicalType(String proposedType) {
213
		// Start of user code getEdgeGraphicalType(String proposedType)
214
		// End of user code
215
	
216
		if(UMLElementTypes.CONNECTOR.getSemanticHint().equals(proposedType)) {
217
			return UMLGraphicalTypes.LINK_UML_CONNECTOR_ID;
218
		}		
219
		if(UMLElementTypes.DEPENDENCY.getSemanticHint().equals(proposedType)) {
220
			return UMLGraphicalTypes.LINK_UML_DEPENDENCY_ID;
221
		}		
222
		return super.getEdgeGraphicalType(proposedType);
223
	}		
224
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomGraphicalTypes.java (+13 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider; 
2
3
public class CustomGraphicalTypes {
4
5
	/** ********************************************************* */
6
	/** Diagram custom graphical types id *********************** */
7
	/** ********************************************************* */
8
9
10
11
12
13
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomViewProvider.java (+87 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider; 
2
3
import java.util.HashMap;
4
import java.util.Map;
5
6
import org.eclipse.core.runtime.IAdaptable;
7
import org.eclipse.gmf.runtime.notation.View;
8
import org.eclipse.papyrus.gmf.diagram.common.factory.AffixedLabelViewFactory;
9
import org.eclipse.papyrus.gmf.diagram.common.factory.CompartmentShapeViewFactory;
10
import org.eclipse.papyrus.gmf.diagram.common.factory.ConnectorLabelViewFactory;
11
import org.eclipse.papyrus.gmf.diagram.common.factory.InnerLabelViewFactory;
12
import org.eclipse.papyrus.gmf.diagram.common.provider.CustomAbstractViewProvider;
13
import org.eclipse.papyrus.sysml.diagram.common.factory.BlockCompositeClassifierViewFactory;
14
import org.eclipse.papyrus.sysml.diagram.common.factory.BlockPropertyCompositeClassifierViewFactory;
15
import org.eclipse.papyrus.sysml.diagram.common.factory.ConstraintBlockPropertyCompositeClassifierViewFactory;
16
import org.eclipse.papyrus.sysml.diagram.common.factory.FlowPortAffixedNodeViewFactory;
17
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
18
import org.eclipse.papyrus.uml.diagram.common.factory.ConnectorLinkViewFactory;
19
import org.eclipse.papyrus.uml.diagram.common.factory.ConstraintPropertyAffixedNodeViewFactory;
20
import org.eclipse.papyrus.uml.diagram.common.factory.DependencyLinkViewFactory;
21
import org.eclipse.papyrus.uml.diagram.common.factory.PortAffixedNodeViewFactory;
22
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
23
24
public class CustomViewProvider extends CustomAbstractViewProvider {
25
26
	/** Map containing node view types supported by this provider */
27
	protected Map<String, Class<?>> nodeMap = new HashMap<String, Class<?>>();
28
	
29
	/** Map containing edge view types supported by this provider */
30
	protected Map<String, Class<?>> edgeMap = new HashMap<String, Class<?>>();
31
	
32
	/** Default constructor */
33
	public CustomViewProvider() {
34
		super();
35
		this.registry = new CustomGraphicalTypeRegistry();
36
37
		diagramType = ElementTypes.DIAGRAM_ID;
38
		
39
		// Custom classifier nodes
40
		nodeMap.put(SysMLGraphicalTypes.SHAPE_SYSML_BLOCK_AS_COMPOSITE_ID, BlockCompositeClassifierViewFactory.class);
41
		nodeMap.put(SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID, BlockPropertyCompositeClassifierViewFactory.class);
42
		nodeMap.put(SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID, ConstraintBlockPropertyCompositeClassifierViewFactory.class);
43
		nodeMap.put(UMLGraphicalTypes.SHAPE_UML_PROPERTY_AS_AFFIXED_ID, ConstraintPropertyAffixedNodeViewFactory.class);
44
		// Custom affixed nodes
45
		nodeMap.put(SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID, FlowPortAffixedNodeViewFactory.class);
46
		nodeMap.put(UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID, PortAffixedNodeViewFactory.class);
47
		// Custom child node labels
48
		// Custom inner labels
49
		nodeMap.put(SysMLGraphicalTypes.LABEL_SYSML_BLOCK_NAME_ID, InnerLabelViewFactory.class);
50
		nodeMap.put(UMLGraphicalTypes.LABEL_UML_PROPERTY_LABEL_ID, InnerLabelViewFactory.class);
51
		nodeMap.put(UMLGraphicalTypes.SHAPE_UML_CONSTRAINT_AS_LABEL_ID, InnerLabelViewFactory.class);
52
		// Custom compartments
53
		nodeMap.put(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID, CompartmentShapeViewFactory.class);		
54
		nodeMap.put(SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID, CompartmentShapeViewFactory.class);
55
		// Custom affixed labels
56
		nodeMap.put(SysMLGraphicalTypes.AFFIXEDLABEL_SYSML_FLOWPORT_LABEL_ID, AffixedLabelViewFactory.class);
57
		nodeMap.put(UMLGraphicalTypes.AFFIXEDLABEL_UML_APPLIEDSTEREOTYPE_ID, AffixedLabelViewFactory.class);
58
		nodeMap.put(UMLGraphicalTypes.AFFIXEDLABEL_UML_PORT_LABEL_ID, AffixedLabelViewFactory.class);
59
		
60
		// Custom edges
61
		edgeMap.put(UMLGraphicalTypes.LINK_UML_CONNECTOR_ID, ConnectorLinkViewFactory.class);
62
		edgeMap.put(UMLGraphicalTypes.LINK_UML_DEPENDENCY_ID, DependencyLinkViewFactory.class);
63
64
		// Custom edge labels
65
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_APPLIEDSTEREOTYPE_ID, ConnectorLabelViewFactory.class);
66
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_LABEL_ID, ConnectorLabelViewFactory.class);
67
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_SOURCE_MULTIPLICITY_ID, ConnectorLabelViewFactory.class);
68
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_TARGET_MULTIPLICITY_ID, ConnectorLabelViewFactory.class);
69
		nodeMap.put(UMLGraphicalTypes.LINKLABEL_UML_NAMEDELEMENT_NAME_ID, ConnectorLabelViewFactory.class);
70
	}
71
72
	/**
73
	 * {@inheritDoc}
74
	 */
75
	@Override
76
	protected Class<?> getNodeViewClass(IAdaptable semanticAdapter, View containerView, String graphicalType) {
77
		return nodeMap.get(graphicalType);
78
	}
79
	
80
	/**
81
	 * {@inheritDoc}
82
	 */
83
	@Override
84
	protected Class<?> getEdgeViewClass(IAdaptable semanticAdapter, View containerView, String graphicalType) {
85
		return edgeMap.get(graphicalType);
86
	}
87
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/ElementTypes.java (+52 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
2
3
import org.eclipse.gmf.runtime.emf.type.core.AbstractElementTypeEnumerator;
4
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
5
6
public class ElementTypes extends AbstractElementTypeEnumerator {
7
8
	/** ********************************************************* */
9
	/** SysML Parametric Diagram specific elements **************** */
10
	/** ********************************************************* */
11
12
	/** SysML Parametric Diagram :: Diagram */
13
	public static final String DIAGRAM_ID = "Parametric"; //$NON-NLS-1$
14
15
	
16
17
18
	/** ********************************************************* */
19
	/** SysML Parametric Diagram - CompositeDiagram related elements */
20
	/** ********************************************************* */
21
22
	/** CompositeDiagram :: CONSTRAINT */
23
	public static final IHintedType CONSTRAINT = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.composite.Constraint_2114"); //$NON-NLS-1$
24
25
	public static final String CONSTRAINT_LABEL_NAME_HINT = "5197"; //$NON-NLS-1$
26
27
	public static final String CONSTRAINT_LABEL_SPECIFICATION_HINT = "6039"; //$NON-NLS-1$
28
29
	/** CompositeDiagram :: COMMENT_CN */
30
	public static final IHintedType COMMENT_CN = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.composite.Comment_3097"); //$NON-NLS-1$
31
32
	public static final String COMMENT_CN_LABEL_BODY_HINT = "5150"; //$NON-NLS-1$
33
34
	/** CompositeDiagram :: COMMENT */
35
	public static final IHintedType COMMENT = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.composite.Comment_2109"); //$NON-NLS-1$
36
37
	public static final String COMMENT_LABEL_BODY_HINT = "5192"; //$NON-NLS-1$
38
39
	/** CompositeDiagram :: CONSTRAINT_CN */
40
	public static final IHintedType CONSTRAINT_CN = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.composite.Constraint_3120"); //$NON-NLS-1$
41
42
	public static final String CONSTRAINT_CN_LABEL_NAME_HINT = "6048"; //$NON-NLS-1$
43
44
	public static final String CONSTRAINT_CN_LABEL_SPECIFICATION_HINT = "6049"; //$NON-NLS-1$
45
46
	/** CompositeDiagram :: COMMENT_ANNOTATED_ELEMENT */
47
	public static final IHintedType COMMENT_ANNOTATED_ELEMENT = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.composite.CommentAnnotatedElement_4002"); //$NON-NLS-1$
48
49
	/** CompositeDiagram :: CONSTRAINT_CONSTRAINED_ELEMENT */
50
	public static final IHintedType CONSTRAINT_CONSTRAINED_ELEMENT = (IHintedType)getElementType("org.eclipse.papyrus.uml.diagram.composite.ConstraintConstrainedElement_4003"); //$NON-NLS-1$
51
	
52
}	
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/GraphicalTypeRegistry.java (+195 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
15
16
import java.util.HashSet;
17
import java.util.Set;
18
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
21
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
22
import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry;
23
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
24
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
25
26
/**
27
 * <pre>
28
 * This class provides graphical type id (used as View type) for
29
 * domain element according to their actual or expected graphical
30
 * container type.
31
 * </pre>
32
 */
33
public class GraphicalTypeRegistry implements IGraphicalTypeRegistry {
34
35
	/** A Set containing all known node graphical types */
36
	protected Set<String> knownNodes = new HashSet<String>();
37
38
	/** A Set containing all known edge graphical types */
39
	protected Set<String> knownEdges = new HashSet<String>();
40
41
	/** Default constructor */
42
	public GraphicalTypeRegistry() {
43
44
		// Fill known edges set
45
		knownEdges.add(ElementTypes.COMMENT_ANNOTATED_ELEMENT.getSemanticHint());
46
		knownEdges.add(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT.getSemanticHint());
47
48
		// Fill known nodes set (primary nodes)
49
		knownNodes.add(UMLElementTypes.CONSTRAINT.getSemanticHint());
50
		knownNodes.add(UMLElementTypes.COMMENT.getSemanticHint());
51
52
		knownNodes.add(ElementTypes.CONSTRAINT.getSemanticHint());
53
		knownNodes.add(ElementTypes.COMMENT_CN.getSemanticHint());
54
		knownNodes.add(ElementTypes.COMMENT.getSemanticHint());
55
		knownNodes.add(ElementTypes.CONSTRAINT_CN.getSemanticHint());
56
57
		// Fill known nodes set (child label nodes)
58
	}
59
60
	/**
61
	 * {@inheritDoc}
62
	 */
63
	public String getEdgeGraphicalType(EObject domainElement) {
64
65
		String graphicalType = UNDEFINED_TYPE;
66
		if(domainElement == null) {
67
			return UNDEFINED_TYPE;
68
		}
69
		return graphicalType;
70
	}
71
72
	/**
73
	 * {@inheritDoc}
74
	 */
75
	public String getEdgeGraphicalType(IElementType elementType) {
76
		if(elementType instanceof IHintedType) {
77
			String semanticHint = ((IHintedType)elementType).getSemanticHint();
78
			return getEdgeGraphicalType(semanticHint);
79
		}
80
81
		return UNDEFINED_TYPE;
82
	}
83
84
	/**
85
	 * {@inheritDoc}
86
	 */
87
	public String getEdgeGraphicalType(String proposedType) {
88
		if(isKnownEdgeType(proposedType)) {
89
			return proposedType;
90
		}
91
92
		return UNDEFINED_TYPE;
93
	}
94
95
	/**
96
	 * {@inheritDoc}
97
	 */
98
	public String getNodeGraphicalType(EObject domainElement, String containerType) {
99
100
		String graphicalType = UNDEFINED_TYPE;
101
		if((containerType == null) || (domainElement == null)) {
102
			return UNDEFINED_TYPE;
103
		}
104
105
		if(domainElement instanceof org.eclipse.uml2.uml.Constraint) {
106
			if(ElementTypes.DIAGRAM_ID.equals(containerType)) { // Constraint TopNode
107
				graphicalType = ElementTypes.CONSTRAINT.getSemanticHint();
108
			}
109
			if(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
110
				graphicalType = ElementTypes.CONSTRAINT_CN.getSemanticHint();
111
			}
112
113
		}
114
115
		if(domainElement instanceof org.eclipse.uml2.uml.Comment) {
116
			if(ElementTypes.DIAGRAM_ID.equals(containerType)) { // Comment TopNode
117
				graphicalType = ElementTypes.COMMENT.getSemanticHint();
118
			}
119
			if(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
120
				graphicalType = ElementTypes.COMMENT_CN.getSemanticHint();
121
			}
122
			if(SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
123
				graphicalType = ElementTypes.COMMENT_CN.getSemanticHint();
124
			}
125
126
		}
127
128
		return graphicalType;
129
	}
130
131
	/**
132
	 * {@inheritDoc}
133
	 */
134
	public String getNodeGraphicalType(IElementType elementType, String containerType) {
135
		if(elementType instanceof IHintedType) {
136
			String semanticHint = ((IHintedType)elementType).getSemanticHint();
137
			return getNodeGraphicalType(semanticHint, containerType);
138
		}
139
140
		return UNDEFINED_TYPE;
141
	}
142
143
	/**
144
	 * {@inheritDoc}
145
	 */
146
	public String getNodeGraphicalType(String proposedType, String containerType) {
147
		if((UMLElementTypes.COMMENT.getSemanticHint().equals(proposedType))) {
148
149
			if(ElementTypes.DIAGRAM_ID.equals(containerType)) { // Constraint TopNode
150
				return ElementTypes.COMMENT.getSemanticHint();
151
			}
152
153
			if(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
154
				return ElementTypes.COMMENT_CN.getSemanticHint();
155
			}
156
157
			if(SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerType)) {
158
				return ElementTypes.COMMENT_CN.getSemanticHint();
159
			}
160
161
			return UNDEFINED_TYPE;
162
		}
163
164
		if(UMLElementTypes.CONSTRAINT.getSemanticHint().equals(proposedType)) {
165
166
			if(ElementTypes.DIAGRAM_ID.equals(containerType)) { // Constraint TopNode
167
				return ElementTypes.CONSTRAINT.getSemanticHint();
168
			}
169
			if(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerType)) {
170
				return ElementTypes.CONSTRAINT_CN.getSemanticHint();
171
			}
172
173
			return UNDEFINED_TYPE;
174
		}
175
		if(isKnownNodeType(proposedType)) {
176
			return proposedType;
177
		}
178
179
		return UNDEFINED_TYPE;
180
	}
181
182
	/**
183
	 * {@inheritDoc}
184
	 */
185
	public boolean isKnownEdgeType(String type) {
186
		return knownEdges.contains(type);
187
	}
188
189
	/**
190
	 * {@inheritDoc}
191
	 */
192
	public boolean isKnownNodeType(String type) {
193
		return knownNodes.contains(type);
194
	}
195
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/IGraphicalTypeRegistry.java (+97 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
2
3
import org.eclipse.emf.ecore.EObject;
4
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
5
6
/**
7
 * This interface provides an API for accessing the local graphical type registry.
8
 * This registry provides a graphical type for existing model elements.
9
 */
10
public interface IGraphicalTypeRegistry {
11
12
	/** Constant for undefined graphical type */
13
	public static final String UNDEFINED_TYPE = "undefined_type";
14
15
	/**
16
	 * Get a valid edge graphical type for the domain element.
17
	 * 
18
	 * @param domainElement
19
	 *        the domain element.
20
	 * @return the domain element graphical type.
21
	 */
22
	public String getEdgeGraphicalType(EObject domainElement);
23
	
24
	/**
25
	 * Get a valid edge graphical type for the element type.
26
	 * 
27
	 * @param elementType
28
	 *        the element type.
29
	 * @param containerType
30
	 *        the type of the graphical owner of the domain element.
31
	 * @return the domain element graphical type.
32
	 */
33
	public String getEdgeGraphicalType(IElementType elementType);
34
	
35
	/**
36
	 * Get a valid edge graphical type for the proposed type.
37
	 * 
38
	 * @param proposedType
39
	 *        the proposed type.
40
	 * @param containerType
41
	 *        the type of the graphical owner of the domain element.
42
	 * @return the domain element graphical type.
43
	 */
44
	public String getEdgeGraphicalType(String proposedType);
45
	
46
	/**
47
	 * Get a valid node graphical type for the domain element.
48
	 * 
49
	 * @param domainElement
50
	 *        the domain element.
51
	 * @param containerType
52
	 *        the type of the graphical owner of the domain element.
53
	 * @return the domain element graphical type.
54
	 */
55
	public String getNodeGraphicalType(EObject domainElement, String containerType);
56
	
57
	/**
58
	 * Get a valid node graphical type for the element type.
59
	 * 
60
	 * @param elementType
61
	 *        the element type.
62
	 * @param containerType
63
	 *        the type of the graphical owner of the domain element.
64
	 * @return the domain element graphical type.
65
	 */
66
	public String getNodeGraphicalType(IElementType elementType, String containerType);
67
	
68
	/**
69
	 * Get a valid node graphical type for the proposed type.
70
	 * 
71
	 * @param proposedType
72
	 *        the proposed type.
73
	 * @param containerType
74
	 *        the type of the graphical owner of the domain element.
75
	 * @return the domain element graphical type.
76
	 */
77
	public String getNodeGraphicalType(String proposedType, String containerType);
78
	
79
	/**
80
	 * Test if the type is a known edge graphical type in this diagram
81
	 * 
82
	 * @param type
83
	 *        the type to test
84
	 * @return true if the type is known
85
	 */
86
	public boolean isKnownEdgeType(String type);
87
	
88
	/**
89
	 * Test if the type is a known node graphical type in this diagram
90
	 * 
91
	 * @param type
92
	 *        the type to test
93
	 * @return true if the type is known
94
	 */
95
	public boolean isKnownNodeType(String type);
96
97
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramEditPartProvider.java (+54 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
2
3
import org.eclipse.emf.ecore.EObject;
4
import org.eclipse.gmf.runtime.common.core.service.IOperation;
5
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation;
6
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
7
import org.eclipse.gmf.runtime.notation.View;
8
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
9
import org.eclipse.papyrus.uml.diagram.composite.providers.UMLEditPartProvider;
10
11
public class InheritedCompositeDiagramEditPartProvider extends UMLEditPartProvider {
12
13
14
	@Override
15
	public synchronized boolean provides(IOperation operation) {
16
		if(operation instanceof CreateGraphicEditPartOperation) {
17
			View view = ((IEditPartOperation)operation).getView();
18
19
			// Ensure current diagram is a Parametric Diagram
20
			if(!ElementTypes.DIAGRAM_ID.equals(view.getDiagram().getType())) {
21
				return false;
22
			}
23
24
			// Test supported inherited types
25
			EObject eobject = view.getElement();
26
27
			/** Nodes (and ChildLabelNodes) *********** */
28
			if(eobject instanceof org.eclipse.uml2.uml.Constraint) {
29
				return true;
30
			}
31
			if(eobject instanceof org.eclipse.uml2.uml.Comment) {
32
				return true;
33
			}
34
35
			// Additional test needed here to decide whether to support Feature type links.
36
			// As feature type link are not related to a MetaClass from the domain model
37
			// they are not already handled by previous tests.
38
			// Also concerns NotationType.
39
			String hint = view.getType();
40
41
			/** Edges (Feature) : COMMENT_ANNOTATED_ELEMENT *********** */
42
			if(ElementTypes.COMMENT_ANNOTATED_ELEMENT.getSemanticHint().equals(hint)) {
43
				return true;
44
			}
45
			/** Edges (Feature) : CONSTRAINT_CONSTRAINED_ELEMENT *********** */
46
			if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT.getSemanticHint().equals(hint)) {
47
				return true;
48
			}
49
50
		}
51
		return false;
52
	}
53
54
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/InheritedCompositeDiagramViewProvider.java (+218 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
2
3
4
import org.eclipse.core.runtime.IAdaptable;
5
import org.eclipse.emf.ecore.EAnnotation;
6
import org.eclipse.emf.ecore.EObject;
7
import org.eclipse.emf.ecore.EcoreFactory;
8
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
9
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateEdgeViewOperation;
10
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateNodeViewOperation;
11
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateViewForKindOperation;
12
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
13
import org.eclipse.gmf.runtime.notation.Edge;
14
import org.eclipse.gmf.runtime.notation.Node;
15
import org.eclipse.gmf.runtime.notation.View;
16
import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry;
17
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
18
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
19
import org.eclipse.papyrus.sysml.diagram.parametric.provider.GraphicalTypeRegistry;
20
import org.eclipse.papyrus.sysml.diagram.parametric.Activator;
21
import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
22
import org.eclipse.papyrus.uml.diagram.composite.providers.UMLViewProvider;
23
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
24
25
public class InheritedCompositeDiagramViewProvider extends UMLViewProvider {
26
27
	/** Local graphical type registry */
28
	protected IGraphicalTypeRegistry registry = new GraphicalTypeRegistry();
29
30
	@Override
31
	public Edge createEdge(IAdaptable semanticAdapter, View containerView, String semanticHint, int index, boolean persisted, PreferencesHint preferencesHint) {
32
		Edge createdEdge = null;
33
34
		IElementType elementType = (IElementType)semanticAdapter.getAdapter(IElementType.class);
35
		if(elementType != null) {
36
			createdEdge = super.createEdge(semanticAdapter, containerView, semanticHint, index, persisted, preferencesHint);
37
		} else {
38
39
			EObject domainElement = (EObject)semanticAdapter.getAdapter(EObject.class);
40
41
			String domainElementGraphicalType = semanticHint;
42
			if(domainElementGraphicalType == null) {
43
				domainElementGraphicalType = registry.getEdgeGraphicalType(domainElement);
44
			}
45
46
			if((!IGraphicalTypeRegistry.UNDEFINED_TYPE.equals(domainElementGraphicalType)) && (registry.isKnownEdgeType(domainElementGraphicalType))) {
47
				// Cannot use createEdge from super class as it never take the graphical type (semanticHint) into account.
48
				// createdEdge = super.createEdge(semanticAdapter, containerView, domainElementGraphicalType, index, persisted, preferencesHint);
49
50
				if(ElementTypes.COMMENT_ANNOTATED_ELEMENT.getSemanticHint().equals(domainElementGraphicalType)) {
51
					createdEdge = createCommentAnnotatedElement_4002(containerView, index, persisted, preferencesHint);
52
				}
53
				if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT.getSemanticHint().equals(domainElementGraphicalType)) {
54
					createdEdge = createConstraintConstrainedElement_4003(containerView, index, persisted, preferencesHint);
55
				}
56
			}
57
		}
58
59
		if(createdEdge == null) {
60
			Activator.log.error(new Exception("Could not create Edge."));
61
		}
62
63
		return createdEdge;
64
	}
65
66
	@Override
67
	protected boolean provides(CreateViewForKindOperation op) {
68
		// Never use this method (often incorrectly implemented due to GMF Tooling choices).
69
		String diagramType = op.getContainerView().getDiagram().getType();
70
		if(!ElementTypes.DIAGRAM_ID.equals(diagramType)) {
71
			return false;
72
		}
73
74
		throw new UnsupportedOperationException("Should never be called by the " + diagramType + " diagram.");
75
	}
76
77
	@Override
78
	protected boolean provides(CreateEdgeViewOperation op) {
79
80
		// Must have a container
81
		if(op.getContainerView() == null) {
82
			return false;
83
		}
84
85
		// This provider is registered for InternalBlock Diagram only
86
		String diagramType = op.getContainerView().getDiagram().getType();
87
		if(!ElementTypes.DIAGRAM_ID.equals(diagramType)) {
88
			return false;
89
		}
90
91
		IElementType elementType = getSemanticElementType(op.getSemanticAdapter());
92
		if(elementType == ElementTypes.COMMENT_ANNOTATED_ELEMENT) {
93
			return true;
94
		}
95
		if(elementType == ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT) {
96
			return true;
97
		}
98
99
		// /////////////////////////////////////////////////////////////////////
100
		// Test possibility to provide a view based on the semantic nature and its expected container.
101
		// /////////////////////////////////////////////////////////////////////
102
103
		// IElementType may be null (especially when drop from ModelExplorer).
104
		// In such a case, test the semantic EObject instead.	
105
		if(elementType == null) {
106
			EObject domainElement = (EObject)op.getSemanticAdapter().getAdapter(EObject.class);
107
			String domainElementGraphicalType = op.getSemanticHint();
108
			if(domainElementGraphicalType == null) {
109
				domainElementGraphicalType = registry.getEdgeGraphicalType(domainElement);
110
			}
111
112
			if((!IGraphicalTypeRegistry.UNDEFINED_TYPE.equals(domainElementGraphicalType)) && (registry.isKnownEdgeType(domainElementGraphicalType))) {
113
				return true;
114
			}
115
		}
116
117
		return false;
118
	}
119
120
	@Override
121
	protected boolean provides(CreateNodeViewOperation op) {
122
		// Must have a container
123
		if(op.getContainerView() == null) {
124
			return false;
125
		}
126
		// Get the type of the container
127
		String containerGraphicalType = op.getContainerView().getType();
128
129
		// This provider is registered for InternalBlock Diagram only
130
		String diagramType = op.getContainerView().getDiagram().getType();
131
		if(!ElementTypes.DIAGRAM_ID.equals(diagramType)) {
132
			return false;
133
		}
134
135
		// /////////////////////////////////////////////////////////////////////
136
		// Test possibility to provide a view based on the ElementType and its expected container.
137
		// /////////////////////////////////////////////////////////////////////
138
139
		IElementType elementType = (IElementType)op.getSemanticAdapter().getAdapter(IElementType.class);
140
		if(elementType == UMLElementTypes.CONSTRAINT) {
141
			if(ElementTypes.DIAGRAM_ID.equals(containerGraphicalType)) {
142
				return true;
143
			}
144
			if(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerGraphicalType)) {
145
				return true;
146
			}
147
		}
148
		if(elementType == UMLElementTypes.COMMENT) {
149
			if(ElementTypes.DIAGRAM_ID.equals(containerGraphicalType)) {
150
				return true;
151
			}
152
			if(SysMLGraphicalTypes.COMPARTMENT_SYSML_STRUCTURE_ID.equals(containerGraphicalType)) {
153
				return true;
154
			}
155
			if(SysMLGraphicalTypes.COMPARTMENT_SYSML_BLOCKPROPERTY_STRUCTURE_ID.equals(containerGraphicalType)) {
156
				return true;
157
			}
158
		}
159
160
		// /////////////////////////////////////////////////////////////////////
161
		// Test possibility to provide a view based on the semantic nature and its expected container.
162
		// /////////////////////////////////////////////////////////////////////
163
164
		// IElementType may be null (especially when drop from ModelExplorer).
165
		// In such a case, test the semantic EObject instead.
166
		if(elementType == null) {
167
			EObject domainElement = (EObject)op.getSemanticAdapter().getAdapter(EObject.class);
168
			String domainElementGraphicalType = op.getSemanticHint();
169
			if(domainElementGraphicalType == null) {
170
				domainElementGraphicalType = registry.getNodeGraphicalType(domainElement, containerGraphicalType);
171
			} else {
172
				domainElementGraphicalType = registry.getNodeGraphicalType(domainElementGraphicalType, containerGraphicalType);
173
			}
174
175
			if((!IGraphicalTypeRegistry.UNDEFINED_TYPE.equals(domainElementGraphicalType)) && (registry.isKnownNodeType(domainElementGraphicalType))) {
176
				return true;
177
			}
178
		}
179
		return false;
180
	}
181
182
	@Override
183
	public Node createNode(IAdaptable semanticAdapter, View containerView, String semanticHint, int index, boolean persisted, PreferencesHint preferencesHint) {
184
185
		// Use the GraphicalTypeRegistry to find the expected type for a domain element
186
		// Get the type of the container
187
		String containerGraphicalType = containerView.getType();
188
189
		// Get the type of the domain element
190
		EObject domainElement = (EObject)semanticAdapter.getAdapter(EObject.class);
191
192
		if(semanticHint != null) {
193
			// Look for a possible graphicalType replacement
194
			String graphicalType = registry.getNodeGraphicalType(semanticHint, containerGraphicalType);
195
			return super.createNode(new SemanticAdapter(domainElement, null), containerView, graphicalType, index, persisted, preferencesHint);
196
		}
197
198
		String domainElementGraphicalType = registry.getNodeGraphicalType(domainElement, containerGraphicalType);
199
200
		// Create the expected node
201
		if(!IGraphicalTypeRegistry.UNDEFINED_TYPE.equals(domainElementGraphicalType)) {
202
			return super.createNode(semanticAdapter, containerView, domainElementGraphicalType, index, persisted, preferencesHint);
203
		}
204
205
		Activator.log.error(new Exception("Could not create Node."));
206
		return null;
207
	}
208
209
	@Override
210
	protected void stampShortcut(View containerView, Node target) {
211
		if(!ElementTypes.DIAGRAM_ID.equals(containerView.getDiagram().getType())) {
212
			EAnnotation shortcutAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
213
			shortcutAnnotation.setSource("Shortcut"); //$NON-NLS-1$
214
			shortcutAnnotation.getDetails().put("modelID", ElementTypes.DIAGRAM_ID); //$NON-NLS-1$
215
			target.getEAnnotations().add(shortcutAnnotation);
216
		}
217
	}
218
}	
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/ParametricDiagramEditPartProvider.java (+37 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
2
3
import org.eclipse.gmf.runtime.common.core.service.IOperation;
4
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider;
5
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation;
6
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
7
import org.eclipse.gmf.runtime.notation.View;
8
import org.eclipse.papyrus.sysml.diagram.parametric.Activator;
9
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.ParametricDiagramEditPart;
10
11
public class ParametricDiagramEditPartProvider extends AbstractEditPartProvider {
12
13
	@Override
14
	public boolean provides(IOperation operation) {
15
		if(operation instanceof CreateGraphicEditPartOperation) {
16
			View view = ((IEditPartOperation)operation).getView();
17
18
			// Ensure current diagram is Parametric Diagram
19
			if(ElementTypes.DIAGRAM_ID.equals(view.getType())) {
20
				return true;
21
			}
22
		}
23
24
		return false;
25
	}
26
27
	@Override
28
	protected Class<?> getDiagramEditPartClass(View view) {
29
		if(ElementTypes.DIAGRAM_ID.equals(view.getType())) {
30
			return ParametricDiagramEditPart.class;
31
		}
32
33
		Activator.log.error(new Exception("Could not create EditPart."));
34
		return null;
35
	}
36
37
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/ParametricDiagramEditPolicyProvider.java (+50 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
2
3
import org.eclipse.gef.EditPart;
4
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
5
import org.eclipse.gmf.runtime.common.core.service.IOperation;
6
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
7
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
8
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
9
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
10
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomDragDropEditPolicy;
11
import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedNodeEditPart;
12
13
public class ParametricDiagramEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider {
14
15
	public boolean provides(IOperation operation) {
16
17
		CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation)operation;
18
		if(!(epOperation.getEditPart() instanceof GraphicalEditPart)) {
19
			return false;
20
		}
21
		GraphicalEditPart gep = (GraphicalEditPart)epOperation.getEditPart();
22
		String diagramType = gep.getNotationView().getDiagram().getType();
23
		if(!ElementTypes.DIAGRAM_ID.equals(diagramType)) {
24
			return false;
25
		}
26
27
		if(gep instanceof org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConstraintEditPart) {
28
			return true;
29
		}	
30
		if(gep instanceof PortAffixedNodeEditPart) {
31
			return true;
32
		}	
33
		if(gep instanceof org.eclipse.papyrus.uml.diagram.composite.edit.parts.UseCaseEditPartCN) {
34
			return true;
35
		}	
36
		if(gep instanceof org.eclipse.papyrus.uml.diagram.composite.edit.parts.CommentEditPart) {
37
			return true;
38
		}	
39
		if(gep instanceof org.eclipse.papyrus.uml.diagram.composite.edit.parts.InteractionConstraintEditPartCN) {
40
			return true;
41
		}	
42
43
		return false;
44
	}
45
46
	public void createEditPolicies(EditPart editPart) {
47
		editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDragDropEditPolicy());
48
	}
49
50
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/provider/ParametricDiagramViewProvider.java (+31 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
2
3
import org.eclipse.core.runtime.IAdaptable;
4
import org.eclipse.gmf.runtime.diagram.core.providers.AbstractViewProvider;
5
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation;
6
import org.eclipse.papyrus.sysml.diagram.parametric.Activator;
7
import org.eclipse.papyrus.sysml.diagram.parametric.factory.ParametricDiagramViewFactory;
8
9
public class ParametricDiagramViewProvider extends AbstractViewProvider {
10
11
		@Override
12
		protected boolean provides(CreateDiagramViewOperation operation) {
13
	
14
			if(ElementTypes.DIAGRAM_ID.equals(operation.getSemanticHint())) {
15
				return true;
16
			}
17
	
18
			return false;
19
		}
20
	
21
		@Override
22
		protected Class<?> getDiagramViewClass(IAdaptable semanticAdapter, String diagramKind) {
23
			if(ElementTypes.DIAGRAM_ID.equals(diagramKind)) {
24
				return ParametricDiagramViewFactory.class;
25
			}
26
	
27
			Activator.log.error(new Exception("Could not create View."));
28
			return null;
29
		}
30
}
31
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src-gen/org/eclipse/papyrus/sysml/diagram/parametric/utils/ParametricDiagramGraphicalTypes.java (+15 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.utils; 
2
3
public class ParametricDiagramGraphicalTypes {
4
5
	/** ********************************************************* */
6
	/** Diagram custom graphical types id *********************** */
7
	/** ********************************************************* */
8
9
10
11
12
13
14
15
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/Activator.java (+105 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric;
15
16
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.jface.resource.ImageDescriptor;
19
import org.eclipse.papyrus.infra.core.log.LogHelper;
20
import org.eclipse.papyrus.sysml.diagram.parametric.preferences.CustomPreferenceInitializer;
21
import org.eclipse.ui.plugin.AbstractUIPlugin;
22
import org.osgi.framework.BundleContext;
23
24
/** The activator class controls the plug-in life cycle */
25
public class Activator extends AbstractUIPlugin {
26
27
	/** The plug-in ID */
28
	public static final String PLUGIN_ID = "org.eclipse.papyrus.sysml.diagram.parametric";
29
30
	/** The plug-in shared instance */
31
	private static Activator plugin;
32
33
	/** The logging helper */
34
	public static LogHelper log;
35
36
	/** The plug-in Preference store */
37
	public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint(PLUGIN_ID);
38
39
	/** Default constructor */
40
	public Activator() {
41
	}
42
43
	/*
44
	 * (non-Javadoc)
45
	 * 
46
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
47
	 */
48
	public void start(BundleContext context) throws Exception {
49
		super.start(context);
50
		plugin = this;
51
52
		// register the login helper
53
		log = new LogHelper(plugin);
54
55
		// register the preference store
56
		PreferencesHint.registerPreferenceStore(DIAGRAM_PREFERENCES_HINT, getPreferenceStore());
57
58
		// Preferences initialization
59
		CustomPreferenceInitializer diagramPreferenceInitializer = new CustomPreferenceInitializer();
60
		diagramPreferenceInitializer.initializeDefaultPreferences();
61
	}
62
63
	/*
64
	 * (non-Javadoc)
65
	 * 
66
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
67
	 */
68
	public void stop(BundleContext context) throws Exception {
69
		plugin = null;
70
		super.stop(context);
71
	}
72
73
	/**
74
	 * Returns the shared instance
75
	 * 
76
	 * @return the shared instance
77
	 */
78
	public static Activator getInstance() {
79
		return plugin;
80
	}
81
82
	/**
83
	 * Returns an image descriptor for the image file at the given plug-in relative path.
84
	 * 
85
	 * @generated
86
	 * @param path
87
	 *        the path
88
	 * @return the image descriptor
89
	 */
90
	public static ImageDescriptor getBundledImageDescriptor(String path) {
91
		return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
92
	}
93
94
	/**
95
	 * 
96
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#getPreferenceStore()
97
	 * 
98
	 * @return Shared Preference Store.
99
	 */
100
	@Override
101
	public IPreferenceStore getPreferenceStore() {
102
		IPreferenceStore store = org.eclipse.papyrus.infra.gmfdiag.preferences.Activator.getDefault().getPreferenceStore();
103
		return store;
104
	}
105
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/CreateParametricDiagramWithNavigationHandler.java (+25 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric;
15
16
import org.eclipse.papyrus.infra.gmfdiag.navigation.CreateDiagramWithNavigationHandler;
17
18
19
public class CreateParametricDiagramWithNavigationHandler extends CreateDiagramWithNavigationHandler {
20
21
	public CreateParametricDiagramWithNavigationHandler() {
22
		super(new ParametricDiagramCreateCommand(), new ParametricDiagramCondition());
23
	}
24
25
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/ParametricDiagramCondition.java (+44 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric;
15
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.papyrus.infra.core.extension.commands.PerspectiveContextDependence;
18
import org.eclipse.papyrus.sysml.blocks.Block;
19
import org.eclipse.uml2.uml.util.UMLUtil;
20
21
/**
22
 * ParametricDiagramCondition to set conditions for the diagram creation
23
 */
24
public class ParametricDiagramCondition extends PerspectiveContextDependence {
25
26
	/**
27
	 * {@inheritDoc}
28
	 */
29
	@Override
30
	public boolean create(EObject selectedElement) {
31
		if(super.create(selectedElement)) {
32
			if(selectedElement instanceof org.eclipse.uml2.uml.Class) {
33
				org.eclipse.uml2.uml.Class clazz = (org.eclipse.uml2.uml.Class)selectedElement;
34
				if(UMLUtil.getStereotypeApplication(clazz, Block.class) != null) {
35
					return true;
36
				}
37
			}
38
			else if(selectedElement instanceof org.eclipse.uml2.uml.Package) {
39
				return true;
40
			}
41
		}
42
		return false;
43
	}
44
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/commands/CustomBindingConnectorCreateCommand.java (+113 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 CEA LIST.
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
package org.eclipse.papyrus.sysml.diagram.parametric.commands;
10
11
import org.eclipse.core.commands.ExecutionException;
12
import org.eclipse.core.runtime.IAdaptable;
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.emf.ecore.EObject;
15
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
16
import org.eclipse.gmf.runtime.common.core.command.ICommand;
17
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
18
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
19
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
20
import org.eclipse.gmf.runtime.notation.View;
21
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
22
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
23
import org.eclipse.papyrus.sysml.blocks.BlocksPackage;
24
import org.eclipse.papyrus.sysml.constraints.ConstraintBlock;
25
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
26
import org.eclipse.papyrus.uml.service.types.utils.ConnectorUtils;
27
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterUtils;
28
import org.eclipse.uml2.uml.Connector;
29
import org.eclipse.uml2.uml.Element;
30
import org.eclipse.uml2.uml.Property;
31
import org.eclipse.uml2.uml.StructuredClassifier;
32
import org.eclipse.uml2.uml.util.UMLUtil;
33
import org.eclipse.uml2.uml.util.UMLUtil.StereotypeApplicationHelper;
34
35
/**
36
 * Creates a Message between MessageOccurrenceSpecifications. Converts OccurrenceSpecifications to
37
 * MessageOccurrenceSpecifications if needed
38
 */
39
public class CustomBindingConnectorCreateCommand extends EditElementCommand {
40
41
	private final EObject source;
42
	private final EObject target;
43
44
	public CustomBindingConnectorCreateCommand(final CreateRelationshipRequest request) {
45
		super(request.getLabel(), null, request);
46
		this.source = request.getSource();
47
		this.target = request.getTarget();
48
		
49
	}
50
51
	@Override
52
	public boolean canExecute() {
53
		if(this.source == null) {
54
			return false;
55
		}
56
		if(this.target == null) {
57
			return true;
58
		}
59
		if(this.source == this.target) {
60
			return false;
61
		}
62
		if (this.source != null && this.target != null) {
63
			return isConstraintParameter((Element)source, RequestParameterUtils.getSourceView(getRequest())) 
64
					|| isConstraintParameter((Element)target, RequestParameterUtils.getTargetView(getRequest()));
65
		}
66
		return false;
67
	}
68
69
	private boolean isConstraintParameter(Element element, View view) {
70
		if (element instanceof Property) {
71
			Property property = (Property) element;
72
			Element ownerConstraintBlock = property.getOwner();
73
			if (ownerConstraintBlock instanceof org.eclipse.uml2.uml.Class && UMLUtil.getStereotypeApplication(ownerConstraintBlock, ConstraintBlock.class) != null) {
74
				// check for graphics : owned by a constraintProperty
75
				View containerView = ViewUtil.getContainerView(view);
76
				Element containerElement = (Element)containerView.getElement();
77
				return containerElement instanceof Property 
78
						&& UMLUtil.getStereotypeApplication(containerElement, ConstraintProperty.class) != null 
79
						&& ((Property)containerElement).getType() == ownerConstraintBlock;
80
			}
81
		}
82
		return false;
83
	}
84
85
	@Override
86
	protected CommandResult doExecuteWithResult(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
87
88
		if(!canExecute()) {
89
			throw new ExecutionException("Invalid arguments in create link command"); //$NON-NLS-1$
90
		}
91
92
		// Create the Connector and its ConnectorEnd. Correct container are set and paths are set in case of <<NestedConnectorEnd>>.
93
		StructuredClassifier deducedContainer = new ConnectorUtils().deduceContainer(RequestParameterUtils.getSourceView(getRequest()), RequestParameterUtils.getTargetView(getRequest()));
94
		((CreateRelationshipRequest)getRequest()).setContainer(deducedContainer);
95
		IElementEditService commandProvider = ElementEditServiceUtils.getCommandProvider(deducedContainer);
96
		ICommand editCommand = commandProvider.getEditCommand(getRequest());
97
		
98
		if (editCommand.canExecute()) {
99
			editCommand.execute(monitor, info);
100
			Object newObject = editCommand.getCommandResult().getReturnValue();
101
			
102
			if (newObject instanceof Connector) {
103
				Connector connector = (Connector)newObject;
104
				// Apply the <<BindingConnector>> stereotype
105
				StereotypeApplicationHelper.INSTANCE.applyStereotype(connector, BlocksPackage.eINSTANCE.getBindingConnector());
106
			}
107
108
			return CommandResult.newOKCommandResult(newObject);
109
		}
110
		return CommandResult.newErrorCommandResult("Invalid arguments in create link command");
111
	}
112
	
113
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/commands/ConnectorCreateCommand.java (-174 lines)
Lines 1-174 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.commands;
15
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
21
import org.eclipse.gmf.runtime.common.core.command.ICommand;
22
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
23
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
24
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
25
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
27
import org.eclipse.gmf.runtime.notation.Node;
28
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.SysmlBaseItemSemanticEditPolicy;
29
import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
30
import org.eclipse.uml2.uml.ConnectableElement;
31
import org.eclipse.uml2.uml.Connector;
32
import org.eclipse.uml2.uml.ConnectorEnd;
33
import org.eclipse.uml2.uml.StructuredClassifier;
34
import org.eclipse.uml2.uml.UMLFactory;
35
36
/**
37
 * @generated
38
 */
39
public class ConnectorCreateCommand extends EditElementCommand {
40
41
	/**
42
	 * @generated
43
	 */
44
	protected final EObject source;
45
46
	/**
47
	 * @generated
48
	 */
49
	protected final EObject target;
50
51
	/**
52
	 * @generated
53
	 */
54
	protected StructuredClassifier container;
55
56
	/**
57
	 * @generated
58
	 */
59
	public ConnectorCreateCommand(CreateRelationshipRequest request, EObject source, EObject target) {
60
		super(request.getLabel(), null, request);
61
		this.source = source;
62
		this.target = target;
63
		container = deduceContainer(source, target);
64
	}
65
66
	/**
67
	 * @generated
68
	 */
69
	public boolean canExecute() {
70
		if(source == null && target == null) {
71
			return false;
72
		}
73
		if(source != null && false == source instanceof ConnectableElement) {
74
			return false;
75
		}
76
		if(target != null && false == target instanceof ConnectableElement) {
77
			return false;
78
		}
79
		if(getSource() == null) {
80
			return true; // link creation is in progress; source is not defined yet
81
		}
82
		// target may be null here but it's possible to check constraint
83
		if(getContainer() == null) {
84
			return false;
85
		}
86
		return SysmlBaseItemSemanticEditPolicy.getLinkConstraints().canCreateConnector_4001(getContainer(), getSource(), getTarget());
87
	}
88
89
	/**
90
	 * @generated NOT
91
	 */
92
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
93
		if(!canExecute()) {
94
			throw new ExecutionException("Invalid arguments in create link command"); //$NON-NLS-1$
95
		}
96
		Connector newElement = UMLFactory.eINSTANCE.createConnector();
97
		if(getContainer() != null) {
98
			getContainer().getOwnedConnectors().add(newElement);
99
		}
100
		// create the connector ends
101
		ConnectorEnd source = newElement.createEnd();
102
		ConnectorEnd target = newElement.createEnd();
103
		source.setRole(getSource());
104
		target.setRole(getTarget());
105
106
		doConfigure(newElement, monitor, info);
107
		((CreateElementRequest)getRequest()).setNewElement(newElement);
108
		return CommandResult.newOKCommandResult(newElement);
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	protected void doConfigure(Connector newElement, IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
115
		IElementType elementType = ((CreateElementRequest)getRequest()).getElementType();
116
		ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
117
		configureRequest.setClientContext(((CreateElementRequest)getRequest()).getClientContext());
118
		configureRequest.addParameters(getRequest().getParameters());
119
		configureRequest.setParameter(CreateRelationshipRequest.SOURCE, getSource());
120
		configureRequest.setParameter(CreateRelationshipRequest.TARGET, getTarget());
121
		ICommand configureCommand = elementType.getEditCommand(configureRequest);
122
		if(configureCommand != null && configureCommand.canExecute()) {
123
			configureCommand.execute(monitor, info);
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void setElementToEdit(EObject element) {
131
		throw new UnsupportedOperationException();
132
	}
133
134
	/**
135
	 * @generated
136
	 */
137
	protected ConnectableElement getSource() {
138
		return (ConnectableElement)source;
139
	}
140
141
	/**
142
	 * @generated
143
	 */
144
	protected ConnectableElement getTarget() {
145
		return (ConnectableElement)target;
146
	}
147
148
	/**
149
	 * @generated
150
	 */
151
	public StructuredClassifier getContainer() {
152
		return container;
153
	}
154
155
	/**
156
	 * Default approach is to traverse ancestors of the source to find instance of container. Modify
157
	 * with appropriate logic.
158
	 * 
159
	 * @generated NOT
160
	 */
161
	private static StructuredClassifier deduceContainer(EObject source, EObject target) {
162
		// get the structured classifier, graphical container of the
163
		for(Object obj : DiagramEditPartsUtil.getEObjectViews(source)) {
164
			if(obj instanceof Node && ((Node)obj).getDiagram() != null) {
165
				EObject element = ((Node)obj).getDiagram().getElement();
166
				if(element instanceof StructuredClassifier) {
167
					return (StructuredClassifier)element;
168
				}
169
			}
170
		}
171
		return null;
172
	}
173
174
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/commands/ConnectorReorientCommand.java (-190 lines)
Lines 1-190 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.commands;
15
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.emf.common.util.EList;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
22
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
23
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
24
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.SysmlBaseItemSemanticEditPolicy;
25
import org.eclipse.uml2.uml.ConnectableElement;
26
import org.eclipse.uml2.uml.Connector;
27
import org.eclipse.uml2.uml.ConnectorEnd;
28
import org.eclipse.uml2.uml.StructuredClassifier;
29
30
/**
31
 * @generated
32
 */
33
public class ConnectorReorientCommand extends EditElementCommand {
34
35
	/**
36
	 * @generated
37
	 */
38
	private final int reorientDirection;
39
40
	/**
41
	 * @generated
42
	 */
43
	private final EObject oldEnd;
44
45
	/**
46
	 * @generated
47
	 */
48
	private final EObject newEnd;
49
50
	/**
51
	 * @generated
52
	 */
53
	public ConnectorReorientCommand(ReorientRelationshipRequest request) {
54
		super(request.getLabel(), request.getRelationship(), request);
55
		reorientDirection = request.getDirection();
56
		oldEnd = request.getOldRelationshipEnd();
57
		newEnd = request.getNewRelationshipEnd();
58
	}
59
60
	/**
61
	 * @generated
62
	 */
63
	public boolean canExecute() {
64
		if(false == getElementToEdit() instanceof Connector) {
65
			return false;
66
		}
67
		if(reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
68
			return canReorientSource();
69
		}
70
		if(reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
71
			return canReorientTarget();
72
		}
73
		return false;
74
	}
75
76
	/**
77
	 * @generated NOT
78
	 */
79
	protected boolean canReorientSource() {
80
		if(!(oldEnd instanceof ConnectableElement && newEnd instanceof ConnectableElement)) {
81
			return false;
82
		}
83
		ConnectableElement target = null;
84
		EList<ConnectorEnd> ends = getLink().getEnds();
85
		if(ends != null && !ends.isEmpty()) {
86
			target = ends.get(1).getRole();
87
		}
88
		if(!(getLink().eContainer() instanceof StructuredClassifier)) {
89
			return false;
90
		}
91
		StructuredClassifier container = (StructuredClassifier)getLink().eContainer();
92
		return SysmlBaseItemSemanticEditPolicy.LinkConstraints.canExistConnector_4001(container, getNewSource(), target);
93
	}
94
95
	/**
96
	 * @generated NOT
97
	 */
98
	protected boolean canReorientTarget() {
99
		if(!(oldEnd instanceof ConnectableElement && newEnd instanceof ConnectableElement)) {
100
			return false;
101
		}
102
		ConnectableElement source = null;
103
		EList<ConnectorEnd> ends = getLink().getEnds();
104
		if(ends != null && !ends.isEmpty()) {
105
			source = ends.get(0).getRole();
106
		}
107
		if(!(getLink().eContainer() instanceof StructuredClassifier)) {
108
			return false;
109
		}
110
		StructuredClassifier container = (StructuredClassifier)getLink().eContainer();
111
		return SysmlBaseItemSemanticEditPolicy.LinkConstraints.canExistConnector_4001(container, source, getNewTarget());
112
	}
113
114
	/**
115
	 * @generated
116
	 */
117
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
118
		if(!canExecute()) {
119
			throw new ExecutionException("Invalid arguments in reorient link command"); //$NON-NLS-1$
120
		}
121
		if(reorientDirection == ReorientRelationshipRequest.REORIENT_SOURCE) {
122
			return reorientSource();
123
		}
124
		if(reorientDirection == ReorientRelationshipRequest.REORIENT_TARGET) {
125
			return reorientTarget();
126
		}
127
		throw new IllegalStateException();
128
	}
129
130
	/**
131
	 * @generated NOT
132
	 */
133
	protected CommandResult reorientSource() throws ExecutionException {
134
		EList<ConnectorEnd> ends = getLink().getEnds();
135
		if(ends != null && !ends.isEmpty()) {
136
			ends.get(0).setRole(getNewSource());
137
			return CommandResult.newOKCommandResult(getLink());
138
		} else {
139
			return CommandResult.newCancelledCommandResult();
140
		}
141
	}
142
143
	/**
144
	 * @generated NOT
145
	 */
146
	protected CommandResult reorientTarget() throws ExecutionException {
147
		EList<ConnectorEnd> ends = getLink().getEnds();
148
		if(ends != null && !ends.isEmpty()) {
149
			ends.get(1).setRole(getNewTarget());
150
			return CommandResult.newOKCommandResult(getLink());
151
		} else {
152
			return CommandResult.newCancelledCommandResult();
153
		}
154
	}
155
156
	/**
157
	 * @generated
158
	 */
159
	protected Connector getLink() {
160
		return (Connector)getElementToEdit();
161
	}
162
163
	/**
164
	 * @generated
165
	 */
166
	protected ConnectableElement getOldSource() {
167
		return (ConnectableElement)oldEnd;
168
	}
169
170
	/**
171
	 * @generated
172
	 */
173
	protected ConnectableElement getNewSource() {
174
		return (ConnectableElement)newEnd;
175
	}
176
177
	/**
178
	 * @generated
179
	 */
180
	protected ConnectableElement getOldTarget() {
181
		return (ConnectableElement)oldEnd;
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	protected ConnectableElement getNewTarget() {
188
		return (ConnectableElement)newEnd;
189
	}
190
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/commands/ConstraintPropertyCreateCommand.java (-138 lines)
Lines 1-138 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.commands;
15
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.emf.ecore.EClass;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
22
import org.eclipse.gmf.runtime.common.core.command.ICommand;
23
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
24
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
25
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
27
import org.eclipse.gmf.runtime.notation.View;
28
import org.eclipse.papyrus.resource.Resource;
29
import org.eclipse.papyrus.resource.util.ResourceUtil;
30
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
31
import org.eclipse.papyrus.sysml.constraints.ConstraintsFactory;
32
import org.eclipse.uml2.uml.Class;
33
import org.eclipse.uml2.uml.Property;
34
import org.eclipse.uml2.uml.UMLFactory;
35
36
/**
37
 * @generated
38
 */
39
public class ConstraintPropertyCreateCommand extends EditElementCommand {
40
41
	/**
42
	 * @generated
43
	 */
44
	private EClass eClass = null;
45
46
	/**
47
	 * @generated
48
	 */
49
	private EObject eObject = null;
50
51
	/**
52
	 * @generated
53
	 */
54
	public ConstraintPropertyCreateCommand(CreateElementRequest req, EObject eObject) {
55
		super(req.getLabel(), null, req);
56
		this.eObject = eObject;
57
		this.eClass = eObject != null ? eObject.eClass() : null;
58
	}
59
60
	/**
61
	 * @generated
62
	 */
63
	public static ConstraintPropertyCreateCommand create(CreateElementRequest req, EObject eObject) {
64
		return new ConstraintPropertyCreateCommand(req, eObject);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	public ConstraintPropertyCreateCommand(CreateElementRequest req) {
71
		super(req.getLabel(), null, req);
72
	}
73
74
	/**
75
	 * FIXME: replace with setElementToEdit()
76
	 * 
77
	 * @generated
78
	 */
79
	protected EObject getElementToEdit() {
80
81
		EObject container = ((CreateElementRequest)getRequest()).getContainer();
82
		if(container instanceof View) {
83
			container = ((View)container).getElement();
84
		}
85
		if(container != null) {
86
			return container;
87
		}
88
		return eObject;
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public boolean canExecute() {
95
96
		return true;
97
98
	}
99
100
	/**
101
	 * @generated NOT
102
	 */
103
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
104
		ConstraintProperty newElement = ConstraintsFactory.eINSTANCE.createConstraintProperty();
105
106
		EObject elementToEdit = getElementToEdit();
107
108
		if(elementToEdit instanceof Class) {
109
			Class aClass = (Class)elementToEdit;
110
			Property property = UMLFactory.eINSTANCE.createProperty();
111
			aClass.getOwnedAttributes().add(property);
112
			newElement.setBase_Property(property);
113
		}
114
115
		Resource owner = ResourceUtil.getResource(elementToEdit);
116
		owner.getEobjects().add(newElement);
117
118
		doConfigure(newElement, monitor, info);
119
120
		((CreateElementRequest)getRequest()).setNewElement(newElement);
121
		return CommandResult.newOKCommandResult(newElement);
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	protected void doConfigure(ConstraintProperty newElement, IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
128
		IElementType elementType = ((CreateElementRequest)getRequest()).getElementType();
129
		ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
130
		configureRequest.setClientContext(((CreateElementRequest)getRequest()).getClientContext());
131
		configureRequest.addParameters(getRequest().getParameters());
132
		ICommand configureCommand = elementType.getEditCommand(configureRequest);
133
		if(configureCommand != null && configureCommand.canExecute()) {
134
			configureCommand.execute(monitor, info);
135
		}
136
	}
137
138
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/commands/Property2CreateCommand.java (-141 lines)
Lines 1-141 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.commands;
15
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.emf.ecore.EClass;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
22
import org.eclipse.gmf.runtime.common.core.command.ICommand;
23
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
24
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
25
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
27
import org.eclipse.gmf.runtime.notation.View;
28
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
29
import org.eclipse.uml2.uml.Property;
30
import org.eclipse.uml2.uml.StructuredClassifier;
31
import org.eclipse.uml2.uml.Type;
32
import org.eclipse.uml2.uml.UMLFactory;
33
34
/**
35
 * @generated
36
 */
37
public class Property2CreateCommand extends EditElementCommand {
38
39
	/**
40
	 * @generated
41
	 */
42
	private EClass eClass = null;
43
44
	/**
45
	 * @generated
46
	 */
47
	private EObject eObject = null;
48
49
	/**
50
	 * @generated
51
	 */
52
	public Property2CreateCommand(CreateElementRequest req, EObject eObject) {
53
		super(req.getLabel(), null, req);
54
		this.eObject = eObject;
55
		this.eClass = eObject != null ? eObject.eClass() : null;
56
	}
57
58
	/**
59
	 * @generated
60
	 */
61
	public static Property2CreateCommand create(CreateElementRequest req, EObject eObject) {
62
		return new Property2CreateCommand(req, eObject);
63
	}
64
65
	/**
66
	 * @generated
67
	 */
68
	public Property2CreateCommand(CreateElementRequest req) {
69
		super(req.getLabel(), null, req);
70
	}
71
72
	/**
73
	 * FIXME: replace with setElementToEdit()
74
	 * 
75
	 * @generated
76
	 */
77
	protected EObject getElementToEdit() {
78
79
		EObject container = ((CreateElementRequest)getRequest()).getContainer();
80
		if(container instanceof View) {
81
			container = ((View)container).getElement();
82
		}
83
		if(container != null) {
84
			return container;
85
		}
86
		return eObject;
87
	}
88
89
	/**
90
	 * @generated NOT
91
	 */
92
	public boolean canExecute() {
93
		ConstraintProperty container = (ConstraintProperty)getElementToEdit();
94
		Property baseProperty = container.getBase_Property();
95
		if(baseProperty != null && baseProperty.getType() != null) {
96
			// TODO constraint is too restrictive
97
			// && StereotypeUtils.isStereotypeApplied("SysML::Constraints::ConstraintBlock",
98
			// baseProperty.getType())) {
99
			return true;
100
		}
101
		return false;
102
103
	}
104
105
	/**
106
	 * @generated NOT
107
	 */
108
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
109
110
		Property newElement = UMLFactory.eINSTANCE.createProperty();
111
		ConstraintProperty owner = (ConstraintProperty)getElementToEdit();
112
		Type type = owner.getBase_Property().getType();
113
114
		if(type != null && type instanceof StructuredClassifier) {
115
			StructuredClassifier classifier = (StructuredClassifier)type;
116
			classifier.getOwnedAttributes().add(newElement);
117
118
			doConfigure(newElement, monitor, info);
119
120
			((CreateElementRequest)getRequest()).setNewElement(newElement);
121
			return CommandResult.newOKCommandResult(newElement);
122
		} else {
123
			return CommandResult.newCancelledCommandResult();
124
		}
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void doConfigure(Property newElement, IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
131
		IElementType elementType = ((CreateElementRequest)getRequest()).getElementType();
132
		ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
133
		configureRequest.setClientContext(((CreateElementRequest)getRequest()).getClientContext());
134
		configureRequest.addParameters(getRequest().getParameters());
135
		ICommand configureCommand = elementType.getEditCommand(configureRequest);
136
		if(configureCommand != null && configureCommand.canExecute()) {
137
			configureCommand.execute(monitor, info);
138
		}
139
	}
140
141
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/commands/PropertyCreateCommand.java (-126 lines)
Lines 1-126 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.commands;
15
16
import org.eclipse.core.commands.ExecutionException;
17
import org.eclipse.core.runtime.IAdaptable;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
import org.eclipse.emf.ecore.EClass;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
22
import org.eclipse.gmf.runtime.common.core.command.ICommand;
23
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
24
import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
25
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
27
import org.eclipse.gmf.runtime.notation.View;
28
import org.eclipse.uml2.uml.Property;
29
import org.eclipse.uml2.uml.StructuredClassifier;
30
import org.eclipse.uml2.uml.UMLFactory;
31
32
/**
33
 * @generated
34
 */
35
public class PropertyCreateCommand extends EditElementCommand {
36
37
	/**
38
	 * @generated
39
	 */
40
	private EClass eClass = null;
41
42
	/**
43
	 * @generated
44
	 */
45
	private EObject eObject = null;
46
47
	/**
48
	 * @generated
49
	 */
50
	public PropertyCreateCommand(CreateElementRequest req, EObject eObject) {
51
		super(req.getLabel(), null, req);
52
		this.eObject = eObject;
53
		this.eClass = eObject != null ? eObject.eClass() : null;
54
	}
55
56
	/**
57
	 * @generated
58
	 */
59
	public static PropertyCreateCommand create(CreateElementRequest req, EObject eObject) {
60
		return new PropertyCreateCommand(req, eObject);
61
	}
62
63
	/**
64
	 * @generated
65
	 */
66
	public PropertyCreateCommand(CreateElementRequest req) {
67
		super(req.getLabel(), null, req);
68
	}
69
70
	/**
71
	 * FIXME: replace with setElementToEdit()
72
	 * 
73
	 * @generated
74
	 */
75
	protected EObject getElementToEdit() {
76
77
		EObject container = ((CreateElementRequest)getRequest()).getContainer();
78
		if(container instanceof View) {
79
			container = ((View)container).getElement();
80
		}
81
		if(container != null) {
82
			return container;
83
		}
84
		return eObject;
85
	}
86
87
	/**
88
	 * @generated
89
	 */
90
	public boolean canExecute() {
91
92
		return true;
93
94
	}
95
96
	/**
97
	 * @generated
98
	 */
99
	protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
100
101
		Property newElement = UMLFactory.eINSTANCE.createProperty();
102
103
		StructuredClassifier owner = (StructuredClassifier)getElementToEdit();
104
		owner.getOwnedAttributes().add(newElement);
105
106
		doConfigure(newElement, monitor, info);
107
108
		((CreateElementRequest)getRequest()).setNewElement(newElement);
109
		return CommandResult.newOKCommandResult(newElement);
110
	}
111
112
	/**
113
	 * @generated
114
	 */
115
	protected void doConfigure(Property newElement, IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
116
		IElementType elementType = ((CreateElementRequest)getRequest()).getElementType();
117
		ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, elementType);
118
		configureRequest.setClientContext(((CreateElementRequest)getRequest()).getClientContext());
119
		configureRequest.addParameters(getRequest().getParameters());
120
		ICommand configureCommand = elementType.getEditCommand(configureRequest);
121
		if(configureCommand != null && configureCommand.canExecute()) {
122
			configureCommand.execute(monitor, info);
123
		}
124
	}
125
126
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/commands/SysmlReorientConnectionViewCommand.java (-80 lines)
Lines 1-80 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.commands;
15
16
import java.util.List;
17
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.emf.transaction.TransactionalEditingDomain;
21
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
22
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
23
import org.eclipse.gmf.runtime.notation.Edge;
24
import org.eclipse.gmf.runtime.notation.View;
25
26
/**
27
 * @generated
28
 */
29
public class SysmlReorientConnectionViewCommand extends AbstractTransactionalCommand {
30
31
	/**
32
	 * @generated
33
	 */
34
	private IAdaptable edgeAdaptor;
35
36
	/**
37
	 * @generated
38
	 */
39
	public SysmlReorientConnectionViewCommand(TransactionalEditingDomain editingDomain, String label) {
40
		super(editingDomain, label, null);
41
	}
42
43
	/**
44
	 * @generated
45
	 */
46
	public List getAffectedFiles() {
47
		View view = (View)edgeAdaptor.getAdapter(View.class);
48
		if(view != null) {
49
			return getWorkspaceFiles(view);
50
		}
51
		return super.getAffectedFiles();
52
	}
53
54
	/**
55
	 * @generated
56
	 */
57
	public IAdaptable getEdgeAdaptor() {
58
		return edgeAdaptor;
59
	}
60
61
	/**
62
	 * @generated
63
	 */
64
	public void setEdgeAdaptor(IAdaptable edgeAdaptor) {
65
		this.edgeAdaptor = edgeAdaptor;
66
	}
67
68
	/**
69
	 * @generated
70
	 */
71
	protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) {
72
		assert null != edgeAdaptor : "Null child in SysmlReorientConnectionViewCommand"; //$NON-NLS-1$
73
		Edge edge = (Edge)getEdgeAdaptor().getAdapter(Edge.class);
74
		assert null != edge : "Null edge in SysmlReorientConnectionViewCommand"; //$NON-NLS-1$
75
		View tempView = edge.getSource();
76
		edge.setSource(edge.getTarget());
77
		edge.setTarget(tempView);
78
		return CommandResult.newOKCommandResult();
79
	}
80
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/helpers/ConnectorEditHelper.java (-20 lines)
Lines 1-20 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers;
15
16
/**
17
 * @generated
18
 */
19
public class ConnectorEditHelper extends SysmlBaseEditHelper {
20
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/helpers/ConstraintPropertyEditHelper.java (-20 lines)
Lines 1-20 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers;
15
16
/**
17
 * @generated
18
 */
19
public class ConstraintPropertyEditHelper extends SysmlBaseEditHelper {
20
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/helpers/PropertyEditHelper.java (-20 lines)
Lines 1-20 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers;
15
16
/**
17
 * @generated
18
 */
19
public class PropertyEditHelper extends SysmlBaseEditHelper {
20
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/helpers/ResourceEditHelper.java (-20 lines)
Lines 1-20 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers;
15
16
/**
17
 * @generated
18
 */
19
public class ResourceEditHelper extends SysmlBaseEditHelper {
20
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/helpers/SysmlBaseEditHelper.java (-99 lines)
Lines 1-99 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers;
15
16
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
17
import org.eclipse.gmf.runtime.common.core.command.ICommand;
18
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper;
21
import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
22
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
23
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
24
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
25
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
27
28
/**
29
 * @generated
30
 */
31
public class SysmlBaseEditHelper extends AbstractEditHelper {
32
33
	/**
34
	 * @generated
35
	 */
36
	public static final String EDIT_POLICY_COMMAND = "edit policy command"; //$NON-NLS-1$
37
38
	/**
39
	 * @generated
40
	 */
41
	public static final String CONTEXT_ELEMENT_TYPE = "context element type"; //$NON-NLS-1$
42
43
	/**
44
	 * @generated
45
	 */
46
	protected IEditHelperAdvice[] getEditHelperAdvice(IEditCommandRequest req) {
47
		if(req.getParameter(CONTEXT_ELEMENT_TYPE) instanceof IElementType) {
48
			return ElementTypeRegistry.getInstance().getEditHelperAdvice((IElementType)req.getParameter(CONTEXT_ELEMENT_TYPE));
49
		}
50
		return super.getEditHelperAdvice(req);
51
	}
52
53
	/**
54
	 * @generated
55
	 */
56
	protected ICommand getInsteadCommand(IEditCommandRequest req) {
57
		ICommand epCommand = (ICommand)req.getParameter(EDIT_POLICY_COMMAND);
58
		req.setParameter(EDIT_POLICY_COMMAND, null);
59
		ICommand ehCommand = super.getInsteadCommand(req);
60
		if(epCommand == null) {
61
			return ehCommand;
62
		}
63
		if(ehCommand == null) {
64
			return epCommand;
65
		}
66
		CompositeCommand command = new CompositeCommand(null);
67
		command.add(epCommand);
68
		command.add(ehCommand);
69
		return command;
70
	}
71
72
	/**
73
	 * @generated
74
	 */
75
	protected ICommand getCreateCommand(CreateElementRequest req) {
76
		return null;
77
	}
78
79
	/**
80
	 * @generated
81
	 */
82
	protected ICommand getCreateRelationshipCommand(CreateRelationshipRequest req) {
83
		return null;
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	protected ICommand getDestroyElementCommand(DestroyElementRequest req) {
90
		return null;
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected ICommand getDestroyReferenceCommand(DestroyReferenceRequest req) {
97
		return null;
98
	}
99
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomBlockCompositeEditPartTN.java (+69 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.part;
2
3
import org.eclipse.draw2d.IFigure;
4
import org.eclipse.gef.EditPart;
5
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
6
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
7
import org.eclipse.gmf.runtime.notation.View;
8
import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockLabelNameEditPart;
9
import org.eclipse.papyrus.sysml.diagram.common.edit.part.StructureCompartmentEditPart;
10
import org.eclipse.papyrus.sysml.diagram.common.figure.SysMLDiagramFrameFigure;
11
import org.eclipse.papyrus.sysml.diagram.parametric.figures.ParametricDiagramFrameFigure;
12
import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementEditPart;
13
import org.eclipse.papyrus.uml.diagram.common.figure.node.NodeNamedElementFigure;
14
15
16
public class CustomBlockCompositeEditPartTN extends AbstractElementEditPart {
17
18
	public CustomBlockCompositeEditPartTN(View view) {
19
		super(view);
20
	}
21
22
	@Override
23
	protected IFigure createNodeShape() {
24
		return this.primaryShape = new ParametricDiagramFrameFigure();
25
	}
26
	
27
	@Override
28
	public NodeNamedElementFigure getPrimaryShape() {
29
		return (NodeNamedElementFigure)primaryShape;
30
	}
31
	
32
	@Override
33
	protected boolean addFixedChild(EditPart childEditPart) {
34
		if(childEditPart instanceof BlockLabelNameEditPart) {
35
			((BlockLabelNameEditPart)childEditPart).setLabel(getPrimaryShape().getNameLabel());
36
			return true;
37
		}
38
		if(childEditPart instanceof StructureCompartmentEditPart) {
39
			IFigure pane = ((SysMLDiagramFrameFigure)getPrimaryShape()).getStructureCompartmentFigure();
40
			setupContentPane(pane);
41
			pane.add(((StructureCompartmentEditPart)childEditPart).getFigure());
42
			return true;
43
		}
44
		return false;
45
	}
46
47
	@Override
48
	protected boolean removeFixedChild(EditPart childEditPart) {
49
		return false;
50
	}
51
52
	@Override
53
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
54
		if(editPart instanceof StructureCompartmentEditPart) {
55
			return ((SysMLDiagramFrameFigure)getPrimaryShape()).getStructureCompartmentFigure();
56
		}
57
		return getContentPane();
58
	}
59
60
	@Override
61
	public EditPart getPrimaryChildEditPart() {
62
		return null;
63
	}
64
65
	@Override
66
	protected LayoutEditPolicy createLayoutEditPolicy() {
67
		return null;
68
	}
69
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomBlockLabelNameEditPart.java (+17 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.part;
2
3
import org.eclipse.gmf.runtime.notation.View;
4
import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockLabelNameEditPart;
5
6
public class CustomBlockLabelNameEditPart extends BlockLabelNameEditPart {
7
8
	public CustomBlockLabelNameEditPart(View view) {
9
		super(view);
10
	}
11
12
	@Override
13
	protected String getLabelText() {
14
		String diagramName = getDiagramView().getName();
15
		return super.getLabelText() + " [" + diagramName + "]";
16
	}
17
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomBlockPropertyCompositeEditPart.java (+20 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.part;
2
3
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
4
import org.eclipse.gmf.runtime.notation.View;
5
import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyCompositeEditPart;
6
import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomParametricSemanticPolicy;
7
8
public class CustomBlockPropertyCompositeEditPart extends
9
		BlockPropertyCompositeEditPart {
10
11
	public CustomBlockPropertyCompositeEditPart(View view) {
12
		super(view);
13
	}
14
	
15
	@Override
16
	protected void createDefaultEditPolicies() {
17
		super.createDefaultEditPolicies();
18
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
19
	}
20
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomConstraintBlockPropertyCompositeEditPart.java (+21 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.part;
2
3
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
4
import org.eclipse.gmf.runtime.notation.View;
5
import org.eclipse.papyrus.sysml.diagram.common.edit.part.ConstraintBlockPropertyCompositeEditPart;
6
import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomParametricSemanticPolicy;
7
8
public class CustomConstraintBlockPropertyCompositeEditPart extends
9
		ConstraintBlockPropertyCompositeEditPart {
10
11
	public CustomConstraintBlockPropertyCompositeEditPart(View view) {
12
		super(view);
13
	}
14
	
15
	@Override
16
	protected void createDefaultEditPolicies() {
17
		super.createDefaultEditPolicies();
18
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
19
	}
20
21
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomConstraintParameterAffixedNodeEditPart.java (+19 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.part;
2
3
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
4
import org.eclipse.gmf.runtime.notation.View;
5
import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomParametricSemanticPolicy;
6
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintParameterAffixedNodeEditPart;
7
8
public class CustomConstraintParameterAffixedNodeEditPart extends ConstraintParameterAffixedNodeEditPart {
9
10
	public CustomConstraintParameterAffixedNodeEditPart(View view) {
11
		super(view);
12
	}
13
14
	@Override
15
	protected void createDefaultEditPolicies() {
16
		super.createDefaultEditPolicies();
17
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
18
	}
19
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/part/CustomPortAffixedNodeEditPart.java (+20 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.part;
2
3
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
4
import org.eclipse.gmf.runtime.notation.View;
5
import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomParametricSemanticPolicy;
6
import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedNodeEditPart;
7
8
public class CustomPortAffixedNodeEditPart extends PortAffixedNodeEditPart {
9
10
	public CustomPortAffixedNodeEditPart(View view) {
11
		super(view);
12
	}
13
14
	@Override
15
	protected void createDefaultEditPolicies() {
16
		super.createDefaultEditPolicies();
17
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
18
	}
19
20
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/ConnectorEditPart.java (-154 lines)
Lines 1-154 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import org.eclipse.draw2d.Connection;
17
import org.eclipse.gef.EditPart;
18
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITreeBranchEditPart;
19
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
20
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
21
import org.eclipse.gmf.runtime.notation.View;
22
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.ConnectorItemSemanticEditPolicy;
23
import org.eclipse.papyrus.uml.diagram.common.editparts.UMLConnectionNodeEditPart;
24
import org.eclipse.papyrus.uml.diagram.common.figure.edge.UMLEdgeFigure;
25
26
/**
27
 * @generated
28
 */
29
public class ConnectorEditPart extends UMLConnectionNodeEditPart
30
31
implements ITreeBranchEditPart {
32
33
	/**
34
	 * @generated
35
	 */
36
	public static final int VISUAL_ID = 4001;
37
38
	/**
39
	 * @generated
40
	 */
41
	public ConnectorEditPart(View view) {
42
		super(view);
43
	}
44
45
	/**
46
	 * @generated
47
	 */
48
	protected void createDefaultEditPolicies() {
49
		super.createDefaultEditPolicies();
50
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ConnectorItemSemanticEditPolicy());
51
	}
52
53
	/**
54
	 * @generated
55
	 */
56
	protected boolean addFixedChild(EditPart childEditPart) {
57
		if(childEditPart instanceof ConnectorNameEditPart) {
58
			((ConnectorNameEditPart)childEditPart).setLabel(getPrimaryShape().getConnectorLabel());
59
			return true;
60
		}
61
		return false;
62
	}
63
64
	/**
65
	 * @generated
66
	 */
67
	protected void addChildVisual(EditPart childEditPart, int index) {
68
		if(addFixedChild(childEditPart)) {
69
			return;
70
		}
71
		super.addChildVisual(childEditPart, -1);
72
	}
73
74
	/**
75
	 * @generated
76
	 */
77
	protected boolean removeFixedChild(EditPart childEditPart) {
78
		if(childEditPart instanceof ConnectorNameEditPart) {
79
			return true;
80
		}
81
		return false;
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	protected void removeChildVisual(EditPart childEditPart) {
88
		if(removeFixedChild(childEditPart)) {
89
			return;
90
		}
91
		super.removeChildVisual(childEditPart);
92
	}
93
94
	/**
95
	 * Creates figure for this edit part.
96
	 * 
97
	 * Body of this method does not depend on settings in generation model so you may safely remove
98
	 * <i>generated</i> tag and modify it.
99
	 * 
100
	 * @generated
101
	 */
102
103
	protected Connection createConnectionFigure() {
104
		return new ConnectorFigure();
105
	}
106
107
	/**
108
	 * @generated
109
	 */
110
	public ConnectorFigure getPrimaryShape() {
111
		return (ConnectorFigure)getFigure();
112
	}
113
114
	/**
115
	 * @generated NOT extends UMLEdgeFigure
116
	 */
117
	public class ConnectorFigure extends UMLEdgeFigure {
118
119
		/**
120
		 * @generated
121
		 */
122
		private WrappingLabel fConnectorLabel;
123
124
		/**
125
		 * @generated
126
		 */
127
		public ConnectorFigure() {
128
			this.setLineWidth(1);
129
130
			createContents();
131
		}
132
133
		/**
134
		 * @generated NOT protected
135
		 */
136
		protected void createContents() {
137
138
			fConnectorLabel = new WrappingLabel();
139
			fConnectorLabel.setText("");
140
141
			this.add(fConnectorLabel);
142
143
		}
144
145
		/**
146
		 * @generated
147
		 */
148
		public WrappingLabel getConnectorLabel() {
149
			return fConnectorLabel;
150
		}
151
152
	}
153
154
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/ConnectorNameEditPart.java (-756 lines)
Lines 1-756 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import java.util.Collections;
17
import java.util.List;
18
19
import org.eclipse.draw2d.ConnectionLocator;
20
import org.eclipse.draw2d.IFigure;
21
import org.eclipse.draw2d.Label;
22
import org.eclipse.draw2d.geometry.Point;
23
import org.eclipse.emf.common.notify.Notification;
24
import org.eclipse.emf.ecore.EAnnotation;
25
import org.eclipse.emf.ecore.EObject;
26
import org.eclipse.emf.transaction.RecordingCommand;
27
import org.eclipse.emf.transaction.RunnableWithResult;
28
import org.eclipse.emf.transaction.TransactionalEditingDomain;
29
import org.eclipse.gef.AccessibleEditPart;
30
import org.eclipse.gef.EditPolicy;
31
import org.eclipse.gef.Request;
32
import org.eclipse.gef.requests.DirectEditRequest;
33
import org.eclipse.gef.tools.DirectEditManager;
34
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
35
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
36
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
37
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
38
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
39
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
40
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
41
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
42
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
43
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
44
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
45
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
46
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
47
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
48
import org.eclipse.gmf.runtime.notation.FontStyle;
49
import org.eclipse.gmf.runtime.notation.NotationPackage;
50
import org.eclipse.gmf.runtime.notation.View;
51
import org.eclipse.jface.dialogs.Dialog;
52
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
53
import org.eclipse.jface.viewers.ICellEditorValidator;
54
import org.eclipse.jface.window.Window;
55
import org.eclipse.papyrus.extensionpoints.editors.Activator;
56
import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration;
57
import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
58
import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
59
import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
60
import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
61
import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper;
62
import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
63
import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
64
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.SysmlTextSelectionEditPolicy;
65
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
66
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
67
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlParserProvider;
68
import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager;
69
import org.eclipse.papyrus.uml.diagram.common.editparts.ILabelRoleProvider;
70
import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition;
71
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
72
import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
73
import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
74
import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants;
75
import org.eclipse.papyrus.infra.emf.appearance.helper.NameLabelIconHelper;
76
import org.eclipse.swt.SWT;
77
import org.eclipse.swt.accessibility.AccessibleEvent;
78
import org.eclipse.swt.graphics.Color;
79
import org.eclipse.swt.graphics.FontData;
80
import org.eclipse.swt.graphics.Image;
81
import org.eclipse.ui.PlatformUI;
82
83
/**
84
 * @generated
85
 */
86
public class ConnectorNameEditPart extends LabelEditPart implements ITextAwareEditPart, ILabelRoleProvider {
87
88
	/**
89
	 * @generated
90
	 */
91
	public static final int VISUAL_ID = 6001;
92
93
	/**
94
	 * @generated
95
	 */
96
	private DirectEditManager manager;
97
98
	/**
99
	 * @generated
100
	 */
101
	private IParser parser;
102
103
	/**
104
	 * @generated
105
	 */
106
	private List<?> parserElements;
107
108
	/**
109
	 * @generated
110
	 */
111
	private String defaultText;
112
113
	/** direct edition mode (default, undefined, registered editor, etc.) */
114
	protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR;
115
116
	/** configuration from a registered edit dialog */
117
	protected IDirectEditorConfiguration configuration;
118
119
	/**
120
	 * @generated
121
	 */
122
	static {
123
		registerSnapBackPosition(SysmlVisualIDRegistry.getType(org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorNameEditPart.VISUAL_ID), new Point(0, 40));
124
	}
125
126
	/**
127
	 * @generated
128
	 */
129
	public ConnectorNameEditPart(View view) {
130
		super(view);
131
	}
132
133
	/**
134
	 * @generated
135
	 */
136
	protected void createDefaultEditPolicies() {
137
		super.createDefaultEditPolicies();
138
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
139
		installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new SysmlTextSelectionEditPolicy());
140
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ParametricEditPart.LinkLabelDragPolicy());
141
	}
142
143
	/**
144
	 * @generated
145
	 */
146
	public int getKeyPoint() {
147
		return ConnectionLocator.MIDDLE;
148
	}
149
150
	/**
151
	 * @generated
152
	 */
153
	protected String getLabelTextHelper(IFigure figure) {
154
		if(figure instanceof WrappingLabel) {
155
			return ((WrappingLabel)figure).getText();
156
		} else if(figure instanceof ILabelFigure) {
157
			return ((ILabelFigure)figure).getText();
158
		} else {
159
			return ((Label)figure).getText();
160
		}
161
	}
162
163
	/**
164
	 * @generated
165
	 */
166
	protected void setLabelTextHelper(IFigure figure, String text) {
167
		if(figure instanceof WrappingLabel) {
168
			((WrappingLabel)figure).setText(text);
169
		} else if(figure instanceof ILabelFigure) {
170
			((ILabelFigure)figure).setText(text);
171
		} else {
172
			((Label)figure).setText(text);
173
		}
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	protected Image getLabelIconHelper(IFigure figure) {
180
		if(figure instanceof WrappingLabel) {
181
			return ((WrappingLabel)figure).getIcon();
182
		} else if(figure instanceof ILabelFigure) {
183
			return ((ILabelFigure)figure).getIcon();
184
		} else {
185
			return ((Label)figure).getIcon();
186
		}
187
	}
188
189
	/**
190
	 * @generated
191
	 */
192
	protected void setLabelIconHelper(IFigure figure, Image icon) {
193
		if(figure instanceof WrappingLabel) {
194
			((WrappingLabel)figure).setIcon(icon);
195
		} else if(figure instanceof ILabelFigure) {
196
			((ILabelFigure)figure).setIcon(icon);
197
		} else {
198
			((Label)figure).setIcon(icon);
199
		}
200
	}
201
202
	/**
203
	 * @generated
204
	 */
205
	public void setLabel(WrappingLabel figure) {
206
		unregisterVisuals();
207
		setFigure(figure);
208
		defaultText = getLabelTextHelper(figure);
209
		registerVisuals();
210
		refreshVisuals();
211
	}
212
213
	/**
214
	 * @generated
215
	 */
216
	protected List getModelChildren() {
217
		return Collections.EMPTY_LIST;
218
	}
219
220
	/**
221
	 * @generated
222
	 */
223
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
224
		return null;
225
	}
226
227
	/**
228
	 * @generated
229
	 */
230
	protected EObject getParserElement() {
231
		return resolveSemanticElement();
232
	}
233
234
	/**
235
	 * @generated NOT
236
	 */
237
	protected Image getLabelIcon() {
238
		EObject parserElement = getParserElement();
239
		if(parserElement == null) {
240
			return null;
241
		}
242
243
		List<View> views = DiagramEditPartsUtil.findViews(parserElement, getViewer());
244
		for(View view : views) {
245
			if(NameLabelIconHelper.showLabelIcon(view)) {
246
				return SysmlElementTypes.getImage(parserElement.eClass());
247
			}
248
		}
249
		return null;
250
251
	}
252
253
	/**
254
	 * @generated
255
	 */
256
	protected String getLabelText() {
257
		String text = null;
258
		EObject parserElement = getParserElement();
259
		if(parserElement != null && getParser() != null) {
260
			text = getParser().getPrintString(new EObjectAdapter(parserElement), getParserOptions().intValue());
261
		}
262
		if(text == null || text.length() == 0) {
263
			text = defaultText;
264
		}
265
		return text;
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public void setLabelText(String text) {
272
		setLabelTextHelper(getFigure(), text);
273
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
274
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
275
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
276
		}
277
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
278
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
279
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
280
		}
281
	}
282
283
	/**
284
	 * @generated
285
	 */
286
	public String getEditText() {
287
		if(getParserElement() == null || getParser() == null) {
288
			return ""; //$NON-NLS-1$
289
		}
290
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
291
	}
292
293
	/**
294
	 * @generated
295
	 */
296
	protected boolean isEditable() {
297
		return getParser() != null;
298
	}
299
300
	/**
301
	 * @generated
302
	 */
303
	public ICellEditorValidator getEditTextValidator() {
304
		return new ICellEditorValidator() {
305
306
			public String isValid(final Object value) {
307
				if(value instanceof String) {
308
					final EObject element = getParserElement();
309
					final IParser parser = getParser();
310
					try {
311
						IParserEditStatus valid = (IParserEditStatus)getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
312
313
							public void run() {
314
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String)value));
315
							}
316
						});
317
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
318
					} catch (InterruptedException ie) {
319
						ie.printStackTrace();
320
					}
321
				}
322
323
				// shouldn't get here
324
				return null;
325
			}
326
		};
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	public IContentAssistProcessor getCompletionProcessor() {
333
		if(getParserElement() == null || getParser() == null) {
334
			return null;
335
		}
336
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
337
	}
338
339
	/**
340
	 * @generated
341
	 */
342
	public ParserOptions getParserOptions() {
343
		return ParserOptions.NONE;
344
	}
345
346
	/**
347
	 * @generated
348
	 */
349
	public IParser getParser() {
350
		if(parser == null) {
351
			parser = SysmlParserProvider.getParser(SysmlElementTypes.Connector_4001, getParserElement(), SysmlVisualIDRegistry.getType(org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorNameEditPart.VISUAL_ID));
352
		}
353
		return parser;
354
	}
355
356
	/**
357
	 * @generated
358
	 */
359
	protected DirectEditManager getManager() {
360
		if(manager == null) {
361
			setManager(new MultilineLabelDirectEditManager(this, MultilineLabelDirectEditManager.getTextCellEditorClass(this), SysmlEditPartFactory.getTextCellEditorLocator(this)));
362
		}
363
		return manager;
364
	}
365
366
	/**
367
	 * @generated
368
	 */
369
	protected void setManager(DirectEditManager manager) {
370
		this.manager = manager;
371
	}
372
373
	/**
374
	 * @generated
375
	 */
376
	protected void performDirectEdit() {
377
		getManager().show();
378
	}
379
380
	/**
381
	 * @generated
382
	 */
383
	protected void performDirectEdit(Point eventLocation) {
384
		if(getManager() instanceof TextDirectEditManager) {
385
			((TextDirectEditManager)getManager()).show(eventLocation.getSWTPoint());
386
		}
387
	}
388
389
	/**
390
	 * @generated
391
	 */
392
	private void performDirectEdit(char initialCharacter) {
393
		if(getManager() instanceof TextDirectEditManager) {
394
			((TextDirectEditManager)getManager()).show(initialCharacter);
395
		} else {
396
			performDirectEdit();
397
		}
398
	}
399
400
	/**
401
	 * @generated
402
	 */
403
	protected void performDirectEditRequest(Request request) {
404
405
		final Request theRequest = request;
406
407
		if(IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
408
			directEditionMode = getDirectEditionType();
409
		}
410
		switch(directEditionMode) {
411
		case IDirectEdition.NO_DIRECT_EDITION:
412
			// no direct edition mode => does nothing
413
			return;
414
		case IDirectEdition.EXTENDED_DIRECT_EDITOR:
415
			updateExtendedEditorConfiguration();
416
			if(configuration == null || configuration.getLanguage() == null) {
417
				performDefaultDirectEditorEdit(theRequest);
418
			} else {
419
				configuration.preEditAction(resolveSemanticElement());
420
				Dialog dialog = null;
421
				if(configuration instanceof IPopupEditorConfiguration) {
422
					IPopupEditorHelper helper = ((IPopupEditorConfiguration)configuration).createPopupEditorHelper(this);
423
					helper.showEditor();
424
					return;
425
				} else if(configuration instanceof IAdvancedEditorConfiguration) {
426
					dialog = ((IAdvancedEditorConfiguration)configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()));
427
				} else if(configuration instanceof IDirectEditorConfiguration) {
428
					dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), ((IDirectEditorConfiguration)configuration).getTextToEdit(resolveSemanticElement()), (IDirectEditorConfiguration)configuration);
429
				} else {
430
					return;
431
				}
432
				final Dialog finalDialog = dialog;
433
434
				if(Window.OK == dialog.open()) {
435
					TransactionalEditingDomain domain = getEditingDomain();
436
					RecordingCommand command = new RecordingCommand(domain, "Edit Label") {
437
438
						@Override
439
						protected void doExecute() {
440
							configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog)finalDialog).getValue());
441
442
						}
443
					};
444
					domain.getCommandStack().execute(command);
445
				}
446
			}
447
			break;
448
		case IDirectEdition.DEFAULT_DIRECT_EDITOR:
449
450
			// initialize the direct edit manager
451
			try {
452
				getEditingDomain().runExclusive(new Runnable() {
453
454
					public void run() {
455
						if(isActive() && isEditable()) {
456
							if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
457
								Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
458
								performDirectEdit(initialChar.charValue());
459
							} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
460
								DirectEditRequest editRequest = (DirectEditRequest)theRequest;
461
								performDirectEdit(editRequest.getLocation());
462
							} else {
463
								performDirectEdit();
464
							}
465
						}
466
					}
467
				});
468
			} catch (InterruptedException e) {
469
				e.printStackTrace();
470
			}
471
			break;
472
		default:
473
			break;
474
		}
475
	}
476
477
	/**
478
	 * @generated
479
	 */
480
	protected void refreshVisuals() {
481
		super.refreshVisuals();
482
		refreshLabel();
483
		refreshFont();
484
		refreshFontColor();
485
		refreshUnderline();
486
		refreshStrikeThrough();
487
	}
488
489
	/**
490
	 * @generated
491
	 */
492
	protected void refreshLabel() {
493
		EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
494
		if(maskLabelPolicy == null) {
495
			setLabelTextHelper(getFigure(), getLabelText());
496
			setLabelIconHelper(getFigure(), getLabelIcon());
497
		}
498
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
499
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
500
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
501
		}
502
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
503
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
504
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
505
		}
506
	}
507
508
	/**
509
	 * @generated
510
	 */
511
	protected void refreshUnderline() {
512
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
513
		if(style != null && getFigure() instanceof WrappingLabel) {
514
			((WrappingLabel)getFigure()).setTextUnderline(style.isUnderline());
515
		}
516
	}
517
518
	/**
519
	 * @generated
520
	 */
521
	protected void refreshStrikeThrough() {
522
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
523
		if(style != null && getFigure() instanceof WrappingLabel) {
524
			((WrappingLabel)getFigure()).setTextStrikeThrough(style.isStrikeThrough());
525
		}
526
	}
527
528
	/**
529
	 * @generated
530
	 */
531
	protected void refreshFont() {
532
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
533
		if(style != null) {
534
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
535
			setFont(fontData);
536
		}
537
	}
538
539
	/**
540
	 * @generated
541
	 */
542
	protected void setFontColor(Color color) {
543
		getFigure().setForegroundColor(color);
544
	}
545
546
	/**
547
	 * @generated
548
	 */
549
	protected void addSemanticListeners() {
550
		if(getParser() instanceof ISemanticParser) {
551
			EObject element = resolveSemanticElement();
552
			parserElements = ((ISemanticParser)getParser()).getSemanticElementsBeingParsed(element);
553
			for(int i = 0; i < parserElements.size(); i++) {
554
				addListenerFilter("SemanticModel" + i, this, (EObject)parserElements.get(i)); //$NON-NLS-1$
555
			}
556
		} else {
557
			super.addSemanticListeners();
558
		}
559
	}
560
561
	/**
562
	 * @generated
563
	 */
564
	protected void removeSemanticListeners() {
565
		if(parserElements != null) {
566
			for(int i = 0; i < parserElements.size(); i++) {
567
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
568
			}
569
		} else {
570
			super.removeSemanticListeners();
571
		}
572
	}
573
574
	/**
575
	 * @generated
576
	 */
577
	protected AccessibleEditPart getAccessibleEditPart() {
578
		if(accessibleEP == null) {
579
			accessibleEP = new AccessibleGraphicalEditPart() {
580
581
				public void getName(AccessibleEvent e) {
582
					e.result = getLabelTextHelper(getFigure());
583
				}
584
			};
585
		}
586
		return accessibleEP;
587
	}
588
589
	/**
590
	 * @generated
591
	 */
592
	private View getFontStyleOwnerView() {
593
		return getPrimaryView();
594
	}
595
596
	/**
597
	 * Returns the kind of associated editor for direct edition.
598
	 * 
599
	 * @return an <code>int</code> corresponding to the kind of direct editor, @see
600
	 *         org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition
601
	 * @generated
602
	 */
603
	public int getDirectEditionType() {
604
		if(checkExtendedEditor()) {
605
			initExtendedEditorConfiguration();
606
			return IDirectEdition.EXTENDED_DIRECT_EDITOR;
607
		}
608
		if(checkDefaultEdition()) {
609
			return IDirectEdition.DEFAULT_DIRECT_EDITOR;
610
		}
611
612
		// not a named element. no specific editor => do nothing
613
		return IDirectEdition.NO_DIRECT_EDITION;
614
	}
615
616
	/**
617
	 * Checks if an extended editor is present.
618
	 * 
619
	 * @return <code>true</code> if an extended editor is present.
620
	 * @generated
621
	 */
622
	protected boolean checkExtendedEditor() {
623
		if(resolveSemanticElement() != null) {
624
			return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName());
625
		}
626
		return false;
627
	}
628
629
	/**
630
	 * Checks if a default direct edition is available
631
	 * 
632
	 * @return <code>true</code> if a default direct edition is available
633
	 * @generated
634
	 */
635
	protected boolean checkDefaultEdition() {
636
		return (getParser() != null);
637
	}
638
639
	/**
640
	 * Initializes the extended editor configuration
641
	 * 
642
	 * @generated
643
	 */
644
	protected void initExtendedEditorConfiguration() {
645
		if(configuration == null) {
646
			final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
647
			if(languagePreferred != null && !languagePreferred.equals("")) {
648
				configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
649
			} else {
650
				configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName());
651
			}
652
		}
653
	}
654
655
	/**
656
	 * Updates the preference configuration
657
	 */
658
	protected void updateExtendedEditorConfiguration() {
659
		String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
660
		if(languagePreferred != null && !languagePreferred.equals("") && languagePreferred != configuration.getLanguage()) {
661
			configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
662
		} else if(IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) {
663
			configuration = null;
664
		}
665
	}
666
667
	/**
668
	 * Performs the direct edit usually used by GMF editors.
669
	 * 
670
	 * @param theRequest
671
	 *        the direct edit request that starts the direct edit system
672
	 */
673
	protected void performDefaultDirectEditorEdit(final Request theRequest) {
674
		// initialize the direct edit manager
675
		try {
676
			getEditingDomain().runExclusive(new Runnable() {
677
678
				public void run() {
679
					if(isActive() && isEditable()) {
680
						if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
681
							Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
682
							performDirectEdit(initialChar.charValue());
683
						} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
684
							DirectEditRequest editRequest = (DirectEditRequest)theRequest;
685
							performDirectEdit(editRequest.getLocation());
686
						} else {
687
							performDirectEdit();
688
						}
689
					}
690
				}
691
			});
692
		} catch (InterruptedException e) {
693
			e.printStackTrace();
694
		}
695
	}
696
697
	/**
698
	 * @generated
699
	 */
700
	protected void handleNotificationEvent(Notification event) {
701
		Object feature = event.getFeature();
702
		if(NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
703
			Integer c = (Integer)event.getNewValue();
704
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
705
		} else if(NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
706
			refreshUnderline();
707
		} else if(NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
708
			refreshStrikeThrough();
709
		} else if(NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
710
			refreshFont();
711
		} else {
712
			if(getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
713
				refreshLabel();
714
			}
715
			if(getParser() instanceof ISemanticParser) {
716
				ISemanticParser modelParser = (ISemanticParser)getParser();
717
				if(modelParser.areSemanticElementsAffected(null, event)) {
718
					removeSemanticListeners();
719
					if(resolveSemanticElement() != null) {
720
						addSemanticListeners();
721
					}
722
					refreshLabel();
723
				}
724
			}
725
		}
726
727
		if(event.getNewValue() instanceof EAnnotation && VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON.equals(((EAnnotation)event.getNewValue()).getSource())) {
728
			refreshLabel();
729
		}
730
731
		super.handleNotificationEvent(event);
732
	}
733
734
	/**
735
	 * @generated
736
	 */
737
	protected IFigure createFigure() {
738
		// Parent should assign one using setLabel() method
739
		return null;
740
	}
741
742
	/**
743
	 * @generated
744
	 */
745
	public String getLabelRole() {
746
		return "Name";//$NON-NLS-1$
747
	}
748
749
	/**
750
	 * @generated
751
	 */
752
	public String getIconPathRole() {
753
		return "platform:/plugin/org.eclipse.papyrus.uml.diagram.common/icons/label_role/name.png";//$NON-NLS-1$
754
	}
755
756
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/ConstraintLabelEditPart.java (-767 lines)
Lines 1-767 Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
2
3
import java.util.Collections;
4
import java.util.List;
5
6
import org.eclipse.draw2d.IFigure;
7
import org.eclipse.draw2d.Label;
8
import org.eclipse.draw2d.geometry.Point;
9
import org.eclipse.emf.common.notify.Notification;
10
import org.eclipse.emf.ecore.EAnnotation;
11
import org.eclipse.emf.ecore.EObject;
12
import org.eclipse.emf.transaction.RecordingCommand;
13
import org.eclipse.emf.transaction.RunnableWithResult;
14
import org.eclipse.emf.transaction.TransactionalEditingDomain;
15
import org.eclipse.gef.AccessibleEditPart;
16
import org.eclipse.gef.EditPolicy;
17
import org.eclipse.gef.Request;
18
import org.eclipse.gef.requests.DirectEditRequest;
19
import org.eclipse.gef.tools.DirectEditManager;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
24
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
28
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
29
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
30
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
31
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
32
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
33
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
34
import org.eclipse.gmf.runtime.notation.FontStyle;
35
import org.eclipse.gmf.runtime.notation.NotationPackage;
36
import org.eclipse.gmf.runtime.notation.View;
37
import org.eclipse.jface.dialogs.Dialog;
38
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
39
import org.eclipse.jface.viewers.ICellEditorValidator;
40
import org.eclipse.jface.window.Window;
41
import org.eclipse.papyrus.extensionpoints.editors.Activator;
42
import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration;
43
import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
44
import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
45
import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
46
import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
47
import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper;
48
import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
49
import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
50
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromModelEditPolicy;
51
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.SysmlTextSelectionEditPolicy;
52
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
53
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
54
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlParserProvider;
55
import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager;
56
import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition;
57
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
58
import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
59
import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
60
import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants;
61
import org.eclipse.papyrus.infra.emf.appearance.helper.NameLabelIconHelper;
62
import org.eclipse.swt.SWT;
63
import org.eclipse.swt.accessibility.AccessibleEvent;
64
import org.eclipse.swt.graphics.Color;
65
import org.eclipse.swt.graphics.FontData;
66
import org.eclipse.swt.graphics.Image;
67
import org.eclipse.ui.PlatformUI;
68
69
/**
70
 * @generated
71
 */
72
public class ConstraintLabelEditPart extends CompartmentEditPart implements ITextAwareEditPart {
73
74
	/**
75
	 * @generated
76
	 */
77
	public static final int VISUAL_ID = 5004;
78
79
	/**
80
	 * @generated
81
	 */
82
	private DirectEditManager manager;
83
84
	/**
85
	 * @generated
86
	 */
87
	private IParser parser;
88
89
	/**
90
	 * @generated
91
	 */
92
	private List<?> parserElements;
93
94
	/**
95
	 * @generated
96
	 */
97
	private String defaultText;
98
99
	/** direct edition mode (default, undefined, registered editor, etc.) */
100
	protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR;
101
102
	/** configuration from a registered edit dialog */
103
	protected IDirectEditorConfiguration configuration;
104
105
	/**
106
	 * @generated
107
	 */
108
	public ConstraintLabelEditPart(View view) {
109
		super(view);
110
	}
111
112
	/**
113
	 * @generated
114
	 */
115
	protected void createDefaultEditPolicies() {
116
		super.createDefaultEditPolicies();
117
		installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new SysmlTextSelectionEditPolicy());
118
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
119
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ParametricEditPart.NodeLabelDragPolicy());
120
		installEditPolicy(RequestConstants.REQ_SEMANTIC_WRAPPER, new NoDeleteFromModelEditPolicy());
121
	}
122
123
	/**
124
	 * @generated
125
	 */
126
	protected String getLabelTextHelper(IFigure figure) {
127
		if(figure instanceof WrappingLabel) {
128
			return ((WrappingLabel)figure).getText();
129
		} else if(figure instanceof ILabelFigure) {
130
			return ((ILabelFigure)figure).getText();
131
		} else {
132
			return ((Label)figure).getText();
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected void setLabelTextHelper(IFigure figure, String text) {
140
		if(figure instanceof WrappingLabel) {
141
			((WrappingLabel)figure).setText(text);
142
		} else if(figure instanceof ILabelFigure) {
143
			((ILabelFigure)figure).setText(text);
144
		} else {
145
			((Label)figure).setText(text);
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected Image getLabelIconHelper(IFigure figure) {
153
		if(figure instanceof WrappingLabel) {
154
			return ((WrappingLabel)figure).getIcon();
155
		} else if(figure instanceof ILabelFigure) {
156
			return ((ILabelFigure)figure).getIcon();
157
		} else {
158
			return ((Label)figure).getIcon();
159
		}
160
	}
161
162
	/**
163
	 * @generated
164
	 */
165
	protected void setLabelIconHelper(IFigure figure, Image icon) {
166
		if(figure instanceof WrappingLabel) {
167
			((WrappingLabel)figure).setIcon(icon);
168
		} else if(figure instanceof ILabelFigure) {
169
			((ILabelFigure)figure).setIcon(icon);
170
		} else {
171
			((Label)figure).setIcon(icon);
172
		}
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public void setLabel(WrappingLabel figure) {
179
		unregisterVisuals();
180
		setFigure(figure);
181
		defaultText = getLabelTextHelper(figure);
182
		registerVisuals();
183
		refreshVisuals();
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	protected List getModelChildren() {
190
		return Collections.EMPTY_LIST;
191
	}
192
193
	/**
194
	 * @generated
195
	 */
196
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
197
		return null;
198
	}
199
200
	/**
201
	 * @generated
202
	 */
203
	protected EObject getParserElement() {
204
		return resolveSemanticElement();
205
	}
206
207
	/**
208
	 * @generated NOT
209
	 */
210
	protected Image getLabelIcon() {
211
		EObject parserElement = getParserElement();
212
		if(parserElement == null) {
213
			return null;
214
		}
215
216
		List<View> views = DiagramEditPartsUtil.findViews(parserElement, getViewer());
217
		for(View view : views) {
218
			if(NameLabelIconHelper.showLabelIcon(view)) {
219
				return SysmlElementTypes.getImage(parserElement.eClass());
220
			}
221
		}
222
		return null;
223
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	protected String getLabelText() {
230
		String text = null;
231
		EObject parserElement = getParserElement();
232
		if(parserElement != null && getParser() != null) {
233
			text = getParser().getPrintString(new EObjectAdapter(parserElement), getParserOptions().intValue());
234
		}
235
		if(text == null || text.length() == 0) {
236
			text = defaultText;
237
		}
238
		return text;
239
	}
240
241
	/**
242
	 * @generated
243
	 */
244
	public void setLabelText(String text) {
245
		setLabelTextHelper(getFigure(), text);
246
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
247
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
248
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
249
		}
250
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
251
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
252
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
253
		}
254
	}
255
256
	/**
257
	 * @generated
258
	 */
259
	public String getEditText() {
260
		if(getParserElement() == null || getParser() == null) {
261
			return ""; //$NON-NLS-1$
262
		}
263
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
264
	}
265
266
	/**
267
	 * @generated
268
	 */
269
	protected boolean isEditable() {
270
		return getParser() != null;
271
	}
272
273
	/**
274
	 * @generated
275
	 */
276
	public ICellEditorValidator getEditTextValidator() {
277
		return new ICellEditorValidator() {
278
279
			public String isValid(final Object value) {
280
				if(value instanceof String) {
281
					final EObject element = getParserElement();
282
					final IParser parser = getParser();
283
					try {
284
						IParserEditStatus valid = (IParserEditStatus)getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
285
286
							public void run() {
287
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String)value));
288
							}
289
						});
290
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
291
					} catch (InterruptedException ie) {
292
						ie.printStackTrace();
293
					}
294
				}
295
296
				// shouldn't get here
297
				return null;
298
			}
299
		};
300
	}
301
302
	/**
303
	 * @generated
304
	 */
305
	public IContentAssistProcessor getCompletionProcessor() {
306
		if(getParserElement() == null || getParser() == null) {
307
			return null;
308
		}
309
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	public ParserOptions getParserOptions() {
316
		return ParserOptions.NONE;
317
	}
318
319
	/**
320
	 * @generated
321
	 */
322
	public IParser getParser() {
323
		if(parser == null) {
324
			parser = SysmlParserProvider.getParser(SysmlElementTypes.ConstraintProperty_2003, getParserElement(), SysmlVisualIDRegistry.getType(org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintLabelEditPart.VISUAL_ID));
325
		}
326
		return parser;
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	protected DirectEditManager getManager() {
333
		if(manager == null) {
334
			setManager(new MultilineLabelDirectEditManager(this, MultilineLabelDirectEditManager.getTextCellEditorClass(this), SysmlEditPartFactory.getTextCellEditorLocator(this)));
335
		}
336
		return manager;
337
	}
338
339
	/**
340
	 * @generated
341
	 */
342
	protected void setManager(DirectEditManager manager) {
343
		this.manager = manager;
344
	}
345
346
	/**
347
	 * @generated
348
	 */
349
	protected void performDirectEdit() {
350
		getManager().show();
351
	}
352
353
	/**
354
	 * @generated
355
	 */
356
	protected void performDirectEdit(Point eventLocation) {
357
		if(getManager() instanceof TextDirectEditManager) {
358
			((TextDirectEditManager)getManager()).show(eventLocation.getSWTPoint());
359
		}
360
	}
361
362
	/**
363
	 * @generated
364
	 */
365
	private void performDirectEdit(char initialCharacter) {
366
		if(getManager() instanceof TextDirectEditManager) {
367
			((TextDirectEditManager)getManager()).show(initialCharacter);
368
		} else {
369
			performDirectEdit();
370
		}
371
	}
372
373
	/**
374
	 * @generated
375
	 */
376
	protected void performDirectEditRequest(Request request) {
377
378
		final Request theRequest = request;
379
380
		if(IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
381
			directEditionMode = getDirectEditionType();
382
		}
383
		switch(directEditionMode) {
384
		case IDirectEdition.NO_DIRECT_EDITION:
385
			// no direct edition mode => does nothing
386
			return;
387
		case IDirectEdition.EXTENDED_DIRECT_EDITOR:
388
			updateExtendedEditorConfiguration();
389
			if(configuration == null || configuration.getLanguage() == null) {
390
				performDefaultDirectEditorEdit(theRequest);
391
			} else {
392
				configuration.preEditAction(resolveSemanticElement());
393
				Dialog dialog = null;
394
				if(configuration instanceof IPopupEditorConfiguration) {
395
					IPopupEditorHelper helper = ((IPopupEditorConfiguration)configuration).createPopupEditorHelper(this);
396
					helper.showEditor();
397
					return;
398
				} else if(configuration instanceof IAdvancedEditorConfiguration) {
399
					dialog = ((IAdvancedEditorConfiguration)configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()));
400
				} else if(configuration instanceof IDirectEditorConfiguration) {
401
					dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), ((IDirectEditorConfiguration)configuration).getTextToEdit(resolveSemanticElement()), (IDirectEditorConfiguration)configuration);
402
				} else {
403
					return;
404
				}
405
				final Dialog finalDialog = dialog;
406
407
				if(Window.OK == dialog.open()) {
408
					TransactionalEditingDomain domain = getEditingDomain();
409
					RecordingCommand command = new RecordingCommand(domain, "Edit Label") {
410
411
						@Override
412
						protected void doExecute() {
413
							configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog)finalDialog).getValue());
414
415
						}
416
					};
417
					domain.getCommandStack().execute(command);
418
				}
419
			}
420
			break;
421
		case IDirectEdition.DEFAULT_DIRECT_EDITOR:
422
423
			// initialize the direct edit manager
424
			try {
425
				getEditingDomain().runExclusive(new Runnable() {
426
427
					public void run() {
428
						if(isActive() && isEditable()) {
429
							if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
430
								Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
431
								performDirectEdit(initialChar.charValue());
432
							} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
433
								DirectEditRequest editRequest = (DirectEditRequest)theRequest;
434
								performDirectEdit(editRequest.getLocation());
435
							} else {
436
								performDirectEdit();
437
							}
438
						}
439
					}
440
				});
441
			} catch (InterruptedException e) {
442
				e.printStackTrace();
443
			}
444
			break;
445
		default:
446
			break;
447
		}
448
	}
449
450
	/**
451
	 * @generated
452
	 */
453
	protected void refreshVisuals() {
454
		super.refreshVisuals();
455
		refreshLabel();
456
		refreshFont();
457
		refreshFontColor();
458
		refreshUnderline();
459
		refreshStrikeThrough();
460
	}
461
462
	/**
463
	 * @generated
464
	 */
465
	protected void refreshLabel() {
466
		EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
467
		if(maskLabelPolicy == null) {
468
			setLabelTextHelper(getFigure(), getLabelText());
469
			setLabelIconHelper(getFigure(), getLabelIcon());
470
		}
471
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
472
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
473
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
474
		}
475
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
476
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
477
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
478
		}
479
	}
480
481
	/**
482
	 * @generated
483
	 */
484
	protected void refreshUnderline() {
485
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
486
		if(style != null && getFigure() instanceof WrappingLabel) {
487
			((WrappingLabel)getFigure()).setTextUnderline(style.isUnderline());
488
		}
489
	}
490
491
	/**
492
	 * @generated
493
	 */
494
	protected void refreshStrikeThrough() {
495
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
496
		if(style != null && getFigure() instanceof WrappingLabel) {
497
			((WrappingLabel)getFigure()).setTextStrikeThrough(style.isStrikeThrough());
498
		}
499
	}
500
501
	/**
502
	 * @generated
503
	 */
504
	protected void refreshFont() {
505
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
506
		if(style != null) {
507
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
508
			setFont(fontData);
509
		}
510
	}
511
512
	/**
513
	 * @generated
514
	 */
515
	protected void setFontColor(Color color) {
516
		getFigure().setForegroundColor(color);
517
	}
518
519
	/**
520
	 * @generated
521
	 */
522
	protected void addSemanticListeners() {
523
		if(getParser() instanceof ISemanticParser) {
524
			EObject element = resolveSemanticElement();
525
			parserElements = ((ISemanticParser)getParser()).getSemanticElementsBeingParsed(element);
526
			for(int i = 0; i < parserElements.size(); i++) {
527
				addListenerFilter("SemanticModel" + i, this, (EObject)parserElements.get(i)); //$NON-NLS-1$
528
			}
529
		} else {
530
			super.addSemanticListeners();
531
		}
532
	}
533
534
	/**
535
	 * @generated
536
	 */
537
	protected void removeSemanticListeners() {
538
		if(parserElements != null) {
539
			for(int i = 0; i < parserElements.size(); i++) {
540
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
541
			}
542
		} else {
543
			super.removeSemanticListeners();
544
		}
545
	}
546
547
	/**
548
	 * @generated
549
	 */
550
	protected AccessibleEditPart getAccessibleEditPart() {
551
		if(accessibleEP == null) {
552
			accessibleEP = new AccessibleGraphicalEditPart() {
553
554
				public void getName(AccessibleEvent e) {
555
					e.result = getLabelTextHelper(getFigure());
556
				}
557
			};
558
		}
559
		return accessibleEP;
560
	}
561
562
	/**
563
	 * @generated
564
	 */
565
	private View getFontStyleOwnerView() {
566
		return getPrimaryView();
567
	}
568
569
	/**
570
	 * Returns the kind of associated editor for direct edition.
571
	 * 
572
	 * @return an <code>int</code> corresponding to the kind of direct editor, @see
573
	 *         org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition
574
	 * @generated
575
	 */
576
	public int getDirectEditionType() {
577
		if(checkExtendedEditor()) {
578
			initExtendedEditorConfiguration();
579
			return IDirectEdition.EXTENDED_DIRECT_EDITOR;
580
		}
581
		if(checkDefaultEdition()) {
582
			return IDirectEdition.DEFAULT_DIRECT_EDITOR;
583
		}
584
585
		// not a named element. no specific editor => do nothing
586
		return IDirectEdition.NO_DIRECT_EDITION;
587
	}
588
589
	/**
590
	 * Checks if an extended editor is present.
591
	 * 
592
	 * @return <code>true</code> if an extended editor is present.
593
	 * @generated
594
	 */
595
	protected boolean checkExtendedEditor() {
596
		if(resolveSemanticElement() != null) {
597
			return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName());
598
		}
599
		return false;
600
	}
601
602
	/**
603
	 * Checks if a default direct edition is available
604
	 * 
605
	 * @return <code>true</code> if a default direct edition is available
606
	 * @generated
607
	 */
608
	protected boolean checkDefaultEdition() {
609
		return (getParser() != null);
610
	}
611
612
	/**
613
	 * Initializes the extended editor configuration
614
	 * 
615
	 * @generated
616
	 */
617
	protected void initExtendedEditorConfiguration() {
618
		if(configuration == null) {
619
			final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
620
			if(languagePreferred != null && !languagePreferred.equals("")) {
621
				configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
622
			} else {
623
				configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName());
624
			}
625
		}
626
	}
627
628
	/**
629
	 * Updates the preference configuration
630
	 */
631
	protected void updateExtendedEditorConfiguration() {
632
		String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
633
		if(languagePreferred != null && !languagePreferred.equals("") && languagePreferred != configuration.getLanguage()) {
634
			configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
635
		} else if(IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) {
636
			configuration = null;
637
		}
638
	}
639
640
	/**
641
	 * Performs the direct edit usually used by GMF editors.
642
	 * 
643
	 * @param theRequest
644
	 *        the direct edit request that starts the direct edit system
645
	 */
646
	protected void performDefaultDirectEditorEdit(final Request theRequest) {
647
		// initialize the direct edit manager
648
		try {
649
			getEditingDomain().runExclusive(new Runnable() {
650
651
				public void run() {
652
					if(isActive() && isEditable()) {
653
						if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
654
							Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
655
							performDirectEdit(initialChar.charValue());
656
						} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
657
							DirectEditRequest editRequest = (DirectEditRequest)theRequest;
658
							performDirectEdit(editRequest.getLocation());
659
						} else {
660
							performDirectEdit();
661
						}
662
					}
663
				}
664
			});
665
		} catch (InterruptedException e) {
666
			e.printStackTrace();
667
		}
668
	}
669
670
	/**
671
	 * @generated
672
	 */
673
	protected void addNotationalListeners() {
674
		super.addNotationalListeners();
675
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
676
	}
677
678
	/**
679
	 * @generated
680
	 */
681
	protected void removeNotationalListeners() {
682
		super.removeNotationalListeners();
683
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
684
	}
685
686
	/**
687
	 * @generated
688
	 */
689
	protected void handleNotificationEvent(Notification event) {
690
		refreshLabel();
691
		Object feature = event.getFeature();
692
		if(NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
693
			Integer c = (Integer)event.getNewValue();
694
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
695
		} else if(NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
696
			refreshUnderline();
697
		} else if(NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
698
			refreshStrikeThrough();
699
		} else if(NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
700
			refreshFont();
701
		} else {
702
			if(getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
703
				refreshLabel();
704
			}
705
			if(getParser() instanceof ISemanticParser) {
706
				ISemanticParser modelParser = (ISemanticParser)getParser();
707
				if(modelParser.areSemanticElementsAffected(null, event)) {
708
					removeSemanticListeners();
709
					if(resolveSemanticElement() != null) {
710
						addSemanticListeners();
711
					}
712
					refreshLabel();
713
				}
714
			}
715
		}
716
717
		if(event.getNewValue() instanceof EAnnotation && VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON.equals(((EAnnotation)event.getNewValue()).getSource())) {
718
			refreshLabel();
719
		}
720
721
		super.handleNotificationEvent(event);
722
	}
723
724
	/**
725
	 * @generated
726
	 */
727
	protected IFigure createFigure() {
728
		// Parent should assign one using setLabel() method
729
		return null;
730
	}
731
732
	private static final String ADD_PARENT_MODEL = "AddParentModel";
733
734
	/**
735
	 * @generated
736
	 */
737
	public void activate() {
738
		super.activate();
739
		addOwnerElementListeners();
740
	}
741
742
	/**
743
	 * @generated
744
	 */
745
	protected void addOwnerElementListeners() {
746
		addListenerFilter(ADD_PARENT_MODEL, this, ((View)getParent().getModel())); //$NON-NLS-1$
747
748
	}
749
750
	/**
751
	 * @generated
752
	 */
753
	public void deactivate() {
754
		removeOwnerElementListeners();
755
		super.deactivate();
756
757
	}
758
759
	/**
760
	 * @generated
761
	 */
762
	protected void removeOwnerElementListeners() {
763
		removeListenerFilter(ADD_PARENT_MODEL);
764
765
	}
766
767
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/ConstraintPropertyEditPart.java (-496 lines)
Lines 1-496 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import org.eclipse.draw2d.GridData;
17
import org.eclipse.draw2d.GridLayout;
18
import org.eclipse.draw2d.IFigure;
19
import org.eclipse.draw2d.PositionConstants;
20
import org.eclipse.draw2d.RoundedRectangle;
21
import org.eclipse.draw2d.Shape;
22
import org.eclipse.draw2d.StackLayout;
23
import org.eclipse.draw2d.geometry.Dimension;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.gef.EditPart;
27
import org.eclipse.gef.EditPolicy;
28
import org.eclipse.gef.Request;
29
import org.eclipse.gef.RequestConstants;
30
import org.eclipse.gef.commands.Command;
31
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
32
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
33
import org.eclipse.gef.requests.CreateRequest;
34
import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderedShapeEditPart;
35
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
36
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
37
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CreationEditPolicy;
38
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.DragDropEditPolicy;
39
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
40
import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
41
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
42
import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
43
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
44
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
45
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
46
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
47
import org.eclipse.gmf.runtime.notation.NotationPackage;
48
import org.eclipse.gmf.runtime.notation.View;
49
import org.eclipse.jface.preference.IPreferenceStore;
50
import org.eclipse.jface.preference.PreferenceConverter;
51
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.GradientPreferenceConverter;
52
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
53
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
54
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.ConstraintPropertyItemSemanticEditPolicy;
55
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.CreateParameterEditPolicy;
56
import org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel;
57
import org.eclipse.papyrus.sysml.diagram.parametric.helper.SelfCompartmentNotificationHelper;
58
import org.eclipse.papyrus.sysml.diagram.parametric.locator.ParameterPositionLocator;
59
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
60
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
61
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
62
import org.eclipse.papyrus.uml.diagram.common.editpolicies.BorderItemResizableEditPolicy;
63
import org.eclipse.papyrus.uml.diagram.common.helper.PreferenceInitializerForElementHelper;
64
import org.eclipse.swt.graphics.Color;
65
import org.eclipse.uml2.uml.Property;
66
import org.eclipse.uml2.uml.UMLPackage;
67
68
/**
69
 * @generated
70
 */
71
public class ConstraintPropertyEditPart extends
72
73
AbstractBorderedShapeEditPart {
74
75
	/**
76
	 * @generated
77
	 */
78
	public static final int VISUAL_ID = 2003;
79
80
	/**
81
	 * @generated
82
	 */
83
	protected IFigure contentPane;
84
85
	/**
86
	 * @generated
87
	 */
88
	protected IFigure primaryShape;
89
90
	/**
91
	 * Notifier for listening and stop listening model element.
92
	 */
93
	private SelfCompartmentNotificationHelper notifier = new SelfCompartmentNotificationHelper(this, UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute(), (IHintedType)SysmlElementTypes.Property_3002);
94
95
	/**
96
	 * @generated
97
	 */
98
	public ConstraintPropertyEditPart(View view) {
99
		super(view);
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	protected void createDefaultEditPolicies() {
106
		installEditPolicy(EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());
107
		super.createDefaultEditPolicies();
108
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ConstraintPropertyItemSemanticEditPolicy());
109
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new DragDropEditPolicy());
110
111
		//in Papyrus diagrams are not strongly synchronised
112
		//installEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CANONICAL_ROLE, new org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.ConstraintPropertyCanonicalEditPolicy());
113
114
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
115
		installEditPolicy(RequestConstants.REQ_CREATE, new CreateParameterEditPolicy());
116
		// XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
117
		// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected LayoutEditPolicy createLayoutEditPolicy() {
124
		org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy lep = new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy() {
125
126
			protected EditPolicy createChildEditPolicy(EditPart child) {
127
				View childView = (View)child.getModel();
128
				switch(SysmlVisualIDRegistry.getVisualID(childView)) {
129
				case Property2EditPart.VISUAL_ID:
130
131
					return new BorderItemResizableEditPolicy();
132
133
				}
134
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
135
				if(result == null) {
136
					result = new NonResizableEditPolicy();
137
				}
138
				return result;
139
			}
140
141
			protected Command getMoveChildrenCommand(Request request) {
142
				return null;
143
			}
144
145
			protected Command getCreateCommand(CreateRequest request) {
146
				return null;
147
			}
148
		};
149
		return lep;
150
	}
151
152
	/**
153
	 * @generated
154
	 */
155
	protected IFigure createNodeShape() {
156
		return primaryShape = new ConstraintPropertyFigureDescriptor();
157
	}
158
159
	/**
160
	 * @generated
161
	 */
162
	public ConstraintPropertyFigureDescriptor getPrimaryShape() {
163
		return (ConstraintPropertyFigureDescriptor)primaryShape;
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected boolean addFixedChild(EditPart childEditPart) {
170
		if(childEditPart instanceof ConstraintPropertyNameEditPart) {
171
			((ConstraintPropertyNameEditPart)childEditPart).setLabel(getPrimaryShape().getConstraintPropertyFigureLabel());
172
			return true;
173
		}
174
		if(childEditPart instanceof ConstraintLabelEditPart) {
175
			((ConstraintLabelEditPart)childEditPart).setLabel(getPrimaryShape().getConstraintLabel());
176
			return true;
177
		}
178
179
		//Papyrus Gencode :Affixed Parameter locator
180
		if(childEditPart instanceof Property2EditPart) {
181
			IBorderItemLocator locator = new ParameterPositionLocator(getMainFigure(), PositionConstants.NONE);
182
			getBorderedFigure().getBorderItemContainer().add(((Property2EditPart)childEditPart).getFigure(), locator);
183
			return true;
184
		}
185
186
		return false;
187
	}
188
189
	/**
190
	 * @generated
191
	 */
192
	protected boolean removeFixedChild(EditPart childEditPart) {
193
		if(childEditPart instanceof ConstraintPropertyNameEditPart) {
194
			return true;
195
		}
196
		if(childEditPart instanceof ConstraintLabelEditPart) {
197
			return true;
198
		}
199
		if(childEditPart instanceof Property2EditPart) {
200
			getBorderedFigure().getBorderItemContainer().remove(((Property2EditPart)childEditPart).getFigure());
201
			return true;
202
		}
203
		return false;
204
	}
205
206
	/**
207
	 * @generated
208
	 */
209
	protected void addChildVisual(EditPart childEditPart, int index) {
210
		if(addFixedChild(childEditPart)) {
211
			return;
212
		}
213
		super.addChildVisual(childEditPart, -1);
214
	}
215
216
	/**
217
	 * @generated
218
	 */
219
	protected void removeChildVisual(EditPart childEditPart) {
220
		if(removeFixedChild(childEditPart)) {
221
			return;
222
		}
223
		super.removeChildVisual(childEditPart);
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
230
		if(editPart instanceof IBorderItemEditPart) {
231
			return getBorderedFigure().getBorderItemContainer();
232
		}
233
		return getContentPane();
234
	}
235
236
	/**
237
	 * @generated
238
	 */
239
	protected NodeFigure createNodePlate() {
240
		String prefElementId = "ConstraintProperty";
241
		IPreferenceStore store = SysmlDiagramEditorPlugin.getInstance().getPreferenceStore();
242
		String preferenceConstantWitdh = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferenceConstantHelper.WIDTH);
243
		String preferenceConstantHeight = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferenceConstantHelper.HEIGHT);
244
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(store.getInt(preferenceConstantWitdh), store.getInt(preferenceConstantHeight));
245
246
		return result;
247
	}
248
249
	/**
250
	 * Creates figure for this edit part.
251
	 * 
252
	 * Body of this method does not depend on settings in generation model so you may safely remove
253
	 * <i>generated</i> tag and modify it.
254
	 * 
255
	 * @generated
256
	 */
257
	protected NodeFigure createMainFigure() {
258
		NodeFigure figure = createNodePlate();
259
		figure.setLayoutManager(new StackLayout());
260
		IFigure shape = createNodeShape();
261
		figure.add(shape);
262
		contentPane = setupContentPane(shape);
263
		return figure;
264
	}
265
266
	/**
267
	 * Default implementation treats passed figure as content pane. Respects layout one may have set
268
	 * for generated figure.
269
	 * 
270
	 * @param nodeShape
271
	 *        instance of generated figure class
272
	 * @generated
273
	 */
274
	protected IFigure setupContentPane(IFigure nodeShape) {
275
		if(nodeShape.getLayoutManager() == null) {
276
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
277
			layout.setSpacing(5);
278
			nodeShape.setLayoutManager(layout);
279
		}
280
		return nodeShape; // use nodeShape itself as contentPane
281
	}
282
283
	/**
284
	 * @generated
285
	 */
286
	public IFigure getContentPane() {
287
		if(contentPane != null) {
288
			return contentPane;
289
		}
290
		return super.getContentPane();
291
	}
292
293
	/**
294
	 * @generated
295
	 */
296
	protected void setForegroundColor(Color color) {
297
		if(primaryShape != null) {
298
			primaryShape.setForegroundColor(color);
299
		}
300
	}
301
302
	/**
303
	 * @generated
304
	 */
305
	protected void setLineWidth(int width) {
306
		if(primaryShape instanceof Shape) {
307
			((Shape)primaryShape).setLineWidth(width);
308
		}
309
	}
310
311
	/**
312
	 * @generated
313
	 */
314
	protected void setLineType(int style) {
315
		if(primaryShape instanceof Shape) {
316
			((Shape)primaryShape).setLineStyle(style);
317
		}
318
	}
319
320
	/**
321
	 * @generated
322
	 */
323
	public EditPart getPrimaryChildEditPart() {
324
		return getChildBySemanticHint(SysmlVisualIDRegistry.getType(ConstraintPropertyNameEditPart.VISUAL_ID));
325
	}
326
327
	/**
328
	 * @generated
329
	 */
330
	public class ConstraintPropertyFigureDescriptor extends RoundedRectangle {
331
332
		/**
333
		 * @generated
334
		 */
335
		private CenteredWrappedLabel fConstraintPropertyFigureLabel;
336
337
		/**
338
		 * @generated
339
		 */
340
		private WrappingLabel fConstraintLabel;
341
342
		/**
343
		 * @generated
344
		 */
345
		public ConstraintPropertyFigureDescriptor() {
346
347
			GridLayout layoutThis = new GridLayout();
348
			layoutThis.numColumns = 1;
349
			layoutThis.makeColumnsEqualWidth = true;
350
			this.setLayoutManager(layoutThis);
351
352
			this.setCornerDimensions(new Dimension(getMapMode().DPtoLP(25), getMapMode().DPtoLP(25)));
353
			this.setLineWidth(1);
354
			this.setMinimumSize(new Dimension(getMapMode().DPtoLP(200), getMapMode().DPtoLP(120)));
355
			createContents();
356
		}
357
358
		/**
359
		 * @generated
360
		 */
361
		private void createContents() {
362
363
			fConstraintPropertyFigureLabel = new CenteredWrappedLabel();
364
365
			GridData constraintFConstraintPropertyFigureLabel = new GridData();
366
			constraintFConstraintPropertyFigureLabel.verticalAlignment = GridData.END;
367
			constraintFConstraintPropertyFigureLabel.horizontalAlignment = GridData.CENTER;
368
			constraintFConstraintPropertyFigureLabel.horizontalIndent = 0;
369
			constraintFConstraintPropertyFigureLabel.horizontalSpan = 1;
370
			constraintFConstraintPropertyFigureLabel.verticalSpan = 1;
371
			constraintFConstraintPropertyFigureLabel.grabExcessHorizontalSpace = true;
372
			constraintFConstraintPropertyFigureLabel.grabExcessVerticalSpace = true;
373
			this.add(fConstraintPropertyFigureLabel, constraintFConstraintPropertyFigureLabel);
374
375
			fConstraintLabel = new WrappingLabel();
376
377
			GridData constraintFConstraintLabel = new GridData();
378
			constraintFConstraintLabel.verticalAlignment = GridData.BEGINNING;
379
			constraintFConstraintLabel.horizontalAlignment = GridData.END;
380
			constraintFConstraintLabel.horizontalIndent = 0;
381
			constraintFConstraintLabel.horizontalSpan = 1;
382
			constraintFConstraintLabel.verticalSpan = 1;
383
			constraintFConstraintLabel.grabExcessHorizontalSpace = true;
384
			constraintFConstraintLabel.grabExcessVerticalSpace = true;
385
			this.add(fConstraintLabel, constraintFConstraintLabel);
386
387
		}
388
389
		/**
390
		 * @generated
391
		 */
392
		private boolean myUseLocalCoordinates = false;
393
394
		/**
395
		 * @generated
396
		 */
397
		protected boolean useLocalCoordinates() {
398
			return myUseLocalCoordinates;
399
		}
400
401
		/**
402
		 * @generated
403
		 */
404
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
405
			myUseLocalCoordinates = useLocalCoordinates;
406
		}
407
408
		/**
409
		 * @generated
410
		 */
411
		public CenteredWrappedLabel getConstraintPropertyFigureLabel() {
412
			return fConstraintPropertyFigureLabel;
413
		}
414
415
		/**
416
		 * @generated
417
		 */
418
		public WrappingLabel getConstraintLabel() {
419
			return fConstraintLabel;
420
		}
421
422
	}
423
424
	/**
425
	 * @generated
426
	 */
427
	@Override
428
	public Object getPreferredValue(EStructuralFeature feature) {
429
		IPreferenceStore preferenceStore = (IPreferenceStore)getDiagramPreferencesHint().getPreferenceStore();
430
		Object result = null;
431
432
		if(feature == NotationPackage.eINSTANCE.getLineStyle_LineColor() || feature == NotationPackage.eINSTANCE.getFontStyle_FontColor() || feature == NotationPackage.eINSTANCE.getFillStyle_FillColor()) {
433
			String prefColor = null;
434
			if(feature == NotationPackage.eINSTANCE.getLineStyle_LineColor()) {
435
				prefColor = PreferenceConstantHelper.getElementConstant("ConstraintProperty", PreferenceConstantHelper.COLOR_LINE);
436
			} else if(feature == NotationPackage.eINSTANCE.getFontStyle_FontColor()) {
437
				prefColor = PreferenceConstantHelper.getElementConstant("ConstraintProperty", PreferenceConstantHelper.COLOR_FONT);
438
			} else if(feature == NotationPackage.eINSTANCE.getFillStyle_FillColor()) {
439
				prefColor = PreferenceConstantHelper.getElementConstant("ConstraintProperty", PreferenceConstantHelper.COLOR_FILL);
440
			}
441
			result = FigureUtilities.RGBToInteger(PreferenceConverter.getColor((IPreferenceStore)preferenceStore, prefColor));
442
		} else if(feature == NotationPackage.eINSTANCE.getFillStyle_Transparency() || feature == NotationPackage.eINSTANCE.getFillStyle_Gradient()) {
443
			String prefGradient = PreferenceConstantHelper.getElementConstant("ConstraintProperty", PreferenceConstantHelper.COLOR_GRADIENT);
444
			GradientPreferenceConverter gradientPreferenceConverter = new GradientPreferenceConverter(preferenceStore.getString(prefGradient));
445
			if(feature == NotationPackage.eINSTANCE.getFillStyle_Transparency()) {
446
				result = new Integer(gradientPreferenceConverter.getTransparency());
447
			} else if(feature == NotationPackage.eINSTANCE.getFillStyle_Gradient()) {
448
				result = gradientPreferenceConverter.getGradientData();
449
			}
450
		}
451
452
		if(result == null) {
453
			result = getStructuralFeatureValue(feature);
454
		}
455
		return result;
456
	}
457
458
	/**
459
	 * Activate a listener for to Handle notification for new owned property
460
	 */
461
	@Override
462
	public void activate() {
463
		super.activate();
464
		EObject parent = resolveSemanticElement();
465
		// listen constraint property and self base property
466
		notifier.listenObject(parent);
467
		if(parent instanceof ConstraintProperty) {
468
			Property property = ((ConstraintProperty)parent).getBase_Property();
469
			notifier.listenObject(property);
470
			if(property.getType() != null) {
471
				notifier.listenObject(property.getType());
472
			}
473
		}
474
		// ensure children parts are correctly initialized.
475
		SelfCompartmentNotificationHelper.updatePropertiesParts(this, UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute(), (IHintedType)SysmlElementTypes.Property_3002);
476
	}
477
478
	/**
479
	 * Deactivate listeners to handle notification in the message occurence specification
480
	 */
481
	@Override
482
	public void deactivate() {
483
		notifier.unlistenAll();
484
		super.deactivate();
485
	}
486
487
	/**
488
	 * Remove listeners to handle notification in the message occurence specification
489
	 */
490
	@Override
491
	public void removeNotify() {
492
		notifier.unlistenAll();
493
		super.removeNotify();
494
	}
495
496
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/ConstraintPropertyNameEditPart.java (-792 lines)
Lines 1-792 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import java.util.Collections;
17
import java.util.List;
18
19
import org.eclipse.draw2d.IFigure;
20
import org.eclipse.draw2d.Label;
21
import org.eclipse.draw2d.geometry.Point;
22
import org.eclipse.emf.common.notify.Notification;
23
import org.eclipse.emf.ecore.EAnnotation;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.transaction.RecordingCommand;
26
import org.eclipse.emf.transaction.RunnableWithResult;
27
import org.eclipse.emf.transaction.TransactionalEditingDomain;
28
import org.eclipse.gef.AccessibleEditPart;
29
import org.eclipse.gef.EditPolicy;
30
import org.eclipse.gef.Request;
31
import org.eclipse.gef.requests.DirectEditRequest;
32
import org.eclipse.gef.tools.DirectEditManager;
33
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
34
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
35
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
36
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
37
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
38
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
39
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
40
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
41
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
42
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
43
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
44
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
45
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
46
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
47
import org.eclipse.gmf.runtime.notation.FontStyle;
48
import org.eclipse.gmf.runtime.notation.NotationPackage;
49
import org.eclipse.gmf.runtime.notation.View;
50
import org.eclipse.jface.dialogs.Dialog;
51
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
52
import org.eclipse.jface.viewers.ICellEditorValidator;
53
import org.eclipse.jface.window.Window;
54
import org.eclipse.papyrus.extensionpoints.editors.Activator;
55
import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration;
56
import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
57
import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
58
import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
59
import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
60
import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper;
61
import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
62
import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
63
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
64
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.SysmlTextSelectionEditPolicy;
65
import org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel;
66
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
67
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
68
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlParserProvider;
69
import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager;
70
import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition;
71
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
72
import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
73
import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
74
import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants;
75
import org.eclipse.papyrus.infra.emf.appearance.helper.NameLabelIconHelper;
76
import org.eclipse.swt.SWT;
77
import org.eclipse.swt.accessibility.AccessibleEvent;
78
import org.eclipse.swt.graphics.Color;
79
import org.eclipse.swt.graphics.FontData;
80
import org.eclipse.swt.graphics.Image;
81
import org.eclipse.ui.PlatformUI;
82
83
/**
84
 * @generated
85
 */
86
public class ConstraintPropertyNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
87
88
	/**
89
	 * @generated
90
	 */
91
	public static final int VISUAL_ID = 5001;
92
93
	/**
94
	 * @generated
95
	 */
96
	private DirectEditManager manager;
97
98
	/**
99
	 * @generated
100
	 */
101
	private IParser parser;
102
103
	/**
104
	 * @generated
105
	 */
106
	private List<?> parserElements;
107
108
	/**
109
	 * @generated
110
	 */
111
	private String defaultText;
112
113
	/** direct edition mode (default, undefined, registered editor, etc.) */
114
	protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR;
115
116
	/** configuration from a registered edit dialog */
117
	protected IDirectEditorConfiguration configuration;
118
119
	/**
120
	 * @generated
121
	 */
122
	public ConstraintPropertyNameEditPart(View view) {
123
		super(view);
124
	}
125
126
	/**
127
	 * @generated
128
	 */
129
	protected void createDefaultEditPolicies() {
130
		super.createDefaultEditPolicies();
131
		installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new SysmlTextSelectionEditPolicy());
132
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
133
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ParametricEditPart.NodeLabelDragPolicy());
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected String getLabelTextHelper(IFigure figure) {
140
		if(figure instanceof WrappingLabel) {
141
			return ((WrappingLabel)figure).getText();
142
		} else if(figure instanceof ILabelFigure) {
143
			return ((ILabelFigure)figure).getText();
144
		} else {
145
			return ((Label)figure).getText();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelTextHelper(IFigure figure, String text) {
153
		if(figure instanceof WrappingLabel) {
154
			((WrappingLabel)figure).setText(text);
155
		} else if(figure instanceof ILabelFigure) {
156
			((ILabelFigure)figure).setText(text);
157
		} else {
158
			((Label)figure).setText(text);
159
		}
160
	}
161
162
	/**
163
	 * @generated
164
	 */
165
	protected Image getLabelIconHelper(IFigure figure) {
166
		if(figure instanceof WrappingLabel) {
167
			return ((WrappingLabel)figure).getIcon();
168
		} else if(figure instanceof ILabelFigure) {
169
			return ((ILabelFigure)figure).getIcon();
170
		} else {
171
			return ((Label)figure).getIcon();
172
		}
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	protected void setLabelIconHelper(IFigure figure, Image icon) {
179
		if(figure instanceof WrappingLabel) {
180
			((WrappingLabel)figure).setIcon(icon);
181
		} else if(figure instanceof ILabelFigure) {
182
			((ILabelFigure)figure).setIcon(icon);
183
		} else {
184
			((Label)figure).setIcon(icon);
185
		}
186
	}
187
188
	/**
189
	 * @generated
190
	 */
191
	public void setLabel(CenteredWrappedLabel figure) {
192
		unregisterVisuals();
193
		setFigure(figure);
194
		defaultText = getLabelTextHelper(figure);
195
		registerVisuals();
196
		refreshVisuals();
197
	}
198
199
	/**
200
	 * @generated
201
	 */
202
	protected List getModelChildren() {
203
		return Collections.EMPTY_LIST;
204
	}
205
206
	/**
207
	 * @generated
208
	 */
209
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
210
		return null;
211
	}
212
213
	/**
214
	 * @generated
215
	 */
216
	protected EObject getParserElement() {
217
		return resolveSemanticElement();
218
	}
219
220
	/**
221
	 * @generated NOT
222
	 */
223
	protected Image getLabelIcon() {
224
		EObject parserElement = getParserElement();
225
		if(parserElement == null) {
226
			return null;
227
		}
228
229
		List<View> views = DiagramEditPartsUtil.findViews(parserElement, getViewer());
230
		for(View view : views) {
231
			if(NameLabelIconHelper.showLabelIcon(view)) {
232
				return SysmlElementTypes.getImage(parserElement.eClass());
233
			}
234
		}
235
		return null;
236
237
	}
238
239
	/**
240
	 * @generated
241
	 */
242
	protected String getLabelText() {
243
		String text = null;
244
		EObject parserElement = getParserElement();
245
		if(parserElement != null && getParser() != null) {
246
			text = getParser().getPrintString(new EObjectAdapter(parserElement), getParserOptions().intValue());
247
		}
248
		if(text == null || text.length() == 0) {
249
			text = defaultText;
250
		}
251
		return text;
252
	}
253
254
	/**
255
	 * @generated
256
	 */
257
	public void setLabelText(String text) {
258
		setLabelTextHelper(getFigure(), text);
259
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
260
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
261
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
262
		}
263
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
264
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
265
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
266
		}
267
	}
268
269
	/**
270
	 * @generated
271
	 */
272
	public String getEditText() {
273
		if(getParserElement() == null || getParser() == null) {
274
			return ""; //$NON-NLS-1$
275
		}
276
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
277
	}
278
279
	/**
280
	 * @generated
281
	 */
282
	protected boolean isEditable() {
283
		return getParser() != null;
284
	}
285
286
	/**
287
	 * @generated
288
	 */
289
	public ICellEditorValidator getEditTextValidator() {
290
		return new ICellEditorValidator() {
291
292
			public String isValid(final Object value) {
293
				if(value instanceof String) {
294
					final EObject element = getParserElement();
295
					final IParser parser = getParser();
296
					try {
297
						IParserEditStatus valid = (IParserEditStatus)getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
298
299
							public void run() {
300
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String)value));
301
							}
302
						});
303
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
304
					} catch (InterruptedException ie) {
305
						ie.printStackTrace();
306
					}
307
				}
308
309
				// shouldn't get here
310
				return null;
311
			}
312
		};
313
	}
314
315
	/**
316
	 * @generated
317
	 */
318
	public IContentAssistProcessor getCompletionProcessor() {
319
		if(getParserElement() == null || getParser() == null) {
320
			return null;
321
		}
322
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	public ParserOptions getParserOptions() {
329
		return ParserOptions.NONE;
330
	}
331
332
	/**
333
	 * @generated
334
	 */
335
	public IParser getParser() {
336
		if(parser == null) {
337
			parser = SysmlParserProvider.getParser(SysmlElementTypes.ConstraintProperty_2003, getParserElement(), SysmlVisualIDRegistry.getType(org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyNameEditPart.VISUAL_ID));
338
		}
339
		return parser;
340
	}
341
342
	/**
343
	 * @generated
344
	 */
345
	protected DirectEditManager getManager() {
346
		if(manager == null) {
347
			setManager(new MultilineLabelDirectEditManager(this, MultilineLabelDirectEditManager.getTextCellEditorClass(this), SysmlEditPartFactory.getTextCellEditorLocator(this)));
348
		}
349
		return manager;
350
	}
351
352
	/**
353
	 * @generated
354
	 */
355
	protected void setManager(DirectEditManager manager) {
356
		this.manager = manager;
357
	}
358
359
	/**
360
	 * @generated
361
	 */
362
	protected void performDirectEdit() {
363
		getManager().show();
364
	}
365
366
	/**
367
	 * @generated
368
	 */
369
	protected void performDirectEdit(Point eventLocation) {
370
		if(getManager() instanceof TextDirectEditManager) {
371
			((TextDirectEditManager)getManager()).show(eventLocation.getSWTPoint());
372
		}
373
	}
374
375
	/**
376
	 * @generated
377
	 */
378
	private void performDirectEdit(char initialCharacter) {
379
		if(getManager() instanceof TextDirectEditManager) {
380
			((TextDirectEditManager)getManager()).show(initialCharacter);
381
		} else {
382
			performDirectEdit();
383
		}
384
	}
385
386
	/**
387
	 * @generated
388
	 */
389
	protected void performDirectEditRequest(Request request) {
390
391
		final Request theRequest = request;
392
393
		if(IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
394
			directEditionMode = getDirectEditionType();
395
		}
396
		switch(directEditionMode) {
397
		case IDirectEdition.NO_DIRECT_EDITION:
398
			// no direct edition mode => does nothing
399
			return;
400
		case IDirectEdition.EXTENDED_DIRECT_EDITOR:
401
			updateExtendedEditorConfiguration();
402
			if(configuration == null || configuration.getLanguage() == null) {
403
				performDefaultDirectEditorEdit(theRequest);
404
			} else {
405
				configuration.preEditAction(resolveSemanticElement());
406
				Dialog dialog = null;
407
				if(configuration instanceof IPopupEditorConfiguration) {
408
					IPopupEditorHelper helper = ((IPopupEditorConfiguration)configuration).createPopupEditorHelper(this);
409
					helper.showEditor();
410
					return;
411
				} else if(configuration instanceof IAdvancedEditorConfiguration) {
412
					dialog = ((IAdvancedEditorConfiguration)configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()));
413
				} else if(configuration instanceof IDirectEditorConfiguration) {
414
					dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), ((IDirectEditorConfiguration)configuration).getTextToEdit(resolveSemanticElement()), (IDirectEditorConfiguration)configuration);
415
				} else {
416
					return;
417
				}
418
				final Dialog finalDialog = dialog;
419
420
				if(Window.OK == dialog.open()) {
421
					TransactionalEditingDomain domain = getEditingDomain();
422
					RecordingCommand command = new RecordingCommand(domain, "Edit Label") {
423
424
						@Override
425
						protected void doExecute() {
426
							configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog)finalDialog).getValue());
427
428
						}
429
					};
430
					domain.getCommandStack().execute(command);
431
				}
432
			}
433
			break;
434
		case IDirectEdition.DEFAULT_DIRECT_EDITOR:
435
436
			// initialize the direct edit manager
437
			try {
438
				getEditingDomain().runExclusive(new Runnable() {
439
440
					public void run() {
441
						if(isActive() && isEditable()) {
442
							if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
443
								Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
444
								performDirectEdit(initialChar.charValue());
445
							} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
446
								DirectEditRequest editRequest = (DirectEditRequest)theRequest;
447
								performDirectEdit(editRequest.getLocation());
448
							} else {
449
								performDirectEdit();
450
							}
451
						}
452
					}
453
				});
454
			} catch (InterruptedException e) {
455
				e.printStackTrace();
456
			}
457
			break;
458
		default:
459
			break;
460
		}
461
	}
462
463
	/**
464
	 * @generated
465
	 */
466
	protected void refreshVisuals() {
467
		super.refreshVisuals();
468
		refreshLabel();
469
		refreshFont();
470
		refreshFontColor();
471
		refreshUnderline();
472
		refreshStrikeThrough();
473
	}
474
475
	/**
476
	 * @generated
477
	 */
478
	protected void refreshLabel() {
479
		EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
480
		if(maskLabelPolicy == null) {
481
			setLabelTextHelper(getFigure(), getLabelText());
482
			setLabelIconHelper(getFigure(), getLabelIcon());
483
		}
484
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
485
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
486
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
487
		}
488
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
489
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
490
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
491
		}
492
	}
493
494
	/**
495
	 * @generated
496
	 */
497
	protected void refreshUnderline() {
498
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
499
		if(style != null && getFigure() instanceof WrappingLabel) {
500
			((WrappingLabel)getFigure()).setTextUnderline(style.isUnderline());
501
		}
502
	}
503
504
	/**
505
	 * @generated
506
	 */
507
	protected void refreshStrikeThrough() {
508
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
509
		if(style != null && getFigure() instanceof WrappingLabel) {
510
			((WrappingLabel)getFigure()).setTextStrikeThrough(style.isStrikeThrough());
511
		}
512
	}
513
514
	/**
515
	 * @generated
516
	 */
517
	protected void refreshFont() {
518
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
519
		if(style != null) {
520
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
521
			setFont(fontData);
522
		}
523
	}
524
525
	/**
526
	 * @generated
527
	 */
528
	protected void setFontColor(Color color) {
529
		getFigure().setForegroundColor(color);
530
	}
531
532
	/**
533
	 * @generated
534
	 */
535
	protected void addSemanticListeners() {
536
		if(getParser() instanceof ISemanticParser) {
537
			EObject element = resolveSemanticElement();
538
			parserElements = ((ISemanticParser)getParser()).getSemanticElementsBeingParsed(element);
539
			for(int i = 0; i < parserElements.size(); i++) {
540
				addListenerFilter("SemanticModel" + i, this, (EObject)parserElements.get(i)); //$NON-NLS-1$
541
			}
542
		} else {
543
			super.addSemanticListeners();
544
		}
545
	}
546
547
	/**
548
	 * @generated
549
	 */
550
	protected void removeSemanticListeners() {
551
		if(parserElements != null) {
552
			for(int i = 0; i < parserElements.size(); i++) {
553
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
554
			}
555
		} else {
556
			super.removeSemanticListeners();
557
		}
558
	}
559
560
	/**
561
	 * @generated
562
	 */
563
	protected AccessibleEditPart getAccessibleEditPart() {
564
		if(accessibleEP == null) {
565
			accessibleEP = new AccessibleGraphicalEditPart() {
566
567
				public void getName(AccessibleEvent e) {
568
					e.result = getLabelTextHelper(getFigure());
569
				}
570
			};
571
		}
572
		return accessibleEP;
573
	}
574
575
	/**
576
	 * @generated
577
	 */
578
	private View getFontStyleOwnerView() {
579
		return getPrimaryView();
580
	}
581
582
	/**
583
	 * Returns the kind of associated editor for direct edition.
584
	 * 
585
	 * @return an <code>int</code> corresponding to the kind of direct editor, @see
586
	 *         org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition
587
	 * @generated
588
	 */
589
	public int getDirectEditionType() {
590
		if(checkExtendedEditor()) {
591
			initExtendedEditorConfiguration();
592
			return IDirectEdition.EXTENDED_DIRECT_EDITOR;
593
		}
594
		if(checkDefaultEdition()) {
595
			return IDirectEdition.DEFAULT_DIRECT_EDITOR;
596
		}
597
598
		// not a named element. no specific editor => do nothing
599
		return IDirectEdition.NO_DIRECT_EDITION;
600
	}
601
602
	/**
603
	 * Checks if an extended editor is present.
604
	 * 
605
	 * @return <code>true</code> if an extended editor is present.
606
	 * @generated NOT
607
	 */
608
	protected boolean checkExtendedEditor() {
609
		EObject semanticElement = resolveSemanticElement();
610
		if(semanticElement != null && semanticElement instanceof ConstraintProperty) {
611
			boolean hasSpecificEditorConfiguration = DirectEditorsUtil.hasSpecificEditorConfiguration(((ConstraintProperty)semanticElement).getBase_Property().eClass().getInstanceClassName());
612
613
			return hasSpecificEditorConfiguration;
614
		}
615
		return false;
616
	}
617
618
	/**
619
	 * Checks if a default direct edition is available
620
	 * 
621
	 * @return <code>true</code> if a default direct edition is available
622
	 * @generated
623
	 */
624
	protected boolean checkDefaultEdition() {
625
		return (getParser() != null);
626
	}
627
628
	/**
629
	 * Initializes the extended editor configuration
630
	 * 
631
	 * @generated NOT
632
	 */
633
	protected void initExtendedEditorConfiguration() {
634
		if(configuration == null) {
635
			final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
636
			if(languagePreferred != null && !languagePreferred.equals("")) {
637
				configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
638
			} else {
639
				configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.SYSML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName());
640
			}
641
		}
642
	}
643
644
	/**
645
	 * Updates the preference configuration
646
	 */
647
	protected void updateExtendedEditorConfiguration() {
648
		String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
649
		if(languagePreferred != null && !languagePreferred.equals("") && languagePreferred != configuration.getLanguage()) {
650
			configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
651
		} else if(IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) {
652
			configuration = null;
653
		}
654
	}
655
656
	/**
657
	 * Performs the direct edit usually used by GMF editors.
658
	 * 
659
	 * @param theRequest
660
	 *        the direct edit request that starts the direct edit system
661
	 */
662
	protected void performDefaultDirectEditorEdit(final Request theRequest) {
663
		// initialize the direct edit manager
664
		try {
665
			getEditingDomain().runExclusive(new Runnable() {
666
667
				public void run() {
668
					if(isActive() && isEditable()) {
669
						if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
670
							Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
671
							performDirectEdit(initialChar.charValue());
672
						} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
673
							DirectEditRequest editRequest = (DirectEditRequest)theRequest;
674
							performDirectEdit(editRequest.getLocation());
675
						} else {
676
							performDirectEdit();
677
						}
678
					}
679
				}
680
			});
681
		} catch (InterruptedException e) {
682
			e.printStackTrace();
683
		}
684
	}
685
686
	/**
687
	 * @generated
688
	 */
689
	protected void addNotationalListeners() {
690
		super.addNotationalListeners();
691
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
692
	}
693
694
	/**
695
	 * @generated
696
	 */
697
	protected void removeNotationalListeners() {
698
		super.removeNotationalListeners();
699
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
700
	}
701
702
	/**
703
	 * @generated
704
	 */
705
	protected void handleNotificationEvent(Notification event) {
706
		refreshLabel();
707
		Object feature = event.getFeature();
708
		if(NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
709
			Integer c = (Integer)event.getNewValue();
710
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
711
		} else if(NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
712
			refreshUnderline();
713
		} else if(NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
714
			refreshStrikeThrough();
715
		} else if(NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
716
			refreshFont();
717
		} else {
718
			if(getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
719
				refreshLabel();
720
			}
721
			if(getParser() instanceof ISemanticParser) {
722
				ISemanticParser modelParser = (ISemanticParser)getParser();
723
				if(modelParser.areSemanticElementsAffected(null, event)) {
724
					removeSemanticListeners();
725
					if(resolveSemanticElement() != null) {
726
						addSemanticListeners();
727
					}
728
					refreshLabel();
729
				}
730
			}
731
		}
732
733
		if(event.getNewValue() instanceof EAnnotation && VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON.equals(((EAnnotation)event.getNewValue()).getSource())) {
734
			refreshLabel();
735
		}
736
737
		super.handleNotificationEvent(event);
738
	}
739
740
	/**
741
	 * @generated
742
	 */
743
	protected IFigure createFigure() {
744
		// Parent should assign one using setLabel() method
745
		return null;
746
	}
747
748
	private static final String ADD_PARENT_MODEL = "AddParentModel";
749
750
	/**
751
	 * @generated
752
	 */
753
	public void activate() {
754
		super.activate();
755
		addOwnerElementListeners();
756
	}
757
758
	/**
759
	 * @generated
760
	 */
761
	protected void addOwnerElementListeners() {
762
		addListenerFilter(ADD_PARENT_MODEL, this, ((View)getParent().getModel())); //$NON-NLS-1$
763
764
	}
765
766
	/**
767
	 * @generated
768
	 */
769
	public void deactivate() {
770
		removeOwnerElementListeners();
771
		super.deactivate();
772
773
	}
774
775
	/**
776
	 * @generated
777
	 */
778
	protected void removeOwnerElementListeners() {
779
		removeListenerFilter(ADD_PARENT_MODEL);
780
781
	}
782
783
	// @Override
784
	// public EObject resolveSemanticElement() {
785
	// EObject semanticElement = super.resolveSemanticElement();
786
	// if (semanticElement instanceof ConstraintProperty) {
787
	// semanticElement = ((ConstraintProperty) semanticElement).getBase_Property();
788
	// }
789
	// return semanticElement;
790
	// }
791
792
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/ParametricEditPart.java (-147 lines)
Lines 1-147 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import java.util.Collections;
17
import java.util.List;
18
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.ecore.EAnnotation;
21
import org.eclipse.gef.GraphicalEditPart;
22
import org.eclipse.gef.Request;
23
import org.eclipse.gef.commands.Command;
24
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
25
import org.eclipse.gef.handles.MoveHandle;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
28
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableLabelEditPolicy;
29
import org.eclipse.gmf.runtime.notation.View;
30
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.CustomDiagramDragDropEditPolicy;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.ParametricItemSemanticEditPolicy;
32
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
33
import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy;
34
import org.eclipse.papyrus.uml.diagram.common.providers.ViewInfo;
35
import org.eclipse.papyrus.uml.diagram.common.util.MDTUtil;
36
37
/**
38
 * @generated
39
 */
40
public class ParametricEditPart extends DiagramEditPart {
41
42
	/**
43
	 * @generated
44
	 */
45
	public final static String MODEL_ID = "Parametric"; //$NON-NLS-1$
46
47
	/**
48
	 * @generated
49
	 */
50
	public static final int VISUAL_ID = 1000;
51
52
	/**
53
	 * @generated
54
	 */
55
	public ParametricEditPart(View view) {
56
		super(view);
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected void createDefaultEditPolicies() {
63
		super.createDefaultEditPolicies();
64
		installEditPolicy(DuplicatePasteEditPolicy.PASTE_ROLE, new DuplicatePasteEditPolicy());
65
66
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new ParametricItemSemanticEditPolicy());
67
68
		//in Papyrus diagrams are not strongly synchronised
69
		//installEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CANONICAL_ROLE, new org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.ParametricCanonicalEditPolicy());
70
71
		installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDragDropEditPolicy());
72
		// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.POPUPBAR_ROLE);
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	/* package-local */static class NodeLabelDragPolicy extends NonResizableEditPolicy {
79
80
		/**
81
		 * @generated
82
		 */
83
		@SuppressWarnings("rawtypes")
84
		protected List createSelectionHandles() {
85
			MoveHandle h = new MoveHandle((GraphicalEditPart)getHost());
86
			h.setBorder(null);
87
			return Collections.singletonList(h);
88
		}
89
90
		/**
91
		 * @generated
92
		 */
93
		public Command getCommand(Request request) {
94
			return null;
95
		}
96
97
		/**
98
		 * @generated
99
		 */
100
		public boolean understandsRequest(Request request) {
101
			return false;
102
		}
103
	}
104
105
	/**
106
	 * @generated
107
	 */
108
	/* package-local */static class LinkLabelDragPolicy extends NonResizableLabelEditPolicy {
109
110
		/**
111
		 * @generated
112
		 */
113
		@SuppressWarnings("rawtypes")
114
		protected List createSelectionHandles() {
115
			MoveHandle mh = new MoveHandle((GraphicalEditPart)getHost());
116
			mh.setBorder(null);
117
			return Collections.singletonList(mh);
118
		}
119
	}
120
121
	/**
122
	 * @generated
123
	 */
124
	protected void handleNotificationEvent(Notification event) {
125
126
		super.handleNotificationEvent(event);
127
		if(event.getNotifier() instanceof EAnnotation) {
128
			EAnnotation eAnnotation = (EAnnotation)event.getNotifier();
129
			if(eAnnotation.getSource() != null && eAnnotation.getSource().equals(MDTUtil.FilterViewAndLabelsSource)) {
130
				//modification form MOSKitt approach, canonical policies are not called
131
				MDTUtil.filterDiagramViews(this.getDiagramView());
132
			}
133
		}
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	public Object getAdapter(Class adapter) {
140
141
		if(adapter != null && adapter.equals(ViewInfo.class)) {
142
			return SysmlVisualIDRegistry.getDiagramViewInfo();
143
		}
144
		return super.getAdapter(adapter);
145
	}
146
147
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/Property2EditPart.java (-383 lines)
Lines 1-383 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import java.util.ArrayList;
17
import java.util.Collections;
18
import java.util.LinkedList;
19
import java.util.List;
20
21
import org.eclipse.draw2d.IFigure;
22
import org.eclipse.draw2d.PositionConstants;
23
import org.eclipse.draw2d.RectangleFigure;
24
import org.eclipse.draw2d.Shape;
25
import org.eclipse.draw2d.StackLayout;
26
import org.eclipse.draw2d.geometry.Dimension;
27
import org.eclipse.emf.ecore.EStructuralFeature;
28
import org.eclipse.gef.EditPart;
29
import org.eclipse.gef.EditPolicy;
30
import org.eclipse.gef.GraphicalEditPart;
31
import org.eclipse.gef.Request;
32
import org.eclipse.gef.commands.Command;
33
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
34
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
35
import org.eclipse.gef.handles.MoveHandle;
36
import org.eclipse.gef.requests.CreateRequest;
37
import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart;
38
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
39
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
40
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.BorderItemSelectionEditPolicy;
41
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
42
import org.eclipse.gmf.runtime.diagram.ui.figures.BorderItemLocator;
43
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
44
import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
45
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
46
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
47
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
48
import org.eclipse.gmf.runtime.notation.NotationPackage;
49
import org.eclipse.gmf.runtime.notation.View;
50
import org.eclipse.jface.preference.IPreferenceStore;
51
import org.eclipse.jface.preference.PreferenceConverter;
52
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.GradientPreferenceConverter;
53
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
54
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromDiagramEditPolicy;
55
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromModelEditPolicy;
56
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.OpenDiagramEditPolicy;
57
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.Property2ItemSemanticEditPolicy;
58
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
59
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
60
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
61
import org.eclipse.papyrus.uml.diagram.common.helper.PreferenceInitializerForElementHelper;
62
import org.eclipse.swt.graphics.Color;
63
64
/**
65
 * @generated
66
 */
67
public class Property2EditPart extends
68
69
BorderedBorderItemEditPart {
70
71
	/**
72
	 * @generated
73
	 */
74
	public static final int VISUAL_ID = 3002;
75
76
	/**
77
	 * @generated
78
	 */
79
	protected IFigure contentPane;
80
81
	/**
82
	 * @generated
83
	 */
84
	protected IFigure primaryShape;
85
86
	/**
87
	 * @generated
88
	 */
89
	public Property2EditPart(View view) {
90
		super(view);
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void createDefaultEditPolicies() {
97
		super.createDefaultEditPolicies();
98
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, getPrimaryDragEditPolicy());
99
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new Property2ItemSemanticEditPolicy());
100
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
101
		installEditPolicy(EditPolicyRoles.OPEN_ROLE, new OpenDiagramEditPolicy());
102
		installEditPolicy(RequestConstants.REQ_DELETE, new NoDeleteFromDiagramEditPolicy());
103
		installEditPolicy(RequestConstants.REQ_SEMANTIC_WRAPPER, new NoDeleteFromModelEditPolicy());
104
		// XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
105
		// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
106
	}
107
108
	/**
109
	 * @generated
110
	 */
111
	protected LayoutEditPolicy createLayoutEditPolicy() {
112
		org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy lep = new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy() {
113
114
			protected EditPolicy createChildEditPolicy(EditPart child) {
115
				View childView = (View)child.getModel();
116
				switch(SysmlVisualIDRegistry.getVisualID(childView)) {
117
				case PropertyName2EditPart.VISUAL_ID:
118
					return new BorderItemSelectionEditPolicy() {
119
120
						protected List createSelectionHandles() {
121
							MoveHandle mh = new MoveHandle((GraphicalEditPart)getHost());
122
							mh.setBorder(null);
123
							return Collections.singletonList(mh);
124
						}
125
					};
126
				}
127
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
128
				if(result == null) {
129
					result = new NonResizableEditPolicy();
130
				}
131
				return result;
132
			}
133
134
			protected Command getMoveChildrenCommand(Request request) {
135
				return null;
136
			}
137
138
			protected Command getCreateCommand(CreateRequest request) {
139
				return null;
140
			}
141
		};
142
		return lep;
143
	}
144
145
	/**
146
	 * @generated
147
	 */
148
	protected IFigure createNodeShape() {
149
		return primaryShape = new ParameterDescriptor();
150
	}
151
152
	/**
153
	 * @generated
154
	 */
155
	public ParameterDescriptor getPrimaryShape() {
156
		return (ParameterDescriptor)primaryShape;
157
	}
158
159
	/**
160
	 * @generated
161
	 */
162
	protected void addBorderItem(IFigure borderItemContainer, IBorderItemEditPart borderItemEditPart) {
163
		if(borderItemEditPart instanceof PropertyName2EditPart) {
164
			BorderItemLocator locator = new BorderItemLocator(getMainFigure(), PositionConstants.SOUTH);
165
			locator.setBorderItemOffset(new Dimension(-20, -20));
166
			borderItemContainer.add(borderItemEditPart.getFigure(), locator);
167
		} else {
168
			super.addBorderItem(borderItemContainer, borderItemEditPart);
169
		}
170
	}
171
172
	/**
173
	 * @generated
174
	 */
175
	protected NodeFigure createNodePlate() {
176
		String prefElementId = "Property";
177
		IPreferenceStore store = SysmlDiagramEditorPlugin.getInstance().getPreferenceStore();
178
		String preferenceConstantWitdh = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferenceConstantHelper.WIDTH);
179
		String preferenceConstantHeight = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferenceConstantHelper.HEIGHT);
180
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(store.getInt(preferenceConstantWitdh), store.getInt(preferenceConstantHeight));
181
182
		//FIXME: workaround for #154536
183
		result.getBounds().setSize(result.getPreferredSize());
184
		return result;
185
	}
186
187
	/**
188
	 * Creates figure for this edit part.
189
	 * 
190
	 * Body of this method does not depend on settings in generation model so you may safely remove
191
	 * <i>generated</i> tag and modify it.
192
	 * 
193
	 * @generated
194
	 */
195
	protected NodeFigure createMainFigure() {
196
		NodeFigure figure = createNodePlate();
197
		figure.setLayoutManager(new StackLayout());
198
		IFigure shape = createNodeShape();
199
		figure.add(shape);
200
		contentPane = setupContentPane(shape);
201
		return figure;
202
	}
203
204
	/**
205
	 * Default implementation treats passed figure as content pane. Respects layout one may have set
206
	 * for generated figure.
207
	 * 
208
	 * @param nodeShape
209
	 *        instance of generated figure class
210
	 * @generated
211
	 */
212
	protected IFigure setupContentPane(IFigure nodeShape) {
213
		return nodeShape; // use nodeShape itself as contentPane
214
	}
215
216
	/**
217
	 * @generated
218
	 */
219
	public IFigure getContentPane() {
220
		if(contentPane != null) {
221
			return contentPane;
222
		}
223
		return super.getContentPane();
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	protected void setForegroundColor(Color color) {
230
		if(primaryShape != null) {
231
			primaryShape.setForegroundColor(color);
232
		}
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	protected void setLineWidth(int width) {
239
		if(primaryShape instanceof Shape) {
240
			((Shape)primaryShape).setLineWidth(width);
241
		}
242
	}
243
244
	/**
245
	 * @generated
246
	 */
247
	protected void setLineType(int style) {
248
		if(primaryShape instanceof Shape) {
249
			((Shape)primaryShape).setLineStyle(style);
250
		}
251
	}
252
253
	/**
254
	 * @generated
255
	 */
256
	public EditPart getPrimaryChildEditPart() {
257
		return getChildBySemanticHint(SysmlVisualIDRegistry.getType(PropertyName2EditPart.VISUAL_ID));
258
	}
259
260
	/**
261
	 * @generated
262
	 */
263
	public List<IElementType> getMARelTypesOnSource() {
264
		ArrayList<IElementType> types = new ArrayList<IElementType>(1);
265
		types.add(SysmlElementTypes.Connector_4001);
266
		return types;
267
	}
268
269
	/**
270
	 * @generated
271
	 */
272
	public List<IElementType> getMARelTypesOnSourceAndTarget(IGraphicalEditPart targetEditPart) {
273
		LinkedList<IElementType> types = new LinkedList<IElementType>();
274
		if(targetEditPart instanceof PropertyEditPart) {
275
			types.add(SysmlElementTypes.Connector_4001);
276
		}
277
		if(targetEditPart instanceof org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart) {
278
			types.add(SysmlElementTypes.Connector_4001);
279
		}
280
		return types;
281
	}
282
283
	/**
284
	 * @generated
285
	 */
286
	public List<IElementType> getMATypesForTarget(IElementType relationshipType) {
287
		LinkedList<IElementType> types = new LinkedList<IElementType>();
288
		if(relationshipType == SysmlElementTypes.Connector_4001) {
289
			types.add(SysmlElementTypes.Property_2005);
290
			types.add(SysmlElementTypes.Property_3002);
291
		}
292
		return types;
293
	}
294
295
	/**
296
	 * @generated
297
	 */
298
	public List<IElementType> getMARelTypesOnTarget() {
299
		ArrayList<IElementType> types = new ArrayList<IElementType>(1);
300
		types.add(SysmlElementTypes.Connector_4001);
301
		return types;
302
	}
303
304
	/**
305
	 * @generated
306
	 */
307
	public List<IElementType> getMATypesForSource(IElementType relationshipType) {
308
		LinkedList<IElementType> types = new LinkedList<IElementType>();
309
		if(relationshipType == SysmlElementTypes.Connector_4001) {
310
			types.add(SysmlElementTypes.Property_2005);
311
			types.add(SysmlElementTypes.Property_3002);
312
		}
313
		return types;
314
	}
315
316
	/**
317
	 * @generated
318
	 */
319
	public class ParameterDescriptor extends RectangleFigure {
320
321
		/**
322
		 * @generated
323
		 */
324
		public ParameterDescriptor() {
325
			this.setLineWidth(1);
326
			this.setPreferredSize(new Dimension(getMapMode().DPtoLP(16), getMapMode().DPtoLP(16)));
327
		}
328
329
		/**
330
		 * @generated
331
		 */
332
		private boolean myUseLocalCoordinates = false;
333
334
		/**
335
		 * @generated
336
		 */
337
		protected boolean useLocalCoordinates() {
338
			return myUseLocalCoordinates;
339
		}
340
341
		/**
342
		 * @generated
343
		 */
344
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
345
			myUseLocalCoordinates = useLocalCoordinates;
346
		}
347
348
	}
349
350
	/**
351
	 * @generated
352
	 */
353
	@Override
354
	public Object getPreferredValue(EStructuralFeature feature) {
355
		IPreferenceStore preferenceStore = (IPreferenceStore)getDiagramPreferencesHint().getPreferenceStore();
356
		Object result = null;
357
358
		if(feature == NotationPackage.eINSTANCE.getLineStyle_LineColor() || feature == NotationPackage.eINSTANCE.getFontStyle_FontColor() || feature == NotationPackage.eINSTANCE.getFillStyle_FillColor()) {
359
			String prefColor = null;
360
			if(feature == NotationPackage.eINSTANCE.getLineStyle_LineColor()) {
361
				prefColor = PreferenceConstantHelper.getElementConstant("Property", PreferenceConstantHelper.COLOR_LINE);
362
			} else if(feature == NotationPackage.eINSTANCE.getFontStyle_FontColor()) {
363
				prefColor = PreferenceConstantHelper.getElementConstant("Property", PreferenceConstantHelper.COLOR_FONT);
364
			} else if(feature == NotationPackage.eINSTANCE.getFillStyle_FillColor()) {
365
				prefColor = PreferenceConstantHelper.getElementConstant("Property", PreferenceConstantHelper.COLOR_FILL);
366
			}
367
			result = FigureUtilities.RGBToInteger(PreferenceConverter.getColor((IPreferenceStore)preferenceStore, prefColor));
368
		} else if(feature == NotationPackage.eINSTANCE.getFillStyle_Transparency() || feature == NotationPackage.eINSTANCE.getFillStyle_Gradient()) {
369
			String prefGradient = PreferenceConstantHelper.getElementConstant("Property", PreferenceConstantHelper.COLOR_GRADIENT);
370
			GradientPreferenceConverter gradientPreferenceConverter = new GradientPreferenceConverter(preferenceStore.getString(prefGradient));
371
			if(feature == NotationPackage.eINSTANCE.getFillStyle_Transparency()) {
372
				result = new Integer(gradientPreferenceConverter.getTransparency());
373
			} else if(feature == NotationPackage.eINSTANCE.getFillStyle_Gradient()) {
374
				result = gradientPreferenceConverter.getGradientData();
375
			}
376
		}
377
378
		if(result == null) {
379
			result = getStructuralFeatureValue(feature);
380
		}
381
		return result;
382
	}
383
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/PropertyEditPart.java (-427 lines)
Lines 1-427 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import java.util.ArrayList;
17
import java.util.LinkedList;
18
import java.util.List;
19
20
import org.eclipse.draw2d.IFigure;
21
import org.eclipse.draw2d.RectangleFigure;
22
import org.eclipse.draw2d.Shape;
23
import org.eclipse.draw2d.StackLayout;
24
import org.eclipse.draw2d.geometry.Dimension;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.gef.EditPart;
27
import org.eclipse.gef.EditPolicy;
28
import org.eclipse.gef.Request;
29
import org.eclipse.gef.commands.Command;
30
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
31
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
32
import org.eclipse.gef.requests.CreateRequest;
33
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
34
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
35
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
36
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
37
import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
38
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
39
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
40
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
41
import org.eclipse.gmf.runtime.notation.NotationPackage;
42
import org.eclipse.gmf.runtime.notation.View;
43
import org.eclipse.jface.preference.IPreferenceStore;
44
import org.eclipse.jface.preference.PreferenceConverter;
45
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.GradientPreferenceConverter;
46
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
47
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.PropertyItemSemanticEditPolicy;
48
import org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel;
49
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
50
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
51
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
52
import org.eclipse.papyrus.uml.diagram.common.draw2d.CenterLayout;
53
import org.eclipse.papyrus.uml.diagram.common.helper.PreferenceInitializerForElementHelper;
54
import org.eclipse.swt.graphics.Color;
55
56
/**
57
 * @generated
58
 */
59
public class PropertyEditPart extends
60
61
ShapeNodeEditPart {
62
63
	/**
64
	 * @generated
65
	 */
66
	public static final int VISUAL_ID = 2005;
67
68
	/**
69
	 * @generated
70
	 */
71
	protected IFigure contentPane;
72
73
	/**
74
	 * @generated
75
	 */
76
	protected IFigure primaryShape;
77
78
	/**
79
	 * @generated
80
	 */
81
	public PropertyEditPart(View view) {
82
		super(view);
83
	}
84
85
	/**
86
	 * @generated
87
	 */
88
	protected void createDefaultEditPolicies() {
89
		super.createDefaultEditPolicies();
90
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new PropertyItemSemanticEditPolicy());
91
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
92
		// XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
93
		// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
94
	}
95
96
	/**
97
	 * @generated
98
	 */
99
	protected LayoutEditPolicy createLayoutEditPolicy() {
100
		org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy lep = new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy() {
101
102
			protected EditPolicy createChildEditPolicy(EditPart child) {
103
				EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
104
				if(result == null) {
105
					result = new NonResizableEditPolicy();
106
				}
107
				return result;
108
			}
109
110
			protected Command getMoveChildrenCommand(Request request) {
111
				return null;
112
			}
113
114
			protected Command getCreateCommand(CreateRequest request) {
115
				return null;
116
			}
117
		};
118
		return lep;
119
	}
120
121
	/**
122
	 * @generated
123
	 */
124
	protected IFigure createNodeShape() {
125
		return primaryShape = new PropertyFigure();
126
	}
127
128
	/**
129
	 * @generated
130
	 */
131
	public PropertyFigure getPrimaryShape() {
132
		return (PropertyFigure)primaryShape;
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected boolean addFixedChild(EditPart childEditPart) {
139
		if(childEditPart instanceof PropertyNameEditPart) {
140
			((PropertyNameEditPart)childEditPart).setLabel(getPrimaryShape().getPropertyFigureLabel());
141
			return true;
142
		}
143
144
		return false;
145
	}
146
147
	/**
148
	 * @generated
149
	 */
150
	protected boolean removeFixedChild(EditPart childEditPart) {
151
		if(childEditPart instanceof PropertyNameEditPart) {
152
			return true;
153
		}
154
		return false;
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	protected void addChildVisual(EditPart childEditPart, int index) {
161
		if(addFixedChild(childEditPart)) {
162
			return;
163
		}
164
		super.addChildVisual(childEditPart, -1);
165
	}
166
167
	/**
168
	 * @generated
169
	 */
170
	protected void removeChildVisual(EditPart childEditPart) {
171
		if(removeFixedChild(childEditPart)) {
172
			return;
173
		}
174
		super.removeChildVisual(childEditPart);
175
	}
176
177
	/**
178
	 * @generated
179
	 */
180
	protected IFigure getContentPaneFor(IGraphicalEditPart editPart) {
181
		return getContentPane();
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	protected NodeFigure createNodePlate() {
188
		String prefElementId = "Property";
189
		IPreferenceStore store = SysmlDiagramEditorPlugin.getInstance().getPreferenceStore();
190
		String preferenceConstantWitdh = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferenceConstantHelper.WIDTH);
191
		String preferenceConstantHeight = PreferenceInitializerForElementHelper.getpreferenceKey(getNotationView(), prefElementId, PreferenceConstantHelper.HEIGHT);
192
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(store.getInt(preferenceConstantWitdh), store.getInt(preferenceConstantHeight));
193
194
		return result;
195
	}
196
197
	/**
198
	 * Creates figure for this edit part.
199
	 * 
200
	 * Body of this method does not depend on settings in generation model so you may safely remove
201
	 * <i>generated</i> tag and modify it.
202
	 * 
203
	 * @generated
204
	 */
205
	protected NodeFigure createNodeFigure() {
206
		NodeFigure figure = createNodePlate();
207
		figure.setLayoutManager(new StackLayout());
208
		IFigure shape = createNodeShape();
209
		figure.add(shape);
210
		contentPane = setupContentPane(shape);
211
		return figure;
212
	}
213
214
	/**
215
	 * Default implementation treats passed figure as content pane. Respects layout one may have set
216
	 * for generated figure.
217
	 * 
218
	 * @param nodeShape
219
	 *        instance of generated figure class
220
	 * @generated
221
	 */
222
	protected IFigure setupContentPane(IFigure nodeShape) {
223
		if(nodeShape.getLayoutManager() == null) {
224
			ConstrainedToolbarLayout layout = new ConstrainedToolbarLayout();
225
			layout.setSpacing(5);
226
			nodeShape.setLayoutManager(layout);
227
		}
228
		return nodeShape; // use nodeShape itself as contentPane
229
	}
230
231
	/**
232
	 * @generated
233
	 */
234
	public IFigure getContentPane() {
235
		if(contentPane != null) {
236
			return contentPane;
237
		}
238
		return super.getContentPane();
239
	}
240
241
	/**
242
	 * @generated
243
	 */
244
	protected void setForegroundColor(Color color) {
245
		if(primaryShape != null) {
246
			primaryShape.setForegroundColor(color);
247
		}
248
	}
249
250
	/**
251
	 * @generated
252
	 */
253
	protected void setLineWidth(int width) {
254
		if(primaryShape instanceof Shape) {
255
			((Shape)primaryShape).setLineWidth(width);
256
		}
257
	}
258
259
	/**
260
	 * @generated
261
	 */
262
	protected void setLineType(int style) {
263
		if(primaryShape instanceof Shape) {
264
			((Shape)primaryShape).setLineStyle(style);
265
		}
266
	}
267
268
	/**
269
	 * @generated
270
	 */
271
	public EditPart getPrimaryChildEditPart() {
272
		return getChildBySemanticHint(SysmlVisualIDRegistry.getType(PropertyNameEditPart.VISUAL_ID));
273
	}
274
275
	/**
276
	 * @generated
277
	 */
278
	public List<IElementType> getMARelTypesOnSource() {
279
		ArrayList<IElementType> types = new ArrayList<IElementType>(1);
280
		types.add(SysmlElementTypes.Connector_4001);
281
		return types;
282
	}
283
284
	/**
285
	 * @generated
286
	 */
287
	public List<IElementType> getMARelTypesOnSourceAndTarget(IGraphicalEditPart targetEditPart) {
288
		LinkedList<IElementType> types = new LinkedList<IElementType>();
289
		if(targetEditPart instanceof org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart) {
290
			types.add(SysmlElementTypes.Connector_4001);
291
		}
292
		if(targetEditPart instanceof Property2EditPart) {
293
			types.add(SysmlElementTypes.Connector_4001);
294
		}
295
		return types;
296
	}
297
298
	/**
299
	 * @generated
300
	 */
301
	public List<IElementType> getMATypesForTarget(IElementType relationshipType) {
302
		LinkedList<IElementType> types = new LinkedList<IElementType>();
303
		if(relationshipType == SysmlElementTypes.Connector_4001) {
304
			types.add(SysmlElementTypes.Property_2005);
305
			types.add(SysmlElementTypes.Property_3002);
306
		}
307
		return types;
308
	}
309
310
	/**
311
	 * @generated
312
	 */
313
	public List<IElementType> getMARelTypesOnTarget() {
314
		ArrayList<IElementType> types = new ArrayList<IElementType>(1);
315
		types.add(SysmlElementTypes.Connector_4001);
316
		return types;
317
	}
318
319
	/**
320
	 * @generated
321
	 */
322
	public List<IElementType> getMATypesForSource(IElementType relationshipType) {
323
		LinkedList<IElementType> types = new LinkedList<IElementType>();
324
		if(relationshipType == SysmlElementTypes.Connector_4001) {
325
			types.add(SysmlElementTypes.Property_2005);
326
			types.add(SysmlElementTypes.Property_3002);
327
		}
328
		return types;
329
	}
330
331
	/**
332
	 * @generated
333
	 */
334
	public class PropertyFigure extends RectangleFigure {
335
336
		/**
337
		 * @generated
338
		 */
339
		private CenteredWrappedLabel fPropertyFigureLabel;
340
341
		/**
342
		 * @generated
343
		 */
344
		public PropertyFigure() {
345
346
			CenterLayout layoutThis = new CenterLayout();
347
348
			this.setLayoutManager(layoutThis);
349
350
			this.setLineWidth(1);
351
			this.setMinimumSize(new Dimension(getMapMode().DPtoLP(100), getMapMode().DPtoLP(40)));
352
			createContents();
353
		}
354
355
		/**
356
		 * @generated
357
		 */
358
		private void createContents() {
359
360
			fPropertyFigureLabel = new CenteredWrappedLabel();
361
362
			this.add(fPropertyFigureLabel);
363
364
		}
365
366
		/**
367
		 * @generated
368
		 */
369
		private boolean myUseLocalCoordinates = false;
370
371
		/**
372
		 * @generated
373
		 */
374
		protected boolean useLocalCoordinates() {
375
			return myUseLocalCoordinates;
376
		}
377
378
		/**
379
		 * @generated
380
		 */
381
		protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
382
			myUseLocalCoordinates = useLocalCoordinates;
383
		}
384
385
		/**
386
		 * @generated
387
		 */
388
		public CenteredWrappedLabel getPropertyFigureLabel() {
389
			return fPropertyFigureLabel;
390
		}
391
392
	}
393
394
	/**
395
	 * @generated
396
	 */
397
	@Override
398
	public Object getPreferredValue(EStructuralFeature feature) {
399
		IPreferenceStore preferenceStore = (IPreferenceStore)getDiagramPreferencesHint().getPreferenceStore();
400
		Object result = null;
401
402
		if(feature == NotationPackage.eINSTANCE.getLineStyle_LineColor() || feature == NotationPackage.eINSTANCE.getFontStyle_FontColor() || feature == NotationPackage.eINSTANCE.getFillStyle_FillColor()) {
403
			String prefColor = null;
404
			if(feature == NotationPackage.eINSTANCE.getLineStyle_LineColor()) {
405
				prefColor = PreferenceConstantHelper.getElementConstant("Property", PreferenceConstantHelper.COLOR_LINE);
406
			} else if(feature == NotationPackage.eINSTANCE.getFontStyle_FontColor()) {
407
				prefColor = PreferenceConstantHelper.getElementConstant("Property", PreferenceConstantHelper.COLOR_FONT);
408
			} else if(feature == NotationPackage.eINSTANCE.getFillStyle_FillColor()) {
409
				prefColor = PreferenceConstantHelper.getElementConstant("Property", PreferenceConstantHelper.COLOR_FILL);
410
			}
411
			result = FigureUtilities.RGBToInteger(PreferenceConverter.getColor((IPreferenceStore)preferenceStore, prefColor));
412
		} else if(feature == NotationPackage.eINSTANCE.getFillStyle_Transparency() || feature == NotationPackage.eINSTANCE.getFillStyle_Gradient()) {
413
			String prefGradient = PreferenceConstantHelper.getElementConstant("Property", PreferenceConstantHelper.COLOR_GRADIENT);
414
			GradientPreferenceConverter gradientPreferenceConverter = new GradientPreferenceConverter(preferenceStore.getString(prefGradient));
415
			if(feature == NotationPackage.eINSTANCE.getFillStyle_Transparency()) {
416
				result = new Integer(gradientPreferenceConverter.getTransparency());
417
			} else if(feature == NotationPackage.eINSTANCE.getFillStyle_Gradient()) {
418
				result = gradientPreferenceConverter.getGradientData();
419
			}
420
		}
421
422
		if(result == null) {
423
			result = getStructuralFeatureValue(feature);
424
		}
425
		return result;
426
	}
427
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/PropertyName2EditPart.java (-754 lines)
Lines 1-754 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import java.util.Collections;
17
import java.util.List;
18
19
import org.eclipse.draw2d.IFigure;
20
import org.eclipse.draw2d.Label;
21
import org.eclipse.draw2d.geometry.Point;
22
import org.eclipse.draw2d.geometry.Rectangle;
23
import org.eclipse.emf.common.notify.Notification;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.transaction.RecordingCommand;
26
import org.eclipse.emf.transaction.RunnableWithResult;
27
import org.eclipse.emf.transaction.TransactionalEditingDomain;
28
import org.eclipse.gef.AccessibleEditPart;
29
import org.eclipse.gef.EditPolicy;
30
import org.eclipse.gef.Request;
31
import org.eclipse.gef.requests.DirectEditRequest;
32
import org.eclipse.gef.tools.DirectEditManager;
33
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
34
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
35
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
36
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
37
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
38
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
39
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
40
import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
41
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
42
import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
43
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
44
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
45
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
46
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
47
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
48
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
49
import org.eclipse.gmf.runtime.notation.FontStyle;
50
import org.eclipse.gmf.runtime.notation.NotationPackage;
51
import org.eclipse.gmf.runtime.notation.View;
52
import org.eclipse.jface.dialogs.Dialog;
53
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
54
import org.eclipse.jface.viewers.ICellEditorValidator;
55
import org.eclipse.jface.window.Window;
56
import org.eclipse.papyrus.extensionpoints.editors.Activator;
57
import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration;
58
import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
59
import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
60
import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
61
import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
62
import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper;
63
import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
64
import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
65
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromDiagramEditPolicy;
66
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.NoDeleteFromModelEditPolicy;
67
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.SysmlTextSelectionEditPolicy;
68
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
69
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
70
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlParserProvider;
71
import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager;
72
import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition;
73
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
74
import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
75
import org.eclipse.swt.SWT;
76
import org.eclipse.swt.accessibility.AccessibleEvent;
77
import org.eclipse.swt.graphics.Color;
78
import org.eclipse.swt.graphics.FontData;
79
import org.eclipse.swt.graphics.Image;
80
import org.eclipse.ui.PlatformUI;
81
82
/**
83
 * @generated
84
 */
85
public class PropertyName2EditPart
86
87
extends LabelEditPart
88
89
implements ITextAwareEditPart, IBorderItemEditPart {
90
91
	/**
92
	 * @generated
93
	 */
94
	public static final int VISUAL_ID = 5003;
95
96
	/**
97
	 * @generated
98
	 */
99
	private DirectEditManager manager;
100
101
	/**
102
	 * @generated
103
	 */
104
	private IParser parser;
105
106
	/**
107
	 * @generated
108
	 */
109
	private List<?> parserElements;
110
111
	/**
112
	 * @generated
113
	 */
114
	private String defaultText;
115
116
	/** direct edition mode (default, undefined, registered editor, etc.) */
117
	// disable direct edition for property of a constraint property
118
	protected int directEditionMode = IDirectEdition.NO_DIRECT_EDITION;
119
120
	/** configuration from a registered edit dialog */
121
	protected IDirectEditorConfiguration configuration;
122
123
	/**
124
	 * @generated
125
	 */
126
	static {
127
		registerSnapBackPosition(SysmlVisualIDRegistry.getType(org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyName2EditPart.VISUAL_ID), new Point(0, 0));
128
	}
129
130
	/**
131
	 * @generated
132
	 */
133
	public PropertyName2EditPart(View view) {
134
		super(view);
135
	}
136
137
	/**
138
	 * @generated
139
	 */
140
	protected void createDefaultEditPolicies() {
141
		super.createDefaultEditPolicies();
142
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
143
		installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new SysmlTextSelectionEditPolicy());
144
		installEditPolicy(RequestConstants.REQ_DELETE, new NoDeleteFromDiagramEditPolicy());
145
		installEditPolicy(RequestConstants.REQ_SEMANTIC_WRAPPER, new NoDeleteFromModelEditPolicy());
146
	}
147
148
	/**
149
	 * @generated
150
	 */
151
	public IBorderItemLocator getBorderItemLocator() {
152
		IFigure parentFigure = getFigure().getParent();
153
		if(parentFigure != null && parentFigure.getLayoutManager() != null) {
154
			Object constraint = parentFigure.getLayoutManager().getConstraint(getFigure());
155
			return (IBorderItemLocator)constraint;
156
		}
157
		return null;
158
	}
159
160
	/**
161
	 * @generated
162
	 */
163
	public void refreshBounds() {
164
		int x = ((Integer)getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue();
165
		int y = ((Integer)getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue();
166
		int width = ((Integer)getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue();
167
		int height = ((Integer)getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue();
168
		getBorderItemLocator().setConstraint(new Rectangle(x, y, width, height));
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected String getLabelTextHelper(IFigure figure) {
175
		if(figure instanceof WrappingLabel) {
176
			return ((WrappingLabel)figure).getText();
177
		} else if(figure instanceof ILabelFigure) {
178
			return ((ILabelFigure)figure).getText();
179
		} else {
180
			return ((Label)figure).getText();
181
		}
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	protected void setLabelTextHelper(IFigure figure, String text) {
188
		if(figure instanceof WrappingLabel) {
189
			((WrappingLabel)figure).setText(text);
190
		} else if(figure instanceof ILabelFigure) {
191
			((ILabelFigure)figure).setText(text);
192
		} else {
193
			((Label)figure).setText(text);
194
		}
195
	}
196
197
	/**
198
	 * @generated
199
	 */
200
	protected Image getLabelIconHelper(IFigure figure) {
201
		if(figure instanceof WrappingLabel) {
202
			return ((WrappingLabel)figure).getIcon();
203
		} else if(figure instanceof ILabelFigure) {
204
			return ((ILabelFigure)figure).getIcon();
205
		} else {
206
			return ((Label)figure).getIcon();
207
		}
208
	}
209
210
	/**
211
	 * @generated
212
	 */
213
	protected void setLabelIconHelper(IFigure figure, Image icon) {
214
		if(figure instanceof WrappingLabel) {
215
			((WrappingLabel)figure).setIcon(icon);
216
		} else if(figure instanceof ILabelFigure) {
217
			((ILabelFigure)figure).setIcon(icon);
218
		} else {
219
			((Label)figure).setIcon(icon);
220
		}
221
	}
222
223
	/**
224
	 * @generated
225
	 */
226
	public void setLabel(IFigure figure) {
227
		unregisterVisuals();
228
		setFigure(figure);
229
		defaultText = getLabelTextHelper(figure);
230
		registerVisuals();
231
		refreshVisuals();
232
	}
233
234
	/**
235
	 * @generated
236
	 */
237
	protected List getModelChildren() {
238
		return Collections.EMPTY_LIST;
239
	}
240
241
	/**
242
	 * @generated
243
	 */
244
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
245
		return null;
246
	}
247
248
	/**
249
	 * @generated
250
	 */
251
	protected EObject getParserElement() {
252
		return resolveSemanticElement();
253
	}
254
255
	/**
256
	 * @generated
257
	 */
258
	protected Image getLabelIcon() {
259
		return null;
260
	}
261
262
	/**
263
	 * @generated
264
	 */
265
	protected String getLabelText() {
266
		String text = null;
267
		EObject parserElement = getParserElement();
268
		if(parserElement != null && getParser() != null) {
269
			text = getParser().getPrintString(new EObjectAdapter(parserElement), getParserOptions().intValue());
270
		}
271
		if(text == null || text.length() == 0) {
272
			text = defaultText;
273
		}
274
		return text;
275
	}
276
277
	/**
278
	 * @generated
279
	 */
280
	public void setLabelText(String text) {
281
		setLabelTextHelper(getFigure(), text);
282
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
283
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
284
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
285
		}
286
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
287
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
288
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
289
		}
290
	}
291
292
	/**
293
	 * @generated
294
	 */
295
	public String getEditText() {
296
		if(getParserElement() == null || getParser() == null) {
297
			return ""; //$NON-NLS-1$
298
		}
299
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
300
	}
301
302
	/**
303
	 * @generated
304
	 */
305
	protected boolean isEditable() {
306
		return getParser() != null;
307
	}
308
309
	/**
310
	 * @generated
311
	 */
312
	public ICellEditorValidator getEditTextValidator() {
313
		return new ICellEditorValidator() {
314
315
			public String isValid(final Object value) {
316
				if(value instanceof String) {
317
					final EObject element = getParserElement();
318
					final IParser parser = getParser();
319
					try {
320
						IParserEditStatus valid = (IParserEditStatus)getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
321
322
							public void run() {
323
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String)value));
324
							}
325
						});
326
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
327
					} catch (InterruptedException ie) {
328
						ie.printStackTrace();
329
					}
330
				}
331
332
				// shouldn't get here
333
				return null;
334
			}
335
		};
336
	}
337
338
	/**
339
	 * @generated
340
	 */
341
	public IContentAssistProcessor getCompletionProcessor() {
342
		if(getParserElement() == null || getParser() == null) {
343
			return null;
344
		}
345
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
346
	}
347
348
	/**
349
	 * @generated
350
	 */
351
	public ParserOptions getParserOptions() {
352
		return ParserOptions.NONE;
353
	}
354
355
	/**
356
	 * @generated
357
	 */
358
	public IParser getParser() {
359
		if(parser == null) {
360
			parser = SysmlParserProvider.getParser(SysmlElementTypes.Property_3002, getParserElement(), SysmlVisualIDRegistry.getType(org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyName2EditPart.VISUAL_ID));
361
		}
362
		return parser;
363
	}
364
365
	/**
366
	 * @generated
367
	 */
368
	protected DirectEditManager getManager() {
369
		if(manager == null) {
370
			setManager(new MultilineLabelDirectEditManager(this, MultilineLabelDirectEditManager.getTextCellEditorClass(this), SysmlEditPartFactory.getTextCellEditorLocator(this)));
371
		}
372
		return manager;
373
	}
374
375
	/**
376
	 * @generated
377
	 */
378
	protected void setManager(DirectEditManager manager) {
379
		this.manager = manager;
380
	}
381
382
	/**
383
	 * @generated
384
	 */
385
	protected void performDirectEdit() {
386
		getManager().show();
387
	}
388
389
	/**
390
	 * @generated
391
	 */
392
	protected void performDirectEdit(Point eventLocation) {
393
		if(getManager() instanceof TextDirectEditManager) {
394
			((TextDirectEditManager)getManager()).show(eventLocation.getSWTPoint());
395
		}
396
	}
397
398
	/**
399
	 * @generated
400
	 */
401
	private void performDirectEdit(char initialCharacter) {
402
		if(getManager() instanceof TextDirectEditManager) {
403
			((TextDirectEditManager)getManager()).show(initialCharacter);
404
		} else {
405
			performDirectEdit();
406
		}
407
	}
408
409
	/**
410
	 * @generated
411
	 */
412
	protected void performDirectEditRequest(Request request) {
413
414
		final Request theRequest = request;
415
416
		if(IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
417
			directEditionMode = getDirectEditionType();
418
		}
419
		switch(directEditionMode) {
420
		case IDirectEdition.NO_DIRECT_EDITION:
421
			// no direct edition mode => does nothing
422
			return;
423
		case IDirectEdition.EXTENDED_DIRECT_EDITOR:
424
			updateExtendedEditorConfiguration();
425
			if(configuration == null || configuration.getLanguage() == null) {
426
				performDefaultDirectEditorEdit(theRequest);
427
			} else {
428
				configuration.preEditAction(resolveSemanticElement());
429
				Dialog dialog = null;
430
				if(configuration instanceof IPopupEditorConfiguration) {
431
					IPopupEditorHelper helper = ((IPopupEditorConfiguration)configuration).createPopupEditorHelper(this);
432
					helper.showEditor();
433
					return;
434
				} else if(configuration instanceof IAdvancedEditorConfiguration) {
435
					dialog = ((IAdvancedEditorConfiguration)configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()));
436
				} else if(configuration instanceof IDirectEditorConfiguration) {
437
					dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), ((IDirectEditorConfiguration)configuration).getTextToEdit(resolveSemanticElement()), (IDirectEditorConfiguration)configuration);
438
				} else {
439
					return;
440
				}
441
				final Dialog finalDialog = dialog;
442
443
				if(Window.OK == dialog.open()) {
444
					TransactionalEditingDomain domain = getEditingDomain();
445
					RecordingCommand command = new RecordingCommand(domain, "Edit Label") {
446
447
						@Override
448
						protected void doExecute() {
449
							configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog)finalDialog).getValue());
450
451
						}
452
					};
453
					domain.getCommandStack().execute(command);
454
				}
455
			}
456
			break;
457
		case IDirectEdition.DEFAULT_DIRECT_EDITOR:
458
459
			// initialize the direct edit manager
460
			try {
461
				getEditingDomain().runExclusive(new Runnable() {
462
463
					public void run() {
464
						if(isActive() && isEditable()) {
465
							if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
466
								Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
467
								performDirectEdit(initialChar.charValue());
468
							} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
469
								DirectEditRequest editRequest = (DirectEditRequest)theRequest;
470
								performDirectEdit(editRequest.getLocation());
471
							} else {
472
								performDirectEdit();
473
							}
474
						}
475
					}
476
				});
477
			} catch (InterruptedException e) {
478
				e.printStackTrace();
479
			}
480
			break;
481
		default:
482
			break;
483
		}
484
	}
485
486
	/**
487
	 * @generated
488
	 */
489
	protected void refreshVisuals() {
490
		super.refreshVisuals();
491
		refreshLabel();
492
		refreshFont();
493
		refreshFontColor();
494
		refreshUnderline();
495
		refreshStrikeThrough();
496
	}
497
498
	/**
499
	 * @generated
500
	 */
501
	protected void refreshLabel() {
502
		EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
503
		if(maskLabelPolicy == null) {
504
			setLabelTextHelper(getFigure(), getLabelText());
505
			setLabelIconHelper(getFigure(), getLabelIcon());
506
		}
507
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
508
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
509
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
510
		}
511
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
512
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
513
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
514
		}
515
	}
516
517
	/**
518
	 * @generated
519
	 */
520
	protected void refreshUnderline() {
521
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
522
		if(style != null && getFigure() instanceof WrappingLabel) {
523
			((WrappingLabel)getFigure()).setTextUnderline(style.isUnderline());
524
		}
525
	}
526
527
	/**
528
	 * @generated
529
	 */
530
	protected void refreshStrikeThrough() {
531
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
532
		if(style != null && getFigure() instanceof WrappingLabel) {
533
			((WrappingLabel)getFigure()).setTextStrikeThrough(style.isStrikeThrough());
534
		}
535
	}
536
537
	/**
538
	 * @generated
539
	 */
540
	protected void refreshFont() {
541
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
542
		if(style != null) {
543
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
544
			setFont(fontData);
545
		}
546
	}
547
548
	/**
549
	 * @generated
550
	 */
551
	protected void setFontColor(Color color) {
552
		getFigure().setForegroundColor(color);
553
	}
554
555
	/**
556
	 * @generated
557
	 */
558
	protected void addSemanticListeners() {
559
		if(getParser() instanceof ISemanticParser) {
560
			EObject element = resolveSemanticElement();
561
			parserElements = ((ISemanticParser)getParser()).getSemanticElementsBeingParsed(element);
562
			for(int i = 0; i < parserElements.size(); i++) {
563
				addListenerFilter("SemanticModel" + i, this, (EObject)parserElements.get(i)); //$NON-NLS-1$
564
			}
565
		} else {
566
			super.addSemanticListeners();
567
		}
568
	}
569
570
	/**
571
	 * @generated
572
	 */
573
	protected void removeSemanticListeners() {
574
		if(parserElements != null) {
575
			for(int i = 0; i < parserElements.size(); i++) {
576
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
577
			}
578
		} else {
579
			super.removeSemanticListeners();
580
		}
581
	}
582
583
	/**
584
	 * @generated
585
	 */
586
	protected AccessibleEditPart getAccessibleEditPart() {
587
		if(accessibleEP == null) {
588
			accessibleEP = new AccessibleGraphicalEditPart() {
589
590
				public void getName(AccessibleEvent e) {
591
					e.result = getLabelTextHelper(getFigure());
592
				}
593
			};
594
		}
595
		return accessibleEP;
596
	}
597
598
	/**
599
	 * @generated
600
	 */
601
	private View getFontStyleOwnerView() {
602
		return getPrimaryView();
603
	}
604
605
	/**
606
	 * Returns the kind of associated editor for direct edition.
607
	 * 
608
	 * @return an <code>int</code> corresponding to the kind of direct editor, @see
609
	 *         org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition
610
	 * @generated
611
	 */
612
	public int getDirectEditionType() {
613
		if(checkExtendedEditor()) {
614
			initExtendedEditorConfiguration();
615
			return IDirectEdition.EXTENDED_DIRECT_EDITOR;
616
		}
617
		if(checkDefaultEdition()) {
618
			return IDirectEdition.DEFAULT_DIRECT_EDITOR;
619
		}
620
621
		// not a named element. no specific editor => do nothing
622
		return IDirectEdition.NO_DIRECT_EDITION;
623
	}
624
625
	/**
626
	 * Checks if an extended editor is present.
627
	 * 
628
	 * @return <code>true</code> if an extended editor is present.
629
	 * @generated
630
	 */
631
	protected boolean checkExtendedEditor() {
632
		if(resolveSemanticElement() != null) {
633
			return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName());
634
		}
635
		return false;
636
	}
637
638
	/**
639
	 * Checks if a default direct edition is available
640
	 * 
641
	 * @return <code>true</code> if a default direct edition is available
642
	 * @generated
643
	 */
644
	protected boolean checkDefaultEdition() {
645
		return (getParser() != null);
646
	}
647
648
	/**
649
	 * Initializes the extended editor configuration
650
	 * 
651
	 * @generated
652
	 */
653
	protected void initExtendedEditorConfiguration() {
654
		if(configuration == null) {
655
			final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
656
			if(languagePreferred != null && !languagePreferred.equals("")) {
657
				configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
658
			} else {
659
				configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName());
660
			}
661
		}
662
	}
663
664
	/**
665
	 * Updates the preference configuration
666
	 */
667
	protected void updateExtendedEditorConfiguration() {
668
		String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
669
		if(languagePreferred != null && !languagePreferred.equals("") && languagePreferred != configuration.getLanguage()) {
670
			configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
671
		} else if(IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) {
672
			configuration = null;
673
		}
674
	}
675
676
	/**
677
	 * Performs the direct edit usually used by GMF editors.
678
	 * 
679
	 * @param theRequest
680
	 *        the direct edit request that starts the direct edit system
681
	 */
682
	protected void performDefaultDirectEditorEdit(final Request theRequest) {
683
		// initialize the direct edit manager
684
		try {
685
			getEditingDomain().runExclusive(new Runnable() {
686
687
				public void run() {
688
					if(isActive() && isEditable()) {
689
						if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
690
							Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
691
							performDirectEdit(initialChar.charValue());
692
						} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
693
							DirectEditRequest editRequest = (DirectEditRequest)theRequest;
694
							performDirectEdit(editRequest.getLocation());
695
						} else {
696
							performDirectEdit();
697
						}
698
					}
699
				}
700
			});
701
		} catch (InterruptedException e) {
702
			e.printStackTrace();
703
		}
704
	}
705
706
	/**
707
	 * @generated
708
	 */
709
	protected void handleNotificationEvent(Notification event) {
710
		Object feature = event.getFeature();
711
		if(NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
712
			Integer c = (Integer)event.getNewValue();
713
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
714
		} else if(NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
715
			refreshUnderline();
716
		} else if(NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
717
			refreshStrikeThrough();
718
		} else if(NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
719
			refreshFont();
720
		} else {
721
			if(getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
722
				refreshLabel();
723
			}
724
			if(getParser() instanceof ISemanticParser) {
725
				ISemanticParser modelParser = (ISemanticParser)getParser();
726
				if(modelParser.areSemanticElementsAffected(null, event)) {
727
					removeSemanticListeners();
728
					if(resolveSemanticElement() != null) {
729
						addSemanticListeners();
730
					}
731
					refreshLabel();
732
				}
733
			}
734
		}
735
		super.handleNotificationEvent(event);
736
	}
737
738
	/**
739
	 * @generated
740
	 */
741
	protected IFigure createFigure() {
742
		IFigure label = createFigurePrim();
743
		defaultText = getLabelTextHelper(label);
744
		return label;
745
	}
746
747
	/**
748
	 * @generated
749
	 */
750
	protected IFigure createFigurePrim() {
751
		return new WrappingLabel();
752
	}
753
754
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/PropertyNameEditPart.java (-800 lines)
Lines 1-800 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import java.util.Collections;
17
import java.util.List;
18
19
import org.eclipse.draw2d.IFigure;
20
import org.eclipse.draw2d.Label;
21
import org.eclipse.draw2d.geometry.Point;
22
import org.eclipse.emf.common.notify.Notification;
23
import org.eclipse.emf.ecore.EAnnotation;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.transaction.RecordingCommand;
26
import org.eclipse.emf.transaction.RunnableWithResult;
27
import org.eclipse.emf.transaction.TransactionalEditingDomain;
28
import org.eclipse.gef.AccessibleEditPart;
29
import org.eclipse.gef.EditPolicy;
30
import org.eclipse.gef.Request;
31
import org.eclipse.gef.requests.DirectEditRequest;
32
import org.eclipse.gef.tools.DirectEditManager;
33
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
34
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
35
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
36
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
37
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
38
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
39
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
40
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.LabelDirectEditPolicy;
41
import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
42
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
43
import org.eclipse.gmf.runtime.diagram.ui.tools.TextDirectEditManager;
44
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
45
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
46
import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser;
47
import org.eclipse.gmf.runtime.notation.FontStyle;
48
import org.eclipse.gmf.runtime.notation.NotationPackage;
49
import org.eclipse.gmf.runtime.notation.View;
50
import org.eclipse.jface.dialogs.Dialog;
51
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
52
import org.eclipse.jface.viewers.ICellEditorValidator;
53
import org.eclipse.jface.window.Window;
54
import org.eclipse.papyrus.extensionpoints.editors.Activator;
55
import org.eclipse.papyrus.extensionpoints.editors.configuration.IAdvancedEditorConfiguration;
56
import org.eclipse.papyrus.extensionpoints.editors.configuration.IDirectEditorConfiguration;
57
import org.eclipse.papyrus.extensionpoints.editors.configuration.IPopupEditorConfiguration;
58
import org.eclipse.papyrus.extensionpoints.editors.ui.ExtendedDirectEditionDialog;
59
import org.eclipse.papyrus.extensionpoints.editors.ui.ILabelEditorDialog;
60
import org.eclipse.papyrus.extensionpoints.editors.ui.IPopupEditorHelper;
61
import org.eclipse.papyrus.extensionpoints.editors.utils.DirectEditorsUtil;
62
import org.eclipse.papyrus.extensionpoints.editors.utils.IDirectEditorsIds;
63
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.SysmlTextSelectionEditPolicy;
64
import org.eclipse.papyrus.sysml.diagram.parametric.figures.CenteredWrappedLabel;
65
import org.eclipse.papyrus.sysml.diagram.parametric.parsers.PropertyLabelParser;
66
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
67
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
68
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlParserProvider;
69
import org.eclipse.papyrus.uml.diagram.common.directedit.MultilineLabelDirectEditManager;
70
import org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition;
71
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
72
import org.eclipse.papyrus.uml.diagram.common.figure.node.ILabelFigure;
73
import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
74
import org.eclipse.papyrus.infra.emf.appearance.helper.VisualInformationPapyrusConstants;
75
import org.eclipse.papyrus.infra.emf.appearance.helper.NameLabelIconHelper;
76
import org.eclipse.swt.SWT;
77
import org.eclipse.swt.accessibility.AccessibleEvent;
78
import org.eclipse.swt.graphics.Color;
79
import org.eclipse.swt.graphics.FontData;
80
import org.eclipse.swt.graphics.Image;
81
import org.eclipse.ui.PlatformUI;
82
83
/**
84
 * @generated
85
 */
86
public class PropertyNameEditPart extends CompartmentEditPart implements ITextAwareEditPart {
87
88
	/**
89
	 * @generated
90
	 */
91
	public static final int VISUAL_ID = 5002;
92
93
	/**
94
	 * @generated
95
	 */
96
	private DirectEditManager manager;
97
98
	/**
99
	 * @generated
100
	 */
101
	private IParser parser;
102
103
	/**
104
	 * @generated
105
	 */
106
	private List<?> parserElements;
107
108
	/**
109
	 * @generated
110
	 */
111
	private String defaultText;
112
113
	/** direct edition mode (default, undefined, registered editor, etc.) */
114
	protected int directEditionMode = IDirectEdition.UNDEFINED_DIRECT_EDITOR;
115
116
	/** configuration from a registered edit dialog */
117
	protected IDirectEditorConfiguration configuration;
118
119
	/**
120
	 * @generated
121
	 */
122
	public PropertyNameEditPart(View view) {
123
		super(view);
124
	}
125
126
	/**
127
	 * @generated
128
	 */
129
	protected void createDefaultEditPolicies() {
130
		super.createDefaultEditPolicies();
131
		installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new SysmlTextSelectionEditPolicy());
132
		installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new LabelDirectEditPolicy());
133
		installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ParametricEditPart.NodeLabelDragPolicy());
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected String getLabelTextHelper(IFigure figure) {
140
		if(figure instanceof WrappingLabel) {
141
			return ((WrappingLabel)figure).getText();
142
		} else if(figure instanceof ILabelFigure) {
143
			return ((ILabelFigure)figure).getText();
144
		} else {
145
			return ((Label)figure).getText();
146
		}
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	protected void setLabelTextHelper(IFigure figure, String text) {
153
		if(figure instanceof WrappingLabel) {
154
			((WrappingLabel)figure).setText(text);
155
		} else if(figure instanceof ILabelFigure) {
156
			((ILabelFigure)figure).setText(text);
157
		} else {
158
			((Label)figure).setText(text);
159
		}
160
	}
161
162
	/**
163
	 * @generated
164
	 */
165
	protected Image getLabelIconHelper(IFigure figure) {
166
		if(figure instanceof WrappingLabel) {
167
			return ((WrappingLabel)figure).getIcon();
168
		} else if(figure instanceof ILabelFigure) {
169
			return ((ILabelFigure)figure).getIcon();
170
		} else {
171
			return ((Label)figure).getIcon();
172
		}
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	protected void setLabelIconHelper(IFigure figure, Image icon) {
179
		if(figure instanceof WrappingLabel) {
180
			((WrappingLabel)figure).setIcon(icon);
181
		} else if(figure instanceof ILabelFigure) {
182
			((ILabelFigure)figure).setIcon(icon);
183
		} else {
184
			((Label)figure).setIcon(icon);
185
		}
186
	}
187
188
	/**
189
	 * @generated
190
	 */
191
	public void setLabel(CenteredWrappedLabel figure) {
192
		unregisterVisuals();
193
		setFigure(figure);
194
		defaultText = getLabelTextHelper(figure);
195
		registerVisuals();
196
		refreshVisuals();
197
	}
198
199
	/**
200
	 * @generated
201
	 */
202
	protected List getModelChildren() {
203
		return Collections.EMPTY_LIST;
204
	}
205
206
	/**
207
	 * @generated
208
	 */
209
	public IGraphicalEditPart getChildBySemanticHint(String semanticHint) {
210
		return null;
211
	}
212
213
	/**
214
	 * @generated
215
	 */
216
	protected EObject getParserElement() {
217
		return resolveSemanticElement();
218
	}
219
220
	/**
221
	 * @generated NOT
222
	 */
223
	protected Image getLabelIcon() {
224
		EObject parserElement = getParserElement();
225
		if(parserElement == null) {
226
			return null;
227
		}
228
229
		List<View> views = DiagramEditPartsUtil.findViews(parserElement, getViewer());
230
		for(View view : views) {
231
			if(NameLabelIconHelper.showLabelIcon(view)) {
232
				return SysmlElementTypes.getImage(parserElement.eClass());
233
			}
234
		}
235
		return null;
236
237
	}
238
239
	//	/**
240
	//	 * @generated
241
	//	 */
242
	//	protected String getLabelText() {
243
	//		String text = null;
244
	//		EObject parserElement = getParserElement();
245
	//		if (parserElement != null && getParser() != null) {
246
	//			text = getParser().getPrintString(new EObjectAdapter(parserElement), getParserOptions().intValue());
247
	//		}
248
	//		if (text == null || text.length() == 0) {
249
	//			text = defaultText;
250
	//		}
251
	//		return text;
252
	//	}
253
254
	/**
255
	 * @generated NOT
256
	 */
257
	protected String getLabelText() {
258
		String text = null;
259
		EObject parserElement = getParserElement();
260
		if(parserElement != null && getParser() != null && getDiagramView() != null) {
261
			EObject element = getDiagramView().getElement();
262
			if(getParser() instanceof PropertyLabelParser) {
263
				// set the container to compute the property name depth
264
				((PropertyLabelParser)getParser()).setBlock(element);
265
			}
266
			text = getParser().getPrintString(new EObjectAdapter(parserElement), getParserOptions().intValue());
267
		}
268
		if(text == null || text.length() == 0) {
269
			text = defaultText;
270
		}
271
		return text;
272
	}
273
274
	/**
275
	 * @generated
276
	 */
277
	public void setLabelText(String text) {
278
		setLabelTextHelper(getFigure(), text);
279
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
280
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
281
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
282
		}
283
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
284
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
285
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
286
		}
287
	}
288
289
	/**
290
	 * @generated
291
	 */
292
	public String getEditText() {
293
		if(getParserElement() == null || getParser() == null) {
294
			return ""; //$NON-NLS-1$
295
		}
296
		return getParser().getEditString(new EObjectAdapter(getParserElement()), getParserOptions().intValue());
297
	}
298
299
	/**
300
	 * @generated
301
	 */
302
	protected boolean isEditable() {
303
		return getParser() != null;
304
	}
305
306
	/**
307
	 * @generated
308
	 */
309
	public ICellEditorValidator getEditTextValidator() {
310
		return new ICellEditorValidator() {
311
312
			public String isValid(final Object value) {
313
				if(value instanceof String) {
314
					final EObject element = getParserElement();
315
					final IParser parser = getParser();
316
					try {
317
						IParserEditStatus valid = (IParserEditStatus)getEditingDomain().runExclusive(new RunnableWithResult.Impl() {
318
319
							public void run() {
320
								setResult(parser.isValidEditString(new EObjectAdapter(element), (String)value));
321
							}
322
						});
323
						return valid.getCode() == ParserEditStatus.EDITABLE ? null : valid.getMessage();
324
					} catch (InterruptedException ie) {
325
						ie.printStackTrace();
326
					}
327
				}
328
329
				// shouldn't get here
330
				return null;
331
			}
332
		};
333
	}
334
335
	/**
336
	 * @generated
337
	 */
338
	public IContentAssistProcessor getCompletionProcessor() {
339
		if(getParserElement() == null || getParser() == null) {
340
			return null;
341
		}
342
		return getParser().getCompletionProcessor(new EObjectAdapter(getParserElement()));
343
	}
344
345
	/**
346
	 * @generated
347
	 */
348
	public ParserOptions getParserOptions() {
349
		return ParserOptions.NONE;
350
	}
351
352
	/**
353
	 * @generated
354
	 */
355
	public IParser getParser() {
356
		if(parser == null) {
357
			parser = SysmlParserProvider.getParser(SysmlElementTypes.Property_2005, getParserElement(), SysmlVisualIDRegistry.getType(org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyNameEditPart.VISUAL_ID));
358
		}
359
		return parser;
360
	}
361
362
	/**
363
	 * @generated
364
	 */
365
	protected DirectEditManager getManager() {
366
		if(manager == null) {
367
			setManager(new MultilineLabelDirectEditManager(this, MultilineLabelDirectEditManager.getTextCellEditorClass(this), SysmlEditPartFactory.getTextCellEditorLocator(this)));
368
		}
369
		return manager;
370
	}
371
372
	/**
373
	 * @generated
374
	 */
375
	protected void setManager(DirectEditManager manager) {
376
		this.manager = manager;
377
	}
378
379
	/**
380
	 * @generated
381
	 */
382
	protected void performDirectEdit() {
383
		getManager().show();
384
	}
385
386
	/**
387
	 * @generated
388
	 */
389
	protected void performDirectEdit(Point eventLocation) {
390
		if(getManager() instanceof TextDirectEditManager) {
391
			((TextDirectEditManager)getManager()).show(eventLocation.getSWTPoint());
392
		}
393
	}
394
395
	/**
396
	 * @generated
397
	 */
398
	private void performDirectEdit(char initialCharacter) {
399
		if(getManager() instanceof TextDirectEditManager) {
400
			((TextDirectEditManager)getManager()).show(initialCharacter);
401
		} else {
402
			performDirectEdit();
403
		}
404
	}
405
406
	/**
407
	 * @generated
408
	 */
409
	protected void performDirectEditRequest(Request request) {
410
411
		final Request theRequest = request;
412
413
		if(IDirectEdition.UNDEFINED_DIRECT_EDITOR == directEditionMode) {
414
			directEditionMode = getDirectEditionType();
415
		}
416
		switch(directEditionMode) {
417
		case IDirectEdition.NO_DIRECT_EDITION:
418
			// no direct edition mode => does nothing
419
			return;
420
		case IDirectEdition.EXTENDED_DIRECT_EDITOR:
421
			updateExtendedEditorConfiguration();
422
			if(configuration == null || configuration.getLanguage() == null) {
423
				performDefaultDirectEditorEdit(theRequest);
424
			} else {
425
				configuration.preEditAction(resolveSemanticElement());
426
				Dialog dialog = null;
427
				if(configuration instanceof IPopupEditorConfiguration) {
428
					IPopupEditorHelper helper = ((IPopupEditorConfiguration)configuration).createPopupEditorHelper(this);
429
					helper.showEditor();
430
					return;
431
				} else if(configuration instanceof IAdvancedEditorConfiguration) {
432
					dialog = ((IAdvancedEditorConfiguration)configuration).createDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), configuration.getTextToEdit(resolveSemanticElement()));
433
				} else if(configuration instanceof IDirectEditorConfiguration) {
434
					dialog = new ExtendedDirectEditionDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), resolveSemanticElement(), ((IDirectEditorConfiguration)configuration).getTextToEdit(resolveSemanticElement()), (IDirectEditorConfiguration)configuration);
435
				} else {
436
					return;
437
				}
438
				final Dialog finalDialog = dialog;
439
440
				if(Window.OK == dialog.open()) {
441
					TransactionalEditingDomain domain = getEditingDomain();
442
					RecordingCommand command = new RecordingCommand(domain, "Edit Label") {
443
444
						@Override
445
						protected void doExecute() {
446
							configuration.postEditAction(resolveSemanticElement(), ((ILabelEditorDialog)finalDialog).getValue());
447
448
						}
449
					};
450
					domain.getCommandStack().execute(command);
451
				}
452
			}
453
			break;
454
		case IDirectEdition.DEFAULT_DIRECT_EDITOR:
455
456
			// initialize the direct edit manager
457
			try {
458
				getEditingDomain().runExclusive(new Runnable() {
459
460
					public void run() {
461
						if(isActive() && isEditable()) {
462
							if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
463
								Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
464
								performDirectEdit(initialChar.charValue());
465
							} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
466
								DirectEditRequest editRequest = (DirectEditRequest)theRequest;
467
								performDirectEdit(editRequest.getLocation());
468
							} else {
469
								performDirectEdit();
470
							}
471
						}
472
					}
473
				});
474
			} catch (InterruptedException e) {
475
				e.printStackTrace();
476
			}
477
			break;
478
		default:
479
			break;
480
		}
481
	}
482
483
	/**
484
	 * @generated
485
	 */
486
	protected void refreshVisuals() {
487
		super.refreshVisuals();
488
		refreshLabel();
489
		refreshFont();
490
		refreshFontColor();
491
		refreshUnderline();
492
		refreshStrikeThrough();
493
	}
494
495
	/**
496
	 * @generated
497
	 */
498
	protected void refreshLabel() {
499
		EditPolicy maskLabelPolicy = getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
500
		if(maskLabelPolicy == null) {
501
			setLabelTextHelper(getFigure(), getLabelText());
502
			setLabelIconHelper(getFigure(), getLabelIcon());
503
		}
504
		Object pdEditPolicy = getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
505
		if(pdEditPolicy instanceof SysmlTextSelectionEditPolicy) {
506
			((SysmlTextSelectionEditPolicy)pdEditPolicy).refreshFeedback();
507
		}
508
		Object sfEditPolicy = getEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE);
509
		if(sfEditPolicy instanceof SysmlTextSelectionEditPolicy) {
510
			((SysmlTextSelectionEditPolicy)sfEditPolicy).refreshFeedback();
511
		}
512
	}
513
514
	/**
515
	 * @generated
516
	 */
517
	protected void refreshUnderline() {
518
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
519
		if(style != null && getFigure() instanceof WrappingLabel) {
520
			((WrappingLabel)getFigure()).setTextUnderline(style.isUnderline());
521
		}
522
	}
523
524
	/**
525
	 * @generated
526
	 */
527
	protected void refreshStrikeThrough() {
528
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
529
		if(style != null && getFigure() instanceof WrappingLabel) {
530
			((WrappingLabel)getFigure()).setTextStrikeThrough(style.isStrikeThrough());
531
		}
532
	}
533
534
	/**
535
	 * @generated
536
	 */
537
	protected void refreshFont() {
538
		FontStyle style = (FontStyle)getFontStyleOwnerView().getStyle(NotationPackage.eINSTANCE.getFontStyle());
539
		if(style != null) {
540
			FontData fontData = new FontData(style.getFontName(), style.getFontHeight(), (style.isBold() ? SWT.BOLD : SWT.NORMAL) | (style.isItalic() ? SWT.ITALIC : SWT.NORMAL));
541
			setFont(fontData);
542
		}
543
	}
544
545
	/**
546
	 * @generated
547
	 */
548
	protected void setFontColor(Color color) {
549
		getFigure().setForegroundColor(color);
550
	}
551
552
	/**
553
	 * @generated
554
	 */
555
	protected void addSemanticListeners() {
556
		if(getParser() instanceof ISemanticParser) {
557
			EObject element = resolveSemanticElement();
558
			parserElements = ((ISemanticParser)getParser()).getSemanticElementsBeingParsed(element);
559
			for(int i = 0; i < parserElements.size(); i++) {
560
				addListenerFilter("SemanticModel" + i, this, (EObject)parserElements.get(i)); //$NON-NLS-1$
561
			}
562
		} else {
563
			super.addSemanticListeners();
564
		}
565
	}
566
567
	/**
568
	 * @generated
569
	 */
570
	protected void removeSemanticListeners() {
571
		if(parserElements != null) {
572
			for(int i = 0; i < parserElements.size(); i++) {
573
				removeListenerFilter("SemanticModel" + i); //$NON-NLS-1$
574
			}
575
		} else {
576
			super.removeSemanticListeners();
577
		}
578
	}
579
580
	/**
581
	 * @generated
582
	 */
583
	protected AccessibleEditPart getAccessibleEditPart() {
584
		if(accessibleEP == null) {
585
			accessibleEP = new AccessibleGraphicalEditPart() {
586
587
				public void getName(AccessibleEvent e) {
588
					e.result = getLabelTextHelper(getFigure());
589
				}
590
			};
591
		}
592
		return accessibleEP;
593
	}
594
595
	/**
596
	 * @generated
597
	 */
598
	private View getFontStyleOwnerView() {
599
		return getPrimaryView();
600
	}
601
602
	/**
603
	 * Returns the kind of associated editor for direct edition.
604
	 * 
605
	 * @return an <code>int</code> corresponding to the kind of direct editor, @see
606
	 *         org.eclipse.papyrus.uml.diagram.common.editpolicies.IDirectEdition
607
	 * @generated
608
	 */
609
	public int getDirectEditionType() {
610
		if(checkExtendedEditor()) {
611
			initExtendedEditorConfiguration();
612
			return IDirectEdition.EXTENDED_DIRECT_EDITOR;
613
		}
614
		if(checkDefaultEdition()) {
615
			return IDirectEdition.DEFAULT_DIRECT_EDITOR;
616
		}
617
618
		// not a named element. no specific editor => do nothing
619
		return IDirectEdition.NO_DIRECT_EDITION;
620
	}
621
622
	/**
623
	 * Checks if an extended editor is present.
624
	 * 
625
	 * @return <code>true</code> if an extended editor is present.
626
	 * @generated
627
	 */
628
	protected boolean checkExtendedEditor() {
629
		if(resolveSemanticElement() != null) {
630
			return DirectEditorsUtil.hasSpecificEditorConfiguration(resolveSemanticElement().eClass().getInstanceClassName());
631
		}
632
		return false;
633
	}
634
635
	/**
636
	 * Checks if a default direct edition is available
637
	 * 
638
	 * @return <code>true</code> if a default direct edition is available
639
	 * @generated
640
	 */
641
	protected boolean checkDefaultEdition() {
642
		return (getParser() != null);
643
	}
644
645
	/**
646
	 * Initializes the extended editor configuration
647
	 * 
648
	 * @generated
649
	 */
650
	protected void initExtendedEditorConfiguration() {
651
		if(configuration == null) {
652
			final String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
653
			if(languagePreferred != null && !languagePreferred.equals("")) {
654
				configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
655
			} else {
656
				configuration = DirectEditorsUtil.findEditorConfiguration(IDirectEditorsIds.UML_LANGUAGE, resolveSemanticElement().eClass().getInstanceClassName());
657
			}
658
		}
659
	}
660
661
	/**
662
	 * Updates the preference configuration
663
	 */
664
	protected void updateExtendedEditorConfiguration() {
665
		String languagePreferred = Activator.getDefault().getPreferenceStore().getString(IDirectEditorsIds.EDITOR_FOR_ELEMENT + resolveSemanticElement().eClass().getInstanceClassName());
666
		if(languagePreferred != null && !languagePreferred.equals("") && languagePreferred != configuration.getLanguage()) {
667
			configuration = DirectEditorsUtil.findEditorConfiguration(languagePreferred, resolveSemanticElement().eClass().getInstanceClassName());
668
		} else if(IDirectEditorsIds.SIMPLE_DIRECT_EDITOR.equals(languagePreferred)) {
669
			configuration = null;
670
		}
671
	}
672
673
	/**
674
	 * Performs the direct edit usually used by GMF editors.
675
	 * 
676
	 * @param theRequest
677
	 *        the direct edit request that starts the direct edit system
678
	 */
679
	protected void performDefaultDirectEditorEdit(final Request theRequest) {
680
		// initialize the direct edit manager
681
		try {
682
			getEditingDomain().runExclusive(new Runnable() {
683
684
				public void run() {
685
					if(isActive() && isEditable()) {
686
						if(theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR) instanceof Character) {
687
							Character initialChar = (Character)theRequest.getExtendedData().get(RequestConstants.REQ_DIRECTEDIT_EXTENDEDDATA_INITIAL_CHAR);
688
							performDirectEdit(initialChar.charValue());
689
						} else if((theRequest instanceof DirectEditRequest) && (getEditText().equals(getLabelText()))) {
690
							DirectEditRequest editRequest = (DirectEditRequest)theRequest;
691
							performDirectEdit(editRequest.getLocation());
692
						} else {
693
							performDirectEdit();
694
						}
695
					}
696
				}
697
			});
698
		} catch (InterruptedException e) {
699
			e.printStackTrace();
700
		}
701
	}
702
703
	/**
704
	 * @generated
705
	 */
706
	protected void addNotationalListeners() {
707
		super.addNotationalListeners();
708
		addListenerFilter("PrimaryView", this, getPrimaryView()); //$NON-NLS-1$
709
	}
710
711
	/**
712
	 * @generated
713
	 */
714
	protected void removeNotationalListeners() {
715
		super.removeNotationalListeners();
716
		removeListenerFilter("PrimaryView"); //$NON-NLS-1$
717
	}
718
719
	/**
720
	 * @generated
721
	 */
722
	protected void handleNotificationEvent(Notification event) {
723
		refreshLabel();
724
		Object feature = event.getFeature();
725
		if(NotationPackage.eINSTANCE.getFontStyle_FontColor().equals(feature)) {
726
			Integer c = (Integer)event.getNewValue();
727
			setFontColor(DiagramColorRegistry.getInstance().getColor(c));
728
		} else if(NotationPackage.eINSTANCE.getFontStyle_Underline().equals(feature)) {
729
			refreshUnderline();
730
		} else if(NotationPackage.eINSTANCE.getFontStyle_StrikeThrough().equals(feature)) {
731
			refreshStrikeThrough();
732
		} else if(NotationPackage.eINSTANCE.getFontStyle_FontHeight().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_FontName().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Bold().equals(feature) || NotationPackage.eINSTANCE.getFontStyle_Italic().equals(feature)) {
733
			refreshFont();
734
		} else {
735
			if(getParser() != null && getParser().isAffectingEvent(event, getParserOptions().intValue())) {
736
				refreshLabel();
737
			}
738
			if(getParser() instanceof ISemanticParser) {
739
				ISemanticParser modelParser = (ISemanticParser)getParser();
740
				if(modelParser.areSemanticElementsAffected(null, event)) {
741
					removeSemanticListeners();
742
					if(resolveSemanticElement() != null) {
743
						addSemanticListeners();
744
					}
745
					refreshLabel();
746
				}
747
			}
748
		}
749
750
		if(event.getNewValue() instanceof EAnnotation && VisualInformationPapyrusConstants.DISPLAY_NAMELABELICON.equals(((EAnnotation)event.getNewValue()).getSource())) {
751
			refreshLabel();
752
		}
753
754
		super.handleNotificationEvent(event);
755
	}
756
757
	/**
758
	 * @generated
759
	 */
760
	protected IFigure createFigure() {
761
		// Parent should assign one using setLabel() method
762
		return null;
763
	}
764
765
	private static final String ADD_PARENT_MODEL = "AddParentModel";
766
767
	/**
768
	 * @generated
769
	 */
770
	public void activate() {
771
		super.activate();
772
		addOwnerElementListeners();
773
	}
774
775
	/**
776
	 * @generated
777
	 */
778
	protected void addOwnerElementListeners() {
779
		addListenerFilter(ADD_PARENT_MODEL, this, ((View)getParent().getModel())); //$NON-NLS-1$
780
781
	}
782
783
	/**
784
	 * @generated
785
	 */
786
	public void deactivate() {
787
		removeOwnerElementListeners();
788
		super.deactivate();
789
790
	}
791
792
	/**
793
	 * @generated
794
	 */
795
	protected void removeOwnerElementListeners() {
796
		removeListenerFilter(ADD_PARENT_MODEL);
797
798
	}
799
800
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/parts/SysmlEditPartFactory.java (-228 lines)
Lines 1-228 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.parts;
15
16
import org.eclipse.draw2d.FigureUtilities;
17
import org.eclipse.draw2d.Label;
18
import org.eclipse.draw2d.geometry.Dimension;
19
import org.eclipse.draw2d.geometry.Rectangle;
20
import org.eclipse.gef.EditPart;
21
import org.eclipse.gef.EditPartFactory;
22
import org.eclipse.gef.tools.CellEditorLocator;
23
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
24
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
25
import org.eclipse.gmf.runtime.notation.View;
26
import org.eclipse.jface.viewers.CellEditor;
27
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
28
import org.eclipse.papyrus.uml.diagram.common.figure.node.IMultilineEditableFigure;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.widgets.Text;
31
32
/**
33
 * @generated
34
 */
35
public class SysmlEditPartFactory implements EditPartFactory {
36
37
	/**
38
	 * @generated
39
	 */
40
	public EditPart createEditPart(EditPart context, Object model) {
41
		if(model instanceof View) {
42
			View view = (View)model;
43
			switch(SysmlVisualIDRegistry.getVisualID(view)) {
44
45
			case ParametricEditPart.VISUAL_ID:
46
				return new ParametricEditPart(view);
47
48
			case ConstraintPropertyEditPart.VISUAL_ID:
49
				return new ConstraintPropertyEditPart(view);
50
51
			case ConstraintPropertyNameEditPart.VISUAL_ID:
52
				return new ConstraintPropertyNameEditPart(view);
53
54
			case ConstraintLabelEditPart.VISUAL_ID:
55
				return new ConstraintLabelEditPart(view);
56
57
			case PropertyEditPart.VISUAL_ID:
58
				return new PropertyEditPart(view);
59
60
			case PropertyNameEditPart.VISUAL_ID:
61
				return new PropertyNameEditPart(view);
62
63
			case Property2EditPart.VISUAL_ID:
64
				return new Property2EditPart(view);
65
66
			case PropertyName2EditPart.VISUAL_ID:
67
				return new PropertyName2EditPart(view);
68
69
			case ConnectorEditPart.VISUAL_ID:
70
				return new ConnectorEditPart(view);
71
72
			case ConnectorNameEditPart.VISUAL_ID:
73
				return new ConnectorNameEditPart(view);
74
75
			}
76
		}
77
		return createUnrecognizedEditPart(context, model);
78
	}
79
80
	/**
81
	 * @generated
82
	 */
83
	private EditPart createUnrecognizedEditPart(EditPart context, Object model) {
84
		// Handle creation of unrecognized child node EditParts here
85
		return null;
86
	}
87
88
	/**
89
	 * @generated
90
	 */
91
	public static CellEditorLocator getTextCellEditorLocator(ITextAwareEditPart source) {
92
		if(source.getFigure() instanceof IMultilineEditableFigure)
93
			return new MultilineCellEditorLocator((IMultilineEditableFigure)source.getFigure());
94
		else if(source.getFigure() instanceof WrappingLabel)
95
			return new TextCellEditorLocator((WrappingLabel)source.getFigure());
96
		else {
97
			return new LabelCellEditorLocator((Label)source.getFigure());
98
		}
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	static private class MultilineCellEditorLocator implements CellEditorLocator {
105
106
		/**
107
		 * @generated
108
		 */
109
		private IMultilineEditableFigure multilineEditableFigure;
110
111
		/**
112
		 * @generated
113
		 */
114
		public MultilineCellEditorLocator(IMultilineEditableFigure figure) {
115
			this.multilineEditableFigure = figure;
116
		}
117
118
		/**
119
		 * @generated
120
		 */
121
		public IMultilineEditableFigure getMultilineEditableFigure() {
122
			return multilineEditableFigure;
123
		}
124
125
		/**
126
		 * @generated
127
		 */
128
		public void relocate(CellEditor celleditor) {
129
			Text text = (Text)celleditor.getControl();
130
			Rectangle rect = getMultilineEditableFigure().getBounds().getCopy();
131
			rect.x = getMultilineEditableFigure().getEditionLocation().x;
132
			rect.y = getMultilineEditableFigure().getEditionLocation().y;
133
			getMultilineEditableFigure().translateToAbsolute(rect);
134
			if(getMultilineEditableFigure().getText().length() > 0) {
135
				rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
136
			}
137
			if(!rect.equals(new Rectangle(text.getBounds()))) {
138
				text.setBounds(rect.x, rect.y, rect.width, rect.height);
139
			}
140
		}
141
	}
142
143
	/**
144
	 * @generated
145
	 */
146
	static private class TextCellEditorLocator implements CellEditorLocator {
147
148
		/**
149
		 * @generated
150
		 */
151
		private WrappingLabel wrapLabel;
152
153
		/**
154
		 * @generated
155
		 */
156
		public TextCellEditorLocator(WrappingLabel wrapLabel) {
157
			this.wrapLabel = wrapLabel;
158
		}
159
160
		/**
161
		 * @generated
162
		 */
163
		public WrappingLabel getWrapLabel() {
164
			return wrapLabel;
165
		}
166
167
		/**
168
		 * @generated
169
		 */
170
		public void relocate(CellEditor celleditor) {
171
			Text text = (Text)celleditor.getControl();
172
			Rectangle rect = getWrapLabel().getTextBounds().getCopy();
173
			getWrapLabel().translateToAbsolute(rect);
174
			if(!text.getFont().isDisposed()) {
175
				if(getWrapLabel().isTextWrapOn() && getWrapLabel().getText().length() > 0) {
176
					rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
177
				} else {
178
					int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
179
					rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
180
				}
181
			}
182
			if(!rect.equals(new Rectangle(text.getBounds()))) {
183
				text.setBounds(rect.x, rect.y, rect.width, rect.height);
184
			}
185
		}
186
	}
187
188
	/**
189
	 * @generated
190
	 */
191
	private static class LabelCellEditorLocator implements CellEditorLocator {
192
193
		/**
194
		 * @generated
195
		 */
196
		private Label label;
197
198
		/**
199
		 * @generated
200
		 */
201
		public LabelCellEditorLocator(Label label) {
202
			this.label = label;
203
		}
204
205
		/**
206
		 * @generated
207
		 */
208
		public Label getLabel() {
209
			return label;
210
		}
211
212
		/**
213
		 * @generated
214
		 */
215
		public void relocate(CellEditor celleditor) {
216
			Text text = (Text)celleditor.getControl();
217
			Rectangle rect = getLabel().getTextBounds().getCopy();
218
			getLabel().translateToAbsolute(rect);
219
			if(!text.getFont().isDisposed()) {
220
				int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
221
				rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
222
			}
223
			if(!rect.equals(new Rectangle(text.getBounds()))) {
224
				text.setBounds(rect.x, rect.y, rect.width, rect.height);
225
			}
226
		}
227
	}
228
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/ConnectorItemSemanticEditPolicy.java (-52 lines)
Lines 1-52 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import java.util.ArrayList;
17
import java.util.List;
18
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.edit.command.DeleteCommand;
21
import org.eclipse.gef.commands.Command;
22
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
23
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
24
import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
25
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
26
27
/**
28
 * @generated
29
 */
30
public class ConnectorItemSemanticEditPolicy extends SysmlBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	public ConnectorItemSemanticEditPolicy() {
36
		super(SysmlElementTypes.Connector_4001);
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
43
		CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
44
		cmd.setTransactionNestingEnabled(true);
45
		List<EObject> todestroy = new ArrayList<EObject>();
46
		todestroy.add(req.getElementToDestroy());
47
		//cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req));
48
		cmd.add(new EMFtoGMFCommandWrapper(new DeleteCommand(getEditingDomain(), todestroy)));
49
		return getGEFWrapper(cmd.reduce());
50
		//return getGEFWrapper(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req));
51
	}
52
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/ConstraintPropertyCanonicalEditPolicy.java (-172 lines)
Lines 1-172 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import java.util.ArrayList;
17
import java.util.Collection;
18
import java.util.Iterator;
19
import java.util.LinkedList;
20
import java.util.List;
21
22
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.EStructuralFeature;
25
import org.eclipse.gef.EditPart;
26
import org.eclipse.gef.commands.Command;
27
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
28
import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand;
29
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
30
import org.eclipse.gmf.runtime.diagram.ui.commands.SetViewMutabilityCommand;
31
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
32
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
33
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
34
import org.eclipse.gmf.runtime.notation.Node;
35
import org.eclipse.gmf.runtime.notation.View;
36
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
37
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramUpdater;
38
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlNodeDescriptor;
39
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
40
import org.eclipse.uml2.uml.UMLPackage;
41
42
/**
43
 * @generated
44
 */
45
public class ConstraintPropertyCanonicalEditPolicy extends CanonicalEditPolicy {
46
47
	/**
48
	 * @generated
49
	 */
50
	protected void refreshOnActivate() {
51
		// Need to activate editpart children before invoking the canonical refresh for EditParts to add event listeners
52
		List<?> c = getHost().getChildren();
53
		for(int i = 0; i < c.size(); i++) {
54
			((EditPart)c.get(i)).activate();
55
		}
56
		super.refreshOnActivate();
57
	}
58
59
	/**
60
	 * @generated
61
	 */
62
	protected EStructuralFeature getFeatureToSynchronize() {
63
		return UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute();
64
	}
65
66
	/**
67
	 * @generated
68
	 */
69
	@SuppressWarnings("rawtypes")
70
	protected List getSemanticChildrenList() {
71
		View viewObject = (View)getHost().getModel();
72
		LinkedList<EObject> result = new LinkedList<EObject>();
73
		List<SysmlNodeDescriptor> childDescriptors = SysmlDiagramUpdater.getConstraintProperty_2003SemanticChildren(viewObject);
74
		for(SysmlNodeDescriptor d : childDescriptors) {
75
			result.add(d.getModelElement());
76
		}
77
		return result;
78
	}
79
80
	/**
81
	 * @generated
82
	 */
83
	protected boolean isOrphaned(Collection<EObject> semanticChildren, final View view) {
84
		return isMyDiagramElement(view) && !semanticChildren.contains(view.getElement());
85
	}
86
87
	/**
88
	 * @generated
89
	 */
90
	private boolean isMyDiagramElement(View view) {
91
		return Property2EditPart.VISUAL_ID == SysmlVisualIDRegistry.getVisualID(view);
92
	}
93
94
	/**
95
	 * @generated
96
	 */
97
	protected void refreshSemantic() {
98
		if(resolveSemanticElement() == null) {
99
			return;
100
		}
101
		LinkedList<IAdaptable> createdViews = new LinkedList<IAdaptable>();
102
		List<SysmlNodeDescriptor> childDescriptors = SysmlDiagramUpdater.getConstraintProperty_2003SemanticChildren((View)getHost().getModel());
103
		LinkedList<View> orphaned = new LinkedList<View>();
104
		// we care to check only views we recognize as ours
105
		LinkedList<View> knownViewChildren = new LinkedList<View>();
106
		for(View v : getViewChildren()) {
107
			if(isMyDiagramElement(v)) {
108
				knownViewChildren.add(v);
109
			}
110
		}
111
		// alternative to #cleanCanonicalSemanticChildren(getViewChildren(), semanticChildren)
112
		//
113
		// iteration happens over list of desired semantic elements, trying to find best matching View, while original CEP
114
		// iterates views, potentially losing view (size/bounds) information - i.e. if there are few views to reference same EObject, only last one 
115
		// to answer isOrphaned == true will be used for the domain element representation, see #cleanCanonicalSemanticChildren()
116
		for(Iterator<SysmlNodeDescriptor> descriptorsIterator = childDescriptors.iterator(); descriptorsIterator.hasNext();) {
117
			SysmlNodeDescriptor next = descriptorsIterator.next();
118
			String hint = SysmlVisualIDRegistry.getType(next.getVisualID());
119
			LinkedList<View> perfectMatch = new LinkedList<View>(); // both semanticElement and hint match that of NodeDescriptor
120
			for(View childView : getViewChildren()) {
121
				EObject semanticElement = childView.getElement();
122
				if(next.getModelElement().equals(semanticElement)) {
123
					if(hint.equals(childView.getType())) {
124
						perfectMatch.add(childView);
125
						// actually, can stop iteration over view children here, but
126
						// may want to use not the first view but last one as a 'real' match (the way original CEP does
127
						// with its trick with viewToSemanticMap inside #cleanCanonicalSemanticChildren
128
					}
129
				}
130
			}
131
			if(perfectMatch.size() > 0) {
132
				descriptorsIterator.remove(); // precise match found no need to create anything for the NodeDescriptor
133
				// use only one view (first or last?), keep rest as orphaned for further consideration
134
				knownViewChildren.remove(perfectMatch.getFirst());
135
			}
136
		}
137
		// those left in knownViewChildren are subject to removal - they are our diagram elements we didn't find match to,
138
		// or those we have potential matches to, and thus need to be recreated, preserving size/location information.
139
		orphaned.addAll(knownViewChildren);
140
		//
141
		ArrayList<CreateViewRequest.ViewDescriptor> viewDescriptors = new ArrayList<CreateViewRequest.ViewDescriptor>(childDescriptors.size());
142
		for(SysmlNodeDescriptor next : childDescriptors) {
143
			String hint = SysmlVisualIDRegistry.getType(next.getVisualID());
144
			IAdaptable elementAdapter = new CanonicalElementAdapter(next.getModelElement(), hint);
145
			CreateViewRequest.ViewDescriptor descriptor = new CreateViewRequest.ViewDescriptor(elementAdapter, Node.class, hint, ViewUtil.APPEND, false, host().getDiagramPreferencesHint());
146
			viewDescriptors.add(descriptor);
147
		}
148
149
		boolean changed = deleteViews(orphaned.iterator());
150
		//
151
		CreateViewRequest request = getCreateViewRequest(viewDescriptors);
152
		Command cmd = getCreateViewCommand(request);
153
		if(cmd != null && cmd.canExecute()) {
154
			SetViewMutabilityCommand.makeMutable(new EObjectAdapter(host().getNotationView())).execute();
155
			executeCommand(cmd);
156
			@SuppressWarnings("unchecked")
157
			List<IAdaptable> nl = (List<IAdaptable>)request.getNewObject();
158
			createdViews.addAll(nl);
159
		}
160
		if(changed || createdViews.size() > 0) {
161
			postProcessRefreshSemantic(createdViews);
162
		}
163
		if(createdViews.size() > 1) {
164
			// perform a layout of the container
165
			DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host().getEditingDomain(), createdViews, host());
166
			executeCommand(new ICommandProxy(layoutCmd));
167
		}
168
169
		makeViewsImmutable(createdViews);
170
	}
171
172
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/ConstraintPropertyItemSemanticEditPolicy.java (-115 lines)
Lines 1-115 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import java.util.Iterator;
17
18
import org.eclipse.emf.ecore.EAnnotation;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.gef.commands.Command;
21
import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand;
22
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
23
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
24
import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
25
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
27
import org.eclipse.gmf.runtime.notation.Node;
28
import org.eclipse.gmf.runtime.notation.View;
29
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
30
import org.eclipse.papyrus.sysml.diagram.parametric.edit.commands.Property2CreateCommand;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
32
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
33
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
34
import org.eclipse.uml2.uml.Property;
35
36
/**
37
 * @generated
38
 */
39
public class ConstraintPropertyItemSemanticEditPolicy extends SysmlBaseItemSemanticEditPolicy {
40
41
	/**
42
	 * @generated
43
	 */
44
	public ConstraintPropertyItemSemanticEditPolicy() {
45
		super(SysmlElementTypes.ConstraintProperty_2003);
46
	}
47
48
	/**
49
	 * @generated
50
	 */
51
	protected Command getCreateCommand(CreateElementRequest req) {
52
		if(SysmlElementTypes.Property_3002 == req.getElementType()) {
53
			return getGEFWrapper(new Property2CreateCommand(req));
54
		}
55
		return super.getCreateCommand(req);
56
	}
57
58
	/**
59
	 * @generated NOT delete property views if any
60
	 */
61
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
62
		View view = (View)getHost().getModel();
63
		CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
64
		cmd.setTransactionNestingEnabled(false);
65
		EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
66
		if(annotation == null) {
67
			// there are indirectly referenced children, need extra commands: true
68
			addDestroyChildNodesCommand(cmd);
69
			addDestroyShortcutsCommand(cmd, view);
70
			// delete host element
71
			cmd.add(new DestroyElementCommand(req));
72
			// destroy base property
73
			addDestroyBasePropertyCommand(cmd);
74
		} else {
75
			cmd.add(new DeleteCommand(getEditingDomain(), view));
76
		}
77
		return getGEFWrapper(cmd.reduce());
78
	}
79
80
	/**
81
	 * Delete property views of the constraint property
82
	 * 
83
	 * @generated NOT
84
	 */
85
	private void addDestroyChildNodesCommand(ICompositeCommand cmd) {
86
		View view = (View)getHost().getModel();
87
		for(Iterator<?> nit = view.getChildren().iterator(); nit.hasNext();) {
88
			Node node = (Node)nit.next();
89
			switch(SysmlVisualIDRegistry.getVisualID(node)) {
90
			case Property2EditPart.VISUAL_ID:
91
				// only delete from diagram
92
				cmd.add(new DeleteCommand(getEditingDomain(), node));
93
				break;
94
			}
95
		}
96
	}
97
98
	/**
99
	 * Delete the base property from the constraint property
100
	 * 
101
	 * @generated NOT
102
	 */
103
	private void addDestroyBasePropertyCommand(ICompositeCommand cmd) {
104
		View view = (View)getHost().getModel();
105
		EObject element = view.getElement();
106
		if(element instanceof ConstraintProperty) {
107
			Property property = ((ConstraintProperty)element).getBase_Property();
108
			if(property != null) {
109
				DestroyElementRequest request = new DestroyElementRequest(property, false);
110
				cmd.add(new DestroyElementCommand(request));
111
			}
112
		}
113
	}
114
115
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/OpenDiagramEditPolicy.java (-183 lines)
Lines 1-183 Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
2
3
import java.io.IOException;
4
import java.lang.reflect.InvocationTargetException;
5
import java.util.Iterator;
6
7
import org.eclipse.core.commands.ExecutionException;
8
import org.eclipse.core.runtime.CoreException;
9
import org.eclipse.core.runtime.IAdaptable;
10
import org.eclipse.core.runtime.IProgressMonitor;
11
import org.eclipse.emf.common.ui.URIEditorInput;
12
import org.eclipse.emf.common.util.URI;
13
import org.eclipse.emf.ecore.EObject;
14
import org.eclipse.emf.ecore.resource.Resource;
15
import org.eclipse.emf.ecore.util.EcoreUtil;
16
import org.eclipse.emf.transaction.util.TransactionUtil;
17
import org.eclipse.gef.EditPart;
18
import org.eclipse.gef.Request;
19
import org.eclipse.gef.commands.Command;
20
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
21
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
22
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
23
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
24
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.OpenEditPolicy;
25
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
26
import org.eclipse.gmf.runtime.notation.Diagram;
27
import org.eclipse.gmf.runtime.notation.HintedDiagramLinkStyle;
28
import org.eclipse.gmf.runtime.notation.NotationPackage;
29
import org.eclipse.gmf.runtime.notation.Style;
30
import org.eclipse.gmf.runtime.notation.View;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
32
import org.eclipse.papyrus.sysml.diagram.parametric.part.Messages;
33
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditor;
34
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
35
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorUtil;
36
import org.eclipse.ui.IEditorInput;
37
import org.eclipse.ui.IWorkbenchPage;
38
import org.eclipse.ui.PlatformUI;
39
import org.eclipse.ui.actions.WorkspaceModifyOperation;
40
41
/**
42
 * @generated
43
 */
44
public class OpenDiagramEditPolicy extends OpenEditPolicy {
45
46
	/**
47
	 * @generated
48
	 */
49
	protected Command getOpenCommand(Request request) {
50
		EditPart targetEditPart = getTargetEditPart(request);
51
		if(false == targetEditPart.getModel() instanceof View) {
52
			return null;
53
		}
54
		View view = (View)targetEditPart.getModel();
55
		Style link = view.getStyle(NotationPackage.eINSTANCE.getHintedDiagramLinkStyle());
56
		if(false == link instanceof HintedDiagramLinkStyle) {
57
			return null;
58
		}
59
		return new ICommandProxy(new OpenDiagramCommand((HintedDiagramLinkStyle)link));
60
	}
61
62
	/**
63
	 * @generated
64
	 */
65
	private static class OpenDiagramCommand extends AbstractTransactionalCommand {
66
67
		/**
68
		 * @generated
69
		 */
70
		private final HintedDiagramLinkStyle diagramFacet;
71
72
		/**
73
		 * @generated
74
		 */
75
		OpenDiagramCommand(HintedDiagramLinkStyle linkStyle) {
76
			// editing domain is taken for original diagram, 
77
			// if we open diagram from another file, we should use another editing domain
78
			super(TransactionUtil.getEditingDomain(linkStyle), Messages.CommandName_OpenDiagram, null);
79
			diagramFacet = linkStyle;
80
		}
81
82
		// FIXME canExecute if !(readOnly && getDiagramToOpen == null), i.e. open works on ro
83
		// diagrams only when there's associated diagram already
84
85
		/**
86
		 * @generated
87
		 */
88
		protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
89
			try {
90
				Diagram diagram = getDiagramToOpen();
91
				if(diagram == null) {
92
					diagram = intializeNewDiagram();
93
				}
94
				URI uri = EcoreUtil.getURI(diagram);
95
				String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram);
96
				IEditorInput editorInput = new URIEditorInput(uri, editorName);
97
				IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
98
				page.openEditor(editorInput, getEditorID());
99
				return CommandResult.newOKCommandResult();
100
			} catch (Exception ex) {
101
				throw new ExecutionException("Can't open diagram", ex);
102
			}
103
		}
104
105
		/**
106
		 * @generated
107
		 */
108
		protected Diagram getDiagramToOpen() {
109
			return diagramFacet.getDiagramLink();
110
		}
111
112
		/**
113
		 * @generated
114
		 */
115
		protected Diagram intializeNewDiagram() throws ExecutionException {
116
			Diagram d = ViewService.createDiagram(getDiagramDomainElement(), getDiagramKind(), getPreferencesHint());
117
			if(d == null) {
118
				throw new ExecutionException("Can't create diagram of '" + getDiagramKind() + "' kind");
119
			}
120
			diagramFacet.setDiagramLink(d);
121
			assert diagramFacet.eResource() != null;
122
			diagramFacet.eResource().getContents().add(d);
123
			EObject container = diagramFacet.eContainer();
124
			while(container instanceof View) {
125
				((View)container).persist();
126
				container = container.eContainer();
127
			}
128
			try {
129
				new WorkspaceModifyOperation() {
130
131
					protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
132
						try {
133
							for(Iterator it = diagramFacet.eResource().getResourceSet().getResources().iterator(); it.hasNext();) {
134
								Resource nextResource = (Resource)it.next();
135
								if(nextResource.isLoaded() && !getEditingDomain().isReadOnly(nextResource)) {
136
									nextResource.save(SysmlDiagramEditorUtil.getSaveOptions());
137
								}
138
							}
139
						} catch (IOException ex) {
140
							throw new InvocationTargetException(ex, "Save operation failed");
141
						}
142
					}
143
				}.run(null);
144
			} catch (InvocationTargetException e) {
145
				throw new ExecutionException("Can't create diagram of '" + getDiagramKind() + "' kind", e);
146
			} catch (InterruptedException e) {
147
				throw new ExecutionException("Can't create diagram of '" + getDiagramKind() + "' kind", e);
148
			}
149
			return d;
150
		}
151
152
		/**
153
		 * @generated
154
		 */
155
		protected EObject getDiagramDomainElement() {
156
			// use same element as associated with EP
157
			return ((View)diagramFacet.eContainer()).getElement();
158
		}
159
160
		/**
161
		 * @generated
162
		 */
163
		protected PreferencesHint getPreferencesHint() {
164
			// XXX prefhint from target diagram's editor?
165
			return SysmlDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
166
		}
167
168
		/**
169
		 * @generated
170
		 */
171
		protected String getDiagramKind() {
172
			return ParametricEditPart.MODEL_ID;
173
		}
174
175
		/**
176
		 * @generated
177
		 */
178
		protected String getEditorID() {
179
			return SysmlDiagramEditor.ID;
180
		}
181
	}
182
183
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/ParametricCanonicalEditPolicy.java (-352 lines)
Lines 1-352 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import java.util.ArrayList;
17
import java.util.Collection;
18
import java.util.Collections;
19
import java.util.HashMap;
20
import java.util.HashSet;
21
import java.util.Iterator;
22
import java.util.LinkedList;
23
import java.util.List;
24
import java.util.Map;
25
import java.util.Set;
26
27
import org.eclipse.core.runtime.IAdaptable;
28
import org.eclipse.emf.ecore.EObject;
29
import org.eclipse.emf.ecore.EStructuralFeature;
30
import org.eclipse.gef.EditPart;
31
import org.eclipse.gef.commands.Command;
32
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
33
import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand;
34
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
35
import org.eclipse.gmf.runtime.diagram.ui.commands.SetViewMutabilityCommand;
36
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
37
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
38
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
39
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
40
import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
41
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
42
import org.eclipse.gmf.runtime.notation.Diagram;
43
import org.eclipse.gmf.runtime.notation.Edge;
44
import org.eclipse.gmf.runtime.notation.Node;
45
import org.eclipse.gmf.runtime.notation.View;
46
import org.eclipse.papyrus.resource.ResourcePackage;
47
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
48
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
49
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
50
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
51
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart;
52
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramUpdater;
53
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlLinkDescriptor;
54
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlNodeDescriptor;
55
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
56
import org.eclipse.uml2.uml.UMLPackage;
57
58
/**
59
 * @generated
60
 */
61
public class ParametricCanonicalEditPolicy extends CanonicalEditPolicy {
62
63
	/**
64
	 * @generated
65
	 */
66
	private Set<EStructuralFeature> myFeaturesToSynchronize;
67
68
	/**
69
	 * @generated
70
	 */
71
	protected void refreshOnActivate() {
72
		// Need to activate editpart children before invoking the canonical refresh for EditParts to add event listeners
73
		List<?> c = getHost().getChildren();
74
		for(int i = 0; i < c.size(); i++) {
75
			((EditPart)c.get(i)).activate();
76
		}
77
		super.refreshOnActivate();
78
	}
79
80
	/**
81
	 * @generated
82
	 */
83
	@SuppressWarnings("rawtypes")
84
	protected List getSemanticChildrenList() {
85
		View viewObject = (View)getHost().getModel();
86
		LinkedList<EObject> result = new LinkedList<EObject>();
87
		List<SysmlNodeDescriptor> childDescriptors = SysmlDiagramUpdater.getResource_1000SemanticChildren(viewObject);
88
		for(SysmlNodeDescriptor d : childDescriptors) {
89
			result.add(d.getModelElement());
90
		}
91
		return result;
92
	}
93
94
	/**
95
	 * @generated
96
	 */
97
	protected boolean isOrphaned(Collection<EObject> semanticChildren, final View view) {
98
		return isMyDiagramElement(view) && !semanticChildren.contains(view.getElement());
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	private boolean isMyDiagramElement(View view) {
105
		int visualID = SysmlVisualIDRegistry.getVisualID(view);
106
		return visualID == ConstraintPropertyEditPart.VISUAL_ID || visualID == PropertyEditPart.VISUAL_ID;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected Set getFeaturesToSynchronize() {
113
		if(myFeaturesToSynchronize == null) {
114
			myFeaturesToSynchronize = new HashSet<EStructuralFeature>();
115
			myFeaturesToSynchronize.add(ResourcePackage.eINSTANCE.getResource_Eobjects());
116
			myFeaturesToSynchronize.add(UMLPackage.eINSTANCE.getStructuredClassifier_OwnedAttribute());
117
		}
118
		return myFeaturesToSynchronize;
119
	}
120
121
	/**
122
	 * @generated
123
	 */
124
	protected void refreshSemantic() {
125
		if(resolveSemanticElement() == null) {
126
			return;
127
		}
128
		LinkedList<IAdaptable> createdViews = new LinkedList<IAdaptable>();
129
		List<SysmlNodeDescriptor> childDescriptors = SysmlDiagramUpdater.getResource_1000SemanticChildren((View)getHost().getModel());
130
		LinkedList<View> orphaned = new LinkedList<View>();
131
		// we care to check only views we recognize as ours
132
		LinkedList<View> knownViewChildren = new LinkedList<View>();
133
		for(View v : getViewChildren()) {
134
			if(isMyDiagramElement(v)) {
135
				knownViewChildren.add(v);
136
			}
137
		}
138
		// alternative to #cleanCanonicalSemanticChildren(getViewChildren(), semanticChildren)
139
		//
140
		// iteration happens over list of desired semantic elements, trying to find best matching View, while original CEP
141
		// iterates views, potentially losing view (size/bounds) information - i.e. if there are few views to reference same EObject, only last one 
142
		// to answer isOrphaned == true will be used for the domain element representation, see #cleanCanonicalSemanticChildren()
143
		for(Iterator<SysmlNodeDescriptor> descriptorsIterator = childDescriptors.iterator(); descriptorsIterator.hasNext();) {
144
			SysmlNodeDescriptor next = descriptorsIterator.next();
145
			String hint = SysmlVisualIDRegistry.getType(next.getVisualID());
146
			LinkedList<View> perfectMatch = new LinkedList<View>(); // both semanticElement and hint match that of NodeDescriptor
147
			for(View childView : getViewChildren()) {
148
				EObject semanticElement = childView.getElement();
149
				if(next.getModelElement().equals(semanticElement)) {
150
					if(hint.equals(childView.getType())) {
151
						perfectMatch.add(childView);
152
						// actually, can stop iteration over view children here, but
153
						// may want to use not the first view but last one as a 'real' match (the way original CEP does
154
						// with its trick with viewToSemanticMap inside #cleanCanonicalSemanticChildren
155
					}
156
				}
157
			}
158
			if(perfectMatch.size() > 0) {
159
				descriptorsIterator.remove(); // precise match found no need to create anything for the NodeDescriptor
160
				// use only one view (first or last?), keep rest as orphaned for further consideration
161
				knownViewChildren.remove(perfectMatch.getFirst());
162
			}
163
		}
164
		// those left in knownViewChildren are subject to removal - they are our diagram elements we didn't find match to,
165
		// or those we have potential matches to, and thus need to be recreated, preserving size/location information.
166
		orphaned.addAll(knownViewChildren);
167
		//
168
		ArrayList<CreateViewRequest.ViewDescriptor> viewDescriptors = new ArrayList<CreateViewRequest.ViewDescriptor>(childDescriptors.size());
169
		for(SysmlNodeDescriptor next : childDescriptors) {
170
			String hint = SysmlVisualIDRegistry.getType(next.getVisualID());
171
			IAdaptable elementAdapter = new CanonicalElementAdapter(next.getModelElement(), hint);
172
			CreateViewRequest.ViewDescriptor descriptor = new CreateViewRequest.ViewDescriptor(elementAdapter, Node.class, hint, ViewUtil.APPEND, false, host().getDiagramPreferencesHint());
173
			viewDescriptors.add(descriptor);
174
		}
175
176
		boolean changed = deleteViews(orphaned.iterator());
177
		//
178
		CreateViewRequest request = getCreateViewRequest(viewDescriptors);
179
		Command cmd = getCreateViewCommand(request);
180
		if(cmd != null && cmd.canExecute()) {
181
			SetViewMutabilityCommand.makeMutable(new EObjectAdapter(host().getNotationView())).execute();
182
			executeCommand(cmd);
183
			@SuppressWarnings("unchecked")
184
			List<IAdaptable> nl = (List<IAdaptable>)request.getNewObject();
185
			createdViews.addAll(nl);
186
		}
187
		if(changed || createdViews.size() > 0) {
188
			postProcessRefreshSemantic(createdViews);
189
		}
190
191
		Collection<IAdaptable> createdConnectionViews = refreshConnections();
192
193
		if(createdViews.size() > 1) {
194
			// perform a layout of the container
195
			DeferredLayoutCommand layoutCmd = new DeferredLayoutCommand(host().getEditingDomain(), createdViews, host());
196
			executeCommand(new ICommandProxy(layoutCmd));
197
		}
198
199
		createdViews.addAll(createdConnectionViews);
200
201
		makeViewsImmutable(createdViews);
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	private Diagram getDiagram() {
208
		return ((View)getHost().getModel()).getDiagram();
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	private Collection<IAdaptable> refreshConnections() {
215
		Map<EObject, View> domain2NotationMap = new HashMap<EObject, View>();
216
		Collection<SysmlLinkDescriptor> linkDescriptors = collectAllLinks(getDiagram(), domain2NotationMap);
217
		Collection existingLinks = new LinkedList(getDiagram().getEdges());
218
		for(Iterator linksIterator = existingLinks.iterator(); linksIterator.hasNext();) {
219
			Edge nextDiagramLink = (Edge)linksIterator.next();
220
			int diagramLinkVisualID = SysmlVisualIDRegistry.getVisualID(nextDiagramLink);
221
			if(diagramLinkVisualID == -1) {
222
				if(nextDiagramLink.getSource() != null && nextDiagramLink.getTarget() != null) {
223
					linksIterator.remove();
224
				}
225
				continue;
226
			}
227
			EObject diagramLinkObject = nextDiagramLink.getElement();
228
			EObject diagramLinkSrc = nextDiagramLink.getSource().getElement();
229
			EObject diagramLinkDst = nextDiagramLink.getTarget().getElement();
230
			for(Iterator<SysmlLinkDescriptor> linkDescriptorsIterator = linkDescriptors.iterator(); linkDescriptorsIterator.hasNext();) {
231
				SysmlLinkDescriptor nextLinkDescriptor = linkDescriptorsIterator.next();
232
				if(diagramLinkObject == nextLinkDescriptor.getModelElement() && diagramLinkSrc == nextLinkDescriptor.getSource() && diagramLinkDst == nextLinkDescriptor.getDestination() && diagramLinkVisualID == nextLinkDescriptor.getVisualID()) {
233
					linksIterator.remove();
234
					linkDescriptorsIterator.remove();
235
					break;
236
				}
237
			}
238
		}
239
		deleteViews(existingLinks.iterator());
240
		return createConnections(linkDescriptors, domain2NotationMap);
241
	}
242
243
	/**
244
	 * @generated
245
	 */
246
	private Collection<SysmlLinkDescriptor> collectAllLinks(View view, Map<EObject, View> domain2NotationMap) {
247
		if(!ParametricEditPart.MODEL_ID.equals(SysmlVisualIDRegistry.getModelID(view))) {
248
			return Collections.emptyList();
249
		}
250
		LinkedList<SysmlLinkDescriptor> result = new LinkedList<SysmlLinkDescriptor>();
251
		switch(SysmlVisualIDRegistry.getVisualID(view)) {
252
		case ParametricEditPart.VISUAL_ID:
253
		{
254
			if(!domain2NotationMap.containsKey(view.getElement())) {
255
				result.addAll(SysmlDiagramUpdater.getResource_1000ContainedLinks(view));
256
			}
257
			if(!domain2NotationMap.containsKey(view.getElement()) || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
258
				domain2NotationMap.put(view.getElement(), view);
259
			}
260
			break;
261
		}
262
		case ConstraintPropertyEditPart.VISUAL_ID:
263
		{
264
			if(!domain2NotationMap.containsKey(view.getElement())) {
265
				result.addAll(SysmlDiagramUpdater.getConstraintProperty_2003ContainedLinks(view));
266
			}
267
			if(!domain2NotationMap.containsKey(view.getElement()) || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
268
				domain2NotationMap.put(view.getElement(), view);
269
			}
270
			break;
271
		}
272
		case PropertyEditPart.VISUAL_ID:
273
		{
274
			if(!domain2NotationMap.containsKey(view.getElement())) {
275
				result.addAll(SysmlDiagramUpdater.getProperty_2005ContainedLinks(view));
276
			}
277
			if(!domain2NotationMap.containsKey(view.getElement()) || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
278
				domain2NotationMap.put(view.getElement(), view);
279
			}
280
			break;
281
		}
282
		case Property2EditPart.VISUAL_ID:
283
		{
284
			if(!domain2NotationMap.containsKey(view.getElement())) {
285
				result.addAll(SysmlDiagramUpdater.getProperty_3002ContainedLinks(view));
286
			}
287
			if(!domain2NotationMap.containsKey(view.getElement()) || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
288
				domain2NotationMap.put(view.getElement(), view);
289
			}
290
			break;
291
		}
292
		case ConnectorEditPart.VISUAL_ID:
293
		{
294
			if(!domain2NotationMap.containsKey(view.getElement())) {
295
				result.addAll(SysmlDiagramUpdater.getConnector_4001ContainedLinks(view));
296
			}
297
			if(!domain2NotationMap.containsKey(view.getElement()) || view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$
298
				domain2NotationMap.put(view.getElement(), view);
299
			}
300
			break;
301
		}
302
		}
303
		for(Iterator children = view.getChildren().iterator(); children.hasNext();) {
304
			result.addAll(collectAllLinks((View)children.next(), domain2NotationMap));
305
		}
306
		for(Iterator edges = view.getSourceEdges().iterator(); edges.hasNext();) {
307
			result.addAll(collectAllLinks((View)edges.next(), domain2NotationMap));
308
		}
309
		return result;
310
	}
311
312
	/**
313
	 * @generated
314
	 */
315
	private Collection<IAdaptable> createConnections(Collection<SysmlLinkDescriptor> linkDescriptors, Map<EObject, View> domain2NotationMap) {
316
		LinkedList<IAdaptable> adapters = new LinkedList<IAdaptable>();
317
		for(SysmlLinkDescriptor nextLinkDescriptor : linkDescriptors) {
318
			EditPart sourceEditPart = getEditPart(nextLinkDescriptor.getSource(), domain2NotationMap);
319
			EditPart targetEditPart = getEditPart(nextLinkDescriptor.getDestination(), domain2NotationMap);
320
			if(sourceEditPart == null || targetEditPart == null) {
321
				continue;
322
			}
323
			CreateConnectionViewRequest.ConnectionViewDescriptor descriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(nextLinkDescriptor.getSemanticAdapter(), SysmlVisualIDRegistry.getType(nextLinkDescriptor.getVisualID()), ViewUtil.APPEND, false, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
324
			CreateConnectionViewRequest ccr = new CreateConnectionViewRequest(descriptor);
325
			ccr.setType(RequestConstants.REQ_CONNECTION_START);
326
			ccr.setSourceEditPart(sourceEditPart);
327
			sourceEditPart.getCommand(ccr);
328
			ccr.setTargetEditPart(targetEditPart);
329
			ccr.setType(RequestConstants.REQ_CONNECTION_END);
330
			Command cmd = targetEditPart.getCommand(ccr);
331
			if(cmd != null && cmd.canExecute()) {
332
				executeCommand(cmd);
333
				IAdaptable viewAdapter = (IAdaptable)ccr.getNewObject();
334
				if(viewAdapter != null) {
335
					adapters.add(viewAdapter);
336
				}
337
			}
338
		}
339
		return adapters;
340
	}
341
342
	/**
343
	 * @generated
344
	 */
345
	private EditPart getEditPart(EObject domainModelElement, Map<EObject, View> domain2NotationMap) {
346
		View view = (View)domain2NotationMap.get(domainModelElement);
347
		if(view != null) {
348
			return (EditPart)getHost().getViewer().getEditPartRegistry().get(view);
349
		}
350
		return null;
351
	}
352
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/ParametricItemSemanticEditPolicy.java (-80 lines)
Lines 1-80 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import org.eclipse.emf.transaction.TransactionalEditingDomain;
17
import org.eclipse.gef.commands.Command;
18
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
19
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
20
import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest;
21
import org.eclipse.gmf.runtime.notation.Diagram;
22
import org.eclipse.papyrus.sysml.diagram.parametric.edit.commands.ConstraintPropertyCreateCommand;
23
import org.eclipse.papyrus.sysml.diagram.parametric.edit.commands.PropertyCreateCommand;
24
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
25
import org.eclipse.papyrus.uml.diagram.common.commands.DuplicateNamedElementCommand;
26
27
/**
28
 * @generated
29
 */
30
public class ParametricItemSemanticEditPolicy extends SysmlBaseItemSemanticEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	public ParametricItemSemanticEditPolicy() {
36
		super(SysmlElementTypes.Resource_1000);
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	protected Command getCreateCommand(CreateElementRequest req) {
43
		if(SysmlElementTypes.ConstraintProperty_2003 == req.getElementType()) {
44
			return getGEFWrapper(new ConstraintPropertyCreateCommand(req));
45
		}
46
		if(SysmlElementTypes.Property_2005 == req.getElementType()) {
47
			return getGEFWrapper(new PropertyCreateCommand(req));
48
		}
49
		return super.getCreateCommand(req);
50
	}
51
52
	/**
53
	 * @generated
54
	 */
55
	protected Command getDuplicateCommand(DuplicateElementsRequest req) {
56
		TransactionalEditingDomain editingDomain = ((IGraphicalEditPart)getHost()).getEditingDomain();
57
		Diagram currentDiagram = null;
58
		if(getHost() instanceof IGraphicalEditPart) {
59
			currentDiagram = ((IGraphicalEditPart)getHost()).getNotationView().getDiagram();
60
		}
61
		return getGEFWrapper(new DuplicateAnythingCommand(editingDomain, req, currentDiagram));
62
	}
63
64
	/**
65
	 * @generated
66
	 */
67
	private static class DuplicateAnythingCommand extends DuplicateNamedElementCommand {
68
69
		private Diagram diagram;
70
71
		/**
72
		 * @generated
73
		 */
74
		public DuplicateAnythingCommand(TransactionalEditingDomain editingDomain, DuplicateElementsRequest req, Diagram currentDiagram) {
75
			super(editingDomain, req.getLabel(), req.getElementsToBeDuplicated(), req.getAllDuplicatedElementsMap(), currentDiagram);
76
			this.diagram = currentDiagram;
77
		}
78
	}
79
80
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/Property2ItemSemanticEditPolicy.java (-111 lines)
Lines 1-111 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import java.util.ArrayList;
17
import java.util.List;
18
19
import org.eclipse.emf.ecore.EAnnotation;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.gef.commands.Command;
22
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
23
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
24
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
25
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
27
import org.eclipse.gmf.runtime.notation.View;
28
import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
29
import org.eclipse.papyrus.sysml.diagram.parametric.edit.commands.ConnectorCreateCommand;
30
import org.eclipse.papyrus.sysml.diagram.parametric.edit.commands.ConnectorReorientCommand;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
32
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
33
34
/**
35
 * @generated
36
 */
37
public class Property2ItemSemanticEditPolicy extends SysmlBaseItemSemanticEditPolicy {
38
39
	/**
40
	 * @generated
41
	 */
42
	public Property2ItemSemanticEditPolicy() {
43
		super(SysmlElementTypes.Property_3002);
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
50
		View view = (View)getHost().getModel();
51
		CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
52
		cmd.setTransactionNestingEnabled(true);
53
54
		EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
55
		if(annotation == null) {
56
			// there are indirectly referenced children, need extra commands: false
57
			addDestroyShortcutsCommand(cmd, view);
58
			// delete host element
59
			List<EObject> todestroy = new ArrayList<EObject>();
60
			todestroy.add(req.getElementToDestroy());
61
			//cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req));
62
			cmd.add(new EMFtoGMFCommandWrapper(new org.eclipse.emf.edit.command.DeleteCommand(getEditingDomain(), todestroy)));
63
		} else {
64
			cmd.add(new DeleteCommand(getEditingDomain(), view));
65
		}
66
		return getGEFWrapper(cmd.reduce());
67
	}
68
69
	/**
70
	 * @generated
71
	 */
72
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
73
		Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) : getCompleteCreateRelationshipCommand(req);
74
		return command != null ? command : super.getCreateRelationshipCommand(req);
75
	}
76
77
	/**
78
	 * @generated
79
	 */
80
	protected Command getStartCreateRelationshipCommand(CreateRelationshipRequest req) {
81
		if(SysmlElementTypes.Connector_4001 == req.getElementType()) {
82
			return getGEFWrapper(new ConnectorCreateCommand(req, req.getSource(), req.getTarget()));
83
		}
84
		return null;
85
	}
86
87
	/**
88
	 * @generated
89
	 */
90
	protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
91
		if(SysmlElementTypes.Connector_4001 == req.getElementType()) {
92
			return getGEFWrapper(new ConnectorCreateCommand(req, req.getSource(), req.getTarget()));
93
		}
94
		return null;
95
	}
96
97
	/**
98
	 * Returns command to reorient EClass based link. New link target or source should be the domain
99
	 * model element associated with this node.
100
	 * 
101
	 * @generated
102
	 */
103
	protected Command getReorientRelationshipCommand(ReorientRelationshipRequest req) {
104
		switch(getVisualID(req)) {
105
		case ConnectorEditPart.VISUAL_ID:
106
			return getGEFWrapper(new ConnectorReorientCommand(req));
107
		}
108
		return super.getReorientRelationshipCommand(req);
109
	}
110
111
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/PropertyItemSemanticEditPolicy.java (-111 lines)
Lines 1-111 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import java.util.ArrayList;
17
import java.util.List;
18
19
import org.eclipse.emf.ecore.EAnnotation;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.gef.commands.Command;
22
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
23
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
24
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
25
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
26
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
27
import org.eclipse.gmf.runtime.notation.View;
28
import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
29
import org.eclipse.papyrus.sysml.diagram.parametric.edit.commands.ConnectorCreateCommand;
30
import org.eclipse.papyrus.sysml.diagram.parametric.edit.commands.ConnectorReorientCommand;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
32
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
33
34
/**
35
 * @generated
36
 */
37
public class PropertyItemSemanticEditPolicy extends SysmlBaseItemSemanticEditPolicy {
38
39
	/**
40
	 * @generated
41
	 */
42
	public PropertyItemSemanticEditPolicy() {
43
		super(SysmlElementTypes.Property_2005);
44
	}
45
46
	/**
47
	 * @generated
48
	 */
49
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
50
		View view = (View)getHost().getModel();
51
		CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(getEditingDomain(), null);
52
		cmd.setTransactionNestingEnabled(true);
53
54
		EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
55
		if(annotation == null) {
56
			// there are indirectly referenced children, need extra commands: false
57
			addDestroyShortcutsCommand(cmd, view);
58
			// delete host element
59
			List<EObject> todestroy = new ArrayList<EObject>();
60
			todestroy.add(req.getElementToDestroy());
61
			//cmd.add(new org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand(req));
62
			cmd.add(new EMFtoGMFCommandWrapper(new org.eclipse.emf.edit.command.DeleteCommand(getEditingDomain(), todestroy)));
63
		} else {
64
			cmd.add(new DeleteCommand(getEditingDomain(), view));
65
		}
66
		return getGEFWrapper(cmd.reduce());
67
	}
68
69
	/**
70
	 * @generated
71
	 */
72
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
73
		Command command = req.getTarget() == null ? getStartCreateRelationshipCommand(req) : getCompleteCreateRelationshipCommand(req);
74
		return command != null ? command : super.getCreateRelationshipCommand(req);
75
	}
76
77
	/**
78
	 * @generated
79
	 */
80
	protected Command getStartCreateRelationshipCommand(CreateRelationshipRequest req) {
81
		if(SysmlElementTypes.Connector_4001 == req.getElementType()) {
82
			return getGEFWrapper(new ConnectorCreateCommand(req, req.getSource(), req.getTarget()));
83
		}
84
		return null;
85
	}
86
87
	/**
88
	 * @generated
89
	 */
90
	protected Command getCompleteCreateRelationshipCommand(CreateRelationshipRequest req) {
91
		if(SysmlElementTypes.Connector_4001 == req.getElementType()) {
92
			return getGEFWrapper(new ConnectorCreateCommand(req, req.getSource(), req.getTarget()));
93
		}
94
		return null;
95
	}
96
97
	/**
98
	 * Returns command to reorient EClass based link. New link target or source should be the domain
99
	 * model element associated with this node.
100
	 * 
101
	 * @generated
102
	 */
103
	protected Command getReorientRelationshipCommand(ReorientRelationshipRequest req) {
104
		switch(getVisualID(req)) {
105
		case ConnectorEditPart.VISUAL_ID:
106
			return getGEFWrapper(new ConnectorReorientCommand(req));
107
		}
108
		return super.getReorientRelationshipCommand(req);
109
	}
110
111
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/SysmlBaseItemSemanticEditPolicy.java (-379 lines)
Lines 1-379 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import java.util.Iterator;
17
18
import org.eclipse.emf.transaction.TransactionalEditingDomain;
19
import org.eclipse.gef.Request;
20
import org.eclipse.gef.commands.Command;
21
import org.eclipse.gef.commands.UnexecutableCommand;
22
import org.eclipse.gef.requests.ReconnectRequest;
23
import org.eclipse.gmf.runtime.common.core.command.ICommand;
24
import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand;
25
import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
26
import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
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.SemanticEditPolicy;
30
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
31
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
32
import org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand;
33
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
34
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
35
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
36
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
37
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyReferenceRequest;
38
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyRequest;
39
import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest;
40
import org.eclipse.gmf.runtime.emf.type.core.requests.GetEditContextRequest;
41
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
42
import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
43
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
44
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
45
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
46
import org.eclipse.gmf.runtime.notation.View;
47
import org.eclipse.papyrus.infra.extendedtypes.types.IExtendedHintedElementType;
48
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
49
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
50
import org.eclipse.papyrus.sysml.diagram.parametric.edit.helpers.SysmlBaseEditHelper;
51
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
52
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
53
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
54
import org.eclipse.uml2.uml.ConnectableElement;
55
import org.eclipse.uml2.uml.Connector;
56
import org.eclipse.uml2.uml.StructuredClassifier;
57
import org.eclipse.uml2.uml.Type;
58
59
/**
60
 * @generated
61
 */
62
public class SysmlBaseItemSemanticEditPolicy extends SemanticEditPolicy {
63
64
	/**
65
	 * Extended request data key to hold editpart visual id.
66
	 * 
67
	 * @generated
68
	 */
69
	public static final String VISUAL_ID_KEY = "visual_id"; //$NON-NLS-1$
70
71
	/**
72
	 * Extended request data key to hold the edge view during a reconnect request.
73
	 * 
74
	 * @generated
75
	 */
76
	public static final String GRAPHICAL_RECONNECTED_EDGE = "graphical_edge"; //$NON-NLS-1$
77
78
	/**
79
	 * @generated
80
	 */
81
	private final IElementType myElementType;
82
83
	/**
84
	 * @generated
85
	 */
86
	protected SysmlBaseItemSemanticEditPolicy(IElementType elementType) {
87
		myElementType = elementType;
88
	}
89
90
	/**
91
	 * Extended request data key to hold editpart visual id. Add visual id of edited editpart to
92
	 * extended data of the request so command switch can decide what kind of diagram element is
93
	 * being edited. It is done in those cases when it's not possible to deduce diagram element kind
94
	 * from domain element.
95
	 * 
96
	 * @generated
97
	 */
98
	@SuppressWarnings("unchecked")
99
	public Command getCommand(Request request) {
100
		if(request instanceof ReconnectRequest) {
101
			Object view = ((ReconnectRequest)request).getConnectionEditPart().getModel();
102
			if(view instanceof View) {
103
				Integer id = new Integer(SysmlVisualIDRegistry.getVisualID((View)view));
104
				request.getExtendedData().put(VISUAL_ID_KEY, id);
105
				request.getExtendedData().put(GRAPHICAL_RECONNECTED_EDGE, (View)view);
106
			}
107
		}
108
		return super.getCommand(request);
109
	}
110
111
	/**
112
	 * Returns visual id from request parameters.
113
	 * 
114
	 * @generated
115
	 */
116
	protected int getVisualID(IEditCommandRequest request) {
117
		Object id = request.getParameter(VISUAL_ID_KEY);
118
		return id instanceof Integer ? ((Integer)id).intValue() : -1;
119
	}
120
121
	/**
122
	 * @generated
123
	 */
124
	protected Command getSemanticCommand(IEditCommandRequest request) {
125
		IEditCommandRequest completedRequest = completeRequest(request);
126
		Command semanticCommand = getSemanticCommandSwitch(completedRequest);
127
		semanticCommand = getEditHelperCommand(completedRequest, semanticCommand);
128
		if(completedRequest instanceof DestroyRequest) {
129
			DestroyRequest destroyRequest = (DestroyRequest)completedRequest;
130
			return shouldProceed(destroyRequest) ? addDeleteViewCommand(semanticCommand, destroyRequest) : null;
131
		}
132
		return semanticCommand;
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	protected Command addDeleteViewCommand(Command mainCommand, DestroyRequest completedRequest) {
139
		Command deleteViewCommand = getGEFWrapper(new DeleteCommand(getEditingDomain(), (View)getHost().getModel()));
140
		return mainCommand == null ? deleteViewCommand : mainCommand.chain(deleteViewCommand);
141
	}
142
143
	/**
144
	 * @generated
145
	 */
146
	private Command getEditHelperCommand(IEditCommandRequest request, Command editPolicyCommand) {
147
		if(editPolicyCommand != null) {
148
			ICommand command = editPolicyCommand instanceof ICommandProxy ? ((ICommandProxy)editPolicyCommand).getICommand() : new CommandProxy(editPolicyCommand);
149
			request.setParameter(SysmlBaseEditHelper.EDIT_POLICY_COMMAND, command);
150
		}
151
		IElementType requestContextElementType = getContextElementType(request);
152
		request.setParameter(SysmlBaseEditHelper.CONTEXT_ELEMENT_TYPE, requestContextElementType);
153
		ICommand command = requestContextElementType.getEditCommand(request);
154
		request.setParameter(SysmlBaseEditHelper.EDIT_POLICY_COMMAND, null);
155
		request.setParameter(SysmlBaseEditHelper.CONTEXT_ELEMENT_TYPE, null);
156
		if(command != null) {
157
			if(!(command instanceof CompositeTransactionalCommand)) {
158
				command = new CompositeTransactionalCommand(getEditingDomain(), command.getLabel()).compose(command);
159
			}
160
			return new ICommandProxy(command);
161
		}
162
		return editPolicyCommand;
163
	}
164
165
	/**
166
	 * @generated
167
	 */
168
	protected IElementType getContextElementType(IEditCommandRequest request) {
169
		IElementType requestContextElementType = SysmlElementTypes.getElementType(getVisualID(request));
170
		return requestContextElementType != null ? requestContextElementType : myElementType;
171
	}
172
173
	/**
174
	 * @generated
175
	 */
176
	protected Command getSemanticCommandSwitch(IEditCommandRequest req) {
177
		if(req instanceof CreateRelationshipRequest) {
178
			return getCreateRelationshipCommand((CreateRelationshipRequest)req);
179
		} else if(req instanceof CreateElementRequest) {
180
			return getCreateCommand((CreateElementRequest)req);
181
		} else if(req instanceof ConfigureRequest) {
182
			return getConfigureCommand((ConfigureRequest)req);
183
		} else if(req instanceof DestroyElementRequest) {
184
			return getDestroyElementCommand((DestroyElementRequest)req);
185
		} else if(req instanceof DestroyReferenceRequest) {
186
			return getDestroyReferenceCommand((DestroyReferenceRequest)req);
187
		} else if(req instanceof DuplicateElementsRequest) {
188
			return getDuplicateCommand((DuplicateElementsRequest)req);
189
		} else if(req instanceof GetEditContextRequest) {
190
			return getEditContextCommand((GetEditContextRequest)req);
191
		} else if(req instanceof MoveRequest) {
192
			return getMoveCommand((MoveRequest)req);
193
		} else if(req instanceof ReorientReferenceRelationshipRequest) {
194
			return getReorientReferenceRelationshipCommand((ReorientReferenceRelationshipRequest)req);
195
		} else if(req instanceof ReorientRelationshipRequest) {
196
			return getReorientRelationshipCommand((ReorientRelationshipRequest)req);
197
		} else if(req instanceof SetRequest) {
198
			return getSetCommand((SetRequest)req);
199
		}
200
		return null;
201
	}
202
203
	/**
204
	 * @generated
205
	 */
206
	protected Command getConfigureCommand(ConfigureRequest req) {
207
		return null;
208
	}
209
210
	/**
211
	 * @generated
212
	 */
213
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
214
		return null;
215
	}
216
217
	/**
218
	 * @generated
219
	 */
220
	protected Command getCreateCommand(CreateElementRequest req) {
221
		// check if the type is an extended type, and then create directly the element...
222
		IElementType type = req.getElementType();
223
		if(type instanceof IExtendedHintedElementType) {
224
			IElementEditService provider = ElementEditServiceUtils.getCommandProvider(req.getContainer());
225
			if(provider == null) {
226
				return UnexecutableCommand.INSTANCE;
227
			}
228
229
			// Retrieve create command from the Element Edit service
230
			ICommand createGMFCommand = provider.getEditCommand(req);
231
232
			return getGEFWrapper(createGMFCommand);
233
		}
234
235
		return null;
236
	}
237
238
	/**
239
	 * @generated
240
	 */
241
	protected Command getSetCommand(SetRequest req) {
242
		return null;
243
	}
244
245
	/**
246
	 * @generated
247
	 */
248
	protected Command getEditContextCommand(GetEditContextRequest req) {
249
		return null;
250
	}
251
252
	/**
253
	 * @generated
254
	 */
255
	protected Command getDestroyElementCommand(DestroyElementRequest req) {
256
		return null;
257
	}
258
259
	/**
260
	 * @generated
261
	 */
262
	protected Command getDestroyReferenceCommand(DestroyReferenceRequest req) {
263
		return null;
264
	}
265
266
	/**
267
	 * @generated
268
	 */
269
	protected Command getDuplicateCommand(DuplicateElementsRequest req) {
270
		return null;
271
	}
272
273
	/**
274
	 * @generated
275
	 */
276
	protected Command getMoveCommand(MoveRequest req) {
277
278
		return getGEFWrapper(new MoveElementsCommand(req));
279
280
	}
281
282
	/**
283
	 * @generated
284
	 */
285
	protected Command getReorientReferenceRelationshipCommand(ReorientReferenceRelationshipRequest req) {
286
		return UnexecutableCommand.INSTANCE;
287
	}
288
289
	/**
290
	 * @generated
291
	 */
292
	protected Command getReorientRelationshipCommand(ReorientRelationshipRequest req) {
293
		return UnexecutableCommand.INSTANCE;
294
	}
295
296
	/**
297
	 * @generated
298
	 */
299
	protected final Command getGEFWrapper(ICommand cmd) {
300
		return new ICommandProxy(cmd);
301
	}
302
303
	/**
304
	 * Returns editing domain from the host edit part.
305
	 * 
306
	 * @generated
307
	 */
308
	protected TransactionalEditingDomain getEditingDomain() {
309
		return ((IGraphicalEditPart)getHost()).getEditingDomain();
310
	}
311
312
	/**
313
	 * Clean all shortcuts to the host element from the same diagram
314
	 * 
315
	 * @generated
316
	 */
317
	protected void addDestroyShortcutsCommand(ICompositeCommand cmd, View view) {
318
		assert view.getEAnnotation("Shortcut") == null; //$NON-NLS-1$
319
		for(Iterator it = view.getDiagram().getChildren().iterator(); it.hasNext();) {
320
			View nextView = (View)it.next();
321
			if(nextView.getEAnnotation("Shortcut") == null || !nextView.isSetElement() || nextView.getElement() != view.getElement()) { //$NON-NLS-1$
322
				continue;
323
			}
324
			cmd.add(new DeleteCommand(getEditingDomain(), nextView));
325
		}
326
	}
327
328
	/**
329
	 * @generated
330
	 */
331
	public static LinkConstraints getLinkConstraints() {
332
		LinkConstraints cached = SysmlDiagramEditorPlugin.getInstance().getLinkConstraints();
333
		if(cached == null) {
334
			SysmlDiagramEditorPlugin.getInstance().setLinkConstraints(cached = new LinkConstraints());
335
		}
336
		return cached;
337
	}
338
339
	/**
340
	 * @generated
341
	 */
342
	public static class LinkConstraints {
343
344
		/**
345
		 * @generated
346
		 */
347
		public LinkConstraints() {
348
			// use static method #getLinkConstraints() to access instance
349
		}
350
351
		/**
352
		 * @generated
353
		 */
354
		public boolean canCreateConnector_4001(StructuredClassifier container, ConnectableElement source, ConnectableElement target) {
355
			return canExistConnector_4001(container, null, source, target);
356
		}
357
358
		/**
359
		 * @generated
360
		 */
361
		public boolean canExistConnector_4001(StructuredClassifier container, Connector linkInstance, ConnectableElement source, ConnectableElement target) {
362
			return true;
363
		}
364
365
		/**
366
		 * Connector source and target must have the salme type
367
		 * 
368
		 * @generated NOT
369
		 */
370
		public static boolean canExistConnector_4001(StructuredClassifier container, ConnectableElement source, ConnectableElement target) {
371
			Type sourceType = (source == null) ? null : source.getType();
372
			Type targetType = (target == null) ? null : target.getType();
373
			if(sourceType != null && target == null) {
374
				return true;
375
			}
376
			return (sourceType != null && targetType != null && sourceType.equals(targetType));
377
		}
378
	}
379
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/SysmlTextNonResizableEditPolicy.java (-236 lines)
Lines 1-236 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import java.util.Collections;
17
import java.util.List;
18
19
import org.eclipse.draw2d.ColorConstants;
20
import org.eclipse.draw2d.Figure;
21
import org.eclipse.draw2d.FigureListener;
22
import org.eclipse.draw2d.Graphics;
23
import org.eclipse.draw2d.IFigure;
24
import org.eclipse.draw2d.Label;
25
import org.eclipse.draw2d.RectangleFigure;
26
import org.eclipse.draw2d.geometry.Rectangle;
27
import org.eclipse.gef.GraphicalEditPart;
28
import org.eclipse.gef.handles.MoveHandle;
29
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.NonResizableEditPolicyEx;
30
import org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx;
31
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
32
33
/**
34
 * @generated
35
 */
36
public class SysmlTextNonResizableEditPolicy extends NonResizableEditPolicyEx {
37
38
	/**
39
	 * @generated
40
	 */
41
	private IFigure selectionFeedbackFigure;
42
43
	/**
44
	 * @generated
45
	 */
46
	private IFigure focusFeedbackFigure;
47
48
	/**
49
	 * @generated
50
	 */
51
	private FigureListener hostPositionListener;
52
53
	/**
54
	 * @generated
55
	 */
56
	protected void showPrimarySelection() {
57
		if(getHostFigure() instanceof WrappingLabel) {
58
			((WrappingLabel)getHostFigure()).setSelected(true);
59
			((WrappingLabel)getHostFigure()).setFocus(true);
60
		} else {
61
			showSelection();
62
			showFocus();
63
		}
64
	}
65
66
	/**
67
	 * @generated
68
	 */
69
	protected void showSelection() {
70
		if(getHostFigure() instanceof WrappingLabel) {
71
			((WrappingLabel)getHostFigure()).setSelected(true);
72
			((WrappingLabel)getHostFigure()).setFocus(false);
73
		} else {
74
			hideSelection();
75
			addFeedback(selectionFeedbackFigure = createSelectionFeedbackFigure());
76
			getHostFigure().addFigureListener(getHostPositionListener());
77
			refreshSelectionFeedback();
78
			hideFocus();
79
		}
80
	}
81
82
	/**
83
	 * @generated
84
	 */
85
	protected void hideSelection() {
86
		if(getHostFigure() instanceof WrappingLabel) {
87
			((WrappingLabel)getHostFigure()).setSelected(false);
88
			((WrappingLabel)getHostFigure()).setFocus(false);
89
		} else {
90
			if(selectionFeedbackFigure != null) {
91
				removeFeedback(selectionFeedbackFigure);
92
				getHostFigure().removeFigureListener(getHostPositionListener());
93
				selectionFeedbackFigure = null;
94
			}
95
			hideFocus();
96
		}
97
	}
98
99
	/**
100
	 * @generated
101
	 */
102
	protected void showFocus() {
103
		if(getHostFigure() instanceof WrappingLabel) {
104
			((WrappingLabel)getHostFigure()).setFocus(true);
105
		} else {
106
			hideFocus();
107
			addFeedback(focusFeedbackFigure = createFocusFeedbackFigure());
108
			refreshFocusFeedback();
109
		}
110
	}
111
112
	/**
113
	 * @generated
114
	 */
115
	protected void hideFocus() {
116
		if(getHostFigure() instanceof WrappingLabel) {
117
			((WrappingLabel)getHostFigure()).setFocus(false);
118
		} else {
119
			if(focusFeedbackFigure != null) {
120
				removeFeedback(focusFeedbackFigure);
121
				focusFeedbackFigure = null;
122
			}
123
		}
124
	}
125
126
	/**
127
	 * @generated
128
	 */
129
	protected Rectangle getFeedbackBounds() {
130
		Rectangle bounds;
131
		if(getHostFigure() instanceof Label) {
132
			bounds = ((Label)getHostFigure()).getTextBounds();
133
			bounds.intersect(getHostFigure().getBounds());
134
		} else {
135
			bounds = getHostFigure().getBounds().getCopy();
136
		}
137
		getHostFigure().getParent().translateToAbsolute(bounds);
138
		getFeedbackLayer().translateToRelative(bounds);
139
		return bounds;
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	protected IFigure createSelectionFeedbackFigure() {
146
		if(getHostFigure() instanceof Label) {
147
			Label feedbackFigure = new Label();
148
			feedbackFigure.setOpaque(true);
149
			feedbackFigure.setBackgroundColor(ColorConstants.menuBackgroundSelected);
150
			feedbackFigure.setForegroundColor(ColorConstants.menuForegroundSelected);
151
			return feedbackFigure;
152
		} else {
153
			RectangleFigure feedbackFigure = new RectangleFigure();
154
			feedbackFigure.setFill(false);
155
			return feedbackFigure;
156
		}
157
	}
158
159
	/**
160
	 * @generated
161
	 */
162
	protected IFigure createFocusFeedbackFigure() {
163
		return new Figure() {
164
165
			protected void paintFigure(Graphics graphics) {
166
				graphics.drawFocus(getBounds().getResized(-1, -1));
167
			}
168
		};
169
	}
170
171
	/**
172
	 * @generated
173
	 */
174
	protected void updateLabel(Label target) {
175
		Label source = (Label)getHostFigure();
176
		target.setText(source.getText());
177
		target.setTextAlignment(source.getTextAlignment());
178
		target.setFont(source.getFont());
179
	}
180
181
	/**
182
	 * @generated
183
	 */
184
	protected void refreshSelectionFeedback() {
185
		if(selectionFeedbackFigure != null) {
186
			if(selectionFeedbackFigure instanceof Label) {
187
				updateLabel((Label)selectionFeedbackFigure);
188
				selectionFeedbackFigure.setBounds(getFeedbackBounds());
189
			} else {
190
				selectionFeedbackFigure.setBounds(getFeedbackBounds().expand(5, 5));
191
			}
192
		}
193
	}
194
195
	/**
196
	 * @generated
197
	 */
198
	protected void refreshFocusFeedback() {
199
		if(focusFeedbackFigure != null) {
200
			focusFeedbackFigure.setBounds(getFeedbackBounds());
201
		}
202
	}
203
204
	/**
205
	 * @generated
206
	 */
207
	public void refreshFeedback() {
208
		refreshSelectionFeedback();
209
		refreshFocusFeedback();
210
	}
211
212
	/**
213
	 * @generated
214
	 */
215
	private FigureListener getHostPositionListener() {
216
		if(hostPositionListener == null) {
217
			hostPositionListener = new FigureListener() {
218
219
				public void figureMoved(IFigure source) {
220
					refreshFeedback();
221
				}
222
			};
223
		}
224
		return hostPositionListener;
225
	}
226
227
	/**
228
	 * @generated
229
	 */
230
	protected List createSelectionHandles() {
231
		MoveHandle moveHandle = new MoveHandle((GraphicalEditPart)getHost());
232
		moveHandle.setBorder(null);
233
		moveHandle.setDragTracker(new DragEditPartsTrackerEx(getHost()));
234
		return Collections.singletonList(moveHandle);
235
	}
236
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/edit/policies/SysmlTextSelectionEditPolicy.java (-220 lines)
Lines 1-220 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.edit.policies;
15
16
import org.eclipse.draw2d.ColorConstants;
17
import org.eclipse.draw2d.Figure;
18
import org.eclipse.draw2d.FigureListener;
19
import org.eclipse.draw2d.Graphics;
20
import org.eclipse.draw2d.IFigure;
21
import org.eclipse.draw2d.Label;
22
import org.eclipse.draw2d.RectangleFigure;
23
import org.eclipse.draw2d.geometry.Rectangle;
24
import org.eclipse.gef.editpolicies.SelectionEditPolicy;
25
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
26
27
/**
28
 * @generated
29
 */
30
public class SysmlTextSelectionEditPolicy extends SelectionEditPolicy {
31
32
	/**
33
	 * @generated
34
	 */
35
	private IFigure selectionFeedbackFigure;
36
37
	/**
38
	 * @generated
39
	 */
40
	private IFigure focusFeedbackFigure;
41
42
	/**
43
	 * @generated
44
	 */
45
	private FigureListener hostPositionListener;
46
47
	/**
48
	 * @generated
49
	 */
50
	protected void showPrimarySelection() {
51
		if(getHostFigure() instanceof WrappingLabel) {
52
			((WrappingLabel)getHostFigure()).setSelected(true);
53
			((WrappingLabel)getHostFigure()).setFocus(true);
54
		} else {
55
			showSelection();
56
			showFocus();
57
		}
58
	}
59
60
	/**
61
	 * @generated
62
	 */
63
	protected void showSelection() {
64
		if(getHostFigure() instanceof WrappingLabel) {
65
			((WrappingLabel)getHostFigure()).setSelected(true);
66
			((WrappingLabel)getHostFigure()).setFocus(false);
67
		} else {
68
			hideSelection();
69
			addFeedback(selectionFeedbackFigure = createSelectionFeedbackFigure());
70
			getHostFigure().addFigureListener(getHostPositionListener());
71
			refreshSelectionFeedback();
72
			hideFocus();
73
		}
74
	}
75
76
	/**
77
	 * @generated
78
	 */
79
	protected void hideSelection() {
80
		if(getHostFigure() instanceof WrappingLabel) {
81
			((WrappingLabel)getHostFigure()).setSelected(false);
82
			((WrappingLabel)getHostFigure()).setFocus(false);
83
		} else {
84
			if(selectionFeedbackFigure != null) {
85
				removeFeedback(selectionFeedbackFigure);
86
				getHostFigure().removeFigureListener(getHostPositionListener());
87
				selectionFeedbackFigure = null;
88
			}
89
			hideFocus();
90
		}
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	protected void showFocus() {
97
		if(getHostFigure() instanceof WrappingLabel) {
98
			((WrappingLabel)getHostFigure()).setFocus(true);
99
		} else {
100
			hideFocus();
101
			addFeedback(focusFeedbackFigure = createFocusFeedbackFigure());
102
			refreshFocusFeedback();
103
		}
104
	}
105
106
	/**
107
	 * @generated
108
	 */
109
	protected void hideFocus() {
110
		if(getHostFigure() instanceof WrappingLabel) {
111
			((WrappingLabel)getHostFigure()).setFocus(false);
112
		} else {
113
			if(focusFeedbackFigure != null) {
114
				removeFeedback(focusFeedbackFigure);
115
				focusFeedbackFigure = null;
116
			}
117
		}
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	protected Rectangle getFeedbackBounds() {
124
		Rectangle bounds;
125
		if(getHostFigure() instanceof Label) {
126
			bounds = ((Label)getHostFigure()).getTextBounds();
127
			bounds.intersect(getHostFigure().getBounds());
128
		} else {
129
			bounds = getHostFigure().getBounds().getCopy();
130
		}
131
		getHostFigure().getParent().translateToAbsolute(bounds);
132
		getFeedbackLayer().translateToRelative(bounds);
133
		return bounds;
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected IFigure createSelectionFeedbackFigure() {
140
		if(getHostFigure() instanceof Label) {
141
			Label feedbackFigure = new Label();
142
			feedbackFigure.setOpaque(true);
143
			feedbackFigure.setBackgroundColor(ColorConstants.menuBackgroundSelected);
144
			feedbackFigure.setForegroundColor(ColorConstants.menuForegroundSelected);
145
			return feedbackFigure;
146
		} else {
147
			RectangleFigure feedbackFigure = new RectangleFigure();
148
			feedbackFigure.setFill(false);
149
			return feedbackFigure;
150
		}
151
	}
152
153
	/**
154
	 * @generated
155
	 */
156
	protected IFigure createFocusFeedbackFigure() {
157
		return new Figure() {
158
159
			protected void paintFigure(Graphics graphics) {
160
				graphics.drawFocus(getBounds().getResized(-1, -1));
161
			}
162
		};
163
	}
164
165
	/**
166
	 * @generated
167
	 */
168
	protected void updateLabel(Label target) {
169
		Label source = (Label)getHostFigure();
170
		target.setText(source.getText());
171
		target.setTextAlignment(source.getTextAlignment());
172
		target.setFont(source.getFont());
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	protected void refreshSelectionFeedback() {
179
		if(selectionFeedbackFigure != null) {
180
			if(selectionFeedbackFigure instanceof Label) {
181
				updateLabel((Label)selectionFeedbackFigure);
182
				selectionFeedbackFigure.setBounds(getFeedbackBounds());
183
			} else {
184
				selectionFeedbackFigure.setBounds(getFeedbackBounds().expand(5, 5));
185
			}
186
		}
187
	}
188
189
	/**
190
	 * @generated
191
	 */
192
	protected void refreshFocusFeedback() {
193
		if(focusFeedbackFigure != null) {
194
			focusFeedbackFigure.setBounds(getFeedbackBounds());
195
		}
196
	}
197
198
	/**
199
	 * @generated
200
	 */
201
	public void refreshFeedback() {
202
		refreshSelectionFeedback();
203
		refreshFocusFeedback();
204
	}
205
206
	/**
207
	 * @generated
208
	 */
209
	private FigureListener getHostPositionListener() {
210
		if(hostPositionListener == null) {
211
			hostPositionListener = new FigureListener() {
212
213
				public void figureMoved(IFigure source) {
214
					refreshFeedback();
215
				}
216
			};
217
		}
218
		return hostPositionListener;
219
	}
220
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/figures/CustomBlockPropertyCompositeFigure.java (+24 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.figures;
2
3
import org.eclipse.draw2d.Label;
4
import org.eclipse.papyrus.sysml.diagram.common.figure.BlockPropertyCompositeFigure;
5
6
public class CustomBlockPropertyCompositeFigure extends
7
		BlockPropertyCompositeFigure {
8
9
	@Override
10
	protected void initTagLabel(String value) {
11
		// do nothing: we don't want a two lines element (tag + name)
12
	}
13
	
14
	@Override
15
	public Label getTaggedLabel() {
16
		// return a mock Label
17
		return new Label();
18
	}
19
	
20
	@Override
21
	public void setNameLabelIcon(boolean displayNameLabelIcon) {
22
		getNameLabel().setIcon(null);
23
	}
24
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/figures/ParametricDiagramFrameFigure.java (+17 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2013 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
 *****************************************************************************/
11
package org.eclipse.papyrus.sysml.diagram.parametric.figures;
12
13
import org.eclipse.papyrus.sysml.diagram.common.figure.SysMLDiagramFrameFigure;
14
15
public class ParametricDiagramFrameFigure extends SysMLDiagramFrameFigure {
16
17
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlAbstractNavigatorItem.java (-71 lines)
Lines 1-71 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import org.eclipse.core.runtime.IAdapterFactory;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.core.runtime.PlatformObject;
19
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
20
21
/**
22
 * @generated
23
 */
24
public abstract class SysmlAbstractNavigatorItem extends PlatformObject {
25
26
	/**
27
	 * @generated
28
	 */
29
	static {
30
		final Class[] supportedTypes = new Class[]{ ITabbedPropertySheetPageContributor.class };
31
		final ITabbedPropertySheetPageContributor propertySheetPageContributor = new ITabbedPropertySheetPageContributor() {
32
33
			public String getContributorId() {
34
				return "org.eclipse.papyrus.sysml.diagram.parametric"; //$NON-NLS-1$
35
			}
36
		};
37
		Platform.getAdapterManager().registerAdapters(new IAdapterFactory() {
38
39
			public Object getAdapter(Object adaptableObject, Class adapterType) {
40
				if(adaptableObject instanceof org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlAbstractNavigatorItem && adapterType == ITabbedPropertySheetPageContributor.class) {
41
					return propertySheetPageContributor;
42
				}
43
				return null;
44
			}
45
46
			public Class[] getAdapterList() {
47
				return supportedTypes;
48
			}
49
		}, org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlAbstractNavigatorItem.class);
50
	}
51
52
	/**
53
	 * @generated
54
	 */
55
	private Object myParent;
56
57
	/**
58
	 * @generated
59
	 */
60
	protected SysmlAbstractNavigatorItem(Object parent) {
61
		myParent = parent;
62
	}
63
64
	/**
65
	 * @generated
66
	 */
67
	public Object getParent() {
68
		return myParent;
69
	}
70
71
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlDomainNavigatorContentProvider.java (-230 lines)
Lines 1-230 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import java.util.ArrayList;
17
import java.util.Collection;
18
import java.util.HashMap;
19
import java.util.Iterator;
20
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.emf.common.util.URI;
23
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.resource.Resource;
25
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
26
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
27
import org.eclipse.emf.transaction.TransactionalEditingDomain;
28
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
29
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
30
import org.eclipse.jface.viewers.Viewer;
31
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
32
import org.eclipse.ui.IMemento;
33
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
34
import org.eclipse.ui.navigator.ICommonContentProvider;
35
36
/**
37
 * @generated
38
 */
39
public class SysmlDomainNavigatorContentProvider implements ICommonContentProvider {
40
41
	/**
42
	 * @generated
43
	 */
44
	private AdapterFactoryContentProvider myAdapterFctoryContentProvier;
45
46
	/**
47
	 * @generated
48
	 */
49
	private static final Object[] EMPTY_ARRAY = new Object[0];
50
51
	/**
52
	 * @generated
53
	 */
54
	private Viewer myViewer;
55
56
	/**
57
	 * @generated
58
	 */
59
	private AdapterFactoryEditingDomain myEditingDomain;
60
61
	/**
62
	 * @generated
63
	 */
64
	private WorkspaceSynchronizer myWorkspaceSynchronizer;
65
66
	/**
67
	 * @generated
68
	 */
69
	private Runnable myViewerRefreshRunnable;
70
71
	/**
72
	 * @generated
73
	 */
74
	public SysmlDomainNavigatorContentProvider() {
75
		myAdapterFctoryContentProvier = new AdapterFactoryContentProvider(SysmlDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory());
76
		TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
77
		myEditingDomain = (AdapterFactoryEditingDomain)editingDomain;
78
		myEditingDomain.setResourceToReadOnlyMap(new HashMap() {
79
80
			public Object get(Object key) {
81
				if(!containsKey(key)) {
82
					put(key, Boolean.TRUE);
83
				}
84
				return super.get(key);
85
			}
86
		});
87
		myViewerRefreshRunnable = new Runnable() {
88
89
			public void run() {
90
				if(myViewer != null) {
91
					myViewer.refresh();
92
				}
93
			}
94
		};
95
		myWorkspaceSynchronizer = new WorkspaceSynchronizer(editingDomain, new WorkspaceSynchronizer.Delegate() {
96
97
			public void dispose() {
98
			}
99
100
			public boolean handleResourceChanged(final Resource resource) {
101
				for(Iterator it = myEditingDomain.getResourceSet().getResources().iterator(); it.hasNext();) {
102
					Resource nextResource = (Resource)it.next();
103
					nextResource.unload();
104
				}
105
				if(myViewer != null) {
106
					myViewer.getControl().getDisplay().asyncExec(myViewerRefreshRunnable);
107
				}
108
				return true;
109
			}
110
111
			public boolean handleResourceDeleted(Resource resource) {
112
				for(Iterator it = myEditingDomain.getResourceSet().getResources().iterator(); it.hasNext();) {
113
					Resource nextResource = (Resource)it.next();
114
					nextResource.unload();
115
				}
116
				if(myViewer != null) {
117
					myViewer.getControl().getDisplay().asyncExec(myViewerRefreshRunnable);
118
				}
119
				return true;
120
			}
121
122
			public boolean handleResourceMoved(Resource resource, final URI newURI) {
123
				for(Iterator it = myEditingDomain.getResourceSet().getResources().iterator(); it.hasNext();) {
124
					Resource nextResource = (Resource)it.next();
125
					nextResource.unload();
126
				}
127
				if(myViewer != null) {
128
					myViewer.getControl().getDisplay().asyncExec(myViewerRefreshRunnable);
129
				}
130
				return true;
131
			}
132
		});
133
	}
134
135
	/**
136
	 * @generated
137
	 */
138
	public void dispose() {
139
		myWorkspaceSynchronizer.dispose();
140
		myWorkspaceSynchronizer = null;
141
		myViewerRefreshRunnable = null;
142
		for(Iterator it = myEditingDomain.getResourceSet().getResources().iterator(); it.hasNext();) {
143
			Resource resource = (Resource)it.next();
144
			resource.unload();
145
		}
146
		((TransactionalEditingDomain)myEditingDomain).dispose();
147
		myEditingDomain = null;
148
	}
149
150
	/**
151
	 * @generated
152
	 */
153
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
154
		myViewer = viewer;
155
	}
156
157
	/**
158
	 * @generated
159
	 */
160
	public Object[] getElements(Object inputElement) {
161
		return getChildren(inputElement);
162
	}
163
164
	/**
165
	 * @generated
166
	 */
167
	public void restoreState(IMemento aMemento) {
168
	}
169
170
	/**
171
	 * @generated
172
	 */
173
	public void saveState(IMemento aMemento) {
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	public void init(ICommonContentExtensionSite aConfig) {
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	public Object[] getChildren(Object parentElement) {
186
		if(parentElement instanceof IFile) {
187
			IFile file = (IFile)parentElement;
188
			URI fileURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
189
			Resource resource = myEditingDomain.getResourceSet().getResource(fileURI, true);
190
			return wrapEObjects(myAdapterFctoryContentProvier.getChildren(resource), parentElement);
191
		}
192
193
		if(parentElement instanceof SysmlDomainNavigatorItem) {
194
			return wrapEObjects(myAdapterFctoryContentProvier.getChildren(((SysmlDomainNavigatorItem)parentElement).getEObject()), parentElement);
195
		}
196
		return EMPTY_ARRAY;
197
	}
198
199
	/**
200
	 * @generated
201
	 */
202
	public Object[] wrapEObjects(Object[] objects, Object parentElement) {
203
		Collection result = new ArrayList();
204
		for(int i = 0; i < objects.length; i++) {
205
			if(objects[i] instanceof EObject) {
206
				result.add(new SysmlDomainNavigatorItem((EObject)objects[i], parentElement, myAdapterFctoryContentProvier));
207
			}
208
		}
209
		return result.toArray();
210
	}
211
212
	/**
213
	 * @generated
214
	 */
215
	public Object getParent(Object element) {
216
		if(element instanceof SysmlAbstractNavigatorItem) {
217
			SysmlAbstractNavigatorItem abstractNavigatorItem = (SysmlAbstractNavigatorItem)element;
218
			return abstractNavigatorItem.getParent();
219
		}
220
		return null;
221
	}
222
223
	/**
224
	 * @generated
225
	 */
226
	public boolean hasChildren(Object element) {
227
		return element instanceof IFile || getChildren(element).length > 0;
228
	}
229
230
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlDomainNavigatorItem.java (-119 lines)
Lines 1-119 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import org.eclipse.core.runtime.IAdapterFactory;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.core.runtime.PlatformObject;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.util.EcoreUtil;
21
import org.eclipse.ui.views.properties.IPropertySource;
22
import org.eclipse.ui.views.properties.IPropertySourceProvider;
23
24
/**
25
 * @generated
26
 */
27
public class SysmlDomainNavigatorItem extends PlatformObject {
28
29
	/**
30
	 * @generated
31
	 */
32
	static {
33
		final Class[] supportedTypes = new Class[]{ EObject.class, IPropertySource.class };
34
		Platform.getAdapterManager().registerAdapters(new IAdapterFactory() {
35
36
			public Object getAdapter(Object adaptableObject, Class adapterType) {
37
				if(adaptableObject instanceof org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorItem) {
38
					org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorItem domainNavigatorItem = (org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorItem)adaptableObject;
39
					EObject eObject = domainNavigatorItem.getEObject();
40
					if(adapterType == EObject.class) {
41
						return eObject;
42
					}
43
					if(adapterType == IPropertySource.class) {
44
						return domainNavigatorItem.getPropertySourceProvider().getPropertySource(eObject);
45
					}
46
				}
47
48
				return null;
49
			}
50
51
			public Class[] getAdapterList() {
52
				return supportedTypes;
53
			}
54
		}, org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorItem.class);
55
	}
56
57
	/**
58
	 * @generated
59
	 */
60
	private Object myParent;
61
62
	/**
63
	 * @generated
64
	 */
65
	private EObject myEObject;
66
67
	/**
68
	 * @generated
69
	 */
70
	private IPropertySourceProvider myPropertySourceProvider;
71
72
	/**
73
	 * @generated
74
	 */
75
	public SysmlDomainNavigatorItem(EObject eObject, Object parent, IPropertySourceProvider propertySourceProvider) {
76
		myParent = parent;
77
		myEObject = eObject;
78
		myPropertySourceProvider = propertySourceProvider;
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	public Object getParent() {
85
		return myParent;
86
	}
87
88
	/**
89
	 * @generated
90
	 */
91
	public EObject getEObject() {
92
		return myEObject;
93
	}
94
95
	/**
96
	 * @generated
97
	 */
98
	public IPropertySourceProvider getPropertySourceProvider() {
99
		return myPropertySourceProvider;
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public boolean equals(Object obj) {
106
		if(obj instanceof org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorItem) {
107
			return EcoreUtil.getURI(getEObject()).equals(EcoreUtil.getURI(((org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlDomainNavigatorItem)obj).getEObject()));
108
		}
109
		return super.equals(obj);
110
	}
111
112
	/**
113
	 * @generated
114
	 */
115
	public int hashCode() {
116
		return EcoreUtil.getURI(getEObject()).hashCode();
117
	}
118
119
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlDomainNavigatorLabelProvider.java (-107 lines)
Lines 1-107 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
17
import org.eclipse.jface.viewers.ILabelProviderListener;
18
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
19
import org.eclipse.swt.graphics.Image;
20
import org.eclipse.ui.IMemento;
21
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
22
import org.eclipse.ui.navigator.ICommonLabelProvider;
23
24
/**
25
 * @generated
26
 */
27
public class SysmlDomainNavigatorLabelProvider implements ICommonLabelProvider {
28
29
	/**
30
	 * @generated
31
	 */
32
	private AdapterFactoryLabelProvider myAdapterFactoryLabelProvider = new AdapterFactoryLabelProvider(SysmlDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory());
33
34
	/**
35
	 * @generated
36
	 */
37
	public void init(ICommonContentExtensionSite aConfig) {
38
	}
39
40
	/**
41
	 * @generated
42
	 */
43
	public Image getImage(Object element) {
44
		if(element instanceof SysmlDomainNavigatorItem) {
45
			return myAdapterFactoryLabelProvider.getImage(((SysmlDomainNavigatorItem)element).getEObject());
46
		}
47
		return null;
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	public String getText(Object element) {
54
		if(element instanceof SysmlDomainNavigatorItem) {
55
			return myAdapterFactoryLabelProvider.getText(((SysmlDomainNavigatorItem)element).getEObject());
56
		}
57
		return null;
58
	}
59
60
	/**
61
	 * @generated
62
	 */
63
	public void addListener(ILabelProviderListener listener) {
64
		myAdapterFactoryLabelProvider.addListener(listener);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	public void dispose() {
71
		myAdapterFactoryLabelProvider.dispose();
72
	}
73
74
	/**
75
	 * @generated
76
	 */
77
	public boolean isLabelProperty(Object element, String property) {
78
		return myAdapterFactoryLabelProvider.isLabelProperty(element, property);
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	public void removeListener(ILabelProviderListener listener) {
85
		myAdapterFactoryLabelProvider.removeListener(listener);
86
	}
87
88
	/**
89
	 * @generated
90
	 */
91
	public void restoreState(IMemento aMemento) {
92
	}
93
94
	/**
95
	 * @generated
96
	 */
97
	public void saveState(IMemento aMemento) {
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	public String getDescription(Object anElement) {
104
		return null;
105
	}
106
107
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlNavigatorActionProvider.java (-181 lines)
Lines 1-181 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.emf.common.ui.URIEditorInput;
18
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.resource.Resource;
21
import org.eclipse.emf.ecore.util.EcoreUtil;
22
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
23
import org.eclipse.gmf.runtime.notation.Diagram;
24
import org.eclipse.gmf.runtime.notation.View;
25
import org.eclipse.jface.action.Action;
26
import org.eclipse.jface.action.IMenuManager;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
29
import org.eclipse.papyrus.sysml.diagram.parametric.part.Messages;
30
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditor;
31
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
32
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
33
import org.eclipse.ui.IActionBars;
34
import org.eclipse.ui.IEditorInput;
35
import org.eclipse.ui.IWorkbenchPage;
36
import org.eclipse.ui.PartInitException;
37
import org.eclipse.ui.navigator.CommonActionProvider;
38
import org.eclipse.ui.navigator.ICommonActionConstants;
39
import org.eclipse.ui.navigator.ICommonActionExtensionSite;
40
import org.eclipse.ui.navigator.ICommonViewerWorkbenchSite;
41
import org.eclipse.ui.part.FileEditorInput;
42
43
/**
44
 * @generated
45
 */
46
public class SysmlNavigatorActionProvider extends CommonActionProvider {
47
48
	/**
49
	 * @generated
50
	 */
51
	private boolean myContribute;
52
53
	/**
54
	 * @generated
55
	 */
56
	private OpenDiagramAction myOpenDiagramAction;
57
58
	/**
59
	 * @generated
60
	 */
61
	public void init(ICommonActionExtensionSite aSite) {
62
		super.init(aSite);
63
		if(aSite.getViewSite() instanceof ICommonViewerWorkbenchSite) {
64
			myContribute = true;
65
			makeActions((ICommonViewerWorkbenchSite)aSite.getViewSite());
66
		} else {
67
			myContribute = false;
68
		}
69
	}
70
71
	/**
72
	 * @generated
73
	 */
74
	private void makeActions(ICommonViewerWorkbenchSite viewerSite) {
75
		myOpenDiagramAction = new OpenDiagramAction(viewerSite);
76
	}
77
78
	/**
79
	 * @generated
80
	 */
81
	public void fillActionBars(IActionBars actionBars) {
82
		if(!myContribute) {
83
			return;
84
		}
85
		IStructuredSelection selection = (IStructuredSelection)getContext().getSelection();
86
		myOpenDiagramAction.selectionChanged(selection);
87
		if(myOpenDiagramAction.isEnabled()) {
88
			actionBars.setGlobalActionHandler(ICommonActionConstants.OPEN, myOpenDiagramAction);
89
		}
90
	}
91
92
	/**
93
	 * @generated
94
	 */
95
	public void fillContextMenu(IMenuManager menu) {
96
	}
97
98
	/**
99
	 * @generated
100
	 */
101
	private static class OpenDiagramAction extends Action {
102
103
		/**
104
		 * @generated
105
		 */
106
		private Diagram myDiagram;
107
108
		/**
109
		 * @generated
110
		 */
111
		private ICommonViewerWorkbenchSite myViewerSite;
112
113
		/**
114
		 * @generated
115
		 */
116
		public OpenDiagramAction(ICommonViewerWorkbenchSite viewerSite) {
117
			super(Messages.NavigatorActionProvider_OpenDiagramActionName);
118
			myViewerSite = viewerSite;
119
		}
120
121
		/**
122
		 * @generated
123
		 */
124
		public final void selectionChanged(IStructuredSelection selection) {
125
			myDiagram = null;
126
			if(selection.size() == 1) {
127
				Object selectedElement = selection.getFirstElement();
128
				if(selectedElement instanceof SysmlNavigatorItem) {
129
					selectedElement = ((SysmlNavigatorItem)selectedElement).getView();
130
				} else if(selectedElement instanceof IAdaptable) {
131
					selectedElement = ((IAdaptable)selectedElement).getAdapter(View.class);
132
				}
133
				if(selectedElement instanceof Diagram) {
134
					Diagram diagram = (Diagram)selectedElement;
135
					if(ParametricEditPart.MODEL_ID.equals(SysmlVisualIDRegistry.getModelID(diagram))) {
136
						myDiagram = diagram;
137
					}
138
				}
139
			}
140
			setEnabled(myDiagram != null);
141
		}
142
143
		/**
144
		 * @generated
145
		 */
146
		public void run() {
147
			if(myDiagram == null || myDiagram.eResource() == null) {
148
				return;
149
			}
150
151
			IEditorInput editorInput = getEditorInput(myDiagram);
152
			IWorkbenchPage page = myViewerSite.getPage();
153
			try {
154
				page.openEditor(editorInput, SysmlDiagramEditor.ID);
155
			} catch (PartInitException e) {
156
				SysmlDiagramEditorPlugin.getInstance().logError("Exception while openning diagram", e); //$NON-NLS-1$
157
			}
158
		}
159
160
		/**
161
		 * @generated
162
		 */
163
		private static IEditorInput getEditorInput(Diagram diagram) {
164
			Resource diagramResource = diagram.eResource();
165
			for(EObject nextEObject : diagramResource.getContents()) {
166
				if(nextEObject == diagram) {
167
					return new FileEditorInput(WorkspaceSynchronizer.getFile(diagramResource));
168
				}
169
				if(nextEObject instanceof Diagram) {
170
					break;
171
				}
172
			}
173
			URI uri = EcoreUtil.getURI(diagram);
174
			String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram);
175
			IEditorInput editorInput = new URIEditorInput(uri, editorName);
176
			return editorInput;
177
		}
178
179
	}
180
181
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlNavigatorContentProvider.java (-503 lines)
Lines 1-503 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import java.util.ArrayList;
17
import java.util.Collection;
18
import java.util.Collections;
19
import java.util.HashMap;
20
import java.util.Iterator;
21
22
import org.eclipse.core.resources.IFile;
23
import org.eclipse.emf.common.util.URI;
24
import org.eclipse.emf.ecore.resource.Resource;
25
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
26
import org.eclipse.emf.transaction.TransactionalEditingDomain;
27
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
28
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
29
import org.eclipse.gmf.runtime.notation.Diagram;
30
import org.eclipse.gmf.runtime.notation.Edge;
31
import org.eclipse.gmf.runtime.notation.View;
32
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
34
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
35
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
36
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
37
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart;
38
import org.eclipse.papyrus.sysml.diagram.parametric.part.Messages;
39
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
40
import org.eclipse.ui.IMemento;
41
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
42
import org.eclipse.ui.navigator.ICommonContentProvider;
43
44
/**
45
 * @generated
46
 */
47
public class SysmlNavigatorContentProvider implements ICommonContentProvider {
48
49
	/**
50
	 * @generated
51
	 */
52
	private static final Object[] EMPTY_ARRAY = new Object[0];
53
54
	/**
55
	 * @generated
56
	 */
57
	private Viewer myViewer;
58
59
	/**
60
	 * @generated
61
	 */
62
	private AdapterFactoryEditingDomain myEditingDomain;
63
64
	/**
65
	 * @generated
66
	 */
67
	private WorkspaceSynchronizer myWorkspaceSynchronizer;
68
69
	/**
70
	 * @generated
71
	 */
72
	private Runnable myViewerRefreshRunnable;
73
74
	/**
75
	 * @generated
76
	 */
77
	@SuppressWarnings({ "unchecked", "serial", "rawtypes" })
78
	public SysmlNavigatorContentProvider() {
79
		TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
80
		myEditingDomain = (AdapterFactoryEditingDomain)editingDomain;
81
		myEditingDomain.setResourceToReadOnlyMap(new HashMap() {
82
83
			public Object get(Object key) {
84
				if(!containsKey(key)) {
85
					put(key, Boolean.TRUE);
86
				}
87
				return super.get(key);
88
			}
89
		});
90
		myViewerRefreshRunnable = new Runnable() {
91
92
			public void run() {
93
				if(myViewer != null) {
94
					myViewer.refresh();
95
				}
96
			}
97
		};
98
		myWorkspaceSynchronizer = new WorkspaceSynchronizer(editingDomain, new WorkspaceSynchronizer.Delegate() {
99
100
			public void dispose() {
101
			}
102
103
			public boolean handleResourceChanged(final Resource resource) {
104
				for(Iterator it = myEditingDomain.getResourceSet().getResources().iterator(); it.hasNext();) {
105
					Resource nextResource = (Resource)it.next();
106
					nextResource.unload();
107
				}
108
				if(myViewer != null) {
109
					myViewer.getControl().getDisplay().asyncExec(myViewerRefreshRunnable);
110
				}
111
				return true;
112
			}
113
114
			public boolean handleResourceDeleted(Resource resource) {
115
				for(Iterator it = myEditingDomain.getResourceSet().getResources().iterator(); it.hasNext();) {
116
					Resource nextResource = (Resource)it.next();
117
					nextResource.unload();
118
				}
119
				if(myViewer != null) {
120
					myViewer.getControl().getDisplay().asyncExec(myViewerRefreshRunnable);
121
				}
122
				return true;
123
			}
124
125
			public boolean handleResourceMoved(Resource resource, final URI newURI) {
126
				for(Iterator it = myEditingDomain.getResourceSet().getResources().iterator(); it.hasNext();) {
127
					Resource nextResource = (Resource)it.next();
128
					nextResource.unload();
129
				}
130
				if(myViewer != null) {
131
					myViewer.getControl().getDisplay().asyncExec(myViewerRefreshRunnable);
132
				}
133
				return true;
134
			}
135
		});
136
	}
137
138
	/**
139
	 * 
140
	 * Papyrus Template this method is a modification of gmf code in order to avoid
141
	 * getViewChidreen() method becoming greater than 64kb.
142
	 * 
143
	 * @generated
144
	 **/
145
	private Object[] getViewChildrenForParametricEditPart(View view, Object parentElement) {
146
		Collection result = new ArrayList();
147
		SysmlNavigatorGroup links = new SysmlNavigatorGroup(Messages.NavigatorGroupName_Resource_1000_links, "icons/linksNavigatorGroup.gif", parentElement); //$NON-NLS-1$
148
		Collection connectedViews = getChildrenByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(ConstraintPropertyEditPart.VISUAL_ID));
149
		result.addAll(createNavigatorItems(connectedViews, parentElement, false));
150
		connectedViews = getChildrenByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(PropertyEditPart.VISUAL_ID));
151
		result.addAll(createNavigatorItems(connectedViews, parentElement, false));
152
		connectedViews = getDiagramLinksByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(ConnectorEditPart.VISUAL_ID));
153
		links.addChildren(createNavigatorItems(connectedViews, links, false));
154
		if(!links.isEmpty()) {
155
			result.add(links);
156
		}
157
		return result.toArray();
158
	}
159
160
	/**
161
	 * 
162
	 * Papyrus Template this method is a modification of gmf code in order to avoid
163
	 * getViewChidreen() method becoming greater than 64kb.
164
	 * 
165
	 * @generated
166
	 **/
167
	private Object[] getViewChildrenForConstraintPropertyEditPart(View view, Object parentElement) {
168
		Collection result = new ArrayList();
169
		Collection connectedViews = getChildrenByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(Property2EditPart.VISUAL_ID));
170
		result.addAll(createNavigatorItems(connectedViews, parentElement, false));
171
		return result.toArray();
172
	}
173
174
	/**
175
	 * 
176
	 * Papyrus Template this method is a modification of gmf code in order to avoid
177
	 * getViewChidreen() method becoming greater than 64kb.
178
	 * 
179
	 * @generated
180
	 **/
181
	private Object[] getViewChildrenForPropertyEditPart(View view, Object parentElement) {
182
		Collection result = new ArrayList();
183
		SysmlNavigatorGroup incominglinks = new SysmlNavigatorGroup(Messages.NavigatorGroupName_Property_2005_incominglinks, "icons/incomingLinksNavigatorGroup.gif", parentElement); //$NON-NLS-1$
184
		SysmlNavigatorGroup outgoinglinks = new SysmlNavigatorGroup(Messages.NavigatorGroupName_Property_2005_outgoinglinks, "icons/outgoingLinksNavigatorGroup.gif", parentElement); //$NON-NLS-1$
185
		Collection connectedViews = getIncomingLinksByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(ConnectorEditPart.VISUAL_ID));
186
		incominglinks.addChildren(createNavigatorItems(connectedViews, incominglinks, true));
187
		connectedViews = getOutgoingLinksByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(ConnectorEditPart.VISUAL_ID));
188
		outgoinglinks.addChildren(createNavigatorItems(connectedViews, outgoinglinks, true));
189
		if(!incominglinks.isEmpty()) {
190
			result.add(incominglinks);
191
		}
192
		if(!outgoinglinks.isEmpty()) {
193
			result.add(outgoinglinks);
194
		}
195
		return result.toArray();
196
	}
197
198
	/**
199
	 * 
200
	 * Papyrus Template this method is a modification of gmf code in order to avoid
201
	 * getViewChidreen() method becoming greater than 64kb.
202
	 * 
203
	 * @generated
204
	 **/
205
	private Object[] getViewChildrenForProperty2EditPart(View view, Object parentElement) {
206
		Collection result = new ArrayList();
207
		SysmlNavigatorGroup incominglinks = new SysmlNavigatorGroup(Messages.NavigatorGroupName_Property_3002_incominglinks, "icons/incomingLinksNavigatorGroup.gif", parentElement); //$NON-NLS-1$
208
		SysmlNavigatorGroup outgoinglinks = new SysmlNavigatorGroup(Messages.NavigatorGroupName_Property_3002_outgoinglinks, "icons/outgoingLinksNavigatorGroup.gif", parentElement); //$NON-NLS-1$
209
		Collection connectedViews = getIncomingLinksByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(ConnectorEditPart.VISUAL_ID));
210
		incominglinks.addChildren(createNavigatorItems(connectedViews, incominglinks, true));
211
		connectedViews = getOutgoingLinksByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(ConnectorEditPart.VISUAL_ID));
212
		outgoinglinks.addChildren(createNavigatorItems(connectedViews, outgoinglinks, true));
213
		if(!incominglinks.isEmpty()) {
214
			result.add(incominglinks);
215
		}
216
		if(!outgoinglinks.isEmpty()) {
217
			result.add(outgoinglinks);
218
		}
219
		return result.toArray();
220
	}
221
222
	/**
223
	 * 
224
	 * Papyrus Template this method is a modification of gmf code in order to avoid
225
	 * getViewChidreen() method becoming greater than 64kb.
226
	 * 
227
	 * @generated
228
	 **/
229
	private Object[] getViewChildrenForConnectorEditPart(View view, Object parentElement) {
230
		Collection result = new ArrayList();
231
		SysmlNavigatorGroup target = new SysmlNavigatorGroup(Messages.NavigatorGroupName_Connector_4001_target, "icons/linkTargetNavigatorGroup.gif", parentElement); //$NON-NLS-1$
232
		SysmlNavigatorGroup source = new SysmlNavigatorGroup(Messages.NavigatorGroupName_Connector_4001_source, "icons/linkSourceNavigatorGroup.gif", parentElement); //$NON-NLS-1$
233
		Collection connectedViews = getLinksTargetByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(PropertyEditPart.VISUAL_ID));
234
		target.addChildren(createNavigatorItems(connectedViews, target, true));
235
		connectedViews = getLinksTargetByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(Property2EditPart.VISUAL_ID));
236
		target.addChildren(createNavigatorItems(connectedViews, target, true));
237
		connectedViews = getLinksSourceByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(PropertyEditPart.VISUAL_ID));
238
		source.addChildren(createNavigatorItems(connectedViews, source, true));
239
		connectedViews = getLinksSourceByType(Collections.singleton(view), SysmlVisualIDRegistry.getType(Property2EditPart.VISUAL_ID));
240
		source.addChildren(createNavigatorItems(connectedViews, source, true));
241
		if(!target.isEmpty()) {
242
			result.add(target);
243
		}
244
		if(!source.isEmpty()) {
245
			result.add(source);
246
		}
247
		return result.toArray();
248
	}
249
250
	/**
251
	 * @generated
252
	 */
253
	public void dispose() {
254
		myWorkspaceSynchronizer.dispose();
255
		myWorkspaceSynchronizer = null;
256
		myViewerRefreshRunnable = null;
257
		for(Iterator it = myEditingDomain.getResourceSet().getResources().iterator(); it.hasNext();) {
258
			Resource resource = (Resource)it.next();
259
			resource.unload();
260
		}
261
		((TransactionalEditingDomain)myEditingDomain).dispose();
262
		myEditingDomain = null;
263
	}
264
265
	/**
266
	 * @generated
267
	 */
268
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
269
		myViewer = viewer;
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	public Object[] getElements(Object inputElement) {
276
		return getChildren(inputElement);
277
	}
278
279
	/**
280
	 * @generated
281
	 */
282
	public void restoreState(IMemento aMemento) {
283
	}
284
285
	/**
286
	 * @generated
287
	 */
288
	public void saveState(IMemento aMemento) {
289
	}
290
291
	/**
292
	 * @generated
293
	 */
294
	public void init(ICommonContentExtensionSite aConfig) {
295
	}
296
297
	/**
298
	 * @generated
299
	 */
300
	public Object[] getChildren(Object parentElement) {
301
		if(parentElement instanceof IFile) {
302
			IFile file = (IFile)parentElement;
303
			URI fileURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
304
			Resource resource = myEditingDomain.getResourceSet().getResource(fileURI, true);
305
			Collection result = new ArrayList();
306
			return result.toArray();
307
		}
308
309
		if(parentElement instanceof SysmlNavigatorGroup) {
310
			SysmlNavigatorGroup group = (SysmlNavigatorGroup)parentElement;
311
			return group.getChildren();
312
		}
313
314
		if(parentElement instanceof SysmlNavigatorItem) {
315
			SysmlNavigatorItem navigatorItem = (SysmlNavigatorItem)parentElement;
316
			if(navigatorItem.isLeaf() || !isOwnView(navigatorItem.getView())) {
317
				return EMPTY_ARRAY;
318
			}
319
			return getViewChildren(navigatorItem.getView(), parentElement);
320
		}
321
322
		return EMPTY_ARRAY;
323
	}
324
325
	/**
326
	 * @generated
327
	 */
328
	private Object[] getViewChildren(View view, Object parentElement) {
329
		switch(SysmlVisualIDRegistry.getVisualID(view)) {
330
331
		case ParametricEditPart.VISUAL_ID:
332
		{
333
334
			//modification of the template to avoid mistake of 65kb.
335
			return getViewChildrenForParametricEditPart(view, parentElement);
336
337
		}
338
339
		case Property2EditPart.VISUAL_ID:
340
		{
341
342
			//modification of the template to avoid mistake of 65kb.
343
			return getViewChildrenForProperty2EditPart(view, parentElement);
344
345
		}
346
347
		case ConnectorEditPart.VISUAL_ID:
348
		{
349
350
			//modification of the template to avoid mistake of 65kb.
351
			return getViewChildrenForConnectorEditPart(view, parentElement);
352
353
		}
354
355
		case PropertyEditPart.VISUAL_ID:
356
		{
357
358
			//modification of the template to avoid mistake of 65kb.
359
			return getViewChildrenForPropertyEditPart(view, parentElement);
360
361
		}
362
363
		case ConstraintPropertyEditPart.VISUAL_ID:
364
		{
365
366
			//modification of the template to avoid mistake of 65kb.
367
			return getViewChildrenForConstraintPropertyEditPart(view, parentElement);
368
369
		}
370
371
		}
372
		return EMPTY_ARRAY;
373
	}
374
375
	/**
376
	 * @generated
377
	 */
378
	private Collection getLinksSourceByType(Collection edges, String type) {
379
		Collection result = new ArrayList();
380
		for(Iterator it = edges.iterator(); it.hasNext();) {
381
			Edge nextEdge = (Edge)it.next();
382
			View nextEdgeSource = nextEdge.getSource();
383
			if(type.equals(nextEdgeSource.getType()) && isOwnView(nextEdgeSource)) {
384
				result.add(nextEdgeSource);
385
			}
386
		}
387
		return result;
388
	}
389
390
	/**
391
	 * @generated
392
	 */
393
	private Collection getLinksTargetByType(Collection edges, String type) {
394
		Collection result = new ArrayList();
395
		for(Iterator it = edges.iterator(); it.hasNext();) {
396
			Edge nextEdge = (Edge)it.next();
397
			View nextEdgeTarget = nextEdge.getTarget();
398
			if(type.equals(nextEdgeTarget.getType()) && isOwnView(nextEdgeTarget)) {
399
				result.add(nextEdgeTarget);
400
			}
401
		}
402
		return result;
403
	}
404
405
	/**
406
	 * @generated
407
	 */
408
	private Collection getOutgoingLinksByType(Collection nodes, String type) {
409
		Collection result = new ArrayList();
410
		for(Iterator it = nodes.iterator(); it.hasNext();) {
411
			View nextNode = (View)it.next();
412
			result.addAll(selectViewsByType(nextNode.getSourceEdges(), type));
413
		}
414
		return result;
415
	}
416
417
	/**
418
	 * @generated
419
	 */
420
	private Collection getIncomingLinksByType(Collection nodes, String type) {
421
		Collection result = new ArrayList();
422
		for(Iterator it = nodes.iterator(); it.hasNext();) {
423
			View nextNode = (View)it.next();
424
			result.addAll(selectViewsByType(nextNode.getTargetEdges(), type));
425
		}
426
		return result;
427
	}
428
429
	/**
430
	 * @generated
431
	 */
432
	private Collection getChildrenByType(Collection nodes, String type) {
433
		Collection result = new ArrayList();
434
		for(Iterator it = nodes.iterator(); it.hasNext();) {
435
			View nextNode = (View)it.next();
436
			result.addAll(selectViewsByType(nextNode.getChildren(), type));
437
		}
438
		return result;
439
	}
440
441
	/**
442
	 * @generated
443
	 */
444
	private Collection getDiagramLinksByType(Collection diagrams, String type) {
445
		Collection result = new ArrayList();
446
		for(Iterator it = diagrams.iterator(); it.hasNext();) {
447
			Diagram nextDiagram = (Diagram)it.next();
448
			result.addAll(selectViewsByType(nextDiagram.getEdges(), type));
449
		}
450
		return result;
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	private Collection selectViewsByType(Collection views, String type) {
457
		Collection result = new ArrayList();
458
		for(Iterator it = views.iterator(); it.hasNext();) {
459
			View nextView = (View)it.next();
460
			if(type.equals(nextView.getType()) && isOwnView(nextView)) {
461
				result.add(nextView);
462
			}
463
		}
464
		return result;
465
	}
466
467
	/**
468
	 * @generated
469
	 */
470
	private boolean isOwnView(View view) {
471
		return ParametricEditPart.MODEL_ID.equals(SysmlVisualIDRegistry.getModelID(view));
472
	}
473
474
	/**
475
	 * @generated
476
	 */
477
	private Collection createNavigatorItems(Collection views, Object parent, boolean isLeafs) {
478
		Collection result = new ArrayList();
479
		for(Iterator it = views.iterator(); it.hasNext();) {
480
			result.add(new SysmlNavigatorItem((View)it.next(), parent, isLeafs));
481
		}
482
		return result;
483
	}
484
485
	/**
486
	 * @generated
487
	 */
488
	public Object getParent(Object element) {
489
		if(element instanceof SysmlAbstractNavigatorItem) {
490
			SysmlAbstractNavigatorItem abstractNavigatorItem = (SysmlAbstractNavigatorItem)element;
491
			return abstractNavigatorItem.getParent();
492
		}
493
		return null;
494
	}
495
496
	/**
497
	 * @generated
498
	 */
499
	public boolean hasChildren(Object element) {
500
		return element instanceof IFile || getChildren(element).length > 0;
501
	}
502
503
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlNavigatorGroup.java (-110 lines)
Lines 1-110 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import java.util.Collection;
17
import java.util.LinkedList;
18
19
/**
20
 * @generated
21
 */
22
public class SysmlNavigatorGroup extends SysmlAbstractNavigatorItem {
23
24
	/**
25
	 * @generated
26
	 */
27
	private String myGroupName;
28
29
	/**
30
	 * @generated
31
	 */
32
	private String myIcon;
33
34
	/**
35
	 * @generated
36
	 */
37
	private Collection myChildren = new LinkedList();
38
39
	/**
40
	 * @generated
41
	 */
42
	SysmlNavigatorGroup(String groupName, String icon, Object parent) {
43
		super(parent);
44
		myGroupName = groupName;
45
		myIcon = icon;
46
	}
47
48
	/**
49
	 * @generated
50
	 */
51
	public String getGroupName() {
52
		return myGroupName;
53
	}
54
55
	/**
56
	 * @generated
57
	 */
58
	public String getIcon() {
59
		return myIcon;
60
	}
61
62
	/**
63
	 * @generated
64
	 */
65
	public Object[] getChildren() {
66
		return myChildren.toArray();
67
	}
68
69
	/**
70
	 * @generated
71
	 */
72
	public void addChildren(Collection children) {
73
		myChildren.addAll(children);
74
	}
75
76
	/**
77
	 * @generated
78
	 */
79
	public void addChild(Object child) {
80
		myChildren.add(child);
81
	}
82
83
	/**
84
	 * @generated
85
	 */
86
	public boolean isEmpty() {
87
		return myChildren.size() == 0;
88
	}
89
90
	/**
91
	 * @generated
92
	 */
93
	public boolean equals(Object obj) {
94
		if(obj instanceof org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorGroup) {
95
			org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorGroup anotherGroup = (org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorGroup)obj;
96
			if(getGroupName().equals(anotherGroup.getGroupName())) {
97
				return getParent().equals(anotherGroup.getParent());
98
			}
99
		}
100
		return super.equals(obj);
101
	}
102
103
	/**
104
	 * @generated
105
	 */
106
	public int hashCode() {
107
		return getGroupName().hashCode();
108
	}
109
110
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlNavigatorItem.java (-97 lines)
Lines 1-97 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import org.eclipse.core.runtime.IAdapterFactory;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.util.EcoreUtil;
20
import org.eclipse.gmf.runtime.notation.View;
21
22
/**
23
 * @generated
24
 */
25
public class SysmlNavigatorItem extends SysmlAbstractNavigatorItem {
26
27
	/**
28
	 * @generated
29
	 */
30
	static {
31
		final Class[] supportedTypes = new Class[]{ View.class, EObject.class };
32
		Platform.getAdapterManager().registerAdapters(new IAdapterFactory() {
33
34
			public Object getAdapter(Object adaptableObject, Class adapterType) {
35
				if(adaptableObject instanceof org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorItem && (adapterType == View.class || adapterType == EObject.class)) {
36
					return ((org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorItem)adaptableObject).getView();
37
				}
38
				return null;
39
			}
40
41
			public Class[] getAdapterList() {
42
				return supportedTypes;
43
			}
44
		}, org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorItem.class);
45
	}
46
47
	/**
48
	 * @generated
49
	 */
50
	private View myView;
51
52
	/**
53
	 * @generated
54
	 */
55
	private boolean myLeaf = false;
56
57
	/**
58
	 * @generated
59
	 */
60
	public SysmlNavigatorItem(View view, Object parent, boolean isLeaf) {
61
		super(parent);
62
		myView = view;
63
		myLeaf = isLeaf;
64
	}
65
66
	/**
67
	 * @generated
68
	 */
69
	public View getView() {
70
		return myView;
71
	}
72
73
	/**
74
	 * @generated
75
	 */
76
	public boolean isLeaf() {
77
		return myLeaf;
78
	}
79
80
	/**
81
	 * @generated
82
	 */
83
	public boolean equals(Object obj) {
84
		if(obj instanceof org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorItem) {
85
			return EcoreUtil.getURI(getView()).equals(EcoreUtil.getURI(((org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorItem)obj).getView()));
86
		}
87
		return super.equals(obj);
88
	}
89
90
	/**
91
	 * @generated
92
	 */
93
	public int hashCode() {
94
		return EcoreUtil.getURI(getView()).hashCode();
95
	}
96
97
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlNavigatorLabelProvider.java (-274 lines)
Lines 1-274 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
17
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
18
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.notation.View;
21
import org.eclipse.jface.resource.ImageDescriptor;
22
import org.eclipse.jface.resource.ImageRegistry;
23
import org.eclipse.jface.viewers.ITreePathLabelProvider;
24
import org.eclipse.jface.viewers.LabelProvider;
25
import org.eclipse.jface.viewers.TreePath;
26
import org.eclipse.jface.viewers.ViewerLabel;
27
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
28
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorNameEditPart;
29
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
30
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyNameEditPart;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
32
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
33
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart;
34
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyName2EditPart;
35
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyNameEditPart;
36
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
37
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
38
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
39
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlParserProvider;
40
import org.eclipse.swt.graphics.Image;
41
import org.eclipse.ui.IMemento;
42
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
43
import org.eclipse.ui.navigator.ICommonLabelProvider;
44
45
/**
46
 * @generated
47
 */
48
public class SysmlNavigatorLabelProvider extends LabelProvider implements ICommonLabelProvider, ITreePathLabelProvider {
49
50
	/**
51
	 * @generated
52
	 */
53
	static {
54
		SysmlDiagramEditorPlugin.getInstance().getImageRegistry().put("Navigator?UnknownElement", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
55
		SysmlDiagramEditorPlugin.getInstance().getImageRegistry().put("Navigator?ImageNotFound", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
56
	}
57
58
	/**
59
	 * @generated
60
	 */
61
	public void updateLabel(ViewerLabel label, TreePath elementPath) {
62
		Object element = elementPath.getLastSegment();
63
		if(element instanceof SysmlNavigatorItem && !isOwnView(((SysmlNavigatorItem)element).getView())) {
64
			return;
65
		}
66
		label.setText(getText(element));
67
		label.setImage(getImage(element));
68
	}
69
70
	/**
71
	 * @generated
72
	 */
73
	public Image getImage(Object element) {
74
		if(element instanceof SysmlNavigatorGroup) {
75
			SysmlNavigatorGroup group = (SysmlNavigatorGroup)element;
76
			return SysmlDiagramEditorPlugin.getInstance().getBundledImage(group.getIcon());
77
		}
78
79
		if(element instanceof SysmlNavigatorItem) {
80
			SysmlNavigatorItem navigatorItem = (SysmlNavigatorItem)element;
81
			if(!isOwnView(navigatorItem.getView())) {
82
				return super.getImage(element);
83
			}
84
			return getImage(navigatorItem.getView());
85
		}
86
87
		return super.getImage(element);
88
	}
89
90
	/**
91
	 * @generated
92
	 */
93
	public Image getImage(View view) {
94
		switch(SysmlVisualIDRegistry.getVisualID(view)) {
95
		case ParametricEditPart.VISUAL_ID:
96
			return getImage("Navigator?Diagram?http://www.eclipse.org/papyurs/0.7.0/Resource?Resource", SysmlElementTypes.Resource_1000); //$NON-NLS-1$
97
		case Property2EditPart.VISUAL_ID:
98
			return getImage("Navigator?Node?http://www.eclipse.org/uml2/3.0.0/UML?Property", SysmlElementTypes.Property_3002); //$NON-NLS-1$
99
		case ConnectorEditPart.VISUAL_ID:
100
			return getImage("Navigator?Link?http://www.eclipse.org/uml2/3.0.0/UML?Connector", SysmlElementTypes.Connector_4001); //$NON-NLS-1$
101
		case PropertyEditPart.VISUAL_ID:
102
			return getImage("Navigator?TopLevelNode?http://www.eclipse.org/uml2/3.0.0/UML?Property", SysmlElementTypes.Property_2005); //$NON-NLS-1$
103
		case ConstraintPropertyEditPart.VISUAL_ID:
104
			return getImage("Navigator?TopLevelNode?http://www.eclipse.org/papyrus/0.7.0/SysML/Constraints?ConstraintProperty", SysmlElementTypes.ConstraintProperty_2003); //$NON-NLS-1$
105
		}
106
		return getImage("Navigator?UnknownElement", null); //$NON-NLS-1$
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	private Image getImage(String key, IElementType elementType) {
113
		ImageRegistry imageRegistry = SysmlDiagramEditorPlugin.getInstance().getImageRegistry();
114
		Image image = imageRegistry.get(key);
115
		if(image == null && elementType != null && SysmlElementTypes.isKnownElementType(elementType)) {
116
			image = SysmlElementTypes.getImage(elementType);
117
			imageRegistry.put(key, image);
118
		}
119
120
		if(image == null) {
121
			image = imageRegistry.get("Navigator?ImageNotFound"); //$NON-NLS-1$
122
			imageRegistry.put(key, image);
123
		}
124
		return image;
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	public String getText(Object element) {
131
		if(element instanceof SysmlNavigatorGroup) {
132
			SysmlNavigatorGroup group = (SysmlNavigatorGroup)element;
133
			return group.getGroupName();
134
		}
135
136
		if(element instanceof SysmlNavigatorItem) {
137
			SysmlNavigatorItem navigatorItem = (SysmlNavigatorItem)element;
138
			if(!isOwnView(navigatorItem.getView())) {
139
				return null;
140
			}
141
			return getText(navigatorItem.getView());
142
		}
143
144
		return super.getText(element);
145
	}
146
147
	/**
148
	 * @generated
149
	 */
150
	public String getText(View view) {
151
		if(view.getElement() != null && view.getElement().eIsProxy()) {
152
			return getUnresolvedDomainElementProxyText(view);
153
		}
154
		switch(SysmlVisualIDRegistry.getVisualID(view)) {
155
		case ParametricEditPart.VISUAL_ID:
156
			return getResource_1000Text(view);
157
		case Property2EditPart.VISUAL_ID:
158
			return getProperty_3002Text(view);
159
		case ConnectorEditPart.VISUAL_ID:
160
			return getConnector_4001Text(view);
161
		case PropertyEditPart.VISUAL_ID:
162
			return getProperty_2005Text(view);
163
		case ConstraintPropertyEditPart.VISUAL_ID:
164
			return getConstraintProperty_2003Text(view);
165
		}
166
		return getUnknownElementText(view);
167
	}
168
169
	/**
170
	 * @generated
171
	 */
172
	private String getResource_1000Text(View view) {
173
		return ""; //$NON-NLS-1$
174
	}
175
176
	/**
177
	 * @generated
178
	 */
179
	private String getConstraintProperty_2003Text(View view) {
180
		IParser parser = SysmlParserProvider.getParser(SysmlElementTypes.ConstraintProperty_2003, view.getElement() != null ? view.getElement() : view, SysmlVisualIDRegistry.getType(ConstraintPropertyNameEditPart.VISUAL_ID));
181
		if(parser != null) {
182
			return parser.getPrintString(new EObjectAdapter(view.getElement() != null ? view.getElement() : view), ParserOptions.NONE.intValue());
183
		} else {
184
			SysmlDiagramEditorPlugin.getInstance().logError("Parser was not found for label " + 5001); //$NON-NLS-1$
185
			return ""; //$NON-NLS-1$
186
		}
187
	}
188
189
	/**
190
	 * @generated
191
	 */
192
	private String getProperty_2005Text(View view) {
193
		IParser parser = SysmlParserProvider.getParser(SysmlElementTypes.Property_2005, view.getElement() != null ? view.getElement() : view, SysmlVisualIDRegistry.getType(PropertyNameEditPart.VISUAL_ID));
194
		if(parser != null) {
195
			return parser.getPrintString(new EObjectAdapter(view.getElement() != null ? view.getElement() : view), ParserOptions.NONE.intValue());
196
		} else {
197
			SysmlDiagramEditorPlugin.getInstance().logError("Parser was not found for label " + 5002); //$NON-NLS-1$
198
			return ""; //$NON-NLS-1$
199
		}
200
	}
201
202
	/**
203
	 * @generated
204
	 */
205
	private String getProperty_3002Text(View view) {
206
		IParser parser = SysmlParserProvider.getParser(SysmlElementTypes.Property_3002, view.getElement() != null ? view.getElement() : view, SysmlVisualIDRegistry.getType(PropertyName2EditPart.VISUAL_ID));
207
		if(parser != null) {
208
			return parser.getPrintString(new EObjectAdapter(view.getElement() != null ? view.getElement() : view), ParserOptions.NONE.intValue());
209
		} else {
210
			SysmlDiagramEditorPlugin.getInstance().logError("Parser was not found for label " + 5003); //$NON-NLS-1$
211
			return ""; //$NON-NLS-1$
212
		}
213
	}
214
215
	/**
216
	 * @generated
217
	 */
218
	private String getConnector_4001Text(View view) {
219
		IParser parser = SysmlParserProvider.getParser(SysmlElementTypes.Connector_4001, view.getElement() != null ? view.getElement() : view, SysmlVisualIDRegistry.getType(ConnectorNameEditPart.VISUAL_ID));
220
		if(parser != null) {
221
			return parser.getPrintString(new EObjectAdapter(view.getElement() != null ? view.getElement() : view), ParserOptions.NONE.intValue());
222
		} else {
223
			SysmlDiagramEditorPlugin.getInstance().logError("Parser was not found for label " + 6001); //$NON-NLS-1$
224
			return ""; //$NON-NLS-1$
225
		}
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	private String getUnknownElementText(View view) {
232
		return "<UnknownElement Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$  //$NON-NLS-2$
233
	}
234
235
	/**
236
	 * @generated
237
	 */
238
	private String getUnresolvedDomainElementProxyText(View view) {
239
		return "<Unresolved domain element Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$  //$NON-NLS-2$
240
	}
241
242
	/**
243
	 * @generated
244
	 */
245
	public void init(ICommonContentExtensionSite aConfig) {
246
	}
247
248
	/**
249
	 * @generated
250
	 */
251
	public void restoreState(IMemento aMemento) {
252
	}
253
254
	/**
255
	 * @generated
256
	 */
257
	public void saveState(IMemento aMemento) {
258
	}
259
260
	/**
261
	 * @generated
262
	 */
263
	public String getDescription(Object anElement) {
264
		return null;
265
	}
266
267
	/**
268
	 * @generated
269
	 */
270
	private boolean isOwnView(View view) {
271
		return ParametricEditPart.MODEL_ID.equals(SysmlVisualIDRegistry.getModelID(view));
272
	}
273
274
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlNavigatorLinkHelper.java (-128 lines)
Lines 1-128 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.emf.common.ui.URIEditorInput;
18
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.resource.Resource;
21
import org.eclipse.emf.ecore.resource.ResourceSet;
22
import org.eclipse.emf.ecore.util.EcoreUtil;
23
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
24
import org.eclipse.gef.EditPart;
25
import org.eclipse.gef.GraphicalViewer;
26
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
27
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
28
import org.eclipse.gmf.runtime.notation.Diagram;
29
import org.eclipse.gmf.runtime.notation.View;
30
import org.eclipse.jface.viewers.IStructuredSelection;
31
import org.eclipse.jface.viewers.StructuredSelection;
32
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
33
import org.eclipse.ui.IEditorInput;
34
import org.eclipse.ui.IEditorPart;
35
import org.eclipse.ui.IWorkbenchPage;
36
import org.eclipse.ui.navigator.ILinkHelper;
37
import org.eclipse.ui.part.FileEditorInput;
38
39
/**
40
 * @generated
41
 */
42
public class SysmlNavigatorLinkHelper implements ILinkHelper {
43
44
	/**
45
	 * @generated
46
	 */
47
	private static IEditorInput getEditorInput(Diagram diagram) {
48
		Resource diagramResource = diagram.eResource();
49
		for(EObject nextEObject : diagramResource.getContents()) {
50
			if(nextEObject == diagram) {
51
				return new FileEditorInput(WorkspaceSynchronizer.getFile(diagramResource));
52
			}
53
			if(nextEObject instanceof Diagram) {
54
				break;
55
			}
56
		}
57
		URI uri = EcoreUtil.getURI(diagram);
58
		String editorName = uri.lastSegment() + '#' + diagram.eResource().getContents().indexOf(diagram);
59
		IEditorInput editorInput = new URIEditorInput(uri, editorName);
60
		return editorInput;
61
	}
62
63
	/**
64
	 * @generated
65
	 */
66
	public IStructuredSelection findSelection(IEditorInput anInput) {
67
		IDiagramDocument document = SysmlDiagramEditorPlugin.getInstance().getDocumentProvider().getDiagramDocument(anInput);
68
		if(document == null) {
69
			return StructuredSelection.EMPTY;
70
		}
71
		Diagram diagram = document.getDiagram();
72
		if(diagram == null || diagram.eResource() == null) {
73
			return StructuredSelection.EMPTY;
74
		}
75
		IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
76
		if(file != null) {
77
			SysmlNavigatorItem item = new SysmlNavigatorItem(diagram, file, false);
78
			return new StructuredSelection(item);
79
		}
80
		return StructuredSelection.EMPTY;
81
	}
82
83
	/**
84
	 * @generated
85
	 */
86
	public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
87
		if(aSelection == null || aSelection.isEmpty()) {
88
			return;
89
		}
90
		if(false == aSelection.getFirstElement() instanceof SysmlAbstractNavigatorItem) {
91
			return;
92
		}
93
94
		SysmlAbstractNavigatorItem abstractNavigatorItem = (SysmlAbstractNavigatorItem)aSelection.getFirstElement();
95
		View navigatorView = null;
96
		if(abstractNavigatorItem instanceof SysmlNavigatorItem) {
97
			navigatorView = ((SysmlNavigatorItem)abstractNavigatorItem).getView();
98
		} else if(abstractNavigatorItem instanceof SysmlNavigatorGroup) {
99
			SysmlNavigatorGroup navigatorGroup = (SysmlNavigatorGroup)abstractNavigatorItem;
100
			if(navigatorGroup.getParent() instanceof SysmlNavigatorItem) {
101
				navigatorView = ((SysmlNavigatorItem)navigatorGroup.getParent()).getView();
102
			}
103
		}
104
		if(navigatorView == null) {
105
			return;
106
		}
107
		IEditorInput editorInput = getEditorInput(navigatorView.getDiagram());
108
		IEditorPart editor = aPage.findEditor(editorInput);
109
		if(editor == null) {
110
			return;
111
		}
112
		aPage.bringToTop(editor);
113
		if(editor instanceof DiagramEditor) {
114
			DiagramEditor diagramEditor = (DiagramEditor)editor;
115
			ResourceSet diagramEditorResourceSet = diagramEditor.getEditingDomain().getResourceSet();
116
			EObject selectedView = diagramEditorResourceSet.getEObject(EcoreUtil.getURI(navigatorView), true);
117
			if(selectedView == null) {
118
				return;
119
			}
120
			GraphicalViewer graphicalViewer = (GraphicalViewer)diagramEditor.getAdapter(GraphicalViewer.class);
121
			EditPart selectedEditPart = (EditPart)graphicalViewer.getEditPartRegistry().get(selectedView);
122
			if(selectedEditPart != null) {
123
				graphicalViewer.select(selectedEditPart);
124
			}
125
		}
126
	}
127
128
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/navigator/SysmlNavigatorSorter.java (-40 lines)
Lines 1-40 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.navigator;
15
16
import org.eclipse.jface.viewers.ViewerSorter;
17
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
18
19
/**
20
 * @generated
21
 */
22
public class SysmlNavigatorSorter extends ViewerSorter {
23
24
	/**
25
	 * @generated
26
	 */
27
	private static final int GROUP_CATEGORY = 4003;
28
29
	/**
30
	 * @generated
31
	 */
32
	public int category(Object element) {
33
		if(element instanceof SysmlNavigatorItem) {
34
			SysmlNavigatorItem item = (SysmlNavigatorItem)element;
35
			return SysmlVisualIDRegistry.getVisualID(item.getView());
36
		}
37
		return GROUP_CATEGORY;
38
	}
39
40
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/parser/ParametricFrameParser.java (+22 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.parser;
2
3
import org.eclipse.core.runtime.IAdaptable;
4
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
5
import org.eclipse.papyrus.sysml.constraints.ConstraintBlock;
6
import org.eclipse.papyrus.uml.diagram.common.parser.NamedElementLabelParser;
7
import org.eclipse.uml2.uml.util.UMLUtil;
8
9
public class ParametricFrameParser extends NamedElementLabelParser {
10
11
	@Override
12
	public String getPrintString(IAdaptable element, int flags) {
13
		String elementType = null;
14
		if (element instanceof EObjectAdapter) {
15
			Object realObject = ((EObjectAdapter)element).getRealObject();
16
			if (realObject instanceof org.eclipse.uml2.uml.Class) {
17
				elementType = UMLUtil.getStereotypeApplication(((org.eclipse.uml2.uml.Class)realObject), ConstraintBlock.class) != null ? "ConstraintBlock" : "Block";
18
			}
19
		}
20
		return "par [" + elementType + "] " + super.getPrintString(element, flags);
21
	}
22
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/parsers/AbstractParser.java (-431 lines)
Lines 1-431 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.parsers;
15
16
import java.util.Arrays;
17
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.emf.common.notify.Notification;
20
import org.eclipse.emf.ecore.EAttribute;
21
import org.eclipse.emf.ecore.EClassifier;
22
import org.eclipse.emf.ecore.EDataType;
23
import org.eclipse.emf.ecore.EEnum;
24
import org.eclipse.emf.ecore.EEnumLiteral;
25
import org.eclipse.emf.ecore.EObject;
26
import org.eclipse.emf.transaction.TransactionalEditingDomain;
27
import org.eclipse.emf.transaction.util.TransactionUtil;
28
import org.eclipse.gmf.runtime.common.core.command.ICommand;
29
import org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand;
30
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
31
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
32
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
33
import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
34
import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
35
import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
36
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
37
import org.eclipse.osgi.util.NLS;
38
import org.eclipse.papyrus.sysml.diagram.parametric.part.Messages;
39
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
40
41
/**
42
 * @generated
43
 */
44
public abstract class AbstractParser implements IParser {
45
46
	/**
47
	 * @generated
48
	 */
49
	protected final EAttribute[] features;
50
51
	/**
52
	 * @generated
53
	 */
54
	protected final EAttribute[] editableFeatures;
55
56
	/**
57
	 * @generated
58
	 */
59
	private String viewPattern;
60
61
	/**
62
	 * @generated
63
	 */
64
	private String editorPattern;
65
66
	/**
67
	 * @generated
68
	 */
69
	private String editPattern;
70
71
	/**
72
	 * @generated
73
	 */
74
	public AbstractParser(EAttribute[] features) {
75
		if(features == null || Arrays.asList(features).contains(null)) {
76
			throw new IllegalArgumentException();
77
		}
78
		this.editableFeatures = this.features = features;
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	public AbstractParser(EAttribute[] features, EAttribute[] editableFeatures) {
85
		if(features == null || Arrays.asList(features).contains(null)) {
86
			throw new IllegalArgumentException();
87
		}
88
		this.features = features;
89
		if(editableFeatures == null || Arrays.asList(editableFeatures).contains(null)) {
90
			throw new IllegalArgumentException();
91
		}
92
		this.editableFeatures = editableFeatures;
93
	}
94
95
	/**
96
	 * @generated
97
	 */
98
	public String getViewPattern() {
99
		return viewPattern;
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	public void setViewPattern(String viewPattern) {
106
		this.viewPattern = viewPattern;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	public String getEditorPattern() {
113
		return editorPattern;
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	public void setEditorPattern(String editorPattern) {
120
		this.editorPattern = editorPattern;
121
	}
122
123
	/**
124
	 * @generated
125
	 */
126
	public String getEditPattern() {
127
		return editPattern;
128
	}
129
130
	/**
131
	 * @generated
132
	 */
133
	public void setEditPattern(String editPattern) {
134
		this.editPattern = editPattern;
135
	}
136
137
	/**
138
	 * @generated
139
	 */
140
	public boolean isAffectingEvent(Object event, int flags) {
141
		if(event instanceof Notification) {
142
			return isAffectingFeature(((Notification)event).getFeature());
143
		}
144
		return false;
145
	}
146
147
	/**
148
	 * @generated
149
	 */
150
	protected boolean isAffectingFeature(Object feature) {
151
		for(int i = 0; i < features.length; i++) {
152
			if(features[i] == feature) {
153
				return true;
154
			}
155
		}
156
		return false;
157
	}
158
159
	/**
160
	 * @generated
161
	 */
162
	public IContentAssistProcessor getCompletionProcessor(IAdaptable element) {
163
		return null;
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	protected Object[] getValues(EObject element) {
170
		Object[] values = new Object[features.length];
171
		for(int i = 0; i < features.length; i++) {
172
			values[i] = getValue(element, features[i]);
173
		}
174
		return values;
175
	}
176
177
	/**
178
	 * @generated
179
	 */
180
	protected Object[] getEditableValues(EObject element) {
181
		Object[] values = new Object[editableFeatures.length];
182
		for(int i = 0; i < editableFeatures.length; i++) {
183
			values[i] = getValue(element, editableFeatures[i]);
184
		}
185
		return values;
186
	}
187
188
	/**
189
	 * @generated
190
	 */
191
	protected Object getValue(EObject element, EAttribute feature) {
192
		Object value = element.eGet(feature);
193
		Class iClass = feature.getEAttributeType().getInstanceClass();
194
		if(String.class.equals(iClass)) {
195
			if(value == null) {
196
				value = ""; //$NON-NLS-1$
197
			}
198
		}
199
		return value;
200
	}
201
202
	/**
203
	 * @generated
204
	 */
205
	protected ICommand getParseCommand(IAdaptable adapter, Object[] values, int flags) {
206
		if(values == null || validateNewValues(values).getCode() != IParserEditStatus.EDITABLE) {
207
			return UnexecutableCommand.INSTANCE;
208
		}
209
		EObject element = (EObject)adapter.getAdapter(EObject.class);
210
		TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(element);
211
		if(editingDomain == null) {
212
			return UnexecutableCommand.INSTANCE;
213
		}
214
		CompositeTransactionalCommand command = new CompositeTransactionalCommand(editingDomain, "Set Values"); //$NON-NLS-1$
215
		for(int i = 0; i < values.length; i++) {
216
			command.compose(getModificationCommand(element, editableFeatures[i], values[i]));
217
		}
218
		return command;
219
	}
220
221
	/**
222
	 * @generated
223
	 */
224
	protected ICommand getModificationCommand(EObject element, EAttribute feature, Object value) {
225
		value = getValidNewValue(feature, value);
226
		if(value instanceof InvalidValue) {
227
			return UnexecutableCommand.INSTANCE;
228
		}
229
		SetRequest request = new SetRequest(element, feature, value);
230
		return new SetValueCommand(request);
231
	}
232
233
	/**
234
	 * @generated
235
	 */
236
	protected IParserEditStatus validateNewValues(Object[] values) {
237
		if(values.length != editableFeatures.length) {
238
			return ParserEditStatus.UNEDITABLE_STATUS;
239
		}
240
		for(int i = 0; i < values.length; i++) {
241
			Object value = getValidNewValue(editableFeatures[i], values[i]);
242
			if(value instanceof InvalidValue) {
243
				return new ParserEditStatus(SysmlDiagramEditorPlugin.ID, IParserEditStatus.UNEDITABLE, value.toString());
244
			}
245
		}
246
		return ParserEditStatus.EDITABLE_STATUS;
247
	}
248
249
	/**
250
	 * @generated
251
	 */
252
	protected Object getValidNewValue(EAttribute feature, Object value) {
253
		EClassifier type = feature.getEType();
254
		if(type instanceof EDataType) {
255
			Class iClass = type.getInstanceClass();
256
			if(Boolean.TYPE.equals(iClass)) {
257
				if(value instanceof Boolean) {
258
					// ok
259
				} else if(value instanceof String) {
260
					value = Boolean.valueOf((String)value);
261
				} else {
262
					value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
263
				}
264
			} else if(Character.TYPE.equals(iClass)) {
265
				if(value instanceof Character) {
266
					// ok
267
				} else if(value instanceof String) {
268
					String s = (String)value;
269
					if(s.length() == 0) {
270
						value = null;
271
					} else {
272
						value = new Character(s.charAt(0));
273
					}
274
				} else {
275
					value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
276
				}
277
			} else if(Byte.TYPE.equals(iClass)) {
278
				if(value instanceof Byte) {
279
					// ok
280
				} else if(value instanceof Number) {
281
					value = new Byte(((Number)value).byteValue());
282
				} else if(value instanceof String) {
283
					String s = (String)value;
284
					if(s.length() == 0) {
285
						value = null;
286
					} else {
287
						try {
288
							value = Byte.valueOf(s);
289
						} catch (NumberFormatException nfe) {
290
							value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
291
						}
292
					}
293
				} else {
294
					value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
295
				}
296
			} else if(Short.TYPE.equals(iClass)) {
297
				if(value instanceof Short) {
298
					// ok
299
				} else if(value instanceof Number) {
300
					value = new Short(((Number)value).shortValue());
301
				} else if(value instanceof String) {
302
					String s = (String)value;
303
					if(s.length() == 0) {
304
						value = null;
305
					} else {
306
						try {
307
							value = Short.valueOf(s);
308
						} catch (NumberFormatException nfe) {
309
							value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
310
						}
311
					}
312
				} else {
313
					value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
314
				}
315
			} else if(Integer.TYPE.equals(iClass)) {
316
				if(value instanceof Integer) {
317
					// ok
318
				} else if(value instanceof Number) {
319
					value = new Integer(((Number)value).intValue());
320
				} else if(value instanceof String) {
321
					String s = (String)value;
322
					if(s.length() == 0) {
323
						value = null;
324
					} else {
325
						try {
326
							value = Integer.valueOf(s);
327
						} catch (NumberFormatException nfe) {
328
							value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
329
						}
330
					}
331
				} else {
332
					value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
333
				}
334
			} else if(Long.TYPE.equals(iClass)) {
335
				if(value instanceof Long) {
336
					// ok
337
				} else if(value instanceof Number) {
338
					value = new Long(((Number)value).longValue());
339
				} else if(value instanceof String) {
340
					String s = (String)value;
341
					if(s.length() == 0) {
342
						value = null;
343
					} else {
344
						try {
345
							value = Long.valueOf(s);
346
						} catch (NumberFormatException nfe) {
347
							value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
348
						}
349
					}
350
				} else {
351
					value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
352
				}
353
			} else if(Float.TYPE.equals(iClass)) {
354
				if(value instanceof Float) {
355
					// ok
356
				} else if(value instanceof Number) {
357
					value = new Float(((Number)value).floatValue());
358
				} else if(value instanceof String) {
359
					String s = (String)value;
360
					if(s.length() == 0) {
361
						value = null;
362
					} else {
363
						try {
364
							value = Float.valueOf(s);
365
						} catch (NumberFormatException nfe) {
366
							value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
367
						}
368
					}
369
				} else {
370
					value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
371
				}
372
			} else if(Double.TYPE.equals(iClass)) {
373
				if(value instanceof Double) {
374
					// ok
375
				} else if(value instanceof Number) {
376
					value = new Double(((Number)value).doubleValue());
377
				} else if(value instanceof String) {
378
					String s = (String)value;
379
					if(s.length() == 0) {
380
						value = null;
381
					} else {
382
						try {
383
							value = Double.valueOf(s);
384
						} catch (NumberFormatException nfe) {
385
							value = new InvalidValue(NLS.bind(Messages.AbstractParser_WrongStringConversion, iClass.getName()));
386
						}
387
					}
388
				} else {
389
					value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, iClass.getName()));
390
				}
391
			} else if(type instanceof EEnum) {
392
				if(value instanceof String) {
393
					EEnumLiteral literal = ((EEnum)type).getEEnumLiteralByLiteral((String)value);
394
					if(literal == null) {
395
						value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnknownLiteral, value));
396
					} else {
397
						value = literal.getInstance();
398
					}
399
				} else {
400
					value = new InvalidValue(NLS.bind(Messages.AbstractParser_UnexpectedValueType, String.class.getName()));
401
				}
402
			}
403
		}
404
		return value;
405
	}
406
407
	/**
408
	 * @generated
409
	 */
410
	protected class InvalidValue {
411
412
		/**
413
		 * @generated
414
		 */
415
		private String description;
416
417
		/**
418
		 * @generated
419
		 */
420
		public InvalidValue(String description) {
421
			this.description = description;
422
		}
423
424
		/**
425
		 * @generated
426
		 */
427
		public String toString() {
428
			return description;
429
		}
430
	}
431
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/parsers/MessageFormatParser.java (-202 lines)
Lines 1-202 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.parsers;
15
16
import java.text.FieldPosition;
17
import java.text.MessageFormat;
18
import java.text.ParsePosition;
19
20
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.emf.ecore.EAttribute;
22
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.gmf.runtime.common.core.command.ICommand;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserEditStatus;
25
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus;
26
import org.eclipse.osgi.util.NLS;
27
import org.eclipse.papyrus.sysml.diagram.parametric.part.Messages;
28
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
29
30
/**
31
 * @generated
32
 */
33
public class MessageFormatParser extends AbstractParser {
34
35
	/**
36
	 * @generated
37
	 */
38
	private String defaultPattern;
39
40
	/**
41
	 * @generated
42
	 */
43
	private String defaultEditablePattern;
44
45
	/**
46
	 * @generated
47
	 */
48
	private MessageFormat viewProcessor;
49
50
	/**
51
	 * @generated
52
	 */
53
	private MessageFormat editorProcessor;
54
55
	/**
56
	 * @generated
57
	 */
58
	private MessageFormat editProcessor;
59
60
	/**
61
	 * @generated
62
	 */
63
	public MessageFormatParser(EAttribute[] features) {
64
		super(features);
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	public MessageFormatParser(EAttribute[] features, EAttribute[] editableFeatures) {
71
		super(features, editableFeatures);
72
	}
73
74
	/**
75
	 * @generated
76
	 */
77
	protected String getDefaultPattern() {
78
		if(defaultPattern == null) {
79
			StringBuffer sb = new StringBuffer();
80
			for(int i = 0; i < features.length; i++) {
81
				if(i > 0) {
82
					sb.append(' ');
83
				}
84
				sb.append('{');
85
				sb.append(i);
86
				sb.append('}');
87
			}
88
			defaultPattern = sb.toString();
89
		}
90
		return defaultPattern;
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	public void setViewPattern(String viewPattern) {
97
		super.setViewPattern(viewPattern);
98
		viewProcessor = null;
99
	}
100
101
	/**
102
	 * @generated
103
	 */
104
	public void setEditorPattern(String editorPattern) {
105
		super.setEditorPattern(editorPattern);
106
		editorProcessor = null;
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected MessageFormat getViewProcessor() {
113
		if(viewProcessor == null) {
114
			viewProcessor = new MessageFormat(getViewPattern() == null ? getDefaultPattern() : getViewPattern());
115
		}
116
		return viewProcessor;
117
	}
118
119
	/**
120
	 * @generated
121
	 */
122
	protected MessageFormat getEditorProcessor() {
123
		if(editorProcessor == null) {
124
			editorProcessor = new MessageFormat(getEditorPattern() == null ? getDefaultEditablePattern() : getEditorPattern());
125
		}
126
		return editorProcessor;
127
	}
128
129
	/**
130
	 * @generated
131
	 */
132
	protected String getDefaultEditablePattern() {
133
		if(defaultEditablePattern == null) {
134
			StringBuffer sb = new StringBuffer();
135
			for(int i = 0; i < editableFeatures.length; i++) {
136
				if(i > 0) {
137
					sb.append(' ');
138
				}
139
				sb.append('{');
140
				sb.append(i);
141
				sb.append('}');
142
			}
143
			defaultEditablePattern = sb.toString();
144
		}
145
		return defaultEditablePattern;
146
	}
147
148
	/**
149
	 * @generated
150
	 */
151
	public void setEditPattern(String editPattern) {
152
		super.setEditPattern(editPattern);
153
		editProcessor = null;
154
	}
155
156
	/**
157
	 * @generated
158
	 */
159
	protected MessageFormat getEditProcessor() {
160
		if(editProcessor == null) {
161
			editProcessor = new MessageFormat(getEditPattern() == null ? getDefaultEditablePattern() : getEditPattern());
162
		}
163
		return editProcessor;
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	public String getEditString(IAdaptable adapter, int flags) {
170
		EObject element = (EObject)adapter.getAdapter(EObject.class);
171
		return getEditorProcessor().format(getEditableValues(element), new StringBuffer(), new FieldPosition(0)).toString();
172
	}
173
174
	/**
175
	 * @generated
176
	 */
177
	public IParserEditStatus isValidEditString(IAdaptable adapter, String editString) {
178
		ParsePosition pos = new ParsePosition(0);
179
		Object[] values = getEditProcessor().parse(editString, pos);
180
		if(values == null) {
181
			return new ParserEditStatus(SysmlDiagramEditorPlugin.ID, IParserEditStatus.UNEDITABLE, NLS.bind(Messages.MessageFormatParser_InvalidInputError, new Integer(pos.getErrorIndex())));
182
		}
183
		return validateNewValues(values);
184
	}
185
186
	/**
187
	 * @generated
188
	 */
189
	public ICommand getParseCommand(IAdaptable adapter, String newString, int flags) {
190
		Object[] values = getEditProcessor().parse(newString, new ParsePosition(0));
191
		return getParseCommand(adapter, values, flags);
192
	}
193
194
	/**
195
	 * @generated
196
	 */
197
	public String getPrintString(IAdaptable adapter, int flags) {
198
		EObject element = (EObject)adapter.getAdapter(EObject.class);
199
		return getViewProcessor().format(getValues(element), new StringBuffer(), new FieldPosition(0)).toString();
200
	}
201
202
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/DeleteElementAction.java (-16 lines)
Lines 1-16 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/DiagramEditorContextMenuProvider.java (-62 lines)
Lines 1-62 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.transaction.util.TransactionUtil;
18
import org.eclipse.gef.EditPartViewer;
19
import org.eclipse.gmf.runtime.common.ui.services.action.contributionitem.ContributionItemService;
20
import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
21
import org.eclipse.gmf.runtime.diagram.ui.providers.DiagramContextMenuProvider;
22
import org.eclipse.jface.action.IMenuManager;
23
import org.eclipse.ui.IWorkbenchPart;
24
25
/**
26
 * @generated
27
 */
28
public class DiagramEditorContextMenuProvider extends DiagramContextMenuProvider {
29
30
	/**
31
	 * @generated
32
	 */
33
	private IWorkbenchPart part;
34
35
	/**
36
	 * @generated
37
	 */
38
	public DiagramEditorContextMenuProvider(IWorkbenchPart part, EditPartViewer viewer) {
39
		super(part, viewer);
40
		this.part = part;
41
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	public void buildContextMenu(final IMenuManager menu) {
48
		getViewer().flush();
49
		try {
50
			TransactionUtil.getEditingDomain((EObject)getViewer().getContents().getModel()).runExclusive(new Runnable() {
51
52
				public void run() {
53
					ContributionItemService.getInstance().contributeToPopupMenu(DiagramEditorContextMenuProvider.this, part);
54
					menu.remove(ActionIds.ACTION_DELETE_FROM_MODEL);
55
56
				}
57
			});
58
		} catch (Exception e) {
59
			SysmlDiagramEditorPlugin.getInstance().logError("Error building context menu", e);
60
		}
61
	}
62
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/LoadResourceAction.java (-43 lines)
Lines 1-43 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.core.commands.AbstractHandler;
17
import org.eclipse.core.commands.ExecutionEvent;
18
import org.eclipse.core.commands.ExecutionException;
19
import org.eclipse.emf.transaction.TransactionalEditingDomain;
20
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
21
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.ui.IEditorPart;
23
import org.eclipse.ui.handlers.HandlerUtil;
24
25
/**
26
 * @generated
27
 */
28
public class LoadResourceAction extends AbstractHandler {
29
30
	/**
31
	 * @generated
32
	 */
33
	public Object execute(ExecutionEvent event) throws ExecutionException {
34
		IEditorPart diagramEditor = HandlerUtil.getActiveEditorChecked(event);
35
		Shell shell = diagramEditor.getEditorSite().getShell();
36
		assert diagramEditor instanceof DiagramEditor;
37
		TransactionalEditingDomain editingDomain = ((DiagramEditor)diagramEditor).getEditingDomain();
38
		org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog loadResourceDialog = new org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog(shell, editingDomain);
39
		loadResourceDialog.open();
40
		return null;
41
	}
42
43
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/Messages.java (-367 lines)
Lines 1-367 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.osgi.util.NLS;
17
18
/**
19
 * @generated
20
 */
21
public class Messages extends NLS {
22
23
	/**
24
	 * @generated
25
	 */
26
	static {
27
		NLS.initializeMessages("messages", Messages.class); //$NON-NLS-1$
28
	}
29
30
	/**
31
	 * @generated
32
	 */
33
	private Messages() {
34
	}
35
36
	/**
37
	 * @generated
38
	 */
39
	public static String SysmlCreationWizardTitle;
40
41
	/**
42
	 * @generated
43
	 */
44
	public static String SysmlCreationWizard_DiagramModelFilePageTitle;
45
46
	/**
47
	 * @generated
48
	 */
49
	public static String SysmlCreationWizard_DiagramModelFilePageDescription;
50
51
	/**
52
	 * @generated
53
	 */
54
	public static String SysmlCreationWizard_DomainModelFilePageTitle;
55
56
	/**
57
	 * @generated
58
	 */
59
	public static String SysmlCreationWizard_DomainModelFilePageDescription;
60
61
	/**
62
	 * @generated
63
	 */
64
	public static String SysmlCreationWizardOpenEditorError;
65
66
	/**
67
	 * @generated
68
	 */
69
	public static String SysmlCreationWizardCreationError;
70
71
	/**
72
	 * @generated
73
	 */
74
	public static String SysmlCreationWizardPageExtensionError;
75
76
	/**
77
	 * @generated
78
	 */
79
	public static String SysmlDiagramEditorUtil_OpenModelResourceErrorDialogTitle;
80
81
	/**
82
	 * @generated
83
	 */
84
	public static String SysmlDiagramEditorUtil_OpenModelResourceErrorDialogMessage;
85
86
	/**
87
	 * @generated
88
	 */
89
	public static String SysmlDiagramEditorUtil_CreateDiagramProgressTask;
90
91
	/**
92
	 * @generated
93
	 */
94
	public static String SysmlDiagramEditorUtil_CreateDiagramCommandLabel;
95
96
	/**
97
	 * @generated
98
	 */
99
	public static String SysmlDocumentProvider_isModifiable;
100
101
	/**
102
	 * @generated
103
	 */
104
	public static String SysmlDocumentProvider_handleElementContentChanged;
105
106
	/**
107
	 * @generated
108
	 */
109
	public static String SysmlDocumentProvider_IncorrectInputError;
110
111
	/**
112
	 * @generated
113
	 */
114
	public static String SysmlDocumentProvider_NoDiagramInResourceError;
115
116
	/**
117
	 * @generated
118
	 */
119
	public static String SysmlDocumentProvider_DiagramLoadingError;
120
121
	/**
122
	 * @generated
123
	 */
124
	public static String SysmlDocumentProvider_UnsynchronizedFileSaveError;
125
126
	/**
127
	 * @generated
128
	 */
129
	public static String SysmlDocumentProvider_SaveDiagramTask;
130
131
	/**
132
	 * @generated
133
	 */
134
	public static String SysmlDocumentProvider_SaveNextResourceTask;
135
136
	/**
137
	 * @generated
138
	 */
139
	public static String SysmlDocumentProvider_SaveAsOperation;
140
141
	/**
142
	 * @generated
143
	 */
144
	public static String InitDiagramFile_ResourceErrorDialogTitle;
145
146
	/**
147
	 * @generated
148
	 */
149
	public static String InitDiagramFile_ResourceErrorDialogMessage;
150
151
	/**
152
	 * @generated
153
	 */
154
	public static String InitDiagramFile_WizardTitle;
155
156
	/**
157
	 * @generated
158
	 */
159
	public static String InitDiagramFile_OpenModelFileDialogTitle;
160
161
	/**
162
	 * @generated
163
	 */
164
	public static String SysmlNewDiagramFileWizard_CreationPageName;
165
166
	/**
167
	 * @generated
168
	 */
169
	public static String SysmlNewDiagramFileWizard_CreationPageTitle;
170
171
	/**
172
	 * @generated
173
	 */
174
	public static String SysmlNewDiagramFileWizard_CreationPageDescription;
175
176
	/**
177
	 * @generated
178
	 */
179
	public static String SysmlNewDiagramFileWizard_RootSelectionPageName;
180
181
	/**
182
	 * @generated
183
	 */
184
	public static String SysmlNewDiagramFileWizard_RootSelectionPageTitle;
185
186
	/**
187
	 * @generated
188
	 */
189
	public static String SysmlNewDiagramFileWizard_RootSelectionPageDescription;
190
191
	/**
192
	 * @generated
193
	 */
194
	public static String SysmlNewDiagramFileWizard_RootSelectionPageSelectionTitle;
195
196
	/**
197
	 * @generated
198
	 */
199
	public static String SysmlNewDiagramFileWizard_RootSelectionPageNoSelectionMessage;
200
201
	/**
202
	 * @generated
203
	 */
204
	public static String SysmlNewDiagramFileWizard_RootSelectionPageInvalidSelectionMessage;
205
206
	/**
207
	 * @generated
208
	 */
209
	public static String SysmlNewDiagramFileWizard_InitDiagramCommand;
210
211
	/**
212
	 * @generated
213
	 */
214
	public static String SysmlNewDiagramFileWizard_IncorrectRootError;
215
216
	/**
217
	 * @generated
218
	 */
219
	public static String SysmlDiagramEditor_SavingDeletedFile;
220
221
	/**
222
	 * @generated
223
	 */
224
	public static String SysmlDiagramEditor_SaveAsErrorTitle;
225
226
	/**
227
	 * @generated
228
	 */
229
	public static String SysmlDiagramEditor_SaveAsErrorMessage;
230
231
	/**
232
	 * @generated
233
	 */
234
	public static String SysmlDiagramEditor_SaveErrorTitle;
235
236
	/**
237
	 * @generated
238
	 */
239
	public static String SysmlDiagramEditor_SaveErrorMessage;
240
241
	/**
242
	 * @generated
243
	 */
244
	public static String SysmlElementChooserDialog_SelectModelElementTitle;
245
246
	/**
247
	 * @generated
248
	 */
249
	public static String ModelElementSelectionPageMessage;
250
251
	/**
252
	 * @generated
253
	 */
254
	public static String ValidateActionMessage;
255
256
	/**
257
	 * @generated
258
	 */
259
	public static String createParametric1Group_title;
260
261
	/**
262
	 * @generated
263
	 */
264
	public static String createConstraintProperty1CreationTool_title;
265
266
	/**
267
	 * @generated
268
	 */
269
	public static String createConstraintProperty1CreationTool_desc;
270
271
	/**
272
	 * @generated
273
	 */
274
	public static String createProperty2CreationTool_title;
275
276
	/**
277
	 * @generated
278
	 */
279
	public static String createProperty2CreationTool_desc;
280
281
	/**
282
	 * @generated
283
	 */
284
	public static String createConnector3CreationTool_title;
285
286
	/**
287
	 * @generated
288
	 */
289
	public static String createConnector3CreationTool_desc;
290
291
	/**
292
	 * @generated
293
	 */
294
	public static String CommandName_OpenDiagram;
295
296
	/**
297
	 * @generated
298
	 */
299
	public static String NavigatorGroupName_Resource_1000_links;
300
301
	/**
302
	 * @generated
303
	 */
304
	public static String NavigatorGroupName_Property_2005_incominglinks;
305
306
	/**
307
	 * @generated
308
	 */
309
	public static String NavigatorGroupName_Property_2005_outgoinglinks;
310
311
	/**
312
	 * @generated
313
	 */
314
	public static String NavigatorGroupName_Property_3002_incominglinks;
315
316
	/**
317
	 * @generated
318
	 */
319
	public static String NavigatorGroupName_Property_3002_outgoinglinks;
320
321
	/**
322
	 * @generated
323
	 */
324
	public static String NavigatorGroupName_Connector_4001_target;
325
326
	/**
327
	 * @generated
328
	 */
329
	public static String NavigatorGroupName_Connector_4001_source;
330
331
	/**
332
	 * @generated
333
	 */
334
	public static String NavigatorActionProvider_OpenDiagramActionName;
335
336
	/**
337
	 * @generated
338
	 */
339
	public static String AbstractParser_UnexpectedValueType;
340
341
	/**
342
	 * @generated
343
	 */
344
	public static String AbstractParser_WrongStringConversion;
345
346
	/**
347
	 * @generated
348
	 */
349
	public static String AbstractParser_UnknownLiteral;
350
351
	/**
352
	 * @generated
353
	 */
354
	public static String MessageFormatParser_InvalidInputError;
355
356
	/**
357
	 * @generated
358
	 */
359
	public static String SysmlModelingAssistantProviderTitle;
360
361
	/**
362
	 * @generated
363
	 */
364
	public static String SysmlModelingAssistantProviderMessage;
365
366
	// TODO: put accessor fields manually
367
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/ModelElementSelectionPage.java (-156 lines)
Lines 1-156 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.ecore.util.FeatureMap;
18
import org.eclipse.emf.edit.provider.IWrapperItemProvider;
19
import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
20
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
21
import org.eclipse.jface.viewers.ISelectionChangedListener;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.jface.viewers.SelectionChangedEvent;
24
import org.eclipse.jface.viewers.StructuredSelection;
25
import org.eclipse.jface.viewers.TreeViewer;
26
import org.eclipse.jface.wizard.WizardPage;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.layout.GridData;
29
import org.eclipse.swt.layout.GridLayout;
30
import org.eclipse.swt.widgets.Composite;
31
import org.eclipse.swt.widgets.Label;
32
33
/**
34
 * Wizard page that allows to select element from model.
35
 * 
36
 * @generated
37
 */
38
public class ModelElementSelectionPage extends WizardPage {
39
40
	/**
41
	 * @generated
42
	 */
43
	protected EObject selectedModelElement;
44
45
	/**
46
	 * @generated
47
	 */
48
	private TreeViewer modelViewer;
49
50
	/**
51
	 * @generated
52
	 */
53
	public ModelElementSelectionPage(String pageName) {
54
		super(pageName);
55
	}
56
57
	/**
58
	 * @generated
59
	 */
60
	public EObject getModelElement() {
61
		return selectedModelElement;
62
	}
63
64
	/**
65
	 * @generated
66
	 */
67
	public void setModelElement(EObject modelElement) {
68
		selectedModelElement = modelElement;
69
		if(modelViewer != null) {
70
			if(selectedModelElement != null) {
71
				modelViewer.setInput(selectedModelElement.eResource());
72
				modelViewer.setSelection(new StructuredSelection(selectedModelElement));
73
			} else {
74
				modelViewer.setInput(null);
75
			}
76
			setPageComplete(validatePage());
77
		}
78
	}
79
80
	/**
81
	 * @generated
82
	 */
83
	public void createControl(Composite parent) {
84
		initializeDialogUnits(parent);
85
86
		Composite plate = new Composite(parent, SWT.NONE);
87
		plate.setLayoutData(new GridData(GridData.FILL_BOTH));
88
		GridLayout layout = new GridLayout();
89
		layout.marginWidth = 0;
90
		plate.setLayout(layout);
91
		setControl(plate);
92
93
		Label label = new Label(plate, SWT.NONE);
94
		label.setText(getSelectionTitle());
95
		label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
96
97
		modelViewer = new TreeViewer(plate, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
98
		GridData layoutData = new GridData(GridData.FILL_BOTH);
99
		layoutData.heightHint = 300;
100
		layoutData.widthHint = 300;
101
		modelViewer.getTree().setLayoutData(layoutData);
102
		modelViewer.setContentProvider(new AdapterFactoryContentProvider(SysmlDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()));
103
		modelViewer.setLabelProvider(new AdapterFactoryLabelProvider(SysmlDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()));
104
		if(selectedModelElement != null) {
105
			modelViewer.setInput(selectedModelElement.eResource());
106
			modelViewer.setSelection(new StructuredSelection(selectedModelElement));
107
		}
108
		modelViewer.addSelectionChangedListener(new ISelectionChangedListener() {
109
110
			public void selectionChanged(SelectionChangedEvent event) {
111
				ModelElementSelectionPage.this.updateSelection((IStructuredSelection)event.getSelection());
112
			}
113
		});
114
115
		setPageComplete(validatePage());
116
	}
117
118
	/**
119
	 * Override to provide custom model element description.
120
	 * 
121
	 * @generated
122
	 */
123
	protected String getSelectionTitle() {
124
		return Messages.ModelElementSelectionPageMessage;
125
	}
126
127
	/**
128
	 * @generated
129
	 */
130
	protected void updateSelection(IStructuredSelection selection) {
131
		selectedModelElement = null;
132
		if(selection.size() == 1) {
133
			Object selectedElement = selection.getFirstElement();
134
			if(selectedElement instanceof IWrapperItemProvider) {
135
				selectedElement = ((IWrapperItemProvider)selectedElement).getValue();
136
			}
137
			if(selectedElement instanceof FeatureMap.Entry) {
138
				selectedElement = ((FeatureMap.Entry)selectedElement).getValue();
139
			}
140
			if(selectedElement instanceof EObject) {
141
				selectedModelElement = (EObject)selectedElement;
142
			}
143
		}
144
		setPageComplete(validatePage());
145
	}
146
147
	/**
148
	 * Override to provide specific validation of the selected model element.
149
	 * 
150
	 * @generated
151
	 */
152
	protected boolean validatePage() {
153
		return true;
154
	}
155
156
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlCreationWizard.java (-167 lines)
Lines 1-167 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.lang.reflect.InvocationTargetException;
17
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IProgressMonitor;
20
import org.eclipse.emf.ecore.resource.Resource;
21
import org.eclipse.jface.dialogs.ErrorDialog;
22
import org.eclipse.jface.operation.IRunnableWithProgress;
23
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.jface.wizard.Wizard;
25
import org.eclipse.ui.INewWizard;
26
import org.eclipse.ui.IWorkbench;
27
import org.eclipse.ui.PartInitException;
28
import org.eclipse.ui.actions.WorkspaceModifyOperation;
29
30
/**
31
 * @generated
32
 */
33
public class SysmlCreationWizard extends Wizard implements INewWizard {
34
35
	/**
36
	 * @generated
37
	 */
38
	private IWorkbench workbench;
39
40
	/**
41
	 * @generated
42
	 */
43
	protected IStructuredSelection selection;
44
45
	/**
46
	 * @generated
47
	 */
48
	protected SysmlCreationWizardPage diagramModelFilePage;
49
50
	/**
51
	 * @generated
52
	 */
53
	protected SysmlCreationWizardPage domainModelFilePage;
54
55
	/**
56
	 * @generated
57
	 */
58
	protected Resource diagram;
59
60
	/**
61
	 * @generated
62
	 */
63
	private boolean openNewlyCreatedDiagramEditor = true;
64
65
	/**
66
	 * @generated
67
	 */
68
	public IWorkbench getWorkbench() {
69
		return workbench;
70
	}
71
72
	/**
73
	 * @generated
74
	 */
75
	public IStructuredSelection getSelection() {
76
		return selection;
77
	}
78
79
	/**
80
	 * @generated
81
	 */
82
	public final Resource getDiagram() {
83
		return diagram;
84
	}
85
86
	/**
87
	 * @generated
88
	 */
89
	public final boolean isOpenNewlyCreatedDiagramEditor() {
90
		return openNewlyCreatedDiagramEditor;
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	public void setOpenNewlyCreatedDiagramEditor(boolean openNewlyCreatedDiagramEditor) {
97
		this.openNewlyCreatedDiagramEditor = openNewlyCreatedDiagramEditor;
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	public void init(IWorkbench workbench, IStructuredSelection selection) {
104
		this.workbench = workbench;
105
		this.selection = selection;
106
		setWindowTitle(Messages.SysmlCreationWizardTitle);
107
		setDefaultPageImageDescriptor(SysmlDiagramEditorPlugin.getBundledImageDescriptor("icons/wizban/NewResourceWizard.gif")); //$NON-NLS-1$
108
		setNeedsProgressMonitor(true);
109
	}
110
111
	/**
112
	 * @generated
113
	 */
114
	public void addPages() {
115
		diagramModelFilePage = new SysmlCreationWizardPage("DiagramModelFile", getSelection(), "sysml_diagram"); //$NON-NLS-1$ //$NON-NLS-2$
116
		diagramModelFilePage.setTitle(Messages.SysmlCreationWizard_DiagramModelFilePageTitle);
117
		diagramModelFilePage.setDescription(Messages.SysmlCreationWizard_DiagramModelFilePageDescription);
118
		addPage(diagramModelFilePage);
119
120
		domainModelFilePage = new SysmlCreationWizardPage("DomainModelFile", getSelection(), "sysml") { //$NON-NLS-1$ //$NON-NLS-2$
121
122
			public void setVisible(boolean visible) {
123
				if(visible) {
124
					String fileName = diagramModelFilePage.getFileName();
125
					fileName = fileName.substring(0, fileName.length() - ".sysml_diagram".length()); //$NON-NLS-1$
126
					setFileName(SysmlDiagramEditorUtil.getUniqueFileName(getContainerFullPath(), fileName, "sysml")); //$NON-NLS-1$
127
				}
128
				super.setVisible(visible);
129
			}
130
		};
131
		domainModelFilePage.setTitle(Messages.SysmlCreationWizard_DomainModelFilePageTitle);
132
		domainModelFilePage.setDescription(Messages.SysmlCreationWizard_DomainModelFilePageDescription);
133
		addPage(domainModelFilePage);
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	public boolean performFinish() {
140
		IRunnableWithProgress op = new WorkspaceModifyOperation(null) {
141
142
			protected void execute(IProgressMonitor monitor) throws CoreException, InterruptedException {
143
				diagram = SysmlDiagramEditorUtil.createDiagram(diagramModelFilePage.getURI(), domainModelFilePage.getURI(), monitor);
144
				if(isOpenNewlyCreatedDiagramEditor() && diagram != null) {
145
					try {
146
						SysmlDiagramEditorUtil.openDiagram(diagram);
147
					} catch (PartInitException e) {
148
						ErrorDialog.openError(getContainer().getShell(), Messages.SysmlCreationWizardOpenEditorError, null, e.getStatus());
149
					}
150
				}
151
			}
152
		};
153
		try {
154
			getContainer().run(false, true, op);
155
		} catch (InterruptedException e) {
156
			return false;
157
		} catch (InvocationTargetException e) {
158
			if(e.getTargetException() instanceof CoreException) {
159
				ErrorDialog.openError(getContainer().getShell(), Messages.SysmlCreationWizardCreationError, null, ((CoreException)e.getTargetException()).getStatus());
160
			} else {
161
				SysmlDiagramEditorPlugin.getInstance().logError("Error creating diagram", e.getTargetException()); //$NON-NLS-1$
162
			}
163
			return false;
164
		}
165
		return diagram != null;
166
	}
167
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlCreationWizardPage.java (-96 lines)
Lines 1-96 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.core.runtime.IPath;
17
import org.eclipse.core.runtime.Path;
18
import org.eclipse.emf.common.util.URI;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
23
24
/**
25
 * @generated
26
 */
27
public class SysmlCreationWizardPage extends WizardNewFileCreationPage {
28
29
	/**
30
	 * @generated
31
	 */
32
	private final String fileExtension;
33
34
	/**
35
	 * @generated
36
	 */
37
	public SysmlCreationWizardPage(String pageName, IStructuredSelection selection, String fileExtension) {
38
		super(pageName, selection);
39
		this.fileExtension = fileExtension;
40
	}
41
42
	/**
43
	 * Override to create files with this extension.
44
	 * 
45
	 * @generated
46
	 */
47
	protected String getExtension() {
48
		return fileExtension;
49
	}
50
51
	/**
52
	 * @generated
53
	 */
54
	public URI getURI() {
55
		return URI.createPlatformResourceURI(getFilePath().toString(), false);
56
	}
57
58
	/**
59
	 * @generated
60
	 */
61
	protected IPath getFilePath() {
62
		IPath path = getContainerFullPath();
63
		if(path == null) {
64
			path = new Path(""); //$NON-NLS-1$
65
		}
66
		String fileName = getFileName();
67
		if(fileName != null) {
68
			path = path.append(fileName);
69
		}
70
		return path;
71
	}
72
73
	/**
74
	 * @generated
75
	 */
76
	public void createControl(Composite parent) {
77
		super.createControl(parent);
78
		setFileName(SysmlDiagramEditorUtil.getUniqueFileName(getContainerFullPath(), getFileName(), getExtension()));
79
		setPageComplete(validatePage());
80
	}
81
82
	/**
83
	 * @generated
84
	 */
85
	protected boolean validatePage() {
86
		if(!super.validatePage()) {
87
			return false;
88
		}
89
		String extension = getExtension();
90
		if(extension != null && !getFilePath().toString().endsWith("." + extension)) {
91
			setErrorMessage(NLS.bind(Messages.SysmlCreationWizardPageExtensionError, extension));
92
			return false;
93
		}
94
		return true;
95
	}
96
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlDiagramActionBarContributor.java (-60 lines)
Lines 1-60 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramActionBarContributor;
17
import org.eclipse.jface.action.GroupMarker;
18
import org.eclipse.jface.action.IAction;
19
import org.eclipse.jface.action.IMenuManager;
20
import org.eclipse.ui.IActionBars;
21
import org.eclipse.ui.IWorkbenchActionConstants;
22
import org.eclipse.ui.IWorkbenchPage;
23
24
/**
25
 * @generated
26
 */
27
public class SysmlDiagramActionBarContributor extends DiagramActionBarContributor {
28
29
	/**
30
	 * @generated
31
	 */
32
	protected Class getEditorClass() {
33
		return SysmlDiagramEditor.class;
34
	}
35
36
	/**
37
	 * @generated
38
	 */
39
	protected String getEditorId() {
40
		return SysmlDiagramEditor.ID;
41
	}
42
43
	/**
44
	 * @generated
45
	 */
46
	public void init(IActionBars bars, IWorkbenchPage page) {
47
		super.init(bars, page);
48
		// print preview
49
		IMenuManager fileMenu = bars.getMenuManager().findMenuUsingPath(IWorkbenchActionConstants.M_FILE);
50
		assert fileMenu != null;
51
		fileMenu.remove("pageSetupAction"); //$NON-NLS-1$
52
		IMenuManager editMenu = bars.getMenuManager().findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
53
		assert editMenu != null;
54
		if(editMenu.find("validationGroup") == null) { //$NON-NLS-1$
55
			editMenu.add(new GroupMarker("validationGroup")); //$NON-NLS-1$
56
		}
57
		IAction validateAction = new ValidateAction(page);
58
		editMenu.appendToGroup("validationGroup", validateAction); //$NON-NLS-1$
59
	}
60
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlDiagramEditor.java (-569 lines)
Lines 1-569 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.util.EventObject;
17
18
import org.eclipse.core.commands.operations.IUndoableOperation;
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IMarker;
21
import org.eclipse.core.runtime.IProgressMonitor;
22
import org.eclipse.core.runtime.NullProgressMonitor;
23
import org.eclipse.emf.transaction.TransactionalEditingDomain;
24
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
25
import org.eclipse.gef.GraphicalViewer;
26
import org.eclipse.gef.KeyHandler;
27
import org.eclipse.gef.Tool;
28
import org.eclipse.gef.commands.CommandStackListener;
29
import org.eclipse.gef.palette.PaletteRoot;
30
import org.eclipse.gef.ui.palette.PaletteViewer;
31
import org.eclipse.gef.ui.palette.PaletteViewerProvider;
32
import org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener;
33
import org.eclipse.gmf.runtime.common.core.service.ProviderChangeEvent;
34
import org.eclipse.gmf.runtime.common.ui.services.marker.MarkerNavigationService;
35
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
36
import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds;
37
import org.eclipse.gmf.runtime.diagram.ui.internal.parts.PaletteToolTransferDragSourceListener;
38
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
39
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocumentProvider;
40
import org.eclipse.gmf.runtime.notation.Diagram;
41
import org.eclipse.jface.util.LocalSelectionTransfer;
42
import org.eclipse.jface.viewers.ISelection;
43
import org.eclipse.jface.viewers.StructuredSelection;
44
import org.eclipse.papyrus.infra.gmfdiag.common.GmfMultiDiagramDocumentProvider;
45
import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
46
import org.eclipse.papyrus.infra.core.services.ServiceException;
47
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
48
import org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorItem;
49
import org.eclipse.papyrus.uml.diagram.common.listeners.DropTargetListener;
50
import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPaletteContextMenuProvider;
51
import org.eclipse.papyrus.uml.diagram.common.part.PapyrusPaletteViewer;
52
import org.eclipse.papyrus.uml.diagram.common.part.UmlGmfDiagramEditor;
53
import org.eclipse.papyrus.uml.diagram.common.service.PapyrusPaletteService;
54
import org.eclipse.swt.SWT;
55
import org.eclipse.swt.dnd.TransferData;
56
import org.eclipse.swt.events.KeyEvent;
57
import org.eclipse.swt.events.MouseEvent;
58
import org.eclipse.swt.events.MouseListener;
59
import org.eclipse.swt.widgets.Composite;
60
import org.eclipse.ui.IEditorInput;
61
import org.eclipse.ui.IEditorPart;
62
import org.eclipse.ui.IWorkbenchPart;
63
import org.eclipse.ui.ide.IGotoMarker;
64
import org.eclipse.ui.navigator.resources.ProjectExplorer;
65
import org.eclipse.ui.part.IShowInTargetList;
66
import org.eclipse.ui.part.ShowInContext;
67
68
/**
69
 * @generated
70
 */
71
public class SysmlDiagramEditor extends UmlGmfDiagramEditor implements IProviderChangeListener, IGotoMarker {
72
73
	/**
74
	 * @generated
75
	 */
76
	public static final String ID = "org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorID"; //$NON-NLS-1$
77
78
	/**
79
	 * @generated
80
	 */
81
	public static final String CONTEXT_ID = "org.eclipse.papyrus.sysml.diagram.parametric.ui.diagramContext"; //$NON-NLS-1$
82
83
	/**
84
	 * @generated
85
	 */
86
	private KeyHandler paletteKeyHandler = null;
87
88
	/**
89
	 * @generated
90
	 */
91
	private MouseListener paletteMouseListener = null;
92
93
	/**
94
	 * @generated
95
	 */
96
	private IUndoableOperation savedOperation = null;
97
98
	/**
99
	 * @generated
100
	 */
101
	private TransactionalEditingDomain editingDomain;
102
103
	/**
104
	 * @generated
105
	 */
106
	private IDocumentProvider documentProvider;
107
108
	/**
109
	 * @generated
110
	 */
111
	public SysmlDiagramEditor(ServicesRegistry servicesRegistry, Diagram diagram) throws ServiceException {
112
		super(servicesRegistry, diagram);
113
114
		// adds a listener to the palette service, which reacts to palette customizations
115
		PapyrusPaletteService.getInstance().addProviderChangeListener(this);
116
117
		// Share the same editing provider
118
		editingDomain = servicesRegistry.getService(TransactionalEditingDomain.class);
119
		documentProvider = new GmfMultiDiagramDocumentProvider(editingDomain);
120
121
		// overrides editing domain created by super constructor
122
		setDocumentProvider(documentProvider);
123
124
	}
125
126
	/**
127
	 * @generated
128
	 */
129
	@Override
130
	protected String getContextID() {
131
		return CONTEXT_ID;
132
	}
133
134
	/**
135
	 * @generated
136
	 */
137
	@Override
138
	protected PaletteRoot createPaletteRoot(PaletteRoot existingPaletteRoot) {
139
		PaletteRoot paletteRoot;
140
		if(existingPaletteRoot == null) {
141
			paletteRoot = PapyrusPaletteService.getInstance().createPalette(this, getDefaultPaletteContent());
142
		} else {
143
			PapyrusPaletteService.getInstance().updatePalette(existingPaletteRoot, this, getDefaultPaletteContent());
144
			paletteRoot = existingPaletteRoot;
145
		}
146
		applyCustomizationsToPalette(paletteRoot);
147
		return paletteRoot;
148
	}
149
150
	/**
151
	 * @generated
152
	 */
153
	@Override
154
	protected PreferencesHint getPreferencesHint() {
155
		return SysmlDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
156
	}
157
158
	/**
159
	 * @generated
160
	 */
161
	@Override
162
	public String getContributorId() {
163
		return SysmlDiagramEditorPlugin.ID;
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	@Override
170
	public Object getAdapter(Class type) {
171
		if(type == IShowInTargetList.class) {
172
			return new IShowInTargetList() {
173
174
				public String[] getShowInTargetIds() {
175
					return new String[]{ ProjectExplorer.VIEW_ID };
176
				}
177
			};
178
		}
179
		return super.getAdapter(type);
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	@Override
186
	protected final IDocumentProvider getDocumentProvider(IEditorInput input) {
187
		return documentProvider;
188
	}
189
190
	/**
191
	 * 
192
	 * @see org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor#getKeyHandler()
193
	 * 
194
	 * @return
195
	 * 
196
	 * @generated NOT
197
	 */
198
	@Override
199
	protected KeyHandler getKeyHandler() {
200
		//we remove all keybinding provided by GMF
201
		KeyHandler keyHandler = new KeyHandler();
202
		return keyHandler;
203
	}
204
205
	/**
206
	 * @generated
207
	 */
208
	@Override
209
	public TransactionalEditingDomain getEditingDomain() {
210
		return editingDomain;
211
	}
212
213
	/**
214
	 * @generated
215
	 */
216
	@Override
217
	protected final void setDocumentProvider(IEditorInput input) {
218
		// Already set in the constructor
219
	}
220
221
	/**
222
	 * @generated
223
	 */
224
	public void gotoMarker(IMarker marker) {
225
		MarkerNavigationService.getInstance().gotoMarker(this, marker);
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	@Override
232
	public boolean isSaveAsAllowed() {
233
		return true;
234
	}
235
236
	/**
237
	 * @generated
238
	 */
239
	@Override
240
	public void doSaveAs() {
241
		performSaveAs(new NullProgressMonitor());
242
	}
243
244
	/**
245
	 * @generated
246
	 */
247
	@Override
248
	protected void performSaveAs(IProgressMonitor progressMonitor) {
249
		// Nothing
250
	}
251
252
	/**
253
	 * @generated
254
	 */
255
	@Override
256
	public ShowInContext getShowInContext() {
257
		return new ShowInContext(getEditorInput(), getNavigatorSelection());
258
	}
259
260
	/**
261
	 * @generated
262
	 */
263
	private ISelection getNavigatorSelection() {
264
		IDiagramDocument document = getDiagramDocument();
265
		if(document == null) {
266
			return StructuredSelection.EMPTY;
267
		}
268
		Diagram diagram = document.getDiagram();
269
		if(diagram == null || diagram.eResource() == null) {
270
			return StructuredSelection.EMPTY;
271
		}
272
		IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
273
		if(file != null) {
274
			SysmlNavigatorItem item = new SysmlNavigatorItem(diagram, file, false);
275
			return new StructuredSelection(item);
276
		}
277
		return StructuredSelection.EMPTY;
278
	}
279
280
	/**
281
	 * @generated
282
	 */
283
	@Override
284
	protected void configureGraphicalViewer() {
285
		super.configureGraphicalViewer();
286
		DiagramEditorContextMenuProvider provider = new DiagramEditorContextMenuProvider(this, getDiagramGraphicalViewer());
287
		getDiagramGraphicalViewer().setContextMenu(provider);
288
		getSite().registerContextMenu(ActionIds.DIAGRAM_EDITOR_CONTEXT_MENU, provider, getDiagramGraphicalViewer());
289
	}
290
291
	/**
292
	 * @generated
293
	 */
294
	@Override
295
	protected TransactionalEditingDomain createEditingDomain() {
296
		// Already configured
297
		return editingDomain;
298
	}
299
300
	/**
301
	 * @generated
302
	 */
303
	@Override
304
	protected void configureDiagramEditDomain() {
305
		super.configureDiagramEditDomain();
306
		getDiagramEditDomain().getDiagramCommandStack().addCommandStackListener(new CommandStackListener() {
307
308
			public void commandStackChanged(EventObject event) {
309
				firePropertyChange(IEditorPart.PROP_DIRTY);
310
			}
311
		});
312
	}
313
314
	/**
315
	 * @generated
316
	 */
317
	@Override
318
	public void doSave(IProgressMonitor progressMonitor) {
319
		// The saving of the resource is done by the CoreMultiDiagramEditor
320
		savedOperation = getOperationHistory().getUndoOperation(getUndoContext());
321
	}
322
323
	/**
324
	 * @generated
325
	 */
326
	@Override
327
	public boolean isDirty() {
328
		IUndoableOperation op = getOperationHistory().getUndoOperation(getUndoContext());
329
		return savedOperation != op;
330
	}
331
332
	/**
333
	 * @generated
334
	 */
335
	public void providerChanged(ProviderChangeEvent event) {
336
		// update the palette if the palette service has changed
337
		if(PapyrusPaletteService.getInstance().equals(event.getSource())) {
338
			PapyrusPaletteService.getInstance().updatePalette(getPaletteViewer().getPaletteRoot(), this, getDefaultPaletteContent());
339
		}
340
	}
341
342
	/**
343
	 * @generated
344
	 */
345
	@Override
346
	public void dispose() {
347
		// remove palette service listener
348
		// remove preference listener
349
		PapyrusPaletteService.getInstance().removeProviderChangeListener(this);
350
351
		super.dispose();
352
	}
353
354
	/**
355
	 * @generated
356
	 */
357
	protected PaletteViewer getPaletteViewer() {
358
		return getEditDomain().getPaletteViewer();
359
	}
360
361
	/**
362
	 * @generated
363
	 */
364
	@Override
365
	protected PaletteViewer constructPaletteViewer() {
366
		return new PapyrusPaletteViewer();
367
	}
368
369
	/**
370
	 * @generated
371
	 */
372
	@Override
373
	protected PaletteViewerProvider createPaletteViewerProvider() {
374
		getEditDomain().setPaletteRoot(createPaletteRoot(null));
375
		return new PaletteViewerProvider(getEditDomain()) {
376
377
			/**
378
			 * Override to provide the additional behavior for the tools. Will intialize with a
379
			 * PaletteEditPartFactory that has a TrackDragger that understand how to handle the
380
			 * mouseDoubleClick event for shape creation tools. Also will initialize the palette
381
			 * with a defaultTool that is the SelectToolEx that undestands how to handle the enter
382
			 * key which will result in the creation of the shape also.
383
			 */
384
			protected void configurePaletteViewer(PaletteViewer viewer) {
385
				super.configurePaletteViewer(viewer);
386
387
				// customize menu...
388
				viewer.setContextMenu(new PapyrusPaletteContextMenuProvider(viewer));
389
390
				viewer.getKeyHandler().setParent(getPaletteKeyHandler());
391
				viewer.getControl().addMouseListener(getPaletteMouseListener());
392
393
				// Add a transfer drag target listener that is supported on
394
				// palette template entries whose template is a creation tool.
395
				// This will enable drag and drop of the palette shape creation
396
				// tools.
397
				viewer.addDragSourceListener(new PaletteToolTransferDragSourceListener(viewer));
398
				viewer.setCustomizer(createPaletteCustomizer());
399
			}
400
401
			public PaletteViewer createPaletteViewer(Composite parent) {
402
				PaletteViewer pViewer = constructPaletteViewer();
403
				pViewer.createControl(parent);
404
				configurePaletteViewer(pViewer);
405
				hookPaletteViewer(pViewer);
406
				return pViewer;
407
			}
408
409
			/**
410
			 * @return Palette Key Handler for the palette
411
			 */
412
			private KeyHandler getPaletteKeyHandler() {
413
414
				if(paletteKeyHandler == null) {
415
416
					paletteKeyHandler = new KeyHandler() {
417
418
						/**
419
						 * Processes a <i>key released </i> event. This method is called by the Tool
420
						 * whenever a key is released, and the Tool is in the proper state. Override
421
						 * to support pressing the enter key to create a shape or connection
422
						 * (between two selected shapes)
423
						 * 
424
						 * @param event
425
						 *        the KeyEvent
426
						 * @return <code>true</code> if KeyEvent was handled in some way
427
						 */
428
						public boolean keyReleased(KeyEvent event) {
429
430
							if(event.keyCode == SWT.Selection) {
431
432
								Tool tool = getPaletteViewer().getActiveTool().createTool();
433
434
								if(toolSupportsAccessibility(tool)) {
435
436
									tool.keyUp(event, getDiagramGraphicalViewer());
437
438
									// deactivate current selection
439
									getPaletteViewer().setActiveTool(null);
440
441
									return true;
442
								}
443
444
							}
445
							return super.keyReleased(event);
446
						}
447
448
					};
449
450
				}
451
				return paletteKeyHandler;
452
			}
453
454
			/**
455
			 * @return Palette Mouse listener for the palette
456
			 */
457
			private MouseListener getPaletteMouseListener() {
458
459
				if(paletteMouseListener == null) {
460
461
					paletteMouseListener = new MouseListener() {
462
463
						/**
464
						 * Flag to indicate that the current active tool should be cleared after a
465
						 * mouse double-click event.
466
						 */
467
						private boolean clearActiveTool = false;
468
469
						/**
470
						 * Override to support double-clicking a palette tool entry to create a
471
						 * shape or connection (between two selected shapes).
472
						 * 
473
						 * @see MouseListener#mouseDoubleClick(MouseEvent)
474
						 */
475
						public void mouseDoubleClick(MouseEvent e) {
476
							Tool tool = getPaletteViewer().getActiveTool().createTool();
477
478
							if(toolSupportsAccessibility(tool)) {
479
480
								tool.setViewer(getDiagramGraphicalViewer());
481
								tool.setEditDomain(getDiagramGraphicalViewer().getEditDomain());
482
								tool.mouseDoubleClick(e, getDiagramGraphicalViewer());
483
484
								// Current active tool should be deactivated,
485
								// but if it is down here it will get
486
								// reactivated deep in GEF palette code after
487
								// receiving mouse up events.
488
								clearActiveTool = true;
489
							}
490
						}
491
492
						public void mouseDown(MouseEvent e) {
493
							// do nothing
494
						}
495
496
						public void mouseUp(MouseEvent e) {
497
							// Deactivate current active tool here if a
498
							// double-click was handled.
499
							if(clearActiveTool) {
500
								getPaletteViewer().setActiveTool(null);
501
								clearActiveTool = false;
502
							}
503
504
						}
505
					};
506
507
				}
508
				return paletteMouseListener;
509
			}
510
511
		};
512
	}
513
514
	/**
515
	 * @generated
516
	 */
517
	@Override
518
	public GraphicalViewer getGraphicalViewer() {
519
		return super.getGraphicalViewer();
520
	}
521
522
	/**
523
	 * @generated
524
	 */
525
	@Override
526
	protected void initializeGraphicalViewer() {
527
		super.initializeGraphicalViewer();
528
529
		// Enable Drop
530
		getDiagramGraphicalViewer().addDropTargetListener(new DropTargetListener(getDiagramGraphicalViewer(), LocalSelectionTransfer.getTransfer()) {
531
532
			@Override
533
			protected Object getJavaObject(TransferData data) {
534
				return LocalSelectionTransfer.getTransfer().nativeToJava(data);
535
			}
536
537
			@Override
538
			protected TransactionalEditingDomain getTransactionalEditingDomain() {
539
				return getEditingDomain();
540
			}
541
		});
542
543
	}
544
545
	/**
546
	 * @generated
547
	 */
548
	@Override
549
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
550
		if(getSite().getPage().getActiveEditor() instanceof IMultiDiagramEditor) {
551
			IMultiDiagramEditor editor = (IMultiDiagramEditor)getSite().getPage().getActiveEditor();
552
			// If not the active editor, ignore selection changed.
553
			if(this.equals(editor.getActiveEditor())) {
554
				updateActions(getSelectionActions());
555
				super.selectionChanged(part, selection);
556
			} else {
557
				super.selectionChanged(part, selection);
558
			}
559
		} else {
560
			super.selectionChanged(part, selection);
561
		}
562
		// from
563
		// org.eclipse.gmf.runtime.diagram.ui.resources.editor.parts.DiagramDocumentEditor.selectionChanged(IWorkbenchPart,
564
		// ISelection)
565
		if(part == this) {
566
			rebuildStatusLine();
567
		}
568
	}
569
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlDiagramEditorPlugin.java (-333 lines)
Lines 1-333 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.util.ArrayList;
17
import java.util.List;
18
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Path;
22
import org.eclipse.core.runtime.Platform;
23
import org.eclipse.core.runtime.Status;
24
import org.eclipse.emf.common.notify.AdapterFactory;
25
import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory;
26
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
27
import org.eclipse.emf.edit.provider.IItemLabelProvider;
28
import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
29
import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry;
30
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
31
import org.eclipse.jface.preference.IPreferenceStore;
32
import org.eclipse.jface.resource.ImageDescriptor;
33
import org.eclipse.papyrus.infra.gmfdiag.preferences.Activator;
34
import org.eclipse.papyrus.resource.provider.ResourceItemProviderAdapterFactory;
35
import org.eclipse.papyrus.sysml.activities.provider.ActivitiesItemProviderAdapterFactory;
36
import org.eclipse.papyrus.sysml.allocations.provider.AllocationsItemProviderAdapterFactory;
37
import org.eclipse.papyrus.sysml.blocks.provider.BlocksItemProviderAdapterFactory;
38
import org.eclipse.papyrus.sysml.constraints.provider.ConstraintsItemProviderAdapterFactory;
39
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policies.SysmlBaseItemSemanticEditPolicy;
40
import org.eclipse.papyrus.sysml.diagram.parametric.preferences.DiagramPreferenceInitializer;
41
import org.eclipse.papyrus.sysml.diagram.parametric.providers.ElementInitializers;
42
import org.eclipse.papyrus.sysml.modelelements.provider.ModelelementsItemProviderAdapterFactory;
43
import org.eclipse.papyrus.sysml.portandflows.provider.PortandflowsItemProviderAdapterFactory;
44
import org.eclipse.papyrus.sysml.requirements.provider.RequirementsItemProviderAdapterFactory;
45
import org.eclipse.papyrus.uml.standard.provider.StandardItemProviderAdapterFactory;
46
import org.eclipse.swt.graphics.Image;
47
import org.eclipse.ui.plugin.AbstractUIPlugin;
48
import org.eclipse.uml2.uml.edit.providers.UMLItemProviderAdapterFactory;
49
import org.osgi.framework.BundleContext;
50
51
/**
52
 * @generated
53
 */
54
public class SysmlDiagramEditorPlugin extends AbstractUIPlugin {
55
56
	/**
57
	 * @generated
58
	 */
59
	public static final String ID = "org.eclipse.papyrus.sysml.diagram.parametric"; //$NON-NLS-1$
60
61
	/**
62
	 * @generated
63
	 */
64
	public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint(ID);
65
66
	/**
67
	 * @generated
68
	 */
69
	private static SysmlDiagramEditorPlugin instance;
70
71
	/**
72
	 * @generated
73
	 */
74
	private ComposedAdapterFactory adapterFactory;
75
76
	/**
77
	 * @generated
78
	 */
79
	private SysmlDocumentProvider documentProvider;
80
81
	/**
82
	 * @generated
83
	 */
84
	private SysmlBaseItemSemanticEditPolicy.LinkConstraints linkConstraints;
85
86
	/**
87
	 * @generated
88
	 */
89
	private ElementInitializers initializers;
90
91
	/**
92
	 * @generated
93
	 */
94
	public SysmlDiagramEditorPlugin() {
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	public void start(BundleContext context) throws Exception {
101
		super.start(context);
102
		instance = this;
103
		PreferencesHint.registerPreferenceStore(DIAGRAM_PREFERENCES_HINT, getPreferenceStore());
104
		adapterFactory = createAdapterFactory();
105
		DiagramPreferenceInitializer diagramPreferenceInitializer = new DiagramPreferenceInitializer();
106
		diagramPreferenceInitializer.initializeDefaultPreferences();
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	public void stop(BundleContext context) throws Exception {
113
		adapterFactory.dispose();
114
		adapterFactory = null;
115
		linkConstraints = null;
116
		initializers = null;
117
		instance = null;
118
		super.stop(context);
119
	}
120
121
	/**
122
	 * @generated
123
	 */
124
	public static SysmlDiagramEditorPlugin getInstance() {
125
		return instance;
126
	}
127
128
	/**
129
	 * @generated
130
	 */
131
	public IPreferenceStore getPreferenceStore() {
132
		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
133
		return store;
134
	}
135
136
	/**
137
	 * @generated
138
	 */
139
	protected ComposedAdapterFactory createAdapterFactory() {
140
		ArrayList<AdapterFactory> factories = new ArrayList<AdapterFactory>();
141
		fillItemProviderFactories(factories);
142
		return new ComposedAdapterFactory(factories);
143
	}
144
145
	/**
146
	 * @generated NOT
147
	 */
148
	protected void fillItemProviderFactories(List factories) {
149
		// factories.add(new SysmlItemProviderAdapterFactory());
150
		factories.add(new ModelelementsItemProviderAdapterFactory());
151
		factories.add(new BlocksItemProviderAdapterFactory());
152
		factories.add(new PortandflowsItemProviderAdapterFactory());
153
		factories.add(new ConstraintsItemProviderAdapterFactory());
154
		factories.add(new ActivitiesItemProviderAdapterFactory());
155
		factories.add(new AllocationsItemProviderAdapterFactory());
156
		factories.add(new RequirementsItemProviderAdapterFactory());
157
		// factories.add(new InteractionsItemProviderAdapterFactory());
158
		// factories.add(new StatemachinesItemProviderAdapterFactory());
159
		// factories.add(new UsecasesItemProviderAdapterFactory());
160
		factories.add(new EcoreItemProviderAdapterFactory());
161
		factories.add(new StandardItemProviderAdapterFactory());
162
		factories.add(new UMLItemProviderAdapterFactory());
163
		factories.add(new ResourceItemProviderAdapterFactory());
164
		factories.add(new org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory());
165
		factories.add(new ReflectiveItemProviderAdapterFactory());
166
	}
167
168
	/**
169
	 * @generated
170
	 */
171
	public AdapterFactory getItemProvidersAdapterFactory() {
172
		return adapterFactory;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	public ImageDescriptor getItemImageDescriptor(Object item) {
179
		IItemLabelProvider labelProvider = (IItemLabelProvider)adapterFactory.adapt(item, IItemLabelProvider.class);
180
		if(labelProvider != null) {
181
			return ExtendedImageRegistry.getInstance().getImageDescriptor(labelProvider.getImage(item));
182
		}
183
		return null;
184
	}
185
186
	/**
187
	 * Returns an image descriptor for the image file at the given plug-in relative path.
188
	 * 
189
	 * @generated
190
	 * @param path
191
	 *        the path
192
	 * @return the image descriptor
193
	 */
194
	public static ImageDescriptor getBundledImageDescriptor(String path) {
195
		return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path);
196
	}
197
198
	/**
199
	 * Respects images residing in any plug-in. If path is relative, then this bundle is looked up
200
	 * for the image, otherwise, for absolute path, first segment is taken as id of plug-in with
201
	 * image
202
	 * 
203
	 * @generated
204
	 * @param path
205
	 *        the path to image, either absolute (with plug-in id as first segment), or relative
206
	 *        for bundled images
207
	 * @return the image descriptor
208
	 */
209
	public static ImageDescriptor findImageDescriptor(String path) {
210
		final IPath p = new Path(path);
211
		if(p.isAbsolute() && p.segmentCount() > 1) {
212
			return AbstractUIPlugin.imageDescriptorFromPlugin(p.segment(0), p.removeFirstSegments(1).makeAbsolute().toString());
213
		} else {
214
			return getBundledImageDescriptor(p.makeAbsolute().toString());
215
		}
216
	}
217
218
	/**
219
	 * Returns an image for the image file at the given plug-in relative path. Client do not need to
220
	 * dispose this image. Images will be disposed automatically.
221
	 * 
222
	 * @generated
223
	 * @param path
224
	 *        the path
225
	 * @return image instance
226
	 */
227
	public Image getBundledImage(String path) {
228
		Image image = getImageRegistry().get(path);
229
		if(image == null) {
230
			getImageRegistry().put(path, getBundledImageDescriptor(path));
231
			image = getImageRegistry().get(path);
232
		}
233
		return image;
234
	}
235
236
	/**
237
	 * Returns string from plug-in's resource bundle
238
	 * 
239
	 * @generated
240
	 */
241
	public static String getString(String key) {
242
		return Platform.getResourceString(getInstance().getBundle(), "%" + key); //$NON-NLS-1$
243
	}
244
245
	/**
246
	 * @generated
247
	 */
248
	public SysmlDocumentProvider getDocumentProvider() {
249
		if(documentProvider == null) {
250
			documentProvider = new SysmlDocumentProvider();
251
		}
252
		return documentProvider;
253
	}
254
255
	/**
256
	 * @generated
257
	 */
258
	public SysmlBaseItemSemanticEditPolicy.LinkConstraints getLinkConstraints() {
259
		return linkConstraints;
260
	}
261
262
	/**
263
	 * @generated
264
	 */
265
	public void setLinkConstraints(SysmlBaseItemSemanticEditPolicy.LinkConstraints lc) {
266
		this.linkConstraints = lc;
267
	}
268
269
	/**
270
	 * @generated
271
	 */
272
	public ElementInitializers getElementInitializers() {
273
		return initializers;
274
	}
275
276
	/**
277
	 * @generated
278
	 */
279
	public void setElementInitializers(ElementInitializers i) {
280
		this.initializers = i;
281
	}
282
283
	/**
284
	 * @generated
285
	 */
286
	public void logError(String error) {
287
		logError(error, null);
288
	}
289
290
	/**
291
	 * @generated
292
	 */
293
	public void logError(String error, Throwable throwable) {
294
		if(error == null && throwable != null) {
295
			error = throwable.getMessage();
296
		}
297
		getLog().log(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, IStatus.OK, error, throwable));
298
		debug(error, throwable);
299
	}
300
301
	/**
302
	 * @generated
303
	 */
304
	public void logInfo(String message) {
305
		logInfo(message, null);
306
	}
307
308
	/**
309
	 * @generated
310
	 */
311
	public void logInfo(String message, Throwable throwable) {
312
		if(message == null && throwable != null) {
313
			message = throwable.getMessage();
314
		}
315
		getLog().log(new Status(IStatus.INFO, SysmlDiagramEditorPlugin.ID, IStatus.OK, message, throwable));
316
		debug(message, throwable);
317
	}
318
319
	/**
320
	 * @generated
321
	 */
322
	private void debug(String message, Throwable throwable) {
323
		if(!isDebugging()) {
324
			return;
325
		}
326
		if(message != null) {
327
			System.err.println(message);
328
		}
329
		if(throwable != null) {
330
			throwable.printStackTrace();
331
		}
332
	}
333
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlDiagramEditorUtil.java (-377 lines)
Lines 1-377 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.io.IOException;
17
import java.util.Collections;
18
import java.util.HashMap;
19
import java.util.Iterator;
20
import java.util.LinkedList;
21
import java.util.List;
22
import java.util.Map;
23
import java.util.Set;
24
25
import org.eclipse.core.commands.ExecutionException;
26
import org.eclipse.core.commands.operations.OperationHistoryFactory;
27
import org.eclipse.core.resources.IFile;
28
import org.eclipse.core.resources.IResource;
29
import org.eclipse.core.resources.ResourcesPlugin;
30
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IAdaptable;
32
import org.eclipse.core.runtime.IPath;
33
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.NullProgressMonitor;
35
import org.eclipse.core.runtime.Path;
36
import org.eclipse.core.runtime.SubProgressMonitor;
37
import org.eclipse.emf.common.util.URI;
38
import org.eclipse.emf.ecore.EObject;
39
import org.eclipse.emf.ecore.resource.Resource;
40
import org.eclipse.emf.ecore.xmi.XMLResource;
41
import org.eclipse.emf.transaction.TransactionalEditingDomain;
42
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
43
import org.eclipse.gef.EditPart;
44
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
45
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
46
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
47
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
48
import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
49
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
50
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
51
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
52
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
53
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
54
import org.eclipse.gmf.runtime.notation.Diagram;
55
import org.eclipse.gmf.runtime.notation.View;
56
import org.eclipse.jface.dialogs.IDialogSettings;
57
import org.eclipse.jface.wizard.Wizard;
58
import org.eclipse.jface.wizard.WizardDialog;
59
import org.eclipse.papyrus.resource.ResourceFactory;
60
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
61
import org.eclipse.swt.widgets.Shell;
62
import org.eclipse.ui.IWorkbenchPage;
63
import org.eclipse.ui.PartInitException;
64
import org.eclipse.ui.PlatformUI;
65
import org.eclipse.ui.part.FileEditorInput;
66
67
/**
68
 * @generated
69
 */
70
public class SysmlDiagramEditorUtil {
71
72
	/**
73
	 * @generated
74
	 */
75
	public static Map<?, ?> getSaveOptions() {
76
		HashMap<String, Object> saveOptions = new HashMap<String, Object>();
77
		saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
78
		saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
79
		return saveOptions;
80
	}
81
82
	/**
83
	 * @generated
84
	 */
85
	public static boolean openDiagram(Resource diagram) throws PartInitException {
86
		String path = diagram.getURI().toPlatformString(true);
87
		IResource workspaceResource = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(path));
88
		if(workspaceResource instanceof IFile) {
89
			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
90
			return null != page.openEditor(new FileEditorInput((IFile)workspaceResource), SysmlDiagramEditor.ID);
91
		}
92
		return false;
93
	}
94
95
	/**
96
	 * @generated
97
	 */
98
	public static void setCharset(IFile file) {
99
		if(file == null) {
100
			return;
101
		}
102
		try {
103
			file.setCharset("UTF-8", new NullProgressMonitor()); //$NON-NLS-1$
104
		} catch (CoreException e) {
105
			SysmlDiagramEditorPlugin.getInstance().logError("Unable to set charset for file " + file.getFullPath(), e); //$NON-NLS-1$
106
		}
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	public static String getUniqueFileName(IPath containerFullPath, String fileName, String extension) {
113
		if(containerFullPath == null) {
114
			containerFullPath = new Path(""); //$NON-NLS-1$
115
		}
116
		if(fileName == null || fileName.trim().length() == 0) {
117
			fileName = "default"; //$NON-NLS-1$
118
		}
119
		IPath filePath = containerFullPath.append(fileName);
120
		if(extension != null && !extension.equals(filePath.getFileExtension())) {
121
			filePath = filePath.addFileExtension(extension);
122
		}
123
		extension = filePath.getFileExtension();
124
		fileName = filePath.removeFileExtension().lastSegment();
125
		int i = 1;
126
		while(ResourcesPlugin.getWorkspace().getRoot().exists(filePath)) {
127
			i++;
128
			filePath = containerFullPath.append(fileName + i);
129
			if(extension != null) {
130
				filePath = filePath.addFileExtension(extension);
131
			}
132
		}
133
		return filePath.lastSegment();
134
	}
135
136
	/**
137
	 * Runs the wizard in a dialog.
138
	 * 
139
	 * @generated
140
	 */
141
	public static void runWizard(Shell shell, Wizard wizard, String settingsKey) {
142
		IDialogSettings pluginDialogSettings = SysmlDiagramEditorPlugin.getInstance().getDialogSettings();
143
		IDialogSettings wizardDialogSettings = pluginDialogSettings.getSection(settingsKey);
144
		if(wizardDialogSettings == null) {
145
			wizardDialogSettings = pluginDialogSettings.addNewSection(settingsKey);
146
		}
147
		wizard.setDialogSettings(wizardDialogSettings);
148
		WizardDialog dialog = new WizardDialog(shell, wizard);
149
		dialog.create();
150
		dialog.getShell().setSize(Math.max(500, dialog.getShell().getSize().x), 500);
151
		dialog.open();
152
	}
153
154
	/**
155
	 * This method should be called within a workspace modify operation since it creates resources.
156
	 * 
157
	 * @generated
158
	 */
159
	public static Resource createDiagram(URI diagramURI, URI modelURI, IProgressMonitor progressMonitor) {
160
		TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
161
		progressMonitor.beginTask(Messages.SysmlDiagramEditorUtil_CreateDiagramProgressTask, 3);
162
		final Resource diagramResource = editingDomain.getResourceSet().createResource(diagramURI);
163
		final Resource modelResource = editingDomain.getResourceSet().createResource(modelURI);
164
		final String diagramName = diagramURI.lastSegment();
165
		AbstractTransactionalCommand command = new AbstractTransactionalCommand(editingDomain, Messages.SysmlDiagramEditorUtil_CreateDiagramCommandLabel, Collections.EMPTY_LIST) {
166
167
			protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
168
				org.eclipse.papyrus.resource.Resource model = createInitialModel();
169
				attachModelToResource(model, modelResource);
170
171
				Diagram diagram = ViewService.createDiagram(model, ParametricEditPart.MODEL_ID, SysmlDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
172
				if(diagram != null) {
173
					diagramResource.getContents().add(diagram);
174
					diagram.setName(diagramName);
175
					diagram.setElement(model);
176
				}
177
178
				try {
179
					modelResource.save(org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorUtil.getSaveOptions());
180
					diagramResource.save(org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorUtil.getSaveOptions());
181
				} catch (IOException e) {
182
183
					SysmlDiagramEditorPlugin.getInstance().logError("Unable to store model and diagram resources", e); //$NON-NLS-1$
184
				}
185
				return CommandResult.newOKCommandResult();
186
			}
187
		};
188
		try {
189
			OperationHistoryFactory.getOperationHistory().execute(command, new SubProgressMonitor(progressMonitor, 1), null);
190
		} catch (ExecutionException e) {
191
			SysmlDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e); //$NON-NLS-1$
192
		}
193
		setCharset(WorkspaceSynchronizer.getFile(modelResource));
194
		setCharset(WorkspaceSynchronizer.getFile(diagramResource));
195
		return diagramResource;
196
	}
197
198
	/**
199
	 * Create a new instance of domain element associated with canvas.
200
	 * <!-- begin-user-doc --> <!--
201
	 * end-user-doc -->
202
	 * 
203
	 * @generated
204
	 */
205
	private static org.eclipse.papyrus.resource.Resource createInitialModel() {
206
		return ResourceFactory.eINSTANCE.createResource();
207
	}
208
209
	/**
210
	 * Store model element in the resource.
211
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
212
	 * 
213
	 * @generated
214
	 */
215
	private static void attachModelToResource(org.eclipse.papyrus.resource.Resource model, Resource resource) {
216
		resource.getContents().add(model);
217
	}
218
219
	/**
220
	 * @generated
221
	 */
222
	public static void selectElementsInDiagram(IDiagramWorkbenchPart diagramPart, List<EditPart> editParts) {
223
		diagramPart.getDiagramGraphicalViewer().deselectAll();
224
225
		EditPart firstPrimary = null;
226
		for(EditPart nextPart : editParts) {
227
			diagramPart.getDiagramGraphicalViewer().appendSelection(nextPart);
228
			if(firstPrimary == null && nextPart instanceof IPrimaryEditPart) {
229
				firstPrimary = nextPart;
230
			}
231
		}
232
233
		if(!editParts.isEmpty()) {
234
			diagramPart.getDiagramGraphicalViewer().reveal(firstPrimary != null ? firstPrimary : (EditPart)editParts.get(0));
235
		}
236
	}
237
238
	/**
239
	 * @generated
240
	 */
241
	private static int findElementsInDiagramByID(DiagramEditPart diagramPart, EObject element, List<EditPart> editPartCollector) {
242
		IDiagramGraphicalViewer viewer = (IDiagramGraphicalViewer)diagramPart.getViewer();
243
		final int intialNumOfEditParts = editPartCollector.size();
244
245
		if(element instanceof View) { // support notation element lookup
246
			EditPart editPart = (EditPart)viewer.getEditPartRegistry().get(element);
247
			if(editPart != null) {
248
				editPartCollector.add(editPart);
249
				return 1;
250
			}
251
		}
252
253
		String elementID = EMFCoreUtil.getProxyID(element);
254
		@SuppressWarnings("unchecked")
255
		List<EditPart> associatedParts = viewer.findEditPartsForElement(elementID, IGraphicalEditPart.class);
256
		// perform the possible hierarchy disjoint -> take the top-most parts only
257
		for(EditPart nextPart : associatedParts) {
258
			EditPart parentPart = nextPart.getParent();
259
			while(parentPart != null && !associatedParts.contains(parentPart)) {
260
				parentPart = parentPart.getParent();
261
			}
262
			if(parentPart == null) {
263
				editPartCollector.add(nextPart);
264
			}
265
		}
266
267
		if(intialNumOfEditParts == editPartCollector.size()) {
268
			if(!associatedParts.isEmpty()) {
269
				editPartCollector.add(associatedParts.get(0));
270
			} else {
271
				if(element.eContainer() != null) {
272
					return findElementsInDiagramByID(diagramPart, element.eContainer(), editPartCollector);
273
				}
274
			}
275
		}
276
		return editPartCollector.size() - intialNumOfEditParts;
277
	}
278
279
	/**
280
	 * @generated
281
	 */
282
	public static View findView(DiagramEditPart diagramEditPart, EObject targetElement, LazyElement2ViewMap lazyElement2ViewMap) {
283
		boolean hasStructuralURI = false;
284
		if(targetElement.eResource() instanceof XMLResource) {
285
			hasStructuralURI = ((XMLResource)targetElement.eResource()).getID(targetElement) == null;
286
		}
287
288
		View view = null;
289
		LinkedList<EditPart> editPartHolder = new LinkedList<EditPart>();
290
		if(hasStructuralURI && !lazyElement2ViewMap.getElement2ViewMap().isEmpty()) {
291
			view = lazyElement2ViewMap.getElement2ViewMap().get(targetElement);
292
		} else if(findElementsInDiagramByID(diagramEditPart, targetElement, editPartHolder) > 0) {
293
			EditPart editPart = editPartHolder.get(0);
294
			view = editPart.getModel() instanceof View ? (View)editPart.getModel() : null;
295
		}
296
297
		return (view == null) ? diagramEditPart.getDiagramView() : view;
298
	}
299
300
	/**
301
	 * @generated
302
	 */
303
	public static class LazyElement2ViewMap {
304
305
		/**
306
		 * @generated
307
		 */
308
		private Map<EObject, View> element2ViewMap;
309
310
		/**
311
		 * @generated
312
		 */
313
		private View scope;
314
315
		/**
316
		 * @generated
317
		 */
318
		private Set<? extends EObject> elementSet;
319
320
		/**
321
		 * @generated
322
		 */
323
		public LazyElement2ViewMap(View scope, Set<? extends EObject> elements) {
324
			this.scope = scope;
325
			this.elementSet = elements;
326
		}
327
328
		/**
329
		 * @generated
330
		 */
331
		public final Map<EObject, View> getElement2ViewMap() {
332
			if(element2ViewMap == null) {
333
				element2ViewMap = new HashMap<EObject, View>();
334
				// map possible notation elements to itself as these can't be found by view.getElement()
335
				for(EObject element : elementSet) {
336
					if(element instanceof View) {
337
						View view = (View)element;
338
						if(view.getDiagram() == scope.getDiagram()) {
339
							element2ViewMap.put(element, view); // take only those that part of our diagram
340
						}
341
					}
342
				}
343
344
				buildElement2ViewMap(scope, element2ViewMap, elementSet);
345
			}
346
			return element2ViewMap;
347
		}
348
349
		/**
350
		 * @generated
351
		 */
352
		private static boolean buildElement2ViewMap(View parentView, Map<EObject, View> element2ViewMap, Set<? extends EObject> elements) {
353
			if(elements.size() == element2ViewMap.size()) {
354
				return true;
355
			}
356
357
			if(parentView.isSetElement() && !element2ViewMap.containsKey(parentView.getElement()) && elements.contains(parentView.getElement())) {
358
				element2ViewMap.put(parentView.getElement(), parentView);
359
				if(elements.size() == element2ViewMap.size()) {
360
					return true;
361
				}
362
			}
363
			boolean complete = false;
364
			for(Iterator<?> it = parentView.getChildren().iterator(); it.hasNext() && !complete;) {
365
				complete = buildElement2ViewMap((View)it.next(), element2ViewMap, elements);
366
			}
367
			for(Iterator<?> it = parentView.getSourceEdges().iterator(); it.hasNext() && !complete;) {
368
				complete = buildElement2ViewMap((View)it.next(), element2ViewMap, elements);
369
			}
370
			for(Iterator<?> it = parentView.getTargetEdges().iterator(); it.hasNext() && !complete;) {
371
				complete = buildElement2ViewMap((View)it.next(), element2ViewMap, elements);
372
			}
373
			return complete;
374
		}
375
	} // LazyElement2ViewMap
376
377
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlDiagramUpdateCommand.java (-91 lines)
Lines 1-91 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.util.Iterator;
17
import java.util.List;
18
19
import org.eclipse.core.commands.ExecutionEvent;
20
import org.eclipse.core.commands.ExecutionException;
21
import org.eclipse.core.commands.IHandler;
22
import org.eclipse.core.commands.IHandlerListener;
23
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.gef.EditPart;
25
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
26
import org.eclipse.gmf.runtime.notation.View;
27
import org.eclipse.jface.viewers.ISelection;
28
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.ui.PlatformUI;
30
31
/**
32
 * @generated
33
 */
34
public class SysmlDiagramUpdateCommand implements IHandler {
35
36
	/**
37
	 * @generated
38
	 */
39
	public void addHandlerListener(IHandlerListener handlerListener) {
40
	}
41
42
	/**
43
	 * @generated
44
	 */
45
	public void dispose() {
46
	}
47
48
	/**
49
	 * @generated
50
	 */
51
	public Object execute(ExecutionEvent event) throws ExecutionException {
52
		ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
53
		if(selection instanceof IStructuredSelection) {
54
			IStructuredSelection structuredSelection = (IStructuredSelection)selection;
55
			if(structuredSelection.size() != 1) {
56
				return null;
57
			}
58
			if(structuredSelection.getFirstElement() instanceof EditPart && ((EditPart)structuredSelection.getFirstElement()).getModel() instanceof View) {
59
				EObject modelElement = ((View)((EditPart)structuredSelection.getFirstElement()).getModel()).getElement();
60
				List editPolicies = CanonicalEditPolicy.getRegisteredEditPolicies(modelElement);
61
				for(Iterator it = editPolicies.iterator(); it.hasNext();) {
62
					CanonicalEditPolicy nextEditPolicy = (CanonicalEditPolicy)it.next();
63
					nextEditPolicy.refresh();
64
				}
65
66
			}
67
		}
68
		return null;
69
	}
70
71
	/**
72
	 * @generated
73
	 */
74
	public boolean isEnabled() {
75
		return true;
76
	}
77
78
	/**
79
	 * @generated
80
	 */
81
	public boolean isHandled() {
82
		return true;
83
	}
84
85
	/**
86
	 * @generated
87
	 */
88
	public void removeHandlerListener(IHandlerListener handlerListener) {
89
	}
90
91
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlDiagramUpdater.java (-359 lines)
Lines 1-359 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.util.Collection;
17
import java.util.Collections;
18
import java.util.Iterator;
19
import java.util.LinkedList;
20
import java.util.List;
21
import java.util.Map;
22
23
import org.eclipse.emf.common.util.EList;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.emf.ecore.util.EcoreUtil;
27
import org.eclipse.gmf.runtime.notation.View;
28
import org.eclipse.papyrus.resource.util.ResourceUtil;
29
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
30
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
32
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
33
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
34
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart;
35
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
36
import org.eclipse.uml2.uml.Class;
37
import org.eclipse.uml2.uml.ConnectableElement;
38
import org.eclipse.uml2.uml.Connector;
39
import org.eclipse.uml2.uml.ConnectorEnd;
40
import org.eclipse.uml2.uml.Property;
41
import org.eclipse.uml2.uml.StructuredClassifier;
42
import org.eclipse.uml2.uml.UMLPackage;
43
44
/**
45
 * @generated
46
 */
47
public class SysmlDiagramUpdater {
48
49
	/**
50
	 * @generated
51
	 */
52
	public static List<SysmlNodeDescriptor> getSemanticChildren(View view) {
53
		switch(SysmlVisualIDRegistry.getVisualID(view)) {
54
		case ParametricEditPart.VISUAL_ID:
55
			return getResource_1000SemanticChildren(view);
56
		case ConstraintPropertyEditPart.VISUAL_ID:
57
			return getConstraintProperty_2003SemanticChildren(view);
58
		}
59
		return Collections.emptyList();
60
	}
61
62
	/**
63
	 * @generated NOT
64
	 */
65
	public static List getConstraintProperty_2003SemanticChildren(View view) {
66
		if(!view.isSetElement()) {
67
			return Collections.EMPTY_LIST;
68
		}
69
		ConstraintProperty modelElement = (ConstraintProperty)view.getElement();
70
		List result = new LinkedList();
71
		{
72
			Property childElement = modelElement.getBase_Property();
73
			int visualID = SysmlVisualIDRegistry.getNodeVisualID(view, childElement);
74
			if(visualID == Property2EditPart.VISUAL_ID) {
75
				result.add(new SysmlNodeDescriptor(childElement, visualID));
76
			}
77
		}
78
		return result;
79
		/*
80
		 * if (!view.isSetElement()) { return Collections.EMPTY_LIST; } ConstraintProperty
81
		 * modelElement = (ConstraintProperty) view.getElement(); List result = new LinkedList();
82
		 * 
83
		 * Object oclRuleResult = OCLUtils.runOclRule("self.base_Property.type", modelElement); if
84
		 * (oclRuleResult != null) { if (oclRuleResult instanceof StructuredClassifier) {
85
		 * StructuredClassifier aClass = (StructuredClassifier) oclRuleResult; for (Iterator it =
86
		 * aClass.getAttributes().iterator(); it.hasNext();) { Property childElement = (Property)
87
		 * it.next(); int visualID = SysmlVisualIDRegistry.getNodeVisualID(view, childElement); if
88
		 * (visualID == Property2EditPart.VISUAL_ID) { result.add(new
89
		 * SysmlNodeDescriptor(childElement, visualID)); //continue; } } } else { throw new
90
		 * UnsupportedOperationException("Can't access with ..."); } }
91
		 */
92
	}
93
94
	/**
95
	 * @generated NOT
96
	 */
97
	public static List getResource_1000SemanticChildren(View view) {
98
		if(!view.isSetElement()) {
99
			return Collections.EMPTY_LIST;
100
		}
101
		List result = new LinkedList();
102
		EObject eObject = view.getElement();
103
		// element is a block
104
		if(eObject instanceof Class) {
105
			Class modelElement = (Class)eObject;
106
			// we get the papyrus resource from the model object
107
			EList<EObject> eobjects = ResourceUtil.getResource(modelElement).getEobjects();
108
			for(Iterator it = eobjects.iterator(); it.hasNext();) {
109
				EObject childElement = (EObject)it.next();
110
				int visualID = SysmlVisualIDRegistry.getNodeVisualID(view, (EObject)childElement);
111
				if(visualID == ConstraintPropertyEditPart.VISUAL_ID) {
112
					result.add(new SysmlNodeDescriptor((EObject)childElement, visualID));
113
					continue;
114
				}
115
			}
116
			for(Iterator it = modelElement.getOwnedAttributes().iterator(); it.hasNext();) {
117
				EObject obj = (EObject)it.next();
118
				if(obj instanceof Property) {
119
					Property childElement = (Property)obj;
120
					int visualID = SysmlVisualIDRegistry.getNodeVisualID(view, childElement);
121
					if((visualID == PropertyEditPart.VISUAL_ID) && (childElement.getAppliedStereotype("SysML::Constraints::ConstraintProperty") == null)) {
122
						result.add(new SysmlNodeDescriptor(childElement, visualID));
123
						continue;
124
					}
125
				}
126
			}
127
		}
128
		return result;
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	public static List<SysmlLinkDescriptor> getContainedLinks(View view) {
135
		switch(SysmlVisualIDRegistry.getVisualID(view)) {
136
		case ParametricEditPart.VISUAL_ID:
137
			return getResource_1000ContainedLinks(view);
138
		case ConstraintPropertyEditPart.VISUAL_ID:
139
			return getConstraintProperty_2003ContainedLinks(view);
140
		case PropertyEditPart.VISUAL_ID:
141
			return getProperty_2005ContainedLinks(view);
142
		case Property2EditPart.VISUAL_ID:
143
			return getProperty_3002ContainedLinks(view);
144
		case ConnectorEditPart.VISUAL_ID:
145
			return getConnector_4001ContainedLinks(view);
146
		}
147
		return Collections.emptyList();
148
	}
149
150
	/**
151
	 * @generated
152
	 */
153
	public static List<SysmlLinkDescriptor> getIncomingLinks(View view) {
154
		switch(SysmlVisualIDRegistry.getVisualID(view)) {
155
		case ConstraintPropertyEditPart.VISUAL_ID:
156
			return getConstraintProperty_2003IncomingLinks(view);
157
		case PropertyEditPart.VISUAL_ID:
158
			return getProperty_2005IncomingLinks(view);
159
		case Property2EditPart.VISUAL_ID:
160
			return getProperty_3002IncomingLinks(view);
161
		case ConnectorEditPart.VISUAL_ID:
162
			return getConnector_4001IncomingLinks(view);
163
		}
164
		return Collections.emptyList();
165
	}
166
167
	/**
168
	 * @generated
169
	 */
170
	public static List<SysmlLinkDescriptor> getOutgoingLinks(View view) {
171
		switch(SysmlVisualIDRegistry.getVisualID(view)) {
172
		case ConstraintPropertyEditPart.VISUAL_ID:
173
			return getConstraintProperty_2003OutgoingLinks(view);
174
		case PropertyEditPart.VISUAL_ID:
175
			return getProperty_2005OutgoingLinks(view);
176
		case Property2EditPart.VISUAL_ID:
177
			return getProperty_3002OutgoingLinks(view);
178
		case ConnectorEditPart.VISUAL_ID:
179
			return getConnector_4001OutgoingLinks(view);
180
		}
181
		return Collections.emptyList();
182
	}
183
184
	/**
185
	 * @generated
186
	 */
187
	public static List<SysmlLinkDescriptor> getResource_1000ContainedLinks(View view) {
188
		return Collections.emptyList();
189
	}
190
191
	/**
192
	 * @generated
193
	 */
194
	public static List<SysmlLinkDescriptor> getConstraintProperty_2003ContainedLinks(View view) {
195
		return Collections.emptyList();
196
	}
197
198
	/**
199
	 * @generated
200
	 */
201
	public static List<SysmlLinkDescriptor> getProperty_2005ContainedLinks(View view) {
202
		return Collections.emptyList();
203
	}
204
205
	/**
206
	 * @generated
207
	 */
208
	public static List<SysmlLinkDescriptor> getProperty_3002ContainedLinks(View view) {
209
		return Collections.emptyList();
210
	}
211
212
	/**
213
	 * @generated
214
	 */
215
	public static List<SysmlLinkDescriptor> getConnector_4001ContainedLinks(View view) {
216
		return Collections.emptyList();
217
	}
218
219
	/**
220
	 * @generated
221
	 */
222
	public static List<SysmlLinkDescriptor> getConstraintProperty_2003IncomingLinks(View view) {
223
		return Collections.emptyList();
224
	}
225
226
	/**
227
	 * @generated
228
	 */
229
	public static List<SysmlLinkDescriptor> getProperty_2005IncomingLinks(View view) {
230
		Property modelElement = (Property)view.getElement();
231
		Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences = EcoreUtil.CrossReferencer.find(view.eResource().getResourceSet().getResources());
232
		LinkedList<SysmlLinkDescriptor> result = new LinkedList<SysmlLinkDescriptor>();
233
		result.addAll(getIncomingTypeModelFacetLinks_Connector_4001(modelElement, crossReferences));
234
		return result;
235
	}
236
237
	/**
238
	 * @generated
239
	 */
240
	public static List<SysmlLinkDescriptor> getProperty_3002IncomingLinks(View view) {
241
		Property modelElement = (Property)view.getElement();
242
		Map<EObject, Collection<EStructuralFeature.Setting>> crossReferences = EcoreUtil.CrossReferencer.find(view.eResource().getResourceSet().getResources());
243
		LinkedList<SysmlLinkDescriptor> result = new LinkedList<SysmlLinkDescriptor>();
244
		result.addAll(getIncomingTypeModelFacetLinks_Connector_4001(modelElement, crossReferences));
245
		return result;
246
	}
247
248
	/**
249
	 * @generated
250
	 */
251
	public static List<SysmlLinkDescriptor> getConnector_4001IncomingLinks(View view) {
252
		return Collections.emptyList();
253
	}
254
255
	/**
256
	 * @generated
257
	 */
258
	public static List<SysmlLinkDescriptor> getConstraintProperty_2003OutgoingLinks(View view) {
259
		return Collections.emptyList();
260
	}
261
262
	/**
263
	 * @generated
264
	 */
265
	public static List<SysmlLinkDescriptor> getProperty_2005OutgoingLinks(View view) {
266
		Property modelElement = (Property)view.getElement();
267
		LinkedList<SysmlLinkDescriptor> result = new LinkedList<SysmlLinkDescriptor>();
268
		result.addAll(getOutgoingTypeModelFacetLinks_Connector_4001(modelElement));
269
		return result;
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	public static List<SysmlLinkDescriptor> getProperty_3002OutgoingLinks(View view) {
276
		Property modelElement = (Property)view.getElement();
277
		LinkedList<SysmlLinkDescriptor> result = new LinkedList<SysmlLinkDescriptor>();
278
		result.addAll(getOutgoingTypeModelFacetLinks_Connector_4001(modelElement));
279
		return result;
280
	}
281
282
	/**
283
	 * @generated
284
	 */
285
	public static List<SysmlLinkDescriptor> getConnector_4001OutgoingLinks(View view) {
286
		return Collections.emptyList();
287
	}
288
289
	/**
290
	 * @generated NOT
291
	 */
292
	private static Collection getIncomingTypeModelFacetLinks_Connector_4001(ConnectableElement target, Map crossReferences) {
293
		Collection result = new LinkedList();
294
		Collection settings = (Collection)crossReferences.get(target);
295
		for(Iterator it = settings.iterator(); it.hasNext();) {
296
			EStructuralFeature.Setting setting = (EStructuralFeature.Setting)it.next();
297
			if(setting.getEStructuralFeature() != UMLPackage.eINSTANCE.getConnectorEnd_Role() || false == setting.getEObject() instanceof ConnectorEnd) {
298
				continue;
299
			}
300
			ConnectorEnd connectorEnd = (ConnectorEnd)setting.getEObject();
301
			Connector link = (Connector)connectorEnd.getOwner();
302
			if(ConnectorEditPart.VISUAL_ID != SysmlVisualIDRegistry.getLinkWithClassVisualID(link)) {
303
				continue;
304
			}
305
			ConnectableElement src = null;
306
			EList<ConnectorEnd> ends = link.getEnds();
307
			if(ends != null && !ends.isEmpty()) {
308
				src = ends.get(0).getRole();
309
			}
310
			result.add(new SysmlLinkDescriptor(src, target, link, SysmlElementTypes.Connector_4001, ConnectorEditPart.VISUAL_ID));
311
		}
312
		return result;
313
	}
314
315
	/**
316
	 * @generated NOT
317
	 */
318
	private static Collection getOutgoingTypeModelFacetLinks_Connector_4001(ConnectableElement source) {
319
		StructuredClassifier container = null;
320
		// Find container element for the link.
321
		// Climb up by containment hierarchy starting from the source
322
		// and return the first element that is instance of the container class.
323
		for(EObject element = source; element != null && container == null; element = element.eContainer()) {
324
			if(element instanceof StructuredClassifier) {
325
				container = (StructuredClassifier)element;
326
			}
327
		}
328
		if(container == null) {
329
			return Collections.EMPTY_LIST;
330
		}
331
		Collection result = new LinkedList();
332
		for(Iterator links = container.getOwnedConnectors().iterator(); links.hasNext();) {
333
			EObject linkObject = (EObject)links.next();
334
			if(false == linkObject instanceof Connector) {
335
				continue;
336
			}
337
			Connector link = (Connector)linkObject;
338
			if(ConnectorEditPart.VISUAL_ID != SysmlVisualIDRegistry.getLinkWithClassVisualID(link)) {
339
				continue;
340
			}
341
342
			ConnectableElement src = null;
343
			ConnectableElement dst = null;
344
			EList<ConnectorEnd> ends = link.getEnds();
345
			if(ends != null && !ends.isEmpty() && ends.size() > 1) {
346
				src = ends.get(0).getRole();
347
				dst = ends.get(1).getRole();
348
			}
349
350
			if(src != source) {
351
				continue;
352
			}
353
			result.add(new SysmlLinkDescriptor(src, dst, link, SysmlElementTypes.Connector_4001, ConnectorEditPart.VISUAL_ID));
354
355
		}
356
		return result;
357
	}
358
359
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlDocumentProvider.java (-988 lines)
Lines 1-988 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.io.IOException;
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
import java.util.Map;
24
25
import org.eclipse.core.commands.ExecutionException;
26
import org.eclipse.core.resources.IFile;
27
import org.eclipse.core.resources.IResource;
28
import org.eclipse.core.resources.IResourceStatus;
29
import org.eclipse.core.resources.IStorage;
30
import org.eclipse.core.resources.ResourcesPlugin;
31
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.IAdaptable;
33
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.Path;
36
import org.eclipse.core.runtime.Status;
37
import org.eclipse.core.runtime.jobs.ISchedulingRule;
38
import org.eclipse.core.runtime.jobs.MultiRule;
39
import org.eclipse.emf.common.notify.Adapter;
40
import org.eclipse.emf.common.notify.Notification;
41
import org.eclipse.emf.common.notify.Notifier;
42
import org.eclipse.emf.common.ui.URIEditorInput;
43
import org.eclipse.emf.common.util.URI;
44
import org.eclipse.emf.ecore.EObject;
45
import org.eclipse.emf.ecore.resource.Resource;
46
import org.eclipse.emf.ecore.resource.ResourceSet;
47
import org.eclipse.emf.ecore.util.EContentAdapter;
48
import org.eclipse.emf.ecore.util.EcoreUtil;
49
import org.eclipse.emf.transaction.NotificationFilter;
50
import org.eclipse.emf.transaction.TransactionalEditingDomain;
51
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
52
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
53
import org.eclipse.gmf.runtime.diagram.core.DiagramEditingDomainFactory;
54
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.AbstractDocumentProvider;
55
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.DiagramDocument;
56
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument;
57
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocumentProvider;
58
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDocument;
59
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.EditorStatusCodes;
60
import org.eclipse.gmf.runtime.diagram.ui.resources.editor.internal.util.DiagramIOUtil;
61
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
62
import org.eclipse.gmf.runtime.emf.core.resources.GMFResourceFactory;
63
import org.eclipse.gmf.runtime.notation.Diagram;
64
import org.eclipse.jface.operation.IRunnableContext;
65
import org.eclipse.osgi.util.NLS;
66
import org.eclipse.swt.widgets.Display;
67
import org.eclipse.ui.IEditorInput;
68
import org.eclipse.ui.part.FileEditorInput;
69
70
/**
71
 * @generated
72
 */
73
public class SysmlDocumentProvider extends AbstractDocumentProvider implements IDiagramDocumentProvider {
74
75
	/**
76
	 * @generated
77
	 */
78
	protected ElementInfo createElementInfo(Object element) throws CoreException {
79
		if(false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) {
80
			throw new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, 0, NLS.bind(Messages.SysmlDocumentProvider_IncorrectInputError, new Object[]{ element, "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ 
81
			null));
82
		}
83
		IEditorInput editorInput = (IEditorInput)element;
84
		IDiagramDocument document = (IDiagramDocument)createDocument(editorInput);
85
86
		ResourceSetInfo info = new ResourceSetInfo(document, editorInput);
87
		info.setModificationStamp(computeModificationStamp(info));
88
		info.fStatus = null;
89
		return info;
90
	}
91
92
	/**
93
	 * @generated
94
	 */
95
	protected IDocument createDocument(Object element) throws CoreException {
96
		if(false == element instanceof FileEditorInput && false == element instanceof URIEditorInput) {
97
			throw new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, 0, NLS.bind(Messages.SysmlDocumentProvider_IncorrectInputError, new Object[]{ element, "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ 
98
			null));
99
		}
100
		IDocument document = createEmptyDocument();
101
		setDocumentContent(document, (IEditorInput)element);
102
		setupDocument(element, document);
103
		return document;
104
	}
105
106
	/**
107
	 * Sets up the given document as it would be provided for the given element. The content of the
108
	 * document is not changed. This default implementation is empty. Subclasses may reimplement.
109
	 * 
110
	 * @param element
111
	 *        the blue-print element
112
	 * @param document
113
	 *        the document to set up
114
	 * @generated
115
	 */
116
	protected void setupDocument(Object element, IDocument document) {
117
		// for subclasses
118
	}
119
120
	/**
121
	 * @generated
122
	 */
123
	private long computeModificationStamp(ResourceSetInfo info) {
124
		int result = 0;
125
		for(Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
126
			Resource nextResource = it.next();
127
			IFile file = WorkspaceSynchronizer.getFile(nextResource);
128
			if(file != null) {
129
				if(file.getLocation() != null) {
130
					result += file.getLocation().toFile().lastModified();
131
				} else {
132
					result += file.getModificationStamp();
133
				}
134
			}
135
		}
136
		return result;
137
	}
138
139
	/**
140
	 * @generated
141
	 */
142
	protected IDocument createEmptyDocument() {
143
		DiagramDocument document = new DiagramDocument();
144
		document.setEditingDomain(createEditingDomain());
145
		return document;
146
	}
147
148
	/**
149
	 * @generated
150
	 */
151
	private TransactionalEditingDomain createEditingDomain() {
152
		TransactionalEditingDomain editingDomain = DiagramEditingDomainFactory.getInstance().createEditingDomain();
153
		editingDomain.setID("org.eclipse.papyrus.sysml.diagram.parametric.EditingDomain"); //$NON-NLS-1$
154
		final NotificationFilter diagramResourceModifiedFilter = NotificationFilter.createNotifierFilter(editingDomain.getResourceSet()).and(NotificationFilter.createEventTypeFilter(Notification.ADD)).and(NotificationFilter.createFeatureFilter(ResourceSet.class, ResourceSet.RESOURCE_SET__RESOURCES));
155
		editingDomain.getResourceSet().eAdapters().add(new Adapter() {
156
157
			private Notifier myTarger;
158
159
			public Notifier getTarget() {
160
				return myTarger;
161
			}
162
163
			public boolean isAdapterForType(Object type) {
164
				return false;
165
			}
166
167
			public void notifyChanged(Notification notification) {
168
				if(diagramResourceModifiedFilter.matches(notification)) {
169
					Object value = notification.getNewValue();
170
					if(value instanceof Resource) {
171
						((Resource)value).setTrackingModification(true);
172
					}
173
				}
174
			}
175
176
			public void setTarget(Notifier newTarget) {
177
				myTarger = newTarget;
178
			}
179
180
		});
181
182
		return editingDomain;
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected void setDocumentContent(IDocument document, IEditorInput element) throws CoreException {
189
		IDiagramDocument diagramDocument = (IDiagramDocument)document;
190
		TransactionalEditingDomain domain = diagramDocument.getEditingDomain();
191
		if(element instanceof FileEditorInput) {
192
			IStorage storage = ((FileEditorInput)element).getStorage();
193
			Diagram diagram = DiagramIOUtil.load(domain, storage, true, getProgressMonitor());
194
			document.setContent(diagram);
195
		} else if(element instanceof URIEditorInput) {
196
			URI uri = ((URIEditorInput)element).getURI();
197
			Resource resource = null;
198
			try {
199
				resource = domain.getResourceSet().getResource(uri.trimFragment(), false);
200
				if(resource == null) {
201
					resource = domain.getResourceSet().createResource(uri.trimFragment());
202
				}
203
				if(!resource.isLoaded()) {
204
					try {
205
						Map options = new HashMap(GMFResourceFactory.getDefaultLoadOptions());
206
						// @see 171060 
207
						// options.put(org.eclipse.emf.ecore.xmi.XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);
208
						resource.load(options);
209
					} catch (IOException e) {
210
						resource.unload();
211
						throw e;
212
					}
213
				}
214
				if(uri.fragment() != null) {
215
					EObject rootElement = resource.getEObject(uri.fragment());
216
					if(rootElement instanceof Diagram) {
217
						document.setContent((Diagram)rootElement);
218
						return;
219
					}
220
				} else {
221
					for(Iterator it = resource.getContents().iterator(); it.hasNext();) {
222
						Object rootElement = it.next();
223
						if(rootElement instanceof Diagram) {
224
							document.setContent((Diagram)rootElement);
225
							return;
226
						}
227
					}
228
				}
229
				throw new RuntimeException(Messages.SysmlDocumentProvider_NoDiagramInResourceError);
230
			} catch (Exception e) {
231
				CoreException thrownExcp = null;
232
				if(e instanceof CoreException) {
233
					thrownExcp = (CoreException)e;
234
				} else {
235
					String msg = e.getLocalizedMessage();
236
					thrownExcp = new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, 0, msg != null ? msg : Messages.SysmlDocumentProvider_DiagramLoadingError, e));
237
				}
238
				throw thrownExcp;
239
			}
240
		} else {
241
			throw new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, 0, NLS.bind(Messages.SysmlDocumentProvider_IncorrectInputError, new Object[]{ element, "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ 
242
			null));
243
		}
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	public long getModificationStamp(Object element) {
250
		ResourceSetInfo info = getResourceSetInfo(element);
251
		if(info != null) {
252
			return computeModificationStamp(info);
253
		}
254
		return super.getModificationStamp(element);
255
	}
256
257
	/**
258
	 * @generated
259
	 */
260
	public boolean isDeleted(Object element) {
261
		IDiagramDocument document = getDiagramDocument(element);
262
		if(document != null) {
263
			Resource diagramResource = document.getDiagram().eResource();
264
			if(diagramResource != null) {
265
				IFile file = WorkspaceSynchronizer.getFile(diagramResource);
266
				return file == null || file.getLocation() == null || !file.getLocation().toFile().exists();
267
			}
268
		}
269
		return super.isDeleted(element);
270
	}
271
272
	/**
273
	 * @generated
274
	 */
275
	public ResourceSetInfo getResourceSetInfo(Object editorInput) {
276
		return (ResourceSetInfo)super.getElementInfo(editorInput);
277
	}
278
279
	/**
280
	 * @generated
281
	 */
282
	protected void disposeElementInfo(Object element, ElementInfo info) {
283
		if(info instanceof ResourceSetInfo) {
284
			ResourceSetInfo resourceSetInfo = (ResourceSetInfo)info;
285
			resourceSetInfo.dispose();
286
		}
287
		super.disposeElementInfo(element, info);
288
	}
289
290
	/**
291
	 * @generated
292
	 */
293
	protected void doValidateState(Object element, Object computationContext) throws CoreException {
294
		ResourceSetInfo info = getResourceSetInfo(element);
295
		if(info != null) {
296
			LinkedList<IFile> files2Validate = new LinkedList<IFile>();
297
			for(Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
298
				Resource nextResource = it.next();
299
				IFile file = WorkspaceSynchronizer.getFile(nextResource);
300
				if(file != null && file.isReadOnly()) {
301
					files2Validate.add(file);
302
				}
303
			}
304
			ResourcesPlugin.getWorkspace().validateEdit((IFile[])files2Validate.toArray(new IFile[files2Validate.size()]), computationContext);
305
		}
306
307
		super.doValidateState(element, computationContext);
308
	}
309
310
	/**
311
	 * @generated
312
	 */
313
	public boolean isReadOnly(Object element) {
314
		ResourceSetInfo info = getResourceSetInfo(element);
315
		if(info != null) {
316
			if(info.isUpdateCache()) {
317
				try {
318
					updateCache(element);
319
				} catch (CoreException ex) {
320
					SysmlDiagramEditorPlugin.getInstance().logError(Messages.SysmlDocumentProvider_isModifiable, ex);
321
					// Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable
322
				}
323
			}
324
			return info.isReadOnly();
325
		}
326
		return super.isReadOnly(element);
327
	}
328
329
	/**
330
	 * @generated
331
	 */
332
	public boolean isModifiable(Object element) {
333
		if(!isStateValidated(element)) {
334
			if(element instanceof FileEditorInput || element instanceof URIEditorInput) {
335
				return true;
336
			}
337
		}
338
		ResourceSetInfo info = getResourceSetInfo(element);
339
		if(info != null) {
340
			if(info.isUpdateCache()) {
341
				try {
342
					updateCache(element);
343
				} catch (CoreException ex) {
344
					SysmlDiagramEditorPlugin.getInstance().logError(Messages.SysmlDocumentProvider_isModifiable, ex);
345
					// Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.StorageDocumentProvider_isModifiable
346
				}
347
			}
348
			return info.isModifiable();
349
		}
350
		return super.isModifiable(element);
351
	}
352
353
	/**
354
	 * @generated
355
	 */
356
	protected void updateCache(Object element) throws CoreException {
357
		ResourceSetInfo info = getResourceSetInfo(element);
358
		if(info != null) {
359
			for(Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
360
				Resource nextResource = it.next();
361
				IFile file = WorkspaceSynchronizer.getFile(nextResource);
362
				if(file != null && file.isReadOnly()) {
363
					info.setReadOnly(true);
364
					info.setModifiable(false);
365
					return;
366
				}
367
			}
368
			info.setReadOnly(false);
369
			info.setModifiable(true);
370
			return;
371
		}
372
	}
373
374
	/**
375
	 * @generated
376
	 */
377
	protected void doUpdateStateCache(Object element) throws CoreException {
378
		ResourceSetInfo info = getResourceSetInfo(element);
379
		if(info != null) {
380
			info.setUpdateCache(true);
381
		}
382
		super.doUpdateStateCache(element);
383
	}
384
385
	/**
386
	 * @generated
387
	 */
388
	public boolean isSynchronized(Object element) {
389
		ResourceSetInfo info = getResourceSetInfo(element);
390
		if(info != null) {
391
			return info.isSynchronized();
392
		}
393
		return super.isSynchronized(element);
394
	}
395
396
	/**
397
	 * @generated
398
	 */
399
	protected ISchedulingRule getResetRule(Object element) {
400
		ResourceSetInfo info = getResourceSetInfo(element);
401
		if(info != null) {
402
			LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
403
			for(Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
404
				Resource nextResource = it.next();
405
				IFile file = WorkspaceSynchronizer.getFile(nextResource);
406
				if(file != null) {
407
					rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(file));
408
				}
409
			}
410
			return new MultiRule((ISchedulingRule[])rules.toArray(new ISchedulingRule[rules.size()]));
411
		}
412
		return null;
413
	}
414
415
	/**
416
	 * @generated
417
	 */
418
	protected ISchedulingRule getSaveRule(Object element) {
419
		ResourceSetInfo info = getResourceSetInfo(element);
420
		if(info != null) {
421
			LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
422
			for(Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
423
				Resource nextResource = it.next();
424
				IFile file = WorkspaceSynchronizer.getFile(nextResource);
425
				if(file != null) {
426
					rules.add(computeSchedulingRule(file));
427
				}
428
			}
429
			return new MultiRule((ISchedulingRule[])rules.toArray(new ISchedulingRule[rules.size()]));
430
		}
431
		return null;
432
	}
433
434
	/**
435
	 * @generated
436
	 */
437
	protected ISchedulingRule getSynchronizeRule(Object element) {
438
		ResourceSetInfo info = getResourceSetInfo(element);
439
		if(info != null) {
440
			LinkedList<ISchedulingRule> rules = new LinkedList<ISchedulingRule>();
441
			for(Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
442
				Resource nextResource = it.next();
443
				IFile file = WorkspaceSynchronizer.getFile(nextResource);
444
				if(file != null) {
445
					rules.add(ResourcesPlugin.getWorkspace().getRuleFactory().refreshRule(file));
446
				}
447
			}
448
			return new MultiRule((ISchedulingRule[])rules.toArray(new ISchedulingRule[rules.size()]));
449
		}
450
		return null;
451
	}
452
453
	/**
454
	 * @generated
455
	 */
456
	protected ISchedulingRule getValidateStateRule(Object element) {
457
		ResourceSetInfo info = getResourceSetInfo(element);
458
		if(info != null) {
459
			LinkedList<ISchedulingRule> files = new LinkedList<ISchedulingRule>();
460
			for(Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
461
				Resource nextResource = it.next();
462
				IFile file = WorkspaceSynchronizer.getFile(nextResource);
463
				if(file != null) {
464
					files.add(file);
465
				}
466
			}
467
			return ResourcesPlugin.getWorkspace().getRuleFactory().validateEditRule((IFile[])files.toArray(new IFile[files.size()]));
468
		}
469
		return null;
470
	}
471
472
	/**
473
	 * @generated
474
	 */
475
	private ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) {
476
		if(toCreateOrModify.exists())
477
			return ResourcesPlugin.getWorkspace().getRuleFactory().modifyRule(toCreateOrModify);
478
479
		IResource parent = toCreateOrModify;
480
		do {
481
			/*
482
			 * XXX This is a workaround for
483
			 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
484
			 * IResourceRuleFactory.createRule should iterate the hierarchy
485
			 * itself.
486
			 */
487
			toCreateOrModify = parent;
488
			parent = toCreateOrModify.getParent();
489
		} while(parent != null && !parent.exists());
490
491
		return ResourcesPlugin.getWorkspace().getRuleFactory().createRule(toCreateOrModify);
492
	}
493
494
	/**
495
	 * @generated
496
	 */
497
	protected void doSynchronize(Object element, IProgressMonitor monitor) throws CoreException {
498
		ResourceSetInfo info = getResourceSetInfo(element);
499
		if(info != null) {
500
			for(Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
501
				Resource nextResource = it.next();
502
				handleElementChanged(info, nextResource, monitor);
503
			}
504
			return;
505
		}
506
		super.doSynchronize(element, monitor);
507
	}
508
509
	/**
510
	 * @generated
511
	 */
512
	protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite) throws CoreException {
513
		ResourceSetInfo info = getResourceSetInfo(element);
514
		if(info != null) {
515
			if(!overwrite && !info.isSynchronized()) {
516
				throw new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, IResourceStatus.OUT_OF_SYNC_LOCAL, Messages.SysmlDocumentProvider_UnsynchronizedFileSaveError, null));
517
			}
518
			info.stopResourceListening();
519
			fireElementStateChanging(element);
520
			try {
521
				monitor.beginTask(Messages.SysmlDocumentProvider_SaveDiagramTask, info.getResourceSet().getResources().size() + 1); //"Saving diagram"
522
				for(Iterator<Resource> it = info.getLoadedResourcesIterator(); it.hasNext();) {
523
					Resource nextResource = it.next();
524
					monitor.setTaskName(NLS.bind(Messages.SysmlDocumentProvider_SaveNextResourceTask, nextResource.getURI()));
525
					if(nextResource.isLoaded() && !info.getEditingDomain().isReadOnly(nextResource)) {
526
						try {
527
							nextResource.save(SysmlDiagramEditorUtil.getSaveOptions());
528
						} catch (IOException e) {
529
							fireElementStateChangeFailed(element);
530
							throw new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, EditorStatusCodes.RESOURCE_FAILURE, e.getLocalizedMessage(), null));
531
						}
532
					}
533
					monitor.worked(1);
534
				}
535
				monitor.done();
536
				info.setModificationStamp(computeModificationStamp(info));
537
			} catch (RuntimeException x) {
538
				fireElementStateChangeFailed(element);
539
				throw x;
540
			} finally {
541
				info.startResourceListening();
542
			}
543
		} else {
544
			URI newResoruceURI;
545
			List<IFile> affectedFiles = null;
546
			if(element instanceof FileEditorInput) {
547
				IFile newFile = ((FileEditorInput)element).getFile();
548
				affectedFiles = Collections.singletonList(newFile);
549
				newResoruceURI = URI.createPlatformResourceURI(newFile.getFullPath().toString(), true);
550
			} else if(element instanceof URIEditorInput) {
551
				newResoruceURI = ((URIEditorInput)element).getURI();
552
			} else {
553
				fireElementStateChangeFailed(element);
554
				throw new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, 0, NLS.bind(Messages.SysmlDocumentProvider_IncorrectInputError, new Object[]{ element, "org.eclipse.ui.part.FileEditorInput", "org.eclipse.emf.common.ui.URIEditorInput" }), //$NON-NLS-1$ //$NON-NLS-2$ 
555
				null));
556
			}
557
			if(false == document instanceof IDiagramDocument) {
558
				fireElementStateChangeFailed(element);
559
				throw new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, 0, "Incorrect document used: " + document + " instead of org.eclipse.gmf.runtime.diagram.ui.resources.editor.document.IDiagramDocument", null)); //$NON-NLS-1$ //$NON-NLS-2$
560
			}
561
			IDiagramDocument diagramDocument = (IDiagramDocument)document;
562
			final Resource newResource = diagramDocument.getEditingDomain().getResourceSet().createResource(newResoruceURI);
563
			final Diagram diagramCopy = (Diagram)EcoreUtil.copy(diagramDocument.getDiagram());
564
			try {
565
				new AbstractTransactionalCommand(diagramDocument.getEditingDomain(), NLS.bind(Messages.SysmlDocumentProvider_SaveAsOperation, diagramCopy.getName()), affectedFiles) {
566
567
					protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
568
						newResource.getContents().add(diagramCopy);
569
						return CommandResult.newOKCommandResult();
570
					}
571
				}.execute(monitor, null);
572
				newResource.save(SysmlDiagramEditorUtil.getSaveOptions());
573
			} catch (ExecutionException e) {
574
				fireElementStateChangeFailed(element);
575
				throw new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null));
576
			} catch (IOException e) {
577
				fireElementStateChangeFailed(element);
578
				throw new CoreException(new Status(IStatus.ERROR, SysmlDiagramEditorPlugin.ID, 0, e.getLocalizedMessage(), null));
579
			}
580
			newResource.unload();
581
		}
582
	}
583
584
	/**
585
	 * @generated
586
	 */
587
	protected void handleElementChanged(ResourceSetInfo info, Resource changedResource, IProgressMonitor monitor) {
588
		IFile file = WorkspaceSynchronizer.getFile(changedResource);
589
		if(file != null) {
590
			try {
591
				file.refreshLocal(IResource.DEPTH_INFINITE, monitor);
592
			} catch (CoreException ex) {
593
				SysmlDiagramEditorPlugin.getInstance().logError(Messages.SysmlDocumentProvider_handleElementContentChanged, ex);
594
				// Error message to log was initially taken from org.eclipse.gmf.runtime.diagram.ui.resources.editor.ide.internal.l10n.EditorMessages.FileDocumentProvider_handleElementContentChanged
595
			}
596
		}
597
		changedResource.unload();
598
599
		fireElementContentAboutToBeReplaced(info.getEditorInput());
600
		removeUnchangedElementListeners(info.getEditorInput(), info);
601
		info.fStatus = null;
602
		try {
603
			setDocumentContent(info.fDocument, info.getEditorInput());
604
		} catch (CoreException e) {
605
			info.fStatus = e.getStatus();
606
		}
607
		if(!info.fCanBeSaved) {
608
			info.setModificationStamp(computeModificationStamp(info));
609
		}
610
		addUnchangedElementListeners(info.getEditorInput(), info);
611
		fireElementContentReplaced(info.getEditorInput());
612
	}
613
614
	/**
615
	 * @generated
616
	 */
617
	protected void handleElementMoved(IEditorInput input, URI uri) {
618
		if(input instanceof FileEditorInput) {
619
			IFile newFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(URI.decode(uri.path())).removeFirstSegments(1));
620
			fireElementMoved(input, newFile == null ? null : new FileEditorInput(newFile));
621
			return;
622
		}
623
		// TODO: append suffix to the URI! (use diagram as a parameter)
624
		fireElementMoved(input, new URIEditorInput(uri));
625
	}
626
627
	/**
628
	 * @generated
629
	 */
630
	public IEditorInput createInputWithEditingDomain(IEditorInput editorInput, TransactionalEditingDomain domain) {
631
		return editorInput;
632
	}
633
634
	/**
635
	 * @generated
636
	 */
637
	public IDiagramDocument getDiagramDocument(Object element) {
638
		IDocument doc = getDocument(element);
639
		if(doc instanceof IDiagramDocument) {
640
			return (IDiagramDocument)doc;
641
		}
642
		return null;
643
	}
644
645
	/**
646
	 * @generated
647
	 */
648
	protected IRunnableContext getOperationRunner(IProgressMonitor monitor) {
649
		return null;
650
	}
651
652
	/**
653
	 * @generated
654
	 */
655
	protected class ResourceSetInfo extends ElementInfo {
656
657
		/**
658
		 * @generated
659
		 */
660
		private long myModificationStamp = IResource.NULL_STAMP;
661
662
		/**
663
		 * @generated
664
		 */
665
		private WorkspaceSynchronizer mySynchronizer;
666
667
		/**
668
		 * @generated
669
		 */
670
		private LinkedList<Resource> myUnSynchronizedResources = new LinkedList<Resource>();
671
672
		/**
673
		 * @generated
674
		 */
675
		private IDiagramDocument myDocument;
676
677
		/**
678
		 * @generated
679
		 */
680
		private IEditorInput myEditorInput;
681
682
		/**
683
		 * @generated
684
		 */
685
		private boolean myUpdateCache = true;
686
687
		/**
688
		 * @generated
689
		 */
690
		private boolean myModifiable = false;
691
692
		/**
693
		 * @generated
694
		 */
695
		private boolean myReadOnly = true;
696
697
		/**
698
		 * @generated
699
		 */
700
		private ResourceSetModificationListener myResourceSetListener;
701
702
		/**
703
		 * @generated
704
		 */
705
		public ResourceSetInfo(IDiagramDocument document, IEditorInput editorInput) {
706
			super(document);
707
			myDocument = document;
708
			myEditorInput = editorInput;
709
			startResourceListening();
710
			myResourceSetListener = new ResourceSetModificationListener(this);
711
			getResourceSet().eAdapters().add(myResourceSetListener);
712
		}
713
714
		/**
715
		 * @generated
716
		 */
717
		public long getModificationStamp() {
718
			return myModificationStamp;
719
		}
720
721
		/**
722
		 * @generated
723
		 */
724
		public void setModificationStamp(long modificationStamp) {
725
			myModificationStamp = modificationStamp;
726
		}
727
728
		/**
729
		 * @generated
730
		 */
731
		public TransactionalEditingDomain getEditingDomain() {
732
			return myDocument.getEditingDomain();
733
		}
734
735
		/**
736
		 * @generated
737
		 */
738
		public ResourceSet getResourceSet() {
739
			return getEditingDomain().getResourceSet();
740
		}
741
742
		/**
743
		 * @generated
744
		 */
745
		public Iterator<Resource> getLoadedResourcesIterator() {
746
			return new ArrayList<Resource>(getResourceSet().getResources()).iterator();
747
		}
748
749
		/**
750
		 * @generated
751
		 */
752
		public IEditorInput getEditorInput() {
753
			return myEditorInput;
754
		}
755
756
		/**
757
		 * @generated
758
		 */
759
		public void dispose() {
760
			stopResourceListening();
761
			getResourceSet().eAdapters().remove(myResourceSetListener);
762
			for(Iterator<Resource> it = getLoadedResourcesIterator(); it.hasNext();) {
763
				Resource resource = it.next();
764
				resource.unload();
765
			}
766
			getEditingDomain().dispose();
767
		}
768
769
		/**
770
		 * @generated
771
		 */
772
		public boolean isSynchronized() {
773
			return myUnSynchronizedResources.size() == 0;
774
		}
775
776
		/**
777
		 * @generated
778
		 */
779
		public void setUnSynchronized(Resource resource) {
780
			myUnSynchronizedResources.add(resource);
781
		}
782
783
		/**
784
		 * @generated
785
		 */
786
		public void setSynchronized(Resource resource) {
787
			myUnSynchronizedResources.remove(resource);
788
		}
789
790
		/**
791
		 * @generated
792
		 */
793
		public final void stopResourceListening() {
794
			mySynchronizer.dispose();
795
			mySynchronizer = null;
796
		}
797
798
		/**
799
		 * @generated
800
		 */
801
		public final void startResourceListening() {
802
			mySynchronizer = new WorkspaceSynchronizer(getEditingDomain(), new SynchronizerDelegate());
803
		}
804
805
		/**
806
		 * @generated
807
		 */
808
		public boolean isUpdateCache() {
809
			return myUpdateCache;
810
		}
811
812
		/**
813
		 * @generated
814
		 */
815
		public void setUpdateCache(boolean update) {
816
			myUpdateCache = update;
817
		}
818
819
		/**
820
		 * @generated
821
		 */
822
		public boolean isModifiable() {
823
			return myModifiable;
824
		}
825
826
		/**
827
		 * @generated
828
		 */
829
		public void setModifiable(boolean modifiable) {
830
			myModifiable = modifiable;
831
		}
832
833
		/**
834
		 * @generated
835
		 */
836
		public boolean isReadOnly() {
837
			return myReadOnly;
838
		}
839
840
		/**
841
		 * @generated
842
		 */
843
		public void setReadOnly(boolean readOnly) {
844
			myReadOnly = readOnly;
845
		}
846
847
		/**
848
		 * @generated
849
		 */
850
		private class SynchronizerDelegate implements WorkspaceSynchronizer.Delegate {
851
852
			/**
853
			 * @generated
854
			 */
855
			public void dispose() {
856
			}
857
858
			/**
859
			 * @generated
860
			 */
861
			public boolean handleResourceChanged(final Resource resource) {
862
				synchronized(ResourceSetInfo.this) {
863
					if(ResourceSetInfo.this.fCanBeSaved) {
864
						ResourceSetInfo.this.setUnSynchronized(resource);
865
						return true;
866
					}
867
				}
868
				Display.getDefault().asyncExec(new Runnable() {
869
870
					public void run() {
871
						handleElementChanged(ResourceSetInfo.this, resource, null);
872
					}
873
				});
874
				return true;
875
			}
876
877
			/**
878
			 * @generated
879
			 */
880
			public boolean handleResourceDeleted(Resource resource) {
881
				synchronized(ResourceSetInfo.this) {
882
					if(ResourceSetInfo.this.fCanBeSaved) {
883
						ResourceSetInfo.this.setUnSynchronized(resource);
884
						return true;
885
					}
886
				}
887
				Display.getDefault().asyncExec(new Runnable() {
888
889
					public void run() {
890
						fireElementDeleted(ResourceSetInfo.this.getEditorInput());
891
					}
892
				});
893
				return true;
894
			}
895
896
			/**
897
			 * @generated
898
			 */
899
			public boolean handleResourceMoved(Resource resource, final URI newURI) {
900
				synchronized(ResourceSetInfo.this) {
901
					if(ResourceSetInfo.this.fCanBeSaved) {
902
						ResourceSetInfo.this.setUnSynchronized(resource);
903
						return true;
904
					}
905
				}
906
				if(myDocument.getDiagram().eResource() == resource) {
907
					Display.getDefault().asyncExec(new Runnable() {
908
909
						public void run() {
910
							handleElementMoved(ResourceSetInfo.this.getEditorInput(), newURI);
911
						}
912
					});
913
				} else {
914
					handleResourceDeleted(resource);
915
				}
916
				return true;
917
			}
918
919
		}
920
921
	}
922
923
	/**
924
	 * @generated
925
	 */
926
	private class ResourceSetModificationListener extends EContentAdapter {
927
928
		/**
929
		 * @generated
930
		 */
931
		private NotificationFilter myModifiedFilter;
932
933
		/**
934
		 * @generated
935
		 */
936
		private ResourceSetInfo myInfo;
937
938
		/**
939
		 * @generated
940
		 */
941
		public ResourceSetModificationListener(ResourceSetInfo info) {
942
			myInfo = info;
943
			myModifiedFilter = NotificationFilter.createEventTypeFilter(Notification.SET).or(NotificationFilter.createEventTypeFilter(Notification.UNSET)).and(NotificationFilter.createFeatureFilter(Resource.class, Resource.RESOURCE__IS_MODIFIED));
944
		}
945
946
		/**
947
		 * @generated
948
		 */
949
		public void notifyChanged(Notification notification) {
950
			if(notification.getNotifier() instanceof ResourceSet) {
951
				super.notifyChanged(notification);
952
			}
953
			if(!notification.isTouch() && myModifiedFilter.matches(notification)) {
954
				if(notification.getNotifier() instanceof Resource) {
955
					Resource resource = (Resource)notification.getNotifier();
956
					if(resource.isLoaded()) {
957
						boolean modified = false;
958
						for(Iterator/* <org.eclipse.emf.ecore.resource.Resource> */it = myInfo.getLoadedResourcesIterator(); it.hasNext() && !modified;) {
959
							Resource nextResource = (Resource)it.next();
960
							if(nextResource.isLoaded()) {
961
								modified = nextResource.isModified();
962
							}
963
						}
964
						boolean dirtyStateChanged = false;
965
						synchronized(myInfo) {
966
							if(modified != myInfo.fCanBeSaved) {
967
								myInfo.fCanBeSaved = modified;
968
								dirtyStateChanged = true;
969
							}
970
							if(!resource.isModified()) {
971
								myInfo.setSynchronized(resource);
972
							}
973
						}
974
						if(dirtyStateChanged) {
975
							fireElementDirtyStateChanged(myInfo.getEditorInput(), modified);
976
977
							if(!modified) {
978
								myInfo.setModificationStamp(computeModificationStamp(myInfo));
979
							}
980
						}
981
					}
982
				}
983
			}
984
		}
985
986
	}
987
988
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlInitDiagramFileAction.java (-99 lines)
Lines 1-99 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.core.resources.IFile;
17
import org.eclipse.emf.common.util.URI;
18
import org.eclipse.emf.common.util.WrappedException;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.resource.Resource;
21
import org.eclipse.emf.ecore.resource.ResourceSet;
22
import org.eclipse.emf.transaction.TransactionalEditingDomain;
23
import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
24
import org.eclipse.jface.action.IAction;
25
import org.eclipse.jface.dialogs.MessageDialog;
26
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.jface.wizard.Wizard;
29
import org.eclipse.osgi.util.NLS;
30
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.ui.IObjectActionDelegate;
33
import org.eclipse.ui.IWorkbenchPart;
34
35
/**
36
 * @generated
37
 */
38
public class SysmlInitDiagramFileAction implements IObjectActionDelegate {
39
40
	/**
41
	 * @generated
42
	 */
43
	private IWorkbenchPart targetPart;
44
45
	/**
46
	 * @generated
47
	 */
48
	private URI domainModelURI;
49
50
	/**
51
	 * @generated
52
	 */
53
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
54
		this.targetPart = targetPart;
55
	}
56
57
	/**
58
	 * @generated
59
	 */
60
	public void selectionChanged(IAction action, ISelection selection) {
61
		domainModelURI = null;
62
		action.setEnabled(false);
63
		if(selection instanceof IStructuredSelection == false || selection.isEmpty()) {
64
			return;
65
		}
66
		IFile file = (IFile)((IStructuredSelection)selection).getFirstElement();
67
		domainModelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
68
		action.setEnabled(true);
69
	}
70
71
	/**
72
	 * @generated
73
	 */
74
	private Shell getShell() {
75
		return targetPart.getSite().getShell();
76
	}
77
78
	/**
79
	 * @generated
80
	 */
81
	public void run(IAction action) {
82
		TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE.createEditingDomain();
83
		ResourceSet resourceSet = editingDomain.getResourceSet();
84
		EObject diagramRoot = null;
85
		try {
86
			Resource resource = resourceSet.getResource(domainModelURI, true);
87
			diagramRoot = (EObject)resource.getContents().get(0);
88
		} catch (WrappedException ex) {
89
			SysmlDiagramEditorPlugin.getInstance().logError("Unable to load resource: " + domainModelURI, ex); //$NON-NLS-1$
90
		}
91
		if(diagramRoot == null) {
92
			MessageDialog.openError(getShell(), Messages.InitDiagramFile_ResourceErrorDialogTitle, Messages.InitDiagramFile_ResourceErrorDialogMessage);
93
			return;
94
		}
95
		Wizard wizard = new SysmlNewDiagramFileWizard(domainModelURI, diagramRoot, editingDomain);
96
		wizard.setWindowTitle(NLS.bind(Messages.InitDiagramFile_WizardTitle, ParametricEditPart.MODEL_ID));
97
		SysmlDiagramEditorUtil.runWizard(getShell(), wizard, "InitDiagramFile"); //$NON-NLS-1$
98
	}
99
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlLinkDescriptor.java (-105 lines)
Lines 1-105 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
21
/**
22
 * @generated
23
 */
24
public class SysmlLinkDescriptor extends SysmlNodeDescriptor {
25
26
	/**
27
	 * @generated
28
	 */
29
	private EObject mySource;
30
31
	/**
32
	 * @generated
33
	 */
34
	private EObject myDestination;
35
36
	/**
37
	 * @generated
38
	 */
39
	private IAdaptable mySemanticAdapter;
40
41
	/**
42
	 * @generated
43
	 */
44
	private SysmlLinkDescriptor(EObject source, EObject destination, EObject linkElement, int linkVID) {
45
		super(linkElement, linkVID);
46
		mySource = source;
47
		myDestination = destination;
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	public SysmlLinkDescriptor(EObject source, EObject destination, IElementType elementType, int linkVID) {
54
		this(source, destination, (EObject)null, linkVID);
55
		final IElementType elementTypeCopy = elementType;
56
		mySemanticAdapter = new IAdaptable() {
57
58
			public Object getAdapter(Class adapter) {
59
				if(IElementType.class.equals(adapter)) {
60
					return elementTypeCopy;
61
				}
62
				return null;
63
			}
64
		};
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	public SysmlLinkDescriptor(EObject source, EObject destination, EObject linkElement, IElementType elementType, int linkVID) {
71
		this(source, destination, linkElement, linkVID);
72
		final IElementType elementTypeCopy = elementType;
73
		mySemanticAdapter = new EObjectAdapter(linkElement) {
74
75
			public Object getAdapter(Class adapter) {
76
				if(IElementType.class.equals(adapter)) {
77
					return elementTypeCopy;
78
				}
79
				return super.getAdapter(adapter);
80
			}
81
		};
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	public EObject getSource() {
88
		return mySource;
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public EObject getDestination() {
95
		return myDestination;
96
	}
97
98
	/**
99
	 * @generated
100
	 */
101
	public IAdaptable getSemanticAdapter() {
102
		return mySemanticAdapter;
103
	}
104
105
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlMatchingStrategy.java (-47 lines)
Lines 1-47 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.emf.common.ui.URIEditorInput;
17
import org.eclipse.ui.IEditorInput;
18
import org.eclipse.ui.IEditorMatchingStrategy;
19
import org.eclipse.ui.IEditorReference;
20
import org.eclipse.ui.PartInitException;
21
22
/**
23
 * @generated
24
 */
25
public class SysmlMatchingStrategy implements IEditorMatchingStrategy {
26
27
	/**
28
	 * @generated
29
	 */
30
	public boolean matches(IEditorReference editorRef, IEditorInput input) {
31
		IEditorInput editorInput;
32
		try {
33
			editorInput = editorRef.getEditorInput();
34
		} catch (PartInitException e) {
35
			return false;
36
		}
37
38
		if(editorInput.equals(input)) {
39
			return true;
40
		}
41
		if(editorInput instanceof URIEditorInput && input instanceof URIEditorInput) {
42
			return ((URIEditorInput)editorInput).getURI().equals(((URIEditorInput)input).getURI());
43
		}
44
		return false;
45
	}
46
47
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlNewDiagramFileWizard.java (-174 lines)
Lines 1-174 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.io.IOException;
17
import java.util.LinkedList;
18
19
import org.eclipse.core.commands.ExecutionException;
20
import org.eclipse.core.commands.operations.OperationHistoryFactory;
21
import org.eclipse.core.resources.IFile;
22
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.core.runtime.IPath;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.NullProgressMonitor;
26
import org.eclipse.core.runtime.Path;
27
import org.eclipse.emf.common.util.URI;
28
import org.eclipse.emf.ecore.EObject;
29
import org.eclipse.emf.ecore.resource.Resource;
30
import org.eclipse.emf.ecore.resource.ResourceSet;
31
import org.eclipse.emf.transaction.TransactionalEditingDomain;
32
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
33
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
34
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation;
35
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
36
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
37
import org.eclipse.gmf.runtime.notation.Diagram;
38
import org.eclipse.jface.viewers.StructuredSelection;
39
import org.eclipse.jface.wizard.Wizard;
40
import org.eclipse.osgi.util.NLS;
41
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
42
import org.eclipse.ui.PartInitException;
43
import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
44
45
/**
46
 * @generated
47
 */
48
public class SysmlNewDiagramFileWizard extends Wizard {
49
50
	/**
51
	 * @generated
52
	 */
53
	private WizardNewFileCreationPage myFileCreationPage;
54
55
	/**
56
	 * @generated
57
	 */
58
	private ModelElementSelectionPage diagramRootElementSelectionPage;
59
60
	/**
61
	 * @generated
62
	 */
63
	private TransactionalEditingDomain myEditingDomain;
64
65
	/**
66
	 * @generated
67
	 */
68
	public SysmlNewDiagramFileWizard(URI domainModelURI, EObject diagramRoot, TransactionalEditingDomain editingDomain) {
69
		assert domainModelURI != null : "Domain model uri must be specified"; //$NON-NLS-1$
70
		assert diagramRoot != null : "Doagram root element must be specified"; //$NON-NLS-1$
71
		assert editingDomain != null : "Editing domain must be specified"; //$NON-NLS-1$
72
73
		myFileCreationPage = new WizardNewFileCreationPage(Messages.SysmlNewDiagramFileWizard_CreationPageName, StructuredSelection.EMPTY);
74
		myFileCreationPage.setTitle(Messages.SysmlNewDiagramFileWizard_CreationPageTitle);
75
		myFileCreationPage.setDescription(NLS.bind(Messages.SysmlNewDiagramFileWizard_CreationPageDescription, ParametricEditPart.MODEL_ID));
76
		IPath filePath;
77
		String fileName = URI.decode(domainModelURI.trimFileExtension().lastSegment());
78
		if(domainModelURI.isPlatformResource()) {
79
			filePath = new Path(domainModelURI.trimSegments(1).toPlatformString(true));
80
		} else if(domainModelURI.isFile()) {
81
			filePath = new Path(domainModelURI.trimSegments(1).toFileString());
82
		} else {
83
			// TODO : use some default path
84
			throw new IllegalArgumentException("Unsupported URI: " + domainModelURI); //$NON-NLS-1$
85
		}
86
		myFileCreationPage.setContainerFullPath(filePath);
87
		myFileCreationPage.setFileName(SysmlDiagramEditorUtil.getUniqueFileName(filePath, fileName, "sysml_diagram")); //$NON-NLS-1$
88
89
		diagramRootElementSelectionPage = new DiagramRootElementSelectionPage(Messages.SysmlNewDiagramFileWizard_RootSelectionPageName);
90
		diagramRootElementSelectionPage.setTitle(Messages.SysmlNewDiagramFileWizard_RootSelectionPageTitle);
91
		diagramRootElementSelectionPage.setDescription(Messages.SysmlNewDiagramFileWizard_RootSelectionPageDescription);
92
		diagramRootElementSelectionPage.setModelElement(diagramRoot);
93
94
		myEditingDomain = editingDomain;
95
	}
96
97
	/**
98
	 * @generated
99
	 */
100
	public void addPages() {
101
		addPage(myFileCreationPage);
102
		addPage(diagramRootElementSelectionPage);
103
	}
104
105
	/**
106
	 * @generated
107
	 */
108
	public boolean performFinish() {
109
		LinkedList<IFile> affectedFiles = new LinkedList<IFile>();
110
		IFile diagramFile = myFileCreationPage.createNewFile();
111
		SysmlDiagramEditorUtil.setCharset(diagramFile);
112
		affectedFiles.add(diagramFile);
113
		URI diagramModelURI = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
114
		ResourceSet resourceSet = myEditingDomain.getResourceSet();
115
		final Resource diagramResource = resourceSet.createResource(diagramModelURI);
116
		AbstractTransactionalCommand command = new AbstractTransactionalCommand(myEditingDomain, Messages.SysmlNewDiagramFileWizard_InitDiagramCommand, affectedFiles) {
117
118
			protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
119
				int diagramVID = SysmlVisualIDRegistry.getDiagramVisualID(diagramRootElementSelectionPage.getModelElement());
120
				if(diagramVID != ParametricEditPart.VISUAL_ID) {
121
					return CommandResult.newErrorCommandResult(Messages.SysmlNewDiagramFileWizard_IncorrectRootError);
122
				}
123
				Diagram diagram = ViewService.createDiagram(diagramRootElementSelectionPage.getModelElement(), ParametricEditPart.MODEL_ID, SysmlDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT);
124
				diagramResource.getContents().add(diagram);
125
				return CommandResult.newOKCommandResult();
126
			}
127
		};
128
		try {
129
			OperationHistoryFactory.getOperationHistory().execute(command, new NullProgressMonitor(), null);
130
			diagramResource.save(SysmlDiagramEditorUtil.getSaveOptions());
131
			SysmlDiagramEditorUtil.openDiagram(diagramResource);
132
		} catch (ExecutionException e) {
133
			SysmlDiagramEditorPlugin.getInstance().logError("Unable to create model and diagram", e); //$NON-NLS-1$
134
		} catch (IOException ex) {
135
			SysmlDiagramEditorPlugin.getInstance().logError("Save operation failed for: " + diagramModelURI, ex); //$NON-NLS-1$
136
		} catch (PartInitException ex) {
137
			SysmlDiagramEditorPlugin.getInstance().logError("Unable to open editor", ex); //$NON-NLS-1$
138
		}
139
		return true;
140
	}
141
142
	/**
143
	 * @generated
144
	 */
145
	private static class DiagramRootElementSelectionPage extends ModelElementSelectionPage {
146
147
		/**
148
		 * @generated
149
		 */
150
		protected DiagramRootElementSelectionPage(String pageName) {
151
			super(pageName);
152
		}
153
154
		/**
155
		 * @generated
156
		 */
157
		protected String getSelectionTitle() {
158
			return Messages.SysmlNewDiagramFileWizard_RootSelectionPageSelectionTitle;
159
		}
160
161
		/**
162
		 * @generated
163
		 */
164
		protected boolean validatePage() {
165
			if(selectedModelElement == null) {
166
				setErrorMessage(Messages.SysmlNewDiagramFileWizard_RootSelectionPageNoSelectionMessage);
167
				return false;
168
			}
169
			boolean result = ViewService.getInstance().provides(new CreateDiagramViewOperation(new EObjectAdapter(selectedModelElement), ParametricEditPart.MODEL_ID, SysmlDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT));
170
			setErrorMessage(result ? null : Messages.SysmlNewDiagramFileWizard_RootSelectionPageInvalidSelectionMessage);
171
			return result;
172
		}
173
	}
174
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlNodeDescriptor.java (-55 lines)
Lines 1-55 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.emf.ecore.EObject;
17
18
/**
19
 * @generated
20
 */
21
public class SysmlNodeDescriptor {
22
23
	/**
24
	 * @generated
25
	 */
26
	private final EObject myModelElement;
27
28
	/**
29
	 * @generated
30
	 */
31
	private final int myVisualID;
32
33
	/**
34
	 * @generated
35
	 */
36
	public SysmlNodeDescriptor(EObject modelElement, int visualID) {
37
		myModelElement = modelElement;
38
		myVisualID = visualID;
39
	}
40
41
	/**
42
	 * @generated
43
	 */
44
	public EObject getModelElement() {
45
		return myModelElement;
46
	}
47
48
	/**
49
	 * @generated
50
	 */
51
	public int getVisualID() {
52
		return myVisualID;
53
	}
54
55
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlPaletteFactory.java (-111 lines)
Lines 1-111 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.util.ArrayList;
17
import java.util.List;
18
19
import org.eclipse.gef.Tool;
20
import org.eclipse.gmf.runtime.diagram.ui.services.palette.PaletteFactory;
21
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
22
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
23
import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeConnectionTool;
24
import org.eclipse.papyrus.uml.diagram.common.service.AspectUnspecifiedTypeCreationTool;
25
26
/**
27
 * @generated
28
 */
29
public class SysmlPaletteFactory extends PaletteFactory.Adapter {
30
31
	/**
32
	 * @generated
33
	 */
34
	private final static String CREATECONSTRAINTPROPERTY1CREATIONTOOL = "createConstraintProperty1CreationTool"; //$NON-NLS-1$
35
36
	/**
37
	 * @generated
38
	 */
39
	private final static String CREATEPROPERTY2CREATIONTOOL = "createProperty2CreationTool"; //$NON-NLS-1$
40
41
	/**
42
	 * @generated
43
	 */
44
	private final static String CREATECONNECTOR3CREATIONTOOL = "createConnector3CreationTool"; //$NON-NLS-1$
45
46
	/**
47
	 * @generated
48
	 */
49
	public SysmlPaletteFactory() {
50
51
	}
52
53
	/**
54
	 * @generated
55
	 */
56
	public Tool createTool(String toolId) {
57
		if(toolId.equals(CREATECONSTRAINTPROPERTY1CREATIONTOOL)) {
58
			return createConstraintProperty1CreationTool();
59
		}
60
		if(toolId.equals(CREATEPROPERTY2CREATIONTOOL)) {
61
			return createProperty2CreationTool();
62
		}
63
		if(toolId.equals(CREATECONNECTOR3CREATIONTOOL)) {
64
			return createConnector3CreationTool();
65
		}
66
67
		// default return: null
68
		return null;
69
	}
70
71
	public Object getTemplate(String templateId) {
72
73
		// default return: null
74
		return null;
75
	}
76
77
	/**
78
	 * @generated
79
	 */
80
	private Tool createConstraintProperty1CreationTool() {
81
		List<IElementType> types = new ArrayList<IElementType>(1);
82
		types.add(SysmlElementTypes.ConstraintProperty_2003);
83
84
		Tool tool = new AspectUnspecifiedTypeCreationTool(types);
85
		return tool;
86
	}
87
88
	/**
89
	 * @generated
90
	 */
91
	private Tool createProperty2CreationTool() {
92
		List<IElementType> types = new ArrayList<IElementType>(2);
93
		types.add(SysmlElementTypes.Property_3002);
94
		types.add(SysmlElementTypes.Property_2005);
95
96
		Tool tool = new AspectUnspecifiedTypeCreationTool(types);
97
		return tool;
98
	}
99
100
	/**
101
	 * @generated
102
	 */
103
	private Tool createConnector3CreationTool() {
104
		List<IElementType> types = new ArrayList<IElementType>(1);
105
		types.add(SysmlElementTypes.Connector_4001);
106
107
		Tool tool = new AspectUnspecifiedTypeConnectionTool(types);
108
		return tool;
109
	}
110
111
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlUriEditorInputTester.java (-35 lines)
Lines 1-35 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.core.expressions.PropertyTester;
17
import org.eclipse.emf.common.ui.URIEditorInput;
18
19
/**
20
 * @generated
21
 */
22
public class SysmlUriEditorInputTester extends PropertyTester {
23
24
	/**
25
	 * @generated
26
	 */
27
	public boolean test(Object receiver, String method, Object[] args, Object expectedValue) {
28
		if(false == receiver instanceof URIEditorInput) {
29
			return false;
30
		}
31
		URIEditorInput editorInput = (URIEditorInput)receiver;
32
		return "sysml_diagram".equals(editorInput.getURI().fileExtension()); //$NON-NLS-1$
33
	}
34
35
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/SysmlVisualIDRegistry.java (-283 lines)
Lines 1-283 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.emf.ecore.EAnnotation;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.gmf.runtime.notation.Diagram;
20
import org.eclipse.gmf.runtime.notation.View;
21
import org.eclipse.papyrus.resource.Resource;
22
import org.eclipse.papyrus.sysml.constraints.ConstraintsPackage;
23
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
24
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorNameEditPart;
25
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintLabelEditPart;
26
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
27
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyNameEditPart;
28
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
29
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
30
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyName2EditPart;
32
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyNameEditPart;
33
import org.eclipse.papyrus.uml.diagram.common.providers.BaseViewInfo;
34
import org.eclipse.papyrus.uml.diagram.common.providers.ViewInfo;
35
import org.eclipse.uml2.uml.UMLPackage;
36
37
/**
38
 * This registry is used to determine which type of visual object should be created for the
39
 * corresponding Diagram, Node, ChildNode or Link represented by a domain model object.
40
 * 
41
 * @generated
42
 */
43
public class SysmlVisualIDRegistry {
44
45
	/**
46
	 * @generated
47
	 */
48
	private static final String DEBUG_KEY = "org.eclipse.papyrus.sysml.diagram.parametric/debug/visualID"; //$NON-NLS-1$
49
50
	/**
51
	 * @generated
52
	 */
53
	public static int getVisualID(View view) {
54
		if(view instanceof Diagram) {
55
			if(ParametricEditPart.MODEL_ID.equals(view.getType())) {
56
				return ParametricEditPart.VISUAL_ID;
57
			} else {
58
				return -1;
59
			}
60
		}
61
		return org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry.getVisualID(view.getType());
62
	}
63
64
	/**
65
	 * @generated
66
	 */
67
	public static String getModelID(View view) {
68
		View diagram = view.getDiagram();
69
		while(view != diagram) {
70
			EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
71
			if(annotation != null) {
72
				return (String)annotation.getDetails().get("modelID"); //$NON-NLS-1$
73
			}
74
			view = (View)view.eContainer();
75
		}
76
		return diagram != null ? diagram.getType() : null;
77
	}
78
79
	/**
80
	 * @generated
81
	 */
82
	public static int getVisualID(String type) {
83
		try {
84
			return Integer.parseInt(type);
85
		} catch (NumberFormatException e) {
86
			if(Boolean.TRUE.toString().equalsIgnoreCase(Platform.getDebugOption(DEBUG_KEY))) {
87
				SysmlDiagramEditorPlugin.getInstance().logError("Unable to parse view type as a visualID number: " + type);
88
			}
89
		}
90
		return -1;
91
	}
92
93
	/**
94
	 * @generated
95
	 */
96
	public static String getType(int visualID) {
97
		return Integer.toString(visualID);
98
	}
99
100
	/**
101
	 * @generated NOT
102
	 */
103
	public static int getDiagramVisualID(EObject domainElement) {
104
		if(domainElement == null) {
105
			return -1;
106
		}
107
		// test if it is a class for the parametric diagram
108
		if(UMLPackage.eINSTANCE.getClass_().equals(domainElement.eClass())) {
109
			return ParametricEditPart.VISUAL_ID;
110
		}
111
		return -1;
112
	}
113
114
	/**
115
	 * @generated
116
	 */
117
	public static int getNodeVisualID(View containerView, EObject domainElement) {
118
		if(domainElement == null) {
119
			return -1;
120
		}
121
		String containerModelID = org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry.getModelID(containerView);
122
		if(!ParametricEditPart.MODEL_ID.equals(containerModelID)) {
123
			return -1;
124
		}
125
		int containerVisualID;
126
		if(ParametricEditPart.MODEL_ID.equals(containerModelID)) {
127
			containerVisualID = org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry.getVisualID(containerView);
128
		} else {
129
			if(containerView instanceof Diagram) {
130
				containerVisualID = ParametricEditPart.VISUAL_ID;
131
			} else {
132
				return -1;
133
			}
134
		}
135
		switch(containerVisualID) {
136
		case ParametricEditPart.VISUAL_ID:
137
			if(ConstraintsPackage.eINSTANCE.getConstraintProperty().isSuperTypeOf(domainElement.eClass())
138
139
			) {
140
				return ConstraintPropertyEditPart.VISUAL_ID;
141
			}
142
			if(UMLPackage.eINSTANCE.getProperty().isSuperTypeOf(domainElement.eClass())
143
144
			) {
145
				return PropertyEditPart.VISUAL_ID;
146
			}
147
			break;
148
		case ConstraintPropertyEditPart.VISUAL_ID:
149
			if(UMLPackage.eINSTANCE.getProperty().isSuperTypeOf(domainElement.eClass())
150
151
			) {
152
				return Property2EditPart.VISUAL_ID;
153
			}
154
			break;
155
		}
156
		return -1;
157
	}
158
159
	/**
160
	 * @generated
161
	 */
162
	public static boolean canCreateNode(View containerView, int nodeVisualID) {
163
		String containerModelID = org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry.getModelID(containerView);
164
		if(!ParametricEditPart.MODEL_ID.equals(containerModelID)) {
165
			return false;
166
		}
167
		int containerVisualID;
168
		if(ParametricEditPart.MODEL_ID.equals(containerModelID)) {
169
			containerVisualID = org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry.getVisualID(containerView);
170
		} else {
171
			if(containerView instanceof Diagram) {
172
				containerVisualID = ParametricEditPart.VISUAL_ID;
173
			} else {
174
				return false;
175
			}
176
		}
177
		switch(containerVisualID) {
178
		case ParametricEditPart.VISUAL_ID:
179
			if(ConstraintPropertyEditPart.VISUAL_ID == nodeVisualID) {
180
				return true;
181
			}
182
			if(PropertyEditPart.VISUAL_ID == nodeVisualID) {
183
				return true;
184
			}
185
			break;
186
		case ConstraintPropertyEditPart.VISUAL_ID:
187
			if(ConstraintPropertyNameEditPart.VISUAL_ID == nodeVisualID) {
188
				return true;
189
			}
190
			if(ConstraintLabelEditPart.VISUAL_ID == nodeVisualID) {
191
				return true;
192
			}
193
			if(Property2EditPart.VISUAL_ID == nodeVisualID) {
194
				return true;
195
			}
196
			break;
197
		case PropertyEditPart.VISUAL_ID:
198
			if(PropertyNameEditPart.VISUAL_ID == nodeVisualID) {
199
				return true;
200
			}
201
			break;
202
		case Property2EditPart.VISUAL_ID:
203
			if(PropertyName2EditPart.VISUAL_ID == nodeVisualID) {
204
				return true;
205
			}
206
			break;
207
		case ConnectorEditPart.VISUAL_ID:
208
			if(ConnectorNameEditPart.VISUAL_ID == nodeVisualID) {
209
				return true;
210
			}
211
			break;
212
		}
213
		return false;
214
	}
215
216
	/**
217
	 * @generated
218
	 */
219
	public static int getLinkWithClassVisualID(EObject domainElement) {
220
		if(domainElement == null) {
221
			return -1;
222
		}
223
		if(UMLPackage.eINSTANCE.getConnector().isSuperTypeOf(domainElement.eClass())
224
225
		) {
226
			return ConnectorEditPart.VISUAL_ID;
227
		}
228
		return -1;
229
	}
230
231
	/**
232
	 * User can change implementation of this method to handle some specific situations not covered
233
	 * by default logic.
234
	 * 
235
	 * @generated
236
	 */
237
	private static boolean isDiagram(Resource element) {
238
		return true;
239
	}
240
241
	/**
242
	 * @generated
243
	 */
244
	private static ViewInfo diagramViewInfo = null;
245
246
	/**
247
	 * @generated
248
	 */
249
	public static ViewInfo getDiagramViewInfo() {
250
		if(diagramViewInfo == null) {
251
			diagramViewInfo = getResource_1000ViewInfo();
252
		}
253
		return diagramViewInfo;
254
	}
255
256
	/**
257
	 * @generated
258
	 */
259
	protected static ViewInfo getResource_1000ViewInfo() {
260
		ViewInfo root = new BaseViewInfo(1000, ViewInfo.Head, "", null, null);
261
		ViewInfo viewInfo = null;
262
		ViewInfo labelInfo = null;
263
264
		viewInfo = new BaseViewInfo(2003, ViewInfo.Node, "ConstraintProperty");
265
		root.addNode(1000, viewInfo);
266
267
		viewInfo = new BaseViewInfo(2005, ViewInfo.Node, "Property");
268
		root.addNode(1000, viewInfo);
269
270
		viewInfo = new BaseViewInfo(4001, ViewInfo.Edge, "");
271
		root.addNode(1000, viewInfo);
272
273
		labelInfo = new BaseViewInfo(6001, ViewInfo.Label, "", null, viewInfo);
274
		viewInfo.getChildren().add(labelInfo);
275
276
		viewInfo = new BaseViewInfo(3002, ViewInfo.Node, "Property");
277
278
		root.addNode(2003, viewInfo);
279
280
		return root;
281
	}
282
283
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/part/ValidateAction.java (-264 lines)
Lines 1-264 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.part;
15
16
import java.lang.reflect.InvocationTargetException;
17
import java.util.ArrayList;
18
import java.util.HashSet;
19
import java.util.Iterator;
20
import java.util.List;
21
import java.util.Set;
22
23
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.runtime.IProgressMonitor;
25
import org.eclipse.core.runtime.IStatus;
26
import org.eclipse.core.runtime.NullProgressMonitor;
27
import org.eclipse.emf.common.util.Diagnostic;
28
import org.eclipse.emf.ecore.EObject;
29
import org.eclipse.emf.ecore.util.Diagnostician;
30
import org.eclipse.emf.transaction.TransactionalEditingDomain;
31
import org.eclipse.emf.transaction.util.TransactionUtil;
32
import org.eclipse.emf.validation.model.EvaluationMode;
33
import org.eclipse.emf.validation.model.IConstraintStatus;
34
import org.eclipse.emf.validation.service.IBatchValidator;
35
import org.eclipse.emf.validation.service.ModelValidationService;
36
import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
37
import org.eclipse.gef.EditPartViewer;
38
import org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory;
39
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
40
import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
41
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
42
import org.eclipse.gmf.runtime.notation.View;
43
import org.eclipse.jface.action.Action;
44
import org.eclipse.jface.operation.IRunnableWithProgress;
45
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlMarkerNavigationProvider;
46
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlValidationProvider;
47
import org.eclipse.ui.IEditorPart;
48
import org.eclipse.ui.IWorkbenchPage;
49
import org.eclipse.ui.IWorkbenchPart;
50
import org.eclipse.ui.PlatformUI;
51
import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
52
53
/**
54
 * @generated
55
 */
56
public class ValidateAction extends Action {
57
58
	/**
59
	 * @generated
60
	 */
61
	private IWorkbenchPage page;
62
63
	/**
64
	 * @generated
65
	 */
66
	public ValidateAction(IWorkbenchPage page) {
67
		setText(Messages.ValidateActionMessage);
68
		this.page = page;
69
	}
70
71
	/**
72
	 * @generated
73
	 */
74
	public void run() {
75
		IWorkbenchPart workbenchPart = page.getActivePart();
76
		if(workbenchPart instanceof IDiagramWorkbenchPart) {
77
			final IDiagramWorkbenchPart part = (IDiagramWorkbenchPart)workbenchPart;
78
			try {
79
				new WorkspaceModifyDelegatingOperation(new IRunnableWithProgress() {
80
81
					public void run(IProgressMonitor monitor) throws InterruptedException, InvocationTargetException {
82
						runValidation(part.getDiagramEditPart(), part.getDiagram());
83
					}
84
				}).run(new NullProgressMonitor());
85
			} catch (Exception e) {
86
				SysmlDiagramEditorPlugin.getInstance().logError("Validation action failed", e); //$NON-NLS-1$
87
			}
88
		}
89
	}
90
91
	/**
92
	 * @generated
93
	 */
94
	public static void runValidation(View view) {
95
		try {
96
			if(SysmlDiagramEditorUtil.openDiagram(view.eResource())) {
97
				IEditorPart editorPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
98
				if(editorPart instanceof IDiagramWorkbenchPart) {
99
					runValidation(((IDiagramWorkbenchPart)editorPart).getDiagramEditPart(), view);
100
				} else {
101
					runNonUIValidation(view);
102
				}
103
			}
104
		} catch (Exception e) {
105
			SysmlDiagramEditorPlugin.getInstance().logError("Validation action failed", e); //$NON-NLS-1$
106
		}
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	public static void runNonUIValidation(View view) {
113
		DiagramEditPart diagramEditPart = OffscreenEditPartFactory.getInstance().createDiagramEditPart(view.getDiagram());
114
		runValidation(diagramEditPart, view);
115
	}
116
117
	/**
118
	 * @generated
119
	 */
120
	public static void runValidation(DiagramEditPart diagramEditPart, View view) {
121
		final DiagramEditPart fpart = diagramEditPart;
122
		final View fview = view;
123
		TransactionalEditingDomain txDomain = TransactionUtil.getEditingDomain(view);
124
		SysmlValidationProvider.runWithConstraints(txDomain, new Runnable() {
125
126
			public void run() {
127
				validate(fpart, fview);
128
			}
129
		});
130
	}
131
132
	/**
133
	 * @generated
134
	 */
135
	private static Diagnostic runEMFValidator(View target) {
136
		if(target.isSetElement() && target.getElement() != null) {
137
			return new Diagnostician() {
138
139
				public String getObjectLabel(EObject eObject) {
140
					return EMFCoreUtil.getQualifiedName(eObject, true);
141
				}
142
			}.validate(target.getElement());
143
		}
144
		return Diagnostic.OK_INSTANCE;
145
	}
146
147
	/**
148
	 * @generated
149
	 */
150
	private static void validate(DiagramEditPart diagramEditPart, View view) {
151
		IFile target = view.eResource() != null ? WorkspaceSynchronizer.getFile(view.eResource()) : null;
152
		if(target != null) {
153
			SysmlMarkerNavigationProvider.deleteMarkers(target);
154
		}
155
		Diagnostic diagnostic = runEMFValidator(view);
156
		createMarkers(target, diagnostic, diagramEditPart);
157
		IBatchValidator validator = (IBatchValidator)ModelValidationService.getInstance().newValidator(EvaluationMode.BATCH);
158
		validator.setIncludeLiveConstraints(true);
159
		if(view.isSetElement() && view.getElement() != null) {
160
			IStatus status = validator.validate(view.getElement());
161
			createMarkers(target, status, diagramEditPart);
162
		}
163
	}
164
165
	/**
166
	 * @generated
167
	 */
168
	private static void createMarkers(IFile target, IStatus validationStatus, DiagramEditPart diagramEditPart) {
169
		if(validationStatus.isOK()) {
170
			return;
171
		}
172
		final IStatus rootStatus = validationStatus;
173
		List allStatuses = new ArrayList();
174
		SysmlDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new SysmlDiagramEditorUtil.LazyElement2ViewMap(diagramEditPart.getDiagramView(), collectTargetElements(rootStatus, new HashSet<EObject>(), allStatuses));
175
		for(Iterator it = allStatuses.iterator(); it.hasNext();) {
176
			IConstraintStatus nextStatus = (IConstraintStatus)it.next();
177
			View view = SysmlDiagramEditorUtil.findView(diagramEditPart, nextStatus.getTarget(), element2ViewMap);
178
			addMarker(diagramEditPart.getViewer(), target, view.eResource().getURIFragment(view), EMFCoreUtil.getQualifiedName(nextStatus.getTarget(), true), nextStatus.getMessage(), nextStatus.getSeverity());
179
		}
180
	}
181
182
	/**
183
	 * @generated
184
	 */
185
	private static void createMarkers(IFile target, Diagnostic emfValidationStatus, DiagramEditPart diagramEditPart) {
186
		if(emfValidationStatus.getSeverity() == Diagnostic.OK) {
187
			return;
188
		}
189
		final Diagnostic rootStatus = emfValidationStatus;
190
		List allDiagnostics = new ArrayList();
191
		SysmlDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new SysmlDiagramEditorUtil.LazyElement2ViewMap(diagramEditPart.getDiagramView(), collectTargetElements(rootStatus, new HashSet<EObject>(), allDiagnostics));
192
		for(Iterator it = emfValidationStatus.getChildren().iterator(); it.hasNext();) {
193
			Diagnostic nextDiagnostic = (Diagnostic)it.next();
194
			List data = nextDiagnostic.getData();
195
			if(data != null && !data.isEmpty() && data.get(0) instanceof EObject) {
196
				EObject element = (EObject)data.get(0);
197
				View view = SysmlDiagramEditorUtil.findView(diagramEditPart, element, element2ViewMap);
198
				addMarker(diagramEditPart.getViewer(), target, view.eResource().getURIFragment(view), EMFCoreUtil.getQualifiedName(element, true), nextDiagnostic.getMessage(), diagnosticToStatusSeverity(nextDiagnostic.getSeverity()));
199
			}
200
		}
201
	}
202
203
	/**
204
	 * @generated
205
	 */
206
	private static void addMarker(EditPartViewer viewer, IFile target, String elementId, String location, String message, int statusSeverity) {
207
		if(target == null) {
208
			return;
209
		}
210
		SysmlMarkerNavigationProvider.addMarker(target, elementId, location, message, statusSeverity);
211
	}
212
213
	/**
214
	 * @generated
215
	 */
216
	private static int diagnosticToStatusSeverity(int diagnosticSeverity) {
217
		if(diagnosticSeverity == Diagnostic.OK) {
218
			return IStatus.OK;
219
		} else if(diagnosticSeverity == Diagnostic.INFO) {
220
			return IStatus.INFO;
221
		} else if(diagnosticSeverity == Diagnostic.WARNING) {
222
			return IStatus.WARNING;
223
		} else if(diagnosticSeverity == Diagnostic.ERROR || diagnosticSeverity == Diagnostic.CANCEL) {
224
			return IStatus.ERROR;
225
		}
226
		return IStatus.INFO;
227
	}
228
229
	/**
230
	 * @generated
231
	 */
232
	private static Set<EObject> collectTargetElements(IStatus status, Set<EObject> targetElementCollector, List allConstraintStatuses) {
233
		if(status instanceof IConstraintStatus) {
234
			targetElementCollector.add(((IConstraintStatus)status).getTarget());
235
			allConstraintStatuses.add(status);
236
		}
237
		if(status.isMultiStatus()) {
238
			IStatus[] children = status.getChildren();
239
			for(int i = 0; i < children.length; i++) {
240
				collectTargetElements(children[i], targetElementCollector, allConstraintStatuses);
241
			}
242
		}
243
		return targetElementCollector;
244
	}
245
246
	/**
247
	 * @generated
248
	 */
249
	private static Set<EObject> collectTargetElements(Diagnostic diagnostic, Set<EObject> targetElementCollector, List allDiagnostics) {
250
		List data = diagnostic.getData();
251
		EObject target = null;
252
		if(data != null && !data.isEmpty() && data.get(0) instanceof EObject) {
253
			target = (EObject)data.get(0);
254
			targetElementCollector.add(target);
255
			allDiagnostics.add(diagnostic);
256
		}
257
		if(diagnostic.getChildren() != null && !diagnostic.getChildren().isEmpty()) {
258
			for(Iterator it = diagnostic.getChildren().iterator(); it.hasNext();) {
259
				collectTargetElements((Diagnostic)it.next(), targetElementCollector, allDiagnostics);
260
			}
261
		}
262
		return targetElementCollector;
263
	}
264
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomDefaultSemanticEditPolicy.java (+94 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.policies;
15
16
import org.eclipse.gef.commands.Command;
17
import org.eclipse.gef.commands.UnexecutableCommand;
18
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
19
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
20
import org.eclipse.gmf.runtime.notation.View;
21
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy;
22
import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry;
23
import org.eclipse.papyrus.sysml.diagram.parametric.provider.CustomGraphicalTypeRegistry;
24
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
25
import org.eclipse.papyrus.sysml.diagram.parametric.provider.GraphicalTypeRegistry;
26
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementCreateCommand;
27
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementReorientCommand;
28
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementCreateCommand;
29
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementReorientCommand;
30
import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
31
32
/**
33
 * <pre>
34
 * Custom semantic edit policy that replace DefaultSemanticEditPolicy
35
 * in order to manage Class Diagram specific elements (reference 
36
 * relationships COMMENT_ANNOTATED_ELEMENT and CONSTRAINT_CONSTRAINED_ELEMENT).
37
 * </pre>
38
 */
39
public class CustomDefaultSemanticEditPolicy extends DefaultSemanticEditPolicy {
40
41
	/** Local graphical type registry for graphical elements */
42
	private IGraphicalTypeRegistry registry = new CustomGraphicalTypeRegistry();
43
44
	/** Local graphical type registry for inherited graphical elements */
45
	private IGraphicalTypeRegistry inheritedRegistry = new GraphicalTypeRegistry();
46
47
	/**
48
	 * {@inheritDoc}
49
	 */
50
	@Override
51
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
52
53
		if(ElementTypes.COMMENT_ANNOTATED_ELEMENT == req.getElementType()) {
54
			return getGEFWrapper(new CommentAnnotatedElementCreateCommand(req, req.getSource(), req.getTarget()));
55
		}
56
57
		if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT == req.getElementType()) {
58
			return getGEFWrapper(new ConstraintConstrainedElementCreateCommand(req, req.getSource(), req.getTarget()));
59
		}
60
61
		String newEdgeGraphicalType = registry.getEdgeGraphicalType(req.getElementType());
62
63
		if(inheritedRegistry.isKnownEdgeType(newEdgeGraphicalType)) {
64
			return UnexecutableCommand.INSTANCE;
65
		}
66
67
		if(!registry.isKnownEdgeType(newEdgeGraphicalType)) {
68
			return UnexecutableCommand.INSTANCE;
69
		}
70
71
		return super.getCreateRelationshipCommand(req);
72
	}
73
74
	/**
75
	 * {@inheritDoc}
76
	 */
77
	@Override
78
	protected Command getReorientReferenceRelationshipCommand(ReorientReferenceRelationshipRequest req) {
79
80
		View reconnectedView = (View)req.getParameter(RequestParameterConstants.GRAPHICAL_RECONNECTED_EDGE);
81
		String reconnectedViewType = (reconnectedView != null) ? reconnectedView.getType() : IGraphicalTypeRegistry.UNDEFINED_TYPE;
82
83
		if(ElementTypes.COMMENT_ANNOTATED_ELEMENT.getSemanticHint().equals(reconnectedViewType)) {
84
			return getGEFWrapper(new CommentAnnotatedElementReorientCommand(req));
85
		}
86
87
		if(ElementTypes.CONSTRAINT_CONSTRAINED_ELEMENT.getSemanticHint().equals(reconnectedViewType)) {
88
			return getGEFWrapper(new ConstraintConstrainedElementReorientCommand(req));
89
		}
90
91
		return super.getReorientReferenceRelationshipCommand(req);
92
	}
93
94
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomDragDropEditPolicy.java (+277 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.policies;
15
16
import java.util.Collection;
17
import java.util.HashSet;
18
import java.util.Iterator;
19
import java.util.List;
20
import java.util.Set;
21
22
import org.eclipse.core.runtime.IAdaptable;
23
import org.eclipse.emf.ecore.EObject;
24
import org.eclipse.emf.ecore.EReference;
25
import org.eclipse.gmf.runtime.common.core.command.ICommand;
26
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
27
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
29
import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
30
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
31
import org.eclipse.gmf.runtime.notation.Diagram;
32
import org.eclipse.gmf.runtime.notation.NotationPackage;
33
import org.eclipse.gmf.runtime.notation.View;
34
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.CommonDiagramDragDropEditPolicy;
35
import org.eclipse.papyrus.sysml.blocks.NestedConnectorEnd;
36
import org.eclipse.papyrus.sysml.diagram.internalblock.dnd.helper.CustomLinkMappingHelper;
37
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.CustomGraphicalTypeRegistry;
38
import org.eclipse.papyrus.sysml.service.types.utils.ConnectorUtils;
39
import org.eclipse.papyrus.uml.diagram.common.commands.CommonDeferredCreateConnectionViewCommand;
40
import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
41
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
42
import org.eclipse.uml2.uml.Connector;
43
import org.eclipse.uml2.uml.ConnectorEnd;
44
import org.eclipse.uml2.uml.EncapsulatedClassifier;
45
import org.eclipse.uml2.uml.Port;
46
import org.eclipse.uml2.uml.Property;
47
import org.eclipse.uml2.uml.util.UMLUtil;
48
49
/** Customization of the DND edit policy for the Internal Block Diagram */
50
public class CustomDragDropEditPolicy extends CommonDiagramDragDropEditPolicy {
51
52
	private ConnectorUtils utils = new ConnectorUtils();
53
	
54
	/** Default constructor. */
55
	public CustomDragDropEditPolicy() {
56
		super(new CustomLinkMappingHelper());
57
		registry = new CustomGraphicalTypeRegistry();
58
	}
59
60
	/**
61
	 * {@inheritDoc}
62
	 */
63
	@Override
64
	protected Set<String> getSpecificDropBehaviorTypes() {
65
		Set<String> specificDropBehaviorTypes = new HashSet<String>();
66
67
		specificDropBehaviorTypes.add(UMLGraphicalTypes.LINK_UML_CONNECTOR_ID);
68
69
		return specificDropBehaviorTypes;
70
	}
71
72
	/**
73
	 * {@inheritDoc}
74
	 */
75
	@Override
76
	protected ICommand getSpecificDropCommand(DropObjectsRequest dropRequest, EObject droppedEObject, String nodeType, String edgeType) {
77
		if((UMLGraphicalTypes.LINK_UML_CONNECTOR_ID.equals(edgeType)) && (droppedEObject instanceof Connector)) {
78
			return getConnectorDropCommand(dropRequest, (Connector)droppedEObject, edgeType);
79
		}
80
81
		return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
82
	}
83
84
	protected ICommand getConnectorDropCommand(DropObjectsRequest dropRequest, Connector droppedEObject, String edgeType) {
85
86
		// Only manage binary link during drop
87
		if(droppedEObject.getEnds().size() != 2) {
88
			return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
89
		}
90
91
		ConnectorEnd source = droppedEObject.getEnds().get(0);
92
		ConnectorEnd target = droppedEObject.getEnds().get(1);
93
94
		// Find views in current diagram representing source and target 
95
		Collection<View> sourceViews = getViewsForConnectorEnd(source);
96
		Collection<View> targetViews = getViewsForConnectorEnd(target);
97
98
		IAdaptable sourceViewAdapter = null;
99
		IAdaptable targetViewAdapter = null;
100
101
		// If either a source or target lacks create view for these elements, abort...
102
		if(sourceViews.isEmpty() || targetViews.isEmpty()) {
103
			return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
104
		}
105
106
		View selectedSourceView = null;
107
		View selectedTargetView = null;
108
		// until a correct one is found, check that source and target views selected are correct given the current path for the connector...
109
		for(View sourceView : sourceViews) {
110
			View targetView = getFirstValidTargetViewForSource(sourceView, targetViews, droppedEObject);
111
			if(targetView !=null) {
112
				selectedSourceView = sourceView;
113
				selectedTargetView = targetView;
114
				break;
115
			}
116
		}
117
		
118
		
119
		// Create source adapter
120
		if(selectedSourceView!=null) { // sourceViewAdapter should still be null in this case
121
			sourceViewAdapter = new SemanticAdapter(null, selectedSourceView);
122
		} else {
123
			return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
124
		}
125
126
		// Create target adapter
127
		if(selectedTargetView!=null) { // targetViewAdapter should still be null in this case
128
			targetViewAdapter = new SemanticAdapter(null, selectedTargetView);
129
		} else {
130
			return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
131
		}
132
133
		// Create a view for the dropped link between the source and target view adapters
134
		IAdaptable droppedObjectAdapter = new SemanticAdapter(droppedEObject, null);
135
136
		CreateConnectionViewRequest.ConnectionViewDescriptor linkdescriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(droppedObjectAdapter, edgeType, getDiagramPreferencesHint());
137
138
		CommonDeferredCreateConnectionViewCommand createConnectionViewCommand = new CommonDeferredCreateConnectionViewCommand(getEditingDomain(), edgeType, sourceViewAdapter, targetViewAdapter, getViewer(), getDiagramPreferencesHint(), linkdescriptor, null);
139
		createConnectionViewCommand.setElement(droppedEObject);
140
141
		return createConnectionViewCommand;
142
	}
143
144
	/**
145
	 * get the first valid target view for the given source. the couple source/target is valid if the path to them from the future container is valid
146
	 * @param sourceView
147
	 * @param targetViews
148
	 * @return
149
	 */
150
	private View getFirstValidTargetViewForSource(View sourceView, Collection<View> targetViews, Connector droppedConnector) {
151
		for(View targetView : targetViews) {
152
			if(isValidTargetViewForSource(sourceView, targetView, droppedConnector)) {
153
				return targetView;
154
			}
155
		}
156
		 
157
		return null;
158
	}
159
	
160
	private boolean isValidTargetViewForSource(View sourceView, View targetView, Connector droppedConnector) {
161
		if(!(utils.isCrossingEncapsulation(sourceView, targetView))) {
162
			// no encapsulation. Computes the end paths
163
			List<Property> sourceNestedPaths = utils.getNestedPropertyPath(sourceView, targetView);
164
			List<Property> targetNestedPaths = utils.getNestedPropertyPath(targetView, sourceView);
165
			
166
			// check this is compatible with current connector
167
			ConnectorEnd sourceConnectorEnd = utils.getSourceConnectorEnd(droppedConnector);
168
			NestedConnectorEnd nestedSourceConnectorEnd = UMLUtil.getStereotypeApplication(sourceConnectorEnd, NestedConnectorEnd.class);
169
			if(nestedSourceConnectorEnd!=null) {
170
				List<Property> currentSourceConnectorPropertyPath = nestedSourceConnectorEnd.getPropertyPath();
171
				// compare the 2 list
172
				if(!sourceNestedPaths.equals(currentSourceConnectorPropertyPath)) {
173
					return false;
174
				}
175
				
176
			} else { // no end for the current connector, so the sourceNestedPath should be empty 
177
				if(!sourceNestedPaths.isEmpty()) {
178
					return false;
179
				}
180
			}
181
			
182
			
183
			ConnectorEnd targetConnectorEnd = utils.getTargetConnectorEnd(droppedConnector);
184
			NestedConnectorEnd nestedTargetConnectorEnd = UMLUtil.getStereotypeApplication(targetConnectorEnd, NestedConnectorEnd.class);
185
			if(nestedTargetConnectorEnd!=null) {
186
				List<Property> currentTargetConnectorPropertyPath = nestedTargetConnectorEnd.getPropertyPath();
187
				// compare the 2 list
188
				if(!targetNestedPaths.equals(currentTargetConnectorPropertyPath)) {
189
					return false;
190
				}
191
				
192
			} else { // no end for the current connector, so the targetNestedPaths should be empty 
193
				if(!targetNestedPaths.isEmpty()) {
194
					return false;
195
				}
196
			}
197
		}
198
		return true;
199
	}
200
201
	/**
202
	 * This methods looks for views representing a given {@link ConnectorEnd} in the host diagram.
203
	 * 
204
	 * @param end
205
	 *        the {@link ConnectorEnd} to look for.
206
	 * @return the list of {@link View} representing the eObject.
207
	 */
208
	protected Set<View> getViewsForConnectorEnd(ConnectorEnd end) {
209
		Set<View> views = new HashSet<View>();
210
211
		// Retrieve host diagram
212
		View hostView = ((IGraphicalEditPart)getHost()).getNotationView();
213
		View hostDiagram = (hostView instanceof Diagram) ? hostView : hostView.getDiagram();
214
215
		// Retrieve all views for the ConnectorEnd role
216
		EReference[] refs = { NotationPackage.eINSTANCE.getView_Element() };
217
		@SuppressWarnings("unchecked")
218
		Collection<View> relatedViews = EMFCoreUtil.getReferencers(end.getRole(), refs);
219
220
		// TODO: We should filter views not only for the current diagram,
221
		//       but also consider only views nested within the owner of the connector that are closest to the host view
222
		//       (in case there are several instances of a Part within which the connector could appear).
223
		// Connector connector = (Connector)end.getOwner();
224
		// StructuredClassifier connectorOwner = (StructuredClassifier)connector.getOwner();
225
		// Parse and select views from host diagram only	
226
		Iterator<View> it = relatedViews.iterator();
227
		while(it.hasNext()) {
228
			View currentView = it.next();
229
			if(currentView.getDiagram() == hostDiagram) { // FIXME: Cf TODO above.
230
231
				boolean isInView = false;
232
				View containerView = currentView;
233
				while(containerView != null && !(containerView instanceof Diagram)) {
234
					if(containerView == getReferenceViewForConnectorEnd()) {
235
						isInView = true;
236
					}
237
					containerView = ViewUtil.getContainerView(containerView);
238
				}
239
240
				if(isInView) {
241
242
					EObject containerElement = ViewUtil.getContainerView(currentView).getElement();
243
244
					// If the ConnectorEnd partWithPort is not null, only select Views for which 
245
					// the graphical parent reference partWithPort.
246
					if(end.getPartWithPort() != null) {
247
						if(containerElement == end.getPartWithPort()) {
248
							views.add(currentView);
249
						}
250
					} else {
251
						// If the role is a Port, its graphical parent is a EncapsulatedClassifier
252
						if(end.getRole() instanceof Port) {
253
							if(containerElement instanceof EncapsulatedClassifier) {
254
								views.add(currentView);
255
							} else if(containerElement instanceof Property) {
256
								Property property = (Property)containerElement;
257
								if(property.getType() == end.getRole().getOwner()) {
258
									views.add(currentView);
259
								}
260
							}
261
						} else { // No further test needed
262
							views.add(currentView);
263
						}
264
265
					}
266
				}
267
			}
268
		}
269
270
		return views;
271
	}
272
273
	protected View getReferenceViewForConnectorEnd() {
274
		return ((IGraphicalEditPart)getHost()).getNotationView();
275
	}
276
277
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomParametricSemanticPolicy.java (+38 lines)
Added Link Here
1
package org.eclipse.papyrus.sysml.diagram.parametric.policies;
2
3
import org.eclipse.gef.commands.Command;
4
import org.eclipse.gef.commands.UnexecutableCommand;
5
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
6
import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyCompositeEditPart;
7
import org.eclipse.papyrus.sysml.diagram.common.edit.part.ConstraintBlockPropertyCompositeEditPart;
8
import org.eclipse.papyrus.sysml.diagram.parametric.commands.CustomBindingConnectorCreateCommand;
9
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomBlockCompositeEditPartTN;
10
import org.eclipse.papyrus.sysml.diagram.parametric.edit.policy.DiagramSemanticEditPolicy;
11
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintParameterAffixedNodeEditPart;
12
import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedNodeEditPart;
13
import org.eclipse.uml2.uml.UMLPackage;
14
15
public class CustomParametricSemanticPolicy extends DiagramSemanticEditPolicy {
16
17
	@Override
18
	protected Command getCreateRelationshipCommand(CreateRelationshipRequest req) {
19
		if (req.getElementType().getEClass() == UMLPackage.eINSTANCE.getConnector()) {
20
			if (getHost() instanceof CustomBlockCompositeEditPartTN) {
21
				return UnexecutableCommand.INSTANCE;
22
			}
23
			if (getHost() instanceof ConstraintBlockPropertyCompositeEditPart) {
24
				return UnexecutableCommand.INSTANCE;			
25
			}
26
			if (getHost() instanceof ConstraintParameterAffixedNodeEditPart) {
27
				return getGEFWrapper(new CustomBindingConnectorCreateCommand(req));			
28
			}
29
			if (getHost() instanceof PortAffixedNodeEditPart) {
30
				return getGEFWrapper(new CustomBindingConnectorCreateCommand(req));				
31
			}
32
			if (getHost() instanceof BlockPropertyCompositeEditPart) {
33
				return getGEFWrapper(new CustomBindingConnectorCreateCommand(req));				
34
			}
35
		}
36
		return super.getCreateRelationshipCommand(req);
37
	}
38
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/StructureClassifierDropEditPolicy.java (+139 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.policies;
15
16
import java.util.ArrayList;
17
import java.util.List;
18
19
import org.eclipse.emf.transaction.RunnableWithResult;
20
import org.eclipse.gef.commands.Command;
21
import org.eclipse.gef.commands.UnexecutableCommand;
22
import org.eclipse.gmf.runtime.common.core.command.ICommand;
23
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
24
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
25
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
27
import org.eclipse.gmf.runtime.notation.View;
28
import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand;
29
import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomDragDropEditPolicy;
30
import org.eclipse.papyrus.sysml.diagram.parametric.utils.BlockDropHelper;
31
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
32
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
33
import org.eclipse.swt.widgets.Display;
34
import org.eclipse.ui.PlatformUI;
35
36
/**
37
 * <pre>
38
 * Customization of the DND edit policy for the StructureClassifier compartments, that enables the direct
39
 * creation of typed Part, Reference, Value, ActorPart or Property by dragging types in a Block structure compartment.
40
 * </pre>
41
 */
42
public class StructureClassifierDropEditPolicy extends CustomDragDropEditPolicy {
43
44
	/** Default constructor */
45
	public StructureClassifierDropEditPolicy() {
46
		super();
47
	}
48
49
	/**
50
	 * {@inheritedDoc}.
51
	 */
52
	@Override
53
	public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
54
55
		BlockDropHelper helper = new BlockDropHelper(getEditingDomain());
56
57
		// Single drop management possible drop action list can be proposed
58
		if(dropRequest.getObjects().size() == 1) {
59
60
			// List of available drop commands
61
			final List<Command> commandChoice = new ArrayList<Command>();
62
63
			// 1. Try to create a Part typed by the dropped object
64
			Command dropAsTypedPart = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.PART_PROPERTY);
65
			if((dropAsTypedPart != null) && (dropAsTypedPart.canExecute())) {
66
				commandChoice.add(dropAsTypedPart);
67
			}
68
69
			// 2. Try to create a Reference typed by the dropped object
70
			Command dropAsTypedReference = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.REFERENCE_PROPERTY);
71
			if((dropAsTypedReference != null) && (dropAsTypedReference.canExecute())) {
72
				commandChoice.add(dropAsTypedReference);
73
			}
74
75
			// 3. Try to create an ActorPart typed by the dropped object
76
			Command dropAsTypedActorPart = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.ACTOR_PART_PROPERTY);
77
			if((dropAsTypedActorPart != null) && (dropAsTypedActorPart.canExecute())) {
78
				commandChoice.add(dropAsTypedActorPart);
79
			}
80
81
			// 4. Try to create a Value typed by the dropped object
82
			Command dropAsTypedValue = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.VALUE_PROPERTY);
83
			if((dropAsTypedValue != null) && (dropAsTypedValue.canExecute())) {
84
				commandChoice.add(dropAsTypedValue);
85
			}
86
87
			// 5. Try to create a Property typed by the dropped object
88
			Command dropAsTypedProperty = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), UMLElementTypes.PROPERTY);
89
			if((dropAsTypedProperty != null) && (dropAsTypedProperty.canExecute())) {
90
				commandChoice.add(dropAsTypedProperty);
91
			}
92
			
93
			// 6. Try to create a ConstraintProperty typed by the dropped object
94
			Command dropAsTypedConstraintProperty = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart)getHost(), SysMLElementTypes.CONSTRAINT_PROPERTY);
95
			if((dropAsTypedConstraintProperty != null) && (dropAsTypedConstraintProperty.canExecute())) {
96
				commandChoice.add(dropAsTypedConstraintProperty);
97
			}
98
99
			// 7. Build default drop command (show view of the dropped object)
100
			Command defaultDropCommand = super.getDropObjectsCommand(dropRequest);
101
			defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)");
102
			if((defaultDropCommand != null) && (defaultDropCommand.canExecute())) {
103
				commandChoice.add(defaultDropCommand);
104
			}
105
106
			// Prepare the selection command (if several command are available) or return the drop command
107
			if(commandChoice.size() > 1) {
108
				RunnableWithResult<ICommand> runnable;
109
				Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() {
110
111
					public void run() {
112
						setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice));
113
					}
114
				});
115
116
				ICommand selectCommand = runnable.getResult();
117
118
				return new ICommandProxy(selectCommand);
119
120
			} else if(commandChoice.size() == 1) {
121
				return commandChoice.get(0);
122
			}
123
124
			// else (command choice is empty)
125
			return UnexecutableCommand.INSTANCE;
126
127
		}
128
129
		return super.getDropObjectsCommand(dropRequest);
130
	}
131
	
132
	/**
133
	 * {@inheritDoc}
134
	 */
135
	@Override
136
	protected View getReferenceViewForConnectorEnd() {
137
		return ViewUtil.getContainerView(super.getReferenceViewForConnectorEnd());
138
	}
139
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/BlockPropertyCompositePreferencePage.java (+42 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.gmf.runtime.common.ui.preferences.AbstractPreferencePage;
17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.swt.widgets.Composite;
19
20
public class BlockPropertyCompositePreferencePage extends AbstractPreferencePage {
21
22
	/** Constructor */
23
	public BlockPropertyCompositePreferencePage() {
24
		super();
25
	}
26
27
	/** Default preferences initializer */
28
	public static void initDefaults(IPreferenceStore store) {
29
		CustomBlockPropertyCompositePreferencePage.initDefaults(store);
30
		/*CustomNestedBlockPropertyCompositePreferencePage.initDefaults(store);*/
31
	}
32
33
	@Override
34
	protected void addFields(Composite parent) {
35
36
	}
37
38
	@Override
39
	protected void initHelp() {
40
41
	}
42
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ConnectorPreferencePage.java (-88 lines)
Lines 1-88 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import java.util.Map;
17
import java.util.TreeMap;
18
19
import org.eclipse.jface.preference.IPreferenceStore;
20
import org.eclipse.papyrus.infra.gmfdiag.preferences.pages.AbstractPapyrusLinkPreferencePage;
21
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
22
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
23
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
24
import org.eclipse.papyrus.uml.diagram.common.util.StringComparator;
25
26
/**
27
 * @generated
28
 */
29
public class ConnectorPreferencePage extends AbstractPapyrusLinkPreferencePage {
30
31
	/**
32
	 * @generated
33
	 */
34
	public ConnectorPreferencePage() {
35
		super();
36
		setPreferenceKey(ParametricEditPart.MODEL_ID + "_Connector");
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	@Override
43
	protected String getBundleId() {
44
		return SysmlDiagramEditorPlugin.ID;
45
	}
46
47
	/**
48
	 * @generated
49
	 */
50
	public static void initDefaults(IPreferenceStore store) {
51
52
		String key = ParametricEditPart.MODEL_ID + "_Connector";
53
		Map<String, Boolean> map = getStaticLabelVisibilityPreferences();
54
		for(String role : map.keySet()) {
55
			String preferenceName = PreferenceConstantHelper.getLabelElementConstant(key, role, PreferenceConstantHelper.LABEL_VISIBILITY);
56
			store.setDefault(preferenceName, map.get(role));
57
		}
58
59
	}
60
61
	/**
62
	 * @generated
63
	 */
64
	private static TreeMap<String, String> getStaticLabelRole() {
65
		TreeMap<String, String> map = new TreeMap<String, String>(new StringComparator());
66
		map.put("Name", "platform:/plugin/org.eclipse.papyrus.uml.diagram.common/icons/label_role/name.png");//$NON-NLS-1$ //$NON-NLS-2$
67
		return map;
68
	}
69
70
	/**
71
	 * @generated
72
	 */
73
	private static TreeMap<String, Boolean> getStaticLabelVisibilityPreferences() {
74
		TreeMap<String, Boolean> map = new TreeMap<String, Boolean>();
75
76
		map.put("Name", Boolean.FALSE);//$NON-NLS-1$
77
78
		return map;
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	protected TreeMap<String, String> getLabelRole() {
85
		return getStaticLabelRole();
86
	}
87
88
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ConstraintParameterAsBorderItemPreferencePage.java (+302 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULTVALUE;
17
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY;
18
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DERIVE;
19
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MODIFIERS;
20
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MULTIPLICITY;
21
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_NAME;
22
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_TYPE;
23
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_UNDEFINED_TYPE;
24
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_VISIBILITY;
25
26
import java.util.Collections;
27
import java.util.LinkedHashMap;
28
import java.util.Map;
29
30
import org.eclipse.jface.preference.IPreferenceStore;
31
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
32
import org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants;
33
import org.eclipse.papyrus.sysml.diagram.common.preferences.LabelPreferenceHelper;
34
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
35
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
36
import org.eclipse.swt.SWT;
37
import org.eclipse.swt.events.SelectionEvent;
38
import org.eclipse.swt.events.SelectionListener;
39
import org.eclipse.swt.layout.FormAttachment;
40
import org.eclipse.swt.layout.FormData;
41
import org.eclipse.swt.layout.FormLayout;
42
import org.eclipse.swt.widgets.Button;
43
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Group;
45
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
46
47
/**
48
 * {@link Port} preference page.
49
 */
50
public class ConstraintParameterAsBorderItemPreferencePage extends ParametricDiagramNodePreferencePage {
51
52
	/** Constant key to access preferences */
53
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_" + UMLGraphicalTypes.SHAPE_UML_PROPERTY_AS_AFFIXED_ID; //$NON-NLS-1$
54
55
	public static String prefLabelKey = prefKey + "-" + UMLGraphicalTypes.AFFIXEDLABEL_UML_PORT_LABEL_ID; //$NON-NLS-1$
56
57
	/** The labels default visibility for preferences */
58
	public static final Map<String, Boolean> labelDefaultVisibilityMap;
59
60
	/** Static attribute initialization */
61
	static {
62
		labelDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
63
		labelDefaultVisibilityMap.put("Stereotype", Boolean.TRUE); //$NON-NLS-1$	
64
		labelDefaultVisibilityMap.put("Label", Boolean.TRUE); //$NON-NLS-1$	
65
66
		// Start of user code custom static initializations
67
		// End of user code
68
69
		Collections.unmodifiableMap(labelDefaultVisibilityMap);
70
	}
71
72
	/** Constructor */
73
	public ConstraintParameterAsBorderItemPreferencePage() {
74
		super();
75
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_" + UMLGraphicalTypes.SHAPE_UML_PROPERTY_AS_AFFIXED_ID); //$NON-NLS-1$
76
	}
77
78
	/** Default preferences initializer */
79
	public static void initDefaults(IPreferenceStore store) {
80
		store.setDefault(LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE), DISP_NAME | DISP_TYPE | DISP_MULTIPLICITY | DISP_UNDEFINED_TYPE);
81
82
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.WIDTH), 20);
83
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.HEIGHT), 20);
84
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.ELEMENTICON), 0);
85
86
		// Initialize default visibility for labels in preference page.
87
		for(String labelName : labelDefaultVisibilityMap.keySet()) {
88
			String showLabelKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, labelName, PreferenceConstantHelper.LABEL_VISIBILITY);
89
			store.setDefault(showLabelKey, labelDefaultVisibilityMap.get(labelName));
90
		}
91
	}
92
93
	/**
94
	 * {@inheritDoc}
95
	 */
96
	@Override
97
	protected void initializeLabelsList() {
98
		for(String name : labelDefaultVisibilityMap.keySet()) {
99
			this.labelsList.add(name);
100
		}
101
	}
102
103
	/** buttons to select the display mask of the label */
104
	protected Button bttnVisibility, bttnDerive, bttnName, bttnType, bttnUndefined_Type, bttnMultiplicity, bttnDefault_Multiplicity, bttnDefaultValue, bttnModifiers;
105
106
	private String labelDisplayPreferenceKey = LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE);
107
108
	/** current property display style */
109
	private int propertyValue = getPreferenceStore().getInt(labelDisplayPreferenceKey);
110
111
	/**
112
	 * Creates a button with the {@link SWT#CHECK} style.
113
	 * 
114
	 * @param parent
115
	 *        the parent of the button
116
	 * @param label
117
	 *        the label of the button
118
	 * @param mask
119
	 *        the value controlled by the button
120
	 * @return the button created
121
	 */
122
	protected Button createCheckButton(Composite parent, String label, int mask) {
123
		Button button = new Button(parent, SWT.CHECK);
124
		button.setText(label);
125
		button.addSelectionListener(new AppearenceSelectionListener(mask));
126
		return button;
127
	}
128
129
	/**
130
	 * Creates the group and check boxes to choose the kind of display
131
	 * 
132
	 * @param parent
133
	 *        the parent composite that holds the group
134
	 */
135
	protected void createLabelPreferencesButtons(Composite parent) {
136
		// create group that host the buttons
137
		Group group = new Group(parent, SWT.SHADOW_NONE);
138
		group.setText("Label Display");
139
		group.setLayout(new FormLayout());
140
141
		FormData data;
142
143
		bttnVisibility = createCheckButton(group, "Visibility", DISP_VISIBILITY);
144
		data = new FormData();
145
		data.left = new FormAttachment(0, 0);
146
		data.top = new FormAttachment(0, 0);
147
		bttnVisibility.setLayoutData(data);
148
149
		bttnDerive = createCheckButton(group, "Derive", DISP_DERIVE);
150
		data = new FormData();
151
		data.left = new FormAttachment(bttnVisibility, 85);
152
		data.top = new FormAttachment(0, 0);
153
		bttnDerive.setLayoutData(data);
154
155
		bttnName = createCheckButton(group, "Name", DISP_NAME);
156
		data = new FormData();
157
		data.left = new FormAttachment(bttnDerive, 85);
158
		data.top = new FormAttachment(0, 0);
159
		bttnName.setLayoutData(data);
160
161
		bttnType = createCheckButton(group, "Type", DISP_TYPE);
162
		data = new FormData();
163
		data.left = new FormAttachment(bttnName, 85);
164
		data.top = new FormAttachment(0, 0);
165
		bttnType.setLayoutData(data);
166
167
		bttnUndefined_Type = createCheckButton(group, "Undefined_Type", DISP_UNDEFINED_TYPE);
168
		data = new FormData();
169
		data.left = new FormAttachment(0, 0);
170
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
171
		bttnUndefined_Type.setLayoutData(data);
172
173
		bttnMultiplicity = createCheckButton(group, "Multiplicity", DISP_MULTIPLICITY);
174
		data = new FormData();
175
		data.left = new FormAttachment(bttnVisibility, 85);
176
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
177
		bttnMultiplicity.setLayoutData(data);
178
179
		bttnDefault_Multiplicity = createCheckButton(group, "Default_Multiplicity", DISP_DEFAULT_MULTIPLICITY);
180
		data = new FormData();
181
		data.left = new FormAttachment(bttnDerive, 85);
182
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
183
		bttnDefault_Multiplicity.setLayoutData(data);
184
185
		bttnDefaultValue = createCheckButton(group, "DefaultValue", DISP_DEFAULTVALUE);
186
		data = new FormData();
187
		data.left = new FormAttachment(bttnName, 85);
188
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
189
		bttnDefaultValue.setLayoutData(data);
190
191
		bttnModifiers = createCheckButton(group, "Modifiers", DISP_MODIFIERS);
192
		data = new FormData();
193
		data.left = new FormAttachment(0, 0);
194
		data.top = new FormAttachment(bttnUndefined_Type, ITabbedPropertyConstants.HSPACE);
195
		bttnModifiers.setLayoutData(data);
196
197
	}
198
199
	/**
200
	 * {@inheritDoc}
201
	 */
202
	@Override
203
	protected void createPageContents(Composite parent) {
204
		super.createPageContents(parent);
205
206
		// adds the label preferences check boxes
207
		createLabelPreferencesButtons(parent);
208
209
		refreshButtons();
210
	}
211
212
	/**
213
	 * Load the default preferences of the fields contained in this page
214
	 */
215
	protected void loadDefaultPreferences() {
216
		propertyValue = getPreferenceStore().getDefaultInt(labelDisplayPreferenceKey);
217
		refreshButtons();
218
	}
219
220
	/**
221
	 * {@inheritDoc}
222
	 */
223
	@Override
224
	protected void performDefaults() {
225
		loadDefaultPreferences();
226
		super.performDefaults();
227
	}
228
229
	/**
230
	 * {@inheritDoc}
231
	 */
232
	@Override
233
	public boolean performOk() {
234
		storePreferences();
235
		return super.performOk();
236
	}
237
238
	/**
239
	 * Refresh the buttons that manages the display.
240
	 */
241
	protected void refreshButtons() {
242
243
		bttnVisibility.setSelection((propertyValue & DISP_VISIBILITY) == DISP_VISIBILITY);
244
		bttnDerive.setSelection((propertyValue & DISP_DERIVE) == DISP_DERIVE);
245
		bttnName.setSelection((propertyValue & DISP_NAME) == DISP_NAME);
246
		bttnType.setSelection((propertyValue & DISP_TYPE) == DISP_TYPE);
247
		bttnUndefined_Type.setSelection((propertyValue & DISP_UNDEFINED_TYPE) == DISP_UNDEFINED_TYPE);
248
		bttnMultiplicity.setSelection((propertyValue & DISP_MULTIPLICITY) == DISP_MULTIPLICITY);
249
		bttnDefault_Multiplicity.setSelection((propertyValue & DISP_DEFAULT_MULTIPLICITY) == DISP_DEFAULT_MULTIPLICITY);
250
		bttnDefaultValue.setSelection((propertyValue & DISP_DEFAULTVALUE) == DISP_DEFAULTVALUE);
251
		bttnModifiers.setSelection((propertyValue & DISP_MODIFIERS) == DISP_MODIFIERS);
252
253
	}
254
255
	/**
256
	 * Stores the values of the fields contained in this page into the preference store.
257
	 */
258
	protected void storePreferences() {
259
		super.storePreferences();
260
		IPreferenceStore store = getPreferenceStore();
261
		// checks the stored value and the actual one, so does not refresh diagram if it is not
262
		// needed
263
		if(propertyValue != store.getInt(labelDisplayPreferenceKey)) {
264
			store.setValue(labelDisplayPreferenceKey, propertyValue);
265
		}
266
	}
267
268
	/**
269
	 * Listeners for the check buttons that select the display.
270
	 */
271
	private class AppearenceSelectionListener implements SelectionListener {
272
273
		/** The constant which refers the element to display or not. */
274
		final private int style;
275
276
		/**
277
		 * Default Constructor.
278
		 * 
279
		 * @param style
280
		 */
281
		public AppearenceSelectionListener(int style) {
282
			this.style = style;
283
		}
284
285
		/**
286
		 * {@inheritDoc}
287
		 */
288
		public void widgetDefaultSelected(SelectionEvent e) {
289
290
		}
291
292
		/**
293
		 * {@inheritDoc}
294
		 */
295
		public void widgetSelected(SelectionEvent e) {
296
			// add or remove the flag to the display property value (invert the current value)
297
			propertyValue = propertyValue ^ style;
298
			// refresh buttons to show current values
299
			refreshButtons();
300
		}
301
	}
302
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/ConstraintPropertyPreferencePage.java (-64 lines)
Lines 1-64 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.papyrus.infra.gmfdiag.preferences.pages.AbstractPapyrusNodePreferencePage;
18
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
19
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
20
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
21
22
/**
23
 * @generated
24
 */
25
public class ConstraintPropertyPreferencePage extends AbstractPapyrusNodePreferencePage {
26
27
	/**
28
	 * @generated
29
	 */
30
	public ConstraintPropertyPreferencePage() {
31
		super();
32
		setPreferenceKey(ParametricEditPart.MODEL_ID + "_ConstraintProperty");
33
	}
34
35
	/**
36
	 * @generated
37
	 */
38
	@Override
39
	protected String getBundleId() {
40
		return SysmlDiagramEditorPlugin.ID;
41
	}
42
43
	/**
44
	 * @generated
45
	 */
46
	public static void initDefaults(IPreferenceStore store) {
47
48
		String key = ParametricEditPart.MODEL_ID + "_ConstraintProperty";
49
		store.setDefault(PreferenceConstantHelper.getElementConstant(key, PreferenceConstantHelper.WIDTH), 40);
50
		store.setDefault(PreferenceConstantHelper.getElementConstant(key, PreferenceConstantHelper.HEIGHT), 40);
51
52
		//org.eclipse.jface.preference.PreferenceConverter.setDefault(store, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.getElementConstant(elementName, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.COLOR_FILL), new org.eclipse.swt.graphics.RGB(255, 255, 255));
53
		//org.eclipse.jface.preference.PreferenceConverter.setDefault(store, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.getElementConstant(elementName, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.COLOR_LINE), new org.eclipse.swt.graphics.RGB(0, 0, 0));
54
55
		// Set the default for the gradient
56
		//store.setDefault(org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.getElementConstant(elementName, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.GRADIENT_POLICY),false);
57
		//org.eclipse.papyrus.infra.gmfdiag.preferences.utils.GradientPreferenceConverter gradientPreferenceConverter = new  org.eclipse.papyrus.infra.gmfdiag.preferences.utils.GradientPreferenceConverter(
58
		//		new org.eclipse.swt.graphics.RGB(255, 255, 255),
59
		//		new org.eclipse.swt.graphics.RGB(0, 0, 0), 0, 0);
60
		//store.setDefault(org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.getElementConstant(elementName, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.COLOR_GRADIENT), gradientPreferenceConverter.getPreferenceValue());
61
62
	}
63
64
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/CustomBlockPropertyCompositePreferencePage.java (+327 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULTVALUE;
17
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY;
18
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DERIVE;
19
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MODIFIERS;
20
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MULTIPLICITY;
21
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_NAME;
22
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_TYPE;
23
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_UNDEFINED_TYPE;
24
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_VISIBILITY;
25
26
import java.util.Collections;
27
import java.util.LinkedHashMap;
28
import java.util.Map;
29
30
import org.eclipse.jface.preference.IPreferenceStore;
31
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
32
import org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants;
33
import org.eclipse.papyrus.sysml.diagram.common.preferences.LabelPreferenceHelper;
34
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
35
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
36
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
37
import org.eclipse.swt.SWT;
38
import org.eclipse.swt.events.SelectionEvent;
39
import org.eclipse.swt.events.SelectionListener;
40
import org.eclipse.swt.layout.FormAttachment;
41
import org.eclipse.swt.layout.FormData;
42
import org.eclipse.swt.layout.FormLayout;
43
import org.eclipse.swt.widgets.Button;
44
import org.eclipse.swt.widgets.Composite;
45
import org.eclipse.swt.widgets.Group;
46
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
47
48
/**
49
 * Preference page for Part and References.
50
 */
51
public class CustomBlockPropertyCompositePreferencePage extends ParametricDiagramNodePreferencePage {
52
53
	/** Constant key to access preferences */
54
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_" + SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID; //$NON-NLS-1$
55
56
	public static String prefLabelKey = prefKey + "-" + UMLGraphicalTypes.LABEL_UML_PROPERTY_LABEL_ID; //$NON-NLS-1$	
57
58
	/** The compartments default visibility for preferences */
59
	public static final Map<String, Boolean> compartmentDefaultVisibilityMap;
60
61
	/** The compartment titles default visibility for preferences */
62
	public static final Map<String, Boolean> compartmentTitleDefaultVisibilityMap;
63
64
	/** Static attribute initialization */
65
	static {
66
		compartmentDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
67
		compartmentDefaultVisibilityMap.put("structure", Boolean.TRUE); //$NON-NLS-1$	
68
69
		compartmentTitleDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
70
		compartmentTitleDefaultVisibilityMap.put("structure", Boolean.TRUE); //$NON-NLS-1$
71
72
		// Start of user code custom static initializations
73
		compartmentTitleDefaultVisibilityMap.remove("structure"); //$NON-NLS-1$
74
		compartmentTitleDefaultVisibilityMap.put("structure", Boolean.FALSE); //$NON-NLS-1$
75
		// End of user code
76
77
		Collections.unmodifiableMap(compartmentDefaultVisibilityMap);
78
		Collections.unmodifiableMap(compartmentTitleDefaultVisibilityMap);
79
	}
80
81
	/** Constructor */
82
	public CustomBlockPropertyCompositePreferencePage() {
83
		super();
84
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_" + SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID); //$NON-NLS-1$
85
	}
86
87
	/** Default preferences initializer */
88
	public static void initDefaults(IPreferenceStore store) {
89
		// Start of user code custom default initializations
90
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.WIDTH), 200);
91
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.HEIGHT), 100);
92
		store.setDefault(LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE), DISP_NAME | DISP_TYPE | DISP_UNDEFINED_TYPE);
93
		// End of user code
94
95
		// Initialize default visibility for compartments in preference page.
96
		for(String compartmentName : compartmentDefaultVisibilityMap.keySet()) {
97
			String showCompartmentKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, compartmentName, PreferenceConstantHelper.COMPARTMENT_VISIBILITY);
98
			store.setDefault(showCompartmentKey, compartmentDefaultVisibilityMap.get(compartmentName));
99
		}
100
101
		// Initialize default title visibility for compartments in preference page.
102
		for(String compartmentName : compartmentTitleDefaultVisibilityMap.keySet()) {
103
			String showCompartmentTitleKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, compartmentName, PreferenceConstantHelper.COMPARTMENT_NAME_VISIBILITY);
104
			store.setDefault(showCompartmentTitleKey, compartmentTitleDefaultVisibilityMap.get(compartmentName));
105
		}
106
	}
107
108
	/**
109
	 * {@inheritDoc}
110
	 */
111
	@Override
112
	protected void initializeCompartmentNamesList() {
113
		for(String name : compartmentDefaultVisibilityMap.keySet()) {
114
			this.compartmentNamesList.add(name);
115
		}
116
	}
117
118
	/**
119
	 * {@inheritDoc}
120
	 */
121
	@Override
122
	protected void initializeCompartmentTitlesList() {
123
		for(String name : compartmentTitleDefaultVisibilityMap.keySet()) {
124
			this.compartmentTitlesList.add(name);
125
		}
126
	}
127
128
	/** buttons to select the display mask of the label */
129
	protected Button bttnVisibility, bttnDerive, bttnName, bttnType, bttnUndefined_Type, bttnMultiplicity, bttnDefault_Multiplicity, bttnDefaultValue, bttnModifiers;
130
131
	private String labelDisplayPreferenceKey = LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE);
132
133
	/** current property display style */
134
	private int propertyValue = getPreferenceStore().getInt(labelDisplayPreferenceKey);
135
136
	/**
137
	 * Creates a button with the {@link SWT#CHECK} style.
138
	 * 
139
	 * @param parent
140
	 *        the parent of the button
141
	 * @param label
142
	 *        the label of the button
143
	 * @param mask
144
	 *        the value controlled by the button
145
	 * @return the button created
146
	 */
147
	protected Button createCheckButton(Composite parent, String label, int mask) {
148
		Button button = new Button(parent, SWT.CHECK);
149
		button.setText(label);
150
		button.addSelectionListener(new AppearenceSelectionListener(mask));
151
		return button;
152
	}
153
154
	/**
155
	 * Creates the group and check boxes to choose the kind of display
156
	 * 
157
	 * @param parent
158
	 *        the parent composite that holds the group
159
	 */
160
	protected void createLabelPreferencesButtons(Composite parent) {
161
		// create group that host the buttons
162
		Group group = new Group(parent, SWT.SHADOW_NONE);
163
		group.setText("Label Display");
164
		group.setLayout(new FormLayout());
165
166
		FormData data;
167
168
		bttnVisibility = createCheckButton(group, "Visibility", DISP_VISIBILITY);
169
		data = new FormData();
170
		data.left = new FormAttachment(0, 0);
171
		data.top = new FormAttachment(0, 0);
172
		bttnVisibility.setLayoutData(data);
173
174
		bttnDerive = createCheckButton(group, "Derive", DISP_DERIVE);
175
		data = new FormData();
176
		data.left = new FormAttachment(bttnVisibility, 85);
177
		data.top = new FormAttachment(0, 0);
178
		bttnDerive.setLayoutData(data);
179
180
		bttnName = createCheckButton(group, "Name", DISP_NAME);
181
		data = new FormData();
182
		data.left = new FormAttachment(bttnDerive, 85);
183
		data.top = new FormAttachment(0, 0);
184
		bttnName.setLayoutData(data);
185
186
		bttnType = createCheckButton(group, "Type", DISP_TYPE);
187
		data = new FormData();
188
		data.left = new FormAttachment(bttnName, 85);
189
		data.top = new FormAttachment(0, 0);
190
		bttnType.setLayoutData(data);
191
192
		bttnUndefined_Type = createCheckButton(group, "Undefined_Type", DISP_UNDEFINED_TYPE);
193
		data = new FormData();
194
		data.left = new FormAttachment(0, 0);
195
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
196
		bttnUndefined_Type.setLayoutData(data);
197
198
		bttnMultiplicity = createCheckButton(group, "Multiplicity", DISP_MULTIPLICITY);
199
		data = new FormData();
200
		data.left = new FormAttachment(bttnVisibility, 85);
201
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
202
		bttnMultiplicity.setLayoutData(data);
203
204
		bttnDefault_Multiplicity = createCheckButton(group, "Default_Multiplicity", DISP_DEFAULT_MULTIPLICITY);
205
		data = new FormData();
206
		data.left = new FormAttachment(bttnDerive, 85);
207
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
208
		bttnDefault_Multiplicity.setLayoutData(data);
209
210
		bttnDefaultValue = createCheckButton(group, "DefaultValue", DISP_DEFAULTVALUE);
211
		data = new FormData();
212
		data.left = new FormAttachment(bttnName, 85);
213
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
214
		bttnDefaultValue.setLayoutData(data);
215
216
		bttnModifiers = createCheckButton(group, "Modifiers", DISP_MODIFIERS);
217
		data = new FormData();
218
		data.left = new FormAttachment(0, 0);
219
		data.top = new FormAttachment(bttnUndefined_Type, ITabbedPropertyConstants.HSPACE);
220
		bttnModifiers.setLayoutData(data);
221
222
	}
223
224
	/**
225
	 * {@inheritDoc}
226
	 */
227
	@Override
228
	protected void createPageContents(Composite parent) {
229
		super.createPageContents(parent);
230
231
		// adds the label preferences check boxes
232
		createLabelPreferencesButtons(parent);
233
234
		refreshButtons();
235
	}
236
237
	/**
238
	 * Load the default preferences of the fields contained in this page
239
	 */
240
	protected void loadDefaultPreferences() {
241
		propertyValue = getPreferenceStore().getDefaultInt(labelDisplayPreferenceKey);
242
		refreshButtons();
243
	}
244
245
	/**
246
	 * {@inheritDoc}
247
	 */
248
	@Override
249
	protected void performDefaults() {
250
		loadDefaultPreferences();
251
		super.performDefaults();
252
	}
253
254
	/**
255
	 * {@inheritDoc}
256
	 */
257
	@Override
258
	public boolean performOk() {
259
		storePreferences();
260
		return super.performOk();
261
	}
262
263
	/**
264
	 * Refresh the buttons that manages the display.
265
	 */
266
	protected void refreshButtons() {
267
268
		bttnVisibility.setSelection((propertyValue & DISP_VISIBILITY) == DISP_VISIBILITY);
269
		bttnDerive.setSelection((propertyValue & DISP_DERIVE) == DISP_DERIVE);
270
		bttnName.setSelection((propertyValue & DISP_NAME) == DISP_NAME);
271
		bttnType.setSelection((propertyValue & DISP_TYPE) == DISP_TYPE);
272
		bttnUndefined_Type.setSelection((propertyValue & DISP_UNDEFINED_TYPE) == DISP_UNDEFINED_TYPE);
273
		bttnMultiplicity.setSelection((propertyValue & DISP_MULTIPLICITY) == DISP_MULTIPLICITY);
274
		bttnDefault_Multiplicity.setSelection((propertyValue & DISP_DEFAULT_MULTIPLICITY) == DISP_DEFAULT_MULTIPLICITY);
275
		bttnDefaultValue.setSelection((propertyValue & DISP_DEFAULTVALUE) == DISP_DEFAULTVALUE);
276
		bttnModifiers.setSelection((propertyValue & DISP_MODIFIERS) == DISP_MODIFIERS);
277
278
	}
279
280
	/**
281
	 * Stores the values of the fields contained in this page into the preference store.
282
	 */
283
	protected void storePreferences() {
284
		super.storePreferences();
285
		IPreferenceStore store = getPreferenceStore();
286
		// checks the stored value and the actual one, so does not refresh diagram if it is not
287
		// needed
288
		if(propertyValue != store.getInt(labelDisplayPreferenceKey)) {
289
			store.setValue(labelDisplayPreferenceKey, propertyValue);
290
		}
291
	}
292
293
	/**
294
	 * Listeners for the check buttons that select the display.
295
	 */
296
	private class AppearenceSelectionListener implements SelectionListener {
297
298
		/** The constant which refers the element to display or not. */
299
		final private int style;
300
301
		/**
302
		 * Default Constructor.
303
		 * 
304
		 * @param style
305
		 */
306
		public AppearenceSelectionListener(int style) {
307
			this.style = style;
308
		}
309
310
		/**
311
		 * {@inheritDoc}
312
		 */
313
		public void widgetDefaultSelected(SelectionEvent e) {
314
315
		}
316
317
		/**
318
		 * {@inheritDoc}
319
		 */
320
		public void widgetSelected(SelectionEvent e) {
321
			// add or remove the flag to the display property value (invert the current value)
322
			propertyValue = propertyValue ^ style;
323
			// refresh buttons to show current values
324
			refreshButtons();
325
		}
326
	}
327
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/CustomConnectorPreferencePage.java (+464 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY;
17
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MULTIPLICITY;
18
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_NAME;
19
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_TYPE;
20
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_UNDEFINED_TYPE;
21
22
import java.util.Collections;
23
import java.util.LinkedHashMap;
24
import java.util.Map;
25
26
import org.eclipse.jface.preference.IPreferenceStore;
27
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
28
import org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants;
29
import org.eclipse.papyrus.sysml.diagram.common.preferences.LabelPreferenceHelper;
30
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
31
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
32
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.events.SelectionListener;
35
import org.eclipse.swt.layout.FormAttachment;
36
import org.eclipse.swt.layout.FormData;
37
import org.eclipse.swt.layout.FormLayout;
38
import org.eclipse.swt.widgets.Button;
39
import org.eclipse.swt.widgets.Composite;
40
import org.eclipse.swt.widgets.Group;
41
42
/**
43
 * {@link Connector} preference page.
44
 */
45
public class CustomConnectorPreferencePage extends ParametricDiagramLinkPreferencePage {
46
47
	/** Constant key to access preferences */
48
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_" + UMLGraphicalTypes.LINK_UML_CONNECTOR_ID; //$NON-NLS-1$
49
50
	/** The labels default visibility for preferences */
51
	public static final Map<String, Boolean> labelDefaultVisibilityMap;
52
53
	/** Static attribute initialization */
54
	static {
55
		labelDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
56
		labelDefaultVisibilityMap.put("Stereotype", Boolean.TRUE); //$NON-NLS-1$	
57
		labelDefaultVisibilityMap.put("Label", Boolean.TRUE); //$NON-NLS-1$	
58
		labelDefaultVisibilityMap.put("SourceMultiplicity", Boolean.TRUE); //$NON-NLS-1$	
59
		labelDefaultVisibilityMap.put("TargetMultiplicity", Boolean.TRUE); //$NON-NLS-1$	
60
61
		// Start of user code custom static initializations
62
		// End of user code
63
64
		Collections.unmodifiableMap(labelDefaultVisibilityMap);
65
	}
66
67
	/** Constructor */
68
	public CustomConnectorPreferencePage() {
69
		super();
70
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_" + UMLGraphicalTypes.LINK_UML_CONNECTOR_ID); //$NON-NLS-1$
71
	}
72
73
	/** Default preferences initializer */
74
	public static void initDefaults(IPreferenceStore store) {
75
		// Start of user code custom default initializations
76
77
		// Label default masks initialization
78
		store.setDefault(LabelPreferenceHelper.getPreferenceConstant(labelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE), DISP_NAME | DISP_TYPE);
79
		store.setDefault(LabelPreferenceHelper.getPreferenceConstant(sourceMultLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE), DISP_MULTIPLICITY);
80
		store.setDefault(LabelPreferenceHelper.getPreferenceConstant(targetMultLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE), DISP_MULTIPLICITY);
81
82
		// End of user code
83
84
		// Initialize default visibility for labels in preference page.
85
		for(String labelName : labelDefaultVisibilityMap.keySet()) {
86
			String showLabelKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, labelName, PreferenceConstantHelper.LABEL_VISIBILITY);
87
			store.setDefault(showLabelKey, labelDefaultVisibilityMap.get(labelName));
88
		}
89
	}
90
91
	/**
92
	 * {@inheritDoc}
93
	 */
94
	@Override
95
	protected void initializeLabelsList() {
96
		for(String name : labelDefaultVisibilityMap.keySet()) {
97
			this.labelsList.add(name);
98
		}
99
	}
100
101
	// Label display mask management in preference page
102
103
	/** buttons to select the display mask of the label */
104
	protected Button bttnName, bttnType, bttnUndefined_Type;
105
106
	/** buttons to select the display mask of the source labels */
107
	protected Button bttnSourceMultMultiplicity, bttnSourceMultDefault_Multiplicity;
108
109
	/** buttons to select the display mask of the target labels */
110
	protected Button bttnTargetMultMultiplicity, bttnTargetMultDefault_Multiplicity;
111
112
	/** Preference keys */
113
	public static String labelKey = ElementTypes.DIAGRAM_ID + "_" + UMLGraphicalTypes.LINK_UML_CONNECTOR_ID + "-" + UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_LABEL_ID; //$NON-NLS-1$	
114
115
	public static String sourceMultLabelKey = ElementTypes.DIAGRAM_ID + "_" + UMLGraphicalTypes.LINK_UML_CONNECTOR_ID + "-" + UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_SOURCE_MULTIPLICITY_ID; //$NON-NLS-1$	
116
117
	public static String targetMultLabelKey = ElementTypes.DIAGRAM_ID + "_" + UMLGraphicalTypes.LINK_UML_CONNECTOR_ID + "-" + UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_TARGET_MULTIPLICITY_ID; //$NON-NLS-1$	
118
119
	private String labelDisplayPreferenceKey = LabelPreferenceHelper.getPreferenceConstant(labelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE);
120
121
	private String sourceMultLabelDisplayPreferenceKey = LabelPreferenceHelper.getPreferenceConstant(sourceMultLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE);
122
123
	private String targetMultLabelDisplayPreferenceKey = LabelPreferenceHelper.getPreferenceConstant(targetMultLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE);
124
125
	/** Current property display styles for labels */
126
	private int labelDisplayValue = getPreferenceStore().getInt(labelDisplayPreferenceKey);
127
128
	private int sourceMultDisplayValue = getPreferenceStore().getInt(sourceMultLabelDisplayPreferenceKey);
129
130
	private int targetMultDisplayValue = getPreferenceStore().getInt(targetMultLabelDisplayPreferenceKey);
131
132
	/**
133
	 * Creates the group and check boxes to choose the kind of display
134
	 * 
135
	 * @param parent
136
	 *        the parent composite that holds the group
137
	 */
138
	protected void createLabelPreferencesButtons(Composite parent) {
139
		// create group that host the buttons
140
		Group group = new Group(parent, SWT.SHADOW_NONE);
141
		group.setText("Label Display");
142
		group.setLayout(new FormLayout());
143
144
		FormData data;
145
146
		bttnName = createLabelCheckButton(group, "Name", DISP_NAME);
147
		data = new FormData();
148
		data.left = new FormAttachment(0, 0);
149
		data.top = new FormAttachment(0, 0);
150
		bttnName.setLayoutData(data);
151
152
		bttnType = createLabelCheckButton(group, "Type", DISP_TYPE);
153
		data = new FormData();
154
		data.left = new FormAttachment(bttnName, 85);
155
		data.top = new FormAttachment(0, 0);
156
		bttnType.setLayoutData(data);
157
158
		bttnUndefined_Type = createLabelCheckButton(group, "Undefined_Type", DISP_UNDEFINED_TYPE);
159
		data = new FormData();
160
		data.left = new FormAttachment(bttnType, 85);
161
		data.top = new FormAttachment(0, 0);
162
		bttnUndefined_Type.setLayoutData(data);
163
	}
164
165
	/**
166
	 * Creates the group and check boxes to choose the kind of display
167
	 * 
168
	 * @param parent
169
	 *        the parent composite that holds the group
170
	 */
171
	protected void createSourceMultLabelPreferencesButtons(Composite parent) {
172
		// create group that host the buttons
173
		Group group = new Group(parent, SWT.SHADOW_NONE);
174
		group.setText("Source Multiplicity Label Display");
175
		group.setLayout(new FormLayout());
176
177
		FormData data;
178
179
		bttnSourceMultMultiplicity = createSourceMultCheckButton(group, "Multiplicity", DISP_MULTIPLICITY);
180
		data = new FormData();
181
		data.left = new FormAttachment(0, 0);
182
		data.top = new FormAttachment(0, 0);
183
		bttnSourceMultMultiplicity.setLayoutData(data);
184
185
		bttnSourceMultDefault_Multiplicity = createSourceMultCheckButton(group, "Default_Multiplicity", DISP_DEFAULT_MULTIPLICITY);
186
		data = new FormData();
187
		data.left = new FormAttachment(bttnSourceMultMultiplicity, 85);
188
		data.top = new FormAttachment(0, 0);
189
		bttnSourceMultDefault_Multiplicity.setLayoutData(data);
190
	}
191
192
	/**
193
	 * Creates the group and check boxes to choose the kind of display
194
	 * 
195
	 * @param parent
196
	 *        the parent composite that holds the group
197
	 */
198
	protected void createTargetMultLabelPreferencesButtons(Composite parent) {
199
		// create group that host the buttons
200
		Group group = new Group(parent, SWT.SHADOW_NONE);
201
		group.setText("Target Multiplicity Label Display");
202
		group.setLayout(new FormLayout());
203
204
		FormData data;
205
206
		bttnTargetMultMultiplicity = createTargetMultCheckButton(group, "Multiplicity", DISP_MULTIPLICITY);
207
		data = new FormData();
208
		data.left = new FormAttachment(0, 0);
209
		data.top = new FormAttachment(0, 0);
210
		bttnTargetMultMultiplicity.setLayoutData(data);
211
212
		bttnTargetMultDefault_Multiplicity = createTargetMultCheckButton(group, "Default_Multiplicity", DISP_DEFAULT_MULTIPLICITY);
213
		data = new FormData();
214
		data.left = new FormAttachment(bttnTargetMultMultiplicity, 85);
215
		data.top = new FormAttachment(0, 0);
216
		bttnTargetMultDefault_Multiplicity.setLayoutData(data);
217
	}
218
219
	/**
220
	 * {@inheritDoc}
221
	 */
222
	@Override
223
	protected void createPageContents(Composite parent) {
224
		super.createPageContents(parent);
225
226
		// adds the label preferences check boxes
227
		createLabelPreferencesButtons(parent);
228
		createSourceMultLabelPreferencesButtons(parent);
229
		createTargetMultLabelPreferencesButtons(parent);
230
231
		refreshButtons();
232
	}
233
234
	/**
235
	 * Load the default preferences of the fields contained in this page
236
	 */
237
	protected void loadDefaultPreferences() {
238
		labelDisplayValue = getPreferenceStore().getDefaultInt(labelDisplayPreferenceKey);
239
		sourceMultDisplayValue = getPreferenceStore().getDefaultInt(sourceMultLabelDisplayPreferenceKey);
240
		targetMultDisplayValue = getPreferenceStore().getDefaultInt(targetMultLabelDisplayPreferenceKey);
241
242
		refreshButtons();
243
	}
244
245
	/**
246
	 * {@inheritDoc}
247
	 */
248
	@Override
249
	protected void performDefaults() {
250
		loadDefaultPreferences();
251
		super.performDefaults();
252
	}
253
254
	/**
255
	 * {@inheritDoc}
256
	 */
257
	@Override
258
	public boolean performOk() {
259
		storePreferences();
260
		return super.performOk();
261
	}
262
263
	/**
264
	 * Refresh the buttons that manages the display.
265
	 */
266
	protected void refreshButtons() {
267
268
		// Label refresh buttons
269
		bttnName.setSelection((labelDisplayValue & DISP_NAME) == DISP_NAME);
270
		bttnType.setSelection((labelDisplayValue & DISP_TYPE) == DISP_TYPE);
271
		bttnUndefined_Type.setSelection((labelDisplayValue & DISP_UNDEFINED_TYPE) == DISP_UNDEFINED_TYPE);
272
273
		// Source Label Buttons
274
		bttnSourceMultMultiplicity.setSelection((sourceMultDisplayValue & DISP_MULTIPLICITY) == DISP_MULTIPLICITY);
275
		bttnSourceMultDefault_Multiplicity.setSelection((sourceMultDisplayValue & DISP_DEFAULT_MULTIPLICITY) == DISP_DEFAULT_MULTIPLICITY);
276
277
		// Target Label Buttons
278
		bttnTargetMultMultiplicity.setSelection((targetMultDisplayValue & DISP_MULTIPLICITY) == DISP_MULTIPLICITY);
279
		bttnTargetMultDefault_Multiplicity.setSelection((targetMultDisplayValue & DISP_DEFAULT_MULTIPLICITY) == DISP_DEFAULT_MULTIPLICITY);
280
281
	}
282
283
	/**
284
	 * Stores the values of the fields contained in this page into the preference store.
285
	 */
286
	protected void storePreferences() {
287
		super.storePreferences();
288
		IPreferenceStore store = getPreferenceStore();
289
		// checks the stored value and the actual one, so does not refresh diagram if it is not
290
		// needed
291
		if(labelDisplayValue != store.getInt(labelDisplayPreferenceKey)) {
292
			store.setValue(labelDisplayPreferenceKey, labelDisplayValue);
293
		}
294
		if(sourceMultDisplayValue != store.getInt(sourceMultLabelDisplayPreferenceKey)) {
295
			store.setValue(sourceMultLabelDisplayPreferenceKey, sourceMultDisplayValue);
296
		}
297
		if(targetMultDisplayValue != store.getInt(targetMultLabelDisplayPreferenceKey)) {
298
			store.setValue(targetMultLabelDisplayPreferenceKey, targetMultDisplayValue);
299
		}
300
	}
301
302
	/**
303
	 * Creates a button with the {@link SWT#CHECK} style.
304
	 * 
305
	 * @param parent
306
	 *        the parent of the button
307
	 * @param label
308
	 *        the label of the button
309
	 * @param mask
310
	 *        the value controlled by the button
311
	 * @return the button created
312
	 */
313
	protected Button createLabelCheckButton(Composite parent, String label, int mask) {
314
		Button button = new Button(parent, SWT.CHECK);
315
		button.setText(label);
316
		button.addSelectionListener(new LabelAppearenceSelectionListener(mask));
317
		return button;
318
	}
319
320
	/**
321
	 * Creates a button with the {@link SWT#CHECK} style.
322
	 * 
323
	 * @param parent
324
	 *        the parent of the button
325
	 * @param label
326
	 *        the label of the button
327
	 * @param mask
328
	 *        the value controlled by the button
329
	 * @return the button created
330
	 */
331
	protected Button createSourceMultCheckButton(Composite parent, String label, int mask) {
332
		Button button = new Button(parent, SWT.CHECK);
333
		button.setText(label);
334
		button.addSelectionListener(new SourceMultAppearenceSelectionListener(mask));
335
		return button;
336
	}
337
338
	/**
339
	 * Creates a button with the {@link SWT#CHECK} style.
340
	 * 
341
	 * @param parent
342
	 *        the parent of the button
343
	 * @param label
344
	 *        the label of the button
345
	 * @param mask
346
	 *        the value controlled by the button
347
	 * @return the button created
348
	 */
349
	protected Button createTargetMultCheckButton(Composite parent, String label, int mask) {
350
		Button button = new Button(parent, SWT.CHECK);
351
		button.setText(label);
352
		button.addSelectionListener(new TargetMultAppearenceSelectionListener(mask));
353
		return button;
354
	}
355
356
	/**
357
	 * Listeners for the check buttons that select the label display.
358
	 */
359
	private class LabelAppearenceSelectionListener implements SelectionListener {
360
361
		/** The constant which refers the element to display or not. */
362
		final private int style;
363
364
		/**
365
		 * Default Constructor.
366
		 * 
367
		 * @param style
368
		 */
369
		public LabelAppearenceSelectionListener(int style) {
370
			this.style = style;
371
		}
372
373
		/**
374
		 * {@inheritDoc}
375
		 */
376
		public void widgetDefaultSelected(SelectionEvent e) {
377
378
		}
379
380
		/**
381
		 * {@inheritDoc}
382
		 */
383
		public void widgetSelected(SelectionEvent e) {
384
			// add or remove the flag to the display property value (invert the current value)
385
			labelDisplayValue = labelDisplayValue ^ style;
386
387
			// refresh buttons to show current values
388
			refreshButtons();
389
		}
390
	}
391
392
	/**
393
	 * Listeners for the check buttons that select the source multiplicity display.
394
	 */
395
	private class SourceMultAppearenceSelectionListener implements SelectionListener {
396
397
		/** The constant which refers the element to display or not. */
398
		final private int style;
399
400
		/**
401
		 * Default Constructor.
402
		 * 
403
		 * @param style
404
		 */
405
		public SourceMultAppearenceSelectionListener(int style) {
406
			this.style = style;
407
		}
408
409
		/**
410
		 * {@inheritDoc}
411
		 */
412
		public void widgetDefaultSelected(SelectionEvent e) {
413
414
		}
415
416
		/**
417
		 * {@inheritDoc}
418
		 */
419
		public void widgetSelected(SelectionEvent e) {
420
			// add or remove the flag to the display property value (invert the current value)
421
			sourceMultDisplayValue = sourceMultDisplayValue ^ style;
422
423
			// refresh buttons to show current values
424
			refreshButtons();
425
		}
426
	}
427
428
	/**
429
	 * Listeners for the check buttons that select the target multiplicity display.
430
	 */
431
	private class TargetMultAppearenceSelectionListener implements SelectionListener {
432
433
		/** The constant which refers the element to display or not. */
434
		final private int style;
435
436
		/**
437
		 * Default Constructor.
438
		 * 
439
		 * @param style
440
		 */
441
		public TargetMultAppearenceSelectionListener(int style) {
442
			this.style = style;
443
		}
444
445
		/**
446
		 * {@inheritDoc}
447
		 */
448
		public void widgetDefaultSelected(SelectionEvent e) {
449
450
		}
451
452
		/**
453
		 * {@inheritDoc}
454
		 */
455
		public void widgetSelected(SelectionEvent e) {
456
			// add or remove the flag to the display property value (invert the current value)
457
			targetMultDisplayValue = targetMultDisplayValue ^ style;
458
459
			// refresh buttons to show current values
460
			refreshButtons();
461
		}
462
	}
463
464
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/CustomConstraintPropertyCompositePreferencePage.java (+327 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULTVALUE;
17
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY;
18
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DERIVE;
19
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MODIFIERS;
20
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MULTIPLICITY;
21
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_NAME;
22
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_TYPE;
23
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_UNDEFINED_TYPE;
24
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_VISIBILITY;
25
26
import java.util.Collections;
27
import java.util.LinkedHashMap;
28
import java.util.Map;
29
30
import org.eclipse.jface.preference.IPreferenceStore;
31
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
32
import org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants;
33
import org.eclipse.papyrus.sysml.diagram.common.preferences.LabelPreferenceHelper;
34
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
35
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
36
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
37
import org.eclipse.swt.SWT;
38
import org.eclipse.swt.events.SelectionEvent;
39
import org.eclipse.swt.events.SelectionListener;
40
import org.eclipse.swt.layout.FormAttachment;
41
import org.eclipse.swt.layout.FormData;
42
import org.eclipse.swt.layout.FormLayout;
43
import org.eclipse.swt.widgets.Button;
44
import org.eclipse.swt.widgets.Composite;
45
import org.eclipse.swt.widgets.Group;
46
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
47
48
/**
49
 * Preference page for Part and References.
50
 */
51
public class CustomConstraintPropertyCompositePreferencePage extends ParametricDiagramNodePreferencePage {
52
53
	/** Constant key to access preferences */
54
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_" + SysMLGraphicalTypes.SHAPE_SYSML_CONSTRAINTBLOCKPROPERTY_AS_COMPOSITE_ID; //$NON-NLS-1$
55
56
	public static String prefLabelKey = prefKey + "-" + UMLGraphicalTypes.LABEL_UML_PROPERTY_LABEL_ID; //$NON-NLS-1$	
57
58
	/** The compartments default visibility for preferences */
59
	public static final Map<String, Boolean> compartmentDefaultVisibilityMap;
60
61
	/** The compartment titles default visibility for preferences */
62
	public static final Map<String, Boolean> compartmentTitleDefaultVisibilityMap;
63
64
	/** Static attribute initialization */
65
	static {
66
		compartmentDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
67
		compartmentDefaultVisibilityMap.put("structure", Boolean.TRUE); //$NON-NLS-1$	
68
69
		compartmentTitleDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
70
		compartmentTitleDefaultVisibilityMap.put("structure", Boolean.TRUE); //$NON-NLS-1$
71
72
		// Start of user code custom static initializations
73
		compartmentTitleDefaultVisibilityMap.remove("structure"); //$NON-NLS-1$
74
		compartmentTitleDefaultVisibilityMap.put("structure", Boolean.FALSE); //$NON-NLS-1$
75
		// End of user code
76
77
		Collections.unmodifiableMap(compartmentDefaultVisibilityMap);
78
		Collections.unmodifiableMap(compartmentTitleDefaultVisibilityMap);
79
	}
80
81
	/** Constructor */
82
	public CustomConstraintPropertyCompositePreferencePage() {
83
		super();
84
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_" + SysMLGraphicalTypes.SHAPE_SYSML_BLOCKPROPERTY_AS_COMPOSITE_ID); //$NON-NLS-1$
85
	}
86
87
	/** Default preferences initializer */
88
	public static void initDefaults(IPreferenceStore store) {
89
		// Start of user code custom default initializations
90
//		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.WIDTH), 200);
91
//		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.HEIGHT), 100);
92
		store.setDefault(LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE), DISP_NAME | DISP_TYPE | DISP_UNDEFINED_TYPE);
93
		// End of user code
94
95
		// Initialize default visibility for compartments in preference page.
96
		for(String compartmentName : compartmentDefaultVisibilityMap.keySet()) {
97
			String showCompartmentKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, compartmentName, PreferenceConstantHelper.COMPARTMENT_VISIBILITY);
98
			store.setDefault(showCompartmentKey, compartmentDefaultVisibilityMap.get(compartmentName));
99
		}
100
101
		// Initialize default title visibility for compartments in preference page.
102
		for(String compartmentName : compartmentTitleDefaultVisibilityMap.keySet()) {
103
			String showCompartmentTitleKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, compartmentName, PreferenceConstantHelper.COMPARTMENT_NAME_VISIBILITY);
104
			store.setDefault(showCompartmentTitleKey, compartmentTitleDefaultVisibilityMap.get(compartmentName));
105
		}
106
	}
107
108
	/**
109
	 * {@inheritDoc}
110
	 */
111
	@Override
112
	protected void initializeCompartmentNamesList() {
113
		for(String name : compartmentDefaultVisibilityMap.keySet()) {
114
			this.compartmentNamesList.add(name);
115
		}
116
	}
117
118
	/**
119
	 * {@inheritDoc}
120
	 */
121
	@Override
122
	protected void initializeCompartmentTitlesList() {
123
		for(String name : compartmentTitleDefaultVisibilityMap.keySet()) {
124
			this.compartmentTitlesList.add(name);
125
		}
126
	}
127
128
	/** buttons to select the display mask of the label */
129
	protected Button bttnVisibility, bttnDerive, bttnName, bttnType, bttnUndefined_Type, bttnMultiplicity, bttnDefault_Multiplicity, bttnDefaultValue, bttnModifiers;
130
131
	private String labelDisplayPreferenceKey = LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE);
132
133
	/** current property display style */
134
	private int propertyValue = getPreferenceStore().getInt(labelDisplayPreferenceKey);
135
136
	/**
137
	 * Creates a button with the {@link SWT#CHECK} style.
138
	 * 
139
	 * @param parent
140
	 *        the parent of the button
141
	 * @param label
142
	 *        the label of the button
143
	 * @param mask
144
	 *        the value controlled by the button
145
	 * @return the button created
146
	 */
147
	protected Button createCheckButton(Composite parent, String label, int mask) {
148
		Button button = new Button(parent, SWT.CHECK);
149
		button.setText(label);
150
		button.addSelectionListener(new AppearenceSelectionListener(mask));
151
		return button;
152
	}
153
154
	/**
155
	 * Creates the group and check boxes to choose the kind of display
156
	 * 
157
	 * @param parent
158
	 *        the parent composite that holds the group
159
	 */
160
	protected void createLabelPreferencesButtons(Composite parent) {
161
		// create group that host the buttons
162
		Group group = new Group(parent, SWT.SHADOW_NONE);
163
		group.setText("Label Display");
164
		group.setLayout(new FormLayout());
165
166
		FormData data;
167
168
		bttnVisibility = createCheckButton(group, "Visibility", DISP_VISIBILITY);
169
		data = new FormData();
170
		data.left = new FormAttachment(0, 0);
171
		data.top = new FormAttachment(0, 0);
172
		bttnVisibility.setLayoutData(data);
173
174
		bttnDerive = createCheckButton(group, "Derive", DISP_DERIVE);
175
		data = new FormData();
176
		data.left = new FormAttachment(bttnVisibility, 85);
177
		data.top = new FormAttachment(0, 0);
178
		bttnDerive.setLayoutData(data);
179
180
		bttnName = createCheckButton(group, "Name", DISP_NAME);
181
		data = new FormData();
182
		data.left = new FormAttachment(bttnDerive, 85);
183
		data.top = new FormAttachment(0, 0);
184
		bttnName.setLayoutData(data);
185
186
		bttnType = createCheckButton(group, "Type", DISP_TYPE);
187
		data = new FormData();
188
		data.left = new FormAttachment(bttnName, 85);
189
		data.top = new FormAttachment(0, 0);
190
		bttnType.setLayoutData(data);
191
192
		bttnUndefined_Type = createCheckButton(group, "Undefined_Type", DISP_UNDEFINED_TYPE);
193
		data = new FormData();
194
		data.left = new FormAttachment(0, 0);
195
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
196
		bttnUndefined_Type.setLayoutData(data);
197
198
		bttnMultiplicity = createCheckButton(group, "Multiplicity", DISP_MULTIPLICITY);
199
		data = new FormData();
200
		data.left = new FormAttachment(bttnVisibility, 85);
201
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
202
		bttnMultiplicity.setLayoutData(data);
203
204
		bttnDefault_Multiplicity = createCheckButton(group, "Default_Multiplicity", DISP_DEFAULT_MULTIPLICITY);
205
		data = new FormData();
206
		data.left = new FormAttachment(bttnDerive, 85);
207
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
208
		bttnDefault_Multiplicity.setLayoutData(data);
209
210
		bttnDefaultValue = createCheckButton(group, "DefaultValue", DISP_DEFAULTVALUE);
211
		data = new FormData();
212
		data.left = new FormAttachment(bttnName, 85);
213
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
214
		bttnDefaultValue.setLayoutData(data);
215
216
		bttnModifiers = createCheckButton(group, "Modifiers", DISP_MODIFIERS);
217
		data = new FormData();
218
		data.left = new FormAttachment(0, 0);
219
		data.top = new FormAttachment(bttnUndefined_Type, ITabbedPropertyConstants.HSPACE);
220
		bttnModifiers.setLayoutData(data);
221
222
	}
223
224
	/**
225
	 * {@inheritDoc}
226
	 */
227
	@Override
228
	protected void createPageContents(Composite parent) {
229
		super.createPageContents(parent);
230
231
		// adds the label preferences check boxes
232
		createLabelPreferencesButtons(parent);
233
234
		refreshButtons();
235
	}
236
237
	/**
238
	 * Load the default preferences of the fields contained in this page
239
	 */
240
	protected void loadDefaultPreferences() {
241
		propertyValue = getPreferenceStore().getDefaultInt(labelDisplayPreferenceKey);
242
		refreshButtons();
243
	}
244
245
	/**
246
	 * {@inheritDoc}
247
	 */
248
	@Override
249
	protected void performDefaults() {
250
		loadDefaultPreferences();
251
		super.performDefaults();
252
	}
253
254
	/**
255
	 * {@inheritDoc}
256
	 */
257
	@Override
258
	public boolean performOk() {
259
		storePreferences();
260
		return super.performOk();
261
	}
262
263
	/**
264
	 * Refresh the buttons that manages the display.
265
	 */
266
	protected void refreshButtons() {
267
268
		bttnVisibility.setSelection((propertyValue & DISP_VISIBILITY) == DISP_VISIBILITY);
269
		bttnDerive.setSelection((propertyValue & DISP_DERIVE) == DISP_DERIVE);
270
		bttnName.setSelection((propertyValue & DISP_NAME) == DISP_NAME);
271
		bttnType.setSelection((propertyValue & DISP_TYPE) == DISP_TYPE);
272
		bttnUndefined_Type.setSelection((propertyValue & DISP_UNDEFINED_TYPE) == DISP_UNDEFINED_TYPE);
273
		bttnMultiplicity.setSelection((propertyValue & DISP_MULTIPLICITY) == DISP_MULTIPLICITY);
274
		bttnDefault_Multiplicity.setSelection((propertyValue & DISP_DEFAULT_MULTIPLICITY) == DISP_DEFAULT_MULTIPLICITY);
275
		bttnDefaultValue.setSelection((propertyValue & DISP_DEFAULTVALUE) == DISP_DEFAULTVALUE);
276
		bttnModifiers.setSelection((propertyValue & DISP_MODIFIERS) == DISP_MODIFIERS);
277
278
	}
279
280
	/**
281
	 * Stores the values of the fields contained in this page into the preference store.
282
	 */
283
	protected void storePreferences() {
284
		super.storePreferences();
285
		IPreferenceStore store = getPreferenceStore();
286
		// checks the stored value and the actual one, so does not refresh diagram if it is not
287
		// needed
288
		if(propertyValue != store.getInt(labelDisplayPreferenceKey)) {
289
			store.setValue(labelDisplayPreferenceKey, propertyValue);
290
		}
291
	}
292
293
	/**
294
	 * Listeners for the check buttons that select the display.
295
	 */
296
	private class AppearenceSelectionListener implements SelectionListener {
297
298
		/** The constant which refers the element to display or not. */
299
		final private int style;
300
301
		/**
302
		 * Default Constructor.
303
		 * 
304
		 * @param style
305
		 */
306
		public AppearenceSelectionListener(int style) {
307
			this.style = style;
308
		}
309
310
		/**
311
		 * {@inheritDoc}
312
		 */
313
		public void widgetDefaultSelected(SelectionEvent e) {
314
315
		}
316
317
		/**
318
		 * {@inheritDoc}
319
		 */
320
		public void widgetSelected(SelectionEvent e) {
321
			// add or remove the flag to the display property value (invert the current value)
322
			propertyValue = propertyValue ^ style;
323
			// refresh buttons to show current values
324
			refreshButtons();
325
		}
326
	}
327
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/CustomPreferenceInitializer.java (+80 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
18
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
19
import org.eclipse.papyrus.sysml.diagram.parametric.Activator;
20
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
21
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
22
23
/**
24
 * Custom preferences initializer.
25
 */
26
public class CustomPreferenceInitializer extends ParametricDiagramPreferenceInitializer {
27
28
	protected IPreferenceStore getPreferenceStore() {
29
		return Activator.getInstance().getPreferenceStore();
30
	}
31
32
	@Override
33
	public void initializeDefaultPreferences() {
34
		super.initializeDefaultPreferences();
35
36
		IPreferenceStore store = getPreferenceStore();
37
38
		PortAsBorderItemPreferencePage.initDefaults(store);
39
		ConstraintParameterAsBorderItemPreferencePage.initDefaults(store);
40
		FlowPortAsBorderItemPreferencePage.initDefaults(store);
41
		BlockPropertyCompositePreferencePage.initDefaults(store);
42
		CustomConstraintPropertyCompositePreferencePage.initDefaults(store);
43
		CustomConnectorPreferencePage.initDefaults(store);
44
45
		// Initialize default positions for labels.
46
		initDefaultPosition(UMLGraphicalTypes.LINK_UML_DEPENDENCY_ID, UMLGraphicalTypes.LINKLABEL_UML_NAMEDELEMENT_NAME_ID, 0, -10);
47
		initDefaultPosition(UMLGraphicalTypes.LINK_UML_DEPENDENCY_ID, UMLGraphicalTypes.LINKLABEL_UML_APPLIEDSTEREOTYPE_ID, 0, -30);
48
49
		initDefaultPosition(UMLGraphicalTypes.LINK_UML_CONNECTOR_ID, UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_LABEL_ID, 0, -10);
50
		initDefaultPosition(UMLGraphicalTypes.LINK_UML_CONNECTOR_ID, UMLGraphicalTypes.LINKLABEL_UML_APPLIEDSTEREOTYPE_ID, 0, -30);
51
		initDefaultPosition(UMLGraphicalTypes.LINK_UML_CONNECTOR_ID, UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_SOURCE_MULTIPLICITY_ID, 0, 10);
52
		initDefaultPosition(UMLGraphicalTypes.LINK_UML_CONNECTOR_ID, UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_TARGET_MULTIPLICITY_ID, 0, 10);
53
54
		initDefaultPosition(UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID, UMLGraphicalTypes.AFFIXEDLABEL_UML_PORT_LABEL_ID, 30, 0);
55
		initDefaultPosition(UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID, UMLGraphicalTypes.AFFIXEDLABEL_UML_APPLIEDSTEREOTYPE_ID, 30, -20);
56
57
		initDefaultPosition(SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID, SysMLGraphicalTypes.AFFIXEDLABEL_SYSML_FLOWPORT_LABEL_ID, 30, 0);
58
		initDefaultPosition(SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID, UMLGraphicalTypes.AFFIXEDLABEL_UML_APPLIEDSTEREOTYPE_ID, 30, -20);
59
	}
60
61
	/**
62
	 * Initialize default position of a link label in preferences.
63
	 * 
64
	 * @param parentGraphicalType
65
	 *        the graphical type of the view owning the label
66
	 * @param graphicalType
67
	 *        the graphical type of the label
68
	 * @param x
69
	 * @param y
70
	 */
71
	protected void initDefaultPosition(String parentGraphicalType, String graphicalType, int x, int y) {
72
		IPreferenceStore store = getPreferenceStore();
73
74
		String xKey = PreferenceConstantHelper.getElementConstant(ElementTypes.DIAGRAM_ID + "_" + parentGraphicalType + "-" + graphicalType, PreferenceConstantHelper.LOCATION_X);
75
		String yKey = PreferenceConstantHelper.getElementConstant(ElementTypes.DIAGRAM_ID + "_" + parentGraphicalType + "-" + graphicalType, PreferenceConstantHelper.LOCATION_Y);
76
77
		store.setDefault(xKey, x);
78
		store.setDefault(yKey, y);
79
	}
80
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/DiagramAppearancePreferencePage.java (-31 lines)
Lines 1-31 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.gmf.runtime.diagram.ui.preferences.AppearancePreferencePage;
17
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
18
19
/**
20
 * @generated
21
 */
22
public class DiagramAppearancePreferencePage extends AppearancePreferencePage {
23
24
	/**
25
	 * @generated
26
	 */
27
	public DiagramAppearancePreferencePage() {
28
		setPreferenceStore(SysmlDiagramEditorPlugin.getInstance().getPreferenceStore());
29
30
	}
31
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/DiagramConnectionsPreferencePage.java (-31 lines)
Lines 1-31 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.gmf.runtime.diagram.ui.preferences.ConnectionsPreferencePage;
17
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
18
19
/**
20
 * @generated
21
 */
22
public class DiagramConnectionsPreferencePage extends ConnectionsPreferencePage {
23
24
	/**
25
	 * @generated
26
	 */
27
	public DiagramConnectionsPreferencePage() {
28
		setPreferenceStore(SysmlDiagramEditorPlugin.getInstance().getPreferenceStore());
29
30
	}
31
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/DiagramGeneralPreferencePage.java (-33 lines)
Lines 1-33 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.papyrus.infra.gmfdiag.preferences.pages.DiagramPreferencePage;
17
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
18
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
19
20
/**
21
 * @generated
22
 */
23
public class DiagramGeneralPreferencePage extends DiagramPreferencePage {
24
25
	/**
26
	 * @generated
27
	 */
28
	public DiagramGeneralPreferencePage() {
29
		setPreferenceStore(SysmlDiagramEditorPlugin.getInstance().getPreferenceStore());
30
		setPreferenceKey(ParametricEditPart.MODEL_ID);
31
32
	}
33
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/DiagramPreferenceInitializer.java (-45 lines)
Lines 1-45 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
17
import org.eclipse.jface.preference.IPreferenceStore;
18
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
19
20
/**
21
 * @generated
22
 */
23
public class DiagramPreferenceInitializer extends AbstractPreferenceInitializer {
24
25
	/**
26
	 * @generated
27
	 */
28
	public void initializeDefaultPreferences() {
29
		IPreferenceStore store = getPreferenceStore();
30
31
		ConstraintPropertyPreferencePage.initDefaults(store);
32
33
		PropertyPreferencePage.initDefaults(store);
34
35
		ConnectorPreferencePage.initDefaults(store);
36
37
	}
38
39
	/**
40
	 * @generated
41
	 */
42
	protected IPreferenceStore getPreferenceStore() {
43
		return SysmlDiagramEditorPlugin.getInstance().getPreferenceStore();
44
	}
45
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/DiagramPrintingPreferencePage.java (-31 lines)
Lines 1-31 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.gmf.runtime.diagram.ui.preferences.PrintingPreferencePage;
17
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
18
19
/**
20
 * @generated
21
 */
22
public class DiagramPrintingPreferencePage extends PrintingPreferencePage {
23
24
	/**
25
	 * @generated
26
	 */
27
	public DiagramPrintingPreferencePage() {
28
		setPreferenceStore(SysmlDiagramEditorPlugin.getInstance().getPreferenceStore());
29
30
	}
31
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/DiagramRulersAndGridPreferencePage.java (-31 lines)
Lines 1-31 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.gmf.runtime.diagram.ui.preferences.RulerGridPreferencePage;
17
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
18
19
/**
20
 * @generated
21
 */
22
public class DiagramRulersAndGridPreferencePage extends RulerGridPreferencePage {
23
24
	/**
25
	 * @generated
26
	 */
27
	public DiagramRulersAndGridPreferencePage() {
28
		setPreferenceStore(SysmlDiagramEditorPlugin.getInstance().getPreferenceStore());
29
30
	}
31
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/FlowPortAsBorderItemPreferencePage.java (+310 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULTVALUE;
17
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY;
18
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DERIVE;
19
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DIRECTION;
20
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MODIFIERS;
21
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MULTIPLICITY;
22
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_NAME;
23
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_TYPE;
24
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_UNDEFINED_TYPE;
25
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_VISIBILITY;
26
27
import java.util.Collections;
28
import java.util.LinkedHashMap;
29
import java.util.Map;
30
31
import org.eclipse.jface.preference.IPreferenceStore;
32
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
33
import org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants;
34
import org.eclipse.papyrus.sysml.diagram.common.preferences.LabelPreferenceHelper;
35
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
36
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
37
import org.eclipse.swt.SWT;
38
import org.eclipse.swt.events.SelectionEvent;
39
import org.eclipse.swt.events.SelectionListener;
40
import org.eclipse.swt.layout.FormAttachment;
41
import org.eclipse.swt.layout.FormData;
42
import org.eclipse.swt.layout.FormLayout;
43
import org.eclipse.swt.widgets.Button;
44
import org.eclipse.swt.widgets.Composite;
45
import org.eclipse.swt.widgets.Group;
46
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
47
48
/**
49
 * FlowPort preference page.
50
 */
51
public class FlowPortAsBorderItemPreferencePage extends ParametricDiagramNodePreferencePage {
52
53
	/** Constant key to access preferences */
54
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_" + SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID; //$NON-NLS-1$
55
56
	public static String prefLabelKey = prefKey + "-" + SysMLGraphicalTypes.AFFIXEDLABEL_SYSML_FLOWPORT_LABEL_ID; //$NON-NLS-1$
57
58
	/** The labels default visibility for preferences */
59
	public static final Map<String, Boolean> labelDefaultVisibilityMap;
60
61
	/** Static attribute initialization */
62
	static {
63
		labelDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
64
		labelDefaultVisibilityMap.put("Stereotype", Boolean.TRUE); //$NON-NLS-1$	
65
		labelDefaultVisibilityMap.put("Label", Boolean.TRUE); //$NON-NLS-1$	
66
67
		// Start of user code custom static initializations
68
		// End of user code
69
70
		Collections.unmodifiableMap(labelDefaultVisibilityMap);
71
	}
72
73
	/** Constructor */
74
	public FlowPortAsBorderItemPreferencePage() {
75
		super();
76
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_" + SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID); //$NON-NLS-1$
77
	}
78
79
	/** Default preferences initializer */
80
	public static void initDefaults(IPreferenceStore store) {
81
82
		store.setDefault(LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE), DISP_DIRECTION | DISP_NAME | DISP_TYPE | DISP_UNDEFINED_TYPE);
83
84
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.WIDTH), 20);
85
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.HEIGHT), 20);
86
87
		// Initialize default visibility for labels in preference page.
88
		for(String labelName : labelDefaultVisibilityMap.keySet()) {
89
			String showLabelKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, labelName, PreferenceConstantHelper.LABEL_VISIBILITY);
90
			store.setDefault(showLabelKey, labelDefaultVisibilityMap.get(labelName));
91
		}
92
	}
93
94
	/**
95
	 * {@inheritDoc}
96
	 */
97
	@Override
98
	protected void initializeLabelsList() {
99
		for(String name : labelDefaultVisibilityMap.keySet()) {
100
			this.labelsList.add(name);
101
		}
102
	}
103
104
	/** buttons to select the display mask of the label */
105
	protected Button bttnDirection, bttnVisibility, bttnDerive, bttnName, bttnType, bttnUndefined_Type, bttnMultiplicity, bttnDefault_Multiplicity, bttnDefaultValue, bttnModifiers;
106
107
	private String labelDisplayPreferenceKey = LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE);
108
109
	/** current property display style */
110
	private int propertyValue = getPreferenceStore().getInt(labelDisplayPreferenceKey);
111
112
	/**
113
	 * Creates a button with the {@link SWT#CHECK} style.
114
	 * 
115
	 * @param parent
116
	 *        the parent of the button
117
	 * @param label
118
	 *        the label of the button
119
	 * @param mask
120
	 *        the value controlled by the button
121
	 * @return the button created
122
	 */
123
	protected Button createCheckButton(Composite parent, String label, int mask) {
124
		Button button = new Button(parent, SWT.CHECK);
125
		button.setText(label);
126
		button.addSelectionListener(new AppearenceSelectionListener(mask));
127
		return button;
128
	}
129
130
	/**
131
	 * Creates the group and check boxes to choose the kind of display
132
	 * 
133
	 * @param parent
134
	 *        the parent composite that holds the group
135
	 */
136
	protected void createLabelPreferencesButtons(Composite parent) {
137
		// create group that host the buttons
138
		Group group = new Group(parent, SWT.SHADOW_NONE);
139
		group.setText("Label Display");
140
		group.setLayout(new FormLayout());
141
142
		FormData data;
143
144
		bttnDirection = createCheckButton(group, "Direction", DISP_DIRECTION);
145
		data = new FormData();
146
		data.left = new FormAttachment(0, 0);
147
		data.top = new FormAttachment(0, 0);
148
		bttnDirection.setLayoutData(data);
149
150
		bttnVisibility = createCheckButton(group, "Visibility", DISP_VISIBILITY);
151
		data = new FormData();
152
		data.left = new FormAttachment(bttnDirection, 85);
153
		data.top = new FormAttachment(0, 0);
154
		bttnVisibility.setLayoutData(data);
155
156
		bttnDerive = createCheckButton(group, "Derive", DISP_DERIVE);
157
		data = new FormData();
158
		data.left = new FormAttachment(bttnVisibility, 85);
159
		data.top = new FormAttachment(0, 0);
160
		bttnDerive.setLayoutData(data);
161
162
		bttnName = createCheckButton(group, "Name", DISP_NAME);
163
		data = new FormData();
164
		data.left = new FormAttachment(bttnDerive, 85);
165
		data.top = new FormAttachment(0, 0);
166
		bttnName.setLayoutData(data);
167
168
		bttnType = createCheckButton(group, "Type", DISP_TYPE);
169
		data = new FormData();
170
		data.left = new FormAttachment(0, 0);
171
		data.top = new FormAttachment(bttnDirection, ITabbedPropertyConstants.HSPACE);
172
		bttnType.setLayoutData(data);
173
174
		bttnUndefined_Type = createCheckButton(group, "Undefined_Type", DISP_UNDEFINED_TYPE);
175
		data = new FormData();
176
		data.left = new FormAttachment(bttnDirection, 85);
177
		data.top = new FormAttachment(bttnDirection, ITabbedPropertyConstants.HSPACE);
178
		bttnUndefined_Type.setLayoutData(data);
179
180
		bttnMultiplicity = createCheckButton(group, "Multiplicity", DISP_MULTIPLICITY);
181
		data = new FormData();
182
		data.left = new FormAttachment(bttnVisibility, 85);
183
		data.top = new FormAttachment(bttnDirection, ITabbedPropertyConstants.HSPACE);
184
		bttnMultiplicity.setLayoutData(data);
185
186
		bttnDefault_Multiplicity = createCheckButton(group, "Default_Multiplicity", DISP_DEFAULT_MULTIPLICITY);
187
		data = new FormData();
188
		data.left = new FormAttachment(bttnDerive, 85);
189
		data.top = new FormAttachment(bttnDirection, ITabbedPropertyConstants.HSPACE);
190
		bttnDefault_Multiplicity.setLayoutData(data);
191
192
		bttnDefaultValue = createCheckButton(group, "DefaultValue", DISP_DEFAULTVALUE);
193
		data = new FormData();
194
		data.left = new FormAttachment(0, 0);
195
		data.top = new FormAttachment(bttnType, ITabbedPropertyConstants.HSPACE);
196
		bttnDefaultValue.setLayoutData(data);
197
198
		bttnModifiers = createCheckButton(group, "Modifiers", DISP_MODIFIERS);
199
		data = new FormData();
200
		data.left = new FormAttachment(bttnDirection, 85);
201
		data.top = new FormAttachment(bttnType, ITabbedPropertyConstants.HSPACE);
202
		bttnModifiers.setLayoutData(data);
203
204
	}
205
206
	/**
207
	 * {@inheritDoc}
208
	 */
209
	@Override
210
	protected void createPageContents(Composite parent) {
211
		super.createPageContents(parent);
212
213
		// adds the label preferences check boxes
214
		createLabelPreferencesButtons(parent);
215
216
		refreshButtons();
217
	}
218
219
	/**
220
	 * Load the default preferences of the fields contained in this page
221
	 */
222
	protected void loadDefaultPreferences() {
223
		propertyValue = getPreferenceStore().getDefaultInt(labelDisplayPreferenceKey);
224
		refreshButtons();
225
	}
226
227
	/**
228
	 * {@inheritDoc}
229
	 */
230
	@Override
231
	protected void performDefaults() {
232
		loadDefaultPreferences();
233
		super.performDefaults();
234
	}
235
236
	/**
237
	 * {@inheritDoc}
238
	 */
239
	@Override
240
	public boolean performOk() {
241
		storePreferences();
242
		return super.performOk();
243
	}
244
245
	/**
246
	 * Refresh the buttons that manages the display.
247
	 */
248
	protected void refreshButtons() {
249
250
		bttnDirection.setSelection((propertyValue & DISP_DIRECTION) == DISP_DIRECTION);
251
		bttnVisibility.setSelection((propertyValue & DISP_VISIBILITY) == DISP_VISIBILITY);
252
		bttnDerive.setSelection((propertyValue & DISP_DERIVE) == DISP_DERIVE);
253
		bttnName.setSelection((propertyValue & DISP_NAME) == DISP_NAME);
254
		bttnType.setSelection((propertyValue & DISP_TYPE) == DISP_TYPE);
255
		bttnUndefined_Type.setSelection((propertyValue & DISP_UNDEFINED_TYPE) == DISP_UNDEFINED_TYPE);
256
		bttnMultiplicity.setSelection((propertyValue & DISP_MULTIPLICITY) == DISP_MULTIPLICITY);
257
		bttnDefault_Multiplicity.setSelection((propertyValue & DISP_DEFAULT_MULTIPLICITY) == DISP_DEFAULT_MULTIPLICITY);
258
		bttnDefaultValue.setSelection((propertyValue & DISP_DEFAULTVALUE) == DISP_DEFAULTVALUE);
259
		bttnModifiers.setSelection((propertyValue & DISP_MODIFIERS) == DISP_MODIFIERS);
260
261
	}
262
263
	/**
264
	 * Stores the values of the fields contained in this page into the preference store.
265
	 */
266
	protected void storePreferences() {
267
		super.storePreferences();
268
		IPreferenceStore store = getPreferenceStore();
269
		// checks the stored value and the actual one, so does not refresh diagram if it is not
270
		// needed
271
		if(propertyValue != store.getInt(labelDisplayPreferenceKey)) {
272
			store.setValue(labelDisplayPreferenceKey, propertyValue);
273
		}
274
	}
275
276
	/**
277
	 * Listeners for the check buttons that select the display.
278
	 */
279
	private class AppearenceSelectionListener implements SelectionListener {
280
281
		/** The constant which refers the element to display or not. */
282
		final private int style;
283
284
		/**
285
		 * Default Constructor.
286
		 * 
287
		 * @param style
288
		 */
289
		public AppearenceSelectionListener(int style) {
290
			this.style = style;
291
		}
292
293
		/**
294
		 * {@inheritDoc}
295
		 */
296
		public void widgetDefaultSelected(SelectionEvent e) {
297
298
		}
299
300
		/**
301
		 * {@inheritDoc}
302
		 */
303
		public void widgetSelected(SelectionEvent e) {
304
			// add or remove the flag to the display property value (invert the current value)
305
			propertyValue = propertyValue ^ style;
306
			// refresh buttons to show current values
307
			refreshButtons();
308
		}
309
	}
310
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/PortAsBorderItemPreferencePage.java (+301 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULTVALUE;
17
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DEFAULT_MULTIPLICITY;
18
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_DERIVE;
19
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MODIFIERS;
20
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_MULTIPLICITY;
21
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_NAME;
22
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_TYPE;
23
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_UNDEFINED_TYPE;
24
import static org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants.DISP_VISIBILITY;
25
26
import java.util.Collections;
27
import java.util.LinkedHashMap;
28
import java.util.Map;
29
30
import org.eclipse.jface.preference.IPreferenceStore;
31
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
32
import org.eclipse.papyrus.sysml.diagram.common.preferences.ILabelPreferenceConstants;
33
import org.eclipse.papyrus.sysml.diagram.common.preferences.LabelPreferenceHelper;
34
import org.eclipse.papyrus.sysml.diagram.parametric.provider.ElementTypes;
35
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
36
import org.eclipse.swt.SWT;
37
import org.eclipse.swt.events.SelectionEvent;
38
import org.eclipse.swt.events.SelectionListener;
39
import org.eclipse.swt.layout.FormAttachment;
40
import org.eclipse.swt.layout.FormData;
41
import org.eclipse.swt.layout.FormLayout;
42
import org.eclipse.swt.widgets.Button;
43
import org.eclipse.swt.widgets.Composite;
44
import org.eclipse.swt.widgets.Group;
45
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
46
47
/**
48
 * {@link Port} preference page.
49
 */
50
public class PortAsBorderItemPreferencePage extends ParametricDiagramNodePreferencePage {
51
52
	/** Constant key to access preferences */
53
	public static String prefKey = ElementTypes.DIAGRAM_ID + "_" + UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID; //$NON-NLS-1$
54
55
	public static String prefLabelKey = prefKey + "-" + UMLGraphicalTypes.AFFIXEDLABEL_UML_PORT_LABEL_ID; //$NON-NLS-1$
56
57
	/** The labels default visibility for preferences */
58
	public static final Map<String, Boolean> labelDefaultVisibilityMap;
59
60
	/** Static attribute initialization */
61
	static {
62
		labelDefaultVisibilityMap = new LinkedHashMap<String, Boolean>();
63
		labelDefaultVisibilityMap.put("Stereotype", Boolean.TRUE); //$NON-NLS-1$	
64
		labelDefaultVisibilityMap.put("Label", Boolean.TRUE); //$NON-NLS-1$	
65
66
		// Start of user code custom static initializations
67
		// End of user code
68
69
		Collections.unmodifiableMap(labelDefaultVisibilityMap);
70
	}
71
72
	/** Constructor */
73
	public PortAsBorderItemPreferencePage() {
74
		super();
75
		setPreferenceKey(ElementTypes.DIAGRAM_ID + "_" + UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID); //$NON-NLS-1$
76
	}
77
78
	/** Default preferences initializer */
79
	public static void initDefaults(IPreferenceStore store) {
80
		store.setDefault(LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE), DISP_NAME | DISP_TYPE | DISP_MULTIPLICITY | DISP_UNDEFINED_TYPE);
81
82
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.WIDTH), 20);
83
		store.setDefault(PreferenceConstantHelper.getElementConstant(prefKey, PreferenceConstantHelper.HEIGHT), 20);
84
85
		// Initialize default visibility for labels in preference page.
86
		for(String labelName : labelDefaultVisibilityMap.keySet()) {
87
			String showLabelKey = PreferenceConstantHelper.getCompartmentElementConstant(prefKey, labelName, PreferenceConstantHelper.LABEL_VISIBILITY);
88
			store.setDefault(showLabelKey, labelDefaultVisibilityMap.get(labelName));
89
		}
90
	}
91
92
	/**
93
	 * {@inheritDoc}
94
	 */
95
	@Override
96
	protected void initializeLabelsList() {
97
		for(String name : labelDefaultVisibilityMap.keySet()) {
98
			this.labelsList.add(name);
99
		}
100
	}
101
102
	/** buttons to select the display mask of the label */
103
	protected Button bttnVisibility, bttnDerive, bttnName, bttnType, bttnUndefined_Type, bttnMultiplicity, bttnDefault_Multiplicity, bttnDefaultValue, bttnModifiers;
104
105
	private String labelDisplayPreferenceKey = LabelPreferenceHelper.getPreferenceConstant(prefLabelKey, ILabelPreferenceConstants.LABEL_DISPLAY_PREFERENCE);
106
107
	/** current property display style */
108
	private int propertyValue = getPreferenceStore().getInt(labelDisplayPreferenceKey);
109
110
	/**
111
	 * Creates a button with the {@link SWT#CHECK} style.
112
	 * 
113
	 * @param parent
114
	 *        the parent of the button
115
	 * @param label
116
	 *        the label of the button
117
	 * @param mask
118
	 *        the value controlled by the button
119
	 * @return the button created
120
	 */
121
	protected Button createCheckButton(Composite parent, String label, int mask) {
122
		Button button = new Button(parent, SWT.CHECK);
123
		button.setText(label);
124
		button.addSelectionListener(new AppearenceSelectionListener(mask));
125
		return button;
126
	}
127
128
	/**
129
	 * Creates the group and check boxes to choose the kind of display
130
	 * 
131
	 * @param parent
132
	 *        the parent composite that holds the group
133
	 */
134
	protected void createLabelPreferencesButtons(Composite parent) {
135
		// create group that host the buttons
136
		Group group = new Group(parent, SWT.SHADOW_NONE);
137
		group.setText("Label Display");
138
		group.setLayout(new FormLayout());
139
140
		FormData data;
141
142
		bttnVisibility = createCheckButton(group, "Visibility", DISP_VISIBILITY);
143
		data = new FormData();
144
		data.left = new FormAttachment(0, 0);
145
		data.top = new FormAttachment(0, 0);
146
		bttnVisibility.setLayoutData(data);
147
148
		bttnDerive = createCheckButton(group, "Derive", DISP_DERIVE);
149
		data = new FormData();
150
		data.left = new FormAttachment(bttnVisibility, 85);
151
		data.top = new FormAttachment(0, 0);
152
		bttnDerive.setLayoutData(data);
153
154
		bttnName = createCheckButton(group, "Name", DISP_NAME);
155
		data = new FormData();
156
		data.left = new FormAttachment(bttnDerive, 85);
157
		data.top = new FormAttachment(0, 0);
158
		bttnName.setLayoutData(data);
159
160
		bttnType = createCheckButton(group, "Type", DISP_TYPE);
161
		data = new FormData();
162
		data.left = new FormAttachment(bttnName, 85);
163
		data.top = new FormAttachment(0, 0);
164
		bttnType.setLayoutData(data);
165
166
		bttnUndefined_Type = createCheckButton(group, "Undefined_Type", DISP_UNDEFINED_TYPE);
167
		data = new FormData();
168
		data.left = new FormAttachment(0, 0);
169
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
170
		bttnUndefined_Type.setLayoutData(data);
171
172
		bttnMultiplicity = createCheckButton(group, "Multiplicity", DISP_MULTIPLICITY);
173
		data = new FormData();
174
		data.left = new FormAttachment(bttnVisibility, 85);
175
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
176
		bttnMultiplicity.setLayoutData(data);
177
178
		bttnDefault_Multiplicity = createCheckButton(group, "Default_Multiplicity", DISP_DEFAULT_MULTIPLICITY);
179
		data = new FormData();
180
		data.left = new FormAttachment(bttnDerive, 85);
181
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
182
		bttnDefault_Multiplicity.setLayoutData(data);
183
184
		bttnDefaultValue = createCheckButton(group, "DefaultValue", DISP_DEFAULTVALUE);
185
		data = new FormData();
186
		data.left = new FormAttachment(bttnName, 85);
187
		data.top = new FormAttachment(bttnVisibility, ITabbedPropertyConstants.HSPACE);
188
		bttnDefaultValue.setLayoutData(data);
189
190
		bttnModifiers = createCheckButton(group, "Modifiers", DISP_MODIFIERS);
191
		data = new FormData();
192
		data.left = new FormAttachment(0, 0);
193
		data.top = new FormAttachment(bttnUndefined_Type, ITabbedPropertyConstants.HSPACE);
194
		bttnModifiers.setLayoutData(data);
195
196
	}
197
198
	/**
199
	 * {@inheritDoc}
200
	 */
201
	@Override
202
	protected void createPageContents(Composite parent) {
203
		super.createPageContents(parent);
204
205
		// adds the label preferences check boxes
206
		createLabelPreferencesButtons(parent);
207
208
		refreshButtons();
209
	}
210
211
	/**
212
	 * Load the default preferences of the fields contained in this page
213
	 */
214
	protected void loadDefaultPreferences() {
215
		propertyValue = getPreferenceStore().getDefaultInt(labelDisplayPreferenceKey);
216
		refreshButtons();
217
	}
218
219
	/**
220
	 * {@inheritDoc}
221
	 */
222
	@Override
223
	protected void performDefaults() {
224
		loadDefaultPreferences();
225
		super.performDefaults();
226
	}
227
228
	/**
229
	 * {@inheritDoc}
230
	 */
231
	@Override
232
	public boolean performOk() {
233
		storePreferences();
234
		return super.performOk();
235
	}
236
237
	/**
238
	 * Refresh the buttons that manages the display.
239
	 */
240
	protected void refreshButtons() {
241
242
		bttnVisibility.setSelection((propertyValue & DISP_VISIBILITY) == DISP_VISIBILITY);
243
		bttnDerive.setSelection((propertyValue & DISP_DERIVE) == DISP_DERIVE);
244
		bttnName.setSelection((propertyValue & DISP_NAME) == DISP_NAME);
245
		bttnType.setSelection((propertyValue & DISP_TYPE) == DISP_TYPE);
246
		bttnUndefined_Type.setSelection((propertyValue & DISP_UNDEFINED_TYPE) == DISP_UNDEFINED_TYPE);
247
		bttnMultiplicity.setSelection((propertyValue & DISP_MULTIPLICITY) == DISP_MULTIPLICITY);
248
		bttnDefault_Multiplicity.setSelection((propertyValue & DISP_DEFAULT_MULTIPLICITY) == DISP_DEFAULT_MULTIPLICITY);
249
		bttnDefaultValue.setSelection((propertyValue & DISP_DEFAULTVALUE) == DISP_DEFAULTVALUE);
250
		bttnModifiers.setSelection((propertyValue & DISP_MODIFIERS) == DISP_MODIFIERS);
251
252
	}
253
254
	/**
255
	 * Stores the values of the fields contained in this page into the preference store.
256
	 */
257
	protected void storePreferences() {
258
		super.storePreferences();
259
		IPreferenceStore store = getPreferenceStore();
260
		// checks the stored value and the actual one, so does not refresh diagram if it is not
261
		// needed
262
		if(propertyValue != store.getInt(labelDisplayPreferenceKey)) {
263
			store.setValue(labelDisplayPreferenceKey, propertyValue);
264
		}
265
	}
266
267
	/**
268
	 * Listeners for the check buttons that select the display.
269
	 */
270
	private class AppearenceSelectionListener implements SelectionListener {
271
272
		/** The constant which refers the element to display or not. */
273
		final private int style;
274
275
		/**
276
		 * Default Constructor.
277
		 * 
278
		 * @param style
279
		 */
280
		public AppearenceSelectionListener(int style) {
281
			this.style = style;
282
		}
283
284
		/**
285
		 * {@inheritDoc}
286
		 */
287
		public void widgetDefaultSelected(SelectionEvent e) {
288
289
		}
290
291
		/**
292
		 * {@inheritDoc}
293
		 */
294
		public void widgetSelected(SelectionEvent e) {
295
			// add or remove the flag to the display property value (invert the current value)
296
			propertyValue = propertyValue ^ style;
297
			// refresh buttons to show current values
298
			refreshButtons();
299
		}
300
	}
301
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/preferences/PropertyPreferencePage.java (-64 lines)
Lines 1-64 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.preferences;
15
16
import org.eclipse.jface.preference.IPreferenceStore;
17
import org.eclipse.papyrus.infra.gmfdiag.preferences.pages.AbstractPapyrusNodePreferencePage;
18
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
19
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
20
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
21
22
/**
23
 * @generated
24
 */
25
public class PropertyPreferencePage extends AbstractPapyrusNodePreferencePage {
26
27
	/**
28
	 * @generated
29
	 */
30
	public PropertyPreferencePage() {
31
		super();
32
		setPreferenceKey(ParametricEditPart.MODEL_ID + "_Property");
33
	}
34
35
	/**
36
	 * @generated
37
	 */
38
	@Override
39
	protected String getBundleId() {
40
		return SysmlDiagramEditorPlugin.ID;
41
	}
42
43
	/**
44
	 * @generated
45
	 */
46
	public static void initDefaults(IPreferenceStore store) {
47
48
		String key = ParametricEditPart.MODEL_ID + "_Property";
49
		store.setDefault(PreferenceConstantHelper.getElementConstant(key, PreferenceConstantHelper.WIDTH), 40);
50
		store.setDefault(PreferenceConstantHelper.getElementConstant(key, PreferenceConstantHelper.HEIGHT), 40);
51
52
		//org.eclipse.jface.preference.PreferenceConverter.setDefault(store, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.getElementConstant(elementName, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.COLOR_FILL), new org.eclipse.swt.graphics.RGB(255, 255, 255));
53
		//org.eclipse.jface.preference.PreferenceConverter.setDefault(store, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.getElementConstant(elementName, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.COLOR_LINE), new org.eclipse.swt.graphics.RGB(0, 0, 0));
54
55
		// Set the default for the gradient
56
		//store.setDefault(org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.getElementConstant(elementName, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.GRADIENT_POLICY),false);
57
		//org.eclipse.papyrus.infra.gmfdiag.preferences.utils.GradientPreferenceConverter gradientPreferenceConverter = new  org.eclipse.papyrus.infra.gmfdiag.preferences.utils.GradientPreferenceConverter(
58
		//		new org.eclipse.swt.graphics.RGB(255, 255, 255),
59
		//		new org.eclipse.swt.graphics.RGB(0, 0, 0), 0, 0);
60
		//store.setDefault(org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.getElementConstant(elementName, org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper.COLOR_GRADIENT), gradientPreferenceConverter.getPreferenceValue());
61
62
	}
63
64
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/provider/CustomEditPolicyProvider.java (+188 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
15
16
import org.eclipse.gef.EditPart;
17
import org.eclipse.gef.EditPolicy;
18
import org.eclipse.gmf.runtime.common.core.service.IOperation;
19
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
20
import org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart;
21
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
22
import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
23
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultCreationEditPolicy;
24
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultGraphicalNodeEditPolicy;
25
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.DefaultXYLayoutEditPolicy;
26
import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockCompositeEditPart;
27
import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyCompositeEditPart;
28
import org.eclipse.papyrus.sysml.diagram.common.edit.part.BlockPropertyStructureCompartmentEditPart;
29
import org.eclipse.papyrus.sysml.diagram.common.edit.part.ConstraintBlockPropertyCompositeEditPart;
30
import org.eclipse.papyrus.sysml.diagram.common.edit.part.FlowPortAffixedNodeEditPart;
31
import org.eclipse.papyrus.sysml.diagram.common.edit.part.StructureCompartmentEditPart;
32
import org.eclipse.papyrus.sysml.diagram.common.edit.policy.CustomDuplicatePasteEditPolicy;
33
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.part.InternalBlockDiagramEditPart;
34
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomBlockCompositeSemanticEditPolicy;
35
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomBlockPropertyCompositeDropEditPolicy;
36
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy;
37
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomDefaultSemanticEditPolicy;
38
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomDiagramDropEditPolicy;
39
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.CustomDragDropEditPolicy;
40
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.EncapsulatedClassifierDropEditPolicy;
41
import org.eclipse.papyrus.sysml.diagram.parametric.policies.StructureClassifierDropEditPolicy;
42
import org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy.TypedElementDropEditPolicy;
43
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.CustomBlockCompositeEditPartTN;
44
import org.eclipse.papyrus.sysml.diagram.parametric.edit.part.ParametricDiagramEditPart;
45
import org.eclipse.papyrus.sysml.diagram.parametric.policies.CustomParametricSemanticPolicy;
46
import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementBorderEditPart;
47
import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementEditPart;
48
import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementLinkEditPart;
49
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConnectorEditPart;
50
import org.eclipse.papyrus.uml.diagram.common.edit.part.ConstraintParameterAffixedNodeEditPart;
51
import org.eclipse.papyrus.uml.diagram.common.edit.part.DependencyEditPart;
52
import org.eclipse.papyrus.uml.diagram.common.edit.part.PortAffixedNodeEditPart;
53
import org.eclipse.papyrus.uml.diagram.common.editpolicies.DuplicatePasteEditPolicy;
54
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.CommentEditPart;
55
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.CommentEditPartCN;
56
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConstraintEditPart;
57
import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ConstraintEditPartCN;
58
59
/**
60
 * Custom edit policy provider.
61
 */
62
public class CustomEditPolicyProvider extends ParametricDiagramEditPolicyProvider {
63
64
	@Override
65
	public boolean provides(IOperation operation) {
66
67
		CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation)operation;
68
		if(!(epOperation.getEditPart() instanceof IGraphicalEditPart)) {
69
			return false;
70
		}
71
72
		// Make sure this concern Parametric Diagram only
73
		IGraphicalEditPart gep = (IGraphicalEditPart)epOperation.getEditPart();
74
		String diagramType = gep.getNotationView().getDiagram().getType();
75
		if(!ElementTypes.DIAGRAM_ID.equals(diagramType)) {
76
			return false;
77
		}
78
79
		// provides for the main diagram edit part
80
		if(gep instanceof ParametricDiagramEditPart) {
81
			return true;
82
		}
83
84
		// Provides for edit parts that represent nodes in Internal Block diagram
85
		if(gep instanceof AbstractElementEditPart) {
86
			return true;
87
		}
88
		if(gep instanceof AbstractElementBorderEditPart) {
89
			return true;
90
		}
91
92
		// Provides for edit parts that represent edges in Internal Block diagram
93
		if(gep instanceof AbstractElementLinkEditPart) {
94
			return true;
95
		}
96
97
		if(gep instanceof ResizableCompartmentEditPart) {
98
			return true;
99
		}
100
101
		return super.provides(operation);
102
	}
103
104
	@Override
105
	public void createEditPolicies(EditPart editPart) {
106
		super.createEditPolicies(editPart);
107
108
		if(editPart instanceof InternalBlockDiagramEditPart) {
109
			editPart.installEditPolicy(DuplicatePasteEditPolicy.PASTE_ROLE, new CustomDuplicatePasteEditPolicy());
110
			editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDiagramDropEditPolicy());
111
			// no installation of other policies. 
112
			return;
113
		}
114
115
		editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomDragDropEditPolicy());
116
117
		if((editPart instanceof ConstraintEditPart) || (editPart instanceof ConstraintEditPartCN)) {
118
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomDefaultSemanticEditPolicy());
119
			editPart.installEditPolicy(EditPolicyRoles.CREATION_ROLE, new DefaultCreationEditPolicy());
120
			editPart.installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new DefaultGraphicalNodeEditPolicy());
121
		}
122
123
		if((editPart instanceof CommentEditPart) || (editPart instanceof CommentEditPartCN)) {
124
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomDefaultSemanticEditPolicy());
125
			editPart.installEditPolicy(EditPolicyRoles.CREATION_ROLE, new DefaultCreationEditPolicy());
126
			editPart.installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new DefaultGraphicalNodeEditPolicy());
127
		}
128
129
		if(editPart instanceof FlowPortAffixedNodeEditPart) {
130
			editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new TypedElementDropEditPolicy());
131
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
132
		}
133
134
		if(editPart instanceof PortAffixedNodeEditPart) {
135
			editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new TypedElementDropEditPolicy());
136
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
137
		}
138
139
		if(editPart instanceof BlockPropertyCompositeEditPart) {
140
			editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomBlockPropertyCompositeDropEditPolicy());
141
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
142
		}
143
144
		/*
145
		 * if(editPart instanceof NestedBlockPropertyCompositeEditPart) {
146
		 * editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomBlockPropertyCompositeDropEditPolicy());
147
		 * editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomNestedBlockPropertyCompositeSemanticEditPolicy());
148
		 * }
149
		 */
150
151
		if(editPart instanceof BlockPropertyStructureCompartmentEditPart) {
152
			editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy());
153
			editPart.installEditPolicy(EditPolicy.LAYOUT_ROLE, new DefaultXYLayoutEditPolicy());
154
		}
155
156
		if(editPart instanceof BlockCompositeEditPart) {
157
			editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new EncapsulatedClassifierDropEditPolicy());
158
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomBlockCompositeSemanticEditPolicy());
159
		}
160
161
		if(editPart instanceof StructureCompartmentEditPart) {
162
			editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new StructureClassifierDropEditPolicy());
163
			editPart.installEditPolicy(EditPolicy.LAYOUT_ROLE, new DefaultXYLayoutEditPolicy());
164
		}
165
166
		if(editPart instanceof DependencyEditPart) {
167
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomDefaultSemanticEditPolicy());
168
		}
169
170
		if(editPart instanceof ConnectorEditPart) {
171
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomDefaultSemanticEditPolicy());
172
		}
173
		
174
		if(editPart instanceof ConstraintBlockPropertyCompositeEditPart) {
175
			editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new CustomBlockPropertyCompositeDropEditPolicy());
176
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
177
		}
178
		if(editPart instanceof ConstraintParameterAffixedNodeEditPart) {
179
			editPart.installEditPolicy(EditPolicyRoles.DRAG_DROP_ROLE, new TypedElementDropEditPolicy());
180
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
181
		}
182
		if(editPart instanceof CustomBlockCompositeEditPartTN) {
183
			editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomParametricSemanticPolicy());
184
		}
185
186
	}
187
188
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/provider/ParserProvider.java (+107 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.provider;
15
16
import java.util.HashMap;
17
import java.util.Map;
18
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
21
import org.eclipse.gmf.runtime.common.core.service.IOperation;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
24
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
25
import org.eclipse.gmf.runtime.notation.Diagram;
26
import org.eclipse.gmf.runtime.notation.View;
27
import org.eclipse.papyrus.sysml.diagram.common.parser.FlowPortLabelParser;
28
import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
29
import org.eclipse.papyrus.sysml.diagram.parametric.parser.ParametricFrameParser;
30
import org.eclipse.papyrus.uml.diagram.common.parser.ConnectorLabelParser;
31
import org.eclipse.papyrus.uml.diagram.common.parser.ConstraintLabelParser;
32
import org.eclipse.papyrus.uml.diagram.common.parser.MultiplicityElementLabelParser;
33
import org.eclipse.papyrus.uml.diagram.common.parser.NamedElementLabelParser;
34
import org.eclipse.papyrus.uml.diagram.common.parser.PropertyLabelParser;
35
import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
36
37
/**
38
 * Parser provider for labels used by this diagram.
39
 */
40
public class ParserProvider extends AbstractProvider implements IParserProvider {
41
42
	/** map from graphical hint to parsers */
43
	private static final Map<String, IParser> graphicalHintToParser = new HashMap<String, IParser>();
44
45
	static {
46
		graphicalHintToParser.put(SysMLGraphicalTypes.LABEL_SYSML_BLOCK_NAME_ID, new ParametricFrameParser());
47
		graphicalHintToParser.put(UMLGraphicalTypes.LABEL_UML_PROPERTY_LABEL_ID, new PropertyLabelParser());
48
		graphicalHintToParser.put(UMLGraphicalTypes.SHAPE_UML_CONSTRAINT_AS_LABEL_ID, new ConstraintLabelParser());
49
50
		graphicalHintToParser.put(UMLGraphicalTypes.AFFIXEDLABEL_UML_PORT_LABEL_ID, new PropertyLabelParser());
51
		graphicalHintToParser.put(SysMLGraphicalTypes.AFFIXEDLABEL_SYSML_FLOWPORT_LABEL_ID, new FlowPortLabelParser());
52
53
		graphicalHintToParser.put(UMLGraphicalTypes.LINKLABEL_UML_NAMEDELEMENT_NAME_ID, new NamedElementLabelParser());
54
		graphicalHintToParser.put(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_LABEL_ID, new ConnectorLabelParser());
55
		graphicalHintToParser.put(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_SOURCE_MULTIPLICITY_ID, new MultiplicityElementLabelParser());
56
		graphicalHintToParser.put(UMLGraphicalTypes.LINKLABEL_UML_CONNECTOR_TARGET_MULTIPLICITY_ID, new MultiplicityElementLabelParser());
57
	}
58
59
	/**
60
	 * {@inheritDoc}
61
	 */
62
	public boolean provides(IOperation operation) {
63
		if(operation instanceof GetParserOperation) {
64
			IAdaptable hint = ((GetParserOperation)operation).getHint();
65
66
			if(!ElementTypes.DIAGRAM_ID.equals(getDiagramType(hint))) {
67
				return false;
68
			}
69
70
			return getParser(hint) != null;
71
		}
72
		return false;
73
	}
74
75
	/**
76
	 * {@inheritDoc}
77
	 */
78
	public IParser getParser(IAdaptable hint) {
79
		String parserHint = (String)hint.getAdapter(String.class);
80
		if(parserHint != null) {
81
			IParser parser = graphicalHintToParser.get(parserHint);
82
			if(parser != null) {
83
				return parser;
84
			}
85
		}
86
87
		View view = (View)hint.getAdapter(View.class);
88
		if(view != null) {
89
			IParser parser = graphicalHintToParser.get(view.getType());
90
			if(parser != null) {
91
				return parser;
92
			}
93
		}
94
95
		return null;
96
	}
97
98
	private String getDiagramType(IAdaptable hint) {
99
		Diagram diagram = (Diagram)hint.getAdapter(Diagram.class);
100
		if(diagram != null) {
101
			return diagram.getType();
102
		}
103
104
		return "undefined";
105
	}
106
107
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/providers/ElementInitializers.java (-38 lines)
Lines 1-38 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
17
18
/**
19
 * @generated
20
 */
21
public class ElementInitializers {
22
23
	protected ElementInitializers() {
24
		// use #getInstance to access cached instance
25
	}
26
27
	/**
28
	 * @generated
29
	 */
30
	public static ElementInitializers getInstance() {
31
		ElementInitializers cached = SysmlDiagramEditorPlugin.getInstance().getElementInitializers();
32
		if(cached == null) {
33
			SysmlDiagramEditorPlugin.getInstance().setElementInitializers(cached = new ElementInitializers());
34
		}
35
		return cached;
36
	}
37
38
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/providers/SysmlEditPartProvider.java (-154 lines)
Lines 1-154 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import java.lang.ref.WeakReference;
17
18
import org.eclipse.gef.EditPart;
19
import org.eclipse.gef.EditPartFactory;
20
import org.eclipse.gmf.runtime.common.core.service.IOperation;
21
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
22
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider;
23
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation;
24
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
25
import org.eclipse.gmf.runtime.notation.View;
26
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
27
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.SysmlEditPartFactory;
28
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
29
30
/**
31
 * @generated
32
 */
33
public class SysmlEditPartProvider extends AbstractEditPartProvider {
34
35
	/**
36
	 * @generated
37
	 */
38
	private EditPartFactory factory;
39
40
	/**
41
	 * @generated
42
	 */
43
	private boolean allowCaching;
44
45
	/**
46
	 * @generated
47
	 */
48
	private WeakReference cachedPart;
49
50
	/**
51
	 * @generated
52
	 */
53
	private WeakReference cachedView;
54
55
	/**
56
	 * @generated
57
	 */
58
	public SysmlEditPartProvider() {
59
		setFactory(new SysmlEditPartFactory());
60
		setAllowCaching(true);
61
	}
62
63
	/**
64
	 * @generated
65
	 */
66
	public final EditPartFactory getFactory() {
67
		return factory;
68
	}
69
70
	/**
71
	 * @generated
72
	 */
73
	protected void setFactory(EditPartFactory factory) {
74
		this.factory = factory;
75
	}
76
77
	/**
78
	 * @generated
79
	 */
80
	public final boolean isAllowCaching() {
81
		return allowCaching;
82
	}
83
84
	/**
85
	 * @generated
86
	 */
87
	protected synchronized void setAllowCaching(boolean allowCaching) {
88
		this.allowCaching = allowCaching;
89
		if(!allowCaching) {
90
			cachedPart = null;
91
			cachedView = null;
92
		}
93
	}
94
95
	/**
96
	 * @generated
97
	 */
98
	protected IGraphicalEditPart createEditPart(View view) {
99
		EditPart part = factory.createEditPart(null, view);
100
		if(part instanceof IGraphicalEditPart) {
101
			return (IGraphicalEditPart)part;
102
		}
103
		return null;
104
	}
105
106
	/**
107
	 * @generated
108
	 */
109
	protected IGraphicalEditPart getCachedPart(View view) {
110
		if(cachedView != null && cachedView.get() == view) {
111
			return (IGraphicalEditPart)cachedPart.get();
112
		}
113
		return null;
114
	}
115
116
	/**
117
	 * @generated
118
	 */
119
	public synchronized IGraphicalEditPart createGraphicEditPart(View view) {
120
		if(isAllowCaching()) {
121
			IGraphicalEditPart part = getCachedPart(view);
122
			cachedPart = null;
123
			cachedView = null;
124
			if(part != null) {
125
				return part;
126
			}
127
		}
128
		return createEditPart(view);
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	public synchronized boolean provides(IOperation operation) {
135
		if(operation instanceof CreateGraphicEditPartOperation) {
136
			View view = ((IEditPartOperation)operation).getView();
137
			if(!ParametricEditPart.MODEL_ID.equals(SysmlVisualIDRegistry.getModelID(view))) {
138
				return false;
139
			}
140
			if(isAllowCaching() && getCachedPart(view) != null) {
141
				return true;
142
			}
143
			IGraphicalEditPart part = createEditPart(view);
144
			if(part != null) {
145
				if(isAllowCaching()) {
146
					cachedPart = new WeakReference(part);
147
					cachedView = new WeakReference(view);
148
				}
149
				return true;
150
			}
151
		}
152
		return false;
153
	}
154
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/providers/SysmlElementTypes.java (-252 lines)
Lines 1-252 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import java.util.HashSet;
17
import java.util.IdentityHashMap;
18
import java.util.Map;
19
import java.util.Set;
20
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.emf.ecore.EClass;
23
import org.eclipse.emf.ecore.EClassifier;
24
import org.eclipse.emf.ecore.ENamedElement;
25
import org.eclipse.emf.ecore.EStructuralFeature;
26
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
27
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
28
import org.eclipse.jface.resource.ImageDescriptor;
29
import org.eclipse.jface.resource.ImageRegistry;
30
import org.eclipse.papyrus.resource.ResourcePackage;
31
import org.eclipse.papyrus.sysml.constraints.ConstraintsPackage;
32
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
33
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
34
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
35
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
36
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart;
37
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
38
import org.eclipse.swt.graphics.Image;
39
import org.eclipse.uml2.uml.UMLPackage;
40
41
/**
42
 * @generated
43
 */
44
public class SysmlElementTypes {
45
46
	/**
47
	 * @generated
48
	 */
49
	private SysmlElementTypes() {
50
	}
51
52
	/**
53
	 * @generated
54
	 */
55
	private static Map<IElementType, ENamedElement> elements;
56
57
	/**
58
	 * @generated
59
	 */
60
	private static ImageRegistry imageRegistry;
61
62
	/**
63
	 * @generated
64
	 */
65
	private static Set<IElementType> KNOWN_ELEMENT_TYPES;
66
67
	/**
68
	 * @generated
69
	 */
70
	public static final IElementType Resource_1000 = getElementType("org.eclipse.papyrus.sysml.diagram.parametric.Resource_1000"); //$NON-NLS-1$
71
72
	/**
73
	 * @generated
74
	 */
75
	public static final IElementType ConstraintProperty_2003 = getElementType("org.eclipse.papyrus.sysml.diagram.parametric.ConstraintProperty_2003"); //$NON-NLS-1$
76
77
	/**
78
	 * @generated
79
	 */
80
	public static final IElementType Property_2005 = getElementType("org.eclipse.papyrus.sysml.diagram.parametric.Property_2005"); //$NON-NLS-1$
81
82
	/**
83
	 * @generated
84
	 */
85
	public static final IElementType Property_3002 = getElementType("org.eclipse.papyrus.sysml.diagram.parametric.Property_3002"); //$NON-NLS-1$
86
87
	/**
88
	 * @generated
89
	 */
90
	public static final IElementType Connector_4001 = getElementType("org.eclipse.papyrus.sysml.diagram.parametric.Connector_4001"); //$NON-NLS-1$
91
92
	/**
93
	 * @generated
94
	 */
95
	private static ImageRegistry getImageRegistry() {
96
		if(imageRegistry == null) {
97
			imageRegistry = new ImageRegistry();
98
		}
99
		return imageRegistry;
100
	}
101
102
	/**
103
	 * @generated
104
	 */
105
	private static String getImageRegistryKey(ENamedElement element) {
106
		return element.getName();
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	private static ImageDescriptor getProvidedImageDescriptor(ENamedElement element) {
113
		if(element instanceof EStructuralFeature) {
114
			EStructuralFeature feature = ((EStructuralFeature)element);
115
			EClass eContainingClass = feature.getEContainingClass();
116
			EClassifier eType = feature.getEType();
117
			if(eContainingClass != null && !eContainingClass.isAbstract()) {
118
				element = eContainingClass;
119
			} else if(eType instanceof EClass && !((EClass)eType).isAbstract()) {
120
				element = eType;
121
			}
122
		}
123
		if(element instanceof EClass) {
124
			EClass eClass = (EClass)element;
125
			if(!eClass.isAbstract()) {
126
				return SysmlDiagramEditorPlugin.getInstance().getItemImageDescriptor(eClass.getEPackage().getEFactoryInstance().create(eClass));
127
			}
128
		}
129
		// TODO : support structural features
130
		return null;
131
	}
132
133
	/**
134
	 * @generated
135
	 */
136
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
137
		String key = getImageRegistryKey(element);
138
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
139
		if(imageDescriptor == null) {
140
			imageDescriptor = getProvidedImageDescriptor(element);
141
			if(imageDescriptor == null) {
142
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
143
			}
144
			getImageRegistry().put(key, imageDescriptor);
145
		}
146
		return imageDescriptor;
147
	}
148
149
	/**
150
	 * @generated
151
	 */
152
	public static Image getImage(ENamedElement element) {
153
		String key = getImageRegistryKey(element);
154
		Image image = getImageRegistry().get(key);
155
		if(image == null) {
156
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
157
			if(imageDescriptor == null) {
158
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
159
			}
160
			getImageRegistry().put(key, imageDescriptor);
161
			image = getImageRegistry().get(key);
162
		}
163
		return image;
164
	}
165
166
	/**
167
	 * @generated
168
	 */
169
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
170
		ENamedElement element = getElement(hint);
171
		if(element == null) {
172
			return null;
173
		}
174
		return getImageDescriptor(element);
175
	}
176
177
	/**
178
	 * @generated
179
	 */
180
	public static Image getImage(IAdaptable hint) {
181
		ENamedElement element = getElement(hint);
182
		if(element == null) {
183
			return null;
184
		}
185
		return getImage(element);
186
	}
187
188
	/**
189
	 * Returns 'type' of the ecore object associated with the hint.
190
	 * 
191
	 * @generated
192
	 */
193
	public static ENamedElement getElement(IAdaptable hint) {
194
		Object type = hint.getAdapter(IElementType.class);
195
		if(elements == null) {
196
			elements = new IdentityHashMap<IElementType, ENamedElement>();
197
198
			elements.put(Resource_1000, ResourcePackage.eINSTANCE.getResource());
199
200
			elements.put(ConstraintProperty_2003, ConstraintsPackage.eINSTANCE.getConstraintProperty());
201
202
			elements.put(Property_2005, UMLPackage.eINSTANCE.getProperty());
203
204
			elements.put(Property_3002, UMLPackage.eINSTANCE.getProperty());
205
206
			elements.put(Connector_4001, UMLPackage.eINSTANCE.getConnector());
207
		}
208
		return (ENamedElement)elements.get(type);
209
	}
210
211
	/**
212
	 * @generated
213
	 */
214
	private static IElementType getElementType(String id) {
215
		return ElementTypeRegistry.getInstance().getType(id);
216
	}
217
218
	/**
219
	 * @generated
220
	 */
221
	public static boolean isKnownElementType(IElementType elementType) {
222
		if(KNOWN_ELEMENT_TYPES == null) {
223
			KNOWN_ELEMENT_TYPES = new HashSet<IElementType>();
224
			KNOWN_ELEMENT_TYPES.add(Resource_1000);
225
			KNOWN_ELEMENT_TYPES.add(ConstraintProperty_2003);
226
			KNOWN_ELEMENT_TYPES.add(Property_2005);
227
			KNOWN_ELEMENT_TYPES.add(Property_3002);
228
			KNOWN_ELEMENT_TYPES.add(Connector_4001);
229
		}
230
		return KNOWN_ELEMENT_TYPES.contains(elementType);
231
	}
232
233
	/**
234
	 * @generated
235
	 */
236
	public static IElementType getElementType(int visualID) {
237
		switch(visualID) {
238
		case ParametricEditPart.VISUAL_ID:
239
			return Resource_1000;
240
		case ConstraintPropertyEditPart.VISUAL_ID:
241
			return ConstraintProperty_2003;
242
		case PropertyEditPart.VISUAL_ID:
243
			return Property_2005;
244
		case Property2EditPart.VISUAL_ID:
245
			return Property_3002;
246
		case ConnectorEditPart.VISUAL_ID:
247
			return Connector_4001;
248
		}
249
		return null;
250
	}
251
252
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/providers/SysmlIconProvider.java (-44 lines)
Lines 1-44 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
18
import org.eclipse.gmf.runtime.common.core.service.IOperation;
19
import org.eclipse.gmf.runtime.common.ui.services.icon.GetIconOperation;
20
import org.eclipse.gmf.runtime.common.ui.services.icon.IIconProvider;
21
import org.eclipse.swt.graphics.Image;
22
23
/**
24
 * @generated
25
 */
26
public class SysmlIconProvider extends AbstractProvider implements IIconProvider {
27
28
	/**
29
	 * @generated
30
	 */
31
	public Image getIcon(IAdaptable hint, int flags) {
32
		return SysmlElementTypes.getImage(hint);
33
	}
34
35
	/**
36
	 * @generated
37
	 */
38
	public boolean provides(IOperation operation) {
39
		if(operation instanceof GetIconOperation) {
40
			return ((GetIconOperation)operation).execute(this) != null;
41
		}
42
		return false;
43
	}
44
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/providers/SysmlMarkerNavigationProvider.java (-94 lines)
Lines 1-94 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import java.util.Arrays;
17
import java.util.Map;
18
19
import org.eclipse.core.resources.IFile;
20
import org.eclipse.core.resources.IMarker;
21
import org.eclipse.core.resources.IResource;
22
import org.eclipse.core.runtime.CoreException;
23
import org.eclipse.core.runtime.IStatus;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.gef.EditPart;
26
import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
27
import org.eclipse.gmf.runtime.emf.ui.providers.marker.AbstractModelMarkerNavigationProvider;
28
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
29
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorUtil;
30
31
/**
32
 * @generated
33
 */
34
public class SysmlMarkerNavigationProvider extends AbstractModelMarkerNavigationProvider {
35
36
	/**
37
	 * @generated
38
	 */
39
	public static final String MARKER_TYPE = SysmlDiagramEditorPlugin.ID + ".diagnostic"; //$NON-NLS-1$
40
41
	/**
42
	 * @generated
43
	 */
44
	protected void doGotoMarker(IMarker marker) {
45
		String elementId = marker.getAttribute(org.eclipse.gmf.runtime.common.core.resources.IMarker.ELEMENT_ID, null);
46
		if(elementId == null || !(getEditor() instanceof DiagramEditor)) {
47
			return;
48
		}
49
		DiagramEditor editor = (DiagramEditor)getEditor();
50
		Map editPartRegistry = editor.getDiagramGraphicalViewer().getEditPartRegistry();
51
		EObject targetView = editor.getDiagram().eResource().getEObject(elementId);
52
		if(targetView == null) {
53
			return;
54
		}
55
		EditPart targetEditPart = (EditPart)editPartRegistry.get(targetView);
56
		if(targetEditPart != null) {
57
			SysmlDiagramEditorUtil.selectElementsInDiagram(editor, Arrays.asList(new EditPart[]{ targetEditPart }));
58
		}
59
	}
60
61
	/**
62
	 * @generated
63
	 */
64
	public static void deleteMarkers(IResource resource) {
65
		try {
66
			resource.deleteMarkers(MARKER_TYPE, true, IResource.DEPTH_ZERO);
67
		} catch (CoreException e) {
68
			SysmlDiagramEditorPlugin.getInstance().logError("Failed to delete validation markers", e); //$NON-NLS-1$
69
		}
70
	}
71
72
	/**
73
	 * @generated
74
	 */
75
	public static IMarker addMarker(IFile file, String elementId, String location, String message, int statusSeverity) {
76
		IMarker marker = null;
77
		try {
78
			marker = file.createMarker(MARKER_TYPE);
79
			marker.setAttribute(IMarker.MESSAGE, message);
80
			marker.setAttribute(IMarker.LOCATION, location);
81
			marker.setAttribute(org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, elementId);
82
			int markerSeverity = IMarker.SEVERITY_INFO;
83
			if(statusSeverity == IStatus.WARNING) {
84
				markerSeverity = IMarker.SEVERITY_WARNING;
85
			} else if(statusSeverity == IStatus.ERROR || statusSeverity == IStatus.CANCEL) {
86
				markerSeverity = IMarker.SEVERITY_ERROR;
87
			}
88
			marker.setAttribute(IMarker.SEVERITY, markerSeverity);
89
		} catch (CoreException e) {
90
			SysmlDiagramEditorPlugin.getInstance().logError("Failed to create validation marker", e); //$NON-NLS-1$
91
		}
92
		return marker;
93
	}
94
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/providers/SysmlModelingAssistantProvider.java (-202 lines)
Lines 1-202 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import java.util.ArrayList;
17
import java.util.Collection;
18
import java.util.Collections;
19
import java.util.HashSet;
20
import java.util.Iterator;
21
import java.util.List;
22
23
import org.eclipse.core.runtime.IAdaptable;
24
import org.eclipse.emf.ecore.EObject;
25
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
27
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
28
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
29
import org.eclipse.gmf.runtime.emf.ui.services.modelingassistant.ModelingAssistantProvider;
30
import org.eclipse.gmf.runtime.notation.Diagram;
31
import org.eclipse.jface.viewers.ILabelProvider;
32
import org.eclipse.jface.window.Window;
33
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
34
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
35
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
36
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart;
37
import org.eclipse.papyrus.sysml.diagram.parametric.part.Messages;
38
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
39
import org.eclipse.swt.widgets.Display;
40
import org.eclipse.swt.widgets.Shell;
41
import org.eclipse.ui.dialogs.ElementListSelectionDialog;
42
43
/**
44
 * @generated
45
 */
46
public class SysmlModelingAssistantProvider extends ModelingAssistantProvider {
47
48
	/**
49
	 * @generated
50
	 */
51
	public List getTypesForPopupBar(IAdaptable host) {
52
		IGraphicalEditPart editPart = (IGraphicalEditPart)host.getAdapter(IGraphicalEditPart.class);
53
		if(editPart instanceof ParametricEditPart) {
54
			ArrayList<IElementType> types = new ArrayList<IElementType>(2);
55
			types.add(SysmlElementTypes.ConstraintProperty_2003);
56
			types.add(SysmlElementTypes.Property_2005);
57
			return types;
58
		}
59
		if(editPart instanceof ConstraintPropertyEditPart) {
60
			ArrayList<IElementType> types = new ArrayList<IElementType>(1);
61
			types.add(SysmlElementTypes.Property_3002);
62
			return types;
63
		}
64
		return Collections.EMPTY_LIST;
65
	}
66
67
	/**
68
	 * @generated
69
	 */
70
	public List getRelTypesOnSource(IAdaptable source) {
71
		IGraphicalEditPart sourceEditPart = (IGraphicalEditPart)source.getAdapter(IGraphicalEditPart.class);
72
		if(sourceEditPart instanceof PropertyEditPart) {
73
			return ((PropertyEditPart)sourceEditPart).getMARelTypesOnSource();
74
		}
75
		if(sourceEditPart instanceof Property2EditPart) {
76
			return ((Property2EditPart)sourceEditPart).getMARelTypesOnSource();
77
		}
78
		return Collections.EMPTY_LIST;
79
	}
80
81
	/**
82
	 * @generated
83
	 */
84
	public List getRelTypesOnTarget(IAdaptable target) {
85
		IGraphicalEditPart targetEditPart = (IGraphicalEditPart)target.getAdapter(IGraphicalEditPart.class);
86
		if(targetEditPart instanceof PropertyEditPart) {
87
			return ((PropertyEditPart)targetEditPart).getMARelTypesOnTarget();
88
		}
89
		if(targetEditPart instanceof Property2EditPart) {
90
			return ((Property2EditPart)targetEditPart).getMARelTypesOnTarget();
91
		}
92
		return Collections.EMPTY_LIST;
93
	}
94
95
	/**
96
	 * @generated
97
	 */
98
	public List getRelTypesOnSourceAndTarget(IAdaptable source, IAdaptable target) {
99
		IGraphicalEditPart sourceEditPart = (IGraphicalEditPart)source.getAdapter(IGraphicalEditPart.class);
100
		IGraphicalEditPart targetEditPart = (IGraphicalEditPart)target.getAdapter(IGraphicalEditPart.class);
101
		if(sourceEditPart instanceof PropertyEditPart) {
102
			return ((PropertyEditPart)sourceEditPart).getMARelTypesOnSourceAndTarget(targetEditPart);
103
		}
104
		if(sourceEditPart instanceof Property2EditPart) {
105
			return ((Property2EditPart)sourceEditPart).getMARelTypesOnSourceAndTarget(targetEditPart);
106
		}
107
		return Collections.EMPTY_LIST;
108
	}
109
110
	/**
111
	 * @generated
112
	 */
113
	public List getTypesForSource(IAdaptable target, IElementType relationshipType) {
114
		IGraphicalEditPart targetEditPart = (IGraphicalEditPart)target.getAdapter(IGraphicalEditPart.class);
115
		if(targetEditPart instanceof PropertyEditPart) {
116
			return ((PropertyEditPart)targetEditPart).getMATypesForSource(relationshipType);
117
		}
118
		if(targetEditPart instanceof Property2EditPart) {
119
			return ((Property2EditPart)targetEditPart).getMATypesForSource(relationshipType);
120
		}
121
		return Collections.EMPTY_LIST;
122
	}
123
124
	/**
125
	 * @generated
126
	 */
127
	public List getTypesForTarget(IAdaptable source, IElementType relationshipType) {
128
		IGraphicalEditPart sourceEditPart = (IGraphicalEditPart)source.getAdapter(IGraphicalEditPart.class);
129
		if(sourceEditPart instanceof PropertyEditPart) {
130
			return ((PropertyEditPart)sourceEditPart).getMATypesForTarget(relationshipType);
131
		}
132
		if(sourceEditPart instanceof Property2EditPart) {
133
			return ((Property2EditPart)sourceEditPart).getMATypesForTarget(relationshipType);
134
		}
135
		return Collections.EMPTY_LIST;
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	public EObject selectExistingElementForSource(IAdaptable target, IElementType relationshipType) {
142
		return selectExistingElement(target, getTypesForSource(target, relationshipType));
143
	}
144
145
	/**
146
	 * @generated
147
	 */
148
	public EObject selectExistingElementForTarget(IAdaptable source, IElementType relationshipType) {
149
		return selectExistingElement(source, getTypesForTarget(source, relationshipType));
150
	}
151
152
	/**
153
	 * @generated
154
	 */
155
	protected EObject selectExistingElement(IAdaptable host, Collection types) {
156
		if(types.isEmpty()) {
157
			return null;
158
		}
159
		IGraphicalEditPart editPart = (IGraphicalEditPart)host.getAdapter(IGraphicalEditPart.class);
160
		if(editPart == null) {
161
			return null;
162
		}
163
		Diagram diagram = (Diagram)editPart.getRoot().getContents().getModel();
164
		HashSet<EObject> elements = new HashSet<EObject>();
165
		for(Iterator<EObject> it = diagram.getElement().eAllContents(); it.hasNext();) {
166
			EObject element = it.next();
167
			if(isApplicableElement(element, types)) {
168
				elements.add(element);
169
			}
170
		}
171
		if(elements.isEmpty()) {
172
			return null;
173
		}
174
		return selectElement((EObject[])elements.toArray(new EObject[elements.size()]));
175
	}
176
177
	/**
178
	 * @generated
179
	 */
180
	protected boolean isApplicableElement(EObject element, Collection types) {
181
		IElementType type = ElementTypeRegistry.getInstance().getElementType(element);
182
		return types.contains(type);
183
	}
184
185
	/**
186
	 * @generated
187
	 */
188
	protected EObject selectElement(EObject[] elements) {
189
		Shell shell = Display.getCurrent().getActiveShell();
190
		ILabelProvider labelProvider = new AdapterFactoryLabelProvider(SysmlDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory());
191
		ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, labelProvider);
192
		dialog.setMessage(Messages.SysmlModelingAssistantProviderMessage);
193
		dialog.setTitle(Messages.SysmlModelingAssistantProviderTitle);
194
		dialog.setMultipleSelection(false);
195
		dialog.setElements(elements);
196
		EObject selected = null;
197
		if(dialog.open() == Window.OK) {
198
			selected = (EObject)dialog.getFirstResult();
199
		}
200
		return selected;
201
	}
202
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/providers/SysmlParserProvider.java (-205 lines)
Lines 1-205 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
19
import org.eclipse.gmf.runtime.common.core.service.IOperation;
20
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
21
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
22
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
23
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
24
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
25
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
26
import org.eclipse.gmf.runtime.notation.View;
27
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorNameEditPart;
28
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintLabelEditPart;
29
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyNameEditPart;
30
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyName2EditPart;
31
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyNameEditPart;
32
import org.eclipse.papyrus.sysml.diagram.parametric.parsers.ConnectorLabelParser;
33
import org.eclipse.papyrus.sysml.diagram.parametric.parsers.ConstraintLabelParser;
34
import org.eclipse.papyrus.sysml.diagram.parametric.parsers.ConstraintPropertyLabelParser;
35
import org.eclipse.papyrus.sysml.diagram.parametric.parsers.PropertyLabelParser;
36
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
37
38
/**
39
 * @generated
40
 */
41
public class SysmlParserProvider extends AbstractProvider implements IParserProvider {
42
43
	/**
44
	 * @generated
45
	 */
46
	private ConstraintPropertyLabelParser constraintPropertyLabel_5001Parser;
47
48
	/**
49
	 * @generated
50
	 */
51
	private IParser getConstraintPropertyLabel_5001Parser() {
52
		if(constraintPropertyLabel_5001Parser == null) {
53
			constraintPropertyLabel_5001Parser = new ConstraintPropertyLabelParser();
54
		}
55
		return constraintPropertyLabel_5001Parser;
56
	}
57
58
	/**
59
	 * @generated
60
	 */
61
	private ConstraintLabelParser constraintPropertyLabel_5004Parser;
62
63
	/**
64
	 * @generated
65
	 */
66
	private IParser getConstraintPropertyLabel_5004Parser() {
67
		if(constraintPropertyLabel_5004Parser == null) {
68
			constraintPropertyLabel_5004Parser = new ConstraintLabelParser();
69
		}
70
		return constraintPropertyLabel_5004Parser;
71
	}
72
73
	/**
74
	 * @generated
75
	 */
76
	private PropertyLabelParser propertyName_5002Parser;
77
78
	/**
79
	 * @generated
80
	 */
81
	private IParser getPropertyName_5002Parser() {
82
		if(propertyName_5002Parser == null) {
83
			propertyName_5002Parser = new PropertyLabelParser();
84
		}
85
		return propertyName_5002Parser;
86
	}
87
88
	/**
89
	 * @generated
90
	 */
91
	private PropertyLabelParser propertyName_5003Parser;
92
93
	/**
94
	 * @generated
95
	 */
96
	private IParser getPropertyName_5003Parser() {
97
		if(propertyName_5003Parser == null) {
98
			propertyName_5003Parser = new PropertyLabelParser();
99
		}
100
		return propertyName_5003Parser;
101
	}
102
103
	/**
104
	 * @generated
105
	 */
106
	private ConnectorLabelParser connectorName_6001Parser;
107
108
	/**
109
	 * @generated
110
	 */
111
	private IParser getConnectorName_6001Parser() {
112
		if(connectorName_6001Parser == null) {
113
			connectorName_6001Parser = new ConnectorLabelParser();
114
		}
115
		return connectorName_6001Parser;
116
	}
117
118
	/**
119
	 * @generated
120
	 */
121
	protected IParser getParser(int visualID) {
122
		switch(visualID) {
123
		case ConstraintPropertyNameEditPart.VISUAL_ID:
124
			return getConstraintPropertyLabel_5001Parser();
125
		case ConstraintLabelEditPart.VISUAL_ID:
126
			return getConstraintPropertyLabel_5004Parser();
127
		case PropertyNameEditPart.VISUAL_ID:
128
			return getPropertyName_5002Parser();
129
		case PropertyName2EditPart.VISUAL_ID:
130
			return getPropertyName_5003Parser();
131
		case ConnectorNameEditPart.VISUAL_ID:
132
			return getConnectorName_6001Parser();
133
		}
134
		return null;
135
	}
136
137
	/**
138
	 * Utility method that consults ParserService
139
	 * 
140
	 * @generated
141
	 */
142
	public static IParser getParser(IElementType type, EObject object, String parserHint) {
143
		return ParserService.getInstance().getParser(new HintAdapter(type, object, parserHint));
144
	}
145
146
	/**
147
	 * @generated
148
	 */
149
	public IParser getParser(IAdaptable hint) {
150
		String vid = (String)hint.getAdapter(String.class);
151
		if(vid != null) {
152
			return getParser(SysmlVisualIDRegistry.getVisualID(vid));
153
		}
154
		View view = (View)hint.getAdapter(View.class);
155
		if(view != null) {
156
			return getParser(SysmlVisualIDRegistry.getVisualID(view));
157
		}
158
		return null;
159
	}
160
161
	/**
162
	 * @generated
163
	 */
164
	public boolean provides(IOperation operation) {
165
		if(operation instanceof GetParserOperation) {
166
			IAdaptable hint = ((GetParserOperation)operation).getHint();
167
			if(SysmlElementTypes.getElement(hint) == null) {
168
				return false;
169
			}
170
			return getParser(hint) != null;
171
		}
172
		return false;
173
	}
174
175
	/**
176
	 * @generated
177
	 */
178
	private static class HintAdapter extends ParserHintAdapter {
179
180
		/**
181
		 * @generated
182
		 */
183
		private final IElementType elementType;
184
185
		/**
186
		 * @generated
187
		 */
188
		public HintAdapter(IElementType type, EObject object, String parserHint) {
189
			super(object, parserHint);
190
			assert type != null;
191
			elementType = type;
192
		}
193
194
		/**
195
		 * @generated
196
		 */
197
		public Object getAdapter(Class adapter) {
198
			if(IElementType.class.equals(adapter)) {
199
				return elementType;
200
			}
201
			return super.getAdapter(adapter);
202
		}
203
	}
204
205
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/providers/SysmlValidationProvider.java (-166 lines)
Lines 1-166 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.transaction.TransactionalEditingDomain;
19
import org.eclipse.emf.validation.AbstractModelConstraint;
20
import org.eclipse.emf.validation.IValidationContext;
21
import org.eclipse.emf.validation.model.IClientSelector;
22
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
23
import org.eclipse.gmf.runtime.notation.View;
24
import org.eclipse.papyrus.sysml.blocks.NestedConnectorEnd;
25
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
26
import org.eclipse.papyrus.sysml.diagram.parametric.helper.ModelValidationHelper;
27
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlDiagramEditorPlugin;
28
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
29
import org.eclipse.uml2.uml.Connector;
30
import org.eclipse.uml2.uml.ConnectorEnd;
31
import org.eclipse.uml2.uml.Property;
32
33
/**
34
 * @generated
35
 */
36
public class SysmlValidationProvider {
37
38
	/**
39
	 * @generated
40
	 */
41
	private static boolean constraintsActive = false;
42
43
	/**
44
	 * @generated
45
	 */
46
	public static boolean shouldConstraintsBePrivate() {
47
		return false;
48
	}
49
50
	/**
51
	 * @generated
52
	 */
53
	public static void runWithConstraints(TransactionalEditingDomain editingDomain, Runnable operation) {
54
		final Runnable op = operation;
55
		Runnable task = new Runnable() {
56
57
			public void run() {
58
				try {
59
					constraintsActive = true;
60
					op.run();
61
				} finally {
62
					constraintsActive = false;
63
				}
64
			}
65
		};
66
		if(editingDomain != null) {
67
			try {
68
				editingDomain.runExclusive(task);
69
			} catch (Exception e) {
70
				SysmlDiagramEditorPlugin.getInstance().logError("Validation failed", e); //$NON-NLS-1$
71
			}
72
		} else {
73
			task.run();
74
		}
75
	}
76
77
	/**
78
	 * @generated
79
	 */
80
	static boolean isInDefaultEditorContext(Object object) {
81
		if(shouldConstraintsBePrivate() && !constraintsActive) {
82
			return false;
83
		}
84
		if(object instanceof View) {
85
			return constraintsActive && ParametricEditPart.MODEL_ID.equals(SysmlVisualIDRegistry.getModelID((View)object));
86
		}
87
		return true;
88
	}
89
90
	/**
91
	 * @generated
92
	 */
93
	public static class DefaultCtx implements IClientSelector {
94
95
		/**
96
		 * @generated
97
		 */
98
		public boolean selects(Object object) {
99
			return isInDefaultEditorContext(object);
100
		}
101
	}
102
103
	/**
104
	 * @generated
105
	 */
106
	public static class Adapter1 extends AbstractModelConstraint {
107
108
		/**
109
		 * @generated
110
		 */
111
		public IStatus validate(IValidationContext ctx) {
112
			Connector context = (Connector)ctx.getTarget();
113
			return ModelValidationHelper.validateConnector(context, ctx);
114
		}
115
	}
116
117
	/**
118
	 * @generated
119
	 */
120
	public static class Adapter2 extends AbstractModelConstraint {
121
122
		/**
123
		 * @generated
124
		 */
125
		public IStatus validate(IValidationContext ctx) {
126
			Property context = (Property)ctx.getTarget();
127
			return ModelValidationHelper.validateProperty(context, ctx);
128
		}
129
	}
130
131
	/**
132
	 * @generated
133
	 */
134
	public static class Adapter3 extends AbstractModelConstraint {
135
136
		/**
137
		 * @generated
138
		 */
139
		public IStatus validate(IValidationContext ctx) {
140
			ConnectorEnd context = (ConnectorEnd)ctx.getTarget();
141
			return ModelValidationHelper.validateConnectorEnd(context, ctx);
142
		}
143
	}
144
145
	/**
146
	 * @generated
147
	 */
148
	public static class Adapter4 extends AbstractModelConstraint {
149
150
		/**
151
		 * @generated
152
		 */
153
		public IStatus validate(IValidationContext ctx) {
154
			NestedConnectorEnd context = (NestedConnectorEnd)ctx.getTarget();
155
			return ModelValidationHelper.validateNestedConnectorEnd(context, ctx);
156
		}
157
	}
158
159
	/**
160
	 * @generated
161
	 */
162
	static String formatElement(EObject object) {
163
		return EMFCoreUtil.getQualifiedName(object, true);
164
	}
165
166
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/providers/SysmlViewProvider.java (-489 lines)
Lines 1-489 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.providers;
15
16
import java.util.ArrayList;
17
18
import org.eclipse.core.runtime.IAdaptable;
19
import org.eclipse.emf.ecore.EAnnotation;
20
import org.eclipse.emf.ecore.EObject;
21
import org.eclipse.emf.ecore.EcoreFactory;
22
import org.eclipse.emf.transaction.util.TransactionUtil;
23
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
24
import org.eclipse.gmf.runtime.common.core.service.IOperation;
25
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
26
import org.eclipse.gmf.runtime.diagram.core.providers.IViewProvider;
27
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation;
28
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateEdgeViewOperation;
29
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateNodeViewOperation;
30
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateViewForKindOperation;
31
import org.eclipse.gmf.runtime.diagram.core.services.view.CreateViewOperation;
32
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
33
import org.eclipse.gmf.runtime.draw2d.ui.figures.FigureUtilities;
34
import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
35
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
36
import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
37
import org.eclipse.gmf.runtime.notation.Connector;
38
import org.eclipse.gmf.runtime.notation.DecorationNode;
39
import org.eclipse.gmf.runtime.notation.Diagram;
40
import org.eclipse.gmf.runtime.notation.Edge;
41
import org.eclipse.gmf.runtime.notation.FillStyle;
42
import org.eclipse.gmf.runtime.notation.FontStyle;
43
import org.eclipse.gmf.runtime.notation.Location;
44
import org.eclipse.gmf.runtime.notation.MeasurementUnit;
45
import org.eclipse.gmf.runtime.notation.Node;
46
import org.eclipse.gmf.runtime.notation.NotationFactory;
47
import org.eclipse.gmf.runtime.notation.NotationPackage;
48
import org.eclipse.gmf.runtime.notation.RelativeBendpoints;
49
import org.eclipse.gmf.runtime.notation.Shape;
50
import org.eclipse.gmf.runtime.notation.View;
51
import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint;
52
import org.eclipse.jface.preference.IPreferenceStore;
53
import org.eclipse.jface.preference.PreferenceConverter;
54
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.GradientPreferenceConverter;
55
import org.eclipse.papyrus.infra.gmfdiag.preferences.utils.PreferenceConstantHelper;
56
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
57
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorEditPart;
58
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConnectorNameEditPart;
59
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintLabelEditPart;
60
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyEditPart;
61
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ConstraintPropertyNameEditPart;
62
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.ParametricEditPart;
63
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.Property2EditPart;
64
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyEditPart;
65
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyName2EditPart;
66
import org.eclipse.papyrus.sysml.diagram.parametric.edit.parts.PropertyNameEditPart;
67
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
68
import org.eclipse.papyrus.uml.diagram.common.helper.PreferenceInitializerForElementHelper;
69
import org.eclipse.swt.SWT;
70
import org.eclipse.swt.graphics.FontData;
71
import org.eclipse.uml2.uml.Property;
72
import org.eclipse.uml2.uml.StructuredClassifier;
73
import org.eclipse.uml2.uml.Type;
74
75
/**
76
 * @generated
77
 */
78
public class SysmlViewProvider extends AbstractProvider implements IViewProvider {
79
80
	/**
81
	 * @generated
82
	 */
83
	public final boolean provides(IOperation operation) {
84
		if(operation instanceof CreateViewForKindOperation) {
85
			return provides((CreateViewForKindOperation)operation);
86
		}
87
		assert operation instanceof CreateViewOperation;
88
		if(operation instanceof CreateDiagramViewOperation) {
89
			return provides((CreateDiagramViewOperation)operation);
90
		} else if(operation instanceof CreateEdgeViewOperation) {
91
			return provides((CreateEdgeViewOperation)operation);
92
		} else if(operation instanceof CreateNodeViewOperation) {
93
			return provides((CreateNodeViewOperation)operation);
94
		}
95
		return false;
96
	}
97
98
	/**
99
	 * @generated
100
	 */
101
	protected boolean provides(CreateViewForKindOperation op) {
102
		/*
103
		 * if (op.getViewKind() == Node.class)
104
		 * return getNodeViewClass(op.getSemanticAdapter(), op.getContainerView(), op.getSemanticHint()) != null;
105
		 * if (op.getViewKind() == Edge.class)
106
		 * return getEdgeViewClass(op.getSemanticAdapter(), op.getContainerView(), op.getSemanticHint()) != null;
107
		 */
108
109
		// check Diagram Type should be the class diagram
110
		String modelID = SysmlVisualIDRegistry.getModelID(op.getContainerView());
111
		if(!getDiagramProvidedId().equals(modelID)) {
112
			return false;
113
		}
114
115
		int visualID = SysmlVisualIDRegistry.getVisualID(op.getSemanticHint());
116
		if(Node.class.isAssignableFrom(op.getViewKind())) {
117
			return SysmlVisualIDRegistry.canCreateNode(op.getContainerView(), visualID);
118
		}
119
120
		return true;
121
	}
122
123
	/**
124
	 * @generated
125
	 */
126
	protected String getDiagramProvidedId() {
127
		/*
128
		 * Indicates for which diagram this provider works for.
129
		 * <p>
130
		 * This method can be overloaded when diagram editor inherits from another one, but should never be <code>null</code>
131
		 * </p>
132
		 * 
133
		 * @return the unique identifier of the diagram for which views are provided.
134
		 */
135
		return ParametricEditPart.MODEL_ID;
136
	}
137
138
	/**
139
	 * @generated
140
	 */
141
	protected boolean provides(CreateDiagramViewOperation op) {
142
		return ParametricEditPart.MODEL_ID.equals(op.getSemanticHint()) && SysmlVisualIDRegistry.getDiagramVisualID(getSemanticElement(op.getSemanticAdapter())) != -1;
143
	}
144
145
	/**
146
	 * @generated
147
	 */
148
	protected boolean provides(CreateNodeViewOperation op) {
149
		if(op.getContainerView() == null) {
150
			return false;
151
		}
152
		IElementType elementType = getSemanticElementType(op.getSemanticAdapter());
153
		EObject domainElement = getSemanticElement(op.getSemanticAdapter());
154
		int visualID;
155
		if(op.getSemanticHint() == null) {
156
			// Semantic hint is not specified. Can be a result of call from CanonicalEditPolicy.
157
			// In this situation there should be NO elementType, visualID will be determined
158
			// by VisualIDRegistry.getNodeVisualID() for domainElement.
159
			if(elementType != null || domainElement == null) {
160
				return false;
161
			}
162
			visualID = SysmlVisualIDRegistry.getNodeVisualID(op.getContainerView(), domainElement);
163
		} else {
164
			visualID = SysmlVisualIDRegistry.getVisualID(op.getSemanticHint());
165
			if(elementType != null) {
166
				if(!SysmlElementTypes.isKnownElementType(elementType) || (!(elementType instanceof IHintedType))) {
167
					return false; // foreign element type
168
				}
169
				String elementTypeHint = ((IHintedType)elementType).getSemanticHint();
170
				if(!op.getSemanticHint().equals(elementTypeHint)) {
171
					return false; // if semantic hint is specified it should be the same as in element type
172
				}
173
				if(domainElement != null && visualID != SysmlVisualIDRegistry.getNodeVisualID(op.getContainerView(), domainElement)) {
174
					return false; // visual id for node EClass should match visual id from element type
175
				}
176
			} else {
177
				if(!ParametricEditPart.MODEL_ID.equals(SysmlVisualIDRegistry.getModelID(op.getContainerView()))) {
178
					return false; // foreign diagram
179
				}
180
				switch(visualID) {
181
				case ConstraintPropertyEditPart.VISUAL_ID:
182
				case Property2EditPart.VISUAL_ID:
183
				case PropertyEditPart.VISUAL_ID:
184
					if(domainElement == null || visualID != SysmlVisualIDRegistry.getNodeVisualID(op.getContainerView(), domainElement)) {
185
						return false; // visual id in semantic hint should match visual id for domain element
186
					}
187
					break;
188
				default:
189
					return false;
190
				}
191
			}
192
		}
193
		return ConstraintPropertyEditPart.VISUAL_ID == visualID || PropertyEditPart.VISUAL_ID == visualID || Property2EditPart.VISUAL_ID == visualID;
194
	}
195
196
	/**
197
	 * @generated
198
	 */
199
	protected boolean provides(CreateEdgeViewOperation op) {
200
		IElementType elementType = getSemanticElementType(op.getSemanticAdapter());
201
		if(!SysmlElementTypes.isKnownElementType(elementType) || (!(elementType instanceof IHintedType))) {
202
			return false; // foreign element type
203
		}
204
		String elementTypeHint = ((IHintedType)elementType).getSemanticHint();
205
		if(elementTypeHint == null || (op.getSemanticHint() != null && !elementTypeHint.equals(op.getSemanticHint()))) {
206
			return false; // our hint is visual id and must be specified, and it should be the same as in element type
207
		}
208
		int visualID = SysmlVisualIDRegistry.getVisualID(elementTypeHint);
209
		EObject domainElement = getSemanticElement(op.getSemanticAdapter());
210
		if(domainElement != null && visualID != SysmlVisualIDRegistry.getLinkWithClassVisualID(domainElement)) {
211
			return false; // visual id for link EClass should match visual id from element type
212
		}
213
		return true;
214
	}
215
216
	/**
217
	 * @generated
218
	 */
219
	public Diagram createDiagram(IAdaptable semanticAdapter, String diagramKind, PreferencesHint preferencesHint) {
220
		Diagram diagram = NotationFactory.eINSTANCE.createDiagram();
221
		diagram.getStyles().add(NotationFactory.eINSTANCE.createDiagramStyle());
222
		diagram.setType(ParametricEditPart.MODEL_ID);
223
		diagram.setElement(getSemanticElement(semanticAdapter));
224
		diagram.setMeasurementUnit(MeasurementUnit.PIXEL_LITERAL);
225
		return diagram;
226
	}
227
228
	/**
229
	 * @generated
230
	 */
231
	public Node createNode(IAdaptable semanticAdapter, View containerView, String semanticHint, int index, boolean persisted, PreferencesHint preferencesHint) {
232
		final EObject domainElement = getSemanticElement(semanticAdapter);
233
		final int visualID;
234
		if(semanticHint == null) {
235
			visualID = SysmlVisualIDRegistry.getNodeVisualID(containerView, domainElement);
236
		} else {
237
			visualID = SysmlVisualIDRegistry.getVisualID(semanticHint);
238
		}
239
		switch(visualID) {
240
		case ConstraintPropertyEditPart.VISUAL_ID:
241
			return createConstraintProperty_2003(domainElement, containerView, index, persisted, preferencesHint);
242
		case PropertyEditPart.VISUAL_ID:
243
			return createProperty_2005(domainElement, containerView, index, persisted, preferencesHint);
244
		case Property2EditPart.VISUAL_ID:
245
			return createProperty_3002(domainElement, containerView, index, persisted, preferencesHint);
246
		}
247
		// can't happen, provided #provides(CreateNodeViewOperation) is correct
248
		return null;
249
	}
250
251
	/**
252
	 * @generated
253
	 */
254
	public Edge createEdge(IAdaptable semanticAdapter, View containerView, String semanticHint, int index, boolean persisted, PreferencesHint preferencesHint) {
255
		IElementType elementType = getSemanticElementType(semanticAdapter);
256
		String elementTypeHint = ((IHintedType)elementType).getSemanticHint();
257
		switch(SysmlVisualIDRegistry.getVisualID(elementTypeHint)) {
258
		case ConnectorEditPart.VISUAL_ID:
259
			return createConnector_4001(getSemanticElement(semanticAdapter), containerView, index, persisted, preferencesHint);
260
		}
261
		// can never happen, provided #provides(CreateEdgeViewOperation) is correct
262
		return null;
263
	}
264
265
	/**
266
	 * @generated NOT
267
	 */
268
	public Node createConstraintProperty_2003(EObject domainElement, View containerView, int index, boolean persisted, PreferencesHint preferencesHint) {
269
		Shape node = NotationFactory.eINSTANCE.createShape();
270
		node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
271
		node.setType(SysmlVisualIDRegistry.getType(ConstraintPropertyEditPart.VISUAL_ID));
272
		ViewUtil.insertChildView(containerView, node, index, persisted);
273
		node.setElement(domainElement);
274
		// node.setElement(((ConstraintProperty) domainElement).getBase_Property());
275
276
		stampShortcut(containerView, node);
277
		// initializeFromPreferences
278
		final IPreferenceStore prefStore = (IPreferenceStore)preferencesHint.getPreferenceStore();
279
280
		initForegroundFromPrefs(node, prefStore, "ConstraintProperty");
281
282
		initFontStyleFromPrefs(node, prefStore, "ConstraintProperty");
283
284
		initBackgroundFromPrefs(node, prefStore, "ConstraintProperty");
285
286
		Node label5001 = createLabel(node, SysmlVisualIDRegistry.getType(ConstraintPropertyNameEditPart.VISUAL_ID));
287
		Node label5004 = createLabel(node, SysmlVisualIDRegistry.getType(ConstraintLabelEditPart.VISUAL_ID));
288
289
		// create the associated properties
290
		Type type = ((ConstraintProperty)domainElement).getBase_Property().getType();
291
		if(type != null && type instanceof StructuredClassifier) {
292
			for(Property property : ((StructuredClassifier)type).getOwnedAttributes()) {
293
				createProperty_3002(property, node, index, persisted, preferencesHint);
294
			}
295
		}
296
		return node;
297
	}
298
299
	/**
300
	 * @generated
301
	 */
302
	public Node createProperty_2005(EObject domainElement, View containerView, int index, boolean persisted, PreferencesHint preferencesHint) {
303
		Shape node = NotationFactory.eINSTANCE.createShape();
304
		node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
305
		node.setType(SysmlVisualIDRegistry.getType(PropertyEditPart.VISUAL_ID));
306
		ViewUtil.insertChildView(containerView, node, index, persisted);
307
		node.setElement(domainElement);
308
		stampShortcut(containerView, node);
309
		// initializeFromPreferences 
310
		final IPreferenceStore prefStore = (IPreferenceStore)preferencesHint.getPreferenceStore();
311
312
		PreferenceInitializerForElementHelper.initForegroundFromPrefs(node, prefStore, "Property");
313
314
		PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Property");
315
316
		PreferenceInitializerForElementHelper.initBackgroundFromPrefs(node, prefStore, "Property");
317
318
		Node label5002 = createLabel(node, SysmlVisualIDRegistry.getType(PropertyNameEditPart.VISUAL_ID));
319
320
		return node;
321
	}
322
323
	/**
324
	 * @generated
325
	 */
326
	public Node createProperty_3002(EObject domainElement, View containerView, int index, boolean persisted, PreferencesHint preferencesHint) {
327
		Shape node = NotationFactory.eINSTANCE.createShape();
328
		node.getStyles().add(NotationFactory.eINSTANCE.createHintedDiagramLinkStyle());
329
		node.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
330
		node.setType(SysmlVisualIDRegistry.getType(Property2EditPart.VISUAL_ID));
331
		ViewUtil.insertChildView(containerView, node, index, persisted);
332
		node.setElement(domainElement);
333
		// initializeFromPreferences 
334
		final IPreferenceStore prefStore = (IPreferenceStore)preferencesHint.getPreferenceStore();
335
336
		PreferenceInitializerForElementHelper.initForegroundFromPrefs(node, prefStore, "Property");
337
338
		PreferenceInitializerForElementHelper.initFontStyleFromPrefs(node, prefStore, "Property");
339
340
		PreferenceInitializerForElementHelper.initBackgroundFromPrefs(node, prefStore, "Property");
341
342
		Node label5003 = createLabel(node, SysmlVisualIDRegistry.getType(PropertyName2EditPart.VISUAL_ID));
343
		label5003.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
344
345
		Location location5003 = (Location)label5003.getLayoutConstraint();
346
		location5003.setX(0);
347
		location5003.setY(5);
348
349
		return node;
350
	}
351
352
	/**
353
	 * @generated
354
	 */
355
	public Edge createConnector_4001(EObject domainElement, View containerView, int index, boolean persisted, PreferencesHint preferencesHint) {
356
		Connector edge = NotationFactory.eINSTANCE.createConnector();
357
		edge.getStyles().add(NotationFactory.eINSTANCE.createFontStyle());
358
		RelativeBendpoints bendpoints = NotationFactory.eINSTANCE.createRelativeBendpoints();
359
		ArrayList<RelativeBendpoint> points = new ArrayList<RelativeBendpoint>(2);
360
		points.add(new RelativeBendpoint());
361
		points.add(new RelativeBendpoint());
362
		bendpoints.setPoints(points);
363
		edge.setBendpoints(bendpoints);
364
		ViewUtil.insertChildView(containerView, edge, index, persisted);
365
		edge.setType(SysmlVisualIDRegistry.getType(ConnectorEditPart.VISUAL_ID));
366
		edge.setElement(domainElement);
367
		// initializePreferences
368
		final IPreferenceStore prefStore = (IPreferenceStore)preferencesHint.getPreferenceStore();
369
370
		PreferenceInitializerForElementHelper.initForegroundFromPrefs(edge, prefStore, "Connector");
371
372
		PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, "Connector");
373
374
		//org.eclipse.gmf.runtime.notation.Routing routing = org.eclipse.gmf.runtime.notation.Routing.get(prefStore.getInt(org.eclipse.gmf.runtime.diagram.ui.preferences.IPreferenceConstants.PREF_LINE_STYLE));
375
		//if (routing != null) {
376
		//	org.eclipse.gmf.runtime.diagram.core.util.ViewUtil.setStructuralFeatureValue(edge, org.eclipse.gmf.runtime.notation.NotationPackage.eINSTANCE.getRoutingStyle_Routing(), routing);
377
		//}
378
379
		PreferenceInitializerForElementHelper.initRountingFromPrefs(edge, prefStore, "Connector");
380
381
		Node label6001 = createLabel(edge, SysmlVisualIDRegistry.getType(ConnectorNameEditPart.VISUAL_ID));
382
		label6001.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
383
		Location location6001 = (Location)label6001.getLayoutConstraint();
384
		location6001.setX(0);
385
		location6001.setY(40);
386
387
		PreferenceInitializerForElementHelper.initLabelVisibilityFromPrefs(edge, prefStore, "Connector");
388
389
		return edge;
390
	}
391
392
	/**
393
	 * @generated
394
	 */
395
	protected void stampShortcut(View containerView, Node target) {
396
		if(!ParametricEditPart.MODEL_ID.equals(SysmlVisualIDRegistry.getModelID(containerView))) {
397
			EAnnotation shortcutAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
398
			shortcutAnnotation.setSource("Shortcut"); //$NON-NLS-1$
399
			shortcutAnnotation.getDetails().put("modelID", ParametricEditPart.MODEL_ID); //$NON-NLS-1$
400
			target.getEAnnotations().add(shortcutAnnotation);
401
		}
402
	}
403
404
	/**
405
	 * @generated
406
	 */
407
	protected Node createLabel(View owner, String hint) {
408
		DecorationNode rv = NotationFactory.eINSTANCE.createDecorationNode();
409
		rv.setType(hint);
410
		ViewUtil.insertChildView(owner, rv, ViewUtil.APPEND, true);
411
		return rv;
412
	}
413
414
	/**
415
	 * @generated
416
	 */
417
	protected EObject getSemanticElement(IAdaptable semanticAdapter) {
418
		if(semanticAdapter == null) {
419
			return null;
420
		}
421
		EObject eObject = (EObject)semanticAdapter.getAdapter(EObject.class);
422
		if(eObject != null) {
423
			return EMFCoreUtil.resolve(TransactionUtil.getEditingDomain(eObject), eObject);
424
		}
425
		return null;
426
	}
427
428
	/**
429
	 * @generated
430
	 */
431
	protected IElementType getSemanticElementType(IAdaptable semanticAdapter) {
432
		if(semanticAdapter == null) {
433
			return null;
434
		}
435
		return (IElementType)semanticAdapter.getAdapter(IElementType.class);
436
	}
437
438
	/**
439
	 * @generated
440
	 */
441
	private void initFontStyleFromPrefs(View view, final IPreferenceStore store, String elementName) {
442
		String fontConstant = PreferenceConstantHelper.getElementConstant(elementName, PreferenceConstantHelper.FONT);
443
		String fontColorConstant = PreferenceConstantHelper.getElementConstant(elementName, PreferenceConstantHelper.COLOR_FONT);
444
445
		FontStyle viewFontStyle = (FontStyle)view.getStyle(NotationPackage.Literals.FONT_STYLE);
446
		if(viewFontStyle != null) {
447
			FontData fontData = PreferenceConverter.getFontData(store, fontConstant);
448
			viewFontStyle.setFontName(fontData.getName());
449
			viewFontStyle.setFontHeight(fontData.getHeight());
450
			viewFontStyle.setBold((fontData.getStyle() & SWT.BOLD) != 0);
451
			viewFontStyle.setItalic((fontData.getStyle() & SWT.ITALIC) != 0);
452
453
			org.eclipse.swt.graphics.RGB fontRGB = PreferenceConverter.getColor(store, fontColorConstant);
454
			viewFontStyle.setFontColor(FigureUtilities.RGBToInteger(fontRGB).intValue());
455
		}
456
	}
457
458
	/**
459
	 * @generated
460
	 */
461
	private void initForegroundFromPrefs(View view, final IPreferenceStore store, String elementName) {
462
		String lineColorConstant = PreferenceConstantHelper.getElementConstant(elementName, PreferenceConstantHelper.COLOR_LINE);
463
		org.eclipse.swt.graphics.RGB lineRGB = PreferenceConverter.getColor(store, lineColorConstant);
464
		ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLineStyle_LineColor(), FigureUtilities.RGBToInteger(lineRGB));
465
	}
466
467
	/**
468
	 * @generated
469
	 */
470
	private void initBackgroundFromPrefs(View view, final IPreferenceStore store, String elementName) {
471
		String fillColorConstant = PreferenceConstantHelper.getElementConstant(elementName, PreferenceConstantHelper.COLOR_FILL);
472
		String gradientColorConstant = PreferenceConstantHelper.getElementConstant(elementName, PreferenceConstantHelper.COLOR_GRADIENT);
473
		String gradientPolicyConstant = PreferenceConstantHelper.getElementConstant(elementName, PreferenceConstantHelper.GRADIENT_POLICY);
474
475
		org.eclipse.swt.graphics.RGB fillRGB = PreferenceConverter.getColor(store, fillColorConstant);
476
		ViewUtil.setStructuralFeatureValue(view, NotationPackage.eINSTANCE.getFillStyle_FillColor(), FigureUtilities.RGBToInteger(fillRGB));
477
478
		FillStyle fillStyle = (FillStyle)view.getStyle(NotationPackage.Literals.FILL_STYLE);
479
		fillStyle.setFillColor(FigureUtilities.RGBToInteger(fillRGB).intValue());
480
481
		;
482
		if(store.getBoolean(gradientPolicyConstant)) {
483
			GradientPreferenceConverter gradientPreferenceConverter = new GradientPreferenceConverter(store.getString(gradientColorConstant));
484
			fillStyle.setGradient(gradientPreferenceConverter.getGradientData());
485
			fillStyle.setTransparency(gradientPreferenceConverter.getTransparency());
486
		}
487
	}
488
489
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/sheet/SysmlPropertySection.java (-123 lines)
Lines 1-123 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.sheet;
15
16
import java.util.ArrayList;
17
import java.util.Iterator;
18
19
import org.eclipse.core.runtime.IAdaptable;
20
import org.eclipse.emf.common.notify.AdapterFactory;
21
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
22
import org.eclipse.emf.edit.provider.IItemPropertySource;
23
import org.eclipse.emf.edit.ui.provider.PropertySource;
24
import org.eclipse.emf.transaction.TransactionalEditingDomain;
25
import org.eclipse.emf.transaction.util.TransactionUtil;
26
import org.eclipse.gef.EditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.properties.sections.AdvancedPropertySection;
28
import org.eclipse.gmf.runtime.notation.View;
29
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.ui.IWorkbenchPart;
32
import org.eclipse.ui.views.properties.IPropertySource;
33
import org.eclipse.ui.views.properties.IPropertySourceProvider;
34
35
/**
36
 * @generated
37
 */
38
public class SysmlPropertySection extends AdvancedPropertySection implements IPropertySourceProvider {
39
40
	/**
41
	 * @generated
42
	 */
43
	public IPropertySource getPropertySource(Object object) {
44
		if(object instanceof IPropertySource) {
45
			return (IPropertySource)object;
46
		}
47
		AdapterFactory af = getAdapterFactory(object);
48
		if(af != null) {
49
			IItemPropertySource ips = (IItemPropertySource)af.adapt(object, IItemPropertySource.class);
50
			if(ips != null) {
51
				return new PropertySource(object, ips);
52
			}
53
		}
54
		if(object instanceof IAdaptable) {
55
			return (IPropertySource)((IAdaptable)object).getAdapter(IPropertySource.class);
56
		}
57
		return null;
58
	}
59
60
	/**
61
	 * @generated
62
	 */
63
	protected IPropertySourceProvider getPropertySourceProvider() {
64
		return this;
65
	}
66
67
	/**
68
	 * Modify/unwrap selection.
69
	 * 
70
	 * @generated
71
	 */
72
	protected Object transformSelection(Object selected) {
73
74
		if(selected instanceof EditPart) {
75
			Object model = ((EditPart)selected).getModel();
76
			return model instanceof View ? ((View)model).getElement() : null;
77
		}
78
		if(selected instanceof View) {
79
			return ((View)selected).getElement();
80
		}
81
		if(selected instanceof IAdaptable) {
82
			View view = (View)((IAdaptable)selected).getAdapter(View.class);
83
			if(view != null) {
84
				return view.getElement();
85
			}
86
		}
87
		return selected;
88
	}
89
90
	/**
91
	 * @generated
92
	 */
93
	public void setInput(IWorkbenchPart part, ISelection selection) {
94
		if(selection.isEmpty() || false == selection instanceof StructuredSelection) {
95
			super.setInput(part, selection);
96
			return;
97
		}
98
		final StructuredSelection structuredSelection = ((StructuredSelection)selection);
99
		ArrayList transformedSelection = new ArrayList(structuredSelection.size());
100
		for(Iterator it = structuredSelection.iterator(); it.hasNext();) {
101
			Object r = transformSelection(it.next());
102
			if(r != null) {
103
				transformedSelection.add(r);
104
			}
105
		}
106
		super.setInput(part, new StructuredSelection(transformedSelection));
107
	}
108
109
	/**
110
	 * @generated
111
	 */
112
	protected AdapterFactory getAdapterFactory(Object object) {
113
		if(getEditingDomain() instanceof AdapterFactoryEditingDomain) {
114
			return ((AdapterFactoryEditingDomain)getEditingDomain()).getAdapterFactory();
115
		}
116
		TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(object);
117
		if(editingDomain != null) {
118
			return ((AdapterFactoryEditingDomain)editingDomain).getAdapterFactory();
119
		}
120
		return null;
121
	}
122
123
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/sheet/SysmlSheetLabelProvider.java (-91 lines)
Lines 1-91 Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009 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
 *  Emilien Perico (Atos Origin) emilien.perico@atosorigin.com - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.sheet;
15
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
18
import org.eclipse.gmf.runtime.notation.View;
19
import org.eclipse.jface.viewers.BaseLabelProvider;
20
import org.eclipse.jface.viewers.ILabelProvider;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.papyrus.sysml.diagram.parametric.navigator.SysmlNavigatorGroup;
23
import org.eclipse.papyrus.sysml.diagram.parametric.part.SysmlVisualIDRegistry;
24
import org.eclipse.papyrus.sysml.diagram.parametric.providers.SysmlElementTypes;
25
import org.eclipse.swt.graphics.Image;
26
27
/**
28
 * @generated
29
 */
30
public class SysmlSheetLabelProvider extends BaseLabelProvider implements ILabelProvider {
31
32
	/**
33
	 * @generated
34
	 */
35
	public String getText(Object element) {
36
		element = unwrap(element);
37
		if(element instanceof SysmlNavigatorGroup) {
38
			return ((SysmlNavigatorGroup)element).getGroupName();
39
		}
40
		IElementType etype = getElementType(getView(element));
41
		return etype == null ? "" : etype.getDisplayName();
42
	}
43
44
	/**
45
	 * @generated
46
	 */
47
	public Image getImage(Object element) {
48
		IElementType etype = getElementType(getView(unwrap(element)));
49
		return etype == null ? null : SysmlElementTypes.getImage(etype);
50
	}
51
52
	/**
53
	 * @generated
54
	 */
55
	private Object unwrap(Object element) {
56
		if(element instanceof IStructuredSelection) {
57
			return ((IStructuredSelection)element).getFirstElement();
58
		}
59
		return element;
60
	}
61
62
	/**
63
	 * @generated
64
	 */
65
	private View getView(Object element) {
66
		if(element instanceof View) {
67
			return (View)element;
68
		}
69
		if(element instanceof IAdaptable) {
70
			return (View)((IAdaptable)element).getAdapter(View.class);
71
		}
72
		return null;
73
	}
74
75
	/**
76
	 * @generated
77
	 */
78
	private IElementType getElementType(View view) {
79
		// For intermediate views climb up the containment hierarchy to find the one associated with an element type.
80
		while(view != null) {
81
			int vid = SysmlVisualIDRegistry.getVisualID(view);
82
			IElementType etype = SysmlElementTypes.getElementType(vid);
83
			if(etype != null) {
84
				return etype;
85
			}
86
			view = view.eContainer() instanceof View ? (View)view.eContainer() : null;
87
		}
88
		return null;
89
	}
90
91
}
(-)a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/utils/BlockDropHelper.java (+239 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2011 CEA LIST.
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
 *		
11
 *		CEA LIST - Initial API and implementation
12
 *
13
 *****************************************************************************/
14
package org.eclipse.papyrus.sysml.diagram.parametric.utils;
15
16
import org.eclipse.core.runtime.IAdaptable;
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.emf.transaction.TransactionalEditingDomain;
19
import org.eclipse.gef.commands.Command;
20
import org.eclipse.gef.commands.CompoundCommand;
21
import org.eclipse.gef.commands.UnexecutableCommand;
22
import org.eclipse.gmf.runtime.common.core.command.ICommand;
23
import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
24
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
25
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
26
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
27
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
28
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
29
import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
30
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
31
import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
32
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
33
import org.eclipse.gmf.runtime.notation.Node;
34
import org.eclipse.gmf.runtime.notation.View;
35
import org.eclipse.papyrus.infra.gmfdiag.common.utils.ViewDescriptorUtil;
36
import org.eclipse.papyrus.infra.services.edit.commands.ConfigureFeatureCommandFactory;
37
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
38
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
39
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
40
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
41
import org.eclipse.papyrus.uml.diagram.common.helper.ElementHelper;
42
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
43
import org.eclipse.uml2.uml.Actor;
44
import org.eclipse.uml2.uml.Association;
45
import org.eclipse.uml2.uml.DataType;
46
import org.eclipse.uml2.uml.Type;
47
import org.eclipse.uml2.uml.TypedElement;
48
import org.eclipse.uml2.uml.UMLPackage;
49
50
/**
51
 * This class provides convenience methods to create Block specific drop action (Part or Reference creation).
52
 */
53
public class BlockDropHelper extends ElementHelper {
54
55
	public BlockDropHelper(TransactionalEditingDomain editDomain) {
56
		this.editDomain = editDomain;
57
	}
58
59
	public Command getDropAsStructureItemOnPart(DropObjectsRequest request, GraphicalEditPart host, IElementType elementType) {
60
		String label = "";
61
		if(elementType == SysMLElementTypes.PART_PROPERTY) {
62
			label = "Create a new Part";
63
		}
64
		if(elementType == SysMLElementTypes.REFERENCE_PROPERTY) {
65
			label = "Create a new Reference";
66
		}
67
		if(elementType == SysMLElementTypes.ACTOR_PART_PROPERTY) {
68
			label = "Create a new ActorPart";
69
		}
70
		if(elementType == SysMLElementTypes.VALUE_PROPERTY) {
71
			label = "Create a new Value";
72
		}
73
		if(elementType == UMLElementTypes.PROPERTY) {
74
			label = "Create a new Property";
75
		}
76
		CompoundCommand cc = new CompoundCommand(label);
77
78
		Object droppedEObject = request.getObjects().get(0);
79
		if(!isValidStructureItemType(droppedEObject, elementType)) {
80
			return UnexecutableCommand.INSTANCE;
81
		}
82
83
		// Verify target nature
84
		EObject target = getHostEObject(host);
85
		if((!(target instanceof TypedElement)) || (((TypedElement)target).getType() == null)) {
86
			return UnexecutableCommand.INSTANCE;
87
		}
88
89
		// The target type has to be a Block (will hold the created Port)
90
		Type targetType = ((TypedElement)target).getType();
91
		if(!((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(targetType)) {
92
			return UnexecutableCommand.INSTANCE;
93
		}
94
95
		// Prepare a command for the element creation and the drop in diagram
96
97
		// 1. Prepare creation command
98
		ICommand createElementCommand = null;
99
		CreateElementRequest createElementRequest = new CreateElementRequest(getEditingDomain(), targetType, elementType);
100
		createElementRequest.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new ConfigureFeatureCommandFactory(UMLPackage.eINSTANCE.getTypedElement_Type(), request.getObjects().get(0)));
101
		IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetType);
102
		if(provider != null) {
103
			createElementCommand = provider.getEditCommand(createElementRequest);
104
		}
105
		IAdaptable createElementRequestAdapter = new CreateElementRequestAdapter(createElementRequest);
106
107
		// 2. Prepare the drop command
108
		ViewDescriptor descriptor = new ViewDescriptor(createElementRequestAdapter, Node.class, /* explicit semantic hint is mandatory */ null, ViewDescriptorUtil.PERSISTED, host.getDiagramPreferencesHint());
109
		CreateViewRequest createViewRequest = new CreateViewRequest(descriptor);
110
		createViewRequest.setLocation(request.getLocation().getCopy());
111
		Command viewCreateCommand = host.getCommand(createViewRequest);
112
113
		// 3. Create the compound command
114
		cc.add(new ICommandProxy(createElementCommand));
115
		cc.add(viewCreateCommand);
116
117
		return cc;
118
	}
119
120
	public Command getDropAsStructureItem(DropObjectsRequest request, GraphicalEditPart host, IElementType elementType) {
121
		Object droppedEObject = request.getObjects().get(0);
122
		String label = "";
123
		
124
		// Filter part/reference : a property type by a ConstraintBlock MUST be a ConstraintProperty
125
		if(elementType == SysMLElementTypes.PART_PROPERTY) {
126
			label = "Create a new Part";
127
			if (droppedEObject instanceof Type) {
128
				if (((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type)droppedEObject)) {
129
					return UnexecutableCommand.INSTANCE;
130
				}
131
			}
132
		}
133
		if(elementType == SysMLElementTypes.REFERENCE_PROPERTY) {
134
			label = "Create a new Reference";
135
			if (droppedEObject instanceof Type) {
136
				if (((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type)droppedEObject)) {
137
					return UnexecutableCommand.INSTANCE;
138
				}
139
			}
140
		}
141
		if(elementType == SysMLElementTypes.ACTOR_PART_PROPERTY) {
142
			label = "Create a new ActorPart";
143
		}
144
		if(elementType == SysMLElementTypes.VALUE_PROPERTY) {
145
			label = "Create a new Value";
146
		}
147
		if(elementType == UMLElementTypes.PROPERTY) {
148
			label = "Create a new Property";
149
		}
150
		
151
		if(elementType == SysMLElementTypes.CONSTRAINT_PROPERTY) {
152
			label = "Create a new ConstraintProperty";
153
			// Constraint Property on ConstraintBlock strictly
154
			if (droppedEObject instanceof Type) {
155
				if (!((ISpecializationType)SysMLElementTypes.CONSTRAINT_BLOCK).getMatcher().matches((Type)droppedEObject)) {
156
					return UnexecutableCommand.INSTANCE;
157
				}
158
			}
159
		}
160
		CompoundCommand cc = new CompoundCommand(label);
161
162
		if(!isValidStructureItemType(droppedEObject, elementType)) {
163
			return UnexecutableCommand.INSTANCE;
164
		}
165
166
		// Prepare a command for the element creation and the drop in diagram
167
168
		// 1. Prepare creation command
169
		ICommand createElementCommand = null;
170
		CreateElementRequest createElementRequest = new CreateElementRequest(getEditingDomain(), getHostEObject(host), elementType);
171
		createElementRequest.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new ConfigureFeatureCommandFactory(UMLPackage.eINSTANCE.getTypedElement_Type(), request.getObjects().get(0)));
172
		IElementEditService provider = ElementEditServiceUtils.getCommandProvider(getHostEObject(host));
173
		if(provider != null) {
174
			createElementCommand = provider.getEditCommand(createElementRequest);
175
		}
176
		IAdaptable createElementRequestAdapter = new CreateElementRequestAdapter(createElementRequest);
177
178
		// 2. Prepare the drop command
179
		ViewDescriptor descriptor = new ViewDescriptor(createElementRequestAdapter, Node.class, /* explicit semantic hint is mandatory */ null, ViewDescriptorUtil.PERSISTED, host.getDiagramPreferencesHint());
180
		CreateViewRequest createViewRequest = new CreateViewRequest(descriptor);
181
		createViewRequest.setLocation(request.getLocation().getCopy());
182
		Command viewCreateCommand = host.getCommand(createViewRequest);
183
184
		// 3. Create the compound command
185
		cc.add(new ICommandProxy(createElementCommand));
186
		cc.add(viewCreateCommand);
187
188
		return cc;
189
	}
190
191
	private boolean isValidStructureItemType(Object object, IElementType elementType) {
192
		boolean isValid = false;
193
194
		if((object != null) && (object instanceof Type) && !(object instanceof Association)) {
195
196
			Type type = (Type)object;
197
			if((elementType == SysMLElementTypes.PART_PROPERTY) || (elementType == SysMLElementTypes.REFERENCE_PROPERTY)) {
198
				if(((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(type)) {
199
					isValid = true;
200
				}
201
			}
202
			if(elementType == SysMLElementTypes.ACTOR_PART_PROPERTY) {
203
				if(type instanceof Actor) {
204
					isValid = true;
205
				}
206
			}
207
			if(elementType == SysMLElementTypes.VALUE_PROPERTY) {
208
				if(((ISpecializationType)SysMLElementTypes.VALUE_TYPE).getMatcher().matches(type) || (type instanceof DataType)) {
209
					isValid = true;
210
				}
211
			}
212
			if((elementType == SysMLElementTypes.CONSTRAINT_PROPERTY)) {
213
				if(((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(type)) {
214
					isValid = true;
215
				}
216
			}
217
			if(elementType == UMLElementTypes.PROPERTY) {
218
				if(!((ISpecializationType)SysMLElementTypes.BLOCK).getMatcher().matches(type)
219
						&& !(type instanceof Actor)
220
						&& !(type instanceof DataType)
221
						&& !((ISpecializationType)SysMLElementTypes.VALUE_TYPE).getMatcher().matches(type)) {
222
					isValid = true;
223
				}
224
			}
225
		}
226
227
		return isValid;
228
	}
229
230
	/**
231
	 * return the host Edit Part's semantic element, if the semantic element
232
	 * is <code>null</code> or unresolvable it will return <code>null</code>
233
	 * 
234
	 * @return EObject
235
	 */
236
	protected EObject getHostEObject(GraphicalEditPart host) {
237
		return ViewUtil.resolveSemanticElement((View)host.getModel());
238
	}
239
}
(-)a/plugins/sysml/modelexplorer/org.eclipse.papyrus.sysml.modelexplorer/src-gen/org/eclipse/papyrus/sysml/modelexplorer/handler/ConstraintPropertyHandler.java (+44 lines)
Lines 11-17 Link Here
11
 *****************************************************************************/
11
 *****************************************************************************/
12
package org.eclipse.papyrus.sysml.modelexplorer.handler;
12
package org.eclipse.papyrus.sysml.modelexplorer.handler;
13
13
14
import org.eclipse.emf.common.command.Command;
15
import org.eclipse.emf.common.command.UnexecutableCommand;
16
import org.eclipse.emf.ecore.EObject;
17
import org.eclipse.emf.ecore.EReference;
18
import org.eclipse.gmf.runtime.common.core.command.ICommand;
14
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
19
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
20
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
21
import org.eclipse.papyrus.infra.services.edit.commands.IConfigureCommandFactory;
22
import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
23
import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
24
import org.eclipse.papyrus.sysml.diagram.common.commands.CreateConstraintPropertyWithTypeConfigureCommandFactory;
25
import org.eclipse.papyrus.sysml.diagram.common.commands.CreatePartWithTypeConfigureCommandFactory;
15
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
26
import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
16
27
17
/**
28
/**
Lines 37-40 Link Here
37
	protected IElementType getElementTypeToCreate() {
48
	protected IElementType getElementTypeToCreate() {
38
		return SysMLElementTypes.CONSTRAINT_PROPERTY;
49
		return SysMLElementTypes.CONSTRAINT_PROPERTY;
39
	}
50
	}
51
	
52
	/**
53
	 * {@inheritDoc}
54
	 */
55
	@Override
56
	protected Command buildCommand() {
57
58
		if(getCommandContext() == null) {
59
			return UnexecutableCommand.INSTANCE;
60
		}
61
62
		EObject container = getCommandContext().getContainer();
63
		EReference reference = getCommandContext().getReference();
64
65
		IElementEditService provider = ElementEditServiceUtils.getCommandProvider(container);
66
		if(provider == null) {
67
			return UnexecutableCommand.INSTANCE;
68
		}
69
70
		CreateElementRequest createRequest = null;
71
		if(reference == null) {
72
			createRequest = new CreateElementRequest(container, getElementTypeToCreate());
73
		} else {
74
			createRequest = new CreateElementRequest(container, getElementTypeToCreate(), reference);
75
		}
76
		createRequest.setParameter(IConfigureCommandFactory.CONFIGURE_COMMAND_FACTORY_ID, new CreateConstraintPropertyWithTypeConfigureCommandFactory());
77
78
		// Retrieve create command from the Element Edit service
79
		ICommand createGMFCommand = provider.getEditCommand(createRequest);
80
		Command emfCommand = new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(createGMFCommand);
81
		return emfCommand;
82
	}
83
40
}
84
}
(-)a/plugins/sysml/org.eclipse.papyrus.sysml.service.types/src/org/eclipse/papyrus/sysml/service/types/helper/ConstraintParameterEditHelperAdvice.java (+50 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2010 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
 *****************************************************************************/
11
package org.eclipse.papyrus.sysml.service.types.helper;
12
13
import org.eclipse.emf.ecore.EObject;
14
import org.eclipse.gmf.runtime.common.core.command.ICommand;
15
import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
16
import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
17
import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
18
import org.eclipse.papyrus.sysml.constraints.ConstraintBlock;
19
import org.eclipse.papyrus.sysml.constraints.ConstraintProperty;
20
import org.eclipse.uml2.uml.Class;
21
import org.eclipse.uml2.uml.Property;
22
import org.eclipse.uml2.uml.Type;
23
import org.eclipse.uml2.uml.util.UMLUtil;
24
25
/** Specific advice for Property creation owned by a {@link ConstraintBlock}
26
 *	ConstraintParameter are defined in ConstraintProperty but really owned by ConstraintBlock  
27
 */
28
public class ConstraintParameterEditHelperAdvice extends AbstractEditHelperAdvice {
29
30
	@Override
31
	public ICommand getBeforeEditCommand(IEditCommandRequest request) {
32
		if (request instanceof ConfigureRequest) {
33
			EObject elementToConfigure = ((ConfigureRequest)request).getElementToConfigure();
34
			if (elementToConfigure != null && elementToConfigure instanceof Property) {
35
				EObject container = elementToConfigure.eContainer();
36
				if (container != null && container instanceof Property) {
37
					Property constraintProperty = (Property) container;
38
					if (UMLUtil.getStereotypeApplication(constraintProperty, ConstraintProperty.class) != null) {
39
						Type type = constraintProperty.getType();
40
						if (type != null && type instanceof Class && UMLUtil.getStereotypeApplication(type, ConstraintBlock.class) != null) {
41
							((Class)type).getOwnedAttributes().add((Property)elementToConfigure);
42
						}
43
					}
44
				}
45
			}
46
		}
47
		return super.getBeforeEditCommand(request);
48
	}
49
	
50
}
(-)a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/locator/ConstraintParameterPositionLocator.java (+108 lines)
Added Link Here
1
/*****************************************************************************
2
 * Copyright (c) 2009-2010 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
 *  Yann Tanguy (CEA LIST) yann.tanguy@cea.fr - Initial API and implementation
12
 *  Vincent Lorenzo(CEA-List) vincent.lorenzo@cea.fr - getCurrentSideOfParent()
13
 *****************************************************************************/
14
package org.eclipse.papyrus.uml.diagram.common.locator;
15
16
import org.eclipse.draw2d.IFigure;
17
import org.eclipse.draw2d.geometry.Rectangle;
18
19
/**
20
 * 
21
 * This code comes form composite diagram. I was copied to avoid dependencies
22
 * This class is used to constrain the position of ConstraintParameter when they are added on a ConstraintProperty
23
 * 
24
 * <pre>
25
 * 	 +-------------------+
26
 * 	 |   [Constraint]    |
27
 * 	 +-------------------+
28
 * 	 |                   |
29
 * 	 |                   |
30
 * 	 |                 +-+ - Expected position of ConstraintParameter 
31
 * 	 |                 +-+
32
 * 	 |                   |
33
 * 	 +-------------------+
34
 * 
35
 * </pre>
36
 * 
37
 * <pre>
38
 * TODO  : The ConstraintParameter is not re-sizable
39
 * </pre>
40
 */
41
public class ConstraintParameterPositionLocator extends PortPositionLocator {
42
43
	/** the width of the area surrounding the parent figure where border item can be put */
44
45
	private int constraintParameterSize = 20;
46
	
47
	/** Constructor **/
48
	public ConstraintParameterPositionLocator(IFigure parentFigure, int preferredSide) {
49
		super(parentFigure, preferredSide);
50
		borderItemOffset = 0;
51
	}
52
53
	/**
54
	 * 
55
	 * @param proposedLocation
56
	 *        the proposed location
57
	 * @return a possible location on parent figure border
58
	 */
59
	public Rectangle getPreferredLocation(Rectangle proposedLocation) {
60
61
		// Initialize port location with proposed location
62
		// and resolve the bounds of it graphical parent
63
		Rectangle realLocation = new Rectangle(proposedLocation);
64
65
		Rectangle parentRec = getParentFigure().getBounds().getCopy();
66
67
		// Calculate Max position around the graphical parent (1/2 size or the port around
68
		// the graphical parent bounds.
69
		int xMin = parentRec.x;
70
		int xMax = parentRec.x + parentRec.width - constraintParameterSize;
71
		int yMin = parentRec.y;
72
		int yMax = parentRec.y + parentRec.height - constraintParameterSize;
73
74
		// Modify Port location if MAX X or Y are exceeded
75
		if(realLocation.x < xMin) {
76
			realLocation.x = xMin;
77
		}
78
79
		if(realLocation.x > xMax) {
80
			realLocation.x = xMax;
81
		}
82
83
		if(realLocation.y < yMin) {
84
			realLocation.y = yMin;
85
		}
86
87
		if(realLocation.y > yMax) {
88
			realLocation.y = yMax;
89
		}
90
91
		// Ensure the port is positioned on its parent borders and not in the middle.
92
		// Modify position if needed.
93
		if((realLocation.y != yMin) && (realLocation.y != yMax)) {
94
			if((realLocation.x != xMin) && (realLocation.x != xMax)) {
95
96
				if(realLocation.x <= (xMin + (parentRec.width / 2))) {
97
					realLocation.x = xMin;
98
				} else {
99
					realLocation.x = xMax;
100
				}
101
			}
102
		}
103
104
		// Return constrained location
105
		return realLocation;
106
	}
107
108
}

Return to bug 297816