Example usage for javax.swing JTable setModel

List of usage examples for javax.swing JTable setModel

Introduction

In this page you can find the example usage for javax.swing JTable setModel.

Prototype

@BeanProperty(description = "The model that is the source of the data for this view.")
public void setModel(final TableModel dataModel) 

Source Link

Document

Sets the data model for this table to dataModel and registers with it for listener notifications from the new data model.

Usage

From source file:org.nuclos.client.ui.collect.result.ResultController.java

/**
 * TODO: Make this protected again./*from  www .j  a v  a2s.com*/
 */
public void setModel(CollectableTableModel<Clct> tblmodel) {
    final ResultPanel<Clct> panel = getResultPanel();
    final JTable resultTable = panel.getResultTable();
    resultTable.setModel(tblmodel);
    ((ToolTipsTableHeader) resultTable.getTableHeader()).setExternalModel(tblmodel);
    if (tblmodel instanceof SortableTableModel) {
        ((SortableTableModel) tblmodel).addSortingListener(newResultTablePreferencesUpdateListener());
    }
}

From source file:org.simmi.GeneSetHead.java

License:asdf

public Set<String> getSelspec(Component comp, final List<String> specs, final JCheckBox... contigs) {
    final JTable table = new JTable();
    table.setDragEnabled(true);/*from  ww w  .j a v a2  s.  c  om*/
    JScrollPane scroll = new JScrollPane(table);
    table.setAutoCreateRowSorter(true);

    final List<Sequence> ctgs = new ArrayList<Sequence>(geneset.contigmap.values());
    final TableModel contigmodel = new TableModel() {
        @Override
        public int getRowCount() {
            return ctgs.size();
        }

        @Override
        public int getColumnCount() {
            return 1;
        }

        @Override
        public String getColumnName(int columnIndex) {
            return "Contigs/Scaffolds";
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return String.class;
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            return ctgs.get(rowIndex).toString();
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        }

        @Override
        public void addTableModelListener(TableModelListener l) {
        }

        @Override
        public void removeTableModelListener(TableModelListener l) {
        }
    };
    final TableModel specmodel = new TableModel() {
        @Override
        public int getRowCount() {
            return specs.size();
        }

        @Override
        public int getColumnCount() {
            return 2;
        }

        @Override
        public String getColumnName(int columnIndex) {
            return columnIndex == 0 ? "Id" : "Spec";
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return String.class;
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            if (columnIndex == 1)
                return Sequence.nameFix(specs.get(rowIndex), true);
            else
                return specs.get(rowIndex);
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        }

        @Override
        public void addTableModelListener(TableModelListener l) {
        }

        @Override
        public void removeTableModelListener(TableModelListener l) {
        }
    };
    table.setModel(specmodel);

    TransferHandler th = dragRows(table, specs);
    table.setTransferHandler(th);

    if (contigs != null && contigs.length > 0 && !contigs[0].getText().equals("Plasmid"))
        contigs[0].addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                if (contigs[0] != null && contigs[0].isSelected())
                    table.setModel(contigmodel);
                else
                    table.setModel(specmodel);
            }
        });

    Object[] ctls = new Object[] { scroll, contigs };
    //Object[] ctls2 = new Object[] { scroll };

    //if( contigs != null ) 
    JOptionPane.showMessageDialog(comp, ctls);
    //else JOptionPane.showMessageDialog( comp, ctls2 );
    Set<String> selspec = new LinkedHashSet<>();
    for (int i = 0; i < table.getRowCount(); i++) {
        if (table.isRowSelected(i)) {
            String spec = (String) table.getValueAt(i, 0);
            System.err.println("test " + spec);
            selspec.add(spec);
        }
    }
    return selspec;
}

From source file:org.simmi.GeneSetHead.java

License:asdf

