Author: neildhruva
Date: 2012-06-27 05:44:03 -0700 (Wed, 27 Jun 2012)
New Revision: 29701

Modified:
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CyActivator.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyTableModel.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PanelComponents.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableDestroyedEvent.java
Log:
Instead of storing JTables corresponding to all networks, it is generated every 
time the network is selected. The columns in each table that are shown/hidden 
are managed through a CyTable which stores the network SUID and the 
corresponding List of boolean values that suggest whether a column is show or 
hidden.

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CyActivator.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CyActivator.java
      2012-06-26 23:55:13 UTC (rev 29700)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CyActivator.java
      2012-06-27 12:44:03 UTC (rev 29701)
@@ -2,6 +2,7 @@
 
 import org.cytoscape.application.events.SetCurrentNetworkListener;
 import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.model.CyTableFactory;
 import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
 import org.cytoscape.service.util.AbstractCyActivator;
 import org.osgi.framework.BundleContext;
@@ -16,9 +17,11 @@
 
        public void start(BundleContext bc) {
                
+               CyTableFactory cyDataTableFactoryServiceRef = 
getService(bc,CyTableFactory.class);
+               
                MyCytoPanel myCytoPanel = new MyCytoPanel();
-               TableAddedEvent tableAddedEvent =new 
TableAddedEvent(myCytoPanel);
-               TableDestroyedEvent tableDestroyedEvent =new 
TableDestroyedEvent();
+               TableAddedEvent tableAddedEvent =new 
TableAddedEvent(myCytoPanel, cyDataTableFactoryServiceRef);
+               TableDestroyedEvent tableDestroyedEvent =new 
TableDestroyedEvent(myCytoPanel);
                
                registerService(bc,myCytoPanel,CytoPanelComponent.class, new 
Properties());
                
registerService(bc,tableAddedEvent,SetCurrentNetworkListener.class, new 
Properties());

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
      2012-06-26 23:55:13 UTC (rev 29700)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
      2012-06-27 12:44:03 UTC (rev 29701)
@@ -39,15 +39,17 @@
         * @param checkBoxArray The <code>JCheckBox</code>[] array to be 
displayed in this <code>JPanel</code>
         * @param tableColumnCount The initial column count of the 
<code>JTable</code>
         */
-       public void initComponents(JTable jtable, JCheckBox[] checkBoxArray, 
int tableColumnCount){
+       public void initComponents(JTable table, JCheckBox[] checkBoxArray, int 
tableColumnCount){
                
-               if(this.table!=null)
+               //if(this.table!=null)
+               //      this.removeAll();
+               if(this.getComponents().length>0)
                        this.removeAll();
                
                cytoChart = new CytoChart();
                myChart = cytoChart.createChart();
                
-        this.table = jtable;
+        this.table = table;
         this.checkBoxArray = checkBoxArray;
         this.tableColumnCount = tableColumnCount;
         
@@ -73,6 +75,16 @@
                checkBoxGroupHor.addComponent(checkBoxArray[i]);
         }
         
+               /*layout.setHorizontalGroup(
+                   layout.createParallelGroup(GroupLayout.Alignment.LEADING)
+                   .addGroup(layout.createSequentialGroup()
+                       .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 
260, GroupLayout.PREFERRED_SIZE)
+                       .addGap(18, 18, 18)
+                       .addGroup(checkBoxGroupHor)
+                       .addContainerGap(246, Short.MAX_VALUE))
+               );
+               */
+               
                layout.setHorizontalGroup(
                    layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
@@ -84,6 +96,17 @@
                        .addGap(35, 35, 35))
                );
                
+        /*layout.setHorizontalGroup(
+            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 350, 
GroupLayout.PREFERRED_SIZE)
+                .addGap(18, 18, 18)
+                .addGroup(checkBoxGroupHor)
+                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 118, 
Short.MAX_VALUE)
+                .addComponent(myChart, GroupLayout.PREFERRED_SIZE, 
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                .addGap(88, 88, 88))
+        );*/
+        
         SequentialGroup checkBoxGroupVert = layout.createSequentialGroup();
         checkBoxGroupVert.addContainerGap();
         for(int i=0;i<tableColumnCount;i++){
@@ -93,6 +116,13 @@
                }
         }
         
+        /*layout.setVerticalGroup(
+                layout.createParallelGroup(GroupLayout.Alignment.LEADING)
+                .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 300, 
Short.MAX_VALUE)
+                .addGroup(checkBoxGroupVert)
+            );
+        */
+        
         layout.setVerticalGroup(
                 layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                 .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 304, 
Short.MAX_VALUE)

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyTableModel.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyTableModel.java
     2012-06-26 23:55:13 UTC (rev 29700)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyTableModel.java
     2012-06-27 12:44:03 UTC (rev 29701)
