Package javax.swing.table

Examples of javax.swing.table.TableModel


    updateComponents();
  }

  private DCTable getDatabaseDriverTable() {
    final List<DatabaseDriverDescriptor> databaseDrivers = _databaseDriverCatalog.getDatabaseDrivers();
    final TableModel tableModel = new DefaultTableModel(new String[] { "", "Database", "Driver class", "Installed?",
        "Used?" }, databaseDrivers.size());

    final DCTable table = new DCTable(tableModel);

    final Icon validIcon = imageManager.getImageIcon("images/status/valid.png", IconUtils.ICON_SIZE_SMALL);
    final Icon invalidIcon = imageManager.getImageIcon("images/status/error.png", IconUtils.ICON_SIZE_SMALL);

    final int installedCol = 3;
    final int usedCol = 4;
    int row = 0;
    for (final DatabaseDriverDescriptor dd : databaseDrivers) {
      final String driverClassName = dd.getDriverClassName();
      final String displayName = dd.getDisplayName();

      final Icon driverIcon = imageManager.getImageIcon(DatabaseDriverCatalog.getIconImagePath(dd),
          IconUtils.ICON_SIZE_SMALL);

      tableModel.setValueAt(driverIcon, row, 0);
      tableModel.setValueAt(displayName, row, 1);
      tableModel.setValueAt(driverClassName, row, 2);
      tableModel.setValueAt("", row, 3);
      tableModel.setValueAt("", row, 4);

      final DatabaseDriverState state = _databaseDriverCatalog.getState(dd);
      if (state == DatabaseDriverState.INSTALLED_WORKING) {
        tableModel.setValueAt(validIcon, row, installedCol);
      } else if (state == DatabaseDriverState.INSTALLED_NOT_WORKING) {
        tableModel.setValueAt(invalidIcon, row, installedCol);
      } else if (state == DatabaseDriverState.NOT_INSTALLED) {
        final String[] downloadUrls = dd.getDownloadUrls();
        if (downloadUrls != null) {
          final DCPanel buttonPanel = new DCPanel();
          buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0));

          final JButton downloadButton = WidgetFactory.createSmallButton("images/actions/download.png");
          downloadButton.setToolTipText("Download and install the driver for " + dd.getDisplayName());

          downloadButton.addActionListener(createDownloadActionListener(dd));
          buttonPanel.add(downloadButton);

          tableModel.setValueAt(buttonPanel, row, installedCol);
        }
      }

      if (isUsed(driverClassName)) {
        tableModel.setValueAt(validIcon, row, usedCol);
      }

      row++;
    }
View Full Code Here


    }
    updateComponents();
  }

  private void updateComponents() {
    TableModel model = new DefaultTableModel(headers, _columns.size());
    int i = 0;
    Icon icon = imageManager.getImageIcon("images/model/column.png", IconUtils.ICON_SIZE_SMALL);
    for (final InputColumn<?> column : _columns) {
      if (column instanceof MutableInputColumn<?>) {
        final JXTextField textField = WidgetFactory.createTextField("Column name");
        textField.setText(column.getName());
        final MutableInputColumn<?> mutableInputColumn = (MutableInputColumn<?>) column;
        textField.addFocusListener(new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent e) {
            if (!mutableInputColumn.getName().equals(textField.getText())) {
              mutableInputColumn.setName(textField.getText());

              TransformerJobBuilder<?> tjb = _analysisJobBuilder.getOriginatingTransformer(mutableInputColumn);
              if (tjb != null) {
                tjb.onOutputChanged();
              }
            }
          }
        });
        DCPanel panel = new DCPanel();
        panel.setLayout(new HorizontalLayout(4));
        panel.add(new JLabel(icon));
        panel.add(textField);
        model.setValueAt(panel, i, 0);
      } else {
        model.setValueAt(new JLabel(column.getName(), icon, JLabel.LEFT), i, 0);
      }
      model.setValueAt(column.getDataTypeFamily(), i, 1);

      JButton removeButton = WidgetFactory.createSmallButton("images/actions/remove.png");
      removeButton.setToolTipText("Remove column from source");
      removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          _analysisJobBuilder.removeSourceColumn(column.getPhysicalColumn());
        }
      });

      DCPanel buttonPanel = new DCPanel();
      buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 0));
      // buttonPanel.add(transformButton);
      // buttonPanel.add(filterButton);
      if (column.isPhysicalColumn()) {
        buttonPanel.add(removeButton);
      }

      model.setValueAt(buttonPanel, i, 2);
      i++;
    }
    _columnTable.setModel(model);

    TableColumnExt columnExt = _columnTable.getColumnExt(2);
