Author: ruschein
Date: 2010-09-30 13:22:43 -0700 (Thu, 30 Sep 2010)
New Revision: 22106
Modified:
cytoscape/trunk/application/src/main/java/cytoscape/Cytoscape.java
cytoscape/trunk/coreplugins/TableImport/src/main/java/edu/ucsd/bioeng/coreplugin/tableImport/ui/ImportAttributeTableTask.java
cytoscape/trunk/coreplugins/browser/src/main/java/browser/AttributeBrowser.java
Log:
Now we ask the user whether she/he wants to display newly loaded attrs in the
browser or not.
Modified: cytoscape/trunk/application/src/main/java/cytoscape/Cytoscape.java
===================================================================
--- cytoscape/trunk/application/src/main/java/cytoscape/Cytoscape.java
2010-09-30 19:51:24 UTC (rev 22105)
+++ cytoscape/trunk/application/src/main/java/cytoscape/Cytoscape.java
2010-09-30 20:22:43 UTC (rev 22106)
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -239,6 +240,12 @@
public static final String NESTED_NETWORK_DESTROYED =
"NESTED_NETWORK_DESTROYED";
/**
+ * Fired every time new attributes are loaded and provides the
CyAttributes that was modified
+ * as well as a set of the new attribute names..
+ */
+ public static final String NEW_ATTRS_LOADED = "NEW_ATTRS_LOADED";
+
+ /**
* When creating a network, use one of the standard suffixes to have it
* parsed correctly<BR>
* <ul>
@@ -1596,6 +1603,11 @@
public static void loadAttributes(String[] nodeAttrLocations, String[]
edgeAttrLocations) {
// check to see if there are Node Attributes passed
if (nodeAttrLocations != null) {
+ final Set<String> oldNodeAttrNames = new
HashSet<String>();
+ for (final String attrName :
nodeAttributes.getAttributeNames())
+ oldNodeAttrNames.add(attrName);
+
+ boolean fireChange = false;
for (int i = 0; i < nodeAttrLocations.length; ++i) {
try {
InputStreamReader reader = null;
@@ -1608,7 +1620,7 @@
reader.close();
}
}
- firePropertyChange(ATTRIBUTES_CHANGED,
null, null);
+ fireChange = true;
} catch (Exception e) {
// e.printStackTrace();
throw new
IllegalArgumentException("Failure loading node attribute data: "
@@ -1616,23 +1628,39 @@
+
e.getMessage());
}
}
+
+ if (fireChange) {
+ final Set<String> newNodeAttrNames = new
HashSet<String>();
+ for (final String attrName :
nodeAttributes.getAttributeNames()) {
+ if
(!oldNodeAttrNames.contains(attrName))
+ newNodeAttrNames.add(attrName);
+ }
+
+ firePropertyChange(ATTRIBUTES_CHANGED, null,
null);
+ firePropertyChange(NEW_ATTRS_LOADED,
nodeAttributes, newNodeAttrNames);
+ }
}
// Check to see if there are Edge Attributes Passed
if (edgeAttrLocations != null) {
+ final Set<String> oldEdgeAttrNames = new
HashSet<String>();
+ for (final String attrName :
edgeAttributes.getAttributeNames())
+ oldEdgeAttrNames.add(attrName);
+
+ boolean fireChange = false;
for (int j = 0; j < edgeAttrLocations.length; ++j) {
try {
InputStreamReader reader = null;
- try {
+ try {
reader = new
InputStreamReader(FileUtil.getInputStream(edgeAttrLocations[j]));
- CyAttributesReader.loadAttributes(edgeAttributes,
reader);
- }
- finally {
- if (reader != null) {
- reader.close();
- }
- }
- firePropertyChange(ATTRIBUTES_CHANGED,
null, null);
+
CyAttributesReader.loadAttributes(edgeAttributes, reader);
+ }
+ finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ fireChange = true;
} catch (Exception e) {
// e.printStackTrace();
throw new
IllegalArgumentException("Failure loading edge attribute data: "
@@ -1640,10 +1668,20 @@
+
e.getMessage());
}
}
+
+ if (fireChange) {
+ final Set<String> newEdgeAttrNames = new
HashSet<String>();
+ for (final String attrName :
edgeAttributes.getAttributeNames()) {
+ if
(!oldEdgeAttrNames.contains(attrName))
+ newEdgeAttrNames.add(attrName);
+ }
+
+ firePropertyChange(ATTRIBUTES_CHANGED, null,
null);
+ firePropertyChange(NEW_ATTRS_LOADED,
edgeAttributes, newEdgeAttrNames);
+ }
}
}
-
/**
* This will replace the bioDataServer.
*/
Modified:
cytoscape/trunk/coreplugins/TableImport/src/main/java/edu/ucsd/bioeng/coreplugin/tableImport/ui/ImportAttributeTableTask.java
===================================================================
---
cytoscape/trunk/coreplugins/TableImport/src/main/java/edu/ucsd/bioeng/coreplugin/tableImport/ui/ImportAttributeTableTask.java
2010-09-30 19:51:24 UTC (rev 22105)
+++
cytoscape/trunk/coreplugins/TableImport/src/main/java/edu/ucsd/bioeng/coreplugin/tableImport/ui/ImportAttributeTableTask.java
2010-09-30 20:22:43 UTC (rev 22106)
@@ -1,14 +1,6 @@
-
/*
- Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2007, 2010, The Cytoscape Consortium (www.cytoscape.org)
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
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
@@ -33,18 +25,15 @@
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-
package edu.ucsd.bioeng.coreplugin.tableImport.ui;
+
import cytoscape.Cytoscape;
import cytoscape.task.Task;
import cytoscape.task.TaskMonitor;
import edu.ucsd.bioeng.coreplugin.tableImport.reader.TextTableReader;
-/**
- *
- */
public class ImportAttributeTableTask implements Task {
private TextTableReader reader;
private String source;
@@ -73,7 +62,8 @@
try {
reader.readTable();
taskMonitor.setPercentCompleted(100);
-
Cytoscape.firePropertyChange(Cytoscape.ATTRIBUTES_CHANGED,null,null);
+
Cytoscape.firePropertyChange(Cytoscape.ATTRIBUTES_CHANGED, null, null);
+
Cytoscape.firePropertyChange(Cytoscape.NEW_ATTRS_LOADED, null, null);
informUserOfAnnotationStats();
} catch (Exception e) {
e.printStackTrace();
Modified:
cytoscape/trunk/coreplugins/browser/src/main/java/browser/AttributeBrowser.java
===================================================================
---
cytoscape/trunk/coreplugins/browser/src/main/java/browser/AttributeBrowser.java
2010-09-30 19:51:24 UTC (rev 22105)
+++
cytoscape/trunk/coreplugins/browser/src/main/java/browser/AttributeBrowser.java
2010-09-30 20:22:43 UTC (rev 22106)
@@ -1,13 +1,6 @@
/*
Copyright (c) 2006, 2007, 2010, The Cytoscape Consortium (www.cytoscape.org)
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Institut Pasteur
- - Agilent Technologies
-
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
@@ -34,6 +27,7 @@
*/
package browser;
+
import giny.model.GraphObject;
import java.awt.BorderLayout;
@@ -43,11 +37,14 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import javax.swing.JPanel;
+import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
@@ -80,8 +77,7 @@
* panel to AttrMod Dialog Peng-Liang wang 9/28/2006
*
*/
-public class AttributeBrowser implements TableColumnModelListener {
-
+public class AttributeBrowser implements TableColumnModelListener,
PropertyChangeListener {
private static final Dimension PANEL_SIZE = new Dimension(400, 300);
protected static Object pcsO = new Object();
@@ -116,7 +112,7 @@
// Each Attribute Browser operates on one CytoscapeData object, and on
// either Nodes or Edges.
- private final CyAttributes attrData;
+ private final CyAttributes attributes;
// Type of attribute
private final DataObjectType panelType;
@@ -164,14 +160,14 @@
/**
* Creates a new DataTable object.
*
- * @param attrData
+ * @param attributes
* DOCUMENT ME!
* @param tableObjectType
* DOCUMENT ME!
*/
private AttributeBrowser(final DataObjectType panelType) {
// set up CytoscapeData Object and GraphObject Type
- this.attrData = panelType.getAssociatedAttributes();
+ this.attributes = panelType.getAssociatedAttributes();
this.panelType = panelType;
this.orderedColumn = new ArrayList<String>();
@@ -183,7 +179,7 @@
// Toolbar for selecting attributes and create new attribute.
attributeBrowserToolBar = new
AttributeBrowserToolBar(tableModel, attributeTable,
- new
AttributeModel(attrData), orderedColumn,
+ new
AttributeModel(attributes), orderedColumn,
panelType);
// the attribute table display: CytoPanel 2, horizontal SOUTH
panel.
@@ -212,10 +208,28 @@
// Add main browser panel to CytoPanel 2 (SOUTH)
Cytoscape.getDesktop().getCytoPanel(SwingConstants.SOUTH)
.add(panelType.getDisplayName() + " Attribute
Browser", mainPanel);
+
Cytoscape.getDesktop().getCytoPanel(SwingConstants.SOUTH).setState(CytoPanelState.DOCK);
-
Cytoscape.getDesktop().getCytoPanel(SwingConstants.SOUTH).setState(CytoPanelState.DOCK);
+
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(Cytoscape.NEW_ATTRS_LOADED,
this);
}
+ public void propertyChange(PropertyChangeEvent e) {
+ // This will handle the case for the change of attribute
userVisibility
+ if (e.getPropertyName() == Cytoscape.NEW_ATTRS_LOADED &&
e.getOldValue() == attributes) {
+ final Set<String> newAttrNames =
(Set<String>)e.getNewValue();
+ if (JOptionPane.showConfirmDialog(
+ null,
+ "Display " + newAttrNames.size() + " newly
loaded attributes in the attribute browser?",
+ "Confirmation", JOptionPane.YES_NO_OPTION)
+ == JOptionPane.YES_OPTION)
+ {
+ for (final String newAttrName : newAttrNames)
+ orderedColumn.add(newAttrName);
+ tableModel.setTableData(null, orderedColumn);
+ }
+ }
+ }
+
/**
* DOCUMENT ME!
*
@@ -266,7 +280,7 @@
private DataTableModel makeModel() {
- final List<String> attributeNames =
CyAttributesUtils.getVisibleAttributeNames(attrData);
+ final List<String> attributeNames =
CyAttributesUtils.getVisibleAttributeNames(attributes);
final List<GraphObject> graphObjects =
getSelectedGraphObjects();
final DataTableModel model = new DataTableModel(graphObjects,
attributeNames, panelType);
--
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.