Example usage for javax.swing JOptionPane OK_CANCEL_OPTION

List of usage examples for javax.swing JOptionPane OK_CANCEL_OPTION

Introduction

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

Prototype

int OK_CANCEL_OPTION

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

Click Source Link

Document

Type used for showConfirmDialog.

Usage

From source file:org.datavyu.views.DataControllerV.java

/**
 * Presents a confirmation dialog when removing a plugin from the project.
 * @return True if the plugin should be removed, false otherwise.
 *///from   w ww .  j  a va2  s  .  co m
private boolean shouldRemove() {
    ResourceMap rMap = Application.getInstance(Datavyu.class).getContext().getResourceMap(Datavyu.class);

    String cancel = "Cancel";
    String ok = "OK";

    String[] options = new String[2];

    if (Datavyu.getPlatform() == Platform.MAC) {
        options[0] = cancel;
        options[1] = ok;
    } else {
        options[0] = ok;
        options[1] = cancel;
    }

    int selection = JOptionPane.showOptionDialog(this, rMap.getString("ClosePluginDialog.message"),
            rMap.getString("ClosePluginDialog.title"), JOptionPane.OK_CANCEL_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, options, cancel);

    // Button behaviour is platform dependent.
    return (Datavyu.getPlatform() == Platform.MAC) ? (selection == 1) : (selection == 0);
}

From source file:org.eobjects.datacleaner.actions.OpenAnalysisJobActionListener.java

/**
 * Opens a job file/*from   ww  w  . j a va 2s.  com*/
 * 
 * @param file
 * @return
 */
public Injector openAnalysisJob(FileObject file) {
    JaxbJobReader reader = new JaxbJobReader(_configuration);
    try {
        AnalysisJobBuilder ajb = reader.create(file);

        return openAnalysisJob(file, ajb);
    } catch (NoSuchDatastoreException e) {
        if (_windowContext == null) {
            // This can happen in case of single-datastore + job file
            // bootstrapping of DC
            throw e;
        }

        AnalysisJobMetadata metadata = reader.readMetadata(file);
        int result = JOptionPane.showConfirmDialog(null,
                e.getMessage() + "\n\nDo you wish to open this job as a template?", "Error: " + e.getMessage(),
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE);
        if (result == JOptionPane.OK_OPTION) {
            OpenAnalysisJobAsTemplateDialog dialog = new OpenAnalysisJobAsTemplateDialog(_windowContext,
                    _configuration, file, metadata, Providers.of(this));
            dialog.setVisible(true);
        }
        return null;
    }
}

From source file:org.executequery.gui.browser.SSHTunnelConnectionPanel.java

public boolean canConnect() {

    if (useSshCheckbox.isSelected()) {

        if (!hasValue(userNameField)) {

            GUIUtilities/*www . j a va2s  .  c o  m*/
                    .displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH user name");
            return false;
        }

        if (!hasValue(portField)) {

            GUIUtilities.displayErrorMessage("You have selected SSH Tunnel but have not provided an SSH port");
            return false;
        }

        if (!hasValue(passwordField)) {

            final JPasswordField field = WidgetFactory.createPasswordField();

            JOptionPane optionPane = new JOptionPane(field, JOptionPane.QUESTION_MESSAGE,
                    JOptionPane.OK_CANCEL_OPTION);
            JDialog dialog = optionPane.createDialog("Enter SSH password");

            dialog.addWindowFocusListener(new WindowAdapter() {
                @Override
                public void windowGainedFocus(WindowEvent e) {
                    field.requestFocusInWindow();
                }
            });

            dialog.pack();
            dialog.setLocation(GUIUtilities.getLocationForDialog(dialog.getSize()));
            dialog.setVisible(true);
            dialog.dispose();

            int result = Integer.parseInt(optionPane.getValue().toString());
            if (result == JOptionPane.OK_OPTION) {

                String password = MiscUtils.charsToString(field.getPassword());
                if (StringUtils.isNotBlank(password)) {

                    passwordField.setText(password);
                    return true;

                } else {

                    GUIUtilities.displayErrorMessage(
                            "You have selected SSH Tunnel but have not provided an SSH password");

                    // send back here and force them to select cancel if they want to bail

                    return canConnect();
                }

            }
            return false;
        }

    }

    return true;
}

