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
August 2008
- 1 participants
- 31 discussions
r827 - trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action
by tchemit@users.labs.libre-entreprise.org 10 Aug '08
by tchemit@users.labs.libre-entreprise.org 10 Aug '08
10 Aug '08
Author: tchemit
Date: 2008-08-10 15:18:09 +0000 (Sun, 10 Aug 2008)
New Revision: 827
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java
Log:
fix bug : can not use Class.forname on uncompiled classes
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-10 13:14:47 UTC (rev 826)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionAnnotationProcessing.java 2008-08-10 15:18:09 UTC (rev 827)
@@ -43,6 +43,8 @@
import javax.tools.JavaFileObject;
import javax.tools.StandardLocation;
import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -133,20 +135,22 @@
if ((roundEnv.processingOver())) {
printDebug("round is over " + roundEnv);
try {
- if (providerConfig == null) {
+ if (providerConfig != null) {
+ // found the base action class to be compiled, so we have to write provider things...
+ writeProviderClass();
+ writeProviderServiceDeclaration();
+ } else {
+
// baseActionClass was not compiled at this time, must find it back
+ // this means they should have an already mapping file written
- findProviderConfigFromCompiledClass();
+ actionsFileLocation = findMappingFile();
- if (providerConfig == null) {
- throw new IllegalStateException("no provider name found, you must add on baseaction the annotation " + ActionProviderAnnotation.class);
- }
- actionsFileLocation = String.format(actionsFileLocation, providerConfig.name());
- } else {
- writeProviderClass();
- writeProviderServiceDeclaration();
+ printInfo("reused actionFilesLocation " + actionsFileLocation);
}
+
writeActionMapping();
+
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
@@ -158,8 +162,36 @@
return true;
}
+ protected String findMappingFile() throws IOException {
+ String path = String.format(actionsFileLocation, "dummy_" + System.nanoTime());
+
+
+ FileObject oldFo = processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT, "", path);
+ File dummyFile = new File(oldFo.toUri().toString()).getParentFile();
+ File[] files = dummyFile.listFiles(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ return name.startsWith("jaxx-") && name.endsWith("-actions.properties");
+ }
+ });
+ if (files.length < 1) {
+ // this is not normal, should have exactly one file here
+ throw new IllegalStateException("no provider name found, you must add on baseaction the annotation " + ActionProviderAnnotation.class);
+ }
+ File f = files[0];
+ int index = f.getAbsolutePath().indexOf("META-INF");
+
+ return f.getAbsolutePath().substring(index);
+ }
+
+ /**
+ * @throws ClassNotFoundException ifclass not find
+ * @deprecated Can not use anylonger this class, beacause at compile time we are not garanted to have
+ * some actions classes compiled, so can not use {@link Class#forName(String)} method.
+ */
+ @Deprecated
protected void findProviderConfigFromCompiledClass() throws ClassNotFoundException {
- if (!processedClass.isEmpty()) {
+ if (!actions.isEmpty()) {
Class<?> klazz = Class.forName(processedClass.get(0));
providerConfig = klazz.getAnnotation(ActionProviderAnnotation.class);
while (klazz != null && providerConfig == null) {
@@ -240,11 +272,17 @@
}
protected void writeActionMapping() throws IOException {
+ if (actions.isEmpty()) {
+ // nothing to write or overwrite
+ return;
+ }
+
BufferedWriter w = null;
try {
Properties oldProps = loadOldActionMapping();
if (oldProps != null) {
- actions.putAll(oldProps);
+ oldProps.putAll(actions);
+ actions = oldProps;
}
// ecriture de toutes les actions trouvees
FileObject fo = processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "", actionsFileLocation);
@@ -260,11 +298,10 @@
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()) {
+ if (!new File(oldFo.toUri().toString()).exists()) {
return null;
}
- Properties oldProps = new Properties();
+ Properties oldProps = new SortedProperties();
InputStream inputStream = null;
try {
inputStream = oldFo.openInputStream();
1
0
r826 - trunk/lutinjaxx/core/src/main/java/jaxx/runtime
by tchemit@users.labs.libre-entreprise.org 10 Aug '08
by tchemit@users.labs.libre-entreprise.org 10 Aug '08
10 Aug '08
Author: tchemit
Date: 2008-08-10 13:14:47 +0000 (Sun, 10 Aug 2008)
New Revision: 826
Modified:
trunk/lutinjaxx/core/src/main/java/jaxx/runtime/JAXXObject.java
Log:
ajout en visibilite public de la methode get$objectMap pour pouvoir utiliser de l'exterieur cet dictionnaire
Modified: trunk/lutinjaxx/core/src/main/java/jaxx/runtime/JAXXObject.java
===================================================================
--- trunk/lutinjaxx/core/src/main/java/jaxx/runtime/JAXXObject.java 2008-08-09 10:27:18 UTC (rev 825)
+++ trunk/lutinjaxx/core/src/main/java/jaxx/runtime/JAXXObject.java 2008-08-10 13:14:47 UTC (rev 826)
@@ -14,6 +14,11 @@
*/
public Object getObjectById(String id);
+ /**
+ * Pretrieves the dictonary of knwon objects indexed by their ids.
+ * @return the dictonary of objects.
+ */
+ public java.util.Map<String,Object> get$objectMap();
public void applyDataBinding(String id);
1
0
r825 - 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:27:18 +0000 (Sat, 09 Aug 2008)
New Revision: 825
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/
Log:
simplification du code : suppression du paquetage initializer
1
0
r824 - 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:55 +0000 (Sat, 09 Aug 2008)
New Revision: 824
Modified:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java
Log:
simplification du code : suppression du paquetage initializer
Modified: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java 2008-08-09 10:26:44 UTC (rev 823)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionFactoryFromProvider.java 2008-08-09 10:26:55 UTC (rev 824)
@@ -21,11 +21,6 @@
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;
1
0
r823 - in trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action: . initializer
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:44 +0000 (Sat, 09 Aug 2008)
New Revision: 823
Added:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionConfigurationResolver.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfigConfigurationResolver.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfigurationResolver.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfigConfigurationResolver.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfigConfigurationResolver.java
Removed:
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionConfigurationResolver.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigConfigurationResolver.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigurationResolver.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigConfigurationResolver.java
trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigConfigurationResolver.java
Log:
simplification du code : suppression du paquetage initializer
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionConfigurationResolver.java (from rev 820, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionConfigurationResolver.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionConfigurationResolver.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/AbstractActionConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -0,0 +1,70 @@
+/**
+ * # #% 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 javax.swing.JComponent;
+
+/**
+ * Common abstract class of a resolver of action configuration.
+ * <p/>
+ * The class implements the logic of research of the configuration annotation.
+ *
+ * @author chemit
+ */
+public abstract class AbstractActionConfigurationResolver<A extends java.lang.annotation.Annotation, C extends JComponent> implements ActionConfigurationResolver<A, C> {
+
+ /** the type of configuration's annotation */
+ protected final Class<A> annotationImpl;
+
+ /** the type of component that can fire an action */
+ protected final Class<C> componentImpl;
+
+ /**
+ * The typed method (on component) to apply configuration on the action and component.
+ *
+ * @param component the component which fires the action
+ * @param action the given action
+ * @return the configuration's annotation
+ */
+ protected abstract A applyConfiguration0(C component, MyAbstractAction action);
+
+ protected AbstractActionConfigurationResolver(Class<A> annotationImpl, Class<C> componentImpl) {
+ this.annotationImpl = annotationImpl;
+ this.componentImpl = componentImpl;
+ }
+
+ public A resolveConfiguration(MyAbstractAction action) {
+ if (action.hasDelegate()) {
+ return resolveConfiguration(action.getDelegate());
+ }
+ return action.getClass().getAnnotation(annotationImpl);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public A applyConfiguration(JComponent component, MyAbstractAction action) {
+ if (component != null && componentImpl.isAssignableFrom(component.getClass()))
+ return applyConfiguration0((C) component, action);
+
+ return null;
+ }
+
+ public Class<A> getAnnotationImpl() {
+ return annotationImpl;
+ }
+
+ public Class<C> getComponentImpl() {
+ return componentImpl;
+ }
+}
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfigConfigurationResolver.java (from rev 820, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigConfigurationResolver.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfigConfigurationResolver.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfigConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -0,0 +1,67 @@
+/**
+ * # #% Copyright (C) 2008 Code Lutin, Tony Chemit
+ * This program is free software; you
+ * can redistribute it and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. This program is
+ * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
+ * should have received a copy of the GNU General Public License along with this
+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place
+ * - Suite 330, Boston, MA 02111-1307, USA.
+ * # #%
+ */
+package org.codelutin.jaxx.action;
+
+import static org.codelutin.i18n.I18n._;
+
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+
+/**
+ * Implementation of configuration's resolver for annotation {@link ActionConfig}
+ *
+ * @author chemit
+ */
+public class ActionConfigConfigurationResolver extends AbstractActionConfigurationResolver<ActionConfig, AbstractButton> {
+
+ public ActionConfigConfigurationResolver() {
+ super(ActionConfig.class, AbstractButton.class);
+ }
+
+ protected ActionConfig applyConfiguration0(AbstractButton component, MyAbstractAction action) {
+ ActionConfig anno = resolveConfiguration(action);
+ if (anno == null) {
+ return null;
+ }
+ // inject les données
+ if (!anno.name().isEmpty()) {
+ //System.out.println("found action with name : " + anno.name());
+ action.putValue(Action.NAME, _(anno.name()));
+ }
+ //if (!anno.shortDescription().isEmpty()) {
+ action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
+ //}
+ if (!anno.smallIcon().isEmpty()) {
+ action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon()));
+ }
+ if (anno.mnemonic() != '\0') {
+ action.putValue(Action.MNEMONIC_KEY, anno.mnemonic());
+ } else if (component != null) {
+ action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
+ }
+ //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
+
+ if (component == null) {
+ action.putValue("hideActionText", anno.hideActionText());
+ } else {
+ boolean actionText = component.getHideActionText();
+ action.putValue("hideActionText", anno.hideActionText() || actionText);
+ }
+ action.putValue(Action.SELECTED_KEY, anno.selected());
+ action.setEnabled(anno.enabled());
+
+ return anno;
+ }
+}
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfigurationResolver.java (from rev 820, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigurationResolver.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfigurationResolver.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ActionConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -0,0 +1,52 @@
+/**
+ * # #% 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 javax.swing.JComponent;
+
+/**
+ * The contract to be realized to resolve an {@link MyAbstractAction} configuration.
+ * <p/>
+ * Configuration is done by a Annotation of type {@link A} placed on the action class.
+ * <p/>
+ * If the instanciated action box the real action, we should always search on the boxed action.
+ * <p/>
+ * Moreover, a action can only be fired by a certain type of component (for example a Button or a ComboBox), the class
+ * of the component type is given by the {@link C} class.
+ *
+ * @author chemit
+ */
+public interface ActionConfigurationResolver<A extends java.lang.annotation.Annotation, C extends JComponent> {
+ /**
+ * Search the annotation that configure the given action (or the boxed action).
+ *
+ * @param action current action
+ * @return the configuration of the action
+ */
+ A resolveConfiguration(MyAbstractAction action);
+
+ /**
+ * @param component widget that requires the action
+ * @param action given action
+ * @return the configuration of the action
+ */
+ A applyConfiguration(JComponent component, MyAbstractAction action);
+
+ /** @return the configuration annotation dealed by this resolver */
+ Class<A> getAnnotationImpl();
+
+ /** @return the class of the component which can fired the action */
+ Class<C> getComponentImpl();
+}
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfigConfigurationResolver.java (from rev 820, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigConfigurationResolver.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfigConfigurationResolver.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/SelectActionConfigConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -0,0 +1,53 @@
+/**
+ * # #% Copyright (C) 2008 Code Lutin, Tony Chemit
+ * This program is free software; you
+ * can redistribute it and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. This program is
+ * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
+ * should have received a copy of the GNU General Public License along with this
+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place
+ * - Suite 330, Boston, MA 02111-1307, USA.
+ * # #%
+ */
+package org.codelutin.jaxx.action;
+
+import static org.codelutin.i18n.I18n._;
+
+import javax.swing.Action;
+import javax.swing.JComboBox;
+
+/**
+ * Implementation of configuration's resolver for annotation {@link SelectActionConfig}
+ *
+ * @author chemit
+ */
+public class SelectActionConfigConfigurationResolver extends AbstractActionConfigurationResolver<SelectActionConfig, JComboBox> {
+
+ public SelectActionConfigConfigurationResolver() {
+ super(SelectActionConfig.class, JComboBox.class);
+ }
+
+ protected SelectActionConfig applyConfiguration0(JComboBox component, MyAbstractAction action) {
+ SelectActionConfig anno = resolveConfiguration(action);
+ if (anno == null) {
+ return null;
+ }
+ // inject les données
+ if (!anno.name().isEmpty()) {
+ action.putValue(Action.NAME, _(anno.name()));
+ }
+ if (!anno.shortDescription().isEmpty()) {
+ action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
+ } else {
+ action.putValue(Action.SHORT_DESCRIPTION, _(component.getToolTipText()));
+ }
+ action.putValue("selectedIndex", anno.selectedIndex());
+ //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
+ action.setEnabled(anno.enabled());
+
+ return anno;
+ }
+}
\ No newline at end of file
Copied: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfigConfigurationResolver.java (from rev 820, trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigConfigurationResolver.java)
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfigConfigurationResolver.java (rev 0)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/ToggleActionConfigConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -0,0 +1,79 @@
+/**
+ * # #% Copyright (C) 2008 Code Lutin, Tony Chemit
+ * This program is free software; you
+ * can redistribute it and/or modify it under the terms of the GNU General
+ * Public License as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. This program is
+ * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
+ * should have received a copy of the GNU General Public License along with this
+ * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place
+ * - Suite 330, Boston, MA 02111-1307, USA.
+ * # #%
+ */
+package org.codelutin.jaxx.action;
+
+import static org.codelutin.i18n.I18n._;
+
+import javax.swing.AbstractButton;
+import javax.swing.Action;
+
+/**
+ * Implementation of configuration's resolver for annotation {@link ToggleActionConfig}
+ *
+ * @author chemit
+ */
+public class ToggleActionConfigConfigurationResolver extends AbstractActionConfigurationResolver<ToggleActionConfig, AbstractButton> {
+
+ public ToggleActionConfigConfigurationResolver() {
+ super(ToggleActionConfig.class, AbstractButton.class);
+ }
+
+ protected ToggleActionConfig applyConfiguration0(AbstractButton component, MyAbstractAction action) {
+ ToggleActionConfig anno = resolveConfiguration(action);
+ if (anno == null) {
+ return null;
+ }
+ // inject les données
+ if (!anno.name().isEmpty()) {
+ //System.out.println("found action with name : " + anno.name());
+ action.putValue(Action.NAME, _(anno.name()));
+ }
+ if (!anno.name2().isEmpty()) {
+ //System.out.println("found action with name2 : " + anno.name2());
+ action.putValue(Action.NAME + "2", _(anno.name2()));
+ }
+
+ if (!anno.shortDescription().isEmpty()) {
+ action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
+ }
+ if (!anno.shortDescription2().isEmpty()) {
+ action.putValue(Action.SHORT_DESCRIPTION + "2", _(anno.shortDescription2()));
+ }
+
+ if (!anno.smallIcon().isEmpty()) {
+ action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon()));
+ }
+ if (!anno.smallIcon2().isEmpty()) {
+ action.putValue(Action.SMALL_ICON + "2", org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon2()));
+ }
+
+ if (anno.mnemonic() != '\0') {
+ action.putValue(Action.MNEMONIC_KEY, anno.mnemonic());
+ } else if (component != null) {
+ action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
+ }
+ if (anno.mnemonic2() != '\0') {
+ action.putValue(Action.MNEMONIC_KEY + "2", anno.mnemonic2());
+ }
+ //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
+
+
+ action.putValue("hideActionText", anno.hideActionText());
+ action.putValue(Action.SELECTED_KEY, anno.selected());
+ action.setEnabled(anno.enabled());
+
+ return anno;
+ }
+}
\ No newline at end of file
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionConfigurationResolver.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionConfigurationResolver.java 2008-08-09 10:26:02 UTC (rev 822)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/AbstractActionConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -1,72 +0,0 @@
-/**
- * # #% Copyright (C) 2008 Code Lutin, Tony Chemit
- * This program is free software; you
- * can redistribute it and/or modify it under the terms of the GNU General
- * Public License as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. This program is
- * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
- * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
- * should have received a copy of the GNU General Public License along with this
- * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place
- * - Suite 330, Boston, MA 02111-1307, USA.
- * # #%
- */
-package org.codelutin.jaxx.action.initializer;
-
-import org.codelutin.jaxx.action.MyAbstractAction;
-
-import javax.swing.JComponent;
-
-/**
- * Common abstract class of a resolver of action configuration.
- * <p/>
- * The class implements the logic of research of the configuration annotation.
- *
- * @author chemit
- */
-public abstract class AbstractActionConfigurationResolver<A extends java.lang.annotation.Annotation, C extends JComponent> implements ActionConfigurationResolver<A, C> {
-
- /** the type of configuration's annotation */
- protected final Class<A> annotationImpl;
-
- /** the type of component that can fire an action */
- protected final Class<C> componentImpl;
-
- /**
- * The typed method (on component) to apply configuration on the action and component.
- *
- * @param component the component which fires the action
- * @param action the given action
- * @return the configuration's annotation
- */
- protected abstract A applyConfiguration0(C component, MyAbstractAction action);
-
- protected AbstractActionConfigurationResolver(Class<A> annotationImpl, Class<C> componentImpl) {
- this.annotationImpl = annotationImpl;
- this.componentImpl = componentImpl;
- }
-
- public A resolveConfiguration(MyAbstractAction action) {
- if (action.hasDelegate()) {
- return resolveConfiguration(action.getDelegate());
- }
- return action.getClass().getAnnotation(annotationImpl);
- }
-
- @SuppressWarnings({"unchecked"})
- public A applyConfiguration(JComponent component, MyAbstractAction action) {
- if (component != null && componentImpl.isAssignableFrom(component.getClass()))
- return applyConfiguration0((C) component, action);
-
- return null;
- }
-
- public Class<A> getAnnotationImpl() {
- return annotationImpl;
- }
-
- public Class<C> getComponentImpl() {
- return componentImpl;
- }
-}
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigConfigurationResolver.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigConfigurationResolver.java 2008-08-09 10:26:02 UTC (rev 822)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -1,69 +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.initializer;
-
-import static org.codelutin.i18n.I18n._;
-import org.codelutin.jaxx.action.ActionConfig;
-import org.codelutin.jaxx.action.MyAbstractAction;
-
-import javax.swing.AbstractButton;
-import javax.swing.Action;
-
-/**
- * Implementation of configuration's resolver for annotation {@link ActionConfig}
- *
- * @author chemit
- */
-public class ActionConfigConfigurationResolver extends AbstractActionConfigurationResolver<ActionConfig, AbstractButton> {
-
- public ActionConfigConfigurationResolver() {
- super(ActionConfig.class, AbstractButton.class);
- }
-
- protected ActionConfig applyConfiguration0(AbstractButton component, MyAbstractAction action) {
- ActionConfig anno = resolveConfiguration(action);
- if (anno == null) {
- return null;
- }
- // inject les données
- if (!anno.name().isEmpty()) {
- //System.out.println("found action with name : " + anno.name());
- action.putValue(Action.NAME, _(anno.name()));
- }
- //if (!anno.shortDescription().isEmpty()) {
- action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
- //}
- if (!anno.smallIcon().isEmpty()) {
- action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon()));
- }
- if (anno.mnemonic() != '\0') {
- action.putValue(Action.MNEMONIC_KEY, anno.mnemonic());
- } else if (component != null) {
- action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
- }
- //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
-
- if (component == null) {
- action.putValue("hideActionText", anno.hideActionText());
- } else {
- boolean actionText = component.getHideActionText();
- action.putValue("hideActionText", anno.hideActionText() || actionText);
- }
- action.putValue(Action.SELECTED_KEY, anno.selected());
- action.setEnabled(anno.enabled());
-
- return anno;
- }
-}
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigurationResolver.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigurationResolver.java 2008-08-09 10:26:02 UTC (rev 822)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ActionConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -1,54 +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.initializer;
-
-import org.codelutin.jaxx.action.MyAbstractAction;
-
-import javax.swing.JComponent;
-
-/**
- * The contract to be realized to resolve an {@link MyAbstractAction} configuration.
- * <p/>
- * Configuration is done by a Annotation of type {@link A} placed on the action class.
- * <p/>
- * If the instanciated action box the real action, we should always search on the boxed action.
- * <p/>
- * Moreover, a action can only be fired by a certain type of component (for example a Button or a ComboBox), the class
- * of the component type is given by the {@link C} class.
- *
- * @author chemit
- */
-public interface ActionConfigurationResolver<A extends java.lang.annotation.Annotation, C extends JComponent> {
- /**
- * Search the annotation that configure the given action (or the boxed action).
- *
- * @param action current action
- * @return the configuration of the action
- */
- A resolveConfiguration(MyAbstractAction action);
-
- /**
- * @param component widget that requires the action
- * @param action given action
- * @return the configuration of the action
- */
- A applyConfiguration(JComponent component, MyAbstractAction action);
-
- /** @return the configuration annotation dealed by this resolver */
- Class<A> getAnnotationImpl();
-
- /** @return the class of the component which can fired the action */
- Class<C> getComponentImpl();
-}
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigConfigurationResolver.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigConfigurationResolver.java 2008-08-09 10:26:02 UTC (rev 822)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/SelectActionConfigConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -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.action.initializer;
-
-import static org.codelutin.i18n.I18n._;
-import org.codelutin.jaxx.action.MyAbstractAction;
-import org.codelutin.jaxx.action.SelectActionConfig;
-
-import javax.swing.Action;
-import javax.swing.JComboBox;
-
-/**
- * Implementation of configuration's resolver for annotation {@link SelectActionConfig}
- *
- * @author chemit
- */
-public class SelectActionConfigConfigurationResolver extends AbstractActionConfigurationResolver<SelectActionConfig, JComboBox> {
-
- public SelectActionConfigConfigurationResolver() {
- super(SelectActionConfig.class, JComboBox.class);
- }
-
- protected SelectActionConfig applyConfiguration0(JComboBox component, MyAbstractAction action) {
- SelectActionConfig anno = resolveConfiguration(action);
- if (anno == null) {
- return null;
- }
- // inject les données
- if (!anno.name().isEmpty()) {
- action.putValue(Action.NAME, _(anno.name()));
- }
- if (!anno.shortDescription().isEmpty()) {
- action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
- } else {
- action.putValue(Action.SHORT_DESCRIPTION, _(component.getToolTipText()));
- }
- action.putValue("selectedIndex", anno.selectedIndex());
- //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
- action.setEnabled(anno.enabled());
-
- return anno;
- }
-}
\ No newline at end of file
Deleted: trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigConfigurationResolver.java
===================================================================
--- trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigConfigurationResolver.java 2008-08-09 10:26:02 UTC (rev 822)
+++ trunk/lutinjaxx/jaxx-swing-action/src/main/java/org/codelutin/jaxx/action/initializer/ToggleActionConfigConfigurationResolver.java 2008-08-09 10:26:44 UTC (rev 823)
@@ -1,81 +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.initializer;
-
-import static org.codelutin.i18n.I18n._;
-import org.codelutin.jaxx.action.MyAbstractAction;
-import org.codelutin.jaxx.action.ToggleActionConfig;
-
-import javax.swing.AbstractButton;
-import javax.swing.Action;
-
-/**
- * Implementation of configuration's resolver for annotation {@link ToggleActionConfig}
- *
- * @author chemit
- */
-public class ToggleActionConfigConfigurationResolver extends AbstractActionConfigurationResolver<ToggleActionConfig, AbstractButton> {
-
- public ToggleActionConfigConfigurationResolver() {
- super(ToggleActionConfig.class, AbstractButton.class);
- }
-
- protected ToggleActionConfig applyConfiguration0(AbstractButton component, MyAbstractAction action) {
- ToggleActionConfig anno = resolveConfiguration(action);
- if (anno == null) {
- return null;
- }
- // inject les données
- if (!anno.name().isEmpty()) {
- //System.out.println("found action with name : " + anno.name());
- action.putValue(Action.NAME, _(anno.name()));
- }
- if (!anno.name2().isEmpty()) {
- //System.out.println("found action with name2 : " + anno.name2());
- action.putValue(Action.NAME + "2", _(anno.name2()));
- }
-
- if (!anno.shortDescription().isEmpty()) {
- action.putValue(Action.SHORT_DESCRIPTION, _(anno.shortDescription()));
- }
- if (!anno.shortDescription2().isEmpty()) {
- action.putValue(Action.SHORT_DESCRIPTION + "2", _(anno.shortDescription2()));
- }
-
- if (!anno.smallIcon().isEmpty()) {
- action.putValue(Action.SMALL_ICON, org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon()));
- }
- if (!anno.smallIcon2().isEmpty()) {
- action.putValue(Action.SMALL_ICON + "2", org.codelutin.jaxx.util.UIHelper.createImageIcon(anno.smallIcon2()));
- }
-
- if (anno.mnemonic() != '\0') {
- action.putValue(Action.MNEMONIC_KEY, anno.mnemonic());
- } else if (component != null) {
- action.putValue(Action.MNEMONIC_KEY, component.getMnemonic());
- }
- if (anno.mnemonic2() != '\0') {
- action.putValue(Action.MNEMONIC_KEY + "2", anno.mnemonic2());
- }
- //TODO Convert it from String action.putValue(Action.ACCELERATOR_KEY, anno.accelerator());
-
-
- action.putValue("hideActionText", anno.hideActionText());
- action.putValue(Action.SELECTED_KEY, anno.selected());
- action.setEnabled(anno.enabled());
-
- return anno;
- }
-}
\ No newline at end of file
1
0
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