Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 111304 Details for
Bug 245547
[ui] Templates View for XML
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Makes the Templates Pages configurable by Editor
XMLTemplatesPagepatchv2.txt (text/plain), 32.36 KB, created by
David Carver
on 2008-08-29 10:44:33 EDT
(
hide
)
Description:
Makes the Templates Pages configurable by Editor
Filename:
MIME Type:
Creator:
David Carver
Created:
2008-08-29 10:44:33 EDT
Size:
32.36 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.wst.sse.ui >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.35 >diff -u -r1.35 MANIFEST.MF >--- META-INF/MANIFEST.MF 19 Aug 2008 19:37:30 -0000 1.35 >+++ META-INF/MANIFEST.MF 29 Aug 2008 14:39:12 -0000 >@@ -38,6 +38,7 @@ > org.eclipse.wst.sse.ui.internal.selection;x-friends:="org.eclipse.wst.dtd.ui,org.eclipse.wst.xml.ui,org.eclipse.wst.xsd.ui", > org.eclipse.wst.sse.ui.internal.spelling;x-friends:="org.eclipse.wst.dtd.ui,org.eclipse.wst.xml.ui,org.eclipse.wst.xsd.ui", > org.eclipse.wst.sse.ui.internal.taginfo;x-friends:="org.eclipse.wst.dtd.ui,org.eclipse.wst.xml.ui,org.eclipse.wst.xsd.ui", >+ org.eclipse.wst.sse.ui.internal.templates, > org.eclipse.wst.sse.ui.internal.text;x-friends:="org.eclipse.wst.dtd.ui,org.eclipse.wst.xml.ui,org.eclipse.wst.xsd.ui", > org.eclipse.wst.sse.ui.internal.ui;x-friends:="org.eclipse.wst.dtd.ui,org.eclipse.wst.xml.ui,org.eclipse.wst.xsd.ui", > org.eclipse.wst.sse.ui.internal.util;x-friends:="org.eclipse.wst.dtd.ui,org.eclipse.wst.xml.ui,org.eclipse.wst.xsd.ui", >Index: src/org/eclipse/wst/sse/ui/StructuredTextEditor.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextEditor.java,v >retrieving revision 1.97 >diff -u -r1.97 StructuredTextEditor.java >--- src/org/eclipse/wst/sse/ui/StructuredTextEditor.java 9 Aug 2008 19:12:56 -0000 1.97 >+++ src/org/eclipse/wst/sse/ui/StructuredTextEditor.java 29 Aug 2008 14:39:14 -0000 >@@ -8,6 +8,9 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Jens Lukowski/Innoopract - initial renaming/restructuring >+ * David Carver/STAR - bug 245547 - Added ITemplatesPage check to getAdaptor() >+ * Also refactored getAdaptor() for easier >+ * maintenance and readability. > * > *******************************************************************************/ > package org.eclipse.wst.sse.ui; >@@ -135,6 +138,7 @@ > import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; > import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; > import org.eclipse.ui.texteditor.TextOperationAction; >+import org.eclipse.ui.texteditor.templates.ITemplatesPage; > import org.eclipse.ui.views.contentoutline.IContentOutlinePage; > import org.eclipse.ui.views.properties.IPropertySheetPage; > import org.eclipse.wst.sse.core.StructuredModelManager; >@@ -184,6 +188,7 @@ > import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools; > import org.eclipse.wst.sse.ui.internal.provisional.extensions.breakpoint.NullSourceEditingTextTools; > import org.eclipse.wst.sse.ui.internal.selection.SelectionHistory; >+import org.eclipse.wst.sse.ui.internal.templates.AbstractTemplatesPageConfiguration; > import org.eclipse.wst.sse.ui.internal.text.DocumentRegionEdgeMatcher; > import org.eclipse.wst.sse.ui.internal.util.Assert; > import org.eclipse.wst.sse.ui.internal.util.EditorUtility; >@@ -1129,6 +1134,7 @@ > private IDocumentListener fInternalDocumentListener; > private InternalModelStateListener fInternalModelStateListener; > private IContentOutlinePage fOutlinePage; >+ private ITemplatesPage fTemplatesPage; > > private OutlinePageListener fOutlinePageListener = null; > /** This editor's projection model updater */ >@@ -1555,6 +1561,22 @@ > } > return cfg; > } >+ >+ private ITemplatesPage createTemplatesPageConfiguration() { >+ AbstractTemplatesPageConfiguration templatesPageConfiguration = null; >+ ExtendedConfigurationBuilder builder = ExtendedConfigurationBuilder.getInstance(); >+ String[] ids = getConfigurationPoints(); >+ >+ for (int i = 0; templatesPageConfiguration == null && i < ids.length; i++) { >+ templatesPageConfiguration = (AbstractTemplatesPageConfiguration) builder.getConfiguration(ExtendedConfigurationBuilder.TEMPLATESPAGECONFIGURATION, ids[i]); >+ } >+ if (templatesPageConfiguration != null) { >+ if (fTemplatesPage == null) { >+ fTemplatesPage = templatesPageConfiguration.getTemplatePage(this); >+ } >+ } >+ return fTemplatesPage; >+ } > > protected void createModelDependentFields() { > // none at this level >@@ -2083,81 +2105,56 @@ > if (org.eclipse.wst.sse.core.internal.util.Debug.perfTestAdapterClassLoading) { > startPerfTime = System.currentTimeMillis(); > } >- Object result = null; >- // text editor >- IStructuredModel internalModel = getInternalModel(); >+ > if (ITextEditor.class.equals(required)) { >- result = this; >+ return this; > } >- else if (IWorkbenchSiteProgressService.class.equals(required)) { >- return getEditorPart().getSite().getAdapter(IWorkbenchSiteProgressService.class); >+ >+ if (IWorkbenchSiteProgressService.class.equals(required)) { >+ return getWorkbenchSiteProgressService(); > } >- // content outline page >- else if (IContentOutlinePage.class.equals(required)) { >- if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed()) { >- ContentOutlineConfiguration cfg = createContentOutlineConfiguration(); >- if (cfg != null) { >- ConfigurableContentOutlinePage outlinePage = new ConfigurableContentOutlinePage(); >- outlinePage.setConfiguration(cfg); >- if (internalModel != null) { >- outlinePage.setInputContentTypeIdentifier(internalModel.getContentTypeIdentifier()); >- outlinePage.setInput(internalModel); >- } >- >- if (fOutlinePageListener == null) { >- fOutlinePageListener = new OutlinePageListener(); >- } >- >- outlinePage.addSelectionChangedListener(fOutlinePageListener); >- outlinePage.addDoubleClickListener(fOutlinePageListener); >- >- fOutlinePage = outlinePage; >- } >- } >- result = fOutlinePage; >+ >+ if (IWorkbenchSiteProgressService.class.equals(required)) { >+ return getWorkbenchSiteProgressService(); > } >+ > // property sheet page, but only if the input's editable >- else if (IPropertySheetPage.class.equals(required) && isEditable()) { >- if (fPropertySheetPage == null || fPropertySheetPage.getControl() == null || fPropertySheetPage.getControl().isDisposed()) { >- PropertySheetConfiguration cfg = createPropertySheetConfiguration(); >- if (cfg != null) { >- ConfigurablePropertySheetPage propertySheetPage = new ConfigurablePropertySheetPage(); >- propertySheetPage.setConfiguration(cfg); >- fPropertySheetPage = propertySheetPage; >- } >- } >- result = fPropertySheetPage; >+ if (IPropertySheetPage.class.equals(required) && isEditable()) { >+ return getPropertySheetPage(); > } >- else if (IDocument.class.equals(required)) { >- result = getDocumentProvider().getDocument(getEditorInput()); >+ >+ if (IDocument.class.equals(required)) { >+ return getDocument(); > } >- else if (ISourceEditingTextTools.class.equals(required)) { >- result = createSourceEditingTextTools(); >+ >+ if (ISourceEditingTextTools.class.equals(required)) { >+ return createSourceEditingTextTools(); > } >- else if (IToggleBreakpointsTarget.class.equals(required)) { >- result = ToggleBreakpointsTarget.getInstance(); >+ >+ if (IToggleBreakpointsTarget.class.equals(required)) { >+ return ToggleBreakpointsTarget.getInstance(); > } >- else if (IShowInTargetList.class.equals(required)) { >+ >+ if (IShowInTargetList.class.equals(required)) { > return new ShowInTargetListAdapter(); > } >- else if (SelectionHistory.class.equals(required)) { >- if (fSelectionHistory == null) >- fSelectionHistory = new SelectionHistory(this); >- return fSelectionHistory; >+ >+ if (SelectionHistory.class.equals(required)) { >+ return getSelectionHistory(); > } >- else { >- if (result == null && internalModel != null) { >- result = internalModel.getAdapter(required); >- } >- // others >- if (result == null) >- result = super.getAdapter(required); >+ >+ if (ITemplatesPage.class.equals(required)) { >+ return getTemplatesPage(); > } >+ >+ Object result = getInternalModelAdaptors(required); >+ > if (org.eclipse.wst.sse.core.internal.util.Debug.perfTestAdapterClassLoading) { > long stop = System.currentTimeMillis(); > adapterRequests++; > adapterTime += (stop - startPerfTime); > } >+ > if (org.eclipse.wst.sse.core.internal.util.Debug.perfTestAdapterClassLoading) { > System.out.println("Total calls to getAdapter: " + adapterRequests); //$NON-NLS-1$ > System.out.println("Total time in getAdapter: " + adapterTime); //$NON-NLS-1$ >@@ -2166,6 +2163,128 @@ > return result; > } > >+ /** >+ * @param required >+ * @param result >+ * @return >+ */ >+ private Object getInternalModelAdaptors(Class required) { >+ IStructuredModel internalModel = getInternalModel(); >+ Object result = null; >+ // text editor >+ >+ // content outline page >+ if (IContentOutlinePage.class.equals(required)) { >+ result = getOutlinePage(internalModel); >+ } else { >+ result = getInternalAdaptor(required, result, internalModel); >+ } >+ >+ // others >+ if (result == null) >+ result = super.getAdapter(required); >+ return result; >+ } >+ >+ /** >+ * Returns a Workbench Site Progress Service >+ * @return >+ */ >+ private Object getWorkbenchSiteProgressService() { >+ return getEditorPart().getSite().getAdapter(IWorkbenchSiteProgressService.class); >+ } >+ >+ /** >+ * Returens an Internal Model Adapter. >+ * @param required >+ * @param result >+ * @param internalModel >+ * @return >+ */ >+ private Object getInternalAdaptor(Class required, Object result, >+ IStructuredModel internalModel) { >+ if (result == null && internalModel != null) { >+ result = internalModel.getAdapter(required); >+ } >+ return result; >+ } >+ >+ /** >+ * Returns a Selection History Adaptor >+ * @return >+ */ >+ protected Object getSelectionHistory() { >+ if (fSelectionHistory == null) >+ fSelectionHistory = new SelectionHistory(this); >+ return fSelectionHistory; >+ } >+ >+ /** >+ * Returns the current document for the editor. >+ * @return >+ */ >+ protected Object getDocument() { >+ Object result; >+ result = getDocumentProvider().getDocument(getEditorInput()); >+ return result; >+ } >+ >+ /** >+ * Returns a Property Sheet Page >+ * @return >+ */ >+ protected Object getPropertySheetPage() { >+ Object result; >+ if (fPropertySheetPage == null || fPropertySheetPage.getControl() == null || fPropertySheetPage.getControl().isDisposed()) { >+ PropertySheetConfiguration cfg = createPropertySheetConfiguration(); >+ if (cfg != null) { >+ ConfigurablePropertySheetPage propertySheetPage = new ConfigurablePropertySheetPage(); >+ propertySheetPage.setConfiguration(cfg); >+ fPropertySheetPage = propertySheetPage; >+ } >+ } >+ result = fPropertySheetPage; >+ return result; >+ } >+ >+ protected Object getTemplatesPage() { >+ if (fTemplatesPage == null || fTemplatesPage.getControl() == null || fTemplatesPage.getControl().isDisposed()) { >+ fTemplatesPage = createTemplatesPageConfiguration(); >+ } >+ return fTemplatesPage; >+ } >+ >+ /** >+ * Returns the current configural OutlinePage >+ * @param internalModel >+ * @return >+ */ >+ protected Object getOutlinePage(IStructuredModel internalModel) { >+ Object result; >+ if (fOutlinePage == null || fOutlinePage.getControl() == null || fOutlinePage.getControl().isDisposed()) { >+ ContentOutlineConfiguration cfg = createContentOutlineConfiguration(); >+ if (cfg != null) { >+ ConfigurableContentOutlinePage outlinePage = new ConfigurableContentOutlinePage(); >+ outlinePage.setConfiguration(cfg); >+ if (internalModel != null) { >+ outlinePage.setInputContentTypeIdentifier(internalModel.getContentTypeIdentifier()); >+ outlinePage.setInput(internalModel); >+ } >+ >+ if (fOutlinePageListener == null) { >+ fOutlinePageListener = new OutlinePageListener(); >+ } >+ >+ outlinePage.addSelectionChangedListener(fOutlinePageListener); >+ outlinePage.addDoubleClickListener(fOutlinePageListener); >+ >+ fOutlinePage = outlinePage; >+ } >+ } >+ result = fOutlinePage; >+ return result; >+ } >+ > private String[] getConfigurationPoints() { > String contentTypeIdentifierID = null; > if (getInternalModel() != null) { >@@ -2179,19 +2298,16 @@ > * error condition, then viewer will have already been disposed. > */ > protected String getCursorPosition() { >- String result = null; > // this may be too expensive in terms of > // performance, to do this check > // every time, just to gaurd against error > // condition. > // perhaps there's a better way? >+ > if (getSourceViewer() != null && getSourceViewer().getTextWidget() != null && !getSourceViewer().getTextWidget().isDisposed()) { >- result = super.getCursorPosition(); >+ return super.getCursorPosition(); > } >- else { >- result = "0:0"; //$NON-NLS-1$ >- } >- return result; >+ return "0:0"; > } > > >Index: src/org/eclipse/wst/sse/ui/internal/ExtendedConfigurationBuilder.java >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/ExtendedConfigurationBuilder.java,v >retrieving revision 1.6 >diff -u -r1.6 ExtendedConfigurationBuilder.java >--- src/org/eclipse/wst/sse/ui/internal/ExtendedConfigurationBuilder.java 5 Nov 2007 22:20:31 -0000 1.6 >+++ src/org/eclipse/wst/sse/ui/internal/ExtendedConfigurationBuilder.java 29 Aug 2008 14:39:15 -0000 >@@ -8,7 +8,7 @@ > * Contributors: > * IBM Corporation - initial API and implementation > * Jens Lukowski/Innoopract - initial renaming/restructuring >- * >+ * David Carver/STAR - bug 245547 - Added templatesPageConfiguration to provisionalConfiguration > *******************************************************************************/ > package org.eclipse.wst.sse.ui.internal; > >@@ -66,6 +66,12 @@ > * strategy > */ > public static final String DOUBLECLICKSTRATEGY = "doubleClickStrategy"; //$NON-NLS-1$ >+ >+ >+ /** >+ * Extension type to pass into getConfigurations to get TemplatesPages for the Templates Viewer >+ */ >+ public static final String TEMPLATESPAGECONFIGURATION = "templatesPageConfiguration"; > > private static final String ATT_CLASS = "class"; //$NON-NLS-1$ > private static final String ATT_TARGET = "target"; //$NON-NLS-1$ >@@ -137,7 +143,8 @@ > List result = new ArrayList(1); > for (int i = 0; i < configurations.size(); i++) { > IConfigurationElement element = (IConfigurationElement) configurations.get(i); >- if ((element.getName().equals(extensionType) || (element.getName().equals(CONFIGURATION) && extensionType.equals(element.getAttribute(ATT_TYPE))))) { >+ String name = element.getName(); >+ if ((name != null && ( element.getName().equals(extensionType) || (element.getName().equals(CONFIGURATION) && extensionType.equals(element.getAttribute(ATT_TYPE)))))) { > String[] targets = StringUtils.unpack(element.getAttribute(ATT_TARGET)); > for (int j = 0; j < targets.length; j++) { > if (targetID.equals(targets[j].trim())) { >Index: src/org/eclipse/wst/sse/ui/internal/templates/AbstractStructuredTemplatesPage.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/internal/templates/AbstractStructuredTemplatesPage.java >diff -N src/org/eclipse/wst/sse/ui/internal/templates/AbstractStructuredTemplatesPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/internal/templates/AbstractStructuredTemplatesPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,237 @@ >+/******************************************************************************* >+ *Copyright (c) 2008 Standards for Technology in Automotive Retail and others. >+ *All rights reserved. This program and the accompanying materials >+ *are made available under the terms of the Eclipse Public License v1.0 >+ *which accompanies this distribution, and is available at >+ *http://www.eclipse.org/legal/epl-v10.html >+ * >+ *Contributors: >+ * David Carver - bug 245547 - initial API and implementation. based on >+ * JavaTemplatesPage code from eclipse 3.4 >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.internal.templates; >+ >+ >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.jface.text.BadLocationException; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.ITextSelection; >+import org.eclipse.jface.text.ITextViewerExtension; >+import org.eclipse.jface.text.Region; >+import org.eclipse.jface.text.TextSelection; >+import org.eclipse.jface.text.source.ISourceViewer; >+import org.eclipse.jface.text.templates.ContextTypeRegistry; >+import org.eclipse.jface.text.templates.DocumentTemplateContext; >+import org.eclipse.jface.text.templates.Template; >+import org.eclipse.jface.text.templates.TemplateContextType; >+import org.eclipse.jface.text.templates.TemplateProposal; >+import org.eclipse.jface.text.templates.persistence.TemplateStore; >+import org.eclipse.ui.texteditor.ChainedPreferenceStore; >+import org.eclipse.ui.texteditor.templates.AbstractTemplatesPage; >+import org.eclipse.wst.sse.ui.StructuredTextEditor; >+ >+/** >+ * The Structured Templates Page is used by the TemplatesViewer to display available >+ * Structured Templates for use within a XML Structured Text Editor. Implementations are expected >+ * to extend this. >+ * >+ * @author dcarver >+ * >+ */ >+public abstract class AbstractStructuredTemplatesPage extends AbstractTemplatesPage { >+ >+ /** >+ * The Preference Page ID for the Templates >+ */ >+ protected String PREFERENCE_PAGE_ID = null; //$NON-NLS-1$ >+ >+ /** >+ * Template store be used >+ */ >+ protected TemplateStore TEMPLATE_STORE = null; >+ >+ /** >+ * A preference store related to the templates >+ */ >+ protected IPreferenceStore PREFERENCE_STORE = null; >+ >+ /** >+ * Template Context Registry >+ */ >+ protected ContextTypeRegistry TEMPLATE_CONTEXT_REGISTRY = null; >+ >+ /** >+ * An instance of the Structured Text Editor that is related to the Templates View >+ */ >+ protected StructuredTextEditor fTextEditor; >+ >+ /** >+ * An Array of Structured Source Editor Preference Stores. Used in cases >+ * where more than one plugin's preference stores needs to be used. >+ */ >+ protected IPreferenceStore[] SSE_PREFERENCE_STORES; >+ >+ public static final String ID = "templatesPageConfiguration"; >+ >+ >+ public AbstractStructuredTemplatesPage(StructuredTextEditor structuredTextEditor) { >+ super(structuredTextEditor, structuredTextEditor.getTextViewer()); >+ fTextEditor = structuredTextEditor; >+ >+ } >+ >+ >+ /** >+ * This code inserts a specific template into the document at a given location. >+ * It allows takes into affect the ability to do and undo the actions, as well as >+ * replacing the existing text. >+ * >+ * FIXME: Selection is off by one in replacements. >+ */ >+ protected void insertTemplate(Template template, IDocument document) { >+ ISourceViewer contextViewer = fTextEditor.getTextViewer(); >+ ITextSelection textSelection = (ITextSelection) contextViewer >+ .getSelectionProvider().getSelection(); >+ if (!isValidTemplate(document, template, textSelection.getOffset(), >+ textSelection.getLength())) >+ return; >+ beginCompoundChange(contextViewer); >+ /* >+ * The Editor checks whether a completion for a word exists before it >+ * allows for the template to be applied. We pickup the current text at >+ * the selection position and replace it with the first char of the >+ * template name for this to succeed. Another advantage by this method >+ * is that the template replaces the selected text provided the >+ * selection by itself is not used in the template pattern. >+ */ >+ String savedText; >+ try { >+ savedText = document.get(textSelection.getOffset(), textSelection >+ .getLength()); >+ if (savedText.length() == 0) { >+ String prefix = getIdentifierPart(document, template, >+ textSelection.getOffset(), textSelection.getLength()); >+ if (prefix.length() > 0 >+ && !template.getName().startsWith(prefix.toString())) { >+ return; >+ } >+ if (prefix.length() > 0) { >+ contextViewer.setSelectedRange(textSelection.getOffset() >+ - prefix.length(), prefix.length()); >+ textSelection = (ITextSelection) contextViewer >+ .getSelectionProvider().getSelection(); >+ } >+ } >+ document.replace(textSelection.getOffset(), textSelection >+ .getLength(), template.getName().substring(0, 1)); >+ } catch (BadLocationException e) { >+ endCompoundChange(contextViewer); >+ return; >+ } >+ Region region = new Region(textSelection.getOffset() + 1, 0); >+ contextViewer.getSelectionProvider().setSelection( >+ new TextSelection(textSelection.getOffset(), 1)); >+ >+ DocumentTemplateContext context = getContext(document, template, >+ textSelection.getOffset(), textSelection.getLength()); >+ context.setVariable("selection", savedText); //$NON-NLS-1$ >+ if (context.getKey().length() == 0) { >+ try { >+ document.replace(textSelection.getOffset(), 1, savedText); >+ } catch (BadLocationException e) { >+ endCompoundChange(contextViewer); >+ return; >+ } >+ } >+ TemplateProposal proposal = new TemplateProposal(template, context, >+ region, null); >+ fTextEditor.getSite().getPage().activate(fTextEditor); >+ proposal.apply(fTextEditor.getTextViewer(), ' ', 0, region.getOffset()); >+ endCompoundChange(contextViewer); >+ >+ } >+ >+ protected boolean isValidTemplate(IDocument document, Template template, >+ int offset, int length) { >+ String[] contextIds = getContextTypeIds(document, offset); >+ for (int i = 0; i < contextIds.length; i++) { >+ if (contextIds[i].equals(template.getContextTypeId())) { >+ DocumentTemplateContext context = getContext(document, >+ template, offset, length); >+ return context.canEvaluate(template); >+ } >+ } >+ return false; >+ } >+ >+ /** >+ * Undomanager - end compound change >+ * >+ * @param viewer >+ */ >+ private void endCompoundChange(ISourceViewer viewer) { >+ if (viewer instanceof ITextViewerExtension) >+ ((ITextViewerExtension) viewer).getRewriteTarget() >+ .endCompoundChange(); >+ } >+ >+ /** >+ * Undomanager - begin a compound change >+ * >+ * @param viewer >+ */ >+ private void beginCompoundChange(ISourceViewer viewer) { >+ if (viewer instanceof ITextViewerExtension) >+ ((ITextViewerExtension) viewer).getRewriteTarget() >+ .beginCompoundChange(); >+ } >+ >+ /** >+ * Get context >+ * >+ * @param document >+ * @param template >+ * @param offset >+ * @param length >+ * @return the context >+ */ >+ private DocumentTemplateContext getContext(IDocument document, >+ Template template, final int offset, int length) { >+ TemplateContextType contextType = TEMPLATE_CONTEXT_REGISTRY.getContextType(template.getContextTypeId()); >+ return new DocumentTemplateContext(contextType, document, offset, >+ length); >+ } >+ >+ /** >+ * Get the identifier terminated at the given offset >+ * >+ * @param document >+ * @param template >+ * @param offset >+ * @param length >+ * @return the identifier part >+ * @throws BadLocationException >+ */ >+ private String getIdentifierPart(IDocument document, Template template, >+ int offset, int length) throws BadLocationException { >+ return getContext(document, template, offset, length).getKey(); >+ } >+ >+ /** >+ * Create a preference store that combines the source editor preferences >+ * with the base editor's preferences. >+ * >+ * @return IPreferenceStore >+ */ >+ protected IPreferenceStore createCombinedPreferenceStore() { >+ return new ChainedPreferenceStore(getPreferenceStores()); >+ } >+ >+ /** >+ * An array of Preference Stores. Used by createCombinedPreferenceStore >+ * @return >+ */ >+ protected abstract IPreferenceStore[] getPreferenceStores(); >+ >+ >+} >Index: src/org/eclipse/wst/sse/ui/internal/templates/AbstractTemplatesPageConfiguration.java >=================================================================== >RCS file: src/org/eclipse/wst/sse/ui/internal/templates/AbstractTemplatesPageConfiguration.java >diff -N src/org/eclipse/wst/sse/ui/internal/templates/AbstractTemplatesPageConfiguration.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/sse/ui/internal/templates/AbstractTemplatesPageConfiguration.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ *Copyright (c) 2008 Standards for Technology in Automotive Retail and others. >+ *All rights reserved. This program and the accompanying materials >+ *are made available under the terms of the Eclipse Public License v1.0 >+ *which accompanies this distribution, and is available at >+ *http://www.eclipse.org/legal/epl-v10.html >+ * >+ *Contributors: >+ * David Carver (STAR) - bug 245547 - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.sse.ui.internal.templates; >+ >+import org.eclipse.ui.texteditor.templates.ITemplatesPage; >+import org.eclipse.wst.sse.ui.StructuredTextEditor; >+ >+/** >+ * This class provides the configuration information for a Templates Page to be used >+ * by a Structured Text Editor. Because the TemplatesPage interface doesn't have >+ * a base constructor that doesn't take parameters, this calls is used to provide an >+ * interface to instantiate the Templates Page to be used. >+ * @author dcarver >+ * @since 3.1 >+ * >+ */ >+public abstract class AbstractTemplatesPageConfiguration { >+ >+ public AbstractTemplatesPageConfiguration() { >+ >+ } >+ >+ /** >+ * The templates page to be returned. >+ * >+ * @param structuredTextEditor An instance of the structured text editor. This is the >+ * text editor that is used by the templates page view. >+ * @return >+ */ >+ public abstract ITemplatesPage getTemplatePage(StructuredTextEditor structuredTextEditor); >+ >+} >#P org.eclipse.wst.xml.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/sourceediting/plugins/org.eclipse.wst.xml.ui/plugin.xml,v >retrieving revision 1.96 >diff -u -r1.96 plugin.xml >--- plugin.xml 5 Jun 2008 19:01:52 -0000 1.96 >+++ plugin.xml 29 Aug 2008 14:39:16 -0000 >@@ -54,6 +54,10 @@ > class="org.eclipse.wst.xml.ui.internal.text.XMLDocumentRegionEdgeMatcher" > target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> > <provisionalConfiguration >+ type="templatesPageConfiguration" >+ class="org.eclipse.wst.xml.ui.internal.templates.XMLTemplatesPageConfiguration" >+ target="org.eclipse.core.runtime.xml, org.eclipse.core.runtime.xml.source"/> >+ <provisionalConfiguration > type="structuredtextfoldingprovider" > class="org.eclipse.wst.xml.ui.internal.projection.StructuredTextFoldingProviderXML" > target="org.eclipse.core.runtime.xml, org.eclipse.wst.xml.core.xmlsource" /> >Index: src/org/eclipse/wst/xml/ui/internal/templates/XMLTemplatesPageConfiguration.java >=================================================================== >RCS file: src/org/eclipse/wst/xml/ui/internal/templates/XMLTemplatesPageConfiguration.java >diff -N src/org/eclipse/wst/xml/ui/internal/templates/XMLTemplatesPageConfiguration.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/xml/ui/internal/templates/XMLTemplatesPageConfiguration.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,38 @@ >+/******************************************************************************* >+ *Copyright (c) 2008 Standards for Technology in Automotive Retail and others. >+ *All rights reserved. This program and the accompanying materials >+ *are made available under the terms of the Eclipse Public License v1.0 >+ *which accompanies this distribution, and is available at >+ *http://www.eclipse.org/legal/epl-v10.html >+ * >+ *Contributors: >+ * David Carver (STAR) - bug 245547 - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.wst.xml.ui.internal.templates; >+ >+import org.eclipse.ui.texteditor.templates.ITemplatesPage; >+import org.eclipse.wst.sse.ui.StructuredTextEditor; >+import org.eclipse.wst.sse.ui.internal.templates.AbstractTemplatesPageConfiguration; >+ >+/** >+ * Implements a Templates Page Configuration for the XML editor. >+ * >+ * @author dcarver >+ * @since 3.1 >+ */ >+public class XMLTemplatesPageConfiguration extends >+ AbstractTemplatesPageConfiguration { >+ >+ /** >+ * This returns an instance of ITemplatesPage that implements the XML Templates for the >+ * Templates View. It is used by the templatesPageConfiguration provisionalProvider >+ * extension point for a structured Source Editor. >+ * >+ * @param structuredTextEditor The structured text editor that relates to the Templates Page >+ * @return ITemplatesPage An instance of XMLTemplatesPage for the StructuredTextEditor >+ */ >+ public ITemplatesPage getTemplatePage(StructuredTextEditor structuredTextEditor) { >+ return new XMLTemplatesPage(structuredTextEditor); >+ } >+ >+} >Index: src/org/eclipse/wst/xml/ui/internal/templates/XMLTemplatesPage.java >=================================================================== >RCS file: src/org/eclipse/wst/xml/ui/internal/templates/XMLTemplatesPage.java >diff -N src/org/eclipse/wst/xml/ui/internal/templates/XMLTemplatesPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/xml/ui/internal/templates/XMLTemplatesPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,101 @@ >+/******************************************************************************* >+ *Copyright (c) 2008 Standards for Technology in Automotive Retail and others. >+ *All rights reserved. This program and the accompanying materials >+ *are made available under the terms of the Eclipse Public License v1.0 >+ *which accompanies this distribution, and is available at >+ *http://www.eclipse.org/legal/epl-v10.html >+ * >+ *Contributors: >+ * David Carver - bug 245547 - initial API and implementation. based on >+ * JavaTemplatesPage code from eclipse 3.4 >+ *******************************************************************************/ >+package org.eclipse.wst.xml.ui.internal.templates; >+ >+import org.eclipse.jface.preference.IPreferenceStore; >+import org.eclipse.jface.text.IDocument; >+import org.eclipse.jface.text.templates.ContextTypeRegistry; >+import org.eclipse.jface.text.templates.persistence.TemplateStore; >+import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; >+import org.eclipse.wst.sse.ui.StructuredTextEditor; >+import org.eclipse.wst.sse.ui.internal.templates.AbstractStructuredTemplatesPage; >+ >+/** >+ * The XML Templates Page is used by the TemplatesViewer to display available >+ * XML Templates for use within a XML Structured Text Editor. >+ * >+ * @author dcarver >+ * @since 3.1 >+ */ >+public class XMLTemplatesPage extends AbstractStructuredTemplatesPage { >+ >+ protected String PREFERENCE_PAGE_ID = "org.eclipse.wst.sse.ui.preferences.xml.templates"; //$NON-NLS-1$ >+ protected TemplateStore TEMPLATE_STORE = XMLUIPlugin.getDefault().getTemplateStore(); >+ protected ContextTypeRegistry TEMPLATE_CONTEXT_REGISTRY = XMLUIPlugin >+ .getDefault().getTemplateContextRegistry(); >+ >+ protected IPreferenceStore PREFERENCE_STORE; >+ >+ /** >+ * Constructor that creates the initial Templates page. It takes a >+ * StructuredTextEditor as a parameter. >+ * @param structuredTextEditor >+ */ >+ public XMLTemplatesPage(StructuredTextEditor structuredTextEditor) { >+ super(structuredTextEditor); >+ PREFERENCE_STORE = this.createCombinedPreferenceStore(); >+ } >+ >+ >+ /* >+ * (non-Javadoc) >+ * @see org.eclipse.ui.texteditor.templates.AbstractTemplatesPage#getContextTypeIds(org.eclipse.jface.text.IDocument, int) >+ */ >+ protected String[] getContextTypeIds(IDocument document, int offset) { >+ return new String[] { TemplateContextTypeIdsXML.ALL, >+ TemplateContextTypeIdsXML.ATTRIBUTE, >+ TemplateContextTypeIdsXML.TAG, TemplateContextTypeIdsXML.TAG }; >+ } >+ >+ >+ /* >+ * (non-Javadoc) >+ * @see org.eclipse.ui.texteditor.templates.AbstractTemplatesPage#getContextTypeRegistry() >+ */ >+ protected ContextTypeRegistry getContextTypeRegistry() { >+ return TEMPLATE_CONTEXT_REGISTRY; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * @see org.eclipse.ui.texteditor.templates.AbstractTemplatesPage#getPreferencePageId() >+ */ >+ protected String getPreferencePageId() { >+ return PREFERENCE_PAGE_ID; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * @see org.eclipse.ui.texteditor.templates.AbstractTemplatesPage#getTemplateStore() >+ */ >+ protected TemplateStore getTemplateStore() { >+ return TEMPLATE_STORE; >+ } >+ >+ /** >+ * Returns a list of preferences stores as an array. More than one >+ * preference store can be returned. Used by the createPrefenceStore >+ * method >+ */ >+ protected IPreferenceStore[] getPreferenceStores() { >+ return new IPreferenceStore[] {XMLUIPlugin.getDefault().getPreferenceStore() }; >+ } >+ >+ /* >+ * (non-Javadoc) >+ * @see org.eclipse.ui.texteditor.templates.AbstractTemplatesPage#getTemplatePreferenceStore() >+ */ >+ protected IPreferenceStore getTemplatePreferenceStore() { >+ return PREFERENCE_STORE; >+ } >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
bjorn.freeman-benson
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 245547
:
111237
| 111304