1 /*******************************************************************************
2 * Copyright (c) 2013 hangum.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the GNU Lesser Public License v2.1
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
9 * hangum - initial API and implementation
10 ******************************************************************************/
11 package com
.hangum
.tadpole
.preference
.ui
;
13 import java
.util
.Locale
;
15 import javax
.servlet
.http
.Cookie
;
16 import javax
.servlet
.http
.HttpServletRequest
;
18 import org
.apache
.commons
.lang
.math
.NumberUtils
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
21 import org
.eclipse
.rap
.rwt
.RWT
;
22 import org
.eclipse
.swt
.SWT
;
23 import org
.eclipse
.swt
.events
.ModifyEvent
;
24 import org
.eclipse
.swt
.events
.ModifyListener
;
25 import org
.eclipse
.swt
.events
.SelectionAdapter
;
26 import org
.eclipse
.swt
.events
.SelectionEvent
;
27 import org
.eclipse
.swt
.layout
.GridData
;
28 import org
.eclipse
.swt
.layout
.GridLayout
;
29 import org
.eclipse
.swt
.widgets
.Button
;
30 import org
.eclipse
.swt
.widgets
.Combo
;
31 import org
.eclipse
.swt
.widgets
.Composite
;
32 import org
.eclipse
.swt
.widgets
.Control
;
33 import org
.eclipse
.swt
.widgets
.Label
;
34 import org
.eclipse
.swt
.widgets
.Text
;
35 import org
.eclipse
.ui
.IWorkbench
;
36 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
38 import com
.hangum
.tadpole
.commons
.google
.analytics
.AnalyticCaller
;
39 import com
.hangum
.tadpole
.commons
.libs
.core
.define
.PublicTadpoleDefine
;
40 import com
.hangum
.tadpole
.commons
.libs
.core
.message
.CommonMessages
;
41 import com
.hangum
.tadpole
.commons
.util
.CookieUtils
;
42 import com
.hangum
.tadpole
.preference
.Messages
;
43 import com
.hangum
.tadpole
.preference
.define
.PreferenceDefine
;
44 import com
.hangum
.tadpole
.preference
.get
.GetPreferenceGeneral
;
45 import com
.hangum
.tadpole
.session
.manager
.SessionManager
;
53 public class GeneralPreferencePage
extends TadpoleDefaulPreferencePage
implements IWorkbenchPreferencePage
{
54 private static final Logger logger
= Logger
.getLogger(GeneralPreferencePage
.class);
56 private Label lblLanguage
;
57 private Combo comboLanguage
;
59 private Text textSessionTime
;
60 private Text textExportDelimit
;
61 private Text textHomePage
;
62 private Button btnCheckButtonHomepage
;
64 public static final int SESSION_TIMEOUT_MIN
= 5; /* minutes */
65 public static final int SESSION_TIMEOUT_MAX
= 300; /* minutes */
66 public static final int SESSION_TIMEOUT_DEFAULT
= 180; /* minutes */
68 public GeneralPreferencePage() {
72 public void init(IWorkbench workbench
) {
76 protected Control
createContents(Composite parent
) {
77 Composite container
= new Composite(parent
, SWT
.NULL
);
78 container
.setLayout(new GridLayout(2, false));
80 lblLanguage
= new Label(container
, SWT
.NONE
);
81 lblLanguage
.setText(Messages
.get().LoginDialog_lblLanguage_text
);
83 comboLanguage
= new Combo(container
, SWT
.READ_ONLY
);
84 comboLanguage
.addSelectionListener(new SelectionAdapter() {
86 public void widgetSelected(SelectionEvent e
) {
87 changeUILocale(comboLanguage
.getText());
90 comboLanguage
.add(Locale
.ENGLISH
.getDisplayLanguage(Locale
.ENGLISH
));
91 comboLanguage
.add(Locale
.KOREAN
.getDisplayLanguage(Locale
.KOREAN
));
92 comboLanguage
.setData(Locale
.ENGLISH
.getDisplayLanguage(Locale
.ENGLISH
), Locale
.ENGLISH
);
93 comboLanguage
.setData(Locale
.KOREAN
.getDisplayLanguage(Locale
.KOREAN
), Locale
.KOREAN
);
95 Label lblNewLabel
= new Label(container
, SWT
.NONE
);
96 lblNewLabel
.setText(Messages
.get().SessionTimeout_mins
);
98 textSessionTime
= new Text(container
, SWT
.BORDER
);
99 textSessionTime
.addModifyListener(new ModifyListener() {
100 public void modifyText(ModifyEvent event
) {
104 textSessionTime
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
105 if(PublicTadpoleDefine
.YES_NO
.NO
.name().equals(SessionManager
.getIsModifyPerference())) {
106 textSessionTime
.setEditable(false);
107 textSessionTime
.setEnabled(false);
110 Label lblExportDilimit
= new Label(container
, SWT
.NONE
);
111 lblExportDilimit
.setText(Messages
.get().GeneralPreferencePage_lblExportDilimit_text
);
113 textExportDelimit
= new Text(container
, SWT
.BORDER
);
114 textExportDelimit
.setText(",");
115 textExportDelimit
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
117 Label lblHomePage
= new Label(container
, SWT
.NONE
);
118 lblHomePage
.setText(Messages
.get().GeneralPreferencePage_lblHomePage_text
);
120 textHomePage
= new Text(container
, SWT
.BORDER
);
121 textHomePage
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false, 1, 1));
122 new Label(container
, SWT
.NONE
);
124 btnCheckButtonHomepage
= new Button(container
, SWT
.CHECK
);
125 btnCheckButtonHomepage
.setText(Messages
.get().GeneralPreferencePage_btnCheckButton_text
);
126 btnCheckButtonHomepage
.setSelection(true);
131 AnalyticCaller
.track(this.getClass().getName());
137 public boolean isValid() {
138 String txtSessionTime
= textSessionTime
.getText();
140 if(!NumberUtils
.isNumber(txtSessionTime
)) {
141 textSessionTime
.setFocus();
143 setErrorMessage(Messages
.get().SessionTimeout_mins
+ CommonMessages
.get().EnterNumbersOnly
);
146 } else if(!((NumberUtils
.toInt(txtSessionTime
) >= SESSION_TIMEOUT_MIN
)
147 && (NumberUtils
.toInt(txtSessionTime
) <= SESSION_TIMEOUT_MAX
))) {
148 textSessionTime
.setFocus();
150 setErrorMessage(String
.format(CommonMessages
.get().InvalidRange_GEAndLEWithItem
,
151 Messages
.get().SessionTimeout_mins
, SESSION_TIMEOUT_MIN
, SESSION_TIMEOUT_MAX
));
156 setErrorMessage(null);
165 * @param strComoboStr
167 private void changeUILocale(String strComoboStr
) {
168 Locale localeSelect
= (Locale
)comboLanguage
.getData(strComoboStr
);
169 RWT
.getUISession().setLocale(localeSelect
);
173 public boolean performOk() {
174 if(!isValid()) return false;
176 String strLocale
= comboLanguage
.getText();
177 String txtSessionTime
= textSessionTime
.getText();
178 String txtExportDelimit
= textExportDelimit
.getText();
179 String txtHomePage
= textHomePage
.getText();
180 String txtHomePageUse
= ""+btnCheckButtonHomepage
.getSelection();
183 Locale locale
= (Locale
)comboLanguage
.getData(strLocale
);
184 CookieUtils
.saveCookie(PublicTadpoleDefine
.TDB_COOKIE_USER_LANGUAGE
, locale
.toLanguageTag());
185 RWT
.getUISession().setLocale(locale
);
189 updateInfo(PreferenceDefine
.SESSION_DFEAULT_PREFERENCE
, txtSessionTime
);
190 updateInfo(PreferenceDefine
.EXPORT_DILIMITER
, txtExportDelimit
);
191 updateInfo(PreferenceDefine
.DEFAULT_HOME_PAGE
, txtHomePage
);
192 updateInfo(PreferenceDefine
.DEFAULT_HOME_PAGE_USE
, txtHomePageUse
);
193 } catch(Exception e
) {
194 logger
.error("GeneralPreference saveing", e
);
196 MessageDialog
.openError(getShell(), CommonMessages
.get().Confirm
, Messages
.get().GeneralPreferencePage_2
+ e
.getMessage()); //$NON-NLS-1$
200 return super.performOk();
204 public boolean performCancel() {
207 return super.performCancel();
211 protected void performApply() {
213 super.performApply();
217 protected void performDefaults() {
220 super.performDefaults();
226 private void initLocale() {
228 // 개인 사용자는 기본 언어가 없을 수 있으므로..
229 HttpServletRequest request
= RWT
.getRequest();
230 Cookie
[] cookies
= request
.getCookies();
232 boolean isExist
= false;
233 if(cookies
!= null) {
234 for (Cookie cookie
: cookies
) {
235 if(PublicTadpoleDefine
.TDB_COOKIE_USER_LANGUAGE
.equals(cookie
.getName())) {
237 Locale locale
= Locale
.forLanguageTag(cookie
.getValue());
238 comboLanguage
.setText(locale
.getDisplayLanguage(locale
));
240 changeUILocale(comboLanguage
.getText());
248 // 세션에 기본 로케일이 지정되어 있지 않으면.
249 if(!isExist
) comboLanguage
.setText(Locale
.ENGLISH
.getDisplayLanguage(Locale
.ENGLISH
));
256 private void initDefaultValue() {
259 textSessionTime
.setText(GetPreferenceGeneral
.getValue(PreferenceDefine
.SESSION_DFEAULT_PREFERENCE
, PreferenceDefine
.SESSION_SERVER_DEFAULT_PREFERENCE_VALUE
));//"" + GetPreferenceGeneral.getSessionTimeout() ); //$NON-NLS-1$
260 textExportDelimit
.setText(GetPreferenceGeneral
.getValue(PreferenceDefine
.EXPORT_DILIMITER
, PreferenceDefine
.EXPORT_DILIMITER_VALUE
));// "" + GetPreferenceGeneral.getExportDelimit() ); //$NON-NLS-1$
261 textHomePage
.setText(GetPreferenceGeneral
.getValue(PreferenceDefine
.DEFAULT_HOME_PAGE
, PreferenceDefine
.DEFAULT_HOME_PAGE_VALUE
)); //$NON-NLS-1$
263 String use
= GetPreferenceGeneral
.getValue(PreferenceDefine
.DEFAULT_HOME_PAGE_USE
, PreferenceDefine
.DEFAULT_HOME_PAGE_USE_VALUE
);//GetPreferenceGeneral.getDefaultHomePageUse();
264 if(Boolean
.parseBoolean(use
)) {
265 btnCheckButtonHomepage
.setSelection(true);
267 btnCheckButtonHomepage
.setSelection(false);