JFace -SWT How to make TitleAreaDialog similaire to Eclipse one - java

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;
}

Related

How to display a composite on the top of another composite which contains a table viewer?

In the createControl(parent) method of the Wizard Page, the code is as below-
top = new Composite(parent, SWT.NONE);
top.setLayout(new FillLayout());
setControl(top);
setPageComplete(false);
createViewer(top);
I want to add a row above the composite denoted by top.
It doesn't allows me. If I add it, the composite denoted by top gets lost.
The below is rendered for the top composite -
The moment I place the below code before the top composite, the top composite gets lost -
upper = new Composite(parent, SWT.NONE);
upper.setLayout(new FillLayout());
setControl(upper);
Label label = new Label(page, SWT.NONE);
label.setText("Some text to disply");
Please suggest on how to achieve the same.
The below is the createControl snippet in my case. It breaks the scrolling and size of the table viewer if add a row.
#Override
public void createControl(Composite parent) {
/*top = new Composite(parent, SWT.NONE);
top.setLayout(new FillLayout());
setControl(top);*/
setPageComplete(false);
top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
setControl(top);
Label label = new Label(top, SWT.NONE);
label.setText("Some text to disply");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
createViewer(top);
}
private void createViewer(Composite parent) {
tableLayout = new TableColumnLayout();
// A separate composite containing just the table viewer is required
Composite tableComp = new Composite(parent, SWT.NONE);
tableComp.setLayout(tableLayout);
viewer = new TableViewer(tableComp, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
createColumns(parent, viewer);
final Table table = viewer.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
viewer.setContentProvider(new ArrayContentProvider());
// Layout the viewer
GridData gridData = new GridData();
gridData.verticalAlignment = GridData.FILL;
gridData.horizontalSpan = 2;
gridData.grabExcessHorizontalSpace = true;
gridData.grabExcessVerticalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
viewer.getControl().setLayoutData(gridData);
}
public TableViewer getViewer() {
return viewer;
}
// This will create the columns for the table
private void createColumns(final Composite parent, final TableViewer viewer) {
String[] titles = { "Node Status", "Node Type", "Node Name" };
int[] bounds = { 100, 100, 100 };
Image HEADER = CommonUtility.HEADER;
TableViewerColumn col = null;
// First column is for type
col = createTableViewerColumn(HEADER, titles[0], bounds[0], 0);
col.setLabelProvider(new CentredImageCellLabelProvider() {
#Override
public Image getImage(Object element) {
GenerateSkeletonComponentsStatusModel model = (GenerateSkeletonComponentsStatusModel) element;
if (model.isNew()) {
return CommonUtility.CHECKED;
} else {
return CommonUtility.UNCHECKED;
}
}
});
// Weight for column
tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(50));
// now the newly created
col = createTableViewerColumn(HEADER, titles[1], bounds[1], 1);
col.setLabelProvider(new CentredImageCellLabelProvider() {
#Override
public Image getImage(Object element) {
GenerateSkeletonComponentsStatusModel model = (GenerateSkeletonComponentsStatusModel) element;
if ("ns_flow".equals(model.getIcon())) {
return CommonUtility.FLOW_SERVICE;
}
if ("ns_open_interface".equals(model.getIcon())) {
return CommonUtility.FOLDER;
}
if ("ns_record".equals(model.getIcon())) {
return CommonUtility.DOCUMENT_TYPE;
}
if ("ns_package".equals(model.getIcon())) {
return CommonUtility.PACKAGE;
}
if("RestResource".equals(model.getIcon())){
return CommonUtility.RESTFUL_FOLDER;
}
return null;
}
});
// Weight for column
tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(50));
// First column is for the component name
col = createTableViewerColumn(HEADER, titles[2], bounds[2], 2);
col.setLabelProvider(new ColumnLabelProvider() {
#Override
public String getText(Object element) {
GenerateSkeletonComponentsStatusModel model = (GenerateSkeletonComponentsStatusModel) element;
return model.getComponentName();
}
});
// Weight for column
tableLayout.setColumnData(col.getColumn(), new ColumnWeightData(100));
}
private TableViewerColumn createTableViewerColumn(Image image, String title, int bound, final int colNumber) {
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.LEAD);
final TableColumn column = viewerColumn.getColumn();
column.setImage(image);
column.setText(title);
column.setWidth(bound);
column.setResizable(true);
column.setMoveable(true);
column.setAlignment(SWT.CENTER);
return viewerColumn;
}
A wizard page must only have one top level composite. You can add multiple controls (including nested composites) to that composite.
So for a label above to table:
top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
setControl(top);
Label label = new Label(top, SWT.NONE);
label.setText("Some text to disply");
label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
TableViewer viewer = new TableViewer(top, .... flags
viewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

ScrolledComposite rendering incorrectly when adding a large amount of content

When trying to add a lot of labels on to a Composite that is contained in a ScrolledComposite after a certain number (1638) for me, it just seems to give up and stop drawing the components after it. Is this a hard limit on a number of things that can be displayed or something I'm doing wrong.
This also happens if I just add one label with 2000 lines of text in.
public class LoadsOfLabelsTestDialog extends Dialog
{
List<Label> displaylabels = new ArrayList<>();
Composite content, list;
ScrolledComposite scroll;
public LoadsOfLabelsTestDialog(Shell parentShell)
{
super(parentShell);
}
#Override
protected void configureShell(Shell shell)
{
super.configureShell(shell);
shell.setSize(new Point(700, 500));
shell.setText("FML"); //$NON-NLS-1$
}
#Override
public Control createDialogArea(final Composite comp)
{
content = (Composite) super.createDialogArea(comp);
content.setLayout(new GridLayout(1, false));
content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Button set1 = new Button(content, SWT.PUSH);
set1.setText("Display List 1");
set1.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
List<String> rows = new ArrayList<>();
for (int i = 0; i < 2000; i++) {
rows.add(i +" row");
}
updateList(rows);
}
});
scroll = new ScrolledComposite(content, SWT.V_SCROLL);
list = new Composite(scroll, SWT.NONE);
list.setLayout(new GridLayout(1, true));
scroll.setContent(list);
scroll.setExpandHorizontal(true);
scroll.setExpandVertical(true);
scroll.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
new Label(content, SWT.HORIZONTAL | SWT.SEPARATOR);
setScrollSize();
return content;
}
private void setScrollSize() {
scroll.setMinSize(list.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
private void updateList(List<String> rows) {
if (this.displaylabels == null) {
this.displaylabels = new ArrayList<>();
}
for (Label l : displaylabels) {
l.dispose();
}
this.displaylabels.clear();
for (String item : rows) {
addListLabel(item);
}
content.layout(true, true);
setScrollSize();
}
private void addListLabel(String whoText) {
Label a = new Label(list, SWT.NONE);
a.setText(whoText);
this.displaylabels.add(a);
}
public static void main(String[] args)
{
Display d = new Display();
Shell s = new Shell();
LoadsOfLabelsTestDialog fml = new LoadsOfLabelsTestDialog(s);
fml.open();
}
}
You hit a hard limit, probably the maximum size of a control. While this limit may differ slightly on other platforms, you can't size a control arbitrarily.
As #greg-449 suggested, prefer using a Table. If the content per table row is more than just an image and text, you can add a paint listener to draw the row contents yourself.

Can't update label inside keyPressed()

I just started to learn Java. I have already looked Swing and at the moment I'm trying to do something with SWT.
But I have the next problem. Key Listener that I added for Text field is working, but inside this listener I can't change for example my label.
I have seen a few demos they worked, but I don't see any differences.
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class FirstClass {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("First Application");
GridLayout layout = new GridLayout(2, false);
shell.setLayout(layout);
Text word = new Text(shell,SWT.SINGLE | SWT.BORDER | SWT.FILL);
GridData wordGrDt = new GridData();
wordGrDt.heightHint = 130;
wordGrDt.minimumHeight = 130;
wordGrDt.horizontalAlignment = SWT.FILL;
wordGrDt.verticalAlignment = SWT.FILL;
wordGrDt.horizontalSpan = 2;
word.setLayoutData(wordGrDt);
GridData statusGrDt = new GridData();
statusGrDt.grabExcessHorizontalSpace = true;
statusGrDt.horizontalSpan = 1;
statusGrDt.horizontalAlignment = SWT.LEFT_TO_RIGHT;
Label status = new Label(shell, SWT.PUSH);
status.setEnabled(true);
status.setText("");
status.setLayoutData(statusGrDt);
GridData checkGrDt = new GridData();
checkGrDt.widthHint = 150;
checkGrDt.horizontalSpan = 1;
checkGrDt.horizontalAlignment = SWT.RIGHT_TO_LEFT;
Button check = new Button(shell, SWT.PUSH);
check.setText("Check");
check.setLayoutData(checkGrDt);
word.addKeyListener(new org.eclipse.swt.events.KeyAdapter() {
public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
if (e.keyCode == SWT.CR) {
System.out.println("worked!!!");
status.setText("ababahalamaha");
}
}
});
shell.setMinimumSize(400, 300);
shell.open();
shell.pack();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Add a layout() call to the parent of the Label:
word.addKeyListener(new org.eclipse.swt.events.KeyAdapter() {
public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
if (e.keyCode == SWT.CR) {
System.out.println("worked!!!");
status.setText("ababahalamaha");
status.getParent().layout();
}
}
});
The label originally has a width of 0, as it doesn't contain any text. When you add content, the parent has to know to re-layout its children.
As a note:
Please check which style you use with which widget. A Label does not know what to do with the style SWT.PUSH for example.