@@ -18,9 +18,8 @@
        
        public MyTableModel(CyTable cytable){
                this.cytable = cytable;
-               this.columnLength =cytable.getColumns().size();
-               this.columnNames = new String[this.columnLength];
-               setColumnNames();
+               this.columnLength = setColumnCount();
+               this.columnNames = setColumnNames();
        }
        
        @Override
@@ -54,19 +53,40 @@
        }
        
        /**
-        * Sets the names of columns from the <code>CyTable</code>
+        * Sets the count of columns from the <code>CyTable</code>, excluding 
the ones that 
+        * contain data in the form of a <code>List</code>.
         *
         */
-       public void setColumnNames() {
+       public int setColumnCount() {
                Collection<CyColumn> cycolumns = (Collection<CyColumn>) 
cytable.getColumns(); 
                int count=0;
                for(CyColumn cycolumn : cycolumns){
-                        columnNames[count] = cycolumn.getName();
-                        count++;
+                        if(!cycolumn.getType().isInterface()) {
+                                count++;
+                        }
                }       
+               return count;
        }
        
        /**
+        * Sets the names of columns from the <code>CyTable</code>. Only those 
columns that don't
+        * contain <code>List</code> data are added to the array.
+        *
+        */
+       public String[] setColumnNames() {
+               String[] columnNameArray = new String [this.columnLength];
+               Collection<CyColumn> cycolumns = (Collection<CyColumn>) 
cytable.getColumns(); 
+               int count=0;
+               for(CyColumn cycolumn : cycolumns){
+                       if(!cycolumn.getType().isInterface()){
+                               columnNameArray[count] = cycolumn.getName();
+                               count++;
+                       }
+               }
+               return columnNameArray; 
+       }
+       
+       /**
         * Returns a vector of names of columns from the <code>CyTable</code> 
that are of the type Integer, Long or Double.
         * 
         * @return Vector containing names of columns that are of the type 
Integer, Long or Double.

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PanelComponents.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PanelComponents.java
  2012-06-26 23:55:13 UTC (rev 29700)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PanelComponents.java
  2012-06-27 12:44:03 UTC (rev 29701)
@@ -4,46 +4,69 @@
 import java.awt.event.ItemListener;
 import java.io.Serializable;
 import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import javax.swing.JCheckBox;
 import javax.swing.JTable;
 import javax.swing.table.TableColumn;
 import javax.swing.table.TableColumnModel;
 
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.CyTableFactory;
+
 public class PanelComponents {
 
     private JTable table;
        private TableColumnModel tableColumnModel;
-       private HashMap<String, Serializable> hiddenColumnsColumn;
-    private HashMap<String, Serializable> hiddenColumnsIndex;
+       public static Map<String, Serializable> hiddenColumnsColumn;
+    public static Map<String, Serializable> hiddenColumnsIndex;
        private JCheckBox[] checkBoxArray;
        private int columnCount;
-       
+       public static CyTable myCyTable;
+       private List<Boolean> checkBoxState;
+       private Long networkSUID;
     
-    public PanelComponents(JTable table) {
+    public PanelComponents() {
+       
+    }
     
-       this.table = table;
-       this.tableColumnModel = table.getColumnModel();
-       this.columnCount = table.getColumnCount();
-       this.hiddenColumnsColumn = new HashMap<String, Serializable>();
-        this.hiddenColumnsIndex = new HashMap<String, Serializable>();
+    static {
+       hiddenColumnsColumn = new HashMap<String, Serializable>();
+        hiddenColumnsIndex = new HashMap<String, Serializable>();
     }
 
+    public void initCyTable(CyTableFactory tableFactory) {
+               if(myCyTable==null) {
+                       myCyTable = tableFactory.createTable("MyCyTable", 
"SUID", Long.class, true, true);
+                       myCyTable.createListColumn("States", Boolean.class, 
true);
+               }
+    }
+    
     /**
      * Initializes an array of checkboxes with column names of the table as 
titles and
-     * sets each checkbox selected by default. The checkboxes allows user to 
select/deselect
-     * a particular column.  
+     * sets each checkbox checked/unchecked corresponding to the Boolean 
values in which track hidden columns.
+     * The checkboxes allows user to check/uncheck a particular column.  
      * 
      * @return JCheckBox[] Array of checkboxes initialized with column names 
as titles
      */
-    public JCheckBox[] initialiseCheckBoxArray(){
+    public JCheckBox[] initCheckBoxArray(List<Boolean> checkBoxState, Long 
networkSUID, JTable table){
                
+       this.table = table;
+       this.tableColumnModel = table.getColumnModel();
+       this.columnCount = table.getColumnCount();
+       this.checkBoxState = checkBoxState;
+       this.networkSUID = networkSUID;
+       
         checkBoxArray = new JCheckBox[columnCount];
         
         for(int i=0;i<columnCount;i++){
                checkBoxArray[i] = new JCheckBox();
                checkBoxArray[i].setText(table.getColumnName(i));
-               checkBoxArray[i].setSelected(true);
+               checkBoxArray[i].setSelected(checkBoxState.get(i));
+               
                final int j=i;
+               
                /* 
                 * A listener is add to each checkbox so that when the 
corresponding
                 * checkbox is clicked, the hideColumn and showColumn methods 
can be
@@ -62,6 +85,14 @@
                });
         }
     
+        //hide all the columns that the user intends to hide in the JTable
+        for(int i=0;i<columnCount;i++){
+               if(!checkBoxState.get(i)) {
+                       TableColumn column = 
tableColumnModel.getColumn(tableColumnModel.getColumnIndex(checkBoxArray[i].getText()));
+                       tableColumnModel.removeColumn(column);
+               }
+        }
+        
         return checkBoxArray;
     }
     
@@ -72,13 +103,20 @@
      * @param columnName Name of the column that has to be hidden
      */
     public void hideColumn(String columnName) {
-        int index = tableColumnModel.getColumnIndex(columnName);
-        TableColumn column = tableColumnModel.getColumn(index);
+        int columnIndex = tableColumnModel.getColumnIndex(columnName);
+        TableColumn column = tableColumnModel.getColumn(columnIndex);
+        //appending column name with network SUID to uniquely identify the 
column
+        //of a given network
+        columnName+=networkSUID;
         //enter the columnName-column combination in the HashMap 
hiddenColumnsColumn
         hiddenColumnsColumn.put(columnName, column);
         //enter the columnName-index combination in the HashMap 
hiddenColumnsIndex
-        hiddenColumnsIndex.put(columnName, new Integer(index));
+        hiddenColumnsIndex.put(columnName, new Integer(columnIndex));
         tableColumnModel.removeColumn(column);
+        
+        checkBoxState.set(columnIndex, false);
+        myCyTable.getRow(networkSUID).set("States", checkBoxState);
+        
     }
 
     /**
@@ -88,8 +126,11 @@
      * @param columnName Name of the column that has to be made visible
      */
        public void showColumn(String columnName) {
+               //appending column name with network SUID to uniquely identify 
the column
+        //of a given network
+               columnName+=networkSUID;
                //o acquires the column corresponding to the column name
-        Object o = hiddenColumnsColumn.remove(columnName);
+               Object o = hiddenColumnsColumn.remove(columnName);
         if (o == null) {
             return;
         }
@@ -105,6 +146,9 @@
         if(columnIndex < lastColumn){
                tableColumnModel.moveColumn(lastColumn, columnIndex);
         }
+        
+        checkBoxState.set(columnIndex, true);
+        myCyTable.getRow(networkSUID).set("States", checkBoxState);
     }
        
        /**

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
  2012-06-26 23:55:13 UTC (rev 29700)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
  2012-06-27 12:44:03 UTC (rev 29701)
@@ -1,62 +1,70 @@
 package org.cytoscape.sample.internal;
 
-import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.swing.JCheckBox;
 import javax.swing.JTable;
 
 import org.cytoscape.application.events.SetCurrentNetworkEvent;
 import org.cytoscape.application.events.SetCurrentNetworkListener;
+import org.cytoscape.model.CyRow;
 import org.cytoscape.model.CyTable;
+import org.cytoscape.model.CyTableFactory;
 
 public class TableAddedEvent implements SetCurrentNetworkListener{
 
-       private MyCytoPanel myCytoPanel;
+       private MyCytoPanel myCytoPanel; 
        private JTable table;
        private CyTable cytable;
-       private static HashMap<String, Object> panelComponentMap;
        private JCheckBox[] checkBoxArray;
        private PanelComponents panelComponents;
        private int tableColumnCount;
        public static boolean networkDestroyed = false;
+       private List<Boolean> checkBoxState;
        
-       TableAddedEvent(MyCytoPanel myCytoPanel){
+       TableAddedEvent(MyCytoPanel myCytoPanel, CyTableFactory tableFactory){
                
                this.myCytoPanel = myCytoPanel;
-               panelComponentMap = new HashMap<String, Object>();
+               this.panelComponents = new PanelComponents();
+               panelComponents.initCyTable(tableFactory);
        }
 
        
        @Override
        public void handleEvent(SetCurrentNetworkEvent e) {
+               
                //If this method was called immediately following a network 
destroyed event, which it by default does,
                //then such a current network event should not be implemented 
because the pointer doesn't point to 
                //a particular network at that time.
-               if(!networkDestroyed){  
-                       cytable = e.getNetwork().getDefaultNodeTable();
-                       if(cytable!=null)
-                       {
-                               
if(panelComponentMap.containsKey(cytable.getTitle())) { 
-                                       
-                                       panelComponents = (PanelComponents) 
panelComponentMap.get(cytable.getTitle());
-                                       table = panelComponents.getTable();
-                                       checkBoxArray = 
panelComponents.getCheckBoxArray();
-                               } else {
-                                       
-                                       table = new JTable(new 
MyTableModel(cytable));
-                                       panelComponents = new 
PanelComponents(table);
-                                       checkBoxArray = 
panelComponents.initialiseCheckBoxArray();
-                                       
panelComponentMap.put(cytable.getTitle(), panelComponents);
-                               }       
+               if(networkDestroyed) {
+                       networkDestroyed = false;
+                       return;
+               }       
                        
-                               tableColumnCount = 
panelComponents.getTableColumnCount();
-                               myCytoPanel.initComponents(table, 
checkBoxArray, tableColumnCount);
+               //cytable is the CyTable corresponding to the current node 
table        
+               cytable = e.getNetwork().getDefaultNodeTable();
+               if(cytable==null)
+                       return;
+               
+               Long networkSUID = e.getNetwork().getSUID();
+               table = new JTable(new MyTableModel(cytable));
+               tableColumnCount = table.getColumnCount();
+               
+               if(PanelComponents.myCyTable.rowExists(networkSUID)) {  
+                       checkBoxState = 
PanelComponents.myCyTable.getRow(networkSUID).getList("States", Boolean.class);
+                       checkBoxArray = 
panelComponents.initCheckBoxArray(checkBoxState, networkSUID, table);
+               } else {
+                       checkBoxState = new ArrayList<Boolean>();
+                       for(int i=0; i<tableColumnCount; i++) {
+                               checkBoxState.add(true);
                        }
-               } else {
-                       networkDestroyed = false;
-               }
+                       CyRow cyrow = 
PanelComponents.myCyTable.getRow(networkSUID);
+                       cyrow.set("States", checkBoxState);
+                       checkBoxArray = 
panelComponents.initCheckBoxArray(checkBoxState, networkSUID, table);
+               }       
+               
+               table = panelComponents.getTable();
+               myCytoPanel.initComponents(table, checkBoxArray, 
tableColumnCount);             
        }
-       
-       public static HashMap<String, Object> getPanelComponentMap(){
-               return panelComponentMap;
-       }
 }

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableDestroyedEvent.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableDestroyedEvent.java
      2012-06-26 23:55:13 UTC (rev 29700)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableDestroyedEvent.java
      2012-06-27 12:44:03 UTC (rev 29701)
@@ -1,29 +1,52 @@
 package org.cytoscape.sample.internal;
 
-import java.util.HashMap;
+import java.awt.GridLayout;
+import java.util.Collection;
+
+import javax.swing.JLabel;
+
+import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyTable;
 import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
 import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
 
 public class TableDestroyedEvent implements NetworkAboutToBeDestroyedListener{
 
        private MyCytoPanel myCytoPanel;
-       private HashMap<String, Object> panelComponentMap;
        
+       
        TableDestroyedEvent(MyCytoPanel myCytoPanel){
                
                this.myCytoPanel = myCytoPanel;
-               panelComponentMap = new HashMap<String, Object>();
+               
        }
        
        @Override
        public void handleEvent(NetworkAboutToBeDestroyedEvent e) {
                
-               panelComponentMap = TableAddedEvent.getPanelComponentMap();
-               
panelComponentMap.remove(e.getNetwork().getDefaultNodeTable().getTitle());
+               long networkSUID = e.getNetwork().getSUID();
                
+               //TODO: delete row in cytable 
+               
+               //removing all the entries from hiddenColumnsColumn and 
hiddenColumnsIndex Hashmaps
+               String columnName;
+               CyTable cytable =e.getNetwork().getDefaultNodeTable();
+               Collection<CyColumn> columns = cytable.getColumns();
+               for(CyColumn column: columns) {
+                       columnName =column.getName();
+                       columnName+=networkSUID;
+                       
if(PanelComponents.hiddenColumnsColumn.containsKey(columnName)) {
+                               
PanelComponents.hiddenColumnsColumn.remove(columnName);
+                               
PanelComponents.hiddenColumnsIndex.remove(columnName);
+                       }
+               }
+               
                //Clear the Table View Panel
                myCytoPanel.removeAll();
-               myCytoPanel.repaint();
+               JLabel label = new JLabel("Please select/import a network");
+               myCytoPanel.setLayout(new GridLayout());
+               myCytoPanel.add(label);
+               myCytoPanel.revalidate();
                
                //Set networkDestroyed to true in order to keep from 
implementing the code in TableAddedEvent.java
                TableAddedEvent.networkDestroyed = true;

-- 
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.

Reply via email to