use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project xtext-eclipse by eclipse.
the class AdvancedTemplatesPreferencePage method updateViewerInput.
@Override
protected void updateViewerInput() {
IStructuredSelection selection = (IStructuredSelection) getTableViewer().getSelection();
if (selection.size() == 1) {
TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
Template template = data.getTemplate();
String name = template.getName();
TemplateContextType contextType = getContextTypeRegistry().getContextType(template.getContextTypeId());
if (contextType != null) {
String prefix = "templates for " + grammarAccess.getGrammar().getName() + "'" + name + "'" + " for " + getContextTypeForGrammar(contextType) + ">>";
String editablePart = template.getPattern();
String suffix = "";
partialEditor.updateModel(prefix, editablePart, suffix);
} else {
partialEditor.updateModel("", template.getPattern(), "");
}
} else {
partialEditor.updateModel("", "", "");
}
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class ContributionTemplateStore method loadContributedTemplates.
/**
* Loads the templates contributed via the templates extension point.
*
* @throws IOException {@inheritDoc}
*/
@Override
protected void loadContributedTemplates() throws IOException {
IConfigurationElement[] extensions = getTemplateExtensions();
Collection<TemplatePersistenceData> contributed = readContributedTemplates(extensions);
for (Iterator<TemplatePersistenceData> it = contributed.iterator(); it.hasNext(); ) {
TemplatePersistenceData data = it.next();
internalAdd(data);
}
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class ContributionTemplateStore method createTemplate.
private void createTemplate(Collection<TemplatePersistenceData> map, IConfigurationElement element) {
String contextTypeId = element.getAttribute(CONTEXT_TYPE_ID);
// log failures since extension point id and name are mandatory
if (contextExists(contextTypeId)) {
String id = element.getAttribute(ID);
if (isValidTemplateId(id)) {
String name = element.getAttribute(NAME);
if (name != null) {
String pattern = element.getChildren(PATTERN)[0].getValue();
if (pattern != null) {
String desc = element.getAttribute(DESCRIPTION);
if (desc == null)
// $NON-NLS-1$
desc = "";
String autoInsert = element.getAttribute(AUTO_INSERT);
boolean bAutoInsert;
if (autoInsert == null)
bAutoInsert = true;
else
bAutoInsert = Boolean.valueOf(autoInsert).booleanValue();
Template template = new Template(name, desc, contextTypeId, pattern, bAutoInsert);
TemplatePersistenceData data = new TemplatePersistenceData(template, true, id);
if (validateTemplate(template))
map.add(data);
}
}
}
}
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method addTemplate.
/**
* Add a template. The dialog is filled with the values from the given template.
*
* @param template the template
*/
private void addTemplate(Template template) {
Template newTemplate;
newTemplate = editTemplate(template, false, true);
if (newTemplate != null) {
TemplatePersistenceData data = new TemplatePersistenceData(newTemplate, true);
getTemplateStore().add(data);
saveTemplateStore();
refresh();
fTreeViewer.setSelection(new StructuredSelection(data), true);
}
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method createActions.
/**
* Create all the actions
*/
private void createActions() {
fInsertAction = new Action(TemplatesMessages.TemplatesPage_insert) {
@Override
public void run() {
TemplatePersistenceData[] selectedTemplates = getSelectedTemplates();
insertTemplate(selectedTemplates[0].getTemplate());
}
};
fInsertAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_INSERT));
fInsertAction.setDisabledImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_INSERT));
fInsertAction.setToolTipText(TemplatesMessages.TemplatesPage_insert_tooltip);
fAddAction = new Action(TemplatesMessages.TemplatesPage_new) {
@Override
public void run() {
addTemplate();
}
};
fAddAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_NEW));
fAddAction.setToolTipText(TemplatesMessages.TemplatesPage_new_tooltip);
fEditAction = new Action(TemplatesMessages.TemplatesPage_edit) {
@Override
public void run() {
editTemplate();
}
};
fEditAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_EDIT));
fEditAction.setDisabledImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_EDIT));
fEditAction.setToolTipText(TemplatesMessages.TemplatesPage_edit_tooltip);
fRemoveAction = new Action(TemplatesMessages.TemplatesPage_remove) {
@Override
public void run() {
removeTemplates();
}
};
fRemoveAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_DLCL_TEMPLATE_DELETE));
fRemoveAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_DELETE));
fRemoveAction.setToolTipText(TemplatesMessages.TemplatesPage_remove_tooltip);
fLinkWithEditorAction = new Action(TemplatesMessages.TemplatesPage_link_to_editor, IAction.AS_CHECK_BOX) {
@Override
public void run() {
fPreferenceStore.setValue(LINK_ACTION_PREF_ID, fLinkWithEditorAction.isChecked());
refresh();
}
};
fLinkWithEditorAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_LINK));
fLinkWithEditorAction.setChecked(fPreferenceStore.getBoolean(LINK_ACTION_PREF_ID));
fLinkWithEditorAction.setToolTipText(TemplatesMessages.TemplatesPage_link_to_editor_tooltip);
fCollapseAllAction = new Action(TemplatesMessages.TemplatesPage_collapse_all) {
@Override
public void run() {
fTreeViewer.collapseAll();
}
};
fCollapseAllAction.setImageDescriptor(TemplatesPageImages.getDescriptor(TemplatesPageImages.IMG_ELCL_TEMPLATE_COLLAPSE_ALL));
fCollapseAllAction.setToolTipText(TemplatesMessages.TemplatesPage_collapse_all_tooltip);
if (getPreferencePageId() != null) {
fPreferencePageAction = new Action(TemplatesMessages.TemplatesPage_preference_page) {
@Override
public void run() {
showPreferencePage();
}
};
fPreferencePageAction.setToolTipText(TemplatesMessages.TemplatesPage_preference_page_tooltip);
}
fPasteAction = new Action() {
@Override
public void run() {
Clipboard clipboard = new Clipboard(getShell().getDisplay());
try {
String pattern = ((String) clipboard.getContents(TextTransfer.getInstance()));
if (pattern != null) {
// $NON-NLS-1$//$NON-NLS-2$
final Template template = new Template(createTemplateName(), TemplatesMessages.TemplatesPage_paste_description, getContextTypeId(), pattern.replaceAll("\\$", "\\$\\$"), true);
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
addTemplate(template);
}
});
return;
}
TemplatePersistenceData[] templates = (TemplatePersistenceData[]) clipboard.getContents(TemplatesTransfer.getInstance());
if (templates != null)
copyTemplates(templates, getContextTypeId());
} finally {
clipboard.dispose();
}
}
};
fCopyAction = new Action() {
@Override
public void run() {
Clipboard clipboard = new Clipboard(getShell().getDisplay());
try {
clipboard.setContents(new Object[] { getSelectedTemplates() }, new Transfer[] { TemplatesTransfer.getInstance() });
} finally {
clipboard.dispose();
}
}
};
}
Aggregations