下面列出了org.eclipse.swt.widgets.Text#getText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static final SelectionAdapter getSelectionAdapter( final Shell shell, final Text destination ) {
// Listen to the Browse... button
return new SelectionAdapter() {
public void widgetSelected( SelectionEvent e ) {
DirectoryDialog dialog = new DirectoryDialog( shell, SWT.OPEN );
if ( destination.getText() != null ) {
String fpath = destination.getText();
// String fpath = StringUtil.environmentSubstitute(destination.getText());
dialog.setFilterPath( fpath );
}
if ( dialog.open() != null ) {
String str = dialog.getFilterPath();
destination.setText( str );
}
}
};
}
private void handleModifierModified(Text source) {
int i = fHoverTable.getSelectionIndex();
PyEditorTextHoverDescriptor hover = null;
Text editor = source;
if (source == fCombiningHoverModifierEditor) {
hover = PydevPlugin.getCombiningHoverDescriptor();
} else {
if (i < 0) {
return;
}
hover = fHoverDescs[i];
}
String modifiers = editor.getText();
hover.fModifierString = modifiers;
hover.fStateMask = PyEditorTextHoverDescriptor.computeStateMask(modifiers);
// update table
if (!fHoverTableViewer.isCellEditorActive() && i >= 0) {
fHoverTableViewer.refresh(fHoverDescs[i]);
}
updateStatus(hover);
}
/**
* Save the checked entries' ID in the view context before changing trace and
* check them again in the new tree.
*/
private void saveViewContext() {
ITmfTrace previousTrace = getTrace();
if (previousTrace != null) {
Object[] checkedElements = fCheckboxTree.getCheckedElements();
Set<Long> ids = new HashSet<>();
for (Object checkedElement : checkedElements) {
if (checkedElement instanceof TmfGenericTreeEntry) {
ids.add(((TmfGenericTreeEntry) checkedElement).getModel().getId());
}
}
Text filterControl = fCheckboxTree.getFilterControl();
String filterString = filterControl != null ? filterControl.getText() : null;
TmfTraceManager.getInstance().updateTraceContext(previousTrace,
builder -> builder.setData(getDataContextId(CHECKED_ELEMENTS), ids)
.setData(getDataContextId(FILTER_STRING), filterString));
}
}
protected void textChanged( Text textControl )
{
Key key = (Key) textControl.getData( );
String path = textControl.getText( );
if ( path != null && textControl == resourceText )
{
if ( path.startsWith( DEFAULT_RESOURCE_FOLDER_DISPLAY ) )
{
path = path.replaceFirst( DEFAULT_RESOURCE_FOLDER_DISPLAY,
PREF_RESOURCE.getDefaultValue( fPref ) );
}
}
String oldValue = setValue( key, path );
validateSettings( key, oldValue, path );
}
private static boolean isTextEmpty( Text text )
{
String s = text.getText( );
if ( ( s != null ) && ( s.trim( ).length( ) > 0 ) )
return false;
return true;
}
@Override
protected void okPressed(){
StringBuilder sb = new StringBuilder();
for (Text text : inputs) {
String varname = (String) text.getData("varname");
String varcontents = text.getText();
sb.append(varname).append("=").append(varcontents).append(",");
}
sb.deleteCharAt(sb.length() - 1);
result = sb.toString();
super.okPressed();
}
public InfoFilter() {
super();
//We have to get the actual text from the control, because the
Text pattern = (Text) getPatternControl();
String stringPattern = ""; //$NON-NLS-1$
if (pattern != null && !pattern.getText().equals("*")) { //$NON-NLS-1$
stringPattern = pattern.getText();
}
this.initialPattern = stringPattern;
}
private void setStringValue(Object bean, String property, Text text) {
log.trace("Change value {} @ {}", property, bean);
String val = text.getText();
try {
Bean.setValue(bean, property, val);
} catch (Exception e) {
error("Cannot set bean value", e);
}
}
private void handleEnterPressed(Composite parent, Composite labels, Text filterText) {
String currentRegex = filterText.getText();
if (currentRegex.isEmpty() || fFilterRegexes.size() == MAX_FILTER_REGEX_SIZE || fFilterRegexes.contains(currentRegex)) {
filterText.setBackground(fColorScheme.getColor(TimeGraphColorScheme.TOOL_BACKGROUND));
return;
}
boolean added = fFilterRegexes.add(currentRegex);
if (added) {
filterText.setText(EMPTY_STRING);
fRegex = EMPTY_STRING;
createCLabels(parent, labels, currentRegex);
}
}
protected void createNameLabel(Composite labelComposite) {
nameLabel = new Text(labelComposite, SWT.SINGLE | SWT.NORMAL);
GridDataFactory.fillDefaults().indent(5, 1).grab(true, false).align(SWT.FILL, SWT.CENTER).applyTo(nameLabel);
Optional<String> name = getStatechartName();
if (name.isPresent()) {
nameLabel.setText(name.get());
}
nameLabel.setEditable(isStatechart());
nameLabel.setBackground(ColorConstants.white);
nameModificationListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
Optional<Statechart> sct = getStatechart();
if (sct.isPresent()) {
if (Objects.equals(sct.get().getName(), nameLabel.getText())) {
return;
}
getSash().setRedraw(false);
TransactionalEditingDomain domain = getTransactionalEditingDomain();
SetCommand command = new SetCommand(domain, sct.get(),
BasePackage.Literals.NAMED_ELEMENT__NAME, nameLabel.getText());
domain.getCommandStack().execute(command);
refresh(nameLabel.getParent());
getSash().setRedraw(true);
}
}
};
nameLabel.addModifyListener(nameModificationListener);
}
public static String getTextValue(final Text txt, final String defVal) {
if ((txt == null) || (txt.isDisposed())) {
return defVal;
}
return (txt.getText());
}
public static final void checkPasswordVisible( Text wPassword ) {
String password = wPassword.getText();
java.util.List<String> list = new ArrayList<String>();
StringUtil.getUsedVariables( password, list, true );
// ONLY show the variable in clear text if there is ONE variable used
// Also, it has to be the only string in the field.
//
if ( list.size() != 1 ) {
wPassword.setEchoChar( '*' );
} else {
String variableName = null;
if ( ( password.startsWith( StringUtil.UNIX_OPEN ) && password.endsWith( StringUtil.UNIX_CLOSE ) ) ) {
// ${VAR}
// 012345
//
variableName =
password.substring( StringUtil.UNIX_OPEN.length(), password.length() - StringUtil.UNIX_CLOSE.length() );
}
if ( ( password.startsWith( StringUtil.WINDOWS_OPEN ) && password.endsWith( StringUtil.WINDOWS_CLOSE ) ) ) {
// %VAR%
// 01234
//
variableName =
password.substring( StringUtil.WINDOWS_OPEN.length(), password.length()
- StringUtil.WINDOWS_CLOSE.length() );
}
// If there is a variable name in there AND if it's defined in the system properties...
// Otherwise, we'll leave it alone.
//
if ( variableName != null && System.getProperty( variableName ) != null ) {
wPassword.setEchoChar( '\0' ); // Show it all...
} else {
wPassword.setEchoChar( '*' );
}
}
}
void inputNewline(Text text)
{
StringBuilder sb = new StringBuilder(text.getText());
Point selection = text.getSelection();
String delimiter = Text.DELIMITER;
sb.replace(selection.x, selection.y, delimiter);
text.setText(sb.toString());
text.setSelection(selection.x + delimiter.length());
}
protected Integer getIntegerValue(Text text) {
final String value = text.getText();
if (Check.isEmpty(value)) {
return null;
}
try {
return Integer.valueOf(value.trim());
} catch (final NumberFormatException e) {
return null;
}
}
protected void numberFieldChanged(Text textControl) {
String number = textControl.getText();
IStatus status = validatePositiveNumber(number);
if (!status.matches(IStatus.ERROR)) {
fOverlayStore.setValue(fTextFields.get(textControl), number);
}
updateStatus(status);
}
public static String getTextValue( Text aText )
{
String tempText = aText.getText();
if ( "".equals( tempText ) )
{
return null;
}
else
{
return tempText;
}
}
public ODBCBasedImporter(final Composite parent, final ImporterPage home){
super(parent, SWT.NONE);
setLayout(new GridLayout());
final Label lSource = new Label(this, SWT.NONE);
tSource = new Text(this, SWT.BORDER);
lSource.setText(Messages.ImporterPage_source); //$NON-NLS-1$
tSource.setEditable(false);
lSource.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
tSource.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
tSource.setText(CoreHub.localCfg.get(
"ImporterPage/" + home.getTitle() + "/ODBC-Source", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
home.results = new String[1];
home.results[0] = tSource.getText();
Button bSource = new Button(this, SWT.PUSH);
bSource.setText(Messages.ImporterPage_enter); //$NON-NLS-1$
bSource.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e){
InputDialog in =
new InputDialog(parent.getShell(), Messages.ImporterPage_odbcSource, //$NON-NLS-1$
Messages.ImporterPage_pleaseEnterODBC, null, null); //$NON-NLS-1$
if (in.open() == Dialog.OK) {
tSource.setText(in.getValue());
home.results[0] = in.getValue();
CoreHub.localCfg.set(
"ImporterPage/" + home.getTitle() + "/ODBC-Source", home.results[0]); //$NON-NLS-1$ //$NON-NLS-2$
}
}
});
}
private void getWidgetsData( Object sourceData, GuiElements guiElements ) {
if ( guiElements.isIgnored() ) {
return;
}
// Do we add the element or the children?
//
if ( guiElements.getId() != null ) {
Control control = widgetsMap.get( guiElements.getId() );
if ( control != null ) {
// What's the value?
//
Object value = null;
switch ( guiElements.getType() ) {
case TEXT:
if ( guiElements.isVariablesEnabled() ) {
TextVar textVar = (TextVar) control;
value = textVar.getText();
} else {
Text text = (Text) control;
value = text.getText();
}
break;
case CHECKBOX:
Button button = (Button) control;
value = button.getSelection();
break;
case COMBO:
if ( guiElements.isVariablesEnabled() ) {
ComboVar comboVar = (ComboVar) control;
value = comboVar.getText();
} else {
Combo combo = (Combo) control;
value = combo.getText();
}
break;
default:
System.err.println( "WARNING: getting data from widget with ID " + guiElements.getId() + " : not implemented type " + guiElements.getType() + " yet." );
break;
}
// Set the value on the source data object
//
try {
new PropertyDescriptor( guiElements.getFieldName(), sourceData.getClass() )
.getWriteMethod()
.invoke( sourceData, value )
;
} catch ( Exception e ) {
System.err.println( "Unable to set value '" + value + "'on field: '" + guiElements.getFieldName() + "' : " + e.getMessage() );
e.printStackTrace();
}
} else {
System.err.println( "Widget not found to set value on for id: " + guiElements.getId()+", label: "+guiElements.getLabel() );
}
} else {
// Add the children
//
for ( GuiElements child : guiElements.getChildren() ) {
getWidgetsData( sourceData, child );
}
}
}
public boolean performOk( )
{
for ( int i = 0; i < propList.size( ); i++ )
{
try
{
String value = null;
Text propertyText = (Text) propertyTextList.get( i );
if ( !propertyText.isDisposed( )
&& propertyText.getText( ) != null
&& propertyText.getText( ).trim( ).length( ) > 0 )
{
value = propertyText.getText( ).trim( );
}
Expression expr = new Expression( value,
(String) propertyText.getData( DataUIConstants.EXPR_TYPE ) );
if ( ds instanceof DesignElementHandle )
{
if ( propList.get( i ) instanceof String[] )
{
( (DesignElementHandle) ds ).setPropertyBinding( ( (String[]) propList.get( i ) )[0],
expr );
}
else if ( propList.get( i ) instanceof Property )
{
( (DesignElementHandle) ds ).setPropertyBinding( ( (Property) propList.get( i ) ).getName( ),
expr );
}
}
}
catch ( Exception e )
{
logger.log( Level.FINE, e.getMessage( ), e );
ExceptionHandler.handle( e );
return true;
}
}
return super.performOk( );
}
protected void textChanged(Text textControl) {
Key key= (Key) textControl.getData();
String number= textControl.getText();
String oldValue= setValue(key, number);
validateSettings(key, oldValue, number);
}