Example usage for javax.swing JOptionPane CLOSED_OPTION

List of usage examples for javax.swing JOptionPane CLOSED_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane CLOSED_OPTION.

Prototype

int CLOSED_OPTION

To view the source code for javax.swing JOptionPane CLOSED_OPTION.

Click Source Link

Document

Return value from class method if user closes window without selecting anything, more than likely this should be treated as either a CANCEL_OPTION or NO_OPTION.

Usage

From source file:edu.ku.brc.af.ui.forms.FormViewObj.java

public boolean isDataCompleteAndValid(final boolean throwAwayOnDiscard) {
    //log.debug((formValidator != null) +" "+ formValidator.hasChanged() +"  "+mvParent.isTopLevel() +" "+ mvParent.hasChanged());

    // Figure out if it is New and whether it has changed or is incomplete
    boolean isNewAndComplete = true;
    if (mvParent != null) {
        Object topParentData = mvParent.getTopLevel().getData();
        if (topParentData != null && topParentData instanceof FormDataObjIFace) {
            if (((FormDataObjIFace) topParentData).getId() == null) {
                if (formValidator != null && dataObj != null) {
                    isNewAndComplete = formValidator.isFormValid();
                }//w  w  w .  j a  v a 2 s.  c  om
            }
        }
    }

    //log.debug("Form     Val: "+(formValidator != null && formValidator.hasChanged()));
    //log.debug("mvParent Val: "+(mvParent != null && mvParent.isTopLevel() && mvParent.hasChanged()));

    //if ((formValidator != null && formValidator.hasChanged()) ||
    //    (mvParent != null && mvParent.isTopLevel() && mvParent.hasChanged()))
    if (!doingDiscard && mvParent != null && mvParent.isTopLevel() && mvParent.hasChanged()) {
        try {
            doingDiscard = true;
            String title = null;
            if (dataObj != null) {
                if (tableInfo == null) {
                    tableInfo = DBTableIdMgr.getInstance()
                            .getByShortClassName(dataObj.getClass().getSimpleName());
                }

                title = tableInfo != null ? tableInfo.getTitle() : null;

                if (StringUtils.isEmpty(title)) {
                    title = UIHelper.makeNamePretty(dataObj.getClass().getSimpleName());
                }
            }

            if (StringUtils.isEmpty(title)) {
                title = "data"; // I18N, not really sure what to put here.
            }

            // For the DISCARD
            // Since JOptionPane doesn't have a YES_CANCEL_OPTION 
            // I have to use YES_NO_OPTION and since this is a Discard question
            // the rv has completely different meanings:
            // YES -> Means don't save (Discard) and close dialog (return true)
            // NO  -> Means do nothing so return false

            String[] optionLabels;
            int dlgOptions;
            int defaultRV;
            if (!isNewAndComplete || (formValidator != null && !formValidator.isFormValid())) {
                dlgOptions = JOptionPane.YES_NO_OPTION;
                optionLabels = new String[] { getResourceString("DiscardChangesBtn"),
                        getResourceString("CANCEL") };
                defaultRV = JOptionPane.NO_OPTION;
            } else {
                dlgOptions = JOptionPane.YES_NO_CANCEL_OPTION;
                optionLabels = new String[] { getResourceString("SaveChangesBtn"),
                        getResourceString("DiscardChangesBtn"), getResourceString("CANCEL") };
                defaultRV = JOptionPane.CANCEL_OPTION;
            }

            int rv = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(),
                    isNewAndComplete ? UIRegistry.getLocalizedMessage("DiscardChanges", title)
                            : UIRegistry.getLocalizedMessage("SaveChanges", title),
                    isNewAndComplete ? getResourceString("DiscardChangesTitle")
                            : getResourceString("SaveChangesTitle"),
                    dlgOptions, JOptionPane.QUESTION_MESSAGE, null, optionLabels, optionLabels[0]);

            if (rv == JOptionPane.CLOSED_OPTION) {
                rv = defaultRV;
            }

            if (dlgOptions == JOptionPane.YES_NO_OPTION) {
                if (rv == JOptionPane.YES_OPTION) {
                    discardCurrentObject(throwAwayOnDiscard);
                    return true;

                } else if (rv == JOptionPane.NO_OPTION) {
                    return false;
                }

            } else {
                if (rv == JOptionPane.YES_OPTION) {
                    return saveObject();

                } else if (rv == JOptionPane.CANCEL_OPTION) {
                    return false;

                } else if (rv == JOptionPane.NO_OPTION) {
                    // NO means Discard
                    discardCurrentObject(throwAwayOnDiscard);
                    return true;
                }
            }
        } finally {
            doingDiscard = false;
        }

    } else {
        return true;
    }
    return isNewAndComplete;
}

