Java Code Examples for org.eclipse.jface.text.templates.persistence.TemplatePersistenceData#getId()

The following examples show how to use org.eclipse.jface.text.templates.persistence.TemplatePersistenceData#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GamlTemplateStore.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public void directAdd(final TemplatePersistenceData data, final boolean isEdited) {
	if (isEdited) {
		add(data);
	} else {
		// Trick the template store so that (1) the template is considered
		// as "user added" while (2) maintaining a proper id
		final String id = data.getId();
		final TemplatePersistenceData d2 = new TemplatePersistenceData(data.getTemplate(), true) {

			@Override
			public String getId() {
				return id;
			}

		};
		add(d2);
	}
}
 
Example 2
Source File: ProjectTemplateStore.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void load() throws IOException {
	if (fProjectStore != null) {
		fProjectStore.load();

		Set<String> datas= new HashSet<String>();
		TemplatePersistenceData[] data= fProjectStore.getTemplateData(false);
		for (int i= 0; i < data.length; i++) {
			datas.add(data[i].getId());
		}

		data= fInstanceStore.getTemplateData(false);
		for (int i= 0; i < data.length; i++) {
			TemplatePersistenceData orig= data[i];
			if (!datas.contains(orig.getId())) {
				TemplatePersistenceData copy= new TemplatePersistenceData(new Template(orig.getTemplate()), orig.isEnabled(), orig.getId());
				fProjectStore.add(copy);
				copy.setDeleted(true);
			}
		}
	}
}
 
Example 3
Source File: ConfigurableTemplateStore.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Contribute templates defined in file with the give URL.
 * 
 * @param templates
 *          the URL of the file with templates
 */
private void addTemplatesFromFile(final URL templates) {
  if (templates != null) {
    TemplateReaderWriter reader = new TemplateReaderWriter();
    try {
      InputStream openStream = templates.openStream();
      try {
        TemplatePersistenceData[] datas = reader.read(openStream, null);
        int templateCounter = 0;
        for (TemplatePersistenceData data : datas) {
          if (data.getId() == null) {
            templateCounter++;
            TemplatePersistenceData dataWithGenId = new TemplatePersistenceData(data.getTemplate(), data.isEnabled(), templates.getPath() + "." //$NON-NLS-1$
                + templateCounter);
            dataWithGenId.setDeleted(data.isDeleted());
            internalAdd(dataWithGenId);
          } else {
            // if contributed template has an id
            internalAdd(data);
          }
        }
      } finally {
        openStream.close();
      }
    } catch (IOException e) {
      LOG.error(e);
    }
  }
}
 
Example 4
Source File: CodeTemplateBlock.java    From typescript.java with MIT License 4 votes vote down vote up
public int category(Object element) {
	if (element == COMMENT_NODE) {
		return 1;
	} else if (element == CODE_NODE) {
		return 2;
	}

	TemplatePersistenceData data = (TemplatePersistenceData) element;
	String id = data.getId();

	if (CodeTemplateContextType.NEWTYPE_ID.equals(id)) {
		return 101;
	} else if (CodeTemplateContextType.CLASSBODY_ID.equals(id)) {
		return 102;
	} else if (CodeTemplateContextType.METHODSTUB_ID.equals(id)) {
		return 106;
	} else if (CodeTemplateContextType.CONSTRUCTORSTUB_ID.equals(id)) {
		return 107;
	} else if (CodeTemplateContextType.GETTERSTUB_ID.equals(id)) {
		return 108;
	} else if (CodeTemplateContextType.SETTERSTUB_ID.equals(id)) {
		return 109;
	} else if (CodeTemplateContextType.CATCHBLOCK_ID.equals(id)) {
		return 110;
	} else if (CodeTemplateContextType.FILECOMMENT_ID.equals(id)) {
		return 1;
	} else if (CodeTemplateContextType.TYPECOMMENT_ID.equals(id)) {
		return 2;
	} else if (CodeTemplateContextType.FIELDCOMMENT_ID.equals(id)) {
		return 3;
	} else if (CodeTemplateContextType.CONSTRUCTORCOMMENT_ID.equals(id)) {
		return 4;
	} else if (CodeTemplateContextType.METHODCOMMENT_ID.equals(id)) {
		return 5;
	} else if (CodeTemplateContextType.OVERRIDECOMMENT_ID.equals(id)) {
		return 6;
	} else if (CodeTemplateContextType.DELEGATECOMMENT_ID.equals(id)) {
		return 7;
	} else if (CodeTemplateContextType.GETTERCOMMENT_ID.equals(id)) {
		return 8;
	} else if (CodeTemplateContextType.SETTERCOMMENT_ID.equals(id)) {
		return 9;
	}
	return 1000;
}
 
