PageRenderTime 294ms CodeModel.GetById 121ms app.highlight 60ms RepoModel.GetById 107ms app.codeStats 0ms

/src/mpv5/utils/models/ImportTableModel.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 91 lines | 47 code | 13 blank | 31 comment | 7 complexity | da8b31a98f08a3d9ba5238411862ce9c MD5 | raw file
 1/*
 2 *  This file is part of YaBS.
 3 *
 4 *      YaBS is free software: you can redistribute it and/or modify
 5 *      it under the terms of the GNU General Public License as published by
 6 *      the Free Software Foundation, either version 3 of the License, or
 7 *      (at your option) any later version.
 8 *
 9 *      YaBS is distributed in the hope that it will be useful,
10 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
11 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 *      GNU General Public License for more details.
13 *
14 *      You should have received a copy of the GNU General Public License
15 *      along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
16 */
17package mpv5.utils.models;
18
19import java.util.ArrayList;
20import java.util.List;
21import javax.swing.table.TableModel;
22import mpv5.db.common.DatabaseObject;
23import mpv5.globals.Headers;
24
25/**
26 *
27 *  
28 */
29public class ImportTableModel extends MPTableModel {
30
31    private static final long serialVersionUID = 1L;
32
33    /**
34     * 
35     * @param objs
36     * @param selectOnlyNonExisting
37     * @return
38     */
39    public static ImportTableModel getModel(ArrayList<ArrayList<DatabaseObject>> objs, boolean selectOnlyNonExisting) {
40        ArrayList<DatabaseObject> l = new ArrayList<DatabaseObject>();
41
42        for (int i = 0; i < objs.size(); i++) {
43            ArrayList<DatabaseObject> arrayList = objs.get(i);
44            for (int j = 0; j < arrayList.size(); j++) {
45                DatabaseObject databaseObject = arrayList.get(j);
46                l.add(databaseObject);
47            }
48        }
49        return new ImportTableModel(l, selectOnlyNonExisting);
50    }
51
52    /**
53     *
54     * @param list
55     * @param selectOnlyNonExisting
56     */
57    public ImportTableModel(ArrayList<DatabaseObject> list, boolean selectOnlyNonExisting) {
58        super();
59
60        Object[][] data = new Object[list.size()][5];
61
62        for (int i = 0; i < list.size(); i++) {
63            DatabaseObject databaseObject = list.get(i);
64            List<String[]> t = databaseObject.getValues();
65
66            String sdata = "";
67            for (int j = 0; j < t.size(); j++) {
68                String[] strings = t.get(j);
69                sdata += strings[0] + ": " + strings[1] + "  ";
70            }
71            data[i][0] = databaseObject;
72            if (selectOnlyNonExisting) {
73                if (DatabaseObject.exists(databaseObject.getContext(), databaseObject.__getIDS())) {
74                    data[i][1] = false;
75                } else {
76                    data[i][1] = true;
77                }
78            }
79            data[i][2] = databaseObject.getDbIdentity();
80            data[i][3] = databaseObject.__getCname();
81            data[i][4] = sdata;
82        }
83
84        setCanEdits(new boolean[]{false, true, false, false, false, false});
85        setTypes(new Class[]{Object.class, Boolean.class, Object.class, Object.class, Object.class, Object.class});
86        setDataVector(data, Headers.IMPORT.getValue());
87
88    }
89
90
91}