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:nz.govt.natlib.ndha.manualdeposit.customizemetadata.CustomizeMetaDataForm.java

public boolean confirm(final String message, final boolean useYesNo) {
    int optionType;
    if (useYesNo) {
        optionType = JOptionPane.YES_NO_OPTION;
    } else {/*from   w w  w  .  j  ava2 s . c o  m*/
        optionType = JOptionPane.OK_CANCEL_OPTION;
    }
    return (JOptionPane.showConfirmDialog(this, message, "Please Confirm",
            optionType) == JOptionPane.YES_OPTION);
}

From source file:nz.govt.natlib.ndha.manualdeposit.login.Login.java

public boolean confirm(String message) {
    if (JOptionPane.showConfirmDialog(this, message, "Please Confirm",
            JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
        return true;
    } else {//from  w w  w  .  j a  v a 2 s  .  c om
        return false;
    }
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

public boolean confirm(String message, boolean useYesNo) {
    int optionType;
    if (useYesNo) {
        optionType = JOptionPane.YES_NO_OPTION;
    } else {//  ww w  . j a v  a 2 s.co m
        optionType = JOptionPane.OK_CANCEL_OPTION;
    }
    return (JOptionPane.showConfirmDialog(this, message, "Please Confirm",
            optionType) == JOptionPane.OK_OPTION);
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

private JPanel addStockPanelToolButtons() {
    JPanel panel = new JPanel();
    panel.setLayout(new MigLayout("insets 0 0 0 0, gapx 0"));
    List<Integer> editableColumns = new ArrayList<Integer>();
    editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION));
    editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE));
    editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.GENERATION));
    stockTablePanel.getTable().setEditableColumns(editableColumns);
    ;/*from ww w .ja v  a2  s.  c o m*/
    JButton importStockList = new JButton("Import Stocks By Search");
    JButton importHarvestGroup = new JButton("Import Stocks From Harvest Group");
    JPanel subPanel1 = new JPanel();
    subPanel1.setLayout(new MigLayout("insets 0 0 0 0, gapx 0"));
    subPanel1.add(importStockList, "gapRight 10");
    subPanel1.add(importHarvestGroup, "gapRight 10, wrap");
    panel.add(subPanel1, "gapLeft 10, spanx,wrap");
    importStockList.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            StocksInfoPanel stockInfoPanel = CreateStocksInfoPanel
                    .createStockInfoPanel("stock annotation popup");
            stockInfoPanel.setSize(new Dimension(500, 400));
            int option = JOptionPane.showConfirmDialog(null, stockInfoPanel, "Search Stock Packets",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            ArrayList<Integer> stockIds = new ArrayList<Integer>();

            if (option == JOptionPane.OK_OPTION) {
                DefaultTableModel model = (DefaultTableModel) stockTablePanel.getTable().getModel();
                CheckBoxIndexColumnTable stocksOutputTable = stockInfoPanel.getSaveTablePanel().getTable();
                for (int row = 0; row < stocksOutputTable.getRowCount(); ++row) {
                    int stockId = (Integer) stocksOutputTable.getValueAt(row,
                            stocksOutputTable.getIndexOf(ColumnConstants.STOCK_ID));
                    stockIds.add(stockId);
                }
                List<Stock> stocks = StockDAO.getInstance().getStocksByIds(stockIds);
                for (Stock stock : stocks) {
                    Object[] rowData = new Object[stockTablePanel.getTable().getColumnCount()];
                    rowData[0] = new Boolean(false);
                    Passport passport = stock.getPassport();
                    StockGeneration generation = stock.getStockGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_NAME)] = stock
                            .getStockName();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_ID)] = stock
                            .getStockId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.GENERATION)] = generation == null ? null
                                    : generation.getGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.PASSPORT_ID)] = passport == null ? null : passport.getPassportId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION)] = passport == null
                            ? null
                            : passport.getAccession_name();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE)] = passport == null
                            ? null
                            : passport.getPedigree();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_CODE)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationCode();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_ID)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.POPULATION)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getPopulation();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.TAXONOMY_ID)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getTaxonomyId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.MODIFIED)] = new Boolean(
                            false);
                    model.addRow(rowData);
                }

            }

        }

    });

    importHarvestGroup.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ArrayList<PMProject> projects = TokenRelationDAO.getInstance()
                    .findProjectObjects(LoginScreen.loginUserId);
            HashMap<String, Harvesting> name_tap = new HashMap<String, Harvesting>();
            for (PMProject project : projects) {
                List<HarvestingGroup> HarvestingGroups = HarvestingGroupDAO.getInstance()
                        .findByProjectid(project.getProjectId());
                for (HarvestingGroup hg : HarvestingGroups) {
                    Harvesting harvestingPanel = (Harvesting) getContext()
                            .getBean("Harvesting - " + project.getProjectId() + hg.getHarvestingGroupName());
                    name_tap.put(project.getProjectName() + "-" + hg.getHarvestingGroupName(), harvestingPanel);
                }

            }
            JPanel popup = new JPanel(new MigLayout("insets 0, gap 5"));
            JScrollPane jsp = new JScrollPane(popup) {
                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(250, 320);
                }
            };
            ButtonGroup group = new ButtonGroup();
            for (String name : name_tap.keySet()) {
                JRadioButton button = new JRadioButton(name);
                group.add(button);
                popup.add(button, "wrap");

                button.setSelected(true);
            }
            String selected_group = null;
            int option = JOptionPane.showConfirmDialog(null, jsp, "Select Harvesting Group Name: ",
                    JOptionPane.OK_CANCEL_OPTION);
            if (option == JOptionPane.OK_OPTION) {
                for (Enumeration<AbstractButton> buttons = group.getElements(); buttons.hasMoreElements();) {
                    AbstractButton button = buttons.nextElement();
                    if (button.isSelected()) {
                        selected_group = button.getText();

                    }
                }
            }
            if (selected_group != null) {
                Harvesting harvestingPanel = name_tap.get(selected_group);
                DefaultTableModel model = (DefaultTableModel) stockTablePanel.getTable().getModel();
                ArrayList<String> stocknames = harvestingPanel.getStickerGenerator().getCreatedStocks();
                List<Stock> stocks = StockDAO.getInstance().getStocksByNames(stocknames);
                for (Stock stock : stocks) {
                    Object[] rowData = new Object[stockTablePanel.getTable().getColumnCount()];
                    rowData[0] = new Boolean(false);
                    Passport passport = stock.getPassport();
                    StockGeneration generation = stock.getStockGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_NAME)] = stock
                            .getStockName();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_ID)] = stock
                            .getStockId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.GENERATION)] = generation == null ? null
                                    : generation.getGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.PASSPORT_ID)] = passport == null ? null : passport.getPassportId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION)] = passport == null
                            ? null
                            : passport.getAccession_name();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE)] = passport == null
                            ? null
                            : passport.getPedigree();

                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_CODE)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationCode();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_ID)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.POPULATION)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getPopulation();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.TAXONOMY_ID)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getTaxonomyId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.MODIFIED)] = new Boolean(
                            false);
                    model.addRow(rowData);
                }
            }

        }

    });
    getstockTablePanel().getTable().addFocusListener(new FocusAdapter() {
        public void focusLost(FocusEvent e) {
            int row = getstockTablePanel().getTable().getSelectionModel().getAnchorSelectionIndex();
            getstockTablePanel().getTable().setValueAt(true, row,
                    getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));
        }
    });
    JPanel subPanel2 = new JPanel();
    subPanel2.setLayout(new MigLayout("insets 0 0 0 0 , gapx 0"));
    subPanel2.add(new JLabel("Pedigree: "));
    this.pedigreeField = new JTextField(10);
    subPanel2.add(pedigreeField);
    JButton setPedigree = new JButton("set");
    setPedigree.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int row : getstockTablePanel().getTable().getSelectedRows()) {
                getstockTablePanel().getTable().setValueAt(pedigreeField.getText(), row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.PEDIGREE));
                getstockTablePanel().getTable().setValueAt(true, row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));
            }
        }
    });
    subPanel2.add(setPedigree, "gapRight 15");

    subPanel2.add(new JLabel("Accession: "));
    this.accessionField = new JTextField(10);
    subPanel2.add(accessionField);
    JButton setAccession = new JButton("set");
    setAccession.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int row : getstockTablePanel().getTable().getSelectedRows()) {
                getstockTablePanel().getTable().setValueAt(accessionField.getText(), row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.ACCESSION));
                getstockTablePanel().getTable().setValueAt(true, row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));

            }
        }
    });
    subPanel2.add(setAccession, "gapRight 15");

    subPanel2.add(new JLabel("Generarion: "));
    this.generarionField = new JTextField(10);
    subPanel2.add(generarionField);
    JButton setGeneration = new JButton("set");
    setGeneration.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int row : getstockTablePanel().getTable().getSelectedRows()) {
                getstockTablePanel().getTable().setValueAt(generarionField.getText(), row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.GENERATION));
                getstockTablePanel().getTable().setValueAt(true, row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));
            }
        }
    });
    subPanel2.add(setGeneration);

    panel.add(subPanel2, "gapLeft 10,spanx");
    return panel;

}

