root / src / org / gss_project / gss / admin / client / ui / UserClassListPanel.java @ 1205:fbeae20462e6
History | View | Annotate | Download (7.4 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2010 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 org.gss_project.gss.admin.client.ui; |
20 |
|
21 |
import org.gss_project.gss.admin.client.TwoAdmin; |
22 |
import org.gss_project.gss.common.dto.UserClassDTO; |
23 |
|
24 |
import java.util.List; |
25 |
|
26 |
import com.google.gwt.core.client.GWT; |
27 |
import com.google.gwt.event.dom.client.ClickEvent; |
28 |
import com.google.gwt.event.dom.client.ClickHandler; |
29 |
import com.google.gwt.uibinder.client.UiBinder; |
30 |
import com.google.gwt.uibinder.client.UiField; |
31 |
import com.google.gwt.uibinder.client.UiHandler; |
32 |
import com.google.gwt.user.client.rpc.AsyncCallback; |
33 |
import com.google.gwt.user.client.ui.Button; |
34 |
import com.google.gwt.user.client.ui.Composite; |
35 |
import com.google.gwt.user.client.ui.FlexTable; |
36 |
import com.google.gwt.user.client.ui.HTML; |
37 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
38 |
import com.google.gwt.user.client.ui.TextBox; |
39 |
import com.google.gwt.user.client.ui.Widget; |
40 |
|
41 |
|
42 |
/**
|
43 |
* @author kman
|
44 |
*
|
45 |
*/
|
46 |
public class UserClassListPanel extends Composite { |
47 |
|
48 |
private static UserClassListPanelUiBinder uiBinder = GWT.create(UserClassListPanelUiBinder.class); |
49 |
|
50 |
interface UserClassListPanelUiBinder extends UiBinder<Widget, UserClassListPanel> { |
51 |
} |
52 |
@UiField(provided=true) |
53 |
FlexTable userClassList; |
54 |
@UiField(provided=true) |
55 |
FlexTable userClassEdit; |
56 |
@UiField
|
57 |
Button saveButton;
|
58 |
@UiField
|
59 |
Button newButton;
|
60 |
TextBox nameBox = new TextBox();
|
61 |
TextBox quotaBox = new TextBox();
|
62 |
TextBox bandwithBox = new TextBox();
|
63 |
UserClassDTO userClass; |
64 |
|
65 |
public UserClassListPanel() {
|
66 |
userClassList = new FlexTable();
|
67 |
userClassEdit = new FlexTable();
|
68 |
userClassList.setText(0, 0, "Name"); |
69 |
userClassList.setText(0, 1, "Quota"); |
70 |
userClassList.setText(0, 2, "Bandwith Quota"); |
71 |
userClassList.setText(0, 3, ""); |
72 |
userClassList.setText(0, 4, ""); |
73 |
userClassList.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
74 |
userClassList.getFlexCellFormatter().setStyleName(0, 1, "props-toplabels"); |
75 |
userClassList.getFlexCellFormatter().setStyleName(0, 2, "props-toplabels"); |
76 |
userClassList.getFlexCellFormatter().setStyleName(0, 3, "props-toplabels"); |
77 |
userClassList.getFlexCellFormatter().setStyleName(0, 4, "props-toplabels"); |
78 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER); |
79 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER); |
80 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER); |
81 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 3, HasHorizontalAlignment.ALIGN_CENTER); |
82 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(0, 4, HasHorizontalAlignment.ALIGN_CENTER); |
83 |
userClassList.addStyleName("gss-permList");
|
84 |
|
85 |
|
86 |
|
87 |
userClassEdit.setText(0, 0, "Name"); |
88 |
userClassEdit.setText(1, 0, "Quota"); |
89 |
userClassEdit.setText(2, 0, "Bandwith Quota"); |
90 |
userClassEdit.setText(3, 0, ""); |
91 |
|
92 |
userClassEdit.setWidget(0, 1, nameBox); |
93 |
userClassEdit.setWidget(1, 1, quotaBox); |
94 |
userClassEdit.setWidget(2, 1, bandwithBox); |
95 |
userClassEdit.setText(3, 0, ""); |
96 |
userClassList.getFlexCellFormatter().setStyleName(0, 0, "props-toplabels"); |
97 |
userClassList.getFlexCellFormatter().setStyleName(1, 0, "props-toplabels"); |
98 |
userClassList.getFlexCellFormatter().setStyleName(2, 0, "props-toplabels"); |
99 |
userClassList.getFlexCellFormatter().setStyleName(3, 0, "props-toplabels"); |
100 |
initWidget(uiBinder.createAndBindUi(this));
|
101 |
|
102 |
|
103 |
updateTable(); |
104 |
} |
105 |
|
106 |
public void updateTable(){ |
107 |
clearInput(); |
108 |
clearTable(); |
109 |
TwoAdmin.get().getAdminService().getUserClasses(new AsyncCallback<List<UserClassDTO>>() { |
110 |
|
111 |
@Override
|
112 |
public void onSuccess(List<UserClassDTO> result) { |
113 |
int i=1; |
114 |
for(final UserClassDTO dto : result){ |
115 |
userClassList.setHTML(i, 0, "<span>" + dto.getName() + "</span>"); |
116 |
userClassList.setHTML(i, 1, "<span>" + dto.getQuotaAsString() + "</span>"); |
117 |
userClassList.setHTML(i, 2, "<span></span>"); // XXX |
118 |
HTML edit = new HTML("<a href='#'>Edit</a>"); |
119 |
edit.addClickHandler(new ClickHandler() {
|
120 |
|
121 |
@Override
|
122 |
public void onClick(ClickEvent event) { |
123 |
userClass = dto; |
124 |
updateInput(); |
125 |
} |
126 |
}); |
127 |
userClassList.setWidget(i, 3, edit);
|
128 |
HTML delete = new HTML("<a href='#'>Remove</a>"); |
129 |
delete.addClickHandler(new ClickHandler() {
|
130 |
|
131 |
@Override
|
132 |
public void onClick(ClickEvent event) { |
133 |
clearInput(); |
134 |
TwoAdmin.get().getAdminService().removeUserClass(dto, new AsyncCallback<Void>() { |
135 |
|
136 |
@Override
|
137 |
public void onFailure(Throwable caught) { |
138 |
TwoAdmin.get().hideLoadingBox(); |
139 |
GWT.log("Error deleting class", caught);
|
140 |
TwoAdmin.get().showErrorBox("Unable to Delete User Class");
|
141 |
|
142 |
} |
143 |
|
144 |
@Override
|
145 |
public void onSuccess(Void removeResult) { |
146 |
updateTable(); |
147 |
|
148 |
}}); |
149 |
} |
150 |
}); |
151 |
userClassList.setWidget(i, 4, delete);
|
152 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 0, HasHorizontalAlignment.ALIGN_CENTER);
|
153 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER);
|
154 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER);
|
155 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER);
|
156 |
userClassList.getFlexCellFormatter().setHorizontalAlignment(i, 4, HasHorizontalAlignment.ALIGN_CENTER);
|
157 |
i++; |
158 |
} |
159 |
|
160 |
} |
161 |
|
162 |
@Override
|
163 |
public void onFailure(Throwable caught) { |
164 |
// TODO Auto-generated method stub
|
165 |
|
166 |
} |
167 |
}); |
168 |
} |
169 |
public void clearTable(){ |
170 |
int count = userClassList.getRowCount();
|
171 |
for(int i=1;i<count;i++){ |
172 |
userClassList.setHTML(i, 0, "<span></span>"); |
173 |
userClassList.setHTML(i, 1, "<span></span>"); |
174 |
userClassList.setHTML(i, 2, "<span></span>"); |
175 |
userClassList.setHTML(i, 3, "<span></span>"); |
176 |
userClassList.setHTML(i, 4, "<span></span>"); |
177 |
} |
178 |
} |
179 |
public void clearInput(){ |
180 |
userClass= new UserClassDTO();
|
181 |
nameBox.setText("");
|
182 |
quotaBox.setText("");
|
183 |
bandwithBox.setText("");
|
184 |
} |
185 |
|
186 |
public void updateInput(){ |
187 |
nameBox.setText(userClass.getName()); |
188 |
quotaBox.setText(String.valueOf(userClass.getQuota()));
|
189 |
bandwithBox.setText(""); // XXX |
190 |
} |
191 |
|
192 |
@UiHandler("newButton") |
193 |
public void handleNew(@SuppressWarnings("unused") ClickEvent e){ |
194 |
clearInput(); |
195 |
} |
196 |
|
197 |
@UiHandler("saveButton") |
198 |
public void handleSave(@SuppressWarnings("unused") ClickEvent e){ |
199 |
userClass.setName(nameBox.getText()); |
200 |
userClass.setQuota(Long.parseLong(quotaBox.getText()));
|
201 |
TwoAdmin.get().getAdminService().saveOrUpdateUserClass(userClass, new AsyncCallback<Void>() { |
202 |
|
203 |
@Override
|
204 |
public void onFailure(Throwable caught) { |
205 |
TwoAdmin.get().hideLoadingBox(); |
206 |
GWT.log("Error saving class", caught);
|
207 |
TwoAdmin.get().showErrorBox("Unable to Save User Class");
|
208 |
|
209 |
} |
210 |
|
211 |
@Override
|
212 |
public void onSuccess(Void result) { |
213 |
updateTable(); |
214 |
|
215 |
}}); |
216 |
} |
217 |
|
218 |
|
219 |
} |