import com.google.gwt.dom.client.Touch;
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;
* TODO implement unregistering for child components in Cells
*/
public class VScrollTable extends FlowPanel implements Table, ScrollHandler,
- VHasDropHandler, FocusHandler, BlurHandler, Focusable {
+ VHasDropHandler, FocusHandler, BlurHandler, Focusable, ActionOwner {
public static final String CLASSNAME = "v-table";
public static final String CLASSNAME_SELECTION_FOCUS = CLASSNAME + "-focus";
*/
private int scrollingVelocity = 10;
- private Timer scrollingVelocityTimer = null;;
+ private Timer scrollingVelocityTimer = null;
+
+ private String[] bodyActionKeys;
/**
* Represents a select range of rows
}
}, TouchStartEvent.getType());
+ scrollBodyPanel.sinkEvents(Event.ONCONTEXTMENU);
+ scrollBodyPanel.addDomHandler(new ContextMenuHandler() {
+ public void onContextMenu(ContextMenuEvent event) {
+ handleBodyContextMenu(event);
+ }
+ }, ContextMenuEvent.getType());
+
setStyleName(CLASSNAME);
add(tHead);
}
+ private void handleBodyContextMenu(ContextMenuEvent event) {
+ if (enabled && bodyActionKeys != null) {
+ int left = Util.getTouchOrMouseClientX(event.getNativeEvent());
+ int top = Util.getTouchOrMouseClientY(event.getNativeEvent());
+ top += Window.getScrollTop();
+ left += Window.getScrollLeft();
+ client.getContextMenu().showAt(this, left, top);
+ }
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
/**
* Fires a column resize event which sends the resize information to the
* server.
multiselectmode = uidl.hasAttribute("multiselectmode") ? uidl
.getIntAttribute("multiselectmode") : MULTISELECT_MODE_DEFAULT;
+ if (uidl.hasAttribute("alb")) {
+ bodyActionKeys = uidl.getStringArrayAttribute("alb");
+ }
+
setCacheRate(uidl.hasAttribute("cr") ? uidl.getDoubleAttribute("cr")
: CACHE_RATE_DEFAULT);
}
});
}
+
+ 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];
+ Action bodyAction = new TreeAction(this, null, actionKey);
+ bodyAction.setCaption(getActionCaption(actionKey));
+ bodyAction.setIconUrl(getActionIcon(actionKey));
+ actions[i] = bodyAction;
+ }
+ return actions;
+ }
+
+ public ApplicationConnection getClient() {
+ return client;
+ }
+
+ public String getPaintableId() {
+ return paintableId;
+ }
}
final Action action = (Action) actionMapper.get(st.nextToken());
if (action != null && containsId(itemId)
&& actionHandlers != null) {
+ // Item action
for (final Iterator<Handler> i = actionHandlers.iterator(); i
.hasNext();) {
(i.next()).handleAction(action, this, itemId);
}
+ } else if (action != null && actionHandlers != null
+ && itemId == null) {
+ // Body action
+ for (final Iterator<Handler> i = actionHandlers.iterator(); i
+ .hasNext();) {
+ (i.next()).handleAction(action, this, null);
+ }
}
}
}
target.addAttribute("colfooters", columnFootersVisible);
+ /*
+ * Body actions - Actions which has the target null and can be invoked
+ * by right clicking on the table body.
+ */
+ final Set<Action> actionSet = new LinkedHashSet<Action>();
+ if (actionHandlers != null) {
+ final ArrayList<String> keys = new ArrayList<String>();
+ for (final Iterator<Handler> ahi = actionHandlers.iterator(); ahi
+ .hasNext();) {
+
+ // Getting actions for the null item, which in this case means
+ // the body item
+ final Action[] aa = (ahi.next()).getActions(null, this);
+ if (aa != null) {
+ for (int ai = 0; ai < aa.length; ai++) {
+ final String key = actionMapper.key(aa[ai]);
+ actionSet.add(aa[ai]);
+ keys.add(key);
+ }
+ }
+ }
+ target.addAttribute("alb", keys.toArray());
+ }
+
// Visible column order
final Collection<?> sortables = getSortableContainerPropertyIds();
final ArrayList<String> visibleColOrder = new ArrayList<String>();
target.addAttribute("vcolorder", visibleColOrder.toArray());
// Rows
- final Set<Action> actionSet = new LinkedHashSet<Action>();
final boolean selectable = isSelectable();
final boolean[] iscomponent = new boolean[visibleColumns.size()];
int iscomponentIndex = 0;