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);
}
}
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;
}
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);
}
}
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();
}
}
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);
}
}
Aggregations