a5e1e6fd3dd06b2a0e370c7f833a42bc0bbf941e
[public/netxms.git] / webui / webapp / DataCollection / src / org / netxms / ui / eclipse / datacollection / dialogs / EditTableThresholdDialog.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.datacollection.dialogs;
20
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.GridData;
24 import org.eclipse.swt.layout.GridLayout;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.swt.widgets.Control;
27 import org.eclipse.swt.widgets.Label;
28 import org.eclipse.swt.widgets.Shell;
29 import org.netxms.client.datacollection.TableThreshold;
30 import org.netxms.ui.eclipse.datacollection.Messages;
31 import org.netxms.ui.eclipse.datacollection.propertypages.TableColumns.TableColumnDataProvider;
32 import org.netxms.ui.eclipse.datacollection.widgets.TableConditionsEditor;
33 import org.netxms.ui.eclipse.eventmanager.widgets.EventSelector;
34 import org.netxms.ui.eclipse.tools.WidgetHelper;
35
36 /**
37 * Table threshold editing dialog
38 */
39 public class EditTableThresholdDialog extends Dialog
40 {
41 private TableThreshold threshold;
42 private EventSelector activationEvent;
43 private EventSelector deactivationEvent;
44 private TableConditionsEditor conditionsEditor;
45 private TableColumnDataProvider columnCallback;
46
47 /**
48 * @param parentShell
49 * @param threshold
50 */
51 public EditTableThresholdDialog(Shell parentShell, TableThreshold threshold, TableColumnDataProvider columnCallback)
52 {
53 super(parentShell);
54 this.threshold = threshold;
55 this.columnCallback = columnCallback;
56 }
57
58 /* (non-Javadoc)
59 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
60 */
61 @Override
62 protected void configureShell(Shell newShell)
63 {
64 super.configureShell(newShell);
65 newShell.setText(Messages.get().EditTableThresholdDialog_Title);
66 }
67
68 /* (non-Javadoc)
69 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
70 */
71 @Override
72 protected Control createDialogArea(Composite parent)
73 {
74 Composite dialogArea = (Composite)super.createDialogArea(parent);
75
76 GridLayout layout = new GridLayout();
77 layout.verticalSpacing = WidgetHelper.DIALOG_SPACING;
78 dialogArea.setLayout(layout);
79
80 activationEvent = new EventSelector(dialogArea, SWT.NONE);
81 activationEvent.setLabel(Messages.get().EditTableThresholdDialog_ActivationEvent);
82 activationEvent.setEventCode(threshold.getActivationEvent());
83 activationEvent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
84
85 deactivationEvent = new EventSelector(dialogArea, SWT.NONE);
86 deactivationEvent.setLabel(Messages.get().EditTableThresholdDialog_DeactivationEvent);
87 deactivationEvent.setEventCode(threshold.getDeactivationEvent());
88 deactivationEvent.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
89
90 new Label(dialogArea, SWT.NONE).setText(Messages.get().EditTableThresholdDialog_Conditions);
91
92 conditionsEditor = new TableConditionsEditor(dialogArea, SWT.BORDER, columnCallback);
93 GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
94 gd.widthHint = 700;
95 gd.heightHint = 400;
96 conditionsEditor.setLayoutData(gd);
97 conditionsEditor.setConditions(threshold.getConditions());
98
99 return dialogArea;
100 }
101
102 /* (non-Javadoc)
103 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
104 */
105 @Override
106 protected void okPressed()
107 {
108 threshold.setActivationEvent((int)activationEvent.getEventCode());
109 threshold.setDeactivationEvent((int)deactivationEvent.getEventCode());
110 threshold.setConditions(conditionsEditor.getConditions());
111 super.okPressed();
112 }
113 }