use of org.eclipse.jface.fieldassist.ContentProposalAdapter in project sling by apache.
the class NewNodeDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite composite = (Composite) super.createDialogArea(parent);
Control[] children = composite.getChildren();
Control errorMessageText = children[children.length - 1];
GridData errorMessageGridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL);
errorMessageGridData.heightHint = convertHeightInCharsToPixels(2);
errorMessageText.setLayoutData(errorMessageGridData);
// now add the node type dropbox-combo
Label label = new Label(composite, SWT.WRAP);
label.moveAbove(errorMessageText);
label.setText("Define node type");
GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_CENTER);
data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
label.setLayoutData(data);
label.setFont(parent.getFont());
combo = new Combo(composite, SWT.DROP_DOWN);
combo.moveAbove(errorMessageText);
if (allowedChildren != null) {
combo.setItems(allowedChildren.toArray(new String[0]));
}
combo.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
combo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
comboSelection = combo.getText();
validateInput();
}
});
combo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
comboSelection = combo.getText();
validateInput();
}
});
SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(combo.getItems());
proposalProvider.setFiltering(true);
final ComboContentAdapter controlContentAdapter = new ComboContentAdapter() {
@Override
public void insertControlContents(Control control, String text, int cursorPosition) {
Point selection = combo.getSelection();
combo.setText(text);
selection.x = selection.x + cursorPosition;
selection.y = selection.x;
combo.setSelection(selection);
}
@Override
public Rectangle getInsertionBounds(Control control) {
final Rectangle insertionBounds = super.getInsertionBounds(control);
// always insert at start
insertionBounds.x = 0;
insertionBounds.y = 0;
return insertionBounds;
}
};
// this variant opens auto-complete on each character
proposalAdapter = new ContentProposalAdapter(combo, controlContentAdapter, proposalProvider, null, null);
// this variant opens auto-complete only when invoking the auto-complete hotkey
if (allowedChildren != null && allowedChildren.size() == 1) {
combo.setText(allowedChildren.iterator().next());
} else if (allowedChildren != null) {
if (allowedChildren.contains(lastChosenNodeType)) {
combo.setText(lastChosenNodeType);
}
}
return composite;
}
use of org.eclipse.jface.fieldassist.ContentProposalAdapter in project sling by apache.
the class JcrEditingSupport method doGetCellEditor.
protected CellEditor doGetCellEditor(Object element) {
if (!canEdit(element)) {
return null;
}
switch(columnId) {
case NAME:
{
// no validator needed - any string is OK
return new TextCellEditor(tableViewer.getTable());
}
case TYPE:
{
// using a dropdown editor
final ComboBoxCellEditor editor = new ComboBoxCellEditor(tableViewer.getTable(), PropertyTypeSupport.PROPERTY_TYPES, SWT.NONE);
editor.setActivationStyle(ComboBoxCellEditor.DROP_DOWN_ON_KEY_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_MOUSE_ACTIVATION | ComboBoxCellEditor.DROP_DOWN_ON_TRAVERSE_ACTIVATION);
return editor;
}
case VALUE:
{
final Field field = asField(element);
if (getNode().getProperty(field.getPropertyName()).isMultiple()) {
// then launch the MVPEditor instead of returning an editor here
return new MVNCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
}
if (field.getPropertyType() == PropertyType.DATE) {
return new DateTimeCellEditor(tableViewer.getTable(), getNode(), field.getPropertyName());
}
if (field.getPropertyType() == PropertyType.BOOLEAN) {
return new ComboBoxCellEditor(tableViewer.getTable(), new String[] { "false", "true" }, SWT.READ_ONLY);
}
CellEditor editor;
if (field.getPropertyName().equals("jcr:primaryType")) {
editor = new TextCellEditor(tableViewer.getTable()) {
@Override
protected Control createControl(Composite parent) {
Text text = (Text) super.createControl(parent);
Repository repository = ServerUtil.getDefaultRepository(getNode().getProject());
NodeTypeRegistry ntManager = (repository == null) ? null : repository.getNodeTypeRegistry();
if (ntManager == null) {
return text;
}
try {
Collection<String> types = ntManager.getAllowedPrimaryChildNodeTypes(getNode().getParent().getPrimaryType());
SimpleContentProposalProvider proposalProvider = new SimpleContentProposalProvider(types.toArray(new String[0]));
proposalProvider.setFiltering(true);
ContentProposalAdapter adapter = new ContentProposalAdapter(text, new TextContentAdapter(), proposalProvider, null, null);
adapter.setPropagateKeys(true);
adapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
return text;
} catch (RepositoryException e) {
return text;
}
}
};
} else {
editor = new TextCellEditor(tableViewer.getTable());
}
// value might require a validator depending on the property type
int propertyType = getNode().getPropertyType(field.getPropertyName());
switch(propertyType) {
case PropertyType.STRING:
case PropertyType.NAME:
{
//TODO: check jcr rules for name
break;
}
case PropertyType.DECIMAL:
{
editor.setValidator(new DecimalValidator(editor));
break;
}
default:
{
//TODO
break;
}
}
return editor;
}
case MULTIPLE:
{
if (element instanceof NewRow) {
return null;
}
return new ComboBoxCellEditor(tableViewer.getTable(), new String[] { "false", "true" }, SWT.READ_ONLY);
}
default:
{
throw new IllegalStateException("Unknown columnId: " + columnId);
}
}
}
use of org.eclipse.jface.fieldassist.ContentProposalAdapter in project linuxtools by eclipse.
the class RunImageMainTab method createImageSettingsSection.
/**
* Creates the {@link Composite} container that will display widgets to
* select an {@link IDockerImage}, name it and specify the command to run.
*
* @param container
* the parent {@link Composite}
*/
private void createImageSettingsSection(final Composite container) {
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(3, 1).applyTo(new Label(container, SWT.NONE));
final Label connectionSelectionLabel = new Label(container, SWT.NONE);
connectionSelectionLabel.setText(// $NON-NLS-1$
WizardMessages.getString("Connection.label"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(connectionSelectionLabel);
final Combo connectionSelectionCombo = new Combo(container, SWT.BORDER);
connectionSelectionCombo.setToolTipText(// $NON-NLS-1$
LaunchMessages.getString("RunMainTabSelectConnection.tooltip"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(connectionSelectionCombo);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).applyTo(new Label(container, SWT.NONE));
new ControlDecoration(connectionSelectionCombo, SWT.TOP | SWT.LEFT);
final ComboViewer connectionSelectionComboViewer = new ComboViewer(connectionSelectionCombo);
connectionSelectionComboViewer.setContentProvider(new ArrayContentProvider());
connectionSelectionComboViewer.setInput(DockerConnectionManager.getInstance().getConnectionNames().toArray());
dbc.bindValue(WidgetProperties.selection().observe(connectionSelectionCombo), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_CONNECTION_NAME).observe(model));
// Image selection name
final Label imageSelectionLabel = new Label(container, SWT.NONE);
// $NON-NLS-1$
imageSelectionLabel.setText(WizardMessages.getString("Image.label"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
final Combo imageSelectionCombo = new Combo(container, SWT.BORDER);
final ComboViewer imageSelectionComboViewer = new ComboViewer(imageSelectionCombo);
imageSelectionCombo.setToolTipText(WizardMessages.getString(// $NON-NLS-1$
"ImageRunSelectionPage.selectTooltip"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(imageSelectionCombo);
new ControlDecoration(imageSelectionCombo, SWT.TOP | SWT.LEFT);
new ContentProposalAdapter(imageSelectionCombo, new ComboContentAdapter() {
@Override
public void insertControlContents(Control control, String text, int cursorPosition) {
final Combo combo = (Combo) control;
final Point selection = combo.getSelection();
combo.setText(text);
selection.x = text.length();
selection.y = selection.x;
combo.setSelection(selection);
}
}, getImageNameContentProposalProvider(imageSelectionCombo), null, null);
// image search
final Button searchImageButton = new Button(container, SWT.NONE);
searchImageButton.setText(// $NON-NLS-1$
WizardMessages.getString("ImageRunSelectionPage.search"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).hint(LaunchConfigurationUtils.getButtonWidthHint(searchImageButton), SWT.DEFAULT).applyTo(searchImageButton);
searchImageButton.addSelectionListener(onSearchImage());
imageSelectionComboViewer.setContentProvider(new ObservableListContentProvider());
dbc.bindList(WidgetProperties.items().observe(imageSelectionCombo), BeanProperties.list(ImageRunSelectionModel.class, ImageRunSelectionModel.IMAGE_NAMES).observe(model));
dbc.bindValue(WidgetProperties.selection().observe(imageSelectionCombo), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.SELECTED_IMAGE_NAME).observe(model));
// Container name (optional)
final Label containerNameLabel = new Label(container, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
containerNameLabel.setText(WizardMessages.getString(// $NON-NLS-1$
"ImageRunSelectionPage.containerName"));
final Text containerNameText = new Text(container, SWT.BORDER);
containerNameText.setToolTipText(WizardMessages.getString(// $NON-NLS-1$
"ImageRunSelectionPage.containerTooltip"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(containerNameText);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).applyTo(new Label(container, SWT.NONE));
dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(containerNameText), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.CONTAINER_NAME).observe(model));
// EntryPoint (optional)
final Label entrypointLabel = new Label(container, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
entrypointLabel.setText(// $NON-NLS-1$
WizardMessages.getString("ImageRunSelectionPage.entrypoint"));
// TODO: include SWT.SEARCH | SWT.ICON_SEARCH to support value reset
final Text entrypointText = new Text(container, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(entrypointText);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).applyTo(new Label(container, SWT.NONE));
dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(entrypointText), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.ENTRYPOINT).observe(model));
// Command (optional)
final Label commandLabel = new Label(container, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(imageSelectionLabel);
commandLabel.setText(// $NON-NLS-1$
WizardMessages.getString("ImageRunSelectionPage.command"));
final Text commandText = new Text(container, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(commandText);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).span(1, 1).applyTo(new Label(container, SWT.NONE));
dbc.bindValue(WidgetProperties.text(SWT.Modify).observe(commandText), BeanProperties.value(ImageRunSelectionModel.class, ImageRunSelectionModel.COMMAND).observe(model));
}
use of org.eclipse.jface.fieldassist.ContentProposalAdapter in project linuxtools by eclipse.
the class ContainerLinkDialog method createDialogArea.
@Override
protected Control createDialogArea(final Composite parent) {
final int COLUMNS = 2;
final Composite container = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, false).applyTo(container);
GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(10, 10).applyTo(container);
final Label explanationLabel = new Label(container, SWT.NONE);
explanationLabel.setText(WizardMessages.getString(// $NON-NLS-1$
"ContainerLinkDialog.explanationLabel"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(false, false).applyTo(explanationLabel);
final Label containerLabel = new Label(container, SWT.NONE);
containerLabel.setText(// $NON-NLS-1$
WizardMessages.getString("ContainerLinkDialog.containerLabel"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(containerLabel);
final Combo containerSelectionCombo = new Combo(container, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(containerSelectionCombo);
final ComboViewer containerSelectionComboViewer = new ComboViewer(containerSelectionCombo);
containerSelectionComboViewer.setContentProvider(new ArrayContentProvider());
containerSelectionComboViewer.setInput(model.getContainerNames());
new ContentProposalAdapter(containerSelectionCombo, new ComboContentAdapter() {
@Override
public void insertControlContents(Control control, String text, int cursorPosition) {
final Combo combo = (Combo) control;
final Point selection = combo.getSelection();
combo.setText(text);
selection.x = text.length();
selection.y = selection.x;
combo.setSelection(selection);
}
}, getContainerNameContentProposalProvider(containerSelectionCombo), null, null);
final Label aliasLabel = new Label(container, SWT.NONE);
aliasLabel.setText(// $NON-NLS-1$
WizardMessages.getString("ContainerLinkDialog.aliasLabel"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(aliasLabel);
final Text containerAliasText = new Text(container, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(containerAliasText);
// error message
final Label errorMessageLabel = new Label(container, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(true, false).applyTo(errorMessageLabel);
final ISWTObservableValue containerNameObservable = WidgetProperties.selection().observe(containerSelectionComboViewer.getCombo());
dbc.bindValue(containerNameObservable, BeanProperties.value(ContainerLinkDialogModel.class, ContainerLinkDialogModel.CONTAINER_NAME).observe(model));
final ISWTObservableValue containerAliasObservable = WidgetProperties.text(SWT.Modify).observe(containerAliasText);
dbc.bindValue(containerAliasObservable, BeanProperties.value(ContainerLinkDialogModel.class, ContainerLinkDialogModel.CONTAINER_ALIAS).observe(model));
containerNameObservable.addValueChangeListener(onContainerLinkSettingsChanged());
containerAliasObservable.addValueChangeListener(onContainerLinkSettingsChanged());
return container;
}
use of org.eclipse.jface.fieldassist.ContentProposalAdapter in project linuxtools by eclipse.
the class ImageBuildDialog method createDialogArea.
@Override
protected Control createDialogArea(final Composite parent) {
final int COLUMNS = 2;
final Composite container = new Composite(parent, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, false).applyTo(container);
GridLayoutFactory.fillDefaults().numColumns(COLUMNS).margins(10, 10).applyTo(container);
final Label explanationLabel = new Label(container, SWT.NONE);
explanationLabel.setText(// $NON-NLS-1$
WizardMessages.getString("ImageBuildDialog.explanationLabel"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(COLUMNS, 1).grab(false, false).applyTo(explanationLabel);
final Label containerLabel = new Label(container, SWT.NONE);
containerLabel.setText(// $NON-NLS-1$
WizardMessages.getString("ImageBuildDialog.connectionLabel"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(containerLabel);
final Combo containerSelectionCombo = new Combo(container, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(containerSelectionCombo);
final ComboViewer connectionSelectionComboViewer = new ComboViewer(containerSelectionCombo);
connectionSelectionComboViewer.setContentProvider(new ArrayContentProvider());
final List<String> connectionNames = model.getConnectionNames();
connectionSelectionComboViewer.setInput(connectionNames);
new ContentProposalAdapter(containerSelectionCombo, new ComboContentAdapter() {
@Override
public void insertControlContents(Control control, String text, int cursorPosition) {
final Combo combo = (Combo) control;
final Point selection = combo.getSelection();
combo.setText(text);
selection.x = text.length();
selection.y = selection.x;
combo.setSelection(selection);
}
}, getConnectionNameContentProposalProvider(containerSelectionCombo), null, null);
final Label repoNameLabel = new Label(container, SWT.NONE);
repoNameLabel.setToolTipText(// $NON-NLS-1$
WizardMessages.getString("ImageBuildName.toolTip"));
// $NON-NLS-1$
repoNameLabel.setText(WizardMessages.getString("ImageBuildName.label"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(repoNameLabel);
final Text repoNameText = new Text(container, SWT.BORDER);
repoNameText.setToolTipText(// $NON-NLS-1$
WizardMessages.getString("ImageBuildName.toolTip"));
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(repoNameText);
final ISWTObservableValue connnectionNameObservable = WidgetProperties.selection().observe(connectionSelectionComboViewer.getCombo());
// pre-select with first connection
if (!connectionNames.isEmpty()) {
model.setConnectionName(connectionNames.get(0));
}
// error message
final Composite errorContainer = new Composite(container, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).span(COLUMNS, 1).grab(true, true).applyTo(errorContainer);
GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(2).applyTo(errorContainer);
final Label errorMessageIcon = new Label(errorContainer, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(20, SWT.DEFAULT).applyTo(errorMessageIcon);
final Label errorMessageLabel = new Label(errorContainer, SWT.NONE);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(errorMessageLabel);
dbc.bindValue(connnectionNameObservable, BeanProperties.value(ImageBuildDialogModel.class, ImageBuildDialogModel.CONNECTION_NAME).observe(model));
final ISWTObservableValue repoNameObservable = WidgetProperties.text(SWT.Modify).observe(repoNameText);
dbc.bindValue(repoNameObservable, BeanProperties.value(ImageBuildDialogModel.class, ImageBuildDialogModel.REPO_NAME).observe(model));
// must be called after bindings were set
setupValidationSupport(errorMessageIcon, errorMessageLabel);
return container;
}
Aggregations