OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 132 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73 Rev 83
Line 19... Line 19...
19
import org.openconcerto.sql.users.User;
19
import org.openconcerto.sql.users.User;
20
import org.openconcerto.sql.users.UserManager;
20
import org.openconcerto.sql.users.UserManager;
21
import org.openconcerto.sql.users.rights.UserRights;
21
import org.openconcerto.sql.users.rights.UserRights;
22
import org.openconcerto.sql.users.rights.UserRightsManager;
22
import org.openconcerto.sql.users.rights.UserRightsManager;
23
import org.openconcerto.ui.FormLayouter;
23
import org.openconcerto.ui.FormLayouter;
24
import org.openconcerto.ui.SystemInfoPanel;
-
 
25
import org.openconcerto.ui.component.HTMLTextField;
24
import org.openconcerto.ui.component.HTMLTextField;
26
import org.openconcerto.utils.ProductInfo;
25
import org.openconcerto.utils.ProductInfo;
-
 
26
import org.openconcerto.utils.SystemInfo;
-
 
27
import org.openconcerto.utils.cc.IFactory;
27
import org.openconcerto.utils.i18n.I18nUtils;
28
import org.openconcerto.utils.i18n.I18nUtils;
28
 
29
 
-
 
30
import java.util.HashMap;
-
 
31
import java.util.Map;
-
 
32
 
29
import javax.swing.JLabel;
33
import javax.swing.JLabel;
30
import javax.swing.JPanel;
34
import javax.swing.JPanel;
31
 
35
 
32
/**
36
/**
33
 * A panel displaying various software informations.
37
 * A panel displaying various software informations.
Line 35... Line 39...
35
 * @author Sylvain CUAZ
39
 * @author Sylvain CUAZ
36
 * @see Configuration
40
 * @see Configuration
37
 */
41
 */
38
public class SoftwareInfoPanel extends JPanel {
42
public class SoftwareInfoPanel extends JPanel {
39
 
43
 
40
    public SoftwareInfoPanel() {
44
    public static enum Info {
-
 
45
        RIGHTS, USER, APP_NAME, APP_VERSION, SECURE_LINK, DB_URL, DIRS
-
 
46
    }
-
 
47
 
-
 
48
    public static final IFactory<String> FACTORY = new IFactory<String>() {
-
 
49
        @Override
-
 
50
        public String createChecked() {
-
 
51
            return get(false).toString();
-
 
52
        }
-
 
53
    };
-
 
54
 
-
 
55
    public static Map<Info, String> get(final boolean html) {
41
        final FormLayouter l = new FormLayouter(this, 1);
56
        final Map<Info, String> res = new HashMap<Info, String>();
42
 
57
 
43
        final UserRightsManager userRightsManager = UserRightsManager.getInstance();
58
        final UserRightsManager userRightsManager = UserRightsManager.getInstance();
44
        l.add(TM.tr("infoPanel.rights"), new JLabel(org.openconcerto.utils.i18n.TM.tr(I18nUtils.getYesNoKey(userRightsManager != null))));
59
        res.put(Info.RIGHTS, org.openconcerto.utils.i18n.TM.tr(I18nUtils.getYesNoKey(userRightsManager != null)));
45
        final User user = UserManager.getUser();
60
        final User user = UserManager.getUser();
46
        if (user != null) {
61
        if (user != null) {
47
            final UserRights userRights = UserRightsManager.getCurrentUserRights();
62
            final UserRights userRights = UserRightsManager.getCurrentUserRights();
48
            final String userS = user.toString() + (userRights.isSuperUser() ? " (superuser)" : "");
63
            res.put(Info.USER, user.toString() + (userRights.isSuperUser() ? " (superuser)" : ""));
49
            l.add(org.openconcerto.utils.i18n.TM.tr("user"), new JLabel(userS));
-
 
50
        }
64
        }
51
 
65
 
52
        final Configuration conf = Configuration.getInstance();
66
        final Configuration conf = Configuration.getInstance();
53
        final PropsConfiguration propsConf;
67
        final PropsConfiguration propsConf;
54
        final ProductInfo productInfo;
68
        final ProductInfo productInfo;
Line 66... Line 80...
66
            version = TM.tr("infoPanel.noVersion");
80
            version = TM.tr("infoPanel.noVersion");
67
        } else {
81
        } else {
68
            name = productInfo.getName();
82
            name = productInfo.getName();
69
            version = productInfo.getProperty(ProductInfo.VERSION, TM.tr("infoPanel.noVersion"));
83
            version = productInfo.getProperty(ProductInfo.VERSION, TM.tr("infoPanel.noVersion"));
70
        }
84
        }
71
        l.add(TM.tr("infoPanel.appName"), new JLabel(name));
85
        res.put(Info.APP_NAME, name);
72
        l.add(TM.tr("infoPanel.version"), new JLabel(version));
86
        res.put(Info.APP_VERSION, version);
73
        if (propsConf != null && propsConf.isUsingSSH()) {
87
        if (propsConf != null && propsConf.isUsingSSH()) {
-
 
88
            res.put(Info.SECURE_LINK, propsConf.getWanHostAndPort());
-
 
89
        }
-
 
90
        res.put(Info.DB_URL, conf.getSystemRoot().getDataSource().getUrl());
-
 
91
        final String logs = propsConf == null ? "" : " ; " + SystemInfo.getLink(TM.tr("infoPanel.logs"), propsConf.getLogDir().toURI(), html);
-
 
92
        res.put(Info.DIRS, SystemInfo.getLink(TM.tr("infoPanel.docs"), conf.getWD().toURI(), html) + logs);
-
 
93
 
-
 
94
        return res;
-
 
95
    }
-
 
96
 
-
 
97
    public SoftwareInfoPanel() {
-
 
98
        final Map<Info, String> infos = get(true);
-
 
99
        final FormLayouter l = new FormLayouter(this, 1);
-
 
100
 
-
 
101
        l.add(TM.tr("infoPanel.rights"), new JLabel(infos.get(Info.RIGHTS)));
-
 
102
        final String user = infos.get(Info.USER);
-
 
103
        if (user != null) {
-
 
104
            l.add(org.openconcerto.utils.i18n.TM.tr("user"), new JLabel(user));
-
 
105
        }
-
 
106
 
-
 
107
        l.add(TM.tr("infoPanel.appName"), new JLabel(infos.get(Info.APP_NAME)));
-
 
108
        l.add(TM.tr("infoPanel.version"), new JLabel(infos.get(Info.APP_VERSION)));
-
 
109
        final String secureLink = infos.get(Info.SECURE_LINK);
-
 
110
        if (secureLink != null) {
74
            l.add(TM.tr("infoPanel.secureLink"), new JLabel(propsConf.getWanHostAndPort()));
111
            l.add(TM.tr("infoPanel.secureLink"), new JLabel(secureLink));
75
        }
112
        }
76
        l.add(TM.tr("infoPanel.dbURL"), new JLabel(conf.getSystemRoot().getDataSource().getUrl()));
113
        l.add(TM.tr("infoPanel.dbURL"), new JLabel(infos.get(Info.DB_URL)));
77
        final String logs = propsConf == null ? "" : " ; " + SystemInfoPanel.getLink(TM.tr("infoPanel.logs"), propsConf.getLogDir().toURI());
-
 
78
        l.add(TM.tr("infoPanel.dirs"), new HTMLTextField(SystemInfoPanel.getLink(TM.tr("infoPanel.docs"), conf.getWD().toURI()) + logs));
114
        l.add(TM.tr("infoPanel.dirs"), new HTMLTextField(infos.get(Info.DIRS)));
79
    }
115
    }
80
}
116
}