this.setLayout(new BorderLayout());
}
private JTable createTable(final ViewState state) {
JTable table = null;
final ModelGraph selected = state.getSelected();
if (selected != null) {
final Vector<Vector<String>> rows = new Vector<Vector<String>>();
HashMap<String, String> keyToGroupMap = new HashMap<String, String>();
Metadata staticMet = selected.getModel().getStaticMetadata();
Metadata inheritedMet = selected.getInheritedStaticMetadata(state);
Metadata completeMet = new Metadata();
if (staticMet != null) {
completeMet.replaceMetadata(staticMet.getSubMetadata(state
.getCurrentMetGroup()));
}
if (selected.getModel().getExtendsConfig() != null) {
for (String configGroup : selected.getModel().getExtendsConfig()) {
Metadata extendsMetadata = state.getGlobalConfigGroups()
.get(configGroup).getMetadata()
.getSubMetadata(state.getCurrentMetGroup());
for (String key : extendsMetadata.getAllKeys()) {
if (!completeMet.containsKey(key)) {
keyToGroupMap.put(key, configGroup);
completeMet.replaceMetadata(key,
extendsMetadata.getAllMetadata(key));
}
}
}
}
if (inheritedMet != null) {
Metadata inheritedMetadata = inheritedMet.getSubMetadata(state
.getCurrentMetGroup());
for (String key : inheritedMetadata.getAllKeys()) {
if (!completeMet.containsKey(key)) {
keyToGroupMap.put(key, "__inherited__");
completeMet.replaceMetadata(key,
inheritedMetadata.getAllMetadata(key));
}
}
}
List<String> keys = completeMet.getAllKeys();
Collections.sort(keys);
for (String key : keys) {
if (key.endsWith("/envReplace"))
continue;
String values = StringUtils.join(completeMet.getAllMetadata(key), ",");
Vector<String> row = new Vector<String>();
row.add(keyToGroupMap.get(key));
row.add(key);
row.add(values);
row.add(Boolean.toString(Boolean.parseBoolean(completeMet
.getMetadata(key + "/envReplace"))));
rows.add(row);
}
table = new JTable();// rows, new Vector<String>(Arrays.asList(new
// String[] { "key", "values", "envReplace" })));
table.setModel(new AbstractTableModel() {
public String getColumnName(int col) {
switch (col) {
case 0:
return "group";
case 1:
return "key";
case 2:
return "values";
case 3:
return "envReplace";
default:
return null;
}
}
public int getRowCount() {
return rows.size() + 1;
}
public int getColumnCount() {
return 4;
}
public Object getValueAt(int row, int col) {
if (row >= rows.size())
return null;
String value = rows.get(row).get(col);
if (value == null && col == 3)
return "false";
if (value == null && col == 0)
return "__local__";
return value;
}
public boolean isCellEditable(int row, int col) {
if (row >= rows.size()) {
if (selected.getModel().getStaticMetadata()
.containsGroup(state.getCurrentMetGroup()))
return true;
else
return false;
}
if (col == 0)
return false;
String key = rows.get(row).get(1);
if (key == null
|| (selected.getModel().getStaticMetadata() != null && selected
.getModel().getStaticMetadata()
.containsKey(getKey(key, state))))
return true;
return false;
}