Re: Change style of TreeNode

2008-08-27 Thread Kai Schubert-Altmann
Thanks a lot, Edvin.

I will try your answers to 2. and 3..

But I think, that overwriting the populateTreeItem method wouldn't help,
because i want to modify nodes of an existing tree, for example mark them
red if I click on them.

Any suggestions?

2008/8/26 Edvin Syse <[EMAIL PROTECTED]>

> Kai Schubert-Altmann skrev:
>
>> Hi everybody,
>>
>> I have some question regarding my existing wicket tree:
>>
>> 1. How can I change the style or css class of one or more TreeNodes?
>>
>
> If you override the populateTreeItem() method, you can add an
> AbstractBehaviour to the item and override the onComponentTag method. From
> there you can do tag.put("class", "yourValue").
>
>  2. How can I specify custom icons for some nodes?
>>
>
> Override the getNodeIcon() method of the tree.
>
>  3. How can i change the name, that will be shown in the tree, without
>> changing the name of the userObject?
>>
>
> I guess the simple solution would be to provide a toString() method on
> your userObject that returns the desired value :)
>
> Alternatively you could override the renderNode method of the Tree, which
> by default does:
>
>protected String renderNode(TreeNode node)
>{
>return node.toString();
>}
>
>
> Just get your userObject from the node and return the string you want from
> there :)
>
> -- Edvin
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


Change style of TreeNode

2008-08-26 Thread Kai Schubert-Altmann
Hi everybody,

I have some question regarding my existing wicket tree:

1. How can I change the style or css class of one or more TreeNodes?
2. How can I specify custom icons for some nodes?
3. How can i change the name, that will be shown in the tree, without
changing the name of the userObject?

Has somebody any ideas?

Kai


Re: How to add nodes to a tree using Ajax

2008-07-04 Thread Kai Schubert-Altmann
Hello,

2. Thanks, but your file contains only an empty class.

3. If the tree has ever 2000 nodes, it lasts maybe a little bit to long to
get all data at once from the database.

Kai

2008/7/4 geke <[EMAIL PROTECTED]>:

>
> Hello,
>
> to your point 2.
> You have to build a subclass from LinkTree.
> A example is in the attachement.
> http://www.nabble.com/file/p18273760/MyTree.java MyTree.java
>
> To point 3.
>
> Why you only want to load only the root and reload the next level?
> In my solution all Node are updated via updateTree().
>
> GeKe
>
>
> Kai Schubert-Altmann wrote:
> >
> > HI everybody
> >
> > I solved the first problem by my own by adding the following method to
> the
> > tree:
> >
> >   public DefaultMutableTreeNode getSelectedNode() {
> > Object selected = null;
> > try {
> >   selected =
> this.getTreeState().getSelectedNodes().iterator().next();
> > } catch (NoSuchElementException nseEx) { }
> > return (selected instanceof DefaultMutableTreeNode)?
> > (DefaultMutableTreeNode)selected : null;
> >   }
> >
> > That worked for me without problems. Or is there an easier way?
> >
> > Kai
> >
> > 2008/7/3 Kai Schubert-Altmann <[EMAIL PROTECTED]>:
> >
> >> Hi,
> >>
> >> thanks to both of you! Matejs code worked very fine, so i didn't tried
> >> gekes version.
> >>
> >> But now i have the next three problems/questions:
> >>
> >> 1. If i want to add a new node to the selected node, then i have to get
> >> the
> >> selected node first. How can i do that?
> >>
> >> 2. Can i change the shown icons to custom ones?
> >>
> >> 3. Is it possible to load the root element only and reload the next
> >> level,
> >> when you click the plus-image?
> >>
> >> Kai
> >>
> >> 2008/6/27 geke <[EMAIL PROTECTED]>:
> >>
> >>
> >>> try this code:
> >>>
> >>> fileTree = new LinkTree();
> >>>
> >>> TreeNode existingTreeNode = ...;
> >>>
> >>> DefaultMutableTreeNode newTreeNode = new
> DefaultMutableTreeNode(object);
> >>> DefaultTreeModel model = (DefaultTreeModel)fileTree.getModelObject();
> >>> model.insertNodeInto(newTreeNode, treeNode, 0);
> >>> fileTree.updateTree(target);
> >>>
> >>>
> >>>
> >>>
> >>> Kai Schubert-Altmann wrote:
> >>> >
> >>> > Hi,
> >>> >
> >>> > how can I add nodes to a wicket tree using a AjaxLink?
> >>> >
> >>> > I tried to add a node to the SimpleTree of this example:
> >>> > http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
> >>> >
> >>> > with this code:
> >>> >
> >>> > add(new AjaxLink("addNode")
> >>> > {
> >>> > public void onClick(AjaxRequestTarget target)
> >>> > {
> >>> >   List list = new ArrayList();
> >>> >   list.add("new node");
> >>> >   BaseTreePage.this.add(rootNode,list);
> >>> >   getTree().updateTree(target);
> >>> > }
> >>> > });
> >>> >
> >>> > But the tree will not update itself.
> >>> >
> >>> > Thanks in advance,
> >>> > Kai
> >>> >
> >>> >
> >>>
> >>> --
> >>> View this message in context:
> >>>
> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18150967.html
> >>> Sent from the Wicket - User mailing list archive at Nabble.com.
> >>>
> >>>
> >>> -
> >>> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>> For additional commands, e-mail: [EMAIL PROTECTED]
> >>>
> >>>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18273760.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


