root / src / org / gss_project / gss / admin / client / ui / UserClassListPanel.java @ 1205:fbeae20462e6
History | View | Annotate | Download (7.4 kB)
1 | 623:66f69a7348ed | pastith | /*
|
---|---|---|---|
2 | 623:66f69a7348ed | pastith | * Copyright 2010 Electronic Business Systems Ltd.
|
3 | 623:66f69a7348ed | pastith | *
|
4 | 623:66f69a7348ed | pastith | * This file is part of GSS.
|
5 | 623:66f69a7348ed | pastith | *
|
6 | 623:66f69a7348ed | pastith | * GSS is free software: you can redistribute it and/or modify
|
7 | 623:66f69a7348ed | pastith | * it under the terms of the GNU General Public License as published by
|
8 | 623:66f69a7348ed | pastith | * the Free Software Foundation, either version 3 of the License, or
|
9 | 623:66f69a7348ed | pastith | * (at your option) any later version.
|
10 | 623:66f69a7348ed | pastith | *
|
11 | 623:66f69a7348ed | pastith | * GSS is distributed in the hope that it will be useful,
|
12 | 623:66f69a7348ed | pastith | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 623:66f69a7348ed | pastith | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 | 623:66f69a7348ed | pastith | * GNU General Public License for more details.
|
15 | 623:66f69a7348ed | pastith | *
|
16 | 623:66f69a7348ed | pastith | * You should have received a copy of the GNU General Public License
|
17 | 623:66f69a7348ed | pastith | * along with GSS. If not, see <http://www.gnu.org/licenses/>.
|
18 | 623:66f69a7348ed | pastith | */
|
19 | 1205:fbeae20462e6 | chstath | package org.gss_project.gss.admin.client.ui; |
20 | 623:66f69a7348ed | pastith | |
21 | 1205:fbeae20462e6 | chstath | import org.gss_project.gss.admin.client.TwoAdmin; |
22 | 1205:fbeae20462e6 | chstath | import org.gss_project.gss.common.dto.UserClassDTO; |
23 | 623:66f69a7348ed | pastith | |
24 | 623:66f69a7348ed | pastith | import java.util.List; |
25 | 623:66f69a7348ed | pastith | |
26 | 623:66f69a7348ed | pastith | import com.google.gwt.core.client.GWT; |
27 | 623:66f69a7348ed | pastith | import com.google.gwt.event.dom.client.ClickEvent; |
28 | 623:66f69a7348ed | pastith | import com.google.gwt.event.dom.client.ClickHandler; |
29 | 623:66f69a7348ed | pastith | import com.google.gwt.uibinder.client.UiBinder; |
30 | 623:66f69a7348ed | pastith | import com.google.gwt.uibinder.client.UiField; |
31 | 623:66f69a7348ed | pastith | import com.google.gwt.uibinder.client.UiHandler; |
32 | 623:66f69a7348ed | pastith | import com.google.gwt.user.client.rpc.AsyncCallback; |
33 | 623:66f69a7348ed | pastith | import com.google.gwt.user.client.ui.Button; |
34 | 623:66f69a7348ed | pastith | import com.google.gwt.user.client.ui.Composite; |
35 | 623:66f69a7348ed | pastith | import com.google.gwt.user.client.ui.FlexTable; |
36 | 623:66f69a7348ed | pastith | import com.google.gwt.user.client.ui.HTML; |
37 | 623:66f69a7348ed | pastith | import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
38 | 623:66f69a7348ed | pastith | import com.google.gwt.user.client.ui.TextBox; |
39 | 623:66f69a7348ed | pastith | import com.google.gwt.user.client.ui.Widget; |
40 | 623:66f69a7348ed | pastith | |
41 | 623:66f69a7348ed | pastith | |
42 | 623:66f69a7348ed | pastith | /**
|
43 | 623:66f69a7348ed | pastith | * @author kman
|
44 | 623:66f69a7348ed | pastith | *
|
45 | 623:66f69a7348ed | pastith | */
|
46 | 623:66f69a7348ed | pastith | public class UserClassListPanel extends Composite { |
47 | 623:66f69a7348ed | pastith | |
48 | 623:66f69a7348ed | pastith | private static UserClassListPanelUiBinder uiBinder = GWT.create(UserClassListPanelUiBinder.class); |
49 | 623:66f69a7348ed | pastith | |
50 | 623:66f69a7348ed | pastith | interface UserClassListPanelUiBinder extends UiBinder<Widget, UserClassListPanel> { |
51 | 623:66f69a7348ed | pastith | } |
52 | 623:66f69a7348ed | pastith | @UiField(provided=true) |
53 | 623:66f69a7348ed | pastith | FlexTable userClassList; |
54 | 623:66f69a7348ed | pastith | @UiField(provided=true) |
55 | 623:66f69a7348ed | pastith | FlexTable userClassEdit; |
56 | 623:66f69a7348ed | pastith | @UiField
|
57 | 623:66f69a7348ed | pastith | Button saveButton;
|
58 | 623:66f69a7348ed | pastith | @UiField
|
59 | 623:66f69a7348ed | pastith | Button newButton;
|
60 | 623:66f69a7348ed | pastith | TextBox nameBox = new TextBox();
|
61 | 623:66f69a7348ed | pastith | TextBox quotaBox = new TextBox();
|
62 | 623:66f69a7348ed | pastith | TextBox bandwithBox = new TextBox();
|
63 | 623:66f69a7348ed | pastith | UserClassDTO userClass; |
64 | 623:66f69a7348ed | pastith | |
65 | 623:66f69a7348ed | pastith | public UserClassListPanel() {
|
66 | 623:66f69a7348ed | pastith | userClassList = new FlexTable();
|
67 | 623:66f69a7348ed | pastith | userClassEdit = new FlexTable();
|
68 | 623:66f69a7348ed | pastith | userClassList.setText(0, 0, "Name"); |
69 | 623:66f69a7348ed | pastith | userClassList.setText(0, 1, "Quota"); |
70 | 623:66f69a7348ed | pastith | userClassList.setText(0, 2, "Bandwith Quota"); |
71 | 623:66f69a7348ed | pastith | userClassList.setText(0, 3, ""); |
72 | 623:66f69a7348ed | pastith | userClassList.setText(0, 4, ""); |
73 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
74 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
75 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
76 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels"); |
77 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setStyleName(0, 4, "props-toplabels"); |
78 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); |
79 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER); |
80 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER); |
81 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER); |
82 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER); |
83 | 623:66f69a7348ed | pastith | userClassList.addStyleName("gss-permList");
|
84 | 623:66f69a7348ed | pastith | |
85 | 623:66f69a7348ed | pastith | |
86 | 623:66f69a7348ed | pastith | |
87 | 623:66f69a7348ed | pastith | userClassEdit.setText(0, 0, "Name"); |
88 | 623:66f69a7348ed | pastith | userClassEdit.setText(1, 0, "Quota"); |
89 | 623:66f69a7348ed | pastith | userClassEdit.setText(2, 0, "Bandwith Quota"); |
90 | 623:66f69a7348ed | pastith | userClassEdit.setText(3, 0, ""); |
91 | 623:66f69a7348ed | pastith | |
92 | 623:66f69a7348ed | pastith | userClassEdit.setWidget(0, 1, nameBox); |
93 | 623:66f69a7348ed | pastith | userClassEdit.setWidget(1, 1, quotaBox); |
94 | 623:66f69a7348ed | pastith | userClassEdit.setWidget(2, 1, bandwithBox); |
95 | 623:66f69a7348ed | pastith | userClassEdit.setText(3, 0, ""); |
96 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
97 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setStyleName(1, 0, "props-toplabels"); |
98 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setStyleName(2, 0, "props-toplabels"); |
99 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setStyleName(3, 0, "props-toplabels"); |
100 | 623:66f69a7348ed | pastith | initWidget(uiBinder.createAndBindUi(this));
|
101 | 623:66f69a7348ed | pastith | |
102 | 623:66f69a7348ed | pastith | |
103 | 623:66f69a7348ed | pastith | updateTable(); |
104 | 623:66f69a7348ed | pastith | } |
105 | 623:66f69a7348ed | pastith | |
106 | 623:66f69a7348ed | pastith | public void updateTable(){ |
107 | 623:66f69a7348ed | pastith | clearInput(); |
108 | 623:66f69a7348ed | pastith | clearTable(); |
109 | 623:66f69a7348ed | pastith | TwoAdmin.get().getAdminService().getUserClasses(new AsyncCallback<List<UserClassDTO>>() { |
110 | 623:66f69a7348ed | pastith | |
111 | 623:66f69a7348ed | pastith | @Override
|
112 | 623:66f69a7348ed | pastith | public void onSuccess(List<UserClassDTO> result) { |
113 | 623:66f69a7348ed | pastith | int i=1; |
114 | 623:66f69a7348ed | pastith | for(final UserClassDTO dto : result){ |
115 | 623:66f69a7348ed | pastith | userClassList.setHTML(i, 0, "<span>" + dto.getName() + "</span>"); |
116 | 623:66f69a7348ed | pastith | userClassList.setHTML(i, 1, "<span>" + dto.getQuotaAsString() + "</span>"); |
117 | 623:66f69a7348ed | pastith | userClassList.setHTML(i, 2, "<span></span>"); // XXX |
118 | 623:66f69a7348ed | pastith | HTML edit = new HTML("<a href='#'>Edit</a>"); |
119 | 623:66f69a7348ed | pastith | edit.addClickHandler(new ClickHandler() {
|
120 | 623:66f69a7348ed | pastith | |
121 | 623:66f69a7348ed | pastith | @Override
|
122 | 623:66f69a7348ed | pastith | public void onClick(ClickEvent event) { |
123 | 623:66f69a7348ed | pastith | userClass = dto; |
124 | 623:66f69a7348ed | pastith | updateInput(); |
125 | 623:66f69a7348ed | pastith | } |
126 | 623:66f69a7348ed | pastith | }); |
127 | 623:66f69a7348ed | pastith | userClassList.setWidget(i, 3, edit);
|
128 | 623:66f69a7348ed | pastith | HTML delete = new HTML("<a href='#'>Remove</a>"); |
129 | 623:66f69a7348ed | pastith | delete.addClickHandler(new ClickHandler() {
|
130 | 623:66f69a7348ed | pastith | |
131 | 623:66f69a7348ed | pastith | @Override
|
132 | 623:66f69a7348ed | pastith | public void onClick(ClickEvent event) { |
133 | 623:66f69a7348ed | pastith | clearInput(); |
134 | 623:66f69a7348ed | pastith | TwoAdmin.get().getAdminService().removeUserClass(dto, new AsyncCallback<Void>() { |
135 | 623:66f69a7348ed | pastith | |
136 | 623:66f69a7348ed | pastith | @Override
|
137 | 623:66f69a7348ed | pastith | public void onFailure(Throwable caught) { |
138 | 623:66f69a7348ed | pastith | TwoAdmin.get().hideLoadingBox(); |
139 | 623:66f69a7348ed | pastith | GWT.log("Error deleting class", caught);
|
140 | 623:66f69a7348ed | pastith | TwoAdmin.get().showErrorBox("Unable to Delete User Class");
|
141 | 623:66f69a7348ed | pastith | |
142 | 623:66f69a7348ed | pastith | } |
143 | 623:66f69a7348ed | pastith | |
144 | 623:66f69a7348ed | pastith | @Override
|
145 | 623:66f69a7348ed | pastith | public void onSuccess(Void removeResult) { |
146 | 623:66f69a7348ed | pastith | updateTable(); |
147 | 623:66f69a7348ed | pastith | |
148 | 623:66f69a7348ed | pastith | }}); |
149 | 623:66f69a7348ed | pastith | } |
150 | 623:66f69a7348ed | pastith | }); |
151 | 623:66f69a7348ed | pastith | userClassList.setWidget(i, 4, delete);
|
152 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_CENTER);
|
153 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
|
154 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
|
155 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
|
156 | 623:66f69a7348ed | pastith | userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 4, HasHorizontalAlignment.ALIGN_CENTER);
|
157 | 623:66f69a7348ed | pastith | i++; |
158 | 623:66f69a7348ed | pastith | } |
159 | 623:66f69a7348ed | pastith | |
160 | 623:66f69a7348ed | pastith | } |
161 | 623:66f69a7348ed | pastith | |
162 | 623:66f69a7348ed | pastith | @Override
|
163 | 623:66f69a7348ed | pastith | public void onFailure(Throwable caught) { |
164 | 623:66f69a7348ed | pastith | // TODO Auto-generated method stub
|
165 | 623:66f69a7348ed | pastith | |
166 | 623:66f69a7348ed | pastith | } |
167 | 623:66f69a7348ed | pastith | }); |
168 | 623:66f69a7348ed | pastith | } |
169 | 623:66f69a7348ed | pastith | public void clearTable(){ |
170 | 623:66f69a7348ed | pastith | int count = userClassList.getRowCount();
|
171 | 623:66f69a7348ed | pastith | for(int i=1;i<count;i++){ |
172 | 623:66f69a7348ed | pastith | userClassList.setHTML(i, 0, "<span></span>"); |
173 | 623:66f69a7348ed | pastith | userClassList.setHTML(i, 1, "<span></span>"); |
174 | 623:66f69a7348ed | pastith | userClassList.setHTML(i, 2, "<span></span>"); |
175 | 623:66f69a7348ed | pastith | userClassList.setHTML(i, 3, "<span></span>"); |
176 | 623:66f69a7348ed | pastith | userClassList.setHTML(i, 4, "<span></span>"); |
177 | 623:66f69a7348ed | pastith | } |
178 | 623:66f69a7348ed | pastith | } |
179 | 623:66f69a7348ed | pastith | public void clearInput(){ |
180 | 623:66f69a7348ed | pastith | userClass= new UserClassDTO();
|
181 | 623:66f69a7348ed | pastith | nameBox.setText("");
|
182 | 623:66f69a7348ed | pastith | quotaBox.setText("");
|
183 | 623:66f69a7348ed | pastith | bandwithBox.setText("");
|
184 | 623:66f69a7348ed | pastith | } |
185 | 623:66f69a7348ed | pastith | |
186 | 623:66f69a7348ed | pastith | public void updateInput(){ |
187 | 623:66f69a7348ed | pastith | nameBox.setText(userClass.getName()); |
188 | 623:66f69a7348ed | pastith | quotaBox.setText(String.valueOf(userClass.getQuota()));
|
189 | 623:66f69a7348ed | pastith | bandwithBox.setText(""); // XXX |
190 | 623:66f69a7348ed | pastith | } |
191 | 623:66f69a7348ed | pastith | |
192 | 623:66f69a7348ed | pastith | @UiHandler("newButton") |
193 | 623:66f69a7348ed | pastith | public void handleNew(@SuppressWarnings("unused") ClickEvent e){ |
194 | 623:66f69a7348ed | pastith | clearInput(); |
195 | 623:66f69a7348ed | pastith | } |
196 | 623:66f69a7348ed | pastith | |
197 | 623:66f69a7348ed | pastith | @UiHandler("saveButton") |
198 | 623:66f69a7348ed | pastith | public void handleSave(@SuppressWarnings("unused") ClickEvent e){ |
199 | 623:66f69a7348ed | pastith | userClass.setName(nameBox.getText()); |
200 | 623:66f69a7348ed | pastith | userClass.setQuota(Long.parseLong(quotaBox.getText()));
|
201 | 623:66f69a7348ed | pastith | TwoAdmin.get().getAdminService().saveOrUpdateUserClass(userClass, new AsyncCallback<Void>() { |
202 | 623:66f69a7348ed | pastith | |
203 | 623:66f69a7348ed | pastith | @Override
|
204 | 623:66f69a7348ed | pastith | public void onFailure(Throwable caught) { |
205 | 623:66f69a7348ed | pastith | TwoAdmin.get().hideLoadingBox(); |
206 | 623:66f69a7348ed | pastith | GWT.log("Error saving class", caught);
|
207 | 623:66f69a7348ed | pastith | TwoAdmin.get().showErrorBox("Unable to Save User Class");
|
208 | 623:66f69a7348ed | pastith | |
209 | 623:66f69a7348ed | pastith | } |
210 | 623:66f69a7348ed | pastith | |
211 | 623:66f69a7348ed | pastith | @Override
|
212 | 623:66f69a7348ed | pastith | public void onSuccess(Void result) { |
213 | 623:66f69a7348ed | pastith | updateTable(); |
214 | 623:66f69a7348ed | pastith | |
215 | 623:66f69a7348ed | pastith | }}); |
216 | 623:66f69a7348ed | pastith | } |
217 | 623:66f69a7348ed | pastith | |
218 | 623:66f69a7348ed | pastith | |
219 | 1176:ec08a929c703 | chstath | } |