Author: vyemialyanchyk
Date: 2009-10-07 07:21:00 -0400 (Wed, 07 Oct 2009)
New Revision: 17953
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/MessageShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInput.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInputFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorStorage.java
Removed:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/ObjectEditorInput.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/META-INF/MANIFEST.MF
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/plugin.xml
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/DiagramViewerMessages.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/DiagramViewerMessages.properties
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramContentOutlinePage.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramViewer.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/AutoLayoutAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/CollapseAllAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/DiagramBaseAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExpandAllAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/OpenMappingAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/OpenSourceAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/RefreshAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/figures/TitleFigure.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/figures/TitleLabel.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/BaseElement.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ComponentShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ExpandableShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmShape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Shape.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Utils.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/DiagramEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmEditPartFactory.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/ShapeEditPart.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OpenDiagramActionDelegate.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmImageMap.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelProvider.java
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.test/src/org/jboss/tools/hibernate/ui/diagram/editors/model/test/OrmDiagramTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4866 &
https://jira.jboss.org/jira/browse/JBIDE-4964 - fixed
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/META-INF/MANIFEST.MF
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/META-INF/MANIFEST.MF 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/META-INF/MANIFEST.MF 2009-10-07
11:21:00 UTC (rev 17953)
@@ -12,7 +12,6 @@
org.eclipse.ui.views,
org.eclipse.core.runtime,
org.eclipse.gef,
- org.eclipse.ui.editors,
org.eclipse.core.resources,
org.hibernate.eclipse,
org.eclipse.jdt.core,
Modified: trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/plugin.xml
===================================================================
--- trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/plugin.xml 2009-10-07
10:14:09 UTC (rev 17952)
+++ trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/plugin.xml 2009-10-07
11:21:00 UTC (rev 17953)
@@ -4,6 +4,8 @@
<extension
point="org.eclipse.ui.editors">
<editor
+ default="true"
+ extensions="hibernate"
class="org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer"
contributorClass="org.jboss.tools.hibernate.ui.diagram.editors.DiagramActionBarContributor"
icon="$nl$/icons/hibernate_small_icon.gif"
@@ -30,5 +32,12 @@
</action>
</objectContribution>
</extension>
+ <extension
+ point="org.eclipse.ui.elementFactories">
+ <factory
+
class="org.jboss.tools.hibernate.ui.view.DiagramEditorInputFactory"
+
id="org.jboss.tools.hibernate.ui.view.DiagramEditorInputFactory">
+ </factory>
+ </extension>
</plugin>
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/DiagramViewerMessages.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/DiagramViewerMessages.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/DiagramViewerMessages.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -57,4 +57,5 @@
public static String TogglePropertyMappingAction_property_mappings;
public static String ToggleAssociationAction_associations;
public static String ToggleForeignKeyConstraintAction_foreign_key_constraints;
+ public static String MessageShape_warning;
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/DiagramViewerMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/DiagramViewerMessages.properties 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/DiagramViewerMessages.properties 2009-10-07
11:21:00 UTC (rev 17953)
@@ -33,3 +33,4 @@
TogglePropertyMappingAction_property_mappings=Property Mappings
ToggleAssociationAction_associations=Associations
ToggleForeignKeyConstraintAction_foreign_key_constraints=Foreign key constraints
+MessageShape_warning=Hibernate Console Configuration is not loaded cause Hibernate
plugins are not active. To activate Open Hibernate Configurations view and press refresh
button.
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramContentOutlinePage.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramContentOutlinePage.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramContentOutlinePage.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -378,7 +378,9 @@
setDescription(DiagramViewerMessages.DiagramViewer_OutlinePage_Sort_description);
boolean checked = getOrmDiagram().isDeepIntoSort();
- valueChanged(checked);
+ if (checked) {
+ valueChanged(checked);
+ }
}
public void run() {
@@ -389,15 +391,10 @@
setChecked(on);
BusyIndicator.showWhile(outline.getDisplay(), new Runnable() {
public void run() {
- if (on) {
- getOrmDiagram().setDeepIntoSort(true);
- getOrmDiagram().refresh();
- setContents(getOrmDiagram());
- } else {
- getOrmDiagram().setDeepIntoSort(false);
- getOrmDiagram().refresh();
- setContents(getOrmDiagram());
- }
+ final OrmDiagram od = getOrmDiagram();
+ od.setDeepIntoSort(on);
+ od.refresh();
+ setContents(od);
}
});
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramViewer.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramViewer.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramViewer.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -18,6 +18,9 @@
import java.util.List;
import java.util.Set;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.gef.DefaultEditDomain;
@@ -55,9 +58,9 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.dialogs.SaveAsDialog;
+import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.mapping.RootClass;
import org.jboss.tools.hibernate.ui.diagram.DiagramViewerMessages;
import org.jboss.tools.hibernate.ui.diagram.editors.actions.ActionMenu;
import org.jboss.tools.hibernate.ui.diagram.editors.actions.AutoLayoutAction;
@@ -83,7 +86,7 @@
import org.jboss.tools.hibernate.ui.diagram.editors.popup.PopupMenuProvider;
import org.jboss.tools.hibernate.ui.diagram.rulers.DiagramRuler;
import org.jboss.tools.hibernate.ui.diagram.rulers.DiagramRulerProvider;
-import org.jboss.tools.hibernate.ui.view.ObjectEditorInput;
+import org.jboss.tools.hibernate.ui.view.DiagramEditorInput;
/**
*
@@ -92,7 +95,6 @@
*/
public class DiagramViewer extends GraphicalEditor {
- private OrmDiagram ormDiagram = null;
private GEFRootEditPart gefRootEditPart = new GEFRootEditPart();
private RulerComposite rulerComp;
@@ -102,11 +104,29 @@
public void doSave(IProgressMonitor monitor) {
saveProperties();
- ormDiagram.saveInFile();
- ormDiagram.setDirty(false);
+ //getOrmDiagram().saveInFile();
+ getOrmDiagram().saveInXmlFile();
+ getOrmDiagram().setDirty(false);
}
public void doSaveAs() {
+ SaveAsDialog saveAsDialog = new
SaveAsDialog(getSite().getWorkbenchWindow().getShell());
+ saveAsDialog.setOriginalName(getDiagramName());
+ saveAsDialog.open();
+ final IPath pathSave = saveAsDialog.getResult();
+ if (pathSave == null) {
+ return;
+ }
+ saveProperties();
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IPath pathTmp = workspace.getRoot().getFullPath().append(pathSave);
+ pathTmp = workspace.getRoot().getLocation().append(pathTmp);
+ String ext = pathSave.getFileExtension();
+ if (ext == null) {
+ pathTmp = pathTmp.addFileExtension("hibernate"); //$NON-NLS-1$
+ }
+ getOrmDiagram().saveInFile(pathTmp, true);
+ getOrmDiagram().setDirty(false);
}
protected void initializeGraphicalViewer() {
@@ -125,7 +145,7 @@
//
viewer.setRootEditPart(gefRootEditPart);
viewer.addDropTargetListener(createTransferDropTargetListener());
- viewer.setContents(ormDiagram);
+ viewer.setContents(getOrmDiagram());
PopupMenuProvider provider = new PopupMenuProvider(viewer, getActionRegistry());
viewer.setContextMenu(provider);
@@ -134,20 +154,20 @@
viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1),
MouseWheelZoomHandler.SINGLETON);
// Ruler properties
- DiagramRuler ruler = ormDiagram.getRuler(PositionConstants.WEST);
+ DiagramRuler ruler = getOrmDiagram().getRuler(PositionConstants.WEST);
RulerProvider rulerProvider = null;
if (ruler != null) {
rulerProvider = new DiagramRulerProvider(ruler);
}
getGraphicalViewer().setProperty(RulerProvider.PROPERTY_VERTICAL_RULER,
rulerProvider);
- ruler = ormDiagram.getRuler(PositionConstants.NORTH);
+ ruler = getOrmDiagram().getRuler(PositionConstants.NORTH);
rulerProvider = null;
if (ruler != null) {
rulerProvider = new DiagramRulerProvider(ruler);
}
getGraphicalViewer().setProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER,
rulerProvider);
getGraphicalViewer().setProperty(RulerProvider.PROPERTY_RULER_VISIBILITY,
- new Boolean(ormDiagram.getRulerVisibility()));
+ new Boolean(getOrmDiagram().getRulerVisibility()));
loadProperties();
}
@@ -260,7 +280,7 @@
}
public boolean isSaveAsAllowed() {
- return false;
+ return true;
}
public boolean isSaveOnCloseNeeded() {
@@ -272,34 +292,40 @@
}
public boolean isDirty() {
- return ormDiagram.isDirty();
+ return getOrmDiagram().isDirty();
}
protected void setInput(IEditorInput input) {
- ObjectEditorInput objectEditorInput = (ObjectEditorInput)input;
- ConsoleConfiguration configuration = objectEditorInput.getConfiguration();
- ArrayList<RootClass> roots = objectEditorInput.getRootClasses();
- setPartName(DiagramViewerMessages.DiagramViewer_diagram_for + " " +
objectEditorInput.getName()); //$NON-NLS-1$
- if (roots.size() == 1) {
- RootClass rootClass = roots.get(0);
- ormDiagram = new OrmDiagram(configuration, rootClass);
- } else if (roots.size() > 1) {
- RootClass[] rootClasses = roots.toArray(new RootClass[0]);
- ormDiagram = new OrmDiagram(configuration, rootClasses);
+ DiagramEditorInput diagramInput = null;
+ if (input instanceof FileEditorInput) {
+ diagramInput = new DiagramEditorInput((FileEditorInput)input);
+ } else if (input instanceof DiagramEditorInput) {
+ diagramInput = (DiagramEditorInput)input;
}
- super.setInput(input);
+ setPartName(DiagramViewerMessages.DiagramViewer_diagram_for + " " +
diagramInput.getName()); //$NON-NLS-1$
+ super.setInput(diagramInput);
loadProperties();
}
+ public DiagramEditorInput getDiagramInput() {
+ DiagramEditorInput diagramInput = (DiagramEditorInput)getEditorInput();
+ return diagramInput;
+ }
+
public String getDiagramName() {
IEditorInput input = getEditorInput();
- if (input instanceof ObjectEditorInput) {
- ObjectEditorInput objectEditorInput = (ObjectEditorInput)input;
+ if (input instanceof DiagramEditorInput) {
+ DiagramEditorInput objectEditorInput = (DiagramEditorInput)input;
return objectEditorInput.getName();
}
return ""; //$NON-NLS-1$
}
+ public void refresh() {
+ getOrmDiagram().refresh();
+ setPartName(DiagramViewerMessages.DiagramViewer_diagram_for + " " +
getDiagramInput().getName()); //$NON-NLS-1$
+ }
+
/**
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
*/
@@ -310,7 +336,7 @@
new TreeViewer(), getActionRegistry());
outline.setGraphicalViewer(getGraphicalViewer());
outline.setSelectionSynchronizer(getSelectionSynchronizer());
- outline.setOrmDiagram(ormDiagram);
+ outline.setOrmDiagram(getOrmDiagram());
outline.setEditor(this);
RefreshAction refreshAction = (RefreshAction)getActionRegistry().getAction(
ActionFactory.REFRESH.getId());
@@ -337,8 +363,8 @@
return ret;
}
- public OrmDiagram getViewerContents() {
- return ormDiagram;
+ public OrmDiagram getOrmDiagram() {
+ return getDiagramInput().getOrmDiagram();
}
public DefaultEditDomain getDefaultEditDomain() {
@@ -361,56 +387,56 @@
}
protected boolean loadProperties() {
- if (ormDiagram == null || getGraphicalViewer() == null) {
+ if (getOrmDiagram() == null || getGraphicalViewer() == null) {
return false;
}
// Ruler properties
- DiagramRuler ruler = ormDiagram.getRuler(PositionConstants.WEST);
+ DiagramRuler ruler = getOrmDiagram().getRuler(PositionConstants.WEST);
RulerProvider provider = null;
if (ruler != null) {
provider = new DiagramRulerProvider(ruler);
}
getGraphicalViewer().setProperty(RulerProvider.PROPERTY_VERTICAL_RULER, provider);
- ruler = ormDiagram.getRuler(PositionConstants.NORTH);
+ ruler = getOrmDiagram().getRuler(PositionConstants.NORTH);
provider = null;
if (ruler != null) {
provider = new DiagramRulerProvider(ruler);
}
getGraphicalViewer().setProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER, provider);
getGraphicalViewer().setProperty(RulerProvider.PROPERTY_RULER_VISIBILITY,
- new Boolean(ormDiagram.getRulerVisibility()));
+ new Boolean(getOrmDiagram().getRulerVisibility()));
// Snap to Geometry property
getGraphicalViewer().setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED,
- new Boolean(ormDiagram.isSnapToGeometryEnabled()));
+ new Boolean(getOrmDiagram().isSnapToGeometryEnabled()));
// Grid properties
getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_ENABLED,
- new Boolean(ormDiagram.isGridEnabled()));
+ new Boolean(getOrmDiagram().isGridEnabled()));
// We keep grid visibility and enablement in sync
getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE,
- new Boolean(ormDiagram.isGridEnabled()));
+ new Boolean(getOrmDiagram().isGridEnabled()));
// Zoom
ZoomManager manager = (ZoomManager)getGraphicalViewer()
.getProperty(ZoomManager.class.toString());
if (manager != null) {
- manager.setZoom(ormDiagram.getZoom());
+ manager.setZoom(getOrmDiagram().getZoom());
}
return true;
}
protected boolean saveProperties() {
- if (ormDiagram == null || getGraphicalViewer() == null) {
+ if (getOrmDiagram() == null || getGraphicalViewer() == null) {
return false;
}
- ormDiagram.setRulerVisibility(((Boolean)getGraphicalViewer()
+ getOrmDiagram().setRulerVisibility(((Boolean)getGraphicalViewer()
.getProperty(RulerProvider.PROPERTY_RULER_VISIBILITY)).booleanValue());
- ormDiagram.setGridEnabled(((Boolean)getGraphicalViewer()
+ getOrmDiagram().setGridEnabled(((Boolean)getGraphicalViewer()
.getProperty(SnapToGrid.PROPERTY_GRID_ENABLED)).booleanValue());
- ormDiagram.setSnapToGeometry(((Boolean)getGraphicalViewer()
+ getOrmDiagram().setSnapToGeometry(((Boolean)getGraphicalViewer()
.getProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED)).booleanValue());
- ormDiagram.setZoom(getZoom());
+ getOrmDiagram().setZoom(getZoom());
return true;
}
@@ -494,44 +520,44 @@
public boolean getConnectionsVisibilityAssociation() {
- return getViewerContents().getConnectionsVisibilityAssociation();
+ return getOrmDiagram().getConnectionsVisibilityAssociation();
}
public void setConnectionsVisibilityAssociation(boolean
connectionsVisibilityAssociation) {
- getViewerContents().setConnectionsVisibilityAssociation(connectionsVisibilityAssociation);
+ getOrmDiagram().setConnectionsVisibilityAssociation(connectionsVisibilityAssociation);
ActionRegistry registry = getActionRegistry();
IAction action = registry.getAction(ToggleAssociationAction.ACTION_ID);
action.setChecked(connectionsVisibilityAssociation);
}
public boolean getConnectionsVisibilityClassMapping() {
- return getViewerContents().getConnectionsVisibilityClassMapping();
+ return getOrmDiagram().getConnectionsVisibilityClassMapping();
}
public void setConnectionsVisibilityClassMapping(boolean
connectionsVisibilityClassMapping) {
- getViewerContents().setConnectionsVisibilityClassMapping(connectionsVisibilityClassMapping);
+ getOrmDiagram().setConnectionsVisibilityClassMapping(connectionsVisibilityClassMapping);
ActionRegistry registry = getActionRegistry();
IAction action = registry.getAction(ToggleClassMappingAction.ACTION_ID);
action.setChecked(connectionsVisibilityClassMapping);
}
public boolean getConnectionsVisibilityForeignKeyConstraint() {
- return getViewerContents().getConnectionsVisibilityForeignKeyConstraint();
+ return getOrmDiagram().getConnectionsVisibilityForeignKeyConstraint();
}
public void setConnectionsVisibilityForeignKeyConstraint(boolean
connectionsVisibilityForeignKeyConstraint) {
- getViewerContents().setConnectionsVisibilityForeignKeyConstraint(connectionsVisibilityForeignKeyConstraint);
+ getOrmDiagram().setConnectionsVisibilityForeignKeyConstraint(connectionsVisibilityForeignKeyConstraint);
ActionRegistry registry = getActionRegistry();
IAction action = registry.getAction(ToggleForeignKeyConstraintAction.ACTION_ID);
action.setChecked(connectionsVisibilityForeignKeyConstraint);
}
public boolean getConnectionsVisibilityPropertyMapping() {
- return getViewerContents().getConnectionsVisibilityPropertyMapping();
+ return getOrmDiagram().getConnectionsVisibilityPropertyMapping();
}
public void setConnectionsVisibilityPropertyMapping(boolean
connectionsVisibilityPropertyMapping) {
- getViewerContents().setConnectionsVisibilityPropertyMapping(connectionsVisibilityPropertyMapping);
+ getOrmDiagram().setConnectionsVisibilityPropertyMapping(connectionsVisibilityPropertyMapping);
ActionRegistry registry = getActionRegistry();
IAction action = registry.getAction(TogglePropertyMappingAction.ACTION_ID);
action.setChecked(connectionsVisibilityPropertyMapping);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/AutoLayoutAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/AutoLayoutAction.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/AutoLayoutAction.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -32,6 +32,6 @@
}
public void run() {
- getDiagramViewer().getViewerContents().autolayout();
+ getDiagramViewer().getOrmDiagram().autolayout();
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/CollapseAllAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/CollapseAllAction.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/CollapseAllAction.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -29,6 +29,6 @@
}
public void run() {
- getDiagramViewer().getViewerContents().collapseAll();
+ getDiagramViewer().getOrmDiagram().collapseAll();
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/DiagramBaseAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/DiagramBaseAction.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/DiagramBaseAction.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -11,7 +11,9 @@
package org.jboss.tools.hibernate.ui.diagram.editors.actions;
import org.eclipse.jface.action.Action;
+import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.views.contentoutline.ContentOutline;
import org.jboss.tools.hibernate.ui.diagram.editors.DiagramContentOutlinePage;
@@ -35,7 +37,15 @@
protected DiagramViewer getDiagramViewer() {
DiagramViewer res = editor;
- IWorkbenchPart part =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart();
+ final IWorkbenchWindow workbenchWindow =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (workbenchWindow == null) {
+ return res;
+ }
+ final IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
+ if (workbenchPage == null) {
+ return res;
+ }
+ IWorkbenchPart part = workbenchPage.getActivePart();
if (part instanceof DiagramViewer) {
res = (DiagramViewer)part;
} else if (part instanceof ContentOutline) {
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExpandAllAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExpandAllAction.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExpandAllAction.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -29,6 +29,6 @@
}
public void run() {
- getDiagramViewer().getViewerContents().expandAll();
+ getDiagramViewer().getOrmDiagram().expandAll();
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/OpenMappingAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/OpenMappingAction.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/OpenMappingAction.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -28,7 +28,7 @@
import org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer;
import org.jboss.tools.hibernate.ui.diagram.editors.model.Shape;
import org.jboss.tools.hibernate.ui.diagram.editors.model.SpecialRootClass;
-import org.jboss.tools.hibernate.ui.view.ObjectEditorInput;
+import org.jboss.tools.hibernate.ui.view.DiagramEditorInput;
/**
* @author Dmitry Geraskov
@@ -47,8 +47,8 @@
}
public void run() {
- ObjectEditorInput objectEditorInput =
(ObjectEditorInput)((DiagramViewer)getWorkbenchPart()).getEditorInput();
- ConsoleConfiguration consoleConfig = objectEditorInput.getConfiguration();
+ DiagramEditorInput objectEditorInput =
(DiagramEditorInput)((DiagramViewer)getWorkbenchPart()).getEditorInput();
+ ConsoleConfiguration consoleConfig = objectEditorInput.getConsoleConfig();
DiagramViewer part = (DiagramViewer)getWorkbenchPart();
Set<Shape> selectedElements = part.getSelectedElements();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/OpenSourceAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/OpenSourceAction.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/OpenSourceAction.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -30,7 +30,7 @@
import org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer;
import org.jboss.tools.hibernate.ui.diagram.editors.model.Connection;
import org.jboss.tools.hibernate.ui.diagram.editors.model.Shape;
-import org.jboss.tools.hibernate.ui.view.ObjectEditorInput;
+import org.jboss.tools.hibernate.ui.view.DiagramEditorInput;
/**
* @author Dmitry Geraskov
@@ -49,8 +49,8 @@
}
public void run() {
- ObjectEditorInput objectEditorInput =
(ObjectEditorInput)((DiagramViewer)getWorkbenchPart()).getEditorInput();
- ConsoleConfiguration consoleConfig = objectEditorInput.getConfiguration();
+ DiagramEditorInput objectEditorInput =
(DiagramEditorInput)((DiagramViewer)getWorkbenchPart()).getEditorInput();
+ ConsoleConfiguration consoleConfig = objectEditorInput.getConsoleConfig();
DiagramViewer part = (DiagramViewer)getWorkbenchPart();
Set<Shape> selectedElements = part.getSelectedElements();
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/RefreshAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/RefreshAction.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/RefreshAction.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -36,7 +36,7 @@
}
public void run() {
- getDiagramViewer().getViewerContents().refresh();
+ getDiagramViewer().refresh();
if (outline != null) {
// synchronize contents of outline page
outline.setContents(outline.getOrmDiagram());
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/figures/TitleFigure.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/figures/TitleFigure.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/figures/TitleFigure.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -18,6 +18,7 @@
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
@@ -59,10 +60,15 @@
removeTitle();
TitleLabel label = new TitleLabel(fontHeight);
label.setText(text);
- FontData fontData[] = Display.getCurrent().getSystemFont().getFontData();
- fontData[0].setStyle(SWT.BOLD);
- fontData[0].height = fontHeight;
- label.setFont(ResourceManager.getInstance().getFont(fontData[0]));
+ if (Display.getCurrent() != null) {
+ final Font font = Display.getCurrent().getSystemFont();
+ if (font != null) {
+ FontData fontData[] = font.getFontData();
+ fontData[0].setStyle(SWT.BOLD);
+ fontData[0].height = fontHeight;
+ label.setFont(ResourceManager.getInstance().getFont(fontData[0]));
+ }
+ }
label.setBackgroundColor(bg);
label.setIcon(icon);
label.setLabelAlignment(PositionConstants.LEFT);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/figures/TitleLabel.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/figures/TitleLabel.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/figures/TitleLabel.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -14,6 +14,7 @@
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
@@ -37,9 +38,14 @@
protected boolean expanded = true;
public TitleLabel(float fontHeight) {
- FontData fontData[] = Display.getCurrent().getSystemFont().getFontData();
- fontData[0].height = fontHeight;
- setFont(ResourceManager.getInstance().getFont(fontData[0]));
+ if (Display.getCurrent() != null) {
+ final Font font = Display.getCurrent().getSystemFont();
+ if (font != null) {
+ FontData fontData[] = font.getFontData();
+ fontData[0].height = fontHeight;
+ setFont(ResourceManager.getInstance().getFont(fontData[0]));
+ }
+ }
}
/**
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/BaseElement.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/BaseElement.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/BaseElement.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Properties;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
@@ -29,6 +30,7 @@
*/
public abstract class BaseElement implements IPropertySource,
Comparable<BaseElement> {
+ public static final String CLASS_NAME = "className"; //$NON-NLS-1$
public static final String SELECTED = "selected"; //$NON-NLS-1$
public static final String VISIBLE = "visible"; //$NON-NLS-1$
public static final String VISIBLE_CHILDREN = "visibileChildren";
//$NON-NLS-1$
@@ -266,33 +268,90 @@
* @return key value for object of this class
*/
public abstract String getKey();
+
+ public void setPrValue(IMemento memento, String propertyName, boolean value) {
+ Utils.setPropertyValue(memento, getKey() + "." + propertyName, value);
//$NON-NLS-1$
+ }
+
+ public boolean getPrValue(IMemento memento, String propertyName, boolean def) {
+ return Utils.getPropertyValue(memento, getKey() + "." + propertyName, def);
//$NON-NLS-1$
+ }
+
+ public void setPrValue(Properties properties, String propertyName, boolean value) {
+ Utils.setPropertyValue(properties, getKey() + "." + propertyName, value);
//$NON-NLS-1$
+ }
+
+ public boolean getPrValue(Properties properties, String propertyName, boolean def) {
+ return Utils.getPropertyValue(properties, getKey() + "." + propertyName,
def); //$NON-NLS-1$
+ }
+
+ public void setPrValue(IMemento memento, String propertyName, int value) {
+ Utils.setPropertyValue(memento, getKey() + "." + propertyName,
Integer.toString(value)); //$NON-NLS-1$
+ }
+
+ public int getPrValue(IMemento memento, String propertyName, int def) {
+ return Utils.getPropertyValue(memento, getKey() + "." + propertyName, def);
//$NON-NLS-1$
+ }
+
+ public void setPrValue(Properties properties, String propertyName, int value) {
+ Utils.setPropertyValue(properties, getKey() + "." + propertyName,
Integer.toString(value)); //$NON-NLS-1$
+ }
+
+ public int getPrValue(Properties properties, String propertyName, int def) {
+ return Utils.getPropertyValue(properties, getKey() + "." + propertyName,
def); //$NON-NLS-1$
+ }
+
+ public void setPrValue(IMemento memento, String propertyName, double value) {
+ Utils.setPropertyValue(memento, getKey() + "." + propertyName,
Double.toString(value)); //$NON-NLS-1$
+ }
+
+ public double getPrValue(IMemento memento, String propertyName, double def) {
+ return Utils.getPropertyValue(memento, getKey() + "." + propertyName, def);
//$NON-NLS-1$
+ }
+
+ public void setPrValue(Properties properties, String propertyName, double value) {
+ Utils.setPropertyValue(properties, getKey() + "." + propertyName,
Double.toString(value)); //$NON-NLS-1$
+ }
+
+ public double getPrValue(Properties properties, String propertyName, double def) {
+ return Utils.getPropertyValue(properties, getKey() + "." + propertyName,
def); //$NON-NLS-1$
+ }
- protected void setPropertyValue(Properties properties, String key, boolean value) {
- if (properties.containsKey(key)) {
- properties.remove(key);
- }
- properties.put(key, Boolean.valueOf(value).toString());
+ public void setPrValue(IMemento memento, String propertyName, String value) {
+ Utils.setPropertyValue(memento, getKey() + "." + propertyName, value);
//$NON-NLS-1$
}
- protected boolean getPropertyValue(Properties properties, String key) {
- String str = properties.getProperty(key, "true"); //$NON-NLS-1$
- return Boolean.valueOf(str).booleanValue();
+ public String getPrValue(IMemento memento, String propertyName, String def) {
+ return Utils.getPropertyValue(memento, getKey() + "." + propertyName, def);
//$NON-NLS-1$
}
- public void setPrValue(Properties properties, boolean value, String propertyName) {
- setPropertyValue(properties, getKey() + "." + propertyName, value);
//$NON-NLS-1$
+ public void setPrValue(Properties properties, String propertyName, String value) {
+ Utils.setPropertyValue(properties, getKey() + "." + propertyName, value);
//$NON-NLS-1$
}
- public boolean getPrValue(Properties properties, String propertyName) {
- return getPropertyValue(properties, getKey() + "." + propertyName);
//$NON-NLS-1$
+ public String getPrValue(Properties properties, String propertyName, String def) {
+ return Utils.getPropertyValue(properties, getKey() + "." + propertyName,
def); //$NON-NLS-1$
}
+ public void loadState(IMemento memento) {
+ boolean visibleChildren = getPrValue(memento, VISIBLE_CHILDREN, true);
+ setVisibleChildren(visibleChildren);
+ boolean visible = getPrValue(memento, VISIBLE, true);
+ setVisible(visible);
+ boolean selected = getPrValue(memento, SELECTED, true);
+ setSelected(selected);
+ Iterator<Shape> it = getChildrenIterator();
+ while (it.hasNext()) {
+ it.next().loadState(memento);
+ }
+ }
+
protected void loadFromProperties(Properties properties) {
- boolean visibleChildren = getPrValue(properties, VISIBLE_CHILDREN);
+ boolean visibleChildren = getPrValue(properties, VISIBLE_CHILDREN, true);
setVisibleChildren(visibleChildren);
- boolean visible = getPrValue(properties, VISIBLE);
+ boolean visible = getPrValue(properties, VISIBLE, true);
setVisible(visible);
- boolean selected = getPrValue(properties, SELECTED);
+ boolean selected = getPrValue(properties, SELECTED, true);
setSelected(selected);
Iterator<Shape> it = getChildrenIterator();
while (it.hasNext()) {
@@ -300,13 +359,30 @@
}
}
+ public void saveState(IMemento memento) {
+ String className = getClass().getCanonicalName();
+ setPrValue(memento, CLASS_NAME, className);
+ boolean visibleChildren = isVisibleChildren();
+ setPrValue(memento, VISIBLE_CHILDREN, visibleChildren);
+ boolean visible = isVisible();
+ setPrValue(memento, VISIBLE, visible);
+ boolean selected = isSelected();
+ setPrValue(memento, SELECTED, selected);
+ Iterator<Shape> it = getChildrenIterator();
+ while (it.hasNext()) {
+ it.next().saveState(memento);
+ }
+ }
+
protected void saveInProperties(Properties properties) {
+ String className = getClass().getCanonicalName();
+ setPrValue(properties, CLASS_NAME, className);
boolean visibleChildren = isVisibleChildren();
- setPrValue(properties, visibleChildren, VISIBLE_CHILDREN);
+ setPrValue(properties, VISIBLE_CHILDREN, visibleChildren);
boolean visible = isVisible();
- setPrValue(properties, visible, VISIBLE);
+ setPrValue(properties, VISIBLE, visible);
boolean selected = isSelected();
- setPrValue(properties, selected, SELECTED);
+ setPrValue(properties, SELECTED, selected);
Iterator<Shape> it = getChildrenIterator();
while (it.hasNext()) {
it.next().saveInProperties(properties);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ComponentShape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ComponentShape.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ComponentShape.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.diagram.editors.model;
+import java.util.Properties;
+
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Property;
@@ -38,4 +40,14 @@
addChild(bodyOrmShape);
}
}
+
+ @Override
+ protected void loadFromProperties(Properties properties) {
+ super.loadFromProperties(properties);
+ }
+
+ @Override
+ protected void saveInProperties(Properties properties) {
+ super.saveInProperties(properties);
+ }
}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ElementsFactory.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -74,7 +74,8 @@
Type type = ((Property)element).getType();
if (type.isEntityType()) {
EntityType et = (EntityType) type;
- Object clazz = config.getClassMapping(et.getAssociatedEntityName());
+ Object clazz = config != null ?
+ config.getClassMapping(et.getAssociatedEntityName()) : null;
if (clazz instanceof RootClass) {
RootClass rootClass = (RootClass)clazz;
s = getOrCreatePersistentClass(rootClass, null);
@@ -192,15 +193,17 @@
tableShape = getShape(databaseTable);
if (tableShape == null) {
tableShape = createShape(databaseTable);
- Iterator iterator = config.getClassMappings();
- while (iterator.hasNext()) {
- Object clazz = iterator.next();
- if (clazz instanceof RootClass) {
- RootClass cls = (RootClass)clazz;
- if (databaseTable.equals(cls.getTable())) {
- // create persistent class shape only for RootClass,
- // which has same table reference
- getOrCreatePersistentClass(cls, null);
+ if (config != null) {
+ Iterator iterator = config.getClassMappings();
+ while (iterator.hasNext()) {
+ Object clazz = iterator.next();
+ if (clazz instanceof RootClass) {
+ RootClass cls = (RootClass)clazz;
+ if (databaseTable.equals(cls.getTable())) {
+ // create persistent class shape only for RootClass,
+ // which has same table reference
+ getOrCreatePersistentClass(cls, null);
+ }
}
}
}
@@ -363,8 +366,6 @@
}
return classShape;
}
-
-
protected OrmShape createShape(Object ormElement) {
OrmShape ormShape = null;
@@ -386,10 +387,7 @@
}
return ormShape;
}
-
-
-
@SuppressWarnings("unchecked")
private boolean createConnections(ExpandableShape persistentClass, ExpandableShape
dbTable) {
boolean res = false;
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ExpandableShape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ExpandableShape.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/ExpandableShape.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -12,6 +12,8 @@
import java.util.Properties;
+import org.eclipse.ui.IMemento;
+
/**
* Shape with two intrinsic states: expand and collapse.
*
@@ -77,16 +79,30 @@
}
@Override
+ public void loadState(IMemento memento) {
+ super.loadState(memento);
+ boolean expanded = getPrValue(memento, EXPANDED, true);
+ setExpanded(expanded);
+ }
+
+ @Override
protected void loadFromProperties(Properties properties) {
super.loadFromProperties(properties);
- boolean expanded = getPrValue(properties, EXPANDED);
+ boolean expanded = getPrValue(properties, EXPANDED, true);
setExpanded(expanded);
}
@Override
+ public void saveState(IMemento memento) {
+ boolean expanded = isExpanded();
+ setPrValue(memento, EXPANDED, expanded);
+ super.saveState(memento);
+ }
+
+ @Override
protected void saveInProperties(Properties properties) {
boolean expanded = isExpanded();
- setPrValue(properties, expanded, EXPANDED);
+ setPrValue(properties, EXPANDED, expanded);
super.saveInProperties(properties);
}
}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/MessageShape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/MessageShape.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/MessageShape.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.ui.diagram.editors.model;
+
+import org.jboss.tools.hibernate.ui.diagram.DiagramViewerMessages;
+
+/**
+*
+* author: Vitali Yemialyanchyk
+*/
+public class MessageShape extends OrmShape {
+
+ protected MessageShape() {
+ super(DiagramViewerMessages.MessageShape_warning);
+ }
+
+ @Override
+ public String getKey() {
+ return null;
+ }
+
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmDiagram.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -10,15 +10,18 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.diagram.editors.model;
+import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
@@ -33,8 +36,13 @@
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.WorkbenchException;
+import org.eclipse.ui.XMLMemento;
import org.hibernate.cfg.Configuration;
import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.eclipse.console.utils.ProjectUtils;
import org.hibernate.mapping.RootClass;
@@ -45,7 +53,7 @@
/**
* The whole diagram, all information about diagram elements are here.
- * @author some modifications from Vitali
+ * @author Vitali Yemialianchyk
* @see BaseElement
*/
public class OrmDiagram extends BaseElement {
@@ -56,80 +64,123 @@
public static final String AUTOLAYOUT = "autolayout"; //$NON-NLS-1$
// hibernate console configuration is the source of diagram elements
- private ConsoleConfiguration consoleConfig;
- private OrmLabelProvider labelProvider = new OrmLabelProvider();
+ protected String consoleConfigName;
+ protected ArrayList<RootClass> roots = new ArrayList<RootClass>();
+ protected ArrayList<String> entityNames = new ArrayList<String>();
private boolean dirty = false;
- private HashMap<String, OrmShape> elements = new HashMap<String,
OrmShape>();
- private RootClass[] ormElements;
- private String[] entityNames;
- private boolean connectionsVisibilityClassMapping = true;
- private boolean connectionsVisibilityPropertyMapping = true;
- private boolean connectionsVisibilityAssociation = true;
- private boolean connectionsVisibilityForeignKeyConstraint = true;
- private ArrayList<Connection> connections = new ArrayList<Connection>();
+
+ protected HashMap<String, OrmShape> elements = new HashMap<String,
OrmShape>();
+ protected ArrayList<Connection> connections = new ArrayList<Connection>();
+
+ protected OrmLabelProvider labelProvider = new OrmLabelProvider();
+ protected boolean connectionsVisibilityClassMapping = true;
+ protected boolean connectionsVisibilityPropertyMapping = true;
+ protected boolean connectionsVisibilityAssociation = true;
+ protected boolean connectionsVisibilityForeignKeyConstraint = true;
+
// editor elements settings
protected DiagramRuler leftRuler, topRuler;
- private boolean rulersVisibility = false;
- private boolean snapToGeometry = false;
- private boolean gridEnabled = false;
- private double zoom = 1.0;
- private float fontHeight = 8.5f;
- private boolean deepIntoSort = false;
-
+ protected boolean rulersVisibility = false;
+ protected boolean snapToGeometry = false;
+ protected boolean gridEnabled = false;
+ protected double zoom = 1.0;
+ protected float fontHeight = 8.5f;
+ protected boolean deepIntoSort = false;
//
private boolean fileLoadSuccessfull = false;
+ // this is workaround to load diagram state in the case if Console Config loaded later
+ // so we can correctly refresh diagram state
+ private IMemento memento = null;
- public OrmDiagram(ConsoleConfiguration consoleConfig, RootClass ioe) {
- initFontHeight();
- createRulers();
- this.consoleConfig = consoleConfig;
- labelProvider.setConfig(consoleConfig.getConfiguration());
- ormElements = new RootClass[1];
- ormElements[0] = ioe;
- entityNames = new String[1];
- entityNames[0] = ioe.getEntityName();
- recreateChildren();
- sortChildren(deepIntoSort);
- loadFromFile();
- refreshDiagramElements();
- setDirty(false);
+ public class RootClassComparator implements Comparator<RootClass> {
+ public int compare(RootClass o1, RootClass o2) {
+ return getItemName(o1).compareTo(getItemName(o2));
+ }
}
- public OrmDiagram(ConsoleConfiguration consoleConfig, RootClass[] ioe) {
+ public OrmDiagram(String consoleConfigName, ArrayList<RootClass> rts) {
initFontHeight();
createRulers();
- this.consoleConfig = consoleConfig;
- labelProvider.setConfig(consoleConfig.getConfiguration());
- ormElements = new RootClass[ioe.length];
- System.arraycopy(ioe, 0, ormElements, 0, ioe.length);
+ this.consoleConfigName = consoleConfigName;
+ @SuppressWarnings("unused")
+ ConsoleConfiguration consoleConfig = getConsoleConfig();
+ labelProvider.setConsoleConfigName(consoleConfigName);
+ roots.addAll(rts);
// should sort elements - cause different sort order gives different file name
// for the same thing
- Arrays.sort(ormElements, new OrmElCompare());
- entityNames = new String[ioe.length];
- for (int i = 0; i < ormElements.length; i++) {
- entityNames[i] = ormElements[i].getEntityName();
+ Collections.sort(roots, new RootClassComparator());
+ entityNames.clear();
+ for (int i = 0; i < roots.size(); i++) {
+ entityNames.add(getItemFullName(roots.get(i)));
}
recreateChildren();
sortChildren(deepIntoSort);
- loadFromFile();
+ if (consoleConfigName.length() > 0) {
+ ////loadFromFile();
+ loadFromXmlFile();
+ }
refreshDiagramElements();
setDirty(false);
}
+
+ public String getDiagramName() {
+ String name = ""; //$NON-NLS-1$
+ ArrayList<String> names = new ArrayList<String>();
+ for (int i = 0; i < entityNames.size(); i++) {
+ names.add(getItemName(entityNames.get(i)));
+ }
+ // sort to get same name for same combinations of entities
+ Collections.sort(names);
+ name = names.size() > 0 ? names.get(0) : ""; //$NON-NLS-1$
+ for (int i = 1; i < names.size(); i++) {
+ name += " & " + names.get(i); //$NON-NLS-1$
+ }
+ return name;
+ }
- protected void recreateChildren() {
+ protected String getItemFullName(RootClass rootClass) {
+ if (rootClass == null) {
+ return ""; //$NON-NLS-1$
+ }
+ String res = rootClass.getEntityName();
+ if (res == null) {
+ res = rootClass.getClassName();
+ }
+ if (res == null) {
+ res = rootClass.getNodeName();
+ }
+ return res;
+ }
+
+ protected String getItemName(String name) {
+ String res = name;
+ return res.substring(res.lastIndexOf(".") + 1); //$NON-NLS-1$
+ }
+
+ protected String getItemName(RootClass rootClass) {
+ return getItemName(getItemFullName(rootClass));
+ }
+
+ public void recreateChildren() {
deleteChildren();
elements.clear();
connections.clear();
final ElementsFactory factory = new ElementsFactory(
- consoleConfig.getConfiguration(), elements, connections);
- for (int i = 0; i < ormElements.length; i++) {
- factory.getOrCreatePersistentClass(ormElements[i], null);
+ getConfig(), elements, connections);
+ for (int i = 0; i < roots.size(); i++) {
+ RootClass rc = roots.get(i);
+ if (rc != null) {
+ factory.getOrCreatePersistentClass(rc, null);
+ }
}
updateChildrenList();
factory.createChildren(this);
updateChildrenList();
+ if (getChildrenNumber() == 0) {
+ addChild(new MessageShape());
+ }
}
protected void updateChildrenList() {
@@ -174,6 +225,7 @@
public IPath getStoreFolderPath() {
IPath storePath = null;
+ ConsoleConfiguration consoleConfig = getConsoleConfig();
IJavaProject javaProject = ProjectUtils.findJavaProject(consoleConfig);
if (javaProject != null && javaProject.getProject() != null) {
storePath = javaProject.getProject().getLocation();
@@ -195,13 +247,13 @@
*/
public String getStoreFileName() {
StringBuilder name = new StringBuilder();
- for (int i = 0; i < ormElements.length; i++) {
+ for (int i = 0; i < entityNames.size(); i++) {
name.append("_"); //$NON-NLS-1$
- name.append(ormElements[i].getNodeName());
+ name.append(getItemName(entityNames.get(i)));
}
- String res = consoleConfig.getName() + name.toString();
+ String res = getConsoleConfigName() + name.toString();
if (res.length() > 64) {
- res = consoleConfig.getName() + "_" + md5sum(name.toString());
//$NON-NLS-1$
+ res = getConsoleConfigName() + "_" + md5sum(name.toString()); //$NON-NLS-1$
}
return res;
}
@@ -241,35 +293,53 @@
}
public RootClass getOrmElement(int idx) {
- if (0 > idx || idx >= ormElements.length) {
+ if (0 > idx || idx >= roots.size()) {
return null;
}
- return ormElements[idx];
+ return roots.get(idx);
}
- public RootClass[] getOrmElements() {
- return ormElements;
+ public boolean refreshRootsFromNames() {
+ final Configuration config = getConfig();
+ if (config == null) {
+ return false;
+ }
+ for (int i = 0; i < roots.size(); i++) {
+ RootClass newOrmElement = (RootClass)config.getClassMapping(entityNames.get(i));
+ if (roots.get(i) == null) {
+ if (newOrmElement == null) {
+ continue;
+ }
+ }
+ else if (roots.get(i).equals(newOrmElement)) {
+ continue;
+ }
+ roots.set(i, newOrmElement);
+ }
+ return true;
}
@Override
public void refresh() {
- final Configuration config = consoleConfig.getConfiguration();
- for (int i = 0; i < ormElements.length; i++) {
- RootClass newOrmElement = (RootClass)config.getClassMapping(entityNames[i]);
- if (ormElements[i].equals(newOrmElement)) {
- continue;
- }
- ormElements[i] = newOrmElement;
- }
+ refreshRootsFromNames();
// -> save just into properties
Properties properties = new Properties();
- saveInProperties(properties);
+ if (memento == null) {
+ saveInProperties(properties);
+ }
recreateChildren();
sortChildren(deepIntoSort);
- // -> load just from properties
- loadFromProperties(properties);
+ if (memento == null) {
+ // -> load just from properties
+ loadFromProperties(properties);
+ } else {
+ loadState(memento);
+ }
refreshDiagramElements();
- updateDirty(true);
+ updateDirty(memento != null ? false : true);
+ if (memento != null && getConsoleConfig() != null) {
+ memento = null;
+ }
super.refresh();
}
@@ -387,58 +457,123 @@
}
}
+ static public String getConsoleConfigName(IMemento memento) {
+ String str = memento.getString("consoleConfig_name"); //$NON-NLS-1$
+ if (str == null) {
+ str = ""; //$NON-NLS-1$
+ }
+ return str;
+ }
+
@Override
+ public void loadState(IMemento memento) {
+ super.loadState(memento);
+ consoleConfigName = getPrValue(memento, "consoleConfig_name", "");
//$NON-NLS-1$ //$NON-NLS-2$
+ @SuppressWarnings("unused")
+ ConsoleConfiguration consoleConfig = getConsoleConfig();
+ labelProvider.setConsoleConfigName(consoleConfigName);
+ int size = getPrValue(memento, "entityNames_size", 0); //$NON-NLS-1$
+ roots.clear();
+ entityNames.clear();
+ for (int i = 0; i < size; i++) {
+ roots.add(null);
+ entityNames.add(getPrValue(memento, "entityNames_" + Integer.toString(i),
"")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ rulersVisibility = getPrValue(memento, "rulersVisibility", false);
//$NON-NLS-1$
+ snapToGeometry = getPrValue(memento, "snapToGeometry", false); //$NON-NLS-1$
+ gridEnabled = getPrValue(memento, "gridEnabled", false); //$NON-NLS-1$
+ zoom = getPrValue(memento, "zoom", 1.0); //$NON-NLS-1$
+ deepIntoSort = getPrValue(memento, "deepIntoSort", false); //$NON-NLS-1$
+ connectionsVisibilityAssociation = getPrValue(memento,
"connectionsVisibilityAssociation", true); //$NON-NLS-1$
+ connectionsVisibilityClassMapping = getPrValue(memento,
"connectionsVisibilityClassMapping", true); //$NON-NLS-1$
+ connectionsVisibilityForeignKeyConstraint = getPrValue(memento,
"connectionsVisibilityForeignKeyConstraint", true); //$NON-NLS-1$
+ connectionsVisibilityPropertyMapping = getPrValue(memento,
"connectionsVisibilityPropertyMapping", true); //$NON-NLS-1$
+ refreshRootsFromNames();
+ }
+
+ @Override
protected void loadFromProperties(Properties properties) {
super.loadFromProperties(properties);
- String str = properties.getProperty("rulersVisibility", "false");
//$NON-NLS-1$ //$NON-NLS-2$
- rulersVisibility = Boolean.valueOf(str).booleanValue();
- str = properties.getProperty("snapToGeometry", "false");
//$NON-NLS-1$ //$NON-NLS-2$
- snapToGeometry = Boolean.valueOf(str).booleanValue();
- str = properties.getProperty("gridEnabled", "false"); //$NON-NLS-1$
//$NON-NLS-2$
- gridEnabled = Boolean.valueOf(str).booleanValue();
- str = properties.getProperty("zoom", "1.0"); //$NON-NLS-1$
//$NON-NLS-2$
- zoom = Double.valueOf(str).doubleValue();
- str = properties.getProperty("deepIntoSort", "false");
//$NON-NLS-1$ //$NON-NLS-2$
- deepIntoSort = Boolean.valueOf(str).booleanValue();
- str = properties.getProperty("connectionsVisibilityAssociation",
"true"); //$NON-NLS-1$ //$NON-NLS-2$
- connectionsVisibilityAssociation = Boolean.valueOf(str).booleanValue();
- str = properties.getProperty("connectionsVisibilityClassMapping",
"true"); //$NON-NLS-1$ //$NON-NLS-2$
- connectionsVisibilityClassMapping = Boolean.valueOf(str).booleanValue();
- str = properties.getProperty("connectionsVisibilityForeignKeyConstraint",
"true"); //$NON-NLS-1$ //$NON-NLS-2$
- connectionsVisibilityForeignKeyConstraint = Boolean.valueOf(str).booleanValue();
- str = properties.getProperty("connectionsVisibilityPropertyMapping",
"true"); //$NON-NLS-1$ //$NON-NLS-2$
- connectionsVisibilityPropertyMapping = Boolean.valueOf(str).booleanValue();
+ consoleConfigName = getPrValue(properties, "consoleConfig_name",
""); //$NON-NLS-1$ //$NON-NLS-2$
+ @SuppressWarnings("unused")
+ ConsoleConfiguration consoleConfig = getConsoleConfig();
+ labelProvider.setConsoleConfigName(consoleConfigName);
+ int size = getPrValue(properties, "entityNames_size", 0); //$NON-NLS-1$
+ roots.clear();
+ entityNames.clear();
+ for (int i = 0; i < size; i++) {
+ roots.add(null);
+ entityNames.add(getPrValue(properties, "entityNames_" + Integer.toString(i),
"")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ rulersVisibility = getPrValue(properties, "rulersVisibility", false);
//$NON-NLS-1$
+ snapToGeometry = getPrValue(properties, "snapToGeometry", false);
//$NON-NLS-1$
+ gridEnabled = getPrValue(properties, "gridEnabled", false); //$NON-NLS-1$
+ zoom = getPrValue(properties, "zoom", 1.0); //$NON-NLS-1$
+ deepIntoSort = getPrValue(properties, "deepIntoSort", false); //$NON-NLS-1$
+ connectionsVisibilityAssociation = getPrValue(properties,
"connectionsVisibilityAssociation", true); //$NON-NLS-1$
+ connectionsVisibilityClassMapping = getPrValue(properties,
"connectionsVisibilityClassMapping", true); //$NON-NLS-1$
+ connectionsVisibilityForeignKeyConstraint = getPrValue(properties,
"connectionsVisibilityForeignKeyConstraint", true); //$NON-NLS-1$
+ connectionsVisibilityPropertyMapping = getPrValue(properties,
"connectionsVisibilityPropertyMapping", true); //$NON-NLS-1$
+ refreshRootsFromNames();
}
@Override
+ public void saveState(IMemento memento) {
+ setPrValue(memento, "consoleConfig_name", consoleConfigName); //$NON-NLS-1$
+ setPrValue(memento, "entityNames_size", "" + entityNames.size());
//$NON-NLS-1$ //$NON-NLS-2$
+ for (int i = 0; i < entityNames.size(); i++) {
+ setPrValue(memento, "entityNames_" + Integer.toString(i), "" +
entityNames.get(i)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ setPrValue(memento, "rulersVisibility", "" + rulersVisibility);
//$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(memento, "snapToGeometry", "" + snapToGeometry);
//$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(memento, "gridEnabled", "" + gridEnabled); //$NON-NLS-1$
//$NON-NLS-2$
+ setPrValue(memento, "zoom", "" + zoom); //$NON-NLS-1$
//$NON-NLS-2$
+ setPrValue(memento, "deepIntoSort", "" + deepIntoSort);
//$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(memento, "connectionsVisibilityAssociation", "" +
connectionsVisibilityAssociation); //$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(memento, "connectionsVisibilityClassMapping", "" +
connectionsVisibilityClassMapping); //$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(memento, "connectionsVisibilityForeignKeyConstraint", ""
+ connectionsVisibilityForeignKeyConstraint); //$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(memento, "connectionsVisibilityPropertyMapping", "" +
connectionsVisibilityPropertyMapping); //$NON-NLS-1$ //$NON-NLS-2$
+ super.saveState(memento);
+ }
+
+ @Override
protected void saveInProperties(Properties properties) {
- properties.put("rulersVisibility", "" + rulersVisibility);
//$NON-NLS-1$ //$NON-NLS-2$
- properties.put("snapToGeometry", "" + snapToGeometry);
//$NON-NLS-1$ //$NON-NLS-2$
- properties.put("gridEnabled", "" + gridEnabled); //$NON-NLS-1$
//$NON-NLS-2$
- properties.put("zoom", "" + zoom); //$NON-NLS-1$ //$NON-NLS-2$
- properties.put("deepIntoSort", "" + deepIntoSort); //$NON-NLS-1$
//$NON-NLS-2$
- properties.put("connectionsVisibilityAssociation", "" +
connectionsVisibilityAssociation); //$NON-NLS-1$ //$NON-NLS-2$
- properties.put("connectionsVisibilityClassMapping", "" +
connectionsVisibilityClassMapping); //$NON-NLS-1$ //$NON-NLS-2$
- properties.put("connectionsVisibilityForeignKeyConstraint", "" +
connectionsVisibilityForeignKeyConstraint); //$NON-NLS-1$ //$NON-NLS-2$
- properties.put("connectionsVisibilityPropertyMapping", "" +
connectionsVisibilityPropertyMapping); //$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(properties, "consoleConfig_name", consoleConfigName);
//$NON-NLS-1$
+ setPrValue(properties, "entityNames_size", "" +
entityNames.size()); //$NON-NLS-1$ //$NON-NLS-2$
+ for (int i = 0; i < entityNames.size(); i++) {
+ setPrValue(properties, "entityNames_" + Integer.toString(i), "" +
entityNames.get(i)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ setPrValue(properties, "rulersVisibility", "" + rulersVisibility);
//$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(properties, "snapToGeometry", "" + snapToGeometry);
//$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(properties, "gridEnabled", "" + gridEnabled);
//$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(properties, "zoom", "" + zoom); //$NON-NLS-1$
//$NON-NLS-2$
+ setPrValue(properties, "deepIntoSort", "" + deepIntoSort);
//$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(properties, "connectionsVisibilityAssociation", "" +
connectionsVisibilityAssociation); //$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(properties, "connectionsVisibilityClassMapping", "" +
connectionsVisibilityClassMapping); //$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(properties, "connectionsVisibilityForeignKeyConstraint",
"" + connectionsVisibilityForeignKeyConstraint); //$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(properties, "connectionsVisibilityPropertyMapping", "" +
connectionsVisibilityPropertyMapping); //$NON-NLS-1$ //$NON-NLS-2$
super.saveInProperties(properties);
}
- public void saveInFile() {
- Properties properties = new Properties();
- saveInProperties(properties);
+ public void saveInFile(IPath path, boolean format) {
FileOutputStream fos = null;
try {
- File folder = new File(getStoreFolderPath().toOSString());
- if (!folder.exists()) {
- folder.mkdirs();
- }
- File file = new File(getStoreFilePath().toOSString());
+ File file = new File(path.toOSString());
if (!file.exists()) {
file.createNewFile();
}
fos = new FileOutputStream(file);
- properties.store(fos, ""); //$NON-NLS-1$
+ if (format) {
+ XMLMemento memento = XMLMemento.createWriteRoot("OrmDiagram");
//$NON-NLS-1$
+ saveState(memento);
+ OutputStreamWriter writer = new OutputStreamWriter(fos, "utf-8");
//$NON-NLS-1$
+ memento.save(writer);
+ writer.close();
+ } else {
+ Properties properties = new Properties();
+ saveInProperties(properties);
+ properties.store(fos, ""); //$NON-NLS-1$
+ }
} catch (IOException e) {
HibernateConsolePlugin.getDefault().logErrorMessage("Can't save layout of
mapping.", e); //$NON-NLS-1$
} finally {
@@ -451,6 +586,22 @@
}
}
}
+
+ public void saveInXmlFile() {
+ File folder = new File(getStoreFolderPath().toOSString());
+ if (!folder.exists()) {
+ folder.mkdirs();
+ }
+ saveInFile(getStoreFilePath(), true);
+ }
+
+ public void saveInFile() {
+ File folder = new File(getStoreFolderPath().toOSString());
+ if (!folder.exists()) {
+ folder.mkdirs();
+ }
+ saveInFile(getStoreFilePath(), false);
+ }
public IFile createLayoutFile(InputStream source) {
IFile file = null;
@@ -470,17 +621,29 @@
return file;
}
- public void loadFromFile() {
+ public void loadFromFile(IPath path, boolean format) {
fileLoadSuccessfull = false;
FileInputStream fis = null;
try {
- File file = new File(getStoreFilePath().toOSString());
+ File file = new File(path.toOSString());
if (file.exists()) {
fis = new FileInputStream(file);
- Properties properties = new Properties();
- properties.load(fis);
- loadFromProperties(properties);
- fileLoadSuccessfull = true;
+ if (format) {
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(fis, "utf-8")); //$NON-NLS-1$
+ try {
+ IMemento memento = XMLMemento.createReadRoot(reader);
+ loadState(memento);
+ fileLoadSuccessfull = true;
+ } catch (WorkbenchException e) {
+ HibernateConsolePlugin.getDefault().logErrorMessage("Can't load layout of
mapping.", e); //$NON-NLS-1$
+ }
+ } else {
+ Properties properties = new Properties();
+ properties.load(fis);
+ loadFromProperties(properties);
+ fileLoadSuccessfull = true;
+ }
}
} catch (IOException ex) {
HibernateConsolePlugin.getDefault().logErrorMessage("Can't load layout of
mapping.", ex); //$NON-NLS-1$
@@ -494,12 +657,47 @@
}
}
}
+
+ public void loadFromXmlFile() {
+ loadFromFile(getStoreFilePath(), true);
+ }
+
+ public void loadFromFile() {
+ loadFromFile(getStoreFilePath(), false);
+ }
public boolean isFileLoadSuccessfull() {
return fileLoadSuccessfull;
}
+ public String getConsoleConfigName() {
+ return consoleConfigName;
+ }
+
+ protected Configuration getConfig() {
+ final ConsoleConfiguration consoleConfig = getConsoleConfig();
+ if (consoleConfig != null) {
+ Configuration config = consoleConfig.getConfiguration();
+ if (config == null) {
+ consoleConfig.build();
+ consoleConfig.execute(new ExecutionContext.Command() {
+ public Object execute() {
+ if (consoleConfig.hasConfiguration()) {
+ consoleConfig.getConfiguration().buildMappings();
+ }
+ return consoleConfig;
+ }
+ } );
+ config = consoleConfig.getConfiguration();
+ }
+ return config;
+ }
+ return null;
+ }
+
public ConsoleConfiguration getConsoleConfig() {
+ final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
+ ConsoleConfiguration consoleConfig = knownConfigurations.find(consoleConfigName);
return consoleConfig;
}
@@ -579,4 +777,48 @@
public void setDeepIntoSort(boolean deepIntoSort) {
this.deepIntoSort = deepIntoSort;
}
+
+ public boolean equals(Object obj) {
+ boolean res = false;
+ if (!(obj instanceof OrmDiagram)) {
+ return res;
+ }
+ final OrmDiagram od = (OrmDiagram)obj;
+ if (consoleConfigName == null) {
+ if (od.getConsoleConfigName() != null) {
+ return res;
+ }
+ } else if (!consoleConfigName.equals(od.getConsoleConfigName())) {
+ return res;
+ }
+ final ArrayList<RootClass> rootsOd = od.roots;
+ if (roots.size() != rootsOd.size()) {
+ return res;
+ }
+ res = true;
+ for (int i = 0; i < roots.size(); i++) {
+ RootClass rc = roots.get(i);
+ if (rc == null) {
+ if (rc != rootsOd.get(i)) {
+ res = false;
+ break;
+ }
+ } else if (!rc.equals(rootsOd.get(i))) {
+ res = false;
+ break;
+ }
+ }
+ return res;
+ }
+
+ public int hashCode() {
+ if (consoleConfigName == null) {
+ return roots.hashCode();
+ }
+ return roots.hashCode() + consoleConfigName.hashCode();
+ }
+
+ public void setMemento(IMemento memento) {
+ this.memento = memento;
+ }
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmShape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmShape.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/OrmShape.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -14,6 +14,7 @@
import java.util.Properties;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.ui.IMemento;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Component;
@@ -248,6 +249,22 @@
verticalGuide = vGuide;
}
+ protected Point getPoint(IMemento memento, String key) {
+ Point point = new Point(0, 0);
+ String str = Utils.getPropertyValue(memento, key + ".x", "0");
//$NON-NLS-1$ //$NON-NLS-2$
+ point.x = Integer.parseInt(str);
+ String str2 = Utils.getPropertyValue(memento, key + ".y", "0");
//$NON-NLS-1$ //$NON-NLS-2$
+ point.y = Integer.parseInt(str2);
+ return point;
+ }
+
+ protected void setPoint(IMemento memento, String key, Point point) {
+ String key1 = key + ".x"; //$NON-NLS-1$
+ memento.putString(key1, "" + point.x); //$NON-NLS-1$
+ String key2 = key + ".y"; //$NON-NLS-1$
+ memento.putString(key2, "" + point.y); //$NON-NLS-1$
+ }
+
protected 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$
@@ -261,19 +278,24 @@
String key1 = key + ".x"; //$NON-NLS-1$
if (!properties.containsKey(key1)) {
properties.remove(key1);
- properties.put(key1, "" + point.x); //$NON-NLS-1$
- } else {
- properties.put(key1, "" + point.x); //$NON-NLS-1$
}
+ 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$
}
+ public void setPosition(IMemento memento) {
+ Point point = getLocation();
+ setPoint(memento, getKey(), point);
+ }
+
+ public Point getPosition(IMemento memento) {
+ return getPoint(memento, getKey());
+ }
+
public void setPosition(Properties properties) {
Point point = getLocation();
setPoint(properties, getKey(), point);
@@ -284,6 +306,13 @@
}
@Override
+ public void loadState(IMemento memento) {
+ super.loadState(memento);
+ Point pos = getPosition(memento);
+ setLocation(pos);
+ }
+
+ @Override
protected void loadFromProperties(Properties properties) {
super.loadFromProperties(properties);
Point pos = getPosition(properties);
@@ -291,6 +320,12 @@
}
@Override
+ public void saveState(IMemento memento) {
+ setPosition(memento);
+ super.saveState(memento);
+ }
+
+ @Override
protected void saveInProperties(Properties properties) {
setPosition(properties);
super.saveInProperties(properties);
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Shape.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Shape.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Shape.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -14,6 +14,7 @@
import java.util.List;
import java.util.Properties;
+import org.eclipse.ui.IMemento;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;
import org.hibernate.mapping.Column;
@@ -31,6 +32,7 @@
public class Shape extends BaseElement {
public static final String SET_FOCUS = "setFocus"; //$NON-NLS-1$
+ public static final String IDENT = "indent"; //$NON-NLS-1$
/**
* left indent for property string on diagram
@@ -212,15 +214,28 @@
}
@Override
+ public void loadState(IMemento memento) {
+ super.loadState(memento);
+ int indentTmp = getPrValue(memento, IDENT, 0);
+ indent = indentTmp;
+ }
+
+ @Override
protected void loadFromProperties(Properties properties) {
super.loadFromProperties(properties);
- String str = properties.getProperty("indent", "0"); //$NON-NLS-1$
//$NON-NLS-2$
- indent = Integer.valueOf(str).intValue();
+ int indentTmp = getPrValue(properties, IDENT, 0);
+ indent = indentTmp;
}
@Override
+ public void saveState(IMemento memento) {
+ setPrValue(memento, IDENT, indent);
+ super.saveState(memento);
+ }
+
+ @Override
protected void saveInProperties(Properties properties) {
- properties.put("indent", "" + indent); //$NON-NLS-1$ //$NON-NLS-2$
+ setPrValue(properties, IDENT, indent);
super.saveInProperties(properties);
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Utils.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Utils.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/model/Utils.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -11,9 +11,12 @@
package org.jboss.tools.hibernate.ui.diagram.editors.model;
import java.util.List;
+import java.util.Properties;
+import org.eclipse.ui.IMemento;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
+import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
/**
@@ -55,12 +58,18 @@
} else if (obj instanceof Property) {
Property property = (Property)obj;
res = property.getPersistentClass().getEntityName() + "." +
property.getName(); //$NON-NLS-1$
+ } else if (obj instanceof SimpleValue) {
+ SimpleValue sv = (SimpleValue)obj;
+ res = getTableName(sv.getTable()) + "." + sv.getForeignKeyName();
//$NON-NLS-1$
} else if (obj instanceof String) {
res = (String)obj;
}
if (res.length() > 0 && res.indexOf(".") < 0) { //$NON-NLS-1$
return "default." + res; //$NON-NLS-1$
}
+ if (res.length() == 0) {
+ res = "null"; //$NON-NLS-1$
+ }
return res;
}
@@ -71,4 +80,87 @@
public static String getTableName(Table table) {
return getTableName(table.getCatalog(), table.getSchema(), table.getName());
}
+
+ ////////////////////////////////////////////
+
+ public static void setPropertyValue(IMemento memento, String key, boolean value) {
+ memento.putString(key, Boolean.valueOf(value).toString());
+ }
+
+ public static boolean getPropertyValue(IMemento memento, String key, boolean def) {
+ String str = memento.getString(key);
+ if (str == null) {
+ str = Boolean.toString(def);
+ }
+ return Boolean.valueOf(str).booleanValue();
+ }
+
+ public static void setPropertyValue(Properties properties, String key, boolean value) {
+ if (properties.containsKey(key)) {
+ properties.remove(key);
+ }
+ properties.put(key, Boolean.valueOf(value).toString());
+ }
+
+ public static boolean getPropertyValue(Properties properties, String key, boolean def)
{
+ String str = properties.getProperty(key, Boolean.toString(def));
+ return Boolean.valueOf(str).booleanValue();
+ }
+
+ ///
+
+ public static double getPropertyValue(IMemento memento, String key, double def) {
+ String str = memento.getString(key);
+ if (str == null) {
+ str = Double.toString(def);
+ }
+ return Double.valueOf(str).doubleValue();
+ }
+
+ public static double getPropertyValue(Properties properties, String key, double def) {
+ String str = properties.getProperty(key, Double.toString(def));
+ return Double.valueOf(str).doubleValue();
+ }
+
+ ///
+
+ public static int getPropertyValue(IMemento memento, String key, int def) {
+ String str = memento.getString(key);
+ if (str == null) {
+ str = Integer.toString(def);
+ }
+ return Integer.valueOf(str).intValue();
+ }
+
+ public static int getPropertyValue(Properties properties, String key, int def) {
+ String str = properties.getProperty(key, Integer.toString(def));
+ return Integer.valueOf(str).intValue();
+ }
+
+ ///
+
+ public static String getPropertyValue(IMemento memento, String key, String def) {
+ String str = memento.getString(key);
+ if (str == null) {
+ str = def;
+ }
+ return str;
+ }
+
+ public static void setPropertyValue(IMemento memento, String key, String value) {
+ memento.putString(key, value);
+ }
+
+ public static String getPropertyValue(Properties properties, String key, String def) {
+ return properties.getProperty(key, def);
+ }
+
+ public static void setPropertyValue(Properties properties, String key, String value) {
+ if (properties.containsKey(key)) {
+ properties.remove(key);
+ }
+ if (value != null) {
+ properties.put(key, value);
+ }
+ }
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/DiagramEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/DiagramEditPart.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/DiagramEditPart.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -146,7 +146,7 @@
Iterator<Shape> it = diagram.getChildrenIterator();
while (it.hasNext()) {
Shape child = it.next();
- if (child.isVisible()) {
+ if (child.isVisible() && (child instanceof OrmShape)) {
IItemInfo item = new DiagramElementInfo((OrmShape)child);
addItem(item);
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmEditPart.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmEditPart.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -193,7 +193,7 @@
public OrmDiagram getOrmDiagram() {
BaseElement modelTmp = (BaseElement)getModel();
OrmDiagram res = modelTmp instanceof OrmDiagram ? (OrmDiagram)modelTmp : null;
- while (modelTmp.getParent() != null) {
+ while (modelTmp != null && modelTmp.getParent() != null) {
modelTmp = modelTmp.getParent();
res = modelTmp instanceof OrmDiagram ? (OrmDiagram)modelTmp : res;
}
@@ -202,6 +202,6 @@
public BaseElement getModelParent() {
BaseElement modelTmp = (BaseElement)getModel();
- return modelTmp.getParent();
+ return modelTmp != null ? modelTmp.getParent() : null;
}
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmEditPartFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmEditPartFactory.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmEditPartFactory.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -16,6 +16,7 @@
import org.jboss.tools.hibernate.ui.diagram.editors.model.ComponentShape;
import org.jboss.tools.hibernate.ui.diagram.editors.model.Connection;
import org.jboss.tools.hibernate.ui.diagram.editors.model.ExpandableShape;
+import org.jboss.tools.hibernate.ui.diagram.editors.model.MessageShape;
import org.jboss.tools.hibernate.ui.diagram.editors.model.OrmDiagram;
import org.jboss.tools.hibernate.ui.diagram.editors.model.OrmShape;
import org.jboss.tools.hibernate.ui.diagram.editors.model.Shape;
@@ -46,6 +47,8 @@
res = new ShapeEditPart();
} else if (baseElement instanceof Connection) {
res = new ConnectionEditPart();
+ } else if (baseElement instanceof MessageShape) {
+ res = new OrmShapeEditPart();
}
if (res == null) {
throw new RuntimeException(
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmShapeEditPart.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/OrmShapeEditPart.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -32,7 +32,7 @@
/**
* @author some modifications from Vitali
*/
-public class OrmShapeEditPart extends ExpandableShapeEditPart{
+public class OrmShapeEditPart extends ExpandableShapeEditPart {
public OrmShape getModelOrmShape() {
return (OrmShape)getModel();
@@ -128,6 +128,8 @@
Integer.parseInt(ColorConstants.Colors_DatabaseColumnR),
Integer.parseInt(ColorConstants.Colors_DatabaseColumnG),
Integer.parseInt(ColorConstants.Colors_DatabaseColumnB)));
+ } else if (element instanceof String) {
+ return ResourceManager.getInstance().getColor(new RGB(0, 0, 0));
} else {
throw new IllegalArgumentException();
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/ShapeEditPart.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/ShapeEditPart.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/parts/ShapeEditPart.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -78,7 +78,8 @@
label.setLabelAlignment(PositionConstants.LEFT);
label.setOpaque(true);
TopLineBorder border = new TopLineBorder(1, 2 + getModelShape().getIndent(), 1, 2);
- border.setColor(getOrmShapeEditPart().getColor());
+ final OrmShapeEditPart osep = getOrmShapeEditPart();
+ border.setColor(osep != null ? osep.getColor() :
ResourceManager.getInstance().getColor(new RGB(0, 0, 0)));
label.setBorder(border);
return label;
}
@@ -283,7 +284,7 @@
protected OrmShapeEditPart getOrmShapeEditPart() {
int i = 0;
EditPart part = this;
- while (!((part instanceof OrmShapeEditPart))) {
+ while (part != null && !(part instanceof OrmShapeEditPart)) {
part = part.getParent();
if (i++ > 4) {
throw new RuntimeException();
Copied:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInput.java
(from rev 17792,
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/ObjectEditorInput.java)
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInput.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInput.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.ui.view;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPersistableElement;
+import org.eclipse.ui.IStorageEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.mapping.RootClass;
+import org.jboss.tools.hibernate.ui.diagram.editors.model.OrmDiagram;
+
+/**
+ *
+ * author: Vitali Yemialyanchyk
+ */
+public class DiagramEditorInput implements IEditorInput, IStorageEditorInput,
IPersistableElement {
+
+ protected OrmDiagram ormDiagram = null;
+ /** The storage object used by this editor input. */
+ private DiagramEditorStorage storage = new DiagramEditorStorage();
+
+ public DiagramEditorInput() {
+ ArrayList<RootClass> roots = new ArrayList<RootClass>();
+ createOrmDiagram("", roots); //$NON-NLS-1$
+ }
+
+ public DiagramEditorInput(FileEditorInput fei) {
+ ArrayList<RootClass> roots = new ArrayList<RootClass>();
+ createOrmDiagram("", roots); //$NON-NLS-1$
+ ormDiagram.loadFromFile(fei.getPath(), true);
+ if (ormDiagram.getConsoleConfig() != null) {
+ ormDiagram.recreateChildren();
+ ormDiagram.loadFromFile(fei.getPath(), true);
+ ormDiagram.refresh();
+ }
+ ormDiagram.setDirty(false);
+ }
+
+ public DiagramEditorInput(String configName, RootClass rc) {
+ ArrayList<RootClass> roots = new ArrayList<RootClass>();
+ roots.add(rc);
+ createOrmDiagram(configName, roots);
+ }
+
+ public DiagramEditorInput(String configName, RootClass[] rcs) {
+ ArrayList<RootClass> roots = new ArrayList<RootClass>();
+ for (int i = 0; i < rcs.length; i++) {
+ roots.add(rcs[i]);
+ }
+ createOrmDiagram(configName, roots);
+ }
+
+ protected void createOrmDiagram(String configName, ArrayList<RootClass> roots) {
+ ormDiagram = new OrmDiagram(configName, roots);
+ }
+
+ public OrmDiagram getOrmDiagram() {
+ return ormDiagram;
+ }
+
+ public ConsoleConfiguration getConsoleConfig() {
+ return getOrmDiagram().getConsoleConfig();
+ }
+
+ public boolean exists() {
+ if (storage != null) {
+ return true;
+ }
+ return false;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return ImageDescriptor.getMissingImageDescriptor();
+ }
+
+ public String getName() {
+ return ormDiagram.getDiagramName();
+ }
+
+ public IPersistableElement getPersistable() {
+ return this;
+ }
+
+ public String getToolTipText() {
+ return getName();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+ public boolean equals(Object obj) {
+ boolean res = false;
+ if (!(obj instanceof DiagramEditorInput)) {
+ return res;
+ }
+ final DiagramEditorInput oei = (DiagramEditorInput)obj;
+ return ormDiagram.equals(oei.ormDiagram);
+ }
+
+ public int hashCode() {
+ return ormDiagram.hashCode();
+ }
+
+ public IStorage getStorage() {
+ return storage;
+ }
+
+ public String getFactoryId() {
+ return DiagramEditorInputFactory.ID_FACTORY;
+ }
+
+ public void saveState(IMemento memento) {
+ ormDiagram.saveState(memento);
+ //DiagramEditorInputFactory.saveState(memento, this);
+ }
+
+
+ public void loadState(final IMemento memento) {
+ ormDiagram.loadState(memento);
+ if (ormDiagram.getConsoleConfig() != null) {
+ //ormDiagram.recreateChildren();
+ //ormDiagram.loadState(memento);
+ ormDiagram.setMemento(memento);
+ ormDiagram.refresh();
+ } else {
+ ormDiagram.setMemento(memento);
+ }
+ ormDiagram.setDirty(false);
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInputFactory.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInputFactory.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInputFactory.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.ui.view;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.IElementFactory;
+import org.eclipse.ui.IMemento;
+
+/**
+ *
+ * author: Vitali Yemialyanchyk
+ */
+public class DiagramEditorInputFactory implements IElementFactory {
+
+ public final static String ID_FACTORY =
"org.jboss.tools.hibernate.ui.view.DiagramEditorInputFactory"; //$NON-NLS-1$
+
+ public IAdaptable createElement(IMemento memento) {
+ DiagramEditorInput hqlStorageInput = new DiagramEditorInput();
+ hqlStorageInput.loadState(memento);
+ IAdaptable input = hqlStorageInput;
+ return input;
+ }
+}
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorStorage.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorStorage.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorStorage.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.hibernate.ui.view;
+
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.jboss.tools.hibernate.ui.diagram.editors.model.OrmDiagram;
+
+/**
+ *
+ * author: Vitali Yemialyanchyk
+ */
+public class DiagramEditorStorage implements IStorage {
+
+ protected OrmDiagram ormDiagram = null;
+
+ public void init(OrmDiagram ormDiagram) {
+ this.ormDiagram = ormDiagram;
+ }
+
+ public InputStream getContents() throws CoreException {
+ if (ormDiagram == null) {
+ return null;
+ }
+ return null;
+ }
+
+ public IPath getFullPath() {
+ if (ormDiagram == null) {
+ return null;
+ }
+ return ormDiagram.getStoreFilePath();
+ }
+
+ public String getName() {
+ if (ormDiagram == null) {
+ return null;
+ }
+ return ormDiagram.getDiagramName();
+ }
+
+ public boolean isReadOnly() {
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object getAdapter(Class adapter) {
+ return null;
+ }
+
+}
Deleted:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/ObjectEditorInput.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/ObjectEditorInput.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/ObjectEditorInput.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2009 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.hibernate.ui.view;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-import org.hibernate.console.ConsoleConfiguration;
-import org.hibernate.mapping.RootClass;
-
-/**
- *
- * author: ?
- * author: Vitali Yemialyanchyk
- */
-public class ObjectEditorInput implements IEditorInput{
-
- protected ArrayList<RootClass> roots;
- protected ConsoleConfiguration configuration;
-
- public ObjectEditorInput(ConsoleConfiguration configuration, RootClass rc) {
- roots = new ArrayList<RootClass>();
- roots.add(rc);
- this.configuration = configuration;
- }
-
- public ObjectEditorInput(ConsoleConfiguration configuration, RootClass[] rcs) {
- roots = new ArrayList<RootClass>();
- for (int i = 0; i < rcs.length; i++) {
- roots.add(rcs[i]);
- }
- Collections.sort(roots, new RootClassComparator());
- this.configuration = configuration;
- }
-
- public class RootClassComparator implements Comparator<RootClass> {
- public int compare(RootClass o1, RootClass o2) {
- return getItemName(o1).compareTo(getItemName(o2));
- }
- }
-
- public boolean exists() {
- return false;
- }
-
- public ArrayList<RootClass> getRootClasses() {
- return roots;
- }
-
- public ImageDescriptor getImageDescriptor() {
- return ImageDescriptor.getMissingImageDescriptor();
- }
-
- public String getName() {
- return getDiagramName();
- }
-
- public String getDiagramName() {
- String name = ""; //$NON-NLS-1$
- ArrayList<String> names = new ArrayList<String>();
- for (int i = 0; i < roots.size(); i++) {
- names.add(getItemName(roots.get(i)));
- }
- // sort to get same name for same combinations of entities
- Collections.sort(names);
- name = names.size() > 0 ? names.get(0) : ""; //$NON-NLS-1$
- for (int i = 1; i < names.size(); i++) {
- name += " & " + names.get(i); //$NON-NLS-1$
- }
- return name;
- }
-
- protected String getItemName(RootClass rootClass) {
- String res = rootClass.getEntityName();
- if (res == null) {
- res = rootClass.getClassName();
- }
- if (res == null) {
- res = rootClass.getNodeName();
- }
- res = res.substring(res.lastIndexOf(".") + 1); //$NON-NLS-1$
- return res;
- }
-
- public IPersistableElement getPersistable() {
- return null;
- }
-
-
- public String getToolTipText() {
- return ""; //$NON-NLS-1$
- }
-
-
- @SuppressWarnings("unchecked")
- public Object getAdapter(Class adapter) {
- return null;
- }
-
- public ConsoleConfiguration getConfiguration() {
- return configuration;
- }
-
- public boolean equals(Object obj) {
- boolean res = false;
- if (!(obj instanceof ObjectEditorInput)) {
- return res;
- }
- final ObjectEditorInput oei = (ObjectEditorInput)obj;
- if (!configuration.equals(oei.getConfiguration())) {
- return res;
- }
- final ArrayList<RootClass> rootsOei = oei.getRootClasses();
- if (roots.size() != rootsOei.size()) {
- return res;
- }
- res = true;
- for (int i = 0; i < roots.size(); i++) {
- if (!roots.get(i).equals(rootsOei.get(i))) {
- res = false;
- break;
- }
- }
- return res;
- }
-
- public int hashCode() {
- return roots.hashCode() + configuration.hashCode();
- }
-}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OpenDiagramActionDelegate.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OpenDiagramActionDelegate.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OpenDiagramActionDelegate.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -104,12 +104,12 @@
}
public IEditorPart openEditor(PersistentClass persClass,
- ConsoleConfiguration consoleConfiguration) throws PartInitException {
- ObjectEditorInput input = new ObjectEditorInput(consoleConfiguration,
persClass.getRootClass());
+ ConsoleConfiguration consoleConfig) throws PartInitException {
+ DiagramEditorInput input = new DiagramEditorInput(consoleConfig.getName(),
persClass.getRootClass());
return IDE.openEditor(UiPlugin.getPage(), input,
"org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer"); //$NON-NLS-1$
}
- public IEditorPart openEditor(Set<PersistentClass> setPC, ConsoleConfiguration
consoleConfiguration) throws PartInitException {
+ public IEditorPart openEditor(Set<PersistentClass> setPC, ConsoleConfiguration
consoleConfig) throws PartInitException {
if (setPC.size() <= 0) {
return null;
@@ -121,7 +121,7 @@
persClass = it.next();
rcArr[i++] = persClass.getRootClass();
}
- ObjectEditorInput input = new ObjectEditorInput(consoleConfiguration, rcArr);
+ DiagramEditorInput input = new DiagramEditorInput(consoleConfig.getName(), rcArr);
return IDE.openEditor(UiPlugin.getPage(), input,
"org.jboss.tools.hibernate.ui.diagram.editors.DiagramViewer"); //$NON-NLS-1$
}
}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmImageMap.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmImageMap.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmImageMap.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -55,6 +55,8 @@
imageName = getImageName((SimpleValue)obj);
} else if (obj instanceof PersistentClass) {
imageName = getImageName((PersistentClass)obj);
+ } else if (obj instanceof String) {
+ imageName = "Image_Error"; //$NON-NLS-1$;
}
return UiPlugin.getImageDescriptor("images/" +
ImageBundle.getString(imageName)); //$NON-NLS-1$
}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelProvider.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/OrmLabelProvider.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -26,6 +26,9 @@
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.execution.ExecutionContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.eclipse.console.HibernateConsolePlugin;
import org.hibernate.engine.Mapping;
@@ -40,27 +43,54 @@
private Map<ImageDescriptor, Image> imageCache = new HashMap<ImageDescriptor,
Image>(25);
- protected Configuration config = null;
+ protected String consoleConfigName;
protected Mapping mapping = null;
protected Dialect dialect = null;
public OrmLabelProvider() {
}
- public OrmLabelProvider(Configuration config) {
+ public OrmLabelProvider(String consoleConfigName) {
super();
- setConfig(config);
+ setConsoleConfigName(consoleConfigName);
}
- public void setConfig(Configuration config) {
- if (this.config == config) {
+ public void setConsoleConfigName(String consoleConfigName) {
+ if (this.consoleConfigName == consoleConfigName) {
return;
}
- this.config = config;
+ this.consoleConfigName = consoleConfigName;
mapping = null;
dialect = null;
}
+ protected Configuration getConfig() {
+ final ConsoleConfiguration consoleConfig = getConsoleConfig();
+ if (consoleConfig != null) {
+ Configuration config = consoleConfig.getConfiguration();
+ if (config == null) {
+ consoleConfig.build();
+ consoleConfig.execute(new ExecutionContext.Command() {
+ public Object execute() {
+ if (consoleConfig.hasConfiguration()) {
+ consoleConfig.getConfiguration().buildMappings();
+ }
+ return consoleConfig;
+ }
+ } );
+ config = consoleConfig.getConfiguration();
+ }
+ return config;
+ }
+ return null;
+ }
+
+ protected ConsoleConfiguration getConsoleConfig() {
+ final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
+ ConsoleConfiguration consoleConfig = knownConfigurations.find(consoleConfigName);
+ return consoleConfig;
+ }
+
@Override
public Image getImage(Object element) {
ImageDescriptor descriptor = OrmImageMap.getImageDescriptor(element);
@@ -118,10 +148,11 @@
if (sqlType != null) {
return false;
}
- if (mapping == null) {
+ final Configuration config = getConfig();
+ if (mapping == null && config != null) {
mapping = config.buildMapping();
}
- if (dialect == null) {
+ if (dialect == null && config != null) {
final String dialectName = config.getProperty(Environment.DIALECT);
if (dialectName != null) {
try {
Modified:
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.test/src/org/jboss/tools/hibernate/ui/diagram/editors/model/test/OrmDiagramTest.java
===================================================================
---
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.test/src/org/jboss/tools/hibernate/ui/diagram/editors/model/test/OrmDiagramTest.java 2009-10-07
10:14:09 UTC (rev 17952)
+++
trunk/hibernatetools/tests/org.jboss.tools.hibernate.ui.test/src/org/jboss/tools/hibernate/ui/diagram/editors/model/test/OrmDiagramTest.java 2009-10-07
11:21:00 UTC (rev 17953)
@@ -43,6 +43,8 @@
final ConsoleConfiguration consoleConfig = context.mock(ConsoleConfiguration.class);
final Configuration config = context.mock(Configuration.class);
final RootClass ioe = context.mock(RootClass.class);
+ ArrayList<RootClass> rts = new ArrayList<RootClass>();
+ rts.add(ioe);
final List<Object> emptyList = new ArrayList<Object>();
final Iterator<Object> emptyListIterator = emptyList.iterator();
@@ -94,7 +96,11 @@
will(returnValue("")); //$NON-NLS-1$
}
});
- final OrmDiagram ormDiagram = new OrmDiagram(consoleConfig, ioe);
+ final OrmDiagram ormDiagram = new OrmDiagram("", rts) { //$NON-NLS-1$
+ public ConsoleConfiguration getConsoleConfig() {
+ return consoleConfig;
+ }
+ };
ormDiagram.saveInFile();
// test is the folder created
File folder = new File(ormDiagram.getStoreFolderPath().toOSString());