I'm currently developing an application that will allow people to download the files from the online FTP repository, I have it connecting perfectly with Apache Commons, My only trouble is making a JTable out of it.
I know how to create a JTree, My problem is adding the nodes when they are called (Someone presses the plus icon, Load files in sub directory)
Also determining whether they are leafs... I'm sorry, I'm so lost at the moment!
If it were me, i'd remove the plus button, and just load sub directories when you get tree will expand events.
So What you could do, is populate the top level node, with a Stub node under it, and show the tree with the top level node, non-expanded. When the user expands it, you will get the tree will expand event. Look at the child, and see if it's a Stub node. If it is remove it, and use apache commons to load the children, populating each one, and each one with it's own stub node.
What is a stub node? Just a node that somehow tells you that this node is a placeholder. It means that you haven't tried to load children yet. Most likely this Node class will be a special class called StubNode or something. Of course you only need to add Stub nodes to directories, not files, as you won't be expanding files.
http://www.java2s.com/Tutorial/Java/0240__Swing/TreeWillExpandListener.htm
Related
My RCP app provides content through the CommonNavigator to the ProjectExplorer view. It provides a node whose children are resources which exist in various places on the file system inside the project, similar to how JDT or other toolkits provide a container that provides access to library resources, etc.
When a file is created on the file system inside the project, by a program external to eclipse, I detect it with an IResourceChangeListener and invoke
refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor())
on the resource, and the file appears automatically in the file tree of ProjectExplorer, in the node corresponding to its actual place on the file system. But it doesn't appear under the custom node that I contributed to the CommonNavigator, unless I manually refresh the tree from the UI.
I worked around the problem somewhat by getting a reference to the ProjectExplorer view, and calling refresh() on its CommonViewer instance. The problem with this is that the entire tree is refreshed, collapsing all nodes. But when they're re-expanded the new file shows up in my custom node as desired. I tried calling refresh(theResource) on the CommonViewer, but that has no effect.
Is there any way to cause the file to be added automatically to my custom node when it's created from outside eclipse, just as it's added to its regular place in the file tree?
UPDATE: I implemented an ICommonviewerMapper, which I set on the viewer so that it reports the mapping of model objects to Tree items. With this class I call viewer.refresh(item), where item is the Tree item that the viewer indicated to the mapper is mapped to the model object that I'm updating. In my case, the model object is an IContainer instance to which the ContentProvider adds IFile instances as children (it's one of these files that is being created outside of eclipse, which I want the viewer to show).
So I'm calling viewer.refresh() with the Tree element that is a container to which the ContentProvider will add as a child the file that was created, and still the viewer takes no action. The ContentProvider's getChildren() method is not called after refresh is invoked on the viewer. The viewer seems to be ignoring the invocation of refresh with a Tree item that I know exists in the viewer.
I am working in the java swings application and in the application we have the front menu that contain the list of the other button and the drop down menus. in the application we have the various events that are associated to one another and leads to the opening of the various frames. i want to get the list of the parents through which the particular page is open as i am right now using parent-of-parent but that will give me reference to the two level above the hierarchy but not the entire list. please help...
I'm currently learning the adf framework, and while doing this I found myself in a situation I am not able to solve.
I have a tree component that works fine. I also have different forms, corresponding to different levels of the tree. Rather than having all of the forms visible at one time, I would like to only show the one that corresponds to the selected item in the tree.
To solve this, I created af:switcher, created facets and moved the forms there. Here is where I am lost, how do I tell the switcher to change the form? I tried to link them together using the facetName on the switcher, but no success. I suspect I did not link the right thing there, but I could not find anything helpful from the tree either! I assume it has something to do with the selectionListener and a bean, but I could not figure out a way to do this. Any clues?
See Sample #50 of http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html#CodeCornerSamples
Frank
What i want to do:
I want to make the menu of my application customizable, giving the user the possibility of changing the order of the menus. For this i have build a tree (rich:tree) representing the menus in my application. By drag-n-drop the user can change the order of the menus.
The menus are kept in a xhtml file (a hierarchical structure of rich:menuGroup and rich:menuItems)
What my problem is:
When the user finishes drag-n-drop, on save i should generate xhtml code corresponding to my tree. More concrete: For each parent node in the tree generate a rich:menuGroup and for each leaf node generate a rich:menuItem. By traversing the tree i should build a hierarchical structure with menu groups containing other menu groups and/or menu items.
Is there any tool or easy way for doing this?
It would be a real pain to traverse the tree and manually concatenate hard-coded strings or something like that.
Thanks
You can use ui:repeat tag, and create menuGroups from an array in the backing bean that you created according to the tree structure. In the array, properties of each menuGroup should be provided.
Actually I'm interested to create an inverted JTree in Java in such a way that root exists at top and its child nodes at the next level and so on. As we know in case of simple JTree the child nodes appears expanding on the right side of the parent node but I want to implement inverted JTree in my project where child nodes expands downwards which gives an appearance of "TREE" type of data structure.
As this is very essential for my project so can anyone suggest me the code for the above mentioned problem?
Thanks in advance.
Then JTree is not the correct choice. Perhaps, you should look into Java2D and stuff like that.