[jbosstools-commits] JBoss Tools SVN: r17810 - trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Tue Sep 29 16:19:58 EDT 2009


Author: dgolovin
Date: 2009-09-29 16:19:58 -0400 (Tue, 29 Sep 2009)
New Revision: 17810

Added:
   trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/ITextViewerConfiguration.java
   trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextViewerConfigurationDelegate.java
Modified:
   trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java
   trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java
Log:
duplicated code was removed from JSP editor

Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java	2009-09-29 19:32:45 UTC (rev 17809)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java	2009-09-29 20:19:58 UTC (rev 17810)
@@ -31,97 +31,29 @@
 import org.jboss.tools.jst.jsp.format.HTMLFormatProcessor;
 import org.osgi.framework.Bundle;
 
-public class HTMLTextViewerConfiguration extends StructuredTextViewerConfigurationHTML {
+public class HTMLTextViewerConfiguration extends StructuredTextViewerConfigurationHTML implements ITextViewerConfiguration{
 
+	TextViewerConfigurationDelegate configurationDelegate;	
 	public HTMLTextViewerConfiguration() {
 		super();
+		configurationDelegate = new TextViewerConfigurationDelegate(this);
 	}
 
 	@SuppressWarnings("restriction")
     protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) {
-		SortingCompoundContentAssistProcessor sortingCompoundProcessor = new SortingCompoundContentAssistProcessor(sourceViewer, partitionType);
-		
-		if (sortingCompoundProcessor.supportsPartitionType(partitionType)) {
-			// Add the default WTP CA processors to our SortingCompoundContentAssistProcessor
-			IContentAssistProcessor[] superProcessors = super.getContentAssistProcessors(sourceViewer, partitionType);
-
-			if (superProcessors != null && superProcessors.length > 0) {
-				for (int i = 0; i < superProcessors.length; i++)
-					sortingCompoundProcessor.addContentAssistProcessor(partitionType, superProcessors[i]);
-			}
-
-			return new IContentAssistProcessor[] {sortingCompoundProcessor};
-		}
-
-		
-		return new IContentAssistProcessor[0];
+		return configurationDelegate.getContentAssistProcessors(sourceViewer, partitionType);
 	}
 
-
 	/*
 	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer)
 	 * @since 3.1
 	 */
 	public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
-		if (fPreferenceStore == null)
-			return null;
-		if (sourceViewer == null || !fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
-			return null;
-
-		List allDetectors = new ArrayList(0);
-
-		IHyperlinkDetector extHyperlinkDetector = getTextEditorsExtensionsHyperlinkDetector(); 
-
-		if (extHyperlinkDetector != null) allDetectors.add(extHyperlinkDetector);
-		
-/*		
-		IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer);
-		for (int m = 0; m < superDetectors.length; m++) {
-			IHyperlinkDetector detector = superDetectors[m];
-			if (!allDetectors.contains(detector)) {
-				allDetectors.add(detector);
-			}
-		}
-*/
-		return (IHyperlinkDetector[]) allDetectors.toArray(new IHyperlinkDetector[0]);
+			return configurationDelegate.getHyperlinkDetectors(
+					sourceViewer,
+					fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED));
 	}
 
-	private IHyperlinkDetector getTextEditorsExtensionsHyperlinkDetector() {
-		Plugin plugin = Platform.getPlugin("org.jboss.tools.common.text.ext"); //$NON-NLS-1$
-		return (plugin != null && plugin instanceof IAdaptable ? (IHyperlinkDetector)((IAdaptable)plugin).getAdapter(IHyperlinkDetector.class):null);
-	}
-
-	private IHyperlinkDetector getTextEditorsExtensionsHyperlinkDetector1() {
-		IHyperlinkDetector result = null;
-		final Object[] bundleActivationResult = new Object[] { Boolean.FALSE };
-		final Bundle bundle = Platform.getBundle("org.jboss.tools.common.text.ext"); //$NON-NLS-1$
-		if (bundle != null && bundle.getState() == org.osgi.framework.Bundle.ACTIVE) {
-			bundleActivationResult[0] = Boolean.TRUE;
-		} else {
-			BusyIndicator.showWhile(null, new Runnable() {
-				public void run() {
-					bundleActivationResult[0] = Boolean.TRUE;
-				}
-			});
-		}
-
-		if (Boolean.TRUE.equals(bundleActivationResult[0])) {
-			try {
-				Dictionary headers = bundle.getHeaders();
-				String pluginClass = (String)headers.get("Plugin-Class"); //$NON-NLS-1$
-				Class plugin = bundle.loadClass(pluginClass);
-				
-				Object obj = plugin.newInstance();
-				if (obj instanceof IAdaptable) {
-					result = (IHyperlinkDetector)((IAdaptable)obj).getAdapter(IHyperlinkDetector.class);
-				}
-			} catch (Exception x) {
-				JspEditorPlugin.getPluginLog().logError("Error in loading hyperlink detector", x); //$NON-NLS-1$
-			}
-		}
-		return result;
-	}
-
 	/*
 	 * (non-Javadoc)
 	 * @see org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML#getContentFormatter(org.eclipse.jface.text.source.ISourceViewer)
@@ -131,4 +63,9 @@
 		formatter.setMasterStrategy(new StructuredFormattingStrategy(new HTMLFormatProcessor()));
 		return formatter;
 	}
+
+	public IContentAssistProcessor[] getContentAssistProcessorsForPartitionType(
+			ISourceViewer sourceViewer, String partitionType) {
+		return super.getContentAssistProcessors(sourceViewer, partitionType);
+	}
 }
\ No newline at end of file

Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/ITextViewerConfiguration.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/ITextViewerConfiguration.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/ITextViewerConfiguration.java	2009-09-29 20:19:58 UTC (rev 17810)
@@ -0,0 +1,11 @@
+package org.jboss.tools.jst.jsp;
+
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+public interface ITextViewerConfiguration {
+	static final IHyperlinkDetector[] NO_CA_DETECTORS = new IHyperlinkDetector[0];
+	IContentAssistProcessor[] getContentAssistProcessorsForPartitionType(ISourceViewer sourceViewer, String partitionType);
+	IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer);
+}


Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/ITextViewerConfiguration.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java	2009-09-29 19:32:45 UTC (rev 17809)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java	2009-09-29 20:19:58 UTC (rev 17810)
@@ -10,54 +10,28 @@
  ******************************************************************************/ 
 package org.jboss.tools.jst.jsp;
 
