use of org.eclipse.jface.fieldassist.TextContentAdapter in project dbeaver by dbeaver.
the class PrefPageSQLFormat method createPreferenceContent.
@Override
protected Control createPreferenceContent(Composite parent) {
Composite composite = UIUtils.createPlaceholder(parent, 2, 5);
// Autoclose
{
Composite acGroup = UIUtils.createControlGroup(composite, CoreMessages.pref_page_sql_format_group_auto_close, 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
acSingleQuotesCheck = UIUtils.createCheckbox(acGroup, CoreMessages.pref_page_sql_format_label_single_quotes, false);
acDoubleQuotesCheck = UIUtils.createCheckbox(acGroup, CoreMessages.pref_page_sql_format_label_double_quotes, false);
acBracketsCheck = UIUtils.createCheckbox(acGroup, CoreMessages.pref_page_sql_format_label_brackets, false);
}
{
// Formatting
Composite afGroup = UIUtils.createControlGroup(composite, CoreMessages.pref_page_sql_format_group_auto_format, 1, GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING, 0);
afKeywordCase = UIUtils.createCheckbox(afGroup, CoreMessages.pref_page_sql_format_label_convert_keyword_case, CoreMessages.pref_page_sql_format_label_convert_keyword_case_tip, false, 1);
afExtractFromSource = UIUtils.createCheckbox(afGroup, CoreMessages.pref_page_sql_format_label_extract_sql_from_source_code, CoreMessages.pref_page_sql_format_label_extract_sql_from_source_code_tip, false, 1);
}
Composite formatterGroup = UIUtils.createControlGroup(composite, CoreMessages.pref_page_sql_format_group_formatter, 1, GridData.FILL_BOTH, 0);
((GridData) formatterGroup.getLayoutData()).horizontalSpan = 2;
{
Composite formatterPanel = UIUtils.createPlaceholder(formatterGroup, 2);
formatterPanel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
formatterSelector = UIUtils.createLabelCombo(formatterPanel, CoreMessages.pref_page_sql_format_label_formatter, SWT.DROP_DOWN | SWT.READ_ONLY);
formatters = SQLFormatterConfigurationRegistry.getInstance().getFormatters();
for (SQLFormatterDescriptor formatterDesc : formatters) {
formatterSelector.add(DBPIdentifierCase.capitalizeCaseName(formatterDesc.getLabel()));
}
formatterSelector.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
showFormatterSettings();
performApply();
}
});
formatterSelector.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
}
// Default formatter settings
{
defaultGroup = UIUtils.createPlaceholder(formatterGroup, 2, 0);
defaultGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
keywordCaseCombo = UIUtils.createLabelCombo(defaultGroup, CoreMessages.pref_page_sql_format_label_keyword_case, SWT.DROP_DOWN | SWT.READ_ONLY);
keywordCaseCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
keywordCaseCombo.add("Database");
for (DBPIdentifierCase c : DBPIdentifierCase.values()) {
keywordCaseCombo.add(DBPIdentifierCase.capitalizeCaseName(c.name()));
}
keywordCaseCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
performApply();
}
});
}
// External formatter
{
externalGroup = UIUtils.createPlaceholder(formatterGroup, 2, 5);
externalGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING));
externalCmdText = UIUtils.createLabelText(externalGroup, CoreMessages.pref_page_sql_format_label_external_command_line, "");
externalCmdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
UIUtils.installContentProposal(externalCmdText, new TextContentAdapter(), new SimpleContentProposalProvider(new String[] { GeneralUtils.variablePattern(SQLFormatterExternal.VAR_FILE) }));
UIUtils.setContentProposalToolTip(externalCmdText, CoreMessages.pref_page_sql_format_label_external_set_content_tool_tip, SQLFormatterExternal.VAR_FILE);
externalUseFile = UIUtils.createLabelCheckbox(externalGroup, CoreMessages.pref_page_sql_format_label_external_use_temp_file, CoreMessages.pref_page_sql_format_label_external_use_temp_file_tip + GeneralUtils.variablePattern(SQLFormatterExternal.VAR_FILE), false);
externalTimeout = UIUtils.createLabelSpinner(externalGroup, CoreMessages.pref_page_sql_format_label_external_exec_timeout, CoreMessages.pref_page_sql_format_label_external_exec_timeout_tip, 100, 100, 10000);
}
{
// SQL preview
Composite previewGroup = new Composite(formatterGroup, SWT.BORDER);
previewGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
previewGroup.setLayout(new FillLayout());
sqlViewer = new SQLEditorBase() {
@Override
public DBCExecutionContext getExecutionContext() {
final DBPDataSourceContainer container = getDataSourceContainer();
if (container != null) {
final DBPDataSource dataSource = container.getDataSource();
if (dataSource != null) {
return dataSource.getDefaultContext(false);
}
}
return null;
}
};
try {
try (final InputStream sqlStream = getClass().getResourceAsStream(FORMAT_FILE_NAME)) {
final String sqlText = ContentUtils.readToString(sqlStream, GeneralUtils.DEFAULT_ENCODING);
IEditorSite subSite = new SubEditorSite(DBeaverUI.getActiveWorkbenchWindow().getActivePage().getActivePart().getSite());
StringEditorInput sqlInput = new StringEditorInput("SQL preview", sqlText, true, GeneralUtils.getDefaultFileEncoding());
sqlViewer.init(subSite, sqlInput);
}
} catch (Exception e) {
log.error(e);
}
sqlViewer.createPartControl(previewGroup);
Object text = sqlViewer.getAdapter(Control.class);
if (text instanceof StyledText) {
((StyledText) text).setWordWrap(true);
}
sqlViewer.reloadSyntaxRules();
previewGroup.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
sqlViewer.dispose();
}
});
}
return composite;
}
use of org.eclipse.jface.fieldassist.TextContentAdapter in project egit by eclipse.
the class UIUtils method addPreviousValuesContentProposalToText.
/**
* Adds a "previously used values" content proposal handler to a text field.
* <p>
* The list will be limited to 10 values.
*
* @param textField
* the text field
* @param preferenceKey
* the key under which to store the "previously used values" in
* the dialog settings
* @return the handler the proposal handler
*/
public static IPreviousValueProposalHandler addPreviousValuesContentProposalToText(final Text textField, final String preferenceKey) {
KeyStroke stroke = UIUtils.getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
if (stroke == null)
addBulbDecorator(textField, UIText.UIUtils_StartTypingForPreviousValuesMessage);
else
addBulbDecorator(textField, NLS.bind(UIText.UIUtils_PressShortcutMessage, stroke.format()));
IContentProposalProvider cp = new IContentProposalProvider() {
@Override
public IContentProposal[] getProposals(String contents, int position) {
List<IContentProposal> resultList = new ArrayList<>();
Pattern pattern = createProposalPattern(contents);
String[] proposals = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings().getArray(preferenceKey);
if (proposals != null) {
for (final String uriString : proposals) {
if (pattern != null && !pattern.matcher(uriString).matches()) {
continue;
}
IContentProposal propsal = new IContentProposal() {
@Override
public String getLabel() {
return null;
}
@Override
public String getDescription() {
return null;
}
@Override
public int getCursorPosition() {
return 0;
}
@Override
public String getContent() {
return uriString;
}
};
resultList.add(propsal);
}
}
return resultList.toArray(new IContentProposal[resultList.size()]);
}
};
ContentProposalAdapter adapter = new ContentProposalAdapter(textField, new TextContentAdapter(), cp, stroke, VALUE_HELP_ACTIVATIONCHARS);
// set the acceptance style to always replace the complete content
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
return new IPreviousValueProposalHandler() {
@Override
public void updateProposals() {
String value = textField.getText();
// don't store empty values
if (value.length() > 0) {
// we don't want to save too much in the preferences
if (value.length() > 2000) {
value = value.substring(0, 1999);
}
// now we need to mix the value into the list
IDialogSettings settings = org.eclipse.egit.ui.Activator.getDefault().getDialogSettings();
String[] existingValues = settings.getArray(preferenceKey);
if (existingValues == null) {
existingValues = new String[] { value };
settings.put(preferenceKey, existingValues);
} else {
List<String> values = new ArrayList<>(existingValues.length + 1);
for (String existingValue : existingValues) values.add(existingValue);
// anything
if (values.indexOf(value) == 0)
return;
values.remove(value);
// we insert at the top
values.add(0, value);
// of values
while (values.size() > 10) values.remove(values.size() - 1);
settings.put(preferenceKey, values.toArray(new String[values.size()]));
}
}
}
};
}
use of org.eclipse.jface.fieldassist.TextContentAdapter in project egit by eclipse.
the class PushToGerritPage method addTopicProposal.
private void addTopicProposal(Text textField) {
if (topicProposals.isEmpty()) {
return;
}
KeyStroke stroke = UIUtils.getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
if (stroke != null) {
UIUtils.addBulbDecorator(textField, NLS.bind(UIText.PushToGerritPage_TopicContentProposalHoverText, stroke.format()));
}
String[] recentTopics = topicProposals.keySet().toArray(new String[topicProposals.size()]);
Arrays.sort(recentTopics, CommonUtils.STRING_ASCENDING_COMPARATOR);
SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(recentTopics);
proposalProvider.setFiltering(true);
ContentProposalAdapter adapter = new ContentProposalAdapter(textField, new TextContentAdapter(), proposalProvider, stroke, null);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
}
use of org.eclipse.jface.fieldassist.TextContentAdapter in project jbosstools-openshift by jbosstools.
the class DeployImagePage method createImageNameControls.
private void createImageNameControls(final Composite parent, final DataBindingContext dbc) {
// Image
final Label imageNameLabel = new Label(parent, SWT.NONE);
imageNameLabel.setText("Image Name: ");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(imageNameLabel);
final Text imageNameText = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(imageNameText);
final IObservableValue<String> imageNameTextObservable = WidgetProperties.text(SWT.Modify).observeDelayed(500, imageNameText);
final IObservableValue<String> imageNameObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_IMAGE_NAME).observe(model);
Binding imageBinding = ValueBindingBuilder.bind(imageNameTextObservable).converting(new TrimmingStringConverter()).validatingAfterConvert(new DockerImageValidator()).to(imageNameObservable).in(dbc);
ControlDecorationSupport.create(imageBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
imageNameProposalAdapter = new ContentProposalAdapter(imageNameText, // move the cursor to the end of the selected value
new TextContentAdapter() {
@Override
public void insertControlContents(Control control, String text, int cursorPosition) {
final Text imageNameText = (Text) control;
final Point selection = imageNameText.getSelection();
imageNameText.setText(text);
selection.x = text.length();
selection.y = selection.x;
imageNameText.setSelection(selection);
}
}, getImageNameContentProposalProvider(imageNameText), null, null);
// List local Docker images
Button btnDockerBrowse = new Button(parent, SWT.NONE);
btnDockerBrowse.setText("Browse...");
btnDockerBrowse.setToolTipText("Look-up an image by browsing the Docker daemon");
btnDockerBrowse.addSelectionListener(onBrowseImage());
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(btnDockerBrowse);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnDockerBrowse)).notUpdatingParticipant().to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
// search on Docker registry (Docker Hub)
Button btnDockerSearch = new Button(parent, SWT.NONE);
btnDockerSearch.setText("Search...");
btnDockerSearch.setToolTipText("Search an image on the Docker registry");
btnDockerSearch.addSelectionListener(onSearchImage(imageNameText));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(btnDockerSearch);
ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnDockerSearch)).notUpdatingParticipant().to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
}
use of org.eclipse.jface.fieldassist.TextContentAdapter in project jbosstools-openshift by jbosstools.
the class SelectProjectComponentBuilder method build.
public void build(Composite container, DataBindingContext dbc) {
Label existingProjectLabel = new Label(container, SWT.NONE);
existingProjectLabel.setText("Eclipse Project: ");
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(existingProjectLabel);
final Text existingProjectNameText = new Text(container, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(hSpan, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(existingProjectNameText);
projectNameTextObservable = WidgetProperties.text(SWT.Modify).observe(existingProjectNameText);
Binding eclipseProjectBinding = ValueBindingBuilder.bind(projectNameTextObservable).validatingAfterConvert(new IValidator() {
@Override
public IStatus validate(Object value) {
if (value instanceof String) {
return ValidationStatus.ok();
} else if (value == null) {
if (required) {
return ValidationStatus.error("Select an existing project");
} else if (!StringUtils.isEmpty(existingProjectNameText.getText())) {
return ValidationStatus.error(NLS.bind("Project {0} does not exist", existingProjectNameText.getText()));
}
}
return ValidationStatus.ok();
}
}).converting(new Converter(String.class, IProject.class) {
@Override
public Object convert(Object fromObject) {
String name = (String) fromObject;
return ProjectUtils.getProject(name);
}
}).to(eclipseProjectObservable).converting(new Converter(IProject.class, String.class) {
@Override
public Object convert(Object fromObject) {
return fromObject == null ? "" : ((IProject) fromObject).getName();
}
}).in(dbc);
ControlDecorationSupport.create(eclipseProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
// project name content assist
ControlDecoration dec = new ControlDecoration(existingProjectNameText, SWT.TOP | SWT.RIGHT);
FieldDecoration contentProposalFieldIndicator = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
dec.setImage(contentProposalFieldIndicator.getImage());
dec.setDescriptionText("Auto-completion is enabled when you start typing a project name.");
dec.setShowOnlyOnFocus(true);
new AutoCompleteField(existingProjectNameText, new TextContentAdapter(), ProjectUtils.getAllAccessibleProjectNames());
// browse projects
Button browseProjectsButton = new Button(container, SWT.NONE);
browseProjectsButton.setText("Browse...");
GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).indent(buttonIndent, 0).applyTo(browseProjectsButton);
UIUtils.setDefaultButtonWidth(browseProjectsButton);
browseProjectsButton.addSelectionListener(selectionListener);
}
Aggregations