@SuppressWarnings("unchecked")
public SyntaxEditorInfoTable(final JTextComponent editor) {
super(null);
final GroupingTreeTableModel ttModel =
new GroupingTreeTableModel(tableModel =
new InfoProviderTableModel(Collections.EMPTY_LIST), 0) {
@Override
protected Object getValueForGroup(Object groupingObject,
int columnIndex) {
if (columnIndex == 1) {
return String.format("(%d) Elements",
this.getElementCountInGroup(groupingObject));
}
return super.getValueForGroup(groupingObject, columnIndex);
}
};
super.setTreeTableModel(ttModel);
// set dimensions of table columns
getColumnModel().getColumn(0).setWidth(45);
getColumnModel().getColumn(0).setMaxWidth(45);
getColumnModel().getColumn(0).setMinWidth(45);
getColumnModel().getColumn(0).setCellRenderer(new IconAwareCellRenderer());
getTableHeader().setReorderingAllowed(false);
// react on double click on table item -> select area in editor
// specified by token
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
int row = ttModel.getRowForNode(getNode(getSelectedRow()));
if (row >= 0) {
ILexerToken token = tableModel.getTokenAt(row);
editor.select(token.getStart(), token.getEnd());
editor.requestFocus();
}
e.consume();
}
}
});
// react on left click on specific information entries with
// information actions
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
mouseReleased(e);
}
@Override
public void mouseReleased(MouseEvent event) {
if (event.isPopupTrigger()) {
// get token at triggered location
int row = ttModel.getRowForNode(getNode(getSelectedRow()));
if (row >= 0) {
ILexerToken token = tableModel.getTokenAt(row);
// get provider for token
IInfoProvider provider = tableModel.getInfoProviderForToken(token);