提交 c55ea04e 编写于 作者: M Mathieu Bastian 提交者: Mathieu Bastian

Replace ChangeListener by PropertyChangeListener in ProjectInformation and...

Replace ChangeListener by PropertyChangeListener in ProjectInformation and WorkspaceInformation. Also improve documentation in ProjectAPI.
上级 5888438c
...@@ -87,8 +87,6 @@ public interface ProjectController { ...@@ -87,8 +87,6 @@ public interface ProjectController {
public void closeCurrentWorkspace(); public void closeCurrentWorkspace();
public void cleanWorkspace(Workspace workspace);
public Workspace duplicateWorkspace(Workspace workspace); public Workspace duplicateWorkspace(Workspace workspace);
public void setSource(Workspace workspace, String source); public void setSource(Workspace workspace, String source);
......
...@@ -38,37 +38,113 @@ made subject to such option by the copyright holder. ...@@ -38,37 +38,113 @@ made subject to such option by the copyright holder.
Contributor(s): Contributor(s):
Portions Copyrighted 2011 Gephi Consortium. Portions Copyrighted 2011 Gephi Consortium.
*/ */
package org.gephi.project.api; package org.gephi.project.api;
import java.beans.PropertyChangeListener;
import java.io.File; import java.io.File;
import javax.swing.event.ChangeListener;
/** /**
* Hosts various information about a project the module is maintaining. * Hosts various information about a project.
* <p>
* Clients can subscribe to changes by using the
* {@link #addChangeListener(java.beans.PropertyChangeListener) } method. It
* triggers the following events:
* <ul>
* <li><b>EVENT_OPEN:</b> Project opened
* <li><b>EVENT_CLOSE:</b> Project closed
* <li><b>EVENT_RENAME:</b> Project renamed
* <li><b>EVENT_SET_FILE:</b> Project file set
* </ul>
* *
* @author Mathieu Bastian * @author Mathieu Bastian
* @see Project * @see Project
*/ */
public interface ProjectInformation { public interface ProjectInformation {
public static final String EVENT_OPEN = "open";
public static final String EVENT_CLOSE = "close";
public static final String EVENT_RENAME = "rename";
public static final String EVENT_SET_FILE = "setFile";
/**
* Returns true if the project is open.
*
* @return true if open, false otherwise
*/
public boolean isOpen(); public boolean isOpen();
/**
* Returns true if the project is closed.
*
* @return true if closed, false otherwise
*/
public boolean isClosed(); public boolean isClosed();
/**
* Returns true if the project is invalid.
*
* @return true if invalid, false otherwise
*/
public boolean isInvalid(); public boolean isInvalid();
/**
* Returns the name of the project.
* <p>
* The name can't be null and has a default value (e.g. Project 1).
*
* @return the project's name
*/
public String getName(); public String getName();
/**
* Returns true if the project is associated with a file.
* <p>
* A project is associated with a file if it has been saved/loaded to/from a
* file.
*
* @return true if associated with a file, false otherwise
*/
public boolean hasFile(); public boolean hasFile();
/**
* Returns the filename associated with this project.
* <p>
* Returns an empty string if the project isn't associated with a file.
*
* @see #hasFile()
* @return file name
*/
public String getFileName(); public String getFileName();
/**
* Returns the file associated with this project.
* <p>
* Returns null if the project isn't associated with a file.
*
* @see #hasFile()
* @return file or null if none
*/
public File getFile(); public File getFile();
/**
* Returns the project this information class belongs to.
*
* @return project reference
*/
public Project getProject(); public Project getProject();
public void addChangeListener(ChangeListener listener); /**
* Add change listener.
public void removeChangeListener(ChangeListener listener); *
* @param listener change listener
*/
public void addChangeListener(PropertyChangeListener listener);
/**
* Remove change listener.
*
* @param listener change listener
*/
public void removeChangeListener(PropertyChangeListener listener);
} }
...@@ -38,30 +38,73 @@ made subject to such option by the copyright holder. ...@@ -38,30 +38,73 @@ made subject to such option by the copyright holder.
Contributor(s): Contributor(s):
Portions Copyrighted 2011 Gephi Consortium. Portions Copyrighted 2011 Gephi Consortium.
*/ */
package org.gephi.project.api; package org.gephi.project.api;
/** /**
* Hosts user data about a project. These information are usually saved to the * Hosts user data about a project.
* project file. * <p>
* These information are also saved to the project file.
* *
* @author Mathieu Bastian * @author Mathieu Bastian
*/ */
public interface ProjectMetaData { public interface ProjectMetaData {
/**
* Returns the keywords of this project.
*
* @return the project's keywords or empty string if missing
*/
public String getKeywords(); public String getKeywords();
/**
* Returns the author of this project.
* <p>
* The default value is the computer's user name.
*
* @return project's author
*/
public String getAuthor(); public String getAuthor();
/**
* Returns the description of this project.
*
* @return the project's description or empty string if missing
*/
public String getDescription(); public String getDescription();
/**
* Returns the title of this project.
*
* @return the project's title or empty string if missing
*/
public String getTitle(); public String getTitle();
/**
* Sets the project's author.
*
* @param author author
*/
public void setAuthor(String author); public void setAuthor(String author);
/**
* Sets the project's description.
*
* @param description description
*/
public void setDescription(String description); public void setDescription(String description);
/**
* Sets the project's keywords.
*
* @param keywords keywords
*/
public void setKeywords(String keywords); public void setKeywords(String keywords);
/**
* Sets the project's title.
*
* @param title title
*/
public void setTitle(String title); public void setTitle(String title);
} }
...@@ -38,19 +38,34 @@ made subject to such option by the copyright holder. ...@@ -38,19 +38,34 @@ made subject to such option by the copyright holder.
Contributor(s): Contributor(s):
Portions Copyrighted 2011 Gephi Consortium. Portions Copyrighted 2011 Gephi Consortium.
*/ */
package org.gephi.project.api; package org.gephi.project.api;
/** /**
* Hosts the project lists and the currently selected project. * Hosts the project lists and the currently selected project.
* *
* @author Mathieu Bastian * @author Mathieu Bastian
*/ */
public interface Projects { public interface Projects {
/**
* Returns true if a project is selected.
*
* @return true if current project, false otherwise
*/
public boolean hasCurrentProject(); public boolean hasCurrentProject();
/**
* Returns the current project or null if missing.
*
* @return current project or null if missing
*/
public Project getCurrentProject(); public Project getCurrentProject();
/**
* Returns an array of all projects.
*
* @return project array
*/
public Project[] getProjects(); public Project[] getProjects();
} }
...@@ -91,15 +91,14 @@ public interface Workspace extends Lookup.Provider { ...@@ -91,15 +91,14 @@ public interface Workspace extends Lookup.Provider {
* storing models in this lookup. * storing models in this lookup.
* <p> * <p>
* May contains: * May contains:
* <ol><li><code>GraphModel</code></li> * <ul><li><code>GraphModel</code></li>
* <li><code>AttributeModel</code></li>
* <li><code>LayoutModel</code></li> * <li><code>LayoutModel</code></li>
* <li><code>StatisticsModel</code></li> * <li><code>StatisticsModel</code></li>
* <li><code>FiltersModel</code></li> * <li><code>FiltersModel</code></li>
* <li><code>PreviewModel</code></li> * <li><code>PreviewModel</code></li>
* <li><code>VizModel</code></li> * <li><code>VizModel</code></li>
* <li>...</li> * <li>...</li>
* </ol> * </ul>
* *
* @return the workspace's lookup * @return the workspace's lookup
*/ */
......
...@@ -41,29 +41,86 @@ ...@@ -41,29 +41,86 @@
*/ */
package org.gephi.project.api; package org.gephi.project.api;
import javax.swing.event.ChangeListener; import java.beans.PropertyChangeListener;
/** /**
* Hosts various information about a workspace the module is maintaining. * Hosts various information about a workspace.
* <p>
* Clients can subscribe to changes by using the
* {@link #addChangeListener(java.beans.PropertyChangeListener) } method. It
* triggers the following events:
* <ul>
* <li><b>EVENT_OPEN:</b> Workspace opened
* <li><b>EVENT_CLOSE:</b> Workspace closed
* <li><b>EVENT_RENAME:</b> Workspace renamed
* <li><b>EVENT_SET_SOURCE:</b> Workspace source set
* </ul>
* *
* @author Mathieu Bastian * @author Mathieu Bastian
* @see Workspace * @see Workspace
*/ */
public interface WorkspaceInformation { public interface WorkspaceInformation {
public static final String EVENT_OPEN = "open";
public static final String EVENT_CLOSE = "close";
public static final String EVENT_RENAME = "rename";
public static final String EVENT_SET_SOURCE = "setSource";
/**
* Returns true if the workspace is open.
*
* @return true if open, false otherwise
*/
public boolean isOpen(); public boolean isOpen();
/**
* Returns true if the workspace is closed.
*
* @return true if closed, false otherwise
*/
public boolean isClosed(); public boolean isClosed();
/**
* Returns true if the workspace is invalid.
*
* @return true if invalid, false otherwise
*/
public boolean isInvalid(); public boolean isInvalid();
/**
* Returns the name of the workspace.
* <p>
* The name can't be null and has a default value (e.g. Workspace 1).
*
* @return the workspace's name
*/
public String getName();
/**
* Returns true if the workspace has a source.
*
* @return true if has a source, false otherwise
*/
public boolean hasSource(); public boolean hasSource();
/**
* Returns the workspace's source or null if missing.
*
* @return workspace's source or null if missing
*/
public String getSource(); public String getSource();
public String getName(); /**
* Add change listener.
public void addChangeListener(ChangeListener listener); *
* @param listener change listener
public void removeChangeListener(ChangeListener listener); */
public void addChangeListener(PropertyChangeListener listener);
/**
* Remove change listener.
*
* @param listener change listener
*/
public void removeChangeListener(PropertyChangeListener listener);
} }
...@@ -38,7 +38,7 @@ made subject to such option by the copyright holder. ...@@ -38,7 +38,7 @@ made subject to such option by the copyright holder.
Contributor(s): Contributor(s):
Portions Copyrighted 2011 Gephi Consortium. Portions Copyrighted 2011 Gephi Consortium.
*/ */
package org.gephi.project.api; package org.gephi.project.api;
/** /**
...@@ -50,25 +50,29 @@ public interface WorkspaceListener { ...@@ -50,25 +50,29 @@ public interface WorkspaceListener {
/** /**
* Notify a workspace has been created. * Notify a workspace has been created.
*
* @param workspace the workspace that was created * @param workspace the workspace that was created
*/ */
public void initialize(Workspace workspace); public void initialize(Workspace workspace);
/** /**
* Notify a workspace has become the selected workspace. * Notify a workspace has become the selected workspace.
*
* @param workspace the workspace that was made current workspace * @param workspace the workspace that was made current workspace
*/ */
public void select(Workspace workspace); public void select(Workspace workspace);
/** /**
* Notify another workspace will be selected. The <code>select()</code> always * Notify another workspace will be selected. The <code>select()</code>
* follows. * always follows.
*
* @param workspace the workspace that is currently the selected workspace * @param workspace the workspace that is currently the selected workspace
*/ */
public void unselect(Workspace workspace); public void unselect(Workspace workspace);
/** /**
* Notify a workspace will be closed, all data must be destroyed. * Notify a workspace will be closed, all data must be destroyed.
*
* @param workspace the workspace that is to be closed * @param workspace the workspace that is to be closed
*/ */
public void close(Workspace workspace); public void close(Workspace workspace);
......
...@@ -49,11 +49,34 @@ package org.gephi.project.api; ...@@ -49,11 +49,34 @@ package org.gephi.project.api;
*/ */
public interface WorkspaceProvider { public interface WorkspaceProvider {
/**
* Returns the current workspace or null if none.
*
* @return current workspace or null if missing
*/
public Workspace getCurrentWorkspace(); public Workspace getCurrentWorkspace();
/**
* Returns true if the project has a current workspace.
*
* @return true if has a current workspace, false otherwise
*/
public boolean hasCurrentWorkspace(); public boolean hasCurrentWorkspace();
/**
* Returns all the workspaces.
* <p>
* Returns an empty array if no workspaces.
*
* @return an array of all workspaces
*/
public Workspace[] getWorkspaces(); public Workspace[] getWorkspaces();
/**
* Retrieve a workspace based on its unique identifier.
*
* @param id workspace's unique identifier
* @return found workspace or null if not found
*/
public Workspace getWorkspace(int id); public Workspace getWorkspace(int id);
} }
...@@ -41,11 +41,11 @@ ...@@ -41,11 +41,11 @@
*/ */
package org.gephi.project.impl; package org.gephi.project.impl;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.gephi.project.api.Project; import org.gephi.project.api.Project;
import org.gephi.project.api.ProjectInformation; import org.gephi.project.api.ProjectInformation;
...@@ -65,23 +65,25 @@ public class ProjectInformationImpl implements ProjectInformation { ...@@ -65,23 +65,25 @@ public class ProjectInformationImpl implements ProjectInformation {
private Status status = Status.CLOSED; private Status status = Status.CLOSED;
private File file; private File file;
//Event //Event
private final transient List<ChangeListener> listeners; private final transient List<PropertyChangeListener> listeners;
public ProjectInformationImpl(Project project, String name) { public ProjectInformationImpl(Project project, String name) {
this.project = project; this.project = project;
this.name = name; this.name = name;
listeners = new ArrayList<ChangeListener>(); listeners = new ArrayList<PropertyChangeListener>();
status = Status.CLOSED; status = Status.CLOSED;
} }
public void open() { public void open() {
this.status = Status.OPEN; Status oldStatus = status;
fireChangeEvent(); status = Status.OPEN;
fireChangeEvent(ProjectInformation.EVENT_OPEN, oldStatus, status);
} }
public void close() { public void close() {
this.status = Status.CLOSED; Status oldStatus = status;
fireChangeEvent(); status = Status.CLOSED;
fireChangeEvent(ProjectInformation.EVENT_CLOSE, oldStatus, status);
} }
@Override @Override
...@@ -120,8 +122,9 @@ public class ProjectInformationImpl implements ProjectInformation { ...@@ -120,8 +122,9 @@ public class ProjectInformationImpl implements ProjectInformation {
} }
public void setName(String name) { public void setName(String name) {
String oldName = this.name;
this.name = name; this.name = name;
fireChangeEvent(); fireChangeEvent(ProjectInformation.EVENT_RENAME, oldName, name);
} }
@Override @Override
...@@ -135,25 +138,29 @@ public class ProjectInformationImpl implements ProjectInformation { ...@@ -135,25 +138,29 @@ public class ProjectInformationImpl implements ProjectInformation {
} }
public void setFile(File file) { public void setFile(File file) {
File oldFile = this.file;
this.file = file; this.file = file;
fireChangeEvent(); fireChangeEvent(ProjectInformation.EVENT_SET_FILE, oldFile, file);
} }
//EVENTS //EVENTS
@Override @Override
public void addChangeListener(ChangeListener listener) { public void addChangeListener(PropertyChangeListener listener) {
listeners.add(listener); listeners.add(listener);
} }
@Override @Override
public void removeChangeListener(ChangeListener listener) { public void removeChangeListener(PropertyChangeListener listener) {
listeners.remove(listener); listeners.remove(listener);
} }
public void fireChangeEvent() { public void fireChangeEvent(String eventName, Object oldValue, Object newValue) {
ChangeEvent event = new ChangeEvent(this); if ((oldValue == null && newValue != null) || (oldValue != null && newValue == null)
for (ChangeListener listener : listeners) { || (oldValue != null && !oldValue.equals(newValue))) {
listener.stateChanged(event); PropertyChangeEvent event = new PropertyChangeEvent(this, eventName, oldValue, newValue);
for (PropertyChangeListener listener : listeners) {
listener.propertyChange(event);
}
} }
} }
} }
...@@ -46,41 +46,34 @@ import java.io.DataOutputStream; ...@@ -46,41 +46,34 @@ import java.io.DataOutputStream;
import org.gephi.project.api.Workspace; import org.gephi.project.api.Workspace;
/** /**
* This class is similar to {@link WorkspacePersistenceProvider} except that it
* allows bytes serialization instead of XML.
* *
* @author mbastian * @author Mathieu Bastian
*/ */
public interface WorkspaceBytesPersistenceProvider { public interface WorkspaceBytesPersistenceProvider {
/** /**
* <p>This is automatically called when saving a project file.</p> * This is automatically called when saving a project file.
* <p>Your implementation must enclose all your data xml in a tag with the
* name provided in your
* <code>getIdentifier</code> method.</p>
* *
* @param writer XMLStreamWriter for xml serialization of this persistence * @param stream DataOutputStream stream to write to
* provider data * @param workspace current workspace being serialized
* @param workspace Current workspace being serialized
*/ */
public void writeBytes(DataOutputStream stream, Workspace workspace); public void writeBytes(DataOutputStream stream, Workspace workspace);
/** /**
* <p>This is automatically called when a start element with the tag name * This is automatically called when loading a project file.
* provided in your
* <code>getIdentifier</code> method.</p>
* <p>Your implementation must detect the tag end element to stop
* reading.</p>
* *
* @param reader XMLStreamReader for deserialization of this persistence * @param stream DataInputStream stream to read from
* provider data previously serialized * @param workspace current workspace being deserialized
* @param workspace Current workspace being deserialized
*/ */
public void readBytes(DataInputStream stream, Workspace workspace); public void readBytes(DataInputStream stream, Workspace workspace);
/** /**
* Unique XML tag identifier for your * Unique tag identifier for your
* <code>WorkspacePersistenceProvider</code> * <code>WorkspaceBytesPersistenceProvider</code>
* *
* @return Unique identifier describing your data * @return unique identifier describing your data
*/ */
public String getIdentifier(); public String getIdentifier();
} }
...@@ -38,12 +38,16 @@ made subject to such option by the copyright holder. ...@@ -38,12 +38,16 @@ made subject to such option by the copyright holder.
Contributor(s): Contributor(s):
Portions Copyrighted 2011 Gephi Consortium. Portions Copyrighted 2011 Gephi Consortium.
*/ */
package org.gephi.project.spi; package org.gephi.project.spi;
import org.gephi.project.api.Workspace; import org.gephi.project.api.Workspace;
/** /**
* Interface to implement workspace duplicate providers.
* <p>
* Implementations should take care of duplicating the models they are
* responsible for.
* *
* @author Mathieu Bastian * @author Mathieu Bastian
*/ */
......
...@@ -38,7 +38,7 @@ made subject to such option by the copyright holder. ...@@ -38,7 +38,7 @@ made subject to such option by the copyright holder.
Contributor(s): Contributor(s):
Portions Copyrighted 2011 Gephi Consortium. Portions Copyrighted 2011 Gephi Consortium.
*/ */
package org.gephi.project.spi; package org.gephi.project.spi;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
...@@ -46,53 +46,68 @@ import javax.xml.stream.XMLStreamWriter; ...@@ -46,53 +46,68 @@ import javax.xml.stream.XMLStreamWriter;
import org.gephi.project.api.Workspace; import org.gephi.project.api.Workspace;
/** /**
* Interface modules implement to notify the system they can read/write part * Interface modules implement to notify the system they can read/write part of
* of the .gephi project file to serialize states and data. * the .gephi project file to serialize states and data.
* <h3>How saving a project works</h3> * <h3>How saving a project works</h3>
* <ol><li>The saving task is looking for all implementations of this interface and * <ol><li>The saving task is looking for all implementations of this interface
* asks to return an XML element that represents data for each workspace.</li> * and asks to return an XML element that represents data for each
* workspace.</li>
* <li>All of these elements are written in the .gephi project file.</li></ol> * <li>All of these elements are written in the .gephi project file.</li></ol>
* <h3>How loading a project works</h3> * <h3>How loading a project works</h3>
* <ol><li>The loading task is looking for all implementations of this interface and * <ol><li>The loading task is looking for all implementations of this interface
* asks for the identifier returned by <code>getIdentifier()</code>.</li> * and asks for the identifier returned by <code>getIdentifier()</code>.</li>
* <li>When traversing the gephi project XML document it tries to match markups with * <li>When traversing the gephi project XML document it tries to match markups
* identifiers. When match, call this provider <code>readXML()</code> method * with identifiers. When match, call this provider <code>readXML()</code>
* with the XML element.</li></ol> * method with the XML element.</li></ol>
* *
* <p>Thus this interface allows any module to serialize and deserialize its data * <p>
* Thus this interface allows any module to serialize and deserialize its data
* to gephi project files.</p> * to gephi project files.</p>
* *
* <p> * <p>
* In order to have your <code>WorkspacePersistenceProvider</code> called, * In order to have your <code>WorkspacePersistenceProvider</code> called, you
* you must annotate it with <code>@ServiceProvider(service = WorkspacePersistenceProvider.class, position = xy)</code> * must annotate it with
* <code>@ServiceProvider(service = WorkspacePersistenceProvider.class, position = xy)</code>
* </p> * </p>
* <p> * <p>
* The <code>position</code> parameter is optional but often useful when when you need other <code>WorkspacePersistenceProvider</code> data deserialized before yours. * The <code>position</code> parameter is optional but often useful when when
* you need other <code>WorkspacePersistenceProvider</code> data deserialized
* before yours.
* </p> * </p>
* *
* @author Mathieu Bastian * @author Mathieu Bastian
* @see Workspace * @see Workspace
*/ */
public interface WorkspacePersistenceProvider { public interface WorkspacePersistenceProvider {
/** /**
* <p>This is automatically called when saving a project file.</p> * This is automatically called when saving a project file.
* <p>Your implementation must enclose all your data xml in a tag with the name provided in your <code>getIdentifier</code> method.</p> * <p>
* @param writer XMLStreamWriter for xml serialization of this persistence provider data * Your implementation must enclose all your data xml in a tag with the name
* provided in your <code>getIdentifier</code> method.
*
* @param writer XMLStreamWriter for xml serialization of this persistence
* provider data
* @param workspace Current workspace being serialized * @param workspace Current workspace being serialized
*/ */
public void writeXML(XMLStreamWriter writer, Workspace workspace); public void writeXML(XMLStreamWriter writer, Workspace workspace);
/** /**
* <p>This is automatically called when a start element with the tag name provided in your <code>getIdentifier</code> method.</p> * This is automatically called when a start element with the tag name
* <p>Your implementation must detect the tag end element to stop reading.</p> * provided in your <code>getIdentifier</code> method.
* @param reader XMLStreamReader for deserialization of this persistence provider data previously serialized * <p>
* Your implementation must detect the tag end element to stop reading.
*
* @param reader XMLStreamReader for deserialization of this persistence
* provider data previously serialized
* @param workspace Current workspace being deserialized * @param workspace Current workspace being deserialized
*/ */
public void readXML(XMLStreamReader reader, Workspace workspace); public void readXML(XMLStreamReader reader, Workspace workspace);
/** /**
* Unique XML tag identifier for your <code>WorkspacePersistenceProvider</code> * Unique XML tag identifier for your
* <code>WorkspacePersistenceProvider</code>.
*
* @return Unique identifier describing your data * @return Unique identifier describing your data
*/ */
public String getIdentifier(); public String getIdentifier();
......
...@@ -41,10 +41,10 @@ ...@@ -41,10 +41,10 @@
*/ */
package org.gephi.workspace.impl; package org.gephi.workspace.impl;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.gephi.project.api.WorkspaceInformation; import org.gephi.project.api.WorkspaceInformation;
/** /**
...@@ -61,7 +61,7 @@ public class WorkspaceInformationImpl implements WorkspaceInformation { ...@@ -61,7 +61,7 @@ public class WorkspaceInformationImpl implements WorkspaceInformation {
private Status status = Status.CLOSED; private Status status = Status.CLOSED;
private String source; private String source;
//Lookup //Lookup
private final transient List<ChangeListener> listeners = new ArrayList<ChangeListener>(); private final transient List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
public WorkspaceInformationImpl(String name) { public WorkspaceInformationImpl(String name) {
this.name = name; this.name = name;
...@@ -82,12 +82,15 @@ public class WorkspaceInformationImpl implements WorkspaceInformation { ...@@ -82,12 +82,15 @@ public class WorkspaceInformationImpl implements WorkspaceInformation {
} }
public void setName(String name) { public void setName(String name) {
String oldValue = this.name;
this.name = name; this.name = name;
fireChangeEvent(); fireChangeEvent(WorkspaceInformation.EVENT_RENAME, oldValue, name);
} }
public void setSource(String source) { public void setSource(String source) {
String oldValue = this.source;
this.source = source; this.source = source;
fireChangeEvent(WorkspaceInformation.EVENT_SET_SOURCE, oldValue, source);
} }
@Override @Override
...@@ -101,13 +104,15 @@ public class WorkspaceInformationImpl implements WorkspaceInformation { ...@@ -101,13 +104,15 @@ public class WorkspaceInformationImpl implements WorkspaceInformation {
} }
public void open() { public void open() {
this.status = Status.OPEN; Status oldValue = status;
fireChangeEvent(); status = Status.OPEN;
fireChangeEvent(WorkspaceInformation.EVENT_OPEN, oldValue, status);
} }
public void close() { public void close() {
this.status = Status.CLOSED; Status oldValue = status;
fireChangeEvent(); status = Status.CLOSED;
fireChangeEvent(WorkspaceInformation.EVENT_CLOSE, oldValue, status);
} }
public void invalid() { public void invalid() {
...@@ -130,19 +135,22 @@ public class WorkspaceInformationImpl implements WorkspaceInformation { ...@@ -130,19 +135,22 @@ public class WorkspaceInformationImpl implements WorkspaceInformation {
} }
@Override @Override
public void addChangeListener(ChangeListener listener) { public void addChangeListener(PropertyChangeListener listener) {
listeners.add(listener); listeners.add(listener);
} }
@Override @Override
public void removeChangeListener(ChangeListener listener) { public void removeChangeListener(PropertyChangeListener listener) {
listeners.remove(listener); listeners.remove(listener);
} }
public void fireChangeEvent() { public void fireChangeEvent(String eventName, Object oldValue, Object newValue) {
ChangeEvent event = new ChangeEvent(this); if ((oldValue == null && newValue != null) || (oldValue != null && newValue == null)
for (ChangeListener listener : listeners) { || (oldValue != null && !oldValue.equals(newValue))) {
listener.stateChanged(event); PropertyChangeEvent event = new PropertyChangeEvent(this, eventName, oldValue, newValue);
for (PropertyChangeListener listener : listeners) {
listener.propertyChange(event);
}
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册