[208933] add provisionalConfiguration for slave formatting strategy
diff --git a/bundles/org.eclipse.jst.jsp.ui/plugin.xml b/bundles/org.eclipse.jst.jsp.ui/plugin.xml
index 7355c47..37b116f 100644
--- a/bundles/org.eclipse.jst.jsp.ui/plugin.xml
+++ b/bundles/org.eclipse.jst.jsp.ui/plugin.xml
@@ -38,6 +38,14 @@
<propertySheetConfiguration
class="org.eclipse.wst.xml.ui.views.properties.XMLPropertySheetConfiguration"
target="org.eclipse.jst.jsp.core.jspsource" />
+ <documentationTextHover
+ class="org.eclipse.jst.jsp.ui.internal.taginfo.JSPTagInfoHoverProcessor"
+ target="org.eclipse.jst.jsp.DEFAULT_JSP, org.eclipse.jst.jsp.JSP_DIRECTIVE">
+ </documentationTextHover>
+ <documentationTextHover
+ class="org.eclipse.jst.jsp.ui.internal.taginfo.JSPJavaJavadocHoverProcessor"
+ target="org.eclipse.jst.jsp.SCRIPT.JAVA">
+ </documentationTextHover>
<provisionalConfiguration
type="sourceeditingtexttools"
class="org.eclipse.jst.jsp.ui.internal.editor.JSPSourceEditingTextTools"
@@ -62,14 +70,6 @@
type="spellingregions"
value="XML_COMMENT_TEXT, JSP_COMMENT_TEXT, XML_CONTENT, HTML_CONTENT"
target="org.eclipse.jst.jsp.core.jspsource" />
- <documentationTextHover
- class="org.eclipse.jst.jsp.ui.internal.taginfo.JSPTagInfoHoverProcessor"
- target="org.eclipse.jst.jsp.DEFAULT_JSP, org.eclipse.jst.jsp.JSP_DIRECTIVE">
- </documentationTextHover>
- <documentationTextHover
- class="org.eclipse.jst.jsp.ui.internal.taginfo.JSPJavaJavadocHoverProcessor"
- target="org.eclipse.jst.jsp.SCRIPT.JAVA">
- </documentationTextHover>
</extension>
<!--======================================================================================-->
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextViewerConfigurationJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextViewerConfigurationJSP.java
index 7dd8c58..bc4158f 100644
--- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextViewerConfigurationJSP.java
+++ b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextViewerConfigurationJSP.java
@@ -221,10 +221,16 @@
}
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- MultiPassContentFormatter formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IXMLPartitions.XML_DEFAULT);
+ IContentFormatter formatter = super.getContentFormatter(sourceViewer);
+ // super was unable to create a formatter, probably because
+ // sourceViewer does not have document set yet, so just create a
+ // generic one
+ if (!(formatter instanceof MultiPassContentFormatter))
+ formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IXMLPartitions.XML_DEFAULT);
- formatter.setMasterStrategy(new StructuredFormattingStrategy(new HTMLFormatProcessorImpl()));
- formatter.setSlaveStrategy(new FormattingStrategyJSPJava(), IJSPPartitions.JSP_CONTENT_JAVA);
+ MultiPassContentFormatter multiFormatter = (MultiPassContentFormatter) formatter;
+ multiFormatter.setMasterStrategy(new StructuredFormattingStrategy(new HTMLFormatProcessorImpl()));
+ multiFormatter.setSlaveStrategy(new FormattingStrategyJSPJava(), IJSPPartitions.JSP_CONTENT_JAVA);
return formatter;
}
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/StructuredTextViewerConfigurationCSS.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/StructuredTextViewerConfigurationCSS.java
index c932d49..b470936 100644
--- a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/StructuredTextViewerConfigurationCSS.java
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/StructuredTextViewerConfigurationCSS.java
@@ -89,9 +89,14 @@
}
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- final MultiPassContentFormatter formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), ICSSPartitions.STYLE);
+ IContentFormatter formatter = super.getContentFormatter(sourceViewer);
+ // super was unable to create a formatter, probably because
+ // sourceViewer does not have document set yet, so just create a
+ // generic one
+ if (!(formatter instanceof MultiPassContentFormatter))
+ formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), ICSSPartitions.STYLE);
- formatter.setMasterStrategy(new StructuredFormattingStrategy(new FormatProcessorCSS()));
+ ((MultiPassContentFormatter) formatter).setMasterStrategy(new StructuredFormattingStrategy(new FormatProcessorCSS()));
return formatter;
}
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/StructuredTextViewerConfigurationHTML.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/StructuredTextViewerConfigurationHTML.java
index feafd8d..4da55ee 100644
--- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/StructuredTextViewerConfigurationHTML.java
+++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/StructuredTextViewerConfigurationHTML.java
@@ -77,7 +77,7 @@
*/
private StructuredTextViewerConfiguration fXMLSourceViewerConfiguration;
private ILabelProvider fStatusLineLabelProvider;
-
+
/**
* Create new instance of StructuredTextViewerConfigurationHTML
*/
@@ -136,9 +136,13 @@
}
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- final MultiPassContentFormatter formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IHTMLPartitions.HTML_DEFAULT);
-
- formatter.setMasterStrategy(new StructuredFormattingStrategy(new HTMLFormatProcessorImpl()));
+ IContentFormatter formatter = super.getContentFormatter(sourceViewer);
+ // super was unable to create a formatter, probably because
+ // sourceViewer does not have document set yet, so just create a
+ // generic one
+ if (!(formatter instanceof MultiPassContentFormatter))
+ formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IHTMLPartitions.HTML_DEFAULT);
+ ((MultiPassContentFormatter) formatter).setMasterStrategy(new StructuredFormattingStrategy(new HTMLFormatProcessorImpl()));
return formatter;
}
@@ -149,8 +153,8 @@
return getXMLSourceViewerConfiguration().getDoubleClickStrategy(sourceViewer, IXMLPartitions.XML_DEFAULT);
}
else
- return super.getDoubleClickStrategy(sourceViewer, contentType);
-
+ return super.getDoubleClickStrategy(sourceViewer, contentType);
+
}
public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
diff --git a/bundles/org.eclipse.wst.sse.core/schema/formatProcessors.exsd b/bundles/org.eclipse.wst.sse.core/schema/formatProcessors.exsd
index e5bd5eb..8ed7304 100644
--- a/bundles/org.eclipse.wst.sse.core/schema/formatProcessors.exsd
+++ b/bundles/org.eclipse.wst.sse.core/schema/formatProcessors.exsd
@@ -6,7 +6,7 @@
<meta.schema plugin="org.eclipse.wst.sse.core" id="formatProcessors" name="Format Processors Extension Point"/>
</appInfo>
<documentation>
- This extension point is for defining the format processsor for a content type.
+ <b>This extension point is deprecated and should not be used.</b>
</documentation>
</annotation>
@@ -69,7 +69,7 @@
<meta.section type="since"/>
</appInfo>
<documentation>
- <b>This extension point is internal and should not be used by any other plugins.</b>
+ <b>This extension point is deprecated and should not be used.</b>
</documentation>
</annotation>
@@ -90,30 +90,14 @@
</documentation>
</annotation>
- <annotation>
- <appInfo>
- <meta.section type="apiInfo"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
- <annotation>
- <appInfo>
- <meta.section type="implementation"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
<annotation>
<appInfo>
<meta.section type="copyright"/>
</appInfo>
<documentation>
- Copyright (c) 2005 IBM Corporation and others.<br>
+ Copyright (c) 2005, 2007 IBM Corporation and others.<br>
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 <a
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextMultiPassContentFormatter.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextMultiPassContentFormatter.java
new file mode 100644
index 0000000..af0ac28
--- /dev/null
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextMultiPassContentFormatter.java
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation 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:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.sse.ui;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.TypedPosition;
+import org.eclipse.jface.text.formatter.FormattingContextProperties;
+import org.eclipse.jface.text.formatter.IFormattingContext;
+import org.eclipse.jface.text.formatter.IFormattingStrategy;
+import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
+import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder;
+
+/**
+ * Extends the MultiPassContentFormatter to allow clients to contribute
+ * additional slave formatting strategies via the
+ * <code>org.eclipse.wst.sse.ui.editorConfiguration</code> extension point
+ */
+class StructuredTextMultiPassContentFormatter extends MultiPassContentFormatter {
+ /**
+ * The value of "type" attribute in the provisionalConfiguration element
+ */
+ private static final String SLAVE_FORMATTING_STRATEGY_EXTENDED_ID = "slaveformattingstrategy"; //$NON-NLS-1$
+ /**
+ * list of partition types that already have a formatting strategy
+ */
+ private List fInstalledPartitionTypes;
+
+ /**
+ * Creates a new content formatter.
+ *
+ * @param partitioning
+ * the document partitioning for this formatter
+ * @param type
+ * the default content type
+ */
+ public StructuredTextMultiPassContentFormatter(final String partitioning, final String type) {
+ super(partitioning, type);
+ }
+
+ /*
+ * Overwritten to check for additional slave formatting strategies
+ * contributed via the editorConfiguration extension point.
+ */
+ protected void formatSlave(IFormattingContext context, IDocument document, int offset, int length, String type) {
+ List installedTypes = getInstalledPartitionTypes();
+ if (installedTypes.contains(type)) {
+ // we've already set the slave formatter strategy so just perform
+ // as normal
+ super.formatSlave(context, document, offset, length, type);
+ }
+ else {
+ boolean findExtendedSlaveFormatter = true;
+
+ // need to figure out if there's already a slave formatter set, so
+ // just attempt to format as normal
+ super.formatSlave(context, document, offset, length, type);
+
+ // now, determine if slave formatter was already set by checking
+ // context (it would be set if there's already one)
+ Object contextPartition = context.getProperty(FormattingContextProperties.CONTEXT_PARTITION);
+ if (contextPartition instanceof TypedPosition) {
+ String contextType = ((TypedPosition) contextPartition).getType();
+ if (contextType == type) {
+ // there's already a slave formatter set, so just add it
+ // to the list of installed partition types for future
+ // reference
+ installedTypes.add(type);
+ findExtendedSlaveFormatter = false;
+ }
+ }
+ // no slave formatter is set yet, so try to find one contributed
+ // via the editorConfiguration extension point
+ if (findExtendedSlaveFormatter) {
+ Object configuration = ExtendedConfigurationBuilder.getInstance().getConfiguration(SLAVE_FORMATTING_STRATEGY_EXTENDED_ID, type);
+ if (configuration instanceof IFormattingStrategy) {
+ // found a formatter, so add it in
+ setSlaveStrategy((IFormattingStrategy) configuration, type);
+ // try to format slave again now that one is set
+ super.formatSlave(context, document, offset, length, type);
+ }
+ // note that we've already checked this partition type for
+ // future reference
+ installedTypes.add(type);
+ }
+ }
+ }
+
+ /**
+ * Get the list of partition types that have already been evaluated for
+ * slave formatting strategies for this formatter.
+ *
+ * @return List
+ */
+ private List getInstalledPartitionTypes() {
+ if (fInstalledPartitionTypes == null)
+ fInstalledPartitionTypes = new ArrayList();
+ return fInstalledPartitionTypes;
+ }
+}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextViewerConfiguration.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextViewerConfiguration.java
index 780f076..0e3b9e0 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextViewerConfiguration.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/StructuredTextViewerConfiguration.java
@@ -19,6 +19,9 @@
import org.eclipse.jface.preference.PreferenceConverter;
import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.IAutoEditStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentExtension3;
+import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
@@ -46,6 +49,7 @@
import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
import org.eclipse.ui.texteditor.ChainedPreferenceStore;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredPartitioning;
+import org.eclipse.wst.sse.core.internal.text.rules.StructuredTextPartitioner;
import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder;
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.internal.StructuredTextAnnotationHover;
@@ -318,7 +322,23 @@
* not be supported
*/
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- return null;
+ // try to use the StructuredTextMultiPassContentFormatter so that it
+ // picks up any additional formatting strategies contributed via the
+ // editorConfiguration extension point
+ IContentFormatter formatter = null;
+ if (sourceViewer != null) {
+ IDocument document = sourceViewer.getDocument();
+ if (document instanceof IDocumentExtension3) {
+ String partitioning = getConfiguredDocumentPartitioning(sourceViewer);
+ IDocumentPartitioner partitioner = ((IDocumentExtension3) document).getDocumentPartitioner(partitioning);
+ if (partitioner instanceof StructuredTextPartitioner) {
+ String defaultPartitionType = ((StructuredTextPartitioner) partitioner).getDefaultPartitionType();
+ formatter = new StructuredTextMultiPassContentFormatter(partitioning, defaultPartitionType);
+ }
+ }
+ }
+
+ return formatter;
}
/**
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java
index 69d3786..f737962 100644
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java
+++ b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/StructuredTextViewer.java
@@ -87,6 +87,10 @@
// private ViewerSelectionManager fViewerSelectionManager;
private SourceViewerConfiguration fConfiguration;
+ /*
+ * True if formatter has been set
+ */
+ private boolean fFormatterSet = false;
/**
* @see org.eclipse.jface.text.source.SourceViewer#SourceViewer(Composite,
@@ -133,7 +137,8 @@
}
case FORMAT_DOCUMENT :
case FORMAT_ACTIVE_ELEMENTS : {
- return (fContentFormatter != null && isEditable());
+ // if formatter not set yet, contentformatter can be null
+ return ((fContentFormatter != null || !fFormatterSet) && isEditable());
}
}
return super.canDoOperation(operation);
@@ -746,6 +751,12 @@
// notify highlighter
updateHighlighter(structuredDocument);
+ // set the formatter again now that document has been set
+ if (!fFormatterSet && fConfiguration != null) {
+ fContentFormatter = fConfiguration.getContentFormatter(this);
+ fFormatterSet = true;
+ }
+
// set document in the viewer-based undo manager
if (fUndoManager != null) {
fUndoManager.disconnect();
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java
index b1c1952..d91f9a9 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/StructuredTextViewerConfigurationXML.java
@@ -115,9 +115,13 @@
}
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- final MultiPassContentFormatter formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IXMLPartitions.XML_DEFAULT);
-
- formatter.setMasterStrategy(new StructuredFormattingStrategy(new FormatProcessorXML()));
+ IContentFormatter formatter = super.getContentFormatter(sourceViewer);
+ // super was unable to create a formatter, probably because
+ // sourceViewer does not have document set yet, so just create a
+ // generic one
+ if (!(formatter instanceof MultiPassContentFormatter))
+ formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), IXMLPartitions.XML_DEFAULT);
+ ((MultiPassContentFormatter) formatter).setMasterStrategy(new StructuredFormattingStrategy(new FormatProcessorXML()));
return formatter;
}