Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » RAP Button - content alignment
RAP Button - content alignment [message #1404443] Fri, 01 August 2014 12:34 Go to next message
Reinhold Kern is currently offline Reinhold KernFriend
Messages: 20
Registered: August 2014
Junior Member
Hi

how to align the content of a button (image + text) to a distinct direction e. g. left side. The property 'label position' seem not to work. I does not matter which value I use, the content is always centered. The button is inside a GroupBox and the property 'Fill Horizontal' is true.

In the attached image yout can see how I want to align the content.

Thanks in advance.




Re: RAP Button - content alignment [message #1404549 is a reply to message #1404443] Mon, 04 August 2014 06:57 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
Messages: 197
Registered: August 2013
Senior Member
Hi Reinhold,

thanks for your question. Unfortunately, the alignment of the button seems to be hardcoded:

org.eclipse.scout.rt.ui.rap.form.fields.button.RwtScoutButton.initializeUi(Composite)
...
uiFieldAsButton = createSwtPushButton(m_menuMarkerComposite, SWT.CENTER | SWT.PUSH);


As for the moment there is no "easy" way to change the alignment. However it would be possible to override this "global" behaviour in a kind of workaround. If you are interested in the workaround, let me know. Otherwise you could create a new bug and specify it as "enhancement".

Hope this helps,
Matthias
Re: RAP Button - content alignment [message #1404557 is a reply to message #1404549] Mon, 04 August 2014 07:46 Go to previous messageGo to next message
Reinhold Kern is currently offline Reinhold KernFriend
Messages: 20
Registered: August 2014
Junior Member
Hi Matthias,

thank you for the fast reply!

So the "global" workaround would mean, that I could only set a distinct aligment for all buttons in the application and not for each?

But I am interested anyway.

Thanks in advance.

Reinhold.
Re: RAP Button - content alignment [message #1404573 is a reply to message #1404557] Mon, 04 August 2014 09:11 Go to previous messageGo to next message
Matthias Nick is currently offline Matthias NickFriend
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'.
index.php/fa/18739/0/

4) Create a new uiFactory below the new entry, which references your MyButtonFieldFactory
index.php/fa/18740/0/

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.

index.php/fa/18741/0/
  • 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

Re: RAP Button - content alignment [message #1404581 is a reply to message #1404573] Mon, 04 August 2014 09:47 Go to previous message
Reinhold Kern is currently offline Reinhold KernFriend
Messages: 20
Registered: August 2014
Junior Member
Thank you very much!!!
Previous Topic:Renaming and plugin.xml
Next Topic:Dynamic form width
Goto Forum:
  


Current Time: Wed Apr 24 22:42:55 GMT 2024

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

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

Back to the top