eaf5d8e7852483f8e178b1396f8d626af427d471
[public/netxms.git] / src / java / netxms-eclipse / ObjectTools / src / org / netxms / ui / eclipse / objecttools / propertypages / Filter.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2011 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.objecttools.propertypages;
20
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.events.SelectionEvent;
23 import org.eclipse.swt.events.SelectionListener;
24 import org.eclipse.swt.layout.GridData;
25 import org.eclipse.swt.layout.GridLayout;
26 import org.eclipse.swt.widgets.Button;
27 import org.eclipse.swt.widgets.Composite;
28 import org.eclipse.swt.widgets.Control;
29 import org.eclipse.swt.widgets.Text;
30 import org.eclipse.ui.dialogs.PropertyPage;
31 import org.netxms.client.objecttools.ObjectTool;
32 import org.netxms.client.objecttools.ObjectToolDetails;
33 import org.netxms.ui.eclipse.tools.WidgetHelper;
34
35 /**
36 * "Filter" property page for object tool
37 *
38 */
39 public class Filter extends PropertyPage
40 {
41 private ObjectToolDetails objectTool;
42 private Button checkAgent;
43 private Button checkSNMP;
44 private Button checkMatchOID;
45 private Text textOID;
46
47 /* (non-Javadoc)
48 * @see org.eclipse.jface.preference.PreferencePage#createControl(org.eclipse.swt.widgets.Composite)
49 */
50 @Override
51 public void createControl(Composite parent)
52 {
53 noDefaultAndApplyButton();
54 super.createControl(parent);
55 }
56
57 /* (non-Javadoc)
58 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
59 */
60 @Override
61 protected Control createContents(Composite parent)
62 {
63 objectTool = (ObjectToolDetails)getElement().getAdapter(ObjectToolDetails.class);
64
65 Composite dialogArea = new Composite(parent, SWT.NONE);
66
67 GridLayout layout = new GridLayout();
68 layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
69 layout.marginWidth = 0;
70 layout.marginHeight = 0;
71 dialogArea.setLayout(layout);
72
73 checkAgent = new Button(dialogArea, SWT.CHECK);
74 checkAgent.setText("NetXMS agent should be available");
75 checkAgent.setSelection((objectTool.getFlags() & ObjectTool.REQUIRES_AGENT) != 0);
76
77 checkSNMP = new Button(dialogArea, SWT.CHECK);
78 checkSNMP.setText("Node should support SNMP");
79 checkSNMP.setSelection((objectTool.getFlags() & ObjectTool.REQUIRES_SNMP) != 0);
80
81 checkMatchOID = new Button(dialogArea, SWT.CHECK);
82 checkMatchOID.setText("Node SNMP OID should match with the following template:");
83 checkMatchOID.setSelection((objectTool.getFlags() & ObjectTool.REQUIRES_OID_MATCH) != 0);
84 checkMatchOID.addSelectionListener(new SelectionListener() {
85 @Override
86 public void widgetSelected(SelectionEvent e)
87 {
88 textOID.setEnabled(checkMatchOID.getSelection());
89 if (checkMatchOID.getSelection())
90 textOID.setFocus();
91 }
92
93 @Override
94 public void widgetDefaultSelected(SelectionEvent e)
95 {
96 widgetSelected(e);
97 }
98 });
99
100 textOID = new Text(dialogArea, SWT.BORDER);
101 textOID.setText(objectTool.getSnmpOid());
102 GridData gd = new GridData();
103 gd.horizontalAlignment = SWT.FILL;
104 gd.grabExcessHorizontalSpace = true;
105 gd.horizontalIndent = 20;
106 textOID.setLayoutData(gd);
107 textOID.setEnabled(checkMatchOID.getSelection());
108
109 return dialogArea;
110 }
111
112 /**
113 * Apply changes
114 *
115 * @param isApply true if update operation caused by "Apply" button
116 */
117 protected void applyChanges(final boolean isApply)
118 {
119 if (checkAgent.getSelection())
120 objectTool.setFlags(objectTool.getFlags() | ObjectTool.REQUIRES_AGENT);
121 else
122 objectTool.setFlags(objectTool.getFlags() & ~ObjectTool.REQUIRES_AGENT);
123
124 if (checkSNMP.getSelection())
125 objectTool.setFlags(objectTool.getFlags() | ObjectTool.REQUIRES_SNMP);
126 else
127 objectTool.setFlags(objectTool.getFlags() & ~ObjectTool.REQUIRES_SNMP);
128
129 if (checkMatchOID.getSelection())
130 objectTool.setFlags(objectTool.getFlags() | ObjectTool.REQUIRES_OID_MATCH);
131 else
132 objectTool.setFlags(objectTool.getFlags() & ~ObjectTool.REQUIRES_OID_MATCH);
133
134 objectTool.setSnmpOid(textOID.getText());
135 }
136
137 /* (non-Javadoc)
138 * @see org.eclipse.jface.preference.PreferencePage#performApply()
139 */
140 @Override
141 protected void performApply()
142 {
143 applyChanges(true);
144 }
145
146 /* (non-Javadoc)
147 * @see org.eclipse.jface.preference.PreferencePage#performOk()
148 */
149 @Override
150 public boolean performOk()
151 {
152 applyChanges(false);
153 return true;
154 }
155 }