Java Code Examples for org.openide.filesystems.FileChooserBuilder#showMultiOpenDialog()

The following examples show how to use org.openide.filesystems.FileChooserBuilder#showMultiOpenDialog() . 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: SearchScopeBrowse.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Open file chooser to choose search roots.
 */
private FileObject[] chooseRoots() {
    FileChooserBuilder chooserBuilder =
            new FileChooserBuilder(SearchScopeBrowse.class);
    chooserBuilder.setTitle(UiUtils.getText(
            "LBL_ScopeBrowseFileChooserTitle"));                    //NOI18N
    chooserBuilder.setApproveText(UiUtils.getText(
            "LBL_ScopeBrowseFileChooserApprove"));                  //NOI18N
    File[] files = chooserBuilder.showMultiOpenDialog();
    if (files == null) {
        files = new File[0];
    }
    List<File> existingFiles = selectExistingFiles(files);
    FileObject[] fileObjects = new FileObject[existingFiles.size()];
    for (int i = 0; i < existingFiles.size(); i++) {
        fileObjects[i] = FileUtil.toFileObject(existingFiles.get(i));
    }
    if (fileObjects.length > 0) {
        roots = fileObjects;
    }
    return fileObjects;
}
 
Example 2
Source File: PathUiSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void addFolders() {
    FileChooserBuilder builder = new FileChooserBuilder(directoryHandler.getDirKey())
            .setDirectoriesOnly(true)
            .setTitle(NbBundle.getMessage(PathUiSupport.class, "LBL_AddFolders_DialogTitle"));
    File currentDirectory = directoryHandler.getCurrentDirectory();
    if (currentDirectory != null) {
        builder.forceUseOfDefaultWorkingDirectory(true)
                .setDefaultWorkingDirectory(currentDirectory);
    }
    File[] selectedFiles = builder.showMultiOpenDialog();
    if (selectedFiles != null
            && selectedFiles.length > 0) {
        String[] paths = new String[selectedFiles.length];
        for (int i = 0; i < selectedFiles.length; i++) {
            paths[i] = selectedFiles[i].getAbsolutePath();
        }
        int[] newSelection = PathUiSupport.addFolders(listModel, list.getSelectedIndices(), paths);
        list.setSelectedIndices(newSelection);
    }
}
 
Example 3
Source File: SourceRootsUi.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Handles button events
 */        
public void actionPerformed( ActionEvent e ) {
    
    Object source = e.getSource();
    
    if ( source == addFolderButton ) { 
        
        // Let user search for the Jar file
        FileChooserBuilder builder = new FileChooserBuilder(SourceRootsUi.class).setDirectoriesOnly(true);
        builder.setDefaultWorkingDirectory(FileUtil.toFile(this.project.getProjectDirectory()));
        String type = RootsAccessor.getInstance().getType(sourceRoots);
        boolean isModule = JavaProjectConstants.SOURCES_TYPE_MODULES.equals(type);
        if (sourceRoots.isTest()) {
            builder.setTitle(NbBundle.getMessage(SourceRootsUi.class, isModule ? "LBL_TestModuleFolder_DialogTitle" : "LBL_TestFolder_DialogTitle"));  // NOI18N
        } else {
            builder.setTitle(NbBundle.getMessage(SourceRootsUi.class, isModule ? "LBL_ModuleFolder_DialogTitle" : "LBL_SourceFolder_DialogTitle")); // NOI18N
        }
        File files[] = builder.showMultiOpenDialog();
        if ( files != null ) {
            addFolders( files );
        }
    }
    else if ( source == removeButton ) { 
        removeElements();
    }
    else if ( source == upButton ) {
        moveUp();
    }
    else if ( source == downButton ) {
        moveDown();
    }
}
 
Example 4
Source File: CreateAvdVisualPanel1.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void importProfileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importProfileButtonActionPerformed
    // TODO add your handling code here:
    FileChooserBuilder builder = new FileChooserBuilder("android-devices");
    builder.setFilesOnly(true);
    builder.setFileFilter(new FileNameExtensionFilter("Android devide definition", "xml", "XML"));
    File[] files = builder.showMultiOpenDialog();
    if (files != null) {
        for (File file : files) {
            try {
                Table<String, String, Device> devices = DeviceParser.parse(file);
                Map<String, Map<String, Device>> rowMap = devices.rowMap();
                rowMap.values().stream().forEach((t) -> {
                    t.values().stream().forEach((d) -> {
                        Device device = AvdHwProfile.showDeviceProfiler(d, deviceManager, false);
                        if (device != null) {
                            deviceManager.addUserDevice(d);
                        }
                    });
                });
            } catch (Exception ex) {
                NotifyDescriptor nd = new NotifyDescriptor.Message("Error while parsing Android device definition!", NotifyDescriptor.ERROR_MESSAGE);
                DialogDisplayer.getDefault().notifyLater(nd);
            }
        }
        deviceManager.saveUserDevices();
        refreshDevices();
    }
}
 
