f9278a615d7061cc45d84538ba05253023a38030
[public/netxms.git] / src / java / netxms-eclipse / Core / src / org / netxms / ui / eclipse / views / AbstractTraceView.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.views;
20
21 import org.eclipse.jface.action.Action;
22 import org.eclipse.jface.action.IMenuManager;
23 import org.eclipse.jface.action.IToolBarManager;
24 import org.eclipse.jface.action.Separator;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.ui.IActionBars;
27 import org.eclipse.ui.contexts.IContextService;
28 import org.eclipse.ui.part.ViewPart;
29 import org.netxms.ui.eclipse.console.Messages;
30 import org.netxms.ui.eclipse.console.resources.SharedIcons;
31 import org.netxms.ui.eclipse.widgets.AbstractTraceWidget;
32
33 /**
34 * Abstract trace view (like event trace)
35 */
36 public abstract class AbstractTraceView extends ViewPart
37 {
38 private AbstractTraceWidget traceWidget;
39 private Action actionClear;
40
41 /* (non-Javadoc)
42 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
43 */
44 @Override
45 public void createPartControl(Composite parent)
46 {
47 traceWidget = createTraceWidget(parent);
48
49 createActions();
50 contributeToActionBars();
51
52 activateContext();
53 }
54
55 /**
56 * @param parent
57 * @return trace widget to be used
58 */
59 protected abstract AbstractTraceWidget createTraceWidget(Composite parent);
60
61 /**
62 * @return
63 */
64 protected AbstractTraceWidget getTraceWidget()
65 {
66 return traceWidget;
67 }
68
69 /**
70 * Activate context
71 */
72 protected void activateContext()
73 {
74 IContextService contextService = (IContextService)getSite().getService(IContextService.class);
75 if (contextService != null)
76 {
77 contextService.activateContext("org.netxms.ui.eclipse.library.context.AbstractTraceView"); //$NON-NLS-1$
78 }
79 }
80
81 /**
82 * Create actions
83 */
84 protected void createActions()
85 {
86 actionClear = new Action(Messages.get().AbstractTraceView_Clear, SharedIcons.CLEAR_LOG) {
87 @Override
88 public void run()
89 {
90 traceWidget.clear();
91 }
92 };
93 }
94
95 /**
96 * Contribute actions to action bar
97 */
98 private void contributeToActionBars()
99 {
100 IActionBars bars = getViewSite().getActionBars();
101 fillLocalPullDown(bars.getMenuManager());
102 fillLocalToolBar(bars.getToolBarManager());
103 }
104
105 /**
106 * Fill local pull-down menu
107 *
108 * @param manager
109 * Menu manager for pull-down menu
110 */
111 protected void fillLocalPullDown(IMenuManager manager)
112 {
113 manager.add(traceWidget.getActionShowFilter());
114 manager.add(new Separator());
115 manager.add(traceWidget.getActionPause());
116 manager.add(actionClear);
117 manager.add(new Separator());
118 manager.add(traceWidget.getActionCopy());
119 }
120
121 /**
122 * Fill local tool bar
123 *
124 * @param manager
125 * Menu manager for local toolbar
126 */
127 protected void fillLocalToolBar(IToolBarManager manager)
128 {
129 manager.add(traceWidget.getActionPause());
130 manager.add(actionClear);
131 }
132
133 /* (non-Javadoc)
134 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
135 */
136 @Override
137 public void setFocus()
138 {
139 traceWidget.setFocus();
140 }
141 }