OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 19 | Rev 26 | Go to most recent revision | 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 public DBRoot getRoot() {
19 ilm 36
        return Configuration.getInstance().getRoot();
37
    }
38
 
25 ilm 39
    static String getAppPrefPath() {
19 ilm 40
        return Configuration.getInstance().getAppID() + '/';
41
    }
42
 
43
    public static class SQLPrefView<T> extends PrefView<T> {
44
 
45
        public SQLPrefView(PrefType<T> type, String name, String prefKey) {
46
            super(type, name, prefKey);
47
        }
48
 
49
        public SQLPrefView(PrefType<T> type, int length, String name, String prefKey) {
50
            super(type, length, name, prefKey);
51
        }
52
 
53
        @Override
54
        protected JComponent createComponent() {
55
            final JComponent comp;
56
            if (Boolean.class.isAssignableFrom(this.getViewClass())) {
57
                // ATTN hack to view the focus (should try to paint around the button)
58
                comp = new JCheckBox(" ");
59
            } else if (Date.class.isAssignableFrom(this.getViewClass())) {
60
                comp = new JDate();
61
            } else if (String.class.isAssignableFrom(this.getViewClass()) && this.getLength() >= 512) {
62
                comp = new SQLSearchableTextCombo(ComboLockedMode.UNLOCKED, true);
63
            } else {
64
                comp = new SQLTextCombo(false);
65
            }
66
            return comp;
67
        }
68
 
69
        @Override
70
        public void init(final JavaPrefPreferencePanel prefPanel) {
71
            final JComponent comp = this.getVW().getComp();
72
            if (comp instanceof SQLTextCombo) {
73
                ((SQLTextCombo) comp).initCache(createCache(prefPanel));
74
            } else if (comp instanceof SQLSearchableTextCombo) {
75
                ((SQLSearchableTextCombo) comp).initCacheLater(new ISQLListModel(createCache(prefPanel)));
76
            }
77
        }
78
 
79
        private ITextComboCacheSQL createCache(final JavaPrefPreferencePanel prefPanel) {
80
            return new ITextComboCacheSQL(getRoot(), prefPanel.getPrefPath() + '/' + this.getPrefKey());
81
        }
82
    }
83
 
84
    public ModulePreferencePanel(final String title) {
85
        super(title, null);
86
 
87
    }
88
 
89
    public final void init(final ModuleFactory module, final boolean local) {
25 ilm 90
        this.setPrefs(module.getPreferences(local, getRoot()));
19 ilm 91
    }
92
}