You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2017/06/30 14:54:05 UTC

cayenne git commit: CAY-2323 Graph. No warning while saving the image with existing name

Repository: cayenne
Updated Branches:
  refs/heads/STABLE-4.0 99dcc1a64 -> 30a244bc7


CAY-2323 Graph. No warning while saving the image with existing name


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/30a244bc
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/30a244bc
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/30a244bc

Branch: refs/heads/STABLE-4.0
Commit: 30a244bc768186231c4b4367acd29aee0de3904f
Parents: 99dcc1a
Author: Nikita Timofeev <st...@gmail.com>
Authored: Fri Jun 30 17:53:59 2017 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Fri Jun 30 17:53:59 2017 +0300

----------------------------------------------------------------------
 .../modeler/graph/action/SaveAsImageAction.java     | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/30a244bc/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/SaveAsImageAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/SaveAsImageAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/SaveAsImageAction.java
index d9e85dc..73f56ac 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/SaveAsImageAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/action/SaveAsImageAction.java
@@ -20,6 +20,7 @@ package org.apache.cayenne.modeler.graph.action;
 
 import java.awt.event.ActionEvent;
 import java.awt.image.BufferedImage;
+import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
@@ -80,12 +81,23 @@ public class SaveAsImageAction extends CayenneAction {
 				path += "." + ext;
 			}
 
-			try {
+			File file = new File(path);
 
+			try {
 				JGraph graph = dataDomainGraphTab.getGraph();
 				BufferedImage img = graph.getImage(null, 0);
 
-				try (OutputStream out = new FileOutputStream(path);) {
+				if (file.exists()) {
+					int response = JOptionPane.showConfirmDialog(null,
+							"Do you want to replace the existing file?",
+							"Confirm", JOptionPane.YES_NO_OPTION,
+							JOptionPane.QUESTION_MESSAGE);
+					if (response != JOptionPane.YES_OPTION) {
+						return;
+					}
+				}
+
+				try (OutputStream out = new FileOutputStream(file)) {
 					ImageIO.write(img, ext, out);
 					out.flush();
 				}