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