Author: pwang
Date: 2010-01-19 12:16:01 -0800 (Tue, 19 Jan 2010)
New Revision: 18961
Modified:
coreplugins/trunk/browser/src/browser/ui/AttributeBrowserToolBar.java
Log:
persistence the order of columns
Modified: coreplugins/trunk/browser/src/browser/ui/AttributeBrowserToolBar.java
===================================================================
--- coreplugins/trunk/browser/src/browser/ui/AttributeBrowserToolBar.java
2010-01-19 20:14:22 UTC (rev 18960)
+++ coreplugins/trunk/browser/src/browser/ui/AttributeBrowserToolBar.java
2010-01-19 20:16:01 UTC (rev 18961)
@@ -76,8 +76,8 @@
import cytoscape.dialogs.NetworkMetaDataDialog;
import cytoscape.logger.CyLogger;
import cytoscape.util.swing.CheckBoxJList;
+import java.util.HashMap;
-
/**
* Define toolbar for Attribute Browser.
*
@@ -788,13 +788,69 @@
public List<String> getUpdatedSelectedList() {
final Object[] selected = attributeList.getSelectedValues();
- orderedCol.clear();
+
+ orderedCol.remove("ID");
- for (Object colName : selected)
- orderedCol.add(colName.toString());
+ // determine if orderedCol is ordered (drag and drop column may
change the order)
+ boolean isColOrdered = true;
+ for (int i=0; i< orderedCol.size()-1; i++){
+ if
(orderedCol.get(i).compareToIgnoreCase(orderedCol.get(i+1)) > 0){
+ isColOrdered = false;
+ }
+ }
+
+ if (isColOrdered){
+ // The original columns are in order, leave as is
+ orderedCol.clear();
+ for (Object colName : selected)
+ orderedCol.add(colName.toString());
+ return orderedCol;
+ }
+
+ // The original columns are out of order
+
+ // Determine the cols to be added
+ ArrayList<String> colsToBeAdded = new ArrayList<String>();
+ HashMap<String, String> hashMap_orig = new HashMap<String,
String>();
+
+ for (int i=0; i< orderedCol.size(); i++){
+ hashMap_orig.put(orderedCol.get(i), null);
+ }
+
+ for (Object colName : selected) {
+ if (!hashMap_orig.containsKey(colName.toString())){
+ colsToBeAdded.add(colName.toString());
+ }
+ }
+
+ // Determine the cols to be deleted
+ HashMap<String, String> hashMap_new = new HashMap<String,
String>();
+ ArrayList<String> colsToBeDeleted = new ArrayList<String>();
+
+ for (Object colName : selected) {
+ hashMap_new.put(colName.toString(), null);
+ }
+
+ for (int i=0; i< orderedCol.size(); i++){
+ if (!hashMap_new.containsKey(orderedCol.get(i))){
+ colsToBeDeleted.add(orderedCol.get(i));
+ }
+ }
+
+ // delete the cols to be deleted from orderedCol
+ for (int i=0; i< colsToBeDeleted.size(); i++){
+ orderedCol.remove(colsToBeDeleted.get(i));
+ }
+
+ // Append the new columns to the end
+ for (int i=0; i< colsToBeAdded.size(); i++){
+ orderedCol.add(colsToBeAdded.get(i));
+ }
+
return orderedCol;
}
+
public void updateList(List<String> newSelection) {
orderedCol = newSelection;
attributeList.setSelectedItems(orderedCol);
--
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.