Automated merge with https://gss.googlecode.com/hg/
[pithos] / src / gr / ebs / gss / client / commands / DeleteCommand.java
1 /*
2  * Copyright 2008, 2009 Electronic Business Systems Ltd.
3  *
4  * This file is part of GSS.
5  *
6  * GSS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * GSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 package gr.ebs.gss.client.commands;
20
21 import gr.ebs.gss.client.DeleteFileDialog;
22 import gr.ebs.gss.client.DeleteFolderDialog;
23 import gr.ebs.gss.client.DeleteGroupDialog;
24 import gr.ebs.gss.client.EditMenu.Images;
25 import gr.ebs.gss.client.GSS;
26 import gr.ebs.gss.client.rest.resource.FileResource;
27 import gr.ebs.gss.client.rest.resource.FolderResource;
28 import gr.ebs.gss.client.rest.resource.GroupResource;
29 import gr.ebs.gss.client.rest.resource.GroupUserResource;
30 import gr.ebs.gss.client.rest.resource.RestResourceWrapper;
31
32 import java.util.List;
33
34 import com.google.gwt.core.client.GWT;
35 import com.google.gwt.user.client.Command;
36 import com.google.gwt.user.client.ui.PopupPanel;
37
38
39 /**
40  * Delete selected object command
41  * @author kman
42  *
43  */
44 public class DeleteCommand implements Command{
45         private PopupPanel containerPanel;
46         final Images newImages;
47
48         /**
49          * @param _containerPanel
50          * @param _newImages the images of all the possible delete dialogs
51          */
52         public DeleteCommand( PopupPanel _containerPanel, final Images _newImages ){
53                 containerPanel = _containerPanel;
54                 newImages=_newImages;
55         }
56
57         @Override
58         public void execute() {
59                 containerPanel.hide();
60                 displayDelete();
61         }
62         /**
63          * Display the delete dialog, according to the selected object.
64          *
65          *
66          */
67         void displayDelete() {
68                 Object selection = GSS.get().getCurrentSelection();
69                 if (selection == null)
70                         return;
71                 GWT.log("selection: " + selection.toString(), null);
72                 if (selection instanceof RestResourceWrapper) {
73                         DeleteFolderDialog dlg = new DeleteFolderDialog(newImages);
74                         dlg.center();
75                 } else if (selection instanceof FileResource || selection instanceof List) {
76                         DeleteFileDialog dlg = new DeleteFileDialog(newImages);
77                         dlg.center();
78                 } else if (selection instanceof GroupUserResource) {
79                         // TODO implement user deletion
80                 } else if (selection instanceof GroupResource) {
81                         DeleteGroupDialog dlg = new DeleteGroupDialog(newImages);
82                         dlg.center();
83                 }
84         }
85 }