/hg/icedtea-web: PolicyEditor fixes for Save As
aazores at icedtea.classpath.org
aazores at icedtea.classpath.org
Thu May 22 19:45:54 UTC 2014
changeset 4e236cc7181c in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=4e236cc7181c
author: Andrew Azores <aazores at redhat.com>
date: Thu May 22 15:45:37 2014 -0400
PolicyEditor fixes for Save As
PolicyEditor can be made to Save As to a different file than the current file,
without extra changes having to be made first in the editor. Additionally,
if the file is deleted from the disk by another process, PolicyEditor will
save over the file rather than again requiring the user make changes.
2014-05-22 Jie Kang <jkang at redhat.com>
* netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
(saveAsButtonAction): set changesMade to true to allow savePolicyFile to save
(savePolicyFile): no longer immediately returns if changesMade is false
(updateMd5WithDialog): use changesMade along with file MD5 sum changes to
determine whether to continue saving to disk, added check for FileNotFound and
displays warning message telling user what has happened, also privatized
method and renamed method to checkPolicyChangesWithDialog
* netx/net/sourceforge/jnlp/util/MD5SumWatcher.java: Removed unused imports.
* netx/net/sourceforge/jnlp/resources/Message.properties (PEFileMissing): Added
new warning message for PolicyEditor
diffstat:
ChangeLog | 13 ++++
netx/net/sourceforge/jnlp/resources/Messages.properties | 1 +
netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java | 27 ++++++---
netx/net/sourceforge/jnlp/util/MD5SumWatcher.java | 5 -
4 files changed, 32 insertions(+), 14 deletions(-)
diffs (118 lines):
diff -r 0c7dcde1cfe0 -r 4e236cc7181c ChangeLog
--- a/ChangeLog Thu May 22 18:30:41 2014 +0200
+++ b/ChangeLog Thu May 22 15:45:37 2014 -0400
@@ -1,3 +1,16 @@
+2014-05-22 Jie Kang <jkang at redhat.com>
+
+ * netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
+ (saveAsButtonAction): set changesMade to true to allow savePolicyFile to save
+ (savePolicyFile): no longer immediately returns if changesMade is false
+ (updateMd5WithDialog): use changesMade along with file MD5 sum changes to
+ determine whether to continue saving to disk, added check for FileNotFound and
+ displays warning message telling user what has happened, also privatized
+ method and renamed method to checkPolicyChangesWithDialog
+ * netx/net/sourceforge/jnlp/util/MD5SumWatcher.java: Removed unused imports.
+ * netx/net/sourceforge/jnlp/resources/Message.properties (PEFileMissing): Added
+ new warning message for PolicyEditor
+
2014-05-21 Jiri Vanek <jvanek at redhat.com>
Fixed slipped test classlaoder fix
diff -r 0c7dcde1cfe0 -r 4e236cc7181c netx/net/sourceforge/jnlp/resources/Messages.properties
--- a/netx/net/sourceforge/jnlp/resources/Messages.properties Thu May 22 18:30:41 2014 +0200
+++ b/netx/net/sourceforge/jnlp/resources/Messages.properties Thu May 22 15:45:37 2014 -0400
@@ -574,6 +574,7 @@
PECustomPermissionsItem=Custom Permissions...
PEFileModified=File Modification Warning
PEFileModifiedDetail=The policy file at {0} has been modified since it was opened. Reload and re-edit before saving?
+PEFileMissing=The policy file was missing from disk. A new file has been saved with the same name.
PEGAccesUnowenedCode = Execute unowned code
PEGMediaAccess = Media access
PEGrightClick = right click to fold/unfold
diff -r 0c7dcde1cfe0 -r 4e236cc7181c netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java
--- a/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Thu May 22 18:30:41 2014 +0200
+++ b/netx/net/sourceforge/jnlp/security/policyeditor/PolicyEditor.java Thu May 22 15:45:37 2014 -0400
@@ -312,6 +312,7 @@
final int choice = fileChooser.showSaveDialog(weakThis.get());
if (choice == JFileChooser.APPROVE_OPTION) {
file = fileChooser.getSelectedFile();
+ changesMade = true;
savePolicyFile();
}
}
@@ -1276,14 +1277,11 @@
* Save the policy model into the file pointed to by the filePath field.
*/
private void savePolicyFile() {
- if (!changesMade) {
- return;
- }
new Thread() {
@Override
public void run() {
try {
- final int response = updateMd5WithDialog();
+ final int response = checkPolicyChangesWithDialog();
switch (response) {
case JOptionPane.YES_OPTION:
openAndParsePolicyFile();
@@ -1377,22 +1375,33 @@
}
/**
- * Detect if the file's MD5 has changed. If so, track its new sum, and prompt the user on how to proceed
- * @return the user's choice (Yes/No/Cancel - see JOptionPane constants). "No" if the file hasn't changed.
- * @throws FileNotFoundException if the watched file does not exist
+ * Detect if the policy settings have changed, either on-disk or in-app.
+ * If an on-disk change has occurred, update the Md5.
+ * @return The user's choice (Yes/No/Cancel - see JOptionPane constants).
+ * "Cancel" if the file hasn't changed but the user has made modifications
+ * to the settings. "No" otherwise
* @throws IOException if the file cannot be read
*/
- public int updateMd5WithDialog() throws FileNotFoundException, IOException {
+ private int checkPolicyChangesWithDialog() throws IOException {
if (fileWatcher == null) {
if (file != null) {
fileWatcher = new MD5SumWatcher(file);
}
return JOptionPane.NO_OPTION;
}
- final boolean changed = fileWatcher.update();
+ boolean changed;
+ try {
+ changed = fileWatcher.update();
+ } catch (FileNotFoundException e){
+ JOptionPane.showMessageDialog(weakThis.get(), R("PEFileMissing"), R("PEFileModified"), JOptionPane.WARNING_MESSAGE);
+ return JOptionPane.NO_OPTION;
+ }
if (changed) {
return JOptionPane.showConfirmDialog(weakThis.get(), R("PEFileModifiedDetail", file.getCanonicalPath()),
R("PEFileModified"), JOptionPane.YES_NO_CANCEL_OPTION);
+ } else if (!changesMade) {
+ //Return without saving or reloading
+ return JOptionPane.CANCEL_OPTION;
}
return JOptionPane.NO_OPTION;
}
diff -r 0c7dcde1cfe0 -r 4e236cc7181c netx/net/sourceforge/jnlp/util/MD5SumWatcher.java
--- a/netx/net/sourceforge/jnlp/util/MD5SumWatcher.java Thu May 22 18:30:41 2014 +0200
+++ b/netx/net/sourceforge/jnlp/util/MD5SumWatcher.java Thu May 22 15:45:37 2014 -0400
@@ -36,17 +36,12 @@
package net.sourceforge.jnlp.util;
-import static net.sourceforge.jnlp.runtime.Translator.R;
-
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
-import javax.swing.JFrame;
-import javax.swing.JOptionPane;
-
import net.sourceforge.jnlp.util.logging.OutputController;
public class MD5SumWatcher {
More information about the distro-pkg-dev
mailing list