1 11 package org.eclipse.team.internal.ccvs.ui.wizards; 12 13 14 import java.text.Collator ; import java.util.ArrayList ; 16 import java.util.Arrays ; 17 import java.util.Comparator ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Observable ; 21 import java.util.Observer ; 22 23 import org.eclipse.jface.dialogs.IDialogConstants; 24 import org.eclipse.jface.resource.JFaceResources; 25 import org.eclipse.jface.viewers.*; 26 import org.eclipse.jface.wizard.WizardPage; 27 import org.eclipse.osgi.util.NLS; 28 import org.eclipse.swt.SWT; 29 import org.eclipse.swt.custom.SashForm; 30 import org.eclipse.swt.events.ModifyEvent; 31 import org.eclipse.swt.events.ModifyListener; 32 import org.eclipse.swt.events.SelectionAdapter; 33 import org.eclipse.swt.events.SelectionEvent; 34 import org.eclipse.swt.events.SelectionListener; 35 import org.eclipse.swt.graphics.Image; 36 import org.eclipse.swt.layout.GridData; 37 import org.eclipse.swt.layout.GridLayout; 38 import org.eclipse.swt.widgets.Button; 39 import org.eclipse.swt.widgets.Combo; 40 import org.eclipse.swt.widgets.Composite; 41 import org.eclipse.swt.widgets.Group; 42 import org.eclipse.swt.widgets.Item; 43 import org.eclipse.swt.widgets.Label; 44 import org.eclipse.swt.widgets.Shell; 45 import org.eclipse.swt.widgets.Table; 46 import org.eclipse.swt.widgets.TableColumn; 47 import org.eclipse.swt.widgets.Text; 48 import org.eclipse.team.internal.ccvs.core.client.Command.KSubstOption; 49 import org.eclipse.team.internal.ccvs.core.util.StringMatcher; 50 import org.eclipse.team.internal.ccvs.ui.*; 51 import org.eclipse.team.internal.ccvs.ui.wizards.ModeWizard.ModeChange; 52 import org.eclipse.team.internal.ui.PixelConverter; 53 import org.eclipse.team.internal.ui.SWTUtils; 54 import org.eclipse.ui.PlatformUI; 55 import org.eclipse.ui.model.WorkbenchLabelProvider; 56 57 60 public class ModeWizardSelectionPage extends WizardPage { 61 62 private final static class ModeChangeCellModifier implements ICellModifier { 63 64 private final ModeChangeTable fTable; 65 66 public ModeChangeCellModifier(ModeChangeTable table) { 67 fTable= table; 68 } 69 70 public boolean canModify(Object element, String property) { 71 return PROPERTY_MODE.equals(property); 72 } 73 74 public Object getValue(Object element, String property) { 75 if (PROPERTY_MODE.equals(property)) { 76 final KSubstOption mode= ((ModeChange)element).getNewMode(); 77 for (int i = 0; i < MODES.length; i++) { 78 if (MODES[i].equals(mode)) { 79 return new Integer (i); 80 } 81 } 82 } 83 return null; 84 } 85 86 public void modify(Object element, String property, Object value) { 87 if (element instanceof Item) 88 element= ((Item)element).getData(); 89 if (PROPERTY_MODE.equals(property)) { 90 ((ModeChange)element).setNewMode(MODES[((Integer )value).intValue()]); 91 fTable.modelChanged(true); 92 } 93 } 94 } 95 96 private final static class ModeChangeLabelProvider implements ITableLabelProvider { 97 98 private final DecoratingLabelProvider fDecoratingLP; 99 private final ModeChangeTable fTable; 100 101 public ModeChangeLabelProvider(ModeChangeTable table) { 102 fTable= table; 103 fDecoratingLP= new DecoratingLabelProvider(new WorkbenchLabelProvider(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()); 104 fDecoratingLP.addListener(fTable); 105 } 106 107 public Image getColumnImage(Object element, int columnIndex) { 108 if (columnIndex == INDEX_FILE) { 109 return fDecoratingLP.getImage(((ModeChange)element).getFile()); 110 } 111 return null; 112 } 113 114 public String getColumnText(Object element, int columnIndex) { 115 final ModeChange change= (ModeChange)element; 116 switch (columnIndex) { 117 case INDEX_FILE: return (change.hasChanged() ? "* " : "") + change.getFile().getName(); case INDEX_MODE: return change.getNewMode().getLongDisplayText(); 119 case INDEX_PATH: return change.getFile().getFullPath().toOSString(); 120 } 121 throw new IllegalArgumentException (); 122 } 123 124 public void addListener(ILabelProviderListener listener) { 125 } 126 127 public boolean isLabelProperty(Object element, String property) { 128 return false; 129 } 130 131 public void dispose() { 132 fDecoratingLP.removeListener(fTable); 133 } 134 135 public void removeListener(ILabelProviderListener listener) { 136 } 137 } 138 139 private final static class TableComparator extends ViewerComparator implements SelectionListener { 140 141 private final Collator fCollator; 142 private final TableViewer fViewer; 143 private final TableColumn fFile, fMode, fPath; 144 145 private int fIndex; 146 private boolean fAscending; 147 148 149 public TableComparator(TableViewer viewer, TableColumn fileColumn, TableColumn modeColumn, TableColumn pathColumn) { 150 fCollator= Collator.getInstance(); 152 fViewer= viewer; 153 154 fFile= fileColumn; 155 fMode= modeColumn; 156 fPath= pathColumn; 157 158 fIndex= INDEX_FILE; 160 fViewer.getTable().setSortColumn(fFile); 161 fViewer.getTable().setSortDirection(SWT.DOWN); 162 fAscending= true; 163 164 fileColumn.addSelectionListener(this); 165 modeColumn.addSelectionListener(this); 166 pathColumn.addSelectionListener(this); 167 } 168 169 public int compare(Viewer viewer, Object e1, Object e2) { 170 171 final ModeChange mc1= (ModeChange)e1; 172 final ModeChange mc2= (ModeChange)e2; 173 174 final String s1, s2; 175 176 switch (fIndex) { 177 178 case INDEX_FILE: 179 s1= mc1.getFile().getName(); 180 s2= mc2.getFile().getName(); 181 break; 182 183 case INDEX_MODE: 184 s1= mc1.getNewMode().getLongDisplayText(); 185 s2= mc2.getNewMode().getLongDisplayText(); 186 break; 187 188 case INDEX_PATH: 189 s1= mc1.getFile().getFullPath().toOSString(); 190 s2= mc2.getFile().getFullPath().toOSString(); 191 break; 192 193 default: 194 throw new IllegalArgumentException (); 195 } 196 197 final int compare= fCollator.compare(s1, s2); 198 return fAscending ? compare : -compare; 199 } 200 201 public void widgetSelected(SelectionEvent e) { 202 final int index= columnToIndex(e.widget); 203 if (index == fIndex) { 204 fIndex= index; 205 fAscending= !fAscending; 206 fViewer.getTable().setSortDirection(fAscending ? SWT.DOWN : SWT.UP); 207 } else { 208 fIndex= index; 209 TableColumn tableCol = null; 210 switch(fIndex){ 211 case INDEX_FILE: 212 tableCol = fFile; 213 break; 214 215 case INDEX_MODE: 216 tableCol = fMode; 217 break; 218 219 case INDEX_PATH: 220 tableCol = fPath; 221 break; 222 } 223 fViewer.getTable().setSortColumn(tableCol); 224 fViewer.getTable().setSortDirection(fAscending ? SWT.DOWN : SWT.UP); 225 } 226 fViewer.refresh(); 227 } 228 229 public void widgetDefaultSelected(SelectionEvent e) { 230 } 232 233 private int columnToIndex(Object column) { 234 if (column == fFile) return INDEX_FILE; 235 if (column == fMode) return INDEX_MODE; 236 if (column == fPath) return INDEX_PATH; 237 throw new IllegalArgumentException (); 238 } 239 } 240 241 private static final class ModeChangeTable extends Observable implements ISelectionChangedListener, ILabelProviderListener { 242 243 private final List fChanges; 244 private final TableViewer fViewer; 245 private final Filter fFilter; 246 private int fNumberOfChanges; 247 248 public ModeChangeTable(Composite composite, PixelConverter converter, List changes) { 249 250 fChanges= changes; 251 fNumberOfChanges= 0; 252 253 256 final Table table = new Table(composite, SWT.V_SCROLL | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); 257 table.setLayoutData(SWTUtils.createHVFillGridData()); 258 table.setLinesVisible(false); 259 table.setHeaderVisible(true); 260 261 264 final TableColumn fileColumn = new TableColumn(table, SWT.NONE, INDEX_FILE); 265 fileColumn.setWidth(converter.convertWidthInCharsToPixels(LARGE_COLUMN)); 266 fileColumn.setText(CVSUIMessages.ModeWizardSelectionPage_2); 267 table.setSortColumn(fileColumn); 268 table.setSortDirection(SWT.DOWN); 269 272 final TableColumn newModeColumn = new TableColumn(table, SWT.NONE, INDEX_MODE); 273 newModeColumn.setWidth(converter.convertWidthInCharsToPixels(COLUMN_MIN_WIDTH_IN_CHARS + 6)); 274 newModeColumn.setText(CVSUIMessages.ModeWizardSelectionPage_3); 275 276 279 final TableColumn pathColumn= new TableColumn(table, SWT.NONE, INDEX_PATH); 280 pathColumn.setWidth(converter.convertWidthInCharsToPixels(50)); 281 pathColumn.setText(CVSUIMessages.ModeWizardSelectionPage_4); 282 283 284 fViewer= new TableViewer(table); 285 fViewer.setContentProvider(new ModeChangeContentProvider()); 286 fViewer.setLabelProvider(new ModeChangeLabelProvider(this)); 287 fViewer.getControl().setLayoutData(SWTUtils.createHVFillGridData()); 288 289 final CellEditor newModeEditor = new ComboBoxCellEditor(table, COMBO_TEXT, SWT.READ_ONLY); 290 291 fViewer.setCellEditors(new CellEditor [] { null, newModeEditor, null }); 292 fViewer.setColumnProperties(new String [] { PROPERTY_FILE, PROPERTY_MODE, PROPERTY_CHANGED }); 293 fViewer.setCellModifier(new ModeChangeCellModifier(this)); 294 295 fViewer.addFilter(fFilter= new Filter()); 296 297 fViewer.setComparator(new TableComparator(fViewer, fileColumn, newModeColumn, pathColumn)); 298 299 fViewer.setInput(fChanges); 300 301 fViewer.addSelectionChangedListener(this); 303 304 fileColumn.addSelectionListener(new SelectionAdapter() { 305 public void widgetSelected(SelectionEvent e) { 306 307 } 308 }); 309 310 fViewer.refresh(); 311 } 312 313 public TableViewer getViewer() { 314 return fViewer; 315 } 316 317 public void selectionChanged(SelectionChangedEvent event) { 318 setChanged(); 319 notifyObservers(fViewer.getSelection()); 320 } 321 322 public void modelChanged(boolean updateLabels) { 323 fViewer.refresh(updateLabels); 324 fNumberOfChanges= 0; 325 for (Iterator iter = fChanges.iterator(); iter.hasNext();) { 326 ModeChange change = (ModeChange) iter.next(); 327 if (change.hasChanged()) 328 ++fNumberOfChanges; 329 } 330 setChanged(); 331 notifyObservers(); 332 } 333 334 public Filter getFilter() { 335 return fFilter; 336 } 337 338 public IStructuredSelection getSelection() { 339 return (IStructuredSelection)fViewer.getSelection(); 340 } 341 342 public void labelProviderChanged(LabelProviderChangedEvent event) { 343 fViewer.refresh(); 344 } 345 346 public void selectAll() { 347 fViewer.setSelection(new StructuredSelection(fChanges)); 348 fViewer.getControl().setFocus(); 349 } 350 351 public void selectNone() { 352 fViewer.setSelection(StructuredSelection.EMPTY); 353 fViewer.getControl().setFocus(); 354 } 355 356 public int getNumberOfChanges() { 357 return fNumberOfChanges; 358 } 359 } 360 361 private static final class ModeChangeContentProvider implements IStructuredContentProvider { 362 363 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 364 } 365 366 public Object [] getElements(Object inputElement) { 367 return ((List )inputElement).toArray(); 370 } 371 372 public void dispose() { 373 } 374 } 375 376 private static final class ModeCombo extends SelectionAdapter implements Observer { 377 378 private final Combo fCombo; 379 private final ModeChangeTable fTable; 380 381 public ModeCombo(ModeChangeTable table, Composite parent) { 382 fTable= table; 383 fCombo= new Combo(parent, SWT.READ_ONLY); 384 fCombo.setLayoutData(SWTUtils.createHFillGridData()); 385 fCombo.setItems(COMBO_TEXT); 386 fCombo.addSelectionListener(this); 387 fTable.addObserver(this); 388 } 389 390 public void widgetSelected(SelectionEvent e) { 391 final KSubstOption mode= MODES[fCombo.getSelectionIndex()]; 392 final IStructuredSelection selection= fTable.getSelection(); 393 for (final Iterator iter = selection.iterator(); iter.hasNext();) { 394 final ModeChange change = (ModeChange) iter.next(); 395 change.setNewMode(mode); 396 } 397 fTable.modelChanged(true); 398 } 399 400 public void update(Observable o, Object arg) { 401 final IStructuredSelection selection= (IStructuredSelection)fTable.getViewer().getSelection(); 402 403 if (selection.isEmpty()) { 404 fCombo.deselectAll(); 405 fCombo.setEnabled(false); 406 } else { 407 fCombo.setEnabled(true); 408 final KSubstOption option= ((ModeChange)selection.getFirstElement()).getNewMode(); 409 for (Iterator iter = selection.iterator(); iter.hasNext();) { 410 if (option != ((ModeChange)iter.next()).getNewMode()) { 411 fCombo.deselectAll(); 412 return; 413 } 414 } 415 fCombo.setText(option.getLongDisplayText()); 416 } 417 } 418 } 419 420 private static final class Filter extends ViewerFilter { 421 422 private boolean fFilterUnchanged; 423 private StringMatcher fMatcher; 424 425 public Filter() { 426 fFilterUnchanged= false; 427 fMatcher= new StringMatcher("*", true, false); } 429 430 public boolean select(Viewer viewer, Object parentElement, Object element) { 431 final ModeChange change= (ModeChange)element; 432 if (fFilterUnchanged && !change.hasChanged()) 433 return false; 434 if (!fMatcher.match(change.getFile().getName())) 435 return false; 436 return true; 437 } 438 439 public void setPattern(String pattern) { 440 pattern= pattern.trim(); 441 if (!pattern.endsWith("*")) { pattern += "*"; } 444 fMatcher= new StringMatcher(pattern, true, false); 445 } 446 447 public void filterUnchanged(boolean filter) { 448 fFilterUnchanged= filter; 449 } 450 } 451 452 private static final class ResetButton extends SelectionAdapter implements Observer { 453 454 private final ModeChangeTable fTable; 455 private final Button fButton; 456 457 public ResetButton(ModeChangeTable table, Composite parent, PixelConverter converter) { 458 final int buttonWidth= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 459 fTable= table; 460 fButton= new Button(parent, SWT.NONE); 461 fButton.setLayoutData(SWTUtils.createGridData(buttonWidth, SWT.DEFAULT, SWT.FILL, SWT.CENTER, false, false)); 462 fButton.setText(CVSUIMessages.ModeWizardSelectionPage_8); 463 fButton.setToolTipText(CVSUIMessages.ModeWizardSelectionPage_9); 464 fButton.addSelectionListener(this); 465 fTable.addObserver(this); 466 } 467 468 public void widgetSelected(SelectionEvent e) { 469 fButton.setEnabled(false); 470 final IStructuredSelection selection= fTable.getSelection(); 471 for (Iterator iter = selection.iterator(); iter.hasNext();) { 472 final ModeChange change = (ModeChange) iter.next(); 473 change.setNewMode(change.getMode()); 474 } 475 fTable.modelChanged(true); 476 } 477 478 public void update(Observable o, Object arg) { 479 final IStructuredSelection selection= fTable.getSelection(); 480 for (final Iterator iter = selection.iterator(); iter.hasNext();) { 481 if (((ModeChange)iter.next()).hasChanged()) { 482 fButton.setEnabled(true); 483 return; 484 } 485 } 486 fButton.setEnabled(false); 487 } 488 } 489 490 private static final class GuessButton extends SelectionAdapter implements Observer { 491 492 private final ModeChangeTable fTable; 493 private final Button fButton; 494 495 public GuessButton(ModeChangeTable table, Composite parent, PixelConverter converter) { 496 fTable= table; 497 final int buttonWidth= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 498 fButton= new Button(parent, SWT.NONE); 499 fButton.setLayoutData(SWTUtils.createGridData(buttonWidth, SWT.DEFAULT, SWT.FILL, SWT.CENTER, false, false)); 500 fButton.setText(CVSUIMessages.ModeWizardSelectionPage_10); 501 fButton.setToolTipText(CVSUIMessages.ModeWizardSelectionPage_11); 502 fButton.addSelectionListener(this); 503 fTable.addObserver(this); 504 505 } 506 507 public void widgetSelected(SelectionEvent e) { 508 final IStructuredSelection selection= fTable.getSelection(); 509 for (Iterator iter = selection.iterator(); iter.hasNext();) { 510 final ModeChange change = (ModeChange) iter.next(); 511 change.setNewMode(KSubstOption.fromFile(change.getFile())); 512 } 513 fTable.modelChanged(true); 514 } 515 516 public void update(Observable o, Object arg) { 517 fButton.setEnabled(!fTable.getSelection().isEmpty()); 518 } 519 } 520 521 private static final class SelectAllButton extends SelectionAdapter { 522 523 private final ModeWizardSelectionPage fPage; 524 private final Button fButton; 525 526 public SelectAllButton(ModeWizardSelectionPage page, Composite parent, PixelConverter converter) { 527 fPage= page; 528 final int buttonWidth= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 529 fButton= new Button(parent, SWT.NONE); 530 fButton.setLayoutData(SWTUtils.createGridData(buttonWidth, SWT.DEFAULT, SWT.FILL, SWT.CENTER, false, false)); 531 fButton.setText(CVSUIMessages.ModeWizardSelectionPage_12); 532 fButton.addSelectionListener(this); 533 } 534 535 public void widgetSelected(SelectionEvent e) { 536 fPage.getTable().selectAll(); 537 } 538 } 539 540 private static final class SelectNoneButton extends SelectionAdapter { 541 542 private final ModeWizardSelectionPage fPage; 543 private final Button fButton; 544 545 public SelectNoneButton(ModeWizardSelectionPage page, Composite parent, PixelConverter converter) { 546 fPage= page; 547 final int buttonWidth= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 548 fButton= new Button(parent, SWT.NONE); 549 fButton.setLayoutData(SWTUtils.createGridData(buttonWidth, SWT.DEFAULT, SWT.FILL, SWT.CENTER, false, false)); 550 fButton.setText(CVSUIMessages.ModeWizardSelectionPage_13); 551 fButton.addSelectionListener(this); 552 } 553 554 public void widgetSelected(SelectionEvent e) { 555 fPage.getTable().selectNone(); 556 } 557 } 558 559 private static final class ShowChangesOnlyCheckbox extends SelectionAdapter { 560 561 private final ModeWizardSelectionPage fPage; 562 private final Button fCheck; 563 564 public ShowChangesOnlyCheckbox(ModeWizardSelectionPage page, Composite parent) { 565 fPage= page; 566 fCheck= new Button(parent, SWT.CHECK); 567 fCheck.setText(CVSUIMessages.ModeWizardSelectionPage_14); 568 fCheck.setLayoutData(SWTUtils.createHFillGridData()); 569 fCheck.setSelection(false); 570 fCheck.addSelectionListener(this); 571 } 572 573 public void widgetSelected(SelectionEvent e) { 574 final ModeChangeTable table= fPage.getTable(); 575 table.getFilter().filterUnchanged(fCheck.getSelection()); 576 table.modelChanged(true); 577 } 578 } 579 580 private static final class FilterTextBox extends SelectionAdapter implements ModifyListener { 581 private final ModeWizardSelectionPage fPage; 582 private final Text fTextField; 583 584 public FilterTextBox(ModeWizardSelectionPage page, Composite parent, PixelConverter converter) { 585 fPage= page; 586 fTextField= new Text(parent, SWT.SINGLE | SWT.BORDER); 587 fTextField.setLayoutData(SWTUtils.createHFillGridData()); 588 589 final int buttonWidth= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); 590 final Button button= new Button(parent, SWT.PUSH); 591 button.setText(CVSUIMessages.ModeWizardSelectionPage_15); 592 button.setLayoutData(SWTUtils.createGridData(buttonWidth, SWT.DEFAULT, SWT.FILL, SWT.CENTER, false, false)); 593 button.addSelectionListener(this); 594 595 fTextField.addModifyListener(this); 596 } 597 598 public void widgetSelected(SelectionEvent e) { 599 fTextField.setText(""); fTextField.setFocus(); 601 } 602 603 public void modifyText(ModifyEvent e) { 604 final ModeChangeTable table= fPage.getTable(); 605 table.getFilter().setPattern(fTextField.getText()); 606 table.modelChanged(false); 607 } 608 609 public void setFocus() { 610 fTextField.setFocus(); 611 } 612 } 613 614 private static final class ChangeCounterLabel implements Observer { 615 616 private final Label fLabel; 617 private final ModeChangeTable fTable; 618 619 ChangeCounterLabel(Composite parent, ModeChangeTable table) { 620 fTable= table; 621 fTable.addObserver(this); 622 fLabel= SWTUtils.createLabel(parent, null); 623 fLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); 624 } 625 626 public void update(Observable o, Object arg) { 627 updateText(fTable.getNumberOfChanges()); 628 } 629 630 633 private void updateText(int numberOfChanges) { 634 fLabel.setText(NLS.bind(CVSUIMessages.ModeWizardSelectionPage_17, new String [] { Integer.toString(numberOfChanges) })); 635 } 636 637 } 638 639 private static final class SelectionCounterLabel implements Observer { 640 641 private final Label fLabel; 642 private final ModeChangeTable fTable; 643 644 public SelectionCounterLabel(Composite parent, ModeChangeTable table) { 645 fTable= table; 646 fTable.addObserver(this); 647 fLabel= new Label(parent, SWT.WRAP | SWT.RIGHT); 648 fLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); 649 } 650 651 public void update(Observable o, Object arg) { 652 updateText(fTable.getSelection().size()); 653 } 654 655 658 private void updateText(int selected) { 659 fLabel.setText(NLS.bind(CVSUIMessages.ModeWizardSelectionPage_25, new String [] { Integer.toString(selected) })); 660 } 661 } 662 663 private final static int LARGE_COLUMN= 50; 664 665 protected static final int INDEX_FILE= 0; 666 protected static final int INDEX_MODE= 1; 667 protected static final int INDEX_PATH= 2; 668 669 protected static final String PROPERTY_FILE= "file"; protected static final String PROPERTY_MODE= "mode"; protected static final String PROPERTY_CHANGED= "changed"; 673 protected static final KSubstOption [] MODES; 674 protected static final String [] COMBO_TEXT; 675 676 static final int COLUMN_MIN_WIDTH_IN_CHARS; 677 678 static { 679 MODES= KSubstOption.getAllKSubstOptions(); 680 Arrays.sort(MODES, new Comparator () { 681 public int compare(Object a, Object b) { 682 String aKey = ((KSubstOption)a).getLongDisplayText(); 683 String bKey = ((KSubstOption) b).getLongDisplayText(); 684 return aKey.compareTo(bKey); 685 } 686 }); 687 COMBO_TEXT= new String [MODES.length]; 688 int maxLength= 0; 689 for (int i = 0; i < MODES.length; i++) { 690 COMBO_TEXT[i]= MODES[i].getLongDisplayText(); 691 if (COMBO_TEXT[i].length() > maxLength) maxLength= COMBO_TEXT[i].length(); 692 } 693 COLUMN_MIN_WIDTH_IN_CHARS= maxLength; 694 } 695 696 private final List fChanges; 697 protected ModeChangeTable fTable; 698 699 private CommitCommentArea fCommentArea; 700 701 public ModeWizardSelectionPage(List modeChanges) { 702 super(CVSUIMessages.ModeWizardSelectionPage_18, CVSUIMessages.ModeWizardSelectionPage_19, CVSUIPlugin.getPlugin().getImageDescriptor(ICVSUIConstants.IMG_WIZBAN_KEYWORD)); setDescription(CVSUIMessages.ModeWizardSelectionPage_20); 704 fChanges= modeChanges; 705 } 706 707 public void createControl(final Composite parent) { 708 709 final PixelConverter converter= SWTUtils.createDialogPixelConverter(parent); 710 711 final int horizontalSpace= converter.convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 712 final int verticalSpace= converter.convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 713 714 717 final Composite mainComposite= SWTUtils.createHVFillComposite(parent, SWTUtils.MARGINS_DEFAULT); 718 PlatformUI.getWorkbench().getHelpSystem().setHelp(mainComposite, IHelpContextIds.KEYWORD_SUBSTITUTION_PAGE); 720 721 final SashForm mainSash= new SashForm(mainComposite, SWT.VERTICAL); 722 mainSash.setLayoutData(SWTUtils.createHVFillGridData()); 723 724 727 final Composite topComposite= SWTUtils.createHVFillComposite(mainSash, SWTUtils.MARGINS_NONE); 728 ((GridLayout)topComposite.getLayout()).marginBottom= verticalSpace; 729 730 final Composite topGroup= SWTUtils.createHVFillGroup(topComposite, CVSUIMessages.ModeWizardSelectionPage_21, SWTUtils.MARGINS_DIALOG); 731 732 final Composite filterComposite= SWTUtils.createHFillComposite(topGroup, SWTUtils.MARGINS_NONE, 2); 733 final FilterTextBox filterBox= new FilterTextBox(ModeWizardSelectionPage.this, filterComposite, converter); 734 735 fTable= new ModeChangeTable(topGroup, converter, fChanges); 736 737 final Composite selectionComposite= SWTUtils.createHFillComposite(topGroup, SWTUtils.MARGINS_NONE, 2); 738 739 new ChangeCounterLabel(selectionComposite, fTable); 740 new SelectionCounterLabel(selectionComposite, fTable); 741 742 new ShowChangesOnlyCheckbox(ModeWizardSelectionPage.this, selectionComposite); 743 744 final Composite buttonComposite= SWTUtils.createHFillComposite(selectionComposite, SWTUtils.MARGINS_NONE, 2); 745 buttonComposite.setLayoutData(new GridData()); 746 new SelectAllButton(ModeWizardSelectionPage.this, buttonComposite, converter); 747 new SelectNoneButton(ModeWizardSelectionPage.this, buttonComposite, converter); 748 749 752 final SashForm bottomSash= new SashForm(mainSash, SWT.NONE); 753 bottomSash.setLayoutData(SWTUtils.createHFillGridData()); 754 755 758 final Composite leftComposite= SWTUtils.createHVFillComposite(bottomSash, SWTUtils.MARGINS_NONE, 1); 759 ((GridLayout)leftComposite.getLayout()).marginRight= horizontalSpace; 760 ((GridLayout)leftComposite.getLayout()).marginTop= verticalSpace; 761 762 final Group leftGroup= SWTUtils.createHVFillGroup(leftComposite, CVSUIMessages.ModeWizardSelectionPage_22, SWTUtils.MARGINS_DIALOG, 3); 763 764 new ModeCombo(fTable, leftGroup); 765 new GuessButton(fTable, leftGroup, converter); 766 new ResetButton(fTable, leftGroup, converter); 767 SWTUtils.createPlaceholder(leftGroup, 1); 768 final Label infoLabel= SWTUtils.createLabel(leftGroup, CVSUIMessages.ModeWizardSelectionPage_23, 3); 769 770 fTable.addObserver(new Observer () { 771 public void update(Observable o, Object arg) { 772 final boolean enabled= !fTable.getSelection().isEmpty(); 773 leftGroup.setEnabled(enabled); 774 infoLabel.setEnabled(enabled); 775 } 776 }); 777 778 781 final Composite rightComposite= SWTUtils.createHVFillComposite(bottomSash, SWTUtils.MARGINS_NONE); 782 ((GridLayout)rightComposite.getLayout()).marginLeft= horizontalSpace; 783 ((GridLayout)rightComposite.getLayout()).marginTop= verticalSpace; 784 785 final Group rightGroup= SWTUtils.createHVFillGroup(rightComposite, CVSUIMessages.ModeWizardSelectionPage_24, SWTUtils.MARGINS_DIALOG); 786 (fCommentArea= new CommitCommentArea()).createArea(rightGroup); 787 788 791 mainSash.setWeights(new int [] { 5, 2 }); 792 bottomSash.setWeights(new int [] { 3, 2 }); 793 fTable.modelChanged(true); 794 fTable.selectAll(); 795 filterBox.setFocus(); 796 setControl(mainComposite); 797 } 798 799 protected ModeChangeTable getTable() { 800 return fTable; 801 } 802 803 public List getChanges() { 804 final List changes= new ArrayList (); 805 for (Iterator iter = fChanges.iterator(); iter.hasNext();) { 806 final ModeChange change = (ModeChange) iter.next(); 807 if (change.hasChanged()) 808 changes.add(change); 809 } 810 return changes; 811 } 812 813 public String getComment(Shell shell) { 814 return fCommentArea.getCommentWithPrompt(shell); 815 } 816 } 817 | Popular Tags |