assert (cell != null);
final JPopupMenu menu = new JPopupMenu();
menu.add(new AbstractAction("Show InferredType") {
public void actionPerformed(ActionEvent e) {
String selected = (String) cell.getUserObject();
XQExpression expr = sourceExprMap.get(selected);
Type type = expr.getType();
JOptionPane.showMessageDialog(frame, (type == null) ? "nil" : type);
}
});
menu.add(new AbstractAction("Eval Expression") {
public void actionPerformed(ActionEvent e) {
String selected = (String) cell.getUserObject();
XQExpression expr = sourceExprMap.get(selected);
DynamicContext dynEnv = new DynamicContext(statEnv);
StringWriter sw = new StringWriter();
SAXSerializer ser = new SAXSerializer(new SAXWriter(sw), sw);
try {
expr.evalAsEvents(ser, ValueSequence.EMPTY_SEQUENCE, dynEnv);
} catch (Exception ex) {
JOptionPane.showMessageDialog(frame, "eval failed!: " + ex.getMessage());
ex.printStackTrace();
return;
}
JOptionPane.showMessageDialog(frame, sw.toString());
}
});
menu.add(new AbstractAction("Eval Expression (pull)") {
public void actionPerformed(ActionEvent e) {
String selected = (String) cell.getUserObject();
XQExpression expr = sourceExprMap.get(selected);
DynamicContext dynEnv = new DynamicContext(statEnv);
final Sequence result;
try {
result = expr.eval(ValueSequence.EMPTY_SEQUENCE, dynEnv);
} catch (Exception ex) {
JOptionPane.showMessageDialog(frame, "eval failed!: " + ex.getMessage());
ex.printStackTrace();
return;
}
JOptionPane.showMessageDialog(frame, result.toString());
}
});
menu.add(new AbstractAction("Print Tree") {
public void actionPerformed(ActionEvent e) {
String selected = (String) cell.getUserObject();
XQExpression expr = sourceExprMap.get(selected);
String s = expr.toString();
JOptionPane.showMessageDialog(frame, (expr == null) ? selected : s);
System.out.println(s);
System.out.println();
}
});