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
r1816 - in trunk: jaxx-runtime/src/main/java/jaxx/runtime jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard jaxx-widgets/src/main/java/jaxx/runtime/swing jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model
by tchemit@users.nuiton.org 27 Mar '10
by tchemit@users.nuiton.org 27 Mar '10
27 Mar '10
Author: tchemit
Date: 2010-03-27 17:12:27 +0100 (Sat, 27 Mar 2010)
New Revision: 1816
Log:
Evolution #420: Nettoyer les listeners qui ne servent plus
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanel.jaxx
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUI.jaxx
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CategoryModel.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigTableModel.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java
trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java
trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilderTest.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-03-27 16:12:27 UTC (rev 1816)
@@ -25,8 +25,11 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import javax.swing.*;
+import java.awt.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeListenerProxy;
+import java.beans.PropertyChangeSupport;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationHandler;
@@ -34,6 +37,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.*;
+import java.util.List;
public class JAXXUtil {
@@ -290,6 +294,46 @@
return listener;
}
+ /**
+ * Remove all listeners registred in given {@code pcs}.
+ *
+ * @param pcs the pcs to clean
+ */
+ public static void destroy(PropertyChangeSupport pcs) {
+ PropertyChangeListener[] listeners = pcs.getPropertyChangeListeners();
+ for (PropertyChangeListener l : listeners) {
+ if (log.isInfoEnabled()) {
+ if (l instanceof PropertyChangeListenerProxy) {
+ PropertyChangeListenerProxy ll = (PropertyChangeListenerProxy) l;
+ log.info("remove property change listener " + ll.getPropertyName() + " : " + l);
+ } else {
+ log.info("remove property change listener " + l);
+ }
+ }
+ pcs.removePropertyChangeListener(l);
+ }
+ }
+
+ /**
+ * Remove all listeners registred in given {@code component}.
+ *
+ * @param component the pcs to clean
+ */
+ public static void destroy(Component component) {
+ PropertyChangeListener[] listeners = component.getPropertyChangeListeners();
+ for (PropertyChangeListener l : listeners) {
+ if (log.isInfoEnabled()) {
+ if (l instanceof PropertyChangeListenerProxy) {
+ PropertyChangeListenerProxy ll = (PropertyChangeListenerProxy) l;
+ log.info("remove property change listener " + ll.getPropertyName() + " : " + l);
+ } else {
+ log.info("remove property change listener " + l);
+ }
+ }
+ component.removePropertyChangeListener(l);
+ }
+ }
+
public static boolean assignment(boolean value,
String name,
JAXXObject src) {
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/wizard/WizardModel.java 2010-03-27 16:12:27 UTC (rev 1816)
@@ -20,6 +20,8 @@
*/
package jaxx.runtime.swing.wizard;
+import jaxx.runtime.JAXXUtil;
+
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
@@ -98,6 +100,11 @@
setStep(startStep);
}
+ public void destroy() {
+ // suppression de tous les listeners
+ JAXXUtil.destroy(pcs);
+ }
+
public void gotoNextStep() {
E nextStep = getNextStep();
if (nextStep == null) {
@@ -224,11 +231,15 @@
}
public void removePropertyChangeListeners() {
- for (PropertyChangeListener l : pcs.getPropertyChangeListeners()) {
- pcs.removePropertyChangeListener(l);
- }
+ JAXXUtil.destroy(pcs);
}
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ destroy();
+ }
+
public void validate() {
if (step == null) {
// pas de validation quand aucune etape n'est sélectionnée
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanel.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanel.jaxx 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/AboutPanel.jaxx 2010-03-27 16:12:27 UTC (rev 1816)
@@ -124,6 +124,17 @@
rootPane.setDefaultButton(close);
rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("ESCAPE"), "close");
rootPane.getActionMap().put("close", closeAction);
+ f.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosed(WindowEvent e) {
+ Component ui = (Component) e.getSource();
+ if (log.isInfoEnabled()) {
+ log.info("destroy ui "+ ui);
+ }
+ JAXXUtil.destroy(ui);
+ JAXXUtil.destroy(AboutPanel.this);
+ }
+ });
SwingUtil.center(ui, f);
f.setVisible(true);
}
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUI.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUI.jaxx 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/ErrorDialogUI.jaxx 2010-03-27 16:12:27 UTC (rev 1816)
@@ -42,6 +42,9 @@
instance.setVisible(true);
}
public static void disposeUI() {
+ if (instance != null) {
+ JAXXUtil.destroy(instance);
+ }
instance=null;
}
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUI.jaxx 2010-03-27 16:12:27 UTC (rev 1816)
@@ -3,35 +3,47 @@
<style source='ConfigUI.css'/>
<script><![CDATA[
- import jaxx.runtime.swing.editor.config.model.ConfigUIModel;
+import jaxx.runtime.swing.editor.config.model.ConfigUIModel;
- categories.setModel(new DefaultSingleSelectionModel() {
+categories.setModel(new DefaultSingleSelectionModel() {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- @Override
- public void setSelectedIndex(int index) {
- // check if catgeory can be quit
- boolean canContinue = !isSelected() || ConfigUIBuilder.canQuitCategory(ConfigUI.this);
- if (canContinue) {
- if (log.isDebugEnabled()) {
- log.debug("new index : " + index);
- }
- // was authorized to continue
- super.setSelectedIndex(index);
+ @Override
+ public void setSelectedIndex(int index) {
+ // check if catgeory can be quit
+ boolean canContinue = !isSelected() || ConfigUIBuilder.canQuitCategory(ConfigUI.this);
+ if (canContinue) {
+ if (log.isDebugEnabled()) {
+ log.debug("new index : " + index);
}
+ // was authorized to continue
+ super.setSelectedIndex(index);
}
- });
+ }
+});
- protected void changeCategory(ChangeEvent e) {
- JPanel p = (JPanel) getCategories().getSelectedComponent();
- if (p == null) {
- // pas de selection
- return;
- }
- getModel().setCategory(p.getName());
- getCategories().invalidate();
+public void destroy() {
+ log.info("destroy ui " + getName());
+ JAXXUtil.destroy(this);
+ model.destroy();
+}
+
+@Override
+protected void finalize() throws Throwable {
+ super.finalize();
+ destroy();
+}
+
+protected void changeCategory(ChangeEvent e) {
+ JPanel p = (JPanel) getCategories().getSelectedComponent();
+ if (p == null) {
+ // pas de selection
+ return;
}
+ getModel().setCategory(p.getName());
+ getCategories().invalidate();
+}
]]>
</script>
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/ConfigUIBuilder.java 2010-03-27 16:12:27 UTC (rev 1816)
@@ -85,6 +85,8 @@
// just quit, no callBack can be apply here
+ ui.destroy();
+
// close the configu ui
parentWindow.dispose();
return;
@@ -96,6 +98,8 @@
if (forSaved.isEmpty()) {
// just quit, no callBack to call
+ ui.destroy();
+
// close the configu ui
parentWindow.dispose();
return;
@@ -297,159 +301,4 @@
return response;
}
-
- /**
- * // prepare quit action
- Action quitAction = new AbstractAction(quitButton.getText(),
- quitButton.getIcon()) {
-
- private static final long serialVersionUID = 1L;
-
- @Override public void actionPerformed(ActionEvent e) {
- if (!canQuitCategory(ui)) {
- return;
- }
-
- boolean needReloadUI = false;
- boolean needReloadApplication = false;
-
- StringBuilder reloadUIBuffer = new StringBuilder();
-
- StringBuilder reloadApplicationBuffer = new StringBuilder();
-
- if (model.isSaved() && !model.isStandalone()) {
-
-
- StringBuilder buffer = new StringBuilder();
-
- // on doit verifier si des options sauvees necessite
- // un redemarrage de l'application
- for (CategoryModel cat : model) {
- List<OptionModel> savedOptions = cat.getSavedOptions();
- List<OptionModel> needReloadUIOptions = new ArrayList<OptionModel>();
- List<OptionModel> needReloadApplicationOptions = new ArrayList<OptionModel>();
- if (!savedOptions.isEmpty()) {
- Iterator<OptionModel> itr = savedOptions.iterator();
- buffer.append("\n").append(_("config.category.saved", _(cat.getCategory()))).append("\n");
- while (itr.hasNext()) {
- OptionModel option = itr.next();
- buffer.append("\n- ").append(option.getKey());
- if (option.isNeedReloadApplication()) {
- needReloadApplication = true;
- needReloadApplicationOptions.add(option);
- continue;
- }
- if (option.isNeedReloadUI()) {
- needReloadUI = true;
- needReloadUIOptions.add(option);
- continue;
- }
- itr.remove();
-
- }
- if (!savedOptions.isEmpty()) {
-
- if (!needReloadApplicationOptions.isEmpty()) {
- reloadApplicationBuffer.append("\n");
- reloadApplicationBuffer.append(_("config.category.needReloadApplication", _(cat.getCategory())));
- reloadApplicationBuffer.append("\n");
- // second pass to obtain needReloadUI
- for (OptionModel option : needReloadApplicationOptions) {
- reloadApplicationBuffer.append("\n- ").append(option.getKey());
- }
- }
-
- if (!needReloadUIOptions.isEmpty()) {
- reloadUIBuffer.append("\n");
- reloadUIBuffer.append(_("config.category.needReloadUI", _(cat.getCategory())));
- reloadUIBuffer.append("\n");
- // second pass to obtain needReloadUI
- for (OptionModel option : needReloadUIOptions) {
- reloadUIBuffer.append("\n- ").append(option.getKey());
- }
- }
- }
-
- }
- }
-
- if (log.isInfoEnabled()) {
- log.info("save options :\n" + buffer.toString());
- }
-
- if (needReloadApplication) {
-
- // reloading application implies reloading ui
- needReloadUI = false;
-
- askUser(ui,
- _("config.title.will.reload.application"),
- _("config.model.needReloadApplication") +
- reloadApplicationBuffer.toString(),
- JOptionPane.INFORMATION_MESSAGE,
- new Object[]{_("config.choice.ok")},
- 0);
- }
-
- if (needReloadUI) {
- askUser(ui,
- _("config.title.will.reload.ui"),
- _("config.model.needReloadUI") +
- reloadUIBuffer.toString(),
- JOptionPane.INFORMATION_MESSAGE,
- new Object[]{_("config.choice.ok")},
- 0);
- }
- }
-
- // close the configu ui
- ui.getParentContainer(Window.class).dispose();
-
- if (needReloadApplication) {
-
- Runnable callback = model.getReloadApplicationCallback();
- if (callback == null) {
- throw new IllegalStateException(
- "No reloadApplicationCallback found in model");
- }
-
- SwingUtilities.invokeLater(callback);
- } else if (needReloadUI) {
-
- Runnable callback = model.getReloadUICallback();
- if (callback == null) {
- throw new IllegalStateException(
- "No reloadUICallback found in model");
- }
- SwingUtilities.invokeLater(callback);
- }
-
-
- }
- };
- String tip = quitButton.getToolTipText();
- quitButton.setAction(quitAction);
- quitButton.setToolTipText(tip);
-
- // build categories tabs
- for (CategoryModel categoryModel : model) {
- String category = categoryModel.getCategory();
- String categoryLabel = _(categoryModel.getCategoryLabel());
- ConfigCategoryUI p = new ConfigCategoryUI(new
- JAXXInitialContext().add(ui).add(categoryModel));
- p.getCategoryLabel().setText(categoryLabel);
- p.setName(category);
- ui.getCategories().addTab(_(category), null, p, categoryLabel);
- }
-
- model.setCategory(defaultCategory);
- int categoryIndex = model.getCategoryIndex(defaultCategory);
- if (log.isDebugEnabled()) {
- log.debug("index of default category (" + defaultCategory + ") : "
- + categoryIndex);
- }
- ui.getCategories().setSelectedIndex(categoryIndex);
- return ui;
- }
- */
}
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CategoryModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CategoryModel.java 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/CategoryModel.java 2010-03-27 16:12:27 UTC (rev 1816)
@@ -20,6 +20,8 @@
*/
package jaxx.runtime.swing.editor.config.model;
+import jaxx.runtime.JAXXUtil;
+
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
@@ -50,10 +52,9 @@
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
protected CategoryModel(String category, String categoryLabel) {
- super();
this.category = category;
this.categoryLabel = categoryLabel;
- this.entries = new ArrayList<OptionModel>();
+ entries = new ArrayList<OptionModel>();
}
protected void addOption(OptionModel option) {
@@ -62,7 +63,6 @@
@Deprecated
public CategoryModel(String category, String categoryLabel, OptionModel[] entries) {
- super();
this.category = category;
this.categoryLabel = categoryLabel;
this.entries = Collections.unmodifiableList(Arrays.asList(entries));
@@ -186,4 +186,14 @@
public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
return pcs.getPropertyChangeListeners();
}
+
+ public void destroy() {
+ JAXXUtil.destroy(pcs);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ destroy();
+ }
}
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigTableModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigTableModel.java 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigTableModel.java 2010-03-27 16:12:27 UTC (rev 1816)
@@ -20,24 +20,26 @@
*/
package jaxx.runtime.swing.editor.config.model;
+import org.nuiton.util.ConverterUtil;
+
+import javax.swing.table.AbstractTableModel;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import javax.swing.table.AbstractTableModel;
-import org.nuiton.util.ConverterUtil;
/**
* le modele du tableau d'options pour une categorie donnee.
- *
+ * <p/>
* Le modele se base sur le modele d'une categorie d'option.
*
* @author tchemit
- *
* @see CategoryModel
*/
public class ConfigTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
+
private static final Class<?>[] columnClass = {String.class, Object.class, String.class};
+
/** le modele d'une categorie */
protected final CategoryModel categoryModel;
@@ -115,7 +117,7 @@
}
OptionModel key = getEntry(row);
Object val;
- if (aValue == null || key.getType() == aValue.getClass()) {
+ if (aValue == null || key.getType().equals(aValue.getClass())) {
val = aValue;
} else {
String valStr = String.valueOf(aValue).trim();
@@ -133,4 +135,17 @@
categoryModel.setValue(key, val);
fireTableRowsUpdated(row, row);
}
+
+
+ public void destroy() {
+ if (categoryModel != null) {
+ categoryModel.destroy();
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ destroy();
+ }
}
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModel.java 2010-03-27 16:12:27 UTC (rev 1816)
@@ -20,16 +20,17 @@
*/
package jaxx.runtime.swing.editor.config.model;
+import jaxx.runtime.JAXXUtil;
import org.apache.commons.beanutils.PropertyUtils;
-import static org.nuiton.i18n.I18n._;
import org.nuiton.util.ApplicationConfig;
-import org.nuiton.util.ApplicationConfig.OptionDef;
import javax.swing.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.*;
+import static org.nuiton.i18n.I18n._;
+
/**
* Le modele de l'ui des preferences.
* <p/>
@@ -72,16 +73,6 @@
* Callbacks manager
*/
protected CallBacksManager callBacksManager;
- /**
- * call back when reload ui is necessary
- */
- @Deprecated
- protected Runnable reloadUICallback;
- /**
- * call back when reload application is necessary
- */
- @Deprecated
- protected Runnable reloadApplicationCallback;
/**
* suport of modification
@@ -90,43 +81,13 @@
public ConfigUIModel(ApplicationConfig config) {
this.config = config;
- this.categories = new LinkedHashMap<String, CategoryModel>();
- this.callBacksManager = new CallBacksManager();
+ categories = new LinkedHashMap<String, CategoryModel>();
+ callBacksManager = new CallBacksManager();
}
/**
* Ajoute une categorie dans le modele.
*
- * @param category l'id de la categorie (la clef de traduction du nom
- * de la categorie)
- * @param categoryLabel la clef de traduction de la description de
- * la categorie
- * @param keys les options de la categorie
- * @deprecated since 2.0.0 prefer use the
- * {@link #addCategory(CategoryModel)}
- */
- @Deprecated
- public void addCategory(String category,
- String categoryLabel,
- OptionDef... keys) {
- if (categories.containsKey(category)) {
- throw new IllegalArgumentException(
- _("config.error.category.already.exists", category));
- }
- OptionModel[] entries = new OptionModel[keys.length];
- int index = 0;
- for (OptionDef d : keys) {
- Object value = config.getOption(d);
- OptionModel e = new OptionModel(d, value);
- entries[index++] = e;
- }
- CategoryModel m = new CategoryModel(category, categoryLabel, entries);
- categories.put(category, m);
- }
-
- /**
- * Ajoute une categorie dans le modele.
- *
* @param category la categorie a ajouter au modèle.
*/
public void addCategory(CategoryModel category) {
@@ -222,16 +183,6 @@
this.standalone = standalone;
}
- @Deprecated
- public Runnable getReloadApplicationCallback() {
- return reloadApplicationCallback;
- }
-
- @Deprecated
- public Runnable getReloadUICallback() {
- return reloadUICallback;
- }
-
public void saveModified() {
// compute transients keys (to never be saved)
List<String> transients = new ArrayList<String>();
@@ -360,15 +311,14 @@
return pcs.getPropertyChangeListeners();
}
- @Deprecated
- protected void setReloadApplicationCallback(
- Runnable reloadApplicationCallback) {
- this.reloadApplicationCallback = reloadApplicationCallback;
+ public void destroy() {
+ JAXXUtil.destroy(pcs);
}
- @Deprecated
- protected void setReloadUICallback(Runnable reloadUICallback) {
- this.reloadUICallback = reloadUICallback;
+ @Override
+ protected void finalize() throws Throwable {
+ super.finalize();
+ destroy();
}
protected ApplicationConfig getConfig() {
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilder.java 2010-03-27 16:12:27 UTC (rev 1816)
@@ -8,7 +8,7 @@
import javax.swing.table.TableCellEditor;
/**
- * A builder of {@link jaxx.runtime.swing.editor.config.model.ConfigUIModel}
+ * A builder of {@link ConfigUIModel}
* Created: 22 déc. 2009
*
* @author Tony Chemit <chemit(a)codelutin.com> Copyright Code Lutin
@@ -55,37 +55,6 @@
}
/**
- * Set the {@code reloadApplicationCallback} of the current model.
- *
- * @param callback the call back to set
- * @throws IllegalStateException if there is not a current model
- * @throws NullPointerException if any of parameter is {@code null}
- * @see ConfigUIModel#setReloadApplicationCallback(Runnable)
- */
- @Deprecated
- public void setReloadApplicationCallback(Runnable callback)
- throws IllegalStateException, NullPointerException {
- checkCurrent(model, "model");
- checkNotNull(callback, "setReloadApplicationCallback", "callback");
- model.setReloadApplicationCallback(callback);
- }
-
- /**
- * Set the {@code reloadUICallback} of the current model.
- *
- * @param callback the call back to set
- * @throws IllegalStateException if there is not a current model
- * @throws NullPointerException if any of parameter is {@code null}
- * @see ConfigUIModel#setReloadUICallback(Runnable)
- */
- @Deprecated
- public void setReloadUICallback(Runnable callback) {
- checkCurrent(model, "model");
- checkNotNull(callback, "setReloadUICallback", "callback");
- model.setReloadUICallback(callback);
- }
-
- /**
* Add a new category, and set it as current.
* <p/>
* <b>Note:</b> As side effets, if a previous category, then store it to
@@ -179,7 +148,7 @@
* @param editor the editor to set in the current option.
* @throws IllegalStateException if there is not a current option set.
* @throws NullPointerException if any of parameter is {@code null}
- * @see OptionModel#setEditor(javax.swing.table.TableCellEditor)
+ * @see OptionModel#setEditor(TableCellEditor)
*/
public void setOptionEditor(TableCellEditor editor)
throws IllegalStateException, NullPointerException {
@@ -222,33 +191,6 @@
}
/**
- * Set the needReloadUI flag on the current option.
- *
- * @param needReload new value to set
- * @throws IllegalStateException if there is not a current option set.
- * @see OptionModel#setNeedReloadUI(boolean)
- */
- @Deprecated
- public void setOptionNeedReloadUI(boolean needReload)
- throws IllegalStateException {
- checkCurrent(option, "option");
- option.setNeedReloadUI(needReload);
- }
-
- /**
- * Set the needReloadApplication flag on the current option.
- *
- * @param needReload new value to set
- * @throws IllegalStateException if there is not a current option set.
- * @see OptionModel#setNeedReloadUI(boolean)
- */
- public void setOptionNeedReloadApplication(boolean needReload)
- throws IllegalStateException {
- checkCurrent(option, "option");
- option.setNeedReloadApplication(needReload);
- }
-
- /**
* Flush the model and return it.
* <p/>
* <b>Note:</b> As a side effect, nothing is available in the builder
Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java
===================================================================
--- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/config/model/OptionModel.java 2010-03-27 16:12:27 UTC (rev 1816)
@@ -42,18 +42,9 @@
/**
* un drapeau pour savoir si l'option a été sauvée
*/
- protected boolean saved = false;
+ protected boolean saved;
+
/**
- * un drapeau pour savoir si le changement de l'option nécessite un redémarrage de l'ui.
- */
- @Deprecated
- protected boolean needReloadUI = false;
- /**
- * un drapeau pour savoir si le changement de l'option nécessite un redémarrage de l'application.
- */
- @Deprecated
- protected boolean needReloadApplication = false;
- /**
* la valeur non modifié de l'option
*/
protected Object originalValue;
@@ -105,16 +96,6 @@
return def.isFinal();
}
- @Deprecated
- public boolean isNeedReloadUI() {
- return needReloadUI;
- }
-
- @Deprecated
- public boolean isNeedReloadApplication() {
- return needReloadApplication;
- }
-
public Object getOriginalValue() {
return originalValue;
}
@@ -149,7 +130,7 @@
public void initValue(Object originalValue) {
this.originalValue = originalValue;
- this.value = originalValue;
+ value = originalValue;
}
public String getPropertyName() {
@@ -164,16 +145,6 @@
this.editor = editor;
}
- @Deprecated
- protected void setNeedReloadUI(boolean needReloadUI) {
- this.needReloadUI = needReloadUI;
- }
-
- @Deprecated
- protected void setNeedReloadApplication(boolean needReloadApplication) {
- this.needReloadApplication = needReloadApplication;
- }
-
protected void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}
Modified: trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilderTest.java
===================================================================
--- trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilderTest.java 2010-03-26 18:15:08 UTC (rev 1815)
+++ trunk/jaxx-widgets/src/test/java/jaxx/runtime/swing/editor/config/model/ConfigUIModelBuilderTest.java 2010-03-27 16:12:27 UTC (rev 1816)
@@ -210,7 +210,6 @@
Assert.assertNotNull(optionModel);
Assert.assertEquals(MyConfig.Option.LOCALE, optionModel.def);
Assert.assertEquals(MyConfig.PROPERTY_LOCALE, optionModel.propertyName);
-// Assert.assertEquals(false, optionModel.needReloadUI);
Assert.assertNull(optionModel.editor);
}
@@ -252,7 +251,6 @@
Assert.assertNotNull(optionModel);
Assert.assertEquals(MyConfig.Option.LOCALE, optionModel.def);
Assert.assertNull(optionModel.propertyName);
-// Assert.assertEquals(false, optionModel.needReloadUI);
Assert.assertEquals(cellEditor, optionModel.editor);
}
1
0
r1815 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable
by tchemit@users.nuiton.org 26 Mar '10
by tchemit@users.nuiton.org 26 Mar '10
26 Mar '10
Author: tchemit
Date: 2010-03-26 19:15:08 +0100 (Fri, 26 Mar 2010)
New Revision: 1815
Log:
add constructor on NavigationTreeTableModel with the superb MyDefaultTreeTableModel TreeTableModel implemantation
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java 2010-03-26 18:05:31 UTC (rev 1814)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java 2010-03-26 18:15:08 UTC (rev 1815)
@@ -59,6 +59,14 @@
protected List<String> columnsName;
+ public NavigationTreeTableModel(MyDefaultTreeTableModel delegate,
+ String pathSeparator,
+ JAXXContext context,
+ List<String> columnsName) {
+ super(delegate, pathSeparator, context);
+ this.columnsName = columnsName;
+ }
+
public NavigationTreeTableModel(String pathSeparator, JAXXContext context, List<String> columnsName) {
super(new MyDefaultTreeTableModel(), pathSeparator, context);
this.columnsName = columnsName;
1
0
Author: tchemit
Date: 2010-03-26 19:05:31 +0100 (Fri, 26 Mar 2010)
New Revision: 1814
Log:
small refactor of navigation api
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationMultiTreeHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationOneClicSelectionHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableNode.java
Removed:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java
Modified:
trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst
trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/package.html
trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
trunk/src/site/rst/NavigationModel.rst
Modified: trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst
===================================================================
--- trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst 2010-03-26 18:05:31 UTC (rev 1814)
@@ -15,12 +15,12 @@
Le développement est effectué dans le paquetage *jaxx.runtime.swing.navigation*.
-jaxx.runtime.swing.navigation.NavigationTreeNodeModel
+jaxx.runtime.swing.navigation.tree.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.NavigationTreeNodeModel.NavigationTreeNode*.
+Les noeuds présents dans ce modèle sont aussi typés en *jaxx.runtime.swing.navigation.tree.NavigationTreeModel.NavigationTreeNode*.
L'idée principale est de pouvoir associé à un noeud précis un chemin depuis la racine, ce que l'on appele *chemin de navigation*.
@@ -30,7 +30,7 @@
Définition d'un noeud
=====================
-Le noeud (*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*.
+Le noeud (*jaxx.runtime.swing.navigation.tree.NavigationTreeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*.
Il apporte les nouvelles propriétés suivantes :
Modified: trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java
===================================================================
--- trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -28,7 +28,7 @@
/*@Test
public void testGetClassDescriptor() throws Exception {
- ClassDescriptorLoader.getClassDescriptor("jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode");
+ ClassDescriptorLoader.getClassDescriptor("jaxx.runtime.swing.navigation.tree.NavigationTreeModel.NavigationTreeNode");
}*/
@Test
public void testBuiltInClassName() throws ClassNotFoundException, NoSuchMethodException {
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -40,7 +40,13 @@
import jaxx.runtime.context.JAXXContextEntryDef;
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
-import jaxx.runtime.swing.navigation.*;
+import jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler;
+import jaxx.runtime.swing.navigation.handler.NavigationHandler;
+import jaxx.runtime.swing.navigation.handler.NavigationTreeHandlerWithCardLayout;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeHelper;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModel;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -59,7 +65,7 @@
}
@Override
- public NavigationTreeNodeModel createTreeModel(JAXXContext context) {
+ public NavigationTreeModel createTreeModel(JAXXContext context) {
if (log.isDebugEnabled()) {
log.debug("start creating demo model");
@@ -126,7 +132,7 @@
addDemo(CounterDemo.class).
addDemo(CalculatorDemo.class);
- NavigationTreeNodeModel model = builder.getModel();
+ NavigationTreeModel model = builder.getModel();
if (log.isDebugEnabled()) {
builder.printModel(model.getRoot());
@@ -137,20 +143,20 @@
}
@Override
- public NavigationTreeHandler<NavigationTreeNode> createTreeHandler(JAXXObject context) {
+ public NavigationHandler<NavigationTreeNode> createTreeHandler(JAXXObject context) {
- NavigationTreeHandler<NavigationTreeNode> handler;
+ NavigationHandler<NavigationTreeNode> handler;
handler = new NavigationTreeHandlerWithCardLayout<NavigationTreeNode>(
getPrefix(),
context,
- NavigationTreeHandler.Strategy.PER_UI_TYPE) {
+ NavigationHandler.Strategy.PER_UI_TYPE) {
private static final long serialVersionUID = 1L;
@Override
- protected NavigationTreeNodeModel getNavigationTreeModel() {
- return (NavigationTreeNodeModel) getModel(getContext());
+ public NavigationTreeModel getNavigationTreeModel() {
+ return (NavigationTreeModel) getModel(getContext());
}
@Override
@@ -164,7 +170,7 @@
}
@Override
- protected void treateError(Exception e) {
+ public void treateError(Exception e) {
ErrorDialogUI.showError(e);
}
@@ -174,14 +180,14 @@
}
};
// on ne peut selectionner qu'un seul noeud a la fois
- handler.setSelectionMode(NavigationTreeHandler.SINGLE_TREE_SELECTION);
+ handler.setSelectionMode(NavigationHandler.SINGLE_TREE_SELECTION);
// save handler in ui context
setTreeHandler(context, handler);
return handler;
}
- static class TreeModelBuilder extends NavigationTreeNodeModelBuilder {
+ static class TreeModelBuilder extends NavigationTreeModelBuilder {
/** la definition de l'unqiue object a partage */
static private final JAXXContextEntryDef<DemoConfig> def =
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -33,7 +33,7 @@
import jaxx.runtime.swing.editor.config.ConfigUIBuilder;
import jaxx.runtime.swing.editor.config.model.ConfigUIModel;
import jaxx.runtime.swing.editor.config.model.ConfigUIModelBuilder;
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -27,6 +27,12 @@
import jaxx.runtime.swing.CardLayout2;
import jaxx.runtime.swing.ErrorDialogUI;
import jaxx.runtime.swing.navigation.*;
+import jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler;
+import jaxx.runtime.swing.navigation.handler.NavigationHandler;
+import jaxx.runtime.swing.navigation.handler.NavigationTreeHandlerWithCardLayout;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeHelper;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModel;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -41,17 +47,6 @@
*/
public class FullNavigationTreeHelper extends NavigationTreeHelper {
-// static {
-// // register decorator one for all
-//
-// DecoratorUtils.register(
-// Movie.class.getSimpleName(),
-// DecoratorUtils.newMultiJXPathDecorator(Movie.class, "${title}$s##${year}$s", "##", " - "));
-//
-// DecoratorUtils.register(
-// People.class.getSimpleName(),
-// DecoratorUtils.newMultiJXPathDecorator(People.class, "${firstName}$s##${lastName}$s", "##", " "));
-// }
/**
* Logger
*/
@@ -95,7 +90,7 @@
}
@Override
- public NavigationTreeNodeModel createTreeModel(JAXXContext context) {
+ public NavigationTreeModel createTreeModel(JAXXContext context) {
if (builder == null) {
builder = new FullNavigationTreeModelBuilder(context);
@@ -103,7 +98,7 @@
builder.createInitialModel();
- NavigationTreeNodeModel model = builder.getModel();
+ NavigationTreeModel model = builder.getModel();
// save tree model in context
setModel(context, model);
@@ -111,23 +106,23 @@
}
@Override
- public NavigationTreeHandler createTreeHandler(JAXXObject context) {
+ public NavigationHandler<NavigationTreeNode> createTreeHandler(JAXXObject context) {
if (log.isDebugEnabled()) {
log.debug("create handler");
}
- NavigationTreeHandler handler;
+ NavigationHandler<NavigationTreeNode> handler;
- handler = new NavigationTreeHandlerWithCardLayout(
+ handler = new NavigationTreeHandlerWithCardLayout<NavigationTreeNode>(
getPrefix(),
context,
- NavigationTreeHandler.Strategy.PER_UI_TYPE) {
+ NavigationHandler.Strategy.PER_UI_TYPE) {
private static final long serialVersionUID = 1L;
@Override
- protected NavigationModel getNavigationTreeModel() {
+ public NavigationModel<NavigationTreeNode> getNavigationTreeModel() {
return getSafeModel(getContext());
}
@@ -142,7 +137,7 @@
}
@Override
- protected void treateError(Exception e) {
+ public void treateError(Exception e) {
ErrorDialogUI.showError(e);
}
@@ -152,7 +147,7 @@
}
};
// on ne peut selectionner qu'un seul noeud a la fois
- handler.setSelectionMode(NavigationTreeHandler.SINGLE_TREE_SELECTION);
+ handler.setSelectionMode(NavigationHandler.SINGLE_TREE_SELECTION);
// save handler in ui context
setTreeHandler(context, handler);
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -27,24 +27,22 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.decorator.Decorator;
import jaxx.runtime.decorator.DecoratorProvider;
-import jaxx.runtime.swing.navigation.NavigationTreeNodeModelBuilder;
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import static org.nuiton.i18n.I18n._;
import java.util.List;
+import static org.nuiton.i18n.I18n._;
+
/**
- *
* @author chemit
* @since 2.0.0
*/
-public class FullNavigationTreeModelBuilder extends NavigationTreeNodeModelBuilder {
+public class FullNavigationTreeModelBuilder extends NavigationTreeModelBuilder {
- /**
- * Logger
- */
+ /** Logger */
static private final Log log = LogFactory.getLog(FullNavigationTreeModelBuilder.class);
protected FullNavigationTreeModelBuilder(JAXXContext context) {
@@ -55,7 +53,7 @@
//TODO
}
- public void addActor(People people,Movie... movies) {
+ public void addActor(People people, Movie... movies) {
//TODO
}
@@ -122,8 +120,8 @@
// construction du noeud avec les acteurs
NavigationTreeNode actorsNode = build(rootNode, _("actors"),
- FullNavigationTreeHelper.ACTORS,
- "actors", ActorsContentUI.class, null);
+ FullNavigationTreeHelper.ACTORS,
+ "actors", ActorsContentUI.class, null);
for (People p : actors) {
// navigation path = $root/actors/p.id
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814)
@@ -21,7 +21,7 @@
<ContentUI superGenericType='People'>
<script><![CDATA[
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
import jaxx.demo.component.jaxx.navigation.*;
@Override
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ActorsContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814)
@@ -23,7 +23,7 @@
<script><![CDATA[
import jaxx.demo.component.jaxx.navigation.*;
import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer;
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
@Override
public void openUI(NavigationTreeNode node) throws Exception {
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814)
@@ -25,7 +25,7 @@
<script><![CDATA[
import jaxx.demo.component.jaxx.navigation.*;
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
ContentUIHandler getHandler() {
return getContextValue(ContentUIHandler.class);
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MovieContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814)
@@ -21,7 +21,7 @@
<ContentUI superGenericType='Movie'>
<script><![CDATA[
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
import jaxx.demo.component.jaxx.navigation.*;
@Override
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/MoviesContentUI.jaxx 2010-03-26 18:05:31 UTC (rev 1814)
@@ -23,7 +23,7 @@
<script><![CDATA[
import jaxx.demo.component.jaxx.navigation.*;
import jaxx.runtime.swing.renderer.DecoratorProviderListCellRenderer;
-import jaxx.runtime.swing.navigation.NavigationTreeNode;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
@Override
public void openUI(NavigationTreeNode node) throws Exception {
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -22,6 +22,9 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
+import jaxx.runtime.swing.navigation.handler.NavigationHandler;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeHelper;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdesktop.swingx.JXTreeTable;
@@ -35,14 +38,14 @@
/**
* Helper object associated to a given navigation tree system.
* <p/>
- * To helper is context safe (base on a {@link NavigationTreeContextHelper}.
+ * To helper is context safe (base on a {@link NavigationContextHelper}.
*
- * @author Letellier
+ * @author letellier <letellier(a)codelutin.com>
* @param <E> type of nodes in model
- * @see NavigationTreeNodeModel
+ * @see NavigationTreeModel
* @since 2.0.1
*/
-public abstract class AbstractNavigationHelper<E extends NavigationNode<E>> extends NavigationTreeContextHelper<E> {
+public abstract class AbstractNavigationHelper<E extends NavigationNode<E>> extends NavigationContextHelper<E> {
/** Logger */
static private final Log log =
@@ -62,7 +65,7 @@
* @param context the context to associate with fresh handler
* @return the new handler
*/
- public abstract NavigationTreeHandler createTreeHandler(JAXXObject context);
+ public abstract NavigationHandler<E> createTreeHandler(JAXXObject context);
public AbstractNavigationHelper(String contextPrefix) {
super(contextPrefix);
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -21,6 +21,7 @@
package jaxx.runtime.swing.navigation;
import jaxx.runtime.JAXXContext;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -41,38 +42,74 @@
* @since 2.0.1
*/
public abstract class AbstractNavigationModel<E extends NavigationNode<E>> implements NavigationModel<E> {
-//public abstract class AbstractNavigationModel<E extends NavigationNode<E>> extends DefaultTreeModel implements NavigationModel<E> {
-// static private final long serialVersionUID = 1L;
-
/** Logger */
- static private final Log log = LogFactory.getLog(NavigationTreeNodeModel.class);
+ static private final Log log = LogFactory.getLog(NavigationTreeModel.class);
- final TreeModel delegate;
+ /** the delegate model */
+ protected final TreeModel delegate;
/**
- * The path separator used to build the {@link NavigationTreeNode#fullPath}.
+ * The path separator used to build the {@link NavigationNode#getFullPath()}.
*
- * @see NavigationTreeNode#getNodePath()
- * @see NavigationTreeNode#getFullPath()
+ * @see NavigationNode#getNodePath()
+ * @see NavigationNode#getFullPath()
*/
protected final String pathSeparator;
/** Context to retrieve beans */
private JAXXContext context;
- public AbstractNavigationModel(TreeModel delegate, String pathSeparator, JAXXContext context) {
+ public AbstractNavigationModel(TreeModel delegate,
+ String pathSeparator,
+ JAXXContext context) {
this.pathSeparator = pathSeparator;
this.context = context;
this.delegate = delegate;
}
+ //--------------------------------------------------------------------------
+ // NavigationModel implementation
+ //--------------------------------------------------------------------------
+
@Override
+ public JAXXContext getContext() {
+ return context;
+ }
+
+ public TreeModel getDelegate() {
+ return delegate;
+ }
+
+ @Override
+ public final String getPathSeparator() {
+ return pathSeparator;
+ }
+
+ @Override
public final E getRoot() {
return (E) getDelegate().getRoot();
}
@Override
+ public final Object getBean(String navigationPath) {
+ Object result;
+ E node = findNode(navigationPath, (Pattern) null);
+ result = getBean(node);
+ return result;
+ }
+
+ @Override
+ public final Object getBean(E node) {
+ if (node == null) {
+ return null;
+ //fixme should throw a NPE exception
+ //throw new NullPointerException("node can not be null");
+ }
+ return node.getBean(getContext());
+ }
+
+ @Override
public final E findNode(String path) {
return findNode(getRoot(), path, (Pattern) null);
}
@@ -127,38 +164,6 @@
}
@Override
- public JAXXContext getContext() {
- return context;
- }
-
- public TreeModel getDelegate() {
- return delegate;
- }
-
- @Override
- public final String getPathSeparator() {
- return pathSeparator;
- }
-
- @Override
- public final Object getBean(String navigationPath) {
- Object result;
- E node = findNode(navigationPath, (Pattern) null);
- result = getBean(node);
- return result;
- }
-
- @Override
- public final Object getBean(E node) {
- if (node == null) {
- return null;
- //fixme should throw a NPE exception
- //throw new NullPointerException("node can not be null");
- }
- return node.getBean(getContext());
- }
-
- @Override
public final void nodeChanged(E node) {
nodeChanged(node, false);
if (log.isDebugEnabled()) {
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -73,7 +73,7 @@
@Override
public E buildEmptyRoot(JAXXContextEntryDef<?> entryDef,
String contextName) {
- E node = createNavigationTreeNode(
+ E node = createNavigationNode(
model.getPathSeparator(),
contextName,
entryDef,
@@ -91,7 +91,7 @@
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(
+ E node = createNavigationNode(
model.getPathSeparator(),
contextName,
entryDef,
@@ -109,7 +109,7 @@
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(
+ E node = createNavigationNode(
model.getPathSeparator(),
contextName,
entryDef,
@@ -127,7 +127,7 @@
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(
+ E node = createNavigationNode(
model.getPathSeparator(),
contextName,
null,
@@ -146,7 +146,7 @@
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(
+ E node = createNavigationNode(
model.getPathSeparator(),
contextName,
entryDef,
@@ -164,7 +164,7 @@
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(
+ E node = createNavigationNode(
model.getPathSeparator(),
contextName,
entryDef,
@@ -182,7 +182,7 @@
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(
+ E node = createNavigationNode(
model.getPathSeparator(),
contextName,
null,
@@ -212,12 +212,12 @@
@Override
public void addI18nNodeRenderer(E node, String libelle) {
- node.setRenderer(new NavigationTreeNodeRendererI18nImpl(libelle));
+ node.setRenderer(new NavigationNodeRendererI18nImpl(libelle));
}
@Override
public void addDecoratorNodeRenderer(E node, Decorator<?> decorator) {
- node.setRenderer(new NavigationTreeNodeRendererDecoratorImpl(decorator));
+ node.setRenderer(new NavigationNodeRendererDecoratorImpl(decorator));
}
@Override
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -20,6 +20,8 @@
*/
package jaxx.runtime.swing.navigation;
+import jaxx.runtime.swing.navigation.handler.NavigationHandler;
+
import java.awt.*;
/**
@@ -32,21 +34,21 @@
/**
* Init the ui just before been opened by the method {@link
- * NavigationTreeHandler#openUI(Component, NavigationNode)}.
+ * NavigationHandler#openUI(Component, NavigationNode)}.
*
* @param node the selected node associated to the ui
* @throws Exception if any pb while opening the content's ui
- * @see NavigationTreeHandler#openUI(Component, NavigationNode)
+ * @see NavigationHandler#openUI(Component, NavigationNode)
*/
void openUI(E node) throws Exception;
/**
* Clean the ui after been closed by the method {@link
- * NavigationTreeHandler#closeUI(Component)}.
+ * NavigationHandler#closeUI(Component)}.
*
* @param node the selected node associated to the ui
* @throws Exception if any pb when closing the content'sui
- * @see NavigationTreeHandler#closeUI(Component)
+ * @see NavigationHandler#closeUI(Component)
*/
void closeUI(E node) throws Exception;
}
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,253 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXUtil;
+import jaxx.runtime.context.JAXXContextEntryDef;
+import jaxx.runtime.swing.navigation.handler.NavigationHandler;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdesktop.swingx.JXTreeTable;
+
+import javax.swing.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * To help getting and setting navigation tree objects from a {@link
+ * JAXXContext}.
+ * <p/>
+ * 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> </ul>
+ * <p/>
+ * To make possible the use of more than one navigation tree system in a same
+ * context, we <b>MUST</b> distinguish the context entries definition. For this
+ * purpose, entries definition are normalized and prefixed by a unique {@link
+ * #prefix}.
+ * <p/>
+ * 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> </ul>
+ *
+ * @author chemit
+ * @since 1.7.2
+ */
+public class NavigationContextHelper<E extends NavigationNode<E>> {
+
+ /** Logger */
+ static private final Log log = LogFactory.getLog(NavigationContextHelper.class);
+
+ protected final String prefix;
+
+ protected JAXXContextEntryDef<List<String>> selectedPathsContextEntry;
+
+ protected JAXXContextEntryDef<List<Object>> selectedBeansContextEntry;
+
+ protected JAXXContextEntryDef<List<E>> selectedNodesContextEntry;
+
+ protected JAXXContextEntryDef<NavigationModel<E>> modelContextEntry;
+
+ protected JAXXContextEntryDef<NavigationHandler<E>> handlerContextEntry;
+
+ protected JAXXContextEntryDef<JTree> treeContextEntry;
+
+ protected JAXXContextEntryDef<JXTreeTable> treeTableContextEntry;
+
+ public NavigationContextHelper(String prefix) {
+ this.prefix = prefix;
+ treeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree", JTree.class);
+ treeTableContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-table", JXTreeTable.class);
+ modelContextEntry = (JAXXContextEntryDef) JAXXUtil.newContextEntryDef(prefix + "-model", NavigationModel.class);
+ handlerContextEntry = (JAXXContextEntryDef) JAXXUtil.newContextEntryDef(prefix + "-handler", NavigationHandler.class);
+ selectedBeansContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-beans");
+ selectedNodesContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-nodes");
+ selectedPathsContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-paths");
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public JTree getTree(JAXXContext context) {
+ JTree r = getTreeContextEntry().getContextValue(context);
+ return r;
+ }
+
+ public JXTreeTable getTreeTable(JAXXContext context) {
+ JXTreeTable r = getTreeTableContextEntry().getContextValue(context);
+ return r;
+ }
+
+ public NavigationModel<E> getModel(JAXXContext context) {
+ NavigationModel<E> r = getModelContextEntry().getContextValue(context);
+ return r;
+ }
+
+ public NavigationHandler<E> getTreeHandler(JAXXContext context) {
+ NavigationHandler<E> r =
+ getTreeHandlerContextEntry().getContextValue(context);
+ return r;
+ }
+
+ public String getSelectedPath(JAXXContext context) {
+ String result = getSelectedValue(getSelectedPathContextEntry(), context);
+ return result;
+ }
+
+ public List<String> getSelectedPaths(JAXXContext context) {
+ return getSelectedPathContextEntry().getContextValue(context);
+ }
+
+ public E getSelectedNode(JAXXContext context) {
+ E result = getSelectedValue(getSelectedNodeContextEntry(), context);
+ return result;
+ }
+
+ public List<E> getSelectedNodes(JAXXContext context) {
+ return getSelectedNodeContextEntry().getContextValue(context);
+ }
+
+ public Object getSelectedBean(JAXXContext context) {
+ Object result = getSelectedValue(getSelectedBeanContextEntry(), context);
+ return result;
+ }
+
+ public List<Object> getSelectedBeans(JAXXContext context) {
+ return getSelectedBeanContextEntry().getContextValue(context);
+ }
+
+ public void setModel(JAXXContext context, NavigationModel<E> model) {
+ getModelContextEntry().setContextValue(context, model);
+ }
+
+ public void setTree(JAXXContext context, JTree tree) {
+ getTreeContextEntry().setContextValue(context, tree);
+ }
+
+ public void setTreeTable(JAXXContext context, JXTreeTable treeTable) {
+ getTreeTableContextEntry().setContextValue(context, treeTable);
+ }
+
+ public void setTreeHandler(JAXXContext context,
+ NavigationHandler<E> handler) {
+ getTreeHandlerContextEntry().setContextValue(context, handler);
+ }
+
+ public void setSelectedPath(JAXXContext context, String path) {
+ setSelectedValue(getSelectedPathContextEntry(), context, path);
+ }
+
+ public void setSelectedPaths(JAXXContext context, List<String> paths) {
+ setSelectedValues(getSelectedPathContextEntry(), context, paths);
+ }
+
+ public void setSelectedNode(JAXXContext context, E node) {
+ setSelectedValue(getSelectedNodeContextEntry(), context, node);
+ }
+
+ public void setSelectedNodes(JAXXContext context, List<E> nodes) {
+ setSelectedValues(getSelectedNodeContextEntry(), context, nodes);
+ }
+
+ public void setSelectedBean(JAXXContext context, Object bean) {
+ setSelectedValue(getSelectedBeanContextEntry(), context, bean);
+ }
+
+ public void setSelectedBeans(JAXXContext context, List<Object> beans) {
+ setSelectedValues(getSelectedBeanContextEntry(), context, beans);
+ }
+
+ protected JAXXContextEntryDef<NavigationModel<E>> getModelContextEntry() {
+ return modelContextEntry;
+ }
+
+ protected JAXXContextEntryDef<NavigationHandler<E>>
+ getTreeHandlerContextEntry() {
+ return handlerContextEntry;
+ }
+
+ protected JAXXContextEntryDef<List<Object>> getSelectedBeanContextEntry() {
+ return selectedBeansContextEntry;
+ }
+
+ protected JAXXContextEntryDef<List<E>> getSelectedNodeContextEntry() {
+ return selectedNodesContextEntry;
+ }
+
+ protected JAXXContextEntryDef<List<String>> getSelectedPathContextEntry() {
+ return selectedPathsContextEntry;
+ }
+
+ protected JAXXContextEntryDef<JTree> getTreeContextEntry() {
+ return treeContextEntry;
+ }
+
+ protected JAXXContextEntryDef<JXTreeTable> getTreeTableContextEntry() {
+ return treeTableContextEntry;
+ }
+
+ 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;
+ }
+
+ 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);
+ }
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContextHelper.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -21,6 +21,7 @@
package jaxx.runtime.swing.navigation;
import jaxx.runtime.JAXXContext;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreePath;
@@ -29,13 +30,12 @@
/**
* Interface to create model of the tree used for a navigation tree.
* <p/>
- * Il est composé de {@link NavigationTreeNode}
+ * Il est composé de {@link NavigationNode}
*
* @author sletellier
* @since 2.0.0
*/
-public interface NavigationModel<E extends NavigationNode<E>> {
-//public interface NavigationModel<E extends NavigationNode<E>> extends TreeModel {
+public interface NavigationModel<E extends NavigationNode<E>> {
E getRoot();
@@ -54,8 +54,8 @@
* <pre>$root.child1.leaf1</pre>
*
* @param path the fully path of the searched node.
- * @return the node matching the fully context from the root node,
- * or <code>null</code> if not find.
+ * @return the node matching the fully context from the root node, or
+ * <code>null</code> if not find.
*/
E findNode(String path);
@@ -113,14 +113,14 @@
* Apply first the regex pattern to obtain the searched node.
* <p/>
* Search then from a given root node a node named by his fully path
- * (concatenation of nodes) {@link NavigationTreeNode#path} valued
- * separated by {@link #getPathSeparator()}.
+ * (concatenation of nodes) {@link NavigationTreeNode#path} valued separated
+ * by {@link #getPathSeparator()}.
*
* @param root root node to be used
* @param path the fully path of the searched node.
* @param regex a previous regex to apply to path : must have a matches
- * @return the node matching the fully context from the given root node,
- * or <code>null</code> if not found.
+ * @return the node matching the fully context from the given root node, or
+ * <code>null</code> if not found.
*/
E findNode(E root, String path, String regex);
@@ -134,16 +134,16 @@
* @param root root node to be used
* @param path the fully path of the searched node.
* @param regex a previous regex to apply to path : must have a matches
- * @return the node matching the fully context from the given root node,
- * or <code>null</code> if not found.
+ * @return the node matching the fully context from the given root node, or
+ * <code>null</code> if not found.
*/
E findNode(E root, String path, Pattern regex);
JAXXContext getContext();
/**
- * Obtain the associated bean value from context corresponding to node
- * from given navigation path.
+ * Obtain the associated bean value from context corresponding to node from
+ * given navigation path.
*
* @param navigationPath the current context path of the node
* @return the value associated in context with the given navigation path
@@ -165,69 +165,64 @@
void nodeChanged(E node, boolean deep);
String getPathSeparator();
-
+
/**
- * Returns the child of <code>parent</code> at index <code>index</code>
- * in the parent's
- * child array. <code>parent</code> must be a node previously obtained
- * from this data source. This should not return <code>null</code>
- * if <code>index</code>
- * is a valid index for <code>parent</code> (that is <code>index >= 0 &&
- * index < getChildCount(parent</code>)).
+ * Returns the child of <code>parent</code> at index <code>index</code> in
+ * the parent's child array. <code>parent</code> must be a node previously
+ * obtained from this data source. This should not return <code>null</code>
+ * if <code>index</code> is a valid index for <code>parent</code> (that is
+ * <code>index >= 0 && index < getChildCount(parent</code>)).
*
- * @param parent a node in the tree, obtained from this data source
- * @return the child of <code>parent</code> at index <code>index</code>
+ * @param parent a node in the tree, obtained from this data source
+ * @param index index of the node
+ * @return the child of <code>parent</code> at index <code>index</code>
*/
Object getChild(Object parent, int index);
-
/**
- * Returns the number of children of <code>parent</code>.
- * Returns 0 if the node
- * is a leaf or if it has no children. <code>parent</code> must be a node
- * previously obtained from this data source.
+ * Returns the number of children of <code>parent</code>. Returns 0 if the
+ * node is a leaf or if it has no children. <code>parent</code> must be a
+ * node previously obtained from this data source.
*
- * @param parent a node in the tree, obtained from this data source
- * @return the number of children of the node <code>parent</code>
+ * @param parent a node in the tree, obtained from this data source
+ * @return the number of children of the node <code>parent</code>
*/
int getChildCount(Object parent);
-
/**
- * Returns <code>true</code> if <code>node</code> is a leaf.
- * It is possible for this method to return <code>false</code>
- * even if <code>node</code> has no children.
- * A directory in a filesystem, for example,
- * may contain no files; the node representing
- * the directory is not a leaf, but it also has no children.
+ * Returns <code>true</code> if <code>node</code> is a leaf. It is possible
+ * for this method to return <code>false</code> even if <code>node</code>
+ * has no children. A directory in a filesystem, for example, may contain no
+ * files; the node representing the directory is not a leaf, but it also has
+ * no children.
*
- * @param node a node in the tree, obtained from this data source
- * @return true if <code>node</code> is a leaf
+ * @param node a node in the tree, obtained from this data source
+ * @return true if <code>node</code> is a leaf
*/
boolean isLeaf(Object node);
/**
- * Messaged when the user has altered the value for the item identified
- * by <code>path</code> to <code>newValue</code>.
- * If <code>newValue</code> signifies a truly new value
- * the model should post a <code>treeNodesChanged</code> event.
- *
- * @param path path to the node that the user has altered
- * @param newValue the new value from the TreeCellEditor
- */
+ * Messaged when the user has altered the value for the item identified by
+ * <code>path</code> to <code>newValue</code>. If <code>newValue</code>
+ * signifies a truly new value the model should post a
+ * <code>treeNodesChanged</code> event.
+ *
+ * @param path path to the node that the user has altered
+ * @param newValue the new value from the TreeCellEditor
+ */
void valueForPathChanged(TreePath path, Object newValue);
/**
- * Returns the index of child in parent. If either <code>parent</code>
- * or <code>child</code> is <code>null</code>, returns -1.
- * If either <code>parent</code> or <code>child</code> don't
- * belong to this tree model, returns -1.
+ * Returns the index of child in parent. If either <code>parent</code> or
+ * <code>child</code> is <code>null</code>, returns -1. If either
+ * <code>parent</code> or <code>child</code> don't belong to this tree
+ * model, returns -1.
*
* @param parent a node in the tree, obtained from this data source
- * @param child the node we are interested in
+ * @param child the node we are interested in
* @return the index of the child in the parent, or -1 if either
- * <code>child</code> or <code>parent</code> are <code>null</code>
- * or don't belong to this tree model
+ * <code>child</code> or <code>parent</code> are <code>null</code>
+ * or don't belong to this tree model
*/
int getIndexOfChild(Object parent, Object child);
@@ -236,21 +231,19 @@
//
/**
- * Adds a listener for the <code>TreeModelEvent</code>
- * posted after the tree changes.
+ * Adds a listener for the {@code TreeModelEvent} posted after the tree
+ * changes.
*
- * @param l the listener to add
- * @see #removeTreeModelListener
+ * @param l the listener to add
+ * @see #removeTreeModelListener
*/
void addTreeModelListener(TreeModelListener l);
/**
- * Removes a listener previously added with
- * <code>addTreeModelListener</code>.
+ * Removes a listener previously added with {@code addTreeModelListener}.
*
- * @see #addTreeModelListener
- * @param l the listener to remove
+ * @param l the listener to remove
+ * @see #addTreeModelListener
*/
void removeTreeModelListener(TreeModelListener l);
-
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -26,7 +26,7 @@
import jaxx.runtime.decorator.Decorator;
/**
- * Interface to create a builder, this object is design to build a {@link
+ * Contract to create a builder, this object is design to build a {@link
* NavigationModel}.
*
* @author sletellier
@@ -38,7 +38,7 @@
// To create your own instance of NavigationTreeTableNode
- E createNavigationTreeNode(
+ E createNavigationNode(
String pathSeparator,
String contextName,
JAXXContextEntryDef<?> jaxxContextEntryDef,
@@ -92,10 +92,11 @@
E removeChildNode(E node);
+ void moveNode(E parentNode, E node, int position);
+
void addI18nNodeRenderer(E node, String libelle);
- void addDecoratorNodeRenderer(E node,
- Decorator<?> decorator);
+ void addDecoratorNodeRenderer(E node, Decorator<?> decorator);
void addNodeJaxxClasses(
E node,
@@ -103,6 +104,4 @@
Class<? extends JAXXAction> uIHandlerClass);
void printModel(E node);
-
- void moveNode(E parentNode, E node, int position);
}
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-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -21,6 +21,8 @@
package jaxx.runtime.swing.navigation;
+import jaxx.runtime.swing.navigation.handler.NavigationMultiTreeHandler;
+
import java.awt.*;
import java.util.List;
@@ -38,16 +40,17 @@
*
* @param nodes the selected node associated to the ui
* @throws Exception if any pb while opening the content's ui
+ * @see NavigationMultiTreeHandler#openUI(Component, List)
*/
void openUI(List<E> nodes) throws Exception;
/**
* Clean the ui after been closed by the method {@link
- * NavigationTreeHandler#closeUI(Component)}.
+ * NavigationMultiTreeHandler#closeUI(Component)}.
*
* @param nodes the selected node associated to the ui
* @throws Exception if any pb when closing the content'sui
- * @see NavigationTreeHandler#closeUI(Component)
+ * @see NavigationMultiTreeHandler#closeUI(Component)
*/
void closeUI(List<E> nodes) throws Exception;
}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,187 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.tree.TreePath;
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The handler of a navigation tree.
- * <p/>
- * This is also the selection model to use, since we must check before moving
- * from nodes we can not just listen selection model changed, we must control
- * it.
- * <p/>
- * This one is used to enable multi selection
- *
- * @author sletellier
- * @since 2.0.1
- */
-public abstract class NavigationMultiTreeHandler<E extends NavigationNode<E>> extends NavigationTreeHandler<E> {
-
- /** Logger */
- static private final Log log =
- LogFactory.getLog(NavigationMultiTreeHandler.class);
-
-
- public NavigationMultiTreeHandler(String contextPrefix,
- JAXXObject context,
- Strategy strategy) {
- super(contextPrefix, context, strategy);
-
- // Enable multi selection
- setSelectionMode(DISCONTIGUOUS_TREE_SELECTION);
- }
-
- @Override
- public void valueChanged(TreeSelectionEvent event) {
- TreePath[] paths = event.getPaths();
-
- // TODO : verifier que la selection n'est pas la même
- List<E> nodes = new ArrayList<E>();
- if (paths == null) {
- selectNodeUI(new ArrayList<E>());
- return;
- }
- for (TreePath path : paths) {
- E node = (E) path.getLastPathComponent();
- nodes.add(node);
- if (log.isDebugEnabled()) {
- log.debug("Adding path : " + path);
- log.debug("As node : " + node.getFullPath());
- }
- }
- selectNodeUI(nodes);
- }
-
- /**
- * Ouvre l'ui associée aux noeuds sélectionnés dans l'arbre de navigation.
- *
- * @param newUI l'ui associé au noeud sélectionné à ouvrir
- * @param nodes les node de l'ui a ouvrir
- * @throws Exception if any
- */
- protected abstract void openUI(Component newUI,
- List<E> nodes)
- throws Exception;
-
- /**
- * Instancie une nouvelle ui associé à des noeuds de l'arbre de navigation
- *
- * @param nodes les noeuds associés à l'ui à créer
- * @return la nouvelle ui associée au noeud
- * @throws Exception if any
- */
- protected abstract Component createUI(List<E> nodes)
- throws Exception;
-
- /**
- * @param nodes les noeuds associés à l'ui à retrouver
- * @return l'ui associés au nouveau noeud sélectionné
- */
- protected abstract Component getUI(List<E> nodes);
-
- protected void selectNodeUI(List<E> nodes) {
- log.info("select nodes " + nodes);
-
- try {
-// List<String> paths = new ArrayList<String>();
- List<Object> beans = new ArrayList<Object>();
- for (E node : nodes) {
-
- String path = node.getFullPath();
-// paths.add(path);
-
- if (log.isTraceEnabled()) {
- log.trace(path);
- }
- // now, we are free to open the ui associated with the selected
- // node in navigation
-
- // get the bean associated with the node
- beans.add(getNavigationTreeModel().getBean(path));
- }
-
- Component newUI = getUI(nodes);
-
- // save it in context (must be done before init ui)
- JAXXContext ctxt = getContext();
- NavigationTreeContextHelper<E> helper = getContextHelper();
-
- // remove previous selected bean
- //TODO-TC-20091004 should have an automatic clean context method
- //TODO-TC-20091004 while
- helper.setSelectedBean(ctxt, null);
-
-// if (beans != null) {
- helper.setSelectedBeans(ctxt, beans);
-// }
-
- if (newUI == null) {
-
- // a new ui instance is required
- newUI = createUI(nodes);
- }
-
- // save in context current node context path
- helper.setSelectedPaths(ctxt, getPaths(nodes));
-
- // save in context current node
- helper.setSelectedNodes(ctxt, nodes);
-
- // save in context current ui
-// helper.setSelectedUI(ctxt, newUI);
-
- // really open the ui associated with the selected node
- // init ui before to be visible
- if (newUI instanceof NavigationMultiContentUI<?>) {
- ((NavigationMultiContentUI<E>) newUI).openUI(nodes);
- }
-
- // set ui in content
- openUI(newUI, nodes);
-
- } catch (Exception e) {
- // remove data from context
-
- // if any error, go back to previvous node
- treateError(e);
- }
- }
-
- protected List<String> getPaths(List<E> nodes) {
- List<String> result = new ArrayList<String>();
- for (E node : nodes) {
- result.add(node.getFullPath());
- }
- return result;
- }
-
-}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -8,36 +8,29 @@
import java.io.Serializable;
import java.util.Enumeration;
+/**
+ * Contract of a navigation node.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @param <E> type of the node
+ * @since 2.0.1
+ */
public interface NavigationNode<E extends NavigationNode<E>> extends Cloneable, Serializable {
-// public interface NavigationNode<E extends NavigationNode<E>> extends Cloneable, MutableTreeNode, Serializable {
- NavigationTreeNodeRenderer getRenderer();
- void setRenderer(NavigationTreeNodeRenderer renderer);
+ NavigationNodeRenderer getRenderer();
String getPathSeparator();
String getNodePath();
- void setNodePath(String navigationPath);
-
Class<? extends JAXXObject> getUIClass();
- void setUIClass(Class<? extends JAXXObject> uIClass);
-
- void setInternalClass(Class<?> internalClass);
-
Class<? extends JAXXAction> getUIHandlerClass();
- void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass);
-
JAXXContextEntryDef<?> getJaxxContextEntryDef();
- void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef);
-
String getJaxxContextEntryPath();
- void setJaxxContextEntryPath(String jaxxContextEntryPath);
-
Class<?> getInternalClass();
String getFullPath();
@@ -50,24 +43,8 @@
Object getBean();
- void setBean(Object bean);
-
- void reload(JAXXContext context);
-
Object getBean(JAXXContext context);
- void insert(E child, int index);
-
- void remove(int index);
-
- void remove(E node);
-
- void setUserObject(Object object);
-
- void removeFromParent();
-
- void setParent(E newParent);
-
int getChildCount();
int getIndex(E node);
@@ -82,10 +59,40 @@
Object getUserObject();
- void add(E node);
+ E[] getPathToRoot(E aNode, int depth);
- E[] getPathToRoot(E aNode, int depth) ;
-
E[] getPath();
+ void setRenderer(NavigationNodeRenderer renderer);
+
+ void setNodePath(String navigationPath);
+
+ void setUIClass(Class<? extends JAXXObject> uIClass);
+
+ void setInternalClass(Class<?> internalClass);
+
+ void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass);
+
+ void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef);
+
+ void setJaxxContextEntryPath(String jaxxContextEntryPath);
+
+ void setParent(E newParent);
+
+ void setBean(Object bean);
+
+ void setUserObject(Object object);
+
+ void reload(JAXXContext context);
+
+ void add(E node);
+
+ void insert(E child, int index);
+
+ void remove(int index);
+
+ void remove(E node);
+
+ void removeFromParent();
+
}
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,62 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import javax.swing.tree.TreeCellRenderer;
+import java.io.Serializable;
+
+/**
+ * Text Renderer of a {@link NavigationNode}.
+ * <p/>
+ * This object will be placed as the {@link NavigationNode#getUserObject()} of
+ * nodes.
+ * <p/>
+ * <p/>
+ * In that way, we can use the {@link #toString()} value to render the node
+ * without writing any {@link TreeCellRenderer}.
+ * <p/>
+ * To rebuild the renderer text of a node use the method {@link #reload(Object)}
+ * with the {@code bean} provides by the model for the node.
+ *
+ * @author chemit
+ * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear
+ * soon...
+ */
+public interface NavigationNodeRenderer extends Serializable {
+
+ /** @return the render value of the node */
+ @Override
+ String toString();
+
+ /**
+ * Can override the node internal class for display purpose.
+ *
+ * @return the type of data to be displayed.
+ */
+ Class<?> getInternalClass();
+
+ /**
+ * Reload the render value from the {@code bean} of node.
+ *
+ * @param bean the bean associated to the node to render
+ */
+ void reload(Object bean);
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRenderer.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,72 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.decorator.Decorator;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
+
+/**
+ * Decorator Renderer of a {@link NavigationTreeNode}.
+ * <p/>
+ * Apply a {@link Decorator} to the {@code bean} associated to the node.
+ *
+ * @author chemit
+ * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear
+ * soon...
+ */
+public class NavigationNodeRendererDecoratorImpl implements NavigationNodeRenderer {
+
+ private static final long serialVersionUID = -1L;
+
+ /** Decorator */
+ protected final Decorator<?> decorator;
+
+ /** internal class of representing data */
+ protected final Class<?> internalClass;
+
+ /** last renderered value */
+ protected String text;
+
+ public NavigationNodeRendererDecoratorImpl(Decorator<?> decorator) {
+ internalClass = decorator.getInternalClass();
+ this.decorator = decorator;
+ }
+
+ @Override
+ public String toString() {
+ return text;
+ }
+
+ @Override
+ public void reload(Object bean) {
+ try {
+ text = decorator.toString(bean);
+
+ } catch (Exception e) {
+ text = "";
+ }
+ }
+
+ @Override
+ public Class<?> getInternalClass() {
+ return internalClass;
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererDecoratorImpl.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,68 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
+
+import static org.nuiton.i18n.I18n._;
+
+/**
+ * I18n label Renderer of a {@link NavigationTreeNode}.
+ * <p/>
+ * Just apply a i18n translation on the given {@link #libelle}.
+ *
+ * @author chemit
+ * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear
+ * soon...
+ */
+public class NavigationNodeRendererI18nImpl implements NavigationNodeRenderer {
+
+ private static final long serialVersionUID = -1L;
+
+ /** Static i18n label to render */
+ protected final String libelle;
+
+ /** internal class of representing data */
+ protected final Class<?> internalClass;
+
+ /** last renderered value */
+ protected String text;
+
+ public NavigationNodeRendererI18nImpl(String libelle) {
+ this.libelle = libelle;
+ internalClass = String.class;
+ }
+
+ @Override
+ public String toString() {
+ return text;
+ }
+
+ @Override
+ public void reload(Object data) {
+ text = _(libelle);
+ }
+
+ @Override
+ public Class<?> getInternalClass() {
+ return internalClass;
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNodeRendererI18nImpl.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,66 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXObject;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.tree.TreePath;
-import java.util.Arrays;
-
-/**
- * The handler of a navigation tree.
- * <p/>
- * This is also the selection model to use, since we must check before moving
- * from nodes we can not just listen selection model changed, we must control
- * it.
- * <p/>
- * This one is used to enable one clic multi selection
- *
- * @author sletellier
- * @since 2.0.1
- */
-public abstract class NavigationOneClicSelectionHandler<E extends NavigationNode<E>> extends NavigationMultiTreeHandler<E> {
-
- /** Logger */
- static private final Log log =
- LogFactory.getLog(NavigationOneClicSelectionHandler.class);
-
-
- public NavigationOneClicSelectionHandler(String contextPrefix,
- JAXXObject context,
- Strategy strategy) {
- super(contextPrefix, context, strategy);
- }
-
- @Override
- public void setSelectionPath(TreePath path) {
- TreePath[] treePaths = getSelectionPaths();
- if (treePaths == null || !Arrays.asList(treePaths).contains(path)) {
- addSelectionPath(path);
- } else {
- removeSelectionPath(path);
- }
- }
-
-}
Deleted: 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-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,253 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXUtil;
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jdesktop.swingx.JXTreeTable;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.swing.JTree;
-
-/**
- * To help getting and setting navigation tree objects from a {@link JAXXContext}.
- * <p/>
- * 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>
- * </ul>
- * <p/>
- * To make possible the use of more than one navigation tree system in a same
- * context, we <b>MUST</b> distinguish the context entries definition. For this
- * purpose, entries definition are normalized and prefixed by a unique {@link #prefix}.
- * <p/>
- * 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>
- * </ul>
- *
- * @author chemit
- * @since 1.7.2
- */
-public class NavigationTreeContextHelper <E extends NavigationNode<E>> {
-
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(NavigationTreeContextHelper.class);
-
- protected final String prefix;
- protected JAXXContextEntryDef<List<String>> selectedPathsContextEntry;
- protected JAXXContextEntryDef<List<Object>> selectedBeansContextEntry;
- protected JAXXContextEntryDef<List<E>> selectedNodesContextEntry;
- protected JAXXContextEntryDef<NavigationModel<E>> modelContextEntry;
- protected JAXXContextEntryDef<NavigationTreeHandler> handlerContextEntry;
- protected JAXXContextEntryDef<JTree> treeContextEntry;
- protected JAXXContextEntryDef<JXTreeTable> treeTableContextEntry;
-
- public NavigationTreeContextHelper(String prefix) {
- this.prefix = prefix;
- treeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree", JTree.class);
- treeTableContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-table", JXTreeTable.class);
- modelContextEntry = (JAXXContextEntryDef)JAXXUtil.newContextEntryDef(prefix + "-model", NavigationModel.class);
- handlerContextEntry = JAXXUtil.newContextEntryDef(prefix + "-handler", NavigationTreeHandler.class);
- selectedBeansContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-beans");
- selectedNodesContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-nodes");
- selectedPathsContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-paths");
- }
-
- public String getPrefix() {
- return prefix;
- }
-
- public JTree getTree(JAXXContext context) {
- JTree r = getTreeContextEntry().getContextValue(context);
- return r;
- }
-
- public JXTreeTable getTreeTable(JAXXContext context) {
- JXTreeTable r = getTreeTableContextEntry().getContextValue(context);
- return r;
- }
-
- public NavigationModel<E> getModel(JAXXContext context) {
- NavigationModel<E> r = getModelContextEntry().getContextValue(context);
- return r;
- }
-
- public NavigationTreeHandler getTreeHandler(JAXXContext context) {
- NavigationTreeHandler r =
- getTreeHandlerContextEntry().getContextValue(context);
- return r;
- }
-
- public String getSelectedPath(JAXXContext context) {
- String result = getSelectedValue(getSelectedPathContextEntry(),context);
- return result;
- }
-
- public List<String> getSelectedPaths(JAXXContext context) {
- return getSelectedPathContextEntry().getContextValue(context);
- }
-
- public E getSelectedNode(JAXXContext context) {
- E result = getSelectedValue(getSelectedNodeContextEntry(),context);
- return result;
- }
-
- public List<E> getSelectedNodes(JAXXContext context) {
- return getSelectedNodeContextEntry().getContextValue(context);
- }
-
- public Object getSelectedBean(JAXXContext context) {
- Object result = getSelectedValue(getSelectedBeanContextEntry(),context);
- return result;
- }
-
- public List<Object> getSelectedBeans(JAXXContext context) {
- return getSelectedBeanContextEntry().getContextValue(context);
- }
-
- public void setModel(JAXXContext context, NavigationModel<E> model) {
- getModelContextEntry().setContextValue(context, model);
- }
-
- public void setTree(JAXXContext context, JTree tree) {
- getTreeContextEntry().setContextValue(context, tree);
- }
-
- public void setTreeTable(JAXXContext context, JXTreeTable treeTable) {
- getTreeTableContextEntry().setContextValue(context, treeTable);
- }
-
- public void setTreeHandler(JAXXContext context,
- NavigationTreeHandler handler) {
- getTreeHandlerContextEntry().setContextValue(context, handler);
- }
-
- public void setSelectedPath(JAXXContext context, String path) {
- setSelectedValue(getSelectedPathContextEntry(), context, path);
- }
-
- public void setSelectedPaths(JAXXContext context, List<String> paths) {
- setSelectedValues(getSelectedPathContextEntry(), context, paths);
- }
-
- public void setSelectedNode(JAXXContext context, E node) {
- setSelectedValue(getSelectedNodeContextEntry(), context, node);
- }
-
- public void setSelectedNodes(JAXXContext context, List<E> nodes) {
- setSelectedValues(getSelectedNodeContextEntry(), context, nodes);
- }
-
- public void setSelectedBean(JAXXContext context, Object bean) {
- setSelectedValue(getSelectedBeanContextEntry(), context, bean);
- }
-
- public void setSelectedBeans(JAXXContext context, List<Object> beans) {
- setSelectedValues(getSelectedBeanContextEntry(), context, beans);
- }
-
- protected JAXXContextEntryDef<NavigationModel<E>> getModelContextEntry() {
- return modelContextEntry;
- }
-
- protected JAXXContextEntryDef<NavigationTreeHandler>
- getTreeHandlerContextEntry() {
- return handlerContextEntry;
- }
-
- protected JAXXContextEntryDef<List<Object>> getSelectedBeanContextEntry() {
- return selectedBeansContextEntry;
- }
-
- protected JAXXContextEntryDef<List<E>> getSelectedNodeContextEntry() {
- return selectedNodesContextEntry;
- }
-
- protected JAXXContextEntryDef<List<String>> getSelectedPathContextEntry() {
- return selectedPathsContextEntry;
- }
-
- protected JAXXContextEntryDef<JTree> getTreeContextEntry() {
- return treeContextEntry;
- }
-
- protected JAXXContextEntryDef<JXTreeTable> getTreeTableContextEntry() {
- return treeTableContextEntry;
- }
-
- 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;
- }
-
- 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);
- }
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,342 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXAction;
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.context.JAXXInitialContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
-import javax.swing.tree.DefaultTreeSelectionModel;
-import javax.swing.tree.TreePath;
-import java.awt.*;
-import java.util.Arrays;
-
-/**
- * The handler of a navigation tree.
- * <p/>
- * This is also the selection model to use, since we must check before moving
- * from a node we can not just listen selection model changed, we must control
- * it.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 1.7.2
- */
-public abstract class NavigationTreeHandler<E extends NavigationNode<E>> extends DefaultTreeSelectionModel implements TreeSelectionListener {
-
- private static final long serialVersionUID = 1L;
-
- /** Logger */
- static private final Log log = LogFactory.getLog(NavigationTreeHandler.class);
-
- /**
- * Strategy of instanciation of ui.
- * <p/>
- * For a given {@code node}, the method {@link #getId(NavigationNode)}
- * returns the id of ui to use.
- */
- public enum Strategy {
-
- /** instanciate a ui for a node */
- PER_NODE {
-
- @Override
- public String getId(NavigationNode<?> node) {
- return node.getFullPath();
- }
- },
- /**
- * instanciate only one a ui for a type,nodes will share the
- * instanciation
- */
- PER_UI_TYPE {
-
- @Override
- public String getId(NavigationNode<?> node) {
- return node.getUIClass().getName();
- }
- };
-
- public abstract String getId(NavigationNode<?> node);
- }
-
- /** UI which contains navigation tree */
- protected JAXXContext context;
-
- /** UI Instanciation strategy */
- protected Strategy strategy;
-
- /**
- * JAXXContext access helper.
- *
- * @since 1.7.2
- */
- protected NavigationTreeContextHelper<E> contextHelper;
-
- protected NavigationTreeHandler(String contextPrefix, JAXXObject context, Strategy strategy) {
- contextHelper = new NavigationTreeContextHelper<E>(contextPrefix);
- this.context = context;
- this.strategy = strategy;
- addTreeSelectionListener(this);
- }
-
- @Override
- public void valueChanged(TreeSelectionEvent event) {
- if (log.isDebugEnabled()) {
- log.debug("Value changed for path : " + event.getPath());
- log.debug("Old lead selection path : " + event.getOldLeadSelectionPath());
- }
- if (event.getOldLeadSelectionPath() != null && event.getOldLeadSelectionPath().equals(event.getPath())) {
- // do not treate this if no path changed
- return;
- }
- E node = (E) event.getPath().getLastPathComponent();
- selectNodeUI(node);
- }
-
- /** @return le modèle de navigation associé */
- protected abstract NavigationModel<?> getNavigationTreeModel();
-
- /**
- * @return le composent actuellement visible associé au noeud courant ou au
- * noeud précédent lors d'un changement de noeud.
- */
- protected abstract Component getCurrentUI();
-
- /**
- * @param node le noeud associé à l'ui à retrouver
- * @return l'ui associé au novueau noeud sélectionné
- */
- protected abstract Component getUI(E node);
-
- /**
- * @param component le composent actuellement visible
- * @return <code>true</code> si le composent a bien été fermé,
- * <code>false</code> sinon
- * @throws Exception if any
- */
- protected abstract boolean closeUI(Component component) throws Exception;
-
- /**
- * Instancie une nouvelle ui associé à un noeud de l'arbre de navigation
- *
- * @param node le noeud associé à l'ui à créer
- * @return la nouvelle ui associée au noeud
- * @throws Exception if any
- */
- protected abstract Component createUI(E node) throws Exception;
-
- /**
- * Ouvre l'ui associée au noeud sélectionné dans l'arbre de navigation.
- *
- * @param newUI l'ui associé au noeud sélectionné à ouvrir
- * @param node le node de l'ui a ouvrir
- * @throws Exception if any
- */
- protected abstract void openUI(Component newUI, E node) throws Exception;
-
- /**
- * Traitement des exceptions.
- *
- * @param e l'erreur recontrée (ou null si pas d"erreur)
- */
- protected abstract void treateError(Exception e);
-
- public JAXXContext getContext() {
- return context;
- }
-
- public NavigationTreeContextHelper<E> getContextHelper() {
- return contextHelper;
- }
-
- @Override
- public void setSelectionPath(TreePath path) {
- if (path.equals(getSelectionPath())) {
- // stay on same node, can skip
- if (log.isDebugEnabled()) {
- log.debug("skip stay on path " + path);
- }
- return;
- }
- Component component = getCurrentUI();
-
- try {
- if (!closeUI(component)) {
- if (log.isDebugEnabled()) {
- log.debug("changing node canceled!");
- }
- // can not changed current node
- return;
- }
- if (component instanceof NavigationContentUI<?>) {
- ((NavigationContentUI<E>) component).closeUI((E) path.getLastPathComponent());
- }
- } catch (Exception ex) {
- treateError(ex);
- return;
- }
- if (log.isDebugEnabled()) {
- log.debug("will select path " + path);
- }
- // ok can safely select the new path
- super.setSelectionPath(path);
- }
-
- @Override
- public void setSelectionPaths(TreePath[] paths) {
- //FIXME-TC20100315 this can not work...
- // can't test like this paths as Array...
- if (Arrays.equals(paths, getSelectionPaths())) {
- // stay on same node, can skip
- if (log.isDebugEnabled()) {
- log.debug("skip stay on path " + Arrays.toString(paths));
- }
- return;
- }
- Component component = getCurrentUI();
-
- try {
- if (!closeUI(component)) {
- if (log.isDebugEnabled()) {
- log.debug("changing node canceled!");
- }
- // can not changed current node
- return;
- }
- if (component instanceof NavigationMultiContentUI<?>) {
- if (paths.length == 1) {
- NavigationTreeContextHelper<E> helper = getContextHelper();
- ((NavigationMultiContentUI<E>) component).closeUI(helper.getSelectedNodes(getContext()));
- }
- }
- } catch (Exception ex) {
- treateError(ex);
- return;
- }
- if (log.isDebugEnabled()) {
- log.debug("will select " + paths.length + " paths");
- }
- // ok can safely select the new path
- super.setSelectionPaths(paths);
- }
-
- protected void selectNodeUI(E node) {
-
- try {
-
- String path = node.getFullPath();
-
- if (log.isTraceEnabled()) {
- log.trace(path);
- }
-
- Component newUI = getUI(node);
-
- // now, we are free to open the ui associated with the selected node in navigation
-
- // get the bean associated with the node
- Object data = getNavigationTreeModel().getBean(path);
-
- // save it in context (must be done before init ui)
- addSelectedBeanInContext(node, data);
-
- if (newUI == null) {
-
- // a new ui instance is required
- newUI = createUI(node);
- }
-
- JAXXContext ctxt = getContext();
- NavigationTreeContextHelper<E> helper = getContextHelper();
-
- // save in context current node context path
- helper.setSelectedPath(ctxt, node.getFullPath());
-
- // save in context current node
- helper.setSelectedNode(ctxt, node);
-
- // save in context current ui
-// helper.setSelectedUI(ctxt, newUI);
-
- // really open the ui associated with the selected node
- // init ui before to be visible
- if (newUI instanceof NavigationContentUI<?>) {
- ((NavigationContentUI<E>) newUI).openUI(node);
- }
-
- // set ui in content
- openUI(newUI, node);
-
- } catch (Exception e) {
- // remove data from context
-
- // if any error, go back to previvous node
- treateError(e);
- }
- }
-
- /**
- * Prepare le context a utiliser pour initialiser une nouvelle ui.
- *
- * @param node le noeud associé à l'ui à créer
- * @return le context à utiliser pour instancier l'ui
- * @throws Exception if any
- */
- protected JAXXContext createUIContext(E node) throws Exception {
-
- if (node.getUIHandlerClass() == null) {
- if (log.isWarnEnabled()) {
- log.warn("no action associated with ui " + node.getUIClass());
- }
- // no action associated, just
- return getContext();
- }
-
- JAXXAction action = node.getUIHandlerClass().newInstance();
-
- // init context with
- JAXXInitialContext uiContext = action.init(getContext());
- return uiContext;
- }
-
- protected void addSelectedBeanInContext(E node, Object data) {
-
- if (log.isDebugEnabled()) {
- log.debug("find data for contextPath <" + node.getFullPath() + "> : " + (data == null ? null : data.getClass()));
- }
- JAXXContext ctxt = getContext();
- NavigationTreeContextHelper<E> helper = getContextHelper();
-
- // remove previous selected bean
- //TODO-TC-20091004 should have an automatic clean context method while
- helper.setSelectedBean(ctxt, null);
-
- if (data != null) {
-
- helper.setSelectedBean(ctxt, data);
- }
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,131 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.swing.CardLayout2;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.*;
-import java.awt.*;
-import java.lang.reflect.Constructor;
-
-/**
- * Simple {@link NavigationTreeHandler} implementation with a {@link
- * CardLayout2} to manage components to associated with tree's nodes.
- * <p/>
- * For each node, the ui associated has a constraints in a cardlayout which is
- * the node context path.
- * <p/>
- * A single container managed by the cardlayout is used to display the
- * components associated with tree's nodes.
- *
- * @author chemit
- */
-public abstract class NavigationTreeHandlerWithCardLayout<E extends NavigationNode<E>> extends NavigationTreeHandler<E> {
-
- /** Logger */
- static private final Log log = LogFactory.getLog(NavigationTreeHandlerWithCardLayout.class);
-
- /**
- * All components associated with a tree's node is displayed in a single
- * container.
- *
- * @return the containter of components
- */
- protected abstract JPanel getContentContainer();
-
- /**
- * the cardlayout managing components associated with tree node. The
- * constraints of each component is the node contextPath.
- *
- * @return the layout used to display components associated with tree's
- * nodes.
- */
- protected abstract CardLayout2 getContentLayout();
-
- public NavigationTreeHandlerWithCardLayout(String contextPrefix,
- JAXXObject context,
- Strategy strategy) {
- super(contextPrefix, context, strategy);
- if (getContentContainer() == null) {
- throw new IllegalArgumentException(
- "could not have a null 'contentContainer' in ui " + context);
- }
- if (getContentLayout() == null) {
- throw new IllegalArgumentException(
- "could not have a null 'contentLayout' in ui " + context);
- }
- }
-
- @Override
- protected Component getCurrentUI() {
- CardLayout2 layout = getContentLayout();
- JPanel container = getContentContainer();
- return layout.getVisibleComponent(container);
- }
-
- @Override
- protected Component getUI(E node) {
- CardLayout2 layout = getContentLayout();
- JPanel container = getContentContainer();
- String constraints = strategy.getId(node);
- return layout.contains(constraints) ?
- layout.getComponent(container, constraints) : null;
- }
-
- @Override
- protected void openUI(Component newUI, E node) throws
- Exception {
-
- CardLayout2 layout = getContentLayout();
- JPanel container = getContentContainer();
- // switch layout
- String constraints = strategy.getId(node);
- layout.show(container, constraints);
- }
-
- @Override
- protected boolean closeUI(Component component) throws Exception {
- // by default, we says that component was succesfull closed
- return true;
- }
-
- @Override
- protected Component createUI(E node) throws Exception {
-
- JAXXContext uiContext = createUIContext(node);
-
- Constructor<? extends JAXXObject> constructor =
- node.getUIClass().getConstructor(JAXXContext.class);
- JAXXObject newUI = constructor.newInstance(uiContext);
-
- if (log.isDebugEnabled()) {
- log.debug("instanciate new ui " + newUI);
- }
- String constraints = strategy.getId(node);
- getContentContainer().add((Component) newUI, constraints);
- return (Component) newUI;
- }
-}
-
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,37 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-/**
- * Helper object associated to a given navigation tree system.
- *
- * To helper is context safe (base on a {@link NavigationTreeContextHelper}.
- *
- * @author chemit
- * @since 1.7.2
- * @see NavigationTreeNodeModel
- */
-public abstract class NavigationTreeHelper extends AbstractNavigationHelper<NavigationTreeNode> {
-
- protected NavigationTreeHelper(String contextPrefix) {
- super(contextPrefix);
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,551 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXAction;
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.tree.DefaultMutableTreeNode;
-import javax.swing.tree.TreeNode;
-import java.util.Enumeration;
-
-/**
- * Node of the {@link NavigationTreeNodeModel}.
- * <p/>
- * Each node is associated with : <ul> <li> a {@code bean} coming from a {@link
- * JAXXContext} </li> <li> a {@code uiClass} to build the associated ui </li>
- * </ul>
- * <p/>
- * To retrieve the bean from the context, there is a huge logic in the method
- * {@link #getBean(JAXXContext)}.
- * <p/>
- * In few words, if the {@link #jaxxContextEntryDef} is defined, it means that
- * the object is taken from the {@code context}.
- * <p/>
- * Otherwise, find the first ancestor with an context entry and retrieve from
- * here the bean.
- * <p/>
- * Then go down to the initial node by applying the jxpath expressions {@link
- * #jaxxContextEntryPath} of each node on road back.
- * <p/>
- * <p/>
- * To identify easly a node, each node has a {@link #path} and a {@link
- * #fullPath} (full path from root node).
- * <p/>
- * <p/>
- * To display the node we use a {@link NavigationTreeNodeRenderer} which is in
- * fact the {@link #userObject}, the object can be synch with the bean via the
- * {@link NavigationTreeNodeRenderer#reload(Object)} method.
- *
- * @author chemit
- * @see NavigationTreeNodeModel
- * @see NavigationTreeNodeRenderer
- * @since 1.7.2
- */
-public class NavigationTreeNode extends DefaultMutableTreeNode implements NavigationNode<NavigationTreeNode> {
-
- private static final long serialVersionUID = 1L;
-
- /** Logger */
- static private final Log log = LogFactory.getLog(NavigationTreeNode.class);
-
- /**
- * The path separator used to build the {@link #fullPath}.
- *
- * @see #path
- * @see #fullPath
- */
- protected final String pathSeparator;
-
- /**
- * The node path.
- * <p/>
- * Used to build the {@link #fullPath} which gives a unique identifier of
- * the node.
- *
- * @see #pathSeparator
- * @see #fullPath
- */
- protected String path;
-
- /**
- * The full path for the node from the rood node.
- * <p/>
- * This path is build by appending nodes {@link #path} from the root node to
- * this node, between each path we introduce the {@link #pathSeparator}.
- * <p/>
- * Exemple :
- * <pre>
- * root
- * $root
- * `-- child1
- * `-- child2
- * </pre>
- * will given {@code $root/child1/child2}.
- *
- * @see #pathSeparator
- * @see #path
- */
- protected String fullPath;
-
- /**
- * The UI class associated with the node.
- * <p/>
- * This class can be {@code null}, in that case, the {@link
- * NavigationTreeNodeModelBuilder#defaultUIClass} will be used while building
- * the model.
- */
- protected Class<? extends JAXXObject> uIClass;
-
- /**
- * The UI handler class associated with the node.
- * <p/>
- * This class can be {@code null}, in that case, the {@link
- * NavigationTreeNodeModelBuilder#defaultUIHandlerClass} will be used while
- * building the model.
- */
- protected Class<? extends JAXXAction> uIHandlerClass;
-
- /**
- * The context entry definition to retrieve the bean.
- * <p/>
- * <b>Note:</b> If not set - the {@code bean} will be retrieve on a ancestor
- * node.
- */
- protected JAXXContextEntryDef<?> jaxxContextEntryDef;
-
- /**
- * The jxPath to process to obtain real {@code bean} from the data retrieve
- * in the context.
- * <p/>
- * <b>Note:</b> If not set -no jxpath will be apply on the bean from
- * context.
- */
- protected String jaxxContextEntryPath;
-
- /**
- * The bean associated with the node ( the value can be obtain via the
- * method {@link #getBean(JAXXContext)} or directly set via method {@link
- * #setBean(Object)}.
- * <p/>
- * cache of bean associated with bean to improve performance
- */
- protected transient Object bean;
-
- /**
- * The type of the related bean associated with the node.
- * <p/>
- * Note: This type is here to override the NodeRenderer internalClass, since
- * we could need to override this data.
- * <p/>
- * If this property is let to null, then we will use the NodeRenderer one
- */
- protected Class<?> internalClass;
-
- public NavigationTreeNode(String pathSeparator,
- String navigationPath,
- Object jaxxContextEntryDef) {
- this.pathSeparator = pathSeparator;
- path = navigationPath;
- if (jaxxContextEntryDef instanceof JAXXContextEntryDef<?>) {
- this.jaxxContextEntryDef = ((JAXXContextEntryDef<?>) jaxxContextEntryDef);
- } else if (jaxxContextEntryDef instanceof String) {
- jaxxContextEntryPath = (String) jaxxContextEntryDef;
- } else if (jaxxContextEntryDef != null) {
- // wrong context definition type
- throw new IllegalArgumentException(
- "to define a context link, must be a String (jxpath) or a " + JAXXContextEntryDef.class + ", but was " + jaxxContextEntryDef);
- }
- }
-
- public NavigationTreeNode(String pathSeparator,
- String navigationPath,
- JAXXContextEntryDef<?> jaxxContextEntryDef,
- String jaxxContextEntryPath) {
- this.pathSeparator = pathSeparator;
- path = navigationPath;
- this.jaxxContextEntryDef = jaxxContextEntryDef;
- this.jaxxContextEntryPath = jaxxContextEntryPath;
- }
-
- /** @return the text node renderer (store in {@link #userObject} property. */
- @Override
- public NavigationTreeNodeRenderer getRenderer() {
- NavigationTreeNodeRenderer render = null;
- Object o = getUserObject();
- if (o != null && o instanceof NavigationTreeNodeRenderer) {
- render = (NavigationTreeNodeRenderer) o;
- }
- return render;
- }
-
- @Override
- public void setRenderer(NavigationTreeNodeRenderer renderer) {
- // clear all cache
- bean = null;
- setUserObject(renderer);
- }
-
- @Override
- public String getPathSeparator() {
- return pathSeparator;
- }
-
- @Override
- public String getNodePath() {
- return path;
- }
-
- @Override
- public void setNodePath(String navigationPath) {
- path = navigationPath;
- }
-
- @Override
- public Class<? extends JAXXObject> getUIClass() {
- return uIClass;
- }
-
- @Override
- public void setUIClass(Class<? extends JAXXObject> uIClass) {
- this.uIClass = uIClass;
- }
-
- @Override
- public void setInternalClass(Class<?> internalClass) {
- this.internalClass = internalClass;
- }
-
- @Override
- public Class<? extends JAXXAction> getUIHandlerClass() {
- return uIHandlerClass;
- }
-
- @Override
- public void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass) {
- this.uIHandlerClass = uIHandlerClass;
- }
-
- @Override
- public JAXXContextEntryDef<?> getJaxxContextEntryDef() {
- return jaxxContextEntryDef;
- }
-
- @Override
- public void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef) {
- this.jaxxContextEntryDef = jaxxContextEntryDef;
- }
-
- @Override
- public String getJaxxContextEntryPath() {
- return jaxxContextEntryPath;
- }
-
- @Override
- public void setJaxxContextEntryPath(String jaxxContextEntryPath) {
- this.jaxxContextEntryPath = jaxxContextEntryPath;
- }
-
- @Override
- public Class<?> getInternalClass() {
- if (internalClass == null && getRenderer() != null) {
- return getRenderer().getInternalClass();
- }
- return internalClass;
- }
-
- /** @return the fully context path of the node from the root node to this. */
- @Override
- public String getFullPath() {
- if (fullPath == null) {
- StringBuilder sb = new StringBuilder();
- for (TreeNode treeNode : getPath()) {
- NavigationTreeNode myNode = (NavigationTreeNode) treeNode;
- sb.append(pathSeparator).append(myNode.getNodePath());
- }
- fullPath = sb.substring(1);
- }
- return fullPath;
- }
-
- @Override
- public NavigationTreeNode getChildAt(int index) {
- return (NavigationTreeNode) super.getChildAt(index);
- }
-
- @Override
- public NavigationTreeNode getParent() {
- return (NavigationTreeNode) super.getParent();
- }
-
- /**
- * @param path the name of the {@link #path} to be matched in the child of
- * this node.
- * @return the child of this node with given {@link #path} value.
- */
- @Override
- public NavigationTreeNode getChild(String path) {
- Enumeration<? extends NavigationTreeNode> childs = children();
- while (childs.hasMoreElements()) {
- NavigationTreeNode son = childs.nextElement();
- if (path.equals(son.getNodePath())) {
- return son;
- }
- }
- return null;
- }
-
- @Override
- public Object getBean() {
- return bean;
- }
-
- @Override
- public void setBean(Object bean) {
- this.bean = bean;
- }
-
- @Override
- public void reload(JAXXContext context) {
-
- // clear bean cache
- bean = null;
-
- // clear context navigation cache
- fullPath = null;
-
- NavigationTreeNodeRenderer renderer = getRenderer();
- if (renderer == null) {
- // this can't be !
- throw new NullPointerException(
- "could not find the renderer for node " + this);
- }
-
- String s = getFullPath();
- Object b = null;
- try {
- b = getBean(context);
- } finally {
- if (log.isInfoEnabled()) {
- log.info("bean for path [" + s + "] = " + bean);
- }
- }
-
- renderer.reload(b);
- }
-
- /**
- * Obtain the associated bean value from context corresponding to node
- *
- * @param context the context to seek
- * @return the value associated in context with the given context path
- */
- @Override
- public Object getBean(JAXXContext context) {
- if (bean != null) {
- // use cached bean
- return bean;
- }
- Object result;
- if (getJaxxContextEntryDef() != null && jaxxContextEntryPath == null) {
- // the node maps directly a value in context, with no jxpath resolving
- result = getJaxxContextEntryDef().getContextValue(context);
- // save in cache
- setBean(result);
- return result;
- }
- // find the first ancestor node with a context def
- NavigationTreeNode parentNode = getFirstAncestorWithDef();
- if (parentNode == null) {
- log.warn("could not find a ancestor node with a definition of" +
- " a context entry from node (" + this + ")");
- // todo must be an error
- // no parent found
- return null;
- }
- Object parentBean = parentNode.getJaxxContextEntryDef().getContextValue(context);
- if (parentBean == null) {
- // must be an error no bean found
- log.warn("could not find a bean attached in context from context" +
- " entry definition " + parentNode.getJaxxContextEntryDef());
- return null;
- }
- if (parentNode.jaxxContextEntryPath != null) {
- // apply the jxpath on parentBean
- JXPathContext jxcontext = JXPathContext.newContext(parentBean);
- parentBean = jxcontext.getValue(parentNode.jaxxContextEntryPath);
- }
- // save in cache
- parentNode.setBean(parentBean);
- if (parentNode.equals(this)) {
- // current node is the node matching the context entry value and
- // no jxpath is found
- return parentBean;
- }
- if (jaxxContextEntryPath == null) {
- // todo must be an error
- log.warn("must find a jaxxContextEntryPath on node (" + this +
- ")");
- return null;
- }
- String jxpathExpression = computeJXPath(jaxxContextEntryPath,
- parentNode);
- if (jxpathExpression == null) {
- /// todo must be an error
- log.warn("could not build jxpath from node " + parentNode +
- " to " + this);
- // could not retreave the jxpath...
- return null;
- }
- if (jxpathExpression.startsWith("[")) {
- // special case when we want to access a collection
- jxpathExpression = '.' + jxpathExpression;
- }
- if (log.isDebugEnabled()) {
- log.debug("jxpath : " + jxpathExpression);
- }
- JXPathContext jxcontext = JXPathContext.newContext(parentBean);
- result = jxcontext.getValue(jxpathExpression);
- // save in cache
- setBean(result);
- return result;
- }
-
- @Override
- public void insert(NavigationTreeNode child, int index) {
- super.insert(child, index);
- }
-
- @Override
- public void remove(NavigationTreeNode node) {
- super.remove(node);
- }
-
- @Override
- public void setParent(NavigationTreeNode newParent) {
- super.setParent(newParent);
- }
-
- @Override
- public int getIndex(NavigationTreeNode node) {
- return super.getIndex(node);
- }
-
- @Override
- public Enumeration<? extends NavigationTreeNode> children() {
- return super.children();
- }
-
- /**
- * @return the first ancestor with a none null {@link #jaxxContextEntryDef}
- * or <code>null</code> if none find..
- */
- protected NavigationTreeNode getFirstAncestorWithDef() {
- if (jaxxContextEntryDef != null) {
- // find a node with a direct link with the context
- return this;
- }
- // the node is not linked to context
- // seek in his parent
- NavigationTreeNode ancestor = getParent();
- return ancestor == null ? null : ancestor.getFirstAncestorWithDef();
- }
-
- protected String computeJXPath(String expr, NavigationTreeNode parentNode) {
- if (equals(parentNode)) {
- // reach the parent limit node, return the expr computed
- return expr;
- }
- int firstIndex = expr.indexOf("..");
- int lastIndex = expr.lastIndexOf("..");
- if (firstIndex == -1) {
- // this is a error, since current node is not parent limit node,
- // we must find somewhere a way to go up in nodes
- throw new IllegalArgumentException(
- expr + " should contains at least one \"..\"");
- }
- if (firstIndex != 0) {
- // this is a error, the ../ must be at the beginning of the expression
- throw new IllegalArgumentException(
- "\"..\" must be at the beginning but was : " + expr);
- }
- NavigationTreeNode ancestor = getParent();
- if (firstIndex == lastIndex) {
- // found only one go up, so must be substitute by the parent node context
- String newExpr = expr.substring(2);
- //String newExpr = expr.substring(expr.startsWith("../") ? 3 : 2);
- if (getParent().equals(parentNode)) {
- // parent node is the final parent node, so no substitution needed
- return newExpr;
- }
- // ancestor must have a jaxxContextEntryPath
- if (ancestor.jaxxContextEntryPath == null) {
- throw new IllegalArgumentException(
- "with the expression " + expr + ", the ancestor node ("
- + ancestor + ") must have a jaxxContextEntryPath " +
- "definition, but was not ");
- }
- newExpr = ancestor.jaxxContextEntryPath + newExpr;
- return ancestor.computeJXPath(newExpr, parentNode);
- }
- // have more than one go up, so the ancestor node can not have a
- // jaxxContextEntryPath
- if (ancestor.jaxxContextEntryPath != null) {
- throw new IllegalArgumentException(
- "with the expression " + expr + ", the ancestor node can " +
- "not have a jaxxContextEntryPath definition");
- }
- // substitute the last ..[/] and delegate to ancestor
- String newExpr = expr.substring(0, lastIndex - 1) +
- expr.substring(
- lastIndex +
- (expr.charAt(lastIndex + 3) == '/' ? 3 : 2)
- );
- return ancestor.computeJXPath(newExpr, parentNode);
- }
-
- @Override
- public void add(NavigationTreeNode node) {
- super.add(node);
- }
-
-
- @Override
- public NavigationTreeNode[] getPath() {
- TreeNode[] treeNodes = super.getPath();
- NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length];
- System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
- return result;
- }
-
- @Override
- public NavigationTreeNode[] getPathToRoot(NavigationTreeNode aNode, int depth) {
- TreeNode[] treeNodes = super.getPathToRoot(aNode, depth);
- NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length];
- System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
- return result;
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,99 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.tree.DefaultTreeModel;
-import javax.swing.tree.TreeModel;
-import javax.swing.tree.TreeNode;
-
-/**
- * Model of the tree used for a navigation tree.
- * <p/>
- * Il est composé de {@link NavigationTreeNode}
- *
- * @author chemit
- * @since 1.7.2
- */
-public class NavigationTreeNodeModel extends AbstractNavigationModel<NavigationTreeNode> implements TreeModel {
-
- /** Logger */
- private static final Log log =
- LogFactory.getLog(NavigationTreeNodeModel.class);
-
-// private static final long serialVersionUID = 1L;
-
- public NavigationTreeNodeModel(String pathSeparator, JAXXContext context) {
- super(new DefaultTreeModel(null), pathSeparator, context);
- }
-//
-// @Override
-// public NavigationTreeNode getRoot() {
-// return (NavigationTreeNode) delegate.getRoot();
-// }
-
- @Override
- public void setRoot(NavigationTreeNode root) {
- getDelegate().setRoot(root);
- }
-
- public DefaultTreeModel getDelegate() {
- return (DefaultTreeModel) delegate;
- }
-
- @Override
- public NavigationTreeNode[] getPathToRoot(NavigationTreeNode aNode) {
- TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode);
- NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length];
- System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
- return result;
- }
-
- @Override
- public void removeNodeFromParent(NavigationTreeNode node) {
- getDelegate().removeNodeFromParent(node);
- }
-
- @Override
- public void nodeStructureChanged(NavigationTreeNode node) {
- NavigationTreeNode n = node;
- //TC-20091004 never launch a deep reload
- reload(n, true);
- getDelegate().nodeStructureChanged(node);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- }
-
- @Override
- public void nodeChanged(NavigationTreeNode node, boolean deep) {
-
- NavigationTreeNode n = node;
- //TC-20091004 never launch a deep clean, since we do a deep nodeChanged.
- reload(n, deep);
- getDelegate().nodeChanged(node);
- }
-
-
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,90 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXAction;
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * This object is design to build a {@link NavigationTreeNodeModel}.
- *
- * @author chemit
- * @see NavigationModelBuilder
- * @since 17.2
- */
-public class NavigationTreeNodeModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeNode> {
-
- /** Logger */
- static private final Log log =
- LogFactory.getLog(NavigationTreeNodeModelBuilder.class);
-
- public NavigationTreeNodeModelBuilder(
- String pathSeparator,
- JAXXContext context,
- Class<? extends JAXXObject> defaultUIClass,
- Class<? extends JAXXAction> defaultUIHandlerClass) {
- this(defaultUIClass,
- defaultUIHandlerClass,
- new NavigationTreeNodeModel(pathSeparator, context)
- );
- }
-
- @Override
- public NavigationTreeNodeModel getModel() {
- return (NavigationTreeNodeModel) super.getModel();
- }
-
- public NavigationTreeNodeModelBuilder(
- Class<? extends JAXXObject> defaultUIClass,
- Class<? extends JAXXAction> defaultUIHandlerClass,
- NavigationTreeNodeModel model) {
- super(defaultUIClass, defaultUIHandlerClass, model);
- }
-
- @Override
- public NavigationTreeNode createNavigationTreeNode(
- String pathSeparator,
- String contextName,
- JAXXContextEntryDef<?> jaxxContextEntryDef,
- String jaxxContextEntryPath) {
- return new NavigationTreeNode(
- pathSeparator,
- contextName,
- jaxxContextEntryDef,
- jaxxContextEntryPath
- );
- }
-
-// // TODO : to remove
-// /**
-// * @deprecated please use NavigationModel for return type
-// * @return the tree model
-// */
-// @Override
-// @Deprecated
-// public NavigationTreeNodeModel getModel() {
-// return (NavigationTreeNodeModel)super.getModel();
-// }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,65 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import javax.swing.tree.TreeCellRenderer;
-import java.io.Serializable;
-
-/**
- * Text Renderer of a {@link NavigationNode}.
- * <p/>
- * This object will be placed as the {@link NavigationTreeNode#getUserObject()} of
- * nodes.
- * <p/>
- *
- * In that way, we can use the {@link #toString()} value to render the node
- * without writing any {@link TreeCellRenderer}.
- * <p/>
- * To rebuild the renderer text of a node use the method {@link #reload(Object)}
- * with the {@code bean} provides by the model for the node.
- *
- * @author chemit
- * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear soon...
- */
-public interface NavigationTreeNodeRenderer extends Serializable {
-
- /**
- *
- * @return the render value of the node
- */
- @Override
- String toString();
-
- /**
- *
- * Can override the the node internal class for display purpose.
- *
- * @return the type of data to be displayed.
- */
- Class<?> getInternalClass();
-
- /**
- * Reload the render value from the {@code bean} of node.
- *
- * @param bean the bean associated to the node to render
- */
- void reload(Object bean);
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,71 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.decorator.Decorator;
-
-/**
- * Decorator Renderer of a {@link NavigationTreeNode}.
- * <p/>
- * Apply a {@link Decorator} to the {@code bean} associated to the node.
- *
- * @author chemit
- * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear
- * soon...
- */
-public class NavigationTreeNodeRendererDecoratorImpl implements NavigationTreeNodeRenderer {
-
- private static final long serialVersionUID = -1L;
-
- /** Decorator */
- protected final Decorator<?> decorator;
-
- /** internal class of representing data */
- protected final Class<?> internalClass;
-
- /** last renderered value */
- protected String text;
-
- public NavigationTreeNodeRendererDecoratorImpl(Decorator<?> decorator) {
- internalClass = decorator.getInternalClass();
- this.decorator = decorator;
- }
-
- @Override
- public String toString() {
- return text;
- }
-
- @Override
- public void reload(Object bean) {
- try {
- text = decorator.toString(bean);
-
- } catch (Exception e) {
- text = "";
- }
- }
-
- @Override
- public Class<?> getInternalClass() {
- return internalClass;
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,68 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import static org.nuiton.i18n.I18n._;
-
-/**
- * I18n label Renderer of a {@link NavigationTreeNode}.
- *
- * Just apply a i18n translation on the given {@link #libelle}.
- *
- * @author chemit
- * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear soon...
- */
-public class NavigationTreeNodeRendererI18nImpl implements NavigationTreeNodeRenderer {
-
- private static final long serialVersionUID = -1L;
- /**
- * Static i18n label to render
- */
- protected final String libelle;
- /**
- * internal class of representing data
- */
- protected final Class<?> internalClass;
- /**
- * last renderered value
- */
- protected String text;
-
- public NavigationTreeNodeRendererI18nImpl(String libelle) {
- this.libelle = libelle;
- internalClass = String.class;
- }
-
- @Override
- public String toString() {
- return text;
- }
-
- @Override
- public void reload(Object data) {
- text = _(libelle);
- }
-
- @Override
- public Class<?> getInternalClass() {
- return internalClass;
- }
-}
Deleted: 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-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,328 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jdesktop.swingx.tree.TreeModelSupport;
-import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
-import org.jdesktop.swingx.treetable.TreeTableModel;
-
-import javax.swing.tree.TreeNode;
-import javax.swing.tree.TreePath;
-import java.util.List;
-
-/**
- * Model of the tree table used for a navigation tree table.
- * <p/>
- * Il est composé de {@link NavigationTreeNode}
- * <p/>
- * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeNodeModel}
- *
- * @author sletellier
- * @since 2.0.0
- */
-public class NavigationTreeTableModel extends AbstractNavigationModel<NavigationTreeTableNode> implements TreeTableModel {
-
-// static private final long serialVersionUID = 1L;
-
- /** Logger */
- static private final Log log =
- LogFactory.getLog(NavigationTreeTableModel.class);
-
- public static class MyDefaultTreeTableModel extends DefaultTreeTableModel {
-
- public TreeModelSupport getModelSupport() {
- return modelSupport;
- }
- }
-
-// /**
-// * The path separator used to build the {@link NavigationTreeNode#fullPath}.
-// *
-// * @see NavigationTreeNode#getNodePath()
-// * @see NavigationTreeNode#getFullPath()
-// */
-// protected final String pathSeparator;
-//
-// /** Context to retrieve beans */
-// private JAXXContext context;
-
- protected List<String> columnsName;
-
- public NavigationTreeTableModel(String pathSeparator, JAXXContext context, List<String> columnsName) {
- super(new MyDefaultTreeTableModel(), pathSeparator, context);
-// this.pathSeparator = pathSeparator;
-// this.context = context;
- this.columnsName = columnsName;
- }
-
-
- public MyDefaultTreeTableModel getDelegate() {
- return (MyDefaultTreeTableModel) delegate;
- }
-
-// @Override
-// public NavigationTreeTableNode getRoot() {
-// return (NavigationTreeTableNode) getDelegate().getRoot();
-// }
-
- @Override
- public NavigationTreeTableNode[] getPathToRoot(NavigationTreeTableNode aNode) {
- if (aNode == null) {
- return null;
- }
- TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode);
- NavigationTreeTableNode[] result = new NavigationTreeTableNode[treeNodes.length];
- System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
- return result;
-
- }
-
- @Override
- public void setRoot(NavigationTreeTableNode root) {
- getDelegate().setRoot(root);
-// this.root = root;
- getModelSupport().fireNewRoot();
- }
-
- /**
- * Message this to remove node from its parent. This will message
- * nodesWereRemoved to create the appropriate event. This is the preferred
- * way to remove a node as it handles the event creation for you.
- */
- @Override
- public void removeNodeFromParent(NavigationTreeTableNode node) {
- NavigationTreeTableNode parent = node.getParent();
-
- if (parent == null) {
- throw new IllegalArgumentException("node does not have a parent.");
- }
-
- int index = parent.getIndex(node);
- node.removeFromParent();
- getModelSupport().fireChildRemoved(new TreePath(getPathToRoot(parent)),
- index, node);
- }
-
-// @Override
-// public NavigationTreeTableNode findNode(String path) {
-// return findNode(getRoot(), path, (Pattern) null);
-// }
-//
-// @Override
-// public NavigationTreeTableNode findNode(String path, String regex) {
-// return findNode(getRoot(), path, regex);
-// }
-//
-// @Override
-// public NavigationTreeTableNode findNode(String path, Pattern regex) {
-// return findNode(getRoot(), path, regex);
-// }
-//
-// @Override
-// public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
-// String path) {
-// return findNode(root, path, (Pattern) null);
-// }
-//
-// @Override
-// public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
-// String path,
-// String regex) {
-// return findNode(root, path, regex == null ?
-// null : Pattern.compile(regex));
-// }
-//
-// @Override
-// public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
-// String path,
-// Pattern regex) {
-// if (regex != null) {
-// Matcher matcher = regex.matcher(path);
-// if (!matcher.matches() || matcher.groupCount() < 1) {
-// log.warn("no matching regex " + regex + " to " + path);
-// return null;
-// }
-// path = matcher.group(1);
-// if (log.isDebugEnabled()) {
-// log.debug("matching regex " + regex + " : " + path);
-// }
-// }
-// StringTokenizer stk = new StringTokenizer(path, pathSeparator);
-// NavigationTreeTableNode result = root;
-// // pas the first token (matches the root node)
-// if (root.isRoot() && stk.hasMoreTokens()) {
-// String rootPath = stk.nextToken();
-// if (!rootPath.equals(root.getNodePath())) {
-// return null;
-// }
-// }
-// while (stk.hasMoreTokens()) {
-// result = result.getChild(stk.nextToken());
-// }
-// return result;
-// }
-//
-// @Override
-// public JAXXContext getContext() {
-// return context;
-// }
-//
-// @Override
-// public Object getBean(String navigationPath) {
-// Object result;
-// NavigationTreeTableNode node = findNode(navigationPath, (Pattern) null);
-// result = getBean(node);
-// return result;
-// }
-//
-// @Override
-// public Object getBean(NavigationTreeTableNode node) {
-// if (node == null) {
-// return null;
-// //fixme should throw a NPE exception
-// //throw new NullPointerException("node can not be null");
-// }
-// return node.getBean(getContext());
-// }
-
-
- /**
- * Accessor to tree model support.
- *
- * @return tree model support
- */
- protected TreeModelSupport getModelSupport() {
- return getDelegate().getModelSupport();
- }
-
-// @Override
-// public void nodeChanged(NavigationTreeTableNode node) {
-// if (node != null) {
-// NavigationTreeTableNode parent = node.getParent();
-// NavigationTreeTableNode[] treeNodes = getPathToRoot(parent);
-// if (treeNodes != null) {
-// getModelSupport().fireChildChanged(
-// new TreePath(treeNodes), parent.getIndex(node), node);
-// } else {
-// log.error("[Node changed] Path to root is null !");
-// }
-// reload((NavigationTreeTableNode) node, true);
-// } else {
-// log.error("Node is null !");
-// }
-// }
-
- @Override
- public void nodeStructureChanged(NavigationTreeTableNode node) {
- if (node != null) {
- NavigationTreeTableNode parent = node.getParent();
- TreeNode[] treeNodes = getPathToRoot(parent);
- if (treeNodes != null) {
- getModelSupport().fireTreeStructureChanged(new TreePath(treeNodes));
- } else {
- log.error("[Node structure changed] Path to root is null !");
- }
- reload(node, true);
- } else {
- log.error("Node is null !");
- }
- }
-
- @Override
- public void nodeChanged(NavigationTreeTableNode node, boolean deep) {
- if (node != null) {
- NavigationTreeTableNode parent = node.getParent();
- TreeNode[] treeNodes = getPathToRoot(parent);
- if (treeNodes != null) {
- getModelSupport().fireChildChanged(
- new TreePath(treeNodes), parent.getIndex(node), node);
- } else {
- log.error("[Node changed] Path to root is null !");
- }
- reload(node, deep);
- } else {
- log.error("Node is null !");
- }
- }
-//
-// @Override
-// public String getPathSeparator() {
-// return pathSeparator;
-// }
-
- @Override
- public Class<?> getColumnClass(int i) {
- return getDelegate().getColumnClass(i);
- }
-
- @Override
- public int getColumnCount() {
- return columnsName.size();
- }
-
- @Override
- public String getColumnName(int column) {
- return columnsName.get(column);
- }
-
- @Override
- public int getHierarchicalColumn() {
- return getDelegate().getHierarchicalColumn();
- }
-
- @Override
- public Object getValueAt(Object o, int i) {
- return getDelegate().getValueAt(o, i);
- }
-
- @Override
- public boolean isCellEditable(Object o, int i) {
- return getDelegate().isCellEditable(o, i);
- }
-
- @Override
- public void setValueAt(Object o, Object o1, int i) {
- getDelegate().setValueAt(o, o1, i);
- }
-//
-// protected void reload(NavigationTreeTableNode node) {
-// reload(node, false);
-// }
-//
-// protected void reload(NavigationTreeTableNode node, boolean deep) {
-// if (node == null) {
-// return;
-// }
-// node.reload(getContext());
-//
-// if (deep) {
-// Enumeration<?> childs = node.children();
-// while (childs.hasMoreElements()) {
-// NavigationTreeTableNode o = (NavigationTreeTableNode) childs.nextElement();
-// reload(o, true);
-// }
-// }
-// }
-
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,29 +0,0 @@
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXAction;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.context.JAXXContextEntryDef;
-
-public class NavigationTreeTableModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeTableNode> {
-
- public NavigationTreeTableModelBuilder(
- Class<? extends JAXXObject> defaultUIClass,
- Class<? extends JAXXAction> defaultUIHandlerClass,
- NavigationModel<NavigationTreeTableNode> model) {
- super(defaultUIClass, defaultUIHandlerClass, model);
- }
-
- @Override
- public NavigationTreeTableNode createNavigationTreeNode(
- String pathSeparator,
- String contextName,
- JAXXContextEntryDef<?> jaxxContextEntryDef,
- String jaxxContextEntryPath) {
- return new NavigationTreeTableNode(
- pathSeparator,
- contextName,
- jaxxContextEntryDef,
- jaxxContextEntryPath
- );
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,568 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXAction;
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.jxpath.JXPathContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
-
-import javax.swing.tree.TreeNode;
-import java.util.Enumeration;
-
-/**
- * Node of the {@link NavigationTreeTableModel}.
- *
- * @author sletellier
- * @see NavigationTreeNode
- * @since 2.0.0
- */
-public class NavigationTreeTableNode extends DefaultMutableTreeTableNode implements NavigationNode<NavigationTreeTableNode> {
-//public abstract class NavigationTreeTableNode extends NavigationTreeNode implements TreeTableNode, NavigationNode<NavigationTreeTableNode> {
-
- private static final long serialVersionUID = -1L;
-
- /** Logger */
- private static final Log log =
- LogFactory.getLog(NavigationTreeTableNode.class);
-
- /**
- * The path separator used to build the {@link #fullPath}.
- *
- * @see #path
- * @see #fullPath
- */
- protected final String pathSeparator;
-
- /**
- * The node path.
- * <p/>
- * Used to build the {@link #fullPath} which gives a unique identifier of
- * the node.
- *
- * @see #pathSeparator
- * @see #fullPath
- */
- protected String path;
-
- /**
- * The full path for the node from the rood node.
- * <p/>
- * This path is build by appending nodes {@link #path} from the root node to
- * this node, between each path we introduce the {@link #pathSeparator}.
- * <p/>
- * Exemple :
- * <pre>
- * root
- * $root
- * `-- child1
- * `-- child2
- * </pre>
- * will given {@code $root/child1/child2}.
- *
- * @see #pathSeparator
- * @see #path
- */
- protected String fullPath;
-
- /**
- * The UI class associated with the node.
- * <p/>
- * This class can be {@code null}, in that case, the {@link
- * NavigationTreeNodeModelBuilder#defaultUIClass} will be used while building
- * the model.
- */
- protected Class<? extends JAXXObject> uIClass;
-
- /**
- * The UI handler class associated with the node.
- * <p/>
- * This class can be {@code null}, in that case, the {@link
- * NavigationTreeNodeModelBuilder#defaultUIHandlerClass} will be used while
- * building the model.
- */
- protected Class<? extends JAXXAction> uIHandlerClass;
-
- /**
- * The context entry definition to retrieve the bean.
- * <p/>
- * <b>Note:</b> If not set - the {@code bean} will be retrieve on a ancestor
- * node.
- */
- protected JAXXContextEntryDef<?> jaxxContextEntryDef;
-
- /**
- * The jxPath to process to obtain real {@code bean} from the data retrieve
- * in the context.
- * <p/>
- * <b>Note:</b> If not set -no jxpath will be apply on the bean from
- * context.
- */
- protected String jaxxContextEntryPath;
-
- /**
- * The bean associated with the node ( the value can be obtain via the
- * method {@link #getBean(JAXXContext)} or directly set via method {@link
- * #setBean(Object)}.
- * <p/>
- * cache of bean associated with bean to improve performance
- */
- protected transient Object bean;
-
- /**
- * The type of the related bean associated with the node.
- * <p/>
- * Note: This type is here to override the NodeRenderer internalClass, since
- * we could need to override this data.
- * <p/>
- * If this property is let to null, then we will use the NodeRenderer one
- */
- protected Class<?> internalClass;
-
-// public NavigationTreeTableNode(String pathSeparator,
-// String navigationPath,
-// Object jaxxContextEntryDef) {
-// super(pathSeparator, navigationPath, jaxxContextEntryDef);
-// }
-//
-// public NavigationTreeTableNode(String pathSeparator,
-// String navigationPath,
-// JAXXContextEntryDef<?> jaxxContextEntryDef,
-// String jaxxContextEntryPath) {
-// super(pathSeparator,
-// navigationPath,
-// jaxxContextEntryDef,
-// jaxxContextEntryPath
-// );
-// }
-
- public NavigationTreeTableNode(String pathSeparator,
- String navigationPath,
- Object jaxxContextEntryDef) {
- this.pathSeparator = pathSeparator;
- path = navigationPath;
- if (jaxxContextEntryDef instanceof JAXXContextEntryDef<?>) {
- this.jaxxContextEntryDef = ((JAXXContextEntryDef<?>) jaxxContextEntryDef);
- } else if (jaxxContextEntryDef instanceof String) {
- jaxxContextEntryPath = (String) jaxxContextEntryDef;
- } else if (jaxxContextEntryDef != null) {
- // wrong context definition type
- throw new IllegalArgumentException(
- "to define a context link, must be a String (jxpath) or a " + JAXXContextEntryDef.class + ", but was " + jaxxContextEntryDef);
- }
- }
-
- public NavigationTreeTableNode(String pathSeparator,
- String navigationPath,
- JAXXContextEntryDef<?> jaxxContextEntryDef,
- String jaxxContextEntryPath) {
- this.pathSeparator = pathSeparator;
- path = navigationPath;
- this.jaxxContextEntryDef = jaxxContextEntryDef;
- this.jaxxContextEntryPath = jaxxContextEntryPath;
- }
-
- /** @return the text node renderer (store in {@link #userObject} property. */
- @Override
- public NavigationTreeNodeRenderer getRenderer() {
- NavigationTreeNodeRenderer render = null;
- Object o = getUserObject();
- if (o != null && o instanceof NavigationTreeNodeRenderer) {
- render = (NavigationTreeNodeRenderer) o;
- }
- return render;
- }
-
- @Override
- public void setRenderer(NavigationTreeNodeRenderer renderer) {
- // clear all cache
- bean = null;
- setUserObject(renderer);
- }
-
- @Override
- public String getPathSeparator() {
- return pathSeparator;
- }
-
- @Override
- public String getNodePath() {
- return path;
- }
-
- @Override
- public void setNodePath(String navigationPath) {
- path = navigationPath;
- }
-
- @Override
- public Class<? extends JAXXObject> getUIClass() {
- return uIClass;
- }
-
- @Override
- public void setUIClass(Class<? extends JAXXObject> uIClass) {
- this.uIClass = uIClass;
- }
-
- @Override
- public void setInternalClass(Class<?> internalClass) {
- this.internalClass = internalClass;
- }
-
- @Override
- public Class<? extends JAXXAction> getUIHandlerClass() {
- return uIHandlerClass;
- }
-
- @Override
- public void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass) {
- this.uIHandlerClass = uIHandlerClass;
- }
-
- @Override
- public JAXXContextEntryDef<?> getJaxxContextEntryDef() {
- return jaxxContextEntryDef;
- }
-
- @Override
- public void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef) {
- this.jaxxContextEntryDef = jaxxContextEntryDef;
- }
-
- @Override
- public String getJaxxContextEntryPath() {
- return jaxxContextEntryPath;
- }
-
- @Override
- public void setJaxxContextEntryPath(String jaxxContextEntryPath) {
- this.jaxxContextEntryPath = jaxxContextEntryPath;
- }
-
- @Override
- public Class<?> getInternalClass() {
- if (internalClass == null && getRenderer() != null) {
- return getRenderer().getInternalClass();
- }
- return internalClass;
- }
-
- /** @return the fully context path of the node from the root node to this. */
- @Override
- public String getFullPath() {
- if (fullPath == null) {
- StringBuilder sb = new StringBuilder();
- for (TreeNode treeNode : getPath()) {
- NavigationTreeTableNode myNode = (NavigationTreeTableNode) treeNode;
- sb.append(pathSeparator).append(myNode.getNodePath());
- }
- fullPath = sb.substring(1);
- }
- return fullPath;
- }
-
- /**
- * @return the first ancestor with a none null {@link #jaxxContextEntryDef}
- * or <code>null</code> if none find..
- */
- protected NavigationTreeTableNode getFirstAncestorWithDef() {
- if (jaxxContextEntryDef != null) {
- // find a node with a direct link with the context
- return this;
- }
- // the node is not linked to context
- // seek in his parent
- NavigationTreeTableNode ancestor = getParent();
- return ancestor == null ? null : ancestor.getFirstAncestorWithDef();
- }
-
- protected String computeJXPath(String expr, NavigationTreeTableNode parentNode) {
- if (equals(parentNode)) {
- // reach the parent limit node, return the expr computed
- return expr;
- }
- int firstIndex = expr.indexOf("..");
- int lastIndex = expr.lastIndexOf("..");
- if (firstIndex == -1) {
- // this is a error, since current node is not parent limit node,
- // we must find somewhere a way to go up in nodes
- throw new IllegalArgumentException(
- expr + " should contains at least one \"..\"");
- }
- if (firstIndex != 0) {
- // this is a error, the ../ must be at the beginning of the expression
- throw new IllegalArgumentException(
- "\"..\" must be at the beginning but was : " + expr);
- }
- NavigationTreeTableNode ancestor = getParent();
- if (firstIndex == lastIndex) {
- // found only one go up, so must be substitute by the parent node context
- String newExpr = expr.substring(2);
- //String newExpr = expr.substring(expr.startsWith("../") ? 3 : 2);
- if (getParent().equals(parentNode)) {
- // parent node is the final parent node, so no substitution needed
- return newExpr;
- }
- // ancestor must have a jaxxContextEntryPath
- if (ancestor.jaxxContextEntryPath == null) {
- throw new IllegalArgumentException(
- "with the expression " + expr + ", the ancestor node ("
- + ancestor + ") must have a jaxxContextEntryPath " +
- "definition, but was not ");
- }
- newExpr = ancestor.jaxxContextEntryPath + newExpr;
- return ancestor.computeJXPath(newExpr, parentNode);
- }
- // have more than one go up, so the ancestor node can not have a
- // jaxxContextEntryPath
- if (ancestor.jaxxContextEntryPath != null) {
- throw new IllegalArgumentException(
- "with the expression " + expr + ", the ancestor node can " +
- "not have a jaxxContextEntryPath definition");
- }
- // substitute the last ..[/] and delegate to ancestor
- String newExpr = expr.substring(0, lastIndex - 1) +
- expr.substring(
- lastIndex +
- (expr.charAt(lastIndex + 3) == '/' ? 3 : 2)
- );
- return ancestor.computeJXPath(newExpr, parentNode);
- }
-
-
- @Override
- public Object getBean() {
- return bean;
- }
-
- @Override
- public void setBean(Object bean) {
- this.bean = bean;
- }
-
- @Override
- public void reload(JAXXContext context) {
-
- // clear bean cache
- bean = null;
-
- // clear context navigation cache
- fullPath = null;
-
- NavigationTreeNodeRenderer renderer = getRenderer();
- if (renderer == null) {
- // this can't be !
- throw new NullPointerException(
- "could not find the renderer for node " + this);
- }
-
- String s = getFullPath();
- Object b = null;
- try {
- b = getBean(context);
- } finally {
- if (log.isInfoEnabled()) {
- log.info("bean for path [" + s + "] = " + bean);
- }
- }
-
- renderer.reload(b);
- }
-
- /**
- * Obtain the associated bean value from context corresponding to node
- *
- * @param context the context to seek
- * @return the value associated in context with the given context path
- */
- @Override
- public Object getBean(JAXXContext context) {
- if (bean != null) {
- // use cached bean
- return bean;
- }
- Object result;
- if (getJaxxContextEntryDef() != null && jaxxContextEntryPath == null) {
- // the node maps directly a value in context, with no jxpath resolving
- result = getJaxxContextEntryDef().getContextValue(context);
- // save in cache
- setBean(result);
- return result;
- }
- // find the first ancestor node with a context def
- NavigationTreeTableNode parentNode = getFirstAncestorWithDef();
- if (parentNode == null) {
- log.warn("could not find a ancestor node with a definition of" +
- " a context entry from node (" + this + ")");
- // todo must be an error
- // no parent found
- return null;
- }
- Object parentBean = parentNode.getJaxxContextEntryDef().getContextValue(context);
- if (parentBean == null) {
- // must be an error no bean found
- log.warn("could not find a bean attached in context from context" +
- " entry definition " + parentNode.getJaxxContextEntryDef());
- return null;
- }
- if (parentNode.jaxxContextEntryPath != null) {
- // apply the jxpath on parentBean
- JXPathContext jxcontext = JXPathContext.newContext(parentBean);
- parentBean = jxcontext.getValue(parentNode.jaxxContextEntryPath);
- }
- // save in cache
- parentNode.setBean(parentBean);
- if (parentNode.equals(this)) {
- // current node is the node matching the context entry value and
- // no jxpath is found
- return parentBean;
- }
- if (jaxxContextEntryPath == null) {
- // todo must be an error
- log.warn("must find a jaxxContextEntryPath on node (" + this +
- ")");
- return null;
- }
- String jxpathExpression = computeJXPath(jaxxContextEntryPath,
- parentNode);
- if (jxpathExpression == null) {
- /// todo must be an error
- log.warn("could not build jxpath from node " + parentNode +
- " to " + this);
- // could not retreave the jxpath...
- return null;
- }
- if (jxpathExpression.startsWith("[")) {
- // special case when we want to access a collection
- jxpathExpression = '.' + jxpathExpression;
- }
- if (log.isDebugEnabled()) {
- log.debug("jxpath : " + jxpathExpression);
- }
- JXPathContext jxcontext = JXPathContext.newContext(parentBean);
- result = jxcontext.getValue(jxpathExpression);
- // save in cache
- setBean(result);
- return result;
- }
-
-
- @Override
- public NavigationTreeTableNode getChildAt(int index) {
- return (NavigationTreeTableNode) super.getChildAt(index);
- }
-
- @Override
- public NavigationTreeTableNode getParent() {
- return (NavigationTreeTableNode) super.getParent();
- }
-
- @Override
- public NavigationTreeTableNode getChild(String path) {
- Enumeration<?> childs = children();
- while (childs.hasMoreElements()) {
- NavigationTreeTableNode son =
- (NavigationTreeTableNode) childs.nextElement();
- if (path.equals(son.getNodePath())) {
- return son;
- }
- }
- return null;
- }
-
- @Override
- public Enumeration<? extends NavigationTreeTableNode> children() {
- return (Enumeration<? extends NavigationTreeTableNode>) super.children();
- }
-
- @Override
- public void insert(NavigationTreeTableNode child, int index) {
- super.insert(child, index);
- }
-
- @Override
- public void remove(NavigationTreeTableNode node) {
- super.remove(node);
- }
-
- @Override
- public void setParent(NavigationTreeTableNode newParent) {
- super.setParent(newParent);
- }
-
- @Override
- public int getIndex(NavigationTreeTableNode node) {
- return super.getIndex(node);
- }
-
- @Override
- public void add(NavigationTreeTableNode node) {
- super.add(node);
- }
-
- @Override
- public NavigationTreeTableNode[] getPath() {
- return getPathToRoot(this, 0);
- }
-
- @Override
- public NavigationTreeTableNode[] getPathToRoot(NavigationTreeTableNode aNode, int depth) {
- NavigationTreeTableNode[] retNodes;
-
- /* Check for null, in case someone passed in a null node, or
- they passed in an element that isn't rooted at root. */
- if (aNode == null) {
- if (depth == 0) {
- return null;
- } else {
- retNodes = new NavigationTreeTableNode[depth];
- }
- } else {
- depth++;
- retNodes = getPathToRoot(aNode.getParent(), depth);
- retNodes[retNodes.length - depth] = aNode;
- }
- return retNodes;
- }
-
- @Override
- public boolean isRoot() {
- return getParent() == null;
- }
-
- //
-// @Override
-// public abstract Object getValueAt(int column);
-//
-// @Override
-// public abstract int getColumnCount();
-//
-// @Override
-// public abstract boolean isEditable(int column);
-//
-// @Override
-// public abstract void setValueAt(Object aValue, int column);
-}
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,273 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation.handler;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXInitialContext;
+import jaxx.runtime.swing.navigation.NavigationContentUI;
+import jaxx.runtime.swing.navigation.NavigationContextHelper;
+import jaxx.runtime.swing.navigation.NavigationMultiContentUI;
+import jaxx.runtime.swing.navigation.NavigationNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.tree.DefaultTreeSelectionModel;
+import javax.swing.tree.TreePath;
+import java.awt.*;
+import java.util.Arrays;
+
+/**
+ * The handler of a navigation tree.
+ * <p/>
+ * This is also the selection model to use, since we must check before moving
+ * from a node we can not just listen selection model changed, we must control
+ * it.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 1.7.2
+ */
+public abstract class AbstractNavigationHandler<E extends NavigationNode<E>> extends DefaultTreeSelectionModel implements NavigationHandler<E> {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(AbstractNavigationHandler.class);
+
+ /** UI which contains navigation tree */
+ protected JAXXContext context;
+
+ /** UI Instanciation strategy */
+ protected Strategy strategy;
+
+ /**
+ * JAXXContext access helper.
+ *
+ * @since 1.7.2
+ */
+ protected NavigationContextHelper<E> contextHelper;
+
+ protected AbstractNavigationHandler(String contextPrefix,
+ JAXXObject context,
+ Strategy strategy) {
+ contextHelper = new NavigationContextHelper<E>(contextPrefix);
+ this.context = context;
+ this.strategy = strategy;
+ addTreeSelectionListener(this);
+ }
+
+ @Override
+ public void valueChanged(TreeSelectionEvent event) {
+ if (log.isDebugEnabled()) {
+ log.debug("Value changed for path : " + event.getPath());
+ log.debug("Old lead selection path : " +
+ event.getOldLeadSelectionPath());
+ }
+ if (event.getOldLeadSelectionPath() != null &&
+ event.getOldLeadSelectionPath().equals(event.getPath())) {
+ // do not treate this if no path changed
+ return;
+ }
+ E node = (E) event.getPath().getLastPathComponent();
+ selectNodeUI(node);
+ }
+
+ @Override
+ public JAXXContext getContext() {
+ return context;
+ }
+
+ @Override
+ public NavigationContextHelper<E> getContextHelper() {
+ return contextHelper;
+ }
+
+ @Override
+ public void setSelectionPath(TreePath path) {
+ if (path.equals(getSelectionPath())) {
+ // stay on same node, can skip
+ if (log.isDebugEnabled()) {
+ log.debug("skip stay on path " + path);
+ }
+ return;
+ }
+ Component component = getCurrentUI();
+
+ try {
+ if (!closeUI(component)) {
+ if (log.isDebugEnabled()) {
+ log.debug("changing node canceled!");
+ }
+ // can not changed current node
+ return;
+ }
+ if (component instanceof NavigationContentUI<?>) {
+ ((NavigationContentUI<E>) component).closeUI((E) path.getLastPathComponent());
+ }
+ } catch (Exception ex) {
+ treateError(ex);
+ return;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("will select path " + path);
+ }
+ // ok can safely select the new path
+ super.setSelectionPath(path);
+ }
+
+ @Override
+ public void setSelectionPaths(TreePath[] paths) {
+ //FIXME-TC20100315 this can not work...
+ // can't test like this paths as Array...
+ if (Arrays.equals(paths, getSelectionPaths())) {
+ // stay on same node, can skip
+ if (log.isDebugEnabled()) {
+ log.debug("skip stay on path " + Arrays.toString(paths));
+ }
+ return;
+ }
+ Component component = getCurrentUI();
+
+ try {
+ if (!closeUI(component)) {
+ if (log.isDebugEnabled()) {
+ log.debug("changing node canceled!");
+ }
+ // can not changed current node
+ return;
+ }
+ if (component instanceof NavigationMultiContentUI<?>) {
+ if (paths.length == 1) {
+ NavigationContextHelper<E> helper = getContextHelper();
+ ((NavigationMultiContentUI<E>) component).closeUI(helper.getSelectedNodes(getContext()));
+ }
+ }
+ } catch (Exception ex) {
+ treateError(ex);
+ return;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("will select " + paths.length + " paths");
+ }
+ // ok can safely select the new path
+ super.setSelectionPaths(paths);
+ }
+
+ protected void selectNodeUI(E node) {
+
+ try {
+
+ String path = node.getFullPath();
+
+ if (log.isTraceEnabled()) {
+ log.trace(path);
+ }
+
+ Component newUI = getUI(node);
+
+ // now, we are free to open the ui associated with the selected node in navigation
+
+ // get the bean associated with the node
+ Object data = getNavigationTreeModel().getBean(path);
+
+ // save it in context (must be done before init ui)
+ addSelectedBeanInContext(node, data);
+
+ if (newUI == null) {
+
+ // a new ui instance is required
+ newUI = createUI(node);
+ }
+
+ JAXXContext ctxt = getContext();
+ NavigationContextHelper<E> helper = getContextHelper();
+
+ // save in context current node context path
+ helper.setSelectedPath(ctxt, node.getFullPath());
+
+ // save in context current node
+ helper.setSelectedNode(ctxt, node);
+
+ // save in context current ui
+// helper.setSelectedUI(ctxt, newUI);
+
+ // really open the ui associated with the selected node
+ // init ui before to be visible
+ if (newUI instanceof NavigationContentUI<?>) {
+ ((NavigationContentUI<E>) newUI).openUI(node);
+ }
+
+ // set ui in content
+ openUI(newUI, node);
+
+ } catch (Exception e) {
+ // remove data from context
+
+ // if any error, go back to previvous node
+ treateError(e);
+ }
+ }
+
+ /**
+ * Prepare le context a utiliser pour initialiser une nouvelle ui.
+ *
+ * @param node le noeud associé à l'ui à créer
+ * @return le context à utiliser pour instancier l'ui
+ * @throws Exception if any
+ */
+ protected JAXXContext createUIContext(E node) throws Exception {
+
+ if (node.getUIHandlerClass() == null) {
+ if (log.isWarnEnabled()) {
+ log.warn("no action associated with ui " + node.getUIClass());
+ }
+ // no action associated, just
+ return getContext();
+ }
+
+ JAXXAction action = node.getUIHandlerClass().newInstance();
+
+ // init context with
+ JAXXInitialContext uiContext = action.init(getContext());
+ return uiContext;
+ }
+
+ protected void addSelectedBeanInContext(E node, Object data) {
+
+ if (log.isDebugEnabled()) {
+ log.debug("find data for contextPath <" + node.getFullPath() + "> : " + (data == null ? null : data.getClass()));
+ }
+ JAXXContext ctxt = getContext();
+ NavigationContextHelper<E> helper = getContextHelper();
+
+ // remove previous selected bean
+ //TODO-TC-20091004 should have an automatic clean context method while
+ helper.setSelectedBean(ctxt, null);
+
+ if (data != null) {
+
+ helper.setSelectedBean(ctxt, data);
+ }
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/AbstractNavigationHandler.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,109 @@
+package jaxx.runtime.swing.navigation.handler;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.swing.navigation.NavigationContextHelper;
+import jaxx.runtime.swing.navigation.NavigationModel;
+import jaxx.runtime.swing.navigation.NavigationNode;
+
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.TreePath;
+import javax.swing.tree.TreeSelectionModel;
+import java.awt.*;
+import java.io.Serializable;
+
+public interface NavigationHandler<E extends NavigationNode<E>> extends Cloneable, Serializable, TreeSelectionModel, TreeSelectionListener {
+
+ /**
+ * Strategy of instanciation of ui.
+ * <p/>
+ * For a given {@code node}, the method {@link #getId(NavigationNode)}
+ * returns the id of ui to use.
+ */
+ enum Strategy {
+
+ /** instanciate a ui for a node */
+ PER_NODE {
+
+ @Override
+ public String getId(NavigationNode<?> node) {
+ return node.getFullPath();
+ }
+ },
+ /**
+ * instanciate only one a ui for a type,nodes will share the
+ * instanciation
+ */
+ PER_UI_TYPE {
+
+ @Override
+ public String getId(NavigationNode<?> node) {
+ return node.getUIClass().getName();
+ }
+ };
+
+ public abstract String getId(NavigationNode<?> node);
+ }
+
+ JAXXContext getContext();
+
+ /** @return le modèle de navigation associé */
+ NavigationModel<E> getNavigationTreeModel();
+
+ /**
+ * @return le composent actuellement visible associé au noeud courant ou au
+ * noeud précédent lors d'un changement de noeud.
+ */
+ Component getCurrentUI();
+
+ /**
+ * @param node le noeud associé à l'ui à retrouver
+ * @return l'ui associé au novueau noeud sélectionné
+ */
+ Component getUI(E node);
+
+ /**
+ * @param component le composent actuellement visible
+ * @return <code>true</code> si le composent a bien été fermé,
+ * <code>false</code> sinon
+ * @throws Exception if any
+ */
+ boolean closeUI(Component component) throws Exception;
+
+ /**
+ * Instancie une nouvelle ui associé à un noeud de l'arbre de navigation
+ *
+ * @param node le noeud associé à l'ui à créer
+ * @return la nouvelle ui associée au noeud
+ * @throws Exception if any
+ */
+ Component createUI(E node) throws Exception;
+
+ /**
+ * Ouvre l'ui associée au noeud sélectionné dans l'arbre de navigation.
+ *
+ * @param newUI l'ui associé au noeud sélectionné à ouvrir
+ * @param node le node de l'ui a ouvrir
+ * @throws Exception if any
+ */
+ void openUI(Component newUI, E node) throws Exception;
+
+ /**
+ * Traitement des exceptions.
+ *
+ * @param e l'erreur recontrée (ou null si pas d"erreur)
+ */
+ void treateError(Exception e);
+
+
+ @Override
+ void valueChanged(TreeSelectionEvent event);
+
+ NavigationContextHelper<E> getContextHelper();
+
+ @Override
+ void setSelectionPath(TreePath path);
+
+ @Override
+ void setSelectionPaths(TreePath[] paths);
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationHandler.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationMultiTreeHandler.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationMultiTreeHandler.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationMultiTreeHandler.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,189 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+
+package jaxx.runtime.swing.navigation.handler;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.swing.navigation.NavigationContextHelper;
+import jaxx.runtime.swing.navigation.NavigationMultiContentUI;
+import jaxx.runtime.swing.navigation.NavigationNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.tree.TreePath;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * The handler of a navigation tree.
+ * <p/>
+ * This is also the selection model to use, since we must check before moving
+ * from nodes we can not just listen selection model changed, we must control
+ * it.
+ * <p/>
+ * This one is used to enable multi selection
+ *
+ * @author sletellier
+ * @since 2.0.1
+ */
+public abstract class NavigationMultiTreeHandler<E extends NavigationNode<E>> extends AbstractNavigationHandler<E> {
+
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(NavigationMultiTreeHandler.class);
+
+
+ public NavigationMultiTreeHandler(String contextPrefix,
+ JAXXObject context,
+ Strategy strategy) {
+ super(contextPrefix, context, strategy);
+
+ // Enable multi selection
+ setSelectionMode(DISCONTIGUOUS_TREE_SELECTION);
+ }
+
+ @Override
+ public void valueChanged(TreeSelectionEvent event) {
+ TreePath[] paths = event.getPaths();
+
+ // TODO : verifier que la selection n'est pas la même
+ List<E> nodes = new ArrayList<E>();
+ if (paths == null) {
+ selectNodeUI(new ArrayList<E>());
+ return;
+ }
+ for (TreePath path : paths) {
+ E node = (E) path.getLastPathComponent();
+ nodes.add(node);
+ if (log.isDebugEnabled()) {
+ log.debug("Adding path : " + path);
+ log.debug("As node : " + node.getFullPath());
+ }
+ }
+ selectNodeUI(nodes);
+ }
+
+ /**
+ * Ouvre l'ui associée aux noeuds sélectionnés dans l'arbre de navigation.
+ *
+ * @param newUI l'ui associé au noeud sélectionné à ouvrir
+ * @param nodes les node de l'ui a ouvrir
+ * @throws Exception if any
+ */
+ protected abstract void openUI(Component newUI, List<E> nodes)
+ throws Exception;
+
+ /**
+ * Instancie une nouvelle ui associé à des noeuds de l'arbre de navigation
+ *
+ * @param nodes les noeuds associés à l'ui à créer
+ * @return la nouvelle ui associée au noeud
+ * @throws Exception if any
+ */
+ protected abstract Component createUI(List<E> nodes)
+ throws Exception;
+
+ /**
+ * @param nodes les noeuds associés à l'ui à retrouver
+ * @return l'ui associés au nouveau noeud sélectionné
+ */
+ protected abstract Component getUI(List<E> nodes);
+
+ protected void selectNodeUI(List<E> nodes) {
+ log.info("select nodes " + nodes);
+
+ try {
+// List<String> paths = new ArrayList<String>();
+ List<Object> beans = new ArrayList<Object>();
+ for (E node : nodes) {
+
+ String path = node.getFullPath();
+// paths.add(path);
+
+ if (log.isTraceEnabled()) {
+ log.trace(path);
+ }
+ // now, we are free to open the ui associated with the selected
+ // node in navigation
+
+ // get the bean associated with the node
+ beans.add(getNavigationTreeModel().getBean(path));
+ }
+
+ Component newUI = getUI(nodes);
+
+ // save it in context (must be done before init ui)
+ JAXXContext ctxt = getContext();
+ NavigationContextHelper<E> helper = getContextHelper();
+
+ // remove previous selected bean
+ //TODO-TC-20091004 should have an automatic clean context method
+ //TODO-TC-20091004 while
+ helper.setSelectedBean(ctxt, null);
+
+// if (beans != null) {
+ helper.setSelectedBeans(ctxt, beans);
+// }
+
+ if (newUI == null) {
+
+ // a new ui instance is required
+ newUI = createUI(nodes);
+ }
+
+ // save in context current node context path
+ helper.setSelectedPaths(ctxt, getPaths(nodes));
+
+ // save in context current node
+ helper.setSelectedNodes(ctxt, nodes);
+
+ // save in context current ui
+// helper.setSelectedUI(ctxt, newUI);
+
+ // really open the ui associated with the selected node
+ // init ui before to be visible
+ if (newUI instanceof NavigationMultiContentUI<?>) {
+ ((NavigationMultiContentUI<E>) newUI).openUI(nodes);
+ }
+
+ // set ui in content
+ openUI(newUI, nodes);
+
+ } catch (Exception e) {
+ // remove data from context
+
+ // if any error, go back to previvous node
+ treateError(e);
+ }
+ }
+
+ protected List<String> getPaths(List<E> nodes) {
+ List<String> result = new ArrayList<String>();
+ for (E node : nodes) {
+ result.add(node.getFullPath());
+ }
+ return result;
+ }
+
+}
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationOneClicSelectionHandler.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationOneClicSelectionHandler.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationOneClicSelectionHandler.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,67 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+
+package jaxx.runtime.swing.navigation.handler;
+
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.swing.navigation.NavigationNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.TreePath;
+import java.util.Arrays;
+
+/**
+ * The handler of a navigation tree.
+ * <p/>
+ * This is also the selection model to use, since we must check before moving
+ * from nodes we can not just listen selection model changed, we must control
+ * it.
+ * <p/>
+ * This one is used to enable one clic multi selection
+ *
+ * @author sletellier
+ * @since 2.0.1
+ */
+public abstract class NavigationOneClicSelectionHandler<E extends NavigationNode<E>> extends NavigationMultiTreeHandler<E> {
+
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(NavigationOneClicSelectionHandler.class);
+
+
+ public NavigationOneClicSelectionHandler(String contextPrefix,
+ JAXXObject context,
+ Strategy strategy) {
+ super(contextPrefix, context, strategy);
+ }
+
+ @Override
+ public void setSelectionPath(TreePath path) {
+ TreePath[] treePaths = getSelectionPaths();
+ if (treePaths == null || !Arrays.asList(treePaths).contains(path)) {
+ addSelectionPath(path);
+ } else {
+ removeSelectionPath(path);
+ }
+ }
+
+}
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,132 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation.handler;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.swing.CardLayout2;
+import jaxx.runtime.swing.navigation.NavigationNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.*;
+import java.awt.*;
+import java.lang.reflect.Constructor;
+
+/**
+ * Simple {@link AbstractNavigationHandler} implementation with a {@link
+ * CardLayout2} to manage components to associated with tree's nodes.
+ * <p/>
+ * For each node, the ui associated has a constraints in a cardlayout which is
+ * the node context path.
+ * <p/>
+ * A single container managed by the cardlayout is used to display the
+ * components associated with tree's nodes.
+ *
+ * @author chemit
+ */
+public abstract class NavigationTreeHandlerWithCardLayout<E extends NavigationNode<E>> extends AbstractNavigationHandler<E> {
+
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(NavigationTreeHandlerWithCardLayout.class);
+
+ /**
+ * All components associated with a tree's node is displayed in a single
+ * container.
+ *
+ * @return the containter of components
+ */
+ protected abstract JPanel getContentContainer();
+
+ /**
+ * the cardlayout managing components associated with tree node. The
+ * constraints of each component is the node contextPath.
+ *
+ * @return the layout used to display components associated with tree's
+ * nodes.
+ */
+ protected abstract CardLayout2 getContentLayout();
+
+ public NavigationTreeHandlerWithCardLayout(String contextPrefix,
+ JAXXObject context,
+ Strategy strategy) {
+ super(contextPrefix, context, strategy);
+ if (getContentContainer() == null) {
+ throw new IllegalArgumentException(
+ "could not have a null 'contentContainer' in ui " + context);
+ }
+ if (getContentLayout() == null) {
+ throw new IllegalArgumentException(
+ "could not have a null 'contentLayout' in ui " + context);
+ }
+ }
+
+ @Override
+ public Component getCurrentUI() {
+ CardLayout2 layout = getContentLayout();
+ JPanel container = getContentContainer();
+ return layout.getVisibleComponent(container);
+ }
+
+ @Override
+ public Component getUI(E node) {
+ CardLayout2 layout = getContentLayout();
+ JPanel container = getContentContainer();
+ String constraints = strategy.getId(node);
+ return layout.contains(constraints) ?
+ layout.getComponent(container, constraints) : null;
+ }
+
+ @Override
+ public void openUI(Component newUI, E node) throws Exception {
+
+ CardLayout2 layout = getContentLayout();
+ JPanel container = getContentContainer();
+ // switch layout
+ String constraints = strategy.getId(node);
+ layout.show(container, constraints);
+ }
+
+ @Override
+ public boolean closeUI(Component component) throws Exception {
+ // by default, we says that component was succesfull closed
+ return true;
+ }
+
+ @Override
+ public Component createUI(E node) throws Exception {
+
+ JAXXContext uiContext = createUIContext(node);
+
+ Constructor<? extends JAXXObject> constructor =
+ node.getUIClass().getConstructor(JAXXContext.class);
+ JAXXObject newUI = constructor.newInstance(uiContext);
+
+ if (log.isDebugEnabled()) {
+ log.debug("instanciate new ui " + newUI);
+ }
+ String constraints = strategy.getId(node);
+ getContentContainer().add((Component) newUI, constraints);
+ return (Component) newUI;
+ }
+}
+
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/handler/NavigationTreeHandlerWithCardLayout.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/package.html
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/package.html 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/package.html 2010-03-26 18:05:31 UTC (rev 1814)
@@ -1,12 +1,12 @@
<html>
- <body>
- <h1>JAXX - tree utilities</h1>
+<body>
+<h1>JAXX - tree utilities</h1>
- This package contains all the classes of the navigation tree framework.
+This package contains all the classes of the navigation tree framework.
- <p>
- Replace the previous framework from package
- <code>jaxx.runtime.swing.navigation</code>
- </p>
- </body>
-</html>
\ No newline at end of file
+<p>
+ Replace the previous framework from package
+ <code>jaxx.runtime.swing.navigation</code>
+</p>
+</body>
+</html>
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,40 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation.tree;
+
+import jaxx.runtime.swing.navigation.AbstractNavigationHelper;
+import jaxx.runtime.swing.navigation.NavigationContextHelper;
+
+/**
+ * Helper object associated to a given navigation tree system.
+ * <p/>
+ * To helper is context safe (base on a {@link NavigationContextHelper}.
+ *
+ * @author chemit
+ * @see NavigationTreeModel
+ * @since 1.7.2
+ */
+public abstract class NavigationTreeHelper extends AbstractNavigationHelper<NavigationTreeNode> {
+
+ protected NavigationTreeHelper(String contextPrefix) {
+ super(contextPrefix);
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeHelper.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java (from rev 1813, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,93 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation.tree;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.swing.navigation.AbstractNavigationModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreeNode;
+
+/**
+ * Model of the tree used for a navigation tree.
+ * <p/>
+ * Il est composé de {@link NavigationTreeNode}
+ *
+ * @author chemit
+ * @since 1.7.2
+ */
+public class NavigationTreeModel extends AbstractNavigationModel<NavigationTreeNode> implements TreeModel {
+
+ /** Logger */
+ private static final Log log =
+ LogFactory.getLog(NavigationTreeModel.class);
+
+ public NavigationTreeModel(String pathSeparator, JAXXContext context) {
+ super(new DefaultTreeModel(null), pathSeparator, context);
+ }
+
+ @Override
+ public void setRoot(NavigationTreeNode root) {
+ getDelegate().setRoot(root);
+ }
+
+ public DefaultTreeModel getDelegate() {
+ return (DefaultTreeModel) super.getDelegate();
+ }
+
+ @Override
+ public NavigationTreeNode[] getPathToRoot(NavigationTreeNode aNode) {
+ TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode);
+ NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length];
+ System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
+ return result;
+ }
+
+ @Override
+ public void removeNodeFromParent(NavigationTreeNode node) {
+ getDelegate().removeNodeFromParent(node);
+ }
+
+ @Override
+ public void nodeStructureChanged(NavigationTreeNode node) {
+ NavigationTreeNode n = node;
+ //TC-20091004 never launch a deep reload
+ reload(n, true);
+ getDelegate().nodeStructureChanged(node);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ }
+
+ @Override
+ public void nodeChanged(NavigationTreeNode node, boolean deep) {
+
+ NavigationTreeNode n = node;
+ //TC-20091004 never launch a deep clean, since we do a deep nodeChanged.
+ reload(n, deep);
+ getDelegate().nodeChanged(node);
+ }
+
+
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModel.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,81 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation.tree;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXContextEntryDef;
+import jaxx.runtime.swing.navigation.AbstractNavigationModelBuilder;
+import jaxx.runtime.swing.navigation.NavigationModelBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This object is design to build a {@link NavigationTreeModel}.
+ *
+ * @author chemit
+ * @see NavigationModelBuilder
+ * @since 17.2
+ */
+public class NavigationTreeModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeNode> {
+
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(NavigationTreeModelBuilder.class);
+
+ public NavigationTreeModelBuilder(
+ String pathSeparator,
+ JAXXContext context,
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass) {
+ this(defaultUIClass,
+ defaultUIHandlerClass,
+ new NavigationTreeModel(pathSeparator, context)
+ );
+ }
+
+ public NavigationTreeModelBuilder(
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass,
+ NavigationTreeModel model) {
+ super(defaultUIClass, defaultUIHandlerClass, model);
+ }
+
+ @Override
+ public NavigationTreeNode createNavigationNode(
+ String pathSeparator,
+ String contextName,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
+ return new NavigationTreeNode(
+ pathSeparator,
+ contextName,
+ jaxxContextEntryDef,
+ jaxxContextEntryPath
+ );
+ }
+
+ @Override
+ public NavigationTreeModel getModel() {
+ return (NavigationTreeModel) super.getModel();
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeModelBuilder.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,556 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation.tree;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXContextEntryDef;
+import jaxx.runtime.swing.navigation.NavigationNode;
+import jaxx.runtime.swing.navigation.NavigationNodeRenderer;
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreeNode;
+import java.util.Enumeration;
+
+/**
+ * Node of the {@link NavigationTreeModel}.
+ * <p/>
+ * Each node is associated with : <ul> <li> a {@code bean} coming from a {@link
+ * JAXXContext} </li> <li> a {@code uiClass} to build the associated ui </li>
+ * </ul>
+ * <p/>
+ * To retrieve the bean from the context, there is a huge logic in the method
+ * {@link #getBean(JAXXContext)}.
+ * <p/>
+ * In few words, if the {@link #jaxxContextEntryDef} is defined, it means that
+ * the object is taken from the {@code context}.
+ * <p/>
+ * Otherwise, find the first ancestor with an context entry and retrieve from
+ * here the bean.
+ * <p/>
+ * Then go down to the initial node by applying the jxpath expressions {@link
+ * #jaxxContextEntryPath} of each node on road back.
+ * <p/>
+ * <p/>
+ * To identify easly a node, each node has a {@link #path} and a {@link
+ * #fullPath} (full path from root node).
+ * <p/>
+ * <p/>
+ * To display the node we use a {@link NavigationNodeRenderer}
+ * which is in fact the {@link #userObject}, the object can be synch with the
+ * bean via the {@link NavigationNodeRenderer#reload(Object)}
+ * method.
+ *
+ * @author chemit
+ * @see NavigationTreeModel
+ * @see NavigationNodeRenderer
+ * @since 1.7.2
+ */
+public class NavigationTreeNode extends DefaultMutableTreeNode implements NavigationNode<NavigationTreeNode> {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger */
+ static private final Log log = LogFactory.getLog(NavigationTreeNode.class);
+
+ /**
+ * The path separator used to build the {@link #fullPath}.
+ *
+ * @see #path
+ * @see #fullPath
+ */
+ protected final String pathSeparator;
+
+ /**
+ * The node path.
+ * <p/>
+ * Used to build the {@link #fullPath} which gives a unique identifier of
+ * the node.
+ *
+ * @see #pathSeparator
+ * @see #fullPath
+ */
+ protected String path;
+
+ /**
+ * The full path for the node from the rood node.
+ * <p/>
+ * This path is build by appending nodes {@link #path} from the root node to
+ * this node, between each path we introduce the {@link #pathSeparator}.
+ * <p/>
+ * Exemple :
+ * <pre>
+ * root
+ * $root
+ * `-- child1
+ * `-- child2
+ * </pre>
+ * will given {@code $root/child1/child2}.
+ *
+ * @see #pathSeparator
+ * @see #path
+ */
+ protected String fullPath;
+
+ /**
+ * The UI class associated with the node.
+ * <p/>
+ * This class can be {@code null}, in that case, the {@link
+ * NavigationTreeModelBuilder#defaultUIClass} will be used while building
+ * the model.
+ */
+ protected Class<? extends JAXXObject> uIClass;
+
+ /**
+ * The UI handler class associated with the node.
+ * <p/>
+ * This class can be {@code null}, in that case, the {@link
+ * NavigationTreeModelBuilder#defaultUIHandlerClass} will be used while
+ * building the model.
+ */
+ protected Class<? extends JAXXAction> uIHandlerClass;
+
+ /**
+ * The context entry definition to retrieve the bean.
+ * <p/>
+ * <b>Note:</b> If not set - the {@code bean} will be retrieve on a ancestor
+ * node.
+ */
+ protected JAXXContextEntryDef<?> jaxxContextEntryDef;
+
+ /**
+ * The jxPath to process to obtain real {@code bean} from the data retrieve
+ * in the context.
+ * <p/>
+ * <b>Note:</b> If not set -no jxpath will be apply on the bean from
+ * context.
+ */
+ protected String jaxxContextEntryPath;
+
+ /**
+ * The bean associated with the node ( the value can be obtain via the
+ * method {@link #getBean(JAXXContext)} or directly set via method {@link
+ * #setBean(Object)}.
+ * <p/>
+ * cache of bean associated with bean to improve performance
+ */
+ protected transient Object bean;
+
+ /**
+ * The type of the related bean associated with the node.
+ * <p/>
+ * Note: This type is here to override the NodeRenderer internalClass, since
+ * we could need to override this data.
+ * <p/>
+ * If this property is let to null, then we will use the NodeRenderer one
+ */
+ protected Class<?> internalClass;
+
+ public NavigationTreeNode(String pathSeparator,
+ String navigationPath,
+ Object jaxxContextEntryDef) {
+ this.pathSeparator = pathSeparator;
+ path = navigationPath;
+ if (jaxxContextEntryDef instanceof JAXXContextEntryDef<?>) {
+ this.jaxxContextEntryDef =
+ (JAXXContextEntryDef<?>) jaxxContextEntryDef;
+ } else if (jaxxContextEntryDef instanceof String) {
+ jaxxContextEntryPath = (String) jaxxContextEntryDef;
+ } else if (jaxxContextEntryDef != null) {
+ // wrong context definition type
+ throw new IllegalArgumentException(
+ "to define a context link, must be a String (jxpath) or" +
+ " a " + JAXXContextEntryDef.class + ", but was " +
+ jaxxContextEntryDef);
+ }
+ }
+
+ public NavigationTreeNode(String pathSeparator,
+ String navigationPath,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
+ this.pathSeparator = pathSeparator;
+ path = navigationPath;
+ this.jaxxContextEntryDef = jaxxContextEntryDef;
+ this.jaxxContextEntryPath = jaxxContextEntryPath;
+ }
+
+ /** @return the text node renderer (store in {@link #userObject} property. */
+ @Override
+ public NavigationNodeRenderer getRenderer() {
+ NavigationNodeRenderer render = null;
+ Object o = getUserObject();
+ if (o != null && o instanceof NavigationNodeRenderer) {
+ render = (NavigationNodeRenderer) o;
+ }
+ return render;
+ }
+
+ @Override
+ public void setRenderer(NavigationNodeRenderer renderer) {
+ // clear all cache
+ bean = null;
+ setUserObject(renderer);
+ }
+
+ @Override
+ public String getPathSeparator() {
+ return pathSeparator;
+ }
+
+ @Override
+ public String getNodePath() {
+ return path;
+ }
+
+ @Override
+ public void setNodePath(String navigationPath) {
+ path = navigationPath;
+ }
+
+ @Override
+ public Class<? extends JAXXObject> getUIClass() {
+ return uIClass;
+ }
+
+ @Override
+ public void setUIClass(Class<? extends JAXXObject> uIClass) {
+ this.uIClass = uIClass;
+ }
+
+ @Override
+ public void setInternalClass(Class<?> internalClass) {
+ this.internalClass = internalClass;
+ }
+
+ @Override
+ public Class<? extends JAXXAction> getUIHandlerClass() {
+ return uIHandlerClass;
+ }
+
+ @Override
+ public void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass) {
+ this.uIHandlerClass = uIHandlerClass;
+ }
+
+ @Override
+ public JAXXContextEntryDef<?> getJaxxContextEntryDef() {
+ return jaxxContextEntryDef;
+ }
+
+ @Override
+ public void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef) {
+ this.jaxxContextEntryDef = jaxxContextEntryDef;
+ }
+
+ @Override
+ public String getJaxxContextEntryPath() {
+ return jaxxContextEntryPath;
+ }
+
+ @Override
+ public void setJaxxContextEntryPath(String jaxxContextEntryPath) {
+ this.jaxxContextEntryPath = jaxxContextEntryPath;
+ }
+
+ @Override
+ public Class<?> getInternalClass() {
+ if (internalClass == null && getRenderer() != null) {
+ return getRenderer().getInternalClass();
+ }
+ return internalClass;
+ }
+
+ /** @return the fully context path of the node from the root node to this. */
+ @Override
+ public String getFullPath() {
+ if (fullPath == null) {
+ StringBuilder sb = new StringBuilder();
+ for (TreeNode treeNode : getPath()) {
+ NavigationTreeNode myNode = (NavigationTreeNode) treeNode;
+ sb.append(pathSeparator).append(myNode.getNodePath());
+ }
+ fullPath = sb.substring(1);
+ }
+ return fullPath;
+ }
+
+ @Override
+ public NavigationTreeNode getChildAt(int index) {
+ return (NavigationTreeNode) super.getChildAt(index);
+ }
+
+ @Override
+ public NavigationTreeNode getParent() {
+ return (NavigationTreeNode) super.getParent();
+ }
+
+ /**
+ * @param path the name of the {@link #path} to be matched in the child of
+ * this node.
+ * @return the child of this node with given {@link #path} value.
+ */
+ @Override
+ public NavigationTreeNode getChild(String path) {
+ Enumeration<? extends NavigationTreeNode> childs = children();
+ while (childs.hasMoreElements()) {
+ NavigationTreeNode son = childs.nextElement();
+ if (path.equals(son.getNodePath())) {
+ return son;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Object getBean() {
+ return bean;
+ }
+
+ @Override
+ public void setBean(Object bean) {
+ this.bean = bean;
+ }
+
+ @Override
+ public void reload(JAXXContext context) {
+
+ // clear bean cache
+ bean = null;
+
+ // clear context navigation cache
+ fullPath = null;
+
+ NavigationNodeRenderer renderer = getRenderer();
+ if (renderer == null) {
+ // this can't be !
+ throw new NullPointerException(
+ "could not find the renderer for node " + this);
+ }
+
+ String s = getFullPath();
+ Object b = null;
+ try {
+ b = getBean(context);
+ } finally {
+ if (log.isInfoEnabled()) {
+ log.info("bean for path [" + s + "] = " + bean);
+ }
+ }
+
+ renderer.reload(b);
+ }
+
+ /**
+ * Obtain the associated bean value from context corresponding to node
+ *
+ * @param context the context to seek
+ * @return the value associated in context with the given context path
+ */
+ @Override
+ public Object getBean(JAXXContext context) {
+ if (bean != null) {
+ // use cached bean
+ return bean;
+ }
+ Object result;
+ if (getJaxxContextEntryDef() != null && jaxxContextEntryPath == null) {
+ // the node maps directly a value in context, with no jxpath resolving
+ result = getJaxxContextEntryDef().getContextValue(context);
+ // save in cache
+ setBean(result);
+ return result;
+ }
+ // find the first ancestor node with a context def
+ NavigationTreeNode parentNode = getFirstAncestorWithDef();
+ if (parentNode == null) {
+ log.warn("could not find a ancestor node with a definition of" +
+ " a context entry from node (" + this + ")");
+ // todo must be an error
+ // no parent found
+ return null;
+ }
+ Object parentBean = parentNode.getJaxxContextEntryDef().getContextValue(context);
+ if (parentBean == null) {
+ // must be an error no bean found
+ log.warn("could not find a bean attached in context from context" +
+ " entry definition " + parentNode.getJaxxContextEntryDef());
+ return null;
+ }
+ if (parentNode.jaxxContextEntryPath != null) {
+ // apply the jxpath on parentBean
+ JXPathContext jxcontext = JXPathContext.newContext(parentBean);
+ parentBean = jxcontext.getValue(parentNode.jaxxContextEntryPath);
+ }
+ // save in cache
+ parentNode.setBean(parentBean);
+ if (parentNode.equals(this)) {
+ // current node is the node matching the context entry value and
+ // no jxpath is found
+ return parentBean;
+ }
+ if (jaxxContextEntryPath == null) {
+ // todo must be an error
+ log.warn("must find a jaxxContextEntryPath on node (" + this +
+ ")");
+ return null;
+ }
+ String jxpathExpression = computeJXPath(jaxxContextEntryPath,
+ parentNode);
+ if (jxpathExpression == null) {
+ /// todo must be an error
+ log.warn("could not build jxpath from node " + parentNode +
+ " to " + this);
+ // could not retreave the jxpath...
+ return null;
+ }
+ if (jxpathExpression.startsWith("[")) {
+ // special case when we want to access a collection
+ jxpathExpression = '.' + jxpathExpression;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("jxpath : " + jxpathExpression);
+ }
+ JXPathContext jxcontext = JXPathContext.newContext(parentBean);
+ result = jxcontext.getValue(jxpathExpression);
+ // save in cache
+ setBean(result);
+ return result;
+ }
+
+ @Override
+ public void insert(NavigationTreeNode child, int index) {
+ super.insert(child, index);
+ }
+
+ @Override
+ public void remove(NavigationTreeNode node) {
+ super.remove(node);
+ }
+
+ @Override
+ public void setParent(NavigationTreeNode newParent) {
+ super.setParent(newParent);
+ }
+
+ @Override
+ public int getIndex(NavigationTreeNode node) {
+ return super.getIndex(node);
+ }
+
+ @Override
+ public Enumeration<? extends NavigationTreeNode> children() {
+ return super.children();
+ }
+
+ @Override
+ public void add(NavigationTreeNode node) {
+ super.add(node);
+ }
+
+ @Override
+ public NavigationTreeNode[] getPath() {
+ TreeNode[] treeNodes = super.getPath();
+ NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length];
+ System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
+ return result;
+ }
+
+ @Override
+ public NavigationTreeNode[] getPathToRoot(NavigationTreeNode aNode, int depth) {
+ TreeNode[] treeNodes = super.getPathToRoot(aNode, depth);
+ NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length];
+ System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
+ return result;
+ }
+
+ /**
+ * @return the first ancestor with a none null {@link #jaxxContextEntryDef}
+ * or <code>null</code> if none find..
+ */
+ protected NavigationTreeNode getFirstAncestorWithDef() {
+ if (jaxxContextEntryDef != null) {
+ // find a node with a direct link with the context
+ return this;
+ }
+ // the node is not linked to context
+ // seek in his parent
+ NavigationTreeNode ancestor = getParent();
+ return ancestor == null ? null : ancestor.getFirstAncestorWithDef();
+ }
+
+ protected String computeJXPath(String expr, NavigationTreeNode parentNode) {
+ if (equals(parentNode)) {
+ // reach the parent limit node, return the expr computed
+ return expr;
+ }
+ int firstIndex = expr.indexOf("..");
+ int lastIndex = expr.lastIndexOf("..");
+ if (firstIndex == -1) {
+ // this is a error, since current node is not parent limit node,
+ // we must find somewhere a way to go up in nodes
+ throw new IllegalArgumentException(
+ expr + " should contains at least one \"..\"");
+ }
+ if (firstIndex != 0) {
+ // this is a error, the ../ must be at the beginning of the expression
+ throw new IllegalArgumentException(
+ "\"..\" must be at the beginning but was : " + expr);
+ }
+ NavigationTreeNode ancestor = getParent();
+ if (firstIndex == lastIndex) {
+ // found only one go up, so must be substitute by the parent node context
+ String newExpr = expr.substring(2);
+ //String newExpr = expr.substring(expr.startsWith("../") ? 3 : 2);
+ if (getParent().equals(parentNode)) {
+ // parent node is the final parent node, so no substitution needed
+ return newExpr;
+ }
+ // ancestor must have a jaxxContextEntryPath
+ if (ancestor.jaxxContextEntryPath == null) {
+ throw new IllegalArgumentException(
+ "with the expression " + expr + ", the ancestor node ("
+ + ancestor + ") must have a jaxxContextEntryPath " +
+ "definition, but was not ");
+ }
+ newExpr = ancestor.jaxxContextEntryPath + newExpr;
+ return ancestor.computeJXPath(newExpr, parentNode);
+ }
+ // have more than one go up, so the ancestor node can not have a
+ // jaxxContextEntryPath
+ if (ancestor.jaxxContextEntryPath != null) {
+ throw new IllegalArgumentException(
+ "with the expression " + expr + ", the ancestor node can " +
+ "not have a jaxxContextEntryPath definition");
+ }
+ // substitute the last ..[/] and delegate to ancestor
+ String newExpr = expr.substring(0, lastIndex - 1) +
+ expr.substring(
+ lastIndex +
+ (expr.charAt(lastIndex + 3) == '/' ? 3 : 2)
+ );
+ return ancestor.computeJXPath(newExpr, parentNode);
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/NavigationTreeNode.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,41 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation.treetable;
+
+import jaxx.runtime.swing.navigation.AbstractNavigationHelper;
+import jaxx.runtime.swing.navigation.NavigationContextHelper;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModel;
+
+/**
+ * Helper object associated to a given navigation tree table system.
+ * <p/>
+ * To helper is context safe (base on a {@link NavigationContextHelper}.
+ *
+ * @author chemit
+ * @see NavigationTreeModel
+ * @since 1.7.2
+ */
+public abstract class NavigationTreeTableHelper extends AbstractNavigationHelper<NavigationTreeTableNode> {
+
+ protected NavigationTreeTableHelper(String contextPrefix) {
+ super(contextPrefix);
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableHelper.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java (from rev 1813, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModel.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,186 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation.treetable;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.swing.navigation.AbstractNavigationModel;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModel;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdesktop.swingx.tree.TreeModelSupport;
+import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
+import org.jdesktop.swingx.treetable.TreeTableModel;
+
+import javax.swing.tree.TreeNode;
+import javax.swing.tree.TreePath;
+import java.util.List;
+
+/**
+ * Model of the tree table used for a navigation tree table.
+ * <p/>
+ * Il est composé de {@link NavigationTreeNode}
+ * <p/>
+ * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeModel}
+ *
+ * @author sletellier
+ * @since 2.0.0
+ */
+public class NavigationTreeTableModel extends AbstractNavigationModel<NavigationTreeTableNode> implements TreeTableModel {
+
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(NavigationTreeTableModel.class);
+
+ public static class MyDefaultTreeTableModel extends DefaultTreeTableModel {
+
+ public TreeModelSupport getModelSupport() {
+ return modelSupport;
+ }
+ }
+
+ protected List<String> columnsName;
+
+ public NavigationTreeTableModel(String pathSeparator, JAXXContext context, List<String> columnsName) {
+ super(new MyDefaultTreeTableModel(), pathSeparator, context);
+ this.columnsName = columnsName;
+ }
+
+
+ public MyDefaultTreeTableModel getDelegate() {
+ return (MyDefaultTreeTableModel) delegate;
+ }
+
+ @Override
+ public NavigationTreeTableNode[] getPathToRoot(NavigationTreeTableNode aNode) {
+ if (aNode == null) {
+ return null;
+ }
+ TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode);
+ NavigationTreeTableNode[] result = new NavigationTreeTableNode[treeNodes.length];
+ System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
+ return result;
+
+ }
+
+ @Override
+ public void setRoot(NavigationTreeTableNode root) {
+ getDelegate().setRoot(root);
+ getModelSupport().fireNewRoot();
+ }
+
+ /**
+ * Message this to remove node from its parent. This will message
+ * nodesWereRemoved to create the appropriate event. This is the preferred
+ * way to remove a node as it handles the event creation for you.
+ */
+ @Override
+ public void removeNodeFromParent(NavigationTreeTableNode node) {
+ NavigationTreeTableNode parent = node.getParent();
+
+ if (parent == null) {
+ throw new IllegalArgumentException("node does not have a parent.");
+ }
+
+ int index = parent.getIndex(node);
+ node.removeFromParent();
+ getModelSupport().fireChildRemoved(new TreePath(getPathToRoot(parent)),
+ index, node);
+ }
+
+ /**
+ * Accessor to tree model support.
+ *
+ * @return tree model support
+ */
+ protected TreeModelSupport getModelSupport() {
+ return getDelegate().getModelSupport();
+ }
+
+ @Override
+ public void nodeStructureChanged(NavigationTreeTableNode node) {
+ if (node != null) {
+ NavigationTreeTableNode parent = node.getParent();
+ TreeNode[] treeNodes = getPathToRoot(parent);
+ if (treeNodes != null) {
+ getModelSupport().fireTreeStructureChanged(new TreePath(treeNodes));
+ } else {
+ log.error("[Node structure changed] Path to root is null !");
+ }
+ reload(node, true);
+ } else {
+ log.error("Node is null !");
+ }
+ }
+
+ @Override
+ public void nodeChanged(NavigationTreeTableNode node, boolean deep) {
+ if (node != null) {
+ NavigationTreeTableNode parent = node.getParent();
+ TreeNode[] treeNodes = getPathToRoot(parent);
+ if (treeNodes != null) {
+ getModelSupport().fireChildChanged(
+ new TreePath(treeNodes), parent.getIndex(node), node);
+ } else {
+ log.error("[Node changed] Path to root is null !");
+ }
+ reload(node, deep);
+ } else {
+ log.error("Node is null !");
+ }
+ }
+
+ @Override
+ public Class<?> getColumnClass(int i) {
+ return getDelegate().getColumnClass(i);
+ }
+
+ @Override
+ public int getColumnCount() {
+ return columnsName.size();
+ }
+
+ @Override
+ public String getColumnName(int column) {
+ return columnsName.get(column);
+ }
+
+ @Override
+ public int getHierarchicalColumn() {
+ return getDelegate().getHierarchicalColumn();
+ }
+
+ @Override
+ public Object getValueAt(Object o, int i) {
+ return getDelegate().getValueAt(o, i);
+ }
+
+ @Override
+ public boolean isCellEditable(Object o, int i) {
+ return getDelegate().isCellEditable(o, i);
+ }
+
+ @Override
+ public void setValueAt(Object o, Object o1, int i) {
+ getDelegate().setValueAt(o, o1, i);
+ }
+
+}
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java (from rev 1812, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,51 @@
+package jaxx.runtime.swing.navigation.treetable;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXContextEntryDef;
+import jaxx.runtime.swing.navigation.AbstractNavigationModelBuilder;
+
+import java.util.List;
+
+public class NavigationTreeTableModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeTableNode> {
+
+
+ public NavigationTreeTableModelBuilder(
+ String pathSeparator,
+ JAXXContext context,
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass,
+ List<String> columnsName) {
+ this(defaultUIClass,
+ defaultUIHandlerClass,
+ new NavigationTreeTableModel(pathSeparator, context, columnsName)
+ );
+ }
+
+ public NavigationTreeTableModelBuilder(
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass,
+ NavigationTreeTableModel model) {
+ super(defaultUIClass, defaultUIHandlerClass, model);
+ }
+
+ @Override
+ public NavigationTreeTableNode createNavigationNode(
+ String pathSeparator,
+ String contextName,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
+ return new NavigationTreeTableNode(
+ pathSeparator,
+ contextName,
+ jaxxContextEntryDef,
+ jaxxContextEntryPath
+ );
+ }
+
+ @Override
+ public NavigationTreeTableModel getModel() {
+ return (NavigationTreeTableModel) super.getModel();
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableModelBuilder.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableNode.java (from rev 1810, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableNode.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/NavigationTreeTableNode.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -0,0 +1,552 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation.treetable;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXContextEntryDef;
+import jaxx.runtime.swing.navigation.NavigationNode;
+import jaxx.runtime.swing.navigation.NavigationNodeRenderer;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
+
+import javax.swing.tree.TreeNode;
+import java.util.Enumeration;
+
+/**
+ * Node of the {@link NavigationTreeTableModel}.
+ *
+ * @author sletellier
+ * @see NavigationTreeNode
+ * @since 2.0.0
+ */
+public class NavigationTreeTableNode extends DefaultMutableTreeTableNode implements NavigationNode<NavigationTreeTableNode> {
+
+ private static final long serialVersionUID = -1L;
+
+ /** Logger */
+ private static final Log log =
+ LogFactory.getLog(NavigationTreeTableNode.class);
+
+ /**
+ * The path separator used to build the {@link #fullPath}.
+ *
+ * @see #path
+ * @see #fullPath
+ */
+ protected final String pathSeparator;
+
+ /**
+ * The node path.
+ * <p/>
+ * Used to build the {@link #fullPath} which gives a unique identifier of
+ * the node.
+ *
+ * @see #pathSeparator
+ * @see #fullPath
+ */
+ protected String path;
+
+ /**
+ * The full path for the node from the rood node.
+ * <p/>
+ * This path is build by appending nodes {@link #path} from the root node to
+ * this node, between each path we introduce the {@link #pathSeparator}.
+ * <p/>
+ * Exemple :
+ * <pre>
+ * root
+ * $root
+ * `-- child1
+ * `-- child2
+ * </pre>
+ * will given {@code $root/child1/child2}.
+ *
+ * @see #pathSeparator
+ * @see #path
+ */
+ protected String fullPath;
+
+ /**
+ * The UI class associated with the node.
+ * <p/>
+ * This class can be {@code null}, in that case, the {@link
+ * NavigationTreeModelBuilder#defaultUIClass} will be used while building
+ * the model.
+ */
+ protected Class<? extends JAXXObject> uIClass;
+
+ /**
+ * The UI handler class associated with the node.
+ * <p/>
+ * This class can be {@code null}, in that case, the {@link
+ * NavigationTreeModelBuilder#defaultUIHandlerClass} will be used while
+ * building the model.
+ */
+ protected Class<? extends JAXXAction> uIHandlerClass;
+
+ /**
+ * The context entry definition to retrieve the bean.
+ * <p/>
+ * <b>Note:</b> If not set - the {@code bean} will be retrieve on a ancestor
+ * node.
+ */
+ protected JAXXContextEntryDef<?> jaxxContextEntryDef;
+
+ /**
+ * The jxPath to process to obtain real {@code bean} from the data retrieve
+ * in the context.
+ * <p/>
+ * <b>Note:</b> If not set -no jxpath will be apply on the bean from
+ * context.
+ */
+ protected String jaxxContextEntryPath;
+
+ /**
+ * The bean associated with the node ( the value can be obtain via the
+ * method {@link #getBean(JAXXContext)} or directly set via method {@link
+ * #setBean(Object)}.
+ * <p/>
+ * cache of bean associated with bean to improve performance
+ */
+ protected transient Object bean;
+
+ /**
+ * The type of the related bean associated with the node.
+ * <p/>
+ * Note: This type is here to override the NodeRenderer internalClass, since
+ * we could need to override this data.
+ * <p/>
+ * If this property is let to null, then we will use the NodeRenderer one
+ */
+ protected Class<?> internalClass;
+
+ public NavigationTreeTableNode(String pathSeparator,
+ String navigationPath,
+ Object jaxxContextEntryDef) {
+ this.pathSeparator = pathSeparator;
+ path = navigationPath;
+ if (jaxxContextEntryDef instanceof JAXXContextEntryDef<?>) {
+ this.jaxxContextEntryDef =
+ (JAXXContextEntryDef<?>) jaxxContextEntryDef;
+ } else if (jaxxContextEntryDef instanceof String) {
+ jaxxContextEntryPath = (String) jaxxContextEntryDef;
+ } else if (jaxxContextEntryDef != null) {
+ // wrong context definition type
+ throw new IllegalArgumentException(
+ "to define a context link, must be a String (jxpath) or" +
+ " a " + JAXXContextEntryDef.class + ", but was " +
+ jaxxContextEntryDef);
+ }
+ }
+
+ public NavigationTreeTableNode(String pathSeparator,
+ String navigationPath,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
+ this.pathSeparator = pathSeparator;
+ path = navigationPath;
+ this.jaxxContextEntryDef = jaxxContextEntryDef;
+ this.jaxxContextEntryPath = jaxxContextEntryPath;
+ }
+
+ /** @return the text node renderer (store in {@link #userObject} property. */
+ @Override
+ public NavigationNodeRenderer getRenderer() {
+ NavigationNodeRenderer render = null;
+ Object o = getUserObject();
+ if (o != null && o instanceof NavigationNodeRenderer) {
+ render = (NavigationNodeRenderer) o;
+ }
+ return render;
+ }
+
+ @Override
+ public void setRenderer(NavigationNodeRenderer renderer) {
+ // clear all cache
+ bean = null;
+ setUserObject(renderer);
+ }
+
+ @Override
+ public String getPathSeparator() {
+ return pathSeparator;
+ }
+
+ @Override
+ public String getNodePath() {
+ return path;
+ }
+
+ @Override
+ public void setNodePath(String navigationPath) {
+ path = navigationPath;
+ }
+
+ @Override
+ public Class<? extends JAXXObject> getUIClass() {
+ return uIClass;
+ }
+
+ @Override
+ public void setUIClass(Class<? extends JAXXObject> uIClass) {
+ this.uIClass = uIClass;
+ }
+
+ @Override
+ public void setInternalClass(Class<?> internalClass) {
+ this.internalClass = internalClass;
+ }
+
+ @Override
+ public Class<? extends JAXXAction> getUIHandlerClass() {
+ return uIHandlerClass;
+ }
+
+ @Override
+ public void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass) {
+ this.uIHandlerClass = uIHandlerClass;
+ }
+
+ @Override
+ public JAXXContextEntryDef<?> getJaxxContextEntryDef() {
+ return jaxxContextEntryDef;
+ }
+
+ @Override
+ public void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef) {
+ this.jaxxContextEntryDef = jaxxContextEntryDef;
+ }
+
+ @Override
+ public String getJaxxContextEntryPath() {
+ return jaxxContextEntryPath;
+ }
+
+ @Override
+ public void setJaxxContextEntryPath(String jaxxContextEntryPath) {
+ this.jaxxContextEntryPath = jaxxContextEntryPath;
+ }
+
+ @Override
+ public Class<?> getInternalClass() {
+ if (internalClass == null && getRenderer() != null) {
+ return getRenderer().getInternalClass();
+ }
+ return internalClass;
+ }
+
+ /** @return the fully context path of the node from the root node to this. */
+ @Override
+ public String getFullPath() {
+ if (fullPath == null) {
+ StringBuilder sb = new StringBuilder();
+ for (TreeNode treeNode : getPath()) {
+ NavigationTreeTableNode myNode =
+ (NavigationTreeTableNode) treeNode;
+ sb.append(pathSeparator).append(myNode.getNodePath());
+ }
+ fullPath = sb.substring(1);
+ }
+ return fullPath;
+ }
+
+ /**
+ * @return the first ancestor with a none null {@link #jaxxContextEntryDef}
+ * or <code>null</code> if none find..
+ */
+ protected NavigationTreeTableNode getFirstAncestorWithDef() {
+ if (jaxxContextEntryDef != null) {
+ // find a node with a direct link with the context
+ return this;
+ }
+ // the node is not linked to context
+ // seek in his parent
+ NavigationTreeTableNode ancestor = getParent();
+ return ancestor == null ? null : ancestor.getFirstAncestorWithDef();
+ }
+
+ protected String computeJXPath(String expr,
+ NavigationTreeTableNode parentNode) {
+ if (equals(parentNode)) {
+ // reach the parent limit node, return the expr computed
+ return expr;
+ }
+ int firstIndex = expr.indexOf("..");
+ int lastIndex = expr.lastIndexOf("..");
+ if (firstIndex == -1) {
+ // this is a error, since current node is not parent limit node,
+ // we must find somewhere a way to go up in nodes
+ throw new IllegalArgumentException(
+ expr + " should contains at least one \"..\"");
+ }
+ if (firstIndex != 0) {
+ // this is a error, the ../ must be at the beginning of the
+ // expression
+ throw new IllegalArgumentException(
+ "\"..\" must be at the beginning but was : " + expr);
+ }
+ NavigationTreeTableNode ancestor = getParent();
+ if (firstIndex == lastIndex) {
+ // found only one go up, so must be substitute by the parent node
+ // context
+ String newExpr = expr.substring(2);
+ //String newExpr = expr.substring(expr.startsWith("../") ? 3 : 2);
+ if (getParent().equals(parentNode)) {
+ // parent node is the final parent node, so no substitution
+ // needed
+ return newExpr;
+ }
+ // ancestor must have a jaxxContextEntryPath
+ if (ancestor.jaxxContextEntryPath == null) {
+ throw new IllegalArgumentException(
+ "with the expression " + expr + ", the ancestor node ("
+ + ancestor + ") must have a jaxxContextEntryPath " +
+ "definition, but was not ");
+ }
+ newExpr = ancestor.jaxxContextEntryPath + newExpr;
+ return ancestor.computeJXPath(newExpr, parentNode);
+ }
+ // have more than one go up, so the ancestor node can not have a
+ // jaxxContextEntryPath
+ if (ancestor.jaxxContextEntryPath != null) {
+ throw new IllegalArgumentException(
+ "with the expression " + expr + ", the ancestor node can " +
+ "not have a jaxxContextEntryPath definition");
+ }
+ // substitute the last ..[/] and delegate to ancestor
+ String newExpr = expr.substring(0, lastIndex - 1) +
+ expr.substring(
+ lastIndex +
+ (expr.charAt(lastIndex + 3) == '/' ? 3 : 2)
+ );
+ return ancestor.computeJXPath(newExpr, parentNode);
+ }
+
+
+ @Override
+ public Object getBean() {
+ return bean;
+ }
+
+ @Override
+ public void setBean(Object bean) {
+ this.bean = bean;
+ }
+
+ @Override
+ public void reload(JAXXContext context) {
+
+ // clear bean cache
+ bean = null;
+
+ // clear context navigation cache
+ fullPath = null;
+
+ NavigationNodeRenderer renderer = getRenderer();
+ if (renderer == null) {
+ // this can't be !
+ throw new NullPointerException(
+ "could not find the renderer for node " + this);
+ }
+
+ String s = getFullPath();
+ Object b = null;
+ try {
+ b = getBean(context);
+ } finally {
+ if (log.isInfoEnabled()) {
+ log.info("bean for path [" + s + "] = " + bean);
+ }
+ }
+ renderer.reload(b);
+ }
+
+ /**
+ * Obtain the associated bean value from context corresponding to node
+ *
+ * @param context the context to seek
+ * @return the value associated in context with the given context path
+ */
+ @Override
+ public Object getBean(JAXXContext context) {
+ if (bean != null) {
+ // use cached bean
+ return bean;
+ }
+ Object result;
+ if (getJaxxContextEntryDef() != null && jaxxContextEntryPath == null) {
+ // the node maps directly a value in context, with no jxpath
+ // resolving
+ result = getJaxxContextEntryDef().getContextValue(context);
+ // save in cache
+ setBean(result);
+ return result;
+ }
+ // find the first ancestor node with a context def
+ NavigationTreeTableNode parentNode = getFirstAncestorWithDef();
+ if (parentNode == null) {
+ log.warn("could not find a ancestor node with a definition of" +
+ " a context entry from node (" + this + ")");
+ // todo must be an error
+ // no parent found
+ return null;
+ }
+ Object parentBean =
+ parentNode.getJaxxContextEntryDef().getContextValue(context);
+ if (parentBean == null) {
+ // must be an error no bean found
+ log.warn("could not find a bean attached in context from context" +
+ " entry definition " + parentNode.getJaxxContextEntryDef());
+ return null;
+ }
+ if (parentNode.jaxxContextEntryPath != null) {
+ // apply the jxpath on parentBean
+ JXPathContext jxcontext = JXPathContext.newContext(parentBean);
+ parentBean = jxcontext.getValue(parentNode.jaxxContextEntryPath);
+ }
+ // save in cache
+ parentNode.setBean(parentBean);
+ if (parentNode.equals(this)) {
+ // current node is the node matching the context entry value and
+ // no jxpath is found
+ return parentBean;
+ }
+ if (jaxxContextEntryPath == null) {
+ // todo must be an error
+ log.warn("must find a jaxxContextEntryPath on node (" + this +
+ ")");
+ return null;
+ }
+ String jxpathExpression = computeJXPath(jaxxContextEntryPath,
+ parentNode);
+ if (jxpathExpression == null) {
+ /// todo must be an error
+ log.warn("could not build jxpath from node " + parentNode +
+ " to " + this);
+ // could not retreave the jxpath...
+ return null;
+ }
+ if (jxpathExpression.startsWith("[")) {
+ // special case when we want to access a collection
+ jxpathExpression = '.' + jxpathExpression;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("jxpath : " + jxpathExpression);
+ }
+ JXPathContext jxcontext = JXPathContext.newContext(parentBean);
+ result = jxcontext.getValue(jxpathExpression);
+ // save in cache
+ setBean(result);
+ return result;
+ }
+
+
+ @Override
+ public NavigationTreeTableNode getChildAt(int index) {
+ return (NavigationTreeTableNode) super.getChildAt(index);
+ }
+
+ @Override
+ public NavigationTreeTableNode getParent() {
+ return (NavigationTreeTableNode) super.getParent();
+ }
+
+ @Override
+ public NavigationTreeTableNode getChild(String path) {
+ Enumeration<?> childs = children();
+ while (childs.hasMoreElements()) {
+ NavigationTreeTableNode son =
+ (NavigationTreeTableNode) childs.nextElement();
+ if (path.equals(son.getNodePath())) {
+ return son;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Enumeration<? extends NavigationTreeTableNode> children() {
+ return (Enumeration<? extends NavigationTreeTableNode>) super.children();
+ }
+
+ @Override
+ public void insert(NavigationTreeTableNode child, int index) {
+ super.insert(child, index);
+ }
+
+ @Override
+ public void remove(NavigationTreeTableNode node) {
+ super.remove(node);
+ }
+
+ @Override
+ public void setParent(NavigationTreeTableNode newParent) {
+ super.setParent(newParent);
+ }
+
+ @Override
+ public int getIndex(NavigationTreeTableNode node) {
+ return super.getIndex(node);
+ }
+
+ @Override
+ public void add(NavigationTreeTableNode node) {
+ super.add(node);
+ }
+
+ @Override
+ public NavigationTreeTableNode[] getPath() {
+ return getPathToRoot(this, 0);
+ }
+
+ @Override
+ public NavigationTreeTableNode[] getPathToRoot(
+ NavigationTreeTableNode aNode, int depth) {
+ NavigationTreeTableNode[] retNodes;
+
+ /* Check for null, in case someone passed in a null node, or
+ they passed in an element that isn't rooted at root. */
+ if (aNode == null) {
+ if (depth == 0) {
+ return null;
+ } else {
+ retNodes = new NavigationTreeTableNode[depth];
+ }
+ } else {
+ depth++;
+ retNodes = getPathToRoot(aNode.getParent(), depth);
+ retNodes[retNodes.length - depth] = aNode;
+ }
+ return retNodes;
+ }
+
+ @Override
+ public boolean isRoot() {
+ return getParent() == null;
+ }
+
+}
Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
===================================================================
--- trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-03-26 18:05:31 UTC (rev 1814)
@@ -23,6 +23,9 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.DefaultJAXXContext;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModel;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder;
+import jaxx.runtime.swing.navigation.tree.NavigationTreeNode;
import org.junit.Assert;
import org.junit.Test;
@@ -46,7 +49,7 @@
@Test
public void testFindNode() throws Exception {
- NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, new DefaultJAXXContext(), null, null);
+ NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, new DefaultJAXXContext(), null, null);
NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null);
@@ -104,7 +107,7 @@
}
/**
- * Test the {@link NavigationTreeNodeModel#getBean(String)}} with an entry point
+ * Test the {@link NavigationTreeModel#getBean(String)}} with an entry point
* as a bean.
* <p/>
* Tree is like this
@@ -158,7 +161,7 @@
new Model("two", 2, Collections.<Model>emptyList()),
new Model("three", 3, Collections.<Model>emptyList()))));
- NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, context, null, null);
+ NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, context, null, null);
NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null);
@@ -224,7 +227,7 @@
}
/**
- * Test the {@link NavigationTreeNodeModel#getBean(String)} with an entry point
+ * Test the {@link NavigationTreeModel#getBean(String)} with an entry point
* as a list.
* <p/>
* Tree is like this
@@ -279,7 +282,7 @@
context.setContextValue(list, "models");
- NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, context, null, null);
+ NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, context, null, null);
NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null);
Modified: trunk/src/site/rst/NavigationModel.rst
===================================================================
--- trunk/src/site/rst/NavigationModel.rst 2010-03-26 14:57:07 UTC (rev 1813)
+++ trunk/src/site/rst/NavigationModel.rst 2010-03-26 18:05:31 UTC (rev 1814)
@@ -22,7 +22,7 @@
Contrat 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.NavigationTreeNodeModel.NavigationTreeNode*.
+*jaxx.runtime.swing.navigation.tree.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*.
@@ -33,25 +33,25 @@
Tout les models suivants implémantent cette interface.
-jaxx.runtime.swing.navigation.NavigationTreeNodeModel
+jaxx.runtime.swing.navigation.tree.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
+jaxx.runtime.swing.navigation.treetable.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.NavigationTreeNodeModel.NavigationTreeTableNode* qui
-étend *jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*.
+*jaxx.runtime.swing.navigation.tree.NavigationTreeModel.NavigationTreeTableNode* qui
+étend *jaxx.runtime.swing.navigation.tree.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*).
+du builder (*jaxx.runtime.swing.navigation.treetable.NavigationTreeTableModelBuilder*).
Les builders
============
@@ -64,23 +64,23 @@
Tous les builders implémentent cette interface.
-jaxx.runtime.swing.navigation.NavigationTreeNodeModelBuilder
+jaxx.runtime.swing.navigation.tree.NavigationTreeModelBuilder
--------------------------------------------------------
Classe utilitaire pour construire le model (ici un
-*jaxx.runtime.swing.navigation.NavigationTreeNodeModel*) et décorer un arbre.
+*jaxx.runtime.swing.navigation.tree.NavigationTreeModel*) et décorer un arbre.
-jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder
+jaxx.runtime.swing.navigation.treetable.NavigationTreeTableModelBuilder
-------------------------------------------------------------
Classe utilitaire pour construire le model (ici un
-*jaxx.runtime.swing.navigation.NavigationTreeTableModel*) et décorer un arbre
+*jaxx.runtime.swing.navigation.treetable.NavigationTreeTableModel*) et décorer un arbre
tableau.
Les Handlers
============
-jaxx.runtime.swing.navigation.NavigationTreeHandler
+jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler
---------------------------------------------------
Cette classe est une implémentation d'un model de sélection pour les arbres
@@ -90,31 +90,31 @@
(*Strategy.PER_NODE*) soit on associe une ui par type de noeud
(*Strategy.PER_UI_TYPE*).
-jaxx.runtime.swing.navigation.NavigationTreeHandlerWithCardLayout
+jaxx.runtime.swing.navigation.handler.NavigationTreeHandlerWithCardLayout
-----------------------------------------------------------------
-Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour
+Extension de *jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler* pour
l'utilisation de CardLayout (*jaxx.runtime.swing.CardLayout2*).
-jaxx.runtime.swing.navigation.NavigationMultiTreeHandler
+jaxx.runtime.swing.navigation.handler.NavigationMultiTreeHandler
--------------------------------------------------------
TODO ajouter la strategie de la multiselection
-Extension de *jaxx.runtime.swing.navigation.NavigationTreeHandler* pour
+Extension de *jaxx.runtime.swing.navigation.handler.AbstractNavigationHandler* pour
ajouter la possibilité d'utiliser la multisélection.
-jaxx.runtime.swing.navigation.NavigationOneClicSelectionHandler
+jaxx.runtime.swing.navigation.handler.NavigationOneClicSelectionHandler
---------------------------------------------------------------
-Extension de *jaxx.runtime.swing.navigation.NavigationMultiTreeHandler* pour
+Extension de *jaxx.runtime.swing.navigation.handler.NavigationMultiTreeHandler* pour
activer le simple clic lors de la multi-selection.
Définition d'un noeud
=====================
Le noeud
-(*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*) est
+(*jaxx.runtime.swing.navigation.tree.NavigationTreeModel.NavigationTreeNode*) est
une extension d'un *javax.swing.tree.DefaultMutableTreeNode*.
Il apporte les nouvelles propriétés suivantes :
1
0
r1813 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 26 Mar '10
by tchemit@users.nuiton.org 26 Mar '10
26 Mar '10
Author: tchemit
Date: 2010-03-26 15:57:07 +0100 (Fri, 26 Mar 2010)
New Revision: 1813
Log:
improve Navigation model
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java
Removed:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java 2010-03-26 12:32:10 UTC (rev 1812)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java 2010-03-26 14:57:07 UTC (rev 1813)
@@ -24,10 +24,9 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.swing.tree.DefaultTreeModel;
-import javax.swing.tree.MutableTreeNode;
-import javax.swing.tree.TreeNode;
-import java.lang.reflect.Array;
+import javax.swing.event.TreeModelListener;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreePath;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
@@ -41,13 +40,16 @@
* @param <E> the type of nodes in model
* @since 2.0.1
*/
-public abstract class AbstractNavigationModel<E extends NavigationNode<E>> extends DefaultTreeModel implements NavigationModel<E> {
+public abstract class AbstractNavigationModel<E extends NavigationNode<E>> implements NavigationModel<E> {
+//public abstract class AbstractNavigationModel<E extends NavigationNode<E>> extends DefaultTreeModel implements NavigationModel<E> {
- static private final long serialVersionUID = 1L;
+// static private final long serialVersionUID = 1L;
/** Logger */
static private final Log log = LogFactory.getLog(NavigationTreeNodeModel.class);
+ final TreeModel delegate;
+
/**
* The path separator used to build the {@link NavigationTreeNode#fullPath}.
*
@@ -59,50 +61,45 @@
/** Context to retrieve beans */
private JAXXContext context;
- public AbstractNavigationModel(String pathSeparator, JAXXContext context) {
- super(null);
+ public AbstractNavigationModel(TreeModel delegate, String pathSeparator, JAXXContext context) {
this.pathSeparator = pathSeparator;
this.context = context;
+ this.delegate = delegate;
}
@Override
- public E getRoot() {
- return (E) super.getRoot();
+ public final E getRoot() {
+ return (E) getDelegate().getRoot();
}
@Override
- public void setRoot(E root) {
- setRoot((TreeNode) root);
- }
-
- @Override
- public E findNode(String path) {
+ public final E findNode(String path) {
return findNode(getRoot(), path, (Pattern) null);
}
@Override
- public E findNode(String path, String regex) {
+ public final E findNode(String path, String regex) {
return findNode(getRoot(), path, regex);
}
@Override
- public E findNode(String path, Pattern regex) {
+ public final E findNode(String path, Pattern regex) {
return findNode(getRoot(), path, regex);
}
@Override
- public E findNode(E root, String path) {
+ public final E findNode(E root, String path) {
return findNode(root, path, (Pattern) null);
}
@Override
- public E findNode(E root, String path, String regex) {
+ public final E findNode(E root, String path, String regex) {
return findNode(root, path,
regex == null ? null : Pattern.compile(regex));
}
@Override
- public E findNode(E root, String path, Pattern regex) {
+ public final E findNode(E root, String path, Pattern regex) {
if (regex != null) {
Matcher matcher = regex.matcher(path);
if (!matcher.matches() || matcher.groupCount() < 1) {
@@ -134,8 +131,17 @@
return context;
}
+ public TreeModel getDelegate() {
+ return delegate;
+ }
+
@Override
- public Object getBean(String navigationPath) {
+ public final String getPathSeparator() {
+ return pathSeparator;
+ }
+
+ @Override
+ public final Object getBean(String navigationPath) {
Object result;
E node = findNode(navigationPath, (Pattern) null);
result = getBean(node);
@@ -143,7 +149,7 @@
}
@Override
- public Object getBean(E node) {
+ public final Object getBean(E node) {
if (node == null) {
return null;
//fixme should throw a NPE exception
@@ -153,43 +159,18 @@
}
@Override
- public void nodeChanged(E node) {
+ public final void nodeChanged(E node) {
nodeChanged(node, false);
if (log.isDebugEnabled()) {
log.debug(node);
}
}
- @Override
- public void nodeStructureChanged(E node) {
- E n = node;
- //TC-20091004 never launch a deep reload
- reload(n, true);
- nodeStructureChanged((TreeNode) node);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- }
-
- @Override
- public void nodeChanged(E node, boolean deep) {
-
- E n = node;
- //TC-20091004 never launch a deep clean, since we do a deep nodeChanged.
- reload(n, deep);
- nodeChanged((TreeNode) node);
- }
-
- @Override
- public String getPathSeparator() {
- return pathSeparator;
- }
-
- protected void reload(E node) {
+ protected final void reload(E node) {
reload(node, false);
}
- protected void reload(E node, boolean deep) {
+ protected final void reload(E node, boolean deep) {
if (node == null) {
return;
}
@@ -204,16 +185,42 @@
}
}
+ //--------------------------------------------------------------------------
+ // TreeModel implementation
+ //--------------------------------------------------------------------------
+
@Override
- public E[] getPathToRoot(E aNode) {
- TreeNode[] treeNodes = getPathToRoot((TreeNode) aNode);
- E[] result = (E[]) Array.newInstance(aNode.getClass(), treeNodes.length);
- System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
- return result;
+ public final Object getChild(Object parent, int index) {
+ return getDelegate().getChild(parent, index);
}
@Override
- public void removeNodeFromParent(E node) {
- removeNodeFromParent((MutableTreeNode) node);
+ public final int getChildCount(Object parent) {
+ return getDelegate().getChildCount(parent);
}
+
+ @Override
+ public final boolean isLeaf(Object node) {
+ return getDelegate().isLeaf(node);
+ }
+
+ @Override
+ public final void valueForPathChanged(TreePath path, Object newValue) {
+ getDelegate().valueForPathChanged(path, newValue);
+ }
+
+ @Override
+ public final int getIndexOfChild(Object parent, Object child) {
+ return getDelegate().getIndexOfChild(parent, child);
+ }
+
+ @Override
+ public final void addTreeModelListener(TreeModelListener l) {
+ getDelegate().addTreeModelListener(l);
+ }
+
+ @Override
+ public final void removeTreeModelListener(TreeModelListener l) {
+ getDelegate().removeTreeModelListener(l);
+ }
}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java 2010-03-26 12:32:10 UTC (rev 1812)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java 2010-03-26 14:57:07 UTC (rev 1813)
@@ -1,40 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXContext;
-
-/**
- * Model of the tree used for a navigation tree.
- * <p/>
- * Il est composé de {@link NavigationTreeNode}
- *
- * @author chemit
- * @since 1.7.2
- */
-public class NavigationTreeNodeModel extends AbstractNavigationModel<NavigationTreeNode> {
-
- private static final long serialVersionUID = 1L;
-
- public NavigationTreeNodeModel(String pathSeparator, JAXXContext context) {
- super(pathSeparator, context);
- }
-}
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java 2010-03-26 14:57:07 UTC (rev 1813)
@@ -0,0 +1,99 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeModel;
+import javax.swing.tree.TreeNode;
+
+/**
+ * Model of the tree used for a navigation tree.
+ * <p/>
+ * Il est composé de {@link NavigationTreeNode}
+ *
+ * @author chemit
+ * @since 1.7.2
+ */
+public class NavigationTreeNodeModel extends AbstractNavigationModel<NavigationTreeNode> implements TreeModel {
+
+ /** Logger */
+ private static final Log log =
+ LogFactory.getLog(NavigationTreeNodeModel.class);
+
+// private static final long serialVersionUID = 1L;
+
+ public NavigationTreeNodeModel(String pathSeparator, JAXXContext context) {
+ super(new DefaultTreeModel(null), pathSeparator, context);
+ }
+//
+// @Override
+// public NavigationTreeNode getRoot() {
+// return (NavigationTreeNode) delegate.getRoot();
+// }
+
+ @Override
+ public void setRoot(NavigationTreeNode root) {
+ getDelegate().setRoot(root);
+ }
+
+ public DefaultTreeModel getDelegate() {
+ return (DefaultTreeModel) delegate;
+ }
+
+ @Override
+ public NavigationTreeNode[] getPathToRoot(NavigationTreeNode aNode) {
+ TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode);
+ NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length];
+ System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
+ return result;
+ }
+
+ @Override
+ public void removeNodeFromParent(NavigationTreeNode node) {
+ getDelegate().removeNodeFromParent(node);
+ }
+
+ @Override
+ public void nodeStructureChanged(NavigationTreeNode node) {
+ NavigationTreeNode n = node;
+ //TC-20091004 never launch a deep reload
+ reload(n, true);
+ getDelegate().nodeStructureChanged(node);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ }
+
+ @Override
+ public void nodeChanged(NavigationTreeNode node, boolean deep) {
+
+ NavigationTreeNode n = node;
+ //TC-20091004 never launch a deep clean, since we do a deep nodeChanged.
+ reload(n, deep);
+ getDelegate().nodeChanged(node);
+ }
+
+
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
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-26 12:32:10 UTC (rev 1812)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-26 14:57:07 UTC (rev 1813)
@@ -25,14 +25,11 @@
import org.apache.commons.logging.LogFactory;
import org.jdesktop.swingx.tree.TreeModelSupport;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
+import org.jdesktop.swingx.treetable.TreeTableModel;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
-import java.util.Enumeration;
import java.util.List;
-import java.util.StringTokenizer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Model of the tree table used for a navigation tree table.
@@ -44,51 +41,67 @@
* @author sletellier
* @since 2.0.0
*/
-public class NavigationTreeTableModel extends DefaultTreeTableModel implements NavigationModel<NavigationTreeTableNode> {
+public class NavigationTreeTableModel extends AbstractNavigationModel<NavigationTreeTableNode> implements TreeTableModel {
- static private final long serialVersionUID = 1L;
+// static private final long serialVersionUID = 1L;
/** Logger */
static private final Log log =
LogFactory.getLog(NavigationTreeTableModel.class);
- /**
- * The path separator used to build the {@link NavigationTreeNode#fullPath}.
- *
- * @see NavigationTreeNode#getNodePath()
- * @see NavigationTreeNode#getFullPath()
- */
- protected final String pathSeparator;
+ public static class MyDefaultTreeTableModel extends DefaultTreeTableModel {
- /** Context to retrieve beans */
- private JAXXContext context;
+ public TreeModelSupport getModelSupport() {
+ return modelSupport;
+ }
+ }
+// /**
+// * The path separator used to build the {@link NavigationTreeNode#fullPath}.
+// *
+// * @see NavigationTreeNode#getNodePath()
+// * @see NavigationTreeNode#getFullPath()
+// */
+// protected final String pathSeparator;
+//
+// /** Context to retrieve beans */
+// private JAXXContext context;
+
protected List<String> columnsName;
public NavigationTreeTableModel(String pathSeparator, JAXXContext context, List<String> columnsName) {
- super(null);
- this.pathSeparator = pathSeparator;
- this.context = context;
+ super(new MyDefaultTreeTableModel(), pathSeparator, context);
+// this.pathSeparator = pathSeparator;
+// this.context = context;
this.columnsName = columnsName;
}
- @Override
- public NavigationTreeTableNode getRoot() {
- return (NavigationTreeTableNode) super.root;
+
+ public MyDefaultTreeTableModel getDelegate() {
+ return (MyDefaultTreeTableModel) delegate;
}
+// @Override
+// public NavigationTreeTableNode getRoot() {
+// return (NavigationTreeTableNode) getDelegate().getRoot();
+// }
+
@Override
public NavigationTreeTableNode[] getPathToRoot(NavigationTreeTableNode aNode) {
if (aNode == null) {
return null;
}
- return (NavigationTreeTableNode[]) super.getPathToRoot(aNode);
+ TreeNode[] treeNodes = getDelegate().getPathToRoot(aNode);
+ NavigationTreeTableNode[] result = new NavigationTreeTableNode[treeNodes.length];
+ System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
+ return result;
}
@Override
public void setRoot(NavigationTreeTableNode root) {
- this.root = root;
+ getDelegate().setRoot(root);
+// this.root = root;
getModelSupport().fireNewRoot();
}
@@ -107,127 +120,126 @@
int index = parent.getIndex(node);
node.removeFromParent();
-
- modelSupport.fireChildRemoved(new TreePath(getPathToRoot(parent)),
- index, node);
+ getModelSupport().fireChildRemoved(new TreePath(getPathToRoot(parent)),
+ index, node);
}
- @Override
- public NavigationTreeTableNode findNode(String path) {
- return findNode(getRoot(), path, (Pattern) null);
- }
+// @Override
+// public NavigationTreeTableNode findNode(String path) {
+// return findNode(getRoot(), path, (Pattern) null);
+// }
+//
+// @Override
+// public NavigationTreeTableNode findNode(String path, String regex) {
+// return findNode(getRoot(), path, regex);
+// }
+//
+// @Override
+// public NavigationTreeTableNode findNode(String path, Pattern regex) {
+// return findNode(getRoot(), path, regex);
+// }
+//
+// @Override
+// public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
+// String path) {
+// return findNode(root, path, (Pattern) null);
+// }
+//
+// @Override
+// public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
+// String path,
+// String regex) {
+// return findNode(root, path, regex == null ?
+// null : Pattern.compile(regex));
+// }
+//
+// @Override
+// public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
+// String path,
+// Pattern regex) {
+// if (regex != null) {
+// Matcher matcher = regex.matcher(path);
+// if (!matcher.matches() || matcher.groupCount() < 1) {
+// log.warn("no matching regex " + regex + " to " + path);
+// return null;
+// }
+// path = matcher.group(1);
+// if (log.isDebugEnabled()) {
+// log.debug("matching regex " + regex + " : " + path);
+// }
+// }
+// StringTokenizer stk = new StringTokenizer(path, pathSeparator);
+// NavigationTreeTableNode result = root;
+// // pas the first token (matches the root node)
+// if (root.isRoot() && stk.hasMoreTokens()) {
+// String rootPath = stk.nextToken();
+// if (!rootPath.equals(root.getNodePath())) {
+// return null;
+// }
+// }
+// while (stk.hasMoreTokens()) {
+// result = result.getChild(stk.nextToken());
+// }
+// return result;
+// }
+//
+// @Override
+// public JAXXContext getContext() {
+// return context;
+// }
+//
+// @Override
+// public Object getBean(String navigationPath) {
+// Object result;
+// NavigationTreeTableNode node = findNode(navigationPath, (Pattern) null);
+// result = getBean(node);
+// return result;
+// }
+//
+// @Override
+// public Object getBean(NavigationTreeTableNode node) {
+// if (node == null) {
+// return null;
+// //fixme should throw a NPE exception
+// //throw new NullPointerException("node can not be null");
+// }
+// return node.getBean(getContext());
+// }
- @Override
- public NavigationTreeTableNode findNode(String path, String regex) {
- return findNode(getRoot(), path, regex);
- }
- @Override
- public NavigationTreeTableNode findNode(String path, Pattern regex) {
- return findNode(getRoot(), path, regex);
- }
-
- @Override
- public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
- String path) {
- return findNode(root, path, (Pattern) null);
- }
-
- @Override
- public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
- String path,
- String regex) {
- return findNode(root, path, regex == null ?
- null : Pattern.compile(regex));
- }
-
- @Override
- public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
- String path,
- Pattern regex) {
- if (regex != null) {
- Matcher matcher = regex.matcher(path);
- if (!matcher.matches() || matcher.groupCount() < 1) {
- log.warn("no matching regex " + regex + " to " + path);
- return null;
- }
- path = matcher.group(1);
- if (log.isDebugEnabled()) {
- log.debug("matching regex " + regex + " : " + path);
- }
- }
- StringTokenizer stk = new StringTokenizer(path, pathSeparator);
- NavigationTreeTableNode result = root;
- // pas the first token (matches the root node)
- if (root.isRoot() && stk.hasMoreTokens()) {
- String rootPath = stk.nextToken();
- if (!rootPath.equals(root.getNodePath())) {
- return null;
- }
- }
- while (stk.hasMoreTokens()) {
- result = result.getChild(stk.nextToken());
- }
- return result;
- }
-
- @Override
- public JAXXContext getContext() {
- return context;
- }
-
- @Override
- public Object getBean(String navigationPath) {
- Object result;
- NavigationTreeTableNode node = findNode(navigationPath, (Pattern) null);
- result = getBean(node);
- return result;
- }
-
- @Override
- public Object getBean(NavigationTreeTableNode node) {
- if (node == null) {
- return null;
- //fixme should throw a NPE exception
- //throw new NullPointerException("node can not be null");
- }
- return node.getBean(getContext());
- }
-
-
/**
* Accessor to tree model support.
*
* @return tree model support
*/
protected TreeModelSupport getModelSupport() {
- return modelSupport;
+ return getDelegate().getModelSupport();
}
- @Override
- public void nodeChanged(NavigationTreeTableNode node) {
- if (node != null) {
- NavigationTreeTableNode parent = node.getParent();
- NavigationTreeTableNode[] treeNodes = getPathToRoot(parent);
- if (treeNodes != null) {
- modelSupport.fireChildChanged(
- new TreePath(treeNodes), parent.getIndex(node), node);
- } else {
- log.error("[Node changed] Path to root is null !");
- }
- reload((NavigationTreeTableNode) node, true);
- } else {
- log.error("Node is null !");
- }
- }
+// @Override
+// public void nodeChanged(NavigationTreeTableNode node) {
+// if (node != null) {
+// NavigationTreeTableNode parent = node.getParent();
+// NavigationTreeTableNode[] treeNodes = getPathToRoot(parent);
+// if (treeNodes != null) {
+// getModelSupport().fireChildChanged(
+// new TreePath(treeNodes), parent.getIndex(node), node);
+// } else {
+// log.error("[Node changed] Path to root is null !");
+// }
+// reload((NavigationTreeTableNode) node, true);
+// } else {
+// log.error("Node is null !");
+// }
+// }
@Override
public void nodeStructureChanged(NavigationTreeTableNode node) {
if (node != null) {
- NavigationTreeTableNode parent = node.getParent();
+ NavigationTreeTableNode parent = node.getParent();
TreeNode[] treeNodes = getPathToRoot(parent);
if (treeNodes != null) {
- modelSupport.fireTreeStructureChanged(new TreePath(treeNodes));
+ getModelSupport().fireTreeStructureChanged(new TreePath(treeNodes));
} else {
log.error("[Node structure changed] Path to root is null !");
}
@@ -243,7 +255,7 @@
NavigationTreeTableNode parent = node.getParent();
TreeNode[] treeNodes = getPathToRoot(parent);
if (treeNodes != null) {
- modelSupport.fireChildChanged(
+ getModelSupport().fireChildChanged(
new TreePath(treeNodes), parent.getIndex(node), node);
} else {
log.error("[Node changed] Path to root is null !");
@@ -253,10 +265,15 @@
log.error("Node is null !");
}
}
+//
+// @Override
+// public String getPathSeparator() {
+// return pathSeparator;
+// }
@Override
- public String getPathSeparator() {
- return pathSeparator;
+ public Class<?> getColumnClass(int i) {
+ return getDelegate().getColumnClass(i);
}
@Override
@@ -269,23 +286,43 @@
return columnsName.get(column);
}
- protected void reload(NavigationTreeTableNode node) {
- reload(node, false);
+ @Override
+ public int getHierarchicalColumn() {
+ return getDelegate().getHierarchicalColumn();
}
- protected void reload(NavigationTreeTableNode node, boolean deep) {
- if (node == null) {
- return;
- }
- node.reload(getContext());
+ @Override
+ public Object getValueAt(Object o, int i) {
+ return getDelegate().getValueAt(o, i);
+ }
- if (deep) {
- Enumeration<?> childs = node.children();
- while (childs.hasMoreElements()) {
- NavigationTreeTableNode o = (NavigationTreeTableNode) childs.nextElement();
- reload(o, true);
- }
- }
+ @Override
+ public boolean isCellEditable(Object o, int i) {
+ return getDelegate().isCellEditable(o, i);
}
+ @Override
+ public void setValueAt(Object o, Object o1, int i) {
+ getDelegate().setValueAt(o, o1, i);
+ }
+//
+// protected void reload(NavigationTreeTableNode node) {
+// reload(node, false);
+// }
+//
+// protected void reload(NavigationTreeTableNode node, boolean deep) {
+// if (node == null) {
+// return;
+// }
+// node.reload(getContext());
+//
+// if (deep) {
+// Enumeration<?> childs = node.children();
+// while (childs.hasMoreElements()) {
+// NavigationTreeTableNode o = (NavigationTreeTableNode) childs.nextElement();
+// reload(o, true);
+// }
+// }
+// }
+
}
1
0
r1812 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 26 Mar '10
by tchemit@users.nuiton.org 26 Mar '10
26 Mar '10
Author: tchemit
Date: 2010-03-26 13:32:10 +0100 (Fri, 26 Mar 2010)
New Revision: 1812
Log:
add TreeTable model builder
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java 2010-03-26 12:31:26 UTC (rev 1811)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java 2010-03-26 12:32:10 UTC (rev 1812)
@@ -6,16 +6,24 @@
public class NavigationTreeTableModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeTableNode> {
- public NavigationTreeTableModelBuilder(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, NavigationModel<NavigationTreeTableNode> navigationTreeTableNodeNavigationModel) {
- super(defaultUIClass, defaultUIHandlerClass, navigationTreeTableNodeNavigationModel);
+ public NavigationTreeTableModelBuilder(
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass,
+ NavigationModel<NavigationTreeTableNode> model) {
+ super(defaultUIClass, defaultUIHandlerClass, model);
}
@Override
- public NavigationTreeTableNode createNavigationTreeNode(String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
+ public NavigationTreeTableNode createNavigationTreeNode(
+ String pathSeparator,
+ String contextName,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
return new NavigationTreeTableNode(
pathSeparator,
contextName,
- jaxxContextEntryDef
+ jaxxContextEntryDef,
+ jaxxContextEntryPath
);
}
}
1
0
r1811 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 26 Mar '10
by tchemit@users.nuiton.org 26 Mar '10
26 Mar '10
Author: tchemit
Date: 2010-03-26 13:31:26 +0100 (Fri, 26 Mar 2010)
New Revision: 1811
Log:
add TreeTable model builder
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java 2010-03-26 12:31:26 UTC (rev 1811)
@@ -0,0 +1,21 @@
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXContextEntryDef;
+
+public class NavigationTreeTableModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeTableNode> {
+
+ public NavigationTreeTableModelBuilder(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, NavigationModel<NavigationTreeTableNode> navigationTreeTableNodeNavigationModel) {
+ super(defaultUIClass, defaultUIHandlerClass, navigationTreeTableNodeNavigationModel);
+ }
+
+ @Override
+ public NavigationTreeTableNode createNavigationTreeNode(String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
+ return new NavigationTreeTableNode(
+ pathSeparator,
+ contextName,
+ jaxxContextEntryDef
+ );
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
1
0
26 Mar '10
Author: tchemit
Date: 2010-03-26 12:34:09 +0100 (Fri, 26 Mar 2010)
New Revision: 1810
Log:
Evolution #419: Refactor navigation package (a abstract based + a impl package for tree and treetable)
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/tree/
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/treetable/
Removed:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java
Modified:
trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst
trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java
trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
trunk/src/site/rst/NavigationModel.rst
Modified: trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst
===================================================================
--- trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-compiler/src/site/rst/NavigationTreeModel.rst 2010-03-26 11:34:09 UTC (rev 1810)
@@ -15,12 +15,12 @@
Le développement est effectué dans le paquetage *jaxx.runtime.swing.navigation*.
-jaxx.runtime.swing.navigation.NavigationTreeModel
+jaxx.runtime.swing.navigation.NavigationTreeNodeModel
=================================================
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*.
+Les noeuds présents dans ce modèle sont aussi typés en *jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*.
L'idée principale est de pouvoir associé à un noeud précis un chemin depuis la racine, ce que l'on appele *chemin de navigation*.
@@ -30,7 +30,7 @@
Définition d'un noeud
=====================
-Le noeud (*jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*.
+Le noeud (*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*) est une extension d'un *javax.swing.tree.DefaultMutableTreeNode*.
Il apporte les nouvelles propriétés suivantes :
Modified: trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java
===================================================================
--- trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-compiler/src/test/java/jaxx/compiler/reflect/ClassDescriptorTest.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -1,23 +1,23 @@
-/*
- * *##%
- * JAXX Compiler
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
+/*
+ * *##%
+ * JAXX Compiler
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
package jaxx.compiler.reflect;
import static org.junit.Assert.assertEquals;
@@ -28,7 +28,7 @@
/*@Test
public void testGetClassDescriptor() throws Exception {
- ClassDescriptorLoader.getClassDescriptor("jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode");
+ ClassDescriptorLoader.getClassDescriptor("jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode");
}*/
@Test
public void testBuiltInClassName() throws ClassNotFoundException, NoSuchMethodException {
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -59,7 +59,7 @@
}
@Override
- public NavigationModel<NavigationTreeNode> createTreeModel(JAXXContext context) {
+ public NavigationTreeNodeModel createTreeModel(JAXXContext context) {
if (log.isDebugEnabled()) {
log.debug("start creating demo model");
@@ -126,7 +126,7 @@
addDemo(CounterDemo.class).
addDemo(CalculatorDemo.class);
- NavigationModel<NavigationTreeNode> model = builder.getModel();
+ NavigationTreeNodeModel model = builder.getModel();
if (log.isDebugEnabled()) {
builder.printModel(model.getRoot());
@@ -137,11 +137,11 @@
}
@Override
- public NavigationTreeHandler createTreeHandler(JAXXObject context) {
+ public NavigationTreeHandler<NavigationTreeNode> createTreeHandler(JAXXObject context) {
- NavigationTreeHandler handler;
+ NavigationTreeHandler<NavigationTreeNode> handler;
- handler = new NavigationTreeHandlerWithCardLayout(
+ handler = new NavigationTreeHandlerWithCardLayout<NavigationTreeNode>(
getPrefix(),
context,
NavigationTreeHandler.Strategy.PER_UI_TYPE) {
@@ -149,8 +149,8 @@
private static final long serialVersionUID = 1L;
@Override
- protected NavigationTreeModel getNavigationTreeModel() {
- return (NavigationTreeModel) getModel(getContext());
+ protected NavigationTreeNodeModel getNavigationTreeModel() {
+ return (NavigationTreeNodeModel) getModel(getContext());
}
@Override
@@ -181,7 +181,7 @@
return handler;
}
- static class TreeModelBuilder extends NavigationTreeModelBuilder {
+ static class TreeModelBuilder extends NavigationTreeNodeModelBuilder {
/** la definition de l'unqiue object a partage */
static private final JAXXContextEntryDef<DemoConfig> def =
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -95,7 +95,7 @@
}
@Override
- public NavigationTreeModel createTreeModel(JAXXContext context) {
+ public NavigationTreeNodeModel createTreeModel(JAXXContext context) {
if (builder == null) {
builder = new FullNavigationTreeModelBuilder(context);
@@ -103,7 +103,7 @@
builder.createInitialModel();
- NavigationTreeModel model = builder.getModel();
+ NavigationTreeNodeModel model = builder.getModel();
// save tree model in context
setModel(context, model);
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -27,7 +27,7 @@
import jaxx.runtime.JAXXContext;
import jaxx.runtime.decorator.Decorator;
import jaxx.runtime.decorator.DecoratorProvider;
-import jaxx.runtime.swing.navigation.NavigationTreeModelBuilder;
+import jaxx.runtime.swing.navigation.NavigationTreeNodeModelBuilder;
import jaxx.runtime.swing.navigation.NavigationTreeNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -40,7 +40,7 @@
* @author chemit
* @since 2.0.0
*/
-public class FullNavigationTreeModelBuilder extends NavigationTreeModelBuilder {
+public class FullNavigationTreeModelBuilder extends NavigationTreeNodeModelBuilder {
/**
* Logger
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/content/ContentUI.jaxx 2010-03-26 11:34:09 UTC (rev 1810)
@@ -21,7 +21,7 @@
<JPanel abstract='true'
layout='{new BorderLayout()}'
genericType='B extends Object'
- implements='jaxx.runtime.swing.navigation.NavigationContentUI'>
+ implements='jaxx.runtime.swing.navigation.NavigationContentUI<NavigationTreeNode>'>
<script><![CDATA[
import jaxx.demo.component.jaxx.navigation.*;
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationHelper.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -0,0 +1,294 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdesktop.swingx.JXTreeTable;
+
+import javax.swing.*;
+import javax.swing.tree.TreePath;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Enumeration;
+import java.util.regex.Pattern;
+
+/**
+ * Helper object associated to a given navigation tree system.
+ * <p/>
+ * To helper is context safe (base on a {@link NavigationTreeContextHelper}.
+ *
+ * @author Letellier
+ * @param <E> type of nodes in model
+ * @see NavigationTreeNodeModel
+ * @since 2.0.1
+ */
+public abstract class AbstractNavigationHelper<E extends NavigationNode<E>> extends NavigationTreeContextHelper<E> {
+
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(NavigationTreeHelper.class);
+
+ /**
+ * Create the model.
+ *
+ * @param context the context to associate with fresh model
+ * @return the new model build with data from the given context
+ */
+ public abstract NavigationModel<E> createTreeModel(JAXXContext context);
+
+ /**
+ * Create the tree handler.
+ *
+ * @param context the context to associate with fresh handler
+ * @return the new handler
+ */
+ public abstract NavigationTreeHandler createTreeHandler(JAXXObject context);
+
+ public AbstractNavigationHelper(String contextPrefix) {
+ super(contextPrefix);
+ }
+
+ public Object getContextValue(JAXXContext context, String path)
+ throws InvocationTargetException, NoSuchMethodException,
+ IllegalAccessException {
+ NavigationModel<E> treeModel = getSafeModel(context);
+ return treeModel.getBean(path);
+ }
+
+ public E findNode(JAXXContext context, String path) {
+ NavigationModel<E> treeModel = getSafeModel(context);
+ return treeModel.findNode(path);
+ }
+
+ public E findNode(JAXXContext context, String path,
+ String regex) {
+ NavigationModel<E> treeModel = getSafeModel(context);
+ return treeModel.findNode(path, regex);
+ }
+
+ public E findNode(JAXXContext context, String path,
+ Pattern regex) {
+
+ NavigationModel<E> treeModel = getSafeModel(context);
+ return treeModel.findNode(path, regex);
+ }
+
+ public E findNode(JAXXContext context, String path,
+ String regex, String suffix) {
+
+ NavigationModel<E> treeModel = getSafeModel(context);
+
+ E node = treeModel.findNode(path, regex);
+ if (node != null && suffix != null) {
+ node = treeModel.findNode(node, suffix);
+ }
+ return node;
+ }
+
+ public E findNode(JAXXContext context, String path,
+ Pattern regex, String suffix) {
+
+ NavigationModel<E> treeModel = getSafeModel(context);
+
+ E node = treeModel.findNode(path, regex);
+ if (node != null && suffix != null) {
+ node = treeModel.findNode(node, suffix);
+ }
+ return node;
+ }
+
+ /**
+ * Sélection d'un noeud dans l'arbre de navigation à partir de son path.
+ *
+ * @param context le contexte applicatif
+ * @param path le path absolue du noeud dans l'arbre
+ */
+ public void selectNode(JAXXContext context, String path) {
+ E node = findNode(context, path);
+ if (log.isDebugEnabled()) {
+ log.debug(path + " :: " + node);
+ }
+ if (node != null) {
+ selectNode(context, node);
+ }
+ }
+
+ /**
+ * Sélection d'un noeud dans l'arbre de navigation.
+ *
+ * @param context le contexte applicatif
+ * @param node le noeud à sélectionner dans l'arbre
+ */
+ public void selectNode(JAXXContext context, E node) {
+
+
+ NavigationModel<E> navigationModel = getSafeModel(context);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ TreePath path = new TreePath(navigationModel.getPathToRoot(node));
+ JTree tree = getTree(context);
+ if (tree == null) {
+ // FIXME : Refactor in other helper ?
+ // If its JXTreeTable
+ JXTreeTable treeTable = getSafeTreeTable(context);
+ treeTable.getTreeSelectionModel().setSelectionPath(path);
+ treeTable.scrollPathToVisible(path);
+ return;
+ }
+ tree.setSelectionPath(path);
+ tree.scrollPathToVisible(path);
+ }
+
+ /**
+ * Sélection du parent du noeud selectionne dans l'arbre de navigation.
+ *
+ * @param context le contexte applicatif
+ */
+ public void gotoParentNode(JAXXContext context) {
+
+ E node = getSelectedNode(context);
+
+ if (node == null) {
+ // pas de noeud selectionne
+ throw new NullPointerException("no selected node in context");
+ }
+ node = node.getParent();
+
+ selectNode(context, node);
+ }
+
+ /**
+ * Obtain the first ancestor with the matching internalClass
+ *
+ * @param current the node to test
+ * @param beanClass the type of the internal class to seek of
+ * @return the first ancestor node with the matching class or {@code null}
+ * if not found
+ */
+ public E getParentNode(E current,
+ Class<?> beanClass) {
+ if (current == null) {
+ // ancestor not found
+ return null;
+ }
+ if (beanClass.isAssignableFrom(current.getInternalClass())) {
+ // matching node
+ return current;
+ }
+ // try in the parent of node
+ return getParentNode(current.getParent(), beanClass);
+ }
+
+ /**
+ * Sélection d'un fils du noeud selectionne dans l'arbre de navigation.
+ *
+ * @param context le contexte applicatif
+ * @param childIndex index du fils a selectionner
+ */
+ public void gotoChildNode(JAXXContext context, int childIndex) {
+
+ E node = getSelectedNode(context);
+
+ if (node == null) {
+ // pas de noeud selectionne
+ throw new NullPointerException("no selected node in context");
+ }
+ node = node.getChildAt(childIndex);
+
+ selectNode(context, node);
+ }
+
+ /**
+ * Demande une opération de repaint sur un noeud de l'arbre de navigation.
+ * <p/>
+ * <b>Note:</b> La descendance du noeud n'est pas repainte.
+ *
+ * @param context le contexte applicatif
+ * @param node le noeud à repaindre
+ */
+ public void repaintNode(JAXXContext context, E node) {
+ repaintNode(context, node, false);
+ }
+
+ /**
+ * Demande une opération de repaint sur un noeud de l'arbre de navigation.
+ * <p/>
+ * <b>Note:</b> La descendance du noeud est repainte si le paramètre
+ * <code>deep</code> est à <code>true</code>.
+ *
+ * @param context le contexte applicatif
+ * @param node le noeud à repaindre
+ * @param deep un flag pour activer la repainte de la descendance du
+ * noeud
+ */
+ public void repaintNode(JAXXContext context, E node,
+ boolean deep) {
+ NavigationModel<E> navigationModel = getSafeModel(context);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ navigationModel.nodeChanged(node);
+ if (deep) {
+ // repaint childs nodes
+ //todo we should only repaint necessary nodes ?
+ Enumeration<? extends E> e = node.children();
+ while (e.hasMoreElements()) {
+ E child = e.nextElement();
+ repaintNode(context, child, true);
+ }
+ }
+ }
+
+ public NavigationModel<E> getSafeModel(JAXXContext context)
+ throws NullPointerException {
+ NavigationModel<E> model = getModel(context);
+ if (model == null) {
+ throw new NullPointerException(
+ "could not find tree model with key " +
+ getModelContextEntry() + " in context " + context);
+ }
+ return model;
+ }
+
+ public JTree getSafeTree(JAXXContext context) throws NullPointerException {
+ JTree tree = getTree(context);
+ if (tree == null) {
+ throw new NullPointerException(
+ "could not find tree with key " + getTreeContextEntry() +
+ " in context " + context);
+ }
+ return tree;
+ }
+
+ public JXTreeTable getSafeTreeTable(JAXXContext context)
+ throws NullPointerException {
+ JXTreeTable treeTable = getTreeTable(context);
+ if (treeTable == null) {
+ throw new NullPointerException(
+ "could not find tree with key " +
+ getTreeTableContextEntry() + " in context " + context);
+ }
+ return treeTable;
+ }
+}
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModel.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -0,0 +1,219 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.MutableTreeNode;
+import javax.swing.tree.TreeNode;
+import java.lang.reflect.Array;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Model of the tree used for a navigation tree. It is composed of {@link E}
+ * nodes.
+ *
+ * @author letellier
+ * @param <E> the type of nodes in model
+ * @since 2.0.1
+ */
+public abstract class AbstractNavigationModel<E extends NavigationNode<E>> extends DefaultTreeModel implements NavigationModel<E> {
+
+ static private final long serialVersionUID = 1L;
+
+ /** Logger */
+ static private final Log log = LogFactory.getLog(NavigationTreeNodeModel.class);
+
+ /**
+ * The path separator used to build the {@link NavigationTreeNode#fullPath}.
+ *
+ * @see NavigationTreeNode#getNodePath()
+ * @see NavigationTreeNode#getFullPath()
+ */
+ protected final String pathSeparator;
+
+ /** Context to retrieve beans */
+ private JAXXContext context;
+
+ public AbstractNavigationModel(String pathSeparator, JAXXContext context) {
+ super(null);
+ this.pathSeparator = pathSeparator;
+ this.context = context;
+ }
+
+ @Override
+ public E getRoot() {
+ return (E) super.getRoot();
+ }
+
+ @Override
+ public void setRoot(E root) {
+ setRoot((TreeNode) root);
+ }
+
+ @Override
+ public E findNode(String path) {
+ return findNode(getRoot(), path, (Pattern) null);
+ }
+
+ @Override
+ public E findNode(String path, String regex) {
+ return findNode(getRoot(), path, regex);
+ }
+
+ @Override
+ public E findNode(String path, Pattern regex) {
+ return findNode(getRoot(), path, regex);
+ }
+
+ @Override
+ public E findNode(E root, String path) {
+ return findNode(root, path, (Pattern) null);
+ }
+
+ @Override
+ public E findNode(E root, String path, String regex) {
+ return findNode(root, path,
+ regex == null ? null : Pattern.compile(regex));
+ }
+
+ @Override
+ public E findNode(E root, String path, Pattern regex) {
+ if (regex != null) {
+ Matcher matcher = regex.matcher(path);
+ if (!matcher.matches() || matcher.groupCount() < 1) {
+ log.warn("no matching regex " + regex + " to " + path);
+ return null;
+ }
+ path = matcher.group(1);
+ if (log.isDebugEnabled()) {
+ log.debug("matching regex " + regex + " : " + path);
+ }
+ }
+ StringTokenizer stk = new StringTokenizer(path, pathSeparator);
+ E result = root;
+ // pas the first token (matches the root node)
+ if (root.isRoot() && stk.hasMoreTokens()) {
+ String rootPath = stk.nextToken();
+ if (!rootPath.equals(root.getNodePath())) {
+ return null;
+ }
+ }
+ while (stk.hasMoreTokens()) {
+ result = result.getChild(stk.nextToken());
+ }
+ return result;
+ }
+
+ @Override
+ public JAXXContext getContext() {
+ return context;
+ }
+
+ @Override
+ public Object getBean(String navigationPath) {
+ Object result;
+ E node = findNode(navigationPath, (Pattern) null);
+ result = getBean(node);
+ return result;
+ }
+
+ @Override
+ public Object getBean(E node) {
+ if (node == null) {
+ return null;
+ //fixme should throw a NPE exception
+ //throw new NullPointerException("node can not be null");
+ }
+ return node.getBean(getContext());
+ }
+
+ @Override
+ public void nodeChanged(E node) {
+ nodeChanged(node, false);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ }
+
+ @Override
+ public void nodeStructureChanged(E node) {
+ E n = node;
+ //TC-20091004 never launch a deep reload
+ reload(n, true);
+ nodeStructureChanged((TreeNode) node);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ }
+
+ @Override
+ public void nodeChanged(E node, boolean deep) {
+
+ E n = node;
+ //TC-20091004 never launch a deep clean, since we do a deep nodeChanged.
+ reload(n, deep);
+ nodeChanged((TreeNode) node);
+ }
+
+ @Override
+ public String getPathSeparator() {
+ return pathSeparator;
+ }
+
+ protected void reload(E node) {
+ reload(node, false);
+ }
+
+ protected void reload(E node, boolean deep) {
+ if (node == null) {
+ return;
+ }
+ node.reload(getContext());
+
+ if (deep) {
+ Enumeration<? extends E> childs = node.children();
+ while (childs.hasMoreElements()) {
+ E o = childs.nextElement();
+ reload(o, true);
+ }
+ }
+ }
+
+ @Override
+ public E[] getPathToRoot(E aNode) {
+ TreeNode[] treeNodes = getPathToRoot((TreeNode) aNode);
+ E[] result = (E[]) Array.newInstance(aNode.getClass(), treeNodes.length);
+ System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
+ return result;
+ }
+
+ @Override
+ public void removeNodeFromParent(E node) {
+ removeNodeFromParent((MutableTreeNode) node);
+ }
+}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -27,7 +27,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.util.Collection;
import java.util.Enumeration;
/**
@@ -37,7 +36,7 @@
* @author sletellier
* @since 2.0.0
*/
-public abstract class AbstractNavigationModelBuilder<E extends NavigationTreeNode> implements NavigationModelBuilder<E> {
+public abstract class AbstractNavigationModelBuilder<E extends NavigationNode<E>> implements NavigationModelBuilder<E> {
/** Logger */
static private final Log log =
@@ -196,7 +195,7 @@
@Override
public E removeChildNode(E node) {
- E parentNode = (E) node.getParent();
+ E parentNode = node.getParent();
model.removeNodeFromParent(node);
return parentNode;
}
@@ -243,9 +242,9 @@
log.debug("value from node " + node.getBean(getModel().getContext()));
log.debug("value from model " + getModel().getBean(node));
}
- Enumeration<?> children = node.children();
+ Enumeration<? extends E> children = node.children();
while (children.hasMoreElements()) {
- printModel((E) children.nextElement());
+ printModel(children.nextElement());
}
}
@@ -269,84 +268,4 @@
return node;
}
- public static abstract class ChildBuilder<O, E extends NavigationTreeNode> {
-
- protected AbstractNavigationModelBuilder<E> builder;
-
- protected ChildBuilder(AbstractNavigationModelBuilder<E> builder) {
- this.builder = builder;
- }
-
- protected abstract void init(Class<? extends O> klass);
-
- protected abstract Decorator<? extends O> getDecorator(O child);
-
- protected abstract String getJXPath(O child);
-
- protected abstract String getNavigationPath(O child);
-
- public void build(E parent,
- boolean cacheValues,
- Class<? extends O> klass,
- Collection<? extends O> beans,
- Class<? extends JAXXObject> ui,
- Class<? extends JAXXAction> actionClass) {
-
- if (beans == null || beans.isEmpty()) {
- // no bean to treate
- return;
- }
-
- init(klass);
-
- E node;
-
- for (O o : beans) {
- node = builder.build(
- parent,
- getDecorator(o),
- getJXPath(o),
- getNavigationPath(o),
- ui,
- actionClass
- );
- if (cacheValues) {
- // cache the bean value to improve performance
- node.setBean(o);
- }
- }
- }
-
- public void build(E parent,
- boolean cacheValues,
- Class<? extends O> klass,
- O[] beans,
- Class<? extends JAXXObject> ui,
- Class<? extends JAXXAction> actionClass) {
-
- if (beans == null || beans.length == 0) {
- // no bean to treate
- return;
- }
-
- init(klass);
-
- E node;
-
- for (O o : beans) {
- node = builder.build(
- parent,
- getDecorator(o),
- getJXPath(o),
- getNavigationPath(o),
- ui,
- actionClass
- );
- if (cacheValues) {
- // cache the bean value to improve performance
- node.setBean(o);
- }
- }
- }
- }
}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -1,294 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jdesktop.swingx.JXTreeTable;
-
-import javax.swing.*;
-import javax.swing.tree.TreePath;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Enumeration;
-import java.util.regex.Pattern;
-
-/**
- * Helper object associated to a given navigation tree system.
- * <p/>
- * To helper is context safe (base on a {@link NavigationTreeContextHelper}.
- *
- * @author Letellier
- * @param <E> type of nodes in model
- * @see NavigationTreeModel
- * @since 2.0.1
- */
-public abstract class GenericNavigationHelper<E extends NavigationTreeNode> extends NavigationTreeContextHelper<E> {
-
- /** Logger */
- static private final Log log =
- LogFactory.getLog(NavigationTreeHelper.class);
-
- /**
- * Create the model.
- *
- * @param context the context to associate with fresh model
- * @return the new model build with data from the given context
- */
- public abstract NavigationModel<E> createTreeModel(JAXXContext context);
-
- /**
- * Create the tree handler.
- *
- * @param context the context to associate with fresh handler
- * @return the new handler
- */
- public abstract NavigationTreeHandler createTreeHandler(JAXXObject context);
-
- public GenericNavigationHelper(String contextPrefix) {
- super(contextPrefix);
- }
-
- public Object getContextValue(JAXXContext context, String path)
- throws InvocationTargetException, NoSuchMethodException,
- IllegalAccessException {
- NavigationModel<E> treeModel = getSafeModel(context);
- return treeModel.getBean(path);
- }
-
- public E findNode(JAXXContext context, String path) {
- NavigationModel<E> treeModel = getSafeModel(context);
- return treeModel.findNode(path);
- }
-
- public E findNode(JAXXContext context, String path,
- String regex) {
- NavigationModel<E> treeModel = getSafeModel(context);
- return treeModel.findNode(path, regex);
- }
-
- public E findNode(JAXXContext context, String path,
- Pattern regex) {
-
- NavigationModel<E> treeModel = getSafeModel(context);
- return treeModel.findNode(path, regex);
- }
-
- public E findNode(JAXXContext context, String path,
- String regex, String suffix) {
-
- NavigationModel<E> treeModel = getSafeModel(context);
-
- E node = treeModel.findNode(path, regex);
- if (node != null && suffix != null) {
- node = treeModel.findNode(node, suffix);
- }
- return node;
- }
-
- public E findNode(JAXXContext context, String path,
- Pattern regex, String suffix) {
-
- NavigationModel<E> treeModel = getSafeModel(context);
-
- E node = treeModel.findNode(path, regex);
- if (node != null && suffix != null) {
- node = treeModel.findNode(node, suffix);
- }
- return node;
- }
-
- /**
- * Sélection d'un noeud dans l'arbre de navigation à partir de son path.
- *
- * @param context le contexte applicatif
- * @param path le path absolue du noeud dans l'arbre
- */
- public void selectNode(JAXXContext context, String path) {
- E node = findNode(context, path);
- if (log.isDebugEnabled()) {
- log.debug(path + " :: " + node);
- }
- if (node != null) {
- selectNode(context, node);
- }
- }
-
- /**
- * Sélection d'un noeud dans l'arbre de navigation.
- *
- * @param context le contexte applicatif
- * @param node le noeud à sélectionner dans l'arbre
- */
- public void selectNode(JAXXContext context, E node) {
-
-
- NavigationModel<E> navigationModel = getSafeModel(context);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- TreePath path = new TreePath(navigationModel.getPathToRoot(node));
- JTree tree = getTree(context);
- if (tree == null) {
- // FIXME : Refactor in other helper ?
- // If its JXTreeTable
- JXTreeTable treeTable = getSafeTreeTable(context);
- treeTable.getTreeSelectionModel().setSelectionPath(path);
- treeTable.scrollPathToVisible(path);
- return;
- }
- tree.setSelectionPath(path);
- tree.scrollPathToVisible(path);
- }
-
- /**
- * Sélection du parent du noeud selectionne dans l'arbre de navigation.
- *
- * @param context le contexte applicatif
- */
- public void gotoParentNode(JAXXContext context) {
-
- E node = getSelectedNode(context);
-
- if (node == null) {
- // pas de noeud selectionne
- throw new NullPointerException("no selected node in context");
- }
- node = (E) node.getParent();
-
- selectNode(context, node);
- }
-
- /**
- * Obtain the first ancestor with the matching internalClass
- *
- * @param current the node to test
- * @param beanClass the type of the internal class to seek of
- * @return the first ancestor node with the matching class or {@code null}
- * if not found
- */
- public E getParentNode(E current,
- Class<?> beanClass) {
- if (current == null) {
- // ancestor not found
- return null;
- }
- if (beanClass.isAssignableFrom(current.getInternalClass())) {
- // matching node
- return current;
- }
- // try in the parent of node
- return getParentNode((E) current.getParent(), beanClass);
- }
-
- /**
- * Sélection d'un fils du noeud selectionne dans l'arbre de navigation.
- *
- * @param context le contexte applicatif
- * @param childIndex index du fils a selectionner
- */
- public void gotoChildNode(JAXXContext context, int childIndex) {
-
- E node = getSelectedNode(context);
-
- if (node == null) {
- // pas de noeud selectionne
- throw new NullPointerException("no selected node in context");
- }
- node = (E) node.getChildAt(childIndex);
-
- selectNode(context, node);
- }
-
- /**
- * Demande une opération de repaint sur un noeud de l'arbre de navigation.
- * <p/>
- * <b>Note:</b> La descendance du noeud n'est pas repainte.
- *
- * @param context le contexte applicatif
- * @param node le noeud à repaindre
- */
- public void repaintNode(JAXXContext context, E node) {
- repaintNode(context, node, false);
- }
-
- /**
- * Demande une opération de repaint sur un noeud de l'arbre de navigation.
- * <p/>
- * <b>Note:</b> La descendance du noeud est repainte si le paramètre
- * <code>deep</code> est à <code>true</code>.
- *
- * @param context le contexte applicatif
- * @param node le noeud à repaindre
- * @param deep un flag pour activer la repainte de la descendance du
- * noeud
- */
- public void repaintNode(JAXXContext context, E node,
- boolean deep) {
- NavigationModel<E> navigationModel = getSafeModel(context);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- navigationModel.nodeChanged(node);
- if (deep) {
- // repaint childs nodes
- //todo we should only repaint necessary nodes ?
- Enumeration<?> e = node.children();
- while (e.hasMoreElements()) {
- E child = (E) e.nextElement();
- repaintNode(context, child, true);
- }
- }
- }
-
- public NavigationModel<E> getSafeModel(JAXXContext context)
- throws NullPointerException {
- NavigationModel<E> model = getModel(context);
- if (model == null) {
- throw new NullPointerException(
- "could not find tree model with key " +
- getModelContextEntry() + " in context " + context);
- }
- return model;
- }
-
- public JTree getSafeTree(JAXXContext context) throws NullPointerException {
- JTree tree = getTree(context);
- if (tree == null) {
- throw new NullPointerException(
- "could not find tree with key " + getTreeContextEntry() +
- " in context " + context);
- }
- return tree;
- }
-
- public JXTreeTable getSafeTreeTable(JAXXContext context)
- throws NullPointerException {
- JXTreeTable treeTable = getTreeTable(context);
- if (treeTable == null) {
- throw new NullPointerException(
- "could not find tree with key " +
- getTreeTableContextEntry() + " in context " + context);
- }
- return treeTable;
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -1,219 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.tree.DefaultTreeModel;
-import javax.swing.tree.TreeNode;
-import java.lang.reflect.Array;
-import java.util.Enumeration;
-import java.util.StringTokenizer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Model of the tree used for a navigation tree. It is composed of {@link E}
- * nodes.
- *
- * @author letellier
- * @since 2.0.1
- * @param <E> the type of nodes in model
- */
-public class GenericNavigationTreeModel<E extends NavigationTreeNode> extends DefaultTreeModel implements NavigationModel<E> {
-
- static private final long serialVersionUID = 1L;
-
- /** Logger */
- static private final Log log = LogFactory.getLog(NavigationTreeModel.class);
-
- /**
- * The path separator used to build the {@link NavigationTreeNode#fullPath}.
- *
- * @see NavigationTreeNode#getNodePath()
- * @see NavigationTreeNode#getFullPath()
- */
- protected final String pathSeparator;
-
- /** Context to retrieve beans */
- private JAXXContext context;
-
- public GenericNavigationTreeModel(String pathSeparator,
- JAXXContext context) {
- super(null);
- this.pathSeparator = pathSeparator;
- this.context = context;
- }
-
- @Override
- public E getRoot() {
- return (E) super.getRoot();
- }
-
- @Override
- public void setRoot(E root) {
- super.setRoot(root);
- }
-
- @Override
- public E findNode(String path) {
- return findNode(getRoot(), path, (Pattern) null);
- }
-
- @Override
- public E findNode(String path, String regex) {
- return findNode(getRoot(), path, regex);
- }
-
- @Override
- public E findNode(String path, Pattern regex) {
- return findNode(getRoot(), path, regex);
- }
-
- @Override
- public E findNode(E root, String path) {
- return findNode(root, path, (Pattern) null);
- }
-
- @Override
- public E findNode(E root, String path, String regex) {
- return findNode(root, path,
- regex == null ? null : Pattern.compile(regex));
- }
-
- @Override
- public E findNode(E root, String path, Pattern regex) {
- if (regex != null) {
- Matcher matcher = regex.matcher(path);
- if (!matcher.matches() || matcher.groupCount() < 1) {
- log.warn("no matching regex " + regex + " to " + path);
- return null;
- }
- path = matcher.group(1);
- if (log.isDebugEnabled()) {
- log.debug("matching regex " + regex + " : " + path);
- }
- }
- StringTokenizer stk = new StringTokenizer(path, pathSeparator);
- E result = root;
- // pas the first token (matches the root node)
- if (root.isRoot() && stk.hasMoreTokens()) {
- String rootPath = stk.nextToken();
- if (!rootPath.equals(root.getNodePath())) {
- return null;
- }
- }
- while (stk.hasMoreTokens()) {
- result = (E) result.getChild(stk.nextToken());
- }
- return result;
- }
-
- @Override
- public JAXXContext getContext() {
- return context;
- }
-
- @Override
- public Object getBean(String navigationPath) {
- Object result;
- E node = findNode(navigationPath, (Pattern) null);
- result = getBean(node);
- return result;
- }
-
- @Override
- public Object getBean(E node) {
- if (node == null) {
- return null;
- //fixme should throw a NPE exception
- //throw new NullPointerException("node can not be null");
- }
- return node.getBean(getContext());
- }
-
- @Override
- public void nodeChanged(E node) {
- nodeChanged(node, false);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- }
-
- @Override
- public void nodeStructureChanged(E node) {
- E n = node;
- //TC-20091004 never launch a deep reload
- reload(n, true);
- super.nodeStructureChanged(node);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- }
-
- @Override
- public void nodeChanged(E node, boolean deep) {
-
- E n = node;
- //TC-20091004 never launch a deep clean, since we do a deep nodeChanged.
- reload(n, deep);
- super.nodeChanged(node);
- }
-
- @Override
- public String getPathSeparator() {
- return pathSeparator;
- }
-
- protected void reload(E node) {
- reload(node, false);
- }
-
- protected void reload(E node, boolean deep) {
- if (node == null) {
- return;
- }
- node.reload(getContext());
-
- if (deep) {
- Enumeration<?> childs = node.children();
- while (childs.hasMoreElements()) {
- E o = (E) childs.nextElement();
- reload(o, true);
- }
- }
- }
-
- @Override
- public E[] getPathToRoot(E aNode) {
- TreeNode[] treeNodes = super.getPathToRoot(aNode);
- E[] result = (E[]) Array.newInstance(aNode.getClass(),treeNodes.length);
- System.arraycopy(treeNodes,0,result,0,treeNodes.length);
- return result;
- }
-
- @Override
- public void removeNodeFromParent(E node) {
- super.removeNodeFromParent(node);
- }
-}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -28,17 +28,17 @@
* @author chemit
* @since 2.0.0
*/
-public interface NavigationContentUI {
+public interface NavigationContentUI<E extends NavigationNode<E>> {
/**
* Init the ui just before been opened by the method {@link
- * NavigationTreeHandler#openUI(Component, NavigationTreeNode)}.
+ * NavigationTreeHandler#openUI(Component, NavigationNode)}.
*
* @param node the selected node associated to the ui
* @throws Exception if any pb while opening the content's ui
- * @see NavigationTreeHandler#openUI(Component, NavigationTreeNode)
+ * @see NavigationTreeHandler#openUI(Component, NavigationNode)
*/
- void openUI(NavigationTreeNode node) throws Exception;
+ void openUI(E node) throws Exception;
/**
* Clean the ui after been closed by the method {@link
@@ -48,5 +48,5 @@
* @throws Exception if any pb when closing the content'sui
* @see NavigationTreeHandler#closeUI(Component)
*/
- void closeUI(NavigationTreeNode node) throws Exception;
+ void closeUI(E node) throws Exception;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -22,8 +22,8 @@
import jaxx.runtime.JAXXContext;
-import javax.swing.tree.TreeModel;
-import javax.swing.tree.TreeNode;
+import javax.swing.event.TreeModelListener;
+import javax.swing.tree.TreePath;
import java.util.regex.Pattern;
/**
@@ -34,13 +34,14 @@
* @author sletellier
* @since 2.0.0
*/
-public interface NavigationModel<E extends NavigationTreeNode> extends TreeModel {
+public interface NavigationModel<E extends NavigationNode<E>> {
+//public interface NavigationModel<E extends NavigationNode<E>> extends TreeModel {
E getRoot();
void setRoot(E root);
- TreeNode[] getPathToRoot(E aNode);
+ E[] getPathToRoot(E aNode);
void removeNodeFromParent(E node);
@@ -164,4 +165,92 @@
void nodeChanged(E node, boolean deep);
String getPathSeparator();
+
+ /**
+ * Returns the child of <code>parent</code> at index <code>index</code>
+ * in the parent's
+ * child array. <code>parent</code> must be a node previously obtained
+ * from this data source. This should not return <code>null</code>
+ * if <code>index</code>
+ * is a valid index for <code>parent</code> (that is <code>index >= 0 &&
+ * index < getChildCount(parent</code>)).
+ *
+ * @param parent a node in the tree, obtained from this data source
+ * @return the child of <code>parent</code> at index <code>index</code>
+ */
+ Object getChild(Object parent, int index);
+
+
+ /**
+ * Returns the number of children of <code>parent</code>.
+ * Returns 0 if the node
+ * is a leaf or if it has no children. <code>parent</code> must be a node
+ * previously obtained from this data source.
+ *
+ * @param parent a node in the tree, obtained from this data source
+ * @return the number of children of the node <code>parent</code>
+ */
+ int getChildCount(Object parent);
+
+
+ /**
+ * Returns <code>true</code> if <code>node</code> is a leaf.
+ * It is possible for this method to return <code>false</code>
+ * even if <code>node</code> has no children.
+ * A directory in a filesystem, for example,
+ * may contain no files; the node representing
+ * the directory is not a leaf, but it also has no children.
+ *
+ * @param node a node in the tree, obtained from this data source
+ * @return true if <code>node</code> is a leaf
+ */
+ boolean isLeaf(Object node);
+
+ /**
+ * Messaged when the user has altered the value for the item identified
+ * by <code>path</code> to <code>newValue</code>.
+ * If <code>newValue</code> signifies a truly new value
+ * the model should post a <code>treeNodesChanged</code> event.
+ *
+ * @param path path to the node that the user has altered
+ * @param newValue the new value from the TreeCellEditor
+ */
+ void valueForPathChanged(TreePath path, Object newValue);
+
+ /**
+ * Returns the index of child in parent. If either <code>parent</code>
+ * or <code>child</code> is <code>null</code>, returns -1.
+ * If either <code>parent</code> or <code>child</code> don't
+ * belong to this tree model, returns -1.
+ *
+ * @param parent a node in the tree, obtained from this data source
+ * @param child the node we are interested in
+ * @return the index of the child in the parent, or -1 if either
+ * <code>child</code> or <code>parent</code> are <code>null</code>
+ * or don't belong to this tree model
+ */
+ int getIndexOfChild(Object parent, Object child);
+
+//
+// Change Events
+//
+
+ /**
+ * Adds a listener for the <code>TreeModelEvent</code>
+ * posted after the tree changes.
+ *
+ * @param l the listener to add
+ * @see #removeTreeModelListener
+ */
+ void addTreeModelListener(TreeModelListener l);
+
+ /**
+ * Removes a listener previously added with
+ * <code>addTreeModelListener</code>.
+ *
+ * @see #addTreeModelListener
+ * @param l the listener to remove
+ */
+ void removeTreeModelListener(TreeModelListener l);
+
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -32,7 +32,7 @@
* @author sletellier
* @since 2.0.0
*/
-public interface NavigationModelBuilder<E extends NavigationTreeNode> {
+public interface NavigationModelBuilder<E extends NavigationNode<E>> {
NavigationModel<E> getModel();
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-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -30,7 +30,7 @@
* @author sletellier
* @since 2.0.1
*/
-public interface NavigationMultiContentUI extends NavigationContentUI {
+public interface NavigationMultiContentUI<E extends NavigationNode<E>> extends NavigationContentUI<E> {
/**
* Init the ui just before been opened by the method {@link
@@ -39,7 +39,7 @@
* @param nodes the selected node associated to the ui
* @throws Exception if any pb while opening the content's ui
*/
- void openUI(List<NavigationTreeNode> nodes) throws Exception;
+ void openUI(List<E> nodes) throws Exception;
/**
* Clean the ui after been closed by the method {@link
@@ -49,5 +49,5 @@
* @throws Exception if any pb when closing the content'sui
* @see NavigationTreeHandler#closeUI(Component)
*/
- void closeUI(List<NavigationTreeNode> nodes) throws Exception;
+ void closeUI(List<E> nodes) throws Exception;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -44,7 +44,7 @@
* @author sletellier
* @since 2.0.1
*/
-public abstract class NavigationMultiTreeHandler extends NavigationTreeHandler {
+public abstract class NavigationMultiTreeHandler<E extends NavigationNode<E>> extends NavigationTreeHandler<E> {
/** Logger */
static private final Log log =
@@ -65,14 +65,13 @@
TreePath[] paths = event.getPaths();
// TODO : verifier que la selection n'est pas la même
- List<NavigationTreeNode> nodes = new ArrayList<NavigationTreeNode>();
+ List<E> nodes = new ArrayList<E>();
if (paths == null) {
- selectNodeUI(new ArrayList<NavigationTreeNode>());
+ selectNodeUI(new ArrayList<E>());
return;
}
for (TreePath path : paths) {
- NavigationTreeNode node =
- (NavigationTreeNode) path.getLastPathComponent();
+ E node = (E) path.getLastPathComponent();
nodes.add(node);
if (log.isDebugEnabled()) {
log.debug("Adding path : " + path);
@@ -90,7 +89,7 @@
* @throws Exception if any
*/
protected abstract void openUI(Component newUI,
- List<NavigationTreeNode> nodes)
+ List<E> nodes)
throws Exception;
/**
@@ -100,25 +99,25 @@
* @return la nouvelle ui associée au noeud
* @throws Exception if any
*/
- protected abstract Component createUI(List<NavigationTreeNode> nodes)
+ protected abstract Component createUI(List<E> nodes)
throws Exception;
/**
* @param nodes les noeuds associés à l'ui à retrouver
* @return l'ui associés au nouveau noeud sélectionné
*/
- protected abstract Component getUI(List<NavigationTreeNode> nodes);
+ protected abstract Component getUI(List<E> nodes);
- protected void selectNodeUI(List<NavigationTreeNode> nodes) {
+ protected void selectNodeUI(List<E> nodes) {
log.info("select nodes " + nodes);
try {
- List<String> paths = new ArrayList<String>();
+// List<String> paths = new ArrayList<String>();
List<Object> beans = new ArrayList<Object>();
- for (NavigationTreeNode node : nodes) {
+ for (E node : nodes) {
String path = node.getFullPath();
- paths.add(path);
+// paths.add(path);
if (log.isTraceEnabled()) {
log.trace(path);
@@ -134,7 +133,7 @@
// save it in context (must be done before init ui)
JAXXContext ctxt = getContext();
- NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper();
+ NavigationTreeContextHelper<E> helper = getContextHelper();
// remove previous selected bean
//TODO-TC-20091004 should have an automatic clean context method
@@ -162,8 +161,8 @@
// really open the ui associated with the selected node
// init ui before to be visible
- if (newUI instanceof NavigationMultiContentUI) {
- ((NavigationMultiContentUI) newUI).openUI(nodes);
+ if (newUI instanceof NavigationMultiContentUI<?>) {
+ ((NavigationMultiContentUI<E>) newUI).openUI(nodes);
}
// set ui in content
@@ -177,9 +176,9 @@
}
}
- protected List<String> getPaths(List<NavigationTreeNode> nodes) {
+ protected List<String> getPaths(List<E> nodes) {
List<String> result = new ArrayList<String>();
- for (NavigationTreeNode node : nodes) {
+ for (E node : nodes) {
result.add(node.getFullPath());
}
return result;
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -0,0 +1,91 @@
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXContextEntryDef;
+
+import java.io.Serializable;
+import java.util.Enumeration;
+
+public interface NavigationNode<E extends NavigationNode<E>> extends Cloneable, Serializable {
+// public interface NavigationNode<E extends NavigationNode<E>> extends Cloneable, MutableTreeNode, Serializable {
+ NavigationTreeNodeRenderer getRenderer();
+
+ void setRenderer(NavigationTreeNodeRenderer renderer);
+
+ String getPathSeparator();
+
+ String getNodePath();
+
+ void setNodePath(String navigationPath);
+
+ Class<? extends JAXXObject> getUIClass();
+
+ void setUIClass(Class<? extends JAXXObject> uIClass);
+
+ void setInternalClass(Class<?> internalClass);
+
+ Class<? extends JAXXAction> getUIHandlerClass();
+
+ void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass);
+
+ JAXXContextEntryDef<?> getJaxxContextEntryDef();
+
+ void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef);
+
+ String getJaxxContextEntryPath();
+
+ void setJaxxContextEntryPath(String jaxxContextEntryPath);
+
+ Class<?> getInternalClass();
+
+ String getFullPath();
+
+ E getChildAt(int index);
+
+ E getParent();
+
+ E getChild(String path);
+
+ Object getBean();
+
+ void setBean(Object bean);
+
+ void reload(JAXXContext context);
+
+ Object getBean(JAXXContext context);
+
+ void insert(E child, int index);
+
+ void remove(int index);
+
+ void remove(E node);
+
+ void setUserObject(Object object);
+
+ void removeFromParent();
+
+ void setParent(E newParent);
+
+ int getChildCount();
+
+ int getIndex(E node);
+
+ boolean getAllowsChildren();
+
+ boolean isLeaf();
+
+ Enumeration<? extends E> children();
+
+ boolean isRoot();
+
+ Object getUserObject();
+
+ void add(E node);
+
+ E[] getPathToRoot(E aNode, int depth) ;
+
+ E[] getPath();
+
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationNode.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -40,7 +40,7 @@
* @author sletellier
* @since 2.0.1
*/
-public abstract class NavigationOneClicSelectionHandler extends NavigationMultiTreeHandler {
+public abstract class NavigationOneClicSelectionHandler<E extends NavigationNode<E>> extends NavigationMultiTreeHandler<E> {
/** Logger */
static private final Log log =
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-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -64,7 +64,7 @@
* @author chemit
* @since 1.7.2
*/
-public class NavigationTreeContextHelper <E extends NavigationTreeNode> {
+public class NavigationTreeContextHelper <E extends NavigationNode<E>> {
/**
* Logger
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -20,22 +20,23 @@
*/
package jaxx.runtime.swing.navigation;
-import java.awt.Component;
-import java.util.Arrays;
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
-import javax.swing.tree.DefaultTreeSelectionModel;
-import javax.swing.tree.TreePath;
import jaxx.runtime.JAXXAction;
import jaxx.runtime.JAXXContext;
-import jaxx.runtime.context.JAXXInitialContext;
import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXInitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.DefaultTreeSelectionModel;
+import javax.swing.tree.TreePath;
+import java.awt.*;
+import java.util.Arrays;
+
/**
* The handler of a navigation tree.
- *
+ * <p/>
* This is also the selection model to use, since we must check before moving
* from a node we can not just listen selection model changed, we must control
* it.
@@ -43,52 +44,48 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 1.7.2
*/
-public abstract class NavigationTreeHandler extends DefaultTreeSelectionModel implements TreeSelectionListener{
+public abstract class NavigationTreeHandler<E extends NavigationNode<E>> extends DefaultTreeSelectionModel implements TreeSelectionListener {
private static final long serialVersionUID = 1L;
- /**
- * Logger
- */
+
+ /** Logger */
static private final Log log = LogFactory.getLog(NavigationTreeHandler.class);
/**
* Strategy of instanciation of ui.
* <p/>
- * For a given {@code node}, the method {@link #getId(NavigationTreeNode)}
+ * For a given {@code node}, the method {@link #getId(NavigationNode)}
* returns the id of ui to use.
*/
public enum Strategy {
- /**
- * instanciate a ui for a node
- */
+ /** instanciate a ui for a node */
PER_NODE {
@Override
- public String getId(NavigationTreeNode node) {
+ public String getId(NavigationNode<?> node) {
return node.getFullPath();
}
},
/**
- * instanciate only one a ui for a type,nodes will share the instanciation
+ * instanciate only one a ui for a type,nodes will share the
+ * instanciation
*/
PER_UI_TYPE {
@Override
- public String getId(NavigationTreeNode node) {
+ public String getId(NavigationNode<?> node) {
return node.getUIClass().getName();
}
};
- public abstract String getId(NavigationTreeNode node);
+ public abstract String getId(NavigationNode<?> node);
}
- /**
- * UI which contains navigation tree
- */
+
+ /** UI which contains navigation tree */
protected JAXXContext context;
- /**
- * UI Instanciation strategy
- */
+
+ /** UI Instanciation strategy */
protected Strategy strategy;
/**
@@ -96,10 +93,10 @@
*
* @since 1.7.2
*/
- protected NavigationTreeContextHelper<NavigationTreeNode> contextHelper;
+ protected NavigationTreeContextHelper<E> contextHelper;
protected NavigationTreeHandler(String contextPrefix, JAXXObject context, Strategy strategy) {
- contextHelper = new NavigationTreeContextHelper<NavigationTreeNode>(contextPrefix);
+ contextHelper = new NavigationTreeContextHelper<E>(contextPrefix);
this.context = context;
this.strategy = strategy;
addTreeSelectionListener(this);
@@ -107,7 +104,7 @@
@Override
public void valueChanged(TreeSelectionEvent event) {
- if (log.isDebugEnabled()){
+ if (log.isDebugEnabled()) {
log.debug("Value changed for path : " + event.getPath());
log.debug("Old lead selection path : " + event.getOldLeadSelectionPath());
}
@@ -115,18 +112,16 @@
// do not treate this if no path changed
return;
}
- NavigationTreeNode node = (NavigationTreeNode) event.getPath().getLastPathComponent();
+ E node = (E) event.getPath().getLastPathComponent();
selectNodeUI(node);
}
- /**
- * @return le modèle de navigation associé
- */
+ /** @return le modèle de navigation associé */
protected abstract NavigationModel<?> getNavigationTreeModel();
/**
- * @return le composent actuellement visible associé au noeud courant ou
- * au noeud précédent lors d'un changement de noeud.
+ * @return le composent actuellement visible associé au noeud courant ou au
+ * noeud précédent lors d'un changement de noeud.
*/
protected abstract Component getCurrentUI();
@@ -134,11 +129,12 @@
* @param node le noeud associé à l'ui à retrouver
* @return l'ui associé au novueau noeud sélectionné
*/
- protected abstract Component getUI(NavigationTreeNode node);
+ protected abstract Component getUI(E node);
/**
* @param component le composent actuellement visible
- * @return <code>true</code> si le composent a bien été fermé, <code>false</code> sinon
+ * @return <code>true</code> si le composent a bien été fermé,
+ * <code>false</code> sinon
* @throws Exception if any
*/
protected abstract boolean closeUI(Component component) throws Exception;
@@ -150,7 +146,7 @@
* @return la nouvelle ui associée au noeud
* @throws Exception if any
*/
- protected abstract Component createUI(NavigationTreeNode node) throws Exception;
+ protected abstract Component createUI(E node) throws Exception;
/**
* Ouvre l'ui associée au noeud sélectionné dans l'arbre de navigation.
@@ -159,12 +155,12 @@
* @param node le node de l'ui a ouvrir
* @throws Exception if any
*/
- protected abstract void openUI(Component newUI, NavigationTreeNode node) throws Exception;
+ protected abstract void openUI(Component newUI, E node) throws Exception;
/**
* Traitement des exceptions.
*
- * @param e l'erreur recontrée (ou null si pas d"erreur)
+ * @param e l'erreur recontrée (ou null si pas d"erreur)
*/
protected abstract void treateError(Exception e);
@@ -172,7 +168,7 @@
return context;
}
- public NavigationTreeContextHelper<NavigationTreeNode> getContextHelper() {
+ public NavigationTreeContextHelper<E> getContextHelper() {
return contextHelper;
}
@@ -195,8 +191,8 @@
// can not changed current node
return;
}
- if (component instanceof NavigationContentUI) {
- ((NavigationContentUI) component).closeUI((NavigationTreeNode) path.getLastPathComponent());
+ if (component instanceof NavigationContentUI<?>) {
+ ((NavigationContentUI<E>) component).closeUI((E) path.getLastPathComponent());
}
} catch (Exception ex) {
treateError(ex);
@@ -216,7 +212,7 @@
if (Arrays.equals(paths, getSelectionPaths())) {
// stay on same node, can skip
if (log.isDebugEnabled()) {
- log.debug("skip stay on path " + paths);
+ log.debug("skip stay on path " + Arrays.toString(paths));
}
return;
}
@@ -230,10 +226,10 @@
// can not changed current node
return;
}
- if (component instanceof NavigationMultiContentUI) {
- if (paths.length == 1){
- NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper();
- ((NavigationMultiContentUI) component).closeUI(helper.getSelectedNodes(getContext()));
+ if (component instanceof NavigationMultiContentUI<?>) {
+ if (paths.length == 1) {
+ NavigationTreeContextHelper<E> helper = getContextHelper();
+ ((NavigationMultiContentUI<E>) component).closeUI(helper.getSelectedNodes(getContext()));
}
}
} catch (Exception ex) {
@@ -247,7 +243,7 @@
super.setSelectionPaths(paths);
}
- protected void selectNodeUI(NavigationTreeNode node) {
+ protected void selectNodeUI(E node) {
try {
@@ -274,7 +270,7 @@
}
JAXXContext ctxt = getContext();
- NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper();
+ NavigationTreeContextHelper<E> helper = getContextHelper();
// save in context current node context path
helper.setSelectedPath(ctxt, node.getFullPath());
@@ -287,8 +283,8 @@
// really open the ui associated with the selected node
// init ui before to be visible
- if (newUI instanceof NavigationContentUI) {
- ((NavigationContentUI) newUI).openUI(node);
+ if (newUI instanceof NavigationContentUI<?>) {
+ ((NavigationContentUI<E>) newUI).openUI(node);
}
// set ui in content
@@ -309,7 +305,7 @@
* @return le context à utiliser pour instancier l'ui
* @throws Exception if any
*/
- protected JAXXContext createUIContext(NavigationTreeNode node) throws Exception {
+ protected JAXXContext createUIContext(E node) throws Exception {
if (node.getUIHandlerClass() == null) {
if (log.isWarnEnabled()) {
@@ -326,13 +322,13 @@
return uiContext;
}
- protected void addSelectedBeanInContext(NavigationTreeNode node, Object data) {
+ protected void addSelectedBeanInContext(E node, Object data) {
if (log.isDebugEnabled()) {
log.debug("find data for contextPath <" + node.getFullPath() + "> : " + (data == null ? null : data.getClass()));
}
JAXXContext ctxt = getContext();
- NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper();
+ NavigationTreeContextHelper<E> helper = getContextHelper();
// remove previous selected bean
//TODO-TC-20091004 should have an automatic clean context method while
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -42,7 +42,7 @@
*
* @author chemit
*/
-public abstract class NavigationTreeHandlerWithCardLayout extends NavigationTreeHandler {
+public abstract class NavigationTreeHandlerWithCardLayout<E extends NavigationNode<E>> extends NavigationTreeHandler<E> {
/** Logger */
static private final Log log = LogFactory.getLog(NavigationTreeHandlerWithCardLayout.class);
@@ -86,7 +86,7 @@
}
@Override
- protected Component getUI(NavigationTreeNode node) {
+ protected Component getUI(E node) {
CardLayout2 layout = getContentLayout();
JPanel container = getContentContainer();
String constraints = strategy.getId(node);
@@ -95,7 +95,7 @@
}
@Override
- protected void openUI(Component newUI, NavigationTreeNode node) throws
+ protected void openUI(Component newUI, E node) throws
Exception {
CardLayout2 layout = getContentLayout();
@@ -112,7 +112,7 @@
}
@Override
- protected Component createUI(NavigationTreeNode node) throws Exception {
+ protected Component createUI(E node) throws Exception {
JAXXContext uiContext = createUIContext(node);
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -27,9 +27,9 @@
*
* @author chemit
* @since 1.7.2
- * @see NavigationTreeModel
+ * @see NavigationTreeNodeModel
*/
-public abstract class NavigationTreeHelper extends GenericNavigationHelper<NavigationTreeNode> {
+public abstract class NavigationTreeHelper extends AbstractNavigationHelper<NavigationTreeNode> {
protected NavigationTreeHelper(String contextPrefix) {
super(contextPrefix);
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -1,40 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXContext;
-
-/**
- * Model of the tree used for a navigation tree.
- * <p/>
- * Il est composé de {@link NavigationTreeNode}
- *
- * @author chemit
- * @since 1.7.2
- */
-public class NavigationTreeModel extends GenericNavigationTreeModel<NavigationTreeNode> {
-
- private static final long serialVersionUID = 1L;
-
- public NavigationTreeModel(String pathSeparator, JAXXContext context) {
- super(pathSeparator, context);
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -1,90 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXAction;
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * This object is design to build a {@link NavigationTreeModel}.
- *
- * @author chemit
- * @see NavigationModelBuilder
- * @since 17.2
- */
-public class NavigationTreeModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeNode> {
-
- /** Logger */
- static private final Log log =
- LogFactory.getLog(NavigationTreeModelBuilder.class);
-
- public NavigationTreeModelBuilder(
- String pathSeparator,
- JAXXContext context,
- Class<? extends JAXXObject> defaultUIClass,
- Class<? extends JAXXAction> defaultUIHandlerClass) {
- this(defaultUIClass,
- defaultUIHandlerClass,
- new NavigationTreeModel(pathSeparator, context)
- );
- }
-
- @Override
- public NavigationTreeModel getModel() {
- return (NavigationTreeModel) super.getModel();
- }
-
- public NavigationTreeModelBuilder(
- Class<? extends JAXXObject> defaultUIClass,
- Class<? extends JAXXAction> defaultUIHandlerClass,
- NavigationTreeModel model) {
- super(defaultUIClass, defaultUIHandlerClass, model);
- }
-
- @Override
- public NavigationTreeNode createNavigationTreeNode(
- String pathSeparator,
- String contextName,
- JAXXContextEntryDef<?> jaxxContextEntryDef,
- String jaxxContextEntryPath) {
- return new NavigationTreeNode(
- pathSeparator,
- contextName,
- jaxxContextEntryDef,
- jaxxContextEntryPath
- );
- }
-
-// // TODO : to remove
-// /**
-// * @deprecated please use NavigationModel for return type
-// * @return the tree model
-// */
-// @Override
-// @Deprecated
-// public NavigationTreeModel getModel() {
-// return (NavigationTreeModel)super.getModel();
-// }
-}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -33,7 +33,7 @@
import java.util.Enumeration;
/**
- * Node of the {@link NavigationTreeModel}.
+ * Node of the {@link NavigationTreeNodeModel}.
* <p/>
* Each node is associated with : <ul> <li> a {@code bean} coming from a {@link
* JAXXContext} </li> <li> a {@code uiClass} to build the associated ui </li>
@@ -61,11 +61,11 @@
* {@link NavigationTreeNodeRenderer#reload(Object)} method.
*
* @author chemit
- * @see NavigationTreeModel
+ * @see NavigationTreeNodeModel
* @see NavigationTreeNodeRenderer
* @since 1.7.2
*/
-public class NavigationTreeNode extends DefaultMutableTreeNode {
+public class NavigationTreeNode extends DefaultMutableTreeNode implements NavigationNode<NavigationTreeNode> {
private static final long serialVersionUID = 1L;
@@ -115,7 +115,7 @@
* The UI class associated with the node.
* <p/>
* This class can be {@code null}, in that case, the {@link
- * NavigationTreeModelBuilder#defaultUIClass} will be used while building
+ * NavigationTreeNodeModelBuilder#defaultUIClass} will be used while building
* the model.
*/
protected Class<? extends JAXXObject> uIClass;
@@ -124,7 +124,7 @@
* The UI handler class associated with the node.
* <p/>
* This class can be {@code null}, in that case, the {@link
- * NavigationTreeModelBuilder#defaultUIHandlerClass} will be used while
+ * NavigationTreeNodeModelBuilder#defaultUIHandlerClass} will be used while
* building the model.
*/
protected Class<? extends JAXXAction> uIHandlerClass;
@@ -192,6 +192,7 @@
}
/** @return the text node renderer (store in {@link #userObject} property. */
+ @Override
public NavigationTreeNodeRenderer getRenderer() {
NavigationTreeNodeRenderer render = null;
Object o = getUserObject();
@@ -201,60 +202,74 @@
return render;
}
+ @Override
public void setRenderer(NavigationTreeNodeRenderer renderer) {
// clear all cache
bean = null;
setUserObject(renderer);
}
+ @Override
public String getPathSeparator() {
return pathSeparator;
}
+ @Override
public String getNodePath() {
return path;
}
+ @Override
public void setNodePath(String navigationPath) {
path = navigationPath;
}
+ @Override
public Class<? extends JAXXObject> getUIClass() {
return uIClass;
}
+ @Override
public void setUIClass(Class<? extends JAXXObject> uIClass) {
this.uIClass = uIClass;
}
+ @Override
public void setInternalClass(Class<?> internalClass) {
this.internalClass = internalClass;
}
+ @Override
public Class<? extends JAXXAction> getUIHandlerClass() {
return uIHandlerClass;
}
+ @Override
public void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass) {
this.uIHandlerClass = uIHandlerClass;
}
+ @Override
public JAXXContextEntryDef<?> getJaxxContextEntryDef() {
return jaxxContextEntryDef;
}
+ @Override
public void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef) {
this.jaxxContextEntryDef = jaxxContextEntryDef;
}
+ @Override
public String getJaxxContextEntryPath() {
return jaxxContextEntryPath;
}
+ @Override
public void setJaxxContextEntryPath(String jaxxContextEntryPath) {
this.jaxxContextEntryPath = jaxxContextEntryPath;
}
+ @Override
public Class<?> getInternalClass() {
if (internalClass == null && getRenderer() != null) {
return getRenderer().getInternalClass();
@@ -263,6 +278,7 @@
}
/** @return the fully context path of the node from the root node to this. */
+ @Override
public String getFullPath() {
if (fullPath == null) {
StringBuilder sb = new StringBuilder();
@@ -290,10 +306,11 @@
* this node.
* @return the child of this node with given {@link #path} value.
*/
+ @Override
public NavigationTreeNode getChild(String path) {
- Enumeration<?> childs = children();
+ Enumeration<? extends NavigationTreeNode> childs = children();
while (childs.hasMoreElements()) {
- NavigationTreeNode son = (NavigationTreeNode) childs.nextElement();
+ NavigationTreeNode son = childs.nextElement();
if (path.equals(son.getNodePath())) {
return son;
}
@@ -301,14 +318,17 @@
return null;
}
+ @Override
public Object getBean() {
return bean;
}
+ @Override
public void setBean(Object bean) {
this.bean = bean;
}
+ @Override
public void reload(JAXXContext context) {
// clear bean cache
@@ -343,6 +363,7 @@
* @param context the context to seek
* @return the value associated in context with the given context path
*/
+ @Override
public Object getBean(JAXXContext context) {
if (bean != null) {
// use cached bean
@@ -413,6 +434,31 @@
return result;
}
+ @Override
+ public void insert(NavigationTreeNode child, int index) {
+ super.insert(child, index);
+ }
+
+ @Override
+ public void remove(NavigationTreeNode node) {
+ super.remove(node);
+ }
+
+ @Override
+ public void setParent(NavigationTreeNode newParent) {
+ super.setParent(newParent);
+ }
+
+ @Override
+ public int getIndex(NavigationTreeNode node) {
+ return super.getIndex(node);
+ }
+
+ @Override
+ public Enumeration<? extends NavigationTreeNode> children() {
+ return super.children();
+ }
+
/**
* @return the first ancestor with a none null {@link #jaxxContextEntryDef}
* or <code>null</code> if none find..
@@ -429,7 +475,7 @@
}
protected String computeJXPath(String expr, NavigationTreeNode parentNode) {
- if (this == parentNode) {
+ if (equals(parentNode)) {
// reach the parent limit node, return the expr computed
return expr;
}
@@ -480,4 +526,26 @@
);
return ancestor.computeJXPath(newExpr, parentNode);
}
+
+ @Override
+ public void add(NavigationTreeNode node) {
+ super.add(node);
+ }
+
+
+ @Override
+ public NavigationTreeNode[] getPath() {
+ TreeNode[] treeNodes = super.getPath();
+ NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length];
+ System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
+ return result;
+ }
+
+ @Override
+ public NavigationTreeNode[] getPathToRoot(NavigationTreeNode aNode, int depth) {
+ TreeNode[] treeNodes = super.getPathToRoot(aNode, depth);
+ NavigationTreeNode[] result = new NavigationTreeNode[treeNodes.length];
+ System.arraycopy(treeNodes, 0, result, 0, treeNodes.length);
+ return result;
+ }
}
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -0,0 +1,40 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXContext;
+
+/**
+ * Model of the tree used for a navigation tree.
+ * <p/>
+ * Il est composé de {@link NavigationTreeNode}
+ *
+ * @author chemit
+ * @since 1.7.2
+ */
+public class NavigationTreeNodeModel extends AbstractNavigationModel<NavigationTreeNode> {
+
+ private static final long serialVersionUID = 1L;
+
+ public NavigationTreeNodeModel(String pathSeparator, JAXXContext context) {
+ super(pathSeparator, context);
+ }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModel.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Copied: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java (from rev 1809, trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java)
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -0,0 +1,90 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXContextEntryDef;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This object is design to build a {@link NavigationTreeNodeModel}.
+ *
+ * @author chemit
+ * @see NavigationModelBuilder
+ * @since 17.2
+ */
+public class NavigationTreeNodeModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeNode> {
+
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(NavigationTreeNodeModelBuilder.class);
+
+ public NavigationTreeNodeModelBuilder(
+ String pathSeparator,
+ JAXXContext context,
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass) {
+ this(defaultUIClass,
+ defaultUIHandlerClass,
+ new NavigationTreeNodeModel(pathSeparator, context)
+ );
+ }
+
+ @Override
+ public NavigationTreeNodeModel getModel() {
+ return (NavigationTreeNodeModel) super.getModel();
+ }
+
+ public NavigationTreeNodeModelBuilder(
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass,
+ NavigationTreeNodeModel model) {
+ super(defaultUIClass, defaultUIHandlerClass, model);
+ }
+
+ @Override
+ public NavigationTreeNode createNavigationTreeNode(
+ String pathSeparator,
+ String contextName,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
+ return new NavigationTreeNode(
+ pathSeparator,
+ contextName,
+ jaxxContextEntryDef,
+ jaxxContextEntryPath
+ );
+ }
+
+// // TODO : to remove
+// /**
+// * @deprecated please use NavigationModel for return type
+// * @return the tree model
+// */
+// @Override
+// @Deprecated
+// public NavigationTreeNodeModel getModel() {
+// return (NavigationTreeNodeModel)super.getModel();
+// }
+}
Property changes on: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeModelBuilder.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL
Added: svn:mergeinfo
+
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -24,9 +24,9 @@
import java.io.Serializable;
/**
- * Text Renderer of a {@link NavigationTreeNode}.
+ * Text Renderer of a {@link NavigationNode}.
* <p/>
- * This object will be placed as the {@link NavigationTreeNode#userObject} of
+ * This object will be placed as the {@link NavigationTreeNode#getUserObject()} of
* nodes.
* <p/>
*
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-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -26,7 +26,6 @@
import org.jdesktop.swingx.tree.TreeModelSupport;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
-import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import java.util.Enumeration;
@@ -40,7 +39,7 @@
* <p/>
* Il est composé de {@link NavigationTreeNode}
* <p/>
- * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeModel}
+ * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeNodeModel}
*
* @author sletellier
* @since 2.0.0
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -20,9 +20,16 @@
*/
package jaxx.runtime.swing.navigation;
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
import jaxx.runtime.context.JAXXContextEntryDef;
-import org.jdesktop.swingx.treetable.TreeTableNode;
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
+import javax.swing.tree.TreeNode;
import java.util.Enumeration;
/**
@@ -32,26 +39,438 @@
* @see NavigationTreeNode
* @since 2.0.0
*/
-public abstract class NavigationTreeTableNode extends NavigationTreeNode implements TreeTableNode {
+public class NavigationTreeTableNode extends DefaultMutableTreeTableNode implements NavigationNode<NavigationTreeTableNode> {
+//public abstract class NavigationTreeTableNode extends NavigationTreeNode implements TreeTableNode, NavigationNode<NavigationTreeTableNode> {
+ private static final long serialVersionUID = -1L;
+
+ /** Logger */
+ private static final Log log =
+ LogFactory.getLog(NavigationTreeTableNode.class);
+
+ /**
+ * The path separator used to build the {@link #fullPath}.
+ *
+ * @see #path
+ * @see #fullPath
+ */
+ protected final String pathSeparator;
+
+ /**
+ * The node path.
+ * <p/>
+ * Used to build the {@link #fullPath} which gives a unique identifier of
+ * the node.
+ *
+ * @see #pathSeparator
+ * @see #fullPath
+ */
+ protected String path;
+
+ /**
+ * The full path for the node from the rood node.
+ * <p/>
+ * This path is build by appending nodes {@link #path} from the root node to
+ * this node, between each path we introduce the {@link #pathSeparator}.
+ * <p/>
+ * Exemple :
+ * <pre>
+ * root
+ * $root
+ * `-- child1
+ * `-- child2
+ * </pre>
+ * will given {@code $root/child1/child2}.
+ *
+ * @see #pathSeparator
+ * @see #path
+ */
+ protected String fullPath;
+
+ /**
+ * The UI class associated with the node.
+ * <p/>
+ * This class can be {@code null}, in that case, the {@link
+ * NavigationTreeNodeModelBuilder#defaultUIClass} will be used while building
+ * the model.
+ */
+ protected Class<? extends JAXXObject> uIClass;
+
+ /**
+ * The UI handler class associated with the node.
+ * <p/>
+ * This class can be {@code null}, in that case, the {@link
+ * NavigationTreeNodeModelBuilder#defaultUIHandlerClass} will be used while
+ * building the model.
+ */
+ protected Class<? extends JAXXAction> uIHandlerClass;
+
+ /**
+ * The context entry definition to retrieve the bean.
+ * <p/>
+ * <b>Note:</b> If not set - the {@code bean} will be retrieve on a ancestor
+ * node.
+ */
+ protected JAXXContextEntryDef<?> jaxxContextEntryDef;
+
+ /**
+ * The jxPath to process to obtain real {@code bean} from the data retrieve
+ * in the context.
+ * <p/>
+ * <b>Note:</b> If not set -no jxpath will be apply on the bean from
+ * context.
+ */
+ protected String jaxxContextEntryPath;
+
+ /**
+ * The bean associated with the node ( the value can be obtain via the
+ * method {@link #getBean(JAXXContext)} or directly set via method {@link
+ * #setBean(Object)}.
+ * <p/>
+ * cache of bean associated with bean to improve performance
+ */
+ protected transient Object bean;
+
+ /**
+ * The type of the related bean associated with the node.
+ * <p/>
+ * Note: This type is here to override the NodeRenderer internalClass, since
+ * we could need to override this data.
+ * <p/>
+ * If this property is let to null, then we will use the NodeRenderer one
+ */
+ protected Class<?> internalClass;
+
+// public NavigationTreeTableNode(String pathSeparator,
+// String navigationPath,
+// Object jaxxContextEntryDef) {
+// super(pathSeparator, navigationPath, jaxxContextEntryDef);
+// }
+//
+// public NavigationTreeTableNode(String pathSeparator,
+// String navigationPath,
+// JAXXContextEntryDef<?> jaxxContextEntryDef,
+// String jaxxContextEntryPath) {
+// super(pathSeparator,
+// navigationPath,
+// jaxxContextEntryDef,
+// jaxxContextEntryPath
+// );
+// }
+
public NavigationTreeTableNode(String pathSeparator,
String navigationPath,
Object jaxxContextEntryDef) {
- super(pathSeparator, navigationPath, jaxxContextEntryDef);
+ this.pathSeparator = pathSeparator;
+ path = navigationPath;
+ if (jaxxContextEntryDef instanceof JAXXContextEntryDef<?>) {
+ this.jaxxContextEntryDef = ((JAXXContextEntryDef<?>) jaxxContextEntryDef);
+ } else if (jaxxContextEntryDef instanceof String) {
+ jaxxContextEntryPath = (String) jaxxContextEntryDef;
+ } else if (jaxxContextEntryDef != null) {
+ // wrong context definition type
+ throw new IllegalArgumentException(
+ "to define a context link, must be a String (jxpath) or a " + JAXXContextEntryDef.class + ", but was " + jaxxContextEntryDef);
+ }
}
public NavigationTreeTableNode(String pathSeparator,
String navigationPath,
JAXXContextEntryDef<?> jaxxContextEntryDef,
String jaxxContextEntryPath) {
- super(pathSeparator,
- navigationPath,
- jaxxContextEntryDef,
- jaxxContextEntryPath
- );
+ this.pathSeparator = pathSeparator;
+ path = navigationPath;
+ this.jaxxContextEntryDef = jaxxContextEntryDef;
+ this.jaxxContextEntryPath = jaxxContextEntryPath;
}
+ /** @return the text node renderer (store in {@link #userObject} property. */
@Override
+ public NavigationTreeNodeRenderer getRenderer() {
+ NavigationTreeNodeRenderer render = null;
+ Object o = getUserObject();
+ if (o != null && o instanceof NavigationTreeNodeRenderer) {
+ render = (NavigationTreeNodeRenderer) o;
+ }
+ return render;
+ }
+
+ @Override
+ public void setRenderer(NavigationTreeNodeRenderer renderer) {
+ // clear all cache
+ bean = null;
+ setUserObject(renderer);
+ }
+
+ @Override
+ public String getPathSeparator() {
+ return pathSeparator;
+ }
+
+ @Override
+ public String getNodePath() {
+ return path;
+ }
+
+ @Override
+ public void setNodePath(String navigationPath) {
+ path = navigationPath;
+ }
+
+ @Override
+ public Class<? extends JAXXObject> getUIClass() {
+ return uIClass;
+ }
+
+ @Override
+ public void setUIClass(Class<? extends JAXXObject> uIClass) {
+ this.uIClass = uIClass;
+ }
+
+ @Override
+ public void setInternalClass(Class<?> internalClass) {
+ this.internalClass = internalClass;
+ }
+
+ @Override
+ public Class<? extends JAXXAction> getUIHandlerClass() {
+ return uIHandlerClass;
+ }
+
+ @Override
+ public void setUIHandlerClass(Class<? extends JAXXAction> uIHandlerClass) {
+ this.uIHandlerClass = uIHandlerClass;
+ }
+
+ @Override
+ public JAXXContextEntryDef<?> getJaxxContextEntryDef() {
+ return jaxxContextEntryDef;
+ }
+
+ @Override
+ public void setJaxxContextEntryDef(JAXXContextEntryDef<?> jaxxContextEntryDef) {
+ this.jaxxContextEntryDef = jaxxContextEntryDef;
+ }
+
+ @Override
+ public String getJaxxContextEntryPath() {
+ return jaxxContextEntryPath;
+ }
+
+ @Override
+ public void setJaxxContextEntryPath(String jaxxContextEntryPath) {
+ this.jaxxContextEntryPath = jaxxContextEntryPath;
+ }
+
+ @Override
+ public Class<?> getInternalClass() {
+ if (internalClass == null && getRenderer() != null) {
+ return getRenderer().getInternalClass();
+ }
+ return internalClass;
+ }
+
+ /** @return the fully context path of the node from the root node to this. */
+ @Override
+ public String getFullPath() {
+ if (fullPath == null) {
+ StringBuilder sb = new StringBuilder();
+ for (TreeNode treeNode : getPath()) {
+ NavigationTreeTableNode myNode = (NavigationTreeTableNode) treeNode;
+ sb.append(pathSeparator).append(myNode.getNodePath());
+ }
+ fullPath = sb.substring(1);
+ }
+ return fullPath;
+ }
+
+ /**
+ * @return the first ancestor with a none null {@link #jaxxContextEntryDef}
+ * or <code>null</code> if none find..
+ */
+ protected NavigationTreeTableNode getFirstAncestorWithDef() {
+ if (jaxxContextEntryDef != null) {
+ // find a node with a direct link with the context
+ return this;
+ }
+ // the node is not linked to context
+ // seek in his parent
+ NavigationTreeTableNode ancestor = getParent();
+ return ancestor == null ? null : ancestor.getFirstAncestorWithDef();
+ }
+
+ protected String computeJXPath(String expr, NavigationTreeTableNode parentNode) {
+ if (equals(parentNode)) {
+ // reach the parent limit node, return the expr computed
+ return expr;
+ }
+ int firstIndex = expr.indexOf("..");
+ int lastIndex = expr.lastIndexOf("..");
+ if (firstIndex == -1) {
+ // this is a error, since current node is not parent limit node,
+ // we must find somewhere a way to go up in nodes
+ throw new IllegalArgumentException(
+ expr + " should contains at least one \"..\"");
+ }
+ if (firstIndex != 0) {
+ // this is a error, the ../ must be at the beginning of the expression
+ throw new IllegalArgumentException(
+ "\"..\" must be at the beginning but was : " + expr);
+ }
+ NavigationTreeTableNode ancestor = getParent();
+ if (firstIndex == lastIndex) {
+ // found only one go up, so must be substitute by the parent node context
+ String newExpr = expr.substring(2);
+ //String newExpr = expr.substring(expr.startsWith("../") ? 3 : 2);
+ if (getParent().equals(parentNode)) {
+ // parent node is the final parent node, so no substitution needed
+ return newExpr;
+ }
+ // ancestor must have a jaxxContextEntryPath
+ if (ancestor.jaxxContextEntryPath == null) {
+ throw new IllegalArgumentException(
+ "with the expression " + expr + ", the ancestor node ("
+ + ancestor + ") must have a jaxxContextEntryPath " +
+ "definition, but was not ");
+ }
+ newExpr = ancestor.jaxxContextEntryPath + newExpr;
+ return ancestor.computeJXPath(newExpr, parentNode);
+ }
+ // have more than one go up, so the ancestor node can not have a
+ // jaxxContextEntryPath
+ if (ancestor.jaxxContextEntryPath != null) {
+ throw new IllegalArgumentException(
+ "with the expression " + expr + ", the ancestor node can " +
+ "not have a jaxxContextEntryPath definition");
+ }
+ // substitute the last ..[/] and delegate to ancestor
+ String newExpr = expr.substring(0, lastIndex - 1) +
+ expr.substring(
+ lastIndex +
+ (expr.charAt(lastIndex + 3) == '/' ? 3 : 2)
+ );
+ return ancestor.computeJXPath(newExpr, parentNode);
+ }
+
+
+ @Override
+ public Object getBean() {
+ return bean;
+ }
+
+ @Override
+ public void setBean(Object bean) {
+ this.bean = bean;
+ }
+
+ @Override
+ public void reload(JAXXContext context) {
+
+ // clear bean cache
+ bean = null;
+
+ // clear context navigation cache
+ fullPath = null;
+
+ NavigationTreeNodeRenderer renderer = getRenderer();
+ if (renderer == null) {
+ // this can't be !
+ throw new NullPointerException(
+ "could not find the renderer for node " + this);
+ }
+
+ String s = getFullPath();
+ Object b = null;
+ try {
+ b = getBean(context);
+ } finally {
+ if (log.isInfoEnabled()) {
+ log.info("bean for path [" + s + "] = " + bean);
+ }
+ }
+
+ renderer.reload(b);
+ }
+
+ /**
+ * Obtain the associated bean value from context corresponding to node
+ *
+ * @param context the context to seek
+ * @return the value associated in context with the given context path
+ */
+ @Override
+ public Object getBean(JAXXContext context) {
+ if (bean != null) {
+ // use cached bean
+ return bean;
+ }
+ Object result;
+ if (getJaxxContextEntryDef() != null && jaxxContextEntryPath == null) {
+ // the node maps directly a value in context, with no jxpath resolving
+ result = getJaxxContextEntryDef().getContextValue(context);
+ // save in cache
+ setBean(result);
+ return result;
+ }
+ // find the first ancestor node with a context def
+ NavigationTreeTableNode parentNode = getFirstAncestorWithDef();
+ if (parentNode == null) {
+ log.warn("could not find a ancestor node with a definition of" +
+ " a context entry from node (" + this + ")");
+ // todo must be an error
+ // no parent found
+ return null;
+ }
+ Object parentBean = parentNode.getJaxxContextEntryDef().getContextValue(context);
+ if (parentBean == null) {
+ // must be an error no bean found
+ log.warn("could not find a bean attached in context from context" +
+ " entry definition " + parentNode.getJaxxContextEntryDef());
+ return null;
+ }
+ if (parentNode.jaxxContextEntryPath != null) {
+ // apply the jxpath on parentBean
+ JXPathContext jxcontext = JXPathContext.newContext(parentBean);
+ parentBean = jxcontext.getValue(parentNode.jaxxContextEntryPath);
+ }
+ // save in cache
+ parentNode.setBean(parentBean);
+ if (parentNode.equals(this)) {
+ // current node is the node matching the context entry value and
+ // no jxpath is found
+ return parentBean;
+ }
+ if (jaxxContextEntryPath == null) {
+ // todo must be an error
+ log.warn("must find a jaxxContextEntryPath on node (" + this +
+ ")");
+ return null;
+ }
+ String jxpathExpression = computeJXPath(jaxxContextEntryPath,
+ parentNode);
+ if (jxpathExpression == null) {
+ /// todo must be an error
+ log.warn("could not build jxpath from node " + parentNode +
+ " to " + this);
+ // could not retreave the jxpath...
+ return null;
+ }
+ if (jxpathExpression.startsWith("[")) {
+ // special case when we want to access a collection
+ jxpathExpression = '.' + jxpathExpression;
+ }
+ if (log.isDebugEnabled()) {
+ log.debug("jxpath : " + jxpathExpression);
+ }
+ JXPathContext jxcontext = JXPathContext.newContext(parentBean);
+ result = jxcontext.getValue(jxpathExpression);
+ // save in cache
+ setBean(result);
+ return result;
+ }
+
+
+ @Override
public NavigationTreeTableNode getChildAt(int index) {
return (NavigationTreeTableNode) super.getChildAt(index);
}
@@ -75,14 +494,75 @@
}
@Override
- public abstract Object getValueAt(int column);
+ public Enumeration<? extends NavigationTreeTableNode> children() {
+ return (Enumeration<? extends NavigationTreeTableNode>) super.children();
+ }
@Override
- public abstract int getColumnCount();
+ public void insert(NavigationTreeTableNode child, int index) {
+ super.insert(child, index);
+ }
@Override
- public abstract boolean isEditable(int column);
+ public void remove(NavigationTreeTableNode node) {
+ super.remove(node);
+ }
@Override
- public abstract void setValueAt(Object aValue, int column);
+ public void setParent(NavigationTreeTableNode newParent) {
+ super.setParent(newParent);
+ }
+
+ @Override
+ public int getIndex(NavigationTreeTableNode node) {
+ return super.getIndex(node);
+ }
+
+ @Override
+ public void add(NavigationTreeTableNode node) {
+ super.add(node);
+ }
+
+ @Override
+ public NavigationTreeTableNode[] getPath() {
+ return getPathToRoot(this, 0);
+ }
+
+ @Override
+ public NavigationTreeTableNode[] getPathToRoot(NavigationTreeTableNode aNode, int depth) {
+ NavigationTreeTableNode[] retNodes;
+
+ /* Check for null, in case someone passed in a null node, or
+ they passed in an element that isn't rooted at root. */
+ if (aNode == null) {
+ if (depth == 0) {
+ return null;
+ } else {
+ retNodes = new NavigationTreeTableNode[depth];
+ }
+ } else {
+ depth++;
+ retNodes = getPathToRoot(aNode.getParent(), depth);
+ retNodes[retNodes.length - depth] = aNode;
+ }
+ return retNodes;
+ }
+
+ @Override
+ public boolean isRoot() {
+ return getParent() == null;
+ }
+
+ //
+// @Override
+// public abstract Object getValueAt(int column);
+//
+// @Override
+// public abstract int getColumnCount();
+//
+// @Override
+// public abstract boolean isEditable(int column);
+//
+// @Override
+// public abstract void setValueAt(Object aValue, int column);
}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -1,63 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXAction;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * This object is design to build a {@link NavigationTreeModel} with sorted
- * nodes {@link SortedNavigationTreeNode} .
- *
- * @author sletellier
- * @see NavigationModelBuilder
- * @since 2.0.1
- */
-public class SortedNavigationTreeModelBuilder extends AbstractNavigationModelBuilder<SortedNavigationTreeNode> {
-
- /** Logger */
- static private final Log log =
- LogFactory.getLog(SortedNavigationTreeModelBuilder.class);
-
- public SortedNavigationTreeModelBuilder(
- Class<? extends JAXXObject> defaultUIClass,
- Class<? extends JAXXAction> defaultUIHandlerClass,
- NavigationModel<SortedNavigationTreeNode> navigationModel) {
- super(defaultUIClass, defaultUIHandlerClass, navigationModel);
- }
-
- @Override
- public SortedNavigationTreeNode createNavigationTreeNode(
- String pathSeparator,
- String contextName,
- JAXXContextEntryDef<?> jaxxContextEntryDef,
- String jaxxContextEntryPath) {
- return new SortedNavigationTreeNode(
- pathSeparator,
- contextName,
- jaxxContextEntryDef,
- jaxxContextEntryPath
- );
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -1,147 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.context.JAXXContextEntryDef;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.tree.MutableTreeNode;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.List;
-
-/**
- * Sprted node
- *
- * @author sletellier
- * @see NavigationTreeNode
- * @since 2.0.1
- */
-public class SortedNavigationTreeNode extends NavigationTreeNode {
-
- private static final long serialVersionUID = -1L;
-
- /** Logger */
- static private final Log log =
- LogFactory.getLog(SortedNavigationTreeNode.class);
-
- @Override
- public SortedNavigationTreeNode getChildAt(int index) {
- return (SortedNavigationTreeNode) super.getChildAt(index);
- }
-
- @Override
- public SortedNavigationTreeNode getParent() {
- return (SortedNavigationTreeNode) super.getParent();
- }
-
- @Override
- public Enumeration<SortedNavigationTreeNode> children() {
- return super.children();
- }
-
- @Override
- public void add(MutableTreeNode newChild) {
-
- List<SortedNavigationTreeNode> children =
- Collections.list(children());
-
- if (children.isEmpty()) {
- insert(newChild, 0);
- return;
- }
-
- SortedNavigationTreeNode newNode = (SortedNavigationTreeNode) newChild;
-
- children.add(newNode);
-
- Collections.sort(children, rendererDecorator);
- int index = children.indexOf(newChild);
-
- log.info("Insert node : " + newNode.getRenderer().toString() + " in " +
- index + " of parent " + this.getRenderer().toString());
-
- insert(newChild, index);
- }
-
-
- public SortedNavigationTreeNode(String pathSeparator,
- String navigationPath,
- Object jaxxContextEntryDef) {
- super(pathSeparator, navigationPath, jaxxContextEntryDef);
-// sort();
- }
-
- public SortedNavigationTreeNode(String pathSeparator,
- String navigationPath,
- JAXXContextEntryDef<?> jaxxContextEntryDef,
- String jaxxContextEntryPath) {
- super(pathSeparator,
- navigationPath,
- jaxxContextEntryDef,
- jaxxContextEntryPath
- );
-// sort();
- }
-
-// public void sort() {
-// List<SortedNavigationTreeNode> children = Collections.list(children());
-//
-// if (children.isEmpty() || children.size() == 1){
-// return;
-// }
-//
-// Collections.sort(children, rendererDecorator);
-//
-// if (children == null){
-// return;
-// }
-//
-// Iterator<SortedNavigationTreeNode> childrenIterator = children.iterator();
-// if (childrenIterator != null){
-// removeAllChildren();
-//
-// if (log.isDebugEnabled()){
-// log.debug("Adding " + children.size() + " children to parent " + getBean());
-// }
-// while (childrenIterator.hasNext()) {
-// SortedNavigationTreeNode childNode = childrenIterator.next();
-// childNode.sort();
-// add(childNode);
-// }
-// }
-// }
-
- final Comparator<NavigationTreeNode> rendererDecorator = new Comparator<NavigationTreeNode>() {
- @Override
- public int compare(NavigationTreeNode o1, NavigationTreeNode o2) {
- try {
- String label1 = ((NavigationTreeNode) o1).getRenderer().toString();
- String label2 = ((NavigationTreeNode) o2).getRenderer().toString();
- return label1.compareToIgnoreCase(label2);
- } catch (Exception eee) {
- return 0;
- }
- }
- };
-}
Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
===================================================================
--- trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-03-26 11:34:09 UTC (rev 1810)
@@ -46,7 +46,7 @@
@Test
public void testFindNode() throws Exception {
- NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, new DefaultJAXXContext(), null, null);
+ NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, new DefaultJAXXContext(), null, null);
NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null);
@@ -60,7 +60,7 @@
}
}
- NavigationModel<?> model = builder.getModel();
+ NavigationModel<NavigationTreeNode> model = builder.getModel();
NavigationTreeNode node;
String contextPath;
@@ -104,7 +104,7 @@
}
/**
- * Test the {@link NavigationTreeModel#getBean(String)}} with an entry point
+ * Test the {@link NavigationTreeNodeModel#getBean(String)}} with an entry point
* as a bean.
* <p/>
* Tree is like this
@@ -158,7 +158,7 @@
new Model("two", 2, Collections.<Model>emptyList()),
new Model("three", 3, Collections.<Model>emptyList()))));
- NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, context, null, null);
+ NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, context, null, null);
NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null);
@@ -224,7 +224,7 @@
}
/**
- * Test the {@link NavigationTreeModel#getBean(String)} with an entry point
+ * Test the {@link NavigationTreeNodeModel#getBean(String)} with an entry point
* as a list.
* <p/>
* Tree is like this
@@ -279,7 +279,7 @@
context.setContextValue(list, "models");
- NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, context, null, null);
+ NavigationTreeNodeModelBuilder builder = new NavigationTreeNodeModelBuilder(separator, context, null, null);
NavigationTreeNode rootNode = builder.build(null, (String) null, (String) null, ROOT_CONTEXT, null, null);
Modified: trunk/src/site/rst/NavigationModel.rst
===================================================================
--- trunk/src/site/rst/NavigationModel.rst 2010-03-25 16:43:48 UTC (rev 1809)
+++ trunk/src/site/rst/NavigationModel.rst 2010-03-26 11:34:09 UTC (rev 1810)
@@ -22,7 +22,7 @@
Contrat 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*.
+*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.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*.
@@ -33,7 +33,7 @@
Tout les models suivants implémantent cette interface.
-jaxx.runtime.swing.navigation.NavigationTreeModel
+jaxx.runtime.swing.navigation.NavigationTreeNodeModel
=================================================
Il s'agit du modèle de l'arbre utilisé, c'est une extension d'un
@@ -46,8 +46,8 @@
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*.
+*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeTableNode* qui
+étend *jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*.
NavigationTreeTableNode est abstaite, l'instance doit donc être crée en
implementant la méthode createNavigationTreeTableNode
@@ -64,11 +64,11 @@
Tous les builders implémentent cette interface.
-jaxx.runtime.swing.navigation.NavigationTreeModelBuilder
+jaxx.runtime.swing.navigation.NavigationTreeNodeModelBuilder
--------------------------------------------------------
Classe utilitaire pour construire le model (ici un
-*jaxx.runtime.swing.navigation.NavigationTreeModel*) et décorer un arbre.
+*jaxx.runtime.swing.navigation.NavigationTreeNodeModel*) et décorer un arbre.
jaxx.runtime.swing.navigation.NavigationTreeTableModelBuilder
-------------------------------------------------------------
@@ -114,7 +114,7 @@
=====================
Le noeud
-(*jaxx.runtime.swing.navigation.NavigationTreeModel.NavigationTreeNode*) est
+(*jaxx.runtime.swing.navigation.NavigationTreeNodeModel.NavigationTreeNode*) est
une extension d'un *javax.swing.tree.DefaultMutableTreeNode*.
Il apporte les nouvelles propriétés suivantes :
1
0
r1809 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 25 Mar '10
by tchemit@users.nuiton.org 25 Mar '10
25 Mar '10
Author: tchemit
Date: 2010-03-25 17:43:48 +0100 (Thu, 25 Mar 2010)
New Revision: 1809
Log:
add moveNode in NavigationModelBuilder api
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-25 16:35:00 UTC (rev 1808)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809)
@@ -66,10 +66,12 @@
this.model = model;
}
+ @Override
public NavigationModel<E> getModel() {
return model;
}
+ @Override
public E buildEmptyRoot(JAXXContextEntryDef<?> entryDef,
String contextName) {
E node = createNavigationTreeNode(
@@ -82,6 +84,7 @@
return addChildNode(null, node);
}
+ @Override
public E build(E parentNode,
String libelle,
JAXXContextEntryDef<?> entryDef,
@@ -100,6 +103,7 @@
return addChildNode(parentNode, node);
}
+ @Override
public E build(E parentNode,
String libelle,
JAXXContextEntryDef<?> entryDef,
@@ -117,6 +121,7 @@
return addChildNode(parentNode, node);
}
+ @Override
public E build(E parentNode,
String libelle,
String entryPath,
@@ -134,6 +139,7 @@
return addChildNode(parentNode, node);
}
+ @Override
public E build(E parentNode,
Decorator<?> decorator,
JAXXContextEntryDef<?> entryDef,
@@ -152,6 +158,7 @@
return addChildNode(parentNode, node);
}
+ @Override
public E build(E parentNode,
Decorator<?> decorator,
JAXXContextEntryDef<?> entryDef,
@@ -169,6 +176,7 @@
return addChildNode(parentNode, node);
}
+ @Override
public E build(E parentNode,
Decorator<?> decorator,
String entryPath,
@@ -186,40 +194,34 @@
return addChildNode(parentNode, node);
}
- protected E addChildNode(E parentNode, E node) {
-
- if (node.getUIClass() == null) {
- // no ui is associated with this node, use the default one
- node.setUIClass(defaultUIClass);
- }
-
- if (node.getUIHandlerClass() == null) {
- // no ui handler associated with this node, use the default one
- node.setUIHandlerClass(defaultUIHandlerClass);
- }
- if (parentNode == null) {
- model.setRoot(node);
- } else {
- parentNode.add(node);
- }
- model.nodeStructureChanged(parentNode == null ? node : parentNode);
- return node;
- }
-
+ @Override
public E removeChildNode(E node) {
E parentNode = (E) node.getParent();
model.removeNodeFromParent(node);
return parentNode;
}
+ @Override
+ public void moveNode(E parentNode,
+ E node,
+ int position) {
+ parentNode.remove(node);
+ parentNode.insert(node, position);
+ NavigationModel<E> treeModel = getModel();
+ treeModel.nodeStructureChanged(parentNode);
+ }
+
+ @Override
public void addI18nNodeRenderer(E node, String libelle) {
node.setRenderer(new NavigationTreeNodeRendererI18nImpl(libelle));
}
+ @Override
public void addDecoratorNodeRenderer(E node, Decorator<?> decorator) {
node.setRenderer(new NavigationTreeNodeRendererDecoratorImpl(decorator));
}
+ @Override
public void addNodeJaxxClasses(
E node,
Class<? extends JAXXObject> uIClass,
@@ -228,6 +230,7 @@
node.setUIHandlerClass(uIHandlerClass);
}
+ @Override
public void printModel(E node) {
if (node == null) {
return;
@@ -246,14 +249,26 @@
}
}
-// // To create your own instance of NavigationTreeTableNode
-//
-// public abstract E createNavigationTreeNode(
-// String pathSeparator,
-// String contextName,
-// JAXXContextEntryDef<?> jaxxContextEntryDef,
-// String jaxxContextEntryPath);
+ protected E addChildNode(E parentNode, E node) {
+ if (node.getUIClass() == null) {
+ // no ui is associated with this node, use the default one
+ node.setUIClass(defaultUIClass);
+ }
+
+ if (node.getUIHandlerClass() == null) {
+ // no ui handler associated with this node, use the default one
+ node.setUIHandlerClass(defaultUIHandlerClass);
+ }
+ if (parentNode == null) {
+ model.setRoot(node);
+ } else {
+ parentNode.add(node);
+ }
+ model.nodeStructureChanged(parentNode == null ? node : parentNode);
+ return node;
+ }
+
public static abstract class ChildBuilder<O, E extends NavigationTreeNode> {
protected AbstractNavigationModelBuilder<E> builder;
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-25 16:35:00 UTC (rev 1808)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-25 16:43:48 UTC (rev 1809)
@@ -43,7 +43,7 @@
String contextName,
JAXXContextEntryDef<?> jaxxContextEntryDef,
String jaxxContextEntryPath);
-
+
E buildEmptyRoot(JAXXContextEntryDef<?> entryDef, String contextName);
E build(E parentNode,
@@ -103,4 +103,6 @@
Class<? extends JAXXAction> uIHandlerClass);
void printModel(E node);
+
+ void moveNode(E parentNode, E node, int position);
}
1
0
r1808 - in trunk: jaxx-demo/src/main/java/jaxx/demo jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation
by tchemit@users.nuiton.org 25 Mar '10
by tchemit@users.nuiton.org 25 Mar '10
25 Mar '10
Author: tchemit
Date: 2010-03-25 17:35:00 +0100 (Thu, 25 Mar 2010)
New Revision: 1808
Log:
- clean navigation code
- remove deprecated Item navigation api
Removed:
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/item/
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationCardPanel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationPanel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemTreeNavigationAdapter.java
Modified:
trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java
trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -26,7 +26,6 @@
import jaxx.demo.component.jaxx.editor.I18nEditorDemo;
import jaxx.demo.component.jaxx.editor.NumberEditorDemo;
import jaxx.demo.component.jaxx.navigation.FullNavigationTreeDemo;
-import jaxx.demo.component.jaxx.navigation.item.ItemTreeNavigationDemo;
import jaxx.demo.component.swing.*;
import jaxx.demo.feature.databinding.BeanDataBindingDemo;
import jaxx.demo.feature.databinding.BindingExtremeDemo;
@@ -44,15 +43,13 @@
import jaxx.runtime.swing.navigation.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import static org.nuiton.i18n.I18n.n_;
import javax.swing.*;
import java.util.Stack;
-/**
- *
- * @author chemit
- */
+import static org.nuiton.i18n.I18n.n_;
+
+/** @author chemit */
public class DemoTreeHelper extends NavigationTreeHelper {
static private final Log log = LogFactory.getLog(DemoTreeHelper.class);
@@ -62,7 +59,7 @@
}
@Override
- public NavigationTreeModel createTreeModel(JAXXContext context) {
+ public NavigationModel<NavigationTreeNode> createTreeModel(JAXXContext context) {
if (log.isDebugEnabled()) {
log.debug("start creating demo model");
@@ -109,7 +106,6 @@
addDemo(I18nEditorDemo.class).
goUp().
addText(n_("jaxxdemo.tree.component.jaxx.tree.navigation")).
- addDemo(ItemTreeNavigationDemo.class).
addDemo(FullNavigationTreeDemo.class).
goUp().
addDemo(BoxedDecoratorDemo.class).
@@ -130,7 +126,7 @@
addDemo(CounterDemo.class).
addDemo(CalculatorDemo.class);
- NavigationTreeModel model = builder.getModel();
+ NavigationModel<NavigationTreeNode> model = builder.getModel();
if (log.isDebugEnabled()) {
builder.printModel(model.getRoot());
@@ -187,13 +183,11 @@
static class TreeModelBuilder extends NavigationTreeModelBuilder {
- /**
- * la definition de l'unqiue object a partage
- */
- static private final JAXXContextEntryDef<DemoConfig> def = JAXXUtil.newContextEntryDef(DemoConfig.class);
- /**
- * la pile des noeuds parent
- */
+ /** la definition de l'unqiue object a partage */
+ static private final JAXXContextEntryDef<DemoConfig> def =
+ JAXXUtil.newContextEntryDef(DemoConfig.class);
+
+ /** la pile des noeuds parent */
protected Stack<NavigationTreeNode> nodes;
protected TreeModelBuilder(JAXXContext context) {
Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java
===================================================================
--- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeModelBuilder.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -75,12 +75,12 @@
// construction du noeud root
// il ne contient pas de context et ne sera pas visible
- NavigationTreeNode rootNode = this.buildEmptyRoot(null, "$root");
+ NavigationTreeNode rootNode = buildEmptyRoot(null, "$root");
// construction du noeud avec les films recupere la liste des films
// dans le context avec la clef movies
// navigation path = $root/movies
- NavigationTreeNode moviesNode = this.build(
+ NavigationTreeNode moviesNode = build(
rootNode,
_("movies"),
FullNavigationTreeHelper.MOVIES,
@@ -91,7 +91,7 @@
for (Movie m : movies) {
// navigation path = $root/movies/m.id
- NavigationTreeNode movieNode = this.build(
+ NavigationTreeNode movieNode = build(
moviesNode,
mDecorator,
"..[@id=\"" + m.getId() + "\"]",
@@ -100,7 +100,7 @@
null);
// navigation path = $root/movies/m.id/actors
- NavigationTreeNode actorsNode = this.build(
+ NavigationTreeNode actorsNode = build(
movieNode,
_("actors"),
"../actors",
@@ -110,7 +110,7 @@
for (People p : m.getActors()) {
// navigation path = $root/movies/m.id/actors/p.id
- this.build(
+ build(
actorsNode,
pDecorator,
"..[@id=\"" + p.getId() + "\"]",
@@ -121,13 +121,13 @@
}
// construction du noeud avec les acteurs
- NavigationTreeNode actorsNode = this.build(rootNode, _("actors"),
+ NavigationTreeNode actorsNode = build(rootNode, _("actors"),
FullNavigationTreeHelper.ACTORS,
"actors", ActorsContentUI.class, null);
for (People p : actors) {
// navigation path = $root/actors/p.id
- this.build(
+ build(
actorsNode,
pDecorator,
"..[@id=\"" + p.getId() + "\"]",
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -27,38 +27,40 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.util.Collection;
import java.util.Enumeration;
/**
- * Interface to create a builder, this object is design to build a
- * {@link NavigationModel}.
+ * Interface to create a builder, this object is design to build a {@link
+ * NavigationModel}.
*
* @author sletellier
* @since 2.0.0
*/
public abstract class AbstractNavigationModelBuilder<E extends NavigationTreeNode> implements NavigationModelBuilder<E> {
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(AbstractNavigationModelBuilder.class);
+
/**
- * Logger
- */
- static private final Log log = LogFactory.getLog(AbstractNavigationModelBuilder.class);
- /**
* The model dealed by the builder.
- *
- * <b>Note:</b> It is a good idea to keep only one instance of the model.
- * If reset is required, should empty the model but not reinstanciate it.
+ * <p/>
+ * <b>Note:</b> It is a good idea to keep only one instance of the model. If
+ * reset is required, should empty the model but not reinstanciate it.
*/
protected NavigationModel<E> model;
- /**
- * default ui class to use if node does not define an ui class
- */
+
+ /** default ui class to use if node does not define an ui class */
protected Class<? extends JAXXObject> defaultUIClass;
- /**
- * [optional] default action class
- */
+
+ /** [optional] default action class */
protected Class<? extends JAXXAction> defaultUIHandlerClass;
- public AbstractNavigationModelBuilder(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, NavigationModel<E> model) {
+ public AbstractNavigationModelBuilder(
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass,
+ NavigationModel<E> model) {
this.defaultUIClass = defaultUIClass;
this.defaultUIHandlerClass = defaultUIHandlerClass;
this.model = model;
@@ -68,75 +70,117 @@
return model;
}
- public E buildEmptyRoot(JAXXContextEntryDef<?> entryDef, String contextName) {
- E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, null);
+ public E buildEmptyRoot(JAXXContextEntryDef<?> entryDef,
+ String contextName) {
+ E node = createNavigationTreeNode(
+ model.getPathSeparator(),
+ contextName,
+ entryDef,
+ null
+ );
addI18nNodeRenderer(node, "");
return addChildNode(null, node);
}
- public E build(E parentNode, String libelle,
- JAXXContextEntryDef<?> entryDef,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, entryPath);
+ public E build(E parentNode,
+ String libelle,
+ JAXXContextEntryDef<?> entryDef,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(
+ model.getPathSeparator(),
+ contextName,
+ entryDef,
+ entryPath
+ );
addI18nNodeRenderer(node, libelle);
addNodeJaxxClasses(node, uiClass, actionClass);
return addChildNode(parentNode, node);
}
- public E build(E parentNode, String libelle,
- JAXXContextEntryDef<?> entryDef,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, null);
+ public E build(E parentNode,
+ String libelle,
+ JAXXContextEntryDef<?> entryDef,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(
+ model.getPathSeparator(),
+ contextName,
+ entryDef,
+ null
+ );
addI18nNodeRenderer(node, libelle);
addNodeJaxxClasses(node, uiClass, actionClass);
return addChildNode(parentNode, node);
}
- public E build(E parentNode, String libelle,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(model.getPathSeparator(), contextName, null, entryPath);
+ public E build(E parentNode,
+ String libelle,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(
+ model.getPathSeparator(),
+ contextName,
+ null,
+ entryPath
+ );
addI18nNodeRenderer(node, libelle);
addNodeJaxxClasses(node, uiClass, actionClass);
return addChildNode(parentNode, node);
}
- public E build(E parentNode, Decorator<?> decorator,
- JAXXContextEntryDef<?> entryDef,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, entryPath);
+ public E build(E parentNode,
+ Decorator<?> decorator,
+ JAXXContextEntryDef<?> entryDef,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(
+ model.getPathSeparator(),
+ contextName,
+ entryDef,
+ entryPath
+ );
addDecoratorNodeRenderer(node, decorator);
addNodeJaxxClasses(node, uiClass, actionClass);
return addChildNode(parentNode, node);
}
- public E build(E parentNode, Decorator<?> decorator,
- JAXXContextEntryDef<?> entryDef,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, null);
+ public E build(E parentNode,
+ Decorator<?> decorator,
+ JAXXContextEntryDef<?> entryDef,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(
+ model.getPathSeparator(),
+ contextName,
+ entryDef,
+ null
+ );
addDecoratorNodeRenderer(node, decorator);
addNodeJaxxClasses(node, uiClass, actionClass);
return addChildNode(parentNode, node);
}
- public E build(E parentNode, Decorator<?> decorator,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- E node = createNavigationTreeNode(model.getPathSeparator(), contextName, null, entryPath);
+ public E build(E parentNode,
+ Decorator<?> decorator,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(
+ model.getPathSeparator(),
+ contextName,
+ null,
+ entryPath
+ );
addDecoratorNodeRenderer(node, decorator);
addNodeJaxxClasses(node, uiClass, actionClass);
return addChildNode(parentNode, node);
@@ -158,12 +202,12 @@
} else {
parentNode.add(node);
}
- model.nodeStructureChanged(node);
+ model.nodeStructureChanged(parentNode == null ? node : parentNode);
return node;
}
public E removeChildNode(E node) {
- E parentNode = (E)node.getParent();
+ E parentNode = (E) node.getParent();
model.removeNodeFromParent(node);
return parentNode;
}
@@ -188,7 +232,9 @@
if (node == null) {
return;
}
- log.info("node " + node.getFullPath() + ", jxpath: " + node.getJaxxContextEntryPath() + ", entryContextDef: " + node.getJaxxContextEntryDef());
+ log.info("node " + node.getFullPath() + ", jxpath: " +
+ node.getJaxxContextEntryPath() + ", entryContextDef: " +
+ node.getJaxxContextEntryDef());
if (log.isDebugEnabled()) {
log.debug("node userObject" + node.getUserObject());
log.debug("value from node " + node.getBean(getModel().getContext()));
@@ -200,8 +246,13 @@
}
}
- // To create your own instance of NavigationTreeTableNode
- public abstract E createNavigationTreeNode(String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath);
+// // To create your own instance of NavigationTreeTableNode
+//
+// public abstract E createNavigationTreeNode(
+// String pathSeparator,
+// String contextName,
+// JAXXContextEntryDef<?> jaxxContextEntryDef,
+// String jaxxContextEntryPath);
public static abstract class ChildBuilder<O, E extends NavigationTreeNode> {
@@ -219,7 +270,12 @@
protected abstract String getNavigationPath(O child);
- public void build(E parent, boolean cacheValues, Class<? extends O> klass, java.util.Collection<? extends O> beans, Class<? extends JAXXObject> ui, Class<? extends JAXXAction> actionClass) {
+ public void build(E parent,
+ boolean cacheValues,
+ Class<? extends O> klass,
+ Collection<? extends O> beans,
+ Class<? extends JAXXObject> ui,
+ Class<? extends JAXXAction> actionClass) {
if (beans == null || beans.isEmpty()) {
// no bean to treate
@@ -231,7 +287,14 @@
E node;
for (O o : beans) {
- node = builder.build(parent, getDecorator(o), getJXPath(o), getNavigationPath(o), ui, actionClass);
+ node = builder.build(
+ parent,
+ getDecorator(o),
+ getJXPath(o),
+ getNavigationPath(o),
+ ui,
+ actionClass
+ );
if (cacheValues) {
// cache the bean value to improve performance
node.setBean(o);
@@ -239,7 +302,12 @@
}
}
- public void build(E parent, boolean cacheValues, Class<? extends O> klass, O[] beans, Class<? extends JAXXObject> ui, Class<? extends JAXXAction> actionClass) {
+ public void build(E parent,
+ boolean cacheValues,
+ Class<? extends O> klass,
+ O[] beans,
+ Class<? extends JAXXObject> ui,
+ Class<? extends JAXXAction> actionClass) {
if (beans == null || beans.length == 0) {
// no bean to treate
@@ -251,7 +319,14 @@
E node;
for (O o : beans) {
- node = builder.build(parent, getDecorator(o), getJXPath(o), getNavigationPath(o), ui, actionClass);
+ node = builder.build(
+ parent,
+ getDecorator(o),
+ getJXPath(o),
+ getNavigationPath(o),
+ ui,
+ actionClass
+ );
if (cacheValues) {
// cache the bean value to improve performance
node.setBean(o);
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -34,18 +34,17 @@
/**
* Helper object associated to a given navigation tree system.
- *
+ * <p/>
* To helper is context safe (base on a {@link NavigationTreeContextHelper}.
*
* @author Letellier
- * @since 2.0.1
+ * @param <E> type of nodes in model
* @see NavigationTreeModel
+ * @since 2.0.1
*/
-public abstract class GenericNavigationHelper <E extends NavigationTreeNode> extends NavigationTreeContextHelper<E>{
+public abstract class GenericNavigationHelper<E extends NavigationTreeNode> extends NavigationTreeContextHelper<E> {
- /**
- * Logger
- */
+ /** Logger */
static private final Log log =
LogFactory.getLog(NavigationTreeHelper.class);
@@ -55,7 +54,7 @@
* @param context the context to associate with fresh model
* @return the new model build with data from the given context
*/
- public abstract NavigationModel createTreeModel(JAXXContext context);
+ public abstract NavigationModel<E> createTreeModel(JAXXContext context);
/**
* Create the tree handler.
@@ -71,8 +70,8 @@
public Object getContextValue(JAXXContext context, String path)
throws InvocationTargetException, NoSuchMethodException,
- IllegalAccessException {
- NavigationModel treeModel = getSafeModel(context);
+ IllegalAccessException {
+ NavigationModel<E> treeModel = getSafeModel(context);
return treeModel.getBean(path);
}
@@ -82,24 +81,24 @@
}
public E findNode(JAXXContext context, String path,
- String regex) {
+ String regex) {
NavigationModel<E> treeModel = getSafeModel(context);
return treeModel.findNode(path, regex);
}
public E findNode(JAXXContext context, String path,
- Pattern regex) {
+ Pattern regex) {
NavigationModel<E> treeModel = getSafeModel(context);
return treeModel.findNode(path, regex);
}
public E findNode(JAXXContext context, String path,
- String regex, String suffix) {
+ String regex, String suffix) {
NavigationModel<E> treeModel = getSafeModel(context);
- E node= treeModel.findNode(path, regex);
+ E node = treeModel.findNode(path, regex);
if (node != null && suffix != null) {
node = treeModel.findNode(node, suffix);
}
@@ -107,7 +106,7 @@
}
public E findNode(JAXXContext context, String path,
- Pattern regex, String suffix) {
+ Pattern regex, String suffix) {
NavigationModel<E> treeModel = getSafeModel(context);
@@ -122,7 +121,7 @@
* Sélection d'un noeud dans l'arbre de navigation à partir de son path.
*
* @param context le contexte applicatif
- * @param path le path absolue du noeud dans l'arbre
+ * @param path le path absolue du noeud dans l'arbre
*/
public void selectNode(JAXXContext context, String path) {
E node = findNode(context, path);
@@ -138,18 +137,18 @@
* Sélection d'un noeud dans l'arbre de navigation.
*
* @param context le contexte applicatif
- * @param node le noeud à sélectionner dans l'arbre
+ * @param node le noeud à sélectionner dans l'arbre
*/
public void selectNode(JAXXContext context, E node) {
- NavigationModel navigationModel = getSafeModel(context);
+ NavigationModel<E> navigationModel = getSafeModel(context);
if (log.isDebugEnabled()) {
log.debug(node);
}
TreePath path = new TreePath(navigationModel.getPathToRoot(node));
JTree tree = getTree(context);
- if (tree == null){
+ if (tree == null) {
// FIXME : Refactor in other helper ?
// If its JXTreeTable
JXTreeTable treeTable = getSafeTreeTable(context);
@@ -174,7 +173,7 @@
// pas de noeud selectionne
throw new NullPointerException("no selected node in context");
}
- node = (E)node.getParent();
+ node = (E) node.getParent();
selectNode(context, node);
}
@@ -184,11 +183,11 @@
*
* @param current the node to test
* @param beanClass the type of the internal class to seek of
- * @return the first ancestor node with the matching class or
- * {@code null} if not found
+ * @return the first ancestor node with the matching class or {@code null}
+ * if not found
*/
public E getParentNode(E current,
- Class<?> beanClass) {
+ Class<?> beanClass) {
if (current == null) {
// ancestor not found
return null;
@@ -198,13 +197,13 @@
return current;
}
// try in the parent of node
- return getParentNode((E)current.getParent(), beanClass);
+ return getParentNode((E) current.getParent(), beanClass);
}
/**
* Sélection d'un fils du noeud selectionne dans l'arbre de navigation.
*
- * @param context le contexte applicatif
+ * @param context le contexte applicatif
* @param childIndex index du fils a selectionner
*/
public void gotoChildNode(JAXXContext context, int childIndex) {
@@ -215,18 +214,18 @@
// pas de noeud selectionne
throw new NullPointerException("no selected node in context");
}
- node = (E)node.getChildAt(childIndex);
+ node = (E) node.getChildAt(childIndex);
selectNode(context, node);
}
/**
* Demande une opération de repaint sur un noeud de l'arbre de navigation.
- *
+ * <p/>
* <b>Note:</b> La descendance du noeud n'est pas repainte.
*
* @param context le contexte applicatif
- * @param node le noeud à repaindre
+ * @param node le noeud à repaindre
*/
public void repaintNode(JAXXContext context, E node) {
repaintNode(context, node, false);
@@ -234,17 +233,18 @@
/**
* Demande une opération de repaint sur un noeud de l'arbre de navigation.
- *
+ * <p/>
* <b>Note:</b> La descendance du noeud est repainte si le paramètre
* <code>deep</code> est à <code>true</code>.
*
* @param context le contexte applicatif
- * @param node le noeud à repaindre
- * @param deep un flag pour activer la repainte de la descendance du noeud
+ * @param node le noeud à repaindre
+ * @param deep un flag pour activer la repainte de la descendance du
+ * noeud
*/
public void repaintNode(JAXXContext context, E node,
boolean deep) {
- NavigationModel navigationModel = getSafeModel(context);
+ NavigationModel<E> navigationModel = getSafeModel(context);
if (log.isDebugEnabled()) {
log.debug(node);
}
@@ -260,30 +260,13 @@
}
}
- /**
- * @deprecated please use {@link #getSafeModel(JAXXContext)}, will be
- * remove soon
- * @param context where to find
- * @return the tree model
- * @throws NullPointerException if model is null
- */
- @Deprecated
- public NavigationTreeModel getSafeTreeModel(JAXXContext context)
+ public NavigationModel<E> getSafeModel(JAXXContext context)
throws NullPointerException {
- NavigationModel model = getSafeModel(context);
- if (model instanceof NavigationTreeModel){
- return (NavigationTreeModel) model;
- }
- return null;
- }
-
- public NavigationModel getSafeModel(JAXXContext context)
- throws NullPointerException {
- NavigationModel model = getModel(context);
+ NavigationModel<E> model = getModel(context);
if (model == null) {
- throw new NullPointerException("could not find tree model " +
- "with key " + getModelContextEntry() + " in context " +
- context);
+ throw new NullPointerException(
+ "could not find tree model with key " +
+ getModelContextEntry() + " in context " + context);
}
return model;
}
@@ -291,8 +274,9 @@
public JTree getSafeTree(JAXXContext context) throws NullPointerException {
JTree tree = getTree(context);
if (tree == null) {
- throw new NullPointerException("could not find tree with key " +
- getTreeContextEntry() + " in context " + context);
+ throw new NullPointerException(
+ "could not find tree with key " + getTreeContextEntry() +
+ " in context " + context);
}
return tree;
}
@@ -301,7 +285,8 @@
throws NullPointerException {
JXTreeTable treeTable = getTreeTable(context);
if (treeTable == null) {
- throw new NullPointerException("could not find tree with key " +
+ throw new NullPointerException(
+ "could not find tree with key " +
getTreeTableContextEntry() + " in context " + context);
}
return treeTable;
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -26,26 +26,27 @@
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeNode;
+import java.lang.reflect.Array;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
- * Model of the tree used for a navigation tree.
- * <p/>
- * Il est composé de {@link NavigationTreeNode}
+ * Model of the tree used for a navigation tree. It is composed of {@link E}
+ * nodes.
*
* @author letellier
* @since 2.0.1
+ * @param <E> the type of nodes in model
*/
-public class GenericNavigationTreeModel<E extends NavigationTreeNode> extends DefaultTreeModel implements NavigationModel<E>{
+public class GenericNavigationTreeModel<E extends NavigationTreeNode> extends DefaultTreeModel implements NavigationModel<E> {
static private final long serialVersionUID = 1L;
- /**
- * Logger
- */
+
+ /** Logger */
static private final Log log = LogFactory.getLog(NavigationTreeModel.class);
+
/**
* The path separator used to build the {@link NavigationTreeNode#fullPath}.
*
@@ -53,20 +54,17 @@
* @see NavigationTreeNode#getFullPath()
*/
protected final String pathSeparator;
- /**
- * Context to retrieve beans
- */
+
+ /** Context to retrieve beans */
private JAXXContext context;
- public GenericNavigationTreeModel(String pathSeparator, JAXXContext context) {
+ public GenericNavigationTreeModel(String pathSeparator,
+ JAXXContext context) {
super(null);
this.pathSeparator = pathSeparator;
this.context = context;
}
- /**
- * @see NavigationModel#getRoot()
- */
@Override
public E getRoot() {
return (E) super.getRoot();
@@ -77,56 +75,34 @@
super.setRoot(root);
}
- /**
- * @see NavigationModel#findNode(String)
- */
@Override
public E findNode(String path) {
return findNode(getRoot(), path, (Pattern) null);
}
- /**
- * @see NavigationModel#findNode(String, String)
- */
@Override
public E findNode(String path, String regex) {
return findNode(getRoot(), path, regex);
}
- /**
- * @see NavigationModel#findNode(String, Pattern)
- */
@Override
public E findNode(String path, Pattern regex) {
return findNode(getRoot(), path, regex);
}
- /**
- * @see NavigationModel#findNode(NavigationTreeNode, String)
- */
@Override
public E findNode(E root, String path) {
return findNode(root, path, (Pattern) null);
}
- /**
- * @see NavigationModel#findNode(NavigationTreeNode, String, String)
- */
@Override
- public E findNode(E root,
- String path,
- String regex) {
+ public E findNode(E root, String path, String regex) {
return findNode(root, path,
- regex == null ? null : Pattern.compile(regex));
+ regex == null ? null : Pattern.compile(regex));
}
- /**
- * @see NavigationModel#findNode(NavigationTreeNode, String, Pattern)
- */
@Override
- public E findNode(E root,
- String path,
- Pattern regex) {
+ public E findNode(E root, String path, Pattern regex) {
if (regex != null) {
Matcher matcher = regex.matcher(path);
if (!matcher.matches() || matcher.groupCount() < 1) {
@@ -148,22 +124,16 @@
}
}
while (stk.hasMoreTokens()) {
- result = (E)result.getChild(stk.nextToken());
+ result = (E) result.getChild(stk.nextToken());
}
return result;
}
- /**
- * @see NavigationModel#getContext()
- */
@Override
public JAXXContext getContext() {
return context;
}
- /**
- * @see NavigationModel#getBean(String)
- */
@Override
public Object getBean(String navigationPath) {
Object result;
@@ -172,9 +142,6 @@
return result;
}
- /**
- * @see NavigationModel#getBean(NavigationTreeNode)
- */
@Override
public Object getBean(E node) {
if (node == null) {
@@ -185,23 +152,17 @@
return node.getBean(getContext());
}
- /**
- * @see NavigationModel#nodeChanged(TreeNode)
- */
@Override
- public void nodeChanged(TreeNode node) {
+ public void nodeChanged(E node) {
nodeChanged(node, false);
if (log.isDebugEnabled()) {
log.debug(node);
}
}
- /**
- * @see NavigationModel#nodeStructureChanged(TreeNode)
- */
@Override
- public void nodeStructureChanged(TreeNode node) {
- E n = (E) node;
+ public void nodeStructureChanged(E node) {
+ E n = node;
//TC-20091004 never launch a deep reload
reload(n, true);
super.nodeStructureChanged(node);
@@ -210,18 +171,20 @@
}
}
- /**
- * @see NavigationModel#nodeChanged(TreeNode, boolean)
- */
@Override
- public void nodeChanged(TreeNode node, boolean deep) {
+ public void nodeChanged(E node, boolean deep) {
- E n = (E) node;
+ E n = node;
//TC-20091004 never launch a deep clean, since we do a deep nodeChanged.
reload(n, deep);
super.nodeChanged(node);
}
+ @Override
+ public String getPathSeparator() {
+ return pathSeparator;
+ }
+
protected void reload(E node) {
reload(node, false);
}
@@ -241,11 +204,16 @@
}
}
- /**
- * @see NavigationModel#getPathSeparator()
- */
@Override
- public String getPathSeparator() {
- return pathSeparator;
+ public E[] getPathToRoot(E aNode) {
+ TreeNode[] treeNodes = super.getPathToRoot(aNode);
+ E[] result = (E[]) Array.newInstance(aNode.getClass(),treeNodes.length);
+ System.arraycopy(treeNodes,0,result,0,treeNodes.length);
+ return result;
}
+
+ @Override
+ public void removeNodeFromParent(E node) {
+ super.removeNodeFromParent(node);
+ }
}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationCardPanel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationCardPanel.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationCardPanel.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -1,82 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import java.awt.CardLayout;
-import java.awt.Component;
-import javax.swing.JPanel;
-import jaxx.runtime.swing.Item;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- *
- * @author letellier
- * @since 1.7.2
- */
-public class ItemNavigationCardPanel extends JPanel {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private final Log log = LogFactory.getLog(ItemNavigationCardPanel.class);
- private static final long serialVersionUID = 1L;
- CardLayout layout;
-
- public ItemNavigationCardPanel() {
- super();
-
- layout = new CardLayout();
- setLayout(layout);
- }
-
- public void showItem(Item i) {
- if (i != null) {
- Object value = i.getValue();
- if (value != null) {
- if (value instanceof Class<?>) {
- layout.show(this, ((Class<?>) value).getName());
- } else {
- layout.show(this, value.getClass().getName());
- }
- }
- }
- }
-
- public Component getShowedComponent() {
- Component[] components = getComponents();
- if (components != null) {
- for (Component c : components) {
- if (c.isVisible()) {
- return c;
- }
- }
- }
- return null;
- }
-
- @Override
- public Component add(Component comp) {
- if (!(comp instanceof ItemNavigationPanel)) {
- throw new IllegalArgumentException("ItemNavigationCardPanel must be have only ItemNavigationPanel children");
- }
- super.add(comp, ((ItemNavigationPanel) comp).getAssociatedClass().getName());
- return comp;
- }
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationPanel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationPanel.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemNavigationPanel.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -1,44 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-
-package jaxx.runtime.swing.navigation;
-
-import javax.swing.JPanel;
-
-/**
- *
- * @author letellier
- */
-public class ItemNavigationPanel extends JPanel{
-
- private static final long serialVersionUID = 1L;
-
- protected Class<?> associatedClass = null;
-
- public ItemNavigationPanel(Class<?> associatedClass) {
- this.associatedClass = associatedClass;
- }
-
- public Class<?> getAssociatedClass() {
- return associatedClass;
- }
-
-}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemTreeNavigationAdapter.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemTreeNavigationAdapter.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/ItemTreeNavigationAdapter.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -1,89 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import javax.swing.event.TreeSelectionEvent;
-import javax.swing.event.TreeSelectionListener;
-import javax.swing.tree.TreeModel;
-import javax.swing.tree.TreePath;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.swing.Item;
-import jaxx.runtime.swing.JAXXTree;
-import jaxx.runtime.swing.JAXXTree.JAXXTreeModel;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/** A {@link javax.swing.event.TreeSelectionListener} implementation@@author letellier */
-public abstract class ItemTreeNavigationAdapter implements TreeSelectionListener {
-
- /** to use log facility, just put in your code: log.info(\"...\"); */
- static private final Log log = LogFactory.getLog(ItemTreeNavigationAdapter.class);
-
- /** l'ui contenant l'arbre de navigation */
- protected JAXXObject context;
-
- protected JAXXTree tree;
- protected ItemNavigationCardPanel cardPanel;
-
- public ItemTreeNavigationAdapter(JAXXObject context, JAXXTree tree, ItemNavigationCardPanel cardPanel) {
- super();
- this.context = context;
- this.tree = tree;
- this.cardPanel = cardPanel;
-
- // Attache ce listener a l'arbre de navigation
- tree.addTreeSelectionListener(this);
- }
-
- @Override
- public void valueChanged(TreeSelectionEvent e) {
- log.debug("Selection in JAXXTree changed" + e.getPath());
-
- // Recuperation du path selectionne
- TreePath path = e.getNewLeadSelectionPath();
- if (path == null){
- path = e.getOldLeadSelectionPath();
- }
- TreeModel model = tree.getModel();
-
- if (!(model instanceof JAXXTreeModel)){
- log.error("Its not an JAXXTreeModel");
- return;
- }
-
- // Find item coresponding
- Object lastPathComponent = path.getLastPathComponent();
- Item itemSelected = ((JAXXTreeModel) model).findItem(lastPathComponent);
-
- // Show corresponding panel
- cardPanel.showItem(itemSelected);
-
- // Notifie change
- valueChanged(itemSelected.getValue());
- }
-
- /**
- * Method abstraite pour pouvoir propager la donnee selectionner
- *
- * @param data value of the node selected
- */
- protected abstract void valueChanged(Object data);
-}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationContentUI.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -20,6 +20,8 @@
*/
package jaxx.runtime.swing.navigation;
+import java.awt.*;
+
/**
* Basic contract on a content UI.
*
@@ -29,24 +31,22 @@
public interface NavigationContentUI {
/**
- * Init the ui just before been opened by the method
- * {@link NavigationTreeHandler#openUI(java.awt.Component,
- * jaxx.runtime.swing.navigation.NavigationTreeNode)}.
+ * Init the ui just before been opened by the method {@link
+ * NavigationTreeHandler#openUI(Component, NavigationTreeNode)}.
*
* @param node the selected node associated to the ui
* @throws Exception if any pb while opening the content's ui
- * @see NavigationTreeHandler#openUI(java.awt.Component,
- * jaxx.runtime.swing.navigation.NavigationTreeNode)
+ * @see NavigationTreeHandler#openUI(Component, NavigationTreeNode)
*/
void openUI(NavigationTreeNode node) throws Exception;
/**
- * Clean the ui after been closed by the method
- * {@link NavigationTreeHandler#closeUI(java.awt.Component)}.
+ * Clean the ui after been closed by the method {@link
+ * NavigationTreeHandler#closeUI(Component)}.
*
* @param node 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(NavigationTreeNode node) throws Exception;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -22,7 +22,6 @@
import jaxx.runtime.JAXXContext;
-import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import java.util.regex.Pattern;
@@ -41,9 +40,9 @@
void setRoot(E root);
- TreeNode[] getPathToRoot(TreeNode aNode);
+ TreeNode[] getPathToRoot(E aNode);
- public void removeNodeFromParent(MutableTreeNode node);
+ void removeNodeFromParent(E node);
/**
* Search from the root node a node named by his fully path (concatenation
@@ -122,8 +121,7 @@
* @return the node matching the fully context from the given root node,
* or <code>null</code> if not found.
*/
- E findNode(E root, String path,
- String regex);
+ E findNode(E root, String path, String regex);
/**
* Apply first the regex pattern to obtain the searched node.
@@ -138,8 +136,7 @@
* @return the node matching the fully context from the given root node,
* or <code>null</code> if not found.
*/
- E findNode(E root, String path,
- Pattern regex);
+ E findNode(E root, String path, Pattern regex);
JAXXContext getContext();
@@ -160,11 +157,11 @@
*/
Object getBean(E node);
- void nodeChanged(TreeNode node);
+ void nodeChanged(E node);
- void nodeStructureChanged(TreeNode node);
+ void nodeStructureChanged(E node);
- void nodeChanged(TreeNode node, boolean deep);
+ void nodeChanged(E node, boolean deep);
String getPathSeparator();
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -26,67 +26,73 @@
import jaxx.runtime.decorator.Decorator;
/**
- * Interface to create a builder, this object is design to build a
- * {@link NavigationModel}.
+ * Interface to create a builder, this object is design to build a {@link
+ * NavigationModel}.
*
* @author sletellier
* @since 2.0.0
*/
-public interface NavigationModelBuilder <E extends NavigationTreeNode> {
+public interface NavigationModelBuilder<E extends NavigationTreeNode> {
- NavigationModel getModel();
+ NavigationModel<E> getModel();
- E buildEmptyRoot(JAXXContextEntryDef<?> entryDef,
- String contextName);
+ // To create your own instance of NavigationTreeTableNode
+ E createNavigationTreeNode(
+ String pathSeparator,
+ String contextName,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath);
+
+ E buildEmptyRoot(JAXXContextEntryDef<?> entryDef, String contextName);
+
E build(E parentNode,
- String libelle,
- JAXXContextEntryDef<?> entryDef,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass);
+ String libelle,
+ JAXXContextEntryDef<?> entryDef,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass);
E build(E parentNode,
- String libelle,
- JAXXContextEntryDef<?> entryDef,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass);
+ String libelle,
+ JAXXContextEntryDef<?> entryDef,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass);
E build(E parentNode,
- String libelle,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass);
+ String libelle,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass);
E build(E parentNode,
- Decorator<?> decorator,
- JAXXContextEntryDef<?> entryDef,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass);
+ Decorator<?> decorator,
+ JAXXContextEntryDef<?> entryDef,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass);
E build(E parentNode,
- Decorator<?> decorator,
- JAXXContextEntryDef<?> entryDef,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass);
+ Decorator<?> decorator,
+ JAXXContextEntryDef<?> entryDef,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass);
E build(E parentNode,
- Decorator<?> decorator,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass);
+ Decorator<?> decorator,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass);
E removeChildNode(E node);
- void addI18nNodeRenderer(E node,
- String libelle);
+ void addI18nNodeRenderer(E node, String libelle);
void addDecoratorNodeRenderer(E node,
Decorator<?> decorator);
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-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiContentUI.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -21,7 +21,7 @@
package jaxx.runtime.swing.navigation;
-import java.awt.Component;
+import java.awt.*;
import java.util.List;
/**
@@ -30,11 +30,11 @@
* @author sletellier
* @since 2.0.1
*/
-public interface NavigationMultiContentUI extends NavigationContentUI{
+public interface NavigationMultiContentUI extends NavigationContentUI {
/**
- * Init the ui just before been opened by the method
- * {@link NavigationMultiTreeHandler#openUI(Component, List)}.
+ * Init the ui just before been opened by the method {@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
@@ -42,8 +42,8 @@
void openUI(List<NavigationTreeNode> nodes) throws Exception;
/**
- * Clean the ui after been closed by the method
- * {@link NavigationTreeHandler#closeUI(Component)}.
+ * Clean the ui after been closed by the method {@link
+ * NavigationTreeHandler#closeUI(Component)}.
*
* @param nodes the selected node associated to the ui
* @throws Exception if any pb when closing the content'sui
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationMultiTreeHandler.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -28,26 +28,25 @@
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreePath;
-import java.awt.Component;
+import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* The handler of a navigation tree.
- *
+ * <p/>
* This is also the selection model to use, since we must check before moving
* from nodes we can not just listen selection model changed, we must control
* it.
- *
+ * <p/>
* This one is used to enable multi selection
*
* @author sletellier
* @since 2.0.1
*/
public abstract class NavigationMultiTreeHandler extends NavigationTreeHandler {
- /**
- * Logger
- */
+
+ /** Logger */
static private final Log log =
LogFactory.getLog(NavigationMultiTreeHandler.class);
@@ -67,15 +66,15 @@
// TODO : verifier que la selection n'est pas la même
List<NavigationTreeNode> nodes = new ArrayList<NavigationTreeNode>();
- if (paths == null){
+ if (paths == null) {
selectNodeUI(new ArrayList<NavigationTreeNode>());
return;
}
- for(TreePath path : paths){
+ for (TreePath path : paths) {
NavigationTreeNode node =
(NavigationTreeNode) path.getLastPathComponent();
nodes.add(node);
- if (log.isDebugEnabled()){
+ if (log.isDebugEnabled()) {
log.debug("Adding path : " + path);
log.debug("As node : " + node.getFullPath());
}
@@ -116,7 +115,7 @@
try {
List<String> paths = new ArrayList<String>();
List<Object> beans = new ArrayList<Object>();
- for (NavigationTreeNode node : nodes){
+ for (NavigationTreeNode node : nodes) {
String path = node.getFullPath();
paths.add(path);
@@ -135,7 +134,7 @@
// save it in context (must be done before init ui)
JAXXContext ctxt = getContext();
- NavigationTreeContextHelper helper = getContextHelper();
+ NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper();
// remove previous selected bean
//TODO-TC-20091004 should have an automatic clean context method
@@ -178,9 +177,9 @@
}
}
- protected List<String> getPaths(List<NavigationTreeNode> nodes){
+ protected List<String> getPaths(List<NavigationTreeNode> nodes) {
List<String> result = new ArrayList<String>();
- for (NavigationTreeNode node : nodes){
+ for (NavigationTreeNode node : nodes) {
result.add(node.getFullPath());
}
return result;
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationOneClicSelectionHandler.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -21,37 +21,28 @@
package jaxx.runtime.swing.navigation;
-import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.jdesktop.swingx.JXTreeTable;
-import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreePath;
-import javax.swing.tree.TreeSelectionModel;
-import java.awt.Component;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
/**
* The handler of a navigation tree.
- *
+ * <p/>
* This is also the selection model to use, since we must check before moving
* from nodes we can not just listen selection model changed, we must control
* it.
- *
+ * <p/>
* This one is used to enable one clic multi selection
*
* @author sletellier
* @since 2.0.1
*/
public abstract class NavigationOneClicSelectionHandler extends NavigationMultiTreeHandler {
- /**
- * Logger
- */
+
+ /** Logger */
static private final Log log =
LogFactory.getLog(NavigationOneClicSelectionHandler.class);
@@ -65,11 +56,11 @@
@Override
public void setSelectionPath(TreePath path) {
TreePath[] treePaths = getSelectionPaths();
- if (treePaths == null || !Arrays.asList(treePaths).contains(path)){
+ if (treePaths == null || !Arrays.asList(treePaths).contains(path)) {
addSelectionPath(path);
} else {
removeSelectionPath(path);
}
}
-
+
}
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-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -75,7 +75,7 @@
protected JAXXContextEntryDef<List<String>> selectedPathsContextEntry;
protected JAXXContextEntryDef<List<Object>> selectedBeansContextEntry;
protected JAXXContextEntryDef<List<E>> selectedNodesContextEntry;
- protected JAXXContextEntryDef<NavigationModel> modelContextEntry;
+ protected JAXXContextEntryDef<NavigationModel<E>> modelContextEntry;
protected JAXXContextEntryDef<NavigationTreeHandler> handlerContextEntry;
protected JAXXContextEntryDef<JTree> treeContextEntry;
protected JAXXContextEntryDef<JXTreeTable> treeTableContextEntry;
@@ -84,7 +84,7 @@
this.prefix = prefix;
treeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree", JTree.class);
treeTableContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-table", JXTreeTable.class);
- modelContextEntry = JAXXUtil.newContextEntryDef(prefix + "-model", NavigationModel.class);
+ modelContextEntry = (JAXXContextEntryDef)JAXXUtil.newContextEntryDef(prefix + "-model", NavigationModel.class);
handlerContextEntry = JAXXUtil.newContextEntryDef(prefix + "-handler", NavigationTreeHandler.class);
selectedBeansContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-beans");
selectedNodesContextEntry = JAXXUtil.newListContextEntryDef(prefix + "-selected-nodes");
@@ -105,26 +105,11 @@
return r;
}
- public NavigationModel getModel(JAXXContext context) {
- NavigationModel r = getModelContextEntry().getContextValue(context);
+ public NavigationModel<E> getModel(JAXXContext context) {
+ NavigationModel<E> r = getModelContextEntry().getContextValue(context);
return r;
}
- /**
- * @param context where to find model
- * @deprecated since 2.0 please use {@link #getModel(JAXXContext)}, will
- * be remove soon
- * @return the specific tree model
- */
- @Deprecated
- public NavigationTreeModel getTreeModel(JAXXContext context) {
- NavigationModel r = getModel(context);
- if (r instanceof NavigationTreeModel) {
- return (NavigationTreeModel) r;
- }
- return null;
- }
-
public NavigationTreeHandler getTreeHandler(JAXXContext context) {
NavigationTreeHandler r =
getTreeHandlerContextEntry().getContextValue(context);
@@ -158,18 +143,7 @@
return getSelectedBeanContextEntry().getContextValue(context);
}
- /**
- * @param context where to store model
- * @param model model to store
- * @deprecated since 2.0 please use {@link #setModel(JAXXContext, NavigationModel)},
- * will be remove soon
- */
- @Deprecated
- public void setTreeModel(JAXXContext context, NavigationModel model) {
- setModel(context, model);
- }
-
- public void setModel(JAXXContext context, NavigationModel model) {
+ public void setModel(JAXXContext context, NavigationModel<E> model) {
getModelContextEntry().setContextValue(context, model);
}
@@ -210,7 +184,7 @@
setSelectedValues(getSelectedBeanContextEntry(), context, beans);
}
- protected JAXXContextEntryDef<NavigationModel> getModelContextEntry() {
+ protected JAXXContextEntryDef<NavigationModel<E>> getModelContextEntry() {
return modelContextEntry;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandler.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -21,6 +21,7 @@
package jaxx.runtime.swing.navigation;
import java.awt.Component;
+import java.util.Arrays;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultTreeSelectionModel;
@@ -95,10 +96,10 @@
*
* @since 1.7.2
*/
- protected NavigationTreeContextHelper contextHelper;
+ protected NavigationTreeContextHelper<NavigationTreeNode> contextHelper;
protected NavigationTreeHandler(String contextPrefix, JAXXObject context, Strategy strategy) {
- contextHelper = new NavigationTreeContextHelper(contextPrefix);
+ contextHelper = new NavigationTreeContextHelper<NavigationTreeNode>(contextPrefix);
this.context = context;
this.strategy = strategy;
addTreeSelectionListener(this);
@@ -121,7 +122,7 @@
/**
* @return le modèle de navigation associé
*/
- protected abstract NavigationModel getNavigationTreeModel();
+ protected abstract NavigationModel<?> getNavigationTreeModel();
/**
* @return le composent actuellement visible associé au noeud courant ou
@@ -171,7 +172,7 @@
return context;
}
- public NavigationTreeContextHelper getContextHelper() {
+ public NavigationTreeContextHelper<NavigationTreeNode> getContextHelper() {
return contextHelper;
}
@@ -212,7 +213,7 @@
public void setSelectionPaths(TreePath[] paths) {
//FIXME-TC20100315 this can not work...
// can't test like this paths as Array...
- if (paths.equals(getSelectionPaths())) {
+ if (Arrays.equals(paths, getSelectionPaths())) {
// stay on same node, can skip
if (log.isDebugEnabled()) {
log.debug("skip stay on path " + paths);
@@ -231,7 +232,7 @@
}
if (component instanceof NavigationMultiContentUI) {
if (paths.length == 1){
- NavigationTreeContextHelper helper = getContextHelper();
+ NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper();
((NavigationMultiContentUI) component).closeUI(helper.getSelectedNodes(getContext()));
}
}
@@ -273,7 +274,7 @@
}
JAXXContext ctxt = getContext();
- NavigationTreeContextHelper helper = getContextHelper();
+ NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper();
// save in context current node context path
helper.setSelectedPath(ctxt, node.getFullPath());
@@ -331,7 +332,7 @@
log.debug("find data for contextPath <" + node.getFullPath() + "> : " + (data == null ? null : data.getClass()));
}
JAXXContext ctxt = getContext();
- NavigationTreeContextHelper helper = getContextHelper();
+ NavigationTreeContextHelper<NavigationTreeNode> helper = getContextHelper();
// remove previous selected bean
//TODO-TC-20091004 should have an automatic clean context method while
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHandlerWithCardLayout.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -26,49 +26,55 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import javax.swing.JPanel;
-import java.awt.Component;
-import java.util.List;
+import javax.swing.*;
+import java.awt.*;
+import java.lang.reflect.Constructor;
/**
- * Simple {@link NavigationTreeHandler} implementation with a {@link CardLayout2} to manage components to
- * associated with tree's nodes.
+ * Simple {@link NavigationTreeHandler} implementation with a {@link
+ * CardLayout2} to manage components to associated with tree's nodes.
* <p/>
- * For each node, the ui associated has a constraints in a cardlayout which is the node context path.
+ * For each node, the ui associated has a constraints in a cardlayout which is
+ * the node context path.
* <p/>
- * A single container managed by the cardlayout is used to display the components associated with tree's nodes.
+ * A single container managed by the cardlayout is used to display the
+ * components associated with tree's nodes.
*
* @author chemit
*/
public abstract class NavigationTreeHandlerWithCardLayout extends NavigationTreeHandler {
- /**
- * Logger
- */
+ /** Logger */
static private final Log log = LogFactory.getLog(NavigationTreeHandlerWithCardLayout.class);
/**
- * All components associated with a tree's node is displayed in a single container.
+ * All components associated with a tree's node is displayed in a single
+ * container.
*
* @return the containter of components
*/
protected abstract JPanel getContentContainer();
/**
- * the cardlayout managing components associated with tree node. The constraints
- * of each component is the node contextPath.
+ * the cardlayout managing components associated with tree node. The
+ * constraints of each component is the node contextPath.
*
- * @return the layout used to display components associated with tree's nodes.
+ * @return the layout used to display components associated with tree's
+ * nodes.
*/
protected abstract CardLayout2 getContentLayout();
- public NavigationTreeHandlerWithCardLayout(String contextPrefix, JAXXObject context, Strategy strategy) {
+ public NavigationTreeHandlerWithCardLayout(String contextPrefix,
+ JAXXObject context,
+ Strategy strategy) {
super(contextPrefix, context, strategy);
if (getContentContainer() == null) {
- throw new IllegalArgumentException("could not have a null 'contentContainer' in ui " + context);
+ throw new IllegalArgumentException(
+ "could not have a null 'contentContainer' in ui " + context);
}
if (getContentLayout() == null) {
- throw new IllegalArgumentException("could not have a null 'contentLayout' in ui " + context);
+ throw new IllegalArgumentException(
+ "could not have a null 'contentLayout' in ui " + context);
}
}
@@ -84,11 +90,13 @@
CardLayout2 layout = getContentLayout();
JPanel container = getContentContainer();
String constraints = strategy.getId(node);
- return layout.contains(constraints) ? layout.getComponent(container, constraints) : null;
+ return layout.contains(constraints) ?
+ layout.getComponent(container, constraints) : null;
}
@Override
- protected void openUI(Component newUI, NavigationTreeNode node) throws Exception {
+ protected void openUI(Component newUI, NavigationTreeNode node) throws
+ Exception {
CardLayout2 layout = getContentLayout();
JPanel container = getContentContainer();
@@ -108,7 +116,9 @@
JAXXContext uiContext = createUIContext(node);
- JAXXObject newUI = node.getUIClass().getConstructor(JAXXContext.class).newInstance(uiContext);
+ Constructor<? extends JAXXObject> constructor =
+ node.getUIClass().getConstructor(JAXXContext.class);
+ JAXXObject newUI = constructor.newInstance(uiContext);
if (log.isDebugEnabled()) {
log.debug("instanciate new ui " + newUI);
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -20,17 +20,6 @@
*/
package jaxx.runtime.swing.navigation;
-import java.lang.reflect.InvocationTargetException;
-import java.util.Enumeration;
-import java.util.regex.Pattern;
-import javax.swing.JTree;
-import javax.swing.tree.TreePath;
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jdesktop.swingx.JXTreeTable;
-
/**
* Helper object associated to a given navigation tree system.
*
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -32,6 +32,8 @@
*/
public class NavigationTreeModel extends GenericNavigationTreeModel<NavigationTreeNode> {
+ private static final long serialVersionUID = 1L;
+
public NavigationTreeModel(String pathSeparator, JAXXContext context) {
super(pathSeparator, context);
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -20,51 +20,71 @@
*/
package jaxx.runtime.swing.navigation;
-import java.util.Enumeration;
import jaxx.runtime.JAXXAction;
import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
import jaxx.runtime.context.JAXXContextEntryDef;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.decorator.Decorator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* This object is design to build a {@link NavigationTreeModel}.
*
+ * @author chemit
* @see NavigationModelBuilder
- *
- * @author chemit
* @since 17.2
*/
-public class NavigationTreeModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeNode>{
+public class NavigationTreeModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeNode> {
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(NavigationTreeModelBuilder.class);
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(NavigationTreeModelBuilder.class);
- public NavigationTreeModelBuilder(String pathSeparator, JAXXContext context, Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass) {
- this(defaultUIClass, defaultUIHandlerClass, new NavigationTreeModel(pathSeparator, context));
+ public NavigationTreeModelBuilder(
+ String pathSeparator,
+ JAXXContext context,
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass) {
+ this(defaultUIClass,
+ defaultUIHandlerClass,
+ new NavigationTreeModel(pathSeparator, context)
+ );
}
- public NavigationTreeModelBuilder(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, NavigationTreeModel model) {
+ @Override
+ public NavigationTreeModel getModel() {
+ return (NavigationTreeModel) super.getModel();
+ }
+
+ public NavigationTreeModelBuilder(
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass,
+ NavigationTreeModel model) {
super(defaultUIClass, defaultUIHandlerClass, model);
}
@Override
- public NavigationTreeNode createNavigationTreeNode(String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
- return new NavigationTreeNode(pathSeparator, contextName, jaxxContextEntryDef, jaxxContextEntryPath);
+ public NavigationTreeNode createNavigationTreeNode(
+ String pathSeparator,
+ String contextName,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
+ return new NavigationTreeNode(
+ pathSeparator,
+ contextName,
+ jaxxContextEntryDef,
+ jaxxContextEntryPath
+ );
}
- // TODO : to remove
- /**
- * @deprecated please use NavigationModel for return type
- * @return the tree model
- */
- @Override
- @Deprecated
- public NavigationTreeModel getModel() {
- return (NavigationTreeModel)super.getModel();
- }
+// // TODO : to remove
+// /**
+// * @deprecated please use NavigationModel for return type
+// * @return the tree model
+// */
+// @Override
+// @Deprecated
+// public NavigationTreeModel getModel() {
+// return (NavigationTreeModel)super.getModel();
+// }
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNode.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -58,7 +58,7 @@
* <p/>
* To display the node we use a {@link NavigationTreeNodeRenderer} which is in
* fact the {@link #userObject}, the object can be synch with the bean via the
- * {@link NavigationTreeNodeRenderer#reload(java.lang.Object)} method.
+ * {@link NavigationTreeNodeRenderer#reload(Object)} method.
*
* @author chemit
* @see NavigationTreeModel
@@ -165,24 +165,28 @@
*/
protected Class<?> internalClass;
- public NavigationTreeNode(String pathSeparator, String navigationPath, Object jaxxContextEntryDef) {
- super();
+ public NavigationTreeNode(String pathSeparator,
+ String navigationPath,
+ Object jaxxContextEntryDef) {
this.pathSeparator = pathSeparator;
- this.path = navigationPath;
+ path = navigationPath;
if (jaxxContextEntryDef instanceof JAXXContextEntryDef<?>) {
this.jaxxContextEntryDef = ((JAXXContextEntryDef<?>) jaxxContextEntryDef);
} else if (jaxxContextEntryDef instanceof String) {
- this.jaxxContextEntryPath = (String) jaxxContextEntryDef;
+ jaxxContextEntryPath = (String) jaxxContextEntryDef;
} else if (jaxxContextEntryDef != null) {
// wrong context definition type
- throw new IllegalArgumentException("to define a context link, must be a String (jxpath) or a " + JAXXContextEntryDef.class + ", but was " + jaxxContextEntryDef);
+ throw new IllegalArgumentException(
+ "to define a context link, must be a String (jxpath) or a " + JAXXContextEntryDef.class + ", but was " + jaxxContextEntryDef);
}
}
- public NavigationTreeNode(String pathSeparator, String navigationPath, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
- super();
+ public NavigationTreeNode(String pathSeparator,
+ String navigationPath,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
this.pathSeparator = pathSeparator;
- this.path = navigationPath;
+ path = navigationPath;
this.jaxxContextEntryDef = jaxxContextEntryDef;
this.jaxxContextEntryPath = jaxxContextEntryPath;
}
@@ -212,7 +216,7 @@
}
public void setNodePath(String navigationPath) {
- this.path = navigationPath;
+ path = navigationPath;
}
public Class<? extends JAXXObject> getUIClass() {
@@ -316,7 +320,8 @@
NavigationTreeNodeRenderer renderer = getRenderer();
if (renderer == null) {
// this can't be !
- throw new NullPointerException("could not find the renderer for node " + this);
+ throw new NullPointerException(
+ "could not find the renderer for node " + this);
}
String s = getFullPath();
@@ -354,7 +359,8 @@
// find the first ancestor node with a context def
NavigationTreeNode parentNode = getFirstAncestorWithDef();
if (parentNode == null) {
- log.warn("could not find a ancestor node with a definition of a context entry from node (" + this + ")");
+ log.warn("could not find a ancestor node with a definition of" +
+ " a context entry from node (" + this + ")");
// todo must be an error
// no parent found
return null;
@@ -362,7 +368,8 @@
Object parentBean = parentNode.getJaxxContextEntryDef().getContextValue(context);
if (parentBean == null) {
// must be an error no bean found
- log.warn("could not find a bean attached in context from context entry definition " + parentNode.getJaxxContextEntryDef());
+ log.warn("could not find a bean attached in context from context" +
+ " entry definition " + parentNode.getJaxxContextEntryDef());
return null;
}
if (parentNode.jaxxContextEntryPath != null) {
@@ -372,19 +379,23 @@
}
// save in cache
parentNode.setBean(parentBean);
- if (this == parentNode) {
- // current node is the node matching the context entry value and no jxpath is found
+ if (parentNode.equals(this)) {
+ // current node is the node matching the context entry value and
+ // no jxpath is found
return parentBean;
}
if (jaxxContextEntryPath == null) {
// todo must be an error
- log.warn("must find a jaxxContextEntryPath on node (" + this + ")");
+ log.warn("must find a jaxxContextEntryPath on node (" + this +
+ ")");
return null;
}
- String jxpathExpression = computeJXPath(jaxxContextEntryPath, parentNode);
+ String jxpathExpression = computeJXPath(jaxxContextEntryPath,
+ parentNode);
if (jxpathExpression == null) {
/// todo must be an error
- log.warn("could not build jxpath from node " + parentNode + " to " + this);
+ log.warn("could not build jxpath from node " + parentNode +
+ " to " + this);
// could not retreave the jxpath...
return null;
}
@@ -418,7 +429,7 @@
}
protected String computeJXPath(String expr, NavigationTreeNode parentNode) {
- if (parentNode == this) {
+ if (this == parentNode) {
// reach the parent limit node, return the expr computed
return expr;
}
@@ -427,11 +438,13 @@
if (firstIndex == -1) {
// this is a error, since current node is not parent limit node,
// we must find somewhere a way to go up in nodes
- throw new IllegalArgumentException(expr + " should contains at least one \"..\"");
+ throw new IllegalArgumentException(
+ expr + " should contains at least one \"..\"");
}
if (firstIndex != 0) {
// this is a error, the ../ must be at the beginning of the expression
- throw new IllegalArgumentException("\"..\" must be at the beginning but was : " + expr);
+ throw new IllegalArgumentException(
+ "\"..\" must be at the beginning but was : " + expr);
}
NavigationTreeNode ancestor = getParent();
if (firstIndex == lastIndex) {
@@ -444,17 +457,27 @@
}
// ancestor must have a jaxxContextEntryPath
if (ancestor.jaxxContextEntryPath == null) {
- throw new IllegalArgumentException("with the expression " + expr + ", the ancestor node (" + ancestor + ") must have a jaxxContextEntryPath definition, but was not ");
+ throw new IllegalArgumentException(
+ "with the expression " + expr + ", the ancestor node ("
+ + ancestor + ") must have a jaxxContextEntryPath " +
+ "definition, but was not ");
}
newExpr = ancestor.jaxxContextEntryPath + newExpr;
return ancestor.computeJXPath(newExpr, parentNode);
}
- // have more than one go up, so the ancestor node can not have a jaxxContextEntryPath
+ // have more than one go up, so the ancestor node can not have a
+ // jaxxContextEntryPath
if (ancestor.jaxxContextEntryPath != null) {
- throw new IllegalArgumentException("with the expression " + expr + ", the ancestor node can not have a jaxxContextEntryPath definition");
+ throw new IllegalArgumentException(
+ "with the expression " + expr + ", the ancestor node can " +
+ "not have a jaxxContextEntryPath definition");
}
// substitute the last ..[/] and delegate to ancestor
- String newExpr = expr.substring(0, lastIndex - 1) + expr.substring(lastIndex + (expr.charAt(lastIndex + 3) == '/' ? 3 : 2));
+ String newExpr = expr.substring(0, lastIndex - 1) +
+ expr.substring(
+ lastIndex +
+ (expr.charAt(lastIndex + 3) == '/' ? 3 : 2)
+ );
return ancestor.computeJXPath(newExpr, parentNode);
}
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRenderer.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -21,6 +21,7 @@
package jaxx.runtime.swing.navigation;
import javax.swing.tree.TreeCellRenderer;
+import java.io.Serializable;
/**
* Text Renderer of a {@link NavigationTreeNode}.
@@ -38,7 +39,7 @@
* @author chemit
* @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear soon...
*/
-public interface NavigationTreeNodeRenderer extends java.io.Serializable {
+public interface NavigationTreeNodeRenderer extends Serializable {
/**
*
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererDecoratorImpl.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -24,30 +24,28 @@
/**
* Decorator Renderer of a {@link NavigationTreeNode}.
- *
+ * <p/>
* Apply a {@link Decorator} to the {@code bean} associated to the node.
- *
+ *
* @author chemit
- * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear soon...
+ * @since 1.7.2, replace {@code NavigationUtil#NodeRenderer} which disappear
+ * soon...
*/
public class NavigationTreeNodeRendererDecoratorImpl implements NavigationTreeNodeRenderer {
private static final long serialVersionUID = -1L;
- /**
- * Decorator
- */
+
+ /** Decorator */
protected final Decorator<?> decorator;
- /**
- * internal class of representing data
- */
+
+ /** internal class of representing data */
protected final Class<?> internalClass;
- /**
- * last renderered value
- */
+
+ /** last renderered value */
protected String text;
public NavigationTreeNodeRendererDecoratorImpl(Decorator<?> decorator) {
- this.internalClass = decorator.getInternalClass();
+ internalClass = decorator.getInternalClass();
this.decorator = decorator;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeNodeRendererI18nImpl.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -48,7 +48,7 @@
public NavigationTreeNodeRendererI18nImpl(String libelle) {
this.libelle = libelle;
- this.internalClass = String.class;
+ internalClass = String.class;
}
@Override
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-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -25,7 +25,6 @@
import org.apache.commons.logging.LogFactory;
import org.jdesktop.swingx.tree.TreeModelSupport;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
-import org.jdesktop.swingx.treetable.TreeTableNode;
import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeNode;
@@ -40,9 +39,9 @@
* Model of the tree table used for a navigation tree table.
* <p/>
* Il est composé de {@link NavigationTreeNode}
+ * <p/>
+ * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeModel}
*
- * FIXME : Essayer d'enlever les copier coller {@link NavigationTreeModel}
- *
* @author sletellier
* @since 2.0.0
*/
@@ -50,10 +49,9 @@
static private final long serialVersionUID = 1L;
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(NavigationTreeTableModel.class);
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(NavigationTreeTableModel.class);
/**
* The path separator used to build the {@link NavigationTreeNode#fullPath}.
@@ -63,9 +61,7 @@
*/
protected final String pathSeparator;
- /**
- * Context to retrieve beans
- */
+ /** Context to retrieve beans */
private JAXXContext context;
protected List<String> columnsName;
@@ -77,20 +73,17 @@
this.columnsName = columnsName;
}
- /**
- * @see NavigationModel#getRoot()
- */
@Override
public NavigationTreeTableNode getRoot() {
return (NavigationTreeTableNode) super.root;
}
@Override
- public TreeNode[] getPathToRoot(TreeNode aNode) {
- if (aNode == null){
+ public NavigationTreeTableNode[] getPathToRoot(NavigationTreeTableNode aNode) {
+ if (aNode == null) {
return null;
}
- return super.getPathToRoot((TreeTableNode)aNode);
+ return (NavigationTreeTableNode[]) super.getPathToRoot(aNode);
}
@@ -106,8 +99,8 @@
* way to remove a node as it handles the event creation for you.
*/
@Override
- public void removeNodeFromParent(MutableTreeNode node) {
- NavigationTreeTableNode parent = (NavigationTreeTableNode)node.getParent();
+ public void removeNodeFromParent(NavigationTreeTableNode node) {
+ NavigationTreeTableNode parent = node.getParent();
if (parent == null) {
throw new IllegalArgumentException("node does not have a parent.");
@@ -117,54 +110,42 @@
node.removeFromParent();
modelSupport.fireChildRemoved(new TreePath(getPathToRoot(parent)),
- index, node);
+ index, node);
}
- /**
- * @see NavigationModel#findNode(String)
- */
@Override
public NavigationTreeTableNode findNode(String path) {
return findNode(getRoot(), path, (Pattern) null);
}
- /**
- * @see NavigationModel#findNode(String, String)
- */
@Override
public NavigationTreeTableNode findNode(String path, String regex) {
return findNode(getRoot(), path, regex);
}
- /**
- * @see NavigationModel#findNode(String, Pattern)
- */
@Override
public NavigationTreeTableNode findNode(String path, Pattern regex) {
return findNode(getRoot(), path, regex);
}
- /**
- * @see NavigationModel#findNode(NavigationTreeNode, String)
- */
@Override
- public NavigationTreeTableNode findNode(NavigationTreeTableNode root, String path) {
+ public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
+ String path) {
return findNode(root, path, (Pattern) null);
}
- /**
- * @see NavigationModel#findNode(NavigationTreeNode, String, String)
- */
@Override
- public NavigationTreeTableNode findNode(NavigationTreeTableNode root, String path, String regex) {
- return findNode(root, path, regex == null ? null : Pattern.compile(regex));
+ public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
+ String path,
+ String regex) {
+ return findNode(root, path, regex == null ?
+ null : Pattern.compile(regex));
}
- /**
- * @see NavigationModel#findNode(NavigationTreeNode, String, Pattern)
- */
@Override
- public NavigationTreeTableNode findNode(NavigationTreeTableNode root, String path, Pattern regex) {
+ public NavigationTreeTableNode findNode(NavigationTreeTableNode root,
+ String path,
+ Pattern regex) {
if (regex != null) {
Matcher matcher = regex.matcher(path);
if (!matcher.matches() || matcher.groupCount() < 1) {
@@ -191,16 +172,11 @@
return result;
}
- /**
- * @see NavigationModel#getContext()
- */
+ @Override
public JAXXContext getContext() {
return context;
}
- /**
- * @see NavigationModel#getBean(String)
- */
@Override
public Object getBean(String navigationPath) {
Object result;
@@ -209,9 +185,6 @@
return result;
}
- /**
- * @see NavigationModel#getBean(NavigationTreeNode)
- */
@Override
public Object getBean(NavigationTreeTableNode node) {
if (node == null) {
@@ -232,60 +205,71 @@
return modelSupport;
}
- /**
- * @see NavigationModel#nodeChanged(TreeNode)
- */
- public void nodeChanged(TreeNode node) {
- if (node != null){
- MutableTreeNode parent = (MutableTreeNode)node.getParent();
- TreeNode[] treeNodes = getPathToRoot(parent);
- if (treeNodes != null){
- modelSupport.fireChildChanged(new TreePath(treeNodes), parent.getIndex(node), node);
+ @Override
+ public void nodeChanged(NavigationTreeTableNode node) {
+ if (node != null) {
+ NavigationTreeTableNode parent = node.getParent();
+ NavigationTreeTableNode[] treeNodes = getPathToRoot(parent);
+ if (treeNodes != null) {
+ modelSupport.fireChildChanged(
+ new TreePath(treeNodes), parent.getIndex(node), node);
} else {
log.error("[Node changed] Path to root is null !");
}
- reload((NavigationTreeTableNode)node, true);
+ reload((NavigationTreeTableNode) node, true);
} else {
log.error("Node is null !");
}
}
- /**
- * @see NavigationModel#nodeStructureChanged(TreeNode)
- */
- public void nodeStructureChanged(TreeNode node) {
- if (node != null){
- MutableTreeNode parent = (MutableTreeNode)node.getParent();
+ @Override
+ public void nodeStructureChanged(NavigationTreeTableNode node) {
+ if (node != null) {
+ NavigationTreeTableNode parent = node.getParent();
TreeNode[] treeNodes = getPathToRoot(parent);
- if (treeNodes != null){
+ if (treeNodes != null) {
modelSupport.fireTreeStructureChanged(new TreePath(treeNodes));
} else {
log.error("[Node structure changed] Path to root is null !");
}
- reload((NavigationTreeTableNode)node, true);
+ reload(node, true);
} else {
log.error("Node is null !");
}
}
- /**
- * @see NavigationModel#nodeChanged(TreeNode, boolean)
- */
- public void nodeChanged(TreeNode node, boolean deep) {
- if (node != null){
- MutableTreeNode parent = (MutableTreeNode)node.getParent();
+ @Override
+ public void nodeChanged(NavigationTreeTableNode node, boolean deep) {
+ if (node != null) {
+ NavigationTreeTableNode parent = node.getParent();
TreeNode[] treeNodes = getPathToRoot(parent);
- if (treeNodes != null){
- modelSupport.fireChildChanged(new TreePath(treeNodes), parent.getIndex(node), node);
+ if (treeNodes != null) {
+ modelSupport.fireChildChanged(
+ new TreePath(treeNodes), parent.getIndex(node), node);
} else {
log.error("[Node changed] Path to root is null !");
}
- reload((NavigationTreeTableNode)node, deep);
+ reload(node, deep);
} else {
log.error("Node is null !");
}
}
+ @Override
+ public String getPathSeparator() {
+ return pathSeparator;
+ }
+
+ @Override
+ public int getColumnCount() {
+ return columnsName.size();
+ }
+
+ @Override
+ public String getColumnName(int column) {
+ return columnsName.get(column);
+ }
+
protected void reload(NavigationTreeTableNode node) {
reload(node, false);
}
@@ -305,21 +289,4 @@
}
}
- /**
- * @see NavigationModel#getPathSeparator()
- */
- public String getPathSeparator() {
- return pathSeparator;
- }
-
- @Override
- public int getColumnCount(){
- return columnsName.size();
- }
-
- @Override
- public String getColumnName(int column){
- return columnsName.get(column);
- }
-
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableNode.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -28,19 +28,27 @@
/**
* Node of the {@link NavigationTreeTableModel}.
*
+ * @author sletellier
* @see NavigationTreeNode
- *
- * @author sletellier
* @since 2.0.0
*/
-public abstract class NavigationTreeTableNode extends NavigationTreeNode implements TreeTableNode{
+public abstract class NavigationTreeTableNode extends NavigationTreeNode implements TreeTableNode {
- public NavigationTreeTableNode(String pathSeparator, String navigationPath, Object jaxxContextEntryDef) {
+ public NavigationTreeTableNode(String pathSeparator,
+ String navigationPath,
+ Object jaxxContextEntryDef) {
super(pathSeparator, navigationPath, jaxxContextEntryDef);
}
- public NavigationTreeTableNode(String pathSeparator, String navigationPath, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
- super(pathSeparator, navigationPath, jaxxContextEntryDef, jaxxContextEntryPath);
+ public NavigationTreeTableNode(String pathSeparator,
+ String navigationPath,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
+ super(pathSeparator,
+ navigationPath,
+ jaxxContextEntryDef,
+ jaxxContextEntryPath
+ );
}
@Override
@@ -53,14 +61,12 @@
return (NavigationTreeTableNode) super.getParent();
}
- /**
- * @see NavigationTreeNode#getChild(String)
- */
@Override
public NavigationTreeTableNode getChild(String path) {
Enumeration<?> childs = children();
while (childs.hasMoreElements()) {
- NavigationTreeTableNode son = (NavigationTreeTableNode) childs.nextElement();
+ NavigationTreeTableNode son =
+ (NavigationTreeTableNode) childs.nextElement();
if (path.equals(son.getNodePath())) {
return son;
}
@@ -68,11 +74,15 @@
return null;
}
+ @Override
public abstract Object getValueAt(int column);
+ @Override
public abstract int getColumnCount();
+ @Override
public abstract boolean isEditable(int column);
+ @Override
public abstract void setValueAt(Object aValue, int column);
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -27,26 +27,37 @@
import org.apache.commons.logging.LogFactory;
/**
- * This object is design to build a {@link NavigationTreeModel} with sorted nodes {@link SortedNavigationTreeNode} .
+ * This object is design to build a {@link NavigationTreeModel} with sorted
+ * nodes {@link SortedNavigationTreeNode} .
*
+ * @author sletellier
* @see NavigationModelBuilder
- *
- * @author sletellier
* @since 2.0.1
*/
public class SortedNavigationTreeModelBuilder extends AbstractNavigationModelBuilder<SortedNavigationTreeNode> {
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(SortedNavigationTreeModelBuilder.class);
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(SortedNavigationTreeModelBuilder.class);
- public SortedNavigationTreeModelBuilder(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, NavigationModel<SortedNavigationTreeNode> navigationModel) {
+ public SortedNavigationTreeModelBuilder(
+ Class<? extends JAXXObject> defaultUIClass,
+ Class<? extends JAXXAction> defaultUIHandlerClass,
+ NavigationModel<SortedNavigationTreeNode> navigationModel) {
super(defaultUIClass, defaultUIHandlerClass, navigationModel);
}
@Override
- public SortedNavigationTreeNode createNavigationTreeNode(String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
- return new SortedNavigationTreeNode(pathSeparator, contextName, jaxxContextEntryDef, jaxxContextEntryPath);
+ public SortedNavigationTreeNode createNavigationTreeNode(
+ String pathSeparator,
+ String contextName,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
+ return new SortedNavigationTreeNode(
+ pathSeparator,
+ contextName,
+ jaxxContextEntryDef,
+ jaxxContextEntryPath
+ );
}
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -20,29 +20,31 @@
*/
package jaxx.runtime.swing.navigation;
-import jaxx.runtime.JAXXContext;
import jaxx.runtime.context.JAXXContextEntryDef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.swing.tree.MutableTreeNode;
-import java.util.*;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Enumeration;
+import java.util.List;
/**
* Sprted node
*
+ * @author sletellier
* @see NavigationTreeNode
- *
- * @author sletellier
* @since 2.0.1
*/
public class SortedNavigationTreeNode extends NavigationTreeNode {
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(SortedNavigationTreeNode.class);
+ private static final long serialVersionUID = -1L;
+ /** Logger */
+ static private final Log log =
+ LogFactory.getLog(SortedNavigationTreeNode.class);
+
@Override
public SortedNavigationTreeNode getChildAt(int index) {
return (SortedNavigationTreeNode) super.getChildAt(index);
@@ -52,13 +54,19 @@
public SortedNavigationTreeNode getParent() {
return (SortedNavigationTreeNode) super.getParent();
}
-
+
@Override
+ public Enumeration<SortedNavigationTreeNode> children() {
+ return super.children();
+ }
+
+ @Override
public void add(MutableTreeNode newChild) {
- List<SortedNavigationTreeNode> children = Collections.list(children());
+ List<SortedNavigationTreeNode> children =
+ Collections.list(children());
- if (children.isEmpty()){
+ if (children.isEmpty()) {
insert(newChild, 0);
return;
}
@@ -70,19 +78,29 @@
Collections.sort(children, rendererDecorator);
int index = children.indexOf(newChild);
- log.info("Insert node : " + newNode.getRenderer().toString() + " in " + index + " of parent " + this.getRenderer().toString());
+ log.info("Insert node : " + newNode.getRenderer().toString() + " in " +
+ index + " of parent " + this.getRenderer().toString());
insert(newChild, index);
}
- public SortedNavigationTreeNode(String pathSeparator, String navigationPath, Object jaxxContextEntryDef) {
+ public SortedNavigationTreeNode(String pathSeparator,
+ String navigationPath,
+ Object jaxxContextEntryDef) {
super(pathSeparator, navigationPath, jaxxContextEntryDef);
// sort();
}
- public SortedNavigationTreeNode(String pathSeparator, String navigationPath, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
- super(pathSeparator, navigationPath, jaxxContextEntryDef, jaxxContextEntryPath);
+ public SortedNavigationTreeNode(String pathSeparator,
+ String navigationPath,
+ JAXXContextEntryDef<?> jaxxContextEntryDef,
+ String jaxxContextEntryPath) {
+ super(pathSeparator,
+ navigationPath,
+ jaxxContextEntryDef,
+ jaxxContextEntryPath
+ );
// sort();
}
@@ -114,12 +132,12 @@
// }
// }
- final Comparator rendererDecorator = new Comparator() {
+ final Comparator<NavigationTreeNode> rendererDecorator = new Comparator<NavigationTreeNode>() {
@Override
- public int compare(Object o1, Object o2) {
+ public int compare(NavigationTreeNode o1, NavigationTreeNode o2) {
try {
- String label1 = ((NavigationTreeNode)o1).getRenderer().toString();
- String label2 = ((NavigationTreeNode)o2).getRenderer().toString();
+ String label1 = ((NavigationTreeNode) o1).getRenderer().toString();
+ String label2 = ((NavigationTreeNode) o2).getRenderer().toString();
return label1.compareToIgnoreCase(label2);
} catch (Exception eee) {
return 0;
Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java
===================================================================
--- trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-03-25 13:20:44 UTC (rev 1807)
+++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-03-25 16:35:00 UTC (rev 1808)
@@ -20,9 +20,9 @@
*/
package jaxx.runtime.swing.navigation;
+import jaxx.runtime.JAXXContext;
import jaxx.runtime.JAXXUtil;
import jaxx.runtime.context.DefaultJAXXContext;
-import jaxx.runtime.JAXXContext;
import org.junit.Assert;
import org.junit.Test;
@@ -38,7 +38,9 @@
public class NavigationTreeModelTest {
private static final String ROOT_CONTEXT = "$root";
+
private static final String FAKE = "-fake";
+
private static final String separator = "/";
@Test
@@ -58,7 +60,7 @@
}
}
- NavigationTreeModel model = builder.getModel();
+ NavigationModel<?> model = builder.getModel();
NavigationTreeNode node;
String contextPath;
@@ -151,10 +153,10 @@
context.setContextValue(
new Model("modelName", 10,
- Arrays.asList(
- new Model("one", 1, Collections.<Model>emptyList()),
- new Model("two", 2, Collections.<Model>emptyList()),
- new Model("three", 3, Collections.<Model>emptyList()))));
+ Arrays.asList(
+ new Model("one", 1, Collections.<Model>emptyList()),
+ new Model("two", 2, Collections.<Model>emptyList()),
+ new Model("three", 3, Collections.<Model>emptyList()))));
NavigationTreeModelBuilder builder = new NavigationTreeModelBuilder(separator, context, null, null);
@@ -193,32 +195,32 @@
builder.build(sonSonSonNode, (String) null, "../..[3]/integerValue", "integerValue", null, null);
builder.build(sonSonSonNode, (String) null, "../..[3]/sons", "sons", null, null);
- NavigationTreeModel model = builder.getModel();
+ NavigationModel<?> model = builder.getModel();
Assert.assertNull(model.getBean("$root.name" + FAKE));
- testBinding(model, context, "$root/name", context.getContextValue(String.class, "name"));
- testBinding(model, context, "$root/name2", context.getContextValue(String.class, "name2"));
+ testBinding(model, "$root/name", context.getContextValue(String.class, "name"));
+ testBinding(model, "$root/name2", context.getContextValue(String.class, "name2"));
Model bean = context.getContextValue(Model.class);
- testBinding(model, context, "$root/model", bean);
- testBinding(model, context, "$root/model/name", bean.getName());
- testBinding(model, context, "$root/model/integerValue", bean.getIntegerValue());
- testBinding(model, context, "$root/model/sons", bean.getSons());
+ testBinding(model, "$root/model", bean);
+ testBinding(model, "$root/model/name", bean.getName());
+ testBinding(model, "$root/model/integerValue", bean.getIntegerValue());
+ testBinding(model, "$root/model/sons", bean.getSons());
- testBinding(model, context, "$root/model/sons/0/name", bean.getSons().get(0).getName());
- testBinding(model, context, "$root/model/sons/0/integerValue", bean.getSons().get(0).getIntegerValue());
- testBinding(model, context, "$root/model/sons/0/sons", bean.getSons().get(0).getSons());
+ testBinding(model, "$root/model/sons/0/name", bean.getSons().get(0).getName());
+ testBinding(model, "$root/model/sons/0/integerValue", bean.getSons().get(0).getIntegerValue());
+ testBinding(model, "$root/model/sons/0/sons", bean.getSons().get(0).getSons());
- testBinding(model, context, "$root/model/sons/1/name", bean.getSons().get(1).getName());
- testBinding(model, context, "$root/model/sons/1/integerValue", bean.getSons().get(1).getIntegerValue());
- testBinding(model, context, "$root/model/sons/1/sons", bean.getSons().get(1).getSons());
+ testBinding(model, "$root/model/sons/1/name", bean.getSons().get(1).getName());
+ testBinding(model, "$root/model/sons/1/integerValue", bean.getSons().get(1).getIntegerValue());
+ testBinding(model, "$root/model/sons/1/sons", bean.getSons().get(1).getSons());
- testBinding(model, context, "$root/model/sons/2/name", bean.getSons().get(2).getName());
- testBinding(model, context, "$root/model/sons/2/integerValue", bean.getSons().get(2).getIntegerValue());
- testBinding(model, context, "$root/model/sons/2/sons", bean.getSons().get(2).getSons());
+ testBinding(model, "$root/model/sons/2/name", bean.getSons().get(2).getName());
+ testBinding(model, "$root/model/sons/2/integerValue", bean.getSons().get(2).getIntegerValue());
+ testBinding(model, "$root/model/sons/2/sons", bean.getSons().get(2).getSons());
}
/**
@@ -259,20 +261,20 @@
List<Model> list = Arrays.asList(
new Model("entryOne", 10,
- Arrays.asList(
- new Model("one", 1, Collections.<Model>emptyList()),
- new Model("two", 2, Collections.<Model>emptyList()),
- new Model("three", 3, Collections.<Model>emptyList()))),
+ Arrays.asList(
+ new Model("one", 1, Collections.<Model>emptyList()),
+ new Model("two", 2, Collections.<Model>emptyList()),
+ new Model("three", 3, Collections.<Model>emptyList()))),
new Model("entryTwo", 20,
- Arrays.asList(
- new Model("2one", 1, Collections.<Model>emptyList()),
- new Model("2two", 2, Collections.<Model>emptyList()),
- new Model("2three", 3, Collections.<Model>emptyList()))),
+ Arrays.asList(
+ new Model("2one", 1, Collections.<Model>emptyList()),
+ new Model("2two", 2, Collections.<Model>emptyList()),
+ new Model("2three", 3, Collections.<Model>emptyList()))),
new Model("entryThree", 30,
- Arrays.asList(
- new Model("3one", 1, Collections.<Model>emptyList()),
- new Model("3two", 2, Collections.<Model>emptyList()),
- new Model("3three", 3, Collections.<Model>emptyList()))));
+ Arrays.asList(
+ new Model("3one", 1, Collections.<Model>emptyList()),
+ new Model("3two", 2, Collections.<Model>emptyList()),
+ new Model("3three", 3, Collections.<Model>emptyList()))));
JAXXContext context = new DefaultJAXXContext();
context.setContextValue(list, "models");
@@ -312,35 +314,37 @@
builder.build(sonSonNode, (String) null, "../integerValue", "integerValue", null, null);
builder.build(sonSonNode, (String) null, "../sons", "sons", null, null);
- NavigationTreeModel model = builder.getModel();
+ NavigationModel<?> model = builder.getModel();
Model bean;
- testBinding(model, context, "$root/models", list);
+ testBinding(model, "$root/models", list);
bean = list.get(0);
- testBinding(model, context, "$root/models/0", bean);
- testBinding(model, context, "$root/models/0/name", bean.getName());
- testBinding(model, context, "$root/models/0/integerValue", bean.getIntegerValue());
- testBinding(model, context, "$root/models/0/sons", bean.getSons());
- testBinding(model, context, "$root/models/0/sons/0", bean.getSons().get(0));
- testBinding(model, context, "$root/models/0/sons/0/name", bean.getSons().get(0).getName());
+ testBinding(model, "$root/models/0", bean);
+ testBinding(model, "$root/models/0/name", bean.getName());
+ testBinding(model, "$root/models/0/integerValue", bean.getIntegerValue());
+ testBinding(model, "$root/models/0/sons", bean.getSons());
+ testBinding(model, "$root/models/0/sons/0", bean.getSons().get(0));
+ testBinding(model, "$root/models/0/sons/0/name", bean.getSons().get(0).getName());
bean = list.get(1);
- testBinding(model, context, "$root/models/1", bean);
- testBinding(model, context, "$root/models/1/name", bean.getName());
- testBinding(model, context, "$root/models/1/integerValue", bean.getIntegerValue());
- testBinding(model, context, "$root/models/1/sons", bean.getSons());
+ testBinding(model, "$root/models/1", bean);
+ testBinding(model, "$root/models/1/name", bean.getName());
+ testBinding(model, "$root/models/1/integerValue", bean.getIntegerValue());
+ testBinding(model, "$root/models/1/sons", bean.getSons());
bean = list.get(2);
- testBinding(model, context, "$root/models/2", bean);
- testBinding(model, context, "$root/models/2/name", bean.getName());
- testBinding(model, context, "$root/models/2/integerValue", bean.getIntegerValue());
- testBinding(model, context, "$root/models/2/sons", bean.getSons());
+ testBinding(model, "$root/models/2", bean);
+ testBinding(model, "$root/models/2/name", bean.getName());
+ testBinding(model, "$root/models/2/integerValue", bean.getIntegerValue());
+ testBinding(model, "$root/models/2/sons", bean.getSons());
}
- protected void testBinding(NavigationTreeModel model, JAXXContext context, String contextPath, Object expected) throws Exception {
+ protected void testBinding(NavigationModel<?> model,
+ String contextPath,
+ Object expected) throws Exception {
Object value;
value = model.getBean(contextPath);
@@ -368,7 +372,9 @@
public static class Model {
protected String name;
+
protected int integerValue;
+
protected List<Model> sons;
public Model(String name, int integerValue, List<Model> sons) {
1
0
r1807 - trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation
by sletellier@users.nuiton.org 25 Mar '10
by sletellier@users.nuiton.org 25 Mar '10
25 Mar '10
Author: sletellier
Date: 2010-03-25 14:20:44 +0100 (Thu, 25 Mar 2010)
New Revision: 1807
Log:
- Remove sorted tree adapter
- Refactor helper to create generic builder / helper / model
- Creating builder to build a sorted model
Added:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java
Removed:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationSortedTreeAdapter.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java
Modified:
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java
trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/AbstractNavigationModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -0,0 +1,262 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXContextEntryDef;
+import jaxx.runtime.decorator.Decorator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.Enumeration;
+
+/**
+ * Interface to create a builder, this object is design to build a
+ * {@link NavigationModel}.
+ *
+ * @author sletellier
+ * @since 2.0.0
+ */
+public abstract class AbstractNavigationModelBuilder<E extends NavigationTreeNode> implements NavigationModelBuilder<E> {
+
+ /**
+ * Logger
+ */
+ static private final Log log = LogFactory.getLog(AbstractNavigationModelBuilder.class);
+ /**
+ * The model dealed by the builder.
+ *
+ * <b>Note:</b> It is a good idea to keep only one instance of the model.
+ * If reset is required, should empty the model but not reinstanciate it.
+ */
+ protected NavigationModel<E> model;
+ /**
+ * default ui class to use if node does not define an ui class
+ */
+ protected Class<? extends JAXXObject> defaultUIClass;
+ /**
+ * [optional] default action class
+ */
+ protected Class<? extends JAXXAction> defaultUIHandlerClass;
+
+ public AbstractNavigationModelBuilder(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, NavigationModel<E> model) {
+ this.defaultUIClass = defaultUIClass;
+ this.defaultUIHandlerClass = defaultUIHandlerClass;
+ this.model = model;
+ }
+
+ public NavigationModel<E> getModel() {
+ return model;
+ }
+
+ public E buildEmptyRoot(JAXXContextEntryDef<?> entryDef, String contextName) {
+ E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, null);
+ addI18nNodeRenderer(node, "");
+ return addChildNode(null, node);
+ }
+
+ public E build(E parentNode, String libelle,
+ JAXXContextEntryDef<?> entryDef,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, entryPath);
+ addI18nNodeRenderer(node, libelle);
+ addNodeJaxxClasses(node, uiClass, actionClass);
+ return addChildNode(parentNode, node);
+ }
+
+ public E build(E parentNode, String libelle,
+ JAXXContextEntryDef<?> entryDef,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, null);
+ addI18nNodeRenderer(node, libelle);
+ addNodeJaxxClasses(node, uiClass, actionClass);
+ return addChildNode(parentNode, node);
+ }
+
+ public E build(E parentNode, String libelle,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(model.getPathSeparator(), contextName, null, entryPath);
+ addI18nNodeRenderer(node, libelle);
+ addNodeJaxxClasses(node, uiClass, actionClass);
+ return addChildNode(parentNode, node);
+ }
+
+ public E build(E parentNode, Decorator<?> decorator,
+ JAXXContextEntryDef<?> entryDef,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, entryPath);
+ addDecoratorNodeRenderer(node, decorator);
+ addNodeJaxxClasses(node, uiClass, actionClass);
+ return addChildNode(parentNode, node);
+ }
+
+ public E build(E parentNode, Decorator<?> decorator,
+ JAXXContextEntryDef<?> entryDef,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(model.getPathSeparator(), contextName, entryDef, null);
+ addDecoratorNodeRenderer(node, decorator);
+ addNodeJaxxClasses(node, uiClass, actionClass);
+ return addChildNode(parentNode, node);
+ }
+
+ public E build(E parentNode, Decorator<?> decorator,
+ String entryPath,
+ String contextName,
+ Class<? extends JAXXObject> uiClass,
+ Class<? extends JAXXAction> actionClass) {
+ E node = createNavigationTreeNode(model.getPathSeparator(), contextName, null, entryPath);
+ addDecoratorNodeRenderer(node, decorator);
+ addNodeJaxxClasses(node, uiClass, actionClass);
+ return addChildNode(parentNode, node);
+ }
+
+ protected E addChildNode(E parentNode, E node) {
+
+ if (node.getUIClass() == null) {
+ // no ui is associated with this node, use the default one
+ node.setUIClass(defaultUIClass);
+ }
+
+ if (node.getUIHandlerClass() == null) {
+ // no ui handler associated with this node, use the default one
+ node.setUIHandlerClass(defaultUIHandlerClass);
+ }
+ if (parentNode == null) {
+ model.setRoot(node);
+ } else {
+ parentNode.add(node);
+ }
+ model.nodeStructureChanged(node);
+ return node;
+ }
+
+ public E removeChildNode(E node) {
+ E parentNode = (E)node.getParent();
+ model.removeNodeFromParent(node);
+ return parentNode;
+ }
+
+ public void addI18nNodeRenderer(E node, String libelle) {
+ node.setRenderer(new NavigationTreeNodeRendererI18nImpl(libelle));
+ }
+
+ public void addDecoratorNodeRenderer(E node, Decorator<?> decorator) {
+ node.setRenderer(new NavigationTreeNodeRendererDecoratorImpl(decorator));
+ }
+
+ public void addNodeJaxxClasses(
+ E node,
+ Class<? extends JAXXObject> uIClass,
+ Class<? extends JAXXAction> uIHandlerClass) {
+ node.setUIClass(uIClass);
+ node.setUIHandlerClass(uIHandlerClass);
+ }
+
+ public void printModel(E node) {
+ if (node == null) {
+ return;
+ }
+ log.info("node " + node.getFullPath() + ", jxpath: " + node.getJaxxContextEntryPath() + ", entryContextDef: " + node.getJaxxContextEntryDef());
+ if (log.isDebugEnabled()) {
+ log.debug("node userObject" + node.getUserObject());
+ log.debug("value from node " + node.getBean(getModel().getContext()));
+ log.debug("value from model " + getModel().getBean(node));
+ }
+ Enumeration<?> children = node.children();
+ while (children.hasMoreElements()) {
+ printModel((E) children.nextElement());
+ }
+ }
+
+ // To create your own instance of NavigationTreeTableNode
+ public abstract E createNavigationTreeNode(String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath);
+
+ public static abstract class ChildBuilder<O, E extends NavigationTreeNode> {
+
+ protected AbstractNavigationModelBuilder<E> builder;
+
+ protected ChildBuilder(AbstractNavigationModelBuilder<E> builder) {
+ this.builder = builder;
+ }
+
+ protected abstract void init(Class<? extends O> klass);
+
+ protected abstract Decorator<? extends O> getDecorator(O child);
+
+ protected abstract String getJXPath(O child);
+
+ protected abstract String getNavigationPath(O child);
+
+ public void build(E parent, boolean cacheValues, Class<? extends O> klass, java.util.Collection<? extends O> beans, Class<? extends JAXXObject> ui, Class<? extends JAXXAction> actionClass) {
+
+ if (beans == null || beans.isEmpty()) {
+ // no bean to treate
+ return;
+ }
+
+ init(klass);
+
+ E node;
+
+ for (O o : beans) {
+ node = builder.build(parent, getDecorator(o), getJXPath(o), getNavigationPath(o), ui, actionClass);
+ if (cacheValues) {
+ // cache the bean value to improve performance
+ node.setBean(o);
+ }
+ }
+ }
+
+ public void build(E parent, boolean cacheValues, Class<? extends O> klass, O[] beans, Class<? extends JAXXObject> ui, Class<? extends JAXXAction> actionClass) {
+
+ if (beans == null || beans.length == 0) {
+ // no bean to treate
+ return;
+ }
+
+ init(klass);
+
+ E node;
+
+ for (O o : beans) {
+ node = builder.build(parent, getDecorator(o), getJXPath(o), getNavigationPath(o), ui, actionClass);
+ if (cacheValues) {
+ // cache the bean value to improve performance
+ node.setBean(o);
+ }
+ }
+ }
+ }
+}
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationHelper.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -0,0 +1,309 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.JAXXObject;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdesktop.swingx.JXTreeTable;
+
+import javax.swing.*;
+import javax.swing.tree.TreePath;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Enumeration;
+import java.util.regex.Pattern;
+
+/**
+ * Helper object associated to a given navigation tree system.
+ *
+ * To helper is context safe (base on a {@link NavigationTreeContextHelper}.
+ *
+ * @author Letellier
+ * @since 2.0.1
+ * @see NavigationTreeModel
+ */
+public abstract class GenericNavigationHelper <E extends NavigationTreeNode> extends NavigationTreeContextHelper<E>{
+
+ /**
+ * Logger
+ */
+ static private final Log log =
+ LogFactory.getLog(NavigationTreeHelper.class);
+
+ /**
+ * Create the model.
+ *
+ * @param context the context to associate with fresh model
+ * @return the new model build with data from the given context
+ */
+ public abstract NavigationModel createTreeModel(JAXXContext context);
+
+ /**
+ * Create the tree handler.
+ *
+ * @param context the context to associate with fresh handler
+ * @return the new handler
+ */
+ public abstract NavigationTreeHandler createTreeHandler(JAXXObject context);
+
+ public GenericNavigationHelper(String contextPrefix) {
+ super(contextPrefix);
+ }
+
+ public Object getContextValue(JAXXContext context, String path)
+ throws InvocationTargetException, NoSuchMethodException,
+ IllegalAccessException {
+ NavigationModel treeModel = getSafeModel(context);
+ return treeModel.getBean(path);
+ }
+
+ public E findNode(JAXXContext context, String path) {
+ NavigationModel<E> treeModel = getSafeModel(context);
+ return treeModel.findNode(path);
+ }
+
+ public E findNode(JAXXContext context, String path,
+ String regex) {
+ NavigationModel<E> treeModel = getSafeModel(context);
+ return treeModel.findNode(path, regex);
+ }
+
+ public E findNode(JAXXContext context, String path,
+ Pattern regex) {
+
+ NavigationModel<E> treeModel = getSafeModel(context);
+ return treeModel.findNode(path, regex);
+ }
+
+ public E findNode(JAXXContext context, String path,
+ String regex, String suffix) {
+
+ NavigationModel<E> treeModel = getSafeModel(context);
+
+ E node= treeModel.findNode(path, regex);
+ if (node != null && suffix != null) {
+ node = treeModel.findNode(node, suffix);
+ }
+ return node;
+ }
+
+ public E findNode(JAXXContext context, String path,
+ Pattern regex, String suffix) {
+
+ NavigationModel<E> treeModel = getSafeModel(context);
+
+ E node = treeModel.findNode(path, regex);
+ if (node != null && suffix != null) {
+ node = treeModel.findNode(node, suffix);
+ }
+ return node;
+ }
+
+ /**
+ * Sélection d'un noeud dans l'arbre de navigation à partir de son path.
+ *
+ * @param context le contexte applicatif
+ * @param path le path absolue du noeud dans l'arbre
+ */
+ public void selectNode(JAXXContext context, String path) {
+ E node = findNode(context, path);
+ if (log.isDebugEnabled()) {
+ log.debug(path + " :: " + node);
+ }
+ if (node != null) {
+ selectNode(context, node);
+ }
+ }
+
+ /**
+ * Sélection d'un noeud dans l'arbre de navigation.
+ *
+ * @param context le contexte applicatif
+ * @param node le noeud à sélectionner dans l'arbre
+ */
+ public void selectNode(JAXXContext context, E node) {
+
+
+ NavigationModel navigationModel = getSafeModel(context);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ TreePath path = new TreePath(navigationModel.getPathToRoot(node));
+ JTree tree = getTree(context);
+ if (tree == null){
+ // FIXME : Refactor in other helper ?
+ // If its JXTreeTable
+ JXTreeTable treeTable = getSafeTreeTable(context);
+ treeTable.getTreeSelectionModel().setSelectionPath(path);
+ treeTable.scrollPathToVisible(path);
+ return;
+ }
+ tree.setSelectionPath(path);
+ tree.scrollPathToVisible(path);
+ }
+
+ /**
+ * Sélection du parent du noeud selectionne dans l'arbre de navigation.
+ *
+ * @param context le contexte applicatif
+ */
+ public void gotoParentNode(JAXXContext context) {
+
+ E node = getSelectedNode(context);
+
+ if (node == null) {
+ // pas de noeud selectionne
+ throw new NullPointerException("no selected node in context");
+ }
+ node = (E)node.getParent();
+
+ selectNode(context, node);
+ }
+
+ /**
+ * Obtain the first ancestor with the matching internalClass
+ *
+ * @param current the node to test
+ * @param beanClass the type of the internal class to seek of
+ * @return the first ancestor node with the matching class or
+ * {@code null} if not found
+ */
+ public E getParentNode(E current,
+ Class<?> beanClass) {
+ if (current == null) {
+ // ancestor not found
+ return null;
+ }
+ if (beanClass.isAssignableFrom(current.getInternalClass())) {
+ // matching node
+ return current;
+ }
+ // try in the parent of node
+ return getParentNode((E)current.getParent(), beanClass);
+ }
+
+ /**
+ * Sélection d'un fils du noeud selectionne dans l'arbre de navigation.
+ *
+ * @param context le contexte applicatif
+ * @param childIndex index du fils a selectionner
+ */
+ public void gotoChildNode(JAXXContext context, int childIndex) {
+
+ E node = getSelectedNode(context);
+
+ if (node == null) {
+ // pas de noeud selectionne
+ throw new NullPointerException("no selected node in context");
+ }
+ node = (E)node.getChildAt(childIndex);
+
+ selectNode(context, node);
+ }
+
+ /**
+ * Demande une opération de repaint sur un noeud de l'arbre de navigation.
+ *
+ * <b>Note:</b> La descendance du noeud n'est pas repainte.
+ *
+ * @param context le contexte applicatif
+ * @param node le noeud à repaindre
+ */
+ public void repaintNode(JAXXContext context, E node) {
+ repaintNode(context, node, false);
+ }
+
+ /**
+ * Demande une opération de repaint sur un noeud de l'arbre de navigation.
+ *
+ * <b>Note:</b> La descendance du noeud est repainte si le paramètre
+ * <code>deep</code> est à <code>true</code>.
+ *
+ * @param context le contexte applicatif
+ * @param node le noeud à repaindre
+ * @param deep un flag pour activer la repainte de la descendance du noeud
+ */
+ public void repaintNode(JAXXContext context, E node,
+ boolean deep) {
+ NavigationModel navigationModel = getSafeModel(context);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ navigationModel.nodeChanged(node);
+ if (deep) {
+ // repaint childs nodes
+ //todo we should only repaint necessary nodes ?
+ Enumeration<?> e = node.children();
+ while (e.hasMoreElements()) {
+ E child = (E) e.nextElement();
+ repaintNode(context, child, true);
+ }
+ }
+ }
+
+ /**
+ * @deprecated please use {@link #getSafeModel(JAXXContext)}, will be
+ * remove soon
+ * @param context where to find
+ * @return the tree model
+ * @throws NullPointerException if model is null
+ */
+ @Deprecated
+ public NavigationTreeModel getSafeTreeModel(JAXXContext context)
+ throws NullPointerException {
+ NavigationModel model = getSafeModel(context);
+ if (model instanceof NavigationTreeModel){
+ return (NavigationTreeModel) model;
+ }
+ return null;
+ }
+
+ public NavigationModel getSafeModel(JAXXContext context)
+ throws NullPointerException {
+ NavigationModel model = getModel(context);
+ if (model == null) {
+ throw new NullPointerException("could not find tree model " +
+ "with key " + getModelContextEntry() + " in context " +
+ context);
+ }
+ return model;
+ }
+
+ public JTree getSafeTree(JAXXContext context) throws NullPointerException {
+ JTree tree = getTree(context);
+ if (tree == null) {
+ throw new NullPointerException("could not find tree with key " +
+ getTreeContextEntry() + " in context " + context);
+ }
+ return tree;
+ }
+
+ public JXTreeTable getSafeTreeTable(JAXXContext context)
+ throws NullPointerException {
+ JXTreeTable treeTable = getTreeTable(context);
+ if (treeTable == null) {
+ throw new NullPointerException("could not find tree with key " +
+ getTreeTableContextEntry() + " in context " + context);
+ }
+ return treeTable;
+ }
+}
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/GenericNavigationTreeModel.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -0,0 +1,251 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeNode;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Model of the tree used for a navigation tree.
+ * <p/>
+ * Il est composé de {@link NavigationTreeNode}
+ *
+ * @author letellier
+ * @since 2.0.1
+ */
+public class GenericNavigationTreeModel<E extends NavigationTreeNode> extends DefaultTreeModel implements NavigationModel<E>{
+
+ static private final long serialVersionUID = 1L;
+ /**
+ * Logger
+ */
+ static private final Log log = LogFactory.getLog(NavigationTreeModel.class);
+ /**
+ * The path separator used to build the {@link NavigationTreeNode#fullPath}.
+ *
+ * @see NavigationTreeNode#getNodePath()
+ * @see NavigationTreeNode#getFullPath()
+ */
+ protected final String pathSeparator;
+ /**
+ * Context to retrieve beans
+ */
+ private JAXXContext context;
+
+ public GenericNavigationTreeModel(String pathSeparator, JAXXContext context) {
+ super(null);
+ this.pathSeparator = pathSeparator;
+ this.context = context;
+ }
+
+ /**
+ * @see NavigationModel#getRoot()
+ */
+ @Override
+ public E getRoot() {
+ return (E) super.getRoot();
+ }
+
+ @Override
+ public void setRoot(E root) {
+ super.setRoot(root);
+ }
+
+ /**
+ * @see NavigationModel#findNode(String)
+ */
+ @Override
+ public E findNode(String path) {
+ return findNode(getRoot(), path, (Pattern) null);
+ }
+
+ /**
+ * @see NavigationModel#findNode(String, String)
+ */
+ @Override
+ public E findNode(String path, String regex) {
+ return findNode(getRoot(), path, regex);
+ }
+
+ /**
+ * @see NavigationModel#findNode(String, Pattern)
+ */
+ @Override
+ public E findNode(String path, Pattern regex) {
+ return findNode(getRoot(), path, regex);
+ }
+
+ /**
+ * @see NavigationModel#findNode(NavigationTreeNode, String)
+ */
+ @Override
+ public E findNode(E root, String path) {
+ return findNode(root, path, (Pattern) null);
+ }
+
+ /**
+ * @see NavigationModel#findNode(NavigationTreeNode, String, String)
+ */
+ @Override
+ public E findNode(E root,
+ String path,
+ String regex) {
+ return findNode(root, path,
+ regex == null ? null : Pattern.compile(regex));
+ }
+
+ /**
+ * @see NavigationModel#findNode(NavigationTreeNode, String, Pattern)
+ */
+ @Override
+ public E findNode(E root,
+ String path,
+ Pattern regex) {
+ if (regex != null) {
+ Matcher matcher = regex.matcher(path);
+ if (!matcher.matches() || matcher.groupCount() < 1) {
+ log.warn("no matching regex " + regex + " to " + path);
+ return null;
+ }
+ path = matcher.group(1);
+ if (log.isDebugEnabled()) {
+ log.debug("matching regex " + regex + " : " + path);
+ }
+ }
+ StringTokenizer stk = new StringTokenizer(path, pathSeparator);
+ E result = root;
+ // pas the first token (matches the root node)
+ if (root.isRoot() && stk.hasMoreTokens()) {
+ String rootPath = stk.nextToken();
+ if (!rootPath.equals(root.getNodePath())) {
+ return null;
+ }
+ }
+ while (stk.hasMoreTokens()) {
+ result = (E)result.getChild(stk.nextToken());
+ }
+ return result;
+ }
+
+ /**
+ * @see NavigationModel#getContext()
+ */
+ @Override
+ public JAXXContext getContext() {
+ return context;
+ }
+
+ /**
+ * @see NavigationModel#getBean(String)
+ */
+ @Override
+ public Object getBean(String navigationPath) {
+ Object result;
+ E node = findNode(navigationPath, (Pattern) null);
+ result = getBean(node);
+ return result;
+ }
+
+ /**
+ * @see NavigationModel#getBean(NavigationTreeNode)
+ */
+ @Override
+ public Object getBean(E node) {
+ if (node == null) {
+ return null;
+ //fixme should throw a NPE exception
+ //throw new NullPointerException("node can not be null");
+ }
+ return node.getBean(getContext());
+ }
+
+ /**
+ * @see NavigationModel#nodeChanged(TreeNode)
+ */
+ @Override
+ public void nodeChanged(TreeNode node) {
+ nodeChanged(node, false);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ }
+
+ /**
+ * @see NavigationModel#nodeStructureChanged(TreeNode)
+ */
+ @Override
+ public void nodeStructureChanged(TreeNode node) {
+ E n = (E) node;
+ //TC-20091004 never launch a deep reload
+ reload(n, true);
+ super.nodeStructureChanged(node);
+ if (log.isDebugEnabled()) {
+ log.debug(node);
+ }
+ }
+
+ /**
+ * @see NavigationModel#nodeChanged(TreeNode, boolean)
+ */
+ @Override
+ public void nodeChanged(TreeNode node, boolean deep) {
+
+ E n = (E) node;
+ //TC-20091004 never launch a deep clean, since we do a deep nodeChanged.
+ reload(n, deep);
+ super.nodeChanged(node);
+ }
+
+ protected void reload(E node) {
+ reload(node, false);
+ }
+
+ protected void reload(E node, boolean deep) {
+ if (node == null) {
+ return;
+ }
+ node.reload(getContext());
+
+ if (deep) {
+ Enumeration<?> childs = node.children();
+ while (childs.hasMoreElements()) {
+ E o = (E) childs.nextElement();
+ reload(o, true);
+ }
+ }
+ }
+
+ /**
+ * @see NavigationModel#getPathSeparator()
+ */
+ @Override
+ public String getPathSeparator() {
+ return pathSeparator;
+ }
+}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-24 16:59:37 UTC (rev 1806)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModel.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -22,6 +22,7 @@
import jaxx.runtime.JAXXContext;
+import javax.swing.tree.MutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;
import java.util.regex.Pattern;
@@ -34,12 +35,16 @@
* @author sletellier
* @since 2.0.0
*/
-public interface NavigationModel extends TreeModel {
+public interface NavigationModel<E extends NavigationTreeNode> extends TreeModel {
- Object getRoot();
+ E getRoot();
+ void setRoot(E root);
+
TreeNode[] getPathToRoot(TreeNode aNode);
+ public void removeNodeFromParent(MutableTreeNode node);
+
/**
* Search from the root node a node named by his fully path (concatenation
* of nodes {@link NavigationTreeNode#path} valued separated by dot.
@@ -52,7 +57,7 @@
* @return the node matching the fully context from the root node,
* or <code>null</code> if not find.
*/
- NavigationTreeNode findNode(String path);
+ E findNode(String path);
/**
* Apply first the regex pattern to obtain the searched node fi the given
@@ -72,7 +77,7 @@
* @return the node matching the fully context from the root node, or
* <code>null</code> if not found.
*/
- NavigationTreeNode findNode(String path, String regex);
+ E findNode(String path, String regex);
/**
* Apply first the regex pattern to obtain the searched node.
@@ -90,7 +95,7 @@
* @return the node matching the fully context from the root node, or
* <code>null</code> if not found.
*/
- NavigationTreeNode findNode(String path, Pattern regex);
+ E findNode(String path, Pattern regex);
/**
* Search from a given root node a node named by his fully path
@@ -102,7 +107,7 @@
* @return the node matching the fully context from the given root node, or
* <code>null</code> if not found.
*/
- NavigationTreeNode findNode(NavigationTreeNode root, String path);
+ E findNode(E root, String path);
/**
* Apply first the regex pattern to obtain the searched node.
@@ -117,7 +122,7 @@
* @return the node matching the fully context from the given root node,
* or <code>null</code> if not found.
*/
- NavigationTreeNode findNode(NavigationTreeNode root, String path,
+ E findNode(E root, String path,
String regex);
/**
@@ -133,7 +138,7 @@
* @return the node matching the fully context from the given root node,
* or <code>null</code> if not found.
*/
- NavigationTreeNode findNode(NavigationTreeNode root, String path,
+ E findNode(E root, String path,
Pattern regex);
JAXXContext getContext();
@@ -153,7 +158,7 @@
* @param node the current node
* @return the value associated in context with the given node.
*/
- Object getBean(NavigationTreeNode node);
+ Object getBean(E node);
void nodeChanged(TreeNode node);
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-24 16:59:37 UTC (rev 1806)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -32,14 +32,14 @@
* @author sletellier
* @since 2.0.0
*/
-public interface NavigationModelBuilder {
+public interface NavigationModelBuilder <E extends NavigationTreeNode> {
NavigationModel getModel();
- NavigationTreeNode buildEmptyRoot(JAXXContextEntryDef<?> entryDef,
+ E buildEmptyRoot(JAXXContextEntryDef<?> entryDef,
String contextName);
- NavigationTreeNode build(NavigationTreeNode parentNode,
+ E build(E parentNode,
String libelle,
JAXXContextEntryDef<?> entryDef,
String entryPath,
@@ -47,21 +47,21 @@
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass);
- NavigationTreeNode build(NavigationTreeNode parentNode,
+ E build(E parentNode,
String libelle,
JAXXContextEntryDef<?> entryDef,
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass);
- NavigationTreeNode build(NavigationTreeNode parentNode,
+ E build(E parentNode,
String libelle,
String entryPath,
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass);
- NavigationTreeNode build(NavigationTreeNode parentNode,
+ E build(E parentNode,
Decorator<?> decorator,
JAXXContextEntryDef<?> entryDef,
String entryPath,
@@ -69,32 +69,32 @@
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass);
- NavigationTreeNode build(NavigationTreeNode parentNode,
+ E build(E parentNode,
Decorator<?> decorator,
JAXXContextEntryDef<?> entryDef,
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass);
- NavigationTreeNode build(NavigationTreeNode parentNode,
+ E build(E parentNode,
Decorator<?> decorator,
String entryPath,
String contextName,
Class<? extends JAXXObject> uiClass,
Class<? extends JAXXAction> actionClass);
- NavigationTreeNode removeChildNode(NavigationTreeNode node);
+ E removeChildNode(E node);
- void addI18nNodeRenderer(NavigationTreeNode node,
+ void addI18nNodeRenderer(E node,
String libelle);
- void addDecoratorNodeRenderer(NavigationTreeNode node,
+ void addDecoratorNodeRenderer(E node,
Decorator<?> decorator);
void addNodeJaxxClasses(
- NavigationTreeNode node,
+ E node,
Class<? extends JAXXObject> uIClass,
Class<? extends JAXXAction> uIHandlerClass);
- void printModel(NavigationTreeNode node);
+ void printModel(E node);
}
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationSortedTreeAdapter.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationSortedTreeAdapter.java 2010-03-24 16:59:37 UTC (rev 1806)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationSortedTreeAdapter.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -1,260 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.decorator.Decorator;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.swing.event.TreeModelEvent;
-import javax.swing.event.TreeModelListener;
-import java.util.*;
-
-/**
- * Adapter to sort NavigationModel
- * FIXME : Dont work with TreeTable
- *
- * @author sletellier
- * @since 2.0.1
- */
-public class NavigationSortedTreeAdapter implements TreeModelListener {
-
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(NavigationSortedTreeAdapter.class);
-
- protected NavigationModel model;
- protected List<Comparator> comparators;
- protected boolean ignoreCase = false;
-
- /**
- * Used to sort NavigationTreeModel by decorator
- *
- * @param model of navigation tree
- */
- public NavigationSortedTreeAdapter(NavigationModel model){
- this.model = model;
- model.addTreeModelListener(this);
- }
-
- /**
- * Used to sort NavigationTreeModel by decorator
- *
- * @param model of navigation tree
- * @param ignoreCase tio ignore renderer case renderer
- */
- public NavigationSortedTreeAdapter(NavigationModel model, boolean ignoreCase){
- this.ignoreCase = ignoreCase;
- this.model = model;
- model.addTreeModelListener(this);
- }
-
- /**
- * Used to sort NavigationTreeModel by comparator
- *
- * @param model of navigation tree
- * @param comparator used to sort tree
- */
- public NavigationSortedTreeAdapter(NavigationModel model, Comparator comparator){
- this.model = model;
- comparators = new ArrayList<Comparator>();
- comparators.add(comparator);
- model.addTreeModelListener(this);
- }
-
- /**
- * Used to sort NavigationTreeModel by comparators
- *
- * @param model of navigation tree
- * @param comparators used to sort tree
- */
- public NavigationSortedTreeAdapter(NavigationModel model, List<Comparator> comparators){
- this.model = model;
- this.comparators = comparators;
- model.addTreeModelListener(this);
- }
-
- /**
- * Used to sort NavigationTreeModel by comparators
- *
- * @param model of navigation tree
- * @param comparators used to sort tree
- */
- public NavigationSortedTreeAdapter(NavigationModel model, Comparator ... comparators){
- this.model = model;
- this.comparators = Arrays.asList(comparators);
- model.addTreeModelListener(this);
- }
-
- // TODO : find how optimize this (structure not change every times)
- @Override
- public void treeNodesChanged(TreeModelEvent e) {
- sort(getCurrentNode(e), true);
- }
-
- @Override
- public void treeNodesInserted(TreeModelEvent e) {
- sort(getCurrentNode(e), true);
- }
-
- @Override
- public void treeNodesRemoved(TreeModelEvent e) {
- }
-
- @Override
- public void treeStructureChanged(TreeModelEvent e) {
- sort(getCurrentNode(e), true);
- }
-
- protected NavigationTreeNode getCurrentNode(TreeModelEvent e){
- return (NavigationTreeNode) e.getTreePath().getLastPathComponent();
- }
-
- // Sort
- protected void sort() {
- NavigationTreeNode rootNode = (NavigationTreeNode) model.getRoot();
- if (rootNode != null && log.isDebugEnabled()){
- log.debug("Sort from root node : " + rootNode.getBean());
- }
- sort(rootNode, true);
- }
- protected void sort(NavigationTreeNode parent, boolean structureChanged) {
-
- if (parent == null){
- return;
- }
-
- List<NavigationTreeNode> children = Collections.list(parent.children());
-
- if (comparators == null || comparators.isEmpty()){
- Collections.sort(children, rendererDecorator);
- } else {
- children = sortWithComparators(children);
- }
-
- if (children == null || children.isEmpty()){
- return;
- }
-
- Iterator<NavigationTreeNode> childrenIterator = children.iterator();
- if (childrenIterator != null){
-
- model.removeTreeModelListener(this);
-
- parent.removeAllChildren();
- while (childrenIterator.hasNext()) {
- NavigationTreeNode childNode = childrenIterator.next();
- if (log.isDebugEnabled()){
- log.debug("Adding child " + childNode.getBean() + " to parent " + parent.getBean());
- }
- parent.add(childNode);
- }
-
- if (structureChanged){
- model.nodeStructureChanged(parent);
- } else {
- model.nodeChanged(parent, true);
- }
- model.addTreeModelListener(this);
- }
- }
-
- protected List<NavigationTreeNode> sortWithComparators(List<NavigationTreeNode> children) {
- for (Comparator<?> comparator : comparators){
- List<NavigationTreeNode> result = sortWithComparator(children, comparator);
- if (result != null){
- return result;
- }
- }
- return null;
- }
-
- protected <T> List<NavigationTreeNode> sortWithComparator(List<NavigationTreeNode> children,
- Comparator<T> comparator) {
- Map<T, NavigationTreeNode> toSort = new HashMap<T, NavigationTreeNode>();
-
- List<T> beans = new ArrayList<T>();
-
- // Extract beans
- for (NavigationTreeNode child : children){
- Object o = child.getBean();
- if (o != null){
- try{
- T casted = (T) o;
- beans.add(casted);
- toSort.put(casted, child);
- } catch (ClassCastException eee){
- return null;
- }
- }
- }
-
- if (beans.isEmpty()){
- return null;
- }
-
- // Sort beans
- if (log.isDebugEnabled()){
- log.debug("Sorting : " +
- beans.get(0).getClass().getName() +
- " With comparator : " + comparator.getClass().getName());
- }
-
- try{
- Collections.sort(beans, comparator);
- } catch (Exception eee){
- if (log.isWarnEnabled()){
- log.warn("Cant appply comparator : " + comparator.getClass().getName()
- + " with entity of type : "
- + (beans.isEmpty() ? " vide " : beans.get(0).getClass().getName()));
- }
- return null;
- }
-
- // Retrieve sorted nodes
- children.clear();
- int cnt = 0;
- for (T bean : beans){
- if (log.isDebugEnabled()){
- log.debug("Retrieve sorted bean : " + ++cnt + " - " + bean);
- }
- children.add(toSort.get(bean));
- }
- return children;
- }
-
- final Comparator rendererDecorator = new Comparator() {
- @Override
- public int compare(Object o1, Object o2) {
- try {
- String label1 = ((NavigationTreeNode)o1).getRenderer().toString();
- String label2 = ((NavigationTreeNode)o2).getRenderer().toString();
- if (ignoreCase){
- return label1.compareToIgnoreCase(label2);
- }
- return label1.compareTo(label2);
- } catch (Exception eee) {
- return 0;
- }
- }
- };
-}
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-24 16:59:37 UTC (rev 1806)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -64,7 +64,7 @@
* @author chemit
* @since 1.7.2
*/
-public class NavigationTreeContextHelper {
+public class NavigationTreeContextHelper <E extends NavigationTreeNode> {
/**
* Logger
@@ -74,7 +74,7 @@
protected final String prefix;
protected JAXXContextEntryDef<List<String>> selectedPathsContextEntry;
protected JAXXContextEntryDef<List<Object>> selectedBeansContextEntry;
- protected JAXXContextEntryDef<List<NavigationTreeNode>> selectedNodesContextEntry;
+ protected JAXXContextEntryDef<List<E>> selectedNodesContextEntry;
protected JAXXContextEntryDef<NavigationModel> modelContextEntry;
protected JAXXContextEntryDef<NavigationTreeHandler> handlerContextEntry;
protected JAXXContextEntryDef<JTree> treeContextEntry;
@@ -140,12 +140,12 @@
return getSelectedPathContextEntry().getContextValue(context);
}
- public NavigationTreeNode getSelectedNode(JAXXContext context) {
- NavigationTreeNode result = getSelectedValue(getSelectedNodeContextEntry(),context);
+ public E getSelectedNode(JAXXContext context) {
+ E result = getSelectedValue(getSelectedNodeContextEntry(),context);
return result;
}
- public List<NavigationTreeNode> getSelectedNodes(JAXXContext context) {
+ public List<E> getSelectedNodes(JAXXContext context) {
return getSelectedNodeContextEntry().getContextValue(context);
}
@@ -194,11 +194,11 @@
setSelectedValues(getSelectedPathContextEntry(), context, paths);
}
- public void setSelectedNode(JAXXContext context, NavigationTreeNode node) {
+ public void setSelectedNode(JAXXContext context, E node) {
setSelectedValue(getSelectedNodeContextEntry(), context, node);
}
- public void setSelectedNodes(JAXXContext context, List<NavigationTreeNode> nodes) {
+ public void setSelectedNodes(JAXXContext context, List<E> nodes) {
setSelectedValues(getSelectedNodeContextEntry(), context, nodes);
}
@@ -223,7 +223,7 @@
return selectedBeansContextEntry;
}
- protected JAXXContextEntryDef<List<NavigationTreeNode>> getSelectedNodeContextEntry() {
+ protected JAXXContextEntryDef<List<E>> getSelectedNodeContextEntry() {
return selectedNodesContextEntry;
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-24 16:59:37 UTC (rev 1806)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeHelper.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -40,269 +40,9 @@
* @since 1.7.2
* @see NavigationTreeModel
*/
-public abstract class NavigationTreeHelper extends NavigationTreeContextHelper {
-
- /**
- * Logger
- */
- static private final Log log =
- LogFactory.getLog(NavigationTreeHelper.class);
-
- /**
- * Create the model.
- *
- * @param context the context to associate with fresh model
- * @return the new model build with data from the given context
- */
- public abstract NavigationModel createTreeModel(JAXXContext context);
-
- /**
- * Create the tree handler.
- *
- * @param context the context to associate with fresh handler
- * @return the new handler
- */
- public abstract NavigationTreeHandler createTreeHandler(JAXXObject context);
-
- public NavigationTreeHelper(String contextPrefix) {
+public abstract class NavigationTreeHelper extends GenericNavigationHelper<NavigationTreeNode> {
+
+ protected NavigationTreeHelper(String contextPrefix) {
super(contextPrefix);
}
-
- public Object getContextValue(JAXXContext context, String path)
- throws InvocationTargetException, NoSuchMethodException,
- IllegalAccessException {
- NavigationModel treeModel = getSafeModel(context);
- return treeModel.getBean(path);
- }
-
- public NavigationTreeNode findNode(JAXXContext context, String path) {
- NavigationModel treeModel = getSafeModel(context);
- return treeModel.findNode(path);
- }
-
- public NavigationTreeNode findNode(JAXXContext context, String path,
- String regex) {
- NavigationModel treeModel = getSafeModel(context);
- return treeModel.findNode(path, regex);
- }
-
- public NavigationTreeNode findNode(JAXXContext context, String path,
- Pattern regex) {
-
- NavigationModel treeModel = getSafeModel(context);
- return treeModel.findNode(path, regex);
- }
-
- public NavigationTreeNode findNode(JAXXContext context, String path,
- String regex, String suffix) {
-
- NavigationModel treeModel = getSafeModel(context);
-
- NavigationTreeNode navigationTreeNode = treeModel.findNode(path, regex);
- if (navigationTreeNode != null && suffix != null) {
- navigationTreeNode = treeModel.findNode(navigationTreeNode, suffix);
- }
- return navigationTreeNode;
- }
-
- public NavigationTreeNode findNode(JAXXContext context, String path,
- Pattern regex, String suffix) {
-
- NavigationModel treeModel = getSafeModel(context);
-
- NavigationTreeNode navigationTreeNode = treeModel.findNode(path, regex);
- if (navigationTreeNode != null && suffix != null) {
- navigationTreeNode = treeModel.findNode(navigationTreeNode, suffix);
- }
- return navigationTreeNode;
- }
-
- /**
- * Sélection d'un noeud dans l'arbre de navigation à partir de son path.
- *
- * @param context le contexte applicatif
- * @param path le path absolue du noeud dans l'arbre
- */
- public void selectNode(JAXXContext context, String path) {
- NavigationTreeNode node = findNode(context, path);
- if (log.isDebugEnabled()) {
- log.debug(path + " :: " + node);
- }
- if (node != null) {
- selectNode(context, node);
- }
- }
-
- /**
- * Sélection d'un noeud dans l'arbre de navigation.
- *
- * @param context le contexte applicatif
- * @param node le noeud à sélectionner dans l'arbre
- */
- public void selectNode(JAXXContext context, NavigationTreeNode node) {
-
-
- NavigationModel navigationModel = getSafeModel(context);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- TreePath path = new TreePath(navigationModel.getPathToRoot(node));
- JTree tree = getTree(context);
- if (tree == null){
- // FIXME : Refactor in other helper ?
- // If its JXTreeTable
- JXTreeTable treeTable = getSafeTreeTable(context);
- treeTable.getTreeSelectionModel().setSelectionPath(path);
- treeTable.scrollPathToVisible(path);
- return;
- }
- tree.setSelectionPath(path);
- tree.scrollPathToVisible(path);
- }
-
- /**
- * Sélection du parent du noeud selectionne dans l'arbre de navigation.
- *
- * @param context le contexte applicatif
- */
- public void gotoParentNode(JAXXContext context) {
-
- NavigationTreeNode node = getSelectedNode(context);
-
- if (node == null) {
- // pas de noeud selectionne
- throw new NullPointerException("no selected node in context");
- }
- node = node.getParent();
-
- selectNode(context, node);
- }
-
- /**
- * Obtain the first ancestor with the matching internalClass
- *
- * @param current the node to test
- * @param beanClass the type of the internal class to seek of
- * @return the first ancestor node with the matching class or
- * {@code null} if not found
- */
- public NavigationTreeNode getParentNode(NavigationTreeNode current,
- Class<?> beanClass) {
- if (current == null) {
- // ancestor not found
- return null;
- }
- if (beanClass.isAssignableFrom(current.getInternalClass())) {
- // matching node
- return current;
- }
- // try in the parent of node
- return getParentNode(current.getParent(), beanClass);
- }
-
- /**
- * Sélection d'un fils du noeud selectionne dans l'arbre de navigation.
- *
- * @param context le contexte applicatif
- * @param childIndex index du fils a selectionner
- */
- public void gotoChildNode(JAXXContext context, int childIndex) {
-
- NavigationTreeNode node = getSelectedNode(context);
-
- if (node == null) {
- // pas de noeud selectionne
- throw new NullPointerException("no selected node in context");
- }
- node = node.getChildAt(childIndex);
-
- selectNode(context, node);
- }
-
- /**
- * Demande une opération de repaint sur un noeud de l'arbre de navigation.
- *
- * <b>Note:</b> La descendance du noeud n'est pas repainte.
- *
- * @param context le contexte applicatif
- * @param node le noeud à repaindre
- */
- public void repaintNode(JAXXContext context, NavigationTreeNode node) {
- repaintNode(context, node, false);
- }
-
- /**
- * Demande une opération de repaint sur un noeud de l'arbre de navigation.
- *
- * <b>Note:</b> La descendance du noeud est repainte si le paramètre
- * <code>deep</code> est à <code>true</code>.
- *
- * @param context le contexte applicatif
- * @param node le noeud à repaindre
- * @param deep un flag pour activer la repainte de la descendance du noeud
- */
- public void repaintNode(JAXXContext context, NavigationTreeNode node,
- boolean deep) {
- NavigationModel navigationModel = getSafeModel(context);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- navigationModel.nodeChanged(node);
- if (deep) {
- // repaint childs nodes
- //todo we should only repaint necessary nodes ?
- Enumeration<?> e = node.children();
- while (e.hasMoreElements()) {
- NavigationTreeNode child = (NavigationTreeNode) e.nextElement();
- repaintNode(context, child, true);
- }
- }
- }
-
- /**
- * @deprecated please use {@link #getSafeModel(JAXXContext)}, will be
- * remove soon
- * @param context where to find
- * @return the tree model
- * @throws NullPointerException if model is null
- */
- @Deprecated
- public NavigationTreeModel getSafeTreeModel(JAXXContext context)
- throws NullPointerException {
- NavigationModel model = getSafeModel(context);
- if (model instanceof NavigationTreeModel){
- return (NavigationTreeModel) model;
- }
- return null;
- }
-
- public NavigationModel getSafeModel(JAXXContext context)
- throws NullPointerException {
- NavigationModel model = getModel(context);
- if (model == null) {
- throw new NullPointerException("could not find tree model " +
- "with key " + getModelContextEntry() + " in context " +
- context);
- }
- return model;
- }
-
- public JTree getSafeTree(JAXXContext context) throws NullPointerException {
- JTree tree = getTree(context);
- if (tree == null) {
- throw new NullPointerException("could not find tree with key " +
- getTreeContextEntry() + " in context " + context);
- }
- return tree;
- }
-
- public JXTreeTable getSafeTreeTable(JAXXContext context)
- throws NullPointerException {
- JXTreeTable treeTable = getTreeTable(context);
- if (treeTable == null) {
- throw new NullPointerException("could not find tree with key " +
- getTreeTableContextEntry() + " in context " + context);
- }
- return treeTable;
- }
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java 2010-03-24 16:59:37 UTC (rev 1806)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModel.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -21,16 +21,7 @@
package jaxx.runtime.swing.navigation;
import jaxx.runtime.JAXXContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import javax.swing.tree.DefaultTreeModel;
-import javax.swing.tree.TreeNode;
-import java.util.Enumeration;
-import java.util.StringTokenizer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
/**
* Model of the tree used for a navigation tree.
* <p/>
@@ -39,209 +30,9 @@
* @author chemit
* @since 1.7.2
*/
-public class NavigationTreeModel extends DefaultTreeModel implements
- NavigationModel{
+public class NavigationTreeModel extends GenericNavigationTreeModel<NavigationTreeNode> {
- static private final long serialVersionUID = 1L;
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(NavigationTreeModel.class);
- /**
- * The path separator used to build the {@link NavigationTreeNode#fullPath}.
- *
- * @see NavigationTreeNode#getNodePath()
- * @see NavigationTreeNode#getFullPath()
- */
- protected final String pathSeparator;
- /**
- * Context to retrieve beans
- */
- private JAXXContext context;
-
public NavigationTreeModel(String pathSeparator, JAXXContext context) {
- super(null);
- this.pathSeparator = pathSeparator;
- this.context = context;
+ super(pathSeparator, context);
}
-
- /**
- * @see NavigationModel#getRoot()
- */
- @Override
- public NavigationTreeNode getRoot() {
- return (NavigationTreeNode) super.getRoot();
- }
-
- /**
- * @see NavigationModel#findNode(String)
- */
- @Override
- public NavigationTreeNode findNode(String path) {
- return findNode(getRoot(), path, (Pattern) null);
- }
-
- /**
- * @see NavigationModel#findNode(String, String)
- */
- @Override
- public NavigationTreeNode findNode(String path, String regex) {
- return findNode(getRoot(), path, regex);
- }
-
- /**
- * @see NavigationModel#findNode(String, Pattern)
- */
- @Override
- public NavigationTreeNode findNode(String path, Pattern regex) {
- return findNode(getRoot(), path, regex);
- }
-
- /**
- * @see NavigationModel#findNode(NavigationTreeNode, String)
- */
- @Override
- public NavigationTreeNode findNode(NavigationTreeNode root, String path) {
- return findNode(root, path, (Pattern) null);
- }
-
- /**
- * @see NavigationModel#findNode(NavigationTreeNode, String, String)
- */
- @Override
- public NavigationTreeNode findNode(NavigationTreeNode root,
- String path,
- String regex) {
- return findNode(root, path,
- regex == null ? null : Pattern.compile(regex));
- }
-
- /**
- * @see NavigationModel#findNode(NavigationTreeNode, String, Pattern)
- */
- @Override
- public NavigationTreeNode findNode(NavigationTreeNode root,
- String path,
- Pattern regex) {
- if (regex != null) {
- Matcher matcher = regex.matcher(path);
- if (!matcher.matches() || matcher.groupCount() < 1) {
- log.warn("no matching regex " + regex + " to " + path);
- return null;
- }
- path = matcher.group(1);
- if (log.isDebugEnabled()) {
- log.debug("matching regex " + regex + " : " + path);
- }
- }
- StringTokenizer stk = new StringTokenizer(path, pathSeparator);
- NavigationTreeNode result = root;
- // pas the first token (matches the root node)
- if (root.isRoot() && stk.hasMoreTokens()) {
- String rootPath = stk.nextToken();
- if (!rootPath.equals(root.getNodePath())) {
- return null;
- }
- }
- while (stk.hasMoreTokens()) {
- result = result.getChild(stk.nextToken());
- }
- return result;
- }
-
- /**
- * @see NavigationModel#getContext()
- */
- @Override
- public JAXXContext getContext() {
- return context;
- }
-
- /**
- * @see NavigationModel#getBean(String)
- */
- @Override
- public Object getBean(String navigationPath) {
- Object result;
- NavigationTreeNode node = findNode(navigationPath, (Pattern) null);
- result = getBean(node);
- return result;
- }
-
- /**
- * @see NavigationModel#getBean(NavigationTreeNode)
- */
- @Override
- public Object getBean(NavigationTreeNode node) {
- if (node == null) {
- return null;
- //fixme should throw a NPE exception
- //throw new NullPointerException("node can not be null");
- }
- return node.getBean(getContext());
- }
-
- /**
- * @see NavigationModel#nodeChanged(TreeNode)
- */
- @Override
- public void nodeChanged(TreeNode node) {
- nodeChanged(node, false);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- }
-
- /**
- * @see NavigationModel#nodeStructureChanged(TreeNode)
- */
- @Override
- public void nodeStructureChanged(TreeNode node) {
- NavigationTreeNode n = (NavigationTreeNode) node;
- //TC-20091004 never launch a deep reload
- reload(n, true);
- super.nodeStructureChanged(node);
- if (log.isDebugEnabled()) {
- log.debug(node);
- }
- }
-
- /**
- * @see NavigationModel#nodeChanged(TreeNode, boolean)
- */
- @Override
- public void nodeChanged(TreeNode node, boolean deep) {
-
- NavigationTreeNode n = (NavigationTreeNode) node;
- //TC-20091004 never launch a deep clean, since we do a deep nodeChanged.
- reload(n, deep);
- super.nodeChanged(node);
- }
-
- protected void reload(NavigationTreeNode node) {
- reload(node, false);
- }
-
- protected void reload(NavigationTreeNode node, boolean deep) {
- if (node == null) {
- return;
- }
- node.reload(getContext());
-
- if (deep) {
- Enumeration<?> childs = node.children();
- while (childs.hasMoreElements()) {
- NavigationTreeNode o = (NavigationTreeNode) childs.nextElement();
- reload(o, true);
- }
- }
- }
-
- /**
- * @see NavigationModel#getPathSeparator()
- */
- @Override
- public String getPathSeparator() {
- return pathSeparator;
- }
}
Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java 2010-03-24 16:59:37 UTC (rev 1806)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -37,229 +37,34 @@
* @author chemit
* @since 17.2
*/
-public class NavigationTreeModelBuilder implements NavigationModelBuilder{
+public class NavigationTreeModelBuilder extends AbstractNavigationModelBuilder<NavigationTreeNode>{
/**
* Logger
*/
static private final Log log = LogFactory.getLog(NavigationTreeModelBuilder.class);
- /**
- * The model dealed by the builder.
- *
- * <b>Note:</b> It is a good idea to keep only one instance of the model.
- * If reset is required, should empty the model but not reinstanciate it.
- */
- protected NavigationTreeModel model;
- /**
- * default ui class to use if node does not define an ui class
- */
- protected Class<? extends JAXXObject> defaultUIClass;
- /**
- * [optional] default action class
- */
- protected Class<? extends JAXXAction> defaultUIHandlerClass;
public NavigationTreeModelBuilder(String pathSeparator, JAXXContext context, Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass) {
this(defaultUIClass, defaultUIHandlerClass, new NavigationTreeModel(pathSeparator, context));
}
public NavigationTreeModelBuilder(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, NavigationTreeModel model) {
- this.defaultUIClass = defaultUIClass;
- this.defaultUIHandlerClass = defaultUIHandlerClass;
- this.model = model;
+ super(defaultUIClass, defaultUIHandlerClass, model);
}
- public NavigationTreeModel getModel() {
- return model;
+ @Override
+ public NavigationTreeNode createNavigationTreeNode(String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
+ return new NavigationTreeNode(pathSeparator, contextName, jaxxContextEntryDef, jaxxContextEntryPath);
}
- public NavigationTreeNode buildEmptyRoot(JAXXContextEntryDef<?> entryDef, String contextName) {
- NavigationTreeNode node = new NavigationTreeNode(model.pathSeparator, contextName, entryDef, null);
- addI18nNodeRenderer(node, "");
- return addChildNode(null, node);
+ // TODO : to remove
+ /**
+ * @deprecated please use NavigationModel for return type
+ * @return the tree model
+ */
+ @Override
+ @Deprecated
+ public NavigationTreeModel getModel() {
+ return (NavigationTreeModel)super.getModel();
}
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, String libelle,
- JAXXContextEntryDef<?> entryDef,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeNode node = new NavigationTreeNode(model.pathSeparator, contextName, entryDef, entryPath);
- addI18nNodeRenderer(node, libelle);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, String libelle,
- JAXXContextEntryDef<?> entryDef,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeNode node = new NavigationTreeNode(model.pathSeparator, contextName, entryDef);
- // TODO : Must be : NavigationTreeNode node = new NavigationTreeNode(model.pathSeparator, contextName, null, entryDef); ???
- addI18nNodeRenderer(node, libelle);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, String libelle,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeNode node = new NavigationTreeNode(model.pathSeparator, contextName, entryPath);
- addI18nNodeRenderer(node, libelle);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, Decorator<?> decorator,
- JAXXContextEntryDef<?> entryDef,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeNode node = new NavigationTreeNode(model.pathSeparator, contextName, entryDef, entryPath);
- addDecoratorNodeRenderer(node, decorator);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, Decorator<?> decorator,
- JAXXContextEntryDef<?> entryDef,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeNode node = new NavigationTreeNode(model.pathSeparator, contextName, entryDef);
- addDecoratorNodeRenderer(node, decorator);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, Decorator<?> decorator,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeNode node = new NavigationTreeNode(model.pathSeparator, contextName, null, entryPath);
- addDecoratorNodeRenderer(node, decorator);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- protected NavigationTreeNode addChildNode(NavigationTreeNode parentNode, NavigationTreeNode node) {
-
- if (node.getUIClass() == null) {
- // no ui is associated with this node, use the default one
- node.setUIClass(defaultUIClass);
- }
-
- if (node.getUIHandlerClass() == null) {
- // no ui handler associated with this node, use the default one
- node.setUIHandlerClass(defaultUIHandlerClass);
- }
- if (parentNode == null) {
- model.setRoot(node);
- } else {
- parentNode.add(node);
- }
- model.nodeStructureChanged(parentNode);
- return node;
- }
-
- public NavigationTreeNode removeChildNode(NavigationTreeNode node) {
- NavigationTreeNode parentNode = node.getParent();
- model.removeNodeFromParent(node);
- return parentNode;
- }
-
- public void addI18nNodeRenderer(NavigationTreeNode node, String libelle) {
- node.setRenderer(new NavigationTreeNodeRendererI18nImpl(libelle));
- }
-
- public void addDecoratorNodeRenderer(NavigationTreeNode node, Decorator<?> decorator) {
- node.setRenderer(new NavigationTreeNodeRendererDecoratorImpl(decorator));
- }
-
- public void addNodeJaxxClasses(
- NavigationTreeNode node,
- Class<? extends JAXXObject> uIClass,
- Class<? extends JAXXAction> uIHandlerClass) {
- node.setUIClass(uIClass);
- node.setUIHandlerClass(uIHandlerClass);
- }
-
- public void printModel(NavigationTreeNode node) {
- if (node == null) {
- return;
- }
- log.info("node " + node.getFullPath() + ", jxpath: " + node.getJaxxContextEntryPath() + ", entryContextDef: " + node.getJaxxContextEntryDef());
- if (log.isDebugEnabled()) {
- log.debug("node userObject" + node.getUserObject());
- log.debug("value from node " + node.getBean(getModel().getContext()));
- log.debug("value from model " + getModel().getBean(node));
- }
- Enumeration<?> children = node.children();
- while (children.hasMoreElements()) {
- printModel((NavigationTreeNode) children.nextElement());
- }
- }
-
- public static abstract class ChildBuilder<O> {
-
- protected NavigationTreeModelBuilder builder;
-
- protected ChildBuilder(NavigationTreeModelBuilder builder) {
- this.builder = builder;
- }
-
- protected abstract void init(Class<? extends O> klass);
-
- protected abstract Decorator<? extends O> getDecorator(O child);
-
- protected abstract String getJXPath(O child);
-
- protected abstract String getNavigationPath(O child);
-
- public void build(NavigationTreeNode parent, boolean cacheValues, Class<? extends O> klass, java.util.Collection<? extends O> beans, Class<? extends JAXXObject> ui, Class<? extends JAXXAction> actionClass) {
-
- if (beans == null || beans.isEmpty()) {
- // no bean to treate
- return;
- }
-
- init(klass);
-
- NavigationTreeNode node;
-
- for (O o : beans) {
- node = builder.build(parent, getDecorator(o), getJXPath(o), getNavigationPath(o), ui, actionClass);
- if (cacheValues) {
- // cache the bean value to improve performance
- node.setBean(o);
- }
- }
- }
-
- public void build(NavigationTreeNode parent, boolean cacheValues, Class<? extends O> klass, O[] beans, Class<? extends JAXXObject> ui, Class<? extends JAXXAction> actionClass) {
-
- if (beans == null || beans.length == 0) {
- // no bean to treate
- return;
- }
-
- init(klass);
-
- NavigationTreeNode node;
-
- for (O o : beans) {
- node = builder.build(parent, getDecorator(o), getJXPath(o), getNavigationPath(o), ui, actionClass);
- if (cacheValues) {
- // cache the bean value to improve performance
- node.setBean(o);
- }
- }
- }
- }
}
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-24 16:59:37 UTC (rev 1806)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModel.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -46,7 +46,7 @@
* @author sletellier
* @since 2.0.0
*/
-public class NavigationTreeTableModel extends DefaultTreeTableModel implements NavigationModel {
+public class NavigationTreeTableModel extends DefaultTreeTableModel implements NavigationModel<NavigationTreeTableNode> {
static private final long serialVersionUID = 1L;
@@ -80,10 +80,12 @@
/**
* @see NavigationModel#getRoot()
*/
+ @Override
public NavigationTreeTableNode getRoot() {
return (NavigationTreeTableNode) super.root;
}
+ @Override
public TreeNode[] getPathToRoot(TreeNode aNode) {
if (aNode == null){
return null;
@@ -92,6 +94,7 @@
}
+ @Override
public void setRoot(NavigationTreeTableNode root) {
this.root = root;
getModelSupport().fireNewRoot();
@@ -102,7 +105,8 @@
* nodesWereRemoved to create the appropriate event. This is the preferred
* way to remove a node as it handles the event creation for you.
*/
- public void removeNodeFromParent(NavigationTreeNode node) {
+ @Override
+ public void removeNodeFromParent(MutableTreeNode node) {
NavigationTreeTableNode parent = (NavigationTreeTableNode)node.getParent();
if (parent == null) {
@@ -119,42 +123,48 @@
/**
* @see NavigationModel#findNode(String)
*/
- public NavigationTreeNode findNode(String path) {
+ @Override
+ public NavigationTreeTableNode findNode(String path) {
return findNode(getRoot(), path, (Pattern) null);
}
/**
* @see NavigationModel#findNode(String, String)
*/
- public NavigationTreeNode findNode(String path, String regex) {
+ @Override
+ public NavigationTreeTableNode findNode(String path, String regex) {
return findNode(getRoot(), path, regex);
}
/**
* @see NavigationModel#findNode(String, Pattern)
*/
- public NavigationTreeNode findNode(String path, Pattern regex) {
+ @Override
+ public NavigationTreeTableNode findNode(String path, Pattern regex) {
return findNode(getRoot(), path, regex);
}
/**
* @see NavigationModel#findNode(NavigationTreeNode, String)
*/
- public NavigationTreeNode findNode(NavigationTreeNode root, String path) {
+ @Override
+ public NavigationTreeTableNode findNode(NavigationTreeTableNode root, String path) {
return findNode(root, path, (Pattern) null);
}
/**
* @see NavigationModel#findNode(NavigationTreeNode, String, String)
*/
- public NavigationTreeNode findNode(NavigationTreeNode root, String path, String regex) {
+ @Override
+ public NavigationTreeTableNode findNode(NavigationTreeTableNode root, String path, String regex) {
return findNode(root, path, regex == null ? null : Pattern.compile(regex));
}
/**
* @see NavigationModel#findNode(NavigationTreeNode, String, Pattern)
*/
- public NavigationTreeNode findNode(NavigationTreeNode root, String path, Pattern regex) {
+ @Override
+ public NavigationTreeTableNode findNode(NavigationTreeTableNode root, String path, Pattern regex) {
if (regex != null) {
Matcher matcher = regex.matcher(path);
if (!matcher.matches() || matcher.groupCount() < 1) {
@@ -167,7 +177,7 @@
}
}
StringTokenizer stk = new StringTokenizer(path, pathSeparator);
- NavigationTreeNode result = root;
+ NavigationTreeTableNode result = root;
// pas the first token (matches the root node)
if (root.isRoot() && stk.hasMoreTokens()) {
String rootPath = stk.nextToken();
@@ -191,9 +201,10 @@
/**
* @see NavigationModel#getBean(String)
*/
+ @Override
public Object getBean(String navigationPath) {
Object result;
- NavigationTreeNode node = findNode(navigationPath, (Pattern) null);
+ NavigationTreeTableNode node = findNode(navigationPath, (Pattern) null);
result = getBean(node);
return result;
}
@@ -201,7 +212,8 @@
/**
* @see NavigationModel#getBean(NavigationTreeNode)
*/
- public Object getBean(NavigationTreeNode node) {
+ @Override
+ public Object getBean(NavigationTreeTableNode node) {
if (node == null) {
return null;
//fixme should throw a NPE exception
Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java 2010-03-24 16:59:37 UTC (rev 1806)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeTableModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -1,264 +0,0 @@
-/*
- * *##%
- * JAXX Runtime
- * Copyright (C) 2008 - 2009 CodeLutin
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
- * License along with this program. If not, see
- * <http://www.gnu.org/licenses/lgpl-3.0.html>.
- * ##%*
- */
-package jaxx.runtime.swing.navigation;
-
-import jaxx.runtime.JAXXAction;
-import jaxx.runtime.JAXXContext;
-import jaxx.runtime.JAXXObject;
-import jaxx.runtime.context.JAXXContextEntryDef;
-import jaxx.runtime.decorator.Decorator;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.Enumeration;
-
-/**
- * This object is design to build a {@link NavigationTreeTableModel}.
- *
- * @see NavigationModelBuilder
- *
- * @author sletellier
- * @since 2.0.0
- */
-public abstract class NavigationTreeTableModelBuilder implements NavigationModelBuilder{
-
- /**
- * Logger
- */
- static private final Log log = LogFactory.getLog(NavigationTreeModelBuilder.class);
- /**
- * The model dealed by the builder.
- *
- * <b>Note:</b> It is a good idea to keep only one instance of the model.
- * If reset is required, should empty the model but not reinstanciate it.
- */
- protected NavigationTreeTableModel model;
- /**
- * default ui class to use if node does not define an ui class
- */
- protected Class<? extends JAXXObject> defaultUIClass;
- /**
- * [optional] default action class
- */
- protected Class<? extends JAXXAction> defaultUIHandlerClass;
-
- public NavigationTreeTableModelBuilder(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, NavigationTreeTableModel model) {
- this.defaultUIClass = defaultUIClass;
- this.defaultUIHandlerClass = defaultUIHandlerClass;
- this.model = model;
- }
-
- public NavigationTreeTableModel getModel() {
- return model;
- }
-
- public NavigationTreeNode buildEmptyRoot(JAXXContextEntryDef<?> entryDef, String contextName) {
- NavigationTreeTableNode node = createNavigationTreeTableNode(model.pathSeparator, contextName, entryDef, null);
- addI18nNodeRenderer(node, "");
- return addChildNode(null, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, String libelle,
- JAXXContextEntryDef<?> entryDef,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeTableNode node = createNavigationTreeTableNode(model.pathSeparator, contextName, entryDef, entryPath);
- addI18nNodeRenderer(node, libelle);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, String libelle,
- JAXXContextEntryDef<?> entryDef,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeTableNode node = createNavigationTreeTableNode(model.pathSeparator, contextName, entryDef, null);
- addI18nNodeRenderer(node, libelle);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, String libelle,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeTableNode node = createNavigationTreeTableNode(model.pathSeparator, contextName, null, entryPath);
- addI18nNodeRenderer(node, libelle);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, Decorator<?> decorator,
- JAXXContextEntryDef<?> entryDef,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeTableNode node = createNavigationTreeTableNode(model.pathSeparator, contextName, entryDef, entryPath);
- addDecoratorNodeRenderer(node, decorator);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, Decorator<?> decorator,
- JAXXContextEntryDef<?> entryDef,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeTableNode node = createNavigationTreeTableNode(model.pathSeparator, contextName, entryDef, null);
- addDecoratorNodeRenderer(node, decorator);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- public NavigationTreeNode build(NavigationTreeNode parentNode, Decorator<?> decorator,
- String entryPath,
- String contextName,
- Class<? extends JAXXObject> uiClass,
- Class<? extends JAXXAction> actionClass) {
- NavigationTreeTableNode node = createNavigationTreeTableNode(model.pathSeparator, contextName, null, entryPath);
- addDecoratorNodeRenderer(node, decorator);
- addNodeJaxxClasses(node, uiClass, actionClass);
- return addChildNode(parentNode, node);
- }
-
- protected NavigationTreeNode addChildNode(NavigationTreeNode parentNode, NavigationTreeTableNode node) {
-
- if (node.getUIClass() == null) {
- // no ui is associated with this node, use the default one
- node.setUIClass(defaultUIClass);
- }
-
- if (node.getUIHandlerClass() == null) {
- // no ui handler associated with this node, use the default one
- node.setUIHandlerClass(defaultUIHandlerClass);
- }
- if (parentNode == null) {
- model.setRoot(node);
- } else {
- parentNode.add(node);
- }
- model.nodeStructureChanged(node);
- return node;
- }
-
- public NavigationTreeNode removeChildNode(NavigationTreeNode node) {
- NavigationTreeNode parentNode = node.getParent();
- model.removeNodeFromParent(node);
- return parentNode;
- }
-
- public void addI18nNodeRenderer(NavigationTreeNode node, String libelle) {
- node.setRenderer(new NavigationTreeNodeRendererI18nImpl(libelle));
- }
-
- public void addDecoratorNodeRenderer(NavigationTreeNode node, Decorator<?> decorator) {
- node.setRenderer(new NavigationTreeNodeRendererDecoratorImpl(decorator));
- }
-
- public void addNodeJaxxClasses(
- NavigationTreeNode node,
- Class<? extends JAXXObject> uIClass,
- Class<? extends JAXXAction> uIHandlerClass) {
- node.setUIClass(uIClass);
- node.setUIHandlerClass(uIHandlerClass);
- }
-
- public void printModel(NavigationTreeNode node) {
- if (node == null) {
- return;
- }
- log.info("node " + node.getFullPath() + ", jxpath: " + node.getJaxxContextEntryPath() + ", entryContextDef: " + node.getJaxxContextEntryDef());
- if (log.isDebugEnabled()) {
- log.debug("node userObject" + node.getUserObject());
- log.debug("value from node " + node.getBean(getModel().getContext()));
- log.debug("value from model " + getModel().getBean(node));
- }
- Enumeration<?> children = node.children();
- while (children.hasMoreElements()) {
- printModel((NavigationTreeNode) children.nextElement());
- }
- }
-
- // To create your own instance of NavigationTreeTableNode
- public abstract NavigationTreeTableNode createNavigationTreeTableNode(String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath);
-
- public static abstract class ChildBuilder<O> {
-
- protected NavigationTreeModelBuilder builder;
-
- protected ChildBuilder(NavigationTreeModelBuilder builder) {
- this.builder = builder;
- }
-
- protected abstract void init(Class<? extends O> klass);
-
- protected abstract Decorator<? extends O> getDecorator(O child);
-
- protected abstract String getJXPath(O child);
-
- protected abstract String getNavigationPath(O child);
-
- public void build(NavigationTreeNode parent, boolean cacheValues, Class<? extends O> klass, java.util.Collection<? extends O> beans, Class<? extends JAXXObject> ui, Class<? extends JAXXAction> actionClass) {
-
- if (beans == null || beans.isEmpty()) {
- // no bean to treate
- return;
- }
-
- init(klass);
-
- NavigationTreeNode node;
-
- for (O o : beans) {
- node = builder.build(parent, getDecorator(o), getJXPath(o), getNavigationPath(o), ui, actionClass);
- if (cacheValues) {
- // cache the bean value to improve performance
- node.setBean(o);
- }
- }
- }
-
- public void build(NavigationTreeNode parent, boolean cacheValues, Class<? extends O> klass, O[] beans, Class<? extends JAXXObject> ui, Class<? extends JAXXAction> actionClass) {
-
- if (beans == null || beans.length == 0) {
- // no bean to treate
- return;
- }
-
- init(klass);
-
- NavigationTreeNode node;
-
- for (O o : beans) {
- node = builder.build(parent, getDecorator(o), getJXPath(o), getNavigationPath(o), ui, actionClass);
- if (cacheValues) {
- // cache the bean value to improve performance
- node.setBean(o);
- }
- }
- }
- }
-}
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeModelBuilder.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -0,0 +1,52 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXAction;
+import jaxx.runtime.JAXXObject;
+import jaxx.runtime.context.JAXXContextEntryDef;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This object is design to build a {@link NavigationTreeModel} with sorted nodes {@link SortedNavigationTreeNode} .
+ *
+ * @see NavigationModelBuilder
+ *
+ * @author sletellier
+ * @since 2.0.1
+ */
+public class SortedNavigationTreeModelBuilder extends AbstractNavigationModelBuilder<SortedNavigationTreeNode> {
+
+ /**
+ * Logger
+ */
+ static private final Log log = LogFactory.getLog(SortedNavigationTreeModelBuilder.class);
+
+ public SortedNavigationTreeModelBuilder(Class<? extends JAXXObject> defaultUIClass, Class<? extends JAXXAction> defaultUIHandlerClass, NavigationModel<SortedNavigationTreeNode> navigationModel) {
+ super(defaultUIClass, defaultUIHandlerClass, navigationModel);
+ }
+
+ @Override
+ public SortedNavigationTreeNode createNavigationTreeNode(String pathSeparator, String contextName, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
+ return new SortedNavigationTreeNode(pathSeparator, contextName, jaxxContextEntryDef, jaxxContextEntryPath);
+ }
+}
Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java
===================================================================
--- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java (rev 0)
+++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/SortedNavigationTreeNode.java 2010-03-25 13:20:44 UTC (rev 1807)
@@ -0,0 +1,129 @@
+/*
+ * *##%
+ * JAXX Runtime
+ * Copyright (C) 2008 - 2009 CodeLutin
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * ##%*
+ */
+package jaxx.runtime.swing.navigation;
+
+import jaxx.runtime.JAXXContext;
+import jaxx.runtime.context.JAXXContextEntryDef;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.swing.tree.MutableTreeNode;
+import java.util.*;
+
+/**
+ * Sprted node
+ *
+ * @see NavigationTreeNode
+ *
+ * @author sletellier
+ * @since 2.0.1
+ */
+public class SortedNavigationTreeNode extends NavigationTreeNode {
+
+ /**
+ * Logger
+ */
+ static private final Log log = LogFactory.getLog(SortedNavigationTreeNode.class);
+
+ @Override
+ public SortedNavigationTreeNode getChildAt(int index) {
+ return (SortedNavigationTreeNode) super.getChildAt(index);
+ }
+
+ @Override
+ public SortedNavigationTreeNode getParent() {
+ return (SortedNavigationTreeNode) super.getParent();
+ }
+
+ @Override
+ public void add(MutableTreeNode newChild) {
+
+ List<SortedNavigationTreeNode> children = Collections.list(children());
+
+ if (children.isEmpty()){
+ insert(newChild, 0);
+ return;
+ }
+
+ SortedNavigationTreeNode newNode = (SortedNavigationTreeNode) newChild;
+
+ children.add(newNode);
+
+ Collections.sort(children, rendererDecorator);
+ int index = children.indexOf(newChild);
+
+ log.info("Insert node : " + newNode.getRenderer().toString() + " in " + index + " of parent " + this.getRenderer().toString());
+
+ insert(newChild, index);
+ }
+
+
+ public SortedNavigationTreeNode(String pathSeparator, String navigationPath, Object jaxxContextEntryDef) {
+ super(pathSeparator, navigationPath, jaxxContextEntryDef);
+// sort();
+ }
+
+ public SortedNavigationTreeNode(String pathSeparator, String navigationPath, JAXXContextEntryDef<?> jaxxContextEntryDef, String jaxxContextEntryPath) {
+ super(pathSeparator, navigationPath, jaxxContextEntryDef, jaxxContextEntryPath);
+// sort();
+ }
+
+// public void sort() {
+// List<SortedNavigationTreeNode> children = Collections.list(children());
+//
+// if (children.isEmpty() || children.size() == 1){
+// return;
+// }
+//
+// Collections.sort(children, rendererDecorator);
+//
+// if (children == null){
+// return;
+// }
+//
+// Iterator<SortedNavigationTreeNode> childrenIterator = children.iterator();
+// if (childrenIterator != null){
+// removeAllChildren();
+//
+// if (log.isDebugEnabled()){
+// log.debug("Adding " + children.size() + " children to parent " + getBean());
+// }
+// while (childrenIterator.hasNext()) {
+// SortedNavigationTreeNode childNode = childrenIterator.next();
+// childNode.sort();
+// add(childNode);
+// }
+// }
+// }
+
+ final Comparator rendererDecorator = new Comparator() {
+ @Override
+ public int compare(Object o1, Object o2) {
+ try {
+ String label1 = ((NavigationTreeNode)o1).getRenderer().toString();
+ String label2 = ((NavigationTreeNode)o2).getRenderer().toString();
+ return label1.compareToIgnoreCase(label2);
+ } catch (Exception eee) {
+ return 0;
+ }
+ }
+ };
+}
1
0