diff options
Diffstat (limited to 'bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional')
14 files changed, 0 insertions, 3141 deletions
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/preferences/CommonEditorPreferenceNames.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/preferences/CommonEditorPreferenceNames.java deleted file mode 100644 index 3eaa30d143..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/preferences/CommonEditorPreferenceNames.java +++ /dev/null @@ -1,35 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - -package org.eclipse.wst.sse.ui.internal.provisional.preferences; - -import org.eclipse.wst.sse.ui.internal.preferences.EditorPreferenceNames; - -/** - * Common editor preference keys used by the Structured Text Editor. - * - * @plannedfor 1.0 - */ -public class CommonEditorPreferenceNames { - private CommonEditorPreferenceNames() { - // empty private constructor so users cannot instantiate class - } - - /** - * A named preference that controls as-you-type validation - * <p> - * Value is of type <code>Boolean</code>. - * </p> - */ - public static final String EVALUATE_TEMPORARY_PROBLEMS = EditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS; -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryProvider.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryProvider.java deleted file mode 100644 index e2bf0d49c9..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.provisional.registry; - -import org.eclipse.wst.sse.core.internal.ltk.modelhandler.IDocumentTypeHandler; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; - - -public interface AdapterFactoryProvider { - - public void addAdapterFactories(IStructuredModel structuredModel); - - // TODO_issue: IDocumentTypeHandler doesn't seem correct in this API. - // reexamine and see if should be ModelHandler, or ContentTypeIdentifer - // instead. - public boolean isFor(IDocumentTypeHandler contentTypeDescription); - - /** - * This method should only add those factories related to embedded content - * type - */ - public void reinitializeFactories(IStructuredModel structuredModel); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistry.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistry.java deleted file mode 100644 index 0a04339f39..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistry.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.provisional.registry; - -import java.util.Iterator; - -/** - * This is basically a "factory for factories". It is to used to associate - * "edit time" AdapterFactories with a StructuredModel, based on the - * IStructuredModel's ContentTypeDescription. In plugin.xml files, there - * should be an AdapterFactoryProvider defined for every definition of - * ContentTypeDescription. - */ -public interface AdapterFactoryRegistry { - - /** - * Returns an Iterator over a Collection of AdapterFactoryProviders - * - * @return - */ - public Iterator getAdapterFactories(); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistryExtension.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistryExtension.java deleted file mode 100644 index bc47269fd4..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistryExtension.java +++ /dev/null @@ -1,22 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.provisional.registry; - -import java.util.Iterator; -import java.util.List; - -public interface AdapterFactoryRegistryExtension { - Iterator getAdapterFactories(String contentTypeID); - - List getAdapterFactoriesAsList(String contentTypeID); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistryImpl.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistryImpl.java deleted file mode 100644 index 78ebf475bc..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistryImpl.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.provisional.registry; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.content.IContentTypeManager; -import org.eclipse.wst.sse.ui.internal.Logger; - - -public class AdapterFactoryRegistryImpl implements AdapterFactoryRegistry, AdapterFactoryRegistryExtension { - - protected final static String ATT_CLASS = "class"; //$NON-NLS-1$ - - private static AdapterFactoryRegistry instance = null; - - static synchronized public AdapterFactoryRegistry getInstance() { - if (instance == null) { - instance = new AdapterFactoryRegistryImpl(); - } - return instance; - } - - // this map exists so there is only one provider - // instance not duplicate providers for different content types - private HashMap adapterProviders = null; - - private boolean DEBUG = false; - /** - * This HashMap contains: [contentTypeId -> element2providerMap] | V - * [configurationElement -> AdapterFactoryProvider] - * - */ - private HashMap hashMap = null; - - // providers with no content type associated - // just added through the add(...) method - private HashSet unassociatedProviders = null; - - private AdapterFactoryRegistryImpl() { - super(); - this.hashMap = new HashMap(); - this.unassociatedProviders = new HashSet(); - this.adapterProviders = new HashMap(); - - // doesn't instantiate classes, just stores configuration elements - AdapterFactoryRegistryReader.readRegistry(hashMap); - } - - void add(AdapterFactoryProvider adapterFactoryProvider) { - this.unassociatedProviders.add(adapterFactoryProvider); - } - - public Iterator getAdapterFactories() { - if (DEBUG) { - System.out.println("===================================================================================="); //$NON-NLS-1$ - System.out.println("GETTING ALL ADAPTER FACTORIES"); //$NON-NLS-1$ - } - - List results = new ArrayList(); - - // add providers that have no content type specification - results.addAll(this.unassociatedProviders); - Iterator it = this.hashMap.keySet().iterator(); - String contentTypeId = null; - while (it.hasNext()) { - contentTypeId = (String) it.next(); - - if (DEBUG) - System.out.println(" + for: " + contentTypeId); //$NON-NLS-1$ - - results.addAll(getAdapterFactoriesAsList(contentTypeId)); - } - - if (DEBUG) { - System.out.println("===================================================================================="); //$NON-NLS-1$ - } - - return results.iterator(); - } - - public Iterator getAdapterFactories(String contentTypeID) { - if (DEBUG) { - System.out.println("===================================================================================="); //$NON-NLS-1$ - System.out.println("GETTING ADAPTER FACTORIES for: " + contentTypeID); //$NON-NLS-1$ - } - - List results = new ArrayList(); - - // add providers that have no content type specification - results.addAll(unassociatedProviders); - - // add unknown content type providers (for backwards compatability) - results.addAll(getAdapterFactoriesAsList(AdapterFactoryRegistryReader.UNKNOWN_CONTENT_TYPE)); - - // add providers for specific content type - results.addAll(getAdapterFactoriesAsList(Platform.getContentTypeManager().getContentType(contentTypeID))); - - - if (DEBUG) { - System.out.println("===================================================================================="); //$NON-NLS-1$ - } - - return results.iterator(); - } - - public List getAdapterFactoriesAsList(IContentType contentType) { - IContentType type = contentType; - List results = new ArrayList(); - while (type != null && !type.getId().equals(IContentTypeManager.CT_TEXT)) { - results.addAll(getAdapterFactoriesAsList(type.getId())); - type = type.getBaseType(); - } - return results; - } - - /** - * Using this new API, only AdapterFactoryProviders for a certain content - * type are instantiated. This will allow for the minimum number of - * plugins to be loaded rather than all that implement the adapter factory - * extension point. - * - * @param contentTypeID - * @return - */ - public List getAdapterFactoriesAsList(String contentTypeID) { - - List results = new ArrayList(); - - // get element2Provider map for specified content type - Object o = hashMap.get(contentTypeID); - if (o != null) { - // instantiate if necessary from - // element2adapterFactoryProvider - // map - Map element2Provider = (Map) o; - Iterator it = element2Provider.keySet().iterator(); - IConfigurationElement element = null; - String classname = null; - Object existing = null; - AdapterFactoryProvider p = null; - while (it.hasNext()) { - element = (IConfigurationElement) it.next(); - o = element2Provider.get(element); - if (o != null) { - // this provider has already been created - if (DEBUG) - System.out.println("already created: " + element.getAttribute(ATT_CLASS)); //$NON-NLS-1$ - - results.add(o); - } - else { - // need to create the provider - try { - classname = element.getAttribute(ATT_CLASS); - - if (DEBUG) - System.out.println("about to create: " + classname); //$NON-NLS-1$ - - // check if we created one already - existing = this.adapterProviders.get(classname); - if (existing == null) { - // this is the only place - // AdapterFactoryProviders - // are created - p = (AdapterFactoryProvider) element.createExecutableExtension(ATT_CLASS); // $NON-NLS-1$ - this.adapterProviders.put(classname, p); - } - else { - p = (AdapterFactoryProvider) existing; - } - - // add to element2Provider for this contentType - element2Provider.put(element, p); - // add to results to return for this method - results.add(p); - - } - catch (CoreException e) { - // if the provider throws any exception, just log - // and - // continue - Logger.logException(e); - } - } - } - } - - return results; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistryReader.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistryReader.java deleted file mode 100644 index 383e5e0b48..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/registry/AdapterFactoryRegistryReader.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.provisional.registry; - -import java.util.HashMap; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.Platform; -import org.eclipse.wst.sse.ui.internal.Logger; - - -/** - * This class just converts what's in the plugins registry into a form more - * easily useable by others, the ContentTypeRegistry. - */ -class AdapterFactoryRegistryReader { - protected final static String ATT_CLASS = "class"; //$NON-NLS-1$ - - protected final static String ATT_ID = "id"; //$NON-NLS-1$ - - private static boolean DEBUG = false; - protected final static String EXTENSION_POINT_ID = "adapterFactoryDescription"; //$NON-NLS-1$ - // - protected final static String PLUGIN_ID = "org.eclipse.wst.sse.ui"; //$NON-NLS-1$ - protected final static String TAG_CONTENT_TYPE = "contentType"; //$NON-NLS-1$ - - protected final static String TAG_NAME = "adapterFactoryDescription"; //$NON-NLS-1$ - - public final static String UNKNOWN_CONTENT_TYPE = "unknown"; //$NON-NLS-1$ - - /** - * adds configuration element to contentTypeId map [contentTypeId -> - * element2providerMap] | V [element -> provider] - * - * NOTE: this doesn't create the provider yet, that must be done on demand - * and stored in the appropriate element2provider - * - * @param map - * @param contentTypeId - * @param element - */ - private static void addElementForContentType(HashMap map, String contentTypeId, IConfigurationElement element) { - - Object o = map.get(contentTypeId); - if (o == null) { - HashMap element2provider = new HashMap(); - // don't create the executable extension yet - element2provider.put(element, null); - map.put(contentTypeId, element2provider); - - if (DEBUG) - System.out.println("added " + element.getAttribute(ATT_CLASS) + ", but didn't create exec extension"); //$NON-NLS-1$ //$NON-NLS-2$ - } else { - // add element to unknown list (not executable ext yet...) - HashMap element2provider = (HashMap) o; - element2provider.put(element, null); - - if (DEBUG) - System.out.println("added " + element.getAttribute(ATT_CLASS) + " to unknown list, but didn't create exec extension"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * the map passed in: [contentTypeId -> element2providerMap] | V [element -> - * provider] - * - * @param element - * @param map - * @return - */ - protected static AdapterFactoryProvider readElement(IConfigurationElement element, HashMap map) { - - AdapterFactoryProvider adapterFactoryProvider = null; - if (element.getName().equals(TAG_NAME)) { - try { - IConfigurationElement[] children = element.getChildren(); - boolean specifiedContentType = false; - if (children != null && children.length > 0) { - // content types are specified - for (int i = 0; i < children.length; i++) { - if (children[i].getName().equals(TAG_CONTENT_TYPE)) { - // it's possible to have non-contentType childrent - specifiedContentType = true; - String contentType = children[i].getAttribute(ATT_ID); - addElementForContentType(map, contentType, element); - } - } - } - if (!specifiedContentType) { - // no content type association - addElementForContentType(map, UNKNOWN_CONTENT_TYPE, element); - } - } catch (Exception e) { - // if the provider throws any exception, just log and continue - Logger.logException(e); - } - } - return adapterFactoryProvider; - } - - /** - * We simply require an 'add' method, of what ever it is we are to read - * into - */ - static void readRegistry(HashMap map) { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint point = registry.getExtensionPoint(PLUGIN_ID, EXTENSION_POINT_ID); - if (point != null) { - IConfigurationElement[] elements = point.getConfigurationElements(); - for (int i = 0; i < elements.length; i++) { - readElement(elements[i], map); - } - } - } - - protected IConfigurationElement configElement = null; - - // protected final static String ADAPTER_CLASS = "adapterClass"; - // //$NON-NLS-1$ - // protected final static String DOC_TYPE_ID = "docTypeId"; //$NON-NLS-1$ - // protected final static String MIME_TYPE_LIST = "mimeTypeList"; - // //$NON-NLS-1$ - // - /** - * ContentTypeRegistryReader constructor comment. - */ - AdapterFactoryRegistryReader() { - super(); - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/AbstractLineStyleProvider.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/AbstractLineStyleProvider.java deleted file mode 100644 index 2b80125bf4..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/AbstractLineStyleProvider.java +++ /dev/null @@ -1,405 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.provisional.style; - -import java.util.Collection; -import java.util.HashMap; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; -import org.eclipse.wst.sse.core.internal.util.Debug; -import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper; -import org.eclipse.wst.sse.ui.internal.util.EditorUtility; - - -public abstract class AbstractLineStyleProvider { - private class PropertyChangeListener implements IPropertyChangeListener { - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent) - */ - public void propertyChange(PropertyChangeEvent event) { - // have to do it this way so others can override the method - handlePropertyChange(event); - } - } - - protected IStructuredDocument fDocument; - protected Highlighter fHighlighter; - private boolean fInitialized; - protected PropertyChangeListener fPreferenceListener = new PropertyChangeListener(); - - //private ISourceViewer fSourceViewer = null; - protected ReconcilerHighlighter fRecHighlighter = null; - - /** Contains all text attributes pertaining to this line style provider */ - private HashMap fTextAttributes = null; - - // we keep track of LogMessage to avoid writing hundreds of messages, - // but still give a hint that something is wrong with attributeProviders - // and/or regions. - // It's only written in the case of a program error, but there's no use - // adding - // salt to the wound. - // private boolean wroteOneLogMessage; - /** - */ - protected AbstractLineStyleProvider() { - } - - /** - * Looks up the colorKey in the preference store and adds the style - * information to list of TextAttributes - * - * @param colorKey - */ - protected void addTextAttribute(String colorKey) { - if (getColorPreferences() != null) { - String prefString = getColorPreferences().getString(colorKey); - String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); - if (stylePrefs != null) { - RGB foreground = ColorHelper.toRGB(stylePrefs[0]); - RGB background = ColorHelper.toRGB(stylePrefs[1]); - boolean bold = Boolean.valueOf(stylePrefs[2]).booleanValue(); - boolean italic = Boolean.valueOf(stylePrefs[3]).booleanValue(); - boolean strikethrough = Boolean.valueOf(stylePrefs[4]).booleanValue(); - boolean underline = Boolean.valueOf(stylePrefs[5]).booleanValue(); - int style = SWT.NORMAL; - if (bold) { - style = style | SWT.BOLD; - } - if (italic) { - style = style | SWT.ITALIC; - } - if (strikethrough) { - style = style | TextAttribute.STRIKETHROUGH; - } - if (underline) { - style = style | TextAttribute.UNDERLINE; - } - - TextAttribute createTextAttribute = createTextAttribute(foreground, background, style); - getTextAttributes().put(colorKey, createTextAttribute); - } - } - } - - protected void commonInit(IStructuredDocument document, Highlighter highlighter) { - - fDocument = document; - fHighlighter = highlighter; - } - - /** - * this version does "trim" regions to match request - */ - private StyleRange createStyleRange(ITextRegionCollection flatNode, ITextRegion region, TextAttribute attr, int startOffset, int length) { - int start = flatNode.getStartOffset(region); - if (start < startOffset) - start = startOffset; - - // Base the text end offset off of the, possibly adjusted, start - int textEnd = start + region.getTextLength(); - int maxOffset = startOffset + length; - - int end = flatNode.getEndOffset(region); - // Use the end of the text in the region to avoid applying background color to trailing whitespace - if(textEnd < end) - end = textEnd; - // instead of end-start? - if (end > maxOffset) - end = maxOffset; - StyleRange result = new StyleRange(start, end - start, attr.getForeground(), attr.getBackground(), attr.getStyle()); - if((attr.getStyle() & TextAttribute.STRIKETHROUGH) != 0) { - result.strikeout = true; - } - if((attr.getStyle() & TextAttribute.UNDERLINE) != 0) { - result.underline = true; - } - return result; - - } - - protected TextAttribute createTextAttribute(RGB foreground, RGB background, boolean bold) { - return new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, bold ? SWT.BOLD : SWT.NORMAL); - } - - protected TextAttribute createTextAttribute(RGB foreground, RGB background, int style) { - return new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, style); - } - - abstract protected TextAttribute getAttributeFor(ITextRegion region); - - protected TextAttribute getAttributeFor(ITextRegionCollection collection, ITextRegion region) { - return getAttributeFor(region); - } - - abstract protected IPreferenceStore getColorPreferences(); - - protected IStructuredDocument getDocument() { - return fDocument; - } - - public void setDocument(IStructuredDocument document) { - fDocument = document; - } - - /** - */ - protected Highlighter getHighlighter() { - return fHighlighter; - } - - /** - * Returns the hashtable containing all the text attributes for this line - * style provider. Lazily creates a hashtable if one has not already been - * created. - * - * @return - */ - protected HashMap getTextAttributes() { - if (fTextAttributes == null) { - fTextAttributes = new HashMap(); - loadColors(); - } - return fTextAttributes; - } - - protected void handlePropertyChange(PropertyChangeEvent event) { - // force a full update of the text viewer - if(fRecHighlighter != null) - fRecHighlighter.refreshDisplay(); - } - - public void init(IStructuredDocument structuredDocument, Highlighter highlighter) { - - commonInit(structuredDocument, highlighter); - - if (isInitialized()) - return; - - registerPreferenceManager(); - - setInitialized(true); - } - - public void init(IStructuredDocument structuredDocument, ISourceViewer sourceViewer) { - init(structuredDocument, (Highlighter) null); - } - - public void init(IStructuredDocument structuredDocument, ReconcilerHighlighter highlighter) { - fDocument = structuredDocument; - fRecHighlighter = highlighter; - - if(isInitialized()) - return; - - registerPreferenceManager(); - - setInitialized(true); - } - - /** - * @deprecated - left because it's public, but we aren't adapters any more - */ - public boolean isAdapterForType(java.lang.Object type) { - return type == LineStyleProvider.class; - } - - /** - * Returns the initialized. - * - * @return boolean - */ - public boolean isInitialized() { - return fInitialized; - } - - abstract protected void loadColors(); - - public boolean prepareRegions(ITypedRegion typedRegion, int lineRequestStart, int lineRequestLength, Collection holdResults) { - final int partitionStartOffset = typedRegion.getOffset(); - final int partitionLength = typedRegion.getLength(); - IStructuredDocumentRegion structuredDocumentRegion = getDocument().getRegionAtCharacterOffset(partitionStartOffset); - boolean handled = false; - - handled = prepareTextRegions(structuredDocumentRegion, partitionStartOffset, partitionLength, holdResults); - - return handled; - } - - /** - * @param region - * @param start - * @param length - * @param holdResults - * @return - */ - private boolean prepareTextRegion(ITextRegionCollection blockedRegion, int partitionStartOffset, int partitionLength, Collection holdResults) { - boolean handled = false; - final int partitionEndOffset = partitionStartOffset + partitionLength - 1; - ITextRegion region = null; - ITextRegionList regions = blockedRegion.getRegions(); - int nRegions = regions.size(); - StyleRange styleRange = null; - for (int i = 0; i < nRegions; i++) { - region = regions.get(i); - TextAttribute attr = null; - TextAttribute previousAttr = null; - if (blockedRegion.getStartOffset(region) > partitionEndOffset) - break; - if (blockedRegion.getEndOffset(region) <= partitionStartOffset) - continue; - - if (region instanceof ITextRegionCollection) { - handled = prepareTextRegion((ITextRegionCollection) region, partitionStartOffset, partitionLength, holdResults); - } else { - - attr = getAttributeFor(blockedRegion, region); - if (attr != null) { - handled = true; - // if this region's attr is the same as previous one, then - // just adjust the previous style range - // instead of creating a new instance of one - // note: to use 'equals' in this case is important, since - // sometimes - // different instances of attributes are associated with a - // region, even the - // the attribute has the same values. - // TODO: this needs to be improved to handle readonly - // regions correctly - if ((styleRange != null) && (previousAttr != null) && (previousAttr.equals(attr))) { - styleRange.length += region.getLength(); - } else { - styleRange = createStyleRange(blockedRegion, region, attr, partitionStartOffset, partitionLength); - holdResults.add(styleRange); - // technically speaking, we don't need to update - // previousAttr - // in the other case, because the other case is when - // it hasn't changed - previousAttr = attr; - } - } else { - previousAttr = null; - } - } - } - return handled; - } - - private boolean prepareTextRegions(IStructuredDocumentRegion structuredDocumentRegion, int partitionStartOffset, int partitionLength, Collection holdResults) { - boolean handled = false; - final int partitionEndOffset = partitionStartOffset + partitionLength - 1; - while (structuredDocumentRegion != null && structuredDocumentRegion.getStartOffset() <= partitionEndOffset) { - ITextRegion region = null; - ITextRegionList regions = structuredDocumentRegion.getRegions(); - int nRegions = regions.size(); - StyleRange styleRange = null; - for (int i = 0; i < nRegions; i++) { - region = regions.get(i); - TextAttribute attr = null; - TextAttribute previousAttr = null; - if (structuredDocumentRegion.getStartOffset(region) > partitionEndOffset) - break; - if (structuredDocumentRegion.getEndOffset(region) <= partitionStartOffset) - continue; - - if (region instanceof ITextRegionCollection) { - boolean handledCollection = (prepareTextRegion((ITextRegionCollection) region, partitionStartOffset, partitionLength, holdResults)); - handled = (!handled) ? handledCollection : handled; - } else { - - attr = getAttributeFor(structuredDocumentRegion, region); - if (attr != null) { - handled = true; - // if this region's attr is the same as previous one, - // then just adjust the previous style range - // instead of creating a new instance of one - // note: to use 'equals' in this case is important, - // since sometimes - // different instances of attributes are associated - // with a region, even the - // the attribute has the same values. - // TODO: this needs to be improved to handle readonly - // regions correctly - if ((styleRange != null) && (previousAttr != null) && (previousAttr.equals(attr))) { - styleRange.length += region.getLength(); - } else { - styleRange = createStyleRange(structuredDocumentRegion, region, attr, partitionStartOffset, partitionLength); - holdResults.add(styleRange); - // technically speaking, we don't need to update - // previousAttr - // in the other case, because the other case is - // when it hasn't changed - previousAttr = attr; - } - } else { - previousAttr = null; - } - } - - if (Debug.syntaxHighlighting && !handled) { - System.out.println("not handled in prepareRegions"); //$NON-NLS-1$ - } - } - structuredDocumentRegion = structuredDocumentRegion.getNext(); - } - return handled; - } - - protected void registerPreferenceManager() { - IPreferenceStore pref = getColorPreferences(); - if (pref != null) { - pref.addPropertyChangeListener(fPreferenceListener); - } - } - - public void release() { - unRegisterPreferenceManager(); - if (fTextAttributes != null) { - fTextAttributes.clear(); - fTextAttributes = null; - } - setInitialized(false); - } - - /** - * Sets the initialized. - * - * @param initialized - * The initialized to set - */ - private void setInitialized(boolean initialized) { - this.fInitialized = initialized; - } - - protected void unRegisterPreferenceManager() { - IPreferenceStore pref = getColorPreferences(); - if (pref != null) { - pref.removePropertyChangeListener(fPreferenceListener); - } - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/CompatibleHighlighter.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/CompatibleHighlighter.java deleted file mode 100644 index a54398bf78..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/CompatibleHighlighter.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.internal.provisional.style; - -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.swt.custom.LineStyleEvent; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; - -/** - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=224209 - * - * Created to provide compatibility with refreshDisplay() and getTextViewer() - * methods on the superclass that might be called by LineStyleProviders. - */ -public final class CompatibleHighlighter extends Highlighter { - - private ITextViewer textViewer; - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#addProvider(java.lang.String, - * org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider) - */ - public void addProvider(String partitionType, LineStyleProvider provider) { - super.addProvider(partitionType, provider); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#getTextViewer() - */ - public ITextViewer getTextViewer() { - return super.getTextViewer(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#install(org.eclipse.jface.text.ITextViewer) - */ - public void install(ITextViewer newTextViewer) { - textViewer = newTextViewer; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#lineGetStyle(int, - * int) - */ - public StyleRange[] lineGetStyle(int eventLineOffset, int eventLineLength) { - return new StyleRange[0]; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#lineGetStyle(org.eclipse.swt.custom.LineStyleEvent) - */ - public void lineGetStyle(LineStyleEvent event) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#refreshDisplay() - */ - public void refreshDisplay() { - if (textViewer != null) - textViewer.invalidateTextPresentation(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#refreshDisplay(int, - * int) - */ - public void refreshDisplay(int start, int length) { - refreshDisplay(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#removeProvider(java.lang.String) - */ - public void removeProvider(String partitionType) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#setDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) - */ - public void setDocument(IStructuredDocument structuredDocument) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#setDocumentPartitioning(java.lang.String) - */ - public void setDocumentPartitioning(String partitioning) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.ui.internal.provisional.style.Highlighter#uninstall() - */ - public void uninstall() { - super.uninstall(); - textViewer = null; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/Highlighter.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/Highlighter.java deleted file mode 100644 index b47107d67c..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/Highlighter.java +++ /dev/null @@ -1,904 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.provisional.style; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.IDocumentExtension3; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.ITextViewerExtension5; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.util.IPropertyChangeListener; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.swt.custom.LineStyleEvent; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.util.Debug; -import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder; -import org.eclipse.wst.sse.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.preferences.EditorPreferenceNames; -import org.eclipse.wst.sse.ui.internal.util.EditorUtility; - -/** - * This class is to directly mediate between the Structured Document data - * structure and the text widget's text and events. It assumes there only the - * model is interested in text events, and all other views will work from that - * model. Changes to the text widgets input can cause changes in the model, - * which in turn cause changes to the widget's display. - * - */ -public class Highlighter implements IHighlighter { - - /** - * A utility class to do various color manipulations - */ - private class YUV_RGBConverter { - /** - * This class "holds" the YUV values corresponding to RGB color - */ - private class YUV { - - class NormalizedRGB { - double blue; - double green; - private final double maxRGB = 256.0; - double red; - - public NormalizedRGB(RGB rgb) { - // first normalize to between 0 - 1 - red = rgb.red / maxRGB; - green = rgb.green / maxRGB; - blue = rgb.blue / maxRGB; - - red = gammaNormalized(red); - green = gammaNormalized(green); - blue = gammaNormalized(blue); - - } - } - - private NormalizedRGB normalizedRGB; - - private double u = -1; - private double v = -1; - private double y = -1; - - private YUV() { - super(); - } - - public YUV(double y, double u, double v) { - this(); - this.y = y; - this.u = u; - this.v = v; - } - - public YUV(RGB rgb) { - this(); - normalizedRGB = new NormalizedRGB(rgb); - // force calculations - getY(); - getV(); - getU(); - } - - /** - * normalize to "average" gamma 2.2222 or 1/0.45 - */ - double gammaNormalized(double colorComponent) { - if (colorComponent < 0.018) { - return colorComponent * 0.45; - } - else { - return 1.099 * Math.pow(colorComponent, 0.45) - 0.099; - } - } - - /** - * @return RGB based on original RGB and current YUV values; - */ - public RGB getRGB() { - RGB result = null; - double r = getY() + 1.14 * getV(); - double g = getY() - 0.395 * getU() - 0.58 * getV(); - double b = getY() + 2.032 * getU(); - - int red = (int) (inverseGammaNormalized(r) * 256); - int green = (int) (inverseGammaNormalized(g) * 256); - int blue = (int) (inverseGammaNormalized(b) * 256); - if (red < 0) - red = 0; - else if (red > 255) - red = 255; - if (green < 0) - green = 0; - else if (green > 255) - green = 255; - if (blue < 0) - blue = 0; - else if (blue > 255) - blue = 255; - - result = new RGB(red, green, blue); - return result; - } - - public double getU() { - if (u == -1) { - u = 0.4949 * (normalizedRGB.blue - getY()); - } - return u; - - } - - public double getV() { - if (v == -1) { - v = 0.877 * (normalizedRGB.red - getY()); - } - return v; - } - - public double getY() { - if (y == -1) { - y = 0.299 * normalizedRGB.red + 0.587 * normalizedRGB.green + 0.114 * normalizedRGB.blue; - } - return y; - } - - double inverseGammaNormalized(double colorComponent) { - if (colorComponent < 0.018) { - return colorComponent * .222; - } - else { - return Math.pow(((.9099 * colorComponent + 0.09)), 2.22); - } - } - - } - - public YUV_RGBConverter() { - super(); - } - - public double calculateYComponent(Color targetColor) { - return new YUV(targetColor.getRGB()).getY(); - } - - public RGB transformRGB(RGB originalRGB, double scaleFactor, double target) { - RGB transformedRGB = null; - // CCIR601 yuv = new CCIR601(originalRGB); - YUV yuv = new YUV(originalRGB); - double y = yuv.getY(); - // zero is black, one is white - if (y < target) { - // is "dark" make lighter - y = y + ((target - y) * scaleFactor); - } - else { - // is "light" make darker - y = y - ((y - target) * scaleFactor); - } - // yuv.setY(y); - YUV newYUV = new YUV(y, yuv.getU(), yuv.getV()); - // CCIR601 newYUV = new CCIR601(y, yuv.getCb601(), - // yuv.getCr601()); - transformedRGB = newYUV.getRGB(); - return transformedRGB; - } - - public RGB transformRGBToGrey(RGB originalRGB, double scaleFactor, double target) { - RGB transformedRGB = null; - // we left the "full" API method signature, but this - // version does not take into account originalRGB, though - // it might someday. - // for now, we'll simply make the new RGB grey, either a little - // lighter, or a little darker than background. - double y = 0; - double mid = 0.5; - // zero is black, one is white - if (target < mid) { - // is "dark" make lighter - y = target + scaleFactor; - } - else { - // is "light" make darker - y = target - scaleFactor; - } - int c = (int) Math.round(y * 255); - // just to gaurd against mis-use, or scale's values greater - // than mid point (and possibly rounding error) - if (c > 255) - c = 255; - if (c < 0) - c = 0; - transformedRGB = new RGB(c, c, c); - return transformedRGB; - } - } - - private final boolean DEBUG = false; - private final StyleRange[] EMPTY_STYLE_RANGE = new StyleRange[0]; - static final String LINE_STYLE_PROVIDER_EXTENDED_ID = "linestyleprovider"; //$NON-NLS-1$ - private static final int MAX_NUMBER_STYLES = 500; - private static final int LEFT_STYLES_SIZE = 200; - private static final int RIGHT_STYLES_SIZE = 200; - private static final int MIDDLE_STYLES_SIZE = 1; - - private IPropertyChangeListener fForegroundScaleListener = new IPropertyChangeListener() { - public void propertyChange(PropertyChangeEvent event) { - if (EditorPreferenceNames.READ_ONLY_FOREGROUND_SCALE.equals(event.getProperty())) { - IPreferenceStore editorStore = SSEUIPlugin.getDefault().getPreferenceStore(); - readOnlyForegroundScaleFactor = editorStore.getInt(EditorPreferenceNames.READ_ONLY_FOREGROUND_SCALE); - disposeColorTable(); - refreshDisplay(); - } - } - }; - private List fHoldStyleResults; - private String fPartitioning = IDocumentExtension3.DEFAULT_PARTITIONING; - - private int fSavedLength = -1; - private int fSavedOffset = -1; - private StyleRange[] fSavedRanges = null; - - private IStructuredDocument fStructuredDocument; - private Map fTableOfProviders; - - private Map fExtendedProviders; - - protected final LineStyleProvider NOOP_PROVIDER = new LineStyleProviderForNoOp(); - - private double readOnlyBackgroundScaleFactor = 10; - private Hashtable readOnlyColorTable; - double readOnlyForegroundScaleFactor = 30; - - private YUV_RGBConverter rgbConverter; - private ITextViewer textViewer; - private StyledText textWidget; - - public Highlighter() { - super(); - - // in the 'limitSize' method, we make this strong assumption, so, will check here, - // so if tweaked in future, we'll get a quick reminder. - if (LEFT_STYLES_SIZE + MIDDLE_STYLES_SIZE + RIGHT_STYLES_SIZE > MAX_NUMBER_STYLES) { - throw new IllegalStateException("Highligher constants are not defined correctly"); //$NON-NLS-1$ - } - } - - protected void addEmptyRange(int start, int length, Collection holdResults) { - StyleRange result = new StyleRange(); - result.start = start; - result.length = length; - holdResults.add(result); - } - - /** - * Registers a given line style provider for a particular partition type. - * If there is already a line style provider registered for this type, the - * new line style provider is registered instead of the old one. - * - * @param partitionType - * the partition type under which to register - * @param the - * line style provider to register, or <code>null</code> to - * remove an existing one - */ - public void addProvider(String partitionType, LineStyleProvider provider) { - getTableOfProviders().put(partitionType, provider); - } - - /** - * Adjust the style ranges' start and length so that they refer to the - * textviewer widget's range instead of the textviewer's document range. - * - * @param ranges - * @param adjustment - */ - protected void adjust(StyleRange[] ranges, int adjustment) { - ITextViewer viewer = getTextViewer(); - - if (adjustment != 0) { - // just use the adjustment value - // convert document regions back to widget regions - for (int i = 0; i < ranges.length; i++) { - // just adjust the range using the given adjustment - ranges[i].start += adjustment; - } - } - else if (viewer instanceof ITextViewerExtension5) { - // use ITextViewerExtension5 - ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; - - // convert document regions back to widget regions - for (int i = 0; i < ranges.length; i++) { - // get document range, taking into account folding - // regions in viewer - IRegion region = extension.modelRange2WidgetRange(new Region(ranges[i].start, ranges[i].length)); - if (region != null) { - ranges[i].start = region.getOffset(); - ranges[i].length = region.getLength(); - } // else what happens if region is not found?! - } - } - } - - - /** - * @deprecated - Read Only areas have unchanged background colors - */ - void adjustBackground(StyleRange styleRange) { - RGB oldRGB = null; - Color oldColor = styleRange.background; - if (oldColor == null) { - oldColor = getTextWidget().getBackground(); - } - oldRGB = oldColor.getRGB(); - Color newColor = getCachedColorFor(oldRGB); - if (newColor == null) { - double target = getRGBConverter().calculateYComponent(oldColor); - // if background is "light" make it darker, and vice versa - if (target < 0.5) - target = 1.0; - else - target = 0.0; - RGB newRGB = getRGBConverter().transformRGB(oldRGB, readOnlyBackgroundScaleFactor / 100.0, target); - - cacheColor(oldRGB, newRGB); - newColor = getCachedColorFor(oldRGB); - } - styleRange.background = newColor; - } - - private void adjustForeground(StyleRange styleRange) { - RGB oldRGB = null; - // Color oldColor = styleRange.foreground; - Color oldColor = styleRange.background; - if (oldColor == null) { - // oldRGB = getTextWidget().getForeground().getRGB(); - oldColor = getTextWidget().getBackground(); - oldRGB = oldColor.getRGB(); - } - else { - oldRGB = oldColor.getRGB(); - } - Color newColor = getCachedColorFor(oldRGB); - if (newColor == null) { - // make text "closer to" background lumanence - double target = getRGBConverter().calculateYComponent(oldColor); - RGB newRGB = getRGBConverter().transformRGBToGrey(oldRGB, readOnlyForegroundScaleFactor / 100.0, target); - - // save conversion, so calculations only need to be done once - cacheColor(oldRGB, newRGB); - newColor = getCachedColorFor(oldRGB); - } - styleRange.foreground = newColor; - } - - /** - * Cache read-only color. - * - * @param oldRGB - * @param newColor - */ - private void cacheColor(RGB oldRGB, RGB newColor) { - if (readOnlyColorTable == null) { - readOnlyColorTable = new Hashtable(); - } - readOnlyColorTable.put(oldRGB, newColor); - } - - /** - * @param result - * @return - */ - private StyleRange[] convertReadOnlyRegions(StyleRange[] result, int start, int length) { - IStructuredDocument structuredDocument = getDocument(); - - /** - * (dmw) For client/provider simplicity (and consistent look and feel) - * we'll handle readonly regions in one spot, here in the Highlighter. - * Currently it is a fair assumption that each readonly region will be - * on an ITextRegion boundary, so we combine consecutive styles when - * found to be equivalent. Plus, for now, we'll just adjust - * foreground. Eventually will use a "dimming" algrorithm to adjust - * color's satuation/brightness. - */ - if (structuredDocument.containsReadOnly(start, length)) { - // something is read-only in the line, so go through each style, - // and adjust - for (int i = 0; i < result.length; i++) { - StyleRange styleRange = result[i]; - if (structuredDocument.containsReadOnly(styleRange.start, styleRange.length)) { - adjustForeground(styleRange); - } - } - } - return result; - } - - /** - * Clear out the readOnlyColorTable - */ - void disposeColorTable() { - if (readOnlyColorTable != null) { - readOnlyColorTable.clear(); - } - readOnlyColorTable = null; - } - - /** - * This method is just to get existing read-only colors. - */ - private Color getCachedColorFor(RGB oldRGB) { - Color result = null; - - if (readOnlyColorTable != null) { - RGB readOnlyRGB = (RGB) readOnlyColorTable.get(oldRGB); - result = EditorUtility.getColor(readOnlyRGB); - } - - return result; - } - - protected IStructuredDocument getDocument() { - return fStructuredDocument; - } - - /** - * Adjust the given widget offset and length so that they are the - * textviewer document's offset and length, taking into account what is - * actually visible in the document. - * - * @param offset - * @param length - * @return a region containing the offset and length within the - * textviewer's document or null if the offset is not within the - * document - */ - private IRegion getDocumentRangeFromWidgetRange(int offset, int length) { - IRegion styleRegion = null; - ITextViewer viewer = getTextViewer(); - if (viewer instanceof ITextViewerExtension5) { - // get document range, taking into account folding regions in - // viewer - ITextViewerExtension5 extension = (ITextViewerExtension5) viewer; - styleRegion = extension.widgetRange2ModelRange(new Region(offset, length)); - } - else { - // get document range, taking into account viewer visible region - // get visible region in viewer - IRegion vr = null; - if (viewer != null) - vr = viewer.getVisibleRegion(); - else - vr = new Region(0, getDocument().getLength()); - - // if offset is not within visible region, then we don't really - // care - if (offset <= vr.getLength()) { - // Adjust the offset to be within visible region - styleRegion = new Region(offset + vr.getOffset(), length); - } - } - return styleRegion; - } - - - private Map getExtendedProviders() { - if (fExtendedProviders == null) { - fExtendedProviders = new HashMap(3); - } - return fExtendedProviders; - } - - /** - * Method getProviderFor. - * - * @param typedRegion - * @return LineStyleProvider - */ - private LineStyleProvider getProviderFor(ITypedRegion typedRegion) { - String type = typedRegion.getType(); - LineStyleProvider result = (LineStyleProvider) fTableOfProviders.get(type); - if (result == null) { - // NOT YET FINALIZED - DO NOT CONSIDER AS API - synchronized (getExtendedProviders()) { - if (!getExtendedProviders().containsKey(type)) { - LineStyleProvider provider = (LineStyleProvider) ExtendedConfigurationBuilder.getInstance().getConfiguration(LINE_STYLE_PROVIDER_EXTENDED_ID, type); - getExtendedProviders().put(type, provider); - if (provider != null) { - provider.init(getDocument(), this); - } - result = provider; - } - else { - result = (LineStyleProvider) getExtendedProviders().get(type); - } - } - } - if (result == null) { - result = NOOP_PROVIDER; - } - return result; - } - - private YUV_RGBConverter getRGBConverter() { - if (rgbConverter == null) { - rgbConverter = new YUV_RGBConverter(); - } - return rgbConverter; - } - - private Map getTableOfProviders() { - if (fTableOfProviders == null) { - fTableOfProviders = new HashMap(); - } - return fTableOfProviders; - } - - /** - * Returns the textViewer. - * - * @return ITextViewer - */ - public ITextViewer getTextViewer() { - return textViewer; - } - - /** - * @return - */ - protected StyledText getTextWidget() { - return textWidget; - } - - /** - * Installs highlighter support on the given text viewer. - * - * @param textViewer - * the text viewer on which content assist will work - */ - public void install(ITextViewer newTextViewer) { - this.textViewer = newTextViewer; - - IPreferenceStore editorStore = SSEUIPlugin.getDefault().getPreferenceStore(); - editorStore.addPropertyChangeListener(fForegroundScaleListener); - readOnlyForegroundScaleFactor = editorStore.getInt(EditorPreferenceNames.READ_ONLY_FOREGROUND_SCALE); - - if (textWidget != null) { - textWidget.removeLineStyleListener(this); - } - textWidget = newTextViewer.getTextWidget(); - if (textWidget != null) { - textWidget.addLineStyleListener(this); - } - - refreshDisplay(); - } - - public StyleRange[] lineGetStyle(int eventLineOffset, int eventLineLength) { - StyleRange[] eventStyles = EMPTY_STYLE_RANGE; - try { - if (getDocument() == null || eventLineLength == 0) { - // getDocument() == null - // during initialization, this is sometimes called before our - // structured - // is set, in which case we set styles to be the empty style - // range - // (event.styles can not be null) - - // eventLineLength == 0 - // we sometimes get odd requests from the very last CRLF in - // the - // document - // it has no length, and there is no node for it! - eventStyles = EMPTY_STYLE_RANGE; - } - else { - /* - * LineStyleProviders work using absolute document offsets. To - * support visible regions, adjust the requested range up to - * the full document offsets. - */ - IRegion styleRegion = getDocumentRangeFromWidgetRange(eventLineOffset, eventLineLength); - if (styleRegion != null) { - int start = styleRegion.getOffset(); - int length = styleRegion.getLength(); - - ITypedRegion[] partitions = TextUtilities.computePartitioning(getDocument(), fPartitioning, start, length, false); - eventStyles = prepareStyleRangesArray(partitions, start, length); - - /* - * If there is a subtext offset, the style ranges must be - * adjusted to the expected offsets just check if - * eventLineOffset is different than start then adjust, - * otherwise u can leave it alone unless there is special - * handling for itextviewerextension5? - */ - if (start != eventLineOffset) { - int offset = 0; - // figure out visible region to use for adjustment - // only adjust if need to - if (!(getTextViewer() instanceof ITextViewerExtension5)) { - IRegion vr = getTextViewer().getVisibleRegion(); - if (vr != null) { - offset = vr.getOffset(); - } - } - adjust(eventStyles, -offset); - } - - eventStyles = limitSize(eventStyles); - - // for debugging only - if (DEBUG) { - if (!valid(eventStyles, eventLineOffset, eventLineLength)) { - Logger.log(Logger.WARNING, "Highlighter::lineGetStyle found invalid styles at offset " + eventLineOffset); //$NON-NLS-1$ - } - } - } - - } - - } - catch (Exception e) { - // if ANY exception occurs during highlighting, - // just return "no highlighting" - eventStyles = EMPTY_STYLE_RANGE; - if (Debug.syntaxHighlighting) { - System.out.println("Exception during highlighting!"); //$NON-NLS-1$ - } - } - - return eventStyles; - } - - /** - * This method is to centralize the logic in limiting the overall number of style ranges - * that make it to the styled text widget. - * - * Too many styles sent to StyledText results in apparent, but not real, - * hangs of Eclipse Display thread. See - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=108806 - * - * @param eventStyles - * @return - */ - private StyleRange[] limitSize(StyleRange[] eventStyles) { - - // quick return with same object if not modification needed - if (eventStyles.length < MAX_NUMBER_STYLES) { - return eventStyles; - } - else { - // we could just take the easy way out and truncate, but will - // be much better appearing if both the start of the line and the - // end of the line are displayed with styles. Since these are both - // the parts of the line a user is likely to look at. The middle of the - // line will still be "plain". Presumably, the user would re-format the - // file to avoid long lines, so unlikely to see the middle. - StyleRange[] newRanges = new StyleRange[LEFT_STYLES_SIZE + RIGHT_STYLES_SIZE + MIDDLE_STYLES_SIZE]; - System.arraycopy(eventStyles, 0, newRanges, 0, LEFT_STYLES_SIZE); - // - // do end, before we do middle - System.arraycopy(eventStyles, eventStyles.length-RIGHT_STYLES_SIZE, newRanges, LEFT_STYLES_SIZE + MIDDLE_STYLES_SIZE, RIGHT_STYLES_SIZE); - // - // technically, we should compute the exact middle as one big style range, - // with default colors and styles, so if someone does actually type or work with - // documnet as is, will still be correct. - // - StyleRange allBlank = new StyleRange(); - StyleRange lastKnown = newRanges[LEFT_STYLES_SIZE - 1]; - allBlank.start = lastKnown.start + lastKnown.length; - StyleRange nextKnown = newRanges[LEFT_STYLES_SIZE + MIDDLE_STYLES_SIZE + 1]; - allBlank.length = nextKnown.start - allBlank.start; - newRanges[LEFT_STYLES_SIZE] = allBlank; - return newRanges; - } - } - - /** - * A passthrough method that extracts relevant data from the - * LineStyleEvent and passes it along. This method was separated for - * performance testing purposes. - * - * @see org.eclipse.swt.custom.LineStyleListener#lineGetStyle(LineStyleEvent) - */ - public void lineGetStyle(LineStyleEvent event) { - int offset = event.lineOffset; - int length = event.lineText.length(); - - /* - * For some reason, we are sometimes asked for the same style range - * over and over again. This was found to happen during 'revert' of a - * file with one line in it that is 40K long! So, while we don't know - * root cause, caching the styled ranges in case the exact same - * request is made multiple times seems like cheap insurance. - */ - if (offset == fSavedOffset && length == fSavedLength && fSavedRanges != null) { - event.styles = fSavedRanges; - } - else { - // need to assign this array here, or else the field won't get - // updated - event.styles = lineGetStyle(offset, length); - // now saved "cached data" for repeated requests which are exaclty - // same - fSavedOffset = offset; - fSavedLength = length; - fSavedRanges = event.styles; - } - } - - /** - * Note: its very important this method never return null, which is why - * the final null check is in a finally clause - */ - - protected StyleRange[] prepareStyleRangesArray(ITypedRegion[] partitions, int start, int length) { - - StyleRange[] result = EMPTY_STYLE_RANGE; - - if (fHoldStyleResults == null) { - fHoldStyleResults = new ArrayList(partitions.length); - } - else { - fHoldStyleResults.clear(); - } - - // TODO: make some of these instance variables to prevent creation on - // stack - LineStyleProvider currentLineStyleProvider = null; - boolean handled = false; - for (int i = 0; i < partitions.length; i++) { - ITypedRegion currentPartition = partitions[i]; - currentLineStyleProvider = getProviderFor(currentPartition); - currentLineStyleProvider.init(getDocument(), this); - handled = currentLineStyleProvider.prepareRegions(currentPartition, currentPartition.getOffset(), currentPartition.getLength(), fHoldStyleResults); - if (Debug.syntaxHighlighting && !handled) { - System.out.println("Did not handle highlighting in Highlighter inner while"); //$NON-NLS-1$ - } - } - - int resultSize = fHoldStyleResults.size(); - if (resultSize > 0) { - result = (StyleRange[]) fHoldStyleResults.toArray(new StyleRange[fHoldStyleResults.size()]); - } - else { - result = EMPTY_STYLE_RANGE; - } - result = convertReadOnlyRegions(result, start, length); - return result; - } - - public void refreshDisplay() { - if (textWidget != null && !textWidget.isDisposed()) - textWidget.redraw(); - } - - /** - */ - public void refreshDisplay(int start, int length) { - if (textWidget != null && !textWidget.isDisposed()) - textWidget.redrawRange(start, length, true); - } - - public void removeProvider(String partitionType) { - getTableOfProviders().remove(partitionType); - } - - public void setDocument(IStructuredDocument structuredDocument) { - fStructuredDocument = structuredDocument; - } - - public void setDocumentPartitioning(String partitioning) { - if (partitioning != null) { - fPartitioning = partitioning; - } - else { - fPartitioning = IDocumentExtension3.DEFAULT_PARTITIONING; - } - } - - /** - * Uninstalls highlighter support from the text viewer it has previously - * be installed on. - */ - public void uninstall() { - if (textWidget != null && !textWidget.isDisposed()) { - textWidget.removeLineStyleListener(this); - } - textWidget = null; - - Collection providers = getTableOfProviders().values(); - Iterator iterator = providers.iterator(); - while (iterator.hasNext()) { - LineStyleProvider lineStyleProvider = (LineStyleProvider) iterator.next(); - lineStyleProvider.release(); - // this remove probably isn't strictly needed, since - // typically highlighter instance as a whole will go - // away ... but in case that ever changes, this seems like - // a better style. - iterator.remove(); - } - - synchronized (getExtendedProviders()) { - providers = new ArrayList(getExtendedProviders().values()); - getExtendedProviders().clear(); - } - iterator = providers.iterator(); - while (iterator.hasNext()) { - LineStyleProvider lineStyleProvider = (LineStyleProvider) iterator.next(); - if (lineStyleProvider != null) { - lineStyleProvider.release(); - iterator.remove(); - } - } - - IPreferenceStore editorStore = SSEUIPlugin.getDefault().getPreferenceStore(); - editorStore.removePropertyChangeListener(fForegroundScaleListener); - disposeColorTable(); - - // clear out cached variables (d282894) - fSavedOffset = -1; - fSavedLength = -1; - fSavedRanges = null; - } - - /** - * Purely a debugging aide. - */ - private boolean valid(StyleRange[] eventStyles, int startOffset, int lineLength) { - boolean result = false; - if (eventStyles != null) { - if (eventStyles.length > 0) { - StyleRange first = eventStyles[0]; - StyleRange last = eventStyles[eventStyles.length - 1]; - if (startOffset > first.start) { - result = false; - } - else { - int lineEndOffset = startOffset + lineLength; - int lastOffset = last.start + last.length; - if (lastOffset > lineEndOffset) { - result = false; - } - else { - result = true; - } - } - } - else { - // a zero length array is ok - result = true; - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/IHighlighter.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/IHighlighter.java deleted file mode 100644 index caf37d0b22..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/IHighlighter.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - -package org.eclipse.wst.sse.ui.internal.provisional.style; - -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.swt.custom.LineStyleListener; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; - -/** - * @author davidw - * - */ -public interface IHighlighter extends LineStyleListener { - void addProvider(String partitionType, LineStyleProvider provider); - - void install(ITextViewer viewer); - - void removeProvider(String partitionType); - - void setDocument(IStructuredDocument structuredDocument); - - void uninstall(); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/LineStyleProvider.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/LineStyleProvider.java deleted file mode 100644 index ff81827d98..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/LineStyleProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.provisional.style; - -import java.util.Collection; - -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; - -/** - * This interface is not intended to be implemented by clients. Clients - * should instead subclass AbstractLineStyleProvider - * - */ -public interface LineStyleProvider { - - /** - * Initializes this provider for the given Highlighter and document. This - * method will be called at least once before prepareRegions is called. - * - * @param document - * @param highlighter - */ - void init(IStructuredDocument document, Highlighter highlighter); - - /** - * Optionally appends StyleRanges to the styleRanges Collection, in order, - * and only covering the given range within the document. StyleRanges added - * to the collection should not expand outside of the range of the currentRegion - * ITypedRegion. - * - * @param currentRegion - - * the current document partition - * @param start - * @param length - * @param styleRanges - * @return whether this LineStyleProvider handled the request; handling - * includes not adding StyleRanges if that is still the correct - * behavior - */ - boolean prepareRegions(ITypedRegion currentRegion, int start, int length, Collection styleRanges); - - /** - * Instructs this provider to free up any "resources" it might be holding - * on to (such as listening for preference changes). It is only called - * once in the lifetime of this provider. - */ - void release(); -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/LineStyleProviderForNoOp.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/LineStyleProviderForNoOp.java deleted file mode 100644 index 3d609293be..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/LineStyleProviderForNoOp.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 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 - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.sse.ui.internal.provisional.style; - - - -import java.util.Collection; - -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; - -/** - * This class can be used by default, if no attribute provider is found for a - * certain region type. Its probably an error in a factory somewhere if an - * adapter is not found, but this class allows the logic to proceed basically - * simply providing default colored syntax highlighting. - * - * Not to be subclassed. - */ -final public class LineStyleProviderForNoOp implements LineStyleProvider { - - public void init(IStructuredDocument document, Highlighter highlighter) { - // nothing to do - } - - /** - * @see org.eclipse.wst.sse.ui.internal.provisional.style.AbstractLineStyleProvider#prepareRegions(org.eclipse.jface.text.ITypedRegion, - * int, int, java.util.Collection) - */ - public boolean prepareRegions(ITypedRegion currentRegion, int start, int length, Collection holdResults) { - // add nothing, but say handled. - return true; - } - - public void release() { - // nothing to do - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/ReconcilerHighlighter.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/ReconcilerHighlighter.java deleted file mode 100644 index 1a39d4b7ae..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/ReconcilerHighlighter.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 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.internal.provisional.style; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder; -import org.eclipse.wst.sse.ui.internal.Logger; - -public class ReconcilerHighlighter { - - private static final String LINE_STYLE_PROVIDER_EXTENDED_ID = Highlighter.LINE_STYLE_PROVIDER_EXTENDED_ID; - - private Map fTableOfProviders = null; - - private Map fExtendedProviders = null; - - private ITextViewer fTextViewer = null; - - private final static boolean _trace = Boolean.valueOf(Platform.getDebugOption("org.eclipse.wst.sse.ui/structuredPresentationReconciler")).booleanValue(); //$NON-NLS-1$ - private final static String TRACE_PREFIX = "StructuredPresentationReconciler: "; //$NON-NLS-1$ - private long time0; - - /** - * instance for older LineStyleProviders loaded by extension point, - * created if needed - */ - private CompatibleHighlighter fCompatibleHighlighter = null; - - public void refreshDisplay() { - if (_trace) { - time0 = System.currentTimeMillis(); - } - if (fTextViewer != null) - fTextViewer.invalidateTextPresentation(); - if (_trace) { - System.out.println(TRACE_PREFIX + "ReconcilerHighlighter refreshDisplay took " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.flush(); - } - } - - /** - * Registers a given line style provider for a particular partition type. - * If there is already a line style provider registered for this type, the - * new line style provider is registered instead of the old one. - * - * @param partitionType - * the partition type under which to register - * @param the - * line style provider to register, or <code>null</code> to - * remove an existing one - */ - public void addProvider(String partitionType, LineStyleProvider provider) { - getTableOfProviders().put(partitionType, provider); - } - - public void removeProvider(String partitionType) { - getTableOfProviders().remove(partitionType); - } - - public LineStyleProvider getProvider(String partitionType) { - LineStyleProvider result = (LineStyleProvider) getTableOfProviders().get(partitionType); - - // The provider was not within the default set of providers. Use the - // extended configuration - // to look up additional providers - if (result == null) { - // NOT YET FINALIZED - DO NOT CONSIDER AS API - synchronized (getExtendedProviders()) { - if (!getExtendedProviders().containsKey(partitionType)) { - result = (LineStyleProvider) ExtendedConfigurationBuilder.getInstance().getConfiguration(LINE_STYLE_PROVIDER_EXTENDED_ID, partitionType); - getExtendedProviders().put(partitionType, result); - - if (result != null && fTextViewer != null && fTextViewer.getDocument() instanceof IStructuredDocument) { - if (result instanceof AbstractLineStyleProvider) { - ((AbstractLineStyleProvider) result).init((IStructuredDocument) fTextViewer.getDocument(), this); - } - else { - Logger.log(Logger.INFO_DEBUG, "CompatibleHighlighter installing compatibility for " + result.getClass()); //$NON-NLS-1$ - if (fCompatibleHighlighter == null) { - fCompatibleHighlighter = new CompatibleHighlighter(); - fCompatibleHighlighter.install(fTextViewer); - } - result.init((IStructuredDocument) fTextViewer.getDocument(), fCompatibleHighlighter); - } - } - } - else { - result = (LineStyleProvider) getExtendedProviders().get(partitionType); - } - } - } - return result; - } - - private Map getTableOfProviders() { - if (fTableOfProviders == null) { - fTableOfProviders = new HashMap(); - } - return fTableOfProviders; - } - - private Map getExtendedProviders() { - if (fExtendedProviders == null) { - fExtendedProviders = new HashMap(3); - } - return fExtendedProviders; - } - - public void install(ITextViewer textViewer) { - fTextViewer = textViewer; - if (fCompatibleHighlighter != null) { - fCompatibleHighlighter.uninstall(); - fCompatibleHighlighter.install(fTextViewer); - } - refreshDisplay(); - } - - public void uninstall() { - Iterator it = getTableOfProviders().values().iterator(); - - while (it.hasNext()) { - LineStyleProvider provider = (LineStyleProvider) it.next(); - if (provider != null) - provider.release(); - } - - it = getExtendedProviders().values().iterator(); - while (it.hasNext()) { - LineStyleProvider provider = (LineStyleProvider) it.next(); - if (provider != null) - provider.release(); - } - - getTableOfProviders().clear(); - getExtendedProviders().clear(); - fTableOfProviders = null; - if (fCompatibleHighlighter != null) { - fCompatibleHighlighter.uninstall(); - } - fTextViewer = null; - } -} diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/StructuredPresentationReconciler.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/StructuredPresentationReconciler.java deleted file mode 100644 index ba9a8668b9..0000000000 --- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/provisional/style/StructuredPresentationReconciler.java +++ /dev/null @@ -1,932 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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.internal.provisional.style; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.runtime.Assert; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.BadPositionCategoryException; -import org.eclipse.jface.text.DefaultPositionUpdater; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.DocumentPartitioningChangedEvent; -import org.eclipse.jface.text.DocumentRewriteSessionEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentExtension3; -import org.eclipse.jface.text.IDocumentExtension4; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.IDocumentPartitioningListener; -import org.eclipse.jface.text.IDocumentPartitioningListenerExtension; -import org.eclipse.jface.text.IDocumentPartitioningListenerExtension2; -import org.eclipse.jface.text.IDocumentRewriteSessionListener; -import org.eclipse.jface.text.IPositionUpdater; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextInputListener; -import org.eclipse.jface.text.ITextListener; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.ITextViewerExtension5; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.TypedPosition; -import org.eclipse.jface.text.presentation.IPresentationDamager; -import org.eclipse.jface.text.presentation.IPresentationReconciler; -import org.eclipse.jface.text.presentation.IPresentationReconcilerExtension; -import org.eclipse.jface.text.presentation.IPresentationRepairer; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.wst.sse.core.internal.provisional.events.IStructuredDocumentListener; -import org.eclipse.wst.sse.core.internal.provisional.events.NewDocumentEvent; -import org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent; -import org.eclipse.wst.sse.core.internal.provisional.events.RegionChangedEvent; -import org.eclipse.wst.sse.core.internal.provisional.events.RegionsReplacedEvent; -import org.eclipse.wst.sse.core.internal.provisional.events.StructuredDocumentRegionsReplacedEvent; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegionList; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion; -import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList; - -public class StructuredPresentationReconciler implements IPresentationReconciler, IPresentationReconcilerExtension { - - /** Prefix of the name of the position category for tracking damage regions. */ - final static String TRACKED_PARTITION= "__reconciler_tracked_partition"; //$NON-NLS-1$ - - private final static boolean _trace = Boolean.valueOf(Platform.getDebugOption("org.eclipse.wst.sse.ui/structuredPresentationReconciler")).booleanValue(); //$NON-NLS-1$ - private final static boolean _traceTime = Boolean.valueOf(Platform.getDebugOption("org.eclipse.wst.sse.ui/structuredPresentationReconciler/time")).booleanValue(); //$NON-NLS-1$ - private static final String TRACE_PREFIX = "StructuredPresentationReconciler: "; - private long time0; - private long time1; - - /** - * Internal listener class. - */ - class InternalListener implements - ITextInputListener, IDocumentListener, ITextListener, IStructuredDocumentListener, - IDocumentPartitioningListener, IDocumentPartitioningListenerExtension, IDocumentPartitioningListenerExtension2, IDocumentRewriteSessionListener { - - /** Set to <code>true</code> if between a document about to be changed and a changed event. */ - private boolean fDocumentChanging= false; - - /** Flag for the document being in a rewrite session */ - private boolean fInRewriteSession = false; - - /** Flag for some kind of changes being applied during a document rewrite session */ - private boolean fHasIncomingChanges = false; - - /** - * The cached redraw state of the text viewer. - * @since 3.0 - */ - private boolean fCachedRedrawState= true; - - public void newModel(NewDocumentEvent structuredDocumentEvent) { - if(fInRewriteSession) { - fHasIncomingChanges = true; - return; - } - if (_trace) { - time1 = System.currentTimeMillis(); - } - int length = structuredDocumentEvent.getLength(); - recordDamage(new Region(0, length), structuredDocumentEvent.getDocument()); - if (_trace) { - System.out.println("\n" + TRACE_PREFIX + "calculated damage for NewDocumentEvent: (length=" + length + ")"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.flush(); - } - if (_trace && _traceTime) { - System.out.println(TRACE_PREFIX + "calculated damage for NewDocumentEvent in " + (System.currentTimeMillis()-time1) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.flush(); - } - } - - public void noChange(NoChangeEvent structuredDocumentEvent) { - if(fInRewriteSession) { - fHasIncomingChanges = true; - return; - } - if (_trace) { - time1 = System.currentTimeMillis(); - } - if (structuredDocumentEvent.reason == NoChangeEvent.READ_ONLY_STATE_CHANGE) { - // fViewer.invalidateTextPresentation(); - } - if (_trace && _traceTime) { - System.out.println("\n" + TRACE_PREFIX + "calculated damage for NoChangeEvent in " + (System.currentTimeMillis()-time1) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.flush(); - } - } - - public void nodesReplaced(StructuredDocumentRegionsReplacedEvent structuredDocumentEvent) { - if(fInRewriteSession) { - fHasIncomingChanges = true; - return; - } - if (_trace) { - time1 = System.currentTimeMillis(); - } - IRegion damage; - IStructuredDocumentRegionList newDocumentRegions = structuredDocumentEvent.getNewStructuredDocumentRegions(); - if (newDocumentRegions.getLength() > 0) { - int startOffset = newDocumentRegions.item(0).getStartOffset(); - int length = newDocumentRegions.item(newDocumentRegions.getLength() - 1).getEndOffset() - startOffset; - damage = new Region(startOffset, length); - - } - else { - damage = new Region(structuredDocumentEvent.fOffset, structuredDocumentEvent.getLength()); - } - recordDamage(damage, structuredDocumentEvent.fDocument); - if (_trace) { - System.out.println("\n" + TRACE_PREFIX + "calculated damage for StructuredDocumentRegionsReplacedEvent: [" + damage.getOffset() + ":" + damage.getLength() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$ - System.out.flush(); - } - if (_trace && _traceTime) { - System.out.println(TRACE_PREFIX + "calculated damage for StructuredDocumentRegionsReplacedEvent in " + (System.currentTimeMillis()-time1) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.flush(); - } - } - - public void regionChanged(RegionChangedEvent structuredDocumentEvent) { - if(fInRewriteSession) { - fHasIncomingChanges = true; - return; - } - if (_trace) { - time1 = System.currentTimeMillis(); - } - IStructuredDocumentRegion documentRegion = structuredDocumentEvent.getStructuredDocumentRegion(); - ITextRegion changedRegion = structuredDocumentEvent.getRegion(); - int startOffset = documentRegion.getStartOffset(changedRegion); - int length = changedRegion.getLength(); - IRegion damage = new Region(startOffset, length); - - recordDamage(damage, structuredDocumentEvent.fDocument); - if (_trace) { - System.out.println("\n" + TRACE_PREFIX + "calculated damage for RegionChangedEvent: [" + damage.getOffset() + ":" + damage.getLength() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$ - System.out.flush(); - } - if (_trace && _traceTime) { - System.out.println(TRACE_PREFIX + "calculated damage for RegionChangedEvent in " + (System.currentTimeMillis()-time1) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.flush(); - } - } - - public void regionsReplaced(RegionsReplacedEvent structuredDocumentEvent) { - if(fInRewriteSession) { - fHasIncomingChanges = true; - return; - } - if (_trace) { - time1 = System.currentTimeMillis(); - } - IRegion damage; - IStructuredDocumentRegion documentRegion = structuredDocumentEvent.getStructuredDocumentRegion(); - ITextRegionList newRegions = structuredDocumentEvent.getNewRegions(); - if (newRegions.size() > 0) { - ITextRegion firstChangedRegion = newRegions.get(0); - ITextRegion lastChangedRegion = newRegions.get(newRegions.size() - 1); - int startOffset = documentRegion.getStartOffset(firstChangedRegion); - int length = documentRegion.getEndOffset(lastChangedRegion) - startOffset; - damage = new Region(startOffset, length); - } - else { - damage = new Region(documentRegion.getStartOffset(), documentRegion.getLength()); - } - recordDamage(damage, structuredDocumentEvent.fDocument); - if (_trace) { - System.out.println("\n" + TRACE_PREFIX + "calculated damage for RegionsReplacedEvent: [" + damage.getOffset() + ":" + damage.getLength() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$ - System.out.flush(); - } - if (_trace && _traceTime) { - System.out.println(TRACE_PREFIX + "calculated damage for RegionsReplacedEvent in " + (System.currentTimeMillis()-time1) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.flush(); - } - } - - /* - * @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument, IDocument) - */ - public void inputDocumentAboutToBeChanged(IDocument oldDocument, IDocument newDocument) { - if (oldDocument != null) { - try { - - fViewer.removeTextListener(this); - oldDocument.removeDocumentListener(this); - oldDocument.removeDocumentPartitioningListener(this); - if (oldDocument instanceof IStructuredDocument) { - ((IStructuredDocument) oldDocument).removeDocumentChangedListener(this); - } - - oldDocument.removePositionUpdater(fPositionUpdater); - oldDocument.removePositionCategory(fPositionCategory); - - } catch (BadPositionCategoryException x) { - // should not happened for former input documents; - } - } - } - - /* - * @see ITextInputListener#inputDocumenChanged(IDocument, IDocument) - */ - public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) { - if (_trace || _traceTime) { - time1 = System.currentTimeMillis(); - } - - fDocumentChanging= false; - fCachedRedrawState= true; - - if (newDocument != null) { - newDocument.addPositionCategory(fPositionCategory); - newDocument.addPositionUpdater(fPositionUpdater); - - if (newDocument instanceof IStructuredDocument) { - newDocument.addDocumentPartitioningListener(this); - newDocument.addDocumentListener(this); - ((IStructuredDocument)newDocument).addDocumentChangedListener(this); - } - fViewer.addTextListener(this); - - if (newDocument instanceof IStructuredDocument) { - setDocumentToDamagers(newDocument); - setDocumentToRepairers(newDocument); - processDamage(new Region(0, newDocument.getLength()), newDocument); - } - } - if (_trace) { - System.out.println(TRACE_PREFIX + "processed damage for inputDocumentChanged in " + (System.currentTimeMillis() - time1) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /* - * @see IDocumentPartitioningListener#documentPartitioningChanged(IDocument) - */ - public void documentPartitioningChanged(IDocument document) { - if (_traceTime) { - time0 = System.currentTimeMillis(); - } - if (!fDocumentChanging && fCachedRedrawState) - processDamage(new Region(0, document.getLength()), document); - else - fDocumentPartitioningChanged= true; - if (_trace) { - System.out.println(TRACE_PREFIX + "processed damage for documentPartitioningChanged [full document]"); //$NON-NLS-1$ - } - if (_trace && _traceTime) { - System.out.println(TRACE_PREFIX + "processed damage for documentPartitioningChanged in " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /* - * @see IDocumentPartitioningListenerExtension#documentPartitioningChanged(IDocument, IRegion) - * @since 2.0 - */ - public void documentPartitioningChanged(IDocument document, IRegion changedRegion) { - if (_traceTime) { - time0 = System.currentTimeMillis(); - } - if (!fDocumentChanging && fCachedRedrawState) { - processDamage(new Region(changedRegion.getOffset(), changedRegion.getLength()), document); - } else { - fDocumentPartitioningChanged= true; - fChangedDocumentPartitions= changedRegion; - } - if (_trace) { - System.out.println(TRACE_PREFIX + "processed damage for documentPartitioningChanged [" + changedRegion.getOffset() + ":" + changedRegion.getLength() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - if (_trace && _traceTime) { - System.out.println(TRACE_PREFIX + "processed damage for documentPartitioningChanged in " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /* - * @see org.eclipse.jface.text.IDocumentPartitioningListenerExtension2#documentPartitioningChanged(org.eclipse.jface.text.DocumentPartitioningChangedEvent) - * @since 3.0 - */ - public void documentPartitioningChanged(DocumentPartitioningChangedEvent event) { - IRegion changedRegion= event.getChangedRegion(getDocumentPartitioning()); - if (changedRegion != null) - documentPartitioningChanged(event.getDocument(), changedRegion); - } - - /* - * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent) - */ - public void documentAboutToBeChanged(DocumentEvent e) { - - fDocumentChanging= true; - if (fCachedRedrawState) { - try { - int offset= e.getOffset() + e.getLength(); - ITypedRegion region= getPartition(e.getDocument(), offset); - fRememberedPosition= new TypedPosition(region); - e.getDocument().addPosition(fPositionCategory, fRememberedPosition); - } catch (BadLocationException x) { - // can not happen - } catch (BadPositionCategoryException x) { - // should not happen on input elements - } - } - } - - /* - * @see IDocumentListener#documentChanged(DocumentEvent) - */ - public void documentChanged(DocumentEvent e) { - if (fCachedRedrawState) { - try { - e.getDocument().removePosition(fPositionCategory, fRememberedPosition); - } catch (BadPositionCategoryException x) { - // can not happen on input documents - } - } - fDocumentChanging= false; - } - - /* - * @see ITextListener#textChanged(TextEvent) - */ - public void textChanged(TextEvent e) { - if(fInRewriteSession) { - fHasIncomingChanges = true; - return; - } - fCachedRedrawState= e.getViewerRedrawState(); - if (!fCachedRedrawState) { - if (_trace) { - System.out.println("\n" + TRACE_PREFIX + "returned early from textChanged(TextEvent)"); //$NON-NLS-1$ //$NON-NLS-2$ - } - return; - } - if (_trace) { - System.out.println("\n" + TRACE_PREFIX + "entering textChanged(TextEvent)"); //$NON-NLS-1$ //$NON-NLS-2$ - time0 = System.currentTimeMillis(); - } - - IRegion damage= null; - IDocument document= null; - - if (e.getDocumentEvent() == null) { - document= fViewer.getDocument(); - if (document != null) { - if (e.getOffset() == 0 && e.getLength() == 0 && e.getText() == null) { - // redraw state change, damage the whole document - damage= new Region(0, document.getLength()); - } else { - IRegion region= widgetRegion2ModelRegion(e); - try { - String text= document.get(region.getOffset(), region.getLength()); - DocumentEvent de= new DocumentEvent(document, region.getOffset(), region.getLength(), text); - damage= getDamage(de, false); - } catch (BadLocationException x) { - /* ignored in platform PresentationReconciler, too */ - } - } - } - } else { - DocumentEvent de= e.getDocumentEvent(); - document= de.getDocument(); - damage= getDamage(de, true); - } - if(_trace && _traceTime) { - System.out.println(TRACE_PREFIX + "calculated simple text damage at " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.flush(); - } - - boolean damageOverlaps = processRecordedDamages(damage, document); - if(_trace && _traceTime) { - System.out.println(TRACE_PREFIX + "processed recorded structured text damage at " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - - if (damage != null && document != null && !damageOverlaps) { - processDamage(damage, document); - if(_trace && _traceTime) { - System.out.println(TRACE_PREFIX + "processed simple text damage at " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - System.out.flush(); - } - } - - fDocumentPartitioningChanged= false; - fChangedDocumentPartitions= null; - if(_trace) { - System.out.println(TRACE_PREFIX + "finished textChanged(TextEvent) in " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /** - * Translates the given text event into the corresponding range of the viewer's document. - * - * @param e the text event - * @return the widget region corresponding the region of the given event - * @since 2.1 - */ - protected IRegion widgetRegion2ModelRegion(TextEvent e) { - - String text= e.getText(); - int length= text == null ? 0 : text.length(); - - if (fViewer instanceof ITextViewerExtension5) { - ITextViewerExtension5 extension= (ITextViewerExtension5) fViewer; - return extension.widgetRange2ModelRange(new Region(e.getOffset(), length)); - } - - IRegion visible= fViewer.getVisibleRegion(); - IRegion region= new Region(e.getOffset() + visible.getOffset(), length); - return region; - } - - public void documentRewriteSessionChanged(DocumentRewriteSessionEvent event) { - fInRewriteSession = (event != null && event.fChangeType == DocumentRewriteSessionEvent.SESSION_START); - if(!fInRewriteSession && fHasIncomingChanges && event != null) { - if (_trace) - time0 = System.currentTimeMillis(); - processDamage(new Region(0, event.fDocument.getLength()), event.fDocument); - if(_trace && _traceTime) - System.out.println(TRACE_PREFIX + " processed damaged after ending document rewrite session at " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - fHasIncomingChanges = false; - } - } - - } - - private static class RecordedDamage { - IRegion damage; - IDocument document; - RecordedDamage(IRegion damage, IDocument document) { - this.damage = damage; - this.document = document; - } - } - - /** The map of presentation damagers. */ - private Map fDamagers; - /** The map of presentation repairers. */ - private Map fRepairers; - /** The target viewer. */ - private ITextViewer fViewer; - /** The internal listener. */ - private InternalListener fInternalListener= new InternalListener(); - /** The name of the position category to track damage regions. */ - private String fPositionCategory; - /** The position updated for the damage regions' position category. */ - private IPositionUpdater fPositionUpdater; - /** The positions representing the damage regions. */ - private TypedPosition fRememberedPosition; - /** Flag indicating the receipt of a partitioning changed notification. */ - private boolean fDocumentPartitioningChanged= false; - /** The range covering the changed partitioning. */ - private IRegion fChangedDocumentPartitions= null; - - /** - * Because structured document events fire before textChanged(), it's - * possible the widget isn't fully aware of the changes to its contents. - * "Record" the damage to process after textChanged() has been fired. - */ - private List fRecordedDamages = new ArrayList(2); - - /** - * The partitioning used by this presentation reconciler. - * @since 3.0 - */ - private String fPartitioning; - - private IDocument fLastDocument; - - /** - * Creates a new presentation reconciler. There are no damagers or repairers - * registered with this reconciler by default. The default partitioning - * <code>IDocumentExtension3.DEFAULT_PARTITIONING</code> is used. - */ - public StructuredPresentationReconciler() { - super(); - fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING; - fPositionCategory= TRACKED_PARTITION + hashCode(); - fPositionUpdater= new DefaultPositionUpdater(fPositionCategory); - } - - /** - * Sets the document partitioning for this presentation reconciler. - * - * @param partitioning the document partitioning for this presentation reconciler. - * @since 3.0 - */ - public void setDocumentPartitioning(String partitioning) { - Assert.isNotNull(partitioning); - fPartitioning= partitioning; - } - - /* - * @see org.eclipse.jface.text.presentation.IPresentationReconcilerExtension#geDocumenttPartitioning() - * @since 3.0 - */ - public String getDocumentPartitioning() { - return fPartitioning; - } - - /** - * Registers the given presentation damager for a particular content type. - * If there is already a damager registered for this type, the old damager - * is removed first. - * - * @param damager the presentation damager to register, or <code>null</code> to remove an existing one - * @param contentType the content type under which to register - */ - public void setDamager(IPresentationDamager damager, String contentType) { - - Assert.isNotNull(contentType); - - if (fDamagers == null) - fDamagers= new HashMap(); - - if (damager == null) - fDamagers.remove(contentType); - else - fDamagers.put(contentType, damager); - } - - /** - * Registers the given presentation repairer for a particular content type. - * If there is already a repairer registered for this type, the old repairer - * is removed first. - * - * @param repairer the presentation repairer to register, or <code>null</code> to remove an existing one - * @param contentType the content type under which to register - */ - public void setRepairer(IPresentationRepairer repairer, String contentType) { - - Assert.isNotNull(contentType); - - if (fRepairers == null) - fRepairers= new HashMap(); - - if (repairer == null) - fRepairers.remove(contentType); - else - fRepairers.put(contentType, repairer); - } - - /* - * @see IPresentationReconciler#install(ITextViewer) - */ - public void install(ITextViewer viewer) { - if(_trace) { - time0 = System.currentTimeMillis(); - } - Assert.isNotNull(viewer); - - fViewer= viewer; - fViewer.addTextInputListener(fInternalListener); - - IDocument document= viewer.getDocument(); - if (document != null) { - fInternalListener.inputDocumentChanged(null, document); - if(document instanceof IStructuredDocument) { - ((IStructuredDocument) document).addDocumentChangedListener(fInternalListener); - } - if(document instanceof IDocumentExtension4) { - ((IDocumentExtension4) document).addDocumentRewriteSessionListener(fInternalListener); - } - } - if(_trace) { - System.out.println(TRACE_PREFIX + "installed to text viewer in " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /* - * @see IPresentationReconciler#uninstall() - */ - public void uninstall() { - if(_trace) { - time0 = System.currentTimeMillis(); - } - fViewer.removeTextInputListener(fInternalListener); - - IDocument document = null; - if(( document = fViewer.getDocument()) instanceof IStructuredDocument) { - ((IStructuredDocument) document).removeDocumentChangedListener(fInternalListener); - } - if(document instanceof IDocumentExtension4) { - ((IDocumentExtension4) document).removeDocumentRewriteSessionListener(fInternalListener); - } - // Ensure we uninstall all listeners - fInternalListener.inputDocumentAboutToBeChanged(fViewer.getDocument(), null); - if(_trace) { - System.out.println(TRACE_PREFIX + "uninstalled from text viewer in " + (System.currentTimeMillis() - time0) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - - /* - * @see IPresentationReconciler#getDamager(String) - */ - public IPresentationDamager getDamager(String contentType) { - - if (fDamagers == null) - return null; - - return (IPresentationDamager) fDamagers.get(contentType); - } - - /* - * @see IPresentationReconciler#getRepairer(String) - */ - public IPresentationRepairer getRepairer(String contentType) { - - if (fRepairers == null) - return null; - - return (IPresentationRepairer) fRepairers.get(contentType); - } - - /** - * Informs all registered damagers about the document on which they will work. - * - * @param document the document on which to work - */ - protected void setDocumentToDamagers(IDocument document) { - if (fDamagers != null) { - Iterator e= fDamagers.values().iterator(); - while (e.hasNext()) { - IPresentationDamager damager= (IPresentationDamager) e.next(); - damager.setDocument(document); - } - } - } - - /** - * Informs all registered repairers about the document on which they will work. - * - * @param document the document on which to work - */ - protected void setDocumentToRepairers(IDocument document) { - if (fRepairers != null) { - Iterator e= fRepairers.values().iterator(); - while (e.hasNext()) { - IPresentationRepairer repairer= (IPresentationRepairer) e.next(); - repairer.setDocument(document); - } - } - } - - /** - * Constructs a "repair description" for the given damage and returns this - * description as a text presentation. For this, it queries the partitioning - * of the damage region and asks the appropriate presentation repairer for - * each partition to construct the "repair description" for this partition. - * - * @param damage the damage to be repaired - * @param document the document whose presentation must be repaired - * @return the presentation repair description as text presentation or - * <code>null</code> if the partitioning could not be computed - */ - protected TextPresentation createPresentation(IRegion damage, IDocument document) { - try { - int validLength = Math.min(damage.getLength(), document.getLength() - damage.getOffset()); - - if (fRepairers == null || fRepairers.isEmpty()) { - TextPresentation presentation= new TextPresentation(damage, 1); - presentation.setDefaultStyleRange(new StyleRange(damage.getOffset(), validLength, null, null)); - return presentation; - } - - TextPresentation presentation= new TextPresentation(damage, 1000); - - ITypedRegion[] partitions= TextUtilities.computePartitioning(document, getDocumentPartitioning(), damage.getOffset(), validLength, false); - for (int i= 0; i < partitions.length; i++) { - ITypedRegion r= partitions[i]; - IPresentationRepairer repairer= getRepairer(r.getType()); - if (repairer != null) - repairer.createPresentation(presentation, r); - } - - return presentation; - - } catch (BadLocationException x) { - /* ignored in platform PresentationReconciler, too */ - } - - return null; - } - - - /** - * Checks for the first and the last affected partition affected by a - * document event and calls their damagers. Invalidates everything from the - * start of the damage for the first partition until the end of the damage - * for the last partition. - * - * @param e the event describing the document change - * @param optimize <code>true</code> if partition changes should be - * considered for optimization - * @return the damaged caused by the change or <code>null</code> if - * computing the partitioning failed - * @since 3.0 - */ - IRegion getDamage(DocumentEvent e, boolean optimize) { - int length= e.getText() == null ? 0 : e.getText().length(); - - if (fDamagers == null || fDamagers.isEmpty()) { - length= Math.max(e.getLength(), length); - length= Math.min(e.getDocument().getLength() - e.getOffset(), length); - return new Region(e.getOffset(), length); - } - - boolean isDeletion= length == 0; - IRegion damage= null; - try { - int offset= e.getOffset(); - if (isDeletion) - offset= Math.max(0, offset - 1); - ITypedRegion partition= getPartition(e.getDocument(), offset); - IPresentationDamager damager= getDamager(partition.getType()); - if (damager == null) - return null; - - IRegion r= damager.getDamageRegion(partition, e, fDocumentPartitioningChanged); - - if (!fDocumentPartitioningChanged && optimize && !isDeletion) { - damage= r; - } else { - - int damageEnd= getDamageEndOffset(e); - - int parititionDamageEnd= -1; - if (fChangedDocumentPartitions != null) - parititionDamageEnd= fChangedDocumentPartitions.getOffset() + fChangedDocumentPartitions.getLength(); - - int end= Math.max(damageEnd, parititionDamageEnd); - - damage= end == -1 ? r : new Region(r.getOffset(), end - r.getOffset()); - } - - } catch (BadLocationException x) { - /* ignored in platform PresentationReconciler, too */ - } - - return damage; - } - - /** - * Returns the end offset of the damage. If a partition has been split by - * the given document event also the second half of the original - * partition must be considered. This is achieved by using the remembered - * partition range. - * - * @param e the event describing the change - * @return the damage end offset (excluding) - * @exception BadLocationException if method accesses invalid offset - */ - int getDamageEndOffset(DocumentEvent e) throws BadLocationException { - - IDocument d= e.getDocument(); - - int length= 0; - if (e.getText() != null) { - length= e.getText().length(); - if (length > 0) - -- length; - } - - ITypedRegion partition= getPartition(d, e.getOffset() + length); - int endOffset= partition.getOffset() + partition.getLength(); - if (endOffset == e.getOffset()) - return -1; - - int end= fRememberedPosition == null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength(); - if (endOffset < end && end < d.getLength()) - partition= getPartition(d, end); - - IPresentationDamager damager= getDamager(partition.getType()); - if (damager == null) - return -1; - - IRegion r= damager.getDamageRegion(partition, e, fDocumentPartitioningChanged); - - return r.getOffset() + r.getLength(); - } - - void processRecordedDamages() { - processRecordedDamages(null, null); - } - - boolean processRecordedDamages(IRegion damage, IDocument document) { - RecordedDamage[] recordings = null; - boolean recordingOverlaps = false; - synchronized (fRecordedDamages) { - recordings = (RecordedDamage[]) fRecordedDamages.toArray(new RecordedDamage[fRecordedDamages.size()]); - fRecordedDamages.clear(); - } - for (int i = 0; i < recordings.length; i++) { - if (isOverlappingRegion(damage, recordings[i].damage) && document == recordings[i].document) - recordingOverlaps = true; - processDamage(recordings[i].damage, recordings[i].document); - } - return recordingOverlaps; - } - - private boolean isOverlappingRegion(IRegion base, IRegion damage) { - if(base == null || damage == null) - return false; - - int baseEnd = base.getOffset() + base.getLength(); - int damageEnd = damage.getOffset() + damage.getLength(); - - return damage.getOffset() <= base.getOffset() && (damageEnd >= baseEnd); - } - - /** - * Processes the given damage. - * @param damage the damage to be repaired - * @param document the document whose presentation must be repaired - */ - void processDamage(IRegion damage, IDocument document) { - if (damage != null && damage.getLength() > 0) { - TextPresentation p = createPresentation(damage, document); - if (p != null) { - /** - * 229749 - Read-Only highlighting support missing - * 272981 - Read-only highlighting moved to semantic highlighting - */ - applyTextRegionCollection(p); - } - } - } - - /** - * Processes the given damage. - * @param damage the damage to be repaired - * @param document the document whose presentation must be repaired - */ - void recordDamage(IRegion damage, IDocument document) { - if (damage != null && damage.getLength() > 0) { - synchronized (fRecordedDamages) { - fRecordedDamages.add(new RecordedDamage(damage, document)); - } - } - } - - /** - * Applies the given text presentation to the text viewer the presentation - * reconciler is installed on. - * - * @param presentation the text presentation to be applied to the text viewer - */ - void applyTextRegionCollection(TextPresentation presentation) { - fViewer.changeTextPresentation(presentation, false); - } - - /** - * Returns the partition for the given offset in the given document. - * - * @param document the document - * @param offset the offset - * @return the partition - * @throws BadLocationException if offset is invalid in the given document - * @since 3.0 - */ - ITypedRegion getPartition(IDocument document, int offset) throws BadLocationException { - return TextUtilities.getPartition(document, getDocumentPartitioning(), offset, false); - } - - /** - * Constructs a "repair description" for the given damage and returns this - * description as a text presentation, essentially making - * {@link #createPresentation(IRegion, IDocument)} publicly callable. - * <p> - * NOTE: Should not be used if this reconciler is installed on a viewer. - * This method is considered EXPERIMENTAL and may not be available in - * subsequent versions. - * </p> - * - * @param damage - * the damage to be repaired - * @param document - * the document whose presentation must be repaired - * @return the presentation repair description as text presentation - */ - public TextPresentation createRepairDescription(IRegion damage, IDocument document) { - if (document != fLastDocument) { - setDocumentToDamagers(document); - setDocumentToRepairers(document); - fLastDocument= document; - } - return createPresentation(damage, document); - } - -} |