use of org.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.
the class SQLCompletionProcessor method getProposalsByNode2.
/**
* DOC dev Comment method "getProposalsByNode2".
*
* @param documentOffset
* @param lastPart
* @param node
* @return
*/
//$NON-NLS-1$
@SuppressWarnings("unchecked")
private ICompletionProposal[] getProposalsByNode2(int documentOffset, String lastPart, INode node) {
String[] proposalsString = dictionary.matchTablePrefix(lastPart.toLowerCase());
ArrayList propList = new ArrayList();
for (int i = 0; i < proposalsString.length; i++) {
ArrayList ls = dictionary.getTableObjectList(proposalsString[i]);
for (int j = 0; j < ls.size(); j++) {
TableNode tbNode = (TableNode) ls.get(j);
Image tmpImage = null;
TableFolderNode totn = (TableFolderNode) tbNode.getParent();
INode catSchema = (INode) totn.getParent();
if (catSchema == node) {
if (tbNode.isView()) {
tmpImage = viewImage;
} else if (tbNode.isTable()) {
tmpImage = tableImage;
}
ICompletionProposal cmp = new ExtendedCompletionProposal(proposalsString[i], documentOffset - lastPart.length(), lastPart.length(), proposalsString[i].length(), tmpImage, proposalsString[i], tbNode);
propList.add(cmp);
}
}
}
ICompletionProposal[] res = new ICompletionProposal[propList.size()];
System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
return res;
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project tdi-studio-se by Talend.
the class SQLCompletionProcessor method computeCompletionProposals.
/**
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
* int)
*/
//$NON-NLS-1$
@SuppressWarnings("unchecked")
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
if (dictionary == null) {
return null;
}
String text = viewer.getDocument().get();
String string = text.substring(0, documentOffset);
if (string.equals("")) {
//$NON-NLS-1$
return null;
}
int position = string.length() - 1;
char character;
while (position > 0) {
character = string.charAt(position);
if (!Character.isJavaIdentifierPart(character) && (character != '.')) {
break;
}
--position;
}
if (position == 0) {
position = -1;
}
string = string.substring(position + 1);
// JFaceDbcPlugin.error("String: "+string,new Exception());
if (string == null || string.equals("")) {
//$NON-NLS-1$
return null;
}
string = string.toLowerCase();
int length = string.length();
if (length < 1) {
return null;
}
//$NON-NLS-1$
int dotIndex = string.lastIndexOf(".");
if (string.charAt(length - 1) == ' ') {
return null;
} else if (string.charAt(length - 1) == '.') {
// Last typed character
// is '.'
String name = string.substring(0, length - 1);
if (name == null) {
return null;
}
//$NON-NLS-1$
int otherDot = name.lastIndexOf(".");
if (otherDot != -1) {
name = name.substring(otherDot + 1);
}
if (name == null || name.equals("")) {
//$NON-NLS-1$
return null;
}
TreeSet st = (TreeSet) dictionary.getColumnListByTableName(name);
if (st != null) {
ArrayList list = (ArrayList) dictionary.getByTableName(name);
if (list == null) {
return null;
}
TableNode nd = null;
if (list.size() == 1) {
nd = (TableNode) list.get(0);
} else {
return null;
}
Object[] obj = st.toArray();
String[] arr = new String[obj.length];
System.arraycopy(obj, 0, arr, 0, obj.length);
ICompletionProposal[] result = new ICompletionProposal[arr.length];
String tableDesc = null;
if (nd != null) {
tableDesc = nd.getTableDesc();
}
for (int i = 0; i < arr.length; i++) {
result[i] = new CompletionProposal(arr[i], documentOffset, 0, arr[i].length(), colImage, arr[i], null, tableDesc);
}
return result;
}
INode node = (INode) dictionary.getByCatalogSchemaName(name);
if (node != null) {
return getProposalsByNode(documentOffset, node);
}
} else if (dotIndex == -1) {
return inputNotContainDot(documentOffset, string, length);
} else if (dotIndex != -1) {
String firstPart = string.substring(0, dotIndex);
//$NON-NLS-1$
int otherDot = firstPart.indexOf(".");
if (otherDot != -1) {
firstPart = firstPart.substring(otherDot + 1);
}
String lastPart = string.substring(dotIndex + 1);
if (//$NON-NLS-1$
lastPart == null || firstPart == null || lastPart.equals("") || firstPart.equals("")) {
//$NON-NLS-1$
return null;
}
TreeSet st = (TreeSet) dictionary.getColumnListByTableName(firstPart);
if (st != null) {
Iterator iter = st.iterator();
ArrayList propList = new ArrayList();
while (iter.hasNext()) {
String colName = (String) iter.next();
int length2 = lastPart.length();
if (colName.length() >= length2) {
if ((colName.substring(0, lastPart.length())).equalsIgnoreCase(lastPart)) {
CompletionProposal cmp = new CompletionProposal(colName, documentOffset - length2, length2, colName.length(), colImage, colName, null, null);
propList.add(cmp);
}
}
}
ICompletionProposal[] res = new ICompletionProposal[propList.size()];
System.arraycopy(propList.toArray(), 0, res, 0, propList.size());
return res;
}
INode node = (INode) dictionary.getByCatalogSchemaName(firstPart);
if (node != null) {
return getProposalsByNode2(documentOffset, lastPart, node);
}
}
return null;
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project bndtools by bndtools.
the class BaselineErrorHandler method getProposals.
@Override
public List<ICompletionProposal> getProposals(IMarker marker) {
List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
int start = marker.getAttribute(IMarker.CHAR_START, 0);
int end = marker.getAttribute(IMarker.CHAR_END, 0);
CompletionProposal proposal = new CompletionProposal("version " + suggestedVersion, start, end - start, end, null, "Change package version to " + suggestedVersion, null, null);
proposals.add(proposal);
return proposals;
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project bndtools by bndtools.
the class BundleVersionErrorHandler method getProposals.
@Override
public List<ICompletionProposal> getProposals(IMarker marker) {
List<ICompletionProposal> result = new LinkedList<ICompletionProposal>();
String suggestedVersion = marker.getAttribute(PROP_SUGGESTED_VERSION, null);
int start = marker.getAttribute(IMarker.CHAR_START, 0);
int end = marker.getAttribute(IMarker.CHAR_END, 0);
CompletionProposal proposal = new CompletionProposal(Constants.BUNDLE_VERSION + ": " + suggestedVersion, start, end - start, end, null, "Change bundle version to " + suggestedVersion, null, null);
result.add(proposal);
return result;
}
use of org.eclipse.jface.text.contentassist.ICompletionProposal in project bndtools by bndtools.
the class BndMarkerQuickAssistProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext context) {
List<ICompletionProposal> proposals = new LinkedList<ICompletionProposal>();
ISourceViewer viewer = context.getSourceViewer();
@SuppressWarnings("unused") IDocument document = viewer.getDocument();
IAnnotationModel model = viewer.getAnnotationModel();
@SuppressWarnings("rawtypes") Iterator iter = model.getAnnotationIterator();
while (iter.hasNext()) {
Annotation annotation = (Annotation) iter.next();
if (annotation instanceof MarkerAnnotation && canFix(annotation)) {
Position position = model.getPosition(annotation);
if (isAtPosition(context.getOffset(), position)) {
IMarker marker = ((MarkerAnnotation) annotation).getMarker();
String errorType = marker.getAttribute("$bndType", null);
if (errorType != null) {
BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(errorType);
if (handler != null) {
proposals.addAll(handler.getProposals(marker));
}
}
}
}
}
if (proposals.isEmpty()) {
proposals.add(new NoCompletionsProposal());
}
return proposals.toArray(new ICompletionProposal[0]);
}
Aggregations