JBoss Tools SVN: r2312 - trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model.
by jbosstools-commits@lists.jboss.org
Author: mdryakhlenkov
Date: 2007-07-05 08:01:25 -0400 (Thu, 05 Jul 2007)
New Revision: 2312
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ComponentShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Connection.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialOrmShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.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/model/ComponentShape.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ComponentShape.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ComponentShape.java 2007-07-05 12:01:25 UTC (rev 2312)
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.util.Iterator;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Table;
+
+public class ComponentShape extends ExpandeableShape {
+ public static final String SET_CHILDS_HIDEN = "set childs hiden";
+
+ protected boolean childsHiden = true;
+
+ public ComponentShape(Object ioe) {
+ super(ioe);
+ Shape bodyOrmShape;
+ if (ioe instanceof Property) {
+ Collection collection = (Collection)((Property)ioe).getValue();
+ bodyOrmShape = new Shape(collection.getKey());
+ bodyOrmShape.setIndent(20);
+ getChildren().add(bodyOrmShape);
+ bodyOrmShape = new Shape(collection.getElement());
+ bodyOrmShape.setIndent(20);
+ getChildren().add(bodyOrmShape);
+ }
+ }
+
+ protected void setChildsHiden(boolean hiden) {
+ for (int i = 0; i < getChildren().size(); i++)
+ ((Shape)getChildren().get(i)).setHiden(hiden);
+ }
+
+ public void refreshChildsHiden(OrmDiagram ormDiagram) {
+ childsHiden = !childsHiden;
+ for (int i = 0; i < getChildren().size(); i++)
+ ((Shape)getChildren().get(i)).setHiden(childsHiden);
+ firePropertyChange(SET_CHILDS_HIDEN, null, new Boolean(childsHiden));
+ ormDiagram.refreshComponentReferences(this);
+ }
+}
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Connection.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Connection.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Connection.java 2007-07-05 12:01:25 UTC (rev 2312)
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * 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.model;
+
+public class Connection extends ModelElement {
+ public static final String HIDE_SELECTION = "hide selection";
+ public static final String SHOW_SELECTION = "show selection";
+ public static final String SET_HIDEN = "set hiden";
+
+ private Shape source;
+ private Shape target;
+
+ private int needHide;
+
+ public Connection(Shape s, Shape newTarget) {
+ if (s == null || newTarget == null || s == newTarget) {
+ throw new IllegalArgumentException();
+ }
+ needHide = 2;
+ this.source = s;
+ this.target = newTarget;
+ source.addConnection(this);
+ target.addConnection(this);
+ }
+
+ public Shape getSource() {
+ return source;
+ }
+
+ public Shape getTarget() {
+ return target;
+ }
+
+ public void hideSelection() {
+ firePropertyChange(HIDE_SELECTION, null, null);
+ source.firePropertyChange(Shape.HIDE_SELECTION, null, null);
+ target.firePropertyChange(Shape.HIDE_SELECTION, null, null);
+ }
+
+ public void showSelection() {
+ firePropertyChange(SHOW_SELECTION, null, null);
+ source.firePropertyChange(Shape.SHOW_SELECTION, null, null);
+ target.firePropertyChange(Shape.SHOW_SELECTION, null, null);
+ }
+
+ public void setHiden(boolean hiden) {
+ if(hiden) {
+ needHide--;
+ if(needHide == 0)
+ return;
+ } else {
+ needHide++;
+ if(needHide == 1)
+ return;
+ }
+ firePropertyChange(SET_HIDEN, null, new Boolean(hiden));
+ }
+
+ public boolean isHiden() {
+ return needHide != 2;
+ }
+}
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java 2007-07-05 12:01:25 UTC (rev 2312)
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.beans.PropertyChangeEvent;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.swt.graphics.RGB;
+import org.jboss.tools.hibernate.ui.veditor.editors.parts.ResourceManager;
+
+public class ExpandeableShape extends Shape {
+
+ public static final String SHOW_REFERENCES = "show references";
+
+ private boolean refHide = false;
+
+ public ExpandeableShape(Object ioe) {
+ super(ioe);
+ }
+
+ public void refreshReferences(Object model) {
+ refHide = !refHide;
+ if (model instanceof OrmDiagram) {
+ ((OrmDiagram)model).processExpand(this);
+ }
+ firePropertyChange(SHOW_REFERENCES, null, new Boolean(refHide));
+ }
+
+ protected boolean getHide() {
+ return refHide;
+ }
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java 2007-07-05 12:01:25 UTC (rev 2312)
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class ModelElement{
+
+ private transient PropertyChangeSupport pcsDelegate = new PropertyChangeSupport(this);
+
+ public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
+ if (l == null) {
+ throw new IllegalArgumentException();
+ }
+ pcsDelegate.addPropertyChangeListener(l);
+ }
+
+ protected void firePropertyChange(String property, Object oldValue, Object newValue) {
+ if (pcsDelegate.hasListeners(property)) {
+ pcsDelegate.firePropertyChange(property, oldValue, newValue);
+ }
+ }
+
+ public synchronized void removePropertyChangeListener(PropertyChangeListener l) {
+ if (l != null) {
+ pcsDelegate.removePropertyChangeListener(l);
+ }
+ }
+
+ private List children = new OList();
+ private ModelElement parent;
+
+ public List getChildren(){
+ return children;
+ }
+
+ public ModelElement getParent(){
+ return parent;
+ }
+
+ public void setParent(ModelElement element){
+ parent = element;
+ }
+
+ class OList extends ArrayList{
+ public OList(){
+
+ }
+
+ public boolean add(Object item){
+ if(item instanceof ModelElement)((ModelElement)item).setParent(ModelElement.this);
+ return super.add(item);
+ }
+
+ public boolean remove(Object item){
+ if(item instanceof ModelElement)((ModelElement)item).setParent(null);
+ return super.remove(item);
+ }
+ }
+
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2007-07-05 12:01:25 UTC (rev 2312)
@@ -0,0 +1,387 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.draw2d.geometry.Point;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.ImageConstants;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.mapping.Bag;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.DependantValue;
+import org.hibernate.mapping.Formula;
+import org.hibernate.mapping.KeyValue;
+import org.hibernate.mapping.ManyToOne;
+import org.hibernate.mapping.Map;
+import org.hibernate.mapping.OneToMany;
+import org.hibernate.mapping.OneToOne;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.Set;
+import org.hibernate.mapping.SimpleValue;
+import org.hibernate.mapping.SingleTableSubclass;
+import org.hibernate.mapping.Table;
+import org.hibernate.mapping.Value;
+import org.hibernate.type.EntityType;
+import org.hibernate.type.Type;
+import org.jboss.tools.hibernate.ui.veditor.VisualEditorPlugin;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.IItemInfo;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.ILinkInfo;
+
+
+public class OrmDiagram extends ModelElement {
+
+ public static final String REFRESH = "refresh";
+ public static final String DIRTY = "dirty";
+ private static final String qualifiedNameString = "OrmDiagramChildrenLocations";
+ private boolean dirty = false;
+ private String childrenLocations[];
+ private IResource resource = null;
+ private HashMap<String,OrmShape> elements = new HashMap<String,OrmShape>();
+ private RootClass ormElement;
+ private Configuration configuration;
+
+
+ public OrmDiagram(Configuration configuration, RootClass ioe) {
+ this.configuration = configuration;
+ ormElement = (RootClass)ioe;
+ if (ormElement instanceof RootClass) {
+ String string = "";
+// resource =((RootClass)ormElement).getPersistentClassMapping().getStorage().getResource();
+// try {
+// int i = 0;
+// String tempString;
+// do {
+// tempString = resource.getPersistentProperty(new QualifiedName(VisualEditorPlugin.PLUGIN_ID,qualifiedNameString+i++));
+// string += tempString;
+// } while (tempString != null);
+// } catch (CoreException e) {
+//// ExceptionHandler.logThrowableError(e, e.getMessage());
+// }
+ childrenLocations = string.split("#");
+ } //else
+// throw new IllegalArgumentException();
+ getOrCreatePersistentClass(ormElement, null);
+
+ }
+
+ public HashMap getCloneElements() {
+ return (HashMap)elements.clone();
+ }
+
+ public RootClass getOrmElement() {
+ return ormElement;
+ }
+
+ public void refresh() {
+ saveHelper();
+ getChildren().clear();
+ elements.clear();
+// if( ((IPersistentClass)ormElement).getProjectMapping().findClass(ormElement.getName()) != null)
+/// getOrCreatePersistentClass((IPersistentClass)ormElement, null);
+ firePropertyChange(REFRESH, null, null);
+ }
+
+ public void save() {
+ String string = "";
+ saveHelper();
+ for (int i = 0; i < childrenLocations.length; i++)
+ string+=childrenLocations[i]+"#";
+ if(resource.exists() && string.length() > 0)
+ try {
+ int i = 0;
+ while(string.length() > 2048*(i+1)) {
+ resource.setPersistentProperty((new QualifiedName(VisualEditorPlugin.PLUGIN_ID,qualifiedNameString+i)),
+ string.substring(2048*i,2048*(i++)+2047));
+ }
+ resource.setPersistentProperty((new QualifiedName(VisualEditorPlugin.PLUGIN_ID,qualifiedNameString+i)),
+ string.substring(2048*i));
+ } catch (CoreException e) {
+// ExceptionHandler.logThrowableError(e, e.getMessage());
+ }
+ }
+
+ private void saveHelper() {
+ childrenLocations = new String[getChildren().size()];
+ for (int i = 0; i < getChildren().size(); i++) {
+ OrmShape shape = (OrmShape) getChildren().get(i);
+ Object ormElement = shape.getOrmElement();
+ if (ormElement instanceof RootClass) {
+ childrenLocations[i] = ((RootClass)ormElement).getClassName() + "@";
+ } else if (ormElement instanceof Table) {
+ childrenLocations[i] = ((Table)ormElement).getSchema() + "." + ((Table)ormElement).getName()+"@";
+// } else if (ormElement instanceof Component) {
+// childrenLocations[i] = ((Component)ormElement).getComponentClassName()+"@";
+ }
+ childrenLocations[i] += shape.getLocation().x + ";" + shape.getLocation().y+";" + shape.isHiden();
+ }
+ }
+
+ private OrmShape createShape(Object ormElement) {
+ OrmShape ormShape = null;
+ if (ormElement instanceof RootClass) {
+ ormShape = new OrmShape(ormElement);
+ getChildren().add(ormShape);
+ elements.put(((RootClass)ormElement).getClassName(), ormShape);
+ } else if (ormElement instanceof Table) {
+ ormShape = new OrmShape(ormElement);
+ getChildren().add(ormShape);
+ Table table = (Table)ormElement;
+ elements.put(table.getSchema() + "." + table.getName(), ormShape);
+ } else if (ormElement instanceof Property) {
+// ormShape = new OrmShape(ormElement);
+ SpecialRootClass specialRootClass = new SpecialRootClass((Property)ormElement);
+ ormShape = new SpecialOrmShape(specialRootClass);
+ getChildren().add(ormShape);
+// Property property = (Property)ormElement;
+// elements.put(property.getPersistentClass().getEntityName() + "." + property.getName(), ormShape);
+ elements.put(specialRootClass.getClassName(), ormShape);
+ } else if (ormElement instanceof SingleTableSubclass) {
+ ormShape = new OrmShape(ormElement);
+ getChildren().add(ormShape);
+ elements.put(((SingleTableSubclass)ormElement).getEntityName(), ormShape);
+ }
+ return ormShape;
+ }
+
+ private OrmShape getOrCreatePersistentClass(PersistentClass persistentClass, Table componentClassDatabaseTable){
+ OrmShape classShape = null;
+ OrmShape shape = null;
+ if(persistentClass != null) {
+ classShape = elements.get(persistentClass.getClassName());
+ if (classShape == null) classShape = createShape(persistentClass);
+ if(componentClassDatabaseTable == null && persistentClass.getTable() != null)
+ componentClassDatabaseTable = persistentClass.getTable();
+ if(componentClassDatabaseTable != null) {
+ shape = elements.get(componentClassDatabaseTable.getSchema() + "." + componentClassDatabaseTable.getName());
+ if (shape == null) shape = getOrCreateDatabaseTable(componentClassDatabaseTable);
+ createConnections(classShape, shape);
+ new Connection(classShape, shape);
+ }
+ RootClass rc = (RootClass)persistentClass;
+ Iterator iter = rc.getSubclassIterator();
+ while (iter.hasNext()) {
+ SingleTableSubclass singleTableSubclass = (SingleTableSubclass)iter.next();
+ OrmShape singleTableSubclassShape = elements.get(singleTableSubclass.getEntityPersisterClass().getCanonicalName());
+ if (singleTableSubclassShape == null) singleTableSubclassShape = createShape(singleTableSubclass);
+ new Connection(singleTableSubclassShape, shape);
+ }
+// if (persistentClass.getPersistentClassMapping() != null) {
+// Iterator iter =((IHibernateClassMapping)(persistentClass).getPersistentClassMapping()).getJoinIterator();
+// while ( iter.hasNext() ) {
+// IJoinMapping jm =(IJoinMapping)iter.next();
+// shape = (OrmShape)elements.get(jm.getTable().getName());
+// if(shape == null)
+// shape = getOrCreateDatabaseTable(jm.getTable());
+// createConnections(classShape, shape);
+// }
+// }
+ }
+ return classShape;
+ }
+ private OrmShape getOrCreateDatabaseTable(Table databaseTable){
+ OrmShape tableShape = null;
+ if(databaseTable != null) {
+ String tableName = databaseTable.getSchema() + "." + databaseTable.getName();
+ tableShape = (OrmShape)elements.get(tableName);
+ if(tableShape == null) {
+ tableShape = createShape(databaseTable);
+ Iterator iterator = getConfiguration().getClassMappings();
+ while (iterator.hasNext()) {
+ Object clazz = iterator.next();
+ if (clazz instanceof RootClass) {
+ RootClass cls = (RootClass)clazz;
+ Table table = cls.getTable();
+ if (tableName.equals(table.getName() + "." + table.getName())) {
+ if (elements.get(cls.getClassName()) == null)
+ getOrCreatePersistentClass(cls, null);
+ }
+// } else if (clazz instanceof SingleTableSubclass) {
+// SingleTableSubclass singleTableSubclass = (SingleTableSubclass)clazz;
+// getOrCreatePersistentClass(singleTableSubclass, null);
+ }
+ }
+// IPersistentClassMapping persistentClassMappings[] = databaseTable.getPersistentClassMappings();
+// for (int j = 0; j < persistentClassMappings.length; j++) {
+// if(persistentClassMappings[j].getPersistentClass() != null ) {
+// OrmShape shape = (OrmShape)elements.get(persistentClassMappings[j].getPersistentClass().getName());
+// if(shape == null)
+// getOrCreatePersistentClass(persistentClassMappings[j].getPersistentClass(), null);
+// }
+// }
+ }
+ }
+ return tableShape;
+ }
+
+ private void createConnections(ExpandeableShape persistentClass, ExpandeableShape databaseTable){
+ int i = 0;
+ boolean check = (persistentClass.getOrmElement() instanceof SpecialRootClass);
+ Iterator persistentFields = persistentClass.getChildren().iterator();
+ List databaseColumns = databaseTable.getChildren();
+ List databaseColumns2 = new ArrayList();
+ Iterator iterator = null;
+ while (persistentFields.hasNext()) {
+ Shape shape = (Shape) persistentFields.next();
+ Object element = shape.getOrmElement();
+ if (element instanceof Property && (!check || ((SpecialRootClass)persistentClass.getOrmElement()).getParentProperty() != element)) {
+ Value value = ((Property)element).getValue();
+ iterator = value.getColumnIterator();
+ while (iterator.hasNext()) {
+ Object o = iterator.next();
+ if (o instanceof Column) {
+ Column databaseColumn = (Column)o;
+ for (int j = 0; j < databaseColumns.size(); j++) {
+ if (databaseColumn.getName().equals(((Column)((Shape)databaseColumns.get(j)).getOrmElement()).getName())) {
+ Shape databaseShape = (Shape)databaseColumns.remove(j);
+ new Connection(shape, databaseShape);
+ databaseColumns2.add(i++, databaseShape);
+ }
+ }
+ }
+ }
+ }
+ }
+ databaseColumns.addAll(databaseColumns2);
+ }
+
+ public String[] getChildrenLocations() {
+ return childrenLocations;
+ }
+
+ public boolean isDirty() {
+ return dirty;
+ }
+
+ public void setDirty(boolean dirty) {
+ if(this.dirty != dirty) {
+ this.dirty = dirty;
+ firePropertyChange(DIRTY, null, null);
+ }
+ }
+
+ public void processExpand(ExpandeableShape shape) {
+ Object element = shape.getOrmElement();
+ if (element instanceof Property) {
+ Type type = ((Property)element).getType();
+ if (type.isEntityType()) {
+ EntityType et = (EntityType) type;
+ RootClass rootClass = (RootClass)getConfiguration().getClassMapping(et.getAssociatedEntityName());
+ OrmShape s = getOrCreatePersistentClass(rootClass, null);
+ HashMap targets = new HashMap();
+ Iterator iterator = shape.getSourceConnections().iterator();
+ while (iterator.hasNext()) {
+ Connection connection = (Connection)iterator.next();
+ connection.setHiden(shape.getHide());
+ Object el = connection.getTarget().getOrmElement();
+ if (el instanceof Column) {
+ targets.put(((Column)el).getName(), connection.getTarget());
+ } else if (el instanceof RootClass) {
+ targets.put(((RootClass)el).getClassName(), connection.getTarget());
+ }
+ }
+ KeyValue id = rootClass.getIdentifier();
+ iterator = id.getColumnIterator();
+ while (iterator.hasNext()) {
+ Column column = (Column)iterator.next();
+ if (targets.get(column.getName()) != null) {
+ new Connection(s, (Shape)targets.get(column.getName()));
+ }
+ }
+ new Connection(shape, s);
+ firePropertyChange(REFRESH, null, null);
+ }
+ }
+ }
+
+ protected Configuration getConfiguration() {
+ return configuration;
+ }
+
+ protected void refreshComponentReferences(ComponentShape componentShape) {
+ Property property = (Property)componentShape.getOrmElement();
+ Type valueType = property.getValue().getType();
+ if (valueType.isCollectionType()) {
+ Collection collection = (Collection)property.getValue();
+ Value component = collection.getElement();
+ if (component instanceof Component) {//valueType.isComponentType()
+ OrmShape childShape = (OrmShape)elements.get(((Component)component).getComponentClassName());
+ if(childShape == null) childShape = getOrCreateComponentClass(property);
+ new Connection((Shape)(componentShape.getChildren().get(1)), childShape);
+ } else if (collection.isOneToMany()) {
+ OrmShape childShape = getOrCreateAssociationClass(property);
+ new Connection((Shape)(componentShape.getChildren().get(1)), childShape);
+ OrmShape keyTableShape = getOrCreateDatabaseTable(collection.getKey().getTable());
+ Iterator iter = collection.getKey().getColumnIterator();
+ while (iter.hasNext()) {
+ Column col = (Column)iter.next();
+ Shape keyColumnShape = keyTableShape.getChild(col);
+ if (keyColumnShape != null) new Connection((Shape)(componentShape.getChildren().get(0)), keyColumnShape);
+ }
+ } else if (collection.isMap() || collection.isSet()) {
+ OrmShape childShape = getOrCreateDatabaseTable(collection.getCollectionTable());
+ Shape keyShape = childShape.getChild((Column)((DependantValue)((Shape)componentShape.getChildren().get(0)).getOrmElement()).getColumnIterator().next());
+ new Connection((Shape)componentShape.getChildren().get(0), keyShape);
+
+ Iterator iter = ((SimpleValue)((Shape)componentShape.getChildren().get(1)).getOrmElement()).getColumnIterator();
+ while (iter.hasNext()) {
+ Column col = (Column)iter.next();
+ Shape elementShape = childShape.getChild(col);
+ new Connection((Shape)componentShape.getChildren().get(1), elementShape);
+ }
+ }
+ setDirty(true);
+ firePropertyChange(REFRESH, null, null);
+ }
+ }
+
+ private OrmShape getOrCreateComponentClass(Property property) {
+ OrmShape classShape = null;
+ Component component = (Component)((Collection)property.getValue()).getElement();
+ if (component != null) {
+ classShape = createShape(property);
+ OrmShape tableShape = (OrmShape)elements.get(component.getTable().getSchema() + "." + component.getTable().getName());
+ if (tableShape == null) tableShape = getOrCreateDatabaseTable(component.getTable());
+ createConnections(classShape, tableShape);
+ new Connection(classShape, tableShape);
+ Shape parentShape = ((SpecialOrmShape)classShape).getParentShape();
+ OrmShape parentClassShape = (OrmShape)elements.get(((Property)parentShape.getOrmElement()).getPersistentClass().getClassName());
+ new Connection(parentShape, parentClassShape);
+ }
+ return classShape;
+ }
+
+ private OrmShape getOrCreateAssociationClass(Property property) {
+ OrmShape classShape = null;
+ OneToMany component = (OneToMany)((Collection)property.getValue()).getElement();
+ if (component != null) {
+ classShape = (OrmShape)elements.get(component.getAssociatedClass().getClassName());
+ if (classShape == null) classShape = createShape(component.getAssociatedClass());
+ OrmShape tableShape = (OrmShape)elements.get(component.getAssociatedClass().getTable().getSchema() + "." + component.getAssociatedClass().getTable().getName());
+ if (tableShape == null) tableShape = getOrCreateDatabaseTable(component.getAssociatedClass().getTable());
+ createConnections(classShape, tableShape);
+ new Connection(classShape, tableShape);
+ }
+ return classShape;
+ }
+}
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java 2007-07-05 12:01:25 UTC (rev 2312)
@@ -0,0 +1,199 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.util.Iterator;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.KeyValue;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+import org.hibernate.mapping.SimpleValue;
+import org.hibernate.mapping.SingleTableSubclass;
+import org.hibernate.mapping.Table;
+
+public class OrmShape extends ExpandeableShape {
+ public static final String SET_HIDEN = "set hiden";
+
+ public static final String LOCATION_PROP = "OrmShape.Location";
+ private Point location = new Point(0, 0);
+ protected boolean hiden = false;
+
+ public OrmShape(Object ioe) {
+ super(ioe);
+ generate();
+ }
+
+ protected void generate() {
+ Shape bodyOrmShape;
+ Object ormElement = getOrmElement();
+ if (ormElement instanceof RootClass) {
+ RootClass rootClass = (RootClass)getOrmElement();
+ Property identifierProperty = rootClass.getIdentifierProperty();
+ if (identifierProperty != null) {
+ getChildren().add(new Shape(identifierProperty));
+ }
+
+ KeyValue identifier = rootClass.getIdentifier();
+ if (identifier instanceof Component) {
+ Iterator iterator = ((Component)identifier).getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property property = (Property) iterator.next();
+ getChildren().add(new Shape(property));
+ }
+ }
+
+ Iterator iterator = rootClass.getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property field = (Property)iterator.next();
+ if (!field.isComposite()) {
+ if (field.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(field);
+ } else if (field.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(field);
+ } else {
+ bodyOrmShape = new Shape(field);
+ }
+ getChildren().add(bodyOrmShape);
+ } else {
+ Component component = (Component)field.getValue();
+ Iterator iter = component.getPropertyIterator();
+ while (iter.hasNext()) {
+ Property property = (Property)iter.next();
+ if (property.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(property);
+ } else if (property.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(property);
+ } else {
+ bodyOrmShape = new Shape(property);
+ }
+ getChildren().add(bodyOrmShape);
+ }
+ }
+ }
+ } else if (ormElement instanceof SingleTableSubclass) {
+ RootClass rootClass = ((SingleTableSubclass)ormElement).getRootClass();
+
+ Property identifierProperty = rootClass.getIdentifierProperty();
+ if (identifierProperty != null) {
+ getChildren().add(new Shape(identifierProperty));
+ }
+
+ KeyValue identifier = rootClass.getIdentifier();
+ if (identifier instanceof Component) {
+ Iterator iterator = ((Component)identifier).getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property property = (Property) iterator.next();
+ getChildren().add(new Shape(property));
+ }
+ }
+
+ Iterator iterator = rootClass.getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property field = (Property)iterator.next();
+ if (!field.isComposite()) {
+ if (field.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(field);
+ } else if (field.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(field);
+ } else {
+ bodyOrmShape = new Shape(field);
+ }
+ getChildren().add(bodyOrmShape);
+ } else {
+ Component component = (Component)field.getValue();
+ Iterator iter = component.getPropertyIterator();
+ while (iter.hasNext()) {
+ Property property = (Property)iter.next();
+ if (property.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(property);
+ } else if (property.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(property);
+ } else {
+ bodyOrmShape = new Shape(property);
+ }
+ getChildren().add(bodyOrmShape);
+ }
+ }
+ }
+ Iterator iter = ((SingleTableSubclass)ormElement).getPropertyIterator();
+ while (iter.hasNext()) {
+ Property property = (Property)iter.next();
+ if (property.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(property);
+ } else if (property.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(property);
+ } else {
+ bodyOrmShape = new Shape(property);
+ }
+ getChildren().add(bodyOrmShape);
+ }
+ } else if (ormElement instanceof Table) {
+ Iterator iterator = ((Table)getOrmElement()).getColumnIterator();
+ while (iterator.hasNext()) {
+ Column column = (Column)iterator.next();
+ bodyOrmShape = new Shape(column);
+ getChildren().add(bodyOrmShape);
+ }
+ }
+ }
+
+ public Shape getChild(Column ormElement) {
+ Shape shape = null;
+ Iterator iter = getChildren().iterator();
+ while (iter.hasNext()) {
+ Shape child = (Shape)iter.next();
+ Object childElement = child.getOrmElement();
+ if (childElement instanceof Column && ormElement.getName().equals(((Column)childElement).getName())) {
+ return child;
+ }
+ }
+ return shape;
+ }
+
+ protected void setHiden(boolean hiden) {
+ super.setHiden(hiden);
+ for (int i = 0; i < getChildren().size(); i++)
+ ((Shape)getChildren().get(i)).setHiden(hiden);
+ }
+
+ public void refreshHiden() {
+ hiden = !hiden;
+ setElementHidden(this, hiden);
+ firePropertyChange(SET_HIDEN, null, new Boolean(hiden));
+ }
+
+ private void setElementHidden(ModelElement element, boolean hidden){
+ for (int i = 0; i < element.getChildren().size(); i++){
+ ((Shape)element.getChildren().get(i)).setHiden(hidden);
+ setElementHidden((ModelElement)element.getChildren().get(i), hidden);
+ }
+ }
+
+ public Point getLocation() {
+ return location.getCopy();
+ }
+
+ public void setLocation(Point newLocation) {
+ if (newLocation == null) {
+ throw new IllegalArgumentException();
+ }
+ location.setLocation(newLocation);
+ firePropertyChange(LOCATION_PROP, null, location);
+ }
+
+ public boolean isHiden() {
+ return hiden;
+ }
+}
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java 2007-07-05 12:01:25 UTC (rev 2312)
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Shape extends ModelElement {
+
+ private int indent = 0;
+
+ private List<Connection> sourceConnections = new ArrayList<Connection>();
+ private List<Connection> targetConnections = new ArrayList<Connection>();
+
+ public static final String HIDE_SELECTION = "hide selection";
+ public static final String SHOW_SELECTION = "show selection";
+ public static final String SET_FOCUS = "set focus";
+
+ private Object ormElement;
+
+ protected Shape(Object ioe) {
+ ormElement = ioe;
+ }
+
+ public void addConnection(Connection conn) {
+ if (conn == null || conn.getSource() == conn.getTarget()) {
+ throw new IllegalArgumentException();
+ }
+ if (conn.getSource() == this) {
+ sourceConnections.add(conn);
+ } else if (conn.getTarget() == this) {
+ targetConnections.add(conn);
+ }
+ }
+
+
+ public List<Connection> getSourceConnections() {
+ return new ArrayList<Connection>(sourceConnections);
+ }
+
+ public List<Connection> getTargetConnections() {
+ return new ArrayList<Connection>(targetConnections);
+ }
+
+ public Object getOrmElement() {
+ return ormElement;
+ }
+
+ public void hideSelection() {
+ firePropertyChange(HIDE_SELECTION, null, null);
+ }
+
+ public void showSelection() {
+ firePropertyChange(SHOW_SELECTION, null, null);
+ }
+
+ public void setFocus() {
+ firePropertyChange(SET_FOCUS, null, null);
+ }
+
+ public int getIndent() {
+ return indent;
+ }
+
+ protected void setIndent(int indent) {
+ this.indent = indent;
+ }
+
+ protected void setHiden(boolean hiden) {
+ for (int i = 0; i < sourceConnections.size(); i++)
+ ((Connection)sourceConnections.get(i)).setHiden(hiden);
+ for (int i = 0; i < targetConnections.size(); i++)
+ ((Connection)targetConnections.get(i)).setHiden(hiden);
+ }
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialOrmShape.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialOrmShape.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialOrmShape.java 2007-07-05 12:01:25 UTC (rev 2312)
@@ -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.model;
+
+import java.util.Iterator;
+
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+
+public class SpecialOrmShape extends OrmShape {
+ private Shape parentShape;
+
+ public SpecialOrmShape(SpecialRootClass ioe) {
+ super(ioe);
+ }
+
+ protected void generate() {
+ Shape bodyOrmShape;
+ RootClass rootClass = (RootClass)getOrmElement();
+ Property identifierProperty = rootClass.getIdentifierProperty();
+ if (identifierProperty != null) getChildren().add(new Shape(identifierProperty));
+
+ SpecialRootClass src = (SpecialRootClass)getOrmElement();
+ if (src.getParentProperty() != null) {
+ bodyOrmShape = new Shape(src.getParentProperty());
+ getChildren().add(bodyOrmShape);
+ parentShape = bodyOrmShape;
+ }
+
+ Iterator iterator = (rootClass).getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property field = (Property)iterator.next();
+ if (field.getValue().getType().isEntityType()) {
+ bodyOrmShape = new ExpandeableShape(field);
+ } else if (field.getValue().getType().isCollectionType()) {
+ bodyOrmShape = new ComponentShape(field);
+ } else {
+ bodyOrmShape = new Shape(field);
+ }
+ getChildren().add(bodyOrmShape);
+ }
+ }
+
+ protected Shape getParentShape() {
+ return parentShape;
+ }
+
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java 2007-07-05 12:01:25 UTC (rev 2312)
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * 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.model;
+
+import java.util.Iterator;
+
+import org.hibernate.mapping.Collection;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Component;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Property;
+import org.hibernate.mapping.RootClass;
+
+public class SpecialRootClass extends RootClass {
+
+ private Property property;
+ private Property parentProperty;
+
+ public SpecialRootClass(Property property) {
+ super();
+ this.property = property;
+ generate();
+ }
+
+ private void generate() {
+ if (property != null) {
+ Collection collection = (Collection)property.getValue();
+ Component component = (Component)collection.getElement();
+ setClassName(component.getComponentClassName());
+ PersistentClass ownerClass = collection.getOwner();
+ if (component.getParentProperty() != null) {
+ Property property = ownerClass.getProperty(component.getParentProperty());
+ if (property == null && ownerClass.getIdentifierProperty().getName().equals(component.getParentProperty())) {
+ property = ownerClass.getIdentifierProperty();
+ }
+ if (property != null) parentProperty = ownerClass.getIdentifierProperty();
+ }
+ Iterator iterator = component.getPropertyIterator();
+ while (iterator.hasNext()) {
+ Property property = (Property)iterator.next();
+ if (property != null) addProperty(property);
+ }
+ }
+ }
+
+ protected Property getParentProperty() {
+ return parentProperty;
+ }
+
+ public Property getProperty() {
+ return this.property;
+ }
+}
17 years, 6 months
JBoss Tools SVN: r2311 - trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures.
by jbosstools-commits@lists.jboss.org
Author: mdryakhlenkov
Date: 2007-07-05 08:01:03 -0400 (Thu, 05 Jul 2007)
New Revision: 2311
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/ComponentFigure.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundLineBorder.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundPolylineConnection.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleFigure.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleLabel.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TopLineBorder.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/figures/ComponentFigure.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/ComponentFigure.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/ComponentFigure.java 2007-07-05 12:01:03 UTC (rev 2311)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.figures;
+
+import java.util.List;
+
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.IFigure;
+
+public class ComponentFigure extends Figure {
+
+ private boolean childsHiden = false;
+
+ public void add(IFigure figure, Object constraint, int index) {
+ if(index != -1){
+ if(index == -2)
+ index = 0;
+ else
+ index++;
+ }
+ super.add(figure, constraint, index);
+ }
+
+ public List getChildren() {
+ if (childsHiden)
+ return super.getChildren().subList(0,1);
+ else
+ return super.getChildren();
+
+ }
+
+ public void setChildsHiden(boolean childsHiden) {
+ this.childsHiden = childsHiden;
+ }
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundLineBorder.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundLineBorder.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundLineBorder.java 2007-07-05 12:01:03 UTC (rev 2311)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.figures;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.LineBorder;
+import org.eclipse.draw2d.geometry.Insets;
+
+public class RoundLineBorder extends LineBorder {
+ public void paint(IFigure figure, Graphics graphics, Insets insets) {
+ tempRect.setBounds(getPaintRectangle(figure, insets).resize(-1,-1));
+ if (getColor() != null)
+ graphics.setForegroundColor(getColor());
+ graphics.drawRoundRectangle(tempRect, 2, 2);
+ }
+}
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundPolylineConnection.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundPolylineConnection.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundPolylineConnection.java 2007-07-05 12:01:03 UTC (rev 2311)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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.figures;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+
+public class RoundPolylineConnection extends PolylineConnection {
+ protected void outlineShape(Graphics g) {
+ PointList points = getPoints();
+ Point point = points.getPoint(0);
+ Point beg = new Point();
+ Point end = new Point();
+ Point eCorner = new Point();
+ Point bCorner = new Point();
+ boolean horiz;
+ beg.x = point.x;
+ beg.y = point.y;
+
+ if (points.getFirstPoint().y == points.getLastPoint().y) {
+ super.outlineShape(g);
+ return;
+ }
+
+ for (int i = 1; i < points.size(); i++) {
+ point = points.getPoint(i);
+ end.x = point.x;
+ end.y = point.y;
+
+ if (beg.y == end.y)
+ horiz = true;
+ else
+ horiz = false;
+
+ eCorner.x = 0;
+ if (i != 1) {
+ if (horiz) {
+ if (end.x > beg.x) {
+ beg.x += 2;
+ } else {
+ beg.x -= 2;
+ }
+ } else {
+ if (end.y > beg.y) {
+ beg.y += 2;
+ } else {
+ beg.y -= 2;
+ }
+ }
+ eCorner.x = beg.x;
+ eCorner.y = beg.y;
+ }
+
+ if (bCorner.x != 0 && eCorner.x != 0)
+ g.drawLine(bCorner, eCorner);
+ bCorner.x = 0;
+
+ if (i != points.size() - 1) {
+ if (horiz) {
+ if (end.x > beg.x) {
+ end.x -= 2;
+ } else {
+ end.x += 2;
+ }
+ } else {
+ if (end.y > beg.y) {
+ end.y -= 2;
+ } else {
+ end.y += 2;
+ }
+ }
+ bCorner.x = end.x;
+ bCorner.y = end.y;
+ }
+
+ g.drawLine(beg, end);
+ point = points.getPoint(i);
+ beg.x = point.x;
+ beg.y = point.y;
+ }
+ }
+}
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleFigure.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleFigure.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleFigure.java 2007-07-05 12:01:03 UTC (rev 2311)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.figures;
+
+import java.util.List;
+
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.IFigure;
+
+public class TitleFigure extends Figure {
+
+ private boolean hiden = false;
+
+ public void add(IFigure figure, Object constraint, int index) {
+ if(index != -1){
+ if(index == -2)
+ index = 0;
+ else
+ index++;
+ }
+ super.add(figure, constraint, index);
+ }
+
+ public List getChildren() {
+ if (hiden)
+ return super.getChildren().subList(0,1);
+ else
+ return super.getChildren();
+
+ }
+
+ public void setHiden(boolean hiden) {
+ this.hiden = hiden;
+ }
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleLabel.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleLabel.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleLabel.java 2007-07-05 12:01:03 UTC (rev 2311)
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * 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.figures;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.Label;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.hibernate.ui.view.ViewPlugin;
+
+
+public class TitleLabel extends Label {
+
+ static Image shevronUp = ViewPlugin.getImageDescriptor(ViewPlugin.BUNDLE_IMAGE.getString("VisualMapping.shevronUp")).createImage();
+ static Image shevronDown = ViewPlugin.getImageDescriptor(ViewPlugin.BUNDLE_IMAGE.getString("VisualMapping.shevronDown")).createImage();
+
+ protected boolean hiden = false;
+
+
+ protected Dimension calculateLabelSize(Dimension txtSize) {
+ Dimension p = super.calculateLabelSize(txtSize).getCopy();
+ p.width+=40;
+ return p;
+ }
+
+ protected void paintFigure(Graphics graphics) {
+ super.paintFigure(graphics);
+ if(hiden)
+ graphics.drawImage(shevronDown, getBounds().x+getBounds().width-20, getBounds().y);
+ else
+ graphics.drawImage(shevronUp, getBounds().x+getBounds().width-20, getBounds().y);
+ }
+
+ public void setHiden(boolean hiden) {
+ this.hiden = hiden;
+ }
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TopLineBorder.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TopLineBorder.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TopLineBorder.java 2007-07-05 12:01:03 UTC (rev 2311)
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * 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.figures;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.MarginBorder;
+import org.eclipse.draw2d.geometry.Insets;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.swt.graphics.Color;
+
+public class TopLineBorder extends MarginBorder {
+
+ private Color color;
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public TopLineBorder(int t, int l, int b, int r) {
+ super(t+1, l, b, r);
+ }
+
+ public void paint(IFigure figure, Graphics graphics, Insets insets) {
+ Rectangle r = getPaintRectangle(figure, insets);
+ if (getColor() != null)
+ graphics.setForegroundColor(getColor());
+ graphics.drawLine(r.x, r.y, r.right(), r.y);
+ }
+
+}
17 years, 6 months
JBoss Tools SVN: r2310 - trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/command.
by jbosstools-commits@lists.jboss.org
Author: mdryakhlenkov
Date: 2007-07-05 08:00:38 -0400 (Thu, 05 Jul 2007)
New Revision: 2310
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/command/ShapeSetConstraintCommand.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/command/ShapeSetConstraintCommand.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/command/ShapeSetConstraintCommand.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/command/ShapeSetConstraintCommand.java 2007-07-05 12:00:38 UTC (rev 2310)
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * 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.command;
+
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
+
+
+public class ShapeSetConstraintCommand extends Command {
+ private final Point newLocation;
+ private Point oldLocation;
+ private final ChangeBoundsRequest request;
+
+ private final OrmShape shape;
+
+ public ShapeSetConstraintCommand(OrmShape shape, ChangeBoundsRequest req,
+ Point newLocation) {
+ if (shape == null || req == null || newLocation == null) {
+ throw new IllegalArgumentException();
+ }
+ this.shape = shape;
+ this.request = req;
+ this.newLocation = newLocation.getCopy();
+ setLabel("move");
+ }
+
+ public boolean canExecute() {
+ Object type = request.getType();
+ return (RequestConstants.REQ_MOVE.equals(type)
+ || RequestConstants.REQ_MOVE_CHILDREN.equals(type));
+ }
+
+ public void execute() {
+ oldLocation = shape.getLocation();
+ redo();
+ }
+
+ public void redo() {
+ shape.setLocation(newLocation);
+ }
+
+ public void undo() {
+ shape.setLocation(oldLocation);
+ }
+}
17 years, 6 months
JBoss Tools SVN: r2309 - trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors.
by jbosstools-commits@lists.jboss.org
Author: mdryakhlenkov
Date: 2007-07-05 08:00:17 -0400 (Thu, 05 Jul 2007)
New Revision: 2309
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/command/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/
Log:
JBIDE-559: Hibernate diagram editor cleanup
17 years, 6 months
JBoss Tools SVN: r2308 - trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor.
by jbosstools-commits@lists.jboss.org
Author: mdryakhlenkov
Date: 2007-07-05 07:59:59 -0400 (Thu, 05 Jul 2007)
New Revision: 2308
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/VisualEditorPlugin.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/VisualEditorPlugin.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/VisualEditorPlugin.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/VisualEditorPlugin.java 2007-07-05 11:59:59 UTC (rev 2308)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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;
+
+import org.eclipse.ui.plugin.*;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.osgi.framework.BundleContext;
+import org.jboss.tools.common.log.BaseUIPlugin;
+import org.jboss.tools.common.log.IPluginLog;
+
+public class VisualEditorPlugin extends BaseUIPlugin {
+
+ public final static String PLUGIN_ID= "org.jboss.tools.hibernate.ui.veditor";
+
+ //The shared instance.
+ private static VisualEditorPlugin plugin;
+
+ public VisualEditorPlugin() {
+ plugin = this;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ plugin = null;
+ }
+
+ public static VisualEditorPlugin getDefault() {
+ return plugin;
+ }
+
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+
+ public static IPluginLog getPluginLog() {
+ return getDefault();
+ }
+
+}
17 years, 6 months
JBoss Tools SVN: r2307 - trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout.
by jbosstools-commits@lists.jboss.org
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);
+}
17 years, 6 months
JBoss Tools SVN: r2306 - in trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors: autolayout and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: mdryakhlenkov
Date: 2007-07-05 07:59:21 -0400 (Thu, 05 Jul 2007)
New Revision: 2306
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/AutoLayoutImpl.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Group.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/GroupArranger.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Groups.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Item.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Items.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/LayuotConstants.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/TransitionArranger.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/impl/AutoLayoutImpl.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/AutoLayoutImpl.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/AutoLayoutImpl.java 2007-07-05 11:59:21 UTC (rev 2306)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * 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.impl;
+
+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;
+
+
+public class AutoLayoutImpl {
+ LayuotConstants constants = new LayuotConstants();
+ protected Items items;
+
+ public AutoLayoutImpl() {}
+
+ public void setGridStep(String gridStep) {
+ constants.update(gridStep);
+ }
+
+ public void setItems(Items items) {
+ this.items = items;
+ items.setConstants(constants);
+ }
+
+ public void setOverride(boolean b) {
+ items.setOverride(b);
+ }
+
+ public void setProcess(IDiagramInfo process) {
+// constants.update();
+ items.setProcess(process);
+ apply();
+ if(items.override) {
+ TransitionArranger a = new TransitionArranger();
+ a.setItems(items.items);
+ a.execute();
+ }
+ }
+
+ private void apply() {
+ resetTransitions(); // temporal
+
+ Item[] is = items.items;
+ int[] yDeltas = items.groups.yDeltas;
+ for (int i = 0; i < is.length; i++) {
+ if(is[i].isSet()) continue;
+ IItemInfo o = is[i].itemInfo;
+ int x = is[i].ix * constants.deltaX + constants.indentX;
+ int y = is[i].iy * constants.deltaY + constants.indentY;
+ if(is[i].ix % 2 == 1) y += 16;
+ x += is[i].group.xDeltas[is[i].ix] * constants.incX;
+ y += yDeltas[is[i].iy] * constants.incY + is[i].yIndent;
+ o.setShape(new int[]{x, y, 0, 0});
+ }
+ }
+
+ private void resetTransitions() {
+ if(!items.override) return;
+ Item[] is = items.items;
+ for (int i = 0; i < is.length; i++) {
+ IItemInfo o = is[i].itemInfo;
+ if(o instanceof ILinkInfo) {
+ ((ILinkInfo)o).setLinkShape(new int[0]);
+ }
+ ILinkInfo[] os = items.getOutput(o);
+ for (int j = 0; j < os.length; j++) {
+ os[j].setLinkShape(new int[0]);
+ }
+ }
+
+ }
+
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Group.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Group.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Group.java 2007-07-05 11:59:21 UTC (rev 2306)
@@ -0,0 +1,237 @@
+/*******************************************************************************
+ * 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.impl;
+
+import java.util.*;
+
+public class Group {
+ LayuotConstants constants;
+ int number;
+ List itemList = new ArrayList();
+ Item[] allitems = null;
+ private int[] items = null;
+ int miny = -1;
+ int[] xDeltas = null;
+ GroupArranger arranger = new GroupArranger(this);
+
+ public Group() {}
+
+ public void setItems(Item[] items) {
+ allitems = items;
+ }
+
+ public void setConstants(LayuotConstants constants) {
+ this.constants = constants;
+ }
+
+ public void expandGroup(int _item) {
+ Item item = allitems[_item];
+ item.group = this;
+ itemList.add(new Integer(_item));
+ int[] is = item.comments;
+ for (int i = 0; i < is.length; i++) {
+ Item item2 = allitems[is[i]];
+ if(!item2.isSet()) {
+ allitems[is[i]].ix = item.ix;
+ }
+ expandGroup(is[i]);
+ }
+ is = item.inputs;
+ for (int i = 0; i < is.length; i++) {
+ Item item2 = allitems[is[i]];
+ if(item2.group != null) continue;
+ if(!item2.isSet()) {
+ item2.ix = item.ix - 1;
+ }
+ expandGroup(is[i]);
+ }
+ is = item.outputs;
+ for (int i = 0; i < is.length; i++) {
+ Item item2 = allitems[is[i]];
+ if(item2.group != null) continue;
+ if(!item2.isSet()) item2.ix = item.ix + 1;
+ expandGroup(is[i]);
+ }
+ }
+
+ int[] items() {
+ if(items == null) {
+ items = new int[itemList.size()];
+ for (int i = 0; i < items.length; i++)
+ items[i] = ((Integer)itemList.get(i)).intValue();
+ }
+ return items;
+ }
+
+ Item getItem(int i) {
+ return allitems[items[i]];
+ }
+
+ public void moveX() {
+ items();
+ int min = 0;
+ for (int i = 0; i < items.length; i++) {
+ if(getItem(i).ix < min) min = getItem(i).ix;
+ }
+ if(min == 0) return;
+ for (int i = 0; i < items.length; i++) {
+ if(!getItem(i).isSet()) {
+ getItem(i).ix -= min;
+ if(getItem(i).ix >= Groups.FX) getItem(i).ix = Groups.FX - 1;
+ }
+ }
+ }
+
+ public void buildY(Item item, int[][] field) {
+ field[item.ix][item.iy] = 1;
+ int[] is = item.comments;
+ for (int i = 0; i < is.length; i++) {
+ Item item2 = allitems[is[i]];
+ if(item2.yAssigned) continue;
+ item2.yAssigned = true;
+ if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ buildY(item2, field);
+ }
+ is = item.inputs;
+ for (int i = 0; i < is.length; i++) {
+ Item item2 = allitems[is[i]];
+ if(item2.yAssigned) continue;
+ item2.yAssigned = true;
+ if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ buildY(item2, field);
+ }
+ is = item.outputs;
+ for (int i = 0; i < is.length; i++) {
+ Item item2 = allitems[is[i]];
+ if(item2.yAssigned) continue;
+ item2.yAssigned = true;
+ if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ buildY(item2, field);
+ }
+ }
+
+ public void buildY_2(Item item, int[][] field) {
+ field[item.ix][item.iy] = 1;
+ int[] is = item.comments;
+ for (int i = 0; i < is.length; i++) {
+ Item item2 = allitems[is[i]];
+ if(item2.yAssigned) continue;
+ item2.yAssigned = true;
+ if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ buildY(item2, field);
+ }
+ is = item.inputs;
+ for (int i = 0; i < is.length; i++) {
+ Item item2 = allitems[is[i]];
+ if(item2.yAssigned) continue;
+ if(item.ix != item2.ix + 1) continue;
+ item2.yAssigned = true;
+ if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ buildY(item2, field);
+ }
+ is = item.outputs;
+ for (int i = 0; i < is.length; i++) {
+ Item item2 = allitems[is[i]];
+ if(item2.yAssigned) continue;
+ if(item.ix != item2.ix - 1) continue;
+ item2.yAssigned = true;
+ if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ buildY(item2, field);
+ }
+ }
+
+ private int findFreeY(int ix, int miny, int prefy, int maxy, int[][] field) {
+ for (int i = 0; i < 20; i++) {
+ int iy = prefy + i;
+ if(iy >= miny && iy < maxy && field[ix][iy] == 0) return iy;
+ iy = prefy - i;
+ if(iy >= miny && iy < maxy && field[ix][iy] == 0) return iy;
+ }
+ return prefy;
+ }
+
+ public int getMaxY() {
+ int maxy = 0;
+ for (int i = 0; i < items.length; i++)
+ if(getItem(i).iy > maxy) maxy = getItem(i).iy;
+ return maxy;
+ }
+
+ public boolean hasSetItems() {
+ items();
+ for (int i = 0; i < items.length; i++) if(getItem(i).isSet()) return true;
+ return false;
+ }
+
+ public void buildXDeltas() {
+ xDeltas = new int[getMaxX() + 1];
+ for (int i = 0; i < xDeltas.length; i++) xDeltas[i] = 0;
+ ///if(hasSetItems()) return;
+ for (int i = 0; i < items.length; i++) {
+ int c = getItem(i).ix;
+ if(c >= xDeltas.length) continue;
+ int sz = getItem(i).inputs.length - 1;
+ if(sz > xDeltas[c]) xDeltas[c] = sz;
+ ++c;
+ if(c >= xDeltas.length) continue;
+ sz = getItem(i).outputs.length - 1;
+ if(sz > xDeltas[c]) xDeltas[c] = sz;
+ }
+ for (int i = 0; i < xDeltas.length; i++) if(xDeltas[i] > 4) xDeltas[i] = 4;
+
+ for (int i = 0; i < items.length; i++) {
+ int c = getItem(i).ix;
+ ++c;
+ if(c >= xDeltas.length) continue;
+ int[] shape = getItem(i).getObject().getShape();
+ if(shape == null || shape.length < 4) continue;
+ int wi = (shape[2] - (constants.deltaX / 2)) / constants.incX;
+ if(wi > xDeltas[c]) xDeltas[c] = wi;
+ }
+ for (int i = 1; i < xDeltas.length; i++) xDeltas[i] += xDeltas[i - 1];
+
+ }
+
+ public int getMaxX() {
+ int maxx = 0;
+ for (int i = 0; i < items.length; i++) if(getItem(i).ix > maxx) maxx = getItem(i).ix;
+ return maxx;
+ }
+
+
+ //////////////////////////////////////////
+
+ public void createGroup(int _item) {
+ expandGroup2(_item);
+ int length = items().length;
+ for (int i = 0; i < length; i++) getItem(i).initActivities();
+ arranger.arrange();
+ }
+
+ private void expandGroup2(int _item) {
+ Item item = allitems[_item];
+ item.group = this;
+ itemList.add(new Integer(_item));
+ int[] is = item.comments;
+ for (int i = 0; i < is.length; i++) {
+ expandGroup2(is[i]);
+ }
+ is = item.inputs;
+ for (int i = 0; i < is.length; i++) {
+ if(allitems[is[i]].group == null) expandGroup2(is[i]);
+ }
+ is = item.outputs;
+ for (int i = 0; i < is.length; i++) {
+ if(allitems[is[i]].group == null) expandGroup2(is[i]);
+ }
+ }
+
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/GroupArranger.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/GroupArranger.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/GroupArranger.java 2007-07-05 11:59:21 UTC (rev 2306)
@@ -0,0 +1,193 @@
+/*******************************************************************************
+ * 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.impl;
+
+public class GroupArranger {
+ Group group;
+ int mgi = 0; // items with indefinite gravity
+ boolean inited = false;
+
+ public GroupArranger(Group group) {
+ this.group = group;
+ }
+
+ private void init() {
+ inited = true;
+ for (int i = 0; i < group.items().length; i++) {
+ Item item = group.getItem(i);
+ if(item.isOwned) {
+ item.gravity = -1;
+ } else if(item.inputs.length == 0) {
+ item.gravity = 0;
+ } else if(item.outputs.length == 0) {
+ item.gravity = 2000;
+ } else {
+ item.gravity = 1000;
+ ++mgi;
+ }
+ }
+ }
+
+ public void arrange() {
+ init();
+ while(mgi > 0) {
+ split();
+ if(mgi > 0) cut(findBestCutIndex());
+ }
+ reduce();
+ }
+
+ private void split() {
+ int length = group.items().length;
+ boolean work = true;
+ while(work) {
+ work = false;
+ for (int i = 0; i < length; i++) {
+ Item item = group.getItem(i);
+ if(item.gravity != 1000) continue;
+ int q = computeLowerWeight(i);
+ if(q < item.gravity) {
+ item.gravity = q;
+ work = true;
+ --mgi;
+ }
+ if(item.gravity != 1000) continue;
+ q = computeUpperWeight(i);
+ if(q > item.gravity) {
+ item.gravity = q;
+ work = true;
+ --mgi;
+ }
+ }
+ }
+ }
+
+ private int computeLowerWeight(int i0) {
+ Item item = group.getItem(i0);
+ int[] is = item.inputs;
+ int q = 0;
+ for (int i = 0; i < is.length; i++) {
+ if(!item.inputActivities[i]) continue;
+ Item si = group.allitems[is[i]];
+ if(si.gravity + 1 > q) q = si.gravity + 1;
+ }
+ return q;
+ }
+
+ private int computeUpperWeight(int i0) {
+ Item item = group.getItem(i0);
+ int[] is = item.outputs;
+ if(is.length == 0) return item.gravity;
+ int q = 2000;
+ for (int i = 0; i < is.length; i++) {
+ if(!item.outputActivities[i]) continue;
+ Item si = group.allitems[is[i]];
+ if(si.gravity - 1 < q) q = si.gravity - 1;
+ }
+ return (q == 2000) ? item.gravity : q;
+ }
+
+
+ void activateInput(Item item, int input, boolean b) {
+ item.inputActivities[input] = b;
+ Item i2 = group.allitems[item.inputs[input]];
+ int[] is = i2.outputs;
+ for (int i = 0; i < is.length; i++)
+ if(is[i] == item.n) i2.outputActivities[i] = b;
+ }
+
+ private int findBestCutIndex() {
+ int k = -1;
+ int w = 20000;
+ for (int i = 0; i < group.items().length; i++) {
+ Item item = group.getItem(i);
+ if(item.gravity != 1000) continue;
+ int w2 = getCuttingPreference(i);
+ if(w2 < w) {
+ w = w2;
+ k = i;
+ }
+ }
+ return k;
+ }
+
+ private int getCuttingPreference(int i0) {
+ Item item = group.getItem(i0);
+ int[] is = item.inputs;
+ int q = 0;
+ for (int i = 0; i < is.length; i++) {
+ if(!item.inputActivities[i]) continue;
+ Item si = group.allitems[is[i]];
+ if(si.gravity == 1000) ++q;
+ }
+ q = 10 * q;
+ is = item.outputs;
+ for (int i = 0; i < is.length; i++) {
+ if(!item.outputActivities[i]) continue;
+ Item si = group.allitems[is[i]];
+ if(si.gravity == 1000) --q;
+ }
+ return q;
+ }
+
+ private void cut(int i0) {
+ Item item = group.getItem(i0);
+ int[] is = item.inputs;
+ for (int i = 0; i < is.length; i++) {
+ if(!item.inputActivities[i]) continue;
+ Item si = group.allitems[is[i]];
+ if(si.gravity == 1000) {
+ activateInput(item, i, false);
+ }
+ }
+ }
+
+ private void reduce() {
+ boolean work = true;
+ while(work) {
+ work = false;
+ for (int i = 0; i < group.items().length; i++) {
+ Item item = group.getItem(i);
+ if(item.gravity < 0) continue;
+ int q = computeLowerWeight(i);
+ if(q < item.gravity) {
+ item.gravity = q;
+ work = true;
+ }
+ }
+ }
+ work = true;
+ while(work) {
+ work = false;
+ for (int i = 0; i < group.items().length; i++) {
+ Item item = group.getItem(i);
+ if(item.gravity < 0) continue;
+ int q = computeUpperWeight(i);
+ if(q > item.gravity) {
+ item.gravity = q;
+ work = true;
+ }
+ }
+ }
+ for (int i = 0; i < group.items().length; i++) {
+ Item item = group.getItem(i);
+ item.ix = item.gravity;
+ }
+ for (int i = 0; i < group.items().length; i++) {
+ Item item = group.getItem(i);
+ int[] cs = item.comments;
+ for (int j = 0; j < cs.length; j++) {
+ group.allitems[cs[j]].ix = item.ix;
+ }
+ }
+ }
+
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Groups.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Groups.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Groups.java 2007-07-05 11:59:21 UTC (rev 2306)
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * 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.impl;
+
+import java.util.*;
+
+public class Groups {
+ protected LayuotConstants constants;
+ static int FX = 30, FY = 120;
+ List groups = new ArrayList();
+ Item[] items;
+ int[][] field;
+ int[] yDeltas = null;
+
+ public Groups() {}
+
+ public void setConstants(LayuotConstants constants) {
+ this.constants = constants;
+ }
+
+ public void load(Item[] items) {
+ this.items = items;
+ init();
+ initField();
+ buildY();
+ buildDeltas();
+ }
+
+ public void init() {
+ groups.clear();
+ int g = 0;
+ boolean isSomethingSet = isSomethingSet();
+ for (int i = 0; i < items.length; i++) {
+ if(items[i].group != null || items[i].isOwned) continue;
+ ++g;
+ Group group = new Group();
+ group.setConstants(constants);
+ group.number = g;
+ groups.add(group);
+ if(!items[i].isSet()) items[i].ix = 0;
+ group.setItems(items);
+ if(isSomethingSet) {
+ group.expandGroup(i);
+ } else {
+ group.createGroup(i);
+ }
+ group.moveX();
+ }
+ }
+
+ private boolean isSomethingSet() {
+ for (int i = 0; i < items.length; i++)
+ if(items[i].isSet) return true;
+ return false;
+ }
+
+ public void initField() {
+ field = new int[FX][];
+ for (int i = 0; i < FX; i++) {
+ field[i] = new int[FY];
+ for (int j = 0; j < FY; j++) field[i][j] = 0;
+ }
+ for (int i = 0; i < items.length; i++) {
+ if(items[i].isSet()) field[items[i].ix][items[i].iy] = 1;
+ }
+ }
+
+ static int MAX_SINGLES_PER_ROW = 5;
+ public void buildY() {
+ int miny = 0;
+ miny = buildYForSingleComments();
+ boolean isSomethingSet = isSomethingSet();
+ for (int i = 0; i < groups.size(); i++) {
+ Group group = (Group)groups.get(i);
+ if(group.items().length < 2) continue;
+ Item item = group.getItem(0);
+ if(item.yAssigned) continue;
+ group.miny = miny;
+ item.yAssigned = true;
+ if(!item.isSet()) item.iy = miny;
+ if(!isSomethingSet) group.buildY_2(item, field);
+ group.buildY(item, field);
+ miny = group.getMaxY() + 1;
+ if(miny > FY - 2) miny = FY - 2;
+ }
+ buildYForSingles(miny);
+ }
+
+ private int buildYForSingleComments() {
+ int miny = 0;
+ int ix = 0;
+ for (int i = 0; i < groups.size(); i++) {
+ Group group = (Group)groups.get(i);
+ if(group.items().length != 1) continue;
+ Item item = group.getItem(0);
+ if(!item.isComment()) continue;
+ if(!item.isSet()) {
+ group.miny = miny;
+ item.ix = ix;
+ item.iy = miny;
+ ix += 2;
+ if(ix > 2) {
+ ix = 0;
+ ++miny;
+ }
+ } else group.miny = 0;
+ }
+ if(ix > 0) ++miny;
+ return miny;
+ }
+
+ private void buildYForSingles(int miny) {
+ int ix = 0;
+ for (int i = 0; i < groups.size(); i++) {
+ Group group = (Group)groups.get(i);
+ if(group.items().length != 1 || group.miny >= 0) continue;
+ group.miny = miny;
+ Item item = group.getItem(0);
+ while(true) {
+ while(ix < field.length && field[ix][miny] == 1) ++ix;
+ if(ix > MAX_SINGLES_PER_ROW) {
+ ix = 0;
+ if(miny < FY - 1) ++miny; else break;
+ } else break;
+ }
+ if(!item.isSet()) {
+ item.iy = miny;
+ item.ix = ix;
+ ++ix;
+ }
+ field[item.ix][item.iy] = 1;
+ }
+ }
+
+ void buildXDeltasForSingles() {
+ int[] xDeltas = new int[100];
+ for (int i = 0; i < groups.size(); i++) {
+ Group group = (Group)groups.get(i);
+ if(group.items().length != 1) continue;
+ group.xDeltas = xDeltas;
+ Item item = group.getItem(0);
+ int c = item.ix;
+ c++;
+ if(c >= xDeltas.length) continue;
+ int[] shape = item.getObject().getShape();
+ if(shape == null || shape.length < 4) continue;
+ int wi = (shape[2] - (constants.deltaX / 2)) / constants.incX;
+ if(wi > xDeltas[c]) xDeltas[c] = wi;
+ }
+ for (int i = 1; i < xDeltas.length; i++) xDeltas[i] += xDeltas[i - 1];
+ }
+
+ public void buildDeltas() {
+ for (int i = 0; i < groups.size(); i++) {
+ Group group = (Group)groups.get(i);
+ group.buildXDeltas();
+ }
+ buildYDeltas();
+ buildXDeltasForSingles();
+ }
+
+ public void buildYDeltas() {
+ yDeltas = new int[getMaxY() + 1];
+ for (int i = 0; i < yDeltas.length; i++) yDeltas[i] = 0;
+ for (int i = 0; i < items.length; i++) {
+ int c = items[i].iy + 1;
+ if(c >= yDeltas.length) continue;
+ int sz = items[i].outputs.length - 1;
+ if(sz > yDeltas[c]) yDeltas[c] = sz;
+ }
+ for (int i = 1; i < yDeltas.length; i++) yDeltas[i] += yDeltas[i - 1];
+ }
+
+ public int getMaxY() {
+ int max = 0;
+ for (int i = 0; i < items.length; i++) if(items[i].iy > max) max = items[i].iy;
+ return max;
+ }
+
+
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Item.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Item.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Item.java 2007-07-05 11:59:21 UTC (rev 2306)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * 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.impl;
+
+import java.util.*;
+
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.IItemInfo;
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.ILinkInfo;
+
+
+public class Item {
+ protected IItemInfo itemInfo;
+ protected int n;
+ protected int x = 0;
+ protected int y = 0;
+ protected int ix = -1;
+ protected int iy = -1;
+ protected int[] inputs = new int[0];
+ protected int[] outputs = new int[0];
+ protected int[] comments = new int[0];
+ protected ArrayList inputLinks = new ArrayList();
+ protected boolean isOwned = false;
+ protected int weight = 0;
+ protected Group group = null;
+ protected int yIndent = 1; // Page = 2; other = 1;
+
+ protected boolean isSet = false;
+ protected boolean yAssigned = false;
+
+ public Item() {}
+
+ public IItemInfo getObject() {
+ return itemInfo;
+ }
+
+ public boolean isSet() {
+ return isSet;
+ }
+
+ public void addInput(int i, ILinkInfo link) {
+ int[] k = new int[inputs.length + 1];
+ System.arraycopy(inputs, 0, k, 0, inputs.length);
+ k[inputs.length] = i;
+ inputs = k;
+ inputLinks.add(link);
+ }
+
+ public void addOutput(int i) {
+ int[] k = new int[outputs.length + 1];
+ System.arraycopy(outputs, 0, k, 0, outputs.length);
+ k[outputs.length] = i;
+ outputs = k;
+ }
+
+ public void addComment(int i) {
+ int[] k = new int[comments.length + 1];
+ System.arraycopy(comments, 0, k, 0, comments.length);
+ k[comments.length] = i;
+ comments = k;
+ }
+
+ public boolean isSingle() {
+ return inputs.length == 0 && outputs.length == 0;
+ }
+
+ public void print() {
+// StringBuffer sb = new StringBuffer();
+/// sb.append(object.getPathPart() + " " + n + " g = " + group + " ix = " + ix + " iy = " + iy);
+/// System.out.println(sb.toString());
+ }
+
+ public boolean isComment() {
+ return itemInfo != null && itemInfo.isComment();
+ }
+
+ int gravity;
+ boolean[] outputActivities;
+ boolean[] inputActivities;
+
+ public void initActivities() {
+ outputActivities = new boolean[outputs.length];
+ for (int i = 0; i < outputActivities.length; i++) outputActivities[i] = outputs[i] != n;
+ inputActivities = new boolean[inputs.length];
+ for (int i = 0; i < inputActivities.length; i++) inputActivities[i] = inputs[i] != n;
+ }
+
+ public void setWeight(int w) {
+ weight = w;
+ }
+
+ public void setYIndent(int y) {
+ yIndent = y;
+ }
+
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Items.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Items.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Items.java 2007-07-05 11:59:21 UTC (rev 2306)
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * 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.impl;
+
+import java.util.*;
+
+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;
+
+
+public class Items {
+ protected LayuotConstants constants;
+ protected IDiagramInfo process;
+ protected Item[] items;
+ protected Map paths = new HashMap();
+ protected Groups groups = new Groups();
+ protected boolean override = false;
+
+ public Items() {}
+
+ public void setConstants(LayuotConstants constants) {
+ this.constants = constants;
+ groups.setConstants(constants);
+ }
+
+ public void setOverride(boolean b) {
+ override = b;
+ }
+
+ public void setProcess(IDiagramInfo process) {
+ this.process = process;
+ try { load(); } catch (Exception e) { e.printStackTrace(); }
+ }
+
+ private void load() {
+ initItems();
+ if(isAllSet()) return;
+ buildBinds();
+ groups.load(items);
+ print();
+ }
+
+ private void initItems() {
+ IItemInfo[] is = process.getItems();
+ items = new Item[is.length];
+ for (int i = 0; i < is.length; i++) {
+ Item item = new Item();
+ items[i] = item;
+ paths.put(is[i].getID(), item);
+ item.n = i;
+ item.itemInfo = is[i];
+ int[] shape = is[i].getShape();
+ if(!override && shape != null && shape.length > 1) {
+ item.x = shape[0];
+ item.y = shape[1];
+ if(item.x != 0 && item.y != 0) item.isSet = true;
+ item.ix = (item.x / constants.deltaX);
+ item.iy = (item.y / constants.deltaY);
+ if(item.ix < 0) item.ix = 0;
+ if(item.iy < 0) item.iy = 0;
+ if(item.ix >= Groups.FX) item.ix = Groups.FX - 1;
+ if(item.iy >= Groups.FY) item.iy = Groups.FY - 1;
+ }
+ initItem(item);
+ }
+ }
+
+ // override
+ protected void initItem(Item item) {}
+
+ // override
+
+ public ILinkInfo[] getOutput(IItemInfo itemObject) {
+ return itemObject.getLinks();
+ }
+
+ private boolean isAllSet() {
+ for (int i = 0; i < items.length; i++) if(!items[i].isSet()) return false;
+ return true;
+ }
+
+ private void buildBinds() {
+ for (int i = 0; i < items.length; i++) {
+ ILinkInfo[] ts = (items[i].itemInfo instanceof ILinkInfo)
+ ? new ILinkInfo[]{(ILinkInfo)items[i].itemInfo}
+ : getOutput(items[i].itemInfo);
+ for (int j = 0; j < ts.length; j++) {
+ String target = ts[j].getTargetID();
+ if(target == null || target.length() == 0) continue;
+ Item item2 = (Item)paths.get(target);
+ if(item2 == null) {
+ continue;
+ } if(items[i].isComment()) {
+ item2.addComment(items[i].n);
+ items[i].isOwned = true;
+ } else if(item2.weight < 0) {
+ continue;
+ } else {
+ item2.addInput(items[i].n, ts[j]);
+ items[i].addOutput(item2.n);
+ }
+ }
+ }
+ }
+
+ private void print() {
+ for (int i = 0; i < items.length; i++)
+ items[i].print();
+ }
+
+}
+
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/LayuotConstants.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/LayuotConstants.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/LayuotConstants.java 2007-07-05 11:59:21 UTC (rev 2306)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * 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.impl;
+
+public class LayuotConstants {
+ static int DELTA_X = 200;
+ static int DELTA_Y = 104;
+ static int X_INC = 32;
+ static int Y_INC = 24;
+
+ public int deltaX = DELTA_X;
+ public int deltaY = DELTA_Y;
+ public int incX = X_INC;
+ public int incY = Y_INC;
+ public int indentX = 24;
+ public int indentY = 16;
+
+ public void update(String gridStep) {
+ try {
+ int step = Integer.parseInt(gridStep);
+ indentX = (step < 24) ? 24 : step;
+ indentY = (step < 16) ? 16 : step;
+ if(step == 16) {
+ deltaX = 208;
+ deltaY = 112;
+ incX = 16;
+ incY = 32;
+ indentX = 32;
+ } else if(step == 24) {
+ deltaX = 240;
+ deltaY = 120;
+ incX = 24;
+ incY = 24;
+ } else if(step == 32) {
+ deltaX = 256;
+ deltaY = 128;
+ incX = 32;
+ incY = 32;
+ } else if(step == 40) {
+ deltaX = 240;
+ deltaY = 120;
+ incX = 40;
+ incY = 40;
+ } else {
+ deltaX = DELTA_X;
+ deltaY = DELTA_Y;
+ incX = X_INC;
+ incY = Y_INC;
+ }
+ } catch (Exception e) {
+ deltaX = DELTA_X;
+ deltaY = DELTA_Y;
+ incX = X_INC;
+ incY = Y_INC;
+ }
+ }
+
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/TransitionArranger.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/TransitionArranger.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/TransitionArranger.java 2007-07-05 11:59:21 UTC (rev 2306)
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * 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.impl;
+
+import java.util.ArrayList;
+
+import org.jboss.tools.hibernate.ui.veditor.editors.autolayout.ILinkInfo;
+
+
+public class TransitionArranger {
+ Item[] items;
+
+ public void setItems(Item[] items) {
+ this.items = items;
+ }
+
+ public void execute() {
+ int maxX = getMaxX();
+ int maxY = getMaxY();
+ int[][] occ = new int[occ0.length][maxY + 1];
+ Item[] v = new Item[maxY + 1];
+ for (int ix = 0; ix <= maxX; ix++) {
+ clean(occ);
+ fill(v, ix);
+ execute(ix, occ, v);
+ }
+ }
+
+ private void clean(int[][] occ) {
+ for (int i = 0; i < occ.length; i++) for (int j = 0; j < occ[0].length; j++) occ[i][j] = 0;
+ }
+
+ private void fill(Item[] v, int ix) {
+ for (int i = 0; i < v.length; i++) v[i] = null;
+ for (int i = 0; i < items.length; i++) {
+ if(items[i].inputs.length == 0 || items[i].isOwned) continue;
+ if(items[i].ix == ix) v[items[i].iy] = items[i];
+ }
+ }
+
+ private int[] occ0 = new int[10];
+
+ private void execute(int ix, int[][] occ, Item[] v) {
+ int delta = 0;
+ for (int iy = 0; iy < v.length; iy++) {
+ if(v[iy] == null) continue;
+ for (int i = 0; i < occ0.length; i++) occ0[i] = 0;
+ int[] is = v[iy].inputs;
+ delta = 0;
+ for (int k = 0; k < is.length; k++) {
+ int iy2 = items[is[k]].iy;
+ int miny = Math.min(iy, iy2);
+ int maxy = Math.max(iy, iy2);
+ if(maxy - miny > delta) delta = maxy - miny;
+ for (int m = 0; m < occ0.length; m++) for (int y = miny; y <= maxy; y++)
+ if(occ[m][y] > 0) occ0[m] += occ[m][y];
+ }
+ int tg = findTransitionLine(delta, occ0);
+ for (int k = 0; k < is.length; k++) {
+ int iy2 = items[is[k]].iy;
+ occ[tg][iy2]++;
+ }
+ apply(v[iy], tg);
+ }
+ }
+
+ private int getMaxX() {
+ int ix = 0;
+ for (int i = 0; i < items.length; i++) {
+ if(items[i].ix > ix) ix = items[i].ix;
+ }
+ return ix;
+ }
+
+ private int getMaxY() {
+ int iy = 0;
+ for (int i = 0; i < items.length; i++) {
+ if(items[i].iy > iy) iy = items[i].iy;
+ }
+ return iy;
+ }
+
+ private int findTransitionLine(int pref, int[] occ0) {
+ if(pref >= occ0.length) pref = occ0.length - 1;
+ int h = 1000;
+ int p = -1;
+ for (int i = 0; i < occ0.length; i++) {
+ int h1 = occ0[i] * 3 + Math.abs(i - pref);
+ if(h1 < h) {
+ h = h1;
+ p = i;
+ }
+ }
+ return p;
+ }
+
+ private void apply(Item item, int tg) {
+ ArrayList links = item.inputLinks;
+ for (int k = 0; k < links.size(); k++) {
+ ILinkInfo io = (ILinkInfo)links.get(k);
+ io.setLinkShape(new int[]{-1, 8 * (tg + 2)});
+ }
+ }
+
+}
17 years, 6 months
JBoss Tools SVN: r2305 - in trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui: veditor and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: mdryakhlenkov
Date: 2007-07-05 07:58:57 -0400 (Thu, 05 Jul 2007)
New Revision: 2305
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/EditorActionContributor.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/Messages.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/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/EditorActionContributor.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/EditorActionContributor.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/EditorActionContributor.java 2007-07-05 11:58:57 UTC (rev 2305)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.ui.veditor.editors;
+
+import org.eclipse.gef.ui.actions.ActionBarContributor;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
+import org.jboss.tools.hibernate.ui.view.ViewPlugin;
+
+public class EditorActionContributor extends ActionBarContributor {
+
+ protected void buildActions() {
+ IWorkbenchAction workbenchAction = ActionFactory.REFRESH.create(getPage().getWorkbenchWindow());
+ workbenchAction.setImageDescriptor(ViewPlugin.getImageDescriptor(ViewPlugin.BUNDLE_IMAGE.getString("Explorer.refreshOrmGef"))); //$NON-NLS-1$
+ workbenchAction.setToolTipText(Messages.EditorActionContributor_Refresh_Visual_Mapping);
+ addAction(workbenchAction);
+ }
+
+ public void contributeToToolBar(IToolBarManager toolBarManager) {
+ toolBarManager.add(getAction(ActionFactory.REFRESH.getId()));
+ }
+
+ protected void declareGlobalActionKeys() {
+ }
+}
\ No newline at end of file
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/Messages.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/Messages.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/Messages.java 2007-07-05 11:58:57 UTC (rev 2305)
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.ui.veditor.editors;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+ private static final String BUNDLE_NAME = "org.jboss.tools.hibernate.ui.veditor.editors.messages";
+
+ private Messages() {
+ }
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ public static String EditorActionContributor_Refresh_Visual_Mapping;
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java 2007-07-05 11:58:57 UTC (rev 2305)
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.ui.veditor.editors;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.gef.DefaultEditDomain;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.dnd.TemplateTransferDropTargetListener;
+import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
+import org.eclipse.gef.requests.CreationFactory;
+import org.eclipse.gef.requests.SimpleFactory;
+import org.eclipse.gef.ui.actions.WorkbenchPartAction;
+import org.eclipse.gef.ui.parts.GraphicalEditor;
+import org.eclipse.jface.util.TransferDropTargetListener;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.actions.ActionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.mapping.RootClass;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+import org.jboss.tools.hibernate.ui.veditor.editors.parts.OrmEditPartFactory;
+import org.jboss.tools.hibernate.ui.view.views.ObjectEditorInput;
+
+public class VisualEditor extends GraphicalEditor {
+
+ private OrmDiagram ormDiagram = null;
+
+ public VisualEditor() {
+ setEditDomain(new DefaultEditDomain(this));
+ }
+
+ public void doSave(IProgressMonitor monitor) {
+ ormDiagram.save();
+ ormDiagram.setDirty(false);
+ }
+
+ public void doSaveAs() {
+ }
+
+ protected void initializeGraphicalViewer() {
+ final GraphicalViewer viewer = getGraphicalViewer();
+ viewer.setEditPartFactory(new OrmEditPartFactory());
+ viewer.setRootEditPart(new ScalableFreeformRootEditPart());
+ viewer.addDropTargetListener(createTransferDropTargetListener());
+ viewer.setContents(ormDiagram);
+ }
+
+ protected void createActions() {
+ getEditorSite().getActionBars().setGlobalActionHandler(ActionFactory.REFRESH.getId(),new WorkbenchPartAction(this){
+
+ protected boolean calculateEnabled() {
+ return true;
+ }
+ public void run() {
+ ormDiagram.refresh();
+ }
+ });
+ super.createActions();
+ }
+
+ private TransferDropTargetListener createTransferDropTargetListener() {
+ return new TemplateTransferDropTargetListener(getGraphicalViewer()) {
+ protected CreationFactory getFactory(Object template) {
+ return new SimpleFactory((Class) template);
+ }
+ };
+ }
+
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ public boolean isSaveOnCloseNeeded() {
+ return true;
+ }
+
+ public void refreshDirty() {
+ firePropertyChange(IEditorPart.PROP_DIRTY);
+ }
+
+ public boolean isDirty() {
+ return ormDiagram.isDirty();
+ }
+
+ protected void setInput(IEditorInput input) {
+ super.setInput(input);
+ ObjectEditorInput objectEditorInput = (ObjectEditorInput)input;
+ Configuration configuration = objectEditorInput.getConfiguration();
+ RootClass rootClass = (RootClass)(objectEditorInput).getObject();
+ setPartName("Diagram for " + rootClass.getClassName());
+ ormDiagram = new OrmDiagram(configuration, rootClass);
+ }
+}
Added: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/messages.properties
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/messages.properties (rev 0)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/messages.properties 2007-07-05 11:58:57 UTC (rev 2305)
@@ -0,0 +1 @@
+EditorActionContributor_Refresh_Visual_Mapping=Refresh Visual Mapping
17 years, 6 months