Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfaure2012-02-28 08:37:04 -0500
committertfaure2012-02-28 08:37:04 -0500
commitfc5a88032661ea8527a97529ee7e9371c7894249 (patch)
treee27999220cec24fd453d07c5b049b9ff6c7df024 /plugins
parentc22e7601505eb475da8fe2324366dedf3268c497 (diff)
downloadorg.eclipse.papyrus-fc5a88032661ea8527a97529ee7e9371c7894249.tar.gz
org.eclipse.papyrus-fc5a88032661ea8527a97529ee7e9371c7894249.tar.xz
org.eclipse.papyrus-fc5a88032661ea8527a97529ee7e9371c7894249.zip
NEW - bug 372724: [Model Explorer] Search function does not traverse EReferences, LinkItems
https://bugs.eclipse.org/bugs/show_bug.cgi?id=372724 trunk backport
Diffstat (limited to 'plugins')
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java36
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/IReferencable.java27
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/LinkNode.java24
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/LinkNodeAdapterFactory.java38
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java114
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java180
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/IMatchingItem.java44
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/LinkItemMatchingItem.java55
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/ModelElementItemMatchingItem.java47
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/ReferencableMatchingItem.java50
10 files changed, 529 insertions, 86 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java
index 2237c11aa83..3aaf6b71061 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/CustomCommonViewer.java
@@ -13,6 +13,8 @@
*****************************************************************************/
package org.eclipse.papyrus.views.modelexplorer;
+import org.eclipse.jface.viewers.IElementComparer;
+import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem;
import org.eclipse.swt.dnd.DND;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService;
@@ -30,21 +32,44 @@ public class CustomCommonViewer extends CommonViewer {
public CustomCommonViewer(String aViewerId, Composite aParent, int aStyle) {
super(aViewerId, aParent, aStyle);
// TODO Auto-generated constructor stub
+ setComparer(new IElementComparer() {
+
+ public int hashCode(Object element) {
+ if(element instanceof IReferencable) {
+ IReferencable ref = (IReferencable)element;
+ return ref.getElementBehind().hashCode();
+ }
+ if(element instanceof IMatchingItem) {
+ IMatchingItem matchItem = (IMatchingItem)element;
+ return matchItem.matchingItemHashcode();
+ }
+ return element.hashCode();
+ }
+
+ public boolean equals(Object a, Object b) {
+ if(a instanceof IMatchingItem) {
+ return ((IMatchingItem)a).matchingItemEquals(b);
+ }
+
+ if(b != null) {
+ return b.equals(a);
+ }
+ return false;
+ }
+ });
}
/**
* {@inheritDoc}
*/
protected void initDragAndDrop() {
- dropAdapter=null;
+ dropAdapter = null;
int operations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
CommonDragAdapter dragAdapter = createDragAdapter();
- addDragSupport(operations, dragAdapter.getSupportedDragTransfers(),
- dragAdapter);
+ addDragSupport(operations, dragAdapter.getSupportedDragTransfers(), dragAdapter);
dropAdapter = createDropAdapter();
- addDropSupport(operations, dropAdapter.getSupportedDropTransfers(),
- dropAdapter);
+ addDropSupport(operations, dropAdapter.getSupportedDropTransfers(), dropAdapter);
NavigatorDnDService dnd = (NavigatorDnDService)getNavigatorContentService().getDnDService();
dnd.setDropAdaptor(dropAdapter);
@@ -52,6 +77,7 @@ public class CustomCommonViewer extends CommonViewer {
/**
* get the listener in order to parameterize during the runtime the drop
+ *
* @return the dropadapter
*/
public CommonDropAdapter getDropAdapter() {
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/IReferencable.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/IReferencable.java
new file mode 100644
index 00000000000..2fb86129ded
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/IReferencable.java
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos) mathieu.velten@atos.net - Initial API and implementation
+ * Philippe Roland (Atos) philippe.roland@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer;
+
+/**
+ * This interface is used to refer any object wishing to transparently
+ * offer access to another child object
+ *
+ * @author proland
+ *
+ */
+public interface IReferencable {
+
+ public Object getElementBehind();
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/LinkNode.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/LinkNode.java
new file mode 100644
index 00000000000..8359c1c5263
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/LinkNode.java
@@ -0,0 +1,24 @@
+/***********************************************************************************************************************
+ * Copyright (c) 2011 Atos.
+ *
+ * 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: Philippe ROLAND (Atos) - initial API and implementation
+ *
+ **********************************************************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer;
+
+/**
+ * Empty Interface. Used by ModelExplorer to refer to any object referencing TreeItems
+ *
+ * @author proland
+ */
+public interface LinkNode {
+
+ static class LinkNodeImpl implements LinkNode {
+ }
+
+ public static LinkNode LinkNodeInstance = new LinkNodeImpl();
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/LinkNodeAdapterFactory.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/LinkNodeAdapterFactory.java
new file mode 100644
index 00000000000..a48dafd5514
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/LinkNodeAdapterFactory.java
@@ -0,0 +1,38 @@
+/***********************************************************************************************************************
+ * Copyright (c) 2011 Atos.
+ *
+ * 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: Philippe ROLAND (Atos) - initial API and implementation
+ *
+ **********************************************************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.facet.infra.browser.uicore.internal.model.LinkItem;
+
+/**
+ * This factory returns a LinkNode instance for any adapter instancing LinkItem or EReference
+ *
+ * @author proland
+ *
+ */
+public class LinkNodeAdapterFactory implements IAdapterFactory {
+
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if(adapterType == LinkNode.class) {
+ if(adaptableObject instanceof LinkItem || adaptableObject instanceof EReference) {
+ return LinkNode.LinkNodeInstance;
+ }
+ }
+ return null;
+ }
+
+ public Class[] getAdapterList() {
+ return new Class[]{};
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
index 1206cb2962e..7b5fa8a8463 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/ModelExplorerView.java
@@ -26,6 +26,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
import org.eclipse.emf.transaction.ResourceSetChangeEvent;
@@ -36,6 +37,7 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.StructuredSelection;
@@ -51,6 +53,10 @@ import org.eclipse.papyrus.infra.core.utils.EditorUtils;
import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
import org.eclipse.papyrus.infra.emf.providers.SemanticFromModelExplorer;
import org.eclipse.papyrus.views.modelexplorer.listener.DoubleClickListener;
+import org.eclipse.papyrus.views.modelexplorer.matching.IMatchingItem;
+import org.eclipse.papyrus.views.modelexplorer.matching.LinkItemMatchingItem;
+import org.eclipse.papyrus.views.modelexplorer.matching.ModelElementItemMatchingItem;
+import org.eclipse.papyrus.views.modelexplorer.matching.ReferencableMatchingItem;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -75,6 +81,9 @@ import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.views.properties.IPropertySheetPage;
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
/**
* Papyrus Model Explorer associated to one {@link IMultiDiagramEditor}.
@@ -650,32 +659,95 @@ public class ModelExplorerView extends CommonNavigator implements IRevealSemanti
}
}
+ public void revealSemanticElement(List<?> elementList) {
+ reveal(elementList, getCommonViewer());
+ }
+
/**
- * {@inheritDoc}
+ * Expands the given CommonViewer to reveal the given elements
+ * @param elementList The elements to reveal
+ * @param commonViewer The CommonViewer they are to be revealed in
*/
- 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(getCommonViewer().getContentProvider() != null) {
- //need the root in order to find all element in the tree
- Object root = getCommonViewer().getInput();
- //look for the path in order to access to this element
- List<Object> path = searchPath(currentEObject, Arrays.asList(((ITreeContentProvider)getCommonViewer().getContentProvider()).getElements(root)));
- if(path.size() > 0) {
- //expand in the common viewer the path
- expandItems(path, getCommonViewer().getTree().getItems());
- treeElementToSelect.add(path.get(path.size() - 1));
+ public static void reveal(Iterable<?> elementList, CommonViewer commonViewer) {
+ ArrayList<IMatchingItem> matchingItemsToSelect = new ArrayList<IMatchingItem>();
+ // filter out non EMF objects
+ Iterable<EObject> list = Iterables.transform(Iterables.filter(elementList, EObject.class), new Function<Object, EObject>() {
+
+ public EObject apply(Object from) {
+ return (EObject)from;
+ }
+ });
+
+ for(EObject currentEObject : list) {
+ matchingItemsToSelect.add(new ModelElementItemMatchingItem(currentEObject));
+
+ // the content provider exist?
+ if(commonViewer.getContentProvider() != null) {
+ // retrieve the ancestors to reveal them
+ // and allow the selection of the object
+ ArrayList<EObject> parents = new ArrayList<EObject>();
+ EObject tmp = currentEObject.eContainer();
+ while(tmp != null) {
+ parents.add(tmp);
+ tmp = tmp.eContainer();
+ }
+
+ Iterable<EObject> reverseParents = Iterables.reverse(parents);
+
+ // reveal the resource if necessary
+ Resource r = parents.get(parents.size() - 1).eResource();
+ if(r != null) {
+ commonViewer.expandToLevel(new ReferencableMatchingItem(r.getResourceSet()), 1);
+ commonViewer.expandToLevel(new ReferencableMatchingItem(r), 1);
+ }
+
+ /*
+ * reveal the ancestors tree using expandToLevel on each of them
+ * in the good order. This is a lot faster than going through the whole tree
+ * using getChildren of the ContentProvider since our Viewer uses a Hashtable
+ * to keep track of the revealed elements.
+ *
+ * However we need to use a dedicated MatchingItem to do the matching,
+ * and a specific comparer in our viewer so than the equals of MatchingItem is
+ * used in priority.
+ *
+ * Please refer to MatchingItem for more infos.
+ */
+ EObject previousParent = null;
+ for(EObject parent : reverseParents) {
+ if(parent.eContainingFeature() != null && previousParent != null) {
+ commonViewer.expandToLevel(new LinkItemMatchingItem(previousParent, parent.eContainmentFeature()), 1);
}
+ commonViewer.expandToLevel(new ModelElementItemMatchingItem(parent), 1);
+ previousParent = parent;
}
+ commonViewer.expandToLevel(new LinkItemMatchingItem(currentEObject.eContainer(), currentEObject.eContainmentFeature()), 1);
}
- selectReveal(new StructuredSelection(treeElementToSelect));
+ }
+
+ selectReveal(new StructuredSelection(matchingItemsToSelect), commonViewer);
+ }
+
+ /**
+ * Selects the given ISelection in the given CommonViwer
+ * @param structuredSelection The ISelection to select
+ * @param commonViewer The ComonViewer to select it in
+ */
+ public static void selectReveal(ISelection structuredSelection, Viewer commonViewer) {
+ commonViewer.setSelection(structuredSelection, true);
+ }
+
+ /**
+ * Selects and, if possible, reveals the given ISelection in the given CommonViwer
+ * @param selection The ISelection to select
+ * @param viewer The ComonViewer to select it in
+ */
+ public static void reveal(ISelection selection, CommonViewer viewer) {
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection structured = (IStructuredSelection)selection;
+ reveal(Lists.newArrayList(), viewer);
+ } else {
+ viewer.setSelection(selection);
}
}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java
index f8ec03b1e4f..cd5af93dc01 100644
--- a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/dialog/NavigatorSearchDialog.java
@@ -10,23 +10,32 @@
******************************************************************************/
package org.eclipse.papyrus.views.modelexplorer.dialog;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
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.views.modelexplorer.LinkNode;
+import org.eclipse.papyrus.views.modelexplorer.ModelExplorerView;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
@@ -41,6 +50,11 @@ import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.CommonViewer;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
/**
* A dialog that allows searching elements in the Model navigator by name.
@@ -61,6 +75,8 @@ public class NavigatorSearchDialog extends TrayDialog {
private List<Object> matchedObjects = Collections.emptyList();
+ protected int currentIndex = 0;
+
private Label matchesLabel;
private Text searchText;
@@ -74,7 +90,7 @@ public class NavigatorSearchDialog extends TrayDialog {
/**
*
* Constructor.
- *
+ *
* @param shell
* @param modelNavigator
* @deprecated Use {@link #NavigatorSearchDialog(Shell, TreeViewer)}
@@ -95,9 +111,10 @@ public class NavigatorSearchDialog extends TrayDialog {
/**
* Constructor.
- *
- * @param shell Shell used to show this Dialog
- * @param viewer
+ *
+ * @param shell
+ * Shell used to show this Dialog
+ * @param viewer
* @param contentProvider
* @param labelProvider
* @param root
@@ -145,9 +162,26 @@ public class NavigatorSearchDialog extends TrayDialog {
*/
private void fireSetSelection( ISelection selection, boolean reveal) {
// Note : if we want to force reveal, it is possible to check if
- // selectionProvider instanceof Viewer, and then call selectionProvider.setSelection(selection, true).
- // By default a TreeViewer reveal the selection.
- viewer.setSelection(selection);
+ // selectionProvider instanceof Viewer, and then call selectionProvider.setSelection(selection, true).
+ // By default a TreeViewer reveal the selection.
+ if(viewer instanceof CommonViewer) {
+ if(selection instanceof IStructuredSelection) {
+ IStructuredSelection structured = (IStructuredSelection)selection;
+ ModelExplorerView.reveal(Iterables.transform(Lists.newArrayList(structured.iterator()), new Function<Object, EObject>() {
+
+ public EObject apply(Object arg0) {
+ if(arg0 instanceof IAdaptable) {
+ IAdaptable adapt = (IAdaptable)arg0;
+ return getAdapter(adapt, EObject.class);
+ }
+ return null;
+ }
+ }), (CommonViewer)viewer);
+ }
+ } else if(viewer instanceof Viewer) {
+ Viewer view = (Viewer)viewer;
+ view.setSelection(selection, true);
+ }
}
/*
* (non-Javadoc)
@@ -196,18 +230,12 @@ public class NavigatorSearchDialog extends TrayDialog {
}
public void widgetSelected(SelectionEvent e) {
- ISelection sel = viewer.getSelection();
- if(!(sel instanceof StructuredSelection)) {
- return;
+ if(currentIndex >= matchedObjects.size() - 1) {
+ currentIndex = 0;
+ } else {
+ currentIndex++;
}
- StructuredSelection ssel = (StructuredSelection)sel;
-
- int index = matchedObjects.lastIndexOf(ssel.getFirstElement());
- if(index == matchedObjects.size() - 1) {
- index = -1;
- }
- index++;
- fireSetSelection(new StructuredSelection(matchedObjects.get(index)), true);
+ fireSetSelection(new StructuredSelection(matchedObjects.get(currentIndex)), true);
}
});
@@ -218,18 +246,12 @@ public class NavigatorSearchDialog extends TrayDialog {
}
public void widgetSelected(SelectionEvent e) {
- ISelection sel = viewer.getSelection();
- if(!(sel instanceof StructuredSelection)) {
- return;
+ if(currentIndex <= 0) {
+ currentIndex = matchedObjects.size() - 1;
+ } else {
+ currentIndex--;
}
- StructuredSelection ssel = (StructuredSelection)sel;
-
- int index = matchedObjects.lastIndexOf(ssel.getFirstElement());
- if(index == 0) {
- index = matchedObjects.size() - 1;
- }
- index--;
- fireSetSelection(new StructuredSelection(matchedObjects.get(index)), true);
+ fireSetSelection(new StructuredSelection(matchedObjects.get(currentIndex)), true);
}
});
@@ -247,8 +269,7 @@ public class NavigatorSearchDialog extends TrayDialog {
caseButton = new Button(background, SWT.CHECK);
caseButton.setText("Case sensitive?");
- GridData caseButtonData = new GridData(
- GridData.HORIZONTAL_ALIGN_BEGINNING);
+ GridData caseButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
caseButtonData.horizontalSpan = 2;
caseButton.setSelection(false);
caseButton.setLayoutData(caseButtonData);
@@ -274,6 +295,14 @@ public class NavigatorSearchDialog extends TrayDialog {
| GridData.FILL_HORIZONTAL));
}
+
+ protected void clearMatches() {
+ matchedObjects = Collections.emptyList();
+ currentIndex = 0;
+ backButton.setEnabled(false);
+ nextButton.setEnabled(false);
+ matchesLabel.setText("");
+ }
private void updateMatches() {
if(contentProvider == null && labelProvider == null) {
@@ -282,10 +311,7 @@ public class NavigatorSearchDialog extends TrayDialog {
String pattern = searchText.getText();
if(pattern.length() == 0) {
- matchedObjects = Collections.emptyList();
- backButton.setEnabled(false);
- nextButton.setEnabled(false);
- matchesLabel.setText("No matchings.");
+ clearMatches();
return;
}
@@ -293,8 +319,7 @@ public class NavigatorSearchDialog extends TrayDialog {
pattern = pattern.toUpperCase();
}
- matchedObjects = searchPattern(pattern, Arrays.asList(contentProvider
- .getElements(root)));
+ launchSearch(pattern, contentProvider.getElements(root));
// Update matches label
matchesLabel.setText(matchedObjects.size() + " matches found");
@@ -311,51 +336,86 @@ public class NavigatorSearchDialog extends TrayDialog {
}
- private List<Object> searchPattern(String pattern, List<Object> objects) {
+ protected void launchSearch(final String pattern, final Object[] root) {
+ final boolean caseSensitive = caseButton.getSelection();
+
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
+ try {
+ dialog.run(true, true, new IRunnableWithProgress() {
+
+ public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
+ matchedObjects = searchPattern(pattern, caseSensitive, Arrays.asList(root), monitor);
+ currentIndex = 0;
+ }
+ });
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private List<Object> searchPattern(String pattern, boolean caseSensitive, List<Object> objects, IProgressMonitor monitor) {
+ if(monitor.isCanceled()) {
+ return Collections.emptyList();
+ }
+
List<Object> matches = new ArrayList<Object>();
- List<Object> childs = new ArrayList<Object>();
+ List<Object> children = new ArrayList<Object>();
String objectLabel;
- boolean caseSensitive = caseButton.getSelection();
+
for(Object o : objects) {
// Search matches in this level
-// if(!(o instanceof Diagram)) {
- objectLabel = caseSensitive ? labelProvider.getText(o)
- : labelProvider.getText(o).toUpperCase();
+ if(!(o instanceof Diagram)) {
+ objectLabel = caseSensitive ? labelProvider.getText(o) : labelProvider.getText(o).toUpperCase();
if(objectLabel.contains(pattern)) {
matches.add(o);
}
-
- // Find childs
-
- EObject parentEObj = (EObject)((IAdaptable)o).getAdapter(EObject.class);
+ EObject parentEObj = (EObject)getAdapter(o, EObject.class);
for(int i = 0; i < contentProvider.getChildren(o).length; i++) {
Object child = contentProvider.getChildren(o)[i];
- if(child instanceof IAdaptable) {
+ //If child can be adapted into a LinkNode, find its referenced EObjects
+ if(getAdapter(child, LinkNode.class) != null) {
+ for(Object referencedObject : contentProvider.getChildren(child)) {
+ EObject referencedEObject = (EObject)((IAdaptable)referencedObject).getAdapter(EObject.class);
+ if(referencedEObject != null && (parentEObj == null || parentEObj.equals(referencedEObject.eContainer()))) {
+ children.add(referencedObject);
+ }
+ }
+ }
+ //If it is an EObject, add it to the list
+ else {
EObject eObject = (EObject)((IAdaptable)child).getAdapter(EObject.class);
-
- //doesn't work for facets (Diagram and table)
-// if(eObject != null && eObject.eContainer() != null && eObject.eContainer().equals(parentEObj)) {
-// childs.add(child);
-// }
-
- //to find diagrams, tables and others
- if(eObject!=null){
- childs.add(child);
+ if(eObject != null && eObject.eContainer() != null && (parentEObj == null || eObject.eContainer().equals(parentEObj))) {
+ children.add(child);
}
}
}
}
-// }
- if(!childs.isEmpty()) {
- matches.addAll(searchPattern(pattern, childs));
+ }
+ if(!children.isEmpty()) {
+ matches.addAll(searchPattern(pattern, caseSensitive, children, monitor));
}
return matches;
}
+ @SuppressWarnings("unchecked")
+ public <T> T getAdapter(Object object, Class<? extends T> toAdapt) {
+ T result = null;
+ if(object instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable)object;
+ result = (T)adaptable.getAdapter(toAdapt);
+ }
+ if(result == null) {
+ result = (T)Platform.getAdapterManager().getAdapter(object, toAdapt);
+ }
+ return result;
+ }
+
protected KeyListener getKeyListener() {
return new KeyListener() {
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/IMatchingItem.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/IMatchingItem.java
new file mode 100644
index 00000000000..81fb5d13965
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/IMatchingItem.java
@@ -0,0 +1,44 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos) mathieu.velten@atos.net - Initial API and implementation
+ * Philippe Roland (Atos) philippe.roland@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.matching;
+
+/**
+ * This interface is only useful to create a fake item
+ * to match an existing facet item in a facet viewer.
+ * To do that each implementation mimics the behavior of the equals and hashCode methods
+ * of the corresponding items.
+ *
+ * @author mvelten
+ * @author proland
+ *
+ */
+public interface IMatchingItem {
+
+ /**
+ * Mimics the corresponding class's equals method
+ *
+ * @param obj
+ * the object to match
+ * @return true if the match is successful
+ */
+ public boolean matchingItemEquals(Object obj);
+
+ /**
+ * Mimics the corresponding class's hashcode method
+ *
+ * @return the hashcode
+ */
+ public int matchingItemHashcode();
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/LinkItemMatchingItem.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/LinkItemMatchingItem.java
new file mode 100644
index 00000000000..a6e8223de46
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/LinkItemMatchingItem.java
@@ -0,0 +1,55 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos) mathieu.velten@atos.net - Initial API and implementation
+ * Philippe Roland (Atos) philippe.roland@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.matching;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.facet.infra.browser.uicore.internal.model.LinkItem;
+
+/***
+ * An IMatchingItem implementation that matches for LinkItems
+ *
+ * @author proland
+ */
+public class LinkItemMatchingItem implements IMatchingItem {
+
+ private EObject parent;
+
+ private EReference ref;
+
+ public LinkItemMatchingItem(EObject parent, EReference ref) {
+ this.parent = parent;
+ this.ref = ref;
+ }
+
+ public boolean matchingItemEquals(Object obj) {
+ if(obj instanceof LinkItem) {
+ if(ref != null && parent != null) {
+ return parent.equals(((LinkItem)obj).getParent()) && ref.equals(((LinkItem)obj).getReference());
+ }
+ }
+ return super.equals(obj);
+ }
+
+ public int matchingItemHashcode() {
+ if(ref != null && parent != null) {
+ final int hashPrime1 = 47;
+ final int hashPrime2 = 13;
+ return ref.hashCode() * hashPrime1 + parent.hashCode() + hashPrime2;
+ }
+ return 0;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/ModelElementItemMatchingItem.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/ModelElementItemMatchingItem.java
new file mode 100644
index 00000000000..d4b00750cf5
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/ModelElementItemMatchingItem.java
@@ -0,0 +1,47 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos) mathieu.velten@atos.net - Initial API and implementation
+ * Philippe Roland (Atos) philippe.roland@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.matching;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.facet.infra.browser.uicore.internal.model.ModelElementItem;
+
+/***
+ * An IMatchingItem implementation that matches for ModelElementItem
+ *
+ * @author proland
+ */
+public class ModelElementItemMatchingItem implements IMatchingItem {
+
+ EObject element;
+
+ public ModelElementItemMatchingItem(EObject currentEObject) {
+ this.element = currentEObject;
+ }
+
+ public boolean matchingItemEquals(Object obj) {
+ if(element != null && obj instanceof ModelElementItem) {
+ return element.equals(((ModelElementItem)obj).getEObject());
+ }
+ return super.equals(obj);
+ }
+
+ public int matchingItemHashcode() {
+ if(element != null) {
+ return element.hashCode();
+ }
+ return 0;
+ }
+
+}
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/ReferencableMatchingItem.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/ReferencableMatchingItem.java
new file mode 100644
index 00000000000..ba2bac40e9c
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/views/modelexplorer/matching/ReferencableMatchingItem.java
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * Copyright (c) 2011 Atos
+ *
+ *
+ * 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:
+ * Mathieu Velten (Atos) mathieu.velten@atos.net - Initial API and implementation
+ * Philippe Roland (Atos) philippe.roland@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.views.modelexplorer.matching;
+
+import org.eclipse.papyrus.views.modelexplorer.IReferencable;
+
+/***
+ * An IMatchingItem implementation that matches for IReferencables
+ * @author proland
+ */
+public class ReferencableMatchingItem implements IMatchingItem
+{
+ Object object;
+
+ public ReferencableMatchingItem(Object object)
+ {
+ this.object = object;
+ }
+
+ public boolean matchingItemEquals(Object obj)
+ {
+ if (obj instanceof IReferencable)
+ {
+ IReferencable referencable = (IReferencable) obj;
+ return referencable.getElementBehind().equals(object);
+ }
+ return super.equals(obj);
+ }
+
+ public int matchingItemHashcode()
+ {
+ if(object!=null) {
+ return object.hashCode();
+ }
+ return 0;
+ }
+
+}

Back to the top