use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewJSPTemplatesWizardPage method getSelectedTemplate.
/**
* Get the currently selected template.
*
* @return
*/
private Template getSelectedTemplate() {
Template template = null;
IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection();
if (selection.size() == 1) {
template = (Template) selection.getFirstElement();
}
return template;
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewJSPTemplatesWizardPage method loadLastSavedPreferences.
/**
* Load the last template name used in New JSP File wizard.
*/
private void loadLastSavedPreferences() {
// $NON-NLS-1$
fLastSelectedTemplateName = "";
boolean setSelection = false;
String templateName = JSPUIPlugin.getDefault().getPreferenceStore().getString(JSPUIPreferenceNames.NEW_FILE_TEMPLATE_NAME);
if (templateName == null || templateName.length() == 0) {
templateName = JSPUIPlugin.getDefault().getPreferenceStore().getString(JSPUIPreferenceNames.NEW_FILE_TEMPLATE_ID);
if (templateName != null && templateName.length() > 0) {
Template template = fTemplateStore.findTemplateById(templateName);
if (template != null) {
fLastSelectedTemplateName = template.getName();
setSelection = true;
}
}
} else {
fLastSelectedTemplateName = templateName;
setSelection = true;
}
fUseTemplateButton.setSelection(setSelection);
enableTemplates();
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewJSPTemplatesWizardPage method enableTemplates.
/**
* Enable/disable controls in page based on fUseTemplateButton's current
* state.
*/
void enableTemplates() {
boolean enabled = fUseTemplateButton.getSelection();
if (!enabled) {
// save last selected template
Template template = getSelectedTemplate();
if (template != null)
fLastSelectedTemplateName = template.getName();
else
// $NON-NLS-1$
fLastSelectedTemplateName = "";
fTableViewer.setSelection(null);
} else {
setSelectedTemplate(fLastSelectedTemplateName);
}
fTableViewer.getControl().setEnabled(enabled);
fPatternViewer.getControl().setEnabled(enabled);
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewTagTemplatesWizardPage method enableTemplates.
/**
* Enable/disable controls in page based on fUseTemplateButton's current
* state.
*/
void enableTemplates() {
boolean enabled = fUseTemplateButton.getSelection();
if (!enabled) {
// save last selected template
Template template = getSelectedTemplate();
if (template != null)
fLastSelectedTemplateName = template.getName();
else
// $NON-NLS-1$
fLastSelectedTemplateName = "";
fTableViewer.setSelection(null);
} else {
setSelectedTemplate(fLastSelectedTemplateName);
}
fTableViewer.getControl().setEnabled(enabled);
fPatternViewer.getControl().setEnabled(enabled);
}
use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.
the class NewTagTemplatesWizardPage method createControl.
public void createControl(Composite ancestor) {
Composite parent = new Composite(ancestor, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
parent.setLayout(layout);
// create checkbox for user to use JSP Template
fUseTemplateButton = new Button(parent, SWT.CHECK);
fUseTemplateButton.setText(JSPUIMessages.NewTagTemplatesWizardPage_4);
GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
fUseTemplateButton.setLayoutData(data);
fUseTemplateButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
enableTemplates();
}
});
// create composite for Templates table
Composite innerParent = new Composite(parent, SWT.NONE);
GridLayout innerLayout = new GridLayout();
innerLayout.numColumns = 2;
innerLayout.marginHeight = 0;
innerLayout.marginWidth = 0;
innerParent.setLayout(innerLayout);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
innerParent.setLayoutData(gd);
Label label = new Label(innerParent, SWT.NONE);
label.setText(JSPUIMessages.NewTagTemplatesWizardPage_7);
data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1);
label.setLayoutData(data);
// create table that displays templates
Table table = new Table(innerParent, SWT.BORDER | SWT.FULL_SELECTION);
data = new GridData(GridData.FILL_BOTH);
data.widthHint = convertWidthInCharsToPixels(2);
data.heightHint = convertHeightInCharsToPixels(10);
data.horizontalSpan = 2;
table.setLayoutData(data);
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableLayout tableLayout = new TableLayout();
table.setLayout(tableLayout);
TableColumn column1 = new TableColumn(table, SWT.NONE);
column1.setText(JSPUIMessages.NewTagTemplatesWizardPage_2);
TableColumn column2 = new TableColumn(table, SWT.NONE);
column2.setText(JSPUIMessages.NewTagTemplatesWizardPage_3);
fTableViewer = new TableViewer(table);
fTableViewer.setLabelProvider(new TemplateLabelProvider());
fTableViewer.setContentProvider(new TemplateContentProvider());
fTableViewer.setSorter(new ViewerSorter() {
public int compare(Viewer viewer, Object object1, Object object2) {
if ((object1 instanceof Template) && (object2 instanceof Template)) {
Template left = (Template) object1;
Template right = (Template) object2;
int result = left.getName().compareToIgnoreCase(right.getName());
if (result != 0)
return result;
return left.getDescription().compareToIgnoreCase(right.getDescription());
}
return super.compare(viewer, object1, object2);
}
public boolean isSorterProperty(Object element, String property) {
return true;
}
});
fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent e) {
updateViewerInput();
}
});
// create viewer that displays currently selected template's contents
fPatternViewer = doCreateViewer(parent);
fTemplateStore = JSPUIPlugin.getDefault().getTemplateStore();
fTableViewer.setInput(fTemplateStore);
// Create linked text to just to templates preference page
Link link = new Link(parent, SWT.NONE);
link.setText(JSPUIMessages.NewTagTemplatesWizardPage_6);
data = new GridData(SWT.END, SWT.FILL, true, false, 2, 1);
link.setLayoutData(data);
link.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
linkClicked();
}
});
configureTableResizing(innerParent, table, column1, column2);
loadLastSavedPreferences();
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.JSP_NEWWIZARD_TEMPLATE_HELPID);
Dialog.applyDialogFont(parent);
setControl(parent);
}
Aggregations