Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Support for color selection in a cell ?
Support for color selection in a cell ? [message #1066746] Thu, 04 July 2013 08:27 Go to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hello,

We are currently using JFace TableViewers in some places in our application. We were thinking of replacing it with a NatTable control to see whether some of the "issues" that we are experiencing can be solved with NatTable.
However, we need to be able to select colors, similar as the JFace ColorCellEditor is providing.

Does NatTable provide such a feature ? I've been browsing through the API doc and saw that there's no support for color cell editors. However, there is ColorPicker class, so I don't if this can be used in any way within a cell ?

Thank you,
Cédric
Re: Support for color selection in a cell ? [message #1066749 is a reply to message #1066746] Thu, 04 July 2013 08:45 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi,

no currently there is no such support out of the box available. And the AFAIK the ColorPicker is used within the style edit dialog and is not intended to be used within a cell.

But with the NatTable 1.0 release we introduced the possibility to create new editors based on SWT/JFace dialogs. Of course we would like to add the most common dialogs, e.g. color selection and file selection, but currently only the file selection is available.

You might want to have a look at the FileDialogCellEditor which opens the FileDialog on activating the editor in NatTable. You could create a new ColorDialogCellEditor similar to the FileDialogCellEditor, that opens the ColorDialog. Additionally you would need to implement the logic that shows the selected color in the NatTable cell. This can be done either by rendering a dynamic image with the specified background color, or by implementing some special ColorCellPainter which could be a customized BackgroundPainter that knows which Color to use for the background color by inspecting the data model.

Hope that helps,
Dirk
Re: Support for color selection in a cell ? [message #1067044 is a reply to message #1066749] Fri, 05 July 2013 15:08 Go to previous messageGo to next message
Cedric Moonen is currently offline Cedric MoonenFriend
Messages: 274
Registered: August 2009
Senior Member
Hi Dirk,

Thanks for the useful help. I'm almost done with this, this was in fact easier than expected. I am able to show the color dialog on click and I am also able to fill the background color with a custom cell painter.

However, I'm now stuck with a small problem: in the AbstractDialogCellEditor class, the RGB color returned by my editor is converted to a string because of this code:

	@Override
	public Object getCanonicalValue(IEditErrorHandler conversionErrorHandler) {
		Object canonicalValue;
		try {
			if (this.displayConverter != null) {
				//always do the conversion to check for valid entered data
				canonicalValue = this.displayConverter.displayToCanonicalValue(
						this.layerCell, this.configRegistry, getEditorValue());
			} else {
				canonicalValue = getEditorValue();
			}

			//if the conversion succeeded, remove error rendering if exists
			conversionErrorHandler.removeError(this);
		} catch (ConversionFailedException e) {
			// conversion failed
			conversionErrorHandler.displayError(this, e);
			throw e;
		} catch (Exception e) {
			// conversion failed
			conversionErrorHandler.displayError(this, e);
			throw new ConversionFailedException(e.getMessage(), e);
		}
		return canonicalValue;
	}


The displayConverter is a DefaultDisplayConverter. Looking at the code, if this displayConverter would be null, this would solve my problem (the getEditorValue() method returns the RGB object).
I tried to attach a null display converter in my edit configuration but that doesn't work:

		configRegistry.registerConfigAttribute(
				CellConfigAttributes.DISPLAY_CONVERTER, null, DisplayMode.EDIT,
				COLOR_FIELD_NAME);


How can I correct that ?
Re: Support for color selection in a cell ? [message #1067085 is a reply to message #1067044] Fri, 05 July 2013 18:21 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Why not creating a converter that simply returns the value without conversion?
Previous Topic:NatTable 1.0.1 released!
Next Topic:Table with no row header
Goto Forum:
  


Current Time: Thu Apr 25 09:50:26 GMT 2024

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

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

Back to the top