2b4f78caab484715417730ed28b53e39276700ce
[public/netxms.git] / webui / webapp / DataCollection / src / org / netxms / ui / eclipse / datacollection / propertypages / SummaryTableGeneral.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.datacollection.propertypages;
20
21 import org.eclipse.core.runtime.IProgressMonitor;
22 import org.eclipse.jface.window.Window;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.events.SelectionEvent;
25 import org.eclipse.swt.events.SelectionListener;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.widgets.Button;
29 import org.eclipse.swt.widgets.Composite;
30 import org.eclipse.swt.widgets.Control;
31 import org.eclipse.ui.dialogs.PropertyPage;
32 import org.netxms.client.NXCSession;
33 import org.netxms.client.datacollection.DciSummaryTable;
34 import org.netxms.ui.eclipse.datacollection.Activator;
35 import org.netxms.ui.eclipse.datacollection.Messages;
36 import org.netxms.ui.eclipse.datacollection.dialogs.SelectDciDialog;
37 import org.netxms.ui.eclipse.jobs.ConsoleJob;
38 import org.netxms.ui.eclipse.shared.ConsoleSharedData;
39 import org.netxms.ui.eclipse.tools.WidgetHelper;
40 import org.netxms.ui.eclipse.widgets.LabeledText;
41
42 /**
43 * "General" page for DCI summary table
44 */
45 public class SummaryTableGeneral extends PropertyPage
46 {
47 private DciSummaryTable table;
48 private LabeledText menuPath;
49 private LabeledText title;
50 private LabeledText dciName;
51 private Button select;
52
53 /* (non-Javadoc)
54 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
55 */
56 @Override
57 protected Control createContents(Composite parent)
58 {
59 table = (DciSummaryTable)getElement().getAdapter(DciSummaryTable.class);
60
61 Composite dialogArea = new Composite(parent, SWT.NONE);
62
63 GridLayout layout = new GridLayout();
64 layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
65 layout.marginWidth = 0;
66 layout.marginHeight = 0;
67 layout.numColumns = 2;
68 dialogArea.setLayout(layout);
69
70 menuPath = new LabeledText(dialogArea, SWT.NONE);
71 menuPath.setLabel(Messages.get().SummaryTableGeneral_MenuPath);
72 menuPath.setText(table.getMenuPath());
73 menuPath.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
74
75 title = new LabeledText(dialogArea, SWT.NONE);
76 title.setLabel(Messages.get().SummaryTableGeneral_Title);
77 title.setText(table.getTitle());
78 title.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
79
80 if (!table.isSingleValue())
81 {
82 dciName = new LabeledText(dialogArea, SWT.NONE);
83 dciName.setLabel("DCI name");
84 dciName.getTextControl().setTextLimit(255);
85 dciName.setText(table.getTableDciName());
86 dciName.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
87
88 select = new Button(dialogArea, SWT.PUSH);
89 select.setText("Select");
90 GridData gd = new GridData(SWT.FILL);
91 gd.verticalIndent = 20;
92 select.setLayoutData(gd);
93 select.addSelectionListener(new SelectionListener() {
94 /* (non-Javadoc)
95 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
96 */
97 @Override
98 public void widgetSelected(SelectionEvent e)
99 {
100 selectDci();
101 }
102
103 /* (non-Javadoc)
104 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
105 */
106 @Override
107 public void widgetDefaultSelected(SelectionEvent e)
108 {
109 widgetSelected(e);
110 }
111 });
112
113 }
114
115 return dialogArea;
116 }
117
118 private void selectDci()
119 {
120 SelectDciDialog dlg = new SelectDciDialog(getShell(), 0);
121 dlg.setDcObjectType(2);
122 dlg.setSingleSelection(true);
123 if (dlg.open() == Window.OK)
124 {
125 table.setTableDciName(dlg.getSelection().get(0).getName());
126 dciName.setText(table.getTableDciName());
127 }
128 }
129
130 /**
131 * Apply changes
132 *
133 * @param isApply true if update operation caused by "Apply" button
134 */
135 protected void applyChanges(final boolean isApply)
136 {
137 if (isApply)
138 setValid(false);
139
140 table.setMenuPath(menuPath.getText());
141 table.setTitle(title.getText());
142
143 final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
144 new ConsoleJob(Messages.get().SummaryTableGeneral_JobName, null, Activator.PLUGIN_ID, null) {
145 @Override
146 protected void runInternal(IProgressMonitor monitor) throws Exception
147 {
148 synchronized(table)
149 {
150 int id = session.modifyDciSummaryTable(table);
151 table.setId(id);
152 }
153 }
154
155 @Override
156 protected String getErrorMessage()
157 {
158 return Messages.get().SummaryTableGeneral_JobError;
159 }
160
161 /* (non-Javadoc)
162 * @see org.netxms.ui.eclipse.jobs.ConsoleJob#jobFinalize()
163 */
164 @Override
165 protected void jobFinalize()
166 {
167 if (isApply)
168 {
169 runInUIThread(new Runnable() {
170 @Override
171 public void run()
172 {
173 SummaryTableGeneral.this.setValid(true);
174 }
175 });
176 }
177 }
178 }.start();
179 }
180
181 /* (non-Javadoc)
182 * @see org.eclipse.jface.preference.PreferencePage#performOk()
183 */
184 @Override
185 public boolean performOk()
186 {
187 applyChanges(false);
188 return true;
189 }
190
191 /* (non-Javadoc)
192 * @see org.eclipse.jface.preference.PreferencePage#performApply()
193 */
194 @Override
195 protected void performApply()
196 {
197 applyChanges(true);
198 }
199 }