OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 65 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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