From source file:com.mirth.connect.client.ui.Frame.java

/**
 * A prompt to ask the user if he would like to save the changes made before leaving the page.
 *//*from  w w  w .  j av a  2 s .c  o m*/
public boolean confirmLeave() {
    if (currentContentPage == channelPanel && isSaveEnabled()) {
        if (!channelPanel.confirmLeave()) {
            return false;
        }
    } else if ((currentContentPage == channelEditPanel || currentContentPage == channelEditPanel.transformerPane
            || currentContentPage == channelEditPanel.filterPane) && isSaveEnabled()) {
        int option = JOptionPane.showConfirmDialog(this, "Would you like to save the channel changes?");
        if (option == JOptionPane.YES_OPTION) {
            if (!channelEditPanel.saveChanges()) {
                return false;
            }
        } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
            return false;
        }
    } else if (currentContentPage == settingsPane && isSaveEnabled()) {
        int option = JOptionPane.showConfirmDialog(this, "Would you like to save the "
                + settingsPane.getCurrentSettingsPanel().getTabName() + " settings changes?");

        if (option == JOptionPane.YES_OPTION) {
            if (!settingsPane.getCurrentSettingsPanel().doSave()) {
                return false;
            }
        } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
            return false;
        }
    } else if (currentContentPage == alertEditPanel && isSaveEnabled()) {
        int option = JOptionPane.showConfirmDialog(this, "Would you like to save the alerts?");

        if (option == JOptionPane.YES_OPTION) {
            if (!alertEditPanel.saveAlert()) {
                return false;
            }
        } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
            return false;
        }
    } else if (currentContentPage == globalScriptsPanel && isSaveEnabled()) {
        int option = JOptionPane.showConfirmDialog(this, "Would you like to save the scripts?");

        if (option == JOptionPane.YES_OPTION) {
            if (!doSaveGlobalScripts()) {
                return false;
            }
        } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
            return false;
        }
    } else if (currentContentPage == codeTemplatePanel && isSaveEnabled()) {
        if (!codeTemplatePanel.confirmLeave()) {
            return false;
        }
    }

    setSaveEnabled(false);
    return true;
}

From source file:GUI.MainWindow.java

