Author: vyemialyanchyk
Date: 2009-10-22 07:42:04 -0400 (Thu, 22 Oct 2009)
New Revision: 18230
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/actions/ExportImageAction.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInput.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5076 - fix
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-22
10:22:30 UTC (rev 18229)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/DiagramViewer.java 2009-10-22
11:42:04 UTC (rev 18230)
@@ -111,7 +111,7 @@
public void doSaveAs() {
SaveAsDialog saveAsDialog = new
SaveAsDialog(getSite().getWorkbenchWindow().getShell());
- saveAsDialog.setOriginalName(getDiagramName());
+ saveAsDialog.setOriginalName(getStoreFileName());
saveAsDialog.open();
final IPath pathSave = saveAsDialog.getResult();
if (pathSave == null) {
@@ -313,14 +313,21 @@
}
public String getDiagramName() {
- IEditorInput input = getEditorInput();
- if (input instanceof DiagramEditorInput) {
- DiagramEditorInput objectEditorInput = (DiagramEditorInput)input;
- return objectEditorInput.getName();
+ DiagramEditorInput diagramInput = getDiagramInput();
+ if (diagramInput != null) {
+ return diagramInput.getName();
}
return ""; //$NON-NLS-1$
}
+ public String getStoreFileName() {
+ DiagramEditorInput diagramInput = getDiagramInput();
+ if (diagramInput != null) {
+ return diagramInput.getStoreFileName();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
public void refresh() {
getOrmDiagram().refresh();
setPartName(DiagramViewerMessages.DiagramViewer_diagram_for + " " +
getDiagramInput().getName()); //$NON-NLS-1$
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExportImageAction.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExportImageAction.java 2009-10-22
10:22:30 UTC (rev 18229)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/diagram/editors/actions/ExportImageAction.java 2009-10-22
11:42:04 UTC (rev 18230)
@@ -10,13 +10,14 @@
******************************************************************************/
package org.jboss.tools.hibernate.ui.diagram.editors.actions;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
-import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.Graphics;
@@ -81,18 +82,17 @@
saveDialog = new
SaveAsDialog(getDiagramViewer().getSite().getWorkbenchWindow().getShell());
createdSaveDialog = true;
}
- saveDialog.setOriginalName(getDiagramViewer().getDiagramName());
+ saveDialog.setOriginalName(getDiagramViewer().getStoreFileName());
saveDialog.open();
- final IPath pathSave = saveDialog.getResult();
+ final IPath pathSave = saveDialog.getResult();
+ saveDialog = null;
if (pathSave == null) {
return;
}
-
final IFigure fig = ((ScalableFreeformRootEditPart) getDiagramViewer()
.getEditPartViewer().getRootEditPart())
.getLayer(LayerConstants.PRINTABLE_LAYERS);
int imageTypeTmp = SWT.IMAGE_BMP;
- IWorkspace workspace = ResourcesPlugin.getWorkspace();
String ext = pathSave.getFileExtension();
if (ext != null) {
ext = ext.toLowerCase();
@@ -106,23 +106,31 @@
imageTypeTmp = SWT.IMAGE_BMP;
}
}
- IPath pathTmp = workspace.getRoot().getFullPath().append(pathSave);
- pathTmp = workspace.getRoot().getLocation().append(pathTmp);
+ IPath pathTmp = pathSave;
if (ext == null) {
pathTmp = pathTmp.addFileExtension("bmp"); //$NON-NLS-1$
}
final IPath path = pathTmp;
final int imageType = imageTypeTmp;
+
+ final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
WorkspaceModifyOperation op = new WorkspaceModifyOperation() {
public void execute(final IProgressMonitor monitor) {
- FileOutputStream outStream = null;
+ ByteArrayInputStream inputStream = null;
try {
- byte[] imageData = createImage(fig, imageType);
- outStream = new FileOutputStream(path.toString());
- outStream.write(imageData);
- outStream.flush();
- } catch (IOException e) {
+ if (file != null) {
+ byte[] imageData = createImage(fig, imageType);
+ if (file.exists()) {
+ file.delete(true, null);
+ }
+ if (!file.exists()) {
+ inputStream = new ByteArrayInputStream(imageData);
+ file.create(inputStream, true, null);
+ }
+ }
+
+ } catch (CoreException e) {
HibernateConsolePlugin.getDefault().logErrorMessage("ExportImageAction",
e); //$NON-NLS-1$
if (showErrDialog) {
MessageDialog.openInformation(getDiagramViewer().getSite().getShell(),
@@ -130,9 +138,9 @@
}
}
finally {
- if (outStream != null) {
+ if (inputStream != null) {
try {
- outStream.close();
+ inputStream.close();
} catch (IOException e) {
// ignore
}
Modified:
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/DiagramEditorInput.java 2009-10-22
10:22:30 UTC (rev 18229)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.ui/src/org/jboss/tools/hibernate/ui/view/DiagramEditorInput.java 2009-10-22
11:42:04 UTC (rev 18230)
@@ -91,6 +91,10 @@
return ormDiagram.getDiagramName();
}
+ public String getStoreFileName() {
+ return ormDiagram.getStoreFileName();
+ }
+
public IPersistableElement getPersistable() {
return this;
}