View Full Code Here

    return panel;
  }

  private void applyDistinctValuesView(DCTable table, AnnotatedRowsResult result) {
    InputColumn<?>[] highlightedColumns = result.getHighlightedColumns();
    TableModel tableModel = result.toDistinctValuesTableModel(highlightedColumns[0]);
    table.setModel(tableModel);
    table.setHighlighters(new Highlighter[0]);
  }
View Full Code Here

@RendererBean(SwingRenderingFormat.class)
public class TableModelResultSwingRenderer extends AbstractRenderer<TableModelResult, JComponent> {

  @Override
  public JComponent render(TableModelResult result) {
    TableModel tableModel = result.toTableModel();
    DCTable table = new DCTable(tableModel);
    return table.toPanel();
  }
View Full Code Here

  }

  private DCTable renderTable(Crosstab<?> crosstab) {
    final CrosstabRenderer renderer = new CrosstabRenderer(crosstab);
    final RendererCallback rendererCallback = new RendererCallback();
    final TableModel tableModel = renderer.render(rendererCallback);
    final Alignment alignment = rendererCallback.getAlignment();
    final DCTable table = new DCTable(tableModel);

    table.setSortable(false);
    table.setAlignment(0, Alignment.LEFT);
View Full Code Here

        myLastSelectedItem = myTableNamesCombo.getSelectedItem();
        loadData(myDBFile, (String) myLastSelectedItem, 0);
    }

    public void actionPerformed(ActionEvent e) {
        TableModel model = myDataTable.getModel();
        if (model instanceof DataTableModel) {
            long start = ((DataTableModel) model).getFirstIndex();
            if (e.getSource() == myPreviousButton) {
                start -= myPageSize;
            } else {
View Full Code Here

                        myPreviousButton.setEnabled(false);
                        myNextButton.setEnabled(false);
                        myRangeLabel.setEnabled(false);
                    }
                });
                TableModel model = null;
                if (dbFile == null) {
                    model = new DefaultTableModel();
                } else {
                    // open db and read schema.
                    progress.start("Loading Data...", myPageSize);
View Full Code Here

        reallocateIndexes();
    }

    public int compareRowsByColumn(int row1, int row2, int column) {
        Class type = model.getColumnClass(column);
        TableModel data = model;

        // Check for nulls.

        Object o1 = data.getValueAt(row1, column);
        Object o2 = data.getValueAt(row2, column);

        // If both values are null, return 0.
        if (o1 == null && o2 == null) {
            return 0;
        } else if (o1 == null) { // Define null less than everything.
            return -1;
        } else if (o2 == null) {
            return 1;
        }

        /*
         * We copy all returned values from the getValue call in case
         * an optimised model is reusing one object to return many
         * values.  The Number subclasses in the JDK are immutable and
         * so will not be used in this way but other subclasses of
         * Number might want to do this to save space and avoid
         * unnecessary heap allocation.
         */

        if (type.getSuperclass() == java.lang.Number.class) {
            Number n1 = (Number)data.getValueAt(row1, column);
            double d1 = n1.doubleValue();
            Number n2 = (Number)data.getValueAt(row2, column);
            double d2 = n2.doubleValue();

            if (d1 < d2) {
                return -1;
            } else if (d1 > d2) {
                return 1;
            } else {
                return 0;
            }
        } else if (type == java.util.Date.class) {
            Date d1 = (Date)data.getValueAt(row1, column);
            long n1 = d1.getTime();
            Date d2 = (Date)data.getValueAt(row2, column);
            long n2 = d2.getTime();

            if (n1 < n2) {
                return -1;
            } else if (n1 > n2) {
                return 1;
            } else {
                return 0;
            }
        } else if (type == String.class) {
            String s1 = (String)data.getValueAt(row1, column);
            String s2    = (String)data.getValueAt(row2, column);
            int result = s1.compareTo(s2);

            if (result < 0) {
                return -1;
            } else if (result > 0) {
                return 1;
            } else {
                return 0;
            }
        } else if (type == Boolean.class) {
            Boolean bool1 = (Boolean)data.getValueAt(row1, column);
            boolean b1 = bool1.booleanValue();
            Boolean bool2 = (Boolean)data.getValueAt(row2, column);
            boolean b2 = bool2.booleanValue();

            if (b1 == b2) {
                return 0;
            } else if (b1) { // Define false < true
                return 1;
            } else {
                return -1;
            }
        } else {
            Object v1 = data.getValueAt(row1, column);
            String s1 = v1.toString();
            Object v2 = data.getValueAt(row2, column);
            String s2 = v2.toString();
            int result = s1.compareTo(s2);

            if (result < 0) {
                return -1;
View Full Code Here

        reallocateIndexes();
    }

    public int compareRowsByColumn(int row1, int row2, int column) {
        Class type = model.getColumnClass(column);
        TableModel data = model;

        // Check for nulls.

        Object o1 = data.getValueAt(row1, column);
        Object o2 = data.getValueAt(row2, column);

        // If both values are null, return 0.
        if (o1 == null && o2 == null) {
            return 0;
        } else if (o1 == null) { // Define null less than everything.
            return -1;
        } else if (o2 == null) {
            return 1;
        }

        /*
         * We copy all returned values from the getValue call in case
         * an optimised model is reusing one object to return many
         * values.  The Number subclasses in the JDK are immutable and
         * so will not be used in this way but other subclasses of
         * Number might want to do this to save space and avoid
         * unnecessary heap allocation.
         */

        if (type.getSuperclass() == java.lang.Number.class) {
            Number n1 = (Number)data.getValueAt(row1, column);
            double d1 = n1.doubleValue();
            Number n2 = (Number)data.getValueAt(row2, column);
            double d2 = n2.doubleValue();

            if (d1 < d2) {
                return -1;
            } else if (d1 > d2) {
                return 1;
            } else {
                return 0;
            }
        } else if (type == java.lang.Integer.class) {
    int d1 = ((Integer)data.getValueAt(row1, column)).intValue();
    int d2 = ((Integer)data.getValueAt(row2, column)).intValue();

    if (d1 < d2) {
      return -1;
    } else if (d1 > d2) {
      return 1;
    } else {
      return 0;
    }
        } else if (type == java.util.Date.class) {
            Date d1 = (Date)data.getValueAt(row1, column);
            long n1 = d1.getTime();
            Date d2 = (Date)data.getValueAt(row2, column);
            long n2 = d2.getTime();

            if (n1 < n2) {
                return -1;
            } else if (n1 > n2) {
                return 1;
            } else {
                return 0;
            }
        } else if (type == String.class) {
            String s1 = (String)data.getValueAt(row1, column);
            String s2    = (String)data.getValueAt(row2, column);
            int result = s1.compareTo(s2);

            if (result < 0) {
                return -1;
            } else if (result > 0) {
                return 1;
            } else {
                return 0;
            }
        } else if (type == Boolean.class) {
            Boolean bool1 = (Boolean)data.getValueAt(row1, column);
            boolean b1 = bool1.booleanValue();
            Boolean bool2 = (Boolean)data.getValueAt(row2, column);
            boolean b2 = bool2.booleanValue();

            if (b1 == b2) {
                return 0;
            } else if (b1) { // Define false < true
                return 1;
            } else {
                return -1;
            }
        } else {
            Object v1 = data.getValueAt(row1, column);
            String s1 = v1.toString();
            Object v2 = data.getValueAt(row2, column);
            String s2 = v2.toString();
            int result = s1.compareTo(s2);

            if (result < 0) {
                return -1;
View Full Code Here

                    }
                }
                reader.close();
                final String[] columnNames = headers;
                final String[][] values = records.toArray(new String[0][]);
                previewTable.setModel(new TableModel() {

                    public int getRowCount() {
                        return values.length;
                    }
View Full Code Here

TOP

Related Classes of javax.swing.table.TableModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.