Package org.eclipse.jface.text.templates

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


    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.getName().startsWith(prefix) &&
          template.matches(prefix, context.getContextType().getId()))
        matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
    }

    return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
  }
View Full Code Here


    context.setVariable("selection", selection.getText()); // name of the selection variables {line, word_selection //$NON-NLS-1$
   
    Template[] templates = getTemplates(context.getContextType().getId());
    List<ICompletionProposal> matches = new ArrayList<ICompletionProposal>();
    for (int i= 0; i < templates.length; i++) {
      Template template= templates[i];
      try {
        context.getContextType().validate(template.getPattern());
      } catch (TemplateException e) {
        continue;
      }
      if(!prefix.equals("") &&prefix.charAt(0)=='<')
        prefix = prefix.substring(1);
      if (!prefix.equals("")&&(template.getName().startsWith(prefix) &&
          template.matches(prefix, context.getContextType().getId())))
        matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
    }
    return matches.toArray(new ICompletionProposal[matches.size()]);
  }
View Full Code Here

    context.setVariable("selection", selection.getText()); // name of the selection variables {line, word_selection //$NON-NLS-1$
   
    Template[] templates = getTemplates(context.getContextType().getId());
    List<ICompletionProposal> matches = new ArrayList<ICompletionProposal>();
    for (int i= 0; i < templates.length; i++) {
      Template template= templates[i];
      try {
        context.getContextType().validate(template.getPattern());
      } catch (TemplateException e) {
        continue;
      }
      if(!prefix.equals("") &&prefix.charAt(0)=='<')
        prefix = prefix.substring(1);
      if (!prefix.equals("")&&(template.getName().startsWith(prefix) &&
          template.matches(prefix, context.getContextType().getId())))
        matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
    }
    return matches.toArray(new ICompletionProposal[matches.size()]);
  }
View Full Code Here

    /*
     * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object,
     *      int)
     */
    public String getColumnText(Object element, int columnIndex) {
      Template template = (Template) element;

      switch (columnIndex) {
        case 0 :
          return template.getName();
        case 1 :
          return template.getDescription();
        default :
          return ""; //$NON-NLS-1$
      }
    }
View Full Code Here

    fTableViewer.setContentProvider(new TemplateContentProvider());

    fTableViewer.setSorter(new ViewerSorter() {
      public int compare(Viewer viewer, Object object1, Object object2) {
        if ((object1 instanceof Template) && (object2 instanceof Template)) {
          Template left = (Template) object1;
          Template right = (Template) object2;
          int result = left.getName().compareToIgnoreCase(right.getName());
          if (result != 0)
            return result;
          return left.getDescription().compareToIgnoreCase(right.getDescription());
        }
        return super.compare(viewer, object1, object2);
      }

      public boolean isSorterProperty(Object element, String property) {
View Full Code Here

  void enableTemplates() {
    boolean enabled = fUseTemplateButton.getSelection();

    if (!enabled) {
      // save last selected template
      Template template = getSelectedTemplate();
      if (template != null)
        fLastSelectedTemplateName = template.getName();
      else
        fLastSelectedTemplateName = ""; //$NON-NLS-1$

      fTableViewer.setSelection(null);
    }
View Full Code Here

   * Get the currently selected template.
   *
   * @return
   */
  private Template getSelectedTemplate() {
    Template template = null;
    IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();

    if (selection.size() == 1) {
      template = (Template) selection.getFirstElement();
    }
View Full Code Here

   * @return String to insert or null if none is to be inserted
   */
  String getTemplateString() {
    String templateString = null;

    Template template = getSelectedTemplate();
    if (template != null) {
      TemplateContextType contextType = JSPUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsJSP.NEW_TAG);
      IDocument document = new Document();
      TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
      try {
View Full Code Here

    boolean setSelection = false;
    String templateName = JSPUIPlugin.getDefault().getPreferenceStore().getString(JSPUIPreferenceNames.NEW_TAG_FILE_TEMPLATE_NAME);
    if (templateName == null || templateName.length() == 0) {
      templateName = JSPUIPlugin.getDefault().getPreferenceStore().getString(JSPUIPreferenceNames.NEW_TAG_FILE_TEMPLATE_ID);
      if (templateName != null && templateName.length() > 0) {
        Template template = fTemplateStore.findTemplateById(templateName);
        if (template != null) {
          fLastSelectedTemplateName = template.getName();
          setSelection = true;
        }
      }
    }
    else {
View Full Code Here

   * Save template name used for next call to New JSP File wizard.
   */
  void saveLastSavedPreferences() {
    String templateName = ""; //$NON-NLS-1$

    Template template = getSelectedTemplate();
    if (template != null) {
      templateName = template.getName();
    }

    JSPUIPlugin.getDefault().getPreferenceStore().setValue(JSPUIPreferenceNames.NEW_TAG_FILE_TEMPLATE_NAME, templateName);
    JSPUIPlugin.getDefault().savePluginPreferences();
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.templates.Template

Copyright © 2018 www.massapicom. 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.