Author: dazarov
Date: 2007-08-07 07:06:02 -0400 (Tue, 07 Aug 2007)
New Revision: 2925
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/DiagramContentOutlinePage.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ConnectionEditPart.java
Log:
http://jira.jboss.com/jira/browse/EXIN-365
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/META-INF/MANIFEST.MF 2007-08-06
23:10:59 UTC (rev 2924)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/META-INF/MANIFEST.MF 2007-08-07
11:06:02 UTC (rev 2925)
@@ -17,7 +17,8 @@
org.jboss.tools.common,
org.eclipse.jdt.core,
org.jboss.tools.common.model,
- org.jboss.tools.hibernate.ui.view
+ org.jboss.tools.hibernate.ui.view,
+ org.jboss.tools.common.gef
Bundle-Version: 2.0.0
Export-Package: org.jboss.tools.hibernate.ui.veditor,
org.jboss.tools.hibernate.ui.veditor.editors,
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/DiagramContentOutlinePage.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/DiagramContentOutlinePage.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/DiagramContentOutlinePage.java 2007-08-07
11:06:02 UTC (rev 2925)
@@ -0,0 +1,241 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.ui.veditor.editors;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.draw2d.*;
+import org.eclipse.draw2d.parts.*;
+import org.eclipse.gef.*;
+import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
+import org.eclipse.gef.editparts.ZoomManager;
+import org.eclipse.gef.ui.parts.*;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.*;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.PageBook;
+
+
+public class DiagramContentOutlinePage extends ContentOutlinePage implements
+ IAdaptable {
+ private GraphicalViewer graphicalViewer;
+
+ private SelectionSynchronizer selectionSynchronizer;
+
+ private PageBook pageBook;
+
+ /*
+ * surface for drawing
+ */
+ private Canvas overview;
+
+ static final int ID_OUTLINE = 0;
+
+ static final int ID_OVERVIEW = 1;
+
+ private Thumbnail thumbnail;
+
+ IPageSite pSite;
+
+ /**
+ * The constructor
+ *
+ * @param viewer
+ */
+ public DiagramContentOutlinePage(EditPartViewer viewer) {
+ super(viewer);
+ }
+
+ /**
+ * Sets graphical viewer
+ *
+ * @param graphicalViewer
+ */
+ public void setGraphicalViewer(GraphicalViewer graphicalViewer) {
+ this.graphicalViewer = graphicalViewer;
+ }
+
+ public void update(GraphicalViewer graphicalViewer){
+ if(this.graphicalViewer != null){
+ if(this.graphicalViewer != graphicalViewer){
+ getSelectionSynchronizer().removeViewer(this.graphicalViewer);
+ replaceSelectionChangedListeners(graphicalViewer);
+ this.graphicalViewer = graphicalViewer;
+ getSelectionSynchronizer().addViewer(graphicalViewer);
+ initializeOverview();
+ }
+ }
+
+ }
+
+
+ /**
+ * @return graphical viewer
+ */
+ public GraphicalViewer getGraphicalViewer() {
+ return graphicalViewer;
+ }
+
+ /**
+ * sets selection synchronizer
+ *
+ * @param selectionSynchronizer
+ */
+ public void setSelectionSynchronizer(
+ SelectionSynchronizer selectionSynchronizer) {
+ this.selectionSynchronizer = selectionSynchronizer;
+ }
+
+ /**
+ * @return returns selection synchronizer
+ */
+ public SelectionSynchronizer getSelectionSynchronizer() {
+ return selectionSynchronizer;
+ }
+
+ /**
+ * initializator
+ */
+ public void init(IPageSite pageSite) {
+ super.init(pageSite);
+ this.pSite = pageSite;
+ }
+
+ /**
+ * Outline viewer configuration
+ *
+ */
+ protected void configureOutlineViewer() {
+ showPage(ID_OUTLINE);
+ }
+
+
+ /**
+ * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createControl(Composite parent) {
+ pageBook = new PageBook(parent, SWT.NONE);
+
+ overview = new Canvas(pageBook, SWT.NONE);
+ pageBook.showPage(overview);
+ configureOutlineViewer();
+ hookOutlineViewer();
+ initializeOutlineViewer();
+ }
+
+
+ /**
+ * @see org.eclipse.ui.part.IPage#dispose()
+ */
+ public void dispose() {
+ unhookOutlineViewer();
+ if (thumbnail != null)
+ thumbnail.deactivate();
+ super.dispose();
+ }
+
+
+ /**
+ * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
+ */
+ public Object getAdapter(Class type) {
+ if (type == ZoomManager.class) {
+ return ((ScalableFreeformRootEditPart) getGraphicalViewer()
+ .getRootEditPart()).getZoomManager();
+ }
+ return null;
+ }
+
+
+ /**
+ * @see org.eclipse.ui.part.IPage#getControl()
+ */
+ public Control getControl() {
+ return pageBook;
+ }
+
+ /**
+ *
+ */
+ protected void hookOutlineViewer() {
+ getSelectionSynchronizer().addViewer(getViewer());
+ }
+
+ /**
+ *
+ */
+ protected void initializeOutlineViewer() {
+ }
+
+
+ /**
+ *
+ */
+ protected void initializeOverview() {
+ LightweightSystem lws = new LightweightSystem(overview);
+ RootEditPart rep = getGraphicalViewer().getRootEditPart();
+
+ if (rep instanceof ScalableFreeformRootEditPart) {
+ ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
+ if(this.thumbnail != null) {
+ this.thumbnail.deactivate();
+ }
+ thumbnail = new ScrollableThumbnail((Viewport) root.getFigure());
+ thumbnail.setBorder(new MarginBorder(3));
+ thumbnail.setSource(root.getLayer(LayerConstants.PRINTABLE_LAYERS));
+ lws.setContents(thumbnail);
+ }
+ }
+
+ /**
+ * @param id
+ */
+ protected void showPage(int id) {
+
+ if (thumbnail == null)
+ initializeOverview();
+ pageBook.showPage(overview);
+ thumbnail.setVisible(true);
+
+ }
+
+ /**
+ *
+ */
+ protected void unhookOutlineViewer() {
+ getSelectionSynchronizer().removeViewer(getViewer());
+ }
+
+ Set listeners = new HashSet();
+
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ super.addSelectionChangedListener(listener);
+ listeners.add(listener);
+ }
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ super.removeSelectionChangedListener(listener);
+ listeners.remove(listener);
+ }
+
+ void replaceSelectionChangedListeners(GraphicalViewer graphicalViewer) {
+ Iterator it = listeners.iterator();
+ while(it.hasNext()) {
+ ISelectionChangedListener l = (ISelectionChangedListener)it.next();
+ getViewer().removeSelectionChangedListener(l);
+ graphicalViewer.addSelectionChangedListener(l);
+ }
+ }
+
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java 2007-08-06
23:10:59 UTC (rev 2924)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java 2007-08-07
11:06:02 UTC (rev 2925)
@@ -17,18 +17,17 @@
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
import org.eclipse.gef.requests.CreationFactory;
import org.eclipse.gef.requests.SimpleFactory;
-import org.eclipse.gef.ui.actions.ActionRegistry;
-import org.eclipse.gef.ui.actions.PrintAction;
import org.eclipse.gef.ui.actions.WorkbenchPartAction;
import org.eclipse.gef.ui.parts.GraphicalEditor;
-import org.eclipse.jface.action.IAction;
+import org.eclipse.gef.ui.parts.TreeViewer;
import org.eclipse.jface.util.TransferDropTargetListener;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.actions.ActionFactory;
-import org.hibernate.cfg.Configuration;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.hibernate.console.ConsoleConfiguration;
import org.hibernate.mapping.RootClass;
+import org.jboss.tools.common.gef.edit.GEFRootEditPart;
import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
import org.jboss.tools.hibernate.ui.veditor.editors.parts.OrmEditPartFactory;
import org.jboss.tools.hibernate.ui.view.views.ObjectEditorInput;
@@ -52,7 +51,7 @@
protected void initializeGraphicalViewer() {
final GraphicalViewer viewer = getGraphicalViewer();
viewer.setEditPartFactory(new OrmEditPartFactory());
- viewer.setRootEditPart(new ScalableFreeformRootEditPart());
+ viewer.setRootEditPart(new GEFRootEditPart());
viewer.addDropTargetListener(createTransferDropTargetListener());
viewer.setContents(ormDiagram);
}
@@ -106,4 +105,16 @@
setPartName("Diagram for " + rootClass.getEntityName());
ormDiagram = new OrmDiagram(configuration, rootClass,
objectEditorInput.getJavaProject());
}
+
+ public Object getAdapter(Class type) {
+ if (type == IContentOutlinePage.class) {
+ DiagramContentOutlinePage outline = new DiagramContentOutlinePage(
+ new TreeViewer());
+ outline.setGraphicalViewer(getGraphicalViewer());
+ outline.setSelectionSynchronizer(getSelectionSynchronizer());
+ return outline;
+ }
+
+ return super.getAdapter(type);
+ }
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ConnectionEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ConnectionEditPart.java 2007-08-06
23:10:59 UTC (rev 2924)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ConnectionEditPart.java 2007-08-07
11:06:02 UTC (rev 2925)
@@ -16,6 +16,8 @@
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartListener;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editparts.AbstractConnectionEditPart;
import org.eclipse.gef.editpolicies.SelectionEditPolicy;
@@ -28,6 +30,7 @@
import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table;
+import org.jboss.tools.common.gef.edit.GEFRootEditPart;
import org.jboss.tools.hibernate.ui.veditor.editors.figures.RoundPolylineConnection;
import org.jboss.tools.hibernate.ui.veditor.editors.model.Connection;
import org.jboss.tools.hibernate.ui.veditor.editors.model.ModelElement;
@@ -35,12 +38,13 @@
class ConnectionEditPart extends AbstractConnectionEditPart
-implements PropertyChangeListener {
+implements PropertyChangeListener, EditPartListener {
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
+ addEditPartListener(this);
}
}
@@ -110,4 +114,28 @@
}
}
+
+ public void childAdded(EditPart child, int index) {
+
+ }
+
+ public void partActivated(EditPart editpart) {
+
+ }
+
+ public void partDeactivated(EditPart editpart) {
+
+ }
+
+ public void removingChild(EditPart child, int index) {
+
+ }
+
+ public void selectedStateChanged(EditPart editpart) {
+ if (this.getSelected() == EditPart.SELECTED_PRIMARY) {
+ ((GEFRootEditPart) getParent()).setToFront(this);
+
+ }
+
+ }
}
\ No newline at end of file