OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 180 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 65... Line 65...
65
import org.openconcerto.sql.users.rights.UserRightsManager;
65
import org.openconcerto.sql.users.rights.UserRightsManager;
66
import org.openconcerto.sql.utils.SQLUtils;
66
import org.openconcerto.sql.utils.SQLUtils;
67
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
67
import org.openconcerto.sql.utils.SQLUtils.SQLFactory;
68
import org.openconcerto.sql.view.EditFrame;
68
import org.openconcerto.sql.view.EditFrame;
69
import org.openconcerto.sql.view.EditPanel.EditMode;
69
import org.openconcerto.sql.view.EditPanel.EditMode;
-
 
70
import org.openconcerto.sql.view.list.IListe.ConvertedAction;
70
import org.openconcerto.sql.view.list.IListeAction;
71
import org.openconcerto.sql.view.list.IListeAction;
-
 
72
import org.openconcerto.sql.view.list.RowAction;
71
import org.openconcerto.sql.view.list.SQLTableModelColumn;
73
import org.openconcerto.sql.view.list.SQLTableModelColumn;
72
import org.openconcerto.sql.view.list.SQLTableModelColumnPath;
74
import org.openconcerto.sql.view.list.SQLTableModelColumnPath;
73
import org.openconcerto.sql.view.list.SQLTableModelSource;
75
import org.openconcerto.sql.view.list.SQLTableModelSource;
74
import org.openconcerto.sql.view.list.SQLTableModelSourceOffline;
76
import org.openconcerto.sql.view.list.SQLTableModelSourceOffline;
75
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
77
import org.openconcerto.sql.view.list.SQLTableModelSourceOnline;
-
 
78
import org.openconcerto.sql.view.list.action.SQLRowValuesAction;
76
import org.openconcerto.ui.group.Group;
79
import org.openconcerto.ui.group.Group;
77
import org.openconcerto.ui.light.ComboValueConvertor;
80
import org.openconcerto.ui.light.ComboValueConvertor;
78
import org.openconcerto.ui.light.IntValueConvertor;
81
import org.openconcerto.ui.light.IntValueConvertor;
79
import org.openconcerto.ui.light.LightUIComboBox;
82
import org.openconcerto.ui.light.LightUIComboBox;
80
import org.openconcerto.ui.light.LightUIElement;
83
import org.openconcerto.ui.light.LightUIElement;
81
import org.openconcerto.ui.light.LightUIFrame;
84
import org.openconcerto.ui.light.LightUIFrame;
82
import org.openconcerto.ui.light.LightUIPanel;
-
 
83
import org.openconcerto.ui.light.StringValueConvertor;
85
import org.openconcerto.ui.light.StringValueConvertor;
84
import org.openconcerto.utils.CollectionMap2Itf.SetMapItf;
86
import org.openconcerto.utils.CollectionMap2Itf.SetMapItf;
85
import org.openconcerto.utils.CollectionUtils;
87
import org.openconcerto.utils.CollectionUtils;
86
import org.openconcerto.utils.CompareUtils;
88
import org.openconcerto.utils.CompareUtils;
87
import org.openconcerto.utils.ExceptionHandler;
89
import org.openconcerto.utils.ExceptionHandler;
Line 125... Line 127...
125
import java.util.Map;
127
import java.util.Map;
126
import java.util.Map.Entry;
128
import java.util.Map.Entry;
127
import java.util.Set;
129
import java.util.Set;
128
import java.util.SortedMap;
130
import java.util.SortedMap;
129
import java.util.concurrent.atomic.AtomicReference;
131
import java.util.concurrent.atomic.AtomicReference;
130
import java.util.logging.Level;
-
 
131
import java.util.function.Supplier;
132
import java.util.function.Supplier;
-
 
133
import java.util.logging.Level;
132
 
134
 
133
import javax.swing.JComponent;
135
import javax.swing.JComponent;
134
import javax.swing.JOptionPane;
136
import javax.swing.JOptionPane;
135
import javax.swing.text.JTextComponent;
137
import javax.swing.text.JTextComponent;
136
 
