Search in sources :

Example 41 with FileObject

use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.

the class SourcePathProviderImpl method setSourceRoots.

/**
 * Sets array of source roots.
 *
 * @param sourceRoots a new array of sourceRoots
 */
public void setSourceRoots(String[] sourceRoots) {
    LOG.log(Level.FINE, "SourcePathProviderImpl.setSourceRoots(" + java.util.Arrays.asList(sourceRoots) + ")");
    Set<String> newRoots = new HashSet<String>(Arrays.asList(sourceRoots));
    ClassPath oldCP = null;
    ClassPath newCP = null;
    synchronized (this) {
        List<FileObject> sourcePath = new ArrayList<FileObject>(Arrays.asList(smartSteppingSourcePath.getRoots()));
        List<FileObject> sourcePathOriginal = new ArrayList<FileObject>(Arrays.asList(originalSourcePath.getRoots()));
        // First check whether there are some new source roots
        Set<String> newOriginalRoots = new HashSet<String>(newRoots);
        for (FileObject fo : sourcePathOriginal) {
            newOriginalRoots.remove(getRoot(fo));
        }
        if (!newOriginalRoots.isEmpty()) {
            for (String root : newOriginalRoots) {
                FileObject fo = getFileObject(root);
                if (fo != null) {
                    sourcePathOriginal.add(fo);
                }
            }
            originalSourcePath = ClassPathSupport.createClassPath(sourcePathOriginal.toArray(new FileObject[0]));
            if (additionalSourceRoots == null) {
                additionalSourceRoots = new HashSet<String>();
            }
            additionalSourceRoots.addAll(newOriginalRoots);
        }
        // Then correct the smart-stepping path
        Set<String> newSteppingRoots = new HashSet<String>(newRoots);
        for (FileObject fo : sourcePath) {
            newSteppingRoots.remove(getRoot(fo));
        }
        Set<FileObject> removedSteppingRoots = new HashSet<FileObject>();
        Set<FileObject> removedOriginalRoots = new HashSet<FileObject>();
        for (FileObject fo : sourcePath) {
            String spr = getRoot(fo);
            if (!newRoots.contains(spr)) {
                removedSteppingRoots.add(fo);
                if (additionalSourceRoots != null && additionalSourceRoots.contains(spr)) {
                    removedOriginalRoots.add(fo);
                    additionalSourceRoots.remove(spr);
                    if (additionalSourceRoots.size() == 0) {
                        additionalSourceRoots = null;
                    }
                }
            }
        }
        if (removedOriginalRoots.size() > 0) {
            sourcePathOriginal.removeAll(removedOriginalRoots);
            originalSourcePath = ClassPathSupport.createClassPath(sourcePathOriginal.toArray(new FileObject[0]));
        }
        if (newSteppingRoots.size() > 0 || removedSteppingRoots.size() > 0) {
            for (String root : newSteppingRoots) {
                FileObject fo = getFileObject(root);
                if (fo != null) {
                    sourcePath.add(fo);
                }
            }
            sourcePath.removeAll(removedSteppingRoots);
            oldCP = smartSteppingSourcePath;
            smartSteppingSourcePath = ClassPathSupport.createClassPath(sourcePath.toArray(new FileObject[0]));
            newCP = smartSteppingSourcePath;
        }
    }
    if (oldCP != null) {
        pcs.firePropertyChange(PROP_SOURCE_ROOTS, oldCP, newCP);
    }
}
Also used : ClassPath(org.netbeans.api.java.classpath.ClassPath) FileObject(org.openide.filesystems.FileObject) HashSet(java.util.HashSet)

Example 42 with FileObject

use of org.openide.filesystems.FileObject in project enclojure by EricThorsen.

the class ClojureSourcesHelper method getClojureSources.

