Author: mes
Date: 2010-10-08 11:47:51 -0700 (Fri, 08 Oct 2010)
New Revision: 22192
Added:
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionAboutToBeSavedEvent.java
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionAboutToBeSavedListener.java
Removed:
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedEvent.java
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedListener.java
Modified:
core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java
core3/session-api/trunk/src/main/java/org/cytoscape/session/CySessionManager.java
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionLoadedEvent.java
Log:
modified events a bit
Modified:
core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java
===================================================================
--- core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java
2010-10-08 18:40:39 UTC (rev 22191)
+++ core3/session-api/trunk/src/main/java/org/cytoscape/session/CySession.java
2010-10-08 18:47:51 UTC (rev 22192)
@@ -120,6 +120,10 @@
cysession = b.cysession;
}
+ /**
+ * A implementation of the builder pattern used to construct immutable
+ * instances of CySession objects.
+ */
public static class Builder {
private Set<CyNetworkView> netViews;
Modified:
core3/session-api/trunk/src/main/java/org/cytoscape/session/CySessionManager.java
===================================================================
---
core3/session-api/trunk/src/main/java/org/cytoscape/session/CySessionManager.java
2010-10-08 18:40:39 UTC (rev 22191)
+++
core3/session-api/trunk/src/main/java/org/cytoscape/session/CySessionManager.java
2010-10-08 18:47:51 UTC (rev 22192)
@@ -10,18 +10,26 @@
*/
public interface CySessionManager {
- // TODO do we need this?
- enum State {
- NEW,
- OPENED,
- CHANGED,
- CLOSED,
- }
-
+ /**
+ * This method returns a CySession object describing the current
+ * state of Cytoscape. The object returned is meant to
+ * be used for serialization and is not meant to be used interactively
+ * to track the state of Cytsocape.
+ * @return An immutable CySession object.
+ */
CySession getCurrentSession();
-
+
+ /**
+ * This method allows a new session to be set and in doing
+ * so <b>erases and overrides the current session!</b>
+ * @param session The new session to be applied to Cytoscape.
+ * @param fileName The name of the file representing the new session.
+ */
void setCurrentSession(CySession session, String fileName);
+ /**
+ * @return The name of the current session file.
+ */
String getCurrentSessionFileName();
}
Copied:
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionAboutToBeSavedEvent.java
(from rev 22177,
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedEvent.java)
===================================================================
---
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionAboutToBeSavedEvent.java
(rev 0)
+++
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionAboutToBeSavedEvent.java
2010-10-08 18:47:51 UTC (rev 22192)
@@ -0,0 +1,64 @@
+
+package org.cytoscape.session;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.File;
+
+import org.cytoscape.event.AbstractCyEvent;
+
+/**
+ * This event is fired synchronously by the CySessionManager at beginning of
the
+ * {...@link CySessionManager#getCySession()} method. The intent is to allow
+ * listeners to provide information to this event object or to update their
+ * state before that state is interrogated by the CySessionManager.
+ */
+public final class SessionAboutToBeSavedEvent extends
AbstractCyEvent<CySessionManager> {
+ final Map<String,List<File>> pluginFileListMap;
+
+ // TODO should the source be the session manager
+ public SessionAboutToBeSavedEvent(final CySessionManager source) {
+ super(source, SessionAboutToBeSavedListener.class);
+
+ pluginFileListMap = new HashMap<String,List<File>>();
+ }
+
+ /**
+ * @param pluginName The name of the plugin that these files should be
stored for.
+ * @param files The list of File objects to be stored in the session
file.
+ */
+ public void addPluginFiles(final String pluginName, List<File> files)
throws Exception {
+ // Throw checked Exceptions here to force plugin authors to
deal with
+ // problems they might create.
+ if ( pluginName == null )
+ throw new Exception("plugin name is null");
+
+ if ( pluginName == "" )
+ throw new Exception("plugin name is empty");
+
+ if ( pluginFileListMap.containsKey( pluginName ) )
+ throw new Exception("The plugin file list already
contains a list of files identified by the name: " + pluginName);
+
+ if ( files == null )
+ throw new Exception("file list is null");
+
+ // allow empty lists
+
+ pluginFileListMap.put(pluginName, new ArrayList<File>(files));
+ }
+
+ /**
+ * This method is not meant to be used by listeners for this event,
+ * although you can and no harm should come to you.
+ * @return A map of plugin names to lists of files to be stored in the
+ * session for that plugin.
+ */
+ public Map<String,List<File>> getPluginFileListMap() {
+ // Make the return value immutable so that listeners
+ // can't mess with us.
+ return Collections.unmodifiableMap( pluginFileListMap );
+ }
+}
Copied:
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionAboutToBeSavedListener.java
(from rev 22177,
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedListener.java)
===================================================================
---
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionAboutToBeSavedListener.java
(rev 0)
+++
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionAboutToBeSavedListener.java
2010-10-08 18:47:51 UTC (rev 22192)
@@ -0,0 +1,18 @@
+
+package org.cytoscape.session;
+
+import org.cytoscape.event.CyListener;
+
+/**
+ * Any object that needs to know that a CySession is about to be
+ * created listen to this event. Additionally, plugins can set
+ * a list of files to be saved in the CySession using the
+ * appropriate method in the SessionAboutToBeSavedEvent.
+ */
+public interface SessionAboutToBeSavedListener extends CyListener {
+
+ /**
+ * @param e The event that the listener is listening for.
+ */
+ public void handleEvent(SessionAboutToBeSavedEvent e);
+}
Modified:
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionLoadedEvent.java
===================================================================
---
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionLoadedEvent.java
2010-10-08 18:40:39 UTC (rev 22191)
+++
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionLoadedEvent.java
2010-10-08 18:47:51 UTC (rev 22192)
@@ -4,10 +4,37 @@
import org.cytoscape.event.AbstractCyEvent;
/**
- *
+ * This event is fired after a new session has been set in the
+ * {...@link CySessionManager#setCurrentCySession(session,filename)}
+ * method and is used to notify interested parties in the change
+ * of state.
*/
public final class SessionLoadedEvent extends
AbstractCyEvent<CySessionManager> {
- public SessionLoadedEvent(final CySessionManager source) {
+
+ private final CySession session;
+ private final String fileName;
+
+ /**
+ * @param source The CySessionManager that is the source of this event.
+ * @param session The CySession object that was just loaded.
+ */
+ public SessionLoadedEvent(final CySessionManager source, CySession
session, String fileName) {
super(source,SessionLoadedListener.class);
+ this.session = session;
+ this.fileName = fileName;
}
+
+ /**
+ * @return The session that was just loaded.
+ */
+ public CySession getLoadedSession() {
+ return session;
+ }
+
+ /**
+ * @return The file name of the session just loaded.
+ */
+ public String getLoadedFileName() {
+ return fileName;
+ }
}
Deleted:
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedEvent.java
===================================================================
---
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedEvent.java
2010-10-08 18:40:39 UTC (rev 22191)
+++
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedEvent.java
2010-10-08 18:47:51 UTC (rev 22192)
@@ -1,13 +0,0 @@
-
-package org.cytoscape.session;
-
-import org.cytoscape.event.AbstractCyEvent;
-
-/**
- *
- */
-public final class SessionSavedEvent extends AbstractCyEvent<CySessionManager>
{
- public SessionSavedEvent(final CySessionManager source) {
- super(source, SessionSavedListener.class);
- }
-}
Deleted:
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedListener.java
===================================================================
---
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedListener.java
2010-10-08 18:40:39 UTC (rev 22191)
+++
core3/session-api/trunk/src/main/java/org/cytoscape/session/SessionSavedListener.java
2010-10-08 18:47:51 UTC (rev 22192)
@@ -1,11 +0,0 @@
-
-package org.cytoscape.session;
-
-import org.cytoscape.event.CyListener;
-
-/**
- *
- */
-public interface SessionSavedListener extends CyListener {
- public void handleEvent(SessionSavedEvent e);
-}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.