Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/.classpath7
-rw-r--r--examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/.project28
-rw-r--r--examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/META-INF/MANIFEST.MF14
-rw-r--r--examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/build.properties5
-rw-r--r--examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/icons/ReportSelectedElementIcon.pngbin0 -> 3683 bytes
-rw-r--r--examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/plugin.properties12
-rw-r--r--examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/plugin.xml74
-rw-r--r--examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/src/org/eclipse/papyrus/example/infra/servicesregistry/retrieval/Activator.java50
-rw-r--r--examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/src/org/eclipse/papyrus/example/infra/servicesregistry/retrieval/menu/handlers/LookupServiceRegistryFromEObjectHandler.java249
9 files changed, 439 insertions, 0 deletions
diff --git a/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/.classpath b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/.classpath
new file mode 100644
index 00000000000..2d1a4302f04
--- /dev/null
+++ b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/.project b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/.project
new file mode 100644
index 00000000000..c1bfde361a9
--- /dev/null
+++ b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.papyrus.example.infra.servicesregistry.retrieval</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/META-INF/MANIFEST.MF b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..42b483ca6b9
--- /dev/null
+++ b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/META-INF/MANIFEST.MF
@@ -0,0 +1,14 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.papyrus.example.infra.servicesregistry.retrieval;singleton:=true
+Bundle-Version: 0.9.0.qualifier
+Bundle-Activator: org.eclipse.papyrus.example.infra.servicesregistry.retrieval.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.papyrus.infra.core;bundle-version="0.9.0",
+ org.eclipse.papyrus.infra.emf;bundle-version="0.9.0",
+ org.eclipse.emf;bundle-version="2.6.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-Vendor: %providerName
diff --git a/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/build.properties b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/build.properties
new file mode 100644
index 00000000000..6f20375d6c7
--- /dev/null
+++ b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/icons/ReportSelectedElementIcon.png b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/icons/ReportSelectedElementIcon.png
new file mode 100644
index 00000000000..6a55c438352
--- /dev/null
+++ b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/icons/ReportSelectedElementIcon.png
Binary files differ
diff --git a/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/plugin.properties b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/plugin.properties
new file mode 100644
index 00000000000..ea0330aedb8
--- /dev/null
+++ b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/plugin.properties
@@ -0,0 +1,12 @@
+#################################################################################
+# Copyright (c) 2012 Cedric Dumoulin.
+# 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:
+# Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+##################################################################################
+pluginName=Papyrus Services Registry Examples
+providerName=Eclipse Modeling Project
diff --git a/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/plugin.xml b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/plugin.xml
new file mode 100644
index 00000000000..c5958e71e55
--- /dev/null
+++ b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/plugin.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ description="Lookup the ServicesRegistry associated to an EObject"
+ id="org.eclipse.papyrus.example.infra.servicesregistry.retrieval.menu.commands.ShowServiceRegistryRetrievalCommand"
+ name="Lookup ServicesRegistry">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.papyrus.example.infra.servicesregistry.retrieval.menu.handlers.LookupServiceRegistryFromEObjectHandler"
+ commandId="org.eclipse.papyrus.example.infra.servicesregistry.retrieval.menu.commands.ShowServiceRegistryRetrievalCommand">
+ </handler>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ locationURI="toolbar:org.eclipse.ui.main.toolbar">
+ <toolbar
+ id="org.eclipse.papyrus.examples.ui.toolbar.examples">
+ <command
+ commandId="org.eclipse.papyrus.example.infra.servicesregistry.retrieval.menu.commands.ShowServiceRegistryRetrievalCommand"
+ icon="icons/ReportSelectedElementIcon.png"
+ label="Lookup ServicesRegistry"
+ style="push">
+ </command>
+ </toolbar>
+ </menuContribution>
+ <menuContribution
+ locationURI="menu:org.eclipse.papyrus.ui.menu">
+ <menu
+ id="org.eclipse.papyrus.example.ui.menu.examples"
+ label="Examples">
+ <command
+ commandId="org.eclipse.papyrus.example.infra.servicesregistry.retrieval.menu.commands.ShowServiceRegistryRetrievalCommand"
+ icon="icons/ReportSelectedElementIcon.png"
+ label="Lookup ServicesRegistry"
+ style="push">
+ </command>
+ </menu>
+ </menuContribution>
+ <menuContribution
+ locationURI="popup:org.eclipse.gmf.runtime.diagram.ui.DiagramEditorContextMenu">
+ <menu
+ id="org.eclipse.papyrus.example.ui.popupmenu.diagram.examples"
+ label="Examples">
+ <command
+ commandId="org.eclipse.papyrus.example.infra.servicesregistry.retrieval.menu.commands.ShowServiceRegistryRetrievalCommand"
+ icon="icons/ReportSelectedElementIcon.png"
+ label="Lookup ServicesRegistry"
+ style="push">
+ </command>
+ </menu>
+ </menuContribution>
+ <menuContribution
+ locationURI="popup:org.eclipse.papyrus.views.modelexplorer.modelexplorer.popup">
+ <menu
+ id="org.eclipse.papyrus.example.ui.popupmenu.modelexplorer.examples"
+ label="Examples">
+ <command
+ commandId="org.eclipse.papyrus.example.infra.servicesregistry.retrieval.menu.commands.ShowServiceRegistryRetrievalCommand"
+ icon="icons/ReportSelectedElementIcon.png"
+ label="Lookup ServicesRegistry"
+ style="push">
+ </command>
+ </menu>
+ </menuContribution>
+ </extension>
+
+</plugin>
diff --git a/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/src/org/eclipse/papyrus/example/infra/servicesregistry/retrieval/Activator.java b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/src/org/eclipse/papyrus/example/infra/servicesregistry/retrieval/Activator.java
new file mode 100644
index 00000000000..87648f0a19e
--- /dev/null
+++ b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/src/org/eclipse/papyrus/example/infra/servicesregistry/retrieval/Activator.java
@@ -0,0 +1,50 @@
+package org.eclipse.papyrus.example.infra.servicesregistry.retrieval;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.papyrus.example.infra.servicesregistry.retrieval"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/src/org/eclipse/papyrus/example/infra/servicesregistry/retrieval/menu/handlers/LookupServiceRegistryFromEObjectHandler.java b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/src/org/eclipse/papyrus/example/infra/servicesregistry/retrieval/menu/handlers/LookupServiceRegistryFromEObjectHandler.java
new file mode 100644
index 00000000000..db553033934
--- /dev/null
+++ b/examples/infra/org.eclipse.papyrus.example.infra.servicesregistry.retrieval/src/org/eclipse/papyrus/example/infra/servicesregistry/retrieval/menu/handlers/LookupServiceRegistryFromEObjectHandler.java
@@ -0,0 +1,249 @@
+/*****************************************************************************
+ * Copyright (c) 2012 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.example.infra.servicesregistry.retrieval.menu.handlers;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+
+/**
+ * A menu handler showing :
+ * <ul>
+ * <li>How to retrieve a UML element from any kind of selected object (using adapters)</li>
+ * <li>How to get the ServicesRegistry from an EObject</li>
+ * </ul>
+ *
+ * @author Cedric dumoulin
+ *
+ */
+public class LookupServiceRegistryFromEObjectHandler extends AbstractHandler implements IHandler {
+
+
+ /**
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ * @param event
+ * @return
+ * @throws ExecutionException
+ *
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+
+ List<EObject> selectedProperties = getAllSelectionAdaptedToType( event, EObject.class );
+ if( selectedProperties == null) {
+
+ showErrorDialog(event, "No object selected", "Please select a Property First.");
+ return null;
+ }
+
+
+ // Get the ServiceRegistry for each of the selected object
+ List<ServicesRegistry> res = new ArrayList<ServicesRegistry>();
+ for( EObject selected : selectedProperties) {
+
+ // Get the servicesRegistry
+ try {
+ ServicesRegistry registry = ServiceUtilsForResource.getInstance().getServiceRegistry(selected.eResource());
+ res.add(registry);
+ System.out.println(" - " + selected + " [" + registry + "]");
+ } catch (ServiceException e) {
+ // Not found
+ res.add(null);
+ System.out.println(" - " + selected + " [Can't get ServicesRegistry !!!]");
+ }
+ //
+
+ }
+
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+
+
+ showResults( window.getShell(), selectedProperties, res);
+
+ return null;
+ }
+
+ /**
+ * Show results in popup.
+ * @param selectedProperties
+ * @param res
+ */
+ private void showResults(Shell shell, List<EObject> selectedProperties, List<ServicesRegistry> res) {
+
+ StringBuffer buff = new StringBuffer();
+
+ Iterator<EObject> selectedIter = selectedProperties.iterator();
+ Iterator<ServicesRegistry> registryIter = res.iterator();
+ while(selectedIter.hasNext()) {
+ EObject selected = selectedIter.next();
+ ServicesRegistry registry = registryIter.next();
+
+ buff.append("\n[ServicesRegistry]\n");
+ if( registry != null )
+ buff.append(registry.toString());
+ else
+ buff.append("Registry not found !!!");
+ buff.append( "\n[EOBject]\n");
+ buff.append(selected.toString());
+ buff.append("\n");
+
+ }
+
+ String message = buff.toString();
+ MessageDialog.openInformation(shell, "ServicesRegistry found for selected objects:", message);
+ }
+
+ /**
+ * Get all selected element of the specified type.
+ *
+ * @param expectedType
+ * @return
+ * @throws ExecutionException
+ */
+ @SuppressWarnings("unchecked")
+ private <T> List<T> getAllSelectionAdaptedToType(ExecutionEvent event, Class<T> expectedType) throws ExecutionException {
+
+ // Get selection from the workbench
+ ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
+
+ // Get the selected objects according to the type of the selected
+ if(selection instanceof IStructuredSelection)
+ {
+ IStructuredSelection structuredSelection = (IStructuredSelection)selection;
+ return getAllElementAdaptedToType( structuredSelection.toList(), expectedType);
+ }
+ else if( selection instanceof TreeSelection) {
+ TreeSelection treeSelection = (TreeSelection)selection;
+ return getAllElementAdaptedToType( treeSelection.toList(), expectedType );
+
+ }
+ return null;
+ }
+
+ /**
+ * Filter the list, and only retain objects that can be adapted to the specified type
+ * @param objects
+ * @param class1
+ * @return
+ */
+ private <T> List<T> getAllElementAdaptedToType(List<Object> list, Class<T> expectedClassType) {
+
+ List<T> res = new ArrayList<T>();
+
+ for( Object cur : list) {
+
+ T adapted = adapt( cur, expectedClassType);
+ if( adapted != null)
+ res.add(adapted);
+ }
+ return res;
+ }
+
+ /**
+ * Adapt the specified object to the requested type, if possible.
+ * Return null if the object can't be adapted.
+ *
+ * @param object
+ * @param expectedClassType
+ * @return The adapted object, or null.
+ */
+ @SuppressWarnings("unchecked")
+ private <T> T adapt( Object object, Class<T> expectedClassType) {
+
+ if( object instanceof IAdaptable ) {
+ T ele = (T)((IAdaptable)object).getAdapter(expectedClassType);
+ if(ele != null) {
+ return ele;
+ }
+ // Try as EObject if the expectedClasType is sub-type of EObject.
+ if( EObject.class.isAssignableFrom( expectedClassType) ) {
+ // to EObject
+ EObject eobject = (EObject)((IAdaptable)object).getAdapter(EObject.class);
+
+ if(eobject != null && expectedClassType.isInstance(eobject)) {
+ return (T)eobject;
+ }
+ }
+ }
+
+ // Try global mechanism
+ {
+ T ele = (T)Platform.getAdapterManager().getAdapter(object, expectedClassType);
+ if(ele != null) {
+ return ele;
+ }
+ // Try as EObject if the expectedClasType is sub-type of EObject.
+ if( EObject.class.isAssignableFrom( expectedClassType) ) {
+ // to EObject
+ EObject eobject = (EObject)Platform.getAdapterManager().getAdapter(object, EObject.class);
+
+ if(eobject != null && expectedClassType.isInstance(eobject)) {
+
+ return (T)eobject;
+ }
+ }
+ }
+ // Can't be adapted
+ return null;
+
+ }
+
+
+ /**
+ *
+ * @param event
+ * @param errorMessage
+ * @throws ExecutionException
+ */
+ private void showErrorDialog(ExecutionEvent event, String title, String errorMessage) throws ExecutionException {
+ IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
+ MessageDialog.openError(
+ window.getShell(),
+ title,
+ errorMessage);
+ }
+
+
+ /**
+ * Get the name used in the {@link RecordingCommand}. This name will be visible in
+ * undo/redo.
+ *
+ * @return The command name to show.
+ */
+ public String getCommandName() {
+ return "Show ServiceRegistry";
+ }
+
+
+
+}

Back to the top