public List getSelspecContigs(List<JComponent> complist, final Map<String, List<Sequence>> speccontigMap,
        final String... selspec) {
    List<Sequence> contigs = null;
    final List<String> specs = new ArrayList<String>(speccontigMap.keySet());
    final JTable stable = new JTable();
    stable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final TableModel stablemodel = new TableModel() {
        @Override/*from   w w  w .  j  av  a 2  s .  c om*/
        public int getRowCount() {
            return specs.size();
        }

        @Override
        public int getColumnCount() {
            return 1;
        }

        @Override
        public String getColumnName(int columnIndex) {
            return "Species";
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return String.class;
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            if (rowIndex >= 0 && rowIndex < specs.size())
                return specs.get(rowIndex);
            return null;
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        }

        @Override
        public void addTableModelListener(TableModelListener l) {
        }

        @Override
        public void removeTableModelListener(TableModelListener l) {
        }
    };
    stable.setModel(stablemodel);

    final JTable ctable = new JTable();
    ctable.setAutoCreateRowSorter(true);
    final TableModel ctablemodel = new TableModel() {
        @Override
        public int getRowCount() {
            int r = stable.getSelectedRow();
            String spec = selspec.length > 0 ? selspec[0] : (String) stable.getValueAt(r, 0);
            if (spec != null) {
                List<Sequence> contigs = geneset.speccontigMap.get(spec);
                return contigs.size();
            }
            return 0;
        }

        @Override
        public int getColumnCount() {
            return 1;
        }

        @Override
        public String getColumnName(int columnIndex) {
            return "Contigs";
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return Sequence.class;
        }

        @Override
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return false;
        }

        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
            int r = stable.getSelectedRow();
            String spec = selspec.length > 0 ? selspec[0] : (String) stable.getValueAt(r, 0);
            List<Sequence> contigs = geneset.speccontigMap.get(spec);
            return contigs.get(rowIndex);
        }

        @Override
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        }

        @Override
        public void addTableModelListener(TableModelListener l) {
        }

        @Override
        public void removeTableModelListener(TableModelListener l) {
        }
    };
    ctable.setModel(ctablemodel);

    JScrollPane sscrollpane = new JScrollPane(stable);
    JScrollPane cscrollpane = new JScrollPane(ctable);

    FlowLayout flowlayout = new FlowLayout();
    JComponent c = new JComponent() {
    };
    c.setLayout(flowlayout);
    if (selspec.length == 0)
        c.add(sscrollpane);
    c.add(cscrollpane);

    if (complist != null) {
        for (JComponent comp : complist) {
            c.add(comp);
        }
    }

    stable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            ctable.tableChanged(new TableModelEvent(ctablemodel));
        }
    });
    JOptionPane.showMessageDialog(this, c);

    int[] rr = stable.getSelectedRows();
    if (rr.length > 1) {
        List slist = new ArrayList();
        for (int r : rr) {
            int i = stable.convertRowIndexToModel(r);
            slist.add(specs.get(i));
        }

        return slist;
    } else {
        int sr = stable.getSelectedRow();
        String spec = selspec.length > 0 ? selspec[0] : (String) stable.getValueAt(sr, 0);
        if (spec != null) {
            List<Sequence> ctgs = geneset.speccontigMap.get(spec);
            rr = ctable.getSelectedRows();
            contigs = new ArrayList<Sequence>();
            for (int r : rr) {
                int i = ctable.convertRowIndexToModel(r);
                contigs.add(ctgs.get(i));
            }
        }

        return contigs;
    }
}

From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java

