Example usage for javax.swing.tree DefaultMutableTreeNode getUserObject

List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode getUserObject.

Prototype

public Object getUserObject() 

Source Link

Document

Returns this node's user object.

Usage

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private DefaultMutableTreeNode convertInfoValueTreeToInfoComponentTree(DefaultMutableTreeNode infoValueTree)
        throws ModelInformationException {
    @SuppressWarnings("rawtypes")
    final Enumeration nodes = infoValueTree.breadthFirstEnumeration();
    nodes.nextElement(); // root

    while (nodes.hasMoreElements()) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
        if (node.getUserObject() != null) {
            @SuppressWarnings("unchecked")
            final Pair<ParameterInfo, String> userObj = (Pair<ParameterInfo, String>) node.getUserObject();
            final JComponent component = convertStringToComponent(userObj.getKey(), userObj.getValue());
            final Pair<ParameterInfo, JComponent> newUserObj = new Pair<ParameterInfo, JComponent>(
                    userObj.getKey(), component);
            node.setUserObject(newUserObj);
        }/*from  ww w.j  a  v  a 2  s  . com*/
    }

    return infoValueTree;
}

From source file:com.pironet.tda.SunJDKParser.java

/**
 * dump the monitor information/*from w ww .j a va  2  s .co m*/
 */
