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.archiviststoolkit.mydomain.DomainTableWorkSurface.java

private void finishOnUpdate() {
    done = false;/*from ww  w . jav a2  s  .c  om*/
    while (!done) {
        if (debug) {
            System.out.println("Thread: " + Thread.currentThread());
        }

        // check to see if the record is not locked
        RecordLocks recordLock = isRecordLocked(currentDomainObject);
        if (recordLock != null) {
            // ask the user if the want to open record read only
            if (!openRecordReadOnly(recordLock)) {
                break;
            } else {
                dialog.setReadOnly(true); // not sure what this those
            }
        }

        if (dialog.showDialog() == javax.swing.JOptionPane.OK_OPTION) {
            int choice = dialog.getConfirmDialogReturn();

            if (choice == JOptionPane.YES_OPTION) {
                saveRecord();
                //wait for the save record to complete
                try {
                    performer.join();
                } catch (InterruptedException e) {
                    new ErrorDialog("", e).showDialog();
                }
            }
        } else if (dialog.getConfirmDialogReturn() == JOptionPane.YES_OPTION) { // called when window is closed and data validated
            saveRecord();
            //wait for the save record to complete
            try {
                performer.join();
            } catch (InterruptedException e) {
                new ErrorDialog("", e).showDialog();
            }
            done = true;
        } else if (dialog.getConfirmDialogReturn() == StandardEditor.NO_SAVE_OPTION) {
            try {
                access.closeLongSessionRollback();
                setSublistWithCurrentDomainObject(); // call this to update the display
            } catch (SQLException e) {
                new ErrorDialog(dialog, "Error canceling record.", e).showDialog();
            }
            done = true;
        } else { // No Option was selected so roll back changes
            done = true;
            try {
                access.closeLongSessionRollback();
            } catch (SQLException e) {
                new ErrorDialog(dialog, "Error canceling record.", e).showDialog();
            }
        }

        // Remove any locks created while accessing record and set to read only false
        clearCurrentRecordLock();
        dialog.setReadOnly(false);
    }
}

From source file:org.archiviststoolkit.mydomain.DomainTableWorkSurface.java

/**
 * on insert display a blank editor and insert the results.
 *//*from   www.  j  a v a  2s.  c o  m*/

