Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9ca69d55da17910955789abf1d8e06ccb936eaeb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
 * Copyright (c) 2009 Red Hat, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Red Hat - initial API and implementation
 *******************************************************************************/
package org.eclipse.linuxtools.internal.rpm.ui.editor.compare;

import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.contentmergeviewer.TextMergeViewer;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.linuxtools.internal.rpm.ui.editor.ColorManager;
import org.eclipse.linuxtools.internal.rpm.ui.editor.SpecfileConfiguration;
import org.eclipse.linuxtools.internal.rpm.ui.editor.scanners.SpecfilePartitionScanner;
import org.eclipse.linuxtools.rpm.ui.editor.SpecfileEditor;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.widgets.Composite;

/**
 * Merge viewer for the files.
 *
 */
public class SpecMergeViewer extends TextMergeViewer {
	private ColorManager colorManager;

	/**
	 * Creates a new SpecMergeViewer.
	 *
	 * @param parent The parent control.
	 * @param configuration The compare configuration.
	 *
	 * @see TextMergeViewer#TextMergeViewer(Composite, CompareConfiguration)
	 */
	public SpecMergeViewer(Composite parent, CompareConfiguration configuration) {
		super(parent, configuration);
	}

	@Override
	public String getTitle() {
		return Messages.SpecMergeViewer_0;
	}

	@Override
	protected IDocumentPartitioner getDocumentPartitioner() {
		return new FastPartitioner(new SpecfilePartitionScanner(),
				SpecfilePartitionScanner.SPEC_PARTITION_TYPES);
	}

	@Override
	protected void configureTextViewer(TextViewer textViewer) {
		if (textViewer instanceof SourceViewer) {
			this.colorManager = new ColorManager();
			SpecfileEditor editor = new SpecfileEditor();
			((SourceViewer) textViewer).configure(new SpecfileConfiguration(
					colorManager, editor));
		}
	}

	/**
	 * Dispose the color manager and invoke the super method.
	 *
	 * @see org.eclipse.compare.contentmergeviewer.TextMergeViewer#handleDispose(org.eclipse.swt.events.DisposeEvent)
	 */
	@Override
	protected void handleDispose(DisposeEvent event) {
		if (colorManager != null) {
			colorManager.dispose();
		}
		super.handleDispose(event);
	}
}

Back to the top