root / gss / src / gr / ebs / gss / client / commands / NewFolderCommand.java @ 555e8e59
History | View | Annotate | Download (3.6 kB)
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.FolderPropertiesDialog; |
22 |
import gr.ebs.gss.client.GSS; |
23 |
import gr.ebs.gss.client.FileMenu.Images; |
24 |
import gr.ebs.gss.client.rest.ExecuteGet; |
25 |
import gr.ebs.gss.client.rest.ExecuteMultipleGet; |
26 |
import gr.ebs.gss.client.rest.resource.GroupResource; |
27 |
import gr.ebs.gss.client.rest.resource.GroupsResource; |
28 |
|
29 |
import java.util.ArrayList; |
30 |
import java.util.List; |
31 |
|
32 |
import com.google.gwt.core.client.GWT; |
33 |
import com.google.gwt.user.client.Command; |
34 |
import com.google.gwt.user.client.DeferredCommand; |
35 |
import com.google.gwt.user.client.IncrementalCommand; |
36 |
import com.google.gwt.user.client.ui.PopupPanel; |
37 |
import com.google.gwt.user.client.ui.TreeItem; |
38 |
|
39 |
|
40 |
/**
|
41 |
* Display the 'new folder' dialog for creating a new folder.
|
42 |
* @author kman
|
43 |
*
|
44 |
*/
|
45 |
public class NewFolderCommand implements Command{ |
46 |
private PopupPanel containerPanel;
|
47 |
final Images images;
|
48 |
|
49 |
private List<GroupResource> groups = null; |
50 |
|
51 |
/**
|
52 |
* @param aContainerPanel
|
53 |
* @param newImages the images of the new folder dialog
|
54 |
*/
|
55 |
public NewFolderCommand(PopupPanel aContainerPanel, final Images newImages){ |
56 |
containerPanel = aContainerPanel; |
57 |
images=newImages; |
58 |
} |
59 |
|
60 |
public void execute() { |
61 |
containerPanel.hide(); |
62 |
getGroups(); |
63 |
DeferredCommand.addCommand(new IncrementalCommand() {
|
64 |
|
65 |
public boolean execute() { |
66 |
boolean res = canContinue();
|
67 |
if (res) {
|
68 |
displayNewFolder(); |
69 |
return false; |
70 |
} |
71 |
return true; |
72 |
} |
73 |
|
74 |
}); |
75 |
} |
76 |
|
77 |
private boolean canContinue() { |
78 |
if (groups == null) |
79 |
return false; |
80 |
return true; |
81 |
} |
82 |
|
83 |
void displayNewFolder() {
|
84 |
TreeItem currentFolder = GSS.get().getFolders().getCurrent(); |
85 |
if (currentFolder == null) { |
86 |
GSS.get().displayError("You have to select the parent folder first");
|
87 |
return;
|
88 |
} |
89 |
FolderPropertiesDialog dlg = new FolderPropertiesDialog(images, true, groups); |
90 |
dlg.center(); |
91 |
} |
92 |
|
93 |
private void getGroups() { |
94 |
ExecuteGet<GroupsResource> gg = new ExecuteGet<GroupsResource>(GroupsResource.class, GSS.get().getCurrentUserResource().getGroupsPath()){
|
95 |
|
96 |
@Override
|
97 |
public void onComplete() { |
98 |
GroupsResource res = getResult(); |
99 |
ExecuteMultipleGet<GroupResource> ga = new ExecuteMultipleGet<GroupResource>(GroupResource.class, res.getGroupPaths().toArray(new String[]{})){ |
100 |
|
101 |
@Override
|
102 |
public void onComplete() { |
103 |
List<GroupResource> groupList = getResult();
|
104 |
groups = groupList; |
105 |
} |
106 |
|
107 |
@Override
|
108 |
public void onError(Throwable t) { |
109 |
GWT.log("", t);
|
110 |
GSS.get().displayError("Unable to fetch groups");
|
111 |
groups = new ArrayList<GroupResource>(); |
112 |
} |
113 |
|
114 |
@Override
|
115 |
public void onError(String p, Throwable throwable) { |
116 |
GWT.log("Path:"+p, throwable);
|
117 |
} |
118 |
}; |
119 |
DeferredCommand.addCommand(ga); |
120 |
} |
121 |
|
122 |
@Override
|
123 |
public void onError(Throwable t) { |
124 |
GWT.log("", t);
|
125 |
GSS.get().displayError("Unable to fetch groups");
|
126 |
groups = new ArrayList<GroupResource>(); |
127 |
} |
128 |
}; |
129 |
DeferredCommand.addCommand(gg); |
130 |
} |
131 |
|
132 |
} |