Search in sources :

Example 1 with JSortTable

use of org.vcell.util.gui.sorttable.JSortTable in project vcell by virtualcell.

the class DialogUtils method showComponentOptionsTableList.

public static TableListResult showComponentOptionsTableList(final Component requester, final String title, final String[] columnNames, final Object[][] rowDataOrig, final Integer listSelectionModel_SelectMode, final ListSelectionListener listSelectionListener, final String[] options, final String initOption, final Comparator<Object> rowSortComparator, final boolean bModal) throws UserCancelException {
    // //Create hidden column with original row index so original row index can
    // //be returned for user selections even if rows are sorted
    // final int hiddenColumnIndex = rowDataOrig[0].length;
    // final Object[][] rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex+1];
    // for (int i = 0; i < rowDataHiddenIndex.length; i++) {
    // for (int j = 0; j < rowDataOrig[i].length; j++) {
    // rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
    // }
    // rowDataHiddenIndex[i][hiddenColumnIndex] = i;
    // }
    Producer<TableListResult> prod = () -> {
        // Create hidden column with original row index so original row index can
        // be returned for user selections even if rows are sorted
        int hiddenColumnIndex = rowDataOrig[0].length;
        Object[][] rowDataHiddenIndex = rowDataOrig;
        if (rowSortComparator != null) {
            rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex + 1];
            for (int i = 0; i < rowDataHiddenIndex.length; i++) {
                for (int j = 0; j < rowDataOrig[i].length; j++) {
                    rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
                }
                rowDataHiddenIndex[i][hiddenColumnIndex] = i;
            }
        }
        @SuppressWarnings("serial") VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(columnNames, rowDataOrig.length) {

            @Override
            public boolean isSortable(int col) {
                if (rowSortComparator != null) {
                    return true;
                }
                return false;
            }

            public Object getValueAt(int row, int column) {
                return getValueAt(row)[column];
            }

            @Override
            public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
                return new Comparator<Object[]>() {

                    public int compare(Object[] o1, Object[] o2) {
                        if (ascending) {
                            return rowSortComparator.compare(o1[col], o2[col]);
                        }
                        return rowSortComparator.compare(o2[col], o1[col]);
                    }
                };
            }
        };
        final JSortTable table = new JSortTable();
        // table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        table.setModel(tableModel);
        tableModel.setData(Arrays.asList(rowDataHiddenIndex));
        if (listSelectionModel_SelectMode != null) {
            table.setSelectionMode(listSelectionModel_SelectMode);
        } else {
            table.setRowSelectionAllowed(false);
            table.setColumnSelectionAllowed(false);
        }
        table.setPreferredScrollableViewportSize(new Dimension(500, 250));
        table.disableUneditableForeground();
        OKEnabler tableListOKEnabler = null;
        if (listSelectionModel_SelectMode != null) {
            tableListOKEnabler = new OKEnabler() {

                private JOptionPane jop;

                public void setJOptionPane(JOptionPane joptionPane) {
                    jop = joptionPane;
                    setInternalNotCancelEnabled(joptionPane, false, false);
                    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                        public void valueChanged(ListSelectionEvent e) {
                            if (!e.getValueIsAdjusting()) {
                                if (table.getSelectedRowCount() != 0) {
                                    setInternalNotCancelEnabled(jop, true, false);
                                } else {
                                    setInternalNotCancelEnabled(jop, false, false);
                                }
                            }
                        }
                    });
                }
            };
        }
        if (listSelectionListener != null) {
            table.getSelectionModel().addListSelectionListener(listSelectionListener);
        }
        TableListResult tableListResult = new TableListResult();
        // HACK to fix horizontal scrollbar not showing for large horizontal tables
        // workaround code from: http://bugs.sun.com/view_bug.do?bug_id=4127936
        final JScrollPane[] jScrollPaneArr = new JScrollPane[1];
        Component[] components = table.getEnclosingScrollPane().getComponents();
        for (int i = 0; i < components.length; i++) {
            if (components[i] instanceof JScrollPane) {
                jScrollPaneArr[0] = (JScrollPane) components[i];
                break;
            }
        }
        if (jScrollPaneArr[0] != null) {
            jScrollPaneArr[0].addComponentListener(new ComponentAdapter() {

                @Override
                public void componentResized(ComponentEvent e) {
                    super.componentResized(e);
                    if (table.getPreferredSize().width <= jScrollPaneArr[0].getViewport().getExtentSize().width) {
                        table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
                    } else {
                        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                    }
                }
            });
        }
        if (options == null) {
            if (bModal) {
                if (showComponentOKCancelDialog(requester, table.getEnclosingScrollPane(), title, tableListOKEnabler) != JOptionPane.OK_OPTION) {
                    throw UserCancelException.CANCEL_GENERIC;
                }
            } else {
                // display non-modal
                JOptionPane jOptionPane = new JOptionPane(table.getEnclosingScrollPane(), JOptionPane.INFORMATION_MESSAGE);
                JDialog jDialog = jOptionPane.createDialog(requester, title);
                jDialog.setResizable(true);
                jDialog.setModal(false);
                jDialog.pack();
                jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
                jDialog.setVisible(true);
            }
            tableListResult.selectedTableRows = table.getSelectedRows();
        } else {
            tableListResult.selectedOption = showOptionsDialog(requester, table.getEnclosingScrollPane(), JOptionPane.QUESTION_MESSAGE, options, initOption, tableListOKEnabler, title);
            tableListResult.selectedTableRows = table.getSelectedRows();
        }
        if (rowSortComparator != null) {
            // return the index of the original unsorted object array that corresponds to the user row selections
            for (int i = 0; i < tableListResult.selectedTableRows.length; i++) {
                tableListResult.selectedTableRows[i] = (Integer) (tableModel.getValueAt(tableListResult.selectedTableRows[i])[hiddenColumnIndex]);
            }
        }
        return tableListResult;
    };
    return VCSwingFunction.executeAsRuntimeException(prod);
}
Also used : JScrollPane(javax.swing.JScrollPane) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Dimension(java.awt.Dimension) JOptionPane(javax.swing.JOptionPane) Comparator(java.util.Comparator) ListSelectionListener(javax.swing.event.ListSelectionListener) JSortTable(org.vcell.util.gui.sorttable.JSortTable) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) ComponentEvent(java.awt.event.ComponentEvent) ComponentAdapter(java.awt.event.ComponentAdapter) JDialog(javax.swing.JDialog)