Re: How to add nodes to a tree using Ajax

2008-07-03 Thread Kai Schubert-Altmann
HI everybody

I solved the first problem by my own by adding the following method to the
tree:

  public DefaultMutableTreeNode getSelectedNode() {
Object selected = null;
try {
  selected = this.getTreeState().getSelectedNodes().iterator().next();
} catch (NoSuchElementException nseEx) { }
return (selected instanceof DefaultMutableTreeNode)?
(DefaultMutableTreeNode)selected : null;
  }

That worked for me without problems. Or is there an easier way?

Kai

2008/7/3 Kai Schubert-Altmann <[EMAIL PROTECTED]>:

> Hi,
>
> thanks to both of you! Matejs code worked very fine, so i didn't tried
> gekes version.
>
> But now i have the next three problems/questions:
>
> 1. If i want to add a new node to the selected node, then i have to get the
> selected node first. How can i do that?
>
> 2. Can i change the shown icons to custom ones?
>
> 3. Is it possible to load the root element only and reload the next level,
> when you click the plus-image?
>
> Kai
>
> 2008/6/27 geke <[EMAIL PROTECTED]>:
>
>
>> try this code:
>>
>> fileTree = new LinkTree();
>>
>> TreeNode existingTreeNode = ...;
>>
>> DefaultMutableTreeNode newTreeNode = new DefaultMutableTreeNode(object);
>> DefaultTreeModel model = (DefaultTreeModel)fileTree.getModelObject();
>> model.insertNodeInto(newTreeNode, treeNode, 0);
>> fileTree.updateTree(target);
>>
>>
>>
>>
>> Kai Schubert-Altmann wrote:
>> >
>> > Hi,
>> >
>> > how can I add nodes to a wicket tree using a AjaxLink?
>> >
>> > I tried to add a node to the SimpleTree of this example:
>> > http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
>> >
>> > with this code:
>> >
>> > add(new AjaxLink("addNode")
>> > {
>> > public void onClick(AjaxRequestTarget target)
>> > {
>> >   List list = new ArrayList();
>> >   list.add("new node");
>> >   BaseTreePage.this.add(rootNode,list);
>> >   getTree().updateTree(target);
>> > }
>> > });
>> >
>> > But the tree will not update itself.
>> >
>> > Thanks in advance,
>> > Kai
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18150967.html
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> -
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>


Re: How to add nodes to a tree using Ajax

2008-07-03 Thread Kai Schubert-Altmann
Hi,

thanks to both of you! Matejs code worked very fine, so i didn't tried gekes
version.

But now i have the next three problems/questions:

1. If i want to add a new node to the selected node, then i have to get the
selected node first. How can i do that?

2. Can i change the shown icons to custom ones?

3. Is it possible to load the root element only and reload the next level,
when you click the plus-image?

Kai

2008/6/27 geke <[EMAIL PROTECTED]>:

>
> try this code:
>
> fileTree = new LinkTree();
>
> TreeNode existingTreeNode = ...;
>
> DefaultMutableTreeNode newTreeNode = new DefaultMutableTreeNode(object);
> DefaultTreeModel model = (DefaultTreeModel)fileTree.getModelObject();
> model.insertNodeInto(newTreeNode, treeNode, 0);
> fileTree.updateTree(target);
>
>
>
>
> Kai Schubert-Altmann wrote:
> >
> > Hi,
> >
> > how can I add nodes to a wicket tree using a AjaxLink?
> >
> > I tried to add a node to the SimpleTree of this example:
> > http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1
> >
> > with this code:
> >
> > add(new AjaxLink("addNode")
> > {
> > public void onClick(AjaxRequestTarget target)
> > {
> >   List list = new ArrayList();
> >   list.add("new node");
> >   BaseTreePage.this.add(rootNode,list);
> >   getTree().updateTree(target);
> > }
> > });
> >
> > But the tree will not update itself.
> >
> > Thanks in advance,
> > Kai
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/How-to-add-nodes-to-a-tree-using-Ajax-tp18130191p18150967.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


How to add nodes to a tree using Ajax

2008-06-26 Thread Kai Schubert-Altmann
Hi,

how can I add nodes to a wicket tree using a AjaxLink?

I tried to add a node to the SimpleTree of this example:
http://www.wicket-library.com/wicket-examples/ajax/tree/simple.1

