Example usage for javax.swing JOptionPane QUESTION_MESSAGE

List of usage examples for javax.swing JOptionPane QUESTION_MESSAGE

Introduction

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

Prototype

int QUESTION_MESSAGE

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

Click Source Link

Document

Used for questions.

Usage

From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java

/**
 * @return/*from  w  w  w  . j  a v  a2s.c  o  m*/
 */
public CollectionResultType initialize() {

    collectionInfoList = CollectionInfo.getCollectionInfoList(oldDBConn, false);
    //fixIdaho();
    if (collectionInfoList == null) {
        if (CollectionInfo.isAskForFix()) {
            if (ConvertTaxonHelper.fixTaxonomicUnitType(oldDBConn)) {
                collectionInfoList = CollectionInfo.getCollectionInfoList(oldDBConn, true);
            } else {
                try {
                    oldDBConn.close();
                } catch (SQLException e) {
                }
                System.exit(0);
            }
        } else {
            try {
                oldDBConn.close();
            } catch (SQLException e) {
            }
            System.exit(0);
        }
    }

    collectionInfoShortList = CollectionInfo.getFilteredCollectionInfoList();

    if (collectionInfoList != null && collectionInfoList.size() > 0) {
        int paleoCnt = 0;

        // This is a Hash of TaxonObjectType to see how many collections use the same TaxonObjectType
        HashMap<Integer, HashSet<CollectionInfo>> taxonomyTypeHash = new HashMap<Integer, HashSet<CollectionInfo>>();

        // Get a List for each type of Paleo Collection, hashed by the Root Id
        HashMap<Integer, Vector<CollectionInfo>> paleoColInfoHash = new HashMap<Integer, Vector<CollectionInfo>>();
        HashMap<Integer, HashSet<DisciplineType.STD_DISCIPLINES>> paleoDispTypeHash = new HashMap<Integer, HashSet<DisciplineType.STD_DISCIPLINES>>();

        for (CollectionInfo colInfo : collectionInfoShortList) {
            // Tracks a 'set' of CollectionInfo objects for each TaxonomyTypeId
            HashSet<CollectionInfo> taxonomyTypeSet = taxonomyTypeHash.get(colInfo.getTaxonomyTypeId());
            if (taxonomyTypeSet == null) {
                System.out.println("Creating TxTypeID: " + colInfo.getTaxonomyTypeId() + "  From "
                        + colInfo.getCatSeriesName());

                taxonomyTypeSet = new HashSet<CollectionInfo>();
                taxonomyTypeHash.put(colInfo.getTaxonomyTypeId(), taxonomyTypeSet);
            } else {
                System.out.println("Adding TxTypeID: " + colInfo.getTaxonomyTypeId() + "  From "
                        + colInfo.getCatSeriesName() + "  " + taxonomyTypeSet.size());
            }
            taxonomyTypeSet.add(colInfo);

            //---
            DisciplineType dType = getStandardDisciplineName(colInfo.getTaxonomyTypeName(),
                    colInfo.getColObjTypeName(), colInfo.getCatSeriesName());
            colInfo.setDisciplineTypeObj(dType);

            if (dType != null && dType.isPaleo()) {
                Vector<CollectionInfo> ciList = paleoColInfoHash.get(colInfo.getTaxonNameId());
                if (ciList == null) {
                    ciList = new Vector<CollectionInfo>();
                    paleoColInfoHash.put(colInfo.getTaxonNameId(), ciList);
                }
                ciList.add(colInfo);

                HashSet<DisciplineType.STD_DISCIPLINES> typeDispSet = paleoDispTypeHash
                        .get(colInfo.getTaxonNameId());
                if (typeDispSet == null) {
                    typeDispSet = new HashSet<DisciplineType.STD_DISCIPLINES>();
                    paleoDispTypeHash.put(colInfo.getTaxonNameId(), typeDispSet);
                }
                typeDispSet.add(colInfo.getDisciplineTypeObj().getDisciplineType());

                paleoCnt++;
            }
            System.out.println("--------------------------------------");
            //System.out.println(colInfo.toString()+"\n");
        } // for loop

        int cnt = 0;
        StringBuilder msg = new StringBuilder();
        for (Integer taxonomyTypId : taxonomyTypeHash.keySet()) {
            HashSet<CollectionInfo> taxonomyTypeSet = taxonomyTypeHash.get(taxonomyTypId);
            if (taxonomyTypeSet.size() > 1) {
                msg.append(
                        String.format("<html>TaxonomyTypeId %d has more than one Discpline/Collection:<br><OL>",
                                taxonomyTypId));
                for (CollectionInfo ci : taxonomyTypeSet) {
                    msg.append(String.format("<LI>%s - %s - %s</LI>", ci.getCatSeriesName(),
                            ci.getColObjTypeName(), ci.getTaxonomyTypeName()));
                }
                msg.append("</OL>");
                cnt++;
            }
        }

        if (cnt > 0) {
            JOptionPane.showConfirmDialog(null, msg.toString(), "Taxomony Type Issues",
                    JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE);
        }

        // Will be zero for no Paleo collections
        if (paleoCnt > 1) {
            // Check to see if they all use the same tree
            if (paleoColInfoHash.size() > 1) {
                msg.setLength(0);
                // We get here when there is more than one Taxon Tree for the Paleo Collections
                for (Integer treeId : paleoColInfoHash.keySet()) {
                    Vector<CollectionInfo> ciList = paleoColInfoHash.get(treeId);
                    CollectionInfo colInfo = ciList.get(0);
                    msg.append(String.format("The following collections use Taxon Tree '%s':\n",
                            colInfo.getTaxonomyTypeName()));
                    for (CollectionInfo ci : paleoColInfoHash.get(treeId)) {
                        DisciplineType dType = getStandardDisciplineName(ci.getTaxonomyTypeName(),
                                ci.getColObjTypeName(), ci.getCatSeriesName());

                        String name = String.format("%s / %s / %s / %s / %s", ci.getCatSeriesPrefix(),
                                ci.getCatSeriesName(), ci.getColObjTypeName(), ci.getTaxonomyTypeName(),
                                dType.toString());
                        msg.append(name);
                        msg.append("\n");
                    }
                    msg.append("\n");
                }

                JOptionPane.showConfirmDialog(null, msg.toString(), "Paleo Taxon Tree Issues",
                        JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE);

            } else {
                StringBuilder colNames = new StringBuilder();
                for (Integer treeId : paleoColInfoHash.keySet()) {
                    for (CollectionInfo ci : paleoColInfoHash.get(treeId)) {
                        colNames.append("<LI>");
                        colNames.append(ci.getCatSeriesName());
                        colNames.append("</LI>");
                    }
                }

                // You get here when all the Paleo Disciplines use the same tree
                String msgStr = "<html>All the Paleo Collections need to use the same Taxon Tree and<br>therefore needs to be in the same discipline:<br><ol>";
                JOptionPane.showConfirmDialog(null, msgStr + colNames.toString(), "Paleo Taxon Tree Issues",
                        JOptionPane.CLOSED_OPTION, JOptionPane.QUESTION_MESSAGE);

                for (Integer treeId : paleoColInfoHash.keySet()) {
                    Vector<CollectionInfo> ciList = paleoColInfoHash.get(treeId);
                    CollectionInfo colInfo = ciList.get(0);
                    for (CollectionInfo ci : paleoColInfoHash.get(treeId)) {
                        ci.setDisciplineTypeObj(colInfo.getDisciplineTypeObj());
                    }
                }
            }
            //
        }

        DefaultTableModel model = CollectionInfo.getCollectionInfoTableModel(false);
        if (model.getRowCount() > 1) {
            TableWriter colInfoTblWriter = convLogger.getWriter("colinfo.html", "Collection Info");

            colInfoTblWriter.startTable();
            colInfoTblWriter.logHdr(CollectionInfoModel.getHeaders());

            Object[] row = new Object[model.getColumnCount()];
            for (int r = 0; r < model.getRowCount(); r++) {
                for (int i = 0; i < model.getColumnCount(); i++) {
                    row[i] = model.getValueAt(r, i);
                }
                colInfoTblWriter.logObjRow(row);
            }
            colInfoTblWriter.endTable();
            colInfoTblWriter.println("<BR><h3>Collections to be Created.</h3>");
            colInfoTblWriter.startTable();
            colInfoTblWriter.logHdr(CollectionInfoModel.getHeaders());

            model = CollectionInfo.getCollectionInfoTableModel(true);
            row = new Object[model.getColumnCount()];
            for (int r = 0; r < model.getRowCount(); r++) {
                for (int i = 0; i < model.getColumnCount(); i++) {
                    row[i] = model.getValueAt(r, i);
                }
                colInfoTblWriter.logObjRow(row);
            }
            colInfoTblWriter.endTable();
            colInfoTblWriter.close();

            File file = new File(colInfoTblWriter.getFileName());
            if (file != null && file.exists()) {
                try {
                    AttachmentUtils.openURI(file.toURI());

                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }

        for (CollectionInfo ci : CollectionInfo.getFilteredCollectionInfoList()) {
            String sql = "select preparationmethod, ct.* from usyscollobjprepmeth pt inner join usysmetafieldsetsubtype st on st.fieldsetsubtypeid = pt.fieldsetsubtypeid "
                    + "inner join collectionobjecttype ct1 on ct1.collectionobjecttypeid = st.fieldvalue "
                    + "inner join collectionobjecttype ct on ct.collectionobjecttypename = replace(ct1.collectionobjecttypename, ' Preparation', '') "
                    + "inner join catalogseriesdefinition csd on csd.objecttypeid = ct.collectionobjecttypeid "
                    + "inner join catalogseries cs on cs.catalogseriesid = csd.catalogseriesid "
                    + "WHERE csd.catalogseriesid = " + ci.getCatSeriesId();

            System.out.println("\n------------------");
            System.out.println(ci.getCatSeriesName());
            System.out.println(sql);
            System.out.println("------------------");

            int i = 0;
            Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql);
            if (list.size() > 0) {
                for (Object[] row : list) {
                    System.out.print(i + " - ");
                    for (Object col : row) {
                        System.out.print(col != null ? col.toString() : "null");
                        System.out.print(", ");
                    }
                    System.out.println();
                    i++;
                }
            } else {
                System.out.println("No Results");
            }

            sql = "select ct.*, (select relatedsubtypevalues from usysmetacontrol c "
                    + "left join usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid "
                    + "where objectid = 10290 and ct.taxonomytypeid = c.relatedsubtypevalues) as DeterminationTaxonType "
                    + "from collectiontaxonomytypes ct where ct.biologicalobjecttypeid = "
                    + ci.getColObjTypeId();

            sql = String.format(
                    "SELECT CollectionTaxonomyTypesID, BiologicalObjectTypeID, CollectionObjectTypeName FROM (select ct.*, "
                            + "(SELECT distinct relatedsubtypevalues FROM usysmetacontrol c "
                            + "LEFT JOIN usysmetafieldsetsubtype fst ON fst.fieldsetsubtypeid = c.fieldsetsubtypeid "
                            + "WHERE objectid = 10290 AND ct.taxonomytypeid = c.relatedsubtypevalues) AS DeterminationTaxonType "
                            + "FROM collectiontaxonomytypes ct WHERE ct.biologicalobjecttypeid = %d) T1 "
                            + "INNER JOIN collectionobjecttype cot ON T1.biologicalobjecttypeid = cot.CollectionObjectTypeID",
                    ci.getColObjTypeId());

            System.out.println("\n------------------");
            System.out.println(ci.getColObjTypeName());
            System.out.println(sql);
            System.out.println("------------------");

            i = 0;
            list = BasicSQLUtils.query(oldDBConn, sql);
            if (list.size() > 0) {
                for (Object[] row : list) {
                    System.out.print(i + " - ");
                    for (Object col : row) {
                        System.out.print(col != null ? col.toString() : "null");
                        System.out.print(", ");
                    }
                    System.out.println();
                    i++;
                }
            } else {
                System.out.println("No Results");
            }
        }

        /*
                
        String sql = " select ct.*, (select relatedsubtypevalues from usysmetacontrol c " +
          "left join usysmetafieldsetsubtype fst on fst.fieldsetsubtypeid = c.fieldsetsubtypeid " +
          "where objectid = 10290 and ct.taxonomytypeid = c.relatedsubtypevalues) as DeterminationTaxonType " +
          "from collectiontaxonomytypes ct where ct.biologicalobjecttypeid = 13";
                
        System.out.println("\n------------------");
        System.out.println("List of the taxonomytypes associated with a CollectionObjectTypeID");
        System.out.println(sql);
        System.out.println("------------------");
                
        int i = 0;
        Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql);
        if (list.size() > 0)
        {
        for (Object[] row : list)
        {
            System.out.print(i+" - ");
            for (Object col: row)
            {
                System.out.print(col != null ? col.toString() : "null");
                System.out.print(", ");
            }
            System.out.println();
        }
        } else
        {
        System.out.println("No Results");
        }*/

        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,2px,f:p:g,10px,p,2px,p:g,8px"));

        JTable tableTop = new JTable(CollectionInfo.getCollectionInfoTableModel(false));
        JTable tableBot = new JTable(
                CollectionInfo.getCollectionInfoTableModel(!CollectionInfo.DOING_ACCESSSION));

        int rows = 10;
        tableTop.setPreferredScrollableViewportSize(new Dimension(
                tableTop.getPreferredScrollableViewportSize().width, rows * tableTop.getRowHeight()));
        tableBot.setPreferredScrollableViewportSize(new Dimension(
                tableBot.getPreferredScrollableViewportSize().width, rows * tableBot.getRowHeight()));

        pb.add(UIHelper.createLabel("Available Specify 5 Taxononmic Types", SwingConstants.CENTER),
                cc.xy(1, 1));
        pb.add(UIHelper.createScrollPane(tableTop), cc.xy(1, 3));

        pb.add(UIHelper.createLabel("Specify 5 Collections to be Created", SwingConstants.CENTER), cc.xy(1, 5));
        pb.add(UIHelper.createScrollPane(tableBot), cc.xy(1, 7));

        pb.setDefaultDialogBorder();
        CustomDialog dlg = new CustomDialog(null, "Taxononic Types", true, pb.getPanel());
        dlg.createUI();

        dlg.setSize(1024, 500);

        UIHelper.centerWindow(dlg);
        dlg.setAlwaysOnTop(true);
        dlg.setVisible(true);

        if (dlg.isCancelled()) {
            return CollectionResultType.eCancel;
        }

        Pair<CollectionInfo, DisciplineType> pair = CollectionInfo.getDisciplineType(oldDBConn);
        if (pair == null || pair.second == null) {
            CollectionInfo colInfo = pair.first;
            disciplineType = getStandardDisciplineName(colInfo.getTaxonomyTypeName(),
                    colInfo.getColObjTypeName(), colInfo.getCatSeriesName());
        } else {
            disciplineType = pair.second;
        }

        return disciplineType != null ? CollectionResultType.eOK : CollectionResultType.eError;
    }
    return CollectionResultType.eError;
}

From source file:com._17od.upm.gui.DatabaseActions.java

/**
 * This method prompts the user for the name of a file.
 * If the file exists then it will ask if they want to overwrite (the file isn't overwritten though,
 * that would be done by the calling method)
 * @param title The string title to put on the dialog
 * @return The file to save to or null// www. j  av a  2s.  c  o  m
 */
private File getSaveAsFile(String title) {
    File selectedFile;

    boolean gotValidFile = false;
    do {
        JFileChooser fc = new JFileChooser();
        fc.setDialogTitle(title);
        int returnVal = fc.showSaveDialog(mainWindow);

        if (returnVal != JFileChooser.APPROVE_OPTION) {
            return null;
        }

        selectedFile = fc.getSelectedFile();

        //Warn the user if the database file already exists
        if (selectedFile.exists()) {
            Object[] options = { "Yes", "No" };
            int i = JOptionPane.showOptionDialog(mainWindow,
                    Translator.translate("fileAlreadyExistsWithFileName", selectedFile.getAbsolutePath()) + '\n'
                            + Translator.translate("overwrite"),
                    Translator.translate("fileAlreadyExists"), JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            if (i == JOptionPane.YES_OPTION) {
                gotValidFile = true;
            }
        } else {
            gotValidFile = true;
        }

    } while (!gotValidFile);

    return selectedFile;
}

From source file:it.cnr.icar.eric.client.ui.swing.RegistryBrowser.java

/**
 * Method Declaration./*w w  w.j a  v  a2s.co  m*/
 * 
 * @param doConfirm
 * @param exitStatus
 */
void exitApplication(boolean doConfirm, int exitStatus) {
    boolean doExit = true;

    if (doConfirm) {
        try {
            // Show a confirmation dialog
            int reply = JOptionPane.showConfirmDialog(this, resourceBundle.getString("message.confirmExit"),
                    resourceBundle.getString("title.registryBrowser.java"), JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE);

            // If the confirmation was affirmative, handle exiting.
            if (reply == JOptionPane.YES_OPTION) {
                this.setVisible(false); // hide the Frame
                this.dispose(); // free the system resources
                exitStatus = 0;
            } else {
                doExit = false;
            }
        } catch (Exception e) {
        }
    }

    if (doExit) {
        System.exit(exitStatus);
    }
}

From source file:com.mirth.connect.connectors.jms.JmsConnectorPanel.java

private void saveTemplateButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveTemplateButtonActionPerformed
    String templateName = null;/*from  ww  w.  j  a  va 2  s  .  c o  m*/
    Object defaultValue = (templateList.getSelectedValue() == null
            || listModel.isPredefinedTemplate(templateList.getSelectedValue().toString())) ? ""
                    : templateList.getSelectedValue();

    do {
        Object response = JOptionPane.showInputDialog(parent, "Enter a name for the connection template:",
                "Save", JOptionPane.QUESTION_MESSAGE, null, null, defaultValue);

        if (response == null) {
            return;
        }

        templateName = StringUtils.trim(response.toString());

        if (templateName.isEmpty()) {
            return;
        }

        if (listModel.isPredefinedTemplate(templateName)) {
            parent.alertWarning(parent, "\"" + templateName
                    + "\" is a reserved template and cannot be overwritten. Please enter a different template name.");
            defaultValue = "";
        }
    } while (listModel.isPredefinedTemplate(templateName));

    if (listModel.containsTemplate(templateName) && !confirmDialog(
            "Are you sure you want to overwrite the existing template named \"" + templateName + "\"?")) {
        return;
    }

    JmsConnectorProperties template = new JmsConnectorProperties();
    template.setUseJndi(useJndiYes.isSelected());
    template.setJndiProviderUrl(providerUrlField.getText());
    template.setJndiInitialContextFactory(initialContextFactoryField.getText());
    template.setJndiConnectionFactoryName(connectionFactoryNameField.getText());
    template.setConnectionFactoryClass(connectionFactoryClassField.getText());
    template.setConnectionProperties(connectionPropertiesTable.getProperties());

    try {
        parent.mirthClient.getServlet(JmsConnectorServletInterface.class).saveTemplate(templateName, template);
    } catch (Exception e) {
        parent.alertThrowable(parent, e);
        return;
    }

    listModel.putTemplate(templateName, template);
    templateList.setSelectedValue(templateName, true);
}

From source file:fll.scheduler.SchedulerUI.java

/**
 * If there is more than 1 sheet, prompt, otherwise just use the sheet.
 * /*from  w w w  .  j  av a2  s  .c  om*/
 * @return the sheet name or null if the user canceled
 * @throws IOException
 * @throws InvalidFormatException
 */
public static String promptForSheetName(final File selectedFile) throws InvalidFormatException, IOException {
    final List<String> sheetNames = ExcelCellReader.getAllSheetNames(selectedFile);
    if (sheetNames.size() == 1) {
        return sheetNames.get(0);
    } else {
        final String[] options = sheetNames.toArray(new String[sheetNames.size()]);
        final int choosenOption = JOptionPane.showOptionDialog(null, "Choose which sheet to work with",
                "Choose Sheet", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options,
                options[0]);
        if (JOptionPane.CLOSED_OPTION == choosenOption) {
            return null;
        }
        return options[choosenOption];
    }
}

From source file:edu.ku.brc.specify.tasks.QueryTask.java

/**
 * @param q//from www  . j  a  va 2 s .  co m
 * @param session
 * @return true if q has no associated reports or user confirms delete
 * @throws Exception
 */
protected boolean okToDeleteQuery(final SpQuery q, DataProviderSessionIFace session) throws Exception {
    //assumes q is force-loaded
    if (q.getReports().size() > 0) {
        CustomDialog cd = new CustomDialog((Frame) UIRegistry.getTopWindow(),
                UIRegistry.getResourceString("REP_CONFIRM_DELETE_TITLE"), true, CustomDialog.OKHELP,
                new QBReportInfoPanel(q, UIRegistry.getResourceString("QB_UNDELETABLE_REPS")));
        cd.setHelpContext("QBUndeletableReps");
        UIHelper.centerAndShow(cd);
        cd.dispose();
        return false;
    }

    int option = JOptionPane.showOptionDialog(UIRegistry.getMostRecentWindow(),
            String.format(UIRegistry.getResourceString("REP_CONFIRM_DELETE"), q.getName()),
            UIRegistry.getResourceString("REP_CONFIRM_DELETE_TITLE"), JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION);

    return option == JOptionPane.YES_OPTION;
}

From source file:lejos.pc.charting.LogChartFrame.java

/** if file exists, ask user to append or overwrite. sets this.theLogFile.
 * @return 0 to replace, 1 to append, 2 to cancel
 */// w ww  .  j  a va  2  s . co  m
private int getFileAppend() {
    JFrame frame = new JFrame("DialogDemo");
    int n = 0;
    Object[] options = { "Replace it", "Add to it", "Cancel" };
    // if the log file field is empty, the PC logger will handle it. we need to make sure the title is appropo
    this.theLogFile = new File(FQPathTextArea.getText(), logFileTextField.getText());
    if (theLogFile.isFile()) {
        n = JOptionPane.showOptionDialog(frame,
                "File \"" + getCanonicalName(theLogFile) + "\" exists.\nWhat do you want to do?",
                "I have a Question...", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, //do not use a custom Icon
                options, //the titles of buttons
                options[0]); //default is "Replace it"
    }
    frame = null;
    if (n == JOptionPane.CLOSED_OPTION)
        n = 2;
    return n;
}

From source file:gdt.jgui.entity.query.JQueryPanel.java

private void clearHeader() {
    int response = JOptionPane.showConfirmDialog(this, "Clear header ?", "Confirm", JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE);
    if (response == JOptionPane.YES_OPTION) {
        try {/*from www  .  j a va 2  s .co m*/
            Entigrator entigrator = console.getEntigrator(entihome$);
            Sack query = entigrator.getEntityAtKey(entityKey$);
            query.removeElement("header.element");
            query.removeElement("header.item");
            query.removeElement("exclude");
            entigrator.save(query);
            DefaultTableModel model = new DefaultTableModel();
            table.setModel(model);

        } catch (Exception e) {
            LOGGER.severe(e.toString());
        }
    }
}

From source file:edu.ku.brc.specify.tasks.RecordSetTask.java

/**
 * Processes all Commands of type RECORD_SET.
 * @param cmdAction the command to be processed
 *///from   w w  w  .j  a  v a 2 s.  c o  m
protected void processRecordSetCommands(final CommandAction cmdAction) {
    if (cmdAction.isAction(SAVE_RECORDSET)) {
        Object data = cmdAction.getData();
        if (data instanceof RecordSetIFace) {
            // If there is only one item in the RecordSet then the User will most likely want it named the same
            // as the "identity" of the data object. So this goes and gets the Identity name and
            // pre-sets the name in the dialog.
            String intialName = "";
            RecordSetIFace recordSet = (RecordSetIFace) cmdAction.getData();
            if (recordSet.getNumItems() == 1) {
                RecordSetItemIFace item = recordSet.getOrderedItems().iterator().next();
                DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession();
                String sqlStr = DBTableIdMgr.getInstance().getQueryForTable(recordSet.getDbTableId(),
                        item.getRecordId());
                if (StringUtils.isNotEmpty(sqlStr)) {
                    Object dataObj = session.getData(sqlStr);
                    if (dataObj != null) {
                        intialName = ((FormDataObjIFace) dataObj).getIdentityTitle();
                    }
                }
                session.close();
            }
            String rsName = getUniqueRecordSetName(intialName);
            if (isNotEmpty(rsName)) {
                RecordSet rs = (RecordSet) data;
                rs.setName(rsName);
                rs.setModifiedByAgent(Agent.getUserAgent());
                saveNewRecordSet(rs);
            }
        }
    } else if (cmdAction.isAction(DELETE_CMD_ACT)) {
        RecordSetIFace recordSet = null;
        if (cmdAction.getData() instanceof RecordSetIFace) {
            recordSet = (RecordSetIFace) cmdAction.getData();

        } else if (cmdAction.getData() instanceof RolloverCommand) {
            RolloverCommand roc = (RolloverCommand) cmdAction.getData();
            if (roc.getData() instanceof RecordSetIFace) {
                recordSet = (RecordSetIFace) roc.getData();
            }
        }

        if (recordSet != null) {
            int option = JOptionPane.showOptionDialog(UIRegistry.getMostRecentWindow(),
                    String.format(UIRegistry.getResourceString("RecordSetTask.CONFIRM_DELETE"),
                            recordSet.getName()),
                    UIRegistry.getResourceString("RecordSetTask.CONFIRM_DELETE_TITLE"),
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION); // I18N

            if (option == JOptionPane.YES_OPTION) {
                deleteRecordSet(recordSet);
                deleteRecordSetFromUI(null, recordSet);
            }
        }

    } else if (cmdAction.isAction("Dropped")) {
        mergeRecordSets(cmdAction.getSrcObj(), cmdAction.getDstObj());

    } else if (cmdAction.isAction("AskForNewRS")) {
        createRecordSet((RecordSet) cmdAction.getSrcObj());

    } else if (cmdAction.isAction("DELETEITEMS")) {
        processDeleteRSItems(cmdAction);
    } else if (cmdAction.isAction(ADD_TO_NAV_BOX)) {
        addToNavBox((RecordSet) cmdAction.getData());
    }

}

From source file:edu.ku.brc.af.core.db.MySQLBackupService.java

/**
 * Checks to see if it is time to do a weekly or monthly backup. Weeks are rolling 7 days and months
 * are rolling 30 days.//from ww  w .  j  a va2  s  .  c  o  m
 * @param doSendExit requests to send an application exit command
 * @param doSkipAsk indicates whether to skip asking the user thus forcing the backup if it is time
 * @return true if the backup was started, false if it wasn't started.
 */
private boolean checkForBackUp(final boolean doSendExit, final boolean doSkipAsk) {
    final long oneDayMilliSecs = 86400000;

    Calendar calNow = Calendar.getInstance();
    Date dateNow = calNow.getTime();

    Long timeDays = getLastBackupTime(WEEKLY_PREF);
    if (timeDays == null) {
        timeDays = dateNow.getTime();
        saveLastBackupTime(WEEKLY_PREF, dateNow.getTime());
    }

    Long timeMons = getLastBackupTime(MONTHLY_PREF);
    if (timeMons == null) {
        timeMons = dateNow.getTime();
        saveLastBackupTime(MONTHLY_PREF, dateNow.getTime());
    }

    Date lastBackUpDays = new Date(timeDays);
    Date lastBackUpMons = new Date(timeMons);

    int diffMons = (int) ((dateNow.getTime() - lastBackUpMons.getTime()) / oneDayMilliSecs);
    int diffDays = (int) ((dateNow.getTime() - lastBackUpDays.getTime()) / oneDayMilliSecs);

    int diff = 0;
    String key = null;
    boolean isMonthly = false;

    if (diffMons > 30) {
        key = "MySQLBackupService.MONTHLY";
        diff = diffMons;
        isMonthly = true;

    } else if (diffDays > 7) {
        key = "MySQLBackupService.WEEKLY";
        diff = diffDays;
    }

    int userChoice = JOptionPane.CANCEL_OPTION;

    if (key != null && (UIRegistry.isEmbedded() || !doSkipAsk)) {
        if (UIRegistry.isEmbedded()) {
            showEZDBBackupMessage(key, diff);

        } else {
            Object[] options = { getResourceString("MySQLBackupService.BACKUP_NOW"), //$NON-NLS-1$
                    getResourceString("MySQLBackupService.BK_SKIP") //$NON-NLS-1$
            };
            userChoice = JOptionPane.showOptionDialog(UIRegistry.getTopWindow(), getLocalizedMessage(key, diff), //$NON-NLS-1$
                    getResourceString("MySQLBackupService.BK_NOW_TITLE"), //$NON-NLS-1$
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
        }
    }

    if (isMonthly) {
        saveLastBackupTime(MONTHLY_PREF, dateNow.getTime());
        if (diffDays > 7) {
            saveLastBackupTime(WEEKLY_PREF, dateNow.getTime());
        }
    } else {
        saveLastBackupTime(WEEKLY_PREF, dateNow.getTime());
    }

    if (!UIRegistry.isEmbedded() && (userChoice == JOptionPane.YES_OPTION || doSkipAsk)) {
        return doBackUp(isMonthly, doSendExit, null);
    }

    return false;
}