1975b9cb8d1da0a346bd9a156d84e4d66d0b7546
[public/netxms.git] / src / java / netxms-eclipse / ObjectManager / src / org / netxms / ui / eclipse / objectmanager / dialogs / AttributeEditDialog.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.dialogs;
20
21 import org.eclipse.jface.dialogs.Dialog;
22 import org.eclipse.swt.SWT;
23 import org.eclipse.swt.layout.FillLayout;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.swt.widgets.Text;
29 import org.netxms.ui.eclipse.objectmanager.Messages;
30 import org.netxms.ui.eclipse.tools.WidgetHelper;
31
32
33 /**
34 * Object's custom attribute edit dialog
35 *
36 */
37 public class AttributeEditDialog extends Dialog
38 {
39 private Text textName;
40 private Text textValue;
41 private String attrName;
42 private String attrValue;
43
44 /**
45 * @param parentShell
46 */
47 public AttributeEditDialog(Shell parentShell, String attrName, String attrValue)
48 {
49 super(parentShell);
50 this.attrName = attrName;
51 this.attrValue = attrValue;
52 }
53
54 /* (non-Javadoc)
55 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
56 */
57 @Override
58 protected Control createDialogArea(Composite parent)
59 {
60 Composite dialogArea = (Composite)super.createDialogArea(parent);
61
62 FillLayout layout = new FillLayout();
63 layout.type = SWT.VERTICAL;
64 layout.marginWidth = WidgetHelper.DIALOG_WIDTH_MARGIN;
65 layout.marginHeight = WidgetHelper.DIALOG_HEIGHT_MARGIN;
66 dialogArea.setLayout(layout);
67
68 Label label = new Label(dialogArea, SWT.NONE);
69 label.setText(Messages.get().AttributeEditDialog_Name);
70
71 textName = new Text(dialogArea, SWT.SINGLE | SWT.BORDER);
72 textName.setTextLimit(63);
73 if (attrName != null)
74 {
75 textName.setText(attrName);
76 textName.setEditable(false);
77 }
78
79 label = new Label(dialogArea, SWT.NONE);
80 label.setText(""); //$NON-NLS-1$
81
82 label = new Label(dialogArea, SWT.NONE);
83 label.setText(Messages.get().AttributeEditDialog_Value);
84
85 textValue = new Text(dialogArea, SWT.SINGLE | SWT.BORDER);
86 textValue.setTextLimit(255);
87 textValue.getShell().setMinimumSize(300, 0);
88 if (attrValue != null)
89 textValue.setText(attrValue);
90
91 if (attrName != null)
92 textValue.setFocus();
93
94 return dialogArea;
95 }
96
97 /* (non-Javadoc)
98 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
99 */
100 @Override
101 protected void configureShell(Shell newShell)
102 {
103 super.configureShell(newShell);
104 newShell.setText((attrName == null) ? Messages.get().AttributeEditDialog_AddAttr : Messages.get().AttributeEditDialog_ModifyAttr);
105 }
106
107
108 /**
109 * Get variable name
110 *
111 */
112 public String getAttrName()
113 {
114 return attrName;
115 }
116
117
118 /**
119 * Get variable value
120 *
121 */
122 public String getAttrValue()
123 {
124 return attrValue;
125 }
126
127
128 /* (non-Javadoc)
129 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
130 */
131 @Override
132 protected void okPressed()
133 {
134 attrName = textName.getText();
135 attrValue = textValue.getText();
136 super.okPressed();
137 }
138 }