Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Dialog problems
Dialog problems [message #53275] Thu, 18 October 2007 10:54 Go to next message
Eclipse UserFriend
Originally posted by: sparkitny.gmail.com

Hello there,

I'm new to RAP and tried to implement a dialog but unfortunately I've got
some problems. First my code:

package rap;

import inmt.web_service.INMTStub;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.rwt.lifecycle.UICallBack;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.webhmi.inmt.xsd.OwnUnitDataDocument.OwnUnitData;

import util.DataProvider;
import util.WaitDialog;

public class MyDialog extends Dialog {

private Text text1;

private Text text2;

private Text text3;

/**
* Constructor
*
* @param parentShell
*/
protected MyDialog(Shell parentShell) {
super(parentShell);
}

/**
* Creates a label, adds it and returns it
*
* @param parent
* @param text
* @return
*/
private CLabel getLabel(Composite parent, String text) {

CLabel label = new CLabel(parent, SWT.BORDER);
label.setText(text);
label.setLayoutData(getGridData(false));
return label;
}

/**
* Creates Textbox
*
* @param parent
* @return
*/
private Text getTextBox(Composite parent) {

Text text = new Text(parent, SWT.BORDER);
GridData griddata = getGridData(true);
text.setLayoutData(griddata);

return text;
}

/**
* Creates grid data
*
* @return
*/
private GridData getGridData(boolean fill) {

GridData griddata = new GridData(SWT.LEFT, SWT.CENTER, true, true);

if (fill) {
griddata.horizontalAlignment = SWT.FILL;
}

return griddata;
}

/**
* Creates the view of the Control
*/
protected Control createContents(Composite parent) {

WaitDialog.getInstance().close();

Composite top = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginHeight = 10;
layout.marginWidth = 10;

top.setLayout(layout);

getLabel(top, "Designator");
text1 = getTextBox(top);
getLabel(top, "FTN");
text2 = getTextBox(top);
getLabel(top, "SNC Version");
text3 = getTextBox(top);

parent.pack(true);
parent.setSize(400, 400);

return parent;
}

/**
* Configures the shell
*/
protected void configureShell(Shell shell) {

super.configureShell(shell);
shell.setText("My Dialog");
shell.setLocation(200, 200);


}

@Override
protected void createButtonsForButtonBar(Composite parent) {
// TODO Auto-generated method stub
super.createButtonsForButtonBar(parent);
createButton(parent, 10, "asda", true);
}
}


There are several problems:

1) The dialog had the problem that after the second opening I didn't
display the Text and Labels anymore. After adding pack()-call the problem
disappeared.
2) Now the buttons are never displayed although I added a call. Why?
3) How can I define new Colors without SWT-constants?
4) How can I center the dialog to the screen?

Thanks in advance,

Sebastian
Re: Dialog problems [message #54501 is a reply to message #53275] Tue, 23 October 2007 09:17 Go to previous message
Eclipse UserFriend
Originally posted by: fappel.innoopract.com

Hi,

1) The dialog had the problem that after the second opening I didn't
display the Text and Labels anymore. After adding pack()-call the
problem
disappeared.

This is because you are overriding the wrong method. Use
Dialog#createDialogArea(Composite) instead of
Dialog#createContents(Composite). Doing so you don't have to call
Control#pack() and the buttons will reappear again.


2) Now the buttons are never displayed although I added a call. Why?

See anser to 1)


3) How can I define new Colors without SWT-constants?

Color red = Graphics.getColor( 255, 0, 0 );


4) How can I center the dialog to the screen?

By overriding the method Dialog#initializeBounds():

protected void initializeBounds() {
super.initializeBounds();
Rectangle displayBounds = Display.getCurrent().getBounds();
Point size = getShell().getSize();
int x = ( displayBounds.width - size.x ) / 2;
int y = ( displayBounds.height - size.y ) / 2;
getShell().setLocation( x, y );
}


Hope that helps!


Ciao
Frank


