Search in sources :

Example 1 with ISemanticHighlighting

use of org.eclipse.wst.sse.ui.ISemanticHighlighting in project webtools.sourceediting by eclipse.

the class SemanticHighlightingManager method handleHighlightingPropertyChange.

/**
 * Handles property change events for individual semantic highlightings.
 * @param event
 */
private void handleHighlightingPropertyChange(PropertyChangeEvent event) {
    String property = event.getProperty();
    if (property == null)
        return;
    boolean refreshRequired = false;
    for (int i = 0; i < fHighlightings.length; i++) {
        ISemanticHighlighting highlighting = fHighlightings[i];
        if (fHighlightingStyleStringKeys[i] != null) {
            if (property.equals(fHighlightingStyleStringKeys[i])) {
                adaptToStyleChange(fHighlightingStyles[i], event);
                fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
                refreshRequired = true;
                continue;
            }
        }
        if (property.equals(highlighting.getBoldPreferenceKey())) {
            adaptToTextStyleChange(fHighlightingStyles[i], event, SWT.BOLD);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getColorPreferenceKey())) {
            adaptToTextForegroundChange(fHighlightingStyles[i], event);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getEnabledPreferenceKey())) {
            adaptToEnablementChange(fHighlightingStyles[i], event);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getItalicPreferenceKey())) {
            adaptToTextStyleChange(fHighlightingStyles[i], event, SWT.ITALIC);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getStrikethroughPreferenceKey())) {
            adaptToTextStyleChange(fHighlightingStyles[i], event, TextAttribute.STRIKETHROUGH);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (property.equals(highlighting.getUnderlinePreferenceKey())) {
            adaptToTextStyleChange(fHighlightingStyles[i], event, TextAttribute.UNDERLINE);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
        if (highlighting instanceof ISemanticHighlightingExtension2 && property.equals(((ISemanticHighlightingExtension2) highlighting).getBackgroundColorPreferenceKey())) {
            adaptToTextBackgroundChange(fHighlightingStyles[i], event);
            fPresenter.highlightingStyleChanged(fHighlightingStyles[i]);
            refreshRequired = true;
            continue;
        }
    }
    if (refreshRequired && fReconciler != null)
        fReconciler.refresh();
}
Also used : ISemanticHighlightingExtension2(org.eclipse.wst.sse.ui.ISemanticHighlightingExtension2) ISemanticHighlighting(org.eclipse.wst.sse.ui.ISemanticHighlighting)

Example 2 with ISemanticHighlighting

use of org.eclipse.wst.sse.ui.ISemanticHighlighting in project webtools.sourceediting by eclipse.

the class SemanticHighlightingManager method loadSemanticHighlightings.

/**
 * Load the semantic highlightings defined for this content type.
 */
private void loadSemanticHighlightings() {
    List semantics = new ArrayList(0);
    ISemanticHighlighting highlighting = null;
    String styleKey = null;
    String id = null;
    String after = null;
    IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(SSEUIPlugin.ID, SEMANTIC_HIGHLIGHTING_EXTENSION_POINT);
    IContentType contentType = Platform.getContentTypeManager().getContentType(fContentTypeId);
    for (int i = 0; i < elements.length; i++) {
        String[] targets = StringUtils.unpack(elements[i].getAttribute(TARGET_ATTR));
        for (int j = 0; j < targets.length; j++) {
            IContentType targetContentType = Platform.getContentTypeManager().getContentType(targets[j]);
            /* Apply semantic highlighting to kinds of targetContentType */
            if (contentType.isKindOf(targetContentType)) {
                try {
                    highlighting = (ISemanticHighlighting) elements[i].createExecutableExtension(CLASS_ATTR);
                    styleKey = elements[i].getAttribute(STYLE_KEY_ATTR);
                    id = elements[i].getAttribute(ID_ATTR);
                    after = elements[i].getAttribute(AFTER_ATTR);
                } catch (CoreException e) {
                    Logger.logException(e);
                }
                if (highlighting != null) {
                    // The highlighting was not inserted through priority; insert at the beginning of the list
                    semantics.add(new SemanticContent(targetContentType, highlighting, styleKey, id, after));
                }
                break;
            }
        }
    }
    /* Sort the semantics, so that styles will be applied from general to specific */
    Collections.sort(semantics);
    fHighlightings = new ISemanticHighlighting[semantics.size()];
    fHighlightingStyles = new HighlightingStyle[semantics.size()];
    fHighlightingStyleStringKeys = new String[semantics.size()];
    for (int i = 0; i < semantics.size(); i++) {
        fHighlightings[i] = ((SemanticContent) semantics.get(i)).getHighlighting();
        styleKey = ((SemanticContent) semantics.get(i)).getStyleKey();
        fHighlightingStyles[i] = createHighlightingStyle(((SemanticContent) semantics.get(i)).getHighlighting(), styleKey);
        fHighlightingStyleStringKeys[i] = styleKey;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IContentType(org.eclipse.core.runtime.content.IContentType) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ISemanticHighlighting(org.eclipse.wst.sse.ui.ISemanticHighlighting)

Aggregations

ISemanticHighlighting (org.eclipse.wst.sse.ui.ISemanticHighlighting)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IContentType (org.eclipse.core.runtime.content.IContentType)1 ISemanticHighlightingExtension2 (org.eclipse.wst.sse.ui.ISemanticHighlightingExtension2)1