eda0e4be6ae48f8d4f0a007d7db791803f713d9e
[public/netxms.git] / src / java / netxms-eclipse / ObjectBrowser / src / org / netxms / ui / eclipse / objectbrowser / widgets / ZoneSelector.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2017 Raden Solutions
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.objectbrowser.widgets;
20
21 import org.eclipse.jface.window.Window;
22 import org.eclipse.swt.widgets.Composite;
23 import org.netxms.client.objects.Zone;
24 import org.netxms.ui.eclipse.objectbrowser.dialogs.ZoneSelectionDialog;
25 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
26 import org.netxms.ui.eclipse.widgets.AbstractSelector;
27
28 /**
29 * Zone selector
30 */
31 public class ZoneSelector extends AbstractSelector
32 {
33 private long zoneUIN = 0;
34 private String emptySelectionName = "<none>";
35
36 /**
37 * @param parent
38 * @param style
39 * @param showClearButton
40 */
41 public ZoneSelector(Composite parent, int style, boolean showClearButton)
42 {
43 super(parent, style, showClearButton ? SHOW_CLEAR_BUTTON : 0);
44 setText(emptySelectionName);
45 }
46
47 /* (non-Javadoc)
48 * @see org.netxms.ui.eclipse.widgets.AbstractSelector#selectionButtonHandler()
49 */
50 @Override
51 protected void selectionButtonHandler()
52 {
53 ZoneSelectionDialog dlg = new ZoneSelectionDialog(getShell());
54 if (dlg.open() == Window.OK)
55 {
56 zoneUIN = dlg.getZoneUIN();
57 setText(dlg.getZoneName());
58 fireModifyListeners();
59 }
60 }
61
62 /* (non-Javadoc)
63 * @see org.netxms.ui.eclipse.widgets.AbstractSelector#clearButtonHandler()
64 */
65 @Override
66 protected void clearButtonHandler()
67 {
68 zoneUIN = -1;
69 setText(emptySelectionName);
70 fireModifyListeners();
71 }
72
73 /**
74 * Get UIN of selected zone
75 *
76 * @return selected zone UIN
77 */
78 public long getZoneUIN()
79 {
80 return zoneUIN;
81 }
82
83 /**
84 * Get name of selected zone
85 *
86 * @return zone name
87 */
88 public String getZoneName()
89 {
90 return getText();
91 }
92
93 /**
94 * Set zone UIN
95 *
96 * @param zoneUIN new zone UIN
97 */
98 public void setZoneUIN(long zoneUIN)
99 {
100 this.zoneUIN = zoneUIN;
101 if (zoneUIN == -1)
102 {
103 setText(emptySelectionName); //$NON-NLS-1$
104 }
105 else
106 {
107 final Zone zone = ConsoleSharedData.getSession().findZone(zoneUIN);
108 setText((zone != null) ? zone.getObjectName() : ("<" + Long.toString(zoneUIN) + ">")); //$NON-NLS-1$ //$NON-NLS-2$
109 }
110 }
111 }