Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 264246 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java (+1 lines)
Lines 118-123 Link Here
118
	public static String JSPFContentSettingsPropertyPage_4;
118
	public static String JSPFContentSettingsPropertyPage_4;
119
	public static String ProjectJSPFContentSettingsPropertyPage_0;
119
	public static String ProjectJSPFContentSettingsPropertyPage_0;
120
	public static String TagPropertyPage_desc;
120
	public static String TagPropertyPage_desc;
121
	public static String Template_Taglib_URI;
121
	public static String Title_InvalidValue;
122
	public static String Title_InvalidValue;
122
	public static String Message_InvalidValue;
123
	public static String Message_InvalidValue;
123
	public static String SyntaxColoringPage_0;
124
	public static String SyntaxColoringPage_0;
(-)src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties (+1 lines)
Lines 167-172 Link Here
167
CustomTagHyperlink_hyperlinkText=Open Declaration
167
CustomTagHyperlink_hyperlinkText=Open Declaration
168
TLDContentOutlineConfiguration_0=Show Content Values
168
TLDContentOutlineConfiguration_0=Show Content Values
169
TagPropertyPage_desc=Specify the surrounding language used in this tag file:
169
TagPropertyPage_desc=Specify the surrounding language used in this tag file:
170
Template_Taglib_URI=Tag Library URI
170
171
171
JSPFilesPreferencePage_Search_group=Search
172
JSPFilesPreferencePage_Search_group=Search
172
JSPFilesPreferencePage_Supply_JSP_search_to_Java_search=&Include JSP matches in Java searches
173
JSPFilesPreferencePage_Supply_JSP_search_to_Java_search=&Include JSP matches in Java searches
(-)src/org/eclipse/jst/jsp/ui/internal/contentassist/LibraryTagsCompletionProposalComputer.java (-1 / +4 lines)
Lines 22-27 Link Here
22
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
22
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager;
23
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration;
23
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration;
24
import org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache;
24
import org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache;
25
import org.eclipse.jst.jsp.core.internal.modelquery.JSPModelQueryExtension;
26
import org.eclipse.jst.jsp.core.internal.modelquery.TaglibModelQueryExtension;
25
import org.eclipse.jst.jsp.core.internal.provisional.JSP12Namespace;
27
import org.eclipse.jst.jsp.core.internal.provisional.JSP12Namespace;
26
import org.eclipse.jst.jsp.core.internal.provisional.JSP20Namespace;
28
import org.eclipse.jst.jsp.core.internal.provisional.JSP20Namespace;
27
import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP;
29
import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP;
Lines 51-56 Link Here
51
import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
53
import org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapter;
52
import org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLModelQueryCompletionProposalComputer;
54
import org.eclipse.wst.xml.ui.internal.contentassist.AbstractXMLModelQueryCompletionProposalComputer;
53
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
55
import org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest;
56
import org.eclipse.wst.xml.ui.internal.contentassist.MarkupCompletionProposal;
54
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentModelGenerator;
57
import org.eclipse.wst.xml.ui.internal.contentassist.XMLContentModelGenerator;
55
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
58
import org.eclipse.wst.xml.ui.internal.contentassist.XMLRelevanceConstants;
56
import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil;
59
import org.eclipse.wst.xml.ui.internal.editor.CMImageUtil;
Lines 340-346 Link Here
340
					// account for the < and >
343
					// account for the < and >
341
					int markupAdjustment = getCursorPositionForProposedText(proposedText);
344
					int markupAdjustment = getCursorPositionForProposedText(proposedText);
342
					String proposedInfo = getAdditionalInfo(null, ed);
345
					String proposedInfo = getAdditionalInfo(null, ed);
