Example usage for javax.swing JOptionPane OK_OPTION

List of usage examples for javax.swing JOptionPane OK_OPTION

Introduction

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

Prototype

int OK_OPTION

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

Click Source Link

Document

Return value form class method if OK is chosen.

Usage

From source file:org.signserver.admin.gui.AddWorkerDialog.java

private void addPropertyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPropertyButtonActionPerformed
    workerPropertyEditor.setKey("");
    workerPropertyEditor.setValue("");

    final int res = workerPropertyEditor.showDialog(this);

    if (res == JOptionPane.OK_OPTION) {
        final String key = workerPropertyEditor.getKey().toUpperCase();
        final String value = workerPropertyEditor.getValue();

        addOrEditProperty(key, value);//from  w  ww. ja  va  2s  . co  m
    }
}

From source file:org.signserver.admin.gui.AddWorkerDialog.java

private void editPropertyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPropertyButtonActionPerformed
    final int row = propertiesTable.getSelectedRow();

    if (row != -1) {
        final String oldKey = (String) propertiesTable.getValueAt(row, 0);
        final String oldValue = (String) propertiesTable.getValueAt(row, 1);

        workerPropertyEditor.setKey(oldKey);
        workerPropertyEditor.setValue(oldValue);

        final int res = workerPropertyEditor.showDialog(this);

        if (res == JOptionPane.OK_OPTION) {
            final String key = workerPropertyEditor.getKey().toUpperCase();
            final String value = workerPropertyEditor.getValue();

            if (!oldKey.equals(key) && !key.equals(PropertiesConstants.NAME)) {
                removeProperty(oldKey);//from   w  w w.  j av a2 s  .co m
            }

            addOrEditProperty(key, value);
        }
    }
}

From source file:org.signserver.admin.gui.MainView.java

private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
    // initialize edit dialog with emptry values
    workerPropertyEditor.setKey("");
    workerPropertyEditor.setValue("");

    final int res = workerPropertyEditor.showDialog(getFrame());

    if (res == JOptionPane.OK_OPTION) {
        int workerId = selectedWorker.getWorkerId();

        try {//w  ww .  jav a  2  s . c  om
            SignServerAdminGUIApplication.getAdminWS().setWorkerProperty(workerId,
                    workerPropertyEditor.getKey(), workerPropertyEditor.getValue());
            SignServerAdminGUIApplication.getAdminWS().reloadConfiguration(workerId);

            refreshButton.doClick();
        } catch (AdminNotAuthorizedException_Exception ex) {
            showAdminNotAuthorized(ex);
        } catch (SOAPFaultException ex) {
            showServerSideException(ex);
        } catch (EJBException ex) {
            showServerSideException(ex);
        }
    }
}

From source file:org.signserver.admin.gui.MainView.java

private void editButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed

    final int row = configurationTable.getSelectedRow();

    if (row != -1) {

        final String oldPropertyName = (String) configurationTable.getValueAt(row, 0);

        workerPropertyEditor.setKey(oldPropertyName);
        workerPropertyEditor.setValue((String) configurationTable.getValueAt(row, 1));

        final int res = workerPropertyEditor.showDialog(getFrame());

        if (res == JOptionPane.OK_OPTION) {
            try {
                final int workerId = selectedWorker.getWorkerId();
                final String newPropertyName = workerPropertyEditor.getKey();

                if (!oldPropertyName.equals(newPropertyName)) {
                    SignServerAdminGUIApplication.getAdminWS().removeWorkerProperty(workerId, oldPropertyName);
                }/*from   ww  w. j  a va 2  s  .co m*/

                SignServerAdminGUIApplication.getAdminWS().setWorkerProperty(workerId, newPropertyName,
                        workerPropertyEditor.getValue());
                SignServerAdminGUIApplication.getAdminWS().reloadConfiguration(workerId);

                refreshButton.doClick();
            } catch (final AdminNotAuthorizedException_Exception ex) {
                showAdminNotAuthorized(ex);
            } catch (SOAPFaultException ex) {
                showServerSideException(ex);
            } catch (EJBException ex) {
                showServerSideException(ex);
            }
        }
    }
}

From source file:org.signserver.admin.gui.MainView.java

