*/\r
package gr.ebs.gss.client;\r
\r
-import gr.ebs.gss.client.FileMenu.Images;\r
import gr.ebs.gss.client.rest.GetCommand;\r
import gr.ebs.gss.client.rest.PostCommand;\r
import gr.ebs.gss.client.rest.RestCommand;\r
import com.google.gwt.user.client.ui.FormSubmitCompleteEvent;\r
import com.google.gwt.user.client.ui.FormSubmitEvent;\r
import com.google.gwt.user.client.ui.Grid;\r
+import com.google.gwt.user.client.ui.HTML;\r
import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
import com.google.gwt.user.client.ui.Hidden;\r
import com.google.gwt.user.client.ui.HorizontalPanel;\r
*/\r
public class FileUploadDialog extends DialogBox implements Updateable {\r
\r
- private int prgBarInterval = 1500;\r
+ protected int prgBarInterval = 1500;\r
\r
private ProgressBar progressBar;\r
\r
- private RepeatingTimer repeater = new RepeatingTimer(this, prgBarInterval);\r
+ protected RepeatingTimer repeater = new RepeatingTimer(this, prgBarInterval);\r
\r
public static final boolean DONE = true;\r
\r
/**\r
* The Form element that performs the file upload.\r
*/\r
- final FormPanel form = new FormPanel();\r
+ private final FormPanel form = new FormPanel();\r
\r
- final FileUpload upload = new FileUpload();\r
+ private final FileUpload upload = new FileUpload();\r
\r
- final Label filenameLabel = new Label("");\r
+ protected final Label filenameLabel = new Label("");\r
\r
- private List<FileResource> files;\r
+ protected List<FileResource> files;\r
\r
- boolean cancelEvent = false;\r
+ protected boolean cancelEvent = false;\r
\r
- private String fileNameToUse;\r
+ protected String fileNameToUse;\r
\r
- final FolderResource folder;\r
- final Images images;\r
+ protected FolderResource folder;\r
\r
/**\r
* The widget's constructor.\r
- * @param _images\r
- * @param _files\r
*/\r
- public FileUploadDialog(final Images _images, List<FileResource> _files) {\r
- images = _images;\r
- files = _files;\r
+ public FileUploadDialog() {\r
// Set the dialog's caption.\r
setText("File upload");\r
setAnimationEnabled(true);\r
// Create a panel to hold all of the form widgets.\r
VerticalPanel panel = new VerticalPanel();\r
form.setWidget(panel);\r
+ final HTML info = new HTML("You may select a file to upload. Install" +\r
+ " <a href='http://gears.google.com/' target='_blank'>Google " +\r
+ "Gears</a><br> for uploading multiple files simultaneously.");\r
+ info.addStyleName("gss-uploadNote");\r
+ panel.add(info);\r
final Hidden date = new Hidden("Date", "");\r
panel.add(date);\r
final Hidden auth = new Hidden("Authorization", "");\r
return true;\r
}\r
\r
-\r
- public void prepareAndSubmit(){\r
+ /**\r
+ * Make any last minute checks and start the upload.\r
+ */\r
+ public void prepareAndSubmit() {\r
final String fname = getFilename(upload.getFilename());\r
if (getFileForName(fname) == null) {\r
//we are going to create a file, so we check to see if there is a trashed file with the same name\r
else {\r
final FileResource sameFile = same;\r
GWT.log("Same deleted file", null);\r
- ConfirmationDialog confirm = new ConfirmationDialog(images, "A file with " +\r
+ ConfirmationDialog confirm = new ConfirmationDialog("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
+ "file '" + fname + "' will be renamed automatically for you.", "Continue") {\r
\r
@Override\r
public void cancel() {\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 " +\r
- "you want to update " + fname + "?", "Update"){\r
+ ConfirmationDialog confirm = new ConfirmationDialog("Are you sure " +\r
+ "you want to update " + fname + "?", "Update") {\r
\r
@Override\r
public void cancel() {\r
* @param name the potentially full path name of a file\r
* @return the file name without extra path information\r
*/\r
- private String getFilename(String name) {\r
+ protected String getFilename(String name) {\r
int pathSepIndex = name.lastIndexOf("\\");\r
if (pathSepIndex == -1) {\r
pathSepIndex = name.lastIndexOf("/");\r
@Override\r
public void onError(Throwable t) {\r
GWT.log("", t);\r
-\r
}\r
\r
};\r
DeferredCommand.addCommand(eg);\r
}\r
\r
- private String getBackupFilename(String filename) {\r
+ protected String getBackupFilename(String filename) {\r
List<FileResource> filesInSameFolder = new ArrayList<FileResource>();\r
for (FileResource deleted : folder.getFiles())\r
if (deleted.isDeleted())\r
return filename + " " + i;\r
}\r
\r
+ /**\r
+ * Rename the conflicting trashed file with the supplied new name.\r
+ */\r
private void updateTrashedFile(String newName, FileResource trashedFile) {\r
JSONObject json = new JSONObject();\r
json.put("name", new JSONString(newName));\r
\r
@Override\r
public void onError(Throwable t) {\r
+ GSS app = GSS.get();\r
GWT.log("", t);\r
if (t instanceof RestException) {\r
int statusCode = ((RestException) t).getHttpStatusCode();\r
if (statusCode == 405)\r
- GSS.get().displayError("You don't have the necessary permissions");\r
+ app.displayError("You don't have the necessary permissions");\r
else if (statusCode == 404)\r
- GSS.get().displayError("User in permissions does not exist");\r
+ app.displayError("User in permissions does not exist");\r
else if (statusCode == 409)\r
- GSS.get().displayError("A file with the same name already exists");\r
+ app.displayError("A file with the same name already exists");\r
else if (statusCode == 413)\r
- GSS.get().displayError("Your quota has been exceeded");\r
+ app.displayError("Your quota has been exceeded");\r
else\r
- GSS.get().displayError("Unable to modify file:" +((RestException)t).getHttpStatusText());\r
+ app.displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText());\r
} else\r
- GSS.get().displayError("System error modifying file:" + t.getMessage());\r
+ app.displayError("System error modifying file:" + t.getMessage());\r
}\r
\r
};\r
DeferredCommand.addCommand(cf);\r
}\r
\r
- private FileResource getFileForName(String name){\r
+ protected FileResource getFileForName(String name){\r
for (FileResource f : folder.getFiles())\r
if (!f.isDeleted() && f.getName().equals(name))\r
return f;\r
* @param decodedURLComponent\r
* @return\r
*/\r
- private String encodeComponent(String decodedURLComponent) {\r
+ protected String encodeComponent(String decodedURLComponent) {\r
String retv = URL.encodeComponent(decodedURLComponent);\r
retv = retv.replaceAll("'", "%27");\r
return retv;\r
}\r
+\r
+ /**\r
+ * Modify the files.\r
+ *\r
+ * @param newFiles the files to set\r
+ */\r
+ public void setFiles(List<FileResource> newFiles) {\r
+ files = newFiles;\r
+ }\r
}\r