public BrowsePanel() {
initialize();
}
private void initialize() {
final RouteConverter r = RouteConverter.getInstance();
CategoryTreeNode localRoot = new CategoryTreeNodeImpl(localCatalog.getRootCategory(), true, false);
final CategoryTreeNodeImpl remoteRoot = new CategoryTreeNodeImpl(remoteCatalog.getRootCategory(), false, true);
final RootTreeNode root = new RootTreeNode(localRoot, remoteRoot);
catalogModel = new UndoCatalogModel(r.getContext().getUndoManager(), root, getOperator());
final ActionManager actionManager = r.getContext().getActionManager();
registerAction(buttonAddCategory, "add-category");
registerAction(buttonRenameCategory, "rename-category");
registerAction(buttonRemoveCategory, "remove-category");
registerAction(buttonAddRouteFromFile, "add-route-from-file");
registerAction(buttonAddRouteFromUrl, "add-route-from-url");
registerAction(buttonRenameRoute, "rename-route");
registerAction(buttonRemoveRoute, "remove-route");
actionManager.register("add-category", new AddCategoryAction(treeCategories, catalogModel));
actionManager.register("add-route-from-file", new AddFileAction());
actionManager.register("add-route-from-url", new AddUrlAction());
actionManager.register("rename-category", new RenameCategoryAction(treeCategories, catalogModel));
actionManager.register("remove-category", new RemoveCategoriesAction(treeCategories, catalogModel));
actionManager.register("rename-route", new RenameRouteAction(tableRoutes, catalogModel));
actionManager.register("remove-route", new RemoveRoutesAction(tableRoutes, catalogModel));
buttonLogin.addActionListener(new FrameAction() {
public void run() {
getOperator().showLogin();
}
});
treeCategories.setModel(catalogModel.getCategoryTreeModel());
treeCategories.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
selectTreePath(e.getPath(), false);
}
});
treeCategories.getModel().addTreeModelListener(new TreeModelListener() {
public void treeNodesChanged(TreeModelEvent e) {
selectTreePath(treeCategories.getSelectionModel().getSelectionPath(), true);
}
public void treeNodesInserted(TreeModelEvent e) {
}
public void treeNodesRemoved(TreeModelEvent e) {
}
public void treeStructureChanged(TreeModelEvent e) {
}
});
treeCategories.setCellRenderer(new CategoryTreeCellRenderer());
treeCategories.setDragEnabled(true);
treeCategories.setDropMode(ON);
treeCategories.setTransferHandler(new TreeDragAndDropHandler());
treeCategories.getSelectionModel().setSelectionMode(CONTIGUOUS_TREE_SELECTION);
tableRoutes.setModel(catalogModel.getRoutesTableModel());
tableRoutes.setDefaultRenderer(Object.class, new RoutesTableCellRenderer());
tableRoutes.registerKeyboardAction(new FrameAction() {
public void run() {
actionManager.run("remove-route");
}
}, getKeyStroke(VK_DELETE, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
tableRoutes.registerKeyboardAction(new FrameAction() {
public void run() {
selectAndScrollToPosition(tableRoutes, 0, 0);
}
}, getKeyStroke(VK_HOME, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
tableRoutes.registerKeyboardAction(new FrameAction() {
public void run() {
selectAndScrollToPosition(tableRoutes, 0, tableRoutes.getSelectedRow());
}
}, getKeyStroke(VK_HOME, SHIFT_DOWN_MASK), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
tableRoutes.registerKeyboardAction(new FrameAction() {
public void run() {
int lastRow = tableRoutes.getRowCount() - 1;
selectAndScrollToPosition(tableRoutes, lastRow, lastRow);
}
}, getKeyStroke(VK_END, 0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
tableRoutes.registerKeyboardAction(new FrameAction() {
public void run() {
selectAndScrollToPosition(tableRoutes, tableRoutes.getRowCount() - 1, tableRoutes.getSelectedRow());
}
}, getKeyStroke(VK_END, SHIFT_DOWN_MASK), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
tableRoutes.setDragEnabled(true);
tableRoutes.setTransferHandler(new TableDragHandler());
tableRoutes.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
handlePositionListUpdate();
}
});
TableCellRenderer headerRenderer = new SimpleHeaderRenderer("description", "creator");
TableColumnModel columns = tableRoutes.getColumnModel();
for (int i = 0; i < columns.getColumnCount(); i++) {
TableColumn column = columns.getColumn(i);
column.setHeaderRenderer(headerRenderer);
if (i == 1) {
column.setPreferredWidth(80);
column.setMaxWidth(100);
}
}
browsePanel.setTransferHandler(new PanelDropHandler());
new Thread(new Runnable() {
public void run() {
// do the loading in a separate thread since treeCategories.setModel(categoryTreeModel)
// would do it in the AWT EventQueue
catalogModel.getCategoryTreeModel().getChildCount(remoteRoot);
invokeLater(new Runnable() {
public void run() {
startWaitCursor(r.getFrame().getRootPane());
try {
String selected = r.getCategoryPreference();
selectTreePath(TreePathStringConversion.fromString(root, selected), true);
// make sure the subcategories of the remote catalog are visible, too
treeCategories.expandPath(new TreePath(new Object[]{root, remoteRoot}));
} finally {
stopWaitCursor(r.getFrame().getRootPane());
}
}
});
}
}, "CategoryTreeInitializer").start();