with this code:

add(new AjaxLink("addNode")
{
public void onClick(AjaxRequestTarget target)
{
  List list = new ArrayList();
  list.add("new node");
  BaseTreePage.this.add(rootNode,list);
  getTree().updateTree(target);
}
});

But the tree will not update itself.

Thanks in advance,
Kai


How to insert childs to a tree with Ajax

2008-06-19 Thread Kai Schubert-Altmann
Hi,

I'm using an extendet wicket tree with an own tree model. I want to insert
child into the tree and want to update the tree with Ajax, but nothing
worked for me. I tried invalidateAll() and updateTree(). What can i do to
insert the childs with Ajax?

Kai

/* *
 * code snippet: create and setup tree
  */

TreeModel treeModel = null;
HwSubCategoryEnvironmentTree root = hwSubCategoryEnvironmentTreeSer
vice.loadPathToRoot(this.hwSubCategoryEnvironmentTree).get(0);
if (root != null) {
  NestedSetNodeWrapper node =
hwSubCategoryEnvironmentTreeService.loadSubtree(root);
  treeModel = node.convertToTreeModel();
}
tree = new IconTree("hwSubCategoryEnvironmentTree", treeModel) {

  private static final long serialVersionUID = -4004667936606595008L;

  protected void onNodeLinkClicked(AjaxRequestTarget target, TreeNode
node)
  {
  ...
  }
};

tree.setRootLess(false);
ResourceReference icon = new ResourceReference(IconTree.class,
"square_orange.png");
tree.setFolderClosedResource(icon);
tree.setFolderOpenResource(icon);
tree.setItemResource(new ResourceReference(IconTree.class,
"square_orange.png"));
selectNode(this.hwSubCategoryEnvironmentTree);
tree.setOutputMarkupId(true);
// add tree
add(tree);

/* *
 * code snippet: update tree
  */
AjaxSubmitLink saveButton = new AjaxSubmitLink("saveRootButton"){
...
protected void onSubmit(AjaxRequestTarget target, Form form) {
...

hwSubCategoryEnvironmentTreeService.save(hwSubCategoryEnvironmentTree);
tree.invalidateAll();
target.addComponent(tree);
}
}

/* *
 * IconTree class
  */
package com.nsn.forlabs.front.components;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.NoSuchElementException;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;

import org.apache.wicket.Component;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AbstractBehavior;
import org.apache.wicket.extensions.markup.html.tree.Tree;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.tree.ITreeStateListener;
import org.apache.wicket.model.IModel;
import org.apache.wicket.util.lang.PropertyResolver;

/**
 * Subclass of [EMAIL PROTECTED] wicket.extensions.markup.html.tree.Tree}
 * 
 * to tweak its appearance
 * to allow for easy setting and retrieval of selected nodes
 * to override a TooltipExtractor
 * to provide for event callbacks on changes to the tree
 * 
 * @author Marco Holmer
 */
@SuppressWarnings("deprecation")
public class IconTree extends Tree implements Serializable
{
  private static final long serialVersionUID = 0L;

  /** Reference to the icon of open tree folder */
  private static final ResourceReference FOLDER_OPEN = new
ResourceReference(
  IconTree.class, "res/node-open.gif");

  /** Reference to the icon of closed tree folder */
  private static final ResourceReference FOLDER_CLOSED = new
ResourceReference(
  IconTree.class, "res/node-closed.gif");

  /** Reference to the icon of tree item (not a folder) */
  private static final ResourceReference ITEM = new ResourceReference(
  IconTree.class, "res/item.gif");

  private TreeStateCallback treeStateCallback;

  private static final Comparator NODE_COMPARATOR = new Comparator() {
public int compare(Object o1, Object o2) {
  return (o1.equals(o2))? 0 : 1;
}
  };

  private static final TooltipExtractor TOOLTIP_EXTRACTOR = new
DefaultTooltipExtractor();

  private ResourceReference itemResource = ITEM;
  private ResourceReference folderClosedResource = FOLDER_CLOSED;
  private ResourceReference folderOpenResource = FOLDER_OPEN;
  private boolean showIcons = true;
  private TooltipExtractor tooltipExtractor = TOOLTIP_EXTRACTOR;

  /**
   * Tree constructor.
   * @param id The component id
   */
  public IconTree(String id)
  {
super(id);
init();
  }

  /**
   * Tree constructor.
   * @param id The component id
   * @param model The tree model
   */
  public IconTree(String id, IModel model)
  {
super(id, model);
init();
  }

  /**
   * Tree constructor.
   * @param id The component id
   * @param treeModel The tree model
   */
  public IconTree(String id, TreeModel treeModel)
  {
super(id, treeModel);
init();
  }

  private void init() {
//getTreeState().addTreeStateListener(new
TreeStateListenerToTreeStateEventConverter());
  }


  protected void populateT