Buix-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
- 1440 discussions
r822 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
09 Aug '08
Author: tchemit
Date: 2008-08-09 10:26:02 +0000 (Sat, 09 Aug 2008)
New Revision: 822
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/MyAbstractAction.java
Log:
javadoc
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-08-09 09:33:42 UTC (rev 821)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/MyAbstractAction.java 2008-08-09 10:26:02 UTC (rev 822)
@@ -24,7 +24,13 @@
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
-/** @author chemit */
+/**
+ * Action de base à utiliser pour encapsuler toutes les actions du système.
+ * <p/>
+ * Ces actions seront chargées par des {@link ActionProvider} et des {@link ActionFactory}.
+ *
+ * @author chemit
+ */
public abstract class MyAbstractAction extends AbstractAction {
protected static org.apache.commons.logging.Log log = LogFactory.getLog(MyAbstractAction.class);
1
0
r821 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
09 Aug '08
Author: tchemit
Date: 2008-08-09 09:33:42 +0000 (Sat, 09 Aug 2008)
New Revision: 821
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/
Log:
simplification du code : suppression du paquetage factory et provider
1
0
r820 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . factory
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
09 Aug '08
Author: tchemit
Date: 2008-08-09 09:32:42 +0000 (Sat, 09 Aug 2008)
New Revision: 820
Added:
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
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
Log:
simplification du code : suppression du paquetage factory
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java (from rev 798, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactory.java 2008-08-09 09:32:42 UTC (rev 820)
@@ -0,0 +1,131 @@
+/**
+ * # #% 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 javax.swing.JComponent;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * Action factory using the ActionConfig annotations to configure the action.
+ * <p/>
+ * Use after the {@link #loadActions(jaxx.runtime.JAXXObject)} to instanciate
+ * actions in ui with id equals a known action...
+ * <p/>
+ * TODO Finish doc
+ *
+ * @author chemit
+ */
+public interface ActionFactory<A extends MyAbstractAction> {
+
+ /**
+ * Method to init the dictionary of knwon action implementations.
+ *
+ * @return the dictionary of known action implementations
+ */
+ Map<String, Class<? extends MyAbstractAction>> init();
+
+ /** @return the class of the base action of the factory. */
+ Class<A> getBaseImpl();
+
+ /** clear the cache of instanciated actions. */
+ void resetCache();
+
+ /**
+ * @param actionKey the key of an action
+ * @return the action with this key from cache, or <code>null</code> if this action is not in cache
+ */
+ A get(String actionKey);
+
+ /**
+ * For a given ui, load all actions registred in factory.
+ * <p/>
+ * The id of the widget in ui is directly mapped to a action key.
+ *
+ * @param ui the ui to treate
+ */
+ void loadActions(JAXXObject ui);
+
+ /**
+ * Obtain an action instance given his key and widget
+ *
+ * @param actionKey the key of action
+ * @param component the component using the action
+ * @return the instanciated action (could come from cache if already instanciated {@link #getActionFromCache(String)}
+ */
+ A newAction(String actionKey, JComponent component);
+
+ /**
+ * Obtain an action instance given his key (should call {@link #newAction(String, javax.swing.JComponent)}
+ * <p/>
+ * This is a convinient method when you want to obtain an action with no attached widget.
+ *
+ * @param actionKey the key of action
+ * @return the instanciated action (could come from cache if already instanciated {@link #getActionFromCache(String)}
+ */
+ A newAction(String actionKey);
+
+ /** @return the array of names of all actions known by the factory */
+ String[] getActionNames();
+
+ /** @return the set of all the action's classes known by the factory. */
+ Set<Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet();
+
+ /** @return the set of all actions cached in factory indexed by their name */
+ Set<Entry<String, A>> cacheEntrySet();
+
+ /**
+ * Fire an action given his key, his source and tthe widget responsible of action
+ *
+ * @param actionKey the action's key
+ * @param source the object source of action
+ * @param component the component doing the action
+ */
+ void fireAction(String actionKey, Object source, JComponent component);
+
+ /**
+ * Fire an action given his key and his source, no widget are involved here
+ *
+ * @param actionKey the action's key
+ * @param source the object source of action
+ */
+ void fireAction(String actionKey, Object source);
+
+ /**
+ * Fire an action given his action's key, his source and the real action.
+ * <p/>
+ * This is a convinient method when you need to modified action before fire it.
+ *
+ * @param actionKey action's key
+ * @param source source of action
+ * @param action real action
+ */
+ void fireAction0(String actionKey, Object source, A action);
+
+ /**
+ * @param actionKey the action's key
+ * @return the action in cache or <code>null</code> if action is not in cache
+ */
+ MyAbstractAction getActionFromCache(String actionKey);
+
+ /**
+ * dispose all actions in cache using {@link org.codelutin.jaxx.action.MyAbstractAction#disposeUI()} on each
+ * action, then {@link #resetCache()}
+ */
+ void dispose();
+}
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java (from rev 819, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java 2008-08-09 09:32:42 UTC (rev 820)
@@ -0,0 +1,410 @@
+/*
+* ##% 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 jaxx.runtime.JAXXObject;
+import jaxx.runtime.swing.JAXXToggleButton;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.codelutin.jaxx.action.initializer.AbstractActionConfigurationResolver;
+import org.codelutin.jaxx.action.initializer.ActionConfigConfigurationResolver;
+import org.codelutin.jaxx.action.initializer.ActionConfigurationResolver;
+import org.codelutin.jaxx.action.initializer.SelectActionConfigConfigurationResolver;
+import org.codelutin.jaxx.action.initializer.ToggleActionConfigConfigurationResolver;
+
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import java.awt.event.ActionEvent;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.ServiceLoader;
+import java.util.Set;
+import java.util.TreeMap;
+
+/**
+ * A simple implementation of {@link ActionFactory} using some {@link ActionProvider} to seek actions.
+ * <p/>
+ * <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.
+ * <p/>
+ * A special clase is to have for a given entry a key like this : <code>action.:fqn'=fqn</code>, in that case,
+ * le fqn' is a classe of type {@link org.codelutin.jaxx.action.ActionNameProvider} which gives us at
+ * runtime the names of each entry to put in cache for the givne action fqn.
+ *
+ * @author chemit
+ */
+public class ActionFactoryFromProvider<A extends MyAbstractAction> implements ActionFactory<A> {
+
+ protected static Log log = LogFactory.getLog(ActionFactoryFromProvider.class);
+
+ public static <A extends MyAbstractAction> ActionFactory<A> newInstance(Class<A> klazz) {
+ return new ActionFactoryFromProvider<A>(klazz);
+ }
+
+ /** class of encapsuling action */
+ protected Class<A> baseImpl;
+
+ /** dictionary of known actions implementations */
+ private Map<String, Class<? extends MyAbstractAction>> impls;
+
+ /** dictionary of instanciated actions */
+ private Map<String, A> cache;
+
+ protected final ActionConfigConfigurationResolver actionConfigInitializer;
+ protected final ToggleActionConfigConfigurationResolver toggleActionConfigInitializer;
+ protected final SelectActionConfigConfigurationResolver selectActionConfigInitializer;
+
+ protected List<AbstractActionConfigurationResolver> configurationResolvers;
+
+ protected ActionFactoryFromProvider(Class<A> baseImpl) {
+ this.baseImpl = baseImpl;
+ this.impls = init();
+ this.cache = new TreeMap<String, A>();
+ this.configurationResolvers = new java.util.ArrayList<AbstractActionConfigurationResolver>();
+
+ this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigConfigurationResolver.class);
+ this.actionConfigInitializer = registerInitializer(ActionConfigConfigurationResolver.class);
+ this.selectActionConfigInitializer = registerInitializer(SelectActionConfigConfigurationResolver.class);
+ }
+
+ public Class<A> getBaseImpl() {
+ return baseImpl;
+ }
+
+ public void resetCache() {
+ cache.clear();
+ }
+
+ public A get(String actionKey) {
+ return cache.get(actionKey);
+ }
+
+ public void loadActions(JAXXObject ui) {
+ if (log.isDebugEnabled()) {
+ log.debug("for ui " + ui.getClass());
+ }
+ 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;
+ A action = newAction(actionKey, component);
+
+ component.setAction(action);
+
+ if (component instanceof JAXXToggleButton) {
+ JAXXToggleButton glueComponent = (JAXXToggleButton) component;
+ glueComponent.setIcon((Icon) action.getValue(Action.SMALL_ICON));
+ Integer integer = (Integer) action.getValue(Action.MNEMONIC_KEY);
+ if (integer != null) {
+ glueComponent.setNormalMnemonic(integer);
+ }
+ glueComponent.setSelectedIcon((Icon) action.getValue(Action.SMALL_ICON + 2));
+ integer = (Integer) action.getValue(Action.MNEMONIC_KEY + 2);
+ if (integer != null) {
+ glueComponent.setGlueMnemonic(integer);
+ }
+ glueComponent.setGlueText((String) action.getValue(Action.NAME + 2));
+ glueComponent.setGlueTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION + 2));
+
+ glueComponent.setNormalText((String) action.getValue(Action.NAME));
+ glueComponent.setNormalTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION));
+ }
+
+ Boolean value = (Boolean) action.getValue("hideActionText");
+ component.setHideActionText(value != null && value);
+ action.setEnabled(true);
+ continue;
+ }
+ // is JComboBox
+ JComboBox component = (JComboBox) comp;
+ A 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);
+ }
+ }
+ }
+
+ /**
+ * @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.
+ */
+ public A newAction(String actionKey, JComponent component) {
+ // try first in cache
+ A result = getActionFromCache(actionKey);
+ if (result != null) {
+ return result;
+ }
+
+ try {
+ result = newActionInstance(actionKey);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("create <" + actionKey + " : " + result + ">");
+ }
+
+ // recherche de l'annotation de configuration
+ ActionConfigurationResolver<?, ?> configurationResolver = resolveActionConfiguration(result);
+
+ if (configurationResolver != null) {
+ configurationResolver.applyConfiguration(component, result);
+ }
+
+ try {
+
+ if (configurationResolver != null) {
+ if (AbstractButton.class.isAssignableFrom(configurationResolver.getComponentImpl())) {
+ finalizeNewAction((AbstractButton) component, result, configurationResolver);
+ }
+
+ if (JComboBox.class.isAssignableFrom(configurationResolver.getComponentImpl())) {
+ finalizeNewAction((JComboBox) component, result, configurationResolver);
+ }
+
+ return result;
+ }
+
+ if (component == null || component instanceof AbstractButton) {
+ finalizeNewAction((AbstractButton) component, result, configurationResolver);
+ return result;
+ }
+
+ if (component instanceof JComboBox) {
+ finalizeNewAction((JComboBox) component, result, configurationResolver);
+ }
+ } finally {
+ // save result in cache
+ cache.put(actionKey, result);
+ }
+
+ return result;
+ }
+
+ public A newAction(String actionKey) {
+ return newAction(actionKey, null);
+ }
+
+ public String[] getActionNames() {
+ return impls.keySet().toArray(new String[impls.size()]);
+ }
+
+ public Set<Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet() {
+ return impls.entrySet();
+ }
+
+ public Set<Entry<String, A>> cacheEntrySet() {
+ return cache.entrySet();
+ }
+
+ public void fireAction(String actionKey, Object source, JComponent component) {
+ A action = newAction(actionKey, component);
+ fireAction0(actionKey, source, action);
+ }
+
+ public void fireAction(String actionKey, Object source) {
+ fireAction(actionKey, source, null);
+ }
+
+ /**
+ * @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 A getActionFromCache(String actionKey) {
+ // on vérifie que l'action existe bien
+ checkRegistredAction(actionKey);
+
+ // try in cache
+ if (cache.containsKey(actionKey)) {
+ // use cached action
+ A action = cache.get(actionKey);
+ if (log.isDebugEnabled()) {
+ log.debug("use cache action " + action);
+ }
+ return action;
+ }
+ return null;
+ }
+
+ public void dispose() {
+ if (log.isInfoEnabled()) {
+ log.info(this);
+ }
+ for (String actionKey : getActionNames()) {
+ MyAbstractAction action = getActionFromCache(actionKey);
+ if (action != null) {
+ action.disposeUI();
+ }
+ }
+ resetCache();
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ resetCache();
+ impls.clear();
+ }
+
+ /**
+ * @param component le button où rattacher l'action
+ * @param action action
+ * @param configurationResolver initializer
+ */
+ protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) {
+
+ if (configurationResolver == null) {
+ // no configurationResolver 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());
+ }
+ }
+
+ }
+
+ 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()));
+ }
+ action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
+ }
+
+ }
+
+ /**
+ * @param component le select box où rattacher l'action
+ * @param action action
+ * @param configurationResolver initializer
+ */
+ protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) {
+
+ if (configurationResolver == null) {
+ action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
+ action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
+ //result.putValue("selectedIndex", component.getSelectedIndex());
+ }
+
+ }
+
+ protected ActionConfigurationResolver resolveActionConfiguration(MyAbstractAction action) {
+ for (ActionConfigurationResolver resolver : configurationResolvers) {
+ if (resolver.resolveConfiguration(action) != null) {
+ return resolver;
+ }
+ }
+ return null;
+ }
+
+ protected <I extends AbstractActionConfigurationResolver> I registerInitializer(Class<I> initizalizer) {
+ try {
+ I instance = initizalizer.newInstance();
+ configurationResolvers.add(instance);
+ return instance;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void fireAction0(String actionKey, Object source, A action) {
+ if (action == null) {
+ log.warn("could not find action " + actionKey);
+ return;
+ }
+ 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);
+ }
+ }
+
+
+ @SuppressWarnings({"unchecked"})
+ protected A 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);
+ if (!getBaseImpl().isAssignableFrom(klazz)) {
+ // the instanciated action must be boxed in the base Action of the factory
+ result = getBaseImpl().getConstructor(MyAbstractAction.class).newInstance(result);
+ }
+ return (A) result;
+ }
+
+
+ public 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 MyAbstractAction>> cache = new TreeMap<String, Class<? extends MyAbstractAction>>();
+
+ for (ActionProvider<?> actionProvider : loader) {
+ if (log.isDebugEnabled()) {
+ log.debug("found " + actionProvider);
+ }
+ cache.putAll(actionProvider.getClasses());
+ }
+ return cache;
+ }
+
+}
\ No newline at end of file
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-08-09 09:32:14 UTC (rev 819)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactory.java 2008-08-09 09:32:42 UTC (rev 820)
@@ -1,132 +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.factory;
-
-import jaxx.runtime.JAXXObject;
-import org.codelutin.jaxx.action.MyAbstractAction;
-
-import javax.swing.JComponent;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-/**
- * Action factory using the ActionConfig annotations to configure the action.
- * <p/>
- * Use after the {@link #loadActions(jaxx.runtime.JAXXObject)} to instanciate
- * actions in ui with id equals a known action...
- * <p/>
- * TODO Finish doc
- *
- * @author chemit
- */
-public interface ActionFactory<A extends MyAbstractAction> {
-
- /**
- * Method to init the dictionary of knwon action implementations.
- *
- * @return the dictionary of known action implementations
- */
- Map<String, Class<? extends MyAbstractAction>> init();
-
- /** @return the class of the base action of the factory. */
- Class<A> getBaseImpl();
-
- /** clear the cache of instanciated actions. */
- void resetCache();
-
- /**
- * @param actionKey the key of an action
- * @return the action with this key from cache, or <code>null</code> if this action is not in cache
- */
- A get(String actionKey);
-
- /**
- * For a given ui, load all actions registred in factory.
- * <p/>
- * The id of the widget in ui is directly mapped to a action key.
- *
- * @param ui the ui to treate
- */
- void loadActions(JAXXObject ui);
-
- /**
- * Obtain an action instance given his key and widget
- *
- * @param actionKey the key of action
- * @param component the component using the action
- * @return the instanciated action (could come from cache if already instanciated {@link #getActionFromCache(String)}
- */
- A newAction(String actionKey, JComponent component);
-
- /**
- * Obtain an action instance given his key (should call {@link #newAction(String, javax.swing.JComponent)}
- * <p/>
- * This is a convinient method when you want to obtain an action with no attached widget.
- *
- * @param actionKey the key of action
- * @return the instanciated action (could come from cache if already instanciated {@link #getActionFromCache(String)}
- */
- A newAction(String actionKey);
-
- /** @return the array of names of all actions known by the factory */
- String[] getActionNames();
-
- /** @return the set of all the action's classes known by the factory. */
- Set<Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet();
-
- /** @return the set of all actions cached in factory indexed by their name */
- Set<Entry<String, A>> cacheEntrySet();
-
- /**
- * Fire an action given his key, his source and tthe widget responsible of action
- *
- * @param actionKey the action's key
- * @param source the object source of action
- * @param component the component doing the action
- */
- void fireAction(String actionKey, Object source, JComponent component);
-
- /**
- * Fire an action given his key and his source, no widget are involved here
- *
- * @param actionKey the action's key
- * @param source the object source of action
- */
- void fireAction(String actionKey, Object source);
-
- /**
- * Fire an action given his action's key, his source and the real action.
- * <p/>
- * This is a convinient method when you need to modified action before fire it.
- *
- * @param actionKey action's key
- * @param source source of action
- * @param action real action
- */
- void fireAction0(String actionKey, Object source, A action);
-
- /**
- * @param actionKey the action's key
- * @return the action in cache or <code>null</code> if action is not in cache
- */
- MyAbstractAction getActionFromCache(String actionKey);
-
- /**
- * dispose all actions in cache using {@link org.codelutin.jaxx.action.MyAbstractAction#disposeUI()} on each
- * action, then {@link #resetCache()}
- */
- void dispose();
-}
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-08-09 09:32:14 UTC (rev 819)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-08-09 09:32:42 UTC (rev 820)
@@ -1,412 +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.factory;
-
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.swing.JAXXToggleButton;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.jaxx.action.ActionProvider;
-import org.codelutin.jaxx.action.MyAbstractAction;
-import org.codelutin.jaxx.action.initializer.AbstractActionConfigurationResolver;
-import org.codelutin.jaxx.action.initializer.ActionConfigConfigurationResolver;
-import org.codelutin.jaxx.action.initializer.ActionConfigurationResolver;
-import org.codelutin.jaxx.action.initializer.SelectActionConfigConfigurationResolver;
-import org.codelutin.jaxx.action.initializer.ToggleActionConfigConfigurationResolver;
-
-import javax.swing.AbstractButton;
-import javax.swing.Action;
-import javax.swing.Icon;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import java.awt.event.ActionEvent;
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.ServiceLoader;
-import java.util.Set;
-import java.util.TreeMap;
-
-/**
- * A simple implementation of {@link ActionFactory} using some {@link ActionProvider} to seek actions.
- * <p/>
- * <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.
- * <p/>
- * A special clase is to have for a given entry a key like this : <code>action.:fqn'=fqn</code>, in that case,
- * le fqn' is a classe of type {@link org.codelutin.jaxx.action.ActionNameProvider} which gives us at
- * runtime the names of each entry to put in cache for the givne action fqn.
- *
- * @author chemit
- */
-public class ActionFactoryFromProvider<A extends MyAbstractAction> implements ActionFactory<A> {
-
- protected static Log log = LogFactory.getLog(ActionFactoryFromProvider.class);
-
- public static <A extends MyAbstractAction> ActionFactory<A> newInstance(Class<A> klazz) {
- return new ActionFactoryFromProvider<A>(klazz);
- }
-
- /** class of encapsuling action */
- protected Class<A> baseImpl;
-
- /** dictionary of known actions implementations */
- private Map<String, Class<? extends MyAbstractAction>> impls;
-
- /** dictionary of instanciated actions */
- private Map<String, A> cache;
-
- protected final ActionConfigConfigurationResolver actionConfigInitializer;
- protected final ToggleActionConfigConfigurationResolver toggleActionConfigInitializer;
- protected final SelectActionConfigConfigurationResolver selectActionConfigInitializer;
-
- protected List<AbstractActionConfigurationResolver> configurationResolvers;
-
- protected ActionFactoryFromProvider(Class<A> baseImpl) {
- this.baseImpl = baseImpl;
- this.impls = init();
- this.cache = new TreeMap<String, A>();
- this.configurationResolvers = new java.util.ArrayList<AbstractActionConfigurationResolver>();
-
- this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigConfigurationResolver.class);
- this.actionConfigInitializer = registerInitializer(ActionConfigConfigurationResolver.class);
- this.selectActionConfigInitializer = registerInitializer(SelectActionConfigConfigurationResolver.class);
- }
-
- public Class<A> getBaseImpl() {
- return baseImpl;
- }
-
- public void resetCache() {
- cache.clear();
- }
-
- public A get(String actionKey) {
- return cache.get(actionKey);
- }
-
- public void loadActions(JAXXObject ui) {
- if (log.isDebugEnabled()) {
- log.debug("for ui " + ui.getClass());
- }
- 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;
- A action = newAction(actionKey, component);
-
- component.setAction(action);
-
- if (component instanceof JAXXToggleButton) {
- JAXXToggleButton glueComponent = (JAXXToggleButton) component;
- glueComponent.setIcon((Icon) action.getValue(Action.SMALL_ICON));
- Integer integer = (Integer) action.getValue(Action.MNEMONIC_KEY);
- if (integer != null) {
- glueComponent.setNormalMnemonic(integer);
- }
- glueComponent.setSelectedIcon((Icon) action.getValue(Action.SMALL_ICON + 2));
- integer = (Integer) action.getValue(Action.MNEMONIC_KEY + 2);
- if (integer != null) {
- glueComponent.setGlueMnemonic(integer);
- }
- glueComponent.setGlueText((String) action.getValue(Action.NAME + 2));
- glueComponent.setGlueTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION + 2));
-
- glueComponent.setNormalText((String) action.getValue(Action.NAME));
- glueComponent.setNormalTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION));
- }
-
- Boolean value = (Boolean) action.getValue("hideActionText");
- component.setHideActionText(value != null && value);
- action.setEnabled(true);
- continue;
- }
- // is JComboBox
- JComboBox component = (JComboBox) comp;
- A 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);
- }
- }
- }
-
- /**
- * @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.
- */
- public A newAction(String actionKey, JComponent component) {
- // try first in cache
- A result = getActionFromCache(actionKey);
- if (result != null) {
- return result;
- }
-
- try {
- result = newActionInstance(actionKey);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- if (log.isDebugEnabled()) {
- log.debug("create <" + actionKey + " : " + result + ">");
- }
-
- // recherche de l'annotation de configuration
- ActionConfigurationResolver<?, ?> configurationResolver = resolveActionConfiguration(result);
-
- if (configurationResolver != null) {
- configurationResolver.applyConfiguration(component, result);
- }
-
- try {
-
- if (configurationResolver != null) {
- if (AbstractButton.class.isAssignableFrom(configurationResolver.getComponentImpl())) {
- finalizeNewAction((AbstractButton) component, result, configurationResolver);
- }
-
- if (JComboBox.class.isAssignableFrom(configurationResolver.getComponentImpl())) {
- finalizeNewAction((JComboBox) component, result, configurationResolver);
- }
-
- return result;
- }
-
- if (component == null || component instanceof AbstractButton) {
- finalizeNewAction((AbstractButton) component, result, configurationResolver);
- return result;
- }
-
- if (component instanceof JComboBox) {
- finalizeNewAction((JComboBox) component, result, configurationResolver);
- }
- } finally {
- // save result in cache
- cache.put(actionKey, result);
- }
-
- return result;
- }
-
- public A newAction(String actionKey) {
- return newAction(actionKey, null);
- }
-
- public String[] getActionNames() {
- return impls.keySet().toArray(new String[impls.size()]);
- }
-
- public Set<Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet() {
- return impls.entrySet();
- }
-
- public Set<Entry<String, A>> cacheEntrySet() {
- return cache.entrySet();
- }
-
- public void fireAction(String actionKey, Object source, JComponent component) {
- A action = newAction(actionKey, component);
- fireAction0(actionKey, source, action);
- }
-
- public void fireAction(String actionKey, Object source) {
- fireAction(actionKey, source, null);
- }
-
- /**
- * @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 A getActionFromCache(String actionKey) {
- // on vérifie que l'action existe bien
- checkRegistredAction(actionKey);
-
- // try in cache
- if (cache.containsKey(actionKey)) {
- // use cached action
- A action = cache.get(actionKey);
- if (log.isDebugEnabled()) {
- log.debug("use cache action " + action);
- }
- return action;
- }
- return null;
- }
-
- public void dispose() {
- if (log.isInfoEnabled()) {
- log.info(this);
- }
- for (String actionKey : getActionNames()) {
- MyAbstractAction action = getActionFromCache(actionKey);
- if (action != null) {
- action.disposeUI();
- }
- }
- resetCache();
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- resetCache();
- impls.clear();
- }
-
- /**
- * @param component le button où rattacher l'action
- * @param action action
- * @param configurationResolver initializer
- */
- protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) {
-
- if (configurationResolver == null) {
- // no configurationResolver 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());
- }
- }
-
- }
-
- 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()));
- }
- action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
- }
-
- }
-
- /**
- * @param component le select box où rattacher l'action
- * @param action action
- * @param configurationResolver initializer
- */
- protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) {
-
- if (configurationResolver == null) {
- action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
- action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
- //result.putValue("selectedIndex", component.getSelectedIndex());
- }
-
- }
-
- protected ActionConfigurationResolver resolveActionConfiguration(MyAbstractAction action) {
- for (ActionConfigurationResolver resolver : configurationResolvers) {
- if (resolver.resolveConfiguration(action) != null) {
- return resolver;
- }
- }
- return null;
- }
-
- protected <I extends AbstractActionConfigurationResolver> I registerInitializer(Class<I> initizalizer) {
- try {
- I instance = initizalizer.newInstance();
- configurationResolvers.add(instance);
- return instance;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public void fireAction0(String actionKey, Object source, A action) {
- if (action == null) {
- log.warn("could not find action " + actionKey);
- return;
- }
- 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);
- }
- }
-
-
- @SuppressWarnings({"unchecked"})
- protected A 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);
- if (!getBaseImpl().isAssignableFrom(klazz)) {
- // the instanciated action must be boxed in the base Action of the factory
- result = getBaseImpl().getConstructor(MyAbstractAction.class).newInstance(result);
- }
- return (A) result;
- }
-
-
- public 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 MyAbstractAction>> cache = new TreeMap<String, Class<? extends MyAbstractAction>>();
-
- for (ActionProvider<?> actionProvider : loader) {
- if (log.isDebugEnabled()) {
- log.debug("found " + actionProvider);
- }
- cache.putAll(actionProvider.getClasses());
- }
- return cache;
- }
-
-}
\ No newline at end of file
1
0
r819 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . factory
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
09 Aug '08
Author: tchemit
Date: 2008-08-09 09:32:14 +0000 (Sat, 09 Aug 2008)
New Revision: 819
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
Log:
simplification du code : suppression du paquetage provider
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-09 09:31:56 UTC (rev 818)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-09 09:32:14 UTC (rev 819)
@@ -22,8 +22,6 @@
import javassist.CtConstructor;
import javassist.LoaderClassPath;
import javassist.NotFoundException;
-import org.codelutin.jaxx.action.provider.ActionProvider;
-import org.codelutin.jaxx.action.provider.ActionProviderFromProperties;
import org.codelutin.util.SortedProperties;
import javax.annotation.processing.AbstractProcessor;
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-08-09 09:31:56 UTC (rev 818)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-08-09 09:32:14 UTC (rev 819)
@@ -21,13 +21,13 @@
import jaxx.runtime.swing.JAXXToggleButton;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.codelutin.jaxx.action.ActionProvider;
import org.codelutin.jaxx.action.MyAbstractAction;
import org.codelutin.jaxx.action.initializer.AbstractActionConfigurationResolver;
import org.codelutin.jaxx.action.initializer.ActionConfigConfigurationResolver;
import org.codelutin.jaxx.action.initializer.ActionConfigurationResolver;
import org.codelutin.jaxx.action.initializer.SelectActionConfigConfigurationResolver;
import org.codelutin.jaxx.action.initializer.ToggleActionConfigConfigurationResolver;
-import org.codelutin.jaxx.action.provider.ActionProvider;
import javax.swing.AbstractButton;
import javax.swing.Action;
1
0
r818 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . provider
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
by tchemit@users.labs.libre-entreprise.org 09 Aug '08
09 Aug '08
Author: tchemit
Date: 2008-08-09 09:31:56 +0000 (Sat, 09 Aug 2008)
New Revision: 818
Added:
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
Removed:
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
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameProvider.java
Log:
simplification du code : suppression du paquetage provider
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameProvider.java 2008-08-06 10:53:44 UTC (rev 817)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameProvider.java 2008-08-09 09:31:56 UTC (rev 818)
@@ -16,6 +16,13 @@
/**
* Contrat pour obtenir les noms d'une action de manière dynamique.
+ * <p/>
+ * Cette méthode sera appelé par un {@link ActionProvider} lorsque la clef dans le
+ * fichier de mapping est :fqn (où fqn correspond à une implantation de ce contrat).
+ * <p/>
+ * Ainsi on peut associer à une action donnée plusieurs instances avec des noms différents mais avec le même comportement.
+ * <p/>
+ * Par exemple, une changement de locale où seule la locale varie (et elle sera retrouvée à partir du nom de l'action).
*
* @author chemit
*/
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java (from rev 796, 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/ActionProvider.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProvider.java 2008-08-09 09:31:56 UTC (rev 818)
@@ -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;
+
+/**
+ * Contract to be realized by a provider of Actions.
+ * <p/>
+ * 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/ActionProviderFromProperties.java (from rev 817, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionProviderFromProperties.java 2008-08-09 09:31:56 UTC (rev 818)
@@ -0,0 +1,142 @@
+/**
+ * # #% 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 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> implements ActionProvider<A> {
+
+ /** default prefix for an entryin mapping file. */
+ protected static final String ACTION_KEY_PREFIX = "action.";
+
+ protected String propertiesPath;
+
+ protected static Log log = LogFactory.getLog(ActionProviderFromProperties.class);
+
+ protected String name;
+
+ protected Class<A> baseClass;
+
+ protected Map<String, Class<? extends A>> actions;
+
+
+ protected ActionProviderFromProperties(String name, Class<A> baseClass, String propertiesPath) {
+
+ this.name = name;
+ this.baseClass = baseClass;
+
+ this.propertiesPath = propertiesPath;
+ 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();
+ }
+
+ @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);
+ if (actionKey.startsWith(":")) {
+ // this is a RuntimeActionNameProvider
+ Class<ActionNameProvider> klazz = (Class<ActionNameProvider>) Class.forName(actionKey.substring(1));
+ for (String s : klazz.newInstance().getActionCommands()) {
+ log.debug("found action <" + s + " : " + implCass + ">");
+ cache.put(s, implCass);
+ }
+ continue;
+ }
+ log.debug("found action <" + actionKey + " : " + implCass + ">");
+ cache.put(actionKey, implCass);
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
+ } catch (InstantiationException e) {
+ throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
+ }
+ }
+
+ return cache;
+ }
+}
Deleted: 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/ActionProvider.java 2008-08-06 10:53:44 UTC (rev 817)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProvider.java 2008-08-09 09:31:56 UTC (rev 818)
@@ -1,37 +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.provider;
-
-import org.codelutin.jaxx.action.MyAbstractAction;
-
-/**
- * Contract to be realized by a provider of Actions.
- * <p/>
- * 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/provider/ActionProviderFromProperties.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-08-06 10:53:44 UTC (rev 817)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-08-09 09:31:56 UTC (rev 818)
@@ -1,144 +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.provider;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import static org.codelutin.i18n.I18n._;
-import org.codelutin.jaxx.action.ActionNameProvider;
-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> implements ActionProvider<A> {
-
- /** default prefix for an entryin mapping file. */
- protected static final String ACTION_KEY_PREFIX = "action.";
-
- protected String propertiesPath;
-
- protected static Log log = LogFactory.getLog(ActionProviderFromProperties.class);
-
- protected String name;
-
- protected Class<A> baseClass;
-
- protected Map<String, Class<? extends A>> actions;
-
-
- protected ActionProviderFromProperties(String name, Class<A> baseClass, String propertiesPath) {
-
- this.name = name;
- this.baseClass = baseClass;
-
- this.propertiesPath = propertiesPath;
- 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();
- }
-
- @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);
- if (actionKey.startsWith(":")) {
- // this is a RuntimeActionNameProvider
- Class<ActionNameProvider> klazz = (Class<ActionNameProvider>) Class.forName(actionKey.substring(1));
- for (String s : klazz.newInstance().getActionCommands()) {
- log.debug("found action <" + s + " : " + implCass + ">");
- cache.put(s, implCass);
- }
- continue;
- }
- log.debug("found action <" + actionKey + " : " + implCass + ">");
- cache.put(actionKey, implCass);
- } catch (ClassNotFoundException e) {
- throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
- } catch (InstantiationException e) {
- throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
- }
- }
-
- return cache;
- }
-}
1
0
r817 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . factory provider
by tchemit@users.labs.libre-entreprise.org 06 Aug '08
by tchemit@users.labs.libre-entreprise.org 06 Aug '08
06 Aug '08
Author: tchemit
Date: 2008-08-06 10:53:44 +0000 (Wed, 06 Aug 2008)
New Revision: 817
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameProvider.java
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameHelper.java
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java
Log:
simplification du code : on conserve uniquement l'interface ActionNameProvider et plus la classe ActionNameHelper et les diff?\195?\169rentes sortes ActionNameProvider car de toute facon il est tr?\195?\168s difficile au niveau de l'AnnotationProcessing d'utiliser une classe en scope compile car celle-ci n'est peut-?\195?\170tre pas compil?\195?\169, ce qui est assez probl?\195?\169matique (il faudrai g?\195?\169rer les rounds de compilation, ce que je ne veux pas faire...)
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-06 10:16:03 UTC (rev 816)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-06 10:53:44 UTC (rev 817)
@@ -306,7 +306,7 @@
TypeMirror t = (TypeMirror) entry.getValue().accept(getAnnotationValueExtractor(), null);
String classname = t.toString();
printDebug("actionCommandProvider = " + classname);
- if (classname.endsWith(ActionNameHelper.ActionNameProvider.class.getName())) {
+ if (classname.equals(ActionNameProvider.class.getName())) {
continue;
}
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java 2008-08-06 10:16:03 UTC (rev 816)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java 2008-08-06 10:53:44 UTC (rev 817)
@@ -48,7 +48,13 @@
/** @return array of names to be used in actions mapping */
String[] actionCommands() default {};
- Class<? extends ActionNameHelper.ActionNameProvider> actionCommandProvider() default ActionNameHelper.ActionNameProvider.class;
+ /**
+ * @return the class to obtain at runtime the array of names to be used in actions mapping.
+ * <p/>
+ * <b>Note : the special value {@link org.codelutin.jaxx.action.ActionNameProvider} is used to says not to used
+ * œthis mecanism since we can not set a null value in a annotation</b>
+ */
+ Class<? extends ActionNameProvider> actionCommandProvider() default org.codelutin.jaxx.action.ActionNameProvider.class;
/**
* @return la clef i18n du texte de l'action, si vide ignoré
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameHelper.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameHelper.java 2008-08-06 10:16:03 UTC (rev 816)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameHelper.java 2008-08-06 10:53:44 UTC (rev 817)
@@ -1,43 +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;
-
-/** @author chemit */
-public class ActionNameHelper {
-
- /**
- * Contrat pour obtenir les noms d'une action.
- *
- * @author chemit
- */
- public static interface ActionNameProvider {
-
- /** @return la liste des noms à utiliser par la classe d'action. */
- String[] getActionCommands();
-
- }
-
- /** Contrat pour obtenir les noms d'actions au moment de la compilation. */
- public static interface CompileActionNameProvider extends ActionNameProvider {
-
- }
-
- /** Contrat pour obtenir les noms d'actions au moment du runtime. */
- public static interface RuntimeActionNameProvider extends ActionNameProvider {
-
- }
-
-
-}
Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameProvider.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameProvider.java 2008-08-06 10:53:44 UTC (rev 817)
@@ -0,0 +1,27 @@
+/**
+ * # #% 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;
+
+/**
+ * Contrat pour obtenir les noms d'une action de manière dynamique.
+ *
+ * @author chemit
+ */
+public interface ActionNameProvider {
+
+ /** @return la liste des noms à utiliser par la classe d'action. */
+ String[] getActionCommands();
+
+}
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java 2008-08-06 10:16:03 UTC (rev 816)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java 2008-08-06 10:53:44 UTC (rev 817)
@@ -48,7 +48,13 @@
/** @return array of names to be used in actions mapping */
String[] actionCommands() default {};
- Class<? extends ActionNameHelper.ActionNameProvider> actionCommandProvider() default ActionNameHelper.ActionNameProvider.class;
+ /**
+ * @return the class to obtain at runtime the array of names to be used in actions mapping.
+ * <p/>
+ * <b>Note : the special value {@link org.codelutin.jaxx.action.ActionNameProvider} is used to says not to used
+ * œthis mecanism since we can not set a null value in a annotation</b>
+ */
+ Class<? extends ActionNameProvider> actionCommandProvider() default org.codelutin.jaxx.action.ActionNameProvider.class;
/**
* @return la clef i18n du texte de l'action, si vide ignoré
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java 2008-08-06 10:16:03 UTC (rev 816)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java 2008-08-06 10:53:44 UTC (rev 817)
@@ -46,7 +46,13 @@
/** @return array of names to be used in actions mapping */
String[] actionCommands() default {};
- Class<? extends ActionNameHelper.ActionNameProvider> actionCommandProvider() default ActionNameHelper.ActionNameProvider.class;
+ /**
+ * @return the class to obtain at runtime the array of names to be used in actions mapping.
+ * <p/>
+ * <b>Note : the special value {@link org.codelutin.jaxx.action.ActionNameProvider} is used to says not to used
+ * œthis mecanism since we can not set a null value in a annotation</b>
+ */
+ Class<? extends ActionNameProvider> actionCommandProvider() default org.codelutin.jaxx.action.ActionNameProvider.class;
/**
* @return la clef i18n du texte de l'action, si vide ignoré
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-08-06 10:16:03 UTC (rev 816)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-08-06 10:53:44 UTC (rev 817)
@@ -44,14 +44,17 @@
import java.util.TreeMap;
/**
- * TODO Do javadoc which is not up to date...
- * A simple implementation of {@link ActionFactory} using a properties file to
- * load action mapping.
+ * A simple implementation of {@link ActionFactory} using some {@link ActionProvider} to seek actions.
* <p/>
+ * <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.
+ * <p/>
+ * A special clase is to have for a given entry a key like this : <code>action.:fqn'=fqn</code>, in that case,
+ * le fqn' is a classe of type {@link org.codelutin.jaxx.action.ActionNameProvider} which gives us at
+ * runtime the names of each entry to put in cache for the givne action fqn.
*
* @author chemit
*/
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-08-06 10:16:03 UTC (rev 816)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-08-06 10:53:44 UTC (rev 817)
@@ -17,7 +17,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import static org.codelutin.i18n.I18n._;
-import org.codelutin.jaxx.action.ActionNameHelper.RuntimeActionNameProvider;
+import org.codelutin.jaxx.action.ActionNameProvider;
import org.codelutin.jaxx.action.MyAbstractAction;
import java.io.IOException;
@@ -121,7 +121,7 @@
String actionKey = key.substring(prefix);
if (actionKey.startsWith(":")) {
// this is a RuntimeActionNameProvider
- Class<RuntimeActionNameProvider> klazz = (Class<RuntimeActionNameProvider>) Class.forName(actionKey.substring(1));
+ Class<ActionNameProvider> klazz = (Class<ActionNameProvider>) Class.forName(actionKey.substring(1));
for (String s : klazz.newInstance().getActionCommands()) {
log.debug("found action <" + s + " : " + implCass + ">");
cache.put(s, implCass);
1
0
r816 - trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx
by tchemit@users.labs.libre-entreprise.org 06 Aug '08
by tchemit@users.labs.libre-entreprise.org 06 Aug '08
06 Aug '08
Author: tchemit
Date: 2008-08-06 10:16:03 +0000 (Wed, 06 Aug 2008)
New Revision: 816
Removed:
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/ActionProviderGeneratorMojo.java
Modified:
trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
Log:
simplification du code : on supprime la classe abstraite car pour le moment y'a qu'une seule implantation :)
Deleted: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractActionGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractActionGeneratorMojo.java 2008-08-06 10:15:00 UTC (rev 815)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractActionGeneratorMojo.java 2008-08-06 10:16:03 UTC (rev 816)
@@ -1,55 +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;
-
-import org.codelutin.util.FileUtil;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * @author chemit
- * @deprecated Now we use the {@link org.codelutin.jaxx.action.ActionAnnotationProcessing}
- */
-public abstract class AbstractActionGeneratorMojo extends AbstractJaxxMojo {
-
- /**
- * @description Nom du fichier d'actions à générer.
- * @parameter expression="${jaxx.actionsFile}"
- * @required
- */
- protected String actionsFile;
-
- /**
- * @description flag to copy generated resource files to outClass
- * @parameter expression="${jaxx.copyToCP}" default-value="false"
- */
- protected boolean copyToCP;
-
- protected void copyResourceToCP(File file) throws IOException {
-
- String path = file.getAbsolutePath().substring(outResource.getAbsolutePath().length() + 1);
- File compiledFile = new File(outClass, path);
- if (verbose) {
- getLog().info("copy to classapth generated file " + compiledFile);
- }
- File parent = compiledFile.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
- FileUtil.copy(file, compiledFile);
- }
-
-}
Deleted: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java 2008-08-06 10:15:00 UTC (rev 815)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/AbstractJaxxMojo.java 2008-08-06 10:16:03 UTC (rev 816)
@@ -1,183 +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;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugin.logging.Log;
-import org.apache.maven.project.MavenProject;
-import static org.codelutin.i18n.I18n._;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Set;
-
-/**
- * Le mojo de base pour les goals Jaxx.
- *
- * @author chemit
- */
-public abstract class AbstractJaxxMojo extends AbstractMojo {
-
- /**
- * @description Dépendance du projet.
- * @parameter default-value="${project}"
- * @readonly
- */
- protected MavenProject project;
-
- /**
- * @description Répertoire de destination des fichiers java à générer.
- * @parameter expression="${jaxx.outJava}" default-value="${basedir}/target/generated-sources/java"
- */
- protected File outJava;
-
- /**
- * @description chemin du répertoire de génération des resources.
- * @parameter expression="${jaxx.outResource}" default-value="${basedir}/target/generated-sources/resources"
- */
- protected File outResource;
-
- /**
- * @description chemin du répertoire de compilation des resources.
- * @parameter expression="${jaxx.outClass}" default-value="${basedir}/target/classes"
- */
- protected File outClass;
-
- /**
- * @description verbose
- * @parameter expression="${jaxx.verbose}" default-value="false"
- */
- protected boolean verbose;
-
-
- protected abstract void doExecute() throws Exception;
-
- public void execute() throws MojoExecutionException, MojoFailureException {
-
- init();
-
- try {
-
- doExecute();
-
- } catch (Exception e) {
- getLog().error(e);
- Throwable e2 = e;
- while (e2.getCause() != null) {
- e2 = e.getCause();
- }
- getLog().error(e2);
-
- throw new MojoExecutionException(e.getMessage(), e);
- }
-
- }
-
- protected void init() {
-
- if (!outResource.exists()) {
- outResource.mkdirs();
- }
-
- if (!outJava.exists()) {
- outJava.mkdirs();
- }
-
- }
-
- protected void fixCompileSourceRoots() {
- if (!project.getCompileSourceRoots().contains(outJava.getPath())) {
- project.addCompileSourceRoot(outJava.getPath());
- }
- }
-
- @SuppressWarnings({"unchecked"})
- protected URLClassLoader initClassLoader(MavenProject project, Log log) {
- URLClassLoader loader = null;
- if (project != null) {
- URLClassLoader result;
- try {
- Set<Artifact> compileClasspathElements = project.getArtifacts();
- URL[] url = new URL[compileClasspathElements.size() + 1];
- url[0] = outClass.toURI().toURL();
- int i = 1;
- for (Artifact artifact : compileClasspathElements) {
- File file = new File(artifact.getFile().getAbsolutePath());
- if (file.getName().endsWith(".jar")) {
- url[i] = new URL("jar", "", file.toURI().toURL().toString() + "!/");
- } else {
- url[i] = file.toURI().toURL();
- }
- i++;
- }
- //ClassLoader parent = Thread.currentThread().getContextClassLoader();
- if (compileClasspathElements.size() == 0) {
- result = new URLClassLoader(url, getClass().getClassLoader());
- } else {
- result = new URLClassLoader(url, getClass().getClassLoader());
- }
- } catch (MalformedURLException eee) {
- throw new RuntimeException(_("Can't create ClassLoader for script, bad directory: {0} for reason {1}", outClass, eee.getMessage()), eee);
- } catch (IOException e) {
- throw new RuntimeException(_("Can't create ClassLoader for script, bad directory: {0} for reason {1}", outClass, e.getMessage()), e);
- }
- loader = result;
- }
- if (verbose && loader != null) {
- for (URL entry : loader.getURLs()) {
- log.info("outClass url " + entry);
- }
- }
- return loader;
- }
-
- public File getOutJava() {
- return outJava;
- }
-
- public void setOutJava(File outJava) {
- this.outJava = outJava;
- }
-
- public File getOutResource() {
- return outResource;
- }
-
- public void setOutResource(File outResource) {
- this.outResource = outResource;
- }
-
- public File getOutClass() {
- return outClass;
- }
-
- public void setOutClass(File outClass) {
- this.outClass = outClass;
- }
-
- public boolean isVerbose() {
- return verbose;
- }
-
- public void setVerbose(boolean verbose) {
- this.verbose = verbose;
- }
-}
\ No newline at end of file
Deleted: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java 2008-08-06 10:15:00 UTC (rev 815)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionGeneratorMojo.java 2008-08-06 10:16:03 UTC (rev 816)
@@ -1,259 +0,0 @@
-/* *##%
- * Copyright (C) 2007
- * JaxxPlugin, Code Lutin
- *
- * 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;
-
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codelutin.jaxx.action.ActionConfig;
-import org.codelutin.jaxx.action.SelectActionConfig;
-import org.codelutin.jaxx.action.ToggleActionConfig;
-import org.codelutin.util.SortedProperties;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.Properties;
-
-/**
- * Classe permettant de generer le fichier de propriétés des actions détectées.
- *
- * @author chemit
- * @goal generate-actions-properties
- * @phase process-classes
- * @deprecated Now we use the {@link org.codelutin.jaxx.action.ActionAnnotationProcessing}
- */
-public class ActionGeneratorMojo extends AbstractActionGeneratorMojo {
-
- /**
- * @description Répertoire sources des fichiers java à traiter.
- * @parameter expression="${jaxx.src}" default-value="${basedir}/src/main/java"
- */
- protected File src;
-
- /**
- * @description pour filter
- * @parameter expression="${jaxx.includes}"
- */
- protected String[] includes;
-
- /**
- * @description pour filter
- * @parameter expression="${jaxx.excludes}"
- */
- protected String[] excludes;
-
- protected String[] files;
-
- protected URLClassLoader loader;
-
- private static final String[] INCLUDES = {"**\\/*.java"};
-
-
- protected void doExecute() throws Exception {
-
- if (verbose) {
- printInit();
- }
-
- Properties result = loadProperties();
-
-
- saveProperties(result);
-
- }
-
- protected Properties loadProperties() throws ClassNotFoundException {
- Properties result = new SortedProperties();
- for (String file : files) {
- String fqn = file.substring(0, file.length() - 5).replaceAll("\\/", ".");
-
- if (verbose) {
- getLog().info("fqn to treate " + fqn);
- }
-
- Class<?> clazz = Class.forName(fqn, false, loader);
-
- // try a ActionConfig
- ActionConfig actionConfig = clazz.getAnnotation(ActionConfig.class);
- if (actionConfig != null) {
-
- if (actionConfig.multiNames().length > 0) {
- // multinames
- registerEntry(clazz, result, actionConfig.multiNames());
- continue;
- }
-
- if (!actionConfig.actionCommand().isEmpty()) {
- registerEntry(clazz, result, actionConfig.actionCommand());
- continue;
- }
-
- getLog().warn("could not treate class " + clazz);
- continue;
- }
-
- // try a SelectActionConfig
- SelectActionConfig selectActionConfig = clazz.getAnnotation(SelectActionConfig.class);
- if (selectActionConfig != null) {
- if (selectActionConfig.multiNames().length > 0) {
- // multinames
- registerEntry(clazz, result, selectActionConfig.multiNames());
- continue;
- }
-
- if (!selectActionConfig.actionCommand().isEmpty()) {
- registerEntry(clazz, result, selectActionConfig.actionCommand());
- continue;
- }
- getLog().warn("could not treate class " + clazz);
- continue;
- }
-
- // try a toggleAction
- ToggleActionConfig toggleActionConfig = clazz.getAnnotation(ToggleActionConfig.class);
- if (toggleActionConfig != null) {
- if (toggleActionConfig.multiNames().length > 0) {
- // multinames
- registerEntry(clazz, result, toggleActionConfig.multiNames());
- continue;
- }
-
- if (!toggleActionConfig.actionCommand().isEmpty()) {
- registerEntry(clazz, result, toggleActionConfig.actionCommand());
- continue;
- }
-
- getLog().warn("could not treate class " + clazz);
- }
-
- }
- return result;
- }
-
- protected void saveProperties(Properties result) throws IOException {
- OutputStream writer = null;
- File generatedFile = new File(outResource, actionsFile);
- File parent = generatedFile.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
- try {
- writer = new org.codelutin.util.PropertiesDateRemoveFilterStream(new java.io.FileOutputStream(generatedFile));
-
- result.store(writer, null);
-
-
- } finally {
- if (writer != null) {
- writer.flush();
- writer.close();
- }
- }
-
- if (copyToCP) {
- // save it also in classes
- copyResourceToCP(generatedFile);
- }
- }
-
-
- @Override
- protected void init() {
-
- super.init();
-
- DirectoryScanner ds;
- ds = new DirectoryScanner();
- ds.setBasedir(src);
- boolean noIncludes = includes == null || includes.length == 0;
- ds.setIncludes(noIncludes ? INCLUDES : includes);
- boolean noExcludes = excludes == null || excludes.length == 0;
- if (!noExcludes) {
- ds.setExcludes(excludes);
- }
- ds.scan();
- files = ds.getIncludedFiles();
-
- getLog().info("jaxx-actions - found " + files.length + " file(s) to treate. ");
-
- loader = initClassLoader(project, getLog());
- }
-
- protected void registerEntry(Class<?> clazz, Properties result, String... names) {
- for (String name : names) {
- if (verbose) {
- getLog().info("name: " + name + ", class:" + clazz);
- }
- result.put("action." + name, clazz.getName());
- }
- }
-
- protected void printInit() {
-
- for (String file : files) {
- getLog().info(file);
- }
-
- printCP();
- }
-
- protected void printCP() {
-
- getLog().info(loader.toString());
-
- for (URL url : loader.getURLs()) {
- getLog().info("url in class loader " + url);
- }
- }
-
- public File getSrc() {
- return src;
- }
-
- public void setSrc(File src) {
- this.src = src;
- }
-
- public String[] getIncludes() {
- return includes;
- }
-
- public void setIncludes(String[] includes) {
- this.includes = includes;
- }
-
- public String[] getExcludes() {
- return excludes;
- }
-
- public void setExcludes(String[] excludes) {
- this.excludes = excludes;
- }
-
- public String[] getFiles() {
- return files;
- }
-
- public void setFiles(String[] files) {
- this.files = files;
- }
-
-}
\ No newline at end of file
Deleted: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java 2008-08-06 10:15:00 UTC (rev 815)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/ActionProviderGeneratorMojo.java 2008-08-06 10:16:03 UTC (rev 816)
@@ -1,145 +0,0 @@
-/* *##%
- * Copyright (C) 2007
- * JaxxPlugin, Code Lutin
- *
- * 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;
-
-import org.codelutin.jaxx.action.provider.ActionProvider;
-import org.codelutin.jaxx.action.provider.ActionProviderFromProperties;
-import org.codelutin.util.FileUtil;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * Classe permettant de generer un {@link org.codelutin.jaxx.action.provider.ActionProvider} et son fichier de déclaration.
- *
- * @author chemit
- * @goal generate-actions-provider
- * @phase process-resources
- * @deprecated Now we use the {@link org.codelutin.jaxx.action.ActionAnnotationProcessing}
- */
-public class ActionProviderGeneratorMojo extends AbstractActionGeneratorMojo {
-
- /**
- * @description FQN de la classe à générer.
- * @parameter expression="${jaxx.fqn}"
- * @required
- */
- protected String fqn;
-
- /**
- * @description nom logique du provider à générer.
- * @parameter expression="${jaxx.providerName}"
- * @required
- */
- protected String providerName;
-
- /**
- * @description FQN de la classe d'action à utiliser.
- * @parameter expression="${jaxx.fqnAction}"
- * @required
- */
- protected String fqnAction;
-
- /**
- * template of ActionProvider
- * $1 : package of class
- * $2 : simple name of class
- * $3 : abstract action fqn
- * $4 : path to actions properties file
- * $5 : provider name
- */
- protected static final String PROVIDER_TEMPLATE =
- "package %1$s;\n" +
- "\n" +
- "public class %2$s extends " + ActionProviderFromProperties.class.getName() + "<%3$s> {\n" +
- "\n" +
- " public %2$s() {\n" +
- " super(\"%5$s\", %3$s.class, \"%4$s\");\n" +
- " }\n" +
- "\n" +
- "}\n";
-
- protected File generateJavaProvider;
-
- protected File generatedProviderDeclaration;
-
-
- protected void doExecute() throws Exception {
-
- generateProvider();
-
- generateProviderDeclaration();
-
- }
-
- protected void generateProvider() throws IOException {
-
- int index = fqn.lastIndexOf(".");
- String packageJava = fqn.substring(0, index);
- String simpleJavaName = fqn.substring(index + 1);
-
- //TODO check if file was modified
- String content = String.format(PROVIDER_TEMPLATE,
- packageJava,
- simpleJavaName,
- fqnAction,
- actionsFile,
- providerName
- );
-
- FileUtil.writeString(generateJavaProvider, content);
- }
-
- protected void generateProviderDeclaration() throws IOException {
-
- //TODO check if file was modified
-
- // just add the fqn inside the file :)
- FileUtil.writeString(generatedProviderDeclaration, fqn);
-
- if (copyToCP) {
- // save it also in classes (since we are in process-resources phase and resources has already been copied)
- copyResourceToCP(generatedProviderDeclaration);
- }
- }
-
- @Override
- protected void init() {
-
- super.init();
-
- generateJavaProvider = new File(outJava, fqn.replaceAll("\\.", java.io.File.separator) + ".java");
-
- File parent = generateJavaProvider.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
-
- generatedProviderDeclaration = new File(outResource, "META-INF/services/" + ActionProvider.class.getName());
- parent = generatedProviderDeclaration.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
-
- fixCompileSourceRoots();
-
- }
-
-}
\ No newline at end of file
Modified: trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java
===================================================================
--- trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-08-06 10:15:00 UTC (rev 815)
+++ trunk/lutinjaxx/maven/src/main/java/org/codelutin/jaxx/JaxxGeneratorMojo.java 2008-08-06 10:16:03 UTC (rev 816)
@@ -22,11 +22,20 @@
import jaxx.compiler.CompilerOptions;
import jaxx.compiler.JAXXCompiler;
import jaxx.tags.TagManager;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.DirectoryScanner;
import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Set;
/**
* Classe permettant de transformer des sources jaxx vers du source java.
@@ -35,9 +44,40 @@
* @goal generate
* @phase process-resources
*/
-public class JaxxGeneratorMojo extends AbstractJaxxMojo {
+public class JaxxGeneratorMojo extends AbstractMojo {
/**
+ * @description Dépendance du projet.
+ * @parameter default-value="${project}"
+ * @readonly
+ */
+ protected MavenProject project;
+
+ /**
+ * @description Répertoire de destination des fichiers java à générer.
+ * @parameter expression="${jaxx.outJava}" default-value="${basedir}/target/generated-sources/java"
+ */
+ protected File outJava;
+
+ /**
+ * @description chemin du répertoire de génération des resources.
+ * @parameter expression="${jaxx.outResource}" default-value="${basedir}/target/generated-sources/resources"
+ */
+ protected File outResource;
+
+ /**
+ * @description chemin du répertoire de compilation des resources.
+ * @parameter expression="${jaxx.outClass}" default-value="${basedir}/target/classes"
+ */
+ protected File outClass;
+
+ /**
+ * @description verbose
+ * @parameter expression="${jaxx.verbose}" default-value="false"
+ */
+ protected boolean verbose;
+
+ /**
* @description Répertoire sources des fichiers jaxx à générer.
* @parameter expression="${jaxx.src}" default-value="${maven.src.dir}/main/uimodel"
*/
@@ -68,8 +108,15 @@
protected CompilerOptions options;
protected void init() {
- super.init();
+ if (!outResource.exists()) {
+ outResource.mkdirs();
+ }
+
+ if (!outJava.exists()) {
+ outJava.mkdirs();
+ }
+
fixCompileSourceRoots();
DirectoryScanner ds;
@@ -143,6 +190,105 @@
}
}
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ init();
+
+ try {
+
+ doExecute();
+
+ } catch (Exception e) {
+ getLog().error(e);
+ Throwable e2 = e;
+ while (e2.getCause() != null) {
+ e2 = e.getCause();
+ }
+ getLog().error(e2);
+
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+
+ }
+
+ protected void fixCompileSourceRoots() {
+ if (!project.getCompileSourceRoots().contains(outJava.getPath())) {
+ project.addCompileSourceRoot(outJava.getPath());
+ }
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected URLClassLoader initClassLoader(MavenProject project, Log log) {
+ URLClassLoader loader = null;
+ if (project != null) {
+ URLClassLoader result;
+ try {
+ Set<Artifact> compileClasspathElements = project.getArtifacts();
+ URL[] url = new URL[compileClasspathElements.size() + 1];
+ url[0] = outClass.toURI().toURL();
+ int i = 1;
+ for (Artifact artifact : compileClasspathElements) {
+ File file = new File(artifact.getFile().getAbsolutePath());
+ if (file.getName().endsWith(".jar")) {
+ url[i] = new URL("jar", "", file.toURI().toURL().toString() + "!/");
+ } else {
+ url[i] = file.toURI().toURL();
+ }
+ i++;
+ }
+ //ClassLoader parent = Thread.currentThread().getContextClassLoader();
+ if (compileClasspathElements.size() == 0) {
+ result = new URLClassLoader(url, getClass().getClassLoader());
+ } else {
+ result = new URLClassLoader(url, getClass().getClassLoader());
+ }
+ } catch (MalformedURLException eee) {
+ throw new RuntimeException("Can't create ClassLoader for script, bad directory: " + outClass + " for reason " + eee.getMessage(), eee);
+ } catch (IOException e) {
+ throw new RuntimeException("Can't create ClassLoader for script, bad directory: " + outClass + " for reason " + e.getMessage(), e);
+ }
+ loader = result;
+ }
+ if (verbose && loader != null) {
+ for (URL entry : loader.getURLs()) {
+ log.info("outClass url " + entry);
+ }
+ }
+ return loader;
+ }
+
+ public File getOutJava() {
+ return outJava;
+ }
+
+ public void setOutJava(File outJava) {
+ this.outJava = outJava;
+ }
+
+ public File getOutResource() {
+ return outResource;
+ }
+
+ public void setOutResource(File outResource) {
+ this.outResource = outResource;
+ }
+
+ public File getOutClass() {
+ return outClass;
+ }
+
+ public void setOutClass(File outClass) {
+ this.outClass = outClass;
+ }
+
+ public boolean isVerbose() {
+ return verbose;
+ }
+
+ public void setVerbose(boolean verbose) {
+ this.verbose = verbose;
+ }
+
public File getSrc() {
return src;
}
1
0
r815 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: factory provider
by tchemit@users.labs.libre-entreprise.org 06 Aug '08
by tchemit@users.labs.libre-entreprise.org 06 Aug '08
06 Aug '08
Author: tchemit
Date: 2008-08-06 10:15:00 +0000 (Wed, 06 Aug 2008)
New Revision: 815
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java
Log:
simplification du code : on supprime la classe abstraite car pour le moment y'a qu'une seule implantation :)
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java 2008-08-05 22:30:47 UTC (rev 814)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/AbstractActionFactory.java 2008-08-06 10:15:00 UTC (rev 815)
@@ -1,387 +0,0 @@
-/*
-* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 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.factory;
-
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.swing.JAXXToggleButton;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.codelutin.jaxx.action.MyAbstractAction;
-import org.codelutin.jaxx.action.initializer.AbstractActionConfigurationResolver;
-import org.codelutin.jaxx.action.initializer.ActionConfigConfigurationResolver;
-import org.codelutin.jaxx.action.initializer.ActionConfigurationResolver;
-import org.codelutin.jaxx.action.initializer.SelectActionConfigConfigurationResolver;
-import org.codelutin.jaxx.action.initializer.ToggleActionConfigConfigurationResolver;
-
-import javax.swing.AbstractButton;
-import javax.swing.Action;
-import javax.swing.Icon;
-import javax.swing.JComboBox;
-import javax.swing.JComponent;
-import java.awt.event.ActionEvent;
-import java.lang.reflect.InvocationTargetException;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.TreeMap;
-
-/**
- * Action factory using the ActionConfig annotations to configure the action.
- * <p/>
- * The factory is abstract, implements method {@link #init()} to fill the
- * dictonary of known action implementations.
- * <p/>
- * Use after the {@link #loadActions(jaxx.runtime.JAXXObject)} to instanciate
- * actions in ui with id equals a known action...
- * <p/>
- * TODO Finish doc
- *
- * @author chemit
- */
-public abstract class AbstractActionFactory<A extends MyAbstractAction> implements ActionFactory<A> {
-
- protected static Log log = LogFactory.getLog(AbstractActionFactory.class);
-
- /** class of encapsuling action */
- protected Class<A> baseImpl;
-
- /** dictionary of known actions implementations */
- private Map<String, Class<? extends MyAbstractAction>> impls;
-
- /** dictionary of instanciated actions */
- private Map<String, A> cache;
-
- protected final ActionConfigConfigurationResolver actionConfigInitializer;
- protected final ToggleActionConfigConfigurationResolver toggleActionConfigInitializer;
- protected final SelectActionConfigConfigurationResolver selectActionConfigInitializer;
-
- protected List<AbstractActionConfigurationResolver> configurationResolvers;
-
-
- protected AbstractActionFactory(Class<A> baseImpl) {
- this.baseImpl = baseImpl;
- this.impls = init();
- this.cache = new TreeMap<String, A>();
- this.configurationResolvers = new java.util.ArrayList<AbstractActionConfigurationResolver>();
-
- this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigConfigurationResolver.class);
- this.actionConfigInitializer = registerInitializer(ActionConfigConfigurationResolver.class);
- this.selectActionConfigInitializer = registerInitializer(SelectActionConfigConfigurationResolver.class);
- }
-
- public Class<A> getBaseImpl() {
- return baseImpl;
- }
-
- public void resetCache() {
- cache.clear();
- }
-
- public A get(String actionKey) {
- return cache.get(actionKey);
- }
-
- public void loadActions(JAXXObject ui) {
- if (log.isDebugEnabled()) {
- log.debug("for ui " + ui.getClass());
- }
- 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;
- A action = newAction(actionKey, component);
-
- component.setAction(action);
-
- if (component instanceof JAXXToggleButton) {
- JAXXToggleButton glueComponent = (JAXXToggleButton) component;
- glueComponent.setIcon((Icon) action.getValue(Action.SMALL_ICON));
- Integer integer = (Integer) action.getValue(Action.MNEMONIC_KEY);
- if (integer != null) {
- glueComponent.setNormalMnemonic(integer);
- }
- glueComponent.setSelectedIcon((Icon) action.getValue(Action.SMALL_ICON + 2));
- integer = (Integer) action.getValue(Action.MNEMONIC_KEY + 2);
- if (integer != null) {
- glueComponent.setGlueMnemonic(integer);
- }
- glueComponent.setGlueText((String) action.getValue(Action.NAME + 2));
- glueComponent.setGlueTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION + 2));
-
- glueComponent.setNormalText((String) action.getValue(Action.NAME));
- glueComponent.setNormalTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION));
- }
-
- Boolean value = (Boolean) action.getValue("hideActionText");
- component.setHideActionText(value != null && value);
- action.setEnabled(true);
- continue;
- }
- // is JComboBox
- JComboBox component = (JComboBox) comp;
- A 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);
- }
- }
- }
-
- /**
- * @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.
- */
- public A newAction(String actionKey, JComponent component) {
- // try first in cache
- A result = getActionFromCache(actionKey);
- if (result != null) {
- return result;
- }
-
- try {
- result = newActionInstance(actionKey);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- if (log.isDebugEnabled()) {
- log.debug("create <" + actionKey + " : " + result + ">");
- }
-
- // recherche de l'annotation de configuration
- ActionConfigurationResolver<?, ?> configurationResolver = resolveActionConfiguration(result);
-
- if (configurationResolver != null) {
- configurationResolver.applyConfiguration(component, result);
- }
-
- try {
-
- if (configurationResolver != null) {
- if (AbstractButton.class.isAssignableFrom(configurationResolver.getComponentImpl())) {
- finalizeNewAction((AbstractButton) component, result, configurationResolver);
- }
-
- if (JComboBox.class.isAssignableFrom(configurationResolver.getComponentImpl())) {
- finalizeNewAction((JComboBox) component, result, configurationResolver);
- }
-
- return result;
- }
-
- if (component == null || component instanceof AbstractButton) {
- finalizeNewAction((AbstractButton) component, result, configurationResolver);
- return result;
- }
-
- if (component instanceof JComboBox) {
- finalizeNewAction((JComboBox) component, result, configurationResolver);
- }
- } finally {
- // save result in cache
- cache.put(actionKey, result);
- }
-
- return result;
- }
-
- public A newAction(String actionKey) {
- return newAction(actionKey, null);
- }
-
- 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<Entry<String, A>> cacheEntrySet() {
- return cache.entrySet();
- }
-
- public void fireAction(String actionKey, Object source, JComponent component) {
- A action = newAction(actionKey, component);
- fireAction0(actionKey, source, action);
- }
-
- public void fireAction(String actionKey, Object source) {
- fireAction(actionKey, source, null);
- }
-
- /**
- * @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 A getActionFromCache(String actionKey) {
- // on vérifie que l'action existe bien
- checkRegistredAction(actionKey);
-
- // try in cache
- if (cache.containsKey(actionKey)) {
- // use cached action
- A action = cache.get(actionKey);
- if (log.isDebugEnabled()) {
- log.debug("use cache action " + action);
- }
- return action;
- }
- return null;
- }
-
- public void dispose() {
- if (log.isInfoEnabled()) {
- log.info(this);
- }
- for (String actionKey : getActionNames()) {
- MyAbstractAction action = getActionFromCache(actionKey);
- if (action != null) {
- action.disposeUI();
- }
- }
- resetCache();
- }
-
- @Override
- protected void finalize() throws Throwable {
- super.finalize();
- resetCache();
- impls.clear();
- }
-
- /**
- * @param component le button où rattacher l'action
- * @param action action
- * @param configurationResolver initializer
- */
- protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) {
-
- if (configurationResolver == null) {
- // no configurationResolver 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());
- }
- }
-
- }
-
- 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()));
- }
- action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
- }
-
- }
-
- /**
- * @param component le select box où rattacher l'action
- * @param action action
- * @param configurationResolver initializer
- */
- protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) {
-
- if (configurationResolver == null) {
- action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
- action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
- //result.putValue("selectedIndex", component.getSelectedIndex());
- }
-
- }
-
- protected ActionConfigurationResolver resolveActionConfiguration(MyAbstractAction action) {
- for (ActionConfigurationResolver resolver : configurationResolvers) {
- if (resolver.resolveConfiguration(action) != null) {
- return resolver;
- }
- }
- return null;
- }
-
- protected <I extends AbstractActionConfigurationResolver> I registerInitializer(Class<I> initizalizer) {
- try {
- I instance = initizalizer.newInstance();
- configurationResolvers.add(instance);
- return instance;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public void fireAction0(String actionKey, Object source, A action) {
- if (action == null) {
- log.warn("could not find action " + actionKey);
- return;
- }
- 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);
- }
- }
-
-
- @SuppressWarnings({"unchecked"})
- protected A 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);
- if (!getBaseImpl().isAssignableFrom(klazz)) {
- // the instanciated action must be boxed in the base Action of the factory
- result = getBaseImpl().getConstructor(MyAbstractAction.class).newInstance(result);
- }
- return (A) result;
- }
-}
\ No newline at end of file
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-08-05 22:30:47 UTC (rev 814)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/factory/ActionFactoryFromProvider.java 2008-08-06 10:15:00 UTC (rev 815)
@@ -17,16 +17,35 @@
* ##% */
package org.codelutin.jaxx.action.factory;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.swing.JAXXToggleButton;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.codelutin.jaxx.action.MyAbstractAction;
+import org.codelutin.jaxx.action.initializer.AbstractActionConfigurationResolver;
+import org.codelutin.jaxx.action.initializer.ActionConfigConfigurationResolver;
+import org.codelutin.jaxx.action.initializer.ActionConfigurationResolver;
+import org.codelutin.jaxx.action.initializer.SelectActionConfigConfigurationResolver;
+import org.codelutin.jaxx.action.initializer.ToggleActionConfigConfigurationResolver;
import org.codelutin.jaxx.action.provider.ActionProvider;
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import java.awt.event.ActionEvent;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.ServiceLoader;
+import java.util.Set;
import java.util.TreeMap;
/**
* TODO Do javadoc which is not up to date...
- * A simple implementation of {@link AbstractActionFactory} using a properties file to
+ * A simple implementation of {@link ActionFactory} using a properties file to
* load action mapping.
* <p/>
* An entry is in that form : <code>action.actionName=fqn</code> where
@@ -36,16 +55,340 @@
*
* @author chemit
*/
-public class ActionFactoryFromProvider<A extends MyAbstractAction> extends AbstractActionFactory<A> {
+public class ActionFactoryFromProvider<A extends MyAbstractAction> implements ActionFactory<A> {
- public static <A extends MyAbstractAction> ActionFactoryFromProvider<A> newInstance(Class<A> klazz) {
+ protected static Log log = LogFactory.getLog(ActionFactoryFromProvider.class);
+
+ public static <A extends MyAbstractAction> ActionFactory<A> newInstance(Class<A> klazz) {
return new ActionFactoryFromProvider<A>(klazz);
}
- protected ActionFactoryFromProvider(Class<A> baseClass) {
- super(baseClass);
+ /** class of encapsuling action */
+ protected Class<A> baseImpl;
+
+ /** dictionary of known actions implementations */
+ private Map<String, Class<? extends MyAbstractAction>> impls;
+
+ /** dictionary of instanciated actions */
+ private Map<String, A> cache;
+
+ protected final ActionConfigConfigurationResolver actionConfigInitializer;
+ protected final ToggleActionConfigConfigurationResolver toggleActionConfigInitializer;
+ protected final SelectActionConfigConfigurationResolver selectActionConfigInitializer;
+
+ protected List<AbstractActionConfigurationResolver> configurationResolvers;
+
+ protected ActionFactoryFromProvider(Class<A> baseImpl) {
+ this.baseImpl = baseImpl;
+ this.impls = init();
+ this.cache = new TreeMap<String, A>();
+ this.configurationResolvers = new java.util.ArrayList<AbstractActionConfigurationResolver>();
+
+ this.toggleActionConfigInitializer = registerInitializer(ToggleActionConfigConfigurationResolver.class);
+ this.actionConfigInitializer = registerInitializer(ActionConfigConfigurationResolver.class);
+ this.selectActionConfigInitializer = registerInitializer(SelectActionConfigConfigurationResolver.class);
}
+ public Class<A> getBaseImpl() {
+ return baseImpl;
+ }
+
+ public void resetCache() {
+ cache.clear();
+ }
+
+ public A get(String actionKey) {
+ return cache.get(actionKey);
+ }
+
+ public void loadActions(JAXXObject ui) {
+ if (log.isDebugEnabled()) {
+ log.debug("for ui " + ui.getClass());
+ }
+ 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;
+ A action = newAction(actionKey, component);
+
+ component.setAction(action);
+
+ if (component instanceof JAXXToggleButton) {
+ JAXXToggleButton glueComponent = (JAXXToggleButton) component;
+ glueComponent.setIcon((Icon) action.getValue(Action.SMALL_ICON));
+ Integer integer = (Integer) action.getValue(Action.MNEMONIC_KEY);
+ if (integer != null) {
+ glueComponent.setNormalMnemonic(integer);
+ }
+ glueComponent.setSelectedIcon((Icon) action.getValue(Action.SMALL_ICON + 2));
+ integer = (Integer) action.getValue(Action.MNEMONIC_KEY + 2);
+ if (integer != null) {
+ glueComponent.setGlueMnemonic(integer);
+ }
+ glueComponent.setGlueText((String) action.getValue(Action.NAME + 2));
+ glueComponent.setGlueTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION + 2));
+
+ glueComponent.setNormalText((String) action.getValue(Action.NAME));
+ glueComponent.setNormalTooltipText((String) action.getValue(Action.SHORT_DESCRIPTION));
+ }
+
+ Boolean value = (Boolean) action.getValue("hideActionText");
+ component.setHideActionText(value != null && value);
+ action.setEnabled(true);
+ continue;
+ }
+ // is JComboBox
+ JComboBox component = (JComboBox) comp;
+ A 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);
+ }
+ }
+ }
+
+ /**
+ * @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.
+ */
+ public A newAction(String actionKey, JComponent component) {
+ // try first in cache
+ A result = getActionFromCache(actionKey);
+ if (result != null) {
+ return result;
+ }
+
+ try {
+ result = newActionInstance(actionKey);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ if (log.isDebugEnabled()) {
+ log.debug("create <" + actionKey + " : " + result + ">");
+ }
+
+ // recherche de l'annotation de configuration
+ ActionConfigurationResolver<?, ?> configurationResolver = resolveActionConfiguration(result);
+
+ if (configurationResolver != null) {
+ configurationResolver.applyConfiguration(component, result);
+ }
+
+ try {
+
+ if (configurationResolver != null) {
+ if (AbstractButton.class.isAssignableFrom(configurationResolver.getComponentImpl())) {
+ finalizeNewAction((AbstractButton) component, result, configurationResolver);
+ }
+
+ if (JComboBox.class.isAssignableFrom(configurationResolver.getComponentImpl())) {
+ finalizeNewAction((JComboBox) component, result, configurationResolver);
+ }
+
+ return result;
+ }
+
+ if (component == null || component instanceof AbstractButton) {
+ finalizeNewAction((AbstractButton) component, result, configurationResolver);
+ return result;
+ }
+
+ if (component instanceof JComboBox) {
+ finalizeNewAction((JComboBox) component, result, configurationResolver);
+ }
+ } finally {
+ // save result in cache
+ cache.put(actionKey, result);
+ }
+
+ return result;
+ }
+
+ public A newAction(String actionKey) {
+ return newAction(actionKey, null);
+ }
+
+ public String[] getActionNames() {
+ return impls.keySet().toArray(new String[impls.size()]);
+ }
+
+ public Set<Entry<String, Class<? extends MyAbstractAction>>> implsEntrySet() {
+ return impls.entrySet();
+ }
+
+ public Set<Entry<String, A>> cacheEntrySet() {
+ return cache.entrySet();
+ }
+
+ public void fireAction(String actionKey, Object source, JComponent component) {
+ A action = newAction(actionKey, component);
+ fireAction0(actionKey, source, action);
+ }
+
+ public void fireAction(String actionKey, Object source) {
+ fireAction(actionKey, source, null);
+ }
+
+ /**
+ * @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 A getActionFromCache(String actionKey) {
+ // on vérifie que l'action existe bien
+ checkRegistredAction(actionKey);
+
+ // try in cache
+ if (cache.containsKey(actionKey)) {
+ // use cached action
+ A action = cache.get(actionKey);
+ if (log.isDebugEnabled()) {
+ log.debug("use cache action " + action);
+ }
+ return action;
+ }
+ return null;
+ }
+
+ public void dispose() {
+ if (log.isInfoEnabled()) {
+ log.info(this);
+ }
+ for (String actionKey : getActionNames()) {
+ MyAbstractAction action = getActionFromCache(actionKey);
+ if (action != null) {
+ action.disposeUI();
+ }
+ }
+ resetCache();
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ resetCache();
+ impls.clear();
+ }
+
+ /**
+ * @param component le button où rattacher l'action
+ * @param action action
+ * @param configurationResolver initializer
+ */
+ protected void finalizeNewAction(AbstractButton component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) {
+
+ if (configurationResolver == null) {
+ // no configurationResolver 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());
+ }
+ }
+
+ }
+
+ 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()));
+ }
+ action.putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY, pos);
+ }
+
+ }
+
+ /**
+ * @param component le select box où rattacher l'action
+ * @param action action
+ * @param configurationResolver initializer
+ */
+ protected void finalizeNewAction(JComboBox component, MyAbstractAction action, ActionConfigurationResolver<?, ?> configurationResolver) {
+
+ if (configurationResolver == null) {
+ action.putValue(Action.ACTION_COMMAND_KEY, component.getName());
+ action.putValue(Action.SHORT_DESCRIPTION, component.getToolTipText());
+ //result.putValue("selectedIndex", component.getSelectedIndex());
+ }
+
+ }
+
+ protected ActionConfigurationResolver resolveActionConfiguration(MyAbstractAction action) {
+ for (ActionConfigurationResolver resolver : configurationResolvers) {
+ if (resolver.resolveConfiguration(action) != null) {
+ return resolver;
+ }
+ }
+ return null;
+ }
+
+ protected <I extends AbstractActionConfigurationResolver> I registerInitializer(Class<I> initizalizer) {
+ try {
+ I instance = initizalizer.newInstance();
+ configurationResolvers.add(instance);
+ return instance;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void fireAction0(String actionKey, Object source, A action) {
+ if (action == null) {
+ log.warn("could not find action " + actionKey);
+ return;
+ }
+ 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);
+ }
+ }
+
+
+ @SuppressWarnings({"unchecked"})
+ protected A 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);
+ if (!getBaseImpl().isAssignableFrom(klazz)) {
+ // the instanciated action must be boxed in the base Action of the factory
+ result = getBaseImpl().getConstructor(MyAbstractAction.class).newInstance(result);
+ }
+ return (A) result;
+ }
+
+
public Map<String, Class<? extends MyAbstractAction>> init() {
if (log.isDebugEnabled()) {
log.debug("start loading " + this);
Deleted: 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/AbstractActionProvider.java 2008-08-05 22:30:47 UTC (rev 814)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/AbstractActionProvider.java 2008-08-06 10:15:00 UTC (rev 815)
@@ -1,73 +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.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();
- }
-}
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-08-05 22:30:47 UTC (rev 814)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-08-06 10:15:00 UTC (rev 815)
@@ -14,6 +14,8 @@
*/
package org.codelutin.jaxx.action.provider;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import static org.codelutin.i18n.I18n._;
import org.codelutin.jaxx.action.ActionNameHelper.RuntimeActionNameProvider;
import org.codelutin.jaxx.action.MyAbstractAction;
@@ -25,19 +27,61 @@
import java.util.TreeMap;
/** @author chemit */
-public class ActionProviderFromProperties<A extends MyAbstractAction> extends AbstractActionProvider<A> {
+public class ActionProviderFromProperties<A extends MyAbstractAction> implements ActionProvider<A> {
/** default prefix for an entryin mapping file. */
protected static final String ACTION_KEY_PREFIX = "action.";
protected String propertiesPath;
+ protected static Log log = LogFactory.getLog(ActionProviderFromProperties.class);
+
+ protected String name;
+
+ protected Class<A> baseClass;
+
+ protected Map<String, Class<? extends A>> actions;
+
+
protected ActionProviderFromProperties(String name, Class<A> baseClass, String propertiesPath) {
- super(name, baseClass, false);
+
+ this.name = name;
+ this.baseClass = baseClass;
+
this.propertiesPath = propertiesPath;
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();
+ }
+
@SuppressWarnings({"unchecked"})
protected Map<String, Class<? extends A>> initCache() {
1
0
r814 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . provider
by tchemit@users.labs.libre-entreprise.org 05 Aug '08
by tchemit@users.labs.libre-entreprise.org 05 Aug '08
05 Aug '08
Author: tchemit
Date: 2008-08-05 22:30:47 +0000 (Tue, 05 Aug 2008)
New Revision: 814
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameHelper.java
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java
Log:
fix bug : on doit faire une reprise sur ancien fichier de mapping si on recompile
ajout de la possibilit?\195?\169 de calculer les noms d'action au runtime
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-05 11:08:02 UTC (rev 813)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-05 22:30:47 UTC (rev 814)
@@ -46,6 +46,7 @@
import javax.tools.StandardLocation;
import java.io.BufferedWriter;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -243,6 +244,11 @@
protected void writeActionMapping() throws IOException {
BufferedWriter w = null;
try {
+ Properties oldProps = loadOldActionMapping();
+ if (oldProps != null) {
+ actions.putAll(oldProps);
+ }
+ // ecriture de toutes les actions trouvees
FileObject fo = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", actionsFileLocation);
printInfo("writing " + fo.toUri());
w = new BufferedWriter(fo.openWriter());
@@ -253,6 +259,30 @@
}
}
+ protected Properties loadOldActionMapping() throws IOException {
+ // reprise sur une ancienne compilation
+ FileObject oldFo = processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, "", actionsFileLocation);
+ System.out.println("URI " + oldFo.toUri());
+ if (!new java.io.File(oldFo.toUri().toString()).exists()) {
+ return null;
+ }
+ Properties oldProps = new Properties();
+ InputStream inputStream = null;
+ try {
+ inputStream = oldFo.openInputStream();
+ if (inputStream != null) {
+ oldProps.load(inputStream);
+ }
+ oldFo.delete();
+ } finally {
+ if (inputStream != null) {
+ inputStream.close();
+ }
+ }
+
+ return oldProps;
+ }
+
/**
* Obtain the array of names to be used by the annotation
*
@@ -266,12 +296,38 @@
ExecutableElement type = entry.getKey();
String name = type.getSimpleName().toString();
- if ("multiNames".equals(name)) {
+ if ("actionCommands".equals(name)) {
List<String> stringList = (List<String>) entry.getValue().accept(getAnnotationValueExtractor(), null);
result = stringList.toArray(new String[stringList.size()]);
- // a multiNames field means
+ // a actionCommands field means
break;
}
+ if ("actionCommandProvider".equals(name)) {
+ TypeMirror t = (TypeMirror) entry.getValue().accept(getAnnotationValueExtractor(), null);
+ String classname = t.toString();
+ printDebug("actionCommandProvider = " + classname);
+ if (classname.endsWith(ActionNameHelper.ActionNameProvider.class.getName())) {
+ continue;
+ }
+
+ /*Class<ActionNameHelper.ActionNameProvider> klazz = (Class<ActionNameHelper.ActionNameProvider>) entry.getValue().accept(getAnnotationValueExtractor(), null);
+ if (ActionNameHelper.CompileActionNameProvider.class.isAssignableFrom(klazz)) {
+ // means there is a compile time names provider
+ try {
+ result = klazz.newInstance().getActionCommands();
+ break;
+ } catch (InstantiationException e) {
+ throw new RuntimeException(e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (ActionNameHelper.RuntimeActionNameProvider.class.isAssignableFrom(klazz)) {*/
+ // means there is a runtime names provider
+ result = new String[]{":" + classname};
+ break;
+ //}
+ }
if ("actionCommand".equals(name)) {
result = new String[]{(String) entry.getValue().accept(getAnnotationValueExtractor(), null)};
}
@@ -297,6 +353,10 @@
}
return realVals;
}
+
+ public Object visitType(TypeMirror t, Void aVoid) {
+ return t;
+ }
};
}
return annotationValueExtractor;
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java 2008-08-05 11:08:02 UTC (rev 813)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfig.java 2008-08-05 22:30:47 UTC (rev 814)
@@ -43,8 +43,13 @@
* @return la clef de la commande (doit être unique)
* @see javax.swing.Action#ACTION_COMMAND_KEY
*/
- public String actionCommand();
+ String actionCommand();
+ /** @return array of names to be used in actions mapping */
+ String[] actionCommands() default {};
+
+ Class<? extends ActionNameHelper.ActionNameProvider> actionCommandProvider() default ActionNameHelper.ActionNameProvider.class;
+
/**
* @return la clef i18n du texte de l'action, si vide ignoré
* @see javax.swing.Action#NAME
@@ -108,7 +113,4 @@
/** @return hideActionText state */
boolean hideActionText() default false;
- /** @return array of names to be used in actions mapping */
- String[] multiNames() default {};
-
}
\ No newline at end of file
Added: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameHelper.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameHelper.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionNameHelper.java 2008-08-05 22:30:47 UTC (rev 814)
@@ -0,0 +1,43 @@
+/**
+ * # #% 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;
+
+/** @author chemit */
+public class ActionNameHelper {
+
+ /**
+ * Contrat pour obtenir les noms d'une action.
+ *
+ * @author chemit
+ */
+ public static interface ActionNameProvider {
+
+ /** @return la liste des noms à utiliser par la classe d'action. */
+ String[] getActionCommands();
+
+ }
+
+ /** Contrat pour obtenir les noms d'actions au moment de la compilation. */
+ public static interface CompileActionNameProvider extends ActionNameProvider {
+
+ }
+
+ /** Contrat pour obtenir les noms d'actions au moment du runtime. */
+ public static interface RuntimeActionNameProvider extends ActionNameProvider {
+
+ }
+
+
+}
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java 2008-08-05 11:08:02 UTC (rev 813)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfig.java 2008-08-05 22:30:47 UTC (rev 814)
@@ -43,45 +43,47 @@
* @return la clef de la commande (doit être unique)
* @see javax.swing.Action#ACTION_COMMAND_KEY
*/
- public abstract String actionCommand();
+ String actionCommand();
+ /** @return array of names to be used in actions mapping */
+ String[] actionCommands() default {};
+
+ Class<? extends ActionNameHelper.ActionNameProvider> actionCommandProvider() default ActionNameHelper.ActionNameProvider.class;
+
/**
* @return la clef i18n du texte de l'action, si vide ignoré
* @see javax.swing.Action#NAME
*/
- public abstract String name() default "";
+ String name() default "";
/**
* @return la clef i18n du tooltip de l'action, si vide ignoré
* @see javax.swing.Action#SHORT_DESCRIPTION
*/
- public abstract String shortDescription() default "";
+ String shortDescription() default "";
/**
* @return la clef i18n du texte de l'action, si vide ignoré
* @see javax.swing.Action#LONG_DESCRIPTION
*/
- public abstract String longDescription() default "";
+ String longDescription() default "";
/**
* @return accelerator key
* @see javax.swing.Action#ACCELERATOR_KEY
*/
- public abstract String accelerator() default "";
+ String accelerator() default "";
/**
* @return la valeur par défaut pour les component selectable
* @see javax.swing.Action#SELECTED_KEY
*/
- public abstract int selectedIndex() default 0;
+ int selectedIndex() default 0;
/**
* @return enabled state
* @see javax.swing.Action#isEnabled()
*/
- public abstract boolean enabled() default true;
+ boolean enabled() default true;
- /** @return array of names to be used in actions mapping */
- public abstract String[] multiNames() default {};
-
}
\ No newline at end of file
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java 2008-08-05 11:08:02 UTC (rev 813)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfig.java 2008-08-05 22:30:47 UTC (rev 814)
@@ -41,107 +41,110 @@
* @return la clef de la commande (doit être unique)
* @see javax.swing.Action#ACTION_COMMAND_KEY
*/
- public abstract String actionCommand();
+ String actionCommand();
+ /** @return array of names to be used in actions mapping */
+ String[] actionCommands() default {};
+
+ Class<? extends ActionNameHelper.ActionNameProvider> actionCommandProvider() default ActionNameHelper.ActionNameProvider.class;
+
/**
* @return la clef i18n du texte de l'action, si vide ignoré
* @see javax.swing.Action#NAME
*/
- public abstract String name() default "";
+ String name() default "";
/**
* @return la clef i18n du tooltip de l'action, si vide ignoré
* @see javax.swing.Action#SHORT_DESCRIPTION
*/
- public abstract String shortDescription() default "";
+ String shortDescription() default "";
/**
* @return la clef i18n du texte de l'action, si vide ignoré
* @see javax.swing.Action#LONG_DESCRIPTION
*/
- public abstract String longDescription() default "";
+ String longDescription() default "";
/**
* @return le nom de l'icone associé, si vide ignoré
* @see javax.swing.Action#SMALL_ICON
*/
- public abstract String smallIcon() default "";
+ String smallIcon() default "";
/**
* @return le nom du grande icone associé, si vide ignoré
* @see javax.swing.Action#LARGE_ICON_KEY
*/
- public abstract String largeIcon() default "";
+ String largeIcon() default "";
/**
* @return accelerator key of default state
* @see javax.swing.Action#ACCELERATOR_KEY
*/
- public abstract String accelerator() default "";
+ String accelerator() default "";
/**
* @return mnemonic key of default state
* @see javax.swing.Action#MNEMONIC_KEY
*/
- public abstract int mnemonic() default '\0';
+ int mnemonic() default '\0';
/**
* @return la clef i18n du texte de l'action, si vide ignoré
* @see javax.swing.Action#NAME
*/
- public abstract String name2() default "";
+ String name2() default "";
/**
* @return la clef i18n du tooltip de l'action, si vide ignoré
* @see javax.swing.Action#SHORT_DESCRIPTION
*/
- public abstract String shortDescription2() default "";
+ String shortDescription2() default "";
/**
* @return la clef i18n du texte de l'action, si vide ignoré
* @see javax.swing.Action#LONG_DESCRIPTION
*/
- public abstract String longDescription2() default "";
+ String longDescription2() default "";
/**
* @return le nom de l'icone associé, si vide ignoré
* @see javax.swing.Action#SMALL_ICON
*/
- public abstract String smallIcon2() default "";
+ String smallIcon2() default "";
/**
* @return le nom du grande icone associé, si vide ignoré
* @see javax.swing.Action#LARGE_ICON_KEY
*/
- public abstract String largeIcon2() default "";
+ String largeIcon2() default "";
/**
* @return accelerator key of default state
* @see javax.swing.Action#ACCELERATOR_KEY
*/
- public abstract String accelerator2() default "";
+ String accelerator2() default "";
/**
* @return mnemonic key of second state
* @see javax.swing.Action#MNEMONIC_KEY
*/
- public abstract int mnemonic2() default '\0';
+ int mnemonic2() default '\0';
/**
* @return la valeur par défaut pour les component selectable
* @see javax.swing.Action#SELECTED_KEY
*/
- public abstract boolean selected() default false;
+ boolean selected() default false;
/**
* @return enaled state
* @see javax.swing.Action#isEnabled()
*/
- public abstract boolean enabled() default true;
+ boolean enabled() default true;
/** @return hideActionText state */
- public abstract boolean hideActionText() default false;
+ boolean hideActionText() default false;
- /** @return array of names to be used in actions mapping */
- public abstract String[] multiNames() default {};
}
\ No newline at end of file
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-08-05 11:08:02 UTC (rev 813)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/provider/ActionProviderFromProperties.java 2008-08-05 22:30:47 UTC (rev 814)
@@ -15,6 +15,7 @@
package org.codelutin.jaxx.action.provider;
import static org.codelutin.i18n.I18n._;
+import org.codelutin.jaxx.action.ActionNameHelper.RuntimeActionNameProvider;
import org.codelutin.jaxx.action.MyAbstractAction;
import java.io.IOException;
@@ -74,10 +75,23 @@
Class<? extends A> implCass;
implCass = (Class<? extends A>) Class.forName(qfn);
String actionKey = key.substring(prefix);
+ if (actionKey.startsWith(":")) {
+ // this is a RuntimeActionNameProvider
+ Class<RuntimeActionNameProvider> klazz = (Class<RuntimeActionNameProvider>) Class.forName(actionKey.substring(1));
+ for (String s : klazz.newInstance().getActionCommands()) {
+ log.debug("found action <" + s + " : " + implCass + ">");
+ cache.put(s, implCass);
+ }
+ continue;
+ }
log.debug("found action <" + actionKey + " : " + implCass + ">");
cache.put(actionKey, implCass);
} catch (ClassNotFoundException e) {
throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
+ } catch (InstantiationException e) {
+ throw new RuntimeException(_("jaxx.error.load.actions.class", key, qfn), e);
}
}
1
0
r813 - in trunk/lutinjaxx: . core jaxx-swing jaxx-swing-action jaxx-swing-action/src/main/java/org/codelutin/jaxx/action jaxx-swing-tab maven runtime util
by tchemit@users.labs.libre-entreprise.org 05 Aug '08
by tchemit@users.labs.libre-entreprise.org 05 Aug '08
05 Aug '08
Author: tchemit
Date: 2008-08-05 11:08:02 +0000 (Tue, 05 Aug 2008)
New Revision: 813
Added:
trunk/lutinjaxx/jaxx-swing-action/changelog
Modified:
trunk/lutinjaxx/core/pom.xml
trunk/lutinjaxx/jaxx-swing-action/pom.xml
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java
trunk/lutinjaxx/jaxx-swing-tab/pom.xml
trunk/lutinjaxx/jaxx-swing/pom.xml
trunk/lutinjaxx/maven/pom.xml
trunk/lutinjaxx/pom.xml
trunk/lutinjaxx/runtime/pom.xml
trunk/lutinjaxx/util/pom.xml
Log:
passage version 0.3-SNAPSHOT pour corriger 2 bugs sur l'annotation processor : (voir changelog)
ajout changelog
Modified: trunk/lutinjaxx/core/pom.xml
===================================================================
--- trunk/lutinjaxx/core/pom.xml 2008-08-05 10:39:58 UTC (rev 812)
+++ trunk/lutinjaxx/core/pom.xml 2008-08-05 11:08:02 UTC (rev 813)
@@ -7,14 +7,14 @@
<parent>
<groupId>org.codelutin.jaxx</groupId>
<artifactId>pom</artifactId>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
</parent>
<artifactId>core</artifactId>
<name>core</name>
<packaging>jar</packaging>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
<description>Jaxx lutin library core</description>
<build>
Modified: trunk/lutinjaxx/jaxx-swing/pom.xml
===================================================================
--- trunk/lutinjaxx/jaxx-swing/pom.xml 2008-08-05 10:39:58 UTC (rev 812)
+++ trunk/lutinjaxx/jaxx-swing/pom.xml 2008-08-05 11:08:02 UTC (rev 813)
@@ -7,14 +7,14 @@
<parent>
<groupId>org.codelutin.jaxx</groupId>
<artifactId>pom</artifactId>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
</parent>
<artifactId>jaxx-swing</artifactId>
<name>jaxx-swing</name>
<packaging>jar</packaging>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
<description>Jaxx library swing extension</description>
<dependencies>
Added: trunk/lutinjaxx/jaxx-swing-action/changelog
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/changelog (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/changelog 2008-08-05 11:08:02 UTC (rev 813)
@@ -0,0 +1,7 @@
+jaxx-swing-action (0.4) stable; urgency=high
+
+ * bug correction when have to compile actions but not the baseAction, providerConfig was null
+ * bug correction when action herites from another not base action, the action has te be treated after the mother action
+ * usemaven-i18n-plugin v0.4
+
+ -- Tony Chemit <chemit(a)codelutin.com> Fri, 05 Aug 2008 02:02:02 +0200
Modified: trunk/lutinjaxx/jaxx-swing-action/pom.xml
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/pom.xml 2008-08-05 10:39:58 UTC (rev 812)
+++ trunk/lutinjaxx/jaxx-swing-action/pom.xml 2008-08-05 11:08:02 UTC (rev 813)
@@ -7,14 +7,14 @@
<parent>
<groupId>org.codelutin.jaxx</groupId>
<artifactId>pom</artifactId>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
</parent>
<artifactId>jaxx-swing-action</artifactId>
<name>jaxx-swing-action</name>
<packaging>jar</packaging>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
<description>Jaxx lutin library swing actions extension</description>
<build>
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-05 10:39:58 UTC (rev 812)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-05 11:08:02 UTC (rev 813)
@@ -116,16 +116,23 @@
String className = e.toString();
if (processedClass.contains(className)) {
+ printWarning("class already processed " + className);
// do not process class twice
continue;
}
- printDebug("process class " + className);
- registerActionsForClass(annotation.asType(), e);
- processedClass.add(className);
+
+ boolean wasTreated = registerActionsForClass(annotation.asType(), e);
+ if (wasTreated) {
+ printDebug("process class " + className);
+ processedClass.add(className);
+ } else {
+ printDebug("class was not processed " + e);
+ }
}
}
if ((roundEnv.processingOver())) {
+ printDebug("round is over " + roundEnv);
try {
if (providerConfig == null) {
// baseActionClass was not compiled at this time, must find it back
@@ -165,16 +172,21 @@
}
}
- protected void registerActionsForClass(TypeMirror annotationType, Element e) {
+ protected boolean registerActionsForClass(TypeMirror annotationType, Element e) {
+ boolean doTreate = false;
for (AnnotationMirror mirror : e.getAnnotationMirrors()) {
if (!mirror.getAnnotationType().equals(annotationType)) {
// do not treate other annotations
continue;
}
+ doTreate = true;
+ printDebug("found a annotation to treate : " + mirror + " for action : " + e.toString());
for (String name : getActionNames(mirror)) {
actions.put("action." + name, e.toString());
+ printDebug("registerActionForClass " + name + " : " + e.toString());
}
}
+ return doTreate;
}
protected void parseOptions() {
Modified: trunk/lutinjaxx/jaxx-swing-tab/pom.xml
===================================================================
--- trunk/lutinjaxx/jaxx-swing-tab/pom.xml 2008-08-05 10:39:58 UTC (rev 812)
+++ trunk/lutinjaxx/jaxx-swing-tab/pom.xml 2008-08-05 11:08:02 UTC (rev 813)
@@ -7,14 +7,14 @@
<parent>
<groupId>org.codelutin.jaxx</groupId>
<artifactId>pom</artifactId>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
</parent>
<artifactId>jaxx-swing-tab</artifactId>
<name>jaxx-swing-tab</name>
<packaging>jar</packaging>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
<description>Jaxx lutin library swing tab extension</description>
<build>
Modified: trunk/lutinjaxx/maven/pom.xml
===================================================================
--- trunk/lutinjaxx/maven/pom.xml 2008-08-05 10:39:58 UTC (rev 812)
+++ trunk/lutinjaxx/maven/pom.xml 2008-08-05 11:08:02 UTC (rev 813)
@@ -12,7 +12,7 @@
<parent>
<groupId>org.codelutin.jaxx</groupId>
<artifactId>pom</artifactId>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
</parent>
<artifactId>maven-jaxx-plugin</artifactId>
@@ -63,7 +63,7 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
<description>
Maven 2 plugin to generate java source from ui interface definitions
Modified: trunk/lutinjaxx/pom.xml
===================================================================
--- trunk/lutinjaxx/pom.xml 2008-08-05 10:39:58 UTC (rev 812)
+++ trunk/lutinjaxx/pom.xml 2008-08-05 11:08:02 UTC (rev 813)
@@ -39,7 +39,7 @@
<!-- *** Project Information ************************************* -->
<!-- ************************************************************* -->
<name>pom</name>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
<description>Jaxx lutin library main pom</description>
<inceptionYear>2008</inceptionYear>
Modified: trunk/lutinjaxx/runtime/pom.xml
===================================================================
--- trunk/lutinjaxx/runtime/pom.xml 2008-08-05 10:39:58 UTC (rev 812)
+++ trunk/lutinjaxx/runtime/pom.xml 2008-08-05 11:08:02 UTC (rev 813)
@@ -7,14 +7,14 @@
<parent>
<groupId>org.codelutin.jaxx</groupId>
<artifactId>pom</artifactId>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
</parent>
<artifactId>runtime</artifactId>
<name>runtime</name>
<packaging>jar</packaging>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
<description>Jaxx lutin library runtime</description>
<build>
Modified: trunk/lutinjaxx/util/pom.xml
===================================================================
--- trunk/lutinjaxx/util/pom.xml 2008-08-05 10:39:58 UTC (rev 812)
+++ trunk/lutinjaxx/util/pom.xml 2008-08-05 11:08:02 UTC (rev 813)
@@ -7,14 +7,14 @@
<parent>
<groupId>org.codelutin.jaxx</groupId>
<artifactId>pom</artifactId>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
</parent>
<artifactId>util</artifactId>
<name>util</name>
<packaging>jar</packaging>
- <version>0.3</version>
+ <version>0.3-SNAPSHOT</version>
<description>Jaxx lutin library utility</description>
<build>
1
0