summaryrefslogtreecommitdiff
path: root/source/com/c2kernel/graph/view/PropertyTableModel.java
diff options
context:
space:
mode:
authorabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
committerabranson <andrew.branson@cern.ch>2011-08-04 00:42:34 +0200
commit0ec8481c10cd8277d84c7c1a785483a0a739e5a0 (patch)
tree5f6e5d9ae75193e67e6f3b3dfa488960c5cde1d5 /source/com/c2kernel/graph/view/PropertyTableModel.java
parent036cbdba66f804743c4c838ed598d6972c4b3e17 (diff)
More code cleanup:
Refactored Entity Proxy Subscription to handle generics better Rewrote RemoteMap to use TreeMap instead of the internal array for order. It now sorts its keys by number if they parse, else as strings. Removed a no-longer-in-progress outcome form class
Diffstat (limited to 'source/com/c2kernel/graph/view/PropertyTableModel.java')
-rw-r--r--source/com/c2kernel/graph/view/PropertyTableModel.java46
1 files changed, 28 insertions, 18 deletions
diff --git a/source/com/c2kernel/graph/view/PropertyTableModel.java b/source/com/c2kernel/graph/view/PropertyTableModel.java
index 22ba4f3..b1e69b1 100644
--- a/source/com/c2kernel/graph/view/PropertyTableModel.java
+++ b/source/com/c2kernel/graph/view/PropertyTableModel.java
@@ -1,6 +1,9 @@
package com.c2kernel.graph.view;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
import javax.swing.JOptionPane;
import javax.swing.event.TableModelEvent;
@@ -23,26 +26,30 @@ public class PropertyTableModel extends AbstractTableModel {
HashMap<String, Object> sourceMap = new HashMap<String, Object>();
ArrayList<String> sortedNameList = new ArrayList<String>();
boolean isEditable = false;
-
+
public PropertyTableModel() {
super();
}
- public int getColumnCount()
+ @Override
+ public int getColumnCount()
{
return mColumnNames.length;
}
- public String getColumnName(int col)
+ @Override
+ public String getColumnName(int col)
{
return mColumnNames[col];
}
- public int getRowCount()
+ @Override
+ public int getRowCount()
{
synchronized (sourceMap) {
return sourceMap.size();
}
}
- public Object getValueAt(int rowIndex, int colIndex)
+ @Override
+ public Object getValueAt(int rowIndex, int colIndex)
{
synchronized (sourceMap) {
String rowName = sortedNameList.get(rowIndex);
@@ -52,18 +59,19 @@ public class PropertyTableModel extends AbstractTableModel {
return sourceMap.get(rowName);
}
}
-
- public void setValueAt(Object value, int rowIndex, int colIndex)
+
+ @Override
+ public void setValueAt(Object value, int rowIndex, int colIndex)
{
synchronized (sourceMap) {
if (colIndex == 0) return;
String rowName = sortedNameList.get(rowIndex);
- Class oldElement = sourceMap.get(rowName).getClass();
+ Class<? extends Object> oldElement = sourceMap.get(rowName).getClass();
if (oldElement == Float.class && value.getClass() == String.class)
try {
value = Float.valueOf((String)value);
} catch (Exception ex) { }
- if (value.getClass() != oldElement)
+ if (value.getClass() != oldElement)
JOptionPane.showMessageDialog(null, "This property should contain a "+oldElement.getName()+" not a "+value.getClass().getName(), "Incorrect datatype", JOptionPane.ERROR_MESSAGE);
else {
sourceMap.put(rowName, value);
@@ -71,24 +79,26 @@ public class PropertyTableModel extends AbstractTableModel {
}
}
}
-
+
public void setMap(HashMap<String, Object> props) {
synchronized (sourceMap) {
sourceMap = props;
sortedNameList = new ArrayList<String>(props.size());
- for (Iterator<String> keys = props.keySet().iterator(); keys.hasNext();)
- sortedNameList.add(keys.next());
-
+ for (String string : props.keySet())
+ sortedNameList.add(string);
+
Collections.sort(sortedNameList, new Comparator<String>() {
- public int compare(String o1, String o2) {
+ @Override
+ public int compare(String o1, String o2) {
return (o1.compareToIgnoreCase(o2));
}
});
}
fireTableChanged(new TableModelEvent(this));
}
-
- public boolean isCellEditable(int row, int col)
+
+ @Override
+ public boolean isCellEditable(int row, int col)
{
return col==1 && isEditable;
}
@@ -112,7 +122,7 @@ public class PropertyTableModel extends AbstractTableModel {
*/
public void addProperty(String text, Object object) {
sourceMap.put(text,object);
- setMap(sourceMap);
+ setMap(sourceMap);
}
/**