From source file:org.alex73.skarynka.scan.ui.scan.ScanDialogController.java

private ScanDialogController(PanelEditController panelController) {
    this.panelController = panelController;
    this.book = panelController.getBook();
    int currentZoom = DataStorage.device.getZoom();

    Dimension[] deviceImageSizes = DataStorage.device.getImageSize();
    Dimension imageSize = deviceImageSizes[0];
    for (int i = 1; i < deviceImageSizes.length; i++) {
        if (!imageSize.equals(deviceImageSizes[i])) {
            JOptionPane.showMessageDialog(DataStorage.mainFrame,
                    Messages.getString("ERROR_WRONG_NOTEQUALSSIZE"), Messages.getString("ERROR_TITLE"),
                    JOptionPane.ERROR_MESSAGE);
            return;
        }/*from  w  w  w.j a va 2  s .  c om*/
    }

    int pagesCount = book.getPagesCount();
    if (pagesCount > 0) {
        int bookZoom = book.zoom;

        if (bookZoom != currentZoom) {
            if (JOptionPane.showConfirmDialog(DataStorage.mainFrame,
                    Messages.getString("ERROR_WRONG_ZOOM", pagesCount, bookZoom, currentZoom),
                    Messages.getString("ERROR_TITLE"), JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
                return;
            }
        }
        if (imageSize.width != book.imageSizeX || imageSize.height != book.imageSizeY) {
            if (JOptionPane.showConfirmDialog(DataStorage.mainFrame,
                    Messages.getString("ERROR_WRONG_IMAGESIZE", pagesCount,
                            s(new Dimension(book.imageSizeX, book.imageSizeY)), s(imageSize)),
                    Messages.getString("ERROR_TITLE"), JOptionPane.OK_CANCEL_OPTION,
                    JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION) {
                return;
            }
            for (String page : book.listPages()) {
                Book2.PageInfo pi = book.getPageInfo(page);
                pi.cropPosX = Integer.MIN_VALUE;
                pi.cropPosY = Integer.MIN_VALUE;
            }
        }
    }

    book.zoom = currentZoom;
    book.imageSizeX = imageSize.width;
    book.imageSizeY = imageSize.height;
    String dpi = Context.getSettings().get("dpi." + book.zoom);
    if (dpi != null) {
        book.dpi = Integer.parseInt(dpi);
    } else {
        book.dpi = 300;
    }

    dialog = new ScanDialog(DataStorage.mainFrame, true);
    dialog.btnClose.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    dialog.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            DataStorage.device.setPreviewPanels();
            panelController.show();
        }
    });

    init(dialog.controlLeft, dialog.liveLeft);
    init(dialog.controlRight, dialog.liveRight);

    checkNumbers();
    showStatus();

    boolean[] visible = DataStorage.device.setPreviewPanels(dialog.liveLeft, dialog.liveRight);
    dialog.controlLeft.setVisible(visible[0]);
    dialog.controlRight.setVisible(visible[1]);
    dialog.liveLeft.setVisible(visible[0]);
    dialog.liveRight.setVisible(visible[1]);

    int[] rotations = DataStorage.device.getRotations();
    dialog.liveLeft.setRotation(rotations[0]);
    dialog.liveRight.setRotation(rotations[1]);

    dialog.setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
    dialog.validate();
    dialog.controlLeft.txtNumber.setVisible(false);
    dialog.controlLeft.txtNumber.setVisible(false);

    int keyCode = HIDScanController.getKeyCode(Context.getSettings().get("hidscan-keys"));
    if (keyCode != 0) {
        addAction(keyCode, actionScan);
    }
    if (keyCode != KeyEvent.VK_F1) {
        addAction(KeyEvent.VK_F1, actionScan);
    }
    dialog.btnScan.addActionListener(actionScan);
    addAction(KeyEvent.VK_F2, actionRescan);
    dialog.btnRescan.addActionListener(actionRescan);

    dialog.setVisible(true);
}

