Author: dazarov
Date: 2007-07-04 09:08:36 -0400 (Wed, 04 Jul 2007)
New Revision: 2282
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/IDiagramInfo.java
Removed:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/IProcessInfo.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/AutoLayout.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/Example.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/impl/AutoLayoutImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/impl/Items.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/model/OrmDiagram.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/parts/DiagramEditPart.java
Log:
http://jira.jboss.com/jira/browse/EXIN-368
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/AutoLayout.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/AutoLayout.java 2007-07-04
12:53:38 UTC (rev 2281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/AutoLayout.java 2007-07-04
13:08:36 UTC (rev 2282)
@@ -37,7 +37,7 @@
engine.setOverride(b);
}
- public void setProcess(IProcessInfo process) {
+ public void setProcess(IDiagramInfo process) {
engine.setProcess(process);
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/Example.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/Example.java 2007-07-04
12:53:38 UTC (rev 2281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/Example.java 2007-07-04
13:08:36 UTC (rev 2282)
@@ -14,7 +14,7 @@
public class Example {
- public static IProcessInfo generateRandomProcess(int nodeCount, int linkCount) {
+ public static IDiagramInfo generateRandomProcess(int nodeCount, int linkCount) {
ProcessInfoImpl process = new ProcessInfoImpl();
for (int i = 0; i < nodeCount; i++) {
ItemInfoImpl item = new ItemInfoImpl();
@@ -33,7 +33,7 @@
return process;
}
- static void printProcess(IProcessInfo process) {
+ static void printProcess(IDiagramInfo process) {
IItemInfo[] items = process.getItems();
for (int i = 0; i < items.length; i++) printItem(items[i]);
}
@@ -55,7 +55,7 @@
}
public static void main(String[] args) {
- IProcessInfo process = generateRandomProcess(10, 17);
+ IDiagramInfo process = generateRandomProcess(10, 17);
System.out.println("Before Layout");
printProcess(process);
AutoLayout layout = new AutoLayout();
@@ -67,7 +67,7 @@
}
}
-class ProcessInfoImpl implements IProcessInfo {
+class ProcessInfoImpl implements IDiagramInfo {
ArrayList items = new ArrayList();
public IItemInfo[] getItems() {
Copied:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/IDiagramInfo.java
(from rev 2257,
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/IProcessInfo.java)
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/IDiagramInfo.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/IDiagramInfo.java 2007-07-04
13:08:36 UTC (rev 2282)
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * 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.veditor.editors.autolayout;
+
+public interface IDiagramInfo {
+ IItemInfo[] getItems();
+}
Deleted:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/IProcessInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/IProcessInfo.java 2007-07-04
12:53:38 UTC (rev 2281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/IProcessInfo.java 2007-07-04
13:08:36 UTC (rev 2282)
@@ -1,15 +0,0 @@
-/*******************************************************************************
- * 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.veditor.editors.autolayout;
-
-public interface IProcessInfo {
- IItemInfo[] getItems();
-}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/impl/AutoLayoutImpl.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/impl/AutoLayoutImpl.java 2007-07-04
12:53:38 UTC (rev 2281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/impl/AutoLayoutImpl.java 2007-07-04
13:08:36 UTC (rev 2282)
@@ -12,7 +12,7 @@
import org.jboss.tools.hibernate.veditor.editors.autolayout.IItemInfo;
import org.jboss.tools.hibernate.veditor.editors.autolayout.ILinkInfo;
-import org.jboss.tools.hibernate.veditor.editors.autolayout.IProcessInfo;
+import org.jboss.tools.hibernate.veditor.editors.autolayout.IDiagramInfo;
public class AutoLayoutImpl {
@@ -34,7 +34,7 @@
items.setOverride(b);
}
- public void setProcess(IProcessInfo process) {
+ public void setProcess(IDiagramInfo process) {
// constants.update();
items.setProcess(process);
apply();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/impl/Items.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/impl/Items.java 2007-07-04
12:53:38 UTC (rev 2281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/autolayout/impl/Items.java 2007-07-04
13:08:36 UTC (rev 2282)
@@ -14,12 +14,12 @@
import org.jboss.tools.hibernate.veditor.editors.autolayout.IItemInfo;
import org.jboss.tools.hibernate.veditor.editors.autolayout.ILinkInfo;
-import org.jboss.tools.hibernate.veditor.editors.autolayout.IProcessInfo;
+import org.jboss.tools.hibernate.veditor.editors.autolayout.IDiagramInfo;
public class Items {
protected LayuotConstants constants;
- protected IProcessInfo process;
+ protected IDiagramInfo process;
protected Item[] items;
protected Map paths = new HashMap();
protected Groups groups = new Groups();
@@ -36,7 +36,7 @@
override = b;
}
- public void setProcess(IProcessInfo process) {
+ public void setProcess(IDiagramInfo process) {
this.process = process;
try { load(); } catch (Exception e) { e.printStackTrace(); }
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/model/OrmDiagram.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/model/OrmDiagram.java 2007-07-04
12:53:38 UTC (rev 2281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/model/OrmDiagram.java 2007-07-04
13:08:36 UTC (rev 2282)
@@ -45,7 +45,6 @@
import org.jboss.tools.hibernate.veditor.VizualEditorPlugin;
import org.jboss.tools.hibernate.veditor.editors.autolayout.IItemInfo;
import org.jboss.tools.hibernate.veditor.editors.autolayout.ILinkInfo;
-import org.jboss.tools.hibernate.veditor.editors.autolayout.IProcessInfo;
/**
@@ -376,158 +375,4 @@
}
return classShape;
}
-
- class DiagramInfo implements IProcessInfo {
-
- ArrayList items = new ArrayList();
-
- /**
- *
- * @param flow
- */
- public DiagramInfo() {
- IItemInfo item;
-
- for (int i = 0; i < getChildren().size(); i++) {
- item = new DiagramElementInfo((OrmShape) 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;
- shape[2] = 100;
- 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) {
- }
- }
-
}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/parts/DiagramEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/parts/DiagramEditPart.java 2007-07-04
12:53:38 UTC (rev 2281)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/veditor/editors/parts/DiagramEditPart.java 2007-07-04
13:08:36 UTC (rev 2282)
@@ -7,11 +7,12 @@
*
* Contributors:
* Exadel, Inc. and Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+ ******************************************************************************/
package org.jboss.tools.hibernate.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;
@@ -43,128 +44,151 @@
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.Table;
import org.jboss.tools.hibernate.veditor.editors.VizualEditor;
+import org.jboss.tools.hibernate.veditor.editors.autolayout.AutoLayout;
+import org.jboss.tools.hibernate.veditor.editors.autolayout.IItemInfo;
+import org.jboss.tools.hibernate.veditor.editors.autolayout.ILinkInfo;
+import org.jboss.tools.hibernate.veditor.editors.autolayout.IDiagramInfo;
import org.jboss.tools.hibernate.veditor.editors.command.ShapeSetConstraintCommand;
+import org.jboss.tools.hibernate.veditor.editors.model.Connection;
import org.jboss.tools.hibernate.veditor.editors.model.ModelElement;
import org.jboss.tools.hibernate.veditor.editors.model.OrmDiagram;
import org.jboss.tools.hibernate.veditor.editors.model.OrmShape;
+import org.jboss.tools.hibernate.veditor.editors.model.Shape;
import org.jboss.tools.hibernate.veditor.editors.model.SpecialOrmShape;
import org.jboss.tools.hibernate.veditor.editors.model.SpecialRootClass;
-
/**
* @author Konstantin Mishin
- *
+ *
*/
-class DiagramEditPart extends OrmEditPart implements PropertyChangeListener{
-
+class DiagramEditPart extends OrmEditPart implements PropertyChangeListener {
+
protected void createEditPolicies() {
- installEditPolicy(EditPolicy.LAYOUT_ROLE, new ShapesXYLayoutEditPolicy());
+ 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);
+
+ 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();
- restore();
+ autolayout();
+ // restore();
} else if (OrmDiagram.DIRTY.equals(prop))
- ((VizualEditor)((DefaultEditDomain)getViewer().getEditDomain()).getEditorPart()).refreshDirty();
+ ((VizualEditor) ((DefaultEditDomain) getViewer().getEditDomain())
+ .getEditorPart()).refreshDirty();
}
-
+
public void restore() {
boolean dirty = getCastedModel().isDirty();
HashMap hashMap = getCastedModel().getCloneElements();
- String childrenLocations[] = getCastedModel().getChildrenLocations();
+ 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 (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);
+ string = childrenLocations[i]
+ .substring(childrenLocations[i].indexOf('@') + 1);
xy = string.split(";");
- if(xy.length>1)
+ 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.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)
+ 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());
+ RootClass persistentClass = (RootClass) getCastedModel()
+ .getOrmElement();
+ ormShape = (OrmShape) hashMap
+ .remove(persistentClass.getClassName());
if (ormShape != null) {
- ormShape.setLocation(new Point(20,20));
- tempPoint = 40 + getChildrenFigurePreferredHeight(ormShape);
+ ormShape.setLocation(new Point(20, 20));
+ tempPoint = 40 + getChildrenFigurePreferredHeight(ormShape);
}
Table table = persistentClass.getTable();
- ormShape = (OrmShape)hashMap.remove(table.getSchema() + "." +
table.getName());
+ ormShape = (OrmShape) hashMap.remove(table.getSchema() + "."
+ + table.getName());
if (ormShape != null) {
- ormShape.setLocation(new Point(pointX,20));
+ ormShape.setLocation(new Point(pointX, 20));
point = 40 + getChildrenFigurePreferredHeight(ormShape);
}
- if(tempPoint > point)
+ 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)
+ 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));
+ 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);
+ part = (GraphicalEditPart) getChildren().get(i);
if (ormShape.equals(part.getModel()))
return part.getFigure().getPreferredSize().height;
}
@@ -175,7 +199,7 @@
int j = 0;
IFigure figure;
for (int i = 0; i < getFigure().getChildren().size(); i++) {
- figure = (IFigure)getFigure().getChildren().get(i);
+ figure = (IFigure) getFigure().getChildren().get(i);
if (figure.getPreferredSize().width > j)
j = figure.getPreferredSize().width;
}
@@ -183,22 +207,32 @@
}
protected List getModelChildren() {
- return getCastedModel().getChildren();
+ return getCastedModel().getChildren();
}
-
+
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
- restore();
+ autolayout();
+ // restore();
}
}
-
- public void setToFront(EditPart ep){
+
+ 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);
+ if (index == -1)
+ return;
+ if (index != getChildren().size() - 1)
+ reorderChild(ep, getChildren().size() - 1);
}
public void deactivate() {
@@ -207,36 +241,198 @@
((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());
+
+ 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);
+ return super.createChangeConstraintCommand(request, child,
+ constraint);
}
-
+
protected Command createAddCommand(EditPart child, Object constraint) {
return null;
}
-
- protected Command createChangeConstraintCommand(EditPart child, Object constraint) {
+
+ 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();
}
}
-}
\ No newline at end of file
+
+
+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)
+ // shape[2] = part.getFigure().getSize().width;
+ //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) {
+ }
+ }
+}}