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://solareclipse.sourceforge.net/legal/cpl-v10.html
9 * Igor Malinin - initial contribution
11 * $Id: InnerDocumentView.java,v 1.2 2004-09-22 18:51:51 jsurfer Exp $
14 package net.sourceforge.phpeclipse.ui.text.rules;
16 import org.eclipse.jface.text.AbstractDocument;
17 import org.eclipse.jface.text.BadLocationException;
18 import org.eclipse.jface.text.DefaultLineTracker;
19 import org.eclipse.jface.text.DocumentEvent;
20 import org.eclipse.jface.text.IDocument;
21 import org.eclipse.jface.text.ITextStore;
24 * Inner view to parent document.
26 * @author Igor Malinin
28 public class InnerDocumentView extends AbstractDocument implements IDocumentView {
31 * Implements ITextStore based on IDocument.
33 class TextStore implements ITextStore {
38 public void set(String txt) {
40 parent.replace(range.offset, range.length, txt);
41 } catch (BadLocationException x) {
46 * @see ITextStore#replace
48 public void replace(int offset, int length, String txt) {
50 parent.replace(range.offset + offset, length, txt);
51 } catch (BadLocationException x) {
56 * @see ITextStore#getLength
58 public int getLength() {
65 public String get(int offset, int length) {
67 return parent.get(range.offset + offset, length);
68 } catch (BadLocationException x) {
77 public char get(int offset) {
79 return parent.getChar(range.offset + offset);
80 } catch (BadLocationException x) {
87 /** The parent document */
90 /** The section inside the parent document */
94 * Constructs inner view to parent document.
100 public InnerDocumentView(IDocument parent, ViewNode range) {
101 this.parent = parent;
104 setTextStore(new TextStore());
105 setLineTracker(new DefaultLineTracker());
106 getTracker().set(getStore().get(0, getLength()));
107 completeInitialization();
111 * @see net.sourceforge.phpeclipse.text.rules.IDocumentView#getParentDocument()
113 public IDocument getParentDocument() {
118 * @see org.eclipse.jface.text.AbstractDocument#fireDocumentAboutToBeChanged(DocumentEvent)
120 protected void fireDocumentAboutToBeChanged(DocumentEvent event) {
121 super.fireDocumentAboutToBeChanged(event);
125 * @see org.eclipse.jface.text.AbstractDocument#fireDocumentChanged(DocumentEvent)
127 protected void fireDocumentChanged(DocumentEvent event) {
129 // TODO: move to a better place
130 getTracker().replace(event.getOffset(), event.getLength(), event.getText());
131 } catch (BadLocationException x) {
134 super.fireDocumentChanged(event);
138 * @see net.sf.wdte.text.rules.IDocumentView#getParentOffset(int)
140 public int getParentOffset(int localOffset) {
141 return localOffset + range.offset;
145 * @see net.sf.wdte.text.rules.IDocumentView#getLocalOffset(int)
147 public int getLocalOffset(int parentOffset) {
148 return parentOffset - range.offset;