diff options
author | ptessier | 2020-10-28 09:44:16 +0000 |
---|---|---|
committer | vincent lorenzo | 2020-11-05 08:07:08 +0000 |
commit | e3b8ccf5f618d96996a9f1b7f64d9a4367861423 (patch) | |
tree | 0105ede176b9cab981b25af2c426843a497ffb07 /plugins/infra | |
parent | 39c29e9dc614a114bad366757c1ee8bc21b12077 (diff) | |
download | org.eclipse.papyrus-e3b8ccf5f618d96996a9f1b7f64d9a4367861423.tar.gz org.eclipse.papyrus-e3b8ccf5f618d96996a9f1b7f64d9a4367861423.tar.xz org.eclipse.papyrus-e3b8ccf5f618d96996a9f1b7f64d9a4367861423.zip |
Bug 568329 - [PropertyView] refresh problem with a usage of constraint
Change-Id: Ie3fca8b0a870674813e04d0635fcd0a8bce343ab
Signed-off-by: ptessier <patrick.tessier@cea.fr>
Diffstat (limited to 'plugins/infra')
5 files changed, 137 insertions, 53 deletions
diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/DataSource.java b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/DataSource.java index f94618c95b0..68881064ace 100644 --- a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/DataSource.java +++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/modelelement/DataSource.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010, 2017 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2010, 2017, 2020 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,7 @@ * Thibault Le Ouay t.leouay@sherpa-eng.com - Add binding implementation * Christian W. Damus (CEA) - bug 417409 * Christian W. Damus - bugs 455075, 510254, 515257 + * Patrick Tessier (CEA LIST), bug 568329 * *****************************************************************************/ package org.eclipse.papyrus.infra.properties.ui.modelelement; @@ -75,7 +76,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL private IStructuredSelection selection; - private Map<String, ModelElement> elements = new HashMap<String, ModelElement>(); + private Map<String, ModelElement> elements = new HashMap<>(); /** * Constructs a new DataSource from the given view and selection @@ -99,7 +100,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL * @param propertyPath * The propertyPath to lookup * @return - * The ModelElement associated to the given propertyPath + * The ModelElement associated to the given propertyPath */ public ModelElement getModelElement(String propertyPath) { // ConfigurationManager.instance.getProperty(propertyPath) @@ -129,7 +130,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL * @param propertyPath * The property path for which we want to retrieve an ObservableValue * @return - * The IObservable corresponding to the given propertyPath + * The IObservable corresponding to the given propertyPath */ public IObservable getObservable(String propertyPath) { String localPropertyPath = getLocalPropertyPath(propertyPath); @@ -159,7 +160,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL * @param propertyPath * The property path for which we want to retrieve a ContentProvider * @return - * The IStaticContentProvider corresponding to the given propertyPath + * The IStaticContentProvider corresponding to the given propertyPath */ public IStaticContentProvider getContentProvider(final String propertyPath) { class Delegator extends EncapsulatedContentProvider implements IDataSourceListener { @@ -216,13 +217,13 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL * @param propertyPath * The property path for which we want to retrieve an ILabelProvider * @return - * The ILabelProvider corresponding to the given propertyPath + * The ILabelProvider corresponding to the given propertyPath */ public ILabelProvider getLabelProvider(final String propertyPath) { class Delegator extends LabelProvider implements IDataSourceListener, ILabelProviderListener, IStyledLabelProvider { private ILabelProvider delegate; - private final CopyOnWriteArrayList<ILabelProviderListener> listeners = new CopyOnWriteArrayList<ILabelProviderListener>(); + private final CopyOnWriteArrayList<ILabelProviderListener> listeners = new CopyOnWriteArrayList<>(); { DataSource.this.addDataSourceListener(this); @@ -314,7 +315,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL /** * {@inhiriteDoc} - * + * * @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object) */ @Override @@ -374,7 +375,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL } @Override - public void handleChange(ChangeEvent event) { + public synchronized void handleChange(ChangeEvent event) { Object[] listeners = changeListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { try { @@ -428,7 +429,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL /** * @param propertyPath * @return - * true if the property represented by this propertyPath is ordered + * true if the property represented by this propertyPath is ordered */ public boolean isOrdered(String propertyPath) { ModelElement element = getModelElement(propertyPath); @@ -441,7 +442,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL /** * @param propertyPath * @return - * true if the property represented by this propertyPath is unique + * true if the property represented by this propertyPath is unique */ public boolean isUnique(String propertyPath) { ModelElement element = getModelElement(propertyPath); @@ -454,7 +455,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL /** * @param propertyPath * @return - * true if the property represented by this propertyPath is mandatory + * true if the property represented by this propertyPath is mandatory */ public boolean isMandatory(String propertyPath) { ModelElement element = getModelElement(propertyPath); @@ -467,7 +468,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL /** * @param propertyPath * @return - * true if the property represented by this propertyPath is editable + * true if the property represented by this propertyPath is editable */ public boolean isEditable(String propertyPath) { ModelElement element = getModelElement(propertyPath); @@ -500,7 +501,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL * @param propertyPath * The property path to lookup * @return - * The factory used to edit and/or instantiate values for this property path + * The factory used to edit and/or instantiate values for this property path */ public ReferenceValueFactory getValueFactory(String propertyPath) { ModelElement element = getModelElement(propertyPath); @@ -515,7 +516,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL * * @param propertyPath * @return - * The default value for the given property + * The default value for the given property */ public Object getDefaultValue(String propertyPath) { ModelElement element = getModelElement(propertyPath); @@ -536,7 +537,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL * * @param propertyPath * @return - * True if the widget should use the direct edition option for the given property + * True if the widget should use the direct edition option for the given property */ public boolean getDirectCreation(String propertyPath) { ModelElement element = getModelElement(propertyPath); @@ -576,7 +577,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL /** * return the NameResolutionHelper to use for completion - * + * * @param propertyPath * @return */ @@ -590,7 +591,7 @@ public class DataSource extends ReferenceCounted<DataSource> implements IChangeL /** * return the Papyrus Converter to convert the object to edit or display string and to find the object from a string - * + * * @param propertyPath * @return */ diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/runtime/DefaultDisplayEngine.java b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/runtime/DefaultDisplayEngine.java index 0cc758304d5..0c587a30446 100644 --- a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/runtime/DefaultDisplayEngine.java +++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/runtime/DefaultDisplayEngine.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010, 2017 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2010, 2017,2020 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -13,6 +13,7 @@ * Christian W. Damus (CEA) - Use URIs to support non-URL-compatible storage (CDO) * Christian W. Damus (CEA) - bugs 417409, 444227 * Christian W. Damus - bugs 450478, 454536, 515257 + * Patrick Tessier (CEA LIST)- bug 568329 * *****************************************************************************/ package org.eclipse.papyrus.infra.properties.ui.runtime; @@ -31,6 +32,8 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.papyrus.infra.constraints.ConstraintDescriptor; +import org.eclipse.papyrus.infra.constraints.constraints.Constraint; import org.eclipse.papyrus.infra.emf.utils.EMFHelper; import org.eclipse.papyrus.infra.properties.catalog.PropertiesURIHandler; import org.eclipse.papyrus.infra.properties.contexts.Context; @@ -75,6 +78,10 @@ public class DefaultDisplayEngine implements DisplayEngine { private boolean allowDuplicate; private Object xmlCache; + // Cache of data source for which the widget page has been build + private List<DataSource> dataSourceCache = new ArrayList<>(); + // Cache about evaluation of set of constraint linked to a data source. + private HashMap<DataSource, Boolean> constraintEvaluationCache = new HashMap<>(); /** * Constructs a new DisplayEnginet that doesn't allow the duplication of sections @@ -289,6 +296,33 @@ public class DefaultDisplayEngine implements DisplayEngine { @Override public void refreshSection(Composite parent, Section section, DataSource source) { + // if the data source is not is the cache, sure we must destroy and construct all controls. + if (!(dataSourceCache.contains(source))) { + dataSourceCache.add(source); + storeConstraintevalutionForSource(section, source); + + disposeAndCreateControl(parent, section, source); + } else { + // in this context, all widget have been constructed and need to be refreshed + // but if constraints have been associated to the data source, maybe new widget may + // appear depending to the change of the value + if (constraintEvaluationCache.containsKey(source)) { + boolean newValue = evaluateConstraintForSection(section, source); + // the value has changed , destruction and creation is needed. + if (newValue != constraintEvaluationCache.get(source).booleanValue()) { + disposeAndCreateControl(parent, section, source); + storeConstraintevalutionForSource(section, source); + + } + // in other case, only refresh is needed. + } + } + } + + /** + * this method destroy all SWT controler and create all. + */ + protected void disposeAndCreateControl(Composite parent, Section section, DataSource source) { for (Control control : parent.getChildren()) { control.dispose(); } @@ -302,6 +336,38 @@ public class DefaultDisplayEngine implements DisplayEngine { } } + /** + * This method is used to store evaluation of constraint to determine if it is needed to add potential new controls. + * + * @since 5.0 + */ + @Override + public void storeConstraintevalutionForSource(Section section, DataSource source) { + if (section.getConstraints().size() > 0) { + boolean value = evaluateConstraintForSection(section, source); + if (constraintEvaluationCache.containsKey(source)) { + constraintEvaluationCache.replace(source, new Boolean(value)); + } else { + constraintEvaluationCache.put(source, new Boolean(value)); + } + } + } + + /** + * Evaluate constraints linked to a data source + * + * @since 5.0 + */ + protected boolean evaluateConstraintForSection(Section section, DataSource source) { + boolean constraintsvalue = false; + for (ConstraintDescriptor cd : section.getConstraints()) { + Constraint c = org.eclipse.papyrus.infra.constraints.runtime.ConstraintFactory.getInstance().createFromModel(cd); + List<?> selectionList = source.getSelection().toList(); + constraintsvalue = constraintsvalue || c.match(selectionList); + } + return constraintsvalue; + } + @Override public Control createSection(Composite parent, Section section, URI sectionFile, DataSource source) { if (sectionFile == null) { @@ -350,7 +416,9 @@ public class DefaultDisplayEngine implements DisplayEngine { XWT.setLoadingContext(xwtContext); } layout(parent); - + // After creation, store values in the caches + dataSourceCache.add(source); + storeConstraintevalutionForSource(section, source); return control; } diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/runtime/DisplayEngine.java b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/runtime/DisplayEngine.java index 04271cb4f06..e9e3aff827f 100644 --- a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/runtime/DisplayEngine.java +++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/runtime/DisplayEngine.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010, 2013 CEA LIST. + * Copyright (c) 2010, 2013, 2020 CEA LIST. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -11,6 +11,7 @@ * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation * Christian W. Damus (CEA) - Use URIs to support non-URL-compatible storage (CDO) + * Patrick Tessier (CEA LIST) -bug 568329 *****************************************************************************/ package org.eclipse.papyrus.infra.properties.ui.runtime; @@ -102,4 +103,11 @@ public interface DisplayEngine { * Disposes this display engine */ public void dispose(); + + /** + * this method is used to store evaluation of constraint to determine if it is needed to add potential new controls. + * + * @since 5.0 + */ + public void storeConstraintevalutionForSource(Section section, DataSource source); } diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/widgets/AbstractPropertyEditor.java b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/widgets/AbstractPropertyEditor.java index 0c6db968792..c891fe798e8 100644 --- a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/widgets/AbstractPropertyEditor.java +++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/widgets/AbstractPropertyEditor.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010, 2016-2017 CEA LIST, Christian W. Damus, Esterel Technologies SAS and others. + * Copyright (c) 2010, 2016-2017,2020 CEA LIST, Christian W. Damus, Esterel Technologies SAS and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -19,6 +19,7 @@ * Sebastien Gabel (Esterel Technologies SAS) - bug 497461 * Nicolas FAUVERGUE (CEA LIST) nicolas.fauvergue@cea.fr - Bug 515650 * Fanch BONNABESSE (ALL4TEC) fanch.bonnabesse@all4tec.net - Bug 522124 + * Patrick Tessier (CEA LIST) -bug 568329 * *****************************************************************************/ package org.eclipse.papyrus.infra.properties.ui.widgets; @@ -215,6 +216,7 @@ public abstract class AbstractPropertyEditor implements IChangeListener, Customi public void widgetDisposed(DisposeEvent e) { if (input != null) { input.removeChangeListener(AbstractPropertyEditor.this); + unhookDataSourceListener(input); } } }); @@ -307,7 +309,8 @@ public abstract class AbstractPropertyEditor implements IChangeListener, Customi public void handleChange(ChangeEvent event) { // Handle the "forceRefresh" behavior when the input DataSource sends a ChangeEvent AbstractEditor editor = getEditor(); - if (editor != null) { + + if (editor != null && !editor.isDisposed()) { editor.refreshValue(); // And refresh the read-only state @@ -518,7 +521,7 @@ public abstract class AbstractPropertyEditor implements IChangeListener, Customi * Tests if this editor is read-only * * @return - * True if this editor is read-only + * True if this editor is read-only */ @Override public boolean getReadOnly() { @@ -598,7 +601,7 @@ public abstract class AbstractPropertyEditor implements IChangeListener, Customi * Returns the editor's Layout Data * * @return - * The editor's layout data + * The editor's layout data */ public Object getLayoutData() { return getEditor() == null ? null : getEditor().getLayoutData(); @@ -619,7 +622,7 @@ public abstract class AbstractPropertyEditor implements IChangeListener, Customi * Returns the editor's Layout * * @return - * The editor's layout + * The editor's layout */ public Layout getLayout() { return getEditor() == null ? null : getEditor().getLayout(); @@ -643,7 +646,7 @@ public abstract class AbstractPropertyEditor implements IChangeListener, Customi * Indicates whether the editor's label is displayed or not * * @return - * true if the label should be displayed + * true if the label should be displayed */ @Override public boolean getShowLabel() { @@ -757,16 +760,16 @@ public abstract class AbstractPropertyEditor implements IChangeListener, Customi return listeningPropertyPaths; } -// /** FIXME: this getter introduce a regression -// See Bug 522124 and https://dev.eclipse.org/mhonarc/lists/mdt-papyrus.dev/msg04151.html -// * Return the HashSet of listening property paths. -// * -// * @return the listeningPropertyPathsSet The HashSet of listening property paths. -// * @since 3.1 -// */ -// public Set<String> getListeningPropertyPathsSet() { -// return listeningPropertyPathsSet; -// } + // /** FIXME: this getter introduce a regression + // See Bug 522124 and https://dev.eclipse.org/mhonarc/lists/mdt-papyrus.dev/msg04151.html + // * Return the HashSet of listening property paths. + // * + // * @return the listeningPropertyPathsSet The HashSet of listening property paths. + // * @since 3.1 + // */ + // public Set<String> getListeningPropertyPathsSet() { + // return listeningPropertyPathsSet; + // } /** * Return the listener classes. @@ -778,16 +781,16 @@ public abstract class AbstractPropertyEditor implements IChangeListener, Customi return listenerClasses; } -// /**FIXME: this getter introduce a regression -// See Bug 522124 and https://dev.eclipse.org/mhonarc/lists/mdt-papyrus.dev/msg04151.html -// * Return the HashSet of listener classes. -// * -// * @return the listenerClassesSet HashSet of listener classes. -// * @since 3.1 -// */ -// public Set<IPropertiesListener> getListenerClassesSet() { -// return listenerClassesSet; -// } + // /**FIXME: this getter introduce a regression + // See Bug 522124 and https://dev.eclipse.org/mhonarc/lists/mdt-papyrus.dev/msg04151.html + // * Return the HashSet of listener classes. + // * + // * @return the listenerClassesSet HashSet of listener classes. + // * @since 3.1 + // */ + // public Set<IPropertiesListener> getListenerClassesSet() { + // return listenerClassesSet; + // } /** * Set the HashSet of listening property paths. @@ -857,7 +860,7 @@ public abstract class AbstractPropertyEditor implements IChangeListener, Customi } catch (ClassNotFoundException e) { Activator.log.error("The listener classes defined in listenerClasses are not correct.", e); //$NON-NLS-1$ - } catch (InstantiationException |IllegalAccessException e) { + } catch (InstantiationException | IllegalAccessException e) { Activator.log.error(e); } } diff --git a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/xwt/XWTSection.java b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/xwt/XWTSection.java index 9d5ae5f2d95..90e75180944 100644 --- a/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/xwt/XWTSection.java +++ b/plugins/infra/properties/org.eclipse.papyrus.infra.properties.ui/src/org/eclipse/papyrus/infra/properties/ui/xwt/XWTSection.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2010, 2017 CEA LIST, Christian W. Damus, and others. + * Copyright (c) 2010, 2017, 2020 CEA LIST, Christian W. Damus, and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -12,6 +12,7 @@ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation * Christian W. Damus (CEA) - bugs 435420, 417409 * Christian W. Damus - bugs 485220, 515257 + * Patrick Tessier (CEA LIST) -bug 568329 * *****************************************************************************/ package org.eclipse.papyrus.infra.properties.ui.xwt; @@ -124,8 +125,10 @@ public class XWTSection extends AbstractPropertySection implements IChangeListen if (oldSource != source) { if (oldSource != null) { - oldSource.removeChangeListener(this); - oldSource.autoRelease(); + if (section.getConstraints().size() == 0) { + oldSource.removeChangeListener(this); + oldSource.autoRelease(); + } } this.source = source; @@ -155,6 +158,7 @@ public class XWTSection extends AbstractPropertySection implements IChangeListen } if (!isApplied()) { + display.storeConstraintevalutionForSource(section, source); hide(); return; } @@ -182,7 +186,7 @@ public class XWTSection extends AbstractPropertySection implements IChangeListen * any constraint, or if at least one of its constraints match the current selection * * @return - * True if the section should be displayed + * True if the section should be displayed */ protected boolean isApplied() { if (getConstraints().isEmpty()) { @@ -205,7 +209,7 @@ public class XWTSection extends AbstractPropertySection implements IChangeListen protected Set<Constraint> getConstraints() { if (constraints == null) { - constraints = new HashSet<Constraint>(); + constraints = new HashSet<>(); for (ConstraintDescriptor constraintDescriptor : section.getConstraints()) { Constraint constraint = ConstraintFactory.getInstance().createFromModel(constraintDescriptor); if (constraint != null) { |