343
					CustomCompletionProposal proposal = new CustomCompletionProposal(
346
					MarkupCompletionProposal proposal = new MarkupCompletionProposal(
344
							proposedText, contentAssistRequest.getReplacementBeginPosition(),
347
							proposedText, contentAssistRequest.getReplacementBeginPosition(),
345
							contentAssistRequest.getReplacementLength(), markupAdjustment, image,
348
							contentAssistRequest.getReplacementLength(), markupAdjustment, image,
346
							tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
349
							tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
(-)src/org/eclipse/jst/jsp/ui/internal/templates/TemplateContextTypeJSP.java (-1 / +126 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 IBM Corporation and others.
2
 * Copyright (c) 2004, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 10-17 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jst.jsp.ui.internal.templates;
11
package org.eclipse.jst.jsp.ui.internal.templates;
12
12
13
import java.util.Arrays;
14
import java.util.HashSet;
15
import java.util.Set;
16
17
import org.eclipse.core.resources.IFile;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.IPath;
20
import org.eclipse.core.runtime.Path;
21
import org.eclipse.jface.text.IDocument;
22
import org.eclipse.jface.text.templates.DocumentTemplateContext;
13
import org.eclipse.jface.text.templates.GlobalTemplateVariables;
23
import org.eclipse.jface.text.templates.GlobalTemplateVariables;
24
import org.eclipse.jface.text.templates.SimpleTemplateVariableResolver;
25
import org.eclipse.jface.text.templates.TemplateContext;
14
import org.eclipse.jface.text.templates.TemplateContextType;
26
import org.eclipse.jface.text.templates.TemplateContextType;
27
import org.eclipse.jface.text.templates.TemplateVariable;
28
import org.eclipse.jst.jsp.core.internal.util.FacetModuleCoreSupport;
29
import org.eclipse.jst.jsp.core.taglib.IJarRecord;
30
import org.eclipse.jst.jsp.core.taglib.ITLDRecord;
31
import org.eclipse.jst.jsp.core.taglib.ITaglibDescriptor;
32
import org.eclipse.jst.jsp.core.taglib.ITaglibRecord;
33
import org.eclipse.jst.jsp.core.taglib.TaglibIndex;
34
import org.eclipse.jst.jsp.ui.internal.JSPUIMessages;
35
import org.eclipse.wst.sse.core.StructuredModelManager;
36
import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
37
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
15
38
16
/**
39
/**
17
 * Base class for JSP template context types. Templates of this context type
40
 * Base class for JSP template context types. Templates of this context type
Lines 29-33 Link Here
29
		addResolver(new GlobalTemplateVariables.WordSelection());
52
		addResolver(new GlobalTemplateVariables.WordSelection());
30
		addResolver(new GlobalTemplateVariables.Year());
53
		addResolver(new GlobalTemplateVariables.Year());
31
		addResolver(new EncodingTemplateVariableResolverJSP());
54
		addResolver(new EncodingTemplateVariableResolverJSP());
55
		addResolver(new URITemplateResolver());
56
		
57
	}
58
59
	/**
60
	 * Resolves the ${uri} Template Variable for a taglib directive providing
61
	 * URIs from the taglib index
62
	 *
63
	 */
64
	class URITemplateResolver extends SimpleTemplateVariableResolver {
65
66
		protected URITemplateResolver() {
67
			super("uri", JSPUIMessages.Template_Taglib_URI); //$NON-NLS-1$
68
		}
69
		
70
		public void resolve(TemplateVariable variable, TemplateContext context) {
71
			if (context instanceof DocumentTemplateContext) {
72
				DocumentTemplateContext docContext = (DocumentTemplateContext) context;
73
				final IPath path = getPath(docContext.getDocument());
74
				if (path != null) {
75
					String[] uris = getURIs(TaglibIndex.getAvailableTaglibRecords(path), path);
76
					if (uris != null && uris.length > 0) {
77
						variable.setValues(uris);
78
					}
79
				}
80
				
81
			}
82
		}
83
84
		private String[] getURIs(ITaglibRecord[] records, IPath basePath) {
85
			if (records != null) {
86
				Set uris = new HashSet(records.length);
87
				for (int i = 0; i < records.length; i++) {
88
					final ITaglibRecord record = records[i];
89
					final ITaglibDescriptor descriptor = record.getDescriptor();
90
					String uri = null;
91
					switch (record.getRecordType()) {
92
						case ITaglibRecord.URL:
93
							uris.add(descriptor.getURI());
94
							break;
95
						case ITaglibRecord.JAR: {
96
							IPath location = ((IJarRecord) record).getLocation();
97
							IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
98
							IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
99
							for (int fileNumber = 0; fileNumber < files.length; fileNumber++) {
100
								if (localContextRoot.isPrefixOf(files[fileNumber].getFullPath())) {
101
									uri = IPath.SEPARATOR +
102
											files[fileNumber].getFullPath().removeFirstSegments(localContextRoot.segmentCount()).toString();
103
								}
104
								else {
105
									uri = FacetModuleCoreSupport.getRuntimePath(files[fileNumber].getFullPath()).toString();
106
								}
107
								uris.add(uri);
108
							}
109
							break;
110
						}
111
						case ITaglibRecord.TLD: {
112
							uri = descriptor.getURI();
113
							if (uri == null || uri.trim().length() == 0) {
114
								IPath path = ((ITLDRecord) record).getPath();
115
								IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
116
								if (localContextRoot.isPrefixOf(path)) {
117
									uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
118
								}
119
								else {
120
									uri = FacetModuleCoreSupport.getRuntimePath(path).toString();
121
								}
122
							}
123
							uris.add(uri);
124
							break;
125
						}
126
						
127
					}
128
				}
129
				String[] urisArray = (String[]) uris.toArray(new String[uris.size()]);
130
				Arrays.sort(urisArray);
131
				return urisArray;
132
			}
133
			return null;
134
		}
135
136
		private IPath getPath(IDocument iDoc) {
137
			IPath path = null;
138
			if (iDoc instanceof IStructuredDocument) {
139
				IStructuredDocument document = (IStructuredDocument) iDoc;
140
				IStructuredModel model = null;
141
				try {
142
					model = StructuredModelManager.getModelManager().getModelForRead(document);
143
					if (model != null) {
144
						String location = model.getBaseLocation();
145
						if (location != null) {
146
							path = new Path(location);
147
						}
148
					}
149
				}
150
				finally {
151
					if (model != null)
152
						model.releaseFromRead();
153
				}
154
			}
155
			return path;
156
		}
32
	}
157
	}
33
}
158
}
(-)templates/jspdefault-templates.properties (-1 / +1 lines)
Lines 28-34 Link Here
28
Templates.jsppagedirective.content=<%@ page contentType="text/html; charset=${encoding}" %>
28
Templates.jsppagedirective.content=<%@ page contentType="text/html; charset=${encoding}" %>
29
Templates.jsptaglibdirective.name=JSP taglib directive
29
Templates.jsptaglibdirective.name=JSP taglib directive
30
Templates.jsptaglibdirective.desc=JSP taglib directive
30
Templates.jsptaglibdirective.desc=JSP taglib directive
31
Templates.jsptaglibdirective.content=<%@ taglib uri="${cursor}" prefix="" %>
31
Templates.jsptaglibdirective.content=<%@ taglib uri="${uri}" prefix="${cursor}" %>
32
Templates.jsphtml.name=New JSP File (html)
32
Templates.jsphtml.name=New JSP File (html)
33
Templates.jsphtml.desc=JSP with html markup
33
Templates.jsphtml.desc=JSP with html markup
34
Templates.jsphtml.content=<%@ page language="java" contentType="text/html; charset=${encoding}"\n    pageEncoding="${encoding}"%>\n<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=${encoding}">\n<title>Insert title here</title>\n</head>\n<body>\n${cursor}\n</body>\n</html>
34
Templates.jsphtml.content=<%@ page language="java" contentType="text/html; charset=${encoding}"\n    pageEncoding="${encoding}"%>\n<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=${encoding}">\n<title>Insert title here</title>\n</head>\n<body>\n${cursor}\n</body>\n</html>
(-)src/org/eclipse/wst/xml/ui/internal/contentassist/AbstractXMLModelQueryCompletionProposalComputer.java (-22 / +22 lines)
Lines 198-204 Link Here
198
							if (attrAtLocationHasValue) {
198
							if (attrAtLocationHasValue) {
199
								// only propose the name
199
								// only propose the name
200
								proposedText = getRequiredName(node, attrDecl);
200
								proposedText = getRequiredName(node, attrDecl);
201
								proposal = new CustomCompletionProposal(
201
								proposal = new MarkupCompletionProposal(
202
										proposedText, contentAssistRequest.getReplacementBeginPosition(),
202
										proposedText, contentAssistRequest.getReplacementBeginPosition(),
203
										contentAssistRequest.getReplacementLength(), proposedText.length(),
203
										contentAssistRequest.getReplacementLength(), proposedText.length(),
204
										attrImage, proposedText, null, proposedInfo,
204
										attrImage, proposedText, null, proposedInfo,
Lines 227-233 Link Here
227
								}
227
								}
228
								if (proposalNeedsSpace)
228
								if (proposalNeedsSpace)
229
									proposedText += " "; //$NON-NLS-1$
229
									proposedText += " "; //$NON-NLS-1$
230
								proposal = new CustomCompletionProposal(proposedText,
230
								proposal = new MarkupCompletionProposal(proposedText,
231
										contentAssistRequest.getReplacementBeginPosition(),
231
										contentAssistRequest.getReplacementBeginPosition(),
232
										contentAssistRequest.getReplacementLength(),
232
										contentAssistRequest.getReplacementLength(),
233
										cursorPosition, attrImage,
233
										cursorPosition, attrImage,
Lines 367-373 Link Here
367
							if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) {
367
							if ((matchString.length() == 0) || possibleValue.startsWith(matchString)) {
368
								String rString = "\"" + possibleValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
368
								String rString = "\"" + possibleValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
369
								alternateMatch = "\"" + alternateMatch; //$NON-NLS-1$
369
								alternateMatch = "\"" + alternateMatch; //$NON-NLS-1$
370
								CustomCompletionProposal proposal = new CustomCompletionProposal(
370
								CustomCompletionProposal proposal = new MarkupCompletionProposal(
371
										rString, rOffset, rLength, possibleValue.length() + 1,
371
										rString, rOffset, rLength, possibleValue.length() + 1,
372
										XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM),
372
										XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM),
373
										rString, alternateMatch, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE, true);
373
										rString, alternateMatch, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE, true);
Lines 377-383 Link Here
377
					}
377
					}
378
					if(defaultValue != null && ((matchString.length() == 0) || defaultValue.startsWith(matchString))) {
378
					if(defaultValue != null && ((matchString.length() == 0) || defaultValue.startsWith(matchString))) {
379
						String rString = "\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
379
						String rString = "\"" + defaultValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$
380
						CustomCompletionProposal proposal = new CustomCompletionProposal(
380
						CustomCompletionProposal proposal = new MarkupCompletionProposal(
381
								rString, rOffset, rLength, defaultValue.length() + 1,
381
								rString, rOffset, rLength, defaultValue.length() + 1,
382
								XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT),
382
								XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT),
383
								rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
383
								rString, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
Lines 392-398 Link Here
392
					String value = attrDecl.getAttrType().getImpliedValue();
392
					String value = attrDecl.getAttrType().getImpliedValue();
393
					if ((value != null) && (value.length() > 0)) {
393
					if ((value != null) && (value.length() > 0)) {
394
						String rValue = "\"" + value + "\"";//$NON-NLS-2$//$NON-NLS-1$
394
						String rValue = "\"" + value + "\"";//$NON-NLS-2$//$NON-NLS-1$
395
						CustomCompletionProposal proposal = new CustomCompletionProposal(
395
						CustomCompletionProposal proposal = new MarkupCompletionProposal(
396
								rValue, contentAssistRequest.getReplacementBeginPosition(),
396
								rValue, contentAssistRequest.getReplacementBeginPosition(),
397
								contentAssistRequest.getReplacementLength(), rValue.length() + 1,
397
								contentAssistRequest.getReplacementLength(), rValue.length() + 1,
398
								image, rValue, null, proposedInfo,
398
								image, rValue, null, proposedInfo,
Lines 400-406 Link Here
400
						contentAssistRequest.addProposal(proposal);
400
						contentAssistRequest.addProposal(proposal);
401
						if ((currentValue.length() > 0) && !value.equals(currentValue)) {
401
						if ((currentValue.length() > 0) && !value.equals(currentValue)) {
402
							rValue = "\"" + currentValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
402
							rValue = "\"" + currentValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
403
							proposal = new CustomCompletionProposal(rValue, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), rValue.length() + 1, image, rValue, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
403
							proposal = new MarkupCompletionProposal(rValue, contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), rValue.length() + 1, image, rValue, null, proposedInfo, XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE);
404
							contentAssistRequest.addProposal(proposal);
404
							contentAssistRequest.addProposal(proposal);
405
						}
405
						}
406
					}
406
					}
Lines 412-418 Link Here
412
				CustomCompletionProposal proposal = null;
412
				CustomCompletionProposal proposal = null;
413
				if ((currentValue != null) && (currentValue.length() > 0)) {
413
				if ((currentValue != null) && (currentValue.length() > 0)) {
414
					String rValue = "\"" + currentValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
414
					String rValue = "\"" + currentValue + "\""; //$NON-NLS-2$//$NON-NLS-1$
415
					proposal = new CustomCompletionProposal(rValue,
415
					proposal = new MarkupCompletionProposal(rValue,
416
							contentAssistRequest.getReplacementBeginPosition(),
416
							contentAssistRequest.getReplacementBeginPosition(),
417
							contentAssistRequest.getReplacementLength(), 1, image,
417
							contentAssistRequest.getReplacementLength(), 1, image,
418
							rValue, null, proposedInfo,
418
							rValue, null, proposedInfo,
Lines 447-453 Link Here
447
			CompletionProposalInvocationContext context) {
447
			CompletionProposalInvocationContext context) {
448
448
449
		if (contentAssistRequest.getStartOffset() + contentAssistRequest.getRegion().getTextLength() < contentAssistRequest.getReplacementBeginPosition()) {
449
		if (contentAssistRequest.getStartOffset() + contentAssistRequest.getRegion().getTextLength() < contentAssistRequest.getReplacementBeginPosition()) {
450
			CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$
450
			CustomCompletionProposal proposal = new MarkupCompletionProposal(">", //$NON-NLS-1$
451
						contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$
451
						contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), 1, XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_TAG_GENERIC), NLS.bind(XMLUIMessages.Close_with__, (new Object[]{" '>'"})), //$NON-NLS-1$
452
						null, null, XMLRelevanceConstants.R_END_TAG_NAME);
452
						null, null, XMLRelevanceConstants.R_END_TAG_NAME);
453
			contentAssistRequest.addProposal(proposal);
453
			contentAssistRequest.addProposal(proposal);
Lines 479-492 Link Here
479
								image = this.getGenericTagImage();
479
								image = this.getGenericTagImage();
480
							}
480
							}
481
							if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_NAME) {
481
							if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_NAME) {
482
								proposal = new CustomCompletionProposal(
482
								proposal = new MarkupCompletionProposal(
483
										replacementText, contentAssistRequest.getStartOffset(),
483
										replacementText, contentAssistRequest.getStartOffset(),
484
										contentAssistRequest.getRegion().getTextLength(),
484
										contentAssistRequest.getRegion().getTextLength(),
485
										replacementText.length(), image, displayText, null,
485
										replacementText.length(), image, displayText, null,
486
										proposedInfo, XMLRelevanceConstants.R_END_TAG_NAME);
486
										proposedInfo, XMLRelevanceConstants.R_END_TAG_NAME);
487
							}
487
							}
488
							else {
488
							else {
489
								proposal = new CustomCompletionProposal(
489
								proposal = new MarkupCompletionProposal(
490
										replacementText,
490
										replacementText,
491
										contentAssistRequest.getReplacementBeginPosition(),
491
										contentAssistRequest.getReplacementBeginPosition(),
492
										contentAssistRequest.getReplacementLength(),
492
										contentAssistRequest.getReplacementLength(),
Lines 631-637 Link Here
631
			setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
631
			setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
632
		}
632
		}
633
		if (addProposal == true) {
633
		if (addProposal == true) {
634
			CustomCompletionProposal proposal = new CustomCompletionProposal(replaceText, replaceBegin, replaceLength, cursorOffset, image, displayString, null, proposedInfo, XMLRelevanceConstants.R_END_TAG);
634
			CustomCompletionProposal proposal = new MarkupCompletionProposal(replaceText, replaceBegin, replaceLength, cursorOffset, image, displayString, null, proposedInfo, XMLRelevanceConstants.R_END_TAG);
635
			contentAssistRequest.addProposal(proposal);
635
			contentAssistRequest.addProposal(proposal);
636
		}
636
		}
637
	}
637
	}
Lines 749-755 Link Here
749
					// prompt with a self-closing end character if needed
749
					// prompt with a self-closing end character if needed
750
					// this is one of the few times to ignore the length -- always insert
750
					// this is one of the few times to ignore the length -- always insert
751
					// contentAssistRequest.getReplacementLength()
751
					// contentAssistRequest.getReplacementLength()
752
					CustomCompletionProposal proposal = new CustomCompletionProposal(
752
					CustomCompletionProposal proposal = new MarkupCompletionProposal(
753
							getContentGenerator().getStartTagClose(node, elementDecl),
753
							getContentGenerator().getStartTagClose(node, elementDecl),
754
							contentAssistRequest.getReplacementBeginPosition(), 0,
754
							contentAssistRequest.getReplacementBeginPosition(), 0,
755
							getContentGenerator().getStartTagClose(node, elementDecl).length(), image,
755
							getContentGenerator().getStartTagClose(node, elementDecl).length(), image,
Lines 759-765 Link Here
759
				}
759
				}
760
				else {
760
				else {
761
					// prompt with a close for the start tag
761
					// prompt with a close for the start tag
762
					CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$
762
					CustomCompletionProposal proposal = new MarkupCompletionProposal(">", //$NON-NLS-1$
763
								contentAssistRequest.getReplacementBeginPosition(),
763
								contentAssistRequest.getReplacementBeginPosition(),
764
								// this is one of the few times to ignore the
764
								// this is one of the few times to ignore the
765
								// length -- always insert
765
								// length -- always insert
Lines 775-781 Link Here
775
						IStructuredDocumentRegion sdr = contentAssistRequest.getDocumentRegion();
775
						IStructuredDocumentRegion sdr = contentAssistRequest.getDocumentRegion();
776
						String openingTagText = (sdr != null) ? sdr.getFullText() : ""; //$NON-NLS-1$
776
						String openingTagText = (sdr != null) ? sdr.getFullText() : ""; //$NON-NLS-1$
777
						if ((openingTagText != null) && (openingTagText.indexOf(node.getNodeName()) != -1)) {
777
						if ((openingTagText != null) && (openingTagText.indexOf(node.getNodeName()) != -1)) {
778
							proposal = new CustomCompletionProposal("></" + node.getNodeName() + ">", //$NON-NLS-2$//$NON-NLS-1$
778
							proposal = new MarkupCompletionProposal("></" + node.getNodeName() + ">", //$NON-NLS-2$//$NON-NLS-1$
779
										contentAssistRequest.getReplacementBeginPosition(),
779
										contentAssistRequest.getReplacementBeginPosition(),
780
										// this is one of the few times to
780
										// this is one of the few times to
781
										// ignore the length -- always insert
781
										// ignore the length -- always insert
Lines 786-792 Link Here
786
					}
786
					}
787
					// prompt with slash bracket "/>" incase if it's a self ending tag
787
					// prompt with slash bracket "/>" incase if it's a self ending tag
788
					if (endWithSlashBracket) {
788
					if (endWithSlashBracket) {
789
						proposal = new CustomCompletionProposal("/>", //$NON-NLS-1$
789
						proposal = new MarkupCompletionProposal("/>", //$NON-NLS-1$
790
									contentAssistRequest.getReplacementBeginPosition(),
790
									contentAssistRequest.getReplacementBeginPosition(),
791
									// this is one of the few times to ignore
791
									// this is one of the few times to ignore
792
									// the length -- always insert
792
									// the length -- always insert
Lines 801-807 Link Here
801
			else if ((contentAssistRequest.getDocumentRegion() == node.getLastStructuredDocumentRegion()) && !node.getLastStructuredDocumentRegion().isEnded()) {
801
			else if ((contentAssistRequest.getDocumentRegion() == node.getLastStructuredDocumentRegion()) && !node.getLastStructuredDocumentRegion().isEnded()) {
802
				setErrorMessage(null);
802
				setErrorMessage(null);
803
				// prompt with a closing end character for the end tag
803
				// prompt with a closing end character for the end tag
804
				CustomCompletionProposal proposal = new CustomCompletionProposal(">", //$NON-NLS-1$
804
				CustomCompletionProposal proposal = new MarkupCompletionProposal(">", //$NON-NLS-1$
805
							contentAssistRequest.getReplacementBeginPosition(),
805
							contentAssistRequest.getReplacementBeginPosition(),
806
							// this is one of the few times to ignore the length -- always insert
806
							// this is one of the few times to ignore the length -- always insert
807
							// contentAssistRequest.getReplacementLength(),
807
							// contentAssistRequest.getReplacementLength(),
Lines 865-871 Link Here
865
						String proposedInfo = getAdditionalInfo(parentDecl, childType);
865
						String proposedInfo = getAdditionalInfo(parentDecl, childType);
866
						for (int i = 0; i < childStrings.length; i++) {
866
						for (int i = 0; i < childStrings.length; i++) {
867
							if(!childStrings[i].equals(defaultValue)) {
867
							if(!childStrings[i].equals(defaultValue)) {
868
								CustomCompletionProposal textProposal = new CustomCompletionProposal(
868
								CustomCompletionProposal textProposal = new MarkupCompletionProposal(
869
										childStrings[i],begin, length, childStrings[i].length(),
869
										childStrings[i],begin, length, childStrings[i].length(),
870
										XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM),
870
										XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ENUM),
871
										childStrings[i], null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
871
										childStrings[i], null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
Lines 873-879 Link Here
873
							}
873
							}
874
						}
874
						}
875
						if(defaultValue != null) {
875
						if(defaultValue != null) {
876
							CustomCompletionProposal textProposal = new CustomCompletionProposal(
876
							CustomCompletionProposal textProposal = new MarkupCompletionProposal(
877
									defaultValue, begin, length, defaultValue.length(),
877
									defaultValue, begin, length, defaultValue.length(),
878
									XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT),
878
									XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_DEFAULT),
879
									defaultValue, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
879
									defaultValue, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
Lines 940-946 Link Here
940
940
941
							String proposedInfo = getAdditionalInfo(parentDecl, elementDecl);
941
							String proposedInfo = getAdditionalInfo(parentDecl, elementDecl);
942
							int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_INSERTION : XMLRelevanceConstants.R_TAG_INSERTION;
942
							int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_INSERTION : XMLRelevanceConstants.R_TAG_INSERTION;
943
							CustomCompletionProposal proposal = new CustomCompletionProposal(
943
							CustomCompletionProposal proposal = new MarkupCompletionProposal(
944
									proposedText, contentAssistRequest.getReplacementBeginPosition(),
944
									proposedText, contentAssistRequest.getReplacementBeginPosition(),
945
									contentAssistRequest.getReplacementLength(), markupAdjustment,
945
									contentAssistRequest.getReplacementLength(), markupAdjustment,
946
									image, tagname, null, proposedInfo, relevance);
946
									image, tagname, null, proposedInfo, relevance);
Lines 1000-1006 Link Here
1000
						// account for the &lt; and &gt;
1000
						// account for the &lt; and &gt;
1001
						int markupAdjustment = getContentGenerator().getMinimalStartTagLength(parent, ed);
1001
						int markupAdjustment = getContentGenerator().getMinimalStartTagLength(parent, ed);
1002
						String proposedInfo = getAdditionalInfo(null, ed);
1002
						String proposedInfo = getAdditionalInfo(null, ed);
1003
						CustomCompletionProposal proposal = new CustomCompletionProposal(
1003
						CustomCompletionProposal proposal = new MarkupCompletionProposal(
1004
								proposedText, contentAssistRequest.getReplacementBeginPosition(),
1004
								proposedText, contentAssistRequest.getReplacementBeginPosition(),
1005
								contentAssistRequest.getReplacementLength(), markupAdjustment, image,
1005
								contentAssistRequest.getReplacementLength(), markupAdjustment, image,
1006
								tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
1006
								tagname, null, proposedInfo, XMLRelevanceConstants.R_TAG_INSERTION);
Lines 1088-1094 Link Here
1088
						}
1088
						}
1089
						int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_NAME : XMLRelevanceConstants.R_TAG_NAME;
1089
						int relevance = isStrictCMNodeSuggestion ? XMLRelevanceConstants.R_STRICTLY_VALID_TAG_NAME : XMLRelevanceConstants.R_TAG_NAME;
1090
						String proposedInfo = getAdditionalInfo(getCMElementDeclaration(parent), elementDecl);
1090
						String proposedInfo = getAdditionalInfo(getCMElementDeclaration(parent), elementDecl);
1091
						CustomCompletionProposal proposal = new CustomCompletionProposal(
1091
						CustomCompletionProposal proposal = new MarkupCompletionProposal(
1092
								proposedText, contentAssistRequest.getReplacementBeginPosition(),
1092
								proposedText, contentAssistRequest.getReplacementBeginPosition(),
1093
								contentAssistRequest.getReplacementLength(), cursorAdjustment, image,
1093
								contentAssistRequest.getReplacementLength(), cursorAdjustment, image,
1094
								getRequiredName(parent, elementDecl), null, proposedInfo,
1094
								getRequiredName(parent, elementDecl), null, proposedInfo,
Lines 1144-1150 Link Here
1144
					if (image == null) {
1144
					if (image == null) {
1145
						image = this.getGenericTagImage();
1145
						image = this.getGenericTagImage();
1146
					}
1146
					}
1147
					CustomCompletionProposal proposal = new CustomCompletionProposal(
1147
					CustomCompletionProposal proposal = new MarkupCompletionProposal(
1148
							proposedText, contentAssistRequest.getReplacementBeginPosition(),
1148
							proposedText, contentAssistRequest.getReplacementBeginPosition(),
1149
							contentAssistRequest.getReplacementLength(), cursorAdjustment, image,
1149
							contentAssistRequest.getReplacementLength(), cursorAdjustment, image,
1150
							getRequiredName(parent, ed), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME);
1150
							getRequiredName(parent, ed), null, proposedInfo, XMLRelevanceConstants.R_TAG_NAME);
(-)src/org/eclipse/wst/xml/ui/internal/contentassist/MarkupCompletionProposal.java (+125 lines)
Added Link Here
1
/**
2
 * 
3
 */
4
package org.eclipse.wst.xml.ui.internal.contentassist;
5
6
import org.eclipse.jface.text.BadLocationException;
7
import org.eclipse.jface.text.IDocument;
8
import org.eclipse.jface.text.IRegion;
9
import org.eclipse.jface.text.ITextViewer;
10
import org.eclipse.jface.text.contentassist.IContextInformation;
11
import org.eclipse.jface.text.link.LinkedModeModel;
12
import org.eclipse.jface.text.link.LinkedModeUI;
13
import org.eclipse.jface.text.link.LinkedPosition;
14
import org.eclipse.jface.text.link.LinkedPositionGroup;
15
import org.eclipse.swt.graphics.Image;
16
import org.eclipse.swt.graphics.Point;
17
import org.eclipse.ui.texteditor.link.EditorLinkedModeUI;
18
import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal;
19
import org.eclipse.wst.xml.ui.internal.Logger;
20
21
public class MarkupCompletionProposal extends CustomCompletionProposal {
22
23
	private IRegion fSelectedRegion = null;
24
25
	public MarkupCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo, int relevance) {
26
		super(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, contextInformation, additionalProposalInfo, relevance);
27
	}
28
29
	public MarkupCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo, int relevance, boolean updateReplacementLengthOnValidate) {
30
		super(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, null, contextInformation, additionalProposalInfo, relevance, updateReplacementLengthOnValidate);
31
	}
32
33
	public MarkupCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, String alternateMatch, IContextInformation contextInformation, String additionalProposalInfo, int relevance, boolean updateReplacementLengthOnValidate) {
34
		super(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, alternateMatch, contextInformation, additionalProposalInfo, relevance, updateReplacementLengthOnValidate);
35
	}
36
37
	public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
38
		super.apply(viewer, trigger, stateMask, offset);
39
40
		getLinkedPositions(viewer);
41
		
42
	}
43
44
	protected void getLinkedPositions(ITextViewer viewer) {
45
		final String replacement = getReplacementString();
46
		final IDocument document = viewer.getDocument();
47
		final int length = replacement.length();
48
		boolean inAttribute = false, hasGroup = false, inEndTag = false;
49
		int offset = 0;
50
		char attType = 0;
51
		int exitPosition = -1;
52
		LinkedModeModel model = new LinkedModeModel();
53
54
		try {
55
			for (int i = 0; i < length; i++) {
56
				final char c = replacement.charAt(i);
57
				switch (c) {
58
					case '=':
59
						// Do we need to see this?
60
						break;
61
					case '\'':
62
					case '\"':
63
						if (!inAttribute) {
64
							offset = i;
65
							attType = c;
66
							inAttribute = true;
67
						}
68
						else {
69
							if (attType == c && replacement.charAt(i - 1) != '\\') {
70
								inAttribute = false; // Record position length
71
								addPosition(model, document, getReplacementOffset() + offset + 1, i - offset - 1);
72
								hasGroup = true;
73
							}
74
						}
75
						break;
76
					case '/':
77
							if (!inAttribute) {
78
								inEndTag = i > 0 && replacement.charAt(i - 1) == '<';
79
							}
80
						break;
81
					case '>':
82
						if (!inAttribute) {
83
							if (i == length - 1) {
84
								exitPosition = getReplacementOffset() + i + 1;
85
								if (!inEndTag) {
86
									addPosition(model, document, getReplacementOffset() + i, 0); // position within start tag
87
									hasGroup = true;
88
								}
89
							}
90
							else {
91
								addPosition(model, document, getReplacementOffset() + i, 0); // position within start tag
92
								addPosition(model, document, getReplacementOffset() + i + 1, 0); // position after start tag
93
								hasGroup = true;
94
							}
95
						}
96
						break;
97
				}
98
			}
99
			if (hasGroup) {
100
				model.forceInstall();
101
				final LinkedModeUI ui= new EditorLinkedModeUI(model, viewer);
102
				ui.setExitPosition(viewer, exitPosition < 0 ? getReplacementOffset() + getReplacementLength() + replacement.length() - 1 : exitPosition, 0, Integer.MAX_VALUE);
103
				ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
104
				ui.setDoContextInfo(true);
105
				ui.enter();
106
				fSelectedRegion = ui.getSelectedRegion();
107
			}
108
		}
109
		catch (BadLocationException e) {
110
			Logger.logException(e);
111
		}
112
	}
113
114
	private void addPosition(LinkedModeModel model, IDocument document, int offset, int length) throws BadLocationException {
115
		final LinkedPositionGroup group = new LinkedPositionGroup();
116
		group.addPosition(new LinkedPosition(document, offset, length, LinkedPositionGroup.NO_STOP));
117
		model.addGroup(group);
118
	}
119
120
	public Point getSelection(IDocument document) {
121
		if (fSelectedRegion == null)
122
			return super.getSelection(document);
123
		return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength());
124
	}
125
}

Return to bug 264246