Skip to content

Package: PropertyDialog$2

PropertyDialog$2

nameinstructionbranchcomplexitylinemethod
modifyText(ModifyEvent)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /********************************************************************************
2: * Copyright (c) 2011 Eike Stepper (Berlin, Germany) and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eike Stepper - initial API and implementation
13: ********************************************************************************/
14: package org.eclipse.emf.ecp.internal.ui.dialogs;
15:
16: import org.eclipse.emf.ecp.internal.ui.Messages;
17: import org.eclipse.jface.dialogs.TitleAreaDialog;
18: import org.eclipse.swt.SWT;
19: import org.eclipse.swt.events.ModifyEvent;
20: import org.eclipse.swt.events.ModifyListener;
21: import org.eclipse.swt.graphics.Point;
22: import org.eclipse.swt.layout.GridData;
23: import org.eclipse.swt.layout.GridLayout;
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:
30: /**
31: * Dialog to edit one property.
32: *
33: * @author Eike Stepper
34: *
35: */
36: public class PropertyDialog extends TitleAreaDialog {
37:         private final boolean keyEditable;
38:
39:         private String key;
40:
41:         private String value;
42:
43:         private Text keyText;
44:
45:         private Text valueText;
46:
47:         /**
48:          * Constructor to edit an existing property.
49:          *
50:          * @param parentShell the paren {@link Shell}
51:          * @param keyEditable if the property is editable
52:          * @param key the key of the property
53:          * @param value the current value of the property
54:          */
55:         public PropertyDialog(Shell parentShell, boolean keyEditable, String key, String value) {
56:                 super(parentShell);
57:                 this.keyEditable = keyEditable;
58:                 this.key = key;
59:                 this.value = value;
60:         }
61:
62:         /**
63:          * Constructor for a new property.
64:          *
65:          * @param parentShell the parent {@link Shell}
66:          */
67:         public PropertyDialog(Shell parentShell) {
68:                 this(parentShell, true, null, null);
69:         }
70:
71:         /**
72:          *
73:          * @return the key of the currently edited property
74:          */
75:         public final String getKey() {
76:                 return key;
77:         }
78:
79:         /**
80:          *
81:          * @return the value of the currently edited property
82:          */
83:         public final String getValue() {
84:                 return value;
85:         }
86:
87:         /**
88:          *
89:          * @return whether the property is editable
90:          */
91:         public final boolean isKeyEditable() {
92:                 return keyEditable;
93:         }
94:
95:         @Override
96:         protected Control createDialogArea(Composite parent) {
97:                 setMessage(Messages.PropertyDialog_Message);
98:                 setTitle(Messages.PropertyDialog_Title);
99:                 final Composite area = (Composite) super.createDialogArea(parent);
100:                 final Composite container = new Composite(area, SWT.NONE);
101:                 container.setLayout(new GridLayout(2, false));
102:                 container.setLayoutData(new GridData(GridData.FILL_BOTH));
103:
104:                 final Label lblKey = new Label(container, SWT.NONE);
105:                 lblKey.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
106:                 lblKey.setText(Messages.PropertyDialog_Key);
107:
108:                 keyText = new Text(container, SWT.BORDER);
109:                 keyText.setText(key == null ? "" : key); //$NON-NLS-1$
110:                 keyText.setEditable(keyEditable);
111:                 keyText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
112:                 keyText.addModifyListener(new ModifyListener() {
113:                         @Override
114:                         public void modifyText(ModifyEvent e) {
115:                                 key = keyText.getText();
116:                         }
117:                 });
118:
119:                 final Label lblValue = new Label(container, SWT.NONE);
120:                 lblValue.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
121:                 lblValue.setText(Messages.PropertyDialog_Value);
122:
123:                 valueText = new Text(container, SWT.BORDER);
124:                 valueText.setText(value == null ? "" : value); //$NON-NLS-1$
125:                 valueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
126:                 valueText.addModifyListener(new ModifyListener() {
127:                         @Override
128:                         public void modifyText(ModifyEvent e) {
129:                                 value = valueText.getText();
130:                         }
131:                 });
132:
133:                 return area;
134:         }
135:
136:         @Override
137:         protected void cancelPressed() {
138:                 key = null;
139:                 value = null;
140:                 super.cancelPressed();
141:         }
142:
143:         @Override
144:         protected Point getInitialSize() {
145:                 return new Point(450, 228);
146:         }
147: }