Author: neildhruva
Date: 2012-07-03 12:16:52 -0700 (Tue, 03 Jul 2012)
New Revision: 29747
Added:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableAdded.java
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableDestroyed.java
Removed:
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
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/PanelComponents.java
Log:
Changed hide/show column implementation.
Renamed TableAddedEvent.java to EventTableAdded.java and
TableDestroyedEvent.java to EventTableDestroyed.java to avoid confusion with
similar classes in Cytoscape code.
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-07-03 19:01:12 UTC (rev 29746)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CyActivator.java
2012-07-03 19:16:52 UTC (rev 29747)
@@ -22,8 +22,8 @@
CyNetworkTableManager cyNetworkTableManagerServiceRef =
getService(bc, CyNetworkTableManager.class);
MyCytoPanel myCytoPanel = new MyCytoPanel();
- TableAddedEvent tableAddedEvent = new
TableAddedEvent(myCytoPanel, cyDataTableFactoryServiceRef,
cyNetworkTableManagerServiceRef);
- TableDestroyedEvent tableDestroyedEvent = new
TableDestroyedEvent(myCytoPanel);
+ EventTableAdded tableAddedEvent = new
EventTableAdded(myCytoPanel, cyDataTableFactoryServiceRef,
cyNetworkTableManagerServiceRef);
+ EventTableDestroyed tableDestroyedEvent = new
EventTableDestroyed(myCytoPanel);
registerService(bc,myCytoPanel,CytoPanelComponent.class, new
Properties());
registerService(bc,tableAddedEvent,SetCurrentNetworkListener.class, new
Properties());
Copied:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableAdded.java
(from rev 29736,
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/EventTableAdded.java
(rev 0)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableAdded.java
2012-07-03 19:16:52 UTC (rev 29747)
@@ -0,0 +1,90 @@
+package org.cytoscape.sample.internal;
+
+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.CyNetwork;
+import org.cytoscape.model.CyNetworkTableManager;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.CyTableFactory;
+
+public class EventTableAdded implements SetCurrentNetworkListener{
+
+ private MyCytoPanel myCytoPanel;
+ private JTable table;
+ private CyTable cytable;
+ private JCheckBox[] checkBoxArray;
+ private PanelComponents panelComponents;
+ private int columnCount;
+ public static boolean networkDestroyed = false;
+ private List<Boolean> checkBoxState;
+ private List<String> columnNamesList;
+ private CyNetworkTableManager networkTableMgr;
+ private CyTableFactory tableFactory;
+
+ EventTableAdded(MyCytoPanel myCytoPanel, CyTableFactory tableFactory,
CyNetworkTableManager networkTableMgr){
+ this.myCytoPanel = myCytoPanel;
+ this.networkTableMgr = networkTableMgr;
+ this.tableFactory = tableFactory;
+ this.panelComponents = new PanelComponents();
+ }
+
+
+ @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) {
+ networkDestroyed = false;
+ return;
+ }
+
+ //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));
+ columnCount = table.getColumnCount();
+
+ CyTable myCyTable = networkTableMgr.getTable(e.getNetwork(),
CyNetwork.class, "PrintTable");
+
+ if(myCyTable!=null) {
+ checkBoxArray =
panelComponents.initCheckBoxArray(myCyTable, networkSUID, cytable);
+ } else {
+ //checkBoxState stores information on whether a given
column of a network table is
+ //hidden or visible depending on the associated boolean
value (true for visible)
+ checkBoxState = new ArrayList<Boolean>();
+ columnNamesList = new ArrayList<String>();
+ for(int i=0; i<columnCount; i++) {
+ columnNamesList.add(table.getColumnName(i));
+ checkBoxState.add(true);
+ }
+
+ //if myCyTable is null, create a new CyTable and
associate it with the current network.
+ myCyTable = tableFactory.createTable("PrintTabl",
"SUID", Long.class, true, true);
+ myCyTable.createListColumn("Names", String.class, true);
+ myCyTable.createListColumn("States", Boolean.class,
true);
+
+ CyRow cyrow = myCyTable.getRow(networkSUID);
+ cyrow.set("Names", columnNamesList);
+ cyrow.set("States", checkBoxState);
+
+ networkTableMgr.setTable(e.getNetwork(),
CyNetwork.class, "PrintTable", myCyTable);
+
+ checkBoxArray =
panelComponents.initCheckBoxArray(myCyTable, networkSUID, cytable);
+ }
+
+ table = panelComponents.getTable();
+ myCytoPanel.initComponents(table, checkBoxArray, columnCount);
+ }
+}
Copied:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableDestroyed.java
(from rev 29736,
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/EventTableDestroyed.java
(rev 0)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableDestroyed.java
2012-07-03 19:16:52 UTC (rev 29747)
@@ -0,0 +1,33 @@
+package org.cytoscape.sample.internal;
+
+import java.awt.GridLayout;
+
+import javax.swing.JLabel;
+
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
+
+public class EventTableDestroyed implements NetworkAboutToBeDestroyedListener{
+
+ private MyCytoPanel myCytoPanel;
+
+
+ EventTableDestroyed(MyCytoPanel myCytoPanel){
+ this.myCytoPanel = myCytoPanel;
+ }
+
+ @Override
+ public void handleEvent(NetworkAboutToBeDestroyedEvent e) {
+
+ //Clear the Table View Panel
+ myCytoPanel.removeAll();
+ 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
+ EventTableAdded.networkDestroyed = true;
+
+ }
+}
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-07-03 19:01:12 UTC (rev 29746)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
2012-07-03 19:16:52 UTC (rev 29747)
@@ -1,10 +1,13 @@
package org.cytoscape.sample.internal;
import java.awt.Component;
+import java.awt.GridLayout;
+
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.Icon;
import javax.swing.JCheckBox;
+import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
@@ -26,6 +29,9 @@
private CytoChart cytoChart;
public MyCytoPanel() {
+ JLabel label = new JLabel("Please select/import a network");
+ this.setLayout(new GridLayout());
+ this.add(label);
this.setVisible(true);
}
@@ -105,14 +111,14 @@
}
/**
- * @return CytoPanelName Location of the CytoPanel
+ * @return Location of the CytoPanel
*/
public CytoPanelName getCytoPanelName() {
return CytoPanelName.SOUTH;
}
/**
- * @return String Title of the CytoPanel
+ * @return Title of the CytoPanel
*/
public String getTitle() {
return "Table View";
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-07-03 19:01:12 UTC (rev 29746)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PanelComponents.java
2012-07-03 19:16:52 UTC (rev 29747)
@@ -22,24 +22,11 @@
private List<Boolean> checkBoxState;
private List<String> columnNamesList;
private Long networkSUID;
- private CyTable cytable;
- private MyCytoPanel myCytoPanel;
+
+ public PanelComponents() {
- public PanelComponents(MyCytoPanel myCytoPanel) {
- this.myCytoPanel = myCytoPanel;
}
- /*public void initCyTable(CyTableFactory tableFactory) {
- //myCyTable stores a network's SUID and a Boolean List that suggests
whether a particular column of
- //the JTable is visible or hidden based on its true/false value. Each
element in the list corresponds
- //to a particular column in a network
- if(myCyTable==null) {
- myCyTable = tableFactory.createTable("MyCyTable",
"SUID", Long.class, true, true);
- myCyTable.createListColumn("Names", String.class, true);
- myCyTable.createListColumn("States", Boolean.class,
true);
- }
- }*/
-
/**
* Initializes an array of checkboxes with column names of the table as
titles and
* sets each checkbox checked/unchecked corresponding to the Boolean
values in which track hidden columns.
@@ -50,7 +37,6 @@
public JCheckBox[] initCheckBoxArray(CyTable myCyTable, Long networkSUID,
CyTable cytable){
this.myCyTable = myCyTable;
- this.cytable = cytable;
this.table = new JTable(new MyTableModel(cytable));
this.tableColumnModel = table.getColumnModel();
this.columnCount = table.getColumnCount();
@@ -102,7 +88,7 @@
/**
* Hides the column from the table view by removing it from the table
column model.
*
- * @param columnName Name of the column that has to be hidden
+ * @param columnName Name of the column that has to be hidden.
*/
public void hideColumn(String columnName) {
@@ -118,32 +104,32 @@
}
/**
- * Makes a column visible in the table view by refreshing the CytoPanel.
+ * Makes a column visible in the JTable.
*
- * @param columnName Name of the column that has to be made visible
+ * @param columnName Name of the column that has to be made visible.
*/
public void showColumn(String columnName) {
int columnIndex = columnNamesList.indexOf(columnName);
- checkBoxState.set(columnIndex, true);
- myCyTable.getRow(networkSUID).set("States", checkBoxState);
- table = new JTable(new MyTableModel(cytable));
- tableColumnModel = table.getColumnModel();
- for(int i=0;i<columnCount;i++){
+ ((MyTableModel) table.getModel()).fireTableStructureChanged();
+
+ checkBoxState.set(columnIndex, true);
+
+ /* after calling fireTableStructureChanged(), the entire JTable
is refreshed. This is done because
+ * table.getAutoCreateColumnsFromModel() is true. So now, all
columns corresponding to unchecked
+ * checkboxes need to be hidden.
+ */
+ for(int i=0;i<columnCount;i++) {
if(!checkBoxState.get(i)) {
- TableColumn column =
tableColumnModel.getColumn(tableColumnModel.getColumnIndex(checkBoxArray[i].getText()));
- tableColumnModel.removeColumn(column);
+ hideColumn(columnNamesList.get(i));
}
}
-
- //refresh the CytoPanel
- myCytoPanel.initComponents(table, checkBoxArray, columnCount);
}
/**
*
- * @return JCheckBox[] The modified checkbox array after the user has
selected/deselected
- * some checkboxes.
+ * @return The modified checkbox array after the user has
selected/deselected
+ * some checkboxes.
*/
public JCheckBox[] getCheckBoxArray(){
return this.checkBoxArray;
@@ -151,7 +137,7 @@
/**
*
- * @return int The initial column count of the table.
+ * @return The initial column count of the table.
*/
public int getTableColumnCount(){
return this.columnCount;
@@ -159,7 +145,7 @@
/**
*
- * @return JTable The modified JTable after some rows have been made
invisible.
+ * @return The modified JTable after some rows have been made invisible.
*/
public JTable getTable(){
return this.table;
Deleted:
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-07-03 19:01:12 UTC (rev 29746)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
2012-07-03 19:16:52 UTC (rev 29747)
@@ -1,90 +0,0 @@
-package org.cytoscape.sample.internal;
-
-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.CyNetwork;
-import org.cytoscape.model.CyNetworkTableManager;
-import org.cytoscape.model.CyRow;
-import org.cytoscape.model.CyTable;
-import org.cytoscape.model.CyTableFactory;
-
-public class TableAddedEvent implements SetCurrentNetworkListener{
-
- private MyCytoPanel myCytoPanel;
- private JTable table;
- private CyTable cytable;
- private JCheckBox[] checkBoxArray;
- private PanelComponents panelComponents;
- private int tableColumnCount;
- public static boolean networkDestroyed = false;
- private List<Boolean> checkBoxState;
- private List<String> columnNamesList;
- private CyNetworkTableManager networkTableMgr;
- private CyTableFactory tableFactory;
-
- TableAddedEvent(MyCytoPanel myCytoPanel, CyTableFactory tableFactory,
CyNetworkTableManager networkTableMgr){
- this.myCytoPanel = myCytoPanel;
- this.networkTableMgr = networkTableMgr;
- this.tableFactory = tableFactory;
- this.panelComponents = new PanelComponents(myCytoPanel);
- }
-
-
- @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) {
- networkDestroyed = false;
- return;
- }
-
- //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();
-
- CyTable myCyTable = networkTableMgr.getTable(e.getNetwork(),
CyNetwork.class, "PrintTable");
-
- if(myCyTable!=null) {
- checkBoxArray =
panelComponents.initCheckBoxArray(myCyTable, networkSUID, cytable);
- } else {
- //checkBoxState stores information on whether a given
column of a network table is
- //hidden or visible depending on the associated boolean
value (true for visible)
- checkBoxState = new ArrayList<Boolean>();
- columnNamesList = new ArrayList<String>();
- for(int i=0; i<tableColumnCount; i++) {
- columnNamesList.add(table.getColumnName(i));
- checkBoxState.add(true);
- }
-
- //if myCyTable is null, create a new CyTable and
associate it with the current network.
- myCyTable = tableFactory.createTable("PrintTabl",
"SUID", Long.class, true, true);
- myCyTable.createListColumn("Names", String.class, true);
- myCyTable.createListColumn("States", Boolean.class,
true);
-
- CyRow cyrow = myCyTable.getRow(networkSUID);
- cyrow.set("Names", columnNamesList);
- cyrow.set("States", checkBoxState);
-
- networkTableMgr.setTable(e.getNetwork(),
CyNetwork.class, "PrintTable", myCyTable);
-
- checkBoxArray =
panelComponents.initCheckBoxArray(myCyTable, networkSUID, cytable);
- }
-
- table = panelComponents.getTable();
- myCytoPanel.initComponents(table, checkBoxArray,
tableColumnCount);
- }
-}
Deleted:
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-07-03 19:01:12 UTC (rev 29746)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableDestroyedEvent.java
2012-07-03 19:16:52 UTC (rev 29747)
@@ -1,35 +0,0 @@
-package org.cytoscape.sample.internal;
-
-import java.awt.GridLayout;
-
-import javax.swing.JLabel;
-
-import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
-import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
-
-public class TableDestroyedEvent implements NetworkAboutToBeDestroyedListener{
-
- private MyCytoPanel myCytoPanel;
-
-
- TableDestroyedEvent(MyCytoPanel myCytoPanel){
-
- this.myCytoPanel = myCytoPanel;
-
- }
-
- @Override
- public void handleEvent(NetworkAboutToBeDestroyedEvent e) {
-
- //Clear the Table View Panel
- myCytoPanel.removeAll();
- 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.