Netbeans Platform and Memory File System

September 1st, 2007 | by Tonny Kohar |

Normally, using Netbeans Platform you have to use DataObject.find() and use the OpenCookie to open the DataObject (eg: file, etc) to be opened on the Editor TopComponent. However, for certain case, I do not have the file yet eg: in Sketsa menu File - New. We do not want to create or store this as file yet, in case the user choose to discard the file. The file will be written to the disk, when the user choose either Save or Save As

Fortunately, Netbeans Platform have build in memory FileSystem that we could use for this kind of problem

FileSystem fs = FileUtil.createMemoryFileSystem();
FileObject fob = fs.getRoot().createData(name,"svg");
DataObject data = DataObject.find(fob);
OpenCookie cookie = (OpenCookie)data.getCookie(OpenCookie.class);
cookie.open();
  1. 3 Responses to “Netbeans Platform and Memory File System”

  2. By Pavel Buzek on Sep 8, 2007 | Reply

    I am curious, how did you make the first Save for .svg file to behave like SaveAs? Is this handled in you SaveCookie or have you changed some code in NetBeans to achieve this? Thanks.

  3. By Tonny Kohar on Sep 8, 2007 | Reply

    Actually, our SaveCookie implementation is very simple. It is just forward the call to our SVGEditorSupport.saveDocument() methods.

    We handled the first Save behaviour in the editorSupport.saveDocument methods by checking the document URI (note: this is SVGDataObject specific).

    protected void saveDocument() throws IOException {
        String uriString = dataObject.getSVGDocument().getDocumentURI();
        if (uriString != null) {
        	String path = null;
            try {
                URI uri = new URI(uriString);
                path = new File(uri).toString();
                //System.out.println(path);
           	} catch (URISyntaxException ex) {
                throw new IOException("URISyntaxException");
            }
     
            boolean compress = false;
     
    	if (path.toLowerCase().endsWith(".svgz")) {
                compress = true;
            }
            saveDocument(path, compress); // normal save
     
        } else {
            saveDocumentAs(); // saveAs behaviour
        }
    }

    Alternatively, you could check for the real physical file exists or not. Since it is memory filesystem, there should not be real file exists (note: we haven’t tried this methods)

  4. By Vinod Kumar Saini on Jan 6, 2009 | Reply

    http://www.smarterdeals.com/Goods.aspx?stxt=&cat_id=All&brand=All&vendor=810&price_from=&price_to=&vpn=&id=

Post a Comment