private void authAddButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_authAddButtonActionPerformed
    editSerialNumberTextfield.setText("");
    editSerialNumberTextfield.setEditable(true);
    editIssuerDNTextfield.setText("");
    editIssuerDNTextfield.setEditable(true);
    editUpdateAllCheckbox.setSelected(false);

    final int res = JOptionPane.showConfirmDialog(getFrame(), authEditPanel, "Add authorized client",
            JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (res == JOptionPane.OK_OPTION) {
        List<Worker> workers;
        if (editUpdateAllCheckbox.isSelected()) {
            workers = selectedWorkers;/*from w  ww  .  ja v a  2  s .c o  m*/
        } else {
            workers = Collections.singletonList(selectedWorker);
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Selected workers: " + workers);
        }

        for (Worker worker : workers) {
            try {
                final BigInteger sn = new BigInteger(editSerialNumberTextfield.getText(), 16);
                org.signserver.admin.gui.adminws.gen.AuthorizedClient client = new org.signserver.admin.gui.adminws.gen.AuthorizedClient();
                client.setCertSN(sn.toString(16));
                client.setIssuerDN(
                        org.cesecore.util.CertTools.stringToBCDNString(editIssuerDNTextfield.getText()));
                SignServerAdminGUIApplication.getAdminWS().addAuthorizedClient(worker.getWorkerId(), client);
                SignServerAdminGUIApplication.getAdminWS().reloadConfiguration(worker.getWorkerId());
            } catch (AdminNotAuthorizedException_Exception ex) {
                showAdminNotAuthorized(ex);
            } catch (NumberFormatException ex) {
                showMalformedSerialNumber(ex);
            } catch (SOAPFaultException ex) {
                showServerSideException(ex);
            } catch (EJBException ex) {
                showServerSideException(ex);
            }
        }
        refreshButton.doClick();
    }
}

From source file:org.signserver.admin.gui.MainView.java

