CheckboxCellEditor but no Checkbox [message #1607] |
Thu, 07 May 2009 06:18  |
Eclipse User |
|
|
|
Hey,
desperately trying to use a CheckboxCellEditor in a table column. The
checkbox behaviour works, but I don't get a visible checkbox control.
I'm somehow irritated by what the CheckboxCellEditor API description says:
Note that this implementation simply fakes it and does does not create
any new controls. The mere activation of this editor means that the value
of the check box is being toggled by the end users; the listener method
<code>applyEditorValue</code> is immediately called to signal the change.
Is this what I'm experiencing? In an intent to actually create a
checkboxControl I created a subclass of CheckboxCellEditor, but that
doesn't work either..
I'm using eclipse 3.3.
@Override
public void createPartControl(Composite parent) {
Table table = new Table(parent, SWT.MULTI | SWT.BORDER |
SWT.FULL_SELECTION);
viewer = new TableViewer(table);
String[] header = new String[] {"", "A", "B", "B" };
int[] width = new int [] { 10, 200, 200, 200 };
for (int i = 0; i < header.length; i++){
TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
column.getColumn().setText(header[i]);
column.getColumn().setWidth(width[i]);
if (i == 0){
column.setEditingSupport(new LaunchcontrolEditingSupport());
}
}
initializeProviders();
viewer.getTable().setHeaderVisible(true);
viewer.getTable().setLinesVisible(true);
viewer.setInput(project);
}
protected void initializeProviders(){
viewer.setContentProvider(new ProjectContentProvider());
viewer.setLabelProvider(new ProjectLabelProvider());
}
public Collection<Element> getChecked(){
if (checked == null){
checked = new HashSet<Element>();
}
return Collections.unmodifiableCollection(checked);
}
@Override
public void setFocus() {
viewer.getTable().setFocus();
}
protected void updateView(){
viewer.setInput(project);
}
class LaunchcontrolEditingSupport extends EditingSupport {
private CellEditor editor;
public LaunchcontrolEditingSupport() {
super(viewer);
editor = new RealEditor(viewer.getTable(), SWT.CHECK);
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected CellEditor getCellEditor(Object element) {
return editor;
}
@Override
protected Object getValue(Object element) {
Boolean result;
if (checked == null){
result = Boolean.FALSE;
} else {
result = checked.contains(element);
}
return result;
}
@Override
protected void setValue(Object element, Object value) {
if (value == Boolean.TRUE){
if (checked == null){
checked = new HashSet<Element>();
}
checked.add((Element)element);
} else if (checked != null){
checked.remove(element);
}
viewer.update(element, null);
}
class RealEditor extends CheckboxCellEditor {
public RealEditor(Composite parent, int style){
super(parent, style);
}
@Override
public Control createControl(Composite parent){
Button b = new Button(parent, SWT.TOGGLE);
b.setText("haha");
return b;
}
}
}
|
|
|
|
|
|
Re: CheckboxCellEditor but no Checkbox [message #2787 is a reply to message #2742] |
Thu, 07 May 2009 16:05  |
Eclipse User |
|
|
|
Hi Felix,
"Felix Dorner" <felix_do@web.de> wrote in message
news:gtulmn$1ev$1@build.eclipse.org...
> Hey Tom,
>
> okay. I've simply adapted the solution from lars's tutorial, faking the
> checkboxes with images that the label provider returns.
>
> What is a CQ?
It's short for "contribution questionnaire", used by the Eclipse Foundation
for tracing and approving IP (intellectual property) contributed by third
parties. In the bug mentioned by Tom, a CQ had to be filed for traceability
reasons so that we can copy code from one Eclipse project to another.
Boris
|
|
|
Powered by
FUDForum. Page generated in 0.07865 seconds