OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 65 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
19 ilm 1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 *
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
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.
10
 *
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
13
 
14
 package org.openconcerto.erp.modules;
15
 
16
import org.openconcerto.sql.Configuration;
17
import org.openconcerto.sql.model.DBRoot;
18
import org.openconcerto.sql.sqlobject.SQLSearchableTextCombo;
19
import org.openconcerto.sql.sqlobject.SQLSearchableTextCombo.ISQLListModel;
20
import org.openconcerto.sql.sqlobject.SQLTextCombo;
21
import org.openconcerto.sql.sqlobject.SQLTextCombo.ITextComboCacheSQL;
22
import org.openconcerto.ui.JDate;
23
import org.openconcerto.ui.component.ComboLockedMode;
24
import org.openconcerto.ui.preferences.JavaPrefPreferencePanel;
25
import org.openconcerto.ui.preferences.PrefView;
26
import org.openconcerto.utils.PrefType;
27
 
28
import java.util.Date;
29
 
30
import javax.swing.JCheckBox;
31
import javax.swing.JComponent;
32
 
33
public abstract class ModulePreferencePanel extends JavaPrefPreferencePanel {
34
 
25 ilm 35
    static String getAppPrefPath() {
19 ilm 36
        return Configuration.getInstance().getAppID() + '/';
37
    }
38
 
39
    public static class SQLPrefView<T> extends PrefView<T> {
40
 
41
        public SQLPrefView(PrefType<T> type, String name, String prefKey) {
42
            super(type, name, prefKey);
43
        }
44
 
45
        public SQLPrefView(PrefType<T> type, int length, String name, String prefKey) {
46
            super(type, length, name, prefKey);
47
        }
48
 
49
        @Override
50
        protected JComponent createComponent() {
51
            final JComponent comp;
52
            if (Boolean.class.isAssignableFrom(this.getViewClass())) {
53
                // ATTN hack to view the focus (should try to paint around the button)
54
                comp = new JCheckBox(" ");
55
            } else if (Date.class.isAssignableFrom(this.getViewClass())) {
56
                comp = new JDate();
57
            } else if (String.class.isAssignableFrom(this.getViewClass()) && this.getLength() >= 512) {
58
                comp = new SQLSearchableTextCombo(ComboLockedMode.UNLOCKED, true);
59
            } else {
60
                comp = new SQLTextCombo(false);
61
            }
62
            return comp;
63
        }
64
 
65
        @Override
66
        public void init(final JavaPrefPreferencePanel prefPanel) {
67
            final JComponent comp = this.getVW().getComp();
68
            if (comp instanceof SQLTextCombo) {
69
                ((SQLTextCombo) comp).initCache(createCache(prefPanel));
70
            } else if (comp instanceof SQLSearchableTextCombo) {
65 ilm 71
                ((SQLSearchableTextCombo) comp).initCache(new ISQLListModel(createCache(prefPanel)).load());
19 ilm 72
            }
73
        }
74
 
75
        private ITextComboCacheSQL createCache(final JavaPrefPreferencePanel prefPanel) {
156 ilm 76
            return new ITextComboCacheSQL(((ModulePreferencePanel) prefPanel).getRoot(), prefPanel.getPrefPath() + '/' + this.getPrefKey());
19 ilm 77
        }
78
    }
79
 
156 ilm 80
    private final DBRoot root;
81
 
82
    public ModulePreferencePanel(final DBRoot root, final String title) {
19 ilm 83
        super(title, null);
156 ilm 84
        this.root = root;
85
    }
19 ilm 86
 
156 ilm 87
    public final DBRoot getRoot() {
88
        return this.root;
19 ilm 89
    }
90
 
91
    public final void init(final ModuleFactory module, final boolean local) {
156 ilm 92
        this.setPrefs(module.getPreferences(local, this.getRoot()));
19 ilm 93
    }
94
}