import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;
-import com.itmill.toolkit.terminal.gwt.client.ui.IContextMenu;
+import com.itmill.toolkit.terminal.gwt.client.ui.ContextMenu;
import com.itmill.toolkit.terminal.gwt.client.ui.IView;
/**
private final WidgetSet widgetSet;
- private IContextMenu contextMenu = null;
+ private ContextMenu contextMenu = null;
private IView view = new IView();
*
* @return IContextMenu object
*/
- public IContextMenu getContextMenu() {
+ public ContextMenu getContextMenu() {
if (contextMenu == null) {
- contextMenu = new IContextMenu();
+ contextMenu = new ContextMenu();
}
return contextMenu;
}
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+import com.google.gwt.user.client.Command;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+
+/**
+ *
+ */
+public abstract class Action implements Command {
+
+ protected IActionOwner owner;
+
+ protected String iconUrl = null;
+
+ protected String caption = "";
+
+ public Action(IActionOwner owner) {
+ this.owner = owner;
+ }
+
+ /**
+ * Executed when action fired
+ */
+ public abstract void execute();
+
+ public String getHTML() {
+ StringBuffer sb = new StringBuffer();
+ if(getIconUrl() != null) {
+ sb.append("<img src=\""+getIconUrl()+"\" alt=\"icon\" />");
+ }
+
+ sb.append(getCaption());
+ return sb.toString();
+ }
+
+ public String getCaption() {
+ return caption;
+ }
+
+ public void setCaption(String caption) {
+ this.caption = caption;
+ }
+
+ public String getIconUrl() {
+ return iconUrl;
+ }
+}
+
+/**
+ * Action owner must provide a set of actions for context menu
+ * and IAction objects.
+ */
+interface IActionOwner {
+
+ /**
+ * @return Array of IActions
+ */
+ public Action[] getActions();
+
+ public ApplicationConnection getClient();
+
+ public String getPaintableId();
+}
\ No newline at end of file
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.MenuBar;
+import com.google.gwt.user.client.ui.MenuItem;
+import com.google.gwt.user.client.ui.PopupPanel;
+
+public class ContextMenu extends PopupPanel {
+
+ private IActionOwner actionOwner;
+
+ private CMenuBar menu = new CMenuBar();
+
+ /**
+ * This method should be used only by Client object as
+ * only one per client should exists. Request an instance
+ * via client.getContextMenu();
+ *
+ * @param cli to be set as an owner of menu
+ */
+ public ContextMenu() {
+ super(true);
+ setWidget(menu);
+ setStyleName("i-contextmenu");
+ }
+
+ /**
+ * Sets the element from which to build menu
+ * @param ao
+ */
+ public void setActionOwner(IActionOwner ao) {
+ this.actionOwner = ao;
+ }
+
+ /**
+ * Shows context menu at given location.
+ *
+ * @param left
+ * @param top
+ */
+ public void showAt(int left, int top) {
+ menu.clearItems();
+ Action[] actions = actionOwner.getActions();
+ for (int i = 0; i < actions.length; i++) {
+ Action a = actions[i];
+ menu.addItem(new MenuItem(a.getHTML(), true, a));
+ }
+
+ setPopupPosition(left, top);
+ show();
+ // fix position if "outside" screen
+ if(DOM.getElementPropertyInt(getElement(),"offsetWidth") + left > Window.getClientWidth()) {
+ left = Window.getClientWidth() - DOM.getElementPropertyInt(getElement(),"offsetWidth");
+ setPopupPosition(left, top);
+ }
+ }
+
+ public void showAt(IActionOwner ao, int left, int top) {
+ setActionOwner(ao);
+ showAt(left, top);
+ }
+
+ /**
+ * Extend standard Gwt MenuBar to set proper settings and
+ * to override onPopupClosed method so that PopupPanel gets
+ * closed.
+ */
+ class CMenuBar extends MenuBar {
+ public CMenuBar() {
+ super(true);
+ }
+
+ public void onPopupClosed(PopupPanel sender, boolean autoClosed) {
+ super.onPopupClosed(sender, autoClosed);
+ ContextMenu.this.hide();
+ }
+ }
+}
+++ /dev/null
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.Command;
-import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
-
-/**
- *
- */
-public abstract class IAction implements Command {
-
- protected IActionOwner owner;
-
- protected String iconUrl = null;
-
- protected String caption = "";
-
- public IAction(IActionOwner owner) {
- this.owner = owner;
- }
-
- /**
- * Executed when action fired
- */
- public abstract void execute();
-
- public String getHTML() {
- StringBuffer sb = new StringBuffer();
- if(getIconUrl() != null) {
- sb.append("<img src=\""+getIconUrl()+"\" alt=\"icon\" />");
- }
- sb.append(getCaption());
- return sb.toString();
- }
-
- public String getCaption() {
- return caption;
- }
-
- public void setCaption(String caption) {
- this.caption = caption;
- }
-
- public String getIconUrl() {
- return iconUrl;
- }
-}
-
-/**
- * Action owner must provide a set of actions for context menu
- * and IAction objects.
- */
-interface IActionOwner {
-
- /**
- * @return Array of IActions
- */
- public IAction[] getActions();
-
- public ApplicationConnection getClient();
-
- public String getPaintableId();
-}
\ No newline at end of file
+++ /dev/null
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Window;
-import com.google.gwt.user.client.ui.MenuBar;
-import com.google.gwt.user.client.ui.MenuItem;
-import com.google.gwt.user.client.ui.PopupPanel;
-
-public class IContextMenu extends PopupPanel {
-
- private IActionOwner actionOwner;
-
- private CMenuBar menu = new CMenuBar();
-
- /**
- * This method should be used only by Client object as
- * only one per client should exists. Request an instance
- * via client.getContextMenu();
- *
- * @param cli to be set as an owner of menu
- */
- public IContextMenu() {
- super(true);
- setWidget(menu);
- setStyleName("i-contextmenu");
- }
-
- /**
- * Sets the element from which to build menu
- * @param ao
- */
- public void setActionOwner(IActionOwner ao) {
- this.actionOwner = ao;
- }
-
- /**
- * Shows context menu at given location.
- *
- * @param left
- * @param top
- */
- public void showAt(int left, int top) {
- menu.clearItems();
- IAction[] actions = actionOwner.getActions();
- for (int i = 0; i < actions.length; i++) {
- IAction a = actions[i];
- menu.addItem(new MenuItem(a.getHTML(), true, a));
- }
-
- setPopupPosition(left, top);
- show();
- // fix position if "outside" screen
- if(DOM.getElementPropertyInt(getElement(),"offsetWidth") + left > Window.getClientWidth()) {
- left = Window.getClientWidth() - DOM.getElementPropertyInt(getElement(),"offsetWidth");
- setPopupPosition(left, top);
- }
- }
-
- public void showAt(IActionOwner ao, int left, int top) {
- setActionOwner(ao);
- showAt(left, top);
- }
-
- /**
- * Extend standard Gwt MenuBar to set proper settings and
- * to override onPopupClosed method so that PopupPanel gets
- * closed.
- */
- class CMenuBar extends MenuBar {
- public CMenuBar() {
- super(true);
- }
-
- public void onPopupClosed(PopupPanel sender, boolean autoClosed) {
- super.onPopupClosed(sender, autoClosed);
- IContextMenu.this.hide();
- }
- }
-}
*
* TODO implement unregistering for child componts in Cells
*/
-public class IScrollTable extends Composite implements ITable,
- ScrollListener {
+public class IScrollTable extends Composite implements ITable, ScrollListener {
public static final String CLASSNAME = "i-table";
/**
}
}
- class VisibleColumnAction extends IAction {
+ class VisibleColumnAction extends Action {
String colKey;
private boolean collapsed;
/*
* Returns columns as Action array for column select popup
*/
- public IAction[] getActions() {
+ public Action[] getActions() {
Object[] cols;
if (IScrollTable.this.columnReordering) {
cols = columnOrder;
for (Iterator it = collapsedColumns.iterator(); it.hasNext();)
cols[i++] = it.next();
}
- IAction[] actions = new IAction[cols.length];
+ Action[] actions = new Action[cols.length];
for (int i = 0; i < cols.length; i++) {
String cid = (String) cols[i];
* element where to attach contenxt menu event
*/
private native void attachContextMenuEvent(Element el) /*-{
- var row = this;
- el.oncontextmenu = function(e) {
- if(!e)
- e = $wnd.event;
- row.@com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable.IScrollTableBody.IScrollTableRow::showContextMenu(Lcom/google/gwt/user/client/Event;)(e);
- return false;
- };
- }-*/;
+ var row = this;
+ el.oncontextmenu = function(e) {
+ if(!e)
+ e = $wnd.event;
+ row.@com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable.IScrollTableBody.IScrollTableRow::showContextMenu(Lcom/google/gwt/user/client/Event;)(e);
+ return false;
+ };
+ }-*/;
public String getKey() {
return String.valueOf(rowKey);
*
* @see com.itmill.toolkit.terminal.gwt.client.ui.IActionOwner#getActions()
*/
- public IAction[] getActions() {
+ public Action[] getActions() {
if (actionKeys == null)
- return new IAction[] {};
- IAction[] actions = new IAction[actionKeys.length];
+ return new Action[] {};
+ Action[] actions = new Action[actionKeys.length];
for (int i = 0; i < actions.length; i++) {
String actionKey = actionKeys[i];
- ITreeAction a = new ITreeAction(this, String
- .valueOf(rowKey), actionKey);
+ TreeAction a = new TreeAction(this, String.valueOf(rowKey),
+ actionKey);
a.setCaption(getActionCaption(actionKey));
actions[i] = a;
}
}
public void add(Widget w) {
- throw new UnsupportedOperationException("ITable can contain only rows created by itself.");
+ throw new UnsupportedOperationException(
+ "ITable can contain only rows created by itself.");
}
public void clear() {
+++ /dev/null
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import com.google.gwt.user.client.ui.KeyboardListener;
-import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
-import com.itmill.toolkit.terminal.gwt.client.UIDL;
-
-/**
- * A helper class to implement keyboard shorcut handling. Keeps
- * a list of owners actions and fires actions to server. User class
- * needs to delegate keyboard events to handleKeyboardEvents function.
- *
- * @author IT Mill ltd
- */
-public class IShortcutActionHandler {
- private ArrayList actions = new ArrayList();
- private ApplicationConnection client;
- private String paintableId;
-
- private IShortcutActionHandler() {}
- /**
- *
- * @param pid Paintable id
- * @param c reference to application connections
- */
- public IShortcutActionHandler(String pid, ApplicationConnection c) {
- paintableId = pid;
- client = c;
- }
-
- /**
- * Updates list of actions this handler listens to.
- *
- * @param c UIDL snippet containing actions
- */
- public void updateActionMap(UIDL c) {
- actions.clear();
- Iterator it = c.getChildIterator();
- while(it.hasNext()) {
- UIDL action = (UIDL) it.next();
-
- int[] modifiers = null;
- if(action.hasAttribute("mk"))
- modifiers = action.getIntArrayAttribute("mk");
-
- ShortcutKeyCombination kc = new ShortcutKeyCombination(
- action.getIntAttribute("kc"),
- modifiers);
- String key = action.getStringAttribute("key");
- String caption = action.getStringAttribute("caption");
- actions.add(new IShortcutAction(key,kc, caption));
- }
- }
-
- /**
- * This method compares given key code and modifier keys to
- * internal list of actions. If matching action is found it
- * is fired.
- *
- * @param keyCode character typed
- * @param modifiers modifier keys (bitmask like in {@link KeyboardListener})
- */
- public void handleKeyboardEvent(char keyCode, int modifiers) {
- ShortcutKeyCombination kc =
- new ShortcutKeyCombination(keyCode, modifiers);
- Iterator it = actions.iterator();
- while(it.hasNext()) {
- IShortcutAction a = (IShortcutAction) it.next();
- if(a.getShortcutCombination().equals(kc)) {
- client.updateVariable(paintableId, "action", a.getKey(), true);
- break;
- }
- }
- }
-
-}
-
-class ShortcutKeyCombination {
-
- public static final int SHIFT = 16;
- public static final int CTRL = 17;
- public static final int ALT = 18;
-
-
-
- char keyCode = 0;
- private int modifiersMask;
-
- public ShortcutKeyCombination() {
- }
-
- ShortcutKeyCombination(char kc, int modifierMask) {
- keyCode = kc;
- this.modifiersMask = modifierMask;
- }
-
- ShortcutKeyCombination(int kc, int[] modifiers) {
- keyCode = (char) kc;
- keyCode = Character.toUpperCase(keyCode);
-
- this.modifiersMask = 0;
- if(modifiers != null) {
- for (int i = 0; i < modifiers.length; i++) {
- switch (modifiers[i]) {
- case ALT:
- modifiersMask = modifiersMask | KeyboardListener.MODIFIER_ALT;
- break;
- case CTRL:
- modifiersMask = modifiersMask | KeyboardListener.MODIFIER_CTRL;
- break;
- case SHIFT:
- modifiersMask = modifiersMask | KeyboardListener.MODIFIER_SHIFT;
- break;
- default:
- break;
- }
- }
- }
- }
-
- public boolean equals(ShortcutKeyCombination other) {
- if( this.keyCode == other.keyCode &&
- this.modifiersMask == other.modifiersMask)
- return true;
- return false;
- }
-}
-
-class IShortcutAction {
-
- private ShortcutKeyCombination sc;
- private String caption;
- private String key;
-
- public IShortcutAction(String key, ShortcutKeyCombination sc, String caption) {
- this.sc = sc;
- this.key = key;
- this.caption = caption;
- }
-
- public ShortcutKeyCombination getShortcutCombination() {
- return sc;
- }
-
- public String getCaption() {
- return caption;
- }
-
- public String getKey() {
- return key;
- }
-
-}
-
+++ /dev/null
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-import com.google.gwt.user.client.ui.HasWidgets;
-import com.itmill.toolkit.terminal.gwt.client.Paintable;
-
-public interface ITable extends HasWidgets, Paintable {
- final int SELECT_MODE_NONE = 0;
- final int SELECT_MODE_SINGLE = 1;
- final int SELECT_MODE_MULTI = 2;
-}
return childrenLoaded;
}
- public IAction[] getActions() {
+ public Action[] getActions() {
if(actionKeys == null)
- return new IAction[] {};
- IAction[] actions = new IAction[actionKeys.length];
+ return new Action[] {};
+ Action[] actions = new Action[actionKeys.length];
for (int i = 0; i < actions.length; i++) {
String actionKey = actionKeys[i];
- ITreeAction a = new ITreeAction(this, String.valueOf(key), actionKey);
+ TreeAction a = new TreeAction(this, String.valueOf(key), actionKey);
a.setCaption(getActionCaption(actionKey));
actions[i] = a;
}
+++ /dev/null
-package com.itmill.toolkit.terminal.gwt.client.ui;
-
-
-/**
- * This class is used for "row actions" in ITree and ITable
- */
-public class ITreeAction extends IAction {
-
- String targetKey = "";
- String actionKey = "";
-
- public ITreeAction(IActionOwner owner) {
- super(owner);
- }
-
- public ITreeAction(IActionOwner owner, String target, String action) {
- this(owner);
- this.targetKey = target;
- this.actionKey = action;
- }
-
-
- /**
- * Sends message to server that this action has been fired.
- * Messages are "standard" Toolkit messages whose value is comma
- * separated pair of targetKey (row, treeNod ...) and actions id.
- *
- * Variablename is always "action".
- *
- * Actions are always sent immediatedly to server.
- */
- public void execute() {
- owner.getClient().updateVariable(
- owner.getPaintableId(),
- "action",
- targetKey + "," + actionKey,
- true);
- owner.getClient().getContextMenu().hide();
- }
-
- public String getActionKey() {
- return actionKey;
- }
-
- public void setActionKey(String actionKey) {
- this.actionKey = actionKey;
- }
-
- public String getTargetKey() {
- return targetKey;
- }
-
- public void setTargetKey(String targetKey) {
- this.targetKey = targetKey;
- }
-
- public String getHTML() {
- StringBuffer sb = new StringBuffer();
- if(iconUrl != null) {
- sb.append("<img src=\""+iconUrl+"\" alt=\"icon\" />");
- }
- sb.append(caption);
- return sb.toString();
- }
-}
private String id;
- private IShortcutActionHandler actionHandler;
+ private ShortcutActionHandler actionHandler;
public IView() {
super();
((Paintable)w).updateFromUIDL(childUidl, client);
} else if ("actions".equals(childUidl.getTag())) {
if(actionHandler == null) {
- actionHandler = new IShortcutActionHandler(id, client);
+ actionHandler = new ShortcutActionHandler(id, client);
}
actionHandler.updateActionMap(childUidl);
}
private String id;
- IShortcutActionHandler shortcutHandler;
+ ShortcutActionHandler shortcutHandler;
public IWindow() {
super();
childUidl = uidl.getChildUIDL(1);
if(childUidl.getTag().equals("actions")) {
if(shortcutHandler == null)
- shortcutHandler = new IShortcutActionHandler(id, client);
+ shortcutHandler = new ShortcutActionHandler(id, client);
shortcutHandler.updateActionMap(childUidl);
}
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import com.google.gwt.user.client.ui.KeyboardListener;
+import com.itmill.toolkit.terminal.gwt.client.ApplicationConnection;
+import com.itmill.toolkit.terminal.gwt.client.UIDL;
+
+/**
+ * A helper class to implement keyboard shorcut handling. Keeps
+ * a list of owners actions and fires actions to server. User class
+ * needs to delegate keyboard events to handleKeyboardEvents function.
+ *
+ * @author IT Mill ltd
+ */
+public class ShortcutActionHandler {
+ private ArrayList actions = new ArrayList();
+ private ApplicationConnection client;
+ private String paintableId;
+
+ private ShortcutActionHandler() {}
+ /**
+ *
+ * @param pid Paintable id
+ * @param c reference to application connections
+ */
+ public ShortcutActionHandler(String pid, ApplicationConnection c) {
+ paintableId = pid;
+ client = c;
+ }
+
+ /**
+ * Updates list of actions this handler listens to.
+ *
+ * @param c UIDL snippet containing actions
+ */
+ public void updateActionMap(UIDL c) {
+ actions.clear();
+ Iterator it = c.getChildIterator();
+ while(it.hasNext()) {
+ UIDL action = (UIDL) it.next();
+
+ int[] modifiers = null;
+ if(action.hasAttribute("mk"))
+ modifiers = action.getIntArrayAttribute("mk");
+
+ ShortcutKeyCombination kc = new ShortcutKeyCombination(
+ action.getIntAttribute("kc"),
+ modifiers);
+ String key = action.getStringAttribute("key");
+ String caption = action.getStringAttribute("caption");
+ actions.add(new IShortcutAction(key,kc, caption));
+ }
+ }
+
+ /**
+ * This method compares given key code and modifier keys to
+ * internal list of actions. If matching action is found it
+ * is fired.
+ *
+ * @param keyCode character typed
+ * @param modifiers modifier keys (bitmask like in {@link KeyboardListener})
+ */
+ public void handleKeyboardEvent(char keyCode, int modifiers) {
+ ShortcutKeyCombination kc =
+ new ShortcutKeyCombination(keyCode, modifiers);
+ Iterator it = actions.iterator();
+ while(it.hasNext()) {
+ IShortcutAction a = (IShortcutAction) it.next();
+ if(a.getShortcutCombination().equals(kc)) {
+ client.updateVariable(paintableId, "action", a.getKey(), true);
+ break;
+ }
+ }
+ }
+
+}
+
+class ShortcutKeyCombination {
+
+ public static final int SHIFT = 16;
+ public static final int CTRL = 17;
+ public static final int ALT = 18;
+
+
+
+ char keyCode = 0;
+ private int modifiersMask;
+
+ public ShortcutKeyCombination() {
+ }
+
+ ShortcutKeyCombination(char kc, int modifierMask) {
+ keyCode = kc;
+ this.modifiersMask = modifierMask;
+ }
+
+ ShortcutKeyCombination(int kc, int[] modifiers) {
+ keyCode = (char) kc;
+ keyCode = Character.toUpperCase(keyCode);
+
+ this.modifiersMask = 0;
+ if(modifiers != null) {
+ for (int i = 0; i < modifiers.length; i++) {
+ switch (modifiers[i]) {
+ case ALT:
+ modifiersMask = modifiersMask | KeyboardListener.MODIFIER_ALT;
+ break;
+ case CTRL:
+ modifiersMask = modifiersMask | KeyboardListener.MODIFIER_CTRL;
+ break;
+ case SHIFT:
+ modifiersMask = modifiersMask | KeyboardListener.MODIFIER_SHIFT;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+
+ public boolean equals(ShortcutKeyCombination other) {
+ if( this.keyCode == other.keyCode &&
+ this.modifiersMask == other.modifiersMask)
+ return true;
+ return false;
+ }
+}
+
+class IShortcutAction {
+
+ private ShortcutKeyCombination sc;
+ private String caption;
+ private String key;
+
+ public IShortcutAction(String key, ShortcutKeyCombination sc, String caption) {
+ this.sc = sc;
+ this.key = key;
+ this.caption = caption;
+ }
+
+ public ShortcutKeyCombination getShortcutCombination() {
+ return sc;
+ }
+
+ public String getCaption() {
+ return caption;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+}
+
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+public interface Table {
+ final int SELECT_MODE_NONE = 0;
+ final int SELECT_MODE_SINGLE = 1;
+ final int SELECT_MODE_MULTI = 2;
+
+}
--- /dev/null
+package com.itmill.toolkit.terminal.gwt.client.ui;
+
+
+/**
+ * This class is used for "row actions" in ITree and ITable
+ */
+public class TreeAction extends Action {
+
+ String targetKey = "";
+ String actionKey = "";
+
+ public TreeAction(IActionOwner owner) {
+ super(owner);
+ }
+
+ public TreeAction(IActionOwner owner, String target, String action) {
+ this(owner);
+ this.targetKey = target;
+ this.actionKey = action;
+ }
+
+
+ /**
+ * Sends message to server that this action has been fired.
+ * Messages are "standard" Toolkit messages whose value is comma
+ * separated pair of targetKey (row, treeNod ...) and actions id.
+ *
+ * Variablename is always "action".
+ *
+ * Actions are always sent immediatedly to server.
+ */
+ public void execute() {
+ owner.getClient().updateVariable(
+ owner.getPaintableId(),
+ "action",
+ targetKey + "," + actionKey,
+ true);
+ owner.getClient().getContextMenu().hide();
+ }
+
+ public String getActionKey() {
+ return actionKey;
+ }
+
+ public void setActionKey(String actionKey) {
+ this.actionKey = actionKey;
+ }
+
+ public String getTargetKey() {
+ return targetKey;
+ }
+
+ public void setTargetKey(String targetKey) {
+ this.targetKey = targetKey;
+ }
+
+ public String getHTML() {
+ StringBuffer sb = new StringBuffer();
+ if(iconUrl != null) {
+ sb.append("<img src=\""+iconUrl+"\" alt=\"icon\" />");
+ }
+ sb.append(caption);
+ return sb.toString();
+ }
+}