From source file:org.intermine.install.swing.ProjectEditor.java

/**
 * Change the look and feel of the application.
 *
 * @param laf The new Look and Feel information.
 *
 * @return <code>true</code> if the look and feel changed ok, <code>false</code>
 * if not./*  www.  ja v  a2s .co  m*/
 *
 * @see <a href="http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/plaf.html#dynamic">
 * The Swing Tutorial</a>
 */
public boolean changeLookAndFeel(LookAndFeelInfo laf) {
    assert SwingUtilities.isEventDispatchThread() : "Can only change L&F from event thread";

    if (laf.getName().equals(UIManager.getLookAndFeel().getName())) {
        return true;
    }

    boolean changeOk = false;
    try {
        UIManager.setLookAndFeel(laf.getClassName());
        SwingUtilities.updateComponentTreeUI(this);
        SwingUtilities.updateComponentTreeUI(modelViewerFrame);
        for (Window w : getOwnedWindows()) {
            SwingUtilities.updateComponentTreeUI(w);
        }

        changeOk = true;
    } catch (Exception e) {
        logger.error("Failed to change look and feel: " + e.getMessage());
        logger.debug("", e);

        int choice = JOptionPane.showConfirmDialog(this,
                Messages.getMessage("preferences.lookandfeel.changefailed.message", e.getMessage()),
                Messages.getMessage("preferences.lookandfeel.changefailed.title"), JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.WARNING_MESSAGE);

        changeOk = choice == JOptionPane.OK_OPTION;
    }

    return changeOk;
}

From source file:org.jajuk.services.startup.StartupCollectionService.java

private static void tryToParseABackupFile() {
    final File[] fBackups = SessionService.getConfFileByPath("").listFiles(new FilenameFilter() {
        @Override/* w w w .j  a va2 s .c  om*/
        public boolean accept(File dir, String name) {
            if (name.indexOf("backup") != -1) {
                return true;
            }
            return false;
        }
    });
    final List<File> alBackupFiles = new ArrayList<File>(Arrays.asList(fBackups));
    Collections.sort(alBackupFiles); // sort alphabetically (newest
    // last)
    Collections.reverse(alBackupFiles); // newest first now
    final Iterator<File> it = alBackupFiles.iterator();
    // parse all backup files, newest first
    boolean parsingOK = false;
    while (!parsingOK && it.hasNext()) {
        final File file = it.next();
        try {
            // Clear all previous collection
            Collection.clearCollection();
            // Load the backup file
            Collection.load(file);
            parsingOK = true;
            // Show a message telling user that we use a backup file
            final int i = Messages.getChoice(Messages.getString("Error.133") + ":\n" + file.getAbsolutePath(),
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE);
            if (i == JOptionPane.CANCEL_OPTION) {
                System.exit(-1); //NOSONAR
            }
            break;
        } catch (final Exception e2) {
            Log.error(5, file.getAbsolutePath(), e2);
        }
    }
}

From source file:org.javaswift.cloudie.CloudiePanel.java