private AbstractWizardPage getPatientFieldsPage() {

    //setup page/*from  w w  w .  j a v  a 2 s.c  om*/
    final DefaultWizardPage page = new DefaultWizardPage(PAGENAME_PATIENTS) {
        @Override
        public void setupWizardButtons() {
            fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK);
            fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.BACK);
            fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH);
            fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);
        }
    };

    page.addText("Add relevant fields for patients. ");

    JScrollPane scrollpane = new JScrollPane();
    scrollpane.setPreferredSize(new Dimension(300, 250));
    scrollpane.getViewport().setBackground(Color.white);

    final JTable table = new JTable() {
        @Override
        public Class<?> getColumnClass(int column) {
            if (column == 2) {
                return Boolean.class;
            } else {
                return String.class;
            }
        }
    };

    patientFormatModel = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int col) {
            return row >= 8;
        }
    };

    patientFormatModel.addColumn("Name");
    patientFormatModel.addColumn("Type");
    patientFormatModel.addColumn("Filterable");
    patientFormatModel.addColumn("Alias");
    patientFormatModel.addColumn("Description");

    patientFormatModel.addRow(new Object[] { FAMILY_ID.getColumnName(), FAMILY_ID.getTypeString(), true,
            FAMILY_ID.getAlias(), "" });
    patientFormatModel.addRow(new Object[] { HOSPITAL_ID.getColumnName(), HOSPITAL_ID.getTypeString(), true,
            HOSPITAL_ID.getAlias(), "" });
    patientFormatModel.addRow(
            new Object[] { IDBIOMOM.getColumnName(), IDBIOMOM.getTypeString(), true, IDBIOMOM.getAlias(), "" });
    patientFormatModel.addRow(
            new Object[] { IDBIODAD.getColumnName(), IDBIODAD.getTypeString(), true, IDBIODAD.getAlias(), "" });
    patientFormatModel.addRow(
            new Object[] { GENDER.getColumnName(), GENDER.getTypeString(), true, GENDER.getAlias(), "" });
    patientFormatModel.addRow(
            new Object[] { AFFECTED.getColumnName(), AFFECTED.getTypeString(), true, AFFECTED.getAlias(), "" });
    patientFormatModel.addRow(
            new Object[] { DNA_IDS.getColumnName(), DNA_IDS.getTypeString(), true, DNA_IDS.getAlias(), "" });
    patientFormatModel.addRow(
            new Object[] { BAM_URL.getColumnName(), BAM_URL.getTypeString(), true, BAM_URL.getAlias(), "" });
    patientFormatModel.addRow(new Object[] { PHENOTYPES.getColumnName(), PHENOTYPES.getTypeString(), true,
            PHENOTYPES.getAlias(), "" });

    if (modify) {
        for (CustomField f : customFields) {
            patientFormatModel.addRow(new Object[] { f.getColumnName(), f.getTypeString(), f.isFilterable(),
                    f.getAlias(), f.getDescription() });
        }
    }

    table.setModel(patientFormatModel);
    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    scrollpane.getViewport().add(table);
    page.addComponent(scrollpane);

    JButton addFieldButton = new JButton("Add Field");
    addFieldButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            patientFormatModel.addRow(new Object[5]);
            table.setModel(patientFormatModel);
        }
    });
    page.addComponent(addFieldButton);

    JButton removeFieldButton = new JButton("Remove Field");
    removeFieldButton.setEnabled(false);
    removeFieldButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            int row = table.getSelectedRow();
            // Minus one because patient_id isn't in the table.
            if (row >= BasicPatientColumns.REQUIRED_PATIENT_FIELDS.length - 1) {
                patientFormatModel.removeRow(row);
            }
            table.setModel(patientFormatModel);
        }
    });
    table.getSelectionModel().addListSelectionListener(
            new RemovalEnabler(BasicPatientColumns.REQUIRED_PATIENT_FIELDS.length - 1, removeFieldButton));
    page.addComponent(removeFieldButton);

    return page;
}

From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java