From source file:org.broad.igv.ui.action.SetTrackHeightMenuAction.java

/**
 * Method description/*from  ww  w .  j  ava 2s  .  c o m*/
 */
final public void doSetTrackHeight() {

    boolean doRefresh = false;
    try {
        JPanel container = new JPanel();
        JLabel trackHeightLabel = new JLabel("Track Height (pixels)");
        JTextField trackHeightField = new JTextField();
        Dimension preferredSize = trackHeightField.getPreferredSize();
        trackHeightField.setPreferredSize(new Dimension(50, (int) preferredSize.getHeight()));
        container.add(trackHeightLabel);
        container.add(trackHeightField);

        int repTrackHeight = getRepresentativeTrackHeight();
        trackHeightField.setText(String.valueOf(repTrackHeight));

        int status = JOptionPane.showConfirmDialog(mainFrame.getMainFrame(), container, "Set Track Height",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null);

        if ((status == JOptionPane.CANCEL_OPTION) || (status == JOptionPane.CLOSED_OPTION)) {
            return;
        }

        try {
            int newTrackHeight = Integer.parseInt(trackHeightField.getText().trim());
            IGV.getInstance().setAllTrackHeights(newTrackHeight);
            lastTrackHeight = newTrackHeight;
            doRefresh = true;
        } catch (NumberFormatException numberFormatException) {
            JOptionPane.showMessageDialog(mainFrame.getMainFrame(), "Track height must be an integer number.");
        }

    } finally {

        // Refresh view
        if (doRefresh) {

            // Update the state of the current tracks for drawing purposes

            mainFrame.doRefresh();
        }
        mainFrame.resetStatusMessage();
    }

}

