root / src / gr / grnet / pithos / web / client / commands / DeleteGroupCommand.java @ 067bbb04
History | View | Annotate | Download (3.6 kB)
1 | 4baffab1 | Christos Stathis | /*
|
---|---|---|---|
2 | 4baffab1 | Christos Stathis | * Copyright 2011 GRNET S.A. All rights reserved.
|
3 | 4baffab1 | Christos Stathis | *
|
4 | 4baffab1 | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 4baffab1 | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 4baffab1 | Christos Stathis | * conditions are met:
|
7 | 4baffab1 | Christos Stathis | *
|
8 | 4baffab1 | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 4baffab1 | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 4baffab1 | Christos Stathis | * disclaimer.
|
11 | 4baffab1 | Christos Stathis | *
|
12 | 4baffab1 | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 4baffab1 | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 4baffab1 | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 4baffab1 | Christos Stathis | * provided with the distribution.
|
16 | 4baffab1 | Christos Stathis | *
|
17 | 4baffab1 | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 4baffab1 | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 4baffab1 | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 4baffab1 | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 4baffab1 | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 4baffab1 | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 4baffab1 | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 4baffab1 | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 4baffab1 | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 4baffab1 | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 4baffab1 | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 4baffab1 | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 4baffab1 | Christos Stathis | *
|
30 | 4baffab1 | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 4baffab1 | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 4baffab1 | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 4baffab1 | Christos Stathis | * or implied, of GRNET S.A.
|
34 | 4baffab1 | Christos Stathis | */
|
35 | 4baffab1 | Christos Stathis | package gr.grnet.pithos.web.client.commands; |
36 | 4baffab1 | Christos Stathis | |
37 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.Pithos; |
38 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.foldertree.Resource; |
39 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.grouptree.Group; |
40 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.rest.PostRequest; |
41 | 4baffab1 | Christos Stathis | import gr.grnet.pithos.web.client.rest.RestException; |
42 | 4baffab1 | Christos Stathis | |
43 | 4baffab1 | Christos Stathis | import com.google.gwt.core.client.GWT; |
44 | 4baffab1 | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
45 | 9539e23d | Christos Stathis | import com.google.gwt.http.client.Response; |
46 | ea94470a | Christos Stathis | import com.google.gwt.http.client.URL; |
47 | 4baffab1 | Christos Stathis | import com.google.gwt.user.client.Command; |
48 | 4baffab1 | Christos Stathis | import com.google.gwt.user.client.Window; |
49 | 4baffab1 | Christos Stathis | import com.google.gwt.user.client.ui.PopupPanel; |
50 | 4baffab1 | Christos Stathis | |
51 | 4baffab1 | Christos Stathis | |
52 | 4baffab1 | Christos Stathis | /**
|
53 | 4baffab1 | Christos Stathis | * Delete selected object command
|
54 | 4baffab1 | Christos Stathis | *
|
55 | 4baffab1 | Christos Stathis | */
|
56 | 4baffab1 | Christos Stathis | public class DeleteGroupCommand implements Command { |
57 | 4baffab1 | Christos Stathis | private PopupPanel containerPanel;
|
58 | 4baffab1 | Christos Stathis | |
59 | abd8738f | Christos Stathis | Group group;
|
60 | 4baffab1 | Christos Stathis | |
61 | 4baffab1 | Christos Stathis | Pithos app; |
62 | 4baffab1 | Christos Stathis | |
63 | 4baffab1 | Christos Stathis | /**
|
64 | 4baffab1 | Christos Stathis | * @param _containerPanel
|
65 | 4baffab1 | Christos Stathis | */
|
66 | 4baffab1 | Christos Stathis | public DeleteGroupCommand(Pithos _app, PopupPanel _containerPanel, Group _group){ |
67 | 4baffab1 | Christos Stathis | app = _app; |
68 | 4baffab1 | Christos Stathis | containerPanel = _containerPanel; |
69 | 4baffab1 | Christos Stathis | group = _group; |
70 | 4baffab1 | Christos Stathis | } |
71 | 4baffab1 | Christos Stathis | |
72 | 4baffab1 | Christos Stathis | @Override
|
73 | 4baffab1 | Christos Stathis | public void execute() { |
74 | 4baffab1 | Christos Stathis | if (containerPanel != null) |
75 | 4baffab1 | Christos Stathis | containerPanel.hide(); |
76 | 4baffab1 | Christos Stathis | if (Window.confirm("Are you sure you want to delete group " + group.getName())) { |
77 | 4baffab1 | Christos Stathis | String path = "?update="; |
78 | 4baffab1 | Christos Stathis | PostRequest updateGroup = new PostRequest(app.getApiPath(), app.getUsername(), path) {
|
79 | 4baffab1 | Christos Stathis | |
80 | 4baffab1 | Christos Stathis | @Override
|
81 | abd8738f | Christos Stathis | public void onSuccess(@SuppressWarnings("unused") Resource result) { |
82 | 61f8605d | Christos Stathis | app.removeGroup(group); |
83 | 4baffab1 | Christos Stathis | } |
84 | 4baffab1 | Christos Stathis | |
85 | 4baffab1 | Christos Stathis | @Override
|
86 | 4baffab1 | Christos Stathis | public void onError(Throwable t) { |
87 | 4baffab1 | Christos Stathis | GWT.log("", t);
|
88 | 4baffab1 | Christos Stathis | if (t instanceof RestException) { |
89 | 4baffab1 | Christos Stathis | app.displayError("Unable to delete group:" + ((RestException) t).getHttpStatusText());
|
90 | 4baffab1 | Christos Stathis | } |
91 | 4baffab1 | Christos Stathis | else
|
92 | 4baffab1 | Christos Stathis | app.displayError("System error deleting group:" + t.getMessage());
|
93 | 4baffab1 | Christos Stathis | } |
94 | 9539e23d | Christos Stathis | |
95 | 9539e23d | Christos Stathis | @Override
|
96 | 9539e23d | Christos Stathis | protected void onUnauthorized(Response response) { |
97 | 9539e23d | Christos Stathis | app.sessionExpired(); |
98 | 9539e23d | Christos Stathis | } |
99 | 4baffab1 | Christos Stathis | }; |
100 | 4baffab1 | Christos Stathis | updateGroup.setHeader("X-Auth-Token", app.getToken());
|
101 | ea94470a | Christos Stathis | updateGroup.setHeader("X-Account-Group-" + URL.encodePathSegment(group.getName()), "~"); |
102 | 4baffab1 | Christos Stathis | Scheduler.get().scheduleDeferred(updateGroup); |
103 | 4baffab1 | Christos Stathis | } |
104 | 4baffab1 | Christos Stathis | } |
105 | 4baffab1 | Christos Stathis | } |