TabItem does not refresh when list of tabItem has changed in SWT

Below is my code, When button press I am changing the item1 list by using item1.setcontrol depends on my condition.
Composite is not refreshing, But when I click on Item2 tab and come back to Item1 tab... List is updated depends on condition.
Please let me know How to refresh the layout with out moving to other Tab item.
final Composite RightComposite = new Composite(paComposite, SWT.NONE);
RightComposite.setLayout(new GridLayout(1, false));
RightComposite.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, true));
Composite findComposite = new Composite(RightComposite, SWT.NONE);
findComposite.setLayout(new GridLayout(2, true));
findComposite.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, false));
txt = new Text(findComposite, SWT.BORDER | SWT.WRAP | SWT.SINGLE);
txt.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, false));
txt.addListener(SWT.Verify, new Listener()
{
#Override
public void handleEvent(final Event e)
{
newString = ((Text) e.widget).getText();
}
});
btn = new Button(findTCComposite, SWT.NONE);
btn.setLayoutData(new GridData(SWT.BEGINNING, GridData.BEGINNING, false, false));
btn.setText("Find button");
final TabFolder tabFolder = new TabFolder(RightComposite, SWT.NONE);
tabFolder.setLayoutData(new GridData(SWT.FILL, GridData.FILL, true, true));
final TabItem item1 = new TabItem(tabFolder, SWT.NONE);
item1.setText("Tab 1 ");
btn.addListener (SWT.Selection, new Listener()
{
public void handleEvent(Event e) {
if(!newString.isEmpty()){
item1.setControl(list1);
}
else
{
item1.setControl(list);
}
}
});
TabItem item2 = new TabItem(tabFolder, SWT.NONE);
Item2.setText("Tab 2");
RightComposite.layout();
Your problem is in the SWT's TabItem class, in the setControl() function. At the end of this function it makes an: oldControl.setVisible (false);
So in your situation the oldControl will be the same control you set (it you set it twice) and it will be hidden. To solve the problem you can modify the code as:
btn.addListener (SWT.Selection, new Listener() {
public void handleEvent(Event e) {
if (!newString.isEmpty()) {
item1.setControl(list1);
list1.setVisible(true);
} else {
item1.setControl(list);
list.setVisible(true);
}
}
});
Or another approach:
btn.addListener (SWT.Selection, new Listener() {
public void handleEvent(Event e) {
if (newString != null && !newString.isEmpty()) {
if (item1.getControl() != list1) {
item1.setControl(list1);
}
} else {
if (item1.getControl() != list) {
item1.setControl(list);
}
}
}
});
I hope this fits your needs.

