Updated copyright notice
[pithos] / web_client / src / gr / grnet / pithos / web / client / commands / DeleteCommand.java
1 /*
2  *  Copyright (c) 2011 Greek Research and Technology Network
3  */
4 package gr.grnet.pithos.web.client.commands;
5
6 import gr.grnet.pithos.web.client.DeleteFileDialog;
7 import gr.grnet.pithos.web.client.DeleteFolderDialog;
8 import gr.grnet.pithos.web.client.DeleteGroupDialog;
9 import gr.grnet.pithos.web.client.EditMenu.Images;
10 import gr.grnet.pithos.web.client.GSS;
11 import gr.grnet.pithos.web.client.rest.resource.FileResource;
12 import gr.grnet.pithos.web.client.rest.resource.GroupResource;
13 import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
14 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
15
16 import java.util.List;
17
18 import com.google.gwt.core.client.GWT;
19 import com.google.gwt.user.client.Command;
20 import com.google.gwt.user.client.ui.PopupPanel;
21
22
23 /**
24  * Delete selected object command
25  *
26  */
27 public class DeleteCommand implements Command{
28         private PopupPanel containerPanel;
29         final Images newImages;
30
31         /**
32          * @param _containerPanel
33          * @param _newImages the images of all the possible delete dialogs
34          */
35         public DeleteCommand( PopupPanel _containerPanel, final Images _newImages ){
36                 containerPanel = _containerPanel;
37                 newImages=_newImages;
38         }
39
40         @Override
41         public void execute() {
42                 containerPanel.hide();
43                 displayDelete();
44         }
45         /**
46          * Display the delete dialog, according to the selected object.
47          *
48          *
49          */
50         void displayDelete() {
51                 Object selection = GSS.get().getCurrentSelection();
52                 if (selection == null)
53                         return;
54                 GWT.log("selection: " + selection.toString(), null);
55                 if (selection instanceof RestResourceWrapper) {
56                         DeleteFolderDialog dlg = new DeleteFolderDialog(newImages);
57                         dlg.center();
58                 } else if (selection instanceof FileResource || selection instanceof List) {
59                         DeleteFileDialog dlg = new DeleteFileDialog(newImages);
60                         dlg.center();
61                 } else if (selection instanceof GroupUserResource) {
62                         // TODO implement user deletion
63                 } else if (selection instanceof GroupResource) {
64                         DeleteGroupDialog dlg = new DeleteGroupDialog(newImages);
65                         dlg.center();
66                 }
67         }
68 }