2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2013 Victor Kirhenshtein
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.
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.
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.
19 package org
.netxms
.ui
.eclipse
.console
;
21 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
22 import org
.eclipse
.jface
.bindings
.BindingManager
;
23 import org
.eclipse
.rap
.rwt
.RWT
;
24 import org
.eclipse
.rap
.rwt
.client
.service
.JavaScriptExecutor
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.custom
.CBanner
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Control
;
29 import org
.eclipse
.swt
.widgets
.Menu
;
30 import org
.eclipse
.swt
.widgets
.Shell
;
31 import org
.eclipse
.ui
.IViewPart
;
32 import org
.eclipse
.ui
.IWorkbenchPage
;
33 import org
.eclipse
.ui
.PartInitException
;
34 import org
.eclipse
.ui
.application
.ActionBarAdvisor
;
35 import org
.eclipse
.ui
.application
.IActionBarConfigurer
;
36 import org
.eclipse
.ui
.application
.IWorkbenchWindowConfigurer
;
37 import org
.eclipse
.ui
.application
.WorkbenchWindowAdvisor
;
38 import org
.eclipse
.ui
.internal
.keys
.BindingService
;
39 import org
.eclipse
.ui
.keys
.IBindingService
;
40 import org
.netxms
.client
.NXCSession
;
41 import org
.netxms
.client
.objects
.AbstractObject
;
42 import org
.netxms
.client
.objects
.Dashboard
;
43 import org
.netxms
.ui
.eclipse
.console
.resources
.RegionalSettings
;
44 import org
.netxms
.ui
.eclipse
.shared
.ConsoleSharedData
;
45 import org
.netxms
.ui
.eclipse
.tools
.MessageDialogHelper
;
48 * Workbench window advisor
50 @SuppressWarnings("restriction")
51 public class ApplicationWorkbenchWindowAdvisor
extends WorkbenchWindowAdvisor
56 public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer
)
62 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#createActionBarAdvisor(org.eclipse.ui.application.IActionBarConfigurer)
64 public ActionBarAdvisor
createActionBarAdvisor(IActionBarConfigurer configurer
)
66 return new ApplicationActionBarAdvisor(configurer
);
70 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#preWindowOpen()
73 public void preWindowOpen()
75 RegionalSettings
.updateFromPreferences();
77 IWorkbenchWindowConfigurer configurer
= getWindowConfigurer();
78 configurer
.setShowPerspectiveBar(true);
79 configurer
.setShowStatusLine(false);
80 configurer
.setTitle(Messages
.get().ApplicationWorkbenchWindowAdvisor_AppTitle
);
81 configurer
.setShellStyle(SWT
.NO_TRIM
);
85 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowCreate()
88 public void postWindowCreate()
90 super.postWindowCreate();
92 NXCSession session
= (NXCSession
)ConsoleSharedData
.getSession();
94 // Changes the page title at runtime
95 JavaScriptExecutor executor
= RWT
.getClient().getService(JavaScriptExecutor
.class);
98 StringBuilder js
= new StringBuilder();
99 js
.append("document.title = "); //$NON-NLS-1$
101 js
.append(Messages
.get().ApplicationWorkbenchWindowAdvisor_AppTitle
);
103 js
.append(session
.getUserName());
105 js
.append(session
.getServerAddress());
108 executor
.execute(js
.toString());
111 BindingService service
= (BindingService
)getWindowConfigurer().getWindow().getWorkbench().getService(IBindingService
.class);
112 BindingManager bindingManager
= service
.getBindingManager();
115 bindingManager
.setActiveScheme(service
.getScheme("org.netxms.ui.eclipse.defaultKeyBinding")); //$NON-NLS-1$
117 catch(NotDefinedException e
)
122 final Shell shell
= getWindowConfigurer().getWindow().getShell();
123 shell
.setMaximized(true);
125 for(Control ctrl
: shell
.getChildren())
127 ctrl
.setData(RWT
.CUSTOM_VARIANT
, "gray"); //$NON-NLS-1$
128 if (ctrl
instanceof CBanner
)
130 for(Control cc
: ((CBanner
)ctrl
).getChildren())
131 cc
.setData(RWT
.CUSTOM_VARIANT
, "gray"); //$NON-NLS-1$
133 else if (ctrl
.getClass().getName().equals("org.eclipse.swt.widgets.Composite")) //$NON-NLS-1$
135 for(Control cc
: ((Composite
)ctrl
).getChildren())
136 cc
.setData(RWT
.CUSTOM_VARIANT
, "gray"); //$NON-NLS-1$
140 Menu menuBar
= shell
.getMenuBar();
142 menuBar
.setData(RWT
.CUSTOM_VARIANT
, "menuBar"); //$NON-NLS-1$
146 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowOpen()
149 public void postWindowOpen()
151 String dashboardId
= RWT
.getRequest().getParameter("dashboard"); //$NON-NLS-1$
152 if (dashboardId
!= null)
153 showDashboard(dashboardId
);
161 private void showDashboard(String dashboardId
)
163 NXCSession session
= (NXCSession
)ConsoleSharedData
.getSession();
168 objectId
= Long
.parseLong(dashboardId
);
170 catch(NumberFormatException e
)
172 AbstractObject object
= session
.findObjectByName(dashboardId
);
173 if ((object
== null) || !(object
instanceof Dashboard
))
175 MessageDialogHelper
.openError(null, Messages
.get().ApplicationWorkbenchWindowAdvisor_Error
, String
.format(Messages
.get().ApplicationWorkbenchWindowAdvisor_CannotOpenDashboard
, dashboardId
));
178 objectId
= object
.getObjectId();
181 Dashboard dashboard
= (Dashboard
)session
.findObjectById(objectId
, Dashboard
.class);
182 if (dashboard
== null)
184 MessageDialogHelper
.openError(null, Messages
.get().ApplicationWorkbenchWindowAdvisor_Error
, String
.format(Messages
.get().ApplicationWorkbenchWindowAdvisor_CannotOpenDashboard
, dashboardId
));
188 IWorkbenchPage page
= getWindowConfigurer().getWindow().getActivePage();
191 IViewPart view
= page
.showView("org.netxms.ui.eclipse.dashboard.views.DashboardView", Long
.toString(objectId
), IWorkbenchPage
.VIEW_ACTIVATE
); //$NON-NLS-1$
192 page
.setPartState(page
.getReference(view
), IWorkbenchPage
.STATE_MAXIMIZED
);
194 catch(PartInitException e
)
196 MessageDialogHelper
.openError(null, Messages
.get().ApplicationWorkbenchWindowAdvisor_Error
, String
.format(Messages
.get().ApplicationWorkbenchWindowAdvisor_CannotOpenDashboardType2
, dashboardId
, e
.getLocalizedMessage()));
201 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowClose()
204 public void postWindowClose()
206 super.postWindowClose();
207 JavaScriptExecutor executor
= RWT
.getClient().getService(JavaScriptExecutor
.class);
208 if (executor
!= null)
209 executor
.execute("location.reload(true);");