1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/*******************************************************************************
* Copyright (c) 2007 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Intel Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.newui;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
public class EnvDialog extends Dialog {
IEnvironmentVariable var;
Button b_add2all;
private Text text1;
private Text text2;
boolean newAction;
Shell shell;
ICConfigurationDescription cfgd;
public String t1 = AbstractCPropertyTab.EMPTY_STR;
public String t2 = AbstractCPropertyTab.EMPTY_STR;
public boolean toAll = false;
public EnvDialog(Shell parent,
IEnvironmentVariable _var,
String title, boolean _newAction,
ICConfigurationDescription _cfgd) {
super(parent);
shell = parent;
var = _var;
newAction = _newAction;
cfgd = _cfgd;
}
/**
* Method is overridden to disable "OK" button at start
*/
protected Control createContents(Composite parent) {
Control out = super.createContents(parent);
setButtons();
return out;
}
protected Control createDialogArea(Composite c) {
c.setLayout(new GridLayout(3, false));
GridData gd;
Label l1 = new Label(c, SWT.NONE);
l1.setText(UIMessages.getString("EnvDialog.0")); //$NON-NLS-1$
l1.setLayoutData(new GridData(GridData.BEGINNING));
text1 = new Text(c, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
gd.widthHint = 400;
text1.setLayoutData(gd);
text1.addModifyListener(new ModifyListener () {
public void modifyText(ModifyEvent e) { setButtons(); }});
Label l2 = new Label(c, SWT.NONE);
l2.setText(UIMessages.getString("EnvDialog.1")); //$NON-NLS-1$
l2.setLayoutData(new GridData(GridData.BEGINNING));
text2 = new Text(c, SWT.SINGLE | SWT.BORDER);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.widthHint = 250;
text2.setLayoutData(gd);
text2.addModifyListener(new ModifyListener () {
public void modifyText(ModifyEvent e) { setButtons(); }});
final Button b = new Button(c, SWT.PUSH);
b.setText(UIMessages.getString("EnvDialog.2")); //$NON-NLS-1$
b.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String x = AbstractCPropertyTab.getVariableDialog(b.getShell(), cfgd);
if (x != null) {
text2.insert(x);
setButtons();
}
}});
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.widthHint = AbstractCPropertyTab.BUTTON_WIDTH;
b.setLayoutData(gd);
b_add2all = new Button(c, SWT.CHECK);
b_add2all.setText(UIMessages.getString("EnvDialog.3")); //$NON-NLS-1$
gd = new GridData(GridData.FILL_HORIZONTAL);
if (cfgd == null)
b_add2all.setVisible(false);
else
b_add2all.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
toAll = b_add2all.getSelection();
}});
if (!newAction) {
gd.heightHint = 1;
b_add2all.setVisible(false);
text1.setText(var.getName());
text1.setEnabled(false); // don't change name
String s = var.getValue();
text2.setText(s == null ? AbstractCPropertyTab.EMPTY_STR : s);
}
gd.horizontalSpan = 3;
b_add2all.setLayoutData(gd);
setButtons();
return c;
}
private void setButtons() {
t1 = text1.getText();
t2 = text2.getText();
Button b = getButton(IDialogConstants.OK_ID);
if (b != null)
b.setEnabled(t1.trim().length() > 0);
}
}
|