org.openide.loaders.UniFileLoader Java Examples

The following examples show how to use org.openide.loaders.UniFileLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DataEditorSupportSaveAsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testUnmodifiedDocumentSaveAs() throws IOException {
    FileUtil.createData(FileUtil.getConfigRoot(), "someFolder/someFile.obj");
    
    DataObject obj = DataObject.find(FileUtil.getConfigFile("someFolder/someFile.obj"));
    assertEquals( MyDataObject.class, obj.getClass());
    assertTrue( "we need UniFileLoader", obj.getLoader() instanceof UniFileLoader );
    
    MyEnv env = new MyEnv( obj );
    MyDataEditorSupport des = new MyDataEditorSupport( obj, env );
    
    FileObject newFolder = FileUtil.createFolder(FileUtil.getConfigRoot(), "otherFolder");
    
    des.saveAs( newFolder, "newFile.newExt" );
    
    DataObject newObj = DataObject.find(FileUtil.getConfigFile("otherFolder/newFile.newExt"));
    assertEquals( MyDataObject.class, newObj.getClass());
    MyDataObject myObj = (MyDataObject)newObj;
    
    assertEquals("the original document was closed", 1, des.closeCounter );
    assertEquals("we don't ask before closing the original document", 0, des.canCloseCounter );
    assertEquals("new document was opened", 1, myObj.openCookieCalls);
}
 
Example #2
Source File: DataEditorSupportSaveAsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testModifiedDocumentSaveAs() throws IOException {
    FileUtil.createData(FileUtil.getConfigRoot(), "someFolder/someFile.obj");
    
    DataObject obj = DataObject.find(FileUtil.getConfigFile("someFolder/someFile.obj"));
    assertEquals( MyDataObject.class, obj.getClass());
    assertTrue( "we need UniFileLoader", obj.getLoader() instanceof UniFileLoader );
    
    obj.setModified( true );
    
    MyEnv env = new MyEnv( obj );
    MyDataEditorSupport des = new MyDataEditorSupport( obj, env );
    
    FileObject newFolder = FileUtil.createFolder(FileUtil.getConfigRoot(), "otherFolder");
    
    des.saveAs( newFolder, "newFile.newExt" );
    
    DataObject newObj = DataObject.find(FileUtil.getConfigFile("otherFolder/newFile.newExt"));
    assertEquals( MyDataObject.class, newObj.getClass());
    MyDataObject myObj = (MyDataObject)newObj;
    
    assertEquals("the original StyledDocument was rendered (no file copy)", 1, des.renderCounter);
    assertFalse("the original document is no longer modified", obj.isModified() );
    assertEquals("the original document was closed", 1, des.closeCounter );
    assertEquals("we don't ask before closing the original document", 0, des.canCloseCounter );
    assertTrue("new document was opened", myObj.openCookieCalls > 0);
}
 
Example #3
Source File: DocumentTitlePropertyTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Test updating document property Document.TitleProperty when dataobject is renamed */
public void testRename () throws IOException {
    FileUtil.createData(FileUtil.getConfigRoot(), "someFolder/someFile.obj");
    
    DataObject obj = DataObject.find(FileUtil.getConfigFile("someFolder/someFile.obj"));
    assertEquals( MyDataObject.class, obj.getClass());
    assertTrue( "we need UniFileLoader", obj.getLoader() instanceof UniFileLoader );

    EditorCookie ec = obj.getCookie(EditorCookie.class);
    
    StyledDocument doc = ec.openDocument();

    String val = (String) doc.getProperty(Document.TitleProperty);
    assertTrue("Test property value", val.startsWith("someFolder/someFile.obj"));

    obj.rename("newFile");

    val = (String) doc.getProperty(Document.TitleProperty);
    assertTrue("Test property value", val.startsWith("someFolder/newFile.obj"));
}
 
Example #4
Source File: DocumentTitlePropertyTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testDocumentId () throws IOException {
    FileUtil.createData(FileUtil.getConfigRoot(), "someFolder/someFile.obj");
    FileUtil.createData(FileUtil.getConfigRoot(), "someFolder/someFile.txt");
    
    DataObject obj = DataObject.find(FileUtil.getConfigFile("someFolder/someFile.obj"));
    DataObject txt = DataObject.find(FileUtil.getConfigFile("someFolder/someFile.txt"));
    assertEquals( MyDataObject.class, obj.getClass());
    assertTrue( "we need UniFileLoader", obj.getLoader() instanceof UniFileLoader );

    CloneableEditorSupport ecobj = (CloneableEditorSupport) obj.getCookie(EditorCookie.class);
    CloneableEditorSupport ectxt = (CloneableEditorSupport) txt.getCookie(EditorCookie.class);
    
    if (ecobj.documentID().equals(ectxt.documentID())) {
        fail("The same ID: " + ectxt.documentID());
    }
    assertEquals("Should be full name of the fileObj", obj.getPrimaryFile().getNameExt(), ecobj.documentID());
    assertEquals("Should be full name of the txtObj", txt.getPrimaryFile().getNameExt(), ectxt.documentID());
}
 