public void addReference(JTree tree, JList list, Reference current) {
    DefaultMutableTreeNode node = ((DefaultMutableTreeNode) tree.getLastSelectedPathComponent());
    if (node == null) {
        return;/*  ww w.  j a  v  a2  s.c o m*/
    }

    Object obj = node.getUserObject();
    if (!(obj instanceof Vulnerability)) {
        return; // here be monsters, most likely in the merge tree
    }
    Vulnerability vuln = (Vulnerability) obj;
    DefaultListModel dlm = (DefaultListModel) list.getModel();
    // Build Input Field and display it
    JTextField description = new JTextField();
    JTextField url = new JTextField();

    // If current is not null then pre-set the description and risk
    if (current != null) {
        description.setText(current.getDescription());
        url.setText(current.getUrl());
    }

    JLabel error = new JLabel(
            "A valid URL needs to be supplied including the protocol i.e. http://www.github.com");
    error.setForeground(Color.red);
    Object[] message = { "Description:", description, "URL:", url };

    String url_string = null;
    Reference newref = null;
    while (url_string == null) {
        int option = JOptionPane.showConfirmDialog(null, message, "Add Reference",
                JOptionPane.OK_CANCEL_OPTION);
        if (option == JOptionPane.OK_OPTION) {
            System.out.println("User clicked ok, validating data");
            String ref_desc = description.getText();
            String ref_url = url.getText();
            if (!ref_desc.equals("") || !ref_url.equals("")) {
                // Both have values
                // Try to validate URL
                try {

                    URL u = new URL(url.getText());
                    u.toURI();
                    url_string = url.getText(); // Causes loop to end with a valid url

                } catch (MalformedURLException ex) {
                    url_string = null;
                    //ex.printStackTrace();
                } catch (URISyntaxException ex) {
                    url_string = null;
                    //ex.printStackTrace();
                }

            }

        } else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
            System.out.println("User clicked cancel/close");
            return; // ends the loop without making any chages
        }

        if (url_string == null) {
            // We need to show an error saying that the url failed to parse
            Object[] message2 = { error, "Description:", description, "URL:", url };
            message = message2;

        }
    }

    // If you get here there is a valid reference URL and description
    Reference ref = new Reference(description.getText(), url.getText());

    if (current == null) {
        // Add it to the vuln
        vuln.addReference(ref);
        // Add it to the GUI 
        dlm.addElement(ref);
        System.out.println("Valid reference added: " + ref);
    } else {
        // Modify it in the vuln
        vuln.modifyReference(current, ref);
        // Update the GUI
        dlm.removeElement(current);
        dlm.addElement(ref);
        System.out.println("Valid reference modified: " + ref);
    }

}

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemOpenTreeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemOpenTreeActionPerformed
    // Select a file to open
    fc.setFileFilter(EPlusConfig.getFileFilter(EPlusConfig.EPUSEROBJ));
    fc.setSelectedFile(new File(""));
    fc.setCurrentDirectory(DefaultDir);//from   ww  w . j  av  a2 s .co m
    if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // load object as a project first
        JEPlusProject proj = JEPlusProject.deserialize(file);
        if (proj != null) {
            Project = proj;
            this.initProjectSection();
            this.setExecType(Project.getExecSettings().getExecutionType());
            this.cboExecutionTypeActionPerformed(null);
            this.initBatchOptions();
            // this does not change current project file reference
        } else if (!deserialize(file)) {
            // if failed, try open it as v0.5 object
            // warning message
            JOptionPane.showMessageDialog(this, "<html><p><center>For some reasons, I cannot load project from "
                    + file.getAbsolutePath()
                    + ".<br /></center></p><p><center> Please check again that the file is a jEPlus v0.5 object file.<br /></center></p>",
                    "Error", JOptionPane.CLOSED_OPTION);
        }
        // set current path to the location of the obj file only if current project is unknown
        if (this.CurrentProjectFile == null)
            DefaultDir = file.getParentFile();
    }
    fc.resetChoosableFileFilters();
    fc.setSelectedFile(new File(""));
}

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemSaveTreeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveTreeActionPerformed
    // Select a file to save
    // fc = new JFileChooser ();
    fc.setFileFilter(EPlusConfig.getFileFilter(EPlusConfig.EPUSEROBJ));
    fc.setSelectedFile(new File(""));
    // @todo do we need project directory?
    fc.setCurrentDirectory(DefaultDir);//from w  w  w  . j ava 2  s.co  m
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // write object
        if (!JEPlusProject.serialize(file, this.getProject())) {
            // warning message
            JOptionPane.showMessageDialog(this, "The Project cannot be saved to " + file.getAbsolutePath()
                    + "for some reason. Is the fold writable?", "Error", JOptionPane.CLOSED_OPTION);
        }
        DefaultDir = file.getParentFile();
    } else {

    }
    fc.resetChoosableFileFilters();
    fc.setSelectedFile(new File(""));
}

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSaveAsActionPerformed
    // Select a file to save
    // fc = new JFileChooser ();
    fc.setFileFilter(EPlusConfig.getFileFilter(EPlusConfig.JEP));
    fc.setSelectedFile(new File(CurrentProjectFile == null ? "" : CurrentProjectFile));
    fc.setCurrentDirectory(DefaultDir);/*  w w w. j a  v a2  s . c o m*/
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        if (!file.getName().endsWith(".jep"))
            file = new File(file.getPath().concat(".jep"));
        // convert to relative paths?
        // Project.convertToRelativeDir(file.getParentFile());
        // write object
        if (!Project.saveAsXML(file)) {
            // warning message
            JOptionPane.showMessageDialog(this, "The JEPlus Project cannot be saved for some reasons. :-(",
                    "Error", JOptionPane.CLOSED_OPTION);
        }
        // Update default dir and current project file reference
        DefaultDir = new File(Project.getBaseDir());
        this.setCurrentProjectFile(file.getPath());
        // update screen
        this.initProjectSection();
        this.cboExecutionTypeActionPerformed(null);
    } else {

    }
    fc.resetChoosableFileFilters();
    fc.setSelectedFile(new File(""));
}

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemImportTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemImportTableActionPerformed
    // Select a file to open
    fc.setFileFilter(EPlusConfig.getFileFilter(EPlusConfig.CSV));
    fc.setSelectedFile(new File(""));
    fc.setCurrentDirectory(DefaultDir);/*from   w w  w . j av  a 2s  . com*/
    if (fc.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // import table
        if (!Project.importParameterTableFile(file)) {
            JOptionPane.showMessageDialog(this,
                    "Import parameter tree from CSV table in " + file.getAbsolutePath()
                            + "failed. Please check the format of the table file.",
                    "Error", JOptionPane.CLOSED_OPTION);
        }
        this.initProjectSection();
    } else {

    }
    fc.setFileFilter(null);
}

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemExportTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExportTableActionPerformed
    // Select a file to open
    fc.setFileFilter(EPlusConfig.getFileFilter(EPlusConfig.CSV));
    fc.setSelectedFile(new File(""));
    fc.setCurrentDirectory(DefaultDir);/*from ww w .jav  a 2 s  . com*/
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        // import table
        if (!Project.exportParameterTableFile(file)) {
            JOptionPane.showMessageDialog(this,
                    "<html>Export parameters to " + file.getAbsolutePath()
                            + "failed. Please make sure the file is writable.</html>",
                    "Error", JOptionPane.CLOSED_OPTION);
        } else {
            JOptionPane.showMessageDialog(this,
                    "<html>Exported parameters to " + file.getAbsolutePath()
                            + ". Please note only the first branch of the parameter tree is saved.</html>",
                    "Information", JOptionPane.CLOSED_OPTION);
        }
        //this.initProjectSection();
    } else {

    }
    fc.resetChoosableFileFilters();
    fc.setSelectedFile(new File(""));
}

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemCreateJobListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCreateJobListActionPerformed
    // Select a file to save
    // fc = new JFileChooser ();
    fc.setFileFilter(EPlusConfig.getFileFilter(EPlusConfig.CSV));
    fc.setSelectedFile(new File(""));
    fc.setCurrentDirectory(DefaultDir);/*from w  w w. j ava2s. c om*/
    if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        if (!file.getName().endsWith(".csv"))
            file = new File(file.getPath().concat(".csv"));
        // convert to relative paths?
        // Project.convertToRelativeDir(file.getParentFile());
        // write object
        if (!this.createJobList(file.getName(), file.getParent().concat(File.separator))) {
            // warning message
            JOptionPane.showMessageDialog(this,
                    "The JEPlus job list cannot be saved to " + file.getAbsolutePath(), "Error",
                    JOptionPane.CLOSED_OPTION);
        }
    }
    fc.resetChoosableFileFilters();
    fc.setSelectedFile(new File(""));
}

From source file:jeplus.JEPlusFrameMain.java

private void jMenuItemViewFolderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemViewFolderActionPerformed
    if (Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
        try {/*  w w w  .j  a v  a 2 s . com*/
            File output = new File(BatchManager.getResolvedEnv().getParentDir());
            if (output.exists()) {
                Desktop.getDesktop().open(output);
            } else {
                JOptionPane.showMessageDialog(this,
                        "Output folder " + output.getAbsolutePath() + " does not exist.");
            }
        } catch (IOException ex) {
            logger.error("Failed to open folder " + BatchManager.getResolvedEnv().getParentDir(), ex);
        }
    } else {
        JOptionPane.showMessageDialog(this,
                "Open folder is not supported, or the current job record is not valid.", "Operation failed",
                JOptionPane.CLOSED_OPTION);
    }

}