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 49383
Collapse All | Expand All

(-)Ant Editor/org/eclipse/ant/internal/ui/editor/AntEditorCompletionProcessor.java (-12 / +69 lines)
Lines 20-25 Link Here
20
import java.io.InputStreamReader;
20
import java.io.InputStreamReader;
21
import java.util.ArrayList;
21
import java.util.ArrayList;
22
import java.util.Arrays;
22
import java.util.Arrays;
23
import java.util.Collection;
23
import java.util.Comparator;
24
import java.util.Comparator;
24
import java.util.Enumeration;
25
import java.util.Enumeration;
25
import java.util.HashMap;
26
import java.util.HashMap;
Lines 55-69 Link Here
55
import org.eclipse.ant.internal.ui.model.AntUIImages;
56
import org.eclipse.ant.internal.ui.model.AntUIImages;
56
import org.eclipse.ant.internal.ui.model.AntUIPlugin;
57
import org.eclipse.ant.internal.ui.model.AntUIPlugin;
57
import org.eclipse.ant.internal.ui.model.IAntUIConstants;
58
import org.eclipse.ant.internal.ui.model.IAntUIConstants;
59
58
import org.eclipse.jface.text.BadLocationException;
60
import org.eclipse.jface.text.BadLocationException;
59
import org.eclipse.jface.text.IDocument;
61
import org.eclipse.jface.text.IDocument;
62
import org.eclipse.jface.text.IRegion;
60
import org.eclipse.jface.text.ITextSelection;
63
import org.eclipse.jface.text.ITextSelection;
61
import org.eclipse.jface.text.ITextViewer;
64
import org.eclipse.jface.text.ITextViewer;
65
import org.eclipse.jface.text.Region;
62
import org.eclipse.jface.text.contentassist.ICompletionProposal;
66
import org.eclipse.jface.text.contentassist.ICompletionProposal;
63
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
67
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
64
import org.eclipse.jface.text.contentassist.IContextInformation;
68
import org.eclipse.jface.text.contentassist.IContextInformation;
65
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
69
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
70
import org.eclipse.jface.text.templates.ContextType;
71
import org.eclipse.jface.text.templates.DocumentTemplateContext;
72
import org.eclipse.jface.text.templates.Template;
73
import org.eclipse.jface.text.templates.TemplateContext;
74
import org.eclipse.jface.text.templates.TemplateProposal;
66
import org.eclipse.swt.graphics.Image;
75
import org.eclipse.swt.graphics.Image;
76
import org.eclipse.swt.graphics.Point;
67
import org.eclipse.ui.IEditorPart;
77
import org.eclipse.ui.IEditorPart;
68
import org.eclipse.ui.IWorkbenchPage;
78
import org.eclipse.ui.IWorkbenchPage;
69
import org.eclipse.ui.part.FileEditorInput;
79
import org.eclipse.ui.part.FileEditorInput;
Lines 78-87 Link Here
78
 
88
 
79
 	private Comparator proposalComparator= new Comparator() {
89
 	private Comparator proposalComparator= new Comparator() {
80
		public int compare(Object o1, Object o2) {
90
		public int compare(Object o1, Object o2) {
81
			AntCompletionProposal p1= (AntCompletionProposal) o1;
91
		    
82
			AntCompletionProposal p2= (AntCompletionProposal) o2;
92
			int type1= getProposalType(o1);
83
			int type1= p1.getType();
93
			int type2= getProposalType(o2);
84
			int type2= p2.getType();
85
			if (type1 != type2) {
94
			if (type1 != type2) {
86
				if (type1 > type2) {
95
				if (type1 > type2) {
87
					return 1;
96
					return 1;
Lines 89-98 Link Here
89
					return -1;
98
					return -1;
90
				}
99
				}
91
			}
100
			}
92
			String string1 = p1.getDisplayString();
101
			String string1 = ((ICompletionProposal)o1).getDisplayString();
93
			String string2 = p2.getDisplayString();
102
			String string2 = ((ICompletionProposal)o2).getDisplayString();
94
			return string1.compareToIgnoreCase(string2);
103
			return string1.compareToIgnoreCase(string2);
95
		}
104
		}
105
		private int getProposalType(Object o){
106
		    if(o instanceof AntCompletionProposal){
107
		        return ((AntCompletionProposal) o).getType();
108
		    } else {
109
		    	return AntCompletionProposal.TASK_PROPOSAL;    
110
		    }
111
		}
96
 	};
112
 	};
97
	
113
	
98
	private final static int PROPOSAL_MODE_NONE = 0;
114
	private final static int PROPOSAL_MODE_NONE = 0;
Lines 570-576 Link Here
570
     * not known.
586
     * not known.
571
     * 
587
     * 
