use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project jbosstools-hibernate by jbosstools.
the class HBMInfoExtractor method generateTypeProposals.
void generateTypeProposals(String matchString, int offset, List proposals, Set alreadyFound, IType[] classes, String filterPackage) throws JavaModelException {
for (int j = 0; j < classes.length; j++) {
IType type = classes[j];
if (!Flags.isAbstract(type.getFlags()) && (filterPackage == null || !type.getFullyQualifiedName().startsWith(filterPackage))) {
String fullName = type.getFullyQualifiedName();
String shortName = type.getElementName();
if (alreadyFound.contains(fullName)) {
continue;
} else {
alreadyFound.add(fullName);
}
if (beginsWith(fullName, matchString) || beginsWith(shortName, matchString)) {
CustomCompletionProposal proposal = new CustomCompletionProposal(fullName, offset, matchString.length(), fullName.length() + 1, null, /*XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE)*/
fullName, null, null, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
proposals.add(proposal);
}
}
}
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class JSPELCompletionProposalComputer method getFunctionProposals.
/**
* <p>Get the EL function proposals, ex: ${fn:| }</p>
* @param prefix
* @param viewer
* @param offset
* @return
*/
private List getFunctionProposals(String prefix, ITextViewer viewer, int offset) {
TLDCMDocumentManager docMgr = TaglibController.getTLDCMDocumentManager(viewer.getDocument());
ArrayList completionList = new ArrayList();
if (docMgr == null)
return null;
Iterator taglibs = docMgr.getCMDocumentTrackers(offset).iterator();
while (taglibs.hasNext()) {
TaglibTracker tracker = (TaglibTracker) taglibs.next();
if (tracker.getPrefix().equals(prefix)) {
CMDocumentImpl doc = (CMDocumentImpl) tracker.getDocument();
List functions = doc.getFunctions();
for (Iterator it = functions.iterator(); it.hasNext(); ) {
TLDFunction function = (TLDFunction) it.next();
CustomCompletionProposal proposal = new // $NON-NLS-1$
CustomCompletionProposal(// $NON-NLS-1$
function.getName() + "()", offset, 0, function.getName().length() + 1, null, function.getName() + " - " + function.getSignature(), null, null, // $NON-NLS-1$
1);
completionList.add(proposal);
}
}
}
return completionList;
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class JSDTHtmlCompletionProcessor method getEndScriptProposal.
public ICompletionProposal getEndScriptProposal(ITextViewer viewer, int offset) {
/* add </script if necisary */
IJsTranslation tran = getJSPTranslation(viewer);
if (tran == null)
return null;
int missingAtOffset = tran.getMissingTagStart();
if (offset >= missingAtOffset && missingAtOffset > -1) {
String allText = viewer.getDocument().get();
// $NON-NLS-1$
String text = "</script>";
int startInTag = -1;
for (int i = 0; i < text.length() && allText.length() > offset - 1; i++) {
if (allText.charAt(offset - 1) == text.charAt(i)) {
startInTag = i;
break;
}
}
if (startInTag == -1) {
// $NON-NLS-1$
String displayText = Messages.getString("JSDTHtmlCompletionProcessor.1");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return new CustomCompletionProposal("\n" + text + "\n", offset, 0, offset, null, displayText, null, Messages.getString("JSDTHtmlCompletionProcessor.4"), 100);
}
String text1 = allText.substring(offset - startInTag - 1, offset).toLowerCase();
String text2 = text.substring(0, startInTag + 1).toLowerCase();
if (startInTag > -1 && text2.compareTo(text1) == 0) {
// $NON-NLS-1$
String displayText = Messages.getString("JSDTHtmlCompletionProcessor.5");
// $NON-NLS-1$
return new CustomCompletionProposal(text, offset - startInTag - 1, 0, text.length(), null, displayText, null, Messages.getString("JSDTHtmlCompletionProcessor.6"), 100);
}
}
return null;
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class JSPPropertyCompletionProposalComputer method addBeanNameProposals.
/**
* <p>Add bean name propoasals to the given {@link ContentAssistRequest}</p>
*
* @param contentAssistRequest
* @param node
* @param matchString
*/
private void addBeanNameProposals(ContentAssistRequest contentAssistRequest, IDOMNode node, String matchString) {
// will not catch useBeans specified using other than actual DOM Nodes
NodeList useBeans = node.getOwnerDocument().getElementsByTagName(JSP11Namespace.ElementName.USEBEAN);
if (useBeans != null) {
// $NON-NLS-1$
String id = "";
String displayString = null;
String classOrType = null;
String imageName = JSPEditorPluginImages.IMG_OBJ_CLASS_OBJ;
for (int j = 0; j < useBeans.getLength(); j++) {
if (useBeans.item(j).getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element useBean = (Element) useBeans.item(j);
if (useBean instanceof IndexedRegion && ((IndexedRegion) useBean).getStartOffset() < node.getStartOffset() && useBean.hasAttribute(JSP11Namespace.ATTR_NAME_ID)) {
id = useBean.hasAttribute(JSP11Namespace.ATTR_NAME_ID) ? StringUtils.strip(useBean.getAttribute(JSP11Namespace.ATTR_NAME_ID)) : null;
displayString = null;
classOrType = null;
imageName = JSPEditorPluginImages.IMG_OBJ_CLASS_OBJ;
// set the Image based on whether the class, type, or beanName attribute is present
if (useBean.hasAttribute(JSP11Namespace.ATTR_NAME_CLASS))
classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_CLASS);
if ((classOrType == null || classOrType.length() < 1) && useBean.hasAttribute(JSP11Namespace.ATTR_NAME_TYPE)) {
classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_TYPE);
imageName = JSPEditorPluginImages.IMG_OBJ_PUBLIC;
}
if ((classOrType == null || classOrType.length() < 1) && useBean.hasAttribute(JSP11Namespace.ATTR_NAME_BEAN_NAME)) {
classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_BEAN_NAME);
imageName = JSPEditorPluginImages.IMG_OBJ_PUBLIC;
}
if (classOrType != null && classOrType.length() > 0) {
// $NON-NLS-1$
displayString = id + " - " + classOrType;
} else {
displayString = id;
}
// https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=2341
if (id != null) {
// filter
if (matchString.length() == 0 || id.startsWith(matchString)) {
CustomCompletionProposal proposal = new // $NON-NLS-1$ //$NON-NLS-2$
CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + id + "\"", contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), id.length() + 2, JSPEditorPluginImageHelper.getInstance().getImage(imageName), displayString, null, null, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
contentAssistRequest.addProposal(proposal);
}
}
}
}
}
}
use of org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal in project webtools.sourceediting by eclipse.
the class JSPTaglibCompletionProposalComputer method addAttributeValueProposals.
/**
* @see org.eclipse.wst.xml.ui.internal.contentassist.DefaultXMLCompletionProposalComputer#addAttributeValueProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
*/
protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context) {
IPath basePath = getBasePath(contentAssistRequest);
if (basePath != null) {
IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
// only add attribute value proposals for specific elements
if (node.getNodeName().equals(JSP11Namespace.ElementName.DIRECTIVE_TAGLIB)) {
// Find the attribute name for which this position should have a value
IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion();
ITextRegionList openRegions = open.getRegions();
int i = openRegions.indexOf(contentAssistRequest.getRegion());
if (i < 0)
return;
ITextRegion nameRegion = null;
while (i >= 0) {
nameRegion = openRegions.get(i--);
if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)
break;
}
String attributeName = null;
if (nameRegion != null)
attributeName = open.getText(nameRegion);
String currentValue = null;
if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
currentValue = contentAssistRequest.getText();
else
// $NON-NLS-1$
currentValue = "";
String matchString = null;
// fixups
int start = contentAssistRequest.getReplacementBeginPosition();
int length = contentAssistRequest.getReplacementLength();
if (currentValue.length() > StringUtils.strip(currentValue).length() && // $NON-NLS-1$ //$NON-NLS-2$
(currentValue.startsWith("\"") || currentValue.startsWith("'")) && contentAssistRequest.getMatchString().length() > 0) {
matchString = currentValue.substring(1, contentAssistRequest.getMatchString().length());
} else {
matchString = currentValue.substring(0, contentAssistRequest.getMatchString().length());
}
boolean existingComplicatedValue = contentAssistRequest.getRegion() != null && contentAssistRequest.getRegion() instanceof ITextRegionContainer;
if (existingComplicatedValue) {
contentAssistRequest.getProposals().clear();
contentAssistRequest.getMacros().clear();
} else {
String lowerCaseMatch = matchString.toLowerCase(Locale.US);
if (attributeName.equals(JSP11Namespace.ATTR_NAME_URI)) {
ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
/*
* a simple enough way to remove duplicates (resolution at
* runtime would be nondeterministic anyway)
*/
Map uriToRecords = new HashMap();
for (int taglibRecordNumber = 0; taglibRecordNumber < availableTaglibRecords.length; taglibRecordNumber++) {
ITaglibRecord taglibRecord = availableTaglibRecords[taglibRecordNumber];
ITaglibDescriptor descriptor = taglibRecord.getDescriptor();
String uri = null;
switch(taglibRecord.getRecordType()) {
case ITaglibRecord.URL:
uri = descriptor.getURI();
uriToRecords.put(uri, taglibRecord);
break;
case ITaglibRecord.JAR:
{
IPath location = ((IJarRecord) taglibRecord).getLocation();
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
for (int fileNumber = 0; fileNumber < files.length; fileNumber++) {
if (localContextRoot.isPrefixOf(files[fileNumber].getFullPath())) {
uri = IPath.SEPARATOR + files[fileNumber].getFullPath().removeFirstSegments(localContextRoot.segmentCount()).toString();
uriToRecords.put(uri, taglibRecord);
} else {
uri = FacetModuleCoreSupport.getRuntimePath(files[fileNumber].getFullPath()).toString();
uriToRecords.put(uri, taglibRecord);
}
}
break;
}
case ITaglibRecord.TLD:
{
uri = descriptor.getURI();
if (uri == null || uri.trim().length() == 0) {
IPath path = ((ITLDRecord) taglibRecord).getPath();
IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
if (localContextRoot.isPrefixOf(path)) {
uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
} else {
uri = FacetModuleCoreSupport.getRuntimePath(path).toString();
}
}
uriToRecords.put(uri, taglibRecord);
break;
}
}
}
/*
* use the records and their descriptors to construct
* proposals
*/
Object[] uris = uriToRecords.keySet().toArray();
for (int uriNumber = 0; uriNumber < uris.length; uriNumber++) {
String uri = uris[uriNumber].toString();
ITaglibRecord taglibRecord = (ITaglibRecord) uriToRecords.get(uri);
ITaglibDescriptor descriptor = (taglibRecord).getDescriptor();
if (uri != null && uri.length() > 0 && (matchString.length() == 0 || uri.toLowerCase(Locale.US).startsWith(lowerCaseMatch))) {
String url = getSmallImageURL(taglibRecord);
ImageDescriptor imageDescriptor = JSPUIPlugin.getInstance().getImageRegistry().getDescriptor(url);
if (imageDescriptor == null && url != null) {
URL imageURL;
try {
imageURL = new URL(url);
imageDescriptor = ImageDescriptor.createFromURL(imageURL);
JSPUIPlugin.getInstance().getImageRegistry().put(url, imageDescriptor);
} catch (MalformedURLException e) {
Logger.logException(e);
}
}
String additionalInfo = // $NON-NLS-1$
descriptor.getDisplayName() + "<br/>" + descriptor.getDescription() + "<br/>" + // $NON-NLS-1$
descriptor.getTlibVersion();
Image image = null;
try {
image = JSPUIPlugin.getInstance().getImageRegistry().get(url);
} catch (Exception e) {
Logger.logException(e);
}
if (image == null) {
image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
}
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + uri + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
uri.length() + 2, image, uri, null, additionalInfo, IRelevanceConstants.R_NONE);
contentAssistRequest.addProposal(proposal);
}
}
} else if (attributeName.equals(JSP20Namespace.ATTR_NAME_TAGDIR)) {
ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
/*
* a simple enough way to remove duplicates (resolution at
* runtime would be nondeterministic anyway)
*/
Map uriToRecords = new HashMap();
IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
for (int taglibRecordNumber = 0; taglibRecordNumber < availableTaglibRecords.length; taglibRecordNumber++) {
ITaglibRecord taglibRecord = availableTaglibRecords[taglibRecordNumber];
String uri = null;
if (taglibRecord.getRecordType() == ITaglibRecord.TAGDIR) {
IPath path = ((ITagDirRecord) taglibRecord).getPath();
if (localContextRoot.isPrefixOf(path)) {
uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
uriToRecords.put(uri, taglibRecord);
}
}
}
/*
* use the records and their descriptors to construct
* proposals
*/
Object[] uris = uriToRecords.keySet().toArray();
for (int uriNumber = 0; uriNumber < uris.length; uriNumber++) {
String uri = uris[uriNumber].toString();
ITaglibRecord taglibRecord = (ITaglibRecord) uriToRecords.get(uri);
ITaglibDescriptor descriptor = (taglibRecord).getDescriptor();
if (uri != null && uri.length() > 0 && (matchString.length() == 0 || uri.toLowerCase(Locale.US).startsWith(lowerCaseMatch))) {
String url = getSmallImageURL(taglibRecord);
ImageDescriptor imageDescriptor = null;
if (url != null) {
imageDescriptor = JSPUIPlugin.getInstance().getImageRegistry().getDescriptor(url);
}
if (imageDescriptor == null && url != null) {
URL imageURL;
try {
imageURL = new URL(url);
imageDescriptor = ImageDescriptor.createFromURL(imageURL);
JSPUIPlugin.getInstance().getImageRegistry().put(url, imageDescriptor);
} catch (MalformedURLException e) {
Logger.logException(e);
}
}
// $NON-NLS-1$
String additionalInfo = descriptor.getDescription() + "<br/>" + descriptor.getTlibVersion();
Image image = null;
try {
image = JSPUIPlugin.getInstance().getImageRegistry().get(url);
} catch (Exception e) {
Logger.logException(e);
}
if (image == null) {
image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
}
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + uri + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
uri.length() + 2, // $NON-NLS-1$ //$NON-NLS-2$
image, // $NON-NLS-1$ //$NON-NLS-2$
uri, null, additionalInfo, IRelevanceConstants.R_NONE);
contentAssistRequest.addProposal(proposal);
}
}
} else if (attributeName.equals(JSP11Namespace.ATTR_NAME_PREFIX)) {
Node uriAttr = node.getAttributes().getNamedItem(JSP11Namespace.ATTR_NAME_URI);
String uri = null;
if (uriAttr != null) {
uri = uriAttr.getNodeValue();
ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
Map prefixMap = new HashMap();
for (int taglibrecordNumber = 0; taglibrecordNumber < availableTaglibRecords.length; taglibrecordNumber++) {
ITaglibDescriptor descriptor = availableTaglibRecords[taglibrecordNumber].getDescriptor();
if (isTaglibForURI(uri, basePath, availableTaglibRecords[taglibrecordNumber])) {
String shortName = descriptor.getShortName().trim();
if (shortName.length() > 0) {
boolean valid = true;
for (int character = 0; character < shortName.length(); character++) {
valid = valid && !Character.isWhitespace(shortName.charAt(character));
}
if (valid) {
prefixMap.put(shortName, descriptor);
}
}
}
}
Object[] prefixes = prefixMap.keySet().toArray();
for (int j = 0; j < prefixes.length; j++) {
String prefix = (String) prefixes[j];
ITaglibDescriptor descriptor = (ITaglibDescriptor) prefixMap.get(prefix);
Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + prefix + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
prefix.length() + 2, // $NON-NLS-1$ //$NON-NLS-2$
image, prefix, null, descriptor.getDescription(), IRelevanceConstants.R_NONE);
contentAssistRequest.addProposal(proposal);
}
} else {
Node dirAttr = node.getAttributes().getNamedItem(JSP20Namespace.ATTR_NAME_TAGDIR);
if (dirAttr != null) {
String dir = dirAttr.getNodeValue();
if (dir != null) {
ITaglibRecord record = TaglibIndex.resolve(basePath.toString(), dir, false);
if (record != null) {
ITaglibDescriptor descriptor = record.getDescriptor();
if (descriptor != null) {
String shortName = descriptor.getShortName();
Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + shortName + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
shortName.length() + 2, image, shortName, null, descriptor.getDescription(), IRelevanceConstants.R_NONE);
contentAssistRequest.addProposal(proposal);
} else {
if (dir.startsWith("/WEB-INF/")) {
// $NON-NLS-1$
dir = dir.substring(9);
}
// $NON-NLS-1$ //$NON-NLS-2$
String prefix = StringUtils.replace(dir, "/", "-");
Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
"\"" + prefix + "\"", // $NON-NLS-1$ //$NON-NLS-2$
start, // $NON-NLS-1$ //$NON-NLS-2$
length, // $NON-NLS-1$ //$NON-NLS-2$
prefix.length() + 2, image, prefix, null, null, IRelevanceConstants.R_NONE);
contentAssistRequest.addProposal(proposal);
}
}
}
}
}
}
}
}
}
}
Aggregations