Java Code Examples for org.eclipse.swt.widgets.Text#addFocusListener()

The following examples show how to use org.eclipse.swt.widgets.Text#addFocusListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: ermasterr   File: ModelPropertiesDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void edit(final TableItem item, final TableEditor tableEditor) {
    final Text text = new Text(table, SWT.NONE);
    text.setText(item.getText(targetColumn));

    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(final FocusEvent e) {
            item.setText(targetColumn, text.getText());
            text.dispose();
        }

    });

    tableEditor.setEditor(text, item, targetColumn);
    text.setFocus();
    text.selectAll();
}
 
Example 2
Source Project: depan   File: RelationDisplayEditor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * In a future world, this might provide access to a complete set
 * of {@code ResourceDocument} properties.
 */
@SuppressWarnings("unused")
private Composite setupProperties(Composite parent) {
  Composite result = Widgets.buildGridContainer(parent, 2);

  Label label = Widgets.buildCompactLabel(result, "&Name:");

  relSetName = new Text(result, SWT.BORDER | SWT.SINGLE);
  relSetName.setLayoutData(Widgets.buildHorzFillData());
  relSetName.addFocusListener(new FocusAdapter() {
    @Override
    public void focusLost(FocusEvent e) {
      if (propInfo.getName().equals(relSetName.getText())) {
        return;
      }
      setDirtyState(true);
      handleDocumentChange();
    }
  });
  return result;
}
 
Example 3
Source Project: depan   File: EdgeMatcherEditor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * In a future world, this might provide access to a complete set
 * of {@code ResourceDocument} properties.
 */
@SuppressWarnings("unused")
private Composite setupProperties(Composite parent) {
  Composite result = Widgets.buildGridContainer(parent, 2);

  Label label = Widgets.buildCompactLabel(result, "&Name:");

  matcherName = new Text(result, SWT.BORDER | SWT.SINGLE);
  matcherName.setLayoutData(Widgets.buildHorzFillData());
  if (null != matcherInfo) {
    matcherName.setText(matcherInfo.getName());
  }
  matcherName.addFocusListener(new FocusAdapter() {
    @Override
    public void focusLost(FocusEvent e) {
      if (matcherInfo.getName().equals(matcherName.getText())) {
        return;
      }
      setDirtyState(true);
      handleDocumentChange();
    }
  });
  return result;
}
 
Example 4
/**
 * In a future world, this might provide access to a complete set
 * of {@code ResourceDocument} properties.
 * @return 
 */
@SuppressWarnings("unused")
private Composite setupProperties(Composite parent) {
  Composite result = Widgets.buildGridContainer(parent, 2);

  Label label = Widgets.buildCompactLabel(result, "&Name:");

  relSetName = new Text(result, SWT.BORDER | SWT.SINGLE);
  relSetName.setLayoutData(Widgets.buildHorzFillData());
  relSetName.addFocusListener(new FocusAdapter() {
    @Override
    public void focusLost(FocusEvent e) {
      if (relSetInfo.getName().equals(relSetName.getText())) {
        return;
      }
      setDirtyState(true);
      handleDocumentChange();
    }
  });
  return result;
}
 
Example 5
Source Project: erflute   File: ModelPropertiesDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void edit(final TableItem item, final TableEditor tableEditor) {
    final Text text = new Text(table, SWT.NONE);
    text.setText(item.getText(targetColumn));

    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            item.setText(targetColumn, text.getText());
            text.dispose();
        }
    });

    tableEditor.setEditor(text, item, targetColumn);
    text.setFocus();
    text.selectAll();
}
 
Example 6
/**
 * 验证用户输入的加权系数的正确性
 * @param equiTxt
 */
private void validEquiTxt(final Text equiTxt){
	final String defaultStr = "0.50";
	equiTxt.setText(defaultStr);
	equiTxt.addFocusListener(new FocusAdapter() {
		@Override
		public void focusLost(FocusEvent e) {
			String textStr = equiTxt.getText().trim();
			if (textStr == null || textStr.trim().length() == 0) {
				equiTxt.setText(defaultStr);
			}else {
				String regular = "1\\.(0){0,2}|0\\.\\d{0,2}";
				if (!textStr.matches(regular)) {
					MessageDialog.openInformation(getShell(), Messages.getString("preference.EquivalentPage.msgTitle"), 
						Messages.getString("preference.EquivalentPage.msg5"));
					equiTxt.setText(defaultStr);
				}
			}
		}
	});
}
 
