diff options
author | Fanch BONNABESSE | 2015-11-09 17:05:07 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-01-28 12:30:11 +0000 |
commit | 712d97566d99446546055c44e8fe6806d99478dd (patch) | |
tree | 5b417a19e3b869c5abcb2d7788460dbe4fa7c8f8 /plugins/uml | |
parent | 23fae62909798c7159511510bc139f1d5ecb0b0d (diff) | |
download | org.eclipse.papyrus-712d97566d99446546055c44e8fe6806d99478dd.tar.gz org.eclipse.papyrus-712d97566d99446546055c44e8fe6806d99478dd.tar.xz org.eclipse.papyrus-712d97566d99446546055c44e8fe6806d99478dd.zip |
Bug 419357: [Diagram][Palette] Diagram must provide a way to restore
existing links
https://bugs.eclipse.org/bugs/show_bug.cgi?id=419357
Creation of a EditPolicyProvider on
"org.eclipse.papyrus.uml.diagram.common" to modify the
"DefaultSemanticEditPolicy" used by many EditPart
Change-Id: I1d3a329841509e1d297b4695019e0455a528a4f5
Signed-off-by: Fanch BONNABESSE <fanch.bonnabesse@all4tec.net>
Diffstat (limited to 'plugins/uml')
8 files changed, 926 insertions, 615 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml index 0f7f527c62a..3229561d801 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml @@ -482,6 +482,12 @@ </Priority> </editpolicyProvider> <editpolicyProvider + class="org.eclipse.papyrus.uml.diagram.common.providers.CustomEditPolicyProvider"> + <Priority + name="Lowest"> + </Priority> + </editpolicyProvider> + <editpolicyProvider class="org.eclipse.papyrus.uml.diagram.common.providers.ImportedElementEditPolicyProvider"> <Priority name="Low"> diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateOrShowExistingLinkDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateOrShowExistingLinkDialog.java index 2a3e6fd48ab..cc6bef0d690 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateOrShowExistingLinkDialog.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateOrShowExistingLinkDialog.java @@ -1,346 +1,400 @@ -/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.dialogs;
-
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ArrayContentProvider;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.ViewerColumn;
-import org.eclipse.papyrus.infra.widgets.Activator;
-import org.eclipse.papyrus.uml.diagram.common.messages.Messages;
-import org.eclipse.papyrus.uml.diagram.common.util.LinkEndsMapper;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-
-
-
-/**
- * This dialog is used to ask to the user if he wants create a new instance of a link, or show an existing link on the diagram
- *
- * @author VL222926
- *
- */
-public class CreateOrShowExistingLinkDialog extends MessageDialog {
-
- /**
- * indexes of the button
- */
- public static final int CREATE = Dialog.OK;
-
- public static final int RESTORE_SELECTED_LINK = CREATE + 1;
-
- public static final int CANCEL = RESTORE_SELECTED_LINK + 1;
-
- /**
- * title for the dialog
- */
- public static final String DIALOG_TITLE = Messages.CreateOrShowExistingLinkDialog_ShowOrCreate;
-
- /**
- * Message for the Buttons
- */
- private static final String CREATE_STRING = Messages.CreateOrShowExistingLinkDialog_Create;
-
- private static final String RESTORE_SELECTION = Messages.CreateOrShowExistingLinkDialog_RestoreSelection;
-
- private static final String CANCEL_STRING = "Cancel"; //$NON-NLS-1$
-
-
- /**
- * Titles for the columns
- */
- private static final String NAME = Messages.CreateOrShowExistingLinkDialog_Name;
-
- private static final String ENDS = Messages.CreateOrShowExistingLinkDialog_Ends;
-
- private static final String SOURCES = Messages.CreateOrShowExistingLinkDialog_Sources;
-
- private static final String TARGETS = Messages.CreateOrShowExistingLinkDialog_Targets;
-
- /**
- * Size for the columns
- */
- private static final int COLUMN_NAME_SIZE = 150;
-
- private static final int COLUMN_SIZE = 200;
-
- /**
- * the list of the elements to display in the Table
- */
- private final List<LinkEndsMapper> existingLinks;
-
-
- final UMLLabelProvider labelProvider = new UMLLabelProvider();
-
- /**
- * the string displayed when there is no value to display
- */
- private static final String NOT_AVAILABLE = "N/A"; //$NON-NLS-1$
-
- /**
- * the image to display when the link is selected
- */
- private static final String CHECKED_ICON_PATH = "icons/checkedRadioButton.gif"; //$NON-NLS-1$
-
- /**
- * the image to display when the link is not selected
- */
- private static final String UNCHECKED_ICON_PATH = "icons/uncheckedRadioButton.gif"; //$NON-NLS-1$
-
- /**
- * the index of the selected element
- */
- private int selectedElementIndex = 0;
-
- /**
- * the selected element
- */
- private EObject result = null;
-
- /**
- *
- * Constructor.
- *
- * @param dialogTitle
- * the title for the dialog
- * @param dialogMessage
- * the message for the dialog
- * @param elements
- * the list of the possible elements
- */
- public CreateOrShowExistingLinkDialog(final String dialogTitle, final String dialogMessage, final List<LinkEndsMapper> elements) {
- super(Display.getDefault().getActiveShell(), dialogTitle, null, dialogMessage, MessageDialog.QUESTION, new String[] { CREATE_STRING, RESTORE_SELECTION, CANCEL_STRING }, RESTORE_SELECTED_LINK);
- this.existingLinks = elements;
- }
-
- /**
- * Constructor.
- *
- * @param title
- * @param bound
- * @param viewer
- * @return
- */
- private TableViewerColumn createTableViewerColumn(String title, int bound, TableViewer viewer) {
- final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
- final TableColumn column = viewerColumn.getColumn();
- column.setText(title);
- column.setWidth(bound);
- column.setResizable(false);
- column.setMoveable(false);
- return viewerColumn;
- }
-
- /**
- *
- * @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
- *
- * @param parent
- * @return
- */
- @Override
- protected Control createCustomArea(final Composite parent) {
- final Composite composite = parent;
- final TableViewer viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
- viewer.setContentProvider(new ArrayContentProvider());
- final Table table = viewer.getTable();
- table.setHeaderVisible(true);
-
- ViewerColumn colCheckbox = createTableViewerColumn("", 20, viewer); //$NON-NLS-1$
- colCheckbox.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- return ""; //$NON-NLS-1$
- }
-
- @Override
- public Image getImage(Object element) {
- if (existingLinks.get(selectedElementIndex) == element) {
- return Activator.getDefault().getImage(org.eclipse.papyrus.uml.diagram.common.Activator.ID, CHECKED_ICON_PATH);
- }
- return Activator.getDefault().getImage(org.eclipse.papyrus.uml.diagram.common.Activator.ID, UNCHECKED_ICON_PATH);
- }
-
- });
- colCheckbox.setEditingSupport(new EditingSupport(viewer) {
-
- private CheckboxCellEditor checkboxCellEditor;
-
- @Override
- protected void setValue(Object element, Object value) {
- if (checkboxCellEditor.getValue() == Boolean.TRUE) {
- selectedElementIndex = existingLinks.indexOf(element);
- }
- for (final LinkEndsMapper current : existingLinks) {
- viewer.update(current, null);
- }
- }
-
- @Override
- protected Object getValue(Object element) {
- return existingLinks.get(selectedElementIndex) == element;
- }
-
- @Override
- protected CellEditor getCellEditor(Object element) {
- checkboxCellEditor = new CheckboxCellEditor(parent, SWT.CHECK | SWT.READ_ONLY);
- return checkboxCellEditor;
- }
-
- @Override
- protected boolean canEdit(Object element) {
- return true;
- }
- });
- TableViewerColumn columnName = createTableViewerColumn(NAME, COLUMN_NAME_SIZE, viewer);
- configureColumn(columnName);
- columnName.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- if (element instanceof LinkEndsMapper) {
- return labelProvider.getText(((LinkEndsMapper) element).getLink());
- }
- // not possible
- return NOT_AVAILABLE;
- }
-
- @Override
- public Image getImage(Object element) {
- return null;
- }
-
-
- });
-
- TableViewerColumn columnEnds = createTableViewerColumn(ENDS, COLUMN_SIZE, viewer);
- configureColumn(columnEnds);
- columnEnds.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- if (element instanceof LinkEndsMapper) {
- return getLabel(((LinkEndsMapper) element).getEnds());
- }
- return NOT_AVAILABLE;
- }
- });
-
-
- TableViewerColumn columnSources = createTableViewerColumn(SOURCES, COLUMN_SIZE, viewer);
- configureColumn(columnSources);
- columnSources.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- if (element instanceof LinkEndsMapper) {
- return getLabel(((LinkEndsMapper) element).getSources());
- }
- return NOT_AVAILABLE;
- }
- });
-
- TableViewerColumn columnTargets = createTableViewerColumn(TARGETS, COLUMN_SIZE, viewer);
- configureColumn(columnTargets);
- columnTargets.setLabelProvider(new ColumnLabelProvider() {
-
- @Override
- public String getText(Object element) {
- if (element instanceof LinkEndsMapper) {
- return getLabel(((LinkEndsMapper) element).getTargets());
- }
- return NOT_AVAILABLE;
- }
- });
-
- GridData gridData = new GridData();
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalSpan = 2;
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.horizontalAlignment = GridData.FILL;
- viewer.getControl().setLayoutData(gridData);
- viewer.setInput(existingLinks);
- parent.pack();
- return parent;
- }
-
- @Override
- protected void buttonPressed(int buttonId) {
- if (buttonId == RESTORE_SELECTED_LINK && this.existingLinks.size() >= this.selectedElementIndex) {
- this.result = this.existingLinks.get(this.selectedElementIndex).getLink();
- }
- super.buttonPressed(buttonId);
- }
-
- /**
- *
- * @param viewerColumn
- * the viewerColumn to configure
- */
- protected void configureColumn(final TableViewerColumn viewerColumn) {
- viewerColumn.getColumn().setMoveable(true);
- viewerColumn.getColumn().setResizable(true);
- }
-
- /**
- *
- * @param list
- * the list of the elements for which we want the label
- * @return
- * the string to display for this list
- */
- private String getLabel(final Collection<?> list) {
- if (list != null) {
- final StringBuilder builder = new StringBuilder();
- final Iterator<?> iter = list.iterator();
- while (iter.hasNext()) {
- builder.append(labelProvider.getText(iter.next()));
- if (iter.hasNext()) {
- builder.append(","); //$NON-NLS-1$
- }
- }
- return builder.toString();
- }
- return NOT_AVAILABLE;
- }
-
- /**
- *
- * @return
- * the selected link
- */
- public EObject getResult() {
- return this.result;
- }
-}
+/***************************************************************************** + * Copyright (c) 2013 CEA LIST. + * + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 419357 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.dialogs; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.CellEditor; +import org.eclipse.jface.viewers.CheckboxCellEditor; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.EditingSupport; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.ViewerColumn; +import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PreferencesConstantsHelper; +import org.eclipse.papyrus.infra.widgets.Activator; +import org.eclipse.papyrus.uml.diagram.common.messages.Messages; +import org.eclipse.papyrus.uml.diagram.common.util.LinkEndsMapper; +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; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; + + + +/** + * This dialog is used to ask to the user if he wants create a new instance of a link, or show an existing link on the diagram + * + * @author VL222926 + * + */ +public class CreateOrShowExistingLinkDialog extends MessageDialog { + + /** + * indexes of the button + */ + public static final int CREATE = Dialog.OK; + public static final int RESTORE_SELECTED_LINK = CREATE + 1; + public static final int CANCEL = RESTORE_SELECTED_LINK + 1; + + /** + * title for the dialog + */ + public static final String DIALOG_TITLE = Messages.CreateOrShowExistingLinkDialog_ShowOrCreate; + + /** + * Message for the Buttons + */ + private static final String CREATE_STRING = Messages.CreateOrShowExistingLinkDialog_Create; + private static final String RESTORE_SELECTION = Messages.CreateOrShowExistingLinkDialog_RestoreSelection; + private static final String CANCEL_STRING = "Cancel"; //$NON-NLS-1$ + + + /** + * Titles for the columns + */ + private static final String NAME = Messages.CreateOrShowExistingLinkDialog_Name; + private static final String ENDS = Messages.CreateOrShowExistingLinkDialog_Ends; + private static final String SOURCES = Messages.CreateOrShowExistingLinkDialog_Sources; + private static final String TARGETS = Messages.CreateOrShowExistingLinkDialog_Targets; + private static final String CHECKBOX_LABEL = Messages.CreateOrShowExistingElementHelper_AlwaysCreateNewLink; + + /** + * Size for the columns + */ + private static final int COLUMN_NAME_SIZE = 150; + private static final int COLUMN_SIZE = 200; + + /** + * the list of the elements to display in the Table + */ + private final List<LinkEndsMapper> existingLinks; + + final UMLLabelProvider labelProvider = new UMLLabelProvider(); + + /** + * the string displayed when there is no value to display + */ + private static final String NOT_AVAILABLE = "N/A"; //$NON-NLS-1$ + + /** + * the image to display when the link is selected + */ + private static final String CHECKED_ICON_PATH = "icons/checkedRadioButton.gif"; //$NON-NLS-1$ + + /** + * the image to display when the link is not selected + */ + private static final String UNCHECKED_ICON_PATH = "icons/uncheckedRadioButton.gif"; //$NON-NLS-1$ + + /** + * the index of the selected element + */ + private int selectedElementIndex = 0; + + /** + * the selected element + */ + private EObject result = null; + + /** + * The value of the toggle button of the dialog. + */ + private boolean toggleState = false; + + /** + * + * Constructor. + * + * @param dialogTitle + * the title for the dialog + * @param dialogMessage + * the message for the dialog + * @param elements + * the list of the possible elements + */ + public CreateOrShowExistingLinkDialog(final String dialogTitle, final String dialogMessage, final List<LinkEndsMapper> elements) { + super(Display.getDefault().getActiveShell(), dialogTitle, null, dialogMessage, MessageDialog.QUESTION, new String[] { CREATE_STRING, RESTORE_SELECTION, CANCEL_STRING }, RESTORE_SELECTED_LINK); + this.existingLinks = elements; + } + + /** + * Constructor. + * + * @param title + * @param bound + * @param viewer + * @return + */ + private TableViewerColumn createTableViewerColumn(final String title, final int bound, final TableViewer viewer) { + final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); + final TableColumn column = viewerColumn.getColumn(); + column.setText(title); + column.setWidth(bound); + column.setResizable(false); + column.setMoveable(false); + return viewerColumn; + } + + /** + * + * @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite) + * + * @param parent + * @return + */ + @Override + protected Control createCustomArea(final Composite parent) { + final Composite composite = parent; + final TableViewer viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + viewer.setContentProvider(new ArrayContentProvider()); + final Table table = viewer.getTable(); + table.setHeaderVisible(true); + + ViewerColumn colCheckbox = createTableViewerColumn("", 20, viewer); //$NON-NLS-1$ + colCheckbox.setLabelProvider(new ColumnLabelProvider() { + + @Override + public String getText(Object element) { + return ""; //$NON-NLS-1$ + } + + @Override + public Image getImage(Object element) { + if (existingLinks.get(selectedElementIndex) == element) { + return Activator.getDefault().getImage(org.eclipse.papyrus.uml.diagram.common.Activator.ID, CHECKED_ICON_PATH); + } + return Activator.getDefault().getImage(org.eclipse.papyrus.uml.diagram.common.Activator.ID, UNCHECKED_ICON_PATH); + } + + }); + colCheckbox.setEditingSupport(new EditingSupport(viewer) { + + private CheckboxCellEditor checkboxCellEditor; + + @Override + protected void setValue(Object element, Object value) { + if (checkboxCellEditor.getValue() == Boolean.TRUE) { + selectedElementIndex = existingLinks.indexOf(element); + } + for (final LinkEndsMapper current : existingLinks) { + viewer.update(current, null); + } + } + + @Override + protected Object getValue(Object element) { + return existingLinks.get(selectedElementIndex) == element; + } + + @Override + protected CellEditor getCellEditor(Object element) { + checkboxCellEditor = new CheckboxCellEditor(parent, SWT.CHECK | SWT.READ_ONLY); + return checkboxCellEditor; + } + + @Override + protected boolean canEdit(Object element) { + return true; + } + }); + TableViewerColumn columnName = createTableViewerColumn(NAME, COLUMN_NAME_SIZE, viewer); + configureColumn(columnName); + columnName.setLabelProvider(new ColumnLabelProvider() { + + @Override + public String getText(Object element) { + if (element instanceof LinkEndsMapper) { + return labelProvider.getText(((LinkEndsMapper) element).getLink()); + } + // not possible + return NOT_AVAILABLE; + } + + @Override + public Image getImage(Object element) { + return null; + } + + + }); + + TableViewerColumn columnEnds = createTableViewerColumn(ENDS, COLUMN_SIZE, viewer); + configureColumn(columnEnds); + columnEnds.setLabelProvider(new ColumnLabelProvider() { + + @Override + public String getText(Object element) { + if (element instanceof LinkEndsMapper) { + return getLabel(((LinkEndsMapper) element).getEnds()); + } + return NOT_AVAILABLE; + } + }); + + + TableViewerColumn columnSources = createTableViewerColumn(SOURCES, COLUMN_SIZE, viewer); + configureColumn(columnSources); + columnSources.setLabelProvider(new ColumnLabelProvider() { + + @Override + public String getText(Object element) { + if (element instanceof LinkEndsMapper) { + return getLabel(((LinkEndsMapper) element).getSources()); + } + return NOT_AVAILABLE; + } + }); + + TableViewerColumn columnTargets = createTableViewerColumn(TARGETS, COLUMN_SIZE, viewer); + configureColumn(columnTargets); + columnTargets.setLabelProvider(new ColumnLabelProvider() { + + @Override + public String getText(Object element) { + if (element instanceof LinkEndsMapper) { + return getLabel(((LinkEndsMapper) element).getTargets()); + } + return NOT_AVAILABLE; + } + }); + + GridData gridData = new GridData(); + gridData.verticalAlignment = GridData.FILL; + gridData.horizontalSpan = 2; + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + gridData.horizontalAlignment = GridData.FILL; + viewer.getControl().setLayoutData(gridData); + viewer.setInput(existingLinks); + parent.pack(); + return parent; + } + + /** + * {@inheritDoc} + */ + @Override + protected void buttonPressed(final int buttonId) { + if (buttonId == RESTORE_SELECTED_LINK && this.existingLinks.size() >= this.selectedElementIndex) { + this.result = this.existingLinks.get(this.selectedElementIndex).getLink(); + } + + // If the user selects CREATE or RESTORE and check the toggle button, the preferences are modified + if ((CREATE == buttonId || RESTORE_SELECTED_LINK == buttonId) && toggleState) { + final IPreferenceStore store = org.eclipse.papyrus.infra.gmfdiag.preferences.Activator.getDefault().getPreferenceStore(); + final String alwaysCreateLinkPreferenceName = PreferencesConstantsHelper.getPapyrusEditorConstant(PreferencesConstantsHelper.RESTORE_LINK_ELEMENT); + store.setValue(alwaysCreateLinkPreferenceName, true); + } + super.buttonPressed(buttonId); + } + + /** + * + * @param viewerColumn + * the viewerColumn to configure + */ + protected void configureColumn(final TableViewerColumn viewerColumn) { + viewerColumn.getColumn().setMoveable(true); + viewerColumn.getColumn().setResizable(true); + } + + /** + * + * @param list + * the list of the elements for which we want the label + * @return + * the string to display for this list + */ + private String getLabel(final Collection<?> list) { + if (list != null) { + final StringBuilder builder = new StringBuilder(); + final Iterator<?> iter = list.iterator(); + while (iter.hasNext()) { + builder.append(labelProvider.getText(iter.next())); + if (iter.hasNext()) { + builder.append(","); //$NON-NLS-1$ + } + } + return builder.toString(); + } + return NOT_AVAILABLE; + } + + /** + * + * @return + * the selected link + */ + public EObject getResult() { + return this.result; + } + + /** + * {@inheritDoc} + */ + @Override + protected Control createDialogArea(final Composite parent) { + final Control createDialogArea = super.createDialogArea(parent); + + if (createDialogArea instanceof Composite) { + createToggleButton((Composite) createDialogArea); + } + + return createDialogArea; + } + + /** + * Creates a toggle button. + * + * @param parent + * The composite in which the toggle button should be placed; + * must not be <code>null</code>. + * @return The added toggle button; never <code>null</code>. + */ + protected Button createToggleButton(final Composite parent) { + final Button button = new Button(parent, SWT.CHECK | SWT.LEFT); + final GridData data = new GridData(SWT.NONE); + data.horizontalSpan = 2; + button.setLayoutData(data); + button.setFont(parent.getFont()); + button.setText(CHECKBOX_LABEL); + button.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + toggleState = button.getSelection(); + } + + }); + + return button; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CustomDefaultSemanticEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CustomDefaultSemanticEditPolicy.java new file mode 100644 index 00000000000..65965bf1dd6 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CustomDefaultSemanticEditPolicy.java @@ -0,0 +1,44 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 419357 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.editpolicies; + +import org.eclipse.gef.commands.Command; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.helper.CreateOrShowExistingElementHelper; + +/** + * <pre> + * Custom semantic edit policy that replace DefaultSemanticEditPolicy + * in order to manage the creation of each links. + * </pre> + */ +public class CustomDefaultSemanticEditPolicy extends DefaultSemanticEditPolicy { + + private CreateOrShowExistingElementHelper existingElementHelper = new CreateOrShowExistingElementHelper(); + + /** + * {@inheritDoc} + */ + @Override + protected Command getCreateRelationshipCommand(final CreateRelationshipRequest req) { + Command defaultCommand = super.getCreateRelationshipCommand(req); + if ((defaultCommand.canExecute()) && (null != req.getSource()) && (null != req.getTarget())) { + final IElementType elementType = req.getElementType(); + defaultCommand = this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType); + } + return defaultCommand; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java index e6ae1ae2e21..56e7aa92ad5 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java @@ -1,257 +1,327 @@ -/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.helper;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
-import org.eclipse.jface.dialogs.MessageDialogWithToggle;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.papyrus.uml.diagram.common.dialogs.CreateOrShowExistingLinkDialog;
-import org.eclipse.papyrus.uml.diagram.common.messages.Messages;
-import org.eclipse.papyrus.uml.diagram.common.util.LinkEndsMapper;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- *
- * This class provides command to restore existing link instead of create new ones
- *
- *
- *
- * @author VL222926
- *
- */
-public class CreateOrShowExistingElementHelper {
-
-
- /**
- * the link helper to use. Will be used in the future
- */
- protected final ILinkMappingHelper linkMappingHelper;
-
- /**
- * preferences used to know if the dialog must be displayed or not
- */
- public static final String DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT = "Display Dialog For Create Or Restore Element"; //$NON-NLS-1$
-
- /**
- *
- * Constructor.
- *
- */
- public CreateOrShowExistingElementHelper() {
- this(new ILinkMappingHelper() {
-
- @Override
- public Collection<?> getTarget(Element link) {
- return LinkMappingHelper.getTarget(link);
- }
-
- @Override
- public Collection<?> getSource(Element link) {
- return LinkMappingHelper.getSource(link);
- }
- });
- }
-
- /**
- *
- * Constructor.
- *
- * @param linkHelper
- * the mapping helper to use to find sources and targets
- */
- public CreateOrShowExistingElementHelper(final ILinkMappingHelper linkHelper) {
- this.linkMappingHelper = linkHelper;
- }
-
- /**
- *
- * @param req
- * the create request
- * @param defaultCommand
- * the default command for this request
- * @param existingElements
- * the list of the link already existing between the source and the target for this kind of link
- * @return
- */
- public Command getCreateOrRestoreElementCommand(final CreateRelationshipRequest req, final Command defaultCommand, final IElementType linkElementType) {
- if (showDialogAccordingPreferences() && defaultCommand.canExecute()) {
- final EObject container = req.getContainer();
- if (container instanceof Element) {
- final List<LinkEndsMapper> existingElements = getExistingLinksBetweenSourceAndTarget(req, linkElementType);
- if (existingElements.size() > 0) {
- final String className = getIElementTypeNameToDisplay(linkElementType);
- final String dialogTitle = NLS.bind(Messages.CreateOrShowExistingElementHelper_CreateOrRestoreX, className);
- final String dialogMessage = NLS.bind(Messages.CreateOrShowExistingElementHelper_XBetweenTheseElementAlreadyExists, className);
- CreateOrShowExistingLinkDialog dialog = new CreateOrShowExistingLinkDialog(dialogTitle, dialogMessage, existingElements);
- return new ICommandProxy(getOpenLinkDialogCommand(req, defaultCommand, dialog, existingElements));
- }
- }
- }
- return defaultCommand;
- }
-
- /**
- *
- * @param element
- * an element
- * @param elementType
- * an element type
- * @return
- * <code>true</code> if the element has the wanted type according to the element type
- */
- protected boolean hasWantedType(final EObject element, final IElementType elementType) {
- return element.eClass() == elementType.getEClass();
- }
-
- /**
- * Returns the preferences AND Create the preference if it doesn't yet exist
- *
- * @return
- * the preference to know if a dialog must ask to the use if he wants create a new edge or restore an existing edge
- */
- protected boolean showDialogAccordingPreferences() {
- final IPreferenceStore store = org.eclipse.papyrus.uml.diagram.common.Activator.getDefault().getPreferenceStore();
- boolean contains = store.contains(DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT);
- if (!contains) {
- store.setValue(DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT, MessageDialogWithToggle.ALWAYS);
- store.setDefault(DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT, MessageDialogWithToggle.NEVER);
- }
- return store.getString(DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT).equals(MessageDialogWithToggle.ALWAYS);
- }
-
- /**
- *
- * @param elementType
- * an element type
- * @return
- * the element type to display in the dialog
- */
- protected String getIElementTypeNameToDisplay(final IElementType elementType) {
- return elementType.getEClass().getName();
- }
-
- /**
- *
- * @param request
- * the request to create the element
- * @param wantedEClass
- * @return
- * a list of {@link EdgeEndsMapper} referencing the existing links between the source and the target
- */
- protected List<LinkEndsMapper> getExistingLinksBetweenSourceAndTarget(final CreateRelationshipRequest request, final IElementType wantedElementType) {
- final List<LinkEndsMapper> existingElement = new ArrayList<LinkEndsMapper>();
- for (final Element current : ((Element) request.getContainer()).getOwnedElements()) {
- if (hasWantedType(current, wantedElementType)) {
- final Collection<?> sources = this.linkMappingHelper.getSource(current);
- final Collection<?> targets = this.linkMappingHelper.getTarget(current);
- if (sources.contains(request.getSource()) && targets.contains(request.getTarget())) {
- final EClass wantedEClass = wantedElementType.getEClass();
- if ((wantedEClass == UMLPackage.eINSTANCE.getConnector()) || (wantedEClass == UMLPackage.eINSTANCE.getAssociation())) {
- existingElement.add(new LinkEndsMapper(current, sources, null, null));
- } else {
- existingElement.add(new LinkEndsMapper(current, null, sources, targets));
- }
- }
- }
- }
- return existingElement;
- }
-
- /**
- *
- * @param request
- * the request (can't be <code>null</code>)
- * @param defaultCommand
- * the default command to use to create the semantic element (can't be <code>null</code>)
- * @param dialog
- * the dialog to open (can't be <code>null</code>)
- * @param existingEObject
- * the list of the existing objects (can't be null, neither empty
- * @return
- * the command to open the dialog AND do the selected action
- */
- public static final ICommand getOpenLinkDialogCommand(final CreateRelationshipRequest request, final Command defaultCommand, final CreateOrShowExistingLinkDialog dialog, final List<LinkEndsMapper> existingEObject) {
- final AbstractTransactionalCommand compoundCommand = new AbstractTransactionalCommand(request.getEditingDomain(), "", null) { //$NON-NLS-1$
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
- *
- * @param monitor
- * @param info
- * @return
- * @throws ExecutionException
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- int result = dialog.open();
- switch (result) {
- case CreateOrShowExistingLinkDialog.CREATE:
- // we execute the default command
- defaultCommand.execute();
- return CommandResult.newOKCommandResult(request.getNewElement());
- case CreateOrShowExistingLinkDialog.RESTORE_SELECTED_LINK:
- final EObject selectedElement = dialog.getResult();
- if (selectedElement != null) {// must always be true
- request.setNewElement(selectedElement);
- return CommandResult.newOKCommandResult(selectedElement);
- } else {
- return CommandResult.newErrorCommandResult("The selected element in the dialog is null"); //$NON-NLS-1$
- }
- default:
- return CommandResult.newCancelledCommandResult();
- }
- }
-
- /**
- *
- * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
- *
- * @return
- */
- @Override
- public boolean canExecute() {
- return defaultCommand.canExecute();
- }
- };
- return compoundCommand;
- }
-
- /**
- *
- * @return
- * the link mapping helper to use
- */
- public ILinkMappingHelper getLinkMappingHelper() {
- return linkMappingHelper;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2013 CEA LIST. + * + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 419357 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.helper; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.gef.commands.Command; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.gmf.runtime.emf.type.core.IElementType; +import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.osgi.util.NLS; +import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PreferencesConstantsHelper; +import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants; +import org.eclipse.papyrus.uml.diagram.common.dialogs.CreateOrShowExistingLinkDialog; +import org.eclipse.papyrus.uml.diagram.common.messages.Messages; +import org.eclipse.papyrus.uml.diagram.common.util.AssociationUtil; +import org.eclipse.papyrus.uml.diagram.common.util.LinkEndsMapper; +import org.eclipse.uml2.uml.AggregationKind; +import org.eclipse.uml2.uml.Association; +import org.eclipse.uml2.uml.Element; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * + * This class provides command to restore existing link instead of create new ones + * + * + * + * @author VL222926 + * + */ +public class CreateOrShowExistingElementHelper { + + + /** + * the link helper to use. Will be used in the future + */ + protected final ILinkMappingHelper linkMappingHelper; + + /** + * + * Constructor. + * + */ + public CreateOrShowExistingElementHelper() { + this(new ILinkMappingHelper() { + + @Override + public Collection<?> getTarget(Element link) { + return LinkMappingHelper.getTarget(link); + } + + @Override + public Collection<?> getSource(Element link) { + return LinkMappingHelper.getSource(link); + } + }); + } + + /** + * + * Constructor. + * + * @param linkHelper + * the mapping helper to use to find sources and targets + */ + public CreateOrShowExistingElementHelper(final ILinkMappingHelper linkHelper) { + this.linkMappingHelper = linkHelper; + } + + /** + * + * Returns the command to restore or create a element. + * + * @param req + * the create request + * @param defaultCommand + * the default command for this request + * @param existingElements + * the list of the link already existing between the source and the target for this kind of link + * @return The command to restore or create element. + */ + public Command getCreateOrRestoreElementCommand(final CreateRelationshipRequest req, final Command defaultCommand, final IElementType linkElementType) { + if (showDialogAccordingPreferences() && defaultCommand.canExecute()) { + final EObject container = req.getContainer(); + if (container instanceof Element) { + final List<LinkEndsMapper> existingElements = getExistingLinksBetweenSourceAndTarget(req, linkElementType); + if (existingElements.size() > 0) { + final String className = getIElementTypeNameToDisplay(linkElementType); + final String dialogTitle = NLS.bind(Messages.CreateOrShowExistingElementHelper_CreateOrRestoreX, className); + final String dialogMessage = NLS.bind(Messages.CreateOrShowExistingElementHelper_XBetweenTheseElementAlreadyExists, className); + CreateOrShowExistingLinkDialog dialog = new CreateOrShowExistingLinkDialog(dialogTitle, dialogMessage, existingElements); + return new ICommandProxy(getOpenLinkDialogCommand(req, defaultCommand, dialog, existingElements)); + } + } + } + return defaultCommand; + } + + /** + * + * Comparison of two types. + * + * @param element + * an element + * @param elementType + * an element type + * @return + * <code>true</code> if the element has the wanted type according to the element type + */ + protected boolean hasWantedType(final EObject element, final IElementType elementType) { + return element.eClass() == elementType.getEClass(); + } + + /** + * + * Returns the preferences AND Create the preference if it doesn't yet exist. + * + * @return + * the preference to know if a dialog must ask to the use if he wants create a new edge or restore an existing edge + */ + protected boolean showDialogAccordingPreferences() { + boolean showDialog = true; + final IPreferenceStore store = org.eclipse.papyrus.infra.gmfdiag.preferences.Activator.getDefault().getPreferenceStore(); + final String preferenceName = PreferencesConstantsHelper.getPapyrusEditorConstant(PreferencesConstantsHelper.RESTORE_LINK_ELEMENT); + + // If the store contains the preference, return the inverse of the value stored in the preferences. + final boolean contains = store.contains(preferenceName); + if (contains) { + showDialog = !store.getBoolean(preferenceName); + } + return showDialog; + } + + /** + * + * Returns the name of the element type. + * + * @param elementType + * an element type + * @return + * the element type to display in the dialog + */ + protected String getIElementTypeNameToDisplay(final IElementType elementType) { + return elementType.getEClass().getName(); + } + + /** + * + * Returns the value of parameter "navigable" of the request. + * + * @param source + * If the member tested is the source. + * @param request + * The creation relationship request. + * @return The value "navigable" of the member tested. + */ + private boolean getExpectedNavigable(final boolean source, final CreateRelationshipRequest request) { + Object isAffects = null; + boolean expectedNavigable = false; + + // Get the parameter "affects Target" to check if the target is navigable + if (!source) { + isAffects = request.getParameter(RequestParameterConstants.AFFECTS_TARGET); + + if (null != isAffects && isAffects.equals(true)) { + expectedNavigable = true; + } + } + + return expectedNavigable; + } + + /** + * + * Returns the existing links between two objects. + * + * @param request + * the request to create the element + * @param wantedEClass + * @return + * a list of {@link EdgeEndsMapper} referencing the existing links between the source and the target + */ + protected List<LinkEndsMapper> getExistingLinksBetweenSourceAndTarget(final CreateRelationshipRequest request, final IElementType wantedElementType) { + final List<LinkEndsMapper> existingElement = new ArrayList<LinkEndsMapper>(); + final EClass wantedEClass = wantedElementType.getEClass(); + + if (UMLPackage.eINSTANCE.getAssociation().equals(wantedEClass)) { + for (final Element current : ((Element) request.getContainer()).getOwnedElements()) { + if (hasWantedType(current, wantedElementType)) { + final Collection<?> sources = this.linkMappingHelper.getSource(current); + final Collection<?> targets = this.linkMappingHelper.getTarget(current); + if (sources.contains(request.getSource()) && targets.contains(request.getTarget())) { + boolean identicalAssociation = true; + final Iterator<Property> iterator = ((Association) current).getMemberEnds().iterator(); + + while (iterator.hasNext() && identicalAssociation) { + final Property property = iterator.next(); + final boolean source = request.getSource().equals(property.getType()); + + boolean expectedNavigable = getExpectedNavigable(source, request); + + if (!AssociationUtil.isIdenticalProperties(expectedNavigable, AggregationKind.NONE_LITERAL, property)) { + identicalAssociation = false; + } + } + + if (identicalAssociation) { + existingElement.add(new LinkEndsMapper(current, sources, null, null)); + } + } + } + } + } else { + for (final Element current : ((Element) request.getContainer()).getOwnedElements()) { + if (hasWantedType(current, wantedElementType)) { + final Collection<?> sources = this.linkMappingHelper.getSource(current); + final Collection<?> targets = this.linkMappingHelper.getTarget(current); + if (sources.contains(request.getSource()) && targets.contains(request.getTarget())) { + if (UMLPackage.eINSTANCE.getConnector().equals(wantedEClass)) { + existingElement.add(new LinkEndsMapper(current, sources, null, null)); + } else { + existingElement.add(new LinkEndsMapper(current, null, sources, targets)); + } + } + } + } + } + return existingElement; + } + + /** + * + * Returns the open link dialog. + * + * @param request + * the request (can't be <code>null</code>) + * @param defaultCommand + * the default command to use to create the semantic element (can't be <code>null</code>) + * @param dialog + * the dialog to open (can't be <code>null</code>) + * @param existingEObject + * the list of the existing objects (can't be null, neither empty + * @return + * the command to open the dialog AND do the selected action + */ + public static final ICommand getOpenLinkDialogCommand(final CreateRelationshipRequest request, final Command defaultCommand, final CreateOrShowExistingLinkDialog dialog, final List<LinkEndsMapper> existingEObject) { + final AbstractTransactionalCommand compoundCommand = new AbstractTransactionalCommand(request.getEditingDomain(), "", null) { //$NON-NLS-1$ + + /** + * + * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) + * + * @param monitor + * @param info + * @return + * @throws ExecutionException + */ + @Override + protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + int result = dialog.open(); + switch (result) { + case CreateOrShowExistingLinkDialog.CREATE: + // we execute the default command + defaultCommand.execute(); + return CommandResult.newOKCommandResult(request.getNewElement()); + case CreateOrShowExistingLinkDialog.RESTORE_SELECTED_LINK: + final EObject selectedElement = dialog.getResult(); + if (selectedElement != null) {// must always be true + request.setNewElement(selectedElement); + return CommandResult.newOKCommandResult(selectedElement); + } else { + return CommandResult.newErrorCommandResult("The selected element in the dialog is null"); //$NON-NLS-1$ + } + default: + return CommandResult.newCancelledCommandResult(); + } + } + + /** + * + * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute() + * + * @return + */ + @Override + public boolean canExecute() { + return defaultCommand.canExecute(); + } + }; + return compoundCommand; + } + + /** + * + * @return + * the link mapping helper to use + */ + public ILinkMappingHelper getLinkMappingHelper() { + return linkMappingHelper; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/Messages.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/Messages.java index 6e61c287366..e94d390daf4 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/Messages.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/Messages.java @@ -9,6 +9,7 @@ * * Contributors: * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation + * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 419357 * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.common.messages; @@ -39,6 +40,8 @@ public class Messages extends NLS { public static String CreateOrShowExistingElementHelper_XBetweenTheseElementAlreadyExists; + public static String CreateOrShowExistingElementHelper_AlwaysCreateNewLink; + public static String CreateOrShowExistingLinkDialog_Create; public static String CreateOrShowExistingLinkDialog_Ends; @@ -52,7 +55,7 @@ public class Messages extends NLS { public static String CreateOrShowExistingLinkDialog_Sources; public static String CreateOrShowExistingLinkDialog_Targets; - + public static String CreateOrSelectTypeDialog_DialogTitle; public static String CreateOrSelectTypeDialog_SelectionSectionTitle; @@ -74,7 +77,7 @@ public class Messages extends NLS { public static String CreateOrSelectTypeDialog_SelectNewTypeContainerDialogTitle; public static String CreateOrSelectTypeDialog_SelectNewTypeContainerDialogMessage; - + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/messages.properties b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/messages.properties index fdda9f02625..0ced120eb38 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/messages.properties +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/messages.properties @@ -1,5 +1,6 @@ CreateOrShowExistingElementHelper_CreateOrRestoreX=Create or Restore {0} CreateOrShowExistingElementHelper_XBetweenTheseElementAlreadyExists={0} between these elements already exists in the model.\nDo you want to restore it? +CreateOrShowExistingElementHelper_AlwaysCreateNewLink=Do not show this again. Always create a new link. CreateOrShowExistingLinkDialog_Create=Create CreateOrShowExistingLinkDialog_Ends=Ends CreateOrShowExistingLinkDialog_Name=Name diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/CustomEditPolicyProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/CustomEditPolicyProvider.java new file mode 100644 index 00000000000..82506653ac6 --- /dev/null +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/CustomEditPolicyProvider.java @@ -0,0 +1,59 @@ +/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 419357 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.providers; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.EditPolicy; +import org.eclipse.gmf.runtime.common.core.service.AbstractProvider; +import org.eclipse.gmf.runtime.common.core.service.IOperation; +import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles; +import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation; +import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider; +import org.eclipse.papyrus.infra.gmfdiag.common.editpart.NodeEditPart; +import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.DefaultSemanticEditPolicy; +import org.eclipse.papyrus.uml.diagram.common.editpolicies.CustomDefaultSemanticEditPolicy; + +/** + * Edit policy provider for the editParts which used DefaultSemanticPolicy for Semantic Role. + */ +public class CustomEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider { + + /** + * {@inheritDoc} + */ + @Override + public boolean provides(final IOperation operation) { + if (operation instanceof CreateEditPoliciesOperation) { + final EditPart editPart = ((CreateEditPoliciesOperation) operation).getEditPart(); + if (editPart instanceof NodeEditPart) { + final EditPolicy editPolicy = editPart.getEditPolicy(EditPolicyRoles.SEMANTIC_ROLE); + if (null != editPolicy) { + if (editPolicy instanceof DefaultSemanticEditPolicy) { + return true; + } + } + } + } + + return false; + } + + /** + * {@inheritDoc} + */ + @Override + public void createEditPolicies(EditPart editPart) { + editPart.installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new CustomDefaultSemanticEditPolicy()); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/AssociationUtil.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/AssociationUtil.java index 2a54b32ff11..887ee1f6223 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/AssociationUtil.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/AssociationUtil.java @@ -1,10 +1,84 @@ -package org.eclipse.papyrus.uml.diagram.common.util;
-
-import org.eclipse.uml2.uml.Property;
-
-public class AssociationUtil {
-
- public static boolean isAssociationEndProperty(Property property) {
- return property.getAssociation() != null;
- }
-}
+/***************************************************************************** + * Copyright (c) 2015 CEA LIST and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Fanch Bonnabesse (ALL4TEC) fanch.bonnabesse@alltec.net - Bug 419357 + * + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.common.util; + +import org.eclipse.uml2.uml.AggregationKind; +import org.eclipse.uml2.uml.Property; + +/** + * + * An utility class to use association. + * + */ +public class AssociationUtil { + + public static boolean isAssociationEndProperty(Property property) { + return property.getAssociation() != null; + } + + /** + * This compares the Property of an Association with expected informations. + * + * @param expectedNavigable + * The expected navigable information. + * @param expectedAggregation + * The expected kind of aggregation. + * @param property + * The property containing the aggregation to compare. + * @return The result of the comparison. + */ + public static boolean isIdenticalProperties(final boolean expectedNavigable, final AggregationKind expectedAggregation, final Property property) { + return (isIdenticalAggregations(expectedAggregation, property) && isIdenticalNavigables(expectedNavigable, property)); + } + + /** + * This compares the aggregation information of a Property with an expected kind of aggregation. + * + * @param expectedAggregation + * The expected kind of aggregation. + * @param property + * The property containing the aggregation to compare. + * @return The result of the comparison. + */ + public static boolean isIdenticalAggregations(final AggregationKind expectedAggregation, final Property property) { + boolean identicalAggregation = false; + + final AggregationKind aggregation = property.getAggregation(); + + if (expectedAggregation.equals(aggregation)) { + identicalAggregation = true; + } + + return identicalAggregation; + } + + /** + * This compares the navigable information of a Property with an expected navigable. + * + * @param expectedNavigable + * The expected navigable information. + * @param property + * The property containing the navigable information to compare. + * @return The result of the comparison. + */ + public static boolean isIdenticalNavigables(final boolean expectedNavigable, final Property property) { + boolean identicalNavigable = false; + final boolean navigable = property.isNavigable(); + + if (expectedNavigable == navigable) { + identicalNavigable = true; + } + + return identicalNavigable; + } +} |