1 11 package org.eclipse.team.internal.ccvs.ui.wizards; 12 13 14 import java.util.Arrays ; 15 import java.util.Comparator ; 16 import java.util.List ; 17 18 import org.eclipse.core.resources.IFile; 19 import org.eclipse.jface.dialogs.Dialog; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 import org.eclipse.jface.viewers.CellEditor; 22 import org.eclipse.jface.viewers.CheckStateChangedEvent; 23 import org.eclipse.jface.viewers.CheckboxTableViewer; 24 import org.eclipse.jface.viewers.ColumnWeightData; 25 import org.eclipse.jface.viewers.ComboBoxCellEditor; 26 import org.eclipse.jface.viewers.ICellModifier; 27 import org.eclipse.jface.viewers.ICheckStateListener; 28 import org.eclipse.jface.viewers.ILabelProviderListener; 29 import org.eclipse.jface.viewers.IStructuredContentProvider; 30 import org.eclipse.jface.viewers.IStructuredSelection; 31 import org.eclipse.jface.viewers.ITableLabelProvider; 32 import org.eclipse.jface.viewers.TableLayout; 33 import org.eclipse.jface.viewers.Viewer; 34 import org.eclipse.jface.viewers.ViewerFilter; 35 import org.eclipse.swt.SWT; 36 import org.eclipse.swt.custom.BusyIndicator; 37 import org.eclipse.swt.custom.TableEditor; 38 import org.eclipse.swt.graphics.Image; 39 import org.eclipse.swt.layout.GridData; 40 import org.eclipse.swt.layout.GridLayout; 41 import org.eclipse.swt.widgets.Button; 42 import org.eclipse.swt.widgets.Composite; 43 import org.eclipse.swt.widgets.Event; 44 import org.eclipse.swt.widgets.Listener; 45 import org.eclipse.swt.widgets.Table; 46 import org.eclipse.swt.widgets.TableColumn; 47 import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption; 48 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds; 49 import org.eclipse.team.internal.ccvs.ui.Policy; 50 import org.eclipse.team.internal.ccvs.ui.wizards.KSubstWizard.KSubstChangeElement; 51 import org.eclipse.ui.help.WorkbenchHelp; 52 import org.eclipse.ui.model.WorkbenchViewerSorter; 53 54 public class KSubstWizardSummaryPage extends CVSWizardPage { 55 private CheckboxTableViewer tableViewer = null; 56 private KSubstOption[] ksubstOptions; 57 private String [] ksubstOptionsDisplayText; 58 private int filterType; 59 60 private Button showUnaffectedFilesButton; 61 private boolean showUnaffectedFiles; 62 63 public KSubstWizardSummaryPage(String pageName, String title, ImageDescriptor image, boolean showUnaffectedFiles) { 64 super(pageName, title, image); 65 this.showUnaffectedFiles = showUnaffectedFiles; 66 67 ksubstOptions = KSubstOption.getAllKSubstOptions(); 69 ksubstOptionsDisplayText = new String [ksubstOptions.length]; 70 Arrays.sort(ksubstOptions, new Comparator () { 71 public int compare(Object a, Object b) { 72 String aKey = getModeDisplayText((KSubstOption) a); 73 String bKey = getModeDisplayText((KSubstOption) b); 74 return aKey.compareTo(bKey); 75 } 76 }); 77 for (int i = 0; i < ksubstOptions.length; i++) { 78 ksubstOptionsDisplayText[i] = getModeDisplayText(ksubstOptions[i]); 79 } 80 } 81 82 public void createControl(Composite parent) { 83 Composite top = new Composite(parent, SWT.NONE); 84 top.setLayout(new GridLayout()); 85 setControl(top); 86 createWrappingLabel(top, Policy.bind("KSubstWizardSummaryPage.contents"), 0); 88 WorkbenchHelp.setHelp(top, IHelpContextIds.KEYWORD_SUBSTITUTION_SUMMARY_PAGE); 90 91 createSeparator(top, 0); 92 93 showUnaffectedFilesButton = new Button(top, SWT.CHECK); 94 showUnaffectedFilesButton.setText(Policy.bind("KSubstWizardSummaryPage.showUnaffectedFiles")); showUnaffectedFilesButton.setSelection(showUnaffectedFiles); 96 showUnaffectedFilesButton.addListener(SWT.Selection, new Listener() { 97 public void handleEvent(Event e) { 98 BusyIndicator.showWhile(getContainer().getShell().getDisplay(), new Runnable () { 99 public void run() { 100 showUnaffectedFiles = showUnaffectedFilesButton.getSelection(); 101 refresh(false); 102 } 103 }); 104 } 105 }); 106 107 tableViewer = createFileTableViewer(top, 108 Policy.bind("KSubstWizardSummaryPage.summaryViewer.title"), Policy.bind("KSubstWizardSummaryPage.summaryViewer.fileHeader"), Policy.bind("KSubstWizardSummaryPage.summaryViewer.ksubstHeader"), LIST_HEIGHT_HINT); 112 Dialog.applyDialogFont(parent); 113 } 114 115 123 public CheckboxTableViewer createFileTableViewer(Composite parent, String title, 124 String fileHeader, String ksubstHeader, int heightHint) { 125 createLabel(parent, title); 126 Table table = new Table(parent, SWT.CHECK | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER | SWT.FULL_SELECTION); 128 GridData data = new GridData(GridData.FILL_BOTH); 129 data.heightHint = heightHint; 130 table.setLayoutData(data); 131 table.setLinesVisible(true); 132 table.setHeaderVisible(true); 133 134 TableColumn column = new TableColumn(table, SWT.LEFT); 136 column.setText(fileHeader); 137 column = new TableColumn(table, SWT.LEFT); 138 column.setText(ksubstHeader); 139 TableLayout tableLayout = new TableLayout(); 140 table.setLayout(tableLayout); 141 tableLayout.addColumnData(new ColumnWeightData(1, true)); 142 tableLayout.addColumnData(new ColumnWeightData(1, true)); 143 144 final CheckboxTableViewer tableViewer = new CheckboxTableViewer(table); 146 tableViewer.setContentProvider(new IStructuredContentProvider() { 147 public Object [] getElements(Object inputElement) { 148 return (Object []) inputElement; 149 } 150 public void dispose() { 151 } 152 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 153 } 154 }); 155 156 tableViewer.setLabelProvider(new ITableLabelProvider() { 158 public Image getColumnImage(Object element, int columnIndex) { 159 return null; 160 } 161 public String getColumnText(Object element, int columnIndex) { 162 KSubstChangeElement change = (KSubstChangeElement) element; 163 if (columnIndex == 0) { 164 return change.getFile().getFullPath().toString(); 165 } else if (columnIndex == 1) { 166 return getModeDisplayText(change.getKSubst()); 167 } 168 return null; 169 } 170 public void addListener(ILabelProviderListener listener) { 171 } 172 public void dispose() { 173 } 174 public boolean isLabelProperty(Object element, String property) { 175 return false; 176 } 177 public void removeListener(ILabelProviderListener listener) { 178 } 179 }); 180 181 tableViewer.setSorter(new WorkbenchViewerSorter() { 183 public int compare(Viewer viewer, Object e1, Object e2) { 184 IFile file1 = ((KSubstChangeElement) e1).getFile(); 185 IFile file2 = ((KSubstChangeElement) e2).getFile(); 186 return super.compare(viewer, file1, file2); 187 } 188 }); 189 190 tableViewer.addFilter(new ViewerFilter() { 192 public boolean select(Viewer viewer, Object parentElement, Object element) { 193 KSubstChangeElement change = (KSubstChangeElement) element; 194 return ( showUnaffectedFiles || change.isNewKSubstMode()) && change.matchesFilter(filterType); 195 } 196 }); 197 198 tableViewer.addCheckStateListener(new ICheckStateListener() { 200 public void checkStateChanged(CheckStateChangedEvent event) { 201 KSubstChangeElement change = (KSubstChangeElement) event.getElement(); 202 if (tableViewer.getGrayed(change)) { 203 updateCheckStatus(change); 205 } else { 206 change.setExcluded(! event.getChecked()); 208 } 209 } 210 }); 211 212 TableEditor tableEditor = new TableEditor(table); 214 CellEditor cellEditor = new ComboBoxCellEditor(table, ksubstOptionsDisplayText); 215 tableViewer.setCellEditors(new CellEditor[] { null, cellEditor }); 216 tableViewer.setColumnProperties(new String [] { "file", "mode" }); tableViewer.setCellModifier(new ICellModifier() { 218 public Object getValue(Object element, String property) { 219 KSubstChangeElement change = (KSubstChangeElement) element; 220 KSubstOption option = change.getKSubst(); 221 for (int i = 0; i < ksubstOptions.length; ++i) { 222 if (ksubstOptions[i].equals(option)) return new Integer (i); 223 } 224 return null; 226 } 227 public boolean canModify(Object element, String property) { 228 return true; 229 } 230 public void modify(Object element, String property, Object value) { 231 IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); 235 element = selection.getFirstElement(); 236 int index = ((Integer ) value).intValue(); 237 if (index != -1) { 239 KSubstChangeElement change = (KSubstChangeElement) element; 240 KSubstOption newOption = ksubstOptions[index]; 241 if (! newOption.equals(change.getKSubst())) { 242 change.setKSubst(newOption); 245 change.setExcluded(false); 246 tableViewer.refresh(change, true ); 247 updateCheckStatus(change); 248 } 249 } 250 } 251 }); 252 return tableViewer; 253 } 254 255 public void setChangeList(List changes, int filterType) { 256 this.filterType = filterType; 257 tableViewer.setInput(changes.toArray()); 258 refresh(true); 259 } 260 261 private void refresh(boolean updateLabels) { 262 tableViewer.refresh(updateLabels); 263 Object [] elements = (Object []) tableViewer.getInput(); 264 for (int i = 0; i < elements.length; i++) { 265 KSubstChangeElement change = (KSubstChangeElement) elements[i]; 266 updateCheckStatus(change); 267 } 268 } 269 270 private void updateCheckStatus(KSubstChangeElement change) { 271 if (change.isNewKSubstMode()) { 272 tableViewer.setGrayed(change, false); 274 tableViewer.setChecked(change, ! change.isExcluded()); 275 } else { 276 tableViewer.setGrayed(change, true); 278 tableViewer.setChecked(change, false); 279 } 280 } 281 282 private String getModeDisplayText(KSubstOption option) { 283 return option.getLongDisplayText(); 284 } 285 public void setVisible(boolean visible) { 286 super.setVisible(visible); 287 if (visible) { 288 showUnaffectedFilesButton.setFocus(); 289 } 290 } 291 } 292 | Popular Tags |