public final void onInsert() {
    // see if to load a plugin editor instead of using the one built into the AT
    if (usePluginDomainEditor(null, null)) {
        return; // custom editor was used to view/edit this record so just return
    }

    ApplicationFrame.editorOpen = true;

    Object instance = null;
    boolean done = false;
    boolean createNewInstance = true;
    DomainEditor dialog = DomainEditorFactory.getInstance().getDialog(clazz);
    dialog.disableNavigationButtons();
    dialog.clearRecordPositionText();
    dialog.setNewRecord(true);
    int returnStatus;

    while (!done) {
        boolean createObject = true;
        if (createNewInstance) {
            try {
                instance = clazz.newInstance();
            } catch (InstantiationException instantiationException) {
                new ErrorDialog(dialog, "Error creating new record.", instantiationException).showDialog();
            } catch (IllegalAccessException illegalAccessException) {
                new ErrorDialog(dialog, "Error creating new record.", illegalAccessException).showDialog();
            }
            if (clazz == Names.class) {
                String nameType = Names.selectNameType(rootComponent);
                if ((nameType != null) && (nameType.length() > 0)) {
                    ((Names) instance).setNameType(nameType);
                } else {
                    createObject = false;
                    done = true;
                }

            } else if (clazz == Accessions.class) {
                ((Accessions) instance)
                        .setRepository(ApplicationFrame.getInstance().getCurrentUserRepository());
            } else if (clazz == Resources.class) {
                ((Resources) instance).setRepository(ApplicationFrame.getInstance().getCurrentUserRepository());
                ((Resources) instance).markRecordAsNew();
            } else if (clazz == DigitalObjects.class) {
                ((DigitalObjects) instance)
                        .setRepository(ApplicationFrame.getInstance().getCurrentUserRepository());
            }
        } else {
            createNewInstance = true;
        }

        if (createObject) {

            dialog.setModel((DomainObject) instance, null);
            returnStatus = dialog.showDialog();
            int choice = dialog.getConfirmDialogReturn();
            Boolean savedNewRecord = dialog.getSavedNewRecord();

            try {
                if (returnStatus == javax.swing.JOptionPane.OK_OPTION) {
                    if (choice == JOptionPane.YES_OPTION) {
                        DomainAccessObject access = DomainAccessObjectFactory.getInstance()
                                .getDomainAccessObject(clazz);
                        if (!savedNewRecord) {
                            access.add((DomainObject) instance);
                        } else { // just update the record
                            access.updateLongSession((DomainObject) instance);
                        }

                        table.getEventList().add((DomainObject) instance);
                        updateRowCount();
                        addToPickers((DomainObject) instance);
                        done = true;
                    }
                } else if (returnStatus == StandardEditor.OK_AND_ANOTHER_OPTION) {
                    DomainAccessObject access = DomainAccessObjectFactory.getInstance()
                            .getDomainAccessObject(clazz);
                    if (!savedNewRecord) {
                        access.add(dialog.getModel());
                    } else {
                        access.updateLongSession((DomainObject) instance);
                    }
                    table.getEventList().add((DomainObject) instance);
                    updateRowCount();
                    addToPickers((DomainObject) instance);
                    dialog.setNewRecord(true);
                } else if (choice == JOptionPane.YES_OPTION) { // called when window is closed and data validated
                    DomainAccessObject access = DomainAccessObjectFactory.getInstance()
                            .getDomainAccessObject(clazz);
                    if (!savedNewRecord) {
                        access.add((DomainObject) instance);
                    } else {
                        access.updateLongSession((DomainObject) instance);
                    }

                    table.getEventList().add((DomainObject) instance);
                    updateRowCount();
                    addToPickers((DomainObject) instance);
                    done = true;
                } else if (choice == JOptionPane.NO_OPTION) {
                    if (savedNewRecord) { // already saved a new record so remove it
                        try {
                            DomainAccessObject access = DomainAccessObjectFactory.getInstance()
                                    .getDomainAccessObject(clazz);
                            access.closeLongSessionRollback();
                        } catch (SQLException e) {
                            new ErrorDialog(dialog, "Error canceling record.", e).showDialog();
                        }

                        //table.getEventList().add((DomainObject) instance);
                        long id = ((DomainObject) instance).getIdentifier();
                        table.getEventList().add(getSimpleDomainObject(id));
                        updateRowCount();
                        addToPickers((DomainObject) instance);
                    }
                    done = true;
                } else {
                    done = true;
                }

                // reset the savedNew field to false;
                dialog.setSavedNewRecord(false);

                // remove any record locks that may have been created
                clearCurrentRecordLock();
            } catch (ConstraintViolationException persistenceException) {
                String message = "Can't save, duplicate record " + instance;
                JOptionPane.showMessageDialog(ApplicationFrame.getInstance(), message);
                logger.error(message, persistenceException);
                ((DomainObject) instance).removeIdAndAuditInfo();
                createNewInstance = false;
            } catch (PersistenceException persistenceException) {
                if (persistenceException.getCause() instanceof ConstraintViolationException) {
                    String message = "Can't save, duplicate record " + instance;
                    JOptionPane.showMessageDialog(ApplicationFrame.getInstance(), message);
                    logger.error(message, persistenceException);
                    ((DomainObject) instance).removeIdAndAuditInfo();
                    createNewInstance = false;
                } else {
                    done = true;
                    new ErrorDialog(dialog, "Error saving new record.", persistenceException).showDialog();
                }
            } /*catch (DeleteException deleteException) {
              done = true;
              new ErrorDialog(dialog, "Error deleting saved record.", deleteException).showDialog();
              }*/
        }
    }
    dialog.setNewRecord(false);

    ApplicationFrame.editorOpen = false;
}

