d78ff82d2f7a0c6b55366dea829de46664daf76a
[public/netxms.git] / src / java / netxms-eclipse / ServerConfig / src / org / netxms / ui / eclipse / serverconfig / views / NetworkDiscoveryConfigurator.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.serverconfig.views;
20
21 import java.util.List;
22 import org.eclipse.core.runtime.IProgressMonitor;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.jface.action.IMenuManager;
25 import org.eclipse.jface.action.IToolBarManager;
26 import org.eclipse.jface.viewers.ArrayContentProvider;
27 import org.eclipse.jface.viewers.IStructuredSelection;
28 import org.eclipse.jface.viewers.TableViewer;
29 import org.eclipse.jface.window.Window;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.events.ModifyEvent;
32 import org.eclipse.swt.events.ModifyListener;
33 import org.eclipse.swt.events.SelectionAdapter;
34 import org.eclipse.swt.events.SelectionEvent;
35 import org.eclipse.swt.events.SelectionListener;
36 import org.eclipse.swt.layout.GridData;
37 import org.eclipse.swt.layout.GridLayout;
38 import org.eclipse.swt.widgets.Button;
39 import org.eclipse.swt.widgets.Composite;
40 import org.eclipse.ui.IActionBars;
41 import org.eclipse.ui.IMemento;
42 import org.eclipse.ui.ISaveablePart;
43 import org.eclipse.ui.IViewSite;
44 import org.eclipse.ui.PartInitException;
45 import org.eclipse.ui.forms.events.HyperlinkAdapter;
46 import org.eclipse.ui.forms.events.HyperlinkEvent;
47 import org.eclipse.ui.forms.widgets.FormToolkit;
48 import org.eclipse.ui.forms.widgets.ImageHyperlink;
49 import org.eclipse.ui.forms.widgets.ScrolledForm;
50 import org.eclipse.ui.forms.widgets.Section;
51 import org.eclipse.ui.forms.widgets.TableWrapData;
52 import org.eclipse.ui.forms.widgets.TableWrapLayout;
53 import org.eclipse.ui.part.ViewPart;
54 import org.netxms.client.IpAddressListElement;
55 import org.netxms.client.constants.NetworkDiscovery;
56 import org.netxms.ui.eclipse.console.resources.SharedIcons;
57 import org.netxms.ui.eclipse.jobs.ConsoleJob;
58 import org.netxms.ui.eclipse.nxsl.widgets.ScriptSelector;
59 import org.netxms.ui.eclipse.serverconfig.Activator;
60 import org.netxms.ui.eclipse.serverconfig.Messages;
61 import org.netxms.ui.eclipse.serverconfig.dialogs.AddAddressListElementDialog;
62 import org.netxms.ui.eclipse.serverconfig.views.helpers.AddressListElementComparator;
63 import org.netxms.ui.eclipse.serverconfig.views.helpers.DiscoveryConfig;
64 import org.netxms.ui.eclipse.tools.MessageDialogHelper;
65
66 /**
67 * Configurator for network discovery
68 */
69 public class NetworkDiscoveryConfigurator extends ViewPart implements ISaveablePart
70 {
71 public static final String ID = "org.netxms.ui.eclipse.serverconfig.views.NetworkDiscoveryConfigurator"; //$NON-NLS-1$
72
73 private DiscoveryConfig config;
74 private boolean modified = false;
75 private FormToolkit toolkit;
76 private ScrolledForm form;
77 private Button radioDiscoveryOff;
78 private Button radioDiscoveryPassive;
79 private Button radioDiscoveryActive;
80 private Button checkUseSnmpTraps;
81 private Button radioFilterOff;
82 private Button radioFilterCustom;
83 private Button radioFilterAuto;
84 private ScriptSelector filterScript;
85 private Button checkAgentOnly;
86 private Button checkSnmpOnly;
87 private Button checkRangeOnly;
88 private TableViewer filterAddressList;
89 private TableViewer activeDiscoveryAddressList;
90 private Action actionSave;
91
92 /*
93 * (non-Javadoc)
94 *
95 * @see org.eclipse.ui.part.ViewPart#init(org.eclipse.ui.IViewSite, org.eclipse.ui.IMemento)
96 */
97 @Override
98 public void init(IViewSite site, IMemento memento) throws PartInitException
99 {
100 super.init(site, memento);
101 }
102
103 /*
104 * (non-Javadoc)
105 *
106 * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
107 */
108 @Override
109 public void createPartControl(Composite parent)
110 {
111 toolkit = new FormToolkit(getSite().getShell().getDisplay());
112 form = toolkit.createScrolledForm(parent);
113 form.setText(Messages.get().NetworkDiscoveryConfigurator_FormTitle);
114
115 TableWrapLayout layout = new TableWrapLayout();
116 layout.numColumns = 2;
117 form.getBody().setLayout(layout);
118
119 createGeneralSection();
120 createFilterSection();
121 createActiveDiscoverySection();
122 createSubnetFilterSection();
123
124 createActions();
125 contributeToActionBars();
126
127 // Restoring, load config
128 new ConsoleJob(Messages.get().NetworkDiscoveryConfigurator_LoadJobName, this, Activator.PLUGIN_ID, null) {
129 @Override
130 protected void runInternal(IProgressMonitor monitor) throws Exception
131 {
132 final DiscoveryConfig loadedConfig = DiscoveryConfig.load();
133 runInUIThread(new Runnable() {
134 @Override
135 public void run()
136 {
137 setConfig(loadedConfig);
138 }
139 });
140 }
141
142 @Override
143 protected String getErrorMessage()
144 {
145 return Messages.get().NetworkDiscoveryConfigurator_LoadJobError;
146 }
147 }.start();
148 }
149
150 /**
151 * Create actions
152 */
153 private void createActions()
154 {
155 actionSave = new Action(Messages.get().NetworkDiscoveryConfigurator_Save, SharedIcons.SAVE) {
156 @Override
157 public void run()
158 {
159 save();
160 }
161 };
162 }
163
164 /**
165 * Contribute actions to action bar
166 */
167 private void contributeToActionBars()
168 {
169 IActionBars bars = getViewSite().getActionBars();
170 fillLocalPullDown(bars.getMenuManager());
171 fillLocalToolBar(bars.getToolBarManager());
172 }
173
174 /**
175 * Fill local pull-down menu
176 *
177 * @param manager Menu manager for pull-down menu
178 */
179 private void fillLocalPullDown(IMenuManager manager)
180 {
181 manager.add(actionSave);
182 }
183
184 /**
185 * Fill local tool bar
186 *
187 * @param manager Menu manager for local toolbar
188 */
189 private void fillLocalToolBar(IToolBarManager manager)
190 {
191 manager.add(actionSave);
192 }
193
194 /**
195 * Create "General" section
196 */
197 private void createGeneralSection()
198 {
199 Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR);
200 section.setText(Messages.get().NetworkDiscoveryConfigurator_SectionGeneral);
201 section.setDescription(Messages.get().NetworkDiscoveryConfigurator_SectionGeneralDescr);
202 TableWrapData td = new TableWrapData();
203 td.align = TableWrapData.FILL;
204 td.grabHorizontal = true;
205 section.setLayoutData(td);
206
207 Composite clientArea = toolkit.createComposite(section);
208 GridLayout layout = new GridLayout();
209 clientArea.setLayout(layout);
210 section.setClient(clientArea);
211
212 final SelectionListener listener = new SelectionListener() {
213 @Override
214 public void widgetSelected(SelectionEvent e)
215 {
216 setModified();
217 if (radioDiscoveryOff.getSelection())
218 {
219 config.setEnabled(false);
220 }
221 else
222 {
223 config.setEnabled(true);
224 config.setActive(radioDiscoveryActive.getSelection());
225 }
226 }
227
228 @Override
229 public void widgetDefaultSelected(SelectionEvent e)
230 {
231 widgetSelected(e);
232 }
233 };
234
235 radioDiscoveryOff = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_Disabled, SWT.RADIO);
236 radioDiscoveryOff.addSelectionListener(listener);
237 radioDiscoveryPassive = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_PassiveDiscovery,
238 SWT.RADIO);
239 radioDiscoveryPassive.addSelectionListener(listener);
240 radioDiscoveryActive = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_ActiveDiscovery,
241 SWT.RADIO);
242 radioDiscoveryActive.addSelectionListener(listener);
243
244 checkUseSnmpTraps = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_UseSNMPTrapsForDiscovery,
245 SWT.CHECK);
246 checkUseSnmpTraps.addSelectionListener(new SelectionAdapter() {
247 @Override
248 public void widgetSelected(SelectionEvent e)
249 {
250 config.setUseSnmpTraps(checkUseSnmpTraps.getSelection());
251 setModified();
252 }
253 });
254 GridData gd = new GridData();
255 gd.verticalIndent = 10;
256 checkUseSnmpTraps.setLayoutData(gd);
257 }
258
259 /**
260 * Create "Filter" section
261 */
262 private void createFilterSection()
263 {
264 Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR);
265 section.setText(Messages.get().NetworkDiscoveryConfigurator_SectionFilter);
266 section.setDescription(Messages.get().NetworkDiscoveryConfigurator_SectionFilterDescr);
267 TableWrapData td = new TableWrapData();
268 td.align = TableWrapData.FILL;
269 td.grabHorizontal = true;
270 section.setLayoutData(td);
271
272 Composite clientArea = toolkit.createComposite(section);
273 GridLayout layout = new GridLayout();
274 clientArea.setLayout(layout);
275 section.setClient(clientArea);
276
277 final SelectionListener radioButtonListener = new SelectionListener() {
278 @Override
279 public void widgetSelected(SelectionEvent e)
280 {
281 updateElementEnablement();
282 setModified();
283 if (radioFilterOff.getSelection())
284 {
285 config.setFilter(NetworkDiscovery.FILTER_NONE);
286 }
287 else if (radioFilterAuto.getSelection())
288 {
289 config.setFilter(NetworkDiscovery.FILTER_AUTO);
290 }
291 else
292 {
293 config.setFilter(filterScript.getScriptName());
294 }
295 }
296
297 @Override
298 public void widgetDefaultSelected(SelectionEvent e)
299 {
300 widgetSelected(e);
301 }
302 };
303
304 final SelectionListener checkBoxListener = new SelectionListener() {
305 @Override
306 public void widgetSelected(SelectionEvent e)
307 {
308 setModified();
309 int flags = 0;
310 if (checkAgentOnly.getSelection())
311 flags |= NetworkDiscovery.FILTER_ALLOW_AGENT;
312 if (checkSnmpOnly.getSelection())
313 flags |= NetworkDiscovery.FILTER_ALLOW_SNMP;
314 if (checkRangeOnly.getSelection())
315 flags |= NetworkDiscovery.FILTER_LIMIT_BY_RANGE;
316 config.setFilterFlags(flags);
317 }
318
319 @Override
320 public void widgetDefaultSelected(SelectionEvent e)
321 {
322 widgetSelected(e);
323 }
324 };
325
326 radioFilterOff = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_NoFiltering, SWT.RADIO);
327 radioFilterOff.addSelectionListener(radioButtonListener);
328 radioFilterCustom = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_CustomScript, SWT.RADIO);
329 radioFilterCustom.addSelectionListener(radioButtonListener);
330 filterScript = new ScriptSelector(clientArea, SWT.NONE, true, false);
331 toolkit.adapt(filterScript);
332 filterScript.getTextControl().setBackground(clientArea.getBackground());
333 GridData gd = new GridData();
334 gd.horizontalAlignment = SWT.FILL;
335 gd.grabExcessHorizontalSpace = true;
336 gd.horizontalIndent = 20;
337 filterScript.setLayoutData(gd);
338 filterScript.addModifyListener(new ModifyListener() {
339 @Override
340 public void modifyText(ModifyEvent e)
341 {
342 if (radioFilterCustom.getSelection())
343 {
344 setModified();
345 config.setFilter(filterScript.getScriptName());
346 }
347 }
348 });
349
350 radioFilterAuto = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_AutoScript, SWT.RADIO);
351 radioFilterAuto.addSelectionListener(radioButtonListener);
352
353 checkAgentOnly = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_AcceptAgent, SWT.CHECK);
354 checkAgentOnly.addSelectionListener(checkBoxListener);
355 gd = new GridData();
356 gd.horizontalIndent = 20;
357 checkAgentOnly.setLayoutData(gd);
358
359 checkSnmpOnly = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_AcceptSNMP, SWT.CHECK);
360 checkSnmpOnly.addSelectionListener(checkBoxListener);
361 gd = new GridData();
362 gd.horizontalIndent = 20;
363 checkSnmpOnly.setLayoutData(gd);
364
365 checkRangeOnly = toolkit.createButton(clientArea, Messages.get().NetworkDiscoveryConfigurator_AcceptRange, SWT.CHECK);
366 checkRangeOnly.addSelectionListener(checkBoxListener);
367 gd = new GridData();
368 gd.horizontalIndent = 20;
369 checkRangeOnly.setLayoutData(gd);
370 }
371
372 /**
373 * Create "Active Discovery Targets" section
374 */
375 private void createActiveDiscoverySection()
376 {
377 Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR);
378 section.setText(Messages.get().NetworkDiscoveryConfigurator_SectionActiveDiscoveryTargets);
379 section.setDescription(Messages.get().NetworkDiscoveryConfigurator_SectionActiveDiscoveryTargetsDescr);
380 TableWrapData td = new TableWrapData();
381 td.align = TableWrapData.FILL;
382 td.grabHorizontal = true;
383 section.setLayoutData(td);
384
385 Composite clientArea = toolkit.createComposite(section);
386 GridLayout layout = new GridLayout();
387 layout.numColumns = 2;
388 clientArea.setLayout(layout);
389 section.setClient(clientArea);
390
391 activeDiscoveryAddressList = new TableViewer(clientArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
392 toolkit.adapt(activeDiscoveryAddressList.getTable());
393 GridData gd = new GridData();
394 gd.horizontalAlignment = SWT.FILL;
395 gd.grabExcessHorizontalSpace = true;
396 gd.verticalAlignment = SWT.FILL;
397 gd.grabExcessVerticalSpace = true;
398 gd.verticalSpan = 2;
399 gd.heightHint = 100;
400 activeDiscoveryAddressList.getTable().setLayoutData(gd);
401 activeDiscoveryAddressList.getTable().setSortDirection(SWT.UP);
402 activeDiscoveryAddressList.setContentProvider(new ArrayContentProvider());
403 activeDiscoveryAddressList.setComparator(new AddressListElementComparator());
404
405 final ImageHyperlink linkAdd = toolkit.createImageHyperlink(clientArea, SWT.NONE);
406 linkAdd.setText(Messages.get().NetworkDiscoveryConfigurator_Add);
407 linkAdd.setImage(SharedIcons.IMG_ADD_OBJECT);
408 gd = new GridData();
409 gd.verticalAlignment = SWT.TOP;
410 linkAdd.setLayoutData(gd);
411 linkAdd.addHyperlinkListener(new HyperlinkAdapter() {
412 @Override
413 public void linkActivated(HyperlinkEvent e)
414 {
415 addTargetAddressListElement();
416 }
417 });
418
419 final ImageHyperlink linkRemove = toolkit.createImageHyperlink(clientArea, SWT.NONE);
420 linkRemove.setText(Messages.get().NetworkDiscoveryConfigurator_Remove);
421 linkRemove.setImage(SharedIcons.IMG_DELETE_OBJECT);
422 gd = new GridData();
423 gd.verticalAlignment = SWT.TOP;
424 linkRemove.setLayoutData(gd);
425 linkRemove.addHyperlinkListener(new HyperlinkAdapter() {
426 @Override
427 public void linkActivated(HyperlinkEvent e)
428 {
429 removeTargetAddressListElements();
430 }
431 });
432 }
433
434 /**
435 * Create "Address Filters" section
436 */
437 private void createSubnetFilterSection()
438 {
439 Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION | Section.TITLE_BAR);
440 section.setText(Messages.get().NetworkDiscoveryConfigurator_SectionAddressFilters);
441 section.setDescription(Messages.get().NetworkDiscoveryConfigurator_SectionAddressFiltersDescr);
442 TableWrapData td = new TableWrapData();
443 td.align = TableWrapData.FILL;
444 td.grabHorizontal = true;
445 section.setLayoutData(td);
446
447 Composite clientArea = toolkit.createComposite(section);
448 GridLayout layout = new GridLayout();
449 layout.numColumns = 2;
450 clientArea.setLayout(layout);
451 section.setClient(clientArea);
452
453 filterAddressList = new TableViewer(clientArea, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
454 toolkit.adapt(filterAddressList.getTable());
455 GridData gd = new GridData();
456 gd.horizontalAlignment = SWT.FILL;
457 gd.grabExcessHorizontalSpace = true;
458 gd.verticalAlignment = SWT.FILL;
459 gd.grabExcessVerticalSpace = true;
460 gd.verticalSpan = 2;
461 gd.heightHint = 100;
462 filterAddressList.getTable().setLayoutData(gd);
463 filterAddressList.getTable().setSortDirection(SWT.UP);
464 filterAddressList.setContentProvider(new ArrayContentProvider());
465 filterAddressList.setComparator(new AddressListElementComparator());
466
467 final ImageHyperlink linkAdd = toolkit.createImageHyperlink(clientArea, SWT.NONE);
468 linkAdd.setText(Messages.get().NetworkDiscoveryConfigurator_Add);
469 linkAdd.setImage(SharedIcons.IMG_ADD_OBJECT);
470 gd = new GridData();
471 gd.verticalAlignment = SWT.TOP;
472 linkAdd.setLayoutData(gd);
473 linkAdd.addHyperlinkListener(new HyperlinkAdapter() {
474 @Override
475 public void linkActivated(HyperlinkEvent e)
476 {
477 addAddressFilterElement();
478 }
479 });
480
481 final ImageHyperlink linkRemove = toolkit.createImageHyperlink(clientArea, SWT.NONE);
482 linkRemove.setText(Messages.get().NetworkDiscoveryConfigurator_Remove);
483 linkRemove.setImage(SharedIcons.IMG_DELETE_OBJECT);
484 gd = new GridData();
485 gd.verticalAlignment = SWT.TOP;
486 linkRemove.setLayoutData(gd);
487 linkRemove.addHyperlinkListener(new HyperlinkAdapter() {
488 @Override
489 public void linkActivated(HyperlinkEvent e)
490 {
491 removeAddressFilterElements();
492 }
493 });
494
495 }
496
497 /*
498 * (non-Javadoc)
499 *
500 * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
501 */
502 @Override
503 public void setFocus()
504 {
505 form.setFocus();
506 }
507
508 /**
509 * @param config
510 */
511 public void setConfig(DiscoveryConfig config)
512 {
513 this.config = config;
514
515 radioDiscoveryOff.setSelection(!config.isEnabled());
516 radioDiscoveryPassive.setSelection(config.isEnabled() && !config.isActive());
517 radioDiscoveryActive.setSelection(config.isEnabled() && config.isActive());
518 checkUseSnmpTraps.setSelection(config.isUseSnmpTraps());
519
520 if (config.getFilter().equalsIgnoreCase(NetworkDiscovery.FILTER_NONE) || config.getFilter().isEmpty())
521 {
522 radioFilterOff.setSelection(true);
523 }
524 else if (config.getFilter().equalsIgnoreCase(NetworkDiscovery.FILTER_AUTO))
525 {
526 radioFilterAuto.setSelection(true);
527 }
528 else
529 {
530 radioFilterCustom.setSelection(true);
531 filterScript.setScriptName(config.getFilter());
532 }
533
534 checkAgentOnly.setSelection((config.getFilterFlags() & NetworkDiscovery.FILTER_ALLOW_AGENT) != 0);
535 checkSnmpOnly.setSelection((config.getFilterFlags() & NetworkDiscovery.FILTER_ALLOW_SNMP) != 0);
536 checkRangeOnly.setSelection((config.getFilterFlags() & NetworkDiscovery.FILTER_LIMIT_BY_RANGE) != 0);
537
538 activeDiscoveryAddressList.setInput(config.getTargets().toArray());
539 filterAddressList.setInput(config.getAddressFilter().toArray());
540
541 updateElementEnablement();
542 modified = false;
543 firePropertyChange(PROP_DIRTY);
544 }
545
546 /**
547 * Update enabled state of elements
548 */
549 private void updateElementEnablement()
550 {
551 // Filter section
552 if (radioFilterOff.getSelection())
553 {
554 filterScript.setEnabled(false);
555 checkAgentOnly.setEnabled(false);
556 checkSnmpOnly.setEnabled(false);
557 checkRangeOnly.setEnabled(false);
558 }
559 else if (radioFilterAuto.getSelection())
560 {
561 filterScript.setEnabled(false);
562 checkAgentOnly.setEnabled(true);
563 checkSnmpOnly.setEnabled(true);
564 checkRangeOnly.setEnabled(true);
565 }
566 if (radioFilterCustom.getSelection())
567 {
568 filterScript.setEnabled(true);
569 checkAgentOnly.setEnabled(false);
570 checkSnmpOnly.setEnabled(false);
571 checkRangeOnly.setEnabled(false);
572 }
573 }
574
575 /**
576 * Mark view as modified
577 */
578 private void setModified()
579 {
580 if (!modified)
581 {
582 modified = true;
583 firePropertyChange(PROP_DIRTY);
584 }
585 }
586
587 /*
588 * (non-Javadoc)
589 *
590 * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
591 */
592 @Override
593 public void doSave(IProgressMonitor monitor)
594 {
595 try
596 {
597 config.save();
598 }
599 catch(Exception e)
600 {
601 MessageDialogHelper.openError(getSite().getShell(), Messages.get().NetworkDiscoveryConfigurator_Error,
602 String.format(Messages.get().NetworkDiscoveryConfigurator_SaveErrorText, e.getLocalizedMessage()));
603 }
604 }
605
606 /*
607 * (non-Javadoc)
608 *
609 * @see org.eclipse.ui.ISaveablePart#doSaveAs()
610 */
611 @Override
612 public void doSaveAs()
613 {
614 }
615
616 /*
617 * (non-Javadoc)
618 *
619 * @see org.eclipse.ui.ISaveablePart#isDirty()
620 */
621 @Override
622 public boolean isDirty()
623 {
624 return modified;
625 }
626
627 /*
628 * (non-Javadoc)
629 *
630 * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
631 */
632 @Override
633 public boolean isSaveAsAllowed()
634 {
635 return false;
636 }
637
638 /*
639 * (non-Javadoc)
640 *
641 * @see org.eclipse.ui.ISaveablePart#isSaveOnCloseNeeded()
642 */
643 @Override
644 public boolean isSaveOnCloseNeeded()
645 {
646 return modified;
647 }
648
649 /**
650 * Save settings
651 */
652 private void save()
653 {
654 new ConsoleJob(Messages.get().NetworkDiscoveryConfigurator_SaveJobName, this, Activator.PLUGIN_ID, null) {
655 @Override
656 protected void runInternal(IProgressMonitor monitor) throws Exception
657 {
658 config.save();
659 runInUIThread(new Runnable() {
660 @Override
661 public void run()
662 {
663 modified = false;
664 firePropertyChange(PROP_DIRTY);
665 }
666 });
667 }
668
669 @Override
670 protected String getErrorMessage()
671 {
672 return Messages.get().NetworkDiscoveryConfigurator_SaveJobError;
673 }
674 }.start();
675 }
676
677 /**
678 * Add element to address filter
679 */
680 private void addTargetAddressListElement()
681 {
682 AddAddressListElementDialog dlg = new AddAddressListElementDialog(getSite().getShell());
683 if (dlg.open() == Window.OK)
684 {
685 final List<IpAddressListElement> list = config.getTargets();
686 IpAddressListElement element = new IpAddressListElement(dlg.getType(), dlg.getAddress1(), dlg.getAddress2());
687 if (!list.contains(element))
688 {
689 list.add(element);
690 activeDiscoveryAddressList.setInput(list.toArray());
691 setModified();
692 }
693 }
694 }
695
696 /**
697 * Remove element(s) from address filter
698 */
699 private void removeTargetAddressListElements()
700 {
701 final List<IpAddressListElement> list = config.getTargets();
702 IStructuredSelection selection = (IStructuredSelection)activeDiscoveryAddressList.getSelection();
703 if (selection.size() > 0)
704 {
705 for(Object o : selection.toList())
706 {
707 list.remove(o);
708 }
709 activeDiscoveryAddressList.setInput(list.toArray());
710 setModified();
711 }
712 }
713
714 /**
715 * Add element to address filter
716 */
717 private void addAddressFilterElement()
718 {
719 AddAddressListElementDialog dlg = new AddAddressListElementDialog(getSite().getShell());
720 if (dlg.open() == Window.OK)
721 {
722 final List<IpAddressListElement> list = config.getAddressFilter();
723 IpAddressListElement element = new IpAddressListElement(dlg.getType(), dlg.getAddress1(), dlg.getAddress2());
724 if (!list.contains(element))
725 {
726 list.add(element);
727 filterAddressList.setInput(list.toArray());
728 setModified();
729 }
730 }
731 }
732
733 /**
734 * Remove element(s) from address filter
735 */
736 private void removeAddressFilterElements()
737 {
738 final List<IpAddressListElement> list = config.getAddressFilter();
739 IStructuredSelection selection = (IStructuredSelection)filterAddressList.getSelection();
740 if (selection.size() > 0)
741 {
742 for(Object o : selection.toList())
743 {
744 list.remove(o);
745 }
746 filterAddressList.setInput(list.toArray());
747 setModified();
748 }
749 }
750 }