From: Jani Laakso Date: Thu, 20 Sep 2007 07:59:01 +0000 (+0000) Subject: Refactoring for new package convention. X-Git-Tag: 6.7.0.beta1~5974 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=02202abb305f617a2258c55baecaf5e89a845b27;p=vaadin-framework.git Refactoring for new package convention. svn changeset:2346/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java index 1b7c2e50f7..9069bbe6d1 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ApplicationConnection.java @@ -22,7 +22,7 @@ import com.google.gwt.user.client.ui.HasFocus; 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; /** @@ -44,7 +44,7 @@ public class ApplicationConnection implements FocusListener { private final WidgetSet widgetSet; - private IContextMenu contextMenu = null; + private ContextMenu contextMenu = null; private IView view = new IView(); @@ -447,9 +447,9 @@ public class ApplicationConnection implements FocusListener { * * @return IContextMenu object */ - public IContextMenu getContextMenu() { + public ContextMenu getContextMenu() { if (contextMenu == null) { - contextMenu = new IContextMenu(); + contextMenu = new ContextMenu(); } return contextMenu; } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/Action.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/Action.java new file mode 100644 index 0000000000..f01c035ad6 --- /dev/null +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/Action.java @@ -0,0 +1,63 @@ +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("\"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 diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ContextMenu.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ContextMenu.java new file mode 100644 index 0000000000..e8160e70df --- /dev/null +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ContextMenu.java @@ -0,0 +1,79 @@ +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(); + } + } +} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IAction.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IAction.java deleted file mode 100644 index 2288b746a1..0000000000 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IAction.java +++ /dev/null @@ -1,62 +0,0 @@ -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("\"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 diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IContextMenu.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IContextMenu.java deleted file mode 100644 index 636e9116c9..0000000000 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IContextMenu.java +++ /dev/null @@ -1,79 +0,0 @@ -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(); - } - } -} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java index b4a70db3b4..a3bd26cce3 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java @@ -49,8 +49,7 @@ import com.itmill.toolkit.terminal.gwt.client.ui.IScrollTable.IScrollTableBody.I * * 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"; /** @@ -1303,7 +1302,7 @@ public class IScrollTable extends Composite implements ITable, } } - class VisibleColumnAction extends IAction { + class VisibleColumnAction extends Action { String colKey; private boolean collapsed; @@ -1353,7 +1352,7 @@ public class IScrollTable extends Composite implements ITable, /* * Returns columns as Action array for column select popup */ - public IAction[] getActions() { + public Action[] getActions() { Object[] cols; if (IScrollTable.this.columnReordering) { cols = columnOrder; @@ -1370,7 +1369,7 @@ public class IScrollTable extends Composite implements ITable, 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]; @@ -1708,14 +1707,14 @@ public class IScrollTable extends Composite implements ITable, * 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); @@ -1852,14 +1851,14 @@ public class IScrollTable extends Composite implements ITable, * * @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; } @@ -1889,7 +1888,8 @@ public class IScrollTable extends Composite implements ITable, } 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() { diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IShortcutActionHandler.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IShortcutActionHandler.java deleted file mode 100644 index 2d481ef914..0000000000 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IShortcutActionHandler.java +++ /dev/null @@ -1,156 +0,0 @@ -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; - } - -} - diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITable.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITable.java deleted file mode 100644 index 458cca95e2..0000000000 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITable.java +++ /dev/null @@ -1,10 +0,0 @@ -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; -} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java index d0ebfa59d2..e6334c3fe5 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITree.java @@ -233,13 +233,13 @@ public class ITree extends Tree implements Paintable { 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; } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITreeAction.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ITreeAction.java deleted file mode 100644 index dd8008da15..0000000000 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ITreeAction.java +++ /dev/null @@ -1,65 +0,0 @@ -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("\"icon\""); - } - sb.append(caption); - return sb.toString(); - } -} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java index 8492f66121..d937447005 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IView.java @@ -27,7 +27,7 @@ public class IView extends SimplePanel implements Paintable { private String id; - private IShortcutActionHandler actionHandler; + private ShortcutActionHandler actionHandler; public IView() { super(); @@ -93,7 +93,7 @@ public class IView extends SimplePanel implements Paintable { ((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); } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java index 031c057d80..420b175738 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java @@ -67,7 +67,7 @@ public class IWindow extends PopupPanel implements Paintable { private String id; - IShortcutActionHandler shortcutHandler; + ShortcutActionHandler shortcutHandler; public IWindow() { super(); @@ -175,7 +175,7 @@ public class IWindow extends PopupPanel implements Paintable { 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); } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ShortcutActionHandler.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ShortcutActionHandler.java new file mode 100644 index 0000000000..5710f1c7ea --- /dev/null +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ShortcutActionHandler.java @@ -0,0 +1,156 @@ +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; + } + +} + diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/Table.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/Table.java new file mode 100644 index 0000000000..6d43946734 --- /dev/null +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/Table.java @@ -0,0 +1,8 @@ +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; + +} diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/TreeAction.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/TreeAction.java new file mode 100644 index 0000000000..f2e283da3d --- /dev/null +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/TreeAction.java @@ -0,0 +1,65 @@ +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("\"icon\""); + } + sb.append(caption); + return sb.toString(); + } +}