Example usage for javax.swing JOptionPane NO_OPTION

List of usage examples for javax.swing JOptionPane NO_OPTION

Introduction

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

Prototype

int NO_OPTION

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

Click Source Link

Document

Return value from class method if NO is chosen.

Usage

From source file:net.sf.jabref.gui.BasePanel.java

private void changeType(List<BibEntry> entries, String newType) {
    if ((entries == null) || (entries.isEmpty())) {
        LOGGER.error("At least one entry must be selected to be able to change the type.");
        return;/*  w  w w . j a va2s.c  o m*/
    }

    if (entries.size() > 1) {
        int choice = JOptionPane.showConfirmDialog(this, Localization.lang(
                "Multiple entries selected. Do you want to change the type of all these to '%0'?", newType),
                Localization.lang("Change entry type"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
        if (choice == JOptionPane.NO_OPTION) {
            return;
        }
    }

    NamedCompound compound = new NamedCompound(Localization.lang("Change entry type"));
    for (BibEntry entry : entries) {
        compound.addEdit(new UndoableChangeType(entry, entry.getType(), newType));
        entry.setType(newType);
    }

    output(formatOutputMessage(Localization.lang("Changed type to '%0' for", newType), entries.size()));
    compound.end();
    getUndoManager().addEdit(compound);
    markBaseChanged();
    updateEntryEditorIfShowing();
}

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

/**
 * Asks if they want to delete and then deletes it
 * @param cmdActionDB the delete command
 *//*from  ww  w  . ja va 2 s  .  c o m*/
private void deleteInfoRequest(final CommandActionForDB cmdActionDB) {
    NavBoxButton nb = (NavBoxButton) cmdActionDB.getSrcObj();
    int option = JOptionPane.showOptionDialog(UIRegistry.getMostRecentWindow(),
            String.format(getResourceString("InteractionsTask.CONFIRM_DELETE_IR"), nb.getName()),
            getResourceString("InteractionsTask.CONFIRM_DELETE_TITLE_IR"), JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE, null, null, JOptionPane.NO_OPTION); // I18N

    if (option == JOptionPane.YES_OPTION) {
        InfoRequest infoRequest = deleteInfoRequest(cmdActionDB.getId());
        deleteInfoRequestFromUI(null, infoRequest);
    }
}

From source file:com.mirth.connect.client.ui.ChannelPanel.java

private boolean handleExportGroups(List<ChannelGroup> groups) {
    // Populate list of groups with full channels
    for (ChannelGroup group : groups) {
        List<Channel> channels = new ArrayList<Channel>();
        for (Channel channel : group.getChannels()) {
            ChannelStatus channelStatus = this.channelStatuses.get(channel.getId());
            if (channelStatus != null) {
                channels.add(channelStatus.getChannel());
            }/*from  w  w  w .  j a  va  2 s . c  o m*/
        }
        group.setChannels(channels);
    }

    try {
        // Add code template libraries to channels if necessary
        if (groupHasLinkedCodeTemplates(groups)) {
            boolean addLibraries;
            String exportChannelCodeTemplateLibraries = Preferences.userNodeForPackage(Mirth.class)
                    .get("exportChannelCodeTemplateLibraries", null);

            if (exportChannelCodeTemplateLibraries == null) {
                JCheckBox alwaysChooseCheckBox = new JCheckBox(
                        "Always choose this option by default in the future (may be changed in the Administrator settings)");
                Object[] params = new Object[] {
                        "<html>One or more channels has code template libraries linked to them.<br/>Do you wish to include these libraries in each respective channel export?</html>",
                        alwaysChooseCheckBox };
                int result = JOptionPane.showConfirmDialog(this, params, "Select an Option",
                        JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);

                if (result == JOptionPane.YES_OPTION || result == JOptionPane.NO_OPTION) {
                    addLibraries = result == JOptionPane.YES_OPTION;
                    if (alwaysChooseCheckBox.isSelected()) {
                        Preferences.userNodeForPackage(Mirth.class)
                                .putBoolean("exportChannelCodeTemplateLibraries", addLibraries);
                    }
                } else {
                    return false;
                }
            } else {
                addLibraries = Boolean.parseBoolean(exportChannelCodeTemplateLibraries);
            }

            if (addLibraries) {
                for (ChannelGroup group : groups) {
                    for (Channel channel : group.getChannels()) {
                        addCodeTemplateLibrariesToChannel(channel);
                    }
                }
            }
        }

        // Update resource names
        for (ChannelGroup group : groups) {
            for (Channel channel : group.getChannels()) {
                addDependenciesToChannel(channel);
                parent.updateResourceNames(channel);
            }
        }

        if (groups.size() == 1) {
            return exportGroup(groups.iterator().next());
        } else {
            return exportGroups(groups);
        }
    } finally {
        // Reset the libraries on the cached channels
        for (ChannelGroup group : groups) {
            for (Channel channel : group.getChannels()) {
                channel.getCodeTemplateLibraries().clear();
                channel.clearDependencies();
            }
        }
    }
}

From source file:net.sf.jabref.gui.JabRefFrame.java

private boolean confirmClose(BasePanel panel) {
    boolean close = false;
    String filename;/*from w w  w .jav  a 2  s .  c  om*/

    if (panel.getBibDatabaseContext().getDatabaseFile() == null) {
        filename = GUIGlobals.UNTITLED_TITLE;
    } else {
        filename = panel.getBibDatabaseContext().getDatabaseFile().getAbsolutePath();
    }

    int answer = showSaveDialog(filename);
    if (answer == JOptionPane.YES_OPTION) {
        // The user wants to save.
        try {
            SaveDatabaseAction saveAction = new SaveDatabaseAction(panel);
            saveAction.runCommand();
            if (saveAction.isSuccess()) {
                close = true;
            }
        } catch (Throwable ex) {
            // do not close
        }

    } else if (answer == JOptionPane.NO_OPTION) {
        // discard changes
        close = true;
    }
    return close;
}

From source file:edu.harvard.i2b2.previousquery.ui.PreviousQueryPanel.java

private void populateChildNodes(DefaultMutableTreeNode node) {
    if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
        QueryMasterData data = (QueryMasterData) node.getUserObject();
        try {//from   w  w w  .j ava  2  s.  co m
            String xmlRequest = data.writeContentQueryXML();

            String xmlResponse = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                xmlResponse = QueryListNamesClient.sendQueryRequestSOAP(xmlRequest);
            } else {
                xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest);
            }
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }

            try {
                JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();
                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                BodyType bt = messageType.getMessageBody();
                InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                        .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                    // change later for working with new xml schema
                    // RunQuery runQuery =

                    QueryInstanceData runData = new QueryInstanceData();

                    runData.visualAttribute("FA");
                    if (queryInstanceType.getQueryStatusType().getName().equalsIgnoreCase("completed")) {
                        XMLGregorianCalendar sCldr = queryInstanceType.getStartDate();
                        XMLGregorianCalendar eCldr = queryInstanceType.getEndDate();
                        long diff = eCldr.toGregorianCalendar().getTimeInMillis()
                                - sCldr.toGregorianCalendar().getTimeInMillis();
                        runData.tooltip("All results are available, run " + (diff / 1000) + " seconds");
                    }
                    runData.id(queryInstanceType.getQueryInstanceId());
                    // runData.patientRefId(new
                    // Integer(queryInstanceType.getRefId()).toString());
                    // runData.patientCount(new
                    // Long(queryInstanceType.getCount()).toString());
                    // XMLGregorianCalendar cldr =
                    // queryInstanceType.getStartDate();
                    /*
                     * runData.name("Results of "+
                     * "["+addZero(cldr.getMonth(
                     * ))+"-"+addZero(cldr.getDay())+"-"
                     * +addZero(cldr.getYear())+"
                     * "+addZero(cldr.getHour())+":"
                     * +addZero(cldr.getMinute())
                     * +":"+addZero(cldr.getSecond())+"]");
                     */
                    runData.name("Results of " + data.name().substring(0, data.name().indexOf("[")));
                    runData.queryName(data.name());
                    data.runs.add(runData);
                    if (!queryInstanceType.getQueryStatusType().getName().equalsIgnoreCase("completed")) {
                        runData.name(
                                runData.name() + " --- " + queryInstanceType.getQueryStatusType().getName());
                        runData.tooltip("The results of the query run");
                    }
                    addNode(runData, node);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            // jTree1.scrollPathToVisible(new TreePath(node.getPath()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryInstanceData")) {
        QueryInstanceData data = (QueryInstanceData) node.getUserObject();

        try {
            String xmlRequest = data.writeContentQueryXML();

            String xmlResponse = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                xmlResponse = QueryListNamesClient.sendQueryRequestSOAP(xmlRequest);
            } else {
                xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest);
            }
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }

            JAXBUtil jaxbUtil = PreviousQueryJAXBUtil.getJAXBUtil();

            JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
            ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
            BodyType bt = messageType.getMessageBody();
            ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                    .getObjectByClass(bt.getAny(), ResultResponseType.class);

            for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                    .getQueryResultInstance()) {
                String status = queryResultInstanceType.getQueryStatusType().getName();

                QueryResultData resultData = new QueryResultData();
                if (queryResultInstanceType.getQueryResultType().getName().equalsIgnoreCase("PATIENTSET")
                        && UserInfoBean.getInstance().isRoleInProject("DATA_LDS")) {
                    resultData.visualAttribute("FA");
                } else {
                    resultData.visualAttribute("LAO");
                }
                // resultData.queryId(data.queryId());
                resultData.patientRefId(queryResultInstanceType.getResultInstanceId());// data.patientRefId());
                resultData.patientCount(new Integer(queryResultInstanceType.getSetSize()).toString());// data.patientCount());
                String resultname = "";
                if ((resultname = queryResultInstanceType.getQueryResultType().getDescription()) == null) {
                    resultname = queryResultInstanceType.getQueryResultType().getName();
                }
                // if (status.equalsIgnoreCase("FINISHED")) {
                if (queryResultInstanceType.getQueryResultType().getName().equals("PATIENTSET")
                /*|| queryResultInstanceType.getQueryResultType().getName()
                .equals("PATIENT_COUNT_XML")*/) {
                    // if (UserInfoBean.getInstance().isRoleInProject(
                    // "DATA_OBFSC")) {
                    // resultData.name(resultname + " - "
                    // + resultData.patientCount() + " Patients");
                    // resultData.tooltip(resultData.patientCount()
                    // + " Patients");
                    // } else {
                    if (queryResultInstanceType.getDescription() != null) {
                        resultname = queryResultInstanceType.getDescription();
                        resultData.name(queryResultInstanceType.getDescription());
                    } else {
                        resultData.name(resultname + " - " + resultData.patientCount() + " Patients");
                    }
                    resultData.tooltip(resultData.patientCount() + " Patients");
                    // }
                } else {
                    if (queryResultInstanceType.getDescription() != null) {
                        resultname = queryResultInstanceType.getDescription();
                        resultData.name(queryResultInstanceType.getDescription());
                    } else {
                        resultData.name(resultname);// + " - " + status);
                        resultData.tooltip(status);
                    }

                }

                resultData.xmlContent(xmlResponse);
                resultData.queryName(data.queryName());
                resultData.type(queryResultInstanceType.getQueryResultType().getName());
                if (!status.equalsIgnoreCase("FINISHED")) {
                    resultData.name(resultData.name() + " --- " + status);
                }
                addNode(resultData, node);
            }
            // }
            // jTree1.scrollPathToVisible(new TreePath(node.getPath()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryResultData")) {
        QueryResultData data = (QueryResultData) node.getUserObject();
        if (data.patientCount().equalsIgnoreCase("0")) {
            return;
        }
        int maxNumPatientsToDisplay = Integer.valueOf(System.getProperty("PQMaxPatientsNumber"));
        if (Integer.valueOf(data.patientCount()) > maxNumPatientsToDisplay) {
            final JPanel parent = this;
            result = JOptionPane.showConfirmDialog(parent,
                    "The patient count is greater than maximum configured to be displayed.\n"
                            + "Populating the patient list may affect performance. \n"
                            + "Do you want to continue?",
                    "Please Note ...", JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.NO_OPTION) {
                DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) node.getChildAt(0);
                QueryData tmpdata = (QueryData) tmpnode.getUserObject();
                if (tmpdata.name().equalsIgnoreCase("working ......")) {
                    tmpdata.name("Over maximum number of patient nodes");
                    treeModel.reload(tmpnode);
                }
                return;
            }
        }
        try {
            String xmlRequest = data.writeContentQueryXML();

            String xmlResponse = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                xmlResponse = QueryListNamesClient.sendPDORequestSOAP(xmlRequest, showName());
            } else {
                xmlResponse = QueryListNamesClient.sendPdoRequestREST(xmlRequest);
            }
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }

            // check response status here ......

            // System.out.println("Response: "+xmlResponse);
            PatientSet patientSet = new PDOResponseMessageFactory().getPatientSetFromResponseXML(xmlResponse);
            List<PatientType> patients = patientSet.getPatient();
            System.out.println("Patient set size: " + patients.size());

            for (int i = 0; i < patients.size(); i++) {
                PatientType patient = patients.get(i);

                PatientData pData = new PatientData();
                pData.patientID(patient.getPatientId().getValue());
                pData.setParamData(patient.getParam());
                pData.visualAttribute("LAO");
                pData.tooltip("Patient");
                pData.patientSetID(data.patientRefId());
                if (showName() && pData.lastName() != null && pData.firstName() != null) {
                    pData.name(pData.patientID() + " [" + pData.lastName().substring(0, 1).toUpperCase()
                            + pData.lastName().substring(1, pData.lastName().length()).toLowerCase() + ", "
                            + pData.firstName().substring(0, 1).toUpperCase()
                            + pData.firstName().substring(1, pData.firstName().length()).toLowerCase() + "]");// ["+pData.age()+"
                    // y/o
                    // "+pData.gender()+"
                    // "+pData.race()+"]");
                } else {
                    pData.name(pData.patientID() + " [" + pData.age() + " y/o " + pData.gender() + " "
                            + pData.race() + "]");
                }
                pData.queryName(data.queryName());
                addNode(pData, node);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // implement for other type of nodes later!!!
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.wbuploader.Uploader.java

/**
 * Called when the WorkbenchPaneSS for the uploaded dataset is shutting down, and when
 * the Upload UI 'Close' button is clicked.
 * //  ww  w.ja va 2s .  c  o m
 * @param shuttingDownSS - the dataset that is shutting down.
 * @return true if the Uploader can be closed, otherwise false.
 */
public boolean aboutToShutdown(final WorkbenchPaneSS shuttingDownSS) {
    if (shuttingDownSS != null && shuttingDownSS != wbSS) {
        return true;
    }
    if (currentTask != null || (shuttingDownSS != null
            && (currentOp.equals(Uploader.SUCCESS) || currentOp.equals(Uploader.SUCCESS_PARTIAL))
            && getUploadedObjects() > 0)) {
        JOptionPane.showMessageDialog(UIRegistry.getTopWindow(),
                getResourceString("WB_UPLOAD_BUSY_CANNOT_CLOSE"));
        return false;
    }

    boolean result = true;

    if (uploadedObjectViewer != null) {
        uploadedObjectViewer.closeView();
    }

    if (result && shuttingDownSS == null
            && (currentOp.equals(Uploader.SUCCESS) || currentOp.equals(Uploader.SUCCESS_PARTIAL))
            && getUploadedObjects() > 0 && !isUpdateUpload()) {
        result = false;
        String msg = String.format(getResourceString("WB_UPLOAD_CONFIRM_SAVE"), theWb.getName());
        JFrame topFrame = (JFrame) UIRegistry.getTopWindow();
        int rv = JOptionPane.showConfirmDialog(topFrame, msg, getResourceString("WB_UPLOAD_FORM_TITLE"),
                JOptionPane.YES_NO_CANCEL_OPTION);

        if (rv == JOptionPane.YES_OPTION) {
            saveRecordSets();
            result = true;
            wbSS.saveObject();
        } else if (rv == JOptionPane.NO_OPTION) {
            undoUpload(shuttingDownSS == null, true, true);
            result = true;
        }
        //else rv equals JOptionPane.CANCEL_OPTION or CLOSED_OPTION
        if (result) {
            for (UploadTable ut : uploadTables) {
                try {
                    ut.shutdown();
                } catch (UploaderException ex) {
                    edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
                    edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(Uploader.class, ex);
                    throw new RuntimeException(ex);
                }
            }
        }
    }
    if (additionalLocksSet) {
        freeAdditionalLocks();
    }
    return result;
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

private void deleteSelectedObjects() {
    final S3Object[] objects = getSelectedObjects();

    if (objects.length == 0) {
        log.warn("Ignoring delete objects command, no currently selected objects");
        return;/*from  w  w  w. jav a 2 s  . c om*/
    }

    int response = JOptionPane.showConfirmDialog(ownerFrame,
            (objects.length == 1 ? "Are you sure you want to delete '" + objects[0].getKey() + "'?"
                    : "Are you sure you want to delete " + objects.length + " objects"),
            "Delete Objects?", JOptionPane.YES_NO_OPTION);

    if (response == JOptionPane.NO_OPTION) {
        return;
    }

    runInBackgroundThread(new Runnable() {
        public void run() {
            s3ServiceMulti.deleteObjects(currentSelectedBucket, objects);

            runInDispatcherThreadImmediately(new Runnable() {
                public void run() {
                    updateObjectsSummary(false);
                    S3Object[] allObjects = objectTableModel.getObjects();
                    cachedBuckets.put(currentSelectedBucket.getName(), allObjects);
                }
            });
        }
    });
}

From source file:edu.harvard.i2b2.patientSet.ui.PatientSetJPanel.java

@SuppressWarnings("rawtypes")
private void populateChildNodes(DefaultMutableTreeNode node) {
    if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryMasterData")) {
        QueryMasterData data = (QueryMasterData) node.getUserObject();
        try {/*from   w w  w  . ja  v  a 2 s . c om*/
            String xmlRequest = data.writeContentQueryXML();

            String xmlResponse = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                xmlResponse = QueryListNamesClient.sendQueryRequestSOAP(xmlRequest);
            } else {
                xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest, true);
            }
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }

            try {
                JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();
                JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
                ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();

                BodyType bt = messageType.getMessageBody();
                InstanceResponseType instanceResponseType = (InstanceResponseType) new JAXBUnWrapHelper()
                        .getObjectByClass(bt.getAny(), InstanceResponseType.class);

                for (QueryInstanceType queryInstanceType : instanceResponseType.getQueryInstance()) {
                    // change later for working with new xml schema
                    // RunQuery runQuery =

                    QueryInstanceData runData = new QueryInstanceData();

                    runData.visualAttribute("FA");
                    if (queryInstanceType.getQueryStatusType().getName().equalsIgnoreCase("completed")) {
                        XMLGregorianCalendar sCldr = queryInstanceType.getStartDate();
                        XMLGregorianCalendar eCldr = queryInstanceType.getEndDate();
                        long diff = eCldr.toGregorianCalendar().getTimeInMillis()
                                - sCldr.toGregorianCalendar().getTimeInMillis();
                        runData.tooltip("All results are available, run " + (diff / 1000) + " seconds");
                    }
                    runData.id(queryInstanceType.getQueryInstanceId());
                    // runData.patientRefId(new
                    // Integer(queryInstanceType.getRefId()).toString());
                    // runData.patientCount(new
                    // Long(queryInstanceType.getCount()).toString());
                    // XMLGregorianCalendar cldr =
                    // queryInstanceType.getStartDate();
                    /*
                     * runData.name("Results of "+
                     * "["+addZero(cldr.getMonth(
                     * ))+"-"+addZero(cldr.getDay())+"-"
                     * +addZero(cldr.getYear())+"
                     * "+addZero(cldr.getHour())+":"
                     * +addZero(cldr.getMinute())
                     * +":"+addZero(cldr.getSecond())+"]");
                     */
                    runData.name("Results of " + data.name().substring(0, data.name().indexOf("[")));
                    runData.queryName(data.name());
                    data.runs.add(runData);
                    if (!queryInstanceType.getQueryStatusType().getName().equalsIgnoreCase("completed")) {
                        runData.name(
                                runData.name() + " --- " + queryInstanceType.getQueryStatusType().getName());
                        runData.tooltip("The results of the query run");
                    }
                    addNode(runData, node);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            // jTree1.scrollPathToVisible(new TreePath(node.getPath()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryInstanceData")) {
        QueryInstanceData data = (QueryInstanceData) node.getUserObject();

        try {
            String xmlRequest = data.writeContentQueryXML();

            String xmlResponse = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                xmlResponse = QueryListNamesClient.sendQueryRequestSOAP(xmlRequest);
            } else {
                xmlResponse = QueryListNamesClient.sendQueryRequestREST(xmlRequest, true);
            }
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }

            JAXBUtil jaxbUtil = PatientSetJAXBUtil.getJAXBUtil();

            JAXBElement jaxbElement = jaxbUtil.unMashallFromString(xmlResponse);
            ResponseMessageType messageType = (ResponseMessageType) jaxbElement.getValue();
            BodyType bt = messageType.getMessageBody();
            ResultResponseType resultResponseType = (ResultResponseType) new JAXBUnWrapHelper()
                    .getObjectByClass(bt.getAny(), ResultResponseType.class);

            for (QueryResultInstanceType queryResultInstanceType : resultResponseType
                    .getQueryResultInstance()) {
                String status = queryResultInstanceType.getQueryStatusType().getName();

                QueryResultData resultData = new QueryResultData();
                if (queryResultInstanceType.getQueryResultType().getName().equalsIgnoreCase("PATIENTSET")
                        && UserInfoBean.getInstance().isRoleInProject("DATA_LDS")) {
                    resultData.visualAttribute("FA");
                } else {
                    resultData.visualAttribute("LAO");
                }
                // resultData.queryId(data.queryId());
                resultData.patientRefId(queryResultInstanceType.getResultInstanceId());// data.patientRefId());
                resultData.patientCount(new Integer(queryResultInstanceType.getSetSize()).toString());// data.patientCount());
                String resultname = "";
                if ((resultname = queryResultInstanceType.getQueryResultType().getDescription()) == null) {
                    resultname = queryResultInstanceType.getQueryResultType().getName();
                }
                // if (status.equalsIgnoreCase("FINISHED")) {
                if (queryResultInstanceType.getQueryResultType().getName().equals("PATIENTSET")
                /*|| queryResultInstanceType.getQueryResultType().getName()
                .equals("PATIENT_COUNT_XML")*/) {
                    // if (UserInfoBean.getInstance().isRoleInProject(
                    // "DATA_OBFSC")) {
                    // resultData.name(resultname + " - "
                    // + resultData.patientCount() + " Patients");
                    // resultData.tooltip(resultData.patientCount()
                    // + " Patients");
                    // } else {
                    if (queryResultInstanceType.getDescription() != null) {
                        resultname = queryResultInstanceType.getDescription();
                        resultData.name(queryResultInstanceType.getDescription());
                    } else {
                        resultData.name(resultname + " - " + resultData.patientCount() + " Patients");
                    }
                    resultData.tooltip(resultData.patientCount() + " Patients");
                    // }
                } else {
                    if (queryResultInstanceType.getDescription() != null) {
                        resultname = queryResultInstanceType.getDescription();
                        resultData.name(queryResultInstanceType.getDescription());
                    } else {
                        resultData.name(resultname);// + " - " + status);
                        resultData.tooltip(status);
                    }

                }

                resultData.xmlContent(xmlResponse);
                resultData.queryName(data.queryName());
                resultData.type(queryResultInstanceType.getQueryResultType().getName());
                if (!status.equalsIgnoreCase("FINISHED")) {
                    resultData.name(resultData.name() + " --- " + status);
                }
                addNode(resultData, node);
            }
            // }
            // jTree1.scrollPathToVisible(new TreePath(node.getPath()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (node.getUserObject().getClass().getSimpleName().equalsIgnoreCase("QueryResultData")) {
        QueryResultData data = (QueryResultData) node.getUserObject();
        if (data.patientCount().equalsIgnoreCase("0")) {
            return;
        }
        int maxNumPatientsToDisplay = Integer.valueOf(System.getProperty("PQMaxPatientsNumber"));
        if (Integer.valueOf(data.patientCount()) > maxNumPatientsToDisplay) {
            final JPanel parent = this;
            result = JOptionPane.showConfirmDialog(parent,
                    "The patient count is greater than maximum configured to be displayed.\n"
                            + "Populating the patient list may affect performance. \n"
                            + "Do you want to continue?",
                    "Please Note ...", JOptionPane.YES_NO_OPTION);
            if (result == JOptionPane.NO_OPTION) {
                DefaultMutableTreeNode tmpnode = (DefaultMutableTreeNode) node.getChildAt(0);
                QueryData tmpdata = (QueryData) tmpnode.getUserObject();
                if (tmpdata.name().equalsIgnoreCase("working ......")) {
                    tmpdata.name("Over maximum number of patient nodes");
                    treeModel.reload(tmpnode);
                }
                return;
            }
        }
        try {
            String xmlRequest = data.writeContentQueryXML();

            String xmlResponse = null;
            if (System.getProperty("webServiceMethod").equals("SOAP")) {
                xmlResponse = QueryListNamesClient.sendPDORequestSOAP(xmlRequest, showName());
            } else {
                xmlResponse = QueryListNamesClient.sendPdoRequestREST(xmlRequest);
            }
            if (xmlResponse.equalsIgnoreCase("CellDown")) {
                final JPanel parent = this;
                java.awt.EventQueue.invokeLater(new Runnable() {
                    public void run() {
                        JOptionPane.showMessageDialog(parent,
                                "Trouble with connection to the remote server, "
                                        + "this is often a network error, please try again",
                                "Network Error", JOptionPane.INFORMATION_MESSAGE);
                    }
                });
                return;
            }

            // check response status here ......

            // System.out.println("Response: "+xmlResponse);
            PatientSet patientSet = new PDOResponseMessageFactory().getPatientSetFromResponseXML(xmlResponse);
            List<PatientType> patients = patientSet.getPatient();
            System.out.println("Patient set size: " + patients.size());

            for (int i = 0; i < patients.size(); i++) {
                PatientType patient = patients.get(i);

                PatientData pData = new PatientData();
                pData.patientID(patient.getPatientId().getValue());
                pData.setParamData(patient.getParam());
                pData.visualAttribute("LAO");
                pData.tooltip("Patient");
                pData.patientSetID(data.patientRefId());
                if (showName() && pData.lastName() != null && pData.firstName() != null) {
                    pData.name(pData.patientID() + " [" + pData.lastName().substring(0, 1).toUpperCase()
                            + pData.lastName().substring(1, pData.lastName().length()).toLowerCase() + ", "
                            + pData.firstName().substring(0, 1).toUpperCase()
                            + pData.firstName().substring(1, pData.firstName().length()).toLowerCase() + "]");// ["+pData.age()+"
                    // y/o
                    // "+pData.gender()+"
                    // "+pData.race()+"]");
                } else {
                    pData.name(pData.patientID() + " [" + pData.age() + " y/o " + pData.gender() + " "
                            + pData.race() + "]");
                }
                pData.queryName(data.queryName());
                addNode(pData, node);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // implement for other type of nodes later!!!
}

From source file:de.tor.tribes.ui.windows.DSWorkbenchMainFrame.java

private void fireExportEvent(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fireExportEvent
    if (evt.getSource() == jExportButton) {
        //do export
        logger.debug("Building export data");

        List<String> plansToExport = new LinkedList<>();
        for (int i = 0; i < jAttackExportTable.getRowCount(); i++) {
            String plan = (String) jAttackExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jAttackExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting attack plan '" + plan + "' to export list");
                plansToExport.add(plan);
            }//from  w  w w. j  a va  2 s. c o  m

        }

        List<String> setsToExport = new LinkedList<>();
        for (int i = 0; i < jMarkerSetExportTable.getRowCount(); i++) {
            String set = (String) jMarkerSetExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jMarkerSetExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting marker set '" + set + "' to export list");
                setsToExport.add(set);
            }

        }
        List<String> reportsToExport = new LinkedList<>();
        for (int i = 0; i < jReportSetExportTable.getRowCount(); i++) {
            String set = (String) jReportSetExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jReportSetExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting report set '" + set + "' to export list");
                reportsToExport.add(set);
            }
        }

        List<String> troopSetsToExport = new LinkedList<>();
        for (int i = 0; i < jTroopSetExportTable.getRowCount(); i++) {
            String set = (String) jTroopSetExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jTroopSetExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting troop set '" + set + "' to export list");
                troopSetsToExport.add(set);
            }
        }
        List<String> noteSetsToExport = new LinkedList<>();
        for (int i = 0; i < jNoteSetExportTable.getRowCount(); i++) {
            String set = (String) jNoteSetExportTable.getValueAt(i, 0);
            Boolean export = (Boolean) jNoteSetExportTable.getValueAt(i, 1);
            if (export) {
                logger.debug("Selecting note set '" + set + "' to export list");
                noteSetsToExport.add(set);
            }
        }
        boolean needExport = false;
        needExport = !plansToExport.isEmpty();
        needExport |= !setsToExport.isEmpty();
        needExport |= !reportsToExport.isEmpty();
        needExport |= jExportTags.isSelected();
        needExport |= !troopSetsToExport.isEmpty();
        needExport |= jExportForms.isSelected();
        needExport |= !noteSetsToExport.isEmpty();
        needExport |= jExportVillageInformation.isSelected();
        needExport |= jExportFarminfos.isSelected();
        needExport |= jExportSOS.isSelected();
        needExport |= jExportSplits.isSelected();
        needExport |= jExportStdAttacks.isSelected();

        if (!needExport) {
            JOptionPaneHelper.showWarningBox(jExportDialog, "Keine Daten fr den Export gewhlt", "Export");
            return;

        }
        String dir = GlobalOptions.getProperty("screen.dir");
        if (dir == null) {
            dir = ".";
        }

        JFileChooser chooser;
        try {
            chooser = new JFileChooser(dir);
        } catch (Exception e) {
            JOptionPaneHelper.showErrorBox(this,
                    "Konnte Dateiauswahldialog nicht ffnen.\nMglicherweise verwendest du Windows Vista. Ist dies der Fall, beende DS Workbench, klicke mit der rechten Maustaste auf DSWorkbench.exe,\n"
                            + "whle 'Eigenschaften' und deaktiviere dort unter 'Kompatibilitt' den Windows XP Kompatibilittsmodus.",
                    "Fehler");
            return;
        }
        chooser.setDialogTitle("Datei auswhlen");
        chooser.setSelectedFile(new File("export.xml"));
        chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {

            @Override
            public boolean accept(File f) {
                return (f != null) && (f.isDirectory() || f.getName().endsWith(".xml"));

            }

            @Override
            public String getDescription() {
                return "*.xml";
            }
        });
        int ret = chooser.showSaveDialog(jExportDialog);
        if (ret == JFileChooser.APPROVE_OPTION) {
            try {
                File f = chooser.getSelectedFile();
                String file = f.getCanonicalPath();
                if (!file.endsWith(".xml")) {
                    file += ".xml";
                }

                File target = new File(file);
                if (target.exists()) {
                    if (JOptionPaneHelper.showQuestionConfirmBox(jExportDialog,
                            "Bestehende Datei berschreiben?", "Export", "Nein",
                            "Ja") == JOptionPane.NO_OPTION) {
                        return;
                    }
                }

                Document doc = JDomUtils.createDocument();
                Element backup = doc.getRootElement();
                if (!plansToExport.isEmpty()) {
                    backup.addContent(AttackManager.getSingleton().getExportData(plansToExport));
                }
                if (!setsToExport.isEmpty()) {
                    backup.addContent(MarkerManager.getSingleton().getExportData(setsToExport));
                }
                if (!reportsToExport.isEmpty()) {
                    backup.addContent(ReportManager.getSingleton().getExportData(reportsToExport));
                }
                if (jExportTags.isSelected()) {
                    backup.addContent(TagManager.getSingleton().getExportData(null));
                }

                if (!troopSetsToExport.isEmpty()) {
                    backup.addContent(TroopsManager.getSingleton().getExportData(troopSetsToExport));
                }

                if (jExportForms.isSelected()) {
                    backup.addContent(FormManager.getSingleton().getExportData(null));
                }

                if (!noteSetsToExport.isEmpty()) {
                    backup.addContent(NoteManager.getSingleton().getExportData(noteSetsToExport));
                }

                if (jExportVillageInformation.isSelected()) {
                    backup.addContent(KnownVillageManager.getSingleton().getExportData(null));
                }

                if (jExportFarminfos.isSelected()) {
                    backup.addContent(FarmManager.getSingleton().getExportData(null));
                }

                if (jExportSOS.isSelected()) {
                    backup.addContent(SOSManager.getSingleton().getExportData(null));
                }

                if (jExportSplits.isSelected()) {
                    backup.addContent(SplitSetHelper.getExportData());
                }

                if (jExportStdAttacks.isSelected()) {
                    backup.addContent(StandardAttackManager.getSingleton().getExportData(null));
                }

                logger.debug("Writing data to disk");
                JDomUtils.saveDocument(doc, file);
                logger.debug("Export finished successfully");
                JOptionPaneHelper.showInformationBox(jExportDialog, "Export erfolgreich beendet.", "Export");
            } catch (Exception e) {
                logger.error("Failed to export data", e);
                JOptionPaneHelper.showErrorBox(this, "Export fehlgeschlagen.", "Export");
            }

        } else {
            //cancel pressed
            return;
        }

    }
    jExportDialog.setAlwaysOnTop(false);
    jExportDialog.setVisible(false);
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void fireCalculateAttackEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireCalculateAttackEvent
    if (!jCalculateButton.isEnabled()) {
        logger.debug("Button disabled. Calculation is still running...");
        return;/*from  w  ww  . j ava 2  s. c o  m*/
    }
    //algorithm calculation
    //pre check
    DefaultTableModel victimModel = (DefaultTableModel) jVictimTable.getModel();
    DefaultTableModel attackModel = (DefaultTableModel) jSourcesTable.getModel();
    if (attackModel.getRowCount() == 0) {
        logger.warn("Validation of attacker tab failed");
        JOptionPaneHelper.showErrorBox(this, "Keine Herkunftsdrfer ausgewhlt", "Fehler");
        jideTabbedPane1.setSelectedIndex(0);
        return;
    }
    if (victimModel.getRowCount() == 0) {
        logger.warn("Validation of victim tab failed");
        JOptionPaneHelper.showErrorBox(this, "Keine Ziele ausgewhlt", "Fehler");
        jideTabbedPane1.setSelectedIndex(1);
        return;
    }
    if (!mSettingsPanel.validatePanel()) {
        logger.warn("Validation of settings tab failed");
        jideTabbedPane1.setSelectedIndex(2);
        return;
    }
    //reading values
    List<Village> victimVillages = new LinkedList<Village>();
    List<Village> victimVillagesFaked = new LinkedList<Village>();
    Hashtable<Village, Integer> maxAttacksTable = new Hashtable<Village, Integer>();
    for (int i = 0; i < victimModel.getRowCount(); i++) {
        if ((Boolean) victimModel.getValueAt(i, 2) == Boolean.TRUE) {
            victimVillagesFaked.add((Village) victimModel.getValueAt(i, 1));
        } else {
            victimVillages.add((Village) victimModel.getValueAt(i, 1));
        }
        maxAttacksTable.put((Village) victimModel.getValueAt(i, 1), (Integer) victimModel.getValueAt(i, 3));
    }
    //build source-unit map
    int snobSources = 0;
    // <editor-fold defaultstate="collapsed" desc=" Build attacks and fakes">
    Hashtable<UnitHolder, List<Village>> sources = new Hashtable<UnitHolder, List<Village>>();
    Hashtable<UnitHolder, List<Village>> fakes = new Hashtable<UnitHolder, List<Village>>();
    for (int i = 0; i < attackModel.getRowCount(); i++) {
        Village vSource = (Village) attackModel.getValueAt(i, 0);
        UnitHolder uSource = (UnitHolder) attackModel.getValueAt(i, 1);
        boolean fake = (Boolean) attackModel.getValueAt(i, 2);
        if (!fake) {
            List<Village> sourcesForUnit = sources.get(uSource);
            if (uSource.getPlainName().equals("snob")) {
                if (sourcesForUnit == null) {
                    snobSources = 0;
                } else {
                    snobSources = sourcesForUnit.size();
                }
            }
            if (sourcesForUnit == null) {
                sourcesForUnit = new LinkedList<Village>();
                sourcesForUnit.add(vSource);
                sources.put(uSource, sourcesForUnit);
            } else {
                sourcesForUnit.add(vSource);
            }
        } else {
            List<Village> fakesForUnit = fakes.get(uSource);
            if (fakesForUnit == null) {
                fakesForUnit = new LinkedList<Village>();
                fakesForUnit.add(vSource);
                fakes.put(uSource, fakesForUnit);
            } else {
                fakesForUnit.add(vSource);
            }
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc=" Check for units not supported by the algorithm">
    boolean useMiscUnits = false;
    Enumeration<UnitHolder> involvedUnits = sources.keys();
    while (involvedUnits.hasMoreElements()) {
        UnitHolder u = involvedUnits.nextElement();
        //check for misc unit
        if (!u.getPlainName().equals("ram") && !u.getPlainName().equals("catapult")) {
            useMiscUnits = true;
            break;
        }
    }
    if (!useMiscUnits) {
        involvedUnits = fakes.keys();
        while (involvedUnits.hasMoreElements()) {
            UnitHolder u = involvedUnits.nextElement();
            //check for misc unit
            if (!u.getPlainName().equals("ram") && !u.getPlainName().equals("catapult")) {
                useMiscUnits = true;
                break;
            }
        }
    }
    // </editor-fold>
    boolean fakeOffTargets = mSettingsPanel.fakeOffTargets();
    //mSettingsPanel.getAttacksPerVillage();
    TimeFrame timeFrame = mSettingsPanel.getTimeFrame();
    //start processing
    AbstractAttackAlgorithm algo = null;
    boolean supportMiscUnits = false;
    if (mSettingsPanel.useBruteForce()) {
        logger.info("Using 'BruteForce' calculation");
        algo = new BruteForce();
        //algo = new Recurrection();
        supportMiscUnits = true;
        logPanel.setAbortable(false);
    } else {
        logger.info("Using 'systematic' calculation");
        algo = new Iterix();
        supportMiscUnits = false;
        logPanel.setAbortable(true);
    }
    //check misc-units criteria
    if (useMiscUnits && !supportMiscUnits) {
        if (JOptionPaneHelper.showQuestionConfirmBox(this,
                "Der gewhlte Algorithmus untersttzt nur Rammen und Katapulte als angreifende Einheiten.\n"
                        + "Drfer fr die eine andere Einheit gewhlt wurde werden ignoriert.\n"
                        + "Trotzdem fortfahren?",
                "Warnung", "Nein", "Ja") == JOptionPane.NO_OPTION) {
            logger.debug("User aborted calculation due to algorithm");
            return;
        }
    }
    mSettingsPanel.storeProperties();
    logPanel.clear();
    algo.initialize(sources, fakes, victimVillages, victimVillagesFaked, maxAttacksTable, timeFrame,
            fakeOffTargets, logPanel);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                jCalculateButton.setEnabled(false);
                mLogFrame.setVisible(true);
                mLogFrame.toFront();
            } catch (Exception e) {
            }
        }
    });
    algo.execute(this);
}