1 11 package org.eclipse.team.internal.ccvs.ui.wizards; 12 13 14 import java.util.ArrayList ; 15 import java.util.Collections ; 16 import java.util.Comparator ; 17 import java.util.List ; 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 39 public class KSubstWizardSelectionPage extends CVSWizardPage { 40 private KSubstOption ksubst; 41 private List 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 pageName, String title, ImageDescriptor image, KSubstOption defaultKSubst) { 49 super(pageName, title, image); 50 this.ksubst = defaultKSubst; 51 52 KSubstOption[] options = KSubstOption.getAllKSubstOptions(); 54 this.ksubstOptions = new ArrayList (); 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 () { 63 public int compare(Object a, Object b) { 64 String aKey = ((KSubstOption) a).getLongDisplayText(); 65 String 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 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 automaticRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.automaticButton"), 1); automaticRadioButton.addListener(SWT.Selection, selectionListener); 88 automaticRadioButton.setSelection(ksubst == null); 89 createWrappingLabel(top, Policy.bind("KSubstWizardSelectionPage.automaticLabel", Command.KSUBST_BINARY.getLongDisplayText(), 91 CVSProviderPlugin.getPlugin().getDefaultTextKSubstOption().getLongDisplayText()), 92 LABEL_INDENT_WIDTH); 93 94 binaryRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.binaryButton"), 1); binaryRadioButton.addListener(SWT.Selection, selectionListener); 97 binaryRadioButton.setSelection(Command.KSUBST_BINARY.equals(ksubst)); 98 createIndentedLabel(top, Policy.bind("KSubstWizardSelectionPage.binaryLabel"), LABEL_INDENT_WIDTH); 100 textRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.textButton"), 1); textRadioButton.addListener(SWT.Selection, selectionListener); 103 textRadioButton.setSelection(Command.KSUBST_TEXT.equals(ksubst)); 104 createIndentedLabel(top, Policy.bind("KSubstWizardSelectionPage.textLabel"), LABEL_INDENT_WIDTH); 106 ksubstRadioButton = createRadioButton(top, Policy.bind("KSubstWizardSelectionPage.textWithSubstitutionsButton"), 1); ksubstRadioButton.addListener(SWT.Selection, selectionListener); 109 ksubstRadioButton.setSelection(false); 110 createIndentedLabel(top, Policy.bind("KSubstWizardSelectionPage.textWithSubstitutionsLabel"), LABEL_INDENT_WIDTH); 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 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 (! ksubstRadioButton.getSelection()) ksubstOptionCombo.select(i); 129 } 130 } 131 updateEnablements(); 132 Dialog.applyDialogFont(parent); 133 } 134 135 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 |