Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Fasani2020-10-23 14:29:42 +0000
committerLaurent Fasani2020-10-27 15:50:52 +0000
commit1917c60fe2a78e55fcda85ce1a60255fc8ab9b20 (patch)
treed127dac582df96b54ff527c7eb25868705e746f0 /plugins
parentc4a51f50dd49c68754d852baa50e73e4f838c15a (diff)
downloadorg.eclipse.sirius-1917c60fe2a78e55fcda85ce1a60255fc8ab9b20.tar.gz
org.eclipse.sirius-1917c60fe2a78e55fcda85ce1a60255fc8ab9b20.tar.xz
org.eclipse.sirius-1917c60fe2a78e55fcda85ce1a60255fc8ab9b20.zip
[568180] Enhance Sirius DAnalysisSelector to allow customization
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=568180 Change-Id: I32861495267676ad2ab2550652ca4fe8cddf2b32 Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.sirius.ui/plugin.properties3
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/analysis/SmartDialogAnalysisSelector.java72
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/dialogs/AnalysisSelectorFilteredItemsSelectionDialog.java63
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/MoveRepresentationAction.java30
-rw-r--r--plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java3
5 files changed, 92 insertions, 79 deletions
diff --git a/plugins/org.eclipse.sirius.ui/plugin.properties b/plugins/org.eclipse.sirius.ui/plugin.properties
index 044e2f7f55..15e65e44dd 100644
--- a/plugins/org.eclipse.sirius.ui/plugin.properties
+++ b/plugins/org.eclipse.sirius.ui/plugin.properties
@@ -60,7 +60,6 @@ AddSemanticResourceAction_title = Add Model
AnalysisSelectorFilteredItemsSelectionDialog_labelProviderDefault = In
AnalysisSelectorFilteredItemsSelectionDialog_labelProviderLocal = Local (in {0})
AnalysisSelectorFilteredItemsSelectionDialog_helpMessage = On this dialog window is presented a list of all the other locations (.aird file) where you can move the selected representation.
-AnalysisSelectorFilteredItemsSelectionDialog_defaultHeader = Select the location where the representation will be placed.
AskSessionOpeningRunnable_title = Session resource version mismatch
AskSessionOpeningRunnable_message_aird = You are trying to open a session with an .aird file coming from a more recent Sirius release:\n\n\t{0}\n
AskSessionOpeningRunnable_message_confirm = \nThe result is unpredictable and can lead to data corruption. Are you sure you want to open it?
@@ -368,7 +367,7 @@ SmartDialogAnalysisSelector_otherFragments = Analysis selection
SmartDialogAnalysisSelector_titleWithRepresentationName = Location selection for "{0}"
SmartDialogAnalysisSelector_messageWithRepresentationName = Select a location where the representation "{0}" will be placed.
SmartDialogAnalysisSelector_titleWithoutRepresentationName = Location selection
-SmartDialogAnalysisSelector_messageWithoutRepresentationName = Select a location.
+SmartDialogAnalysisSelector_messageWithoutRepresentationName = Select a location where the representation will be placed.
SpecificEditorInputTranformer_defaultFileName = file
SpecificEditorInputTranformer_newRepresentationName = new representation
SpecificEditorInputTranformer_transformationFailure = Failing of EditorInput transformation.
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/analysis/SmartDialogAnalysisSelector.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/analysis/SmartDialogAnalysisSelector.java
index ecba0c1b22..d38ee35d70 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/analysis/SmartDialogAnalysisSelector.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/business/api/session/analysis/SmartDialogAnalysisSelector.java
@@ -15,21 +15,18 @@ package org.eclipse.sirius.ui.business.api.session.analysis;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.RunnableWithResult;
import org.eclipse.jface.window.Window;
-import org.eclipse.sirius.business.api.query.DRepresentationQuery;
-import org.eclipse.sirius.business.api.query.EObjectQuery;
import org.eclipse.sirius.business.api.session.danalysis.DAnalysisSelector;
import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil;
import org.eclipse.sirius.ui.tools.api.dialogs.AnalysisSelectorFilteredItemsSelectionDialog;
import org.eclipse.sirius.viewpoint.DAnalysis;
import org.eclipse.sirius.viewpoint.DRepresentation;
-import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
-import org.eclipse.sirius.viewpoint.ViewpointPackage;
+import org.eclipse.sirius.viewpoint.DSemanticDecorator;
import org.eclipse.sirius.viewpoint.provider.Messages;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
@@ -40,7 +37,7 @@ import org.eclipse.swt.widgets.Shell;
* @author mchauvin
*/
public class SmartDialogAnalysisSelector implements DAnalysisSelector {
-
+
/**
* The dialog that displays the analysis where the representation will be placed.
*/
@@ -53,10 +50,10 @@ public class SmartDialogAnalysisSelector implements DAnalysisSelector {
@Override
public DAnalysis selectSmartlyAnalysisForAddedRepresentation(final DRepresentation representation, final Collection<DAnalysis> allAnalysis) {
- DAnalysis selectSmartlyAnalysis = selectSmartlyAnalysis(allAnalysis, representation.getName());
+ DAnalysis selectSmartlyAnalysis = selectSmartlyAnalysis(allAnalysis, representation);
+ // The dialog may be canceled with Esc key but Sirius does not support a null DAnalysis
if (selectSmartlyAnalysis == null) {
- DRepresentationDescriptor representationDescriptor = new DRepresentationQuery(representation).getRepresentationDescriptor();
- selectSmartlyAnalysis = (DAnalysis) new EObjectQuery(representationDescriptor).getFirstAncestorOfType(ViewpointPackage.eINSTANCE.getDAnalysis()).get();
+ selectSmartlyAnalysis = allAnalysis.iterator().next();
}
return selectSmartlyAnalysis;
}
@@ -66,18 +63,21 @@ public class SmartDialogAnalysisSelector implements DAnalysisSelector {
*
* @param allAnalysis
* all available analysis
+ * @param representation
+ * the representation
* @return selected analysis
*/
- private DAnalysis selectSmartlyAnalysis(final Collection<DAnalysis> allAnalysis, String representationName) {
-
+ protected DAnalysis selectSmartlyAnalysis(final Collection<DAnalysis> allAnalysis, DRepresentation representation) {
RunnableWithResult<Object> runnable = new RunnableWithResult.Impl<Object>() {
@Override
public void run() {
-
- dialog = createAnalysisSelectorDialog(Display.getDefault().getActiveShell(), allAnalysis.iterator().next(), allAnalysis, new ArrayList<>(allAnalysis));
+
+ dialog = createAnalysisSelectorDialog(Display.getDefault().getActiveShell(), getDefaultDAnalysis(allAnalysis, representation), allAnalysis, new ArrayList<>(allAnalysis),
+ representation);
dialog.setSeparatorLabel(Messages.SmartDialogAnalysisSelector_otherFragments);
+ String representationName = representation.getName();
if (representationName != null && !representationName.isEmpty()) {
dialog.setTitle(MessageFormat.format(Messages.SmartDialogAnalysisSelector_titleWithRepresentationName, representationName));
dialog.setMessage(MessageFormat.format(Messages.SmartDialogAnalysisSelector_messageWithRepresentationName, representationName));
@@ -86,10 +86,6 @@ public class SmartDialogAnalysisSelector implements DAnalysisSelector {
dialog.setMessage(Messages.SmartDialogAnalysisSelector_messageWithoutRepresentationName);
}
- if (allAnalysis.iterator().next() != null) {
- dialog.setInitialElementSelections(Collections.singletonList(allAnalysis.iterator().next()));
- }
-
if (dialog.open() == Window.OK) {
if (dialog.getFirstResult() != null) {
setResult(dialog.getFirstResult());
@@ -102,10 +98,39 @@ public class SmartDialogAnalysisSelector implements DAnalysisSelector {
};
/* synch execution as the user need to choose before we can get further */
EclipseUIUtil.displaySyncExec(runnable);
- if (runnable.getResult() instanceof DAnalysis) {
- return (DAnalysis) runnable.getResult();
+ return (DAnalysis) runnable.getResult();
+ }
+
+ /**
+ * Get the default DAnalysis.
+ *
+ * @param allAnalysis
+ * All candidate DAnalysis.
+ * @param representation
+ * The representation.
+ * @return The default DAnalysis.
+ */
+ protected DAnalysis getDefaultDAnalysis(Collection<DAnalysis> allAnalysis, DRepresentation representation) {
+ DAnalysis defaultDAnalysis = null;
+ if (allAnalysis.size() > 0) {
+ EObject targetElement = ((DSemanticDecorator) representation).getTarget();
+ Resource targetResource = targetElement.eResource();
+
+ // If different analysis candidates are available, sort them smartly to ease the end-user selection.
+
+ // Loop over analysis candidates.
+ for (DAnalysis candidateAnalysis : allAnalysis) {
+ for (EObject semanticElement : candidateAnalysis.getModels()) {
+ // Is semantic element contains in the same resource ?
+ if (targetResource.equals(semanticElement.eResource())) {
+ // Yes it is :)
+ return candidateAnalysis;
+ }
+ }
+ }
+ defaultDAnalysis = allAnalysis.iterator().next();
}
- return null;
+ return defaultDAnalysis;
}
/**
@@ -119,10 +144,13 @@ public class SmartDialogAnalysisSelector implements DAnalysisSelector {
* all the analysis available
* @param bestCandidates
* list of best candidates
+ * @param representation
+ * the representation for which to select the DAnalysis
* @return the dialog that will be used for selecting the targeted {@link DAnalysis}
*/
- protected AnalysisSelectorFilteredItemsSelectionDialog createAnalysisSelectorDialog(Shell shell, DAnalysis bestCandidate, Collection<DAnalysis> allAnalysis, List<DAnalysis> bestCandidates) {
- return new AnalysisSelectorFilteredItemsSelectionDialog(Display.getDefault().getActiveShell(), allAnalysis.iterator().next(), allAnalysis, new ArrayList<>(allAnalysis));
+ protected AnalysisSelectorFilteredItemsSelectionDialog createAnalysisSelectorDialog(Shell shell, DAnalysis bestCandidate, Collection<DAnalysis> allAnalysis, List<DAnalysis> bestCandidates,
+ DRepresentation representation) {
+ return new AnalysisSelectorFilteredItemsSelectionDialog(Display.getDefault().getActiveShell(), allAnalysis.iterator().next(), allAnalysis, new ArrayList<>(allAnalysis), false);
}
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/dialogs/AnalysisSelectorFilteredItemsSelectionDialog.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/dialogs/AnalysisSelectorFilteredItemsSelectionDialog.java
index 34df27ff87..9902686493 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/dialogs/AnalysisSelectorFilteredItemsSelectionDialog.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/dialogs/AnalysisSelectorFilteredItemsSelectionDialog.java
@@ -28,7 +28,6 @@ import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.widgets.WidgetFactory;
-import org.eclipse.sirius.common.ui.tools.api.util.EclipseUIUtil;
import org.eclipse.sirius.ui.tools.api.views.ViewHelper;
import org.eclipse.sirius.ui.tools.internal.views.common.SessionLabelProvider;
import org.eclipse.sirius.viewpoint.DAnalysis;
@@ -42,7 +41,6 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog;
@@ -66,6 +64,11 @@ public class AnalysisSelectorFilteredItemsSelectionDialog extends FilteredItemsS
*/
protected String helpMessage = Messages.AnalysisSelectorFilteredItemsSelectionDialog_helpMessage;
+ /**
+ * The availability of the cancel button.
+ */
+ protected boolean allowCancel;
+
private final DAnalysis bestCandidate;
private final Collection<DAnalysis> allAnalysis;
@@ -74,10 +77,6 @@ public class AnalysisSelectorFilteredItemsSelectionDialog extends FilteredItemsS
private final ILabelProvider labelProvider;
- private Text messageText;
-
- private final String defaultHeader = Messages.AnalysisSelectorFilteredItemsSelectionDialog_defaultHeader;
-
/**
* Default constructor.
*
@@ -89,8 +88,10 @@ public class AnalysisSelectorFilteredItemsSelectionDialog extends FilteredItemsS
* all the analysis available
* @param bestCandidates
* list of best candidates
+ * @param allowCancel
+ * if true a cancel button is available. If the dialog is cancelled, a null DAnalysis is set as a result.
*/
- public AnalysisSelectorFilteredItemsSelectionDialog(Shell shell, DAnalysis bestCandidate, Collection<DAnalysis> allAnalysis, List<DAnalysis> bestCandidates) {
+ public AnalysisSelectorFilteredItemsSelectionDialog(Shell shell, DAnalysis bestCandidate, Collection<DAnalysis> allAnalysis, List<DAnalysis> bestCandidates, boolean allowCancel) {
super(shell);
this.bestCandidate = bestCandidate;
this.allAnalysis = allAnalysis;
@@ -99,6 +100,8 @@ public class AnalysisSelectorFilteredItemsSelectionDialog extends FilteredItemsS
this.setHelpAvailable(true);
setDetailsLabelProvider(this.labelProvider);
setListLabelProvider(this.labelProvider);
+ setInitialSelections(bestCandidate);
+ this.allowCancel = allowCancel;
}
protected ILabelProvider getLocationLabelProvider() {
@@ -118,31 +121,10 @@ public class AnalysisSelectorFilteredItemsSelectionDialog extends FilteredItemsS
}
return result;
}
-
};
}
/**
- * Changes the header message.
- *
- * @param text
- * new message to display in the header
- */
- public void setHeaderMessageText(String text) {
- EclipseUIUtil.displaySyncExec(new Runnable() {
- public void run() {
- if (!PlatformUI.getWorkbench().isClosing() && messageText != null) {
- if (text.isEmpty()) {
- messageText.setText(defaultHeader);
- } else {
- messageText.setText(text);
- }
- }
- }
- });
- }
-
- /**
* This method was overridden with the goal to add a text at the top of the dialog.
*/
@Override
@@ -152,14 +134,8 @@ public class AnalysisSelectorFilteredItemsSelectionDialog extends FilteredItemsS
layout.marginWidth = 0;
layout.verticalSpacing = 0;
Composite composite = WidgetFactory.composite(0).layout(layout).layoutData(new GridData(GridData.FILL_BOTH)).create(parent);
- messageText = new Text(composite, SWT.READ_ONLY);
- messageText.setText(defaultHeader);
- final GridData anyElementData = new GridData();
- anyElementData.horizontalAlignment = GridData.FILL;
- anyElementData.horizontalIndent = 8;
- anyElementData.verticalIndent = 8;
- anyElementData.grabExcessHorizontalSpace = true;
- messageText.setLayoutData(anyElementData);
+ createHeaderMessagePart(composite);
+
applyDialogFont(composite);
// initialize the dialog units
initializeDialogUnits(composite);
@@ -179,11 +155,19 @@ public class AnalysisSelectorFilteredItemsSelectionDialog extends FilteredItemsS
return parent;
}
+ /**
+ * Create the part containing the header messages.
+ *
+ * @param parent
+ * the parent composite
+ */
+ protected void createHeaderMessagePart(Composite parent) {
+ }
+
protected String getHelpMessage() {
return helpMessage;
}
-
@Override
protected Control createExtendedContentArea(Composite parent) {
return null;
@@ -193,7 +177,9 @@ public class AnalysisSelectorFilteredItemsSelectionDialog extends FilteredItemsS
protected void createButtonsForButtonBar(Composite parent) {
// create OK and Cancel button
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
- createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ if (allowCancel) {
+ createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+ }
}
@Override
@@ -266,7 +252,6 @@ public class AnalysisSelectorFilteredItemsSelectionDialog extends FilteredItemsS
}
return o2.equals(bestCandidate) ? +2 : labelProvider.getText(o1).compareTo(labelProvider.getText(o2));
}
-
};
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/MoveRepresentationAction.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/MoveRepresentationAction.java
index 9e377ef417..de83828476 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/MoveRepresentationAction.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/action/MoveRepresentationAction.java
@@ -17,6 +17,7 @@ import java.util.Collection;
import java.util.Collections;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
@@ -83,7 +84,7 @@ public class MoveRepresentationAction extends Action {
this.setEnabled(false);
}
}
-
+
/**
* Construct a new instance.
*
@@ -118,15 +119,19 @@ public class MoveRepresentationAction extends Action {
Option<EObject> dAnalysisOption = new EObjectQuery(dRepresentationDescriptor).getFirstAncestorOfType(ViewpointPackage.eINSTANCE.getDAnalysis());
Collection<DAnalysis> analysesCandidates = ((DAnalysisSession) session).allAnalyses();
analysesCandidates.remove(dAnalysisOption.get());
- DAnalysis selectedDAnalysis = dAnalysisSelector.selectSmartlyAnalysisForAddedRepresentation(dRepresentationDescriptor.getRepresentation(), analysesCandidates);
- if (selectedDAnalysis != dAnalysisOption.get()) {
- session.getTransactionalEditingDomain().getCommandStack()
- .execute(new MoveRepresentationCommand(session, selectedDAnalysis, Collections.<DRepresentationDescriptor> singleton(dRepresentationDescriptor)));
+ try {
+ DAnalysis selectedDAnalysis = dAnalysisSelector.selectSmartlyAnalysisForAddedRepresentation(dRepresentationDescriptor.getRepresentation(), analysesCandidates);
+ if (selectedDAnalysis != dAnalysisOption.get()) {
+ session.getTransactionalEditingDomain().getCommandStack()
+ .execute(new MoveRepresentationCommand(session, selectedDAnalysis, Collections.<DRepresentationDescriptor> singleton(dRepresentationDescriptor)));
+ }
+ } catch (OperationCanceledException e) {
+ // do nothing
}
}
-
+
} else {
-
+
final IEditingSession uiSession = SessionUIManager.INSTANCE.getUISession(session);
if (uiSession != null) {
for (final DRepresentationDescriptor repDescriptor : repDescriptors) {
@@ -148,16 +153,15 @@ public class MoveRepresentationAction extends Action {
private boolean isValidSelection() {
if (targetAnalysis == null) {
-
return session.getReferencedSessionResources().size() > 0;
} else {
boolean anyInvalidMove = Iterables.any(repDescriptors, new Predicate<DRepresentationDescriptor>() {
-
+
@Override
public boolean apply(DRepresentationDescriptor input) {
boolean invalid = false; // false is the default value
-
+
// Step 1: Check source representation container
EObject container = input.eContainer();
if (container instanceof DView) {
@@ -166,7 +170,7 @@ public class MoveRepresentationAction extends Action {
invalid = true;
}
}
-
+
// Step 2: Check target representation container
if (!invalid) {
DView targetContainer = DAnalysisSessionHelper.findDViewForAddedRepresentation(targetAnalysis, input.getDescription());
@@ -177,11 +181,11 @@ public class MoveRepresentationAction extends Action {
}
}
}
-
+
return invalid;
}
});
-
+
return !anyInvalidMove;
}
}
diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java
index c1448fcf49..68bc359dc7 100644
--- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java
+++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/viewpoint/provider/Messages.java
@@ -161,9 +161,6 @@ public final class Messages {
public static String AnalysisSelectorFilteredItemsSelectionDialog_helpMessage;
@TranslatableMessage
- public static String AnalysisSelectorFilteredItemsSelectionDialog_defaultHeader;
-
- @TranslatableMessage
public static String AnalysisSelectorFilteredItemsSelectionDialog_labelProviderDefault;
@TranslatableMessage

Back to the top