Example #5
Source File: DocumentTitlePropertyTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Test updating document property Document.TitleProperty when dataobject is moved */
public void testMove () throws IOException {
    FileUtil.createData(FileUtil.getConfigRoot(), "someFolder/someFile.obj");
    FileUtil.createFolder(FileUtil.getConfigRoot(), "newFolder");

    DataObject obj = DataObject.find(FileUtil.getConfigFile("someFolder/someFile.obj"));
    DataFolder dFolder = (DataFolder) DataObject.find(FileUtil.getConfigFile("newFolder"));

    assertEquals( MyDataObject.class, obj.getClass());
    assertTrue( "we need UniFileLoader", obj.getLoader() instanceof UniFileLoader );

    EditorCookie ec = obj.getCookie(EditorCookie.class);

    StyledDocument doc = ec.openDocument();

    String val = (String) doc.getProperty(Document.TitleProperty);
    assertTrue("Test property value", val.startsWith("someFolder/someFile.obj"));

    obj.move(dFolder);

    val = (String) doc.getProperty(Document.TitleProperty);
    assertTrue("Test property value", val.startsWith("newFolder/someFile.obj"));
}
 
Example #6
Source File: HtmlDataObject.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** New instance.
 * @param pf primary file object for this data object
 * @param loader the data loader creating it
 * @exception DataObjectExistsException if there was already a data object for it
 */
public HtmlDataObject(FileObject pf, UniFileLoader loader) throws DataObjectExistsException {
    super(pf, loader);
    CookieSet set = getCookieSet();
    set.add(HtmlEditorSupport.class, this);
    set.add(ViewSupport.class, this);
    set.assign(SaveAsCapable.class, new SaveAsCapable() {
        public void saveAs( FileObject folder, String fileName ) throws IOException {
            HtmlEditorSupport es = getCookie( HtmlEditorSupport.class );
            try {
                es.updateEncoding();
                es.saveAs( folder, fileName );
            } catch (UserCancelException e) {
                //ignore, just not save anything
            }
        }
    });

    set.assign(FileEncodingQueryImplementation.class, new FileEncodingQueryImpl());
            
    //add check/validate xml cookies
    InputSource in = DataObjectAdapters.inputSource(this);
    set.add(new ValidateXMLSupport(in));
    set.add(new CheckXMLSupport(in));
    
}
 
Example #7
Source File: JSFConfigLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo(UniFileLoader.class) };
    } catch (IntrospectionException ie) {
        Exceptions.printStackTrace(ie);
        return null;
    }
}
 
Example #8
Source File: SpringXMLConfigDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[]{Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example #9
Source File: StrutsConfigLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo(UniFileLoader.class) };
    } catch (IntrospectionException ie) {
        Exceptions.printStackTrace(ie);
        return null;
    }
}
 
Example #10
Source File: SunDescriptorDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo () {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo (UniFileLoader.class) };
    } catch (IntrospectionException ie) {
        ErrorManager.getDefault().notify(ie);
        return null;
    }
}
 
Example #11
Source File: SQLDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo () {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo(UniFileLoader.class) };
    } catch (IntrospectionException ie) {
 Exceptions.printStackTrace(ie);
        return null;
    }
}
 
Example #12
Source File: HtmlLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo () {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo (UniFileLoader.class) };
    } catch (IntrospectionException ie) {
 Exceptions.printStackTrace(ie);
        return null;
    }
}
 
Example #13
Source File: URLDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Gets additional beaninfo. */
@Override
public BeanInfo[] getAdditionalBeanInfo () {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo (UniFileLoader.class) };
    } catch (IntrospectionException ie) {
        ErrorManager.getDefault().notify(ie);
        
        return null;
    }
}
 
Example #14
Source File: PDFDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Gets additional bean infos. */
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo(UniFileLoader.class) };
    } catch (IntrospectionException ie) {
        ErrorManager.getDefault().notify(ie);
        
        return null;
    }
}
 
Example #15
Source File: ImageDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo () {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo (UniFileLoader.class) };
    } catch (IntrospectionException ie) {
 ErrorManager.getDefault().notify(ie);
        return null;
    }
}
 
