Search in sources :

Example 1 with BranchEvent

use of com.ramussoft.common.event.BranchEvent in project ramus by Vitaliy-Yakovchuk.

the class JournaledEngine method setActiveBranch.

@Override
public void setActiveBranch(long branchId) {
    deligate.setActiveBranch(branchId);
    branchId = deligate.getActiveBranch();
    synchronized (swithJournalLock) {
        journal = journalFactory.getJournal(this, branchId);
    }
    BranchEvent event = new BranchEvent(this, false, branchId, -1l);
    for (BranchListener listener : getBranchListeners()) listener.branchActivated(event);
}
Also used : BranchListener(com.ramussoft.common.event.BranchListener) BranchEvent(com.ramussoft.common.event.BranchEvent)

Example 2 with BranchEvent

use of com.ramussoft.common.event.BranchEvent 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);
}
Also used : JScrollPane(javax.swing.JScrollPane) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionChangeEvent(com.ramussoft.gui.common.event.ActionChangeEvent) BranchEvent(com.ramussoft.common.event.BranchEvent) TreeNode(javax.swing.tree.TreeNode) TreeTableNode(org.jdesktop.swingx.treetable.TreeTableNode) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionChangeListener(com.ramussoft.gui.common.event.ActionChangeListener) BranchAdapter(com.ramussoft.common.event.BranchAdapter)

Example 3 with BranchEvent

use of com.ramussoft.common.event.BranchEvent in project ramus by Vitaliy-Yakovchuk.

the class JournaledEngine method deleteBranch.

@Override
public void deleteBranch(long branchId) {
    BranchEvent event = new BranchEvent(this, false, branchId, -1l);
    long active = getActiveBranch();
    deligate.deleteBranch(branchId);
    for (BranchListener listener : getBranchListeners()) listener.branchDeleted(event);
    if (active == branchId) {
        event = new BranchEvent(this, false, getActiveBranch(), -1l);
        for (BranchListener listener : getBranchListeners()) listener.branchActivated(event);
    }
}
Also used : BranchListener(com.ramussoft.common.event.BranchListener) BranchEvent(com.ramussoft.common.event.BranchEvent)

Example 4 with BranchEvent

use of com.ramussoft.common.event.BranchEvent in project ramus by Vitaliy-Yakovchuk.

the class JournaledEngine method createBranch.

@Override
public void createBranch(long parent, long branchId, String reason, int type, String module) {
    if (parent == -1l)
        parent = getActiveBranch();
    deligate.createBranch(parent, branchId, reason, type, module);
    synchronized (swithJournalLock) {
        Journal parentBranchJournal = journalFactory.getJournal(this, parent);
        parentBranchJournal.store(new NewBranchCommand(this, parent, branchId, reason, type, module));
        // parentBranchJournal.setLock(true);
        journal = journalFactory.getJournal(this, branchId);
    }
    BranchEvent event = new BranchEvent(this, false, branchId, parent);
    for (BranchListener listener : getBranchListeners()) listener.branchCreated(event);
    for (BranchListener listener : getBranchListeners()) listener.branchActivated(event);
}
Also used : BranchListener(com.ramussoft.common.event.BranchListener) BranchEvent(com.ramussoft.common.event.BranchEvent) NewBranchCommand(com.ramussoft.common.journal.command.NewBranchCommand)

Aggregations

BranchEvent (com.ramussoft.common.event.BranchEvent)4 BranchListener (com.ramussoft.common.event.BranchListener)3 BranchAdapter (com.ramussoft.common.event.BranchAdapter)1 NewBranchCommand (com.ramussoft.common.journal.command.NewBranchCommand)1 ActionChangeEvent (com.ramussoft.gui.common.event.ActionChangeEvent)1 ActionChangeListener (com.ramussoft.gui.common.event.ActionChangeListener)1 AbstractAction (javax.swing.AbstractAction)1 Action (javax.swing.Action)1 JScrollPane (javax.swing.JScrollPane)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 TreeNode (javax.swing.tree.TreeNode)1 TreeTableNode (org.jdesktop.swingx.treetable.TreeTableNode)1