perfsonar-dev - perfsonar: r2978 - in branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa: . components
Subject: perfsonar development work
List archive
perfsonar: r2978 - in branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa: . components
Chronological Thread
- From:
- To:
- Subject: perfsonar: r2978 - in branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa: . components
- Date: Sat, 20 Oct 2007 05:04:26 -0400
Author: michael.bischoff
Date: 2007-10-20 05:04:26 -0400 (Sat, 20 Oct 2007)
New Revision: 2978
Added:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/components/ResultTable.java
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowsaMAResponse.java
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/components/ResultPanel.java
Log:
refactor of resultTable
removed xmlns from result
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowsaMAResponse.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowsaMAResponse.java
2007-10-19 14:35:05 UTC (rev 2977)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/FlowsaMAResponse.java
2007-10-20 09:04:26 UTC (rev 2978)
@@ -7,6 +7,14 @@
package org.perfsonar.perfsonarui.flowsa;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
import org.perfsonar.perfsonarui.AbstractPerfsonarResponse;
import org.perfsonar.perfsonarui.AbstractUserData;
import org.perfsonar.perfsonarui.PerfsonarResponseEvent;
@@ -69,26 +77,9 @@
}
private void handleTopResponse(NodeList datums) {
- Node datum;
- String[] header = null;
- String[][] data = null;
- for(int row =0;(datum = datums.item(row)) != null; row++) {
- NamedNodeMap attributes = datum.getAttributes();
- if(header==null || data==null) {
- header = new String[attributes.getLength()];
- data = new
String[datums.getLength()][attributes.getLength()];
- Node attribute;
- for(int column = 0;(attribute =
attributes.item(column)) != null;column++) {
- header[column] =
attribute.getNodeName();
- data[row][column] =
attribute.getNodeValue();
- }
- } else {
- Node attribute;
- for(int column = 0;(attribute =
attributes.item(column)) != null;column++) {
- data[row][column] =
attribute.getNodeValue();
- }
- }
- }
+ List<String> headerList = getHeader(datums);
+ String[][] data = extractData(datums, headerList);
+ String[] header = stripNullValues(headerList);
userData.pushQuery(new Query(new Question("Top query"), new
TopData(header, data)));
}
@@ -125,29 +116,67 @@
}
private void handleRawResponse(NodeList datums) {
- Node datum;
- String[] header = null;
- String[][] data = null;
- for(int row =0;(datum = datums.item(row)) != null; row++) {
- NamedNodeMap attributes = datum.getAttributes();
- if(header==null || data==null) {
- header = new String[attributes.getLength()];
- data = new
String[datums.getLength()][attributes.getLength()];
- Node attribute;
- for(int column = 0;(attribute =
attributes.item(column)) != null;column++) {
- header[column] =
attribute.getNodeName();
- data[row][column] =
attribute.getNodeValue();
- }
- } else {
- Node attribute;
- for(int column = 0;(attribute =
attributes.item(column)) != null;column++) {
- data[row][column] =
attribute.getNodeValue();
- }
- }
- }
- userData.pushQuery(new Query(new Question("Raw query"), new
FlowData(header, data)));
+ List<String> headerList = getHeader(datums);
+ String[][] data = extractData(datums, headerList);
+ String[] header = stripNullValues(headerList);
+ userData.pushQuery(new Query(new Question("Raw query"), new
FlowData(header, data)));
}
+ private String[] stripNullValues(List<String> headerList) {
+ for(Iterator<String> iterator =
headerList.iterator();iterator.hasNext();) {
+ if(iterator.next()==null) {
+ iterator.remove();
+ }
+ }
+ return headerList.toArray(new String[headerList.size()]);
+ }
+
+ private String[][] extractData(NodeList datums, List<String> headerList)
{
+ String[][] data =null;
+ Node datum;
+ for(int row =0;(datum = datums.item(row)) != null; row++) {
+ NamedNodeMap attributes = datum.getAttributes();
+ if(data==null) {
+ data = new String[datums.getLength()][attributes.getLength()
- countNullEntries(headerList)];
+ }
+ Node attribute;
+ int column = 0;
+ for(int i = 0;(attribute = attributes.item(i)) != null;i++) {
+ if(headerList.get(i)!=null) {
+ data[row][column] = attribute.getNodeValue();
+ column++;
+ }
+ }
+ }
+ return data;
+ }
+
+ private int countNullEntries(Collection<? extends Object> list) {
+ int i = 0;
+ for(Object entry : list) {
+ if(entry==null) i++;
+ }
+ return i;
+ }
+
+ private List<String> getHeader(NodeList datums) {
+ ArrayList<String> header = new ArrayList<String>(20);
+ Node datum;
+ if((datum = datums.item(0)) != null) {
+ NamedNodeMap attributes = datum.getAttributes();
+ Node attribute;
+ for(int column = 0;(attribute = attributes.item(column)) !=
null;column++) {
+ String value = attribute.getNodeName();
+ if(value.startsWith("xmlns")) {
+ value = null;
+ }
+ header.add(value);
+ }
+ }
+ header.trimToSize();
+ return header;
+ }
+
private String getAttribute(NamedNodeMap attributes, String name) {
Node value = attributes.getNamedItem(name);
return value==null ? null : value.getNodeValue();
Modified:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/components/ResultPanel.java
===================================================================
---
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/components/ResultPanel.java
2007-10-19 14:35:05 UTC (rev 2977)
+++
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/components/ResultPanel.java
2007-10-20 09:04:26 UTC (rev 2978)
@@ -93,14 +93,14 @@
public static class ResultDisplay extends JScrollPane implements
Observer {
private static final long serialVersionUID = 1L;
- private JTable table;
+ private ResultTable table;
private StatisticsPanel panel;
private FlowsaMAUserData model;
public ResultDisplay(FlowsaMAUserData model) {
this.model = model;
model.addObserver(this);
- table = new JTable(new Object[][] {}, new Object[]
{"No results yet."});
+ table = new ResultTable("No results yet.");
panel = new StatisticsPanel();
setViewportView(table);
}
@@ -115,59 +115,11 @@
revalidate();
} else if(current.getResult() instanceof TopData) {
final TopData data = (TopData) current.getResult();
- table.setModel(new AbstractTableModel() {
-
- private static final
long serialVersionUID = 1L;
-
- @Override
- public String getColumnName(int column) {
- if(data.getHeader().length == 0) {
- return "No results to display.";
- }
- return data.getHeader()[column];
- }
-
- public int getColumnCount() {
- return data.getHeader().length != 0 ?
data.getHeader().length : 1;
- }
-
- public int getRowCount() {
- return data.getData()==null ? 0 :
data.getData().length;
- }
-
- public Object getValueAt(int rowIndex, int
columnIndex) {
- return data.getData()[rowIndex][columnIndex];
- }
-
- });
+ table.setModel(data);
setViewportView(table);
} else if(current.getResult() instanceof FlowData) {
final FlowData data = (FlowData) current.getResult();
- table.setModel(new AbstractTableModel() {
-
- private static final
long serialVersionUID = 1L;
-
- @Override
- public String getColumnName(int column) {
- if(data.getHeader().length == 0) {
- return "No results to display.";
- }
- return data.getHeader()[column];
- }
-
- public int getColumnCount() {
- return data.getHeader().length != 0 ?
data.getHeader().length : 1;
- }
-
- public int getRowCount() {
- return data.getData()==null ? 0 :
data.getData().length;
- }
-
- public Object getValueAt(int rowIndex, int
columnIndex) {
- return data.getData()[rowIndex][columnIndex];
- }
-
- });
+ table.setModel(data);
setViewportView(table);
}
}
Added:
branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa/components/ResultTable.java
- perfsonar: r2978 - in branches/perfsonarui/src/org/perfsonar/perfsonarui/flowsa: . components, svnlog, 10/20/2007
Archive powered by MHonArc 2.6.16.