diff options
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common')
48 files changed, 3507 insertions, 382 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF index 5d8a68c0840..3b4fbd1f950 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF @@ -35,6 +35,10 @@ Export-Package: org.eclipse.papyrus.uml.diagram.common, org.eclipse.papyrus.uml.diagram.common.service.palette, org.eclipse.papyrus.uml.diagram.common.sheet, org.eclipse.papyrus.uml.diagram.common.stereotype, + org.eclipse.papyrus.uml.diagram.common.stereotype.display.command, + org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper, + org.eclipse.papyrus.uml.diagram.common.stereotype.migration, + org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies, org.eclipse.papyrus.uml.diagram.common.strategy.paste, org.eclipse.papyrus.uml.diagram.common.ui.dialogs, org.eclipse.papyrus.uml.diagram.common.ui.helper, @@ -74,7 +78,6 @@ Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="1.1.0", com.google.guava;bundle-version="11.0.0", org.eclipse.papyrus.uml.profile;bundle-version="1.1.0", org.eclipse.papyrus.infra.emf.appearance;bundle-version="1.1.0", - org.eclipse.papyrus.uml.appearance;bundle-version="1.1.0", org.eclipse.uml2.uml.edit;bundle-version="4.0.0", org.eclipse.papyrus.infra.core.log;bundle-version="1.1.0", org.eclipse.papyrus.infra.core.sasheditor;bundle-version="1.1.0", @@ -103,14 +106,17 @@ Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="1.1.0", org.eclipse.papyrus.emf.facet.custom.core;bundle-version="1.1.0", org.eclipse.papyrus.infra.gmfdiag.menu;bundle-version="1.1.0", org.eclipse.e4.ui.css.core, - org.eclipse.papyrus.infra.gmfdiag.canonical;bundle-version="1.1.0", org.eclipse.gmf.runtime.diagram.ui, - org.eclipse.gef + org.eclipse.papyrus.infra.gmfdiag.canonical;bundle-version="1.1.0", + org.eclipse.gef, + org.eclipse.papyrus.uml.appearance;bundle-version="1.1.0", + org.eclipse.emf.common Bundle-Vendor: %providerName Ant-Version: Apache Ant 1.7.0 Bundle-Version: 1.1.0.qualifier Eclipse-BuddyPolicy: dependent Bundle-Activator: org.eclipse.papyrus.uml.diagram.common.Activator Bundle-ManifestVersion: 2 -Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.common;singleton:=true +Bundle-SymbolicName: org.eclipse.papyrus.uml.diagram.common;singleton: + =true diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/DefferedAppliedStereotypeToDisplayCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/DefferedAppliedStereotypeToDisplayCommand.java index fa5a9cbe242..255e3bd3ec0 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/DefferedAppliedStereotypeToDisplayCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/DefferedAppliedStereotypeToDisplayCommand.java @@ -33,7 +33,12 @@ import com.google.common.collect.Collections2; /** * The Class AddAppliedStereotypeToDisplayCommand used to set the list of * applied stereotype to display + * + * @deprecated The Display of stereotype is now treated with notation View (Bug 455311) + * use the command into oep.uml.diagram.common.stereotype.display.command instead + * */ +@Deprecated public class DefferedAppliedStereotypeToDisplayCommand extends CreateEAnnotationCommand { /** The qualified names' stereotypes list . */ @@ -63,7 +68,7 @@ public class DefferedAppliedStereotypeToDisplayCommand extends CreateEAnnotation */ @Override protected void doExecute() { - View view = (View) adapter.getAdapter(View.class); + View view = adapter.getAdapter(View.class); EObject view_element = view.getElement(); Element element = (Element) view_element; Collection<String> strStereotypes = Collections2.transform(element.getAppliedStereotypes(), new Function<Stereotype, String>() { diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/UMLConnectionNodeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/UMLConnectionNodeEditPart.java index 98964d1ad62..1454218594d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/UMLConnectionNodeEditPart.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/UMLConnectionNodeEditPart.java @@ -23,14 +23,12 @@ import org.eclipse.gef.EditPart; import org.eclipse.gef.Request; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ConnectionEditPart; -import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper; -import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant; import org.eclipse.papyrus.uml.diagram.common.Activator; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ApplyStereotypeEditPolicy; import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideLabelEditPolicy; import org.eclipse.papyrus.uml.diagram.common.figure.edge.UMLEdgeFigure; import org.eclipse.papyrus.uml.diagram.common.service.ApplyStereotypeRequest; -import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil; import org.eclipse.papyrus.uml.tools.listeners.StereotypeElementListener.StereotypeExtensionNotification; import org.eclipse.swt.graphics.Image; import org.eclipse.uml2.uml.Element; @@ -187,7 +185,7 @@ public abstract class UMLConnectionNodeEditPart extends ConnectionEditPart imple * @return the list of stereotypes to display */ public String stereotypesToDisplay() { - String stereotypesToDisplay = StereotypeDisplayHelper.getInstance().getStereotypeTextToDisplay((View) getModel()); + String stereotypesToDisplay = StereotypeDisplayUtil.getInstance().getStereotypeTextToDisplay((View) getModel()); return stereotypesToDisplay; @@ -199,21 +197,17 @@ public abstract class UMLConnectionNodeEditPart extends ConnectionEditPart imple * @return the image that represents the first applied stereotype or <code>null</code> if no image has to be displayed */ public Image stereotypeIconToDisplay() { - String stereotypespresentationKind = AppliedStereotypeHelper.getAppliedStereotypePresentationKind((View) getModel()); - if (stereotypespresentationKind == null) { - return null; - } - if (stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION) || stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.TEXT_ICON_STEREOTYPE_PRESENTATION)) { - - // retrieve the first stereotype in the list of displayed stereotype - String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay((View) getModel()); - StringTokenizer tokenizer = new StringTokenizer(stereotypesToDisplay, ","); - if (tokenizer.hasMoreTokens()) { - String firstStereotypeName = tokenizer.nextToken(); - Stereotype stereotype = getUMLElement().getAppliedStereotype(firstStereotypeName); - return Activator.getIconElement(getUMLElement(), stereotype, false); - } + + + // retrieve the first stereotype in the list of displayed stereotype + String stereotypesToDisplay = StereotypeDisplayUtil.getInstance().getStereotypeTextToDisplay((View) getModel()); + StringTokenizer tokenizer = new StringTokenizer(stereotypesToDisplay, ","); + if (tokenizer.hasMoreTokens()) { + String firstStereotypeName = tokenizer.nextToken(); + Stereotype stereotype = getUMLElement().getAppliedStereotype(firstStereotypeName); + return Activator.getIconElement(getUMLElement(), stereotype, false); } + return null; } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java index 20fd0beda5e..01d0e109d7c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractAppliedStereotypeDisplayEditPolicy.java @@ -25,7 +25,6 @@ import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand; import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker; import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener; @@ -37,16 +36,16 @@ import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener; import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; -import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe; import org.eclipse.papyrus.uml.diagram.common.Activator; -import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateAppliedStereotypePropertyViewCommand; -import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateAppliedStereotypeViewCommand; -import org.eclipse.papyrus.uml.diagram.common.stereotype.CreateStereotypeLabelCommand; -import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper; -import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.CreateAppliedStereotypeCompartmentCommand; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.CreateAppliedStereotypePropertyViewCommand; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.CreateStereotypeLabelCommand; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil; +import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.StereotypeMigrationHelper; +import org.eclipse.papyrus.uml.diagram.common.util.CommandUtil; import org.eclipse.papyrus.uml.tools.listeners.StereotypeElementListener.StereotypeExtensionNotification; import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Extension; import org.eclipse.uml2.uml.Property; @@ -58,6 +57,8 @@ import org.eclipse.uml2.uml.Stereotype; */ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends GraphicalEditPolicyEx implements NotificationListener, IPapyrusListener { + protected String EMPTY_STRING = "";//$NON-NLS-1$ + /** constant for this edit policy role */ public final static String STEREOTYPE_LABEL_POLICY = "AppliedStereotypeDisplayEditPolicy";//$NON-NLS-1$ @@ -65,7 +66,10 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic protected Element hostSemanticElement; /** Helper to manipulate applied Stereotype Display model */ - protected StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance(); + protected StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance(); + protected StereotypeMigrationHelper migrationHelper = StereotypeMigrationHelper.getInstance(); + + protected IGraphicalEditPart hostEditPart; @@ -96,10 +100,13 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic // Create and Delete nodes if necessary refreshNotationStructure(); + } } + + /** * Initialize Variables. */ @@ -219,7 +226,7 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic */ public Image stereotypeIconToDisplay() { Image icon = null; - boolean displayIcon = NotationUtils.getBooleanValue(hostView, StereotypeDisplayUtils.DISPLAY_ICON, false); + boolean displayIcon = NotationUtils.getBooleanValue(hostView, StereotypeDisplayConstant.DISPLAY_ICON, false); if (displayIcon) { // retrieve the first stereotype in the list of displayed stereotype Stereotype appliedStereotype; @@ -341,31 +348,9 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic * the stereotype application */ protected void executeAppliedStereotypeBraceCompartmentCreation(final IGraphicalEditPart editPart, final Stereotype stereotype) { - try { - editPart.getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - Display.getCurrent().syncExec(new Runnable() { - - @Override - public void run() { - CreateAppliedStereotypeViewCommand command = new CreateAppliedStereotypeViewCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotype, StereotypeDisplayUtils.STEREOTYPE_BRACE_TYPE); - - // use to avoid to put it in the command stack - try { - GMFUnsafe.write(editPart.getEditingDomain(), command); - } catch (Exception e) { - Activator.log.error(e); - } - } - }); + CreateAppliedStereotypeCompartmentCommand command = new CreateAppliedStereotypeCompartmentCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotype, StereotypeDisplayConstant.STEREOTYPE_BRACE_TYPE); + CommandUtil.executeUnsafeCommand(command, editPart); - } - }); - } catch (Exception e) { - Activator.log.error(e); - } } @@ -380,36 +365,11 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic * the stereotype associated to compartment node */ protected void executeAppliedStereotypeBracePropertyViewCreation(final IGraphicalEditPart editPart, final Node compartment, final Property stereotypeProperty) { - try { - editPart.getEditingDomain().runExclusive(new Runnable() { - - @Override - public void run() { - Display.getCurrent().syncExec(new Runnable() { - - @Override - public void run() { - - // use to avoid to put it in the command stack - CreateAppliedStereotypePropertyViewCommand command = new CreateAppliedStereotypePropertyViewCommand(editPart.getEditingDomain(), compartment, stereotypeProperty, StereotypeDisplayUtils.STEREOTYPE_PROPERTY_BRACE_TYPE); - try { - GMFUnsafe.write(editPart.getEditingDomain(), command); - } catch (Exception e) { - Activator.log.error(e); - } - } - }); - } - }); + CreateAppliedStereotypePropertyViewCommand command = new CreateAppliedStereotypePropertyViewCommand(editPart.getEditingDomain(), compartment, stereotypeProperty, StereotypeDisplayConstant.STEREOTYPE_PROPERTY_BRACE_TYPE); + CommandUtil.executeUnsafeCommand(command, editPart); - } catch (Exception e) { - Activator.log.error(e); - } } - - - /** * The goal of this method is to execute the a command to create a notation node for a stereotype Label. * @@ -419,34 +379,11 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic * The stereotype related to the Label */ protected void executeStereotypeLabelCreation(final IGraphicalEditPart editPart, final Stereotype stereotype) { - try { - editPart.getEditingDomain().runExclusive(new Runnable() { - @Override - public void run() { - Display.getCurrent().syncExec(new Runnable() { - - @Override - public void run() { - - CreateStereotypeLabelCommand command = new CreateStereotypeLabelCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotype); - // use to avoid to put it in the command stack - try { - GMFUnsafe.write(editPart.getEditingDomain(), command); - } catch (Exception e) { - Activator.log.error(e); - } - } - }); - - } - }); - } catch (Exception e) { - Activator.log.error(e); - } - } - + CreateStereotypeLabelCommand command = new CreateStereotypeLabelCommand(editPart.getEditingDomain(), editPart.getNotationView(), stereotype); + CommandUtil.executeUnsafeCommand(command, editPart); + } /** * Gets the diagram event broker from the editing domain. @@ -492,24 +429,10 @@ public abstract class AbstractAppliedStereotypeDisplayEditPolicy extends Graphic * DecorationNode of the Stereotype Label that has to be removed */ protected void executeStereotypeViewRemove(final IGraphicalEditPart editPart, final View view) { - try { - TransactionUtil.getEditingDomain(getView()).runExclusive(new Runnable() { - - @Override - public void run() { - DeleteCommand command = new DeleteCommand(view); - // use to avoid to put it in the command stack - try { - GMFUnsafe.write(editPart.getEditingDomain(), command); - } catch (Exception e) { - Activator.log.error(e); - } - } - }); - } catch (Exception e) { - Activator.log.error(e); - } + DeleteCommand command = new DeleteCommand(view); + CommandUtil.executeUnsafeCommand(command, editPart); + } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java index 6b2cc5d4150..5e5931cc0e4 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeExternalNodeEditPolicy.java @@ -19,7 +19,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart; import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusUMLElementFigure; -import org.eclipse.uml2.uml.Stereotype; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant; /** * This edit policy is used to display only applied stereotypes and properties @@ -50,7 +50,7 @@ public class AppliedStereotypeExternalNodeEditPolicy extends AppliedStereotypeLa getDiagramEventBroker().addNotificationListener(parentView, this); } - refreshDisplay(); + } @@ -64,11 +64,26 @@ public class AppliedStereotypeExternalNodeEditPolicy extends AppliedStereotypeLa } /** - * {@inheritDoc} + * Refresh the text of the stereotype */ @Override - public void refreshDisplay() { - refreshStereotypeDisplay(); + protected void refreshStereotypeDisplay() { + IFigure figure; + if (getHost() instanceof IPapyrusEditPart) { + figure = ((IPapyrusEditPart) getHost()).getPrimaryShape(); + } else { + figure = hostEditPart.getFigure(); + } + + if (figure instanceof IPapyrusUMLElementFigure) {// calculate text + // and icon to display + final String stereotypesToDisplay = stereotypesToDisplay(); + ((IPapyrusUMLElementFigure) figure).setStereotypeDisplay(tag + (stereotypesToDisplay), null); + + } + + + } /** @@ -83,48 +98,38 @@ public class AppliedStereotypeExternalNodeEditPolicy extends AppliedStereotypeLa // retrieve all stereotypes to be displayed if (parentView == null) { - return ""; + return EMPTY_STRING; } // try to display stereotype properties - String stereotypesToDisplay = helper.getStereotypeTextToDisplay(parentView); - return stereotypesToDisplay; - } + final String stereotypesToDisplay = helper.getStereotypeTextToDisplay(parentView); + final String stereotypesPropertiesToDisplay = helper.getStereotypePropertiesInBrace(parentView); + String display = getStereotypeAndPropertiesTextToDisplay(stereotypesToDisplay, stereotypesPropertiesToDisplay); - /** - * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AbstractAppliedStereotypeDisplayEditPolicy#refreshStereotypeBraceStructure(org.eclipse.uml2.uml.Stereotype) - * - * @param stereotype - * Stereotype related to the Brace to refresh - */ - @Override - public void refreshStereotypeBraceStructure(Stereotype stereotype) { - // Nothing to Do - } - + return display; + } /** - * Refresh the text of the stereotype + * @param stereotypesToDisplay + * @param stereotypesPropertiesToDisplay + * @param display + * @return */ - @Override - protected void refreshStereotypeDisplay() { - IFigure figure; - if (getHost() instanceof IPapyrusEditPart) { - figure = ((IPapyrusEditPart) getHost()).getPrimaryShape(); - } else { - figure = hostEditPart.getFigure(); + private String getStereotypeAndPropertiesTextToDisplay(final String stereotypesToDisplay, final String stereotypesPropertiesToDisplay) { + StringBuilder display = new StringBuilder(); + if (stereotypesToDisplay != null && !stereotypesToDisplay.isEmpty()) { + display.append(stereotypesToDisplay); } - if (figure instanceof IPapyrusUMLElementFigure) {// calculate text - // and icon to display - final String stereotypesToDisplay = stereotypesToDisplay(); - ((IPapyrusUMLElementFigure) figure).setStereotypeDisplay(tag + (stereotypesToDisplay), null); - + if (stereotypesPropertiesToDisplay != null && !stereotypesPropertiesToDisplay.isEmpty()) { + if (display.length() > 0) { + display.append(StereotypeDisplayConstant.STEREOTYPE_PROPERTY_SEPARATOR); + } + display.append(StereotypeDisplayConstant.BRACE_LEFT + stereotypesPropertiesToDisplay + StereotypeDisplayConstant.BRACE_RIGHT); } - - - + return display.toString(); } + } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java index ad3347eecb0..3e9589353af 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AppliedStereotypeNodeLabelDisplayEditPolicy.java @@ -40,6 +40,8 @@ public class AppliedStereotypeNodeLabelDisplayEditPolicy extends AppliedStereoty super(tag); } + + /** * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.AppliedStereotypeLabelDisplayEditPolicy#refreshStereotypeDisplay() * diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ApplyStereotypeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ApplyStereotypeEditPolicy.java index be14809b29f..02dc2ee65cf 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ApplyStereotypeEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ApplyStereotypeEditPolicy.java @@ -22,9 +22,7 @@ import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand; import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper; import org.eclipse.papyrus.uml.diagram.common.commands.ApplyStereotypeCommand; -import org.eclipse.papyrus.uml.diagram.common.commands.DefferedAppliedStereotypeToDisplayCommand; import org.eclipse.papyrus.uml.diagram.common.service.ApplyStereotypeRequest; import org.eclipse.uml2.uml.Element; @@ -96,9 +94,6 @@ public class ApplyStereotypeEditPolicy extends AbstractEditPolicy { // 1. apply stereotypes cc.compose(new ApplyStereotypeCommand(editingDomain, request)); - // 2. display stereotypes - cc.compose(new EMFtoGMFCommandWrapper(new DefferedAppliedStereotypeToDisplayCommand(editingDomain, getHost(), ""))); - return new ICommandProxy(cc.reduce()); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java index fc08291350a..a831e3e7dda 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java @@ -36,7 +36,7 @@ import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils; import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe; import org.eclipse.papyrus.uml.diagram.common.Activator; import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure; -import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant; import org.eclipse.swt.widgets.Display; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.util.UMLUtil; @@ -61,7 +61,7 @@ public class CommentShapeForAppliedStereotypeEditPolicy extends AbstractAppliedS element = (Element) getView().getElement(); } else { - EObject object = NotationUtils.getEObjectValue(getView(), StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME, null); + EObject object = NotationUtils.getEObjectValue(getView(), StereotypeDisplayConstant.STEREOTYPE_COMMENT_RELATION_NAME, null); if (object != null) { if (object instanceof Element) { element = (Element) object; diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ImportedElementEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ImportedElementEditPolicy.java index 4da1bf58927..aae33301b74 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ImportedElementEditPolicy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ImportedElementEditPolicy.java @@ -15,6 +15,7 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalReferenceEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.helper.SemanticElementHelper;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Comment;
import org.eclipse.uml2.uml.Constraint;
@@ -75,6 +76,10 @@ public class ImportedElementEditPolicy extends ExternalReferenceEditPolicy { }
+ if (StereotypeDisplayUtil.getInstance().isStereotypeView(getView())) {
+ return false;
+ }
+
// Generic case: graphical containment doesn't match the semantic containment (We only check Package containment)
Element semanticUMLElement = (Element) semanticElement;
Element parentUMLElement = (Element) parentSemanticElement;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/CornerBentFigure.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/CornerBentFigure.java index c29a927cae0..ee77139d3d1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/CornerBentFigure.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/figure/node/CornerBentFigure.java @@ -27,7 +27,7 @@ import org.eclipse.draw2d.geometry.Insets; import org.eclipse.gmf.runtime.diagram.ui.figures.NoteFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.IPapyrusNodeFigure; import org.eclipse.papyrus.infra.gmfdiag.common.figure.node.PapyrusWrappingLabel; -import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; @@ -201,7 +201,7 @@ public class CornerBentFigure extends NoteFigure implements IPapyrusNodeUMLEleme // Set stereotype text on figure if (!"".equals(stereotypeProperties)) { - this.stereotypePropertiesInBraceContent.setText(StereotypeDisplayUtils.BRACE_LEFT + stereotypeProperties + StereotypeDisplayUtils.BRACE_RIGHT); + this.stereotypePropertiesInBraceContent.setText(StereotypeDisplayConstant.BRACE_LEFT + stereotypeProperties + StereotypeDisplayConstant.BRACE_RIGHT); } else { this.stereotypePropertiesInBraceContent.setText(""); } diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/StereotypedElementLabelHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/StereotypedElementLabelHelper.java index 3ced407cc8a..07e3817f3a5 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/StereotypedElementLabelHelper.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/StereotypedElementLabelHelper.java @@ -16,6 +16,7 @@ package org.eclipse.papyrus.uml.diagram.common.helper; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -33,8 +34,8 @@ import org.eclipse.papyrus.infra.emf.appearance.helper.AppearanceHelper; import org.eclipse.papyrus.uml.appearance.helper.AppliedStereotypeHelper; import org.eclipse.papyrus.uml.appearance.helper.UMLVisualInformationPapyrusConstant; import org.eclipse.papyrus.uml.diagram.common.Activator; -import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper; -import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil; import org.eclipse.papyrus.uml.tools.utils.UMLUtil; import org.eclipse.swt.graphics.Image; import org.eclipse.uml2.uml.Element; @@ -46,7 +47,9 @@ import org.eclipse.uml2.uml.Stereotype; */ public abstract class StereotypedElementLabelHelper { - private final static String EMPTY_STRING = ""; + private final static String EMPTY_STRING = "";//$NON-NLS-1$ + + private final static String SPACE = " "; //$NON-NLS-1$ /** * {@inheritDoc} @@ -99,12 +102,14 @@ public abstract class StereotypedElementLabelHelper { } if (stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.ICON_STEREOTYPE_PRESENTATION) || stereotypespresentationKind.equals(UMLVisualInformationPapyrusConstant.TEXT_ICON_STEREOTYPE_PRESENTATION)) { // retrieve the first stereotype in the list of displayed stereotype - String stereotypesToDisplay = AppliedStereotypeHelper.getStereotypesToDisplay((View) editPart.getModel()); Collection<Stereotype> stereotypes = new ArrayList<Stereotype>(); - StringTokenizer tokenizer = new StringTokenizer(stereotypesToDisplay, ","); - while (tokenizer.hasMoreTokens()) { - String firstStereotypeName = tokenizer.nextToken(); - stereotypes.add(getUMLElement(editPart).getAppliedStereotype(firstStereotypeName)); + Iterator<Stereotype> appliedStereotypes = getUMLElement(editPart).getAppliedStereotypes().iterator(); + while (appliedStereotypes.hasNext()) { + Stereotype appliedStereotype = appliedStereotypes.next(); + if (editPart.getModel() instanceof View + && StereotypeDisplayUtil.getInstance().getStereotypeLabel(((View) editPart.getModel()), appliedStereotype).isVisible()) { + stereotypes.add(appliedStereotype); + } } return Activator.getIconElements(getUMLElement(editPart), stereotypes, false); } @@ -120,18 +125,18 @@ public abstract class StereotypedElementLabelHelper { View view = (View) editPart.getModel(); // retrieve all stereotypes to be displayed // try to display stereotype properties - String stereotypesToDisplay = StereotypeDisplayHelper.getInstance().getStereotypeTextToDisplay(view); - String stereotypesPropertiesToDisplay = StereotypeDisplayHelper.getInstance().getStereotypePropertiesInBrace(view); + String stereotypesToDisplay = StereotypeDisplayUtil.getInstance().getStereotypeTextToDisplay(view); + String stereotypesPropertiesToDisplay = StereotypeDisplayUtil.getInstance().getStereotypePropertiesInBrace(view); String display = EMPTY_STRING; if (stereotypesToDisplay != null && !stereotypesToDisplay.equals(EMPTY_STRING)) { - display += stereotypesToDisplay + StereotypeDisplayUtils.STEREOTYPE_PROPERTIES_SEPARATOR; + display += stereotypesToDisplay + StereotypeDisplayConstant.STEREOTYPE_PROPERTIES_SEPARATOR; } if (stereotypesPropertiesToDisplay != null && !stereotypesPropertiesToDisplay.equals(EMPTY_STRING)) { - display += StereotypeDisplayUtils.BRACE_LEFT + stereotypesPropertiesToDisplay + StereotypeDisplayUtils.BRACE_RIGHT; + display += StereotypeDisplayConstant.BRACE_LEFT + stereotypesPropertiesToDisplay + StereotypeDisplayConstant.BRACE_RIGHT + SPACE; } return display; diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java index 96a0ae779cf..64b2a87f323 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/StereotypePropertyParser.java @@ -33,7 +33,7 @@ import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; -import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayHelper; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil; import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Property; @@ -148,7 +148,7 @@ public class StereotypePropertyParser implements IParser, ISemanticParser { @Override public String getPrintString(IAdaptable element, int flags) { - StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance(); + StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance(); if (element instanceof IAdaptable) { final Property property = ((Property) (EMFHelper.getEObject(element))); final View view = ((View) element.getAdapter(View.class)); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/stereotype/AppliedStereotypeParser.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/stereotype/AppliedStereotypeParser.java index 75fddc56543..a0705fad10b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/stereotype/AppliedStereotypeParser.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/parser/stereotype/AppliedStereotypeParser.java @@ -13,7 +13,6 @@ *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.parser.stereotype; -import java.text.MessageFormat; import java.util.LinkedList; import java.util.List; @@ -28,14 +27,23 @@ import org.eclipse.gmf.runtime.common.ui.services.parser.ParserEditStatus; import org.eclipse.gmf.runtime.emf.ui.services.parser.ISemanticParser; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; import org.eclipse.papyrus.uml.diagram.common.parser.assist.FixedSetCompletionProcessor; -import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeDisplayUtils; +import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant; import org.eclipse.uml2.uml.Element; import org.eclipse.uml2.uml.Extension; import org.eclipse.uml2.uml.Stereotype; public class AppliedStereotypeParser implements ISemanticParser { - private static final MessageFormat APPLIED_PROFILE = new MessageFormat("\u00AB{0}\u00BB"); //$NON-NLS-1$ + private final String myDefaultPrintString; + + public AppliedStereotypeParser() { + this(null); + } + + public AppliedStereotypeParser(String defaultPrintString) { + myDefaultPrintString = defaultPrintString; + } + @Override public boolean areSemanticElementsAffected(EObject listener, Object notification) { @@ -98,9 +106,9 @@ public class AppliedStereotypeParser implements ISemanticParser { public String getPrintString(IAdaptable element, int flags) { String editString = getEditString(element, flags); if (editString != null && !editString.isEmpty()) { - return StereotypeDisplayUtils.QUOTE_LEFT + editString + StereotypeDisplayUtils.QUOTE_RIGHT; + return StereotypeDisplayConstant.QUOTE_LEFT + editString + StereotypeDisplayConstant.QUOTE_RIGHT; } - return editString; + return myDefaultPrintString; } @Override diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ChangeStereotypeDisplayPostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ChangeStereotypeDisplayPostAction.java index 937ba07dd1f..10a9f35123d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ChangeStereotypeDisplayPostAction.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/ChangeStereotypeDisplayPostAction.java @@ -42,7 +42,11 @@ import org.w3c.dom.Node; /** * Post action that manages the display of applied stereotypes. + * + * @deprecated Use the commands into oep.uml.diagram.common.stereotype.display.command + * */ +@Deprecated public class ChangeStereotypeDisplayPostAction extends GraphicalPostAction { /** list of stereotypes to display with their names */ @@ -139,7 +143,7 @@ public class ChangeStereotypeDisplayPostAction extends GraphicalPostAction { @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - View view = (View) viewAdapter.getAdapter(View.class); + View view = viewAdapter.getAdapter(View.class); if (view != null) { String stereotypetoDisplay = AppliedStereotypeHelper.getStereotypesToDisplay(view); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePostAction.java index 10f43428c7b..763bb715af1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePostAction.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePostAction.java @@ -146,7 +146,7 @@ public class DisplayAppliedStereotypePostAction extends GraphicalPostAction { @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - View view = (View) viewAdapter.getAdapter(View.class); + View view = viewAdapter.getAdapter(View.class); // creates the commands to display simple stereotypes name for (String stereotypeName : stereotypesToDisplay) { diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePropertiesInCompartmentPostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePropertiesInCompartmentPostAction.java index 03d4b3eeeae..9f1b1573d9c 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePropertiesInCompartmentPostAction.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/DisplayAppliedStereotypePropertiesInCompartmentPostAction.java @@ -58,7 +58,11 @@ import org.w3c.dom.NodeList; * <p> * More precisely, it is in charge of the display of properties of Stereotypes in Compartments * </p> + * + * @deprecated Use the commands into oep.uml.diagram.common.stereotype.display.command + * */ +@Deprecated public class DisplayAppliedStereotypePropertiesInCompartmentPostAction extends GraphicalPostAction { /** map of stereotypes / properties to display with their qualified names */ @@ -134,7 +138,7 @@ public class DisplayAppliedStereotypePropertiesInCompartmentPostAction extends G @Override protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - View view = (View) viewAdapter.getAdapter(View.class); + View view = viewAdapter.getAdapter(View.class); String stereotypesStrList = PaletteUtil.convertToCommaSeparatedRepresentation(listOfDisplayableStereotypeProperties); AppliedStereotypeHelper.getAddAppliedStereotypePropertiesCommand(editingDomain, view, stereotypesStrList).execute(); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/StereotypePostAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/StereotypePostAction.java index 7636719a800..af8c27b1b2d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/StereotypePostAction.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/service/palette/StereotypePostAction.java @@ -54,12 +54,10 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerCell; import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.jface.window.Window; -import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper; import org.eclipse.papyrus.infra.core.utils.EditorUtils; import org.eclipse.papyrus.uml.diagram.common.Activator; import org.eclipse.papyrus.uml.diagram.common.Messages; import org.eclipse.papyrus.uml.diagram.common.commands.ApplyStereotypeCommand; -import org.eclipse.papyrus.uml.diagram.common.commands.DefferedAppliedStereotypeToDisplayCommand; import org.eclipse.papyrus.uml.diagram.common.part.PaletteUtil; import org.eclipse.papyrus.uml.diagram.common.service.ApplyStereotypeRequest; import org.eclipse.papyrus.uml.diagram.common.ui.dialogs.PropertyEditors; @@ -220,7 +218,7 @@ public class StereotypePostAction extends ModelPostAction { /** the column for the stereotypes */ private TreeViewerColumn stereotypeColumn = null; - /** the column with the checkboxes for the runtime properties */ + /** the column with the check boxes for the runtime properties */ private TreeViewerColumn runtimeColumn = null; private ArrayList<Value> savedValues; @@ -291,9 +289,6 @@ public class StereotypePostAction extends ModelPostAction { cmd.add(new ApplyStereotypeCommand(editingDomain, request)); - // 2. display stereotypes - cmd.add(new EMFtoGMFCommandWrapper(new DefferedAppliedStereotypeToDisplayCommand(editingDomain, viewAdapter, ""))); - AbstractTransactionalCommand setPropertiesCommand = new AbstractTransactionalCommand(editingDomain, "Set stereotype values", null) { @Override @@ -631,7 +626,7 @@ public class StereotypePostAction extends ModelPostAction { * <ul> * <li> * {@link #createConfigurationComposite(Composite, PaletteEntryProxy, List)}</li> - * <li> {@link #performAddButtonPressed(TreeViewer)} when we add or remove stereotypes</li> + * <li>{@link #performAddButtonPressed(TreeViewer)} when we add or remove stereotypes</li> * </ul> */ protected void updateStereotypeViewer() { @@ -891,10 +886,10 @@ public class StereotypePostAction extends ModelPostAction { * Set the {@link Button#setEnabled(boolean)} parameter to true or false for * the buttons following the selected element in the {@link StereotypePostAction#stereotypeViewer} * <ul> - * <li> {@link StereotypePostAction#addButton}</li> - * <li> {@link StereotypePostAction#removeButton}</li> - * <li> {@link StereotypePostAction#upButton}</li> - * <li> {@link StereotypePostAction#downButton}</li> + * <li>{@link StereotypePostAction#addButton}</li> + * <li>{@link StereotypePostAction#removeButton}</li> + * <li>{@link StereotypePostAction#upButton}</li> + * <li>{@link StereotypePostAction#downButton}</li> * </ul> * * @param event @@ -1085,7 +1080,8 @@ public class StereotypePostAction extends ModelPostAction { * test if all the selected element in the selection are fron the same level * * @param selection - * @return <ul> + * @return + * <ul> * <li>{@code true} if all the element are from the same level in the tree</li> * <li>{@code false if not}</li> * </ul> diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeLocationEnum.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeLocationEnum.java index 31275816342..bbff436f6ac 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeLocationEnum.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeLocationEnum.java @@ -34,13 +34,14 @@ public enum StereotypeLocationEnum { /**
* Defines the Brace Label into a separate Comment Figure that contains the list of Stereotype Properties
+ * {@link Deprecated Not used}
*/
- IN_COMMENT_BRACE,
+ @Deprecated IN_COMMENT_BRACE,
/**
* Defines the Compartment into a separate Comment Figure dedicated to the Stereotype Properties
*/
- IN_COMMENT_COMPARTMENT
+ IN_COMMENT
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/IStereotypeViewFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/IStereotypeViewFactory.java new file mode 100644 index 00000000000..63d53c9061e --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/IStereotypeViewFactory.java @@ -0,0 +1,78 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display;
+
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * This Factory creates the different Stereotype View related to the Location.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public interface IStereotypeViewFactory {
+
+ /**
+ * Create Property View according to a specific Location.
+ *
+ * @param property
+ * The UML property for the View to be created
+ * @param stereotype
+ * The UML Stereotype for which the property is required
+ * @param location
+ * The property location can be:
+ * <ul>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_COMMENT_LOCATION}</li>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_COMPARTMENT_LOCATION}</li>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_BRACE_LOCATION}</li>
+ * </ul>
+ * @param owner
+ * The Compartment View that should contained the Property View
+ */
+ public void createPropertyView(Property property, Stereotype stereotype, View owner, String location);
+
+ /**
+ * Create Compartment View according to a specific Location.
+ *
+ * @param stereotype
+ * The UML Stereotype for which the property is required
+ * @param location
+ * The property location can be:
+ * <ul>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_COMMENT_LOCATION}</li>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_COMPARTMENT_LOCATION}</li>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_BRACE_LOCATION}</li>
+ * </ul>
+ */
+ public void createCompartmentView(Stereotype stereotype, String location);
+
+
+ /**
+ * Create Label View.
+ *
+ * @param stereotype
+ * The UML Stereotype for which the property is required
+ *
+ */
+ public void createLabelView(Stereotype stereotype);
+
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/IStereotypeViewProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/IStereotypeViewProvider.java new file mode 100644 index 00000000000..8d3e740f8c0 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/IStereotypeViewProvider.java @@ -0,0 +1,79 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display;
+
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * This interface provides the View of the Stereotype Structure
+ * If the view doesn't exist it creates the node thanks to the {@link IStereotypeViewFactory } Class.
+ * It should never return null;
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public interface IStereotypeViewProvider {
+
+ /**
+ * Get the Property View for a specific location
+ *
+ * @param property
+ * The UML property for the View to be created
+ * @param stereotype
+ * The UML Stereotype for which the property is required
+ * @param location
+ * The property location can be:
+ * <ul>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_COMMENT_LOCATION}</li>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_COMPARTMENT_LOCATION}</li>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_BRACE_LOCATION}</li>
+ * </ul>
+ * @return The Property view (existing or newly created)
+ */
+ public View getProperty(Property property, Stereotype stereotype, Enum location);
+
+ /**
+ * Get the Compartment View for a specific location
+ *
+ *
+ * @param stereotype
+ * The UML Stereotype for which the property is required
+ * @param location
+ * The property location can be:
+ * <ul>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_COMMENT_LOCATION}</li>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_COMPARTMENT_LOCATION}</li>
+ * <li>{@link StereotypeDisplayConstant#STEREOTYPE_BRACE_LOCATION}</li>
+ * </ul>
+ * @return The Compartment view (existing or newly created)
+ */
+ public View getCompartment(Stereotype stereotype, Enum location);
+
+
+ /**
+ * Get the Label View for a specific location
+ *
+ *
+ * @param stereotype
+ * The UML Stereotype for which the property is required
+ *
+ * @return The Label view (existing or newly created)
+ */
+ public View getLabel(Stereotype stereotype);
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/StereotypeViewFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/StereotypeViewFactory.java new file mode 100644 index 00000000000..5c6df821bca --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/StereotypeViewFactory.java @@ -0,0 +1,207 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.CreateAppliedStereotypeCompartmentCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.CreateAppliedStereotypePropertyViewCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.CreateStereotypeLabelCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.papyrus.uml.diagram.common.util.CommandUtil;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * This Factory implement {@link IStereotypeViewFactory} and is in charge of creating Stereotype Views.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeViewFactory implements IStereotypeViewFactory {
+
+ private View mainView;
+ private TransactionalEditingDomain domain;
+
+ /**
+ * Constructor.
+ *
+ * @param mainView
+ * The View on which the Stereotype is applied (i.e: A Shape, an Edge, An Operation, ...)
+ *
+ */
+ public StereotypeViewFactory(View mainView) {
+ super();
+ this.mainView = mainView;
+ this.domain = CommandUtil.resolveEditingDomain(mainView);
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.display.IStereotypeViewFactory#createPropertyView(org.eclipse.gmf.runtime.notation.View, org.eclipse.uml2.uml.Property, org.eclipse.uml2.uml.Stereotype, org.eclipse.gmf.runtime.notation.View,
+ * java.lang.String)
+ *
+ */
+ @Override
+ public void createPropertyView(Property property, Stereotype stereotype, View owner, String location) {
+
+ if (StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_LOCATION.equals(location)) {
+ createStereotypePropertyInCompartment(owner, property);
+ } else if (StereotypeDisplayConstant.STEREOTYPE_BRACE_LOCATION.equals(location)) {
+ createStereotypePropertyInBrace(owner, property);
+ } else if (StereotypeDisplayConstant.STEREOTYPE_COMMENT_LOCATION.equals(location)) {
+ createStereotypePropertyInComment(owner, property);
+ }
+
+ }
+
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.display.IStereotypeViewFactory#createCompartmentView(org.eclipse.gmf.runtime.notation.View, org.eclipse.uml2.uml.Stereotype, java.lang.String)
+ *
+ */
+ @Override
+ public void createCompartmentView(Stereotype stereotype, String location) {
+ if (StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_LOCATION.equals(location)) {
+ createStereotypeCompartmentInCompartment(stereotype);
+ } else if (StereotypeDisplayConstant.STEREOTYPE_BRACE_LOCATION.equals(location)) {
+ createStereotypeCompartmentInBrace(stereotype);
+ } else if (StereotypeDisplayConstant.STEREOTYPE_COMMENT_LOCATION.equals(location)) {
+ createStereotypeCompartmentInComment(stereotype);
+ }
+
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.display.IStereotypeViewFactory#createLabelView(org.eclipse.gmf.runtime.notation.View, org.eclipse.uml2.uml.Stereotype)
+ */
+ @Override
+ public void createLabelView(Stereotype stereotype) {
+ createStereotypeLabel(stereotype);
+
+ }
+
+
+ /**
+ * Execute the creation Compartment command
+ *
+ * @param stereotype
+ * Stereotype for which the View is created
+ */
+ private void createStereotypeCompartmentInComment(Stereotype stereotype) {
+ View comment = StereotypeDisplayUtil.getInstance().getStereotypeComment(mainView);
+ CreateAppliedStereotypeCompartmentCommand command = new CreateAppliedStereotypeCompartmentCommand(domain, comment, stereotype, StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_TYPE);
+ CommandUtil.executeUnsafeCommand(command, mainView);
+
+ }
+
+
+
+
+
+ /**
+ * Create the Compartment of Stereotype to be shown into the Compartment of the Shape.
+ *
+ * @param stereotype
+ * The Stereotype of the Compartment that is retrieved.
+ */
+ private void createStereotypeCompartmentInBrace(Stereotype stereotype) {
+ CreateAppliedStereotypeCompartmentCommand command = new CreateAppliedStereotypeCompartmentCommand(domain, mainView, stereotype, StereotypeDisplayConstant.STEREOTYPE_BRACE_TYPE);
+ CommandUtil.executeUnsafeCommand(command, mainView);
+
+ }
+
+ /**
+ * Create the Compartment of Stereotype to be shown into the Compartment of the Shape.
+ *
+ * @param stereotype
+ * The Stereotype of the Compartment that is retrieved.
+ */
+ private void createStereotypeCompartmentInCompartment(Stereotype stereotype) {
+ CreateAppliedStereotypeCompartmentCommand command = new CreateAppliedStereotypeCompartmentCommand(domain, mainView, stereotype, StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_TYPE);
+ CommandUtil.executeUnsafeCommand(command, mainView);
+
+ }
+
+ /**
+ * Create the Property of the Stereotype to be shown into the Compartment of the Shape.
+ *
+ *
+ * @param compartment
+ * The Compartment View that is the Owner of the new Property
+ * @param property
+ * The UML Property of the Stereotype to be retrieved.
+ *
+ */
+ private void createStereotypePropertyInCompartment(View compartment, Property property) {
+ CreateAppliedStereotypePropertyViewCommand command = new CreateAppliedStereotypePropertyViewCommand(domain, compartment, property, StereotypeDisplayConstant.STEREOTYPE_PROPERTY_TYPE);
+ CommandUtil.executeUnsafeCommand(command, mainView);
+
+ }
+
+ /**
+ * Create the Property of the Stereotype to be shown into the Brace of the Shape.
+ *
+ *
+ * @param compartment
+ * The Compartment View that is the Owner of the new Property
+ * @param property
+ * The UML Property of the Stereotype to be retrieved.
+ *
+ */
+ private void createStereotypePropertyInBrace(View compartmentView, Property property) {
+ CreateAppliedStereotypePropertyViewCommand command = new CreateAppliedStereotypePropertyViewCommand(domain, mainView, property, StereotypeDisplayConstant.STEREOTYPE_BRACE_TYPE);
+ CommandUtil.executeUnsafeCommand(command, mainView);
+
+ }
+
+ /**
+ * Create the Property of the Stereotype to be shown into the Comment of the Shape.
+ *
+ *
+ * @param compartment
+ * The Compartment View that is the Owner of the new Property
+ * @param property
+ * The UML Property of the Stereotype to be retrieved.
+ *
+ */
+ private void createStereotypePropertyInComment(View compartmentView, Property property) {
+ CreateAppliedStereotypePropertyViewCommand command = new CreateAppliedStereotypePropertyViewCommand(domain, compartmentView, property, StereotypeDisplayConstant.STEREOTYPE_PROPERTY_TYPE);
+ CommandUtil.executeUnsafeCommand(command, mainView);
+
+ }
+
+
+
+ /**
+ * Execute the {@link CreateStereotypeLabelCommand}
+ *
+ * @param view
+ * The view that required a Stereotype Label
+ */
+ private void createStereotypeLabel(final Stereotype stereotype) {
+ CreateStereotypeLabelCommand command = new CreateStereotypeLabelCommand(domain, mainView, stereotype);
+ CommandUtil.executeUnsafeCommand(command, mainView);
+ }
+
+
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/StereotypeViewProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/StereotypeViewProvider.java new file mode 100644 index 00000000000..d374ace68dd --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/StereotypeViewProvider.java @@ -0,0 +1,225 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display;
+
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeLocationEnum;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * This Class Implement the interface {@link IStereotypeViewProvider} to provide Stereotype Views.
+ *
+ * @see IStereotypeViewProvider
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeViewProvider implements IStereotypeViewProvider {
+
+ private View mainView;
+
+ private static StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+
+ /**
+ * Constructor.
+ *
+ * @param mainView
+ * The View on which the Stereotype is applied (i.e: A Shape, an Edge, An Operation, ...)
+ */
+ public StereotypeViewProvider(View mainView) {
+ super();
+ this.mainView = mainView;
+
+ }
+
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.display.IStereotypeViewProvider#getProperty(org.eclipse.uml2.uml.Property, org.eclipse.uml2.uml.Stereotype, java.lang.String)
+ *
+ */
+ @Override
+ public View getProperty(Property property, Stereotype stereotype, Enum location) {
+ View propertyView = null;
+ if (StereotypeLocationEnum.IN_COMPARTMENT.equals(location)) {
+ propertyView = getStereotypePropertyInCompartment(mainView, stereotype, property);
+ } else if (StereotypeLocationEnum.IN_BRACE.equals(location)) {
+ propertyView = getStereotypePropertyInBrace(mainView, stereotype, property);
+ } else if (StereotypeLocationEnum.IN_COMMENT.equals(location)) {
+ propertyView = getStereotypePropertyInComment(mainView, stereotype, property);
+ }
+ return propertyView;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.display.IStereotypeViewProvider#getCompartment(org.eclipse.uml2.uml.Property, org.eclipse.uml2.uml.Stereotype, java.lang.String)
+ *
+ */
+ @Override
+ public View getCompartment(Stereotype stereotype, Enum location) {
+ View compartmentView = null;
+ if (StereotypeLocationEnum.IN_COMPARTMENT.equals(location)) {
+ compartmentView = getStereotypeCompartmentInCompartment(mainView, stereotype);
+ } else if (StereotypeLocationEnum.IN_BRACE.equals(location)) {
+ compartmentView = getStereotypeCompartmentInBrace(mainView, stereotype);
+ } else if (StereotypeLocationEnum.IN_COMMENT.equals(location)) {
+ compartmentView = getStereotypeCompartmentInComment(mainView, stereotype);
+ }
+ return compartmentView;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.display.IStereotypeViewProvider#getLabel(org.eclipse.uml2.uml.Property, org.eclipse.uml2.uml.Stereotype, java.lang.String)
+ *
+ */
+ @Override
+ public View getLabel(Stereotype stereotype) {
+ return getStereotypeLabel(mainView, stereotype);
+
+ }
+
+
+ /**
+ * Retrieve the Stereotype Compartment related to a Stereotype and create it if null.
+ *
+ * @param view
+ * The view on which the Compartment is checked
+ * @param stereotype
+ * The Stereotype of the Compartment that is retrieved.
+ * @return The Compartment related to the Stereotype (existing or newly created)
+ */
+ public View getStereotypeLabel(final View view, final Stereotype stereotype) {
+ View label = helper.getStereotypeLabel(view, stereotype);
+
+ return label;
+ }
+
+
+ /**
+ * Retrieve the Stereotype Compartment View related to a Stereotype in Compartment and create it if null.
+ *
+ * @param view
+ * The view on which the Compartment is checked
+ * @param stereotype
+ * The Stereotype of the Compartment that is retrieved.
+ * @return The Compartment related to the Stereotype (existing or newly created)
+ */
+ public View getStereotypeCompartmentInCompartment(final View view, final Stereotype stereotype) {
+ View compartment = helper.getStereotypeCompartment(view, stereotype);
+
+ return compartment;
+ }
+
+
+ /**
+ * Retrieve the Stereotype Compartment View related to a Stereotype in Brace and create it if null.
+ *
+ * @param view
+ * The view on which the Compartment is checked
+ * @param stereotype
+ * The Stereotype of the Compartment that is retrieved.
+ * @return The Compartment related to the Stereotype (existing or newly created)
+ */
+ public View getStereotypeCompartmentInBrace(final View view, final Stereotype stereotype) {
+ View compartment = helper.getStereotypeBraceCompartment(view, stereotype);
+
+ return compartment;
+ }
+
+
+ /**
+ * Retrieve the Stereotype Compartment View related to a Stereotype in Comment and create it if null.
+ *
+ * @param view
+ * The view on which the Compartment is checked
+ * @param stereotype
+ * The Stereotype of the Compartment that is retrieved.
+ * @return The Compartment related to the Stereotype (existing or newly created)
+ */
+ public View getStereotypeCompartmentInComment(View view, Stereotype stereotype) {
+ View comment = helper.getStereotypeComment(view);
+ View compartment = helper.getStereotypeCompartment(comment, stereotype);
+
+ return compartment;
+ }
+
+ /**
+ * Retrieve the Stereotype Property related to a Stereotype and create it if null.
+ *
+ * @param view
+ * The view on which the Compartment is checked
+ * @param stereotype
+ * The Stereotype of the Compartment that is retrieved.
+ * @param property
+ * The UML Property of the Stereotype to be retrieved.
+ *
+ * @return The Property related with the Stereotype (existing or newly created)
+ */
+ public View getStereotypePropertyInCompartment(final View view, final Stereotype stereotype, final Property property) {
+ View propertyView = helper.getStereotypeProperty(view, stereotype, property);
+
+
+ return propertyView;
+ }
+
+
+ /**
+ * Retrieve the Stereotype Property View related to a Stereotype in Brace and create it if null.
+ *
+ * @param view
+ * The view on which the Compartment is checked
+ * @param stereotype
+ * The Stereotype of the Compartment that is retrieved.
+ * @param property
+ * The UML Property of the Stereotype to be retrieved.
+ *
+ * @return The Property related with the Stereotype (existing or newly created)
+ */
+ public View getStereotypePropertyInBrace(View view, Stereotype stereotype, Property property) {
+
+ View propertyView = helper.getStereotypePropertyInBrace(view, stereotype, property);
+
+ return propertyView;
+
+ }
+
+
+
+ /**
+ * Retrieve the Stereotype Property View related to a Stereotype in Comment and create it if null.
+ *
+ * @param view
+ * The view on which the Compartment is checked
+ * @param stereotype
+ * The Stereotype of the Compartment that is retrieved.
+ * @param property
+ * The UML Property of the Stereotype to be retrieved.
+ *
+ * @return The Property related with the Stereotype (existing or newly created)
+ */
+ public View getStereotypePropertyInComment(View view, Stereotype stereotype, Property property) {
+
+ View propertyView = helper.getStereotypePropertyInComment(view, stereotype, property);
+
+ return propertyView;
+
+ }
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/AddAppliedQNStereotypeToDisplayCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/AddAppliedQNStereotypeToDisplayCommand.java new file mode 100644 index 00000000000..62fad89c3bd --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/AddAppliedQNStereotypeToDisplayCommand.java @@ -0,0 +1,70 @@ +/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayCommandExecution;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * The Class AddQNAppliedStereotypeToDisplayCommand used to set the list of applied stereotype to
+ * display with the qualifiedName.
+ */
+public class AddAppliedQNStereotypeToDisplayCommand extends RecordingCommand {
+
+
+ private Stereotype stereotype;
+
+ private View view;
+ private TransactionalEditingDomain domain;
+ private String depth;
+
+ private static StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+ private static StereotypeDisplayCommandExecution commandHelper = StereotypeDisplayCommandExecution.getInstance();
+
+
+ /**
+ * Instantiates a new sets the applied stereotype to display command.
+ *
+ * @param domain
+ * the domain
+ * @param object
+ * the object
+ * @param stereotypeList
+ * the stereotype list
+ */
+ public AddAppliedQNStereotypeToDisplayCommand(final TransactionalEditingDomain domain, final View view,
+ final Stereotype stereotype, final String depth) {
+ super(domain, "Display Stereotype with Qualified Name");
+ this.depth = depth;
+ this.domain = domain;
+ this.view = view;
+ this.stereotype = stereotype;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doExecute() {
+ View label = helper.getStereotypeLabel(view, stereotype);
+ commandHelper.setUserDepth(domain, stereotype, label, "full");
+
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/AddAppliedStereotypePropertiesToDisplayCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/AddAppliedStereotypePropertiesToDisplayCommand.java new file mode 100644 index 00000000000..32b5f9a2788 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/AddAppliedStereotypePropertiesToDisplayCommand.java @@ -0,0 +1,85 @@ +/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeLocationEnum;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayCommandExecution;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * The Class AddAppliedStereotypeToDisplayCommand used to set the list of applied stereotype to
+ * display
+ */
+public class AddAppliedStereotypePropertiesToDisplayCommand extends RecordingCommand {
+
+
+ private Property property;
+ private Stereotype stereotype;
+ private View view;
+ private TransactionalEditingDomain domain;
+ private String location;
+
+ private static StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+ private static StereotypeDisplayCommandExecution commandHelper = StereotypeDisplayCommandExecution.getInstance();
+
+
+
+ /**
+ * add a new sets the applied stereotype properties to display command.
+ *
+ * @param domain
+ * the domain
+ * @param object
+ * the object
+ * @param stereotypeList
+ * the stereotype list
+ */
+ public AddAppliedStereotypePropertiesToDisplayCommand(TransactionalEditingDomain domain, View view,
+ Property property, Stereotype stereotype, String location) {
+ super(domain, "Display a Stereotype Property");
+ this.property = property;
+ this.stereotype = stereotype;
+ this.domain = domain;
+ this.view = view;
+ this.location = location;
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doExecute() {
+ View propertyView = null;
+ if (StereotypeLocationEnum.IN_COMPARTMENT.equals(location)) {
+ propertyView = helper.getStereotypeProperty(view, stereotype, property);
+ } else if (StereotypeLocationEnum.IN_BRACE.equals(location)) {
+ propertyView = helper.getStereotypePropertyInBrace(view, stereotype, property);
+ } else if (StereotypeLocationEnum.IN_COMMENT.equals(location)) {
+ propertyView = helper.getStereotypePropertyInComment(view, stereotype, property);
+ }
+
+ commandHelper.setUserVisibility(domain, propertyView, true);
+
+
+ }
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/AddAppliedStereotypeToDisplayCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/AddAppliedStereotypeToDisplayCommand.java new file mode 100644 index 00000000000..8a0ddd21b7e --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/AddAppliedStereotypeToDisplayCommand.java @@ -0,0 +1,71 @@ +/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayCommandExecution;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+
+/**
+ * The Class AddAppliedStereotypeToDisplayCommand used to set the list of applied stereotype to
+ * display
+ */
+public class AddAppliedStereotypeToDisplayCommand extends RecordingCommand {
+
+ /** The qualified name. */
+ private String stereotypeName;
+
+ private View view;
+ private TransactionalEditingDomain domain;
+
+ private static StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+ private static StereotypeDisplayCommandExecution commandHelper = StereotypeDisplayCommandExecution.getInstance();
+
+
+
+ /**
+ * Instantiates a new sets the applied stereotype to display command.
+ *
+ * @param domain
+ * the domain
+ * @param object
+ * the object
+ * @param stereotypeList
+ * the stereotype list
+ */
+ public AddAppliedStereotypeToDisplayCommand(final TransactionalEditingDomain domain, final View view,
+ final String stereotypeName) {
+ super(domain, "Display Stereotype Label");
+ this.stereotypeName = stereotypeName;
+ this.domain = domain;
+ this.view = view;
+
+
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doExecute() {
+ View label = helper.getStereotypeLabel(view, stereotypeName);
+ commandHelper.setUserVisibility(domain, label, true);
+
+
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/CreateAppliedStereotypeCommentViewCommand.java index f39c8d7fe79..54170b04132 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeCommentViewCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/CreateAppliedStereotypeCommentViewCommand.java @@ -12,7 +12,7 @@ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 460356 : Refactor Stereotype Display
*
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.stereotype;
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
import java.util.ArrayList;
@@ -34,6 +34,7 @@ import org.eclipse.gmf.runtime.notation.RelativeBendpoints; import org.eclipse.gmf.runtime.notation.TitleStyle;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
/**
* the goal of this command is to create a comment in the notation that represent a compartment of stereotypes
@@ -82,13 +83,13 @@ public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand ts.setShowTitle(true);
node.getStyles().add(ts);
node.setElement(null);
- node.setType(StereotypeDisplayUtils.STEREOTYPE_COMMENT_TYPE);
+ node.setType(StereotypeDisplayConstant.STEREOTYPE_COMMENT_TYPE);
connectCommentNode(owner, node);
EObjectValueStyle eObjectValueStyle = (EObjectValueStyle) node.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle());
eObjectValueStyle.setEObjectValue(base_element);
- eObjectValueStyle.setName(StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME);
+ eObjectValueStyle.setName(StereotypeDisplayConstant.STEREOTYPE_COMMENT_RELATION_NAME);
// create the link
Connector edge = NotationFactory.eINSTANCE.createConnector();
@@ -100,7 +101,7 @@ public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand bendpoints.setPoints(points);
edge.setBendpoints(bendpoints);
ViewUtil.insertChildView(owner.getDiagram(), edge, -1, true);
- edge.setType(StereotypeDisplayUtils.STEREOTYPE_COMMENT_LINK_TYPE);
+ edge.setType(StereotypeDisplayConstant.STEREOTYPE_COMMENT_LINK_TYPE);
edge.setElement(base_element);
IdentityAnchor anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
edge.setSourceAnchor(anchor);
@@ -111,7 +112,7 @@ public class CreateAppliedStereotypeCommentViewCommand extends RecordingCommand edge.setElement(null);
eObjectValueStyle = (EObjectValueStyle) edge.createStyle(NotationPackage.eINSTANCE.getEObjectValueStyle());
eObjectValueStyle.setEObjectValue(base_element);
- eObjectValueStyle.setName(StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME);
+ eObjectValueStyle.setName(StereotypeDisplayConstant.STEREOTYPE_COMMENT_RELATION_NAME);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/CreateAppliedStereotypeCompartmentCommand.java index 64764162f3e..ca8c41b6947 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypeViewCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/CreateAppliedStereotypeCompartmentCommand.java @@ -11,7 +11,7 @@ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
*
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.stereotype;
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
@@ -21,15 +21,17 @@ import org.eclipse.gmf.runtime.notation.NotationFactory; import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.TitleStyle;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
import org.eclipse.uml2.uml.Stereotype;
/**
* the goal of this command is to create a basic compartment in the notation that represent a compartment of stereotypes
*
*/
-public class CreateAppliedStereotypeViewCommand extends RecordingCommand {
+public class CreateAppliedStereotypeCompartmentCommand extends RecordingCommand {
- protected StereotypeDisplayHelper helper = StereotypeDisplayHelper.getInstance();
+ protected StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
protected View node;
@@ -49,7 +51,7 @@ public class CreateAppliedStereotypeViewCommand extends RecordingCommand { * @param StereotypeApplication
* @param displayit
*/
- public CreateAppliedStereotypeViewCommand(TransactionalEditingDomain domain, View node, Stereotype stereotype, String type) {
+ public CreateAppliedStereotypeCompartmentCommand(TransactionalEditingDomain domain, View node, Stereotype stereotype, String type) {
super(domain, "CreateStereotypeCompartment");
this.node = node;
this.stereotype = stereotype;
@@ -74,14 +76,14 @@ public class CreateAppliedStereotypeViewCommand extends RecordingCommand { // Create Stereotype Name Style
StringValueStyle stereotypeNameStyle = NotationFactory.eINSTANCE.createStringValueStyle();
- stereotypeNameStyle.setName(StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME);
+ stereotypeNameStyle.setName(StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_NAME);
stereotypeNameStyle.setStringValue(stereotype.getQualifiedName());
compartment.getStyles().add(stereotypeNameStyle);
// Complete the creation
compartment.setElement(stereotype);
compartment.setType(type);
- ViewUtil.insertChildView(node, compartment, ViewUtil.APPEND, StereotypeDisplayUtils.PERSISTENT);
+ ViewUtil.insertChildView(node, compartment, ViewUtil.APPEND, StereotypeDisplayConstant.PERSISTENT);
compartment.setMutable(true);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypePropertyViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/CreateAppliedStereotypePropertyViewCommand.java index 6826511702f..c109a891b98 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateAppliedStereotypePropertyViewCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/CreateAppliedStereotypePropertyViewCommand.java @@ -12,7 +12,7 @@ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotypes Display
*
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.stereotype;
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.RecordingCommand;
@@ -21,6 +21,7 @@ import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
@@ -61,7 +62,7 @@ public class CreateAppliedStereotypePropertyViewCommand extends RecordingCommand propertyLabel.setElement(property);
// Add the new Label to it's owner Object
- ViewUtil.insertChildView(owner, propertyLabel, ViewUtil.APPEND, StereotypeDisplayUtils.PERSISTENT);
+ ViewUtil.insertChildView(owner, propertyLabel, ViewUtil.APPEND, StereotypeDisplayConstant.PERSISTENT);
propertyLabel.setMutable(true);
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateStereotypeLabelCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/CreateStereotypeLabelCommand.java index 912498db127..36b35c3c3b3 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/CreateStereotypeLabelCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/CreateStereotypeLabelCommand.java @@ -12,7 +12,7 @@ *
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.stereotype;
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
@@ -21,6 +21,7 @@ import org.eclipse.gmf.runtime.notation.DecorationNode; import org.eclipse.gmf.runtime.notation.NotationFactory;
import org.eclipse.gmf.runtime.notation.StringValueStyle;
import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Stereotype;
@@ -71,18 +72,18 @@ public class CreateStereotypeLabelCommand extends RecordingCommand { // Create Label
DecorationNode label = NotationFactory.eINSTANCE.createDecorationNode();
- label.setType(StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE);
+ label.setType(StereotypeDisplayConstant.STEREOTYPE_LABEL_TYPE);
label.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
label.setElement(stereotype);
// Create Stereotype Name Style
StringValueStyle stereotypeNameStyle = NotationFactory.eINSTANCE.createStringValueStyle();
- stereotypeNameStyle.setName(StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME);
+ stereotypeNameStyle.setName(StereotypeDisplayConstant.STEREOTYPE_LABEL_NAME);
stereotypeNameStyle.setStringValue(stereotype.getQualifiedName());
label.getStyles().add(stereotypeNameStyle);
// Add the new Label to it's owner Object
- ViewUtil.insertChildView(owner, label, ViewUtil.APPEND, StereotypeDisplayUtils.PERSISTENT);
+ ViewUtil.insertChildView(owner, label, ViewUtil.APPEND, StereotypeDisplayConstant.PERSISTENT);
label.setMutable(true);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/RemoveAppliedStereotypePropertiesToDisplayCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/RemoveAppliedStereotypePropertiesToDisplayCommand.java new file mode 100644 index 00000000000..941dd7baf5d --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/RemoveAppliedStereotypePropertiesToDisplayCommand.java @@ -0,0 +1,78 @@ +/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeLocationEnum;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayCommandExecution;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * The Class RemoveAppliedStereotypeToDisplayCommand used to set the list of applied stereotype to
+ * display
+ */
+public class RemoveAppliedStereotypePropertiesToDisplayCommand extends RecordingCommand {
+
+
+ private View view;
+ private TransactionalEditingDomain domain;
+ private Stereotype stereotype;
+ private Property property;
+ private String location;
+
+ private static StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+ private static StereotypeDisplayCommandExecution commandHelper = StereotypeDisplayCommandExecution.getInstance();
+
+ /**
+ * Instantiates a new sets the applied stereotype to display command.
+ *
+ * @param domain
+ * the domain
+ * @param object
+ * the object
+ * @param stereotypePropertyList
+ * the stereotype list
+ */
+ public RemoveAppliedStereotypePropertiesToDisplayCommand(TransactionalEditingDomain domain, View view,
+ final Property property, final Stereotype stereotype, final String location) {
+ super(domain, "Hide a Stereotype Property");
+ this.property = property;
+ this.stereotype = stereotype;
+ this.domain = domain;
+ this.view = view;
+ this.location = location;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doExecute() {
+ View propertyView = null;
+ if (StereotypeLocationEnum.IN_COMPARTMENT.equals(location)) {
+ propertyView = helper.getStereotypeProperty(view, stereotype, property);
+ } else if (StereotypeLocationEnum.IN_BRACE.equals(location)) {
+ propertyView = helper.getStereotypePropertyInBrace(view, stereotype, property);
+ } else if (StereotypeLocationEnum.IN_COMMENT.equals(location)) {
+ propertyView = helper.getStereotypePropertyInComment(view, stereotype, property);
+ }
+
+ commandHelper.setUserVisibility(domain, propertyView, false);
+
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/RemoveAppliedStereotypeToDisplayCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/RemoveAppliedStereotypeToDisplayCommand.java new file mode 100644 index 00000000000..1b54a707f73 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/RemoveAppliedStereotypeToDisplayCommand.java @@ -0,0 +1,67 @@ +/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayCommandExecution;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * The Class RemoveAppliedStereotypeToDisplayCommand used to set the list of applied stereotype to
+ * display
+ */
+public class RemoveAppliedStereotypeToDisplayCommand extends RecordingCommand {
+
+
+ private View view;
+ private TransactionalEditingDomain domain;
+ private Stereotype stereotype;
+
+ private static StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+ private static StereotypeDisplayCommandExecution commandHelper = StereotypeDisplayCommandExecution.getInstance();
+
+
+
+
+ /**
+ * Instantiates a new sets the applied stereotype to display command.
+ *
+ * @param domain
+ * the domain
+ * @param object
+ * the object
+ * @param stereotypeList
+ * the stereotype list
+ */
+
+ public RemoveAppliedStereotypeToDisplayCommand(TransactionalEditingDomain domain, View view,
+ Stereotype stereotype) {
+ super(domain, "Hide Stereotype Label");
+ this.domain = domain;
+ this.view = view;
+ this.stereotype = stereotype;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doExecute() {
+ View label = helper.getStereotypeLabel(view, stereotype);
+ commandHelper.setUserVisibility(domain, label, false);
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/SetPersistentViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/SetPersistentViewCommand.java index 54aff428314..4b0237b8262 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/SetPersistentViewCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/SetPersistentViewCommand.java @@ -12,10 +12,11 @@ *
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.stereotype;
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.View;
/**
@@ -71,8 +72,12 @@ public class SetPersistentViewCommand extends RecordingCommand { // Make the Parent Persistent
makeViewPersistant((View) view.eContainer());
// Move the view from the Transient List to the Persistent Children list
- ((View) view.eContainer()).getPersistedChildren().add(view);
- ((View) view.eContainer()).getTransientChildren().remove(view);
+ if (!(view instanceof Edge)) {
+ ((View) view.eContainer()).getPersistedChildren().add(view);
+ ((View) view.eContainer()).getTransientChildren().remove(view);
+ }
+
+
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/UnsetPersistentViewCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/UnsetPersistentViewCommand.java index 4826f332a26..7648cf62cad 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/UnsetPersistentViewCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/command/UnsetPersistentViewCommand.java @@ -12,7 +12,7 @@ *
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.stereotype;
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.command;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeDisplayCommandExecution.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeDisplayCommandExecution.java new file mode 100644 index 00000000000..1150fd687ee --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeDisplayCommandExecution.java @@ -0,0 +1,228 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.SetNodeVisibilityCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStyleValueCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.SetPersistentViewCommand;
+import org.eclipse.papyrus.uml.diagram.common.util.CommandUtil;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * This Class regroups the Commands and their execution for the Stereotype Display
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public final class StereotypeDisplayCommandExecution {
+ /**
+ * singleton instance
+ */
+ private static StereotypeDisplayCommandExecution labelHelper;
+ private StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+
+ /** Singleton contructor */
+ private StereotypeDisplayCommandExecution() {
+ }
+
+ /**
+ * Returns the singleton instance of this class
+ *
+ * @return the singleton instance.
+ */
+ public static StereotypeDisplayCommandExecution getInstance() {
+ if (labelHelper == null) {
+ labelHelper = new StereotypeDisplayCommandExecution();
+ }
+ return labelHelper;
+ }
+
+ /**
+ * Set the visibility of a view
+ *
+ * @param view
+ * The view on which the visibility has to be set
+ * @param isVisible
+ * True to make the Compartment visible
+ */
+ public void setVisibility(final TransactionalEditingDomain domain, final View view, final boolean isVisible, final boolean inCommandStack) {
+
+
+ if (!inCommandStack) {
+ class SetVisibilityRunnable implements Runnable {
+
+ private boolean visible;
+
+ /**
+ * Constructor.
+ *
+ */
+ public SetVisibilityRunnable(boolean visible) {
+ this.visible = visible;
+ }
+
+ /**
+ * @see java.lang.Runnable#run()
+ *
+ */
+ @Override
+ public void run() {
+ if (view.isVisible() != visible) {
+ view.setVisible(visible);
+ }
+ }
+
+ }
+ CommandUtil.executeUnsafeCommand(new SetVisibilityRunnable(isVisible), domain);
+ } else {
+ SetNodeVisibilityCommand visibility = new SetNodeVisibilityCommand(domain, view, isVisible);
+ CommandUtil.executeCommandInStack(visibility, domain);
+ }
+ }
+
+
+ /**
+ * Set the visibility of a view
+ *
+ * @param view
+ * The view on which the visibility has to be set
+ * @param isVisible
+ * True to make the Compartment visible
+ */
+ public void setPersistency(final TransactionalEditingDomain domain, final View view, boolean inCommandStack) {
+
+
+ if (!inCommandStack) {
+
+ class SetPersistencyRunnable implements Runnable {
+
+ /**
+ * @see java.lang.Runnable#run()
+ *
+ */
+ @Override
+ public void run() {
+ makeViewPersistant(view);
+ }
+
+ }
+ CommandUtil.executeUnsafeCommand(new SetPersistencyRunnable(), domain);
+ } else {
+ SetPersistentViewCommand persitence = new SetPersistentViewCommand(domain, view);
+ CommandUtil.executeCommandInStack(persitence, domain);
+ }
+
+ }
+
+ /**
+ * @param eContainer
+ */
+ public void makeViewPersistant(View view) {
+ if (view != null) {
+ if (view.eContainer() != null && view.eContainer() instanceof View) {
+
+ // Make the Parent Persistent
+ makeViewPersistant((View) view.eContainer());
+ // Move the view from the Transient List to the Persistent Children list
+ if (!(view instanceof Edge)) {
+ ((View) view.eContainer()).getPersistedChildren().add(view);
+ ((View) view.eContainer()).getTransientChildren().remove(view);
+ }
+
+ }
+ }
+
+ }
+
+ /**
+ * Set the depth Name of the Stereotype Label.
+ * It uses the NamedStyle to store the depth into a View.
+ *
+ * @param stereotype
+ * The Stereotype of the Label that should be modified.
+ * @param nodeView
+ * The view of the element that needs to be updated (i.e. The Class)
+ * @param depth
+ * The Depth value as a string (Can be "none", "full" or a negative number )
+ */
+ public void setDepth(final TransactionalEditingDomain domain, final Stereotype stereotype, final View nodeView, final String depth, final boolean inCommandStack) {
+ final View label = helper.getStereotypeLabel(nodeView, stereotype);
+
+ Command command = new CustomStyleValueCommand(label, depth, NotationPackage.eINSTANCE.getStringValueStyle(), NotationPackage.eINSTANCE.getStringValueStyle_StringValue(), StereotypeDisplayConstant.STEREOTYPE_LABEL_DEPTH);
+
+ if (inCommandStack) {
+
+
+ CommandUtil.executeCommandInStack(command, domain);
+ } else {
+ CommandUtil.executeUnsafeCommand(command, domain);
+ }
+
+ }
+
+ /**
+ * This Method is called when the user ask explicitly to display a View.
+ * Then the node is first set as Persistence and the command is put in the command Stack
+ * before to set the Visibility as wanted.
+ *
+ * @param domain
+ * The Transactional Domain
+ * @param view
+ * The View to make visible
+ * @param visible
+ * True if the View has to be visible, false if the Node should be hidden
+ *
+ */
+ public void setUserVisibility(TransactionalEditingDomain domain, View view, boolean visible) {
+ if (view != null && domain != null) {
+
+ SetPersistentViewCommand persitence = new SetPersistentViewCommand(domain, view);
+ CommandUtil.executeCommandInStack(persitence, domain);
+ SetNodeVisibilityCommand visibility = new SetNodeVisibilityCommand(domain, view, visible);
+ CommandUtil.executeCommandInStack(visibility, domain);
+
+ }
+ }
+
+
+ /**
+ * This Method is called when the user ask explicitly to display a View.
+ * Then the node is first set as Persistence and the command is put in the command Stack
+ * before to set the Visibility as wanted.
+ *
+ * @param domain
+ * The Transactional Domain
+ * @param view
+ * The View to make visible
+ * @param visible
+ * True if the View has to be visible, false if the Node should be hidden
+ *
+ */
+ public void setUserDepth(TransactionalEditingDomain domain, Stereotype stereotype, View view, String depth) {
+
+ if (view != null && depth != null && !depth.isEmpty()) {
+ setPersistency(domain, view, true);
+ setDepth(domain, stereotype, view, depth, true);
+ }
+ }
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayUtils.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeDisplayConstant.java index 3e20303ecef..b03aa885035 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayUtils.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeDisplayConstant.java @@ -12,7 +12,7 @@ *
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.stereotype;
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper;
import org.eclipse.papyrus.uml.diagram.common.Activator;
@@ -24,7 +24,7 @@ import org.eclipse.papyrus.uml.diagram.common.Activator; * @author Celine JANSSENS
*
*/
-public class StereotypeDisplayUtils {
+public class StereotypeDisplayConstant {
// Depth Separator of the Stereotype Name
public static final String STEREOTYPE_LABEL_DEPTH_SEPARATOR = "::";//$NON-NLS-1$
@@ -78,6 +78,26 @@ public class StereotypeDisplayUtils { // Icon NamedStyle Property
public static final String DISPLAY_ICON = "displayIcon";// $NON-NLS-1$
- public static final String STEREOTYPE_PROPERTY_LOCATION = "stereotypePropertyLocation";//$NON-NLS-1$
+ // NamedStyle Name for Property Location
+ public static final String STEREOTYPE_PROPERTY_LOCATION = "StereotypePropertyLocation";//$NON-NLS-1$
+
+ // NamedStyle Name for Label Alignment
+ public static final String STEREOTYPE_LABEL_ALIGNMENT = "stereotypeAlignment";//$NON-NLS-1$
+
+ /**
+ * String represent the location of stereotype properties within a comment
+ */
+ public static final String STEREOTYPE_COMMENT_LOCATION = "Comment";//$NON-NLS-1$
+
+ /**
+ * String represent the location of stereotype properties within a compartment of a graph node
+ */
+ public static final String STEREOTYPE_COMPARTMENT_LOCATION = "Compartment";//$NON-NLS-1$
+
+ /**
+ * properties of applied stereotypes are enclose in braces
+ */
+ public static final String STEREOTYPE_BRACE_LOCATION = "With brace";//$NON-NLS-1$
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeDisplayUtil.java index fb40719a199..9e3c0af4d21 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/StereotypeDisplayHelper.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeDisplayUtil.java @@ -12,12 +12,11 @@ *
*****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.stereotype;
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper;
import java.util.Iterator;
import java.util.StringTokenizer;
-import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
@@ -25,14 +24,12 @@ import org.eclipse.gmf.runtime.notation.BasicCompartment; import org.eclipse.gmf.runtime.notation.DecorationNode;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.Shape;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.SetNodeVisibilityCommand;
-import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStyleValueCommand;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe;
import org.eclipse.papyrus.uml.diagram.common.Activator;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.UnsetPersistentViewCommand;
import org.eclipse.papyrus.uml.tools.utils.StereotypeUtil;
import org.eclipse.swt.widgets.Display;
import org.eclipse.uml2.uml.Element;
@@ -47,17 +44,17 @@ import org.eclipse.uml2.uml.util.UMLUtil; * @author Celine JANSSENS
*
*/
-public class StereotypeDisplayHelper {
+public class StereotypeDisplayUtil {
private static final String EMPTY_STRING = ""; // $NON-NLS-1$
/**
* singleton instance
*/
- private static StereotypeDisplayHelper labelHelper;
+ private static StereotypeDisplayUtil labelHelper;
/** Singleton contructor */
- private StereotypeDisplayHelper() {
+ private StereotypeDisplayUtil() {
}
/**
@@ -65,9 +62,9 @@ public class StereotypeDisplayHelper { *
* @return the singleton instance.
*/
- public static StereotypeDisplayHelper getInstance() {
+ public static StereotypeDisplayUtil getInstance() {
if (labelHelper == null) {
- labelHelper = new StereotypeDisplayHelper();
+ labelHelper = new StereotypeDisplayUtil();
}
return labelHelper;
}
@@ -101,18 +98,18 @@ public class StereotypeDisplayHelper { /**
* Get the Semantic Element of the Comment View.
* The Comment View is not attached to its semantic element through the method {@link View#getElement()}.
- * To retrieve the semantic element, it has been added as a namedStyle with the name {@link StereotypeDisplayUtils#STEREOTYPE_COMMENT_RELATION_NAME}
+ * To retrieve the semantic element, it has been added as a namedStyle with the name {@link StereotypeDisplayConstant#STEREOTYPE_COMMENT_RELATION_NAME}
*
* @param view
* The Stereotype Comment View (of type "StereotypeComment")
* @return The Base Element of the Comment
*/
- protected Element getCommentSemanticElement(View view) {
+ public Element getCommentSemanticElement(View view) {
Element elementSemantic = null;
if (isStereotypeComment(view)) {
// Retrieve the Base Element of the Comment as the Semantic element
- EObject baseElement = NotationUtils.getEObjectValue(view, StereotypeDisplayUtils.STEREOTYPE_COMMENT_RELATION_NAME, null);
+ EObject baseElement = NotationUtils.getEObjectValue(view, StereotypeDisplayConstant.STEREOTYPE_COMMENT_RELATION_NAME, null);
if (baseElement instanceof Element) {
elementSemantic = (Element) baseElement;
@@ -183,7 +180,7 @@ public class StereotypeDisplayHelper { if (isStereotypeLabel(object)) {
if (((View) object).isVisible()) {
if (!EMPTY_STRING.equals(textToDisplay.toString()) && (textToDisplay != null)) {
- textToDisplay.append(StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
+ textToDisplay.append(StereotypeDisplayConstant.STEREOTYPE_LABEL_SEPARATOR);
}
textToDisplay.append(getStereotypeName((DecorationNode) object));
}
@@ -193,7 +190,7 @@ public class StereotypeDisplayHelper { // Then add the ornament around the text.
if ((textToDisplay.toString() != null) && (!EMPTY_STRING.equals(textToDisplay.toString()))) {
- finalText.append(StereotypeDisplayUtils.QUOTE_LEFT).append(textToDisplay).append(StereotypeDisplayUtils.QUOTE_RIGHT);
+ finalText.append(StereotypeDisplayConstant.QUOTE_LEFT).append(textToDisplay).append(StereotypeDisplayConstant.QUOTE_RIGHT);
}
// Return the text or null if empty
@@ -236,7 +233,7 @@ public class StereotypeDisplayHelper { *
* @return The String with the new StereotypeName and
*/
- protected String getStereotypeName(DecorationNode label) {
+ public String getStereotypeName(DecorationNode label) {
// Retrieve Name and Depth from CSS or NamedStyle
@@ -263,11 +260,11 @@ public class StereotypeDisplayHelper { protected String getStereotypeNameWithDepth(String qualifiedName, String depth) {
if (depth != null && !EMPTY_STRING.equals(depth)) {
- if (StereotypeDisplayUtils.DEPTH_MIN.equals(depth)) {
+ if (StereotypeDisplayConstant.DEPTH_MIN.equals(depth)) {
return getMinimumDepthName(qualifiedName);
- } else if (StereotypeDisplayUtils.DEPTH_MAX.equals(depth)) {
+ } else if (StereotypeDisplayConstant.DEPTH_MAX.equals(depth)) {
return qualifiedName;
- } else if (StereotypeDisplayUtils.DEPTH_AUTO.equals(depth)) {
+ } else if (StereotypeDisplayConstant.DEPTH_AUTO.equals(depth)) {
// TODO to be computed
return qualifiedName;
} else {
@@ -311,8 +308,8 @@ public class StereotypeDisplayHelper { StringBuffer name = new StringBuffer(qualifiedName);
try {
for (int i = 0; i > depthRetrieve; i--) {
- int index = name.indexOf(StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
- name = name.delete(0, index + StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR.length());
+ int index = name.indexOf(StereotypeDisplayConstant.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
+ name = name.delete(0, index + StereotypeDisplayConstant.STEREOTYPE_LABEL_DEPTH_SEPARATOR.length());
}
} catch (IndexOutOfBoundsException e) {
@@ -331,8 +328,8 @@ public class StereotypeDisplayHelper { public String getMinimumDepthName(String qualifiedName) {
String segment = EMPTY_STRING;
StringBuffer name = new StringBuffer(qualifiedName);
- int index = name.lastIndexOf(StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
- segment = name.substring(index + StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR.length());
+ int index = name.lastIndexOf(StereotypeDisplayConstant.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
+ segment = name.substring(index + StereotypeDisplayConstant.STEREOTYPE_LABEL_DEPTH_SEPARATOR.length());
return segment;
}
@@ -345,7 +342,7 @@ public class StereotypeDisplayHelper { */
protected int getMaxDepth(String qualifiedName) {
- StringTokenizer tok = new StringTokenizer(qualifiedName, StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
+ StringTokenizer tok = new StringTokenizer(qualifiedName, StereotypeDisplayConstant.STEREOTYPE_LABEL_DEPTH_SEPARATOR);
return tok.countTokens();
}
@@ -368,7 +365,7 @@ public class StereotypeDisplayHelper { obj = iter.next();
if (obj instanceof DecorationNode) {
DecorationNode label = (DecorationNode) obj;
- if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
+ if (StereotypeDisplayConstant.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
if (qualifiedName.equals(getName(label))) {
return label;
}
@@ -381,7 +378,7 @@ public class StereotypeDisplayHelper { }
/**
- * Return the associated DecorationNode of a node from it's qualified name.
+ * Return the associated Property view of a node from the property name.
*
* @param node
* Container Node of the StereotypeLabel
@@ -409,6 +406,66 @@ public class StereotypeDisplayHelper { return propertyView;
}
+ /**
+ * Return the associated Property view of a node from the property name.
+ *
+ * @param node
+ * Container Node of the StereotypeLabel
+ * @param qualifiedName
+ * Qualified Name of the Stereotype associated to this Label
+ * @return associated StereotypeLabel
+ */
+ public DecorationNode getStereotypePropertyInBrace(View node, Stereotype stereotype, Property property) {
+ DecorationNode propertyView = null;
+ if ((stereotype != null) && (property != null)) {
+ View compartment = getStereotypeBraceCompartment(node, stereotype);
+ Object obj;
+ if (compartment != null) {
+ Iterator<?> iter = compartment.getChildren().iterator();
+ while (iter.hasNext()) {
+ obj = iter.next();
+ if (isStereotypeBraceProperty(obj) && ((DecorationNode) obj).getElement().equals(property)) {
+ propertyView = (DecorationNode) obj;
+ }
+
+ }
+ }
+ }
+
+ return propertyView;
+ }
+
+ /**
+ * Return the associated Property view of a node from the property name.
+ *
+ * @param node
+ * Container Node of the StereotypeLabel
+ * @param qualifiedName
+ * Qualified Name of the Stereotype associated to this Label
+ * @return associated StereotypeLabel
+ */
+ public DecorationNode getStereotypePropertyInComment(View mainView, Stereotype stereotype, Property property) {
+ View node = getStereotypeComment(mainView);
+ DecorationNode propertyView = null;
+
+ if ((stereotype != null) && (property != null)) {
+ View compartment = getStereotypeCompartment(node, stereotype);
+ Object obj;
+ if (compartment != null) {
+ Iterator<?> iter = compartment.getChildren().iterator();
+ while (iter.hasNext()) {
+ obj = iter.next();
+ if (isStereotypeProperty(obj) && ((DecorationNode) obj).getElement().equals(property)) {
+ propertyView = (DecorationNode) obj;
+ }
+
+ }
+ }
+ }
+
+ return propertyView;
+ }
+
/**
@@ -483,7 +540,7 @@ public class StereotypeDisplayHelper { Edge appliedStereotypeLink = null;
while (edgeIterator.hasNext() && appliedStereotypeLink == null) {
Edge edge = edgeIterator.next();
- if (edge.getType().equals(StereotypeDisplayUtils.STEREOTYPE_COMMENT_LINK_TYPE)) {
+ if (edge.getType().equals(StereotypeDisplayConstant.STEREOTYPE_COMMENT_LINK_TYPE)) {
appliedStereotypeLink = edge;
}
}
@@ -507,7 +564,7 @@ public class StereotypeDisplayHelper { public boolean isStereotypeLabel(Object element) {
boolean stereotypeLabel = Boolean.FALSE;
if (element instanceof DecorationNode) {
- stereotypeLabel = StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(((DecorationNode) element).getType());
+ stereotypeLabel = StereotypeDisplayConstant.STEREOTYPE_LABEL_TYPE.equals(((DecorationNode) element).getType());
}
return stereotypeLabel;
@@ -523,7 +580,7 @@ public class StereotypeDisplayHelper { public boolean isStereotypeCompartment(Object element) {
boolean stereotypeCompartment = Boolean.FALSE;
if (element instanceof BasicCompartment) {
- stereotypeCompartment = StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_TYPE.equals(((DecorationNode) element).getType());
+ stereotypeCompartment = StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_TYPE.equals(((DecorationNode) element).getType());
}
return stereotypeCompartment;
}
@@ -538,7 +595,7 @@ public class StereotypeDisplayHelper { public boolean isStereotypeProperty(Object element) {
boolean stereotypeProperty = Boolean.FALSE;
if (element instanceof DecorationNode) {
- stereotypeProperty = StereotypeDisplayUtils.STEREOTYPE_PROPERTY_TYPE.equals(((DecorationNode) element).getType());
+ stereotypeProperty = StereotypeDisplayConstant.STEREOTYPE_PROPERTY_TYPE.equals(((DecorationNode) element).getType());
}
return stereotypeProperty;
@@ -555,7 +612,7 @@ public class StereotypeDisplayHelper { public boolean isStereotypeBrace(Object element) {
boolean stereotypeBraceCmpt = Boolean.FALSE;
if (element instanceof BasicCompartment) {
- stereotypeBraceCmpt = StereotypeDisplayUtils.STEREOTYPE_BRACE_TYPE.equals(((BasicCompartment) element).getType());
+ stereotypeBraceCmpt = StereotypeDisplayConstant.STEREOTYPE_BRACE_TYPE.equals(((BasicCompartment) element).getType());
}
return stereotypeBraceCmpt;
@@ -572,7 +629,7 @@ public class StereotypeDisplayHelper { public boolean isStereotypeBraceProperty(Object element) {
boolean stereotypeProperty = Boolean.FALSE;
if (element instanceof DecorationNode) {
- stereotypeProperty = StereotypeDisplayUtils.STEREOTYPE_PROPERTY_BRACE_TYPE.equals(((DecorationNode) element).getType());
+ stereotypeProperty = StereotypeDisplayConstant.STEREOTYPE_PROPERTY_BRACE_TYPE.equals(((DecorationNode) element).getType());
}
return stereotypeProperty;
}
@@ -590,7 +647,7 @@ public class StereotypeDisplayHelper { public boolean isStereotypeComment(Object element) {
boolean stereotypeComment = Boolean.FALSE;
if (element instanceof Shape) {
- stereotypeComment = StereotypeDisplayUtils.STEREOTYPE_COMMENT_TYPE.equals(((Shape) element).getType());
+ stereotypeComment = StereotypeDisplayConstant.STEREOTYPE_COMMENT_TYPE.equals(((Shape) element).getType());
}
return stereotypeComment;
}
@@ -612,7 +669,7 @@ public class StereotypeDisplayHelper { }
if (isStereotypeLabel(label)) {
// Retrieve Name from CSS or NamedStyle from the Notation model.
- name = NotationUtils.getStringValue(label, StereotypeDisplayUtils.STEREOTYPE_LABEL_NAME, defaultName);
+ name = NotationUtils.getStringValue(label, StereotypeDisplayConstant.STEREOTYPE_LABEL_NAME, defaultName);
}
return name;
}
@@ -632,7 +689,7 @@ public class StereotypeDisplayHelper { }
if (isStereotypeCompartment(compartment) || isStereotypeBrace(compartment)) {
// Retrieve Name from CSS or NamedStyle from the Notation model.
- name = NotationUtils.getStringValue(compartment, StereotypeDisplayUtils.STEREOTYPE_COMPARTMENT_NAME, defaultName);
+ name = NotationUtils.getStringValue(compartment, StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_NAME, defaultName);
}
return name;
}
@@ -647,9 +704,9 @@ public class StereotypeDisplayHelper { */
public String getDepth(DecorationNode label) {
String depth = EMPTY_STRING;
- if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
+ if (label != null && StereotypeDisplayConstant.STEREOTYPE_LABEL_TYPE.equals(label.getType())) {
// Retrieve Depth from CSS or NamedStyle from the Notation model.
- depth = NotationUtils.getStringValue(label, StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH, StereotypeDisplayUtils.DEFAULT_DEPTH_VALUE);
+ depth = NotationUtils.getStringValue(label, StereotypeDisplayConstant.STEREOTYPE_LABEL_DEPTH, StereotypeDisplayConstant.DEFAULT_DEPTH_VALUE);
}
return depth;
@@ -675,7 +732,7 @@ public class StereotypeDisplayHelper { DecorationNode stereo = (DecorationNode) obj;
- if (StereotypeDisplayUtils.STEREOTYPE_LABEL_TYPE.equals(stereo.getType())) {
+ if (StereotypeDisplayConstant.STEREOTYPE_LABEL_TYPE.equals(stereo.getType())) {
exist = stereo.getElement().equals(stereotype);
}
}
@@ -736,76 +793,6 @@ public class StereotypeDisplayHelper { }
- /**
- * Set the visibility of a view
- *
- * @param view
- * The view on which the visibility has to be set
- * @param isVisible
- * True to make the Compartment visible
- */
- public void setVisibility(final TransactionalEditingDomain domain, final View view, final boolean isVisible) {
- try {
-
- domain.runExclusive(new Runnable() {
-
- @Override
- public void run() {
-
- SetNodeVisibilityCommand setCommand = new SetNodeVisibilityCommand(domain, view, isVisible);
-
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(domain, setCommand);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- });
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
-
-
- /**
- * Set the visibility of a view
- *
- * @param view
- * The view on which the visibility has to be set
- * @param isVisible
- * True to make the Compartment visible
- */
- public void setPersistency(final TransactionalEditingDomain domain, final View view) {
- try {
- domain.runExclusive(new Runnable() {
-
-
- @Override
- public void run() {
- Display.getCurrent().syncExec(new Runnable() {
-
-
- @Override
- public void run() {
-
- // use to avoid to put it in the command stack
- SetPersistentViewCommand command = new SetPersistentViewCommand(domain, view);
- try {
- GMFUnsafe.write(domain, command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- });
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
-
/**
@@ -830,7 +817,7 @@ public class StereotypeDisplayHelper { // if (node.isVisible()) {
if (stereotype != null && property != null && umlElement != null) {
- propertyAndValue = StereotypeUtil.displayPropertyValue(stereotype, property, umlElement, StereotypeDisplayUtils.STEREOTYPE_PROPERTIES_SEPARATOR);
+ propertyAndValue = StereotypeUtil.displayPropertyValue(stereotype, property, umlElement, StereotypeDisplayConstant.STEREOTYPE_PROPERTIES_SEPARATOR);
}
}
@@ -902,13 +889,13 @@ public class StereotypeDisplayHelper { String propAndValueText = getStereotypePropertyToDisplay(propertyNode, propertyElement);
// add it to the String (i.e: "allocatedTo=[], allocatedFrom=[]")
- propertiesText = addTextWithSeparator(propertiesText, propAndValueText, StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
+ propertiesText = addTextWithSeparator(propertiesText, propAndValueText, StereotypeDisplayConstant.STEREOTYPE_LABEL_SEPARATOR);
}
}
}
// And concatenate it to the existing text.(i.e: "isEncapsulated=false, allocatedTo=[], allocatedFrom=[]" )
- newTextToDisplay = addTextWithSeparator(newTextToDisplay, propertiesText.toString(), StereotypeDisplayUtils.STEREOTYPE_LABEL_SEPARATOR);
+ newTextToDisplay = addTextWithSeparator(newTextToDisplay, propertiesText.toString(), StereotypeDisplayConstant.STEREOTYPE_LABEL_SEPARATOR);
String finalText = newTextToDisplay.toString();
return finalText;
@@ -979,6 +966,28 @@ public class StereotypeDisplayHelper { }
+ /**
+ * Defines if the Node has at least one Stereotype View as Child
+ *
+ * @param view
+ * The node on which we do the test
+ * @return true if at least one Stereotype Compartment, Brace or Label
+ */
+ public boolean hasStereotypeViews(View view) {
+
+ Iterator<?> iter = view.getChildren().iterator();
+ boolean compartmentExist = false;
+ while (iter.hasNext() && !compartmentExist) {
+
+ Object obj = iter.next();
+ compartmentExist = isStereotypeCompartment(obj)
+ || isStereotypeBrace(obj)
+ || isStereotypeLabel(obj);
+
+ }
+ return compartmentExist;
+ }
+
/**
* Defines if a Stereotype Comment Node has at least a brace or a compartment
@@ -1032,7 +1041,14 @@ public class StereotypeDisplayHelper { * Defines if an object is a Stereotype View
*
* @param element
- * @return
+ * the Object on which the test is done
+ * @return true if object is one of the following:
+ * <ul>
+ * <li>Stereotype Compartment</li>
+ * <li>Stereotype Brace</li>
+ * <li>Stereotype Label</li>
+ * <li>Stereotype Property</li>
+ * </ul>
*/
public boolean isStereotypeView(Object element) {
@@ -1149,41 +1165,6 @@ public class StereotypeDisplayHelper { return visibleProperties;
}
- /**
- * Set the depth Name of the Stereotype Label.
- * It uses the NamedStyle to store the depth into a View.
- *
- * @param stereotype
- * The Stereotype of the Label that should be modified.
- * @param nodeView
- * The view of the element that needs to be updated (i.e. The Class)
- * @param depth
- * The Depth value as a string (Can be "none", "full" or a negative number )
- */
- public void setDepth(final TransactionalEditingDomain domain, final Stereotype stereotype, final View nodeView, final String depth) {
- final View label = getStereotypeLabel(nodeView, stereotype);
- try {
-
- domain.runExclusive(new Runnable() {
-
- @Override
- public void run() {
- Command command = new CustomStyleValueCommand(label, depth, NotationPackage.eINSTANCE.getStringValueStyle(), NotationPackage.eINSTANCE.getStringValueStyle_StringValue(), StereotypeDisplayUtils.STEREOTYPE_LABEL_DEPTH);
-
- // use to avoid to put it in the command stack
- try {
- GMFUnsafe.write(domain, command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
- });
- } catch (Exception e) {
- Activator.log.error(e);
- }
-
-
- }
/**
* @param domain
@@ -1230,11 +1211,57 @@ public class StereotypeDisplayHelper { public boolean isStereotypeCommentLink(Object element) {
boolean stereotypeCommentLink = Boolean.FALSE;
if (element instanceof Edge) {
- stereotypeCommentLink = StereotypeDisplayUtils.STEREOTYPE_COMMENT_LINK_TYPE.equals(((Edge) element).getType());
+ stereotypeCommentLink = StereotypeDisplayConstant.STEREOTYPE_COMMENT_LINK_TYPE.equals(((Edge) element).getType());
}
return stereotypeCommentLink;
}
+ /**
+ * Get the semantic element from a view.
+ * In case of a view into a Stereotype Comment, return the semantic element of Base Element
+ *
+ * @param view
+ * The view of which the Semantic element is retrieved
+ * @return the semantic element
+ */
+ public Element getSemanticElement(View view) {
+ if (isStereotypeComment(view)) {
+ return getCommentSemanticElement(view);
+ } else {
+ if (view.getElement() instanceof Element) {
+ return (Element) view.getElement();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Concatenate Label and Property in Brace for the floating Stereotype Label.
+ *
+ * @param view
+ * The Main view of the object on which the stereotype is applied
+ * @return String with Stereotype Label and Properties in Braces
+ */
+ public String getStereotypeTextForFloatingLabel(View view) {
+ StringBuilder text = new StringBuilder();
+
+ String label = getStereotypeTextToDisplay(view);
+ String brace = getStereotypePropertiesInBrace(view);
+
+ if (label != null && !label.isEmpty()) {
+ text.append(label);
+
+ }
+
+
+ if (brace != null && !brace.isEmpty()) {
+ text.append(StereotypeDisplayConstant.STEREOTYPE_PROPERTY_SEPARATOR).append(StereotypeDisplayConstant.BRACE_LEFT + brace + StereotypeDisplayConstant.BRACE_RIGHT);
+ }
+
+
+ return text.toString();
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeUserActionHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeUserActionHelper.java new file mode 100644 index 00000000000..96504c9bdc4 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/display/helper/StereotypeUserActionHelper.java @@ -0,0 +1,123 @@ +/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.AddAppliedQNStereotypeToDisplayCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.AddAppliedStereotypePropertiesToDisplayCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.AddAppliedStereotypeToDisplayCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.RemoveAppliedStereotypePropertiesToDisplayCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.command.RemoveAppliedStereotypeToDisplayCommand;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * The Class AppliedStereotypeHelper.
+ * Helper used in the User interaction to display Stereotypes from the Property View.
+ * Note: this class is to be used instead of <i>AppliedStereotypeHelper</i> which is deprecated)
+ */
+public class StereotypeUserActionHelper {
+
+
+
+ /**
+ * add new applied stereotypes to display with the qualified name.
+ *
+ * @param domain
+ * the transactionnal edit domain
+ * @param view
+ * the emodel element that is the display of the uml element
+ * @param appliedStereotypeList
+ * the list of stereotype with qualified name to display
+ *
+ * @return the command to display it
+ */
+ public static RecordingCommand getAddAppliedStereotypeToDisplayWithQNCommand(TransactionalEditingDomain domain, View view, Stereotype stereotype, String depth) {
+ return new AddAppliedQNStereotypeToDisplayCommand(domain, view, stereotype, depth);
+ }
+
+ /**
+ * Gets the adds the applied stereotype command.
+ *
+ * @param domain
+ * the domain
+ * @param view
+ * the view
+ * @param appliedStereotypeListToAdd
+ * the applied stereotype list to add
+ * @param presentationKind
+ * the presentation kind
+ *
+ * @return the adds the applied stereotype command
+ */
+ public static RecordingCommand getAddAppliedStereotypeCommand(TransactionalEditingDomain domain, View view, String stereotypeName) {
+ return new AddAppliedStereotypeToDisplayCommand(domain, view, stereotypeName);
+ }
+
+ /**
+ * Gets the adds the applied stereotype propertiescommand.
+ *
+ * @param domain
+ * the domain
+ * @param view
+ * the view
+ * @param appliedStereotypeListToAdd
+ * the applied stereotype properties list to add
+ *
+ * @return the adds the applied stereotype command
+ */
+ public static RecordingCommand getAddAppliedStereotypePropertiesCommand(TransactionalEditingDomain domain, View view, Stereotype stereotype, Property property, String location) {
+ return new AddAppliedStereotypePropertiesToDisplayCommand(domain, view, property, stereotype, location);
+ }
+
+ /**
+ * Gets the removes the applied stereotype command.
+ *
+ * @param domain
+ * the domain
+ * @param view
+ * the view
+ * @param appliedStereotypeListToRemove
+ * the applied stereotype list to remove
+ * @param presentationKind
+ * the presentation kind
+ *
+ * @return the removes the applied stereotype command
+ */
+ public static RecordingCommand getRemoveAppliedStereotypeCommand(TransactionalEditingDomain domain, View view, Stereotype stereotype) {
+ return new RemoveAppliedStereotypeToDisplayCommand(domain, view, stereotype);
+ }
+
+ /**
+ * Gets the remove applied stereotype properties command.
+ *
+ * @param domain
+ * the domain
+ * @param view
+ * the view
+ * @param appliedStereotypeListToRemove
+ * the applied stereotype list to remove
+ *
+ * @return the removes the applied stereotype properties command
+ */
+ public static RecordingCommand getRemoveAppliedStereotypePropertiesCommand(TransactionalEditingDomain domain, View view, Property property, Stereotype stereotype, String location) {
+ return new RemoveAppliedStereotypePropertiesToDisplayCommand(domain, view, property, stereotype, location);
+ }
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/StereotypeDisplayMigrationConstant.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/StereotypeDisplayMigrationConstant.java new file mode 100644 index 00000000000..f7c40fc46d9 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/StereotypeDisplayMigrationConstant.java @@ -0,0 +1,61 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration;
+
+/**
+ * This class regroups all the constant required for the Migration of the Stereotype Display User Preferences.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public final class StereotypeDisplayMigrationConstant {
+ /**
+ * Stereotype EAnnotation (Old Structure to migrate to the new one)
+ */
+ public static final String STEREOTYPE_ANNOTATION = "Stereotype_Annotation";//$NON-NLS-1$
+ /**
+ * the list of stereotype to display
+ */
+ public static final String STEREOTYPE_LIST = "StereotypeList";//$NON-NLS-1$
+
+ /**
+ * the list of stereotype to display
+ */
+ public static final String STEREOTYPE_WITHQN_LIST = "StereotypeWithQualifiedNameList";//$NON-NLS-1$
+
+ /**
+ * Property location Key
+ */
+ public static final String STEREOTYPE_PROPERTY_LOCATION = "StereotypePropertyLocation";//$NON-NLS-1$
+
+ /**
+ * Property display Key
+ *
+ */
+ public static final String PROPERTY_STEREOTYPE_DISPLAY = "PropStereoDisplay";//$NON-NLS-1$
+
+ /**
+ * the kind of presentation for stereotype
+ */
+ public static final String STEREOTYPE_PRESENTATION_KIND = "Stereotype_Presentation_Kind";//$NON-NLS-1$
+
+ /**
+ * Old Type of Views
+ */
+ public static final String OLD_COMMENT_TYPE = "AppliedStereotypesComment";//$NON-NLS-1$
+ public static final Object OLD_COMMENT_LINK_TYPE = "AppliedStereotypesCommentLink";//$NON-NLS-1$
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/StereotypeMigrationHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/StereotypeMigrationHelper.java new file mode 100644 index 00000000000..a0516ed6c64 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/StereotypeMigrationHelper.java @@ -0,0 +1,416 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.EMap;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EModelElement;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayCommandExecution;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.papyrus.uml.diagram.common.util.CommandUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * This class regroups the methods required to create the new Stereotype Structure based on the Old Structure.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public final class StereotypeMigrationHelper {
+
+
+ public static final String EMPTY_STRING = "";//$NON-NLS-1$
+
+ /**
+ * singleton instance
+ */
+ private static StereotypeMigrationHelper migrationHelper;
+
+ /** Other Helper */
+ private static StereotypeDisplayCommandExecution commandHelper = StereotypeDisplayCommandExecution.getInstance();
+ private static StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+
+ /** Singleton constructor */
+ private StereotypeMigrationHelper() {
+ }
+
+ /**
+ * Returns the singleton instance of this class
+ *
+ * @return the singleton instance.
+ */
+ public static StereotypeMigrationHelper getInstance() {
+ if (migrationHelper == null) {
+ migrationHelper = new StereotypeMigrationHelper();
+ }
+ return migrationHelper;
+ }
+
+
+ /**
+ * Get the Semantic Element of the Comment View.
+ * The Comment View is not attached to its semantic element through the method {@link View#getElement()}.
+ * To retrieve the semantic element, it has been added as a namedStyle with the name {@link StereotypeDisplayConstant#STEREOTYPE_COMMENT_RELATION_NAME}
+ *
+ * @param view
+ * The Stereotype Comment View (of type "StereotypeComment")
+ * @return The Base Element of the Comment
+ */
+ public Element getOldCommentSemanticElement(View view) {
+
+ Element elementSemantic = null;
+ if (isOldComment(view)) {
+ // Retrieve the Base Element of the Comment as the Semantic element
+ EObject baseElement = NotationUtils.getEObjectValue(view, StereotypeDisplayConstant.STEREOTYPE_COMMENT_RELATION_NAME, null);
+
+ if (baseElement instanceof Element) {
+ elementSemantic = (Element) baseElement;
+
+ }
+ }
+ return elementSemantic;
+ }
+
+
+
+ /**
+ * Get a Stereotype from its StereotypeName
+ *
+ * @param view
+ * View on which we try to retrieve the Stereotype
+ * @param stereotypeName
+ * Stereotype Name
+ * @return Stereotype Associated to the stereotype Name for the View.
+ */
+ public Stereotype getStereotypeFromString(View view, String stereotypeName) {
+
+ Stereotype stereotype = null;
+
+ Element element = helper.getSemanticElement(view);
+ stereotype = element.getAppliedStereotype(stereotypeName);
+
+ return stereotype;
+ }
+
+ /**
+ * Get a Property from its Name and its Stereotype
+ *
+ * @param view
+ * The View Containing the Property Compartment (i.e : ClassImpl)
+ * @param propertyName
+ * The Property Name
+ * @return The Property related to the View and to the Stereotype.
+ */
+ public Property getPropertyFromString(View view, Stereotype stereotype, String propertyName) {
+ Property property = null;
+ if (view != null && !propertyName.isEmpty()) {
+
+ Iterator<Property> propertyIterator = stereotype.getAttributes().iterator();
+ while (propertyIterator.hasNext() && property == null) {
+ Property propertyTest = propertyIterator.next();
+ if (propertyTest.getName().equals(propertyName)) {
+ property = propertyTest;
+ }
+ }
+ }
+
+ return property;
+ }
+
+
+
+ /**
+ * Check is the node is persistent and make it persistent if not
+ * Check if the visibility should be modified, and do it accordingly
+ *
+ * @param view
+ * The View to modify
+ * @param diagram
+ * The Diagram that is migrated
+ * @param visible
+ * true if the view has to be visible.
+ */
+ public void updateVisibilityAndPersistence(View view, EObject object, boolean visible) {
+ if (view != null) {
+ if (view.eContainer() instanceof View && !((View) view.eContainer()).getPersistedChildren().contains(view)) {
+ commandHelper.setPersistency(migrationHelper.getDomain(object), view, false);
+ }
+
+ if (visible != view.isVisible()) {
+ commandHelper.setVisibility(migrationHelper.getDomain(object), view, visible, false);
+ }
+ }
+
+
+ }
+
+ /**
+ * Get the Editing domain from Eobject
+ *
+ * @param object
+ * Object used to retrieve the Transactional Editing Domain
+ * @see {@link CommandUtil#resolveEditingDomain(Object)}
+ *
+ * @return Transactional Domain
+ */
+ public TransactionalEditingDomain getDomain(EObject object) {
+ return CommandUtil.resolveEditingDomain(object);
+ }
+
+ /**
+ * Get the EAnnotation, dedicated to the Stereotype Display User preferences (Old structure to be replaced by the new one)
+ *
+ * @param view
+ * The View of which the EAnnotation is necessary.
+ * @return The EAnnotation of the view . Null if does not exist.
+ */
+ public EAnnotation getStereotypeEAnnotation(EModelElement view) {
+ EAnnotation annotation = null;
+ if (view != null) {
+ annotation = view.getEAnnotation(StereotypeDisplayMigrationConstant.STEREOTYPE_ANNOTATION);
+ }
+ return annotation;
+
+ }
+
+ /**
+ *
+ * Define if a view has an Stereotype EAnnotation
+ *
+ * @param content
+ * The view
+ * @return true if the Stereotype is not null.
+ */
+ public boolean hasStereotypeEAnnotation(View content) {
+
+ return getStereotypeEAnnotation(content) != null;
+ }
+
+ /**
+ * Retrieve the list of the appliedStereotypes from a View
+ *
+ * @param view
+ * The view for which the List of Stereotypes is asked
+ * @return The appliedStereotype List. Null if no UML element related to the View.
+ */
+ public EList<Stereotype> getAppliedStereotypesFromView(View view) {
+ EList<Stereotype> list = null;
+
+ Element element = helper.getSemanticElement(view);
+ list = element.getAppliedStereotypes();
+
+ return list;
+ }
+
+
+ /* ******************* Old EAnnotation Method *************************/
+
+ /**
+ * get lhe list of stereotype to display with the qulifiedName.
+ *
+ * @param view
+ * the view of the uml element
+ *
+ * @return the list of applied stereotype to display with their qualified name
+ */
+ public String getStereotypesQNToDisplay(EModelElement view) {
+ EAnnotation eannotation = getStereotypeEAnnotation(view);
+ if (eannotation != null) {
+ EMap<String, String> entries = eannotation.getDetails();
+
+ String stereotypesToDisplay = entries.get(StereotypeDisplayMigrationConstant.STEREOTYPE_WITHQN_LIST);
+ if (stereotypesToDisplay != null) {
+ return stereotypesToDisplay;
+ }
+ }
+ return EMPTY_STRING;
+ }
+
+ /**
+ * get the list of stereotype to display from the eannotation.
+ *
+ * @param view
+ * the view
+ *
+ * @return the list of stereotypes to display separated by a comma. the applied stereotype to
+ * display is represented by the qualified name of the stereotype
+ * Empty String by default.
+ */
+ public String getStereotypesToDisplay(EModelElement view) {
+ EAnnotation eannotation = getStereotypeEAnnotation(view);
+ if (eannotation != null) {
+ EMap<String, String> entries = eannotation.getDetails();
+
+ String stereotypesToDisplay = entries.get(StereotypeDisplayMigrationConstant.STEREOTYPE_LIST);
+ if (stereotypesToDisplay != null) {
+ return stereotypesToDisplay;
+ }
+ }
+ return EMPTY_STRING;
+ }
+
+ /**
+ * Gets the applied stereotypes properties localization.
+ *
+ * @param view
+ * the view
+ *
+ * @return the applied stereotypes properties localization
+ */
+ public String getAppliedStereotypesPropertiesLocalization(EModelElement view) {
+ EAnnotation eannotation = getStereotypeEAnnotation(view);
+ if (eannotation != null) {
+ EMap<String, String> entries = eannotation.getDetails();
+
+ String displayLocalization = entries.get(StereotypeDisplayConstant.STEREOTYPE_PROPERTY_LOCATION);
+ if (displayLocalization != null && !displayLocalization.equals(StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_LOCATION)) {
+ return displayLocalization;
+ }
+ }
+
+
+ return StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_LOCATION;
+ }
+
+
+ /**
+ * Gets the applied stereotypes properties to display.
+ *
+ * @param view
+ * the view the view that displays the stereotyped element
+ *
+ * @return the applied stereotypes properties to display
+ */
+ public String getAppliedStereotypesPropertiesToDisplay(EModelElement view) {
+ EAnnotation eannotation = getStereotypeEAnnotation(view);
+ if (eannotation != null) {
+ EMap<String, String> entries = eannotation.getDetails();
+
+ String stereotypesToDisplay = entries.get(StereotypeDisplayMigrationConstant.PROPERTY_STEREOTYPE_DISPLAY);
+ if (stereotypesToDisplay != null) {
+ return stereotypesToDisplay;
+ }
+ }
+ return EMPTY_STRING;
+ }
+
+ /**
+ * Define if the passed object is the Old Comment View
+ *
+ * @param object
+ * The object to be tested
+ * @return true if the object is a view of type {@link StereotypeDisplayMigrationConstant#OLD_COMMENT_TYPE}
+ */
+ public boolean isOldComment(Object object) {
+
+ if (object instanceof View) {
+ View view = (View) object;
+ return (view.getType().equals(StereotypeDisplayMigrationConstant.OLD_COMMENT_TYPE));
+
+ }
+
+ return false;
+ }
+
+
+
+ /**
+ * Retrieve the old Comment from a hostView
+ *
+ * @param hostView
+ * The view of which the old comment is retrieve
+ * @return The OldComment View or Null if not found.
+ */
+ public View getOldStereotypeComment(View semanticView) {
+ Node node = null;
+ if (semanticView != null && semanticView.getSourceEdges() != null) {
+ // look for all links with the id AppliedStereotypesCommentLinkEditPart.ID
+ Iterator<Edge> edgeIterator = semanticView.getSourceEdges().iterator();
+ Edge appliedStereotypeLink = null;
+ while (edgeIterator.hasNext() && appliedStereotypeLink == null) {
+ Edge edge = edgeIterator.next();
+ if (edge.getType().equals(StereotypeDisplayMigrationConstant.OLD_COMMENT_LINK_TYPE)) {
+ appliedStereotypeLink = edge;
+ }
+ }
+ if (appliedStereotypeLink == null) {
+ return null;
+ }
+ node = (Node) appliedStereotypeLink.getTarget();
+ }
+ return node;
+ }
+
+ /**
+ * Retrieve the Old Link of the HostView
+ *
+ * @param hostView
+ * The view of which the old link is retrieve
+ * @return The Old Link View or Null if not found.
+ */
+ public Edge getOldStereotypeLinkComment(View semanticView) {
+ Edge appliedStereotypeLink = null;
+ if (semanticView != null && semanticView.getSourceEdges() != null) {
+ // look for all links with the id AppliedStereotypesCommentLinkEditPart.ID
+ Iterator<Edge> edgeIterator = semanticView.getSourceEdges().iterator();
+
+ while (edgeIterator.hasNext() && appliedStereotypeLink == null) {
+ Edge edge = edgeIterator.next();
+ if (edge.getType().equals(StereotypeDisplayMigrationConstant.OLD_COMMENT_LINK_TYPE)) {
+ appliedStereotypeLink = edge;
+ }
+ }
+ }
+ return appliedStereotypeLink;
+ }
+
+ /**
+ * Define if an Old Comment is Orphan
+ *
+ * @param view
+ * The View of the Old Comment
+ * @return True if the Comment is not related to another Element or if no stereotype is applied to this Element.
+ */
+ public boolean isOrphanComment(View view) {
+ boolean orphanComment = false;
+
+ if (isOldComment(view)) {
+ // if no stereotypes applied on the Base element, the comment is considered as Orphan
+ Element element = getOldCommentSemanticElement(view);
+ if (element == null || element.getAppliedStereotypes().size() == 0) {
+ orphanComment = true;
+ }
+
+ }
+ return orphanComment;
+ }
+
+
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypeCommentPropertiesMigrationCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypeCommentPropertiesMigrationCommand.java new file mode 100644 index 00000000000..d2f0183e815 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypeCommentPropertiesMigrationCommand.java @@ -0,0 +1,103 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands;
+
+import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeLocationEnum;
+import org.eclipse.papyrus.uml.diagram.common.util.CommandUtil;
+
+/**
+ *
+ * Command to Migrate the StereotypeComment from old Structure (with EAnnotation) to the Structure with NamedStyle.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeCommentPropertiesMigrationCommand extends StereotypePropertiesMigrationCommand {
+
+ /**
+ * Constructor.
+ *
+ * @param label
+ * Label of the Command
+ * @param content
+ * Main view on which the Stereotype is applied
+ */
+ public StereotypeCommentPropertiesMigrationCommand(String label, View content) {
+ super(label, content);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands.StereotypePropertiesMigrationCommand#updateStereotypePropertyDisplay(org.eclipse.gmf.runtime.notation.View, java.lang.String, java.lang.Enum)
+ *
+ */
+ @Override
+ protected void updateStereotypePropertyDisplay(View view, String propertyList, Enum<?> location) {
+ // In case of the Comment, the view will be the comment itself instead of the main View.
+ if (StereotypeLocationEnum.IN_COMMENT.equals(location)) {
+
+ View newComment = helper.getStereotypeComment(view);
+ if (newComment != null) {
+ super.updateStereotypePropertyDisplay(newComment, propertyList, location);
+ setConstraint(view, newComment);
+
+ }
+ deleteOldComment(view);
+ }
+ }
+
+ /**
+ * @param view
+ * @param newComment
+ */
+ private void setConstraint(final View view, final View newComment) {
+ if (newComment instanceof Node) {
+ View oldComment = migrationHelper.getOldStereotypeComment(view);
+ if (oldComment instanceof Node) {
+ ((Node) newComment).setLayoutConstraint(((Node) oldComment).getLayoutConstraint());
+ }
+ }
+ }
+
+ /**
+ * @param view
+ */
+ private void deleteOldComment(final View hostView) {
+ // Delete Comment from the Old Structure
+
+ View oldComment = migrationHelper.getOldStereotypeComment(hostView);
+ if (oldComment != null) {
+ DeleteCommand deleteComment = new DeleteCommand(oldComment);
+ CommandUtil.executeUnsafeCommand(deleteComment, hostView);
+ }
+ Edge oldLink = migrationHelper.getOldStereotypeLinkComment(hostView);
+ if (oldLink != null) {
+ DeleteCommand deleteLink = new DeleteCommand(oldLink);
+ CommandUtil.executeUnsafeCommand(deleteLink, hostView);
+ }
+
+
+
+
+ }
+
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypeLabelMigrationCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypeLabelMigrationCommand.java new file mode 100644 index 00000000000..120732819f6 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypeLabelMigrationCommand.java @@ -0,0 +1,248 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Displays
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands;
+
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.IStereotypeViewProvider;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.StereotypeViewProvider;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayCommandExecution;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.StereotypeMigrationHelper;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * This Command applies the user preferences for the Stereotype Label
+ * In charge of check the visibility, depth and persistence based on the Old EAnnotation
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeLabelMigrationCommand implements Runnable {
+
+ // String Constant
+ private static final String EANNOTATION_LIST_SEPARATOR = ","; //$NON-NLS-1$
+ private static final String QUALIFIED_NAME_DEPTH = "full"; //$NON-NLS-1$
+
+
+ private View mainView;
+
+ // Static Instances of helpers and providers
+ private static StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+ private static StereotypeMigrationHelper migrationHelper = StereotypeMigrationHelper.getInstance();
+ private static StereotypeDisplayCommandExecution commandHelper = StereotypeDisplayCommandExecution.getInstance();
+ protected static IStereotypeViewProvider provider;
+
+
+ /**
+ * Constructor.
+ *
+ * @param label
+ * The Label of the Command
+ * @param content
+ * The View of the element that is migrated.
+ */
+ public StereotypeLabelMigrationCommand(String label, View content) {
+
+ this.mainView = content;
+
+ }
+
+
+ /**
+ * Migrate the Stereotype Label from the old Version.
+ *
+ * @param View
+ * The element of the diagram to migrate
+ */
+ protected void migrateStereotypeLabel(View view) {
+ // Create the provider
+ setProvider(view);
+
+ if (migrationHelper.hasStereotypeEAnnotation(view)) {
+
+ // Update Visibility
+ String oldStereotype = getOldStereotypeToDisplay(view);
+ updateNewStereotypeVisibility(view, oldStereotype);
+
+ // Update Depth
+ String oldQNStereotype = getOldQNStereotypeToDisplay(view);
+ updateNewStereotypeDepth(view, oldQNStereotype);
+
+ }
+ }
+
+ /**
+ * From the Stereotype List to display with they Qualified Name, update the Depth to full
+ *
+ * @param view
+ * The view of the object to migrate
+ * @param stereotypeList
+ * List of Stereotype to display with their Qualified Name
+ */
+ protected void updateNewStereotypeDepth(View view, String stereotypeList) {
+ StringTokenizer tokenizer = new StringTokenizer(stereotypeList, EANNOTATION_LIST_SEPARATOR);
+
+ while (tokenizer.hasMoreTokens()) {
+ String stereotypeName = tokenizer.nextToken();
+ View label = helper.getStereotypeLabel(view, stereotypeName);
+ if (label != null) {
+ commandHelper.setDepth(migrationHelper.getDomain(view), migrationHelper.getStereotypeFromString(view, stereotypeName), view, QUALIFIED_NAME_DEPTH, false);
+ }
+ }
+ }
+
+
+ /**
+ * From the Stereotype List to display , update the Visibility to true
+ * And hide visible Stereotype Label that should not be shown.
+ *
+ * @param view
+ * The view of the object to migrate
+ * @param stereotypeList
+ * List of Stereotype to display
+ */
+ protected void updateNewStereotypeVisibility(View view, String stereotypeList) {
+
+ // Hide all the Label displayed but that should not to be shown
+ hideStereotypeLabelNotDisplayed(stereotypeList, view);
+
+ }
+
+
+ /**
+ * Show each Stereotype from the Stereotype to display list.
+ *
+ * @param stereotypeList
+ * The list of stereotype to display
+ * @param view
+ * The view of the object that is migrated
+ */
+ private void showStereotypeLabelToBeDisplayed(String stereotypeList, View view) {
+ StringTokenizer tokenizer = new StringTokenizer(stereotypeList, EANNOTATION_LIST_SEPARATOR);
+ while (tokenizer.hasMoreTokens()) {
+ String stereotypeName = tokenizer.nextToken();
+ showStereotypeLabel(view, stereotypeName);
+ }
+
+ }
+
+ /**
+ * Show the Label To display.
+ * Updating Visibility and Persistence
+ *
+ * @param view
+ * The view of the object to migrate
+ * @param stereotypeList
+ * List of Stereotype to display
+ */
+ protected void showStereotypeLabel(View view, String stereotypeName) {
+ View label = provider.getLabel(migrationHelper.getStereotypeFromString(view, stereotypeName));
+ if (label != null) {
+ migrationHelper.updateVisibilityAndPersistence(label, view, true);
+ }
+ }
+
+
+ /**
+ * Hide visible Stereotype Label that should not be shown.
+ * List all the applied Stereotypes, if the applied stereotype is not in the Stereotype to Display list,
+ * hide the Node.
+ *
+ * @param view
+ * The view of the object to migrate
+ * @param stereotypeList
+ * List of Stereotype to display
+ */
+ private void hideStereotypeLabelNotDisplayed(String stereotypeList, View view) {
+ EList<Stereotype> appliedStereotypes = migrationHelper.getAppliedStereotypesFromView(view);
+ Iterator<Stereotype> stereotypes = appliedStereotypes.iterator();
+ while (stereotypes.hasNext()) {
+ String stereotypeName = stereotypes.next().getQualifiedName();
+ if (stereotypeList.indexOf(stereotypeName) == -1) {
+ hideStereotypeLabel(view, stereotypeName);
+ }
+ }
+ }
+
+
+
+
+ /**
+ * Hide the Stereotype Label
+ *
+ * @param view
+ * The view of the object that is migrated
+ * @param stereotypeName
+ * Name of the Stereotype of which the Label should be hidden
+ */
+ private void hideStereotypeLabel(View view, String stereotypeName) {
+ View label = provider.getLabel(migrationHelper.getStereotypeFromString(view, stereotypeName));
+ migrationHelper.updateVisibilityAndPersistence(label, mainView, false);
+
+ }
+
+
+ /**
+ * Get List of Stereotype to display with their Qualified Name from the EAnnotation.
+ *
+ * @param view
+ * The view of the object to migrate
+ * @return The List of Stereotype to display with their Qualified Name
+ */
+ protected String getOldQNStereotypeToDisplay(View view) {
+ return migrationHelper.getStereotypesQNToDisplay(view);
+ }
+
+
+ /**
+ * Get List of Stereotype to display from the EAnnotation.
+ *
+ * @param view
+ * The view of the object to migrate
+ * @return The List of Stereotype to display
+ */
+ protected String getOldStereotypeToDisplay(View view) {
+
+ return migrationHelper.getStereotypesToDisplay(view);
+ }
+
+ /**
+ * Create the provider
+ *
+ * @param view
+ * The view on which stereotypes is applied and from which the Stereotype Views will be provided
+ */
+ private void setProvider(View view) {
+ provider = new StereotypeViewProvider(view);
+
+ }
+
+
+ /**
+ * @see java.lang.Runnable#run()
+ *
+ */
+ @Override
+ public void run() {
+ migrateStereotypeLabel(mainView);
+
+ }
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypeNestedPropertiesMigrationCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypeNestedPropertiesMigrationCommand.java new file mode 100644 index 00000000000..6d85814a7b4 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypeNestedPropertiesMigrationCommand.java @@ -0,0 +1,61 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands;
+
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeLocationEnum;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
+
+/**
+ * Command in charge of applying user preferences of stereotype display from the old EANnotation structure to the new one.
+ * For the Properties EAnnotation details.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeNestedPropertiesMigrationCommand extends StereotypePropertiesMigrationCommand {
+
+ /**
+ * Constructor.
+ *
+ * @param label
+ * Command Label
+ * @param content
+ * View on which the Stereotype is applied.
+ */
+ public StereotypeNestedPropertiesMigrationCommand(String label, View content) {
+ super(label, content);
+
+ }
+
+
+ /**
+ *
+ * In this case, the Old structure return "Compartment" as in the new one the properties are stored in the "Brace" location.
+ *
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands.StereotypePropertiesMigrationCommand#getLocation(java.lang.String)
+ *
+ */
+ @Override
+ public Enum getLocation(String oldProperties) {
+ Enum location = StereotypeLocationEnum.IN_BRACE;
+ if (oldProperties.equals(StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_LOCATION)) {
+ location = StereotypeLocationEnum.IN_BRACE;
+ } else if (oldProperties.equals(StereotypeDisplayConstant.STEREOTYPE_BRACE_LOCATION)) {
+ location = StereotypeLocationEnum.IN_BRACE;
+ }
+ return location;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypePropertiesMigrationCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypePropertiesMigrationCommand.java new file mode 100644 index 00000000000..f00e8a96f47 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/commands/StereotypePropertiesMigrationCommand.java @@ -0,0 +1,314 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands;
+
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.StereotypeLocationEnum;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.IStereotypeViewProvider;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.StereotypeViewProvider;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.StereotypeMigrationHelper;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+
+/**
+ * In charge of applying user preferences from the old EAnnotation structure to the new one
+ * For Stereotypes Properties
+ * This means set visibility to the newly created views .
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypePropertiesMigrationCommand implements Runnable {
+
+ protected View mainView;
+
+ protected static IStereotypeViewProvider provider;
+
+ // Helpers
+ protected static StereotypeMigrationHelper migrationHelper = StereotypeMigrationHelper.getInstance();
+ protected static StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+
+ // Constant
+ protected final static String EANNOTATION_LIST_SEPARATOR = ","; //$NON-NLS-1$
+ protected final static String EANNOTATION_PROPERTY_SEPARATOR = "."; //$NON-NLS-1$
+ protected final static String EMPTY_STRING = "";//$NON-NLS-1$
+
+ /**
+ * Constructor.
+ *
+ * @param label
+ * Label of the Command
+ * @param content
+ * Main view on which the Stereotype is applied
+ */
+ public StereotypePropertiesMigrationCommand(String label, View content) {
+
+ this.mainView = content;
+ }
+
+
+
+ /**
+ * Migrate the Stereotype Properties from the old Version.
+ *
+ * @param view
+ * View of the Editpart on which the STereotype is applied
+ */
+ protected void migrateStereotypeProperties(View view) {
+
+ createProvider(view);
+ if (migrationHelper.hasStereotypeEAnnotation(view)) {
+ String oldProperties = getOldPropertiesToDisplay(view);
+ String oldPropertiesLocation = getOldLocationToDisplay(view);
+ Enum<?> location = getLocation(oldPropertiesLocation);
+ updateStereotypePropertyDisplay(view, oldProperties, location);
+
+ }
+ }
+
+
+ /**
+ * Convert the EAnnotation Location to the Property Location to display.
+ * Can be extended.
+ */
+ public Enum<?> getLocation(String oldProperties) {
+ Enum<?> location = StereotypeLocationEnum.IN_BRACE;
+ if (oldProperties.equals(StereotypeDisplayConstant.STEREOTYPE_COMPARTMENT_LOCATION)) {
+ location = StereotypeLocationEnum.IN_COMPARTMENT;
+ } else if (oldProperties.equals(StereotypeDisplayConstant.STEREOTYPE_BRACE_LOCATION)) {
+ location = StereotypeLocationEnum.IN_BRACE;
+ } else if (oldProperties.equals(StereotypeDisplayConstant.STEREOTYPE_COMMENT_LOCATION)) {
+ location = StereotypeLocationEnum.IN_COMMENT;
+ }
+ return location;
+ }
+
+ /**
+ * Create the Provider with the associated View
+ *
+ * @param view
+ * The View of the object that will be taken as Reference to provide the different Stereotype to display View.
+ */
+ protected void createProvider(View view) {
+ provider = new StereotypeViewProvider(view);
+
+ }
+
+
+ /**
+ * From the Stereotype Property List to display , update the Visibility
+ * And hide visible Stereotype property that should not be shown.
+ *
+ * @param view
+ * The view of the object to migrate
+ * @param propertyList
+ * List of property to display
+ * @param location
+ * The Location of the Properties to be displayed or hidden.
+ */
+ protected void updateStereotypePropertyDisplay(View view, String propertyList, Enum<?> location) {
+
+ // Show all the properties that should be displayed
+ showStereotypePropertyToBeDisplayed(propertyList, view, location);
+
+ }
+
+ /**
+ * Show all the Properties from the Properties List and their location
+ *
+ * @param propertyList
+ * List of properties (ie: "SysML::Blocks::Block.isEncapsulated,SysML::Requirement::Requirement.id")
+ * @param view
+ * The View of the Object migrated (ie: CSSShapeImpl)
+ * @param location
+ * Place of the the property to be shown: {@link StereotypeLocationEnum}
+ */
+ private void showStereotypePropertyToBeDisplayed(String propertyList, View view, Enum<?> location) {
+ StringTokenizer tokenizer = new StringTokenizer(propertyList, EANNOTATION_LIST_SEPARATOR);
+ while (tokenizer.hasMoreTokens()) {
+
+ String propertyString = tokenizer.nextToken();
+ Stereotype stereoytpe = getStereotypeFromString(view, propertyString);
+ if (stereoytpe != null) {
+ Property property = getPropertyFromString(view, propertyString, stereoytpe);
+ showStereotypeProperty(view, stereoytpe, property, location);
+ }
+ }
+
+ }
+
+ /**
+ * Show the property and related Location Compartment to display
+ *
+ * @param view
+ * The Main View on which the stereotype is applied.
+ * @param location
+ * The location of the Property to show (Compartment, Comment, With Brace)
+ * @param stereotype
+ * The Stereotype of the Property to show
+ * @param property
+ * UML Property to show
+ */
+ private void showStereotypeProperty(View view, Stereotype stereotype, Property property, Enum<?> location) {
+ // Make The main View visible (Required for the Comment )
+ migrationHelper.updateVisibilityAndPersistence(view, view, true);
+
+ // Make The compartment owning the property visible
+ View compartment = provider.getCompartment(stereotype, location);
+ migrationHelper.updateVisibilityAndPersistence(compartment, view, true);
+
+ // Make the properties node into the Compartment visible
+ View propertyView = provider.getProperty(property, stereotype, location);
+ migrationHelper.updateVisibilityAndPersistence(propertyView, view, true);
+
+ }
+
+
+
+ /**
+ * Hide visible Properties that should not be shown.
+ * List all the applied Stereotypes and their Properties, if the property is not in the property to Display list,
+ * hide the Node.
+ *
+ * @param view
+ * The view of the object to migrate
+ * @param stereotypeList
+ * List of Stereotype to display
+ */
+ private void hideStereotypePropertyNotDisplayed(String propertyList, View view, Enum<?> location) {
+
+ // If applied Stereotype is not in the Stereotype list to display, set the visibility to false to hide the Label.
+ Iterator<Stereotype> stereotypes = migrationHelper.getAppliedStereotypesFromView(view).iterator();
+ while (stereotypes.hasNext()) {
+ Stereotype stereotype = stereotypes.next();
+ hideStereotypeProperties(stereotype, propertyList, location);
+
+ }
+ }
+
+
+ /**
+ * Hide the Properties from the properties list, location and Stereotypes
+ *
+ * @param stereotype
+ * The Stereotype of which the Properties should be hidden
+ * @param propertyList
+ * The list of all the properties to be displayed
+ * @param location
+ * The location of the Properties to be hidden
+ */
+ private void hideStereotypeProperties(Stereotype stereotype, String propertyList, Enum<?> location) {
+ for (Property property : stereotype.allAttributes()) {
+ if (propertyList.indexOf(property.getName()) == -1) {
+
+ // Create the Property view if not existing and Make the properties node into the Compartment visible
+ hideStereotypeProperty(property, stereotype, location);
+ }
+ }
+
+ }
+
+ /**
+ * Hide a single property View based on the stereotype and the location.
+ *
+ * @param property
+ * The property to hide
+ * @param stereotype
+ * The stereotype of the property to hide
+ * @param location
+ * the location of the property to hide
+ */
+ private void hideStereotypeProperty(Property property, Stereotype stereotype, Enum<?> location) {
+ View compartment = provider.getCompartment(stereotype, location);
+ if (compartment != null) {
+ View propertyView = provider.getProperty(property, stereotype, location);
+ if (propertyView != null) {
+ migrationHelper.updateVisibilityAndPersistence(propertyView, mainView, false);
+ }
+ }
+
+ }
+
+ /**
+ * Get the property from String
+ *
+ * @param view
+ * The Main View on which the stereotype is applied.
+ * @param propertyString
+ * the substring from the Old Version (I.e: "SysML::Blocks::Block.isEncapsulate")
+ * @return The corresponding UML property
+ */
+ private Property getPropertyFromString(View view, String propertyString, Stereotype stereotype) {
+ String propertyName = propertyString.substring(propertyString.indexOf(EANNOTATION_PROPERTY_SEPARATOR) + 1, propertyString.length());
+ return migrationHelper.getPropertyFromString(view, stereotype, propertyName);
+ }
+
+
+ /**
+ * Get the stereotype from String
+ *
+ * @param view
+ * The Main View on which the stereotype is applied.
+ * @param propertyString
+ * the substring from the Old Version (I.e: "SysML::Blocks::Block")
+ * @return The corresponding UML Stereotype
+ */
+ private Stereotype getStereotypeFromString(View view, String propertyString) {
+ String qualifiedName = propertyString.substring(0, propertyString.indexOf(EANNOTATION_PROPERTY_SEPARATOR));
+ return migrationHelper.getStereotypeFromString(view, qualifiedName);
+
+ }
+
+
+ /**
+ * Get the EAnnotation Detail value for the properties Location.
+ *
+ * @param view
+ * The view on which the stereotype is applied
+ * @return Location value
+ */
+ protected String getOldLocationToDisplay(View view) {
+ return migrationHelper.getAppliedStereotypesPropertiesLocalization(view);
+ }
+
+
+ /**
+ * Get the EAnnotation Detail value for the Property list to displayed
+ *
+ * @param view
+ * The view on which the stereotype is applied
+ * @return The list of the properties to be displayed
+ */
+ protected String getOldPropertiesToDisplay(View view) {
+ return migrationHelper.getAppliedStereotypesPropertiesToDisplay(view);
+ }
+
+
+ /**
+ * @see java.lang.Runnable#run()
+ *
+ */
+ @Override
+ public void run() {
+ migrateStereotypeProperties(mainView);
+
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationLabelMigrationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationLabelMigrationEditPolicy.java new file mode 100644 index 00000000000..8c9cd48ef08 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationLabelMigrationEditPolicy.java @@ -0,0 +1,85 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.commands.RemoveEAnnotationDetailCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.StereotypeDisplayMigrationConstant;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands.StereotypeLabelMigrationCommand;
+import org.eclipse.papyrus.uml.diagram.common.util.CommandUtil;
+
+/**
+ * Edit Policy for the Stereotype Label user preferences migration.
+ * Should be applied to every graphicalEditPart on which Stereotypes can be applied.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeEAnnotationLabelMigrationEditPolicy extends StereotypeEAnnotationMigrationEditPolicy {
+
+ public static final String LABEL = "Migration of Stereotype Label";//$NON-NLS-1$
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies.StereotypeEAnnotationMigrationEditPolicy#cleanEAnnotationDetails(org.eclipse.gmf.runtime.notation.View)
+ *
+ *
+ * Clean the Key of EAnnotation related to the StereotypeLabel:
+ * <li>{@link StereotypeDisplayMigrationConstant.STEREOTYPE_LIST}</li>
+ * <li>{@link StereotypeDisplayMigrationConstant.STEREOTYPE_WITHQN_LIST}</li>
+ *
+ *
+ * @param view
+ * The view owning the EAnnotation to clean
+ *
+ */
+ @Override
+ public void cleanEAnnotationDetails(View view) {
+
+
+ TransactionalEditingDomain domain = CommandUtil.resolveEditingDomain(view);
+
+ RemoveEAnnotationDetailCommand deleteStereotype = new RemoveEAnnotationDetailCommand(domain, eAnnotation, StereotypeDisplayMigrationConstant.STEREOTYPE_LIST);
+ CommandUtil.executeUnsafeCommand(deleteStereotype, view);
+
+ RemoveEAnnotationDetailCommand deleteQNList = new RemoveEAnnotationDetailCommand(domain, eAnnotation, StereotypeDisplayMigrationConstant.STEREOTYPE_WITHQN_LIST);
+ CommandUtil.executeUnsafeCommand(deleteQNList, view);
+
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies.StereotypeEAnnotationMigrationEditPolicy#hasEAnnotationDetails(org.eclipse.gmf.runtime.notation.View)
+ *
+ */
+ @Override
+ public boolean hasEAnnotationDetails(View view) {
+
+ return migrationHelper.getStereotypesToDisplay(hostView) != null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies.StereotypeEAnnotationMigrationEditPolicy#getStereotypeMigrationCommand(org.eclipse.gmf.runtime.notation.View)
+ *
+ */
+ @Override
+ public Runnable getStereotypeMigrationCommand(View view) {
+
+ return new StereotypeLabelMigrationCommand(LABEL, view);
+
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationMigrationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationMigrationEditPolicy.java new file mode 100644 index 00000000000..4ff6bed855a --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationMigrationEditPolicy.java @@ -0,0 +1,167 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.gef.editpolicies.AbstractEditPolicy;
+import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.commands.RemoveEAnnotationCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ConnectionEditPart;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayUtil;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.StereotypeMigrationHelper;
+import org.eclipse.papyrus.uml.diagram.common.util.CommandUtil;
+
+/**
+ * This Edit Policy is in charge to migrate user preferences from old stereotype display structure
+ * (which were using EAnnotation) to the new structure using NamedStyle and additional notation Views
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public abstract class StereotypeEAnnotationMigrationEditPolicy extends AbstractEditPolicy {
+
+ public static final Object STEREOTYPE_RECONCILER = "Stereotype Display Reconciler"; //$NON-NLS-1$
+
+ protected StereotypeMigrationHelper migrationHelper = StereotypeMigrationHelper.getInstance();
+ protected StereotypeDisplayUtil helper = StereotypeDisplayUtil.getInstance();
+
+ protected View hostView = null;
+ protected EAnnotation eAnnotation = null;
+ protected IGraphicalEditPart editPart = null;
+
+
+
+ /**
+ * Set the attributes and launch the migration.
+ *
+ * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate()
+ *
+ */
+ @Override
+ public void activate() {
+
+ // set editPart
+ if (getHost() instanceof GraphicalEditPart) {
+ this.editPart = (GraphicalEditPart) getHost();
+ }
+
+ if (getHost() instanceof ConnectionEditPart) {
+ this.editPart = (ConnectionEditPart) getHost();
+ }
+
+ // set hostView
+ if (editPart != null && editPart.getModel() instanceof View) {
+ this.hostView = (View) editPart.getModel();
+ }
+
+ // set EAnnotation and start the migration process
+ if (editPart != null && hostView != null) {
+ this.eAnnotation = migrationHelper.getStereotypeEAnnotation(hostView);
+ if (eAnnotation != null && !eAnnotation.getDetails().isEmpty()) {
+ migrateStereotype();
+ }
+ }
+
+ }
+
+ /**
+ * Migrate all the Stereotype User preferences
+ *
+ */
+ protected void migrateStereotype() {
+
+ if (eAnnotation != null) {
+ if (hasEAnnotationDetails(hostView)) {
+ // Retrieve the migration Command and execute it.
+ Runnable command = getStereotypeMigrationCommand(hostView);
+ CommandUtil.executeUnsafeCommand(command, editPart);
+
+ }
+ // Clean the details associated to each sub edit policies;
+ cleanEAnnotationDetails(hostView);
+ }
+ // Clean the EAnnotation if Empty
+ cleanEAnnotation();
+ }
+
+
+ /**
+ * Remove the EAnnotation when necessary
+ */
+ private void cleanEAnnotation() {
+
+ // If the EAnnotation is Empty Delete it
+ if (eAnnotation != null && eAnnotation.getDetails().size() == 0) {
+ RemoveEAnnotationCommand command = new RemoveEAnnotationCommand(editPart.getEditingDomain(), hostView, eAnnotation);
+ CommandUtil.executeUnsafeCommand(command, editPart);
+ }
+
+ // If No Stereotype Structure is Found on the host but EAnnotation is present, delete the EAnnotation
+ if (eAnnotation != null && !helper.hasStereotypeViews(hostView)) {
+ RemoveEAnnotationCommand command = new RemoveEAnnotationCommand(editPart.getEditingDomain(), hostView, eAnnotation);
+ CommandUtil.executeUnsafeCommand(command, editPart);
+ }
+
+ // Delete orphan Comment Node from OldStructure
+ Object container = hostView.eContainer();
+ if (container instanceof View) {
+ View containerView = (View) container;
+ Iterator<Object> sibilings = containerView.getChildren().iterator();
+ while (sibilings.hasNext()) {
+ Object sibiling = sibilings.next();
+ if (migrationHelper.isOldComment(sibiling)) {
+ if (migrationHelper.isOrphanComment((View) sibiling)) {
+ DeleteCommand deleteComment = new DeleteCommand((View) sibiling);
+ CommandUtil.executeUnsafeCommand(deleteComment, sibiling);
+ }
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Clean EAnnotation Details in the model depending of what has been treated.
+ *
+ * @param hostView
+ * The view on which the Stereotype has been applied
+ */
+ public abstract void cleanEAnnotationDetails(View view);
+
+ /**
+ * Define if the Edit Policy detail for the specific EANnotation Detail is not Empty.
+ *
+ * @param view
+ * The view on which the Stereotype has been applied
+ */
+ public abstract boolean hasEAnnotationDetails(View view);
+
+ /**
+ * Get the command to update the Node visibility related to the EAnnotation.
+ *
+ * @param hostView
+ * The view on which the Stereotype has been applied
+ */
+ public abstract Runnable getStereotypeMigrationCommand(View view);
+
+
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationNestedMigrationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationNestedMigrationEditPolicy.java new file mode 100644 index 00000000000..044396de925 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationNestedMigrationEditPolicy.java @@ -0,0 +1,79 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies;
+
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.diagram.common.editparts.UMLCompartmentEditPart;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands.StereotypeNestedPropertiesMigrationCommand;
+
+/**
+ * Edit Policy to manage the migration of the object into Compartment :
+ * <ul>
+ * <li>Operations</li>
+ * <li>Properties</li>
+ * <li>Nested Element</li>
+ * <li>Enumeration</li>
+ * <li>....</li>
+ * </ul>
+ *
+ * To be applied on all the instances of {@link UMLCompartmentEditPart}.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeEAnnotationNestedMigrationEditPolicy extends StereotypeEAnnotationPropertiesMigrationEditPolicy {
+
+
+ /**
+ * Constructor.
+ *
+ */
+ public StereotypeEAnnotationNestedMigrationEditPolicy() {
+ super();
+ }
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies.StereotypeEAnnotationMigrationEditPolicy#activate()
+ *
+ */
+ @Override
+ public void activate() {
+ if (getHost() instanceof GraphicalEditPart) {
+ this.editPart = (GraphicalEditPart) getHost();
+ }
+
+ if (editPart instanceof UMLCompartmentEditPart && editPart.getModel() instanceof View) {
+ this.hostView = (View) editPart.getModel();
+ }
+
+ if (editPart != null && hostView != null) {
+ this.eAnnotation = migrationHelper.getStereotypeEAnnotation(hostView);
+ migrateStereotype();
+ }
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies.StereotypeEAnnotationPropertiesMigrationEditPolicy#getStereotypeMigrationCommand(org.eclipse.gmf.runtime.notation.View)
+ *
+ */
+ @Override
+ public Runnable getStereotypeMigrationCommand(View view) {
+
+ return new StereotypeNestedPropertiesMigrationCommand(LABEL, view);
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationPropertiesMigrationEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationPropertiesMigrationEditPolicy.java new file mode 100644 index 00000000000..d00ac6a648b --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/migration/editpolicies/StereotypeEAnnotationPropertiesMigrationEditPolicy.java @@ -0,0 +1,97 @@ +/*****************************************************************************
+ * Copyright (c) 2015 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:
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ * Celine JANSSENS (ALL4TEC) celine.janssens@all4tec.net - Bug 455311 : Refactor Stereotype Display
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies;
+
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.commands.RemoveEAnnotationDetailCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.StereotypeDisplayMigrationConstant;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands.StereotypeCommentPropertiesMigrationCommand;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.migration.commands.StereotypePropertiesMigrationCommand;
+import org.eclipse.papyrus.uml.diagram.common.util.CommandUtil;
+
+/**
+ * Edit Policy for the Stereotype Properties user preferences migration.
+ * Should be applied to every graphicalEditPart on which Stereotypes Properties can be displayed.
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class StereotypeEAnnotationPropertiesMigrationEditPolicy extends StereotypeEAnnotationMigrationEditPolicy {
+
+ public static final String LABEL = "Migration Stereotype Properties";//$NON-NLS-1$
+
+
+
+ /**
+ * Clean the Key of EAnnotation related to the StereotypeLabel:
+ * <ul>
+ * <li>{@link StereotypeDisplayMigrationConstant.STEREOTYPE_PROPERTY_LOCATION}</li>
+ * <li>{@link StereotypeDisplayMigrationConstant.PROPERTY_STEREOTYPE_DISPLAY}</li>
+ * <li>{@link StereotypeDisplayMigrationConstant.STEREOTYPE_PRESENTATION_KIND}</li>
+ * </ul>
+ *
+ * @param view
+ * The view owning the EAnnotation to clean
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies.StereotypeEAnnotationMigrationEditPolicy#cleanEAnnotationDetails(org.eclipse.gmf.runtime.notation.View)
+ *
+ */
+ @Override
+ public void cleanEAnnotationDetails(View view) {
+
+ TransactionalEditingDomain domain = CommandUtil.resolveEditingDomain(editPart);
+
+ if (domain != null) {
+ RemoveEAnnotationDetailCommand deleteLocation = new RemoveEAnnotationDetailCommand(domain, eAnnotation, StereotypeDisplayMigrationConstant.STEREOTYPE_PROPERTY_LOCATION);
+ CommandUtil.executeUnsafeCommand(deleteLocation, domain);
+ RemoveEAnnotationDetailCommand deleteProperties = new RemoveEAnnotationDetailCommand(domain, eAnnotation, StereotypeDisplayMigrationConstant.PROPERTY_STEREOTYPE_DISPLAY);
+ CommandUtil.executeUnsafeCommand(deleteProperties, domain);
+ RemoveEAnnotationDetailCommand deleteKind = new RemoveEAnnotationDetailCommand(domain, eAnnotation, StereotypeDisplayMigrationConstant.STEREOTYPE_PRESENTATION_KIND);
+ CommandUtil.executeUnsafeCommand(deleteKind, domain);
+ }
+
+ }
+
+
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies.StereotypeEAnnotationMigrationEditPolicy#hasEAnnotationDetails(org.eclipse.gmf.runtime.notation.View)
+ *
+ */
+ @Override
+ public boolean hasEAnnotationDetails(View view) {
+
+ return migrationHelper.getAppliedStereotypesPropertiesToDisplay(hostView) != null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.diagram.common.stereotype.migration.editpolicies.StereotypeEAnnotationMigrationEditPolicy#getStereotypeMigrationCommand(org.eclipse.gmf.runtime.notation.View)
+ *
+ */
+ @Override
+ public Runnable getStereotypeMigrationCommand(View view) {
+ Runnable migrationCommand = null;
+ if (migrationHelper.getAppliedStereotypesPropertiesLocalization(view).equals(StereotypeDisplayConstant.STEREOTYPE_COMMENT_LOCATION)) {
+ // In case of properties in Comment, a dedicated Command is required.
+ migrationCommand = new StereotypeCommentPropertiesMigrationCommand(LABEL, view);
+ } else {
+ migrationCommand = new StereotypePropertiesMigrationCommand(LABEL, view);
+ }
+
+ return migrationCommand;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/CommandUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/CommandUtil.java index 2ce9e5c49ec..319df094508 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/CommandUtil.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/CommandUtil.java @@ -7,6 +7,7 @@ * * Contributors: * Obeo - initial API and implementation + * Celine Janssens (ALL4TEC) celine.janssens@all4tec.net - Enrich Execution Command *******************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.util; @@ -19,14 +20,20 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; +import org.eclipse.emf.common.command.Command; +import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.Transaction; +import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.workspace.AbstractEMFOperation; import org.eclipse.gef.EditPartViewer; -import org.eclipse.gef.commands.Command; +import org.eclipse.gmf.runtime.common.core.command.ICommand; import org.eclipse.gmf.runtime.common.core.util.StringStatics; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer; import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil; +import org.eclipse.papyrus.infra.core.services.ServiceException; +import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject; +import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe; import org.eclipse.papyrus.uml.diagram.common.Activator; /** @@ -36,6 +43,9 @@ import org.eclipse.papyrus.uml.diagram.common.Activator; */ public class CommandUtil { + + private static final String DOMAIN_FORMAT = "The transactional Domain cannot be retrived from the object s1"; + /** * Executes the supplied command inside an <code>unchecked action</code> * @@ -45,7 +55,7 @@ public class CommandUtil { * command that can be executed (i.e., cmd.canExecute() == true) * @param part */ - public static void executeCommand(final Command cmd, IGraphicalEditPart part) { + public static void executeCommand(final org.eclipse.gef.commands.Command cmd, IGraphicalEditPart part) { Map<String, Boolean> options = null; boolean isActivating = true; // use the viewer to determine if we are still initializing the diagram @@ -77,4 +87,167 @@ public class CommandUtil { } } + /** + * Execute a command as unsafe. + * Consequence: the command doesn't appear in the Command Stack and does not make the diagram dirty. + * + * @param command + * The command to execute unsafe + * @param object + * The EObject that is required to define the Transactional domain. + * @param synch + * Define if the command should be execute synchronously or not. + * @see {@link #resolveEditingDomain} + */ + public static void executeUnsafeCommand(final ICommand command, final Object object) { + + TransactionalEditingDomain domain = resolveEditingDomain(object); + if (domain != null) { + executeCommand(command, domain); + } + + } + + /** + * Execute a command as unsafe. + * Consequence: the command doesn't appear in the Command Stack and does not make the diagram dirty. + * + * @param command + * The command to execute unsafe + * @param object + * The EObject that is required to define the Transactional domain. + * @param synch + * Define if the command should be execute synchronously or not. + * @see {@link #resolveEditingDomain} + */ + public static void executeUnsafeCommand(final Command command, final Object object) { + + TransactionalEditingDomain domain = resolveEditingDomain(object); + if (domain != null) { + executeCommand(command, domain); + } + } + + /** + * Execute a command as unsafe. + * Consequence: the command doesn't appear in the Command Stack and does not make the diagram dirty. + * + * @param command + * The command to execute unsafe + * @param object + * The EObject that is required to define the Transactional domain. + * @param synch + * Define if the command should be execute synchronously or not. + * @see {@link #resolveEditingDomain} + */ + public static void executeUnsafeCommand(final Runnable command, final Object object) { + + TransactionalEditingDomain domain = resolveEditingDomain(object); + if (domain != null) { + executeCommand(command, domain); + } + + } + + /** + * Execute a command as unsafe. + * Consequence: the command doesn't appear in the Command Stack and does not make the diagram dirty. + * + * @param command + * The command to execute unsafe + * @param object + * The EObject that is required to define the Transactional domain. + * + * @see {@link #resolveEditingDomain} + */ + public static void executeCommandInStack(final org.eclipse.emf.common.command.Command command, final Object object) { + + TransactionalEditingDomain domain = resolveEditingDomain(object); + domain.getCommandStack().execute(command); + + } + + /** + * Retrieve Editing Domain from an object. + * The Object treated can be a {@link TransactionalEditingDomain}, an {@link EObject} or a {@link IGraphicalEditPart}. + * + * @param object + * The object used to find the Transactional Editing Domain. + * + * @return The associated Editing Domain, or null if not found. + */ + public static TransactionalEditingDomain resolveEditingDomain(Object object) { + TransactionalEditingDomain domain = null; + try { + if (object instanceof TransactionalEditingDomain) { + domain = (TransactionalEditingDomain) object; + } else if (object instanceof IGraphicalEditPart) { + domain = ((IGraphicalEditPart) object).getEditingDomain(); + } else if (object instanceof EObject) { + domain = ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain((EObject) object); + } else { + Activator.log.error(String.format(DOMAIN_FORMAT, object.toString()), null); + } + } catch (ServiceException e) { + Activator.log.error(e); + } + + return domain; + } + + /** + * Run the Command Asynchronously + * + * @param command + * The command to execute + * @param domain + * The Transactional Editing Domain + * + */ + public static void executeCommand(final Command command, final TransactionalEditingDomain domain) { + + try { + GMFUnsafe.write(domain, command); + } catch (Exception e) { + Activator.log.error(e); + } + + } + + /** + * Run the Command Asynchronously + * + * @param command + * The command to execute + * @param domain + * The Transactional Editing Domain + * + */ + private static void executeCommand(final ICommand command, final TransactionalEditingDomain domain) { + try { + GMFUnsafe.write(domain, command); + } catch (Exception e) { + Activator.log.error(e); + } + } + + /** + * Run the Command Asynchronously + * + * @param command + * The command to execute + * @param domain + * The Transactional Editing Domain + * + */ + private static void executeCommand(final Runnable command, final TransactionalEditingDomain domain) { + // use to avoid to put it in the command stack + try { + GMFUnsafe.write(domain, command); + } catch (Exception e) { + Activator.log.error(e); + } + } + + } |