KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > SimpleTextViewer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.compare.internal;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16
17 import org.eclipse.jface.text.source.SourceViewer;
18 import org.eclipse.jface.text.Document;
19
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.compare.*;
22 import org.eclipse.compare.structuremergeviewer.ICompareInput;
23
24
25 public class SimpleTextViewer extends AbstractViewer {
26         
27     private SourceViewer fSourceViewer;
28     private ICompareInput fInput;
29     
30     
31     SimpleTextViewer(Composite parent) {
32         fSourceViewer= new SourceViewer(parent, null, SWT.H_SCROLL | SWT.V_SCROLL);
33         fSourceViewer.setEditable(false);
34     }
35         
36     public Control getControl() {
37         return fSourceViewer.getTextWidget();
38     }
39     
40     public void setInput(Object JavaDoc input) {
41         if (input instanceof IStreamContentAccessor) {
42             fSourceViewer.setDocument(new Document(getString(input)));
43         } else if (input instanceof ICompareInput) {
44             fInput= (ICompareInput) input;
45             ITypedElement left= fInput.getLeft();
46             fSourceViewer.setDocument(new Document(getString(left)));
47         }
48     }
49     
50     public Object JavaDoc getInput() {
51         return fInput;
52     }
53     
54     private String JavaDoc getString(Object JavaDoc input) {
55         
56         if (input instanceof IStreamContentAccessor) {
57             try {
58                 return Utilities.readString((IStreamContentAccessor) input);
59             } catch (CoreException ex) {
60                 // NeedWork
61
CompareUIPlugin.log(ex);
62             }
63         }
64         return ""; //$NON-NLS-1$
65
}
66 }
67
Popular Tags