Ejemplo n.º 1
0
  @Override
  protected String getTemplateType() {
    if (this.window != null) {
      this.editorPart =
          this.window.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    }
    final String fileName =
        this.editorPart == null ? EMPTY_STR : this.editorPart.getEditorInput().getName();
    String[] snippetTypes =
        TemplateSettings.getEnabledTemplateTypes(fileName, this.templatePrefix)
            .toArray(new String[0]);
    snippetTypes = removeExcludedTemplates(snippetTypes, EXCLUDED_TEMPLATES, fileName);
    if (snippetTypes == null || snippetTypes.length == 0) {
      return null;
    }

    final Shell shell =
        this.editorPart == null ? new Shell() : this.editorPart.getSite().getShell();

    final List<String> snpTypes = new ArrayList<String>();
    for (final String snpTyp : snippetTypes) {
      final TemplateSettings templateSetting = super.getTemplateSettings(snpTyp);
      if (templateSetting != null) {
        snpTypes.add(snpTyp);
      }
    }
    snippetTypes = snpTypes.toArray(new String[0]);
    if (snippetTypes == null || snippetTypes.length == 0) {
      return null;
    }
    if (snippetTypes.length == 1) {
      return MessageDialog.openConfirm(
              shell,
              "Confirm",
              "Only one snippet type available for this file, it is "
                  + makeWord(snippetTypes[0])
                  + ". Continue?")
          ? snippetTypes[0]
          : null;
    }

    for (int i = 0; i < snippetTypes.length; i++) {
      snippetTypes[i] =
          snippetTypes[i].replaceFirst("^" + this.templatePrefix + UNDERSCORE, EMPTY_STR);
    }
    final FastCodeSelectionDialog snippetSelectionDialog =
        new StringSelectionDialog(
            shell, "Snippet Types", "Please select one of the snippet types", snippetTypes, false);
    if (snippetSelectionDialog.open() == Window.CANCEL) {
      return null;
    }

    this.templateType =
        this.templatePrefix + UNDERSCORE + (String) snippetSelectionDialog.getResult()[0];
    this.description = makeWord(this.templateType);
    return this.templateType;
  }
 @Override
 public boolean performOk() {
   if (!isEmpty(getErrorMessage())) {
     openError(getShell(), "Error", "There are errors present, cannot save.");
     return false;
   }
   final boolean status = super.performOk();
   TemplateSettings.setReload(status);
   // TemplateSettings.setTemplateSave(true);
   return status;
 }
Ejemplo n.º 3
0
  /** @return */
  protected String[] getTemplateTypes() {
    if (this.window != null) {
      this.editorPart =
          this.window.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    }
    final String fileName =
        this.editorPart == null ? EMPTY_STR : this.editorPart.getEditorInput().getName();
    String[] snippetTypes =
        TemplateSettings.getEnabledTemplateTypes(fileName, this.templatePrefix)
            .toArray(new String[0]);
    snippetTypes = removeExcludedTemplates(snippetTypes, EXCLUDED_TEMPLATES, fileName);
    if (snippetTypes == null || snippetTypes.length == 0) {
      return null;
    }

    final Shell shell =
        this.editorPart == null ? new Shell() : this.editorPart.getSite().getShell();

    final List<String> snpTypes = new ArrayList<String>();
    for (final String snpTyp : snippetTypes) {
      final TemplateSettings templateSetting = super.getTemplateSettings(snpTyp);
      if (templateSetting != null) {
        snpTypes.add(snpTyp);
      }
    }
    snippetTypes = snpTypes.toArray(new String[0]);
    if (snippetTypes == null || snippetTypes.length == 0) {
      return null;
    }

    for (int i = 0; i < snippetTypes.length; i++) {
      snippetTypes[i] =
          snippetTypes[i].replaceFirst("^" + this.templatePrefix + UNDERSCORE, EMPTY_STR);
    }
    return snippetTypes;
  }