Skip to content

Commit 1169a25

Browse files
committed
Simplifing EOModel chooser for portability
1 parent e4526c5 commit 1169a25

1 file changed

Lines changed: 10 additions & 51 deletions

File tree

modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ui/action/ImportEOModelAction.java

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ public ImportEOModelAction(Application application) {
112112
adaptersByDriver.put("org.firebirdsql.jdbc.FBDriver", FirebirdAdapter.class.getName());
113113
}
114114

115+
@Override
115116
public String getIconName() {
116117
return "icon-eomodel.png";
117118
}
118119

120+
@Override
119121
public void performAction(ActionEvent event) {
120122
importEOModel();
121123
}
@@ -129,10 +131,7 @@ protected void importEOModel() {
129131

130132
if (status == JFileChooser.APPROVE_OPTION) {
131133

132-
File file = fileChooser.getSelectedFile();
133-
if (file.isFile()) {
134-
file = file.getParentFile();
135-
}
134+
File file = fileChooser.getSelectedFile().getParentFile();
136135

137136
DataMap currentMap = getProjectSession().getSelectedDataMap();
138137

@@ -331,22 +330,18 @@ public JFileChooser getEOModelChooser() {
331330
}
332331

333332
/**
334-
* Custom file chooser that will pop up again if a bad directory is selected.
333+
* Custom file chooser that will pop up again if an invalid file is selected.
335334
*/
336335
static class EOModelChooser extends JFileChooser {
337336

338-
static final FileFilter eomodelFilter = new EOModelFileFilter();
339-
private static final FileFilter eomodelSelectFilter = new EOModelSelectFilter();
340-
341-
protected FileFilter selectFilter;
342-
protected JDialog cachedDialog;
337+
private static final FileFilter eomodelFilter = new EOModelFileFilter();
343338

339+
private JDialog cachedDialog;
344340

345341
public EOModelChooser(String title) {
346342
super.setFileFilter(eomodelFilter);
347343
super.setDialogTitle(title);
348-
super.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
349-
this.selectFilter = eomodelSelectFilter;
344+
super.setFileSelectionMode(JFileChooser.FILES_ONLY);
350345
}
351346

352347
public int showOpenDialog(Component parent) {
@@ -356,22 +351,16 @@ public int showOpenDialog(Component parent) {
356351
return status;
357352
}
358353

359-
// make sure invalid directory is not selected
360354
File file = this.getSelectedFile();
361-
if (selectFilter.accept(file)) {
355+
if (file.isFile() && eomodelFilter.accept(file)) {
362356
cachedDialog = null;
363357
return JFileChooser.APPROVE_OPTION;
364-
} else {
365-
if (file.isDirectory()) {
366-
this.setCurrentDirectory(file);
367-
}
368-
369-
return this.showOpenDialog(parent);
370358
}
359+
360+
return this.showOpenDialog(parent);
371361
}
372362

373363
protected JDialog createDialog(Component parent) throws HeadlessException {
374-
375364
if (cachedDialog == null) {
376365
cachedDialog = super.createDialog(parent);
377366
}
@@ -403,34 +392,4 @@ public String getDescription() {
403392
}
404393
}
405394

406-
static final class EOModelSelectFilter extends FileFilter {
407-
408-
/**
409-
* Accepts all directories and <code>*.eomodeld/index.eomodeld</code> files.
410-
*
411-
* @see EOModelSelectFilter#accept(File)
412-
*/
413-
public boolean accept(File f) {
414-
if (f.isDirectory()) {
415-
if (f.getName().endsWith(EOModelFileFilter.EOM_SUFFIX)
416-
&& new File(f, EOModelFileFilter.EOM_INDEX).exists()) {
417-
418-
return true;
419-
}
420-
} else if (f.isFile()) {
421-
File parent = f.getParentFile();
422-
if (parent != null
423-
&& parent.getName().endsWith(EOModelFileFilter.EOM_SUFFIX)
424-
&& EOModelFileFilter.EOM_INDEX.equals(f.getName())) {
425-
return true;
426-
}
427-
}
428-
429-
return false;
430-
}
431-
432-
public String getDescription() {
433-
return "*" + EOModelFileFilter.EOM_SUFFIX;
434-
}
435-
}
436395
}

0 commit comments

Comments
 (0)