01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.editors.xml;
05:
06: import org.eclipse.core.runtime.IProgressMonitor;
07: import org.eclipse.jface.text.IDocument;
08: import org.eclipse.jface.text.ITextInputListener;
09: import org.eclipse.swt.custom.StyledText;
10: import org.eclipse.swt.graphics.Point;
11: import org.eclipse.swt.widgets.ScrollBar;
12: import org.eclipse.ui.editors.text.TextEditor;
13: import org.eclipse.ui.ide.IGotoMarker;
14:
15: public class XMLEditor extends TextEditor implements IGotoMarker {
16:
17: private ColorManager colorManager;
18:
19: public XMLEditor() {
20: super ();
21:
22: colorManager = new ColorManager();
23: setSourceViewerConfiguration(new XMLConfiguration(colorManager));
24: setDocumentProvider(new XMLDocumentProvider());
25: }
26:
27: public IDocument getDocument() {
28: return getDocumentProvider().getDocument(getEditorInput());
29: }
30:
31: public void addTextInputListener(ITextInputListener listener) {
32: getSourceViewer().addTextInputListener(listener);
33: }
34:
35: public void removeTextInputListener(ITextInputListener listener) {
36: getSourceViewer().removeTextInputListener(listener);
37: }
38:
39: public void dispose() {
40: colorManager.dispose();
41: super .dispose();
42: }
43:
44: public void doSave(IProgressMonitor progressMonitor) {
45: updateState(getEditorInput());
46: validateState(getEditorInput());
47: performSave(true, progressMonitor);
48: }
49:
50: public StyledText getTextWidget() {
51: return getSourceViewer().getTextWidget();
52: }
53:
54: public int getTopIndex() {
55: return getSourceViewer().getTopIndex();
56: }
57:
58: public void setTopIndex(int index) {
59: getSourceViewer().setTopIndex(index);
60: }
61:
62: public Point getScrollLocation() {
63: Point loc = new Point(0, 0);
64:
65: ScrollBar vertBar = getSourceViewer().getTextWidget()
66: .getVerticalBar();
67: ScrollBar horzBar = getSourceViewer().getTextWidget()
68: .getHorizontalBar();
69:
70: if (vertBar != null)
71: loc.y = vertBar.getSelection();
72: if (horzBar != null)
73: loc.x = horzBar.getSelection();
74:
75: return loc;
76: }
77:
78: public void setScrollLocation(Point loc) {
79: StyledText textWidget = getSourceViewer().getTextWidget();
80: ScrollBar vertBar = textWidget.getVerticalBar();
81: ScrollBar horzBar = textWidget.getHorizontalBar();
82:
83: if (vertBar != null)
84: vertBar.setSelection(loc.y);
85: if (horzBar != null)
86: horzBar.setSelection(loc.x);
87:
88: textWidget.layout(false);
89: textWidget.redraw();
90: }
91: }
|