Example #1
0
 protected Comparator getComparator(int column) {
   Class columnType = tableModel.getColumnClass(column);
   Comparator comparator = (Comparator) columnComparators.get(columnType);
   if (comparator != null) {
     return comparator;
   }
   if (Comparable.class.isAssignableFrom(columnType)) {
     return COMPARABLE_COMAPRATOR;
   }
   return COMPARABLE_COMAPRATOR;
 }
 public Class getColumnClass(int c) {
   return original.getColumnClass(c);
 }
 public Class getColumnClass(int column) {
   return model.getColumnClass(column);
 }
Example #4
0
  /**
   * Construct Statements based on given TableModel.
   *
   * @param tableModel given TableModel
   * @return the constructed Statements. UNKNOWN_STATEMENTS if fail
   */
  public static Statements newInstanceFromTableModel(
      TableModel tableModel, boolean languageIndependent) {
    final CSVHelper csvHelper = (CSVHelper) tableModel;
    final GUIBundleWrapper guiBundleWrapper =
        GUIBundleWrapper.newInstance(
            languageIndependent
                ? GUIBundleWrapper.Language.INDEPENDENT
                : GUIBundleWrapper.Language.DEFAULT);

    final int column = tableModel.getColumnCount();
    final int row = tableModel.getRowCount();

    List<String> strings = new ArrayList<String>();
    for (int i = 0; i < column; i++) {
      final String type =
          languageIndependent
              ? csvHelper.getLanguageIndependentColumnName(i)
              : tableModel.getColumnName(i);
      if (tableModel.getColumnClass(i).equals(Stock.class)) {
        final String code_string = guiBundleWrapper.getString("MainFrame_Code");
        final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");
        strings.add(code_string);
        strings.add(symbol_string);
      } else {
        strings.add(type);
      }
    }

    // Comment handling.
    CommentableContainer commentableContainer = null;
    if (tableModel instanceof CommentableContainer) {
      commentableContainer = (CommentableContainer) tableModel;
    }

    Statement.What what = Statement.what(strings);
    final Statements s = new Statements(what.type, what.guiBundleWrapper);

    for (int i = 0; i < row; i++) {
      final List<Atom> atoms = new ArrayList<Atom>();
      for (int j = 0; j < column; j++) {
        final String type =
            languageIndependent
                ? csvHelper.getLanguageIndependentColumnName(j)
                : tableModel.getColumnName(j);
        final Object object = tableModel.getValueAt(i, j);
        if (tableModel.getColumnClass(j).equals(Stock.class)) {
          final Stock stock = (Stock) object;
          // There are no way to represent Stock in text form. We
          // will represent them in Code and Symbol.
          // Code first. Follow by symbol.

          final String code_string = guiBundleWrapper.getString("MainFrame_Code");
          final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");

          atoms.add(new Atom(stock.getCode().toString(), code_string));
          atoms.add(new Atom(stock.getSymbol().toString(), symbol_string));
        } else if (tableModel.getColumnClass(j).equals(Date.class)) {
          DateFormat dateFormat = org.yccheok.jstock.gui.Utils.getCommonDateFormat();
          atoms.add(
              new Atom(object != null ? dateFormat.format(((Date) object).getTime()) : "", type));
        } else {
          // For fall below and rise above, null value is permitted.
          // Use empty string to represent null value.
          atoms.add(new Atom(object != null ? object : "", type));
        }
      }

      // Comment handling.
      if (commentableContainer != null) {
        atoms.add(
            new Atom(
                commentableContainer.getCommentable(i).getComment(),
                guiBundleWrapper.getString("PortfolioManagementJPanel_Comment")));
      }

      final Statement statement = new Statement(atoms);

      if (s.getType() != statement.getType()) {
        // Doesn't not match. Return UNKNOWN_STATEMENTS to indicate we fail to
        // construct Statements from TableModel.
        return UNKNOWN_STATEMENTS;
      }

      s.statements.add(statement);
    }

    return s;
  }
Example #5
0
 public Class getColumnClass(int iColIndex) {
   return parentModel.getColumnClass(iColIndex);
 }
 public Class getColumnClass(final int columnIndex) {
   return model.getColumnClass(columnIndex);
 }