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.model.SQLTable;
18
import org.openconcerto.sql.view.list.action.ListEvent;
19
import org.openconcerto.ui.list.selection.ListSelection;
19
import org.openconcerto.ui.list.selection.ListSelection;
20
import org.openconcerto.utils.CollectionUtils;
-
 
21
import org.openconcerto.utils.cc.IPredicate;
20
import org.openconcerto.utils.cc.IPredicate;
22
 
21
 
23
import java.util.Collections;
22
import java.util.Collections;
24
import java.util.LinkedHashMap;
23
import java.util.LinkedHashMap;
25
import java.util.List;
24
import java.util.List;
Line 34... Line 33...
34
 * 
33
 * 
35
 * @author Sylvain CUAZ
34
 * @author Sylvain CUAZ
36
 */
35
 */
37
public interface IListeAction {
36
public interface IListeAction {
38
 
37
 
39
    static public class IListeEvent {
38
    static public class IListeEvent extends ListEvent {
40
 
-
 
41
        static private final IPredicate<IListeEvent> emptyTotalRowCountPredicate = createTotalRowCountPredicate(0, 0);
-
 
42
 
-
 
43
        static public final IPredicate<IListeEvent> getEmptyListPredicate() {
-
 
44
            return emptyTotalRowCountPredicate;
-
 
45
        }
-
 
46
 
-
 
47
        static public final IPredicate<IListeEvent> createTotalRowCountPredicate(final int min, final int max) {
-
 
48
            return new IPredicate<IListeEvent>() {
-
 
49
                @Override
-
 
50
                public boolean evaluateChecked(IListeEvent e) {
-
 
51
                    return e.getTotalRowCount() >= min && e.getTotalRowCount() <= max;
-
 
52
                }
-
 
53
            };
-
 
54
        }
-
 
55
 
-
 
56
        static private final IPredicate<IListeEvent> singleSelectionPredicate = createSelectionCountPredicate(1, 1);
-
 
57
        static private final IPredicate<IListeEvent> nonEmptySelectionPredicate = createNonEmptySelectionPredicate(Integer.MAX_VALUE);
-
 
58
 
-
 
59
        static public final IPredicate<IListeEvent> getSingleSelectionPredicate() {
-
 
60
            return singleSelectionPredicate;
-
 
61
        }
-
 
62
 
-
 
63
        static public final IPredicate<IListeEvent> getNonEmptySelectionPredicate() {
-
 
64
            return nonEmptySelectionPredicate;
-
 
65
        }
-
 
66
 
-
 
67
        static public final IPredicate<IListeEvent> createNonEmptySelectionPredicate(final int max) {
-
 
68
            return createSelectionCountPredicate(1, max);
-
 
69
        }
-
 
70
 
-
 
71
        static public final IPredicate<IListeEvent> createSelectionCountPredicate(final int min, final int max) {
-
 
72
            return new IPredicate<IListeEvent>() {
-
 
73
                @Override
-
 
74
                public boolean evaluateChecked(IListeEvent e) {
-
 
75
                    // this is the fastest since it involves no object creation
-
 
76
                    final List<?> selectedIDs = e.getSelectedRows();
-
 
77
                    return selectedIDs.size() >= min && selectedIDs.size() <= max;
-
 
78
                }
-
 
79
            };
-
 
80
        }
-
 
81
 
39
 
82
        private final IListe list;
40
        private final IListe list;
83
        private final List<SQLRowValues> selection;
-
 
84
 
41
 
85
        IListeEvent(final IListe list) {
42
        IListeEvent(final IListe list, final List<SQLRowValues> selection, final List<? extends SQLRowAccessor> selectionAccessor) {
86
            super();
43
            super(list, list.getSource().getElem(), list.getTotalRowCount(), selection, selectionAccessor);
87
            this.list = list;
44
            this.list = list;
88
            // this create instances so cache it
-
 
89
            this.selection = list.getSelectedRows();
-
 
90
        }
-
 
91
 
-
 
92
        public final SQLRowAccessor getSelectedRow() {
-
 
93
            return CollectionUtils.getFirst(this.getSelectedRows());
-
 
94
        }
-
 
95
 
-
 
96
        public final List<SQLRowValues> getSelectedRows() {
-
 
97
            return this.selection;
-
 
98
        }
-
 
99
 
-
 
100
        public final int getTotalRowCount() {
-
 
101
            return this.list.getTotalRowCount();
-
 
102
        }
45
        }
103
 
46
 
104
        public final ListSelection getSelection() {
47
        public final ListSelection getSelection() {
105
            return this.list.getSelection();
48
            return this.list.getSelection();
106
        }
49
        }
107
 
-
 
108
        public final SQLTable getTable() {
-
 
109
            return this.list.getSource().getPrimaryTable();
-
 
110
        }
-
 
111
    }
50
    }
112
 
51
 
113
    /**
52
    /**
114
     * Allow to build a list of buttons and when to enable/disable them.
53
     * Allow to build a list of buttons and when to enable/disable them.
115
     * 
54
     * 
Line 178... Line 117...
178
 
117
 
179
    static public class PopupEvent extends IListeEvent {
118
    static public class PopupEvent extends IListeEvent {
180
 
119
 
181
        private final boolean clickOnRows;
120
        private final boolean clickOnRows;
182
 
121
 
183
        PopupEvent(final IListe list, final boolean clickOnRows) {
122
        PopupEvent(final IListe list, final List<SQLRowValues> selection, final List<? extends SQLRowAccessor> selectionAccessor, final boolean clickOnRows) {
184
            super(list);
123
            super(list, selection, selectionAccessor);
185
            this.clickOnRows = clickOnRows;
124
            this.clickOnRows = clickOnRows;
186
        }
125
        }
187
 
126
 
188
        public final boolean isClickOnRows() {
127
        public final boolean isClickOnRows() {
189
            return this.clickOnRows;
128
            return this.clickOnRows;
Line 283... Line 222...
283
     * of an <code>IListe</code>. The returned action should have a visible feedback.
222
     * of an <code>IListe</code>. The returned action should have a visible feedback.
284
     * 
223
     * 
285
     * @param evt the state of the <code>IListe</code>.
224
     * @param evt the state of the <code>IListe</code>.
286
     * @return the default action to perform, can be <code>null</code>.
225
     * @return the default action to perform, can be <code>null</code>.
287
     */
226
     */
288
    Action getDefaultAction(IListeEvent evt);
227
    Action getDefaultAction(ListEvent evt);
289
 
228
 
290
    // never null
229
    // never null
291
    PopupBuilder getPopupContent(PopupEvent evt);
230
    PopupBuilder getPopupContent(PopupEvent evt);
292
}
231
}