下面列出了org.eclipse.swt.widgets.Text#setMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void createFilter(final Composite listComposite) {
final Text fileStoreListFilter = new Text(listComposite,
SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
fileStoreListFilter.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
fileStoreListFilter.setMessage(WorkbenchMessages.FilteredTree_FilterMessage);
fileStoreListFilter.addModifyListener(new ModifyListener() {
private ViewerFilter filter;
@Override
public void modifyText(final ModifyEvent e) {
final String textForFiltering = fileStoreListFilter.getText();
if (filter != null) {
fileStoreListViewer.removeFilter(filter);
}
if (textForFiltering != null
&& !textForFiltering.isEmpty()) {
filter = new ViewerFilterOnFileStoreName(textForFiltering);
fileStoreListViewer.addFilter(filter);
}
}
});
}
public void createStandardLinkText ( final Composite parent, final String linkFactory, final String attributeName, final String label, final String textMessage, final ConfigurationEditorInput input, final Object valueType )
{
this.toolkit.createLabel ( parent, label + ":" );
final Text text = this.toolkit.createText ( parent, "" );
text.setMessage ( textMessage );
text.setLayoutData ( new GridData ( GridData.FILL, GridData.BEGINNING, true, true ) );
text.setToolTipText ( textMessage );
final IObservableValue value = Observables.observeMapEntry ( input.getDataMap (), attributeName, valueType );
this.dbc.bindValue ( WidgetProperties.text ( SWT.Modify ).observe ( text ), value );
final Hyperlink link = this.toolkit.createHyperlink ( parent, "link", SWT.NONE );
link.setLayoutData ( new GridData ( GridData.FILL, GridData.BEGINNING, false, false ) );
link.addHyperlinkListener ( new HyperlinkAdapter () {
@Override
public void linkActivated ( final HyperlinkEvent e )
{
EditorHelper.handleOpen ( PlatformUI.getWorkbench ().getActiveWorkbenchWindow ().getActivePage (), input.getConnectionUri (), linkFactory, text.getText () );
}
} );
}
@PostConstruct
public void createComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false));
txtInput = new Text(parent, SWT.BORDER);
txtInput.setMessage("Enter text to mark part as dirty");
txtInput.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
dirty.setDirty(true);
}
});
txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
tableViewer = new TableViewer(parent);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());;
tableViewer.setInput(createInitialDataModel());
tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
}
private void createAddressInfoFields(final Composite detailsInfoComposite, final EReference reference) {
final Label cityLabel = new Label(detailsInfoComposite, SWT.NONE);
cityLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
cityLabel.setText(Messages.cityLabel);
final Composite addressInfo = new Composite(detailsInfoComposite, SWT.NONE);
addressInfo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
addressInfo.setLayout(
GridLayoutFactory.fillDefaults().numColumns(5).margins(0, 0).spacing(2, 0).equalWidth(false).create());
final Text cityText = new Text(addressInfo, SWT.BORDER);
cityText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
cityText.setMessage(Messages.cityHint);
bindTextToUserAttribute(cityText, reference, OrganizationPackage.Literals.CONTACT_DATA__CITY,
updateValueStrategy()
.withValidator(maxLengthValidator(Messages.cityLabel, LONG_FIELD_MAX_LENGTH)).create());
createPersonalStateField(addressInfo, reference);
createPersonalZipCodeField(addressInfo, reference);
}
private void createGeneralLastNameField(final Composite detailsInfoComposite) {
final Label lastName = new Label(detailsInfoComposite, SWT.NONE);
lastName.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
lastName.setText(Messages.lastName);
final Text lastNameText = new Text(detailsInfoComposite, SWT.BORDER);
lastNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
lastNameText.setMessage(Messages.lastNameHint);
final IObservableValue lastNameUserValue = EMFObservables.observeDetailValue(Realm.getDefault(),
userSingleSelectionObservable,
OrganizationPackage.Literals.USER__LAST_NAME);
context.bindValue(SWTObservables.observeText(lastNameText, SWT.Modify), lastNameUserValue);
lastNameUserValue.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(final ValueChangeEvent event) {
handleLastNameChange(event);
}
});
}
private void createGeneralTitleField(final Composite detailsInfoComposite) {
final Label titleLabel = new Label(detailsInfoComposite, SWT.NONE);
titleLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
titleLabel.setText(Messages.userTitle);
final Text titleText = new Text(detailsInfoComposite, SWT.BORDER);
titleText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
titleText.setMessage(Messages.titleHint);
// widgetMap.put(OrganizationPackage.Literals.USER__TITLE, titleText) ;
final IObservableValue titleUserValue = EMFObservables.observeDetailValue(Realm.getDefault(),
userSingleSelectionObservable,
OrganizationPackage.Literals.USER__TITLE);
context.bindValue(SWTObservables.observeText(titleText, SWT.Modify), titleUserValue);
}
private void createDescriptionField(final Group group) {
final Label descriptionLabel = new Label(group, SWT.NONE);
descriptionLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.FILL).create());
descriptionLabel.setText(Messages.description);
final Text roleDescriptionText = new Text(group, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
roleDescriptionText
.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 80).create());
roleDescriptionText.setMessage(Messages.descriptionHint);
roleDescriptionText.setTextLimit(255);
final IObservableValue roleDescriptionValue = EMFObservables.observeDetailValue(Realm.getDefault(),
roleSingleSelectionObservable, OrganizationPackage.Literals.ROLE__DESCRIPTION);
context.bindValue(SWTObservables.observeText(roleDescriptionText, SWT.Modify), roleDescriptionValue);
roleDescriptionValue.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(final ValueChangeEvent event) {
handleRoleDescriptionChange(event);
}
});
}
private void createFilterBox() {
//TODO: Directly use the hint flags once Bug 293230 is fixed
FilterTextControl filterTextControl= new FilterTextControl(fParentComposite);
final Text filterBox= filterTextControl.getFilterControl();
filterBox.setMessage(PreferencesMessages.OptionsConfigurationBlock_TypeFilterText);
filterBox.addModifyListener(new ModifyListener() {
private String fPrevFilterText;
public void modifyText(ModifyEvent e) {
String input= filterBox.getText();
if (input != null && input.equalsIgnoreCase(fPrevFilterText))
return;
fPrevFilterText= input;
doFilter(input);
}
});
}
@PostConstruct
public void createComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false));
txtInput = new Text(parent, SWT.BORDER);
txtInput.setMessage("Enter text to mark part as dirty");
txtInput.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
dirty.setDirty(true);
}
});
txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
tableViewer = new TableViewer(parent);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());;
tableViewer.setInput(createInitialDataModel());
tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
}
private void createWebSiteField(final Composite detailsInfoComposite, final EReference reference) {
final Label websiteLabel = new Label(detailsInfoComposite, SWT.NONE);
websiteLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
websiteLabel.setText(Messages.websiteLabel);
final Text websiteText = new Text(detailsInfoComposite, SWT.BORDER);
websiteText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
websiteText.setMessage(Messages.websiteHint);
bindTextToUserAttribute(websiteText, reference, OrganizationPackage.Literals.CONTACT_DATA__WEBSITE,
updateValueStrategy()
.withValidator(maxLengthValidator(Messages.websiteLabel, LONG_FIELD_MAX_LENGTH)).create());
}
private void createDisplayNameField(final Group group) {
final Label displayNameLabel = new Label(group, SWT.NONE);
displayNameLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
displayNameLabel.setText(Messages.displayName);
final Text displayNamedText = new Text(group, SWT.BORDER);
displayNamedText.setMessage(Messages.groupNameExample);
displayNamedText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
final IObservableValue displayNameValue = EMFObservables.observeDetailValue(Realm.getDefault(), groupSingleSelectionObservable,
OrganizationPackage.Literals.GROUP__DISPLAY_NAME);
final Binding binding = context.bindValue(SWTObservables.observeText(displayNamedText, SWT.Modify), displayNameValue,
UpdateStrategyFactory.updateValueStrategy()
.withValidator(maxLengthValidator(Messages.displayName, LONG_FIELD_MAX_LENGTH)).create(),
null);
ControlDecorationSupport.create(binding, SWT.LEFT);
displayNameValue.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(final ValueChangeEvent event) {
handleGroupDisplayName(event);
}
});
}
public void createStandardText ( final Composite parent, final String attributeName, final int style, final String label, final String textMessage, final IObservableMap data, final Object valueType )
{
final Label labelControl = this.toolkit.createLabel ( parent, label + ":" );
final boolean multi = ( style & SWT.MULTI ) > 0;
if ( multi )
{
labelControl.setLayoutData ( new GridData ( SWT.FILL, SWT.FILL, false, false ) );
}
final Text text = this.toolkit.createText ( parent, "", style );
text.setMessage ( textMessage );
final GridData gd = new GridData ( GridData.FILL, multi ? GridData.FILL : GridData.BEGINNING, true, true );
gd.horizontalSpan = 2;
text.setLayoutData ( gd );
text.setToolTipText ( textMessage );
final IObservableValue value = Observables.observeMapEntry ( data, attributeName, String.class );
if ( valueType != null && valueType != String.class )
{
final WritableValue conversionValue = new WritableValue ( null, valueType );
this.dbc.bindValue ( WidgetProperties.text ( SWT.Modify ).observe ( text ), conversionValue );
this.dbc.bindValue ( conversionValue, value );
}
else
{
this.dbc.bindValue ( WidgetProperties.text ( SWT.Modify ).observe ( text ), value );
}
}
private void createPersonalStateField(final Composite addressInfo, final EReference reference) {
final Label stateLabel = new Label(addressInfo, SWT.NONE);
stateLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
stateLabel.setText(Messages.stateLabel);
final Text stateText = new Text(addressInfo, SWT.BORDER);
stateText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
stateText.setMessage(Messages.stateHint);
bindTextToUserAttribute(stateText, reference, OrganizationPackage.Literals.CONTACT_DATA__STATE,
updateValueStrategy()
.withValidator(maxLengthValidator(Messages.stateLabel, LONG_FIELD_MAX_LENGTH)).create());
}
private void createFaxField(final Composite detailsInfoComposite, final EReference reference) {
final Label faxLabel = new Label(detailsInfoComposite, SWT.NONE);
faxLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
faxLabel.setText(Messages.faxLabel);
final Text faxText = new Text(detailsInfoComposite, SWT.BORDER);
faxText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
faxText.setMessage(Messages.faxHint);
bindTextToUserAttribute(faxText, reference, OrganizationPackage.Literals.CONTACT_DATA__FAX_NUMBER,
updateValueStrategy()
.withValidator(maxLengthValidator(Messages.faxLabel, SHORT_FIELD_MAX_LENGTH)).create());
}
@PostConstruct
public void createComposite(Composite parent) {
parent.setLayout(new GridLayout(1, false));
txtInput = new Text(parent, SWT.BORDER);
txtInput.setMessage("Enter text to mark part as dirty");
txtInput.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
dirty.setDirty(true);
}
});
txtInput.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
tableViewer = new TableViewer(parent);
tableViewer.add("Sample item 1");
tableViewer.add("Sample item 2");
tableViewer.add("Sample item 3");
tableViewer.add("Sample item 4");
tableViewer.add("Sample item 5");
tableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
selectionService.setSelection("Hello");
}
});
}
private void createServiceField(Composite parent) {
Label serviceNameLabel = new Label(parent, SWT.LEAD);
serviceNameLabel.setText(Messages.getString("app.engine.service")); //$NON-NLS-1$
serviceNameField = new Text(parent, SWT.BORDER);
serviceNameField.setMessage("default"); //$NON-NLS-1$
serviceNameField.addModifyListener(event -> revalidate());
}
@Override
protected Text createFilterText(final Composite parent) {
final Text filterText = new Text(parent, SWT.SEARCH | SWT.ICON_SEARCH);
filterText.setMessage("Search keyword");
Dialog.applyDialogFont(filterText);
final GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.CENTER;
filterText.setLayoutData(data);
filterText.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(final KeyEvent e) {
if (e.keyCode == 0x0D) {
gotoSelectedElement();
}
if (e.keyCode == SWT.ARROW_DOWN) {
getTreeViewer().getTree().setFocus();
}
if (e.keyCode == SWT.ARROW_UP) {
getTreeViewer().getTree().setFocus();
}
if (e.character == 0x1B) {
dispose();
}
}
});
return filterText;
}
public UZText(Composite parent, String msg, String iconPath) {
parent.setLayout(new GridLayout(2, false));
parent.setBackground(new Color(null, 255, 255, 255));
label = new Label(parent, SWT.NONE);
label.setImage(AuthenticActivator.getImage(iconPath));
label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
text = new Text(parent, SWT.NONE);
text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
1, 1));
text.setMessage(msg);
}
private void createPersonalRoomField(final Composite buildingInfo, final EReference reference) {
final Label roomLabel = new Label(buildingInfo, SWT.NONE);
roomLabel.setLayoutData(GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).create());
roomLabel.setText(Messages.roomLabel);
final Text roomText = new Text(buildingInfo, SWT.BORDER);
roomText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
roomText.setMessage(Messages.roomHint);
bindTextToUserAttribute(roomText, reference, OrganizationPackage.Literals.CONTACT_DATA__ROOM,
updateValueStrategy()
.withValidator(maxLengthValidator(Messages.roomLabel, SHORT_FIELD_MAX_LENGTH)).create());
}
private void createProjectIdSection() {
Label projectIdLabel = new Label(this, SWT.LEAD);
projectIdLabel.setText(Messages.getString("project"));
projectIdLabel.setToolTipText(Messages.getString("tooltip.project.id"));
GridDataFactory.swtDefaults().align(SWT.BEGINNING, SWT.BEGINNING).span(1, 2)
.applyTo(projectIdLabel);
Composite linkComposite = new Composite(this, SWT.NONE);
Link createNewProject = new Link(linkComposite, SWT.WRAP);
createNewProject.setText(Messages.getString("projectselector.createproject",
CREATE_GCP_PROJECT_URL));
createNewProject.setToolTipText(Messages.getString("projectselector.createproject.tooltip"));
FontUtil.convertFontToItalic(createNewProject);
createNewProject.addSelectionListener(new OpenUriSelectionListener(
() -> accountSelector.getSelectedEmail().isEmpty()
? Collections.emptyMap()
: Collections.singletonMap("authuser", accountSelector.getSelectedEmail()),
new ErrorDialogErrorHandler(getShell())));
GridDataFactory.fillDefaults().applyTo(linkComposite);
GridLayoutFactory.fillDefaults().generateLayout(linkComposite);
Composite projectSelectorComposite = new Composite(this, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(projectSelectorComposite);
GridDataFactory.fillDefaults().grab(true, false).applyTo(projectSelectorComposite);
final Text filterField = new Text(projectSelectorComposite,
SWT.BORDER | SWT.SEARCH | SWT.ICON_SEARCH | SWT.ICON_CANCEL);
filterField.setMessage(Messages.getString("projectselector.filter"));
GridDataFactory.fillDefaults().applyTo(filterField);
new Label(projectSelectorComposite, SWT.NONE); // spacer
projectSelector = new ProjectSelector(projectSelectorComposite);
GridDataFactory.fillDefaults().grab(true, false).hint(SWT.DEFAULT, 200)
.applyTo(projectSelector);
final Button refreshProjectsButton = new Button(projectSelectorComposite, SWT.NONE);
refreshProjectsButton.setImage(refreshIcon);
GridDataFactory.swtDefaults().align(SWT.END, SWT.BEGINNING).applyTo(refreshProjectsButton);
refreshProjectsButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
refreshProjectsForSelectedCredential();
}
});
accountSelector.addSelectionListener(
new RefreshProjectOnAccountSelection(refreshProjectsButton));
projectSelector.addSelectionChangedListener(
new ProjectSelectorSelectionChangedListener(accountSelector,
projectRepository,
projectSelector));
filterField.addModifyListener(event -> {
projectSelector.setFilter(filterField.getText());
});
}