Revision dc8cc18a src/gr/grnet/pithos/web/client/GroupCreateDialog.java
b/src/gr/grnet/pithos/web/client/GroupCreateDialog.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 |
import gr.grnet.pithos.web.client.commands.AddUserCommand; |
|
38 |
import gr.grnet.pithos.web.client.foldertree.Folder; |
|
39 |
import gr.grnet.pithos.web.client.grouptree.Group; |
|
40 |
|
|
37 | 41 |
import com.google.gwt.dom.client.NativeEvent; |
38 | 42 |
import com.google.gwt.event.dom.client.ClickEvent; |
39 | 43 |
import com.google.gwt.event.dom.client.ClickHandler; |
... | ... | |
41 | 45 |
import com.google.gwt.event.dom.client.KeyDownEvent; |
42 | 46 |
import com.google.gwt.user.client.Command; |
43 | 47 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
44 |
import com.google.gwt.user.client.ui.*; |
|
45 |
import gr.grnet.pithos.web.client.commands.AddUserCommand; |
|
46 |
import gr.grnet.pithos.web.client.grouptree.Group; |
|
48 |
import com.google.gwt.user.client.ui.Anchor; |
|
49 |
import com.google.gwt.user.client.ui.Button; |
|
50 |
import com.google.gwt.user.client.ui.DialogBox; |
|
51 |
import com.google.gwt.user.client.ui.FlexTable; |
|
52 |
import com.google.gwt.user.client.ui.HasHorizontalAlignment; |
|
53 |
import com.google.gwt.user.client.ui.TextBox; |
|
54 |
import com.google.gwt.user.client.ui.VerticalPanel; |
|
47 | 55 |
|
48 | 56 |
/** |
49 | 57 |
* The 'Folder properties' dialog box implementation. |
... | ... | |
53 | 61 |
protected Pithos app; |
54 | 62 |
|
55 | 63 |
private Command callback; |
56 |
|
|
57 |
/**
|
|
58 |
* The widget that holds the folderName of the folder.
|
|
59 |
*/
|
|
60 |
TextBox groupNameTextBox = new TextBox();
|
|
61 |
|
|
62 |
final VerticalPanel inner;
|
|
63 |
|
|
64 |
public GroupCreateDialog(final Pithos app) {
|
|
65 |
this(app, null);
|
|
66 |
}
|
|
67 |
|
|
68 |
/**
|
|
69 |
* The widget's constructor.
|
|
70 |
*/
|
|
71 |
public GroupCreateDialog(final Pithos app, Command callback) {
|
|
64 |
|
|
65 |
/**
|
|
66 |
* The widget that holds the folderName of the folder.
|
|
67 |
*/
|
|
68 |
TextBox groupName = new TextBox();
|
|
69 |
|
|
70 |
final VerticalPanel inner;
|
|
71 |
|
|
72 |
public GroupCreateDialog(final Pithos app) {
|
|
73 |
this(app, null);
|
|
74 |
}
|
|
75 |
|
|
76 |
/**
|
|
77 |
* The widget's constructor.
|
|
78 |
*/
|
|
79 |
public GroupCreateDialog(final Pithos app, Command callback) {
|
|
72 | 80 |
this.app = app; |
73 | 81 |
this.callback = callback; |
74 |
|
|
75 |
Anchor close = new Anchor("close");
|
|
76 |
close.addStyleName("close");
|
|
77 |
close.addClickHandler(new ClickHandler() {
|
|
78 |
|
|
79 |
@Override
|
|
80 |
public void onClick(ClickEvent event) {
|
|
81 |
hide();
|
|
82 |
}
|
|
83 |
});
|
|
84 |
|
|
85 |
setGlassEnabled(true);
|
|
86 |
setStyleName("pithos-DialogBox");
|
|
87 |
|
|
88 |
// Enable IE selection for the dialog (must disable it upon closing it)
|
|
89 |
Pithos.enableIESelection();
|
|
90 |
|
|
91 |
// Use this opportunity to set the dialog's caption.
|
|
92 |
setText("Create group");
|
|
93 |
|
|
94 |
// Outer contains inner and buttons
|
|
95 |
VerticalPanel outer = new VerticalPanel();
|
|
96 |
outer.add(close);
|
|
97 |
// Inner contains generalPanel and permPanel
|
|
98 |
inner = new VerticalPanel();
|
|
99 |
inner.addStyleName("inner");
|
|
100 |
|
|
101 |
VerticalPanel generalPanel = new VerticalPanel();
|
|
82 |
|
|
83 |
Anchor close = new Anchor("close");
|
|
84 |
close.addStyleName("close");
|
|
85 |
close.addClickHandler(new ClickHandler() {
|
|
86 |
|
|
87 |
@Override
|
|
88 |
public void onClick(ClickEvent event) {
|
|
89 |
hide();
|
|
90 |
}
|
|
91 |
});
|
|
92 |
|
|
93 |
setGlassEnabled(true);
|
|
94 |
setStyleName("pithos-DialogBox");
|
|
95 |
|
|
96 |
// Enable IE selection for the dialog (must disable it upon closing it)
|
|
97 |
Pithos.enableIESelection();
|
|
98 |
|
|
99 |
// Use this opportunity to set the dialog's caption.
|
|
100 |
setText("Create group");
|
|
101 |
|
|
102 |
// Outer contains inner and buttons
|
|
103 |
VerticalPanel outer = new VerticalPanel();
|
|
104 |
outer.add(close);
|
|
105 |
// Inner contains generalPanel and permPanel
|
|
106 |
inner = new VerticalPanel();
|
|
107 |
inner.addStyleName("inner");
|
|
108 |
|
|
109 |
VerticalPanel generalPanel = new VerticalPanel();
|
|
102 | 110 |
FlexTable generalTable = new FlexTable(); |
103 | 111 |
generalTable.setText(0, 0, "Name"); |
104 | 112 |
|
105 |
generalTable.setWidget(0, 1, groupNameTextBox);
|
|
113 |
generalTable.setWidget(0, 1, groupName); |
|
106 | 114 |
|
107 | 115 |
generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); |
108 | 116 |
generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); |
... | ... | |
112 | 120 |
|
113 | 121 |
outer.add(inner); |
114 | 122 |
|
115 |
// Create the 'Create/Update' button, along with a listener that hides the dialog
|
|
116 |
// when the button is clicked and quits the application.
|
|
117 |
String okLabel = "Create";
|
|
118 |
final Button ok = new Button(okLabel, new ClickHandler() {
|
|
119 |
@Override
|
|
120 |
public void onClick(ClickEvent event) {
|
|
121 |
createGroup();
|
|
122 |
closeDialog();
|
|
123 |
}
|
|
124 |
});
|
|
125 |
ok.addStyleName("button");
|
|
126 |
outer.add(ok);
|
|
123 |
// Create the 'Create/Update' button, along with a listener that hides the dialog
|
|
124 |
// when the button is clicked and quits the application.
|
|
125 |
String okLabel = "Create";
|
|
126 |
final Button ok = new Button(okLabel, new ClickHandler() {
|
|
127 |
@Override
|
|
128 |
public void onClick(ClickEvent event) {
|
|
129 |
createGroup();
|
|
130 |
closeDialog();
|
|
131 |
}
|
|
132 |
});
|
|
133 |
ok.addStyleName("button");
|
|
134 |
outer.add(ok);
|
|
127 | 135 |
outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
128 | 136 |
|
129 | 137 |
setWidget(outer); |
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
public void center() { |
|
134 |
super.center(); |
|
135 |
groupNameTextBox.setFocus(true); |
|
136 |
} |
|
137 |
|
|
138 |
@Override |
|
139 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
|
140 |
super.onPreviewNativeEvent(preview); |
|
141 |
|
|
142 |
NativeEvent evt = preview.getNativeEvent(); |
|
143 |
if(evt.getType().equals(KeyDownEvent.getType().getName())) |
|
144 |
// Use the popup's key preview hooks to close the dialog when either |
|
145 |
// enter or escape is pressed. |
|
146 |
{ |
|
147 |
switch(evt.getKeyCode()) { |
|
148 |
case KeyCodes.KEY_ENTER: |
|
149 |
createGroup(); |
|
150 |
closeDialog(); |
|
151 |
break; |
|
152 |
case KeyCodes.KEY_ESCAPE: |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
public void center() { |
|
142 |
super.center(); |
|
143 |
groupName.setFocus(true); |
|
144 |
} |
|
145 |
|
|
146 |
@Override |
|
147 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
|
148 |
super.onPreviewNativeEvent(preview); |
|
149 |
|
|
150 |
NativeEvent evt = preview.getNativeEvent(); |
|
151 |
if (evt.getType().equals(KeyDownEvent.getType().getName())) |
|
152 |
// Use the popup's key preview hooks to close the dialog when either |
|
153 |
// enter or escape is pressed. |
|
154 |
switch (evt.getKeyCode()) { |
|
155 |
case KeyCodes.KEY_ENTER: |
|
156 |
createGroup(); |
|
153 | 157 |
closeDialog(); |
154 |
break;
|
|
155 |
}
|
|
156 |
}
|
|
157 |
}
|
|
158 |
|
|
159 |
|
|
160 |
/** |
|
161 |
* Enables IE selection prevention and hides the dialog |
|
162 |
* (we disable the prevention on creation of the dialog)
|
|
163 |
*/
|
|
164 |
public void closeDialog() {
|
|
165 |
Pithos.preventIESelection();
|
|
166 |
hide();
|
|
167 |
if(callback != null) {
|
|
168 |
callback.execute();
|
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
/** |
|
173 |
* Generate an RPC request to create a new folder.
|
|
174 |
*/
|
|
175 |
void createGroup() {
|
|
176 |
final String groupName = groupNameTextBox.getText().trim();
|
|
177 |
if(groupName.length() == 0) {
|
|
178 |
return;
|
|
179 |
}
|
|
180 |
Group group = app.addGroup(groupName);
|
|
181 |
|
|
182 |
new AddUserCommand(app, null, group).execute();
|
|
183 |
}
|
|
158 |
break;
|
|
159 |
case KeyCodes.KEY_ESCAPE:
|
|
160 |
closeDialog();
|
|
161 |
break;
|
|
162 |
} |
|
163 |
} |
|
164 |
|
|
165 |
|
|
166 |
/**
|
|
167 |
* Enables IE selection prevention and hides the dialog
|
|
168 |
* (we disable the prevention on creation of the dialog)
|
|
169 |
*/
|
|
170 |
public void closeDialog() {
|
|
171 |
Pithos.preventIESelection();
|
|
172 |
hide();
|
|
173 |
if (callback != null)
|
|
174 |
callback.execute();
|
|
175 |
} |
|
176 |
|
|
177 |
/**
|
|
178 |
* Generate an RPC request to create a new folder.
|
|
179 |
*/
|
|
180 |
void createGroup() {
|
|
181 |
String name = groupName.getText().trim();
|
|
182 |
if (name.length() == 0)
|
|
183 |
return;
|
|
184 |
Group group = app.addGroup(name);
|
|
185 |
|
|
186 |
new AddUserCommand(app, null, group).execute();
|
|
187 |
}
|
|
184 | 188 |
} |
Also available in: Unified diff