|
1 | | -/* |
| 1 | +/** |
2 | 2 | * Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com> |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | -package org.utplsql.sqldev.ui.common |
| 16 | +package org.utplsql.sqldev.ui.common; |
17 | 17 |
|
18 | | -import java.io.File |
19 | | -import java.util.logging.Logger |
20 | | -import javax.swing.JFileChooser |
21 | | -import javax.swing.JFrame |
22 | | -import javax.swing.JTextField |
23 | | - |
24 | | -class DirectoryChooser { |
25 | | - val static Logger logger = Logger.getLogger(DirectoryChooser.name) |
26 | | - |
27 | | - def static choose (JFrame parentFrame, String title, String initialDirectory) { |
28 | | - logger.finest('''parantFrame: «parentFrame»''') |
29 | | - var String ret = null |
30 | | - val chooser = new JFileChooser() |
31 | | - chooser.currentDirectory = new File(initialDirectory) |
32 | | - chooser.dialogTitle = title |
33 | | - chooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY |
34 | | - chooser.acceptAllFileFilterUsed = false |
35 | | - if (chooser.showOpenDialog(parentFrame) == JFileChooser.APPROVE_OPTION) { |
36 | | - ret = chooser.selectedFile.absolutePath |
37 | | - } |
38 | | - return ret |
39 | | - } |
40 | | - |
41 | | - def static void choose (JFrame parentFrame, String title, JTextField textField) { |
42 | | - val dir = choose(parentFrame, title, textField.text) |
43 | | - if (dir !== null) { |
44 | | - textField.text = dir |
45 | | - } |
46 | | - } |
| 18 | +import java.io.File; |
| 19 | +import java.util.logging.Logger; |
| 20 | +import javax.swing.JFileChooser; |
| 21 | +import javax.swing.JFrame; |
| 22 | +import javax.swing.JTextField; |
| 23 | +import org.eclipse.xtend2.lib.StringConcatenation; |
47 | 24 |
|
| 25 | +@SuppressWarnings("all") |
| 26 | +public class DirectoryChooser { |
| 27 | + private static final Logger logger = Logger.getLogger(DirectoryChooser.class.getName()); |
| 28 | + |
| 29 | + public static String choose(final JFrame parentFrame, final String title, final String initialDirectory) { |
| 30 | + StringConcatenation _builder = new StringConcatenation(); |
| 31 | + _builder.append("parantFrame: "); |
| 32 | + _builder.append(parentFrame); |
| 33 | + DirectoryChooser.logger.finest(_builder.toString()); |
| 34 | + String ret = null; |
| 35 | + final JFileChooser chooser = new JFileChooser(); |
| 36 | + File _file = new File(initialDirectory); |
| 37 | + chooser.setCurrentDirectory(_file); |
| 38 | + chooser.setDialogTitle(title); |
| 39 | + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
| 40 | + chooser.setAcceptAllFileFilterUsed(false); |
| 41 | + int _showOpenDialog = chooser.showOpenDialog(parentFrame); |
| 42 | + boolean _equals = (_showOpenDialog == JFileChooser.APPROVE_OPTION); |
| 43 | + if (_equals) { |
| 44 | + ret = chooser.getSelectedFile().getAbsolutePath(); |
| 45 | + } |
| 46 | + return ret; |
| 47 | + } |
| 48 | + |
| 49 | + public static void choose(final JFrame parentFrame, final String title, final JTextField textField) { |
| 50 | + final String dir = DirectoryChooser.choose(parentFrame, title, textField.getText()); |
| 51 | + if ((dir != null)) { |
| 52 | + textField.setText(dir); |
| 53 | + } |
| 54 | + } |
48 | 55 | } |
0 commit comments