| /******************************************************************************* |
| * Copyright (c) 2001, 2004 IBM Corporation and others. |
| * 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: |
| * IBM Corporation - initial API and implementation |
| * Jens Lukowski/Innoopract - initial renaming/restructuring |
| * |
| *******************************************************************************/ |
| package org.eclipse.wst.sse.core.events; |
| |
| import org.eclipse.jface.text.DocumentEvent; |
| import org.eclipse.jface.text.IDocument; |
| import org.eclipse.wst.sse.core.text.IStructuredDocument; |
| |
| |
| /** |
| * IStructuredDocument events are generated by the IStructuredDocument, after |
| * the IStructuredDocument acts on a request. |
| */ |
| public abstract class StructuredDocumentEvent extends DocumentEvent { |
| protected String fDeletedText; |
| protected Object fOriginalRequester; |
| |
| public IStructuredDocument fStructuredDocument; |
| |
| //public int fOffset; |
| //public int fLength; |
| //public String fText; |
| /** |
| * We assume that IStructuredDocument's are ALWAYS the source of |
| * IStructuredDocument events |
| */ |
| protected StructuredDocumentEvent(IStructuredDocument source) { |
| super(); |
| if (source == null) |
| throw new IllegalArgumentException("null source"); //$NON-NLS-1$ |
| fDocument = source; |
| fStructuredDocument = source; |
| } |
| |
| protected StructuredDocumentEvent(IStructuredDocument source, Object originalSource) { |
| this(source); |
| fOriginalRequester = originalSource; |
| } |
| |
| protected StructuredDocumentEvent(IStructuredDocument source, Object originalSource, String changes, int offset, int lengthToReplace) { |
| this(source); |
| fOriginalRequester = originalSource; |
| fText = changes; |
| fOffset = offset; |
| fLength = lengthToReplace; |
| } |
| |
| /** |
| * @return java.lang.String |
| */ |
| public java.lang.String getDeletedText() { |
| return fDeletedText; |
| } |
| |
| public IDocument getDocument() { |
| |
| return fStructuredDocument; |
| } |
| |
| public int getLength() { |
| |
| return fLength; |
| } |
| |
| public int getOffset() { |
| |
| return getOriginalStart(); |
| } |
| |
| /** |
| * This method returns the object that originally caused the event to |
| * fire. This is typically not the object that created the event (the |
| * IStructuredDocument) but instead the object object that made a request |
| * to the IStructuredDocument. |
| * |
| * @return java.lang.Object |
| */ |
| public java.lang.Object getOriginalSource() { |
| return fOriginalRequester; |
| } |
| |
| public int getOriginalStart() { |
| return fOffset; |
| } |
| |
| /** |
| * This method is equivalent to 'getSource' except it returns an object of |
| * the appropriate type (namely, a IStructuredDocument, instead of |
| * Object). |
| */ |
| public IStructuredDocument getStructuredDocument() { |
| // a safe case, since constructor can only be called with a |
| // IStructuredDocument |
| return fStructuredDocument; |
| } |
| |
| public String getText() { |
| |
| return fText; |
| } |
| |
| /** |
| * @param newDeletedText |
| * java.lang.String |
| */ |
| public void setDeletedText(java.lang.String newDeletedText) { |
| fDeletedText = newDeletedText; |
| } |
| |
| /** |
| * returns the classname, but not the 'source=' (as super does). |
| */ |
| public String toString() { |
| //return getClass().getName() + "[source=" + source + "]"; |
| return getClass().getName(); |
| } |
| } |