1 | package com.gs3.testGXT.client;
|
---|
2 | import java.util.LinkedList;
|
---|
3 |
|
---|
4 | import com.google.gwt.core.client.EntryPoint;
|
---|
5 | import com.google.gwt.core.client.GWT;
|
---|
6 | import com.google.gwt.resources.client.ClientBundle;
|
---|
7 | import com.google.gwt.resources.client.ImageResource;
|
---|
8 | import com.google.gwt.user.client.rpc.AsyncCallback;
|
---|
9 | import com.google.gwt.user.client.ui.Button;
|
---|
10 | import com.google.gwt.user.client.ui.Label;
|
---|
11 | import com.google.gwt.user.client.ui.RootPanel;
|
---|
12 | import com.google.gwt.user.client.ui.Widget;
|
---|
13 | import com.gs3.testGXT.client.Keys.FileSystemKey;
|
---|
14 | import com.gs3.testGXT.client.Keys.FileSystemShortcutKey;
|
---|
15 | import com.gs3.testGXT.client.Keys.RootFileSystemKey;
|
---|
16 | import com.gs3.testGXT.client.services.StopJobsService;
|
---|
17 | import com.gs3.testGXT.client.services.StopJobsServiceAsync;
|
---|
18 | import com.gs3.testGXT.client.tree.MyLocalFileSystemTree;
|
---|
19 | import com.gs3.testGXT.client.tree.MyRemoteDropTarget;
|
---|
20 | import com.gs3.testGXT.client.tree.MyTreeDragSource;
|
---|
21 | import com.gs3.testGXT.client.tree.MyTreeStoreExt;
|
---|
22 | import com.gs3.testGXT.client.tree.RightBeforeShowContextMenuHandler;
|
---|
23 | import com.sencha.gxt.core.client.ValueProvider;
|
---|
24 | import com.sencha.gxt.core.client.util.Margins;
|
---|
25 | import com.sencha.gxt.data.shared.ModelKeyProvider;
|
---|
26 | import com.sencha.gxt.dnd.core.client.DND.Feedback;
|
---|
27 | import com.sencha.gxt.dnd.core.client.DND.Operation;
|
---|
28 | import com.sencha.gxt.dnd.core.client.TreeDragSource;
|
---|
29 | import com.sencha.gxt.dnd.core.client.TreeDropTarget;
|
---|
30 | import com.sencha.gxt.widget.core.client.ContentPanel;
|
---|
31 | import com.sencha.gxt.widget.core.client.ProgressBar;
|
---|
32 | import com.sencha.gxt.widget.core.client.TabItemConfig;
|
---|
33 | import com.sencha.gxt.widget.core.client.TabPanel;
|
---|
34 | import com.sencha.gxt.widget.core.client.box.AlertMessageBox;
|
---|
35 | import com.sencha.gxt.widget.core.client.button.IconButton;
|
---|
36 | import com.sencha.gxt.widget.core.client.button.IconButton.IconConfig;
|
---|
37 | import com.sencha.gxt.widget.core.client.button.TextButton;
|
---|
38 | import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer;
|
---|
39 | import com.sencha.gxt.widget.core.client.container.BorderLayoutContainer.BorderLayoutData;
|
---|
40 | import com.sencha.gxt.widget.core.client.container.CssFloatLayoutContainer;
|
---|
41 | import com.sencha.gxt.widget.core.client.container.CssFloatLayoutContainer.CssFloatData;
|
---|
42 | import com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer;
|
---|
43 | import com.sencha.gxt.widget.core.client.container.HorizontalLayoutContainer.HorizontalLayoutData;
|
---|
44 | import com.sencha.gxt.widget.core.client.container.MarginData;
|
---|
45 | import com.sencha.gxt.widget.core.client.container.NorthSouthContainer;
|
---|
46 | import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer;
|
---|
47 | import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer.VerticalLayoutData;
|
---|
48 | import com.sencha.gxt.widget.core.client.container.Viewport;
|
---|
49 | import com.sencha.gxt.widget.core.client.event.SelectEvent;
|
---|
50 | import com.sencha.gxt.widget.core.client.event.SelectEvent.SelectHandler;
|
---|
51 | import com.sencha.gxt.widget.core.client.menu.Menu;
|
---|
52 | import com.sencha.gxt.widget.core.client.menu.MenuBar;
|
---|
53 | import com.sencha.gxt.widget.core.client.menu.MenuBarItem;
|
---|
54 | import com.sencha.gxt.widget.core.client.menu.MenuItem;
|
---|
55 | import com.google.gwt.dom.client.Style.Float;
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Entry point classes define <code>onModuleLoad()</code>.
|
---|
59 | */
|
---|
60 | public class TestGXT implements EntryPoint {
|
---|
61 | class myKeyValuePair implements ValueProvider<FileSystemKey, FileSystemKey> {
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public FileSystemKey getValue(FileSystemKey object) {
|
---|
65 | // TODO Auto-generated method stub
|
---|
66 | return object;
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public void setValue(FileSystemKey object, FileSystemKey value) {
|
---|
71 | // TODO Auto-generated method stub
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public String getPath() {
|
---|
77 | // TODO Auto-generated method stub
|
---|
78 | return null;
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | interface TreeBundle extends ClientBundle {
|
---|
83 | ImageResource itext();
|
---|
84 | }
|
---|
85 |
|
---|
86 | interface ButtonIconBundle extends ClientBundle {
|
---|
87 | ImageResource bin();
|
---|
88 | ImageResource folder();
|
---|
89 | }
|
---|
90 |
|
---|
91 | class MyModelKeyProvider implements ModelKeyProvider<FileSystemKey> {
|
---|
92 | @Override
|
---|
93 | public String getKey(FileSystemKey item) {
|
---|
94 | return item.toKey();
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | static final String GS_DIR = "/home/nbk4/Greenstone3/web/sites/localsite/collect";
|
---|
99 | static final String GS_KEY = "collect";
|
---|
100 |
|
---|
101 | static final ProgressBar prog = new ProgressBar();
|
---|
102 | static final IconButton trash = new IconButton(new IconConfig("trash_standard", "trash_hover"));
|
---|
103 | static final IconButton folder = new IconButton(new IconConfig("folder_standard", "folder_hover"));
|
---|
104 |
|
---|
105 | public static final int REALIZING = 1;
|
---|
106 | public static final int RESOLVING = 2;
|
---|
107 | public static final int WAITING = 3;
|
---|
108 |
|
---|
109 | public static void setIndeterminate(int status) {
|
---|
110 | switch (status) {
|
---|
111 | case REALIZING : prog.updateProgress(0.01, "Realizing Files with server..."); break;
|
---|
112 | case RESOLVING : prog.updateProgress(0.02, "Resolving conflicts..."); break;
|
---|
113 | case WAITING : prog.updateProgress(0.03, "Waiting for response from server..."); break;
|
---|
114 | }
|
---|
115 | }
|
---|
116 |
|
---|
117 | public static void setProgress(double progress, String str) {
|
---|
118 | prog.updateProgress(progress*0.97 + 0.03, str);
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * This is the entry point method.
|
---|
123 | */
|
---|
124 | public void onModuleLoad() {
|
---|
125 | TreeBundle bundle = GWT.create(TreeBundle.class);
|
---|
126 |
|
---|
127 | MyTreeStoreExt mtsR = new MyTreeStoreExt(new MyModelKeyProvider());
|
---|
128 | MyTreeStoreExt mtsL = new MyTreeStoreExt(new MyModelKeyProvider());
|
---|
129 |
|
---|
130 | /** local filespace */
|
---|
131 | mtsL.add(new RootFileSystemKey());
|
---|
132 | /** home folder */
|
---|
133 | mtsL.add(new FileSystemShortcutKey("/home/nbk4", "home"));
|
---|
134 | mtsL.add(new FileSystemShortcutKey("/home/nbk4/Dummy Files", "dummy files"));
|
---|
135 | mtsL.add(new FileSystemShortcutKey("/home/nbk4/Greenstone3/web/sites/localsite/collect", "localsites:collect"));
|
---|
136 | /** collections folder */
|
---|
137 | mtsR.add(new FileSystemShortcutKey(GS_DIR, "Collections"));
|
---|
138 |
|
---|
139 | final MyLocalFileSystemTree mtreeL = new MyLocalFileSystemTree(mtsL, new myKeyValuePair());
|
---|
140 |
|
---|
141 | //mtreeL.getCell().
|
---|
142 | //mtreeL.getAppearance().
|
---|
143 | final MyLocalFileSystemTree mtreeR = new MyLocalFileSystemTree(mtsR, new myKeyValuePair());
|
---|
144 |
|
---|
145 | mtreeR.getStyle().setLeafIcon(bundle.itext());
|
---|
146 | mtreeL.getStyle().setLeafIcon(bundle.itext());
|
---|
147 | TreeDragSource<FileSystemKey> tds = new TreeDragSource<FileSystemKey>(mtreeL);
|
---|
148 | TreeDropTarget<FileSystemKey> target = new MyRemoteDropTarget(mtreeR);
|
---|
149 |
|
---|
150 | target.setGroup("copy");
|
---|
151 | tds.setGroup("copy");
|
---|
152 | target.setFeedback(Feedback.BOTH);
|
---|
153 | target.setOperation(Operation.COPY);
|
---|
154 | target.setAllowDropOnLeaf(false);
|
---|
155 | target.setAllowSelfAsSource(true);
|
---|
156 | TreeDragSource<FileSystemKey> rightDragMove = new MyTreeDragSource(mtreeR);
|
---|
157 | TreeDropTarget<FileSystemKey> rightDropMove = new MyRemoteDropTarget(mtreeR);
|
---|
158 |
|
---|
159 | rightDragMove.setGroup("reorder");
|
---|
160 | rightDropMove.setGroup("reorder");
|
---|
161 | rightDropMove.setFeedback(Feedback.APPEND);
|
---|
162 | rightDropMove.setOperation(Operation.MOVE);
|
---|
163 | rightDropMove.setAllowDropOnLeaf(false);
|
---|
164 | rightDropMove.setAllowSelfAsSource(true);
|
---|
165 |
|
---|
166 | mtreeL.addStyleName("tree_style");
|
---|
167 |
|
---|
168 | ContentPanel leftPanel = new ContentPanel();
|
---|
169 | leftPanel.setHeading("Remote Workspace");
|
---|
170 | leftPanel.add(mtreeL);
|
---|
171 |
|
---|
172 | ContentPanel botPanel = new ContentPanel();
|
---|
173 | botPanel.setHeaderVisible(false);
|
---|
174 |
|
---|
175 | Viewport LoadingBar = getLoadingBarPanelViewport();
|
---|
176 | Viewport ActionBar = getActionBarPanelViewport();
|
---|
177 |
|
---|
178 | Viewport ActionPane = getNorthSouthPanelViewport(ActionBar, LoadingBar);
|
---|
179 | botPanel.add(ActionPane);//new Label("Action bar and buttons placeholder"));
|
---|
180 |
|
---|
181 | ContentPanel rightPanel = new ContentPanel();
|
---|
182 | rightPanel.setHeading("Collection");
|
---|
183 | rightPanel.add(mtreeR);
|
---|
184 |
|
---|
185 | Viewport v = GetSplitViewport(leftPanel, rightPanel, botPanel);
|
---|
186 |
|
---|
187 | TabPanel panel = getTabbedPanel(new Label(""), v, new Label(""), new Label(""), new Label(""), new Label(""));
|
---|
188 |
|
---|
189 | v = new Viewport();
|
---|
190 | v.add(panel);
|
---|
191 |
|
---|
192 | v = getMenuViewport(v);
|
---|
193 |
|
---|
194 | panel.setActiveWidget(panel.getWidget(1));
|
---|
195 |
|
---|
196 | RootPanel.get().add(v);
|
---|
197 |
|
---|
198 | Menu contextMenu = new Menu();
|
---|
199 | contextMenu.setWidth(400);
|
---|
200 | mtreeR.setContextMenu(contextMenu);
|
---|
201 |
|
---|
202 | final MenuItem[] menuItems = getMenuItems();
|
---|
203 |
|
---|
204 | for(MenuItem menuItem : menuItems) {
|
---|
205 | contextMenu.add(menuItem);
|
---|
206 | }
|
---|
207 |
|
---|
208 | mtreeR.addBeforeShowContextMenuHandler(new RightBeforeShowContextMenuHandler(menuItems, mtreeR));
|
---|
209 | }
|
---|
210 |
|
---|
211 | //Essentially, everything below here is various ways of condensing things into panels and layouts.
|
---|
212 | private Viewport getNorthSouthPanelViewport(Viewport ActionBar, Viewport LoadingBar) {
|
---|
213 | String width = "80px";
|
---|
214 | String height = "80px";
|
---|
215 |
|
---|
216 | VerticalLayoutContainer vlc = new VerticalLayoutContainer();
|
---|
217 |
|
---|
218 | vlc.add(ActionBar, new VerticalLayoutData(1, 0.6));
|
---|
219 | vlc.add(LoadingBar, new VerticalLayoutData(1, 0.4));
|
---|
220 |
|
---|
221 | HorizontalLayoutContainer hlc = new HorizontalLayoutContainer();
|
---|
222 | hlc.add(vlc, new HorizontalLayoutData(1, 1, new Margins(5, 10, 10, 10)));
|
---|
223 | hlc.add(trash, new HorizontalLayoutData(85, 1, new Margins(5, 5, 5, 0)));
|
---|
224 | hlc.add(folder, new HorizontalLayoutData(85, 1, new Margins(5, 5, 5, 0)));
|
---|
225 |
|
---|
226 | Viewport vout = new Viewport();
|
---|
227 | vout.add(hlc, new MarginData(5));
|
---|
228 | return vout;
|
---|
229 | }
|
---|
230 |
|
---|
231 | private Viewport getActionBarPanelViewport() {
|
---|
232 | CssFloatLayoutContainer floatContainer = new CssFloatLayoutContainer();
|
---|
233 |
|
---|
234 |
|
---|
235 | floatContainer.setStyleFloat(Float.RIGHT);
|
---|
236 |
|
---|
237 | TextButton stopButton = new TextButton("Stop");
|
---|
238 | stopButton.setWidth("80px");
|
---|
239 | stopButton.setHeight("30px");
|
---|
240 |
|
---|
241 | stopButton.addSelectHandler(new SelectHandler() {
|
---|
242 | private StopJobsServiceAsync serv = GWT.create(StopJobsService.class);
|
---|
243 | @Override
|
---|
244 | public void onSelect(SelectEvent event) {
|
---|
245 | AsyncCallback<String> callback = new AsyncCallback<String>() {
|
---|
246 |
|
---|
247 | @Override
|
---|
248 | public void onFailure(Throwable caught) {
|
---|
249 | AlertMessageBox amb = new AlertMessageBox("Error", "Error: " + caught.getMessage()); //TODO: this is going to be messy - fix
|
---|
250 | amb.show();
|
---|
251 | }
|
---|
252 |
|
---|
253 | @Override
|
---|
254 | public void onSuccess(String result) {
|
---|
255 | //do nothing - the response handling is done elsewhere (although it could be moved here, there
|
---|
256 | //may be some weird rare edge case synchronization issues: ie, job cancelled, then we get final
|
---|
257 | //progress update - it was still a valid update, and will overwrite progress bar if set here)
|
---|
258 | }
|
---|
259 | };
|
---|
260 |
|
---|
261 | serv.cancelAllJobs(callback);
|
---|
262 | }
|
---|
263 | });
|
---|
264 |
|
---|
265 | floatContainer.add(stopButton, new CssFloatData(80));
|
---|
266 |
|
---|
267 | Label actionLabel = new Label("Current Action");
|
---|
268 |
|
---|
269 | floatContainer.add(actionLabel, new CssFloatData(1));
|
---|
270 |
|
---|
271 | Viewport outport = new Viewport();
|
---|
272 |
|
---|
273 | outport.add(floatContainer);
|
---|
274 |
|
---|
275 | return outport;
|
---|
276 | }
|
---|
277 |
|
---|
278 | private Viewport getLoadingBarPanelViewport() {
|
---|
279 | Viewport v = new Viewport();
|
---|
280 |
|
---|
281 | prog.setIncrement(8); //not actually sure what increment does...
|
---|
282 | prog.updateProgress(0, "No current actions");
|
---|
283 | prog.setHeight(60);
|
---|
284 |
|
---|
285 | v.add(prog);
|
---|
286 | return v;
|
---|
287 | }
|
---|
288 |
|
---|
289 | private Viewport getMenuViewport(Viewport v) {
|
---|
290 | //TODO: THIS PART
|
---|
291 | MenuBar m = new MenuBar();
|
---|
292 | Menu testMenu = new Menu();
|
---|
293 | testMenu.add(new MenuItem("Test1"));
|
---|
294 | testMenu.add(new MenuItem("Test2"));
|
---|
295 | testMenu.add(new MenuItem("Test3"));
|
---|
296 | m.add(new MenuBarItem("File", testMenu));
|
---|
297 |
|
---|
298 | NorthSouthContainer nsc = new NorthSouthContainer();
|
---|
299 | nsc.setNorthWidget(m);
|
---|
300 | nsc.setSouthWidget(v);
|
---|
301 | v = new Viewport();
|
---|
302 | v.add(nsc);
|
---|
303 |
|
---|
304 | return v;
|
---|
305 | }
|
---|
306 | //Separated out for convenience: dumps the six items, in order, into a tabbed panel with the specified names
|
---|
307 | private TabPanel getTabbedPanel(Widget upload, Widget gather, Widget enrich, Widget design, Widget create, Widget format) {
|
---|
308 | TabPanel panel = new TabPanel();
|
---|
309 |
|
---|
310 | panel.setTabScroll(true);
|
---|
311 | panel.setTabWidth(240);
|
---|
312 | panel.setResizeTabs(false);
|
---|
313 | panel.setAnimScroll(true);
|
---|
314 |
|
---|
315 | panel.add(upload, new TabItemConfig(" Upload ", false));
|
---|
316 | panel.add(gather, new TabItemConfig(" Gather ", false));
|
---|
317 | panel.add(enrich, new TabItemConfig(" Enrich ", false));
|
---|
318 | panel.add(design, new TabItemConfig(" Design ", false));
|
---|
319 | panel.add(create, new TabItemConfig(" Create ", false));
|
---|
320 | panel.add(format, new TabItemConfig(" Format ", false));
|
---|
321 |
|
---|
322 | return panel;
|
---|
323 | }
|
---|
324 |
|
---|
325 | private Viewport GetSplitViewport(ContentPanel left, ContentPanel right, ContentPanel bot) {
|
---|
326 | BorderLayoutContainer con = new BorderLayoutContainer();
|
---|
327 |
|
---|
328 | //LEFT WIDGET: GATHER PANEL
|
---|
329 | BorderLayoutData d = new BorderLayoutData(370);
|
---|
330 | d.setMinSize(100);
|
---|
331 | d.setMargins(new Margins(0, 5, 5, 5));
|
---|
332 | d.setCollapsible(true);
|
---|
333 | d.setFloatable(false);
|
---|
334 | d.setSplit(true);
|
---|
335 | con.setWestWidget(left, d);
|
---|
336 |
|
---|
337 | //SOUTH WIDGET: ACTION BAR REGION
|
---|
338 | d = new BorderLayoutData(120);
|
---|
339 | d.setMargins(new Margins(0, 5, 5, 5));
|
---|
340 | d.setSplit(false);
|
---|
341 | d.setCollapsible(false);
|
---|
342 | con.setSouthWidget(bot, d);
|
---|
343 |
|
---|
344 | //CENTER WIDGET: COLLECTION INTERFACE
|
---|
345 | d = new BorderLayoutData();
|
---|
346 | d.setMargins(new Margins(0, 5, 5, 0));
|
---|
347 | con.setCenterWidget(right, d);
|
---|
348 |
|
---|
349 |
|
---|
350 | Viewport v = new Viewport();
|
---|
351 | v.add(con);
|
---|
352 |
|
---|
353 | return v;
|
---|
354 | }
|
---|
355 |
|
---|
356 | private MenuItem[] getMenuItems() {
|
---|
357 | MenuItem folder = new MenuItem();
|
---|
358 | folder.setText("New Folder");
|
---|
359 |
|
---|
360 | MenuItem close = new MenuItem();
|
---|
361 | close.setText("Close Folder");
|
---|
362 |
|
---|
363 | MenuItem metadata = new MenuItem();
|
---|
364 | metadata.setText("Assigned metadata for the current items");
|
---|
365 |
|
---|
366 | MenuItem delete = new MenuItem();
|
---|
367 | delete.setText("Delete");
|
---|
368 |
|
---|
369 | MenuItem rename = new MenuItem();
|
---|
370 | rename.setText("Rename");
|
---|
371 |
|
---|
372 | MenuItem replace = new MenuItem();
|
---|
373 | replace.setText("Replace...");
|
---|
374 |
|
---|
375 | MenuItem dummy = new MenuItem();
|
---|
376 | dummy.setText("New dummy document");
|
---|
377 |
|
---|
378 | MenuItem refresh = new MenuItem();
|
---|
379 | refresh.setText("Refresh Folder");
|
---|
380 |
|
---|
381 | final MenuItem[] menuItems = new MenuItem[8];
|
---|
382 | menuItems[0] = metadata;
|
---|
383 | menuItems[1] = delete;
|
---|
384 | menuItems[2] = rename;
|
---|
385 | menuItems[3] = close; //also doubles as open
|
---|
386 | menuItems[4] = folder;
|
---|
387 | menuItems[5] = dummy;
|
---|
388 | menuItems[6] = replace;
|
---|
389 | menuItems[7] = refresh;
|
---|
390 |
|
---|
391 | return menuItems;
|
---|
392 | }
|
---|
393 | }
|
---|