summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Trimble2013-01-15 17:22:04 (EST)
committerIan Trimble2013-01-15 17:22:04 (EST)
commite9a523a9b0e0cc389ddebccfd84f3e99a08be23e (patch)
tree6b279b2cf20bbefd53a23f4f8a8a509a48e3d165
parent21da628da908a9ab241764cfc8f348848e971ec6 (diff)
downloadwebtools.jsf-e9a523a9b0e0cc389ddebccfd84f3e99a08be23e.zip
webtools.jsf-e9a523a9b0e0cc389ddebccfd84f3e99a08be23e.tar.gz
webtools.jsf-e9a523a9b0e0cc389ddebccfd84f3e99a08be23e.tar.bz2
[WPE] Need ability to listen for updates to a file in an open editor.
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java72
-rw-r--r--jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/IWPEPersistenceListener.java52
2 files changed, 123 insertions, 1 deletions
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java
index 143c156..2756820 100644
--- a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/HTMLEditor.java
@@ -43,6 +43,8 @@ import org.eclipse.jst.jsf.common.ui.internal.utils.ResourceUtils;
import org.eclipse.jst.pagedesigner.IJMTConstants;
import org.eclipse.jst.pagedesigner.PDPlugin;
import org.eclipse.jst.pagedesigner.dnd.internal.DesignerSourceMouseTrackAdapter;
+import org.eclipse.jst.pagedesigner.editors.IWPEPersistenceListener.IPersistenceEvent;
+import org.eclipse.jst.pagedesigner.editors.IWPEPersistenceListener.PersistenceEventType;
import org.eclipse.jst.pagedesigner.editors.actions.DesignPageActionContributor;
import org.eclipse.jst.pagedesigner.editors.pagedesigner.PageDesignerResources;
import org.eclipse.jst.pagedesigner.jsp.core.pagevar.IPageVariablesProvider;
@@ -175,6 +177,8 @@ public final class HTMLEditor extends MultiPageEditorPart implements
// }
// }
+ private List<IWPEPersistenceListener> persistenceListeners;
+
/**
* Default constructor
*/
@@ -476,7 +480,13 @@ public final class HTMLEditor extends MultiPageEditorPart implements
* @return StructuredTextEditor
*/
protected StructuredTextEditor createTextEditor() {
- return new DesignerStructuredTextEditorJSP();
+ return new DesignerStructuredTextEditorJSP() {
+ @Override
+ protected void performRevert() {
+ super.performRevert();
+ firePersistenceEvent(PersistenceEventType.REVERTED);
+ }
+ };
}
private void disconnectDesignPage() {
@@ -524,12 +534,18 @@ public final class HTMLEditor extends MultiPageEditorPart implements
_model = null;
}
+ if (persistenceListeners != null) {
+ persistenceListeners.clear();
+ persistenceListeners = null;
+ }
+
super.dispose();
}
public void doSave(IProgressMonitor monitor) {
_textEditor.doSave(monitor);
+ firePersistenceEvent(PersistenceEventType.SAVED);
}
/*
@@ -542,6 +558,7 @@ public final class HTMLEditor extends MultiPageEditorPart implements
*/
public void doSaveAs() {
_textEditor.doSaveAs();
+ firePersistenceEvent(PersistenceEventType.SAVED_AS);
}
private void editorInputIsAcceptable(IEditorInput input)
@@ -1228,4 +1245,57 @@ public final class HTMLEditor extends MultiPageEditorPart implements
}
}
+ /**
+ * Adds a {@link IWPEPersistenceListener persistence listener} to this editor.
+ *
+ * <p>This type of listener is cleaned when the editor is disposed.</p>
+ *
+ * @param listener
+ */
+ public void addPersistenceListener(IWPEPersistenceListener listener) {
+ if (persistenceListeners == null) {
+ persistenceListeners = new ArrayList<IWPEPersistenceListener>(5);
+ }
+ persistenceListeners.add(listener);
+ }
+
+ /**
+ * Removes a {@link IWPEPersistenceListener persistence listener} added to this
+ * editor.
+ *
+ * <p>This type of listener is cleaned when the editor is disposed.</p>
+ *
+ * @param listener
+ */
+ public void removePersistenceListener(IWPEPersistenceListener listener) {
+ if (persistenceListeners != null) {
+ if (persistenceListeners.remove(listener) && persistenceListeners.isEmpty()) {
+ persistenceListeners = null;
+ }
+ }
+ }
+
+ private void firePersistenceEvent(final PersistenceEventType type) {
+ if (persistenceListeners != null) {
+ List<IWPEPersistenceListener> listeners = new ArrayList<IWPEPersistenceListener>(persistenceListeners);
+ IPersistenceEvent event = new IPersistenceEvent() {
+ public HTMLEditor getWPEInstance() {
+ return HTMLEditor.this;
+ }
+
+ public PersistenceEventType getEventType() {
+ return type;
+ }
+ };
+
+ for (IWPEPersistenceListener listener : listeners) {
+ try {
+ listener.notify(event);
+ } catch (Exception e) {
+ PDPlugin.log("Exception thrown while notifying a persistence listener", e); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
}
diff --git a/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/IWPEPersistenceListener.java b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/IWPEPersistenceListener.java
new file mode 100644
index 0000000..af319bc
--- /dev/null
+++ b/jsf/plugins/org.eclipse.jst.pagedesigner/src/org/eclipse/jst/pagedesigner/editors/IWPEPersistenceListener.java
@@ -0,0 +1,52 @@
+package org.eclipse.jst.pagedesigner.editors;
+
+/**
+ * Listens for persistence events fired from WPE instances, including
+ * save and revert.
+ */
+public interface IWPEPersistenceListener {
+ /**
+ * The type of the persistence event.
+ *
+ */
+ public static enum PersistenceEventType {
+ /**
+ * WPE was saved
+ */
+ SAVED,
+
+ /**
+ * WPE was saved as
+ */
+ SAVED_AS,
+
+ /**
+ * WPE was reverted.
+ */
+ REVERTED;
+ }
+
+ /**
+ * A persistence event.
+ *
+ * <p>Not intended to be implemented by clients.</p>
+ */
+ public static interface IPersistenceEvent {
+ /**
+ * @return editor
+ */
+ public HTMLEditor getWPEInstance();
+
+ /**
+ * @return EventType
+ */
+ public PersistenceEventType getEventType();
+ }
+
+ /**
+ * A persistence event has occurred
+ * @param event
+ */
+ public void notify(IPersistenceEvent event);
+
+}