Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » XWT: custom LabelProvider for dynamic row coloring
XWT: custom LabelProvider for dynamic row coloring [message #1007437] Tue, 05 February 2013 15:57 Go to next message
Blake M is currently offline Blake M
Messages: 1
Registered: February 2013
Junior Member
Hi Guys,

I need to color each row depending on some conditions. I have tried the following, but get the exception below. Any help?

	<TableViewer x:Name="tblvActions" x:input="{Binding path=actions}">
		  
		<TableViewer.labelProvider>
			<k:MyLabelProvider/>
		</TableViewer.labelProvider>
		
		<TableViewer.table />
		<TableViewer.columns headerVisible="true">
			...
		</TableViewer.columns>
	</TableViewer>


import org.eclipse.e4.xwt.jface.DefaultViewerLabelProvider;
import org.eclipse.jface.viewers.IColorProvider;
...

public class MyLabelProvider extends DefaultViewerLabelProvider implements IColorProvider
{
	public ActionsLabelProvider(Viewer viewer)
	{
		super(viewer);
	}

	@Override
	public Color getBackground(Object arg0)
	{
		return Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW);
	}

	@Override
	public Color getForeground(Object arg0)
	{
		return Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
	}

}


Exception occurred
org.eclipse.core.runtime.AssertionFailedException: assertion failed: Column 0 has no label provider.
	at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
	at org.eclipse.jface.viewers.ViewerColumn.refresh(ViewerColumn.java:149)
	at org.eclipse.jface.viewers.AbstractTableViewer.doUpdateItem(AbstractTableViewer.java:399)
	at org.eclipse.jface.viewers.StructuredViewer$UpdateItemSafeRunnable.run(StructuredViewer.java:485)
	at org.eclipse.jface.util.SafeRunnable$1.run(SafeRunnable.java:128)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
	at org.eclipse.jface.viewers.StructuredViewer.updateItem(StructuredViewer.java:2167)
	at org.eclipse.jface.viewers.AbstractTableViewer.createItem(AbstractTableViewer.java:277)
	at org.eclipse.jface.viewers.AbstractTableViewer.insert(AbstractTableViewer.java:627)
	at org.eclipse.jface.internal.databinding.viewers.TableViewerUpdater.insert(TableViewerUpdater.java:32)
	at org.eclipse.jface.databinding.viewers.ObservableListContentProvider$2.handleAdd(ObservableListContentProvider.java:119)
	at org.eclipse.core.databinding.observable.list.ListDiff.accept(ListDiff.java:137)
	at org.eclipse.jface.databinding.viewers.ObservableListContentProvider$Impl.handleListChange(ObservableListContentProvider.java:117)
	at org.eclipse.core.databinding.observable.list.ListChangeEvent.dispatch(ListChangeEvent.java:61)
	at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
	at org.eclipse.core.databinding.observable.list.DecoratingObservableList.fireListChange(DecoratingObservableList.java:59)
	at org.eclipse.core.databinding.observable.list.DecoratingObservableList.handleListChange(DecoratingObservableList.java:97)
	at org.eclipse.core.databinding.observable.list.DecoratingObservableList$1.handleListChange(DecoratingObservableList.java:71)
	at org.eclipse.core.databinding.observable.list.ListChangeEvent.dispatch(ListChangeEvent.java:61)
	at org.eclipse.core.databinding.observable.ChangeManager.fireEvent(ChangeManager.java:119)
	at org.eclipse.core.databinding.observable.ChangeSupport.fireEvent(ChangeSupport.java:39)
	at org.eclipse.core.databinding.observable.list.AbstractObservableList.fireListChange(AbstractObservableList.java:117)
	at org.eclipse.core.internal.databinding.property.list.SimplePropertyObservableList.notifyIfChanged(SimplePropertyObservableList.java:567)
	at org.eclipse.core.internal.databinding.property.list.SimplePropertyObservableList.access$3(SimplePropertyObservableList.java:559)
	at org.eclipse.core.internal.databinding.property.list.SimplePropertyObservableList$2.run(SimplePropertyObservableList.java:78)
	at org.eclipse.core.databinding.observable.Realm$1.run(Realm.java:148)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.databinding.observable.Realm.safeRun(Realm.java:152)
	at org.eclipse.jface.databinding.swt.SWTObservables$DisplayRealm.access$0(SWTObservables.java:1)
	at org.eclipse.jface.databinding.swt.SWTObservables$1.run(SWTObservables.java:551)
	at org.eclipse.swt.widgets.RunnableLock.run(Unknown Source)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Unknown Source)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Unknown Source)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
Re: XWT: custom LabelProvider for dynamic row coloring [message #1007448 is a reply to message #1007437] Tue, 05 February 2013 16:29 Go to previous message
Erdal Karaca is currently offline Erdal Karaca
Messages: 729
Registered: July 2009
Senior Member
Note: XWT has moved and now has its own forum. You will find it in the "Eclipse Projects" category at the bottom...

It seems that you additionally have set a label provider to one of your columns but not for the first one. You can set a label provider for the entire TableViewer or you have to set a column label provider to ALL of your columns.
BTW. setting the headerVisible property on TableViewer.columns should have no effect.
Previous Topic:Command alternative for editorActions, RulerToggleBreakpointActionDelegate
Next Topic:How to implement 'Close All' and 'Close Others'
Goto Forum:
  


Current Time: Fri Aug 01 03:56:36 EDT 2014

Powered by FUDForum. Page generated in 0.08345 seconds