Example 5
Source File: CodeTemplateBlock.java    From typescript.java with MIT License 4 votes vote down vote up
public String getText(Object element) {
	if (element == COMMENT_NODE || element == CODE_NODE) {
		return (String) element;
	}
	TemplatePersistenceData data = (TemplatePersistenceData) element;
	String id = data.getId();
	// if (CodeTemplateContextType.CATCHBLOCK_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_catchblock_label;
	// } else if (CodeTemplateContextType.METHODSTUB_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_methodstub_label;
	// } else if (CodeTemplateContextType.CONSTRUCTORSTUB_ID.equals(id))
	// {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_constructorstub_label;
	// } else if (CodeTemplateContextType.GETTERSTUB_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_getterstub_label;
	// } else if (CodeTemplateContextType.SETTERSTUB_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_setterstub_label;
	// } else if (CodeTemplateContextType.NEWTYPE_ID.equals(id)) {
	// return JSDTTypeScriptUIMessages.CodeTemplateBlock_newtype_label;
	// } else if (CodeTemplateContextType.CLASSBODY_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_classbody_label;
	// } else if (CodeTemplateContextType.FILECOMMENT_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_filecomment_label;
	// } else if (CodeTemplateContextType.TYPECOMMENT_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_typecomment_label;
	// } else if (CodeTemplateContextType.FIELDCOMMENT_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_fieldcomment_label;
	// } else if (CodeTemplateContextType.METHODCOMMENT_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_methodcomment_label;
	// } else if (CodeTemplateContextType.OVERRIDECOMMENT_ID.equals(id))
	// {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_overridecomment_label;
	// } else if (CodeTemplateContextType.DELEGATECOMMENT_ID.equals(id))
	// {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_delegatecomment_label;
	// } else if
	// (CodeTemplateContextType.CONSTRUCTORCOMMENT_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_constructorcomment_label;
	// } else if (CodeTemplateContextType.GETTERCOMMENT_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_gettercomment_label;
	// } else if (CodeTemplateContextType.SETTERCOMMENT_ID.equals(id)) {
	// return
	// JSDTTypeScriptUIMessages.CodeTemplateBlock_settercomment_label;
	// }
	return data.getTemplate().getDescription();
}
 
Example 6
Source File: TemplateReferenceMenu.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
void add(final TemplatePersistenceData t) {
	final String id = t.getId();
	final List<String> path = new ArrayList<>(Arrays.asList(id.split("\\.")));
	add(t, path);
}
 
