use of org.eclipse.jface.fieldassist.TextContentAdapter in project bndtools by bndtools.
the class GeneralInfoPart method createSection.
private void createSection(Section section, FormToolkit toolkit) {
section.setText("Basic Information");
KeyStroke assistKeyStroke = null;
try {
assistKeyStroke = KeyStroke.getInstance("Ctrl+Space");
} catch (ParseException x) {
// Ignore
}
FieldDecoration contentAssistDecoration = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
Composite composite = toolkit.createComposite(section);
section.setClient(composite);
toolkit.createLabel(composite, "Version:");
txtVersion = toolkit.createText(composite, "", SWT.BORDER);
ToolTips.setupMessageAndToolTipFromSyntax(txtVersion, Constants.BUNDLE_VERSION);
Hyperlink linkActivator = toolkit.createHyperlink(composite, "Activator:", SWT.NONE);
txtActivator = toolkit.createText(composite, "", SWT.BORDER);
ToolTips.setupMessageAndToolTipFromSyntax(txtActivator, Constants.BUNDLE_ACTIVATOR);
// Content Proposal for the Activator field
ContentProposalAdapter activatorProposalAdapter = null;
ActivatorClassProposalProvider proposalProvider = new ActivatorClassProposalProvider();
activatorProposalAdapter = new ContentProposalAdapter(txtActivator, new TextContentAdapter(), proposalProvider, assistKeyStroke, UIConstants.autoActivationCharacters());
activatorProposalAdapter.addContentProposalListener(proposalProvider);
activatorProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
activatorProposalAdapter.setLabelProvider(new JavaContentProposalLabelProvider());
activatorProposalAdapter.setAutoActivationDelay(1000);
// Decorator for the Activator field
ControlDecoration decorActivator = new ControlDecoration(txtActivator, SWT.LEFT | SWT.CENTER, composite);
decorActivator.setImage(contentAssistDecoration.getImage());
decorActivator.setMarginWidth(3);
if (assistKeyStroke == null) {
decorActivator.setDescriptionText("Content Assist is available. Start typing to activate");
} else {
decorActivator.setDescriptionText(MessageFormat.format("Content Assist is available. Press {0} or start typing to activate", assistKeyStroke.format()));
}
decorActivator.setShowOnlyOnFocus(true);
decorActivator.setShowHover(true);
// Listeners
txtVersion.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
addDirtyProperty(Constants.BUNDLE_VERSION);
}
});
}
});
txtActivator.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent ev) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
addDirtyProperty(Constants.BUNDLE_ACTIVATOR);
}
});
}
});
linkActivator.addHyperlinkListener(new HyperlinkAdapter() {
@Override
public void linkActivated(HyperlinkEvent ev) {
String activatorClassName = txtActivator.getText();
if (activatorClassName != null && activatorClassName.length() > 0) {
try {
IJavaProject javaProject = getJavaProject();
if (javaProject == null)
return;
IType activatorType = javaProject.findType(activatorClassName);
if (activatorType != null) {
JavaUI.openInEditor(activatorType, true, true);
}
} catch (PartInitException e) {
ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error opening an editor for activator class '{0}'.", activatorClassName), e));
} catch (JavaModelException e) {
ErrorDialog.openError(getManagedForm().getForm().getShell(), "Error", null, new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, MessageFormat.format("Error searching for activator class '{0}'.", activatorClassName), e));
}
}
}
});
activatorProposalAdapter.addContentProposalListener(new IContentProposalListener() {
@Override
public void proposalAccepted(IContentProposal proposal) {
if (proposal instanceof JavaContentProposal) {
String selectedPackageName = ((JavaContentProposal) proposal).getPackageName();
if (!model.isIncludedPackage(selectedPackageName)) {
model.addPrivatePackage(selectedPackageName);
}
}
}
});
// Layout
GridLayout layout = new GridLayout(2, false);
layout.horizontalSpacing = 15;
composite.setLayout(layout);
GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false);
txtVersion.setLayoutData(gd);
txtActivator.setLayoutData(gd);
}
use of org.eclipse.jface.fieldassist.TextContentAdapter in project tdi-studio-se by Talend.
the class TalendEditorComponentCreationAssist method createAssistText.
private void createAssistText(org.eclipse.swt.graphics.Point cursorRelativePosition) {
// disable key event filter on Display
if (bindingService != null) {
bindingService.setKeyFilterEnabled(false);
}
highlightOveredConnection(cursorRelativePosition);
// create assist input text
assistText = new Text((Composite) graphicControl, SWT.BORDER);
assistText.setLocation(cursorRelativePosition.x, cursorRelativePosition.y - assistText.getLineHeight());
assistText.setSize(200, assistText.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
assistText.setFocus();
/*
* create the proposal by using available components list
*/
// TODO the trigger way may need improved, currently, any visible character will trigger it
// TalendEditorComponentProposalProvider proposalProvider = new
// TalendEditorComponentProposalProvider(components);
TalendEditorComponentProposalProvider proposalProvider = new TalendEditorComponentProposalProvider(this, proposalList);
contentProposalAdapter = new ContentProposalAdapter(assistText, new TextContentAdapter(), proposalProvider, null, null);
contentProposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
contentProposalAdapter.setLabelProvider(new TalendEditorComponentLabelProvider());
}
use of org.eclipse.jface.fieldassist.TextContentAdapter 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.TextContentAdapter in project hale by halestudio.
the class SQLSchemaPage method createContent.
@Override
protected void createContent(Composite page) {
GridLayoutFactory.swtDefaults().numColumns(2).applyTo(page);
GridDataFactory labelFactory = GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER);
// type name
Label typeLabel = new Label(page, SWT.NONE);
labelFactory.applyTo(typeLabel);
typeLabel.setText("Query name:");
typeName = new Text(page, SWT.SINGLE | SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(typeName);
typeName.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateState(false);
}
});
// SQL query
Label sqlLabel = new Label(page, SWT.NONE);
labelFactory.applyTo(sqlLabel);
sqlLabel.setText("SQL query:");
sqlQuery = new Text(page, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
GridDataFactory.fillDefaults().grab(true, true).applyTo(sqlQuery);
sqlQuery.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
updateState(false);
}
});
ContentProposalAdapter adapter = new ContentProposalAdapter(sqlQuery, new TextContentAdapter(), contentProposalProvider, ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
adapter.setAutoActivationDelay(0);
final ControlDecoration infoDeco = new ControlDecoration(sqlQuery, SWT.TOP | SWT.LEFT);
infoDeco.setDescriptionText("Type Ctrl+Space for project variable content assistance");
infoDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
infoDeco.setShowOnlyOnFocus(true);
// button for testing query
Button button = new Button(page, SWT.BORDER | SWT.FLAT);
GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).span(2, 1).applyTo(button);
button.setImage(CommonSharedImages.getImageRegistry().get(CommonSharedImages.IMG_PLAY));
button.setText("Test query");
button.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateState(true);
}
});
updateState(false);
}
use of org.eclipse.jface.fieldassist.TextContentAdapter in project hale by halestudio.
the class RegexAnalysisParameterPage method createContent.
/**
* @see eu.esdihumboldt.hale.ui.HaleWizardPage#createContent(org.eclipse.swt.widgets.Composite)
*/
@Override
protected void createContent(Composite page) {
this.page = page;
page.setLayout(GridLayoutFactory.swtDefaults().numColumns(1).create());
if (getWizard().getUnfinishedCell().getTarget() != null) {
PropertyDefinition propDef = (PropertyDefinition) getWizard().getUnfinishedCell().getTarget().values().iterator().next().getDefinition().getDefinition();
if (!propDef.equals(target)) {
String regexTooltip = "A regular expression containing groups (see http://www.javamex.com/tutorials/regular_expressions/capturing_groups.shtml). Press Ctrl+Space for project variable content assistance.";
Group regexGroup = new Group(page, SWT.NONE);
regexGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
regexGroup.setLayout(new GridLayout(1, false));
regexGroup.setText("Regular Expression");
regexGroup.setToolTipText(regexTooltip);
_regexText = new Text(regexGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
_regexText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
_regexText.setText("");
_regexText.addModifyListener(this);
final ControlDecoration regexInfoDeco = new ControlDecoration(_regexText, SWT.TOP | SWT.LEFT);
regexInfoDeco.setDescriptionText(regexTooltip);
regexInfoDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
regexInfoDeco.setMarginWidth(2);
ContentProposalAdapter regexTextAdapter = new ContentProposalAdapter(_regexText, new TextContentAdapter(), new ProjectVariablesContentProposalProvider(true), ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
regexTextAdapter.setAutoActivationDelay(0);
String formatTooltip = "The output format to apply, containing curly brackets delimited group definitions. Ex. {1} represents the result of group 1 from the regex analysis. Press Ctrl+Space for project variable content assistance.";
Group outformatGroup = new Group(page, SWT.NONE);
outformatGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
outformatGroup.setLayout(new GridLayout(1, false));
outformatGroup.setText("Output format");
outformatGroup.setToolTipText(formatTooltip);
_outformatText = new Text(outformatGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
_outformatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
_outformatText.setText("");
_outformatText.addModifyListener(this);
final ControlDecoration formatInfoDeco = new ControlDecoration(_outformatText, SWT.TOP | SWT.LEFT);
formatInfoDeco.setDescriptionText(formatTooltip);
formatInfoDeco.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
formatInfoDeco.setMarginWidth(2);
ContentProposalAdapter outformatAdapter = new ContentProposalAdapter(_outformatText, new TextContentAdapter(), new ProjectVariablesContentProposalProvider(true), ProjectVariablesContentProposalProvider.CTRL_SPACE, new char[] { '{' });
outformatAdapter.setAutoActivationDelay(0);
Group exampleGroup = new Group(page, SWT.NONE);
exampleGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
exampleGroup.setLayout(new GridLayout(3, false));
exampleGroup.setText("Example");
Label inputLabel = new Label(exampleGroup, SWT.NONE);
inputLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
inputLabel.setText("Sample text");
_inputText = new Text(exampleGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
_inputText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
_inputText.setText("");
Button testButton = new Button(exampleGroup, SWT.PUSH);
GridData testButtonGD = new GridData(SWT.FILL, SWT.FILL, false, false);
testButtonGD.verticalSpan = 2;
testButton.setLayoutData(testButtonGD);
testButton.setText("Test");
Label outputLabel = new Label(exampleGroup, SWT.NONE);
outputLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
outputLabel.setText("Sample result");
final Text outputText = new Text(exampleGroup, SWT.SINGLE | SWT.LEAD | SWT.BORDER);
outputText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
outputText.setText("");
testButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String convertedString = "No match found.";
try {
String regex = new TransformationVariableReplacer().replaceVariables(_regexText.getText());
String outformat = new TransformationVariableReplacer().replaceVariables(_outformatText.getText());
convertedString = RegexAnalysis.analize(regex, outformat, _inputText.getText());
outputText.setText(convertedString);
} catch (Exception e1) {
outputText.setText(e1.getCause().getLocalizedMessage());
}
}
});
}
}
if (_regexText != null && initialRegexValue != null) {
_regexText.setText(initialRegexValue.as(String.class));
}
if (_outformatText != null && initialOutformatValue != null) {
_outformatText.setText(initialOutformatValue.as(String.class));
}
}
Aggregations