private ContainerSpecification doGetContainerSpec() {
    JTextField name = new JTextField();
    JCheckBox priv = new JCheckBox("private container");
    if (JOptionPane.showConfirmDialog(this, new Object[] { "Name", name, priv }, "Create Container",
            JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        return new ContainerSpecification(name.getText(), priv.isSelected());
    }//from  ww w . jav  a 2s.  c  o m
    return null;
}

From source file:org.kuali.test.ui.utils.UIUtils.java

/**
 *
 * @param c/*  w w w  .j av  a  2s. c o m*/
 * @param title
 * @param prompt
 * @return
 */
public static boolean promptForCancel(Component c, String title, String prompt) {
    return (JOptionPane.showConfirmDialog(findWindow(c), prompt, title,
            JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION);
}

From source file:org.netbeans.jpa.modeler.properties.PropertiesHandler.java

public static ComboBoxPropertySupport getCollectionTypeProperty(
        AttributeWidget<? extends Attribute> attributeWidget, final CollectionTypeHandler colSpec) {
    JPAModelerScene modelerScene = attributeWidget.getModelerScene();
    EntityMappings em = modelerScene.getBaseElementSpec();
    ModelerFile modelerFile = modelerScene.getModelerFile();
    ComboBoxListener<String> comboBoxListener = new ComboBoxListener<String>() {
        private final Set<String> value = new HashSet<>();

        @Override/*from   w ww  . j  av a2s.  c o m*/
        public void setItem(ComboBoxValue<String> value) {
            String prevType = colSpec.getCollectionType();
            String newType = value.getValue();
            setCollectionType(value);
            manageMapType(prevType, newType);
            attributeWidget.setAttributeTooltip();
            attributeWidget.visualizeDataType();
        }

        void setCollectionType(ComboBoxValue<String> value) {
            String collectionType = value.getValue();
            boolean valid = false;
            try {
                if (collectionType != null && !collectionType.trim().isEmpty()) {
                    if (java.util.Collection.class.isAssignableFrom(Class.forName(collectionType.trim()))
                            || java.util.Map.class.isAssignableFrom(Class.forName(collectionType.trim()))) {
                        valid = true;
                    }
                }
            } catch (ClassNotFoundException ex) {
                //skip allow = false;
            }
            if (!valid) {
                collectionType = java.util.Collection.class.getName();
            }

            colSpec.setCollectionType(collectionType);
            em.getCache().addCollectionClass(collectionType);//move item to top in cache
        }

        void manageMapType(String prevType, String newType) {

            Class prevClass = null;
            try {
                prevClass = Class.forName(prevType);
            } catch (ClassNotFoundException ex) {
            }
            Class newClass = null;
            try {
                newClass = Class.forName(newType);
            } catch (ClassNotFoundException ex) {
            }

            if ((prevClass != null && newClass != null && prevClass != newClass
                    && (Map.class.isAssignableFrom(prevClass) || Map.class.isAssignableFrom(newClass)))
                    || (prevClass == null && newClass != null && Map.class.isAssignableFrom(newClass))
                    || (prevClass != null && newClass == null && Map.class.isAssignableFrom(prevClass))) {
                if (newClass == null || !Map.class.isAssignableFrom(newClass)) {
                    ((MapKeyHandler) attributeWidget.getBaseElementSpec()).resetMapAttribute();
                }
                attributeWidget.refreshProperties();
            }
        }

        @Override
        public ComboBoxValue<String> getItem() {
            if (!value.contains(colSpec.getCollectionType())) {
                value.add(colSpec.getCollectionType());
                em.getCache().addCollectionClass(colSpec.getCollectionType());
            }
            return new ComboBoxValue(colSpec.getCollectionType(),
                    colSpec.getCollectionType().substring(colSpec.getCollectionType().lastIndexOf('.') + 1));
        }

        @Override
        public List<ComboBoxValue<String>> getItemList() {
            List<ComboBoxValue<String>> comboBoxValues = new ArrayList<>();
            value.addAll(em.getCache().getCollectionClasses());
            em.getCache().getCollectionClasses().stream().forEach((collection) -> {
                Class _class;
                try {
                    _class = Class.forName(collection);
                    comboBoxValues.add(new ComboBoxValue(_class.getName(), _class.getSimpleName()));
                } catch (ClassNotFoundException ex) {
                    comboBoxValues.add(new ComboBoxValue(collection, collection + "(Not Exist)"));
                }
            });
            return comboBoxValues;
        }

        @Override
        public String getDefaultText() {
            return EMPTY;
        }

        @Override
        public ActionHandler getActionHandler() {
            return ActionHandler.getInstance(() -> {
                String collectionType = NBModelerUtil.browseClass(modelerFile);
                return new ComboBoxValue<>(collectionType,
                        collectionType.substring(collectionType.lastIndexOf('.') + 1));
            }).afterCreation(e -> em.getCache().addCollectionClass(e.getValue()))
                    .afterDeletion(e -> em.getCache().getCollectionClasses().remove(e.getValue()))
                    .beforeDeletion(
                            () -> JOptionPane.showConfirmDialog(WindowManager.getDefault().getMainWindow(),
                                    "Are you sue you want to delete this collection class ?",
                                    "Delete Collection Class", JOptionPane.OK_CANCEL_OPTION));
        }
    };
    return new ComboBoxPropertySupport(modelerScene.getModelerFile(), "collectionType", "Collection Type", "",
            comboBoxListener);
}

From source file:org.nuclos.client.common.NuclosCollectController.java

/**
 * command: remove filter//from  w  w w.j  a v  a2s. co  m
 */
protected void cmdRemoveFilter() {
    final SearchFilter filter = getSelectedSearchFilter();
    if (filter != null) {
        if (JOptionPane.showConfirmDialog(this.getTab(),
                getSpringLocaleDelegate().getMessage("NuclosCollectController.16",
                        "Wollen Sie den Filter \"{0}\" wirklich l\u00f6schen?", filter.getName()),
                "Filter l\u00f6schen", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
            UIUtils.runCommand(this.getTab(), new CommonRunnable() {
                @Override
                public void run() throws NuclosBusinessException {
                    getSearchFilters().remove(filter);
                    refreshFilterView();
                    refreshFastFilter();
                }
            });
        }
    }
}

From source file:org.nuclos.client.customcomp.resplan.AbstractResPlanExportDialog.java

@PostConstruct
private void init() {
    double border = 10;
    double inset = 5;
    double size[][] = { { border, 100, inset, 200, inset, 30, inset, 65, border }, // Columns
            { border, 20, inset, 20, inset, 30, border } }; // Rows
    final TableLayout tl = new TableLayout(size);
    setLayout(tl);//w  w  w.j  a v  a  2  s.  com

    final SpringLocaleDelegate sld = getSpringLocaleDelegate();
    final JLabel fileLabel = new JLabel(sld.getText("nuclos.resplan.dialog.file"), SwingConstants.RIGHT);
    add(fileLabel, "1, 1");
    file = new JTextField();
    file.setText(save.getPath());
    add(file, "3, 1");

    final JButton browse = new JButton("...");
    add(browse, "5, 1");

    final JLabel typeLabel = new JLabel(sld.getText("nuclos.resplan.dialog.type"), SwingConstants.RIGHT);
    add(typeLabel, "1, 3");
    fileTypes = new JComboBox(new String[] { ImageType.SVG.getFileExtension(), ImageType.EMF.getFileExtension(),
            ImageType.PNG.getFileExtension() });
    fileTypes.setSelectedItem(defaultFileType);
    fileTypes.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            checkFile();
        }
    });
    add(fileTypes, "3, 3");

    browse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final JFileChooser chooser = new JFileChooser(save.getParent());
            chooser.setAcceptAllFileFilterUsed(false);
            chooser.addChoosableFileFilter(new MyFileFilter((String) fileTypes.getSelectedItem()));
            // chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
            final int returnVal = chooser.showSaveDialog(parent);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                save = chooser.getSelectedFile();
                checkFile();
            }
        }
    });

    final JPanel buttons = new JPanel(new FlowLayout());
    add(buttons, "1, 5, 7, 5");

    final JButton export = new JButton(sld.getText("nuclos.resplan.dialog.export"));
    buttons.add(export);
    export.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final String filePath = file.getText();
            if (!filePath.equals(save.getPath())) {
                save = new File(filePath);
            }
            checkFile();
            if (save.exists()) {
                String file = save.getAbsolutePath();
                if (save.canWrite()) {
                    int ans = JOptionPane.showConfirmDialog(AbstractResPlanExportDialog.this,
                            sld.getMessage("general.overwrite.file", "general.overwrite.file", file),
                            sld.getMessage("general.overwrite.file.title", "general.overwrite.file.title"),
                            JOptionPane.OK_CANCEL_OPTION);
                    if (ans != JOptionPane.YES_OPTION) {
                        return;
                    }
                } else {
                    JOptionPane.showMessageDialog(AbstractResPlanExportDialog.this,
                            sld.getMessage("general.notwritable.file", "general.notwritable.file", file),
                            sld.getMessage("general.notwritable.file.title", "general.notwritable.file.title"),
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
            export();
            storePreferences();
            dispose();
        }
    });

    final JButton cancel = new JButton(sld.getText("general.cancel"));
    buttons.add(cancel);
    cancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });

    pack();
    setLocationRelativeTo(parent);
    setVisible(true);
}