|
|
|
Re: RAP Button - content alignment [message #1404573 is a reply to message #1404557] |
Mon, 04 August 2014 09:11 |
Matthias Nick Messages: 197 Registered: August 2013 |
Senior Member |
|
|
Hi Reinhold,
below I describe a solution where it is possible to set the alignment of a button's content (Left, Center, Right). This is not a global solution, but can be configured from button to button individually.
1) I created the a button and misused the getConfiguredLabelPosition property:
@Order(30.0)
public class DownloadButton extends AbstractButton {
@Override
protected boolean getConfiguredFillHorizontal() {
return true;
}
@Override
protected boolean getConfiguredProcessButton() {
return false;
}
@Override
protected int getConfiguredGridW() {
return 8;
}
@Override
protected String getConfiguredLabel() {
return TEXTS.get("Download");
}
/**
* Misuse property for Button alignment
* -1 = left
* 0 = center
* 1 = right
*/
@Override
protected int getConfiguredLabelPosition() {
return 1;
}
2) Go to your rap bundle: <your project>.ui.rap
2.1) Create the following file
public class RwtScoutAlignedButton extends RwtScoutButton<IButton> {
@Override
protected ButtonEx createSwtPushButton(Composite container, int style) {
style = SWT.PUSH;
if (getScoutObject().getLabelPosition() == -1) {
style |= SWT.LEFT;
}
else if (getScoutObject().getLabelPosition() == 0) {
style |= SWT.CENTER;
}
else {
style |= SWT.RIGHT;
}
return super.createSwtPushButton(container, style);
}
}
Here, we can react on the property we set on our Button
2.2) Create the following file
public class MyButtonFieldFactory extends ButtonFieldFactory {
@Override
protected IRwtScoutButton<IButton> createRwtScoutButton() {
return new RwtScoutAlignedButton();
}
}
3) Now, open the plugin.xml in the <your project>.ui.rap bundle, click on "Add..." and add a new 'org.eclipse.scout.rt.ui.rap.formfields' extension. Create a new formField, and set the modelClass to 'org.eclipse.scout.rt.client.ui.form.fields.button.IButton', 'active' to 'true' and 'scope' to 'global'.
4) Create a new uiFactory below the new entry, which references your MyButtonFieldFactory
Now you can set the alignment of the Button with the following code:
/**
* Misuse property for Button alignment
* -1 = left
* 0 = center
* 1 = right
*/
@Override
protected int getConfiguredLabelPosition() {
return 1;
}
As you can see, you can now change the default alignment. But notice, this solution only applies to RAP in the moment. SWT and Swing will still align the button centered, however you can use the same strategy to change the alignment. However If you really need this feature I would recommend to create a change request.
-
Attachment: plugin1.png
(Size: 43.59KB, Downloaded 347 times) -
Attachment: plugin2.png
(Size: 32.14KB, Downloaded 356 times) -
Attachment: result.png
(Size: 4.63KB, Downloaded 319 times)
[Updated on: Mon, 04 August 2014 09:13] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.02943 seconds