Author: tchemit Date: 2008-07-24 19:04:53 +0000 (Thu, 24 Jul 2008) New Revision: 789 Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/MyAbstractAction.java Log: introduce delegate mecanism in Action Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/MyAbstractAction.java =================================================================== --- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/MyAbstractAction.java 2008-07-24 18:52:48 UTC (rev 788) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/MyAbstractAction.java 2008-07-24 19:04:53 UTC (rev 789) @@ -30,14 +30,25 @@ protected ActionEvent e; + protected MyAbstractAction delegate; + + protected abstract String getPrefix(); + protected MyAbstractAction(String name) { super(name); } - protected abstract String getPrefix(); + protected MyAbstractAction(String name, MyAbstractAction delegate) { + super(name); + this.delegate = delegate; + } public void actionPerformed(java.awt.event.ActionEvent e) { - + if (delegate != null) { + // delegate to real action + delegate.actionPerformed(e); + return; + } log.debug("------------------------------------------------------------"); log.debug("event : " + e); log.debug("source : " + e.getSource()); @@ -63,39 +74,61 @@ } } - protected String getActionName() { - return (String) getValue(ACTION_COMMAND_KEY); + public String getI18nToolTipText() { + if (delegate != null) { + return delegate.getI18nToolTipText(); + } + return getPrefix() + ".action." + getActionName() + ".tooltip"; } - protected boolean beforeAction(ActionEvent e) throws Exception { - return isEnabled(); + public void updateUI() { + if (delegate != null) { + delegate.updateUI(); + } + // nothing by default } - protected JComponent getUIObject(String name, JAXXObject container) { - if (container == null) { - return null; + public void disposeUI() { + if (delegate != null) { + delegate.disposeUI(); } - return (JComponent) container.getObjectById(name); + // nothing by default } - public String getI18nToolTipText() { - return getPrefix() + ".action." + getActionName() + ".tooltip"; + public MyAbstractAction getDelegate() { + return delegate; } - protected void doAction(ActionEvent e) throws Exception { - // nothing by default + protected String getActionName() { + return (String) getValue(ACTION_COMMAND_KEY); } - public void updateUI() { - // nothing by default + protected boolean beforeAction(ActionEvent evt) throws Exception { + boolean enabled = isEnabled(); + if (enabled && delegate != null) { + return delegate.beforeAction(evt); + } + return enabled; } - public void disposeUI() { + protected void doAction(ActionEvent evt) throws Exception { + if (delegate != null) { + delegate.doAction(evt); + } // nothing by default } + protected JComponent getUIObject(String name, JAXXObject container) { + if (container == null) { + return null; + } + return (JComponent) container.getObjectById(name); + } protected void clear() { + if (delegate != null) { + delegate.clear(); + } // nothing by default }