/*
- * Copyright 2011 GRNET S.A. All rights reserved.
+ * Copyright 2011-2012 GRNET S.A. All rights reserved.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
protected Pithos app;
- private ListDataProvider<String> rootDataProvider = new ListDataProvider<String>();
-
- private Cell<String> rootCell = new AbstractCell<String>(ContextMenuEvent.getType().getName()) {
-
- @Override
- public void render(@SuppressWarnings("unused") Context context, String value, SafeHtmlBuilder sb) {
- String html = AbstractImagePrototype.create(GroupTreeView.images.groups()).getHTML();
- sb.appendHtmlConstant(html);
- sb.append(Templates.INSTANCE.nameSpan(value));
- }
-
- @Override
- public void onBrowserEvent(@SuppressWarnings("unused") Cell.Context context, @SuppressWarnings("unused") com.google.gwt.dom.client.Element parent, String s, com.google.gwt.dom.client.NativeEvent event, @SuppressWarnings("unused") com.google.gwt.cell.client.ValueUpdater<String> valueUpdater) {
- GroupTreeViewModel.this.rootSelectionModel.setSelected(s, true);
- if (event.getType().equals(ContextMenuEvent.getType().getName())) {
- GroupContextMenu menu = new GroupContextMenu(app, GroupTreeView.images, null);
- menu.setPopupPosition(event.getClientX(), event.getClientY());
- menu.show();
- }
- }
- };
-
private Cell<Group> groupCell = new AbstractCell<Group>(ContextMenuEvent.getType().getName()) {
@Override
- public void render(@SuppressWarnings("unused") Context context, Group value, SafeHtmlBuilder sb) {
+ public void render(Context context, Group value, SafeHtmlBuilder sb) {
String html = AbstractImagePrototype.create(GroupTreeView.images.group()).getHTML();
- sb.appendHtmlConstant(html);
+ sb.appendHtmlConstant(html).appendHtmlConstant(" ");
sb.append(Templates.INSTANCE.nameSpan(value.getName()));
}
@Override
- public void onBrowserEvent(@SuppressWarnings("unused") Cell.Context context, @SuppressWarnings("unused") com.google.gwt.dom.client.Element parent, Group group, com.google.gwt.dom.client.NativeEvent event, @SuppressWarnings("unused") com.google.gwt.cell.client.ValueUpdater<Group> valueUpdater) {
+ public void onBrowserEvent(Cell.Context context, com.google.gwt.dom.client.Element parent, Group group, com.google.gwt.dom.client.NativeEvent event, com.google.gwt.cell.client.ValueUpdater<Group> valueUpdater) {
GroupTreeViewModel.this.groupSelectionModel.setSelected(group, true);
if (event.getType().equals(ContextMenuEvent.getType().getName())) {
GroupContextMenu menu = new GroupContextMenu(app, GroupTreeView.images, group);
private Cell<User> userCell = new AbstractCell<User>(ContextMenuEvent.getType().getName()) {
@Override
- public void render(@SuppressWarnings("unused") Context context, User value, SafeHtmlBuilder sb) {
+ public void render(Context context, User value, SafeHtmlBuilder sb) {
String html = AbstractImagePrototype.create(GroupTreeView.images.user()).getHTML();
- sb.appendHtmlConstant(html);
+ sb.appendHtmlConstant(html).appendHtmlConstant(" ");
sb.append(Templates.INSTANCE.nameSpan(value.getName()));
}
@Override
- public void onBrowserEvent(@SuppressWarnings("unused") Cell.Context context, @SuppressWarnings("unused") com.google.gwt.dom.client.Element parent, User user, com.google.gwt.dom.client.NativeEvent event, @SuppressWarnings("unused") com.google.gwt.cell.client.ValueUpdater<User> valueUpdater) {
+ public void onBrowserEvent(Cell.Context context, com.google.gwt.dom.client.Element parent, User user, com.google.gwt.dom.client.NativeEvent event, com.google.gwt.cell.client.ValueUpdater<User> valueUpdater) {
GroupTreeViewModel.this.userSelectionModel.setSelected(user, true);
if (event.getType().equals(ContextMenuEvent.getType().getName())) {
UserContextMenu menu = new UserContextMenu(app, GroupTreeView.images, user);
protected Map<Group, ListDataProvider<User>> userDataProviderMap = new HashMap<Group, ListDataProvider<User>>();
- protected Map<String, Set<File>> sharedFiles = new HashMap<String, Set<File>>();
-
- SingleSelectionModel<String> rootSelectionModel;
SingleSelectionModel<Group> groupSelectionModel;
SingleSelectionModel<User> userSelectionModel;
public GroupTreeViewModel(Pithos _app) {
app = _app;
- rootSelectionModel = new SingleSelectionModel<String>();
- app.addSelectionModel(rootSelectionModel);
- rootSelectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
-
- @Override
- public void onSelectionChange(SelectionChangeEvent event) {
- if (rootSelectionModel.getSelectedObject() != null) {
- app.deselectOthers(app.getGroupTreeView(), rootSelectionModel);
- app.showFiles(new HashSet<File>());
- }
- }
- });
groupSelectionModel = new SingleSelectionModel<Group>();
app.addSelectionModel(groupSelectionModel);
if (groupSelectionModel.getSelectedObject() != null) {
app.deselectOthers(app.getGroupTreeView(), groupSelectionModel);
app.showFiles(new HashSet<File>());
+ app.showRelevantToolbarButtons();
+ }
+ else {
+ if (app.getSelectedTree().equals(app.getGroupTreeView()))
+ app.setSelectedTree(null);
+ if (app.getSelectedTree() == null)
+ app.showRelevantToolbarButtons();
}
}
});
if (userSelectionModel.getSelectedObject() != null) {
app.deselectOthers(app.getGroupTreeView(), userSelectionModel);
app.showFiles(new HashSet<File>());
+ app.showRelevantToolbarButtons();
+ }
+ else {
+ if (app.getSelectedTree().equals(app.getGroupTreeView()))
+ app.setSelectedTree(null);
+ if (app.getSelectedTree() == null)
+ app.showRelevantToolbarButtons();
}
}
});
@Override
public <T> NodeInfo<?> getNodeInfo(T value) {
if (value == null) {
- rootDataProvider.getList().add("");
- return new DefaultNodeInfo<String>(rootDataProvider, rootCell, rootSelectionModel, null);
- }
- else if (value instanceof String) {
groupsDataProvider.getList().clear();
- groupsDataProvider.getList().addAll(app.getAccount().getGroups());
+ groupsDataProvider.getList().addAll(app.getAccount().getGroups());
+ groupsDataProvider.getList().add(new Group("Create new group..."));
return new DefaultNodeInfo<Group>(groupsDataProvider, groupCell, groupSelectionModel, null);
}
- else { //Group
- Group g = (Group) value;
- if (userDataProviderMap.get(g) == null) {
- userDataProviderMap.put(g, new ListDataProvider<User>());
- }
- final ListDataProvider<User> dataProvider = userDataProviderMap.get(g);
- dataProvider.getList().clear();
- for (String u : g.getMembers())
- dataProvider.getList().add(new User(u, g));
- return new DefaultNodeInfo<User>(dataProvider, userCell, userSelectionModel, null);
- }
+ Group g = (Group) value;
+ if (userDataProviderMap.get(g) == null) {
+ userDataProviderMap.put(g, new ListDataProvider<User>());
+ }
+ final ListDataProvider<User> dataProvider = userDataProviderMap.get(g);
+ dataProvider.getList().clear();
+ for (String u : g.getMembers())
+ dataProvider.getList().add(new User(u, g));
+ return new DefaultNodeInfo<User>(dataProvider, userCell, userSelectionModel, null);
}
@Override
public boolean isLeaf(Object o) {
- if (o instanceof String) {
- return ((String) o).length() == 0 || app.getAccount().getGroups().isEmpty();
+ if (o instanceof User) {
+ return true;
}
else if (o instanceof Group)
return ((Group) o).getMembers().isEmpty();
- else if (o != null)
- return true;
return false;
}
- public void initialize() {
- rootDataProvider.getList().clear();
- rootDataProvider.getList().add("Groups");
- }
-
public void updateGroupNode(Group group) {
if (group == null) {
groupsDataProvider.getList().clear();
groupsDataProvider.getList().addAll(app.getAccount().getGroups());
+ groupsDataProvider.getList().add(new Group("Create new group..."));
}
else {
if (userDataProviderMap.get(group) == null) {
}
public Object getSelectedObject() {
- if (rootSelectionModel.getSelectedObject() != null)
- return rootSelectionModel.getSelectedObject();
if (groupSelectionModel.getSelectedObject() != null)
return groupSelectionModel.getSelectedObject();
if (userSelectionModel.getSelectedObject() != null)