org.eclipse.swt.widgets.Text#addVerifyListener ( )源码实例Demo

下面列出了org.eclipse.swt.widgets.Text#addVerifyListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void createControl(UI_POSITION position, Composite parent) {
  // We add controls only to the BOTTOM position.
  if (position == UI_POSITION.BOTTOM) {
    portLabel = new Label(parent, SWT.NONE);
    portLabel.setVisible(false);
    portLabel.setText(Messages.getString("NEW_SERVER_DIALOG_PORT"));

    portText = new Text(parent, SWT.SINGLE | SWT.BORDER);
    portText.setVisible(false);
    portText.setText(String.valueOf(LocalAppEngineServerBehaviour.DEFAULT_SERVER_PORT));
    portText.addVerifyListener(new PortChangeMonitor());
    portText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    FieldDecorationRegistry registry = FieldDecorationRegistry.getDefault();
    Image errorImage = registry.getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();

    portDecoration = new ControlDecoration(portText, SWT.LEFT | SWT.TOP);
    portDecoration.setDescriptionText(Messages.getString("NEW_SERVER_DIALOG_INVALID_PORT_VALUE"));
    portDecoration.setImage(errorImage);
    portDecoration.hide();
  }
}
 
private void createPackageField(Composite parent) {
  Label packageNameLabel = new Label(parent, SWT.LEAD);
  packageNameLabel.setText(Messages.getString("java.package")); //$NON-NLS-1$
  javaPackageField = new Text(parent, SWT.BORDER);
  javaPackageField.addModifyListener(event -> revalidate());
  javaPackageField.addVerifyListener(event -> {
    // if the user ever changes the package name field, then we never auto-generate again.
    if (!javaPackageProgrammaticUpdate) {
      autoGeneratePackageName = false;
    }
  });
}
 
/**
 * Creates the controls for the type name field. Expects a <code>GridLayout</code> with at
 * least 2 columns.
 *
 * @param composite the parent composite
 * @param nColumns number of columns to span
 */
protected void createTypeNameControls(Composite composite, int nColumns) {
	fTypeNameDialogField.doFillIntoGrid(composite, nColumns - 1);
	DialogField.createEmptySpace(composite);

	Text text= fTypeNameDialogField.getTextControl(null);
	LayoutUtil.setWidthHint(text, getMaxFieldWidth());
	TextFieldNavigationHandler.install(text);
	
	text.addVerifyListener(new VerifyListener() {
		public void verifyText(VerifyEvent e) {
			if (fCanModifyPackage && ! fEnclosingTypeSelection.isSelected() && e.start == 0 && e.end == ((Text) e.widget).getCharCount()) {
				String typeNameWithoutParameters= getTypeNameWithoutParameters(e.text);
				int lastDot= typeNameWithoutParameters.lastIndexOf('.');
				if (lastDot == -1 || lastDot == typeNameWithoutParameters.length() - 1)
					return;
				
				String pack= typeNameWithoutParameters.substring(0, lastDot);
				if (validatePackageName(pack, null).getSeverity() == IStatus.ERROR)
					return;
				
				fPackageDialogField.setText(pack);
				e.text= e.text.substring(lastDot + 1);
			}
		}
	});
}
 
源代码4 项目: birt   文件: DimensionBuilderDialog.java
/**
 * @param composite
 */
private void createMeasureField(Composite composite) {
	new Label(composite, SWT.NONE).setText(LABEL_MEASURE);

	measure = new Text(composite, SWT.SINGLE | SWT.BORDER);
	GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
	gridData.horizontalSpan = 2;
	measure.setLayoutData(gridData);
	measure.setFont(composite.getFont());
	if ( measureData != null && !measureData.equals( "" ) ) //$NON-NLS-1$
	{
		measure.setText( NumberUtil.double2LocaleNum( ( (Double) measureData ).doubleValue( ) ) );
	}
	measure.addVerifyListener(new VerifyListener(){

		public void verifyText(VerifyEvent e) {
			// TODO Auto-generated method stub
			boolean doit = false;
			
			char eChar = e.character;System.out.print(eChar + 0);
			String validChars = "0123456789,.\b"; //$NON-NLS-1$
			if(e.keyCode == SWT.DEL || validChars.indexOf(eChar) >= 0)
			{					
				doit = true;
			}
			e.doit = doit;
		}});

}
 
源代码5 项目: birt   文件: FolderSelectionGroup.java
/**
 * Create group
 * 
 * @param parent
 */
