Example usage for javax.swing JFileChooser DIRECTORIES_ONLY

List of usage examples for javax.swing JFileChooser DIRECTORIES_ONLY

Introduction

In this page you can find the example usage for javax.swing JFileChooser DIRECTORIES_ONLY.

Prototype

int DIRECTORIES_ONLY

To view the source code for javax.swing JFileChooser DIRECTORIES_ONLY.

Click Source Link

Document

Instruction to display only directories.

Usage

From source file:org.eclim.installer.step.EclipseStep.java

/**
 * {@inheritDoc}//from w  w w  .  ja v  a  2s . c  o  m
 * @see org.formic.wizard.step.GuiStep#init()
 */
public Component init() {
    final JPanel panel = new JPanel(new MigLayout("wrap 2, fillx", "[growprio 0] [fill]"));
    GuiForm form = createForm();

    String home = fieldName("home");

    eclipseHomeChooser = new FileChooser(JFileChooser.DIRECTORIES_ONLY);

    panel.add(form.createMessagePanel(), "span");
    panel.add(new JLabel(Installer.getString(home)));
    panel.add(eclipseHomeChooser);

    form.bind(home, eclipseHomeChooser.getTextField(),
            new ValidatorBuilder().required().isDirectory().validator(new EclipseHomeValidator()).validator());

    String eclipseHomeDefault = getDefaultEclipseHome();
    eclipseHomeChooser.getTextField().setText(eclipseHomeDefault);

    return panel;
}

From source file:org.eclim.installer.step.VimStep.java

/**
 * {@inheritDoc}/*  w  w  w . j  av  a2 s. co  m*/
 * @see org.formic.wizard.step.GuiStep#init()
 */
public Component init() {
    GuiForm form = createForm();

    String files = fieldName("files");
    fileChooser = new FileChooser(JFileChooser.DIRECTORIES_ONLY);

    // allow just .vim dirs to not be hidden
    fileChooser.getFileChooser().setFileHidingEnabled(false);
    fileChooser.getFileChooser().addChoosableFileFilter(new FileFilter() {
        public boolean accept(java.io.File f) {
            String path = f.getAbsolutePath();
            return f.isDirectory() && (path.matches(".*/\\.vim(/.*|$)") || !path.matches(".*/\\..*"));
        }

        public String getDescription() {
            return null;
        }
    });

    String skip = fieldName("skip");
    skipCheckBox = new JCheckBox(Installer.getString(skip));
    skipCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            boolean selected = ((JCheckBox) e.getSource()).isSelected();
            JTextField fileField = fileChooser.getTextField();
            fileField.setEnabled(!selected);
            fileChooser.getButton().setEnabled(!selected);

            if (dirList != null) {
                dirList.setEnabled(!selected);
            }

            // hacky
            Validator validator = (Validator) fileField.getClientProperty("validator");
            setValid(selected || validator.isValid(fileField.getText()));
        }
    });

    panel = new JPanel(new MigLayout("wrap 2", "[fill]", "[] [] [] [fill, grow]"));
    panel.add(form.createMessagePanel(), "span");
    panel.add(new JLabel(Installer.getString(files)), "split");
    panel.add(fileChooser, "skip");
    panel.add(skipCheckBox, "span");

    form.bind(files, fileChooser.getTextField(),
            new ValidatorBuilder().required().isDirectory().fileExists().isWritable().validator());

    return panel;
}

From source file:org.esa.snap.smart.configurator.ui.PerformancePanel.java