138
 
Line 190... Line 192...
190
    // used as a key in SQLElementDirectory so it should be immutable
192
    // used as a key in SQLElementDirectory so it should be immutable
191
    private String code;
193
    private String code;
192
    private ComboSQLRequest combo;
194
    private ComboSQLRequest combo;
193
    private ListSQLRequest list;
195
    private ListSQLRequest list;
194
    private SQLTableModelSourceOnline tableSrc;
196
    private SQLTableModelSourceOnline tableSrc;
-
 
197
    @Deprecated
195
    private final ListChangeRecorder<IListeAction> rowActions;
198
    private final ListChangeRecorder<IListeAction> rowActions;
-
 
199
    private final ListChangeRecorder<SQLRowValuesAction> rowValuesActions;
196
    private final LinkedListMap<String, ITransformer<Tuple2<SQLElement, String>, SQLComponent>> components;
200
    private final LinkedListMap<String, ITransformer<Tuple2<SQLElement, String>, SQLComponent>> components;
197
    // links
201
    // links
198
    private SQLElementLinks ownedLinks;
202
    private SQLElementLinks ownedLinks;
199
    private SQLElementLinks otherLinks;
203
    private SQLElementLinks otherLinks;
200
    // keep it for now as joins are disallowed (see initFF())
204
    // keep it for now as joins are disallowed (see initFF())
Line 234... Line 238...
234
        this.primaryTable = primaryTable;
238
        this.primaryTable = primaryTable;
235
        this.setDefaultName(name);
239
        this.setDefaultName(name);
236
        this.code = code == null ? createCode() : code;
240
        this.code = code == null ? createCode() : code;
237
        this.combo = null;
241
        this.combo = null;
238
        this.list = null;
242
        this.list = null;
239
        this.rowActions = new ListChangeRecorder<IListeAction>(new ArrayList<IListeAction>());
243
        this.rowActions = new ListChangeRecorder<>(Collections.synchronizedList(new ArrayList<>()));
-
 
244
        this.rowActions.getRecipe().addListener(new IClosure<ListChangeIndex<IListeAction>>() {
-
 
245
            private final Map<IListeAction, SQLRowValuesAction> map = new IdentityHashMap<>();
-
 
246
 
-
 
247
            @Override
-
 
248
            public void executeChecked(ListChangeIndex<IListeAction> listChange) {
-
 
249
                final List<SQLRowValuesAction> oldActions = new ArrayList<>();
-
 
250
                for (final IListeAction action : listChange.getItemsRemoved()) {
-
 
251
                    synchronized (this) {
-
 
252
                        final SQLRowValuesAction ra = this.map.remove(action);
-
 
253
                        if (ra != null)
-
 
254
                            oldActions.add(ra);
-
 
255
                    }
-
 
256
                }
-
 
257
                getRowValuesActions().removeAll(oldActions);
-
 
258
 
-
 
259
                final List<SQLRowValuesAction> newActions = new ArrayList<>();
-
 
260
                for (final IListeAction action : listChange.getItemsAdded()) {
-
 
261
                    if (action instanceof RowAction) {
-
 
262
                        synchronized (this) {
-
 
263
                            if (!this.map.containsKey(action)) {
-
 
264
                                final ConvertedAction converted = new ConvertedAction((RowAction) action);
-
 
265
                                this.map.put(action, converted);
-
 
266
                                newActions.add(converted);
-
 
267
                            }
-
 
268
                        }
-
 
269
                    }
-
 
270
                }
-
 
271
                getRowValuesActions().addAll(newActions);
-
 
272
            }
-
 
273
        });
-
 
274
        this.rowValuesActions = new ListChangeRecorder<>(Collections.synchronizedList(new ArrayList<>()));
240
        this.resetRelationships();
275
        this.resetRelationships();
241
 
276
 
242
        this.components = new LinkedListMap<String, ITransformer<Tuple2<SQLElement, String>, SQLComponent>>();
277
        this.components = new LinkedListMap<String, ITransformer<Tuple2<SQLElement, String>, SQLComponent>>();
