Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » HowTo style BUTTON correctly - is there a bug or feature?(Can you help to understand how theme works in RAP?)
HowTo style BUTTON correctly - is there a bug or feature? [message #654660] Wed, 16 February 2011 15:22 Go to next message
derhaa is currently offline derhaaFriend
Messages: 6
Registered: February 2011
Junior Member
I do not understand how theme works in RAP. When I implement sublass of Button (MyButton). Theme does not work as I expect. There is differenct behaviour for BUTTON and subclass of BUTTON. Why?

It can be unproductive - Maybe there will be create another widget with SWT.PUSH and if I use solution in above (theme2 and screenshot 2) widget will be styled same as MyButton. Is it correct?

There are code with implementation of buttons.
public class ViewThemeTest extends ViewPart {

    public static final String ID = "cz.test.ui.viewtheme";
    
    @Override
    public void createPartControl(Composite parent)  {
        GridLayout gl = new GridLayout();
        gl.numColumns = 1;
        gl.horizontalSpacing = 5;
        gl.verticalSpacing = 5;
        gl.marginWidth = 5;
        gl.marginHeight = 5;
        parent.setLayout(gl);
        parent.setLayoutData(null);
        
        Composite main = new Composite(parent, SWT.NONE);
        main.setLayout(new GridLayout(2, false));
        main.setLayoutData(new GridData(2, 2, false, false));
        
        Button btn = new Button(main, SWT.PUSH);
        btn.setText("RAP btn");
        btn.setToolTipText("RAP btn");        
        
        MyButton myBtn = new MyButton(main, SWT.PUSH, "My btn", "My btn");
        myBtn.languageChange();
    }

    @Override
    public void setFocus() {
        // TODO Auto-generated method stub

    }

    private static class MyButton extends Button implements ITranslatable {

        public MyButton(Composite parent, int style, String caption, String tooltip) {
            super(parent, style);
            setText(caption);
            setToolTipText(tooltip);
        }

        @Override
        public void languageChange() {
            //TODO translate caption and tooltip
        }
        
    }
}


THEME.css
Button {
  color: black;
  font : bold 12px Arial, Helvetica, sans-serif;
}

Button[PUSH] {
  /*background-image:none;*/
  background-color : #9dd0ea;
  padding: 10px;
}

Screenshot 1.
http://www.imageshare.web.id/images/uguofsdajzctho2hd4kx.png

//---------------------------------------------------------- ------------------------------------------------------------ ---------------------------------

But when I use *[PUSH] in theme - MyButton is styled as I want. I would expect that can style button uniformly.

THEME2.css
Button {
  color: black;
  font : bold 12px Arial, Helvetica, sans-serif;
}

*[PUSH] {
  padding: 20px;
}

Button[PUSH] {
  background-color : #9dd0ea;
  padding: 10px;
}


Screenshot 2.
http://www.imageshare.web.id/images/fen9ysm3ptl90xq6f9d.png

[Updated on: Wed, 16 February 2011 15:49]

Report message to a moderator

Re: HowTo style BUTTON correctly - is there a bug of feature? [message #654690 is a reply to message #654660] Wed, 16 February 2011 16:42 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2359
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi,
subclassing the Button class is not a good idea. If you read the
documentation, it states:
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
If you want to create your own control, you should subclass Composite or
Canvas (see [1]).
There is a know issue with the theming:
324082: [Theming] ThemeAdapters return wrong values for subclassed widgets
https://bugs.eclipse.org/bugs/show_bug.cgi?id=324082

[1]
http://www.eclipse.org/articles/Article-Writing%20Your%20Own %20Widget/Writing%20Your%20Own%20Widget.htm
HTH,
Ivan

On 2/16/2011 5:22 PM, derhaa wrote:
> I do not understand how theme works in RAP. When I implement sublass
> of Button (MyButton). Theme does not work as I expect. There is
> differenct behaviour for BUTTON and subclass of BUTTON. Why?
>
> It can be unproductive - Maybe there will be create another widget
> with SWT.PUSH and if I use solution in above (theme2 and screenshot
> 2) widget will be styled same as MyButton. Is it correct?
>
> There are code with implementation of buttons.
>
> public class ViewThemeTest extends ViewPart {
>
> public static final String ID = "cz.test.ui.viewtheme";
> @Override
> public void createPartControl(Composite parent) {
> GridLayout gl = new GridLayout();
> gl.numColumns = 1;
> gl.horizontalSpacing = 5;
> gl.verticalSpacing = 5;
> gl.marginWidth = 5;
> gl.marginHeight = 5;
> parent.setLayout(gl);
> parent.setLayoutData(null);
> Composite main = new Composite(parent, SWT.NONE);
> main.setLayout(new GridLayout(2, false));
> main.setLayoutData(new GridData(2, 2, false, false));
> Button btn = new Button(main, SWT.PUSH);
> btn.setText("RAP btn");
> btn.setToolTipText("RAP btn"); MyButton
> myBtn = new MyButton(main, SWT.PUSH, "My btn", "My btn");
> myBtn.languageChange();
> }
>
> @Override
> public void setFocus() {
> // TODO Auto-generated method stub
>
> }
>
> private static class MyButton extends Button implements
> ITranslatable {
>
> public MyButton(Composite parent, int style, String caption,
> String tooltip) {
> super(parent, style);
> setText(caption);
> setToolTipText(tooltip);
> }
>
> @Override
> public void languageChange() {
> //TODO translate caption and tooltip
> }
> }
> }
>
>
> THEME.css
>
> Button {
> color: black;
> font : bold 12px Arial, Helvetica, sans-serif;
> }
>
> Button[PUSH] {
> /*background-image:none;*/
> background-color : #9dd0ea;
> padding: 10px;
> }
>
> Screenshot 1.
> http://www.imageshare.web.id/images/uguofsdajzctho2hd4kx.png
>
> //----------------------------------------------------------
> ------------------------------------------------------------
> ---------------------------------
>
> But when I use *[PUSH] in theme - MyButton is styled as I want. I
> would expect that can style button uniformly.
>
> THEME2.css
>
> Button {
> color: black;
> font : bold 12px Arial, Helvetica, sans-serif;
> }
>
> *[PUSH] {
> padding: 20px;
> }
>
> Button[PUSH] {
> background-color : #9dd0ea;
> padding: 10px;
> }
>
>
> Screenshot 2.
> http://www.imageshare.web.id/images/fen9ysm3ptl90xq6f9d.png
>
Re: HowTo style BUTTON correctly - is there a bug of feature? [message #654795 is a reply to message #654690] Thu, 17 February 2011 08:12 Go to previous message
derhaa is currently offline derhaaFriend
Messages: 6
Registered: February 2011
Junior Member
I overlook the information -
Ivan Furnadjiev wrote on Wed, 16 February 2011 11:42
This class is intended to be subclassed only within the SWT implementation
.

It absolutly crucial changes my design how to implement abstraction of widgets.Thanks for your answer.
Previous Topic:RAP + pageable table
Next Topic:RAP Theming (Focus)
Goto Forum:
  


Current Time: Wed Oct 27 01:57:34 GMT 2021

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

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

Back to the top