Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2014-02-07 08:43:30 -0500
committervlorenzo2014-02-07 08:43:30 -0500
commit3570ba374e4b733ada1d83edc288e8ed199b6e37 (patch)
tree7bcdc1586c8fa23859e81a9a8ac91eb8cd1b1ea1 /plugins
parent7e7ba26a846e15b4692bd3cb2aeb147241a66c0a (diff)
downloadorg.eclipse.papyrus-3570ba374e4b733ada1d83edc288e8ed199b6e37.tar.gz
org.eclipse.papyrus-3570ba374e4b733ada1d83edc288e8ed199b6e37.tar.xz
org.eclipse.papyrus-3570ba374e4b733ada1d83edc288e8ed199b6e37.zip
425725: [Hyperlinks] Cannot create hyperlink to diagram in different
model/project https://bugs.eclipse.org/bugs/show_bug.cgi?id=425725 - Allow to link views from others model - The views are shown only once
Diffstat (limited to 'plugins')
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/EditorLookForEditorShell.java98
-rw-r--r--plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/util/EditorListContentProvider.java79
2 files changed, 158 insertions, 19 deletions
diff --git a/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/EditorLookForEditorShell.java b/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/EditorLookForEditorShell.java
index 3478ecd4af6..d1faf01e192 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/EditorLookForEditorShell.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/ui/EditorLookForEditorShell.java
@@ -13,10 +13,12 @@
*****************************************************************************/
package org.eclipse.papyrus.infra.hyperlink.ui;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
@@ -33,9 +35,12 @@ import org.eclipse.papyrus.commands.CreationCommandRegistry;
import org.eclipse.papyrus.commands.ICreationCommand;
import org.eclipse.papyrus.commands.ICreationCommandRegistry;
import org.eclipse.papyrus.infra.core.editorsfactory.IPageIconsRegistry;
+import org.eclipse.papyrus.infra.core.editorsfactory.PageModelFactoryRegistry;
import org.eclipse.papyrus.infra.core.extension.NotFoundException;
+import org.eclipse.papyrus.infra.core.extension.diagrameditor.PluggableEditorFactoryReader;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.emf.providers.MoDiscoContentProvider;
@@ -53,7 +58,6 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
-
//TODO: Refactor. Remove the diagram creation listener, and use a Dialog (Which is blocker) instead of a Shell
public class EditorLookForEditorShell extends AbstractLookForEditorShell {
@@ -73,6 +77,11 @@ public class EditorLookForEditorShell extends AbstractLookForEditorShell {
}
/**
+ * This factory is used to know if represent a valid editor or not
+ */
+ private PageModelFactoryRegistry pageFactory = null;
+
+ /**
* Sets the selected editor
*
* @param selectedEditor
@@ -229,10 +238,45 @@ public class EditorLookForEditorShell extends AbstractLookForEditorShell {
}
treeViewer.setLabelProvider(labelProvider);
- // treeViewer.setContentProvider(new CustomAdapterFactoryContentProvider(adapterFactory));
- // treeViewer.setContentProvider(new SemanticEMFContentProvider(amodel)); //This content provider will only display the selected element, instead of the root element
- treeViewer.setContentProvider(new MoDiscoContentProvider()); //FIXME: Use a standard, non-deprecated content provider.
- //treeViewer.setInput(model.eResource());
+ // treeViewer.setContentProvider(new
+ // CustomAdapterFactoryContentProvider(adapterFactory));
+ // treeViewer.setContentProvider(new
+ // SemanticEMFContentProvider(amodel)); //This content provider will
+ // only display the selected element, instead of the root element
+ // FIXME: Use a standard, non-deprecated content
+ treeViewer.setContentProvider(new MoDiscoContentProvider() {
+
+ @Override
+ public boolean hasChildren(Object element) {
+ return super.getChildren(element).length > 0;
+ }
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.emf.providers.MoDiscoContentProvider#getChildren(java.lang.Object)
+ *
+ * @param parentElement
+ * @return
+ */
+ //in some case we return diagram twice!
+ //TODO the best correction we be able to manage applied facet, because if we get diagram twice it is probably because there are 2 facets with the same behavior applied
+ @Override
+ public Object[] getChildren(Object parentElement) {
+ List<Object> alreadyVisited = new ArrayList<Object>();
+ List<Object> returnedChildren = new ArrayList<Object>();
+ Object[] children = super.getChildren(parentElement);
+ for(Object current : children) {
+ if(current instanceof IAdaptable) {
+ EObject el = (EObject)((IAdaptable)current).getAdapter(EObject.class);
+ if(!alreadyVisited.contains(el)) {
+ returnedChildren.add(current);
+ alreadyVisited.add(el);
+ }
+ }
+ }
+ return returnedChildren.toArray();
+ }
+ });
+ // treeViewer.setInput(model.eResource());
treeViewer.setInput(registry);
// install diagramlist
@@ -246,8 +290,7 @@ public class EditorLookForEditorShell extends AbstractLookForEditorShell {
//we can't reuse the same instance of the label provider see bug 385599: [Hyperlink] We can't select the diagram/table for referencing them
diagramListTreeViewer.setLabelProvider(labelProvider);
-
- diagramListTreeViewer.setContentProvider(new EditorListContentProvider(model));
+ diagramListTreeViewer.setContentProvider(new EditorListContentProvider(model, getPageModelFactoryRegistry()));
diagramListTreeViewer.setInput(""); //$NON-NLS-1$
// add listner on the new button to display menu for each diagram
@@ -395,14 +438,45 @@ public class EditorLookForEditorShell extends AbstractLookForEditorShell {
if(!(object instanceof EObject)) {
return false;
}
-
- EObject eObject = (EObject)object;
-
+ EObject eobject = (EObject)object;
try {
- return ServiceUtilsForEObject.getInstance().getIPageMngr(eObject).allPages().contains(object);
+ final IPageManager pageMng = ServiceUtilsForEObject.getInstance().getIPageManager(eobject);
+ if(pageMng.allPages().contains(eobject)) {
+ return true;
+ }
} catch (ServiceException ex) {
- return false;
+ //nothing to do
+ }
+
+ //if we are here, there are 2 cases :
+ //1. the object is a valid editor but it is not in the page manager (imported file probably)
+ //2. or the object is not a valid editor
+ IPageModel pageModel = getPageModelFactoryRegistry().createIPageModel(eobject);
+ if(pageModel != null) {
+ pageModel = null;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ *
+ * @return
+ * returns the page model factory
+ */
+ protected PageModelFactoryRegistry getPageModelFactoryRegistry() {
+ if(this.pageFactory == null) {
+ this.pageFactory = new PageModelFactoryRegistry();
+ final PluggableEditorFactoryReader editorReader = new PluggableEditorFactoryReader(org.eclipse.papyrus.infra.core.Activator.PLUGIN_ID);
+ ServicesRegistry reg = null;
+ try {
+ reg = ServiceUtilsForEObject.getInstance().getServiceRegistry(model);
+ editorReader.populate(pageFactory, reg);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
}
+ return this.pageFactory;
}
}
diff --git a/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/util/EditorListContentProvider.java b/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/util/EditorListContentProvider.java
index b7603596d8f..1ee66c8b3f8 100644
--- a/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/util/EditorListContentProvider.java
+++ b/plugins/infra/org.eclipse.papyrus.infra.hyperlink/src/org/eclipse/papyrus/infra/hyperlink/util/EditorListContentProvider.java
@@ -17,9 +17,13 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
+import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageModel;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IPageModelFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
import org.eclipse.papyrus.infra.hyperlink.Activator;
@@ -33,10 +37,33 @@ public class EditorListContentProvider implements ITreeContentProvider {
//The context of the ContentProvider
private EObject model;
+ @Deprecated
+ // since february 2014
public EditorListContentProvider(EObject model) {
+ this(model, null);
+ }
+
+ /**
+ * This factory is used to know if represent a valid editor or not
+ */
+ private IPageModelFactory pageFactory;
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param model
+ * the model
+ * @param pageModelFactory
+ * the page factory used to know is an object can be a page or not
+ */
+ public EditorListContentProvider(EObject model, IPageModelFactory pageModelFactory) {
this.model = model;
+ this.pageFactory = pageModelFactory;
}
+
/**
* {@inheritDoc}
*/
@@ -63,14 +90,25 @@ public class EditorListContentProvider implements ITreeContentProvider {
*/
public Object[] getElements(Object inputElement) {
try {
- IPageManager iPageMngr = ServiceUtilsForEObject.getInstance().getIPageManager(model);
- Object[] result = iPageMngr.allPages().toArray();
-
List<Object> res = new ArrayList<Object>();
- for(Object current : result) {
- if(current != null /* && current instanceof PapyrusTableInstance */) {
- // if the model is a little bit corrupted, we can have a null element in the list
- res.add(current);
+ if(pageFactory == null) {
+ IPageManager iPageMngr = ServiceUtilsForEObject.getInstance().getIPageManager(model);
+ Object[] result = iPageMngr.allPages().toArray();
+
+
+ for(Object current : result) {
+ if(current != null /* && current instanceof PapyrusTableInstance */) {
+ // if the model is a little bit corrupted, we can have a null element in the list
+ res.add(current);
+ }
+ }
+ } else {
+ for(final Resource current : model.eResource().getResourceSet().getResources()) {
+ for(final Object object : current.getContents()) {
+ if(isAValidEditor(object)) {
+ res.add(object);
+ }
+ }
}
}
return res.toArray();
@@ -81,6 +119,33 @@ public class EditorListContentProvider implements ITreeContentProvider {
return null;
}
+ //duplicated code from EditorLookForEditorShell
+ private boolean isAValidEditor(final Object object) {
+ if(!(object instanceof EObject)) {
+ return false;
+ }
+ EObject eobject = (EObject)object;
+ try {
+ final IPageManager pageMng = ServiceUtilsForEObject.getInstance().getIPageManager(eobject);
+ if(pageMng.allPages().contains(eobject)) {
+ return true;
+ }
+ } catch (ServiceException ex) {
+ //nothing to do
+ }
+
+ //if we are here, there are 2 cases :
+ //1. the object is a valid editor but it is not in the page manager (imported file probably)
+ //2. or the object is not a valid editor
+ IPageModel pageModel = this.pageFactory.createIPageModel(eobject);
+ if(pageModel != null) {
+ pageModel = null;
+ return true;
+ }
+ return false;
+ }
+
+
/**
* {@inheritDoc}
*/

Back to the top