diff options
| author | Laurent Fasani | 2015-12-29 14:25:02 +0000 |
|---|---|---|
| committer | Laurent Fasani | 2016-01-08 10:59:27 +0000 |
| commit | 8891d9a1db67a98e507291a6f58be93d7d692443 (patch) | |
| tree | 168153c0ad39fd5a0660e69a9c6d40f54068aca3 | |
| parent | e1935e63fe000a920deb6045753987da5d973671 (diff) | |
| download | org.eclipse.sirius-8891d9a1db67a98e507291a6f58be93d7d692443.tar.gz org.eclipse.sirius-8891d9a1db67a98e507291a6f58be93d7d692443.tar.xz org.eclipse.sirius-8891d9a1db67a98e507291a6f58be93d7d692443.zip | |
[483574] Add typed variable functionality
bug: 483574
Change-Id: I2109ee9211798df1c22c6eef949653ad383873b4
Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
22 files changed, 459 insertions, 95 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 c7e69bc284..ae581e4f0c 100644 --- a/plugins/org.eclipse.sirius.diagram/model/diagram.ecore +++ b/plugins/org.eclipse.sirius.diagram/model/diagram.ecore @@ -2901,19 +2901,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 bfe2d71a30..b039850026 100644 --- a/plugins/org.eclipse.sirius.diagram/model/diagram.genmodel +++ b/plugins/org.eclipse.sirius.diagram/model/diagram.genmodel @@ -950,9 +950,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.tests.junit/data/unit/variablefilter/ticketvp1063/vp-1063.odesign b/plugins/org.eclipse.sirius.tests.junit/data/unit/variablefilter/ticketvp1063/vp-1063.odesign index 30e5fc17a9..9cecbd4d18 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,15 +1,15 @@ <?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.0.0.201505222000"> +<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="<%$EClass.nContains(current)%>"> - <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"> + <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']"/> @@ -17,7 +17,7 @@ </style> </containerMappings> <containerMappings name="EEnum" domainClass="EEnum"> - <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1"> + <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']"/> @@ -25,7 +25,49 @@ </style> </containerMappings> <containerMappings name="EPackage" domainClass="EPackage"> - <style xsi:type="style:FlatContainerStyleDescription" arcWidth="1" arcHeight="1"> + <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"> + <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']"/> 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..14ba6a2cc5 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, 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.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,44 @@ 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) + 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 +214,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 7dd4392c0d..47b2d0aac9 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 @@ -98,13 +98,6 @@ 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 be migrated.", BorderSizeRepresentationFileMigrationParticipant.MIGRATION_VERSION.compareTo(loadedVersion) < 0); } /** @@ -112,11 +105,13 @@ public class BorderSizeMigrationTest extends SiriusTestCase { * plugins. */ public void testBorderSizeMigrationDoneInPlugin() { + 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); + analysis = (DAnalysis) ModelUtils.load(URI.createPlatformResourceURI(TEMPORARY_PROJECT_NAME + "/" + REPRESENTATIONS_FILE_NAME, true), set); } catch (IOException e) { e.printStackTrace(); } @@ -131,6 +126,16 @@ 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))); + try { + analysis.eResource().save(Collections.emptyMap()); + } catch (IOException e) { + e.printStackTrace(); + } + + // 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 85e62570b3..81adf2f8f8 100644 --- a/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.ui/META-INF/MANIFEST.MF @@ -47,6 +47,7 @@ Export-Package: org.eclipse.sirius.description.contribution.provider;version="2. org.eclipse.sirius.ui.tools.api.project;version="2.0.5", org.eclipse.sirius.ui.tools.api.properties;version="2.1.0", org.eclipse.sirius.ui.tools.api.provider;version="2.0.4", + org.eclipse.sirius.ui.tools.api.selection;version="3.1.3", org.eclipse.sirius.ui.tools.api.views;version="2.1.0", org.eclipse.sirius.ui.tools.api.views.common.item;version="2.0.4", org.eclipse.sirius.ui.tools.api.views.interpreterview;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 79daa29513..8706752603 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..0e039f8f29 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; @@ -51,11 +52,13 @@ import org.eclipse.sirius.tools.api.command.ui.UICallBack; 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.selection.TypedVariableValueDialog; import org.eclipse.sirius.ui.tools.api.views.ViewHelper; 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/api/selection/TypedVariableValueDialog.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/selection/TypedVariableValueDialog.java new file mode 100644 index 0000000000..7e9ecbbcbe --- /dev/null +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/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.api.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;; } |
