Skip to content

Commit fecb834

Browse files
committedOct 9, 2018
add a directory choose, to be used in the preferences
·
v1.4.1v0.4.0
1 parent 5549f3a commit fecb834

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
 
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2018 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.utplsql.sqldev
17+
18+
import java.io.File
19+
import java.util.logging.Logger
20+
import javax.swing.JComboBox
21+
import javax.swing.JFileChooser
22+
import javax.swing.JFrame
23+
import javax.swing.JTextField
24+
25+
class DirectoryChooser {
26+
val static Logger logger = Logger.getLogger(DirectoryChooser.name)
27+
28+
def static choose (JFrame parentFrame, String title, String initialDirectory) {
29+
logger.finest('''parantFrame: «parentFrame»''')
30+
var String ret = null
31+
val chooser = new JFileChooser()
32+
chooser.currentDirectory = new File(initialDirectory)
33+
chooser.dialogTitle = title
34+
chooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
35+
chooser.acceptAllFileFilterUsed = false
36+
if (chooser.showOpenDialog(parentFrame) == JFileChooser.APPROVE_OPTION) {
37+
ret = chooser.selectedFile.absolutePath
38+
}
39+
return ret
40+
}
41+
42+
def static void choose (JFrame parentFrame, String title, JTextField textField) {
43+
val dir = choose(parentFrame, title, textField.text)
44+
if (dir !== null) {
45+
textField.text = dir
46+
}
47+
}
48+
49+
def static void choose (JFrame parentFrame, String title, JComboBox<String> comboBox) {
50+
val dir = choose(parentFrame, title, comboBox.editor.item as String);
51+
if (dir !== null) {
52+
comboBox.editor.item = dir
53+
}
54+
}
55+
56+
}

0 commit comments

Comments
 (0)
Please sign in to comment.