572
     * @param document the entire document 
588
     * @param document the entire document 
573
     * @param parentName name of the parent (surrounding) element or 
589
     * @param parentName name of the parent(surrounding) element or 
574
     * <code>null</code> if completion should be done for the root element.
590
     * <code>null</code> if completion should be done for the root element.
575
     * @param prefix the prefix that all proposals should start with. The prefix
591
     * @param prefix the prefix that all proposals should start with. The prefix
576
     * may be an empty string.
592
     * may be an empty string.
Lines 620-627 Link Here
620
						if (prefix.length() == 0 || nestedElement.toLowerCase().startsWith(prefix)) {
636
						if (prefix.length() == 0 || nestedElement.toLowerCase().startsWith(prefix)) {
621
							proposal = newCompletionProposal(document, prefix, nestedElement);
637
							proposal = newCompletionProposal(document, prefix, nestedElement);
622
							proposals.add(proposal);
638
							proposals.add(proposal);
623
						}
639
			}
624
					}
640
        }
625
	        	}
641
	        	}
626
			}
642
			}
627
        }
643
        }
Lines 631-637 Link Here
631
        	proposals.add(proposal);
647
        	proposals.add(proposal);
632
        }
648
        }
633
        
649
        
634
       return (ICompletionProposal[])proposals.toArray(new ICompletionProposal[proposals.size()]);
650
        // TODO Templates may define something other than tasks / types
651
        // Here we assume that all templates are for tasks / types. I can't 
652
        // think of a usecase for templates other than tasks at the moment, but
653
        // since users can add templates via the preferences we may need to 
654
        // rethink this.
655
        proposals.addAll(getTemplateProposals(document,parentName,prefix));
656
        
657
        return (ICompletionProposal[])proposals.toArray(new ICompletionProposal[proposals.size()]);
635
   }
658
   }
636
659
637
    private void createProposals(IDocument document, String prefix, List proposals, Map tasks) {
660
    private void createProposals(IDocument document, String prefix, List proposals, Map tasks) {
Lines 646-652 Link Here
646
		}
669
		}
647
	}
670
	}
648
671
649
	private ICompletionProposal newCompletionProposal(IDocument document, String aPrefix, String elementName) {
672
	/**
673
     * @param document
674
     * @param parentName
675
     * @param prefix
676
     * @return a collection of
677
     *         {@link org.eclipse.jface.text.templates.TemplateProposal}s
678
     */
679
    protected Collection getTemplateProposals(IDocument document,
680
            String parentName, String prefix) {
681
682
        List proposals = new ArrayList();
683
684
        Point selection = viewer.getSelectedRange();
685
        IRegion selectedRegion = new Region(selection.x - (prefix.length()+1),
686
                selection.y + prefix.length()+1);		
687
        
688
        TemplateContext templateContext = new DocumentTemplateContext(
689
                new ContextType("ant"), document, selectedRegion.getOffset(), selectedRegion.getLength());
690
691
        Template template = new Template("fileset",
692
                "ant fileset type with include clause", "ant",
693
                "<fileset dir=\"${dir}\">"
694
                        + "\n\t\t<include name=\"${pattern}\" />"
695
                        + "\n\t</fileset>\n");
696
697
        TemplateProposal templateProposal = new TemplateProposal(template,
698
                templateContext, selectedRegion, AntUIImages
699
                        .getImage(IAntUIConstants.IMG_TASK_PROPOSAL));
700
701
        proposals.add(templateProposal);
702
703
        return proposals;
704
    }
705
706
    private ICompletionProposal newCompletionProposal(IDocument document, String aPrefix, String elementName) {
650
		additionalProposalOffset= 0;
707
		additionalProposalOffset= 0;
651
		Image proposalImage = AntUIImages.getImage(IAntUIConstants.IMG_TASK_PROPOSAL);
708
		Image proposalImage = AntUIImages.getImage(IAntUIConstants.IMG_TASK_PROPOSAL);
652
		String proposalInfo = descriptionProvider.getDescriptionForTask(elementName);
709
		String proposalInfo = descriptionProvider.getDescriptionForTask(elementName);
Lines 779-785 Link Here
779
        		IntrospectionHelper helper= IntrospectionHelper.getHelper(antModel.getProjectNode().getProject(), taskClass);
836
        		IntrospectionHelper helper= IntrospectionHelper.getHelper(antModel.getProjectNode().getProject(), taskClass);
780
        		Enumeration nested= helper.getNestedElements();
837
        		Enumeration nested= helper.getNestedElements();
781
        		return nested.hasMoreElements();
838
        		return nested.hasMoreElements();
782
        	}
839
    }
783
        }
840
        }
784
        return false;
841
        return false;
785
    }
842
    }

Return to bug 49383