Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » AbstractThemeAdapter#getPrimaryElement
AbstractThemeAdapter#getPrimaryElement [message #672021] Thu, 19 May 2011 11:24 Go to next message
Stephan Leicht Vogt is currently offline Stephan Leicht Vogt
Messages: 83
Registered: February 2010
Location: Baden Switzerland
Member

Hi

I overwrite a Widget (for example a Button) to be able to debug like this:

Button button = new Button(parent, style | SWT.FLAT | orientation) {
public void setForeground(Color color) {
if (color != null) {
System.out.println(color);
}
super.setForeground(color);
}
};

Now I continue with following setting:

CSS:
Button {
color: red;
}

Java:
button.setForeground(null);
Color buttonColor = button.getForeground();

The color buttonColor will not be red as mentioned in the css but
something different. Thats because
AbstractThemeAdapter.getPrimaryElement(final Widget widget) searches the
underlying css elment with widget.getClass(), which is in our example
FormToolkit$1.

My question is: Why getPrimaryElement has to search the css element by
the class of the widget? AbstractThemeAdapter is overwritten by the
ButtonThemeAdapter and imho should know that the css element is "Button".

Can someone enlighten me in this matter?

Thanks and greetings
Stephan
Re: AbstractThemeAdapter#getPrimaryElement [message #672039 is a reply to message #672021] Thu, 19 May 2011 12:32 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

I think you've run into bug 324082 [1]. As you discovered, the
"getPrimaryElement" approach in AbstractThemeAdapter does not work
correctly for subclassed widgets.

But you should be able to work around this issue simply by not subclassing
Button. Please note that subclassing Widgets other than Composite and
Canvas is discouraged in SWT anyway [2], so your code would not run in
SWT.

Why don't you use real debugging (set breakpoints and start the
application in debug mode) instead of "sysout debugging"?

Regards, Ralf


