diff options
| author | dsciamma | 2007-11-07 15:14:49 +0000 |
|---|---|---|
| committer | dsciamma | 2007-11-07 15:14:49 +0000 |
| commit | d9341623636d9443baa7d269b64655ffedf09b81 (patch) | |
| tree | c9249847ca05ace06695000fba8ced3378caf615 | |
| parent | c1b36cd32007882356de08a69febedb1d3c0662a (diff) | |
| download | org.eclipse.ecoretools-d9341623636d9443baa7d269b64655ffedf09b81.tar.gz org.eclipse.ecoretools-d9341623636d9443baa7d269b64655ffedf09b81.tar.xz org.eclipse.ecoretools-d9341623636d9443baa7d269b64655ffedf09b81.zip | |
Initial contribution
20 files changed, 2080 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/.classpath b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/.classpath new file mode 100644 index 0000000..751c8f2 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/.project b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/.project new file mode 100644 index 0000000..01fe211 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.gmf.runtime.diagram.ui.outline</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/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/META-INF/MANIFEST.MF b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/META-INF/MANIFEST.MF new file mode 100644 index 0000000..655025f --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %pluginName (Incubation) +Bundle-SymbolicName: org.eclipse.gmf.runtime.diagram.ui.outline +Bundle-Version: 0.8.0.qualifier +Bundle-Activator: org.eclipse.gmf.runtime.diagram.ui.outline.internal.Activator +Bundle-Vendor: %providerName +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.gmf.runtime.notation, + org.eclipse.emf.ecore, + org.eclipse.gef, + org.eclipse.gmf.runtime.diagram.ui, + org.eclipse.emf.edit.ui +Eclipse-LazyStart: true +Export-Package: org.eclipse.gmf.runtime.diagram.ui.outline, + org.eclipse.gmf.runtime.diagram.ui.outline.internal;x-internal:=true +Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Bundle-ClassPath: . diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/about.html b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/about.html new file mode 100644 index 0000000..984e460 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/about.html @@ -0,0 +1,29 @@ +<!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>November 7, 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>
\ No newline at end of file diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/build.properties b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/build.properties new file mode 100644 index 0000000..0040b97 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + icons/,\ + plugin.properties,\ + about.html + diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/icons/all.gif b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/icons/all.gif Binary files differnew file mode 100644 index 0000000..327ea88 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/icons/all.gif diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/icons/overview.gif b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/icons/overview.gif Binary files differnew file mode 100644 index 0000000..8173b81 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/icons/overview.gif diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/icons/tree.gif b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/icons/tree.gif Binary files differnew file mode 100644 index 0000000..852dc81 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/icons/tree.gif diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/plugin.properties b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/plugin.properties new file mode 100644 index 0000000..dbeea7b --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/plugin.properties @@ -0,0 +1,30 @@ +# /** +# * +# * Copyright (c) 2007 Anyware Technologies. +# * 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: +# * Anyware Technologies - Initial API and implementation +# * +# * $Id: plugin.properties,v 1.1 2007/11/07 15:14:49 dsciamma Exp $ +# */ + +# NLS_MESSAGEFORMAT_VAR + +# ============================================================================== +# Do not change the properties between this line and the last line containing: +# %%% END OF TRANSLATED PROPERTIES %%% +# Instead, either redefine an existing property, or create a new property, +# append it to the end of the file, and change the code to use the new name. +# ============================================================================== + +pluginName=Outline Navigator +providerName=Eclipse.org + +# ============================================================================== +# %%% END OF TRANSLATED PROPERTIES %%% +# The above properties have been shipped for translation. +# ============================================================================== diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/AbstractDiagramsOutlinePage.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/AbstractDiagramsOutlinePage.java new file mode 100644 index 0000000..61623e0 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/AbstractDiagramsOutlinePage.java @@ -0,0 +1,538 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.gef.RootEditPart; +import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; +import org.eclipse.gmf.runtime.diagram.ui.outline.internal.Activator; +import org.eclipse.gmf.runtime.diagram.ui.outline.internal.OverviewComposite; +import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor; +import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.viewers.DoubleClickEvent; +import org.eclipse.jface.viewers.IDoubleClickListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.part.IPageSite; +import org.eclipse.ui.part.Page; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.ui.views.contentoutline.IContentOutlinePage; + +/** + * <b>Outline of the modeler editor</b> <br> + * The outline displays the model tree and the diagrams associated with the + * model objects. <br> + * Double-clicking on a diagram change the active diagram edited by the modeler. + * <br> + * + * @author <a href="mailto:david.sciamma@anyware-tech.com">David Sciamma </a> + */ +public abstract class AbstractDiagramsOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener, IAdaptable { + + /** Flag set during selection modification */ + private boolean isDispatching = false; + + private IDiagramGraphicalViewer viewer; + + private AbstractModelNavigator navigator; + + private Composite overview; + + private SashForm sashComp; + + /** Actions */ + private IAction showTreeAction; + + private IAction showOverviewAction; + + private IAction showAllAction; + + private DiagramEditor editor; + + /** + * Constructor + * + * @param ed + * the editor linked with the outline + */ + public AbstractDiagramsOutlinePage(DiagramEditor ed) { + this.viewer = ed.getDiagramGraphicalViewer(); + this.editor = ed; + } + + /** + * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) + */ + public void addSelectionChangedListener(ISelectionChangedListener listener) { + if (navigator != null && !navigator.isDisposed()) { + navigator.getTreeViewer().addSelectionChangedListener(listener); + } + } + + /** + * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) + */ + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + if (navigator != null && !navigator.isDisposed()) { + navigator.getTreeViewer().removeSelectionChangedListener(listener); + } + } + + /** + * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection() + */ + public ISelection getSelection() { + return navigator.getTreeViewer().getSelection(); + } + + /** + * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection) + */ + public void setSelection(ISelection selection) { + navigator.getTreeViewer().setSelection(selection); + } + + /** + * Add listeners on the tree : + * <ul> + * <li>Listen to double-click</li> + * </ul> + */ + protected void hookListeners() { + navigator.getTreeViewer().addDoubleClickListener(new IDoubleClickListener() { + + public void doubleClick(DoubleClickEvent event) { + handleDoubleClickEvent(); + } + }); + + viewer.addSelectionChangedListener(this); + } + + /** + * Handles a double click on the outline tree : if the selected element is a + * diagram, the currently edited diagram is switch in the editor. + */ + protected void handleDoubleClickEvent() { + // IStructuredSelection selection = (IStructuredSelection) + // navigator.getTreeViewer().getSelection(); + // Object selectedObject = selection.getFirstElement(); + // + // // TODO Handle Double-click + // if (selectedObject instanceof Diagram && editor.getActiveDiagram() != + // (Diagram) selectedObject) + // { + // editor.setActiveDiagram((Diagram) selectedObject); + // } + // else if (AdapterFactoryEditingDomain.unwrap(selectedObject) + // instanceof EObject) + // { + // editor.gotoEObject((EObject) + // AdapterFactoryEditingDomain.unwrap(selectedObject)); + // } + } + + /** + * Creates the contents of the outline + * + * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + + // SashForm + sashComp = new SashForm(parent, SWT.VERTICAL); + sashComp.setLayoutData(new GridData(GridData.FILL_BOTH)); + + RootEditPart rootEditPart = viewer.getRootEditPart(); + if (rootEditPart instanceof ScalableFreeformRootEditPart) { + overview = createOverview(sashComp, (ScalableFreeformRootEditPart) rootEditPart); + overview.setLayoutData(new GridData(GridData.FILL_BOTH)); + } + + navigator = createNavigator(sashComp, viewer, getSite()); + + sashComp.setWeights(new int[] { 30, 70 }); + + getSite().setSelectionProvider(navigator.getTreeViewer()); + + createActions(); + hookListeners(); + } + + /** + * Create the composite that shows an overview of the model + * + * @param parent + * the parent + * @param rootEditPart + * the root edit part + * @return the overview composite + */ + protected Composite createOverview(Composite parent, ScalableFreeformRootEditPart rootEditPart) { + return new OverviewComposite(parent, rootEditPart); + } + + /** + * Create the composite that shows a tree view of the model + * + * @param parent + * the parent + * @param viewer + * the Viewer + * @param pageSite + * the IPageSite + * + * @return the navigation composite + */ + protected abstract AbstractModelNavigator createNavigator(Composite parent, IDiagramGraphicalViewer viewer, IPageSite pageSite); + + /** + * Add the actions to the view toolbar + */ + protected void createActions() { + IToolBarManager tbm = getSite().getActionBars().getToolBarManager(); + + createSorterActions(tbm); + + tbm.add(new Separator()); + + createShowOutlineActions(tbm); + + fillDropDownMenu(getSite().getActionBars().getMenuManager()); + } + + /** + * Returns the PreferenceStore to use + * + * @return IPreferenceStore + */ + protected abstract IPreferenceStore getPreferenceStore(); + + /** + * Create the show outline actions in the given tool bar manager. + * + * @param tbm + * the outline tool bar manager + */ + private void createShowOutlineActions(IToolBarManager tbm) { + final IPreferenceStore ps = getPreferenceStore(); + showTreeAction = new Action("Show Navigator", IAction.AS_RADIO_BUTTON) { + + public void run() { + if (navigator != null && !navigator.isDisposed()) { + performShowAction(navigator, ps, 1); + } + } + }; + showTreeAction.setToolTipText(showTreeAction.getText()); + showTreeAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/tree.gif")); + tbm.add(showTreeAction); + + showOverviewAction = new Action("Show Overview", IAction.AS_RADIO_BUTTON) { + + public void run() { + if (overview != null && !overview.isDisposed()) { + performShowAction(overview, ps, 2); + } + } + }; + showOverviewAction.setToolTipText(showOverviewAction.getText()); + showOverviewAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/overview.gif")); + tbm.add(showOverviewAction); + + showAllAction = new Action("Show both", IAction.AS_RADIO_BUTTON) { + + public void run() { + if (sashComp != null && !sashComp.isDisposed()) { + performShowAction(null, ps, 0); + } + } + }; + showAllAction.setToolTipText(showAllAction.getText()); + showAllAction.setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/all.gif")); + tbm.add(showAllAction); + + if (ps != null) { + int showAction = 0;// TODO restore + // ps.getInt(ModelerPreferenceConstants.OUTLINE_SHOW_ACTION_PREF); + Control control = null; + switch (showAction) { + case 1: + control = navigator; + showTreeAction.setChecked(true); + break; + + case 2: + control = overview; + showOverviewAction.setChecked(true); + break; + + default: + control = null; + showAllAction.setChecked(true); + } + performShowAction(control, ps, showAction); + } else { + showAllAction.setChecked(true); + performShowAction(null, ps, 0); + } + + } + + /** + * Create the sorter actions in the given tool bar manager. + * + * @param tbm + * the outline tool bar manager + */ + private void createSorterActions(IToolBarManager tbm) { + // final IPreferenceStore ps = getPreferenceStore(); + // final ArrayList sorterActions = new ArrayList(); + // + // // TODO Restore extension point + // // Get all extended sorters + // Collection sorters = + // OutlineManager.getInstance().getSorters(editor.getSite().getId()); + // // Get the actual sorter id from the preference store + // String sorterId = ps != null ? + // ps.getString(ModelerPreferenceConstants.OUTLINE_SORTER_PREF) : null; + // for (Iterator it = sorters.iterator(); it.hasNext();) + // { + // final SorterConfiguration config = (SorterConfiguration) it.next(); + // // Create an action for each sorter configuration + // IAction sorterAction = new Action(config.getName(), + // IAction.AS_CHECK_BOX) + // { + // public void run() + // { + // navigator.getTreeViewer().setSorter(isChecked() ? config.getSorter() + // : null); + // for (Iterator it2 = sorterActions.iterator(); it2.hasNext();) + // { + // IAction action = (IAction) it2.next(); + // if (action != this) + // { + // action.setChecked(false); + // } + // } + // // Store the selected sorter in the preference store + // if (ps != null) + // { + // ps.setValue(ModelerPreferenceConstants.OUTLINE_SORTER_PREF, + // isChecked() ? config.getId() : ""); + // } + // } + // + // }; + // // Add the newly created action in the actions cache + // sorterActions.add(sorterAction); + // + // // Configure the newly created action + // sorterAction.setChecked(config.getId().equals(sorterId)); + // sorterAction.setImageDescriptor(config.getIcon()); + // sorterAction.setToolTipText(config.getName()); + // + // // Set the actual sorter + // if (config.getId().equals(sorterId)) + // { + // navigator.getTreeViewer().setSorter(config.getSorter()); + // } + // + // tbm.add(sorterAction); + // } + + } + + private void performShowAction(Control control, IPreferenceStore ps, int pref) { + sashComp.setMaximizedControl(control); + if (ps != null) { + // TODO Restore + // ps.setValue(ModelerPreferenceConstants.OUTLINE_SHOW_ACTION_PREF, + // pref); + } + } + + private void fillDropDownMenu(IMenuManager menu) { + // TODO Restore + // Collection configs = + // OutlineManager.getInstance().getCreateChildMenus(editor.getSite().getId()); + // final IPreferenceStore ps = editor.getPreferenceStore(); + // if (configs.size() > 1 && ps != null) + // { + // IMenuManager createChildMenu = new MenuManager("Create child menu"); + // menu.add(createChildMenu); + // + // for (Iterator it = configs.iterator(); it.hasNext();) + // { + // final CreateChildMenuConfiguration config = + // (CreateChildMenuConfiguration) it.next(); + // IAction action = new Action(config.getName(), + // IAction.AS_RADIO_BUTTON) + // { + // public void run() + // { + // ps.setValue(ModelerPreferenceConstants.CREATE_CHILD_MENU_PREF, + // config.getId()); + // } + // }; + // action.setChecked(ps.getString(ModelerPreferenceConstants.CREATE_CHILD_MENU_PREF).equals(config.getId())); + // + // createChildMenu.add(action); + // } + // } + // + // menu.add(new Separator()); + // + // menu.add(new FiltersAction(navigator.getTreeViewer(), editor)); + } + + /** + * @see org.eclipse.ui.part.IPage#getControl() + */ + public Control getControl() { + return sashComp; + } + + /** + * @see org.eclipse.ui.part.Page#init(org.eclipse.ui.part.IPageSite) + */ + public void init(IPageSite pageSite) { + super.init(pageSite); + + // TODO Restore + // IActionBars bars = pageSite.getActionBars(); + // String id = ActionFactory.UNDO.getId(); + // bars.setGlobalActionHandler(id, + // editor.getPublicActionRegistry().getAction(id)); + // id = ActionFactory.REDO.getId(); + // bars.setGlobalActionHandler(id, + // editor.getPublicActionRegistry().getAction(id)); + // bars.updateActionBars(); + } + + /** + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + if (adapter == EditingDomain.class) { + return editor.getEditingDomain(); + } + return null; + } + + /** + * @see org.eclipse.ui.part.IPage#setFocus() + */ + public void setFocus() { + getControl().setFocus(); + } + + /** + * Called when the selection changed in the editor + * + * @param event + */ + public void selectionChanged(SelectionChangedEvent event) { + if (isDispatching) { + return; + } + + ISelection selection = event.getSelection(); + syncSelection(selection); + } + + /** + * Synchronize the outline with the given selection. It also filters the + * + * @param selection + */ + private void syncSelection(ISelection selection) { + isDispatching = true; + + // TODO restore + // List newSelection = new ArrayList(); + // if (selection instanceof IStructuredSelection) + // { + // Iterator it = ((IStructuredSelection) selection).iterator(); + // while (it.hasNext()) + // { + // Object selectedObject = it.next(); + // if (selectedObject instanceof EMFGraphNodeEditPart) + // { + // newSelection.add(((MixedEditDomain) + // editor.getAdapter(MixedEditDomain.class)).getEMFEditingDomain().getWrapper( + // ((EMFGraphNodeEditPart) selectedObject).getEObject())); + // } + // else if (selectedObject instanceof EMFGraphEdgeEditPart) + // { + // newSelection.add(((MixedEditDomain) + // editor.getAdapter(MixedEditDomain.class)).getEMFEditingDomain().getWrapper( + // ((EMFGraphEdgeEditPart) selectedObject).getEObject())); + // } + // else if (selectedObject instanceof GraphElement) + // { + // EObject model = Utils.getElement((GraphElement) selectedObject); + // if (model != null) + // { + // newSelection.add(model); + // } + // } + // else if (selectedObject instanceof EObject) + // { + // newSelection.add(selectedObject); + // } + // else if (selectedObject instanceof DiagramEditPart) + // { + // newSelection.add(Utils.getElement((GraphElement) ((MixedEditDomain) + // editor.getAdapter(MixedEditDomain.class)).getEMFEditingDomain().getWrapper( + // ((DiagramEditPart) selectedObject).getModel()))); + // } + // } + // } + // setSelection(new StructuredSelection(newSelection)); + + isDispatching = false; + } + + /** + * Releases the objects + * + * @see org.eclipse.ui.part.IPage#dispose() + */ + public void dispose() { + unhookListeners(); + overview.dispose(); + navigator.dispose(); + super.dispose(); + } + + /** + * Stop all the listeners + */ + protected void unhookListeners() { + viewer.removeSelectionChangedListener(this); + } +} diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/AbstractModelNavigator.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/AbstractModelNavigator.java new file mode 100644 index 0000000..84d64b5 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/AbstractModelNavigator.java @@ -0,0 +1,578 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.AdapterFactory; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.common.notify.impl.AdapterImpl; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.provider.IViewerNotification; +import org.eclipse.emf.edit.provider.IWrapperItemProvider; +import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider; +import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider; +import org.eclipse.gmf.runtime.diagram.ui.outline.internal.Activator; +import org.eclipse.gmf.runtime.diagram.ui.outline.internal.ModelElementComparer; +import org.eclipse.gmf.runtime.diagram.ui.outline.internal.OutlineDragAdapter; +import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.viewers.DecoratingLabelProvider; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredViewer; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.part.IPageSite; + +/** + * <b>Model navigator :</b><br> + * Display the model as a tree and fill the contextual menu with diagrams and + * EMF actions. <br> + * creation : 30 mai 2005 + * + * @author <a href="mailto:david.sciamma@anyware-tech.com">David Sciamma</a> + */ +public abstract class AbstractModelNavigator extends Composite implements IMenuListener { + + private IDiagramGraphicalViewer diagramViewer; + + private TreeViewer viewer; + + private IPageSite site; + + private Adapter modelListener = new AdapterImpl() { + + /** + * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification) + */ + @Override + public void notifyChanged(Notification msg) { + refreshViewer(true); + } + }; + + /** + * This content provider filters the event from graphical object to only + * refresh when it's needed. + * + * @author <a href="david.sciamma@anyware-tech.com">David Sciamma</a> + */ + protected class NavigatorAdapterFactoryContentProvider extends AdapterFactoryContentProvider { + + /** + * Constructor + * + * @param adapterFactory + * the factory + */ + public NavigatorAdapterFactoryContentProvider(AdapterFactory adapterFactory) { + super(adapterFactory); + } + + /** + * @see org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider#notifyChanged(org.eclipse.emf.common.notify.Notification) + */ + @Override + public void notifyChanged(Notification notification) { + if (notification instanceof IViewerNotification) { + Object element = ((IViewerNotification) notification).getElement(); + if (!(element instanceof View)) { + // Filter only non-graphical object events + super.notifyChanged(notification); + } else if ((element instanceof Diagram) && ((IViewerNotification) notification).isLabelUpdate()) { + // A diagram or a Diagrams is added or removed : refresh the + // whole tree + refreshViewer(true); + } + } else { + super.notifyChanged(notification); + } + } + } + + /** + * Constructor + * + * @param parent + * the parent composite + * @param viewer + * the viewer to edit as tree + * @param pageSite + * the site + */ + public AbstractModelNavigator(Composite parent, IDiagramGraphicalViewer viewer, IPageSite pageSite) { + super(parent, SWT.BORDER); + + this.diagramViewer = viewer; + site = pageSite; + GridLayout gl = new GridLayout(); + gl.marginHeight = 0; + gl.marginWidth = 0; + setLayout(gl); + createContents(this); + } + + /** + * Returns the TreeViewer used as navigator + * + * @return the navigable tree + */ + public TreeViewer getTreeViewer() { + return viewer; + } + + /** + * Create the contents of the widget + * + * @param parent + * the current widget + */ + protected void createContents(Composite parent) { + viewer = new TreeViewer(parent, SWT.MULTI); + viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); + + initDragAndDrop(); + initProviders(); + initFilters(); + hookListeners(); + hookKeyListeners(); + + // Add our custom ElementComparer that unwrap model objects before the + // comparison + viewer.setComparer(new ModelElementComparer()); + viewer.setInput(getModelResource()); + + createContextMenu(viewer); + + refreshViewer(); + } + + protected Resource getModelResource() { + Object model = diagramViewer.getContents().getModel(); + if (model instanceof Diagram) { + EObject eObject = ((Diagram) model).getElement(); + return EcoreUtil.getRootContainer(eObject).eResource(); + } + + return null; + } + + /** + * Add drag and drop ability between the outline to the editor. + */ + protected void initDragAndDrop() { + int ops = DND.DROP_COPY | DND.DROP_MOVE; + + OutlineDragAdapter dragAdapter = new OutlineDragAdapter(viewer); + viewer.addDragSupport(ops, dragAdapter.getSupportedDragTransfers(), dragAdapter); + + // Transfer[] transfers = new Transfer[] + // {OutlineToDiagramTransfer.getInstance()}; + // viewer.addDragSupport(ops, transfers, new + // OutlineDragAdapter(viewer)); + + // // TODO restore EMF internal drag and drop (need model refactoring + // // capabilities) + // 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(modeler.getEditingDomain(), + // viewer)); + } + + /** + * Set the tree providers for the outline + */ + protected void initProviders() { + AdapterFactoryContentProvider adapterContentProvider = new NavigatorAdapterFactoryContentProvider(getAdapterFactory()); + adapterContentProvider.inputChanged(viewer, null, null); + viewer.setContentProvider(new NavigatorContentProvider(diagramViewer, adapterContentProvider)); + + ILabelProvider fullLabelProvider = new DecoratingLabelProvider(new NavigatorLabelProvider(new AdapterFactoryLabelProvider(getAdapterFactory())), Activator.getDefault().getWorkbench() + .getDecoratorManager().getLabelDecorator()); + viewer.setLabelProvider(fullLabelProvider); + } + + protected abstract AdapterFactory getAdapterFactory(); + + protected abstract IPreferenceStore getPreferenceStore(); + + /** + * Set the tree filters for the outline + * + */ + protected void initFilters() { + // TODO Complete This later + // IPreferenceStore ps = modeler.getPreferenceStore(); + // Collection configs = FiltersAction.getFilterConfigurations(ps != null + // ? + // ps.getString(ModelerPreferenceConstants.FILTERS_PREF) : ""); + // + // for (Iterator it = configs.iterator(); it.hasNext();) + // { + // FilterConfiguration config = (FilterConfiguration) it.next(); + // viewer.addFilter(config.getFilter()); + // } + + } + + /** + * Add listeners : <br> - on the model<br> + */ + protected void hookListeners() { + getModelResource().getResourceSet().eAdapters().add(modelListener); + } + + /** + * Remove listeners + */ + protected void unhookListeners() { + getModelResource().getResourceSet().eAdapters().remove(modelListener); + } + + /** + * Add a key listener to the tree control. When a key is released, the + * DELETE key is filtered to fire the action. + */ + protected void hookKeyListeners() { + KeyListener keyListener = new KeyListener() { + + public void keyPressed(KeyEvent e) { + // Do nothing + } + + public void keyReleased(KeyEvent e) { + if (e.keyCode == SWT.DEL) { + // TODO Restore this + // IAction deleteAction = createDeleteAction(); + // deleteAction.run(); + } + } + + }; + viewer.getControl().addKeyListener(keyListener); + } + + /** + * This creates a context menu for the viewer and adds a listener as well + * registering the menu for extension. + * + * @param sViewer + * the tree viewer + */ + protected void createContextMenu(StructuredViewer sViewer) { + MenuManager contextMenu = new MenuManager("#PopUp"); //$NON-NLS-1$ + contextMenu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + contextMenu.setRemoveAllWhenShown(true); + contextMenu.addMenuListener(this); + Menu menu = contextMenu.createContextMenu(viewer.getControl()); + sViewer.getControl().setMenu(menu); + site.registerContextMenu(getClass().getName(), contextMenu, viewer); + } + + /** + * This implements {@link org.eclipse.jface.action.IMenuListener}to help + * fill the context menus with contributions from the Edit menu. + * + * @param menuManager + * the menu to fill + */ + public void menuAboutToShow(IMenuManager menuManager) { + + // Add our standard marker. + // + menuManager.add(new Separator(IOutlineMenuConstants.NEW_GROUP)); + menuManager.add(new Separator(IOutlineMenuConstants.EDIT_GROUP)); + menuManager.add(new Separator(IOutlineMenuConstants.ADDITIONS_GROUP)); + menuManager.add(new Separator(IOutlineMenuConstants.PROPERTIES_GROUP)); + menuManager.add(new Separator(IOutlineMenuConstants.ADDITIONS_END_GROUP)); + + IStructuredSelection sel = (IStructuredSelection) viewer.getSelection(); + + Object currentSel = sel.getFirstElement(); + + // Create context menu if the resource associated to the current + // selection is writable. + if ((currentSel instanceof AdditionalResources))// ADD this || + // ((resource != null) + // && + // !ResourceUtils.isReadOnly(resource))) + { + if (sel.size() == 1) { + Object selection = sel.getFirstElement(); + createSingleSelectionMenu(menuManager, selection); + } + + createMultiSelectionMenu(menuManager, sel); + } + + // TODO Restore this + // if (loadMenu == null) + // { + // MixedEditDomain domain = (MixedEditDomain) + // modeler.getAdapter(MixedEditDomain.class); + // String metamodelURI = + // modeler.getDiagrams().getModel().eClass().getEPackage().getNsURI(); + // loadMenu = new RegisteredModelMenu("Load", + // domain.getEMFEditingDomain(), metamodelURI); + // } + // menuManager.add(loadMenu); + } + + /** + * Add to the MenuManager the actions for a multiple selection. + * + * @param manager + * The menu to fill + * @param selection + * the selection + */ + protected void createMultiSelectionMenu(IMenuManager manager, IStructuredSelection selection) { + // TODO Restore this + // MixedEditDomain domain = (MixedEditDomain) + // modeler.getAdapter(MixedEditDomain.class); + // if (domain != null) + // { + // // Add the delete from model action + // DeleteAction deleteAction = new DeleteAction(domain, + // modeler.getDiagrams(), selection); + // manager.appendToGroup(IOutlineMenuConstants.EDIT_GROUP, + // deleteAction); + // + // // Add load resource action + // LoadResourceAction loadAction = new + // LoadResourceAction(domain.getEMFEditingDomain()); + // manager.appendToGroup(IOutlineMenuConstants.ADDITIONS_GROUP, + // loadAction); + // } + } + + /** + * Add to the MenuManager the actions for a single object. + * + * @param manager + * The menu to fill + * @param selection + * the selected object + */ + protected void createSingleSelectionMenu(IMenuManager manager, Object selection) { + EObject selectedObject = null; + + if (selection instanceof EObject) { + selectedObject = (EObject) selection; + } else if ((selection instanceof IWrapperItemProvider) || (selection instanceof FeatureMap.Entry)) { + selectedObject = (EObject) AdapterFactoryEditingDomain.unwrap(selection); + } + + // The following menu are disable for the diagram objects + if ((selectedObject != null) && !(selectedObject instanceof View)) { + createEMFMenu(manager, selectedObject); + createDiagramsMenu(manager, selectedObject); + createControlActions(manager); + } + + } + + private void createDiagramsMenu(IMenuManager manager, EObject selectedObject) { + if (!isDiagramsMenuEnabledFor(selectedObject)) { + return; + } + MenuManager submenuManager = new MenuManager("Add diagram"); + + // Restore this + // DiagramDescriptor[] diagramDescriptors = + // DiagramsManager.getInstance().getDiagrams(); + // for (int i = 0; i < diagramDescriptors.length; i++) + // { + // if (diagramDescriptors[i].canCreateDiagramOn(selectedObject)) + // { + // CreateDiagramAction action = new CreateDiagramAction(modeler, + // selectedObject, diagramDescriptors[i]); + // submenuManager.add(action); + // } + // } + + manager.appendToGroup(IOutlineMenuConstants.NEW_GROUP, submenuManager); + } + + private void createEMFMenu(IMenuManager manager, EObject selectedObject) { + + if (!isEMFMenuEnabledFor(selectedObject)) { + return; + } + + // TODO Restore this + // MixedEditDomain domain = (MixedEditDomain) + // modeler.getAdapter(MixedEditDomain.class); + // + // if (domain != null) + // { + // IPreferenceStore ps = modeler.getPreferenceStore(); + // if (ps != null) + // { + // String id = + // ps.getString(ModelerPreferenceConstants.CREATE_CHILD_MENU_PREF); + // CreateChildMenuConfiguration config = + // OutlineManager.getInstance().getCreateChildMenuConfiguration(id); + // ICreateChildMenu createChildMenu = null; + // if (config != null) + // { + // createChildMenu = config.getMenu(); + // } + // if (createChildMenu == null) + // { + // createChildMenu = new DefaultCreateChildMenu(); + // } + // + // createChildMenu.removeAll(); + // createChildMenu.setMixedEditDomain(domain); + // createChildMenu.setSelectedEObject(selectedObject); + // createChildMenu.createMenuContents(); + // + // manager.appendToGroup(IOutlineMenuConstants.NEW_GROUP, + // createChildMenu); + // } + // } + } + + /** + * Subclasses should override this method to control enabling/disabling the + * Diagrams menu for the current selection. + * + * Default returns true. + * + * @param selectedObject + * @return whether the control action is enabled for the current selection + * or not. + */ + protected boolean isDiagramsMenuEnabledFor(EObject selectedObject) { + return true; + } + + /** + * Subclasses should override this method to control enabling/disabling the + * EMF menu for the current selection. + * + * Default returns true. + * + * @param selectedObject + * @return whether the control action is enabled for the current selection + * or not. + */ + protected boolean isEMFMenuEnabledFor(EObject selectedObject) { + return true; + } + + /** + * Subclasses should override this method to control enabling/disabling the + * control action for the current selection. + * + * Default returns true. + * + * @param selectedObject + * @return whether the control action is enabled for the current selection + * or not. + */ + protected boolean isControlActionEnabledFor(EObject selectedObject) { + return true; + } + + private void createControlActions(IMenuManager manager) { + EObject selectedObject = null; + Object sel = getTreeViewer().getSelection(); + Object selection = null; + if (sel instanceof IStructuredSelection) { + if (!((IStructuredSelection) sel).isEmpty()) { + selection = ((IStructuredSelection) sel).getFirstElement(); + } + } + + if (selection instanceof EObject) { + selectedObject = (EObject) selection; + } else if ((selection instanceof IWrapperItemProvider) || (selection instanceof FeatureMap.Entry)) { + selectedObject = (EObject) AdapterFactoryEditingDomain.unwrap(selection); + } + + if (!isControlActionEnabledFor(selectedObject)) { + return; + } + } + + /** + * Rfersh the treeviewer in the UI thread if we are in a different thread + */ + protected final void refreshViewer() { + refreshViewer(false); + } + + /** + * Rfersh the treeviewer in the UI thread if we are in a different thread + * + * @param updateLabel + * <code>true</code> if the label must be refreshed + */ + protected final void refreshViewer(final boolean updateLabel) { + if ((viewer != null) && !viewer.getTree().isDisposed()) { + if (Display.getCurrent() != Display.getDefault()) { + syncRefreshViewer(updateLabel); + } else { + viewer.refresh(updateLabel); + } + } + } + + /** + * Refesh the tree viewer in the UI thread + * + * @param updateLabel + * <code>true</code> if the label must be refreshed + */ + private void syncRefreshViewer(final boolean updateLabel) { + viewer.getControl().getDisplay().syncExec(new Runnable() { + + public void run() { + viewer.refresh(updateLabel); + } + }); + } + + /** + * @see org.eclipse.swt.widgets.Widget#dispose() + */ + @Override + public void dispose() { + unhookListeners(); + super.dispose(); + } +} diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/AdditionalResources.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/AdditionalResources.java new file mode 100644 index 0000000..5bb35d3 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/AdditionalResources.java @@ -0,0 +1,57 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.resource.ResourceSet; + +/** + * This object computes all the loaded resources from a resource set. <br> + * creation : 8 juin 2005 + * + * @author <a href="mailto:david.sciamma@anyware-tech.com">David Sciamma</a> + */ +public class AdditionalResources { + + private ResourceSet resourceSet; + + /** + * Constructor + * + * @param rSet + * the ResourceSet to be used to load these Additional Resources + */ + public AdditionalResources(ResourceSet rSet) { + super(); + + this.resourceSet = rSet; + } + + /** + * Returns all the resources without the DI and the domain resources + * + * @return the list of additional resources + */ + public List<Resource> getResources() { + List<Resource> res = new ArrayList<Resource>(resourceSet.getResources()); + + // remove DI and domain resources + res.remove(res.size() - 1); + res.remove(res.size() - 1); + + return res; + } +} diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/IOutlineMenuConstants.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/IOutlineMenuConstants.java new file mode 100644 index 0000000..c8e653b --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/IOutlineMenuConstants.java @@ -0,0 +1,39 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline; + +import org.eclipse.ui.IWorkbenchActionConstants; + +/** + * This interface contains the references of the constants used in the context + * menu + * + * @author <a href="david.sciamma@anyware-tech.com">David Sciamma</a> + */ +public interface IOutlineMenuConstants { + + /** Menu Group for the creation actions */ + String NEW_GROUP = "new"; + + /** Menu Group for the edit actions */ + String EDIT_GROUP = "edit"; + + /** Menu Group for the first set of extended actions */ + String ADDITIONS_GROUP = IWorkbenchActionConstants.MB_ADDITIONS; + + /** Menu Group for the properties actions */ + String PROPERTIES_GROUP = "properties"; + + /** Menu Group for the edit actions */ + String ADDITIONS_END_GROUP = "additions-end"; +} diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/NavigatorContentProvider.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/NavigatorContentProvider.java new file mode 100644 index 0000000..665ec46 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/NavigatorContentProvider.java @@ -0,0 +1,180 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.util.FeatureMap; +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.emf.edit.provider.IWrapperItemProvider; +import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * This Content Provider displays contents of model and diagrams. For the model, + * this provider delegates contents computing to the model content provider. + * <br> + * creation : 7 dec. 2004 + * + * @author <a href="mailto:david.sciamma@anyware-tech.com">David Sciamma </a> + */ +public class NavigatorContentProvider implements ITreeContentProvider { + + private static final Object[] NO_CHILDREN = new Object[0]; + + private ITreeContentProvider delegatedModelProvider; + + private IDiagramGraphicalViewer diagramViewer; + + private AdditionalResources resources; + + /** + * Constructor + * + * @param viewer + * the editor + * @param delegatedProvider + * the delegated content provider + */ + public NavigatorContentProvider(IDiagramGraphicalViewer viewer, ITreeContentProvider delegatedProvider) { + delegatedModelProvider = delegatedProvider; + diagramViewer = viewer; + + resources = new AdditionalResources(getCurrentDiagram().eResource().getResourceSet()); + } + + /** + * Return the current Diagram element associated with the viewer + * + * @return Diagram + */ + protected Diagram getCurrentDiagram() { + return (Diagram) diagramViewer.getContents().getModel(); + } + + /** + * Returns the additional resources node + * + * @return the node + */ + protected AdditionalResources getAdditionalResources() { + return resources; + } + + /** + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + public Object[] getChildren(Object parentElement) { + // Only display diagram (no graphNodes or graphEdges) + if (parentElement instanceof Diagram) { + return NO_CHILDREN; + } + + if (parentElement instanceof AdditionalResources) { + return ((AdditionalResources) parentElement).getResources().toArray(); + } + + // Model children + List<Object> children = new ArrayList<Object>(); + Object[] modelChildren = delegatedModelProvider.getChildren(parentElement); + // children = Arrays.asList(modelChildren); + for (int i = 0; i < modelChildren.length; i++) { + Object child = modelChildren[i]; + children.add(child); + } + + // For the model objects, retrieves model children and merges result + // with diagrams associated with this element + if (parentElement instanceof EObject || parentElement instanceof IWrapperItemProvider || parentElement instanceof FeatureMap.Entry) { + children.addAll(findAllExistingDiagram(getCurrentDiagram().eResource(), (EObject) AdapterFactoryEditingDomain.unwrap(parentElement))); + } + + return children.toArray(); + } + + private Collection<Diagram> findAllExistingDiagram(Resource diagramResource, EObject modelObject) { + List<Diagram> diagrams = new ArrayList<Diagram>(); + if (diagramResource != null) { + for (EObject content : diagramResource.getContents()) { + if (content instanceof Diagram) { + if (modelObject.equals(((Diagram) content).getElement())) { + diagrams.add((Diagram) content); + } + } + } + } + return diagrams; + } + + /** + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + public Object getParent(Object element) { + // The parent of a diagram is the model object that contains it. + if (element instanceof Diagram) { + return ((Diagram) element).getElement(); + } + + // Delegates + if (element instanceof IWrapperItemProvider || element instanceof FeatureMap.Entry || element instanceof EObject) { + return delegatedModelProvider.getParent(element); + } + + return null; + } + + /** + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + public boolean hasChildren(Object element) { + if (element instanceof Diagram) { + return false; + } + + return getChildren(element).length > 0; + } + + /** + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object inputElement) { + if (inputElement instanceof Resource) { + List<Object> children = new ArrayList<Object>(((Resource) inputElement).getContents()); + children.add(resources); + return children.toArray(); + } + return NO_CHILDREN; + } + + /** + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + delegatedModelProvider.dispose(); + } + + /** + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, + * java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + delegatedModelProvider.inputChanged(viewer, oldInput, newInput); + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/NavigatorLabelProvider.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/NavigatorLabelProvider.java new file mode 100644 index 0000000..cf56eff --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/NavigatorLabelProvider.java @@ -0,0 +1,121 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline; + +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +/** + * This Label Provider displays informations about model and diagrams. For the + * model, this provider delegates informations computing to the model label + * provider. <br> + * creation : 7 dec. 2004 + * + * @author <a href="mailto:david.sciamma@anyware-tech.com">David Sciamma </a> + */ +public class NavigatorLabelProvider extends LabelProvider { + + /** The delegated model label provider */ + private ILabelProvider delegatedModelProvider; + + /** + * Constructor + * + * @param delegatedProvider + * the delegated label provider of the model + */ + public NavigatorLabelProvider(ILabelProvider delegatedProvider) { + delegatedModelProvider = delegatedProvider; + } + + /** + * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object) + */ + public Image getImage(Object element) { + if (element instanceof Diagram) { + Diagram diag = (Diagram) element; + + return getDiagramIcon(diag); + } + + return delegatedModelProvider.getImage(element); + } + + /** + * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object) + */ + public String getText(Object element) { + if (element instanceof AdditionalResources) { + return "Additional Resources"; + } + if (element instanceof Diagram) { + Diagram diag = (Diagram) element; + + return getDiagramText(diag); + } + + return delegatedModelProvider.getText(element); + } + + /** + * Compose the diagram label + * + * @param d + * the diagram + * @return the diagram label + */ + private String getDiagramText(Diagram d) { + String name = d.getName(); + String id = d.getType(); + String diagramTypeName = "Diagram"; + if (id != null && !"".equals(id)) { + // TODO Change This ! + // DiagramDescriptor diagDesc = + // DiagramsManager.getInstance().find(id); + // if (diagDesc != null) + // { + // diagramTypeName = diagDesc.getName(); + // } + } + + return name == null || name.length() == 0 ? diagramTypeName : diagramTypeName + " " + name; + } + + /** + * Get the diagram icon + * + * @param d + * the diagram + * @return the diagram label + */ + private Image getDiagramIcon(Diagram d) { + String id = d.getType(); + if (id != null && !"".equals(id)) { + // TODO Change This ! + // DiagramDescriptor diagDesc = + // DiagramsManager.getInstance().find(id); + // if (diagDesc != null) + // { + // Image icon = diagDesc.getIcon(); + // if (icon != null) + // { + // return icon; + // } + // } + } + + return delegatedModelProvider.getImage(d); + } +} diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/Activator.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/Activator.java new file mode 100644 index 0000000..a184824 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/Activator.java @@ -0,0 +1,61 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline.internal; + +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.gmf.runtime.diagram.ui.outline"; + + /** The shared instance */ + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + // Do nothing + } + + /** + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /** + * @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/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/ModelElementComparer.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/ModelElementComparer.java new file mode 100644 index 0000000..105cad6 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/ModelElementComparer.java @@ -0,0 +1,42 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline.internal; + +import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; +import org.eclipse.jface.viewers.IElementComparer; + +/** + * A Comparer of the EMF model objects. Model objects are first unwrapped. + * + * Creation : 31 janv. 2006 + * + * @author <a href="mailto:jacques.lescot@anyware-tech.com">Jacques LESCOT</a> + */ +public class ModelElementComparer implements IElementComparer { + + /** + * @see org.eclipse.jface.viewers.IElementComparer#equals(java.lang.Object, + * java.lang.Object) + */ + public boolean equals(Object a, Object b) { + return AdapterFactoryEditingDomain.unwrap(a).equals(AdapterFactoryEditingDomain.unwrap(b)); + } + + /** + * @see org.eclipse.jface.viewers.IElementComparer#hashCode(java.lang.Object) + */ + public int hashCode(Object element) { + return element.hashCode(); + } + +} diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/OutlineDragAdapter.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/OutlineDragAdapter.java new file mode 100644 index 0000000..c631e33 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/OutlineDragAdapter.java @@ -0,0 +1,148 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline.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.gmf.runtime.notation.View; +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.swt.dnd.DragSource; +import org.eclipse.swt.dnd.DragSourceAdapter; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.part.PluginTransfer; + +/** + * This Adapter listens to dragging operations and fill or clean the clipboard + * with filtered datas. <br> + * creation : 6 dec. 2004 + * + * @author <a href="mailto:david.sciamma@anyware-tech.com">David Sciamma </a> + */ +public class OutlineDragAdapter extends DragSourceAdapter { + + private 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(PluginTransfer.getInstance()); + 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 if (PluginTransfer.getInstance().isSupportedType(event.dataType)) { + // TODO Check this + // event.data = NavigatorPluginDropAction + // .createTransferData(contentService); + } 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 { + // Workaround for 1GEUS9V + DragSource dragSource = (DragSource) event.widget; + Control control = dragSource.getControl(); + if (control == control.getDisplay().getFocusControl()) { + ISelection selection = getSelection(); + if (!selection.isEmpty()) { + LocalSelectionTransfer.getTransfer().setSelection(selection); + event.doit = true; + } else { + event.doit = false; + } + } else { + event.doit = false; + } + } catch (RuntimeException e) { + // TODO log exception + // NavigatorPlugin.logError(0, e.getMessage(), 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); + } + +} diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/OutlineToDiagramTransfer.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/OutlineToDiagramTransfer.java new file mode 100644 index 0000000..c032084 --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/OutlineToDiagramTransfer.java @@ -0,0 +1,67 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline.internal; + +import org.eclipse.gef.dnd.SimpleObjectTransfer; + +/** + * This Transfer expects a java.util.List as the object being transferred. + * + * <br> + * creation : 7 dec. 2004 + * + * @author <a href="mailto:david.sciamma@anyware-tech.com">David Sciamma </a> + */ +public final class OutlineToDiagramTransfer extends SimpleObjectTransfer { + + /** + * <code>TYPE_NAME</code>: key used to mark the type of transfer + */ + public static final String TYPE_NAME = "Outline To Diagram Transfer"; //$NON-NLS-1$ + + private static OutlineToDiagramTransfer TRANSFER = null; + + private static final int TYPE_ID = registerType(TYPE_NAME); + + private OutlineToDiagramTransfer() { + // Do nothing + } + + /** + * Returns the shared instance + * + * @return the singleton + */ + public static OutlineToDiagramTransfer getInstance() { + if (TRANSFER == null) { + TRANSFER = new OutlineToDiagramTransfer(); + } + + return TRANSFER; + } + + /** + * @see org.eclipse.swt.dnd.Transfer#getTypeIds() + */ + protected int[] getTypeIds() { + return new int[] { TYPE_ID }; + } + + /** + * @see org.eclipse.swt.dnd.Transfer#getTypeNames() + */ + protected String[] getTypeNames() { + return new String[] { TYPE_NAME }; + } + +} diff --git a/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/OverviewComposite.java b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/OverviewComposite.java new file mode 100644 index 0000000..666f0eb --- /dev/null +++ b/plugins/org.eclipse.gmf.runtime.diagram.ui.outline/src/org/eclipse/gmf/runtime/diagram/ui/outline/internal/OverviewComposite.java @@ -0,0 +1,128 @@ +/*********************************************************************** + * Copyright (c) 2007 Anyware Technologies + * + * 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: + * Anyware Technologies - initial API and implementation + **********************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.outline.internal; + +import org.eclipse.draw2d.LightweightSystem; +import org.eclipse.draw2d.MarginBorder; +import org.eclipse.draw2d.Viewport; +import org.eclipse.draw2d.parts.ScrollableThumbnail; +import org.eclipse.draw2d.parts.Thumbnail; +import org.eclipse.gef.LayerConstants; +import org.eclipse.gef.editparts.ScalableFreeformRootEditPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * This is a sample implementation of an outline control showing an overview of + * a graphical editor. <br> + * creation : 8 nov. 2004 + * + * @author <a href="mailto:david.sciamma@anyware-tech.com">David Sciamma </a> + */ +public class OverviewComposite extends Composite { + + /** the control of the _overview */ + private Canvas _overview; + + /** the root edit part */ + private ScalableFreeformRootEditPart _rootEditPart; + + /** the _thumbnail */ + private Thumbnail thumbnail; + + /** + * Creates a new OverviewOutlinePage instance. + * + * @param parent + * the parent composite + * @param rootEditPart + * the root edit part + */ + public OverviewComposite(Composite parent, ScalableFreeformRootEditPart rootEditPart) { + super(parent, SWT.BORDER); + _rootEditPart = rootEditPart; + + GridLayout layout = new GridLayout(); + layout.horizontalSpacing = 0; + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.verticalSpacing = 0; + setLayout(layout); + setLayoutData(new GridData(GridData.FILL_BOTH)); + createControl(this); + } + + /** + * Creates the inner controls + * + * @param parent + * the parent composite + */ + public void createControl(Composite parent) { + // create canvas and lws + _overview = new Canvas(parent, SWT.NONE); + _overview.setLayoutData(new GridData(GridData.FILL_BOTH)); + LightweightSystem lws = new LightweightSystem(_overview); + + // create _thumbnail + thumbnail = new ScrollableThumbnail((Viewport) _rootEditPart.getFigure()); + thumbnail.setBorder(new MarginBorder(3)); + thumbnail.setSource(_rootEditPart.getLayer(LayerConstants.SCALABLE_LAYERS)); + + lws.setContents(thumbnail); + // _thumbnail.setSource(_rootEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS)); + // lws.setContents(_thumbnail); + } + + /** + * @see org.eclipse.ui.part.IPage#dispose() + */ + public void dispose() { + if (null != thumbnail) { + thumbnail.deactivate(); + thumbnail = null; + } + + super.dispose(); + } + + /** + * @see org.eclipse.swt.widgets.Control#setVisible(boolean) + */ + public void setVisible(boolean state) { + thumbnail.setVisible(state); + super.setVisible(state); + } + + /** + * @return the main control + */ + public Control getControl() { + return _overview; + } + + /** + * @return <code>true</code> if the focus succeed + */ + public boolean setFocus() { + if (getControl() != null) { + return getControl().setFocus(); + } + + return false; + } +} |
