Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrschnekenbu2012-01-11 09:04:10 +0000
committerrschnekenbu2012-01-11 09:04:10 +0000
commit36df7d20cd96f79048539152ef65ce6cfcd4bb03 (patch)
treefd51c5c48913c98449e57b80984425eb0287d86d /plugins
parentd50cf865f37c904f8ec700978062fb84375eb0ef (diff)
downloadorg.eclipse.papyrus-36df7d20cd96f79048539152ef65ce6cfcd4bb03.tar.gz
org.eclipse.papyrus-36df7d20cd96f79048539152ef65ce6cfcd4bb03.tar.xz
org.eclipse.papyrus-36df7d20cd96f79048539152ef65ce6cfcd4bb03.zip
ASSIGNED - bug 363506: [SysML Block Definition Diagram] Confusion in management of properties (and derivatives) in show/hide content dialog
https://bugs.eclipse.org/bugs/show_bug.cgi?id=363506 - push bug fixes made on branch 0.8.X r6851
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ShowHideRelatedContentsAction.java97
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/AbstractShowHideAction.java338
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/ShowHideContentsAction.java871
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/handlers/AbstractShowHideHandler.java12
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CustomCheckedTreeSelectionDialog.java15
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/CompartmentUtils.java28
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ShowHideRelatedContentsAction.java121
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ShowHideRelatedContentsAction.java98
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/custom-src/org/eclipse/papyrus/uml/diagram/deployment/custom/actions/ShowHideRelatedContentsAction.java116
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/actions/ShowHideCompartmentAction.java440
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/dialogs/ShowHideCompartmentSelectionDialog.java330
11 files changed, 1509 insertions, 957 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ShowHideRelatedContentsAction.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ShowHideRelatedContentsAction.java
index 644443fa149..abb4000c785 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ShowHideRelatedContentsAction.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/handler/ShowHideRelatedContentsAction.java
@@ -13,20 +13,13 @@
*****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.internalblock.handler;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.sysml.diagram.internalblock.messages.Messages;
-import org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction;
import org.eclipse.papyrus.uml.diagram.common.actions.ShowHideContentsAction;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideRelatedContentsEditPolicy;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
+import org.eclipse.papyrus.sysml.diagram.internalblock.messages.Messages;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
public class ShowHideRelatedContentsAction extends ShowHideContentsAction {
@@ -36,53 +29,63 @@ public class ShowHideRelatedContentsAction extends ShowHideContentsAction {
}
/**
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#initAction()
+ * @see org.eclipse.papyrus.diagram.common.actions.AbstractShowHideAction#initAction()
*/
@Override
protected void initAction() {
super.initAction();
- setEditorLabelProvider(new UMLLabelProvider());
- this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
- for(EditPart current : this.selectedElements) {
- //the selected elements which aren't Classifier are ignored
- EObject element = ((View)current.getModel()).getElement();
- if(element instanceof Property) {
- Type type = ((Property)element).getType();
- if(type instanceof Classifier) {
- this.representations.add(new CustomEditPartRepresentation(current, (Classifier)type));
+ for(IGraphicalEditPart current : this.selectedElements) {
+ // the selected elements which aren't Classifier are ignored
+ if(((View)current.getModel()).getElement() instanceof Property) {
+ Property property = (Property)((View)current.getModel()).getElement();
+ if(property.getType() instanceof Classifier) {
+ this.representations.add(new RootEditPartRepresentation(current, (Classifier)property.getType()));
}
}
}
- this.setEditorLabelProvider(new CustomEditorLabelProvider());
- this.setContentProvider(new CustomContentProvider());
+ // setEditorLabelProvider(new EditorLabelProvider());
+ // this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
+ //
+ // for(EditPart current : this.selectedElements) {
+ // //the selected elements which aren't Classifier are ignored
+ // EObject element = ((View)current.getModel()).getElement();
+ // if(element instanceof Property) {
+ // Type type = ((Property)element).getType();
+ // if(type instanceof Classifier) {
+ // this.representations.add(new CustomEditPartRepresentation(current, (Classifier)type));
+ // }
+ // }
+ // }
+ // this.setEditorLabelProvider(new CustomEditorLabelProvider());
+ // this.setContentProvider(new CustomContentProvider());
}
- protected class CustomContentProvider extends ShowHideContentsAction.ContentProvider {
-
- /**
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public Object getParent(Object element) {
- if(!(element instanceof EditPartRepresentation)) {
- EditPartRepresentation rep = findEditPartRepresentation(element);
- if(rep != null) {
- //element can be owned by the class (rep), or by a superclass (ClassifierRepresentation)
- List<ClassifierRepresentation> classes = ((CustomEditPartRepresentation)rep).getSuperClasses();
- for(ClassifierRepresentation classifierRepresentation : classes) {
- if(classifierRepresentation.getRepresentedClassifier().getOwnedMembers().contains(element)) {
- return classifierRepresentation;
- }
- }
- }
- return rep;
- }
- return null;
- }
- }
+ // protected class CustomContentProvider extends ShowHideContentsAction.ContentProvider {
+ //
+ // /**
+ // * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ // *
+ // * @param element
+ // * @return
+ // */
+ // @Override
+ // public Object getParent(Object element) {
+ // if(!(element instanceof EditPartRepresentation)) {
+ // EditPartRepresentation rep = findEditPartRepresentation(element);
+ // if(rep != null) {
+ // //element can be owned by the class (rep), or by a superclass (ClassifierRepresentation)
+ // List<ClassifierRepresentation> classes = ((CustomEditPartRepresentation)rep).getSuperClasses();
+ // for(ClassifierRepresentation classifierRepresentation : classes) {
+ // if(classifierRepresentation.getRepresentedClassifier().getOwnedMembers().contains(element)) {
+ // return classifierRepresentation;
+ // }
+ // }
+ // }
+ // return rep;
+ // }
+ // return null;
+ // }
+ // }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/AbstractShowHideAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/AbstractShowHideAction.java
index 70eacaab215..a05a7a9850c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/AbstractShowHideAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/AbstractShowHideAction.java
@@ -17,6 +17,7 @@ package org.eclipse.papyrus.uml.diagram.common.actions;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
@@ -28,18 +29,19 @@ import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.papyrus.commands.wrappers.GEFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.emf.providers.EMFLabelProvider;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.util.ViewServiceUtil;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
import org.eclipse.ui.dialogs.SelectionDialog;
-import org.eclipse.uml2.uml.Element;
/**
*
@@ -49,7 +51,7 @@ import org.eclipse.uml2.uml.Element;
public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbenchWindowActionDelegate {
/** the selected elements */
- protected List<EditPart> selectedElements;
+ protected List<IGraphicalEditPart> selectedElements;
/** the initial selection */
protected List<Object> initialSelection;
@@ -70,14 +72,12 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
private ITreeContentProvider contentProvider = null;
/** the list of the views to destroy */
- protected List<Object> viewsToDestroy;
+ protected List<EditPartRepresentation> viewsToDestroy;
/** the list of the view to create */
- protected List<Object> viewsToCreate;
+ protected List<EditPartRepresentation> viewsToCreate;
- /**
- * the list of the {@link EditPartRepresentation}
- */
+ /** the list of the {@link EditPartRepresentation} */
protected List<EditPartRepresentation> representations;
/**
@@ -100,31 +100,21 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
}
/**
- *
- * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
- *
+ * {@inheritDoc}
*/
public void dispose() {
- // TODO Auto-generated method stub
-
+ // nothing here
}
/**
- *
- * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
- *
- * @param window
+ * {@inheritDoc}
*/
public void init(IWorkbenchWindow window) {
- // TODO Auto-generated method stub
-
+ // nothing here
}
/**
- *
- * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
- *
- * @param action
+ * {@inheritDoc}
*/
public void run(IAction action) {
@@ -138,7 +128,7 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
if(selectionDialog.getReturnCode() == Dialog.OK) {
buildShowHideElementsList(selectionDialog.getResult());
final Command command = getActionCommand();
- final TransactionalEditingDomain domain = ((IGraphicalEditPart)this.selectedElements.get(0)).getEditingDomain();
+ final TransactionalEditingDomain domain = this.selectedElements.get(0).getEditingDomain();
if(command.canExecute()) {
try {
domain.runExclusive(new Runnable() {
@@ -160,18 +150,37 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
}
}
+ /**
+ * Creates and returns the selection dialog displayed by this action
+ *
+ * @return the created selection dialog
+ */
protected SelectionDialog getSelectionDialog() {
- CheckedTreeSelectionDialog selectionDialog = new CheckedTreeSelectionDialog(DisplayUtils.getDisplay().getActiveShell(), labelProvider, contentProvider);
+ CheckedTreeSelectionDialog selectionDialog = new CheckedTreeSelectionDialog(DisplayUtils.getDisplay().getActiveShell(), getEditorLabelProvider(), getContentProvider());
selectionDialog.setTitle(title);
selectionDialog.setMessage(message);
selectionDialog.setContainerMode(true);
selectionDialog.setInput(getInput());
- selectionDialog.setExpandedElements(getInput().toArray());
- selectionDialog.setInitialElementSelections(this.initialSelection);
+ selectionDialog.setExpandedElements(getExpandedElements());
+ selectionDialog.setInitialElementSelections(getInitialSelection());
return selectionDialog;
}
/**
+ * Returns the list of all elements
+ *
+ * @return the list of all elements
+ */
+ protected Object[] getExpandedElements() {
+ List<Object> allElements = new ArrayList<Object>();
+ for(EditPartRepresentation current : this.representations) {
+ allElements.add(current);
+ allElements.addAll(current.getPossibleElement());
+ }
+ return allElements.toArray();
+ }
+
+ /**
*
* Test if the action can be run! Useful when we press F4 and it's the first
* action in Papyrus
@@ -209,12 +218,12 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
public void selectionChanged(IAction action, ISelection selection) {
boolean enabled = false;
if(editPolicyKey != null) {
- selectedElements = new ArrayList<EditPart>();
+ selectedElements = new ArrayList<IGraphicalEditPart>();
if(selection instanceof StructuredSelection) {
for(Object current : ((StructuredSelection)selection).toArray()) {
- if(current instanceof EditPart) {
- selectedElements.add((EditPart)current);
- EditPolicy policy = ((EditPart)current).getEditPolicy(editPolicyKey);
+ if(current instanceof IGraphicalEditPart) {
+ selectedElements.add((IGraphicalEditPart)current);
+ EditPolicy policy = ((IGraphicalEditPart)current).getEditPolicy(editPolicyKey);
if(policy != null) {
enabled = true;
break;
@@ -240,7 +249,7 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
*
*/
protected void initAction() {
- this.labelProvider = new UMLLabelProvider();
+ this.labelProvider = new EditPartRepresentationLabelProvider();
this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
}
@@ -260,7 +269,25 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
protected void buildInitialSelection() {
this.initialSelection = new ArrayList<Object>();
for(EditPartRepresentation current : this.representations) {
- initialSelection.addAll(current.getInitialSelection());
+ contributeToInitialSelection(initialSelection, current);
+ }
+ }
+
+ /**
+ * Complete the list of initial selection for the given representation and its potential children
+ *
+ * @param listToComplete
+ * the list of selected elements to complete
+ * @param representation
+ * the edit part representation that completes the list
+ */
+ protected void contributeToInitialSelection(List<Object> listToComplete, EditPartRepresentation representation) {
+ listToComplete.addAll(representation.getInitialSelection());
+ List<EditPartRepresentation> children = representation.getPossibleElement();
+ if(children != null) {
+ for(EditPartRepresentation child : children) {
+ contributeToInitialSelection(listToComplete, child);
+ }
}
}
@@ -283,8 +310,8 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
* the interesting element selected in the tree
*/
protected void buildShowHideElementsList(Object[] result) {
- this.viewsToCreate = new ArrayList<Object>();
- this.viewsToDestroy = new ArrayList<Object>();
+ this.viewsToCreate = new ArrayList<EditPartRepresentation>();
+ this.viewsToDestroy = new ArrayList<EditPartRepresentation>();
}
/**
@@ -294,11 +321,26 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
*/
abstract protected Command getActionCommand();
+ /**
+ * Setter for {@link #labelProvider}
+ *
+ * @param provider
+ * the label provider for the tree
+ */
protected void setEditorLabelProvider(ILabelProvider provider) {
this.labelProvider = provider;
}
/**
+ * Returns the label provider used by the dialog
+ *
+ * @return the labelProvider
+ */
+ protected ILabelProvider getEditorLabelProvider() {
+ return labelProvider;
+ }
+
+ /**
* Setter for {@link #contentProvider}
*
* @param provider
@@ -309,6 +351,15 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
}
/**
+ * Returns the content provider for the selection dialog
+ *
+ * @return the contentProvider
+ */
+ protected ITreeContentProvider getContentProvider() {
+ return contentProvider;
+ }
+
+ /**
* Setter for {@link #selectedElements}. When this action is called by a
* popup menu, {@link #selectedElements} is filled by {@link #selectionChanged(IAction, ISelection)} When this action is called
* by a Handler, {@link #selectedElements} is filled with this method
@@ -316,7 +367,7 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
* @param selection
* the current selection
*/
- public void setSelection(List<EditPart> selection) {
+ public void setSelection(List<IGraphicalEditPart> selection) {
this.selectedElements = selection;
}
@@ -339,16 +390,31 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
protected class EditPartRepresentation {
/** the editpart represented by this class */
- protected EditPart representedEditPart;
+ private IGraphicalEditPart representedEditPart;
/** the initial selection */
- protected List<Object> initialSelection;
+ protected List<EditPartRepresentation> initialSelection;
/** the possible element to show/hide */
- protected List<Object> elementsToSelect;
+ protected List<EditPartRepresentation> elementsToSelect;
+
+ /** the semantic element represented by the EditPart */
+ protected EObject eObject;
- /** the UML element represented by the EditPart */
- protected Element UMLElement;
+ /** parent edit part representation */
+ final private EditPartRepresentation parentRepresentation;
+
+ /**
+ * Constructor.
+ *
+ * @param representedEditPart
+ * the represented EditPart
+ * @param eObject
+ * the semantic element represented by EditPartRepresentation
+ */
+ public EditPartRepresentation(IGraphicalEditPart representedEditPart, EObject eObject) {
+ this(representedEditPart, eObject, null);
+ }
/**
*
@@ -356,12 +422,15 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
*
* @param representedEditPart
* the represented EditPart
- * @param umlElement
- * the UMLElement represented by EditPartRepresentation
+ * @param eObject
+ * the semantic element represented by EditPartRepresentation
+ * @param parentRepresentation
+ * parent representation of this edit part representation
*/
- public EditPartRepresentation(EditPart representedEditPart, Element umlElement) {
- this.representedEditPart = representedEditPart;
- this.UMLElement = umlElement;
+ public EditPartRepresentation(IGraphicalEditPart representedEditPart, EObject eObject, EditPartRepresentation parentRepresentation) {
+ this.setRepresentedEditPart(representedEditPart);
+ this.eObject = eObject;
+ this.parentRepresentation = parentRepresentation;
initRepresentation();
}
@@ -370,17 +439,17 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
*
* @return the represented editpart, {@link #representedEditPart}
*/
- public EditPart getRepresentedEditPart() {
+ public IGraphicalEditPart getRepresentedEditPart() {
return this.representedEditPart;
}
/**
- * Getter for {@link #UMLElement}
+ * Getter for {@link #eObject}
*
- * @return {@link #UMLElement}
+ * @return {@link #eObject}
*/
- public Element getUMLElement() {
- return this.UMLElement;
+ public EObject getSemanticElement() {
+ return this.eObject;
}
/**
@@ -388,7 +457,7 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
*
* @return {@link #initialSelection}
*/
- public List<Object> getInitialSelection() {
+ public List<EditPartRepresentation> getInitialSelection() {
return this.initialSelection;
}
@@ -400,8 +469,8 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
* </ul>
*/
protected void initRepresentation() {
- this.initialSelection = new ArrayList<Object>();
- this.elementsToSelect = new ArrayList<Object>();
+ this.initialSelection = new ArrayList<EditPartRepresentation>();
+ this.elementsToSelect = new ArrayList<EditPartRepresentation>();
}
/**
@@ -409,8 +478,167 @@ public abstract class AbstractShowHideAction implements IActionDelegate, IWorkbe
*
* @return {@link #elementsToSelect}
*/
- public List<Object> getPossibleElement() {
+ public List<EditPartRepresentation> getPossibleElement() {
return this.elementsToSelect;
}
+
+ /**
+ * Returns the parent representation of this edit part representation
+ *
+ * @return the parent representation of this edit part representation
+ */
+ public EditPartRepresentation getParentRepresentation() {
+ return parentRepresentation;
+ }
+
+ /**
+ * Setter for the {@link #representedEditPart}
+ *
+ * @param representedEditPart
+ * {@link #representedEditPart}
+ */
+ public void setRepresentedEditPart(IGraphicalEditPart representedEditPart) {
+ this.representedEditPart = representedEditPart;
+ }
+
+ /**
+ * Returns the display label for this edit part representation
+ *
+ * @return the display label for this edit part representation
+ */
+ public String getLabel() {
+ EObject semanticElement = getSemanticElement();
+ if(isElementInherited()) {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(getEditorLabelProvider().getText(getSemanticElement()));
+ buffer.append(" ");
+ buffer.append("(from ");
+ buffer.append(getEditorLabelProvider().getText(getSemanticElement().eContainer()));
+ buffer.append(")");
+ return buffer.toString();
+ }
+ return getEditorLabelProvider().getText(semanticElement);
+ }
+
+ /**
+ * Returns the display label for this edit part representation
+ *
+ * @return the display label for this edit part representation
+ */
+ public Image getImage() {
+ return getEditorLabelProvider().getImage(getSemanticElement());
+ }
+
+ /**
+ * Checks if the parent of the element linked to the given edit part representation is similar to the element of the parent representation
+ *
+ * @param representation
+ * the edit part representation to check
+ * @return <code>true</code> if the element is inherited
+ */
+ protected boolean isElementInherited() {
+ EditPartRepresentation parentRepresentation = getParentRepresentation();
+ if(parentRepresentation == null) { // no parent => can not be inherited
+ return false;
+ }
+
+ // no uml element in representation, can not check
+ if(getSemanticElement() == null) {
+ return false;
+ }
+
+ EObject parentElement = parentRepresentation.getSemanticElement();
+ EObject elementOwner = getSemanticElement().eContainer(); // Null for rer.getUMLElement was already check before.
+ if(parentElement == null || elementOwner == null) { // no element in the parent representation
+ return false;
+ }
+
+ if(!parentElement.equals(elementOwner)) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * label provider that delegates to the edit part representation the label
+ */
+ protected class EditPartRepresentationLabelProvider extends LabelProvider {
+
+ /** editor label provider */
+ protected EMFLabelProvider editorLabelProvider;
+
+ /**
+ * Constructor.
+ */
+ public EditPartRepresentationLabelProvider() {
+ this.editorLabelProvider = new EMFLabelProvider();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getText(Object element) {
+ if(element instanceof EditPartRepresentation) {
+ return ((EditPartRepresentation)element).getLabel();
+ }
+ return editorLabelProvider.getText(element);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Image getImage(Object element) {
+ if(element instanceof EditPartRepresentation) {
+ return ((EditPartRepresentation)element).getImage();
+ }
+ return editorLabelProvider.getImage(element);
+ }
}
+
+ // /**
+ // *
+ // * EditorLabelProvider for the {@link CheckedTreeSelectionDialog}
+ // *
+ // */
+ // public class CustomEditorLabelProvider extends EditorLabelProvider {
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public Image getImage(Object element) {
+ // if(element instanceof EditPartRepresentation) {
+ // element = ((EditPartRepresentation)element).getSemanticElement();
+ // }
+ // return super.getImage(element);
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public String getText(Object element) {
+ // if(element instanceof CompartmentEditPartRepresentation) {
+ // return ((CompartmentEditPartRepresentation)element).getCompartmentName();
+ // } else if(element instanceof EditPartRepresentation) {
+ // EObject semanticElement = ((EditPartRepresentation)element).getSemanticElement();
+ // if(isElementInherited((EditPartRepresentation)element)) {
+ // StringBuffer buffer = new StringBuffer();
+ // buffer.append(super.getText(semanticElement));
+ // buffer.append(" ");
+ // buffer.append("(from ");
+ // buffer.append(super.getText(((EditPartRepresentation)element).getSemanticElement().eContainer()));
+ // buffer.append(")");
+ // return buffer.toString();
+ // } else {
+ // return super.getText(semanticElement);
+ // }
+ // }
+ // return super.getText(element);
+ // }
+ // }
+
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/ShowHideContentsAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/ShowHideContentsAction.java
index b6bfa6c1490..e0b9520a084 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/ShowHideContentsAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/ShowHideContentsAction.java
@@ -16,7 +16,6 @@ package org.eclipse.papyrus.uml.diagram.common.actions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
-import java.util.Iterator;
import java.util.List;
import org.eclipse.draw2d.geometry.Point;
@@ -31,6 +30,7 @@ import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.commands.CreateCommand;
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IResizableCompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
@@ -45,15 +45,15 @@ import org.eclipse.jface.viewers.Viewer;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.Messages;
import org.eclipse.papyrus.uml.diagram.common.commands.ShowHideElementsRequest;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.AffixedNodeAlignmentEditPolicy;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideClassifierContentsEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.util.CompartmentUtils;
import org.eclipse.papyrus.uml.diagram.common.util.Util;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IActionDelegate;
-import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.dialogs.CheckedTreeSelectionDialog;
import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.Type;
@@ -65,19 +65,11 @@ import org.eclipse.uml2.uml.Type;
*/
public class ShowHideContentsAction extends AbstractShowHideAction implements IActionDelegate, IWorkbenchWindowActionDelegate {
- /** title for the dialog */
- private final static String title = Messages.ShowHideContentsAction_Title;
-
- /** title for the message */
- private final static String message = Messages.ShowHideContentsAction_Message;
-
- /** increment for the location of the elements to show(ports and properties) */
- private int increment = 10;
+ /** INCREMENT for the location of the elements to show(ports and properties) */
+ private static int INCREMENT = 10;
/**
- *
* Constructor.
- *
*/
public ShowHideContentsAction() {
this(Messages.ShowHideContentsAction_Title, Messages.ShowHideContentsAction_Message, ShowHideClassifierContentsEditPolicy.SHOW_HIDE_CLASSIFIER_CONTENTS_POLICY);
@@ -99,48 +91,7 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
}
/**
- *
- * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
- *
- */
- @Override
- public void dispose() {
- // TODO Auto-generated method stub
- }
-
- /**
- *
- * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
- *
- * @param window
- */
- @Override
- public void init(IWorkbenchWindow window) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- *
- * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
- *
- * @param action
- */
- @Override
- public void run(IAction action) {
- super.run(action);
- }
-
- /**
- * We can use the show/hide contents action, only if there 1 selected object
- *
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#selectionChanged(org.eclipse.jface.action.IAction,
- * org.eclipse.jface.viewers.ISelection)
- *
- * @param action
- * the current action
- * @param selection
- * the current selection
+ * {@inheritDoc}
*/
@Override
public void selectionChanged(IAction action, ISelection selection) {
@@ -154,44 +105,33 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
}
/**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#initAction()
- *
+ * {@inheritDoc}
*/
@Override
protected void initAction() {
super.initAction();
- for(EditPart current : this.selectedElements) {
+ for(IGraphicalEditPart current : this.selectedElements) {
// the selected elements which aren't Classifier are ignored
if(((View)current.getModel()).getElement() instanceof Classifier) {
- this.representations.add(new CustomEditPartRepresentation(current, (Classifier)((View)current.getModel()).getElement()));
+ this.representations.add(new RootEditPartRepresentation(current, (Classifier)((View)current.getModel()).getElement()));
}
}
- this.setEditorLabelProvider(new CustomEditorLabelProvider());
+ // this.setEditorLabelProvider(new CustomEditorLabelProvider());
this.setContentProvider(new ContentProvider());
}
/**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#getInput()
- *
- * @return
+ * {@inheritDoc}
*/
@Override
protected List<Object> getInput() {
List<Object> list = new ArrayList<Object>();
list.addAll(representations);
- for(EditPartRepresentation current : representations) {
- list.addAll(((CustomEditPartRepresentation)current).getSuperClasses());
- }
return list;
}
/**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#getActionCommand()
- *
- * @return
+ * {@inheritDoc}
*/
@Override
protected Command getActionCommand() {
@@ -202,8 +142,8 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
/*
* the command to hide elements we need the corresponding editpart
*/
- for(Object current : this.viewsToDestroy) {
- EditPart ep = findEditPart(current);
+ for(EditPartRepresentation current : this.viewsToDestroy) {
+ EditPart ep = current.getRepresentedEditPart(); // should not be null, because EP to destroy really exists
if(ep != null) {
req = new ShowHideElementsRequest(ep);
EditPart parent = ep.getParent();
@@ -214,44 +154,43 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
if(cmd != null && cmd.canExecute()) {
completeCmd.add(cmd);
}
+ } else {
+ Activator.log.error("the edit part for this representation " + current + " should not be null", null);
}
}
// the command to show element
Point propertyLocation = new Point();
- Point portLocation = new Point(-10, -2 * increment + 1);
- for(Object current : this.viewsToCreate) {
- EditPartRepresentation rep = findEditPartRepresentation(current);
- if(rep == null) {
+ Point portLocation = new Point(-10, -2 * INCREMENT + 1);
+ for(EditPartRepresentation rep : this.viewsToCreate) {
+ if(!(rep instanceof OptionalEditPartRepresentation)) {
continue;
}
- EditPart ep = findEditPartRepresentation(current).getRepresentedEditPart();
- if(ep != null) {
- View compartment = getCompartmentForCreation(ep, (EObject)current);
- if(compartment != null) {
- req = new ShowHideElementsRequest(compartment, (EObject)current);
- if(isXYLayout(compartment, ep)) {
- propertyLocation.x += increment;
- propertyLocation.y += increment;
+ EditPart ep = ((OptionalEditPartRepresentation)rep).getParentRepresentation().getParentRepresentation().getRepresentedEditPart();
+ View compartmentView = ((OptionalEditPartRepresentation)rep).getParentRepresentation().getRepresentedEditPart().getNotationView();
+ if(compartmentView != null) {
+ req = new ShowHideElementsRequest(compartmentView, ((OptionalEditPartRepresentation)rep).getSemanticElement());
+ if(isXYLayout(compartmentView, ep)) {
+ propertyLocation.x += INCREMENT;
+ propertyLocation.y += INCREMENT;
req.setLocation(new Point(propertyLocation));
- } else if(isAffixedChildNode(ep, (EObject)current)) {
- portLocation.y += increment;
+ } else if(isAffixedChildNode(ep, ((OptionalEditPartRepresentation)rep).getSemanticElement())) {
+ portLocation.y += INCREMENT;
req.setLocation(new Point(portLocation));
}
Command cmd = ep.getCommand(req);
if(cmd != null && cmd.canExecute()) {
completeCmd.add(cmd);
}
- }
}
}
return completeCmd;
}
/**
- * Test if the child is represented by an affixed child node TODO This
- * method will not work if we have an UML element E1 which inherits from
+ * Test if the child is represented by an affixed child node
+ * TODO This method will not work if we have an UML element E1 which inherits from
* another element E2 and if E2 is represented by an affixed child node and
* not E1!
*
@@ -360,45 +299,44 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
return null;
}
- /**
- * Return the EditPart owning the Object or <code>null</code>
- *
- * @param obj
- * @return the EditPart owning the Object or <code>null</code>
- */
- protected EditPart findEditPart(Object obj) {
- EditPart ep = null;
- Iterator<EditPartRepresentation> it = representations.iterator();
- while(ep == null && it.hasNext()) {
- List<EditPart> children = getChildrenEditPart(it.next().getRepresentedEditPart());
- for(EditPart editPart : children) {
- if(((View)editPart.getModel()).getElement() == obj) {
- return editPart;
- }
- }
- }
- return null;
- }
+ // /**
+ // * Return the EditPart owning the Object or <code>null</code>
+ // *
+ // * @param obj
+ // * @return the EditPart owning the Object or <code>null</code>
+ // */
+ // protected EditPart findEditPart(EditPartRepresentation obj) {
+ // EditPart ep = null;
+ // EditPart parentEditPart = obj.getParentRepresentation().getRepresentedEditPart();
+ // for(Object child : parentEditPart.getChildren()) {
+ // EditPart child = (EditPart)child;
+ // }
+ //
+ // Iterator<EditPartRepresentation> it = representations.iterator();
+ //
+ // while(ep == null && it.hasNext()) {
+ // List<EditPart> children = getChildrenEditPart(it.next().getRepresentedEditPart());
+ // for(EditPart editPart : children) {
+ // if(((View)editPart.getModel()).getElement() == obj) {
+ // return editPart;
+ // }
+ // }
+ // }
+ // return null;
+ // }
/**
- * Fill the following fields :
- * <ul>
- * <li> {@link AbstractShowHideAction#viewsToDestroy}</li>
- * <li> {@link AbstractShowHideAction#viewsToCreate}</li>
- * </ul>
- *
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#buildShowHideElementsList(java.lang.Object[])
- *
- * @param results
+ * {@inheritDoc}
*/
@Override
protected void buildShowHideElementsList(Object[] results) {
super.buildShowHideElementsList(results);
+
List<Object> result = new ArrayList<Object>();
// we remove the EditPartRepresentation from the result
for(int i = 0; i < results.length; i++) {
- if((results[i] instanceof EditPartRepresentation) || (results[i] instanceof ClassifierRepresentation)) {
+ if((results[i] instanceof RootEditPartRepresentation || results[i] instanceof CompartmentEditPartRepresentation)) {
continue;
} else {
result.add(results[i]);
@@ -410,15 +348,15 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
if(initialSelection.contains(element)) {
// we do nothing
continue;
- } else {
- viewsToCreate.add(element);
+ } else if(element instanceof EditPartRepresentation) {
+ viewsToCreate.add((EditPartRepresentation)element);
}
}
// we are looking for the view to destroy
for(Object current : this.initialSelection) {
- if(!result.contains(current)) {
- viewsToDestroy.add(current);
+ if(!result.contains(current) && current instanceof EditPartRepresentation) {
+ viewsToDestroy.add((EditPartRepresentation)current);
}
}
}
@@ -435,7 +373,7 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
if(current.getPossibleElement().contains(element)) {
return current;
} else {
- EList<?> views = ((IGraphicalEditPart)current.getRepresentedEditPart()).getNotationView().getChildren();
+ EList<?> views = current.getRepresentedEditPart().getNotationView().getChildren();
if(views.contains(element)) {
return current;
}
@@ -444,57 +382,12 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
return null;
}
- /**
- *
- * EditorLabelProvider for the {@link CheckedTreeSelectionDialog}
- *
- */
- public class CustomEditorLabelProvider extends UMLLabelProvider {
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getImage(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public Image getImage(Object element) {
- if(element instanceof EditPartRepresentation) {
- element = ((EditPartRepresentation)element).getUMLElement();
- } else if(element instanceof ClassifierRepresentation) {
- element = ((ClassifierRepresentation)element).getRepresentedClassifier();
- }
- return super.getImage(element);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.providers.EditorLabelProvider#getText(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public String getText(Object element) {
- if(element instanceof EditPartRepresentation) {
- element = ((EditPartRepresentation)element).getUMLElement();
- } else if(element instanceof ClassifierRepresentation) {
- element = ((ClassifierRepresentation)element).getRepresentedClassifier();
- }
- return super.getText(element);
-
- }
-
- }
-
public class CustomComparator implements Comparator<Object> {
/** this list contains the name of all the classes which want sort */
private List<String> classesList;
/**
- *
* Constructor.
*
* @param members
@@ -519,12 +412,7 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
}
/**
- *
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- *
- * @param o1
- * @param o2
- * @return
*/
public int compare(Object o1, Object o2) {
@@ -559,40 +447,26 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
}
/**
- *
* Content provider for the {@link CheckedTreeSelectionDialog}
- *
*/
public class ContentProvider implements ITreeContentProvider {
/**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- *
+ * {@inheritDoc}
*/
public void dispose() {
- // TODO Auto-generated method stub
-
+ // nothing here
}
/**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- *
- * @param viewer
- * @param oldInput
- * @param newInput
+ * {@inheritDoc}
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- // TODO Auto-generated method stub
+ // nothing here
}
/**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
- *
- * @param inputElement
- * @return
+ * {@inheritDoc}
*/
public Object[] getElements(Object inputElement) {
if(inputElement instanceof List) {
@@ -602,71 +476,87 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
}
/**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- *
- * @param parentElement
- * @return
+ * {@inheritDoc}
*/
public Object[] getChildren(Object parentElement) {
- List<NamedElement> members = new ArrayList<NamedElement>();
- EList<NamedElement> localMembers = null;
+ // if(parentElement instanceof RootEditPartRepresentation) {
+ // RootEditPartRepresentation parentRepresentation = (RootEditPartRepresentation)parentElement;
+ // return parentRepresentation.getPossibleElement().toArray();
+ // } else if(parentElement instanceof CompartmentEditPartRepresentation) {
+ // CompartmentEditPartRepresentation compartmentRepresentation = (CompartmentEditPartRepresentation)parentElement;
+ // return compartmentRepresentation.getPossibleElement().toArray();
+ // }
if(parentElement instanceof EditPartRepresentation) {
- EObject myClassifier = ((EditPartRepresentation)parentElement).getUMLElement();
- if(myClassifier instanceof Classifier) {
- localMembers = ((Classifier)myClassifier).getOwnedMembers();
- for(NamedElement namedElement : localMembers) {
- if(((EditPartRepresentation)parentElement).getPossibleElement().contains(namedElement)) {
- members.add(namedElement);
- }
- }
- }
- } else if(parentElement instanceof ClassifierRepresentation) {
- localMembers = ((ClassifierRepresentation)parentElement).getRepresentedClassifier().getOwnedMembers();
- for(NamedElement namedElement : localMembers) {
- if(((ClassifierRepresentation)parentElement).getEditPartRepresentation().getPossibleElement().contains(namedElement)) {
- members.add(namedElement);
- }
- }
+ return ((EditPartRepresentation)parentElement).getPossibleElement().toArray();
}
- Collections.sort(members, new CustomComparator(members));
- return members.toArray();
+ return new Object[0];
+
+ // // in case of parent is the main edit part => returns all compartment
+ // // if this is a compartment, returns all members that can be displayed
+ // if(parentElement instanceof CompartmentEditPartRepresentation) {
+ // CompartmentEditPartRepresentation compartmentRepresentation = (CompartmentEditPartRepresentation)parentElement;
+ //
+ // // case parent is a compartment edit part
+ // EObject myClassifier = compartmentRepresentation.getUMLElement();
+ // if(myClassifier instanceof Classifier) {
+ // // returns all members that can be displayed in this compartment
+ // List<NamedElement> members = new ArrayList<NamedElement>();
+ // EList<NamedElement> localMembers = ((Classifier)myClassifier).getOwnedMembers();
+ // for(NamedElement namedElement : localMembers) {
+ // if(((EditPartRepresentation)parentElement).getPossibleElement().contains(namedElement)) {
+ // members.add(namedElement);
+ // }
+ // }
+ // Collections.sort(members, new CustomComparator(members));
+ // return members.toArray();
+ // }
+ // } else if(parentElement instanceof EditPartRepresentation) {// case parent is the main edit part
+ // EditPartRepresentation parentRepresentation = (EditPartRepresentation)parentElement;
+ // Element element = parentRepresentation.getUMLElement();
+ // if(element instanceof Classifier) {
+ // List<CompartmentEditPartRepresentation> compartmentRepresentations = new ArrayList<CompartmentEditPartRepresentation>();
+ // List<IResizableCompartmentEditPart> compartmentEditParts = CompartmentUtils.getAllCompartmentsEditPart(parentRepresentation.getRepresentedEditPart(), false);
+ // for(IResizableCompartmentEditPart currentEditPart : compartmentEditParts) {
+ // CompartmentEditPartRepresentation representation = new CompartmentEditPartRepresentation(currentEditPart, (Classifier)element);
+ // compartmentRepresentations.add(representation);
+ // }
+ // return compartmentRepresentations.toArray();
+ // }
+ // }
+ // return new Object[]{};
}
/**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- *
- * @param element
- * @return
+ * {@inheritDoc}
*/
public Object getParent(Object element) {
- if(!(element instanceof EditPartRepresentation)) {
- EditPartRepresentation rep = findEditPartRepresentation(element);
- if(rep != null) {
-
- Classifier classifier = (Classifier)(rep).getUMLElement();
- if(classifier.getOwnedMembers().contains(element)) {
- return rep;
- } else {
- for(ClassifierRepresentation classRep : ((CustomEditPartRepresentation)rep).getSuperClasses()) {
- if(classRep.ownsElement(element)) {
- return classRep;
- }
- }
- }
- }
+ if(element instanceof EditPartRepresentation) {
+ EditPartRepresentation editPartRepresentation = (EditPartRepresentation)element;
+ return editPartRepresentation.getParentRepresentation();
}
+
+ // if(!(element instanceof EditPartRepresentation)) {
+ // EditPartRepresentation rep = findEditPartRepresentation(element);
+ // if(rep != null) {
+ //
+ // Classifier classifier = (Classifier)(rep).getUMLElement();
+ // if(classifier.getOwnedMembers().contains(element)) {
+ // return rep;
+ // } else {
+ // // for(ClassifierRepresentation classRep : ((CustomEditPartRepresentation)rep).getSuperClasses()) {
+ // // if(classRep.ownsElement(element)) {
+ // // return classRep;
+ // // }
+ // // }
+ // }
+ // }
+ // }
return null;
}
/**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- *
- * @param element
- * @return
+ * {@inheritDoc}
*/
public boolean hasChildren(Object element) {
if(getChildren(element) != null && getChildren(element).length > 0) {
@@ -678,131 +568,474 @@ public class ShowHideContentsAction extends AbstractShowHideAction implements IA
}
/**
- *
- * The custom EditPartRepresentation for this action
- *
+ * Class that represents the root edit part taht contains the compartments
*/
- protected class CustomEditPartRepresentation extends EditPartRepresentation {
-
- /**
- * this list contains the representation of all classifier which are
- * superclass of the classifier represented by EditPartRepresentaiton
- */
- protected List<ClassifierRepresentation> superClasses;
+ protected class RootEditPartRepresentation extends EditPartRepresentation {
/**
- *
- * Constructor.
+ * Creates a new {@link RootEditPartRepresentation}
*
* @param representedEditPart
+ * the edit part managed by this representation
* @param classifier
+ * the classifier managed by the represented edit part
*/
- public CustomEditPartRepresentation(EditPart representedEditPart, Classifier classifier) {
+ public RootEditPartRepresentation(IGraphicalEditPart representedEditPart, Classifier classifier) {
super(representedEditPart, classifier);
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public Classifier getSemanticElement() {
+ return (Classifier)super.getSemanticElement();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void initRepresentation() {
+ super.initRepresentation();
+
+ List<IResizableCompartmentEditPart> compartmentEditParts = CompartmentUtils.getAllCompartmentsEditPart(getRepresentedEditPart(), false);
+ for(IResizableCompartmentEditPart currentEditPart : compartmentEditParts) {
+ CompartmentEditPartRepresentation representation = new CompartmentEditPartRepresentation(currentEditPart, getSemanticElement(), this);
+ elementsToSelect.add(representation);
+ }
+
+ // check if the element has a affixed child edit policy => will be treated as a compartment
+ EditPolicy policy = getRepresentedEditPart().getEditPolicy(AffixedNodeAlignmentEditPolicy.AFFIXED_CHILD_ALIGNMENT_ROLE);
+ if(policy != null) {
+ // there can be some affixed children, create a pseudo compartment edit part representation
+ AffixedChildrenEditPartRepresentation representation = new AffixedChildrenEditPartRepresentation(getSemanticElement(), this);
+ elementsToSelect.add(representation);
+ }
+ }
+ }
+
+ /**
+ * Class that represents the compartment edit parts.
+ */
+ protected class CompartmentEditPartRepresentation extends EditPartRepresentation {
+
+ /**
+ * Creates a new {@link CompartmentEditPartRepresentation}
*
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction.EditPartRepresentation#initRepresentation()
- *
+ * @param compartmentEditPart
+ * the compartment edit part managed by this representation
+ * @param classifier
+ * the classifier managed by the represented edit part
+ * @param parentRepresentation
+ * parent presentation of this parent
+ */
+ public CompartmentEditPartRepresentation(IResizableCompartmentEditPart compartmentEditPart, Classifier classifier, EditPartRepresentation parentRepresentation) {
+ super(compartmentEditPart, classifier, parentRepresentation);
+ }
+
+ // /**
+ // * Returns the title of the compartment
+ // *
+ // * @return the title of the compartment
+ // */
+ // public String getCompartmentName() {
+ // if(getRepresentedEditPart() instanceof IResizableCompartmentEditPart) {
+ // return ((IResizableCompartmentEditPart)getRepresentedEditPart()).getCompartmentName();
+ // }
+ // // this is not a compartment, but the virtual placeholder for border items
+ // return "Not a Compartment";
+ // }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getLabel() {
+ if(getRepresentedEditPart() instanceof IResizableCompartmentEditPart) {
+ return ((IResizableCompartmentEditPart)getRepresentedEditPart()).getCompartmentName();
+ }
+ return super.getLabel();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Classifier getSemanticElement() {
+ return (Classifier)super.getSemanticElement();
+ }
+
+ /**
+ * {@inheritDoc}
*/
@Override
protected void initRepresentation() {
+ // call super first
super.initRepresentation();
- this.superClasses = new ArrayList<ShowHideContentsAction.ClassifierRepresentation>();
- if(this.UMLElement instanceof Classifier) {
- EList<Classifier> parents = ((Classifier)UMLElement).allParents();
- for(Classifier classifier : parents) {
- superClasses.add(new ClassifierRepresentation(classifier, this));
- }
- /*
- * build the list of the elements to select we suggest only the
- * elements which can be displayed in the shown compartments
- */
- this.elementsToSelect = new ArrayList<Object>();
- EList<NamedElement> members = ((Classifier)UMLElement).getMembers();
- for(NamedElement namedElement : members) {
- View compartment = getCompartmentForCreation(this.representedEditPart, namedElement);
- if(compartment != null) {
- this.elementsToSelect.add(namedElement);
-
- // build the initial selection
- EList<?> childrenView = compartment.getVisibleChildren();
- for(Object object : childrenView) {
- if(object instanceof View) {
- if(((View)object).getElement() == namedElement) {
- this.initialSelection.add(namedElement);
- break;
+ EList<NamedElement> members = getSemanticElement().getMembers();
+ for(NamedElement namedElement : members) {
+ if(canContain(namedElement)) {
+ // create the leaf representation
+ OptionalEditPartRepresentation editPartRepresentation = new OptionalEditPartRepresentation(null, namedElement, this);
+ this.elementsToSelect.add(editPartRepresentation);
+ // build the initial selection
+ EList<?> childrenView = getRepresentedEditPart().getNotationView().getVisibleChildren();
+ for(Object object : childrenView) {
+ if(object instanceof View) {
+ if(((View)object).getElement() == namedElement) {
+ this.initialSelection.add(editPartRepresentation);
+
+ // set the edit part in the optional edit part representation
+ for(Object o : getRepresentedEditPart().getChildren()) {
+ if(o instanceof IGraphicalEditPart) {
+ if(((View)object).equals(((IGraphicalEditPart)o).getNotationView())) {
+ editPartRepresentation.setRepresentedEditPart((IGraphicalEditPart)o);
+ }
+ }
}
+ break;
}
}
}
}
}
+
}
/**
+ * REturns <code>true</code> if the associated compartment edit part can contain the given element
*
- * @return a list containing the {@link ClassifierRepresentation} for
- * each superclass of the {@link #representedEditPart}
+ * @param namedElement
+ * the named element to show/hide
+ * @return <code>true</code> if the compartment can display the element
*/
- public List<ClassifierRepresentation> getSuperClasses() {
- return this.superClasses;
- }
+ protected boolean canContain(NamedElement namedElement) {
+ TransactionalEditingDomain domain = getRepresentedEditPart().getEditingDomain();
+ ViewDescriptor viewDescriptor = new ViewDescriptor(new EObjectAdapter(namedElement), Node.class, null, ViewUtil.APPEND, false, getRepresentedEditPart().getDiagramPreferencesHint());
+ CreateCommand cmd = new CreateCommand(domain, viewDescriptor, getRepresentedEditPart().getNotationView());
+ return (cmd.canExecute());
+ }
}
/**
- *
- * This class is used to do easily the difference between the nested
- * classifiers and the superclass of the selected class in the Tree The
- * superclass are represented with this class
+ * Specific edit part representation for edit part that can display affixed children. It extends {@link CompartmentEditPartRepresentation}, as
+ * this is displayed at the same level.
*/
- protected class ClassifierRepresentation {
-
- /** the represented classifier */
- protected Classifier representedClassifier;
-
- /** the CustomEditPartRepresentation owning this classifier */
- protected EditPartRepresentation rep;
+ protected class AffixedChildrenEditPartRepresentation extends CompartmentEditPartRepresentation {
/**
- *
* Constructor.
*
- * @param representedClassifier
- * the represented classifier
+ * @param classifier
+ * uml element linked to this representation
+ * @param parentRepresentation
+ * the main edit part against which show/hide content action is performed
*/
- public ClassifierRepresentation(Classifier representedClassifier, CustomEditPartRepresentation rep) {
- this.representedClassifier = representedClassifier;
- this.rep = rep;
+ public AffixedChildrenEditPartRepresentation(Classifier classifier, EditPartRepresentation parentRepresentation) {
+ super(null, classifier, parentRepresentation);
}
- public boolean ownsElement(Object element) {
- if(representedClassifier.getOwnedMembers().contains(element)) {
- return true;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean canContain(NamedElement namedElement) {
+ TransactionalEditingDomain domain = getParentRepresentation().getRepresentedEditPart().getEditingDomain();
+ ViewDescriptor viewDescriptor = new ViewDescriptor(new EObjectAdapter(namedElement), Node.class, null, ViewUtil.APPEND, false, getParentRepresentation().getRepresentedEditPart().getDiagramPreferencesHint());
+
+ CreateCommand cmd = new CreateCommand(domain, viewDescriptor, getParentRepresentation().getRepresentedEditPart().getNotationView());
+ return (cmd.canExecute());
+
+ //return super.canContain(namedElement);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IGraphicalEditPart getRepresentedEditPart() {
+ return getParentRepresentation().getRepresentedEditPart();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getLabel() {
+ return "Border Items";
+ }
+
+ @Override
+ protected void initRepresentation() {
+ this.initialSelection = new ArrayList<EditPartRepresentation>();
+ this.elementsToSelect = new ArrayList<EditPartRepresentation>();
+
+ EList<NamedElement> members = getSemanticElement().getMembers();
+ for(NamedElement namedElement : members) {
+ if(canContain(namedElement)) {
+ // create the leaf representation
+ OptionalEditPartRepresentation editPartRepresentation = new OptionalEditPartRepresentation(null, namedElement, this);
+ this.elementsToSelect.add(editPartRepresentation);
+ // build the initial selection
+ EList<?> childrenView = getParentRepresentation().getRepresentedEditPart().getNotationView().getVisibleChildren();
+ for(Object object : childrenView) {
+ if(object instanceof View) {
+ if(((View)object).getElement() == namedElement) {
+ this.initialSelection.add(editPartRepresentation);
+
+ // set the edit part in the optional edit part representation
+ for(Object o : getParentRepresentation().getRepresentedEditPart().getChildren()) {
+ if(o instanceof IGraphicalEditPart) {
+ if(((View)object).equals(((IGraphicalEditPart)o).getNotationView())) {
+ editPartRepresentation.setRepresentedEditPart((IGraphicalEditPart)o);
+ break;
+ }
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
}
- return false;
}
+
+
+ }
+
+ /**
+ * Class that manages an element that can not be displayed currently
+ */
+ protected class OptionalEditPartRepresentation extends EditPartRepresentation {
+
/**
- * Getter for {@link #representedClassifier}
+ * Creates a new {@link OptionalEditPartRepresentation}
*
- * @return {@link #representedClassifier}
+ * @param representedEditPart
+ * the edit part managed by this representation, which can be <code>null</code> in this implementation
+ * @param element
+ * the semantic element managed by the represented edit part
+ * @param parentRepresentation
+ * parent representation for this edit part (should be a compartment edit part representation)
*/
- public Classifier getRepresentedClassifier() {
- return this.representedClassifier;
+ public OptionalEditPartRepresentation(IGraphicalEditPart representedEditPart, Element element, CompartmentEditPartRepresentation parentRepresentation) {
+ super(representedEditPart, element, parentRepresentation);
}
/**
- * Getter for {@link #rep}
- *
- * @return {@link #rep}
+ * {@inheritDoc}
*/
- public EditPartRepresentation getEditPartRepresentation() {
- return this.rep;
+ @Override
+ public CompartmentEditPartRepresentation getParentRepresentation() {
+ return (CompartmentEditPartRepresentation)super.getParentRepresentation();
}
}
+
+ // /**
+ // * The custom EditPartRepresentation for this action
+ // */
+ // protected class CustomEditPartRepresentation extends EditPartRepresentation {
+ //
+ // /**
+ // * this list contains the representation of all classifiers which are
+ // * superclass of the classifier represented by EditPartRepresentaiton
+ // */
+ // protected List<ClassifierRepresentation> superClasses;
+ //
+ // /**
+ // *
+ // * Constructor.
+ // *
+ // * @param representedEditPart
+ // * the edit part managing the classifier
+ // * @param classifier
+ // * the classifier for which display is customized
+ // */
+ // public CustomEditPartRepresentation(EditPart representedEditPart, Classifier classifier) {
+ // super(representedEditPart, classifier);
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected void initRepresentation() {
+ // super.initRepresentation();
+ // this.superClasses = new ArrayList<ShowHideContentsAction.ClassifierRepresentation>();
+ // if(this.UMLElement instanceof Classifier) {
+ // EList<Classifier> parents = ((Classifier)UMLElement).allParents();
+ // for(Classifier classifier : parents) {
+ // superClasses.add(new ClassifierRepresentation(classifier, this));
+ // }
+ //
+ // /*
+ // * build the list of the elements to select we suggest only the
+ // * elements which can be displayed in the shown compartments
+ // */
+ // EList<NamedElement> members = ((Classifier)UMLElement).getMembers();
+ // for(NamedElement namedElement : members) {
+ // View compartment = getCompartmentForCreation(this.representedEditPart, namedElement);
+ // if(compartment != null) {
+ // this.elementsToSelect.add(namedElement);
+ //
+ // // build the initial selection
+ // EList<?> childrenView = compartment.getVisibleChildren();
+ // for(Object object : childrenView) {
+ // if(object instanceof View) {
+ // if(((View)object).getElement() == namedElement) {
+ // this.initialSelection.add(namedElement);
+ // break;
+ // }
+ // }
+ // }
+ // }
+ // }
+ // }
+ // }
+ //
+ // /**
+ // *
+ // * @return a list containing the {@link ClassifierRepresentation} for
+ // * each superclass of the {@link #representedEditPart}
+ // */
+ // public List<ClassifierRepresentation> getSuperClasses() {
+ // return this.superClasses;
+ // }
+ //
+ // }
+
+ // /**
+ // * Extends the edit part representation only for compartments edit part
+ // */
+ // protected class CompartmentEditPartRepresentation extends EditPartRepresentation {
+ //
+ // /**
+ // * Constructor.
+ // *
+ // * @param compartmentEditPart
+ // * the compartment edit part represented
+ // * @param umlElement
+ // * the uml element for which the compartment is displayed
+ // */
+ // public CompartmentEditPartRepresentation(IResizableCompartmentEditPart compartmentEditPart, Classifier umlElement) {
+ // super(compartmentEditPart, umlElement);
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public IResizableCompartmentEditPart getRepresentedEditPart() {
+ // return (IResizableCompartmentEditPart)super.getRepresentedEditPart();
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public Classifier getUMLElement() {
+ // return (Classifier)super.getUMLElement();
+ // }
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected void initRepresentation() {
+ // // call super first
+ // super.initRepresentation();
+ //
+ // EList<NamedElement> members = getUMLElement().getMembers();
+ // for(NamedElement namedElement : members) {
+ // if(canContain(namedElement)) {
+ // this.elementsToSelect.add(namedElement);
+ // // build the initial selection
+ // EList<?> childrenView = getRepresentedEditPart().getNotationView().getVisibleChildren();
+ // for(Object object : childrenView) {
+ // if(object instanceof View) {
+ // if(((View)object).getElement() == namedElement) {
+ // this.initialSelection.add(namedElement);
+ // break;
+ // }
+ // }
+ // }
+ // }
+ // }
+ //
+ // }
+ //
+ // /**
+ // * REturns <code>true</code> if the associated compartment edit part can contain the given element
+ // *
+ // * @param namedElement
+ // * the named element to show/hide
+ // * @return <code>true</code> if the compartment can display the element
+ // */
+ // protected boolean canContain(NamedElement namedElement) {
+ // TransactionalEditingDomain domain = getRepresentedEditPart().getEditingDomain();
+ // ViewDescriptor viewDescriptor = new ViewDescriptor(new EObjectAdapter(namedElement), Node.class, null, ViewUtil.APPEND, false, getRepresentedEditPart().getDiagramPreferencesHint());
+ //
+ // CreateCommand cmd = new CreateCommand(domain, viewDescriptor, getRepresentedEditPart().getNotationView());
+ // return (cmd.canExecute());
+ // }
+ // }
+
+ // /**
+ // *
+ // * This class is used to do easily the difference between the nested
+ // * classifiers and the superclass of the selected class in the Tree The
+ // * superclass are represented with this class
+ // */
+ // protected class ClassifierRepresentation {
+ //
+ // /** the represented classifier */
+ // protected Classifier representedClassifier;
+ //
+ // /** the CustomEditPartRepresentation owning this classifier */
+ // protected EditPartRepresentation rep;
+ //
+ // /**
+ // * Constructor.
+ // *
+ // * @param representedClassifier
+ // * the represented classifier
+ // * @param rep
+ // * the representation containing this classifier
+ // */
+ // public ClassifierRepresentation(Classifier representedClassifier, CustomEditPartRepresentation rep) {
+ // this.representedClassifier = representedClassifier;
+ // this.rep = rep;
+ // }
+ //
+ // public boolean ownsElement(Object element) {
+ // if(representedClassifier.getOwnedMembers().contains(element)) {
+ // return true;
+ // }
+ // return false;
+ // }
+ //
+ // /**
+ // * Getter for {@link #representedClassifier}
+ // *
+ // * @return {@link #representedClassifier}
+ // */
+ // public Classifier getRepresentedClassifier() {
+ // return this.representedClassifier;
+ // }
+ //
+ // /**
+ // * Getter for {@link #rep}
+ // *
+ // * @return {@link #rep}
+ // */
+ // public EditPartRepresentation getEditPartRepresentation() {
+ // return this.rep;
+ // }
+ //
+ // }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/handlers/AbstractShowHideHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/handlers/AbstractShowHideHandler.java
index 7ff5327f8fc..97aee5e9695 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/handlers/AbstractShowHideHandler.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/actions/handlers/AbstractShowHideHandler.java
@@ -20,8 +20,8 @@ import java.util.List;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction;
@@ -40,10 +40,10 @@ abstract public class AbstractShowHideHandler extends AbstractHandler {
private AbstractShowHideAction action = null;
/** the EditPolicy key for this action */
- private String editpolicy;
+ private final String editpolicy;
/** the current selection */
- private List<EditPart> selection = new ArrayList<EditPart>();
+ private final List<IGraphicalEditPart> selection = new ArrayList<IGraphicalEditPart>();
/**
*
@@ -100,10 +100,10 @@ abstract public class AbstractShowHideHandler extends AbstractHandler {
Iterator<?> it = ((StructuredSelection)selectionTmp).iterator();
while(it.hasNext()) {
Object current = it.next();
- if(current instanceof EditPart) {
- EditPolicy editpolicy = ((EditPart)current).getEditPolicy(this.editpolicy);
+ if(current instanceof IGraphicalEditPart) {
+ EditPolicy editpolicy = ((IGraphicalEditPart)current).getEditPolicy(this.editpolicy);
if(editpolicy != null) {
- this.selection.add((EditPart)current);
+ this.selection.add((IGraphicalEditPart)current);
}
}
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CustomCheckedTreeSelectionDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CustomCheckedTreeSelectionDialog.java
index f32339e8228..0c182074224 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CustomCheckedTreeSelectionDialog.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CustomCheckedTreeSelectionDialog.java
@@ -64,7 +64,7 @@ public class CustomCheckedTreeSelectionDialog extends SelectionStatusDialog {
private CheckboxTreeViewer fViewer;
- private ILabelProvider fLabelProvider;
+ final private ILabelProvider fLabelProvider;
protected ITreeContentProvider fContentProvider;
@@ -93,7 +93,7 @@ public class CustomCheckedTreeSelectionDialog extends SelectionStatusDialog {
/**
* the style of the viewer
*/
- private int fStyle;
+ private final int fStyle;
/**
* Constructs an instance of <code>ElementTreeSelectionDialog</code>.
@@ -412,7 +412,7 @@ public class CustomCheckedTreeSelectionDialog extends SelectionStatusDialog {
return buttonComposite;
}
- private boolean evaluateIfTreeEmpty(Object input) {
+ protected boolean evaluateIfTreeEmpty(Object input) {
Object[] elements = fContentProvider.getElements(input);
if(elements.length > 0) {
if(fFilters != null) {
@@ -424,4 +424,13 @@ public class CustomCheckedTreeSelectionDialog extends SelectionStatusDialog {
}
return elements.length == 0;
}
+
+ /**
+ * Returns the label provider used by this dialog
+ *
+ * @return the label provider used by this dialog
+ */
+ public ILabelProvider getLabelProvider() {
+ return fLabelProvider;
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/CompartmentUtils.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/CompartmentUtils.java
index 1ad60589cec..420402590e1 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/CompartmentUtils.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/CompartmentUtils.java
@@ -20,6 +20,7 @@ import org.eclipse.gef.EditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IResizableCompartmentEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ITextAwareEditPart;
import org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPartService;
import org.eclipse.gmf.runtime.notation.BasicCompartment;
@@ -41,6 +42,33 @@ public class CompartmentUtils {
}
/**
+ * Returns all the compartments edit part of an EditPart
+ *
+ * @param editpart
+ * an editpart
+ * @param includeTitleCompartment
+ * if <code>true</code> we return the title compartment too
+ * @return all compartments of the EditPart
+ */
+ public static List<IResizableCompartmentEditPart> getAllCompartmentsEditPart(EditPart editpart, boolean includeTitleCompartment) {
+ List<IResizableCompartmentEditPart> compartments = new ArrayList<IResizableCompartmentEditPart>();
+
+ List<?> localChildren = editpart.getChildren();
+ for(Object current : localChildren) {
+ if(current instanceof IResizableCompartmentEditPart) {
+ if(includeTitleCompartment) {
+ compartments.add((IResizableCompartmentEditPart)current);
+ } else {
+ if(!(current instanceof ITextAwareEditPart)) {
+ compartments.add((IResizableCompartmentEditPart)current);
+ }
+ }
+ }
+ }
+ return compartments;
+ }
+
+ /**
* Returns all the compartments of an EditPart
*
* @param editpart
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ShowHideRelatedContentsAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ShowHideRelatedContentsAction.java
index 2dd1067a147..3dafe2e000b 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ShowHideRelatedContentsAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.component/custom-src/org/eclipse/papyrus/uml/diagram/component/custom/actions/ShowHideRelatedContentsAction.java
@@ -13,91 +13,70 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.component.custom.actions;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction;
import org.eclipse.papyrus.uml.diagram.common.actions.ShowHideContentsAction;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideRelatedContentsEditPolicy;
import org.eclipse.papyrus.uml.diagram.component.custom.messages.Messages;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
-// TODO: Auto-generated Javadoc
/**
* The Class ShowHideRelatedContentsAction.
*/
public class ShowHideRelatedContentsAction extends ShowHideContentsAction {
/**
- *
* Constructor.
- *
*/
public ShowHideRelatedContentsAction() {
super(Messages.ShowHideRelatedContentsAction_Title, Messages.ShowHideRelatedContentsAction_Message, ShowHideRelatedContentsEditPolicy.SHOW_HIDE_RELATED_CONTENTS_POLICY);
}
- /**
- * Inits the action.
- *
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#initAction()
- */
- @Override
- protected void initAction() {
- super.initAction();
- setEditorLabelProvider(new UMLLabelProvider());
- this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
-
- for(EditPart current : this.selectedElements) {
- //the selected elements which aren't Classifier are ignored
- EObject element = ((View)current.getModel()).getElement();
- if(element instanceof Property) {
- Type type = ((Property)element).getType();
- if(type instanceof Classifier) {
- this.representations.add(new CustomEditPartRepresentation(current, (Classifier)type));
- }
- }
- }
- this.setEditorLabelProvider(new CustomEditorLabelProvider());
- this.setContentProvider(new CustomContentProvider());
-
- }
-
- /**
- * The Class CustomContentProvider.
- */
- protected class CustomContentProvider extends ShowHideContentsAction.ContentProvider {
-
- /**
- * Gets the parent.
- *
- * @param element
- * the element
- * @return the parent
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- */
- @Override
- public Object getParent(Object element) {
- if(!(element instanceof EditPartRepresentation)) {
- EditPartRepresentation rep = findEditPartRepresentation(element);
- if(rep != null) {
- //element can be owned by the class (rep), or by a superclass (ClassifierRepresentation)
- List<ClassifierRepresentation> classes = ((CustomEditPartRepresentation)rep).getSuperClasses();
- for(ClassifierRepresentation classifierRepresentation : classes) {
- if(classifierRepresentation.getRepresentedClassifier().getOwnedMembers().contains(element)) {
- return classifierRepresentation;
- }
- }
- }
- return rep;
- }
- return null;
- }
- }
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected void initAction() {
+ // super.initAction();
+ // setEditorLabelProvider(new EditorLabelProvider());
+ // this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
+ //
+ // for(EditPart current : this.selectedElements) {
+ // //the selected elements which aren't Classifier are ignored
+ // EObject element = ((View)current.getModel()).getElement();
+ // if(element instanceof Property) {
+ // Type type = ((Property)element).getType();
+ // if(type instanceof Classifier) {
+ // this.representations.add(new CustomEditPartRepresentation(current, (Classifier)type));
+ // }
+ // }
+ // }
+ // this.setEditorLabelProvider(new CustomEditorLabelProvider());
+ // this.setContentProvider(new CustomContentProvider());
+ //
+ // }
+ //
+ // /**
+ // * The Class CustomContentProvider.
+ // */
+ // protected class CustomContentProvider extends ShowHideContentsAction.ContentProvider {
+ //
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public Object getParent(Object element) {
+ // if(!(element instanceof EditPartRepresentation)) {
+ // EditPartRepresentation rep = findEditPartRepresentation(element);
+ // if(rep != null) {
+ // //element can be owned by the class (rep), or by a superclass (ClassifierRepresentation)
+ // List<ClassifierRepresentation> classes = ((CustomEditPartRepresentation)rep).getSuperClasses();
+ // for(ClassifierRepresentation classifierRepresentation : classes) {
+ // if(classifierRepresentation.getRepresentedClassifier().getOwnedMembers().contains(element)) {
+ // return classifierRepresentation;
+ // }
+ // }
+ // }
+ // return rep;
+ // }
+ // return null;
+ // }
+ // }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ShowHideRelatedContentsAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ShowHideRelatedContentsAction.java
index 57e25c23f1c..740b3c8a9a3 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ShowHideRelatedContentsAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.composite/custom-src/org/eclipse/papyrus/uml/diagram/composite/custom/actions/ShowHideRelatedContentsAction.java
@@ -13,20 +13,13 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.composite.custom.actions;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction;
import org.eclipse.papyrus.uml.diagram.common.actions.ShowHideContentsAction;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideRelatedContentsEditPolicy;
import org.eclipse.papyrus.uml.diagram.composite.custom.messages.Messages;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
public class ShowHideRelatedContentsAction extends ShowHideContentsAction {
@@ -41,55 +34,64 @@ public class ShowHideRelatedContentsAction extends ShowHideContentsAction {
/**
*
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#initAction()
+ * @see org.eclipse.papyrus.diagram.common.actions.AbstractShowHideAction#initAction()
*
*/
@Override
protected void initAction() {
super.initAction();
- setEditorLabelProvider(new UMLLabelProvider());
- this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
-
- for(EditPart current : this.selectedElements) {
- //the selected elements which aren't Classifier are ignored
- EObject element = ((View)current.getModel()).getElement();
- if(element instanceof Property) {
- Type type = ((Property)element).getType();
- if(type instanceof Classifier) {
- this.representations.add(new CustomEditPartRepresentation(current, (Classifier)type));
+ for(IGraphicalEditPart current : this.selectedElements) {
+ // the selected elements which aren't Classifier are ignored
+ if(((View)current.getModel()).getElement() instanceof Property) {
+ Property property = (Property)((View)current.getModel()).getElement();
+ if(property.getType() instanceof Classifier) {
+ this.representations.add(new RootEditPartRepresentation(current, (Classifier)property.getType()));
}
}
}
- this.setEditorLabelProvider(new CustomEditorLabelProvider());
- this.setContentProvider(new CustomContentProvider());
-
- }
+ // setEditorLabelProvider(new EditorLabelProvider());
+ // this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
- protected class CustomContentProvider extends ShowHideContentsAction.ContentProvider {
+ // for(EditPart current : this.selectedElements) {
+ // //the selected elements which aren't Classifier are ignored
+ // EObject element = ((View)current.getModel()).getElement();
+ // if(element instanceof Property) {
+ // Type type = ((Property)element).getType();
+ // if(type instanceof Classifier) {
+ // this.representations.add(new CustomEditPartRepresentation(current, (Classifier)type));
+ // }
+ // }
+ // }
+ // this.setEditorLabelProvider(new CustomEditorLabelProvider());
+ // this.setContentProvider(new CustomContentProvider());
- /**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public Object getParent(Object element) {
- if(!(element instanceof EditPartRepresentation)) {
- EditPartRepresentation rep = findEditPartRepresentation(element);
- if(rep != null) {
- //element can be owned by the class (rep), or by a superclass (ClassifierRepresentation)
- List<ClassifierRepresentation> classes = ((CustomEditPartRepresentation)rep).getSuperClasses();
- for(ClassifierRepresentation classifierRepresentation : classes) {
- if(classifierRepresentation.getRepresentedClassifier().getOwnedMembers().contains(element)) {
- return classifierRepresentation;
- }
- }
- }
- return rep;
- }
- return null;
- }
}
+
+ // protected class CustomContentProvider extends ShowHideContentsAction.ContentProvider {
+ //
+ // /**
+ // *
+ // * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ // *
+ // * @param element
+ // * @return
+ // */
+ // @Override
+ // public Object getParent(Object element) {
+ // if(!(element instanceof EditPartRepresentation)) {
+ // EditPartRepresentation rep = findEditPartRepresentation(element);
+ // if(rep != null) {
+ // //element can be owned by the class (rep), or by a superclass (ClassifierRepresentation)
+ // List<ClassifierRepresentation> classes = ((CustomEditPartRepresentation)rep).getSuperClasses();
+ // for(ClassifierRepresentation classifierRepresentation : classes) {
+ // if(classifierRepresentation.getRepresentedClassifier().getOwnedMembers().contains(element)) {
+ // return classifierRepresentation;
+ // }
+ // }
+ // }
+ // return rep;
+ // }
+ // return null;
+ // }
+ // }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/custom-src/org/eclipse/papyrus/uml/diagram/deployment/custom/actions/ShowHideRelatedContentsAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/custom-src/org/eclipse/papyrus/uml/diagram/deployment/custom/actions/ShowHideRelatedContentsAction.java
index fe04cb07872..f80cbbb2718 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/custom-src/org/eclipse/papyrus/uml/diagram/deployment/custom/actions/ShowHideRelatedContentsAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.deployment/custom-src/org/eclipse/papyrus/uml/diagram/deployment/custom/actions/ShowHideRelatedContentsAction.java
@@ -13,78 +13,72 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.deployment.custom.actions;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction;
import org.eclipse.papyrus.uml.diagram.common.actions.ShowHideContentsAction;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideRelatedContentsEditPolicy;
import org.eclipse.papyrus.uml.diagram.deployment.custom.messages.Messages;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
public class ShowHideRelatedContentsAction extends ShowHideContentsAction {
/**
+ *
* Constructor.
+ *
*/
public ShowHideRelatedContentsAction() {
super(Messages.ShowHideRelatedContentsAction_Title, Messages.ShowHideRelatedContentsAction_Message, ShowHideRelatedContentsEditPolicy.SHOW_HIDE_RELATED_CONTENTS_POLICY);
}
- /**
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#initAction()
- */
- @Override
- protected void initAction() {
- super.initAction();
- setEditorLabelProvider(new UMLLabelProvider());
- this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
-
- for(EditPart current : this.selectedElements) {
- // the selected elements which aren't Classifier are ignored
- EObject element = ((View)current.getModel()).getElement();
- if(element instanceof Property) {
- Type type = ((Property)element).getType();
- if(type instanceof Classifier) {
- this.representations.add(new CustomEditPartRepresentation(current, (Classifier)type));
- }
- }
- }
- this.setEditorLabelProvider(new CustomEditorLabelProvider());
- this.setContentProvider(new CustomContentProvider());
-
- }
-
- protected class CustomContentProvider extends ShowHideContentsAction.ContentProvider {
-
- /**
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- * @param element
- * @return
- */
- @Override
- public Object getParent(Object element) {
- if(!(element instanceof EditPartRepresentation)) {
- EditPartRepresentation rep = findEditPartRepresentation(element);
- if(rep != null) {
- // element can be owned by the class (rep), or by a
- // superclass (ClassifierRepresentation)
- List<ClassifierRepresentation> classes = ((CustomEditPartRepresentation)rep).getSuperClasses();
- for(ClassifierRepresentation classifierRepresentation : classes) {
- if(classifierRepresentation.getRepresentedClassifier().getOwnedMembers().contains(element)) {
- return classifierRepresentation;
- }
- }
- }
- return rep;
- }
- return null;
- }
- }
+ // /**
+ // *
+ // * @see org.eclipse.papyrus.diagram.common.actions.AbstractShowHideAction#initAction()
+ // *
+ // */
+ // @Override
+ // protected void initAction() {
+ // super.initAction();
+ // setEditorLabelProvider(new EditorLabelProvider());
+ // this.representations = new ArrayList<AbstractShowHideAction.EditPartRepresentation>();
+ //
+ // for(EditPart current : this.selectedElements) {
+ // //the selected elements which aren't Classifier are ignored
+ // EObject element = ((View)current.getModel()).getElement();
+ // if(element instanceof Property) {
+ // Type type = ((Property)element).getType();
+ // if(type instanceof Classifier) {
+ // this.representations.add(new CustomEditPartRepresentation(current, (Classifier)type));
+ // }
+ // }
+ // }
+ // this.setEditorLabelProvider(new CustomEditorLabelProvider());
+ // this.setContentProvider(new CustomContentProvider());
+ //
+ // }
+ //
+ // protected class CustomContentProvider extends ShowHideContentsAction.ContentProvider {
+ //
+ // /**
+ // *
+ // * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ // *
+ // * @param element
+ // * @return
+ // */
+ // @Override
+ // public Object getParent(Object element) {
+ // if(!(element instanceof EditPartRepresentation)) {
+ // EditPartRepresentation rep = findEditPartRepresentation(element);
+ // if(rep != null) {
+ // //element can be owned by the class (rep), or by a superclass (ClassifierRepresentation)
+ // List<ClassifierRepresentation> classes = ((CustomEditPartRepresentation)rep).getSuperClasses();
+ // for(ClassifierRepresentation classifierRepresentation : classes) {
+ // if(classifierRepresentation.getRepresentedClassifier().getOwnedMembers().contains(element)) {
+ // return classifierRepresentation;
+ // }
+ // }
+ // }
+ // return rep;
+ // }
+ // return null;
+ // }
+ // }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/actions/ShowHideCompartmentAction.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/actions/ShowHideCompartmentAction.java
index 2e1e0a37f04..f25cb9bb202 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/actions/ShowHideCompartmentAction.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/actions/ShowHideCompartmentAction.java
@@ -20,6 +20,7 @@ import java.util.List;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
@@ -28,28 +29,26 @@ import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.common.ui.util.DisplayUtils;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IResizableCompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPartService;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.NotationPackage;
import org.eclipse.gmf.runtime.notation.Style;
import org.eclipse.gmf.runtime.notation.TitleStyle;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction;
import org.eclipse.papyrus.uml.diagram.common.commands.ShowHideCompartmentRequest;
import org.eclipse.papyrus.uml.diagram.common.commands.ShowHideTitleOfCompartmentCommand;
import org.eclipse.papyrus.uml.diagram.common.editpolicies.ShowHideCompartmentEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.util.CompartmentTitleRepresentation;
import org.eclipse.papyrus.uml.diagram.common.util.CompartmentUtils;
import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
import org.eclipse.papyrus.uml.diagram.common.util.ViewServiceUtil;
import org.eclipse.papyrus.uml.diagram.menu.dialogs.ShowHideCompartmentSelectionDialog;
import org.eclipse.papyrus.uml.diagram.menu.messages.Messages;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.dialogs.SelectionDialog;
-import org.eclipse.uml2.uml.Element;
/**
*
@@ -59,92 +58,192 @@ import org.eclipse.uml2.uml.Element;
*/
public class ShowHideCompartmentAction extends AbstractShowHideAction {
-
/** the transactional editing domain */
- protected TransactionalEditingDomain domain;
+ //protected TransactionalEditingDomain domain;
+
+ /** list of visible titles */
+ protected List<CompartmentEditPartRepresentation> visibleTitle;
+
+
+ /** the list of the visible views after selection in the dialog, to set title visiblity */
+ protected List<CompartmentEditPartRepresentation> visibleRepresentations;
/**
- *
* Constructor.
- *
- *
*/
public ShowHideCompartmentAction() {
super(Messages.ShowHideCompartmentAction_Title, Messages.ShowHideCompartmentAction_Messages, ShowHideCompartmentEditPolicy.SHOW_HIDE_COMPARTMENT_POLICY);
}
/**
- *
- * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
- *
- * @param window
+ * Edit part representation used as a main element in the tree
*/
- @Override
- public void init(IWorkbenchWindow window) {
+ protected class RootEditPartRepresentation extends EditPartRepresentation {
+
+ /**
+ * Constructor.
+ * @param representedEditPart
+ * the represented EditPart
+ * @param eObject
+ * the semantic element represented by EditPartRepresentation
+ */
+ public RootEditPartRepresentation(IGraphicalEditPart representedEditPart, EObject eObject) {
+ super(representedEditPart, eObject);
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void initRepresentation() {
+ super.initRepresentation();
+
+ List<View> compartmentViews = CompartmentUtils.getAllCompartments(getRepresentedEditPart(), false);
+ List<View> visibleCompartments = CompartmentUtils.getAllVisibleCompartments(getRepresentedEditPart(), false);
+ for(View currentView : compartmentViews) {
+ CompartmentEditPartRepresentation representation = new CompartmentEditPartRepresentation(null, currentView, getSemanticElement(), this);
+ elementsToSelect.add(representation);
+
+ if(visibleCompartments.contains(currentView)) {
+ initialSelection.add(representation);
+ }
+
+ }
+ }
}
/**
- *
- * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
- *
+ * Edit Part Representation for the compartments.
+ * Warning: if the compartment notation view is not visible, the edit part is not created. So we need to manipulate the view, not the edit part in
+ * this representation
*/
- @Override
- public void dispose() {
+ public class CompartmentEditPartRepresentation extends EditPartRepresentation {
- }
+ /** boolean that indicates if the title should be visible or not */
+ private boolean isTitleVisible;
+
+ /** notation view of the compartment */
+ final private View compartmentView;
+
+ /**
+ * Constructor.
+ *
+ * @param representedEditPart
+ * the represented EditPart. this can be <code>null</code> if the compartment is not visible when the dialog is opened
+ * @param compartmentView
+ * notation view for this compartment. this should never be <code>null</code>.
+ * @param eObject
+ * the semantic element represented by EditPartRepresentation
+ * @param parentRepresentation
+ * parent representation of this edit part representation
+ */
+ public CompartmentEditPartRepresentation(IResizableCompartmentEditPart representedEditPart, View compartmentView, EObject eObject, EditPartRepresentation parentRepresentation) {
+ super(representedEditPart, eObject, parentRepresentation);
+ isTitleVisible = CompartmentUtils.isCompartmentTitleVisible(compartmentView);
+ this.compartmentView = compartmentView;
+ assert compartmentView != null : "The compartment view should not be null";
+ }
- protected List<CompartmentTitleRepresentation> rep;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IResizableCompartmentEditPart getRepresentedEditPart() {
+ return (IResizableCompartmentEditPart)super.getRepresentedEditPart();
+ }
- protected List<CompartmentTitleRepresentation> visibleTitle;
+ /**
+ *
+ * @return <code>true</code> if the title of the compartment is displayed
+ * and <code>false</code> if not
+ */
+ public boolean isTitleVisible() {
+ return isTitleVisible;
+ }
- /**
- * Build the initial selection for the tree
- */
- @Override
- protected void buildInitialSelection() {
- this.initialSelection = new ArrayList<Object>();
- rep = new ArrayList<CompartmentTitleRepresentation>();
- visibleTitle = new ArrayList<CompartmentTitleRepresentation>();
- for(EditPart current : this.selectedElements) {
- // initialSelection.add(current);
- initialSelection.addAll(CompartmentUtils.getAllVisibleCompartments(current, false));
- // initialSelection.addAll(getAllVisibleCompartmentName(current));
- for(View view : CompartmentUtils.getAllCompartments(current, false)) {
- CompartmentTitleRepresentation localRep = new CompartmentTitleRepresentation(current, view);
- if(localRep.isTitleVisible()) {
-
- visibleTitle.add(localRep);
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getLabel() {
+ if(getRepresentedEditPart() != null) {
+ return getRepresentedEditPart().getCompartmentName();
+ } else {
+ EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart(getCompartmentView());
+ if(dummyEP instanceof IResizableCompartmentEditPart) {
+ return ((IResizableCompartmentEditPart)dummyEP).getCompartmentName();
}
- rep.add(localRep);
}
+ return getEditorLabelProvider().getText(getCompartmentView());
}
- initialSelection.addAll(visibleTitle);
+ /**
+ * Sets the visibility of the title of the compartment
+ *
+ * @param value
+ * the value to set
+ */
+ public void setTitleVisible(boolean value) {
+ isTitleVisible = value;
+ }
+
+ /**
+ * Returns the view associated to the compartment
+ *
+ * @return the view associated to the compartment
+ */
+ public View getCompartmentView() {
+ return compartmentView;
+ }
}
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // protected void buildInitialSelection() {
+ // this.initialSelection = new ArrayList<Object>();
+ // rep = new ArrayList<CompartmentEditPartRepresentation>();
+ // visibleTitle = new ArrayList<CompartmentEditPartRepresentation>();
+ // for(EditPart current : this.selectedElements) {
+ // // initialSelection.add(current);
+ // initialSelection.addAll(CompartmentUtils.getAllVisibleCompartments(current, false));
+ // // initialSelection.addAll(getAllVisibleCompartmentName(current));
+ // for(View view : CompartmentUtils.getAllCompartments(current, false)) {
+ // CompartmentTitleRepresentation localRep = new CompartmentTitleRepresentation(current, view);
+ // if(localRep.isTitleVisible()) {
+ //
+ // visibleTitle.add(localRep);
+ // }
+ // rep.add(localRep);
+ // }
+ // }
+ //
+ // initialSelection.addAll(visibleTitle);
+ // }
+
/**
*
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#getSelectionDialog()
+ * @see org.eclipse.papyrus.diagram.common.actions.AbstractShowHideAction#getSelectionDialog()
*
* @return
*/
@Override
protected SelectionDialog getSelectionDialog() {
- ShowHideCompartmentSelectionDialog selectionDialog = new ShowHideCompartmentSelectionDialog(DisplayUtils.getDisplay().getActiveShell(), new UMLLabelProvider(), new ContentProvider());
+ ShowHideCompartmentSelectionDialog selectionDialog = new ShowHideCompartmentSelectionDialog(DisplayUtils.getDisplay().getActiveShell(), getEditorLabelProvider(), getContentProvider());
selectionDialog.setTitle(Messages.ShowHideCompartmentAction_Title);
selectionDialog.setMessage(Messages.ShowHideCompartmentAction_Messages);
selectionDialog.setContainerMode(true);
- selectionDialog.setInput(selectedElements);
+ selectionDialog.setInput(getInput());
selectionDialog.setExpandedElements(selectedElements.toArray());
- selectionDialog.setInitialElementSelections(this.initialSelection);
- selectionDialog.setTitleRepresentation(rep);
+ selectionDialog.setInitialElementSelections(getInitialSelection());
+ // selectionDialog.setTitleRepresentation(rep);
return selectionDialog;
}
/**
*
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#buildShowHideElementsList(java.lang.Object[])
+ * @see org.eclipse.papyrus.diagram.common.actions.AbstractShowHideAction#buildShowHideElementsList(java.lang.Object[])
*
* @param results
*/
@@ -168,67 +267,64 @@ public class ShowHideCompartmentAction extends AbstractShowHideAction {
if(initialSelection.contains(node)) {
//we do nothing
continue;
- } else {
- viewsToCreate.add(node);
+ } else if(node instanceof EditPartRepresentation) {
+ viewsToCreate.add((EditPartRepresentation)node);
}
}
//we are looking for the view to destroy
for(Object current : this.initialSelection) {
- if(!result.contains(current) && !(current instanceof EditPart)) {
- viewsToDestroy.add(current);
+ if(!result.contains(current) && (current instanceof EditPartRepresentation)) {
+ viewsToDestroy.add((EditPartRepresentation)current);
}
}
- }
- @Override
- public void run(IAction action) {
- initAction();
- super.run(action);
+ // we are looking for visible elements, to set the shown title or hidden title
+ for(Object node : result) {
+ if(node instanceof CompartmentEditPartRepresentation) {
+ visibleRepresentations.add((CompartmentEditPartRepresentation)node);
+ }
+ }
}
+ // @Override
+ // public void run(IAction action) {
+ // initAction();
+ // super.run(action);
+ // }
+
/**
- * Initialize the following fields :
- * <ul>
- * <li> {@link #representations}</li>
- * <li> {@link #viewsToCreate}</li>
- * <li>{@link #viewsToDestroy}</li>
- * <li> {@link #domain}</li>
- * <li> {@link #initialSelection}</li>
- * </ul>
+ * {@inheritDoc}
*/
@Override
protected void initAction() {
super.initAction();
- if(this.selectedElements.size() < 1) {
- return;
+
+ visibleRepresentations = new ArrayList<CompartmentEditPartRepresentation>();
+
+ for(IGraphicalEditPart current : this.selectedElements) {
+ if(((View)current.getModel()).getElement() != null) {
+ this.representations.add(new RootEditPartRepresentation(current, ((View)current.getModel()).getElement()));
+ }
}
setContentProvider(new ContentProvider());
- this.setEditorLabelProvider(new UMLLabelProvider());
- this.domain = ((IGraphicalEditPart)this.selectedElements.get(0)).getEditingDomain();
- this.initialSelection = getInitialSelection();
+ // setEditorLabelProvider(new EditorLabelProvider());
+ // this.domain = ((IGraphicalEditPart)this.selectedElements.get(0)).getEditingDomain();
+ // this.initialSelection = getInitialSelection();
}
-
/**
- *
- * @see org.eclipse.papyrus.uml.diagram.common.actions.AbstractShowHideAction#getInput()
- *
- * @return
+ * {@inheritDoc}
*/
@Override
protected List<Object> getInput() {
- return this.initialSelection;
+ return new ArrayList<Object>(representations);
}
/**
- * Returns the command to execute to show/hide the selected compartments
- *
- * @return
- * the command to execute to show/hide the selected compartments
+ * {@inheritDoc}
*/
-
@Override
protected Command getActionCommand() {
/* for further information, see bug 302555 */
@@ -238,37 +334,107 @@ public class ShowHideCompartmentAction extends AbstractShowHideAction {
CompoundCommand completeCmd = new CompoundCommand("Destroy and Create Compartment Command"); //$NON-NLS-1$
//the commands to hide compartment
- for(Object current : this.viewsToDestroy) {
- if(current instanceof View) {
- EditPart ep = DiagramEditPartsUtil.getEditPartFromView((View)current, selectedElements.get(0)).getParent();
- req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.HIDE, ((View)current).getType());
- req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
- Command tmp = ep.getCommand(req);
- if(tmp != null && tmp.canExecute()) {
- completeCmd.add(tmp);
+ for(EditPartRepresentation current : this.viewsToDestroy) {
+ if(current instanceof CompartmentEditPartRepresentation) {
+ CompartmentEditPartRepresentation currentRepresentation = (CompartmentEditPartRepresentation)current;
+ View currentView = currentRepresentation.getCompartmentView();
+ EditPart currentEditPart = currentRepresentation.getRepresentedEditPart(); // should not be null, because a view to delete should be visible, and so have an existing associated edit part.
+ // if null, try to find it using gmf methods from the view
+
+ if(currentEditPart == null) {
+ Activator.log.debug("Warning! An edit part representation wished to destroy a view, but no edit part exists currently!" + current);
+ currentEditPart = DiagramEditPartsUtil.getEditPartFromView(currentView, selectedElements.get(0)).getParent();
}
- } else if(current instanceof CompartmentTitleRepresentation) {
- ShowHideTitleOfCompartmentCommand tmp = new ShowHideTitleOfCompartmentCommand(this.domain, (View)((CompartmentTitleRepresentation)current).getRealObject(), false);
- if(tmp != null && tmp.canExecute()) {
- completeCmd.add(new ICommandProxy(tmp));
+
+ if(currentEditPart != null) {
+ req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.HIDE, currentView.getType());
+ req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
+ Command tmp = currentEditPart.getCommand(req);
+ if(tmp != null && tmp.canExecute()) {
+ completeCmd.add(tmp);
+ }
+ } else {
+ Activator.log.debug("Impossible to find an edit part for the given representation: " + current);
}
+
}
+
+ // if(current instanceof View) {
+ // EditPart ep = DiagramEditPartsUtil.getEditPartFromView((View)current, selectedElements.get(0)).getParent();
+ // req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.HIDE, ((View)current).getType());
+ // req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
+ // Command tmp = ep.getCommand(req);
+ // if(tmp != null && tmp.canExecute()) {
+ // completeCmd.add(tmp);
+ // }
+ // } else if(current instanceof CompartmentTitleRepresentation) {
+ // ShowHideTitleOfCompartmentCommand tmp = new ShowHideTitleOfCompartmentCommand(this.domain, (View)((CompartmentTitleRepresentation)current).getRealObject(), false);
+ // if(tmp != null && tmp.canExecute()) {
+ // completeCmd.add(new ICommandProxy(tmp));
+ // }
+ // }
}
//the command to show compartment
- for(Object current : this.viewsToCreate) {
- if(current instanceof View) {
- EditPart ep = CompartmentUtils.getCompartmentTitleRepresentation(rep, (View)current).getParent();
- req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.SHOW, ((View)current).getType());
- req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
- Command tmp = ep.getCommand(req);
- if(tmp != null && tmp.canExecute()) {
- completeCmd.add(tmp);
+ for(EditPartRepresentation current : this.viewsToCreate) {
+ if(current instanceof CompartmentEditPartRepresentation) {
+ CompartmentEditPartRepresentation currentRepresentation = (CompartmentEditPartRepresentation)current;
+ View currentView = currentRepresentation.getCompartmentView();
+ EditPartRepresentation parentRepresentation = currentRepresentation.getParentRepresentation();
+ IGraphicalEditPart parentEditPart = parentRepresentation.getRepresentedEditPart();
+ if(currentView != null && parentEditPart != null) {
+ req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.SHOW, currentView.getType());
+ req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
+ Command tmp = parentEditPart.getCommand(req);
+ if(tmp != null && tmp.canExecute()) {
+ completeCmd.add(tmp);
+ }
}
- } else if(current instanceof CompartmentTitleRepresentation) {
- CompartmentTitleRepresentation compartmentTitleRep = (CompartmentTitleRepresentation)current;
- final View view = (View)compartmentTitleRep.getRealObject();
- Style style = view.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
+ }
+
+ // if(current instanceof View) {
+ // EditPart ep = CompartmentUtils.getCompartmentTitleRepresentation(rep, (View)current).getParent();
+ // req = new ShowHideCompartmentRequest(ShowHideCompartmentRequest.SHOW, ((View)current).getType());
+ // req.setType(ShowHideCompartmentRequest.SHOW_HIDE_COMPARTMENT);
+ // Command tmp = ep.getCommand(req);
+ // if(tmp != null && tmp.canExecute()) {
+ // completeCmd.add(tmp);
+ // }
+ // } else if(current instanceof CompartmentTitleRepresentation) {
+ // CompartmentTitleRepresentation compartmentTitleRep = (CompartmentTitleRepresentation)current;
+ // final View view = (View)compartmentTitleRep.getRealObject();
+ // Style style = view.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
+ // if(style == null) {
+ // // style is not existing yet (true for models created with Papyrus 0.7.x) => create now
+ // // See bug 351084
+ // completeCmd.add(new ICommandProxy(new AbstractTransactionalCommand(domain, "Create title style", Collections.EMPTY_LIST) { //$NON-NLS-1$
+ //
+ // public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) {
+ // TitleStyle style = (TitleStyle)view.createStyle(NotationPackage.eINSTANCE.getTitleStyle());
+ // style.setShowTitle(false);
+ // return CommandResult.newOKCommandResult();
+ // }
+ // }));
+ // }
+ // ShowHideTitleOfCompartmentCommand tmp = new ShowHideTitleOfCompartmentCommand(this.domain, view, true);
+ // if(tmp != null && tmp.canExecute()) {
+ // completeCmd.add(new ICommandProxy(tmp));
+ // }
+ // }
+ }
+
+ // now sets the visibility for all shown views
+
+ for(CompartmentEditPartRepresentation currentRepresentation : visibleRepresentations) {
+ final View currentView = currentRepresentation.getCompartmentView();
+ boolean newVisibility = currentRepresentation.isTitleVisible();
+ boolean oldVisibility = CompartmentUtils.isCompartmentTitleVisible(currentView);
+
+ IGraphicalEditPart parentEditPart = currentRepresentation.getParentRepresentation().getRepresentedEditPart();
+ final TransactionalEditingDomain domain = parentEditPart.getEditingDomain();
+ // visibility has changed => change the model
+ if(newVisibility != oldVisibility) {
+ Style style = currentView.getStyle(NotationPackage.eINSTANCE.getTitleStyle());
if(style == null) {
// style is not existing yet (true for models created with Papyrus 0.7.x) => create now
// See bug 351084
@@ -276,13 +442,13 @@ public class ShowHideCompartmentAction extends AbstractShowHideAction {
@Override
public CommandResult doExecuteWithResult(IProgressMonitor dummy, IAdaptable info) {
- TitleStyle style = (TitleStyle)view.createStyle(NotationPackage.eINSTANCE.getTitleStyle());
+ TitleStyle style = (TitleStyle)currentView.createStyle(NotationPackage.eINSTANCE.getTitleStyle());
style.setShowTitle(false);
return CommandResult.newOKCommandResult();
}
}));
}
- ShowHideTitleOfCompartmentCommand tmp = new ShowHideTitleOfCompartmentCommand(this.domain, view, true);
+ ShowHideTitleOfCompartmentCommand tmp = new ShowHideTitleOfCompartmentCommand(domain, currentView, newVisibility);
if(tmp != null && tmp.canExecute()) {
completeCmd.add(new ICommandProxy(tmp));
}
@@ -294,39 +460,26 @@ public class ShowHideCompartmentAction extends AbstractShowHideAction {
/**
- *
* Provide the element to fill the tree
- *
*/
protected class ContentProvider implements ITreeContentProvider {
/**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#dispose()
- *
+ * {@inheritDoc}
*/
public void dispose() {
//nothing to do
}
/**
- *
- * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
- *
- * @param viewer
- * @param oldInput
- * @param newInput
+ * {@inheritDoc}
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
//nothing to do
}
/**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getElements(java.lang.Object)
- *
- * @param inputElement
- * @return
+ * {@inheritDoc}
*/
public Object[] getElements(Object inputElement) {
if(inputElement instanceof List) {
@@ -336,49 +489,28 @@ public class ShowHideCompartmentAction extends AbstractShowHideAction {
}
/**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
- *
- * @param parentElement
- * @return
+ * {@inheritDoc}
*/
public Object[] getChildren(Object parentElement) {
- if(parentElement instanceof EditPart) {
- return CompartmentUtils.getAllCompartments((EditPart)parentElement, false).toArray();
+ if(parentElement instanceof EditPartRepresentation) {
+ return ((EditPartRepresentation)parentElement).getPossibleElement().toArray();
}
- return null;
+ return new Object[0];
}
/**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
- *
- * @param element
- * @return
+ * {@inheritDoc}
*/
public Object getParent(Object element) {
- if(element instanceof Element) {
- return null;
- }
- if(element instanceof View) {
- CompartmentTitleRepresentation tmp = CompartmentUtils.getCompartmentTitleRepresentation(rep, (View)element);
- if(tmp != null) {
- return tmp.getParent();
- }
-
- }
- if(element instanceof CompartmentTitleRepresentation) {
- return ((CompartmentTitleRepresentation)element).getParent();
+ if(element instanceof EditPartRepresentation) {
+ EditPartRepresentation editPartRepresentation = (EditPartRepresentation)element;
+ return editPartRepresentation.getParentRepresentation();
}
return null;
}
/**
- *
- * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
- *
- * @param element
- * @return
+ * {@inheritDoc}
*/
public boolean hasChildren(Object element) {
Object[] children = getChildren(element);
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/dialogs/ShowHideCompartmentSelectionDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/dialogs/ShowHideCompartmentSelectionDialog.java
index 37198e1b066..0cadd914f9c 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/dialogs/ShowHideCompartmentSelectionDialog.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.menu/src/org/eclipse/papyrus/uml/diagram/menu/dialogs/ShowHideCompartmentSelectionDialog.java
@@ -16,31 +16,22 @@ package org.eclipse.papyrus.uml.diagram.menu.dialogs;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
import java.util.List;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpart.EditPartService;
-import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CellLabelProvider;
import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.ITreeSelection;
-import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.dialogs.AbstractCheckedTreeColumnViewerSelectionDialog;
-import org.eclipse.papyrus.uml.diagram.common.util.CompartmentTitleRepresentation;
-import org.eclipse.papyrus.uml.diagram.common.util.CompartmentUtils;
+import org.eclipse.papyrus.uml.diagram.menu.actions.ShowHideCompartmentAction.CompartmentEditPartRepresentation;
import org.eclipse.papyrus.uml.diagram.menu.messages.Messages;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -66,10 +57,10 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum
protected final static String ICON_UNCHECKED = "/icons/incomplete_tsk.gif"; //$NON-NLS-1$
/** all the title representation */
- protected List<CompartmentTitleRepresentation> titleRepresentations;
+ //protected List<CompartmentTitleRepresentation> titleRepresentations;
/** the selected title representation */
- protected List<CompartmentTitleRepresentation> selectedTitles;
+ // protected List<CompartmentTitleRepresentation> selectedTitles;
/**
*
@@ -90,39 +81,39 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum
}
/**
- * @see org.eclipse.papyrus.uml.diagram.common.dialogs.CustomCheckedTreeSelectionDialog#computeResult()
+ * @see org.eclipse.papyrus.diagram.common.dialogs.CustomCheckedTreeSelectionDialog#computeResult()
*/
@Override
protected void computeResult() {
List<Object> checkedElement = Arrays.asList(getTreeViewer().getCheckedElements());
List<Object> returnedValues = new ArrayList<Object>();
- returnedValues.addAll(selectedTitles);
+ // returnedValues.addAll(selectedTitles);
returnedValues.addAll(checkedElement);
setResult(returnedValues);
}
- /**
- * @see org.eclipse.papyrus.uml.diagram.common.dialogs.CheckedTreeSelectionDialog#setInput()
- */
- @Override
- public void setInput(Object input) {
- super.setInput(input);
- }
-
- /**
- * Setter for {@link #titleRepresentations}
- *
- * @param rep
- * the list of the title representation
- */
- public void setTitleRepresentation(List<CompartmentTitleRepresentation> rep) {
- this.titleRepresentations = rep;
- }
+ // /**
+ // * @see org.eclipse.papyrus.diagram.common.dialogs.CheckedTreeSelectionDialog#setInput()
+ // */
+ // @Override
+ // public void setInput(Object input) {
+ // super.setInput(input);
+ // }
+
+ // /**
+ // * Setter for {@link #titleRepresentations}
+ // *
+ // * @param rep
+ // * the list of the title representation
+ // */
+ // public void setTitleRepresentation(List<CompartmentTitleRepresentation> rep) {
+ // this.titleRepresentations = rep;
+ // }
/**
* Adds the propagation button (in addition to the buttons added by the super class) to the dialog.
*
- * @see org.eclipse.papyrus.uml.diagram.common.dialogs.CustomCheckedTreeSelectionDialog.createSelectionButtons
+ * @see org.eclipse.papyrus.diagram.common.dialogs.CustomCheckedTreeSelectionDialog.createSelectionButtons
* @param composite
* the parent composite
* @return Composite the composite the buttons were created in.
@@ -149,11 +140,11 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum
@Override
public void setInitialElementSelections(List selectedElements) {
super.setInitialElementSelections(selectedElements);
- this.selectedTitles = new ArrayList<CompartmentTitleRepresentation>();
+ // this.selectedTitles = new ArrayList<CompartmentTitleRepresentation>();
for(Object current : selectedElements) {
- if(current instanceof CompartmentTitleRepresentation) {
- this.selectedTitles.add((CompartmentTitleRepresentation)current);
- }
+ // if(current instanceof CompartmentTitleRepresentation) {
+ // this.selectedTitles.add((CompartmentTitleRepresentation)current);
+ // }
}
}
@@ -164,12 +155,12 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum
protected void init() {
setColumnTitles(new String[]{ "Compartments To Display", "Display Compartment Title" });
setColumnWidths(new int[]{ 350, 180 });
- setColumnCellLabelProvider(new CellLabelProvider[]{ new CompartmentNameProvider(), new CheckBoxLabelProvider() });
+ setColumnCellLabelProvider(new CellLabelProvider[]{ new CompartmentNameProvider(), new TitleVisibilityLabelProvider() });
}
/**
*
- * @see org.eclipse.papyrus.uml.diagram.common.dialogs.AbstractCheckedTreeColumnViewerSelectionDialog#getEditingSupport(int)
+ * @see org.eclipse.papyrus.diagram.common.dialogs.AbstractCheckedTreeColumnViewerSelectionDialog#getEditingSupport(int)
*
* @param columnIndex
* @return
@@ -183,27 +174,26 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum
}
/**
- * This class provides the editind support for the visibility of the name of the compartment
- *
- *
- *
+ * This class provides the editing support for the visibility of the name of the compartment
*/
public class NameVisibilityEditingSupport extends EditingSupport {
+ /**
+ * Constructor.
+ *
+ * @param viewer
+ * the viewer for which editing support is provided
+ */
public NameVisibilityEditingSupport(ColumnViewer viewer) {
super(viewer);
}
/**
- *
- * @see org.eclipse.jface.viewers.EditingSupport#getCellEditor(java.lang.Object)
- *
- * @param element
- * @return
+ * {@inheritDoc}
*/
@Override
protected CellEditor getCellEditor(Object element) {
- if(element instanceof View) {
+ if(element instanceof CompartmentEditPartRepresentation) {
CheckboxCellEditor editor = new CheckboxCellEditor();
editor.setValue(getValue(element));
return editor;
@@ -212,57 +202,37 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum
}
/**
- *
- * @see org.eclipse.jface.viewers.EditingSupport#canEdit(java.lang.Object)
- *
- * @param element
- * @return
+ * {@inheritDoc}
*/
@Override
protected boolean canEdit(Object element) {
- if(element instanceof View) {
- EditPart dummyEP = EditPartService.getInstance().createGraphicEditPart((View)element);
- return dummyEP instanceof CompartmentEditPart;
- }
- return false;
+ return (element instanceof CompartmentEditPartRepresentation);
}
/**
- *
- * @see org.eclipse.jface.viewers.EditingSupport#getValue(java.lang.Object)
- *
- * @param element
- * @return
+ * {@inheritDoc}
*/
@Override
protected Object getValue(Object element) {
- if(element instanceof View) {
- CompartmentTitleRepresentation rep = CompartmentUtils.getCompartmentTitleRepresentation(titleRepresentations, (View)element);
- if(rep != null) {
- return selectedTitles.contains(rep);
- }
+ if(element instanceof CompartmentEditPartRepresentation) {
+ return ((CompartmentEditPartRepresentation)element).isTitleVisible();
}
return false;
-
}
/**
- *
- * @see org.eclipse.jface.viewers.EditingSupport#setValue(java.lang.Object, java.lang.Object)
- *
- * @param element
- * @param value
+ * {@inheritDoc}
*/
@Override
protected void setValue(Object element, Object value) {
- if(element instanceof View) {
- CompartmentTitleRepresentation rep = CompartmentUtils.getCompartmentTitleRepresentation(titleRepresentations, (View)element);
- if(rep != null) {
- if(value.equals(true)) {
- selectedTitles.add(rep);
- } else if(value.equals(false)) {
- selectedTitles.remove(rep);
- }
+ if(value == null) {
+ return;
+ }
+ if(element instanceof CompartmentEditPartRepresentation) {
+ if(value.equals(true)) {
+ ((CompartmentEditPartRepresentation)element).setTitleVisible(true);
+ } else {
+ ((CompartmentEditPartRepresentation)element).setTitleVisible(false);
}
}
getTreeViewer().refresh();
@@ -274,35 +244,29 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum
* This provider is used by the 2nd column
*
*/
- class CompartmentNameProvider extends CellLabelProvider implements ILabelProvider {
+ protected class CompartmentNameProvider extends ColumnLabelProvider {
- /** the label provider */
- private final ILabelProvider provider;
+ /** label provider */
+ private final ILabelProvider labelProvider;
public CompartmentNameProvider() {
- provider = new UMLLabelProvider();
+ labelProvider = getLabelProvider();
}
/**
- *
- * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
- *
- * @param element
- * @return
+ * {@inheritDoc}
*/
+ @Override
public Image getImage(Object element) {
- return provider.getImage(element);
+ return labelProvider.getImage(element);
}
/**
- *
- * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
- *
- * @param element
- * @return
+ * {@inheritDoc}
*/
+ @Override
public String getText(Object element) {
- return provider.getText(element);
+ return labelProvider.getText(element);
}
@@ -321,54 +285,32 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum
/**
* The label provider for the 2nd column : Display Name
- *
- *
- *
*/
- public class CheckBoxLabelProvider extends CellLabelProvider {
+ public class TitleVisibilityLabelProvider extends ColumnLabelProvider {
- /**
- *
- * @see org.eclipse.jface.viewers.CellLabelProvider#update(org.eclipse.jface.viewers.ViewerCell)
- *
- * @param cell
- */
- @Override
- public void update(ViewerCell cell) {
- cell.setImage(getImage(cell.getElement()));
- cell.setText(getText(cell.getElement()));
-
- }
+ /** empty string */
+ private static final String EMPTY_STRING = "";
/**
- *
- * @param element
- * an element
- * @return
- * the text to display for this element
+ * {@inheritDoc}
*/
- private String getText(Object element) {
- return "";
+ @Override
+ public String getText(Object element) {
+ return EMPTY_STRING;
}
/**
- *
- * @param element
- * an element
- * @return
- * the image to display for this element
+ * {@inheritDoc}
*/
- private Image getImage(Object element) {
- if(element instanceof View) {
- CompartmentTitleRepresentation representation = CompartmentUtils.getCompartmentTitleRepresentation(titleRepresentations, (View)element);
- if(representation != null) {
- if(selectedTitles.contains(representation)) {
- return Activator.getPluginIconImage(Activator.ID, ICON_CHECKED);
- }
- return Activator.getPluginIconImage(Activator.ID, ICON_UNCHECKED);
+ @Override
+ public Image getImage(Object element) {
+ if(element instanceof CompartmentEditPartRepresentation) {
+ if(((CompartmentEditPartRepresentation)element).isTitleVisible()) {
+ return Activator.getPluginIconImage(Activator.ID, ICON_CHECKED);
}
+ return Activator.getPluginIconImage(Activator.ID, ICON_UNCHECKED);
}
- return null;
+ return super.getImage(element);
}
}
@@ -376,65 +318,67 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum
* Listener for propagation button
*/
public class PropagateSelectionAdapter extends SelectionAdapter {
-
@Override
public void widgetSelected(SelectionEvent e) {
- ISelection sel = getTreeViewer().getSelection();
- if(sel instanceof ITreeSelection) {
- TreePath paths[] = ((ITreeSelection)sel).getPaths();
- EditPart selectedEP;
- // Obtain EditPart at top of selection
- if(paths.length != 1) {
- return;
- }
- Object objSelectedEP = paths[0].getFirstSegment();
- if(objSelectedEP instanceof EditPart) {
- selectedEP = (EditPart)objSelectedEP;
- } else {
- return;
- }
- Class<? extends EditPart> clazz = selectedEP.getClass();
-
- List<View> sourceViews = CompartmentUtils.getAllCompartments(selectedEP, false);
-
- boolean changedTitle = false;
- Object[] viewerElements = fContentProvider.getElements(fInput);
- for(Object viewerElement : viewerElements) {
- // Identity guarantees that viewerElement is an instance of EditPart
- if((viewerElement.getClass() == clazz) && (viewerElement != selectedEP)) {
- // copy selection
- Iterator<View> targetViews = CompartmentUtils.getAllCompartments((EditPart)viewerElement, false).iterator();
- for(View sourceView : sourceViews) {
- if(targetViews.hasNext()) {
- View targetView = targetViews.next();
- boolean isChecked = getTreeViewer().getChecked(sourceView);
- getTreeViewer().setChecked(targetView, isChecked);
-
- // propagate title representation
- CompartmentTitleRepresentation sourceRepresentation = CompartmentUtils.getCompartmentTitleRepresentation(titleRepresentations, sourceView);
- CompartmentTitleRepresentation targetRepresentation = CompartmentUtils.getCompartmentTitleRepresentation(titleRepresentations, targetView);
- if((sourceRepresentation != null) && (targetRepresentation != null)) {
- if(selectedTitles.contains(sourceRepresentation)) {
- if(!selectedTitles.contains(targetRepresentation)) {
- selectedTitles.add(targetRepresentation);
- changedTitle = true;
- }
- } else {
- if(selectedTitles.contains(targetRepresentation)) {
- selectedTitles.remove(targetRepresentation);
- changedTitle = true;
- }
- }
- }
- }
- }
- }
- }
- updateOKStatus();
- if(changedTitle) {
- getTreeViewer().refresh();
- }
- }
+ // ISelection sel = getTreeViewer().getSelection();
+ // if (sel instanceof ITreeSelection) {
+ // TreePath paths[] = ((ITreeSelection) sel).getPaths();
+ // EditPart selectedEP;
+ // // Obtain EditPart at top of selection
+ // if (paths.length != 1) {
+ // return;
+ // }
+ // Object objSelectedEP = paths[0].getFirstSegment();
+ // if (objSelectedEP instanceof EditPart) {
+ // selectedEP = (EditPart) objSelectedEP;
+ // }
+ // else {
+ // return;
+ // }
+ // Class<? extends EditPart> clazz = ((EditPart) selectedEP).getClass();
+ //
+ // List<View> sourceViews = CompartmentUtils.getAllCompartments(selectedEP, false);
+ //
+ // boolean changedTitle = false;
+ // Object[] viewerElements = fContentProvider.getElements(fInput);
+ // for (Object viewerElement : viewerElements) {
+ // // Identity guarantees that viewerElement is an instance of EditPart
+ // if((viewerElement.getClass() == clazz) && (viewerElement != selectedEP)) {
+ // // copy selection
+ // Iterator<View> targetViews = CompartmentUtils.getAllCompartments((EditPart) viewerElement, false).iterator();
+ // for (View sourceView : sourceViews) {
+ // if (targetViews.hasNext()) {
+ // View targetView = targetViews.next();
+ // boolean isChecked = getTreeViewer().getChecked(sourceView);
+ // getTreeViewer().setChecked(targetView, isChecked);
+ //
+ // // propagate title representation
+ // CompartmentTitleRepresentation sourceRepresentation = CompartmentUtils.getCompartmentTitleRepresentation(titleRepresentations, sourceView);
+ // CompartmentTitleRepresentation targetRepresentation = CompartmentUtils.getCompartmentTitleRepresentation(titleRepresentations, targetView);
+ // if((sourceRepresentation != null) && (targetRepresentation != null)) {
+ // if(selectedTitles.contains(sourceRepresentation)) {
+ // if (!selectedTitles.contains(targetRepresentation)) {
+ // selectedTitles.add(targetRepresentation);
+ // changedTitle = true;
+ // }
+ // }
+ // else {
+ // if (selectedTitles.contains(targetRepresentation)) {
+ // selectedTitles.remove(targetRepresentation);
+ // changedTitle = true;
+ // }
+ // }
+ // }
+ // }
+ // }
+ // }
+ // }
+ // updateOKStatus();
+ // if (changedTitle) {
+ // getTreeViewer().refresh();
+ // }
+ // }
}
}
}
+

Back to the top