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
|
package org.eclipse.team.internal.ccvs.ui.wizards;
/*
* (c) Copyright IBM Corp. 2000, 2002.
* All Rights Reserved.
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.team.internal.ccvs.core.client.Command;
import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption;
import org.eclipse.team.internal.ccvs.ui.Policy;
/**
* Page to select keyword substitution mode.
*/
public class KSubstWizardSelectionPage extends CVSWizardPage {
private KSubstOption ksubst;
private List ksubstOptions;
private Button automaticRadioButton;
private Button binaryRadioButton;
private Button textRadioButton;
private Button ksubstRadioButton;
private Combo ksubstOptionCombo;
public KSubstWizardSelectionPage(String pageName, KSubstOption defaultKSubst) {
super(pageName);
this.ksubst = defaultKSubst;
// sort the options by display text
KSubstOption[] options = KSubstOption.getAllKSubstOptions();
this.ksubstOptions = new ArrayList();
for (int i = 0; i < options.length; i++) {
KSubstOption option = options[i];
if (! (Command.KSUBST_BINARY.equals(option) ||
Command.KSUBST_TEXT.equals(option))) {
ksubstOptions.add(option);
}
}
Collections.sort(ksubstOptions, new Comparator() {
public int compare(Object a, Object b) {
String aKey = ((KSubstOption) a).getLongDisplayText();
String bKey = ((KSubstOption) b).getLongDisplayText();
return aKey.compareTo(bKey);
}
});
}
public void createControl(Composite parent) {
Composite top = new Composite(parent, SWT.NONE);
top.setLayout(new GridLayout());
setControl(top);
Listener selectionListener = new Listener() {
public void handleEvent(Event event) {
updateEnablements();
}
};
// Automatic
automaticRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.automaticButton"), 1);
automaticRadioButton.addListener(SWT.Selection, selectionListener);
automaticRadioButton.setSelection(ksubst == null);
createWrappingLabel(top, Policy.bind("KSubstWizardSelectionPage.automaticLabel"), LABEL_INDENT_WIDTH, LABEL_WIDTH_HINT);
// Binary
binaryRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.binaryButton"), 1);
binaryRadioButton.addListener(SWT.Selection, selectionListener);
binaryRadioButton.setSelection(Command.KSUBST_BINARY.equals(ksubst));
createIndentedLabel(top, Policy.bind("KSubstWizardSelectionPage.binaryLabel"), LABEL_INDENT_WIDTH);
// Text without keyword substitution
textRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.textButton"), 1);
textRadioButton.addListener(SWT.Selection, selectionListener);
textRadioButton.setSelection(Command.KSUBST_TEXT.equals(ksubst));
createIndentedLabel(top, Policy.bind("KSubstWizardSelectionPage.textLabel"), LABEL_INDENT_WIDTH);
// Text with keyword substitution
ksubstRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.textWithSubstitutionsButton"), 1);
ksubstRadioButton.addListener(SWT.Selection, selectionListener);
ksubstRadioButton.setSelection(false);
createIndentedLabel(top, Policy.bind("KSubstWizardSelectionPage.textWithSubstitutionsLabel"), LABEL_INDENT_WIDTH);
ksubstOptionCombo = new Combo(top, SWT.READ_ONLY);
ksubstOptionCombo.addListener(SWT.Selection, selectionListener);
GridData data = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_BEGINNING);
data.horizontalIndent = LABEL_INDENT_WIDTH;
ksubstOptionCombo.setLayoutData(data);
// populate the combo box and select the default option
for (int i = 0; i < ksubstOptions.size(); ++i) {
KSubstOption option = (KSubstOption) ksubstOptions.get(i);
ksubstOptionCombo.add(option.getLongDisplayText());
if (option.equals(ksubst)) {
ksubstOptionCombo.select(i);
ksubstRadioButton.setSelection(true);
} else if (option.equals(Command.KSUBST_TEXT_EXPAND)) {
// if no expansion mode selected, show KSUBST_TEXT_EXPAND
// since it is the server default
if (! ksubstRadioButton.getSelection()) ksubstOptionCombo.select(i);
}
}
updateEnablements();
}
/**
* Enable and disable controls based on the selected radio button.
*/
protected void updateEnablements() {
if (ksubstRadioButton.getSelection()) {
ksubstOptionCombo.setEnabled(true);
ksubst = (KSubstOption) ksubstOptions.get(ksubstOptionCombo.getSelectionIndex());
} else {
ksubstOptionCombo.setEnabled(false);
if (automaticRadioButton.getSelection()) {
ksubst = null;
} else if (binaryRadioButton.getSelection()) {
ksubst = Command.KSUBST_BINARY;
} else if (textRadioButton.getSelection()) {
ksubst = Command.KSUBST_TEXT;
}
}
}
public KSubstOption getKSubstOption() {
return ksubst;
}
}
|