diff options
author | Mickael ADAM | 2014-08-29 09:54:21 +0000 |
---|---|---|
committer | Mickael ADAM | 2014-08-29 15:42:00 +0000 |
commit | 9d8ed1a8d2e8fdd460959696489f6979f4d140a6 (patch) | |
tree | 33fc2bbe7f82c3632088446412bbeb4f925754c4 /plugins/developer | |
parent | 9926e69a6d3f6dd3727636e1f056eb2da77f17b4 (diff) | |
parent | 9b896217b5c8540e4f4cfc26df2338e9ea0bf474 (diff) | |
download | org.eclipse.papyrus-9d8ed1a8d2e8fdd460959696489f6979f4d140a6.tar.gz org.eclipse.papyrus-9d8ed1a8d2e8fdd460959696489f6979f4d140a6.tar.xz org.eclipse.papyrus-9d8ed1a8d2e8fdd460959696489f6979f4d140a6.zip |
Merge branch 'change/30428/6' into master2
Patch Set 2:
-Fix some merge error
-Apply format and clean-up
Change-Id: I576a3342509315c9620c09e4186188504d237780
Signed-off-by: Mickael ADAM <mickael.adam@ALL4TEC.net>
Diffstat (limited to 'plugins/developer')
2 files changed, 226 insertions, 0 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.gmfgenextension/plugin.xml b/plugins/developer/org.eclipse.papyrus.gmfgenextension/plugin.xml index 40d84d21c23..70ab2fb840b 100644 --- a/plugins/developer/org.eclipse.papyrus.gmfgenextension/plugin.xml +++ b/plugins/developer/org.eclipse.papyrus.gmfgenextension/plugin.xml @@ -115,6 +115,18 @@ </enablement>
</action>
<action
+ class="org.eclipse.papyrus.papyrusgmfgenextension.popupaction.AddExternalNodeFloatingNameDisplayBehavior"
+ enablesFor="*"
+ id="org.eclipse.papyrus.papyrusgmfgenextension.popupaction.AddExternalNodeFloatingNameDisplayBehavior"
+ label="Add label to display Name as an external Floating node label"
+ menubarPath="org.eclipse.papyrus.papyrusgmfgenextension.popupaction.MenuPapyrus/AddExternalNodeFloatingNameDisplayBehavior">
+ <enablement>
+ <objectClass
+ name="org.eclipse.gmf.codegen.gmfgen.GenNode">
+ </objectClass>
+ </enablement>
+ </action>
+ <action
class="org.eclipse.papyrus.papyrusgmfgenextension.popupaction.AddHyperLinkPopupBarBehavior"
enablesFor="*"
id="org.eclipse.papyrus.papyrusgmfgenextension.popupaction.AddHyperLinkPopupBarBehavior"
diff --git a/plugins/developer/org.eclipse.papyrus.gmfgenextension/src/org/eclipse/papyrus/papyrusgmfgenextension/popupaction/AddExternalNodeFloatingNameDisplayBehavior.java b/plugins/developer/org.eclipse.papyrus.gmfgenextension/src/org/eclipse/papyrus/papyrusgmfgenextension/popupaction/AddExternalNodeFloatingNameDisplayBehavior.java new file mode 100644 index 00000000000..fe32541565f --- /dev/null +++ b/plugins/developer/org.eclipse.papyrus.gmfgenextension/src/org/eclipse/papyrus/papyrusgmfgenextension/popupaction/AddExternalNodeFloatingNameDisplayBehavior.java @@ -0,0 +1,214 @@ +/***************************************************************************** + * Copyright (c) 2009, 2014 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation + * + *****************************************************************************/ + +package org.eclipse.papyrus.papyrusgmfgenextension.popupaction; + +import java.util.Iterator; + +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gmf.codegen.gmfgen.FeatureLabelModelFacet; +import org.eclipse.gmf.codegen.gmfgen.FigureViewmap; +import org.eclipse.gmf.codegen.gmfgen.GMFGenFactory; +import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator; +import org.eclipse.gmf.codegen.gmfgen.GenExternalNodeLabel; +import org.eclipse.gmf.codegen.gmfgen.GenLinkLabel; +import org.eclipse.gmf.codegen.gmfgen.GenNode; +import org.eclipse.gmf.codegen.gmfgen.GenNodeLabel; +import org.eclipse.gmf.codegen.gmfgen.GenParsers; +import org.eclipse.gmf.codegen.gmfgen.PredefinedParser; +import org.eclipse.jface.action.IAction; +import org.eclipse.ui.IViewPart; + +/** + * this class is used to add a label to display name from external node + */ +public class AddExternalNodeFloatingNameDisplayBehavior extends Action { + + public static final String FIGURE_VIEWMAP_PATH = "org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel"; //$NON-NLS-1$ + + public static final String LABEL_POLICY_CLASS = "org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalLabelPrimaryDragRoleEditPolicy"; //$NON-NLS-1$ + + public static final String LABEL_POLICY_KEY = "org.eclipse.gef.EditPolicy.PRIMARY_DRAG_ROLE"; //$NON-NLS-1$ + + public static final String DEFAULT_GETTER_NAME = "getFloatingNameLabel"; //$NON-NLS-1$ + + public static final String DEFAULT_EDITPART_NAME_SUFFIX = "FloatingNameEditPart"; //$NON-NLS-1$ + + public static final String DEFAULT_EDITPOLICY_NAME_SUFFIX = "FloatingNameItemSemanticEditPolicy"; //$NON-NLS-1$ + + public static final String DEFAULT_WRAPPING_LABEL_CLASS = "org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel"; //$NON-NLS-1$ + + public static final String DEFAULT_PARSER_PATTERN = ""; //$NON-NLS-1$ + + public static final String GEN_CLASS_RT_CLASS = "Node"; //$NON-NLS-1$ + + public static final String GEN_CLASS_FACET_META_FEATURE = "NamedElement"; //$NON-NLS-1$ + + public static final String GEN_FEATURE_FACET_META_FEATURE = "name"; //$NON-NLS-1$ + + public static final String URI_NOTATION_GENMODEL = "org.eclipse.gmf.runtime.notation/model/notation.genmodel"; //$NON-NLS-1$ + + public static final String URI_UML_GENMODEL = "org.eclipse.uml2.uml/model/UML.genmodel"; //$NON-NLS-1$ + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) + */ + public void init(IViewPart view) { + // NO OP + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) + */ + public void run(IAction action) { + // Parse selected GenLink(s) and add the desired CustomBehavior + Iterator<EObject> it = getSelectedEObject().iterator(); + while(it.hasNext()) { + EObject eObject = it.next(); + if(eObject instanceof GenNode) { + //test if it has got a external node to display floating name + if(!hasAnFloatingNameExternalNode((GenNode)eObject)) { + createAnFloatingNameExternalNode((GenNode)eObject); + } + } + } + } + + /** + * creation an external node floating name + * + * @param eObject + * the parent genNode + */ + private void createAnFloatingNameExternalNode(GenNode eObject) { + //Create une external node label + GenExternalNodeLabel label = GMFGenFactory.eINSTANCE.createGenExternalNodeLabel(); + + //Set Name of the edit part + label.setEditPartClassName(eObject.getClassNamePrefix() + DEFAULT_EDITPART_NAME_SUFFIX); + //Set item semantic edit policy + label.setItemSemanticEditPolicyClassName(eObject.getClassNamePrefix() + DEFAULT_EDITPOLICY_NAME_SUFFIX); + //Set the Read only + label.setReadOnly(false); + + // Set GenLinkLabel VisualID with new unique ID + int visualID = SetVisualIDWithUnusedValue.getNewVisualID(eObject.eResource(), GenLinkLabel.class); + label.setVisualID(visualID); + + // Retrieve DiagramRunTimeClass in notation.genmodel (Node -> View) + URI uri_notation = URI.createPlatformPluginURI(URI_NOTATION_GENMODEL, false); + Resource notation = eObject.eResource().getResourceSet().getResource(uri_notation, true); + label.setDiagramRunTimeClass(findGenClass(notation, GEN_CLASS_RT_CLASS)); + + // Create Viewmap + FigureViewmap viewmap = GMFGenFactory.eINSTANCE.createFigureViewmap(); + viewmap.setFigureQualifiedClassName(FIGURE_VIEWMAP_PATH); + + // Create FeatureLabelModelFacet + FeatureLabelModelFacet facet = GMFGenFactory.eINSTANCE.createFeatureLabelModelFacet(); + facet.setEditPattern(DEFAULT_PARSER_PATTERN); + facet.setEditorPattern(DEFAULT_PARSER_PATTERN); + facet.setViewPattern(DEFAULT_PARSER_PATTERN); + + // Select NamedElement::name property in UML.genmodel for MetaFeatures + URI uri_uml = URI.createPlatformPluginURI(URI_UML_GENMODEL, false); + Resource uml = eObject.eResource().getResourceSet().getResource(uri_uml, true); + facet.getMetaFeatures().add(findGenFeature(uml, GEN_CLASS_FACET_META_FEATURE, GEN_FEATURE_FACET_META_FEATURE)); + //Attach Predefined Parser MessageFormatParser + //not good must find the predifined parser of the model... + + //Get the predefined parser. + PredefinedParser parser = getPredefinedParser(eObject); + facet.setParser(parser); + + // Attach created element one to another in the model + label.setViewmap(viewmap); + label.setModelFacet(facet); + + //Add custom Policy to have feedback + addCustomBehavior(label, LABEL_POLICY_KEY, LABEL_POLICY_CLASS); + + eObject.getLabels().add(label); + } + + /** + * Gets the predefined parser. + * + * @param eObject + * the e object + * @return the predefined parser + */ + private PredefinedParser getPredefinedParser(GenNode eObject) { + PredefinedParser parser = null; + ///get the ressource contents + EList<EObject> ressourceContents = eObject.eResource().getContents(); + for(EObject ressourceContent : ressourceContents) { + //get the Gen Editor Node + if(ressourceContent instanceof GenEditorGenerator) { + //Get Parsers node + GenParsers genParsers = ((GenEditorGenerator)ressourceContent).getLabelParsers(); + for(EObject GenParsersContent : genParsers.eContents()) { + //Get the predefined parser + if(GenParsersContent instanceof PredefinedParser) { + parser = (PredefinedParser)GenParsersContent; + } + } + } + } + return parser; + } + + /** + * Checks for a floating name external node. + * + * @param node + * the node + * @return true, if successful + */ + public boolean hasAnFloatingNameExternalNode(GenNode node) { + Iterator<GenNodeLabel> iterator = node.getLabels().iterator(); + while(iterator.hasNext()) { + GenNodeLabel currentGenNodeLabel = iterator.next(); + //check each child node + if(currentGenNodeLabel instanceof GenExternalNodeLabel) { + if(isAnFloatingNameExternalNode((GenExternalNodeLabel)currentGenNodeLabel)) { + return true; + } + } + } + return false; + } + + /** + * Checks if is an floating name external node. + * + * @param node + * the node + * @return true, if is an floating name external node + */ + public boolean isAnFloatingNameExternalNode(GenExternalNodeLabel node) { + //Look if the edit part name contains the default edit part name suffix + if(node.getEditPartClassName().contains(DEFAULT_EDITPART_NAME_SUFFIX)) { + return true; + } else { + return false; + } + } +} |