Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraradermache2013-02-25 09:08:31 +0000
committeraradermache2013-02-25 09:08:31 +0000
commit9d2a100e51a967f18d232cb715d422826c13519e (patch)
treea9b32aa7703321b54cc8b1e3328f13c545208a17 /plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf
parentcfad5896992a96ffbb5923ed22f0c4e3295f6875 (diff)
downloadorg.eclipse.papyrus-9d2a100e51a967f18d232cb715d422826c13519e.tar.gz
org.eclipse.papyrus-9d2a100e51a967f18d232cb715d422826c13519e.tar.xz
org.eclipse.papyrus-9d2a100e51a967f18d232cb715d422826c13519e.zip
Initial import
View that displays hierarchy of edit parts, when an element is selected
Diffstat (limited to 'plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf')
-rw-r--r--plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/Activator.java52
-rw-r--r--plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/view/EditPartHierarchyView.java231
-rw-r--r--plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/view/EditPartLabelProvider.java86
3 files changed, 369 insertions, 0 deletions
diff --git a/plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/Activator.java b/plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/Activator.java
new file mode 100644
index 00000000000..e233cd78d69
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/Activator.java
@@ -0,0 +1,52 @@
+package org.eclipse.papyrus.gmf.editpartview;
+
+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.gmf.editpartview"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/view/EditPartHierarchyView.java b/plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/view/EditPartHierarchyView.java
new file mode 100644
index 00000000000..e734e07f4cd
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/view/EditPartHierarchyView.java
@@ -0,0 +1,231 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ * Based on edit policy view from patrick.tessier@cea.fr
+ */
+package org.eclipse.papyrus.gmf.editpartview.view;
+
+import java.util.ArrayList;
+
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.viewers.IContentProvider;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.ui.ISelectionListener;
+import org.eclipse.ui.ISelectionService;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * This view shows the edit-part hierarchy when an edit part is selected
+ */
+public class EditPartHierarchyView extends ViewPart {
+
+ /**
+ * this a object that represents a line into the table
+ */
+ class EditPolicyDescriptor {
+
+ public String role = "NO ROLE";
+
+ public EditPolicy policy = null;
+ }
+
+
+ private ArrayList<EditPolicyDescriptor> editPolicyList = new ArrayList<EditPolicyDescriptor>();
+
+ private ISelectionListener myEditPartlistener;
+
+ private TreeViewer viewer;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
+ */
+ public void setFocus() {
+ Viewer viewer = getViewer();
+ if(viewer != null && !viewer.getControl().isDisposed()) {
+
+ viewer.getControl().setFocus();
+ }
+ }
+
+ /**
+ * Create the main tree control
+ *
+ * @param parent
+ * @return Tree
+ */
+ protected Tree createTree(Composite parent) {
+ Tree tree = new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI
+ | SWT.FULL_SELECTION);
+ tree.setLinesVisible(true);
+ return tree;
+ }
+
+ /**
+ * Return the viewer.
+ *
+ * @return TreeViewer
+ */
+ protected TreeViewer getViewer() {
+ return viewer;
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public EditPartHierarchyView() {
+ myEditPartlistener = new ISelectionListener() {
+
+ public void selectionChanged(IWorkbenchPart part, ISelection selection) {
+
+ if(selection instanceof IStructuredSelection) {
+ Object selectedobject = ((IStructuredSelection)selection).getFirstElement();
+ if(selectedobject instanceof GraphicalEditPart) {
+ GraphicalEditPart graphicalEP = ((GraphicalEditPart)selectedobject);
+
+ if(viewer != null) {
+ viewer.setInput(new Object[]{ graphicalEP });
+ viewer.expandAll();
+ }
+ }
+ }
+ }
+ };
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ selectionService.addSelectionListener(myEditPartlistener);
+
+ }
+
+ protected void createColumns() {
+ viewer.getTree().setHeaderVisible(true);
+ viewer.getTree().setLinesVisible(true);
+
+ TreeColumn tcName = new TreeColumn(viewer.getTree(), SWT.LEFT);
+ tcName.setText("EditPart");
+ tcName.setWidth(150);
+ TreeColumn tcModelElement = new TreeColumn(viewer.getTree(), SWT.LEFT);
+ tcModelElement.setText("Model element");
+ tcModelElement.setWidth(150);
+ TreeColumn tcFigure = new TreeColumn(viewer.getTree(), SWT.LEFT);
+ tcFigure.setText("Figure");
+ tcFigure.setWidth(150);
+ TreeColumn tcFigBounds = new TreeColumn(viewer.getTree(), SWT.LEFT);
+ tcFigBounds.setText("Figure bounds");
+ tcFigBounds.setWidth(150);
+ }
+
+ @Override
+ public void createPartControl(final org.eclipse.swt.widgets.Composite parent) {
+ final IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
+ tbm.add(getClearViewAction());
+ viewer = new TreeViewer(createTree(parent));
+ viewer.setContentProvider(getContentProvider());
+ viewer.setLabelProvider(getLabelProvider());
+ createColumns();
+
+ }
+
+ protected ITableLabelProvider getLabelProvider() {
+ return new EditPartLabelProvider();
+ }
+
+ protected Action getClearViewAction() {
+ return new Action() {
+
+ @Override
+ public void run() {
+ clear();
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public String getToolTipText() {
+ return getText();
+ }
+
+ @Override
+ public String getText() {
+ return "Clear the view";
+ }
+
+ };
+ }
+
+
+ protected IContentProvider getContentProvider() {
+ return new ITreeContentProvider() {
+
+ public Object[] getElements(final Object inputElement) {
+ if(inputElement instanceof Object[]) {
+ return (Object[])inputElement;
+ }
+ return null;
+ }
+
+ public void inputChanged(final Viewer viewer, final Object oldInput, final Object newInput) {
+ // nothing
+ }
+
+ public void dispose() {
+ // nothing
+ }
+
+ public boolean hasChildren(final Object element) {
+
+ return getChildren(element).length != 0;
+ }
+
+ public Object getParent(final Object element) {
+ return null;
+ }
+
+ public Object[] getChildren(final Object parentElement) {
+ if(parentElement instanceof GraphicalEditPart) {
+ return ((GraphicalEditPart)parentElement).getChildren().toArray();
+ }
+ return new Object[0];
+ }
+ };
+ }
+
+ @Override
+ public void dispose() {
+ super.dispose();
+ ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
+ selectionService.removeSelectionListener(myEditPartlistener);
+ clear();
+ }
+
+ private void clear() {
+ this.editPolicyList.clear();
+ }
+}
diff --git a/plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/view/EditPartLabelProvider.java b/plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/view/EditPartLabelProvider.java
new file mode 100644
index 00000000000..217cb1513c3
--- /dev/null
+++ b/plugins/developer/org.eclipse.papyrus.gmf.editpartview/src/org/eclipse/papyrus/gmf/editpartview/view/EditPartLabelProvider.java
@@ -0,0 +1,86 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Ansgar Radermacher (CEA LIST) ansgar.radermacher@cea.fr - Initial API and implementation
+ * Based on edit policy view from patrick.tessier@cea.fr
+ */
+package org.eclipse.papyrus.gmf.editpartview.view;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableColorProvider;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.uml2.uml.NamedElement;
+
+
+/**
+ * This is the label provider to display edit parts
+ *
+ */
+public class EditPartLabelProvider implements ITableLabelProvider, ITableColorProvider {
+
+ protected Color papyrusColor = new Color(Display.getDefault(), 0, 127, 14);
+
+ protected Color customizableDropEditPolicyColor = new Color(Display.getDefault(), 0, 38, 255);
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void dispose() {
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if(element instanceof GraphicalEditPart) {
+ GraphicalEditPart editPart = (GraphicalEditPart)element;
+ IFigure figure = editPart.getContentPane();
+ Object model = editPart.getAdapter(EObject.class);
+ switch(columnIndex) {
+ case 0:
+ return editPart.getClass().getSimpleName();
+ case 1:
+ if(model instanceof NamedElement) {
+ return ((NamedElement)model).getName();
+ }
+ return "not a named element";
+ case 2:
+ return figure.getClass().getSimpleName();
+ case 3:
+ return figure.getBounds().toString();
+ }
+ }
+ return "cannot display it: " + element;
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ return null;
+ }
+
+ public Color getForeground(Object element, int columnIndex) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Color getBackground(Object element, int columnIndex) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+};

Back to the top