Fully expanded tree using tree model

Hi every body,
I have represented into jtree form after reading xml document using the tree model. But I want to displayed
the fully expanded tree at the screen when program run.
Please help me.
Thanks
Edited by: ahmadgee on Jul 11, 2008 3:42 AM

Thanks for your help
For get the the tree in expanded form, I am using the expandAPath funtion by the following way.
public class XMLTreePanel extends JPanel {
       private JTree tree;
       private XMLTreeModel model;
       public XMLTreePanel() {
                setLayout(new BorderLayout());
        model = new XMLTreeModel();
     tree = new JTree();
     tree.setModel(model);
     tree.setShowsRootHandles(true);
     tree.setEditable(false);
     expandAPath(tree);
     JScrollPane pane = new JScrollPane(tree);
     pane.setPreferredSize(new Dimension(300,400));
     add(pane, "Center");
     final JTextField text = new JTextField();
                text.setEditable(false);
     add(text, "South");
     tree.addTreeSelectionListener(new TreeSelectionListener() {
          public void valueChanged(TreeSelectionEvent e) {
          Object lpc = e.getPath().getLastPathComponent();
          if (lpc instanceof XMLTreeNode) {
               text.setText( ((XMLTreeNode)lpc).getText() );
public void expandAPath(JTree tree){               
     for(int i=1; i<tree.getRowCount(); ++i) {
          tree.expandRow(i);            
public void setDocument(Document document) {
     model.setDocument(document);
public Document getDocument() {
     return model.getDocument();
}

Similar Messages

  • ABAP WD: Fully expand a Tree

    Hi all,
    I'm having a very hard time achieving the following:
    I would like to FULLY EXPAND a WD tree in code.
    Allthough it sounds easy i dont get it to work.
    What have i tried allready:
    - the 'Expanded' property of the treenode at designtime.
    - if_wd_context_node->SET_LEAD_SELECTION
    - if_wd_context_element->set_selected
    - fiddled with the 'Initialisation Lead Selection' property
    Any suggetsions?
    Thanks alot!
    Joris Bots

    Roberto,
    Thanks for the quick help.
    I dont have a recursive node, since my tree is allways 2 levels deep, so i have a tree with 1 TreeNodeType and 1 TreeElementType.
    What i dont get to work is to get a reference to the (instantiated) nodes at runtime.
    all i get is a Table with the nodeTYPES (the metadata of the Tree)
    Please have a look at this:
    <u>my tree in RUNTIME looks like this</u>
    Root
       N1
         item1
         item2
         item3
       N2
         item1
         item2
         item3
       N2
         item1
         item2
         item3
    <u>my tree in designtime looks like this</u>
    MY_TREE
       NodeType1
       ElementType1
    what you are saying is that i need to set the EXPANDED property of <b>N1, N2 and N3</b> at runtime instead of setting the property of <b>NodeType1</b> designtime, right?
    I dont know how to get the Ref's to the N1..3 object.
    Hope you can help me,
    Thanks
    Joris Bots

  • Need to expand tree by passing treeId thr URL not by clicking manually.

    Sub: Need to expand tree by passing Id thr URL.
    Hi,
    Here i have Library.java and ajaxTree.jsf files (collected from Jboss richfaces)
    There is having a list of artist .
    If u click on a particular artistname then the respective albums(with their checkboxes) will expand and show like a treenode.
    just look at d url : "http://localhost:8080/richfaces-demo-3.2.1.GA/richfaces/tree.jsf?c=tree&albumIds=1001,1002,1005,1008,1009,1010&client=0"
    I m passing album Ids and clientId in url browser and receiving in d Library.java.
    I need to expand the required client tree to show albums without clicking on artistname rather by passing the clientId from Url.
    I thnk one EventHandling class( PostbackPhaseListener.java ) is responsible for expanding but I m unable to understand.
    How can I do it.
    Plz help asap.
    /###############ajaxTree.jsf##########Start##############/
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:c="http://java.sun.com/jstl/core">
         <p>This tree uses "ajax" switch type, note that for collapse/expand operations it will be Ajax request to the server. You may see short delay in this case.</p>
         <h:form>     
              <rich:tree style="width:300px" value="#{library.data}" var="item" nodeFace="#{item.type}">
                   <rich:treeNode type="artist" >
                        <h:outputText value="#{item.name}" />
                        </rich:treeNode>
                   <rich:treeNode type="album" >
                        <h:selectBooleanCheckbox value="#{item.selected}"/>
                        <h:outputText value="#{item.title}" />
                   </rich:treeNode>
              </rich:tree>
              <h:commandButton value="Update" />
         </h:form>
    </ui:composition>
    /###############ajaxTree.jsf##########End##############/
    /************************Library.java*********Start****************/
    package org.richfaces.demo.tree;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;
    import java.util.StringTokenizer;
    import javax.servlet.http.HttpServletRequest;
    import javax.faces.context.FacesContext;
    import org.richfaces.model.TreeNode;
    public class Library implements TreeNode {
         private static final long serialVersionUID = -3530085227471752526L;
         private Map artists = null;
         private Object state1;
         private Object state2;
         private Map getArtists() {
              if (this.artists==null) {
                   initData();
              return this.artists;
         public void addArtist(Artist artist) {
              addChild(Long.toString(artist.getId()), artist);
         public void addChild(Object identifier, TreeNode child) {
              getArtists().put(identifier, child);
              child.setParent(this);
         public TreeNode getChild(Object id) {
              return (TreeNode) getArtists().get(id);
         public Iterator getChildren() {
              return getArtists().entrySet().iterator();
         public Object getData() {
              return this;
         public TreeNode getParent() {
              return null;
         public boolean isLeaf() {
              return getArtists().isEmpty();
         public void removeChild(Object id) {
              getArtists().remove(id);
         public void setData(Object data) {
         public void setParent(TreeNode parent) {
         public String getType() {
              return "library";
         private long nextId = 0;
         private long getNextId() {
              return nextId++;
         private Map albumCache = new HashMap();
         private Map artistCache = new HashMap();
         private Artist getArtistByName(String name, Library library) {
              Artist artist = (Artist)artistCache.get(name);
              if (artist==null) {
                   artist = new Artist(getNextId());
                   artist.setName(name);
                   artistCache.put(name, artist);
                   library.addArtist(artist);
              return artist;
         private Album getAlbumByTitle(String title, Artist artist) {
              Album album = (Album)albumCache.get(title);
              if (album==null) {
                   album = new Album(getNextId());
                   album.setTitle(title);
                   albumCache.put(title, album);
                   artist.addAlbum(album);
              return album;
         private void initData() {
              artists = new HashMap();
              InputStream is = this.getClass().getClassLoader().getResourceAsStream("org/richfaces/demo/tree/data.txt");
              ByteArrayOutputStream os = new ByteArrayOutputStream();
              byte[] rb = new byte[1024];
              int read;
              HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
         //     System.out.println("request.getParameter(param) "+request.getParameter("param"));
              //System.out.println("request.getParameter(client) "+request.getParameter("client"));
              //System.out.println("request.getParameter() "+request.getParameter("c"));
              try {
                   do {
                        read = is.read(rb);
                        if (read>0) {
                             os.write(rb, 0, read);
                   } while (read>0);
                   String buf = os.toString();
                   StringTokenizer toc1 = new StringTokenizer(buf,"\n");
                        String str1 = request.getParameter("albumIds");
                        int clientId1 =Integer.parseInt( request.getParameter("client"));
                   while (toc1.hasMoreTokens()) {
                        String str = toc1.nextToken();
                        StringTokenizer toc2 = new StringTokenizer(str, "\t");
                        String artistName = toc2.nextToken();
                        String albumTitle = toc2.nextToken();
                        String songTitle = toc2.nextToken();
                        toc2.nextToken();
                        toc2.nextToken();
                        String albumYear = toc2.nextToken();
                        Artist artist = getArtistByName(artistName,this);
                        Album album = getAlbumByTitle(albumTitle, artist);
                        String portfolios[] = new String[100];
                        Integer portfoliosId[] = new Integer[100];
                        int i = 0;
                        StringTokenizer st = new StringTokenizer(str1, ",");
                        while (st.hasMoreTokens()) {
                        portfolios[i] = st.nextToken();
                        if((songTitle.equals(portfolios))&&(!(songTitle == ""))){
                                  //System.out.println("ifff");
                                  album.setSelected(true);
                        i++;
                        album.setYear(new Integer(albumYear));
              } catch (IOException e) {
                   throw new RuntimeException(e);
         public Object getState1() {
              return state1;
         public void setState1(Object state1) {
              this.state1 = state1;
         public Object getState2() {
              return state2;
         public void setState2(Object state2) {
              this.state2 = state2;
         public void walk(TreeNode node, List<TreeNode> appendTo, Class<? extends TreeNode> type) {
              if (type.isInstance(node)){
                   appendTo.add(node);
              Iterator<Map.Entry<Object, TreeNode>> iterator = node.getChildren();
              System.out.println("walk node.getChildren() "+node.getChildren());
              while(iterator.hasNext()) {
                   walk(iterator.next().getValue(), appendTo, type);
         public ArrayList getLibraryAsList(){
              ArrayList appendTo = new ArrayList();
              System.out.println("getLibraryAsList appendTo "+appendTo);
              walk(this, appendTo, Song.class);
              return appendTo;
    /************************Library.java*********End****************/
    /************************PostbackPhaseListener.java*********Start****************/
    package org.richfaces.treemodeladaptor;
    import java.util.Map;
    import javax.faces.context.ExternalContext;
    import javax.faces.context.FacesContext;
    import javax.faces.event.PhaseEvent;
    import javax.faces.event.PhaseId;
    import javax.faces.event.PhaseListener;
    public class PostbackPhaseListener implements PhaseListener {
         public static final String POSTBACK_ATTRIBUTE_NAME = PostbackPhaseListener.class.getName();
         public void afterPhase(PhaseEvent event) {
         public void beforePhase(PhaseEvent event) {
              FacesContext facesContext = event.getFacesContext();
              Map requestMap = facesContext.getExternalContext().getRequestMap();
              requestMap.put(POSTBACK_ATTRIBUTE_NAME, Boolean.TRUE);
         public PhaseId getPhaseId() {
              return PhaseId.APPLY_REQUEST_VALUES;
         public static boolean isPostback() {
              FacesContext facesContext = FacesContext.getCurrentInstance();
              if (facesContext != null) {
                   ExternalContext externalContext = facesContext.getExternalContext();
                   if (externalContext != null) {
                        return Boolean.TRUE.equals(
                                  externalContext.getRequestMap().get(POSTBACK_ATTRIBUTE_NAME));
              return false;
    /************************PostbackPhaseListener.java*********End****************/
    Edited by: rajesh_forum on Sep 17, 2008 6:13 AM
    Edited by: rajesh_forum on Sep 17, 2008 6:18 AM

    Hi
    Can somebody please look into this?
    Thanks
    Raj
    Edited by: RajICWeb on Aug 9, 2009 4:38 AM

  • Expand tree metod: ok in 11.1.1.4, error in 11.1.2

    Hi OTN,
    I have recently migrated my 11.1.1.4 application to 11.1.2.
    The first bug I met is treetable expanding.
    There is a treetable on my JSF page in a region. On panel collection's toolbar there is a toolbarButton for treetable expanding
    <af:commandToolbarButton text="#{templateBundle.EXPAND}"
                                               id="ctb_expand"
                                               actionListener="#{backingBeanScope.TemplateBean1.expandTemplateTree}"
                                               icon="/img/tree.png"
                                               disabled="#{bindings.TemplateView1Iterator.currentRow == null}"/>The following methods are:
        public void expandTemplateTree(ActionEvent actionEvent) {
            System.out.println(">> expandTemplateTree <<");
            try {
            RichTreeTable rt =
                (RichTreeTable)FacesContext.getCurrentInstance().getViewRoot().findComponent("r1:pc_tree:tree1");
                System.out.println(">> rt = "+rt+" <<");
            TemplateUIHelper.expandTree(rt);
            TemplateUIHelper.refreshTemplateTreeTable();
                System.out.println("> END OF expandTemplateTree <");
            } catch (Exception e) {
                System.err.println(">>> expandTemplateTree <<<");
                e.printStackTrace();
            public static void expandTree(RichTreeTable rt) {
            try {
                if (rt != null) {
                    int rowCount = rt.getRowCount();
                    List<Key> rowKey;
                    for (int j = 0; j < rowCount; j++) {
                        oracle.adfinternal.view.faces.model.binding.FacesCtrlHierNodeBinding node =
                            (oracle.adfinternal.view.faces.model.binding.FacesCtrlHierNodeBinding)rt.getRowData(j);
                        rowKey = new ArrayList<Key>();
                        rowKey.add(node.getRowKey());
                        rt.getDisclosedRowKeys().add(rowKey);
                        rt.setRowKey(rowKey);
                        expandTreeTableChildrenNode(rt, node, rowKey);
            } catch (Exception e) {
                System.err.println(">>> expandTree <<<");
                e.printStackTrace();
        private static void expandTreeTableChildrenNode(RichTreeTable rt,
                                                        oracle.adfinternal.view.faces.model.binding.FacesCtrlHierNodeBinding node,
                                                        List<Key> parentRowKey) {
            try {
                System.out.println(">> expandTreeTableChildrenNode <<");
                ArrayList children = node.getChildren();
                List<Key> rowKey;
                if (children != null) {
                    for (int i = 0; i < children.size(); i++) {
                        rowKey = new ArrayList<Key>();
                        rowKey.addAll(parentRowKey);
                        rowKey.add(((oracle.adfinternal.view.faces.model.binding.FacesCtrlHierNodeBinding)children.get(i)).getRowKey());
                        rt.getDisclosedRowKeys().add(rowKey);
                        if (((oracle.adfinternal.view.faces.model.binding.FacesCtrlHierNodeBinding)(children.get(i))).getChildren() ==
                            null)
                            continue;
                        expandTreeTableChildrenNode(rt,
                                                    (oracle.adfinternal.view.faces.model.binding.FacesCtrlHierNodeBinding)(node.getChildren().get(i)),
                                                    rowKey);
            } catch (Exception e) {
                e.printStackTrace();
        }When I click the button in a console window I see that the method is executed to the end without being interrupted by exceptions.
    But the tree is not expanded and I see a messagebox with ADF_FACES-60100 error and HTTP 404 code.
    In console there is a stacktrace:
    expandTemplateTree
    rt = RichTreeTable[org.apache.myfaces.trinidad.component.UIXTree$RowKeyFacesBeanWrapper@1d83b914, id=tree1]
    expandTreeTableChildrenNode
    expandTreeTableChildrenNode
    expandTreeTableChildrenNode
    END OF expandTemplateTree
    <15.07.2011 17:34:56 MSD> <Warning> <oracle.adf.view.rich.component.fragment.UIXRegion> <BEA-000000> <ADF_FACES-10026: During the processing of the region component, either a context change was not found or it did not match the instance set up by the current component. Expected oracle.adf.view.rich.component.fragment.UIXRegion$RegionContextChange but found UIXCollection.CollectionComponentChange[Component class: oracle.adf.view.rich.component.rich.data.RichTreeTable, component ID: tree1].
    <15.07.2011 17:34:56 MSD> <Error> <oracle.adfinternal.view.faces.config.rich.XmlHttpServletResponse> <BEA-000000> <
    javax.servlet.ServletException: ADF_FACES-60101:+Error code+ HTTP: 404."
            at oracle.adfinternal.view.faces.config.rich.XmlHttpServletResponse._logException(XmlHttpServletResponse.java:140)
            at oracle.adfinternal.view.faces.config.rich.XmlHttpServletResponse.sendError(XmlHttpServletResponse.java:106)
            at oracle.adfinternal.view.faces.config.rich.XmlHttpServletResponse.sendError(XmlHttpServletResponse.java:100)
            at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:128)
            at com.sun.faces.application.ViewHandlerResponseWrapper.sendError(ViewHandlerResponseWrapper.java:82)
            at weblogic.servlet.FileServlet.findSource(FileServlet.java:269)
            at weblogic.servlet.FileServlet.doGetHeadPost(FileServlet.java:191)
            at weblogic.servlet.FileServlet.service(FileServlet.java:173)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
            at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
            at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
            at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
            at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:183)
            at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:523)
            at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:253)
            at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546)
            at javax.faces.context.ExternalContextWrapper.dispatch(ExternalContextWrapper.java:93)
            at javax.faces.context.ExternalContextWrapper.dispatch(ExternalContextWrapper.java:93)
            at oracle.adfinternal.view.faces.config.rich.RecordRequestAttributesDuringDispatch.dispatch(RecordRequestAttributesDuringDispatch.java:44)
            at javax.faces.context.ExternalContextWrapper.dispatch(ExternalContextWrapper.java:93)
            at javax.faces.context.ExternalContextWrapper.dispatch(ExternalContextWrapper.java:93)
            at javax.faces.context.ExternalContextWrapper.dispatch(ExternalContextWrapper.java:93)
            at org.apache.myfaces.trinidadinternal.context.FacesContextFactoryImpl$OverrideDispatch.dispatch(FacesContextFactoryImpl.java:167)
            at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:363)
            at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154)
            at org.apache.myfaces.trinidadinternal.application.ViewDeclarationLanguageFactoryImpl$ChangeApplyingVDLWrapper.buildView(ViewDeclarationLanguageFactoryImpl.java:341)
            at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._renderResponse(LifecycleImpl.java:982)
            at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:334)
            at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:232)
            at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
            at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
            at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
            at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
            at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
            at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:173)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
            at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:121)
            at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:468)
            at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
            at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:468)
            at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:293)
            at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:199)
            at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
            at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:111)
            at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:313)
            at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:413)
            at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:94)
            at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:161)
            at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
            at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:136)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
            at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
            at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
            at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
            at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
            at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
            at weblogic.work.ExecuteThread.run(ExecuteThread.java:178){code}
    The method is based upon one of ADF Code Corner articles.
    It is working properly in ADF 11.1.1.4.
    Can't see the error cause. Would like an advice, please.
    Thanks.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    I haven't invented using ADF internals, I was surprised myself. But it worked in 1.4.
    As I said, this method is based on some blog article (thought it was Code Corner, but can't find it right now).
    I'll try Code Corner #78.
    Implemented code corner method.
    The treetable is really initially expanded. But now I can't disclose nodes manually.
    I can undisclose (close) node with no problems but trying to disclose (open) it back manually hungs up the treetable.
    Here is my code (basically the same as on Code Corner):
    <af:treeTable value="#{bindings.ComponentView1.treeModel}" var="node"
                                                  selectionListener="#{backingBeanScope.TemplateBean1.treeMakeCurrent}" // shouldn't cause troubles
                                                  rowSelection="single" id="tree1" partialTriggers=":::pc1:t1"
                                                  columnStretching="column:c7" fetchSize="60" varStatus="vs"
                                                  disclosedRowKeys="#{backingBeanScope.TemplateBean1.newDisclosedTreeTableKeys}">
    public void expandTemplateTreeTable(ActionEvent ae) { // on button
            newDisclosedTreeTableKeys = null;
            getNewDisclosedTreeTableKeys();
            TemplateUIHelper.refreshTemplateTreeTable();
        private RowKeySetImpl newDisclosedTreeTableKeys = null;
        public void setNewDisclosedTreeTableKeys(RowKeySetImpl newDisclosedKeys) {
            this.newDisclosedTreeTableKeys = newDisclosedKeys;
        public RowKeySetImpl getNewDisclosedTreeTableKeys() {
            final int expandTreeToLevelLevel = 10;
            if (newDisclosedTreeTableKeys == null) {
                newDisclosedTreeTableKeys = new RowKeySetImpl();
                FacesContext fctx = FacesContext.getCurrentInstance();
                UIViewRoot root = fctx.getViewRoot();
                //lookup the tree table component by its component ID
                RichTreeTable treeTable = TemplateUIHelper.getTemplateTreeTable();// (RichTreeTable)root.findComponent("tt1");
                //if tree table is found
                if (treeTable != null) {
                    //get the collection model to access the ADF binding layer for
                    //the tree binding used
                    CollectionModel model = (CollectionModel)treeTable.getValue();
                    JUCtrlHierBinding treeBinding =
                        (JUCtrlHierBinding)model.getWrappedData();
                    JUCtrlHierNodeBinding nodeBinding =
                        treeBinding.getRootNodeBinding();         
                    TemplateUIHelper.expandAllNodes(nodeBinding, newDisclosedTreeTableKeys, 0, expandTreeToLevelLevel);
            return newDisclosedTreeTableKeys;
        public static void expandAllNodes(JUCtrlHierNodeBinding nodeBinding,
                                    RowKeySetImpl disclosedKeys,
                                    int currentExpandLevel, int maxExpandLevel) {
            if (currentExpandLevel <= maxExpandLevel) {
                List<JUCtrlHierNodeBinding> childNodes =
                    (List<JUCtrlHierNodeBinding>)nodeBinding.getChildren();
                ArrayList newKeys = new ArrayList();
                if (childNodes != null) {
                    for (JUCtrlHierNodeBinding _node : childNodes) {
                        newKeys.add(_node.getKeyPath());
                        expandAllNodes(_node, disclosedKeys,
                                       currentExpandLevel + 1, maxExpandLevel);
                disclosedKeys.addAll(newKeys);
        }Edited by: ILya Cyclone on Jul 22, 2011 6:26 PM

  • How to hide a tree node from the GUI but still keep it in the tree model?

    Hi, All
    I used a JTree in my project in which I have a DefaultTreeModel to store all the tree structure and a JTree show it on the screen. But for some reason, I want to hide some of the nodes from the user, but I don't want to remove them from the tree model because later on I still need to use them.
    I searched on the web, some people suggested method to hide the root node, but that's not appliable to my project because I want to hide some non-root nodes; Some people also suggested to collapse the parent node when there are child to hide, it is not appliable to me either, because there still some other childnodes (sibling of the node to hide) I want to show.
    How can I hide some of the tree node from the user? Thanks for any information.
    Linda

    Here's an example using a derivation of DefaultTreeModel that shows (or does not show) two types of Sneech (appologies to the good Dr Zeus) by overiding two methods on the model.
    Now, there are many things wrong with this example (using instanceof, for example), but it's pretty tight and shows one way of doing what you want.
    Note: to make it useful, you''d have to change the implementation of setShowStarBelliedSneeches() to do something more sophisticated than simply firing a structure change event on the root node. You'd want to find all the star bellied sneech nodes and call fireTreeNodesRemoved(). That way the tree would stay expanded rather than collapse as it does now.
    import javax.swing.JTree;
    import javax.swing.JScrollPane;
    import javax.swing.JOptionPane;
    import javax.swing.JCheckBox;
    import javax.swing.JPanel;
    import javax.swing.tree.TreePath;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.DefaultMutableTreeNode;
    import java.awt.Dimension;
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Enumeration;
    class FilteredTree
         private class PlainBelliedSneech {
              public String toString() { return "Plain Bellied Sneech"; }
         private class StarBelliedSneech {
              public String toString() { return "Star Bellied Sneech"; }
         private class FilteredTreeModel
              extends DefaultTreeModel
              private boolean mShowStarBelliedSneeches= true;
              private DefaultMutableTreeNode mRoot;
              FilteredTreeModel(DefaultMutableTreeNode root)
                   super(root);
                   mRoot= root;
              public Object getChild(Object parent, int index)
                   DefaultMutableTreeNode node=
                        (DefaultMutableTreeNode) parent;
                   if (mShowStarBelliedSneeches)
                        return node.getChildAt(index);
                   int pos= 0;
                   for (int i= 0, cnt= 0; i< node.getChildCount(); i++) {
                        if (((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject()
                                            instanceof PlainBelliedSneech)
                             if (cnt++ == index) {
                                  pos= i;
                                  break;
                   return node.getChildAt(pos);
              public int getChildCount(Object parent)
                   DefaultMutableTreeNode node=
                        (DefaultMutableTreeNode) parent;
                   if (mShowStarBelliedSneeches)
                        return node.getChildCount();
                   int childCount= 0;
                   Enumeration children= node.children();
                   while (children.hasMoreElements()) {
                        if (((DefaultMutableTreeNode) children.nextElement()).getUserObject()
                                            instanceof PlainBelliedSneech)
                             childCount++;
                   return childCount;
              public boolean getShowStarBelliedSneeches() {
                   return mShowStarBelliedSneeches;
              public void setShowStarBelliedSneeches(boolean showStarBelliedSneeches)
                   if (showStarBelliedSneeches != mShowStarBelliedSneeches) {
                        mShowStarBelliedSneeches= showStarBelliedSneeches;
                        Object[] path= { mRoot };
                        int[] childIndices= new int[root.getChildCount()];
                        Object[] children= new Object[root.getChildCount()];
                        for (int i= 0; i< root.getChildCount(); i++) {
                             childIndices= i;
                             children[i]= root.getChildAt(i);
                        fireTreeStructureChanged(this, path, childIndices, children);
         private FilteredTree()
              final DefaultMutableTreeNode root= new DefaultMutableTreeNode("Root");
              DefaultMutableTreeNode parent;
              DefaultMutableTreeNode child;
              for (int i= 0; i< 2; i++) {
                   parent= new DefaultMutableTreeNode(new PlainBelliedSneech());
                   root.add(parent);
                   for (int j= 0; j< 2; j++) {
                        child= new DefaultMutableTreeNode(new StarBelliedSneech());
                        parent.add(child);
                        for (int k= 0; k< 2; k++)
                             child.add(new DefaultMutableTreeNode(new PlainBelliedSneech()));
                   for (int j= 0; j< 2; j++)
                        parent.add(new DefaultMutableTreeNode(new PlainBelliedSneech()));
                   parent= new DefaultMutableTreeNode(new StarBelliedSneech());
                   root.add(parent);
                   for (int j= 0; j< 2; j++) {
                        child= new DefaultMutableTreeNode(new PlainBelliedSneech());
                        parent.add(child);
                        for (int k= 0; k< 2; k++)
                             child.add(new DefaultMutableTreeNode(new StarBelliedSneech()));
                   for (int j= 0; j< 2; j++)
                        parent.add(new DefaultMutableTreeNode(new StarBelliedSneech()));
              final FilteredTreeModel model= new FilteredTreeModel(root);
              JTree tree= new JTree(model);
    tree.setShowsRootHandles(true);
    tree.putClientProperty("JTree.lineStyle", "Angled");
              tree.setRootVisible(false);
              JScrollPane sp= new JScrollPane(tree);
              sp.setPreferredSize(new Dimension(200,400));
              final JCheckBox check= new JCheckBox("Show Star Bellied Sneeches");
              check.setSelected(model.getShowStarBelliedSneeches());
              check.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        model.setShowStarBelliedSneeches(check.isSelected());
              JPanel panel= new JPanel(new BorderLayout());
              panel.add(check, BorderLayout.NORTH);
              panel.add(sp, BorderLayout.CENTER);
              JOptionPane.showOptionDialog(
                   null, panel, "Sneeches on Beeches",
                   JOptionPane.DEFAULT_OPTION,
                   JOptionPane.PLAIN_MESSAGE,
                   null, new String[0], null
              System.exit(0);
         public static void main(String[] argv) {
              new FilteredTree();

  • Expanded tree view by default

    I have created a tree and placed it in page 0 using application express 3.1
    On the initial page load my tree is not fully expanded and it comes along with "up" link as given below:
    Parent node1 (up)
    subnode1
    subnode2
    But the tree should appear in the expanded mode on the initial page load itself with out the "up" hyperlink as below:
    Root node+
    Parent node1
    subnode1
    subnode2
    Parent node1
    subnode1
    subnode2
    can any one give a suggestion on this?
    Thanks in advance
    Angeline.F

    Varad,
    I tried doing that
    By default the URL will take "::NO::FSP_AFTER_LOGIN_URL:" value.
    But i forced my URL with ":up:NO::P0_TREE_ROOT:1000" which gave me an expanded mode.
    In my application i am using conditional cache. if the url is changed for expand mode then cache is not enabled.
    can you suggest me some other way.
    thanks and regards
    Angeline.F

  • Creating Tree Model in JDeveloper 11.1.2

    hi!
    I tried the steps written in blog below but it didn't work. The output was 'no data to display'. Can anyone suggest me where I can find full procedure according to JDeveloper 11.1.2 for creating our own Tree model.
    [http://www.yonaweb.be/creating_your_own_treemodel_adf_11g_0]
    Thanks in advance!!
    Edited by: 886029 on Sep 22, 2011 4:51 AM

    You can check the tree demos here:
    http://www.oracle.com/technetwork/developer-tools/adf/documentation/adf-faces-rc-demo-083799.html
    for examples of beans with tree model.
    Of course if you are just accessing a database, then using ADF BC or JPA/EJB will get you there without any code needed.

  • Expand tree in WebDynpro ABAP application

    Hi,
    Currently I am working on a WDA application which contains a UI ELEMENT TREE. The tree is generated dynamically at runtime.
    I was guided by the example of SAP "WDT_TREE". After generating the tree looks like this:
    TREE
       | __ NODE1
               | __ LEAF1
               | __ LEAF2
               | __ NODE2
                    | __ LEAF3
               | __ Node3
                    | __ LEAF4
                    | __ LEAF5
                    | __ LEAF6
    Now I have bound the "expanded" property of the node to a context element and execute the following action in the WDDOINIT:
    * Fill tables with the structure of the tree
      fill_foldertable( ).
      fill_filetable( ).
      lr_current_node    = wd_context->get_child_node( 'FOLDER' ).
      lr_current_element = lr_current_node->create_element( ).
      lr_current_node->bind_element( lr_current_element ).
      lr_current_node->set_lead_selection( lr_current_element ).
      lr_current_element->set_attribute( name = 'TEXT' value = 'Products' ).
    lr_current_element->set_attribute( name = 'IS_EXPANDED' value = 'X' ).
    * Create the root node
      create_node(
        EXPORTING
          cur_element = lr_current_element
          parent_key  = 'Categories' ).
    Now the tree is expanded, but i can't see EAF1 and LEAF2. I get them only by clicking again on node1.
    Any ideas?
    Regards.

    Hi All,
    I found the solution for my question.  Expand tree in Webdynpro application
    Soultion
    In the context node i.e used as a source for tree, you create a attribute
    Attribute Name: IS_BOOLEAN
    Attribute type : WDY_BOOLEAN
    Default Value : X
    And in Context node Un check the Initialization lead selection.
    Now bind the Expand property of TreeNodeType with 'IS_EXPAND' which you have created just now.
    This way the whole tree will be expanded.
    Regards,
    Pavan Maddali

  • Box model experts, why wouldnt this layout allow for a container div to fully expand?

    Box model experts, why wouldnt this layout allow for a container div to fully expand?
    Please see attached jpg.
    Live site is at http://www.theminnternet.com/

    You have an answer for the height issue, you may also be interested in this article that talks about cutting down on the stylesheet size... you have a lot of styles in your stylesheet that can really be trimmed down by using shorthand rules.
    http://www.communitymx.com/content/article.cfm?cid=A43B828960590F55

  • Bette way to referenced tree model nodes from UI to perform actions on them

    A singleton facade is built.
    Its init() method loads several "tree model configs", each of them referenced by a name.
    This singleton creates a Project instance for a given "tree model config" calling the facade method -> createProject(String pjrName, String modelConfigName)
    When the Project is built a new Model instance is set ( remember the model instance is a tree holding nodes )
    The new Project instance built is added to a List that the facade has and then it's returned to the UI part that called ->createProject(prjName,modelconfigName)
    Given the Project instance the UI has to build a JTree representation of the model that the project references and the UI will have button actions that should call methods of the Nodes of the model referenced by the Project.
    Doing it this way the UI will be able to reference objects directly without going through the facade.
    Maybe I should return to the UI something like a ProjectKey instance instead of letting have the UI the Project instance ?
    It should be better if I process the possible node actions behind the Facade and not the UI, but how can I do it ?
    Having a ProjectKey in my UI I could ask the facade a model tree representation but not having the real nodes, otherwise having some NodeKey instances ?

    Sounds like you want to represent a tree structure, without a reference to the real tree.
    I'll take it further: maybe you don't want the UI to know there's a real tree data-structure with nodes and pointers to children, because maybe you build the tree on the fly from a database.
    So use the Builder pattern instead of committing to a specific data structure.
    Google results for Builder pattern: http://www.google.com/search?hl=en&q=builder+pattern&btnG=Google+Search
    Your UI should know how to construct nodes and children graphically, when told. This means it should have methods like addNode, but related to the domain: addSubProject maybe.
    A Project object is the Director, knowing which part goes where, but it doesn't know the real end result (a JPanel or HTML). So it has a method buildProject(Builder e) or exportProject(Exporter e), where all logic of assembling the parts is.
    When you have that, write a class JTreeProjectExporter implements Exporter.
    Hope this helps.

  • JTree - with two tree Models

    I have two types of tree Models that I would like to combine into one tree i did the combination this way:
    public CombainedTreeModel(BaseTreeModel firstSubTree,BaseTreeModel secondSubTree) {
    super(null);
    BaseTreeNode root=new BaseTreeNode("root");
    insertNodeInto(firstSubTree.getTreeRoot(),root,GuiConstants.INDEX_ZERO);
    insertNodeInto(secondSubTree.getTreeRoot(),root,GuiConstants.INDEX_ONE);
    and used the combined model (that is extends of BaseTreeModel -> DefaultTreeModel.) as the input of the tree.
    I see that there are elements in the tree but they are not visible.....
    what is the problem?

    I had a bit different interpertation for the MVC in swing:
    model - is a pure java class holds the data
    control- the treeModel that pass the commands to the model and after the comand was done - remove/add/update node from the tree and commite reload so the view will be refreshed
    view - the Jtree
    Everything in this model used to be ok until i combined two tree model to a third model so they will be displayed together.
    this is how I remove a node:
    public void removeContentServer(int contentServerId) throws BitBandGuiRemoveException, BitBandGuiFindException {
    if (logger.isDebugEnabled())
    logger.debug("ContentTreeModel.removeContentServer");
    BaseContentTreeNode contentServerNode = getContentServerNode(contentServerId);
    networkModel.removeContentServer(contentServerId);
    contentServerNode.removeFromParent();
    if (logger.isDebugEnabled()) {
    logger.debug("remove content server from the model" + contentServerId);
    synchronized (contentServerNode) {
    contentServerNode.removeFromParent();
    if (logger.isDebugEnabled()) {
    logger.debug("remove content server from the tree model");
    reload(root);
    }

  • XML and Tree Model !!!

    I am wanting to implement the tree model from xml data.
    I am new to this so would appreicate any help filling in the gaps. My aim is to reflect this xml file in a JTreeTable format (I have left out the table model implementation.)
    A sample xml file looks like this :
    <?xml version="1.0" ?>
    <exam>
    <Column class="xTableModel">Attribute</Column>
    <Column class="String">Value</Column>
    <Question>
    <Id>1</Id>
    <Type>TF></Type>
    <Text>Napolean was french ?></Text>
    <Answer>True</Answer>
    <Mark>3</Mark>
    </Question>
    </exam>
    How I am Reading the file:
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = factory.newDocumentBuilder();
    doc = parser.parse(xmlfile);
    Tree Model Methods. //Not really sure what i am doing here.
    public Object getChild(Object node, int i)
    Node parent = ((Node) node);
    Object child = parent.getChildNodes().item(i);
    return child;
    public int getChildCount(Object node)
    Node parent = ((Node) node);
    // int child = parent.getChildNodes().getLength();
    return 1;
    public boolean isleaf(Object node)
    Node parent = ((Node)node);
    Node child = parent.getFirstChild();
    return (child == null);
    }

    you can use a adapter pattern to convert the xml element to a TreeModel, this can be used by JTree

  • Simple Tree Model  displays the subtree on second click

    Hi,
    I want to display a simple tree model structure with root "Tableset" and subnodes like "MARA". If i click on Mara it has to display all the fields from that table.
    But it takes two clicks till the subtree opens? I suppose it needs something like a "fresh Tree".
    Sinan

    Hello Sinan,
    you have to call the method expand_root_nodes of the tree model:
    CALL METHOD model->expand_root_nodes
              EXPORTING expand_subtree = expand_subtree
                        level_count    = level_count.
    expand_subtree:
    If you set this parameter to 'X' , the system expands all subtrees of the root nodes
    level_count:
    Specifies the depth to which the root nodes should be expanded. Possible values:
    0
    : Only the root nodes themselves are expanded 1
    : The root nodes and their first level of child nodes are expanded n
          : The root nodes are expanded down to their nth level of child nodes.
    Note: If you set the expand_subtree parameter to 'X' , the value of level_count is ignored.

  • Expand tree nodes

    Hi Experts,
    Working jdev 11.1.1.3.0.
    we are using tree component on the page which as 6 childs. so if i click on add button once it will add child to that node and once i click on save done will come back to tree page. so everything is working fine. but the problem is once the node is added child node is not expanding. to resolve this issue i am using tree object in session, but while using this process its taking lot of performance.
    manually i can able to expand the tree but if once i add node to the parent tree and coming back to the page node is not expanding i have to manually expand it.
    so can any one suggest me what could be the best approch to expand the tree.
    Thanks,

    Hi,
    Hope followings useful
    http://andrejusb.blogspot.com/2010/02/how-to-traverse-adf-tree.html
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/20-expand-tree-node-from-label-169156.pdf
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/21-expand-tree-on-initial-render-169158.pdf

  • About ALV tree model transaction

    Hi Every One..
       I got a requirement that we need to display some transactions in alv tree model. and if we click on that transaction then it should display that transaction in next half of custom container (like se80 transaction) .
      Please help me out, it's urgent..
    Thanks & Regards,
    Nagalakshmi

    Hi Nagalakshmi,
    Check these sample codes:
    BCALV_TREE_SIMPLE_DEMO
    BCALV_TREE_DEMO
    BCALV_GRID_DEMO
    BCALV_FULLSCREEN_DEMO_CLASSIC
    BCALV_FULLSCREEN_DEMO
    BCALV_DEMO_HTML
    BC_ALV_DEMO_HTML_D0100
    BCALV_TREE_SIMPLE_DEMO
    Reward If Useful.
    Regards,
    Chitra

Maybe you are looking for

  • How can I remove my account on an iPad and add an existing one

    how can I remove my account on an iPad and add an existing one

  • Adobe Photoshop Scratch File

    Hi Guys, I just installed Adobe Photoshop and when trying to start the application I get this error (Mac OS X Lion): "Could not open a scratch file because the file is locked or you do not have necessary access privledges. Use the 'Get Info' command

  • Regarding database migration from Oracle to MS SQL

    Hi All, In my application, the existing database is oracle. we need to migrate from Oracle db to MS SQL. We need procedure is as below 1.export data from Oracle and keep it in a file.(.dmp) 2.Import data to MS SQL from the exported oracle file. and v

  • Map  new movement type to replace 651+453.

    Dear Experts , While doing pgr we do 651 and then 453 for taking stock into own stock.But if we want to avoid 453. How can we update quantity in pgr  with only one movement type ? New movement type(???) = (651+453).for pgr of customer returns.

  • Appearance of a Dialog

    Hi here is my code public class AudibleHelpDialog extends JDialog{ public ResourceBundle strings = ResourceBundle.getBundle("DefaultSound"); public String HELP = strings.getString("Help"); public static final String DIALOG_TITLE = "Audible Alert Help