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
.application
.start
;
13 import java
.sql
.Timestamp
;
14 import java
.util
.HashMap
;
15 import java
.util
.List
;
16 import java
.util
.Locale
;
19 import javax
.servlet
.http
.Cookie
;
20 import javax
.servlet
.http
.HttpServletRequest
;
21 import javax
.servlet
.http
.HttpSession
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.eclipse
.jface
.dialogs
.Dialog
;
25 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
26 import org
.eclipse
.rap
.rwt
.RWT
;
27 import org
.eclipse
.rap
.rwt
.client
.service
.ExitConfirmation
;
28 import org
.eclipse
.swt
.SWT
;
29 import org
.eclipse
.swt
.widgets
.Display
;
30 import org
.eclipse
.swt
.widgets
.Shell
;
31 import org
.eclipse
.ui
.PlatformUI
;
32 import org
.eclipse
.ui
.application
.ActionBarAdvisor
;
33 import org
.eclipse
.ui
.application
.IActionBarConfigurer
;
34 import org
.eclipse
.ui
.application
.IWorkbenchWindowConfigurer
;
35 import org
.eclipse
.ui
.application
.WorkbenchWindowAdvisor
;
37 import com
.hangum
.tadpole
.commons
.libs
.core
.define
.PublicTadpoleDefine
;
38 import com
.hangum
.tadpole
.commons
.libs
.core
.define
.SystemDefine
;
39 import com
.hangum
.tadpole
.commons
.libs
.core
.message
.CommonMessages
;
40 import com
.hangum
.tadpole
.commons
.util
.ApplicationArgumentUtils
;
41 import com
.hangum
.tadpole
.commons
.util
.IPUtil
;
42 import com
.hangum
.tadpole
.commons
.util
.RequestInfoUtils
;
43 import com
.hangum
.tadpole
.engine
.manager
.TadpoleApplicationContextManager
;
44 import com
.hangum
.tadpole
.engine
.query
.dao
.system
.UserDAO
;
45 import com
.hangum
.tadpole
.engine
.query
.dao
.system
.UserInfoDataDAO
;
46 import com
.hangum
.tadpole
.engine
.query
.sql
.TadpoleSystem_UserInfoData
;
47 import com
.hangum
.tadpole
.engine
.query
.sql
.TadpoleSystem_UserQuery
;
48 import com
.hangum
.tadpole
.engine
.utils
.HttpSessionCollectorUtil
;
49 import com
.hangum
.tadpole
.login
.core
.dialog
.LoginDialog
;
50 import com
.hangum
.tadpole
.preference
.get
.GetPreferenceGeneral
;
51 import com
.hangum
.tadpole
.session
.manager
.SessionManager
;
54 * Configures the initial size and appearance of a workbench window.
56 public class ApplicationWorkbenchWindowAdvisor
extends WorkbenchWindowAdvisor
{
57 private static final Logger logger
= Logger
.getLogger(ApplicationWorkbenchWindowAdvisor
.class);
60 // final ServerPushSession pushSession = new ServerPushSession();
61 // private boolean isUIThreadRunning = true;
63 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer
) {
67 public ActionBarAdvisor
createActionBarAdvisor(IActionBarConfigurer configurer
) {
68 return new ApplicationActionBarAdvisor(configurer
);
71 public void preWindowOpen() {
72 // if("YES".equals(GetAdminPreference.getSupportMonitoring())) {
74 // logger.info("Schedule and Summary Report start.........");
75 // DBSummaryReporter.executer();
76 // ScheduleManager.getInstance();
77 // } catch(Exception e) {
78 // logger.error("Schedule", e);
82 // not support rap yet.
83 // String prop = IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS;
84 // PlatformUI.getPreferenceStore().setValue(prop, false);
86 IWorkbenchWindowConfigurer configurer
= getWindowConfigurer();
88 // remove this line(fixed at https://github.com/hangum/TadpoleForDBTools/issues/350)
89 // configurer.setInitialSize(new Point(Display.getCurrent().getBounds().width, Display.getCurrent().getBounds().height));
90 configurer
.setShowCoolBar(true);
91 configurer
.setShowStatusLine(false);
92 configurer
.setShowMenuBar(true);
93 configurer
.setShowProgressIndicator(false);
94 configurer
.setTitle(SystemDefine
.getDBHubSystemInfo()); //$NON-NLS-1$ //$NON-NLS-2$
97 getWindowConfigurer().setShellStyle(SWT
.NO_TRIM
);
98 getWindowConfigurer().setShowMenuBar(true);
100 // Set system exist message.
101 ExitConfirmation service
= RWT
.getClient().getService( ExitConfirmation
.class );
102 service
.setMessage(Messages
.get().ApplicationWorkbenchWindowAdvisor_4
);
104 // checkSupportBrowser();
111 private void login() {
113 if(ApplicationArgumentUtils
.isTestLogin()) {
115 RWT
.getUISession().setLocale(Locale
.ENGLISH
);
117 UserDAO userDao
= new UserDAO();
119 userDao
.setName("test user");
120 userDao
.setEmail("admin@tadpolehub.com");
121 userDao
.setRole_type("SYSTEM_ADMIN");
122 userDao
.setIs_modify_perference("YES");
123 userDao
.setService_start(new Timestamp(System
.currentTimeMillis()-100000));
124 userDao
.setService_end(new Timestamp(System
.currentTimeMillis()+100000000));
125 SessionManager
.addSession(userDao
, SessionManager
.LOGIN_IP_TYPE
.BROWSER_IP
.name(), "127.0.0.1");
126 initializeUserSession();
130 if(SessionManager
.isLogin()) return;
133 if(TadpoleApplicationContextManager
.isPersonOperationType()) {
134 UserDAO userDao
= TadpoleSystem_UserQuery
.findUser(PublicTadpoleDefine
.SYSTEM_DEFAULT_USER
);
136 String strAllowIP
= userDao
.getAllow_ip();
137 boolean isAllow
= IPUtil
.ifFilterString(strAllowIP
, RequestInfoUtils
.getRequestIP());
138 if(logger
.isDebugEnabled())logger
.debug(Messages
.get().LoginDialog_21
+ userDao
.getEmail() + Messages
.get().LoginDialog_22
+ strAllowIP
+ Messages
.get().LoginDialog_23
+ RequestInfoUtils
.getRequestIP());
140 logger
.error(Messages
.get().LoginDialog_21
+ userDao
.getEmail() + Messages
.get().LoginDialog_22
+ strAllowIP
+ Messages
.get().LoginDialog_26
+ RequestInfoUtils
.getRequestIP());
141 MessageDialog
.openWarning(null, CommonMessages
.get().Warning
, Messages
.get().LoginDialog_28
);
145 SessionManager
.addSession(userDao
, SessionManager
.LOGIN_IP_TYPE
.SERVLET_REQUEST
.name(), RequestInfoUtils
.getRequestIP());
146 // save login_history
147 TadpoleSystem_UserQuery
.saveLoginHistory(userDao
.getSeq(), RequestInfoUtils
.getRequestIP());
149 initializeUserSession();
151 initializeDefaultLocale();
153 LoginDialog loginDialog
= new LoginDialog(Display
.getCurrent().getActiveShell());
154 if(Dialog
.OK
== loginDialog
.open()) {
155 initializeUserSession();
159 // 중복 로그인 방지를 위해 세션을 기록합니다.
160 HttpSessionCollectorUtil
.getInstance().sessionCreated(SessionManager
.getEMAIL(), RWT
.getRequest().getSession(), Integer
.parseInt(GetPreferenceGeneral
.getSessionTimeout()));
162 } catch (Exception e
) {
163 logger
.error("System login fail", e
); //$NON-NLS-1$
164 MessageDialog
.openError(null, CommonMessages
.get().Confirm
, "System login fail. Please contact admin"); //$NON-NLS-1$ //$NON-NLS-2$
170 * initialize default locale
172 private void initializeDefaultLocale() {
173 HttpServletRequest request
= RWT
.getRequest();
174 Cookie
[] cookies
= request
.getCookies();
176 if(cookies
!= null) {
177 for (Cookie cookie
: cookies
) {
178 if(PublicTadpoleDefine
.TDB_COOKIE_USER_LANGUAGE
.equals(cookie
.getName())) {
179 if(cookie
.getValue().equalsIgnoreCase(Locale
.ENGLISH
.getDisplayLanguage(Locale
.ENGLISH
))) {
180 RWT
.getUISession().setLocale(Locale
.ENGLISH
);
181 } else if(cookie
.getValue().equalsIgnoreCase(Locale
.ENGLISH
.getDisplayLanguage(Locale
.KOREAN
))) {
182 RWT
.getUISession().setLocale(Locale
.KOREAN
);
191 * initialize user session
193 private void initializeUserSession() {
195 // Stored user session.
196 List
<UserInfoDataDAO
> listUserInfo
= TadpoleSystem_UserInfoData
.getUserInfoData();
197 Map
<String
, Object
> mapUserInfoData
= new HashMap
<String
, Object
>();
198 for (UserInfoDataDAO userInfoDataDAO
: listUserInfo
) {
199 mapUserInfoData
.put(userInfoDataDAO
.getName(), userInfoDataDAO
);
201 SessionManager
.setUserAllPreferenceData(mapUserInfoData
);
203 // final String strRepresentRole = SessionManager.getRepresentRole();
204 // if(strRepresentRole.equals(PublicTadpoleDefine.USER_ROLE_TYPE.API_USER.name())) {
205 // SessionManager.setPerspective(Perspective.APIUSER);
207 // SessionManager.setPerspective(Perspective.DEFAULT);
209 // if ("".equals(SessionManager.getPerspective())) { //$NON-NLS-1$
210 // SessionManager.setPerspective(Perspective.DEFAULT);
212 // // user 사용자는 default perspective를 사용합니다.
213 // if(PublicTadpoleDefine.USER_TYPE.USER.toString().equals(SessionManager.getRepresentRole())) {
214 // SessionManager.setPerspective(Perspective.DEFAULT);
217 // SelectPerspectiveDialog dialog = new SelectPerspectiveDialog(Display.getCurrent().getActiveShell());
219 // if (Dialog.OK == dialog.open()) {
220 // persp = dialog.getResult();
222 // persp = Perspective.DEFAULT;
224 // SessionManager.setPerspective(persp);
230 } catch(Exception e
) {
231 logger
.error("session set", e
); //$NON-NLS-1$
236 * Set initialize session
238 private void initSession() {
239 HttpSession iss
= RWT
.getUISession().getHttpSession();
241 final int sessionTimeOut
= Integer
.parseInt(GetPreferenceGeneral
.getSessionTimeout());
242 if(sessionTimeOut
<= 0) {
243 iss
.setMaxInactiveInterval(90 * 60);
245 iss
.setMaxInactiveInterval(sessionTimeOut
* 60);
249 // RWT.getUISession().addUISessionListener( new UISessionListener() {
250 // public void beforeDestroy( UISessionEvent event ) {
251 // logger.info(String.format("User has logout. session id is %s", event.getUISession().getId()));
257 public void postWindowCreate() {
258 Shell shell
= getWindowConfigurer().getWindow().getShell();
260 shell
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getShell();
262 shell
.setMaximized(true);
266 // public boolean preWindowShellClose() {
267 // logger.debug("======================> preShutdown execute ================");
268 // ScheduleManager.getInstance().stopSchedule();
269 // logger.debug("======================> preShutdown execute ================");
271 // return super.preWindowShellClose();
275 // * new version checker (특정 사용환경에만 사용할 수 있도록 하기 위해 주석 처리)
277 // private void newVersionChecker() {
279 // if(!CookieUtils.isUpdateChecker()) {
280 // boolean isNew = NewVersionChecker.getInstance().check();
282 // NewVersionObject newVersionObj = NewVersionChecker.getInstance().getNewVersionObj();
283 // NewVersionViewDialog dialog = new NewVersionViewDialog(null, newVersionObj);
286 // } // is update checker
291 public void postWindowOpen() {
292 // if(ApplicationArgumentUtils.isOnlineServer()) return;
293 // if(SessionManager.isSystemAdmin()) {
294 // newVersionChecker();
298 // getWindowConfigurer().getWindow().getShell().setMaximized(true);
300 // 쪽지 기능의 역할에 비해 리소스를 너무 많이 먹는 것으로 판단되어 기능을 막습니다.
301 // 더 의미를 찾을때까지요. - 14.08.25
303 // main ui callback thread
306 // If login after does not DB exist, DB connect Dialog open.
308 //// // fix https://github.com/hangum/TadpoleForDBTools/issues/221
309 // ManagerViewer mv = (ManagerViewer)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(ManagerViewer.ID);
310 // if(0 == mv.getAllTreeList().size()) {
311 // if(MessageDialog.openConfirm(null, Messages.get().ApplicationWorkbenchWindowAdvisor_0, Messages.get().ApplicationWorkbenchWindowAdvisor_3)) {
312 // ConnectDatabase cd = new ConnectDatabase();
316 // } catch(Exception e) {
317 // logger.error("Is DB list?", e); //$NON-NLS-1$
323 // * check support browser
325 // private void checkSupportBrowser() {
327 // // // Add HttpListener(User data collection
328 // // System.out.println("================= start add session ==========================");
329 // // TadpoleSessionListener listener = new TadpoleSessionListener();
330 // // RWT.getUISession().getHttpSession().getServletContext().addListener(listener);//"com.hangum.tadpole.application.start.sessions.TadpoleSessionListener");
331 // // System.out.println("================= end add session ==========================");
332 // // } catch(Exception e) {
333 // // e.printStackTrace();
336 // // Show Information Dialog(Is not Firefox, Chrome, Safari)
337 //// if(!RequestInfoUtils.isSupportBrowser()) {
338 //// UserInformationDialog uiDialog = new UserInformationDialog(Display.getCurrent().getActiveShell(), RequestInfoUtils.getUserBrowser());
339 //// uiDialog.open();
344 // * 시스템에서 사용자에게 메시지를 전해 줍니다.
347 // private void mainUICallback() {
348 // final Display display = PlatformUI.getWorkbench().getDisplay();
350 // Runnable runnable = new Runnable() {
351 // public void run() {
352 // while(isUIThreadRunning) {
354 // if(display.isDisposed()) {
355 // isUIThreadRunning = false;
359 // display.asyncExec( new Runnable() {
360 // public void run() {
363 // List<NotesDAO> listNotes = NoteSystemAlert.getSystemNoteAlert();
364 // if(!listNotes.isEmpty()) {
365 // // refresh note view
366 // NoteListViewPart nlvPart = (NoteListViewPart)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(NoteListViewPart.ID);
367 // nlvPart.initData();
370 // for (NotesDAO notesDAO : listNotes) {
371 // ViewDialog dialog = new ViewDialog(display.getActiveShell(), notesDAO, NotesDefine.NOTE_TYPES.RECEIVE);
379 // } catch(Exception e) {
380 // logger.error("main ui call", e);
384 // Thread.sleep(20 * 1000);
385 // } catch(Exception e){}
390 // pushSession.start();
391 // new Thread(runnable).start();