Author: mdryakhlenkov
Date: 2007-07-05 08:01:50 -0400 (Thu, 05 Jul 2007)
New Revision: 2313
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java
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/DiagramEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/Messages.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPartFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ResourceManager.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/messages.properties
Log:
JBIDE-559: Hibernate diagram editor cleanup
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * 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.parts;
+
+import java.beans.PropertyChangeEvent;
+import java.util.List;
+
+import org.eclipse.draw2d.FocusBorder;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.MarginBorder;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.ToolbarLayout;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.swt.graphics.RGB;
+import org.jboss.tools.hibernate.ui.veditor.editors.figures.ComponentFigure;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ComponentShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+
+
+public class ComponentShapeEditPart extends ExpandeableShapeEditPart {
+
+ protected IFigure createFigure() {
+ if (getModel() instanceof ComponentShape) {
+ IFigure figure = new ComponentFigure();
+ figure.setLayoutManager(new ToolbarLayout());
+ Label label = new Label();
+ label.setText(ormLabelProvider.getText(getCastedModel().getOrmElement()));
+ label.setBackgroundColor(getColor());
+ label.setOpaque(true);
+ label.setIcon(ormLabelProvider.getImage(getCastedModel().getOrmElement()));
+ label.setLabelAlignment(PositionConstants.LEFT);
+ label.setBorder(new MarginBorder(1,2,1,2));
+ figure.add(label,-2);
+ figure.setBorder(new FocusBorder());
+ figure.setSize(-1,-1);
+ return figure;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public void performRequest(Request req) {
+ if(RequestConstants.REQ_OPEN.equals(req.getType()) && getModel() instanceof
ComponentShape) {
+ ((ComponentShape)getModel()).refreshChildsHiden(((OrmDiagram)getViewer().getContents().getModel()));
+ }
+ }
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ String prop = evt.getPropertyName();
+ if (ComponentShape.SET_CHILDS_HIDEN.equals(prop)) {
+ int i = figure.getPreferredSize().width;
+ ((ComponentFigure)figure).setChildsHiden(((Boolean)evt.getNewValue()).booleanValue());
+ if(((Boolean)evt.getNewValue()).booleanValue())
+ figure.setSize(i,-1);
+ else
+ figure.setSize(-1,-1);
+
+ refresh();
+// ((OrmDiagram)getParent().getModel()).setDirty(true);
+ } else {
+ super.propertyChange(evt);
+ }
+ }
+
+ protected void refreshVisuals() {
+ Rectangle bounds = null;
+ if (getModel() instanceof ComponentShape) {
+ bounds = new Rectangle(new Point(0,0), getFigure().getSize());
+ }
+ if (bounds != null) ((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), bounds);
+ }
+}
Added:
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
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ConnectionEditPart.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * 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.parts;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PolygonDecoration;
+import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gef.editpolicies.SelectionEditPolicy;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.SingleTableSubclass;
+import org.hibernate.mapping.Table;
+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;
+
+
+
+class ConnectionEditPart extends AbstractConnectionEditPart
+implements PropertyChangeListener {
+
+ public void activate() {
+ if (!isActive()) {
+ super.activate();
+ ((ModelElement) getModel()).addPropertyChangeListener(this);
+ }
+ }
+
+ protected void createEditPolicies() {
+ installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new
ShapesSelectionEditPolicy());
+ }
+
+ protected IFigure createFigure() {
+ PolylineConnection connection = new RoundPolylineConnection();
+ connection.setForegroundColor(getColor());
+ connection.setTargetDecoration(new PolygonDecoration());
+ connection.setVisible(!getCastedModel().isHiden());
+ return connection;
+ }
+
+ public void deactivate() {
+ if (isActive()) {
+ super.deactivate();
+ ((ModelElement) getModel()).removePropertyChangeListener(this);
+ }
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ String property = event.getPropertyName();
+ if (Connection.SHOW_SELECTION.equals(property))
+ getFigure().setForegroundColor(getSelectionColor());
+ else if (Connection.HIDE_SELECTION.equals(property))
+ getFigure().setForegroundColor(getColor());
+ else if (Connection.SET_HIDEN.equals(property))
+ getFigure().setVisible(!((Boolean)event.getNewValue()).booleanValue());
+ }
+
+ private Connection getCastedModel() {
+ return (Connection) getModel();
+ }
+
+ private Color getColor() {
+ Object element = getCastedModel().getTarget().getOrmElement();
+ if (element instanceof RootClass || element instanceof SingleTableSubclass)
+ return ResourceManager.getInstance().getColor(new RGB(210,155,100));
+ else if (element instanceof Column || element instanceof Table || element instanceof
Property)
+ return ResourceManager.getInstance().getColor(new RGB(160, 160, 160));
+ else
+ throw new IllegalArgumentException();
+ }
+
+ private Color getSelectionColor() {
+ if (getCastedModel().getTarget().getOrmElement() instanceof RootClass)
+ return ResourceManager.getInstance().getColor(new RGB(112,161,99));
+ else if (getCastedModel().getTarget().getOrmElement() instanceof Column ||
+ getCastedModel().getTarget().getOrmElement() instanceof Table ||
+ getCastedModel().getTarget().getOrmElement() instanceof Component)
+ return ResourceManager.getInstance().getColor(new RGB(66,173,247));
+ else
+ throw new IllegalArgumentException();
+ }
+
+ private class ShapesSelectionEditPolicy extends SelectionEditPolicy {
+
+ protected void hideSelection() {
+ getCastedModel().hideSelection();
+ }
+
+ protected void showSelection() {
+ getCastedModel().showSelection();
+ }
+
+ }
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,435 @@
+/*******************************************************************************
+ * 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.parts;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.ConnectionLayer;
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.FreeformLayer;
+import org.eclipse.draw2d.FreeformLayout;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.ManhattanConnectionRouter;
+import org.eclipse.draw2d.MarginBorder;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.DefaultEditDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
+import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.requests.CreateRequest;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Table;
+import org.jboss.tools.hibernate.ui.veditor.editors.VisualEditor;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.AutoLayout;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.IItemInfo;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.ILinkInfo;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.IDiagramInfo;
+import org.jboss.tools.hibernate.ui.veditor.editors.command.ShapeSetConstraintCommand;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Connection;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ModelElement;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.SpecialOrmShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.SpecialRootClass;
+
+class DiagramEditPart extends OrmEditPart implements PropertyChangeListener {
+
+ protected void createEditPolicies() {
+ installEditPolicy(EditPolicy.LAYOUT_ROLE,
+ new ShapesXYLayoutEditPolicy());
+ }
+
+ protected IFigure createFigure() {
+ Figure f = new FreeformLayer();
+ f.setBorder(new MarginBorder(3));
+ f.setLayoutManager(new FreeformLayout());
+
+ ConnectionLayer connLayer = (ConnectionLayer)
getLayer(LayerConstants.CONNECTION_LAYER);
+ connLayer.setConnectionRouter(new ManhattanConnectionRouter());
+
+ return f;
+ }
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ String prop = evt.getPropertyName();
+ if (OrmDiagram.REFRESH.equals(prop)) {
+ refresh();
+ autolayout();
+ // restore();
+ } else if (OrmDiagram.DIRTY.equals(prop))
+ ((VisualEditor) ((DefaultEditDomain) getViewer().getEditDomain())
+ .getEditorPart()).refreshDirty();
+ }
+
+ public void restore() {
+ boolean dirty = getCastedModel().isDirty();
+ HashMap hashMap = getCastedModel().getCloneElements();
+ String childrenLocations[] = getCastedModel().getChildrenLocations();
+ int tempPoint = 1;
+ OrmShape ormShape;
+ int point = 1;
+ int pointX = calculateTableLocation();
+ String string, xy[];
+ for (int i = 0; i < childrenLocations.length; i++)
+ if (childrenLocations[i].indexOf('@') != -1
+ && childrenLocations[i].indexOf(';') != -1) {
+ string = childrenLocations[i].substring(0, childrenLocations[i]
+ .indexOf('@'));
+ ormShape = (OrmShape) hashMap.remove(string);
+ if (ormShape != null) {
+ string = childrenLocations[i]
+ .substring(childrenLocations[i].indexOf('@') + 1);
+ xy = string.split(";");
+ if (xy.length > 1)
+ try {
+ ormShape.setLocation(new Point(Integer
+ .parseInt(xy[0]), Integer.parseInt(xy[1])));
+ } catch (NumberFormatException e) {
+ }
+ if (xy.length > 2)
+ if ((new Boolean(xy[2])).booleanValue())
+ ormShape.refreshHiden();
+ tempPoint = ormShape.getLocation().y
+ + getChildrenFigurePreferredHeight(ormShape) + 20;
+ if (tempPoint > point)
+ point = tempPoint;
+ }
+ }
+ if (getCastedModel().getOrmElement() instanceof RootClass) {
+ RootClass persistentClass = (RootClass) getCastedModel()
+ .getOrmElement();
+ ormShape = (OrmShape) hashMap
+ .remove(persistentClass.getClassName());
+ if (ormShape != null) {
+ ormShape.setLocation(new Point(20, 20));
+ tempPoint = 40 + getChildrenFigurePreferredHeight(ormShape);
+ }
+ Table table = persistentClass.getTable();
+ ormShape = (OrmShape) hashMap.remove(table.getSchema() + "."
+ + table.getName());
+ if (ormShape != null) {
+ ormShape.setLocation(new Point(pointX, 20));
+ point = 40 + getChildrenFigurePreferredHeight(ormShape);
+ }
+ if (tempPoint > point)
+ point = tempPoint;
+
+ }
+ Object objects[] = hashMap.keySet().toArray();
+ for (int i = 0; i < objects.length; i++) {
+ ormShape = (OrmShape) hashMap.get(objects[i]);
+ if (ormShape != null
+ && (ormShape.getOrmElement() instanceof RootClass || ormShape
+ .getOrmElement() instanceof SpecialOrmShape)) {
+ ormShape.setLocation(new Point(20, point));
+ tempPoint = point + getChildrenFigurePreferredHeight(ormShape)
+ + 20;
+ // if (ormShape.getOrmElement() instanceof SpecialRootClass) {
+ Component component = (Component) ((Collection) ((SpecialRootClass) (ormShape
+ .getOrmElement())).getProperty().getValue())
+ .getElement();
+ Table ownerTable = component.getOwner().getTable();
+ ormShape = (OrmShape) hashMap.remove(ownerTable.getSchema()
+ + "." + ownerTable.getName());
+ // }
+ // if (ormShape != null ) {
+ // ormShape.setLocation(new Point(pointX,point));
+ // point = point + getChildrenFigurePreferredHeight(ormShape) +
+ // 20;
+ // }
+ if (tempPoint > point)
+ point = tempPoint;
+ }
+ }
+ Iterator iterator = hashMap.values().iterator();
+ while (iterator.hasNext()) {
+ ormShape = (OrmShape) iterator.next();
+ if (ormShape.getOrmElement() instanceof Table) {
+ ormShape.setLocation(new Point(pointX, point));
+ point = point + getChildrenFigurePreferredHeight(ormShape) + 20;
+ }
+ }
+ getCastedModel().setDirty(dirty);
+ }
+
+ private OrmDiagram getCastedModel() {
+ return (OrmDiagram) getModel();
+ }
+
+ private int getChildrenFigurePreferredHeight(OrmShape ormShape) {
+ GraphicalEditPart part;
+ for (int i = 0; i < getChildren().size(); i++) {
+ part = (GraphicalEditPart) getChildren().get(i);
+ if (ormShape.equals(part.getModel()))
+ return part.getFigure().getPreferredSize().height;
+ }
+ return 0;
+ }
+
+ private int calculateTableLocation() {
+ int j = 0;
+ IFigure figure;
+ for (int i = 0; i < getFigure().getChildren().size(); i++) {
+ figure = (IFigure) getFigure().getChildren().get(i);
+ if (figure.getPreferredSize().width > j)
+ j = figure.getPreferredSize().width;
+ }
+ return j + 120;
+ }
+
+ protected List getModelChildren() {
+ return getCastedModel().getChildren();
+ }
+
+ public void activate() {
+ if (!isActive()) {
+ super.activate();
+ ((ModelElement) getModel()).addPropertyChangeListener(this);
+ autolayout();
+ // restore();
+ }
+ }
+
+ public void autolayout() {
+ IDiagramInfo process = new DiagramInfo(getCastedModel());
+ AutoLayout layout = new AutoLayout();
+ layout.setGridStep("" + 5);
+ layout.setOverride(true);
+ layout.setProcess(process);
+ }
+
+ public void setToFront(EditPart ep) {
+ int index = getChildren().indexOf(ep);
+ if (index == -1)
+ return;
+ if (index != getChildren().size() - 1)
+ reorderChild(ep, getChildren().size() - 1);
+ }
+
+ public void deactivate() {
+ if (isActive()) {
+ super.deactivate();
+ ((ModelElement) getModel()).removePropertyChangeListener(this);
+ }
+ }
+
+ private static class ShapesXYLayoutEditPolicy extends XYLayoutEditPolicy {
+
+ protected Command createChangeConstraintCommand(
+ ChangeBoundsRequest request, EditPart child, Object constraint) {
+ if (child instanceof OrmShapeEditPart
+ && constraint instanceof Rectangle) {
+ return new ShapeSetConstraintCommand((OrmShape) child
+ .getModel(), request, ((Rectangle) constraint)
+ .getLocation());
+ }
+ return super.createChangeConstraintCommand(request, child,
+ constraint);
+ }
+
+ protected Command createAddCommand(EditPart child, Object constraint) {
+ return null;
+ }
+
+ protected Command createChangeConstraintCommand(EditPart child,
+ Object constraint) {
+ return null;
+ }
+
+ protected Command getCreateCommand(CreateRequest request) {
+ return null;
+ }
+
+ protected Command getDeleteDependantCommand(Request request) {
+ return null;
+ }
+
+ protected EditPolicy createChildEditPolicy(EditPart child) {
+ return new NonResizableEditPolicy();
+ }
+ }
+
+
+class DiagramInfo implements IDiagramInfo {
+
+ ArrayList items = new ArrayList();
+ OrmDiagram diagram;
+
+ public DiagramInfo(OrmDiagram diagram) {
+ IItemInfo item;
+ this.diagram = diagram;
+
+ for (int i = 0; i < diagram.getChildren().size(); i++) {
+ item = new DiagramElementInfo((OrmShape) diagram.getChildren().get(
+ i));
+ addItem(item);
+ }
+ }
+
+ /**
+ *
+ */
+ public IItemInfo[] getItems() {
+ return (IItemInfo[]) items.toArray(new IItemInfo[0]);
+ }
+
+ /**
+ *
+ * @param item
+ */
+ public void addItem(IItemInfo item) {
+ items.add(item);
+ }
+
+ class DiagramElementInfo implements IItemInfo {
+ OrmShape element;
+
+ ArrayList links = new ArrayList();
+
+ /**
+ *
+ * @param element
+ */
+ public DiagramElementInfo(OrmShape element) {
+ ILinkInfo link;
+ this.element = element;
+ for (int i = 0; i < element.getSourceConnections().size(); i++) {
+ link = new LinkInfo((Connection) element.getSourceConnections()
+ .get(i));
+ addLink(link);
+ }
+ Shape child;
+ for (int j = 0; j < element.getChildren().size(); j++) {
+ child = (Shape) element.getChildren().get(j);
+ if (child.getSourceConnections().size() == 0) {
+ link = new LinkInfo(getID());
+ addLink(link);
+ }
+ for (int i = 0; i < child.getSourceConnections().size(); i++) {
+ link = new LinkInfo((Connection) child
+ .getSourceConnections().get(i));
+ addLink(link);
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public String getID() {
+ return element.toString();
+ }
+
+ /**
+ *
+ */
+ public boolean isComment() {
+ return false;
+ }
+
+ /**
+ *
+ */
+ public int[] getShape() {
+ int[] shape = new int[4];
+ shape[0] = element.getLocation().x;
+ shape[1] = element.getLocation().y;
+ OrmShapeEditPart part =
(OrmShapeEditPart)getViewer().getEditPartRegistry().get(element);
+ if(part != null){
+ IFigure fig = part.getFigure();
+ shape[2] = fig.getPreferredSize().width;
+ shape[3] = fig.getPreferredSize().height;
+ }else{
+ shape[2] = 600;
+ shape[3] = 100;
+ }
+ return shape;
+ }
+
+ /**
+ *
+ */
+ public ILinkInfo[] getLinks() {
+ return (ILinkInfo[]) links.toArray(new ILinkInfo[0]);
+ }
+
+ /**
+ *
+ * @param link
+ */
+ public void addLink(ILinkInfo link) {
+ links.add(link);
+ }
+
+ /**
+ *
+ */
+ public void setShape(int[] s) {
+ element.setLocation(new Point(s[0], s[1]));
+ }
+
+ }
+
+ class LinkInfo implements ILinkInfo {
+ Connection link = null;
+
+ String id = null;
+
+ /**
+ *
+ * @param link
+ */
+ public LinkInfo(Connection link) {
+ this.link = link;
+ }
+
+ /**
+ *
+ * @param id
+ */
+ public LinkInfo(String id) {
+ this.id = id;
+ }
+
+ /**
+ *
+ */
+ public String getTargetID() {
+ if (id != null)
+ return id;
+ if (link.getTarget() != null)
+ return link.getTarget().toString();
+ else
+ return "";
+ }
+
+ /**
+ *
+ */
+ public void setLinkShape(int[] vs) {
+ }
+ }
+}}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * 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.parts;
+
+import java.beans.PropertyChangeEvent;
+import java.util.List;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.swt.graphics.RGB;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ExpandeableShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
+
+
+public class ExpandeableShapeEditPart extends ShapeEditPart {
+
+ public void performRequest(Request req) {
+ if(RequestConstants.REQ_OPEN.equals(req.getType())) {
+ ((ExpandeableShape)getModel()).refreshReferences(getViewer().getContents().getModel());
+ }
+ }
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ String prop = evt.getPropertyName();
+ if (Shape.SHOW_SELECTION.equals(prop)) {
+ if(getFigure().getChildren().size() > 0){
+ ((IFigure)getFigure().getChildren().get(0)).setBackgroundColor(getSelectionColor());
+ ((IFigure)getFigure().getChildren().get(0)).setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(255,255,255)));
+ }
+ } else if (Shape.HIDE_SELECTION.equals(prop)) {
+ if(getFigure().getChildren().size() > 0){
+ ((IFigure)getFigure().getChildren().get(0)).setBackgroundColor(getColor());
+ ((IFigure)getFigure().getChildren().get(0)).setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(0,0,0)));
+ }
+ }else if (ExpandeableShape.SHOW_REFERENCES.equals(prop)) {
+// ((IFigure)getFigure().getChildren().get(0)).setBackgroundColor(getSelectionColor());
+// ((IFigure)getFigure().getChildren().get(0)).setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(255,255,255)));
+ } else {
+ super.propertyChange(evt);
+ }
+ }
+
+ protected List getModelChildren() {
+ return ((ExpandeableShape)getModel()).getChildren();
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/Messages.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/Messages.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/Messages.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * 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.parts;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.hibernate.ui.veditor.editors.parts.messages"; //$NON-NLS-1$
+
+ private Messages() {
+ }
+
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ public static String Colors_PersistentClassR;
+
+ public static String Colors_PersistentClassG;
+
+ public static String Colors_PersistentClassB;
+
+ public static String Colors_PersistentFieldR;
+
+ public static String Colors_PersistentFieldG;
+
+ public static String Colors_PersistentFieldB;
+
+ public static String Colors_DatabaseTableR;
+
+ public static String Colors_DatabaseTableG;
+
+ public static String Colors_DatabaseTableB;
+
+ public static String Colors_DatabaseColumnR;
+
+ public static String Colors_DatabaseColumnG;
+
+ public static String Colors_DatabaseColumnB;
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPart.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPart.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,168 @@
+/*******************************************************************************
+ * 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.parts;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartListener;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+
+public class OrmEditPart extends AbstractGraphicalEditPart implements EditPartListener{
+
+ public void setModel(Object model) {
+ super.setModel(model);
+ addEditPartListener(this);
+ }
+
+ 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 &&
OrmEditPart.this.getParent() instanceof DiagramEditPart) {
+ ((DiagramEditPart)OrmEditPart.this.getParent()).setToFront(this);
+ }
+ }
+
+ protected IFigure createFigure() {
+ return null;
+ }
+
+ protected void createEditPolicies() {
+ }
+
+ protected void refreshSourceConnections() {
+ int i;
+ org.eclipse.gef.ConnectionEditPart editPart;
+ Object model;
+
+ Map modelToEditPart = new HashMap();
+ List editParts = getSourceConnections();
+
+ for (i = 0; i < editParts.size(); i++) {
+ editPart = (ConnectionEditPart) editParts.get(i);
+ modelToEditPart.put(editPart.getModel(), editPart);
+ }
+
+ List modelObjects = getModelSourceConnections();
+ if (modelObjects == null)
+ modelObjects = new ArrayList();
+
+ for (i = 0; i < modelObjects.size(); i++) {
+ model = modelObjects.get(i);
+
+ if (i < editParts.size()) {
+ editPart = (ConnectionEditPart) editParts.get(i);
+ if (editPart.getModel() == model) {
+ if (editPart.getSource() != this)
+ editPart.setSource(this);
+ continue;
+ }
+ }
+
+ editPart = (ConnectionEditPart) modelToEditPart.get(model);
+ if (editPart != null)
+ reorderSourceConnection(editPart, i);
+ else {
+ editPart = createOrFindConnection(model);
+ addSourceConnection(editPart, i);
+ }
+ }
+
+ // Remove the remaining EditParts
+ List trash = new ArrayList();
+ for (; i < editParts.size(); i++)
+ trash.add(editParts.get(i));
+ for (i = 0; i < trash.size(); i++)
+ removeSourceConnection((ConnectionEditPart) trash.get(i));
+ }
+
+ protected void refreshTargetConnections() {
+ int i;
+ org.eclipse.gef.ConnectionEditPart editPart;
+ Object model;
+
+ Map mapModelToEditPart = new HashMap();
+ List connections = getTargetConnections();
+
+ for (i = 0; i < connections.size(); i++) {
+ editPart = (ConnectionEditPart) connections.get(i);
+ mapModelToEditPart.put(editPart.getModel(), editPart);
+ }
+
+ List modelObjects = getModelTargetConnections();
+ if (modelObjects == null)
+ modelObjects = new ArrayList();
+
+ for (i = 0; i < modelObjects.size(); i++) {
+ model = modelObjects.get(i);
+
+ if (i < connections.size()) {
+ editPart = (org.eclipse.gef.ConnectionEditPart) connections
+ .get(i);
+ if (editPart.getModel() == model) {
+ if (editPart.getTarget() != this)
+ editPart.setTarget(this);
+ continue;
+ }
+ }
+
+ editPart = (org.eclipse.gef.ConnectionEditPart) mapModelToEditPart
+ .get(model);
+ if (editPart != null)
+ reorderTargetConnection(editPart, i);
+ else {
+ editPart = createOrFindConnection(model);
+ addTargetConnection(editPart, i);
+ }
+ }
+
+ // Remove the remaining Connection EditParts
+ List trash = new ArrayList();
+ for (; i < connections.size(); i++)
+ trash.add(connections.get(i));
+ for (i = 0; i < trash.size(); i++)
+ removeTargetConnection((ConnectionEditPart) trash.get(i));
+ }
+
+ protected void removeSourceConnection(ConnectionEditPart connection) {
+ if (connection.getSource() != this)
+ return;
+ fireRemovingSourceConnection(connection, getSourceConnections()
+ .indexOf(connection));
+ connection.deactivate();
+ connection.setSource(null);
+ primRemoveSourceConnection(connection);
+ }
+
+ protected void removeTargetConnection(ConnectionEditPart connection) {
+ if (connection.getTarget() != this)
+ return;
+ fireRemovingTargetConnection(connection, getTargetConnections()
+ .indexOf(connection));
+ connection.setTarget(null);
+ primRemoveTargetConnection(connection);
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPartFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPartFactory.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPartFactory.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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.parts;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartFactory;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ComponentShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Connection;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ExpandeableShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
+
+
+public class OrmEditPartFactory implements EditPartFactory {
+
+
+ public EditPart createEditPart(EditPart context, Object modelElement) {
+ EditPart part = getPartForElement(modelElement);
+ part.setModel(modelElement);
+ return part;
+ }
+
+ private EditPart getPartForElement(Object modelElement) {
+ if (modelElement instanceof OrmDiagram) {
+ return new DiagramEditPart();
+ }
+ if (modelElement instanceof OrmShape) {
+ return new OrmShapeEditPart();
+ }
+ if (modelElement instanceof ComponentShape) {
+ return new ComponentShapeEditPart();
+ }
+ if (modelElement instanceof ExpandeableShape) {
+ return new ExpandeableShapeEditPart();
+ }
+ if (modelElement instanceof Shape) {
+ return new ShapeEditPart();
+ }
+ if (modelElement instanceof Connection) {
+ return new ConnectionEditPart();
+ }
+ throw new RuntimeException(
+ "Can't create part for model element: "
+ + ((modelElement != null) ? modelElement.getClass().getName() : "null"));
+ }
+
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmShapeEditPart.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmShapeEditPart.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * 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.parts;
+
+import java.beans.PropertyChangeEvent;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.MarginBorder;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.ToolbarLayout;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+import org.hibernate.mapping.Bag;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.SingleTableSubclass;
+import org.hibernate.mapping.Table;
+import org.jboss.tools.hibernate.ui.veditor.editors.figures.RoundLineBorder;
+import org.jboss.tools.hibernate.ui.veditor.editors.figures.TitleFigure;
+import org.jboss.tools.hibernate.ui.veditor.editors.figures.TitleLabel;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ExpandeableShape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
+
+
+public class OrmShapeEditPart extends ExpandeableShapeEditPart{
+
+ protected IFigure createFigure() {
+ if (getModel() instanceof OrmShape) {
+ TitleFigure figure = new TitleFigure();
+ figure.setLayoutManager(new ToolbarLayout());
+ TitleLabel label = new TitleLabel();
+ String text = "";
+ Object element = getCastedModel().getOrmElement();
+ if (element instanceof RootClass) {
+ text = ormLabelProvider.getText((PersistentClass)element);
+ } else if (element instanceof Table) {
+ Table table = (Table)element;
+ text = table.getSchema() + "." + table.getName();
+ }
+ label.setText(text);
+ label.setIcon(ormLabelProvider.getImage(getCastedModel().getOrmElement()));
+ FontData fontData[] = Display.getCurrent().getSystemFont().getFontData();
+ fontData[0].setStyle(SWT.BOLD);
+ //fontData[0].height++;
+ label.setFont(ResourceManager.getInstance().getFont(fontData[0]));
+ label.setBackgroundColor(getColor());
+ label.setIcon(ormLabelProvider.getImage(getCastedModel().getOrmElement()));
+ label.setLabelAlignment(PositionConstants.LEFT);
+ label.setBorder(new MarginBorder(1,2,1,2));
+ figure.add(label,-2);
+ label.setOpaque(true);
+ figure.setBackgroundColor(getBackgroundColor());
+ RoundLineBorder border = new RoundLineBorder();
+ border.setColor(ResourceManager.getInstance().getColor(new RGB(160, 160, 160)));
+ figure.setBorder(border);
+ figure.setSize(-1,-1);
+ return figure;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public void performRequest(Request req) {
+ if(RequestConstants.REQ_OPEN.equals(req.getType()) && getModel() instanceof
OrmShape) {
+ ((OrmShape)getModel()).refreshHiden();
+ }
+ }
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ String prop = evt.getPropertyName();
+ if (OrmShape.LOCATION_PROP.equals(prop)) {
+ refreshVisuals();
+ ((OrmDiagram)getParent().getModel()).setDirty(true);
+ } else if (OrmShape.SET_HIDEN.equals(prop)) {
+ int i = figure.getPreferredSize().width;
+ ((TitleFigure)figure).setHiden(((Boolean)evt.getNewValue()).booleanValue());
+ ((TitleLabel)figure.getChildren().get(0)).setHiden(((Boolean)evt.getNewValue()).booleanValue());
+ if(((Boolean)evt.getNewValue()).booleanValue())
+ figure.setSize(i,-1);
+ else
+ figure.setSize(-1,-1);
+ refresh();
+ ((OrmDiagram)getParent().getModel()).setDirty(true);
+ } else {
+ super.propertyChange(evt);
+ }
+ }
+
+ protected void refreshVisuals() {
+ Rectangle bounds = null;
+ if (getModel() instanceof OrmShape) {
+ bounds = new Rectangle(((OrmShape)getModel()).getLocation(), getFigure().getSize());
+ }
+ if (bounds != null) ((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), bounds);
+ }
+
+ protected Color getBackgroundColor() {
+ Object element = getCastedModel().getOrmElement();
+ if (element instanceof PersistentClass || element instanceof Component)
+ return ResourceManager.getInstance().getColor(new RGB(0,0,0));
+ else if (element instanceof Table || element instanceof Property)
+ return ResourceManager.getInstance().getColor(new RGB(
+ Integer.parseInt(Messages.Colors_DatabaseColumnR),
+ Integer.parseInt(Messages.Colors_DatabaseColumnG),
+ Integer.parseInt(Messages.Colors_DatabaseColumnB)));
+ else
+ throw new IllegalArgumentException();
+ }
+
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ResourceManager.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ResourceManager.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ResourceManager.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * 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.parts;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+public class ResourceManager {
+ private Map<RGB,Color> fColorTable = new HashMap<RGB,Color>(10);
+
+ private Map<FontData,Font> fFontTable = new HashMap<FontData,Font>(10);
+
+ private static ResourceManager resourceManager = new ResourceManager();
+
+ public static ResourceManager getInstance() {
+ return resourceManager;
+ }
+
+ private ResourceManager() {};
+
+ private void dispose() {
+ Iterator e = fColorTable.values().iterator();
+ while (e.hasNext())
+ ((Color) e.next()).dispose();
+ e = fFontTable.values().iterator();
+ while (e.hasNext())
+ ((Font) e.next()).dispose();
+ }
+ public Color getColor(RGB rgb) {
+ Color color = (Color) fColorTable.get(rgb);
+ if (color == null) {
+ color = new Color(Display.getCurrent(), rgb);
+ fColorTable.put(rgb, color);
+ }
+ return color;
+ }
+
+ public Font getFont(FontData fontData) {
+ Font font = (Font) fFontTable.get(fontData);
+ if (font == null) {
+ font = new Font(Display.getCurrent(), fontData);
+ fFontTable.put(fontData, font);
+ }
+ return font;
+ }
+
+ protected void finalize() throws Throwable {
+ dispose();
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,275 @@
+/*******************************************************************************
+ * 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.parts;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.ChopboxAnchor;
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.NodeEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gef.editpolicies.SelectionEditPolicy;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.hibernate.mapping.Any;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.DependantValue;
+import org.hibernate.mapping.OneToMany;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.SimpleValue;
+import org.hibernate.mapping.Table;
+import org.jboss.tools.hibernate.ui.veditor.editors.figures.TitleFigure;
+import org.jboss.tools.hibernate.ui.veditor.editors.figures.TopLineBorder;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Connection;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.ModelElement;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.SpecialRootClass;
+import org.jboss.tools.hibernate.ui.view.views.OrmLabelProvider;
+import org.jboss.tools.hibernate.ui.view.views.OrmModelImageVisitor;
+import org.jboss.tools.hibernate.ui.view.views.OrmModelNameVisitor;
+
+
+public class ShapeEditPart extends
+OrmEditPart implements PropertyChangeListener, NodeEditPart {
+
+ static protected OrmLabelProvider ormLabelProvider =
+ new OrmLabelProvider(new OrmModelImageVisitor(), new OrmModelNameVisitor(null));
+
+ protected void createEditPolicies() {
+ installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new
ShapesSelectionEditPolicy());
+ }
+
+
+ protected IFigure createFigure() {
+ if (getModel() instanceof Shape) {
+ Label label = new Label();
+ label.setText(ormLabelProvider.getText(getElement()));
+ label.setBackgroundColor(getColor());
+ label.setIcon(ormLabelProvider.getImage(getElement()));
+ label.setLabelAlignment(PositionConstants.LEFT);
+ label.setOpaque(true);
+ TopLineBorder border = new TopLineBorder(1,2+getCastedModel().getIndent(),1,2);
+ border.setColor(getOrmShapeEditPart().getColor());
+ label.setBorder(border);
+ return label;
+ } else {
+ throw new IllegalArgumentException();
+ }
+ }
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ String prop = evt.getPropertyName();
+ if (Shape.SHOW_SELECTION.equals(prop)) {
+ getFigure().setBackgroundColor(getSelectionColor());
+ getFigure().setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(255,255,255)));
+ } else if (Shape.HIDE_SELECTION.equals(prop)) {
+ getFigure().setBackgroundColor(getColor());
+ getFigure().setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(0,0,0)));
+ } else if (Shape.SET_FOCUS.equals(prop)) {
+ getViewer().select(this);
+ getViewer().reveal(this);
+ }
+ refresh();
+ }
+
+ public void performRequest(Request req) {
+ if(RequestConstants.REQ_OPEN.equals(req.getType())) {
+// if (getCastedModel().getOrmElement() instanceof IDatabaseColumn) {
+ if (getCastedModel().getOrmElement() instanceof Column) {
+ if(getCastedModel().getTargetConnections().size() > 0)
+ ((Connection)getCastedModel().getTargetConnections().get(0)).getSource().setFocus();
+ } else {
+ if(getCastedModel().getSourceConnections().size() > 0)
+ ((Connection)getCastedModel().getSourceConnections().get(0)).getTarget().setFocus();
+ }
+ }
+ }
+
+ public void activate() {
+ if (!isActive()) {
+ super.activate();
+ ((ModelElement) getModel()).addPropertyChangeListener(this);
+ }
+ }
+
+ public void deactivate() {
+ if (isActive()) {
+ super.deactivate();
+ ((ModelElement) getModel()).removePropertyChangeListener(this);
+ }
+ }
+
+ protected Shape getCastedModel() {
+ return (Shape) getModel();
+ }
+
+ protected List getModelSourceConnections() {
+ return getCastedModel().getSourceConnections();
+ }
+
+ protected List getModelTargetConnections() {
+ return getCastedModel().getTargetConnections();
+ }
+
+ public ConnectionAnchor getSourceConnectionAnchor(ConnectionEditPart connection) {
+ return getConnectionAnchor();
+ }
+
+ public ConnectionAnchor getTargetConnectionAnchor(ConnectionEditPart connection) {
+ return getConnectionAnchor();
+ }
+
+ public ConnectionAnchor getSourceConnectionAnchor(Request request) {
+ return getConnectionAnchor();
+ }
+
+ public ConnectionAnchor getTargetConnectionAnchor(Request request) {
+ return getConnectionAnchor();
+ }
+
+ protected ConnectionAnchor getConnectionAnchor() {
+ ChopboxAnchor anchor = new ChopboxAnchor(getFigure()){
+ public Point getLocation(Point reference) {
+ Rectangle r = getOwner().getBounds().getCopy();
+ getOwner().translateToAbsolute(r);
+ if (getOwner() instanceof TitleFigure) {
+ r = ((IFigure)getOwner().getChildren().get(0)).getBounds().getCopy();
+ ((IFigure)getOwner().getChildren().get(0)).translateToAbsolute(r);
+ }
+ OrmShapeEditPart part = getOrmShapeEditPart();
+ Point p = r.getCenter();
+ if (reference.x < p.x)
+ p.x-=part.getFigure().getBounds().width/2;
+ else
+ p.x+=part.getFigure().getBounds().width/2;
+ return p;
+ }
+ };
+ return anchor;
+ }
+
+ private OrmShapeEditPart getOrmShapeEditPart() {
+ int i = 0;
+ EditPart part = this;
+ while (!((part instanceof OrmShapeEditPart))) {
+ part = part.getParent();
+ if(i++ > 4)
+ throw new RuntimeException();
+ }
+ return (OrmShapeEditPart)part;
+ }
+
+ protected Color getColor() {
+ Object element = getCastedModel().getOrmElement();
+ if (element instanceof PersistentClass || element instanceof Component)
+ return ResourceManager.getInstance().getColor(new RGB(
+ Integer.parseInt(Messages.Colors_PersistentClassR),
+ Integer.parseInt(Messages.Colors_PersistentClassG),
+ Integer.parseInt(Messages.Colors_PersistentClassB)));
+//R if (getCastedModel().getOrmElement() instanceof IPersistentField ||
getCastedModel().getOrmElement() instanceof IHibernateValueMapping)
+ else if (element instanceof Property || element instanceof SimpleValue)
+ return ResourceManager.getInstance().getColor(new RGB(
+ Integer.parseInt(Messages.Colors_PersistentFieldR),
+ Integer.parseInt(Messages.Colors_PersistentFieldG),
+ Integer.parseInt(Messages.Colors_PersistentFieldB)));
+//R else if (getCastedModel().getOrmElement() instanceof IDatabaseColumn)
+ else if (element instanceof Column)
+ return ResourceManager.getInstance().getColor(new RGB(
+ Integer.parseInt(Messages.Colors_DatabaseColumnR),
+ Integer.parseInt(Messages.Colors_DatabaseColumnG),
+ Integer.parseInt(Messages.Colors_DatabaseColumnB)));
+//R else if (getCastedModel().getOrmElement() instanceof IPersistentClass)
+//R else if (getCastedModel().getOrmElement() instanceof IDatabaseTable)
+ else if (element instanceof Table)
+ return ResourceManager.getInstance().getColor(new RGB(
+ Integer.parseInt(Messages.Colors_DatabaseTableR),
+ Integer.parseInt(Messages.Colors_DatabaseTableG),
+ Integer.parseInt(Messages.Colors_DatabaseTableB)));
+ else if (element instanceof DependantValue)
+ return ResourceManager.getInstance().getColor(new RGB(
+ Integer.parseInt(Messages.Colors_DatabaseTableR),
+ Integer.parseInt(Messages.Colors_DatabaseTableG),
+ Integer.parseInt(Messages.Colors_DatabaseTableB)));
+ else if (element instanceof OneToMany)
+ return ResourceManager.getInstance().getColor(new RGB(
+ Integer.parseInt(Messages.Colors_DatabaseTableR),
+ Integer.parseInt(Messages.Colors_DatabaseTableG),
+ Integer.parseInt(Messages.Colors_DatabaseTableB)));
+ else
+ throw new IllegalArgumentException();
+ }
+
+ protected Color getSelectionColor() {
+ if (getCastedModel().getOrmElement() instanceof PersistentClass ||
+ getCastedModel().getOrmElement() instanceof Property ||
+ getCastedModel().getOrmElement() instanceof SimpleValue ||
+ getCastedModel().getOrmElement() instanceof OneToMany)
+ return ResourceManager.getInstance().getColor(new RGB(112,161,99));
+ else if (getCastedModel().getOrmElement() instanceof Table ||
getCastedModel().getOrmElement() instanceof Column)
+ return ResourceManager.getInstance().getColor(new RGB(66,173,247));
+ else
+ throw new IllegalArgumentException();
+ }
+
+ private class ShapesSelectionEditPolicy extends SelectionEditPolicy {
+
+ protected void hideSelection() {
+ getCastedModel().hideSelection();
+ Iterator iter = getCastedModel().getSourceConnections().iterator();
+ while (iter.hasNext()) {
+ Connection element = (Connection) iter.next();
+ element.hideSelection();
+ }
+ iter = getCastedModel().getTargetConnections().iterator();
+ while (iter.hasNext()) {
+ Connection element = (Connection) iter.next();
+ element.hideSelection();
+ }
+ }
+
+ protected void showSelection() {
+ getCastedModel().showSelection();
+ Iterator iter = getCastedModel().getSourceConnections().iterator();
+ while (iter.hasNext()) {
+ Connection element = (Connection) iter.next();
+ element.showSelection();
+ }
+ iter = getCastedModel().getTargetConnections().iterator();
+ while (iter.hasNext()) {
+ Connection element = (Connection) iter.next();
+ element.showSelection();
+ }
+ }
+
+ }
+
+ private Object getElement() {
+ Object element = getCastedModel().getOrmElement();
+ if (element instanceof SpecialRootClass) element = (RootClass)element;
+ return element;
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/messages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/messages.properties
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/messages.properties 2007-07-05
12:01:50 UTC (rev 2313)
@@ -0,0 +1,12 @@
+Colors_PersistentClassR=255
+Colors_PersistentClassG=247
+Colors_PersistentClassB=206
+Colors_PersistentFieldR=255
+Colors_PersistentFieldG=255
+Colors_PersistentFieldB=239
+Colors_DatabaseTableR=222
+Colors_DatabaseTableG=231
+Colors_DatabaseTableB=239
+Colors_DatabaseColumnR=239
+Colors_DatabaseColumnG=247
+Colors_DatabaseColumnB=255
\ No newline at end of file