private AbstractWizardPage getVCFFieldsPage() {

    //setup page/*w  w w . j a  va  2  s . c  o m*/
    final DefaultWizardPage page = new DefaultWizardPage(PAGENAME_VCF) {
        @Override
        public void setupWizardButtons() {
            fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK);
            fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.BACK);
            fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH);
            fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);
        }
    };

    page.addText("Add extra fields to parse from INFO text in VCF files. ");

    JScrollPane scrollpane = new JScrollPane();
    scrollpane.setPreferredSize(new Dimension(300, 250));
    scrollpane.getViewport().setBackground(Color.white);

    final JTable table = new JTable() {
        @Override
        public Class<?> getColumnClass(int column) {
            if (column == 2) {
                return Boolean.class;
            } else {
                return String.class;
            }
        }
    };

    variantFormatModel = new DefaultTableModel();

    variantFormatModel.addColumn("Key");
    variantFormatModel.addColumn("Type");
    variantFormatModel.addColumn("Filterable");
    variantFormatModel.addColumn("Alias");
    variantFormatModel.addColumn("Description");

    if (modify) {
        try {
            int firstRef = manager.getReferenceIDsForProject(LoginController.getSessionID(), projectID)[0];
            CustomField[] fields = manager.getCustomVariantFields(LoginController.getSessionID(), projectID,
                    firstRef,
                    manager.getNewestUpdateID(LoginController.getSessionID(), projectID, firstRef, false));
            for (CustomField f : fields) {
                //casing of f.getColumnName should match database.
                variantFormatModel.addRow(new Object[] { f.getColumnName(), f.getTypeString(), f.isFilterable(),
                        f.getAlias(), f.getDescription() });
            }
        } catch (Exception ex) {
            LOG.error("Error getting reference IDs for project.", ex);
        }
    } else {
        variantFormatModel
                .addRow(new Object[] { AA.getColumnName(), AA.getTypeString(), true, AA.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { AC.getColumnName(), AC.getTypeString(), true, AC.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { AF.getColumnName(), AF.getTypeString(), true, AF.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { AN.getColumnName(), AN.getTypeString(), true, AN.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { BQ.getColumnName(), BQ.getTypeString(), true, BQ.getAlias(), "" });
        variantFormatModel.addRow(
                new Object[] { CIGAR.getColumnName(), CIGAR.getTypeString(), true, CIGAR.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { DB.getColumnName(), DB.getTypeString(), true, DB.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { DP.getColumnName(), DP.getTypeString(), true, DP.getAlias(), "" });
        //variantFormatModel.addRow(new Object[]{END.getColumnName(), END.getTypeString(), true, END.getAlias(), ""});
        variantFormatModel
                .addRow(new Object[] { H2.getColumnName(), H2.getTypeString(), true, H2.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { MQ.getColumnName(), MQ.getTypeString(), true, MQ.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { MQ0.getColumnName(), MQ0.getTypeString(), true, MQ0.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { NS.getColumnName(), NS.getTypeString(), true, NS.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { SB.getColumnName(), SB.getTypeString(), true, SB.getAlias(), "" });
        variantFormatModel.addRow(new Object[] { SOMATIC.getColumnName(), SOMATIC.getTypeString(), true,
                SOMATIC.getAlias(), "" });
        variantFormatModel.addRow(new Object[] { VALIDATED.getColumnName(), VALIDATED.getTypeString(), true,
                VALIDATED.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { JANNOVAR_EFFECT.getColumnName(), JANNOVAR_EFFECT.getTypeString(),
                        JANNOVAR_EFFECT.isFilterable(), JANNOVAR_EFFECT.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { JANNOVAR_SYMBOL.getColumnName(), JANNOVAR_SYMBOL.getTypeString(),
                        JANNOVAR_SYMBOL.isFilterable(), JANNOVAR_SYMBOL.getAlias(), "" });
        variantFormatModel.addRow(new Object[] { FORMAT.getColumnName(), FORMAT.getTypeString(),
                FORMAT.isFilterable(), FORMAT.getAlias(), "" });
        variantFormatModel.addRow(new Object[] { SAMPLE_INFO.getColumnName(), SAMPLE_INFO.getTypeString(),
                SAMPLE_INFO.isFilterable(), SAMPLE_INFO.getAlias(), "" });
    }

    table.setModel(variantFormatModel);
    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    scrollpane.getViewport().add(table);
    page.addComponent(scrollpane);

    table.addKeyListener(new KeyListener() {
        @Override
        public void keyTyped(KeyEvent e) {
            variantFieldsChanged = true;
        }

        @Override
        public void keyPressed(KeyEvent e) {
            variantFieldsChanged = true;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            variantFieldsChanged = true;
        }
    });

    JButton addFieldButton = new JButton("Add Field");
    addFieldButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            variantFormatModel.addRow(new Object[2]);
            table.setModel(variantFormatModel);
            variantFieldsChanged = true;
        }
    });
    page.addComponent(addFieldButton);

    JButton removeFieldButton = new JButton("Remove Field");
    removeFieldButton.setEnabled(false);
    removeFieldButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            int row = table.getSelectedRow();
            if (row >= 0) {
                variantFormatModel.removeRow(row);
                table.setModel(variantFormatModel);
                variantFieldsChanged = true;
            }
        }
    });
    table.getSelectionModel().addListSelectionListener(new RemovalEnabler(0, removeFieldButton));
    page.addComponent(removeFieldButton);

    return page;
}

From source file:qic.ui.QicFrame.java

public QicFrame(Main main, String query) {
    super("QIC Search - Simple GUI");
    setLayout(new BorderLayout(5, 5));

    RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
    textArea.setText("Enter a command in the textfield then press Enter..");
    textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
    textArea.setCodeFoldingEnabled(true);
    RTextScrollPane sp = new RTextScrollPane(textArea);

    JTextField searchTf = new JTextField(100);
    JButton runBtn = new JButton("Run");
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS));
    northPanel.add(searchTf);/*from  w  w  w.  ja  v  a2s  .c o  m*/
    northPanel.add(runBtn);
    getContentPane().add(northPanel, BorderLayout.NORTH);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(screenSize.width - 50, screenSize.height - 50);
    setLocationRelativeTo(null);

    searchTf.setText("search bo tmpsc ");
    if (query != null) {
        searchTf.setText(query);
    }

    JTable table = new JTable();
    table.setDefaultRenderer(List.class, new MultiLineTableCellRenderer());

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Table", new JScrollPane(table));
    tabbedPane.addTab("JSON", new JScrollPane(sp));

    BeanPropertyTableModel<SearchResultItem> model = new BeanPropertyTableModel<>(SearchResultItem.class);
    model.setOrderedProperties(asList("id", "buyout", "item", "seller", "reqs", "mods", "q", "APS", "PDPS",
            "EDPS", "DPS", "ele", "phys", "ar", "ev", "ES", "blk", "crit", "lvl"));
    table.setModel(model);
    setColumnWidths(table.getColumnModel(), asList(1, 15, 280, 230, 50, 420));

    getContentPane().add(tabbedPane, BorderLayout.CENTER);

    ActionListener runCommand = e -> {
        String tfText = searchTf.getText();

        Worker<Command> pathNotesWorker = new Worker<Command>(() -> runQuery(main, tfText), command -> {
            String json = command.toJson();
            textArea.setText(json);
            model.setData(command.itemResults);
        }, ex -> {
            String stackTrace = ExceptionUtils.getStackTrace(ex);
            textArea.setText(stackTrace);
            showError(ex);
        });
        pathNotesWorker.execute();
    };

    searchTf.addActionListener(runCommand);
    runBtn.addActionListener(runCommand);

    table.getSelectionModel().addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            int selectedRow = table.getSelectedRow();
            if (selectedRow > -1) {
                SearchResultItem searchResultItem = model.getData().get(selectedRow);
                SwingUtil.copyToClipboard(searchResultItem.wtb());
            }
        }
    });

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setVisible(true);
}

