*/\r
package gr.grnet.pithos.web.client;\r
\r
+import com.google.gwt.event.dom.client.KeyDownEvent;\r
import gr.grnet.pithos.web.client.MessagePanel.Images;\r
-import gr.grnet.pithos.web.client.rest.DeleteCommand;\r
-import gr.grnet.pithos.web.client.rest.RestException;\r
-import gr.grnet.pithos.web.client.rest.resource.FolderResource;\r
-import gr.grnet.pithos.web.client.rest.resource.RestResource;\r
-import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;\r
-import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;\r
+import gr.grnet.pithos.web.client.foldertree.Folder;\r
\r
-import com.google.gwt.core.client.GWT;\r
import com.google.gwt.dom.client.NativeEvent;\r
import com.google.gwt.event.dom.client.ClickEvent;\r
import com.google.gwt.event.dom.client.ClickHandler;\r
import com.google.gwt.event.dom.client.KeyCodes;\r
-import com.google.gwt.user.client.DeferredCommand;\r
import com.google.gwt.user.client.Event.NativePreviewEvent;\r
import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
import com.google.gwt.user.client.ui.Button;\r
*/\r
public class DeleteFolderDialog extends DialogBox {\r
\r
+ protected Pithos app;\r
+ protected Folder folder;\r
+ \r
/**\r
* The widget's constructor.\r
* @param images the supplied images\r
*/\r
- public DeleteFolderDialog(Images images) {\r
+ public DeleteFolderDialog(Pithos _app, Images images, Folder _folder) {\r
+ this.app = _app;\r
+ this.folder = _folder;\r
// Set the dialog's caption.\r
setText("Confirmation");\r
setAnimationEnabled(true);\r
- FolderResource folder = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();\r
// Create a VerticalPanel to contain the HTML label and the buttons.\r
VerticalPanel outer = new VerticalPanel();\r
HorizontalPanel buttons = new HorizontalPanel();\r
// when the button is clicked and deletes the folder.\r
Button ok = new Button("Delete", new ClickHandler() {\r
@Override\r
- public void onClick(ClickEvent event) {\r
- deleteFolder();\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
+ app.deleteFolder(folder);\r
hide();\r
}\r
});\r
- ok.getElement().setId("confirmation.ok");\r
buttons.add(ok);\r
buttons.setCellHorizontalAlignment(ok, HasHorizontalAlignment.ALIGN_CENTER);\r
// Create the 'Cancel' button, along with a listener that hides the\r
// dialog when the button is clicked.\r
Button cancel = new Button("Cancel", new ClickHandler() {\r
@Override\r
- public void onClick(ClickEvent event) {\r
+ public void onClick(@SuppressWarnings("unused") ClickEvent event) {\r
hide();\r
}\r
});\r
- cancel.getElement().setId("confirmation.cancel");\r
buttons.add(cancel);\r
buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER);\r
buttons.setSpacing(8);\r
setWidget(outer);\r
}\r
\r
- /**\r
- * Generate an RPC request to delete a folder.\r
- *\r
- * @param userId the ID of the current user\r
- */\r
- private void deleteFolder() {\r
- RestResource folder = GSS.get().getTreeView().getSelection();\r
- if (folder == null) {\r
- GSS.get().displayError("No folder was selected");\r
- return;\r
- }\r
- if(!(folder instanceof RestResourceWrapper))\r
- return;\r
-\r
- DeleteCommand df = new DeleteCommand(folder.getUri()){\r
-\r
- @Override\r
- public void onComplete() {\r
- FolderResource fres = ((RestResourceWrapper) GSS.get().getTreeView().getSelection()).getResource();\r
- if((RestResourceWrapper) GSS.get().getTreeView().getSelection() instanceof TrashFolderResource)\r
- GSS.get().getTreeView().updateTrashNode();\r
- else\r
- GSS.get().getTreeView().updateNodeChildrenForRemove(fres.getParentURI());\r
- GSS.get().getTreeView().clearSelection();\r
- GSS.get().showFileList(true);\r
- \r
- GSS.get().getStatusPanel().updateStats();\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\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
- else if(statusCode == 404)\r
- GSS.get().displayError("Folder not found");\r
- else\r
- GSS.get().displayError("Unable to delete folder: "+((RestException)t).getHttpStatusText());\r
- }\r
- else\r
- GSS.get().displayError("System error unable to delete folder: "+t.getMessage());\r
- }\r
- };\r
-\r
- DeferredCommand.addCommand(df);\r
- }\r
-\r
@Override\r
protected void onPreviewNativeEvent(NativePreviewEvent preview) {\r
super.onPreviewNativeEvent(preview);\r
\r
NativeEvent evt = preview.getNativeEvent();\r
- if (evt.getType().equals("keydown"))\r
+ if (evt.getType().equals(KeyDownEvent.getType().getName()))\r
// Use the popup's key preview hooks to close the dialog when either\r
// enter or escape is pressed.\r
switch (evt.getKeyCode()) {\r
case KeyCodes.KEY_ENTER:\r
hide();\r
- deleteFolder();\r
+ app.deleteFolder(folder);\r
break;\r
case KeyCodes.KEY_ESCAPE:\r
hide();\r