diff options
| author | Laurent Redor | 2018-01-12 13:33:49 +0000 |
|---|---|---|
| committer | Laurent Redor | 2018-01-29 08:27:14 +0000 |
| commit | 7d1c04a1e090c5cc0df13bf7b743afa551662559 (patch) | |
| tree | e79ed38a645316c0392c59f575a4faa84c51855c | |
| parent | 11513c142681c32e22dc4df8fa2f0ef600c25e0b (diff) | |
| download | org.eclipse.sirius-7d1c04a1e090c5cc0df13bf7b743afa551662559.tar.gz org.eclipse.sirius-7d1c04a1e090c5cc0df13bf7b743afa551662559.tar.xz org.eclipse.sirius-7d1c04a1e090c5cc0df13bf7b743afa551662559.zip | |
[530431] Add standard diagram services to get views
This commit adds some services to get a list of views, ie
DSemanticDecorator, from a diagram according to different aspects:
* representing semantic elements having same EType as current selected
elements
* same mapping as current selected elements
* representing semantic elements having the EType selected by the
end-user (this service will be improve later with completion in the
dialog)
* corresponding to an expression written by the end-user (this service
will be improve later with completion and perhaps with validation in the
dialog)
These services are currently not documented in the release notes as it
is more for a POC.
Bug: 530431
Change-Id: I959218e2489c8063f5917f852b2e0ec3aaf5f7e4
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
4 files changed, 242 insertions, 0 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF index 9338d0c4b0..61f2215028 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.diagram.ui/META-INF/MANIFEST.MF @@ -117,6 +117,7 @@ Export-Package: org.eclipse.sirius.diagram.description.concern.provider;version= org.eclipse.sirius.diagram.ui.tools.api.graphical.edit.palette;version="2.0.4", org.eclipse.sirius.diagram.ui.tools.api.graphical.edit.styles;version="2.0.4", org.eclipse.sirius.diagram.ui.tools.api.image;version="3.0.0", + org.eclipse.sirius.diagram.ui.tools.api.interpreter;version="5.1.2", org.eclipse.sirius.diagram.ui.tools.api.layout;version="3.1.0", org.eclipse.sirius.diagram.ui.tools.api.layout.ordering;version="2.0.4", org.eclipse.sirius.diagram.ui.tools.api.layout.provider;version="2.0.5", diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties index 37ec6a5d38..5177eb87c6 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties @@ -1185,6 +1185,12 @@ SnapBackDistantLabelsMigrationParticipant_nodesMoved = \u0020Some nodes have als SnapBackDistantLabelsMigrationParticipant_severalLabelsSnapBacked = \n\t* {0} labels of edge have been reset to their default location in diagram "{1}". SnapBackDistantLabelsMigrationParticipant_title = Migration done for "Corrupted edge labels" (the result of this migration will be saved on the next session save): SpecificationMenuContribution_openDefinitionMenuLabel = Open Definition +StandardDiagramServices_sameETypeTitle = Select all elements of type +StandardDiagramServices_sameETypeMessage = Choose the domain class of elements to select: +StandardDiagramServices_sameETypeTooltip = Type the name of the domain class of elements to select.\nFor instance in Ecore you can have 'ecore::EReference'. +StandardDiagramServices_expressionTitle = Select all elements returned by an expression +StandardDiagramServices_expressionMessage = Expression returning the views to select: +StandardDiagramServices_expressionTooltip = Expression returning the views to select.\nFor example: aql:self.ownedDiagramElements->select( dde | dde.name.startsWith('C0')) StatusDecorator_validationMarkersFailureMsg = Validation markers refresh failure StatusDecorator_viewIdAccessFailureMsg = ViewID access failure StraightenToAction_commandLabel = Straighten edges To diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java index 926074fe07..4f4661968b 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java @@ -1329,6 +1329,24 @@ public final class Messages { public static String SpecificationMenuContribution_openDefinitionMenuLabel; @TranslatableMessage + public static String StandardDiagramServices_sameETypeTitle; + + @TranslatableMessage + public static String StandardDiagramServices_sameETypeMessage; + + @TranslatableMessage + public static String StandardDiagramServices_sameETypeTooltip; + + @TranslatableMessage + public static String StandardDiagramServices_expressionTitle; + + @TranslatableMessage + public static String StandardDiagramServices_expressionMessage; + + @TranslatableMessage + public static String StandardDiagramServices_expressionTooltip; + + @TranslatableMessage public static String StatusDecorator_validationMarkersFailureMsg; @TranslatableMessage diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/tools/api/interpreter/StandardDiagramServices.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/tools/api/interpreter/StandardDiagramServices.java new file mode 100644 index 0000000000..c2748e78eb --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/tools/api/interpreter/StandardDiagramServices.java @@ -0,0 +1,217 @@ +/******************************************************************************* + * Copyright (c) 2018 THALES GLOBAL SERVICES. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.api.interpreter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.window.Window; +import org.eclipse.sirius.business.api.session.Session; +import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; +import org.eclipse.sirius.common.tools.api.util.StringUtil; +import org.eclipse.sirius.diagram.DDiagramElement; +import org.eclipse.sirius.diagram.DSemanticDiagram; +import org.eclipse.sirius.diagram.business.api.query.DDiagramQuery; +import org.eclipse.sirius.diagram.description.DiagramElementMapping; +import org.eclipse.sirius.diagram.ui.provider.Messages; +import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor; +import org.eclipse.sirius.viewpoint.DSemanticDecorator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + +/** + * Class owning methods used for service: interpreter. The service methods should be prefixed by std to avoid conflict + * with other services. + * + * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> + */ +public class StandardDiagramServices { + /** + * A green color for all field representing a domain class (like in SiriusEditor.colorRegistry). + */ + private static final RGB DOMAIN_CLASS_FIELD_COLOR = new RGB(204, 242, 166); + + /** + * A yellow color for all field representing an interpreted expression (like in SiriusEditor.colorRegistry). + */ + private static final RGB INTERPRETED_EXPRESSION_FIELD_COLOR = new RGB(255, 245, 181); + + private Color domainClassFieldColor; + + private Color interpretedExpressionFieldColor; + + /** + * Default constructor. + */ + public StandardDiagramServices() { + } + + /** + * Return the list of DSemanticDecorator having the same mappings as <code>selectedViews</code> in the + * <code>currentDiagram</code>. + * + * @param currentDiagram + * The current {@link DSemanticDiagram} + * @param selectedViews + * The selected views. If there are several selected views all mappings associated to this views will be + * considered. + * @return A list of DSemanticDecorator having the same mappings as already selected views. + */ + public List<DSemanticDecorator> stdGetViewsWithSameMapping(DSemanticDiagram currentDiagram, List<DSemanticDecorator> selectedViews) { + List<DSemanticDecorator> result = new ArrayList<>(); + Set<DiagramElementMapping> mappingsToSelect = new HashSet<>(); + for (DSemanticDecorator dSemanticDecorator : selectedViews) { + if (dSemanticDecorator instanceof DDiagramElement) { + mappingsToSelect.add(((DDiagramElement) dSemanticDecorator).getDiagramElementMapping()); + } + } + for (DDiagramElement dde : new DDiagramQuery(currentDiagram).getAllDiagramElements()) { + if (mappingsToSelect.contains(dde.getDiagramElementMapping())) { + result.add(dde); + } + } + return result; + } + + /** + * Return the list of DSemanticDecorator representing semantic element with same EType as <code>selectedViews</code> + * in the <code>currentDiagram</code>. + * + * @param currentDiagram + * The current {@link DSemanticDiagram} + * @param selectedViews + * The selected views. If there are several selected views all EType of semantic element of this views + * will be considered. + * @return A list of DSemanticDecorator having the same EType as already selected views. + */ + public List<DSemanticDecorator> stdGetViewsRepresentingSameEType(DSemanticDiagram currentDiagram, List<DSemanticDecorator> selectedViews) { + List<DSemanticDecorator> result = new ArrayList<>(); + Set<EClass> eClassToSelect = new HashSet<>(); + for (DSemanticDecorator dSemanticDecorator : selectedViews) { + if (dSemanticDecorator instanceof DDiagramElement) { + eClassToSelect.add(((DDiagramElement) dSemanticDecorator).getTarget().eClass()); + } + } + for (DDiagramElement dde : new DDiagramQuery(currentDiagram).getAllDiagramElements()) { + if (eClassToSelect.contains(dde.getTarget().eClass())) { + result.add(dde); + } + } + return result; + } + + + /** + * Return the list of DSemanticDecorator representing semantic element having the selected EType in the + * <code>currentDiagram</code>. + * + * @param currentDiagram + * The current {@link DSemanticDiagram} + * @return A list of DSemanticDecorator having the selected EType. + */ + public List<DSemanticDecorator> stdGetViewsRepresentingSelectedType(DSemanticDiagram currentDiagram) { + List<DSemanticDecorator> result = new ArrayList<>(); + // Open a dialog to select the EType + InputDialog domainClassDialog = new InputDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.StandardDiagramServices_sameETypeTitle, + Messages.StandardDiagramServices_sameETypeMessage, StringUtil.EMPTY_STRING, null) { + @Override + protected Control createDialogArea(Composite parent) { + Control control = super.createDialogArea(parent); + getText().setBackground(getDomainClassFieldColor(getShell().getDisplay())); + getText().setToolTipText(Messages.StandardDiagramServices_sameETypeTooltip); + // TODO: Improve this field to have completion and propose only EType of the metamodel known by the + // current diagram. + return control; + } + }; + if (Window.OK == domainClassDialog.open()) { + Optional<Session> optionalSession = Session.of(currentDiagram); + if (optionalSession.isPresent()) { + String typeName = domainClassDialog.getValue(); + ModelAccessor modelAccessor = optionalSession.get().getModelAccessor(); + for (DDiagramElement dde : new DDiagramQuery(currentDiagram).getAllDiagramElements()) { + if (modelAccessor.eInstanceOf(dde.getTarget(), typeName.trim())) { + result.add(dde); + } + } + } + } + return result; + } + + /** + * Return the list of DSemanticDecorator corresponding to the evaluation of an expression written by the end-user. + * + * @param currentDiagram + * The current {@link DSemanticDiagram} + * @return A list of DSemanticDecorator. + */ + public List<DSemanticDecorator> stdGetViewsOfExpression(DSemanticDiagram currentDiagram) { + List<DSemanticDecorator> result = new ArrayList<>(); + Optional<Session> optionalSession = Session.of(currentDiagram); + if (optionalSession.isPresent()) { + // Open a dialog to select the EType + InputDialog expressionDialog = new InputDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), Messages.StandardDiagramServices_expressionTitle, + Messages.StandardDiagramServices_expressionMessage, StringUtil.EMPTY_STRING, null) { + @Override + protected Control createDialogArea(Composite parent) { + Control control = super.createDialogArea(parent); + getText().setBackground(getInterpretedExpressionFieldColor(getShell().getDisplay())); + getText().setToolTipText(Messages.StandardDiagramServices_expressionTooltip); + // TODO: Improve this field to have completion and also validation, ideally like in Interpreter view + return control; + } + }; + if (Window.OK == expressionDialog.open()) { + String expression = expressionDialog.getValue(); + try { + // TODO: Add variables to the interpreter + // * self --> DSemanticDiagram currentDiagram + // * ??? --> List<DSemanticDecorator> selectedViews, + Collection<EObject> expressionResult = optionalSession.get().getInterpreter().evaluateCollection(currentDiagram, expression); + for (EObject eObject : expressionResult) { + if (eObject instanceof DDiagramElement) { + result.add((DDiagramElement) eObject); + } + } + } catch (EvaluationException e) { + // Do nothing (currently there is no feedback if the expression is wrong). + } + } + } + return result; + } + + private Color getDomainClassFieldColor(Display display) { + if (domainClassFieldColor == null) { + domainClassFieldColor = new Color(display, DOMAIN_CLASS_FIELD_COLOR); + } + return domainClassFieldColor; + } + + private Color getInterpretedExpressionFieldColor(Display display) { + if (interpretedExpressionFieldColor == null) { + interpretedExpressionFieldColor = new Color(display, INTERPRETED_EXPRESSION_FIELD_COLOR); + } + return interpretedExpressionFieldColor; + } +} |