private void authEditButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_authEditButtonActionPerformed
    final int row = authTable.getSelectedRow();
    if (row != -1) {

        final String serialNumberBefore = (String) authTable.getValueAt(row, 0);
        final String issuerDNBefore = (String) authTable.getValueAt(row, 1);

        editSerialNumberTextfield.setText(serialNumberBefore);
        editSerialNumberTextfield.setEditable(true);
        editIssuerDNTextfield.setText(issuerDNBefore);
        editIssuerDNTextfield.setEditable(true);
        editUpdateAllCheckbox.setSelected(false);

        final int res = JOptionPane.showConfirmDialog(getFrame(), authEditPanel, "Edit authorized client",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (res == JOptionPane.OK_OPTION) {
            try {
                List<Worker> workers;
                if (editUpdateAllCheckbox.isSelected()) {
                    workers = selectedWorkers;
                } else {
                    workers = Collections.singletonList(selectedWorker);
                }/*from   w  w  w  .j  av  a 2s.  c om*/

                if (LOG.isDebugEnabled()) {
                    LOG.debug("Selected workers: " + workers);
                }

                final AuthorizedClient oldAuthorizedClient = new AuthorizedClient();
                oldAuthorizedClient.setCertSN(serialNumberBefore);
                oldAuthorizedClient.setIssuerDN(issuerDNBefore);

                final AuthorizedClient client = new AuthorizedClient();
                final BigInteger sn = new BigInteger(editSerialNumberTextfield.getText(), 16);

                client.setCertSN(sn.toString(16));
                client.setIssuerDN(
                        org.cesecore.util.CertTools.stringToBCDNString(editIssuerDNTextfield.getText()));

                for (Worker worker : workers) {
                    try {
                        boolean removed = SignServerAdminGUIApplication.getAdminWS()
                                .removeAuthorizedClient(worker.getWorkerId(), oldAuthorizedClient);
                        if (removed) {
                            SignServerAdminGUIApplication.getAdminWS().addAuthorizedClient(worker.getWorkerId(),
                                    client);
                            SignServerAdminGUIApplication.getAdminWS()
                                    .reloadConfiguration(worker.getWorkerId());
                        }
                    } catch (AdminNotAuthorizedException_Exception ex) {
                        showAdminNotAuthorized(ex);
                    } catch (SOAPFaultException ex) {
                        showServerSideException(ex);
                    } catch (EJBException ex) {
                        showServerSideException(ex);
                    }
                }
                refreshButton.doClick();
            } catch (NumberFormatException e) {
                showMalformedSerialNumber(e);
            }
        }
    }
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java

/**
 * Save the settings, issuing warnings if needed.
 *
 * @param tryValidation attempt to validate if set to true, otherwise do not
 *
 * @return true if form ready to close, false otherwise
 *///from   w ww. j  a va  2  s  . c om
boolean saveAndValidateSettings(boolean tryValidation) {
    if (tryValidation) {
        try {
            validateRootDirectory();
        } catch (FolderDidNotValidateException ex) {
            JOptionPane.showMessageDialog(this,
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.BadRootFolder") + " " + ex.getMessage(),
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.BadFolderForInterestingFileExport"),
                    JOptionPane.OK_OPTION);
            return false;
        }

        try {
            validateReportDirectory();
        } catch (FolderDidNotValidateException ex) {
            JOptionPane.showMessageDialog(this,
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.BadReportFolder") + " " + ex.getMessage(),
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.BadFolderForInterestingFileExport"),
                    JOptionPane.OK_OPTION);
            return false;
        }

        if (hasRuleChanged()) {
            // if rule has changed without saving ask if we should save or discard
            if (JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(
                    WindowManager.getDefault().getMainWindow(),
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.ChangesWillBeLost")
                            + " "
                            + NbBundle.getMessage(FileExporterSettingsPanel.class,
                                    "FileExporterSettingsPanel.DoYouWantToSave"),
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.ChangesWillBeLost"),
                    JOptionPane.YES_NO_OPTION)) {
                saveOrUpdateRule();
            }
        }
    }
    store();
    return true;
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java

/**
 * Handles clicking the "Delete Rule" button.
 *
 * @param evt The event which caused this call.
 *///from  w  ww .  jav  a  2s  .c o m
private void bnDeleteRuleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnDeleteRuleActionPerformed
    Item item = (Item) ((DefaultMutableTreeNode) trRuleList.getLastSelectedPathComponent()).getUserObject();
    if (item != null) {
        if (item.getItemType() == ItemType.RULE) {
            String ruleName = item.getName();
            if (JOptionPane.showConfirmDialog(this,
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.ReallyDeleteRule")
                            + " " + ruleName
                            + NbBundle.getMessage(FileExporterSettingsPanel.class,
                                    "FileExporterSettingsPanel.QuestionMark"),
                    NbBundle.getMessage(FileExporterSettingsPanel.class,
                            "FileExporterSettingsPanel.ConfirmRuleDeletion"),
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE) == JOptionPane.OK_OPTION) {
                exportRuleSet.removeRule(ruleName);
                clearRuleEditor();
                localRule = makeRuleFromUserInput();
                populateRuleTree(ruleName);
            }
        }
    } else {
        logger.log(Level.WARNING, "Nothing selected to delete");
    }
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java

/**
 * Creates a rule from the rule editor components on the right side of the
 * panel.//from   w  ww.jav  a 2 s .  c o  m
 *
 * @param showFailures If there is a failure, shows the user a dialog box
 *                     with an explanation of why it failed.
 *
 * @return the rule created from the user's inputs.
 */
private Rule makeRuleFromUserInput(boolean showFailures) {
    String ruleName = tbRuleName.getText();
    Rule rule = new Rule(ruleName);

    FileSizeCondition fileSizeCondition = null;
    if (cbFileSize.isSelected()) {
        try {
            spFileSizeValue.commitEdit();
            fileSizeCondition = new Rule.FileSizeCondition((Integer) spFileSizeValue.getValue(),
                    SizeUnit.valueOf(comboBoxFileSizeUnits.getSelectedItem().toString()),
                    RelationalOp.fromSymbol(comboBoxFileSizeComparison.getSelectedItem().toString()));
        } catch (ParseException ex) {
            fileSizeCondition = null;
            logger.log(Level.WARNING, "Could not create size condition for rule %s: " + ruleName, ex); //NON-NLS
        }
    }

    FileMIMETypeCondition fileMIMETypeCondition = null;
    if (cbMimeType.isSelected()) {
        fileMIMETypeCondition = new Rule.FileMIMETypeCondition(comboBoxMimeValue.getSelectedItem().toString(),
                RelationalOp.fromSymbol(comboBoxMimeTypeComparison.getSelectedItem().toString()));
    }

    try {
        ArtifactCondition artifactCondition = getArtifactConditionFromInput(rule);

        if (fileSizeCondition != null) {
            rule.addFileSizeCondition(fileSizeCondition);
        }

        if (fileMIMETypeCondition != null) {
            rule.addFileMIMETypeCondition(fileMIMETypeCondition);
        }

        if (artifactCondition != null) {
            rule.addArtfactCondition(artifactCondition);
        }

        return rule;

    } catch (IllegalArgumentException ex) {
        String message = "Attribute value '" + tbAttributeValue.getText() + "' is not of type "
                + comboBoxValueType.getSelectedItem().toString() + ". Ignoring invalid Attribute Type clause.";
        logger.log(Level.INFO, message);
        if (showFailures) {
            JOptionPane.showMessageDialog(this, message, "Invalid Type Conversion", JOptionPane.OK_OPTION);
        }
        cbAttributeType.setSelected(false);
        return null;
    }
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.FileExporterSettingsPanel.java

/**
 * This method saves the rule from the editor to the tree, if the rule is
 * not malformed. This means the rule must have a name, and at least one
 * condition is selected. It updates any existing rule in the tree with the
 * same name.//w w  w .  j  a v  a  2s.  c o  m
 *
 */
void saveOrUpdateRule() {
    String ruleName = tbRuleName.getText();
    Rule userInputRule = makeRuleFromUserInput(true);
    if (userInputRule == null) { // we had bad input. do not continue.
        return;
    }
    if ((ruleName != null && !ruleName.isEmpty())
            && (cbFileSize.isSelected() || cbMimeType.isSelected() || cbAttributeType.isSelected())) {
        localRule = userInputRule;
        Rule existingRule = exportRuleSet.getRule(ruleName);
        if (existingRule == null) {
            // This is a new rule. Store it in the list and put it in the tree.
            List<ArtifactCondition> userRuleArtifactConditions = userInputRule.getArtifactConditions();
            for (ArtifactCondition artifactCondition : userRuleArtifactConditions) {
                String displayName = artifactCondition.getTreeDisplayName();
                artifactCondition.setTreeDisplayName(getArtifactClauseNameAndNumber(displayName, null));
            }
            exportRuleSet.addRule(userInputRule);
        } else {
            // Update an existing rule.
            exportRuleSet.removeRule(existingRule); // remove rule if it exists already, does nothing if it does not exist

            if (cbMimeType.isSelected()) {
                FileMIMETypeCondition fileMIMETypeCondition = userInputRule.getFileMIMETypeCondition();
                if (fileMIMETypeCondition != null) {
                    existingRule.addFileMIMETypeCondition(fileMIMETypeCondition);
                }
            } else {
                existingRule.removeFileMIMETypeCondition();
            }

            if (cbFileSize.isSelected()) {
                List<FileSizeCondition> fileSizeConditions = userInputRule.getFileSizeConditions();
                for (FileSizeCondition fileSizeCondition : fileSizeConditions) {
                    // Do not need to de-dupliate, as currently implmented in FileExportRuleSet
                    existingRule.addFileSizeCondition(fileSizeCondition);
                }
            } else {
                existingRule.removeFileSizeCondition();
            }

            if (cbAttributeType.isSelected()) {
                // for every artifact condition in the new rule, disambiguate the name
                List<ArtifactCondition> userRuleArtifactConditions = userInputRule.getArtifactConditions();
                for (ArtifactCondition artifactCondition : userRuleArtifactConditions) {
                    String displayName = artifactCondition.getTreeDisplayName();
                    String newName = getArtifactClauseNameAndNumber(displayName, existingRule);
                    artifactCondition.setTreeDisplayName(newName);
                    existingRule.addArtfactCondition(artifactCondition);
                }
                exportRuleSet.addRule(existingRule);

            } else {
                existingRule.removeArtifactConditions();
            }
            exportRuleSet.addRule(existingRule);
        }
        populateRuleTree(ruleName);
    } else {
        JOptionPane.showMessageDialog(null,
                NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.RuleNotSaved"),
                NbBundle.getMessage(FileExporterSettingsPanel.class, "FileExporterSettingsPanel.MalformedRule"),
                JOptionPane.OK_OPTION);
    }
}