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

The following examples show how to use org.openide.loaders.DataObject#copy() . 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: TemplatesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static DataObject createDuplicateFromNode (Node n) {
    DataObject source = getDOFromNode (n);
    try {
        Node parent = n.getParentNode ();
        DataObject target = source.copy(source.getFolder());
        FileObject srcFo = source.getPrimaryFile();
        FileObject targetFo = target.getPrimaryFile();
        setTemplateAttributes(targetFo, srcFo);
        if (parent != null) {
            Node duplicateNode = null;
            for (Node k : parent.getChildren ().getNodes (true)) {
                if (k.getName ().startsWith (targetFo.getName ())) {
                    duplicateNode = k;
                    break;
                }
            }
            if (duplicateNode != null) {
                final Node finalNode = duplicateNode;
                SwingUtilities.invokeLater (new Runnable () {
                    @Override public void run() {
                        try {
                            manager.setSelectedNodes (new Node [] { finalNode });
                            view.invokeInplaceEditing ();
                        } catch (PropertyVetoException ex) {
                            Logger.getLogger (TemplatesPanel.class.getName ()).log (Level.INFO, ex.getLocalizedMessage (), ex);
                        }
                    }
                });
            }
        }
        return target;
    } catch (IOException ioe) {
        Logger.getLogger(TemplatesPanel.class.getName()).log(Level.WARNING, null, ioe);
    }
    return null;
}
 
Example 2
Source File: CopyFile.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void performChange() {
    try {
        FileObject targetFo = FileHandlingFactory.getOrCreateFolder(target);
        FileObject Fo = fo;
        DataObject dob = DataObject.find(Fo);
        newOne = dob.copy(DataFolder.findFolder(targetFo));
        if(newName != null) {
            newOne.rename(newName);
        }
        FileObject[] newFiles = context.lookup(FileObject[].class);
        FileObject newFile = newOne.getPrimaryFile();
        newFile.setAttribute("originalFile", fo.getNameExt()); //NOI18N
        if (newFiles == null) {
            newFiles = new FileObject[]{newFile};
        } else {
            // rather a special case: there can be files from former run of the refactoring,
            // which had been undone. In that case, those files may be invalid and will cause
            // parser errors if processed.
            List<FileObject> stillValidFiles = new ArrayList<>(newFiles.length);
            for (FileObject f : newFiles) {
                if (f.isValid()) {
                    stillValidFiles.add(f);
                }
            }
            newFiles = new FileObject[stillValidFiles.size() + 1];
            stillValidFiles.toArray(newFiles);
            newFiles[newFiles.length - 1] = newFile;
        }
        context.add(newFiles);
        context.add(newFile);
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
 
Example 3
Source File: CatalogPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static DataObject createDuplicateFromNode(Node n) {
    DataObject source = getDOFromNode(n);
    try {
        return source.copy(source.getFolder());
    } catch (IOException ioe) {
        Logger.getLogger(CatalogPanel.class.getName()).log(Level.WARNING, null, ioe);
    }
    return null;
}
 
Example 4
Source File: FilesystemInterceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void copyDO(File from, File to) throws DataObjectNotFoundException, IOException {
    DataObject daoFrom = DataObject.find(FileUtil.toFileObject(from));
    DataObject daoTarget = DataObject.find(FileUtil.toFileObject(to.getParentFile()));
    daoFrom.copy((DataFolder) daoTarget);
}
 
Example 5
Source File: InteceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void copyDO(File from, File to) throws DataObjectNotFoundException, IOException {
    DataObject daoFrom = DataObject.find(FileUtil.toFileObject(from));
    DataObject daoTarget = DataObject.find(FileUtil.toFileObject(to.getParentFile()));
    daoFrom.copy((DataFolder) daoTarget);
}
 
Example 6
Source File: InterceptorTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void copyDO (File from, File to) throws DataObjectNotFoundException, IOException {
    DataObject daoFrom = DataObject.find(FileUtil.toFileObject(from));
    DataObject daoTarget = DataObject.find(FileUtil.toFileObject(to.getParentFile()));
    daoFrom.copy((DataFolder) daoTarget);
}