Example 7
Source File: CodeTemplateBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public int category(Object element) {
	if (element == COMMENT_NODE) {
		return 1;
	} else if (element == CODE_NODE) {
		return 2;
	}

	TemplatePersistenceData data= (TemplatePersistenceData) element;
	String id= data.getId();

	if (CodeTemplateContextType.NEWTYPE_ID.equals(id)) {
		return 101;
	} else if (CodeTemplateContextType.CLASSBODY_ID.equals(id)) {
		return 102;
	} else if (CodeTemplateContextType.INTERFACEBODY_ID.equals(id)) {
		return 103;
	} else if (CodeTemplateContextType.ENUMBODY_ID.equals(id)) {
		return 104;
	} else if (CodeTemplateContextType.ANNOTATIONBODY_ID.equals(id)) {
		return 105;
	} else if (CodeTemplateContextType.METHODSTUB_ID.equals(id)) {
		return 106;
	} else if (CodeTemplateContextType.CONSTRUCTORSTUB_ID.equals(id)) {
		return 107;
	} else if (CodeTemplateContextType.GETTERSTUB_ID.equals(id)) {
		return 108;
	} else if (CodeTemplateContextType.SETTERSTUB_ID.equals(id)) {
		return 109;
	} else if (CodeTemplateContextType.CATCHBLOCK_ID.equals(id)) {
		return 110;
	} else if (CodeTemplateContextType.FILECOMMENT_ID.equals(id)) {
		return 1;
	} else if (CodeTemplateContextType.TYPECOMMENT_ID.equals(id)) {
		return 2;
	} else if (CodeTemplateContextType.FIELDCOMMENT_ID.equals(id)) {
		return 3;
	} else if (CodeTemplateContextType.CONSTRUCTORCOMMENT_ID.equals(id)) {
		return 4;
	} else if (CodeTemplateContextType.METHODCOMMENT_ID.equals(id)) {
		return 5;
	} else if (CodeTemplateContextType.OVERRIDECOMMENT_ID.equals(id)) {
		return 6;
	} else if (CodeTemplateContextType.DELEGATECOMMENT_ID.equals(id)) {
		return 7;
	} else if (CodeTemplateContextType.GETTERCOMMENT_ID.equals(id)) {
		return 8;
	} else if (CodeTemplateContextType.SETTERCOMMENT_ID.equals(id)) {
		return 9;
	}
	return 1000;
}
 
Example 8
Source File: CodeTemplateBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public String getText(Object element) {
	if (element == COMMENT_NODE || element == CODE_NODE) {
		return (String) element;
	}
	TemplatePersistenceData data= (TemplatePersistenceData) element;
	String id=data.getId();
	if (CodeTemplateContextType.CATCHBLOCK_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_catchblock_label;
	} else if (CodeTemplateContextType.METHODSTUB_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_methodstub_label;
	} else if (CodeTemplateContextType.CONSTRUCTORSTUB_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_constructorstub_label;
	} else if (CodeTemplateContextType.GETTERSTUB_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_getterstub_label;
	} else if (CodeTemplateContextType.SETTERSTUB_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_setterstub_label;
	} else if (CodeTemplateContextType.NEWTYPE_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_newtype_label;
	} else if (CodeTemplateContextType.CLASSBODY_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_classbody_label;
	} else if (CodeTemplateContextType.INTERFACEBODY_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_interfacebody_label;
	} else if (CodeTemplateContextType.ENUMBODY_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_enumbody_label;
	} else if (CodeTemplateContextType.ANNOTATIONBODY_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_annotationbody_label;
	} else if (CodeTemplateContextType.FILECOMMENT_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_filecomment_label;
	} else if (CodeTemplateContextType.TYPECOMMENT_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_typecomment_label;
	} else if (CodeTemplateContextType.FIELDCOMMENT_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_fieldcomment_label;
	} else if (CodeTemplateContextType.METHODCOMMENT_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_methodcomment_label;
	} else if (CodeTemplateContextType.OVERRIDECOMMENT_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_overridecomment_label;
	} else if (CodeTemplateContextType.DELEGATECOMMENT_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_delegatecomment_label;
	} else if (CodeTemplateContextType.CONSTRUCTORCOMMENT_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_constructorcomment_label;
	} else if (CodeTemplateContextType.GETTERCOMMENT_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_gettercomment_label;
	} else if (CodeTemplateContextType.SETTERCOMMENT_ID.equals(id)) {
		return PreferencesMessages.CodeTemplateBlock_settercomment_label;
	}
	return data.getTemplate().getDescription();
}