Example 7
/**
 * 验证用户输入的加权系数的正确性
 * @param equiTxt
 */
private void validEquiTxt(final Text equiTxt){
	final String defaultStr = "0.50";
	equiTxt.setText(defaultStr);
	equiTxt.addFocusListener(new FocusAdapter() {
		@Override
		public void focusLost(FocusEvent e) {
			String textStr = equiTxt.getText().trim();
			if (textStr == null || textStr.trim().length() == 0) {
				equiTxt.setText(defaultStr);
			}else {
				String regular = "1\\.(0){0,2}|0\\.\\d{0,2}";
				if (!textStr.matches(regular)) {
					MessageDialog.openInformation(getShell(), Messages.getString("preference.EquivalentPage.msgTitle"), 
						Messages.getString("preference.EquivalentPage.msg5"));
					equiTxt.setText(defaultStr);
				}
			}
		}
	});
}
 
Example 8
protected void createTextEdit( )
{
	txtValue = new Text( this, iStyle );
	GridData gd = new GridData( GridData.FILL_BOTH );
	txtValue.setLayoutData( gd );
	if ( valueType == TYPE_NUMBERIC )
	{
		txtValue.setToolTipText( Messages.getString( "TextEditorComposite.Tooltip.EnterDecimalOrFractionValue" ) ); //$NON-NLS-1$
	}
	else if ( valueType == TYPE_DATETIME )
	{
		txtValue.setToolTipText( "MM-dd-yyyy HH:mm:ss" ); //$NON-NLS-1$
	}
	txtValue.addModifyListener( this );
	txtValue.addFocusListener( this );
	txtValue.addKeyListener( this );
}
 
Example 9
@Override
protected Control createDialogArea(final Composite parent) {
    text = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.NO_FOCUS);

    // Use the compact margins employed by PopupDialog.
    final GridData gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
    gd.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING;
    gd.verticalIndent = PopupDialog.POPUP_VERTICALSPACING;
    text.setLayoutData(gd);
    text.setText(contents);

    // since SWT.NO_FOCUS is only a hint...
    text.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent event) {
            ContentProposalPopup.this.close();
        }
    });
    return text;
}
 
Example 10
private void edit(final TableItem item, final TableEditor tableEditor) {
	final Text text = new Text(table, SWT.NONE);
	text.setText(item.getText(targetColumn));

	text.addFocusListener(new FocusAdapter() {

		@Override
		public void focusLost(FocusEvent e) {
			item.setText(targetColumn, text.getText());
			text.dispose();
		}

	});

	tableEditor.setEditor(text, item, targetColumn);
	text.setFocus();
	text.selectAll();
}
 
Example 11
public CompositeForCodeTab(final Composite parent, final int style, final Answer answer) {
	super(parent, style);

	// Non-editable text box containing answer value
	final Text txtBoxAnswers = new Text(this, SWT.BORDER);
	txtBoxAnswers.setBounds(5, 5, 210, 25);
	txtBoxAnswers.setEditable(false);
	txtBoxAnswers.setText(answer.getValue());

	// Code dependency text field
	final Text txtValue = new Text(this, SWT.BORDER);
	txtValue.setBounds(220, 5, 200, 25);
	txtValue.setVisible(true);

	final CodeDependency codeDependency = new CodeDependency();

	if (answer.getCodeDependencies() != null) {
		for (final CodeDependency cd : answer.getCodeDependencies()) {
			if (cd.getValue() != null) {
				txtValue.setText(cd.getValue());
				codeDependency.setValue(txtValue.getText());
			}
		}
	}

	txtValue.addFocusListener(new FocusAdapter() {

		@Override
		public void focusLost(final FocusEvent e) {
			codeDependency.setValue(txtValue.getText());
		}
	});

	final ArrayList<CodeDependency> codeDependencies = new ArrayList<CodeDependency>();
	codeDependencies.add(codeDependency);
	answer.setCodeDependencies(codeDependencies);

}
 
Example 12
/**
 * Create the output file name field.
 * @param composite the parent container
 */
