41 |
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.sql.ui;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.sql.Configuration;
|
|
|
17 |
import org.openconcerto.sql.PropsConfiguration;
|
73 |
ilm |
18 |
import org.openconcerto.sql.TM;
|
|
|
19 |
import org.openconcerto.sql.users.User;
|
|
|
20 |
import org.openconcerto.sql.users.UserManager;
|
|
|
21 |
import org.openconcerto.sql.users.rights.UserRights;
|
|
|
22 |
import org.openconcerto.sql.users.rights.UserRightsManager;
|
41 |
ilm |
23 |
import org.openconcerto.ui.FormLayouter;
|
|
|
24 |
import org.openconcerto.ui.component.HTMLTextField;
|
142 |
ilm |
25 |
import org.openconcerto.utils.BaseDirs;
|
41 |
ilm |
26 |
import org.openconcerto.utils.ProductInfo;
|
83 |
ilm |
27 |
import org.openconcerto.utils.SystemInfo;
|
149 |
ilm |
28 |
import org.openconcerto.utils.Tuple2;
|
83 |
ilm |
29 |
import org.openconcerto.utils.cc.IFactory;
|
73 |
ilm |
30 |
import org.openconcerto.utils.i18n.I18nUtils;
|
41 |
ilm |
31 |
|
83 |
ilm |
32 |
import java.util.HashMap;
|
177 |
ilm |
33 |
import java.util.Locale;
|
83 |
ilm |
34 |
import java.util.Map;
|
|
|
35 |
|
41 |
ilm |
36 |
import javax.swing.JLabel;
|
|
|
37 |
import javax.swing.JPanel;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* A panel displaying various software informations.
|
|
|
41 |
*
|
|
|
42 |
* @author Sylvain CUAZ
|
|
|
43 |
* @see Configuration
|
|
|
44 |
*/
|
|
|
45 |
public class SoftwareInfoPanel extends JPanel {
|
|
|
46 |
|
83 |
ilm |
47 |
public static enum Info {
|
|
|
48 |
RIGHTS, USER, APP_NAME, APP_VERSION, SECURE_LINK, DB_URL, DIRS
|
|
|
49 |
}
|
73 |
ilm |
50 |
|
83 |
ilm |
51 |
public static final IFactory<String> FACTORY = new IFactory<String>() {
|
|
|
52 |
@Override
|
|
|
53 |
public String createChecked() {
|
177 |
ilm |
54 |
return get(false, Locale.ENGLISH).toString();
|
83 |
ilm |
55 |
}
|
|
|
56 |
};
|
|
|
57 |
|
177 |
ilm |
58 |
public static Map<Info, String> get(final boolean html, final Locale locale) {
|
83 |
ilm |
59 |
final Map<Info, String> res = new HashMap<Info, String>();
|
|
|
60 |
|
73 |
ilm |
61 |
final UserRightsManager userRightsManager = UserRightsManager.getInstance();
|
177 |
ilm |
62 |
res.put(Info.RIGHTS, org.openconcerto.utils.i18n.TM.tr(locale, I18nUtils.getYesNoKey(userRightsManager != null)));
|
73 |
ilm |
63 |
final User user = UserManager.getUser();
|
|
|
64 |
if (user != null) {
|
|
|
65 |
final UserRights userRights = UserRightsManager.getCurrentUserRights();
|
83 |
ilm |
66 |
res.put(Info.USER, user.toString() + (userRights.isSuperUser() ? " (superuser)" : ""));
|
73 |
ilm |
67 |
}
|
|
|
68 |
|
41 |
ilm |
69 |
final Configuration conf = Configuration.getInstance();
|
|
|
70 |
final PropsConfiguration propsConf;
|
|
|
71 |
final ProductInfo productInfo;
|
|
|
72 |
if (conf instanceof PropsConfiguration) {
|
|
|
73 |
propsConf = (PropsConfiguration) conf;
|
|
|
74 |
productInfo = propsConf.getProductInfo();
|
|
|
75 |
} else {
|
|
|
76 |
propsConf = null;
|
|
|
77 |
productInfo = ProductInfo.getInstance();
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
final String name, version;
|
|
|
81 |
if (productInfo == null) {
|
177 |
ilm |
82 |
name = TM.tr(locale, "infoPanel.noAppName");
|
|
|
83 |
version = TM.tr(locale, "infoPanel.noVersion");
|
41 |
ilm |
84 |
} else {
|
|
|
85 |
name = productInfo.getName();
|
177 |
ilm |
86 |
version = productInfo.getProperty(ProductInfo.VERSION, TM.tr(locale, "infoPanel.noVersion"));
|
41 |
ilm |
87 |
}
|
83 |
ilm |
88 |
res.put(Info.APP_NAME, name);
|
|
|
89 |
res.put(Info.APP_VERSION, version);
|
41 |
ilm |
90 |
if (propsConf != null && propsConf.isUsingSSH()) {
|
149 |
ilm |
91 |
final Tuple2<String, Integer> serverAddressAndPort = propsConf.parseServerAddressAndPort();
|
|
|
92 |
res.put(Info.SECURE_LINK, "localhost:" + propsConf.getTunnelLocalPort() + " ⟷ (" + propsConf.getWanHostAndPort() + ") " + serverAddressAndPort.get0() + ":" + serverAddressAndPort.get1());
|
41 |
ilm |
93 |
}
|
142 |
ilm |
94 |
if (conf != null)
|
|
|
95 |
res.put(Info.DB_URL, conf.getSystemRoot().getDataSource().getUrl());
|
|
|
96 |
if (conf != null) {
|
177 |
ilm |
97 |
final String logs = propsConf == null ? "" : " ; " + SystemInfo.getLink(TM.tr(locale, "infoPanel.logs"), propsConf.getLogDir().toURI(), html);
|
142 |
ilm |
98 |
final BaseDirs baseDirs = conf.getBaseDirs();
|
177 |
ilm |
99 |
String dirs = " ; " + SystemInfo.getLink(TM.tr(locale, "infoPanel.dataDir"), baseDirs.getAppDataFolder().toURI(), html);
|
|
|
100 |
dirs = dirs + " ; " + SystemInfo.getLink(TM.tr(locale, "infoPanel.prefsDir"), baseDirs.getPreferencesFolder().toURI(), html);
|
|
|
101 |
dirs = dirs + " ; " + SystemInfo.getLink(TM.tr(locale, "infoPanel.cacheDir"), baseDirs.getCacheFolder().toURI(), html);
|
|
|
102 |
res.put(Info.DIRS, SystemInfo.getLink(TM.tr(locale, "infoPanel.docs"), conf.getWD().toURI(), html) + logs + dirs);
|
142 |
ilm |
103 |
}
|
83 |
ilm |
104 |
|
|
|
105 |
return res;
|
41 |
ilm |
106 |
}
|
83 |
ilm |
107 |
|
132 |
ilm |
108 |
private final FormLayouter l;
|
|
|
109 |
|
177 |
ilm |
110 |
public SoftwareInfoPanel(final Locale locale) {
|
132 |
ilm |
111 |
this.l = new FormLayouter(this, 1);
|
177 |
ilm |
112 |
this.refresh(locale);
|
132 |
ilm |
113 |
}
|
|
|
114 |
|
177 |
ilm |
115 |
public final void refresh(final Locale locale) {
|
132 |
ilm |
116 |
this.l.clear();
|
177 |
ilm |
117 |
final Map<Info, String> infos = get(true, locale);
|
|
|
118 |
this.l.add(TM.tr(locale, "infoPanel.rights"), new JLabel(infos.get(Info.RIGHTS)));
|
83 |
ilm |
119 |
final String user = infos.get(Info.USER);
|
|
|
120 |
if (user != null) {
|
177 |
ilm |
121 |
this.l.add(org.openconcerto.utils.i18n.TM.tr(locale, "user"), new JLabel(user));
|
83 |
ilm |
122 |
}
|
|
|
123 |
|
177 |
ilm |
124 |
this.l.add(TM.tr(locale, "infoPanel.appName"), new JLabel(infos.get(Info.APP_NAME)));
|
|
|
125 |
this.l.add(TM.tr(locale, "infoPanel.version"), new JLabel(infos.get(Info.APP_VERSION)));
|
83 |
ilm |
126 |
final String secureLink = infos.get(Info.SECURE_LINK);
|
|
|
127 |
if (secureLink != null) {
|
177 |
ilm |
128 |
this.l.add(TM.tr(locale, "infoPanel.secureLink"), new JLabel(secureLink));
|
83 |
ilm |
129 |
}
|
142 |
ilm |
130 |
final JLabel dbURL = new JLabel(infos.get(Info.DB_URL));
|
|
|
131 |
if (dbURL != null)
|
177 |
ilm |
132 |
this.l.add(TM.tr(locale, "infoPanel.dbURL"), dbURL);
|
142 |
ilm |
133 |
final String dirs = infos.get(Info.DIRS);
|
|
|
134 |
if (dirs != null)
|
177 |
ilm |
135 |
this.l.add(TM.tr(locale, "infoPanel.dirs"), new HTMLTextField(dirs));
|
|
|
136 |
|
|
|
137 |
this.l.getComponent().revalidate();
|
83 |
ilm |
138 |
}
|
41 |
ilm |
139 |
}
|