use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project mdw-designer by CenturyLinkCloud.
the class WorkspaceConfigurator method updateTemplate.
private void updateTemplate(TemplatePersistenceData data) {
ProjectTemplateStore templateStore = new ProjectTemplateStore(null);
TemplatePersistenceData[] dataElements = templateStore.getTemplateData();
for (int i = 0; i < dataElements.length; i++) {
String id = dataElements[i].getId();
if (id != null && id.equals(data.getId())) {
dataElements[i].setTemplate(data.getTemplate());
break;
}
}
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project mdw-designer by CenturyLinkCloud.
the class WorkspaceConfigurator method importTemplates.
protected void importTemplates() {
String baseUrl = getWorkspaceConfig().getMdwSettings().getWorkspaceSetupUrl();
if (!baseUrl.endsWith("/"))
baseUrl += "/";
String templatesUrl = baseUrl;
if (getWorkspaceConfig().getCodeTemplates().equals(WorkspaceConfig.CODE_TEMPLATES[0]))
templatesUrl += "CenturyLinkITCodeTemplates.xml";
else
templatesUrl += "MDWCodeTemplates.xml";
InputStream is = null;
try {
URL url = new URL(templatesUrl);
URLConnection connection = url.openConnection();
is = connection.getInputStream();
TemplateReaderWriter reader = new TemplateReaderWriter();
TemplatePersistenceData[] dataElements = reader.read(is, null);
for (int i = 0; i < dataElements.length; i++) {
updateTemplate(dataElements[i]);
}
} catch (Exception ex) {
PluginMessages.uiError(getShell(), ex, "Import Templates");
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// do nothing
}
}
}
}
use of org.eclipse.jface.text.templates.persistence.TemplatePersistenceData in project KaiZen-OpenAPI-Editor by RepreZen.
the class Activator method addNamedTemplates.
private void addNamedTemplates(String inlineContextId, String namedContextId, String key) {
Template[] schemaTemplates = templateStore.getTemplates(inlineContextId);
for (int i = 0; i < schemaTemplates.length; i++) {
Template schemaTemplate = schemaTemplates[i];
Template template = createNamedTemplate(schemaTemplate, namedContextId, key);
templateStore.add(new TemplatePersistenceData(template, true));
}
}
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 AbstractTemplatesPage method initializeDND.
/**
* Initializes drag and drop the template items
*/
private void initializeDND() {
DragSourceAdapter dragListener = new DragSourceAdapter() {
@Override
public void dragStart(DragSourceEvent event) {
if (getSelectedTemplates().length == 0) {
event.doit = false;
}
}
@Override
public void dragSetData(DragSourceEvent event) {
if (TemplatesTransfer.getInstance().isSupportedType(event.dataType)) {
event.data = getSelectedTemplates();
}
}
};
fTreeViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { TemplatesTransfer.getInstance() }, dragListener);
DropTargetAdapter dropListener = new DropTargetAdapter() {
Transfer textTransfer = TextTransfer.getInstance();
Transfer templateTransfer = TemplatesTransfer.getInstance();
@Override
public void dragEnter(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT)
event.detail = DND.DROP_COPY;
}
@Override
public void dragOperationChanged(DropTargetEvent event) {
if (event.detail == DND.DROP_DEFAULT)
event.detail = DND.DROP_COPY;
}
@Override
public void dragOver(DropTargetEvent event) {
event.feedback |= DND.FEEDBACK_SCROLL;
if (event.item == null) {
event.detail = DND.DROP_NONE;
return;
}
int index = 0;
boolean isTemplateTransfer = false;
while (index < event.dataTypes.length) {
if (textTransfer.isSupportedType(event.dataTypes[index])) {
break;
}
if (templateTransfer.isSupportedType(event.dataTypes[index])) {
isTemplateTransfer = true;
break;
}
index++;
}
if (index < event.dataTypes.length) {
event.currentDataType = event.dataTypes[index];
if (event.detail == DND.DROP_DEFAULT || !isTemplateTransfer)
event.detail = DND.DROP_COPY;
return;
}
}
@Override
public void drop(DropTargetEvent event) {
if (event.item == null)
return;
Object object = ((TreeItem) event.item).getData();
final String contextId;
if (object instanceof TemplateContextType)
contextId = ((TemplateContextType) object).getId();
else
contextId = ((TemplatePersistenceData) object).getTemplate().getContextTypeId();
if (textTransfer.isSupportedType(event.currentDataType)) {
// $NON-NLS-1$ //$NON-NLS-2$
String text = ((String) event.data).replaceAll("\\$", "\\$\\$");
final Template template = new Template(createTemplateName(), TemplatesMessages.TemplatesPage_paste_description, contextId, text, true);
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
addTemplate(template);
}
});
return;
}
if (templateTransfer.isSupportedType(event.currentDataType)) {
final TemplatePersistenceData[] templates = (TemplatePersistenceData[]) event.data;
final int dropType = event.detail;
getShell().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (dropType == DND.DROP_COPY)
copyTemplates(templates, contextId);
else
moveTemplates(templates, contextId);
}
});
}
}
};
Transfer[] transfers = new Transfer[] { TextTransfer.getInstance(), TemplatesTransfer.getInstance() };
fTreeViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, dropListener);
}
Aggregations