private void createOutputDirControl(Composite composite) {
    
    // add label
    Label mainLabel = new Label(composite, SWT.LEFT);
    mainLabel.setText(TexlipsePlugin.getResourceString("projectWizardOutputDirLabel"));
    mainLabel.setToolTipText(TexlipsePlugin.getResourceString("projectWizardOutputDirTooltip"));
    mainLabel.setLayoutData(new GridData());
    
    // add text field
    outputDirNameField = new Text(composite, SWT.SINGLE | SWT.BORDER);
    outputDirNameField.setText(attributes.getOutputDir());
    outputDirNameField.setToolTipText(TexlipsePlugin.getResourceString("projectWizardOutputDirTooltip"));
    outputDirNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    outputDirNameField.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent event) {
            if (outputDirItem != null) {
                dirTree.setSelection(new TreeItem[] { outputDirItem });
            }
        }});
    outputDirNameField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (!outputDirNameField.isDisposed()) {
                String t = outputDirNameField.getText();
                attributes.setOutputDir(t);
                validateDirName(outputDirNameField, t);
                if (t == null || t.length() == 0) {
                    recreateSubTree();
                } else if (outputDirItem == null) {
                    recreateSubTree();
                }
                if (outputDirItem != null) {
                    outputDirItem.setText(t);
                }
            }
        }});
}
 
Example 13
/**
 * Create the output file name field.
 * @param composite the parent container
 */
private void createOutputFileControl(Composite composite) {
    
    // add label
    Label mainLabel = new Label(composite, SWT.LEFT);
    mainLabel.setText(TexlipsePlugin.getResourceString("projectWizardOutputFileLabel"));
    mainLabel.setToolTipText(TexlipsePlugin.getResourceString("projectWizardOutputFileTooltip"));
    mainLabel.setLayoutData(new GridData());
    
    // add text field
    outputFileNameField = new Text(composite, SWT.SINGLE | SWT.BORDER);
    outputFileNameField.setText(attributes.getOutputFile());
    outputFileNameField.setToolTipText(TexlipsePlugin.getResourceString("projectWizardOutputFileTooltip"));
    outputFileNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    outputFileNameField.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent event) {
            dirTree.setSelection(new TreeItem[] { outputFileItem });
        }});
    outputFileNameField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (!outputFileNameField.isDisposed()) {
                String t = outputFileNameField.getText();
                outputFileItem.setText(t);
                validateOutputFileName(t);
            }
        }});
}
 
Example 14
/**
 * Create the output file name field.
 * @param composite the parent container
 */
private void createMainDirControl(Composite composite) {
    
    // add label
    Label mainLabel = new Label(composite, SWT.LEFT);
    mainLabel.setText(TexlipsePlugin.getResourceString("projectWizardMainDirLabel"));
    mainLabel.setToolTipText(TexlipsePlugin.getResourceString("projectWizardMainDirTooltip"));
    mainLabel.setLayoutData(new GridData());
    
    // add text field
    sourceDirNameField = new Text(composite, SWT.SINGLE | SWT.BORDER);
    sourceDirNameField.setText(attributes.getSourceDir());
    sourceDirNameField.setToolTipText(TexlipsePlugin.getResourceString("projectWizardMainDirTooltip"));
    sourceDirNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    sourceDirNameField.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent event) {
        	   if (sourceDirItem != null) {
        	       dirTree.setSelection(new TreeItem[] { sourceDirItem });
        	   }
        }});
    sourceDirNameField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (!sourceDirNameField.isDisposed()) {
                String t = sourceDirNameField.getText();
                attributes.setSourceDir(t);
                validateDirName(sourceDirNameField, t);
                if (t == null || t.length() == 0) {
                    recreateSubTree();
                } else if (sourceDirItem == null) {
                    recreateSubTree();
                }
                if (sourceDirItem != null) {
                    sourceDirItem.setText(t);
                }
            }
        }});
}
 
Example 15
/**
 * Create main file settings box.
 * @param composite the parent container
 */