From source file:uk.ac.ebi.demo.picr.swing.PICRBLASTDemo.java

public PICRBLASTDemo() {

    //set general layout
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    add(Box.createVerticalStrut(5));

    //create components
    JPanel row1 = new JPanel();
    row1.setLayout(new BoxLayout(row1, BoxLayout.X_AXIS));
    row1.add(Box.createHorizontalStrut(5));
    row1.setBorder(BorderFactory.createTitledBorder(""));
    row1.add(new JLabel("Fragment:"));
    row1.add(Box.createHorizontalStrut(10));
    final JTextArea sequenceArea = new JTextArea(5, 40);
    sequenceArea.setMaximumSize(sequenceArea.getPreferredSize());
    row1.add(Box.createHorizontalStrut(10));

    row1.add(sequenceArea);/*from  w w w  . j  a v  a  2 s  .  com*/
    row1.add(Box.createHorizontalGlue());

    JPanel row2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    row2.setBorder(BorderFactory.createTitledBorder("Target Databases"));
    final JList databaseList = new JList();
    JScrollPane listScroller = new JScrollPane(databaseList);
    listScroller.setMaximumSize(new Dimension(100, 10));
    JButton loadDBButton = new JButton("Load Databases");
    row2.add(listScroller);
    row2.add(loadDBButton);

    JPanel row3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JCheckBox onlyActiveCheckBox = new JCheckBox("Only Active");
    onlyActiveCheckBox.setSelected(true);
    row3.add(new JLabel("Options:  "));
    row3.add(onlyActiveCheckBox);

    add(row1);
    add(row2);
    add(row3);

    final String[] columns = new String[] { "Database", "Accession", "Version", "Taxon ID" };
    final JTable dataTable = new JTable(new Object[0][0], columns);
    dataTable.setShowGrid(true);
    add(new JScrollPane(dataTable));

    JPanel buttonPanel = new JPanel();
    JButton mapAccessionButton = new JButton("Generate Mapping!");
    buttonPanel.add(mapAccessionButton);
    add(buttonPanel);

    //create listeners!

    //update boolean flag in communication class
    onlyActiveCheckBox.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            client.setOnlyActive(((JCheckBox) e.getSource()).isSelected());
        }
    });

    //performs mapping call and updates interface with results
    mapAccessionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            try {

                if (!"".equals(sequenceArea.getText())) {
                    //TODO filters and database are hardcoded here.  They should be added to the input panel at a later revision.
                    java.util.List<UPEntry> entries = client.performBlastMapping(sequenceArea.getText(),
                            databaseList.getSelectedValues(), "90", "", "IDENTITY", "UniprotKB", "", false,
                            new BlastParameter());

                    //compute size of array
                    if (entries != null) {
                        int size = 0;
                        for (UPEntry entry : entries) {
                            for (CrossReference xref : entry.getIdenticalCrossReferences()) {
                                size++;
                            }
                            for (CrossReference xref : entry.getLogicalCrossReferences()) {
                                size++;
                            }
                        }

                        if (size > 0) {

                            final Object[][] data = new Object[size][4];
                            int i = 0;
                            for (UPEntry entry : entries) {
                                for (CrossReference xref : entry.getIdenticalCrossReferences()) {
                                    data[i][0] = xref.getDatabaseName();
                                    data[i][1] = xref.getAccession();
                                    data[i][2] = xref.getAccessionVersion();
                                    data[i][3] = xref.getTaxonId();
                                    i++;
                                }
                                for (CrossReference xref : entry.getLogicalCrossReferences()) {
                                    data[i][0] = xref.getDatabaseName();
                                    data[i][1] = xref.getAccession();
                                    data[i][2] = xref.getAccessionVersion();
                                    data[i][3] = xref.getTaxonId();
                                    i++;
                                }
                            }

                            //refresh
                            DefaultTableModel dataModel = new DefaultTableModel();
                            dataModel.setDataVector(data, columns);
                            dataTable.setModel(dataModel);

                            System.out.println("update done");

                        } else {
                            JOptionPane.showMessageDialog(null, "No Mappind data found.");
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "No Mappind data found.");
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "You must enter a valid FASTA sequence to map.");
                }
            } catch (SOAPFaultException soapEx) {
                JOptionPane.showMessageDialog(null, "A SOAP Error occurred.");
                soapEx.printStackTrace();
            }
        }
    });

    //loads list of mapping databases from communication class
    loadDBButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            try {

                java.util.List<String> databases = client.loadDatabases();
                if (databases != null && databases.size() > 0) {

                    databaseList.setListData(databases.toArray());
                    System.out.println("database refresh done");

                } else {
                    JOptionPane.showMessageDialog(null, "No Databases Loaded!.");
                }

            } catch (SOAPFaultException soapEx) {
                JOptionPane.showMessageDialog(null, "A SOAP Error occurred.");
                soapEx.printStackTrace();
            }
        }
    });

}

