Decorator Problem [message #665175] |
Wed, 13 April 2011 10:46  |
Eclipse User |
|
|
|
Hi all,
I'm trying to create a Decorator that changes the background in an alerts table
depending on the severity of the Alert and I would like to be able to enable/disable
the decorator at runtime. So I have declare the following extension point:
<extension
point="org.eclipse.ui.decorators">
<decorator
class="net.morcate.console.alerts.views.AlertsDecorator"
id="net.morcate.console.alerts.decorator1"
label="BackgroundDecorator"
lightweight="false"
state="true">
<enablement>
<objectClass
name="net.morcate.bos.alerts.Alert">
</objectClass>
</enablement>
</decorator>
I have implemented the decorator AlertsDecorator
public class AlertsDecorator extends LabelProvider implements ILabelDecorator,
IColorDecorator {
...
}
and the label provider as:
public class AlertsLabelProvider extends ColumnLabelProvider implements IStyledLabelProvider{
...
}
In my view I have the following:
private void makeColumns(TableColumnLayout layout, ColumnSortAdapter columnSortAdapter) {
TableViewerColumn col=null;
...
// for each column 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);
In a preference page I have a toggle to enable/disable the decorator:
@Override
public boolean performOk() {
try {
this.saveValues(this.getPreferenceStore());
PlatformUI.getWorkbench().getDecoratorManager().setEnabled("net.morcate.console.alerts.decorator1", this.useBackgroundHighLighting);
return true;
}
The problem is that this does not change the rendering in the table. If I close
and reopen the view, the table is displayed as expected from the state of the
decorator. So I guess that I have to ask the table viewer to redraw itself but I
don't kown how. Any help?
Thank you very much.
Joaquin Morcate
|
|
|
|
Re: Decorator Problem [message #665323 is a reply to message #665225] |
Thu, 14 April 2011 06:32   |
Eclipse User |
|
|
|
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 #666005 is a reply to message #665370] |
Mon, 18 April 2011 11:12  |
Eclipse User |
|
|
|
Hi Catalin,
Sorry for the delay in my answer.
I have tried both of your suggestions (calling update on the decorator manager and overriding the isLabelProperty) and none of the worked. The only solution that I've been able to find is the one that I mentioned in my previous answer, adding a viewer.refresh() call (and changing the name of the properties of course): I have to create new label providers!
Anyhow, I am a bit confused about how the workbench deals with decorators. My idea was to chain different decorators so the user can decide how he or she what the alerts to be highlighted. Unfortunately, DecoratingStyledCellLabelProvider does not support this. For example, you can code the following:
DecoratingLabelProvider dlp = new DecoratingLabelProvider(
new DecoratingLabelProvider(aLabProv, deco1),
deco2);
because DecoratingLabelProvider implements ILabelProvider and has a contructor that takes as arguments ILabelProvider and ILabelDecorator. But this does not apply to DecoratingStyledCellLabelProvider.
I will let you know if I can find a better solution for this problem.
Thank you very much for your help
Joaquin
|
|
|
Powered by
FUDForum. Page generated in 0.03629 seconds