OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 151 | Rev 177 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 151 Rev 156
Line 36... Line 36...
36
import org.openconcerto.utils.cc.IPredicate;
36
import org.openconcerto.utils.cc.IPredicate;
37
 
37
 
38
import java.beans.PropertyChangeEvent;
38
import java.beans.PropertyChangeEvent;
39
import java.beans.PropertyChangeListener;
39
import java.beans.PropertyChangeListener;
40
import java.beans.PropertyChangeSupport;
40
import java.beans.PropertyChangeSupport;
-
 
41
import java.lang.Thread.UncaughtExceptionHandler;
41
import java.util.ArrayList;
42
import java.util.ArrayList;
42
import java.util.Collection;
43
import java.util.Collection;
43
import java.util.Collections;
44
import java.util.Collections;
44
import java.util.LinkedList;
45
import java.util.LinkedList;
45
import java.util.List;
46
import java.util.List;
Line 65... Line 66...
65
 * searched using {@link #search(SearchSpec)}. Like all Swing model, it ought too be manipulated in
66
 * searched using {@link #search(SearchSpec)}. Like all Swing model, it ought too be manipulated in
66
 * the EDT except explicitly noted. ATTN as soon as nobody listens to an instance (using
67
 * the EDT except explicitly noted. ATTN as soon as nobody listens to an instance (using
67
 * addTableModelListener()) it dies and cannot be used again.
68
 * addTableModelListener()) it dies and cannot be used again.
68
 * 
69
 * 
69
 * @author Sylvain CUAZ
70
 * @author Sylvain CUAZ
-
 
71
 * @see #start()
70
 */
72
 */
71
public class ITableModel extends AbstractTableModel {
73
public class ITableModel extends AbstractTableModel {
72
    public static enum SleepState {
74
    public static enum SleepState {
73
        /**
75
        /**
74
         * The model processes events as they arrive.
76
         * The model processes events as they arrive.
Line 167... Line 169...
167
 
169
 
168
    // whether we should allow edition
170
    // whether we should allow edition
169
    private boolean cellsEditable, orderEditable;
171
    private boolean cellsEditable, orderEditable;
170
    private boolean debug;
172
    private boolean debug;
171
 
173
 
-
 
174
    @GuardedBy("this")
-
 
175
    private UncaughtExceptionHandler uncaughtExnHandler = null;
172
    private DyingQueueExceptionHandler dyingQueueHandler = null;
176
    private DyingQueueExceptionHandler dyingQueueHandler = null;
173
 
177
 
174
    public ITableModel(SQLTableModelSource src) {
178
    public ITableModel(SQLTableModelSource src) {
175
        this.supp = new PropertyChangeSupport(this);
179
        this.supp = new PropertyChangeSupport(this);
176
        this.fullListeners = new LinkedList<TableModelListener>();
180
        this.fullListeners = new LinkedList<TableModelListener>();
Line 878... Line 882...
878
        if (full)
882
        if (full)
879
            this.fullListeners.add(l);
883
            this.fullListeners.add(l);
880
        super.addTableModelListener(l);
884
        super.addTableModelListener(l);
881
    }
885
    }
882
 
886
 
-
 
887
    public synchronized final void setUncaughtExceptionHandler(UncaughtExceptionHandler uncaughtExnHandler) {
-
 
888
        this.uncaughtExnHandler = uncaughtExnHandler;
-
 
889
    }
-
 
890
 
-
 
891
    public synchronized final UncaughtExceptionHandler getUncaughtExceptionHandler() {
883
    // TODO no longer leak this in our constructor
892
        return this.uncaughtExnHandler;
-
 
893
    }
-
 
894
 
884
    public final void start() {
895
    public final void start() {
885
        final RunningState state = this.updateQ.getRunningState();
896
        final RunningState state = this.updateQ.getRunningState();
886
        if (state.compareTo(RunningState.RUNNING) > 0)
897
        if (state.compareTo(RunningState.RUNNING) > 0)
887
            throw new IllegalStateException("dead tableModel: " + this);
898
            throw new IllegalStateException("dead tableModel: " + this);
888
        if (state == RunningState.NEW) {
899
        if (state == RunningState.NEW) {
889
            print("starting");
900
            print("starting");
890
            this.getLinesSource().live();
901
            this.getLinesSource().live();
891
            this.updateQ.start();
902
            this.startQueue(this.updateQ);
-
 
903
        }
892
        }
904
    }
-
 
905
 
-
 
906
    final void startSearchQueue() {
-
 
907
        this.startQueue(this.getSearchQueue());
-
 
908
    }
-
 
909
 
-
 
910
    final void startQueue(final SleepingQueue q) {
-
 
911
        q.start((thr) -> {
-
 
912
            thr.setUncaughtExceptionHandler(getUncaughtExceptionHandler());
-
 
913
        });
893
    }
914
    }
894
 
915
 
895
    @Override
916
    @Override
896
    public void removeTableModelListener(TableModelListener l) {
917
    public void removeTableModelListener(TableModelListener l) {
897
        assert SwingUtilities.isEventDispatchThread();
918
        assert SwingUtilities.isEventDispatchThread();
Line 926... Line 947...
926
     * 
947
     * 
927
     * @param h will be passed the exception thrown by {@link Future#get()} called on the result of
948
     * @param h will be passed the exception thrown by {@link Future#get()} called on the result of
928
     *        {@link SleepingQueue#die()}, <code>null</code> to reset default behavior.
949
     *        {@link SleepingQueue#die()}, <code>null</code> to reset default behavior.
929
     */
950
     */
930
    public void setDyingQueueExceptionHandler(final DyingQueueExceptionHandler h) {
951
    public void setDyingQueueExceptionHandler(final DyingQueueExceptionHandler h) {
-
 
952
        assert SwingUtilities.isEventDispatchThread();
931
        this.dyingQueueHandler = h;
953
        this.dyingQueueHandler = h;
932
    }
954
    }
933
 
955
 
934
    public DyingQueueExceptionHandler getDyingQueueExceptionHandler() {
956
    public DyingQueueExceptionHandler getDyingQueueExceptionHandler() {
935
        return this.dyingQueueHandler;
957
        return this.dyingQueueHandler;