KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > wizards > KSubstWizardSelectionPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ccvs.ui.wizards;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.Collections JavaDoc;
16 import java.util.Comparator JavaDoc;
17 import java.util.List JavaDoc;
18
19 import org.eclipse.jface.dialogs.Dialog;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.Button;
25 import org.eclipse.swt.widgets.Combo;
26 import org.eclipse.swt.widgets.Composite;
27 import org.eclipse.swt.widgets.Event;
28 import org.eclipse.swt.widgets.Listener;
29 import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
30 import org.eclipse.team.internal.ccvs.core.client.Command;
31 import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption;
32 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
33 import org.eclipse.team.internal.ccvs.ui.Policy;
34 import org.eclipse.ui.help.WorkbenchHelp;
35
36 /**
37  * Page to select keyword substitution mode.
38  */

39 public class KSubstWizardSelectionPage extends CVSWizardPage {
40     private KSubstOption ksubst;
41     private List JavaDoc ksubstOptions;
42     private Button automaticRadioButton;
43     private Button binaryRadioButton;
44     private Button textRadioButton;
45     private Button ksubstRadioButton;
46     private Combo ksubstOptionCombo;
47
48     public KSubstWizardSelectionPage(String JavaDoc pageName, String JavaDoc title, ImageDescriptor image, KSubstOption defaultKSubst) {
49         super(pageName, title, image);
50         this.ksubst = defaultKSubst;
51
52         // sort the options by display text
53
KSubstOption[] options = KSubstOption.getAllKSubstOptions();
54         this.ksubstOptions = new ArrayList JavaDoc();
55         for (int i = 0; i < options.length; i++) {
56             KSubstOption option = options[i];
57             if (! (Command.KSUBST_BINARY.equals(option) ||
58                 Command.KSUBST_TEXT.equals(option))) {
59                 ksubstOptions.add(option);
60             }
61         }
62         Collections.sort(ksubstOptions, new Comparator JavaDoc() {
63             public int compare(Object JavaDoc a, Object JavaDoc b) {
64                 String JavaDoc aKey = ((KSubstOption) a).getLongDisplayText();
65                 String JavaDoc bKey = ((KSubstOption) b).getLongDisplayText();
66                 return aKey.compareTo(bKey);
67             }
68         });
69     }
70     
71     public void createControl(Composite parent) {
72         Composite top = new Composite(parent, SWT.NONE);
73         top.setLayout(new GridLayout());
74         setControl(top);
75
76         // set F1 help
77
WorkbenchHelp.setHelp(top, IHelpContextIds.KEYWORD_SUBSTITUTION_SELECTION_PAGE);
78         
79         Listener selectionListener = new Listener() {
80             public void handleEvent(Event event) {
81                 updateEnablements();
82             }
83         };
84         
85         // Automatic
86
automaticRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.automaticButton"), 1); //$NON-NLS-1$
87
automaticRadioButton.addListener(SWT.Selection, selectionListener);
88         automaticRadioButton.setSelection(ksubst == null);
89         createWrappingLabel(top, Policy.bind("KSubstWizardSelectionPage.automaticLabel", //$NON-NLS-1$
90
Command.KSUBST_BINARY.getLongDisplayText(),
91             CVSProviderPlugin.getPlugin().getDefaultTextKSubstOption().getLongDisplayText()),
92             LABEL_INDENT_WIDTH);
93
94         // Binary
95
binaryRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.binaryButton"), 1); //$NON-NLS-1$
96
binaryRadioButton.addListener(SWT.Selection, selectionListener);
97         binaryRadioButton.setSelection(Command.KSUBST_BINARY.equals(ksubst));
98         createIndentedLabel(top, Policy.bind("KSubstWizardSelectionPage.binaryLabel"), LABEL_INDENT_WIDTH); //$NON-NLS-1$
99

100         // Text without keyword substitution
101
textRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.textButton"), 1); //$NON-NLS-1$
102
textRadioButton.addListener(SWT.Selection, selectionListener);
103         textRadioButton.setSelection(Command.KSUBST_TEXT.equals(ksubst));
104         createIndentedLabel(top, Policy.bind("KSubstWizardSelectionPage.textLabel"), LABEL_INDENT_WIDTH); //$NON-NLS-1$
105

106         // Text with keyword substitution
107
ksubstRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.textWithSubstitutionsButton"), 1); //$NON-NLS-1$
108
ksubstRadioButton.addListener(SWT.Selection, selectionListener);
109         ksubstRadioButton.setSelection(false);
110         createIndentedLabel(top, Policy.bind("KSubstWizardSelectionPage.textWithSubstitutionsLabel"), LABEL_INDENT_WIDTH); //$NON-NLS-1$
111

112         ksubstOptionCombo = new Combo(top, SWT.READ_ONLY);
113         ksubstOptionCombo.addListener(SWT.Selection, selectionListener);
114         GridData data = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_BEGINNING);
115         data.horizontalIndent = LABEL_INDENT_WIDTH;
116         ksubstOptionCombo.setLayoutData(data);
117
118         // populate the combo box and select the default option
119
for (int i = 0; i < ksubstOptions.size(); ++i) {
120             KSubstOption option = (KSubstOption) ksubstOptions.get(i);
121             ksubstOptionCombo.add(option.getLongDisplayText());
122             if (option.equals(ksubst)) {
123                 ksubstOptionCombo.select(i);
124                 ksubstRadioButton.setSelection(true);
125             } else if (option.equals(Command.KSUBST_TEXT_EXPAND)) {
126                 // if no expansion mode selected, show KSUBST_TEXT_EXPAND
127
// since it is the server default
128
if (! ksubstRadioButton.getSelection()) ksubstOptionCombo.select(i);
129             }
130         }
131         updateEnablements();
132         Dialog.applyDialogFont(parent);
133     }
134     
135     /**
136      * Enable and disable controls based on the selected radio button.
137      */

138     protected void updateEnablements() {
139         if (ksubstRadioButton.getSelection()) {
140             ksubstOptionCombo.setEnabled(true);
141             ksubst = (KSubstOption) ksubstOptions.get(ksubstOptionCombo.getSelectionIndex());
142         } else {
143             ksubstOptionCombo.setEnabled(false);
144             if (automaticRadioButton.getSelection()) {
145                 ksubst = null;
146             } else if (binaryRadioButton.getSelection()) {
147                 ksubst = Command.KSUBST_BINARY;
148             } else if (textRadioButton.getSelection()) {
149                 ksubst = Command.KSUBST_TEXT;
150             }
151         }
152     }
153     
154     public KSubstOption getKSubstOption() {
155         return ksubst;
156     }
157 }
158
Popular Tags