private void initialize(final JTable table) {
formatAndRoutesModel.addListDataListener(new ListDataListener() {
public void intervalAdded(ListDataEvent e) {
for (int i = e.getIndex0(); i <= e.getIndex1(); i++) {
BaseRoute route = formatAndRoutesModel.getRoute(i);
JMenuItem menuItem = new JMenuItem(new MergePositionListAction(table, route, formatAndRoutesModel));
menuItem.setText(shortenRouteName(route));
menu.add(menuItem, i);
}
menu.setEnabled(formatAndRoutesModel.getSize() > 1);
}
public void intervalRemoved(ListDataEvent e) {
for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
JMenuItem menuItem = i < menu.getMenuComponentCount() ? (JMenuItem) menu.getMenuComponent(i) : null;
if (menuItem != null) {
MergePositionListAction action = (MergePositionListAction) menuItem.getAction();
action.dispose();
menuItem.setAction(null);
}
menu.remove(i);
}
menu.setEnabled(formatAndRoutesModel.getSize() > 1);
}
public void contentsChanged(ListDataEvent e) {
for (int i = e.getIndex0(); i <= e.getIndex1(); i++) {
if (i >= 0 && i < menu.getMenuComponentCount()) {
BaseRoute route = formatAndRoutesModel.getRoute(i);
JMenuItem menuItem = (JMenuItem) menu.getMenuComponent(i);
menuItem.setText(shortenRouteName(route));
}
}
}