package skadistats.clarity.examples.dtinspector;

import javax.swing.table.AbstractTableModel;

import skadistats.clarity.model.DTClass;
import skadistats.clarity.model.PropFlag;
import skadistats.clarity.model.ReceiveProp;

public class TableModel extends AbstractTableModel {
    private static final long serialVersionUID = 2946867068203801119L;

    private final DTClass dtClass;

    public TableModel(DTClass dtClass) {
        this.dtClass = dtClass;
    }

    @Override
    public int getRowCount() {
        return dtClass.getReceiveProps().size();
    }

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

    @Override
    public String getColumnName(int column) {
        switch (column) {
        case 0:
            return "Name";
        case 1:
            return "Type";
        case 2:
            return "Source";
        case 3:
            return "Priority";
        case 4:
            return "Flags";
        default:
            return "";
        }
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        ReceiveProp p = dtClass.getReceiveProps().get(rowIndex);
        switch (columnIndex) {
        case 0:
            return p.getVarName();
        case 1:
            return p.getType();
        case 2:
            return p.getSrc();
        case 3:
            return p.getPriority();
        case 4:
            StringBuffer buf = new StringBuffer();
            for (PropFlag f : PropFlag.values()) {
                if (p.isFlagSet(f)) {
                    if (buf.length() > 0) {
                        buf.append(", ");
                    }
                    buf.append(f.name());
                }
            }
            return buf.toString();
        default:
            return "";
        }
    }
}
@@ -49,56 +49,8 @@
 %0D%0A%0D%0A
-import javax.swing.table.AbstractTableModel;%0D%0A%0D%0A
 impo
@@ -178,16 +178,64 @@
 rop;%0D%0A%0D%0A
+import javax.swing.table.AbstractTableModel;%0D%0A%0D%0A
 public c
@@ -1458,359 +1458,56 @@
     
-StringBuffer buf = new StringBuffer();%0D%0A            for (PropFlag f : PropFlag.values()) %7B%0D%0A                if (p.isFlagSet(f)) %7B%0D%0A                    if (buf.length() %3E 0) %7B%0D%0A                        buf.append(%22, %22);%0D%0A                    %7D%0D%0A                    buf.append(f.name());%0D%0A                %7D%0D%0A            %7D%0D%0A            return buf.toString(
+return PropFlag.descriptionForFlags(p.getFlags()
 );%0D%0A

optimize flag handling, since profiling showed it to be expensive.