private void createMainFileControl(Composite composite) {
    
    // add label
    Label mainLabel = new Label(composite, SWT.LEFT);
    mainLabel.setText(TexlipsePlugin.getResourceString("projectWizardMainFileLabel"));
    mainLabel.setToolTipText(TexlipsePlugin.getResourceString("projectWizardMainFileTooltip"));
    mainLabel.setLayoutData(new GridData());
    
    // add text field
    sourceFileNameField = new Text(composite, SWT.SINGLE | SWT.BORDER);
    sourceFileNameField.setText(attributes.getSourceFile());
    sourceFileNameField.setToolTipText(TexlipsePlugin.getResourceString("projectWizardMainFileTooltip"));
    sourceFileNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    sourceFileNameField.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent event) {
            dirTree.setSelection(new TreeItem[] { sourceFileItem });
        }});
    sourceFileNameField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (!sourceFileNameField.isDisposed()) {
                String t = sourceFileNameField.getText();
                sourceFileItem.setText(t);
                tempFileItem.setText(t.substring(0, t.lastIndexOf('.')+1) + "aux");
                validateMainFileName(t);
            }
        }});
}
 
Example 16
/**
 * Create the output file name field.
 * @param composite the parent container
 */
private void createTempDirControl(Composite composite) {
    
    // add label
    Label mainLabel = new Label(composite, SWT.LEFT);
    mainLabel.setText(TexlipsePlugin.getResourceString("projectWizardTempDirLabel"));
    mainLabel.setToolTipText(TexlipsePlugin.getResourceString("projectWizardTempDirTooltip"));
    mainLabel.setLayoutData(new GridData());
    
    // add text field
    tempDirNameField = new Text(composite, SWT.SINGLE | SWT.BORDER);
    tempDirNameField.setText(attributes.getTempDir());
    tempDirNameField.setToolTipText(TexlipsePlugin.getResourceString("projectWizardTempDirTooltip"));
    tempDirNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    tempDirNameField.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent event) {
        	   if (tempDirItem != null) {
                dirTree.setSelection(new TreeItem[] { tempDirItem });
        	   }
        }});
    tempDirNameField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            if (!tempDirNameField.isDisposed()) {
                String t = tempDirNameField.getText();
                attributes.setTempDir(t);
                validateDirName(tempDirNameField, t);
                if (t == null || t.length() == 0) {
                    recreateSubTree();
                } else if (tempDirItem == null) {
                    recreateSubTree();
                }
                if (tempDirItem != null) {
                    tempDirItem.setText(t);
                }
            }
        }});
}
 
Example 17
/**
 * Creates a combo (find, replace).
 */
private Text createText(String preferenceName)
{
	final Text text = new Text(findBar, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
	text.setLayoutData(createdDefaultGridData(SWT.FILL, SWT.FILL, true, true));

	entriesControlHandles.add(findBarEntriesHelper.register(text, modifyListener, preferenceName));

	text.addFocusListener(findBarActions.createFocusListener(text));
	text.addKeyListener(textKeyListner);
	return text;
}
 
Example 18
protected void placeComponents( )
{
	GridLayout gl = new GridLayout( 1, false );
	gl.marginBottom = 0;
	gl.marginHeight = 0;
	gl.marginLeft = 0;
	gl.marginRight = 0;
	gl.marginTop = 0;
	gl.marginWidth = 0;
	this.setLayout( gl );
	if ( sUnit != null )
	{
		gl.numColumns = 2;
	}
	txtValue = new Text( this, iStyle );
	GridData gd = new GridData( GridData.FILL_HORIZONTAL );
	txtValue.setLayoutData( gd );
	txtValue.setToolTipText( Messages.getString( "TextEditorComposite.Tooltip.EnterDecimalOrFractionValue" ) ); //$NON-NLS-1$
	txtValue.addModifyListener( this );
	txtValue.addFocusListener( this );
	txtValue.addKeyListener( this );

	if ( sUnit != null )
	{
		this.lblUnit = new Label( this, SWT.NONE );
		if ( lblUnit != null )
		{
			lblUnit.setText( sUnit );
		}
	}
}
 
Example 19
/**
  * Sets the <code>Text</code> widget that will be managed by this formatter.<p>
  *
  * The ancestor is override to add a key listener on the text widget.
  *
  * @param text Text widget
  * @see ITextFormatter#setText(Text)
  */
public void setText(Text text) {
	super.setText(text);
	text.addKeyListener(klistener);
	text.addFocusListener(flistener);
}