Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-01-13 09:07:28 -0500
committercletavernie2012-01-13 09:07:28 -0500
commitc4b801688a71f6422529f3e4e12b52bd6836b45d (patch)
treeb3c90b622086407040f508b0d38f026bb0b350c5 /plugins/customization
parent9841d7da3c6c5bd2e0b78dc711b0443340abe10c (diff)
downloadorg.eclipse.papyrus-c4b801688a71f6422529f3e4e12b52bd6836b45d.tar.gz
org.eclipse.papyrus-c4b801688a71f6422529f3e4e12b52bd6836b45d.tar.xz
org.eclipse.papyrus-c4b801688a71f6422529f3e4e12b52bd6836b45d.zip
359794: [UML - Tools] Content/Label providers
https://bugs.eclipse.org/bugs/show_bug.cgi?id=359794
Diffstat (limited to 'plugins/customization')
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/META-INF/MANIFEST.MF3
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/src/org/eclipse/papyrus/customization/properties/model/xwt/resource/XWTResource.java4
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/editor/preview/Preview.java3
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/CustomizationModelElement.java42
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/AbstractContextualContentProvider.java17
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/EnvironmentContentProvider.java29
-rw-r--r--plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java86
7 files changed, 121 insertions, 63 deletions
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/META-INF/MANIFEST.MF b/plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/META-INF/MANIFEST.MF
index 087016a33f4..624751e2ea8 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/META-INF/MANIFEST.MF
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/META-INF/MANIFEST.MF
@@ -8,7 +8,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.views.properties.model;bundle-version="0.9.0",
org.eclipse.papyrus.infra.core.log;bundle-version="0.9.0",
org.eclipse.wst.xml.core;bundle-version="1.1.600",
- org.eclipse.core.resources;bundle-version="3.7.100"
+ org.eclipse.core.resources;bundle-version="3.7.100",
+ org.eclipse.e4.xwt.tools.ui;bundle-version="0.9.0"
Export-Package: org.eclipse.papyrus.customization.properties.model.xwt.resource
Bundle-Vendor: %Bundle-Vendor
Bundle-ActivationPolicy: lazy
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/src/org/eclipse/papyrus/customization/properties/model/xwt/resource/XWTResource.java b/plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/src/org/eclipse/papyrus/customization/properties/model/xwt/resource/XWTResource.java
index 2ec3bb2465b..79640834d13 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/src/org/eclipse/papyrus/customization/properties/model/xwt/resource/XWTResource.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties.model.xwt/src/org/eclipse/papyrus/customization/properties/model/xwt/resource/XWTResource.java
@@ -120,6 +120,10 @@ public class XWTResource extends ResourceImpl {
@Override
protected void doSave(OutputStream outputStream, Map<?, ?> options) throws IOException {
try {
+ if(getContents().isEmpty()) {
+ Activator.log.warn("Cannot save an Empty XWT resource : " + getURI());
+ return;
+ }
Root root = uiSectionToXML((CompositeWidget)getContents().get(0));
xmlResource.getContents().clear();
xmlResource.getContents().add(root);
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/editor/preview/Preview.java b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/editor/preview/Preview.java
index f4c55236488..a20e788320e 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/editor/preview/Preview.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/editor/preview/Preview.java
@@ -258,6 +258,9 @@ public class Preview extends ViewPart implements ISelectionChangedListener, IPar
//The outputstream cannot be formatted. If format is true, this is
//the real file (and not the preview file) that will be formatted
options.put(XWTResource.OPTION_FORMAT, false);
+ if(section.getWidget() == null || section.getWidget().eResource() == null) {
+ return null;
+ }
section.getWidget().eResource().save(os, options);
return xwtFile.toURI().toURL();
} catch (IOException ex) {
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/CustomizationModelElement.java b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/CustomizationModelElement.java
index a41e350993e..685627330ff 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/CustomizationModelElement.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/modelelement/CustomizationModelElement.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.papyrus.customization.properties.providers.ConstraintDescriptorContentProvider;
import org.eclipse.papyrus.customization.properties.providers.ContextLabelProvider;
import org.eclipse.papyrus.customization.properties.providers.DataContextElementContentProvider;
@@ -29,10 +30,16 @@ import org.eclipse.papyrus.customization.properties.providers.PropertyEditorType
import org.eclipse.papyrus.customization.properties.providers.TabContentProvider;
import org.eclipse.papyrus.infra.constraints.ConstraintsPackage;
import org.eclipse.papyrus.infra.constraints.providers.ConstraintTypeContentProvider;
+import org.eclipse.papyrus.infra.emf.providers.EMFGraphicalContentProvider;
+import org.eclipse.papyrus.infra.emf.providers.strategy.ContainmentBrowseStrategy;
+import org.eclipse.papyrus.infra.emf.providers.strategy.StrategyBasedContentProvider;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.providers.EmptyContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
+import org.eclipse.papyrus.infra.widgets.strategy.IStrategyBasedContentProvider;
+import org.eclipse.papyrus.infra.widgets.strategy.ProviderBasedBrowseStrategy;
+import org.eclipse.papyrus.infra.widgets.strategy.TreeBrowseStrategy;
import org.eclipse.papyrus.views.properties.contexts.Context;
import org.eclipse.papyrus.views.properties.contexts.ContextsPackage;
import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
@@ -42,8 +49,8 @@ import org.eclipse.papyrus.views.properties.modelelement.AbstractModelElement;
import org.eclipse.papyrus.views.properties.modelelement.DataSource;
import org.eclipse.papyrus.views.properties.modelelement.EMFModelElement;
import org.eclipse.papyrus.views.properties.modelelement.ModelElement;
+import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager;
import org.eclipse.papyrus.views.properties.ui.PropertyEditor;
-import org.eclipse.papyrus.views.properties.ui.UiPackage;
/**
* A {@link ModelElement} for customization specific properties
@@ -83,6 +90,7 @@ public class CustomizationModelElement extends AbstractModelElement {
providers.put(EnvironmentPackage.eINSTANCE.getStandardWidgetType(), new EnvironmentContentProvider(EnvironmentPackage.eINSTANCE.getEnvironment_WidgetTypes()));
providers.put(EnvironmentPackage.eINSTANCE.getLayoutType(), new EnvironmentContentProvider(EnvironmentPackage.eINSTANCE.getEnvironment_LayoutTypes()));
providers.put(EnvironmentPackage.eINSTANCE.getModelElementFactoryDescriptor(), new EnvironmentContentProvider(EnvironmentPackage.eINSTANCE.getEnvironment_ModelElementFactories()));
+ providers.put(EnvironmentPackage.eINSTANCE.getPropertyEditorType(), new EnvironmentContentProvider(EnvironmentPackage.eINSTANCE.getEnvironment_PropertyEditorTypes()));
providers.put(org.eclipse.papyrus.infra.constraints.environment.EnvironmentPackage.eINSTANCE.getConstraintType(), new ConstraintTypeContentProvider());
}
@@ -103,6 +111,32 @@ public class CustomizationModelElement extends AbstractModelElement {
return EmptyContentProvider.instance;
}
+ IStaticContentProvider provider = findProvider(feature);
+
+ if(provider == null) {
+ return delegate.getContentProvider(propertyPath);
+ }
+
+ if(provider instanceof ITreeContentProvider) {
+ IStrategyBasedContentProvider strategyProvider = getStrategyProvider((ITreeContentProvider)provider);
+
+ if(feature.getEType() == EnvironmentPackage.eINSTANCE.getPropertyEditorType()) {
+ return new PropertyEditorTypeContentProvider(strategyProvider, (PropertyEditor)delegate.getSource());
+ } else {
+ return new EMFGraphicalContentProvider(strategyProvider, ConfigurationManager.instance.getResourceSet(), "history_" + feature.getName());
+ }
+ }
+ return provider;
+ }
+
+ protected IStrategyBasedContentProvider getStrategyProvider(ITreeContentProvider provider) {
+ TreeBrowseStrategy browseStrategy = new ProviderBasedBrowseStrategy(provider);
+ TreeBrowseStrategy revealStrategy = new ContainmentBrowseStrategy(provider);
+
+ return new StrategyBasedContentProvider(browseStrategy, revealStrategy);
+ }
+
+ protected IStaticContentProvider findProvider(EStructuralFeature feature) {
EClassifier classifier = feature.getEType();
if(providers.containsKey(classifier)) {
return providers.get(classifier);
@@ -118,11 +152,9 @@ public class CustomizationModelElement extends AbstractModelElement {
return new DataContextElementContentProvider((DataContextElement)delegate.getSource());
} else if(classifier == ContextsPackage.eINSTANCE.getContext()) {
return new DependencyContentProvider((Context)delegate.getSource());
- } else if(feature == UiPackage.eINSTANCE.getPropertyEditor_WidgetType()) {
- return new PropertyEditorTypeContentProvider((PropertyEditor)delegate.getSource());
- } else {
- return delegate.getContentProvider(propertyPath);
}
+
+ return null;
}
private boolean isDataContextElement(EClassifier classifier) {
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/AbstractContextualContentProvider.java b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/AbstractContextualContentProvider.java
index 34335d381cc..b905edac67b 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/AbstractContextualContentProvider.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/AbstractContextualContentProvider.java
@@ -17,7 +17,8 @@ import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.papyrus.infra.widgets.providers.AbstractFilteredContentProvider;
+import org.eclipse.papyrus.infra.emf.providers.strategy.SemanticEMFContentProvider;
+import org.eclipse.papyrus.infra.tools.util.ListHelper;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.views.properties.contexts.Context;
import org.eclipse.papyrus.views.properties.util.PropertiesUtil;
@@ -30,7 +31,7 @@ import org.eclipse.papyrus.views.properties.util.PropertiesUtil;
* @author Camille Letavernier
*
*/
-public abstract class AbstractContextualContentProvider extends AbstractFilteredContentProvider implements IStaticContentProvider {
+public abstract class AbstractContextualContentProvider extends SemanticEMFContentProvider implements IStaticContentProvider {
/**
* The list of available contexts in the current model
@@ -38,11 +39,6 @@ public abstract class AbstractContextualContentProvider extends AbstractFiltered
protected Collection<Context> contexts;
/**
- * The EObject used to retrieve the available contexts
- */
- protected EObject source;
-
- /**
*
* Constructor.
*
@@ -50,12 +46,11 @@ public abstract class AbstractContextualContentProvider extends AbstractFiltered
* The EObject used to retrieve the available contexts
*/
protected AbstractContextualContentProvider(EObject source) {
- contexts = findContexts(source);
- this.source = source;
- showIfHasVisibleParent = true;
+ super(findContexts(source).toArray(new Context[0]));
+ contexts = ListHelper.asList((Context[])roots);
}
- private List<Context> findContexts(EObject source) {
+ private static List<Context> findContexts(EObject source) {
List<Context> contexts = new LinkedList<Context>();
Context rootContext = null;
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/EnvironmentContentProvider.java b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/EnvironmentContentProvider.java
index e070c7ab8d9..65a4255405b 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/EnvironmentContentProvider.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/EnvironmentContentProvider.java
@@ -14,8 +14,11 @@ package org.eclipse.papyrus.customization.properties.providers;
import java.util.LinkedList;
import java.util.List;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.papyrus.infra.widgets.providers.AbstractFilteredContentProvider;
+import org.eclipse.papyrus.customization.properties.Activator;
+import org.eclipse.papyrus.infra.emf.providers.strategy.SemanticEMFContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.views.properties.environment.Environment;
import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager;
@@ -25,9 +28,7 @@ import org.eclipse.papyrus.views.properties.runtime.ConfigurationManager;
*
* @author Camille Letavernier
*/
-public class EnvironmentContentProvider extends AbstractFilteredContentProvider implements IStaticContentProvider {
-
- private Object[] contents;
+public class EnvironmentContentProvider extends SemanticEMFContentProvider implements IStaticContentProvider {
/**
* Constructor.
@@ -37,20 +38,20 @@ public class EnvironmentContentProvider extends AbstractFilteredContentProvider
* different environments.
*/
public EnvironmentContentProvider(EStructuralFeature feature) {
+ super(null, feature, getRoots(feature));
+ }
+
+ private static EObject[] getRoots(EStructuralFeature feature) {
+ if(!(feature.getEType() instanceof EClass)) {
+ Activator.log.warn("The feature " + feature + " cannot be handled by this content provider");
+ return new EObject[0];
+ }
+
List<Object> allObjects = new LinkedList<Object>();
for(Environment environment : ConfigurationManager.instance.getPropertiesRoot().getEnvironments()) {
allObjects.addAll((List<?>)environment.eGet(feature));
}
- contents = allObjects.toArray();
- showIfHasVisibleParent = true;
- }
-
- public Object[] getElements() {
- return contents;
- }
-
- public Object[] getElements(Object inputElement) {
- return getElements();
+ return allObjects.toArray(new EObject[0]);
}
}
diff --git a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java
index d2981380573..5e0e2b024cb 100644
--- a/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java
+++ b/plugins/customization/org.eclipse.papyrus.customization.properties/src/org/eclipse/papyrus/customization/properties/providers/PropertyEditorTypeContentProvider.java
@@ -1,35 +1,35 @@
package org.eclipse.papyrus.customization.properties.providers;
-import java.util.LinkedList;
-import java.util.List;
-
+import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.emf.providers.EMFGraphicalContentProvider;
import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
import org.eclipse.papyrus.infra.widgets.editors.BooleanToggle;
import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
-import org.eclipse.papyrus.infra.widgets.providers.IGraphicalContentProvider;
-import org.eclipse.papyrus.views.properties.environment.EnvironmentPackage;
+import org.eclipse.papyrus.infra.widgets.providers.AbstractTreeFilter;
import org.eclipse.papyrus.views.properties.environment.PropertyEditorType;
-import org.eclipse.papyrus.views.properties.environment.Type;
import org.eclipse.papyrus.views.properties.ui.PropertyEditor;
import org.eclipse.papyrus.views.properties.widgets.layout.PropertiesLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
-public class PropertyEditorTypeContentProvider extends EnvironmentContentProvider implements IGraphicalContentProvider, ICommitListener {
+public class PropertyEditorTypeContentProvider extends EMFGraphicalContentProvider implements ICommitListener {
private PropertyEditor source;
- private Viewer viewer;
-
- private boolean filter = true;
-
private BooleanToggle filterButton;
- public PropertyEditorTypeContentProvider(PropertyEditor source) {
- super(EnvironmentPackage.eINSTANCE.getEnvironment_PropertyEditorTypes());
+ private PropertyEditorTypeViewerFilter currentFilter;
+
+ public PropertyEditorTypeContentProvider(IStructuredContentProvider semanticProvider, PropertyEditor source) {
+ super(semanticProvider, source.eResource().getResourceSet(), getHistoryId(source));
this.source = source;
+ this.currentFilter = new PropertyEditorTypeViewerFilter();
+ }
+
+ private static String getHistoryId(PropertyEditor source) {
+ return "history_propertyEditorType_" + source.eResource().getURI();
}
@Override
@@ -39,37 +39,59 @@ public class PropertyEditorTypeContentProvider extends EnvironmentContentProvide
filterButton = new BooleanToggle(self);
filterButton.setText("Filter");
- filterButton.setValue(this.filter);
+ filterButton.setValue(currentFilter.getFilter());
filterButton.addCommitListener(this);
super.createBefore(self);
}
@Override
- public Object[] getElements() {
- Object[] elements = super.getElements();
- if(!filter || source.getProperty() == null) {
- return elements;
- }
-
- Type type = source.getProperty().getType();
- boolean isPropertyMultiple = source.getProperty().getMultiplicity() != 1;
- List<Object> filteredElements = new LinkedList<Object>();
- for(Object element : elements) {
- PropertyEditorType editorType = (PropertyEditorType)element;
- boolean isElementMultiple = editorType.getMultiplicity() != 1;
- if(editorType.getType() == type && isPropertyMultiple == isElementMultiple) {
- filteredElements.add(element);
- }
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if(super.viewer != null) {
+ super.viewer.removeFilter(currentFilter);
}
-
- return filteredElements.toArray();
+ super.inputChanged(viewer, oldInput, newInput);
+ super.viewer.addFilter(currentFilter);
}
+ @Override
public void commit(AbstractEditor editor) {
- filter = filterButton.getValue();
+ currentFilter.setFilter(filterButton.getValue());
if(super.viewer != null) {
super.viewer.refresh();
}
}
+ private class PropertyEditorTypeViewerFilter extends AbstractTreeFilter {
+
+ private boolean filter = true;
+
+ @Override
+ public boolean isVisible(Viewer viewer, Object parentElement, Object element) {
+ if(!filter) {
+ return true;
+ }
+
+ Object adaptedValue = getAdaptedValue(element);
+ if(adaptedValue instanceof PropertyEditorType) {
+ PropertyEditorType editorType = (PropertyEditorType)adaptedValue;
+ if(source.getProperty() == null) {
+ return true;
+ }
+ return editorType.getType() == source.getProperty().getType();
+ }
+
+ return false;
+ }
+
+ public boolean getFilter() {
+ return filter;
+ }
+
+ public void setFilter(boolean filter) {
+ this.filter = filter;
+ clearCache();
+ }
+
+ }
+
}

Back to the top