use of com.ramussoft.gui.common.event.ActionChangeListener in project ramus by Vitaliy-Yakovchuk.
the class BranchView method createComponent.
@Override
public JComponent createComponent() {
this.branchModel = new BranchModel(createRoot(engine.getRootBranch()));
this.table = new BranchTreeTable(branchModel, this);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
boolean b = table.getSelectedRow() >= 0;
Node node = null;
if (b) {
node = (Node) table.getPathForRow(table.getSelectedRow()).getLastPathComponent();
if (node.branch.getChildren().size() > 0)
addChildBranch.setEnabled(false);
else
// addChildBranch.putValue(Action.SMALL_ICON,
// branchTree);
addChildBranch.setEnabled(true);
// addChildBranch.putValue(Action.SMALL_ICON,
// branch);
ActionChangeEvent event = new ActionChangeEvent(new Action[] { addChildBranch, editCommment });
for (ActionChangeListener l : getActionChangeListeners()) l.actionsRemoved(event);
for (ActionChangeListener l : getActionChangeListeners()) l.actionsAdded(event);
} else
addChildBranch.setEnabled(false);
activateBranch.setEnabled(b && node.branch.getBranchId() != actualBranch);
editCommment.setEnabled(b && node.parent != null);
}
});
table.setRootVisible(true);
branchListener = new BranchAdapter() {
@Override
public void branchDeleted(BranchEvent event) {
branchModel.setRoot(createRoot(engine.getRootBranch()));
}
@Override
public void branchCreated(final BranchEvent event) {
branchModel.setRoot(createRoot(engine.getRootBranch()));
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
table.expandAll();
for (int i = 0; i < table.getRowCount(); i++) {
Node n = (Node) table.getPathForRow(i).getLastPathComponent();
if (n.branch.getBranchId() == event.getBranchId()) {
table.getSelectionModel().addSelectionInterval(i, i);
break;
}
}
}
});
}
@Override
public void branchActivated(BranchEvent event) {
framework.propertyChanged(Commands.FULL_REFRESH);
actualBranch = event.getBranchId();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
table.repaint();
}
});
}
};
engine.addBranchListener(branchListener);
table.expandAll();
actualBranch = engine.getActiveBranch();
return new JScrollPane(table);
}
Aggregations