Jaxx-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
July 2008
- 1 participants
- 124 discussions
[Buix-commits] r776 - in trunk/lutinjaxx: jaxx-swing-action/src/main/java/org/codelutin/jaxx/action jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider maven/src/main/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 14:10:12 +0000 (Thu, 24 Jul 2008)
New Revision: 776
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProvider.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java
Modified:
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java
Log:
introduce provider package
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java 2008-07-24 14:08:09 UTC (rev 775)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java 2008-07-24 14:10:12 UTC (rev 776)
@@ -1,72 +0,0 @@
-/**
- * # #% 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 org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.Map;
-
-/** @author chemit */
-public abstract class AbstractActionProvider<A extends MyAbstractAction> implements ActionProvider<A> {
-
- protected static Log log = LogFactory.getLog(AbstractActionProvider.class);
-
- protected String name;
-
- protected Class<A> baseClass;
-
- protected Map<String, Class<? extends A>> actions;
-
- protected abstract Map<String, Class<? extends A>> initCache();
-
- protected AbstractActionProvider(String name, Class<A> baseClass, boolean doInitCache) {
- this.name = name;
- this.baseClass = baseClass;
- if (doInitCache) {
- this.actions = initCache();
- }
- }
-
- public String getName() {
- return name;
- }
-
- public Class<A> getBaseClass() {
- return baseClass;
- }
-
- public Map<String, Class<? extends A>> getClasses() {
- return actions;
- }
-
- @Override
- public String toString() {
- return super.toString() + "<name:" + name + ", baseClass:" + baseClass.getSimpleName() + ">";
- }
-
- protected void clearCache() {
- if (actions != null) {
- actions.clear();
- actions = null;
- }
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- clearCache();
- }
-}
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java 2008-07-24 14:08:09 UTC (rev 775)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java 2008-07-24 14:10:12 UTC (rev 776)
@@ -1,33 +0,0 @@
-/**
- * # #% 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;
-
-/**
- * Contract to be realized by a provider of Actions
- *
- * @author chemit
- */
-public interface ActionProvider<A extends MyAbstractAction> {
-
- /** @return the name of the provider */
- String getName();
-
- /** @return the base classe of provided actions */
- Class<A> getBaseClass();
-
- /** @return the provided actions classes */
- java.util.Map<String, Class<? extends A>> getClasses();
-
-}
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java 2008-07-24 14:08:09 UTC (rev 775)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java 2008-07-24 14:10:12 UTC (rev 776)
@@ -1,85 +0,0 @@
-/**
- * # #% 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 static org.codelutin.i18n.I18n._;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
-
-/** @author chemit */
-public class ActionProviderFromProperties<A extends MyAbstractAction> extends AbstractActionProvider<A> {
-
- /** default prefix for an entryin mapping file. */
- protected static final String ACTION_KEY_PREFIX = "action.";
-
- protected String propertiesPath;
-
- protected ActionProviderFromProperties(String name, Class<A> baseClass, String propertiesPath) {
- super(name, baseClass, false);
- this.propertiesPath = propertiesPath;
- this.actions = initCache();
- }
-
- @SuppressWarnings({"unchecked"})
- protected Map<String, Class<? extends A>> initCache() {
-
- InputStream inputStream = null;
-
- Properties properties = new Properties();
-
- try {
- inputStream = getClass().getResourceAsStream(propertiesPath);
- if (inputStream == null) {
- throw new NullPointerException("could not find action file " + propertiesPath);
- }
- log.info("load " + propertiesPath);
- properties.load(inputStream);
- } catch (IOException e) {
- log.warn(_("jaxx.error.load.actions.file", e.getMessage()));
- throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage()));
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- log.warn(_("jaxx.error.close.actions.file", e.getMessage()));
- //throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage()));
- }
- }
- }
-
- Map<String, Class<? extends A>> cache = new TreeMap<String, Class<? extends A>>();
- int prefix = ACTION_KEY_PREFIX.length();
- for (Map.Entry<Object, Object> entry : properties.entrySet()) {
- String key = entry.getKey() + "";
- String qfn = entry.getValue() + "";
- try {
- Class<? extends A> implCass;
- implCass = (Class<? extends A>) Class.forName(qfn);
- String actionKey = key.substring(prefix);
- log.debug("found action <" + actionKey + " : " + implCass + ">");
- cache.put(actionKey, implCass);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
- }
- }
-
- return cache;
- }
-}
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java (from rev 771, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java 2008-07-24 14:10:12 UTC (rev 776)
@@ -0,0 +1,73 @@
+/**
+ * # #% 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.provider;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.jaxx.action.MyAbstractAction;
+
+import java.util.Map;
+
+/** @author chemit */
+public abstract class AbstractActionProvider<A extends MyAbstractAction> implements ActionProvider<A> {
+
+ protected static Log log = LogFactory.getLog(AbstractActionProvider.class);
+
+ protected String name;
+
+ protected Class<A> baseClass;
+
+ protected Map<String, Class<? extends A>> actions;
+
+ protected abstract Map<String, Class<? extends A>> initCache();
+
+ protected AbstractActionProvider(String name, Class<A> baseClass, boolean doInitCache) {
+ this.name = name;
+ this.baseClass = baseClass;
+ if (doInitCache) {
+ this.actions = initCache();
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Class<A> getBaseClass() {
+ return baseClass;
+ }
+
+ public Map<String, Class<? extends A>> getClasses() {
+ return actions;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "<name:" + name + ", baseClass:" + baseClass.getSimpleName() + ">";
+ }
+
+ protected void clearCache() {
+ if (actions != null) {
+ actions.clear();
+ actions = null;
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ clearCache();
+ }
+}
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProvider.java (from rev 775, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProvider.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProvider.java 2008-07-24 14:10:12 UTC (rev 776)
@@ -0,0 +1,35 @@
+/**
+ * # #% 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.provider;
+
+import org.codelutin.jaxx.action.MyAbstractAction;
+
+/**
+ * Contract to be realized by a provider of Actions
+ *
+ * @author chemit
+ */
+public interface ActionProvider<A extends MyAbstractAction> {
+
+ /** @return the name of the provider */
+ String getName();
+
+ /** @return the base classe of provided actions */
+ Class<A> getBaseClass();
+
+ /** @return the provided actions classes */
+ java.util.Map<String, Class<? extends A>> getClasses();
+
+}
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java (from rev 775, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-07-24 14:10:12 UTC (rev 776)
@@ -0,0 +1,86 @@
+/**
+ * # #% 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.provider;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.jaxx.action.MyAbstractAction;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Properties;
+import java.util.TreeMap;
+
+/** @author chemit */
+public class ActionProviderFromProperties<A extends MyAbstractAction> extends AbstractActionProvider<A> {
+
+ /** default prefix for an entryin mapping file. */
+ protected static final String ACTION_KEY_PREFIX = "action.";
+
+ protected String propertiesPath;
+
+ protected ActionProviderFromProperties(String name, Class<A> baseClass, String propertiesPath) {
+ super(name, baseClass, false);
+ this.propertiesPath = propertiesPath;
+ this.actions = initCache();
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected Map<String, Class<? extends A>> initCache() {
+
+ InputStream inputStream = null;
+
+ Properties properties = new Properties();
+
+ try {
+ inputStream = getClass().getResourceAsStream(propertiesPath);
+ if (inputStream == null) {
+ throw new NullPointerException("could not find action file " + propertiesPath);
+ }
+ log.info("load " + propertiesPath);
+ properties.load(inputStream);
+ } catch (IOException e) {
+ log.warn(_("jaxx.error.load.actions.file", e.getMessage()));
+ throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage()));
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ log.warn(_("jaxx.error.close.actions.file", e.getMessage()));
+ //throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage()));
+ }
+ }
+ }
+
+ Map<String, Class<? extends A>> cache = new TreeMap<String, Class<? extends A>>();
+ int prefix = ACTION_KEY_PREFIX.length();
+ for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+ String key = entry.getKey() + "";
+ String qfn = entry.getValue() + "";
+ try {
+ Class<? extends A> implCass;
+ implCass = (Class<? extends A>) Class.forName(qfn);
+ String actionKey = key.substring(prefix);
+ log.debug("found action <" + actionKey + " : " + implCass + ">");
+ cache.put(actionKey, implCass);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
+ }
+ }
+
+ return cache;
+ }
+}
Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java 2008-07-24 14:08:09 UTC (rev 775)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java 2008-07-24 14:10:12 UTC (rev 776)
@@ -19,14 +19,14 @@
package org.codelutin.jaxx;
-import org.codelutin.jaxx.action.ActionProvider;
+import org.codelutin.jaxx.action.provider.ActionProvider;
import org.codelutin.util.FileUtil;
import java.io.File;
import java.io.IOException;
/**
- * Classe permettant de generer un {@link org.codelutin.jaxx.action.ActionProvider} et son fichier de d�claration.
+ * Classe permettant de generer un {@link org.codelutin.jaxx.action.provider.ActionProvider} et son fichier de d�claration.
*
* @author chemit
* @goal generate-actions-provider
@@ -66,7 +66,7 @@
protected static final String PROVIDER_TEMPLATE =
"package %1$s;\n" +
"\n" +
- "public class %2$s extends org.codelutin.jaxx.action.ActionProviderFromProperties<%3$s> {\n" +
+ "public class %2$s extends org.codelutin.jaxx.action.provider.ActionProviderFromProperties<%3$s> {\n" +
"\n" +
" public %2$s() {\n" +
" super(\"%5$s\", %3$s.class, \"%4$s\");\n" +
1
0
[Buix-commits] r775 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 14:08:09 +0000 (Thu, 24 Jul 2008)
New Revision: 775
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java
Log:
refactore code
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java 2008-07-24 14:05:02 UTC (rev 774)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java 2008-07-24 14:08:09 UTC (rev 775)
@@ -22,7 +22,10 @@
import jaxx.runtime.swing.JAXXToggleButton;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import static org.codelutin.i18n.I18n._;
+import org.codelutin.jaxx.action.initializer.ActionConfigInitializer;
+import org.codelutin.jaxx.action.initializer.ActionInitializer;
+import org.codelutin.jaxx.action.initializer.SelectActionConfigInitializer;
+import org.codelutin.jaxx.action.initializer.ToggleActionConfigInitializer;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
@@ -30,6 +33,9 @@
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import java.awt.event.ActionEvent;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -49,25 +55,42 @@
*
* @author chemit
*/
-public abstract class ActionFactory {
+public abstract class ActionFactory<A extends MyAbstractAction> {
protected static Log log = LogFactory.getLog(ActionFactory.class);
+ /** class of encapsuling action */
+ protected Class<A> baseImpl;
+
/** dictionary of known actions implementations */
- private Map<String, Class<? extends AbstractAction>> impls;
+ private Map<String, Class<? extends MyAbstractAction>> impls;
+
/** dictionary of instanciated actions */
- private Map<String, AbstractAction> cache;
+ private Map<String, MyAbstractAction> cache;
+ protected final ActionConfigInitializer actionConfigInitializer;
+ protected final ToggleActionConfigInitializer toggleActionConfigInitializer;
+ protected final SelectActionConfigInitializer selectActionConfigInitializer;
+
/**
* Method to init the dictionary of knwon action implementations.
*
* @return the dictionary of known action implementations
*/
- protected abstract Map<String, Class<? extends AbstractAction>> init();
+ protected abstract Map<String, Class<? extends MyAbstractAction>> init();
- protected ActionFactory() {
- impls = init();
- cache = new TreeMap<String, AbstractAction>();
+ protected List<ActionInitializer> registredInitializers;
+
+
+ protected ActionFactory(Class<A> baseImpl) {
+ this.baseImpl = baseImpl;
+ this.impls = init();
+ this.cache = new TreeMap<String, MyAbstractAction>();
+ this.registredInitializers = new java.util.ArrayList<ActionInitializer>();
+
+ this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigInitializer.class);
+ this.actionConfigInitializer = registerInitializer(ActionConfigInitializer.class);
+ this.selectActionConfigInitializer = registerInitializer(SelectActionConfigInitializer.class);
}
public void resetCache() {
@@ -81,23 +104,28 @@
impls.clear();
}
- public AbstractAction get(String actionKey) {
+ public MyAbstractAction get(String actionKey) {
return cache.get(actionKey);
}
- public AbstractAction[] loadActions(JAXXObject ui) {
- List<AbstractAction> result = new ArrayList<AbstractAction>();
- for (Map.Entry<String, Class<? extends AbstractAction>> entry : implsEntrySet()) {
+ public MyAbstractAction[] loadActions(JAXXObject ui) {
+ if (log.isDebugEnabled()) {
+ log.debug("for ui " + ui.getClass());
+ }
+ List<MyAbstractAction> result = new ArrayList<MyAbstractAction>();
+ for (Map.Entry<String, Class<? extends MyAbstractAction>> entry : implsEntrySet()) {
String actionKey = entry.getKey();
Object comp = ui.getObjectById(actionKey);
if (comp == null || !(comp instanceof AbstractButton || comp instanceof JComboBox)) {
// nothing to do
continue;
}
-
+ if (log.isTraceEnabled()) {
+ log.trace("detect action " + actionKey);
+ }
if (comp instanceof AbstractButton) {
AbstractButton component = (AbstractButton) comp;
- AbstractAction action = newAction(actionKey, component);
+ MyAbstractAction action = newAction(actionKey, component);
component.setAction(action);
@@ -126,36 +154,27 @@
result.add(action);
continue;
}
+ // is JComboBox
+ JComboBox component = (JComboBox) comp;
+ MyAbstractAction action = newAction(actionKey, component);
- if (comp instanceof JComboBox) {
- JComboBox component = (JComboBox) comp;
- AbstractAction action = newAction(actionKey, component);
-
- component.setAction(action);
- Integer val = (Integer) action.getValue("selectedIndex");
- if (val != null && val != -1 && val < component.getItemCount() && val != component.getSelectedIndex()) {
- component.setSelectedIndex(val);
- }
- result.add(action);
+ component.setAction(action);
+ Integer val = (Integer) action.getValue("selectedIndex");
+ if (val != null && val != -1 && val < component.getItemCount() && val != component.getSelectedIndex()) {
+ component.setSelectedIndex(val);
}
+ result.add(action);
}
- return result.toArray(new AbstractAction[result.size()]);
+ return result.toArray(new MyAbstractAction[result.size()]);
}
- public AbstractAction newAction0(String actionKey) {
- // on v�rifie que l'action existe bien
- checkRegistredAction(actionKey);
-
- // try in cache
- if (cache.containsKey(actionKey)) {
- // use cached action
- AbstractAction action = cache.get(actionKey);
- if (log.isDebugEnabled()) {
- log.debug("use cache action " + action);
- }
- return action;
+ public static ImageIcon createImageIcon(String path) {
+ java.net.URL imgURL = org.codelutin.jaxx.action.ActionFactory.class.getResource("/icons/" + path);
+ if (imgURL != null) {
+ return new ImageIcon(imgURL);
+ } else {
+ throw new RuntimeException("could not find icon " + path);
}
- return null;
}
/**
@@ -164,224 +183,207 @@
* @param component le button o� rattacher l'action
* @return une nouvelle instance de l'action associ�e � sa clef.
*/
- public AbstractAction newAction(String actionKey, AbstractButton component) {
-
+ public MyAbstractAction newAction(String actionKey, JComponent component) {
// try first in cache
- AbstractAction result = newAction0(actionKey);
+ MyAbstractAction result = getActionFromCache(actionKey);
if (result != null) {
return result;
}
- // on r�cup�re la classe d'implantation de l'action
- Class<? extends AbstractAction> klazz = impls.get(actionKey);
try {
- result = klazz.getConstructor(String.class).newInstance(actionKey);
- result.putValue(Action.ACTION_COMMAND_KEY, actionKey);
+ result = newActionInstance(actionKey);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
- if (log.isDebugEnabled()) {
- log.debug("create action " + actionKey + " : " + result);
- }
- // recherche de l'annotation de configuration
- ActionConfig anno = initActionConfig(component, result);
+ if (log.isDebugEnabled()) {
+ log.debug("create <" + actionKey + " : " + result + ">");
+ }
- if (anno == null) {
- ToggleActionConfig anno2 = initToggleActionConfig(component, result);
- if (anno2 == null && component != null) {
- result.putValue(Action.ACTION_COMMAND_KEY, component.getName());
- result.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
- result.putValue(Action.SMALL_ICON, component.getIcon());
- result.putValue(Action.NAME, component.getText());
- result.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
- result.putValue("hideActionText", component.getHideActionText());
- if (component instanceof JAXXToggleButton) {
- JAXXToggleButton glueComponent = (JAXXToggleButton) component;
- result.putValue(Action.SHORT_DESCRIPTION, glueComponent.getNormalTooltipText());
- result.putValue(Action.NAME, glueComponent.getNormalText());
- result.putValue(Action.SMALL_ICON, glueComponent.getIcon());
- result.putValue(Action.MNEMONIC_KEY, glueComponent.getNormalMnemonic());
- result.putValue(Action.SHORT_DESCRIPTION + 2, glueComponent.getGlueTooltipText());
- result.putValue(Action.NAME + 2, glueComponent.getGlueText());
- result.putValue(Action.SMALL_ICON + 2, glueComponent.getSelectedIcon());
- result.putValue(Action.MNEMONIC_KEY + 2, glueComponent.getGlueMnemonic());
- }
+ // recherche de l'annotation de configuration
+ ActionInitializer<?, ?> initializer = findInitializer(result.getClass());
+
+ if (initializer != null) {
+ initializer.initAction(component, result);
+ }
+
+ try {
+
+ if (initializer != null) {
+ if (AbstractButton.class.isAssignableFrom(initializer.getComponentImpl())) {
+ finalizeNewAction((AbstractButton) component, result, initializer);
}
- }
- String text = (String) result.getValue(Action.NAME);
- Integer mnemo = (Integer) result.getValue(Action.MNEMONIC_KEY);
- if (mnemo != null && mnemo != '\0') {
- int pos = text.indexOf((char) mnemo.intValue());
- if (pos == -1) {
- pos = text.indexOf(Character.toLowerCase((char) mnemo.intValue()));
+ if (JComboBox.class.isAssignableFrom(initializer.getComponentImpl())) {
+ finalizeNewAction((JComboBox) component, result, initializer);
}
- result.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
+
+ return result;
}
+
+ if (component == null || component instanceof AbstractButton) {
+ finalizeNewAction((AbstractButton) component, result, initializer);
+ return result;
+ }
+
+ if (component instanceof JComboBox) {
+ finalizeNewAction((JComboBox) component, result, initializer);
+ }
+ } finally {
+ // save result in cache
cache.put(actionKey, result);
- return result;
- } catch (Exception e) {
- throw new RuntimeException(e);
}
+
+ return result;
}
+ public String[] getActionNames() {
+ return impls.keySet().toArray(new String[impls.size()]);
+ }
+
+ public Set<Map.Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet() {
+ return impls.entrySet();
+ }
+
+ public Set<Map.Entry<String, MyAbstractAction>> cacheEntrySet() {
+ return cache.entrySet();
+ }
+
+ public void fireAction(String actionKey, Object source, JComponent component) {
+ AbstractAction action = newAction(actionKey, component);
+ fireAction0(actionKey, source, action);
+ }
+
+
/**
- * @param actionKey le nom de l'action tel que d�finie dans le fichier
- * de mapping (sans le prefix action.)
- * @param component le button o� rattacher l'action
- * @return une nouvelle instance de l'action associ�e � sa clef.
+ * @param actionKey la clef de l'action
+ * @return l'action deja stockee dans le cache d'action, ou <code>null</code> si non trouv�e.
*/
- public AbstractAction newAction(String actionKey, JComboBox component) {
+ public MyAbstractAction getActionFromCache(String actionKey) {
+ // on v�rifie que l'action existe bien
+ checkRegistredAction(actionKey);
- // try first in cache
- AbstractAction result = newAction0(actionKey);
- if (result != null) {
- return result;
+ // try in cache
+ if (cache.containsKey(actionKey)) {
+ // use cached action
+ MyAbstractAction action = cache.get(actionKey);
+ if (log.isDebugEnabled()) {
+ log.debug("use cache action " + action);
+ }
+ return action;
}
+ return null;
+ }
- // on r�cup�re la classe d'implantation de l'action
- Class<? extends AbstractAction> klazz = impls.get(actionKey);
+ public void dispose() {
- try {
- result = klazz.getConstructor(String.class).newInstance(actionKey);
- result.putValue(Action.ACTION_COMMAND_KEY, actionKey);
-
- log.debug(actionKey + " : " + result);
- // recherche de l'annotation de configuration
- SelectActionConfig anno = initSelectActionConfig(component, result);
- if (anno == null) {
- result.putValue(Action.ACTION_COMMAND_KEY, component.getName());
- result.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
- //result.putValue("selectedIndex", component.getSelectedIndex());
+ for (String actionKey : getActionNames()) {
+ MyAbstractAction action = getActionFromCache(actionKey);
+ if (action != null) {
+ action.disposeUI();
}
- cache.put(actionKey, result);
- return result;
- } catch (Exception e) {
- throw new RuntimeException(e);
}
+ resetCache();
}
- public static ToggleActionConfig initToggleActionConfig(AbstractButton component, AbstractAction result) {
- ToggleActionConfig anno = result.getClass().getAnnotation(ToggleActionConfig.class);
- if (anno != null) {
- // inject les donn�es
- if (!anno.name().isEmpty()) {
- //System.out.println("found action with name : " + anno.name());
- result.putValue(Action.NAME, _(anno.name()));
- }
- if (!anno.name2().isEmpty()) {
- //System.out.println("found action with name2 : " + anno.name2());
- result.putValue(Action.NAME + "2", _(anno.name2()));
- }
+ /**
+ * @param component le button o� rattacher l'action
+ * @param action action
+ * @param initializer initializer
+ */
+ protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
- if (!anno.shortDescription().isEmpty()) {
- result.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
+ if (initializer == null) {
+ // no initializer matching,
+ if (component != null) {
+ action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
+ action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
+ action.putValue(Action.SMALL_ICON, component.getIcon());
+ action.putValue(Action.NAME, component.getText());
+ action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
+ action.putValue("hideActionText", component.getHideActionText());
+ if (component instanceof JAXXToggleButton) {
+ JAXXToggleButton glueComponent = (JAXXToggleButton) component;
+ action.putValue(Action.SHORT_DESCRIPTION, glueComponent.getNormalTooltipText());
+ action.putValue(Action.NAME, glueComponent.getNormalText());
+ action.putValue(Action.SMALL_ICON, glueComponent.getIcon());
+ action.putValue(Action.MNEMONIC_KEY, glueComponent.getNormalMnemonic());
+ action.putValue(Action.SHORT_DESCRIPTION + 2, glueComponent.getGlueTooltipText());
+ action.putValue(Action.NAME + 2, glueComponent.getGlueText());
+ action.putValue(Action.SMALL_ICON + 2, glueComponent.getSelectedIcon());
+ action.putValue(Action.MNEMONIC_KEY + 2, glueComponent.getGlueMnemonic());
+ }
}
- if (!anno.shortDescription2().isEmpty()) {
- result.putValue(Action.SHORT_DESCRIPTION + "2", _(anno.shortDescription2()));
- }
- if (!anno.smallIcon().isEmpty()) {
- result.putValue(Action.SMALL_ICON, createImageIcon(anno.smallIcon()));
- }
- if (!anno.smallIcon2().isEmpty()) {
- result.putValue(Action.SMALL_ICON + "2", createImageIcon(anno.smallIcon2()));
- }
+ }
- if (anno.mnemonic() != '\0') {
- result.putValue(Action.MNEMONIC_KEY, anno.mnemonic());
- } else if (component != null) {
- result.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
+ String text = (String) action.getValue(Action.NAME);
+ Integer mnemo = (Integer) action.getValue(Action.MNEMONIC_KEY);
+ if (mnemo != null && mnemo != '\0') {
+ int pos = text.indexOf((char) mnemo.intValue());
+ if (pos == -1) {
+ pos = text.indexOf(Character.toLowerCase((char) mnemo.intValue()));
}
- if (anno.mnemonic2() != '\0') {
- result.putValue(Action.MNEMONIC_KEY + "2", anno.mnemonic2());
- }
- //TODO Convert it from String result.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
+ action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
+ }
+ }
- result.putValue("hideActionText", anno.hideActionText());
- result.putValue(Action.SELECTED_KEY, anno.selected());
- result.setEnabled(anno.enabled());
+ /**
+ * @param component le select box o� rattacher l'action
+ * @param action action
+ * @param initializer initializer
+ */
+ protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionInitializer<?, ?> initializer) {
+
+ if (initializer == null) {
+ action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
+ action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
+ //result.putValue("selectedIndex", component.getSelectedIndex());
}
- return anno;
+
}
- public static ActionConfig initActionConfig(AbstractButton component, AbstractAction result) {
- ActionConfig anno = result.getClass().getAnnotation(ActionConfig.class);
- if (anno != null) {
- // inject les donn�es
- if (!anno.name().isEmpty()) {
- //System.out.println("found action with name : " + anno.name());
- result.putValue(Action.NAME, _(anno.name()));
+ protected ActionInitializer findInitializer(Class<? extends AbstractAction> action) {
+ for (ActionInitializer registredInitializer : registredInitializers) {
+ if (registredInitializer.getAnnotation(action) != null) {
+ return registredInitializer;
}
- //if (!anno.shortDescription().isEmpty()) {
- result.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
- //}
- if (!anno.smallIcon().isEmpty()) {
- result.putValue(Action.SMALL_ICON, createImageIcon(anno.smallIcon()));
- }
- if (anno.mnemonic() != '\0') {
- result.putValue(Action.MNEMONIC_KEY, anno.mnemonic());
- } else if (component != null) {
- result.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
- }
- //TODO Convert it from String result.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
+ }
+ return null;
+ }
- if (component == null) {
- result.putValue("hideActionText", anno.hideActionText());
- } else {
- boolean actionText = component.getHideActionText();
- result.putValue("hideActionText", anno.hideActionText() || actionText);
- }
- result.putValue(Action.SELECTED_KEY, anno.selected());
- result.setEnabled(anno.enabled());
-
+ protected <I extends ActionInitializer> I registerInitializer(Class<I> initizalizer) {
+ try {
+ I instance = initizalizer.newInstance();
+ registredInitializers.add(instance);
+ return instance;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
- return anno;
}
- public static SelectActionConfig initSelectActionConfig(JComboBox component, AbstractAction result) {
- SelectActionConfig anno = result.getClass().getAnnotation(SelectActionConfig.class);
- if (anno != null) {
- // inject les donn�es
- if (!anno.name().isEmpty()) {
- result.putValue(Action.NAME, _(anno.name()));
- }
- if (!anno.shortDescription().isEmpty()) {
- result.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
- } else {
- result.putValue(Action.SHORT_DESCRIPTION, _(component.getToolTipText()));
- }
- result.putValue("selectedIndex", anno.selectedIndex());
- //TODO Convert it from String result.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
- result.setEnabled(anno.enabled());
+ protected void fireAction0(String actionKey, Object source, AbstractAction action) {
+ if (action == null) {
+ log.warn("could not find action " + actionKey);
+ return;
}
- return anno;
+ ActionEvent event = new ActionEvent(source, ActionEvent.ACTION_FIRST, actionKey);
+ action.actionPerformed(event);
}
-
protected void checkRegistredAction(String actionKey) {
if (!impls.containsKey(actionKey)) {
throw new IllegalStateException("can not find a registered action for key " + actionKey);
}
}
- public String[] getActionNames() {
- return impls.keySet().toArray(new String[impls.size()]);
- }
- public Set<Map.Entry<String, Class<? extends AbstractAction>>> implsEntrySet() {
- return impls.entrySet();
+ protected MyAbstractAction newActionInstance(String actionKey) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
+ Class<? extends MyAbstractAction> klazz = impls.get(actionKey);
+ MyAbstractAction result;
+ result = klazz.getConstructor(String.class).newInstance(actionKey);
+ result.putValue(Action.ACTION_COMMAND_KEY, actionKey);
+ return result;
}
-
- public Set<Map.Entry<String, AbstractAction>> cacheEntrySet() {
- return cache.entrySet();
- }
-
- public static ImageIcon createImageIcon(String path) {
- java.net.URL imgURL = org.codelutin.jaxx.action.ActionFactory.class.getResource("/icons/" + path);
- if (imgURL != null) {
- return new ImageIcon(imgURL);
- } else {
- throw new RuntimeException("could not find icon " + path);
- }
- }
}
\ No newline at end of file
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java 2008-07-24 14:05:02 UTC (rev 774)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java 2008-07-24 14:08:09 UTC (rev 775)
@@ -17,7 +17,6 @@
* ##% */
package org.codelutin.jaxx.action;
-import javax.swing.AbstractAction;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.TreeMap;
@@ -33,24 +32,27 @@
*
* @author chemit
*/
-public class ActionFactoryFromProvider extends ActionFactory {
+public class ActionFactoryFromProvider<A extends MyAbstractAction> extends ActionFactory<A> {
- /** real file where to load actions mapping */
- protected String actionFilePath;
+ public static <A extends MyAbstractAction> ActionFactoryFromProvider<A> newInstance(Class<A> klazz) {
+ return new ActionFactoryFromProvider<A>(klazz);
+ }
- public ActionFactoryFromProvider() {
- super();
+ protected ActionFactoryFromProvider(Class<A> baseClass) {
+ super(baseClass);
}
-
- protected Map<String, Class<? extends AbstractAction>> init() {
+ protected Map<String, Class<? extends MyAbstractAction>> init() {
+ if (log.isDebugEnabled()) {
+ log.debug("start loading " + this);
+ }
// obtain a ServiceLoader on ActionProvider
ServiceLoader<ActionProvider> loader = ServiceLoader.load(ActionProvider.class);
- Map<String, Class<? extends AbstractAction>> cache = new TreeMap<String, Class<? extends AbstractAction>>();
+ Map<String, Class<? extends MyAbstractAction>> cache = new TreeMap<String, Class<? extends MyAbstractAction>>();
for (ActionProvider<?> actionProvider : loader) {
if (log.isDebugEnabled()) {
- log.debug("load action provider " + actionProvider);
+ log.debug("found " + actionProvider);
}
cache.putAll(actionProvider.getClasses());
}
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java 2008-07-24 14:05:02 UTC (rev 774)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java 2008-07-24 14:08:09 UTC (rev 775)
@@ -19,7 +19,7 @@
*
* @author chemit
*/
-public interface ActionProvider<A extends javax.swing.AbstractAction> {
+public interface ActionProvider<A extends MyAbstractAction> {
/** @return the name of the provider */
String getName();
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java 2008-07-24 14:05:02 UTC (rev 774)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java 2008-07-24 14:08:09 UTC (rev 775)
@@ -16,7 +16,6 @@
import static org.codelutin.i18n.I18n._;
-import javax.swing.AbstractAction;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
@@ -24,7 +23,7 @@
import java.util.TreeMap;
/** @author chemit */
-public class ActionProviderFromProperties<A extends AbstractAction> extends AbstractActionProvider<A> {
+public class ActionProviderFromProperties<A extends MyAbstractAction> extends AbstractActionProvider<A> {
/** default prefix for an entryin mapping file. */
protected static final String ACTION_KEY_PREFIX = "action.";
@@ -46,6 +45,9 @@
try {
inputStream = getClass().getResourceAsStream(propertiesPath);
+ if (inputStream == null) {
+ throw new NullPointerException("could not find action file " + propertiesPath);
+ }
log.info("load " + propertiesPath);
properties.load(inputStream);
} catch (IOException e) {
@@ -64,16 +66,17 @@
Map<String, Class<? extends A>> cache = new TreeMap<String, Class<? extends A>>();
int prefix = ACTION_KEY_PREFIX.length();
- for (Map.Entry<Object, Object> objectObjectEntry : properties.entrySet()) {
- String key = objectObjectEntry.getKey() + "";
- String qfn = objectObjectEntry.getValue() + "";
+ for (Map.Entry<Object, Object> entry : properties.entrySet()) {
+ String key = entry.getKey() + "";
+ String qfn = entry.getValue() + "";
try {
Class<? extends A> implCass;
implCass = (Class<? extends A>) Class.forName(qfn);
- log.debug("found action " + implCass);
- cache.put(key.substring(prefix), implCass);
+ String actionKey = key.substring(prefix);
+ log.debug("found action <" + actionKey + " : " + implCass + ">");
+ cache.put(actionKey, implCass);
} catch (ClassNotFoundException e) {
- throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn));
+ throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
}
}
1
0
[Buix-commits] r774 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
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);
+ }
+
+}
1
0
[Buix-commits] r773 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 14:04:15 +0000 (Thu, 24 Jul 2008)
New Revision: 773
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SimpleActionFactoryImpl.java
Log:
no more used
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SimpleActionFactoryImpl.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SimpleActionFactoryImpl.java 2008-07-24 14:03:59 UTC (rev 772)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SimpleActionFactoryImpl.java 2008-07-24 14:04:15 UTC (rev 773)
@@ -1,103 +0,0 @@
-/*
-* ##% Copyright (C) 2007, 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 static org.codelutin.i18n.I18n._;
-import org.codelutin.util.Resource;
-
-import javax.swing.AbstractAction;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
-
-/**
- * A simple implementation of {@link org.codelutin.jaxx.action.ActionFactory} using a properties file to
- * load action mapping.
- * <p/>
- * An entry is in that form : <code>action.actionName=fqn</code> where
- * <p/>
- * <code>actionName</code> is the key of action used in factory, and
- * <code>fqn</code> is the fully qualified name of the implemented action class.
- *
- * @author chemit
- * @deprecated prefer use {@link org.codelutin.jaxx.action.ActionFactoryFromProvider}
- */
-public class SimpleActionFactoryImpl extends ActionFactory {
- /** default file where to load action mapping */
- protected static final String ACTIONS_FILE_PATH = "/actions.properties";
-
- /** default prefix for an entryin mapping file. */
- protected static final String ACTION_KEY_PREFIX = "action.";
-
- /** real file where to load actions mapping */
- protected String actionFilePath;
-
- public SimpleActionFactoryImpl() {
- this(ACTIONS_FILE_PATH);
- }
-
- public SimpleActionFactoryImpl(String actionFilePath) {
- this.actionFilePath = actionFilePath;
- }
-
- @SuppressWarnings({"unchecked"})
- protected Map<String, Class<? extends AbstractAction>> init() {
- Properties properties = new Properties();
- List<URL> urls = Resource.getURLs(".*jaxx/.+-actions\\.properties");
- for (URL url : urls) {
- InputStream inputStream = null;
- try {
- inputStream = url.openStream();
- log.info("load " + url);
- properties.load(inputStream);
- } catch (IOException e) {
- log.warn(_("jaxx.error.load.actions.file", e.getMessage()));
- //throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage()));
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (IOException e) {
- log.warn(_("jaxx.error.close.actions.file", e.getMessage()));
- //throw new RuntimeException(_("jaxx.error.load.actions.file", e.getMessage()));
- }
- }
- }
- }
- Map<String, Class<? extends AbstractAction>> cache = new TreeMap<String, Class<? extends AbstractAction>>();
- int prefix = ACTION_KEY_PREFIX.length();
- for (Map.Entry<Object, Object> objectObjectEntry : properties.entrySet()) {
- String key = objectObjectEntry.getKey() + "";
- String qfn = objectObjectEntry.getValue() + "";
- try {
- Class<? extends AbstractAction> implCass;
- implCass = (Class<? extends AbstractAction>) Class.forName(qfn);
- log.debug("found action " + implCass);
- cache.put(key.substring(prefix), implCass);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn));
- }
- }
- return cache;
- }
-
-}
\ No newline at end of file
1
0
[Buix-commits] r772 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . initializer
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 14:03:59 +0000 (Thu, 24 Jul 2008)
New Revision: 772
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java
Log:
introduce package initializer
Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigInitializer.java 2008-07-24 14:03:59 UTC (rev 772)
@@ -0,0 +1,66 @@
+/**
+ * # #% 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.initializer;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.jaxx.action.ActionConfig;
+import org.codelutin.jaxx.action.ActionFactory;
+
+import javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+
+/** @author chemit */
+public class ActionConfigInitializer extends ActionInitializer<ActionConfig, AbstractButton> {
+
+ public ActionConfigInitializer() {
+ super(ActionConfig.class, AbstractButton.class);
+ }
+
+ protected ActionConfig initAction0(AbstractButton component, AbstractAction action) {
+ ActionConfig anno = getAnnotation(action.getClass());
+ if (anno == null) {
+ return null;
+ }
+ // inject les donn�es
+ if (!anno.name().isEmpty()) {
+ //System.out.println("found action with name : " + anno.name());
+ action.putValue(Action.NAME, _(anno.name()));
+ }
+ //if (!anno.shortDescription().isEmpty()) {
+ action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
+ //}
+ if (!anno.smallIcon().isEmpty()) {
+ action.putValue(Action.SMALL_ICON, ActionFactory.createImageIcon(anno.smallIcon()));
+ }
+ if (anno.mnemonic() != '\0') {
+ action.putValue(Action.MNEMONIC_KEY, anno.mnemonic());
+ } else if (component != null) {
+ action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
+ }
+ //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
+
+ if (component == null) {
+ action.putValue("hideActionText", anno.hideActionText());
+ } else {
+ boolean actionText = component.getHideActionText();
+ action.putValue("hideActionText", anno.hideActionText() || actionText);
+ }
+ action.putValue(Action.SELECTED_KEY, anno.selected());
+ action.setEnabled(anno.enabled());
+
+ return anno;
+ }
+}
Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionInitializer.java 2008-07-24 14:03:59 UTC (rev 772)
@@ -0,0 +1,57 @@
+/**
+ * # #% 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.initializer;
+
+import javax.swing.AbstractAction;
+import javax.swing.JComponent;
+
+/**
+ * Initializer of a MyAbstractAction described by a typed Annotation <code>A</code> and for a certain type
+ * <code>C</code> of component.
+ *
+ * @author chemit
+ */
+public abstract class ActionInitializer<A extends java.lang.annotation.Annotation, C extends JComponent> {
+
+ final Class<A> annotationImpl;
+ final Class<C> componentImpl;
+
+ protected abstract A initAction0(C component, AbstractAction action);
+
+ protected ActionInitializer(Class<A> annotationImpl, Class<C> componentImpl) {
+ this.annotationImpl = annotationImpl;
+ this.componentImpl = componentImpl;
+ }
+
+ public A getAnnotation(Class<? extends AbstractAction> action) {
+ return action.getAnnotation(annotationImpl);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public A initAction(JComponent component, AbstractAction action) {
+ if (component != null && componentImpl.isAssignableFrom(component.getClass()))
+ return initAction0((C) component, action);
+
+ return null;
+ }
+
+ public Class<A> getAnnotationImpl() {
+ return annotationImpl;
+ }
+
+ public Class<C> getComponentImpl() {
+ return componentImpl;
+ }
+}
Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigInitializer.java 2008-07-24 14:03:59 UTC (rev 772)
@@ -0,0 +1,51 @@
+/**
+ * # #% 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.initializer;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.jaxx.action.SelectActionConfig;
+
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.JComboBox;
+
+/** @author chemit */
+public class SelectActionConfigInitializer extends ActionInitializer<SelectActionConfig, JComboBox> {
+
+ public SelectActionConfigInitializer() {
+ super(SelectActionConfig.class, JComboBox.class);
+ }
+
+ protected SelectActionConfig initAction0(JComboBox component, AbstractAction action) {
+ SelectActionConfig anno = getAnnotation(action.getClass());
+ if (anno == null) {
+ return null;
+ }
+ // inject les donn�es
+ if (!anno.name().isEmpty()) {
+ action.putValue(Action.NAME, _(anno.name()));
+ }
+ if (!anno.shortDescription().isEmpty()) {
+ action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
+ } else {
+ action.putValue(Action.SHORT_DESCRIPTION, _(component.getToolTipText()));
+ }
+ action.putValue("selectedIndex", anno.selectedIndex());
+ //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
+ action.setEnabled(anno.enabled());
+
+ return anno;
+ }
+}
\ No newline at end of file
Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigInitializer.java 2008-07-24 14:03:59 UTC (rev 772)
@@ -0,0 +1,78 @@
+/**
+ * # #% 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.initializer;
+
+import static org.codelutin.i18n.I18n._;
+import org.codelutin.jaxx.action.ActionFactory;
+import org.codelutin.jaxx.action.ToggleActionConfig;
+
+import javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+
+/** @author chemit */
+public class ToggleActionConfigInitializer extends ActionInitializer<ToggleActionConfig, AbstractButton> {
+
+ public ToggleActionConfigInitializer() {
+ super(ToggleActionConfig.class, AbstractButton.class);
+ }
+
+ protected ToggleActionConfig initAction0(AbstractButton component, AbstractAction action) {
+ ToggleActionConfig anno = getAnnotation(action.getClass());
+ if (anno == null) {
+ return null;
+ }
+ // inject les donn�es
+ if (!anno.name().isEmpty()) {
+ //System.out.println("found action with name : " + anno.name());
+ action.putValue(Action.NAME, _(anno.name()));
+ }
+ if (!anno.name2().isEmpty()) {
+ //System.out.println("found action with name2 : " + anno.name2());
+ action.putValue(Action.NAME + "2", _(anno.name2()));
+ }
+
+ if (!anno.shortDescription().isEmpty()) {
+ action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
+ }
+ if (!anno.shortDescription2().isEmpty()) {
+ action.putValue(Action.SHORT_DESCRIPTION + "2", _(anno.shortDescription2()));
+ }
+
+ if (!anno.smallIcon().isEmpty()) {
+ action.putValue(Action.SMALL_ICON, ActionFactory.createImageIcon(anno.smallIcon()));
+ }
+ if (!anno.smallIcon2().isEmpty()) {
+ action.putValue(Action.SMALL_ICON + "2", ActionFactory.createImageIcon(anno.smallIcon2()));
+ }
+
+ if (anno.mnemonic() != '\0') {
+ action.putValue(Action.MNEMONIC_KEY, anno.mnemonic());
+ } else if (component != null) {
+ action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
+ }
+ if (anno.mnemonic2() != '\0') {
+ action.putValue(Action.MNEMONIC_KEY + "2", anno.mnemonic2());
+ }
+ //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
+
+
+ action.putValue("hideActionText", anno.hideActionText());
+ action.putValue(Action.SELECTED_KEY, anno.selected());
+ action.setEnabled(anno.enabled());
+
+ return anno;
+ }
+}
\ No newline at end of file
1
0
[Buix-commits] r771 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
by tchemit@users.labs.libre-entreprise.org 24 Jul '08
24 Jul '08
Author: tchemit
Date: 2008-07-24 12:14:23 +0000 (Thu, 24 Jul 2008)
New Revision: 771
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java
Log:
ajout du module jaxx-swing dans le plugin car on s'en sert ?\195?\160 chaque fois.
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java 2008-07-23 15:49:01 UTC (rev 770)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionProvider.java 2008-07-24 12:14:23 UTC (rev 771)
@@ -17,11 +17,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.swing.AbstractAction;
import java.util.Map;
/** @author chemit */
-public abstract class AbstractActionProvider<A extends AbstractAction> implements ActionProvider<A> {
+public abstract class AbstractActionProvider<A extends MyAbstractAction> implements ActionProvider<A> {
protected static Log log = LogFactory.getLog(AbstractActionProvider.class);
1
0
23 Jul '08
Author: tchemit
Date: 2008-07-23 15:49:01 +0000 (Wed, 23 Jul 2008)
New Revision: 770
Modified:
trunk/lutinjaxx/maven/pom.xml
Log:
ajout du module jaxx-swing dans le plugin car on s'en sert ?\195?\160 chaque fois.
Modified: trunk/lutinjaxx/maven/pom.xml
===================================================================
--- trunk/lutinjaxx/maven/pom.xml 2008-07-23 15:40:45 UTC (rev 769)
+++ trunk/lutinjaxx/maven/pom.xml 2008-07-23 15:49:01 UTC (rev 770)
@@ -41,7 +41,7 @@
<dependency>
<groupId>org.codelutin.jaxx</groupId>
<artifactId>jaxx-swing</artifactId>
- <scope>test</scope>
+ <scope>compile</scope>
</dependency>
<!-- maven plugin project dependencies -->
@@ -50,21 +50,13 @@
<artifactId>maven-plugin-api</artifactId>
<scope>compile</scope>
</dependency>
- <!--dependency>
- <groupId>org.apache.maven</groupId>
- <artifactId>maven-model</artifactId>
- <scope>compile</scope>
- </dependency-->
+
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<scope>compile</scope>
</dependency>
- <!--dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- <scope>compile</scope>
- </dependency-->
+
</dependencies>
<!-- ************************************************************* -->
1
0
[Buix-commits] r769 - in trunk/lutinjaxx: core/src/main/java/jaxx/tags core/src/test/java/jaxx/junit maven/src/main/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org 23 Jul '08
by tchemit@users.labs.libre-entreprise.org 23 Jul '08
23 Jul '08
Author: tchemit
Date: 2008-07-23 15:40:45 +0000 (Wed, 23 Jul 2008)
New Revision: 769
Modified:
trunk/lutinjaxx/core/src/main/java/jaxx/tags/TagManager.java
trunk/lutinjaxx/core/src/test/java/jaxx/junit/TagManagerTest.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
Log:
reset TagManager at each launch of JaxxGenerator goal
Modified: trunk/lutinjaxx/core/src/main/java/jaxx/tags/TagManager.java
===================================================================
--- trunk/lutinjaxx/core/src/main/java/jaxx/tags/TagManager.java 2008-07-23 15:30:43 UTC (rev 768)
+++ trunk/lutinjaxx/core/src/main/java/jaxx/tags/TagManager.java 2008-07-23 15:40:45 UTC (rev 769)
@@ -82,11 +82,11 @@
private TagManager() { /* not instantiable */ }
- public static void reset() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+ public static void reset(boolean verbose) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
registeredBeans.clear();
registeredTags.clear();
defaultNamespaces.clear();
- JAXXCompiler.loadLibraries();
+ JAXXCompiler.loadLibraries(verbose);
}
@@ -123,14 +123,13 @@
* and <JButton xmlns="javax.swing.*"/> are equivalent), so tags with package names are considered
* to have namespaces specified.
*
- * @param tag tag name
+ * @param tag tag name
* @param namespace namespace
*/
public static void registerDefaultNamespace(String tag, String namespace) {
if (defaultNamespaces.containsKey(tag) && !defaultNamespaces.get(tag).equals(namespace)) {
defaultNamespaces.put(tag, null); // tag name is now ambiguous
- }
- else {
+ } else {
defaultNamespaces.put(tag, namespace);
}
}
@@ -194,11 +193,11 @@
/**
* @param beanClass the tag class
* @return the <code>TagHandler</code> that should be used to process the specified class.
- * Only <code>TagHandlers</code> previously registered with <code>registerBean</code>
- * are considered.
+ * Only <code>TagHandlers</code> previously registered with <code>registerBean</code>
+ * are considered.
* @throws jaxx.CompilerException ?
*/
- public static DefaultObjectHandler getTagHandler(ClassDescriptor beanClass) throws CompilerException {
+ public static DefaultObjectHandler getTagHandler(ClassDescriptor beanClass) throws CompilerException {
try {
if (beanClass == null) {
throw new NullPointerException();
Modified: trunk/lutinjaxx/core/src/test/java/jaxx/junit/TagManagerTest.java
===================================================================
--- trunk/lutinjaxx/core/src/test/java/jaxx/junit/TagManagerTest.java 2008-07-23 15:30:43 UTC (rev 768)
+++ trunk/lutinjaxx/core/src/test/java/jaxx/junit/TagManagerTest.java 2008-07-23 15:40:45 UTC (rev 769)
@@ -91,7 +91,7 @@
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
System.setErr(new PrintStream(buffer));
compiler.addImport("java.util.*");
- TagManager.reset();
+ TagManager.reset(false);
assertNull("Still found a handler for Date with an ambiguous import", TagManager.getTagHandler(null, "Date", compiler));
System.setErr(oldErr);
assertTrue("No errors were produced with an ambiguous import", buffer.size() > 0);
Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-07-23 15:30:43 UTC (rev 768)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-07-23 15:40:45 UTC (rev 769)
@@ -21,6 +21,7 @@
import jaxx.compiler.CompilerOptions;
import jaxx.compiler.JAXXCompiler;
+import jaxx.tags.TagManager;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.DirectoryScanner;
@@ -90,7 +91,7 @@
protected void doExecute() throws Exception {
// force compiler init from here, not in a static block
- JAXXCompiler.loadLibraries(verbose);
+ TagManager.reset(verbose);
if (!JAXXCompiler.compile(src, files, options)) {
throw new MojoFailureException("Aborting due to errors reported by jaxxc");
1
0
[Buix-commits] r768 - in trunk/lutinjaxx: core/src/main/java/jaxx/compiler maven/src/main/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org 23 Jul '08
by tchemit@users.labs.libre-entreprise.org 23 Jul '08
23 Jul '08
Author: tchemit
Date: 2008-07-23 15:30:43 +0000 (Wed, 23 Jul 2008)
New Revision: 768
Modified:
trunk/lutinjaxx/core/src/main/java/jaxx/compiler/JAXXCompiler.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractActionGeneratorMojo.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
Log:
do not use log level + fix bug with static block in JaxxCompiler when we want to reexecute the compiler with a secon maven goal in the same time
Modified: trunk/lutinjaxx/core/src/main/java/jaxx/compiler/JAXXCompiler.java
===================================================================
--- trunk/lutinjaxx/core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-07-23 10:27:17 UTC (rev 767)
+++ trunk/lutinjaxx/core/src/main/java/jaxx/compiler/JAXXCompiler.java 2008-07-23 15:30:43 UTC (rev 768)
@@ -244,7 +244,9 @@
static {
try {
- loadLibraries();
+ // fixme beware, this is a very dangerous thing to use a static block
+ //loadLibraries();
+ // fixeme for the moment the compiler is init in maven plugin, not here
}
catch (Exception e) {
throw new RuntimeException(e);
@@ -255,11 +257,15 @@
// forces static initializer to run if it hasn't yet
}
- public static void loadLibraries() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
- ServiceLoader<Initializer> loader = ServiceLoader.load(Initializer.class);
+ public static void loadLibraries(boolean verbose) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+ ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+ if (verbose) {
+ log.info("with cl " + classloader);
+ }
+ ServiceLoader<Initializer> loader = ServiceLoader.load(Initializer.class, classloader);
for (Initializer initializer : loader) {
- if (log.isDebugEnabled()) {
- log.debug("load initializer " + initializer);
+ if (verbose) {
+ log.info("load initializer " + initializer);
}
initializer.initialize();
}
Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractActionGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractActionGeneratorMojo.java 2008-07-23 10:27:17 UTC (rev 767)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractActionGeneratorMojo.java 2008-07-23 15:30:43 UTC (rev 768)
@@ -38,8 +38,8 @@
String path = file.getAbsolutePath().substring(outResource.getAbsolutePath().length() + 1);
File compiledFile = new File(outClass, path);
- if (getLog().isDebugEnabled()) {
- getLog().debug("copy to classapth generated file " + compiledFile);
+ if (verbose) {
+ getLog().info("copy to classapth generated file " + compiledFile);
}
File parent = compiledFile.getParentFile();
if (!parent.exists()) {
Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java 2008-07-23 10:27:17 UTC (rev 767)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java 2008-07-23 15:30:43 UTC (rev 768)
@@ -63,7 +63,7 @@
/**
* @description verbose
- * @parameter expression="${jaxx.verbose}" default-value="${maven.verbose}"
+ * @parameter expression="${jaxx.verbose}" default-value="false"
*/
protected boolean verbose;
@@ -141,7 +141,7 @@
}
loader = result;
}
- if (log.isDebugEnabled() && loader != null) {
+ if (verbose && loader != null) {
for (URL entry : loader.getURLs()) {
log.info("outClass url " + entry);
}
Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java 2008-07-23 10:27:17 UTC (rev 767)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java 2008-07-23 15:30:43 UTC (rev 768)
@@ -84,8 +84,8 @@
for (String file : files) {
String fqn = file.substring(0, file.length() - 5).replaceAll("\\/", ".");
- if (getLog().isDebugEnabled()) {
- getLog().debug("fqn to treate " + fqn);
+ if (verbose) {
+ getLog().info("fqn to treate " + fqn);
}
Class<?> clazz = Class.forName(fqn, false, loader);
@@ -198,8 +198,8 @@
protected void registerEntry(Class<?> clazz, Properties result, String... names) {
for (String name : names) {
- if (getLog().isDebugEnabled()) {
- getLog().debug("name: " + name + ", class:" + clazz);
+ if (verbose) {
+ getLog().info("name: " + name + ", class:" + clazz);
}
result.put("action." + name, clazz.getName());
}
@@ -208,7 +208,7 @@
protected void printInit() {
for (String file : files) {
- getLog().debug(file);
+ getLog().info(file);
}
printCP();
@@ -216,10 +216,10 @@
protected void printCP() {
- getLog().debug(loader.toString());
+ getLog().info(loader.toString());
for (URL url : loader.getURLs()) {
- getLog().debug("url in class loader " + url);
+ getLog().info("url in class loader " + url);
}
}
Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-07-23 10:27:17 UTC (rev 767)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-07-23 15:30:43 UTC (rev 768)
@@ -25,6 +25,7 @@
import org.codehaus.plexus.util.DirectoryScanner;
import java.io.File;
+import java.net.URL;
/**
* Classe permettant de transformer des sources jaxx vers du source java.
@@ -87,6 +88,10 @@
}
protected void doExecute() throws Exception {
+
+ // force compiler init from here, not in a static block
+ JAXXCompiler.loadLibraries(verbose);
+
if (!JAXXCompiler.compile(src, files, options)) {
throw new MojoFailureException("Aborting due to errors reported by jaxxc");
}
@@ -106,14 +111,34 @@
}
protected void printInit() {
- getLog().debug("classPath: " + options.getClassPath());
- getLog().debug("javaOut : " + options.getTargetDirectory());
- getLog().debug("outClass : " + options.getJavacTargetDirectory());
- getLog().debug("javacOpts: " + options.getJavacOpts());
- getLog().debug("optiomize: " + options.getOptimize());
+ getLog().info("classPath: " + options.getClassPath());
+ getLog().info("javaOut : " + options.getTargetDirectory());
+ getLog().info("outClass : " + options.getJavacTargetDirectory());
+ getLog().info("javacOpts: " + options.getJavacOpts());
+ getLog().info("optiomize: " + options.getOptimize());
for (String file : files) {
- getLog().debug(file);
+ getLog().info(file);
}
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ getLog().info(cl.toString());
+ if (cl.getClass().getSimpleName().equals("RealmClassLoader")) {
+ try {
+ java.lang.reflect.Method m = cl.getClass().getDeclaredMethod("getURLs");
+ m.setAccessible(true);
+ URL[] urls = (URL[]) m.invoke(cl);
+
+ for (URL url : urls) {
+ getLog().info("url in class loader " + url);
+ }
+ } catch (Exception e) {
+ getLog().warn("??? : " + e.getMessage(), e);
+ }
+ }
+
+ for (Object e : getPluginContext().keySet()) {
+ getLog().info("pluginContext " + e + " : " + getPluginContext().get(e));
+ }
}
public File getSrc() {
1
0
[Buix-commits] r767 - in trunk/lutinjaxx: . maven
by tchemit@users.labs.libre-entreprise.org 23 Jul '08
by tchemit@users.labs.libre-entreprise.org 23 Jul '08
23 Jul '08
Author: tchemit
Date: 2008-07-23 10:27:17 +0000 (Wed, 23 Jul 2008)
New Revision: 767
Modified:
trunk/lutinjaxx/maven/pom.xml
trunk/lutinjaxx/pom.xml
Log:
clean dependencies
Modified: trunk/lutinjaxx/maven/pom.xml
===================================================================
--- trunk/lutinjaxx/maven/pom.xml 2008-07-23 08:06:48 UTC (rev 766)
+++ trunk/lutinjaxx/maven/pom.xml 2008-07-23 10:27:17 UTC (rev 767)
@@ -50,21 +50,21 @@
<artifactId>maven-plugin-api</artifactId>
<scope>compile</scope>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<scope>compile</scope>
- </dependency>
+ </dependency-->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<scope>compile</scope>
</dependency>
- <dependency>
+ <!--dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<scope>compile</scope>
- </dependency>
+ </dependency-->
</dependencies>
<!-- ************************************************************* -->
Modified: trunk/lutinjaxx/pom.xml
===================================================================
--- trunk/lutinjaxx/pom.xml 2008-07-23 08:06:48 UTC (rev 766)
+++ trunk/lutinjaxx/pom.xml 2008-07-23 10:27:17 UTC (rev 767)
@@ -247,24 +247,13 @@
<version>2.0.4</version>
<scope>compile</scope>
</dependency>
+
<dependency>
<groupId>org.apache.maven</groupId>
- <artifactId>maven-model</artifactId>
- <version>2.0.4</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.0.4</version>
<scope>compile</scope>
</dependency>
- <dependency>
- <groupId>org.codehaus.plexus</groupId>
- <artifactId>plexus-utils</artifactId>
- <version>1.0.5</version>
- <scope>compile</scope>
- </dependency>
</dependencies>
</dependencyManagement>
1
0