Example 2 with JSortTable

use of org.vcell.util.gui.sorttable.JSortTable in project vcell by virtualcell.

the class BioModelEditorPathwayPanel method initialize.

private void initialize() {
    table = new JSortTable();
    tableModel = new PathwayTableModel(table);
    table.setModel(tableModel);
    table.disableUneditableForeground();
    importButton = new JButton("Import", new DownArrowIcon());
    importButton.setHorizontalTextPosition(SwingConstants.LEFT);
    importButton.setEnabled(false);
    importButton.addActionListener(eventHandler);
    table.getSelectionModel().addListSelectionListener(eventHandler);
    int gridy = 0;
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.weightx = 1.0;
    gbc.gridwidth = 6;
    gbc.fill = GridBagConstraints.BOTH;
    pathwayTitleLabel = new JLabel();
    pathwayTitleLabel.setFont(pathwayTitleLabel.getFont().deriveFont(Font.BOLD));
    pathwayTitleLabel.setHorizontalAlignment(JLabel.CENTER);
    add(pathwayTitleLabel, gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.gridwidth = 6;
    gbc.fill = GridBagConstraints.BOTH;
    add(table.getEnclosingScrollPane(), gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.anchor = GridBagConstraints.LINE_END;
    gbc.insets = new Insets(4, 4, 4, 4);
    add(new JLabel("Search "), gbc);
    textFieldSearch = new JTextField(15);
    textFieldSearch.addActionListener(eventHandler);
    textFieldSearch.getDocument().addDocumentListener(eventHandler);
    textFieldSearch.putClientProperty("JTextField.variant", "search");
    gbc = new java.awt.GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.weighty = 0;
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.anchor = GridBagConstraints.LINE_START;
    gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(4, 4, 4, 4);
    add(textFieldSearch, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 3;
    gbc.gridy = gridy;
    gbc.insets = new Insets(4, 20, 4, 4);
    gbc.anchor = GridBagConstraints.LINE_END;
    importButton.setPreferredSize(importButton.getPreferredSize());
    add(importButton, gbc);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JSortTable(org.vcell.util.gui.sorttable.JSortTable) GridBagLayout(java.awt.GridBagLayout) JButton(javax.swing.JButton) DownArrowIcon(org.vcell.util.gui.DownArrowIcon) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) GridBagConstraints(java.awt.GridBagConstraints)

Example 3 with JSortTable

use of org.vcell.util.gui.sorttable.JSortTable in project vcell by virtualcell.

the class BioPaxRelationshipPanel method initialize.

private void initialize() {
    try {
        setName("KineticsTypeTemplatePanel");
        setLayout(new GridBagLayout());
        table = new JSortTable();
        tableModel = new BioPaxRelationshipTableModel(table);
        table.setModel(tableModel);
        table.disableUneditableForeground();
        int gridy = 0;
        GridBagConstraints gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 0.01;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        JLabel info = new JLabel("Edit physiology links by checking or unchecking the Link boxes.");
        add(info, gbc);
        gridy++;
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.insets = new Insets(4, 4, 4, 4);
        table.setPreferredScrollableViewportSize(new Dimension(200, 200));
        add(table.getEnclosingScrollPane(), gbc);
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 8;
        gbc.gridy = gridy;
        add(Box.createRigidArea(new Dimension(0, 75)), gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.insets = new Insets(4, 4, 4, 4);
        add(new JLabel("Search "), gbc);
        textFieldSearch = new JTextField(30);
        textFieldSearch.addActionListener(eventHandler);
        textFieldSearch.getDocument().addDocumentListener(eventHandler);
        textFieldSearch.putClientProperty("JTextField.variant", "search");
        gbc = new java.awt.GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.gridwidth = 3;
        gbc.anchor = GridBagConstraints.LINE_START;
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 0, 4, 0);
        add(textFieldSearch, gbc);
        showLinkedEntityCheckBox = new JCheckBox("Show linked physiology objects only");
        showLinkedEntityCheckBox.setBackground(Color.white);
        showLinkedEntityCheckBox.addActionListener(eventHandler);
        gbc = new java.awt.GridBagConstraints();
        gbc.gridx = 4;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.LINE_END;
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 10, 4, 0);
        add(showLinkedEntityCheckBox, gbc);
        setBackground(Color.white);
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) GridBagConstraints(java.awt.GridBagConstraints) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) JSortTable(org.vcell.util.gui.sorttable.JSortTable)

Example 4 with JSortTable

use of org.vcell.util.gui.sorttable.JSortTable in project vcell by virtualcell.

the class TestingFrameworkWindowManager method queryTCritCrossRef.

@SuppressWarnings("serial")
public void queryTCritCrossRef(final TestSuiteInfoNew tsin, final TestCriteriaNew tcrit, final String varName) {
    try {
        QueryTestCriteriaCrossRefOP queryTestCriteriaCrossRefOP = new QueryTestCriteriaCrossRefOP(tsin.getTSKey(), tcrit.getTCritKey(), varName);
        TestCriteriaCrossRefOPResults testCriteriaCrossRefOPResults = (TestCriteriaCrossRefOPResults) getRequestManager().getDocumentManager().doTestSuiteOP(queryTestCriteriaCrossRefOP);
        final Vector<TestCriteriaCrossRefOPResults.CrossRefData> xrefDataV = testCriteriaCrossRefOPResults.getCrossRefData();
        final TestSuiteInfoNew[] testSuiteInfos = getRequestManager().getDocumentManager().getTestSuiteInfos();
        Vector<TestSuiteInfoNew> missingTestSuites = new Vector<TestSuiteInfoNew>();
        for (int i = 0; i < testSuiteInfos.length; i++) {
            boolean bFound = false;
            for (int j = 0; j < xrefDataV.size(); j++) {
                if (xrefDataV.elementAt(j).tsVersion.equals(testSuiteInfos[i].getTSID())) {
                    bFound = true;
                    break;
                }
            }
            if (!bFound) {
                missingTestSuites.add(testSuiteInfos[i]);
            }
        }
        TestCriteriaCrossRefOPResults.CrossRefData xrefDataSource = null;
        for (int i = 0; i < xrefDataV.size(); i++) {
            if (xrefDataV.elementAt(i).tcritKey.equals(tcrit.getTCritKey())) {
                xrefDataSource = xrefDataV.elementAt(i);
                break;
            }
        }
        if (xrefDataSource == null) {
            throw new RuntimeException("Couldn't find source Test Criteria in query results.");
        }
        final int numColumns = 8;
        final int XREFDATA_ALLOWANCE = 1;
        final int TSKEY_ALLOWANCE = 1;
        final int XREFDATA_OFFSET = numColumns;
        final int TSDATE_OFFSET = 1;
        final int VARNAME_OFFSET = 3;
        final int TSKEYMISSING_OFFSET = numColumns + 1;
        final String[] colNames = new String[numColumns];
        final Object[][] sourceRows = new Object[xrefDataV.size() + missingTestSuites.size()][numColumns + XREFDATA_ALLOWANCE + TSKEY_ALLOWANCE];
        String sourceTestSuite = null;
        colNames[0] = "tsVersion";
        colNames[1] = "tsDate";
        colNames[2] = "tsBaseVersion";
        colNames[3] = "varName";
        colNames[4] = "RelErorr";
        colNames[5] = "limitRelErorr";
        colNames[6] = "limitAbsErorr";
        colNames[7] = "AbsErorr";
        for (int i = 0; i < xrefDataV.size(); i++) {
            sourceRows[i][colNames.length] = xrefDataV.elementAt(i);
            if (xrefDataV.elementAt(i).tcritKey.equals(queryTestCriteriaCrossRefOP.getTestCriterium())) {
                sourceTestSuite = xrefDataV.elementAt(i).tsVersion;
            }
            sourceRows[i][0] = xrefDataV.elementAt(i).tsVersion;
            sourceRows[i][2] = (xrefDataV.elementAt(i).tsRefVersion == null ? (xrefDataV.elementAt(i).regressionModelID == null ? /* && xrefDataV.elementAt(i).regressionMMref==null*/
            "" : "Ref Model exist BUT outside of TestSuites") : xrefDataV.elementAt(i).tsRefVersion);
            sourceRows[i][6] = xrefDataV.elementAt(i).maxAbsErorr;
            sourceRows[i][5] = xrefDataV.elementAt(i).maxRelErorr;
            if (xrefDataV.elementAt(i).varName != null) {
                sourceRows[i][VARNAME_OFFSET] = xrefDataV.elementAt(i).varName;
                sourceRows[i][4] = xrefDataV.elementAt(i).varCompSummary.getRelativeError();
                sourceRows[i][7] = xrefDataV.elementAt(i).varCompSummary.getAbsoluteError();
            } else {
                sourceRows[i][VARNAME_OFFSET] = "-No Report-";
                // "No Report";
                sourceRows[i][4] = null;
                // "No Report";
                sourceRows[i][7] = null;
            }
            for (int j = 0; j < testSuiteInfos.length; j++) {
                if (xrefDataV.elementAt(i).tsVersion.equals(testSuiteInfos[j].getTSID())) {
                    sourceRows[i][1] = testSuiteInfos[j].getTSDate();
                    break;
                }
            }
        }
        for (int i = xrefDataV.size(); i < sourceRows.length; i++) {
            sourceRows[i][0] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSID();
            sourceRows[i][TSDATE_OFFSET] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSDate();
            sourceRows[i][TSKEYMISSING_OFFSET] = missingTestSuites.elementAt(i - xrefDataV.size()).getTSKey();
        }
        // Arrays.sort(rows,
        // new Comparator<Object[]>(){
        // public int compare(Object[] o1, Object[] o2) {
        // return ((String)o1[0]).compareToIgnoreCase((String)o2[0]);
        // //						if(o1[0].equals(o2[0])){
        // //							return o1[3].compareToIgnoreCase(o2[3]);
        // //						}
        // //						return o1[0].compareToIgnoreCase(o2[0]);
        // }
        // }
        // );
        final VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(colNames) {

            public Class<?> getColumnClass(int columnIndex) {
                if (columnIndex == TSDATE_OFFSET) {
                    return Date.class;
                } else if (columnIndex >= 4 && columnIndex <= 7) {
                    return Double.class;
                }
                return String.class;
            }

            public boolean isCellEditable(int row, int column) {
                return false;
            }

            public Object getValueAt(int rowIndex, int columnIndex) {
                return getValueAt(rowIndex)[columnIndex];
            }

            public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
                return new Comparator<Object[]>() {

                    public int compare(Object[] o1, Object[] o2) {
                        if (o1[col] == null && o2[col] == null) {
                            return 0;
                        }
                        // if(ascending){
                        if (o1[col] == null) {
                            return 1;
                        }
                        if (o2[col] == null) {
                            return -1;
                        }
                        // }
                        if (getColumnClass(col).equals(String.class)) {
                            if (ascending) {
                                return ((String) o1[col]).compareToIgnoreCase(((String) o2[col]));
                            } else {
                                return ((String) o2[col]).compareToIgnoreCase(((String) o1[col]));
                            }
                        } else if (getColumnClass(col).equals(Date.class)) {
                            if (ascending) {
                                return ((Date) o1[col]).compareTo(((Date) o2[col]));
                            }
                            return ((Date) o2[col]).compareTo(((Date) o1[col]));
                        } else if (getColumnClass(col).equals(Double.class)) {
                            if (ascending) {
                                return ((Double) o1[col]).compareTo(((Double) o2[col]));
                            }
                            return ((Double) o2[col]).compareTo(((Double) o1[col]));
                        }
                        throw new RuntimeException("TestSuite XRef Query unexpecte column class " + getColumnClass(col).getName());
                    }
                };
            }
        };
        tableModel.setData(Arrays.asList(sourceRows));
        // Create table
        final JSortTable table = new JSortTable();
        table.setModel(tableModel);
        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        final JScrollPane scrollPaneContentPane = new JScrollPane(table);
        table.setPreferredScrollableViewportSize(new Dimension(500, 250));
        table.getColumnModel().getColumn(TSDATE_OFFSET).setCellRenderer(new DefaultTableCellRenderer() {

            // DateFormat formatter = DateFormat.getDateTimeInstance();
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                return super.getTableCellRendererComponent(table, (value == null ? null : ((Date) value).toString()), /*formatter.format((Date)value)*/
                isSelected, hasFocus, row, column);
            }
        });
        DefaultTableCellRenderer dtcr = new DefaultTableCellRenderer() {

            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                return super.getTableCellRendererComponent(table, (value == null ? null : ((Double) value).toString()), /*formatter.format((Date)value)*/
                isSelected, hasFocus, row, column);
            }
        };
        table.getColumnModel().getColumn(4).setCellRenderer(dtcr);
        table.getColumnModel().getColumn(5).setCellRenderer(dtcr);
        table.getColumnModel().getColumn(6).setCellRenderer(dtcr);
        table.getColumnModel().getColumn(7).setCellRenderer(dtcr);
        // table.getColumnModel().getColumn(4).setCellRenderer(
        // new DefaultTableCellRenderer(){
        // public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        // return super.getTableCellRendererComponent(table,(value == null?null:((Double)value).toString())/*formatter.format((Date)value)*/, isSelected, hasFocus, row, column);
        // }
        // }
        // );
        // table.getTableHeader().setReorderingAllowed(false);
        // Popup Menu
        final TestCriteriaCrossRefOPResults.CrossRefData xrefDataSourceFinal = xrefDataSource;
        final JPopupMenu queryPopupMenu = new JPopupMenu();
        final JMenuItem changeLimitsMenuItem = new JMenuItem("Change Selected Error Limits...");
        final String OPEN_MODEL = "Open Model(s)";
        final JMenuItem openModelMenuItem = new JMenuItem(OPEN_MODEL);
        final String OPEN_REGRREFMODEL = "Open Regr Ref Model(s)";
        final JMenuItem openRegrRefModelMenuItem = new JMenuItem(OPEN_REGRREFMODEL);
        final String SELECT_REF_IN_TREE = "Select in Tree View";
        final JMenuItem showInTreeMenuItem = new JMenuItem(SELECT_REF_IN_TREE);
        final String SELECT_REGR_REF_IN_TREE = "Select RegrRef TCase in Tree View";
        final JMenuItem showRegrRefInTreeMenuItem = new JMenuItem(SELECT_REGR_REF_IN_TREE);
        queryPopupMenu.add(changeLimitsMenuItem);
        queryPopupMenu.add(openModelMenuItem);
        queryPopupMenu.add(openRegrRefModelMenuItem);
        queryPopupMenu.add(showInTreeMenuItem);
        queryPopupMenu.add(showRegrRefInTreeMenuItem);
        ActionListener showInTreeActionListener = new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                int[] selectedRows = table.getSelectedRows();
                if (selectedRows == null || selectedRows.length != 1) {
                    PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Action " + actionEvent.getActionCommand() + " accepts only single selection!");
                    return;
                }
                TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[0], XREFDATA_OFFSET);
                BigDecimal missingTSKey = (BigDecimal) tableModel.getValueAt(selectedRows[0], TSKEYMISSING_OFFSET);
                if (actionEvent.getActionCommand().equals(SELECT_REF_IN_TREE)) {
                    getTestingFrameworkWindowPanel().selectInTreeView((xrefData != null ? xrefData.tsKey : missingTSKey), (xrefData != null ? xrefData.tcaseKey : null), (xrefData != null ? xrefData.tcritKey : null));
                } else if (actionEvent.getActionCommand().equals(SELECT_REGR_REF_IN_TREE)) {
                    if (xrefData == null) {
                        PopupGenerator.showErrorDialog(getComponent(), "No Regression Reference info available.");
                        return;
                    }
                    getTestingFrameworkWindowPanel().selectInTreeView((xrefData != null ? xrefData.regressionModelTSuiteID : null), (xrefData != null ? xrefData.regressionModelTCaseID : null), (xrefData != null ? xrefData.regressionModelTCritID : null));
                }
                ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                if (childWindow != null) {
                    childWindow.show();
                }
            }
        };
        showInTreeMenuItem.addActionListener(showInTreeActionListener);
        showRegrRefInTreeMenuItem.addActionListener(showInTreeActionListener);
        ActionListener openModelsActionListener = new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                int[] selectedRows = table.getSelectedRows();
                String failureS = "";
                TestCriteriaCrossRefOPResults.CrossRefData xrefData = null;
                int openCount = 0;
                for (int i = 0; i < selectedRows.length; i++) {
                    try {
                        xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[i], XREFDATA_OFFSET);
                        if (xrefData != null && (actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID != null : true)) {
                            openCount += 1;
                            VCDocumentInfo vcDocInfo = null;
                            if (xrefData.isBioModel) {
                                vcDocInfo = getRequestManager().getDocumentManager().getBioModelInfo(new KeyValue((actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID : xrefData.modelID)));
                            } else {
                                vcDocInfo = getRequestManager().getDocumentManager().getMathModelInfo(new KeyValue((actionEvent.getActionCommand().equals(OPEN_REGRREFMODEL) ? xrefData.regressionModelID : xrefData.modelID)));
                            }
                            getRequestManager().openDocument(vcDocInfo, TestingFrameworkWindowManager.this, true);
                        }
                    } catch (Exception e) {
                        failureS += failureS + "key=" + xrefData.modelID + " " + e.getMessage() + "\n";
                        e.printStackTrace();
                    }
                }
                if (failureS.length() > 0 || openCount == 0) {
                    PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Failed to open some models\n" + failureS + (openCount == 0 ? "Selection(s) had no model(s)" : ""));
                }
                ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                if (childWindow != null) {
                    childWindow.show();
                }
            }
        };
        openModelMenuItem.addActionListener(openModelsActionListener);
        openRegrRefModelMenuItem.addActionListener(openModelsActionListener);
        changeLimitsMenuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent actionEvent) {
                int[] selectedRows = table.getSelectedRows();
                Vector<TestCriteriaCrossRefOPResults.CrossRefData> changeTCritV = new Vector<TestCriteriaCrossRefOPResults.CrossRefData>();
                for (int i = 0; i < selectedRows.length; i++) {
                    TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(selectedRows[i], XREFDATA_OFFSET);
                    if (xrefData != null) {
                        boolean bFound = false;
                        for (int j = 0; j < changeTCritV.size(); j++) {
                            if (changeTCritV.elementAt(j).tcritKey.equals(xrefData.tcritKey)) {
                                bFound = true;
                                break;
                            }
                        }
                        if (!bFound) {
                            changeTCritV.add(xrefData);
                        }
                    }
                }
                if (changeTCritV.size() > 0) {
                    Double relativeErrorLimit = null;
                    Double absoluteErrorLimit = null;
                    while (true) {
                        try {
                            String ret = PopupGenerator.showInputDialog(getComponent(), "Enter new TestCriteria Error Limits for '" + xrefDataSourceFinal.simName + "'.  '-'(dash) to keep original value.", "RelativeErrorLimit,AbsoluteErrorLimit");
                            int commaPosition = ret.indexOf(',');
                            if (commaPosition == -1) {
                                throw new Exception("No comma found separating RelativeErrorLimit AbsoluteErrorLimit");
                            }
                            if (commaPosition != ret.lastIndexOf(',')) {
                                throw new Exception("Only 1 comma allowed separating RelativeErrorLimit and AbsoluteErrorLimit");
                            }
                            final String KEEP_ORIGINAL_VALUE = "-";
                            String relativeErrorS = ret.substring(0, commaPosition);
                            String absoluteErrorS = ret.substring(commaPosition + 1, ret.length());
                            if (!relativeErrorS.equals(KEEP_ORIGINAL_VALUE)) {
                                relativeErrorLimit = Double.parseDouble(relativeErrorS);
                            }
                            if (!absoluteErrorS.equals(KEEP_ORIGINAL_VALUE)) {
                                absoluteErrorLimit = Double.parseDouble(absoluteErrorS);
                            }
                            if ((relativeErrorLimit != null && relativeErrorLimit <= 0) || (absoluteErrorLimit != null && absoluteErrorLimit <= 0)) {
                                throw new Exception("Error limits must be greater than 0");
                            }
                            break;
                        } catch (UserCancelException e) {
                            ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                            if (childWindow != null) {
                                childWindow.show();
                            }
                            return;
                        } catch (Exception e) {
                            PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Error parsing Error Limits\n" + e.getMessage());
                        }
                    }
                    double[] relErrorLimitArr = new double[changeTCritV.size()];
                    double[] absErrorLimitArr = new double[changeTCritV.size()];
                    Object[][] rows = new Object[changeTCritV.size()][5];
                    for (int j = 0; j < changeTCritV.size(); j++) {
                        relErrorLimitArr[j] = (relativeErrorLimit != null ? relativeErrorLimit.doubleValue() : changeTCritV.elementAt(j).maxRelErorr);
                        absErrorLimitArr[j] = (absoluteErrorLimit != null ? absoluteErrorLimit.doubleValue() : changeTCritV.elementAt(j).maxAbsErorr);
                        rows[j][2] = new Double(relErrorLimitArr[j]);
                        rows[j][4] = new Double(absErrorLimitArr[j]);
                        rows[j][1] = new Double(changeTCritV.elementAt(j).maxRelErorr);
                        rows[j][3] = new Double(changeTCritV.elementAt(j).maxAbsErorr);
                        rows[j][0] = changeTCritV.elementAt(j).tsVersion;
                    }
                    try {
                        PopupGenerator.showComponentOKCancelTableList(getComponent(), "Confirm Error Limit Changes", new String[] { "TSVersion", "Orig RelErrorLimit", "New RelErrorLimit", "Orig AbsErrorLimit", "New AbsErrorLimit" }, rows, null);
                    } catch (UserCancelException e) {
                        ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                        if (childWindow != null) {
                            childWindow.show();
                        }
                        return;
                    }
                    // Get information needed to generate new TestCriteria Reports
                    final String YES_ANSWER = "Yes";
                    Hashtable<TestSuiteInfoNew, Vector<TestCriteriaCrossRefOPResults.CrossRefData>> genReportHash = null;
                    String genRepResult = PopupGenerator.showWarningDialog(getComponent(), "Generate Reports for changed Test Criterias?", new String[] { YES_ANSWER, "No" }, YES_ANSWER);
                    if (genRepResult != null && genRepResult.equals(YES_ANSWER)) {
                        genReportHash = new Hashtable<TestSuiteInfoNew, Vector<TestCriteriaCrossRefOPResults.CrossRefData>>();
                        for (int i = 0; i < changeTCritV.size(); i++) {
                            boolean bFound = false;
                            for (int j = 0; j < testSuiteInfos.length; j++) {
                                if (changeTCritV.elementAt(i).tsVersion.equals(testSuiteInfos[j].getTSID())) {
                                    bFound = true;
                                    Vector<TestCriteriaCrossRefOPResults.CrossRefData> tempV = genReportHash.get(testSuiteInfos[j]);
                                    if (tempV == null) {
                                        tempV = new Vector<TestCriteriaCrossRefOPResults.CrossRefData>();
                                        genReportHash.put(testSuiteInfos[j], tempV);
                                    }
                                    tempV.add(changeTCritV.elementAt(i));
                                }
                            }
                            if (!bFound) {
                                PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Couldn't find testsuiteinfo for testcriteria");
                                return;
                            }
                        }
                    }
                    BigDecimal[] changeTCritBDArr = new BigDecimal[changeTCritV.size()];
                    for (int i = 0; i < changeTCritV.size(); i++) {
                        changeTCritBDArr[i] = changeTCritV.elementAt(i).tcritKey;
                    }
                    ChangeTestCriteriaErrorLimitOP changeTestCriteriaErrorLimitOP = new ChangeTestCriteriaErrorLimitOP(changeTCritBDArr, absErrorLimitArr, relErrorLimitArr);
                    try {
                        getTestingFrameworkWindowPanel().getDocumentManager().doTestSuiteOP(changeTestCriteriaErrorLimitOP);
                    } catch (Exception e) {
                        PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Failed Changing Error limits for selected " + xrefDataSourceFinal.simName + "\n" + e.getMessage());
                        return;
                    }
                    ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).getChildWindowFromContentPane(scrollPaneContentPane);
                    if (childWindow != null) {
                        childWindow.close();
                    }
                    getTestingFrameworkWindowPanel().refreshTree((TestSuiteInfoNew) null);
                    if (genReportHash != null) {
                        updateReports(genReportHash);
                    } else {
                        new Thread(new Runnable() {

                            public void run() {
                                TestingFrameworkWindowManager.this.queryTCritCrossRef(tsin, tcrit, varName);
                            }
                        }).start();
                    }
                } else {
                    PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "No selected rows contain Test Criteria.");
                }
            }
        });
        table.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                checkPopup(e);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                super.mousePressed(e);
                checkPopup(e);
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                super.mouseReleased(e);
                checkPopup(e);
            }

            private void checkPopup(MouseEvent mouseEvent) {
                if (mouseEvent.isPopupTrigger()) {
                    // Not use because popupmenu will not show at edge
                    // if(table.getSelectedRowCount() <= 1){
                    // table.getSelectionModel().setSelectionInterval(table.rowAtPoint(mouseEvent.getPoint()),table.rowAtPoint(mouseEvent.getPoint()));
                    // }
                    doPopup(mouseEvent);
                } else {
                    queryPopupMenu.setVisible(false);
                }
            }

            private void doPopup(MouseEvent mouseEvent) {
                // queryPopupMenu.add(showInTreeMenuItem);
                if (table.getSelectedRowCount() == 0) {
                    changeLimitsMenuItem.setEnabled(false);
                    openModelMenuItem.setEnabled(false);
                    openRegrRefModelMenuItem.setEnabled(false);
                    showInTreeMenuItem.setEnabled(false);
                    showRegrRefInTreeMenuItem.setEnabled(false);
                } else {
                    changeLimitsMenuItem.setEnabled(true);
                    openModelMenuItem.setEnabled(true);
                    openRegrRefModelMenuItem.setEnabled(true);
                    showInTreeMenuItem.setEnabled(true);
                    if (table.getSelectedRowCount() == 1) {
                        TestCriteriaCrossRefOPResults.CrossRefData xrefData = (TestCriteriaCrossRefOPResults.CrossRefData) tableModel.getValueAt(table.getSelectedRow(), numColumns);
                        showRegrRefInTreeMenuItem.setEnabled(xrefData != null && xrefData.regressionModelID != null && xrefData.tsRefVersion != null);
                    }
                }
                queryPopupMenu.show(mouseEvent.getComponent(), mouseEvent.getPoint().x, mouseEvent.getPoint().y);
            }
        });
        String title = (xrefDataSource.isBioModel ? "BM" : "MM") + " " + xrefDataSource.tcSolutionType + " (" + sourceTestSuite + ") " + " \"" + (xrefDataSource.isBioModel ? xrefDataSource.bmName : xrefDataSource.mmName) + "\"  ::  " + (xrefDataSource.isBioModel ? "app=\"" + xrefDataSource.bmAppName + "\"  ::  sim=\"" + xrefDataSource.simName + "\"" : "sim=\"" + xrefDataSource.simName + "\"");
        ChildWindow childWindow = TFWFinder.findChildWindowManager(getComponent()).addChildWindow(scrollPaneContentPane, scrollPaneContentPane, title);
        // childWindow.setSize(600,400);
        childWindow.setIsCenteredOnParent();
        childWindow.pack();
        childWindow.setResizable(true);
        childWindow.show();
    } catch (DataAccessException e) {
        e.printStackTrace();
        PopupGenerator.showErrorDialog(TestingFrameworkWindowManager.this, "Error Query TestCriteria Cross Ref:\n" + e.getMessage());
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) ActionEvent(java.awt.event.ActionEvent) UserCancelException(org.vcell.util.UserCancelException) Comparator(java.util.Comparator) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) Component(java.awt.Component) JComponent(javax.swing.JComponent) JMenuItem(javax.swing.JMenuItem) Vector(java.util.Vector) CrossRefData(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults.CrossRefData) DataAccessException(org.vcell.util.DataAccessException) JScrollPane(javax.swing.JScrollPane) QueryTestCriteriaCrossRefOP(cbit.vcell.numericstest.QueryTestCriteriaCrossRefOP) MouseEvent(java.awt.event.MouseEvent) Hashtable(java.util.Hashtable) MouseAdapter(java.awt.event.MouseAdapter) TestCriteriaCrossRefOPResults(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults) Dimension(java.awt.Dimension) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Date(java.util.Date) JPopupMenu(javax.swing.JPopupMenu) BigDecimal(java.math.BigDecimal) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) CrossRefData(cbit.vcell.numericstest.TestCriteriaCrossRefOPResults.CrossRefData) JSortTable(org.vcell.util.gui.sorttable.JSortTable) ActionListener(java.awt.event.ActionListener) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) ChangeTestCriteriaErrorLimitOP(cbit.vcell.numericstest.ChangeTestCriteriaErrorLimitOP) JTable(javax.swing.JTable) TestSuiteInfoNew(cbit.vcell.numericstest.TestSuiteInfoNew)

