Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[pde-dev] CheckboxCellEditor in TableTree

Title: CheckboxCellEditor in TableTree

Hi,

I am trying to use a couple of CheckboxCellEditors in my TableViewer. I have set them as cell editors and my CellModifier is returning a Boolean value for these columns. But the viewer fails to show a checkbox in the color on the table?? The TableViewer current shows a boolean value of "true" or "false". I want the column to show a checkbox instead. But I can't figure out how to make it work.

When I click in the checkbox column to edit the value, I get the following error in the console:

Unhandled exception caught in event loop.
Reason:
Failed to execute runnable (java.lang.ClassCastException: java.lang.Boolean)

*** Stack trace of contained exception ***
Reason:
java.lang.Boolean


When I run the debugger, I know that the debugger gets past the getValue of the CellModifier. As I follow the trace out of my getValue method, it goes to out of the box "TableViewerImpl.class", activateCellEditor method,  where it fails when it tries the following line of code:

cellEditor.activate();

Can anyone tell me what I am doing wrong? The relevant sections of my source are below.

Thanks,
Bob




----------------------------------------------------------------------------
public class AttributesView extends ViewPart implements ISelectionListener {
.
.
.

        public void createPartControl(Composite parent) {
                //viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
                Table table = getTable(parent);
                viewer = new TableViewer(table);
                viewer.setContentProvider(new AttributesViewContentProvider());
                viewer.setLabelProvider(new AttributesViewLabelProvider());
                viewer.setSorter(new NameSorter());
                viewer.setColumnProperties(new String[] {"col_image", "col_attr", "col_name", "col_type", "col_size", "col_req", "col_dyn", "col_state"});

               
                getViewSite().getPage().addSelectionListener(this);
                               
                               
                createFiltersAndSorters();
                makeActions();
                hookContextMenu();
                //hookDoubleClickAction();
                contributeToActionBars();
               
                getViewSite().getPage().addSelectionListener(this);
               
               
                viewer.setCellEditors(
                        new CellEditor[] {
                                null,                                                                                   // no editing in the image column

                                new TextCellEditor(table),                                              // attribute name

                                new TextCellEditor(table),                                              // attribute displayed name

                                new ComboBoxCellEditor(table, listStorageTypes),// attribute storage type
                                new TextCellEditor(table),                                              // attribute storage size

                                new CheckboxCellEditor(table),                                  // attribute required
                                new CheckboxCellEditor(table),                                  // attribute dynamic
                                new TextCellEditor(table)});                                    // state
                               
                viewer.setCellModifier(new ICellModifier() {
                        public boolean canModify(Object element, String property) {
                                MTIAttribute a = (MTIAttribute) element;
                                if (property.equals("col_attr"))
                                        return (! a.getState().equals(ModelConstants.SERVER));
                                else if (property.equals("col_name"))
                                        return true;
                                else if (property.equals("col_type"))
                                        return (! a.getState().equals(ModelConstants.SERVER));
                                else if (property.equals("col_size"))
                                        return a.getStorageType().equals("string");
                                else if (property.equals("col_req"))
                                        return true;
                                else if (property.equals("col_dyn"))
                                        return true;
                                else if (property.equals("col_state"))
                                        return false;
                                else
                                        return false;
                        }
                        
                        public Object getValue(Object element, String property) {
                                MTIAttribute a = (MTIAttribute) element;
                                System.out.println("AttributesView:getValue()");
                                if (property.equals("col_attr"))
                                        return a.getAttribute();
                                else if (property.equals("col_name"))
                                        return a.getDisplayedName();
                                else if (property.equals("col_type")) {
                                        int i = Arrays.asList(listStorageTypes).indexOf(a.getStorageType());
                                        return i == -1 ? null : new Integer(i);
                                }
                                else if (property.equals("col_size"))
                                        return (new Integer(a.getStorageSize())).toString();
                                else if (property.equals("col_req"))
                                        return (new Boolean(a.getRequired()));
                                else if (property.equals("col_dyn"))
                                        return (new Boolean(a.getDynamic()));
                                else if (property.equals("col_state"))
                                        return a.getState();
                                else
                                        return null;
                        }
                       
                        public void modify(Object element, String property, Object value) {
                                if (element instanceof Item)
                                        element = ((Item) element).getData();
                               
                                MTIAttribute a = (MTIAttribute) element;
                                if (property.equals("col_attr"))
                                        a.setAttribute((String) value);
                                else if (property.equals("col_name"))
                                        a.setDisplayedName((String) value);
                                else if (property.equals("col_type"))
                                {
                                        if (value instanceof Integer)
                                        {
                                                int i = ((Integer) value).intValue();
                                                a.setStorageType(listStorageTypes[i]);
                                        }
                                }
                                else if (property.equals("col_size"))
                                        a.setStorageSize((Integer.valueOf((String)value)).intValue());
                                else if (property.equals("col_req"))
                                        a.setRequired(Boolean.getBoolean((String) value));
                                else if (property.equals("col_dyn"))
                                        a.setDynamic(Boolean.getBoolean((String) value));
                                else if (property.equals("col_state"))
                                        a.setState((String) value);
                               
                                System.out.println("AttributesView: modify");
                                MTIClassInfo info = ((AttributesViewContentProvider)viewer.getContentProvider()).getMTIClassInfoForViewer();

                                model.modifyAttribute(info, a);
                        }
                       

                });
        }


Back to the top