From source file:org.colombbus.tangara.CommandSelection.java

private boolean userConfirmOverride(File destinationFile) {
    String title;/*from  w  w  w .j  a v  a  2  s  .c  om*/
    String pattern;
    if (mode == MODE_PROGRAM_CREATION) {
        title = Messages.getString("CommandSelection.programCreation.override.title");
        pattern = Messages.getString("CommandSelection.programCreation.override.message");
    } else {
        title = Messages.getString("CommandSelection.fileCreation.override.title");
        pattern = Messages.getString("CommandSelection.fileCreation.override.message");
    }
    String message = MessageFormat.format(pattern, destinationFile.getName());
    Object[] options = { Messages.getString("tangara.yes"), Messages.getString("tangara.cancel") };
    int optionType = JOptionPane.OK_CANCEL_OPTION;
    int messageType = JOptionPane.QUESTION_MESSAGE;
    Icon icon = null;
    int answer = JOptionPane.showOptionDialog(this, message, title, optionType, messageType, icon, options,
            options[0]);
    return answer == JOptionPane.OK_OPTION;
}

From source file:org.colombbus.tangara.net.FileReceptionDialog.java

/**
 * This method initializes this/*ww w  .j  a  v a2  s.c  o m*/
 * 
 */
public void setVisible() {
    final String[] options = { Messages.getString("FileReceptionDialog.saveButton"),
            Messages.getString("FileReceptionDialog.cancelButton") };
    final String title = Messages.getString("FileReceptionDialog.title");
    final int optionType = JOptionPane.OK_CANCEL_OPTION;
    final int messageType = JOptionPane.QUESTION_MESSAGE;
    final Icon icon = null;

    int choosenOption = JOptionPane.showOptionDialog(owner, message, title, optionType, messageType, icon,
            options, options[0]);
    if (choosenOption == JOptionPane.OK_OPTION)
        setTargetFile();
}

