Package org.eclipse.jface.text.templates

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


   * @param contextId the contextId
   *
   */
  private void moveTemplates(TemplatePersistenceData[] templates, String contextId) {
    for (int i= 0; i < templates.length; i++) {
      Template t= templates[i].getTemplate();
      templates[i].setTemplate(new Template(t.getName(), t.getDescription(), contextId, t
          .getPattern(), t.isAutoInsertable()));
    }
    saveTemplateStore();
    fTreeViewer.setSelection(new StructuredSelection(templates), true);
  }
View Full Code Here


     * @since 3.1
     */
    protected void okPressed() {
      String name= fNameText == null ? fOriginalTemplate.getName() : fNameText.getText();
      boolean isAutoInsertable= fAutoInsertCheckbox != null && fAutoInsertCheckbox.getSelection();
      fNewTemplate= new Template(name, fDescriptionText.getText(), getContextId(), fPatternEditor.getDocument().get(), isAutoInsertable);
      super.okPressed();
    }
View Full Code Here

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

      switch (columnIndex) {
        case 0:
          return template.getName();
        case 1:
          TemplateContextType type= fContextTypeRegistry.getContextType(template.getContextTypeId());
          if (type != null)
            return type.getName();
          return template.getContextTypeId();
        case 2:
          return template.getDescription();
        case 3:
          return template.isAutoInsertable() ? TemplatesMessages.TemplatePreferencePage_on : ""//$NON-NLS-1$
        default:
          return ""; //$NON-NLS-1$
      }
    }
View Full Code Here

   *
   */
  private void copyTemplates(TemplatePersistenceData[] templates, String contextId) {
    TemplatePersistenceData[] newTemplates= new TemplatePersistenceData[templates.length];
    for (int i= 0; i < templates.length; i++) {
      Template t= templates[i].getTemplate();
      newTemplates[i]= new TemplatePersistenceData(new Template(t.getName(), t
          .getDescription(), contextId, t.getPattern(), t.isAutoInsertable()), true);
      getTemplateStore().add(newTemplates[i]);
    }
    saveTemplateStore();
    refresh();
    fTreeViewer.setSelection(new StructuredSelection(newTemplates), true);
View Full Code Here

          contextId= ((TemplateContextType) object).getId();
        else
          contextId= ((TemplatePersistenceData) object).getTemplate().getContextTypeId();
        if (textTransfer.isSupportedType(event.currentDataType)) {
          String text= ((String) event.data).replaceAll("\\$", "\\$\\$"); //$NON-NLS-1$ //$NON-NLS-2$
          final Template template= new Template(createTemplateName(),
              TemplatesMessages.TemplatesPage_paste_description, contextId, text,
              true);
          getShell().getDisplay().asyncExec(new Runnable() {
            public void run() {
              addTemplate(template);
View Full Code Here

     *      java.lang.Object, java.lang.Object)
     */
    public int compare(Viewer viewer, Object object1, Object object2) {
      if ((object1 instanceof TemplatePersistenceData)
          && (object2 instanceof TemplatePersistenceData)) {
        Template left= ((TemplatePersistenceData) object1).getTemplate();
        Template right= ((TemplatePersistenceData) object2).getTemplate();
        int result= Collator.getInstance().compare(left.getName(), right.getName());
        if (result != 0)
          return result;
        return Collator.getInstance()
            .compare(left.getDescription(), right.getDescription());
      }
      if ((object1 instanceof TemplateContextType)
          && (object2 instanceof TemplateContextType)) {
        return Collator.getInstance().compare(((TemplateContextType) object1).getName(),
            ((TemplateContextType) object1).getName());
View Full Code Here

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

        List matches= new ArrayList();
        String prefixLowerCase = prefix.toLowerCase();
        for (int i= 0; i < templates.length; i++) {
            Template template= templates[i];
            if (!context.canEvaluate(template, prefix)) {
                continue;
            }
            try {
                context.getContextType().validate(template.getPattern());
            } catch (TemplateException e) {
                continue;
            }

            if (prefixLowerCase.length() == 0) {
                // original code: doesn't use prefix
                if (template.matches(prefixLowerCase, context.getContextType().getId())) {
                    matches.add(createProposal(template, context, (IRegion) region, getRelevance(template, prefix)));
                }
            } else {
                // as per http://dev.eclipse.org/newslists/news.eclipse.platform/msg26165.html
                if (template.matches(prefix, context.getContextType().getId()) &&
                    template.getName().toLowerCase().startsWith(prefixLowerCase)) {
                    matches.add(createProposal(template, context, (IRegion)region,getRelevance(template, prefixLowerCase)));
                }           
            }
        }
View Full Code Here

            throw new RuntimeException(e);
        }
    }

    private Template createNewTemplate(Template template, String newString) {
        return new Template(template.getName(), template.getDescription(), template.getContextTypeId(), newString,
                template.isAutoInsertable());
    }
View Full Code Here

        }

        IRegion region = ps.getRegion();
        TemplateContext context = createContext(edit.getPySourceViewer(), region, ps.getDoc());

        Template t = new Template("Convert", "% to .format()", "", replacementString, false);
        l.add(new TemplateProposal(t, context, region, imageCache.get(UIConstants.COMPLETION_TEMPLATE), 5));
        return l;
    }
View Full Code Here

        return l;
    }

    private ICompletionProposal createProposal(PySelection ps, ImageCache imageCache, PyEdit edit,
            final String startIndent, IRegion region, int iComp, String comp, TemplateContext context) {
        Template t = new Template("Surround with", SURROUND_WITH_COMPLETIONS[iComp + 1], "", comp, false);
        if (context != null) {
            TemplateProposal proposal = new TemplateProposal(t, context, region,
                    imageCache.get(UIConstants.COMPLETION_TEMPLATE), 5) {
                @Override
                public String getAdditionalProposalInfo() {
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.