001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.compare;
011:
012: import org.eclipse.compare.CompareConfiguration;
013: import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
014: import org.eclipse.jface.preference.IPreferenceStore;
015: import org.eclipse.jface.resource.JFaceResources;
016: import org.eclipse.jface.text.IDocumentPartitioner;
017: import org.eclipse.jface.text.TextViewer;
018: import org.eclipse.jface.text.rules.FastPartitioner;
019: import org.eclipse.jface.text.source.SourceViewer;
020: import org.eclipse.jface.util.IPropertyChangeListener;
021: import org.eclipse.jface.util.PropertyChangeEvent;
022: import org.eclipse.pde.internal.ui.PDEPlugin;
023: import org.eclipse.pde.internal.ui.PDEUIMessages;
024: import org.eclipse.pde.internal.ui.editor.context.XMLDocumentSetupParticpant;
025: import org.eclipse.pde.internal.ui.editor.text.ColorManager;
026: import org.eclipse.pde.internal.ui.editor.text.IColorManager;
027: import org.eclipse.pde.internal.ui.editor.text.XMLConfiguration;
028: import org.eclipse.pde.internal.ui.editor.text.XMLPartitionScanner;
029: import org.eclipse.swt.events.DisposeEvent;
030: import org.eclipse.swt.events.DisposeListener;
031: import org.eclipse.swt.graphics.Font;
032: import org.eclipse.swt.widgets.Composite;
033:
034: public class PluginContentMergeViewer extends TextMergeViewer {
035:
036: private IColorManager fColorManager;
037:
038: public PluginContentMergeViewer(Composite parent,
039: CompareConfiguration config) {
040: super (parent, config);
041: }
042:
043: protected void configureTextViewer(final TextViewer textViewer) {
044: if (textViewer instanceof SourceViewer) {
045: if (fColorManager == null)
046: fColorManager = ColorManager.getDefault();
047: final XMLConfiguration configuration = new XMLConfiguration(
048: fColorManager);
049: textViewer.getControl().addDisposeListener(
050: new DisposeListener() {
051: public void widgetDisposed(DisposeEvent e) {
052: configuration.dispose();
053: }
054: });
055: IPreferenceStore store = PDEPlugin.getDefault()
056: .getPreferenceStore();
057: store
058: .addPropertyChangeListener(new IPropertyChangeListener() {
059: public void propertyChange(
060: PropertyChangeEvent event) {
061: // the configuration will test if the properties affect the presentation also,
062: // but checking it here allows us to prevent the viewer from being invalidated
063: // and saves some unnecessary work
064: if (configuration
065: .affectsColorPresentation(event)
066: || configuration
067: .affectsTextPresentation(event)) {
068: configuration
069: .adaptToPreferenceChange(event);
070: textViewer.invalidateTextPresentation();
071: }
072: }
073: });
074: ((SourceViewer) textViewer).configure(configuration);
075: Font font = JFaceResources
076: .getFont(PluginContentMergeViewer.class.getName());
077: if (font != null)
078: ((SourceViewer) textViewer).getTextWidget().setFont(
079: font);
080: }
081: }
082:
083: protected IDocumentPartitioner getDocumentPartitioner() {
084: return new FastPartitioner(new XMLPartitionScanner(),
085: XMLPartitionScanner.PARTITIONS);
086: }
087:
088: protected String getDocumentPartitioning() {
089: return XMLDocumentSetupParticpant.XML_PARTITIONING;
090: }
091:
092: public String getTitle() {
093: return PDEUIMessages.PluginContentMergeViewer_title;
094: }
095:
096: protected void handleDispose(DisposeEvent event) {
097: if (fColorManager != null)
098: fColorManager.dispose();
099: super.handleDispose(event);
100: }
101: }
|