use specialized subclasses of DocumentEvent for different events
Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/AttributeChangeEvent.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/AttributeChangeEvent.java
new file mode 100644
index 0000000..0395780
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/AttributeChangeEvent.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Florian Thienel 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:
+ * Florian Thienel - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.core.dom;
+
+import org.eclipse.core.runtime.QualifiedName;
+
+/**
+ * Notification about the change of an attribute.
+ *
+ * @author Florian Thienel
+ */
+public class AttributeChangeEvent extends DocumentEvent {
+
+ private static final long serialVersionUID = 1L;
+
+ private final QualifiedName attributeName;
+ private final String oldAttributeValue;
+ private final String newAttributeValue;
+
+ /**
+ * Create an event with attribute information.
+ *
+ * @param document
+ * Document that changed.
+ * @param parent
+ * Parent containing the attribute that changed
+ * @param attributeName
+ * name of the attribute that changed
+ * @param oldAttributeValue
+ * value of the attribute before the change.
+ * @param newAttributeValue
+ * value of the attribute after the change.
+ */
+ public AttributeChangeEvent(final IDocument document, final IParent parent, final QualifiedName attributeName, final String oldAttributeValue, final String newAttributeValue) {
+ super(document, parent);
+ this.attributeName = attributeName;
+ this.oldAttributeValue = oldAttributeValue;
+ this.newAttributeValue = newAttributeValue;
+ }
+
+ /**
+ * @return the value of the attribute before the change. If null, indicates that the attribute was removed
+ */
+ public String getNewAttributeValue() {
+ return newAttributeValue;
+ }
+
+ /**
+ * @return the value of the attribute after the change. If null, indicates the attribute did not exist before the
+ * change
+ */
+ public String getOldAttributeValue() {
+ return oldAttributeValue;
+ }
+
+ /**
+ * @return the qualified name of the attribute that was changed
+ */
+ public QualifiedName getAttributeName() {
+ return attributeName;
+ }
+
+}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/ContentChangeEvent.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/ContentChangeEvent.java
new file mode 100644
index 0000000..fd90917
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/ContentChangeEvent.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Florian Thienel 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:
+ * Florian Thienel - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.core.dom;
+
+/**
+ * Notification about a change of content: content was either inserted or deleted.
+ *
+ * @author Florian Thienel
+ */
+public class ContentChangeEvent extends DocumentEvent {
+
+ private static final long serialVersionUID = 1L;
+
+ private final ContentRange range;
+
+ /**
+ * Create an event.
+ *
+ * @param document
+ * the document that changed
+ * @param parent
+ * the parent node containing the change
+ * @param range
+ * the range which was changed
+ */
+ public ContentChangeEvent(final IDocument document, final IParent parent, final ContentRange range) {
+ super(document, parent);
+
+ this.range = range;
+ }
+
+ /**
+ * @return the range which was changed
+ */
+ public ContentRange getRange() {
+ return range;
+ }
+
+}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/DocumentEvent.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/DocumentEvent.java
index 309d2a3..d4f238a 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/DocumentEvent.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/DocumentEvent.java
@@ -13,21 +13,15 @@
import java.util.EventObject;
-import org.eclipse.core.runtime.QualifiedName;
-
/**
- * Encapsulation of the details of a document change.
+ * This is the base class for notifications about a document change.
*/
-public class DocumentEvent extends EventObject {
+public abstract class DocumentEvent extends EventObject {
private static final long serialVersionUID = -9028980559838712720L;
private final IDocument document;
private final IParent parent;
- private final ContentRange range;
- private final QualifiedName attributeName;
- private final String oldAttributeValue;
- private final String newAttributeValue;
/**
* Create an event.
@@ -36,48 +30,11 @@
* the document that changed
* @param parent
* the parent node containing the change
- * @param range
- * the range which was changed
*/
- public DocumentEvent(final IDocument document, final IParent parent, final ContentRange range) {
+ public DocumentEvent(final IDocument document, final IParent parent) {
super(document);
this.document = document;
this.parent = parent;
- this.range = range;
- attributeName = null;
- oldAttributeValue = null;
- newAttributeValue = null;
- }
-
- /**
- * Create an event with attribute information.
- *
- * @param document
- * Document that changed.
- * @param parent
- * Parent containing the attribute that changed
- * @param attributeName
- * name of the attribute that changed
- * @param oldAttributeValue
- * value of the attribute before the change.
- * @param newAttributeValue
- * value of the attribute after the change.
- */
- public DocumentEvent(final IDocument document, final IParent parent, final QualifiedName attributeName, final String oldAttributeValue, final String newAttributeValue) {
- super(document);
- this.document = document;
- this.parent = parent;
- range = parent.getRange();
- this.attributeName = attributeName;
- this.oldAttributeValue = oldAttributeValue;
- this.newAttributeValue = newAttributeValue;
- }
-
- /**
- * @return the range which was changed
- */
- public ContentRange getRange() {
- return range;
}
/**
@@ -88,28 +45,6 @@
}
/**
- * @return the value of the attribute before the change. If null, indicates that the attribute was removed
- */
- public String getNewAttributeValue() {
- return newAttributeValue;
- }
-
- /**
- * @return the value of the attribute after the change. If null, indicates the attribute did not exist before the
- * change
- */
- public String getOldAttributeValue() {
- return oldAttributeValue;
- }
-
- /**
- * @return the qualified name of the attribute that was changed
- */
- public QualifiedName getAttributeName() {
- return attributeName;
- }
-
- /**
* @return the document for which this event was generated
*/
public IDocument getDocument() {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/IDocumentListener.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/IDocumentListener.java
index 65ff63b..a03bb1f 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/IDocumentListener.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/IDocumentListener.java
@@ -22,7 +22,7 @@
* @param event
* the document event.
*/
- void attributeChanged(DocumentEvent event);
+ void attributeChanged(AttributeChangeEvent event);
/**
* Called when a namespace delcaration is changed in one of the document's elements.
@@ -30,7 +30,7 @@
* @param event
* the document event.
*/
- void namespaceChanged(DocumentEvent event);
+ void namespaceChanged(NamespaceDeclarationChangeEvent event);
/**
* Called before content is deleted from a document.
@@ -38,7 +38,7 @@
* @param event
* the document event
*/
- void beforeContentDeleted(DocumentEvent event);
+ void beforeContentDeleted(ContentChangeEvent event);
/**
* Called before content is inserted into a document.
@@ -46,7 +46,7 @@
* @param event
* the document event
*/
- void beforeContentInserted(DocumentEvent event);
+ void beforeContentInserted(ContentChangeEvent event);
/**
* Called when content is deleted from a document.
@@ -54,7 +54,7 @@
* @param event
* the document event
*/
- void contentDeleted(DocumentEvent event);
+ void contentDeleted(ContentChangeEvent event);
/**
* Called when content is inserted into a document.
@@ -62,6 +62,6 @@
* @param event
* the document event
*/
- void contentInserted(DocumentEvent event);
+ void contentInserted(ContentChangeEvent event);
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/NamespaceDeclarationChangeEvent.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/NamespaceDeclarationChangeEvent.java
new file mode 100644
index 0000000..da10218
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/dom/NamespaceDeclarationChangeEvent.java
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Florian Thienel 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:
+ * Florian Thienel - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.core.dom;
+
+/**
+ * Notification about a change of the namespace delclarations of an element.
+ *
+ * @author Florian Thienel
+ */
+public class NamespaceDeclarationChangeEvent extends DocumentEvent {
+
+ private static final long serialVersionUID = 1L;
+
+ public NamespaceDeclarationChangeEvent(final IDocument document, final IParent parent) {
+ super(document, parent);
+ }
+
+}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
index 63a6603..d62aa25 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Document.java
@@ -19,6 +19,7 @@
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.vex.core.dom.BaseNodeVisitorWithResult;
+import org.eclipse.vex.core.dom.ContentChangeEvent;
import org.eclipse.vex.core.dom.ContentRange;
import org.eclipse.vex.core.dom.DocumentEvent;
import org.eclipse.vex.core.dom.DocumentValidationException;
@@ -244,21 +245,21 @@
throw new DocumentValidationException(MessageFormat.format("Cannot insert text ''{0}'' at offset {1}.", text, offset));
}
- fireBeforeContentInserted(new DocumentEvent(Document.this, element, new ContentRange(offset, offset + adjustedText.length() - 1)));
+ fireBeforeContentInserted(new ContentChangeEvent(Document.this, element, new ContentRange(offset, offset + adjustedText.length() - 1)));
getContent().insertText(offset, adjustedText);
- fireContentInserted(new DocumentEvent(Document.this, element, new ContentRange(offset, offset + adjustedText.length() - 1)));
+ fireContentInserted(new ContentChangeEvent(Document.this, element, new ContentRange(offset, offset + adjustedText.length() - 1)));
}
public void visit(final IText text) {
- fireBeforeContentInserted(new DocumentEvent(Document.this, text.getParent(), new ContentRange(offset, offset + adjustedText.length() - 1)));
+ fireBeforeContentInserted(new ContentChangeEvent(Document.this, text.getParent(), new ContentRange(offset, offset + adjustedText.length() - 1)));
getContent().insertText(offset, adjustedText);
- fireContentInserted(new DocumentEvent(Document.this, text.getParent(), new ContentRange(offset, offset + adjustedText.length() - 1)));
+ fireContentInserted(new ContentChangeEvent(Document.this, text.getParent(), new ContentRange(offset, offset + adjustedText.length() - 1)));
}
public void visit(final IComment comment) {
- fireBeforeContentInserted(new DocumentEvent(Document.this, comment.getParent(), new ContentRange(offset, offset + adjustedText.length() - 1)));
+ fireBeforeContentInserted(new ContentChangeEvent(Document.this, comment.getParent(), new ContentRange(offset, offset + adjustedText.length() - 1)));
getContent().insertText(offset, adjustedText);
- fireContentInserted(new DocumentEvent(Document.this, comment.getParent(), new ContentRange(offset, offset + adjustedText.length() - 1)));
+ fireContentInserted(new ContentChangeEvent(Document.this, comment.getParent(), new ContentRange(offset, offset + adjustedText.length() - 1)));
}
});
}
@@ -291,7 +292,7 @@
final Parent parent = getParentForInsertionAt(offset);
- fireBeforeContentInserted(new DocumentEvent(this, parent, new ContentRange(offset, offset + 1)));
+ fireBeforeContentInserted(new ContentChangeEvent(this, parent, new ContentRange(offset, offset + 1)));
final Comment comment = new Comment();
getContent().insertTagMarker(offset);
@@ -300,7 +301,7 @@
parent.insertChildAt(offset, comment);
- fireContentInserted(new DocumentEvent(this, parent, comment.getRange()));
+ fireContentInserted(new ContentChangeEvent(this, parent, comment.getRange()));
return comment;
}
@@ -318,7 +319,7 @@
throw new DocumentValidationException(MessageFormat.format("Cannot insert element {0} at offset {1}.", elementName, offset));
}
- fireBeforeContentInserted(new DocumentEvent(this, parent, new ContentRange(offset, offset + 1)));
+ fireBeforeContentInserted(new ContentChangeEvent(this, parent, new ContentRange(offset, offset + 1)));
final Element element = new Element(elementName);
getContent().insertTagMarker(offset);
@@ -327,7 +328,7 @@
parent.insertChildAt(offset, element);
- fireContentInserted(new DocumentEvent(this, parent, element.getRange()));
+ fireContentInserted(new ContentChangeEvent(this, parent, element.getRange()));
return element;
}
@@ -344,7 +345,7 @@
throw new DocumentValidationException(MessageFormat.format("Cannot insert document fragment at offset {0}.", offset));
}
- fireBeforeContentInserted(new DocumentEvent(this, parent, new ContentRange(offset, offset + 1)));
+ fireBeforeContentInserted(new ContentChangeEvent(this, parent, new ContentRange(offset, offset + 1)));
getContent().insertContent(offset, fragment.getContent());
@@ -357,7 +358,7 @@
nextOffset = newNode.getEndOffset() + 1;
}
- fireContentInserted(new DocumentEvent(this, parent, new ContentRange(offset, offset + fragment.getContent().length() - 1)));
+ fireContentInserted(new ContentChangeEvent(this, parent, new ContentRange(offset, offset + fragment.getContent().length() - 1)));
}
private void associateDeeply(final Node node, final int offset) {
@@ -406,7 +407,7 @@
throw new DocumentValidationException(MessageFormat.format("Cannot delete {0}", range));
}
- fireBeforeContentDeleted(new DocumentEvent(this, parentForDeletion, range));
+ fireBeforeContentDeleted(new ContentChangeEvent(this, parentForDeletion, range));
for (final INode child : parentForDeletion.children().in(range)) {
parentForDeletion.removeChild((Node) child);
@@ -415,7 +416,7 @@
getContent().remove(range);
- fireContentDeleted(new DocumentEvent(this, parentForDeletion, range));
+ fireContentDeleted(new ContentChangeEvent(this, parentForDeletion, range));
}
/*
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java
index 8da5e15..032755c 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/dom/Element.java
@@ -21,8 +21,7 @@
import java.util.Map.Entry;
import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.vex.core.dom.ContentRange;
-import org.eclipse.vex.core.dom.DocumentEvent;
+import org.eclipse.vex.core.dom.AttributeChangeEvent;
import org.eclipse.vex.core.dom.DocumentValidationException;
import org.eclipse.vex.core.dom.Filters;
import org.eclipse.vex.core.dom.IAttribute;
@@ -31,6 +30,7 @@
import org.eclipse.vex.core.dom.INode;
import org.eclipse.vex.core.dom.INodeVisitor;
import org.eclipse.vex.core.dom.INodeVisitorWithResult;
+import org.eclipse.vex.core.dom.NamespaceDeclarationChangeEvent;
import org.eclipse.vex.core.internal.core.QualifiedNameComparator;
public class Element extends Parent implements IElement {
@@ -160,7 +160,7 @@
return;
}
- document.fireAttributeChanged(new DocumentEvent(document, this, name, oldValue, newValue));
+ document.fireAttributeChanged(new AttributeChangeEvent(document, this, name, oldValue, newValue));
}
public void setAttribute(final String localName, final String value) throws DocumentValidationException {
@@ -189,7 +189,7 @@
return;
}
- document.fireAttributeChanged(new DocumentEvent(document, this, name, oldValue, value));
+ document.fireAttributeChanged(new AttributeChangeEvent(document, this, name, oldValue, value));
}
}
}
@@ -310,7 +310,7 @@
return;
}
- document.fireNamespaceChanged(new DocumentEvent(document, this, new ContentRange(getStartOffset(), getStartOffset())));
+ document.fireNamespaceChanged(new NamespaceDeclarationChangeEvent(document, this));
}
public void removeNamespace(final String namespacePrefix) {
@@ -324,7 +324,7 @@
return; // we have actually removed nothing, so we should not tell anybody about it
}
- document.fireNamespaceChanged(new DocumentEvent(document, this, new ContentRange(getStartOffset(), getStartOffset())));
+ document.fireNamespaceChanged(new NamespaceDeclarationChangeEvent(document, this));
}
public void declareDefaultNamespace(final String namespaceURI) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
index b15bdf9..cbc11dc 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/widget/VexWidgetImpl.java
@@ -26,9 +26,10 @@
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.vex.core.dom.AttributeChangeEvent;
import org.eclipse.vex.core.dom.BaseNodeVisitorWithResult;
+import org.eclipse.vex.core.dom.ContentChangeEvent;
import org.eclipse.vex.core.dom.ContentRange;
-import org.eclipse.vex.core.dom.DocumentEvent;
import org.eclipse.vex.core.dom.DocumentValidationException;
import org.eclipse.vex.core.dom.IComment;
import org.eclipse.vex.core.dom.IDocument;
@@ -39,6 +40,7 @@
import org.eclipse.vex.core.dom.IPosition;
import org.eclipse.vex.core.dom.IText;
import org.eclipse.vex.core.dom.IValidator;
+import org.eclipse.vex.core.dom.NamespaceDeclarationChangeEvent;
import org.eclipse.vex.core.internal.core.Caret;
import org.eclipse.vex.core.internal.core.Color;
import org.eclipse.vex.core.internal.core.ElementName;
@@ -134,7 +136,7 @@
private final IDocumentListener documentListener = new IDocumentListener() {
- public void attributeChanged(final DocumentEvent e) {
+ public void attributeChanged(final AttributeChangeEvent e) {
invalidateElementBox(e.getParent());
/*
@@ -151,13 +153,13 @@
hostComponent.fireSelectionChanged();
}
- public void beforeContentDeleted(final DocumentEvent e) {
+ public void beforeContentDeleted(final ContentChangeEvent e) {
}
- public void beforeContentInserted(final DocumentEvent e) {
+ public void beforeContentInserted(final ContentChangeEvent e) {
}
- public void contentDeleted(final DocumentEvent e) {
+ public void contentDeleted(final ContentChangeEvent e) {
invalidateElementBox(e.getParent());
if (beginWorkCount == 0) {
@@ -165,7 +167,7 @@
}
}
- public void contentInserted(final DocumentEvent e) {
+ public void contentInserted(final ContentChangeEvent e) {
invalidateElementBox(e.getParent());
if (beginWorkCount == 0) {
@@ -173,7 +175,7 @@
}
}
- public void namespaceChanged(final DocumentEvent e) {
+ public void namespaceChanged(final NamespaceDeclarationChangeEvent e) {
invalidateElementBox(e.getParent());
if (beginWorkCount == 0) {
diff --git a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
index 1b7380d..8014a0c 100644
--- a/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
+++ b/org.eclipse.vex.ui/src/org/eclipse/vex/ui/internal/editor/VexEditor.java
@@ -68,11 +68,13 @@
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.IPropertySourceProvider;
import org.eclipse.ui.views.properties.PropertySheetPage;
-import org.eclipse.vex.core.dom.DocumentEvent;
+import org.eclipse.vex.core.dom.AttributeChangeEvent;
+import org.eclipse.vex.core.dom.ContentChangeEvent;
import org.eclipse.vex.core.dom.IDocument;
import org.eclipse.vex.core.dom.IDocumentListener;
import org.eclipse.vex.core.dom.IElement;
import org.eclipse.vex.core.dom.IValidator;
+import org.eclipse.vex.core.dom.NamespaceDeclarationChangeEvent;
import org.eclipse.vex.core.internal.core.ListenerList;
import org.eclipse.vex.core.internal.io.DocumentReader;
import org.eclipse.vex.core.internal.io.DocumentWriter;
@@ -720,29 +722,29 @@
private final IDocumentListener documentListener = new IDocumentListener() {
- public void attributeChanged(final DocumentEvent e) {
+ public void attributeChanged(final AttributeChangeEvent e) {
setDirty();
}
- public void namespaceChanged(final DocumentEvent e) {
+ public void namespaceChanged(final NamespaceDeclarationChangeEvent e) {
setDirty();
}
- public void beforeContentDeleted(final DocumentEvent e) {
+ public void beforeContentDeleted(final ContentChangeEvent e) {
// TODO Auto-generated method stub
}
- public void beforeContentInserted(final DocumentEvent e) {
+ public void beforeContentInserted(final ContentChangeEvent e) {
// TODO Auto-generated method stub
}
- public void contentDeleted(final DocumentEvent e) {
+ public void contentDeleted(final ContentChangeEvent e) {
setDirty();
}
- public void contentInserted(final DocumentEvent e) {
+ public void contentInserted(final ContentChangeEvent e) {
setDirty();
}