From source file:utils.ZTransform.java

@Override
public void actionPerformed(ActionEvent e) {
    List<CMatrix> loadedCMatrices = CoolMapMaster.getLoadedCMatrices();
    if (loadedCMatrices == null || loadedCMatrices.isEmpty()) {
        Messenger.showWarningMessage("No datasets were imported.", "No data");
        return;/*  w  w w .  ja va2 s.co m*/
    }

    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            JTable table = new JTable();
            DefaultTableModel defaultTableModel = Utils.getDefaultTableModel();
            table.setModel(defaultTableModel);
            table.getColumnModel().removeColumn(table.getColumnModel().getColumn(0));
            table.getTableHeader().setReorderingAllowed(false);

            int returnVal = JOptionPane.showConfirmDialog(CoolMapMaster.getCMainFrame(), new JScrollPane(table),
                    "Select data", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            if (returnVal == JOptionPane.OK_OPTION) {
                int[] selectedRows = table.getSelectedRows();
                ArrayList<CMatrix> selectedMatrices = new ArrayList<CMatrix>();
                for (int row : selectedRows) {

                    int index = table.convertRowIndexToModel(row);
                    try {
                        String ID = table.getModel().getValueAt(index, 0).toString();
                        CMatrix mx = CoolMapMaster.getCMatrixByID(ID);
                        if (mx != null) {
                            selectedMatrices.add(mx);
                        }
                    } catch (Exception e) {

                    }
                }
                //do
                createZTransform(selectedMatrices);
            }
        }
    });

}