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

The following examples show how to use org.openide.filesystems.FileChooserBuilder#createFileChooser() . 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: BuildContextVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void buildContextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buildContextButtonActionPerformed
    FileChooserBuilder builder = FileChooserBuilder.create(fileSystem);
    JFileChooser fileChooser = builder.createFileChooser();
    fileChooser.setApproveButtonText(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.button")); // NOI18M
    fileChooser.setDialogTitle(NbBundle.getMessage(BuildContextVisual.class, "BuildContextVisual.fileChooser.dialogTitle")); // NOI18M
    fileChooser.setFileSelectionMode(0);
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    String buildText = UiUtils.getValue(buildContextTextField);
    if (buildText != null) {
        fileChooser.setSelectedFile(new File(buildText));

    }
    if (fileChooser.showOpenDialog(SwingUtilities.getWindowAncestor(this)) == JFileChooser.APPROVE_OPTION) {
        buildContextTextField.setText(fileChooser.getSelectedFile().getAbsolutePath());
    }
}
 
Example 2
Source File: OpenFileAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and initializes a file chooser.
 *
 * @return  the initialized file chooser
 */
protected JFileChooser prepareFileChooser() {
    FileChooserBuilder fcb = new FileChooserBuilder(OpenFileAction.class);
    fcb.setSelectionApprover(new OpenFileSelectionApprover());
    fcb.setFilesOnly(true);
    fcb.addDefaultFileFilters();
    for (OpenFileDialogFilter filter :
            Lookup.getDefault().lookupAll(OpenFileDialogFilter.class)) {
        fcb.addFileFilter(filter);
    }
    JFileChooser chooser = fcb.createFileChooser();
    chooser.setMultiSelectionEnabled(true);
    chooser.getCurrentDirectory().listFiles(); //preload
    chooser.setCurrentDirectory(getCurrentDirectory());
    if (currentFileFilter != null) {
        for (FileFilter ff : chooser.getChoosableFileFilters()) {
            if (currentFileFilter.equals(ff.getDescription())) {
                chooser.setFileFilter(ff);
                break;
            }
        }
    }
    HelpCtx.setHelpIDString(chooser, getHelpCtx().getHelpID());
    return chooser;
}
 
Example 3
Source File: IconChooser.java    From constellation with Apache License 2.0 5 votes vote down vote up
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
    // Save an icon from the icon list.
    final String iconName = getSelectedIconName();
    if (iconName != null) {
        final FileChooserBuilder fChooser = new FileChooserBuilder(IconChooser.class)
                .setTitle("Save icon");
//        final File file = fChooser.showSaveDialog();

        // We need to get a JFileChooser because FileChooserBuilder doesn't have setSelectedFile().
        final JFileChooser chooser = fChooser.createFileChooser();

        chooser.setSelectedFile(new File(iconName + ".png"));
        final int result = chooser.showSaveDialog(this);
        final File file = result == JFileChooser.APPROVE_OPTION ? chooser.getSelectedFile() : null;

        if (file != null) {
            try {
                final IconListModel listModel = (IconListModel) iconsList.getModel();
                final int index = iconsList.getSelectedIndex();
                final IconListElement element = listModel.getElementAt(index);

                try (final FileOutputStream fos = new FileOutputStream(file)) {
                    fos.write(element.iconValue.buildByteArray());
                    fos.flush();
                }
            } catch (IOException ex) {
                final NotifyDescriptor nd = new NotifyDescriptor.Message(String.format("Error writing icon file %s:%n%s", file.toString(), ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE);
                nd.setTitle("Icon file error");
                DialogDisplayer.getDefault().notify(nd);
            }
        }
    }
}
 
Example 4
Source File: SaveAsAction.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void performAction(Node[] activatedNodes) {
    Node node = activatedNodes[0];
    FileObject fo = node.getLookup().lookup(FileObject.class);
    if (fo != null) {
        FileChooserBuilder builder = new FileChooserBuilder(SaveAsAction.class);
        builder.setDirectoriesOnly(false);
        builder.setApproveText("Save");
        builder.setControlButtonsAreShown(true);
        builder.setTitle("Save As...");
        builder.setFilesOnly(true);
        builder.setFileFilter(new FileNameExtensionFilter(fo.getExt(), fo.getExt()));
        JFileChooser chooser = builder.createFileChooser();
        chooser.setSelectedFile(new File(fo.getNameExt()));
        int resp = chooser.showSaveDialog(findDialogParent());
        if (JFileChooser.APPROVE_OPTION == resp) {
            File saveFile = chooser.getSelectedFile();
            if (saveFile != null) {
                try {
                    saveFile.getParentFile().mkdirs();
                    FileObject dfo = FileUtil.toFileObject(saveFile.getParentFile());
                    if (dfo == null) {
                        NotifyDescriptor nd = new NotifyDescriptor.Message("Unable to Save file!", NotifyDescriptor.ERROR_MESSAGE);
                        DialogDisplayer.getDefault().notifyLater(nd);
                        return;
                    }
                    if (saveFile.exists()) {
                        saveFile.delete();
                    }
                    fo.copy(dfo, saveFile.getName(), "");
                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
}