r814 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . provider
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); } }
participants (1)
-
tchemit@users.labs.libre-entreprise.org