Search in sources :

Example 56 with Template

use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.

the class NewHTMLTemplatesWizardPage method saveLastSavedPreferences.

/**
 * Save template name used for next call to New HTML File wizard.
 */
void saveLastSavedPreferences() {
    // $NON-NLS-1$
    String templateName = "";
    Template template = getSelectedTemplate();
    if (template != null) {
        templateName = template.getName();
    }
    HTMLUIPlugin.getDefault().getPreferenceStore().setValue(HTMLUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName);
    HTMLUIPlugin.getDefault().savePluginPreferences();
}
Also used : Template(org.eclipse.jface.text.templates.Template)

Example 57 with Template

use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.

the class CSSTemplateCompletionProcessor method getTemplates.

protected Template[] getTemplates(String contextTypeId) {
    Template[] templates = null;
    TemplateStore store = getTemplateStore();
    if (store != null)
        templates = store.getTemplates(contextTypeId);
    return templates;
}
Also used : TemplateStore(org.eclipse.jface.text.templates.persistence.TemplateStore) Template(org.eclipse.jface.text.templates.Template)

Example 58 with Template

use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.

the class NewCSSTemplatesWizardPage method getTemplateString.

/**
 * Returns template string to insert.
 *
 * @return String to insert or null if none is to be inserted
 */
String getTemplateString() {
    String templateString = null;
    Template template = getSelectedTemplate();
    if (template != null) {
        TemplateContextType contextType = CSSUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsCSS.NEW);
        IDocument document = new Document();
        TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0);
        try {
            TemplateBuffer buffer = context.evaluate(template);
            templateString = buffer.getString();
        } catch (Exception e) {
            // $NON-NLS-1$
            Logger.log(Logger.WARNING_DEBUG, "Could not create template for new css", e);
        }
    }
    return templateString;
}
Also used : DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) TemplateBuffer(org.eclipse.jface.text.templates.TemplateBuffer) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) DocumentTemplateContext(org.eclipse.jface.text.templates.DocumentTemplateContext) TemplateContext(org.eclipse.jface.text.templates.TemplateContext) TemplateContextType(org.eclipse.jface.text.templates.TemplateContextType) IDocument(org.eclipse.jface.text.IDocument) Template(org.eclipse.jface.text.templates.Template)

Example 59 with Template

use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.

the class NewCSSTemplatesWizardPage 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 CSS Template
    fUseTemplateButton = new Button(parent, SWT.CHECK);
    fUseTemplateButton.setText(CSSUIMessages.NewCSSTemplatesWizardPage_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(CSSUIMessages.NewCSSTemplatesWizardPage_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(CSSUIMessages.NewCSSTemplatesWizardPage_2);
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    column2.setText(CSSUIMessages.NewCSSTemplatesWizardPage_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 = CSSUIPlugin.getDefault().getTemplateStore();
    fTableViewer.setInput(fTemplateStore);
    // Create linked text to just to templates preference page
    Link link = new Link(parent, SWT.NONE);
    link.setText(CSSUIMessages.NewCSSTemplatesWizardPage_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.CSS_NEWWIZARD_TEMPLATE_HELPID);
    Dialog.applyDialogFont(parent);
    setControl(parent);
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) TableViewer(org.eclipse.jface.viewers.TableViewer) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer) Viewer(org.eclipse.jface.viewers.Viewer) SourceViewer(org.eclipse.jface.text.source.SourceViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) Template(org.eclipse.jface.text.templates.Template) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableLayout(org.eclipse.jface.viewers.TableLayout) TableViewer(org.eclipse.jface.viewers.TableViewer) Link(org.eclipse.swt.widgets.Link)

Example 60 with Template

use of org.eclipse.jface.text.templates.Template in project webtools.sourceediting by eclipse.

the class NewCSSTemplatesWizardPage 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);
}
Also used : Template(org.eclipse.jface.text.templates.Template)

Aggregations

Template (org.eclipse.jface.text.templates.Template)158 CodeTemplateContext (org.eclipse.jdt.internal.corext.template.java.CodeTemplateContext)27 TemplateBuffer (org.eclipse.jface.text.templates.TemplateBuffer)22 TemplateException (org.eclipse.jface.text.templates.TemplateException)21 TemplateContext (org.eclipse.jface.text.templates.TemplateContext)19 IDocument (org.eclipse.jface.text.IDocument)18 Document (org.eclipse.jface.text.Document)17 ArrayList (java.util.ArrayList)15 BadLocationException (org.eclipse.jface.text.BadLocationException)15 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)15 TemplateContextType (org.eclipse.jface.text.templates.TemplateContextType)14 TemplatePersistenceData (org.eclipse.jface.text.templates.persistence.TemplatePersistenceData)13 TemplateStore (org.eclipse.jface.text.templates.persistence.TemplateStore)12 CoreException (org.eclipse.core.runtime.CoreException)11 Region (org.eclipse.jface.text.Region)11 DocumentTemplateContext (org.eclipse.jface.text.templates.DocumentTemplateContext)11 ISubReference (org.eclipse.titan.designer.AST.ISubReference)11 IRegion (org.eclipse.jface.text.IRegion)10 ITextSelection (org.eclipse.jface.text.ITextSelection)10 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)10