/**
- * @author kman
+ * A dialog for requesting confirmation from the user.
*
+ * @author kman
*/
public abstract class ConfirmationDialog extends DialogBox {
/**
* The widget's constructor.
+ *
* @param images the supplied images
+ * @param message the message to display
+ * @param buttonLabel the label of the confirmation button
*/
- public ConfirmationDialog(final Images images, String message) {
- // Use this opportunity to set the dialog's caption.
- setText("Update File Warning");
+ public ConfirmationDialog(Images images, String message, String buttonLabel) {
+ // Set the dialog's caption.
+ setText("Confirmation");
setAnimationEnabled(true);
- // Create a VerticalPanel to contain the 'about' label and the 'OK'
- // button.
- final VerticalPanel outer = new VerticalPanel();
- final HorizontalPanel buttons = new HorizontalPanel();
+ // Create a VerticalPanel to contain the label and the buttons.
+ VerticalPanel outer = new VerticalPanel();
+ HorizontalPanel buttons = new HorizontalPanel();
- // Create the 'about' text and set a style name so we can style it with
- // CSS.
- final HTML text = new HTML("<table><tr><td rowspan='2'>" + images.warn().getHTML() +
+ HTML text = new HTML("<table><tr><td rowspan='2'>" + images.warn().getHTML() +
"</td><td>" + message + "</td></tr></table>");
text.setStyleName("gss-warnMessage");
outer.add(text);
- // Create the 'Quit' button, along with a listener that hides the dialog
- // when the button is clicked and quits the application.
- final Button ok = new Button("Update File", new ClickListener() {
+ // Create the 'Update' button, along with a listener that hides the dialog
+ // when the button is clicked and renames the file.
+ Button ok = new Button(buttonLabel, new ClickListener() {
public void onClick(Widget sender) {
confirm();
buttons.add(ok);
buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);
// Create the 'Cancel' button, along with a listener that hides the
- // dialog
- // when the button is clicked.
- final Button cancel = new Button("Cancel", new ClickListener() {
+ // dialog when the button is clicked.
+ Button cancel = new Button("Cancel", new ClickListener() {
public void onClick(Widget sender) {
hide();
setWidget(outer);
}
-
-
- /*
- * (non-Javadoc)
- *
- * @see com.google.gwt.user.client.ui.PopupPanel#onKeyDownPreview(char, int)
- */
+ @Override
public boolean onKeyDownPreview(final char key, final int modifiers) {
// Use the popup's key preview hooks to close the dialog when either
// enter or escape is pressed.
cancel();
break;
}
-
return true;
}
\r
/**\r
* The widget's constructor.\r
+ * @param _images\r
* @param _files\r
*/\r
public FileUploadDialog(final Images _images, List<FileResource> _files) {\r
else {\r
final FileResource sameFile = same;\r
GWT.log("Same deleted file", null);\r
- ConfirmationDialog confirm = new ConfirmationDialog(images,"A file with the same name exists in trash. <br/>if you continue trashed file "+fname+" will be renamed?"){\r
-\r
+ ConfirmationDialog confirm = new ConfirmationDialog(images, "A file with " +\r
+ "the same name exists in the trash. If you continue,<br/>the trashed " +\r
+ "file '" + fname + "' will be renamed automatically for you.", "Continue"){\r
\r
+ @Override\r
public void cancel() {\r
FileUploadDialog.this.hide();\r
}\r
\r
-\r
+ @Override\r
public void confirm() {\r
updateTrashedFile(getBackupFilename(fname), sameFile);\r
}\r
\r
};\r
confirm.center();\r
-\r
-\r
}\r
}\r
else {\r
- //we are going to update an existing file so show a confirmation dialog\r
- ConfirmationDialog confirm = new ConfirmationDialog(images,"Are you sure you want to update "+fname+"?"){\r
-\r
+ // We are going to update an existing file, so show a confirmation dialog.\r
+ ConfirmationDialog confirm = new ConfirmationDialog(images, "Are you sure " +\r
+ "you want to update " + fname + "?", "Update"){\r
\r
+ @Override\r
public void cancel() {\r
FileUploadDialog.this.hide();\r
}\r
\r
-\r
+ @Override\r
public void confirm() {\r
form.submit();\r
}\r
confirm.center();\r
}\r
}\r
+\r
/**\r
* Returns the file name from a potential full path argument. Apparently IE\r
* insists on sending the full path name of a file when uploading, forcing\r
return name.substring(pathSepIndex + 1);\r
}\r
\r
- // Check whether the file name exists in selected folder\r
+ /**\r
+ * Check whether the file name exists in selected folder.\r
+ *\r
+ * @return\r
+ */\r
private boolean canContinue() {\r
if (files == null)\r
return false;\r
String fileName = getFilename(upload.getFilename());\r
if (getFileForName(fileName) == null) {\r
- // file creation so check to see if file already exists\r
+ // For file creation, check to see if the file already exists.\r
GWT.log("filename to upload:" + fileName, null);\r
for (FileResource dto : files) {\r
GWT.log("Check:" + dto.getName() + "/" + fileName, null);\r
}\r
}\r
}\r
-\r
- /*\r
- Object selection = GSS.get().getFolders().getCurrent().getUserObject();\r
-\r
- FolderResource folder = (FolderResource) selection;\r
- for (FolderResource dto : folder.get())\r
- if (dto.getName().equals(fileName)) {\r
- cancelEvent = true;\r
- return true;\r
- }\r
- */\r
return true;\r
}\r
\r
apath = apath + URL.encodeComponent(fileNameToUse) + "?progress=" + fileNameToUse;\r
ExecuteGet eg = new ExecuteGet<UploadStatusResource>(UploadStatusResource.class, apath, false) {\r
\r
+ @Override\r
public void onComplete() {\r
UploadStatusResource res = getResult();\r
progressBar.setProgress(res.percent());\r
}\r
\r
+ @Override\r
public void onError(Throwable t) {\r
GWT.log("", t);\r
\r
\r
};\r
DeferredCommand.addCommand(eg);\r
-\r
}\r
\r
private String getBackupFilename(String filename) {\r
if (deleted.isDeleted())\r
filesInSameFolder.add(deleted);\r
int i = 1;\r
- String filenameToCheck = filename;\r
for (FileResource same : filesInSameFolder)\r
if (same.getName().startsWith(filename)) {\r
String toCheck = same.getName().substring(filename.length(), same.getName().length());\r
try {\r
test = Integer.valueOf(toCheck.replace(" ", ""));\r
} catch (NumberFormatException e) {\r
- //do nothing since string is not a number\r
+ // Do nothing since string is not a number.\r
}\r
if (test >= i)\r
i = test + 1;\r
json.put("name", new JSONString(newName));\r
ExecutePost cf = new ExecutePost(trashedFile.getPath() + "?update=", json.toString(), 200) {\r
\r
+ @Override\r
public void onComplete() {\r
form.submit();\r
}\r
\r
+ @Override\r
public void onError(Throwable t) {\r
GWT.log("", t);\r
if (t instanceof RestException) {\r
if (!f.isDeleted() && f.getName().equals(name))\r
return f;\r
return null;\r
-\r
}\r
}\r