I would design TitleAreaDialog similar to those Eclipse but without sucess, below there is two screenshot, Eclipse form and my own form,
i have problem to get the top and bottom separator, if you notice,Eclipse form don't gave a margin and the workspace have margin.
in my own form my separator have a margin
Eclipse Form : http://farm8.staticflickr.com/7437/9075688435_d5c49770fa_b.jpg
My own Form http://farm4.staticflickr.com/3688/9077919366_8c25c40a79_b.jpg
here is the source code of my class
public class CompteDialog extends TitleAreaDialog {
private Text idCompteText;
private Text libelleCompteText;
private Text ribCompteText;
private Text agenceCompteText;
public CompteDialog(Shell parentShell) {
super(parentShell);
}
@Override
public void create() {
super.create();
// Set the title
setTitle("Fiche comptes");
// Set the message
setMessage("Saisissez les informations relatives au compte",
IMessageProvider.INFORMATION);
}
@Override
protected Control createDialogArea(Composite parent) {
setTitleImage(ResourceManager.getPluginImage(
"dz.iaityahia.cieptalcars.matresorerie", "icons/wallet.png"));
GridLayout layout = new GridLayout();
layout.numColumns = 2;
parent.setLayout(layout);
// Champs ID
Label idCompteLabel = new Label(parent, SWT.NONE);
idCompteLabel.setText("Compte ID");
GridData gridData = new GridData(GridData.BEGINNING,
GridData.BEGINNING, true, false, 1, 1);
idCompteText = new Text(parent, SWT.BORDER);
idCompteText.setLayoutData(gridData);
idCompteText.setTextLimit(20);
gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false,
1, 1);
// Champs libelle
Label libelleCompteLabel = new Label(parent, SWT.NONE);
libelleCompteLabel.setText("Libellé compte");
libelleCompteText = new Text(parent, SWT.BORDER);
libelleCompteText.setLayoutData(gridData);
// Champs Rib
Label ribCompteLabel = new Label(parent, SWT.NONE);
ribCompteLabel.setText("R.I.B");
gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false,
1, 1);
ribCompteText = new Text(parent, SWT.BORDER);
ribCompteText.setLayoutData(gridData);
gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false,
1, 1);
// Champs libelle
Label agenceCompteLabel = new Label(parent, SWT.NONE);
agenceCompteLabel.setText("Agence bancaire");
agenceCompteText = new Text(parent, SWT.BORDER);
agenceCompteText.setLayoutData(gridData);
// Create a bottom separator
Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
line.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true, 2, 1));
return parent;
}
@Override
protected Control createButtonBar(Composite parent) {
final Composite buttonBar = new Composite(parent, SWT.NONE);
final GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.makeColumnsEqualWidth = false;
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
buttonBar.setLayout(layout);
GridData gridData = new GridData(GridData.FILL, GridData.END, true,
true, 2, 1);
buttonBar.setLayoutData(gridData);
/*
* org.eclipse.swt.graphics.Color magenta =
* Display.getDefault().getSystemColor(SWT.COLOR_MAGENTA);
* buttonBar.setBackground(magenta);
*/
// Create Add button
// Own method as we need to overview the SelectionAdapter
createOkButton(buttonBar, OK, "Add", true);
// Add a SelectionListener
// Create Cancel button
Button cancelButton = createButton(buttonBar, CANCEL, "Cancel", false);
// Add a SelectionListener
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setReturnCode(CANCEL);
close();
}
});
return buttonBar;
}
protected Button createOkButton(Composite parent, int id, String label,
boolean defaultButton) {
Button button = new Button(parent, SWT.PUSH);
button.setText(label);
button.setFont(JFaceResources.getDialogFont());
button.setData(new Integer(id));
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (isValidInput()) {
okPressed();
}
}
});
if (defaultButton) {
Shell shell = parent.getShell();
if (shell != null) {
shell.setDefaultButton(button);
}
}
setButtonLayoutData(button);
return button;
}
private boolean isValidInput() {
boolean valid = true;
if (idCompteText.getText().length() == 0) {
setErrorMessage("Veuillez saisir le compte ID");
valid = false;
}
if (libelleCompteText.getText().length() == 0) {
setErrorMessage("Veuillez saisir le libellé du compte");
valid = false;
}
return valid;
}
@Override
protected boolean isResizable() {
return true;
}
}
Could someone give me an idea how to get TiteAreaDialog similar to those of Eclipse ?
with my thank's
I finally solved the problem myself, after thoroughly looked at the code of the TitleAreaDilog class, I found that there was no way to do this directly.
with a little imagination I found the trick, it was necessary to create two nested Composites the parent Composite without margin will contain the two separators and the child composite which have margin and will contain others controls.
as we you can see in the example below.
I hope this will help some beginners like me
package dz.iaityahia.cieptalcars.matresorerie.dialogs;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.ResourceManager;
public class CompteDialog extends TitleAreaDialog {
private Text idCompteText;
private Text libelleCompteText;
private Text ribCompteText;
private Text agenceCompteText;
public CompteDialog(Shell parentShell) {
super(parentShell);
setHelpAvailable(true);
// TODO Auto-generated constructor stub
}
@Override
public void create() {
super.create();
// Set the title
setTitle("Fiche comptes");
// Set the message
setMessage("Saisissez les informations relatives au compte",
IMessageProvider.INFORMATION);
setTitleImage(ResourceManager.getPluginImage("dz.iaityahia.cieptalcars.matresorerie", "icons/wallet.png"));
}
@Override
protected Control createDialogArea(Composite parent) {
// cr�ation du Layout du la boite de dialog
GridLayout parentLayout = new GridLayout();
parentLayout.numColumns=1;
parentLayout.marginWidth=0;
parentLayout.marginHeight=0;
parent.setLayout(parentLayout);
//Cr�ation du s�parateur sup�rieur
Label linetop = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
linetop.setLayoutData(new GridData (SWT.FILL,SWT.TOP,true,false));
//Cr�ation du composite contenu
Composite workArea = new Composite(parent, SWT.NONE);
workArea.setLayoutData(new GridData (SWT.FILL,SWT.FILL,true,true));
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth=10;
layout.marginHeight=10;
workArea.setLayout(layout);
// Champs ID
Label idCompteLabel = new Label(workArea,SWT.NONE);
idCompteLabel.setText("Compte ID");
idCompteText = new Text(workArea, SWT.BORDER);
idCompteText.setLayoutData(new GridData(GridData.BEGINNING, GridData.BEGINNING, true,false,1, 1));
idCompteText.setTextLimit(20);
// Champs libelle
Label libelleCompteLabel = new Label(workArea,SWT.NONE);
libelleCompteLabel.setText("Libell� compte");
libelleCompteText = new Text(workArea, SWT.BORDER);
libelleCompteText.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true,false,1, 1));
// Champs Rib
Label ribCompteLabel = new Label(workArea,SWT.NONE);
ribCompteLabel.setText("R.I.B");
ribCompteText = new Text(workArea, SWT.BORDER);
ribCompteText.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true,false, 1, 1));
// Champs Agence bancaire
Label agenceCompteLabel = new Label(workArea,SWT.NONE);
agenceCompteLabel.setText("Agence bancaire");
agenceCompteText = new Text(workArea, SWT.BORDER);
agenceCompteText.setLayoutData( new GridData(GridData.FILL, GridData.BEGINNING, true,false, 1, 1));
return parent;
}
@Override
protected Control createButtonBar(Composite parent) {
Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
line.setLayoutData(new GridData (SWT.FILL,SWT.TOP,true,false));
final Composite buttonBar = new Composite(parent, SWT.NONE);
buttonBar.setLayoutData(new GridData (SWT.FILL,SWT.TOP,true,false));
final GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.makeColumnsEqualWidth = false;
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
buttonBar.setLayout(layout);
// Create Add button
// Own method as we need to overview the SelectionAdapter
createOkButton(buttonBar, OK, "Add", true);
// Add a SelectionListener
// Create Cancel button
Button cancelButton =
createButton(buttonBar, CANCEL, "Cancel", false);
// Add a SelectionListener
cancelButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setReturnCode(CANCEL);
close();
}
});
return buttonBar;
}