From source file:org.archiviststoolkit.mydomain.DomainTableWorkSurface.java

public void onSearch() {

    try {//from   ww w . j av  a 2 s  .  c  o m
        final DomainAccessObject access = DomainAccessObjectFactory.getInstance().getDomainAccessObject(clazz);
        final QueryEditor dialog = DomainEditorFactory.getInstance().getSearchDialog(clazz);

        if (dialog.showDialog() == javax.swing.JOptionPane.OK_OPTION) {
            Thread performer = new Thread(new Runnable() {
                public void run() {
                    InfiniteProgressPanel monitor = ATProgressUtil
                            .createModalProgressMonitor(ApplicationFrame.getInstance(), 0);
                    monitor.start("Performing search...");
                    try {
                        Collection results = access.findByQueryEditor(dialog, monitor);
                        monitor.close();
                        humanReadableSearchString = access.getHumanReadableSearchString();
                        updateListWithNewResultSet(results);
                        monitor.close();
                    } catch (LookupException e) {
                        monitor.close();
                        new ErrorDialog(ApplicationFrame.getInstance(), "Error searching.", e).showDialog();
                    } finally {
                        monitor.close();
                    }
                }
            }, "Search");
            performer.start();
        }

    } catch (PersistenceException e) {
        new ErrorDialog(ApplicationFrame.getInstance(), "Error searching.", e).showDialog();
    }
}

From source file:org.archiviststoolkit.mydomain.DomainTableWorkSurface.java

public void merge() {
    int[] selectedRows = table.getSelectedRows();
    if (selectedRows.length < 2) {
        JOptionPane.showMessageDialog(ApplicationFrame.getInstance(),
                "You must select at least 2 records to merge");
    } else {//from  w w w .  j  av a 2s. c  om
        Vector<DomainObject> selectedDomainObjects = new Vector<DomainObject>();
        for (int loop = 0; loop < selectedRows.length; loop++) {
            selectedDomainObjects.add(table.getFilteredList().get(selectedRows[loop]));
        }

        SelectFromTable dialog = new SelectFromTable(clazz, ApplicationFrame.getInstance(),
                "Select an item to merge into", selectedDomainObjects);
        if (dialog.showDialog() == JOptionPane.OK_OPTION) {

            DomainAccessObject dao;
            if (clazz == Names.class) {
                dao = new NamesDAO();
                mergeRecords(dialog, selectedDomainObjects, dao);
            } else if (clazz == Subjects.class) {
                dao = new SubjectsDAO();
                mergeRecords(dialog, selectedDomainObjects, dao);
            } else if (clazz == Resources.class) {
                dao = new ResourcesDAO();
                mergeRecords(dialog, selectedDomainObjects, dao);
            }
        }
    }
}

From source file:org.bimserver.client.Client.java

