use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method getContextTypeId.
/**
* Returns the context type id of the selected template.
*
* @return the context type id of the selected template or the first from the
* registry if no templates are selected
*/
private String getContextTypeId() {
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
Object item;
if (selection.size() == 0)
return getContextTypeRegistry().contextTypes().next().getId();
if (selection.size() == 1) {
item = selection.getFirstElement();
if (item instanceof TemplatePersistenceData)
return ((TemplatePersistenceData) item).getTemplate().getContextTypeId();
return ((TemplateContextType) item).getId();
}
Iterator<?> it = selection.iterator();
String contextId = null;
while (it.hasNext()) {
item = it.next();
if (contextId == null)
contextId = getContextId(item);
else if (!contextId.equals(getContextId(item)))
return getContextTypeRegistry().contextTypes().next().getId();
}
return contextId;
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method setSelectedTemplates.
/**
* Set the selected templates
*/
private void setSelectedTemplates() {
IStructuredSelection selection = (IStructuredSelection) fTreeViewer.getSelection();
Iterator<?> it = selection.iterator();
TemplatePersistenceData[] data = new TemplatePersistenceData[selection.size()];
int i = 0;
while (it.hasNext()) {
Object o = it.next();
if (o instanceof TemplatePersistenceData)
data[i++] = (TemplatePersistenceData) o;
else {
fSelectedTemplates = new TemplatePersistenceData[0];
return;
}
}
fSelectedTemplates = data;
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class AbstractTemplatesPage method copyTemplates.
/**
* Copy the selected templates to another context
*
* @param templates an array of template data
* @param contextId the context id
*/
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);
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class TemplatePreferencePage method updateViewerInput.
/**
* Updates the pattern viewer.
*/
protected void updateViewerInput() {
IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
if (selection.size() == 1) {
TemplatePersistenceData data = (TemplatePersistenceData) selection.getFirstElement();
Template template = data.getTemplate();
fPatternViewer.getDocument().set(template.getPattern());
} else {
// $NON-NLS-1$
fPatternViewer.getDocument().set("");
}
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project eclipse.platform.text by eclipse.
the class TemplatePreferencePage method edit.
private void edit(TemplatePersistenceData data) {
Template oldTemplate = data.getTemplate();
Template newTemplate = editTemplate(new Template(oldTemplate), true, true);
if (newTemplate != null) {
if (!newTemplate.getName().equals(oldTemplate.getName()) && MessageDialog.openQuestion(getShell(), TemplatesMessages.TemplatePreferencePage_question_create_new_title, TemplatesMessages.TemplatePreferencePage_question_create_new_message)) {
data = new TemplatePersistenceData(newTemplate, true);
fTemplateStore.add(data);
fTableViewer.refresh();
} else {
data.setTemplate(newTemplate);
fTableViewer.refresh(data);
}
selectionChanged1();
fTableViewer.setChecked(data, data.isEnabled());
fTableViewer.setSelection(new StructuredSelection(data));
}
}
Aggregations