Examples of TemplateContext


Examples of org.eclipse.jface.text.templates.TemplateContext

    Template template = getSelectedTemplate();
    if (template != null) {
      TemplateContextType contextType = JSPUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsJSP.NEW);
      IDocument document = new Document();
      TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
      try {
        TemplateBuffer buffer = context.evaluate(template);
        templateString = buffer.getString();
      }
      catch (Exception e) {
        Logger.log(Logger.WARNING_DEBUG, "Could not create template for new jsp", e); //$NON-NLS-1$
      }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContext

    if (selection.getOffset() == offset)
      offset = selection.getOffset() + selection.getLength();

    String prefix = extractPrefix(viewer, offset);
    Region region = new Region(offset - prefix.length(), prefix.length());
    TemplateContext context = createContext(viewer, region, offset);
    if (context == null)
      return new ICompletionProposal[0];

    // name of the selection variables {line, word}_selection
    context.setVariable("selection", selection.getText()); // //$NON-NLS-1$

    Template[] templates = getTemplates(context.getContextType().getId());

    List matches = new ArrayList();
    for (int i = 0; i < templates.length; i++) {
      Template template = templates[i];
      try {
        context.getContextType().validate(template.getPattern());
      }
      catch (TemplateException e) {
        continue;
      }
      if (template.matches(prefix, context.getContextType().getId()))
        matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
    }

    Collections.sort(matches, fgProposalComparator);
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContext

    Template template = getSelectedTemplate();
    if (template != null) {
      TemplateContextType contextType = XMLUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsXML.NEW);
      IDocument document = new Document();
      TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
      try {
        TemplateBuffer buffer = context.evaluate(template);
        templateString = buffer.getString();
      }
      catch (Exception e) {
        Logger.log(Logger.WARNING_DEBUG, "Could not create template for new xml", e); //$NON-NLS-1$
      }
View Full Code Here

Examples of org.eclipse.jface.text.templates.TemplateContext

      offset = selection.getOffset() + selection.getLength();
    }

    String prefix = extractPrefix(viewer, offset);
    Region region = new Region(offset - prefix.length(), prefix.length());
    TemplateContext context = createContext(viewer, region, offset);
    if (context == null) {
      return new ICompletionProposal[0];
    }

    IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, offset);

    currentTapestryComponent = (Node) treeNode; 
    char preChar=0,preChar2=0;
    //In situation user input <, we should store the char before cursor into preChar and even preChar2
    if(currentTapestryComponent.getNodeValue() != null){
      for(int i=offset-treeNode.getStartOffset()-1; i>=0; i--){
        char temp = currentTapestryComponent.getNodeValue().charAt(i);
        if(temp != 9 && temp != 10 && temp != 32){
          if(preChar == 0)
            preChar = temp;
          else{
            preChar2 = temp;
            break;
          }
        }
      }
    }
   
    while ((currentTapestryComponent != null) && (currentTapestryComponent.getNodeType() == Node.TEXT_NODE) && (currentTapestryComponent.getParentNode() != null)) {
      currentTapestryComponent = currentTapestryComponent.getParentNode();
    }

    // name of the selection variables {line, word}_selection
    context.setVariable("selection", selection.getText()); //$NON-NLS-1$
   
    System.out.println(">>>>> Get template list by context id:" + context.getContextType().getId() + "  selection:" + selection.getText());
   
    Template[] templates = getTemplates((IDOMNode) treeNode, offset, context.getContextType().getId(), preChar, preChar2);

    List matches = new ArrayList();
    for (int i = 0; i < templates.length; i++) {
      Template template = templates[i];
      try {
        context.getContextType().validate(template.getPattern());
      }
      catch (TemplateException e) {
        continue;
      }
      if (template.matches(prefix, context.getContextType().getId())) {
        int place = getRelevance(template, prefix);
        matches.add(createProposal(template, context, (IRegion) region, place));
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.