diff options
Diffstat (limited to 'examples')
11 files changed, 820 insertions, 0 deletions
diff --git a/examples/emf/org.eclipse.papyrus.outline.emftree/.classpath b/examples/emf/org.eclipse.papyrus.outline.emftree/.classpath new file mode 100644 index 00000000000..6e16b23d695 --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/examples/emf/org.eclipse.papyrus.outline.emftree/.project b/examples/emf/org.eclipse.papyrus.outline.emftree/.project new file mode 100644 index 00000000000..ded5f0f8e77 --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.papyrus.outline.emftree</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/emf/org.eclipse.papyrus.outline.emftree/META-INF/MANIFEST.MF b/examples/emf/org.eclipse.papyrus.outline.emftree/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..4a04fe4e954 --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0
+Require-Bundle: org.eclipse.papyrus.infra.core;bundle-version="0.9.0",
+ org.eclipse.emf.ecore.editor;bundle-version="2.5.0",
+ org.eclipse.uml2.uml.edit;bundle-version="3.0.0",
+ org.eclipse.core.runtime;bundle-version="3.7.0",
+ org.eclipse.emf.transaction;bundle-version="1.4.0"
+Export-Package: org.eclipse.papyrus.outline.emftree,
+ org.eclipse.papyrus.outline.emftree.internal;x-internal:=true
+Bundle-Vendor: %providerName
+Bundle-ActivationPolicy: lazy
+Bundle-Version: 0.9.0.qualifier
+Bundle-Localization: plugin
+Bundle-Name: %pluginName
+Bundle-ManifestVersion: 2
+Bundle-Activator: org.eclipse.papyrus.outline.emftree.Activator
+Bundle-SymbolicName: org.eclipse.papyrus.outline.emftree;singleton:=tr
+ ue
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+
diff --git a/examples/emf/org.eclipse.papyrus.outline.emftree/about.html b/examples/emf/org.eclipse.papyrus.outline.emftree/about.html new file mode 100644 index 00000000000..82d49bf5f81 --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/about.html @@ -0,0 +1,28 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 5, 2007</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org/">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
diff --git a/examples/emf/org.eclipse.papyrus.outline.emftree/build.properties b/examples/emf/org.eclipse.papyrus.outline.emftree/build.properties new file mode 100644 index 00000000000..c2ddea76617 --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/build.properties @@ -0,0 +1,7 @@ +#
+#Mon Sep 12 09:30:00 CEST 2011
+bin.includes=META-INF/,.,plugin.xml,about.html,plugin.properties
+output..=bin/
+src.includes=about.html,META-INF/,.,plugin.xml,plugin.properties
+source..=src/
+bin..=bin/
diff --git a/examples/emf/org.eclipse.papyrus.outline.emftree/plugin.properties b/examples/emf/org.eclipse.papyrus.outline.emftree/plugin.properties new file mode 100644 index 00000000000..99741782bce --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/plugin.properties @@ -0,0 +1,12 @@ +###############################################################################
+# * Copyright (c) 2008 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:
+# * CEA LIST - initial API and implementation
+###############################################################################
+pluginName=Papyrus Outline (Incubation)
+providerName=Eclipse Modeling Project
diff --git a/examples/emf/org.eclipse.papyrus.outline.emftree/plugin.xml b/examples/emf/org.eclipse.papyrus.outline.emftree/plugin.xml new file mode 100644 index 00000000000..add958c9cbb --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/plugin.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.papyrus.infra.core.papyrusContentOutline">
+ <contentoutline
+ class="org.eclipse.papyrus.outline.emftree.ContentOutline"
+ priority="1">
+ </contentoutline>
+ </extension>
+
+</plugin>
diff --git a/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/Activator.java b/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/Activator.java new file mode 100644 index 00000000000..bf4b2708f87 --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/Activator.java @@ -0,0 +1,65 @@ +/*****************************************************************************
+ * Copyright (c) 2008 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:
+ * Cedric Dumoulin Cedric.Dumoulin@lifl.fr- Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.outline.emftree;
+
+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.outline.emftree";
+
+ // 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/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/ContentOutline.java b/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/ContentOutline.java new file mode 100644 index 00000000000..065c5691c2e --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/ContentOutline.java @@ -0,0 +1,255 @@ +/*****************************************************************************
+ * Copyright (c) 2008 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:
+ * Cedric Dumoulin Cedric.Dumoulin@lifl.fr- Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.outline.emftree;
+
+import org.eclipse.emf.ecore.provider.EcoreItemProviderAdapterFactory;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
+import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
+import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
+import org.eclipse.emf.edit.ui.action.EditingDomainActionBarContributor;
+import org.eclipse.emf.edit.ui.dnd.EditingDomainViewerDropAdapter;
+import org.eclipse.emf.edit.ui.dnd.LocalTransfer;
+import org.eclipse.emf.edit.ui.dnd.ViewerDragAdapter;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
+import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
+import org.eclipse.emf.edit.ui.provider.UnwrappingSelectionProvider;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IStatusLineManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.papyrus.infra.core.contentoutline.IPapyrusContentOutlinePage;
+import org.eclipse.papyrus.infra.core.editor.BackboneException;
+import org.eclipse.papyrus.infra.core.editor.IMultiDiagramEditor;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.outline.emftree.internal.OutlineDragAdapter;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.part.EditorActionBarContributor;
+import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
+import org.eclipse.uml2.uml.edit.providers.UMLItemProviderAdapterFactory;
+
+/**
+ * A Content outline based on the one generated from the DI2 metamodel. This ContentOutlinePage can
+ * be used by the multi editor page.
+ *
+ * @author dumoulin
+ *
+ */
+public class ContentOutline extends ContentOutlinePage implements IMenuListener, IPapyrusContentOutlinePage {
+
+ /**
+ * This keeps track of the editing domain that is used to track all changes to the model. <!--
+ * begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ protected EditingDomain editingDomain;
+
+ /**
+ * This is the one adapter factory used for providing views of the model. <!-- begin-user-doc
+ * --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ protected ComposedAdapterFactory adapterFactory;
+
+ /**
+ * This is the content outline page's viewer. <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ protected TreeViewer contentOutlineViewer;
+
+ private IEditorSite editorSite;
+
+ public ContentOutline() {
+ super();
+ };
+
+ /**
+ * Constructor.
+ *
+ * @param editorSite
+ * @param editingDomain
+ * @param adapterFactory
+ */
+ public ContentOutline(IEditorSite editorSite, EditingDomain editingDomain, ComposedAdapterFactory adapterFactory) {
+ super();
+ this.editorSite = editorSite;
+ this.editingDomain = editingDomain;
+ this.adapterFactory = adapterFactory;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param editorSite
+ * @param editingDomain
+ * @param adapterFactory
+ */
+ public ContentOutline(IEditorSite editorSite, EditingDomain editingDomain) {
+ super();
+ this.editorSite = editorSite;
+ this.editingDomain = editingDomain;
+ initAdapterFactory();
+ }
+
+ /**
+ * Init the outline. This method is used by the MultiPageEditor to initialize the Outline.
+ *
+ * @param multiEditor
+ * @param site
+ * @throws BackboneException
+ */
+ public void init(IMultiDiagramEditor multiEditor) throws BackboneException {
+
+ // Get the EditorActionBarContributor requested by this particular EMF editor.
+ // The EditorActionBarContributor should be registered in extensions under the specified name
+ // String EditorActionBarContributorId = "DiActionBarContributor";
+ // EditorActionBarContributor actionBarContributor = multiEditor.getActionBarContributorRegistry().getActionBarContributor(EditorActionBarContributorId);
+ // IEditorSite site = new MultiPageAdapterSite(multiEditor.getEditorSite(), actionBarContributor);
+ this.editorSite = multiEditor.getEditorSite();
+ try {
+ this.editingDomain = multiEditor.getServicesRegistry().getService(TransactionalEditingDomain.class);
+ } catch (ServiceException e) {
+ throw new BackboneException("Can't get TransactionalEditingDomain", e);
+ }
+ initAdapterFactory();
+
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ super.createControl(parent);
+ contentOutlineViewer = getTreeViewer();
+ contentOutlineViewer.addSelectionChangedListener(this);
+
+ // Set up the tree viewer.
+ //
+ contentOutlineViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
+ contentOutlineViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
+ contentOutlineViewer.setInput(editingDomain.getResourceSet());
+
+ // Make sure our popups work.
+ //
+ createContextMenuFor(contentOutlineViewer);
+
+ if(!editingDomain.getResourceSet().getResources().isEmpty()) {
+ // Select the root object in the view.
+ //
+ contentOutlineViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
+ }
+ // initDragAndDrop();
+ }
+
+ /**
+ * Add drag and drop ability between the outline to the editor.
+ */
+ protected void initDragAndDrop() {
+ int ops = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
+ // Enable Drag
+ OutlineDragAdapter dragAdapter = new OutlineDragAdapter(contentOutlineViewer);
+ contentOutlineViewer.addDragSupport(ops, dragAdapter.getSupportedDragTransfers(), dragAdapter);
+ }
+
+ @Override
+ public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager, IStatusLineManager statusLineManager) {
+ super.makeContributions(menuManager, toolBarManager, statusLineManager);
+ // contentOutlineStatusLineManager = statusLineManager;
+ }
+
+ @Override
+ public void setActionBars(IActionBars actionBars) {
+ super.setActionBars(actionBars);
+ if(getActionBarContributor() != null) {
+ getActionBarContributor().shareGlobalActions(this, actionBars);
+ }
+ }
+
+ private EditingDomainActionBarContributor getActionBarContributor() {
+ if(editorSite.getActionBarContributor() instanceof EditingDomainActionBarContributor) {
+ return (EditingDomainActionBarContributor)editorSite.getActionBarContributor();
+ }
+ return null;
+ }
+
+ /**
+ * This creates a context menu for the viewer and adds a listener as well registering the menu
+ * for extension. <!-- begin-user-doc --> <!-- end-user-doc -->
+ *
+ * @generated
+ */
+ private void createContextMenuFor(StructuredViewer viewer) {
+ MenuManager contextMenu = new MenuManager("#PopUp");
+ contextMenu.add(new Separator("additions"));
+ contextMenu.setRemoveAllWhenShown(true);
+ contextMenu.addMenuListener(this);
+ Menu menu = contextMenu.createContextMenu(viewer.getControl());
+ viewer.getControl().setMenu(menu);
+ getEditorSite().registerContextMenu(contextMenu, new UnwrappingSelectionProvider(viewer));
+
+ int dndOperations = DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK;
+ Transfer[] transfers = new Transfer[]{ LocalTransfer.getInstance() };
+ viewer.addDragSupport(dndOperations, transfers, new ViewerDragAdapter(viewer));
+ viewer.addDropSupport(dndOperations, transfers, new EditingDomainViewerDropAdapter(editingDomain, viewer));
+
+ }
+
+ /**
+ * This implements {@link org.eclipse.jface.action.IMenuListener} to help fill the context menus
+ * with contributions from the Edit menu. <!-- begin-user-doc --> <!-- end-user-doc -->
+ */
+ public void menuAboutToShow(IMenuManager menuManager) {
+ ((IMenuListener)getEditorSite().getActionBarContributor()).menuAboutToShow(menuManager);
+ }
+
+ /**
+ * <!-- begin-user-doc --> <!-- end-user-doc -->
+ */
+ // private EditingDomainActionBarContributor getActionBarContributor() {
+ // return (EditingDomainActionBarContributor)getEditorSite().getActionBarContributor();
+ // }
+ /**
+ *
+ * @return
+ */
+ private IEditorSite getEditorSite() {
+ return editorSite;
+ }
+
+ /**
+ *
+ */
+ private void initAdapterFactory() {
+ adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
+
+ adapterFactory.addAdapterFactory(new ResourceItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new EcoreItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new UMLItemProviderAdapterFactory());
+ adapterFactory.addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
+
+ }
+
+}
diff --git a/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/MultiPageAdapterSite.java b/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/MultiPageAdapterSite.java new file mode 100644 index 00000000000..175fb22796b --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/MultiPageAdapterSite.java @@ -0,0 +1,260 @@ +/**
+ *
+ */
+package org.eclipse.papyrus.outline.emftree;
+
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorActionBarContributor;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IKeyBindingService;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.internal.services.INestable;
+import org.eclipse.ui.part.EditorActionBarContributor;
+
+/**
+ * A site made of a main site and another ActionarContributor.
+ *
+ * @author dumoulin
+ *
+ */
+public class MultiPageAdapterSite implements IEditorSite, INestable {
+
+ /**
+ * The actionBarContributor to use instead of the one in the site.
+ */
+ private EditorActionBarContributor actionBarContributor;
+
+ /**
+ * The site to which methods delegate.
+ */
+ private IEditorSite site;
+
+ /**
+ * Constructor.
+ *
+ * @param workbenchPartSite
+ * @param actionBarContributor
+ */
+ public MultiPageAdapterSite(IEditorSite site, EditorActionBarContributor actionBarContributor) {
+ super();
+ this.site = site;
+ this.actionBarContributor = actionBarContributor;
+ }
+
+ /**
+ * @see org.eclipse.ui.IEditorSite#getActionBarContributor()
+ * @return
+ *
+ */
+ public IEditorActionBarContributor getActionBarContributor() {
+
+ return actionBarContributor;
+ }
+
+ /**
+ * @see org.eclipse.ui.IEditorSite#getActionBars()
+ * @return
+ *
+ */
+ public IActionBars getActionBars() {
+ return site.getActionBars();
+ }
+
+ /**
+ * @see org.eclipse.ui.IEditorSite#registerContextMenu(org.eclipse.jface.action.MenuManager, org.eclipse.jface.viewers.ISelectionProvider,
+ * boolean)
+ * @param menuManager
+ * @param selectionProvider
+ * @param includeEditorInput
+ *
+ */
+ public void registerContextMenu(MenuManager menuManager, ISelectionProvider selectionProvider, boolean includeEditorInput) {
+ site.registerContextMenu(menuManager, selectionProvider, includeEditorInput);
+ }
+
+ /**
+ * @see org.eclipse.ui.IEditorSite#registerContextMenu(java.lang.String, org.eclipse.jface.action.MenuManager,
+ * org.eclipse.jface.viewers.ISelectionProvider, boolean)
+ * @param menuId
+ * @param menuManager
+ * @param selectionProvider
+ * @param includeEditorInput
+ *
+ */
+ public void registerContextMenu(String menuId, MenuManager menuManager, ISelectionProvider selectionProvider, boolean includeEditorInput) {
+ site.registerContextMenu(menuId, menuManager, selectionProvider, includeEditorInput);
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getId()
+ * @return
+ *
+ */
+ public String getId() {
+ return site.getId();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getKeyBindingService()
+ * @return
+ * @deprecated
+ *
+ */
+ public IKeyBindingService getKeyBindingService() {
+ return site.getKeyBindingService();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getPart()
+ * @return
+ *
+ */
+ public IWorkbenchPart getPart() {
+ return site.getPart();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getPluginId()
+ * @return
+ *
+ */
+ public String getPluginId() {
+ return site.getPluginId();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#getRegisteredName()
+ * @return
+ *
+ */
+ public String getRegisteredName() {
+ return site.getRegisteredName();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#registerContextMenu(org.eclipse.jface.action.MenuManager, org.eclipse.jface.viewers.ISelectionProvider)
+ * @param menuManager
+ * @param selectionProvider
+ *
+ */
+ public void registerContextMenu(MenuManager menuManager, ISelectionProvider selectionProvider) {
+ site.registerContextMenu(menuManager, selectionProvider);
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchPartSite#registerContextMenu(java.lang.String, org.eclipse.jface.action.MenuManager,
+ * org.eclipse.jface.viewers.ISelectionProvider)
+ * @param menuId
+ * @param menuManager
+ * @param selectionProvider
+ *
+ */
+ public void registerContextMenu(String menuId, MenuManager menuManager, ISelectionProvider selectionProvider) {
+ site.registerContextMenu(menuId, menuManager, selectionProvider);
+
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchSite#getPage()
+ * @return
+ *
+ */
+ public IWorkbenchPage getPage() {
+ return site.getPage();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchSite#getSelectionProvider()
+ * @return
+ *
+ */
+ public ISelectionProvider getSelectionProvider() {
+ return site.getSelectionProvider();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchSite#getShell()
+ * @return
+ *
+ */
+ public Shell getShell() {
+ return site.getShell();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchSite#getWorkbenchWindow()
+ * @return
+ *
+ */
+ public IWorkbenchWindow getWorkbenchWindow() {
+ return site.getWorkbenchWindow();
+ }
+
+ /**
+ * @see org.eclipse.ui.IWorkbenchSite#setSelectionProvider(org.eclipse.jface.viewers.ISelectionProvider)
+ * @param provider
+ *
+ */
+ public void setSelectionProvider(ISelectionProvider provider) {
+ site.setSelectionProvider(provider);
+
+ }
+
+ /**
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ * @param adapter
+ * @return
+ *
+ */
+ public Object getAdapter(Class adapter) {
+ return site.getAdapter(adapter);
+ }
+
+ /**
+ * @see org.eclipse.ui.services.IServiceLocator#getService(java.lang.Class)
+ * @param api
+ * @return
+ *
+ */
+ public Object getService(Class api) {
+ return site.getService(api);
+ }
+
+ /**
+ * @see org.eclipse.ui.services.IServiceLocator#hasService(java.lang.Class)
+ * @param api
+ * @return
+ *
+ */
+ public boolean hasService(Class api) {
+ return site.hasService(api);
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.internal.services.INestable#activate()
+ *
+ */
+ public void activate() {
+ if(site instanceof INestable)
+ ((INestable)site).activate();
+ }
+
+ /**
+ *
+ * @see org.eclipse.ui.internal.services.INestable#deactivate()
+ *
+ */
+ public void deactivate() {
+ if(site instanceof INestable)
+ ((INestable)site).deactivate();
+ }
+
+}
diff --git a/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/internal/OutlineDragAdapter.java b/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/internal/OutlineDragAdapter.java new file mode 100644 index 00000000000..bd3a2ee9c8d --- /dev/null +++ b/examples/emf/org.eclipse.papyrus.outline.emftree/src/org/eclipse/papyrus/outline/emftree/internal/OutlineDragAdapter.java @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2008 Obeo. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.papyrus.outline.emftree.internal; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.provider.IWrapperItemProvider; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.papyrus.infra.core.utils.PapyrusTrace; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; +import org.eclipse.swt.dnd.Transfer; + +/** + * This Adapter listens to dragging operations and fill or clean the clipboard with filtered datas. <br> + * + * @author <a href="mailto:jerome.benois@obeo.fr">Jerome Benois</a> + */ +// This class is inspired from EcoreTools source code +public class OutlineDragAdapter implements DragSourceListener { + + private final ISelectionProvider selectionProvider; + + /** + * Constructs a new drag adapter. + * + * @param provider + * the object that provide the selected object + */ + public OutlineDragAdapter(ISelectionProvider provider) { + selectionProvider = provider; + } + + /** + * Return the available Transfer + * + * @return Transfer[] + */ + public Transfer[] getSupportedDragTransfers() { + Set<Transfer> supportedTypes = new LinkedHashSet<Transfer>(); + supportedTypes.add(LocalSelectionTransfer.getTransfer()); + Transfer[] transfers = supportedTypes.toArray(new Transfer[supportedTypes.size()]); + return transfers; + } + + /** + * Erase data from the clipboard object + * + * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd.DragSourceEvent) + */ + public void dragFinished(DragSourceEvent event) { + LocalSelectionTransfer.getTransfer().setSelection(null); + } + + /** + * @see org.eclipse.swt.dnd.DragSourceAdapter#dragSetData(org.eclipse.swt.dnd.DragSourceEvent) + */ + public void dragSetData(DragSourceEvent event) { + ISelection selection = LocalSelectionTransfer.getTransfer().getSelection(); + if(LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) { + event.data = selection; + } else { + event.doit = false; + } + } + + /** + * Put selection on the clipboard object + * + * @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.DragSourceEvent) + */ + public void dragStart(DragSourceEvent event) { + try { + ISelection selection = getSelection(); + if(!selection.isEmpty()) { + LocalSelectionTransfer.getTransfer().setSelection(selection); + event.doit = true; + event.data = getSelection(); + } else { + event.doit = false; + } + + } catch (RuntimeException e) { + PapyrusTrace.log(e); + } + } + + /** + * Compute the outline selection : filter on selection, only model elements (displayed as + * GraphNode) can be dragged. + * + * @return the list of selected model elements + */ + protected IStructuredSelection getSelection() { + IStructuredSelection selection = (IStructuredSelection)selectionProvider.getSelection(); + List<Object> transferData = new ArrayList<Object>(); + Iterator<?> it = selection.iterator(); + while(it.hasNext()) { + Object sel = it.next(); + // Ignore diagram objects + if((sel instanceof IWrapperItemProvider || sel instanceof FeatureMap.Entry || sel instanceof EObject) /* && !(sel instanceof View) */) { + transferData.add(AdapterFactoryEditingDomain.unwrap(sel)); + } + } + return new StructuredSelection(transferData); + } + +} |