Search in sources :

Example 6 with FSPath

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);
            }
        }
    }
}
Also used : FSPath(org.apache.cayenne.modeler.pref.FSPath) File(java.io.File)

Example 7 with FSPath

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);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FSPath(org.apache.cayenne.modeler.pref.FSPath) JTextField(javax.swing.JTextField) File(java.io.File)

Example 8 with FSPath

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);
        }
    }
}
Also used : JGraph(org.jgraph.JGraph) JFileChooser(javax.swing.JFileChooser) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FSPath(org.apache.cayenne.modeler.pref.FSPath) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 9 with FSPath

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;
}
Also used : FSPath(org.apache.cayenne.modeler.pref.FSPath) File(java.io.File)

Example 10 with FSPath

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);
        }
    }
}
Also used : FSPath(org.apache.cayenne.modeler.pref.FSPath) EOModelProcessor(org.apache.cayenne.wocompat.EOModelProcessor) File(java.io.File) URL(java.net.URL) DataMap(org.apache.cayenne.map.DataMap)

Aggregations

FSPath (org.apache.cayenne.modeler.pref.FSPath)11 File (java.io.File)7 JFileChooser (javax.swing.JFileChooser)2 BufferedImage (java.awt.image.BufferedImage)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 BackingStoreException (java.util.prefs.BackingStoreException)1 Preferences (java.util.prefs.Preferences)1 JTextField (javax.swing.JTextField)1 AbstractTableModel (javax.swing.table.AbstractTableModel)1 DataMap (org.apache.cayenne.map.DataMap)1 BindingBuilder (org.apache.cayenne.swing.BindingBuilder)1 EOModelProcessor (org.apache.cayenne.wocompat.EOModelProcessor)1 JGraph (org.jgraph.JGraph)1