a99d508f4625282244999a6b38847a4c5f170062
[public/netxms.git] / src / java / netxms-eclipse / ObjectManager / src / org / netxms / ui / eclipse / objectmanager / propertypages / ZoneCommunications.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.objectmanager.propertypages;
20
21 import org.eclipse.core.runtime.IProgressMonitor;
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.ui.dialogs.PropertyPage;
28 import org.netxms.client.NXCObjectModificationData;
29 import org.netxms.client.NXCSession;
30 import org.netxms.client.objects.Zone;
31 import org.netxms.ui.eclipse.jobs.ConsoleJob;
32 import org.netxms.ui.eclipse.objectbrowser.widgets.ObjectSelector;
33 import org.netxms.ui.eclipse.objectmanager.Activator;
34 import org.netxms.ui.eclipse.objectmanager.Messages;
35 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
36
37 /**
38 * "Communications" property page for zone objects
39 */
40 public class ZoneCommunications extends PropertyPage
41 {
42 private Zone zone;
43 private ObjectSelector agentProxy;
44 private ObjectSelector snmpProxy;
45 private ObjectSelector icmpProxy;
46 private ObjectSelector sshProxy;
47
48 /* (non-Javadoc)
49 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
50 */
51 @Override
52 protected Control createContents(Composite parent)
53 {
54 zone = (Zone)getElement().getAdapter(Zone.class);
55
56 Composite dialogArea = new Composite(parent, SWT.NONE);
57 GridLayout dialogLayout = new GridLayout();
58 dialogLayout.marginWidth = 0;
59 dialogLayout.marginHeight = 0;
60 dialogArea.setLayout(dialogLayout);
61
62 agentProxy = new ObjectSelector(dialogArea, SWT.NONE, true);
63 agentProxy.setLabel(Messages.get().ZoneCommunications_DefaultAgentProxy);
64 agentProxy.setObjectId(zone.getAgentProxy());
65 GridData gd = new GridData();
66 gd.horizontalAlignment = SWT.FILL;
67 gd.grabExcessHorizontalSpace = true;
68 agentProxy.setLayoutData(gd);
69
70 snmpProxy = new ObjectSelector(dialogArea, SWT.NONE, true);
71 snmpProxy.setLabel(Messages.get().ZoneCommunications_DefaultSNMPProxy);
72 snmpProxy.setObjectId(zone.getSnmpProxy());
73 gd = new GridData();
74 gd.horizontalAlignment = SWT.FILL;
75 gd.grabExcessHorizontalSpace = true;
76 snmpProxy.setLayoutData(gd);
77
78 icmpProxy = new ObjectSelector(dialogArea, SWT.NONE, true);
79 icmpProxy.setLabel(Messages.get().ZoneCommunications_DefaultICMPProxy);
80 icmpProxy.setObjectId(zone.getIcmpProxy());
81 gd = new GridData();
82 gd.horizontalAlignment = SWT.FILL;
83 gd.grabExcessHorizontalSpace = true;
84 icmpProxy.setLayoutData(gd);
85
86 sshProxy = new ObjectSelector(dialogArea, SWT.NONE, true);
87 sshProxy.setLabel(Messages.get().ZoneCommunications_DefaultSSHProxy);
88 sshProxy.setObjectId(zone.getSshProxy());
89 gd = new GridData();
90 gd.horizontalAlignment = SWT.FILL;
91 gd.grabExcessHorizontalSpace = true;
92 sshProxy.setLayoutData(gd);
93
94 return dialogArea;
95 }
96
97 /**
98 * Apply changes
99 *
100 * @param isApply true if update operation caused by "Apply" button
101 */
102 protected boolean applyChanges(final boolean isApply)
103 {
104 if (isApply)
105 setValid(false);
106
107 final NXCObjectModificationData md = new NXCObjectModificationData(zone.getObjectId());
108 md.setAgentProxy(agentProxy.getObjectId());
109 md.setSnmpProxy(snmpProxy.getObjectId());
110 md.setIcmpProxy(icmpProxy.getObjectId());
111 md.setSshProxy(sshProxy.getObjectId());
112
113 final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
114 new ConsoleJob(String.format(Messages.get().ZoneCommunications_JobName, zone.getObjectName()), null, Activator.PLUGIN_ID, null) {
115 @Override
116 protected void runInternal(IProgressMonitor monitor) throws Exception
117 {
118 session.modifyObject(md);
119 }
120
121 @Override
122 protected String getErrorMessage()
123 {
124 return Messages.get().ZoneCommunications_JobError;
125 }
126
127 @Override
128 protected void jobFinalize()
129 {
130 if (isApply)
131 {
132 runInUIThread(new Runnable() {
133 @Override
134 public void run()
135 {
136 ZoneCommunications.this.setValid(true);
137 }
138 });
139 }
140 }
141 }.start();
142 return true;
143 }
144
145 /* (non-Javadoc)
146 * @see org.eclipse.jface.preference.PreferencePage#performOk()
147 */
148 @Override
149 public boolean performOk()
150 {
151 return applyChanges(false);
152 }
153
154 /* (non-Javadoc)
155 * @see org.eclipse.jface.preference.PreferencePage#performApply()
156 */
157 @Override
158 protected void performApply()
159 {
160 applyChanges(true);
161 }
162
163 /* (non-Javadoc)
164 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
165 */
166 @Override
167 protected void performDefaults()
168 {
169 super.performDefaults();
170
171 agentProxy.setObjectId(0);
172 snmpProxy.setObjectId(0);
173 icmpProxy.setObjectId(0);
174 }
175 }