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.3 2006-10-21 23:13:53 pombredanne 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
32 * Implements ITextStore based on IDocument.
34 class TextStore implements ITextStore {
39 public void set(String txt) {
41 parent.replace(range.offset, range.length, txt);
42 } catch (BadLocationException x) {
47 * @see ITextStore#replace
49 public void replace(int offset, int length, String txt) {
51 parent.replace(range.offset + offset, length, txt);
52 } catch (BadLocationException x) {
57 * @see ITextStore#getLength
59 public int getLength() {
66 public String get(int offset, int length) {
68 return parent.get(range.offset + offset, length);
69 } catch (BadLocationException x) {
78 public char get(int offset) {
80 return parent.getChar(range.offset + offset);
81 } catch (BadLocationException x) {
88 /** The parent document */
91 /** The section inside the parent document */
95 * Constructs inner view to parent document.
101 public InnerDocumentView(IDocument parent, ViewNode range) {
102 this.parent = parent;
105 setTextStore(new TextStore());
106 setLineTracker(new DefaultLineTracker());
107 getTracker().set(getStore().get(0, getLength()));
108 completeInitialization();
112 * @see net.sourceforge.phpeclipse.text.rules.IDocumentView#getParentDocument()
114 public IDocument getParentDocument() {
119 * @see org.eclipse.jface.text.AbstractDocument#fireDocumentAboutToBeChanged(DocumentEvent)
121 protected void fireDocumentAboutToBeChanged(DocumentEvent event) {
122 super.fireDocumentAboutToBeChanged(event);
126 * @see org.eclipse.jface.text.AbstractDocument#fireDocumentChanged(DocumentEvent)
128 protected void fireDocumentChanged(DocumentEvent event) {
130 // TODO: move to a better place
131 getTracker().replace(event.getOffset(), event.getLength(),
133 } catch (BadLocationException x) {
136 super.fireDocumentChanged(event);
140 * @see net.sf.wdte.text.rules.IDocumentView#getParentOffset(int)
142 public int getParentOffset(int localOffset) {
143 return localOffset + range.offset;
147 * @see net.sf.wdte.text.rules.IDocumentView#getLocalOffset(int)
149 public int getLocalOffset(int parentOffset) {
150 return parentOffset - range.offset;