Example #16
Source File: GlslVertexShaderDataLoaderBeanInfo.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[]{Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example #17
Source File: GlslGeometryShaderDataLoaderBeanInfo.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[] {Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example #18
Source File: GlslFragmentShaderDataLoaderBeanInfo.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[]{Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example #19
Source File: JspLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo () {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo (UniFileLoader.class) };
    } catch (IntrospectionException ie) {
        Exceptions.printStackTrace(ie);
        return null;
    }
}
 
Example #20
Source File: EjbJarDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo () {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo (UniFileLoader.class) };
    } catch (IntrospectionException ie) {
        Exceptions.printStackTrace(ie);
        return null;
    }
}
 
Example #21
Source File: ClientDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo () {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo (UniFileLoader.class) };
    } catch (IntrospectionException ie) {
        Exceptions.printStackTrace(ie);
        return null;
    }
}
 
Example #22
Source File: EarDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo () {
    try {
        return new BeanInfo[] { Introspector.getBeanInfo (UniFileLoader.class) };
    } catch (IntrospectionException ie) {
        Exceptions.printStackTrace(ie);
        return null;
    }
}
 
Example #23
Source File: MyDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[] {Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example #24
Source File: WhereUsedDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[] {Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example #25
Source File: PropertyChangeTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Test that fileChange event from FileObject.refresh in DES.Env.getTime is ignored
 * ie. no property change event from DES.Env is fired.
 */
public void testRename () throws IOException {
    counter = 0;
    FileObject folder = FileUtil.toFileObject(getWorkDir());
    FileObject fo = FileUtil.createData(folder,"someFile.obj");
    
    DataObject obj = DataObject.find(fo);
    assertEquals( MyDataObject.class, obj.getClass());
    assertTrue( "we need UniFileLoader", obj.getLoader() instanceof UniFileLoader );

    EditorCookie ec = obj.getCookie(EditorCookie.class);

    DataEditorSupport des = (DataEditorSupport) ec;
    DataEditorSupport.Env env = (DataEditorSupport.Env) des.desEnv();

    File file = FileUtil.toFile(fo);
    //Set lastModified time to future so openDocument -> getTime -> FileObject.refresh
    //will generate fileChange event. fileChange event must be ignored in DES.Env to avoid
    //firing propertyChange event.
    file.setLastModified(file.lastModified() + 1000000L);
    
    env.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            counter++;
        }
    });
    
    StyledDocument doc = ec.openDocument();

    assertEquals("Counter must be zero", 0, counter);
}
 
Example #26
Source File: JnlpDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[] {Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example #27
Source File: BIDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[]{Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example #28
Source File: JarDataLoaderBeanInfo.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[] {Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException ie) {
        throw new AssertionError(ie);
    }
}
 
Example #29
Source File: JspDataObject.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public JspDataObject(FileObject pf, final UniFileLoader l) throws DataObjectExistsException {
    super(pf, l);
    CookieSet set = getCookieSet();
    set.add(BaseJspEditorSupport.class, new CookieSet.Factory() {
        public <T extends Cookie> T createCookie(Class<T> klass) {
            return klass.cast(getJspEditorSupport());
        }
    });
    set.assign( SaveAsCapable.class, new SaveAsCapable() {
        public void saveAs( FileObject folder, String fileName ) throws IOException {
            getJspEditorSupport().saveAs( folder, fileName );
        }
    });
    
    set.assign(FileEncodingQueryImplementation.class, new org.netbeans.spi.queries.FileEncodingQueryImplementation() {

        public Charset getEncoding(FileObject file) {
            assert file != null;
            assert file.equals(getPrimaryFile());

            String charsetName = getFileEncoding();
            try {
                return Charset.forName(charsetName);
            } catch (IllegalCharsetNameException ichse) {
                //the jsp templates contains the ${encoding} property 
                //so the ICHNE is always thrown for them, just ignore
                Boolean template = (Boolean)file.getAttribute("template");//NOI18N
                if(template == null || !template.booleanValue()) {
                    Logger.getLogger("global").log(Level.INFO, "Detected illegal charset name in file " + file.getNameExt() + " (" + ichse.getMessage() + ")");  //NOI18N
                }
            } catch (UnsupportedCharsetException uchse) {
                Logger.getLogger("global").log(Level.INFO, "Detected unsupported charset name in file " + file.getNameExt() + " (" + uchse.getMessage() + ")");  //NOI18N
            }

            return null;
        }
        
    });

    firstStart = true;
    listener = new Listener();
    listener.register(getPrimaryFile());
    refreshPlugin(false);
    
}
 
Example #30
Source File: JspLoader.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected JspDataObject createJspObject(FileObject pf, final UniFileLoader l) 
    throws DataObjectExistsException {
    return new JspDataObject (pf, l);
}