Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 271531 - [CSS] Button styleable properties
Summary: [CSS] Button styleable properties
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 4.1   Edit
Assignee: Kevin McGuire CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 271532 (view as bug list)
Depends on: 277230
Blocks: 271532
  Show dependency tree
 
Reported: 2009-04-07 18:20 EDT by Kevin McGuire CLA
Modified: 2011-05-17 16:23 EDT (History)
2 users (show)

See Also:


Attachments
checked pseudo selector for Button (5.62 KB, patch)
2009-04-17 16:07 EDT, Aghiles Abdesselam CLA
no flags Details | Diff
checked pseudo selector for Button (5.28 KB, patch)
2009-04-17 16:15 EDT, Aghiles Abdesselam CLA
no flags Details | Diff
selected pseudo selector for Button (6.45 KB, patch)
2009-04-22 14:43 EDT, Aghiles Abdesselam CLA
no flags Details | Diff
junit for button:selected (1.80 KB, patch)
2009-04-23 10:38 EDT, Aghiles Abdesselam CLA
no flags Details | Diff
Label and Button now have alignment stylable property (8.12 KB, patch)
2009-04-24 16:23 EDT, Aghiles Abdesselam CLA
john.arthorne: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin McGuire CLA 2009-04-07 18:20:22 EDT
org.eclipse.swt.Button has the following setters which are candidates for styling:

Properties:
  setAlignment: LEFT/RIGHT/CENTER or LEFT/RIGHT/UP/DOWN if ARROW button
  setGrayed: boolean

Pseudo Selectors:
  :selected

I'm not sure what happens for setAlignment as we don't have the notion of a constant in CSS ... do you just write

Button {
  alignment: LEFT;
}

and the value just comes in as a string?
Comment 1 Angelo ZERR CLA 2009-04-08 03:22:48 EDT
>I'm not sure what happens for setAlignment as we don't have the notion of a
>constant in CSS ... do you just write

>Button {
>  alignment: LEFT;
>}

I have two ideas : 

1. Perhaps whe should follow the same idea than SWT style used into selector.

Button[style~='SWT.CHECK'] {
...
}

So we could write : 

Button {
  alignment: 'SWT.LEFT';
}

We could use (and update it if need) class SWTStyleHelpers which manage CSS SWT style String by using int style value.

2. Follow CSS2 Properties

I believe SWT button alignment is the same thing CSS text-align properties. See at http://www.w3schools.com/CSS/pr_text_text-align.asp.

So we could write : 


Button {
  text-align:left;
}

In this cas, value comes from String.

