OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 151 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 151 Rev 182
Line 1... Line 1...
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
Line 13... Line 13...
13
 
13
 
14
 package org.openconcerto.sql.view.list;
14
 package org.openconcerto.sql.view.list;
15
 
15
 
16
import org.openconcerto.sql.model.SQLRowAccessor;
16
import org.openconcerto.sql.model.SQLRowAccessor;
17
import org.openconcerto.sql.model.SQLRowValues;
17
import org.openconcerto.sql.model.SQLRowValues;
-
 
18
import org.openconcerto.sql.view.list.action.ListEvent;
18
import org.openconcerto.utils.cc.IClosure;
19
import org.openconcerto.utils.cc.IClosure;
19
import org.openconcerto.utils.cc.IPredicate;
20
import org.openconcerto.utils.cc.IPredicate;
20
import org.openconcerto.utils.i18n.TranslationManager;
21
import org.openconcerto.utils.i18n.TranslationManager;
21
 
22
 
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionEvent;
Line 48... Line 49...
48
            }
49
            }
49
        };
50
        };
50
    }
51
    }
51
 
52
 
52
    public static class PredicateRowAction extends RowAction {
53
    public static class PredicateRowAction extends RowAction {
53
        private IPredicate<? super IListeEvent> pred = null;
54
        private IPredicate<? super ListEvent> pred = null;
54
 
55
 
55
        public PredicateRowAction(Action action, boolean header) {
56
        public PredicateRowAction(Action action, boolean header) {
56
            super(action, header);
57
            super(action, header);
57
        }
58
        }
58
 
59
 
Line 66... Line 67...
66
 
67
 
67
        public PredicateRowAction(Action action, boolean header, boolean popupMenu, final String id) {
68
        public PredicateRowAction(Action action, boolean header, boolean popupMenu, final String id) {
68
            super(action, header, popupMenu, id);
69
            super(action, header, popupMenu, id);
69
        }
70
        }
70
 
71
 
71
        public final PredicateRowAction setPredicate(IPredicate<? super IListeEvent> pred) {
72
        public final PredicateRowAction setPredicate(IPredicate<? super ListEvent> pred) {
72
            if (pred == null) {
73
            if (pred == null) {
73
                throw new IllegalArgumentException("null predicate");
74
                throw new IllegalArgumentException("null predicate");
74
            }
75
            }
75
            this.pred = pred;
76
            this.pred = pred;
76
            return this;
77
            return this;
Line 79... Line 80...
79
        public final IPredicate<? super IListeEvent> getPredicate() {
80
        public final IPredicate<? super IListeEvent> getPredicate() {
80
            return this.pred;
81
            return this.pred;
81
        }
82
        }
82
 
83
 
83
        @Override
84
        @Override
84
        public boolean enabledFor(IListeEvent evt) {
85
        public boolean enabledFor(ListEvent evt) {
85
            if (this.pred == null) {
86
            if (this.pred == null) {
86
                throw new IllegalStateException("No predicate for " + this);
87
                throw new IllegalStateException("No predicate for " + this);
87
            }
88
            }
88
            return this.pred.evaluateChecked(evt);
89
            return this.pred.evaluateChecked(evt);
89
        }
90
        }
Line 146... Line 147...
146
    public final List<String> getPath() {
147
    public final List<String> getPath() {
147
        return this.path;
148
        return this.path;
148
    }
149
    }
149
 
150
 
150
    public boolean enabledFor(List<SQLRowValues> selection) {
151
    public boolean enabledFor(List<SQLRowValues> selection) {
151
        throw new UnsupportedOperationException("Should overload this method or enabledFor(IListeEvent)");
152
        throw new UnsupportedOperationException("Should overload this method or enabledFor(IListeEvent) on : " + this);
152
    }
153
    }
153
 
154
 
154
    /**
155
    /**
155
     * Whether the action should be enabled in the header or in the popup.
156
     * Whether the action should be enabled in the header or in the popup.
156
     * 
157
     * 
157
     * @param evt the state of the IListe.
158
     * @param evt the state of the IListe.
158
     * @return <code>true</code> if the action can be performed.
159
     * @return <code>true</code> if the action can be performed.
159
     */
160
     */
160
    public boolean enabledFor(IListeEvent evt) {
161
    public boolean enabledFor(ListEvent evt) {
161
        return this.enabledFor(evt.getSelectedRows());
162
        return this.enabledFor(evt.getSelectedRows());
162
    }
163
    }
163
 
164
 
164
    @Override
165
    @Override
165
    public ButtonsBuilder getHeaderButtons() {
166
    public ButtonsBuilder getHeaderButtons() {
Line 170... Line 171...
170
            }
171
            }
171
        });
172
        });
172
    }
173
    }
173
 
174
 
174
    @Override
175
    @Override
175
    public Action getDefaultAction(IListeEvent evt) {
176
    public Action getDefaultAction(ListEvent evt) {
176
        return this.enabledFor(evt) ? this.getAction() : null;
177
        return this.enabledFor(evt) ? this.getAction() : null;
177
    }
178
    }
178
 
179
 
179
    @Override
180
    @Override
180
    public PopupBuilder getPopupContent(PopupEvent evt) {
181
    public PopupBuilder getPopupContent(PopupEvent evt) {