private int[] dumpMonitors(DefaultMutableTreeNode catMonitors, DefaultMutableTreeNode catMonitorsLocks,
        MonitorMap mmap) {
    Iterator iter = mmap.iterOfKeys();
    int monitorsWithoutLocksCount = 0;
    int overallThreadsWaiting = 0;
    while (iter.hasNext()) {
        String monitor = (String) iter.next();
        Map<String, String>[] threads = mmap.getFromMonitorMap(monitor);
        ThreadInfo mi = new ThreadInfo(monitor, null, "", 0, null);
        DefaultMutableTreeNode monitorNode = new DefaultMutableTreeNode(mi);

        // first the locks
        Iterator<String> iterLocks = threads[MonitorMap.LOCK_THREAD_POS].keySet().iterator();
        int locks = 0;
        int sleeps = 0;
        while (iterLocks.hasNext()) {
            String thread = iterLocks.next();
            String stackTrace = threads[MonitorMap.LOCK_THREAD_POS].get(thread);
            if (threads[MonitorMap.SLEEP_THREAD_POS].containsKey(thread)) {
                createNode(monitorNode, "locks and sleeps on monitor: " + thread, null, stackTrace, 0);
                sleeps++;
            } else if (threads[MonitorMap.WAIT_THREAD_POS].containsKey(thread)) {
                createNode(monitorNode, "locks and waits on monitor: " + thread, null, stackTrace, 0);
                sleeps++;
            } else {
                createNode(monitorNode, "locked by " + thread, null, stackTrace, 0);
            }
            locks++;
        }

        Iterator iterWaits = threads[MonitorMap.WAIT_THREAD_POS].keySet().iterator();
        int waits = 0;
        while (iterWaits.hasNext()) {
            String thread = (String) iterWaits.next();
            if (!threads[MonitorMap.LOCK_THREAD_POS].containsKey(thread)) {
                createNode(monitorNode, "waits on monitor: " + thread, null,
                        threads[MonitorMap.WAIT_THREAD_POS].get(thread), 0);
                waits++;
            }
        }

        mi.setContent(ThreadDumpInfo.getMonitorInfo(locks, waits, sleeps));
        mi.setName(mi.getName() + ":    " + (sleeps) + " Thread(s) sleeping, " + (waits)
                + " Thread(s) waiting, " + (locks) + " Thread(s) locking");
        if (ThreadDumpInfo.areALotOfWaiting(waits)) {
            mi.setALotOfWaiting(true);
        }
        mi.setChildCount(monitorNode.getChildCount());

        ((Category) catMonitors.getUserObject()).addToCatNodes(monitorNode);
        if (locks == 0) {
            monitorsWithoutLocksCount++;
            overallThreadsWaiting += waits;
            ((Category) catMonitorsLocks.getUserObject()).addToCatNodes(monitorNode);
        }
    }
    return new int[] { monitorsWithoutLocksCount, overallThreadsWaiting };
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private String checkInfosInGeneTree() {
    final DefaultTreeModel treeModel = gaSearchHandler.getChromosomeTree();
    final DefaultMutableTreeNode root = (DefaultMutableTreeNode) treeModel.getRoot();
    @SuppressWarnings("rawtypes")
    final Enumeration nodes = root.breadthFirstEnumeration();
    nodes.nextElement(); // root
    while (nodes.hasMoreElements()) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
        final ParameterOrGene userObj = (ParameterOrGene) node.getUserObject();
        final String invalid = checkSubmodelInfo(userObj.getInfo());
        if (invalid != null)
            return invalid;
    }/*from  www . j  a v  a2s  . c  om*/

    return null;
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private String checkInfos(final boolean submodel) {
    final DefaultListModel listModel = (DefaultListModel) parameterList.getModel();
    for (int i = 0; i < listModel.getSize(); ++i) {
        final AvailableParameter param = (AvailableParameter) listModel.get(i);
        final String invalid = submodel ? checkSubmodelInfo(param.info) : checkFileInfo(param);
        if (invalid != null)
            return invalid;
    }//  w w w. ja  va  2  s. c  o m

    for (final ParameterCombinationGUI pGUI : parameterTreeBranches) {
        final DefaultMutableTreeNode root = pGUI.combinationRoot;
        @SuppressWarnings("rawtypes")
        final Enumeration nodes = root.breadthFirstEnumeration();
        nodes.nextElement(); // root
        while (nodes.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
            final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
            final String invalid = submodel ? checkSubmodelInfo(userObj.info) : checkFileInfo(userObj);
            if (invalid != null)
                return invalid;
        }
    }

    return null;
}

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 . j  a  va 2  s .com
            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:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private ParameterTree createParameterTreeFromParamSweepGUI() throws ModelInformationException {
    final ParameterTree result = new ParameterTree();

    final DefaultListModel listModel = (DefaultListModel) parameterList.getModel();
    for (int i = 0; i < listModel.getSize(); ++i) {
        final AvailableParameter param = (AvailableParameter) listModel.get(i);
        final AbstractParameterInfo<?> batchParameter = InfoConverter.parameterInfo2ParameterInfo(param.info);
        ParameterTreeUtils.addConstantParameterToParameterTree(batchParameter, result, currentModelHandler);
    }/*from   w w w.ja  v a  2 s.c o m*/

    for (final ParameterCombinationGUI pGUI : parameterTreeBranches) {
        final DefaultMutableTreeNode root = pGUI.combinationRoot;
        @SuppressWarnings("rawtypes")
        final Enumeration nodes = root.breadthFirstEnumeration();
        nodes.nextElement(); // root;
        while (nodes.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
            final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
            ParameterTreeUtils.filterConstants(userObj, result, currentModelHandler);
        }
    }

    for (final ParameterCombinationGUI pGUI : parameterTreeBranches) {
        final DefaultMutableTreeNode root = pGUI.combinationRoot;
        @SuppressWarnings("rawtypes")
        final Enumeration nodes = root.preorderEnumeration();
        nodes.nextElement(); // root
        ParameterNode parent = result.getRoot();
        while (nodes.hasMoreElements()) {
            final DefaultMutableTreeNode node = (DefaultMutableTreeNode) nodes.nextElement();
            final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
            if (ParameterTreeUtils.isMutableParameter(userObj)) {
                final AbstractParameterInfo<?> batchParameter = InfoConverter
                        .parameterInfo2ParameterInfo(userObj.info);
                batchParameter.setRunNumber(1);
                final ParameterNode parameterNode = new ParameterNode(batchParameter);
                parent.add(parameterNode);
                parent = parameterNode;
            }
        }
    }

    return result;
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void savePSParameter(final DefaultMutableTreeNode node, final ObjectFactory factory,
        final Object parent, final int position) {
    final ParameterInATree userObj = (ParameterInATree) node.getUserObject();
    final ParameterInfo info = userObj.info;

    if (info instanceof SubmodelInfo) {
        final SubmodelInfo sInfo = (SubmodelInfo) info;

        final SubmodelParameter parameter = factory.createSubmodelParameter();
        parameter.setName(info.getName());
        parameter.setType(sInfo.getActualType() == null ? "null" : sInfo.getActualType().getName());
        parameter.setPosition(BigInteger.valueOf(position));

        if (parent instanceof Combination) {
            final Combination combination = (Combination) parent;
            combination.getSubmodelParameterList().add(parameter);
        } else if (parent instanceof SubmodelParameter) {
            final SubmodelParameter submodelParameter = (SubmodelParameter) parent;
            submodelParameter.getSubmodelParameterList().add(parameter);
        }//from w w w  . j av a2s.c  om

        if (node.getChildCount() > 0) {
            @SuppressWarnings("rawtypes")
            final Enumeration childNodes = node.children();
            int childPosition = 1;
            while (childNodes.hasMoreElements()) {
                final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) childNodes.nextElement();
                savePSParameter(childNode, factory, parameter, childPosition++);
            }
        }
    } else {
        final Parameter parameter = factory.createParameter();
        parameter.setName(info.getName());
        parameter.setPosition(BigInteger.valueOf(position));

        switch (info.getDefinitionType()) {
        case ParameterInfo.CONST_DEF:
            parameter.setParameterType(ParameterType.CONSTANT);
            parameter.getContent().add(info.getValue().toString());
            break;

        case ParameterInfo.LIST_DEF:
            parameter.setParameterType(ParameterType.LIST);
            savePSListParameter(info, parameter, factory);
            break;

        case ParameterInfo.INCR_DEF:
            parameter.setParameterType(ParameterType.INCREMENT);
            savePSIncrementParameter(info, parameter, factory);
            break;
        }

        if (parent instanceof Combination) {
            final Combination combination = (Combination) parent;
            combination.getParameterList().add(parameter);
        } else if (parent instanceof SubmodelParameter) {
            final SubmodelParameter submodelParameter = (SubmodelParameter) parent;
            submodelParameter.getParameterList().add(parameter);
        }
    }
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private DefaultMutableTreeNode findParameterInfoNode(final ParameterInfo info, final boolean checkParentValue) {
    if (info == null)
        return null;

    @SuppressWarnings("rawtypes")
    final Enumeration treeValues = parameterValueComponentTree.breadthFirstEnumeration();
    treeValues.nextElement(); // root node

    while (treeValues.hasMoreElements()) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeValues.nextElement();
        @SuppressWarnings("unchecked")
        final Pair<ParameterInfo, JComponent> userData = (Pair<ParameterInfo, JComponent>) node.getUserObject();
        final ParameterInfo parameterInfo = userData.getFirst();

        if (checkParentValue && info instanceof ISubmodelGUIInfo && parameterInfo instanceof ISubmodelGUIInfo) {
            final ISubmodelGUIInfo sgi = (ISubmodelGUIInfo) info;
            final ISubmodelGUIInfo otherSgi = (ISubmodelGUIInfo) parameterInfo;
            if (info.equals(parameterInfo) && classEquals(sgi.getParentValue(), otherSgi.getParentValue()))
                return node;
        } else if (info.equals(parameterInfo))
            return node;
    }//from w  ww . j  a v a  2 s  .  c o  m

    return null;
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void saveSubTree(@SuppressWarnings("rawtypes") final Enumeration children,
        final List<Parameter> parameterList, final List<SubmodelParameter> submodelParameterList,
        final Set<ParameterInfo> invalids) throws IOException {

    final ObjectFactory factory = new ObjectFactory();
    while (children.hasMoreElements()) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();

        @SuppressWarnings("unchecked")
        final Pair<ParameterInfo, JComponent> userData = (Pair<ParameterInfo, JComponent>) node.getUserObject();
        final ParameterInfo parameterInfo = userData.getFirst();
        final JComponent valueContainer = userData.getSecond();

        Parameter parameter = null;
        SubmodelParameter submodelParameter = null;
        if (parameterInfo instanceof ISubmodelGUIInfo) {
            final ISubmodelGUIInfo sgi = (ISubmodelGUIInfo) parameterInfo;
            if (sgi.getParent() != null) {
                final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
                @SuppressWarnings("unchecked")
                final Pair<ParameterInfo, JComponent> parentUserData = (Pair<ParameterInfo, JComponent>) parentNode
                        .getUserObject();
                final SubmodelInfo parentParameterInfo = (SubmodelInfo) parentUserData.getFirst();
                if (invalids.contains(parentParameterInfo)
                        || !classEquals(parentParameterInfo.getActualType(), sgi.getParentValue())) {
                    invalids.add(parameterInfo);
                    continue;
                }//w w  w  . j  av a 2 s .  c om
            }
        }

        if (parameterInfo instanceof SubmodelInfo) {
            submodelParameter = factory.createSubmodelParameter();
            submodelParameter.setName(parameterInfo.getName());
        } else {
            parameter = factory.createParameter();
            parameter.setName(parameterInfo.getName());
        }

        if (parameterInfo.isBoolean()) {
            final JCheckBox checkBox = (JCheckBox) valueContainer;
            parameter.getContent().add(String.valueOf(checkBox.isSelected()));
        } else if (parameterInfo.isEnum()) {
            final JComboBox comboBox = (JComboBox) valueContainer;
            parameter.getContent().add(String.valueOf(comboBox.getSelectedItem()));
        } else if (parameterInfo instanceof MasonChooserParameterInfo) {
            final JComboBox comboBox = (JComboBox) valueContainer;
            parameter.getContent().add(String.valueOf(comboBox.getSelectedIndex()));
        } else if (parameterInfo instanceof SubmodelInfo) {
            final JComboBox comboBox = (JComboBox) ((JPanel) valueContainer).getComponent(0);
            final ClassElement selectedElement = (ClassElement) comboBox.getSelectedItem();

            if (selectedElement.clazz == null)
                throw new IOException("No type is selected for parameter "
                        + parameterInfo.getName().replaceAll("([A-Z])", " $1") + ".");

            submodelParameter.setType(selectedElement.clazz.getName());
            saveSubTree(node.children(), submodelParameter.getParameterList(),
                    submodelParameter.getSubmodelParameterList(), invalids);
        } else if (parameterInfo.isFile()) {
            final JTextField textField = (JTextField) valueContainer.getComponent(0);
            parameter.getContent().add(textField.getToolTipText());
        } else if (parameterInfo instanceof MasonIntervalParameterInfo) {
            final JTextField textField = (JTextField) valueContainer.getComponent(0);
            parameter.getContent().add(textField.getText().trim());
        } else {
            final JTextField textField = (JTextField) valueContainer;
            String text = String.valueOf(ParameterInfo.getValue(textField.getText(), parameterInfo.getType()));
            if ("String".equals(parameterInfo.getType()) && parameterInfo.getValue() == null)
                text = textField.getText().trim();
            parameter.getContent().add(text);
        }

        if (parameter != null)
            parameterList.add(parameter);
        else if (submodelParameter != null)
            submodelParameterList.add(submodelParameter);
    }
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

/** {@inheritDoc} 
 *///w ww .j a v a 2  s  .  c  om
@Override
public boolean onButtonPress(final Button button) {
    if (Button.NEXT.equals(button)) {
        ParameterTree parameterTree = null;
        if (tabbedPane.getSelectedIndex() == SINGLE_RUN_GUI_TABINDEX) {
            currentModelHandler.setIntelliMethodPlugin(null);
            parameterTree = new ParameterTree();
            final Set<ParameterInfo> invalids = new HashSet<ParameterInfo>();

            @SuppressWarnings("rawtypes")
            final Enumeration treeValues = parameterValueComponentTree.breadthFirstEnumeration();
            treeValues.nextElement(); // root element
            while (treeValues.hasMoreElements()) {
                final DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeValues.nextElement();
                @SuppressWarnings("unchecked")
                final Pair<ParameterInfo, JComponent> userData = (Pair<ParameterInfo, JComponent>) node
                        .getUserObject();
                final ParameterInfo parameterInfo = userData.getFirst();
                final JComponent valueContainer = userData.getSecond();

                if (parameterInfo instanceof ISubmodelGUIInfo) {
                    final ISubmodelGUIInfo sgi = (ISubmodelGUIInfo) parameterInfo;
                    if (sgi.getParent() != null) {
                        final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
                        @SuppressWarnings("unchecked")
                        final Pair<ParameterInfo, JComponent> parentUserData = (Pair<ParameterInfo, JComponent>) parentNode
                                .getUserObject();
                        final SubmodelInfo parentParameterInfo = (SubmodelInfo) parentUserData.getFirst();
                        if (invalids.contains(parentParameterInfo)
                                || !classEquals(parentParameterInfo.getActualType(), sgi.getParentValue())) {
                            invalids.add(parameterInfo);
                            continue;
                        }
                    }
                }

                if (parameterInfo.isBoolean()) {
                    final JCheckBox checkBox = (JCheckBox) valueContainer;
                    parameterInfo.setValue(checkBox.isSelected());
                } else if (parameterInfo.isEnum()) {
                    final JComboBox comboBox = (JComboBox) valueContainer;
                    parameterInfo.setValue(comboBox.getSelectedItem());
                } else if (parameterInfo instanceof MasonChooserParameterInfo) {
                    final JComboBox comboBox = (JComboBox) valueContainer;
                    parameterInfo.setValue(comboBox.getSelectedIndex());
                } else if (parameterInfo instanceof SubmodelInfo) {
                    // we don't need the SubmodelInfo parameters anymore (all descendant parameters are in the tree too)
                    // but we need to check that an actual type is provided
                    final SubmodelInfo smi = (SubmodelInfo) parameterInfo;
                    final JComboBox comboBox = (JComboBox) ((JPanel) valueContainer).getComponent(0);
                    final ClassElement selected = (ClassElement) comboBox.getSelectedItem();
                    smi.setActualType(selected.clazz, selected.instance);

                    if (smi.getActualType() == null) {
                        final String errorMsg = "Please select a type from the dropdown list of "
                                + smi.getName().replaceAll("([A-Z])", " $1");
                        JOptionPane.showMessageDialog(wizard, new JLabel(errorMsg), "Error",
                                JOptionPane.ERROR_MESSAGE);
                        return false;
                    }

                    //continue;
                } else if (parameterInfo.isFile()) {
                    final JTextField textField = (JTextField) valueContainer.getComponent(0);
                    if (textField.getText().trim().isEmpty())
                        log.warn("Empty string was specified as file parameter "
                                + parameterInfo.getName().replaceAll("([A-Z])", " $1"));

                    final File file = new File(textField.getToolTipText());
                    if (!file.exists()) {
                        final String errorMsg = "Please specify an existing file parameter "
                                + parameterInfo.getName().replaceAll("([A-Z])", " $1");
                        JOptionPane.showMessageDialog(wizard, new JLabel(errorMsg), "Error",
                                JOptionPane.ERROR_MESSAGE);
                        return false;
                    }

                    parameterInfo.setValue(
                            ParameterInfo.getValue(textField.getToolTipText(), parameterInfo.getType()));
                } else if (parameterInfo instanceof MasonIntervalParameterInfo) {
                    final JTextField textField = (JTextField) valueContainer.getComponent(0);
                    parameterInfo.setValue(
                            ParameterInfo.getValue(textField.getText().trim(), parameterInfo.getType()));
                } else {
                    final JTextField textField = (JTextField) valueContainer;
                    parameterInfo
                            .setValue(ParameterInfo.getValue(textField.getText(), parameterInfo.getType()));
                    if ("String".equals(parameterInfo.getType()) && parameterInfo.getValue() == null)
                        parameterInfo.setValue(textField.getText().trim());
                }

                final AbstractParameterInfo<?> batchParameterInfo = InfoConverter
                        .parameterInfo2ParameterInfo(parameterInfo);
                parameterTree.addNode(batchParameterInfo);
            }

            dashboard.setOnLineCharts(onLineChartsCheckBox.isSelected());
            dashboard.setDisplayAdvancedCharts(advancedChartsCheckBox.isSelected());
        }

        if (tabbedPane.getSelectedIndex() == PARAMSWEEP_GUI_TABINDEX) {
            currentModelHandler.setIntelliMethodPlugin(null);
            boolean success = true;
            if (editedNode != null)
                success = modify();

            if (success) {
                String invalidInfoName = checkInfos(true);
                if (invalidInfoName != null) {
                    Utilities.userAlert(sweepPanel,
                            "Please select a type from the dropdown list of " + invalidInfoName);
                    return false;
                }

                invalidInfoName = checkInfos(false);
                if (invalidInfoName != null) {
                    Utilities.userAlert(sweepPanel, "Please specify a file for parameter " + invalidInfoName);
                    return false;
                }

                if (needWarning()) {
                    final int result = Utilities.askUser(sweepPanel, false, "Warning",
                            "There are two or more combination boxes that contains non-constant parameters."
                                    + " Parameters are unsynchronized:",
                            "simulation may exit before all parameter values are assigned.", " ",
                            "To explore all possible combinations you must use only one combination box.", " ",
                            "Do you want to run simulation with these parameter settings?");
                    if (result == 0) {
                        return false;
                    }
                }

                try {
                    parameterTree = createParameterTreeFromParamSweepGUI();

                    final ParameterNode rootNode = parameterTree.getRoot();
                    dumpParameterTree(rootNode);

                    //                  dashboard.setOnLineCharts(onLineChartsCheckBoxPSW.isSelected());
                } catch (final ModelInformationException e) {
                    JOptionPane.showMessageDialog(wizard, new JLabel(e.getMessage()),
                            "Error while creating runs", JOptionPane.ERROR_MESSAGE);
                    e.printStackTrace();
                    return false;
                }
            } else
                return false;
        }

        if (tabbedPane.getSelectedIndex() == GASEARCH_GUI_TABINDEX) {
            final IIntelliDynamicMethodPlugin gaPlugin = (IIntelliDynamicMethodPlugin) gaSearchHandler;
            currentModelHandler.setIntelliMethodPlugin(gaPlugin);
            boolean success = gaSearchPanel.closeActiveModification();

            if (success) {
                String invalidInfoName = checkInfosInGeneTree();
                if (invalidInfoName != null) {
                    Utilities.userAlert(sweepPanel,
                            "Please select a type from the dropdown list of " + invalidInfoName);
                    return false;
                }

                final String[] errors = gaSearchHandler.checkGAModel();
                if (errors != null) {
                    Utilities.userAlert(sweepPanel, (Object[]) errors);
                    return false;
                }

                final DefaultMutableTreeNode parameterTreeRootNode = new DefaultMutableTreeNode();
                final IIntelliContext ctx = new DashboardIntelliContext(parameterTreeRootNode,
                        gaSearchHandler.getChromosomeTree());
                gaPlugin.alterParameterTree(ctx);
                parameterTree = InfoConverter.node2ParameterTree(parameterTreeRootNode);
                dashboard.setOptimizationDirection(gaSearchHandler.getFitnessFunctionDirection());

            } else
                return false;
        }

        currentModelHandler.setParameters(parameterTree);
    }

    return true;
}