Author: ruschein
Date: 2010-12-06 13:33:46 -0800 (Mon, 06 Dec 2010)
New Revision: 23098

Added:
   
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/AttributeBrowser.java
   
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/SortTableModel.java
Modified:
   
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/DataEditAction.java
   
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/DataTableModel.java
Log:
Work in progress.

Copied: 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/AttributeBrowser.java
 (from rev 23085, 
cytoscape/trunk/coreplugins/browser/src/main/java/browser/AttributeBrowser.java)
===================================================================
--- 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/AttributeBrowser.java
                           (rev 0)
+++ 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/AttributeBrowser.java
   2010-12-06 21:33:46 UTC (rev 23098)
@@ -0,0 +1,371 @@
+/*
+ Copyright (c) 2006, 2007, 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.browser.internal;
+
+
+import org.cytoscape.model.CyTableEntry;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.SwingConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.SwingPropertyChangeSupport;
+import javax.swing.event.TableColumnModelEvent;
+import javax.swing.event.TableColumnModelListener;
+import javax.swing.table.TableColumnModel;
+
+import browser.ui.AttributeBrowserToolBar;
+import browser.ui.CyAttributeBrowserTable;
+import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import cytoscape.data.CyAttributesUtils;
+import cytoscape.view.cytopanels.CytoPanelListener;
+import cytoscape.view.cytopanels.CytoPanelState;
+
+
+/**
+ * DataTable class constructs all Panels for the browser.<br>
+ * One DataTable contains the table of values and the toolbar above the table
+ * within a jpanel. This panel is then added to CytoPanel2. Tabbed browsing
+ * between attribute tables is handled by CytoPanel2.
+ *
+ * @author kono xmas
+ *
+ * Combine CytoPanel_2 and CytoPanel_3 Peng-Liang wang 9/12/2006 Move advanced
+ * panel to AttrMod Dialog Peng-Liang wang 9/28/2006
+ *
+ */
+public class AttributeBrowser implements TableColumnModelListener {
+       private static final Dimension PANEL_SIZE = new Dimension(400, 300);
+       
+       protected static Object pcsO = new Object();
+       protected static PropertyChangeSupport pcs = new 
SwingPropertyChangeSupport(pcsO);
+       
+       
+       public static PropertyChangeSupport getPropertyChangeSupport() {
+               return pcs;
+       }
+       
+       public static void firePropertyChange(String property_type, Object 
old_value, Object new_value) {
+               final PropertyChangeEvent e = new PropertyChangeEvent(pcsO, 
property_type, old_value, new_value);
+               getPropertyChangeSupport().firePropertyChange(e);
+       }
+       
+       public static final String ID = "ID";
+
+       /**
+        * 
+        */
+       public static final String NETWORK_METADATA = "Network Metadata";
+
+       /**
+        * 
+        */
+       public static final Color DEFAULT_EDGE_COLOR = Color.RED;
+
+       /**
+        * 
+        */
+       public static final Color DEFAULT_NODE_COLOR = Color.YELLOW;
+
+       // Each Attribute Browser operates on one CytoscapeData object, and on
+       // either Nodes or Edges.
+       private final CyAttributes attributes;
+
+       // Main panel for put everything
+       private JPanel mainPanel;
+
+       // Table object and its model. 
+       private final DataTableModel tableModel;
+       private final CyAttributeBrowserTable attributeTable;
+
+       // Toolbar panel on the top of browser
+       private final AttributeBrowserToolBar attributeBrowserToolBar;
+
+       // Will be used to keep track of column order.
+       private List<String> orderedColumn;
+
+       // Index number for the panels
+       int attributePanelIndex;
+       int modPanelIndex;
+       int tableIndex;
+       int browserIndex;
+
+       
+       /**
+        *
+        */
+       public final static String RESTORE_COLUMN = "RESTORE_COLUMN";
+       public final static String CLEAR_INTERNAL_SELECTION = 
"CLEAR_INTERNAL_SELECTION";
+
+       /**
+        * Browser object is one per attribute type.
+        * Users should access it through this.
+        *
+        * @param type
+        */
+       public static AttributeBrowser getBrowser(final DataObjectType type) {
+               return new AttributeBrowser(type);
+       }
+
+       protected void addMenuItem(Component newItem) {
+               attributeTable.getPopupMenu().add(newItem);
+       }
+
+       /**
+        * Creates a new DataTable object.
+        *
+        * @param attributes
+        *            DOCUMENT ME!
+        * @param tableObjectType
+        *            DOCUMENT ME!
+        */
+       private AttributeBrowser(final DataObjectType panelType) {
+               // set up CytoscapeData Object and GraphObject Type
+               this.attributes = panelType.getAssociatedAttributes();
+               this.panelType = panelType;
+               this.orderedColumn = new ArrayList<String>();
+
+               // Create table model.
+               tableModel = makeModel();
+
+               attributeTable = new CyAttributeBrowserTable(tableModel, 
panelType);
+               attributeTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+       
+               // Toolbar for selecting attributes and create new attribute.
+               attributeBrowserToolBar = new 
AttributeBrowserToolBar(tableModel, attributeTable,
+                                                                     new 
AttributeModel(attributes, this), orderedColumn,
+                                                                     
panelType);
+
+               // the attribute table display: CytoPanel 2, horizontal SOUTH 
panel.
+               mainPanel = new JPanel();
+               mainPanel.setLayout(new BorderLayout());
+               mainPanel.setPreferredSize(PANEL_SIZE);
+               mainPanel.setBorder(null);
+
+               // If this is a network attribute browser, do not allow to swap
+               // column.
+               if (panelType == DataObjectType.NETWORK) {
+                       
attributeTable.getTableHeader().setReorderingAllowed(false);
+               }
+
+               attributeTable.getColumnModel().addColumnModelListener(this);
+               JScrollPane tp = new JScrollPane(attributeTable);
+               tp.addMouseListener(new MouseAdapter() {
+                       public void mouseClicked(MouseEvent e) {
+                               
getPropertyChangeSupport().firePropertyChange(AttributeBrowser.CLEAR_INTERNAL_SELECTION,
 null, panelType);
+                       }
+               });
+               mainPanel.setName(panelType.getDisplayName() + 
"AttributeBrowser");
+               mainPanel.add(tp, BorderLayout.CENTER);
+               mainPanel.add(attributeBrowserToolBar, BorderLayout.NORTH);
+
+               // 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);
+       }
+
+       void refresh() {
+               tableModel.setTableData(null, null);
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public CyAttributeBrowserTable getAttributeTable() {
+               return attributeTable;
+       }
+
+       static class Listener implements CytoPanelListener {
+               int WEST;
+               int SOUTH;
+               int EAST;
+               int myIndex;
+
+               Listener(int w, int s, int e, int my) {
+                       WEST = w;
+                       SOUTH = s;
+                       EAST = e;
+                       myIndex = my;
+               }
+
+               public void onComponentAdded(int count) {
+               }
+
+               public void onComponentRemoved(int count) {
+               }
+
+               public void onComponentSelected(int componentIndex) {
+                       if (componentIndex == myIndex) {
+                               if (WEST != -1) {
+                                       
Cytoscape.getDesktop().getCytoPanel(SwingConstants.WEST).setSelectedIndex(WEST);
+                               }
+
+                               if (SOUTH != -1) {
+                                       
Cytoscape.getDesktop().getCytoPanel(SwingConstants.SOUTH).setSelectedIndex(SOUTH);
+                               }
+
+                               if (EAST != -1) {
+                                       
Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST).setSelectedIndex(EAST);
+                               }
+                       }
+               }
+
+               public void onStateChange(CytoPanelState newState) {
+               }
+       }
+
+       
+       private DataTableModel makeModel() {
+               final List<String> attributeNames = 
CyAttributesUtils.getVisibleAttributeNames(attributes);
+               final List<CyTableEntry> graphObjects = 
getSelectedTableEntries();
+               final DataTableModel model = new DataTableModel(graphObjects, 
attributeNames, panelType);
+
+               return model;
+       }
+
+       private List<CyTableEntry> getSelectedTableEntries() {
+               if (panelType.equals(DataObjectType.NODES))
+                       return new 
ArrayList<CyTableEntry>(Cytoscape.getCurrentNetwork().getSelectedNodes());
+               else if (panelType.equals(DataObjectType.EDGES))
+                       return new 
ArrayList<CyTableEntry>(Cytoscape.getCurrentNetwork().getSelectedEdges());
+               
+               return null;
+       }
+
+       /**
+        *  Return selected items.
+        *
+        * @return  DOCUMENT ME!
+        */
+       public List<String> getSelectedAttributes() {
+               orderedColumn.clear();
+               for(int i=0; 
i<attributeTable.getColumnModel().getColumnCount(); i++) {
+                       
orderedColumn.add(attributeTable.getColumnModel().getColumn(i).getHeaderValue().toString());
+               }
+               return orderedColumn;
+       }
+       
+       public void setSelectedAttributes(List<String> selected) {
+               orderedColumn = selected;
+               attributeBrowserToolBar.updateList(selected);
+               tableModel.setTableData(null, orderedColumn);
+       }
+       
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param newModel DOCUMENT ME!
+        */
+       public void restoreColumnModel(TableColumnModel newModel) {
+               attributeTable.setColumnModel(newModel);
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @return  DOCUMENT ME!
+        */
+       public TableColumnModel getColumnModel() {
+               return attributeTable.getColumnModel();
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param e DOCUMENT ME!
+        */
+       public void columnAdded(TableColumnModelEvent e) {
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param e DOCUMENT ME!
+        */
+       public void columnMarginChanged(ChangeEvent e) {
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param e DOCUMENT ME!
+        */
+       public void columnMoved(TableColumnModelEvent e) {
+               // Ignore if same
+               if (e.getFromIndex() == e.getToIndex())
+                       return;
+
+               final int columnCount = attributeTable.getColumnCount();
+
+               //System.out.print("Ordered: " + e.getFromIndex() + " to " + 
e.getToIndex());
+               orderedColumn.clear();
+
+               for (int i = 0; i < columnCount; i++) {
+                       //System.out.print("[" + 
attributeTable.getColumnName(i) + "] ");
+                       orderedColumn.add(attributeTable.getColumnName(i));
+               }
+
+               //System.out.println("");
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param e DOCUMENT ME!
+        */
+       public void columnRemoved(TableColumnModelEvent e) {
+               // TODO Auto-generated method stub
+       }
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param e DOCUMENT ME!
+        */
+       public void columnSelectionChanged(ListSelectionEvent e) {
+               // TODO Auto-generated method stub
+       }
+}

Modified: 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/DataEditAction.java
===================================================================
--- 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/DataEditAction.java
     2010-12-06 21:13:35 UTC (rev 23097)
+++ 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/DataEditAction.java
     2010-12-06 21:33:46 UTC (rev 23098)
@@ -36,7 +36,7 @@
 import org.cytoscape.equations.LongList;
 import org.cytoscape.equations.StringList;
 import org.cytoscape.model.CyTable;
-import org.cytoscape.work.AbstractUndoableEdit;
+import org.cytoscape.work.undo.AbstractUndoableEdit;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -49,7 +49,7 @@
 /**
  * Validate and set new value to the CyAttributes.
  */
-public class DataEditAction extends org.cytoscape.work.AbstractUndoableEdit {
+public class DataEditAction extends AbstractUndoableEdit {
        private final String attrKey;
        private final String attrName;
        private final Object old_value;

Modified: 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/DataTableModel.java
===================================================================
--- 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/DataTableModel.java
     2010-12-06 21:13:35 UTC (rev 23097)
+++ 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/DataTableModel.java
     2010-12-06 21:33:46 UTC (rev 23098)
@@ -28,23 +28,15 @@
 package org.cytoscape.browser.internal;
 
 
-//import browser.ui.CyAttributeBrowserTable;
-
+import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyTable;
-
-import org.cytoscape.view.CyNetworkView;
+import org.cytoscape.model.CyTableEntry;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
 import org.cytoscape.work.undo.UndoSupport;
 
-import cytoscape.visual.GlobalAppearanceCalculator;
-
-import giny.model.Edge;
-import giny.model.GraphObject;
-import giny.model.Node;
-
-import giny.view.EdgeView;
-import giny.view.NodeView;
-
 import org.cytoscape.equations.Equation;
 
 import java.awt.Color;
@@ -80,13 +72,10 @@
        private final UndoSupport undoSupport;
 
        // Currently selected data objects
-       private List<GraphObject> graphObjects;
+       private List<CyTableEntry> graphObjects;
 
        // Ordered list of attribute names shown as column names.
        private List<String> attributeNames;
-       private final GlobalAppearanceCalculator gac = 
Cytoscape.getVisualMappingManager()
-                                                               
.getVisualStyle()
-                                                               
.getGlobalAppearanceCalculator();
 
        /*
         * Selected nodes & edges color
@@ -114,7 +103,7 @@
         * @param attributeNames  DOCUMENT ME!
         * @param type  DOCUMENT ME!
         */
-       public DataTableModel(final List<GraphObject> graph_objects, final 
List<String> attributeNames,
+       public DataTableModel(final List<CyTableEntry> graph_objects, final 
List<String> attributeNames,
                              final CyTable table, final UndoSupport 
undoSupport)
        {
                this.graphObjects = graph_objects;
@@ -157,12 +146,12 @@
 
                internalSelection = new HashMap<String, Boolean>();
 
-               NodeView nv;
-               EdgeView edgeView;
+               View<CyNode> nv;
+               View<CyEdge> edgeView;
                final CyNetworkView netView = Cytoscape.getCurrentNetworkView();
 
                if (Cytoscape.getCurrentNetworkView() != 
Cytoscape.getNullNetworkView()) {
-                       for (GraphObject obj : graphObjects) {
+                       for (CyTableEntry obj : graphObjects) {
                                internalSelection.put(obj.getIdentifier(), 
DEFAULT_FLAG);
                        }
                }
@@ -269,12 +258,7 @@
                        return null;
        }
 
-       /**
-        *  DOCUMENT ME!
-        *
-        * @return  DOCUMENT ME!
-        */
-       public List getGraphObjects() {
+       public List<CyTableEntry> getGraphObjects() {
                return graphObjects;
        }
 

Copied: 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/SortTableModel.java
 (from rev 23085, 
cytoscape/trunk/coreplugins/browser/src/main/java/browser/SortTableModel.java)
===================================================================
--- 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/SortTableModel.java
                             (rev 0)
+++ 
core3/table-browser-impl/trunk/src/main/java/org/cytoscape/browser/internal/SortTableModel.java
     2010-12-06 21:33:46 UTC (rev 23098)
@@ -0,0 +1,21 @@
+/*
+=====================================================================
+
+  SortTableModel.java
+
+  Created by Claude Duguay
+  Copyright (c) 2002
+
+=====================================================================
+*/
+package org.cytoscape.browser.internal;
+
+
+import javax.swing.table.TableModel;
+
+
+public interface SortTableModel extends TableModel {
+       public boolean isSortable(int col);
+
+       public void sortColumn(int col, boolean ascending);
+}

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