Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 8552 Details for
Bug 49383
templates in the Ant editor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
getting started on template support
patch.txt (text/plain), 6.67 KB, created by
John-Mason P. Shackelford
on 2004-03-13 12:05:35 EST
(
hide
)
Description:
getting started on template support
Filename:
MIME Type:
Creator:
John-Mason P. Shackelford
Created:
2004-03-13 12:05:35 EST
Size:
6.67 KB
patch
obsolete
>Index: Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.ant.ui/Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java,v >retrieving revision 1.32 >diff -u -r1.32 AntEditorCompletionProcessor.java >--- Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java 13 Mar 2004 02:34:54 -0000 1.32 >+++ Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java 13 Mar 2004 16:59:07 -0000 >@@ -20,6 +20,7 @@ > import java.io.InputStreamReader; > import java.util.ArrayList; > import java.util.Arrays; >+import java.util.Collection; > import java.util.Comparator; > import java.util.Enumeration; > import java.util.HashMap; >@@ -55,15 +56,24 @@ > import org.eclipse.ant.internal.ui.model.AntUIImages; > import org.eclipse.ant.internal.ui.model.AntUIPlugin; > import org.eclipse.ant.internal.ui.model.IAntUIConstants; >+ > import org.eclipse.jface.text.BadLocationException; > import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.IRegion; > import org.eclipse.jface.text.ITextSelection; > import org.eclipse.jface.text.ITextViewer; >+import org.eclipse.jface.text.Region; > import org.eclipse.jface.text.contentassist.ICompletionProposal; > import org.eclipse.jface.text.contentassist.IContentAssistProcessor; > import org.eclipse.jface.text.contentassist.IContextInformation; > import org.eclipse.jface.text.contentassist.IContextInformationValidator; >+import org.eclipse.jface.text.templates.ContextType; >+import org.eclipse.jface.text.templates.DocumentTemplateContext; >+import org.eclipse.jface.text.templates.Template; >+import org.eclipse.jface.text.templates.TemplateContext; >+import org.eclipse.jface.text.templates.TemplateProposal; > import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; > import org.eclipse.ui.IEditorPart; > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.part.FileEditorInput; >@@ -78,10 +88,9 @@ > > private Comparator proposalComparator= new Comparator() { > public int compare(Object o1, Object o2) { >- AntCompletionProposal p1= (AntCompletionProposal) o1; >- AntCompletionProposal p2= (AntCompletionProposal) o2; >- int type1= p1.getType(); >- int type2= p2.getType(); >+ >+ int type1= getProposalType(o1); >+ int type2= getProposalType(o2); > if (type1 != type2) { > if (type1 > type2) { > return 1; >@@ -89,10 +98,17 @@ > return -1; > } > } >- String string1 = p1.getDisplayString(); >- String string2 = p2.getDisplayString(); >+ String string1 = ((ICompletionProposal)o1).getDisplayString(); >+ String string2 = ((ICompletionProposal)o2).getDisplayString(); > return string1.compareToIgnoreCase(string2); > } >+ private int getProposalType(Object o){ >+ if(o instanceof AntCompletionProposal){ >+ return ((AntCompletionProposal) o).getType(); >+ } else { >+ return AntCompletionProposal.TASK_PROPOSAL; >+ } >+ } > }; > > private final static int PROPOSAL_MODE_NONE = 0; >@@ -570,7 +586,7 @@ > * not known. > * > * @param document the entire document >- * @param parentName name of the parent (surrounding) element or >+ * @param parentName name of the parent(surrounding) element or > * <code>null</code> if completion should be done for the root element. > * @param prefix the prefix that all proposals should start with. The prefix > * may be an empty string. >@@ -620,8 +636,8 @@ > if (prefix.length() == 0 || nestedElement.toLowerCase().startsWith(prefix)) { > proposal = newCompletionProposal(document, prefix, nestedElement); > proposals.add(proposal); >- } >- } >+ } >+ } > } > } > } >@@ -631,7 +647,14 @@ > proposals.add(proposal); > } > >- return (ICompletionProposal[])proposals.toArray(new ICompletionProposal[proposals.size()]); >+ // TODO Templates may define something other than tasks / types >+ // Here we assume that all templates are for tasks / types. I can't >+ // think of a usecase for templates other than tasks at the moment, but >+ // since users can add templates via the preferences we may need to >+ // rethink this. >+ proposals.addAll(getTemplateProposals(document,parentName,prefix)); >+ >+ return (ICompletionProposal[])proposals.toArray(new ICompletionProposal[proposals.size()]); > } > > private void createProposals(IDocument document, String prefix, List proposals, Map tasks) { >@@ -646,7 +669,41 @@ > } > } > >- private ICompletionProposal newCompletionProposal(IDocument document, String aPrefix, String elementName) { >+ /** >+ * @param document >+ * @param parentName >+ * @param prefix >+ * @return a collection of >+ * {@link org.eclipse.jface.text.templates.TemplateProposal}s >+ */ >+ protected Collection getTemplateProposals(IDocument document, >+ String parentName, String prefix) { >+ >+ List proposals = new ArrayList(); >+ >+ Point selection = viewer.getSelectedRange(); >+ IRegion selectedRegion = new Region(selection.x - (prefix.length()+1), >+ selection.y + prefix.length()+1); >+ >+ TemplateContext templateContext = new DocumentTemplateContext( >+ new ContextType("ant"), document, selectedRegion.getOffset(), selectedRegion.getLength()); >+ >+ Template template = new Template("fileset", >+ "ant fileset type with include clause", "ant", >+ "<fileset dir=\"${dir}\">" >+ + "\n\t\t<include name=\"${pattern}\" />" >+ + "\n\t</fileset>\n"); >+ >+ TemplateProposal templateProposal = new TemplateProposal(template, >+ templateContext, selectedRegion, AntUIImages >+ .getImage(IAntUIConstants.IMG_TASK_PROPOSAL)); >+ >+ proposals.add(templateProposal); >+ >+ return proposals; >+ } >+ >+ private ICompletionProposal newCompletionProposal(IDocument document, String aPrefix, String elementName) { > additionalProposalOffset= 0; > Image proposalImage = AntUIImages.getImage(IAntUIConstants.IMG_TASK_PROPOSAL); > String proposalInfo = descriptionProvider.getDescriptionForTask(elementName); >@@ -779,7 +836,7 @@ > IntrospectionHelper helper= IntrospectionHelper.getHelper(antModel.getProjectNode().getProject(), taskClass); > Enumeration nested= helper.getNestedElements(); > return nested.hasMoreElements(); >- } >+ } > } > return false; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 49383
: 8552