Example usage for javax.swing SwingWorker getPropertyChangeSupport

List of usage examples for javax.swing SwingWorker getPropertyChangeSupport

Introduction

In this page you can find the example usage for javax.swing SwingWorker getPropertyChangeSupport.

Prototype

public final PropertyChangeSupport getPropertyChangeSupport() 

Source Link

Document

Returns the PropertyChangeSupport for this SwingWorker .

Usage

From source file:Main.java

public void loadChildren(final DefaultTreeModel model, final PropertyChangeListener progressListener) {
    if (loaded) {
        return;/*from  w  ww . j ava  2 s . c  o  m*/
    }
    SwingWorker<List<MyTreeNode>, Void> worker = new SwingWorker<List<MyTreeNode>, Void>() {
        @Override
        protected List<MyTreeNode> doInBackground() throws Exception {
            setProgress(0);
            List<MyTreeNode> children = new ArrayList<MyTreeNode>();
            if (depth < 5) {
                for (int i = 0; i < 5; i++) {
                    Thread.sleep(300);
                    children.add(new MyTreeNode(i + 1, depth + 1));
                    setProgress((i + 1) * 20);
                }
            } else {
                Thread.sleep(1000);
            }
            setProgress(0);
            return children;
        }

        @Override
        protected void done() {
            try {
                setChildren(get());
                model.nodeStructureChanged(MyTreeNode.this);
            } catch (Exception e) {
                e.printStackTrace();
            }
            super.done();
        }
    };
    if (progressListener != null) {
        worker.getPropertyChangeSupport().addPropertyChangeListener("progress", progressListener);
    }
    worker.execute();
}