private void browseCachePathButtonActionPerformed() {
    JFileChooser fileChooser = new JFileChooser(cachePathTextField.getText());
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int returnValue = fileChooser.showOpenDialog(this);
    if (returnValue == JFileChooser.APPROVE_OPTION) {
        File selectedDir = fileChooser.getSelectedFile();
        cachePathTextField.setText(selectedDir.getAbsolutePath());
        cachePathTextField.setForeground(CURRENT_VALUES_COLOR);
        controller.changed();//from  ww  w  . j  a  v a 2  s.c om
    }
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java

/**
 * Downloads the objects currently selected in the objects table. The user is
 * prompted// w w  w.j av  a2s  .  com
 * Prepares to perform a download of objects from S3 by prompting the user for a directory
 * to store the files in, then performing the download.
 *
 * @throws IOException
 */
private void downloadSelectedObjects() {
    // Prompt user to choose directory location for downloaded files (or cancel download altogether)
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setDialogTitle("Choose directory to save S3 files in");
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setMultiSelectionEnabled(false);
    fileChooser.setSelectedFile(downloadDirectory);

    int returnVal = fileChooser.showDialog(ownerFrame, "Choose Directory");
    if (returnVal != JFileChooser.APPROVE_OPTION) {
        return;
    }

    downloadDirectory = fileChooser.getSelectedFile();

    // Find clashing files
    final Map filesAlreadyInDownloadDirectoryMap = new HashMap();
    S3Object[] objectsForDownload = getSelectedObjects();
    for (int i = 0; i < objectsForDownload.length; i++) {
        File file = new File(downloadDirectory, objectsForDownload[i].getKey());
        if (file.exists()) {
            filesAlreadyInDownloadDirectoryMap.put(objectsForDownload[i].getKey(), file);
        }
    }

    // Build map of S3 Objects being downloaded.
    final Map s3DownloadObjectsMap = FileComparer.getInstance().populateS3ObjectMap("", objectsForDownload);

    final HyperlinkActivatedListener hyperlinkListener = this;

    runInBackgroundThread(new Runnable() {
        public void run() {
            // Retrieve details of objects for download
            if (!retrieveObjectsDetails(getSelectedObjects())) {
                return;
            }

            try {
                final FileComparerResults comparisonResults = compareRemoteAndLocalFiles(
                        filesAlreadyInDownloadDirectoryMap, s3DownloadObjectsMap);

                DownloadPackage[] downloadPackages = buildDownloadPackageList(comparisonResults,
                        s3DownloadObjectsMap);
                if (downloadPackages == null) {
                    return;
                }

                s3ServiceMulti.downloadObjects(currentSelectedBucket, downloadPackages);

            } catch (final Exception e) {
                runInDispatcherThreadImmediately(new Runnable() {
                    public void run() {
                        String message = "Unable to download objects";
                        log.error(message, e);
                        ErrorDialog.showDialog(ownerFrame, hyperlinkListener, message, e);
                    }
                });
            }
        }
    });
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.gui.LoginLocalFolderPanel.java

private void chooseFolder() {
    // Prompt user to choose their Cockpit home directory.
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setAcceptAllFileFilterUsed(true);
    fileChooser.setDialogTitle("Choose Cockpit Home Folder");
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setApproveButtonText("Choose Folder");
    fileChooser.setCurrentDirectory(cockpitHomeFolder);

    int returnVal = fileChooser.showOpenDialog(ownerFrame);
    if (returnVal != JFileChooser.APPROVE_OPTION) {
        return;/* w  w  w.  j  a v  a2s.  c  o  m*/
    } else {
        this.cockpitHomeFolder = fileChooser.getSelectedFile();
        this.folderPathTextField.setText(this.cockpitHomeFolder.getAbsolutePath());
        refreshStoredCredentialsTable();
    }
}

From source file:org.gcaldaemon.gui.ConfigEditor.java

public final String selectDir(String title, String path) {
    JFileChooser fd = new JFileChooser(path);
    fd.setDialogTitle(title);/*from   w ww . j a va  2s.  c  om*/
    fd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int state = fd.showOpenDialog(this);
    if (state != JFileChooser.APPROVE_OPTION) {
        return null;
    }
    String dir = fd.getSelectedFile().getAbsolutePath();
    return dir.replace('\\', '/');
}

From source file:org.isatools.gui.datamanager.exportisa.ExportISAGUI.java

private JFileChooser createFileChooser() {
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setDialogTitle("Select directory to output to");
    fileChooser.setApproveButtonText("Output here");

    return fileChooser;
}

From source file:org.isatools.isacreator.spreadsheet.SpreadsheetFunctions.java

protected void resolveFileLocations() {
    int[] selectedRows = spreadsheet.getTable().getSelectedRows();
    int selectedColumn = spreadsheet.getTable().getSelectedColumn();

    JFileChooser fileLocChooser = new JFileChooser();
    fileLocChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    fileLocChooser.setDialogTitle("Select directory to search through");
    fileLocChooser.setApproveButtonText("Select directory");

    if (fileLocChooser.showOpenDialog(spreadsheet) == JFileChooser.APPROVE_OPTION) {
        File dir = fileLocChooser.getSelectedFile();

        String[] files = new String[selectedRows.length];

        for (int row = 0; row < selectedRows.length; row++) {
            files[row] = spreadsheet.getTable().getValueAt(selectedRows[row], selectedColumn).toString();
        }//from   ww  w  .j  av  a 2  s.  co  m

        FileLocationMapperUtil fmu = new FileLocationMapperUtil();
        Map<String, String> result = fmu.findProperFileLocations(files, dir);

        for (int selectedRow : selectedRows) {
            String candidateVal = spreadsheet.getTable().getValueAt(selectedRow, selectedColumn).toString();
            if (result.keySet().contains(candidateVal)) {
                spreadsheet.getTable().setValueAt(result.get(candidateVal), selectedRow, selectedColumn);
            }
        }
    }

    // otherwise, do nothing
}

From source file:org.isatools.isacreatorconfigurator.configui.MenuPanel.java

/**
 * Loads a session to allow for editing/*  w w  w  .  j a  v a 2  s. com*/
 *
 * @throws java.io.IOException    - When file not found
 * @throws ClassNotFoundException - When object being read in from input stream doesn't read in properly
 */
private boolean loadSession() throws IOException, ClassNotFoundException, XmlException {
    jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    jfc.setFileFilter(new ConfigurationFileFilter());
    jfc.setDialogTitle("Select configuration file directory");
    jfc.setApproveButtonText("load configuration");
    jfc.showOpenDialog(this);

    if (jfc.getSelectedFile() != null) {

        status.setIcon(CONFIG_LOAD);

        toLoad = jfc.getSelectedFile();

        if (toLoad != null && checkDirectoryContentIsOk(toLoad)) {
            DataEntryPanel dep = new DataEntryPanel(appCont, toLoad);

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    status.setForeground(UIHelper.DARK_GREEN_COLOR);
                    status.setText("<html>attempting to load <i>" + toLoad.getName() + "</i></html>");
                    status.setText("<html>processing files...</html>");
                }
            });

            // we want to attempt to parse the XML since this directory should contain XML describing configurations
            if (toLoad.isDirectory()) {

                ConfigXMLParser parser = new ConfigXMLParser(ConfigurationLoadingSource.ISACONFIGURATOR,
                        toLoad.getAbsolutePath());
                parser.loadConfiguration();
                Configuration c = new Configuration(parser.getMappings());
                for (TableReferenceObject tc : parser.getTables()) {
                    c.addTableObject(tc.getTableFields());
                }

                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        status.setText("<html>connecting to ontology resources...</html>");
                    }
                });

                loadTFO(c, dep);

            }
            // otherwise, this is a legacy TFO or TCO file.
            else {

                ObjectInputStream ois = new ObjectInputStream(new FileInputStream(toLoad));

                if (ConfigurationFileFilter.getExtension(toLoad).equalsIgnoreCase("tfo")) {
                    Configuration c = (Configuration) ois.readObject();
                    ois.close();
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            status.setText("<html>connecting to ontology resources...</html>");
                        }
                    });
                    loadTFO(c, dep);
                } else {
                    log.info("This format is not supported...");
                    showErrorInStatus("<html>This file format is not supported...</html>");

                }
            }

            dep.createGUI();
            status.setText("");
            status.setIcon(null);
            appCont.hideGlassPane();
            appCont.setCurrentPage(dep);
            return true;

        } else {
            showErrorInStatus(
                    "<html>Invalid selection made. Please choose a valid ISA configuration directory...</html>");
        }
    }
    showErrorInStatus(
            "<html>Invalid selection made. Please choose a valid ISA configuration directory...</html>");

    return false;
}

From source file:org.javaswift.cloudie.CloudiePanel.java

protected void onDownloadStoredObject() {
    Container container = getSelectedContainer();
    List<StoredObject> obj = getSelectedStoredObjects();
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(lastFolder);
    if (obj.size() == 1) {
        chooser.setSelectedFile(new File(obj.get(0).getName()));
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    } else {//from w  ww  .  ja va 2 s .  c om
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    }
    if (chooser.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File selected = chooser.getSelectedFile();
        for (StoredObject so : obj) {
            File target = selected;
            if (target.isDirectory()) {
                target = new File(selected, so.getName());
            }
            if (target.exists()) {
                if (confirm("File '" + target.getName() + "' already exists. Overwrite?")) {
                    doSaveStoredObject(target, container, so);
                }
            } else {
                doSaveStoredObject(target, container, so);
            }
        }
        lastFolder = selected.isFile() ? selected.getParentFile() : selected;
    }

}