Revision e6b93be1
b/src/gr/grnet/pithos/web/client/ColumnResizeHelper.java | ||
---|---|---|
1 |
package gr.grnet.pithos.web.client; |
|
2 |
|
|
3 |
import com.google.gwt.dom.client.Element; |
|
4 |
import com.google.gwt.dom.client.NativeEvent; |
|
5 |
import com.google.gwt.dom.client.Node; |
|
6 |
import com.google.gwt.dom.client.NodeList; |
|
7 |
import com.google.gwt.event.shared.HandlerRegistration; |
|
8 |
import com.google.gwt.user.cellview.client.AbstractCellTable; |
|
9 |
import com.google.gwt.user.cellview.client.Column; |
|
10 |
import com.google.gwt.user.client.Event; |
|
11 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
|
12 |
import com.google.gwt.user.client.Event.NativePreviewHandler; |
|
13 |
|
|
14 |
public class ColumnResizeHelper<T> implements NativePreviewHandler { |
|
15 |
|
|
16 |
private HandlerRegistration handler; |
|
17 |
private AbstractCellTable<T> table; |
|
18 |
private Column<T, ?> col; |
|
19 |
private Element el; |
|
20 |
|
|
21 |
public static <T> void handleResize(AbstractCellTable<T> table, NativeEvent event) { |
|
22 |
String eventType = event.getType(); |
|
23 |
if (eventType.equals("mousedown")) { |
|
24 |
int clientX = event.getClientX(); |
|
25 |
Element eventTargetEl = event.getEventTarget().cast(); |
|
26 |
int absoluteLeft = eventTargetEl.getAbsoluteLeft(); |
|
27 |
int offsetWidth = eventTargetEl.getOffsetWidth(); |
|
28 |
if (clientX > absoluteLeft + offsetWidth - 10) { |
|
29 |
// Get column |
|
30 |
NodeList<Node> nodes = eventTargetEl.getParentElement().getChildNodes(); |
|
31 |
for (int i = 0; i < nodes.getLength(); i++) { |
|
32 |
if (nodes.getItem(i).equals(eventTargetEl)) { |
|
33 |
event.preventDefault(); |
|
34 |
event.stopPropagation(); |
|
35 |
new ColumnResizeHelper<T>(table, table.getColumn(i), eventTargetEl); |
|
36 |
break; |
|
37 |
} |
|
38 |
} |
|
39 |
return; |
|
40 |
} |
|
41 |
} |
|
42 |
} |
|
43 |
|
|
44 |
private ColumnResizeHelper(AbstractCellTable<T> table, Column<T, ?> col, Element el) { |
|
45 |
this.el = el; |
|
46 |
this.table = table; |
|
47 |
this.col = col; |
|
48 |
handler = Event.addNativePreviewHandler(this); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public void onPreviewNativeEvent(NativePreviewEvent event) { |
|
53 |
NativeEvent nativeEvent = event.getNativeEvent(); |
|
54 |
nativeEvent.preventDefault(); |
|
55 |
nativeEvent.stopPropagation(); |
|
56 |
|
|
57 |
if (nativeEvent.getType().equals("mousemove")) { |
|
58 |
int absoluteLeft = el.getAbsoluteLeft(); |
|
59 |
int clientX = nativeEvent.getClientX(); |
|
60 |
int newWidth = clientX - absoluteLeft; |
|
61 |
newWidth = newWidth < 10 ? 10 : newWidth; |
|
62 |
table.setColumnWidth(col, newWidth + "px"); |
|
63 |
} else if (nativeEvent.getType().equals("mouseup")) { |
|
64 |
handler.removeHandler(); |
|
65 |
} |
|
66 |
} |
|
67 |
} |
b/src/gr/grnet/pithos/web/client/FileList.java | ||
---|---|---|
271 | 271 |
return super.getCellStyleNames(context, object); |
272 | 272 |
} |
273 | 273 |
}; |
274 |
celltable.addColumn(status,"");
|
|
274 |
celltable.addColumn(status, new ResizableHeader<File>("", celltable, status));
|
|
275 | 275 |
|
276 | 276 |
final Column<File,SafeHtml> nameColumn = new Column<File,SafeHtml>(new SafeHtmlCell()) { |
277 | 277 |
|
... | ... | |
288 | 288 |
} |
289 | 289 |
|
290 | 290 |
}; |
291 |
celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name"));
|
|
291 |
celltable.addColumn(nameColumn, nameHeader = new ResizableHeader<File>("Name", celltable, nameColumn));
|
|
292 | 292 |
allHeaders.add(nameHeader); |
293 | 293 |
nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name")); |
294 | 294 |
|
b/src/gr/grnet/pithos/web/client/Pithos.java | ||
---|---|---|
53 | 53 |
import gr.grnet.pithos.web.client.rest.HeadRequest; |
54 | 54 |
import gr.grnet.pithos.web.client.rest.PutRequest; |
55 | 55 |
import gr.grnet.pithos.web.client.rest.RestException; |
56 |
import gr.grnet.pithos.web.client.tagtree.Tag; |
|
57 | 56 |
|
58 | 57 |
import java.util.ArrayList; |
59 | 58 |
import java.util.HashMap; |
... | ... | |
64 | 63 |
import com.google.gwt.core.client.EntryPoint; |
65 | 64 |
import com.google.gwt.core.client.GWT; |
66 | 65 |
import com.google.gwt.core.client.Scheduler; |
66 |
import com.google.gwt.core.client.Scheduler.RepeatingCommand; |
|
67 | 67 |
import com.google.gwt.core.client.Scheduler.ScheduledCommand; |
68 | 68 |
import com.google.gwt.event.dom.client.ClickEvent; |
69 | 69 |
import com.google.gwt.event.dom.client.ClickHandler; |
... | ... | |
459 | 459 |
} |
460 | 460 |
}); |
461 | 461 |
|
462 |
// Scheduler.get().scheduleDeferred(new Command() { |
|
463 |
// |
|
464 |
// @Override |
|
465 |
// public void execute() { |
|
466 |
// displayError("lalala"); |
|
467 |
// |
|
468 |
// } |
|
469 |
// }); |
|
462 |
Scheduler.get().scheduleFixedDelay(new RepeatingCommand() { |
|
463 |
|
|
464 |
@Override |
|
465 |
public boolean execute() { |
|
466 |
Folder f = getSelection(); |
|
467 |
if (f != null) { |
|
468 |
if (getSelectedTree().equals(folderTreeView)) |
|
469 |
updateFolder(f, true, null); |
|
470 |
else if (getSelectedTree().equals(mysharedTreeView)) |
|
471 |
updateSharedFolder(f, true); |
|
472 |
else if (getSelectedTree().equals(otherSharedTreeView)) |
|
473 |
updateOtherSharedFolder(f, true); |
|
474 |
} |
|
475 |
return true; |
|
476 |
} |
|
477 |
}, 3000); |
|
470 | 478 |
} |
471 | 479 |
|
472 | 480 |
public void applyPermissions(Folder f) { |
b/src/gr/grnet/pithos/web/client/ResizableHeader.java | ||
---|---|---|
1 |
package gr.grnet.pithos.web.client; |
|
2 |
|
|
3 |
|
|
4 |
import com.google.gwt.cell.client.AbstractCell; |
|
5 |
import com.google.gwt.cell.client.Cell.Context; |
|
6 |
import com.google.gwt.dom.client.Element; |
|
7 |
import com.google.gwt.dom.client.NativeEvent; |
|
8 |
import com.google.gwt.dom.client.Style.Cursor; |
|
9 |
import com.google.gwt.event.shared.HandlerRegistration; |
|
10 |
import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
|
11 |
import com.google.gwt.safehtml.shared.SafeHtmlUtils; |
|
12 |
import com.google.gwt.user.cellview.client.AbstractCellTable; |
|
13 |
import com.google.gwt.user.cellview.client.Column; |
|
14 |
import com.google.gwt.user.client.Event; |
|
15 |
import com.google.gwt.user.client.Event.NativePreviewEvent; |
|
16 |
import com.google.gwt.user.client.Event.NativePreviewHandler; |
|
17 |
|
|
18 |
public class ResizableHeader<T> extends SortableHeader { |
|
19 |
|
|
20 |
private Column<T, ?> column = null; |
|
21 |
private AbstractCellTable<T> cellTable; |
|
22 |
private String title = ""; |
|
23 |
static private final int width = 10; |
|
24 |
|
|
25 |
public ResizableHeader(String title, AbstractCellTable<T> cellTable, Column<T, ?> column) { |
|
26 |
super(title); |
|
27 |
this.title = title; |
|
28 |
this.cellTable = cellTable; |
|
29 |
this.column = column; |
|
30 |
} |
|
31 |
|
|
32 |
@Override |
|
33 |
public String getValue() |
|
34 |
{ |
|
35 |
return title; |
|
36 |
} |
|
37 |
|
|
38 |
@Override |
|
39 |
public void onBrowserEvent(Context context, Element target, NativeEvent event) { |
|
40 |
String eventType = event.getType(); |
|
41 |
int clientX = event.getClientX(); |
|
42 |
int absoluteLeft = target.getAbsoluteLeft(); |
|
43 |
int offsetWidth = target.getOffsetWidth(); |
|
44 |
if (clientX > absoluteLeft + offsetWidth - width) { |
|
45 |
setCursor(target, Cursor.COL_RESIZE); |
|
46 |
} else { |
|
47 |
setCursor(target, Cursor.DEFAULT); |
|
48 |
} |
|
49 |
if(eventType.equals("mousedown")) { |
|
50 |
if (clientX > absoluteLeft + offsetWidth - width) { |
|
51 |
new ColumnResizeHelper<T>(cellTable, column, target); |
|
52 |
} |
|
53 |
event.preventDefault(); |
|
54 |
event.stopPropagation(); |
|
55 |
} else { |
|
56 |
return; |
|
57 |
} |
|
58 |
} |
|
59 |
|
|
60 |
private void setCursor(Element element, Cursor cursor) { |
|
61 |
element.getStyle().setCursor(cursor); |
|
62 |
} |
|
63 |
|
|
64 |
class ColumnResizeHelper<T> implements NativePreviewHandler { |
|
65 |
|
|
66 |
private HandlerRegistration handler; |
|
67 |
private AbstractCellTable<T> table; |
|
68 |
private Column<T, ?> col; |
|
69 |
private Element el; |
|
70 |
|
|
71 |
public ColumnResizeHelper(AbstractCellTable<T> table, Column<T, ?> col, Element el) { |
|
72 |
this.el = el; |
|
73 |
this.table = table; |
|
74 |
this.col = col; |
|
75 |
handler = Event.addNativePreviewHandler(this); |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public void onPreviewNativeEvent(NativePreviewEvent event) { |
|
80 |
NativeEvent nativeEvent = event.getNativeEvent(); |
|
81 |
nativeEvent.preventDefault(); |
|
82 |
nativeEvent.stopPropagation(); |
|
83 |
|
|
84 |
if (nativeEvent.getType().equals("mousemove")) { |
|
85 |
int absoluteLeft = el.getAbsoluteLeft(); |
|
86 |
int clientX = nativeEvent.getClientX(); |
|
87 |
int newWidth = clientX - absoluteLeft; |
|
88 |
newWidth = newWidth < 10 ? 10 : newWidth; |
|
89 |
table.setColumnWidth(col, newWidth + "px"); |
|
90 |
} else if (nativeEvent.getType().equals("mouseup")) { |
|
91 |
handler.removeHandler(); |
|
92 |
} |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
static class HeaderCell extends AbstractCell<String> { |
|
97 |
|
|
98 |
public HeaderCell() { |
|
99 |
super("click", "mousedown", "mousemove"); |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public void render(com.google.gwt.cell.client.Cell.Context context, String value, SafeHtmlBuilder sb) { |
|
104 |
sb.append( |
|
105 |
new SafeHtmlBuilder() |
|
106 |
.append(SafeHtmlUtils.fromString(value)) |
|
107 |
.toSafeHtml()); |
|
108 |
} |
|
109 |
|
|
110 |
} |
|
111 |
}; |
|
112 |
|
|
113 |
|
Also available in: Unified diff