[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=324082
[2] http://www.eclipse.org/swt/faq.php#subclassing

--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #672229 is a reply to message #672039] Fri, 20 May 2011 07:44 Go to previous messageGo to next message
Stephan Leicht Vogt is currently offline Stephan Leicht Vogt
Messages: 83
Registered: February 2010
Location: Baden Switzerland
Member

Hi Ralf

You're right, the bug 324082 [1] describes my problem.

Unfortunately not sub-classing the button or other widgets is sometimes
not a option. And since the swt faq just states that sub-classing is not
recommended, I don't see a problem to use this mechanism in special cases.

About my example for the debugging: Sometimes I just want to step into a
method invocation of a certain instance of a class. So this is imho the
simplest way to do it. If there is a simpler way please tell me.

My last question is still unanswered. Why isn't the ButtonThemeAdapter
not aware that the css representation is "Button". Why does it have to
search the representation via the class of the widget?

Kind regards
Stephan

[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=324082
Re: AbstractThemeAdapter#getPrimaryElement [message #672861 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #672877 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #672884 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #672912 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #672947 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #672955 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #673052 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #673058 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #673072 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #673127 is a reply to message #672229] Sun, 22 May 2011 07:31 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Stephan,

> Unfortunately not sub-classing the button or other widgets is sometimes
> not a option. And since the swt faq just states that sub-classing is not
> recommended,

You're right, the SWT article does not exclude the option to subclass.
But only "in extreme circumstances" and when "all other avenues have been
explored and exhausted". From my experience with SWT I can say that I've
hardly ever come to this point and I always found better ways than
subclassing to resolve problems.

> I don't see a problem to use this mechanism in special
> cases.

The SWT article list a number of problems. Moreover, the fact that SWT
throws an exception if you subclass widgets, and the warning in the
widget's API doc
* IMPORTANT: This class is intended to be subclassed <em>only</em>
* within the SWT implementation.
makes it pretty clear that this is not officially supported API. If you
go this path, you are on your own.

> About my example for the debugging: Sometimes I just want to step into a
> method invocation of a certain instance of a class. So this is imho the
> simplest way to do it. If there is a simpler way please tell me.

You can simply open the class in the Eclipse editor, set a breakpoint at
the line that you want to step into (right click at the left editor
border or Ctrl+Shift+B). Then start the application in debug mode (Run >
Debug Configurations... ). It will stop there and let you inspect the
value of all variables.

> My last question is still unanswered. Why isn't the ButtonThemeAdapter
> not aware that the css representation is "Button". Why does it have to
> search the representation via the class of the widget?

There were some corner cases that lead to this implementation, but I
don't remember the details anymore. It might well be that the cause
doesn't even exist anymore do to the refactorings that we made in this
area meanwhile. The solution is clearly problematic for custom widgets
and will be revised with bug 324082. But believe it or not, there are a
number of non-trivial constellations in the theming and changing this
place requires careful testing. Unfortunately it's too late for 1.4.

However, I would rather help you to find a better solution for your
problem than to discuss an issue that you would not have otherwise.

Could you outline the problem that caused you to subclass Button? Which
behavior or appearance did you add?


Best regards, Ralf


--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: AbstractThemeAdapter#getPrimaryElement [message #673614 is a reply to message #672861] Tue, 24 May 2011 04:43 Go to previous messageGo to next message
Stephan Leicht Vogt is currently offline Stephan Leicht Vogt
Messages: 83
Registered: February 2010
Location: Baden Switzerland
Member

Hi Ralf

> Could you outline the problem that caused you to subclass Button? Which
> behavior or appearance did you add?

I just stepped over an quite simple example which I did not find another
easy solution rather then subclassing.

Composite container = new LayoutComposite(parent, SWT.NO_FOCUS);
CLabel label = new CLabel(container, SWT.NO_FOCUS);
Text text = new Text(container, SWT.SINGLE) {
@Override
public void setBackground(Color color) {
super.setBackground(color);
if (label != null) {
label.setBackground(color);
}
}
};


So I have a container with a label and a textfield in it. Now if from
somewhere the textfield gets a new background color the label should
also change its background color. I got this behavior by overwriting the
setBackground of the textfield. What would be the solution without
subclassing? I know I could write a Widget with the textfield as
property, but then I would have to expose every public method of Text in
this widget, right?


Thanks and greetings
Stephan
Re: AbstractThemeAdapter#getPrimaryElement [message #673634 is a reply to message #673614] Tue, 24 May 2011 05:57 Go to previous messageGo to next message
Frank Appel is currently offline Frank Appel
Messages: 46
Registered: July 2009
Member
Stephan,

looking at the code in your latter post I think extending the Text widget like proposed is not a good idea. As an user of the Text widget type I do not expect to interact with another widget by setting the background color of the text. In fact the subclass breaks the contract of control (see JavaDoc), since IMHO the label is not what's called receiver in the API documentation.

If you want to solve your problem with subclassing I would rather use a solution like that one I have drafted below. Looking at the JavaDoc of Composite it states

* This class may be subclassed by custom control implementors
* who are building controls that are constructed from aggregates
* of other controls

which seems to me describes exactly the relationship of text and label in your use case. In case you want to change properties of one of the aggregats (in your case the text field) a simple getter can be used:


public class TextWithLabel extends Composite {
private final Label label;
private final Text text;

public TextWithLabel( Composite parent, int style ) {
super( parent, style );
label = new Label( this, SWT.NO_FOCUS);
text = new Text( this, SWT.SINGLE );
}

public void setChildrenBackground( Color color) {
label.setBackground( color );
text.setBackground( color );
}

public Text getText() {
return text;
}

public Label getLabel() {
return label;
}
}

Regards
Frank
Re: AbstractThemeAdapter#getPrimaryElement [message #673684 is a reply to message #673634] Tue, 24 May 2011 09:19 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan Motsch
Messages: 82
Registered: March 2010
Member
It seems to me that the discussion is drifting away a little bit.
The concern is not swt's lack of subclassing concepts, the concern regards the
architectural design of rwt in which way it maps themes/ui to swt widgets.

A ui to widget mapping - from an architectural point of view - should not just be measured on how strict or straight-forward (class names...) it is but how and where it is extendible, where it is not, and how flexible it is.
In short: Good design is simple, flexible and extensible in its main aspects BUT may be strict, closed and final in its side aspects.

May I point to a very similar area of architectural design pattern regarding ui mapping in swing.
Swing has as it's core concept the separation of widgets (JButton, JTextField) and their ui (ButtonUI, TextFieldUI). A look- and-feel (or theme) is created by creating a ui layer for example SynthButtonUI, SynthTextFieldUI etc.

The connecting glue between widget and ui is JComponent.getUIClassID();
public String getUIClassID() {
return uiClassID;
}
Every subclass of JComponent may overwrite the UIClassID property (for example ComponentUI, ButtonUI, TextFieldUI, etc.)

Also in swing it is not recommended to subclass swing widgets. However sometimes it is done and necessary to work around bugs and features coming too late to the project.
The way swing maps widgets to ui is simple, flexible and extensible.

As it is not realistic to extend SWT's Widget with a property "getUIClassID" we may use the SWT idea of extension. "Adapters".
RWT may add the IUIClassAdapter to their widget implementation.

public interface IUIClassAdapter{
String getUIClassID();
}

The rwt ui mapper may simply call String uiClass=((IUIClassAdapter)aWidget.getAdapter(IUIClassAdapter.class)).getUIClassID();
Whether or not a swt widget is a subclass does compromise ui mapping. There is no drawback to todays solution. That way is more flexible, backward compatible to JRE1.4 and eclipse 3.4 and reduces swt design impacts on rwt ui mapping.
From a design and architecture point of view a "better" solution.

So why reinventing the weel, that kind of mapping is in place for almost 15 years now and did a good job for styleable and extendible look and feel concept.

I think that RWT does a brilliant job. It sits between SWT and Web2.0. The above discussion is - for my flavor - too swt centric. Please also address enough Web2.0 apsects since
RAP will in future more and more be compared to ZK, Vaadin and Google WTK.

Looking foreward to more fantastic RWT development, thanks guys.

[Updated on: Tue, 24 May 2011 09:36]

Report message to a moderator

Re: AbstractThemeAdapter#getPrimaryElement [message #674212 is a reply to message #673684] Thu, 26 May 2011 03:15 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan Motsch
Messages: 82
Registered: March 2010
Member
Hi, i assume major prio is now on the indigo release. However if you find some time later-on i will be happy for feedback.
good luck.
Re: AbstractThemeAdapter#getPrimaryElement [message #674222 is a reply to message #674212] Thu, 26 May 2011 03:20 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan Furnadjiev
Messages: 1421
Registered: July 2009
Senior Member
Hi,
you suggestion sounds reasonable. Could you open an enhancement request
and outline your idea there? Thus, it will help us to keep track on it.
Thanks,
Ivan

On 5/26/2011 10:15 AM, forums-noreply@eclipse.org wrote:
> Hi, i assume major prio is now on the indigo release. However if you
> find some time later-on i will be happy for feedback. good luck.
Re: AbstractThemeAdapter#getPrimaryElement [message #674665 is a reply to message #673684] Fri, 27 May 2011 15:21 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Ivan,

I'm sorry for the delay, I've not been able to follow up during the last days.

If I understand your proposal correctly, you suggest to introduce a mechanism that would allow to specify a certain type of styling for a widget.
Such a mechanism is already in place in RWT, it's called "Custom Variants". Those variants are comparable to classes in CSS. They are strings that can be attached to a widget using SWT's setData() method:

Text text = new Text( parent, SWT.SINGLE );
text.setData( WidgetUtil.CUSTOM_VARIANT, "mySearchField" );

In the theming, you can specify customized CSS parameters for those text fields, that have this custom variant:

Text.mySearchField {
padding: 5px 10px;
background-color: yellow;
...
}

Is this an acceptable replacement for the mapping you described?

Best regards,
Ralf
Re: AbstractThemeAdapter#getPrimaryElement [message #675683 is a reply to message #674665] Wed, 01 June 2011 03:58 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan Motsch
Messages: 82
Registered: March 2010
Member
Hi Ralph,

thanks for the feedback. No, i really meant inlining html and supporting multiline.
I also created a bugzilla that i discussed with Ivan.

I met Holger today, maybe we can do a phone conference (skype) once indigo hot phase is over. That would be a great opportunity to push things forward and synchronize on ideas. Just give me one bit when ready, maybe in 3-4 weeks time.
Re: AbstractThemeAdapter#getPrimaryElement [message #675702 is a reply to message #675683] Wed, 01 June 2011 04:54 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan Motsch
Messages: 82
Registered: March 2010
Member
Errata: when typing the response i was in the wrong mental thread, sorry:)
ignore part 1 (inlining html), only read part 2 (phone conf).
Re: AbstractThemeAdapter#getPrimaryElement [message #675866 is a reply to message #675683] Wed, 01 June 2011 14:36 Go to previous message
Ralf Sternberg is currently offline Ralf Sternberg
Messages: 1146
Registered: July 2009
Senior Member

Hi Ivan,

sure, that sounds like a good plan. I'll come back to you.

Best, Ralf

--
Ralf Sternberg

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Previous Topic:(no subject)
Next Topic:Context menus for TableHeaders
Goto Forum:
  


Current Time: Mon May 20 13:11:28 EDT 2013

Powered by FUDForum. Page generated in 0.02463 seconds