243
 
278
 
244
        this.modelCache = null;
279
        this.modelCache = null;
Line 1943... Line 1978...
1943
 
1978
 
1944
    public final void addListColumn(SQLTableModelColumn col) {
1979
    public final void addListColumn(SQLTableModelColumn col) {
1945
        this.additionalListCols.add(col);
1980
        this.additionalListCols.add(col);
1946
    }
1981
    }
1947
 
1982
 
-
 
1983
    @Deprecated
1948
    public final Collection<IListeAction> getRowActions() {
1984
    public final Collection<IListeAction> getRowActions() {
1949
        return this.rowActions;
1985
        return this.rowActions;
1950
    }
1986
    }
1951
 
1987
 
-
 
1988
    public final List<SQLRowValuesAction> getRowValuesActions() {
-
 
1989
        return this.rowValuesActions;
-
 
1990
    }
-
 
1991
 
1952
    public final void addRowActionsListener(final IClosure<ListChangeIndex<IListeAction>> listener) {
1992
    public final void addRowActionsListener(final IClosure<? super ListChangeIndex<SQLRowValuesAction>> listener) {
1953
        this.rowActions.getRecipe().addListener(listener);
1993
        this.rowValuesActions.getRecipe().addListener(listener);
1954
    }
1994
    }
1955
 
1995
 
1956
    public final void removeRowActionsListener(final IClosure<ListChangeIndex<IListeAction>> listener) {
1996
    public final void removeRowActionsListener(final IClosure<? super ListChangeIndex<SQLRowValuesAction>> listener) {
1957
        this.rowActions.getRecipe().rmListener(listener);
1997
        this.rowValuesActions.getRecipe().rmListener(listener);
1958
    }
1998
    }
1959
 
1999
 
1960
    public String getDescription(SQLRow fromRow) {
2000
    public String getDescription(SQLRow fromRow) {
1961
        return fromRow.toString();
2001
        return fromRow.toString();
1962
    }
2002
    }
Line 2174... Line 2214...
2174
     *        {@link SQLRowAccessor#getIDNumber()} will be used (i.e. if the copy isn't to be linked
2214
     *        {@link SQLRowAccessor#getIDNumber()} will be used (i.e. if the copy isn't to be linked
2175
     *        to its parent, pass a {@link SQLRowAccessor#asRow() row}).
2215
     *        to its parent, pass a {@link SQLRowAccessor#asRow() row}).
2176
     * @return a copy ready to be inserted, or <code>null</code> if <code>row</code> cannot be
2216
     * @return a copy ready to be inserted, or <code>null</code> if <code>row</code> cannot be
2177
     *         copied.
2217
     *         copied.
2178
     */
2218
     */
2179
    public SQLRowValues createCopy(SQLRowAccessor row, SQLRowAccessor parent) {
2219
    public final SQLRowValues createCopy(SQLRowAccessor row, SQLRowAccessor parent) {
2180
        return createCopy(row, false, parent);
2220
        return createCopy(row, false, parent);
2181
    }
2221
    }
2182
 
2222
 
2183
    public SQLRowValues createCopy(SQLRowAccessor row, final boolean full, SQLRowAccessor parent) {
2223
    public final SQLRowValues createCopy(SQLRowAccessor row, final boolean full, SQLRowAccessor parent) {
2184
        return this.createCopy(row, full, parent, null, null);
2224
        return this.createCopy(row, full, parent, null, null);
2185
    }
2225
    }
2186
 
2226
 
2187
    public SQLRowValues createCopy(SQLRowAccessor row, final boolean full, SQLRowAccessor parent, final IdentityHashMap<SQLRowValues, SQLRowValues> valsMap, final Map<SQLRow, SQLRowValues> rowMap) {
2227
    public SQLRowValues createCopy(SQLRowAccessor row, final boolean full, SQLRowAccessor parent, final IdentityHashMap<SQLRowValues, SQLRowValues> valsMap, final Map<SQLRow, SQLRowValues> rowMap) {
2188
        // do NOT copy the undefined
2228
        // do NOT copy the undefined