ce96e4cc52b508339e2b78d088eea0cdfda88ba9
[public/netxms.git] / webui / webapp / Core / src / org / netxms / ui / eclipse / console / Application.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2013 Victor Kirhenshtein
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 package org.netxms.ui.eclipse.console;
20
21 import java.util.Locale;
22 import java.util.Properties;
23 import java.util.TimeZone;
24 import org.eclipse.equinox.app.IApplication;
25 import org.eclipse.equinox.app.IApplicationContext;
26 import org.eclipse.rap.rwt.RWT;
27 import org.eclipse.rap.rwt.client.service.ClientInfo;
28 import org.eclipse.swt.widgets.Display;
29 import org.eclipse.ui.PlatformUI;
30 import org.eclipse.ui.application.WorkbenchAdvisor;
31 import org.netxms.client.NXCSession;
32 import org.netxms.ui.eclipse.console.resources.SharedIcons;
33 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
34
35 /**
36 * This class controls all aspects of the application's execution and is
37 * contributed through the plugin.xml.
38 */
39 public class Application implements IApplication
40 {
41 /* (non-Javadoc)
42 * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
43 */
44 public Object start(IApplicationContext context) throws Exception
45 {
46 String lang = RWT.getRequest().getParameter("lang"); //$NON-NLS-1$
47 if (lang != null)
48 RWT.setLocale(new Locale(lang));
49
50 final Properties properties = new AppPropertiesLoader().load();
51 int timeout;
52 try
53 {
54 timeout = Integer.parseInt(properties.getProperty("sessionTimeout", "600"));
55 }
56 catch(NumberFormatException e)
57 {
58 timeout = 600;
59 }
60
61 final Display display = PlatformUI.createDisplay();
62 RWT.getUISession().getHttpSession().setMaxInactiveInterval(timeout);
63 display.disposeExec(new Runnable() {
64 public void run()
65 {
66 NXCSession session = ConsoleSharedData.getSession();
67 if (session != null)
68 session.disconnect();
69 }
70 });
71
72 ClientInfo clientInfo = RWT.getClient().getService(ClientInfo.class);
73 if (clientInfo != null)
74 {
75 String[] tzList = TimeZone.getAvailableIDs(-clientInfo.getTimezoneOffset() * 60000); // convert offset in minutes to milliseconds (in RAP - means ahead of UTC)
76 if (tzList.length > 0)
77 {
78 RWT.getUISession().setAttribute(ConsoleSharedData.ATTRIBUTE_TIMEZONE, TimeZone.getTimeZone(tzList[0]));
79 }
80 }
81
82 SharedIcons.init(display);
83 WorkbenchAdvisor advisor = new ApplicationWorkbenchAdvisor();
84 return PlatformUI.createAndRunWorkbench(display, advisor);
85 }
86
87 /* (non-Javadoc)
88 * @see org.eclipse.equinox.app.IApplication#stop()
89 */
90 public void stop()
91 {
92 // Do nothing
93 }
94 }