Regards Angelo
Comment 2 Kevin McGuire CLA 2009-04-08 10:23:29 EDT
(In reply to comment #1)
> >I'm not sure what happens for setAlignment as we don't have the notion of a
> >constant in CSS ... do you just write
> 
> >Button {
> >  alignment: LEFT;
> >}
> 
> I have two ideas : 
> 
> 1. Perhaps whe should follow the same idea than SWT style used into selector.
> 
> Button[style~='SWT.CHECK'] {
> ...
> }
> 
> So we could write : 
> 
> Button {
>   alignment: 'SWT.LEFT';
> }

And just treat it as a string property right?

How about how handle boolean ... it's also not a CSS2 property value so we just read as a string but then convert.  In this case we don't quote it in the CSS source.
 
> We could use (and update it if need) class SWTStyleHelpers which manage CSS SWT
> style String by using int style value.

Interesting, didn't know about this class.  But we'd need a different method that went the other direction: took an SWT style string and returned the matching SWT constant.

> 2. Follow CSS2 Properties
> 
> I believe SWT button alignment is the same thing CSS text-align properties. See
> at http://www.w3schools.com/CSS/pr_text_text-align.asp.
> 
> So we could write : 
> 
> 
> Button {
>   text-align:left;
> }
> 
> In this cas, value comes from String.

Very clever, but unfortunately doesn't include all the cases since for arrow buttons we also have SWT.UP, SWT.DOWN.  In any case I like the other approach where we have a standardized way of reading in SWT constant values, validating, and converting.  Thanks for the ideas Angelo.
Comment 3 Aghiles Abdesselam CLA 2009-04-17 16:07:49 EDT
Created attachment 132293 [details]
checked pseudo selector for Button

I added a selector for the Button widget. It is pretty much what you had, selected, but due to current implementation of the selected pseudo, I thought it might be easier to name it "checked" instead. So "Button: checked" can be used for styling. I've been trying for a while to make a Junit test for this, but since the implementation makes use of a SelectionListener, and the fact that setSelection() doesn't seem to send an event, I was unable to do so at the moment.
Comment 4 Aghiles Abdesselam CLA 2009-04-17 16:15:50 EDT
Created attachment 132295 [details]
checked pseudo selector for Button

Going through some of my code I realized that there were some unnecessary lines of code, so I removed them.
Comment 5 Kevin McGuire CLA 2009-04-18 20:00:25 EDT
(In reply to comment #3)
> Created an attachment (id=132293) [details]
> checked pseudo selector for Button
> 
> I added a selector for the Button widget. It is pretty much what you had,
> selected, but due to current implementation of the selected pseudo, I thought
> it might be easier to name it "checked" instead. So "Button: checked" can be
> used for styling. 

I don't understand, why is "button:selected" a problem?  The issue with the word "checked" is one that it doesn't match the getter getSelection(), plus Buttons can be style CHECK, so the pseudo ":checked" and the style "CHECK" seem related but are not. For example, this is the javadoc for getSelection():

 * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
 * it is selected when it is checked. When it is of type <code>TOGGLE</code>,
 * it is selected when it is pushed in. If the receiver is of any other type,
 * this method returns false.
Comment 6 Aghiles Abdesselam CLA 2009-04-22 14:43:00 EDT
(In reply to comment #5)

> I don't understand, why is "button:selected" a problem? 

I looked into my code and made a few changes, and it doesn't seem to conflict with the other "selected" pseudo. The patch is updated, and it is not Button:selected
Comment 7 Aghiles Abdesselam CLA 2009-04-22 14:43:26 EDT
Created attachment 132823 [details]
selected pseudo selector for Button
Comment 8 Aghiles Abdesselam CLA 2009-04-22 14:44:20 EDT
Sorry there was a typo. It is NOW Button:selected
Comment 9 Kevin McGuire CLA 2009-04-22 19:52:06 EDT
(In reply to comment #7)
> Created an attachment (id=132823) [details]
> selected pseudo selector for Button

Great!  Junit? 

Comment 10 Kevin McGuire CLA 2009-04-22 19:53:43 EDT
Verified it works for a standalone test, will close when junit attached. Releasing code now though.
Comment 11 Aghiles Abdesselam CLA 2009-04-23 10:38:50 EDT
Created attachment 132948 [details]
junit for button:selected
Comment 12 Aghiles Abdesselam CLA 2009-04-24 16:23:47 EDT
Created attachment 133183 [details]
Label and Button now have alignment stylable property

Both Button and Label can now be styled with alignment. Unfortunately the engine cannot accept values with quotation marks, single quotes, and periods, therefore the available values are: left, right, center, up, down
Comment 13 Kevin McGuire CLA 2009-05-20 18:00:14 EDT
Applied patch with following changes:

- Label does *not* support alignment UP and DOWN (only for Buttons in arrow mode).  Removed from property handler, tests.
- Tests were a bit thin, only testing one alignment for each of Button and Label, added all alignments, including a second test for Button to create it in ARROW mode.
- test superclass change for bug #277230

Note test classes released as part of #277230.
Comment 14 Kevin McGuire CLA 2009-05-20 18:00:40 EDT
*** Bug 271532 has been marked as a duplicate of this bug. ***
Comment 15 Kevin McGuire CLA 2009-05-20 18:08:43 EDT
reopening to fix owner
Comment 16 Kevin McGuire CLA 2009-05-20 18:09:16 EDT
changing owner
Comment 17 Kevin McGuire CLA 2009-05-20 18:09:49 EDT
re-closing