use of org.apache.cayenne.modeler.pref.FSPath in project cayenne by apache.
the class GeneratorController method initOutputFolder.
private void initOutputFolder() {
String path;
if (getOutputPath() == null) {
if (System.getProperty("cayenne.cgen.destdir") != null) {
setOutputPath(System.getProperty("cayenne.cgen.destdir"));
} else {
// init default directory..
FSPath lastPath = Application.getInstance().getFrameController().getLastDirectory();
path = checkDefaultMavenResourceDir(lastPath, "test");
if (path != null || (path = checkDefaultMavenResourceDir(lastPath, "main")) != null) {
setOutputPath(path);
} else {
File lastDir = (lastPath != null) ? lastPath.getExistingDirectory(false) : null;
setOutputPath(lastDir != null ? lastDir.getAbsolutePath() : null);
}
}
}
}
use of org.apache.cayenne.modeler.pref.FSPath in project cayenne by apache.
the class GeneratorController method selectOutputFolderAction.
/**
* An action method that pops up a file chooser dialog to pick the
* generation directory.
*/
public void selectOutputFolderAction() {
JTextField outputFolder = ((GeneratorControllerPanel) getView()).getOutputFolder();
String currentDir = outputFolder.getText();
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
// guess start directory
if (!Util.isEmptyString(currentDir)) {
chooser.setCurrentDirectory(new File(currentDir));
} else {
FSPath lastDir = Application.getInstance().getFrameController().getLastDirectory();
lastDir.updateChooser(chooser);
}
int result = chooser.showOpenDialog(getView());
if (result == JFileChooser.APPROVE_OPTION) {
File selected = chooser.getSelectedFile();
// update model
String path = selected.getAbsolutePath();
outputFolder.setText(path);
setOutputPath(path);
}
}
use of org.apache.cayenne.modeler.pref.FSPath in project cayenne by apache.
the class SaveAsImageAction method performAction.
@Override
public void performAction(ActionEvent e) {
// find start directory in preferences
FSPath lastDir = getApplication().getFrameController().getLastDirectory();
// configure dialog
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
lastDir.updateChooser(chooser);
chooser.setAcceptAllFileFilterUsed(false);
String ext = "png";
chooser.addChoosableFileFilter(FileFilters.getExtensionFileFilter(ext, "PNG Images"));
int status = chooser.showSaveDialog(Application.getFrame());
if (status == JFileChooser.APPROVE_OPTION) {
lastDir.updateFromChooser(chooser);
String path = chooser.getSelectedFile().getPath();
if (!path.endsWith("." + ext)) {
path += "." + ext;
}
File file = new File(path);
try {
JGraph graph = dataDomainGraphTab.getGraph();
BufferedImage img = graph.getImage(null, 0);
if (file.exists()) {
int response = JOptionPane.showConfirmDialog(null, "Do you want to replace the existing file?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (response != JOptionPane.YES_OPTION) {
return;
}
}
try (OutputStream out = new FileOutputStream(file)) {
ImageIO.write(img, ext, out);
out.flush();
}
} catch (IOException ex) {
logObj.error("Could not save image", ex);
JOptionPane.showMessageDialog(Application.getFrame(), "Could not save image.", "Error saving image", JOptionPane.ERROR_MESSAGE);
}
}
}
use of org.apache.cayenne.modeler.pref.FSPath in project cayenne by apache.
the class ImportDataMapAction method selectDataMap.
protected File selectDataMap(Frame f) {
// find start directory in preferences
FSPath lastDir = getApplication().getFrameController().getLastDirectory();
// configure dialog
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
lastDir.updateChooser(chooser);
chooser.addChoosableFileFilter(FileFilters.getDataMapFilter());
int status = chooser.showDialog(f, "Select DataMap");
if (status == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
// save to preferences...
lastDir.updateFromChooser(chooser);
return file;
}
return null;
}
use of org.apache.cayenne.modeler.pref.FSPath in project cayenne by apache.
the class ImportEOModelAction method importEOModel.
/**
* Allows user to select an EOModel, then imports it as a DataMap.
*/
protected void importEOModel() {
JFileChooser fileChooser = getEOModelChooser();
int status = fileChooser.showOpenDialog(Application.getFrame());
if (status == JFileChooser.APPROVE_OPTION) {
// save preferences
FSPath lastDir = getApplication().getFrameController().getLastEOModelDirectory();
lastDir.updateFromChooser(fileChooser);
File file = fileChooser.getSelectedFile();
if (file.isFile()) {
file = file.getParentFile();
}
DataMap currentMap = getProjectController().getCurrentDataMap();
try {
URL url = file.toURI().toURL();
EOModelProcessor processor = new EOModelProcessor();
// load DataNode if we are not merging with an existing map
if (currentMap == null) {
loadDataNode(processor.loadModeIndex(url));
}
// load DataMap
DataMap map = processor.loadEOModel(url);
addDataMap(map, currentMap);
} catch (Exception ex) {
logObj.info("EOModel Loading Exception", ex);
ErrorDebugDialog.guiException(ex);
}
}
}
Aggregations