Author: mdryakhlenkov
Date: 2007-07-05 07:59:42 -0400 (Thu, 05 Jul 2007)
New Revision: 2307
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/AutoLayout.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/Example.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/IDiagramInfo.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/IItemInfo.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/ILinkInfo.java
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/autolayout/AutoLayout.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/AutoLayout.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/AutoLayout.java 2007-07-05
11:59:42 UTC (rev 2307)
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.autolayout;
+
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.impl.AutoLayoutImpl;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.impl.Items;
+
+
+public class AutoLayout {
+ AutoLayoutImpl engine = new AutoLayoutImpl();
+
+ public AutoLayout() {
+ this(new Items());
+ }
+
+ public AutoLayout(Items items) {
+ setItems(items);
+ }
+
+ public void setGridStep(String gridStep) {
+ engine.setGridStep(gridStep);
+ }
+
+ public void setItems(Items items) {
+ engine.setItems(items);
+ }
+
+ public void setOverride(boolean b) {
+ engine.setOverride(b);
+ }
+
+ public void setProcess(IDiagramInfo process) {
+ engine.setProcess(process);
+ }
+
+}
\ No newline at end of file
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/Example.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/Example.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/Example.java 2007-07-05
11:59:42 UTC (rev 2307)
@@ -0,0 +1,132 @@
+/*******************************************************************************
+ * 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.autolayout;
+
+import java.util.ArrayList;
+
+public class Example {
+
+ public static IDiagramInfo generateRandomProcess(int nodeCount, int linkCount) {
+ ProcessInfoImpl process = new ProcessInfoImpl();
+ for (int i = 0; i < nodeCount; i++) {
+ ItemInfoImpl item = new ItemInfoImpl();
+ item.setID("n_" + i);
+ process.addItem(item);
+ }
+ IItemInfo[] items = process.getItems();
+ for (int i = 0; i < linkCount; i++) {
+ int n1 = (int)(nodeCount * Math.random());
+ int n2 = (int)(nodeCount * Math.random());
+ String target = ((ItemInfoImpl)items[n2]).getID();
+ LinkInfoImpl link = new LinkInfoImpl();
+ link.setTargetID(target);
+ ((ItemInfoImpl)items[n1]).addLink(link);
+ }
+ return process;
+ }
+
+ static void printProcess(IDiagramInfo process) {
+ IItemInfo[] items = process.getItems();
+ for (int i = 0; i < items.length; i++) printItem(items[i]);
+ }
+
+ static void printItem(IItemInfo item) {
+ System.out.print(item.getID() + " (");
+ int[] shape = item.getShape();
+ for (int i = 0; i < shape.length; i++) {
+ if(i > 0) System.out.print(",");
+ System.out.print(shape[i]);
+ }
+ System.out.print(") -->");
+ ILinkInfo[] links = item.getLinks();
+ for (int i = 0; i < links.length; i++) {
+ if(i > 0) System.out.print(",");
+ System.out.print(links[i].getTargetID());
+ }
+ System.out.println("");
+ }
+
+ public static void main(String[] args) {
+ IDiagramInfo process = generateRandomProcess(10, 17);
+ System.out.println("Before Layout");
+ printProcess(process);
+ AutoLayout layout = new AutoLayout();
+ layout.setGridStep("" + 8);
+ layout.setOverride(true);
+ layout.setProcess(process);
+ System.out.println("After Layout");
+ printProcess(process);
+ }
+}
+
+class ProcessInfoImpl implements IDiagramInfo {
+ ArrayList items = new ArrayList();
+
+ public IItemInfo[] getItems() {
+ return (IItemInfo[])items.toArray(new IItemInfo[0]);
+ }
+
+ public void addItem(IItemInfo item) {
+ items.add(item);
+ }
+
+}
+
+class ItemInfoImpl implements IItemInfo {
+ String id = "";
+ int[] shape = new int[0];
+ ArrayList links = new ArrayList();
+
+ public void setID(String id) {
+ this.id = id;
+ }
+
+ public String getID() {
+ return id;
+ }
+
+ public boolean isComment() {
+ return false;
+ }
+
+ public int[] getShape() {
+ return shape;
+ }
+
+ public ILinkInfo[] getLinks() {
+ return (ILinkInfo[])links.toArray(new ILinkInfo[0]);
+ }
+
+ public void addLink(ILinkInfo link) {
+ links.add(link);
+ }
+
+ public void setShape(int[] s) {
+ this.shape = s;
+ }
+
+}
+
+class LinkInfoImpl implements ILinkInfo {
+ String target;
+
+ public void setTargetID(String target) {
+ this.target = target;
+ }
+
+ public String getTargetID() {
+ return target;
+ }
+
+ public void setLinkShape(int[] vs) {
+ }
+
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/IDiagramInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/IDiagramInfo.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/IDiagramInfo.java 2007-07-05
11:59:42 UTC (rev 2307)
@@ -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.ui.veditor.editors.autolayout;
+
+public interface IDiagramInfo {
+ IItemInfo[] getItems();
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/IItemInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/IItemInfo.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/IItemInfo.java 2007-07-05
11:59:42 UTC (rev 2307)
@@ -0,0 +1,19 @@
+/*******************************************************************************
+ * 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.autolayout;
+
+public interface IItemInfo {
+ public String getID();
+ public boolean isComment();
+ public int[] getShape();
+ ILinkInfo[] getLinks();
+ public void setShape(int[] s);
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/ILinkInfo.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/ILinkInfo.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/ILinkInfo.java 2007-07-05
11:59:42 UTC (rev 2307)
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * 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.autolayout;
+
+public interface ILinkInfo {
+ public String getTargetID();
+ public void setLinkShape(int[] vs);
+}