-import java.util.ArrayList;
-import java.util.Dictionary;
-import java.util.List;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Plugin;
 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
 import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
 import org.eclipse.jface.text.source.ISourceViewer;
 import org.eclipse.jst.jsp.core.text.IJSPPartitions;
 import org.eclipse.jst.jsp.ui.StructuredTextViewerConfigurationJSP;
 import org.eclipse.jst.jsp.ui.internal.style.jspel.LineStyleProviderForJSPEL;
-import org.eclipse.swt.custom.BusyIndicator;
 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
 import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider;
-import org.jboss.tools.common.text.xml.contentassist.SortingCompoundContentAssistProcessor;
-import org.osgi.framework.Bundle;
 
 /**
  * @author Igels
  */
-public class JSPTextViewerConfiguration extends StructuredTextViewerConfigurationJSP {
+public class JSPTextViewerConfiguration extends StructuredTextViewerConfigurationJSP implements ITextViewerConfiguration {
+	
+	private TextViewerConfigurationDelegate configurationDelegate;
 
 	public JSPTextViewerConfiguration() {
 		super();
+		configurationDelegate = new TextViewerConfigurationDelegate(this);
 	}
 
-	protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) {
-		SortingCompoundContentAssistProcessor sortingCompoundProcessor = new SortingCompoundContentAssistProcessor(sourceViewer, partitionType);
-		
-		if (sortingCompoundProcessor.supportsPartitionType(partitionType)) {
-			// Add the default WTP CA processors to our SortingCompoundContentAssistProcessor
-			IContentAssistProcessor[] superProcessors = super.getContentAssistProcessors(sourceViewer, partitionType);
 
-			if (superProcessors != null && superProcessors.length > 0) {
-				for (int i = 0; i < superProcessors.length; i++)
-					sortingCompoundProcessor.addContentAssistProcessor(partitionType, superProcessors[i]);
-			}
-
-			return new IContentAssistProcessor[] {sortingCompoundProcessor};
-		}
-
-		
-		return new IContentAssistProcessor[0];
-	}
-
-	
 	/*
 	 * JBIDE-4390:  
 	 * The line style provider for partition type == "org.eclipse.jst.jsp.SCRIPT.JSP_EL2", 
@@ -99,67 +73,23 @@
 		return providers;
 	}
 
+	protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) {
+		return configurationDelegate.getContentAssistProcessors(sourceViewer, partitionType);
+	}
 	
 	/*
 	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer)
 	 * @since 3.1
 	 */
 	public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
-		if (fPreferenceStore == null)
-			return null;
-		if (sourceViewer == null || !fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED))
-			return null;
-
-		List allDetectors = new ArrayList(0);
-
-		IHyperlinkDetector extHyperlinkDetector = getTextEditorsExtensionsHyperlinkDetector(); 
-
-		if (extHyperlinkDetector != null) allDetectors.add(extHyperlinkDetector);
-
-/*		IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer);
-		for (int m = 0; m < superDetectors.length; m++) {
-			IHyperlinkDetector detector = superDetectors[m];
-			if (!allDetectors.contains(detector)) {
-				allDetectors.add(detector);
-			}
-		}
-*/
-		return (IHyperlinkDetector[]) allDetectors.toArray(new IHyperlinkDetector[0]);
+		return configurationDelegate.getHyperlinkDetectors(
+				sourceViewer,
+				fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED));		
 	}
 