Example 5
Source File: AndroidPlatformCustomizer.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void addJavadocActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addJavadocActionPerformed
    FileChooserBuilder builder = new FileChooserBuilder(AndroidPlatformCustomizer.class);
    builder.setAcceptAllFileFilterUsed(false);
    builder.setFileFilter(new ArchiveFileFilter("javadoc files", new String[]{"JAR", "ZIP"}));
    builder.setTitle("Select Javadocs to add");
    File[] files = builder.showMultiOpenDialog();
    if (files != null) {
        for (File file : files) {
            aPackage.addJavadocPath(FileUtil.toFileObject(file).toURL(), true);
        }
        sdk.store();
        fireJavadocAdded();
    }
}
 
Example 6
Source File: AndroidPlatformCustomizer.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void addClasspathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addClasspathActionPerformed
    FileChooserBuilder builder = new FileChooserBuilder(AndroidPlatformCustomizer.class);
    builder.setAcceptAllFileFilterUsed(false);
    builder.setFileFilter(new ArchiveFileFilter("Jar files", new String[]{"JAR"}));
    builder.setTitle("Select ClassPath to add");
    File[] files = builder.showMultiOpenDialog();
    if (files != null) {
        for (File file : files) {
            aPackage.addBootPath(FileUtil.toFileObject(file).toURL(), true);
        }
        sdk.store();
        fireClassPathAdded();
    }
}
 
Example 7
Source File: AndroidPlatformCustomizer.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void addSourcesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addSourcesActionPerformed
    FileChooserBuilder builder = new FileChooserBuilder(AndroidPlatformCustomizer.class);
    builder.setAcceptAllFileFilterUsed(false);
    builder.setFileFilter(new ArchiveFileFilter("src files", new String[]{"JAR", "ZIP"}));
    builder.setTitle("Select Sources to add");
    File[] files = builder.showMultiOpenDialog();
    if (files != null) {
        for (File file : files) {
            aPackage.addSrcPath(FileUtil.toFileObject(file).toURL(), true);
        }
        sdk.store();
        fireSourcesAdded();
    }
}
 
Example 8
Source File: ImportVisualPanel2.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void selectFile() {
    FileChooserBuilder builder = new FileChooserBuilder(this.getClass());
    builder.setFilesOnly(true);
    builder.setTitle("Select Asset File");
    File[] file = builder.showMultiOpenDialog();
    if (file != null) {
        for (int i = 0; i < file.length; i++) {
            File file1 = file[i];
            FileDescription description = AssetPackLoader.getFileDescription(file1);
            description.setPath(pathString());
            list.add(description);
        }
        updateList();
    }
}
 
Example 9
Source File: AddDriverDialog.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
    stopProgress();

    FileChooserBuilder fileChooserBuilder = new FileChooserBuilder(AddDriverDialog.class);
    fileChooserBuilder.setTitle(NbBundle.getMessage(AddDriverDialog.class, "AddDriver_Chooser_Title")); //NOI18N
    //.jar and .zip file filter
    fileChooserBuilder.setFileFilter(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return (f.isDirectory() || f.getName().endsWith(".jar") || f.getName().endsWith(".zip")); //NOI18N
        }

        @Override
        public String getDescription() {
            return NbBundle.getMessage(AddDriverDialog.class, "AddDriver_Chooser_Filter"); //NOI18N
        }
    });

    File[] selectedFiles = fileChooserBuilder.showMultiOpenDialog();
    if (selectedFiles != null) {
        for (final File file : selectedFiles) {
            if (file.isFile()) {
                if (dlm.contains(file.toString())) {
                    // file already added
                    NotifyDescriptor msgDesc = new NotifyDescriptor.Message(NbBundle.getMessage(AddDriverDialog.class, "AddDriverDuplicateFile", file.toString()));
                    DialogDisplayer.getDefault().notify(msgDesc);
                    continue;
                }
                if (drvs.isEmpty()) {
                    dlm.clear();
                }
                dlm.addElement(file.toString());
                try {
                    drvs.add(file.toURI().toURL());
                } catch (MalformedURLException exc) {
                    LOGGER.log(Level.WARNING,
                            "Unable to add driver jar file " +
                            file.getAbsolutePath() +
                            ": can not convert to URL", exc);
                }
                if (wd != null) {
                    boolean privileged = wd.getAllPrivilegedNames().isEmpty();
                    for (String name : wd.getAllPrivilegedNames()) {
                        if (file.getName().startsWith(name)) {
                            privileged = true;
                            break;
                        }
                    }
                    if (privileged) {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                notifyUser(null, false);
                            }
                        });
                    } else {
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                notifyUser(NbBundle.getMessage(AddDriverDialog.class, "AddDriverDialog_NotPrivilegedDriver", // NOI18N
                                        file.getName(), wd.getPrivilegedName()), true);
                            }
                        });
                    }
                }
            }
        }
        findDriverClass();
        if (wp != null) {
            wp.fireChangeEvent();
        }
    }
    updateState();
}