Java Code Examples for org.openide.loaders.DataObject#rename()

The following examples show how to use org.openide.loaders.DataObject#rename() . 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: RenameHandlerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRename(Node node, String newName) {
    InstanceContent ic = new InstanceContent();
    ic.add(node);
    ExplorerContext d = new ExplorerContext();
    d.setNewName(newName);
    ic.add(d);
    Lookup l = new AbstractLookup(ic);
    DataObject dob = node.getCookie(DataObject.class);
    Action a = RefactoringActionsFactory.renameAction().createContextAwareInstance(l);
    if (Boolean.TRUE.equals(a.getValue("applicable"))) {//NOI18N
        a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT);
    } else {
        try {
            dob.rename(newName);
        } catch (IOException ioe) {
            ErrorManager.getDefault().notify(ioe);
        }
    }
}
 
Example 2
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 3
Source File: PHPRenameFileRefactoringUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void doRefactoringBypass() throws IOException {
    DataObject dob = DataObject.find(file);
    if (dob != null) {
        dob.rename(panel.getNameValue());
    }
}
 
Example 4
Source File: FilesystemInterceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void renameDO(File from, File to) throws DataObjectNotFoundException, IOException {
    DataObject daoFrom = DataObject.find(FileUtil.toFileObject(from));
    daoFrom.rename(to.getName());
}
 
Example 5
Source File: InteceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void renameDO(File from, File to) throws DataObjectNotFoundException, IOException {
    DataObject daoFrom = DataObject.find(FileUtil.toFileObject(from));                
    daoFrom.rename(to.getName());               
}
 
Example 6
Source File: InterceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void renameDO (File from, String newName) throws DataObjectNotFoundException, IOException {
    DataObject daoFrom = DataObject.find(FileUtil.toFileObject(from));
    daoFrom.rename(newName);
}