Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcletavernie2012-01-12 16:33:35 +0000
committercletavernie2012-01-12 16:33:35 +0000
commitaaa0f0a63bf9890ee7911e638a41d8b721d7c2fd (patch)
treec3a0567c109cba2de3406ef18fc683e569603484 /plugins/infra
parent76fbe55c1db8045c1be47e31f59296ecac6ae157 (diff)
downloadorg.eclipse.papyrus-aaa0f0a63bf9890ee7911e638a41d8b721d7c2fd.tar.gz
org.eclipse.papyrus-aaa0f0a63bf9890ee7911e638a41d8b721d7c2fd.tar.xz
org.eclipse.papyrus-aaa0f0a63bf9890ee7911e638a41d8b721d7c2fd.zip
359794: [UML - Tools] Content/Label providers
https://bugs.eclipse.org/bugs/show_bug.cgi?id=359794
Diffstat (limited to 'plugins/infra')
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFContentProvider.java3
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFEnumeratorContentProvider.java57
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFGraphicalContentProvider.java (renamed from plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/GraphicalModelExplorerBasedContentProvider.java)157
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/HierarchicViewerFilter.java147
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/IMetaclassFilteredContentProvider.java39
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/SemanticFromModelExplorer.java19
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/ContainmentBrowseStrategy.java293
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/SemanticEMFContentProvider.java186
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/StrategyBasedContentProvider.java98
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java41
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/HistoryUtil.java47
-rw-r--r--plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ProviderHelper.java57
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF2
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/.project4
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/providers/ConstraintTypeContentProvider.java4
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF3
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/databinding/AggregatedObservable.java (renamed from plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/AggregatedObservable.java)2
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/databinding/MultipleObservableValue.java1
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/ListHelper.java41
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF5
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/CLabelObservableValue.java1
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/ComboObservableValue.java1
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/GrayedCheckboxObservableValue.java1
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/TextObservableValue.java1
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java2
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.java10
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java13
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceCombo.java2
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.java6
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringCombo.java2
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeSelectorDialog.java65
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractStaticContentProvider.java4
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractTreeFilter.java37
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/CollectionContentProvider.java16
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EmptyContentProvider.java11
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EncapsulatedContentProvider.java85
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/HierarchicToFlatContentProvider.java7
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IAdaptableContentProvider.java2
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IStaticContentProvider.java4
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/TreeToFlatContentProvider.java7
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java140
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/AbstractTreeBrowseStrategy.java31
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/IStrategyBasedContentProvider.java22
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/ProviderBasedBrowseStrategy.java133
-rw-r--r--plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/TreeBrowseStrategy.java41
46 files changed, 1296 insertions, 557 deletions
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
index 89d7a07b484..a1e65b2873d 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/META-INF/MANIFEST.MF
@@ -22,11 +22,12 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.facet.infra.browser.custom;bundle-version="0.2.0",
org.eclipse.emf.facet.infra.facet.core;bundle-version="0.2.0",
org.eclipse.emf.facet.infra.browser.custom.core;bundle-version="0.2.0",
+ org.eclipse.papyrus.infra.tools;bundle-version="0.9.0",
org.eclipse.emf.transaction;bundle-version="1.4.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.papyrus.infra.emf,
- org.eclipse.papyrus.infra.emf.commands,
org.eclipse.papyrus.infra.emf.databinding,
org.eclipse.papyrus.infra.emf.providers,
+ org.eclipse.papyrus.infra.emf.providers.strategy,
org.eclipse.papyrus.infra.emf.utils
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFContentProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFContentProvider.java
index 705f3c00482..c91107c5e55 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFContentProvider.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFContentProvider.java
@@ -28,8 +28,9 @@ import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider
* A Content provider for EMF references
*
* @author Camille Letavernier
+ * @deprecated Use the new ContentProvider tools
*/
-//TODO : Implement IHierarchicContentProvider, IGraphicalContentProvider
+@Deprecated
public class EMFContentProvider extends AbstractStaticContentProvider {
private EObject eObject;
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFEnumeratorContentProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFEnumeratorContentProvider.java
new file mode 100644
index 00000000000..a4d5f0c9d1d
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFEnumeratorContentProvider.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.providers;
+
+import org.eclipse.emf.common.util.Enumerator;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EEnum;
+import org.eclipse.emf.ecore.EEnumLiteral;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.papyrus.infra.widgets.providers.AbstractStaticContentProvider;
+
+/**
+ * An IStaticContentProvider for EMF enumerators.
+ *
+ * @author Camille Letavernier
+ */
+public class EMFEnumeratorContentProvider extends AbstractStaticContentProvider {
+
+ /**
+ * The feature representing the Enumerator for this ContentProvider
+ */
+ protected EStructuralFeature feature;
+
+ /**
+ * Constructs an EcoreEnumerator for the given Structural Feature
+ *
+ * @param feature
+ */
+ public EMFEnumeratorContentProvider(EStructuralFeature feature) {
+ this.feature = feature;
+ }
+
+ public Object[] getElements() {
+ EClassifier type = feature.getEType();
+ EEnum enumerated = (EEnum)type;
+ EEnumLiteral[] literals = enumerated.getELiterals().toArray(new EEnumLiteral[0]);
+ Enumerator[] values = new Enumerator[literals.length];
+
+ int i = 0;
+ for(EEnumLiteral literal : literals) {
+ Enumerator value = literal.getInstance();
+ values[i++] = value;
+ }
+
+ return values;
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/GraphicalModelExplorerBasedContentProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFGraphicalContentProvider.java
index 4524924576d..ddfc7a43cbe 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/GraphicalModelExplorerBasedContentProvider.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/EMFGraphicalContentProvider.java
@@ -18,22 +18,20 @@ package org.eclipse.papyrus.infra.emf.providers;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Iterator;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
@@ -46,9 +44,8 @@ import org.eclipse.papyrus.infra.emf.Activator;
import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
import org.eclipse.papyrus.infra.widgets.editors.StringEditor;
+import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.IDetailLabelProvider;
-import org.eclipse.papyrus.infra.widgets.providers.IGraphicalContentProvider;
-import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.PatternViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
@@ -62,28 +59,19 @@ import org.eclipse.swt.widgets.Table;
* this is a content provider based on the model explorer on which we can filter wanted meta-classes
* It can only filter if wantedMetaclass and metaclassNotWanted are Eclass
*/
-public class GraphicalModelExplorerBasedContentProvider extends ModelContentProvider implements IMetaclassFilteredContentProvider, IHierarchicContentProvider, IGraphicalContentProvider, ISelectionChangedListener, ICommitListener {
+public class EMFGraphicalContentProvider extends EncapsulatedContentProvider implements ISelectionChangedListener {
-
- private static final String DIALOG_SETTINGS = GraphicalModelExplorerBasedContentProvider.class.getName();
-
- /** The not wanted. */
- protected ArrayList<Object> metaClassNotWantedList = new ArrayList<Object>();
-
- /** The wanted. */
- protected Object metaClassWanted = null;
-
- /**
- * a bridge to find the semantic element behind an object of the model explorer
- */
- protected SemanticFromModelExplorer brige = new SemanticFromModelExplorer();
+ private static final String DIALOG_SETTINGS = EMFGraphicalContentProvider.class.getName();
protected String historyId;
- /**
- * The current metaclass viewer filter
- */
- protected ViewerFilter currentMetaclassViewerFilter;
+ //Unused (yet)
+ //TODO : Add a preference or a collapsible composite for this feature (Or both)
+ //
+ // /**
+ // * The current metaclass viewer filter
+ // */
+ // protected ViewerFilter currentMetaclassViewerFilter;
protected ViewerFilter patternFilter;
@@ -97,6 +85,8 @@ public class GraphicalModelExplorerBasedContentProvider extends ModelContentProv
protected Object selectedObject;
+ protected StructuredViewer viewer;
+
private static final int HISTORY_MAX_SIZE = 5;
private String currentFilterPattern = ""; //$NON-NLS-1$
@@ -107,88 +97,16 @@ public class GraphicalModelExplorerBasedContentProvider extends ModelContentProv
/**
* the constructor
- *
- * @param semanticRoot
- * the root that we want to display at top
*/
- public GraphicalModelExplorerBasedContentProvider(EObject semanticRoot, String historyId) {
- super(semanticRoot);
+ public EMFGraphicalContentProvider(IStructuredContentProvider semanticProvider, String historyId) {
+ super(semanticProvider);
this.historyId = historyId;
}
/**
* {@inheritDoc}
*/
- public void setMetaClassNotWanted(List<Object> metaClassNotWanted) {
- metaClassNotWantedList.clear();
- metaClassNotWantedList.addAll(metaClassNotWanted);
- }
-
- /**
- * {@inheritDoc}
- */
- public void setMetaClassWanted(Object metaClassWanted) {
- this.metaClassWanted = metaClassWanted;
- }
-
-
- /**
- * get Wanted metaclasse
- *
- * @return Eclass that reprensent the wanted metaclass
- */
- public Object getMetaClassWanted() {
- return metaClassWanted;
- }
-
- public boolean isValidValue(Object element) {
-
- //to filter, test if the wanted metaclass is not null
- if(metaClassWanted != null) {
- // get the semantic object form the element
- EObject semanticObject = null;
-
- if(element instanceof IAdaptable) {
- semanticObject = (EObject)brige.getSemanticElement(element);
- }
- if(element instanceof EObject) {
- semanticObject = (EObject)element;
- }
- //return false for Ereference
- if(element instanceof EReference || semanticObject instanceof EReference) {
- return false;
- }
- //the semantic object is not null
- if(semanticObject != null) {
- //test if this is an Eclass
- if(metaClassWanted instanceof EClass) {
- //test if the semanticobject is instance of metaclassWanted
- // and not an instance of metaclassNotWanted
- if(((EClass)metaClassWanted).isSuperTypeOf(semanticObject.eClass())) {
- if(metaClassNotWantedList.size() > 0) {
- Iterator<Object> iternotwanted = metaClassNotWantedList.iterator();
- while(iternotwanted.hasNext()) {
- Object notWanted = iternotwanted.next();
- if(notWanted instanceof EClass) {
- if(((EClass)notWanted).isSuperTypeOf(semanticObject.eClass())) {
- return false;
- }
- }
- }
- }
- return true;
- }
- }
- return false;
- }
-
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
+ @Override
public void createBefore(Composite parent) {
createPatternFilter(parent);
}
@@ -210,7 +128,7 @@ public class GraphicalModelExplorerBasedContentProvider extends ModelContentProv
if(!("".equals(filterPattern) || currentFilterPattern.equals(filterPattern))) {
Object firstMatch = getFirstMatchingElement(null);
if(firstMatch != null) {
- viewer.reveal(firstMatch);
+ revealSemanticElement(Collections.singletonList(firstMatch));
}
currentFilterPattern = filterPattern;
}
@@ -266,6 +184,7 @@ public class GraphicalModelExplorerBasedContentProvider extends ModelContentProv
/**
* {@inheritDoc}
*/
+ @Override
public void createAfter(Composite parent) {
parent.setLayout(new GridLayout(1, false));
// createMetaclassFilter(parent); //Disabled
@@ -306,19 +225,7 @@ public class GraphicalModelExplorerBasedContentProvider extends ModelContentProv
Object selectedObject = selection.getFirstElement();
if(selectedObject instanceof EObject) {
EObject eObject = ((EObject)selectedObject);
- // select the element in the model explorer
- Object containerValue = getContainerValue(eObject);
- if(containerValue == null) {
- viewer.setSelection(StructuredSelection.EMPTY);
- } else {
- viewer.setSelection(new StructuredSelection(containerValue), true);
- }
-
- // update current selection
- // ModelElementItem item = (ModelElementItem)((IStructuredSelection)viewer.getSelection()).getFirstElement();
- // if(item != null) {
- // setCurrentValueItem(item);
- // }
+ revealSemanticElement(Collections.singletonList(eObject));
}
}
});
@@ -510,16 +417,20 @@ public class GraphicalModelExplorerBasedContentProvider extends ModelContentProv
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- super.inputChanged(viewer, oldInput, newInput);
- if(this.viewer != null && newInput != null && this.viewer.getControl() != null && !this.viewer.getControl().isDisposed()) {
- this.viewer.setFilters(new ViewerFilter[]{ new HierarchicViewerFilter(this) });
- this.viewer.addSelectionChangedListener(this);
+ encapsulated.inputChanged(viewer, oldInput, newInput);
+
+ if(viewer instanceof StructuredViewer) {
+ this.viewer = (StructuredViewer)viewer;
+ if(newInput != null && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
+ this.viewer.addSelectionChangedListener(this);
+ }
+ } else {
+ this.viewer = null;
}
}
public void selectionChanged(SelectionChangedEvent event) {
selectedObject = ((IStructuredSelection)event.getSelection()).getFirstElement();
- selectedObject = getAdaptedValue(selectedObject);
updateDetailLabel();
}
@@ -544,15 +455,17 @@ public class GraphicalModelExplorerBasedContentProvider extends ModelContentProv
detailLabel.getParent().getParent().layout();
}
+ @Override
public void commit(AbstractEditor editor) {
- if(selectedObject instanceof EObject) {
- storeDialog(getDialogSettings(), (EObject)selectedObject);
+ Object semanticElement = getAdaptedValue(selectedObject);
+ if(semanticElement instanceof EObject) {
+ storeDialog(getDialogSettings(), (EObject)semanticElement);
}
}
@Override
public void dispose() {
- viewer.removeSelectionChangedListener(this);
super.dispose();
+ viewer.removeSelectionChangedListener(this);
}
}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/HierarchicViewerFilter.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/HierarchicViewerFilter.java
deleted file mode 100644
index a4c407fb4c9..00000000000
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/HierarchicViewerFilter.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Adaptation to AbstractTreeFilter
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.emf.providers;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.facet.infra.browser.uicore.internal.model.BigListItem;
-import org.eclipse.emf.facet.infra.facet.FacetReference;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.papyrus.infra.widgets.providers.AbstractTreeFilter;
-import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider;
-
-/**
- *
- * This a View Filter that use a IHierarchicContentProvider
- *
- */
-public class HierarchicViewerFilter extends AbstractTreeFilter {
-
- /**
- * a constructor
- * @param contentProvider that contains isValidValue() in order to know element to filter
- */
- public HierarchicViewerFilter(IHierarchicContentProvider contentProvider) {
- super();
- this.contentProvider = contentProvider;
- }
-
- /**
- * the content provider
- */
- protected IHierarchicContentProvider contentProvider;
-
- @Override
- public boolean hasOneVisibleChild(Viewer viewer, Object element, ITreeContentProvider contentProvider, Set<Object> visitedElements) {
- //TODO : divide this method
- if(useCache && visibleChild.containsKey(element)) {
- return visibleChild.get(element);
- }
-
- boolean result = false;
-
- if(visitedElements.add(element)) {
- SemanticFromModelExplorer bridge = new SemanticFromModelExplorer();
-
- EObject semanticObject = null;
- if(element instanceof IAdaptable) {
- semanticObject = (EObject)bridge.getSemanticElement(element);
- }
- if(element instanceof EObject) {
- semanticObject = (EObject)element;
- }
-
- if(element instanceof BigListItem) {
- Object[] children = contentProvider.getChildren(element);
- for(Object child : children) {
- if(isVisible(viewer, element, child) || hasOneVisibleChild(viewer, child, contentProvider, visitedElements)) {
- result = true;
- }
- }
- } else if(semanticObject != null) {//it contains nothing
- if(semanticObject instanceof EReference) {
- //Do not display references that are not containment kind
- EReference eReference = (EReference)semanticObject;
- if(isValidReference(eReference)) {
- //this an ereference maybe it references something that is interesting
- Object[] children = contentProvider.getChildren(element);
- for(Object child : children) {
- if(isVisible(viewer, element, child) || hasOneVisibleChild(viewer, child, contentProvider, visitedElements)) {
- result = true;
- }
- }
- }
- }
-
- if(!result) {
-
- //it contains something so we have to test children before
- Iterator<EObject> iter = semanticObject.eAllContents();
- while(iter.hasNext()) {
- EObject subEObject = iter.next();
- if(isVisible(viewer, semanticObject, subEObject) || hasOneVisibleChild(viewer, subEObject, contentProvider, visitedElements)) {
- result = true;
- break;
- }
- }
-
- if(!result) {
- for(EReference eReference : getReferencesToBrowse(semanticObject)) {
- Object values = semanticObject.eGet(eReference);
- if(values instanceof EList) {
- for(Object value : (EList<?>)values) {
- if(isVisible(viewer, semanticObject, value) || hasOneVisibleChild(viewer, value, contentProvider, visitedElements)) {
- result = true;
- break;
- }
- }
- } else if(isVisible(viewer, semanticObject, values) || hasOneVisibleChild(viewer, values, contentProvider, visitedElements)) {
- result = true;
- }
- }
- }
- }
- }
-
- }
-
- if(useCache) {
- visibleChild.put(element, result);
- }
-
- return result;
- }
-
- protected Set<EReference> getReferencesToBrowse(EObject element) {
- return new HashSet<EReference>();
- }
-
- protected boolean isValidReference(EReference eReference) {
- return eReference.isContainment() || eReference instanceof FacetReference || getReferencesToBrowse(null).contains(eReference);
- }
-
- @Override
- public boolean isVisible(Viewer viewer, Object parentElement, Object element) {
- return contentProvider.isValidValue(element);
- }
-
-}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/IMetaclassFilteredContentProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/IMetaclassFilteredContentProvider.java
deleted file mode 100644
index 00f3db2289c..00000000000
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/IMetaclassFilteredContentProvider.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.emf.providers;
-
-import java.util.List;
-
-import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider;
-
-
-/**
- * this is a content provider on which we can filter wanted meta-classes
- * So the method is valid has to take in account the list of metaclasses
- */
-public interface IMetaclassFilteredContentProvider extends
-IHierarchicContentProvider {
- /**
- * set the list of meta-classes that we do not want to display.
- * It could be interesting to look for a kind of metaclasses without sub metaclasses.
- * @param metaClassNotWanted list of metaclasses that are not wanted
- *
- */
- public void setMetaClassNotWanted(List<Object> metaClassNotWanted);
- /**
- * a the kind of metaclasses wanted
- * @param metaClassWanted
- */
- public void setMetaClassWanted(Object metaClassWanted);
-}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/SemanticFromModelExplorer.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/SemanticFromModelExplorer.java
index cde77467d83..b98efd6feab 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/SemanticFromModelExplorer.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/SemanticFromModelExplorer.java
@@ -20,25 +20,28 @@ import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.papyrus.infra.core.IElementWithSemantic;
/**
- * This class is used to obtain the semantic element for element of the model explorer
+ * This class is used to obtain the semantic element for element of the model explorer
+ *
+ * @deprecated See EMFHelper#getEObject(Object)
*/
+@Deprecated
public class SemanticFromModelExplorer implements IElementWithSemantic {
/**
* {@inheritDoc}
*/
public Object getSemanticElement(Object wrapper) {
- if( wrapper instanceof IAdaptable){
- Object obj= ((IAdaptable)wrapper).getAdapter(EObject.class);
- if(obj==null){
- obj= ((IAdaptable)wrapper).getAdapter(EReference.class);
+ if(wrapper instanceof IAdaptable) {
+ Object obj = ((IAdaptable)wrapper).getAdapter(EObject.class);
+ if(obj == null) {
+ obj = ((IAdaptable)wrapper).getAdapter(EReference.class);
}
- if(obj!=null){
+ if(obj != null) {
return obj;
}
}
-
- if( wrapper instanceof Diagram){
+
+ if(wrapper instanceof Diagram) {
return wrapper;
}
return null;
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/ContainmentBrowseStrategy.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/ContainmentBrowseStrategy.java
new file mode 100644
index 00000000000..0f6d94d3894
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/ContainmentBrowseStrategy.java
@@ -0,0 +1,293 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.providers.strategy;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.facet.infra.facet.FacetReference;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.widgets.providers.IAdaptableContentProvider;
+import org.eclipse.papyrus.infra.widgets.strategy.ProviderBasedBrowseStrategy;
+import org.eclipse.swt.widgets.TreeItem;
+
+/**
+ * A TreeBrowseStrategy based on the semantic model.
+ * It can also retrieve a semantic element in a MoDisco tree, when the tree structure is close
+ * to the semantic one (With optional EReferences).
+ *
+ * Container1::Container2::EObject1 can be retrieved in a Tree representing
+ * Container1::(Reference1)::Container2::(Reference2)::EObject1
+ *
+ * @author Camille Letavernier
+ */
+public class ContainmentBrowseStrategy extends ProviderBasedBrowseStrategy {
+
+ protected IAdaptableContentProvider adaptableProvider;
+
+ protected TreeViewer viewer;
+
+ public ContainmentBrowseStrategy(ITreeContentProvider provider) {
+ if(!(provider instanceof IAdaptableContentProvider)) {
+ throw new IllegalArgumentException("The provider must be an IAdaptableContentProvider");
+ }
+
+ setProvider(provider);
+ this.adaptableProvider = (IAdaptableContentProvider)super.provider;
+ }
+
+ //
+ // Elements filtering
+ //
+
+ @Override
+ protected boolean browseElement(Object containerElement) {
+ Object semanticElement = adaptableProvider.getAdaptedValue(containerElement);
+
+ if(semanticElement instanceof EReference && !(semanticElement instanceof FacetReference)) {
+ //Only browse Containment references and Facet references
+ return ((EReference)semanticElement).isContainment();
+ }
+
+ return true;
+ }
+
+ //
+ // Elements search
+ //
+
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public TreePath findPath(Object semanticElement, Object[] rootElements) {
+ // List<Object> semanticPath = new LinkedList<Object>();
+ // findSemanticPath(semanticElement, semanticPath);
+ // return searchPath(semanticPath, rootElements);
+ // }
+
+ // /**
+ // * Fills the semantic path to the given element
+ // *
+ // * @param element
+ // * The element to retrieve
+ // * @param currentPath
+ // * The path to fill (in-out)
+ // */
+ // protected void findSemanticPath(Object element, List<Object> currentPath) {
+ // if(element != null && element instanceof EObject) {
+ // findSemanticPath(getSemanticParent(element), currentPath);
+ // currentPath.add(element);
+ // }
+ // }
+ //
+ // protected Object getSemanticParent(Object element) {
+ // if(element instanceof EObject) {
+ // return ((EObject)element).eContainer();
+ // }
+ // return null;
+ // }
+ //
+ // /**
+ // * Retrieve the graphical TreePath from the given semantic path
+ // *
+ // * @param semanticPath
+ // * @return
+ // */
+ // protected TreePath searchPath(List<Object> semanticPath, Object input) {
+ // List<Object> graphicalPath = new LinkedList<Object>();
+ // Object[] graphicalRootObjects = (Object[])input;
+ // if(!searchPath(semanticPath, graphicalPath, graphicalRootObjects)) {
+ // //Object not found
+ // graphicalPath.clear();
+ // }
+ //
+ // return new TreePath(graphicalPath.toArray());
+ // }
+ //
+ // protected boolean searchPath(List<Object> semanticPath, List<Object> graphicalPath, Object[] graphicalRootObjects) {
+ // if(semanticPath.isEmpty()) {
+ // return true;
+ // }
+ //
+ // if(graphicalRootObjects == null) {
+ // return false;
+ // }
+ //
+ // Object currentElement = semanticPath.get(0);
+ // for(Object graphicalElement : graphicalRootObjects) {
+ // Object semanticValue = adaptableProvider.getAdaptedValue(graphicalElement);
+ //
+ // //Specific case for containment EReference
+ // if(semanticValue instanceof EReference) {
+ // EReference referenceToBrowse = (EReference)semanticValue;
+ // if(referenceToBrowse.isContainment()) {
+ // graphicalPath.add(graphicalElement);
+ //
+ // if(searchPath(semanticPath, graphicalPath, provider.getChildren(graphicalElement))) {
+ // //The element has been found
+ // return true;
+ // }
+ //
+ // //The element has not been found ; we revert the modifications
+ // graphicalPath.remove(graphicalElement);
+ // }
+ // }
+ //
+ // if(semanticValue == currentElement) {
+ // semanticPath.remove(0);
+ // graphicalPath.add(graphicalElement);
+ // if(searchPath(semanticPath, graphicalPath, provider.getChildren(graphicalElement))) {
+ // return true;
+ // }
+ // }
+ // }
+ //
+ // return false;
+ // }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if(viewer instanceof TreeViewer) {
+ this.viewer = (TreeViewer)viewer;
+ }
+ super.inputChanged(viewer, oldInput, newInput);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void revealSemanticElement(List<?> elementList) {
+ //for each element we reveal it
+ Iterator<?> elementListIterator = elementList.iterator();
+ ArrayList<Object> treeElementToSelect = new ArrayList<Object>();
+ while(elementListIterator.hasNext()) {
+ Object currentElement = elementListIterator.next();
+ //test if the type is an EObject
+ if(currentElement instanceof EObject) {
+ EObject currentEObject = (EObject)currentElement;
+ //the content provider exist?
+ if(provider != null) {
+ //need the root in order to find all element in the tree
+ Object root = provider.getElements(null)[0];
+ //look for the path in order to access to this element
+ List<Object> path = searchPath(currentEObject, Arrays.asList(provider.getElements(root)));
+ if(path.size() > 0) {
+ //expand in the common viewer the path
+ expandItems(path, viewer.getTree().getItems());
+ treeElementToSelect.add(path.get(path.size() - 1));
+ }
+ }
+ }
+ selectReveal(new StructuredSelection(treeElementToSelect));
+ }
+ }
+
+ public void expandItems(List<Object> treeElementList, TreeItem[] list) {
+ //the treeElement has more tan one element
+ if(treeElementList.size() > 0) {
+ for(int i = 0; i < list.length; i++) {
+ if(list[i].getData() != null && list[i].getData().equals(treeElementList.get(0))) {
+ if(treeElementList.size() > 1) {//Do no expand the last
+ Object[] toexpand = { treeElementList.get(0) };
+ viewer.setExpandedElements(toexpand);
+ }
+ ArrayList<Object> tmpList = new ArrayList<Object>();
+ tmpList.addAll(treeElementList);
+ tmpList.remove(tmpList.get(0));
+ expandItems(tmpList, list[i].getItems());
+ }
+ }
+ }
+ }
+
+ public void selectReveal(ISelection selection) {
+ if(viewer != null) {
+ viewer.setSelection(selection, true);
+ }
+ }
+
+
+ /**
+ * look for the path the list of element (comes from the content provider) to go the eObject
+ *
+ * @param eobject
+ * that we look for.
+ * @param objects
+ * a list of elements where eobject can be wrapped.
+ * @return the list of modelElementItem ( from the root to the element that wrap the eobject)
+ */
+ protected List<Object> searchPath(EObject eobject, List<Object> objects) {
+ List<Object> path = new ArrayList<Object>();
+
+ for(Object o : objects) {
+ // Search matches in this level
+ if(!(o instanceof Diagram) && o instanceof IAdaptable) {
+ if(eobject.equals(((IAdaptable)o).getAdapter(EObject.class))) {
+ path.add(o);
+ return path;
+ }
+ }
+
+ // Find childs only for feature container
+ for(int i = 0; i < provider.getChildren(o).length; i++) {
+ Object treeItem = provider.getChildren(o)[i];
+
+ List<Object> tmppath = new ArrayList<Object>();
+ Object element = EMFHelper.getEObject(treeItem);
+ if(element != null) {
+ if(element instanceof EReference) {
+ if(((EReference)element).isContainment() && (!((EReference)element).isDerived())) {
+ List<Object> childs = new ArrayList<Object>();
+ childs.add(treeItem);
+ tmppath = searchPath(eobject, childs);
+ }
+ }
+
+ else {
+ if(element instanceof EObject) {
+ List<Object> childs = new ArrayList<Object>();
+ childs.add(treeItem);
+ tmppath = searchPath(eobject, childs);
+ }
+ }
+ }
+
+ // if tmppath contains the wrapped eobject we have find the good path
+ if(tmppath.size() > 0) {
+ if(tmppath.get(tmppath.size() - 1) instanceof IAdaptable) {
+ if(eobject.equals(((IAdaptable)(tmppath.get(tmppath.size() - 1))).getAdapter(EObject.class))) {
+ path.add(o);
+ path.addAll(tmppath);
+ return path;
+ }
+ }
+ }
+ }
+ }
+
+ return new ArrayList<Object>();
+ }
+
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/SemanticEMFContentProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/SemanticEMFContentProvider.java
new file mode 100644
index 00000000000..d02db422d39
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/SemanticEMFContentProvider.java
@@ -0,0 +1,186 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.providers.strategy;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.emf.common.notify.AdapterFactory;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.facet.infra.browser.uicore.CustomizableModelContentProvider;
+import org.eclipse.papyrus.infra.emf.Activator;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.widgets.providers.IAdaptableContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
+
+
+public class SemanticEMFContentProvider extends CustomizableModelContentProvider implements IAdaptableContentProvider, IHierarchicContentProvider, IStaticContentProvider {
+
+ protected EObject[] roots;
+
+ protected List<?> metaclasses = new LinkedList<Object>();
+
+ protected List<?> notWantedMetaclasses = new LinkedList<Object>();
+
+ protected EObject eObject;
+
+ protected EStructuralFeature feature;
+
+ protected AdapterFactory factory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+
+ public SemanticEMFContentProvider(EObject editedEObject, EStructuralFeature feature, EObject[] roots) {
+ super(Activator.getDefault().getCustomizationManager());
+
+ this.roots = roots;
+
+ configureMetaclasses(feature);
+
+ this.eObject = editedEObject;
+ this.feature = feature;
+ }
+
+ protected void configureMetaclasses(EStructuralFeature feature) {
+ if(feature != null) {
+ setWantedMetaclasses(Collections.singletonList(feature.getEType()));
+ }
+ }
+
+ public SemanticEMFContentProvider(EObject editedEObject, EStructuralFeature feature) {
+ this(editedEObject, feature, findRoots(editedEObject));
+ }
+
+ public SemanticEMFContentProvider(EObject[] roots) {
+ this(null, null, roots);
+ }
+
+ public SemanticEMFContentProvider(ResourceSet root) {
+ this(null, null, root);
+ }
+
+ public SemanticEMFContentProvider(EObject editedEObject, EStructuralFeature feature, ResourceSet root) {
+ this(editedEObject, feature, getRoots(root));
+ }
+
+ protected static EObject[] getRoots(ResourceSet root) {
+ List<EObject> roots = new LinkedList<EObject>();
+ for(Resource resource : root.getResources()) {
+ roots.addAll(resource.getContents());
+ }
+ return roots.toArray(new EObject[roots.size()]);
+ }
+
+ protected static EObject[] findRoots(EObject source) {
+
+ //The EObject is not contained in a resource : we return the top-level EObject
+ if(source.eResource() == null) {
+ while(source.eContainer() != null) {
+ source = source.eContainer();
+ }
+
+ return new EObject[]{ source };
+ }
+
+ //The resource is not contained in a resource set : we return the resource's contents
+ if(source.eResource().getResourceSet() == null) {
+ return source.eResource().getContents().toArray(new EObject[0]);
+ }
+
+ //We have a full resourceSet : we return its contents
+ return getRoots(source.eResource().getResourceSet());
+ }
+
+ @Override
+ public EObject[] getRootElements(final Object inputElement) {
+ return roots;
+ }
+
+ public Object getAdaptedValue(Object containerElement) {
+ return EMFHelper.getEObject(containerElement);
+ }
+
+ @Override
+ public boolean hasChildren(Object parent) {
+ //May be expensive
+ return getChildren(parent).length > 0;
+ }
+
+ public boolean isValidValue(Object containerElement) {
+ // get the semantic object form the element
+ Object semanticObject = getAdaptedValue(containerElement);
+
+ //return false for EReference and non-semantic objects
+ if(semanticObject instanceof EReference || semanticObject == null) {
+ return false;
+ }
+
+ //Tests whether the element is compatible with at least one metaclass
+ if(metaclasses != null && !metaclasses.isEmpty()) {
+ boolean compatible = false;
+
+ for(Object metaclass : metaclasses) {
+ if(isCompatibleMetaclass(containerElement, metaclass)) {
+ compatible = true;
+ break;
+ }
+ }
+
+ if(!compatible) {
+ return false;
+ }
+ }
+
+ //If the element is compatible with at least one metaclass from notWanted, then it is not valid
+ for(Object metaclass : notWantedMetaclasses) {
+ if(isCompatibleMetaclass(containerElement, metaclass)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ protected boolean isCompatibleMetaclass(Object containerElement, Object metaclass) {
+ if(metaclass instanceof EClassifier) {
+ Object semanticElement = getAdaptedValue(containerElement);
+ return ((EClassifier)metaclass).isInstance(semanticElement);
+ }
+ return false;
+ }
+
+ public void setWantedMetaclasses(List<?> metaclasses) {
+ this.metaclasses = metaclasses;
+ }
+
+ public void setNotWantedMetaclasses(List<?> notWantedMetaclasses) {
+ this.notWantedMetaclasses = notWantedMetaclasses;
+ }
+
+ public Object[] getElements() {
+ return super.getElements(null);
+ }
+
+ public List<?> getWantedMetaclasses() {
+ return metaclasses;
+ }
+
+ public List<?> getNotWantedMetaclasses() {
+ return notWantedMetaclasses;
+ }
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/StrategyBasedContentProvider.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/StrategyBasedContentProvider.java
new file mode 100644
index 00000000000..12d2f204e45
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/providers/strategy/StrategyBasedContentProvider.java
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.providers.strategy;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider;
+import org.eclipse.papyrus.infra.widgets.strategy.TreeBrowseStrategy;
+
+
+public class StrategyBasedContentProvider extends EncapsulatedContentProvider {
+
+ protected TreeBrowseStrategy browseStrategy;
+
+ protected TreeBrowseStrategy revealStrategy;
+
+ protected StructuredViewer viewer;
+
+ public StrategyBasedContentProvider(TreeBrowseStrategy browseStrategy, TreeBrowseStrategy revealStrategy) {
+ setRevealStrategy(revealStrategy);
+ setBrowseStrategy(browseStrategy);
+ }
+
+ public void setBrowseStrategy(TreeBrowseStrategy strategy) {
+ if(strategy != null) {
+ browseStrategy = strategy;
+ encapsulated = browseStrategy;
+ }
+ }
+
+ public void setRevealStrategy(TreeBrowseStrategy strategy) {
+ if(strategy != null) {
+ revealStrategy = strategy;
+ }
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ browseStrategy = null;
+ revealStrategy = null;
+ }
+
+ @Override
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ super.inputChanged(viewer, oldInput, newInput);
+ if(viewer instanceof StructuredViewer) {
+ this.viewer = (StructuredViewer)viewer;
+ } else {
+ this.viewer = null;
+ }
+
+ revealStrategy.inputChanged(viewer, oldInput, newInput);
+ browseStrategy.inputChanged(viewer, oldInput, newInput);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * Reveals and selects the given semantic elements
+ */
+ @Override
+ public void revealSemanticElement(List<?> semanticElementsList) {
+ revealStrategy.revealSemanticElement(semanticElementsList);
+ // List<Object> containerElements = new LinkedList<Object>();
+ //
+ // for(Object semanticElement : semanticElementsList) {
+ // TreePath path = revealStrategy.findPath(semanticElement, getElements(viewer.getInput()));
+ // if(path.getSegmentCount() > 0) {
+ // viewer.reveal(path);
+ // containerElements.add(path.getLastSegment());
+ // }
+ // }
+ //
+ // viewer.setSelection(new StructuredSelection(containerElements));
+ }
+
+ @Override
+ public TreeBrowseStrategy getBrowseStrategy() {
+ return browseStrategy;
+ }
+
+ @Override
+ public TreeBrowseStrategy getRevealStrategy() {
+ return revealStrategy;
+ }
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java
index f33928e13cc..3c27da2b7ec 100644
--- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java
@@ -23,6 +23,7 @@ import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EEnum;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
+import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
@@ -38,6 +39,7 @@ import org.eclipse.papyrus.infra.emf.Activator;
*
* @author Camille Letavernier
*/
+//TODO : Check implementations. Most of them are old and don't always match the specification
public class EMFHelper {
/**
@@ -146,24 +148,51 @@ public class EMFHelper {
if(source instanceof EObject) {
return (EObject)source;
} else if(source instanceof IAdaptable) {
- return (EObject)((IAdaptable)source).getAdapter(EObject.class);
+ EObject eObject = (EObject)((IAdaptable)source).getAdapter(EObject.class);
+ if(eObject == null) { //EMF Facet
+ eObject = (EObject)((IAdaptable)source).getAdapter(EReference.class);
+ }
+ return eObject;
}
return null;
}
/**
- * Return the eClass' qualified name. The qualified name is obtained by the concatenation
+ * Retrieve the EditingDomain for the given source object. The object is first
+ * resolved to an EObject through #getEObject when possible.
+ *
+ * @param source
+ * @return
+ * The source object's editing domain, or null if it couldn't be found
+ */
+ public static EditingDomain resolveEditingDomain(Object source) {
+ return resolveEditingDomain(getEObject(source));
+ }
+
+ /**
+ * Retrieve the EditingDomain for the given source EObject
+ *
+ * @param source
+ * @return
+ * The source eObject's editing domain, or null if it couldn't be found
+ */
+ public static EditingDomain resolveEditingDomain(EObject source) {
+ return AdapterFactoryEditingDomain.getEditingDomainFor(source);
+ }
+
+ /**
+ * Return the eClassifier' qualified name. The qualified name is obtained by the concatenation
* of its package hierarchy with the class name, separated by the given separator
*
- * @param eClass
+ * @param eClassifier
* @param separator
* The separator used between each package name
* @return
- * The EClass' qualified name
+ * The EClassifier' qualified name
*/
- public static String getQualifiedName(EClass eClass, String separator) {
- return getQualifiedName(eClass.getEPackage(), separator) + separator + eClass.getName();
+ public static String getQualifiedName(EClassifier eClassifier, String separator) {
+ return getQualifiedName(eClassifier.getEPackage(), separator) + separator + eClassifier.getName();
}
/**
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/HistoryUtil.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/HistoryUtil.java
new file mode 100644
index 00000000000..50d10a12b9f
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/HistoryUtil.java
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.utils;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+
+
+public class HistoryUtil {
+
+ /**
+ * Returns a String identifying the History of selected values for the given object/feature
+ *
+ * @param editedObject
+ * @param feature
+ * @return
+ */
+ public static String getHistoryID(EObject editedObject, EStructuralFeature feature) {
+ return getHistoryID(editedObject, feature, "");
+ }
+
+ /**
+ * Returns a String identifying the History of selected values for the given object/feature,
+ * and prepends the given prefix
+ *
+ * @param editedObject
+ * @param feature
+ * @return
+ */
+ public static String getHistoryID(EObject editedObject, EStructuralFeature feature, String prefix) {
+ // return String.format("history_%s:%s:%s", feature.getEType().getEPackage().getName(), feature.getEType().getName(), feature.getName()); //$NON-NLS-1$
+ if(editedObject.eResource() == null) {
+ return String.format("history_%s_%s:%s", prefix, EMFHelper.getQualifiedName(feature.getEType(), ":"), feature.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ return String.format("history_%s_%s:%s:%s", prefix, editedObject.eResource().getURI(), EMFHelper.getQualifiedName(feature.getEType(), ":"), feature.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ProviderHelper.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ProviderHelper.java
new file mode 100644
index 00000000000..24d5b1865dc
--- /dev/null
+++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ProviderHelper.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.emf.utils;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+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.widgets.strategy.ProviderBasedBrowseStrategy;
+import org.eclipse.papyrus.infra.widgets.strategy.TreeBrowseStrategy;
+
+
+public class ProviderHelper {
+
+ /**
+ * Encapsulates the given content provider in a higher-level content provider
+ * The returned provider uses two different strategies to display and search
+ * elements, and adds a pattern filter and an History
+ *
+ * @param provider
+ * The ContentProvider to encapsulate
+ * @return
+ */
+ public static EMFGraphicalContentProvider encapsulateProvider(ITreeContentProvider provider, String historyId) {
+ TreeBrowseStrategy browseStrategy = new ProviderBasedBrowseStrategy(provider);
+ TreeBrowseStrategy revealStrategy = new ContainmentBrowseStrategy(provider);
+ IStructuredContentProvider strategyProvider = new StrategyBasedContentProvider(browseStrategy, revealStrategy);
+ EMFGraphicalContentProvider graphicalProvider = new EMFGraphicalContentProvider(strategyProvider, historyId);
+
+ return graphicalProvider;
+ }
+
+ /**
+ * Encapsulates the given content provider in a higher-level content provider
+ * The returned provider uses two different strategies to display and search
+ * elements, and adds a pattern filter and an History
+ *
+ * @param provider
+ * The ContentProvider to encapsulate
+ * @return
+ */
+ public static EMFGraphicalContentProvider encapsulateProvider(ITreeContentProvider provider, EObject editedEObject, EStructuralFeature feature) {
+ return encapsulateProvider(provider, HistoryUtil.getHistoryID(editedEObject, feature));
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF
index 4328e67e529..4632849b758 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.properties/META-INF/MANIFEST.MF
@@ -11,7 +11,6 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.emf.databinding;bundle-version="1.2.0",
org.eclipse.core.databinding.property;bundle-version="1.4.0",
org.eclipse.core.databinding.beans;bundle-version="1.2.100",
- org.eclipse.papyrus.uml.properties;bundle-version="0.9.0",
org.eclipse.papyrus.infra.core.log;bundle-version="0.9.0",
org.eclipse.emf.edit.ui;bundle-version="2.7.0",
org.eclipse.papyrus.infra.core;bundle-version="0.9.0",
@@ -27,4 +26,3 @@ Bundle-ManifestVersion: 2
Bundle-Activator: org.eclipse.papyrus.infra.gmfdiag.properties.Activator
Bundle-SymbolicName: org.eclipse.papyrus.infra.gmfdiag.properties;singleton:=true
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/.project b/plugins/infra/org.eclipse.papyrus.infra.constraints/.project
index dd9eb68f4f8..68021fd18e9 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/.project
+++ b/plugins/infra/org.eclipse.papyrus.infra.constraints/.project
@@ -21,13 +21,13 @@
</arguments>
</buildCommand>
<buildCommand>
- <name>org.eclipse.gmt.modisco.common.core.builder</name>
+ <name>org.eclipse.emf.facet.common.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
- <nature>org.eclipse.gmt.modisco.common.ProjectNature</nature>
+ <nature>org.eclipse.emf.facet.common.ProjectNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
diff --git a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/providers/ConstraintTypeContentProvider.java b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/providers/ConstraintTypeContentProvider.java
index ca67aa621da..b350660604a 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/providers/ConstraintTypeContentProvider.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.constraints/src/org/eclipse/papyrus/infra/constraints/providers/ConstraintTypeContentProvider.java
@@ -14,4 +14,8 @@ public class ConstraintTypeContentProvider extends AbstractFilteredContentProvid
public Object[] getElements() {
return ConstraintsManager.instance.getConstraintTypes().toArray();
}
+
+ public Object[] getElements(Object inputElement) {
+ return getElements();
+ }
}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF b/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
index 17d7d58cccb..7fa28a51c1c 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/META-INF/MANIFEST.MF
@@ -8,8 +8,7 @@ Bundle-Vendor: Eclipse Modeling Project
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.papyrus.infra.core.log;bundle-version="0.9.0",
- org.eclipse.core.databinding;bundle-version="1.4.1",
- org.eclipse.papyrus.infra.widgets;bundle-version="0.9.0"
+ org.eclipse.core.databinding;bundle-version="1.4.1"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.papyrus.infra.tools.databinding,
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/AggregatedObservable.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/databinding/AggregatedObservable.java
index ecb8fc9f30a..ce180145b78 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/AggregatedObservable.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/databinding/AggregatedObservable.java
@@ -9,7 +9,7 @@
* Contributors:
* Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
*****************************************************************************/
-package org.eclipse.papyrus.infra.widgets.databinding;
+package org.eclipse.papyrus.infra.tools.databinding;
import org.eclipse.core.databinding.observable.IObservable;
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/databinding/MultipleObservableValue.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/databinding/MultipleObservableValue.java
index 28198f51516..87546fa9db8 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/databinding/MultipleObservableValue.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/databinding/MultipleObservableValue.java
@@ -21,7 +21,6 @@ import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.ValueDiff;
-import org.eclipse.papyrus.infra.widgets.databinding.AggregatedObservable;
/**
* MultipleObservableValue is used to map a single element
diff --git a/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/ListHelper.java b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/ListHelper.java
new file mode 100644
index 00000000000..196a7e346bf
--- /dev/null
+++ b/plugins/infra/org.eclipse.papyrus.infra.tools/src/org/eclipse/papyrus/infra/tools/util/ListHelper.java
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.tools.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ListHelper {
+
+ /**
+ * Converts an array to a List
+ *
+ * This method is similar to Arrays.asList, except that it returns
+ * a writeable list
+ *
+ * @param array
+ * The array to transform into a List
+ * @return
+ * A List containing the same elements as the array
+ */
+ public static <T> List<T> asList(T[] array) {
+ if(array == null) {
+ return new ArrayList<T>();
+ }
+
+ List<T> result = new ArrayList<T>(array.length);
+ for(T t : array) {
+ result.add(t);
+ }
+ return result;
+ }
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF
index cfafcbc515f..15d86bf87bf 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/META-INF/MANIFEST.MF
@@ -8,13 +8,16 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.100",
org.eclipse.core.resources;bundle-version="3.7.100",
org.eclipse.ui.ide;bundle-version="3.7.0",
- com.ibm.icu;bundle-version="4.4.2"
+ com.ibm.icu;bundle-version="4.4.2",
+ org.eclipse.papyrus.infra.core;bundle-version="0.9.0",
+ org.eclipse.papyrus.infra.tools;bundle-version="0.9.0"
Export-Package: org.eclipse.papyrus.infra.widgets,
org.eclipse.papyrus.infra.widgets.creation,
org.eclipse.papyrus.infra.widgets.databinding,
org.eclipse.papyrus.infra.widgets.editors,
org.eclipse.papyrus.infra.widgets.providers,
org.eclipse.papyrus.infra.widgets.selectors,
+ org.eclipse.papyrus.infra.widgets.strategy,
org.eclipse.papyrus.infra.widgets.util
Bundle-Vendor: %providerName
Bundle-ActivationPolicy: lazy
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/CLabelObservableValue.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/CLabelObservableValue.java
index 64031f2a893..b98449d4c6d 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/CLabelObservableValue.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/CLabelObservableValue.java
@@ -15,6 +15,7 @@ import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.papyrus.infra.tools.databinding.AggregatedObservable;
import org.eclipse.papyrus.infra.widgets.messages.Messages;
import org.eclipse.swt.custom.CLabel;
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/ComboObservableValue.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/ComboObservableValue.java
index 03e0988c2c6..69f1e88b2aa 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/ComboObservableValue.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/ComboObservableValue.java
@@ -20,6 +20,7 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.papyrus.infra.tools.databinding.AggregatedObservable;
import org.eclipse.papyrus.infra.widgets.providers.ComboLabelProvider;
import org.eclipse.papyrus.infra.widgets.providers.UnchangedObject;
import org.eclipse.papyrus.infra.widgets.providers.UnsetObject;
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/GrayedCheckboxObservableValue.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/GrayedCheckboxObservableValue.java
index db3ca5b4dd0..f7ee5bd120c 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/GrayedCheckboxObservableValue.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/GrayedCheckboxObservableValue.java
@@ -13,6 +13,7 @@ package org.eclipse.papyrus.infra.widgets.databinding;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.databinding.observable.value.ValueDiff;
+import org.eclipse.papyrus.infra.tools.databinding.AggregatedObservable;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Button;
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/TextObservableValue.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/TextObservableValue.java
index 8799a33033d..eaa4b861cd5 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/TextObservableValue.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/databinding/TextObservableValue.java
@@ -4,6 +4,7 @@ import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.ValueDiff;
+import org.eclipse.papyrus.infra.tools.databinding.AggregatedObservable;
import org.eclipse.papyrus.infra.widgets.providers.UnchangedObject;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java
index 9a99333e888..cac6c487131 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/BooleanCheckbox.java
@@ -13,7 +13,7 @@ package org.eclipse.papyrus.infra.widgets.editors;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
-import org.eclipse.papyrus.infra.widgets.databinding.AggregatedObservable;
+import org.eclipse.papyrus.infra.tools.databinding.AggregatedObservable;
import org.eclipse.papyrus.infra.widgets.databinding.GrayedCheckboxObservableValue;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.java
index 810743971be..a0b1f961809 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueEditor.java
@@ -354,11 +354,6 @@ public class MultipleValueEditor extends AbstractListEditor implements Selection
}
if(modelProperty != null) {
- // Object[] initialSelection = new Object[modelProperty.size()];
- // int i = 0;
- // for(Object semanticObject : modelProperty) {
- // initialSelection[i++] = containObject(semanticObject);
- // }
dialog.setInitialSelections(modelProperty.toArray());
} else {
dialog.setInitialSelections(new Object[0]);
@@ -376,11 +371,6 @@ public class MultipleValueEditor extends AbstractListEditor implements Selection
return;
}
- // List<Object> resultElements = new LinkedList<Object>();
- // for(Object r : result) {
- // resultElements.add(adaptResult(r));
- // }
-
modelProperty.addAll(Arrays.asList(result));
commit();
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java
index 508293c8f22..9e9d2811d61 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/MultipleValueSelectorDialog.java
@@ -21,8 +21,9 @@ import java.util.Set;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.papyrus.infra.widgets.Activator;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
import org.eclipse.papyrus.infra.widgets.messages.Messages;
@@ -36,8 +37,8 @@ import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.dialogs.SelectionDialog;
/**
@@ -72,12 +73,12 @@ public class MultipleValueSelectorDialog extends SelectionDialog implements Sele
/**
* The listViewer for chosen elements
*/
- protected ListViewer selectedElementsViewer;
+ protected StructuredViewer selectedElementsViewer;
/**
* The list for chosen elements
*/
- protected List selectedElements;
+ protected Tree selectedElements;
/**
* The add action button
@@ -309,11 +310,11 @@ public class MultipleValueSelectorDialog extends SelectionDialog implements Sele
*/
private void createListSection(Composite parent) {
- selectedElements = new List(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
+ selectedElements = new Tree(parent, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
selectedElements.addSelectionListener(this);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
selectedElements.setLayoutData(data);
- selectedElementsViewer = new ListViewer(selectedElements);
+ selectedElementsViewer = new TreeViewer(selectedElements);
selectedElementsViewer.setContentProvider(CollectionContentProvider.instance);
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceCombo.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceCombo.java
index 8213bd6c1d0..1b4bd4ffebc 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceCombo.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceCombo.java
@@ -17,7 +17,7 @@ import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.papyrus.infra.widgets.databinding.AggregatedObservable;
+import org.eclipse.papyrus.infra.tools.databinding.AggregatedObservable;
import org.eclipse.papyrus.infra.widgets.databinding.ComboObservableValue;
import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.java
index fa3b8291d77..913baf3f66a 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/ReferenceDialog.java
@@ -17,6 +17,7 @@ import java.util.List;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.infra.widgets.Activator;
import org.eclipse.papyrus.infra.widgets.creation.ReferenceValueFactory;
@@ -274,6 +275,11 @@ public class ReferenceDialog extends AbstractValueEditor implements SelectionLis
* The label provider
*/
public void setLabelProvider(ILabelProvider provider) {
+ if(provider == null) {
+ setLabelProvider(new LabelProvider());
+ return;
+ }
+
dialog.setLabelProvider(provider);
this.labelProvider = provider;
if(widgetObservable != null) {
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringCombo.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringCombo.java
index 5fb10328026..62c70d2b5f1 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringCombo.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/StringCombo.java
@@ -14,7 +14,7 @@ package org.eclipse.papyrus.infra.widgets.editors;
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.ValueDiff;
-import org.eclipse.papyrus.infra.widgets.databinding.AggregatedObservable;
+import org.eclipse.papyrus.infra.tools.databinding.AggregatedObservable;
import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.UnchangedObject;
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeSelectorDialog.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeSelectorDialog.java
index b773c6aeedc..f15c1b8b114 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeSelectorDialog.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/editors/TreeSelectorDialog.java
@@ -13,7 +13,6 @@ package org.eclipse.papyrus.infra.widgets.editors;
import java.util.Collections;
import java.util.HashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Set;
@@ -28,6 +27,7 @@ import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.papyrus.infra.core.ui.IRevealSemanticElement;
import org.eclipse.papyrus.infra.widgets.Activator;
import org.eclipse.papyrus.infra.widgets.providers.IAdaptableContentProvider;
import org.eclipse.papyrus.infra.widgets.providers.IGraphicalContentProvider;
@@ -95,20 +95,28 @@ public class TreeSelectorDialog extends SelectionDialog implements ITreeSelector
public void setContentProvider(ITreeContentProvider provider) {
contentProvider = provider;
if(treeViewer != null) {
- treeViewer.setContentProvider(contentProvider);
- if(treeViewer.getInput() == null) {
- doSetInput();
- }
- List<?> initialSelection = getInitialElementSelections();
- if(!initialSelection.isEmpty()) {
- treeViewer.setSelection(new StructuredSelection(initialSelection.get(0)), true);
- }
+ initViewerAndProvider();
}
if(contentProvider instanceof ICommitListener) {
commitListeners.add((ICommitListener)contentProvider);
}
}
+ protected void initViewerAndProvider() {
+ treeViewer.setContentProvider(contentProvider);
+ if(treeViewer.getInput() == null) {
+ doSetInput();
+ }
+ List<?> initialSelection = getInitialElementSelections();
+ if(contentProvider instanceof IRevealSemanticElement) {
+ ((IRevealSemanticElement)contentProvider).revealSemanticElement(initialSelection);
+ } else if(!initialSelection.isEmpty()) {
+ //FIXME : When we use an EncapsulatedContentProvider, we'll not get into this case,
+ //even if the encapsulated provider is not a IRevealSemanticElement
+ treeViewer.setSelection(new StructuredSelection(initialSelection.get(0)), true);
+ }
+ }
+
@Override
protected Composite getDialogArea() {
return (Composite)super.getDialogArea();
@@ -127,15 +135,7 @@ public class TreeSelectorDialog extends SelectionDialog implements ITreeSelector
treeViewer.setLabelProvider(labelProvider);
}
if(contentProvider != null) {
- treeViewer.setContentProvider(contentProvider);
- if(treeViewer.getInput() == null) {
- doSetInput();
- }
-
- List<?> initialSelection = getInitialElementSelections();
- if(!initialSelection.isEmpty() && initialSelection.get(0) != null) {
- treeViewer.setSelection(new StructuredSelection(initialSelection.get(0)), true);
- }
+ initViewerAndProvider();
}
treeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@@ -151,6 +151,9 @@ public class TreeSelectorDialog extends SelectionDialog implements ITreeSelector
if(contentProvider instanceof IHierarchicContentProvider) {
boolean isValidValue = ((IHierarchicContentProvider)contentProvider).isValidValue(selectedElement);
+ if(contentProvider instanceof IAdaptableContentProvider) {
+ selectedElement = ((IAdaptableContentProvider)contentProvider).getAdaptedValue(selectedElement);
+ }
if(isValidValue) {
setResult(Collections.singletonList(selectedElement));
} else {
@@ -192,8 +195,6 @@ public class TreeSelectorDialog extends SelectionDialog implements ITreeSelector
graphicalContentProvider.createAfter(afterTreeComposite);
}
- treeViewer.setSelection(new StructuredSelection(getAdaptedInitialSelection()));
-
getShell().setDefaultButton(null);
getButton(OK).setFocus();
getShell().setImage(Activator.getDefault().getImage("/icons/papyrus.png")); //$NON-NLS-1$
@@ -230,17 +231,19 @@ public class TreeSelectorDialog extends SelectionDialog implements ITreeSelector
this.input = input;
}
- public List<Object> getAdaptedInitialSelection() {
- if(contentProvider instanceof IAdaptableContentProvider) {
- List<Object> result = new LinkedList<Object>();
- for(Object object : getInitialElementSelections()) {
- result.add(((IAdaptableContentProvider)contentProvider).getContainerValue(object));
- }
- return result;
- } else {
- return super.getInitialElementSelections();
- }
- }
+ // @Deprecated
+ // //Unused
+ // public List<Object> getAdaptedInitialSelection() {
+ // if(contentProvider instanceof IAdaptableContentProvider) {
+ // List<Object> result = new LinkedList<Object>();
+ // for(Object object : getInitialElementSelections()) {
+ // result.add(((IAdaptableContentProvider)contentProvider).getContainerValue(object));
+ // }
+ // return result;
+ // } else {
+ // return super.getInitialElementSelections();
+ // }
+ // }
private void doSetInput() {
if(input == null) {
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractStaticContentProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractStaticContentProvider.java
index 9d421be3bcd..a2bc101c076 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractStaticContentProvider.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractStaticContentProvider.java
@@ -29,4 +29,8 @@ public abstract class AbstractStaticContentProvider implements IStaticContentPro
// Nothing
}
+ public Object[] getElements(Object inputElement) {
+ return getElements();
+ }
+
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractTreeFilter.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractTreeFilter.java
index 0ec3462cb48..8db89fe982a 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractTreeFilter.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/AbstractTreeFilter.java
@@ -21,6 +21,9 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
+import org.eclipse.papyrus.infra.widgets.strategy.IStrategyBasedContentProvider;
+import org.eclipse.papyrus.infra.widgets.strategy.ProviderBasedBrowseStrategy;
+import org.eclipse.papyrus.infra.widgets.strategy.TreeBrowseStrategy;
/**
* An abstract ViewerFilter for TreeViewers.
@@ -75,32 +78,37 @@ public abstract class AbstractTreeFilter extends ViewerFilter {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
- ITreeContentProvider contentProvider = null;
+ TreeBrowseStrategy strategy = null;
if(viewer instanceof StructuredViewer) {
IContentProvider baseContentProvider = ((StructuredViewer)viewer).getContentProvider();
- if(baseContentProvider instanceof ITreeContentProvider) {
- contentProvider = (ITreeContentProvider)baseContentProvider;
+ if(baseContentProvider instanceof IStrategyBasedContentProvider) {
+ strategy = ((IStrategyBasedContentProvider)baseContentProvider).getRevealStrategy();
+ }
+
+ if(strategy == null && baseContentProvider instanceof ITreeContentProvider) {
+ strategy = new ProviderBasedBrowseStrategy((ITreeContentProvider)baseContentProvider);
}
}
- if(contentProvider == null) { //The contentProvider is not a TreeContentProvider
+ if(strategy == null) { //The contentProvider is not a TreeContentProvider
return isVisible(viewer, parentElement, element);
}
- return select(viewer, parentElement, element, contentProvider);
+ return select(viewer, parentElement, element, strategy);
}
- protected boolean select(Viewer viewer, Object parentElement, Object element, ITreeContentProvider contentProvider) {
+ protected boolean select(Viewer viewer, Object parentElement, Object element, TreeBrowseStrategy strategy) {
Set<Object> visitedChildren = new HashSet<Object>();
Set<Object> visitedParents = new HashSet<Object>();
if(useCache && visibleElement.containsKey(element)) {
return visibleElement.get(element);
}
- boolean isVisible = isVisible(viewer, parentElement, element) || hasOneVisibleChild(viewer, element, contentProvider, visitedChildren);
+
+ boolean isVisible = isVisible(viewer, parentElement, element) || hasOneVisibleChild(viewer, element, strategy, visitedChildren);
if(showIfHasVisibleParent) {
- isVisible = isVisible || hasOneVisibleParent(viewer, element, contentProvider, visitedParents);
+ isVisible = isVisible || hasOneVisibleParent(viewer, element, strategy, visitedParents);
}
if(useCache) {
@@ -110,7 +118,7 @@ public abstract class AbstractTreeFilter extends ViewerFilter {
return isVisible;
}
- protected boolean hasOneVisibleChild(Viewer viewer, Object element, ITreeContentProvider contentProvider, Set<Object> visitedElements) {
+ protected boolean hasOneVisibleChild(Viewer viewer, Object element, TreeBrowseStrategy strategy, Set<Object> visitedElements) {
//TODO : separate this method in -hasOneVisibleChild() and #doHasOneVisibleChild(), to handle the cache management in a private method,
//while letting the opportunity to override the method
if(useCache && visibleChild.containsKey(element)) {
@@ -121,8 +129,8 @@ public abstract class AbstractTreeFilter extends ViewerFilter {
if(!visitedElements.contains(element)) {
visitedElements.add(element);
- for(Object childElement : contentProvider.getChildren(element)) {
- if(isVisible(viewer, element, childElement) || hasOneVisibleChild(viewer, childElement, contentProvider, visitedElements)) {
+ for(Object childElement : strategy.getChildren(element)) {
+ if(isVisible(viewer, element, childElement) || hasOneVisibleChild(viewer, childElement, strategy, visitedElements)) {
result = true;
break;
}
@@ -135,7 +143,7 @@ public abstract class AbstractTreeFilter extends ViewerFilter {
return result;
}
- protected boolean hasOneVisibleParent(Viewer viewer, Object element, ITreeContentProvider contentProvider, Set<Object> visitedElements) {
+ protected boolean hasOneVisibleParent(Viewer viewer, Object element, TreeBrowseStrategy strategy, Set<Object> visitedElements) {
if(useCache && visibleParent.containsKey(element)) {
return visibleParent.get(element);
}
@@ -145,11 +153,11 @@ public abstract class AbstractTreeFilter extends ViewerFilter {
visitedElements.add(element);
- Object parentElement = contentProvider.getParent(element);
+ Object parentElement = strategy.getParent(element);
if(parentElement == element || parentElement == null) {
result = isVisible(viewer, parentElement, element);
} else {
- result = isVisible(viewer, null, parentElement) || hasOneVisibleParent(viewer, parentElement, contentProvider, visitedElements);
+ result = isVisible(viewer, null, parentElement) || hasOneVisibleParent(viewer, parentElement, strategy, visitedElements);
}
}
@@ -171,5 +179,4 @@ public abstract class AbstractTreeFilter extends ViewerFilter {
public void setShowIfHasVisibleParent(boolean showIfHasVisibleParent) {
this.showIfHasVisibleParent = showIfHasVisibleParent;
}
-
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/CollectionContentProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/CollectionContentProvider.java
index dda77df673a..252ba87cc6f 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/CollectionContentProvider.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/CollectionContentProvider.java
@@ -13,7 +13,7 @@ package org.eclipse.papyrus.infra.widgets.providers;
import java.util.Collection;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
/**
@@ -22,7 +22,7 @@ import org.eclipse.jface.viewers.Viewer;
* @author Camille Letavernier
*
*/
-public class CollectionContentProvider implements IStructuredContentProvider {
+public class CollectionContentProvider implements ITreeContentProvider {
private CollectionContentProvider() {
@@ -65,4 +65,16 @@ public class CollectionContentProvider implements IStructuredContentProvider {
* The Singleton instance
*/
public static CollectionContentProvider instance = new CollectionContentProvider();
+
+ public Object[] getChildren(Object parentElement) {
+ return new Object[0]; //Flat tree
+ }
+
+ public Object getParent(Object element) {
+ return null; //Flat tree
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EmptyContentProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EmptyContentProvider.java
index 6677b40bb9f..bbe00bb195e 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EmptyContentProvider.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EmptyContentProvider.java
@@ -11,7 +11,6 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.providers;
-import org.eclipse.jface.viewers.Viewer;
/**
* A ContentProvider returning empty collections
@@ -19,7 +18,7 @@ import org.eclipse.jface.viewers.Viewer;
* @author Camille Letavernier
*
*/
-public class EmptyContentProvider implements IStaticContentProvider {
+public class EmptyContentProvider extends AbstractStaticContentProvider {
/**
* Singleton instance
@@ -32,14 +31,6 @@ public class EmptyContentProvider implements IStaticContentProvider {
}
- public void dispose() {
- //Nothing
- }
-
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- //Nothing
- }
-
/**
* @see org.eclipse.papyrus.infra.widgets.providers.IStaticContentProvider#getElements()
*
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EncapsulatedContentProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EncapsulatedContentProvider.java
index d2d6f154e3a..3997bd7d823 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EncapsulatedContentProvider.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/EncapsulatedContentProvider.java
@@ -12,41 +12,53 @@
package org.eclipse.papyrus.infra.widgets.providers;
import java.util.LinkedHashSet;
-import java.util.LinkedList;
import java.util.List;
import java.util.Set;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.papyrus.infra.core.ui.IRevealSemanticElement;
+import org.eclipse.papyrus.infra.tools.util.ListHelper;
import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
import org.eclipse.papyrus.infra.widgets.editors.ICommitListener;
+import org.eclipse.papyrus.infra.widgets.strategy.IStrategyBasedContentProvider;
+import org.eclipse.papyrus.infra.widgets.strategy.TreeBrowseStrategy;
import org.eclipse.swt.widgets.Composite;
/**
- * A ContentProvider to adapt an IStaticContentProvider to an
- * IStructurecContentProvider Useful when you need to use a ContentProvider that
- * doesn't depend on its Input Object to return values in a JFace Viewer.
- * This content provider also supports temporary elements, which are added
- * to the list of static elements returned by the encapsulated provider.
+ * A ContentProvider encapsulate another ContentProvider.
+ * This class implements all Papyrus interfaces extending IContentProvider,
+ * and is thus compatible with all papyrus tools, even if the encapsulated
+ * provider is not.
+ *
+ * Moreover, the Encapsulated provider can handle temporary elements.
*
* @author Camille Letavernier
*
*/
-public class EncapsulatedContentProvider implements IHierarchicContentProvider, IGraphicalContentProvider, ICommitListener, IAdaptableContentProvider {
+//TODO : Move the temporary elements feature to another class.
+//This feature is only used by multi-reference dialogs
+public class EncapsulatedContentProvider implements IHierarchicContentProvider, IGraphicalContentProvider, ICommitListener, IAdaptableContentProvider, IRevealSemanticElement, IStrategyBasedContentProvider, IStaticContentProvider {
/**
* The encapsulated static content provider
*/
- protected IStaticContentProvider encapsulated;
+ protected IStructuredContentProvider encapsulated;
+
+ /**
+ * The set of temporaryElements, which are added from outside this ContentProvider
+ */
+ private Set<Object> temporaryElements = new LinkedHashSet<Object>();
/**
*
* Constructor.
*
* @param encapsulated
- * The encapsulated static content provider
+ * The encapsulated content provider, to which all calls will be forwarded
*/
- public EncapsulatedContentProvider(IStaticContentProvider encapsulated) {
+ public EncapsulatedContentProvider(IStructuredContentProvider encapsulated) {
this.encapsulated = encapsulated;
}
@@ -63,19 +75,17 @@ public class EncapsulatedContentProvider implements IHierarchicContentProvider,
* the objects returned by the wrapped StaticContentProvider and the temporary
* elements, which are not known by the wrapped provider.
*
+ * @param elements
+ * The Object[] returned by the encapsulated provider
* @return
* All elements known by this ContentProvider
*/
- private Object[] getAllElements() {
- Object[] elements = encapsulated.getElements();
+ private Object[] getAllElements(Object[] elements) {
if(temporaryElements.isEmpty()) {
return elements;
}
- List<Object> result = new LinkedList<Object>();
- for(Object object : elements) {
- result.add(object);
- }
+ List<Object> result = ListHelper.asList(elements);
result.addAll(temporaryElements);
return result.toArray();
}
@@ -84,21 +94,27 @@ public class EncapsulatedContentProvider implements IHierarchicContentProvider,
* {@inheritDoc}
*/
public void dispose() {
- //Nothing
+ //encapsulated.dispose();
+ //encapsulated = null;
}
/**
* {@inheritDoc}
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- encapsulated.inputChanged(viewer, oldInput, newInput);
+ if(encapsulated != null) {
+ encapsulated.inputChanged(viewer, oldInput, newInput);
+ }
}
/**
* {@inheritDoc}
*/
public Object[] getElements(Object inputElement) {
- return getElements();
+ if(encapsulated == null) {
+ return new Object[0];
+ }
+ return getAllElements(encapsulated.getElements(inputElement));
}
/**
@@ -108,15 +124,13 @@ public class EncapsulatedContentProvider implements IHierarchicContentProvider,
* all elements from the wrapped ContentProvider
*/
public Object[] getElements() {
- return getAllElements();
+ if(encapsulated instanceof IStaticContentProvider) {
+ return getAllElements(((IStaticContentProvider)encapsulated).getElements());
+ }
+ return getElements(null);
}
/**
- * The set of temporaryElements, which are added from outside this ContentProvider
- */
- private Set<Object> temporaryElements = new LinkedHashSet<Object>();
-
- /**
* Adds a Temporary element to this ContentProvider
*
* @param newObject
@@ -218,10 +232,23 @@ public class EncapsulatedContentProvider implements IHierarchicContentProvider,
return selection;
}
- public Object getContainerValue(Object selection) {
- if(encapsulated instanceof IAdaptableContentProvider) {
- return ((IAdaptableContentProvider)encapsulated).getContainerValue(selection);
+ public void revealSemanticElement(List<?> elementList) {
+ if(encapsulated instanceof IRevealSemanticElement) {
+ ((IRevealSemanticElement)encapsulated).revealSemanticElement(elementList);
}
- return selection;
+ }
+
+ public TreeBrowseStrategy getBrowseStrategy() {
+ if(encapsulated instanceof IStrategyBasedContentProvider) {
+ return ((IStrategyBasedContentProvider)encapsulated).getBrowseStrategy();
+ }
+ return null;
+ }
+
+ public TreeBrowseStrategy getRevealStrategy() {
+ if(encapsulated instanceof IStrategyBasedContentProvider) {
+ return ((IStrategyBasedContentProvider)encapsulated).getRevealStrategy();
+ }
+ return null;
}
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/HierarchicToFlatContentProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/HierarchicToFlatContentProvider.java
index 7ba654007c9..01b9cbaa3b4 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/HierarchicToFlatContentProvider.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/HierarchicToFlatContentProvider.java
@@ -18,7 +18,7 @@ import java.util.Set;
import org.eclipse.jface.viewers.Viewer;
-
+//FIXME : Adapt this code to TreeBrowseStrategy
public class HierarchicToFlatContentProvider extends TreeToFlatContentProvider {
private IHierarchicContentProvider contentProvider;
@@ -43,11 +43,6 @@ public class HierarchicToFlatContentProvider extends TreeToFlatContentProvider {
}
@Override
- public Object[] getElements() {
- return getElementsList().toArray();
- }
-
- @Override
protected Collection<Object> getElementsList() {
Collection<Object> result = new LinkedHashSet<Object>();
Set<Object> browsedElements = new HashSet<Object>();
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IAdaptableContentProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IAdaptableContentProvider.java
index 07e684e9c00..213f89192d5 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IAdaptableContentProvider.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IAdaptableContentProvider.java
@@ -38,5 +38,5 @@ public interface IAdaptableContentProvider extends IStructuredContentProvider {
* @return
* The container object wrapping the semantic element
*/
- public Object getContainerValue(Object semanticElement);
+ // public Object getContainerValue(Object semanticElement);
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IStaticContentProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IStaticContentProvider.java
index 107248f9ce1..199a60bb2ae 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IStaticContentProvider.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/IStaticContentProvider.java
@@ -11,7 +11,7 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.widgets.providers;
-import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
/**
* A ContentProvider which returns values that don't depend
@@ -24,7 +24,7 @@ import org.eclipse.jface.viewers.IContentProvider;
* @see AbstractStaticContentProvider
*
*/
-public interface IStaticContentProvider extends IContentProvider {
+public interface IStaticContentProvider extends IStructuredContentProvider {
/**
* @return the elements provided by this class
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/TreeToFlatContentProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/TreeToFlatContentProvider.java
index 569c1903143..bdee78719c4 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/TreeToFlatContentProvider.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/providers/TreeToFlatContentProvider.java
@@ -21,8 +21,8 @@ import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
-
-public class TreeToFlatContentProvider implements IStaticContentProvider {
+//FIXME : Adapt this code to TreeBrowseStrategy
+public class TreeToFlatContentProvider extends AbstractStaticContentProvider {
private ITreeContentProvider contentProvider;
@@ -35,10 +35,12 @@ public class TreeToFlatContentProvider implements IStaticContentProvider {
this.contentProvider = provider;
}
+ @Override
public void dispose() {
contentProvider.dispose();
}
+ @Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if(viewer instanceof StructuredViewer) {
this.viewer = (StructuredViewer)viewer;
@@ -106,5 +108,4 @@ public class TreeToFlatContentProvider implements IStaticContentProvider {
}
}
}
-
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java
index 50bbfb8a9a8..dbf80f91fd1 100644
--- a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/selectors/ReferenceSelector.java
@@ -123,39 +123,39 @@ public class ReferenceSelector implements IElementSelector {
if(selection instanceof IStructuredSelection) {
Object[] containerElementsToMove = getElementsToMove(((IStructuredSelection)selection).toArray());
Object[] semanticElementsToMove = getSemanticElements(containerElementsToMove);
- addSelectedElements(containerElementsToMove);
+ addSelectedElements(semanticElementsToMove);
return semanticElementsToMove;
}
return new Object[0];
}
- /**
- * This method is used for handling correctly the IAdaptableContentProvider
- * The objects can be in two different forms :
- * - The semantic element
- * - The container element
- *
- * This methods returns an array of container elements from an array of
- * semantic elements. This is useful when specifying a selection to a
- * viewer using an IAdaptableContentProvider
- *
- * @param semanticElements
- * The array of semantic elements to be converted
- * @return
- * The array of elements wrapped in their container
- *
- * @see #getSemanticElements(Object[])
- * @see org.eclipse.papyrus.infra.widgets.providers.IAdaptableContentProvider
- */
- private Object[] getContainerElements(Object[] semanticElements) {
- Object[] containerElements = new Object[semanticElements.length];
- int i = 0;
- for(Object semanticElement : semanticElements) {
- containerElements[i++] = contentProvider.getContainerValue(semanticElement);
- }
- return containerElements;
- }
+ // /**
+ // * This method is used for handling correctly the IAdaptableContentProvider
+ // * The objects can be in two different forms :
+ // * - The semantic element
+ // * - The container element
+ // *
+ // * This methods returns an array of container elements from an array of
+ // * semantic elements. This is useful when specifying a selection to a
+ // * viewer using an IAdaptableContentProvider
+ // *
+ // * @param semanticElements
+ // * The array of semantic elements to be converted
+ // * @return
+ // * The array of elements wrapped in their container
+ // *
+ // * @see #getSemanticElements(Object[])
+ // * @see org.eclipse.papyrus.infra.widgets.providers.IAdaptableContentProvider
+ // */
+ // private Object[] getContainerElements(Object[] semanticElements) {
+ // Object[] containerElements = new Object[semanticElements.length];
+ // int i = 0;
+ // for(Object semanticElement : semanticElements) {
+ // containerElements[i++] = contentProvider.getContainerValue(semanticElement);
+ // }
+ // return containerElements;
+ // }
/**
* This method is used for handling correctly the IAdaptableContentProvider
@@ -213,9 +213,9 @@ public class ReferenceSelector implements IElementSelector {
*
* @param elements
*/
- private void addSelectedElements(Object[] containerElements) {
- if(containerElements.length > 0) {
- selectedElements.addAll(Arrays.asList(containerElements));
+ private void addSelectedElements(Object[] semanticElements) {
+ if(semanticElements.length > 0) {
+ selectedElements.addAll(Arrays.asList(semanticElements));
fTree.getViewer().refresh();
}
}
@@ -250,7 +250,7 @@ public class ReferenceSelector implements IElementSelector {
// Object[] containerElementsToMove = getElementsToMove(((IStructuredSelection)fTree.getViewer().getSelection()).toArray());
Object[] containerElementsToMove = getElementsToMove(visibleElements.toArray());
Object[] semanticElementsToMove = getSemanticElements(containerElementsToMove);
- addSelectedElements(containerElementsToMove);
+ addSelectedElements(semanticElementsToMove);
return semanticElementsToMove;
}
@@ -275,7 +275,7 @@ public class ReferenceSelector implements IElementSelector {
*/
public void setSelectedElements(Object[] semanticElements) {
selectedElements.clear();
- selectedElements.addAll(Arrays.asList(getContainerElements(semanticElements)));
+ selectedElements.addAll(Arrays.asList(semanticElements));
fTree.getViewer().refresh();
}
@@ -357,10 +357,10 @@ public class ReferenceSelector implements IElementSelector {
fTree.getViewer().addFilter(new ViewerFilter() {
@Override
- public boolean select(Viewer viewer, Object parentElement, Object element) {
+ public boolean select(Viewer viewer, Object parentElement, Object containerElement) {
if(unique) {
//TODO : check if the selected element has selectable children
- return !selectedElements.contains(element);
+ return !selectedElements.contains(contentProvider.getAdaptedValue(containerElement));
} else {
return true;
}
@@ -394,76 +394,4 @@ public class ReferenceSelector implements IElementSelector {
elementSelectionListeners.add(listener);
}
- // /**
- // * A Text field to let the user type its own filter
- // *
- // * @author Camille Letavernier
- // *
- // */
- // private class Filter extends Composite implements KeyListener {
- //
- // /**
- // * The text box used to edit the filter
- // */
- // private Text text;
- //
- // /**
- // * @param parent
- // * The composite in which the filter should be created
- // * @param style
- // * The style applied to this filter's text box
- // */
- // public Filter(Composite parent, int style) {
- // super(parent, SWT.NONE);
- // setLayout(new FillLayout());
- // text = new Text(this, style);
- // text.addKeyListener(this);
- // listeners = new LinkedList<Listener>();
- // }
- //
- // /**
- // * @return this filter as a String
- // */
- // public String getFilter() {
- // return text.getText();
- // }
- //
- // /**
- // * Adds a listener on this filter. The listener is notified
- // * each time the filter changes
- // *
- // * @param listener
- // */
- // public void addChangeListener(Listener listener) {
- // listeners.add(listener);
- // }
- //
- // /**
- // * Ignored
- // */
- // public void keyPressed(KeyEvent e) {
- // //Nothing
- // }
- //
- // /**
- // * Handles the filter change event
- // */
- // public void keyReleased(KeyEvent e) {
- // for(Listener listener : listeners) {
- // listener.handleEvent(null);
- // }
- // }
- //
- // @Override
- // public void dispose() {
- // listeners.clear();
- // super.dispose();
- // }
- //
- // /**
- // * All registered listeners
- // */
- // private Collection<Listener> listeners;
- // }
-
}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/AbstractTreeBrowseStrategy.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/AbstractTreeBrowseStrategy.java
new file mode 100644
index 00000000000..9bae275fa94
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/AbstractTreeBrowseStrategy.java
@@ -0,0 +1,31 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.strategy;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.Viewer;
+
+
+public abstract class AbstractTreeBrowseStrategy implements TreeBrowseStrategy {
+
+ public void dispose() {
+ //Nothing
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ //Nothing
+ }
+
+ abstract public void revealSemanticElement(List<?> elementsList);
+
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/IStrategyBasedContentProvider.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/IStrategyBasedContentProvider.java
new file mode 100644
index 00000000000..47ea97567e7
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/IStrategyBasedContentProvider.java
@@ -0,0 +1,22 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.strategy;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+
+
+public interface IStrategyBasedContentProvider extends IStructuredContentProvider {
+
+ public TreeBrowseStrategy getBrowseStrategy();
+
+ public TreeBrowseStrategy getRevealStrategy();
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/ProviderBasedBrowseStrategy.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/ProviderBasedBrowseStrategy.java
new file mode 100644
index 00000000000..6bab3b7fe21
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/ProviderBasedBrowseStrategy.java
@@ -0,0 +1,133 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.strategy;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.papyrus.infra.tools.util.ListHelper;
+import org.eclipse.papyrus.infra.widgets.Activator;
+import org.eclipse.papyrus.infra.widgets.providers.EncapsulatedContentProvider;
+import org.eclipse.papyrus.infra.widgets.providers.IHierarchicContentProvider;
+
+
+public class ProviderBasedBrowseStrategy extends EncapsulatedContentProvider implements TreeBrowseStrategy {
+
+ protected ITreeContentProvider provider;
+
+ protected boolean filterElements = false;
+
+ protected final Map<Object, Boolean> cache = new HashMap<Object, Boolean>();
+
+ protected final Map<Object, Boolean> visibleChildCache = new HashMap<Object, Boolean>();
+
+ public ProviderBasedBrowseStrategy(ITreeContentProvider provider) {
+ setProvider(provider);
+ }
+
+ public ProviderBasedBrowseStrategy() {
+
+ }
+
+ public void setProvider(ITreeContentProvider provider) {
+ encapsulated = provider;
+ this.provider = provider;
+ filterElements = provider instanceof IHierarchicContentProvider;
+ clearCache();
+ }
+
+ @Override
+ public Object[] getChildren(Object parent) {
+ if(provider == null) {
+ Activator.log.warn("The provider has not been initialized");
+ return new Object[0];
+ }
+
+ return filterElements ? getValidChildren(parent, new HashSet<Object>()) : super.getChildren(parent);
+ }
+
+ @Override
+ public boolean hasChildren(Object parent) {
+ //May be expensive
+ return getChildren(parent).length > 0;
+ }
+
+ protected Object[] getValidChildren(Object parent, Set<Object> visitedElements) {
+ List<?> children = ListHelper.asList(super.getChildren(parent));
+ Iterator<?> childrenIterator = children.iterator();
+ while(childrenIterator.hasNext()) {
+ Object child = childrenIterator.next();
+ if(!isValid(child, visitedElements)) {
+ childrenIterator.remove();
+ }
+ }
+
+ return children.toArray();
+ }
+
+ protected boolean isValid(Object containerElement, Set<Object> visitedElements) {
+ if(!cache.containsKey(containerElement)) {
+ boolean isVisible;
+
+ if(browseElement(containerElement)) {
+ isVisible = isValidValue(containerElement) || hasOneVisibleChild(containerElement, visitedElements);
+ } else {
+ isVisible = false;
+ }
+
+ cache.put(containerElement, isVisible);
+ }
+ return cache.get(containerElement);
+ }
+
+ protected boolean browseElement(Object containerElement) {
+ return true;
+ }
+
+ protected boolean hasOneVisibleChild(Object element, Set<Object> visitedElements) {
+ if(!visibleChildCache.containsKey(element)) {
+ boolean result = false;
+ if(visitedElements.add(element)) {
+ for(Object child : super.getChildren(element)) {
+ if(isValid(child, visitedElements)) {
+ result = true;
+ break;
+ }
+ }
+ }
+
+ visibleChildCache.put(element, result);
+ }
+ return visibleChildCache.get(element);
+ }
+
+ public TreePath findPath(Object semanticElement, Object[] rootElements) {
+ return TreePath.EMPTY; //TODO : Naive search
+ }
+
+ protected void clearCache() {
+ cache.clear();
+ visibleChildCache.clear();
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ clearCache();
+ }
+}
diff --git a/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/TreeBrowseStrategy.java b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/TreeBrowseStrategy.java
new file mode 100644
index 00000000000..2a36a60429c
--- /dev/null
+++ b/plugins/infra/widget/org.eclipse.papyrus.infra.widgets/src/org/eclipse/papyrus/infra/widgets/strategy/TreeBrowseStrategy.java
@@ -0,0 +1,41 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.widgets.strategy;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreePath;
+import org.eclipse.papyrus.infra.core.ui.IRevealSemanticElement;
+
+
+/**
+ * An interface to define a strategy for browsing a Tree
+ *
+ * @author Camille Letavernier
+ */
+public interface TreeBrowseStrategy extends ITreeContentProvider, IRevealSemanticElement {
+
+ /**
+ * Finds a path to the given element
+ *
+ * @param element
+ * The semanticElement to find
+ * @parem input
+ * The root Elements
+ * @return
+ * @deprecated See {@link #revealSemanticElement(java.util.List)} instead
+ */
+ @Deprecated
+ public TreePath findPath(Object semanticElement, Object[] roots);
+
+
+
+}

Back to the top