Commits

Rui Vieira committed 3c66976

ColumnSet class for OptionTableModel column type, name and number methods.

Comments (0)

Files changed (3)

src/main/java/org/ruivieira/orwell/components/tables/ColumnSet.java

+package org.ruivieira.orwell.components.tables;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Author: rvieira
+ * Date: 14/11/11
+ * Time: 17:07
+ */
+public class ColumnSet {
+
+    protected List<Column> columns = new ArrayList<Column>();
+
+    public ColumnSet() {
+
+    }
+
+    public void add(int index, String name, Class type) {
+        columns.add(new Column(index, name, type));
+    }
+
+    public String getName(int index) {
+        String result = null;
+        for (Column column : columns) {
+            if (column.getIndex() == index) {
+                result = column.getName();
+            }
+        }
+        return result;
+    }
+
+    public Class getClass(int index) {
+        Class c = String.class;
+        for (Column column : columns) {
+            if (column.getIndex() == index) {
+                c = column.getClass();
+            }
+        }
+        return c;
+    }
+
+    public int getSize() {
+        return columns.size();
+    }
+}

src/main/java/org/ruivieira/orwell/components/tables/MultilineFilteredHeaderRendererPopupMenu.java

             uniques.add(val);
         }
         for (String unique : uniques) {
-            JMenuItem item = new JMenuItem();
-            item.setText(unique);
+            JCheckBoxMenuItem item = new JCheckBoxMenuItem(unique);
             System.out.println(unique);
             add(item);
         }

src/main/java/org/ruivieira/orwell/components/tables/OptionsTableModel.java

 public abstract class OptionsTableModel<T> extends DefaultTableModel implements Synchable {
 
     protected List<T> items = new ArrayList<T>();
+    protected ColumnSet columns = new ColumnSet();
 
     public OptionsTableModel() {
         super();
     }
 
+    @Override
+    public String getColumnName(int i) {
+        return columns.getName(i);
+    }
+
+    @Override
+    public int getColumnCount() {
+        return columns.getSize();
+    }
+
+    @Override
+    public Class<?> getColumnClass(int columnIndex) {
+        return columns.getClass(columnIndex);
+    }
+
+
     public void empty() {
         items = new ArrayList<T>();
         while (getRowCount() > 0) {