JTree File Browser solutions and a problem

Hi everyone I have recently needed to create a file browser that allows addition, deletions and rename of files/directores using a JTree component.
I have searched the Sun web site and found a number of examples and from what I can see there are more or less two solutions. The first is to use the DefaultTreeModel and the DefaultMutableTreeNode classes and the other is to implement a new TreeModel taking advantage of a the File objects tree structure. This I found at;
http://java.sun.com/products/jfc/tsc/articles/jtree/
This to me seemed a very elegant solution. However it doesn't contain deletion, addition etc. So far I have tried to implement the addition of files but I have run into problems. The problem I have is that when I add a file a blank space ends up on the JTree view. If someone could take a look and suggest where I am going wrong I would be very greatful. The methods below I added to the FileSystemModel.java class from the url above.
     public File[] getPathToRoot(File file) {
     return getPathToRoot(file, 0);
    protected File[] getPathToRoot(File file, int i) {                              
     File[] files;
     if (file == null) {
         if (i == 0){
          return null;
         files = new File;
     } else {
     i++;
     if (file.equals( getRoot())){
               files = new File[i];
          }else{
          files = getPathToRoot(file.getParentFile(), i);
     files[files.length - i] = file;
     return files;
public void insertFileInto(String newFilePath, File parent) {
     File newFile = new File(parent, newFilePath);
     try{
          newFile.createNewFile();          
          } catch ( IOException io){
                         System.out.println("io ex");
     filesWereInserted( parent,newFile);
public void filesWereInserted(File file, File newFile) {          
     if (listenerList != null && file != null ) {
     Object[] objects = new Object[1];
          objects[0] = newFile;
          int [] is = new int[1];
          is[0] = 0;
     fireTreeNodesInserted(new TreeModelEvent(this, getPathToRoot(file), is, objects));
I basically looked at the DefaultTreeModel and tried to simluate the behaviour for files.
Since I have had this problem I remembered that out of the two solutions I have seen for a file browser the first is far more common. Perhaps I have chosse the wrong solution. Before I switch to the other soluion I thought I'ld put my problem to you guys and ask what you think the best solution is.
Thanks for any help :)

You are right this is a bad idea. You really want to implement delay loading. This means that your tree start out with only the top level folder expanded and dummy nodes in the folders that have children. Then using the expand events you can remove your dummy node and put in the real nodes before the tree displays the children. On the collapse event you can remove the real nodes and put back your dummy node (or you can leave the real nodes, that just means that eventually customers could have nodes for the entire system in memory, with a little work on their part:-). This way you only read the part of the file system that is visible and you only have the currently visible nodes in memory. I am sure you can find some examples of this technique.
While this could be done with the default models I feel that a custom model would be the way to go.
IL

Similar Messages

  • File Browse Item and validation

    Hello
    I have a page with multiple items and validations.
    One of the items is "File Browse..."
    When I select a file on my computer and submit the page, a new record is created in "APEX_APPLICATION_FILES".
    In the page I have a process that saves the blob from "APEX_APPLICATION_FILES" into one of my DB table and then I delete that record.
    That is correct.
    But, if one of my validations is triggered, the record is still created in "APEX_APPLICATION_FILES" and since the validation blocks the execution of my process, the record is not deleted.
    Normally, it should be deleted to prevent the table from taking too much space.
    Is there any DB Job that "cleans" the table?
    Thank you
    Max

    Hi
    I just tough I could do the following validation as the very last one.
    Validation type:
    "Function returning error text"
    Validation Expression:
    begin
       delete from APEX_APPLICATION_FILES
       where name = :P1_MY_BROWSE_ITEM;
       return null;
    end;Condition :
    "Inline validation errors displayed"
    Is there a "cleaner" or better solution I should use ?
    Thanks
    Max

  • JTree File Browser

    I have this class to browse the contents of my default folder. However it displays the
    full path plus the folder & file. How would remove the path and retain the folder
    and file only ?
    import java.awt.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class Tree extends JPanel {
         static JTree tree;
         static Icon leafIcon;
         static Icon openIcon;
         static Icon closedIcon;
         static DefaultTreeCellRenderer render;
         public Tree() {
              super();
              setLayout(new GridLayout());
              final JScrollPane scrollPane = new JScrollPane();
              add(scrollPane);
           setSize(157, 311);
           DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root Label");
              root.add(new DefaultMutableTreeNode("Node Label"));
              File start = new File(System.getProperty("user.dir"));
              TreeModel model = new DefaultTreeModel(new CreateNode(start));
              tree = new JTree(model);
              tree.setCellRenderer(new NodeRenderer());
              tree.setShowsRootHandles(true);
              scrollPane.setViewportView(tree);
         public static void main(String args[]) {
              Tree browse = new Tree();
              JFrame frame = new JFrame("Sample . . .");
              frame.getContentPane().add(browse, BorderLayout.CENTER);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(300,300);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
    class CreateNode extends DefaultMutableTreeNode {
        CreateNode(File dir){
            super(dir);
            fillChildren(dir);
        void fillChildren(File dir){
            String[] list = dir.list();
            if( list == null ){
                return;
            for(int i=0; i<list.length; ++i){
                File child = new File(dir, list);
    if(child.isDirectory()){
    add(new CreateNode(child));
    if(child.isFile()) {
    add(new CreateNode(child));
    class NodeRenderer extends DefaultTreeCellRenderer
    private Icon file1 = new ImageIcon("icons/File.gif");
    private Icon file2 = new ImageIcon("icons/Folder.gif");
    private Icon file3 = new ImageIcon("icons/Image.gif");
    public Component getTreeCellRendererComponent(JTree tree, Object value,
    boolean sel, boolean expanded, boolean leaf, int row,
    boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
    row, hasFocus);
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    File file = (File) node.getUserObject();
    String name = file.getName();
    if (name.endsWith(".gif")) {
    setIcon(file3);
    } else if (file.isDirectory()) {
    setIcon(file2);
    } else {
    setIcon(file1);
    return this;
    public NodeRenderer() {
    super();

    In your node renderer:
          // This is what you have:
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
          File file = (File) node.getUserObject();
          String name = file.getName();
          // This is what you missed:
          setText(name);

  • File not refreshing and error problem

    well i have 2 problems..
    first:
    i dont know why a jsp file does not reload to the edited version
    meaning lets say I have a jsp file doing something it loads up fine and does I edit the file and try reloading the old copy keeps on coming back..
    there are times when the new copy loads up but that is rare..
    second can anyone tell me what is wrong with this code.. I cant figure out what is wrong with it.. only in the <form></form> tags
    because rest of the code is fine
    i keep on getting nullpointerexception i dont understand why
    <%@ page import="java.io.*"%>
    <%@ taglib uri="taglibdb.tld" prefix="sql" %>
    <html>
    <head>Admin Property</head>
    <body>
         <form name="addproperty" method="post" action="../servlet/PropertyServlet">
         <% if (request.getParameter("action").equalsIgnoreCase("edit")){
         %>
              <input type="text" name="val" value="<%=request.getParameter("val")%>">
              <input type="text" name="property" value="<%=request.getParameter("property")%>">
              <input type="submit" name="editproperty">
         <% } else { %>
         <input type="text" name="property">
         <input type="submit" value="addprop">
         <% } %>
    </form>
    <sql:openConnection driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/mydb" user="guest" password="guest" id="A" />
    <sql:ifError id="A">
    <br>Could not connect to database
    </sql:ifError>
    <sql:setQuery id="A" query="select * from PROPERTY" res="B"/>
    <table>
    <sql:forEachRow res="B">
    <tr>
         <td><sql:getColumn position="1" res="B"/></td>
         <td><sql:getColumn position="2" res="B"/></td>
         <td>">Delete...</a></td>
         <td><a href="../jsp/property.jsp?action=edit&val=<sql:getColumn position="1" res="B"/>&property=<sql:getColumn position="2" res="B"/>">Edit...</a></td>
    </tr>
    </sql:forEachRow>
    </table>
    <sql:closeConnection id="A"/>
    </body>
    </html>
    if i change the form part to:
    <form name="addproperty" method="post" action="../servlet/PropertyServlet">
         <input type="text" name="property">
         <input type="submit" value="addprop">
    </form>
    it works fine the way it is suppose to

    In case you are running Tomcat 4.1 the java file and class file of your jsp is located in Tomcat 4.1/work/standalone/.. and your file should be named something like MyJspPage_jsp.java (try search for it).
    About your nullpointer, you should check your spelling when requesting parameters,
    request.getParameter("action") is not the same as request.getParameter("Action") etc.
    Good luck.
    Johan

  • Grantor Managment solutions and BCS problem after technical upgrade.

    Hello every one,
    The current release SAP installation was upgraded to ECC 6.0; this was a technical upgrade and did not replace functionality such as "Former Budgeting" with the new BCS functionality.  SAP developed the Grantor Management solution utilizing BCS.  BCS utilizes a different table structure from the Former Budgeting functionality.  The current tables do not contain the BCS reference points to each other which limits the implementation of Grantor Management in the same instance. There are no plans to upgrade to BCS functionality at this point in time.
    what are my options? How can we work around this issue?
    Regards
    K

    Hi,
    Thanks for the resposnse.
    But when i go through the OSS notes it is provided that there will be performance problem in executing the report.
    How to get it solved?
    Thanks,
    Regards
    M.A

  • Motion problem with File Browser Window

    For some reason I lost the File Browser Inspector and Library window and can't get it back
    I have tried under the window tab and It will not let me check them to show it again. What can I do?
    They appear in my toolbox at the top but also will not let me click on them.

    Ron,
    Trash your preferences, there are loads of posts on here about how to do that if you search.
    Peter

  • Open Cursor Issue because of file browse Item - Is this a Bug in APEX 3.2

    Hi All,
    I am using file browse Item to upload file into the database at two places in my application, but it seems whenever I am submitting those two pages, with file path or without file path, its opening an cursor which remains open after that, because of this open cursor count in the application is getting exceeding every time.
    For testing this I have made an dummy page containing just file browse item and submit button, and still it is increasing the open cursor count.
    Is this a bug in Apex file browse item or there is some other way to handle this.
    Please kindly help me in the above issue as this is affecting the production application.
    Thanks & Regards
    Sanjay
    Edited by: user11204334 on Dec 5, 2010 9:57 PM
    Edited by: user11204334 on Dec 5, 2010 9:58 PM

    Hi,
    One observation, Apex is switching the Session ID after one got killed ? I was working on Apex page with browse Item to test open cursor count,
    after killing the SID (227) on which the open cursor count was getting increase, it APEX automatically switches to new SID(149) for that session.
    Now the problem is even if I have two SID's and one hits the maximum open cursor count, It is not switching to other SID instead the whole application becomes unavailable.
    STATNAME SID VALUE USER
    opened cursors current 20 14 APEX_PUBLIC_USER
    opened cursors current 149 74 APEX_PUBLIC_USER
    opened cursors current 194 71 APEX_PUBLIC_USER
    opened cursors current 211 5 APEX_PUBLIC_USER
    opened cursors current 227 325 APEX_PUBLIC_USER Killed
    opened cursors current 244 15 APEX_PUBLIC_USER
    opened cursors current 20 14 APEX_PUBLIC_USER
    opened cursors current 149 76 APEX_PUBLIC_USER
    opened cursors current 194 71 APEX_PUBLIC_USER
    opened cursors current 211 5 APEX_PUBLIC_USER
    opened cursors current 244 15 APEX_PUBLIC_USER
    Please kindly help in this.
    Thanks in Advance
    Thanks & Regards
    Sanjay
    Edited by: user11204334 on Dec 8, 2010 1:02 AM

  • Unable to Clear File Browse

    Hi ,
    In one of my page I have File Browse item and storage type is WWV_FLOW_FILES.
    by using page process Clear Cache for all items on pages I am clearing all items on this pages. I assign this process to Clear button.
    my requirement is After I chose the file to load  and hit Clear button,  the screen goes blank
    when page goes blank url is looking some thing like this http://172.17.0.135:8080/apexebr/wwv_flow.accept
    I am using Apex 4.1
    Glassfish server
    problem is in every browser.
    db is 11g
    Theme 17
    Please help me regarding this
    Thanks
    Sagar

    Hi,
    as you click brows file and pick your file, and before you submit your page ... the file gets uploaded to Flow_files table.....
    This could be helpful :
    http://docs.oracle.com/cd/E14373_01/appdev.32/e13363/up_dn_files.htm#CJAHDJDA

  • LabVIEW file browser can't see folders

    I am using LabVIEW 7.0 on Sparc Solaris 2.6.  I am using NFS to serve folders from a RHEL5 linux server.  These folders contain my LabVIEW code, and I am mounting them on my Sparc Solaris workstation.  When I open the LabVIEW file browser, some folders and files (but not all) appear to be missing.  LabVIEW will open the files no problem if I type in the complete path.  For example, when I navigate to directory A, there should be SubdirA and SubdirB, but SubdirB does not show up in the file browser.  Yet, if I just type SubdirB in the text box, I can navigate to this directory no problem.  Using my terminal, I can view these folders without issue.  When I use the file browser on nedit, hotjava, tedit, image viewer, etc. I do not have this problem.  It is only the LabVIEW file browser that has the problem.  Can anyone tell me what this could be, and if there is anything I can do to fix it?

    Solaris workstation hostname: stealth3
    Linux server hostname: linux1
    Shared (through NFS) folder directory on linux1: /share/ims_programs
    mounted (through NFS) directory on stealth3: /mnt/ims_programs
    The /mnt/ims_programs folder contains two subdirectories: production and certification.  When using ls from the command line, both subdirectories are visible.  In the same way, the file browser for graphical applications like nedit, tedit, hotjava, etc. can see both subdirectories.  The LabVIEW file browser does not show one of the two.  As best as I can remember, it showed certification but not production.  Descending into the file structure, there are many cases like this, where existing files or folders are "hidden".  When the exact same directory structure is copied to a Solaris server and shared with NFS, the LabVIEW browser can see everything.

  • Prepopulate data in File Browse in APEX

    Hi,
    Here is what I am trying to do and yet unable to figure it out -
    I have a record in a database table with one of the field being the BLOB type.  I need to update several data fields for this record but need to leave the BLOB data untouched. 
    I have a APEX form for this.  On the form, the BLOB data field is displayed as a "File Browse" item (say, File ABC) and is a required field.  However, I am having problems retrieving the corresponding data from the database.  Upon submit, the form always fails with a message saying "File ABC must have some values".
    How can I go about pre-populating the data for this "File Browse" item?  I just need the BLOB data staying untouched and yet being able to bypass the validation for an update of the entire record.
    Any suggestion is highly appreciated.  Thanks in advance!
    Ning

    951789 wrote:
    Please update your forum profile with a real handle instead of "951789".
    I have a APEX form for this.  On the form, the BLOB data field is displayed as a "File Browse" item (say, File ABC) and is a required field.  However, I am having problems retrieving the corresponding data from the database.  Upon submit, the form always fails with a message saying "File ABC must have some values".
    How can I go about pre-populating the data for this "File Browse" item?  I just need the BLOB data staying untouched and yet being able to bypass the validation for an update of the entire record.
    You can't. For security reasons the value of the file browse item cannot be set on the server.
    Make the validation on the file browse item and processing of the uploaded file conditional, for example making it mandatory on insert (when the row PK item is null).

  • File Browser/Inspector is stuck

    After having Motion up on my computer for only a short time I 'lost' the File Browser, Inspector and Library and I can't get it back. actually at the begin i couldn't use the Motion3, then the techion suggect me open a new account. after that i can use the motion3 but only 2~3 weeks the File Browser, Inspector and Library are miss. Do I need to reinstall? Or open a new account AGAIN?

    Yes, so deleting the preferences file solves the problem...for a time. But once I close Motion and re-open, the same problem occurs. So I have to delete this preferences file in order to use the File Browser every time I close Motion. How do we communicate with the programmers to get this bug patched?

  • Dynamic action on File browse change event

    Hi Experts,
    apex version 4.1
    This is what i'm trying to do..
    i have a file browse control and a text field. when user selects a file, selected fiel's name (without file type extension) should be set to text field.
    I tried adding a dynamic action to file browse control's change event and within pl/sql Set Value logic i queried the wwv_flow_files and tried to return the file name it didn't work. i got no data found error. i assumed file is being inserted into wwv_flow_files when a page submission happens.
    In my second approach within the SetValue pl/sql logic i got the file browser control's (by directly accessing field, not by querying wwv_flow_files)value and did some string manipulation and tried to return only the file name. yet i got the same no data found error.
    Any idea how can i implement this ?
    Thanks in advance.
    - kurubaran

    Hi,
    I think PL/SQL approach will not work before you submit data to database.
    Have you think use $v function to get value from file browser?
    http://docs.oracle.com/cd/E23903_01/doc/doc.41/e21676/javascript_api.htm#BGBGDGIH
    Regards,
    Jari
    My Blog: http://dbswh.webhop.net/dbswh/f?p=BLOG:HOME:0
    Twitter: http://www.twitter.com/jariolai

  • How to populate DB column with filename from file browse item?

    Hi,
    Using APEX 3.1.2, I'm trying to easily allow maintenance of a filename stored in a DB column (VARCHAR2(1000)). Using the column as a file browse item seemed to be the way to go, but of course I don't want the resulting file to be uploaded and it appears as though an existing filename is not shown in a form when the row is retrieved.
    After much searching, I found Checking filename length in File Browse item before uploading , but I'm not able to connect the dots. I was thinking that I could create a hidden file browse item and use a button to call Javascript function to activate it, then save the resulting filename to my DB column item and wipe out the hidden item before it was uploaded. But the hidden item doesn't appear, so I'm not able to reference it's form input name.
    Hopefully this mess makes sense. Anyone?
    Thanks!
    Rich
    Edited by: socpres on Sep 5, 2008 2:02 PM because message was truncated after attempting to preview it first.

    Hi John,
    From what I can tell, the path of a local file browsed from a file browse item cannot be retrieved because of security concerns. Although, it seems that while Firefox 3 only returns the filename sans directory, IE6 returns the full path:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
    <head><title>Form Test</title>
    </head><body>
    <script type="text/javascript" language="JavaScript">
    function GetDirectory()
    strFile = document.FileForm.filename.value;
    intPos = strFile.lastIndexOf("\\");
    strDirectory = strFile.substring(0, intPos);
    alert(strDirectory);
    document.FileForm.Directory.value = strDirectory;
    </script>
    <form id="FileForm" name="FileForm">
    <input type="file" id="filename" name="filename" value="" onChange="GetDirectory(this.value)">
    <input type="hidden" id="Directory" name="Directory" value="">
    </form>
    </body>
    </html>
    This Win-specific code displays the path via IE6, but not in Firefox 3. Then again, I can't seem to preview posts here using FF3, either...
    Rich

  • File Browse Item questions..

    Hi all..
    Please help me with these questions on ""file_browse"" item.
    I have a file browse item on a page, like in the following app.
    http://apex.oracle.com/pls/apex/f?p=62812:1
    1) when the user select a file with the browse button,we will get the
    """file path""" in the text field.
    Is it possible to validate (via javascript or any other way), whether that particular
    ""file path"" is correct and a valid file exist as per the ""file path""??The reason for this validation is, sometime our users will copy the ""file path"" instead of using the
    file browse button.
    2) http://apex.oracle.com/pls/apex/f?p=62812:1
    If users enter a valid path, but on that particular page if i have any validations,
    If any of the validations fails, it is clearing of the ""file path"" that the user entered.
    Is it possible to retain the ""file_path"" that the users entered? even if any validations fail?EX: In the following page
    http://apex.oracle.com/pls/apex/f?p=62812:1
    Please
    i)select a valid file from the ""file browse"" item and
    ii)""dont select any select list "" value
    iii) click upload.
    validation will get fired and file path get cleared.
    Thanks

    kumar wrote:
    Thanks for the reply fac...
    fac..just curious to know, what security issue do any one get , if file browse item keeps the ""file path"" they previously selected..The issue is not the server keeping the file "previously selected", but maliciously changing the value to capture a file the user does not intend to submit (e.g /etc/passwd) when the invalid page is resubmitted.
    so every time, when some validation fails, ""user need to reselect that file"".??For their own safety, yes.
    even it is in session state.. for a common user,he feels that it got cleared out and need to ""reselet "" the file again..It's a good practice to clean up any submitted files in APEX_APPLICATION_FILES should any related validations fail.
    Is there any other alternative for this issue? or It is (file browse item) just how it behaves?To ensure a secure and safe web environment it's how it's got to behave.
    Good UI design can be used to minimize the impact on users by isolating file browse items on different pages to items that are prone to validation failure, through the use of multi-page wizards etc.

  • File browser shortcut

    Hello,
      I am using LabWindows CVI v12.0 with Windows 7.  I am using the file browser feature and want to be able to click on a shortcut to another folder, but the shortcut does not appear.  Is there a way to use shortcuts with the file browser?  
    thanks,
    Brent

    Hello there!
    Unfortunately, the File Browser Intrument won't display shortcut links in the left folder tree. These are however listed and available in the right tree, where the directory contents are displayed.
    The reason for this is that, internally, the File Browser Instrument explictly doesn't allow shortcuts to be listed in the right tree, due to the way in which the intrument is written.
    However, you are free to change the behavior of the custom control. The source code is located under <CVI Installation>\toolslib\custctrl\FileBrowser.c, so you can modify it to fit your needs.
    Here is a helpful hint about how you could modify this custom control:
    PopulateFolderWithPath populates the right directory tree with all directories under the current expanded item.
    The folders from that directory are retrieved using GetFirstFile and GetNextFile.
    However, GetFileAttrs filters the items under the directory. As GetFirstFile returns -1 when the .lnk is found, it doesn't add it to the right directory tree and gets skipped.
    Here are some options about how you could work around this limitation:
    Explicitly verify for .lnk files. This way you can determine that the file/folder is actually a link, without using GetFileAttrs.
    Although it's easier to determine symbolic links on Linux (readlink, stat), on Windows, this is a suggestion from MSDN on how to do this: Determining Whether a Directory Is a Mounted Folder
    I hope this helps!
    - Johannes

Maybe you are looking for

  • After installing Lion, Win XP no longer works with Parallels 6. Help!

    The start-up button won't work, windows explorer doesn't work, everything i click on has the hourglass that goes on forever and nothing happens.  If I can't find a solution soon, I will be asking for info on wiping out windows and Parallels completel

  • Links to files not working in Safari 5.1

    I have an HTML document on my hard drive that links to various TextEdit files on my computer. It's a great shortcut tool. I click a link, and it instantly opens up the file in TextEdit. However, I just upgraded to Safari 5.1, and now when I click the

  • Reg : Material warehouse management view 1 & 2

    Hello All, Using a Z-programI am extending the warehouse managemnt view for a single Plant, the view gets created successfully. But some how an Inactive version of Warehouse management view gets created for other plant also. How we can prevent the cr

  • Rolluptime (LastDataRefresh) on infosets

    Hello, We have in our BW 3.5, infoproviders with information from MIC compontent (Internal Control). These infoproviders are mainly infosets that sometimes join ODS and characteristics (type 1), but sometimes have just characteristics as its componen

  • How to delete a SC

    The follow on documents for the SC has been deleted.Now I want to delete the SC.The delete button for this SC has been greyed out.So can you please advice as to how I can delete this SC. Thanks & Regards