Example 5 with JSortTable

use of org.vcell.util.gui.sorttable.JSortTable in project vcell by virtualcell.

the class ServerManageConsole method getServiceStatusTable.

/**
 * Return the ServiceStatusTable property value.
 * @return cbit.vcell.messaging.admin.sorttable.JSortTable
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private JSortTable getServiceStatusTable() {
    if (ivjServiceStatusTable == null) {
        try {
            ivjServiceStatusTable = new JSortTable();
            ivjServiceStatusTable.setModel(new ServiceInstanceStatusTableModel());
            ivjServiceStatusTable.disableUneditableForeground();
        // ivjServiceStatusTable.setBounds(0, 0, 200, 200);
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    return ivjServiceStatusTable;
}
Also used : JSortTable(org.vcell.util.gui.sorttable.JSortTable)

Aggregations

JSortTable (org.vcell.util.gui.sorttable.JSortTable)21 Dimension (java.awt.Dimension)4 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 Insets (java.awt.Insets)4 JLabel (javax.swing.JLabel)4 JTextField (javax.swing.JTextField)4 Comparator (java.util.Comparator)3 JScrollPane (javax.swing.JScrollPane)3 JTable (javax.swing.JTable)3 VCellSortTableModel (cbit.vcell.client.desktop.biomodel.VCellSortTableModel)2 Component (java.awt.Component)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 MouseAdapter (java.awt.event.MouseAdapter)2 MouseEvent (java.awt.event.MouseEvent)2 Vector (java.util.Vector)2 JMenuItem (javax.swing.JMenuItem)2 JPopupMenu (javax.swing.JPopupMenu)2 UserCancelException (org.vcell.util.UserCancelException)2