List of usage examples for org.eclipse.jface.fieldassist ContentProposal getContent
@Override
public String getContent()
From source file:de.ovgu.featureide.fm.ui.editors.ConstraintContentProposalProvider.java
License:Open Source License
/** * @return all possible feature names or junctors. * @param words/*from w w w. ja v a2s .c o m*/ * current and previous word of edited string * @param contents * complete string being edited * */ private List<ContentProposal> getProposalList(String[] words, String contents) { List<ContentProposal> proposalList = new ArrayList<ContentProposal>(); boolean caught = false; for (String feature : features) { if (Operator.isOperatorName(feature) || (feature.contains(" ") && feature.toLowerCase() .startsWith(contents.substring(contents.lastIndexOf('"') + 1).toLowerCase()))) { proposalList.add(new ContentProposal("\"" + feature + "\"")); caught = true; } } if (!caught) { if (words[CURRENT].equals("(") || words[CURRENT].equals(" ") || words[CURRENT].equals("")) { proposalList = getProposalList(words[LAST], features); } else { for (ContentProposal proposal : getProposalList(words[LAST], features)) { if (proposal.getContent().length() > words[CURRENT].trim().length() && proposal.getContent() .substring(0, words[CURRENT].trim().length()).equalsIgnoreCase(words[CURRENT].trim())) { proposalList.add(proposal); } } } } return proposalList; }
From source file:org.dawnsci.common.widgets.celleditor.ExpressionFunctionProposalProvider.java
License:Open Source License
@Override public IContentProposal[] getProposals(String contents, int position) { lastPosition = position;/*from w w w . jav a 2 s.c o m*/ //empty string if (contents.isEmpty()) { Set<String> keys = proposalMap.keySet(); IContentProposal[] proposals = new ContentProposal[keys.size()]; int i = 0; for (String key : keys) { proposals[i++] = new ContentProposal(key); } return proposals; } //last with colon String sub = contents.substring(0, position); Matcher m = functionp.matcher(sub); String last = null; int lastEnd = 0; while (m.find()) { last = m.group(); lastMatchBounds[0] = m.start(); lastMatchBounds[1] = m.end(); lastEnd = m.end(); } if (last == null || lastEnd != position) { m = namespacep.matcher(sub); while (m.find()) { last = m.group(); lastEnd = m.end(); lastMatchBounds[0] = m.start(); lastMatchBounds[1] = m.end(); } if (last != null && lastEnd == position) { Set<String> keys = proposalMap.keySet(); List<IContentProposal> content = new ArrayList<IContentProposal>(); for (String key : keys) { if (key.startsWith(last)) content.add(new ContentProposal(key)); } return content.toArray(new IContentProposal[content.size()]); } else { Set<String> keys = proposalMap.keySet(); IContentProposal[] content = new IContentProposal[keys.size()]; int i = 0; for (String key : keys) content[i++] = new ContentProposal(key); return content; } } String[] strArray = last.split(":"); if (strArray.length == 2) { List<ContentProposal> contentList = proposalMap.get(strArray[0]); if (contentList == null) return new IContentProposal[] { new ContentProposal("") }; List<IContentProposal> content = new ArrayList<IContentProposal>(); for (ContentProposal prop : contentList) { if (prop.getContent().startsWith(strArray[1])) content.add(prop); } return content.toArray(new IContentProposal[content.size()]); } else if (strArray.length == 1) { List<ContentProposal> contentList = proposalMap.get(strArray[0]); if (contentList == null) return new IContentProposal[] { new ContentProposal("") }; return contentList.toArray(new IContentProposal[contentList.size()]); } return new IContentProposal[] { new ContentProposal("") }; }
From source file:org.wso2.developerstudio.eclipse.gmf.esb.diagram.custom.configure.ui.EvaluatorExpressionEditorDialog.java
License:Apache License
/** * Create contents of the dialog.//w w w. java 2 s . co m * * @param parent */ protected Control createDialogArea(Composite parent) { Composite container = (Composite) super.createDialogArea(parent); container.setLayout(new GridLayout(1, false)); Label lblEvaluatorExpression = new Label(container, SWT.NONE); lblEvaluatorExpression.setText("Evaluator Expression"); eETextField = new Text(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL | SWT.MULTI); eETextField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); eETextField.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { saveConfiguration(); } }); String elements[] = { "<match/>", "<and></and>", "<equal/>", "<or></or>", "<not></not>" }; try { SimpleContentProposalProvider provider = new SimpleContentProposalProvider(elements); char[] autoActivationCharacters = new char[] { '<', '>' }; org.eclipse.jface.bindings.keys.KeyStroke keyStroke; keyStroke = org.eclipse.jface.bindings.keys.KeyStroke.getInstance("Ctrl+Space"); ContentProposalAdapter adapter = new ContentProposalAdapter(eETextField, new TextContentAdapter(), provider, keyStroke, autoActivationCharacters); adapter.setLabelProvider(new ILabelProvider() { public void removeListener(ILabelProviderListener arg0) { } public boolean isLabelProperty(Object arg0, String arg1) { return false; } public void dispose() { } public void addListener(ILabelProviderListener arg0) { } public String getText(Object obj) { ContentProposal cp = (ContentProposal) obj; String text = ""; if (!cp.getContent().contains("/>")) { text = cp.getContent().substring(0, cp.getContent().lastIndexOf("/") - 1); } else { text = cp.getContent().substring(0, cp.getContent().lastIndexOf("/")) + ">"; } return text; } public Image getImage(Object obj) { return null; } }); } catch (Exception e) { // TODO: handle exception } loadConfiguration(); return container; }