Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Decorating a boolean column with SWT
Decorating a boolean column with SWT [message #1403173] Tue, 22 July 2014 06:56 Go to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 362
Registered: October 2012
Location: Bern, Switzerland
Senior Member
In our application we would like to replace the checkboxes in a bolean column with a red dot or a green checkmark instead of the normal checkbox when displaying a value.
I've tried using execDecorateCell() to do this (using cell.setIconId() depending on the getValue() of the column). However, this does not seem to have any effect with SWT. I know that Scout "abuses" the icon in ListFields and TreeFields to render checkboxes and can therefore not display an icon for those (unlike Swing). Is this the same issue with BooleanColumn?

If this were a read-only table I guess I could change the type of the column to an ObjectColumn and then use execDecorateCell() to render the information. However this will be an editable column so we would want to fall back on the checkbox when editing this column.

Can anyone think of a way to solve this? Would it be possible to use an ObjectColumn for display but a CheckboxField for editing? If so, how would I do this?
Re: Decorating a boolean column with SWT [message #1403193 is a reply to message #1403173] Tue, 22 July 2014 09:54 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 914
Registered: October 2011
Senior Member
Urs Beeli wrote on Tue, 22 July 2014 08:56
I've tried using execDecorateCell() to do this (using cell.setIconId() depending on the getValue() of the column). However, this does not seem to have any effect with SWT. I know that Scout "abuses" the icon in ListFields and TreeFields to render checkboxes and can therefore not display an icon for those (unlike Swing). Is this the same issue with BooleanColumn?


Yes... The implementation of Boolean Columns brings some problems...

We already discussed some of your issues with Boolean Columns here.

Urs Beeli wrote on Tue, 22 July 2014 08:56
Can anyone think of a way to solve this? Would it be possible to use an ObjectColumn for display but a CheckboxField for editing? If so, how would I do this?


You can provide the field you need with "execPrepareEdit" (this is true for all types of Columns). Here for example I have used a smart field with a YesOrNoCodeType.

index.php/fa/18609/0/

public class MyColumn extends AbstractColumn<Boolean> {

  @Override
  protected String getConfiguredHeaderText() {
    return TEXTS.get("MyColumn");
  }

  @Override
  protected boolean getConfiguredEditable() {
    return true;
  }

  @Override
  protected IFormField execPrepareEdit(ITableRow row) throws ProcessingException {
    AbstractSmartField<Boolean> f = new AbstractSmartField<Boolean>() {
      @Override
      protected Class<? extends ICodeType<?, Boolean>> getConfiguredCodeType() {
        return YesOrNoCodeType.class;
      }
    };
    f.setValue(BooleanUtility.nvl(getValue(row)));
    return f;
  }
}


To make it work, you need to use "AbstractColumn<Boolean>" instead of AbstractBooleanColumn (I do not know why). The problem you have indicated with the misusage of the Icon in the SWT implementation is still present.

---

Following this example I have tried something closer to what you need:
public class MyColumn extends AbstractObjectColumn {

  @Override
  protected String getConfiguredHeaderText() {
    return TEXTS.get("MyColumn");
  }

  @Override
  protected boolean getConfiguredEditable() {
    return true;
  }

  @Override
  protected void execDecorateCell(Cell cell, ITableRow row) throws ProcessingException {
    if (BooleanUtility.nvl((Boolean) getValue(row))) {
      cell.setIconId(Icons.Bookmark);
    }
    else {
      cell.setIconId(Icons.Gears);
    }
  }

  @Override
  protected IFormField execPrepareEdit(ITableRow row) throws ProcessingException {
    AbstractBooleanField f = new AbstractBooleanField() {
    };
    f.setValue((Boolean) getValue(row));
    return f;
  }
}


I think we are near to what you expect. I see something that could be improved: The icon does not disappear when the field is displayed to edit the value.

index.php/fa/18610/0/

I hope writing a custom column implementation is not your only option.

.

[Updated on: Wed, 23 July 2014 05:37]

Report message to a moderator

Re: Decorating a boolean column with SWT [message #1403341 is a reply to message #1403193] Wed, 23 July 2014 06:15 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 362
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jérémie

Thank you for your help with the execPrepareEdit, I'll have a look at this. As to the initial value, maybe the following will work (untested):
  @Override
  protected IFormField execPrepareEdit(ITableRow row) throws ProcessingException {
    AbstractBooleanField f = new AbstractBooleanField() {
    };
    f.setValue(getValue(row));
    return f;
  }


The need for the custom column comes not from this issue. We've already implemented a TriStateField to display a checkbox with three states (true, false, indeterminate) in order to represent a TriState object. We now also need to be able to display such values in tables. One option might be to use an ObjectColumn and to then set the icons accordingly and using execPrepareEdit to use the TriStateField instead of creating a custom TristateColumn. Anyway, thanks for the link (it's a bit embarrassing to see I've asked this question before Smile, I'll have a look, though the blog article seems to focus mainly on RAP, I guess it would also work with SWT.
Re: Decorating a boolean column with SWT [message #1403343 is a reply to message #1403341] Wed, 23 July 2014 06:47 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 914
Registered: October 2011
Senior Member
I think you will be fine with AbstractColumn<TriState> similar to my example AbstractColumn<Boolean>. You do not need a custom table implementation for this.

Thank you for your pointer on the missing "setValue(..)" line. I have udpated my code snippets.
Previous Topic:Is it possible to create CustomColumns for tables?
Next Topic:Setting Ctrl-+ as keystroke on a table
Goto Forum:
  


Current Time: Fri Mar 06 11:03:08 GMT 2015

Powered by FUDForum. Page generated in 0.03015 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software