Author: vyemialyanchyk
Date: 2009-06-18 08:31:56 -0400 (Thu, 18 Jun 2009)
New Revision: 16039
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/DiagramContentOutlinePage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java
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
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
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
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ConnectionEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramTreeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeTreeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/GEFRootEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ResourceManager.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeTreeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/popup/PopupMenuProvider.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4499 - made model structure more clear
(parent-child relations) and format code in one style
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/DiagramContentOutlinePage.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/DiagramContentOutlinePage.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/DiagramContentOutlinePage.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -90,8 +90,8 @@
}
public void update(GraphicalViewer graphicalViewer){
- if(this.graphicalViewer != null){
- if(this.graphicalViewer != graphicalViewer){
+ if (this.graphicalViewer != null) {
+ if (this.graphicalViewer != graphicalViewer) {
getSelectionSynchronizer().removeViewer(this.graphicalViewer);
replaceSelectionChangedListeners(graphicalViewer);
this.graphicalViewer = graphicalViewer;
@@ -233,7 +233,7 @@
if (rep instanceof ScalableFreeformRootEditPart) {
ScalableFreeformRootEditPart root = (ScalableFreeformRootEditPart) rep;
- if(this.thumbnail != null) {
+ if (this.thumbnail != null) {
this.thumbnail.deactivate();
}
thumbnail = new ScrollableThumbnail((Viewport) root.getFigure());
@@ -256,11 +256,13 @@
showOutlineAction.setChecked(true);
showOverviewAction.setChecked(false);
pageBook.showPage(outline);
- if (thumbnail != null)
+ if (thumbnail != null) {
thumbnail.setVisible(false);
+ }
} else if (id == ID_OVERVIEW) {
- if (thumbnail == null)
+ if (thumbnail == null) {
initializeOverview();
+ }
showOutlineAction.setChecked(false);
showOverviewAction.setChecked(true);
pageBook.showPage(overview);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/VisualEditor.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -39,9 +39,7 @@
import org.jboss.tools.hibernate.ui.veditor.editors.actions.ExportImageAction;
import org.jboss.tools.hibernate.ui.veditor.editors.actions.OpenMappingAction;
import org.jboss.tools.hibernate.ui.veditor.editors.actions.OpenSourceAction;
-import org.jboss.tools.hibernate.ui.veditor.editors.model.ModelElement;
import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
-import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
import org.jboss.tools.hibernate.ui.veditor.editors.parts.GEFRootEditPart;
import org.jboss.tools.hibernate.ui.veditor.editors.parts.OrmEditPart;
@@ -139,7 +137,6 @@
}
protected void setInput(IEditorInput input) {
- super.setInput(input);
ObjectEditorInput objectEditorInput = (ObjectEditorInput)input;
ConsoleConfiguration configuration = objectEditorInput.getConfiguration();
Object obj = objectEditorInput.getObject();
@@ -147,8 +144,7 @@
RootClass rootClass = (RootClass)obj;
setPartName(UIVEditorMessages.VisualEditor_diagram_for + rootClass.getEntityName());
ormDiagram = new OrmDiagram(configuration, rootClass);
- }
- else if (obj instanceof RootClass[]) {
+ } else if (obj instanceof RootClass[]) {
RootClass[] rootClasses = (RootClass[])obj;
String name = rootClasses.length > 0 ? rootClasses[0].getEntityName() :
""; //$NON-NLS-1$
for (int i = 1; i < rootClasses.length; i++) {
@@ -157,6 +153,7 @@
setPartName(UIVEditorMessages.VisualEditor_diagram_for + name);
ormDiagram = new OrmDiagram(configuration, rootClasses);
}
+ super.setInput(input);
}
@SuppressWarnings("unchecked")
@@ -174,24 +171,6 @@
return super.getAdapter(type);
}
- public Set<Object> getSelectedElements_old() {
- Set<Object> ret = new HashSet<Object>();
- List<?> selectedEditParts = getGraphicalViewer().getSelectedEditParts();
- Iterator<?> iterator = selectedEditParts.iterator();
- while (iterator.hasNext()) {
- Object elem = iterator.next();
- if (elem instanceof OrmEditPart) {
- Object model = ((OrmEditPart)elem).getModel();
- ModelElement shape = (Shape)model;
- while (!(shape instanceof OrmShape)) {
- shape = shape.getParent();
- }
- ret.add(((OrmShape)shape).getOrmElement());
- }
- }
- return ret;
- }
-
public Set<Object> getSelectedElements() {
Set<Object> ret = new HashSet<Object>();
List<?> selectedEditParts = getGraphicalViewer().getSelectedEditParts();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenMappingAction.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -78,79 +78,6 @@
} catch (FileNotFoundException e) {
HibernateConsolePlugin.getDefault().logErrorMessage(UIVEditorMessages.OpenMappingAction_open_mapping_file,
e);
}
-
- /*IResource resource = null;
- Object selectedElement = selection;
- if (selectedElement instanceof RootClass) {
- RootClass rootClass = (RootClass)selectedElement;
-
- resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
configXMLFile, rootClass);
-
- if (resource == null) {
- if (OpenFileActionUtils.rootClassHasAnnotations(consoleConfiguration,
configXMLFile, rootClass)) {
- String fullyQualifiedName = HibernateUtils.getPersistentClassName(rootClass);
- try {
- resource = proj.findType(fullyQualifiedName).getResource();
- } catch (JavaModelException e) {
- VisualEditorPlugin.getDefault().logInfo("Can't find mapping
file", e);
- }
- } else {
- if (rootClass instanceof SpecialRootClass) {
- PersistentClass src =
((SpecialRootClass)rootClass).getProperty().getPersistentClass();
- while (src instanceof SpecialRootClass) {
- src = ((SpecialRootClass)src).getProperty().getPersistentClass();
- }
- resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
configXMLFile, src);
- }
- }
- }
- } else if (selectedElement instanceof Table) {
- Table table = (Table)selectedElement;
- resource = OpenFileActionUtils.getResource(consoleConfiguration, proj, configXMLFile,
table);
-
- if (resource == null) {
- Iterator classMappingsIterator =
consoleConfiguration.getConfiguration().getClassMappings();
- while (classMappingsIterator.hasNext()) {
- PersistentClass elem = (PersistentClass) classMappingsIterator.next();
- if
(HibernateUtils.getTableName(elem.getTable()).equals(HibernateUtils.getTableName(table)))
{
- String fullyQualifiedName = HibernateUtils.getPersistentClassName(elem);
- try {
- resource = proj.findType(fullyQualifiedName).getResource();
- } catch (JavaModelException e) {
- VisualEditorPlugin.getDefault().logInfo("Can't find mapping
file", e);
- }
- }
- }
- }
-
- if (resource == null) {
- Iterator collectionMappingsIterator =
consoleConfiguration.getConfiguration().getCollectionMappings();
- while (collectionMappingsIterator.hasNext()) {
- Collection elem = (Collection)collectionMappingsIterator.next();
- Table collectionTable = elem.getCollectionTable();
- if
(HibernateUtils.getTableName(collectionTable).equals(HibernateUtils.getTableName(table)))
{
- PersistentClass owner = elem.getOwner();
- resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
configXMLFile, owner);
- }
- }
- }
- } else if (selectedElement instanceof Subclass) {
- Subclass rootClass = (Subclass)selectedElement;
- resource = OpenFileActionUtils.getResource(consoleConfiguration, proj,
configXMLFile, rootClass);
- }
-
- if (resource != null) {
- try {
- IEditorPart editorPart =
OpenFileActionUtils.openEditor(VisualEditorPlugin.getPage(), resource);
- if (selectedElement instanceof PersistentClass
- || (selectedElement instanceof Property
- && ((Property)selectedElement).getPersistentClass() != null)){
- org.hibernate.eclipse.console.actions.OpenMappingAction.applySelectionToEditor(selectedElement,
editorPart);
- }
- } catch (PartInitException e) {
- VisualEditorPlugin.getDefault().logInfo("Can't open mapping file",
e);
- }
- }*/
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/actions/OpenSourceAction.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -48,7 +48,9 @@
rootClass = (PersistentClass) selection;
} else if (selection instanceof Property) {
rootClass = ((Property) selection).getPersistentClass();
- } else continue;
+ } else {
+ continue;
+ }
IResource resource = null;
String fullyQualifiedName =
rootClass.getClassName();//HibernateUtils.getPersistentClassName(rootClass);
@@ -69,6 +71,9 @@
protected boolean calculateEnabled() {
VisualEditor part = (VisualEditor)getWorkbenchPart();
+ return part.getSelectedElements().size() > 0;
+ /** /
+ VisualEditor part = (VisualEditor)getWorkbenchPart();
Set selectedElements = part.getSelectedElements();
Iterator iterator = selectedElements.iterator();
while (iterator.hasNext()) {
@@ -77,5 +82,6 @@
|| elem instanceof Property) return true;
}
return false;
+ /**/
}
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/AutoLayoutImpl.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -38,7 +38,7 @@
// constants.update();
items.setProcess(process);
apply();
- if(items.override) {
+ if (items.override) {
TransitionArranger a = new TransitionArranger();
a.setItems(items.items);
a.execute();
@@ -51,11 +51,15 @@
Item[] is = items.items;
int[] yDeltas = items.groups.yDeltas;
for (int i = 0; i < is.length; i++) {
- if(is[i].isSet()) continue;
+ 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;
+ 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});
@@ -63,11 +67,13 @@
}
private void resetTransitions() {
- if(!items.override) return;
+ 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) {
+ if (o instanceof ILinkInfo) {
((ILinkInfo)o).setLinkShape(new int[0]);
}
ILinkInfo[] os = items.getOutput(o);
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Group.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -15,106 +15,131 @@
public class Group {
LayuotConstants constants;
- int number;
- List<Integer> itemList = new ArrayList<Integer>();
+ int number;
+ List<Integer> itemList = new ArrayList<Integer>();
Item[] allitems = null;
- private int[] items = null;
- int miny = -1;
- int[] xDeltas = 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 Group() {
+ }
- public void setConstants(LayuotConstants constants) {
- this.constants = constants;
- }
+ public void setItems(Item[] items) {
+ allitems = items;
+ }
- public void expandGroup(int _item) {
- Item item = allitems[_item];
- item.group = this;
- itemList.add(Integer.valueOf(_item));
+ public void setConstants(LayuotConstants constants) {
+ this.constants = constants;
+ }
+
+ public void expandGroup(int _item) {
+ Item item = allitems[_item];
+ item.group = this;
+ itemList.add(Integer.valueOf(_item));
int[] is = item.comments;
for (int i = 0; i < is.length; i++) {
Item item2 = allitems[is[i]];
- if(!item2.isSet()) {
+ 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]);
- }
- }
+ 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] = itemList.get(i);
- }
- return items;
- }
-
- Item getItem(int i) {
- return allitems[items[i]];
- }
+ int[] items() {
+ if (items == null) {
+ items = new int[itemList.size()];
+ for (int i = 0; i < items.length; i++) {
+ items[i] = itemList.get(i);
+ }
+ }
+ return items;
+ }
- 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()) {
+ 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;
- }
- }
- }
+ 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;
+ if (item2.yAssigned) {
+ continue;
+ }
item2.yAssigned = true;
- if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ 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 (item2.yAssigned) {
+ continue;
+ }
item2.yAssigned = true;
- if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ 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 (item2.yAssigned) {
+ continue;
+ }
item2.yAssigned = true;
- if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ if (!item2.isSet()) {
+ item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ }
buildY(item2, field);
}
}
@@ -124,27 +149,43 @@
int[] is = item.comments;
for (int i = 0; i < is.length; i++) {
Item item2 = allitems[is[i]];
- if(item2.yAssigned) continue;
+ if (item2.yAssigned) {
+ continue;
+ }
item2.yAssigned = true;
- if(!item2.isSet()) item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ 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;
+ 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);
+ 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;
+ 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);
+ if (!item2.isSet()) {
+ item2.iy = findFreeY(item2.ix, miny, item.iy, Groups.FY, field);
+ }
buildY(item2, field);
}
}
@@ -152,87 +193,127 @@
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;
+ 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;
+ 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;
+ 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 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;
+ 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];
+ }
+ }
- 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 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();
+ 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(Integer.valueOf(_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]);
- }
- }
-
+
+ private void expandGroup2(int _item) {
+ Item item = allitems[_item];
+ item.group = this;
+ itemList.add(Integer.valueOf(_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]);
+ }
+ }
+ }
+
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/GroupArranger.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -12,56 +12,62 @@
public class GroupArranger {
Group group;
- int mgi = 0; // items with indefinite gravity
- boolean inited = false;
-
+ 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) {
+ if (item.isOwned) {
item.gravity = -1;
- } else if(item.inputs.length == 0) {
+ } else if (item.inputs.length == 0) {
item.gravity = 0;
- } else if(item.outputs.length == 0) {
+ } else if (item.outputs.length == 0) {
item.gravity = 2000;
} else {
item.gravity = 1000;
++mgi;
}
- }
+ }
}
-
+
public void arrange() {
init();
- while(mgi > 0) {
+ while (mgi > 0) {
split();
- if(mgi > 0) cut(findBestCutIndex());
+ if (mgi > 0) {
+ cut(findBestCutIndex());
+ }
}
reduce();
}
-
+
private void split() {
int length = group.items().length;
boolean work = true;
- while(work) {
+ while (work) {
work = false;
for (int i = 0; i < length; i++) {
Item item = group.getItem(i);
- if(item.gravity != 1000) continue;
+ if (item.gravity != 1000) {
+ continue;
+ }
int q = computeLowerWeight(i);
- if(q < item.gravity) {
+ if (q < item.gravity) {
item.gravity = q;
work = true;
--mgi;
}
- if(item.gravity != 1000) continue;
+ if (item.gravity != 1000) {
+ continue;
+ }
q = computeUpperWeight(i);
- if(q > item.gravity) {
+ if (q > item.gravity) {
item.gravity = q;
work = true;
--mgi;
@@ -69,109 +75,137 @@
}
}
}
-
+
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;
+ if (!item.inputActivities[i]) {
+ continue;
+ }
Item si = group.allitems[is[i]];
- if(si.gravity + 1 > q) q = si.gravity + 1;
+ 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;
+ if (is.length == 0) {
+ return item.gravity;
+ }
int q = 2000;
for (int i = 0; i < is.length; i++) {
- if(!item.outputActivities[i]) continue;
+ if (!item.outputActivities[i]) {
+ continue;
+ }
Item si = group.allitems[is[i]];
- if(si.gravity - 1 < q) q = si.gravity - 1;
+ 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;
+ 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;
+ if (item.gravity != 1000) {
+ continue;
+ }
int w2 = getCuttingPreference(i);
- if(w2 < w) {
+ if (w2 < w) {
w = w2;
k = i;
}
- }
- return k;
+ }
+ 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;
+ if (!item.inputActivities[i]) {
+ continue;
+ }
Item si = group.allitems[is[i]];
- if(si.gravity == 1000) ++q;
+ if (si.gravity == 1000) {
+ ++q;
+ }
}
q = 10 * q;
is = item.outputs;
for (int i = 0; i < is.length; i++) {
- if(!item.outputActivities[i]) continue;
+ if (!item.outputActivities[i]) {
+ continue;
+ }
Item si = group.allitems[is[i]];
- if(si.gravity == 1000) --q;
+ 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;
+ if (!item.inputActivities[i]) {
+ continue;
+ }
Item si = group.allitems[is[i]];
- if(si.gravity == 1000) {
+ if (si.gravity == 1000) {
activateInput(item, i, false);
- }
+ }
}
}
private void reduce() {
boolean work = true;
- while(work) {
+ while (work) {
work = false;
for (int i = 0; i < group.items().length; i++) {
Item item = group.getItem(i);
- if(item.gravity < 0) continue;
+ if (item.gravity < 0) {
+ continue;
+ }
int q = computeLowerWeight(i);
- if(q < item.gravity) {
+ if (q < item.gravity) {
item.gravity = q;
work = true;
}
}
}
work = true;
- while(work) {
+ while (work) {
work = false;
for (int i = 0; i < group.items().length; i++) {
Item item = group.getItem(i);
- if(item.gravity < 0) continue;
+ if (item.gravity < 0) {
+ continue;
+ }
int q = computeUpperWeight(i);
- if(q > item.gravity) {
+ if (q > item.gravity) {
item.gravity = q;
work = true;
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Groups.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -14,40 +14,45 @@
public class Groups {
protected LayuotConstants constants;
- static int FX = 30, FY = 120;
- List<Group> groups = new ArrayList<Group>();
- Item[] items;
- int[][] field;
- int[] yDeltas = null;
+ static int FX = 30, FY = 120;
+ List<Group> groups = new ArrayList<Group>();
+ Item[] items;
+ int[][] field;
+ int[] yDeltas = null;
- public Groups() {}
+ public Groups() {
+ }
- public void setConstants(LayuotConstants constants) {
- this.constants = constants;
- }
+ public void setConstants(LayuotConstants constants) {
+ this.constants = constants;
+ }
- public void load(Item[] items) {
- this.items = items;
- init();
- initField();
- buildY();
- buildDeltas();
- }
+ 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;
+ 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;
+ if (!items[i].isSet()) {
+ items[i].ix = 0;
+ }
group.setItems(items);
- if(isSomethingSet) {
+ if (isSomethingSet) {
group.expandGroup(i);
} else {
group.createGroup(i);
@@ -55,10 +60,13 @@
group.moveX();
}
}
-
+
private boolean isSomethingSet() {
- for (int i = 0; i < items.length; i++)
- if(items[i].isSet) return true;
+ for (int i = 0; i < items.length; i++) {
+ if (items[i].isSet) {
+ return true;
+ }
+ }
return false;
}
@@ -66,128 +74,185 @@
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 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;
+ 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 = groups.get(i);
- if(group.items().length < 2) continue;
+ if (group.items().length < 2) {
+ continue;
+ }
Item item = group.getItem(0);
- if(item.yAssigned) continue;
+ if (item.yAssigned) {
+ continue;
+ }
group.miny = miny;
item.yAssigned = true;
- if(!item.isSet()) item.iy = miny;
- if(!isSomethingSet) group.buildY_2(item, field);
+ 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;
+ if (miny > FY - 2) {
+ miny = FY - 2;
+ }
}
buildYForSingles(miny);
}
-
- private int buildYForSingleComments() {
+
+ private int buildYForSingleComments() {
int miny = 0;
int ix = 0;
for (int i = 0; i < groups.size(); i++) {
Group group = groups.get(i);
- if(group.items().length != 1) continue;
+ if (group.items().length != 1) {
+ continue;
+ }
Item item = group.getItem(0);
- if(!item.isComment()) continue;
- if(!item.isSet()) {
+ if (!item.isComment()) {
+ continue;
+ }
+ if (!item.isSet()) {
group.miny = miny;
item.ix = ix;
item.iy = miny;
ix += 2;
- if(ix > 2) {
+ if (ix > 2) {
ix = 0;
++miny;
}
- } else group.miny = 0;
+ } else {
+ group.miny = 0;
+ }
}
- if(ix > 0) ++miny;
- return miny;
- }
+ if (ix > 0) {
+ ++miny;
+ }
+ return miny;
+ }
- private void buildYForSingles(int miny) {
- int ix = 0;
- for (int i = 0; i < groups.size(); i++) {
- 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 = 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];
- }
+ private void buildYForSingles(int miny) {
+ int ix = 0;
+ for (int i = 0; i < groups.size(); i++) {
+ 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;
+ }
+ }
- public void buildDeltas() {
- for (int i = 0; i < groups.size(); i++) {
- Group group = groups.get(i);
- group.buildXDeltas();
- }
- buildYDeltas();
- buildXDeltasForSingles();
- }
+ void buildXDeltasForSingles() {
+ int[] xDeltas = new int[100];
+ for (int i = 0; i < groups.size(); i++) {
+ 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 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;
- int[] shape = items[i].getObject().getShape();
- if(shape == null || shape.length < 4) continue;
- int wi = (shape[3] - (constants.deltaY / 2)) / constants.incY;
- if(wi > yDeltas[c]) yDeltas[c] = wi;
- }
- for (int i = 1; i < yDeltas.length; i++) yDeltas[i] += yDeltas[i - 1];
- }
+ public void buildDeltas() {
+ for (int i = 0; i < groups.size(); i++) {
+ Group group = groups.get(i);
+ group.buildXDeltas();
+ }
+ buildYDeltas();
+ buildXDeltasForSingles();
+ }
- 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;
- }
+ 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;
+ }
+ int[] shape = items[i].getObject().getShape();
+ if (shape == null || shape.length < 4) {
+ continue;
+ }
+ int wi = (shape[3] - (constants.deltaY / 2)) / constants.incY;
+ if (wi > yDeltas[c]) {
+ yDeltas[c] = wi;
+ }
+ }
+ 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;
+ }
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Item.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -84,9 +84,13 @@
public void initActivities() {
outputActivities = new boolean[outputs.length];
- for (int i = 0; i < outputActivities.length; i++) outputActivities[i] = outputs[i]
!= n;
+ 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;
+ for (int i = 0; i < inputActivities.length; i++) {
+ inputActivities[i] = (inputs[i] != n);
+ }
}
public void setWeight(int w) {
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/Items.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -17,106 +17,125 @@
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<String, Item> paths = new HashMap<String, Item>();
- protected Groups groups = new Groups();
- protected boolean override = false;
+ protected IDiagramInfo process;
+ protected Item[] items;
+ protected Map<String, Item> paths = new HashMap<String, Item>();
+ protected Groups groups = new Groups();
+ protected boolean override = false;
- public Items() {}
-
- public void setConstants(LayuotConstants constants) {
- this.constants = constants;
- groups.setConstants(constants);
- }
+ public Items() {
+ }
- public void setOverride(boolean b) {
- override = b;
- }
-
- public void setProcess(IDiagramInfo process) {
- this.process = process;
- try { load(); } catch (Exception e) {
VisualEditorPlugin.getDefault().logError(e); }
- }
+ public void setConstants(LayuotConstants constants) {
+ this.constants = constants;
+ groups.setConstants(constants);
+ }
- private void load() {
- initItems();
- if(isAllSet()) return;
- buildBinds();
- groups.load(items);
- print();
- }
+ public void setOverride(boolean b) {
+ override = b;
+ }
- 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;
- }
+ public void setProcess(IDiagramInfo process) {
+ this.process = process;
+ load();
+ }
+
+ 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;
- }
+ // override
+ protected void initItem(Item item) {
+ }
- 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 = paths.get(target);
- if(item2 == null) {
- continue;
- } if(items[i].isComment()) {
+ // 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 = 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 if (item2.weight < 0) {
+ continue;
} else {
- item2.addInput(items[i].n, ts[j]);
- items[i].addOutput(item2.n);
+ 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();
- }
+ private void print() {
+ for (int i = 0; i < items.length; i++) {
+ items[i].print();
+ }
+ }
}
-
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/LayuotConstants.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -24,43 +24,44 @@
public int indentY = 16;
public void update(String gridStep) {
+ int step = 0;
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) {
+ step = Integer.parseInt(gridStep);
+ } catch (NumberFormatException e) {
deltaX = DELTA_X;
deltaY = DELTA_Y;
incX = X_INC;
incY = Y_INC;
}
+ 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;
+ }
}
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/autolayout/impl/TransitionArranger.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -39,10 +39,16 @@
}
private void fill(Item[] v, int ix) {
- for (int i = 0; i < v.length; i++) v[i] = null;
+ 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];
+ if (items[i].inputs.length == 0 || items[i].isOwned) {
+ continue;
+ }
+ if (items[i].ix == ix) {
+ v[items[i].iy] = items[i];
+ }
}
}
@@ -51,8 +57,12 @@
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;
+ 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++) {
@@ -60,8 +70,13 @@
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];
+ 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++) {
@@ -89,12 +104,14 @@
}
private int findTransitionLine(int pref, int[] occ0) {
- if(pref >= occ0.length) pref = occ0.length - 1;
+ 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) {
+ if (h1 < h) {
h = h1;
p = i;
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/ComponentFigure.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -20,29 +20,30 @@
private boolean childsHiden = false;
public void add(IFigure figure, Object constraint, int index) {
- if(index != -1){
- if(index == -2)
+ if (index != -1) {
+ if (index == -2) {
index = 0;
- else
+ } else {
index++;
+ }
}
super.add(figure, constraint, index);
}
public List getChildren() {
- if (childsHiden)
+ if (childsHiden) {
return super.getChildren().subList(0,1);
- else
- return super.getChildren();
-
+ }
+ return super.getChildren();
}
public void setChildsHiden(boolean childsHiden) {
this.childsHiden = childsHiden;
- for(int i=0;i<getChildren().size();i++){
- if(getChildren().get(i) instanceof TitleLabel)
+ for (int i = 0; i < getChildren().size(); i++) {
+ if (getChildren().get(i) instanceof TitleLabel) {
((TitleLabel)getChildren().get(i)).setHidden(childsHiden);
+ }
}
}
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundLineBorder.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -18,8 +18,9 @@
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)
+ if (getColor() != null) {
graphics.setForegroundColor(getColor());
+ }
graphics.drawRoundRectangle(tempRect, 2, 2);
}
}
\ No newline at end of file
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/RoundPolylineConnection.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -33,15 +33,15 @@
}
if (Math.abs(points.getFirstPoint().y - points.getLastPoint().y) < 4) {
int delta = Math.abs(points.getFirstPoint().y - points.getLastPoint().y);
- if(points.size() == 4){
+ if (points.size() == 4) {
Point point1 = points.getPoint(0);
Point point2 = points.getPoint(1);
Point point3 = points.getPoint(2);
Point point4 = points.getPoint(3);
- if(point1.x < point4.x){
+ if (point1.x < point4.x) {
point2.x -= delta/2;
point3.x += delta/2;
- }else{
+ } else {
point2.x += delta/2;
point3.x -= delta/2;
}
@@ -81,8 +81,9 @@
eCorner.y = beg.y;
}
- if (bCorner.x != 0 && eCorner.x != 0)
+ if (bCorner.x != 0 && eCorner.x != 0) {
g.drawLine(bCorner, eCorner);
+ }
bCorner.x = 0;
if (i != points.size() - 1) {
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleFigure.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -20,21 +20,21 @@
private boolean hiden = false;
public void add(IFigure figure, Object constraint, int index) {
- if(index != -1){
- if(index == -2)
+ if (index != -1) {
+ if (index == -2) {
index = 0;
- else
+ } else {
index++;
+ }
}
super.add(figure, constraint, index);
}
public List getChildren() {
- if (hiden)
+ if (hiden) {
return super.getChildren().subList(0,1);
- else
- return super.getChildren();
-
+ }
+ return super.getChildren();
}
public void setHidden(boolean hiden) {
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TitleLabel.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -28,16 +28,17 @@
protected Dimension calculateLabelSize(Dimension txtSize) {
Dimension p = super.calculateLabelSize(txtSize).getCopy();
- p.width+=40;
+ p.width += 40;
return p;
}
protected void paintFigure(Graphics graphics) {
super.paintFigure(graphics);
- if(hiden)
+ if (hiden) {
graphics.drawImage(shevronDown, getBounds().x+getBounds().width-20, getBounds().y);
- else
+ } else {
graphics.drawImage(shevronUp, getBounds().x+getBounds().width-20, getBounds().y);
+ }
}
public void setHidden(boolean hiden) {
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/figures/TopLineBorder.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -35,8 +35,9 @@
public void paint(IFigure figure, Graphics graphics, Insets insets) {
Rectangle r = getPaintRectangle(figure, insets);
- if (getColor() != null)
+ if (getColor() != null) {
graphics.setForegroundColor(getColor());
+ }
graphics.drawLine(r.x, r.y, r.right(), r.y);
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ComponentShape.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -10,16 +10,15 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.veditor.editors.model;
+import java.util.Iterator;
+
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Property;
public class ComponentShape extends ExpandeableShape {
+
public static final String SET_CHILDS_HIDEN = "set childs hiden";
//$NON-NLS-1$
- //protected boolean childsHiden = true;
-
-
-
public ComponentShape(Object ioe) {
super(ioe);
Shape bodyOrmShape;
@@ -27,31 +26,29 @@
Collection collection = (Collection)((Property)ioe).getValue();
bodyOrmShape = new Shape(collection.getKey());
bodyOrmShape.setIndent(20);
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
bodyOrmShape = new Shape(collection.getElement());
bodyOrmShape.setIndent(20);
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
}
}
- protected void setChildsHiden(boolean hiden) {
- for (int i = 0; i < getChildren().size(); i++)
- getChildren().get(i).setHidden(hiden);
+ protected void setChildsHidden(boolean hidden) {
+ Iterator<Shape> it = getChildrenIterator();
+ while (it.hasNext()) {
+ it.next().setHidden(hidden);
+ }
}
public void refreshChildsHiden(OrmDiagram ormDiagram) {
refHide = !refHide;
-
- for (int i = 0; i < getChildren().size(); i++)
- getChildren().get(i).setHidden(!refHide);
-
- if(refHide)
- if(first){
+ setChildsHidden(!refHide);
+ if (refHide) {
+ if (first) {
ormDiagram.refreshComponentReferences(this);
- first=false;
+ first = false;
}
-
-
+ }
firePropertyChange(SET_CHILDS_HIDEN, null, Boolean.valueOf(!refHide));
}
}
\ No newline at end of file
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Connection.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -11,6 +11,7 @@
package org.jboss.tools.hibernate.ui.veditor.editors.model;
public class Connection extends ModelElement {
+
public static final String HIDE_SELECTION = "hide selection"; //$NON-NLS-1$
public static final String SHOW_SELECTION = "show selection"; //$NON-NLS-1$
public static final String SET_HIDEN = "set hiden"; //$NON-NLS-1$
@@ -52,14 +53,16 @@
}
public void setHidden(boolean hiden) {
- if(hiden) {
+ if (hiden) {
needHide--;
- if(needHide == 0)
+ if (needHide == 0) {
return;
+ }
} else {
needHide++;
- if(needHide == 1)
+ if (needHide == 1) {
return;
+ }
}
firePropertyChange(SET_HIDEN, null, Boolean.valueOf(hiden));
}
@@ -67,4 +70,12 @@
public boolean isHiden() {
return needHide != 2;
}
+
+ /**
+ * It has no parent
+ */
+ @Override
+ public ModelElement getParent() {
+ return null;
+ }
}
\ No newline at end of file
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ExpandeableShape.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -15,31 +15,35 @@
public static final String SHOW_REFERENCES = "show references"; //$NON-NLS-1$
public boolean refHide = true;
- protected boolean first=false;
+ protected boolean first = false;
- private OrmShape reference=null;
+ private OrmShape reference = null;
- public void setReference(OrmShape reference){
+ public ExpandeableShape(Object ioe) {
+ super(ioe);
+ }
+
+ public void setReference(OrmShape reference) {
this.reference = reference;
}
- public OrmShape getReference(){
+ public OrmShape getReference() {
return reference;
}
- public boolean isReferenceVisible(){
+ public boolean isReferenceVisible() {
return refHide;
}
-
- public ExpandeableShape(Object ioe) {
- super(ioe);
+
+ protected boolean getHide() {
+ return refHide;
}
public void refreshReferences(Object model) {
refHide = !refHide;
if (model instanceof OrmDiagram) {
- if(refHide){
- if(first){
+ if (refHide) {
+ if (first) {
((OrmDiagram)model).processExpand(this);
first = false;
}
@@ -47,8 +51,4 @@
}
firePropertyChange(SHOW_REFERENCES, null, Boolean.valueOf(refHide));
}
-
- protected boolean getHide() {
- return refHide;
- }
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/ModelElement.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -13,11 +13,15 @@
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
+/**
+ * This is basis model class for diagram items.
+ */
public abstract class ModelElement implements IPropertySource {
/** An empty property descriptor. */
@@ -43,51 +47,74 @@
pcsDelegate.removePropertyChangeListener(l);
}
}
+
+ /**
+ * The result is parent or null if the object has no parent
+ * @return ModelElement
+ */
+ abstract public ModelElement getParent();
- private List<Shape> children = new OList<Shape>();
- private ModelElement parent;
+ /**
+ * The children are items which type is Shape!
+ * In general ModelElement is not a child.
+ */
+ private ArrayList<Shape> children = new ArrayList<Shape>();
- public List<Shape> getChildren(){
- return children;
+ public Iterator<Shape> getChildrenIterator() {
+ return children.iterator();
}
- public ModelElement getParent(){
- return parent;
+ /**
+ * Return copy of children list (to prevent modification of internal array)
+ * @return
+ */
+ public List<Shape> getChildrenList() {
+ ArrayList<Shape> copy = new ArrayList<Shape>();
+ Iterator<Shape> it = getChildrenIterator();
+ while (it.hasNext()) {
+ copy.add(it.next());
+ }
+ return copy;
}
- public void setParent(ModelElement element){
- parent = element;
+ /**
+ * Number of children
+ * @return
+ */
+ public int getChildrenNumber() {
+ return children.size();
}
- public OrmDiagram getOrmDiagram(){
- ModelElement element = this;
- while(true){
- if(element instanceof OrmDiagram) return (OrmDiagram)element;
- if(element.getParent() == null)break;
- element = element.getParent();
- }
- return null;
+ /**
+ * Standard way to add child
+ * @param item
+ * @return
+ */
+ public boolean addChild(Shape item) {
+ item.setParent(this);
+ return children.add(item);
}
- public ExpandeableShape getExtendeableShape(){
- ModelElement element = this;
- while(true){
- if(element instanceof ExpandeableShape) return (ExpandeableShape)element;
- if(element.getParent() == null)break;
- if(element.getParent() instanceof ExpandeableShape) return
(ExpandeableShape)element.getParent();
- element = element.getParent();
- }
- return null;
+ /**
+ * Standard way to remove child
+ * @param item
+ * @return
+ */
+ public boolean removeChild(Shape item) {
+ item.setParent(null);
+ return children.remove(item);
}
- public OrmShape getOrmShape(){
- ModelElement element = this;
- while(true){
- if(element instanceof OrmShape) return (OrmShape)element;
- if(element.getParent() == null)break;
- element = element.getParent();
+ /**
+ * Clear all children
+ */
+ public void deleteChildren() {
+ Iterator<Shape> it = getChildrenIterator();
+ while (it.hasNext()) {
+ Shape me = it.next();
+ me.setParent(null);
}
- return null;
+ children.clear();
}
public Object getEditableValue() {
@@ -128,21 +155,4 @@
public void setPropertyValue(Object id, Object value) {
// do nothing
}
-
- class OList<E> extends ArrayList<E>{
- public OList(){
-
- }
-
- public boolean add(E 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);
- }
- }
-
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmDiagram.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -17,9 +17,10 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Properties;
+import java.util.Set;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -92,6 +93,14 @@
load();
setDirty(false);
}
+
+ /**
+ * It has no parent
+ */
+ @Override
+ public ModelElement getParent() {
+ return null;
+ }
public IPath getStoreFolderPath() {
IPath storePath = null;
@@ -148,7 +157,7 @@
return;
}
saveHelper();
- getChildren().clear();
+ deleteChildren();
elements.clear();
for (int i = 0; i < ormElements.length; i++) {
getOrCreatePersistentClass(ormElements[i], null);
@@ -159,20 +168,22 @@
}
private void expandModel(ModelElement element){
- if(element.getClass().equals(ExpandeableShape.class)){
+ if (element.getClass().equals(ExpandeableShape.class)) {
processExpand((ExpandeableShape)element);
- }else if(element.getClass().equals(ComponentShape.class)){
+ } else if (element.getClass().equals(ComponentShape.class)) {
refreshComponentReferences((ComponentShape)element);
}
- for(int i=0; i <element.getChildren().size(); i++){
- expandModel(element.getChildren().get(i));
+ Iterator<Shape> it = element.getChildrenList().iterator();
+ while (it.hasNext()) {
+ expandModel(it.next());
}
}
private void saveHelper() {
- childrenLocations = new String[getChildren().size()];
- for (int i = 0; i < getChildren().size(); i++) {
- OrmShape shape = (OrmShape) getChildren().get(i);
+ childrenLocations = new String[getChildrenNumber()];
+ Iterator<Shape> it = getChildrenIterator();
+ for (int i = 0; it.hasNext(); i++) {
+ OrmShape shape = (OrmShape)it.next();
Object ormElement = shape.getOrmElement();
if (ormElement instanceof RootClass) {
childrenLocations[i] = ((RootClass)ormElement).getEntityName() + "@";
//$NON-NLS-1$
@@ -190,7 +201,7 @@
ormShape = elements.get(key);
if (null == ormShape) {
ormShape = new OrmShape(ormElement);
- getChildren().add(ormShape);
+ addChild(ormShape);
elements.put(key, ormShape);
}
} else if (ormElement instanceof Table) {
@@ -198,7 +209,7 @@
ormShape = elements.get(key);
if (null == ormShape) {
ormShape = new OrmShape(ormElement);
- getChildren().add(ormShape);
+ addChild(ormShape);
elements.put(key, ormShape);
}
} else if (ormElement instanceof Property) {
@@ -207,7 +218,7 @@
ormShape = elements.get(key);
if (null == ormShape) {
ormShape = new SpecialOrmShape(specialRootClass);
- getChildren().add(ormShape);
+ addChild(ormShape);
elements.put(key, ormShape);
}
} else if (ormElement instanceof Subclass) {
@@ -215,7 +226,7 @@
ormShape = elements.get(key);
if (null == ormShape) {
ormShape = new OrmShape(ormElement);
- getChildren().add(ormShape);
+ addChild(ormShape);
elements.put(key, ormShape);
}
}
@@ -367,39 +378,44 @@
}
@SuppressWarnings("unchecked")
- private void createConnections(ExpandeableShape persistentClass, ExpandeableShape
databaseTable){
- int i = 0;
- boolean check = (persistentClass.getOrmElement() instanceof SpecialRootClass);
- Iterator<Shape> persistentFields = persistentClass.getChildren().iterator();
- List<Shape> databaseColumns = databaseTable.getChildren();
- List<Shape> databaseColumns2 = new ArrayList<Shape>();
- Iterator iterator = null;
- while (persistentFields.hasNext()) {
- Shape shape = persistentFields.next();
+ private void createConnections(ExpandeableShape persistentClass, ExpandeableShape
dbTable){
+ Property parentProperty = null;
+ if (persistentClass.getOrmElement() instanceof SpecialRootClass) {
+ parentProperty =
((SpecialRootClass)persistentClass.getOrmElement()).getParentProperty();
+ }
+ Iterator<Shape> itFields = persistentClass.getChildrenIterator();
+ Set<Shape> processed = new HashSet<Shape>();
+ while (itFields.hasNext()) {
+ final Shape shape = itFields.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)(databaseColumns.get(j)).getOrmElement()).getName()))
{
- Shape databaseShape = databaseColumns.remove(j);
- if(!isConnectionExist(shape, databaseShape)){
- new Connection(shape, databaseShape);
- shape.firePropertyChange(REFRESH, null, null);
- databaseShape.firePropertyChange(REFRESH, null, null);
- }
- databaseColumns2.add(i++, databaseShape);
- }
+ if (!(element instanceof Property && parentProperty != element)) {
+ continue;
+ }
+ Value value = ((Property)element).getValue();
+ Iterator iterator = value.getColumnIterator();
+ while (iterator.hasNext()) {
+ Object o = iterator.next();
+ if (!(o instanceof Column)) {
+ continue;
+ }
+ Column dbColumn = (Column)o;
+ Iterator<Shape> itColumns = dbTable.getChildrenIterator();
+ while (itColumns.hasNext()) {
+ final Shape shapeCol = itColumns.next();
+ if (processed.contains(shapeCol)) {
+ continue;
+ }
+ if (dbColumn.getName().equals(((Column)(shapeCol).getOrmElement()).getName())) {
+ if (!isConnectionExist(shape, shapeCol)) {
+ new Connection(shape, shapeCol);
+ shape.firePropertyChange(REFRESH, null, null);
+ shapeCol.firePropertyChange(REFRESH, null, null);
}
- }
+ processed.add(shapeCol);
+ }
}
}
}
- databaseColumns.addAll(databaseColumns2);
}
private boolean isConnectionExist(Shape source, Shape target){
@@ -422,14 +438,14 @@
}
public void setDirty(boolean dirty) {
- if(this.dirty != dirty) {
+ if (this.dirty != dirty) {
this.dirty = dirty;
firePropertyChange(DIRTY, null, null);
}
}
public void processExpand(ExpandeableShape shape) {
- OrmShape s=null;
+ OrmShape s = null;
Object element = shape.getOrmElement();
if (element instanceof Property) {
Property property = (Property)element;
@@ -442,7 +458,7 @@
if (clazz instanceof RootClass) {
RootClass rootClass = (RootClass)clazz;
s = getOrCreatePersistentClass(rootClass, null);
- if(!isConnectionExist(shape, s)){
+ if (!isConnectionExist(shape, s)) {
new Connection(shape, s);
shape.firePropertyChange(REFRESH, null, null);
s.firePropertyChange(REFRESH, null, null);
@@ -458,8 +474,9 @@
shape.firePropertyChange(REFRESH, null, null);
s.firePropertyChange(REFRESH, null, null);
}
- if(!shape.getParent().equals(s))
+ if(!shape.getParent().equals(s)) {
shape.setReference(s);
+ }
firePropertyChange(REFRESH, null, null);
}
}
@@ -470,96 +487,106 @@
@SuppressWarnings("unchecked")
protected void refreshComponentReferences(ComponentShape componentShape) {
+ Property property = (Property)componentShape.getOrmElement();
+ if (!(property.getValue() instanceof Collection)) {
+ return;
+ }
+ Collection collection = (Collection)property.getValue();
+ Value component = collection.getElement();
+ Shape csChild0 = null, csChild1 = null;
+ Iterator<Shape> tmp = componentShape.getChildrenIterator();
+ if (tmp.hasNext()) {
+ csChild0 = tmp.next();
+ }
+ if (tmp.hasNext()) {
+ csChild1 = tmp.next();
+ }
OrmShape childShape = null;
- Property property = (Property)componentShape.getOrmElement();
-// Type valueType = property.getValue().getType();
- if (property.getValue() instanceof Collection) {
- Collection collection = (Collection)property.getValue();
- Value component = collection.getElement();
- if (component instanceof Component) {// valueType.isComponentType()
- childShape = elements.get(((Component)component).getComponentClassName());
- if(childShape == null) childShape = getOrCreateComponentClass(property);
-
-
- SimpleValue value =
(SimpleValue)(componentShape.getChildren().get(0)).getOrmElement();
- OrmShape tableShape = getOrCreateDatabaseTable(value.getTable());
- Iterator iterator = value.getColumnIterator();
- while (iterator.hasNext()) {
- Object o = iterator.next();
- if (o instanceof Column) {
- Column column = (Column)o;
- Shape colShape = tableShape.getChild(column);
- if(!isConnectionExist(componentShape.getChildren().get(0), colShape)){
- new Connection(componentShape.getChildren().get(0), colShape);
- (componentShape.getChildren().get(0)).firePropertyChange(REFRESH, null, null);
- childShape.firePropertyChange(REFRESH, null, null);
- }
+ if (component instanceof Component) {
+ childShape = elements.get(((Component)component).getComponentClassName());
+ if (childShape == null) {
+ childShape = getOrCreateComponentClass(property);
+ }
+ SimpleValue value = (SimpleValue)csChild0.getOrmElement();
+ OrmShape tableShape = getOrCreateDatabaseTable(value.getTable());
+ Iterator iterator = value.getColumnIterator();
+ while (iterator.hasNext()) {
+ Object o = iterator.next();
+ if (o instanceof Column) {
+ Column column = (Column)o;
+ Shape colShape = tableShape.getChild(column);
+ if (!isConnectionExist(csChild0, colShape)) {
+ new Connection(csChild0, colShape);
+ csChild0.firePropertyChange(REFRESH, null, null);
+ childShape.firePropertyChange(REFRESH, null, null);
}
}
-
- if(!isConnectionExist(componentShape.getChildren().get(1), childShape)){
- new Connection(componentShape.getChildren().get(1), childShape);
- (componentShape.getChildren().get(1)).firePropertyChange(REFRESH, null, null);
- childShape.firePropertyChange(REFRESH, null, null);
- }
-
- } else if (collection.isOneToMany()) {
- childShape = getOrCreateAssociationClass(property);
- if (childShape == null) return;
- if(!isConnectionExist(componentShape.getChildren().get(1), childShape)){
- new Connection(componentShape.getChildren().get(1), childShape);
- (componentShape.getChildren().get(1)).firePropertyChange(REFRESH, null, null);
- childShape.firePropertyChange(REFRESH, null, null);
- }
- OrmShape keyTableShape = getOrCreateDatabaseTable(collection.getKey().getTable());
- Iterator iter = collection.getKey().getColumnIterator();
- while (iter.hasNext()) {
- Object o = iter.next();
- if (o instanceof Column) {
- Column col = (Column)o;
- Shape keyColumnShape = keyTableShape.getChild(col);
- if (keyColumnShape != null &&
!isConnectionExist(componentShape.getChildren().get(0), keyColumnShape)){
- new Connection(componentShape.getChildren().get(0), keyColumnShape);
- (componentShape.getChildren().get(0)).firePropertyChange(REFRESH, null, null);
- keyColumnShape.firePropertyChange(REFRESH, null, null);
- }
+ }
+ if (!isConnectionExist(csChild1, childShape)) {
+ new Connection(csChild1, childShape);
+ csChild1.firePropertyChange(REFRESH, null, null);
+ childShape.firePropertyChange(REFRESH, null, null);
+ }
+
+ } else if (collection.isOneToMany()) {
+ childShape = getOrCreateAssociationClass(property);
+ if (childShape == null) {
+ return;
+ }
+ if (!isConnectionExist(csChild1, childShape)) {
+ new Connection(csChild1, childShape);
+ csChild1.firePropertyChange(REFRESH, null, null);
+ childShape.firePropertyChange(REFRESH, null, null);
+ }
+ OrmShape keyTableShape = getOrCreateDatabaseTable(collection.getKey().getTable());
+ Iterator iter = collection.getKey().getColumnIterator();
+ while (iter.hasNext()) {
+ Object o = iter.next();
+ if (o instanceof Column) {
+ Column col = (Column)o;
+ Shape keyColumnShape = keyTableShape.getChild(col);
+ if (keyColumnShape != null && !isConnectionExist(csChild0, keyColumnShape))
{
+ new Connection(csChild0, keyColumnShape);
+ csChild0.firePropertyChange(REFRESH, null, null);
+ keyColumnShape.firePropertyChange(REFRESH, null, null);
}
}
-
- } else /* if (collection.isMap() || collection.isSet()) */ {
- childShape = getOrCreateDatabaseTable(collection.getCollectionTable());
- Iterator columnIterator =
((DependantValue)componentShape.getChildren().get(0).getOrmElement()).getColumnIterator();
- while (columnIterator.hasNext()) {
- Object o = columnIterator.next();
- if (o instanceof Column) {
- Shape keyShape = childShape.getChild((Column)o);
- if(!isConnectionExist(componentShape.getChildren().get(0), keyShape)){
- new Connection(componentShape.getChildren().get(0), keyShape);
- (componentShape.getChildren().get(0)).firePropertyChange(REFRESH, null, null);
- keyShape.firePropertyChange(REFRESH, null, null);
- }
+ }
+
+ } else /* if (collection.isMap() || collection.isSet()) */ {
+ childShape = getOrCreateDatabaseTable(collection.getCollectionTable());
+ Iterator columnIterator =
((DependantValue)csChild0.getOrmElement()).getColumnIterator();
+ while (columnIterator.hasNext()) {
+ Object o = columnIterator.next();
+ if (o instanceof Column) {
+ Shape keyShape = childShape.getChild((Column)o);
+ if (!isConnectionExist(csChild0, keyShape)) {
+ new Connection(csChild0, keyShape);
+ csChild0.firePropertyChange(REFRESH, null, null);
+ keyShape.firePropertyChange(REFRESH, null, null);
}
}
+ }
- Iterator iter =
((SimpleValue)(componentShape.getChildren().get(1)).getOrmElement()).getColumnIterator();
- while (iter.hasNext()) {
- Object element = iter.next();
- if (element instanceof Column) {
- Column col = (Column)element;
- Shape elementShape = childShape.getChild(col);
- if(!isConnectionExist(componentShape.getChildren().get(1), elementShape)){
- new Connection(componentShape.getChildren().get(1), elementShape);
- (componentShape.getChildren().get(1)).firePropertyChange(REFRESH, null, null);
- elementShape.firePropertyChange(REFRESH, null, null);
- }
+ Iterator iter = ((SimpleValue)csChild1.getOrmElement()).getColumnIterator();
+ while (iter.hasNext()) {
+ Object element = iter.next();
+ if (element instanceof Column) {
+ Column col = (Column)element;
+ Shape elementShape = childShape.getChild(col);
+ if (!isConnectionExist(csChild1, elementShape)){
+ new Connection(csChild1, elementShape);
+ csChild1.firePropertyChange(REFRESH, null, null);
+ elementShape.firePropertyChange(REFRESH, null, null);
}
}
}
- if(!componentShape.getParent().equals(childShape))
- componentShape.setReference(childShape);
- setDirty(true);
- firePropertyChange(REFRESH, null, null);
}
+ if (!componentShape.getParent().equals(childShape)) {
+ componentShape.setReference(childShape);
+ }
+ setDirty(true);
+ firePropertyChange(REFRESH, null, null);
}
public OrmShape getOrCreateComponentClass(Property property) {
@@ -572,7 +599,7 @@
OrmShape tableShape =
elements.get(HibernateUtils.getTableName(component.getTable()));
if (tableShape == null) tableShape =
getOrCreateDatabaseTable(component.getTable());
createConnections(classShape, tableShape);
- if(!isConnectionExist(classShape, tableShape)){
+ if (!isConnectionExist(classShape, tableShape)) {
new Connection(classShape, tableShape);
classShape.firePropertyChange(REFRESH, null, null);
tableShape.firePropertyChange(REFRESH, null, null);
@@ -580,7 +607,7 @@
Shape parentShape = ((SpecialOrmShape)classShape).getParentShape();
if (parentShape != null) {
OrmShape parentClassShape =
elements.get(HibernateUtils.getPersistentClassName(((Property)parentShape.getOrmElement()).getPersistentClass().getEntityName()));
- if(!isConnectionExist(parentShape, parentClassShape)){
+ if (!isConnectionExist(parentShape, parentClassShape)) {
new Connection(parentShape, parentClassShape);
parentShape.firePropertyChange(REFRESH, null, null);
parentClassShape.firePropertyChange(REFRESH, null, null);
@@ -636,37 +663,41 @@
public void propertiesInit(Properties properties, ModelElement shape){
boolean state;
-
- if(shape instanceof OrmShape){
- state = getState(properties, (Shape)shape);
- if(state)
- ((OrmShape)shape).refreshHiden();
- ((OrmShape)shape).setLocation(getPosition(properties, (OrmShape)shape));
- }else if(shape instanceof ExpandeableShape){
- state = getState(properties, (Shape)shape);
- if(!state)
- ((ExpandeableShape)shape).refHide = false;
+ if (shape instanceof OrmShape) {
+ final OrmShape ormShape = (OrmShape)shape;
+ state = getState(properties, ormShape);
+ if (state) {
+ ormShape.refreshHiden();
+ }
+ ormShape.setLocation(getPosition(properties, ormShape));
+ } else if (shape instanceof ExpandeableShape) {
+ final ExpandeableShape expandeableShape = (ExpandeableShape)shape;
+ state = getState(properties, expandeableShape);
+ if (!state) {
+ expandeableShape.refHide = false;
+ }
}
-
- for(int i=0;i<shape.getChildren().size();i++){
- propertiesInit(properties, shape.getChildren().get(i));
+ Iterator<Shape> it = shape.getChildrenIterator();
+ while (it.hasNext()) {
+ propertiesInit(properties, it.next());
}
}
-
-
-
- private void storeProperties(Properties properties, ModelElement shape){
+
+ private void storeProperties(Properties properties, ModelElement shape) {
boolean state;
- if(shape instanceof OrmShape){
- state = ((OrmShape)shape).hiden;
- setState(properties, (Shape)shape, state);
+ if (shape instanceof OrmShape) {
+ final OrmShape ormShape = (OrmShape)shape;
+ state = ormShape.hiden;
+ setState(properties, ormShape, state);
setPosition(properties, (OrmShape)shape);
- }else if(shape instanceof ExpandeableShape){
- state = ((ExpandeableShape)shape).refHide;
- setState(properties, (Shape)shape, state);
+ } else if (shape instanceof ExpandeableShape) {
+ final ExpandeableShape expandeableShape = (ExpandeableShape)shape;
+ state = expandeableShape.refHide;
+ setState(properties, expandeableShape, state);
}
- for(int i=0;i<shape.getChildren().size();i++){
- storeProperties(properties, shape.getChildren().get(i));
+ Iterator<Shape> it = shape.getChildrenIterator();
+ while (it.hasNext()) {
+ storeProperties(properties, it.next());
}
}
@@ -676,11 +707,11 @@
FileOutputStream fos = null;
try {
File folder = new File(getStoreFolderPath().toOSString());
- if(!folder.exists()) {
+ if (!folder.exists()) {
folder.mkdirs();
}
File file = new File(getStoreFilePath().toOSString());
- if(!file.exists()) {
+ if (!file.exists()) {
file.createNewFile();
}
fos = new FileOutputStream(file);
@@ -702,7 +733,7 @@
IFile file = null;
IPath path = getStoreFolderPath();
IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
- if(!folder.exists()) {
+ if (!folder.exists()) {
try {
folder.create(true, true, null);
@@ -722,18 +753,18 @@
public void load(){
Properties properties = new Properties();
FileInputStream fis = null;
- try{
+ try {
File file = new File(getStoreFilePath().toOSString());
- if(file.exists()){
+ if (file.exists()) {
fis = new FileInputStream(file);
properties.load(fis);
propertiesInit(properties, this);
loadSuccessfull = true;
}
- }catch(IOException ex){
+ } catch (IOException ex) {
VisualEditorPlugin.getDefault().logError("Can't load layout of
mapping.", ex); //$NON-NLS-1$
} finally {
- if(fis!=null) {
+ if (fis != null) {
try {
fis.close();
} catch (IOException e) {
@@ -743,52 +774,53 @@
}
}
- public boolean isLoadSuccessfull(){
+ public boolean isLoadSuccessfull() {
return loadSuccessfull;
}
- private void setState(Properties properties,String key, boolean value){
- if(properties.containsKey(key)){
+ private void setState(Properties properties,String key, boolean value) {
+ if (properties.containsKey(key)) {
properties.remove(key);
properties.put(key, Boolean.valueOf(value).toString());
- }else{
+ } else {
properties.put(key, Boolean.valueOf(value).toString());
}
}
- public void setState(Properties properties,Shape shape, boolean value){
+ public void setState(Properties properties,Shape shape, boolean value) {
setState(properties, getKey(shape)+".state", value); //$NON-NLS-1$
}
- private boolean getState(Properties properties, String key){
+ private boolean getState(Properties properties, String key) {
String str = properties.getProperty(key, "true"); //$NON-NLS-1$
-
return Boolean.valueOf(str).booleanValue();
}
- private Point getPoint(Properties properties, String key){
- Point point = new Point(0,0);
- String str = properties.getProperty(key+".x","0"); //$NON-NLS-1$
//$NON-NLS-2$
+ private Point getPoint(Properties properties, String key) {
+ Point point = new Point(0, 0);
+ String str = properties.getProperty(key+".x", "0"); //$NON-NLS-1$
//$NON-NLS-2$
point.x = Integer.parseInt(str);
- String str2 = properties.getProperty(key+".y","0"); //$NON-NLS-1$
//$NON-NLS-2$
+ String str2 = properties.getProperty(key+".y", "0"); //$NON-NLS-1$
//$NON-NLS-2$
point.y = Integer.parseInt(str2);
return point;
}
- private void setPoint(Properties properties, String key, Point point){
+ private void setPoint(Properties properties, String key, Point point) {
String key1 = key+".x"; //$NON-NLS-1$
- if(!properties.containsKey(key1)){
+ if (!properties.containsKey(key1)) {
properties.remove(key1);
- properties.put(key1, ""+point.x); //$NON-NLS-1$
- }else
- properties.put(key1, ""+point.x); //$NON-NLS-1$
- String key2 = key+".y"; //$NON-NLS-1$
- if(!properties.containsKey(key2)){
+ properties.put(key1, "" + point.x); //$NON-NLS-1$
+ } else {
+ properties.put(key1, "" + point.x); //$NON-NLS-1$
+ }
+ String key2 = key + ".y"; //$NON-NLS-1$
+ if (!properties.containsKey(key2)) {
properties.remove(key2);
- properties.put(key2, ""+point.y); //$NON-NLS-1$
- }else
- properties.put(key2, ""+point.y); //$NON-NLS-1$
+ properties.put(key2, "" + point.y); //$NON-NLS-1$
+ } else {
+ properties.put(key2, "" + point.y); //$NON-NLS-1$
+ }
}
public void setPosition(Properties properties, OrmShape shape){
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/OrmShape.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -43,7 +43,7 @@
RootClass rootClass = (RootClass)getOrmElement();
Property identifierProperty = rootClass.getIdentifierProperty();
if (identifierProperty != null) {
- getChildren().add(new Shape(identifierProperty));
+ addChild(new Shape(identifierProperty));
}
KeyValue identifier = rootClass.getIdentifier();
@@ -53,7 +53,7 @@
Iterator<Property> iterator = ((Component)identifier).getPropertyIterator();
while (iterator.hasNext()) {
Property property = iterator.next();
- getChildren().add(new Shape(property));
+ addChild(new Shape(property));
}
}
}
@@ -80,10 +80,10 @@
} else {
bodyOrmShape = new Shape(field);
}
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
} else {
bodyOrmShape = new ExpandeableShape(field);
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
}
}
}
@@ -92,7 +92,7 @@
Property identifierProperty = rootClass.getIdentifierProperty();
if (identifierProperty != null) {
- getChildren().add(new Shape(identifierProperty));
+ addChild(new Shape(identifierProperty));
}
KeyValue identifier = rootClass.getIdentifier();
@@ -100,7 +100,7 @@
Iterator<Property> iterator = ((Component)identifier).getPropertyIterator();
while (iterator.hasNext()) {
Property property = iterator.next();
- getChildren().add(new Shape(property));
+ addChild(new Shape(property));
}
}
@@ -129,10 +129,10 @@
} else {
bodyOrmShape = new Shape(field);
}
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
} else {
bodyOrmShape = new ExpandeableShape(field);
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
}
}
}
@@ -161,7 +161,7 @@
} else {
bodyOrmShape = new ExpandeableShape(property);
}
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
}
}
} else if (ormElement instanceof Table) {
@@ -169,13 +169,18 @@
while (iterator.hasNext()) {
Column column = (Column)iterator.next();
bodyOrmShape = new Shape(column);
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
}
}
}
public Shape getChild(Column ormElement) {
- for (Shape child : getChildren()) {
+ if (ormElement == null) {
+ return null;
+ }
+ Iterator<Shape> it = getChildrenIterator();
+ while (it.hasNext()) {
+ final Shape child = it.next();
Object childElement = child.getOrmElement();
if (childElement instanceof Column &&
ormElement.getName().equals(((Column)childElement).getName())) {
return child;
@@ -185,12 +190,15 @@
}
public Shape getChild(Property ormElement) {
- if (ormElement != null) {
- for (Shape child : getChildren()) {
- Object childElement = child.getOrmElement();
- if (childElement instanceof Property &&
ormElement.getName().equals(((Property)childElement).getName())) {
- return child;
- }
+ if (ormElement == null) {
+ return null;
+ }
+ Iterator<Shape> it = getChildrenIterator();
+ while (it.hasNext()) {
+ final Shape child = it.next();
+ Object childElement = child.getOrmElement();
+ if (childElement instanceof Property &&
ormElement.getName().equals(((Property)childElement).getName())) {
+ return child;
}
}
return null;
@@ -198,7 +206,9 @@
protected void setHidden(boolean hiden) {
super.setHidden(hiden);
- for (Shape child : getChildren()) {
+ Iterator<Shape> it = getChildrenIterator();
+ while (it.hasNext()) {
+ final Shape child = it.next();
child.setHidden(hiden);
}
}
@@ -213,8 +223,10 @@
firePropertyChange(SET_HIDEN, null, Boolean.valueOf(hiden));
}
- private void setElementHidden(ModelElement element, boolean hidden){
- for (Shape child : element.getChildren()) {
+ private void setElementHidden(ModelElement element, boolean hidden) {
+ Iterator<Shape> it = getChildrenIterator();
+ while (it.hasNext()) {
+ final Shape child = it.next();
child.setHidden(hidden);
setElementHidden(child, hidden);
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/Shape.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -94,6 +94,55 @@
ormElement = ioe;
}
+ private ModelElement parent;
+
+ public ModelElement getParent() {
+ return parent;
+ }
+
+ public void setParent(ModelElement element) {
+ parent = element;
+ }
+
+ public OrmDiagram getOrmDiagram() {
+ OrmDiagram res = null;
+ ModelElement el = this;
+ while (el != null) {
+ if (el instanceof OrmDiagram) {
+ res = (OrmDiagram)el;
+ break;
+ }
+ el = el.getParent();
+ }
+ return res;
+ }
+
+ public ExpandeableShape getExtendeableShape() {
+ ExpandeableShape res = null;
+ ModelElement el = this;
+ while (el != null) {
+ if (el instanceof ExpandeableShape) {
+ res = (ExpandeableShape)el;
+ break;
+ }
+ el = el.getParent();
+ }
+ return res;
+ }
+
+ public OrmShape getOrmShape() {
+ OrmShape res = null;
+ ModelElement el = this;
+ while (el != null) {
+ if (el instanceof OrmShape) {
+ res = (OrmShape)el;
+ break;
+ }
+ el = el.getParent();
+ }
+ return res;
+ }
+
public void addConnection(Connection conn) {
if (conn == null || conn.getSource() == conn.getTarget()) {
throw new IllegalArgumentException();
@@ -103,9 +152,8 @@
} else if (conn.getTarget() == this) {
targetConnections.add(conn);
}
- }
+ }
-
public List<Connection> getSourceConnections() {
return sourceConnections;
}
@@ -139,10 +187,12 @@
}
protected void setHidden(boolean hiden) {
- for (int i = 0; i < sourceConnections.size(); i++)
+ for (int i = 0; i < sourceConnections.size(); i++) {
sourceConnections.get(i).setHidden(hiden);
- for (int i = 0; i < targetConnections.size(); i++)
+ }
+ for (int i = 0; i < targetConnections.size(); i++) {
targetConnections.get(i).setHidden(hiden);
+ }
}
/**
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialOrmShape.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -31,12 +31,14 @@
Shape bodyOrmShape;
RootClass rootClass = (RootClass)getOrmElement();
Property identifierProperty = rootClass.getIdentifierProperty();
- if (identifierProperty != null) getChildren().add(new Shape(identifierProperty));
+ if (identifierProperty != null) {
+ addChild(new Shape(identifierProperty));
+ }
SpecialRootClass src = (SpecialRootClass)getOrmElement();
if (src.getParentProperty() != null) {
bodyOrmShape = new Shape(src.getParentProperty());
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
parentShape = bodyOrmShape;
}
@@ -67,7 +69,7 @@
} else {
bodyOrmShape = new Shape(field);
}
- getChildren().add(bodyOrmShape);
+ addChild(bodyOrmShape);
} catch (Exception e) {
VisualEditorPlugin.getDefault().logError(e);
}
Modified:
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 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/model/SpecialRootClass.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -13,7 +13,6 @@
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;
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ComponentShapeEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -11,7 +11,6 @@
package org.jboss.tools.hibernate.ui.veditor.editors.parts;
import java.beans.PropertyChangeEvent;
-import java.util.List;
import org.eclipse.draw2d.FocusBorder;
import org.eclipse.draw2d.IFigure;
@@ -24,14 +23,12 @@
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
-import org.eclipse.swt.graphics.RGB;
import org.jboss.tools.hibernate.ui.veditor.editors.figures.ComponentFigure;
import org.jboss.tools.hibernate.ui.veditor.editors.figures.TitleLabel;
import org.jboss.tools.hibernate.ui.veditor.editors.model.ComponentShape;
import org.jboss.tools.hibernate.ui.veditor.editors.model.ExpandeableShape;
import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
-import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
public class ComponentShapeEditPart extends ExpandeableShapeEditPart {
@@ -77,15 +74,15 @@
int i = figure.getPreferredSize().width;
((ComponentFigure)figure).setChildsHiden(((Boolean)evt.getNewValue()).booleanValue());
- if(((Boolean)evt.getNewValue()).booleanValue())
+ if(((Boolean)evt.getNewValue()).booleanValue()) {
figure.setSize(i,-1);
- else
+ } else {
figure.setSize(-1,-1);
+ }
referenceList.add((OrmShape)getCastedModel().getParent());
refreshReferences((ExpandeableShape)getCastedModel(),
((ExpandeableShape)getCastedModel()).isReferenceVisible());
-
((OrmShape)getParent().getModel()).refreshReference();
} else {
super.propertyChange(evt);
@@ -97,6 +94,8 @@
if (getModel() instanceof ComponentShape) {
bounds = new Rectangle(new Point(0,0), getFigure().getSize());
}
- if (bounds != null) ((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), bounds);
+ if (bounds != null) {
+ ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), bounds);
+ }
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ConnectionEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ConnectionEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ConnectionEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -27,7 +27,6 @@
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.RootClass;
-import org.hibernate.mapping.SingleTableSubclass;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.Table;
import org.jboss.tools.hibernate.ui.veditor.editors.figures.RoundPolylineConnection;
@@ -68,12 +67,13 @@
public void propertyChange(PropertyChangeEvent event) {
String property = event.getPropertyName();
- if (Connection.SHOW_SELECTION.equals(property))
- getFigure().setForegroundColor(getSelectionColor());
- else if (Connection.HIDE_SELECTION.equals(property))
+ if (Connection.SHOW_SELECTION.equals(property)) {
+ getFigure().setForegroundColor(getSelectionColor());
+ } else if (Connection.HIDE_SELECTION.equals(property)) {
getFigure().setForegroundColor(getColor());
- else if (Connection.SET_HIDEN.equals(property))
- getFigure().setVisible(!((Boolean)event.getNewValue()).booleanValue());
+ } else if (Connection.SET_HIDEN.equals(property)) {
+ getFigure().setVisible(!((Boolean)event.getNewValue()).booleanValue());
+ }
}
private Connection getCastedModel() {
@@ -82,24 +82,26 @@
private Color getColor() {
Object element = getCastedModel().getTarget().getOrmElement();
- if (element instanceof RootClass || element instanceof Subclass)
+ if (element instanceof RootClass || element instanceof Subclass) {
return ResourceManager.getInstance().getColor(new RGB(210,155,100));
- else if (element instanceof Column || element instanceof Table || element instanceof
Property)
+ } else if (element instanceof Column || element instanceof Table || element instanceof
Property) {
return ResourceManager.getInstance().getColor(new RGB(160, 160, 160));
- else
+ } else {
throw new IllegalArgumentException();
+ }
}
private Color getSelectionColor() {
if (getCastedModel().getTarget().getOrmElement() instanceof RootClass ||
- getCastedModel().getTarget().getOrmElement() instanceof Subclass)
+ getCastedModel().getTarget().getOrmElement() instanceof Subclass) {
return ResourceManager.getInstance().getColor(new RGB(112,161,99));
- else if (getCastedModel().getTarget().getOrmElement() instanceof Column ||
+ } else if (getCastedModel().getTarget().getOrmElement() instanceof Column ||
getCastedModel().getTarget().getOrmElement() instanceof Table ||
- getCastedModel().getTarget().getOrmElement() instanceof Component)
+ getCastedModel().getTarget().getOrmElement() instanceof Component) {
return ResourceManager.getInstance().getColor(new RGB(66,173,247));
- else
+ } else {
throw new IllegalArgumentException();
+ }
}
private class ShapesSelectionEditPolicy extends SelectionEditPolicy {
@@ -133,8 +135,6 @@
public void selectedStateChanged(EditPart editpart) {
if (this.getSelected() == EditPart.SELECTED_PRIMARY) {
((GEFRootEditPart) getParent()).setToFront(this);
-
}
-
}
}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -60,8 +60,7 @@
class DiagramEditPart extends OrmEditPart implements PropertyChangeListener {
protected void createEditPolicies() {
- installEditPolicy(EditPolicy.LAYOUT_ROLE,
- new ShapesXYLayoutEditPolicy());
+ installEditPolicy(EditPolicy.LAYOUT_ROLE, new ShapesXYLayoutEditPolicy());
}
protected IFigure createFigure() {
@@ -81,15 +80,16 @@
refresh();
autolayout();
// restore();
- } else if (OrmDiagram.DIRTY.equals(prop))
+ } else if (OrmDiagram.DIRTY.equals(prop)) {
((VisualEditor) ((DefaultEditDomain) getViewer().getEditDomain())
.getEditorPart()).refreshDirty();
+ }
}
public void restore() {
- boolean dirty = getCastedModel().isDirty();
- HashMap<String, OrmShape> hashMap = getCastedModel().getCloneElements();
- String childrenLocations[] = getCastedModel().getChildrenLocations();
+ boolean dirty = getOrmDiagram().isDirty();
+ HashMap<String, OrmShape> hashMap = getOrmDiagram().getCloneElements();
+ String childrenLocations[] = getOrmDiagram().getChildrenLocations();
int tempPoint = 1;
OrmShape ormShape;
int point = 1;
@@ -105,24 +105,28 @@
string = childrenLocations[i]
.substring(childrenLocations[i].indexOf('@') + 1);
xy = string.split(";"); //$NON-NLS-1$
- if (xy.length > 1)
+ if (xy.length > 1) {
try {
ormShape.setLocation(new Point(Integer
.parseInt(xy[0]), Integer.parseInt(xy[1])));
} catch (NumberFormatException e) {
VisualEditorPlugin.getDefault().logError(e);
}
- if (xy.length > 2)
- if ((Boolean.valueOf(xy[2])))
+ }
+ if (xy.length > 2) {
+ if ((Boolean.valueOf(xy[2]))) {
ormShape.refreshHiden();
+ }
+ }
tempPoint = ormShape.getLocation().y
+ getChildrenFigurePreferredHeight(ormShape) + 20;
- if (tempPoint > point)
+ if (tempPoint > point) {
point = tempPoint;
+ }
}
}
}
- RootClass[] ormElements = getCastedModel().getOrmElements();
+ RootClass[] ormElements = getOrmDiagram().getOrmElements();
for (int i = 0; i < childrenLocations.length; i++) {
RootClass persistentClass = ormElements[i];
ormShape = hashMap.remove(persistentClass.getEntityName());
@@ -136,9 +140,9 @@
ormShape.setLocation(new Point(pointX, 20));
point = 40 + getChildrenFigurePreferredHeight(ormShape);
}
- if (tempPoint > point)
+ if (tempPoint > point) {
point = tempPoint;
-
+ }
}
Object objects[] = hashMap.keySet().toArray();
for (int i = 0; i < objects.length; i++) {
@@ -161,8 +165,9 @@
// point = point + getChildrenFigurePreferredHeight(ormShape) +
// 20;
// }
- if (tempPoint > point)
+ if (tempPoint > point) {
point = tempPoint;
+ }
}
}
for (OrmShape shape : hashMap.values()) {
@@ -171,10 +176,10 @@
point = point + getChildrenFigurePreferredHeight(shape) + 20;
}
}
- getCastedModel().setDirty(dirty);
+ getOrmDiagram().setDirty(dirty);
}
- private OrmDiagram getCastedModel() {
+ private OrmDiagram getOrmDiagram() {
return (OrmDiagram) getModel();
}
@@ -182,8 +187,9 @@
GraphicalEditPart part;
for (int i = 0; i < getChildren().size(); i++) {
part = (GraphicalEditPart) getChildren().get(i);
- if (ormShape.equals(part.getModel()))
+ if (ormShape.equals(part.getModel())) {
return part.getFigure().getPreferredSize().height;
+ }
}
return 0;
}
@@ -193,30 +199,41 @@
IFigure figure;
for (int i = 0; i < getFigure().getChildren().size(); i++) {
figure = (IFigure) getFigure().getChildren().get(i);
- if (figure.getPreferredSize().width > j)
+ if (figure.getPreferredSize().width > j) {
j = figure.getPreferredSize().width;
+ }
}
return j + 120;
}
+ /**
+ * Returns a <code>List</code> containing the children model objects.
+ * @return the List of children
+ */
+ @Override
protected List<Shape> getModelChildren() {
- return getCastedModel().getChildren();
+ List<Shape> res = new ArrayList<Shape>();
+ Iterator<Shape> it = getOrmDiagram().getChildrenIterator();
+ while (it.hasNext()) {
+ res.add(it.next());
+ }
+ return res;
}
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
- if(!getCastedModel().isLoadSuccessfull()){
+ if (!getOrmDiagram().isLoadSuccessfull()) {
autolayout();
- getCastedModel().setDirty(false);
+ getOrmDiagram().setDirty(false);
}
// restore();
}
}
public void autolayout() {
- IDiagramInfo process = new DiagramInfo(getCastedModel());
+ IDiagramInfo process = new DiagramInfo(getOrmDiagram());
AutoLayout layout = new AutoLayout();
layout.setGridStep("" + 5); //$NON-NLS-1$
layout.setOverride(true);
@@ -225,10 +242,12 @@
public void setToFront(EditPart ep) {
int index = getChildren().indexOf(ep);
- if (index == -1)
+ if (index == -1) {
return;
- if (index != getChildren().size() - 1)
+ }
+ if (index != getChildren().size() - 1) {
reorderChild(ep, getChildren().size() - 1);
+ }
}
public void deactivate() {
@@ -284,12 +303,12 @@
this.diagram = diagram;
OrmShapeEditPart part;
- for (int i = 0; i < diagram.getChildren().size(); i++) {
- part = (OrmShapeEditPart) getViewer().getEditPartRegistry()
- .get(diagram.getChildren().get(i));
+ Iterator<Shape> it = diagram.getChildrenIterator();
+ while (it.hasNext()) {
+ Shape child = it.next();
+ part = (OrmShapeEditPart) getViewer().getEditPartRegistry().get(child);
if (part != null && part.getFigure().isVisible()) {
- item = new DiagramElementInfo((OrmShape) diagram
- .getChildren().get(i));
+ item = new DiagramElementInfo((OrmShape)child);
addItem(item);
}
}
@@ -327,9 +346,9 @@
link = new LinkInfo(connection);
addLink(link);
}
- Shape child;
- for (int j = 0; j < element.getChildren().size(); j++) {
- child = element.getChildren().get(j);
+ Iterator<Shape> it = element.getChildrenIterator();
+ while (it.hasNext()) {
+ Shape child = it.next();
if (child.getSourceConnections().size() == 0) {
link = new LinkInfo(getID());
addLink(link);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramTreeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramTreeEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/DiagramTreeEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -2,10 +2,13 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.swt.widgets.Tree;
import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
+import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
public class DiagramTreeEditPart extends org.eclipse.gef.editparts.AbstractTreeEditPart
implements PropertyChangeListener
@@ -30,13 +33,17 @@
}
/**
- * Returns <code>null</code> as a Tree EditPart holds
- * no children under it.
- *
+ * Returns <code>null</code> as a Tree EditPart holds no children under it.
* @return <code>null</code>
*/
- protected List getModelChildren() {
- return getOrmDiagram().getChildren();
+ @Override
+ protected List<Shape> getModelChildren() {
+ List<Shape> res = new ArrayList<Shape>();
+ Iterator<Shape> it = getOrmDiagram().getChildrenIterator();
+ while (it.hasNext()) {
+ res.add(it.next());
+ }
+ return res;
}
public void propertyChange(PropertyChangeEvent change){
@@ -46,9 +53,10 @@
/**
* Refreshes the visual properties of the TreeItem for this part.
*/
- protected void refreshVisuals(){
- if (getWidget() instanceof Tree)
+ protected void refreshVisuals() {
+ if (getWidget() instanceof Tree) {
return;
+ }
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -12,25 +12,21 @@
import java.beans.PropertyChangeEvent;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
-import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.RequestConstants;
import org.eclipse.swt.graphics.RGB;
import org.hibernate.mapping.RootClass;
import org.hibernate.mapping.Table;
-import org.jboss.tools.hibernate.ui.veditor.editors.figures.ComponentFigure;
import org.jboss.tools.hibernate.ui.veditor.editors.figures.TitleLabel;
import org.jboss.tools.hibernate.ui.veditor.editors.figures.TopLineBorder;
-import org.jboss.tools.hibernate.ui.veditor.editors.model.ComponentShape;
import org.jboss.tools.hibernate.ui.veditor.editors.model.Connection;
import org.jboss.tools.hibernate.ui.veditor.editors.model.ExpandeableShape;
-import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmDiagram;
import org.jboss.tools.hibernate.ui.veditor.editors.model.OrmShape;
import org.jboss.tools.hibernate.ui.veditor.editors.model.Shape;
@@ -74,7 +70,7 @@
if(getFigure().getChildren().size() > 0){
((IFigure)getFigure().getChildren().get(0)).setBackgroundColor(getSelectionColor());
((IFigure)getFigure().getChildren().get(0)).setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(255,255,255)));
- }else{
+ } else {
getFigure().setBackgroundColor(getSelectionColor());
getFigure().setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(255,255,255)));
}
@@ -82,11 +78,11 @@
if(getFigure().getChildren().size() > 0){
((IFigure)getFigure().getChildren().get(0)).setBackgroundColor(getColor());
((IFigure)getFigure().getChildren().get(0)).setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(0,0,0)));
- }else{
+ } else {
getFigure().setBackgroundColor(getColor());
getFigure().setForegroundColor(ResourceManager.getInstance().getColor(new
RGB(0,0,0)));
}
- }else if (ExpandeableShape.SHOW_REFERENCES.equals(prop)) {
+ } else if (ExpandeableShape.SHOW_REFERENCES.equals(prop)) {
refreshReferences(getCastedModel(),
((ExpandeableShape)getCastedModel()).isReferenceVisible());
((TitleLabel)getFigure()).setHidden(!((ExpandeableShape)getCastedModel()).isReferenceVisible());
} else {
@@ -98,53 +94,61 @@
protected void refreshReference(ExpandeableShape shape, boolean visible){
OrmShape refShape = shape.getReference();
- if(refShape == null) return;
- if(!isReferencesCorrect(refShape)) return;
+ if (refShape == null) {
+ return;
+ }
+ if (!isReferencesCorrect(refShape)) {
+ return;
+ }
OrmEditPart refPart = (OrmEditPart)getViewer().getEditPartRegistry().get(refShape);
- if(refPart != null){
+ if (refPart != null) {
refPart.getFigure().setVisible(visible);
setLinksVisible(refPart, visible);
}
Object element = refShape.getOrmElement();
- if(element instanceof RootClass){
+ if (element instanceof RootClass) {
RootClass rc = (RootClass)element;
Table table = rc.getTable();
OrmShape tableShape = refShape.getOrmDiagram().getShape(table);
OrmEditPart tablePart =
(OrmEditPart)getViewer().getEditPartRegistry().get(tableShape);
- if(tablePart != null){
+ if (tablePart != null) {
if(isTableCanBeInvisible(tablePart, visible)){
tablePart.getFigure().setVisible(visible);
setLinksVisible(tablePart, visible);
}
}
}
-
referenceList.add(refShape);
- for(int i=0;i<refShape.getChildren().size();i++){
- if(refShape.getChildren().get(i) instanceof ExpandeableShape){
- refreshReference((ExpandeableShape)refShape.getChildren().get(i), visible);
+ Iterator<Shape> it = refShape.getChildrenIterator();
+ while (it.hasNext()) {
+ final Shape tmp = it.next();
+ if (tmp instanceof ExpandeableShape) {
+ refreshReference((ExpandeableShape)tmp, visible);
}
}
referenceList.remove(refShape);
shape.getOrmDiagram().update();
}
- protected void refreshReferences(Shape shape, boolean visible){
+ protected void refreshReferences(Shape shape, boolean visible) {
Connection link;
OrmShape refShape;
OrmEditPart shapePart = (OrmEditPart)getViewer().getEditPartRegistry().get(shape);
- for(int i=0;i<shape.getSourceConnections().size();i++){
+ for (int i = 0; i < shape.getSourceConnections().size(); i++ ) {
link = shape.getSourceConnections().get(i);
refShape = link.getTarget().getOrmShape();
- if(refShape == null) continue;
- if(!isReferencesCorrect(refShape)) continue;
-
+ if (refShape == null) {
+ continue;
+ }
+ if (!isReferencesCorrect(refShape)) {
+ continue;
+ }
OrmEditPart refPart = (OrmEditPart)getViewer().getEditPartRegistry().get(refShape);
- if(refPart != null){
- if(isShapeCanBeInvisible(shapePart, refPart, visible)){
+ if (refPart != null) {
+ if (isShapeCanBeInvisible(shapePart, refPart, visible)) {
refPart.getFigure().setVisible(visible);
setLinksVisible(refPart, visible);
}
@@ -156,88 +160,125 @@
referenceList.add(shape.getOrmShape());
- for(int i=0;i<shape.getChildren().size();i++){
- refreshReferences(shape.getChildren().get(i), visible);
+ Iterator<Shape> it = shape.getChildrenIterator();
+ while (it.hasNext()) {
+ refreshReferences(it.next(), visible);
}
referenceList.remove(shape.getOrmShape());
shape.getOrmDiagram().update();
}
private boolean isTableCanBeInvisible(OrmEditPart tablePart, boolean visible){
- if(visible) return true;
+ if (visible) {
+ return true;
+ }
ConnectionEditPart link;
- for(int i=0;i<tablePart.getTargetConnections().size();i++){
+ for (int i = 0; i < tablePart.getTargetConnections().size(); i++) {
link = (ConnectionEditPart)tablePart.getTargetConnections().get(i);
- if(link.getFigure().isVisible()) return false;
+ if (link.getFigure().isVisible()) {
+ return false;
+ }
}
return true;
}
private boolean isShapeCanBeInvisible(OrmEditPart source, OrmEditPart target, boolean
visible){
- if(visible) return true;
+ if (visible) {
+ return true;
+ }
ConnectionEditPart link;
- for(int i=0;i<target.getTargetConnections().size();i++){
+ for (int i=0;i<target.getTargetConnections().size();i++) {
link = (ConnectionEditPart)target.getTargetConnections().get(i);
- if(link.getFigure().isVisible() && link.getSource() != source) return false;
+ if (link.getFigure().isVisible() && link.getSource() != source) {
+ return false;
+ }
}
return true;
}
- private boolean isReferencesCorrect(OrmShape shape){
- if(shape == null) return false;
- for(int i=0;i < referenceList.size();i++){
- if(shape.equals(referenceList.get(i))) return false;
+ private boolean isReferencesCorrect(OrmShape shape) {
+ if (shape == null) {
+ return false;
}
+ for (int i = 0; i < referenceList.size(); i++) {
+ if (shape.equals(referenceList.get(i))) {
+ return false;
+ }
+ }
return true;
}
- private void setLinksVisible(OrmEditPart editPart, boolean flag){
+ private void setLinksVisible(OrmEditPart editPart, boolean flag) {
ConnectionEditPart link;
OrmEditPart child;
- for(int i=0;i<editPart.getSourceConnections().size();i++){
+ for (int i = 0; i < editPart.getSourceConnections().size(); i++) {
link = (ConnectionEditPart)editPart.getSourceConnections().get(i);
- if(isLinkCanBeVisible(link, flag))
+ if (isLinkCanBeVisible(link, flag)) {
link.getFigure().setVisible(flag);
+ }
}
- for(int i=0;i<editPart.getTargetConnections().size();i++){
+ for (int i = 0; i < editPart.getTargetConnections().size(); i++) {
link = (ConnectionEditPart)editPart.getTargetConnections().get(i);
- if(isLinkCanBeVisible(link, flag))
+ if (isLinkCanBeVisible(link, flag)) {
link.getFigure().setVisible(flag);
+ }
}
- for(int i=0;i<editPart.getChildren().size();i++){
+ for (int i = 0; i < editPart.getChildren().size();i++) {
child = (OrmEditPart)editPart.getChildren().get(i);
setLinksVisible(child, flag);
}
}
- private boolean isLinkCanBeVisible(ConnectionEditPart link, boolean visible){
- if(!visible) return true;
- if(!((OrmEditPart)link.getSource()).getFigure().isVisible()) return false;
- if(!((OrmEditPart)link.getTarget()).getFigure().isVisible()) return false;
- if(!validateShape((Shape)((OrmEditPart)link.getSource()).getModel())) return false;
- if(!validateShape((Shape)((OrmEditPart)link.getTarget()).getModel())) return false;
+ private boolean isLinkCanBeVisible(ConnectionEditPart link, boolean visible) {
+ if (!visible) {
+ return true;
+ }
+ if (!((OrmEditPart)link.getSource()).getFigure().isVisible()) {
+ return false;
+ }
+ if (!((OrmEditPart)link.getTarget()).getFigure().isVisible()) {
+ return false;
+ }
+ if (!validateShape((Shape)((OrmEditPart)link.getSource()).getModel())) {
+ return false;
+ }
+ if (!validateShape((Shape)((OrmEditPart)link.getTarget()).getModel())) {
+ return false;
+ }
return true;
}
private boolean validateShape(Shape shape){
- if(!shape.getClass().equals(OrmShape.class)){
+ if (!shape.getClass().equals(OrmShape.class)) {
OrmShape ormShape = shape.getOrmShape();
- if(ormShape != null){
- if(ormShape.isHiden()) return false;
+ if (ormShape != null) {
+ if (ormShape.isHiden()) {
+ return false;
+ }
}
}
ExpandeableShape expanableShape = shape.getExtendeableShape();
- if(expanableShape != null && !shape.equals(expanableShape) &&
!expanableShape.getClass().equals(OrmShape.class)){
- if(!expanableShape.isReferenceVisible()) return false;
+ if (expanableShape != null && !shape.equals(expanableShape) &&
!expanableShape.getClass().equals(OrmShape.class)) {
+ if (!expanableShape.isReferenceVisible()) {
+ return false;
+ }
}
-
-
return true;
}
- protected List getModelChildren() {
- return ((ExpandeableShape)getModel()).getChildren();
+ /**
+ * Returns a <code>List</code> containing the children model objects.
+ * @return the List of children
+ */
+ @Override
+ protected List<Shape> getModelChildren() {
+ List<Shape> res = new ArrayList<Shape>();
+ Iterator<Shape> it = ((ExpandeableShape)getModel()).getChildrenIterator();
+ while (it.hasNext()) {
+ res.add(it.next());
+ }
+ return res;
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeTreeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeTreeEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ExpandeableShapeTreeEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -2,6 +2,8 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.eclipse.swt.widgets.Tree;
@@ -39,13 +41,17 @@
}
/**
- * Returns <code>null</code> as a Tree EditPart holds no children under
- * it.
- *
+ * Returns <code>null</code> as a Tree EditPart holds no children under it.
* @return <code>null</code>
*/
- protected List getModelChildren() {
- return getExpandeableShape().getChildren();
+ @Override
+ protected List<Shape> getModelChildren() {
+ List<Shape> res = new ArrayList<Shape>();
+ Iterator<Shape> it = getExpandeableShape().getChildrenIterator();
+ while (it.hasNext()) {
+ res.add(it.next());
+ }
+ return res;
}
public void propertyChange(PropertyChangeEvent change) {
@@ -56,8 +62,9 @@
* Refreshes the visual properties of the TreeItem for this part.
*/
protected void refreshVisuals() {
- if (getWidget() instanceof Tree)
+ if (getWidget() instanceof Tree) {
return;
+ }
Shape model = (Shape) getModel();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/GEFRootEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/GEFRootEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/GEFRootEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -19,13 +19,13 @@
import org.eclipse.gef.editparts.ScalableFreeformRootEditPart;
//import org.eclipse.gef.LayerConstants;
-public class GEFRootEditPart extends ScalableFreeformRootEditPart{
+public class GEFRootEditPart extends ScalableFreeformRootEditPart {
public GEFRootEditPart() {
super();
}
- public void setToFront(AbstractConnectionEditPart editpart){
+ public void setToFront(AbstractConnectionEditPart editpart) {
ConnectionLayer layer = (ConnectionLayer)getLayer(LayerConstants.CONNECTION_LAYER);
IFigure fig = editpart.getFigure();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -21,7 +21,7 @@
import org.eclipse.gef.EditPartListener;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
-public class OrmEditPart extends AbstractGraphicalEditPart implements EditPartListener{
+public class OrmEditPart extends AbstractGraphicalEditPart implements EditPartListener {
public void setModel(Object model) {
super.setModel(model);
@@ -41,7 +41,7 @@
}
public void selectedStateChanged(EditPart editpart) {
- if(this.getSelected() == EditPart.SELECTED_PRIMARY &&
OrmEditPart.this.getParent() instanceof DiagramEditPart) {
+ if (this.getSelected() == EditPart.SELECTED_PRIMARY &&
OrmEditPart.this.getParent() instanceof DiagramEditPart) {
((DiagramEditPart)OrmEditPart.this.getParent()).setToFront(this);
}
}
@@ -77,16 +77,17 @@
if (i < editParts.size()) {
editPart = editParts.get(i);
if (editPart.getModel() == model) {
- if (editPart.getSource() != this)
+ if (editPart.getSource() != this) {
editPart.setSource(this);
+ }
continue;
}
}
editPart = modelToEditPart.get(model);
- if (editPart != null)
+ if (editPart != null) {
reorderSourceConnection(editPart, i);
- else {
+ } else {
editPart = createOrFindConnection(model);
addSourceConnection(editPart, i);
}
@@ -94,10 +95,12 @@
// Remove the remaining EditParts
List<ConnectionEditPart> trash = new ArrayList<ConnectionEditPart>();
- for (; i < editParts.size(); i++)
+ for (; i < editParts.size(); i++) {
trash.add(editParts.get(i));
- for (i = 0; i < trash.size(); i++)
+ }
+ for (i = 0; i < trash.size(); i++) {
removeSourceConnection(trash.get(i));
+ }
}
@SuppressWarnings("unchecked")
@@ -113,27 +116,27 @@
editPart = connections.get(i);
mapModelToEditPart.put(editPart.getModel(), editPart);
}
-
List<?> modelObjects = getModelTargetConnections();
- if (modelObjects == null)
+ if (modelObjects == null) {
modelObjects = new ArrayList<Object>();
-
+ }
for (i = 0; i < modelObjects.size(); i++) {
model = modelObjects.get(i);
if (i < connections.size()) {
editPart = connections.get(i);
if (editPart.getModel() == model) {
- if (editPart.getTarget() != this)
+ if (editPart.getTarget() != this) {
editPart.setTarget(this);
+ }
continue;
}
}
editPart = mapModelToEditPart.get(model);
- if (editPart != null)
+ if (editPart != null) {
reorderTargetConnection(editPart, i);
- else {
+ } else {
editPart = createOrFindConnection(model);
addTargetConnection(editPart, i);
}
@@ -141,15 +144,18 @@
// Remove the remaining Connection EditParts
List<ConnectionEditPart> trash = new ArrayList<ConnectionEditPart>();
- for (; i < connections.size(); i++)
+ for (; i < connections.size(); i++) {
trash.add(connections.get(i));
- for (i = 0; i < trash.size(); i++)
+ }
+ for (i = 0; i < trash.size(); i++) {
removeTargetConnection(trash.get(i));
+ }
}
protected void removeSourceConnection(ConnectionEditPart connection) {
- if (connection.getSource() != this)
+ if (connection.getSource() != this) {
return;
+ }
fireRemovingSourceConnection(connection, getSourceConnections()
.indexOf(connection));
connection.deactivate();
@@ -158,8 +164,9 @@
}
protected void removeTargetConnection(ConnectionEditPart connection) {
- if (connection.getTarget() != this)
+ if (connection.getTarget() != this) {
return;
+ }
fireRemovingTargetConnection(connection, getTargetConnections()
.indexOf(connection));
connection.setTarget(null);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmShapeEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/OrmShapeEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -42,7 +42,7 @@
public void addNotify() {
super.addNotify();
- if(((OrmShape)getModel()).isHiden()){
+ if (((OrmShape)getModel()).isHiden()) {
int i = figure.getPreferredSize().width;
((TitleFigure)figure).setHidden(true);
((TitleLabel)figure.getChildren().get(0)).setHidden(true);
@@ -103,10 +103,11 @@
int i = figure.getPreferredSize().width;
((TitleFigure)figure).setHidden(((Boolean)evt.getNewValue()).booleanValue());
((TitleLabel)figure.getChildren().get(0)).setHidden(((Boolean)evt.getNewValue()).booleanValue());
- if(((Boolean)evt.getNewValue()).booleanValue())
+ if(((Boolean)evt.getNewValue()).booleanValue()) {
figure.setSize(i,-1);
- else
+ } else {
figure.setSize(-1,-1);
+ }
refresh();
((OrmDiagram)getParent().getModel()).setDirty(true);
} else {
@@ -119,20 +120,23 @@
if (getModel() instanceof OrmShape) {
bounds = new Rectangle(((OrmShape)getModel()).getLocation(), getFigure().getSize());
}
- if (bounds != null) ((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), bounds);
+ if (bounds != null) {
+ ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), bounds);
+ }
}
protected Color getBackgroundColor() {
Object element = getCastedModel().getOrmElement();
- if (element instanceof PersistentClass || element instanceof Component)
+ if (element instanceof PersistentClass || element instanceof Component) {
return ResourceManager.getInstance().getColor(new RGB(0,0,0));
- else if (element instanceof Table || element instanceof Property)
+ } else if (element instanceof Table || element instanceof Property) {
return ResourceManager.getInstance().getColor(new RGB(
Integer.parseInt(ColorConstants.Colors_DatabaseColumnR),
Integer.parseInt(ColorConstants.Colors_DatabaseColumnG),
Integer.parseInt(ColorConstants.Colors_DatabaseColumnB)));
- else
+ } else {
throw new IllegalArgumentException();
+ }
}
}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ResourceManager.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ResourceManager.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ResourceManager.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -35,11 +35,13 @@
private void dispose() {
Iterator<Color> e = fColorTable.values().iterator();
- while (e.hasNext())
- e.next().dispose();
+ while (e.hasNext()) {
+ e.next().dispose();
+ }
Iterator<Font> e2 = fFontTable.values().iterator();
- while (e2.hasNext())
- e2.next().dispose();
+ while (e2.hasNext()) {
+ e2.next().dispose();
+ }
}
public Color getColor(RGB rgb) {
Color color = fColorTable.get(rgb);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -105,11 +105,13 @@
public void performRequest(Request req) {
if(RequestConstants.REQ_OPEN.equals(req.getType())) {
if (getCastedModel().getOrmElement() instanceof Column) {
- if(getCastedModel().getTargetConnections().size() > 0)
+ if (getCastedModel().getTargetConnections().size() > 0) {
getCastedModel().getTargetConnections().get(0).getSource().setFocus();
+ }
} else {
- if(getCastedModel().getSourceConnections().size() > 0)
+ if (getCastedModel().getSourceConnections().size() > 0) {
getCastedModel().getSourceConnections().get(0).getTarget().setFocus();
+ }
}
}
}
@@ -167,10 +169,11 @@
}
OrmShapeEditPart part = getOrmShapeEditPart();
Point p = r.getCenter();
- if (reference.x < p.x)
- p.x-=part.getFigure().getBounds().width/2;
- else
- p.x+=part.getFigure().getBounds().width/2;
+ if (reference.x < p.x) {
+ p.x -= part.getFigure().getBounds().width / 2;
+ } else {
+ p.x += part.getFigure().getBounds().width / 2;
+ }
return p;
}
};
@@ -182,8 +185,9 @@
EditPart part = this;
while (!((part instanceof OrmShapeEditPart))) {
part = part.getParent();
- if(i++ > 4)
+ if (i++ > 4) {
throw new RuntimeException();
+ }
}
return (OrmShapeEditPart)part;
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeTreeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeTreeEditPart.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/parts/ShapeTreeEditPart.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -56,9 +56,9 @@
* Refreshes the visual properties of the TreeItem for this part.
*/
protected void refreshVisuals() {
- if (getWidget() instanceof Tree)
+ if (getWidget() instanceof Tree) {
return;
-
+ }
Shape model = (Shape) getModel();
Object element = model.getOrmElement();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/popup/PopupMenuProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/popup/PopupMenuProvider.java 2009-06-18
12:20:43 UTC (rev 16038)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui.veditor/src/org/jboss/tools/hibernate/ui/veditor/editors/popup/PopupMenuProvider.java 2009-06-18
12:31:56 UTC (rev 16039)
@@ -99,8 +99,9 @@
public void createMenuItem(Menu menu, IAction action) {
boolean enabled = action.isEnabled();
boolean hidden = false;
- if (hidden)
+ if (hidden) {
return;
+ }
MenuItem item = new MenuItem(menu, SWT.CASCADE);
String displayName = action.getText();
item.addSelectionListener(new AL(action));