import java.util.List;\r
\r
import com.google.gwt.core.client.GWT;\r
+import com.google.gwt.dom.client.NativeEvent;\r
+import com.google.gwt.event.dom.client.ContextMenuEvent;\r
+import com.google.gwt.event.dom.client.ContextMenuHandler;\r
+import com.google.gwt.event.logical.shared.OpenEvent;\r
+import com.google.gwt.event.logical.shared.OpenHandler;\r
+import com.google.gwt.event.logical.shared.SelectionEvent;\r
+import com.google.gwt.event.logical.shared.SelectionHandler;\r
+import com.google.gwt.resources.client.ClientBundle;\r
+import com.google.gwt.resources.client.ImageResource;\r
import com.google.gwt.user.client.DOM;\r
import com.google.gwt.user.client.DeferredCommand;\r
import com.google.gwt.user.client.Event;\r
import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
import com.google.gwt.user.client.ui.Composite;\r
import com.google.gwt.user.client.ui.HTML;\r
-import com.google.gwt.user.client.ui.KeyboardListener;\r
import com.google.gwt.user.client.ui.Tree;\r
-import com.google.gwt.user.client.ui.TreeImages;\r
import com.google.gwt.user.client.ui.TreeItem;\r
-import com.google.gwt.user.client.ui.TreeListener;\r
\r
/**\r
* A component that displays a list of the user's groups.\r
*/\r
-public class Groups extends Composite implements TreeListener {\r
+public class Groups extends Composite implements SelectionHandler, OpenHandler {\r
\r
/**\r
* An image bundle for this widget.\r
*/\r
- public interface Images extends TreeImages, FileMenu.Images, EditMenu.Images, GroupMenu.Images, MessagePanel.Images {\r
+ public interface Images extends Tree.Resources, ClientBundle, FileMenu.Images, EditMenu.Images, GroupMenu.Images, MessagePanel.Images {\r
\r
/**\r
* Will bundle the file 'groupevent.png' residing in the package\r
*\r
* @return the image prototype\r
*/\r
- @Resource("gr/ebs/gss/resources/groupevent.png")\r
- AbstractImagePrototype groupImage();\r
+ @Source("gr/ebs/gss/resources/groupevent.png")\r
+ ImageResource groupImage();\r
\r
- @Resource("gr/ebs/gss/resources/editdelete.png")\r
- AbstractImagePrototype delete();\r
- }\r
- private boolean ctrlKeyPressed = false;\r
-\r
- private boolean leftClicked = false;\r
+ @Override\r
+ @Source("gr/ebs/gss/resources/editdelete.png")\r
+ ImageResource delete();\r
\r
- private boolean rightClicked = false;\r
+ }\r
\r
+ /**\r
+ * cached latest group selection (for selecting and expanding on refresh)\r
+ */\r
+ private String selectedGroup = null;\r
\r
/**\r
* The tree widget that displays the groups.\r
private TreeItem previous;\r
\r
/**\r
- * A cached copy of the currently changed group widget.\r
- */\r
- private TreeItem changed;\r
-\r
- /**\r
* The widget's image bundle.\r
*/\r
private final Images images;\r
\r
private GroupContextMenu menu;\r
+\r
/**\r
* Constructs a new groups widget with a bundle of images.\r
*\r
images = newImages;\r
menu = new GroupContextMenu(images);\r
tree = new Tree(newImages);\r
- tree.addTreeListener(this);\r
+ this.addHandler(new ContextMenuHandler() {\r
+\r
+ @Override\r
+ public void onContextMenu(ContextMenuEvent event) {\r
+ if(current==null) return;\r
+ int left = current.getAbsoluteLeft() + 40;\r
+ int top = current.getAbsoluteTop() + 20;\r
+ showPopup(left, top);\r
+\r
+ }\r
+ }, ContextMenuEvent.getType());\r
+ tree.addSelectionHandler(this);\r
+ tree.addOpenHandler(this);\r
+ tree.setAnimationEnabled(true);\r
initWidget(tree);\r
setStylePrimaryName("gss-Groups");\r
sinkEvents(Event.ONCONTEXTMENU);\r
sinkEvents(Event.ONMOUSEUP);\r
+ sinkEvents(Event.ONDBLCLICK);\r
}\r
\r
- public void onBrowserEvent(Event event) {\r
- switch (DOM.eventGetType(event)) {\r
- case Event.ONKEYDOWN:\r
- int key = DOM.eventGetKeyCode(event);\r
- if (key == KeyboardListener.KEY_CTRL)\r
- ctrlKeyPressed = true;\r
- break;\r
-\r
- case Event.ONKEYUP:\r
- key = DOM.eventGetKeyCode(event);\r
- if (key == KeyboardListener.KEY_CTRL)\r
- ctrlKeyPressed = false;\r
- break;\r
-\r
- case Event.ONMOUSEDOWN:\r
- if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT)\r
- rightClicked = true;\r
- else if (DOM.eventGetButton(event) == Event.BUTTON_LEFT)\r
- leftClicked = true;\r
- break;\r
-\r
- case Event.ONMOUSEUP:\r
- if (DOM.eventGetButton(event) == Event.BUTTON_RIGHT)\r
- rightClicked = false;\r
- else if (DOM.eventGetButton(event) == Event.BUTTON_LEFT)\r
- leftClicked = false;\r
- break;\r
- }\r
\r
- super.onBrowserEvent(event);\r
- }\r
/**\r
* Make an RPC call to retrieve the groups that belong to the specified\r
* user.\r
- *\r
- * @param userId the user ID\r
*/\r
public void updateGroups() {\r
- GetCommand<GroupsResource> gg = new GetCommand<GroupsResource>(GroupsResource.class, GSS.get().getCurrentUserResource().getGroupsPath()){\r
+ GetCommand<GroupsResource> gg = new GetCommand<GroupsResource>(GroupsResource.class, GSS.get().getCurrentUserResource().getGroupsPath(),null){\r
\r
+ @Override\r
public void onComplete() {\r
GroupsResource res = getResult();\r
- MultipleGetCommand<GroupResource> ga = new MultipleGetCommand<GroupResource>(GroupResource.class, res.getGroupPaths().toArray(new String[]{})){\r
+ MultipleGetCommand<GroupResource> ga = new MultipleGetCommand<GroupResource>(GroupResource.class, res.getGroupPaths().toArray(new String[]{}), null){\r
\r
+ @Override\r
public void onComplete() {\r
List<GroupResource> groupList = getResult();\r
tree.clear();\r
for (int i = 0; i < groupList.size(); i++) {\r
- final TreeItem item = new TreeItem(imageItemHTML(images.groupImage(), groupList.get(i).getName()));\r
- item.setUserObject(groupList.get(i));\r
+ final TreeItem item = new TreeItem();\r
+ item.setWidget(imageItemHTML(images.groupImage(), groupList.get(i).getName(),item));\r
+ item.setUserObject(groupList.get(i)); \r
+// item.getElement().setId("groupsList."+ groupList.get(i).getName());\r
tree.addItem(item);\r
- updateUsers( item);\r
+ updateUsers(item);\r
}\r
}\r
\r
-\r
+ @Override\r
public void onError(Throwable t) {\r
GWT.log("", t);\r
}\r
\r
+ @Override\r
public void onError(String p, Throwable throwable) {\r
GWT.log("Path:"+p, throwable);\r
}\r
DeferredCommand.addCommand(ga);\r
}\r
\r
-\r
+ @Override\r
public void onError(Throwable t) {\r
\r
}\r
};\r
DeferredCommand.addCommand(gg);\r
- /*\r
- GetGroupsCommand gg = new GetGroupsCommand(GSS.get().getCurrentUserResource().getGroupsPath()){\r
-\r
- public void onComplete() {\r
- GroupsResource res = getResource();\r
- GetAllGroupsCommand ga = new GetAllGroupsCommand(res.getGroupPaths().toArray(new String[]{})){\r
-\r
- public void onComplete() {\r
- List<GroupResource> groupList = getList();\r
- tree.clear();\r
- for (int i = 0; i < groupList.size(); i++) {\r
- final TreeItem item = new TreeItem(imageItemHTML(images.groupImage(), groupList.get(i).getName()));\r
- item.setUserObject(groupList.get(i));\r
- tree.addItem(item);\r
- updateUsers( item);\r
- }\r
- }\r
- };\r
- DeferredCommand.addCommand(ga);\r
- }\r
- };\r
- DeferredCommand.addCommand(gg);*/\r
-\r
}\r
\r
/**\r
GSS.get().getStatusPanel().updateCurrentlyShowing(null); //clear stats - nothing to show for the groups tab\r
}\r
\r
-\r
/**\r
* A helper method to simplify adding tree items that have attached images.\r
* {@link #addImageItem(TreeItem, String) code}\r
* @param imageProto\r
* @return the new tree item\r
*/\r
- private TreeItem addImageItem(final TreeItem parent, final String title, final AbstractImagePrototype imageProto) {\r
- final TreeItem item = new TreeItem(imageItemHTML(imageProto, title));\r
+ private TreeItem addImageItem(final TreeItem parent, final String title, final ImageResource imageProto) {\r
+ final TreeItem item = new TreeItem();\r
+ item.setWidget(imageItemHTML(imageProto, title,item));\r
parent.addItem(item);\r
return item;\r
}\r
* @param title the title of the item\r
* @return the resultant HTML\r
*/\r
- private HTML imageItemHTML(final AbstractImagePrototype imageProto, final String title) {\r
- final HTML link = new HTML("<a class='hidden-link' href='javascript:;'>" + "<span>" + imageProto.getHTML() + " " + title + "</span>" + "</a>");\r
+ private HTML imageItemHTML(final ImageResource imageProto, final String title,final TreeItem item) {\r
+ final HTML link = new HTML("<a id='groupsList."+title+"' class='hidden-link' href='javascript:;'>" + "<span>" + AbstractImagePrototype.create(imageProto).getHTML() + " " + title + "</span>" + "</a>"){\r
+ @Override\r
+ public void onBrowserEvent(Event event) {\r
+ switch (DOM.eventGetType(event)) {\r
+ case Event.ONMOUSEDOWN:\r
+ if (DOM.eventGetButton(event) == NativeEvent.BUTTON_RIGHT || DOM.eventGetButton(event) == NativeEvent.BUTTON_LEFT)\r
+ onSelection(item);\r
+ break;\r
+ }\r
+ super.onBrowserEvent(event);\r
+\r
+ }\r
+ };\r
+ link.sinkEvents(Event.ONMOUSEDOWN);\r
return link;\r
}\r
\r
- /*\r
- * (non-Javadoc)\r
- *\r
- * @see com.google.gwt.user.client.ui.TreeListener#onTreeItemSelected(com.google.gwt.user.client.ui.TreeItem)\r
- */\r
- public void onTreeItemSelected(final TreeItem item) {\r
- final Object selected = item.getUserObject();\r
- // Preserve the previously selected item, so that the current's\r
- // onClick() method gets a chance to find it.\r
- if (getPrevious() != null)\r
- getPrevious().getWidget().removeStyleName("gss-SelectedRow");\r
- setCurrent(item);\r
- getCurrent().getWidget().addStyleName("gss-SelectedRow");\r
- setPrevious(getCurrent());\r
- GSS.get().setCurrentSelection(selected);\r
- if (rightClicked) {\r
- int left = item.getAbsoluteLeft() + 40;\r
- int top = item.getAbsoluteTop() + 20;\r
- showPopup(left, top);\r
- }\r
- }\r
+\r
\r
protected void showPopup(final int x, final int y) {\r
- if (getCurrent() == null)\r
+ if (getCurrent() == null){\r
+ GWT.log("[POPUP IS NULL]", null);\r
return;\r
+ }\r
menu.hide();\r
menu = new GroupContextMenu(images);\r
menu.setPopupPosition(x, y);\r
menu.show();\r
}\r
\r
- /*\r
- * (non-Javadoc)\r
- *\r
- * @see com.google.gwt.user.client.ui.TreeListener#onTreeItemStateChanged(com.google.gwt.user.client.ui.TreeItem)\r
- */\r
- public void onTreeItemStateChanged(final TreeItem item) {\r
- // Ignore closed items.\r
- if (!item.getState())\r
- return;\r
\r
- setChanged(item);\r
- updateUsers( item);\r
- }\r
\r
/**\r
* Generate an RPC request to retrieve the users of the specified group for\r
void updateUsers(final TreeItem groupItem) {\r
if(groupItem.getUserObject() instanceof GroupResource){\r
GroupResource res = (GroupResource) groupItem.getUserObject();\r
- MultipleGetCommand<GroupUserResource> gu = new MultipleGetCommand<GroupUserResource>(GroupUserResource.class, res.getUserPaths().toArray(new String[]{})){\r
+ MultipleGetCommand<GroupUserResource> gu = new MultipleGetCommand<GroupUserResource>(GroupUserResource.class, res.getUserPaths().toArray(new String[]{}), null){\r
+ @Override\r
public void onComplete() {\r
List<GroupUserResource> users = getResult();\r
groupItem.removeItems();\r
final TreeItem userItem = addImageItem(groupItem, users.get(i).getName() + " <" + users.get(i).getUsername() + ">", images.permUser());\r
userItem.setUserObject(users.get(i));\r
}\r
+ if (selectedGroup != null && groupItem.getText().equals(selectedGroup)) {\r
+ //SelectionEvent.fire(tree, groupItem);;\r
+ onSelection(groupItem);\r
+ groupItem.setState(true);\r
+ }\r
}\r
\r
-\r
+ @Override\r
public void onError(Throwable t) {\r
GWT.log("", t);\r
}\r
\r
+ @Override\r
public void onError(String p, Throwable throwable) {\r
GWT.log("Path:"+p, throwable);\r
}\r
}\r
\r
/**\r
- * Modify the changed.\r
- *\r
- * @param newChanged the changed to set\r
- */\r
- private void setChanged(final TreeItem newChanged) {\r
- changed = newChanged;\r
- }\r
-\r
- /**\r
* Retrieve the previous.\r
*\r
* @return the previous\r
previous = newPrevious;\r
}\r
\r
- /*\r
- * (non-Javadoc)\r
- *\r
- * @see com.google.gwt.user.client.ui.UIObject#setVisible(boolean)\r
- */\r
+ @Override\r
public void setVisible(final boolean visible) {\r
super.setVisible(visible);\r
if (visible)\r
updateGroups();\r
}\r
+\r
+ @Override\r
+ public void onSelection(SelectionEvent event) {\r
+ final TreeItem item = (TreeItem)event.getSelectedItem();\r
+ onSelection(item);\r
+\r
+ }\r
+\r
+ private void onSelection(TreeItem item){\r
+ final Object selected = item.getUserObject();\r
+ // Preserve the previously selected item, so that the current's\r
+ // onClick() method gets a chance to find it.\r
+ if (getPrevious() != null)\r
+ getPrevious().getWidget().removeStyleName("gss-SelectedRow");\r
+ setCurrent(item);\r
+ getCurrent().getWidget().addStyleName("gss-SelectedRow");\r
+ setPrevious(getCurrent());\r
+ GSS.get().setCurrentSelection(selected);\r
+ //cache the latest top level node (group) for selecting and expanding on refresh\r
+ if (item.getParentItem() == null)\r
+ selectedGroup = item.getText();\r
+ else\r
+ selectedGroup = item.getParentItem().getText();\r
+ }\r
+\r
+ @Override\r
+ public void onOpen(OpenEvent event) {\r
+ final TreeItem item = (TreeItem) event.getTarget();\r
+ updateUsers(item);\r
+ }\r
}\r