|
Re: Decorator Problem [message #665225 is a reply to message #665175] |
Wed, 13 April 2011 19:14 |
|
I had a similar problem. My solution is bellow.
In my view I have a property change listener (from org.eclipse.jface.util) that triggers the refresh of the table:
IPropertyChangeListener preferenceListener = new IPropertyChangeListener() {
/*
* @see IPropertyChangeListener.propertyChange()
*/
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(IPreferenceConstants.P_BOOK_DISPLAY_MODE)) {
tableViewer.refresh(true);
}
if (event.getProperty().equals(
IPreferenceConstants.P_CHECK_COLLECTION_STATUS)) {
tableViewer.refresh(true);
}
}
};
In the init() method of the view I add the listener to the preference store:
BooksActivator.getDefault().getPreferenceStore().addPropertyChangeListener(
preferenceListener);
And finally in the dispose method I remove the listner from the preference store:
BooksActivator.getDefault().getPreferenceStore()
.removePropertyChangeListener(preferenceListener);
Maybe there is a nicer solution to this, but I couldn't find it.
HTH
Catalin
Time is what you make of it.
|
|
|
Re: Decorator Problem [message #665323 is a reply to message #665225] |
Thu, 14 April 2011 10:32 |
Joaquin Morcate Messages: 52 Registered: March 2010 |
Member |
|
|
Hi Catalin,
Thank you very much for your support. Unfortunately I didn't work for me.
I've been debuging how the viewer update the table viewer and I have found that the ViewerColumn class has a method called refresh(ViewerCell vc) that call the update(cell) in the label provider (in my case is an instance of DecoratingStyledCellLabelProvider. This is the place where the cell rendering is evaluated. This is the code to set the background color:
if (this.decorator instance of IColorDecorator) {
Color color=((IColorDecorator)this.decorator).
decorateBackground(element);
if (color!=null)
return color;
}
return super.getBackground(element);
Nowhere is the state of the decorator, enabled or disabled, checked; or at least I cannot find it.
Furthermore, there is something wrong in the way that I create the label provider:
private void makeColumns(TableColumnLayout layout, ColumnSortAdapter columnSortAdapter) {
TableViewerColumn col=null;
...
// for each column col in the table:
IDecoratorManager decoratorManager= getSite().getWorkbenchWindow().getWorkbench().getDecoratorManager();
decorator = decoratorManager.getLabelDecorator("net.morcate.console.alerts.decorator1");
DecoratingStyledCellLabelProvider decoratingLabelProvider = new DecoratingStyledCellLabelProvider(alertsLabelProvider, decorator, null);
col.setLabelProvider(decoratingLabelProvider);
...
}
If the decorator is disabled, the decorator returned by the decoratorManager will be "null" and that is what will be stored in the decorator field member in my instance of DecoratingStyledCellLabelProvider. So, it doesn't matter if I enable/disable the decorator afterwards, the label provider will have a null decorator for ever.
The only solution that I can see is, reusing your suggestion, is to re-instance the label provider in the property change listener. Instead of just calling view.refresh(true), to do the following:
public void propertyChange(PropertyChangeEvent event) {
if (event.getProperty().equals(IPreferenceConstants.P_BOOK_DISPLAY_MODE)) {
IDecoratorManager decoratorManager= getSite().getWorkbenchWindow().getWorkbench().getDecoratorManager();
decorator = decoratorManager.getLabelDecorator("net.morcate.console.alerts.decorator1");
for (each column col in the table) {
DecoratingStyledCellLabelProvider decoratingLabelProvider = new DecoratingStyledCellLabelProvider(alertsLabelProvider, decorator, null);
col.setLabelProvider(decoratingLabelProvider);
}
}
if (event.getProperty().equals(
IPreferenceConstants.P_CHECK_COLLECTION_STATUS)) {
//same thing.
}
But then I can see the convenience of using decorators.
Maybe my approach is complete wrong and I am trying to use decorators in the way they are supposed to be used. I could be following a dead road. Any ideas?
Joaquin Morcate
|
|
|
Re: Decorator Problem [message #665370 is a reply to message #665323] |
Thu, 14 April 2011 13:13 |
|
Just a some remarks:
1.
if (event.getProperty().equals(IPreferenceConstants.P_BOOK_DISPLAY_MODE)) { should be replaced with name of your property from your preference store.
2. Unfortunately my code did not use Decorators as label provider so it's not exactly similar to your situation (I used the property from the preference store in the LabelProvider without depending on another object state (like the Alert in your case)). Further more my experience with decorators is still limited to a small project with very simple scenario.
3. Maybe you need to issue PlatformUI.getWorkbench().getDecoratorManager().update(id_of_your_decorator); in the propertyChange() method to trigger the change (although I guess that you should have a ILabelProviderListener in your code or your LabelProvider should override isLabelProperty() method).
I think that the correct question in your case is: how to trigger the change the label provider of a table at runtime.
In case that you have solved this problem in a different way just let us know how.
Time is what you make of it.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04020 seconds