-	private IHyperlinkDetector getTextEditorsExtensionsHyperlinkDetector() {
-		Plugin plugin = Platform.getPlugin("org.jboss.tools.common.text.ext"); //$NON-NLS-1$
-		return (plugin != null && plugin instanceof IAdaptable ? (IHyperlinkDetector)((IAdaptable)plugin).getAdapter(IHyperlinkDetector.class):null);
+	public IContentAssistProcessor[] getContentAssistProcessorsForPartitionType(
+			ISourceViewer sourceViewer, String partitionType) {
+		// TODO Auto-generated method stub
+		return super.getContentAssistProcessors(sourceViewer, partitionType);
 	}
-
-	private IHyperlinkDetector getTextEditorsExtensionsHyperlinkDetector1() {
-		IHyperlinkDetector result = null;
-		final Object[] bundleActivationResult = new Object[] { Boolean.FALSE };
-		final Bundle bundle = Platform.getBundle("org.jboss.tools.common.text.ext"); //$NON-NLS-1$
-		if (bundle != null && bundle.getState() == org.osgi.framework.Bundle.ACTIVE) {
-			bundleActivationResult[0] = Boolean.TRUE;
-		} else {
-			BusyIndicator.showWhile(null, new Runnable() {
-				public void run() {
-					bundleActivationResult[0] = Boolean.TRUE;
-				}
-			});
-		}
-
-		if (Boolean.TRUE.equals(bundleActivationResult[0])) {
-			try {
-				Dictionary headers = bundle.getHeaders();
-				String pluginClass = (String)headers.get("Plugin-Class"); //$NON-NLS-1$
-				Class plugin = bundle.loadClass(pluginClass);
-				
-				Object obj = plugin.newInstance();
-				if (obj instanceof IAdaptable) {
-					result = (IHyperlinkDetector)((IAdaptable)obj).getAdapter(IHyperlinkDetector.class);
-				}
-			} catch (Exception x) {
-				JspEditorPlugin.getPluginLog().logError("Error in loading hyperlink detector", x); //$NON-NLS-1$
-			}
-		}
-		return result;
-	}
 }
\ No newline at end of file

Added: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextViewerConfigurationDelegate.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextViewerConfigurationDelegate.java	                        (rev 0)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextViewerConfigurationDelegate.java	2009-09-29 20:19:58 UTC (rev 17810)
@@ -0,0 +1,68 @@
+package org.jboss.tools.jst.jsp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
+import org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML;
+import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration;
+import org.jboss.tools.common.text.ext.hyperlink.HyperlinkDetector;
+import org.jboss.tools.common.text.xml.contentassist.SortingCompoundContentAssistProcessor;
+
+public class TextViewerConfigurationDelegate {
+	
+	ITextViewerConfiguration target; 
+	
+	public TextViewerConfigurationDelegate(ITextViewerConfiguration config) {
+		this.target = config;
+	}
+
+    protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer sourceViewer, String partitionType) {
+		SortingCompoundContentAssistProcessor sortingCompoundProcessor = new SortingCompoundContentAssistProcessor(sourceViewer, partitionType);
+		
+		if (sortingCompoundProcessor.supportsPartitionType(partitionType)) {
+			// Add the default WTP CA processors to our SortingCompoundContentAssistProcessor
+			IContentAssistProcessor[] superProcessors = target.getContentAssistProcessorsForPartitionType(sourceViewer, partitionType);
+
+			if (superProcessors != null && superProcessors.length > 0) {
+				for (int i = 0; i < superProcessors.length; i++)
+					sortingCompoundProcessor.addContentAssistProcessor(partitionType, superProcessors[i]);
+			}
+
+			return new IContentAssistProcessor[] {sortingCompoundProcessor};
+		}
+
+		
+		return new IContentAssistProcessor[0];
+	}	
+	
+	/*
+	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer)
+	 * @since 3.1
+	 */
+	public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer, boolean enabled) {
+		IHyperlinkDetector[] result = ITextViewerConfiguration.NO_CA_DETECTORS;
+		if (enabled) {
+			List<IHyperlinkDetector> allDetectors = new ArrayList<IHyperlinkDetector>(0);
+	
+			IHyperlinkDetector extHyperlinkDetector = HyperlinkDetector.getInstance(); 
+	
+			if (extHyperlinkDetector != null) allDetectors.add(extHyperlinkDetector);
+	
+	/*		IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer);
+			for (int m = 0; m < superDetectors.length; m++) {
+				IHyperlinkDetector detector = superDetectors[m];
+				if (!allDetectors.contains(detector)) {
+					allDetectors.add(detector);
+				}
+			}
+	*/
+			result = allDetectors.toArray(new IHyperlinkDetector[0]);
+		}
+		return result;
+	}
+    
+}


Property changes on: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextViewerConfigurationDelegate.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list