Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Styling tabs of MParts
Styling tabs of MParts [message #1398702] Fri, 11 July 2014 13:04 Go to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 63
Registered: March 2012
Member
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 #1398705 is a reply to message #1398702] Fri, 11 July 2014 13:09 Go to previous messageGo to next message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
Hi,

you can add tags in the Application Model or at runtime and then use a
CSS class to style the tabs with the attributes provided. I only tried
this with MPartStacks (as only those provide the tab) and it works fine.

During runtime use DI to get the MPart in your @PostConstruct method and
then call

part.getTags().add("your-tag");

Cheers,
Marina

On 11.07.2014 15:04, Eugen Neufeld wrote:
> 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 #1400448 is a reply to message #1398705] Mon, 14 July 2014 08:04 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 63
Registered: March 2012
Member
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 #1400591 is a reply to message #1400448] Mon, 14 July 2014 12:32 Go to previous messageGo to next message
Marina Knieling is currently offline Marina KnielingFriend
Messages: 83
Registered: February 2013
Member
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 #1400639 is a reply to message #1400591] Mon, 14 July 2014 13:49 Go to previous messageGo to next message
Eugen Neufeld is currently offline Eugen NeufeldFriend
Messages: 63
Registered: March 2012
Member
Hi Marina,
I will look into this.
I think though, that it would be better to create a custom renderer or extend the existing one to directly support such a use case.
If there is a out-of-the-box solution I would be happy to use it.

Cheers.
Eugen
Re: Styling tabs of MParts [message #1739042 is a reply to message #1400639] Wed, 27 July 2016 08:02 Go to previous messageGo to next message
Christin Kocher is currently offline Christin KocherFriend
Messages: 7
Registered: July 2016
Junior Member
Hi,

is there an out of the box solution by now? Or has someone a custom renderer able to do it, which I can use?
I'm interested in exactly the same feature.

Kind regards,
Christin
Re: Styling tabs of MParts [message #1740638 is a reply to message #1398702] Tue, 16 August 2016 14:47 Go to previous message
Simon Scholz is currently offline Simon ScholzFriend
Messages: 1
Registered: August 2016
Junior Member
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
Previous Topic:Persisted object when closing MPart ?
Next Topic:Veto an Eclipse 4 view becoming invisible?
Goto Forum:
  


Current Time: Fri Mar 29 11:36:30 GMT 2024

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

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

Back to the top