From source file:org.colombbus.tangara.net.FileReceptionDialog.java

private void setTargetFile() {
    File targetDir = Configuration.instance().getUserHome();
    JFileChooser chooserDlg = new JFileChooser(targetDir);

    String filterMsg = Messages.getString("FileReceptionDialog.filter.allFiles");
    SimpleFileFilter filter = new SimpleFileFilter(filterMsg);
    chooserDlg.setFileFilter(filter);/*from ww  w .java2 s  .  co m*/

    File originalSelFile = new File(targetDir, sourceFilename);
    File curSelFile = originalSelFile;
    boolean showDialog = true;
    while (showDialog) {
        chooserDlg.setSelectedFile(curSelFile);
        int userAction = chooserDlg.showSaveDialog(owner);
        curSelFile = chooserDlg.getSelectedFile();
        switch (userAction) {
        case JFileChooser.CANCEL_OPTION:
            showDialog = false;
            break;
        case JFileChooser.APPROVE_OPTION:
            if (curSelFile.exists()) {
                String title = Messages.getString("FileReceptionDialog.overwrite.title");
                String msgPattern = Messages.getString("FileReceptionDialog.overwrite.message");
                String overwriteMsg = MessageFormat.format(msgPattern, curSelFile.getName());
                Object[] options = { Messages.getString("FileReceptionDialog.yes"),
                        Messages.getString("FileReceptionDialog.no") };
                int userChoice = JOptionPane.showOptionDialog(owner, overwriteMsg, title,
                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, // do not use a
                        // custom Icon
                        options, // the titles of buttons
                        options[0]);
                if (userChoice == JOptionPane.OK_OPTION) {
                    if (saveFileAs(curSelFile)) {
                        showDialog = false;
                    }
                }
            } else if (saveFileAs(curSelFile)) {
                showDialog = false;
            }
            break;
        case JFileChooser.ERROR_OPTION:
            LOG.error("Error in file chooser dialog");
            // TODO what to do in case of error ? Retry ?
            showDialog = false;
            break;
        }
    }
}

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

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

        return openAnalysisJob(file, ajb);
    } catch (NoSuchComponentException e) {
        final String message;
        if (Version.EDITION_COMMUNITY.equals(Version.getEdition())) {
            message = "<html><p>Failed to open job because of a missing component:</p><pre>" + e.getMessage()
                    + "</pre>"
                    + "<p>This may happen if the job requires a <a href=\"http://datacleaner.org/editions\">Commercial Edition of DataCleaner</a>, or an extension that you do not have installed.</p></html>";
        } else {
            message = "<html>Failed to open job because of a missing component: " + e.getMessage()
                    + "<br/><br/>"
                    + "This may happen if the job requires an extension that you do not have installed.</html>";
        }
        WidgetUtils.showErrorMessage("Cannot open job", message);

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

        final AnalysisJobMetadata metadata = reader.readMetadata(file);
        final 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;
    } catch (ComponentConfigurationException e) {
        final String message;
        final Throwable cause = e.getCause();
        if (cause != null) {
            // check for causes of the mis-configuration. If there's a cause
            // with a message, then show the message first and foremost
            // (usually a validation error).
            if (!Strings.isNullOrEmpty(cause.getMessage())) {
                message = cause.getMessage();
            } else {
                message = e.getMessage();
            }
        } else {
            message = e.getMessage();
        }

        WidgetUtils.showErrorMessage("Failed to validate job configuration", message, e);
        return null;
    } catch (RuntimeException e) {
        logger.error("Unexpected failure when opening job: {}", file, e);
        throw e;
    }
}