public static List<FileObject> getClojureSources(Project project) {
    List<FileObject> result = new ArrayList<FileObject>();
    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] groups = sources.getSourceGroups(Sources.TYPE_GENERIC);
    for (SourceGroup group : groups) {
        FileObject root = group.getRootFolder();
        Enumeration<? extends FileObject> files = root.getData(true);
        while (files.hasMoreElements()) {
            FileObject fobj = files.nextElement();
            if (fobj.getExt().equals(CLOJURE_EXT)) {
                result.add(fobj);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) FileObject(org.openide.filesystems.FileObject) Sources(org.netbeans.api.project.Sources) SourceGroup(org.netbeans.api.project.SourceGroup)

Example 43 with FileObject

use of org.openide.filesystems.FileObject in project Universal-G-Code-Sender by winder.

the class ActionRegistrationService method overrideActionName.

/**
 * Set the display name of an action for a given category.
 *
 * @param category which category the key is in.
 * @param key      identifier for the action.
 * @param name     display name to set.
 */
public void overrideActionName(String category, String key, String name) {
    try {
        FileObject root = FileUtil.getConfigRoot();
        FileObject in = FileUtil.createFolder(root, "Actions/" + category);
        FileObject obj = in.getFileObject(key.replaceAll("\\.", "-"), "instance");
        if (obj != null) {
            obj.setAttribute("displayName", name);
        }
        in.refresh();
        invalidateCache();
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
Also used : FileObject(org.openide.filesystems.FileObject) IOException(java.io.IOException)

Example 44 with FileObject

use of org.openide.filesystems.FileObject in project Universal-G-Code-Sender by winder.

the class NewDesignAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    try {
        FileChooserBuilder fcb = new FileChooserBuilder(OpenAction.class);
        fcb.setFileFilter(OpenAction.DESIGN_FILE_FILTER);
        JFileChooser fileChooser = fcb.createFileChooser();
        fileChooser.setFileHidingEnabled(true);
        if (fileChooser.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
            File file = new File(StringUtils.appendIfMissing(fileChooser.getSelectedFile().getAbsolutePath(), ".ugsd"));
            FileObject dir = FileUtil.toFileObject(fileChooser.getSelectedFile().getParentFile());
            // Removing the old file
            if (file.exists()) {
                if (JOptionPane.showConfirmDialog(SwingUtilities.getRoot((Component) e.getSource()), "Are you sure you want to overwrite the file " + file.getName(), "Overwrite existing file", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) {
                    file.delete();
                } else {
                    return;
                }
            }
            FileObject fileObject = dir.createData(file.getName());
            DataObject.find(fileObject).getLookup().lookup(OpenCookie.class).open();
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}
Also used : FileObject(org.openide.filesystems.FileObject) IOException(java.io.IOException) FileChooserBuilder(org.openide.filesystems.FileChooserBuilder) File(java.io.File) OpenCookie(org.openide.cookies.OpenCookie)

Example 45 with FileObject

use of org.openide.filesystems.FileObject in project gephi by gephi.

the class DesktopImportControllerUI method importFile.

@Override
public void importFile(FileObject fileObject) {
    try {
        final FileImporter importer = controller.getFileImporter(FileUtil.toFile(fileObject));
        if (importer == null) {
            NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(getClass(), "DesktopImportControllerUI.error_no_matching_file_importer"), NotifyDescriptor.WARNING_MESSAGE);
            DialogDisplayer.getDefault().notify(msg);
            return;
        }
        //MRU
        MostRecentFiles mostRecentFiles = Lookup.getDefault().lookup(MostRecentFiles.class);
        mostRecentFiles.addFile(fileObject.getPath());
        ImporterUI ui = controller.getUI(importer);
        if (ui != null) {
            String title = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.file.ui.dialog.title", ui.getDisplayName());
            JPanel panel = ui.getPanel();
            FileImporter[] fi = (FileImporter[]) Array.newInstance(importer.getClass(), 1);
            fi[0] = importer;
            ui.setup(fi);
            final DialogDescriptor dd = new DialogDescriptor(panel, title);
            if (panel instanceof ValidationPanel) {
                ValidationPanel vp = (ValidationPanel) panel;
                vp.addChangeListener(new ChangeListener() {

                    @Override
                    public void stateChanged(ChangeEvent e) {
                        dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
                    }
                });
            }
            Object result = DialogDisplayer.getDefault().notify(dd);
            if (!result.equals(NotifyDescriptor.OK_OPTION)) {
                ui.unsetup(false);
                return;
            }
            ui.unsetup(true);
        }
        LongTask task = null;
        if (importer instanceof LongTask) {
            task = (LongTask) importer;
        }
        //Execute task
        fileObject = getArchivedFile(fileObject);
        final String containerSource = fileObject.getNameExt();
        final InputStream stream = fileObject.getInputStream();
        String taskName = NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
        executor.execute(task, new Runnable() {

            @Override
            public void run() {
                try {
                    Container container = controller.importFile(stream, importer);
                    if (container != null) {
                        container.setSource(containerSource);
                        finishImport(container);
                    }
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        }, taskName, errorHandler);
    } catch (Exception ex) {
        Logger.getLogger("").log(Level.WARNING, "", ex);
    }
}
Also used : ImporterUI(org.gephi.io.importer.spi.ImporterUI) MostRecentFiles(org.gephi.desktop.mrufiles.api.MostRecentFiles) JPanel(javax.swing.JPanel) GZIPInputStream(java.util.zip.GZIPInputStream) BZip2CompressorInputStream(org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileImporter(org.gephi.io.importer.spi.FileImporter) ValidationPanel(org.netbeans.validation.api.ui.ValidationPanel) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) NotifyDescriptor(org.openide.NotifyDescriptor) Container(org.gephi.io.importer.api.Container) ChangeEvent(javax.swing.event.ChangeEvent) LongTask(org.gephi.utils.longtask.spi.LongTask) DialogDescriptor(org.openide.DialogDescriptor) ChangeListener(javax.swing.event.ChangeListener) FileObject(org.openide.filesystems.FileObject)

Aggregations

FileObject (org.openide.filesystems.FileObject)86 File (java.io.File)28 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)11 DataObject (org.openide.loaders.DataObject)8 NotifyDescriptor (org.openide.NotifyDescriptor)7 Project (org.netbeans.api.project.Project)6 ActionEvent (java.awt.event.ActionEvent)5 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 PropertyChangeListener (java.beans.PropertyChangeListener)5 InputStream (java.io.InputStream)5 JFileChooser (javax.swing.JFileChooser)5 JPanel (javax.swing.JPanel)5 ImportControllerUI (org.gephi.desktop.importer.api.ImportControllerUI)5 DialogFileFilter (org.gephi.ui.utils.DialogFileFilter)5 DialogDescriptor (org.openide.DialogDescriptor)5 ActionListener (java.awt.event.ActionListener)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)4 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)4 OpenCookie (org.openide.cookies.OpenCookie)4