"Sebastian Parkitny" <sparkitny@gmail.com> schrieb im Newsbeitrag
news:34f18c952a8dc7e4855d8290103a78f9$1@www.eclipse.org...
> Hello there,
>
> I'm new to RAP and tried to implement a dialog but unfortunately I've got
> some problems. First my code:
>
> package rap;
>
> import inmt.web_service.INMTStub;
>
> import org.eclipse.jface.dialogs.Dialog;
> import org.eclipse.rwt.lifecycle.UICallBack;
> import org.eclipse.swt.SWT;
> import org.eclipse.swt.custom.CLabel;
> import org.eclipse.swt.layout.GridData;
> import org.eclipse.swt.layout.GridLayout;
> import org.eclipse.swt.widgets.Composite;
> import org.eclipse.swt.widgets.Control;
> import org.eclipse.swt.widgets.Display;
> import org.eclipse.swt.widgets.Shell;
> import org.eclipse.swt.widgets.Text;
> import org.webhmi.inmt.xsd.OwnUnitDataDocument.OwnUnitData;
>
> import util.DataProvider;
> import util.WaitDialog;
>
> public class MyDialog extends Dialog {
>
> private Text text1;
>
> private Text text2;
>
> private Text text3;
>
> /**
> * Constructor
> * * @param parentShell
> */
> protected MyDialog(Shell parentShell) {
> super(parentShell);
> }
>
> /**
> * Creates a label, adds it and returns it
> * * @param parent
> * @param text
> * @return
> */
> private CLabel getLabel(Composite parent, String text) {
>
> CLabel label = new CLabel(parent, SWT.BORDER);
> label.setText(text);
> label.setLayoutData(getGridData(false));
> return label;
> }
>
> /**
> * Creates Textbox
> * * @param parent
> * @return
> */
> private Text getTextBox(Composite parent) {
>
> Text text = new Text(parent, SWT.BORDER);
> GridData griddata = getGridData(true);
> text.setLayoutData(griddata);
>
> return text;
> }
>
> /**
> * Creates grid data
> * * @return
> */
> private GridData getGridData(boolean fill) {
>
> GridData griddata = new GridData(SWT.LEFT, SWT.CENTER, true, true);
>
> if (fill) {
> griddata.horizontalAlignment = SWT.FILL;
> }
>
> return griddata;
> }
>
> /**
> * Creates the view of the Control
> */
> protected Control createContents(Composite parent) {
>
> WaitDialog.getInstance().close();
>
> Composite top = new Composite(parent, SWT.NONE);
> GridLayout layout = new GridLayout();
> layout.numColumns = 2;
> layout.marginHeight = 10;
> layout.marginWidth = 10;
>
> top.setLayout(layout);
>
> getLabel(top, "Designator");
> text1 = getTextBox(top);
> getLabel(top, "FTN");
> text2 = getTextBox(top);
> getLabel(top, "SNC Version");
> text3 = getTextBox(top);
>
> parent.pack(true);
> parent.setSize(400, 400);
> return parent;
> }
>
> /**
> * Configures the shell
> */
> protected void configureShell(Shell shell) {
>
> super.configureShell(shell);
> shell.setText("My Dialog");
> shell.setLocation(200, 200);
>
>
> }
>
> @Override
> protected void createButtonsForButtonBar(Composite parent) {
> // TODO Auto-generated method stub
> super.createButtonsForButtonBar(parent);
> createButton(parent, 10, "asda", true);
> }
> }
>
>
> There are several problems:
>
> 1) The dialog had the problem that after the second opening I didn't
> display the Text and Labels anymore. After adding pack()-call the problem
> disappeared.
> 2) Now the buttons are never displayed although I added a call. Why?
> 3) How can I define new Colors without SWT-constants?
> 4) How can I center the dialog to the screen?
>
> Thanks in advance,
>
> Sebastian
>
Previous Topic:FormToolkit classdef problems
Next Topic:TimerTask
Goto Forum:
  


Current Time: Fri Apr 19 15:01:42 GMT 2024

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

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

Back to the top