2 * Copyright (c) 2002-2004 Widespace, OU and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Igor Malinin - initial contribution
11 * $Id: XMLMergeViewer.java,v 1.1 2004-09-02 18:28:05 jsurfer Exp $
14 package net.sourceforge.phpeclipse.xml.ui.internal.compare;
16 import org.eclipse.compare.CompareConfiguration;
17 import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
18 import org.eclipse.jface.preference.IPreferenceStore;
19 import org.eclipse.jface.preference.PreferenceConverter;
20 import org.eclipse.jface.text.IDocumentPartitioner;
21 import org.eclipse.jface.text.TextViewer;
22 import org.eclipse.jface.text.source.SourceViewer;
23 import org.eclipse.jface.util.IPropertyChangeListener;
24 import org.eclipse.jface.util.PropertyChangeEvent;
25 import org.eclipse.swt.events.DisposeEvent;
26 import org.eclipse.swt.graphics.RGB;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.ui.texteditor.AbstractTextEditor;
30 import net.sourceforge.phpeclipse.xml.ui.XMLPlugin;
31 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLConfiguration;
32 import net.sourceforge.phpeclipse.xml.ui.text.XMLTextTools;
35 * @author Igor Malinin
37 public class XMLMergeViewer extends TextMergeViewer {
40 * The preference store.
42 private IPreferenceStore preferenceStore;
45 * The listener for changes to the preference store.
47 private IPropertyChangeListener propertyChangeListener;
52 private XMLTextTools textTools;
55 * @see TextMergeViewer#TextMergeViewer(Composite, int,
56 * CompareConfiguration)
58 public XMLMergeViewer(Composite parent, int style,
59 CompareConfiguration configuration) {
60 super(parent, style, configuration);
63 // TextMergeViewer Implementation
64 // ------------------------------------------
67 * @see TextMergeViewer#configureTextViewer()
69 protected void configureTextViewer(TextViewer textViewer) {
70 XMLPlugin plugin = XMLPlugin.getDefault();
72 preferenceStore = plugin.getPreferenceStore();
73 if (preferenceStore != null) {
74 propertyChangeListener = new IPropertyChangeListener() {
75 public void propertyChange(PropertyChangeEvent event) {
76 handlePreferenceStoreChanged(event);
79 preferenceStore.addPropertyChangeListener(propertyChangeListener);
82 textTools = plugin.getXMLTextTools();
84 if (textViewer instanceof SourceViewer) {
85 SourceViewer sourceViewer = (SourceViewer) textViewer;
86 sourceViewer.configure(new XMLConfiguration(textTools));
89 updateBackgroundColor();
93 * @see TextMergeViewer#getDocumentPartitioner()
95 protected IDocumentPartitioner getDocumentPartitioner() {
96 return textTools.createXMLPartitioner();
100 * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#getTitle()
102 public String getTitle() {
103 return XMLPlugin.getResourceString("XMLMergeViewer.title"); //$NON-NLS-1$
107 * @see org.eclipse.jface.viewers.ContentViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
109 protected void handleDispose(DisposeEvent event) {
110 if (propertyChangeListener != null) {
111 if (preferenceStore != null) {
112 preferenceStore.removePropertyChangeListener(
113 propertyChangeListener);
116 propertyChangeListener = null;
119 super.handleDispose(event);
122 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
123 String p = event.getProperty();
125 if (p.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)
126 || p.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) {
127 updateBackgroundColor();
128 } else if (textTools.affectsBehavior(event)) {
129 invalidateTextPresentation();
133 private void updateBackgroundColor() {
134 boolean defaultBackgroundColor = preferenceStore.getBoolean(
135 AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
137 if (defaultBackgroundColor) {
138 setBackgroundColor(null);
140 RGB backgroundColor = PreferenceConverter.getColor(preferenceStore,
141 AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
142 setBackgroundColor(backgroundColor);