Styling tabs of MParts [message #1398702] |
Fri, 11 July 2014 09:04  |
Eclipse User |
|
|
|
Hi,
I have an application where I want to set the color of a tab dependent on the displayed data, using an id or a tag.
I could only find examples on how to set the color of selected and unselected tabs. Is there another built in possibility for styling tabs, or will I need an own renderer?
If there is no possibility to set the colors yet, I would contribute my renderer or extend the existing e4 CTabRendering if there is an interest in such a feature.
Cheers,
Eugen
|
|
|
|
|
Re: Styling tabs of MParts [message #1400591 is a reply to message #1400448] |
Mon, 14 July 2014 08:32   |
Eclipse User |
|
|
|
Hi Eugen,
now I understand your problem. I reviewed my own code and realized that
I only added those tags to the PartStack and so all Tabs are handled in
the same way (which is not the behaviour YOU want).
However, I got a bit closer with the following idea:
In your Part implementation use
((CTabFolder)(part.getParent().getWidget())).setData("some-key","some-value");
where part is the injected MPart, and so part.getParent() is the
containing CTabFolder (as every PartStack is implemented as a CTabFolder).
In your CSS you can now use:
CTabFolder[some-key='some-value']{
swt-tab-renderer:
url('bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering');
swt-tab-height: 30px;
swt-selected-tab-fill: #ff0000;
}
CTabFolder[some-key='some-value-2']{
swt-tab-renderer:
url('bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering');
swt-tab-height: 20px;
swt-selected-tab-fill: #00ff00;
}
The only problem I got is that when using two or more values, they get
overriden when switching tabs, so when all tabs have been selected once
they all look the same again. But maybe you can investigate that and
find a solution.
Cheers, Marina
On 14.07.2014 10:04, Eugen Neufeld wrote:
> Hi Marina, thanks for the hint. Here is my problem: I have one
> MPartStack and in this PartStack I have multiple Parts. Now I want to
> change the background color of the tab (not the color of the tab content).
> I can add a tag to the MPart but this will only influence the content of
> the tab, as the tabs are provided by the MPartStack.
> So is the MPartStack renderer able to render tabs with different colors?
> If I understood the code of the MPartStack renderer correctly, then it
> only can set a selectedColor and an unselectedColor.
> Cheers,
> Eugen
|
|
|
|
|
Re: Styling tabs of MParts [message #1740638 is a reply to message #1398702] |
Tue, 16 August 2016 10:47  |
Eclipse User |
|
|
|
Hi,
In the previous post you have seen the org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering class being referenced in the application´s css.
You should have a look at the org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering class and implement your own CTabFolderRenderer, where you can read the data of a MPart and set a certain color.
In order to gain access to the MPart in the draw method you can do this:
protected void draw (int part, int state, Rectangle bounds, GC gc) {
CTabItem item = parent.getItem(part);
Object modelElement = item.getData("modelElement");
if (modelElement instanceof MPart) {
MPart part = (MPart) modelElement;
// get tab color information or what ever you need from the MPart
// gives you your part implementation
Object yourPart = part.getObject();
// gives you the IEclipseContext of the part
IEclipseContext context = part.getContext();
}
}
I hope this gives you the ability to implement a solution for your problem.
Cheers,
Simon
|
|
|
Powered by
FUDForum. Page generated in 0.11112 seconds