-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
import com.google.gwt.dom.client.Node;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
+import com.google.gwt.event.dom.client.ContextMenuEvent;
+import com.google.gwt.event.dom.client.ContextMenuHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.event.dom.client.KeyCodes;
*/
public class VTree extends SimpleFocusablePanel implements Paintable,
VHasDropHandler, FocusHandler, BlurHandler, KeyPressHandler,
- KeyDownHandler, SubPartAware {
+ KeyDownHandler, SubPartAware, ActionOwner {
public static final String CLASSNAME = "v-tree";
private boolean selectionHasChanged = false;
+ private String[] bodyActionKeys;
+
public VLazyExecutor iconLoaded = new VLazyExecutor(50,
new ScheduledCommand() {
addFocusHandler(this);
addBlurHandler(this);
+ /*
+ * Listen to context menu events on the empty space in the tree
+ */
+ sinkEvents(Event.ONCONTEXTMENU);
+ addDomHandler(new ContextMenuHandler() {
+ public void onContextMenu(ContextMenuEvent event) {
+ handleBodyContextMenu(event);
+ }
+ }, ContextMenuEvent.getType());
+
/*
* Firefox auto-repeat works correctly only if we use a key press
* handler, other browsers handle it correctly when using a key down
isNullSelectionAllowed = uidl.getBooleanAttribute("nullselect");
+ if (uidl.hasAttribute("alb")) {
+ bodyActionKeys = uidl.getStringArrayAttribute("alb");
+ }
+
body.clear();
for (final Iterator<?> i = uidl.getChildIterator(); i.hasNext();) {
final UIDL childUidl = (UIDL) i.next();
return locator;
}
+ public Action[] getActions() {
+ if (bodyActionKeys == null) {
+ return new Action[] {};
+ }
+ final Action[] actions = new Action[bodyActionKeys.length];
+ for (int i = 0; i < actions.length; i++) {
+ final String actionKey = bodyActionKeys[i];
+ final TreeAction a = new TreeAction(this, null, actionKey);
+ a.setCaption(getActionCaption(actionKey));
+ a.setIconUrl(getActionIcon(actionKey));
+ actions[i] = a;
+ }
+ return actions;
+ }
+
+ public ApplicationConnection getClient() {
+ return client;
+ }
+
+ public String getPaintableId() {
+ return paintableId;
+ }
+
+ private void handleBodyContextMenu(ContextMenuEvent event) {
+ if (!readonly && !disabled) {
+ if (bodyActionKeys != null) {
+ int left = event.getNativeEvent().getClientX();
+ int top = event.getNativeEvent().getClientY();
+ top += Window.getScrollTop();
+ left += Window.getScrollLeft();
+ client.getContextMenu().showAt(this, left, top);
+ }
+ event.stopPropagation();
+ event.preventDefault();
+ }
+ }
+
}
-/*
+/*
@ITMillApache2LicenseForJavaFiles@
*/
import com.vaadin.data.util.ContainerHierarchicalWrapper;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.event.Action;
+import com.vaadin.event.Action.Handler;
import com.vaadin.event.DataBoundTransferable;
import com.vaadin.event.ItemClickEvent;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
// Actions
if (variables.containsKey("action")) {
-
final StringTokenizer st = new StringTokenizer(
(String) variables.get("action"), ",");
if (st.countTokens() == 2) {
final Action action = (Action) actionMapper.get(st.nextToken());
if (action != null && containsId(itemId)
&& actionHandlers != null) {
- for (final Iterator<Action.Handler> i = actionHandlers
- .iterator(); i.hasNext();) {
- i.next().handleAction(action, this, itemId);
+ // Item action
+ for (Handler ah : actionHandlers) {
+ ah.handleAction(action, this, itemId);
+ }
+ } else if (action != null && actionHandlers != null
+ && itemId == null) {
+ // Body action
+ for (Handler ah : actionHandlers) {
+ ah.handleAction(action, this, null);
}
}
}
iteratorStack.push(ids.iterator());
}
+ /*
+ * Body actions - Actions which has the target null and can be invoked
+ * by right clicking on the Tree body
+ */
+ if (actionHandlers != null) {
+ final ArrayList<String> keys = new ArrayList<String>();
+ for (Handler ah : actionHandlers) {
+
+ // Getting action for the null item, which in this case
+ // means the body item
+ final Action[] aa = ah.getActions(null, this);
+ if (aa != null) {
+ for (int ai = 0; ai < aa.length; ai++) {
+ final String akey = actionMapper.key(aa[ai]);
+ actionSet.add(aa[ai]);
+ keys.add(akey);
+ }
+ }
+ }
+ target.addAttribute("alb", keys.toArray());
+ }
+
while (!iteratorStack.isEmpty()) {
// Gets the iterator for current tree level