Author: ruschein
Date: 2011-07-21 16:02:35 -0700 (Thu, 21 Jul 2011)
New Revision: 26244
Added:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnEdit.java
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/SaveColumn.java
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnTask.java
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnTaskFactory.java
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
Log:
Added undo/redo support for column deletions.
Copied:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnEdit.java
(from rev 26241,
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/RenameColumnEdit.java)
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnEdit.java
(rev 0)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnEdit.java
2011-07-21 23:02:35 UTC (rev 26244)
@@ -0,0 +1,39 @@
+package org.cytoscape.task.internal.table;
+
+
+import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.util.swing.CyAbstractEdit;
+
+
+/** An undoable edit that will undo and redo the deletion of a column. */
+final class DeleteColumnEdit extends CyAbstractEdit {
+ private final CyTable table;
+ private final String columnName;
+ private final Class<?> columnType;
+ private SaveColumn savedColumn;
+
+ DeleteColumnEdit(final CyColumn column) {
+ super("Delete Column");
+
+ this.table = column.getTable();
+ this.columnName = column.getName();
+ this.columnType = column.getType();
+ this.savedColumn = new SaveColumn(table, columnName);
+ }
+
+ public void redo() {
+ super.redo();
+
+ savedColumn = new SaveColumn(table, columnName);
+ table.deleteColumn(columnName);
+ }
+
+ public void undo() {
+ super.undo();
+
+ table.createColumn(columnName, columnType, /* isImmutable = */
false);
+ savedColumn.restoreColumn(table, columnName);
+ savedColumn = null;
+ }
+}
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnTask.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnTask.java
2011-07-21 21:41:49 UTC (rev 26243)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnTask.java
2011-07-21 23:02:35 UTC (rev 26244)
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2010-2011, 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
@@ -35,15 +35,22 @@
import org.cytoscape.work.Tunable;
import org.cytoscape.work.TunableValidator;
import org.cytoscape.work.TunableValidator.ValidationState;
+import org.cytoscape.work.undo.UndoSupport;
public final class DeleteColumnTask extends AbstractTableColumnTask implements
TunableValidator {
- DeleteColumnTask(final CyColumn column) {
+ private final UndoSupport undoSupport;
+
+ DeleteColumnTask(final UndoSupport undoSupport, final CyColumn column) {
super(column);
+ this.undoSupport = undoSupport;
}
@Override
public void run(final TaskMonitor taskMonitor) throws Exception {
+ undoSupport.getUndoableEditSupport().postEdit(
+ new DeleteColumnEdit(column));
+
column.getTable().deleteColumn(column.getName());
}
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnTaskFactory.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnTaskFactory.java
2011-07-21 21:41:49 UTC (rev 26243)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/DeleteColumnTaskFactory.java
2011-07-21 23:02:35 UTC (rev 26244)
@@ -29,13 +29,20 @@
import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.undo.UndoSupport;
public final class DeleteColumnTaskFactory extends
AbstractTableColumnTaskFactory {
+ private final UndoSupport undoSupport;
+
+ public DeleteColumnTaskFactory(final UndoSupport undoSupport) {
+ this.undoSupport = undoSupport;
+ }
+
@Override
public TaskIterator getTaskIterator() {
if (column == null)
throw new IllegalStateException("you forgot to set the
CyColumn on this task factory!");
- return new TaskIterator(new DeleteColumnTask(column));
+ return new TaskIterator(new DeleteColumnTask(undoSupport,
column));
}
}
\ No newline at end of file
Added:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/SaveColumn.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/SaveColumn.java
(rev 0)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/table/SaveColumn.java
2011-07-21 23:02:35 UTC (rev 26244)
@@ -0,0 +1,76 @@
+/*
+ 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.task.internal.table;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTable;
+
+
+/** A helper class used by various "edit" classes. */
+final class SaveColumn {
+ final List<PrimaryKeyAndValue> keysAndValues;
+
+ SaveColumn(final CyTable table, final String columnName) {
+ keysAndValues = new
ArrayList<PrimaryKeyAndValue>(table.getRowCount());
+ final String primarykeyName = table.getPrimaryKey().getName();
+ for (final CyRow row : table.getAllRows()) {
+ final Object primaryKey = row.getRaw(primarykeyName);
+ final Object value = row.getRaw(columnName);
+ keysAndValues.add(new PrimaryKeyAndValue(primaryKey,
value));
+ }
+ }
+
+ void restoreColumn(final CyTable table, final String columnName) {
+ for (final PrimaryKeyAndValue keyAndValue : keysAndValues)
+
table.getRow(keyAndValue.getPrimaryKey()).set(columnName,
keyAndValue.getValue());
+ }
+}
+
+
+final class PrimaryKeyAndValue {
+ final Object primaryKey;
+ final Object value;
+
+ PrimaryKeyAndValue(final Object primaryKey, final Object value) {
+ this.primaryKey = primaryKey;
+ this.value = value;
+ }
+
+ Object getPrimaryKey() {
+ return primaryKey;
+ }
+
+ Object getValue() {
+ return value;
+ }
+}
\ No newline at end of file
Modified:
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
---
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
2011-07-21 21:41:49 UTC (rev 26243)
+++
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
2011-07-21 23:02:35 UTC (rev 26244)
@@ -341,6 +341,7 @@
<bean id="deleteColumnTaskFactory"
class="org.cytoscape.task.internal.table.DeleteColumnTaskFactory">
+ <constructor-arg ref="undoSupportServiceRef" />
</bean>
<bean id="renameColumnTaskFactory"
--
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.