Jaxx-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
October 2009
- 3 participants
- 80 discussions
r1620 - branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator
by tchemit@users.nuiton.org 30 Oct '09
by tchemit@users.nuiton.org 30 Oct '09
30 Oct '09
Author: tchemit
Date: 2009-10-30 12:09:43 +0100 (Fri, 30 Oct 2009)
New Revision: 1620
Modified:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java
Log:
Evolution #106: Am?\195?\169lioration de l'api des Decorator
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java 2009-10-29 18:21:10 UTC (rev 1619)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java 2009-10-30 11:09:43 UTC (rev 1620)
@@ -26,7 +26,7 @@
import java.util.*;
/**
- * Some usefull methods on {@link Decorator} to create, decorators and obtain decorators.
+ * Some usefull methods on {@link Decorator} to create, and sort data with decorators.
* <p/>
* To create a new decorator, use one of the methods :
* <ul>
@@ -36,13 +36,6 @@
* <li>{@link #newMultiJXPathDecorator(Class, String, String, String)})</li>
* </ul>
* <p/>
- * <p/>
- * To register a new decorator, use the method {@link #register(String, Decorator)}.
- * <p/>
- * To obtain a registred decorator, use the method {@link #get(String)}
- * (get the decorator based on his registred name). or the method {@link #get(Class, String)}
- * (get the decorator based on the type of decorator and the registred name).
- * <p/>
* To sort a list of data, using a {@link JXPathDecorator}, use the method
* {@link #sort(JXPathDecorator, List, int)}.
* <p/>
@@ -53,13 +46,6 @@
public class DecoratorUtils {
/**
- * Registred decorators.
- * @deprecated prefer use a {@link DecoratorProvider}
- */
- @Deprecated
- protected static List<DecoratorContext<?>> decorators;
-
- /**
* Factory method to instanciate a new {@link PropertyDecorator} for the
* given class {@code internlaClass} and a readable property name.
*
@@ -120,49 +106,7 @@
return new MultiJXPathDecorator<O>(internalClass, expression, separator, separatorReplacement, contexts);
}
- @Deprecated
- public static <T> Decorator<T> get(String context) {
- Decorator<T> result = get(null, context);
- return result;
- }
-
- @Deprecated
- public static <T> Decorator<T> get(Class<T> type, String context) {
- DecoratorContext<T> decoratorContext = getDecoratorContext(type, context);
- Decorator<T> result = decoratorContext == null ? null : decoratorContext.getDecorator();
- return result;
- }
-
/**
- * Register a new decorator in the cache.
- *
- * @param <T> type of data decorated
- * @param context the name decorator
- * @param decorator the decorator to register
- */
- @Deprecated
- public static <T> void register(String context, Decorator<T> decorator) {
-
- DecoratorContext<T> result = getDecoratorContext(decorator.getInternalClass(), context);
-
- if (result != null) {
- throw new IllegalArgumentException("there is an already register decorator " + result);
- }
-
- if (decorators == null) {
- decorators = new java.util.ArrayList<DecoratorContext<?>>();
- }
- decorators.add(new DecoratorContext<T>(context, decorator));
- }
-
- @Deprecated
- public static void clear() {
- if (decorators != null) {
- decorators.clear();
- }
- }
-
- /**
* Sort a list of data based on the first token property of a given context
* in a given decorator.
*
@@ -189,71 +133,6 @@
}
}
- @SuppressWarnings({"unchecked"})
- @Deprecated
- protected static <T> DecoratorContext<T> getDecoratorContext(Class<T> type, String context) {
- DecoratorContext<T> result = null;
- if (decorators != null) {
- for (DecoratorContext<?> d : decorators) {
- if (type == null) {
- if (d.accept(context)) {
- result = (DecoratorContext<T>) d;
- break;
- }
- continue;
- }
- if (d.accept(type, context)) {
- result = (DecoratorContext<T>) d;
- break;
- }
- }
- }
- return result;
- }
-
- @Deprecated
- public static class DecoratorContext<T> {
-
- /**
- * the context name of the decorator
- */
- final String context;
- /**
- * the decorator
- */
- final Decorator<T> decorator;
-
- public DecoratorContext(String context, Decorator<T> decorator) {
- this.context = context;
- this.decorator = decorator;
- }
-
- public String getContext() {
- return context;
- }
-
- public Decorator<T> getDecorator() {
- return decorator;
- }
-
- public Class<T> getType() {
- return decorator.getInternalClass();
- }
-
- public boolean accept(Class<?> type, String context) {
- return getType().isAssignableFrom(type) && accept(context);
- }
-
- public boolean accept(String context) {
- return ((this.context == null && context == null) || (this.context != null && this.context.equals(context)));
- }
-
- @Override
- public String toString() {
- return super.toString() + "<type: " + getType().getName() + ", context :" + context + ">";
- }
- }
-
public static <O> Context<O> createJXPathContext(String expression) {
List<String> lTokens = new ArrayList<String>();
StringBuilder buffer = new StringBuilder();
1
0
r1619 - in branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo: . component/jaxx/navigation
by tchemit@users.nuiton.org 29 Oct '09
by tchemit@users.nuiton.org 29 Oct '09
29 Oct '09
Author: tchemit
Date: 2009-10-29 19:21:10 +0100 (Thu, 29 Oct 2009)
New Revision: 1619
Modified:
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx
Log:
fix context error
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-29 17:06:25 UTC (rev 1618)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-29 18:21:10 UTC (rev 1619)
@@ -84,6 +84,9 @@
// share a unique DecoratorProviderListCellRenderer
DecoratorProvider decoratorProvider = rootContext.getContextValue(DecoratorProvider.class);
+
+ context.add(decoratorProvider);
+
context.add(new DecoratorProviderListCellRenderer(decoratorProvider));
// instanciate ui
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx 2009-10-29 17:06:25 UTC (rev 1618)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeDemo.jaxx 2009-10-29 18:21:10 UTC (rev 1619)
@@ -28,11 +28,14 @@
import jaxx.runtime.SwingUtil;
import jaxx.demo.component.jaxx.navigation.content.*;
+import jaxx.runtime.decorator.DecoratorProvider;
+
private final FullNavigationTreeHelper helper = new FullNavigationTreeHelper();
private final ContentUIHandler contentUIHandler = new ContentUIHandler();
setContextValue(helper);
setContextValue(contentUIHandler);
helper.setTree(this, navigation);
+log.info("decorator provider = "+getContextValue(DecoratorProvider.class));
helper.createModel(this);
@Override
@@ -73,8 +76,6 @@
showsRootHandles='false'
model='{helper.createTreeModel(this)}'
selectionModel="{helper.createTreeHandler(this)}"/>
- <!--cellRenderer='{new NavigationTreeCellRenderer(this, 150)}' />-->
-
</JScrollPane>
<JPanel id="content" layout="{contentLayout}" />
1
0
r1618 - in branches/jaxx-2.X: jaxx-demo jaxx-swing-action maven-jaxx-plugin
by tchemit@users.nuiton.org 29 Oct '09
by tchemit@users.nuiton.org 29 Oct '09
29 Oct '09
Author: tchemit
Date: 2009-10-29 18:06:25 +0100 (Thu, 29 Oct 2009)
New Revision: 1618
Modified:
branches/jaxx-2.X/jaxx-demo/
branches/jaxx-2.X/jaxx-swing-action/
branches/jaxx-2.X/maven-jaxx-plugin/
Log:
svn:ingore idea files
Property changes on: branches/jaxx-2.X/jaxx-demo
___________________________________________________________________
Modified: svn:ignore
- target
+ target
*.iml
Property changes on: branches/jaxx-2.X/jaxx-swing-action
___________________________________________________________________
Modified: svn:ignore
- target
+ target
*.iml
Property changes on: branches/jaxx-2.X/maven-jaxx-plugin
___________________________________________________________________
Modified: svn:ignore
- target
+ target
*.iml
1
0
r1617 - in branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo: . component/jaxx/navigation component/jaxx/navigation/content
by tchemit@users.nuiton.org 29 Oct '09
by tchemit@users.nuiton.org 29 Oct '09
29 Oct '09
Author: tchemit
Date: 2009-10-29 17:48:10 +0100 (Thu, 29 Oct 2009)
New Revision: 1617
Modified:
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx
branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx
Log:
- use DecoratorProviderListCellRenderer
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-29 14:55:21 UTC (rev 1616)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2009-10-29 16:48:10 UTC (rev 1617)
@@ -20,26 +20,28 @@
*/
package jaxx.demo;
-import jaxx.runtime.swing.ErrorDialogUI;
import jaxx.runtime.JAXXContext;
+import jaxx.runtime.context.DefaultApplicationContext;
+import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.context.JAXXInitialContext;
+import jaxx.runtime.decorator.DecoratorProvider;
+import jaxx.runtime.swing.AboutPanel;
+import jaxx.runtime.swing.ErrorDialogUI;
+import jaxx.runtime.swing.editor.config.ConfigUI;
+import jaxx.runtime.swing.editor.config.ConfigUIBuilder;
+import jaxx.runtime.swing.editor.config.model.ConfigUIModel;
import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.i18n.I18n;
import static org.nuiton.i18n.I18n._;
import static org.nuiton.i18n.I18n.n_;
-import java.awt.Desktop;
+import javax.swing.*;
+import java.awt.*;
import java.net.URL;
import java.util.Locale;
-import javax.swing.SwingUtilities;
-import jaxx.runtime.context.DefaultApplicationContext;
-import jaxx.runtime.context.JAXXContextEntryDef;
-import jaxx.runtime.swing.AboutPanel;
-import jaxx.runtime.swing.editor.config.ConfigUI;
-import jaxx.runtime.swing.editor.config.ConfigUIBuilder;
-import jaxx.runtime.swing.editor.config.model.ConfigUIModel;
-import org.nuiton.i18n.I18n;
/**
* Le handler de l'ui principale.
@@ -49,7 +51,9 @@
*/
public class DemoUIHandler { //implements JAXXHelp {
- /** to use log facility, just put in your code: log.info(\"...\"); */
+ /**
+ * to use log facility, just put in your code: log.info(\"...\");
+ */
static private Log log = LogFactory.getLog(DemoUIHandler.class);
static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = jaxx.runtime.Util.newContextEntryDef("mainui", DemoUI.class);
@@ -78,6 +82,10 @@
// share config
context.add(rootContext.getContextValue(DemoConfig.class));
+ // share a unique DecoratorProviderListCellRenderer
+ DecoratorProvider decoratorProvider = rootContext.getContextValue(DecoratorProvider.class);
+ context.add(new DecoratorProviderListCellRenderer(decoratorProvider));
+
// instanciate ui
DemoUI ui = new DemoUI(context);
@@ -145,7 +153,7 @@
// scan main ui
DemoUI ui = getUI(rootContext);
- NavigationTreeNode node = null;
+ NavigationTreeNode node;
String nodePath = null;
if (ui != null) {
@@ -181,7 +189,7 @@
* mode console (c'est à dire en mode plein écran exclusif), sinon on
* passe en mode fenetré normal.
*
- * @param context l'ui principale de l'application
+ * @param context l'ui principale de l'application
* @param fullscreen le nouvel état requis.
*/
public void changeScreen(JAXXContext context, final boolean fullscreen) {
@@ -250,7 +258,7 @@
ConfigUIBuilder.showConfigUI(configUI, ui, false);
}
-// @Override
+ // @Override
public void showHelp(JAXXContext context, String helpId) {
// DemoUI mainUI = getUI(context);
// ObserveHelpBroker helpBroker = context.getContextValue(ObserveHelpBroker.class);
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java 2009-10-29 14:55:21 UTC (rev 1616)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/RunDemo.java 2009-10-29 16:48:10 UTC (rev 1617)
@@ -20,7 +20,11 @@
*/
package jaxx.demo;
+import jaxx.demo.component.jaxx.navigation.Movie;
+import jaxx.demo.component.jaxx.navigation.People;
+import jaxx.runtime.SwingUtil;
import jaxx.runtime.context.DefaultApplicationContext;
+import jaxx.runtime.decorator.DecoratorProvider;
import jaxx.runtime.swing.ErrorDialogUI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -28,10 +32,7 @@
import static org.nuiton.i18n.I18n._;
import org.nuiton.util.StringUtil;
-import jaxx.runtime.SwingUtil;
-
/**
- *
* @author chemit
*/
public class RunDemo {
@@ -41,17 +42,13 @@
*/
private static Log log = LogFactory.getLog(RunDemo.class);
/**
- * When application was started
- */
- private static long startingTime = System.nanoTime();
- /**
* The singleton instance of the main context
*/
protected static DefaultApplicationContext context;
public static void main(String[] args) {
- startingTime = System.nanoTime();
+ long startingTime = System.nanoTime();
log.info("JAXX Demo start at " + new java.util.Date() + " args: " + java.util.Arrays.toString(args));
try {
@@ -81,6 +78,20 @@
// share the config
rootContext.setContextValue(config);
+ // init decorator provider
+ DecoratorProvider p = new DecoratorProvider() {
+
+ @Override
+ protected void loadDecorators() {
+
+ registerMultiJXPathDecorator(Movie.class, "${title}$s##${year}$s", "##", " - ");
+ registerMultiJXPathDecorator(People.class, "${firstName}$s##${lastName}$s", "##", " ");
+ }
+ };
+
+ // share the decorator provider
+ rootContext.setContextValue(p);
+
long t00 = System.nanoTime();
// init i18n
@@ -141,6 +152,7 @@
* l'context partagée.
* <p/>
* Note : Cette méthode ne peut être appelée qu'une seule fois.
+ *
* @return l'context partagée
* @throws IllegalStateException si un contexte applicatif a déja été positionné.
*/
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2009-10-29 14:55:21 UTC (rev 1616)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2009-10-29 16:48:10 UTC (rev 1617)
@@ -20,10 +20,10 @@
*/
package jaxx.demo.component.jaxx.navigation;
-import jaxx.runtime.JAXXObject;
import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.Util;
import jaxx.runtime.context.JAXXContextEntryDef;
-import jaxx.runtime.decorator.DecoratorUtils;
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
import jaxx.runtime.swing.navigation.NavigationTreeHandler;
@@ -34,11 +34,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
+import javax.swing.*;
import java.util.Arrays;
import java.util.List;
-import javax.swing.JPanel;
-import jaxx.runtime.Util;
/**
*
@@ -47,17 +45,17 @@
*/
public class FullNavigationTreeHelper extends NavigationTreeHelper {
- static {
- // register decorator one for all
-
- DecoratorUtils.register(
- Movie.class.getSimpleName(),
- DecoratorUtils.newMultiJXPathDecorator(Movie.class, "${title}$s##${year}$s", "##", " - "));
-
- DecoratorUtils.register(
- People.class.getSimpleName(),
- DecoratorUtils.newMultiJXPathDecorator(People.class, "${firstName}$s##${lastName}$s", "##", " "));
- }
+// static {
+// // register decorator one for all
+//
+// DecoratorUtils.register(
+// Movie.class.getSimpleName(),
+// DecoratorUtils.newMultiJXPathDecorator(Movie.class, "${title}$s##${year}$s", "##", " - "));
+//
+// DecoratorUtils.register(
+// People.class.getSimpleName(),
+// DecoratorUtils.newMultiJXPathDecorator(People.class, "${firstName}$s##${lastName}$s", "##", " "));
+// }
/**
* Logger
*/
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2009-10-29 14:55:21 UTC (rev 1616)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2009-10-29 16:48:10 UTC (rev 1617)
@@ -20,14 +20,17 @@
*/
package jaxx.demo.component.jaxx.navigation;
+import jaxx.demo.component.jaxx.navigation.content.ActorContentUI;
+import jaxx.demo.component.jaxx.navigation.content.ActorsContentUI;
+import jaxx.demo.component.jaxx.navigation.content.MovieContentUI;
+import jaxx.demo.component.jaxx.navigation.content.MoviesContentUI;
import jaxx.runtime.JAXXContext;
import jaxx.runtime.decorator.Decorator;
-import jaxx.runtime.decorator.DecoratorUtils;
+import jaxx.runtime.decorator.DecoratorProvider;
import jaxx.runtime.swing.navigation.NavigationTreeModelBuilder;
import jaxx.runtime.swing.navigation.NavigationTreeNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import jaxx.demo.component.jaxx.navigation.content.*;
import static org.nuiton.i18n.I18n._;
import java.util.List;
@@ -39,7 +42,6 @@
*/
public class FullNavigationTreeModelBuilder extends NavigationTreeModelBuilder {
- private static final long serialVersionUID = 1l;
/**
* Logger
*/
@@ -67,8 +69,9 @@
}
- Decorator<Movie> mDecorator = DecoratorUtils.get(Movie.class.getSimpleName());
- Decorator<People> pDecorator = DecoratorUtils.get(People.class.getSimpleName());
+ DecoratorProvider decoratorProvider = getModel().getContext().getContextValue(DecoratorProvider.class);
+ Decorator<Movie> mDecorator = decoratorProvider.getDecorator(Movie.class);
+ Decorator<People> pDecorator = decoratorProvider.getDecorator(People.class);
// construction du noeud root
// il ne contient pas de context et ne sera pas visible
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2009-10-29 14:55:21 UTC (rev 1616)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2009-10-29 16:48:10 UTC (rev 1617)
@@ -23,8 +23,7 @@
<script><![CDATA[
import jaxx.runtime.SwingUtil;
import jaxx.demo.component.jaxx.navigation.*;
-import jaxx.runtime.decorator.DecoratorUtils;
-import jaxx.runtime.swing.renderer.MultiDecoratorListCellRenderer;
+import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer;
import jaxx.runtime.swing.navigation.NavigationTreeNode;
@Override
@@ -56,7 +55,7 @@
columnHeaderView='{toolbar}'
horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
- <JList id='list' model='{new DefaultListModel()}' cellRenderer='{getContextValue(MultiDecoratorListCellRenderer.class)}'/>
+ <JList id='list' model='{new DefaultListModel()}' cellRenderer='{getContextValue(DecoratorProviderListCellRenderer.class)}'/>
</JScrollPane>
<JToolBar id='toolbar' constraints='BorderLayout.SOUTH'
floatable='false'>
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2009-10-29 14:55:21 UTC (rev 1616)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2009-10-29 16:48:10 UTC (rev 1617)
@@ -26,18 +26,9 @@
<script><![CDATA[
import jaxx.runtime.SwingUtil;
import jaxx.demo.component.jaxx.navigation.*;
-import jaxx.runtime.decorator.DecoratorUtils;
-import jaxx.runtime.decorator.MultiJXPathDecorator;
-import jaxx.runtime.swing.renderer.MultiDecoratorListCellRenderer;
import jaxx.runtime.swing.navigation.NavigationTreeNode;
import jaxx.runtime.swing.navigation.NavigationContentUI;
-// init shared list decorator
-MultiJXPathDecorator<?> d0 = (MultiJXPathDecorator<?>)DecoratorUtils.get(People.class.getSimpleName());
-MultiJXPathDecorator<?> d1 = (MultiJXPathDecorator<?>)DecoratorUtils.get(Movie.class.getSimpleName());
-MultiDecoratorListCellRenderer r = new MultiDecoratorListCellRenderer(d0,d1);
-setContextValue(r);
-
ContentUIHandler getHandler() {
return getContextValue(ContentUIHandler.class);
}
Modified: branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx
===================================================================
--- branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2009-10-29 14:55:21 UTC (rev 1616)
+++ branches/jaxx-2.X/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2009-10-29 16:48:10 UTC (rev 1617)
@@ -23,8 +23,7 @@
<script><![CDATA[
import jaxx.runtime.SwingUtil;
import jaxx.demo.component.jaxx.navigation.*;
-import jaxx.runtime.decorator.DecoratorUtils;
-import jaxx.runtime.swing.renderer.MultiDecoratorListCellRenderer;
+import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer;
import jaxx.runtime.swing.navigation.NavigationTreeNode;
@Override
@@ -56,7 +55,7 @@
columnHeaderView='{toolbar}'
horizontalScrollBarPolicy='{JScrollPane.HORIZONTAL_SCROLLBAR_NEVER}'
verticalScrollBarPolicy='{JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED}'>
- <JList id='list' model='{new DefaultListModel()}' cellRenderer='{getContextValue(MultiDecoratorListCellRenderer.class)}'/>
+ <JList id='list' model='{new DefaultListModel()}' cellRenderer='{getContextValue(DecoratorProviderListCellRenderer.class)}'/>
</JScrollPane>
<JToolBar id='toolbar' opaque='false' constraints='BorderLayout.SOUTH'
floatable='false'>
1
0
r1616 - branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer
by tchemit@users.nuiton.org 29 Oct '09
by tchemit@users.nuiton.org 29 Oct '09
29 Oct '09
Author: tchemit
Date: 2009-10-29 15:55:21 +0100 (Thu, 29 Oct 2009)
New Revision: 1616
Added:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderTableCellRenderer.java
Log:
add a DecoratorProviderTableCellRenderer
Added: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderTableCellRenderer.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderTableCellRenderer.java (rev 0)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderTableCellRenderer.java 2009-10-29 14:55:21 UTC (rev 1616)
@@ -0,0 +1,56 @@
+package jaxx.runtime.swing.renderer;
+
+import jaxx.runtime.decorator.Decorator;
+import jaxx.runtime.decorator.DecoratorProvider;
+
+import javax.swing.*;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.TableCellRenderer;
+import java.awt.*;
+
+/**
+ * A {@link TableCellRenderer} which use decorators from the {@link #provider} to obtain the text to display.
+ * <p/>
+ * The interest of this renderer is to define a unique renderer for your application (put it in JAXXContext)
+ * and then use it simply :)
+ * <p/>
+ * User: chemit
+ * Date: 29 oct. 2009
+ * Time: 03:00:53
+ *
+ * @see DecoratorProvider
+ * @since 2.0.0
+ */
+public class DecoratorProviderTableCellRenderer implements TableCellRenderer {
+
+ /**
+ * Delegate cell renderer
+ */
+ protected TableCellRenderer delegate;
+
+ /**
+ * provider of decorators
+ */
+ protected DecoratorProvider provider;
+
+ public DecoratorProviderTableCellRenderer(DecoratorProvider provider) {
+ this(new DefaultTableCellRenderer(), provider);
+ }
+
+ public DecoratorProviderTableCellRenderer(TableCellRenderer delegate, DecoratorProvider provider) {
+ this.delegate = delegate;
+ this.provider = provider;
+ }
+
+ @Override
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasfocus, int row, int column) {
+ if (value != null) {
+ Decorator<?> decorator = provider.getDecorator(value);
+
+ if (decorator != null) {
+ value = decorator.toString(value);
+ }
+ }
+ return delegate.getTableCellRendererComponent(table, value, isSelected, hasfocus, row, column);
+ }
+}
\ No newline at end of file
Property changes on: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderTableCellRenderer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
1
0
r1615 - branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer
by tchemit@users.nuiton.org 29 Oct '09
by tchemit@users.nuiton.org 29 Oct '09
29 Oct '09
Author: tchemit
Date: 2009-10-29 03:08:58 +0100 (Thu, 29 Oct 2009)
New Revision: 1615
Added:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderListCellRenderer.java
Log:
add a DecoratorProviderListCellRenderer
Added: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderListCellRenderer.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderListCellRenderer.java (rev 0)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderListCellRenderer.java 2009-10-29 02:08:58 UTC (rev 1615)
@@ -0,0 +1,53 @@
+package jaxx.runtime.swing.renderer;
+
+import jaxx.runtime.decorator.Decorator;
+import jaxx.runtime.decorator.DecoratorProvider;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * A {@link ListCellRenderer} which use decorators from the {@link #provider} to obtain the text to display.
+ *
+ * The interest of this renderer is to define a unique renderer for your application (put it in JAXXContext)
+ * and then use it simply :)
+ *
+ * User: chemit
+ * Date: 29 oct. 2009
+ * Time: 03:00:53
+ * @since 2.0.0
+ * @see DecoratorProvider
+ */
+public class DecoratorProviderListCellRenderer implements ListCellRenderer {
+
+ /**
+ * Delegate cell renderer
+ */
+ protected ListCellRenderer delegate;
+
+ /**
+ * provider of decorators
+ */
+ protected DecoratorProvider provider;
+
+ public DecoratorProviderListCellRenderer(DecoratorProvider provider) {
+ this(new DefaultListCellRenderer(), provider);
+ }
+
+ public DecoratorProviderListCellRenderer(ListCellRenderer delegate, DecoratorProvider provider) {
+ this.delegate = delegate;
+ this.provider = provider;
+ }
+
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ if (value != null) {
+ Decorator<?> decorator = provider.getDecorator(value);
+
+ if (decorator != null) {
+ value = decorator.toString(value);
+ }
+ }
+ return delegate.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
+ }
+}
Property changes on: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/swing/renderer/DecoratorProviderListCellRenderer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
1
0
r1614 - in branches/jaxx-2.X/jaxx-runtime: . src/main/java/jaxx/runtime/decorator src/test/java/jaxx/runtime/decorator
by tchemit@users.nuiton.org 29 Oct '09
by tchemit@users.nuiton.org 29 Oct '09
29 Oct '09
Author: tchemit
Date: 2009-10-29 02:42:54 +0100 (Thu, 29 Oct 2009)
New Revision: 1614
Added:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorProvider.java
branches/jaxx-2.X/jaxx-runtime/src/test/java/jaxx/runtime/decorator/DecoratorProviderTest.java
Modified:
branches/jaxx-2.X/jaxx-runtime/
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/JXPathDecorator.java
Log:
- add a DecoratorProvider to store your decorators
- deprecate all states in DecoratorUtils (use a DecoratorProvider to store decorators)
Property changes on: branches/jaxx-2.X/jaxx-runtime
___________________________________________________________________
Modified: svn:ignore
- target
*.log
*.iml
+ target
*.log
Added: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorProvider.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorProvider.java (rev 0)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorProvider.java 2009-10-29 01:42:54 UTC (rev 1614)
@@ -0,0 +1,226 @@
+package jaxx.runtime.decorator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A decorator provider.
+ * <p/>
+ * Implements the method {@link #loadDecorators()} to fill the decorators availables.
+ * <p/>
+ * Then can obtain decorator via the methods {@code getDecorator(...)}
+ * <p/>
+ * User: chemit
+ * Date: 28 oct. 2009
+ * Time: 19:40:48
+ */
+public abstract class DecoratorProvider {
+
+ /**
+ * Logger
+ */
+ private static final Log log = LogFactory.getLog(JXPathDecorator.class);
+ /**
+ * Registred decorators.
+ */
+ protected List<DecoratorContext<?>> decorators;
+
+ public DecoratorProvider() {
+ loadDecorators();
+ }
+
+ /**
+ * Load all decorators of the provider
+ */
+ protected abstract void loadDecorators();
+
+ /**
+ * Obtain a decorator for the given object.
+ *
+ * @param object object of decorated object
+ * @param <O> object of decorated object
+ * @return the decorator or {@code null} if not found
+ */
+ @SuppressWarnings({"unchecked"})
+ public <O> Decorator<O> getDecorator(O object) {
+ return getDecorator(object, null);
+ }
+
+ /**
+ * Obtain a decorator given a object and an extra name to qualify the context.
+ *
+ * @param object object of decorated object
+ * @param name extra name to qualify the decorator to use
+ * @param <O> object of decorated object
+ * @return the decorator or {@code null} if not found
+ */
+ @SuppressWarnings({"unchecked"})
+ public <O> Decorator<O> getDecorator(O object, String name) {
+ Class<O> k = (Class<O>) object.getClass();
+ return getDecorator(k, name);
+ }
+
+ /**
+ * Obtain a decorator given a type.
+ *
+ * @param type type of decorated object
+ * @param <O> type of decorated object
+ * @return the decorator or {@code null} if not found
+ */
+ public <O> Decorator<O> getDecorator(Class<O> type) {
+ return getDecorator(type, null);
+ }
+
+ /**
+ * Obtain a decorator given a type and a extra name.
+ *
+ * @param type type of decorated object
+ * @param name extra name to qualify the decorator to use
+ * @param <O> type of decorated object
+ * @return the decorator or {@code null} if not found
+ */
+ public <O> Decorator<O> getDecorator(Class<O> type, String name) {
+ DecoratorContext<O> d = getDecoratorContext(type, name);
+ return d == null ? null : d.getDecorator();
+ }
+
+ public void reload() {
+ clear();
+ loadDecorators();
+ }
+
+ public void clear() {
+ if (decorators != null) {
+ decorators.clear();
+ }
+ }
+
+ protected void registerPropertyDecorator(Class<?> klass, String expression) {
+ registerPropertyDecorator(klass, null, expression);
+ }
+
+ protected void registerJXPathDecorator(Class<?> klass, String expression) {
+ registerJXPathDecorator(klass, null, expression);
+ }
+
+ protected void registerMultiJXPathDecorator(Class<?> klass, String expression, String separator, String separatorReplacement) {
+ registerMultiJXPathDecorator(klass, null, expression, separator, separatorReplacement);
+ }
+
+ protected void registerPropertyDecorator(Class<?> klass, String name, String expression) {
+ Decorator<?> decorator = DecoratorUtils.newPropertyDecorator(klass, expression);
+ registerDecorator(name, decorator);
+ }
+
+ protected void registerJXPathDecorator(Class<?> klass, String name, String expression) {
+ Decorator<?> decorator = DecoratorUtils.newJXPathDecorator(klass, expression);
+ registerDecorator(name, decorator);
+ }
+
+ protected void registerMultiJXPathDecorator(Class<?> klass, String name, String expression, String separator, String separatorReplacement) {
+ Decorator<?> decorator = DecoratorUtils.newMultiJXPathDecorator(klass, expression, separator, separatorReplacement);
+ registerDecorator(name, decorator);
+ }
+
+ protected void registerDecorator(Decorator<?> decorator) {
+ registerDecorator(null, decorator);
+ }
+
+ /**
+ * Register a new decorator in the cache of the provider.
+ *
+ * @param <T> type of data decorated
+ * @param context the name decorator
+ * @param decorator the decorator to register
+ */
+ protected <T> void registerDecorator(String context, Decorator<T> decorator) {
+
+ // obtain the decorator context
+ DecoratorContext<?> result = getDecoratorContext(decorator.getInternalClass(), context);
+
+ if (result != null) {
+ throw new IllegalArgumentException("there is an already register decorator with context " + result);
+ }
+
+ DecoratorContext<T> decoratorContext = new DecoratorContext<T>(context, decorator);
+ if (log.isDebugEnabled()) {
+ log.debug(decoratorContext);
+ }
+ getDecorators().add(decoratorContext);
+ }
+
+ protected List<DecoratorContext<?>> getDecorators() {
+ if (decorators == null) {
+ decorators = new ArrayList<DecoratorContext<?>>();
+ }
+ return decorators;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ protected <T> DecoratorContext<T> getDecoratorContext(Class<T> type, String context) {
+ DecoratorContext<T> result = null;
+ if (decorators != null) {
+ for (DecoratorContext<?> d : decorators) {
+ if (type == null) {
+ if (d.accept(context)) {
+ result = (DecoratorContext<T>) d;
+ break;
+ }
+ continue;
+ }
+ if (d.accept(type, context)) {
+ result = (DecoratorContext<T>) d;
+ break;
+ }
+ }
+ }
+ return result;
+ }
+
+ public static class DecoratorContext<T> {
+
+ /**
+ * the context name of the decorator
+ */
+ final String context;
+ /**
+ * the decorator
+ */
+ final Decorator<T> decorator;
+
+ public DecoratorContext(String context, Decorator<T> decorator) {
+ this.context = context;
+ this.decorator = decorator;
+ }
+
+ public String getContext() {
+ return context;
+ }
+
+ public Decorator<T> getDecorator() {
+ return decorator;
+ }
+
+ public Class<T> getType() {
+ return decorator.getInternalClass();
+ }
+
+ public boolean accept(Class<?> type, String context) {
+ boolean accept = getType().isAssignableFrom(type) && accept(context);
+ return accept;
+ }
+
+ public boolean accept(String context) {
+ return ((this.context == null && context == null) || (this.context != null && this.context.equals(context)));
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + "<type: " + getType().getName() + ", context :" + context + ">";
+ }
+ }
+
+}
Property changes on: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorProvider.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java 2009-10-28 07:54:21 UTC (rev 1613)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/DecoratorUtils.java 2009-10-29 01:42:54 UTC (rev 1614)
@@ -20,18 +20,14 @@
*/
package jaxx.runtime.decorator;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.StringTokenizer;
+import jaxx.runtime.decorator.JXPathDecorator.Context;
import jaxx.runtime.decorator.JXPathDecorator.JXPathComparator;
-import jaxx.runtime.decorator.JXPathDecorator.Context;
+import java.util.*;
+
/**
- *
* Some usefull methods on {@link Decorator} to create, decorators and obtain decorators.
- *
+ * <p/>
* To create a new decorator, use one of the methods :
* <ul>
* <li>{@link #newPropertyDecorator(Class, String)}</li>
@@ -40,7 +36,7 @@
* <li>{@link #newMultiJXPathDecorator(Class, String, String, String)})</li>
* </ul>
* <p/>
- *
+ * <p/>
* To register a new decorator, use the method {@link #register(String, Decorator)}.
* <p/>
* To obtain a registred decorator, use the method {@link #get(String)}
@@ -50,7 +46,7 @@
* To sort a list of data, using a {@link JXPathDecorator}, use the method
* {@link #sort(JXPathDecorator, List, int)}.
* <p/>
- *
+ *
* @author tony
* @since 1.7.2 (was previously {@code jaxx.runtime.DecoratorUtils})
*/
@@ -58,11 +54,13 @@
/**
* Registred decorators.
+ * @deprecated prefer use a {@link DecoratorProvider}
*/
+ @Deprecated
protected static List<DecoratorContext<?>> decorators;
/**
- * Factory method to instanciate a new {@link PropertyDecorator} for the
+ * Factory method to instanciate a new {@link PropertyDecorator} for the
* given class {@code internlaClass} and a readable property name.
*
* @param internalClass the class of the objects decorated by the new decorator
@@ -104,17 +102,17 @@
}
public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator(Class<O> internalClass,
- String expression,
- String separator)
+ String expression,
+ String separator)
throws IllegalArgumentException, NullPointerException {
return newMultiJXPathDecorator(internalClass, expression, separator, separator);
}
public static <O> MultiJXPathDecorator<O> newMultiJXPathDecorator(Class<O> internalClass,
- String expression,
- String separator,
- String separatorReplacement)
+ String expression,
+ String separator,
+ String separatorReplacement)
throws IllegalArgumentException, NullPointerException {
Context<O>[] contexts = createMultiJXPathContext(expression, separator, separatorReplacement);
@@ -122,11 +120,13 @@
return new MultiJXPathDecorator<O>(internalClass, expression, separator, separatorReplacement, contexts);
}
+ @Deprecated
public static <T> Decorator<T> get(String context) {
Decorator<T> result = get(null, context);
return result;
}
+ @Deprecated
public static <T> Decorator<T> get(Class<T> type, String context) {
DecoratorContext<T> decoratorContext = getDecoratorContext(type, context);
Decorator<T> result = decoratorContext == null ? null : decoratorContext.getDecorator();
@@ -136,10 +136,11 @@
/**
* Register a new decorator in the cache.
*
- * @param <T> type of data decorated
- * @param context the name decorator
+ * @param <T> type of data decorated
+ * @param context the name decorator
* @param decorator the decorator to register
*/
+ @Deprecated
public static <T> void register(String context, Decorator<T> decorator) {
DecoratorContext<T> result = getDecoratorContext(decorator.getInternalClass(), context);
@@ -154,6 +155,7 @@
decorators.add(new DecoratorContext<T>(context, decorator));
}
+ @Deprecated
public static void clear() {
if (decorators != null) {
decorators.clear();
@@ -164,7 +166,7 @@
* Sort a list of data based on the first token property of a given context
* in a given decorator.
*
- * @param <O> type of data to sort
+ * @param <O> type of data to sort
* @param decorator the decorator to use to sort
* @param datas the list of data to sort
* @param pos the index of context to used in decorator to obtain sorted property.
@@ -188,6 +190,7 @@
}
@SuppressWarnings({"unchecked"})
+ @Deprecated
protected static <T> DecoratorContext<T> getDecoratorContext(Class<T> type, String context) {
DecoratorContext<T> result = null;
if (decorators != null) {
@@ -208,9 +211,16 @@
return result;
}
+ @Deprecated
public static class DecoratorContext<T> {
+ /**
+ * the context name of the decorator
+ */
final String context;
+ /**
+ * the decorator
+ */
final Decorator<T> decorator;
public DecoratorContext(String context, Decorator<T> decorator) {
Modified: branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/JXPathDecorator.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/JXPathDecorator.java 2009-10-28 07:54:21 UTC (rev 1613)
+++ branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/JXPathDecorator.java 2009-10-29 01:42:54 UTC (rev 1614)
@@ -24,14 +24,10 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
- * JXPath decorator based on {@link String#format(String, Object[])} method.
+ * JXPath decorator based on {@link String#format(String, Object...)} method.
* <p/>
* To use it, give to him a expression where all jxpath to apply on bean are boxed in <code>${}</code>.
* <p/>
@@ -46,10 +42,10 @@
* assert "expr = %1$s" == d.toString(d);
* </pre>
*
+ * @author chemit
* @param <O> type of data to decorate
- * @author chemit
* @see Decorator
- * @since 1.7.2 (was previously {@code jaxx.runtime.JXPathDecorat})
+ * @since 1.7.2 (was previously {@code jaxx.runtime.JXPathDecorator})
*/
public class JXPathDecorator<O> extends Decorator<O> {
@@ -58,11 +54,17 @@
* Logger
*/
private static final Log log = LogFactory.getLog(JXPathDecorator.class);
- /** the computed context of the decorator */
+ /**
+ * the computed context of the decorator
+ */
protected Context<O> context;
- /** nb jxpath tokens to compute */
+ /**
+ * nb jxpath tokens to compute
+ */
protected int nbToken;
- /** the initial expression used to compute the decorator context. */
+ /**
+ * the initial expression used to compute the decorator context.
+ */
protected String initialExpression;
protected JXPathDecorator(Class<O> internalClass, String expression, Context<O> context) throws IllegalArgumentException, NullPointerException {
@@ -174,11 +176,13 @@
public static class Context<O> implements java.io.Serializable {
/**
- * expression to format using {@link String#format(String, Object[])}, all variables are compute
+ * expression to format using {@link String#format(String, Object...)}, all variables are compute
* using using the jxpath tokens.
*/
protected String expression;
- /** list of jxpath tokens to apply on expression */
+ /**
+ * list of jxpath tokens to apply on expression
+ */
protected String[] tokens;
protected transient Comparator<O> comparator;
private static final long serialVersionUID = 1L;
Added: branches/jaxx-2.X/jaxx-runtime/src/test/java/jaxx/runtime/decorator/DecoratorProviderTest.java
===================================================================
--- branches/jaxx-2.X/jaxx-runtime/src/test/java/jaxx/runtime/decorator/DecoratorProviderTest.java (rev 0)
+++ branches/jaxx-2.X/jaxx-runtime/src/test/java/jaxx/runtime/decorator/DecoratorProviderTest.java 2009-10-29 01:42:54 UTC (rev 1614)
@@ -0,0 +1,153 @@
+package jaxx.runtime.decorator;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.File;
+
+/**
+ * User: chemit
+ * Date: 28 oct. 2009
+ * Time: 21:28:46
+ */
+public class DecoratorProviderTest {
+ private static final String BY_NAME = "name";
+
+ static class MyDecoratorProvider extends DecoratorProvider {
+
+ @Override
+ protected void loadDecorators() {
+
+ registerPropertyDecorator(File.class, "name");
+ registerPropertyDecorator(File.class, BY_NAME, "parent");
+
+
+ registerJXPathDecorator(Class.class, "${simpleName}$s");
+ registerJXPathDecorator(Class.class, BY_NAME, "${name}$s");
+
+ registerMultiJXPathDecorator(Data.class, "${name}$s", "-", " ");
+ registerMultiJXPathDecorator(Data.class, BY_NAME, "${pos}$d", "-", " ");
+ }
+ }
+
+ static DecoratorProvider provider;
+
+ @BeforeClass
+ public static void beforeTest() throws Exception {
+ provider = new MyDecoratorProvider();
+ }
+
+ @Test
+ public void testGetDecoratorByObject() throws Exception {
+
+ File f = new File("myFile");
+ Data d = new Data(0, "name");
+ Class<?> k = File.class;
+
+ Decorator<File> fileDecorator = provider.getDecorator(f);
+ Assert.assertNotNull(fileDecorator);
+ Assert.assertEquals(File.class, fileDecorator.getInternalClass());
+ Assert.assertEquals("myFile", fileDecorator.toString(f));
+
+ Decorator<?> classDecorator = provider.getDecorator(Class.class);
+ Assert.assertNotNull(classDecorator);
+ Assert.assertEquals(Class.class, classDecorator.getInternalClass());
+ Assert.assertEquals("File", classDecorator.toString(k));
+
+ Decorator<Data> dataDecorator = provider.getDecorator(d);
+ Assert.assertNotNull(dataDecorator);
+ Assert.assertEquals(Data.class, dataDecorator.getInternalClass());
+ Assert.assertEquals("name", dataDecorator.toString(d));
+ }
+
+ @Test
+ public void testGetDecoratorByObjectAndName() throws Exception {
+
+ File f = new File("myFile");
+ Data d = new Data(0, "name");
+ Class<?> k = File.class;
+
+ Decorator<File> fileDecorator = provider.getDecorator(f, BY_NAME);
+ Assert.assertNotNull(fileDecorator);
+ Assert.assertEquals(File.class, fileDecorator.getInternalClass());
+ Assert.assertEquals("null", fileDecorator.toString(f));
+
+ Decorator<Class> classDecorator = provider.getDecorator(Class.class, BY_NAME);
+ Assert.assertNotNull(classDecorator);
+ Assert.assertEquals(Class.class, classDecorator.getInternalClass());
+ Assert.assertEquals("java.io.File", classDecorator.toString(k));
+
+
+ Decorator<Data> dataDecorator = provider.getDecorator(d, BY_NAME);
+ Assert.assertNotNull(dataDecorator);
+ Assert.assertEquals(Data.class, dataDecorator.getInternalClass());
+ Assert.assertEquals("0", dataDecorator.toString(d));
+ }
+
+ @Test
+ public void testGetDecoratorByType() throws Exception {
+
+ File f = new File("myFile");
+ Data d = new Data(0, "name");
+ Class<?> k = File.class;
+
+ Decorator<File> fileDecorator = provider.getDecorator(File.class);
+ Assert.assertNotNull(fileDecorator);
+ Assert.assertEquals(File.class, fileDecorator.getInternalClass());
+ Assert.assertEquals("myFile", fileDecorator.toString(f));
+
+ Decorator<Class> classDecorator = provider.getDecorator(Class.class);
+ Assert.assertNotNull(classDecorator);
+ Assert.assertEquals(Class.class, classDecorator.getInternalClass());
+ Assert.assertEquals("File", classDecorator.toString(k));
+
+ Decorator<Data> dataDecorator = provider.getDecorator(Data.class);
+ Assert.assertNotNull(dataDecorator);
+ Assert.assertEquals(Data.class, dataDecorator.getInternalClass());
+ Assert.assertEquals("name", dataDecorator.toString(d));
+ }
+
+ @Test
+ public void testGetDecoratorByTypeAndName() throws Exception {
+ File f = new File("myFile");
+ Data d = new Data(0, "name");
+ Class<?> k = File.class;
+
+ Decorator<File> fileDecorator = provider.getDecorator(File.class, BY_NAME);
+ Assert.assertNotNull(fileDecorator);
+ Assert.assertEquals(File.class, fileDecorator.getInternalClass());
+ Assert.assertEquals("null", fileDecorator.toString(f));
+
+ Decorator<Class> classDecorator = provider.getDecorator(Class.class, BY_NAME);
+ Assert.assertNotNull(classDecorator);
+ Assert.assertEquals(Class.class, classDecorator.getInternalClass());
+ Assert.assertEquals("java.io.File", classDecorator.toString(k));
+
+
+ Decorator<Data> dataDecorator = provider.getDecorator(Data.class, BY_NAME);
+ Assert.assertNotNull(dataDecorator);
+ Assert.assertEquals(Data.class, dataDecorator.getInternalClass());
+ Assert.assertEquals("0", dataDecorator.toString(d));
+ }
+
+
+ @Test
+ public void testReload() throws Exception {
+
+ int nb = provider.getDecorators().size();
+ Assert.assertTrue(nb > 0);
+
+ provider.reload();
+
+ Assert.assertEquals(nb, provider.getDecorators().size());
+ }
+
+ @Test
+ public void testClear() throws Exception {
+ provider.clear();
+
+ Assert.assertTrue(provider.getDecorators().isEmpty());
+ }
+
+}
Property changes on: branches/jaxx-2.X/jaxx-runtime/src/test/java/jaxx/runtime/decorator/DecoratorProviderTest.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
1
0
r1613 - branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler
by tchemit@users.nuiton.org 28 Oct '09
by tchemit@users.nuiton.org 28 Oct '09
28 Oct '09
Author: tchemit
Date: 2009-10-28 08:54:21 +0100 (Wed, 28 Oct 2009)
New Revision: 1613
Removed:
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataBinding.java
branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataSource.java
Log:
remove binding from jaxx.compiler package
Deleted: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataBinding.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataBinding.java 2009-10-28 07:51:37 UTC (rev 1612)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataBinding.java 2009-10-28 07:54:21 UTC (rev 1613)
@@ -1,119 +0,0 @@
-/*
- * *##%
- * JAXX Compiler
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.compiler;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Represents a data binding in a JAXX file. <code>DataBinding</code> uses
- * {@link DataSource} to track changes to a source expression and update
- * the destination.
- */
-public class DataBinding {
-
- /**
- * Logger
- */
- protected static final Log log = LogFactory.getLog(DataBinding.class);
- /**
- * Id of the data binding
- */
- private String id;
- /**
- * source of the data binding
- */
- private String source;
- /**
- * A Java snippet which will cause the destination property to be updated with the current value of
- * the binding.
- */
- private String assignment;
-
- /**
- * Creates a new data binding.
- *
- * @param source the Java source code for the data binding expression
- * @param dest the data binding destination in the form <code><id>.<propertyName></code>
- * @param assignment Java snippet which will cause the destination property to be updated with the current value of the binding
- */
- public DataBinding(String source, String dest, String assignment) {
- this.id = dest;
- this.source = source;
- this.assignment = assignment;
- if (log.isDebugEnabled()) {
- log.debug("id=" + id + " assignement=" + assignment + " source=" + source);
- }
- }
-
- public String getId() {
- return id;
- }
-
- /**
- * Compiles the data binding expression. This method calls methods in
- * <code>JAXXCompiler</code> to add the Java code that performs the data
- * binding setup.
- *
- * @param compiler compiler which includes the data binding
- * @param quickNoDependencies true to optimize bindings with no dependencies by simply running them at startup time
- * @return <code>true</code> if the expression has dependencies, <code>false</code> otherwise
- * @throws CompilerException if a compilation error occurs
- */
- public boolean compile(JAXXCompiler compiler, boolean quickNoDependencies) throws CompilerException {
-
- DataSource dataSource = new DataSource(id, source, compiler);
-
- // handles all of the listener additions
- //TC-20091026 use 'this' instead of root object javaCode
-// boolean result = dataSource.compile("new jaxx.runtime.DataBindingListener(" + compiler.getRootObject().getJavaCode() + ", " + compiler.getJavaCode(id) + ")");
- boolean result = dataSource.compile("new jaxx.runtime.DataBindingListener(this, " + compiler.getJavaCode(id) + ")");
-
- String eol = JAXXCompiler.getLineSeparator();
- if (!result && quickNoDependencies) {
- // layout is specially handled early in the chain
- if (!id.endsWith(".layout")) {
- compiler.appendInitDataBindings(assignment + eol);
- }
- return false; // no dependencies, just a static expression
- }
- if (compiler.hasProcessDataBinding()) {
- compiler.appendProcessDataBinding(" else ");
- } else {
- compiler.appendProcessDataBinding(" ");
- }
- compiler.appendProcessDataBinding("if (" + compiler.getJavaCode(id) + ".equals($dest)) {" + eol);
- String objectCode = dataSource.getObjectCode();
- //TC-20091026 no need to test objectCode not null if on root object
-// boolean needTest = objectCode != null;
- boolean needTest = objectCode != null && !compiler.getRootObject().getId().equals(objectCode);
- if (needTest) {
- compiler.appendProcessDataBinding(" if (" + objectCode + " != null) {" + eol);
- compiler.appendProcessDataBinding(" ");
- }
- compiler.appendProcessDataBinding(" " + assignment.trim());
- if (needTest) {
- compiler.appendProcessDataBinding(eol + " }");
- }
- compiler.appendProcessDataBinding(eol + " }");
- return true;
- }
-}
Deleted: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataSource.java
===================================================================
--- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataSource.java 2009-10-28 07:51:37 UTC (rev 1612)
+++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/DataSource.java 2009-10-28 07:54:21 UTC (rev 1613)
@@ -1,485 +0,0 @@
-/*
- * *##%
- * JAXX Compiler
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.compiler;
-
-import jaxx.compiler.java.JavaField;
-import jaxx.compiler.java.parser.JavaParser;
-import jaxx.compiler.java.parser.JavaParserConstants;
-import jaxx.compiler.java.parser.JavaParserTreeConstants;
-import jaxx.compiler.java.parser.SimpleNode;
-import jaxx.compiler.reflect.ClassDescriptor;
-import jaxx.compiler.reflect.ClassDescriptorLoader;
-import jaxx.compiler.reflect.FieldDescriptor;
-import jaxx.compiler.reflect.MethodDescriptor;
-import jaxx.compiler.tags.DefaultObjectHandler;
-import jaxx.compiler.tags.TagManager;
-import jaxx.compiler.types.TypeManager;
-
-import java.beans.Introspector;
-import java.beans.PropertyChangeListener;
-import java.io.StringReader;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * Represents a Java expression which fires a <code>PropertyChangeEvent</code> when it can be
- * determined that its value may have changed. Events are fired on a "best effort" basis, and events
- * may either be fired too often (the value has not actually changed) or not often enough (the value
- * changed but no event was fired).
- */
-public class DataSource {
-
- /**
- * type attached to "null" constants in parsed expressions
- */
- private class NULL {
- }
- /**
- * id of data source
- */
- private String id;
- /**
- * The Java source code for the expression.
- */
- private String source;
- /**
- * The current <code>JAXXCompiler</code>.
- */
- private JAXXCompiler compiler;
- /**
- * List of symbols which this data source expression depends on.
- */
- private List<String> dependencySymbols = new ArrayList<String>();
- /**
- *
- */
- private StringBuffer addListenerCode = new StringBuffer();
- /**
- *
- */
- private StringBuffer removeListenerCode = new StringBuffer();
- /**
- *
- */
- private boolean compiled;
- /**
- * the delegate of property to be required
- */
- private String objectCode;
-
- /**
- * Creates a new data source. After creating a <code>DataSource</code>, use {@link #compile}
- * to cause it to function at runtime.
- *
- * @param id the DataSource's id
- * @param source the Java source code for the data source expression
- * @param compiler the current <code>JAXXCompiler</code>
- */
- public DataSource(String id, String source, JAXXCompiler compiler) {
- this.id = id;
- this.source = source;
- this.compiler = compiler;
- }
-
- public String getId() {
- return id;
- }
-
- public String getSource() {
- return source;
- }
-
- public String getObjectCode() {
- return objectCode;
- }
-
- /**
- * Compiles the data source expression and listener. This method calls methods in <code>JAXXCompiler</code>
- * to add the Java code that performs the data source setup. Adding listeners to <code>DataSource</code> is
- * slightly more complicated than with ordinary classes, because <code>DataSource</code> only exists at compile
- * time. You must pass in a Java expression which evaluates to a <code>PropertyChangeListener</code>; this
- * expression will be compiled and evaluated at runtime to yield the <code>DataSource's</code> listener.
- *
- * @param propertyChangeListenerCode Java code snippet which evaluates to a <code>PropertyChangeListener</code>
- * @return <code>true</code> if the expression has dependencies, <code>false</code> otherwise
- * @throws CompilerException if a compilation error occurs
- * @throws IllegalStateException if data source was already compiled
- */
- public boolean compile(String propertyChangeListenerCode) throws CompilerException, IllegalStateException {
- if (compiled) {
- throw new IllegalStateException(this + " has already been compiled");
- }
- String autoId = compiler.getAutoId(ClassDescriptorLoader.getClassDescriptor(getClass()));
- JavaParser p = new JavaParser(new StringReader(source + ";"));
- while (!p.Line()) {
- SimpleNode node = p.popNode();
- scanNode(node, autoId);
- }
-
- if (dependencySymbols.size() > 0) {
- //TC 20081108 prefer add a real JavaField instead of raw code
- //compiler.appendBodyCode("private PropertyChangeListener " + id + " = " + propertyChangeListenerCode + ";\n");
- compiler.addSimpleField(new JavaField(Modifier.PRIVATE, PropertyChangeListener.class.getSimpleName(), autoId, false, propertyChangeListenerCode));
- }
-
- compileListeners();
- compiled = true;
-
- return dependencySymbols.size() > 0;
- }
-
- /** @return a list of symbols on which this data source depends. */
- public Collection<String> getDependencies() {
- return Collections.unmodifiableList(dependencySymbols);
- }
-
- /**
- * Examines a node to identify any dependencies it contains.
- *
- * @param node node to scan
- * @param listenerId id of listener
- * @throws CompilerException ?
- */
- private void scanNode(SimpleNode node, String listenerId) throws CompilerException {
- switch (node.getId()) {
- case JavaParserTreeConstants.JJTMETHODDECLARATION:
- break;
- case JavaParserTreeConstants.JJTFIELDDECLARATION:
- break;
-
- default:
- int count = node.jjtGetNumChildren();
- for (int i = 0; i < count; i++) {
- scanNode(node.getChild(i), listenerId);
- }
- determineNodeType(node, listenerId);
- }
- }
-
- private ClassDescriptor determineLiteralType(SimpleNode node) {
- assert node.getId() == JavaParserTreeConstants.JJTLITERAL;
- if (node.jjtGetNumChildren() == 1) {
- int childId = node.getChild(0).getId();
- if (childId == JavaParserTreeConstants.JJTBOOLEANLITERAL) {
- return ClassDescriptorLoader.getClassDescriptor(boolean.class);
- }
- if (childId == JavaParserTreeConstants.JJTNULLLITERAL) {
- return ClassDescriptorLoader.getClassDescriptor(NULL.class);
- }
- throw new RuntimeException("Expected BooleanLiteral or NullLiteral, found " + JavaParserTreeConstants.jjtNodeName[childId]);
- }
- int nodeId = node.firstToken.kind;
- switch (nodeId) {
- case JavaParserConstants.INTEGER_LITERAL:
- if (node.firstToken.image.toLowerCase().endsWith("l")) {
- return ClassDescriptorLoader.getClassDescriptor(long.class);
- }
- return ClassDescriptorLoader.getClassDescriptor(int.class);
- case JavaParserConstants.CHARACTER_LITERAL:
- return ClassDescriptorLoader.getClassDescriptor(char.class);
- case JavaParserConstants.FLOATING_POINT_LITERAL:
- if (node.firstToken.image.toLowerCase().endsWith("f")) {
- return ClassDescriptorLoader.getClassDescriptor(float.class);
- }
- return ClassDescriptorLoader.getClassDescriptor(double.class);
- case JavaParserConstants.STRING_LITERAL:
- return ClassDescriptorLoader.getClassDescriptor(String.class);
- default:
- throw new RuntimeException("Expected literal token, found " + JavaParserConstants.tokenImage[nodeId]);
- }
- }
-
- /**
- * Scans through a compound symbol (foo.bar.baz) to identify and track all trackable pieces of it.
- *
- * @param symbol symbol to scan
- * @param contextClass current class context
- * @param isMethod flag to search a method
- * @param listenerId id of the listener
- * @return the type of the symbol (or null if it could not be determined).
- */
- private ClassDescriptor scanCompoundSymbol(String symbol, ClassDescriptor contextClass, boolean isMethod, String listenerId) {
- String[] tokens = symbol.split("\\s*\\.\\s*");
- StringBuffer currentSymbol = new StringBuffer();
- StringBuffer tokensSeenSoFar = new StringBuffer();
- boolean accepted; // if this ends up false, it means we weren't able to figure out
- // which object the method is being invoked on
- boolean recognizeClassNames = true;
- for (int j = 0; j < tokens.length - (isMethod ? 1 : 0); j++) {
- accepted = false;
-
- if (tokensSeenSoFar.length() > 0) {
- tokensSeenSoFar.append('.');
- }
- tokensSeenSoFar.append(tokens[j]);
- if (currentSymbol.length() > 0) {
- currentSymbol.append('.');
- }
- currentSymbol.append(tokens[j]);
-
- if (currentSymbol.indexOf(".") == -1) {
- String memberName = currentSymbol.toString();
- CompiledObject object = compiler.getCompiledObject(memberName);
- if (object != null) {
- contextClass = object.getObjectClass();
- currentSymbol.setLength(0);
- accepted = true;
- recognizeClassNames = false;
- } else {
- try {
- FieldDescriptor field = contextClass.getFieldDescriptor(memberName);
- trackMemberIfPossible(tokensSeenSoFar.toString(), contextClass, field.getName(), false, listenerId);
- contextClass = field.getType();
- currentSymbol.setLength(0);
- accepted = true;
- recognizeClassNames = false;
- } catch (NoSuchFieldException e) {
- if (j == 0 || j == 1 && tokens[0].equals(compiler.getRootObject().getId())) { // still in root context
- FieldDescriptor[] newFields = compiler.getScriptFields();
- for (FieldDescriptor newField : newFields) {
- if (newField.getName().equals(memberName)) {
- addListener(tokensSeenSoFar.toString(),
- null,
- "addPropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator(),
- "removePropertyChangeListener(\"" + memberName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator());
- contextClass = newField.getType();
- assert contextClass != null : "script field '" + memberName + "' is defined, but has type null";
- currentSymbol.setLength(0);
- accepted = true;
- recognizeClassNames = false;
- break;
- }
- }
- }
- }
- }
- }
- if (currentSymbol.length() > 0 && recognizeClassNames) {
- contextClass = TagManager.resolveClass(currentSymbol.toString(), compiler);
- if (contextClass != null) {
- currentSymbol.setLength(0);
- //accepted = true;
- //recognizeClassNames = false;
- // TODO: for now we don't handle statics
- return null;
- }
- }
- if (!accepted) {
- return null;
- }
- }
-
- return contextClass;
- }
-
- /**
- * Adds type information to nodes where possible, and as a side effect adds event listeners to nodes which
- * can be tracked.
- *
- * @param expression the node to scan
- * @param listenerId id of the listener
- * @return the class descriptor of the return type or null
- */
- private ClassDescriptor determineExpressionType(SimpleNode expression, String listenerId) {
- assert expression.getId() == JavaParserTreeConstants.JJTPRIMARYEXPRESSION;
- SimpleNode prefix = expression.getChild(0);
- if (prefix.jjtGetNumChildren() == 1) {
- int type = prefix.getChild(0).getId();
- if (type == JavaParserTreeConstants.JJTLITERAL || type == JavaParserTreeConstants.JJTEXPRESSION) {
- prefix.setJavaType(prefix.getChild(0).getJavaType());
- } else if (type == JavaParserTreeConstants.JJTNAME && expression.jjtGetNumChildren() == 1) // name with no arguments after it
- {
- prefix.setJavaType(scanCompoundSymbol(prefix.getText().trim(), compiler.getRootObject().getObjectClass(), false, listenerId));
- }
- }
-
- if (expression.jjtGetNumChildren() == 1) {
- return prefix.getJavaType();
- }
-
- ClassDescriptor contextClass = prefix.getJavaType();
- if (contextClass == null) {
- contextClass = compiler.getRootObject().getObjectClass();
- }
- String lastNode = prefix.getText().trim();
-
- for (int i = 1; i < expression.jjtGetNumChildren(); i++) {
- SimpleNode suffix = expression.getChild(i);
- if (suffix.jjtGetNumChildren() == 1 && suffix.getChild(0).getId() == JavaParserTreeConstants.JJTARGUMENTS) {
- if (suffix.getChild(0).jjtGetNumChildren() == 0) {
- // at the moment only no-argument methods are trackable
- contextClass = scanCompoundSymbol(lastNode, contextClass, true, listenerId);
- if (contextClass == null) {
- return null;
- }
- int dotPos = lastNode.lastIndexOf(".");
- String code = dotPos == -1 ? "" : lastNode.substring(0, dotPos);
- for (int j = i - 2; j >= 0; j--) {
- code = expression.getChild(j).getText() + code;
- }
- if (code.length() == 0) {
- code = compiler.getRootObject().getJavaCode();
- }
- String methodName = lastNode.substring(dotPos + 1).trim();
- try {
- MethodDescriptor method = contextClass.getMethodDescriptor(methodName);
- trackMemberIfPossible(code, contextClass, method.getName(), true, listenerId);
- return method.getReturnType();
- } catch (NoSuchMethodException e) {
- // happens for methods defined in the current JAXX file via scripts
- String propertyName = null;
- if (methodName.startsWith("is")) {
- propertyName = Introspector.decapitalize(methodName.substring("is".length()));
- } else if (methodName.startsWith("get")) {
- propertyName = Introspector.decapitalize(methodName.substring("get".length()));
- }
- if (propertyName != null) {
- MethodDescriptor[] newMethods = compiler.getScriptMethods();
- for (MethodDescriptor newMethod : newMethods) {
- if (newMethod.getName().equals(methodName)) {
- addListener(compiler.getRootObject().getId(),
- null,
- "addPropertyChangeListener(\"" + propertyName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator(),
- "removePropertyChangeListener(\"" + propertyName + "\", " + listenerId + ");" + JAXXCompiler.getLineSeparator());
- contextClass = newMethod.getReturnType();
- break;
- }
- }
- }
- }
- }
- }
- lastNode = suffix.getText().trim();
- if (lastNode.startsWith(".")) {
- lastNode = lastNode.substring(1);
- }
- }
-
- return null;
- }
-
- private void trackMemberIfPossible(String objectCode, ClassDescriptor objectClass, String memberName, boolean method, String listenerId) {
- if (objectClass.isInterface()) {
- // might be technically possible to track in some cases, but for now
- // we can't create a DefaultObjectHandler for interfaces
- return;
- }
-
- DefaultObjectHandler handler = TagManager.getTagHandler(objectClass);
- try {
- if (handler.isMemberBound(memberName)) {
- addListener(objectCode + "." + memberName + (method ? "()" : ""),
- objectCode,
- handler.getAddMemberListenerCode(objectCode, id, memberName, listenerId, compiler),
- handler.getRemoveMemberListenerCode(objectCode, id, memberName, listenerId, compiler));
- }
- } catch (UnsupportedAttributeException e) {
- // ignore -- this is thrown for methods like toString(), for which there is no tracking and
- // no setting support
- }
- }
-
- /**
- * Adds type information to nodes where possible, and as a side effect adds event listeners to nodes which
- * can be tracked.
- *
- * @param node node to scan
- * @param listenerId the listener id
- */
- private void determineNodeType(SimpleNode node, String listenerId) {
- ClassDescriptor type = null;
- if (node.jjtGetNumChildren() == 1) {
- type = node.getChild(0).getJavaType();
- }
- switch (node.getId()) {
- case JavaParserTreeConstants.JJTCLASSORINTERFACETYPE:
- type = ClassDescriptorLoader.getClassDescriptor(Class.class);
- break;
- case JavaParserTreeConstants.JJTPRIMARYEXPRESSION:
- type = determineExpressionType(node, listenerId);
- break;
- case JavaParserTreeConstants.JJTLITERAL:
- type = determineLiteralType(node);
- break;
- case JavaParserTreeConstants.JJTCASTEXPRESSION:
- type = TagManager.resolveClass(node.getChild(0).getText(), compiler);
- break;
- }
- node.setJavaType(type);
- }
-
- private void addListener(String dependencySymbol, String objectCode, String addCode, String removeCode) {
- this.objectCode = objectCode;
- //TC-20091026 no need to test objectCode not null if on root object
- boolean needTest = objectCode != null && !compiler.getRootObject().getId().equals(objectCode);
-// boolean needTest = objectCode != null;
- if (!dependencySymbols.contains(dependencySymbol)) {
- dependencySymbols.add(dependencySymbol);
- String eol = JAXXCompiler.getLineSeparator();
- addListenerCode.append(eol);
- if (needTest) {
- addListenerCode.append(" if (").append(objectCode).append(" != null) {").append(eol);
- addListenerCode.append(" ");
- }
- addListenerCode.append(" ").append(addCode.trim());
- if (needTest) {
- addListenerCode.append(eol).append(" }");
- }
-
- removeListenerCode.append(eol);
- if (needTest) {
- removeListenerCode.append(" if (").append(objectCode).append(" != null) {").append(eol);
- removeListenerCode.append(" ");
- }
- removeListenerCode.append(" ").append(removeCode.trim());
- if (needTest) {
- removeListenerCode.append(eol).append(" }");
- }
- }
- }
-
- private void compileListeners() {
- String javaCodeId = TypeManager.getJavaCode(id);
- String eol = JAXXCompiler.getLineSeparator();
- if (addListenerCode.length() > 0) {
- if (compiler.hasApplyDataBinding()) {
- compiler.appendApplyDataBinding(" else ");
- }
-// compiler.appendApplyDataBinding("if (" + javaCodeId + ".equals($binding)) {" + eol);
- compiler.appendApplyDataBinding("if (" + javaCodeId + ".equals($binding)) {");
- compiler.appendApplyDataBinding(" " + addListenerCode + eol);
- compiler.appendApplyDataBinding("}");
- }
-
- if (removeListenerCode.length() > 0) {
- if (compiler.hasRemoveDataBinding()) {
- compiler.appendRemoveDataBinding(" else ");
- }
-// compiler.appendRemoveDataBinding("if (" + javaCodeId + ".equals($binding)) {" + eol);
- compiler.appendRemoveDataBinding("if (" + javaCodeId + ".equals($binding)) {");
- compiler.appendRemoveDataBinding(" " + removeListenerCode + eol);
- compiler.appendRemoveDataBinding("}");
- }
- }
-}
1
0
r1612 - in branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin: . DataBinding
by tchemit@users.nuiton.org 28 Oct '09
by tchemit@users.nuiton.org 28 Oct '09
28 Oct '09
Author: tchemit
Date: 2009-10-28 08:51:37 +0100 (Wed, 28 Oct 2009)
New Revision: 1612
Modified:
branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBinding/Bean.java
branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBinding/BeanImpl.java
branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBindingTest.java
Log:
ajout license
Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBinding/Bean.java
===================================================================
--- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBinding/Bean.java 2009-10-28 07:44:28 UTC (rev 1611)
+++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBinding/Bean.java 2009-10-28 07:51:37 UTC (rev 1612)
@@ -1,3 +1,23 @@
+/*
+ * *##%
+ * JAXX Maven plugin
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
package org.nuiton.jaxx.plugin.DataBinding;
import java.beans.PropertyChangeListener;
Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBinding/BeanImpl.java
===================================================================
--- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBinding/BeanImpl.java 2009-10-28 07:44:28 UTC (rev 1611)
+++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBinding/BeanImpl.java 2009-10-28 07:51:37 UTC (rev 1612)
@@ -1,3 +1,23 @@
+/*
+ * *##%
+ * JAXX Maven plugin
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
package org.nuiton.jaxx.plugin.DataBinding;
import java.beans.PropertyChangeListener;
Modified: branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBindingTest.java
===================================================================
--- branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBindingTest.java 2009-10-28 07:44:28 UTC (rev 1611)
+++ branches/jaxx-2.X/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/DataBindingTest.java 2009-10-28 07:51:37 UTC (rev 1612)
@@ -1,3 +1,23 @@
+/*
+ * *##%
+ * JAXX Maven plugin
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 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 Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
package org.nuiton.jaxx.plugin;
import java.io.IOException;
1
0
r1611 - branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator
by tchemit@users.nuiton.org 28 Oct '09
by tchemit@users.nuiton.org 28 Oct '09
28 Oct '09
Author: tchemit
Date: 2009-10-28 08:44:28 +0100 (Wed, 28 Oct 2009)
New Revision: 1611
Removed:
branches/jaxx-2.X/jaxx-runtime/src/main/java/jaxx/runtime/decorator/swing/
Log:
remove a old empty package
1
0