Object list = app.find("resultsList");
Object row = app.getSelectedItem(list);
if (row == null) {
return;
}
AttributeSource as = (AttributeSource)app.getProperty(row, "state");
if (as == null) {
return;
}
Iterator it = as.getAttributeClassesIterator();
while (it.hasNext()) {
Class cl = (Class)it.next();
String attClass = cl.getName();
if (attClass.startsWith("org.apache.lucene.")) {
attClass = cl.getSimpleName();
}
Attribute att = as.getAttribute(cl);
String implClass = att.getClass().getName();
if (implClass.startsWith("org.apache.lucene.")) {
implClass = att.getClass().getSimpleName();
}
Object r = app.create("row");
Object cell = app.create("cell");
app.add(table, r);
app.add(r, cell);
app.setString(cell, "text", attClass);
cell = app.create("cell");
app.add(r, cell);
app.setString(cell, "text", implClass);
cell = app.create("cell");
app.add(r, cell);
String val = null;
if (attClass.equals("CharTermAttribute")) {
val = ((CharTermAttribute)att).toString();
} else if (attClass.equals("FlagsAttribute")) {
val = Integer.toHexString(((FlagsAttribute)att).getFlags());
} else if (attClass.equals("OffsetAttribute")) {
OffsetAttribute off = (OffsetAttribute)att;
val = off.startOffset() + "-" + off.endOffset();
} else if (attClass.equals("PayloadAttribute")) {
BytesRef payload = ((PayloadAttribute)att).getPayload();
if (payload != null) {
val = Util.bytesToHex(payload.bytes, payload.offset, payload.length, false);
} else {
val = "";
}
} else if (attClass.equals("PositionIncrementAttribute")) {
val = ((PositionIncrementAttribute)att).getPositionIncrement() + "";
} else if (attClass.equals("TypeAttribute")) {
val = ((TypeAttribute)att).type();
} else if (attClass.equals("KeywordAttribute")) {
val = Boolean.toString(((KeywordAttribute)att).isKeyword());
} else {
val = att.toString();
}
app.setString(cell, "text", val);
}
Object inputText = app.find(myUi, "inputText");
if (as.hasAttribute(OffsetAttribute.class)) {
OffsetAttribute off = (OffsetAttribute)as.getAttribute(OffsetAttribute.class);
app.setInteger(inputText, "start", 0);
app.setInteger(inputText, "end", off.endOffset());
app.setInteger(inputText, "start", off.startOffset());
app.requestFocus(inputText);
}