use of org.eclipse.jface.fieldassist.IContentProposal in project tdi-studio-se by Talend.
the class JSONXPathProposalProvider method getProposals4XPath.
/**
* DOC cmeng Comment method "getProposals4XPath".
*
* @param contents
* @param position
* @return
*/
private IContentProposal[] getProposals4XPath(String contents, int position) {
int nodeFieldMax = 500;
int nodeLoopMax = 3000;
int nodeLoopNumberLimit = 10;
int nodeFieldNumberLimit = 10;
int currentNodeNumber = 0;
List<IContentProposal> proposals = new ArrayList<IContentProposal>();
String beforeCursorExp = null;
boolean isRelativeExpression = !contents.trim().startsWith(SLASH);
if (isRelativeTable && isRelativeExpression) {
// beforeCursorExp = linker.getCurrentLoopXPath() + SLASH + contents;
beforeCursorExp = contents;
} else {
beforeCursorExp = contents.substring(0, position);
}
int lastIndexSlash = beforeCursorExp.lastIndexOf(SLASH);
int lastIndexPipe = beforeCursorExp.lastIndexOf(PIPE);
String currentExpr = null;
if (isRelativeTable && isRelativeExpression) {
currentExpr = beforeCursorExp;
}
if (lastIndexSlash == -1 || lastIndexSlash < lastIndexPipe && lastIndexPipe != -1) {
currentExpr = EMPTY_STRING;
} else if (lastIndexPipe < lastIndexSlash && lastIndexPipe != -1) {
currentExpr = beforeCursorExp.substring(lastIndexPipe + 1, lastIndexSlash + 1);
} else if (lastIndexSlash != -1) {
currentExpr = beforeCursorExp.substring(0, lastIndexSlash + 1);
// currentExpr = beforeCursorExp;
} else {
currentExpr = beforeCursorExp;
}
currentExpr = currentExpr.trim();
String currentWord = extractLastWord(beforeCursorExp);
boolean expressionIsEmpty = currentExpr.trim().length() == 0;
// String xPathExpression =
//
// // + " | " +
// createXPathExpression(beforeCursorExp)
// ;
// System.out.println("#############################");
// System.out.println("currentExpr='" + currentExpr + "'");
// System.out.println("beforeCursorExp='"+beforeCursorExp+"'");
// System.out.println("currentWord='"+currentWord+"'");
// System.out.println("1");
ArrayList<Node> allLoopNodes = linker.getAllLoopNodes();
boolean resultsMayBeIncomplete = false;
boolean breakAll = false;
Set<String> alreadyAdded = new HashSet<String>();
//
if (isRelativeTable && (isRelativeExpression || expressionIsEmpty)) {
int allNodesLoopSize = allLoopNodes.size();
// System.out.println("nodeLoop size list : " + allNodesLoopSize);
currentNodeNumber += allNodesLoopSize;
if (allNodesLoopSize > nodeLoopMax) {
resultsMayBeIncomplete = true;
} else {
int nodeLoopNumberOfLoop = allNodesLoopSize;
if (allNodesLoopSize > nodeLoopNumberLimit) {
nodeLoopNumberOfLoop = nodeLoopNumberLimit;
resultsMayBeIncomplete = true;
}
for (int i = 0; i < nodeLoopNumberOfLoop; i++) {
Node nodeLoop = allLoopNodes.get(i);
// System.out.println("nodeLoop : " + i);
List<Node> nodeList = null;
try {
nodeList = this.linker.getNodeRetriever().retrieveNodeListFromNode(modifyXpathToSearchAllChildren(currentExpr, true), nodeLoop);
} catch (XPathExpressionException e) {
ExceptionHandler.process(e);
}
if (nodeList != null && nodeList.size() == 0) {
try {
nodeList = linker.getNodeRetriever().retrieveNodeListFromNode(modifyXpathToSearchAllChildren(beforeCursorExp, true), nodeLoop);
} catch (XPathExpressionException e) {
ExceptionHandler.process(e);
}
}
if (nodeList != null) {
int allNodesFieldsLoopSize = nodeList.size();
currentNodeNumber += allNodesFieldsLoopSize;
if (allNodesFieldsLoopSize > nodeFieldMax) {
resultsMayBeIncomplete = true;
breakAll = true;
} else {
int nodeFieldNumberOfLoop = allNodesFieldsLoopSize;
if (allNodesFieldsLoopSize > nodeFieldMax) {
nodeFieldNumberOfLoop = nodeFieldNumberLimit;
resultsMayBeIncomplete = true;
}
for (int j = 0; j < nodeFieldNumberOfLoop; ++j) {
// System.out.println("nodeField : " + j);
Node node = nodeList.get(j);
String nodeName = node.getNodeName();
String absoluteXPathFromNode = linker.getNodeRetriever().getAbsoluteXPathFromNode(node);
if ((currentWord.length() > 0 && nodeName.startsWith(currentWord) || currentWord.length() == 0 || currentWord.equals(//$NON-NLS-1$
"/")) && !alreadyAdded.contains(absoluteXPathFromNode)) {
XPathContentProposal contentProposal = new XPathContentProposal(node);
if (isRelativeTable && isRelativeExpression) {
contentProposal.setRelative(isRelativeTable);
contentProposal.setFirstRelativeNode(contents.indexOf(SLASH) == -1);
}
proposals.add(contentProposal);
alreadyAdded.add(absoluteXPathFromNode);
}
}
// for (int j = 0; j < nodeListLength; ++j) {
}
if (breakAll) {
break;
}
}
// if (nodeList != null) {
}
// for (int i = 0; i < lstSize; i++) {
}
// } else {
}
// if (!estimationError) {
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////////////////////////
// XPath requests for absolute XPath
//
List<Node> nodeList = null;
if (!expressionIsEmpty) {
try {
nodeList = this.linker.getNodeRetriever().retrieveNodeList(modifyXpathToSetFirstAscendant(currentExpr));
} catch (XPathExpressionException e) {
ExceptionHandler.process(e);
}
}
if (nodeList != null || expressionIsEmpty) {
if (!expressionIsEmpty && nodeList.size() > nodeLoopMax) {
resultsMayBeIncomplete = true;
} else {
try {
nodeList = this.linker.getNodeRetriever().retrieveNodeList(modifyXpathToSearchAllChildren(currentExpr, false));
} catch (XPathExpressionException e) {
ExceptionHandler.process(e);
}
}
if (nodeList != null) {
for (int j = 0; j < nodeList.size(); ++j) {
// System.out.println("nodeField : " + j);
Node node = nodeList.get(j);
String nodeName = node.getNodeName();
String absoluteXPathFromNode = linker.getNodeRetriever().getAbsoluteXPathFromNode(node);
if ((currentWord.length() > 0 && nodeName.startsWith(currentWord) || currentWord.length() == 0 || currentWord.equals(//$NON-NLS-1$
"/")) && !alreadyAdded.contains(absoluteXPathFromNode)) {
// System.out.println(absoluteXPathFromNode);
XPathContentProposal contentProposal = new XPathContentProposal(node);
proposals.add(contentProposal);
alreadyAdded.add(absoluteXPathFromNode);
}
}
// for (int j = 0; j < nodeListLength; ++j) {
}
// if (nodeList != null) {
}
if (resultsMayBeIncomplete) {
addTooManyNodesContentProposal(proposals);
}
IContentProposal[] res = new IContentProposal[proposals.size()];
res = proposals.toArray(res);
return res;
}
use of org.eclipse.jface.fieldassist.IContentProposal in project tdi-studio-se by Talend.
the class ExpressionProposalProvider method getProposals.
@Override
public IContentProposal[] getProposals(String contents, int position) {
List<IContentProposal> proposals = new ArrayList<IContentProposal>();
proposals.addAll(proposalsInside);
for (IContentProposalProvider contentProposalProvider : otherContentProposalProviders) {
proposals.addAll(Arrays.asList(contentProposalProvider.getProposals(contents, position)));
}
IContentProposal[] res = new IContentProposal[proposals.size()];
res = proposals.toArray(res);
return res;
}
use of org.eclipse.jface.fieldassist.IContentProposal in project tdi-studio-se by Talend.
the class TalendCompletionProposalComputer method computeCompletionProposals.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#computeCompletionProposals(org.eclipse.jdt.ui.text
* .java.ContentAssistInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
public List computeCompletionProposals(ITextViewer textViewer, String prefix, int offset, IProgressMonitor monitor) {
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
IProcess process = service.getCurrentProcess();
if (process == null) {
return Collections.EMPTY_LIST;
}
// Compute the length of replacement for proposal. See bug 0004266: Replace value with context value using
// CTRL+Space.
int replacementLength = textViewer.getSelectedRange().y;
if (replacementLength == 0) {
replacementLength = prefix.length();
}
// Proposals based on process context
List<IContextParameter> ctxParams = process.getContextManager().getDefaultContext().getContextParameterList();
for (IContextParameter ctxParam : ctxParams) {
String display = CONTEXT_PREFIX + ctxParam.getName();
String code = getContextContent(ctxParam);
String description = getContextDescription(ctxParam, display);
String ctxName = ctxParam.getName();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.CONTEXT);
proposals.add(proposal);
} else if (prefix.equals("") || ctxName.startsWith(prefix)) {
//$NON-NLS-1$
if (code.startsWith(CONTEXT_PREFIX)) {
code = code.replaceFirst(CONTEXT_PREFIX, "");
}
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.CONTEXT_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.CONTEXT);
proposals.add(proposal);
}
}
// Proposals based on global variables
List<? extends INode> nodes = process.getGraphicalNodes();
for (INode node : nodes) {
List<? extends INodeReturn> nodeReturns = node.getReturns();
for (INodeReturn nodeReturn : nodeReturns) {
//$NON-NLS-1$
String display = node.getLabel() + "." + nodeReturn.getName();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
String code = getNodeReturnContent(nodeReturn, node);
String description = getNodeReturnDescription(nodeReturn, node, display);
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), CoreImageProvider.getComponentIcon(node.getComponent(), ICON_SIZE.ICON_16), display, null, description);
proposal.setType(TalendCompletionProposal.NODE_RETURN);
proposals.add(proposal);
}
}
}
// Proposals based on global variables(only perl ).
// add proposals on global variables in java (bugtracker 2554)
// add variables in java
IContentProposal[] javavars = JavaGlobalUtils.getProposals();
for (IContentProposal javavar : javavars) {
String display = javavar.getLabel();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
String code = javavar.getContent();
String description = getGlobalVarDescription(javavar, display);
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.PROCESS_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.VARIABLE);
proposals.add(proposal);
}
}
FunctionManager functionManager = new FunctionManager();
List<TalendType> talendTypes = functionManager.getTalendTypes();
for (TalendType type : talendTypes) {
for (Object objectFunction : type.getFunctions()) {
Function function = (Function) objectFunction;
//$NON-NLS-1$
String display = function.getCategory() + "." + function.getName();
if (prefix.equals("") || display.startsWith(prefix)) {
//$NON-NLS-1$
String code = FunctionManager.getFunctionMethod(function);
String description = getFunctionDescription(function, display, code);
TalendCompletionProposal proposal = new TalendCompletionProposal(code, offset - prefix.length(), replacementLength, code.length(), ImageProvider.getImage(ECoreImage.ROUTINE_ICON), display, null, description);
proposal.setType(TalendCompletionProposal.ROUTINE);
proposals.add(proposal);
}
}
}
for (IExternalProposals externalProposals : ProposalFactory.getInstances()) {
proposals.addAll(externalProposals.getAdvancedProposals(offset, prefix));
}
return proposals;
}
use of org.eclipse.jface.fieldassist.IContentProposal in project tdi-studio-se by Talend.
the class ExpressionProposalProvider method getProposals.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.fieldassist.IContentProposalProvider#getProposals(java.lang.String, int)
*/
public IContentProposal[] getProposals(String contents, int position) {
List<IContentProposal> proposals = new ArrayList<IContentProposal>();
TableEntryLocation sourceEntryLocation = new TableEntryLocation();
for (IDataMapTable table : this.tables) {
List<IColumnEntry> dataMapTableEntries = table.getColumnEntries();
for (IColumnEntry entrySource : dataMapTableEntries) {
sourceEntryLocation.tableName = entrySource.getParentName();
sourceEntryLocation.columnName = entrySource.getName();
if (mapperManager.getUiManager().checkSourceLocationIsValid(entrySource, currentModifiedEntry)) {
proposals.add(new EntryContentProposal(entrySource, this.currentLanguage));
}
}
// for the globalMap
if (table instanceof InputTable) {
InputTable inputTable = (InputTable) table;
List<GlobalMapEntry> globalMapEntries = inputTable.getGlobalMapEntries();
for (GlobalMapEntry entry : globalMapEntries) {
proposals.add(new EntryContentProposal(entry, this.currentLanguage));
}
}
}
for (IContentProposalProvider contentProposalProvider : otherContentProposalProviders) {
proposals.addAll(Arrays.asList(contentProposalProvider.getProposals(contents, position)));
}
IContentProposal[] res = new IContentProposal[proposals.size()];
res = proposals.toArray(res);
return res;
}
use of org.eclipse.jface.fieldassist.IContentProposal 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);
toolkit.createLabel(composite, "Declarative Services:");
cmbComponents = new Combo(composite, SWT.READ_ONLY);
// 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);
// Decorator for the Components combo
ControlDecoration decorComponents = new ControlDecoration(cmbComponents, SWT.LEFT | SWT.CENTER, composite);
decorComponents.setImage(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage());
decorComponents.setMarginWidth(3);
decorComponents.setDescriptionText("Use Java annotations to detect Declarative Service Components.");
decorComponents.setShowOnlyOnFocus(false);
decorComponents.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);
}
});
}
});
cmbComponents.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
lock.ifNotModifying(new Runnable() {
@Override
public void run() {
ComponentChoice old = componentChoice;
int index = cmbComponents.getSelectionIndex();
if (index >= 0 && index < ComponentChoice.values().length) {
componentChoice = ComponentChoice.values()[cmbComponents.getSelectionIndex()];
if (old != componentChoice) {
addDirtyProperty(aQute.bnd.osgi.Constants.SERVICE_COMPONENT);
addDirtyProperty(aQute.bnd.osgi.Constants.DSANNOTATIONS);
if (old == null) {
cmbComponents.remove(ComponentChoice.values().length);
}
}
}
}
});
}
});
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);
cmbComponents.setLayoutData(gd);
}
Aggregations