public void checkin(SProject project, DataSource dataSource, long fileSize) {
    String comment = JOptionPane.showInputDialog(Client.this, "Please give a short description of your changes",
            "Checkin", JOptionPane.OK_OPTION | JOptionPane.INFORMATION_MESSAGE);
    try {//from  w w w  .  j av a 2 s  . co m
        DataHandler ifcFile = new DataHandler(dataSource);
        int checkinId = serviceHolder.getService().checkin(project.getOid(), comment, "TODO", fileSize, ifcFile,
                false, true);
        SCheckinResult sCheckinResult = serviceHolder.getService().getCheckinState(checkinId);
        JOptionPane.showMessageDialog(this, "New revision number: " + sCheckinResult.getRevisionId(),
                "Checkin successful", JOptionPane.OK_OPTION | JOptionPane.INFORMATION_MESSAGE);
        revisionPanel.showProject(project);
    } catch (ServiceException e) {
        JOptionPane.showMessageDialog(this, e.getUserMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.bimserver.client.Client.java

void checkout(SRevision revision, OutputStream out, boolean report) {
    try {/* ww  w.ja v a 2s  . co m*/
        SProject sProject = serviceHolder.getService().getProjectByPoid(revision.getProjectId());
        int longCheckoutActionId = serviceHolder.getService().checkout(revision.getOid(), "IFC", true);
        SDownloadResult checkout = serviceHolder.getService().getDownloadData(longCheckoutActionId);
        try {
            InputStream inputStream = checkout.getFile().getInputStream();
            byte[] buffer = new byte[1024];
            int red = inputStream.read(buffer);
            int totalRed = 0;
            while (red != -1) {
                out.write(buffer, 0, red);
                totalRed += red;
                red = inputStream.read(buffer);
            }
            out.close();
            if (report) {
                JOptionPane.showMessageDialog(Client.this,
                        "Revision: " + revision.getOid() + "\n" + totalRed + " bytes written",
                        "Checkout successfull", JOptionPane.OK_OPTION | JOptionPane.INFORMATION_MESSAGE);
            }
            SProject project = new SProject();
            project.setName(sProject.getName());
            checkoutsPanel.showProject(project);
        } catch (IOException e) {
            LOGGER.error("", e);
        }
    } catch (ServiceException e) {
        LOGGER.error("", e);
    }
}

From source file:org.bimserver.client.Client.java

public void download(long roid, FileOutputStream out, boolean report) {
    try {//from   ww  w.j ava  2 s  .c om
        int downloadId = serviceHolder.getService().download(roid, "IFC", true, true);
        SDownloadResult download = serviceHolder.getService().getDownloadData(downloadId);
        try {
            InputStream inputStream = download.getFile().getInputStream();
            IOUtils.copy(inputStream, out);
            out.close();
            if (report) {
                JOptionPane.showMessageDialog(Client.this, "Revision: " + download.getRevisionNr() + "\n",
                        "Download successfull", JOptionPane.OK_OPTION | JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (IOException e) {
            LOGGER.error("", e);
        }
    } catch (ServiceException e) {
        LOGGER.error("", e);
    }
}

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

private boolean userConfirmOverride(File destinationFile) {
    String title;// www .j a va  2s  . co  m
    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.EditorFrame.java

private boolean userConfirmFileOverride(File destinationFile) {
    String messagePattern = Messages.getString("EditorFrame.program.override.message"); //$NON-NLS-1$
    String message = MessageFormat.format(messagePattern, destinationFile.getName());
    String title = Messages.getString("EditorFrame.program.override.title"); //$NON-NLS-1$
    Object[] options = { Messages.getString("tangara.yes"), Messages.getString("tangara.cancel") }; //$NON-NLS-1$ //$NON-NLS-2$
    Icon icon = null;/*w w w . j  a  v a  2  s  . co  m*/
    int messageType = JOptionPane.QUESTION_MESSAGE;
    int answer = JOptionPane.showOptionDialog(EditorFrame.this, message, title, optionType, messageType, icon,
            options, options[0]);
    return answer == JOptionPane.OK_OPTION;
}

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

/**
 * Quit Tangara (close the window and the program).
 *
 *///w w  w. ja v a 2s .c  o  m
public void exit() {
    graphicsPane.freeze(true);
    String title = Messages.getString("EditorFrame.exit.title"); //$NON-NLS-1$
    String message = Messages.getString("EditorFrame.exit.message"); //$NON-NLS-1$
    Object[] options = { Messages.getString("tangara.yes"), //$NON-NLS-1$
            Messages.getString("tangara.cancel") }; //$NON-NLS-1$
    int answer = JOptionPane.showOptionDialog(this, message, title, optionType, JOptionPane.QUESTION_MESSAGE,
            null, // do not use a custom Icon
            options, // the titles of buttons
            options[0]);

    if (answer == JOptionPane.OK_OPTION) {
        if (getProgramManager().checkProgramChanged()) {
            dispose();
            Program.instance().exit();
        }
    } else
        graphicsPane.freeze(false);
}