[Buix-commits] r774 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action
Author: tchemit Date: 2008-07-24 14:05:02 +0000 (Thu, 24 Jul 2008) New Revision: 774 Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/MyAbstractAction.java Log: introduce abstract action to be used by the framework Added: 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 (rev 0) +++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/MyAbstractAction.java 2008-07-24 14:05:02 UTC (rev 774) @@ -0,0 +1,106 @@ +/** + * # #% Copyright (C) 2008 Code Lutin, Tony Chemit + * This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. + * # #% + */ +package org.codelutin.jaxx.action; + +import jaxx.runtime.JAXXObject; +import org.apache.commons.logging.LogFactory; + +import javax.swing.AbstractAction; +import javax.swing.JComponent; +import java.awt.event.ActionEvent; + +/** @author chemit */ +public abstract class MyAbstractAction extends AbstractAction { + + protected static org.apache.commons.logging.Log log = LogFactory.getLog(MyAbstractAction.class); + + private static final long serialVersionUID = -810023044364620841L; + + protected ActionEvent e; + + protected MyAbstractAction(String name) { + super(name); + } + + protected abstract String getPrefix(); + + public void actionPerformed(java.awt.event.ActionEvent e) { + + log.debug("------------------------------------------------------------"); + log.debug("event : " + e); + log.debug("source : " + e.getSource()); + this.e = e; + try { + boolean accepted = beforeAction(e); + log.debug("action : " + this); + if (accepted) { + log.info(getActionName() + " (treate:" + accepted + ") : " + this); + } else { + log.debug(getActionName() + " (treate:" + accepted + ") : " + this); + } + if (accepted) { + doAction(e); + updateUI(); + } + } catch (Exception e1) { + showError(e1); + } finally { + this.e = null; + // always clear action after use : actions are staless + clear(); + } + } + + protected String getActionName() { + return (String) getValue(ACTION_COMMAND_KEY); + } + + protected boolean beforeAction(ActionEvent e) throws Exception { + return isEnabled(); + } + + protected JComponent getUIObject(String name, JAXXObject container) { + if (container == null) { + return null; + } + return (JComponent) container.getObjectById(name); + } + + public String getI18nToolTipText() { + return getPrefix() + ".action." + getActionName() + ".tooltip"; + } + + protected void doAction(ActionEvent e) throws Exception { + // nothing by default + } + + public void updateUI() { + // nothing by default + } + + public void disposeUI() { + // nothing by default + } + + + protected void clear() { + // nothing by default + } + + protected void showError(Exception e) { + log.error(e); + } + +}
participants (1)
-
tchemit@users.labs.libre-entreprise.org