diff options
author | aradermache | 2011-07-05 22:31:27 +0000 |
---|---|---|
committer | aradermache | 2011-07-05 22:31:27 +0000 |
commit | 928fc5051e6eda61d536c74384653e776be52c49 (patch) | |
tree | d80bd367ac01439f88d013ee910a9dc1d31ef476 /plugins | |
parent | 3349910ce5c9467f49a3e3155b210f6a817debcc (diff) | |
download | org.eclipse.papyrus-928fc5051e6eda61d536c74384653e776be52c49.tar.gz org.eclipse.papyrus-928fc5051e6eda61d536c74384653e776be52c49.tar.xz org.eclipse.papyrus-928fc5051e6eda61d536c74384653e776be52c49.zip |
Fix for bug 351093: Propagation button in Show/Hide compartment dialog
Implied modification: made properties fContentProvider and fInput of CustomCheckedTreeSelectionDialog protected instead of private, since button listener needs access to these two.
(good for customization, which is the objective behind the class CustomCheckedTreeSelectionDialog)
Diffstat (limited to 'plugins')
4 files changed, 122 insertions, 13 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/dialogs/CustomCheckedTreeSelectionDialog.java b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/dialogs/CustomCheckedTreeSelectionDialog.java index fbb7a53cdcd..89f20d49e4b 100644 --- a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/dialogs/CustomCheckedTreeSelectionDialog.java +++ b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/dialogs/CustomCheckedTreeSelectionDialog.java @@ -65,7 +65,7 @@ public class CustomCheckedTreeSelectionDialog extends SelectionStatusDialog { private ILabelProvider fLabelProvider;
- private ITreeContentProvider fContentProvider;
+ protected ITreeContentProvider fContentProvider;
private ISelectionStatusValidator fValidator = null;
@@ -77,7 +77,7 @@ public class CustomCheckedTreeSelectionDialog extends SelectionStatusDialog { private List fFilters;
- private Object fInput;
+ protected Object fInput;
private boolean fIsEmpty;
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/dialogs/ShowHideCompartmentSelectionDialog.java b/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/dialogs/ShowHideCompartmentSelectionDialog.java index 769348414ca..3dab56a9a91 100644 --- a/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/dialogs/ShowHideCompartmentSelectionDialog.java +++ b/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/dialogs/ShowHideCompartmentSelectionDialog.java @@ -9,37 +9,50 @@ *
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Added propagation button
*
*****************************************************************************/
package org.eclipse.papyrus.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.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.diagram.common.Activator;
import org.eclipse.papyrus.diagram.common.dialogs.AbstractCheckedTreeColumnViewerSelectionDialog;
import org.eclipse.papyrus.diagram.common.providers.EditorLabelProvider;
import org.eclipse.papyrus.diagram.common.util.CompartmentTitleRepresentation;
import org.eclipse.papyrus.diagram.common.util.CompartmentUtils;
+import org.eclipse.papyrus.diagram.menu.messages.Messages;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
/**
- * This class provides a Dialog with 2 columns. In the first column, we have a TreeViewer and in the other one, you have a text.
+ * This class provides a Dialog with 2 columns. In the first column, we have a TreeViewer and in the other one, you have
+ * a check-box with (empty) text (check-box label provider)
*
*
*
@@ -77,20 +90,26 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum }
/**
- *
* @see org.eclipse.papyrus.diagram.common.dialogs.CustomCheckedTreeSelectionDialog#computeResult()
- *
*/
@Override
protected void computeResult() {
- List<Object> chekedElement = Arrays.asList(getTreeViewer().getCheckedElements());
+ List<Object> checkedElement = Arrays.asList(getTreeViewer().getCheckedElements());
List<Object> returnedValues = new ArrayList<Object>();
returnedValues.addAll(selectedTitles);
- returnedValues.addAll(chekedElement);
+ returnedValues.addAll(checkedElement);
setResult(returnedValues);
}
/**
+ * @see org.eclipse.papyrus.diagram.common.dialogs.CheckedTreeSelectionDialog#setInput()
+ */
+ @Override
+ public void setInput(Object input) {
+ super.setInput(input);
+ }
+
+ /**
* Setter for {@link #titleRepresentations}
*
* @param rep
@@ -101,6 +120,26 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum }
/**
+ * Adds the propagation button (in addition to the buttons added by the super class) to the dialog.
+ * @see org.eclipse.papyrus.diagram.common.dialogs.CustomCheckedTreeSelectionDialog.createSelectionButtons
+ * @param composite
+ * the parent composite
+ * @return Composite the composite the buttons were created in.
+ */
+ @Override
+ protected Composite createSelectionButtons(Composite composite) {
+ Composite buttonComposite = super.createSelectionButtons(composite);
+
+ Button propagateToSameType = createButton(buttonComposite,
+ IDialogConstants.SELECT_TYPES_ID, Messages.ShowHideCompartmentAction_PropagateToSameType,
+ false);
+ SelectionListener listener = new PropagateSelectionAdapter();
+ propagateToSameType.addSelectionListener(listener);
+
+ return buttonComposite;
+ }
+
+ /**
*
* @see org.eclipse.ui.dialogs.SelectionDialog#setInitialElementSelections(java.util.List)
*
@@ -124,8 +163,8 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum *
*/
protected void init() {
- setColumnTitles(new String[]{ "Compartments To Display", "Display Name" });
- setColumnWidths(new int[]{ 300, 200 });
+ setColumnTitles(new String[]{ "Compartments To Display", "Display Compartment Title" });
+ setColumnWidths(new int[]{ 350, 180 });
setColumnCellLabelProvider(new CellLabelProvider[]{ new CompartmentNameProvider(), new CheckBoxLabelProvider() });
}
@@ -205,6 +244,7 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum }
}
return false;
+
}
/**
@@ -234,8 +274,6 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum /**
* This provider is used by the 2nd column
*
- *
- *
*/
class CompartmentNameProvider extends CellLabelProvider implements ILabelProvider {
@@ -334,4 +372,72 @@ public class ShowHideCompartmentSelectionDialog extends AbstractCheckedTreeColum return null;
}
}
+
+ /**
+ * Listener for propagation button
+ */
+ public class PropagateSelectionAdapter extends SelectionAdapter {
+ 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 = ((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();
+ }
+ }
+ }
+ }
}
+
+
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/messages/Messages.java b/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/messages/Messages.java index 5166d9afb00..49b2f5ccccc 100644 --- a/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/messages/Messages.java +++ b/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/messages/Messages.java @@ -26,6 +26,8 @@ public class Messages extends NLS public static String ShowHideCompartmentAction_Title;
+ public static String ShowHideCompartmentAction_PropagateToSameType;
+
public static String ShowHideConnectionLabelsAction_LabelsManager;
public static String ShowHideConnectionLabelsAction_SelectTheLabelToDisplay;
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/messages/messages.properties b/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/messages/messages.properties index d00ba8ad606..b9030530b5e 100644 --- a/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/messages/messages.properties +++ b/plugins/uml/org.eclipse.papyrus.diagram.menu/src/org/eclipse/papyrus/diagram/menu/messages/messages.properties @@ -1,9 +1,10 @@ ShowHideCompartmentAction_Messages=Choose the compartments to show.
ShowHideCompartmentAction_No_Name=No name
ShowHideCompartmentAction_Title=Show/Hide compartments
-ShowHideConnectionLabelsAction_LabelsManager=Labels Manager
+ShowHideCompartmentAction_PropagateToSameType=&Propagate selection to elements of same type
+ShowHideConnectionLabelsAction_LabelsManager=Label Manager
ShowHideConnectionLabelsAction_SelectTheLabelToDisplay=Select the labels to display.
ZoomToolbar_Zoom=Zoom
SelectTypeAction_SelectActionName=Select elements with same type
-SelectTypeAction_SelectionActionTooltype=select elements with the same type of selected element in the diagram
+SelectTypeAction_SelectionActionTooltype=Select elements with the same type of selected element in the diagram
\ No newline at end of file |