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
March 2010
- 3 participants
- 75 discussions
12 Mar '10
Author: tchemit
Date: 2010-03-12 17:09:15 +0100 (Fri, 12 Mar 2010)
New Revision: 1776
Log:
add usefull method JAXXUtil.checkJAXXContextEntries to test more than one context entries
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-03-12 15:32:43 UTC (rev 1775)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-03-12 16:09:15 UTC (rev 1776)
@@ -37,14 +37,13 @@
public class JAXXUtil {
- /**
- * Logger
- */
+ /** Logger */
static private final Log log = LogFactory.getLog(JAXXUtil.class);
public static final String PARENT = "parent";
// Maps root objects to lists of event listeners
+
private static Map<Object, WeakReference<List<EventListenerDescriptor>>>
eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
@@ -56,15 +55,20 @@
private static class EventListenerDescriptor {
Class<?> listenerClass;
+
String listenerMethodName;
+
String methodName;
+
Object eventListener;
}
/**
- * Decodes the serialized representation of a JAXXObjectDescriptor. The string must be a byte-to-character mapping
- * of the binary serialization data for a JAXXObjectDescriptor. See the comments in JAXXCompiler.createJAXXObjectDescriptorField
- * for the rationale behind this (admittedly ugly) approach.
+ * Decodes the serialized representation of a JAXXObjectDescriptor. The
+ * string must be a byte-to-character mapping of the binary serialization
+ * data for a JAXXObjectDescriptor. See the comments in
+ * JAXXCompiler.createJAXXObjectDescriptorField for the rationale behind
+ * this (admittedly ugly) approach.
*
* @param descriptor descriptor to decode
* @return the dedoced descriptor
@@ -172,11 +176,11 @@
} else {
for (EventListenerDescriptor descriptor : descriptors) {
if (descriptor.listenerClass.equals(listenerClass) &&
- (listenerMethodName == null ?
- descriptor.listenerMethodName == null :
- listenerMethodName.equals(
- descriptor.listenerMethodName)) &&
- methodName.equals(descriptor.methodName)) {
+ (listenerMethodName == null ?
+ descriptor.listenerMethodName == null :
+ listenerMethodName.equals(
+ descriptor.listenerMethodName)) &&
+ methodName.equals(descriptor.methodName)) {
return (E) descriptor.eventListener;
}
}
@@ -211,41 +215,41 @@
methodContainerClass.getMethod(methodName, parameterTypes);
descriptor.eventListener =
Proxy.newProxyInstance(listenerClass.getClassLoader(),
- new Class<?>[]{listenerClass},
- new InvocationHandler() {
+ new Class<?>[]{listenerClass},
+ new InvocationHandler() {
- @Override
- public Object invoke(Object proxy,
- Method method,
- Object[] args) {
- String methodName = method.getName();
- if ((listenerMethodName == null &&
- listenerMethods.contains(method)) ||
- methodName.equals(listenerMethodName)) {
- try {
- targetMethod.setAccessible(true);
- return targetMethod.invoke(
- methodContainer, args);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(
- "could not invoke on container " +
- methodContainer, e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- }
- if (methodName.equals("toString")) {
- return toString();
- }
- if (methodName.equals("equals")) {
- return descriptor.eventListener == args[0];
- }
- if (methodName.equals("hashCode")) {
- return hashCode();
- }
- return null;
- }
- });
+ @Override
+ public Object invoke(Object proxy,
+ Method method,
+ Object[] args) {
+ String methodName = method.getName();
+ if ((listenerMethodName == null &&
+ listenerMethods.contains(method)) ||
+ methodName.equals(listenerMethodName)) {
+ try {
+ targetMethod.setAccessible(true);
+ return targetMethod.invoke(
+ methodContainer, args);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(
+ "could not invoke on container " +
+ methodContainer, e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ if (methodName.equals("toString")) {
+ return toString();
+ }
+ if (methodName.equals("equals")) {
+ return descriptor.eventListener == args[0];
+ }
+ if (methodName.equals("hashCode")) {
+ return hashCode();
+ }
+ return null;
+ }
+ });
descriptors.add(descriptor);
return (E) descriptor.eventListener;
} catch (NoSuchMethodException e) {
@@ -361,8 +365,8 @@
* Return empty string if given object is null
*
* @param value the value to write
- * @return the string representation of the given object or an empty
- * string if object is null.
+ * @return the string representation of the given object or an empty string
+ * if object is null.
*/
public static String getStringValue(Object value) {
String result;
@@ -371,6 +375,30 @@
}
/**
+ * Test if some entries exists in a given context and throw an
+ * IllegalArgumentException if not.
+ * <p/>
+ *
+ * @param context the context to test
+ * @param defs the definitions of entries to seek in context
+ * @throws IllegalArgumentException if the entry is not found in context.
+ */
+ public static void checkJAXXContextEntries(JAXXContext context,
+ JAXXContextEntryDef<?>... defs)
+ throws IllegalArgumentException {
+
+ for (JAXXContextEntryDef<?> def : defs) {
+ Object value = def.getContextValue(context);
+
+ if (value == null) {
+ throw new IllegalArgumentException(
+ "the context entry [" + def + "] ] was not found in " +
+ "context " + context);
+ }
+ }
+ }
+
+ /**
* Test if a type of entry exists in a given context and throw an
* IllegalArgumentException if not found.
* <p/>
@@ -408,6 +436,7 @@
src.applyDataBinding(binding);
}
}
+
/**
* Convinient method to apply more than one binding on a JAXX ui.
*
@@ -446,8 +475,8 @@
}
/**
- * detects all PropertychangedListener added by Jaxx uis
- * (should be a {@link DataBindingListener}
+ * detects all PropertychangedListener added by Jaxx uis (should be a {@link
+ * DataBindingListener}
*
* @param propertyNames the array of property names to find
* @param listeners the array of listeners to filter
1
0
12 Mar '10
Author: tchemit
Date: 2010-03-12 16:32:43 +0100 (Fri, 12 Mar 2010)
New Revision: 1775
Log:
add javadoc
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java 2010-03-12 00:24:04 UTC (rev 1774)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java 2010-03-12 15:32:43 UTC (rev 1775)
@@ -7,10 +7,24 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+/**
+ * An abstract action thread to consume actions in a non Swing event thread.
+ * <p/>
+ * Implements the method {@code onActionXXX(ActionWorker)} to hook on action
+ * status.
+ * <p/>
+ * To consume an action, use the method {@link #addAction(String, Runnable)}.
+ * <p/>
+ * TODO Make this multi-action enable
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 2.0
+ */
public abstract class AbstractActionThread extends Thread {
/** Logger */
- private static final Log log = LogFactory.getLog(AbstractActionThread.class);
+ private static final Log log =
+ LogFactory.getLog(AbstractActionThread.class);
/** l'état du thread si annulé */
private boolean canceled;
@@ -21,16 +35,20 @@
*/
private final Object LOCK = new Object();
+ /** current worker to execute action */
protected ActionWorker worker;
+ /** the listener of running action */
protected final PropertyChangeListener workerListener;
+ /** State of a running action */
enum ActionStatus {
OK,
CANCEL,
FAIL
}
+ /** Action worker to execute a incoming action. */
public static class ActionWorker extends SwingWorker<Void, Object> {
protected final String actionLabel;
@@ -152,15 +170,13 @@
};
}
-
- public void cancel() {
- log.info("cancel " + this);
- canceled = true;
-
- // on rend la main au thread
- setWaiting(false);
- }
-
+ /**
+ * Add an new action to perform.
+ *
+ * @param actionLabel the name of the action to perform
+ * @param action the action to perform
+ * @return the worker that will launch the action
+ */
public ActionWorker addAction(String actionLabel, Runnable action) {
if (worker != null && !worker.isDone()) {
// on ne peut traiter qu'une seule opération à la fois
@@ -181,12 +197,35 @@
return worker;
}
+ /**
+ * Hook when a action is about to start.
+ *
+ * @param source the action worker containing the action to perform
+ */
public abstract void onActionStart(ActionWorker source);
+
+ /**
+ * Hook when a action has failed.
+ *
+ * @param source the action worker containing the action to perform
+ */
public abstract void onActionFail(ActionWorker source);
+
+ /**
+ * Hook when a action has been canceled.
+ *
+ * @param source the action worker containing the action to perform
+ */
public abstract void onActionCancel(ActionWorker source);
+
+ /**
+ * Hook when a action has end with no failure or cancel.
+ *
+ * @param source the action worker containing the action to perform
+ */
public abstract void onActionEnd(ActionWorker source);
@Override
@@ -256,17 +295,40 @@
throw new RuntimeException(e);
} finally {
unlockThread();
- log.trace(this + " will close...");
+ if (log.isInfoEnabled()) {
+ log.info(this + " will close...");
+ }
close();
}
}
+ /**
+ * Cancel the thread, this will release any lock of the tread.
+ * <p/>
+ * As a side effect, this will close the thread.
+ */
+ public void cancel() {
+ log.info("cancel " + this);
+ canceled = true;
+
+ // on rend la main au thread
+ setWaiting(false);
+ }
+
/** La méthode pour nettoyer le thread, a la fermeture. */
protected void close() {
// par defaut, on ne fait rien
log.info(this);
}
+ /**
+ * Mutates the waiting state of the thread.
+ * <p/>
+ * If parameter {@code waiting} is to {@code true}, then will lock the
+ * thread, otherwise will unlock the thread.
+ *
+ * @param waiting {@code true} if a lock is required
+ */
protected void setWaiting(boolean waiting) {
if (waiting && !canceled) {
@@ -285,6 +347,11 @@
}
}
+ /**
+ * To lock the thread.
+ *
+ * @throws InterruptedException if locking was interruped
+ */
protected void lockThread() throws InterruptedException {
synchronized (LOCK) {
log.trace(this);
@@ -293,6 +360,7 @@
}
}
+ /** To unlock the thread. */
protected void unlockThread() {
synchronized (LOCK) {
log.trace(this);
1
0
12 Mar '10
Author: tchemit
Date: 2010-03-12 01:24:04 +0100 (Fri, 12 Mar 2010)
New Revision: 1774
Log:
improve StatusMessagePanel (add a busy scroll bar)
Modified:
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanel.jaxx
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanelHandler.java
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanel.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanel.jaxx 2010-03-12 00:23:15 UTC (rev 1773)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanel.jaxx 2010-03-12 00:24:04 UTC (rev 1774)
@@ -21,16 +21,10 @@
-->
-<Table border='{BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)}'
+<Table border='{BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)}'
insets='0'
implements='java.awt.event.ActionListener'>
- <Boolean id='showMemoryStatus' javaBean='Boolean.TRUE'/>
- <Boolean id='showClock' javaBean='Boolean.TRUE'/>
- <Boolean id='showI18n' javaBean='Boolean.FALSE'/>
-
- <StatusMessagePanelHandler id='handler' />
-
<script><![CDATA[
// To ensure status bar constant height, no matter what font are in use...
@@ -39,12 +33,38 @@
public void clearStatus() {
handler.stopStatusFader(this);
getStatusLabel().setText(EMPTY_STATUS);
+ //getStatusLabel().setString(EMPTY_STATUS);
}
+public void startProgress() {
+ startProgress(null);
+}
+
+public void startProgress(final String status) {
+ setBusy(true);
+ setStatus(status);
+}
+
+public void stopProgress() {
+ stopProgress(null);
+}
+
+public void stopProgress(String finalStatus) {
+ setBusy(false);
+ setStatus(finalStatus);
+}
+
public void setStatus(String status) {
- handler.stopStatusFader(this);
- getStatusLabel().setText(status);
- handler.startStatusFader(this);
+
+ if (status != null) {
+ handler.stopStatusFader(this);
+ getStatusLabel().setText(status);
+ //getStatusLabel().setString(status);
+ }
+
+ if (!isBusy()) {
+ handler.startStatusFader(this);
+ }
}
@Override
@@ -68,16 +88,63 @@
public void addWidget(Component w, int index) {
box.add(w, index);
}
+
+public void init() {
+ if (isShowBusy()) {
+ Dimension dim = new Dimension(30, 15);
+ //Dimension dim = new Dimension(30, (int) statusLabel.getPreferredSize().getHeight());
+ //log.info("dimension of busy = "+ dim);
+ //busyWidget.setPreferredSize(dim);
+ busyWidget.setMaximumSize(dim);
+ busyWidget.setMinimumSize(dim);
+ }
+}
+
+void $afterCompleteSetup() {
+ init();
+}
]]>
</script>
+
+ <Boolean id='showMemoryStatus' javaBean='Boolean.TRUE'/>
+ <Boolean id='showClock' javaBean='Boolean.TRUE'/>
+ <Boolean id='showI18n' javaBean='Boolean.FALSE'/>
+ <Boolean id='showBusy' javaBean='Boolean.FALSE'/>
+ <Boolean id='busy' javaBean='Boolean.FALSE'/>
+
+ <StatusMessagePanelHandler id='handler'/>
+
<row>
- <cell anchor='west' weightx='1' insets='2'>
- <JLabel id='statusLabel'/>
+ <cell anchor='west' fill='both' weightx='1'>
+ <Box constructorParams='0'>
+ <JProgressBar id='busyWidget'
+ visible='{isShowBusy()}'
+ enabled='{isBusy()}'
+ indeterminate='{isBusy()}'
+ stringPainted='false'
+ borderPainted='true'/>
+ <!--visible='{isBusy() && isShowBusy()}'-->
+
+ <JLabel id='statusLabel'/>
+
+ </Box>
+
</cell>
<cell anchor='east'>
<Box id='box' constructorParams='0'>
+
+ <!--JProgressBar id='busyWidget'
+ visible='{isBusy() && isShowBusy()}'
+ indeterminate='{isBusy()}'
+ stringPainted='false'
+ borderPainted='true'/-->
+ <!--
+ minimumSize='{new Dimension(30,1)}'
+ maximumSize='{new Dimension(30,30)}'
+ preferredSize='{new Dimension(30,30)}'
+ -->
<MemoryStatusWidget/>
- <ClockWidget/>
+ <ClockWidget/>
</Box>
</cell>
</row>
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanelHandler.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanelHandler.java 2010-03-12 00:23:15 UTC (rev 1773)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/StatusMessagePanelHandler.java 2010-03-12 00:24:04 UTC (rev 1774)
@@ -20,31 +20,33 @@
*/
package jaxx.runtime.swing;
-import java.awt.Color;
-import java.awt.event.ActionListener;
-import javax.swing.Timer;
+import javax.swing.*;
+import java.awt.*;
/**
- *
* @author chemit
* @since 1.6.0
*/
public class StatusMessagePanelHandler {
- protected Color statusForeground = null;
- protected String statusReferenceContent = null;
- protected javax.swing.Timer timer = null;
+ protected Color statusForeground;
+ protected String statusReferenceContent;
+
+ protected Timer timer;
+
protected void fadeStatus(StatusMessagePanel ui) {
for (int i = 0; i < 8; i++) {
// synchronized (this) {
if (!statusReferenceContent.equals(ui.getStatusLabel().getText())) {
+// if (!statusReferenceContent.equals(ui.getStatusLabel().getString())) {
return;
}
Color currentForeground = ui.getStatusLabel().getForeground();
Color newColor = new Color(currentForeground.getRed(),
- currentForeground.getGreen(), currentForeground.getBlue(),
- currentForeground.getAlpha() - 25);
+ currentForeground.getGreen(),
+ currentForeground.getBlue(),
+ currentForeground.getAlpha() - 25);
ui.getStatusLabel().setForeground(newColor);
ui.getStatusLabel().repaint();
// }
@@ -60,11 +62,14 @@
protected void startStatusFader(StatusMessagePanel ui) {
statusReferenceContent = ui.getStatusLabel().getText();
+// statusReferenceContent = ui.getStatusLabel().getString();
int millisecondsPerMinute = 5000;
- timer = new Timer(millisecondsPerMinute, (ActionListener) ui);
+ timer = new Timer(millisecondsPerMinute, ui);
timer.setRepeats(false);
- timer.setInitialDelay((int) ((long) millisecondsPerMinute - System.currentTimeMillis() % (long) millisecondsPerMinute) + 500);
+ timer.setInitialDelay((int) ((long) millisecondsPerMinute -
+ System.currentTimeMillis() %
+ (long) millisecondsPerMinute) + 500);
timer.start();
}
1
0
12 Mar '10
Author: tchemit
Date: 2010-03-12 01:23:15 +0100 (Fri, 12 Mar 2010)
New Revision: 1773
Log:
introduce ActionThread
reformat code
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/CardLayout2Ext.java
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java 2010-03-12 00:23:15 UTC (rev 1773)
@@ -0,0 +1,304 @@
+package jaxx.runtime.swing;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.*;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+public abstract class AbstractActionThread extends Thread {
+
+ /** Logger */
+ private static final Log log = LogFactory.getLog(AbstractActionThread.class);
+
+ /** l'état du thread si annulé */
+ private boolean canceled;
+
+ /**
+ * un lock pour permettre la suspension et la reprise du thread lors du mode
+ * interactif.
+ */
+ private final Object LOCK = new Object();
+
+ protected ActionWorker worker;
+
+ protected final PropertyChangeListener workerListener;
+
+ enum ActionStatus {
+ OK,
+ CANCEL,
+ FAIL
+ }
+
+ public static class ActionWorker extends SwingWorker<Void, Object> {
+
+ protected final String actionLabel;
+
+ protected final Runnable target;
+
+ protected ActionStatus status;
+
+ protected Exception error;
+
+ public ActionWorker(String actionLabel, Runnable target) {
+ this.target = target;
+ this.actionLabel = actionLabel;
+ }
+
+ @Override
+ protected Void doInBackground() throws Exception {
+ if (log.isDebugEnabled()) {
+ log.debug("Action is starting " + getActionLabel());
+ }
+ try {
+ target.run();
+ } catch (Exception e) {
+ error = e;
+ }
+ return null;
+ }
+
+ public boolean isFailed() {
+ return (isDone() || isCancelled()) && error != null;
+ }
+
+ public Exception getError() {
+ return error;
+ }
+
+ public ActionStatus getStatus() {
+ return status;
+ }
+
+ public String getActionLabel() {
+ return actionLabel;
+ }
+
+ @Override
+ protected void done() {
+ super.done();
+ if (error != null) {
+ status = ActionStatus.FAIL;
+ return;
+ }
+
+ if (isCancelled()) {
+ status = ActionStatus.CANCEL;
+ return;
+ }
+ status = ActionStatus.OK;
+ if (log.isDebugEnabled()) {
+ log.debug("Action is ending " + getActionLabel() +
+ " with status : " + status);
+ }
+ }
+ }
+
+ protected AbstractActionThread(String name) {
+ super(name);
+ workerListener = new PropertyChangeListener() {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (log.isInfoEnabled()) {
+ log.info("action " + evt.getSource() + " property " +
+ evt.getPropertyName() + " changed <" +
+ evt.getOldValue() + " - " + evt.getNewValue() + ">");
+ }
+
+ if ("state".equals(evt.getPropertyName())) {
+ ActionWorker source = (ActionWorker) evt.getSource();
+ SwingWorker.StateValue state =
+ (SwingWorker.StateValue) evt.getNewValue();
+
+
+ if (state == SwingWorker.StateValue.STARTED) {
+ // starting new action
+
+ onActionStart(source);
+ return;
+ }
+
+ if (state == SwingWorker.StateValue.DONE) {
+ // on rend la main au thread pour qu'il attende une
+ // prochaine operation
+
+ ActionStatus status = source.getStatus();
+ if (log.isInfoEnabled()) {
+ log.info("status = " + status);
+ }
+ try {
+ switch (status) {
+
+ case OK:
+ onActionEnd(source);
+ break;
+ case CANCEL:
+ onActionCancel(source);
+ break;
+ case FAIL:
+ onActionFail(source);
+ break;
+ }
+ } finally {
+
+ // release thread
+ setWaiting(false);
+ }
+ }
+ }
+ }
+ };
+ }
+
+
+ public void cancel() {
+ log.info("cancel " + this);
+ canceled = true;
+
+ // on rend la main au thread
+ setWaiting(false);
+ }
+
+ public ActionWorker addAction(String actionLabel, Runnable action) {
+ if (worker != null && !worker.isDone()) {
+ // on ne peut traiter qu'une seule opération à la fois
+ throw new IllegalStateException(
+ "can not add a operation when thread is busy, or has" +
+ " another operation to be done");
+ }
+ if (action instanceof ActionWorker) {
+
+ worker = (ActionWorker) action;
+ } else {
+ worker = new ActionWorker(actionLabel, action);
+ }
+
+ // on libere le thread pour qu'il execute l'opération
+ setWaiting(false);
+
+ return worker;
+ }
+
+ public abstract void onActionStart(ActionWorker source);
+
+ public abstract void onActionFail(ActionWorker source);
+
+ public abstract void onActionCancel(ActionWorker source);
+
+ public abstract void onActionEnd(ActionWorker source);
+
+ @Override
+ public void run() {
+ if (log.isInfoEnabled()) {
+ log.info("starting... " + this);
+ }
+ try {
+
+ while (!canceled) {
+
+ if (canceled) {
+ // une annulation a été demandé
+ // donc même si une opération est demandée, on ne la traite
+ // pas
+ break;
+ }
+
+ // en attente qu'une opération
+ // le block est bloqué jusqu'à arrivée d'une opération
+ // ou une demande d'annulation
+ setWaiting(true);
+
+ // le thread a repris la main, donc plus en attente
+ log.trace("no more waiting " + this);
+
+ if (!canceled) {
+
+ // une opération a été demandée
+ try {
+
+ // le thread écoute les modifications de l'action
+ worker.addPropertyChangeListener(workerListener);
+
+ // démarrage de l'opération dans un worker
+
+ worker.execute();
+
+ // le thread est bloqué jusqu'à la fin de l'opération
+ // ou une demande d'annulation
+ setWaiting(true);
+
+ // le thread reprend la main des que l'operation
+ // est terminée ou a été annulée, on passera alors
+ // dans la méthode onPropertyChanged
+
+ if (canceled) {
+// getModel().setOperationState(WizardOperationState.CANCELED);
+ } else {
+// getModel().setOperationState(currentAction.getOperationState());
+ }
+
+ } finally {
+ if (worker != null) {
+ // le thread n'écoute plus l'action car elle est terminée
+ // ou annulée
+ worker.removePropertyChangeListener(workerListener);
+
+ // suppression de l'action
+ worker = null;
+ }
+ }
+ }
+ }
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ unlockThread();
+ log.trace(this + " will close...");
+ close();
+ }
+ }
+
+ /** La méthode pour nettoyer le thread, a la fermeture. */
+ protected void close() {
+ // par defaut, on ne fait rien
+ log.info(this);
+ }
+
+ protected void setWaiting(boolean waiting) {
+
+ if (waiting && !canceled) {
+ // locking thread
+ try {
+ lockThread();
+ } catch (InterruptedException ex) {
+ log.error(ex.getMessage(), ex);
+ canceled = true;
+ }
+ }
+
+ if (!waiting) {
+ // release lock
+ unlockThread();
+ }
+ }
+
+ protected void lockThread() throws InterruptedException {
+ synchronized (LOCK) {
+ log.trace(this);
+ // lock
+ LOCK.wait();
+ }
+ }
+
+ protected void unlockThread() {
+ synchronized (LOCK) {
+ log.trace(this);
+ // unlock
+ LOCK.notify();
+ }
+ }
+
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/AbstractActionThread.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/CardLayout2Ext.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/CardLayout2Ext.java 2010-03-11 11:27:15 UTC (rev 1772)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/CardLayout2Ext.java 2010-03-12 00:23:15 UTC (rev 1773)
@@ -84,8 +84,11 @@
}
public void setSelected(String selected) {
+ String oldSelected = this.selected;
this.selected = selected;
show(getContainer(), selected);
+ //TODO-TC20100311 : should propagate the selected ?
+// pcs.firePropertyChange(SELECTED_PROPERTY_NAME, oldSelected, selected);
}
public Container getContainer() {
@@ -99,7 +102,8 @@
pcs.addPropertyChangeListener(listener);
}
- public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ public void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
pcs.addPropertyChangeListener(propertyName, listener);
}
@@ -107,7 +111,8 @@
pcs.removePropertyChangeListener(listener);
}
- public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
+ public void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
pcs.removePropertyChangeListener(propertyName, listener);
}
1
0
Author: sletellier
Date: 2010-03-11 12:27:15 +0100 (Thu, 11 Mar 2010)
New Revision: 1772
Log:
Adding multi and treeTable navigation helper documentations (V2)
Added:
trunk/src/site/rst/NavigationModel.rst
Removed:
trunk/src/site/rst/NavigationTreeModel.rst
Modified:
trunk/src/site/rst/index.rst
Copied: trunk/src/site/rst/NavigationModel.rst (from rev 1771, trunk/src/site/rst/NavigationTreeModel.rst)
===================================================================
--- trunk/src/site/rst/NavigationModel.rst (rev 0)
+++ trunk/src/site/rst/NavigationModel.rst 2010-03-11 11:27:15 UTC (rev 1772)
@@ -0,0 +1,228 @@
+---------------
+NavigationModel
+---------------
+
+.. contents::
+
+**WARNING : documentation non à jour...**
+
+Présentation
+============
+
+Ajout d'un modèle d'arbre de navigation.
+
+Le but de cette fonctionnalité est de pouvoir créer un arbre de navigation lié au context de JAXX, de définir des UI
+rattachés à chaque noeud.
+
+Le développement est effectué dans le paquetage *jaxx.runtime.swing.navigation*.
+
+jaxx.runtime.swing.navigation.NavigationModel
+=============================================
+
+Contract representant le model de l'arbre de navigation.
+
+Les noeuds présents dans se modèle sont aussi typés en *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*.
+
+L'idée principale est de pouvoir associer à un noeud précis un chemin depuis la racine, ce que l'on appele *chemin de navigation*.
+
+Pour obtenir le chemin de navigation d'un noeud donné, on récupère l'enmseble des neoud depuis la racine vers ce noeud
+et les concatène en suffixant par le caractère séparateur défini.
+
+Tout les models suivants implémantent cette interface.
+
+jaxx.runtime.swing.navigation.NavigationTreeModel
+=================================================
+
+Il s'agit du modèle de l'arbre utilisé, c'est une extension d'un *javax.swing.tree.DefaultTreeModel*.
+
+jaxx.runtime.swing.navigation.NavigationTreeTableModel
+======================================================
+
+Il s'agit du modèle de l'arbre tableau (*org.jdesktop.swingx.JXTreeTable*), c'est une extension d'un *org.jdesktop.swingx.treetable.DefaultTreeTableModel*.
+
+Les noeuds présents dans se modèle sont typés en *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeTableNode* qui
+étend *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*.
+
+NavigationTreeTableNode est abstaite, l'instance doit donc être crée en implementant la méthode createNavigationTreeTableNode
+du builder (*jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder*).
+
+Les builders
+============
+
+jaxx.runtime.swing.navigation.NavigationModelBuilder
+----------------------------------------------------
+
+Les builders sont des classes utilitaires permétant de construire le model et les rendus de l'arbre simplement.
+Tous les builders implémentent cette interface.
+
+jaxx.runtime.swing.navigation.NavigationTreeModelBuilder
+--------------------------------------------------------
+
+Classe utilitaire pour construire le model (ici un *jaxx.runtime.swing.navigation.NavigationTreeModel*) et décorer un arbre.
+
+jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder
+-------------------------------------------------------------
+
+Classe utilitaire pour construire le model (ici un *jaxx.runtime.swing.navigation.NavigationTreeTableModel*) et décorer un arbre tableau.
+
+Les Handlers
+============
+
+jaxx.runtime.swing.navigation.NavigationTreeHandler
+---------------------------------------------------
+
+Cette classe est une implémentation d'un model de sélection pour les arbres de navigations.
+
+Il y a 2 façons de l'utiliser, soit l'on associe une ui par noeud (*Strategy.PER_NODE*) soit on associe une ui par type de noeud (*Strategy.PER_UI_TYPE*).
+
+jaxx.runtime.swing.navigation.NavigationTreeHandlerWithCardLayout
+-----------------------------------------------------------------
+
+Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour l'utilisation de CardLayout (*jaxx.runtime.swing.CardLayout2*).
+
+jaxx.runtime.swing.navigation.NavigationMultiTreeHandler
+--------------------------------------------------------
+
+TODO ajouter la strategie de la multiselection
+
+Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour ajouter la possibilité d'utiliser la multisélection.
+
+Définition d'un noeud
+=====================
+
+Le noeud (*jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*.
+
+Il apporte les nouvelles propriétés suivantes :
+
+ * *navigationPath* : nom de chemin de navigation de ce noeud.
+
+ * *jaxxClass* : nom qualifié de la classe d'ui associé à ce noeud (doit être obligatoirement un *JAXXObject*)
+
+ * *jaxxActionClass* : nom qualifié de la classe d'handler d'ui associé à ce noeud (doit être obligatoirement un *JAXXAction*).
+
+ * *jaxxContextEntryDef* : définition de l'entrée dans le context JAXX associé à ce noeud.
+
+ * *jaxxContextEntryJXPath* : définition d'une expression JXPath à appliquer sur le bean associé au noeud.
+
+
+Retrouver un noeud à partir du chemin de navigation
+***************************************************
+
+Il est possible en connaissant le chemin de navigation d'un noued de récupérer le noeud dans l'arbre via la méthode
+
+::
+
+ model.findNode("chemin.de.navigation")
+
+Trouver la valeur associée dans le context JAXX à partir du chemin de navigation
+********************************************************************************
+
+Il est possible en connaissant le chemin de navigation d'un noued de récupérer la valeur associée dans le context JAXX.
+
+::
+
+ model.getJAXXContextValue(myJAXXContext, "chemin.de.navigation")* .
+
+L'algrotihme est le suivant :
+
+ * récupération du noeud associé au chemin de navigation
+
+ * recherche du premier noeud (dans les noeuds qui remontent vers la racine de l'arbre) dont la propriété *jaxxContextEntry* est non nulle, il s'agit du point d'entré dans le context JAXX.
+
+ * redescendre à partir de ce noeud vers le noeud d'origine (si ce noeud était différent) et en descendant conjointement dans l'objet du context JAXX :
+
+ - on utilise l'expression JXPath pour obtenir l'objet associé au noeud
+
+Exemple :
+
+::
+
+ "$root" + <-- la racine de l'abre
+ |
+ + "string" <-- attaché au context JAXX <java.lang.String,"string">
+ |
+ + "liste" + <-- attaché au context JAXX <java.util.List.class,"liste">
+ | |
+ | + "0" <-- le premier élément de la liste
+ | |
+ | + "1" <-- le second élément de la liste
+ | |
+ | + "2" <-- le troisième élément de la liste
+ |
+ + "locale" + <-- attaché au context JAXX <java.util.Locale>
+ |
+ + country
+ |
+ + language
+
+ // preparation du context
+ java.util.List myList = java.util.Arrays.asList("one","two","three");
+ java.util.Locale myLocale = java.util.Locale.FRENCH;
+ context.setContextValue(myList, "liste");
+ context.setContextValue("stringValue","string");
+ context.setContextValue(myLocale);
+
+
+ // récupération des valeurs dans le context à partir de chemin de navigation
+ assert model.getJAXXContextValue(context, "$root") == null;
+ assert model.getJAXXContextValue(context, "$root.string") == "stringValue";
+ assert model.getJAXXContextValue(context, "$root.liste") == myList;
+ assert model.getJAXXContextValue(context, "$root.liste.0") == "one";
+ assert model.getJAXXContextValue(context, "$root.liste.1") == "two";
+ assert model.getJAXXContextValue(context, "$root.liste.2") == "three";
+ assert model.getJAXXContextValue(context, "$root.locale") == myLocale;
+ assert model.getJAXXContextValue(context, "$root.locale.country") == myLocale.getCountry();
+ assert model.getJAXXContextValue(context, "$root.locale.language") == myLocale.getLanguage();
+
+TODO mettre à jour cet exemple suite à l'utilisation de JXPath pour naviguer dans les objets.
+
+A noter qu'une seconde méthode de récupération de valeur du context JAXX est disponible pour pouvoir récupérer cette
+valeur en connaissant le noeud :
+
+::
+
+ model.getJAXXContextValue(context, myNode);
+
+jaxx.runtime.swing.navigation.NavigationTreeSelectionAdapter
+============================================================
+
+Il s'agit d'un listener sur la sélection d'un noeud dans l'arbre de navigation basé sur notre modèle de navigation. Il
+étend *javax.swing.event.TreeSelectionListener*.
+
+Ce listener contient la gestion de passage d'un noeud à un autre avec interaction avec le context JAXX et affichage automatique de l'ui associé au noeud sélectionné.
+
+**Attention : la mécanique ne fonctionne que pour un arbre à selection unique.**
+
+Algorithme
+**********
+
+Voici l'algorithme utilisé lors de la sélection d'un nouveau noeud :
+
+ * *closeUI* : tentative de fermeture de l'ui lié au noeud précédemment selectionné, si cela n'aboutit pas on retourne sur le noeud précédent.
+
+ * *attachBeanFromNodeToContext* : injection dans le context JAXX de la valeur associée au nouveau noeud
+
+ * *createUI* : création de la nouvelle ui (si elle n'existe pas)
+
+ * *openUI* : ouverture de la nouvelle ui
+
+Si une erreur survient lors de ces opérations, on entre dans la méthode *goBackToPreviousNode* qui est abstraite et permet de notifier les erreur de retourner au noeud précdent.
+
+jaxx.runtime.swing.navigation.NavigationTreeSelectionAdapterWithCardLayout
+**************************************************************************
+
+Il s'agit d'une implantation du listener précédent qui suppose que les uis associées aux noeuds sont affichées dans un
+unique container en utilisant le layout *jaxx.runtime.swing.CardLayout2*.
+
+La contrainte de chaque ui sera extactement le chemin de navigation du noeud associé.
+
+Il possède deux méthodes abstraites :
+
+ * *getContentContainer* : qui indique le container d'ui.
+
+ * *getContentLayout* : qui indique le layout utilisé.
+
+Pour pouvoir utilisé cet *adapter*, il vous suffit de définir la méthode suivante (en plus des deux méthodes abstraites) :
+
+ * *goBackToPreviousNode* : comment gérer les erreurs et retourner au noeud précedent.
+
Property changes on: trunk/src/site/rst/NavigationModel.rst
___________________________________________________________________
Added: svn:mergeinfo
+
Deleted: trunk/src/site/rst/NavigationTreeModel.rst
===================================================================
--- trunk/src/site/rst/NavigationTreeModel.rst 2010-03-11 11:12:44 UTC (rev 1771)
+++ trunk/src/site/rst/NavigationTreeModel.rst 2010-03-11 11:27:15 UTC (rev 1772)
@@ -1,221 +0,0 @@
--------------------
-NavigationTreeModel
--------------------
-
-.. contents::
-
-**WARNING : documentation non à jour...**
-
-Présentation
-============
-
-Ajout d'un modèle d'arbre de navigation.
-
-Le but de cette fonctionnalité est de pouvoir créer un arbre de navigation lié au context de JAXX, de définir des UI
-rattachés à chaque noeud.
-
-Le développement est effectué dans le paquetage *jaxx.runtime.swing.navigation*.
-
-jaxx.runtime.swing.navigation.NavigationTreeModel
-=================================================
-
-Il s'agit du modèle de l'arbre utilisé, c'est une extension d'un *javax.swing.tree.DefaultTreeModel*.
-
-Les noeuds présents dans ce modèle sont aussi typés en *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*.
-
-L'idée principale est de pouvoir associer à un noeud précis un chemin depuis la racine, ce que l'on appele *chemin de navigation*.
-
-Pour obtenir le chemin de navigation d'un noeud donné, on récupère l'enmseble des neoud depuis la racine vers ce noeud
-et les concatène en suffixant par le caractère séparateur défini.
-
-jaxx.runtime.swing.navigation.NavigationTreeTableModel
-======================================================
-
-Il s'agit du modèle de l'arbre tableau (*org.jdesktop.swingx.JXTreeTable*), c'est une extension d'un *org.jdesktop.swingx.treetable.DefaultTreeTableModel*.
-
-Les noeuds présents dans ce modèle sont typés en *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeTableNode* qui
-étend *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*.
-
-Cette implmentation est abstaite, l'instance doit
-donc être crée en implementant la méthode createNavigationTreeTableNode du builder (*jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder*).
-
-Les builders
-============
-
-jaxx.runtime.swing.navigation.NavigationModelBuilder
-----------------------------------------------------
-
-Les builders sont des classes utilitaires permetant de construire le model et les rendus de l'arbre simplement.
-Tous les builders implémentes cette interface.
-
-jaxx.runtime.swing.navigation.NavigationTreeModelBuilder
---------------------------------------------------------
-
-Classe utilitaire pour construire le model (ici un *jaxx.runtime.swing.navigation.NavigationTreeModel*) et décorer un arbre.
-
-jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder
--------------------------------------------------------------
-
-Classe utilitaire pour construire le model (ici un *jaxx.runtime.swing.navigation.NavigationTreeTableModel*) et décorer un arbre tableau.
-
-Les Handlers
-============
-
-jaxx.runtime.swing.navigation.NavigationTreeHandler
----------------------------------------------------
-
-Cette classe est une implémentation d'un model de sélection pour les arbres de navigations.
-
-Il y a 2 façons de l'utiliser, soit l'on associe une ui par noeud (*Strategy.PER_NODE*) soit on associe une ui par type de noeud (*Strategy.PER_UI_TYPE*).
-
-jaxx.runtime.swing.navigation.NavigationTreeHandlerWithCardLayout
------------------------------------------------------------------
-
-Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour l'utilisation de CardLayout (*jaxx.runtime.swing.CardLayout2*).
-
-jaxx.runtime.swing.navigation.NavigationMultiTreeHandler
---------------------------------------------------------
-
-TODO ajouter la strategie de la multiselection
-
-Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour ajouter la possibilité d'utiliser la multiselection.
-
-Définition d'un noeud
-=====================
-
-Le noeud (*jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*.
-
-Il apporte les nouvelles propriétés suivantes :
-
- * *navigationPath* : nom de chemin de navigation de ce noeud.
-
- * *jaxxClass* : nom qualifié de la classe d'ui associé à ce noeud (doit être obligatoirement un *JAXXObject*)
-
- * *jaxxActionClass* : nom qualifié de la classe d'handler d'ui associé à ce noeud (doit être obligatoirement un *JAXXAction*).
-
- * *jaxxContextEntryDef* : définition de l'entrée dans le context JAXX associé à ce noeud.
-
- * *jaxxContextEntryJXPath* : définition d'une expression JXPath à appliquer sur le bean associé au noeud.
-
-
-Retrouver un noeud à partir du chemin de navigation
-***************************************************
-
-Il est possible en connaissant le chemin de navigation d'un noued de récupérer le noeud dans l'arbre via la méthode
-
-::
-
- model.findNode("chemin.de.navigation")
-
-Trouver la valeur associée dans le context JAXX à partir du chemin de navigation
-********************************************************************************
-
-Il est possible en connaissant le chemin de navigation d'un noued de récupérer la valeur associée dans le context JAXX.
-
-::
-
- model.getJAXXContextValue(myJAXXContext, "chemin.de.navigation")* .
-
-L'algrotihme est le suivant :
-
- * récupération du noeud associé au chemin de navigation
-
- * recherche du premier noeud (dans les noeuds qui remontent vers la racine de l'arbre) dont la propriété *jaxxContextEntry* est non nulle, il s'agit du point d'entré dans le context JAXX.
-
- * redescendre à partir de ce noeud vers le noeud d'origine (si ce noeud était différent) et en descendant conjointement dans l'objet du context JAXX :
-
- - on utilise l'expression JXPath pour obtenir l'objet associé au noeud
-
-Exemple :
-
-::
-
- "$root" + <-- la racine de l'abre
- |
- + "string" <-- attaché au context JAXX <java.lang.String,"string">
- |
- + "liste" + <-- attaché au context JAXX <java.util.List.class,"liste">
- | |
- | + "0" <-- le premier élément de la liste
- | |
- | + "1" <-- le second élément de la liste
- | |
- | + "2" <-- le troisième élément de la liste
- |
- + "locale" + <-- attaché au context JAXX <java.util.Locale>
- |
- + country
- |
- + language
-
- // preparation du context
- java.util.List myList = java.util.Arrays.asList("one","two","three");
- java.util.Locale myLocale = java.util.Locale.FRENCH;
- context.setContextValue(myList, "liste");
- context.setContextValue("stringValue","string");
- context.setContextValue(myLocale);
-
-
- // récupération des valeurs dans le context à partir de chemin de navigation
- assert model.getJAXXContextValue(context, "$root") == null;
- assert model.getJAXXContextValue(context, "$root.string") == "stringValue";
- assert model.getJAXXContextValue(context, "$root.liste") == myList;
- assert model.getJAXXContextValue(context, "$root.liste.0") == "one";
- assert model.getJAXXContextValue(context, "$root.liste.1") == "two";
- assert model.getJAXXContextValue(context, "$root.liste.2") == "three";
- assert model.getJAXXContextValue(context, "$root.locale") == myLocale;
- assert model.getJAXXContextValue(context, "$root.locale.country") == myLocale.getCountry();
- assert model.getJAXXContextValue(context, "$root.locale.language") == myLocale.getLanguage();
-
-TODO mettre à jour cet exemple suite à l'utilisation de JXPath pour naviguer dans les objets.
-
-A noter qu'une seconde méthode de récupération de valeur du context JAXX est disponible pour pouvoir récupérer cette
-valeur en connaissant le noeud :
-
-::
-
- model.getJAXXContextValue(context, myNode);
-
-jaxx.runtime.swing.navigation.NavigationTreeSelectionAdapter
-============================================================
-
-Il s'agit d'un listener sur la sélection d'un noeud dans l'arbre de navigation basé sur notre modèle de navigation. Il
-étend *javax.swing.event.TreeSelectionListener*.
-
-Ce listener contient la gestion de passage d'un noeud à un autre avec interaction avec le context JAXX et affichage automatique de l'ui associé au noeud sélectionné.
-
-**Attention : la mécanique ne fonctionne que pour un arbre à selection unique.**
-
-Algorithme
-**********
-
-Voici l'algorithme utilisé lors de la sélection d'un nouveau noeud :
-
- * *closeUI* : tentative de fermeture de l'ui lié au noeud précédemment selectionné, si cela n'aboutit pas on retourne sur le noeud précédent.
-
- * *attachBeanFromNodeToContext* : injection dans le context JAXX de la valeur associée au nouveau noeud
-
- * *createUI* : création de la nouvelle ui (si elle n'existe pas)
-
- * *openUI* : ouverture de la nouvelle ui
-
-Si une erreur survient lors de ces opérations, on entre dans la méthode *goBackToPreviousNode* qui est abstraite et permet de notifier les erreur de retourner au noeud précdent.
-
-jaxx.runtime.swing.navigation.NavigationTreeSelectionAdapterWithCardLayout
-**************************************************************************
-
-Il s'agit d'une implantation du listener précédent qui suppose que les uis associées aux noeuds sont affichées dans un
-unique container en utilisant le layout *jaxx.runtime.swing.CardLayout2*.
-
-La contrainte de chaque ui sera extactement le chemin de navigation du noeud associé.
-
-Il possède deux méthodes abstraites :
-
- * *getContentContainer* : qui indique le container d'ui.
-
- * *getContentLayout* : qui indique le layout utilisé.
-
-Pour pouvoir utilisé cet *adapter*, il vous suffit de définir la méthode suivante (en plus des deux méthodes abstraites) :
-
- * *goBackToPreviousNode* : comment gérer les erreurs et retourner au noeud précedent.
-
Modified: trunk/src/site/rst/index.rst
===================================================================
--- trunk/src/site/rst/index.rst 2010-03-11 11:12:44 UTC (rev 1771)
+++ trunk/src/site/rst/index.rst 2010-03-11 11:27:15 UTC (rev 1772)
@@ -43,7 +43,7 @@
* BeanValidator_
- * NavigationTreeModel_
+ * NavigationModel_
Who use JAXX ?
--------------
@@ -75,4 +75,4 @@
.. _BeanValidator: BeanValidator.html
-.. _NavigationTreeModel: NavigationTreeModel.html
+.. _NavigationModel: NavigationModel.html
1
0
r1771 - in trunk: jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation src/site/rst
by sletellier@users.nuiton.org 11 Mar '10
by sletellier@users.nuiton.org 11 Mar '10
11 Mar '10
Author: sletellier
Date: 2010-03-11 12:12:44 +0100 (Thu, 11 Mar 2010)
New Revision: 1771
Log:
Adding multi and treeTable navigation helper documentations
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java
trunk/src/site/rst/NavigationTreeModel.rst
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-11 10:21:02 UTC (rev 1770)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-11 11:12:44 UTC (rev 1771)
@@ -25,11 +25,8 @@
import org.apache.commons.logging.LogFactory;
import org.jdesktop.swingx.tree.TreeModelSupport;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
-import org.jdesktop.swingx.treetable.MutableTreeTableNode;
import org.jdesktop.swingx.treetable.TreeTableNode;
-import javax.swing.table.TableModel;
-import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
Modified: trunk/src/site/rst/NavigationTreeModel.rst
===================================================================
--- trunk/src/site/rst/NavigationTreeModel.rst 2010-03-11 10:21:02 UTC (rev 1770)
+++ trunk/src/site/rst/NavigationTreeModel.rst 2010-03-11 11:12:44 UTC (rev 1771)
@@ -28,6 +28,58 @@
Pour obtenir le chemin de navigation d'un noeud donné, on récupère l'enmseble des neoud depuis la racine vers ce noeud
et les concatène en suffixant par le caractère séparateur défini.
+jaxx.runtime.swing.navigation.NavigationTreeTableModel
+======================================================
+
+Il s'agit du modèle de l'arbre tableau (*org.jdesktop.swingx.JXTreeTable*), c'est une extension d'un *org.jdesktop.swingx.treetable.DefaultTreeTableModel*.
+
+Les noeuds présents dans ce modèle sont typés en *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeTableNode* qui
+étend *jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*.
+
+Cette implmentation est abstaite, l'instance doit
+donc être crée en implementant la méthode createNavigationTreeTableNode du builder (*jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder*).
+
+Les builders
+============
+
+jaxx.runtime.swing.navigation.NavigationModelBuilder
+----------------------------------------------------
+
+Les builders sont des classes utilitaires permetant de construire le model et les rendus de l'arbre simplement.
+Tous les builders implémentes cette interface.
+
+jaxx.runtime.swing.navigation.NavigationTreeModelBuilder
+--------------------------------------------------------
+
+Classe utilitaire pour construire le model (ici un *jaxx.runtime.swing.navigation.NavigationTreeModel*) et décorer un arbre.
+
+jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder
+-------------------------------------------------------------
+
+Classe utilitaire pour construire le model (ici un *jaxx.runtime.swing.navigation.NavigationTreeTableModel*) et décorer un arbre tableau.
+
+Les Handlers
+============
+
+jaxx.runtime.swing.navigation.NavigationTreeHandler
+---------------------------------------------------
+
+Cette classe est une implémentation d'un model de sélection pour les arbres de navigations.
+
+Il y a 2 façons de l'utiliser, soit l'on associe une ui par noeud (*Strategy.PER_NODE*) soit on associe une ui par type de noeud (*Strategy.PER_UI_TYPE*).
+
+jaxx.runtime.swing.navigation.NavigationTreeHandlerWithCardLayout
+-----------------------------------------------------------------
+
+Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour l'utilisation de CardLayout (*jaxx.runtime.swing.CardLayout2*).
+
+jaxx.runtime.swing.navigation.NavigationMultiTreeHandler
+--------------------------------------------------------
+
+TODO ajouter la strategie de la multiselection
+
+Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour ajouter la possibilité d'utiliser la multiselection.
+
Définition d'un noeud
=====================
1
0
r1770 - in trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing: . editor editor/config editor/config/model
by tchemit@users.nuiton.org 11 Mar '10
by tchemit@users.nuiton.org 11 Mar '10
11 Mar '10
Author: tchemit
Date: 2010-03-11 11:21:02 +0100 (Thu, 11 Mar 2010)
New Revision: 1770
Log:
add package javadoc
Added:
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/package.html
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/package.html
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/package.html
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/package.html
Modified:
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx 2010-03-11 10:05:07 UTC (rev 1769)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigCallBackUI.jaxx 2010-03-11 10:21:02 UTC (rev 1770)
@@ -25,23 +25,15 @@
</JScrollPane>
- <!--JPanel constraints='BorderLayout.SOUTH' layout='{new BorderLayout()}'>
-
- <JPanel constraints='BorderLayout.CENTER'
- border='{new TitledBorder(_("config.callBack.description"))}'>
- <JLabel id='callBackDescription'/>
- </JPanel-->
-
<JButton constraints='BorderLayout.SOUTH'
id='go'
text='config.launch.callBack'
toolTipText='config.launch.callBack.tip'
actionIcon='config-quit'
onActionPerformed='getHandler().doAction(this)'/>
- <!--/JPanel-->
<JPanel id='treeHeader' constraints='BorderLayout.EAST'>
<JLabel text='config.detected.callBack'/>
</JPanel>
-</JPanel>
\ No newline at end of file
+</JPanel>
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/package.html
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/package.html (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/package.html 2010-03-11 10:21:02 UTC (rev 1770)
@@ -0,0 +1,7 @@
+<html>
+<body>
+<h1>Package jaxx.runtime.swing.editor.config.model</h1>
+
+the package contains the models of the Config UI.
+</body>
+</html>
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/package.html
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/package.html (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/package.html 2010-03-11 10:21:02 UTC (rev 1770)
@@ -0,0 +1,18 @@
+<html>
+<body>
+<h1>Package jaxx.runtime.swing.editor.config</h1>
+
+This package contains the Config ui, based on org.nuiton.util.ApplicationConfig.
+
+The config ui is categorized and offers possibility to add callbacks to run
+when configuration was saved.
+
+<hr/>
+<ul>
+ <li>
+ ConfigUIBuilder offers you a simple way to build the ConfigUI (and his
+ model).
+ </li>
+</ul>
+</body>
+</html>
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/package.html
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/package.html (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/package.html 2010-03-11 10:21:02 UTC (rev 1770)
@@ -0,0 +1,12 @@
+<html>
+<body>
+<h1>Package jaxx.runtime.swing.editor</h1>
+
+Package containing several richi editors :
+<ul>
+ <li>NumberEditor : a rich number editor with a calculator on popup</li>
+ <li>TimeEditor : a rich time editor based on JSpinner components</li>
+ <li>I18nEditor : a rich locale editor</li>
+</ul>
+</body>
+</html>
Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/package.html
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/package.html (rev 0)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/package.html 2010-03-11 10:21:02 UTC (rev 1770)
@@ -0,0 +1,25 @@
+<html>
+<body>
+<h1>Package jaxx.runtime.swing</h1>
+
+<p>
+ Base package of the project <strong>jaxx-widgets</strong>.
+</p>
+
+In this package, we can find several simple widgets :
+
+<ul>
+ <li>AboutPanel : an About dialog ui</li>
+ <li>ClockWidget : a widget which displays time</li>
+ <li>EntityComboBox : a rich drop list of beans based on Decorator api</li>
+ <li>ErrordialogUI : error dialog to use each time there is an error</li>
+ <li>FontSizor : a widget to change font size</li>
+ <li>HidorButton : a simple widget to show and hide components</li>
+ <li>ListSelectorUI :</li>
+ <li>MemoryStatusWidget : a widget to display memory usage</li>
+ <li>StatusMessagePanel : a panel to display messages and show status of
+ application (busy, waking, ...)
+ </li>
+</ul>
+</body>
+</html>
1
0
r1769 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by sletellier@users.nuiton.org 11 Mar '10
by sletellier@users.nuiton.org 11 Mar '10
11 Mar '10
Author: sletellier
Date: 2010-03-11 11:05:07 +0100 (Thu, 11 Mar 2010)
New Revision: 1769
Log:
Remove comments
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-10 23:49:05 UTC (rev 1768)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-11 10:05:07 UTC (rev 1769)
@@ -134,16 +134,6 @@
public String getSelectedPath(JAXXContext context) {
String result = getSelectedValue(getSelectedPathContextEntry(),context);
return result;
-// List<String> values = getSelectedPathContextEntry().getContextValue(context);
-// if (values == null){
-// return null;
-// }
-// if (log.isWarnEnabled()){
-// if (values.size() > 1){
-// log.warn("More than one values are selected, return first one");
-// }
-// }
-// return values.get(0);
}
public List<String> getSelectedPaths(JAXXContext context) {
@@ -153,16 +143,6 @@
public NavigationTreeNode getSelectedNode(JAXXContext context) {
NavigationTreeNode result = getSelectedValue(getSelectedNodeContextEntry(),context);
return result;
-// List<NavigationTreeNode> values = getSelectedNodeContextEntry().getContextValue(context);
-// if (values == null){
-// return null;
-// }
-// if (log.isWarnEnabled()){
-// if (values.size() > 1){
-// log.warn("More than one values are selected, return first one");
-// }
-// }
-// return values.get(0);
}
public List<NavigationTreeNode> getSelectedNodes(JAXXContext context) {
@@ -172,27 +152,12 @@
public Object getSelectedBean(JAXXContext context) {
Object result = getSelectedValue(getSelectedBeanContextEntry(),context);
return result;
-// List<Object> values = getSelectedBeanContextEntry().getContextValue(context);
-// if (values == null){
-// return null;
-// }
-// if (log.isWarnEnabled()){
-// if (values.size() > 1){
-// log.warn("More than one values are selected, return first one");
-// }
-// }
-// return values.get(0);
}
public List<Object> getSelectedBeans(JAXXContext context) {
return getSelectedBeanContextEntry().getContextValue(context);
}
-// public Component getSelectedUI(JAXXContext context) {
-// Component r = getSelectedUIContextEntry().getContextValue(context);
-// return r;
-// }
-
/**
* @param context where to store model
* @param model model to store
@@ -223,62 +188,26 @@
public void setSelectedPath(JAXXContext context, String path) {
setSelectedValue(getSelectedPathContextEntry(), context, path);
-// if (path == null) {
-// getSelectedPathContextEntry().removeContextValue(context);
-// } else {
-// List<String> selecteds = new ArrayList<String>();
-// selecteds.add(path);
-// getSelectedPathContextEntry().setContextValue(context, selecteds);
-// }
}
public void setSelectedPaths(JAXXContext context, List<String> paths) {
setSelectedValues(getSelectedPathContextEntry(), context, paths);
-// if (paths == null || paths.isEmpty()) {
-// getSelectedPathContextEntry().removeContextValue(context);
-// } else {
-// getSelectedPathContextEntry().setContextValue(context, paths);
-// }
}
public void setSelectedNode(JAXXContext context, NavigationTreeNode node) {
setSelectedValue(getSelectedNodeContextEntry(), context, node);
-// if (node == null) {
-// getSelectedNodeContextEntry().removeContextValue(context);
-// } else {
-// List<NavigationTreeNode> selecteds = new ArrayList<NavigationTreeNode>();
-// selecteds.add(node);
-// getSelectedNodeContextEntry().setContextValue(context, selecteds);
-// }
}
public void setSelectedNodes(JAXXContext context, List<NavigationTreeNode> nodes) {
setSelectedValues(getSelectedNodeContextEntry(), context, nodes);
-// if (nodes == null || nodes.isEmpty()) {
-// getSelectedNodeContextEntry().removeContextValue(context);
-// } else {
-// getSelectedNodeContextEntry().setContextValue(context, nodes);
-// }
}
public void setSelectedBean(JAXXContext context, Object bean) {
setSelectedValue(getSelectedBeanContextEntry(), context, bean);
-// if (bean == null) {
-// getSelectedBeanContextEntry().removeContextValue(context);
-// } else {
-// List<Object> selecteds = new ArrayList<Object>();
-// selecteds.add(bean);
-// getSelectedBeanContextEntry().setContextValue(context, selecteds);
-// }
}
public void setSelectedBeans(JAXXContext context, List<Object> beans) {
setSelectedValues(getSelectedBeanContextEntry(), context, beans);
-// if (beans == null || beans.isEmpty()) {
-// getSelectedBeanContextEntry().removeContextValue(context);
-// } else {
-// getSelectedBeanContextEntry().setContextValue(context, beans);
-// }
}
protected JAXXContextEntryDef<NavigationModel> getModelContextEntry() {
1
0
r1768 - in trunk/jaxx-runtime/src/main/java/jaxx/runtime: . swing/editor swing/navigation
by tchemit@users.nuiton.org 10 Mar '10
by tchemit@users.nuiton.org 10 Mar '10
10 Mar '10
Author: tchemit
Date: 2010-03-11 00:49:05 +0100 (Thu, 11 Mar 2010)
New Revision: 1768
Log:
- fix javadoc
- reformat code
- use none deprecated api
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/editor/LocaleEditor.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-03-10 22:28:59 UTC (rev 1767)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-03-10 23:49:05 UTC (rev 1768)
@@ -21,6 +21,7 @@
package jaxx.runtime;
import jaxx.runtime.context.JAXXContextEntryDef;
+import jaxx.runtime.context.JAXXInitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -36,17 +37,22 @@
public class JAXXUtil {
- // public static final String DEFAULT_ICON_PATH = "/icons/";
- // public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path";
/**
* Logger
*/
static private final Log log = LogFactory.getLog(JAXXUtil.class);
+
public static final String PARENT = "parent";
+
// Maps root objects to lists of event listeners
- private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
- private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>();
+ private static Map<Object, WeakReference<List<EventListenerDescriptor>>>
+ eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>();
+ private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>
+ dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>();
+
+ private static final PropertyChangeListener[] EMPTY_ARRAY_PROPERTY_CHANGE_LISTENERS = new PropertyChangeListener[0];
+
private static class EventListenerDescriptor {
Class<?> listenerClass;
@@ -63,9 +69,11 @@
* @param descriptor descriptor to decode
* @return the dedoced descriptor
*/
- public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(String descriptor) {
+ public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(
+ String descriptor) {
try {
- return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, false);
+ return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor,
+ false);
/*byte[] data = new byte[descriptor.length()];
// copy low-order bytes into the array. The high-order bytes should all be zero.
System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length);
@@ -79,9 +87,11 @@
}
}
- public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(String descriptor) {
+ public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(
+ String descriptor) {
try {
- return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, true);
+ return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor,
+ true);
/*byte[] data = new byte[descriptor.length()];
// copy low-order bytes into the array. The high-order bytes should all be zero.
@@ -96,11 +106,13 @@
}
}
- public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) {
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(
+ Class<O> klass) {
return newContextEntryDef(null, klass);
}
- public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) {
+ public static <O> JAXXContextEntryDef<O> newContextEntryDef(
+ String name, Class<O> klass) {
return new JAXXContextEntryDef<O>(name, klass);
}
@@ -108,42 +120,14 @@
return newListContextEntryDef(null);
}
- public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) {
- Class<List<O>> castList = JAXXUtil.castList();
- JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name, castList);
+ public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(
+ String name) {
+ Class<List<O>> castList = castList();
+ JAXXContextEntryDef<List<O>> contextEntryDef =
+ new JAXXContextEntryDef<List<O>>(name, castList);
return contextEntryDef;
}
-// public static DefaultJAXXBinding registerBinding(Map<String, DefaultJAXXBinding> bindings, DefaultJAXXBinding binding) {
-// bindings.put(binding.getId(), binding);
-//// binding.applyDataBinding();
-//// binding.processDataBinding();
-// return binding;
-// }
-
-// /**
-// * Return parent's container corresponding to the Class clazz
-// *
-// * @param <O> type of container to obtain from context
-// * @param top the top container
-// * @param clazz desired
-// * @return parent's container
-// */
-// @SuppressWarnings({"unchecked"})
-// public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) {
-// if (top == null) {
-// throw new IllegalArgumentException("top parameter can not be null");
-// }
-// if (!Container.class.isAssignableFrom(top.getClass())) {
-// throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class);
-// }
-// Container parent = ((Container) top).getParent();
-// if (parent != null && !clazz.isAssignableFrom(parent.getClass())) {
-// parent = getParentContainer(parent, clazz);
-// }
-// return (O) parent;
-// }
-
@SuppressWarnings({"unchecked"})
protected static <O> Class<List<O>> castList() {
return (Class<List<O>>) Collections.emptyList().getClass();
@@ -157,8 +141,8 @@
*/
public static void initContext(JAXXObject ui, JAXXContext parentContext) {
- if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) {
- ((jaxx.runtime.context.JAXXInitialContext) parentContext).to(ui);
+ if (parentContext instanceof JAXXInitialContext) {
+ ((JAXXInitialContext) parentContext).to(ui);
} else {
ui.setContextValue(parentContext);
}
@@ -169,16 +153,29 @@
}
}
- public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) {
- WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer);
- List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null;
+ public static <E extends EventListener> E getEventListener(
+ Class<E> listenerClass,
+ final String listenerMethodName,
+ final Object methodContainer,
+ String methodName) {
+
+ WeakReference<List<EventListenerDescriptor>> ref =
+ eventListeners.get(methodContainer);
+ List<EventListenerDescriptor> descriptors = ref != null ?
+ ref.get() : null;
if (descriptors == null) {
descriptors = new ArrayList<EventListenerDescriptor>();
- eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors));
+ eventListeners.put(
+ methodContainer,
+ new WeakReference<List<EventListenerDescriptor>>(
+ descriptors));
} else {
for (EventListenerDescriptor descriptor : descriptors) {
- if (listenerClass == descriptor.listenerClass &&
- (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) &&
+ if (descriptor.listenerClass.equals(listenerClass) &&
+ (listenerMethodName == null ?
+ descriptor.listenerMethodName == null :
+ listenerMethodName.equals(
+ descriptor.listenerMethodName)) &&
methodName.equals(descriptor.methodName)) {
return (E) descriptor.eventListener;
}
@@ -191,35 +188,48 @@
descriptor.listenerMethodName = listenerMethodName;
descriptor.methodName = methodName;
try {
- final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods());
+ final List<Method> listenerMethods =
+ Arrays.asList(listenerClass.getMethods());
Method listenerMethod = null;
if (listenerMethodName != null) {
for (Method listenerMethod1 : listenerMethods) {
- if ((listenerMethod1).getName().equals(listenerMethodName)) {
+ if (listenerMethod1.getName().equals(listenerMethodName)) {
listenerMethod = listenerMethod1;
break;
}
}
}
if (listenerMethodName != null && listenerMethod == null) {
- throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName());
+ throw new IllegalArgumentException(
+ "no method named " + listenerMethodName +
+ " found in class " + listenerClass.getName());
}
- Class<?>[] parameterTypes = listenerMethods.get(0).getParameterTypes();
+ Class<?>[] parameterTypes =
+ listenerMethods.get(0).getParameterTypes();
Class<?> methodContainerClass = methodContainer.getClass();
- final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes);
- descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(),
+ final Method targetMethod =
+ methodContainerClass.getMethod(methodName, parameterTypes);
+ descriptor.eventListener =
+ Proxy.newProxyInstance(listenerClass.getClassLoader(),
new Class<?>[]{listenerClass},
new InvocationHandler() {
@Override
- public Object invoke(Object proxy, Method method, Object[] args) {
+ public Object invoke(Object proxy,
+ Method method,
+ Object[] args) {
String methodName = method.getName();
- if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) {
+ if ((listenerMethodName == null &&
+ listenerMethods.contains(method)) ||
+ methodName.equals(listenerMethodName)) {
try {
targetMethod.setAccessible(true);
- return targetMethod.invoke(methodContainer, args);
+ return targetMethod.invoke(
+ methodContainer, args);
} catch (IllegalAccessException e) {
- throw new RuntimeException("could not invoke on container " + methodContainer, e);
+ throw new RuntimeException(
+ "could not invoke on container " +
+ methodContainer, e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
@@ -243,16 +253,26 @@
}
}
- public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final Object methodContainer, final String methodName) {
- return getEventListener(listenerClass, null, methodContainer, methodName);
+ public static <E extends EventListener> E getEventListener(
+ Class<E> listenerClass,
+ Object methodContainer,
+ String methodName) {
+ return getEventListener(listenerClass, null, methodContainer,
+ methodName);
}
- public static DataBindingUpdateListener getDataBindingUpdateListener(JAXXObject object, String bindingName) {
- WeakReference<List<DataBindingUpdateListener>> ref = dataBindingUpdateListeners.get(object);
- List<DataBindingUpdateListener> listeners = ref == null ? null : ref.get();
+ public static DataBindingUpdateListener getDataBindingUpdateListener(
+ JAXXObject object, String bindingName) {
+ WeakReference<List<DataBindingUpdateListener>> ref =
+ dataBindingUpdateListeners.get(object);
+ List<DataBindingUpdateListener> listeners = ref == null ? null :
+ ref.get();
if (listeners == null) {
listeners = new ArrayList<DataBindingUpdateListener>();
- dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners));
+ dataBindingUpdateListeners.put(
+ object,
+ new WeakReference<List<DataBindingUpdateListener>>(
+ listeners));
} else {
for (DataBindingUpdateListener listener : listeners) {
if (bindingName.equals(listener.getBindingName())) {
@@ -260,7 +280,8 @@
}
}
}
- DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName);
+ DataBindingUpdateListener listener =
+ new DataBindingUpdateListener(object, bindingName);
listeners.add(listener);
return listener;
}
@@ -329,7 +350,7 @@
return value;
}
- public static java.lang.Object assignment(java.lang.Object value, String name, JAXXObject src) {
+ public static Object assignment(Object value, String name, JAXXObject src) {
src.firePropertyChange(name.trim(), null, "dummy value");
return value;
}
@@ -340,7 +361,8 @@
* Return empty string if given object is null
*
* @param value the value to write
- * @return the string representation of the given object or an empty string if object is null.
+ * @return the string representation of the given object or an empty
+ * string if object is null.
*/
public static String getStringValue(Object value) {
String result;
@@ -349,7 +371,8 @@
}
/**
- * Test if a type of entry exists in a given context and throw an IllegalArgumentException if not found.
+ * Test if a type of entry exists in a given context and throw an
+ * IllegalArgumentException if not found.
* <p/>
* If entry is found, return his value in context.
*
@@ -359,12 +382,16 @@
* @return the value from the context
* @throws IllegalArgumentException if the entry is not found in context.
*/
- public static <T> T checkJAXXContextEntry(JAXXContext context, JAXXContextEntryDef<T> def) throws IllegalArgumentException {
+ public static <T> T checkJAXXContextEntry(JAXXContext context,
+ JAXXContextEntryDef<T> def)
+ throws IllegalArgumentException {
T value = def.getContextValue(context);
if (value == null) {
- throw new IllegalArgumentException("the context entry [" + def + "] ] was not found in context " + context);
+ throw new IllegalArgumentException(
+ "the context entry [" + def + "] ] was not found in " +
+ "context " + context);
}
return value;
@@ -387,7 +414,8 @@
* @param src the ui to treate
* @param bindings the list of binding to process.
*/
- public static void applyDataBinding(JAXXObject src, Collection<String> bindings) {
+ public static void applyDataBinding(JAXXObject src,
+ Collection<String> bindings) {
for (String binding : bindings) {
src.applyDataBinding(binding);
}
@@ -417,52 +445,6 @@
}
}
-// public static ImageIcon createIcon(String path) {
-// java.net.URL imgURL = JAXXUtil.class.getResource(path);
-// if (imgURL != null) {
-// return new ImageIcon(imgURL);
-// } else {
-// throw new IllegalArgumentException("could not find icon " + path);
-// }
-// }
-
-// /**
-// * @param path the location of icons in root directory icons
-// * @return the icon at {@link #getIconPath()}+path
-// */
-// public static ImageIcon createImageIcon(String path) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + path);
-// }
-//
-// /**
-// * @param key the key of the icon to retreave from {@link UIManager}
-// * @return the icon, or <code>null if no icon found in {@link UIManager}
-// */
-// public static Icon getUIManagerIcon(String key) {
-// return UIManager.getIcon(key);
-// }
-//
-// /**
-// * retreave for the {@link UIManager} the icon prefixed by <code>action.</code>
-// *
-// * @param key the key of the action icon to retreave from {@link UIManager}
-// * @return the icon, or <code>null if no icon found in {@link UIManager}
-// */
-// public static Icon getUIManagerActionIcon(String key) {
-// return getUIManagerIcon("action." + key);
-// }
-//
-// public static ImageIcon createActionIcon(String name) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + "action-" + name + ".png");
-// }
-//
-// public static ImageIcon createI18nIcon(String name) {
-// String iconPath = getIconPath();
-// return createIcon(iconPath + "i18n/" + name + ".png");
-// }
-
/**
* detects all PropertychangedListener added by Jaxx uis
* (should be a {@link DataBindingListener}
@@ -471,13 +453,15 @@
* @param listeners the array of listeners to filter
* @return the filtered listeners
*/
- public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) {
+ public static PropertyChangeListener[] findJaxxPropertyChangeListener(
+ String[] propertyNames, PropertyChangeListener... listeners) {
if (listeners == null || listeners.length == 0) {
- return new PropertyChangeListener[0];
+ return EMPTY_ARRAY_PROPERTY_CHANGE_LISTENERS;
}
List<String> pNames = Arrays.asList(propertyNames);
- List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>();
+ List<PropertyChangeListener> toRemove =
+ new ArrayList<PropertyChangeListener>();
for (PropertyChangeListener listener : listeners) {
String pName = null;
@@ -491,9 +475,12 @@
listener = (PropertyChangeListener) plistener.getListener();
pName = plistener.getPropertyName();
}
- if (plistener != null && pName != null && listener instanceof DataBindingListener) {
+ if (plistener != null &&
+ pName != null &&
+ listener instanceof DataBindingListener) {
if (log.isDebugEnabled()) {
- log.debug("find config listener to remove [" + pName + "] : " + listener);
+ log.debug("find config listener to remove [" + pName +
+ "] : " + listener);
}
toRemove.add(plistener);
//toRemove.add(listener);
@@ -502,15 +489,4 @@
return toRemove.toArray(new PropertyChangeListener[toRemove.size()]);
}
-// private static String getIconPath() {
-// String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY);
-// if (iconPath == null) {
-// iconPath = DEFAULT_ICON_PATH;
-// } else {
-// if (!iconPath.endsWith("/")) {
-// iconPath += "/";
-// }
-// }
-// return iconPath;
-// }
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-03-10 22:28:59 UTC (rev 1767)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-03-10 23:49:05 UTC (rev 1768)
@@ -59,7 +59,6 @@
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
import jaxx.runtime.swing.renderer.BooleanCellRenderer;
import jaxx.runtime.swing.renderer.EmptyNumberTableCellRenderer;
import jaxx.runtime.swing.renderer.EnumTableCellRenderer;
@@ -85,11 +84,17 @@
* to use log facility, just put in your code: log.info(\"...\");
*/
static private final Log log = LogFactory.getLog(SwingUtil.class);
+
public static final String DEFAULT_ICON_PATH = "/icons/";
+
public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path";
+
private static Field numReaders;
+
private static Field notifyingListeners;
+
public static final String ICON_PREFIX = "icon.";
+
public static final String COLOR_PREFIX = "color.";
public static Dimension newMinDimension() {
@@ -161,9 +166,12 @@
* @param data data ot inject in combo
* @param select the object to select in combo after reflling his model
*/
- public static void fillComboBox(JComboBox combo, Collection<?> data, Object select) {
+ public static void fillComboBox(JComboBox combo, Collection<?> data,
+ Object select) {
if (!(combo.getModel() instanceof DefaultComboBoxModel)) {
- throw new IllegalArgumentException("this method need a DefaultComboBoxModel for this model but was " + combo.getModel().getClass());
+ throw new IllegalArgumentException(
+ "this method need a DefaultComboBoxModel for " +
+ "this model but was " + combo.getModel().getClass());
}
DefaultComboBoxModel model = (DefaultComboBoxModel) combo.getModel();
// evince the model
@@ -188,7 +196,9 @@
*/
public static void fillList(JList list, Collection<?> data, Object select) {
if (!(list.getModel() instanceof DefaultListModel)) {
- throw new IllegalArgumentException("this method need a DefaultListModel for this model but was " + list.getModel().getClass());
+ throw new IllegalArgumentException(
+ "this method need a DefaultListModel for this model " +
+ "but was " + list.getModel().getClass());
}
DefaultListModel model = (DefaultListModel) list.getModel();
// evince the model
@@ -216,14 +226,18 @@
* @deprecated since 1.7.XXX this code is moved to JAXXComboBox
*/
@Deprecated
- public static void fillComboBox(JAXXComboBox combo, Collection<?> data, Object select, boolean firstNull) {
+ public static void fillComboBox(JAXXComboBox combo,
+ Collection<?> data,
+ Object select, boolean firstNull) {
List<Item> items = new ArrayList<Item>();
if (firstNull) {
items.add(new Item("null", " ", null, false));
}
if (data != null) {
for (Object d : data) {
- items.add(new Item(d.toString(), d.toString(), d, d.equals(select)));
+ Item item = new Item(d.toString(), d.toString(), d,
+ d.equals(select));
+ items.add(item);
}
}
combo.setItems(items);
@@ -238,12 +252,14 @@
* @return parent's container
*/
@SuppressWarnings({"unchecked"})
- public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) {
+ public static <O extends Container> O getParentContainer(Object top,
+ Class<O> clazz) {
if (top == null) {
throw new IllegalArgumentException("top parameter can not be null");
}
if (!Container.class.isAssignableFrom(top.getClass())) {
- throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class);
+ throw new IllegalArgumentException("top parameter " + top +
+ " is not a " + Container.class);
}
Container parent = ((Container) top).getParent();
if (parent != null && !clazz.isAssignableFrom(parent.getClass())) {
@@ -252,7 +268,9 @@
return (O) parent;
}
- public static int computeTableColumnWidth(JTable table, Font font, int columnIndex, String suffix) {
+ public static int computeTableColumnWidth(JTable table,
+ Font font,
+ int columnIndex, String suffix) {
int width = 0;
if (font == null) {
font = table.getFont();
@@ -272,7 +290,9 @@
return width;
}
- public static void fixTableColumnWidth(JTable table, int columnIndex, int width) {
+ public static void fixTableColumnWidth(JTable table,
+ int columnIndex,
+ int width) {
TableColumn column = table.getColumnModel().getColumn(columnIndex);
column.setMaxWidth(width);
column.setMinWidth(width);
@@ -280,37 +300,69 @@
column.setPreferredWidth(width);
}
- public static void setTableColumnEditor(JTable table, int columnIndex, TableCellEditor editor) {
+ public static void setTableColumnEditor(JTable table,
+ int columnIndex,
+ TableCellEditor editor) {
TableColumn column = table.getColumnModel().getColumn(columnIndex);
column.setCellEditor(editor);
}
- public static void setTableColumnRenderer(JTable table, int columnIndex, TableCellRenderer editor) {
+ public static void setTableColumnRenderer(JTable table,
+ int columnIndex,
+ TableCellRenderer editor) {
TableColumn column = table.getColumnModel().getColumn(columnIndex);
column.setCellRenderer(editor);
}
- public static void setI18nTableHeaderRenderer(JTable table, String... libelles) {
- table.getTableHeader().setDefaultRenderer(new I18nTableCellRenderer(table.getTableHeader().getDefaultRenderer(), libelles));
+ public static void setI18nTableHeaderRenderer(JTable table,
+ String... libelles) {
+ I18nTableCellRenderer defaultRenderer =
+ new I18nTableCellRenderer(
+ table.getTableHeader().getDefaultRenderer(), libelles);
+ table.getTableHeader().setDefaultRenderer(defaultRenderer);
}
- public static TableCellRenderer newStringTableCellRenderer(final DefaultTableCellRenderer renderer, final int length, final boolean tooltip) {
+ public static TableCellRenderer newStringTableCellRenderer(
+ final DefaultTableCellRenderer renderer,
+ final int length,
+ final boolean tooltip) {
return new DefaultTableCellRenderer() {
private static final long serialVersionUID = 1l;
@Override
- public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+ public Component getTableCellRendererComponent(
+ JTable table,
+ Object value,
+ boolean isSelected,
+ boolean hasFocus,
+ int row,
+ int column) {
- renderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
+ renderer.getTableCellRendererComponent(
+ table,
+ value,
+ isSelected,
+ hasFocus,
+ row,
+ column
+ );
String val = renderer.getText();
String val2 = val;
if (val.length() > length) {
val2 = val.substring(0, length - 3) + "...";
}
- JComponent comp = (JComponent) super.getTableCellRendererComponent(table, val2, isSelected, hasFocus, row, column);
+ JComponent comp = (JComponent)
+ super.getTableCellRendererComponent(
+ table,
+ val2,
+ isSelected,
+ hasFocus,
+ row,
+ column
+ );
if (tooltip) {
comp.setToolTipText(val);
}
@@ -320,17 +372,17 @@
}
/**
- * Box a component in a {@link org.jdesktop.jxlayer.JXLayer}.
+ * Box a component in a {@link JXLayer}.
*
* @param component the component to box
- * @return the {@link org.jdesktop.jxlayer.JXLayer} boxing the component
+ * @return the {@link JXLayer} boxing the component
*/
public static JXLayer<?> boxComponentWithJxLayer(JComponent component) {
JXLayer<?> layer = getLayer(component);
if (layer != null) {
return layer;
}
- layer = new org.jdesktop.jxlayer.JXLayer<JComponent>();
+ layer = new JXLayer<JComponent>();
layer.add(component);
return layer;
}
@@ -378,15 +430,19 @@
* @param container le container ou rechercher les composants d'edition
* @return le dictionnaire des composants recherches.
*/
- public static Map<String, JComponent> lookingForEditor(Class<?> clazz, Container container) {
+ public static Map<String, JComponent> lookingForEditor(
+ Class<?> clazz,
+ Container container) {
Map<String, JComponent> result = new HashMap<String, JComponent>();
try {
// looking for all component with name set
- Map<String, JComponent> allNamedComponent = new HashMap<String, JComponent>();
+ Map<String, JComponent> allNamedComponent =
+ new HashMap<String, JComponent>();
List<Container> todo = new LinkedList<Container>();
todo.add(container);
while (todo.size() > 0) {
- for (ListIterator<Container> i = todo.listIterator(); i.hasNext();) {
+ for (ListIterator<Container> i = todo.listIterator();
+ i.hasNext();) {
Container parent = i.next();
i.remove();
for (Component c : parent.getComponents()) {
@@ -463,13 +519,17 @@
}
/**
- * Load the ui.properties file and set in {@link UIManager} colors and icons found.
+ * Load the ui.properties file and set in {@link UIManager} colors and
+ * icons found.
*
- * @param defaultUIConfig le path vers le fichier de la config d'ui par défaut (doit etre dansle class-path)
- * @param extraUIConfig le path vers une surcharge de la config d'ui (doit etre dans le class-path)
+ * @param defaultUIConfig le path vers le fichier de la config d'ui par
+ * défaut (doit etre dansle class-path)
+ * @param extraUIConfig le path vers une surcharge de la config d'ui
+ * (doit etre dans le class-path)
* @throws IOException if could not load the ui.properties file
*/
- public static void loadUIConfig(String defaultUIConfig, String extraUIConfig) throws IOException {
+ public static void loadUIConfig(String defaultUIConfig,
+ String extraUIConfig) throws IOException {
Properties p = new Properties();
log.info("loading default UI config " + defaultUIConfig);
@@ -478,7 +538,8 @@
log.debug(p.toString());
}
if (extraUIConfig != null) {
- InputStream extraStream = SwingUtil.class.getResourceAsStream(extraUIConfig);
+ InputStream extraStream =
+ SwingUtil.class.getResourceAsStream(extraUIConfig);
if (extraStream == null) {
log.warn("could not find extraUIConfig : " + extraUIConfig);
} else {
@@ -506,7 +567,14 @@
if (key.startsWith(COLOR_PREFIX)) {
String value = (String) entry.getValue();
String[] rgb = value.split(",");
- UIManager.put(key.substring(COLOR_PREFIX.length()), new Color(Integer.valueOf(rgb[0]), Integer.valueOf(rgb[1]), Integer.valueOf(rgb[2])));
+ UIManager.put(
+ key.substring(COLOR_PREFIX.length()),
+ new Color(
+ Integer.valueOf(rgb[0]),
+ Integer.valueOf(rgb[1]),
+ Integer.valueOf(rgb[2])
+ )
+ );
}
}
}
@@ -520,7 +588,8 @@
* @return the iterator
* @since 1.4
*/
- public static TabbedPaneIterator<Component> newTabbedPaneIterator(JTabbedPane tabs) {
+ public static TabbedPaneIterator<Component> newTabbedPaneIterator(
+ JTabbedPane tabs) {
return new TabbedPaneIterator<Component>(false, tabs) {
@Override
@@ -533,7 +602,7 @@
/**
* A simple iterator on a {@link JTabbedPane}.
* <p/>
- * Implements the method {@link #get(int, java.awt.Component)} to obtain
+ * Implements the method {@link #get(int, Component)} to obtain
* the data required given the component (or index).
* <p/>
* You can also inverse the order by usin the method {@link #reverse()}.
@@ -598,7 +667,8 @@
@Override
public String toString() {
- return super.toString() + "< reverse:" + reverse + ", index:" + index + ", size:" + tabs.getTabCount() + " >";
+ return super.toString() + "< reverse:" + reverse + ", index:" +
+ index + ", size:" + tabs.getTabCount() + " >";
}
protected void setReverse(boolean reverse) {
@@ -643,7 +713,9 @@
if (parent instanceof Container) {
Container cont = (Container) parent;
// use a copy of 1.3 Container.findComponentAt
- Component child = findComponentAt(cont, cont.getWidth(), cont.getHeight(), x, y);
+ Component child = findComponentAt(cont,
+ cont.getWidth(),
+ cont.getHeight(), x, y);
if (child != null && child != cont) {
//log.info("child find : " + child.getName());
if (child instanceof JRootPane) {
@@ -662,11 +734,16 @@
return parent;
}
- public static Component findComponentAt(Container cont, int width, int height, int x, int y) {
+ public static Component findComponentAt(Container cont,
+ int width,
+ int height,
+ int x,
+ int y) {
//log.info("container : " + cont.getName());
synchronized (cont.getTreeLock()) {
- if (!((x >= 0) && (x < width) && (y >= 0) && (y < height) && cont.isVisible() && cont.isEnabled())) {
+ if (!(x >= 0 && x < width && y >= 0 && y < height &&
+ cont.isVisible() && cont.isEnabled())) {
return null;
}
@@ -687,7 +764,13 @@
comp = layer.getView();
}
if (comp instanceof Container) {
- comp = findComponentAt((Container) comp, rect.width, rect.height, x - rect.x, y - rect.y);
+ comp = findComponentAt(
+ (Container) comp,
+ rect.width,
+ rect.height,
+ x - rect.x,
+ y - rect.y
+ );
} else {
comp = comp.getComponentAt(x - rect.x, y - rect.y);
}
@@ -710,7 +793,13 @@
comp = layer.getView();
}
if (comp instanceof Container) {
- comp = findComponentAt((Container) comp, rect.width, rect.height, x - rect.x, y - rect.y);
+ comp = findComponentAt(
+ (Container) comp,
+ rect.width,
+ rect.height,
+ x - rect.x,
+ y - rect.y
+ );
} else {
comp = comp.getComponentAt(x - rect.x, y - rect.y);
}
@@ -723,7 +812,8 @@
}
}
- public static TableCellRenderer newDeleteCellRenderer(DefaultTableCellRenderer renderer) {
+ public static TableCellRenderer newDeleteCellRenderer(
+ DefaultTableCellRenderer renderer) {
Icon icon = UIManager.getIcon("Table.removeIcon");
if (icon == null) {
// try with default icon
@@ -732,15 +822,18 @@
return new BooleanCellRenderer(renderer, icon);
}
- public static TableCellRenderer newBooleanTableCellRenderer(DefaultTableCellRenderer renderer) {
+ public static TableCellRenderer newBooleanTableCellRenderer(
+ DefaultTableCellRenderer renderer) {
return new BooleanCellRenderer(renderer);
}
- public static EmptyNumberTableCellRenderer newEmptyNumberTableCellRenderer(TableCellRenderer renderer) {
+ public static EmptyNumberTableCellRenderer newEmptyNumberTableCellRenderer(
+ TableCellRenderer renderer) {
return new EmptyNumberTableCellRenderer(renderer);
}
- public static <E extends Enum<E>> EnumTableCellRenderer<E> newEnumTableCellRenderer(TableCellRenderer renderer, Class<E> enumClass) {
+ public static <E extends Enum<E>> EnumTableCellRenderer<E>
+ newEnumTableCellRenderer(TableCellRenderer renderer, Class<E> enumClass) {
return new EnumTableCellRenderer<E>(renderer, enumClass);
}
@@ -758,7 +851,9 @@
if (Desktop.isDesktopSupported()) {
try {
URL u = he.getURL();
- if (u.getProtocol().equalsIgnoreCase("mailto") || u.getProtocol().equalsIgnoreCase("http") || u.getProtocol().equalsIgnoreCase("ftp")) {
+ if (u.getProtocol().equalsIgnoreCase("mailto") ||
+ u.getProtocol().equalsIgnoreCase("http") ||
+ u.getProtocol().equalsIgnoreCase("ftp")) {
Desktop.getDesktop().browse(u.toURI());
}
} catch (IOException e) {
@@ -820,34 +915,38 @@
*/
public static void addExpandOnClickListener(final JTree tree) {
- tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
+ tree.getSelectionModel().addTreeSelectionListener(
+ new TreeSelectionListener() {
- @Override
- public void valueChanged(final TreeSelectionEvent e) {
- TreeNode node = (TreeNode) e.getPath().getLastPathComponent();
- if (node != null && !node.isLeaf()) {
+ @Override
+ public void valueChanged(final TreeSelectionEvent e) {
+ TreeNode node = (TreeNode)
+ e.getPath().getLastPathComponent();
+ if (node != null && !node.isLeaf()) {
- SwingUtilities.invokeLater(new Runnable() {
+ SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- for (TreePath path : e.getPaths()) {
- if (e.isAddedPath(path) && !tree.isExpanded(path)) {
- log.info("expand node [" + path + "]");
- // will expand the node
- tree.expandPath(path);
+ @Override
+ public void run() {
+ for (TreePath path : e.getPaths()) {
+ if (e.isAddedPath(path) &&
+ !tree.isExpanded(path)) {
+ log.info("expand node [" + path
+ + "]");
+ // will expand the node
+ tree.expandPath(path);
+ }
+ }
}
- }
+ });
}
- });
- }
- }
+ }
});
}
/**
- * Add a listener of tree table selection model to expand a new selected node
- * when it is selected.
+ * Add a listener of tree table selection model to expand a new selected
+ * node when it is selected.
*
* FIXME : Voir pour enlever le copier coller
*
@@ -867,7 +966,8 @@
@Override
public void run() {
for (TreePath path : e.getPaths()) {
- if (e.isAddedPath(path) && !treeTable.isExpanded(path)) {
+ if (e.isAddedPath(path) &&
+ !treeTable.isExpanded(path)) {
log.info("expand node [" + path + "]");
// will expand the node
treeTable.expandPath(path);
@@ -890,8 +990,14 @@
component.setSize(width, component.getHeight());
if (component instanceof JComponent) {
JComponent jcomponent = (JComponent) component;
- jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height));
- jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height));
+ jcomponent.setPreferredSize(
+ new Dimension(width,
+ jcomponent.getPreferredSize().height)
+ );
+ jcomponent.setMinimumSize(
+ new Dimension(width,
+ jcomponent.getPreferredSize().height)
+ );
if (jcomponent.isDisplayable()) {
jcomponent.revalidate();
}
@@ -907,8 +1013,10 @@
component.setSize(component.getWidth(), height);
if (component instanceof JComponent) {
JComponent jcomponent = (JComponent) component;
- jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height));
- jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height));
+ jcomponent.setPreferredSize(
+ new Dimension(jcomponent.getPreferredSize().width, height));
+ jcomponent.setMinimumSize(
+ new Dimension(jcomponent.getPreferredSize().width, height));
if (jcomponent.isDisplayable()) {
jcomponent.revalidate();
}
@@ -916,7 +1024,7 @@
}
public static ImageIcon createIcon(String path) {
- java.net.URL imgURL = JAXXUtil.class.getResource(path);
+ URL imgURL = JAXXUtil.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
@@ -942,7 +1050,7 @@
}
/**
- * retreave for the {@link UIManager} the icon prefixed by <code>action.</code>
+ * retreave for the {@link UIManager} the icon prefixed by {@code action}.
*
* @param key the key of the action icon to retreave from {@link UIManager}
* @return the icon, or <code>null if no icon found in {@link UIManager}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/editor/LocaleEditor.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/editor/LocaleEditor.java 2010-03-10 22:28:59 UTC (rev 1767)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/editor/LocaleEditor.java 2010-03-10 23:49:05 UTC (rev 1768)
@@ -22,14 +22,16 @@
import javax.swing.JComboBox;
import java.util.Locale;
import org.nuiton.i18n.I18n;
+import org.nuiton.i18n.I18nStore;
/**
* A {@link Locale} editor.
* <p/>
- * use the static method to have an instance of editor {@link #newEditor(java.util.Locale[])}
+ * use the static method to have an instance of editor
+ * {@link #newEditor(Locale...)}
* <p/>
* If no locale is given to this method, it will go and seek via
- * {@link org.nuiton.i18n.I18nLoader#getLocales()} all loaded locales in i18n system
+ * {@link I18nStore#getLocales()} all loaded locales in i18n system
*
* @author chemit
* @since 1.6.0
@@ -59,7 +61,7 @@
return type;
}
// get availables locales registred in I18n system
- type = I18n.getLoader().getLocales();
+ type = I18n.getStore().getLocales();
return type;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java 2010-03-10 22:28:59 UTC (rev 1767)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java 2010-03-10 23:49:05 UTC (rev 1768)
@@ -21,6 +21,7 @@
package jaxx.runtime.swing.navigation;
+import java.awt.Component;
import java.util.List;
/**
@@ -33,8 +34,7 @@
/**
* Init the ui just before been opened by the method
- * {@link NavigationMultiTreeHandler#openUI(java.awt.Component,
- * java.util.List<jaxx.runtime.swing.navigation.NavigationTreeNode>)}.
+ * {@link NavigationMultiTreeHandler#openUI(Component, List)}.
*
* @param nodes the selected node associated to the ui
* @throws Exception if any pb while opening the content's ui
@@ -43,11 +43,11 @@
/**
* Clean the ui after been closed by the method
- * {@link NavigationTreeHandler#closeUI(java.awt.Component)}.
+ * {@link NavigationTreeHandler#closeUI(Component)}.
*
* @param nodes the selected node associated to the ui
* @throws Exception if any pb when closing the content'sui
- * @see NavigationTreeHandler#closeUI(java.awt.Component)
+ * @see NavigationTreeHandler#closeUI(Component)
*/
void closeUI(List<NavigationTreeNode> nodes) throws Exception;
}
1
0
r1767 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 10 Mar '10
by tchemit@users.nuiton.org 10 Mar '10
10 Mar '10
Author: tchemit
Date: 2010-03-10 23:28:59 +0100 (Wed, 10 Mar 2010)
New Revision: 1767
Log:
Anomalie #374: NPE on NavigationTreehelper due to multi selection + improve code
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-10 12:45:19 UTC (rev 1766)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-10 22:28:59 UTC (rev 1767)
@@ -35,15 +35,15 @@
/**
* To help getting and setting navigation tree objects from a {@link JAXXContext}.
* <p/>
- * There is six types of data which can be hold in a context :
+ * There is seven types of data which can be hold in a context :
* <ul>
* <li>tree : the tree </li>
+ * <li>tree-tablr : the jx tree table</li>
* <li>tree model : the navigation tree model</li>
* <li>tree handler : the navigation tree handler</li>
* <li>selected path : the navigation path of the selected node</li>
* <li>selected node : the selected node</li>
* <li>selected bean : the selected bean</li>
- * <li>selected ui : the selected content ui</li>
* </ul>
* <p/>
* To make possible the use of more than one navigation tree system in a same
@@ -53,12 +53,12 @@
* Here is the keys mapping :
* <ul>
* <li>tree : {@code prefix + "-tree"}</li>
+ * <li>tree-table : {@code prefix + "-tree-table"}</li>
* <li>tree model : {@code prefix + "-tree-model"}</li>
* <li>tree handler : {@code prefix + "-tree-handler"}</li>
* <li>selected path : {@code prefix + "-selected-path"}</li>
* <li>selected node : {@code prefix + "-selected-node"}</li>
* <li>selected bean : {@code prefix + "-selected-bean"}</li>
- * <li>selected ui: {@code prefix + "-selected-ui"}</li>
* </ul>
*
* @author chemit
@@ -79,7 +79,6 @@
protected JAXXContextEntryDef<NavigationTreeHandler> handlerContextEntry;
protected JAXXContextEntryDef<JTree> treeContextEntry;
protected JAXXContextEntryDef<JXTreeTable> treeTableContextEntry;
-// protected JAXXContextEntryDef<Component> selectedUIContextEntry;
public NavigationTreeContextHelper(String prefix) {
this.prefix = prefix;
@@ -90,7 +89,6 @@
selectedBeansContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-beans");
selectedNodesContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-nodes");
selectedPathsContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-paths");
-// selectedUIContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-ui", Component.class);
}
public String getPrefix() {
@@ -114,8 +112,9 @@
/**
* @param context where to find model
- * @deprecated please use {@link #getModel(JAXXContext)}, will be remove
- * soon
+ * @deprecated since 2.0 please use {@link #getModel(JAXXContext)}, will
+ * be remove soon
+ * @return the specific tree model
*/
@Deprecated
public NavigationTreeModel getTreeModel(JAXXContext context) {
@@ -133,16 +132,18 @@
}
public String getSelectedPath(JAXXContext context) {
- List<String> values = getSelectedPathContextEntry().getContextValue(context);
- if (values == null){
- return null;
- }
- if (log.isWarnEnabled()){
- if (values.size() > 1){
- log.warn("More than one values are selected, return first one");
- }
- }
- return values.get(0);
+ String result = getSelectedValue(getSelectedPathContextEntry(),context);
+ return result;
+// List<String> values = getSelectedPathContextEntry().getContextValue(context);
+// if (values == null){
+// return null;
+// }
+// if (log.isWarnEnabled()){
+// if (values.size() > 1){
+// log.warn("More than one values are selected, return first one");
+// }
+// }
+// return values.get(0);
}
public List<String> getSelectedPaths(JAXXContext context) {
@@ -150,16 +151,18 @@
}
public NavigationTreeNode getSelectedNode(JAXXContext context) {
- List<NavigationTreeNode> values = getSelectedNodeContextEntry().getContextValue(context);
- if (values == null){
- return null;
- }
- if (log.isWarnEnabled() && values != null){
- if (values.size() > 1){
- log.warn("More than one values are selected, return first one");
- }
- }
- return values.get(0);
+ NavigationTreeNode result = getSelectedValue(getSelectedNodeContextEntry(),context);
+ return result;
+// List<NavigationTreeNode> values = getSelectedNodeContextEntry().getContextValue(context);
+// if (values == null){
+// return null;
+// }
+// if (log.isWarnEnabled()){
+// if (values.size() > 1){
+// log.warn("More than one values are selected, return first one");
+// }
+// }
+// return values.get(0);
}
public List<NavigationTreeNode> getSelectedNodes(JAXXContext context) {
@@ -167,16 +170,18 @@
}
public Object getSelectedBean(JAXXContext context) {
- List<Object> values = getSelectedBeanContextEntry().getContextValue(context);
- if (values == null){
- return null;
- }
- if (log.isWarnEnabled()){
- if (values.size() > 1){
- log.warn("More than one values are selected, return first one");
- }
- }
- return values.get(0);
+ Object result = getSelectedValue(getSelectedBeanContextEntry(),context);
+ return result;
+// List<Object> values = getSelectedBeanContextEntry().getContextValue(context);
+// if (values == null){
+// return null;
+// }
+// if (log.isWarnEnabled()){
+// if (values.size() > 1){
+// log.warn("More than one values are selected, return first one");
+// }
+// }
+// return values.get(0);
}
public List<Object> getSelectedBeans(JAXXContext context) {
@@ -191,7 +196,7 @@
/**
* @param context where to store model
* @param model model to store
- * @deprecated please use {@link #setModel(JAXXContext, NavigationModel)},
+ * @deprecated since 2.0 please use {@link #setModel(JAXXContext, NavigationModel)},
* will be remove soon
*/
@Deprecated
@@ -217,66 +222,64 @@
}
public void setSelectedPath(JAXXContext context, String path) {
- if (path == null) {
- getSelectedPathContextEntry().removeContextValue(context);
- } else {
- List<String> selecteds = new ArrayList<String>();
- selecteds.add(path);
- getSelectedPathContextEntry().setContextValue(context, selecteds);
- }
+ setSelectedValue(getSelectedPathContextEntry(), context, path);
+// if (path == null) {
+// getSelectedPathContextEntry().removeContextValue(context);
+// } else {
+// List<String> selecteds = new ArrayList<String>();
+// selecteds.add(path);
+// getSelectedPathContextEntry().setContextValue(context, selecteds);
+// }
}
public void setSelectedPaths(JAXXContext context, List<String> paths) {
- if (paths == null || paths.isEmpty()) {
- getSelectedPathContextEntry().removeContextValue(context);
- } else {
- getSelectedPathContextEntry().setContextValue(context, paths);
- }
+ setSelectedValues(getSelectedPathContextEntry(), context, paths);
+// if (paths == null || paths.isEmpty()) {
+// getSelectedPathContextEntry().removeContextValue(context);
+// } else {
+// getSelectedPathContextEntry().setContextValue(context, paths);
+// }
}
public void setSelectedNode(JAXXContext context, NavigationTreeNode node) {
- if (node == null) {
- getSelectedNodeContextEntry().removeContextValue(context);
- } else {
- List<NavigationTreeNode> selecteds = new ArrayList<NavigationTreeNode>();
- selecteds.add(node);
- getSelectedNodeContextEntry().setContextValue(context, selecteds);
- }
+ setSelectedValue(getSelectedNodeContextEntry(), context, node);
+// if (node == null) {
+// getSelectedNodeContextEntry().removeContextValue(context);
+// } else {
+// List<NavigationTreeNode> selecteds = new ArrayList<NavigationTreeNode>();
+// selecteds.add(node);
+// getSelectedNodeContextEntry().setContextValue(context, selecteds);
+// }
}
public void setSelectedNodes(JAXXContext context, List<NavigationTreeNode> nodes) {
- if (nodes == null || nodes.isEmpty()) {
- getSelectedNodeContextEntry().removeContextValue(context);
- } else {
- getSelectedNodeContextEntry().setContextValue(context, nodes);
- }
+ setSelectedValues(getSelectedNodeContextEntry(), context, nodes);
+// if (nodes == null || nodes.isEmpty()) {
+// getSelectedNodeContextEntry().removeContextValue(context);
+// } else {
+// getSelectedNodeContextEntry().setContextValue(context, nodes);
+// }
}
public void setSelectedBean(JAXXContext context, Object bean) {
- if (bean == null) {
- getSelectedBeanContextEntry().removeContextValue(context);
- } else {
- List<Object> selecteds = new ArrayList<Object>();
- selecteds.add(bean);
- getSelectedBeanContextEntry().setContextValue(context, selecteds);
- }
+ setSelectedValue(getSelectedBeanContextEntry(), context, bean);
+// if (bean == null) {
+// getSelectedBeanContextEntry().removeContextValue(context);
+// } else {
+// List<Object> selecteds = new ArrayList<Object>();
+// selecteds.add(bean);
+// getSelectedBeanContextEntry().setContextValue(context, selecteds);
+// }
}
public void setSelectedBeans(JAXXContext context, List<Object> beans) {
- if (beans == null || beans.isEmpty()) {
- getSelectedBeanContextEntry().removeContextValue(context);
- } else {
- getSelectedBeanContextEntry().setContextValue(context, beans);
- }
- }
-
-// public void setSelectedUI(JAXXContext context, Component ui) {
-// if (ui == null) {
-// getSelectedUIContextEntry().removeContextValue(context);
+ setSelectedValues(getSelectedBeanContextEntry(), context, beans);
+// if (beans == null || beans.isEmpty()) {
+// getSelectedBeanContextEntry().removeContextValue(context);
// } else {
-// getSelectedUIContextEntry().setContextValue(context, ui);
+// getSelectedBeanContextEntry().setContextValue(context, beans);
// }
-// }
+ }
protected JAXXContextEntryDef<NavigationModel> getModelContextEntry() {
return modelContextEntry;
@@ -307,9 +310,41 @@
return treeTableContextEntry;
}
-// public JAXXContextEntryDef<Component> getSelectedUIContextEntry() {
+ protected <T> T getSelectedValue(JAXXContextEntryDef<List<T>> entry,
+ JAXXContext context) {
+ List<T> values = entry.getContextValue(context);
+ T result = null;
+ if (values != null && !values.isEmpty()) {
+ if (values.size() > 1) {
+ if (log.isWarnEnabled()) {
+ log.warn("There is " + values.size() +
+ " values selected, will return first one");
+ }
+ }
+ result = values.get(0);
+ }
+ return result;
+ }
-// return selectedUIContextEntry;
+ protected <T> void setSelectedValue(JAXXContextEntryDef<List<T>> entry,
+ JAXXContext context,
+ T value) {
+ if (value == null) {
+ entry.removeContextValue(context);
+ } else {
+ List<T> selecteds = new ArrayList<T>();
+ selecteds.add(value);
+ entry.setContextValue(context, selecteds);
+ }
+ }
-// }
+ protected <T> void setSelectedValues(JAXXContextEntryDef<List<T>> entry,
+ JAXXContext context,
+ List<T> values) {
+ if (values == null || values.isEmpty()) {
+ entry.removeContextValue(context);
+ } else {
+ entry.setContextValue(context, values);
+ }
+ }
}
1
0