How to validate a Text with Jface Dialog?

i created a Dialog with two input fields with the following Code.
public class CCIDDialog extends TitleAreaDialog {
private Text ccidText;
private Text descriptionText;
private String CCID;
private String description;
public CCIDDialog(Shell parentShell) {
super(parentShell);
}
public void create() {
super.create();
setTitle(_title);
setMessage("Bitte geben Sie die CCID "+firstchar+"xxxxxxx und eine Beschreibung ein (max. 7-stellig): ", IMessageProvider.INFORMATION); }
#Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
Composite container = new Composite(area, SWT.NONE);
container.setLayoutData(new GridData(GridData.FILL_BOTH));
GridLayout layout = new GridLayout(2, false);
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
container.setLayout(layout);
createCCID(container);
createDescription(container);
return area;
}
private void createCCID(Composite container) {
Label lbtFirstName = new Label(container, SWT.NONE);
lbtFirstName.setText("CCID (ohne "+firstchar+"): ");
GridData dataCCID = new GridData();
dataCCID.grabExcessHorizontalSpace = true;
dataCCID.horizontalAlignment = GridData.FILL;
ccidText = new Text(container, SWT.BORDER);
ccidText.setLayoutData(dataCCID);
}
private void createDescription(Composite container) {
Label lbtLastName = new Label(container, SWT.NONE);
lbtLastName.setText("Beschreibung: ");
GridData dataDescription = new GridData();
dataDescription.grabExcessHorizontalSpace = true;
dataDescription.horizontalAlignment = GridData.FILL;
descriptionText = new Text(container, SWT.BORDER);
descriptionText.setLayoutData(dataDescription);
}
#Override
protected boolean isResizable() {
return true;
}
// save content of the Text fields because they get disposed
// as soon as the Dialog closes
private void saveInput() {
CCID = ccidText.getText();
description = descriptionText.getText();
}
#Override
protected void okPressed() {
saveInput();
super.okPressed();
}
public String getCCID() {
return CCID;
}
public String getDescription() {
return description;
}
}
Is there a way to validate the ccidtext?
If the user type more then 7 chars, he must get a notification and should not be able to continue the dialog. I read so lot at the internet but can`t find a solution for this problem.
Thank u so much for your help.
JonasInt
You can use Text.addModifyListener to add a ModifyListener which will be called each time the text is changed. You can also use Text.addVerifyListener to add VerifyListener which can actually prevent text being entered.
For TitleAreaDialog you can call setMessage or setErrorMessage to display a message in the title area.
You can disable the OK button on the dialog using:
getButton(IDialogConstants.OK_ID).setEnabled(false);
Note: getButton(xxx) can return null if you call it too early in the dialog construction. Buttons are created during the createContents method after the createDialogArea method has been called.
So you can access the buttons by overriding createContents like this:
#Override
protected Control createContents(final Composite parent)
{
Control control = super.createContents(parent);
// TODO access buttons here
return control;
}

Categories