---------
package my.org.eclipse.swt.snippets;
import java.util.Date;
import org.eclipse.jface.dialogs.DialogPage;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.richclientgui.toolbox.validation.IFieldErrorMessageHandler;
import com.richclientgui.toolbox.validation.ValidatingField;
import com.richclientgui.toolbox.validation.ValidationToolkit;
import com.richclientgui.toolbox.validation.converter.DateStringConverter;
import com.richclientgui.toolbox.validation.converter.IntegerStringConverter;
import com.richclientgui.toolbox.validation.string.StringValidationToolkit;
import com.richclientgui.toolbox.validation.validator.IFieldValidator;
import com.richclientgui.toolbox.validation.validator.TelephoneNumberValidator;
public class TestingRCPToolkitValidators extends WizardPage{
private final IFieldErrorMessageHandler errorMessageHandler;
private static final int DECORATOR_POSITION = SWT.TOP | SWT.LEFT;
private static final int DECORATOR_MARGIN_WIDTH = 1;
private static final int DEFAULT_WIDTH_HINT = 150;
private ValidationToolkit
private StringValidationToolkit strValToolkit = null;
private ValidationToolkit
public TestingRCPToolkitValidators() {
super("booking.pageone","New Booking Entry", null);
errorMessageHandler = new WizardPageErrorHandler();
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(2, false));
createControl(shell);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
class WizardPageErrorHandler implements IFieldErrorMessageHandler {
public void handleErrorMessage(String message, String input) {
setMessage(null, DialogPage.WARNING);
setErrorMessage(message);
}
public void handleWarningMessage(String message, String input) {
setErrorMessage(null);
setMessage(message, DialogPage.WARNING);
}
public void clearMessage() {
setErrorMessage(null);
setMessage(null, DialogPage.WARNING);
}
}
public static void main(String[] args) {
new TestingRCPToolkitValidators();
}
@Override
public void createControl(Composite shell) {
strValToolkit = new StringValidationToolkit(DECORATOR_POSITION, DECORATOR_MARGIN_WIDTH, true);
strValToolkit.setDefaultErrorMessageHandler(errorMessageHandler);
intValToolkit = new ValidationToolkit
intValToolkit.setDefaultErrorMessageHandler(errorMessageHandler);
dateValToolkit = new ValidationToolkit
dateValToolkit.setDefaultErrorMessageHandler(errorMessageHandler);
// TODO Auto-generated method stub
//GridData gridData;
createNameField(shell);
//createAddressField(shell);
//createSportsListWidget(shell);
createTelephoneNumberField(shell);
}
private void createSportsListWidget(Composite shell) {
GridData gridData;
Label sportsLabel = new Label(shell, SWT.NONE);
sportsLabel.setText("Sports played:");
gridData = new GridData();
gridData.horizontalSpan = 2;
sportsLabel.setLayoutData(gridData);
List sportsList = new List(shell, SWT.BORDER | SWT.MULTI);
gridData = new GridData();
gridData.horizontalSpan = 2;
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
sportsList.setLayoutData(gridData);
sportsList.add("Hockey");
sportsList.add("Street Hockey");
}
private void createAddressField(Composite shell) {
GridData gridData;
Label addressLabel = new Label(shell, SWT.NONE);
addressLabel.setText("Address:");
gridData = new GridData();
gridData.verticalAlignment = SWT.TOP;
addressLabel.setLayoutData(gridData);
Text addressText = new Text(shell, SWT.BORDER | SWT.WRAP | SWT.MULTI);
gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
addressText.setLayoutData(gridData);
addressText.setText("This text field and the List\nbelow share any excess space.");
}
private void createNameField(Composite shell) {
// Label nameLabel = new Label(shell, SWT.NONE);
// nameLabel.setText("Name:");
//
// Text nameText = new Text(shell, SWT.BORDER);
// GridData gridData = new GridData();
// gridData.horizontalAlignment = SWT.FILL;
// gridData.grabExcessHorizontalSpace = true;
// nameText.setLayoutData(gridData);
// nameText.setText("Text grows horizontally");
new Label(shell, SWT.NONE).setText("Name:");
final ValidatingField
public String getErrorMessage() {
return "Name may not be empty.";
}
public String getWarningMessage() {
return "That's a very short name...";
}
public boolean isValid(String contents) {
return !(contents.length()==0);
}
public boolean warningExist(String contents) {
return contents.length() < 3;
}
}, true, "");
GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
gd.widthHint = DEFAULT_WIDTH_HINT;
nameField.getControl().setLayoutData(gd);
}
private void createTelephoneNumberField(Composite shell) {
// Label nameLabel = new Label(shell, SWT.NONE);
// nameLabel.setText("Telephone #:");
//
// Text nameText = new Text(shell, SWT.BORDER);
// GridData gridData = new GridData();
// gridData.horizontalAlignment = SWT.FILL;
// gridData.grabExcessHorizontalSpace = true;
// nameText.setLayoutData(gridData);
new Label(shell, SWT.NONE).setText("Contact Telephone Nr:");
final ValidatingField
shell,
new TelephoneNumberValidator(true),
true,
"+44 (55) 555-4321");
GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
gd.widthHint = DEFAULT_WIDTH_HINT;
telephoneField.getControl().setLayoutData(gd);
}
}
---------
This is very good content you share on this blog. it's very informative and provide me future related information.
ReplyDeletepython Training in Pune
python Training in Chennai
python Training in Bangalore
Thanks you for sharing this unique useful information content with us. Really awesome work. keep on blogging
ReplyDeleteData Science Course in Indira nagar
Data Science Course in btm layout
Data Science course in Indira nagar
Data Science Course in Marathahalli
Data Science Course in BTM Layout
Data science course in bangalore