Search in sources :

Example 1 with FileField

use of com.revolsys.swing.field.FileField in project com.revolsys.open by revolsys.

the class FolderConnectionsTrees method addConnection.

private static void addConnection(final FolderConnectionRegistry registry) {
    final ValueField panel = new ValueField();
    panel.setTitle("Add Folder Connection");
    Borders.titled(panel, "Folder Connection");
    SwingUtil.addLabel(panel, "Name");
    final TextField nameField = new TextField(20);
    panel.add(nameField);
    SwingUtil.addLabel(panel, "Folder");
    final FileField folderField = new FileField(JFileChooser.DIRECTORIES_ONLY);
    panel.add(folderField);
    GroupLayouts.makeColumns(panel, 2, true);
    panel.showDialog();
    if (panel.isSaved()) {
        final Path file = folderField.getPath();
        if (file != null && Paths.exists(file)) {
            final String connectionName = nameField.getText();
            registry.addConnection(connectionName, file);
        }
    }
}
Also used : Path(java.nio.file.Path) TextField(com.revolsys.swing.field.TextField) FileField(com.revolsys.swing.field.FileField) ValueField(com.revolsys.swing.component.ValueField)

Example 2 with FileField

use of com.revolsys.swing.field.FileField in project com.revolsys.open by revolsys.

the class RecordStoreConnectionForm method postSetFieldValues.

@Override
protected void postSetFieldValues(final Map<String, Object> newValues) {
    String recordStoreType = (String) newValues.get("recordStoreType");
    if (Property.hasValue(recordStoreType)) {
        if (this.recordStoreTypes.contains(recordStoreType)) {
            refreshUrlFromFieldValues(recordStoreType);
        }
        return;
    }
    final String url = (String) newValues.get("url");
    if (Property.hasValue(url)) {
        for (final RecordStoreFactory recordStoreFactory : this.recordStoreFactoryByName.values()) {
            final Map<String, Object> urlFieldValues = recordStoreFactory.parseUrl(url);
            if (!urlFieldValues.isEmpty()) {
                Maps.retainIfNotEqual(urlFieldValues, newValues);
                if (recordStoreFactory instanceof FileRecordStoreFactory) {
                    final FileRecordStoreFactory fileRecordStoreFactory = (FileRecordStoreFactory) recordStoreFactory;
                    final FileField fileField = getField("file");
                    if (fileRecordStoreFactory.isDirectory()) {
                        fileField.setFileSelectionMode(JFileChooser.FILES_ONLY);
                    } else {
                        fileField.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
                    }
                }
                setFieldValues(urlFieldValues);
                return;
            }
        }
    }
    recordStoreType = getFieldValue("recordStoreType");
    refreshUrlFromFieldValues(recordStoreType);
}
Also used : FileRecordStoreFactory(com.revolsys.record.io.FileRecordStoreFactory) RecordStoreFactory(com.revolsys.record.io.RecordStoreFactory) FileRecordStoreFactory(com.revolsys.record.io.FileRecordStoreFactory) FileField(com.revolsys.swing.field.FileField)

Aggregations

FileField (com.revolsys.swing.field.FileField)2 FileRecordStoreFactory (com.revolsys.record.io.FileRecordStoreFactory)1 RecordStoreFactory (com.revolsys.record.io.RecordStoreFactory)1 ValueField (com.revolsys.swing.component.ValueField)1 TextField (com.revolsys.swing.field.TextField)1 Path (java.nio.file.Path)1