01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.compare;
11:
12: import org.eclipse.swt.SWT;
13: import org.eclipse.swt.widgets.Composite;
14:
15: import org.eclipse.compare.CompareConfiguration;
16: import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
17:
18: import org.eclipse.jface.preference.IPreferenceStore;
19:
20: import org.eclipse.jface.text.IDocumentPartitioner;
21: import org.eclipse.jface.text.TextViewer;
22: import org.eclipse.jface.text.rules.FastPartitioner;
23: import org.eclipse.jface.text.source.SourceViewer;
24: import org.eclipse.jface.text.source.SourceViewerConfiguration;
25:
26: import org.eclipse.jdt.ui.text.JavaTextTools;
27:
28: import org.eclipse.jdt.internal.ui.JavaPlugin;
29: import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions;
30: import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFilePartitionScanner;
31: import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertiesFileSourceViewerConfiguration;
32:
33: /**
34: * Properties file merge viewer.
35: *
36: * @since 3.1
37: */
38: public class PropertiesFileMergeViewer extends TextMergeViewer {
39:
40: /**
41: * Creates a properties file merge viewer under the given parent control.
42: *
43: * @param parent the parent control
44: * @param configuration the configuration object
45: */
46: public PropertiesFileMergeViewer(Composite parent,
47: CompareConfiguration configuration) {
48: super (parent, SWT.LEFT_TO_RIGHT, configuration);
49: }
50:
51: /*
52: * @see org.eclipse.compare.contentmergeviewer.TextMergeViewer#configureTextViewer(org.eclipse.jface.text.TextViewer)
53: */
54: protected void configureTextViewer(TextViewer textViewer) {
55: if (textViewer instanceof SourceViewer) {
56: JavaTextTools tools = JavaCompareUtilities
57: .getJavaTextTools();
58: if (tools != null)
59: ((SourceViewer) textViewer)
60: .configure(getSourceViewerConfiguration(tools));
61: }
62: }
63:
64: private SourceViewerConfiguration getSourceViewerConfiguration(
65: JavaTextTools textTools) {
66: IPreferenceStore store = JavaPlugin.getDefault()
67: .getCombinedPreferenceStore();
68: return new PropertiesFileSourceViewerConfiguration(textTools
69: .getColorManager(), store, null,
70: getDocumentPartitioning());
71: }
72:
73: /*
74: * @see org.eclipse.compare.contentmergeviewer.TextMergeViewer#getDocumentPartitioner()
75: */
76: protected IDocumentPartitioner getDocumentPartitioner() {
77: return new FastPartitioner(
78: new PropertiesFilePartitionScanner(),
79: IPropertiesFilePartitions.PARTITIONS);
80: }
81:
82: /*
83: * @see org.eclipse.compare.contentmergeviewer.TextMergeViewer#getDocumentPartitioning()
84: * @since 3.3
85: */
86: protected String getDocumentPartitioning() {
87: return IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING;
88: }
89:
90: /*
91: * @see org.eclipse.compare.contentmergeviewer.ContentMergeViewer#getTitle()
92: */
93: public String getTitle() {
94: return CompareMessages.PropertiesFileMergeViewer_title;
95: }
96: }
|