Author: ruschein
Date: 2011-02-01 13:41:13 -0800 (Tue, 01 Feb 2011)
New Revision: 23992
Added:
core3/model-api/trunk/src/main/java/org/cytoscape/model/events/ColumnNameChangedEvent.java
core3/model-api/trunk/src/main/java/org/cytoscape/model/events/ColumnNameChangedListener.java
core3/model-api/trunk/src/test/java/org/cytoscape/model/events/ColumnNameChangedEventTest.java
Modified:
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
Log:
Added new ColumnNameChanged{Event,Listener} classes.
Added:
core3/model-api/trunk/src/main/java/org/cytoscape/model/events/ColumnNameChangedEvent.java
===================================================================
---
core3/model-api/trunk/src/main/java/org/cytoscape/model/events/ColumnNameChangedEvent.java
(rev 0)
+++
core3/model-api/trunk/src/main/java/org/cytoscape/model/events/ColumnNameChangedEvent.java
2011-02-01 21:41:13 UTC (rev 23992)
@@ -0,0 +1,68 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.model.events;
+
+
+import org.cytoscape.event.AbstractCyEvent;
+import org.cytoscape.model.CyTable;
+
+
+public class ColumnNameChangedEvent extends AbstractCyEvent<CyTable> {
+ private final String oldColumnName;
+ private final String newColumnName;
+
+ public ColumnNameChangedEvent(final CyTable source, final String
oldColumnName,
+ final String newColumnName)
+ {
+ super(source, ColumnNameChangedListener.class);
+
+ if (oldColumnName == null)
+ throw new NullPointerException("\"oldColumnName\" must
not be null!");
+ this.oldColumnName = oldColumnName;
+
+ if (newColumnName == null)
+ throw new NullPointerException("\"newColumnName\" must
not be null!");
+ this.newColumnName = newColumnName;
+ }
+
+ /**
+ * Returns the old name of the column.
+ * @return the old name of the column
+ */
+ public String getOldColumnName() {
+ return oldColumnName;
+ }
+
+ /**
+ * Returns the new name of the column.
+ * @return the new name of the column
+ */
+ public String getNewColumnName() {
+ return newColumnName;
+ }
+}
Copied:
core3/model-api/trunk/src/main/java/org/cytoscape/model/events/ColumnNameChangedListener.java
(from rev 23991,
core3/model-api/trunk/src/main/java/org/cytoscape/model/events/ColumnCreatedListener.java)
===================================================================
---
core3/model-api/trunk/src/main/java/org/cytoscape/model/events/ColumnNameChangedListener.java
(rev 0)
+++
core3/model-api/trunk/src/main/java/org/cytoscape/model/events/ColumnNameChangedListener.java
2011-02-01 21:41:13 UTC (rev 23992)
@@ -0,0 +1,43 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.model.events;
+
+
+import org.cytoscape.event.CyListener;
+
+
+/**
+ * Listener for ColumnNameChangedEvents.
+ */
+public interface ColumnNameChangedListener extends CyListener {
+ /**
+ * The method that should handle the specified event.
+ * @param e The event to be handled.
+ */
+ void handleEvent(ColumnNameChangedEvent e);
+}
Copied:
core3/model-api/trunk/src/test/java/org/cytoscape/model/events/ColumnNameChangedEventTest.java
(from rev 23991,
core3/model-api/trunk/src/test/java/org/cytoscape/model/events/ColumnCreatedEventTest.java)
===================================================================
---
core3/model-api/trunk/src/test/java/org/cytoscape/model/events/ColumnNameChangedEventTest.java
(rev 0)
+++
core3/model-api/trunk/src/test/java/org/cytoscape/model/events/ColumnNameChangedEventTest.java
2011-02-01 21:41:13 UTC (rev 23992)
@@ -0,0 +1,97 @@
+/*
+ Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.model.events;
+
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.cytoscape.model.CyTable;
+
+import static org.mockito.Mockito.*;
+
+
+public class ColumnNameChangedEventTest extends TestCase {
+ ColumnNameChangedEvent event;
+ CyTable table;
+ final String oldColumnName = "asdf";
+ final String newColumnName = "xyz";
+
+ public void setUp() {
+ table = mock(CyTable.class);
+ event = new ColumnNameChangedEvent(table, oldColumnName,
newColumnName);
+ }
+
+ public void testGetOldColumnName() {
+ assertEquals(event.getOldColumnName(), oldColumnName);
+ }
+
+ public void testGetNewColumnName() {
+ assertEquals(event.getNewColumnName(), newColumnName);
+ }
+
+ public void testGetSource() {
+ assertEquals(event.getSource(), table);
+ }
+
+ public void testGetListenerClass() {
+ assertEquals(event.getListenerClass(),
ColumnNameChangedListener.class);
+ }
+
+ public void testNullOldColumn() {
+ try {
+ ColumnNameChangedEvent ev =
+ new ColumnNameChangedEvent(table, null,
newColumnName);
+ } catch (NullPointerException npe) {
+ return;
+ }
+ fail("didn't catch expected npe for old column name");
+ }
+
+ public void testNullNewColumn() {
+ try {
+ ColumnNameChangedEvent ev =
+ new ColumnNameChangedEvent(table,
oldColumnName, null);
+ } catch (NullPointerException npe) {
+ return;
+ }
+ fail("didn't catch expected npe for new column name");
+ }
+
+ public void testNullTable() {
+ try {
+ ColumnNameChangedEvent ev =
+ new ColumnNameChangedEvent(null, oldColumnName,
newColumnName);
+ } catch (NullPointerException npe) {
+ return;
+ }
+ fail("didn't catch expected npe for table");
+ }
+}
Modified:
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
---
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2011-02-01 20:35:13 UTC (rev 23991)
+++
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
2011-02-01 21:41:13 UTC (rev 23992)
@@ -48,6 +48,7 @@
import org.cytoscape.model.SUIDFactory;
import org.cytoscape.model.events.ColumnCreatedEvent;
import org.cytoscape.model.events.ColumnDeletedEvent;
+import org.cytoscape.model.events.ColumnNameChangedEvent;
import org.cytoscape.model.events.RowSetMicroListener;
import org.cytoscape.model.events.RowCreatedMicroListener;
@@ -117,26 +118,31 @@
virtualColumnMap = new HashMap<String, VirtualColumn>();
}
- synchronized void updateColumnName(final String oldColumnName, final
String newColumnName) {
- if (currentlyActiveAttributes.contains(oldColumnName)) {
- currentlyActiveAttributes.remove(oldColumnName);
- currentlyActiveAttributes.add(newColumnName);
- }
+ void updateColumnName(final String oldColumnName, final String
newColumnName) {
+ synchronized(this) {
+ if (currentlyActiveAttributes.contains(oldColumnName)) {
+ currentlyActiveAttributes.remove(oldColumnName);
+ currentlyActiveAttributes.add(newColumnName);
+ }
- final Map<Object, Object> keyValuePairs =
attributes.get(oldColumnName);
- if (keyValuePairs != null) {
- attributes.remove(oldColumnName);
- attributes.put(newColumnName, keyValuePairs);
- }
+ final Map<Object, Object> keyValuePairs =
attributes.get(oldColumnName);
+ if (keyValuePairs != null) {
+ attributes.remove(oldColumnName);
+ attributes.put(newColumnName, keyValuePairs);
+ }
- final Map<Object, Set<Object>> valueKeysPairs =
reverse.get(oldColumnName);
- if (valueKeysPairs != null) {
- reverse.remove(oldColumnName);
- reverse.put(newColumnName, valueKeysPairs);
+ final Map<Object, Set<Object>> valueKeysPairs =
reverse.get(oldColumnName);
+ if (valueKeysPairs != null) {
+ reverse.remove(oldColumnName);
+ reverse.put(newColumnName, valueKeysPairs);
+ }
+
+ final CyColumn column = types.get(oldColumnName);
+ types.put(newColumnName, column);
}
- final CyColumn column = types.get(oldColumnName);
- types.put(newColumnName, column);
+ eventHelper.fireSynchronousEvent(new
ColumnNameChangedEvent(this, oldColumnName,
+
newColumnName));
}
/**
--
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.