Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Lorenzo2017-09-20 08:19:28 +0000
committervincent lorenzo2017-09-21 16:11:17 +0000
commit97491f79217ed5fc395016f8a09efecaa48c832a (patch)
tree45f8cf3d137e52161998f70d6f6c89089add08e2 /plugins/uml
parent528b6adbdb3444ce4043fb04e61b55f845ef4012 (diff)
downloadorg.eclipse.papyrus-97491f79217ed5fc395016f8a09efecaa48c832a.tar.gz
org.eclipse.papyrus-97491f79217ed5fc395016f8a09efecaa48c832a.tar.xz
org.eclipse.papyrus-97491f79217ed5fc395016f8a09efecaa48c832a.zip
Bug 522564 - [Property View][Profile] Label in TreeViewer is not updated
- add a refresh on the TreeViewer on commandstack event - add a DisposeListener on the Composite parent, because we were not correctly disposed in the previous implementation (dispose method were not called) Change-Id: Ibdaef76bfc421fe8bbf75042945bfdeb02a91761 Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins/uml')
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java1418
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/DecoratedTreeComposite.java1162
-rw-r--r--plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/section/AppliedStereotypeSectionWithView.java309
3 files changed, 1487 insertions, 1402 deletions
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java
index dc705ccc1b1..64882557479 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/AppliedStereotypeCompositeOnModel.java
@@ -1,684 +1,734 @@
-/*****************************************************************************
- * Copyright (c) 2008, 2014 CEA LIST and others.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
- * Christian W. Damus (CEA) - bug 323802
- * Christian W. Damus (CEA) - bug 448139
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.impl.NotificationImpl;
-import org.eclipse.emf.common.util.BasicEList;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.uml.profile.Activator;
-import org.eclipse.papyrus.uml.profile.preference.ProfilePreferenceConstants;
-import org.eclipse.papyrus.uml.profile.tree.ProfileElementContentProvider;
-import org.eclipse.papyrus.uml.profile.tree.ProfileElementLabelProvider;
-import org.eclipse.papyrus.uml.profile.tree.ProfileElementTreeViewerFilter;
-import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypePropertyTreeObject;
-import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypeTreeObject;
-import org.eclipse.papyrus.uml.profile.tree.objects.StereotypedElementTreeObject;
-import org.eclipse.papyrus.uml.profile.tree.objects.TreeObject;
-import org.eclipse.papyrus.uml.profile.utils.Util;
-import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.ChooseSetStereotypeDialog;
-import org.eclipse.papyrus.uml.properties.profile.ui.panels.AppliedStereotypePanel;
-import org.eclipse.papyrus.uml.tools.commands.UnapplyStereotypeCommand;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Stereotype;
-
-
-/**
- * This composite is used to display applied stereotype in the model. It allows applying or desapply a stereotype
- */
-public class AppliedStereotypeCompositeOnModel extends DecoratedTreeComposite implements ISelectionChangedListener {
-
- /**
- * Gets the domain.
- *
- * @return the domain
- */
- public TransactionalEditingDomain getEditingDomain(Element context) {
- try {
- return ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(context);
- } catch (ServiceException ex) {
- Activator.log.error(ex);
- return null;
- }
- }
-
- /** The panel that display applied stereotypes. */
- private AppliedStereotypePanel appliedStereotypePanel;
-
- /** The label. */
- protected CLabel label;
-
- /**
- * The default constructor.
- *
- * @param parent
- * the parent Composite for this panel
- */
- public AppliedStereotypeCompositeOnModel(AppliedStereotypePanel parent) {
- super(parent, SWT.NONE, "Applied stereotypes", true);
-
- appliedStereotypePanel = parent;
- }
-
- /**
- * create a composite applied stereotype on model.
- *
- * @param parent
- * the parent composite
- */
- public AppliedStereotypeCompositeOnModel(Composite parent) {
- super(parent, SWT.NONE, "Applied stereotypes", true);
- }
-
- /**
- * apply a stereotype on current selected element.
- */
- protected void addAppliedStereotype() {
-
- // Open stereotype selection (may add or remove)
- ChooseSetStereotypeDialog dialog = new ChooseSetStereotypeDialog(this.getShell(), getElement());
- int result = dialog.open();
-
- if (result == Window.OK) {
- // Retrieve selected element
- Element element = getElement();
-
- // compare the 2 lists (present list and future list
- EList<Stereotype> oldStereotypeList = element.getAppliedStereotypes();
- ArrayList<Stereotype> newStereotypeList = dialog.getSelectedElements();
-
- // Keep newStereotype order (will be used at the end of the method)
- EList<Stereotype> newOrderList = new BasicEList<Stereotype>();
- newOrderList.addAll(newStereotypeList);
-
- // If the 2 lists differ, apply the new list of stereotypes
- if (!(newStereotypeList.equals(oldStereotypeList))) {
-
- // Parse old list :
- // if stereotype is in the new list : it is already applied
- // --> don't unapply it
- // --> remove it from new list
- Iterator<Stereotype> it = oldStereotypeList.iterator();
- while (it.hasNext()) {
- Stereotype currentStOld = it.next();
- if (newStereotypeList.contains(currentStOld)) {
- newStereotypeList.remove(currentStOld);
- } else {
- unapplyStereotype(element, currentStOld);
- }
- }
-
- // Already applied stereotype should have been removed
- // apply others
- Iterator<Stereotype> newApplyStereotypes = newStereotypeList.iterator();
- while (newApplyStereotypes.hasNext()) {
- Stereotype currentStereotype = newApplyStereotypes.next();
- applyStereotype(element, currentStereotype);
- }
-
- // Update Stereotype order
- // this.reorderStereotypeApplications(element, newOrderList);
-
- // checkSelection(null);
- selectionChanged(null);
-
- if (appliedStereotypePanel != null) {
- appliedStereotypePanel.refresh();
- }
- }
- }
-
- }
-
- /**
- * Button action : open a selection dialog box that allow the user to choose stereotypes to apply (or unapply).
- */
- @Override
- public void addButtonPressed() {
- addAppliedStereotype();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public Composite createContent(Composite parent, TabbedPropertySheetWidgetFactory factory) {
- super.createContent(parent, factory);
- createStereotypesTree();
-
- removeButton.setToolTipText("Remove stereotype");
- addButton.setToolTipText("Apply stereotype");
-
- return this;
- }
-
- /**
- * Creates the stereotypes tree.
- *
- * @return the tree of applied stereotypes and properties
- */
- private void createStereotypesTree() {
- // Tree viewer shows applied stereotypes
- treeViewer.setContentProvider(new ProfileElementContentProvider());
- treeViewer.setLabelProvider(new ProfileElementLabelProvider());
- treeViewer.addFilter(new ProfileElementTreeViewerFilter());
- treeViewer.addSelectionChangedListener(this);
- }
-
- /**
- * Button action : modify display order of stereotypes (selected elements are pushed down in the list).
- */
- @Override
- public void downButtonPressed() {
- int nbrOfSelection = getTree().getSelectionCount();
- if (nbrOfSelection < 1) {
- return;
- }
-
- TreeItem[] items = getTree().getSelection();
- int indexLast = getTree().indexOf(items[items.length - 1]);
- if (indexLast + 1 >= getElement().getAppliedStereotypes().size()) {
- // do nothing
- return;
- }
-
- for (int i = 0; i < nbrOfSelection; i++) {
- TreeItem item = items[nbrOfSelection - 1 - i];
- if (item.getData() instanceof AppliedStereotypeTreeObject) {
- AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
- EList stereotypes = new BasicEList();
- stereotypes.addAll(element.getAppliedStereotypes());
-
- int index = stereotypes.indexOf(sTO.getStereotype());
- if ((index == -1) || (index >= stereotypes.size() - 1)) {
- // Not found of already on top...
- return;
- }
-
- stereotypes.move(index + 1, sTO.getStereotype());
- this.reorderStereotypeApplications(element, stereotypes);
- }
- }
- }
-
- /**
- * Edits the item.
- *
- * @param item
- * the item
- */
- @Override
- public void editItem(TreeItem item) {
- // do nothing
- }
-
- /**
- * Gets the selected.
- *
- * @return Returns the selected element.
- */
- public Element getSelected() {
- return appliedStereotypePanel.getSelected();
- }
-
- /**
- * Gets the tree.
- *
- * @return the tree
- */
- public Tree getTree() {
- return treeViewer.getTree();
- }
-
- /**
- * Checks if is in stereotype display.
- *
- * @param st
- * the stereotype
- *
- * @return true, if checks if is in stereotype display
- */
- protected Boolean isInStereotypeDisplay(Stereotype st) {
- return false;
- }
-
- /**
- * Redraw the treeViewer while preserving selections and non-collapsed tree elements
- * It is not sufficient to redraw only selected elements as an optimization, since
- * derived stereotype attributes (that are not selected) might change in response to
- * changing other attributes.
- *
- * @param propertyView
- */
- public void refreshTreeViewer() {
- treeViewer.refresh();
- }
-
- /**
- * Refresh the content of applied the applied stereotype tree.
- */
- @Override
- public void refresh() {
- super.refresh();
-
- if (treeViewer.getTree() != null && !(treeViewer.getTree().isDisposed())) {
- if (element != null) {
- // Preserve selection
- final ISelection selection = treeViewer.getSelection();
- try {
- treeViewer.setInput(new StereotypedElementTreeObject(element));
- } finally {
- treeViewer.setSelection(selection);
- }
- } else {
- treeViewer.setInput(null);
- }
- StereotypedElementTreeObject rTO = (StereotypedElementTreeObject) treeViewer.getInput();
- if (rTO == null) {
- return;
- }
-
- boolean isEditable = isEditable();
-
- // If the property is Multivalued show Up - Down
- if ((rTO.getChildren() != null) && (rTO.getChildren().length > 1)) {
- upButton.setEnabled(isEditable);
- downButton.setEnabled(isEditable);
- } else {
- upButton.setEnabled(false);
- downButton.setEnabled(false);
- }
-
- if ((rTO.getChildren() != null) && (rTO.getChildren().length == 0)) {
- removeButton.setEnabled(false);
- } else {
- removeButton.setEnabled(isEditable);
- }
- }
- }
-
- /**
- * Button action : unapply the stereotypes selected by the user in the stereotype tree.
- */
- @Override
- public void removeButtonPressed() {
- unapplyStereotype();
- }
-
- /**
- * Selection changed.
- *
- * @param event
- * the event
- */
- public void selectionChanged(SelectionChangedEvent event) {
- if (appliedStereotypePanel != null) {
- if (event == null) {
- appliedStereotypePanel.setSelectedProperty(null);
- return;
- }
-
- IStructuredSelection structSelection = (IStructuredSelection) event.getSelection();
- Object selection = structSelection.getFirstElement();
- if (selection instanceof AppliedStereotypePropertyTreeObject) {
- appliedStereotypePanel.setSelectedProperty((AppliedStereotypePropertyTreeObject) selection);
- } else {
- appliedStereotypePanel.setSelectedProperty(null);
- }
-
- }
- }
-
- /**
- * Sets the input.
- *
- * @param element
- * the element
- */
- public void setInput(StereotypedElementTreeObject element) {
- // Preserve selection
- final ISelection selection = treeViewer.getSelection();
- try {
- treeViewer.setInput(element);
- } finally {
- treeViewer.setSelection(selection);
- }
- if (Activator.getDefault().getPreferenceStore().getBoolean(ProfilePreferenceConstants.EXPAND_STEREOTYPES_TREE)) {
- treeViewer.expandAll();
- }
- }
-
- /**
- * unapply stereotype on current selected element.
- */
- protected void unapplyStereotype() {
- int nbrOfSelection = getTree().getSelectionCount();
- if (nbrOfSelection == 0) {
- return;
- }
-
- for (int i = 0; i < nbrOfSelection; i++) {
- TreeItem item = getTree().getSelection()[i];
- if (item.getData() instanceof AppliedStereotypeTreeObject) {
- AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
- unapplyStereotype(element, sTO.getStereotype());
- sTO.removeMe();
- }
- }
- if (appliedStereotypePanel != null) {
- appliedStereotypePanel.refresh();
- } else {
- refresh();
- }
- }
-
- /**
- * Button action : modify display order of stereotypes (selected elements are pushed up in the list).
- */
- @Override
- public void upButtonPressed() {
- int nbrOfSelection = getTree().getSelectionCount();
- if (nbrOfSelection < 1) {
- return;
- }
-
- TreeItem[] items = getTree().getSelection();
- int indexFirst = getTree().indexOf(items[0]);
- if (indexFirst == 0) {
- // do nothing
- return;
- }
-
- for (int i = 0; i < nbrOfSelection; i++) {
- TreeItem item = items[i];
- if (item.getData() instanceof AppliedStereotypeTreeObject) {
- AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
- EList stereotypes = new BasicEList();
- stereotypes.addAll(element.getAppliedStereotypes());
-
- int index = stereotypes.indexOf(sTO.getStereotype());
- if (index < 1) {
- return;
- }
-
- stereotypes.move(index - 1, sTO.getStereotype());
- this.reorderStereotypeApplications(element, stereotypes);
- }
- }
- if (appliedStereotypePanel != null) {
- appliedStereotypePanel.refresh();
- } else {
- refresh();
- }
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel.DecoratedTreeComposite#keepSelection(org.eclipse.jface.viewers.ISelection)
- *
- * @param pSelection
- */
- @Override
- public void keepSelection(ISelection pSelection) {
- getDisplay().asyncExec(new SelectionKeeper(pSelection));
- }
-
- /**
- * Apply stereotype.
- *
- * @param elt
- * the elt
- * @param st
- * the st
- */
- public void applyStereotype(final Element elt, final Stereotype st) {
- try {
- final TransactionalEditingDomain domain = getEditingDomain(elt);
- domain.runExclusive(new Runnable() {
-
- public void run() {
-
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- domain.getCommandStack().execute(getApplyStereotypeCommand(elt, st, domain));
- }
- });
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
-
- }
-
- /**
- * Unapply stereotype.
- *
- * @param elt
- * the uml element
- * @param st
- * the stereotype to unapply
- */
- protected void unapplyStereotype(final Element elt, final Stereotype st) {
- // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline)
- try {
- final TransactionalEditingDomain domain = getEditingDomain(elt);
- domain.runExclusive(new Runnable() {
-
- public void run() {
-
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- domain.getCommandStack().execute(getUnapplyStereotypeCommand(elt, st, domain));
- }
- });
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
-
- }
-
- /**
- * change the order of applied stereotype
- *
- * @param element
- * the UML element where stereotypes are applied
- * @param stereotypes
- * the lis of applied stereotypes with the wanted order
- */
- public void reorderStereotypeApplications(final Element element, final EList stereotypes) {
- try {
- final TransactionalEditingDomain domain = getEditingDomain(element);
- domain.runExclusive(new Runnable() {
-
- public void run() {
-
- Display.getCurrent().asyncExec(new Runnable() {
-
- public void run() {
- domain.getCommandStack().execute(new RecordingCommand(domain) {
-
- @Override
- protected void doExecute() {
- Util.reorderStereotypeApplications(element, stereotypes);
- refresh();
- }
- });
- }
- });
- }
- });
-
- } catch (Exception e) {
- Activator.log.error(e);
- }
-
- }
-
- /**
- *
- * @author gpascual
- *
- */
- private class SelectionKeeper implements Runnable {
-
- /** Selection to keep. */
- ISelection selection = null;
-
- /**
- *
- * Constructor.
- *
- */
- public SelectionKeeper(ISelection selection) {
- this.selection = selection;
- }
-
- public void run() {
- Object[] vSelectedElements = extractSelectedElements(selection);
- Object[] vCorrespondingElements = getCorrespondingElements(vSelectedElements);
- ISelection vSelection = new StructuredSelection(vCorrespondingElements);
- treeViewer.setSelection(vSelection);
-
- }
-
-
-
-
-
- private Object[] getCorrespondingElements(Object[] vSelectedElements) {
- StereotypedElementTreeObject vStereotypesTree = (StereotypedElementTreeObject) treeViewer.getInput();
- List<Object> vReturn = new ArrayList<Object>();
- for (Object vStereotype : vSelectedElements) {
- if (vStereotype instanceof AppliedStereotypeTreeObject) {
- AppliedStereotypeTreeObject vTreeObject = findAppliedStereotypeInTree(((AppliedStereotypeTreeObject) vStereotype).getStereotype(), vStereotypesTree);
- vReturn.add(vTreeObject);
- }
- }
-
- return vReturn.toArray();
- }
-
- private AppliedStereotypeTreeObject findAppliedStereotypeInTree(Stereotype stereotype, StereotypedElementTreeObject vStereotypesTree) {
- AppliedStereotypeTreeObject vAppliedStereotypeObject = null;
-
- for (TreeObject vChild : vStereotypesTree.getChildren()) {
- if (vChild instanceof AppliedStereotypeTreeObject) {
- if (stereotype.equals(((AppliedStereotypeTreeObject) vChild).getStereotype())) {
- vAppliedStereotypeObject = (AppliedStereotypeTreeObject) vChild;
- }
- }
- }
-
- return vAppliedStereotypeObject;
-
- }
-
- private Object[] extractSelectedElements(ISelection pSelection) {
- List<Object> vObjectsList = new ArrayList<Object>();
- if (pSelection instanceof IStructuredSelection) {
- vObjectsList.addAll(Arrays.asList(((IStructuredSelection) pSelection).toArray()));
- }
- return vObjectsList.toArray();
- }
- }
-
- /**
- * Create command to execute during apply stereotype action.
- *
- * @param elt
- * Element where stereotype was applied
- * @param st
- * Stereotype to apply on element
- *
- * @param domain
- * Transaction domain to execute command
- * @return Command to execute to apply stereotype on element
- */
- protected Command getApplyStereotypeCommand(final Element elt, final Stereotype st, final TransactionalEditingDomain domain) {
- return new RecordingCommand(domain) {
-
- /**
- * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
- */
- @Override
- protected void doExecute() {
- elt.applyStereotype(st);
- refresh();
- }
- };
- }
-
- /**
- * Create command execute during unapply stereotype action.
- *
- * @param elt
- * element where stereotype was unapplied
- * @param st
- * Stereotype to unapply on element
- * @param domain
- * Transaction domain to execute command
- * @return Command to execute to unapply stereotype on element
- */
- protected Command getUnapplyStereotypeCommand(final Element elt, final Stereotype st, final TransactionalEditingDomain domain) {
- return new UnapplyStereotypeCommand(elt, st, domain);
-// return new RecordingCommand(domain) {
-//
-// /**
-// * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
-// */
-// @Override
-// protected void doExecute() {
-// elt.unapplyStereotype(st);
-// elt.eNotify(new NotificationImpl(Notification.SET, true, true, true));
-// refresh();
-// }
-// };
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2008, 2014, 2017 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:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ * Christian W. Damus (CEA) - bug 323802
+ * Christian W. Damus (CEA) - bug 448139
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 522564
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EventObject;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.CommandStackListener;
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.uml.profile.Activator;
+import org.eclipse.papyrus.uml.profile.preference.ProfilePreferenceConstants;
+import org.eclipse.papyrus.uml.profile.tree.ProfileElementContentProvider;
+import org.eclipse.papyrus.uml.profile.tree.ProfileElementLabelProvider;
+import org.eclipse.papyrus.uml.profile.tree.ProfileElementTreeViewerFilter;
+import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypePropertyTreeObject;
+import org.eclipse.papyrus.uml.profile.tree.objects.AppliedStereotypeTreeObject;
+import org.eclipse.papyrus.uml.profile.tree.objects.StereotypedElementTreeObject;
+import org.eclipse.papyrus.uml.profile.tree.objects.TreeObject;
+import org.eclipse.papyrus.uml.profile.utils.Util;
+import org.eclipse.papyrus.uml.properties.profile.ui.dialogs.ChooseSetStereotypeDialog;
+import org.eclipse.papyrus.uml.properties.profile.ui.panels.AppliedStereotypePanel;
+import org.eclipse.papyrus.uml.tools.commands.UnapplyStereotypeCommand;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Stereotype;
+
+
+/**
+ * This composite is used to display applied stereotype in the model. It allows applying or desapply a stereotype
+ */
+public class AppliedStereotypeCompositeOnModel extends DecoratedTreeComposite implements ISelectionChangedListener {
+
+ /**
+ * Gets the domain.
+ *
+ * @return the domain
+ */
+ public TransactionalEditingDomain getEditingDomain(Element context) {
+ try {
+ return ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(context);
+ } catch (ServiceException ex) {
+ Activator.log.error(ex);
+ return null;
+ }
+ }
+
+ /** The panel that display applied stereotypes. */
+ private AppliedStereotypePanel appliedStereotypePanel;
+
+ /** The label. */
+ protected CLabel label;
+
+ /**
+ * This listener is used to refresh the Tree showing the applied stereotype and these properties values.
+ * It is easier to listen the stack than listen the edited property values recusrsively (a DataType owning a DataType owning another one, ...)
+ */
+ private CommandStackListener commandStackListener;
+
+ /**
+ * The default constructor.
+ *
+ * @param parent
+ * the parent Composite for this panel
+ */
+ public AppliedStereotypeCompositeOnModel(AppliedStereotypePanel parent) {
+ super(parent, SWT.NONE, "Applied stereotypes", true);
+
+ appliedStereotypePanel = parent;
+ }
+
+ /**
+ * create a composite applied stereotype on model.
+ *
+ * @param parent
+ * the parent composite
+ */
+ public AppliedStereotypeCompositeOnModel(Composite parent) {
+ super(parent, SWT.NONE, "Applied stereotypes", true);
+ }
+
+ /**
+ * apply a stereotype on current selected element.
+ */
+ protected void addAppliedStereotype() {
+
+ // Open stereotype selection (may add or remove)
+ ChooseSetStereotypeDialog dialog = new ChooseSetStereotypeDialog(this.getShell(), getElement());
+ int result = dialog.open();
+
+ if (result == Window.OK) {
+ // Retrieve selected element
+ Element element = getElement();
+
+ // compare the 2 lists (present list and future list
+ EList<Stereotype> oldStereotypeList = element.getAppliedStereotypes();
+ ArrayList<Stereotype> newStereotypeList = dialog.getSelectedElements();
+
+ // Keep newStereotype order (will be used at the end of the method)
+ EList<Stereotype> newOrderList = new BasicEList<Stereotype>();
+ newOrderList.addAll(newStereotypeList);
+
+ // If the 2 lists differ, apply the new list of stereotypes
+ if (!(newStereotypeList.equals(oldStereotypeList))) {
+
+ // Parse old list :
+ // if stereotype is in the new list : it is already applied
+ // --> don't unapply it
+ // --> remove it from new list
+ Iterator<Stereotype> it = oldStereotypeList.iterator();
+ while (it.hasNext()) {
+ Stereotype currentStOld = it.next();
+ if (newStereotypeList.contains(currentStOld)) {
+ newStereotypeList.remove(currentStOld);
+ } else {
+ unapplyStereotype(element, currentStOld);
+ }
+ }
+
+ // Already applied stereotype should have been removed
+ // apply others
+ Iterator<Stereotype> newApplyStereotypes = newStereotypeList.iterator();
+ while (newApplyStereotypes.hasNext()) {
+ Stereotype currentStereotype = newApplyStereotypes.next();
+ applyStereotype(element, currentStereotype);
+ }
+
+ // Update Stereotype order
+ // this.reorderStereotypeApplications(element, newOrderList);
+
+ // checkSelection(null);
+ selectionChanged(null);
+
+ if (appliedStereotypePanel != null) {
+ appliedStereotypePanel.refresh();
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Button action : open a selection dialog box that allow the user to choose stereotypes to apply (or unapply).
+ */
+ @Override
+ public void addButtonPressed() {
+ addAppliedStereotype();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Composite createContent(Composite parent, TabbedPropertySheetWidgetFactory factory) {
+ super.createContent(parent, factory);
+ createStereotypesTree();
+
+ removeButton.setToolTipText("Remove stereotype");
+ addButton.setToolTipText("Apply stereotype");
+
+ return this;
+ }
+
+ /**
+ * Creates the stereotypes tree.
+ *
+ * @return the tree of applied stereotypes and properties
+ */
+ private void createStereotypesTree() {
+ // Tree viewer shows applied stereotypes
+ treeViewer.setContentProvider(new ProfileElementContentProvider());
+ treeViewer.setLabelProvider(new ProfileElementLabelProvider());
+ treeViewer.addFilter(new ProfileElementTreeViewerFilter());
+ treeViewer.addSelectionChangedListener(this);
+ }
+
+ /**
+ * Button action : modify display order of stereotypes (selected elements are pushed down in the list).
+ */
+ @Override
+ public void downButtonPressed() {
+ int nbrOfSelection = getTree().getSelectionCount();
+ if (nbrOfSelection < 1) {
+ return;
+ }
+
+ TreeItem[] items = getTree().getSelection();
+ int indexLast = getTree().indexOf(items[items.length - 1]);
+ if (indexLast + 1 >= getElement().getAppliedStereotypes().size()) {
+ // do nothing
+ return;
+ }
+
+ for (int i = 0; i < nbrOfSelection; i++) {
+ TreeItem item = items[nbrOfSelection - 1 - i];
+ if (item.getData() instanceof AppliedStereotypeTreeObject) {
+ AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
+ EList stereotypes = new BasicEList();
+ stereotypes.addAll(element.getAppliedStereotypes());
+
+ int index = stereotypes.indexOf(sTO.getStereotype());
+ if ((index == -1) || (index >= stereotypes.size() - 1)) {
+ // Not found of already on top...
+ return;
+ }
+
+ stereotypes.move(index + 1, sTO.getStereotype());
+ this.reorderStereotypeApplications(element, stereotypes);
+ }
+ }
+ }
+
+ /**
+ * Edits the item.
+ *
+ * @param item
+ * the item
+ */
+ @Override
+ public void editItem(TreeItem item) {
+ // do nothing
+ }
+
+ /**
+ * Gets the selected.
+ *
+ * @return Returns the selected element.
+ */
+ public Element getSelected() {
+ return appliedStereotypePanel.getSelected();
+ }
+
+ /**
+ * Gets the tree.
+ *
+ * @return the tree
+ */
+ public Tree getTree() {
+ return treeViewer.getTree();
+ }
+
+ /**
+ * Checks if is in stereotype display.
+ *
+ * @param st
+ * the stereotype
+ *
+ * @return true, if checks if is in stereotype display
+ */
+ protected Boolean isInStereotypeDisplay(Stereotype st) {
+ return false;
+ }
+
+ /**
+ * Redraw the treeViewer while preserving selections and non-collapsed tree elements
+ * It is not sufficient to redraw only selected elements as an optimization, since
+ * derived stereotype attributes (that are not selected) might change in response to
+ * changing other attributes.
+ *
+ * @param propertyView
+ */
+ public void refreshTreeViewer() {
+ treeViewer.refresh();
+ }
+
+ /**
+ * Refresh the content of applied the applied stereotype tree.
+ */
+ @Override
+ public void refresh() {
+ super.refresh();
+
+ if (treeViewer.getTree() != null && !(treeViewer.getTree().isDisposed())) {
+ if (element != null) {
+ // Preserve selection
+ final ISelection selection = treeViewer.getSelection();
+ try {
+ treeViewer.setInput(new StereotypedElementTreeObject(element));
+ } finally {
+ treeViewer.setSelection(selection);
+ }
+ } else {
+ treeViewer.setInput(null);
+ }
+ StereotypedElementTreeObject rTO = (StereotypedElementTreeObject) treeViewer.getInput();
+ if (rTO == null) {
+ return;
+ }
+
+ boolean isEditable = isEditable();
+
+ // If the property is Multivalued show Up - Down
+ if ((rTO.getChildren() != null) && (rTO.getChildren().length > 1)) {
+ upButton.setEnabled(isEditable);
+ downButton.setEnabled(isEditable);
+ } else {
+ upButton.setEnabled(false);
+ downButton.setEnabled(false);
+ }
+
+ if ((rTO.getChildren() != null) && (rTO.getChildren().length == 0)) {
+ removeButton.setEnabled(false);
+ } else {
+ removeButton.setEnabled(isEditable);
+ }
+ }
+ }
+
+ /**
+ * Button action : unapply the stereotypes selected by the user in the stereotype tree.
+ */
+ @Override
+ public void removeButtonPressed() {
+ unapplyStereotype();
+ }
+
+ /**
+ * Selection changed.
+ *
+ * @param event
+ * the event
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+ if (appliedStereotypePanel != null) {
+ if (event == null) {
+ appliedStereotypePanel.setSelectedProperty(null);
+ return;
+ }
+
+ IStructuredSelection structSelection = (IStructuredSelection) event.getSelection();
+ Object selection = structSelection.getFirstElement();
+ if (selection instanceof AppliedStereotypePropertyTreeObject) {
+ appliedStereotypePanel.setSelectedProperty((AppliedStereotypePropertyTreeObject) selection);
+ } else {
+ appliedStereotypePanel.setSelectedProperty(null);
+ }
+
+ }
+ }
+
+ /**
+ * Sets the input.
+ *
+ * @param element
+ * the element
+ */
+ public void setInput(StereotypedElementTreeObject element) {
+ // Preserve selection
+ final ISelection selection = treeViewer.getSelection();
+ try {
+ treeViewer.setInput(element);
+ } finally {
+ treeViewer.setSelection(selection);
+ }
+ if (Activator.getDefault().getPreferenceStore().getBoolean(ProfilePreferenceConstants.EXPAND_STEREOTYPES_TREE)) {
+ treeViewer.expandAll();
+ }
+ }
+
+ /**
+ * unapply stereotype on current selected element.
+ */
+ protected void unapplyStereotype() {
+ int nbrOfSelection = getTree().getSelectionCount();
+ if (nbrOfSelection == 0) {
+ return;
+ }
+
+ for (int i = 0; i < nbrOfSelection; i++) {
+ TreeItem item = getTree().getSelection()[i];
+ if (item.getData() instanceof AppliedStereotypeTreeObject) {
+ AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
+ unapplyStereotype(element, sTO.getStereotype());
+ sTO.removeMe();
+ }
+ }
+ if (appliedStereotypePanel != null) {
+ appliedStereotypePanel.refresh();
+ } else {
+ refresh();
+ }
+ }
+
+ /**
+ * Button action : modify display order of stereotypes (selected elements are pushed up in the list).
+ */
+ @Override
+ public void upButtonPressed() {
+ int nbrOfSelection = getTree().getSelectionCount();
+ if (nbrOfSelection < 1) {
+ return;
+ }
+
+ TreeItem[] items = getTree().getSelection();
+ int indexFirst = getTree().indexOf(items[0]);
+ if (indexFirst == 0) {
+ // do nothing
+ return;
+ }
+
+ for (int i = 0; i < nbrOfSelection; i++) {
+ TreeItem item = items[i];
+ if (item.getData() instanceof AppliedStereotypeTreeObject) {
+ AppliedStereotypeTreeObject sTO = (AppliedStereotypeTreeObject) item.getData();
+ EList stereotypes = new BasicEList();
+ stereotypes.addAll(element.getAppliedStereotypes());
+
+ int index = stereotypes.indexOf(sTO.getStereotype());
+ if (index < 1) {
+ return;
+ }
+
+ stereotypes.move(index - 1, sTO.getStereotype());
+ this.reorderStereotypeApplications(element, stereotypes);
+ }
+ }
+ if (appliedStereotypePanel != null) {
+ appliedStereotypePanel.refresh();
+ } else {
+ refresh();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel.DecoratedTreeComposite#keepSelection(org.eclipse.jface.viewers.ISelection)
+ *
+ * @param pSelection
+ */
+ @Override
+ public void keepSelection(ISelection pSelection) {
+ getDisplay().asyncExec(new SelectionKeeper(pSelection));
+ }
+
+ /**
+ * Apply stereotype.
+ *
+ * @param elt
+ * the elt
+ * @param st
+ * the st
+ */
+ public void applyStereotype(final Element elt, final Stereotype st) {
+ try {
+ final TransactionalEditingDomain domain = getEditingDomain(elt);
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ domain.getCommandStack().execute(getApplyStereotypeCommand(elt, st, domain));
+ }
+ });
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+ /**
+ * Unapply stereotype.
+ *
+ * @param elt
+ * the uml element
+ * @param st
+ * the stereotype to unapply
+ */
+ protected void unapplyStereotype(final Element elt, final Stereotype st) {
+ // bugfix: a selected element is not necessary a diagram element (ex: selection in the outline)
+ try {
+ final TransactionalEditingDomain domain = getEditingDomain(elt);
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ domain.getCommandStack().execute(getUnapplyStereotypeCommand(elt, st, domain));
+ }
+ });
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+ /**
+ * change the order of applied stereotype
+ *
+ * @param element
+ * the UML element where stereotypes are applied
+ * @param stereotypes
+ * the lis of applied stereotypes with the wanted order
+ */
+ public void reorderStereotypeApplications(final Element element, final EList stereotypes) {
+ try {
+ final TransactionalEditingDomain domain = getEditingDomain(element);
+ domain.runExclusive(new Runnable() {
+
+ public void run() {
+
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ public void run() {
+ domain.getCommandStack().execute(new RecordingCommand(domain) {
+
+ @Override
+ protected void doExecute() {
+ Util.reorderStereotypeApplications(element, stereotypes);
+ refresh();
+ }
+ });
+ }
+ });
+ }
+ });
+
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+
+ }
+
+ /**
+ *
+ * @author gpascual
+ *
+ */
+ private class SelectionKeeper implements Runnable {
+
+ /** Selection to keep. */
+ ISelection selection = null;
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public SelectionKeeper(ISelection selection) {
+ this.selection = selection;
+ }
+
+ public void run() {
+ Object[] vSelectedElements = extractSelectedElements(selection);
+ Object[] vCorrespondingElements = getCorrespondingElements(vSelectedElements);
+ ISelection vSelection = new StructuredSelection(vCorrespondingElements);
+ treeViewer.setSelection(vSelection);
+
+ }
+
+
+
+
+
+ private Object[] getCorrespondingElements(Object[] vSelectedElements) {
+ StereotypedElementTreeObject vStereotypesTree = (StereotypedElementTreeObject) treeViewer.getInput();
+ List<Object> vReturn = new ArrayList<Object>();
+ for (Object vStereotype : vSelectedElements) {
+ if (vStereotype instanceof AppliedStereotypeTreeObject) {
+ AppliedStereotypeTreeObject vTreeObject = findAppliedStereotypeInTree(((AppliedStereotypeTreeObject) vStereotype).getStereotype(), vStereotypesTree);
+ vReturn.add(vTreeObject);
+ }
+ }
+
+ return vReturn.toArray();
+ }
+
+ private AppliedStereotypeTreeObject findAppliedStereotypeInTree(Stereotype stereotype, StereotypedElementTreeObject vStereotypesTree) {
+ AppliedStereotypeTreeObject vAppliedStereotypeObject = null;
+
+ for (TreeObject vChild : vStereotypesTree.getChildren()) {
+ if (vChild instanceof AppliedStereotypeTreeObject) {
+ if (stereotype.equals(((AppliedStereotypeTreeObject) vChild).getStereotype())) {
+ vAppliedStereotypeObject = (AppliedStereotypeTreeObject) vChild;
+ }
+ }
+ }
+
+ return vAppliedStereotypeObject;
+
+ }
+
+ private Object[] extractSelectedElements(ISelection pSelection) {
+ List<Object> vObjectsList = new ArrayList<Object>();
+ if (pSelection instanceof IStructuredSelection) {
+ vObjectsList.addAll(Arrays.asList(((IStructuredSelection) pSelection).toArray()));
+ }
+ return vObjectsList.toArray();
+ }
+ }
+
+ /**
+ * Create command to execute during apply stereotype action.
+ *
+ * @param elt
+ * Element where stereotype was applied
+ * @param st
+ * Stereotype to apply on element
+ *
+ * @param domain
+ * Transaction domain to execute command
+ * @return Command to execute to apply stereotype on element
+ */
+ protected Command getApplyStereotypeCommand(final Element elt, final Stereotype st, final TransactionalEditingDomain domain) {
+ return new RecordingCommand(domain) {
+
+ /**
+ * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
+ */
+ @Override
+ protected void doExecute() {
+ elt.applyStereotype(st);
+ refresh();
+ }
+ };
+ }
+
+ /**
+ * Create command execute during unapply stereotype action.
+ *
+ * @param elt
+ * element where stereotype was unapplied
+ * @param st
+ * Stereotype to unapply on element
+ * @param domain
+ * Transaction domain to execute command
+ * @return Command to execute to unapply stereotype on element
+ */
+ protected Command getUnapplyStereotypeCommand(final Element elt, final Stereotype st, final TransactionalEditingDomain domain) {
+ return new UnapplyStereotypeCommand(elt, st, domain);
+ }
+
+ /**
+ * @see org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel.DecoratedTreeComposite#setElement(org.eclipse.uml2.uml.Element)
+ *
+ * @param element
+ */
+ @Override
+ public void setElement(Element element) {
+ // if the new element is null, we remove the command stack listener
+ if (null == element && null != getElement()) {
+ getEditingDomain(getElement()).getCommandStack().removeCommandStackListener(this.commandStackListener);
+ }
+ if (null != element && null == this.commandStackListener) {
+ // if the command stack listener has not yet been created, we create it
+ getEditingDomain(element).getCommandStack().addCommandStackListener(this.commandStackListener = new LocalCommandStackListener());
+ }
+ super.setElement(element);
+ }
+
+ /**
+ * @see org.eclipse.swt.widgets.Widget#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ if (null != this.commandStackListener && null != getElement()) {
+ getEditingDomain(getElement()).getCommandStack().removeCommandStackListener(this.commandStackListener);
+ this.commandStackListener = null;
+ }
+ super.dispose();
+ }
+
+ /**
+ * CommandStackListener used to refresh the TreeView when a stereotype property changed
+ *
+ */
+ private class LocalCommandStackListener implements CommandStackListener {
+
+ /**
+ * @see org.eclipse.emf.common.command.CommandStackListener#commandStackChanged(java.util.EventObject)
+ *
+ * @param event
+ */
+ @Override
+ public void commandStackChanged(EventObject event) {
+ if (!AppliedStereotypeCompositeOnModel.this.treeViewer.getTree().isDisposed()) {
+ final ISelection selection = treeViewer.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ final Object first = ((IStructuredSelection) selection).getFirstElement();
+ if (first instanceof AppliedStereotypePropertyTreeObject) {
+ //we refresh the whole tree viewer and not only the leaf to be OK in case of derived properties
+ AppliedStereotypeCompositeOnModel.this.refreshTreeViewer();
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/DecoratedTreeComposite.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/DecoratedTreeComposite.java
index eb9f41ac291..b615de8e3c9 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/DecoratedTreeComposite.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/compositesformodel/DecoratedTreeComposite.java
@@ -1,560 +1,602 @@
-/*****************************************************************************
- * Copyright (c) 2008, 2014 CEA LIST and others.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
- * Christian W. Damus (CEA) - bug 323802
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel;
-
-import org.eclipse.gef.commands.CommandStack;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.uml.profile.ImageManager;
-import org.eclipse.papyrus.uml.profile.tree.ProfileElementTreeViewer;
-import org.eclipse.papyrus.uml.profile.tree.PropertyValueTreeViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
-import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
-import org.eclipse.uml2.uml.Element;
-
-
-/**
- * Base class for a complex section composite. This composite has a label, a
- * tree that describes a tree structure, and four buttons on the side of the
- * table to add an element into the tree, remove selected element(s), move up
- * or down the selected element.
- *
- * @author Remi SCHNEKENBURGER
- */
-public abstract class DecoratedTreeComposite extends Composite implements ISectionComposite {
-
- // child composites for the table composite
-
- // /** main composite of this complex composite */
- // protected Composite composite;
- /**
- * Label above the table.
- */
- protected CLabel label;
-
- /**
- * Table that displays a property for the current element.
- */
- protected Tree tree;
-
- /**
- * The tree viewer.
- */
- protected TreeViewer treeViewer;
-
- /**
- * Button that adds an element.
- */
- protected Button addButton;
-
- /**
- * Button that removes an element.
- */
- protected Button removeButton;
-
- /**
- * button that moves the element up.
- */
- protected Button upButton;
-
- /**
- * button that moves the element down.
- */
- protected Button downButton;
-
- // listeners for buttons
- /**
- * Listener for the add button.
- */
- protected MouseListener addButtonlistener;
-
- /**
- * Listener for the delete button.
- */
- protected MouseListener removeButtonlistener;
-
- /**
- * Listener for the up button.
- */
- protected MouseListener upButtonlistener;
-
- /**
- * Listener for the down button.
- */
- protected MouseListener downButtonlistener;
-
- /**
- *
- */
- protected Listener treeListener;
-
- /**
- * Element selected in the Papyrus modeler.
- */
- protected Element element;
-
-
- // Construction parameters for the composite
- /**
- * text of the label.
- */
- protected String name;
-
- /**
- * returns the element that is selected in Papyrus tool, for which
- * properties are displayed in the property section.
- *
- * @return the element
- */
- public Element getElement() {
- return element;
- }
-
- /**
- * Sets the element that holds property displyed in property section.
- *
- * @param element
- * the element to set
- */
- public void setElement(Element element) {
- this.element = element;
-
- updateEnablement();
- }
-
- /**
- * Constructor.
- *
- * @param style
- * @param isStereotypeTree
- * @param name
- * text of the Label on the top left of this composite
- * @param parent
- */
- public DecoratedTreeComposite(Composite parent, int style, String name, boolean isStereotypeTree) {
- super(parent, style);
- this.name = name;
- this.setLayout(new FormLayout());
-
- this.addButtonlistener = new AddButtonlistener();
- this.removeButtonlistener = new RemoveButtonlistener();
- this.upButtonlistener = new UpButtonlistener();
- this.downButtonlistener = new DownButtonlistener();
-
- if (isStereotypeTree) {
- treeViewer = new ProfileElementTreeViewer(this);
- } else {
- // Property tree
- treeViewer = new PropertyValueTreeViewer(this);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see com.cea.papyrus.ui.composites.ISectionComposite#createContent(org.eclipse.swt.widgets.Composite,
- * org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory)
- */
- /**
- *
- *
- * @param factory
- * @param parent
- *
- * @return
- */
- public Composite createContent(Composite parent, TabbedPropertySheetWidgetFactory factory) {
-
- FormData data;
-
- // ///////////////////////////////////////////////////////////////////////////
- // Create and place button vertically on the left side
- // Button : Add Element
- // Button Delete Element
- removeButton = factory.createButton(this, "", SWT.PUSH);
- removeButton.setVisible(true);
- removeButton.setImage(ImageManager.IMG_DELETE);
- removeButton.setToolTipText("Delete selected element(s)");
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- data.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
- removeButton.setLayoutData(data);
- removeButton.addMouseListener(removeButtonlistener);
-
- addButton = factory.createButton(this, "", SWT.PUSH);
- addButton.setVisible(true);
- addButton.setImage(ImageManager.IMG_ADD);
- addButton.setToolTipText("Add a new element");
-
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- data.right = new FormAttachment(removeButton, -ITabbedPropertyConstants.HSPACE);
- addButton.setLayoutData(data);
- addButton.addMouseListener(addButtonlistener);
-
- // Button Up
- upButton = factory.createButton(this, "", SWT.PUSH);
- upButton.setVisible(true);
- upButton.setImage(ImageManager.IMG_UP);
- upButton.setToolTipText("Up");
-
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- data.right = new FormAttachment(addButton, -ITabbedPropertyConstants.HSPACE);
- upButton.setLayoutData(data);
- upButton.addMouseListener(upButtonlistener);
-
-
- // Button Down
- downButton = factory.createButton(this, "", SWT.PUSH);
- downButton.setVisible(true);
- downButton.setImage(ImageManager.IMG_DOWN);
- downButton.setToolTipText("Down");
-
- data = new FormData();
- data.top = new FormAttachment(0, 0);
- data.right = new FormAttachment(upButton, -ITabbedPropertyConstants.HSPACE);
- downButton.setLayoutData(data);
- downButton.addMouseListener(downButtonlistener);
-
- // Create label
- label = factory.createCLabel(this, name + ":", SWT.NONE);
- label.setLayout(new FormLayout());
- data = new FormData();
- data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
- data.right = new FormAttachment(downButton, -ITabbedPropertyConstants.HSPACE - 30);
- data.top = new FormAttachment(0, 0);
- label.setLayoutData(data);
-
- // ///////////////////////////////////////////////////////////////////////////
- // Create and place Table
- tree = treeViewer.getTree();
- tree.setLayout(new FormLayout());
- tree.setVisible(true);
- tree.addListener(SWT.MouseDoubleClick, treeListener = new EditItemListener());
-
- data = new FormData();
- data.top = new FormAttachment(addButton, ITabbedPropertyConstants.VSPACE);
- data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
- data.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
- data.bottom = new FormAttachment(100, -ITabbedPropertyConstants.VSPACE);
-
- tree.setLayoutData(data);
-
- // initialize enablement of controls
- updateEnablement();
-
- return this;
- }
-
- public void refresh() {
- updateEnablement();
- }
-
- protected boolean isEditable() {
- return (element != null) && !EMFHelper.isReadOnly(element);
- }
-
- protected void updateEnablement() {
- boolean isEditable = isEditable();
-
- if ((addButton != null) && !addButton.isDisposed()) {
- addButton.setEnabled(isEditable);
- removeButton.setEnabled(isEditable);
- upButton.setEnabled(isEditable);
- downButton.setEnabled(isEditable);
- }
- }
-
- // /**
- // * Sets the layout data to the main composite of this complex element
- // * @param data the new LayoutData
- // */
- // public void setLayoutData(Object data) {
- // composite.setLayoutData(data);
- // }
- //
- // public Composite getMainComposite() {
- // return composite;
- // }
-
- /**
- * Returns the CommmandStack of the current editor.
- *
- * @return the CommmandStack of the current editor
- */
- public CommandStack getCommandStack() {
- if (getActiveEditor() != null) {
- return (CommandStack) getActiveEditor().getAdapter(CommandStack.class);
- }
- return null;
- }
-
- /**
- * Returns the current Editor.
- *
- * @return the current editor
- */
- public IEditorPart getActiveEditor() {
- return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- }
-
- /**
- * action executed when the add button is pressed.
- */
- public void addButtonPressed() {
- }
-
- /**
- * @param pSelection
- */
- public void keepSelection(ISelection pSelection) {
-
- }
-
- /**
- * action executed when the remove button is pressed.
- */
- public abstract void removeButtonPressed();
-
- /**
- * action executed when the up button is pressed.
- */
- public abstract void upButtonPressed();
-
- /**
- * action executed when the down button is pressed.
- */
- public abstract void downButtonPressed();
-
- /**
- * action executed when a table item is edited.
- *
- * @param item
- */
- public abstract void editItem(TreeItem item);
-
- /**
- * Listener for the Add Button
- * Specific behavior is implemented in {@link DecoratedTreeComposite#addButtonPressed()}.
- *
- * @author Remi SCHNEKENBURGER
- */
- private class AddButtonlistener implements MouseListener {
-
- /**
- *
- *
- * @param e
- */
- public void mouseDoubleClick(MouseEvent e) {
- // do nothing
- }
-
- /**
- *
- *
- * @param e
- */
- public void mouseDown(MouseEvent e) {
- // do nothing
- }
-
- /**
- *
- *
- * @param e
- */
- public void mouseUp(MouseEvent e) {
- addButtonPressed();
- refresh();
- }
- }
-
- /**
- * Listener for the Remove Button
- * Specific behavior is implemented in {@link DecoratedTreeComposite#removeButtonPressed()}.
- *
- * @author Remi SCHNEKENBURGER
- */
- private class RemoveButtonlistener implements MouseListener {
-
- /**
- *
- *
- * @param e
- */
- public void mouseDoubleClick(MouseEvent e) {
- // do nothing
- }
-
- /**
- *
- *
- * @param e
- */
- public void mouseDown(MouseEvent e) {
- // do nothing
- }
-
- /**
- *
- *
- * @param e
- */
- public void mouseUp(MouseEvent e) {
- removeButtonPressed();
- refresh();
- }
- }
-
- /**
- * Listener for the Up Button
- * Specific behavior is implemented in {@link DecoratedTreeComposite#upButtonPressed()}.
- *
- * @author Remi SCHNEKENBURGER
- */
- private class UpButtonlistener implements MouseListener {
-
- /**
- *
- *
- * @param e
- */
- public void mouseDoubleClick(MouseEvent e) {
- // do nothing
- }
-
- /**
- *
- *
- * @param e
- */
- public void mouseDown(MouseEvent e) {
- // do nothing
- }
-
- /**
- *
- *
- * @param e
- */
- public void mouseUp(MouseEvent e) {
- ISelection selection = treeViewer.getSelection();
- upButtonPressed();
- refresh();
- // Keep selection
- keepSelection(selection);
- }
- }
-
- /**
- * Listener for the Down Button
- * Specific behavior is implemented in {@link DecoratedTreeComposite#downButtonPressed()}.
- *
- * @author Remi SCHNEKENBURGER
- */
- private class DownButtonlistener implements MouseListener {
-
- /**
- *
- *
- * @param e
- */
- public void mouseDoubleClick(MouseEvent e) {
- // do nothing
- }
-
- /**
- *
- *
- * @param e
- */
- public void mouseDown(MouseEvent e) {
- // do nothing
- }
-
- /**
- *
- *
- * @param e
- */
- public void mouseUp(MouseEvent e) {
- ISelection vSelection = treeViewer.getSelection();
-
- downButtonPressed();
- refresh();
- // Keep selection
- keepSelection(vSelection);
-
- }
- }
-
- /**
- *
- */
- private class EditItemListener implements Listener {
-
- /**
- *
- *
- * @param event
- */
- public void handleEvent(Event event) {
- if (tree.getSelection().length > 0) {
- TreeItem item = tree.getSelection()[0];
- editItem(item);
- }
- }
- }
-
- /**
- * Dipose listeners.
- */
- public void disposeListeners() {
- if (addButton != null && !addButton.isDisposed()) {
- addButton.removeMouseListener(addButtonlistener);
- }
- if (removeButton != null && !removeButton.isDisposed()) {
- removeButton.removeMouseListener(removeButtonlistener);
- }
- if (upButton != null && !upButton.isDisposed()) {
- upButton.removeMouseListener(upButtonlistener);
- }
- if (downButton != null && !downButton.isDisposed()) {
- downButton.removeMouseListener(downButtonlistener);
- }
- if (tree != null && !tree.isDisposed()) {
- tree.removeListener(SWT.MouseDoubleClick, treeListener);
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008, 2014, 2017 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:
+ * Chokri Mraidha (CEA LIST) Chokri.Mraidha@cea.fr - Initial API and implementation
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - modification
+ * Christian W. Damus (CEA) - bug 323802
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 522564
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.properties.profile.ui.compositesformodel;
+
+import org.eclipse.gef.commands.CommandStack;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.uml.profile.ImageManager;
+import org.eclipse.papyrus.uml.profile.tree.ProfileElementTreeViewer;
+import org.eclipse.papyrus.uml.profile.tree.PropertyValueTreeViewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
+import org.eclipse.uml2.uml.Element;
+
+
+/**
+ * Base class for a complex section composite. This composite has a label, a
+ * tree that describes a tree structure, and four buttons on the side of the
+ * table to add an element into the tree, remove selected element(s), move up
+ * or down the selected element.
+ *
+ * @author Remi SCHNEKENBURGER
+ */
+public abstract class DecoratedTreeComposite extends Composite implements ISectionComposite {
+
+ // child composites for the table composite
+
+ // /** main composite of this complex composite */
+ // protected Composite composite;
+ /**
+ * Label above the table.
+ */
+ protected CLabel label;
+
+ /**
+ * Table that displays a property for the current element.
+ */
+ protected Tree tree;
+
+ /**
+ * The tree viewer.
+ */
+ protected TreeViewer treeViewer;
+
+ /**
+ * Button that adds an element.
+ */
+ protected Button addButton;
+
+ /**
+ * Button that removes an element.
+ */
+ protected Button removeButton;
+
+ /**
+ * button that moves the element up.
+ */
+ protected Button upButton;
+
+ /**
+ * button that moves the element down.
+ */
+ protected Button downButton;
+
+ // listeners for buttons
+ /**
+ * Listener for the add button.
+ */
+ protected MouseListener addButtonlistener;
+
+ /**
+ * Listener for the delete button.
+ */
+ protected MouseListener removeButtonlistener;
+
+ /**
+ * Listener for the up button.
+ */
+ protected MouseListener upButtonlistener;
+
+ /**
+ * Listener for the down button.
+ */
+ protected MouseListener downButtonlistener;
+
+ /**
+ * DisposeListener registered for the composite parent
+ */
+ protected DisposeListener parentDisposeListener;
+
+ /**
+ *
+ */
+ protected Listener treeListener;
+
+ /**
+ * Element selected in the Papyrus modeler.
+ */
+ protected Element element;
+
+
+ // Construction parameters for the composite
+ /**
+ * text of the label.
+ */
+ protected String name;
+
+ /**
+ * returns the element that is selected in Papyrus tool, for which
+ * properties are displayed in the property section.
+ *
+ * @return the element
+ */
+ public Element getElement() {
+ return element;
+ }
+
+ /**
+ * Sets the element that holds property displyed in property section.
+ *
+ * @param element
+ * the element to set
+ */
+ public void setElement(Element element) {
+ this.element = element;
+
+ updateEnablement();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param style
+ * @param isStereotypeTree
+ * @param name
+ * text of the Label on the top left of this composite
+ * @param parent
+ */
+ public DecoratedTreeComposite(Composite parent, int style, String name, boolean isStereotypeTree) {
+ super(parent, style);
+
+ //we register a dispose listener on the parent because the dispose method is never called during the dispose
+ //see https://stackoverflow.com/questions/25717036/why-swt-ctabitem-doesnt-dispose-child-widget-recursively
+ parent.addDisposeListener(this.parentDisposeListener = new LocalDisposeListener());
+
+ this.name = name;
+ this.setLayout(new FormLayout());
+
+ this.addButtonlistener = new AddButtonlistener();
+ this.removeButtonlistener = new RemoveButtonlistener();
+ this.upButtonlistener = new UpButtonlistener();
+ this.downButtonlistener = new DownButtonlistener();
+
+ if (isStereotypeTree) {
+ treeViewer = new ProfileElementTreeViewer(this);
+ } else {
+ // Property tree
+ treeViewer = new PropertyValueTreeViewer(this);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.cea.papyrus.ui.composites.ISectionComposite#createContent(org.eclipse.swt.widgets.Composite,
+ * org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory)
+ */
+ /**
+ *
+ *
+ * @param factory
+ * @param parent
+ *
+ * @return
+ */
+ public Composite createContent(Composite parent, TabbedPropertySheetWidgetFactory factory) {
+
+ FormData data;
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // Create and place button vertically on the left side
+ // Button : Add Element
+ // Button Delete Element
+ removeButton = factory.createButton(this, "", SWT.PUSH);
+ removeButton.setVisible(true);
+ removeButton.setImage(ImageManager.IMG_DELETE);
+ removeButton.setToolTipText("Delete selected element(s)");
+ data = new FormData();
+ data.top = new FormAttachment(0, 0);
+ data.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
+ removeButton.setLayoutData(data);
+ removeButton.addMouseListener(removeButtonlistener);
+
+ addButton = factory.createButton(this, "", SWT.PUSH);
+ addButton.setVisible(true);
+ addButton.setImage(ImageManager.IMG_ADD);
+ addButton.setToolTipText("Add a new element");
+
+ data = new FormData();
+ data.top = new FormAttachment(0, 0);
+ data.right = new FormAttachment(removeButton, -ITabbedPropertyConstants.HSPACE);
+ addButton.setLayoutData(data);
+ addButton.addMouseListener(addButtonlistener);
+
+ // Button Up
+ upButton = factory.createButton(this, "", SWT.PUSH);
+ upButton.setVisible(true);
+ upButton.setImage(ImageManager.IMG_UP);
+ upButton.setToolTipText("Up");
+
+ data = new FormData();
+ data.top = new FormAttachment(0, 0);
+ data.right = new FormAttachment(addButton, -ITabbedPropertyConstants.HSPACE);
+ upButton.setLayoutData(data);
+ upButton.addMouseListener(upButtonlistener);
+
+
+ // Button Down
+ downButton = factory.createButton(this, "", SWT.PUSH);
+ downButton.setVisible(true);
+ downButton.setImage(ImageManager.IMG_DOWN);
+ downButton.setToolTipText("Down");
+
+ data = new FormData();
+ data.top = new FormAttachment(0, 0);
+ data.right = new FormAttachment(upButton, -ITabbedPropertyConstants.HSPACE);
+ downButton.setLayoutData(data);
+ downButton.addMouseListener(downButtonlistener);
+
+ // Create label
+ label = factory.createCLabel(this, name + ":", SWT.NONE);
+ label.setLayout(new FormLayout());
+ data = new FormData();
+ data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
+ data.right = new FormAttachment(downButton, -ITabbedPropertyConstants.HSPACE - 30);
+ data.top = new FormAttachment(0, 0);
+ label.setLayoutData(data);
+
+ // ///////////////////////////////////////////////////////////////////////////
+ // Create and place Table
+ tree = treeViewer.getTree();
+ tree.setLayout(new FormLayout());
+ tree.setVisible(true);
+ tree.addListener(SWT.MouseDoubleClick, treeListener = new EditItemListener());
+
+ data = new FormData();
+ data.top = new FormAttachment(addButton, ITabbedPropertyConstants.VSPACE);
+ data.left = new FormAttachment(0, ITabbedPropertyConstants.HSPACE);
+ data.right = new FormAttachment(100, -ITabbedPropertyConstants.HSPACE);
+ data.bottom = new FormAttachment(100, -ITabbedPropertyConstants.VSPACE);
+
+ tree.setLayoutData(data);
+
+ // initialize enablement of controls
+ updateEnablement();
+
+ return this;
+ }
+
+ public void refresh() {
+ updateEnablement();
+ }
+
+ protected boolean isEditable() {
+ return (element != null) && !EMFHelper.isReadOnly(element);
+ }
+
+ protected void updateEnablement() {
+ boolean isEditable = isEditable();
+
+ if ((addButton != null) && !addButton.isDisposed()) {
+ addButton.setEnabled(isEditable);
+ removeButton.setEnabled(isEditable);
+ upButton.setEnabled(isEditable);
+ downButton.setEnabled(isEditable);
+ }
+ }
+
+ // /**
+ // * Sets the layout data to the main composite of this complex element
+ // * @param data the new LayoutData
+ // */
+ // public void setLayoutData(Object data) {
+ // composite.setLayoutData(data);
+ // }
+ //
+ // public Composite getMainComposite() {
+ // return composite;
+ // }
+
+ /**
+ * Returns the CommmandStack of the current editor.
+ *
+ * @return the CommmandStack of the current editor
+ */
+ public CommandStack getCommandStack() {
+ if (getActiveEditor() != null) {
+ return (CommandStack) getActiveEditor().getAdapter(CommandStack.class);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the current Editor.
+ *
+ * @return the current editor
+ */
+ public IEditorPart getActiveEditor() {
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ }
+
+ /**
+ * action executed when the add button is pressed.
+ */
+ public void addButtonPressed() {
+ }
+
+ /**
+ * @param pSelection
+ */
+ public void keepSelection(ISelection pSelection) {
+
+ }
+
+ /**
+ * action executed when the remove button is pressed.
+ */
+ public abstract void removeButtonPressed();
+
+ /**
+ * action executed when the up button is pressed.
+ */
+ public abstract void upButtonPressed();
+
+ /**
+ * action executed when the down button is pressed.
+ */
+ public abstract void downButtonPressed();
+
+ /**
+ * action executed when a table item is edited.
+ *
+ * @param item
+ */
+ public abstract void editItem(TreeItem item);
+
+ /**
+ * Listener for the Add Button
+ * Specific behavior is implemented in {@link DecoratedTreeComposite#addButtonPressed()}.
+ *
+ * @author Remi SCHNEKENBURGER
+ */
+ private class AddButtonlistener implements MouseListener {
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseDoubleClick(MouseEvent e) {
+ // do nothing
+ }
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseDown(MouseEvent e) {
+ // do nothing
+ }
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseUp(MouseEvent e) {
+ addButtonPressed();
+ refresh();
+ }
+ }
+
+ /**
+ * Listener for the Remove Button
+ * Specific behavior is implemented in {@link DecoratedTreeComposite#removeButtonPressed()}.
+ *
+ * @author Remi SCHNEKENBURGER
+ */
+ private class RemoveButtonlistener implements MouseListener {
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseDoubleClick(MouseEvent e) {
+ // do nothing
+ }
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseDown(MouseEvent e) {
+ // do nothing
+ }
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseUp(MouseEvent e) {
+ removeButtonPressed();
+ refresh();
+ }
+ }
+
+ /**
+ * Listener for the Up Button
+ * Specific behavior is implemented in {@link DecoratedTreeComposite#upButtonPressed()}.
+ *
+ * @author Remi SCHNEKENBURGER
+ */
+ private class UpButtonlistener implements MouseListener {
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseDoubleClick(MouseEvent e) {
+ // do nothing
+ }
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseDown(MouseEvent e) {
+ // do nothing
+ }
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseUp(MouseEvent e) {
+ ISelection selection = treeViewer.getSelection();
+ upButtonPressed();
+ refresh();
+ // Keep selection
+ keepSelection(selection);
+ }
+ }
+
+ /**
+ * Listener for the Down Button
+ * Specific behavior is implemented in {@link DecoratedTreeComposite#downButtonPressed()}.
+ *
+ * @author Remi SCHNEKENBURGER
+ */
+ private class DownButtonlistener implements MouseListener {
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseDoubleClick(MouseEvent e) {
+ // do nothing
+ }
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseDown(MouseEvent e) {
+ // do nothing
+ }
+
+ /**
+ *
+ *
+ * @param e
+ */
+ public void mouseUp(MouseEvent e) {
+ ISelection vSelection = treeViewer.getSelection();
+
+ downButtonPressed();
+ refresh();
+ // Keep selection
+ keepSelection(vSelection);
+
+ }
+ }
+
+ /**
+ *
+ */
+ private class EditItemListener implements Listener {
+
+ /**
+ *
+ *
+ * @param event
+ */
+ public void handleEvent(Event event) {
+ if (tree.getSelection().length > 0) {
+ TreeItem item = tree.getSelection()[0];
+ editItem(item);
+ }
+ }
+ }
+
+ /**
+ * Dipose listeners.
+ */
+ public void disposeListeners() {
+ if(!getParent().isDisposed()){
+ getParent().removeDisposeListener(this.parentDisposeListener);
+ }
+ if (addButton != null && !addButton.isDisposed()) {
+ addButton.removeMouseListener(addButtonlistener);
+ }
+ if (removeButton != null && !removeButton.isDisposed()) {
+ removeButton.removeMouseListener(removeButtonlistener);
+ }
+ if (upButton != null && !upButton.isDisposed()) {
+ upButton.removeMouseListener(upButtonlistener);
+ }
+ if (downButton != null && !downButton.isDisposed()) {
+ downButton.removeMouseListener(downButtonlistener);
+ }
+ if (tree != null && !tree.isDisposed()) {
+ tree.removeListener(SWT.MouseDoubleClick, treeListener);
+ }
+ }
+
+ /**
+ * DisposeListener used to listen the parent composite
+ */
+ private class LocalDisposeListener implements DisposeListener{
+
+ /**
+ * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
+ *
+ * @param e
+ */
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ dispose();
+ }
+
+ }
+
+ /**
+ * @see org.eclipse.swt.widgets.Widget#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ disposeListeners();
+ super.dispose();
+ }
+}
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/section/AppliedStereotypeSectionWithView.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/section/AppliedStereotypeSectionWithView.java
index 3c8205ca108..663368ea4b5 100644
--- a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/section/AppliedStereotypeSectionWithView.java
+++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/profile/ui/section/AppliedStereotypeSectionWithView.java
@@ -1,158 +1,151 @@
-/*****************************************************************************
- * 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.properties.profile.ui.section;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.widgets.editors.MultipleReferenceEditor;
-import org.eclipse.papyrus.uml.profile.tree.objects.StereotypedElementTreeObject;
-import org.eclipse.papyrus.uml.properties.profile.ui.compositeforview.AppliedStereotypeCompositeWithView;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
-import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
-import org.eclipse.uml2.uml.Element;
-
-/**
- * This section is used to apply stereotype on uml Element.
- */
-public class AppliedStereotypeSectionWithView extends AbstractPropertySection {
-
- /** The stereotype composite. */
- private AppliedStereotypeCompositeWithView appliedStereotypeComposite;
- private MultipleReferenceEditor editor;
-
- /** The property composite. */
- // private AppliedStereotypePropertyCompositeWithView propertyComposite;
-
- /**
- * Creates the controls.
- *
- * @param tabbedPropertySheetPage
- * the tabbed property sheet page
- * @param parent
- * the parent
- */
- @Override
- public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
- super.createControls(parent, tabbedPropertySheetPage);
- appliedStereotypeComposite = new AppliedStereotypeCompositeWithView(parent);
- appliedStereotypeComposite.createContent(parent, getWidgetFactory());
-
- editor = new MultipleReferenceEditor(parent, 0);
- // propertyComposite = new AppliedStereotypePropertyCompositeWithView(parent, appliedStereotypeComposite);
- // propertyComposite.createContent(parent, getWidgetFactory());
-
- // appliedStereotypeComposite.setPropertyComposite(propertyComposite);
- }
-
- /**
- * Refresh.
- */
- @Override
- public void refresh() {
- appliedStereotypeComposite.refresh();
- editor.refreshValue();
- }
-
- /**
- * Should use extra space.
- *
- * @return true, if successful
- */
- @Override
- public boolean shouldUseExtraSpace() {
- return true;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void setInput(IWorkbenchPart part, ISelection selection) {
- super.setInput(part, selection);
- if (selection instanceof IStructuredSelection) {
- Object input = ((IStructuredSelection) selection).getFirstElement();
-
- if (input instanceof GraphicalEditPart && ((GraphicalEditPart) input).getModel() instanceof View) {
- GraphicalEditPart graphicalEditPart = (GraphicalEditPart) input;
- View view = (View) graphicalEditPart.getModel();
- Element UMLElement = (Element) view.getElement();
- if (UMLElement != null) {
- appliedStereotypeComposite.setDiagramElement(view);
- // propertyComposite.setDiagramElement(view);
- appliedStereotypeComposite.setElement(UMLElement);
- appliedStereotypeComposite.setInput(new StereotypedElementTreeObject(UMLElement));
- }
- }
- else {
- EObject eobject = resolveSemanticObject(input);
-
- if (eobject instanceof Element) {
- Element UMLElement = (Element) eobject;
- appliedStereotypeComposite.setDiagramElement(null);
- appliedStereotypeComposite.setElement(UMLElement);
- appliedStereotypeComposite.setInput(new StereotypedElementTreeObject(UMLElement));
- }
- }
-
- }
- }
-
- /**
- * Resolve semantic element
- *
- * @param object
- * the object to resolve
- * @return <code>null</code> or the semantic element associated to the specified object
- */
- private EObject resolveSemanticObject(Object object) {
- if (object instanceof EObject) {
- return (EObject) object;
- } else if (object instanceof IAdaptable) {
- IAdaptable adaptable = (IAdaptable) object;
- if (EMFHelper.getEObject(adaptable) != null) {
- return EMFHelper.getEObject(adaptable);
- }
- }
- return null;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see com.cea.papyrus.core.ui.properties.tabbed.PropertyViewSection#dispose()
- */
- /**
- * Dispose.
- */
- @Override
- public void dispose() {
- super.dispose();
- if (appliedStereotypeComposite != null)
- {
- appliedStereotypeComposite.disposeListeners();
- // if(propertyComposite != null)
- // propertyComposite.disposeListeners();
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008, 2017 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
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Bug 522564
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.properties.profile.ui.section;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.widgets.editors.MultipleReferenceEditor;
+import org.eclipse.papyrus.uml.profile.tree.objects.StereotypedElementTreeObject;
+import org.eclipse.papyrus.uml.properties.profile.ui.compositeforview.AppliedStereotypeCompositeWithView;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+import org.eclipse.uml2.uml.Element;
+
+/**
+ * This section is used to apply stereotype on uml Element.
+ */
+public class AppliedStereotypeSectionWithView extends AbstractPropertySection {
+
+ /** The stereotype composite. */
+ private AppliedStereotypeCompositeWithView appliedStereotypeComposite;
+ private MultipleReferenceEditor editor;
+
+ /** The property composite. */
+ // private AppliedStereotypePropertyCompositeWithView propertyComposite;
+
+ /**
+ * Creates the controls.
+ *
+ * @param tabbedPropertySheetPage
+ * the tabbed property sheet page
+ * @param parent
+ * the parent
+ */
+ @Override
+ public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
+ super.createControls(parent, tabbedPropertySheetPage);
+ appliedStereotypeComposite = new AppliedStereotypeCompositeWithView(parent);
+ appliedStereotypeComposite.createContent(parent, getWidgetFactory());
+
+ editor = new MultipleReferenceEditor(parent, 0);
+ // propertyComposite = new AppliedStereotypePropertyCompositeWithView(parent, appliedStereotypeComposite);
+ // propertyComposite.createContent(parent, getWidgetFactory());
+
+ // appliedStereotypeComposite.setPropertyComposite(propertyComposite);
+ }
+
+ /**
+ * Refresh.
+ */
+ @Override
+ public void refresh() {
+ appliedStereotypeComposite.refresh();
+ editor.refreshValue();
+ }
+
+ /**
+ * Should use extra space.
+ *
+ * @return true, if successful
+ */
+ @Override
+ public boolean shouldUseExtraSpace() {
+ return true;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void setInput(IWorkbenchPart part, ISelection selection) {
+ super.setInput(part, selection);
+ if (selection instanceof IStructuredSelection) {
+ Object input = ((IStructuredSelection) selection).getFirstElement();
+
+ if (input instanceof GraphicalEditPart && ((GraphicalEditPart) input).getModel() instanceof View) {
+ GraphicalEditPart graphicalEditPart = (GraphicalEditPart) input;
+ View view = (View) graphicalEditPart.getModel();
+ Element UMLElement = (Element) view.getElement();
+ if (UMLElement != null) {
+ appliedStereotypeComposite.setDiagramElement(view);
+ // propertyComposite.setDiagramElement(view);
+ appliedStereotypeComposite.setElement(UMLElement);
+ appliedStereotypeComposite.setInput(new StereotypedElementTreeObject(UMLElement));
+ }
+ } else {
+ EObject eobject = resolveSemanticObject(input);
+
+ if (eobject instanceof Element) {
+ Element UMLElement = (Element) eobject;
+ appliedStereotypeComposite.setDiagramElement(null);
+ appliedStereotypeComposite.setElement(UMLElement);
+ appliedStereotypeComposite.setInput(new StereotypedElementTreeObject(UMLElement));
+ }
+ }
+
+ }
+ }
+
+ /**
+ * Resolve semantic element
+ *
+ * @param object
+ * the object to resolve
+ * @return <code>null</code> or the semantic element associated to the specified object
+ */
+ private EObject resolveSemanticObject(Object object) {
+ if (object instanceof EObject) {
+ return (EObject) object;
+ } else if (object instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable) object;
+ if (EMFHelper.getEObject(adaptable) != null) {
+ return EMFHelper.getEObject(adaptable);
+ }
+ }
+ return null;
+ }
+
+
+ /**
+ * @Override
+ * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+ if (appliedStereotypeComposite != null) {
+ appliedStereotypeComposite.dispose();
+ }
+ }
+}

Back to the top