Java Code Examples for org.openide.loaders.UniFileLoader

The following examples show how to use org.openide.loaders.UniFileLoader. These examples are extracted from open source projects. 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 Project: netbeans   Source File: DataEditorSupportSaveAsTest.java    License: 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 Project: netbeans   Source File: DataEditorSupportSaveAsTest.java    License: 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 Project: netbeans   Source File: DocumentTitlePropertyTest.java    License: 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 Project: netbeans   Source File: DocumentTitlePropertyTest.java    License: 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 Project: netbeans   Source File: DocumentTitlePropertyTest.java    License: 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 Project: netbeans   Source File: HtmlDataObject.java    License: 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 Project: netbeans   Source File: JarDataLoaderBeanInfo.java    License: 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 8
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[]{Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example 9
Source Project: netbeans   Source File: BIDataLoaderBeanInfo.java    License: 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 10
Source Project: netbeans   Source File: JnlpDataLoaderBeanInfo.java    License: 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 11
Source Project: netbeans   Source File: PropertyChangeTest.java    License: 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 12
Source Project: netbeans   Source File: WhereUsedDataLoaderBeanInfo.java    License: 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 13
Source Project: netbeans   Source File: MyDataLoaderBeanInfo.java    License: 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 14
Source Project: netbeans   Source File: EarDataLoaderBeanInfo.java    License: 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 15
Source Project: netbeans   Source File: ClientDataLoaderBeanInfo.java    License: 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 16
Source Project: netbeans   Source File: EjbJarDataLoaderBeanInfo.java    License: 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 17
Source Project: netbeans   Source File: JspLoaderBeanInfo.java    License: 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 18
Source Project: netbeans   Source File: JSFConfigLoaderBeanInfo.java    License: 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 19
Source Project: netbeans   Source File: StrutsConfigLoaderBeanInfo.java    License: 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 20
Source Project: netbeans   Source File: SunDescriptorDataLoaderBeanInfo.java    License: 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 21
Source Project: netbeans   Source File: SQLDataLoaderBeanInfo.java    License: 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 22
Source Project: netbeans   Source File: HtmlLoaderBeanInfo.java    License: 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 23
Source Project: netbeans   Source File: URLDataLoaderBeanInfo.java    License: 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 24
Source Project: netbeans   Source File: PDFDataLoaderBeanInfo.java    License: 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 25
Source Project: netbeans   Source File: ImageDataLoaderBeanInfo.java    License: 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 26
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[]{Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example 27
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[] {Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example 28
@Override
public BeanInfo[] getAdditionalBeanInfo() {
    try {
        return new BeanInfo[]{Introspector.getBeanInfo(UniFileLoader.class)};
    } catch (IntrospectionException e) {
        throw new AssertionError(e);
    }
}
 
Example 29
Source Project: netbeans   Source File: JspLoader.java    License: 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);
}
 
Example 30
Source Project: netbeans   Source File: JspDataObject.java    License: 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);
    
}