public void create( Composite parent )
{
	// get font
	Font font = parent.getFont( );

	// label control
	Label label = new Label( parent, SWT.LEFT );
	label.setFont( font );
	label.setText( this.labelText );

	Composite composite = new Composite( parent, SWT.NULL );
	GridLayout layout = new GridLayout( );
	layout.marginWidth = 0;
	layout.marginHeight = 0;
	layout.numColumns = 2;
	composite.setLayout( layout );

	GridData data = new GridData( GridData.FILL_HORIZONTAL );
	composite.setLayoutData( data );

	// text control
	text = new Text( composite, SWT.BORDER );
	text.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
	text.setFont( font );
	text.setText( this.textValue );
	text.addVerifyListener( new VerifyListener( ) {

		public void verifyText( VerifyEvent e )
		{
			e.doit = e.text.indexOf( DELIMITER ) < 0;
		}
	} );

	// directory selection button
	button = new Button( composite, SWT.PUSH );
	button.setFont( font );
	button.setText( this.buttonText );
	button.addSelectionListener( new SelectionAdapter( ) {

		public void widgetSelected( SelectionEvent event )
		{
			dialog = new DirectoryDialog( PlatformUI.getWorkbench( )
					.getDisplay( ).getActiveShell( ) );

			dialog.setText( dialogTitle );
			dialog.setMessage( dialogMessage );
			dialog.setFilterPath( dialogFilterPath );
			String folderName = dialog.open( );
			if ( folderName == null )
			{
				return;
			}
			text.setText( folderName );
		}
	} );
}
 
源代码6 项目: birt   文件: FolderSelectionGroup.java
/**
 * Create group
 * 
 * @param parent
 */
public void create( Composite parent )
{
	// get font
	Font font = parent.getFont( );

	// label control
	Label label = new Label( parent, SWT.LEFT );
	label.setFont( font );
	label.setText( this.labelText );

	Composite composite = new Composite( parent, SWT.NULL );
	GridLayout layout = new GridLayout( );
	layout.marginWidth = 0;
	layout.marginHeight = 0;
	layout.numColumns = 2;
	composite.setLayout( layout );

	GridData data = new GridData( GridData.FILL_HORIZONTAL );
	composite.setLayoutData( data );

	// text control
	text = new Text( composite, SWT.BORDER );
	text.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
	text.setFont( font );
	text.setText( this.textValue );
	text.addVerifyListener( new VerifyListener( ) {

		public void verifyText( VerifyEvent e )
		{
			e.doit = e.text.indexOf( DELIMITER ) < 0;
		}
	} );

	// directory selection button
	button = new Button( composite, SWT.PUSH );
	button.setFont( font );
	button.setText( this.buttonText );
	button.addSelectionListener( new SelectionAdapter( ) {

		public void widgetSelected( SelectionEvent event )
		{
			dialog = new DirectoryDialog( PlatformUI.getWorkbench( )
					.getDisplay( ).getActiveShell( ) );

			dialog.setText( dialogTitle );
			dialog.setMessage( dialogMessage );
			dialog.setFilterPath( dialogFilterPath );
			String folderName = dialog.open( );
			if ( folderName == null )
			{
				return;
			}
			text.setText( folderName );
		}
	} );
}
 
源代码7 项目: uima-uimaj   文件: ExportImportablePartDialog.java
@Override
protected Control createDialogArea(Composite parent) {

  Composite composite = (Composite) super.createDialogArea(parent);
  AbstractSection.spacer(composite);

  createWideLabel(composite, "Base file name (without path or following \".xml\":");

  baseFileNameUI = new Text(composite, SWT.BORDER);
  baseFileNameUI.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  baseFileNameUI.addModifyListener(m_dialogModifyListener);
  baseFileNameUI.addVerifyListener(new DialogVerifyListener());
  baseFileName = "";

  newErrorMessage(composite);

  createWideLabel(composite, "Where the generated part descriptor file will be stored:");
  genFilePathUI = new Text(composite, SWT.BORDER | SWT.H_SCROLL);
  genFilePathUI.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
  genFilePathUI.setText(rootPath + ".xml");

  new Label(composite, SWT.NONE).setText("");
  importByNameUI = new Button(composite, SWT.RADIO);
  importByNameUI.setText("Import by Name");
  importByNameUI
          .setToolTipText("Importing by name looks up the name on the classpath and datapath.");

  importByLocationUI = new Button(composite, SWT.RADIO);
  importByLocationUI.setText("Import By Location");
  importByLocationUI.setToolTipText("Importing by location requires a relative or absolute URL");

  String defaultBy = CDEpropertyPage.getImportByDefault(editor.getProject());
  if (defaultBy.equals("location")) {
    importByNameUI.setSelection(false);
    importByLocationUI.setSelection(true);
  } else {
    importByNameUI.setSelection(true);
    importByLocationUI.setSelection(false);
  }

  baseFileNameUI.setFocus();
  return composite;
}
 
源代码8 项目: eclipse-cs   文件: SWTUtil.java
/**
 * Adds a verifier to the given text control which allows only digits to be entered.
 *
 * @param text
 *          the text control
 */
public static void addOnlyDigitInputSupport(Text text) {
  text.addVerifyListener(new OnlyDigitsVerifyListener());
}