diff options
| author | Laurent Fasani | 2015-12-29 14:25:02 +0000 |
|---|---|---|
| committer | Laurent Fasani | 2016-01-28 13:58:35 +0000 |
| commit | 88cac8ac10b0d88b0fccd785b49be8152be64ac2 (patch) | |
| tree | 9793cbfa5e4d3df61a0cd885c87c6ea409f8e1af | |
| parent | 03e80e537b0e820bd3e0aa81417bd44772f44d2e (diff) | |
| download | org.eclipse.sirius-88cac8ac10b0d88b0fccd785b49be8152be64ac2.tar.gz org.eclipse.sirius-88cac8ac10b0d88b0fccd785b49be8152be64ac2.tar.xz org.eclipse.sirius-88cac8ac10b0d88b0fccd785b49be8152be64ac2.zip | |
[486654] Add typed variable functionality
bug: 486654
Change-Id: I740cff8ea502cc87ef84ae31650823e57c85f685
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
28 files changed, 621 insertions, 116 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/ActivateFiltersCommand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/ActivateFiltersCommand.java index e34ba0dd1a..46ad7e4e8a 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/ActivateFiltersCommand.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/ActivateFiltersCommand.java @@ -14,9 +14,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; -import java.util.Map; -import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.sirius.common.tools.api.listener.NotificationUtil; @@ -136,8 +134,7 @@ public final class ActivateFiltersCommand extends RecordingCommand { */ if (objFilter instanceof VariableFilter) { final VariableFilter filter = (VariableFilter) objFilter; - final Map<String, EObject> variables = FilterTools.askForFilterValues(vp, filter); - filter.setFilterContext(variables); + FilterTools.askForFilterValues(vp, filter); containsVariableFilters = true; } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/SetCurrentConcernCommand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/SetCurrentConcernCommand.java index 778a42d254..c2f0cb9778 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/SetCurrentConcernCommand.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/commands/SetCurrentConcernCommand.java @@ -11,9 +11,7 @@ package org.eclipse.sirius.diagram.ui.tools.internal.commands; import java.util.Iterator; -import java.util.Map; -import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.RecordingCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.sirius.common.tools.api.listener.NotificationUtil; @@ -92,9 +90,7 @@ public class SetCurrentConcernCommand extends RecordingCommand { */ if (objFilter instanceof VariableFilter && diagram instanceof DSemanticDiagram) { final VariableFilter filter = (VariableFilter) objFilter; - Map<String, EObject> variables; - variables = FilterTools.askForFilterValues((DSemanticDiagram) diagram, filter); - filter.setFilterContext(variables); + FilterTools.askForFilterValues((DSemanticDiagram) diagram, filter); } } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/filter/FilterTools.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/filter/FilterTools.java index 180dad5cc7..8cf8845c19 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/filter/FilterTools.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/filter/FilterTools.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2015 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 @@ -10,36 +10,43 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.tools.internal.filter; +import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.Iterator; -import java.util.Map; +import java.util.List; import org.eclipse.emf.common.util.BasicEList; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; import org.eclipse.sirius.business.api.helper.SelectionDescriptionHelper; +import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager; +import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; import org.eclipse.sirius.common.tools.api.interpreter.IInterpreterSiriusVariables; +import org.eclipse.sirius.common.tools.api.util.StringUtil; import org.eclipse.sirius.common.tools.api.util.TreeItemWrapper; import org.eclipse.sirius.diagram.DSemanticDiagram; import org.eclipse.sirius.diagram.DiagramFactory; import org.eclipse.sirius.diagram.EObjectVariableValue; +import org.eclipse.sirius.diagram.TypedVariableValue; import org.eclipse.sirius.diagram.VariableValue; import org.eclipse.sirius.diagram.description.filter.VariableFilter; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; import org.eclipse.sirius.tools.api.command.ui.UICallBack; import org.eclipse.sirius.viewpoint.SiriusPlugin; -import org.eclipse.sirius.viewpoint.description.AbstractVariable; +import org.eclipse.sirius.viewpoint.description.DescriptionPackage; import org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription; +import org.eclipse.sirius.viewpoint.description.TypedVariable; import org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; +import com.google.common.collect.Lists; + /** * Utility classes for Filters user interfaces. - * + * * @author cbrun - * + * */ public final class FilterTools { @@ -52,16 +59,15 @@ public final class FilterTools { /** * Ask for filter values in a diagram. - * + * * @param diagram * the diagram * @param filter * the filter - * @return a map with the name/variable couples. * @throws InterruptedException * if the user cancels the wizard */ - public static Map<String, EObject> askForFilterValues(final DSemanticDiagram diagram, final VariableFilter filter) throws InterruptedException { + public static void askForFilterValues(final DSemanticDiagram diagram, final VariableFilter filter) throws InterruptedException { final EObject model = diagram.getTarget(); final UICallBack uiCallback = SiriusEditPlugin.getPlugin().getUiCallback(); /* @@ -73,18 +79,25 @@ public final class FilterTools { while (it.hasNext()) { final VariableValue value = it.next(); if (value instanceof EObjectVariableValue) { - EObjectVariableValue objVariableValue = (EObjectVariableValue) value; - if (objVariableValue.getVariableDefinition() == null || objVariableValue.getModelElement() == null - || filter.getOwnedVariables().contains(objVariableValue.getVariableDefinition())) { + EObjectVariableValue objVarValue = (EObjectVariableValue) value; + if (objVarValue.getVariableDefinition() == null || objVarValue.getModelElement() == null || filter.getOwnedVariables().contains(objVarValue.getVariableDefinition())) { + it.remove(); + } + } else if (value instanceof TypedVariableValue) { + TypedVariableValue typedVarValue = (TypedVariableValue) value; + if (typedVarValue.getVariableDefinition() == null || filter.getOwnedVariables().contains(typedVarValue.getVariableDefinition())) { it.remove(); } } } } + /* * Now lets add the new ones. */ final Iterator<InteractiveVariableDescription> itVar = filter.getOwnedVariables().iterator(); + + List<TypedVariable> typedVariableList = new ArrayList<TypedVariable>(); while (itVar.hasNext()) { final InteractiveVariableDescription currentVar = itVar.next(); if (currentVar instanceof SelectModelElementVariable) { @@ -117,24 +130,69 @@ public final class FilterTools { diagram.getFilterVariableHistory().getOwnedValues().addAll(variables); } } + } else if (currentVar instanceof TypedVariable) { + typedVariableList.add((TypedVariable) currentVar); } } + + List<VariableValue> variables = getTypedVariableValue(uiCallback, typedVariableList, diagram); + + if (diagram.getFilterVariableHistory() != null) { + diagram.getFilterVariableHistory().getOwnedValues().addAll(variables); + } + /* * Now changing the model structure in a Map */ - final Map<String, EObject> variables = new HashMap<String, EObject>(); - if (diagram.getFilterVariableHistory() != null) { - final Iterator<VariableValue> it = diagram.getFilterVariableHistory().getOwnedValues().iterator(); - while (it.hasNext()) { - final VariableValue value = it.next(); - if (value instanceof EObjectVariableValue) { - variables.put(((AbstractVariable) ((EObjectVariableValue) value).getVariableDefinition()).getName(), ((EObjectVariableValue) value).getModelElement()); + filter.resetVariables(); + } + + private static List<VariableValue> getTypedVariableValue(UICallBack uiCallback, List<TypedVariable> typedVariableList, DSemanticDiagram diagram) { + List<VariableValue> variables = new ArrayList<VariableValue>(); + if (typedVariableList.size() > 0) { + try { + List<String> values = null; + List<String> defaultValues = computeDefaultValues(typedVariableList, diagram); + values = uiCallback.askForTypedVariable(typedVariableList, defaultValues); + for (int i = 0; i < typedVariableList.size(); i++) { + TypedVariable variableDef = typedVariableList.get(i); + String value = values.get(i); + if (!StringUtil.isEmpty(value)) { + TypedVariableValue newVariableValue = DiagramFactory.eINSTANCE.createTypedVariableValue(); + newVariableValue.setValue(value); + newVariableValue.setVariableDefinition(variableDef); + variables.add(newVariableValue); + } } + } catch (InterruptedException e) { } } return variables; } + private static List<String> computeDefaultValues(List<TypedVariable> typedVariableList, DSemanticDiagram diagram) { + List<String> defaultValues = Lists.newArrayList(); + + IInterpreter interpreter = SiriusPlugin.getDefault().getInterpreterRegistry().getInterpreter(diagram); + EObject diagramSemanticObject = diagram.getTarget(); + for (TypedVariable typedVariable : typedVariableList) { + String defaultValueExpression = typedVariable.getDefaultValueExpression(); + String defaultValue = ""; //$NON-NLS-1$ + if (!StringUtil.isEmpty(defaultValueExpression)) { + interpreter.setVariable(IInterpreterSiriusVariables.DIAGRAM, diagram); + try { + defaultValue = interpreter.evaluateString(diagramSemanticObject, typedVariable.getDefaultValueExpression()); + } catch (EvaluationException e) { + RuntimeLoggerManager.INSTANCE.error(typedVariable, DescriptionPackage.eINSTANCE.getTypedVariable_DefaultValueExpression(), e); + } finally { + interpreter.unSetVariable(IInterpreterSiriusVariables.DIAGRAM); + } + } + defaultValues.add(defaultValue); + } + return defaultValues; + } + private static void computeInput(final DSemanticDiagram diagram, final EObject model, final SelectModelElementVariable var, final TreeItemWrapper input) { final IInterpreter interpreter = SiriusPlugin.getDefault().getInterpreterRegistry().getInterpreter(model); if (var.getCandidatesExpression() != null) { diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/handler/ChangeFilterActivation.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/handler/ChangeFilterActivation.java index 6452e4663b..30425f9ec0 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/handler/ChangeFilterActivation.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/handler/ChangeFilterActivation.java @@ -14,9 +14,7 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Map; -import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.emf.transaction.util.TransactionUtil; import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart; @@ -124,8 +122,7 @@ public class ChangeFilterActivation extends AbstractChangeActivation { */ if (objFilter instanceof VariableFilter) { final VariableFilter filter = (VariableFilter) objFilter; - final Map<String, EObject> variables = FilterTools.askForFilterValues(vp, filter); - filter.setFilterContext(variables); + FilterTools.askForFilterValues(vp, filter); containsVariableFilters = true; } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/filter/provider/VariableFilterItemProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/filter/provider/VariableFilterItemProvider.java index df4d7438cb..7a5662428c 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/filter/provider/VariableFilterItemProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-gen/org/eclipse/sirius/diagram/description/filter/provider/VariableFilterItemProvider.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, 2013 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2015 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 diff --git a/plugins/org.eclipse.sirius.diagram/model/diagram.ecore b/plugins/org.eclipse.sirius.diagram/model/diagram.ecore index 245c883b02..efb8ad925b 100644 --- a/plugins/org.eclipse.sirius.diagram/model/diagram.ecore +++ b/plugins/org.eclipse.sirius.diagram/model/diagram.ecore @@ -2904,19 +2904,10 @@ <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> <details key="documentation" value="A filter that filters viewpoint elements considering an expression and some variables defined by the user.
"/> </eAnnotations> - <eOperations name="setFilterContext"> + <eOperations name="resetVariables"> <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> - <details key="documentation" value="Set the couple (name,value) of variables to consider while evaluating the filter."/> + <details key="documentation" value="Reset the variables of the filter."/> </eAnnotations> - <eParameters name="variables"> - <eAnnotations source="http://www.eclipse.org/emf/2002/GenModel"> - <details key="documentation" value="(name,value) couples where name is a String and value is an EObject"/> - </eAnnotations> - <eGenericType eClassifier="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EMap"> - <eTypeArguments/> - <eTypeArguments/> - </eGenericType> - </eParameters> </eOperations> <eStructuralFeatures xsi:type="ecore:EReference" name="ownedVariables" upperBound="-1" eType="ecore:EClass ../../org.eclipse.sirius/model/viewpoint.ecore#//description/InteractiveVariableDescription" diff --git a/plugins/org.eclipse.sirius.diagram/model/diagram.genmodel b/plugins/org.eclipse.sirius.diagram/model/diagram.genmodel index 44bb57df1a..2e443de12d 100644 --- a/plugins/org.eclipse.sirius.diagram/model/diagram.genmodel +++ b/plugins/org.eclipse.sirius.diagram/model/diagram.genmodel @@ -953,9 +953,7 @@ <genClasses ecoreClass="diagram.ecore#//description/filter/VariableFilter"> <genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference diagram.ecore#//description/filter/VariableFilter/ownedVariables"/> <genFeatures createChild="false" propertyCategory="General" ecoreFeature="ecore:EAttribute diagram.ecore#//description/filter/VariableFilter/semanticConditionExpression"/> - <genOperations ecoreOperation="diagram.ecore#//description/filter/VariableFilter/setFilterContext"> - <genParameters ecoreParameter="diagram.ecore#//description/filter/VariableFilter/setFilterContext/variables"/> - </genOperations> + <genOperations ecoreOperation="diagram.ecore#//description/filter/VariableFilter/resetVariables"/> </genClasses> </nestedGenPackages> <nestedGenPackages prefix="Concern" basePackage="org.eclipse.sirius.diagram.description" diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/description/filter/spec/VariableFilterSpec.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/description/filter/spec/VariableFilterSpec.java index 5422345671..480867cca2 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/description/filter/spec/VariableFilterSpec.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/internal/metamodel/description/filter/spec/VariableFilterSpec.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2015 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 @@ -15,20 +15,24 @@ import java.util.Iterator; import java.util.Map; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.sirius.business.api.logger.RuntimeLoggerManager; import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DDiagramElement; import org.eclipse.sirius.diagram.EObjectVariableValue; +import org.eclipse.sirius.diagram.TypedVariableValue; import org.eclipse.sirius.diagram.VariableValue; import org.eclipse.sirius.diagram.description.filter.FilterPackage; import org.eclipse.sirius.diagram.description.filter.impl.VariableFilterImpl; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import org.eclipse.sirius.viewpoint.SiriusPlugin; import org.eclipse.sirius.viewpoint.description.AbstractVariable; +import org.eclipse.sirius.viewpoint.description.TypedVariable; import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Maps; import com.google.common.collect.Multimap; /** @@ -41,6 +45,8 @@ public class VariableFilterSpec extends VariableFilterImpl { private Multimap<String, EObject> variables; + private Map<String, Object> typedVariables; + private DDiagram curDiagram; /** @@ -73,6 +79,13 @@ public class VariableFilterSpec extends VariableFilterImpl { interpreter.setVariable(key, value); } } + if (typedVariables != null) { + for (final String key : typedVariables.keySet()) { + final Object value = typedVariables.get(key); + interpreter.setVariable(key, value); + } + } + if (getSemanticConditionExpression() != null) { final EObject target = ((DSemanticDecorator) element).getTarget(); if (target == null || target.eResource() == null) { @@ -85,20 +98,43 @@ public class VariableFilterSpec extends VariableFilterImpl { } } } + + // Unset the variables + if (variables != null) { + for (final String key : variables.keySet()) { + interpreter.unSetVariable(key); + } + } + if (typedVariables != null) { + for (final String key : typedVariables.keySet()) { + interpreter.unSetVariable(key); + } + } return valid; } private void getVariablesFromDiagram(final DDiagram dDiagram) { if (curDiagram == null || dDiagram != curDiagram) { variables = ArrayListMultimap.create(); + typedVariables = Maps.newLinkedHashMap(); if (dDiagram.getFilterVariableHistory() != null) { final Iterator<VariableValue> it = dDiagram.getFilterVariableHistory().getOwnedValues().iterator(); while (it.hasNext()) { final VariableValue value = it.next(); if (value instanceof EObjectVariableValue) { - if (getOwnedVariables().contains(((EObjectVariableValue) value).getVariableDefinition())) { - variables.put(((AbstractVariable) ((EObjectVariableValue) value).getVariableDefinition()).getName(), ((EObjectVariableValue) value).getModelElement()); + EObjectVariableValue objectVarValue = (EObjectVariableValue) value; + if (getOwnedVariables().contains(objectVarValue.getVariableDefinition())) { + variables.put(((AbstractVariable) objectVarValue.getVariableDefinition()).getName(), objectVarValue.getModelElement()); + } + } else if (value instanceof TypedVariableValue) { + TypedVariableValue typeVariableValue = (TypedVariableValue) value; + TypedVariable variableDefinition = typeVariableValue.getVariableDefinition(); + if (getOwnedVariables().contains(variableDefinition)) { + // Instantiate value which dataType is defined on + // TypedVariable.valueType. + Object convertedObject = EcoreUtil.createFromString(variableDefinition.getValueType(), typeVariableValue.getValue()); + typedVariables.put(((AbstractVariable) typeVariableValue.getVariableDefinition()).getName(), convertedObject); } } } @@ -107,17 +143,8 @@ public class VariableFilterSpec extends VariableFilterImpl { } } - /** - * {@inheritDoc} - * - * @see org.eclipse.sirius.viewpoint.description.filter.impl.VariableFilterImpl#setFilterContext(java.util.Map) - */ @Override - public void setFilterContext(final Map<?, ?> variablesMap) { - this.variables = ArrayListMultimap.create(); - for (Map.Entry<?, ?> entry : variablesMap.entrySet()) { - this.variables.put((String) entry.getKey(), (EObject) entry.getValue()); - } + public void resetVariables() { this.curDiagram = null; } } diff --git a/plugins/org.eclipse.sirius.diagram/src-gen/org/eclipse/sirius/diagram/description/filter/VariableFilter.java b/plugins/org.eclipse.sirius.diagram/src-gen/org/eclipse/sirius/diagram/description/filter/VariableFilter.java index 304c2fd629..9d98dd7c96 100644 --- a/plugins/org.eclipse.sirius.diagram/src-gen/org/eclipse/sirius/diagram/description/filter/VariableFilter.java +++ b/plugins/org.eclipse.sirius.diagram/src-gen/org/eclipse/sirius/diagram/description/filter/VariableFilter.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, 2013 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2015 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 @@ -11,8 +11,6 @@ */ package org.eclipse.sirius.diagram.description.filter; -import java.util.Map; - import org.eclipse.emf.common.util.EList; import org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription; @@ -95,15 +93,11 @@ public interface VariableFilter extends Filter { /** * <!-- begin-user-doc --> <!-- end-user-doc --> <!-- begin-model-doc --> - * Set the couple (name,value) of variables to consider while evaluating the - * filter. + * Reset the variables of the filter. * - * @param variables - * (name,value) couples where name is a String and value is an - * EObject <!-- end-model-doc --> * @model * @generated */ - void setFilterContext(Map<?, ?> variables); + void resetVariables(); } // VariableFilter diff --git a/plugins/org.eclipse.sirius.diagram/src-gen/org/eclipse/sirius/diagram/description/filter/impl/VariableFilterImpl.java b/plugins/org.eclipse.sirius.diagram/src-gen/org/eclipse/sirius/diagram/description/filter/impl/VariableFilterImpl.java index de2fdf58c1..e87f4d2d2b 100644 --- a/plugins/org.eclipse.sirius.diagram/src-gen/org/eclipse/sirius/diagram/description/filter/impl/VariableFilterImpl.java +++ b/plugins/org.eclipse.sirius.diagram/src-gen/org/eclipse/sirius/diagram/description/filter/impl/VariableFilterImpl.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, 2013 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2015 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 @@ -12,7 +12,6 @@ package org.eclipse.sirius.diagram.description.filter.impl; import java.util.Collection; -import java.util.Map; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.NotificationChain; @@ -139,7 +138,7 @@ public class VariableFilterImpl extends FilterImpl implements VariableFilter { * @generated */ @Override - public void setFilterContext(Map<?, ?> variables) { + public void resetVariables() { // TODO: implement this method // Ensure that you remove @generated or mark it @generated NOT throw new UnsupportedOperationException(); @@ -224,8 +223,8 @@ public class VariableFilterImpl extends FilterImpl implements VariableFilter { case FilterPackage.VARIABLE_FILTER__OWNED_VARIABLES: return ownedVariables != null && !ownedVariables.isEmpty(); case FilterPackage.VARIABLE_FILTER__SEMANTIC_CONDITION_EXPRESSION: - return VariableFilterImpl.SEMANTIC_CONDITION_EXPRESSION_EDEFAULT == null ? semanticConditionExpression != null : !VariableFilterImpl.SEMANTIC_CONDITION_EXPRESSION_EDEFAULT - .equals(semanticConditionExpression); + return VariableFilterImpl.SEMANTIC_CONDITION_EXPRESSION_EDEFAULT == null ? semanticConditionExpression != null + : !VariableFilterImpl.SEMANTIC_CONDITION_EXPRESSION_EDEFAULT.equals(semanticConditionExpression); } return super.eIsSet(featureID); } diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index 6998955b28..6577fa3bb2 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -88,18 +88,19 @@ <h2 id="sirius4.0.0">Changes in Sirius 4.0.0</h2> <h3 id="UserVisibleChanges">User-Visible Changes</h3> <ul> + <li><span class="label label-success">Added</span> The user can now filter elements according to a Typed variable (String, Integer, EEnum or any EDataType). If a user applies a filter containing Typed Variables, a dialog is displayed to allow user entering the Typed Variable values. That values can be used as variables in the Condition Expression of the Variable Filter.</li> <li><span class="label label-info">Modified</span> Now if an object is locked and cannot be modified according to <code>IPermissionAuthority</code>, the properties view will not be editable if this locked object is selected from the Model Explorer view. </li> - </ul> - <ul> <li><span class="label label-info">Modified</span> When trying to reconnect an edge end on another edge, the edge is now highlighted only if a reconnect tool is found (the precondition of the tool is not tested here).</li> </ul> <h3 id="SpecifierVisibleChanges">Specifier-Visible Changes</h3> <ul> + <li><span class="label label-success">Added</span> It is possible to create Typed Variable under Variable Filter.</li> <li><span class="label label-info">Modified</span> The <code>BorderSizeComputationExpression</code> migration has been corrected to recursively handle the sub container mappings. VSM created or migrated with Sirius 3.1.0, 3.1.1 or 3.1.2 might require a manual modification for the style descriptions of sub container mappings with border size computation equals to 0 as we cannot determine if they were added (or updated) after or before the migration: starting with Sirius 3.1.0, no border will be displayed for a 0 pixel value whereas with older version container always had at least a 1 pixel border. </li> + <li><span class="label label-info">Modified</span> The variable under VariableFilter, previously named «Variable», is renamed to «Select Model Element Variable». It is functionally equivalent.</li> </ul> <h3 id="DeveloperVisibleChanges">Developer-Visible Changes</h3> <ul> @@ -121,6 +122,30 @@ <code>ModelOperations</code> outside of the context of a specific representation, provided the <code>ModelOperations</code> work in that context. </li> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.viewpoint.description.TypedVariable</code> has been created. + </li> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription</code> has been created as tag interface for variables that require user interaction to be valued. + </li> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.tools.api.command.ui.UICallBack.askForTypedVariable(List<TypedVariable>, List<String>)</code> has been created. + </li> + <li><span class="label label-info">Added</span> + <code>org.eclipse.sirius.tools.api.command.ui.NoUICallback.askForTypedVariable(List<TypedVariable>, List<String>)</code> has been created. + </li> + <li><span class="label label-info">Modified</span> + <code>org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable</code> now implements + <code>org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription</code>. + </li> + <li><span class="label label-info">Modified</span> + <code>org.eclipse.sirius.viewpoint.description.tool.AbstractVariable</code> has been moved to + <code>org.eclipse.sirius.viewpoint.description.AbstractVariable</code>. + </li> + <li><span class="label label-info">Modified</span> + <code>org.eclipse.sirius.viewpoint.description.tool.SubVariable</code> has been moved to + <code>org.eclipse.sirius.viewpoint.description.SubVariable</code>. + </li> </ul> <h4 id="Changesinorg.eclipse.sirius.common">Changes in <code>org.eclipse.sirius.common</code> @@ -133,6 +158,43 @@ <code>org.eclipse.sirius.common.acceleo.aql.business.internal.AQLSiriusInterpreter</code> which is an implementation providing this type inference. </li> </ul> + <h4 id="Changesinorg.eclipse.sirius.diagram">Changes in + <code>org.eclipse.sirius.diagram</code> + </h4> + <ul> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.diagram.VariableValue</code>, + <code>org.eclipse.sirius.diagram.TypedVariableValue</code> and + <code>org.eclipse.sirius.diagram.EObjectVariableValue</code> has been created. + </li> + <li><span class="label label-success">Added</span> + <code>org.eclipse.sirius.diagram.description.filter.impl.VariableFilterImpl.resetVariables()</code> has been created to indicate that variables have to be computed again. + </li> + <li><span class="label label-info">Modified</span> The type of + <code>org.eclipse.sirius.diagram.description.filter.VariableFilter.ownedVariable</code> has been changed to + <code>org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription</code>. + </li> + <li><span class="label label-info">Modified</span> The type of + <code>org.eclipse.sirius.diagram.FilterVariableHistory.ownedValues</code> has been changed to + <code>org.eclipse.sirius.diagram.VariableValue</code>. + </li> + <li><span class="label label-danger">Removed</span> + <code>org.eclipse.sirius.diagram.description.filter.FilterVariable</code> has been removed. It is replaced by + <code>org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable</code>. + </li> + <li><span class="label label-danger">Removed</span> + <code>org.eclipse.sirius.diagram.description.filter.impl.VariableFilterImpl.setFilterContext()</code> has been removed. This method was, in part, useless and is replaced by + <code>org.eclipse.sirius.diagram.description.filter.impl.VariableFilterImpl.resetVariables()</code>. + </li> + </ul> + <h4 id="Changesinorg.eclipse.sirius.ui">Changes in + <code>org.eclipse.sirius.ui</code> + </h4> + <ul> + <li><span class="label label-info">Added</span> + <code>org.eclipse.sirius.ui.tools.api.command.AbstractSWTCallback.askForTypedVariable(List<TypedVariable>, List<String>)</code> has been created. + </li> + </ul> <h4 id="Changesinorg.eclipse.sirius.diagram.ui">Changes in <code>org.eclipse.sirius.diagram.ui</code> </h4> @@ -161,7 +223,7 @@ <code>org.eclipse.sirius.ext.emf.ui.properties.ExtensiblePropertySource.collector</code> field is now in protected visibility to be modifiable and accessible by subclass. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.ui">Changes in + <h4 id="Changesinorg.eclipse.sirius.ui2">Changes in <code>org.eclipse.sirius.ui</code> </h4> <ul> @@ -565,7 +627,7 @@ <code>org.eclipse.sirius.tools.api.command.IUndoableCommand</code> interface removed because it is useless since undo/redo is managed by EMF Transaction. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.ui2">Changes in + <h4 id="Changesinorg.eclipse.sirius.ui3">Changes in <code>org.eclipse.sirius.ui</code> </h4> <ul> @@ -1180,7 +1242,7 @@ <code>org.eclipse.sirius.viewpoint.DContainer</code> has been removed. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.ui3">Changes in + <h4 id="Changesinorg.eclipse.sirius.ui4">Changes in <code>org.eclipse.sirius.ui</code> </h4> <ul> @@ -1240,7 +1302,7 @@ <code>org.eclipse.sirius.editor.tools.api.assist.TypeContentProposalProvider.bindCompletionProcessor(AbstractPropertySection, Text)</code>, the difference is that it binds the completion processors available in plugins to the text. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.diagram">Changes in + <h4 id="Changesinorg.eclipse.sirius.diagram2">Changes in <code>org.eclipse.sirius.diagram</code> </h4> <ul> @@ -1830,7 +1892,7 @@ <code>org.eclipse.gmf.runtime.emf.core.util.CrossReferenceAdapter</code>. However considering the way Sirius uses GMF, this adapter is not needed. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.ui4">Changes in + <h4 id="Changesinorg.eclipse.sirius.ui5">Changes in <code>org.eclipse.sirius.ui</code> </h4> <ul> @@ -1882,7 +1944,7 @@ <code>IServiceLocator.getService()</code> on the site. </li> </ul> - <h4 id="Changesinorg.eclipse.sirius.diagram2">Changes in + <h4 id="Changesinorg.eclipse.sirius.diagram3">Changes in <code>org.eclipse.sirius.diagram</code> </h4> <ul> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index 5f5d44709d..4a19e98cd9 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -8,15 +8,15 @@ h2(#sirius4.0.0). Changes in Sirius 4.0.0 h3. User-Visible Changes +* <span class="label label-success">Added</span> The user can now filter elements according to a Typed variable (String, Integer, EEnum or any EDataType). If a user applies a filter containing Typed Variables, a dialog is displayed to allow user entering the Typed Variable values. That values can be used as variables in the Condition Expression of the Variable Filter. * <span class="label label-info">Modified</span> Now if an object is locked and cannot be modified according to @IPermissionAuthority@, the properties view will not be editable if this locked object is selected from the Model Explorer view. - * <span class="label label-info">Modified</span> When trying to reconnect an edge end on another edge, the edge is now highlighted only if a reconnect tool is found (the precondition of the tool is not tested here). - h3. Specifier-Visible Changes +* <span class="label label-success">Added</span> It is possible to create Typed Variable under Variable Filter. * <span class="label label-info">Modified</span> The @BorderSizeComputationExpression@ migration has been corrected to recursively handle the sub container mappings. VSM created or migrated with Sirius 3.1.0, 3.1.1 or 3.1.2 might require a manual modification for the style descriptions of sub container mappings with border size computation equals to 0 as we cannot determine if they were added (or updated) after or before the migration: starting with Sirius 3.1.0, no border will be displayed for a 0 pixel value whereas with older version container always had at least a 1 pixel border. - +* <span class="label label-info">Modified</span> The variable under VariableFilter, previously named "Variable", is renamed to "Select Model Element Variable". It is functionally equivalent. h3. Developer-Visible Changes @@ -26,11 +26,30 @@ h3. Developer-Visible Changes h4. Changes in @org.eclipse.sirius@ * <span class="label label-success">Added</span> A new variant of @org.eclipse.sirius.business.api.helper.task.TaskHelper.buildTaskFromModelOperation(EObject, ModelOperation)@ has been added, which does not require to specify a @DRepresentation@ in the context. It allows the creation of a task which executes a behavior specified by @ModelOperations@ outside of the context of a specific representation, provided the @ModelOperations@ work in that context. +* <span class="label label-success">Added</span> @org.eclipse.sirius.viewpoint.description.TypedVariable@ has been created. +* <span class="label label-success">Added</span> @org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription@ has been created as tag interface for variables that require user interaction to be valued. +* <span class="label label-success">Added</span> @org.eclipse.sirius.tools.api.command.ui.UICallBack.askForTypedVariable(List<TypedVariable>, List<String>)@ has been created. +* <span class="label label-info">Added</span> @org.eclipse.sirius.tools.api.command.ui.NoUICallback.askForTypedVariable(List<TypedVariable>, List<String>)@ has been created. +* <span class="label label-info">Modified</span> @org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable@ now implements @org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription@. +* <span class="label label-info">Modified</span> @org.eclipse.sirius.viewpoint.description.tool.AbstractVariable@ has been moved to @org.eclipse.sirius.viewpoint.description.AbstractVariable@. +* <span class="label label-info">Modified</span> @org.eclipse.sirius.viewpoint.description.tool.SubVariable@ has been moved to @org.eclipse.sirius.viewpoint.description.SubVariable@. h4. Changes in @org.eclipse.sirius.common@ * <span class="label label-success">Added</span> A method @getInferredVariableTypes(Boolean value)@ in @org.eclipse.sirius.common.tools.api.interpreter.ValidationResult@ so that @IInterpreter@ implementations able to infer more specific types based on predicates result provides this information to Sirius which will then use it for validating other expressions. You might want to look at @org.eclipse.sirius.common.acceleo.aql.business.internal.AQLSiriusInterpreter@ which is an implementation providing this type inference. +h4. Changes in @org.eclipse.sirius.diagram@ + +* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.VariableValue@, @org.eclipse.sirius.diagram.TypedVariableValue@ and @org.eclipse.sirius.diagram.EObjectVariableValue@ has been created. +* <span class="label label-success">Added</span> @org.eclipse.sirius.diagram.description.filter.impl.VariableFilterImpl.resetVariables()@ has been created to indicate that variables have to be computed again. +* <span class="label label-info">Modified</span> The type of @org.eclipse.sirius.diagram.description.filter.VariableFilter.ownedVariable@ has been changed to @org.eclipse.sirius.viewpoint.description.InteractiveVariableDescription@. +* <span class="label label-info">Modified</span> The type of @org.eclipse.sirius.diagram.FilterVariableHistory.ownedValues@ has been changed to @org.eclipse.sirius.diagram.VariableValue@. +* <span class="label label-danger">Removed</span> @org.eclipse.sirius.diagram.description.filter.FilterVariable@ has been removed. It is replaced by @org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable@. +* <span class="label label-danger">Removed</span> @org.eclipse.sirius.diagram.description.filter.impl.VariableFilterImpl.setFilterContext()@ has been removed. This method was, in part, useless and is replaced by @org.eclipse.sirius.diagram.description.filter.impl.VariableFilterImpl.resetVariables()@. + +h4. Changes in @org.eclipse.sirius.ui@ + +* <span class="label label-info">Added</span> @org.eclipse.sirius.ui.tools.api.command.AbstractSWTCallback.askForTypedVariable(List<TypedVariable>, List<String>)@ has been created. h4. Changes in @org.eclipse.sirius.diagram.ui@ diff --git a/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/Diagrams.html b/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/Diagrams.html index f4fe9a547c..33a286a579 100644 --- a/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/Diagrams.html +++ b/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/Diagrams.html @@ -1475,8 +1475,47 @@ <h3 id="variable_filter">Variable Filter</h3> <p>A <em>Variable Filter</em> is similar to a - <em>Mapping Filter</em>, except that instead of using a list of mappings to select the candidate elements to filter, it opens a dialog box from which the user can select the specific elements he wants to filter. The configuration of the dialog box uses the same properties and semantic as the - <a href="#selection_wizard">Selection Wizard</a> tool. Refer to its documentation for the details. + <em>Mapping Filter</em>, except that instead of using a list of mappings to select the candidate elements to filter, all represented elements are candidates but can be filtered with a Semantic Condition Expression. + <br/>In that expression, the specifier can use variables that are defined in the variable filter. + </p> + <ul> + <li>Select Model Element Variable : it opens a dialog box from which the user can select a collection of EObjects. The configuration of the dialog box uses the same properties and semantic as the + <a href="#selection_wizard">Selection Wizard</a> tool. Refer to its documentation for the details. + </li> + <li>Typed Variable : see + <a href="#filter_with_typed_variable">Filter with Typed Variable</a> + </li> + </ul> + <h4 id="filter_with_typed_variable">Filter with Typed Variable</h4> + <p>A Typed Variable is a variable which value type is a + <em>EDataType</em> as chosen by the specifier and which value is filled by the user when applying the variable filter. + <br/>An interpreted expression allows defining the default value. + </p> + <p> + <img border="0" src="images/typedVariable_PropertyView.png"/> + </p> + <p>When the user applies a variable filter with typed variables, a dialog box is displayed to allow user entering the values. + <br/>This dialog box is prompted after all + <em>Select Model Element</em> wizard have been prompted. + <br/>It contains as many line as number of typed variables under the variable filter. + <br/>The user documentation is displayed as tooltip on question mark. + <br/>The default value is the result of the interpreted expression defined on VSM. + </p> + <p> + <img border="0" src="images/dialog_TypedVariableValue.png"/> + </p> + <p> + <strong>EDataType class instantiation</strong> + </p> + <p>Note that whatever the type of variable is, the field is a text field.</p> + <p>In order that the EDataType class is instantiable, the value given by the user should follow rules which depend on how it is triggered by EMF mechanism. + <br/>If the EFactory of the EDataType is not overloaded, the class corresponding to the EDataType must have a constructor with a String parameter. At instantiation, the string argument will be the string input by the user. This string argument is translated into the right data in the class constructor for example. + <br/>What is done in the constructor described above can also be done overloading the EDataType class EFactory. + </p> + <p>Example: + <br/>If your class represents a point coordinates with two fields x and y of type int, the string input by the user could be + <em lang="integer">,[integer]</em>. This kind of information could be given to the user through the + <em>User documentation</em> </p> <h2 id="validation">Validation Rules</h2> <p>A diagram description can define custom validation rules which will only be applied when launching a validation on an instance of this diagram (using the diff --git a/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/Diagrams.textile b/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/Diagrams.textile index 7384fb6fb9..5c16d19bf0 100644 --- a/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/Diagrams.textile +++ b/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/Diagrams.textile @@ -594,7 +594,36 @@ The expressions of all active filters are evaluated whenever the diagram is refr h3(#variable_filter). Variable Filter -A _Variable Filter_ is similar to a _Mapping Filter_, except that instead of using a list of mappings to select the candidate elements to filter, it opens a dialog box from which the user can select the specific elements he wants to filter. The configuration of the dialog box uses the same properties and semantic as the "Selection Wizard":#selection_wizard tool. Refer to its documentation for the details. +A _Variable Filter_ is similar to a _Mapping Filter_, except that instead of using a list of mappings to select the candidate elements to filter, all represented elements are candidates but can be filtered with a Semantic Condition Expression. +In that expression, the specifier can use variables that are defined in the variable filter. +* Select Model Element Variable : it opens a dialog box from which the user can select a collection of EObjects. The configuration of the dialog box uses the same properties and semantic as the "Selection Wizard":#selection_wizard tool. Refer to its documentation for the details. +* Typed Variable : see "Filter with Typed Variable":#filter_with_typed_variable + +h4(#filter_with_typed_variable). Filter with Typed Variable + +A Typed Variable is a variable which value type is a _EDataType_ as chosen by the specifier and which value is filled by the user when applying the variable filter. +An interpreted expression allows defining the default value. + +!images/typedVariable_PropertyView.png! + +When the user applies a variable filter with typed variables, a dialog box is displayed to allow user entering the values. +This dialog box is prompted after all _Select Model Element_ wizard have been prompted. +It contains as many line as number of typed variables under the variable filter. +The user documentation is displayed as tooltip on question mark. +The default value is the result of the interpreted expression defined on VSM. + +!images/dialog_TypedVariableValue.png! + +*EDataType class instantiation* + +Note that whatever the type of variable is, the field is a text field. + +In order that the EDataType class is instantiable, the value given by the user should follow rules which depend on how it is triggered by EMF mechanism. +If the EFactory of the EDataType is not overloaded, the class corresponding to the EDataType must have a constructor with a String parameter. At instantiation, the string argument will be the string input by the user. This string argument is translated into the right data in the class constructor for example. +What is done in the constructor described above can also be done overloading the EDataType class EFactory. + +Example: +If your class represents a point coordinates with two fields x and y of type int, the string input by the user could be _[integer],[integer]_. This kind of information could be given to the user through the _User documentation_ h2(#validation). Validation Rules diff --git a/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/images/dialog_TypedVariableValue.png b/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/images/dialog_TypedVariableValue.png Binary files differnew file mode 100644 index 0000000000..7ea8238718 --- /dev/null +++ b/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/images/dialog_TypedVariableValue.png diff --git a/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/images/typedVariable_PropertyView.png b/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/images/typedVariable_PropertyView.png Binary files differnew file mode 100644 index 0000000000..1f516e38e0 --- /dev/null +++ b/plugins/org.eclipse.sirius.doc/doc/specifier/diagrams/images/typedVariable_PropertyView.png diff --git a/plugins/org.eclipse.sirius.tests.junit/data/unit/variablefilter/ticketvp1063/vp-1063.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/variablefilter/ticketvp1063/vp-1063.odesign index 1bf8064216..66bc6e9d2e 100644 --- a/plugins/org.eclipse.sirius.tests.junit/data/unit/variablefilter/ticketvp1063/vp-1063.odesign +++ b/plugins/org.eclipse.sirius.tests.junit/data/unit/variablefilter/ticketvp1063/vp-1063.odesign @@ -1,10 +1,52 @@ <?xml version="1.0" encoding="UTF-8"?> -<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:filter="http://www.eclipse.org/sirius/diagram/description/filter/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" version="10.1.3.201511131800"> +<description:Group xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:description="http://www.eclipse.org/sirius/description/1.1.0" xmlns:description_1="http://www.eclipse.org/sirius/diagram/description/1.1.0" xmlns:filter="http://www.eclipse.org/sirius/diagram/description/filter/1.1.0" xmlns:style="http://www.eclipse.org/sirius/diagram/description/style/1.1.0" xmlns:tool="http://www.eclipse.org/sirius/description/tool/1.1.0" version="10.1.3.201601041200"> <ownedViewpoints name="vp1063"> <ownedRepresentations xsi:type="description_1:DiagramDescription" name="vp1063" domainClass="EPackage"> <filters xsi:type="filter:CompositeFilterDescription" name="Classifier"> <filters xsi:type="filter:VariableFilter" semanticConditionExpression="aql:EClass->includes(self)"> - <ownedVariables candidatesExpression="aql:self.eClassifiers" multiple="true" name="EClass"/> + <ownedVariables xsi:type="tool:SelectModelElementVariable" name="EClass" candidatesExpression="aql:self.eClassifiers" multiple="true"/> + </filters> + </filters> + <defaultLayer name="Default"> + <containerMappings name="EClass" domainClass="EClass"> + <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1" borderSizeComputationExpression="1"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </containerMappings> + <containerMappings name="EEnum" domainClass="EEnum"> + <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1" borderSizeComputationExpression="1"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </containerMappings> + <containerMappings name="EPackage" domainClass="EPackage"> + <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1" borderSizeComputationExpression="1"> + <borderColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <labelColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='black']"/> + <backgroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='white']"/> + <foregroundColor xsi:type="description:SystemColor" href="environment:/viewpoint#//@systemColors/@entries[name='light_gray']"/> + </style> + </containerMappings> + </defaultLayer> + </ownedRepresentations> + <ownedRepresentations xsi:type="description_1:DiagramDescription" name="vpForFilterWithTypedVariable" domainClass="EPackage"> + <metamodel href="http://www.eclipse.org/emf/2002/Ecore#/"/> + <filters xsi:type="filter:CompositeFilterDescription" name="FilterWithTypedVariables"> + <filters xsi:type="filter:VariableFilter" semanticConditionExpression="aql:not (rGBVariable.oclIsKindOf(viewpoint::RGBValues) and stringVariable.contains('textDefault') and intVariable+5=10)"> + <ownedVariables xsi:type="description:TypedVariable" userDocumentation="My documentation" name="rGBVariable" defaultValueExpression="113,113,113"> + <valueType href="http://www.eclipse.org/sirius/1.1.0#//RGBValues"/> + </ownedVariables> + <ownedVariables xsi:type="description:TypedVariable" name="stringVariable" defaultValueExpression="textDefault"> + <valueType href="http://www.eclipse.org/emf/2002/Ecore#//EString"/> + </ownedVariables> + <ownedVariables xsi:type="description:TypedVariable" name="intVariable" defaultValueExpression="5"> + <valueType href="http://www.eclipse.org/emf/2002/Ecore#//EInt"/> + </ownedVariables> </filters> </filters> <defaultLayer name="Default"> diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/filter/VariableFilterTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/filter/VariableFilterTest.java index bc95618a26..b5a9e8f0f6 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/filter/VariableFilterTest.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/filter/VariableFilterTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2014 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2016 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 @@ -12,6 +12,7 @@ package org.eclipse.sirius.tests.unit.diagram.filter; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.emf.common.notify.AdapterFactory; @@ -27,6 +28,7 @@ import org.eclipse.sirius.tests.support.api.SiriusDiagramTestCase; import org.eclipse.sirius.tests.support.api.TestsUtil; import org.eclipse.sirius.tools.api.command.ui.NoUICallback; import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; +import org.eclipse.sirius.viewpoint.description.TypedVariable; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; public class VariableFilterTest extends SiriusDiagramTestCase { @@ -38,6 +40,8 @@ public class VariableFilterTest extends SiriusDiagramTestCase { private static final String FILTER_NAME = "Classifier"; + private static final String FILTER_NAME_2 = "FilterWithTypedVariables"; + private static final String TEST_SEMANTIC_MODEL_PATH = "/" + SiriusTestsPlugin.PLUGIN_ID + "/data/unit/variablefilter/ticketvp1063/vp-1063.ecore"; private static final String MODELER_PATH = "/" + SiriusTestsPlugin.PLUGIN_ID + "/data/unit/variablefilter/ticketvp1063/vp-1063.odesign"; @@ -46,6 +50,8 @@ public class VariableFilterTest extends SiriusDiagramTestCase { private static final String ENTITIES_DESC_NAME = "vp1063"; + private static final String DIAGRAM_DESC_NAME_2 = "vpForFilterWithTypedVariable"; + private DDiagram diagram; private DiagramEditor editor; @@ -55,11 +61,16 @@ public class VariableFilterTest extends SiriusDiagramTestCase { * * @Override */ + @Override protected void setUp() throws Exception { super.setUp(); genericSetUp(TEST_SEMANTIC_MODEL_PATH, MODELER_PATH); initViewpoint(DESIGN_VIEWPOINT_NAME); - diagram = (DDiagram) createRepresentation(ENTITIES_DESC_NAME); + + } + + private void openDiagram(String diagramDescriptionName) { + diagram = (DDiagram) createRepresentation(diagramDescriptionName); editor = (DiagramEditor) DialectUIManager.INSTANCE.openEditor(session, diagram, new NullProgressMonitor()); TestsUtil.synchronizationWithUIThread(); assertNotNull(editor); @@ -69,6 +80,8 @@ public class VariableFilterTest extends SiriusDiagramTestCase { * Test multiple variable filter on two selected elements. */ public void testMultipleSelection() { + openDiagram(ENTITIES_DESC_NAME); + activeMultipleSelectionFilter(); final Collection<String> elementNames = new ArrayList<String>(2); elementNames.add("Class"); @@ -82,6 +95,8 @@ public class VariableFilterTest extends SiriusDiagramTestCase { * Test multiple variable filter on one selected element. */ public void testSimpleSelection() { + openDiagram(ENTITIES_DESC_NAME); + activateSimpleSelectionFilter(); final Collection<String> elementNames = new ArrayList<String>(1); elementNames.add("Class"); @@ -98,6 +113,45 @@ public class VariableFilterTest extends SiriusDiagramTestCase { testSimpleSelection(); } + /** + * Test variable filter typed Variable. + */ + public void testFilterWithTypedFilter() { + openDiagram(DIAGRAM_DESC_NAME_2); + + activateTypedVariableFilter(); + + // Check that nodes are not visible + // It means that variables are created with the good type and + // interpreted at runtime. The filter condition expression is: + // aql:not (rGBVariable.oclIsKindOf(viewpoint::RGBValues) and + // stringVariable.contains('textDefault') and intVariable+5=10) + assertTrue(diagram.getDiagramElements().size() != 0); + for (DDiagramElement diagramElement : diagram.getDiagramElements()) { + assertFalse(DIAGRAM_ELEMENT + diagramElement.getName() + " should be hidden", diagramElement.isVisible()); + } + + deactivateFilter(diagram, FILTER_NAME_2); + for (DDiagramElement diagramElement : diagram.getDiagramElements()) { + assertTrue(DIAGRAM_ELEMENT + diagramElement.getName() + SHOULD_BE_VISIBLE, diagramElement.isVisible()); + } + } + + private void activateTypedVariableFilter() { + SiriusEditPlugin.getPlugin().setUiCallback(new NoUICallback() { + List<String> stringValues = new ArrayList<String>(); + + @Override + public List<String> askForTypedVariable(List<TypedVariable> typedVariableList, List<String> defaultValues) { + stringValues.add("113,113,113"); + stringValues.add("textDefault"); + stringValues.add("5"); + return stringValues; + } + }); + activateFilter(diagram, FILTER_NAME_2); + } + private void activateSimpleSelectionFilter() { SiriusEditPlugin.getPlugin().setUiCallback(new NoUICallback() { Collection<EObject> selectedEObjects = new ArrayList<EObject>(); @@ -161,6 +215,7 @@ public class VariableFilterTest extends SiriusDiagramTestCase { * * @Override */ + @Override protected void tearDown() throws Exception { super.tearDown(); } diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/BorderSizeMigrationTest.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/BorderSizeMigrationTest.java index b95e777729..02718bc1a9 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/BorderSizeMigrationTest.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/migration/BorderSizeMigrationTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2016 Obeo. * 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 @@ -88,7 +88,7 @@ public class BorderSizeMigrationTest extends SiriusTestCase { loadedVersion = checkVsmFileMigrationStatus(URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + REPRESENTATIONS_FILE_PATH + PATH_3_1_0 + VSM_FILE_NAME, true), true); assertTrue("The migration must be required on test data.", loadedVersion == null || migration.compareTo(loadedVersion) > 0); assertTrue("The current test VSM data should by partially migrated.", BorderSizeComputationExpressionMigrationParticipant.INITIAL_MIGRATION_VERSION.compareTo(loadedVersion) < 0); - + // Check the migration is also needed on 3.1.3 VSM file loadedVersion = checkVsmFileMigrationStatus(URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + REPRESENTATIONS_FILE_PATH + PATH_3_1_3 + VSM_FILE_NAME, true), true); assertTrue("The migration must be required on test data.", loadedVersion == null || migration.compareTo(loadedVersion) > 0); @@ -105,31 +105,21 @@ public class BorderSizeMigrationTest extends SiriusTestCase { // Check that the migration is needed. Version migration = BorderSizeRepresentationFileMigrationParticipant.MIGRATION_VERSION; assertTrue("The migration must be required on test data.", loadedVersion == null || migration.compareTo(loadedVersion) > 0); - - // Check the migration is not needed on 3.1.0 aird file (testBorderSizeComputationExpressionMigrationNotDoneOn3_1_0_files ensures it will produce no effect) - loadedVersion = checkRepresentationFileMigrationStatus(URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + REPRESENTATIONS_FILE_PATH + PATH_3_1_0 + REPRESENTATIONS_FILE_NAME, true), - false); - assertTrue("The current aird test data should have been migrated to 3.1.0.", BorderSizeRepresentationFileMigrationParticipant.MIGRATION_VERSION.compareTo(loadedVersion) < 0); - - // Check the migration is not also needed on 3.1.3 aird file (testBorderSizeComputationExpressionMigrationNotDoneOn3_1_3_files ensures it will produce no effect) - loadedVersion = checkRepresentationFileMigrationStatus(URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + REPRESENTATIONS_FILE_PATH + PATH_3_1_3 + REPRESENTATIONS_FILE_NAME, true), - false); - assertTrue("The current aird test data should have been migrated to 3.1.3.", BorderSizeRepresentationFileMigrationParticipant.MIGRATION_VERSION.compareTo(loadedVersion) < 0); } /** * Check the behavior of the border size migration on an aird loaded from * plugins. + * + * @throws IOException */ - public void testBorderSizeMigrationDoneInPlugin() { + public void testBorderSizeMigrationDoneInPlugin() throws IOException { + copyFilesToTestProject(SiriusTestsPlugin.PLUGIN_ID, REPRESENTATIONS_FILE_PATH, REPRESENTATIONS_FILE_NAME); + ResourceSet set = new ResourceSetImpl(); DAnalysis analysis = null; - try { - analysis = (DAnalysis) ModelUtils.load(URI.createPlatformPluginURI(SiriusTestsPlugin.PLUGIN_ID + REPRESENTATIONS_FILE_PATH + REPRESENTATIONS_FILE_NAME, true), set); - } catch (IOException e) { - e.printStackTrace(); - } + analysis = (DAnalysis) ModelUtils.load(URI.createPlatformResourceURI(TEMPORARY_PROJECT_NAME + "/" + REPRESENTATIONS_FILE_NAME, true), set); // Check that the migration was done. assertNotNull("Check the aird test data.", analysis); @@ -141,6 +131,12 @@ public class BorderSizeMigrationTest extends SiriusTestCase { assertTrue("Before save, the migration framework will return true even if the migration has been done during load.", RepresentationsFileMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(version))); + analysis.eResource().save(Collections.emptyMap()); + + // save should update the version. + version = analysis.getVersion(); + assertFalse("The version tag should now be set telling that the migration was done.", RepresentationsFileMigrationService.getInstance().isMigrationNeeded(Version.parseVersion(version))); + // We have to check the migration effect to be sure that the migration // is effective. checkMigrationEffect(analysis, true); diff --git a/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF index 274bbab40a..dd01aca60f 100644 --- a/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF @@ -68,6 +68,7 @@ Export-Package: org.eclipse.sirius.description.contribution.provider;version="2. org.eclipse.sirius.ui.tools.internal.perspectives;x-internal:=true;version="2.0.4", org.eclipse.sirius.ui.tools.internal.preference;x-internal:=true;version="2.0.5", org.eclipse.sirius.ui.tools.internal.properties;x-internal:=true;version="2.0.3", + org.eclipse.sirius.ui.tools.internal.selection;x-internal:=true;version="4.0.0", org.eclipse.sirius.ui.tools.internal.util;x-internal:=true;version="2.0.4", org.eclipse.sirius.ui.tools.internal.views;x-internal:=true;version="2.0.4", org.eclipse.sirius.ui.tools.internal.views.common;x-internal:=true;version="2.0.4", diff --git a/plugins/org.eclipse.sirius.ui/icons/full/obj16/TypedVariable.gif b/plugins/org.eclipse.sirius.ui/icons/full/obj16/TypedVariable.gif Binary files differindex 4365960a04..1b41bd7cf1 100644 --- a/plugins/org.eclipse.sirius.ui/icons/full/obj16/TypedVariable.gif +++ b/plugins/org.eclipse.sirius.ui/icons/full/obj16/TypedVariable.gif diff --git a/plugins/org.eclipse.sirius.ui/plugin.properties b/plugins/org.eclipse.sirius.ui/plugin.properties index f1e1aaecef..95f5fd8bc6 100644 --- a/plugins/org.eclipse.sirius.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.ui/plugin.properties @@ -319,6 +319,7 @@ TraceabilityMarkerNavigationProvider_dialogMessage = Select the Representations TraceabilityMarkerNavigationProvider_dialogTitle = Open representations referencing {0} TraceabilityMarkerNavigationProvider_noSessionFoundError = We can''t find a session associated to the given editor "{0}" TreeEditorDialogFactory_error = An error occured in {0} +TypedVariableValueDialog_title = Enter variable value(s) UserSession_openRepresentationTask = Open representation... UserSession_representationNotFound = Cannot find representation: {0} UserSession_viewpointSelectionFailed = Cannot select viewpoints: {0}. diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java index b75687d0e4..072fe4a2b6 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/command/AbstractSWTCallback.java @@ -14,6 +14,7 @@ import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IProgressMonitor; @@ -52,10 +53,12 @@ import org.eclipse.sirius.ui.business.api.dialect.DialectUIManager; import org.eclipse.sirius.ui.business.api.resource.LoadEMFResourceRunnableWithProgress; import org.eclipse.sirius.ui.tools.api.Messages; import org.eclipse.sirius.ui.tools.api.views.ViewHelper; +import org.eclipse.sirius.ui.tools.internal.selection.TypedVariableValueDialog; import org.eclipse.sirius.viewpoint.DAnalysisSessionEObject; import org.eclipse.sirius.viewpoint.DRepresentation; import org.eclipse.sirius.viewpoint.DRepresentationElement; import org.eclipse.sirius.viewpoint.SiriusPlugin; +import org.eclipse.sirius.viewpoint.description.TypedVariable; import org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable; import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.widgets.Display; @@ -204,6 +207,16 @@ public abstract class AbstractSWTCallback implements UICallBack { } @Override + public List<String> askForTypedVariable(List<TypedVariable> typedVariableList, List<String> defaultValues) throws InterruptedException { + final TypedVariableValueDialog dialog = new TypedVariableValueDialog(typedVariableList, defaultValues, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); + final int result = dialog.open(); + if (result == Window.OK) { + return dialog.getValues(); + } + throw new InterruptedException(); + } + + @Override public boolean shouldReload(final Resource resource) { return openQuestion(org.eclipse.sirius.viewpoint.provider.Messages.AbstractSWTCallback_shouldReload_title, MessageFormat.format(org.eclipse.sirius.viewpoint.provider.Messages.AbstractSWTCallback_shouldReload_message, resource.getURI())); @@ -250,7 +263,8 @@ public abstract class AbstractSWTCallback implements UICallBack { * Return an expression describing what is saving : * <UL> * <LI>"Models" if only semantic files have been modified,</LI> - * <LI>"Representations" if only representations files have been modified,</LI> + * <LI>"Representations" if only representations files have been modified, + * </LI> * <LI>"Models and Representations" if both.</LI> * </UL> * suffixed with : @@ -340,5 +354,4 @@ public abstract class AbstractSWTCallback implements UICallBack { MessageDialog.openError(getActiveShell(), title, message); } } - } diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/selection/TypedVariableValueDialog.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/selection/TypedVariableValueDialog.java new file mode 100644 index 0000000000..1fe40d56d6 --- /dev/null +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/selection/TypedVariableValueDialog.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2015 Obeo. + * 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.ui.tools.internal.selection; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.sirius.viewpoint.description.TypedVariable; +import org.eclipse.sirius.viewpoint.provider.Messages; +import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * A dialog to allow the user to give the values of the TypedVariable. + * + * @author <a href="mailto:laurent.fasani@obeo.fr">Laurent Fasani</a> + */ +public class TypedVariableValueDialog extends Dialog { + + /** Full path of the information icon. */ + public static final String ICON_INFORMATION = "icons/full/others/prefshelp.gif"; //$NON-NLS-1$ + + /** + * The full path of the resource. + */ + private List<Text> valueTextList; + + private List<TypedVariable> typedVariableList; + + private List<String> values = new ArrayList<String>(); + + private List<String> defaultValues; + + /** + * Creates a dialog that prompts the user for giving the value for each + * TypedVariable of typedVariableList. + * + * @param typedVariableList + * the TypedVariable for which to user input the value + * @param defaultValues + * used to initialize values. This list must have the + * typedVariableList size. + * @param parentShell + * the parent shell of this dialog + */ + public TypedVariableValueDialog(List<TypedVariable> typedVariableList, List<String> defaultValues, Shell parentShell) { + super(parentShell); + this.typedVariableList = typedVariableList; + valueTextList = new ArrayList<Text>(); + this.defaultValues = defaultValues; + } + + @Override + protected void configureShell(Shell newShell) { + super.configureShell(newShell); + newShell.setText(Messages.TypedVariableValueDialog_title); + } + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + Image image = SiriusEditPlugin.getPlugin().getImage(SiriusEditPlugin.Implementation.findImageDescriptor(ICON_INFORMATION)); + + for (int i = 0; i < typedVariableList.size(); i++) { + GridLayout layout = new GridLayout(3, false); + composite.setLayout(layout); + composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + TypedVariable typedVariable = typedVariableList.get(i); + Label label = new Label(composite, SWT.NONE); + GridData layoutData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false, 1, 1); + label.setLayoutData(layoutData); + label.setText(typedVariable.getName()); + + Label labelImage = new Label(composite, SWT.NONE); + labelImage.setLayoutData(new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false)); + if (image != null) { + labelImage.setImage(image); + } + labelImage.setToolTipText(typedVariable.getUserDocumentation()); + + Text text = new Text(composite, SWT.BORDER); + valueTextList.add(text); + layoutData = new GridData(SWT.FILL, SWT.BEGINNING, true, false); + text.setLayoutData(layoutData); + text.setText(defaultValues.get(i)); + } + + Dialog.applyDialogFont(composite); + + return composite; + } + + @Override + protected void okPressed() { + for (Text text : valueTextList) { + values.add(text.getText()); + } + + super.okPressed(); + } + + /** + * Return the values. + * + * @return the values + */ + public List<String> getValues() { + return values; + } + +} 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 31e667150e..0f76f6b746 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 @@ -940,6 +940,9 @@ public final class Messages { public static String TreeEditorDialogFactory_error; @TranslatableMessage + public static String TypedVariableValueDialog_title; + + @TranslatableMessage public static String UserSession_openRepresentationTask; @TranslatableMessage diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/description/DescriptionInterpretedExpressionTargetSwitch.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/description/DescriptionInterpretedExpressionTargetSwitch.java index 61bf5f1229..e1ec1033f8 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/description/DescriptionInterpretedExpressionTargetSwitch.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/internal/dialect/description/DescriptionInterpretedExpressionTargetSwitch.java @@ -26,6 +26,7 @@ import org.eclipse.sirius.viewpoint.description.EAttributeCustomization; import org.eclipse.sirius.viewpoint.description.InterpolatedColor; import org.eclipse.sirius.viewpoint.description.SelectionDescription; import org.eclipse.sirius.viewpoint.description.SemanticBasedDecoration; +import org.eclipse.sirius.viewpoint.description.TypedVariable; import org.eclipse.sirius.viewpoint.description.VSMElementCustomization; import org.eclipse.sirius.viewpoint.description.util.DescriptionSwitch; @@ -132,6 +133,7 @@ public class DescriptionInterpretedExpressionTargetSwitch extends DescriptionSwi * * @see org.eclipse.sirius.viewpoint.description.util.DescriptionSwitch#caseSemanticBasedDecoration(org.eclipse.sirius.viewpoint.description.SemanticBasedDecoration) */ + @Override public Option<Collection<String>> caseSemanticBasedDecoration(SemanticBasedDecoration object) { Option<Collection<String>> result = null; Collection<String> target = Sets.newLinkedHashSet(); @@ -238,4 +240,22 @@ public class DescriptionInterpretedExpressionTargetSwitch extends DescriptionSwi } return result; } + + @Override + public Option<Collection<String>> caseTypedVariable(TypedVariable object) { + Option<Collection<String>> result = null; + switch (featureID) { + case DescriptionPackage.TYPED_VARIABLE__DEFAULT_VALUE_EXPRESSION: + EObjectQuery query = new EObjectQuery(object); + Option<EObject> parentRepresentationDescription = query.getFirstAncestorOfType(DescriptionPackage.eINSTANCE.getRepresentationDescription()); + if (parentRepresentationDescription.some()) { + result = globalSwitch.doSwitch(parentRepresentationDescription.get(), false); + } + break; + + default: + break; + } + return result; + } } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java index e4818effde..f603473ba8 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/NoUICallback.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2015 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 @@ -12,6 +12,7 @@ package org.eclipse.sirius.tools.api.command.ui; import java.util.Collection; import java.util.Collections; +import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.emf.common.notify.AdapterFactory; @@ -22,13 +23,14 @@ import org.eclipse.sirius.business.api.resource.LoadEMFResource; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.common.tools.api.util.TreeItemWrapper; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.description.TypedVariable; import org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable; /** * This will return default values for the UI-dependent tools. * - * @author Laurent Goubet <a - * href="mailto:laurent.goubet@obeo.fr">laurent.goubet@obeo.fr</a> + * @author Laurent Goubet + * <a href="mailto:laurent.goubet@obeo.fr">laurent.goubet@obeo.fr</a> */ public class NoUICallback implements UICallBack { /** @@ -42,6 +44,7 @@ public class NoUICallback implements UICallBack { * * @see viewpoint.command.ui.UICallBack#askForDetailName(java.lang.String) */ + @Override public String askForDetailName(final String defaultName) throws InterruptedException { return defaultName; } @@ -52,6 +55,7 @@ public class NoUICallback implements UICallBack { * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#askForDetailName(java.lang.String, * java.lang.String) */ + @Override public String askForDetailName(String defaultName, String representationDescription) throws InterruptedException { return defaultName; } @@ -62,6 +66,7 @@ public class NoUICallback implements UICallBack { * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#askForVariableValues(org.eclipse.emf.ecore.EObject, * org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable) */ + @Override public Collection<EObject> askForVariableValues(final EObject model, final SelectModelElementVariable variable) throws InterruptedException { return Collections.emptyList(); } @@ -72,6 +77,7 @@ public class NoUICallback implements UICallBack { * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#openEObjectsDialogMessage(java.util.Collection, * java.lang.String, java.lang.String) */ + @Override public boolean openEObjectsDialogMessage(final Collection<EObject> objects, final String title, final String message) { return false; } @@ -80,6 +86,7 @@ public class NoUICallback implements UICallBack { * * {@inheritDoc} */ + @Override public void openRepresentation(Session openedSession, DRepresentation representation) { // doNothing; } @@ -87,6 +94,7 @@ public class NoUICallback implements UICallBack { /** * {@inheritDoc} */ + @Override public Resource loadResource(final EditingDomain domain, final IFile file) { final LoadEMFResource operation = new LoadEMFResource(domain.getResourceSet(), file); operation.run(); @@ -96,6 +104,7 @@ public class NoUICallback implements UICallBack { /** * {@inheritDoc} */ + @Override public Collection<EObject> askForEObjects(String message, TreeItemWrapper input, AdapterFactory factory) throws InterruptedException { return Collections.emptyList(); } @@ -103,6 +112,7 @@ public class NoUICallback implements UICallBack { /** * {@inheritDoc} */ + @Override public EObject askForEObject(String message, TreeItemWrapper input, AdapterFactory factory) throws InterruptedException { return null; } @@ -113,6 +123,7 @@ public class NoUICallback implements UICallBack { * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#shouldClose(Session, * Resource) */ + @Override public boolean shouldClose(Session session, Resource resource) { return true; } @@ -122,6 +133,7 @@ public class NoUICallback implements UICallBack { * * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#shouldReload(Resource) */ + @Override public boolean shouldReload(Resource resource) { return true; } @@ -131,6 +143,7 @@ public class NoUICallback implements UICallBack { * * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#shouldRemove(Resource) */ + @Override public boolean shouldRemove(Resource resource) { return true; } @@ -140,6 +153,7 @@ public class NoUICallback implements UICallBack { * * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#getSessionDisplayed(org.eclipse.sirius.business.api.session.Session) */ + @Override public String getSessionNameToDisplayWhileSaving(Session session) { return ""; //$NON-NLS-1$ } @@ -150,7 +164,13 @@ public class NoUICallback implements UICallBack { * @see org.eclipse.sirius.tools.api.command.ui.UICallBack#openError(java.lang * .String, java.lang.String) */ + @Override public void openError(String title, String message) { // do nothing } + + @Override + public List<String> askForTypedVariable(List<TypedVariable> typedVariableList, List<String> defaultValues) { + return Collections.emptyList(); + } } diff --git a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java index ff62984d51..dce820296e 100644 --- a/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java +++ b/plugins/org.eclipse.sirius/src/org/eclipse/sirius/tools/api/command/ui/UICallBack.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010, 2011 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2015 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 @@ -11,6 +11,7 @@ package org.eclipse.sirius.tools.api.command.ui; import java.util.Collection; +import java.util.List; import org.eclipse.core.resources.IFile; import org.eclipse.emf.common.notify.AdapterFactory; @@ -20,6 +21,7 @@ import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.sirius.business.api.session.Session; import org.eclipse.sirius.common.tools.api.util.TreeItemWrapper; import org.eclipse.sirius.viewpoint.DRepresentation; +import org.eclipse.sirius.viewpoint.description.TypedVariable; import org.eclipse.sirius.viewpoint.description.tool.SelectModelElementVariable; /** @@ -193,4 +195,21 @@ public interface UICallBack { * of the dialog */ void openError(String title, String message); + + /** + * Open an UI to ask the user the value corresponding to each TypedVariable + * of typedVariableList. </br> + * The returned list has the same size as typedVariableList + * + * @param typedVariableList + * the list of variable for which to get the values + * @param defaultValues + * the default values used to initialize UI. This list must have + * the typedVariableList size. + * @return the value provided by the user + * @throws InterruptedException + * when the process is interrupted (for instance the user + * pressed "cancel".) + */ + List<String> askForTypedVariable(List<TypedVariable> typedVariableList, List<String> defaultValues) throws InterruptedException;; } |
