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: DTDMergeViewer.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.DTDConfiguration;
32 import net.sourceforge.phpeclipse.xml.ui.text.DTDTextTools;
35 * @author Igor Malinin
37 public class DTDMergeViewer 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 DTDTextTools textTools;
55 * @see TextMergeViewer#TextMergeViewer(Composite, int, CompareConfiguration)
57 public DTDMergeViewer(
58 Composite parent, int style, CompareConfiguration configuration
60 super(parent, style, configuration);
63 // TextMergeViewer Implementation ------------------------------------------
66 * @see TextMergeViewer#configureTextViewer()
68 protected void configureTextViewer(TextViewer textViewer) {
69 XMLPlugin plugin = XMLPlugin.getDefault();
71 preferenceStore = plugin.getPreferenceStore();
72 if (preferenceStore != null) {
73 propertyChangeListener = new IPropertyChangeListener() {
74 public void propertyChange(PropertyChangeEvent event) {
75 handlePreferenceStoreChanged(event);
78 preferenceStore.addPropertyChangeListener(propertyChangeListener);
81 textTools = plugin.getDTDTextTools();
83 if (textViewer instanceof SourceViewer) {
84 SourceViewer sourceViewer = (SourceViewer) textViewer;
85 sourceViewer.configure(new DTDConfiguration(textTools));
88 updateBackgroundColor();
92 * @see TextMergeViewer#getDocumentPartitioner()
94 protected IDocumentPartitioner getDocumentPartitioner() {
95 return textTools.createDTDPartitioner();
99 * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#getTitle()
101 public String getTitle() {
102 return XMLPlugin.getResourceString("DTDMergeViewer.title"); //$NON-NLS-1$
106 * @see org.eclipse.jface.viewers.ContentViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
108 protected void handleDispose(DisposeEvent event) {
109 if (propertyChangeListener != null) {
110 if (preferenceStore != null) {
112 .removePropertyChangeListener(propertyChangeListener);
115 propertyChangeListener = null;
118 super.handleDispose(event);
121 protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
122 String p = event.getProperty();
124 if (p.equals(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND) ||
125 p.equals(AbstractTextEditor
126 .PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)
128 updateBackgroundColor();
129 } else if (textTools.affectsBehavior(event)) {
130 invalidateTextPresentation();
134 private void updateBackgroundColor() {
135 boolean defaultBackgroundColor = preferenceStore.getBoolean(
136 AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT);
138 if (defaultBackgroundColor) {
139 setBackgroundColor(null);
141 RGB backgroundColor = PreferenceConverter
142 .getColor(preferenceStore,
143 AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND);
144 setBackgroundColor(backgroundColor);