1 11 package org.eclipse.ltk.internal.ui.refactoring; 12 13 import com.ibm.icu.text.Collator; 14 15 import java.util.ArrayList ; 16 import java.util.Collection ; 17 import java.util.Collections ; 18 import java.util.Comparator ; 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.Set ; 23 24 import org.eclipse.core.runtime.CoreException; 25 26 import org.eclipse.ltk.core.refactoring.Change; 27 import org.eclipse.ltk.core.refactoring.CompositeChange; 28 import org.eclipse.ltk.core.refactoring.GroupCategory; 29 import org.eclipse.ltk.core.refactoring.RefactoringStatus; 30 import org.eclipse.ltk.core.refactoring.TextEditBasedChange; 31 import org.eclipse.ltk.core.refactoring.TextEditBasedChangeGroup; 32 33 import org.eclipse.ltk.internal.ui.refactoring.util.ViewerPane; 34 35 import org.eclipse.swt.SWT; 36 import org.eclipse.swt.custom.BusyIndicator; 37 import org.eclipse.swt.custom.SashForm; 38 import org.eclipse.swt.graphics.Point; 39 import org.eclipse.swt.graphics.Rectangle; 40 import org.eclipse.swt.layout.GridData; 41 import org.eclipse.swt.layout.GridLayout; 42 import org.eclipse.swt.widgets.Composite; 43 import org.eclipse.swt.widgets.Control; 44 import org.eclipse.swt.widgets.Event; 45 import org.eclipse.swt.widgets.Label; 46 import org.eclipse.swt.widgets.Menu; 47 import org.eclipse.swt.widgets.MenuItem; 48 import org.eclipse.swt.widgets.ToolBar; 49 import org.eclipse.swt.widgets.ToolItem; 50 51 import org.eclipse.jface.action.Action; 52 import org.eclipse.jface.action.ActionContributionItem; 53 import org.eclipse.jface.action.IAction; 54 import org.eclipse.jface.action.IMenuCreator; 55 import org.eclipse.jface.action.Separator; 56 import org.eclipse.jface.action.ToolBarManager; 57 import org.eclipse.jface.dialogs.Dialog; 58 import org.eclipse.jface.dialogs.IDialogConstants; 59 import org.eclipse.jface.dialogs.IDialogSettings; 60 import org.eclipse.jface.dialogs.MessageDialog; 61 import org.eclipse.jface.viewers.CheckStateChangedEvent; 62 import org.eclipse.jface.viewers.ICheckStateListener; 63 import org.eclipse.jface.viewers.ILabelProvider; 64 import org.eclipse.jface.viewers.ISelectionChangedListener; 65 import org.eclipse.jface.viewers.IStructuredSelection; 66 import org.eclipse.jface.viewers.ITreeContentProvider; 67 import org.eclipse.jface.viewers.SelectionChangedEvent; 68 import org.eclipse.jface.viewers.StructuredSelection; 69 import org.eclipse.jface.viewers.Viewer; 70 import org.eclipse.jface.viewers.ViewerComparator; 71 72 import org.eclipse.ui.PlatformUI; 73 import org.eclipse.ui.part.PageBook; 74 75 import org.eclipse.compare.CompareUI; 76 77 import org.eclipse.ltk.ui.refactoring.ChangePreviewViewerInput; 78 import org.eclipse.ltk.ui.refactoring.IChangePreviewViewer; 79 import org.eclipse.ltk.ui.refactoring.RefactoringWizard; 80 import org.eclipse.ltk.ui.refactoring.RefactoringWizardPage; 81 82 86 public class PreviewWizardPage extends RefactoringWizardPage implements IPreviewWizardPage { 87 88 private static final String PREVIEW_WIZARD_PAGE_HIDE_DERIVED= "PreviewWizardPage.hide.derived"; protected static final String PREVIOUS_CHANGE_ID= "org.eclipse.ltk.ui.refactoring.previousChange"; protected static final String NEXT_CHANGE_ID= "org.eclipse.ltk.ui.refactoring.nextChange"; 92 private static class NullPreviewer implements IChangePreviewViewer { 93 private Label fLabel; 94 public void createControl(Composite parent) { 95 fLabel= new Label(parent, SWT.CENTER | SWT.FLAT); 96 fLabel.setText(RefactoringUIMessages.PreviewWizardPage_no_preview); 97 } 98 public void refresh() { 99 } 100 public Control getControl() { 101 return fLabel; 102 } 103 public void setInput(ChangePreviewViewerInput input) { 104 } 105 } 106 107 private class NextChange extends Action { 108 public NextChange() { 109 setId(NEXT_CHANGE_ID); 110 setImageDescriptor(CompareUI.DESC_ETOOL_NEXT); 111 setDisabledImageDescriptor(CompareUI.DESC_DTOOL_NEXT); 112 setHoverImageDescriptor(CompareUI.DESC_CTOOL_NEXT); 113 setToolTipText(RefactoringUIMessages.PreviewWizardPage_next_Change); 114 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRefactoringHelpContextIds.NEXT_CHANGE_ACTION); 115 } 116 public void run() { 117 fTreeViewer.revealNext(); 118 } 119 } 120 121 private class PreviousChange extends Action { 122 public PreviousChange() { 123 setId(PREVIOUS_CHANGE_ID); 124 setImageDescriptor(CompareUI.DESC_ETOOL_PREV); 125 setDisabledImageDescriptor(CompareUI.DESC_DTOOL_PREV); 126 setHoverImageDescriptor(CompareUI.DESC_CTOOL_PREV); 127 setToolTipText(RefactoringUIMessages.PreviewWizardPage_previous_Change); 128 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRefactoringHelpContextIds.PREVIOUS_CHANGE_ACTION); 129 } 130 public void run() { 131 fTreeViewer.revealPrevious(); 132 } 133 } 134 135 private class FilterAction extends Action { 136 137 private FilterDropDownAction fOwner; 138 139 private GroupCategory fGroupCategory; 140 141 public FilterAction(FilterDropDownAction owner, GroupCategory category) { 142 super(category.getName(), IAction.AS_RADIO_BUTTON); 143 setToolTipText(category.getDescription()); 144 fOwner= owner; 145 fGroupCategory= category; 146 } 147 148 public void run() { 149 BusyIndicator.showWhile(getShell().getDisplay(), new Runnable () { 150 151 public void run() { 152 setActiveGroupCategory(fGroupCategory); 153 fOwner.executed(FilterAction.this); 154 } 155 }); 156 } 157 } 158 159 private class ShowAllAction extends Action { 160 161 private FilterDropDownAction fOwner; 162 163 public ShowAllAction(FilterDropDownAction owner) { 164 super(RefactoringUIMessages.PreviewWizardPage_showAll_text, IAction.AS_RADIO_BUTTON); 165 super.setToolTipText(RefactoringUIMessages.PreviewWizardPage_showAll_description); 166 fOwner= owner; 167 setChecked(true); 168 } 169 170 public void run() { 171 BusyIndicator.showWhile(getShell().getDisplay(), new Runnable () { 172 173 public final void run() { 174 clearGroupCategories(); 175 fOwner.executed(ShowAllAction.this); 176 } 177 }); 178 } 179 } 180 private class HideDerivedAction extends Action { 181 public HideDerivedAction() { 182 super(RefactoringUIMessages.PreviewWizardPage_hideDerived_text, IAction.AS_CHECK_BOX); 183 setChecked(fDerivedFilterActive); 184 } 185 public void run() { 186 BusyIndicator.showWhile(getShell().getDisplay(), new Runnable () { 187 public final void run() { 188 boolean hideDerived= isChecked(); 189 getRefactoringSettings().put(PREVIEW_WIZARD_PAGE_HIDE_DERIVED, hideDerived); 190 setHideDerived(hideDerived); 191 } 192 }); 193 } 194 } 195 private class FilterDropDownAction extends Action implements IMenuCreator { 196 private Menu fMenu; 197 private ShowAllAction fShowAllAction; 198 private FilterAction[] fFilterActions; 199 private Action fActiveAction; 200 private HideDerivedAction fHideDerivedAction; 201 202 public FilterDropDownAction() { 203 setImageDescriptor(RefactoringPluginImages.DESC_ELCL_FILTER); 204 setDisabledImageDescriptor(RefactoringPluginImages.DESC_DLCL_FILTER); 205 setText(RefactoringUIMessages.PreviewWizardPage_filterChanges); 206 setToolTipText(RefactoringUIMessages.PreviewWizardPage_filterChanges); 207 setMenuCreator(this); 208 } 209 public void initialize(Collection groupCategories) { 210 List list= new ArrayList (groupCategories); 211 Collections.sort(list, new Comparator () { 212 private Collator fCollator= Collator.getInstance(); 213 public final int compare(final Object first, final Object second) { 214 final GroupCategory left= (GroupCategory) first; 215 final GroupCategory right= (GroupCategory) second; 216 return fCollator.compare(left.getName(), right.getName()); 217 } 218 }); 219 fShowAllAction= new ShowAllAction(this); 220 fActiveAction= fShowAllAction; 221 fFilterActions= new FilterAction[list.size()]; 222 int i= 0; 223 for (Iterator iter= list.iterator(); iter.hasNext();) { 224 fFilterActions[i++]= new FilterAction(this, (GroupCategory)iter.next()); 225 } 226 fHideDerivedAction= new HideDerivedAction(); 227 } 228 public void dispose() { 229 if (fMenu != null) { 230 fMenu.dispose(); 231 fMenu= null; 232 } 233 } 234 public Menu getMenu(Control parent) { 235 dispose(); 236 fMenu= new Menu(parent); 237 if (fFilterActions.length != 0) { 238 new ActionContributionItem(fShowAllAction).fill(fMenu, -1); 239 for (int i= 0; i < fFilterActions.length; i++) { 240 new ActionContributionItem(fFilterActions[i]).fill(fMenu, -1); 241 } 242 new MenuItem(fMenu, SWT.SEPARATOR); 243 } 244 new ActionContributionItem(fHideDerivedAction).fill(fMenu, -1); 245 return fMenu; 246 } 247 public Menu getMenu(Menu parent) { 248 return null; 249 } 250 public void runWithEvent(Event event) { 251 ToolItem toolItem= (ToolItem) event.widget; 252 ToolBar toolBar= toolItem.getParent(); 253 Menu menu= getMenu(toolBar); 254 Rectangle toolItemBounds= toolItem.getBounds(); 255 Point location= toolBar.toDisplay(toolItemBounds.x, toolItemBounds.y + toolItemBounds.height); 256 menu.setLocation(location); 257 menu.setVisible(true); 258 } 259 public void executed(Action action) { 260 if (fActiveAction == action) 261 return; 262 fActiveAction.setChecked(false); 263 fActiveAction= action; 264 fActiveAction.setChecked(true); 265 if (fCurrentSelection != null) 266 showPreview(fCurrentSelection); 267 } 268 } 269 270 protected Change fChange; 271 private List fActiveGroupCategories; 272 private boolean fDerivedFilterActive; 273 protected CompositeChange fTreeViewerInputChange; 274 private PreviewNode fCurrentSelection; 275 private PageBook fPageContainer; 276 private Control fStandardPage; 277 private Control fNullPage; 278 protected Action fFilterDropDownAction; 279 protected Action fNextAction; 280 protected Action fPreviousAction; 281 protected ViewerPane fTreeViewerPane; 282 protected ChangeElementTreeViewer fTreeViewer; 283 private PageBook fPreviewContainer; 284 private ChangePreviewViewerDescriptor fCurrentDescriptor; 285 private IChangePreviewViewer fCurrentPreviewViewer; 286 private IChangePreviewViewer fNullPreviewer; 287 288 291 public PreviewWizardPage() { 292 super(PAGE_NAME); 293 setDescription(RefactoringUIMessages.PreviewWizardPage_description); 294 } 295 296 303 public PreviewWizardPage(boolean wizard) { 304 super(PAGE_NAME, wizard); 305 setDescription(RefactoringUIMessages.PreviewWizardPage_description); 306 } 307 308 313 public void setChange(Change change) { 314 if (fChange == change) 315 return; 316 317 fChange= change; 318 if (fChange instanceof CompositeChange) { 319 fTreeViewerInputChange= (CompositeChange)fChange; 320 } else { 321 fTreeViewerInputChange= new CompositeChange("Dummy Change"); fTreeViewerInputChange.add(fChange); 323 } 324 setTreeViewerInput(); 325 } 326 327 335 protected ChangeElementTreeViewer createTreeViewer(Composite parent) { 336 return new ChangeElementTreeViewer(parent); 337 } 338 339 345 protected ITreeContentProvider createTreeContentProvider() { 346 return new ChangeElementContentProvider(); 347 } 348 349 355 protected ILabelProvider createTreeLabelProvider() { 356 return new ChangeElementLabelProvider(); 358 } 359 360 protected ViewerComparator createTreeComparator() { 361 return new ViewerComparator() { 362 public int compare(Viewer viewer, Object e1, Object e2) { 363 PreviewNode node1= (PreviewNode) e1; 364 PreviewNode node2= (PreviewNode) e2; 365 if (node1.hasDerived()) { 366 if (node2.hasDerived()) { 367 return 0; 368 } else { 369 return +1; 370 } 371 } else { 372 if (node2.hasDerived()) { 373 return -1; 374 } else { 375 return 0; 376 } 377 } 378 } 379 }; 380 } 381 382 385 protected boolean performFinish() { 386 UIPerformChangeOperation operation= new UIPerformChangeOperation(getShell().getDisplay(), fChange, getContainer()); 387 FinishResult result= getRefactoringWizard().internalPerformFinish(InternalAPI.INSTANCE, operation); 388 if (result.isException()) 389 return true; 390 if (result.isInterrupted()) 391 return false; 392 RefactoringStatus fValidationStatus= operation.getValidationStatus(); 393 if (fValidationStatus != null && fValidationStatus.hasFatalError()) { 394 RefactoringWizard wizard= getRefactoringWizard(); 395 MessageDialog.openError(wizard.getShell(), wizard.getWindowTitle(), 396 Messages.format( 397 RefactoringUIMessages.RefactoringUI_cannot_execute, 398 fValidationStatus.getMessageMatchingSeverity(RefactoringStatus.FATAL))); 399 return true; 400 } 401 return true; 402 } 403 404 407 public boolean canFlipToNextPage() { 408 return false; 409 } 410 411 414 public void createControl(Composite parent) { 415 initializeDialogUnits(parent); 416 fPageContainer= new PageBook(parent, SWT.NONE); 417 fStandardPage= createStandardPreviewPage(fPageContainer); 418 fNullPage= createNullPage(fPageContainer); 419 setControl(fPageContainer); 420 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IRefactoringHelpContextIds.REFACTORING_PREVIEW_WIZARD_PAGE); 421 } 422 423 private Composite createStandardPreviewPage(Composite parent) { 424 Composite result= new Composite(parent, SWT.NONE); 426 GridLayout layout= new GridLayout(); 427 layout.marginHeight= 0; layout.marginWidth= 0; 428 result.setLayout(layout); 429 430 SashForm sashForm= new SashForm(result, SWT.VERTICAL); 431 432 fTreeViewerPane= new ViewerPane(sashForm, SWT.BORDER | SWT.FLAT); 433 ToolBarManager tbm= fTreeViewerPane.getToolBarManager(); 434 fNextAction= new NextChange(); 435 tbm.add(fNextAction); 436 fPreviousAction= new PreviousChange(); 437 tbm.add(fPreviousAction); 438 tbm.add(new Separator()); 439 final IDialogSettings settings= getRefactoringSettings(); 440 if (settings != null) 441 fDerivedFilterActive= settings.getBoolean(PREVIEW_WIZARD_PAGE_HIDE_DERIVED); 442 fFilterDropDownAction= new FilterDropDownAction(); 443 tbm.add(fFilterDropDownAction); 444 tbm.update(true); 445 446 fTreeViewer= createTreeViewer(fTreeViewerPane); 447 fTreeViewer.setContentProvider(createTreeContentProvider()); 448 fTreeViewer.setLabelProvider(createTreeLabelProvider()); 449 fTreeViewer.setComparator(createTreeComparator()); 450 fTreeViewer.addSelectionChangedListener(createSelectionChangedListener()); 451 fTreeViewer.addCheckStateListener(createCheckStateListener()); 452 fTreeViewerPane.setContent(fTreeViewer.getControl()); 453 setHideDerived(fDerivedFilterActive); 454 setTreeViewerInput(); 455 updateTreeViewerPaneTitle(); 456 457 fPreviewContainer= new PageBook(sashForm, SWT.NONE); 458 fNullPreviewer= new NullPreviewer(); 459 fNullPreviewer.createControl(fPreviewContainer); 460 fPreviewContainer.showPage(fNullPreviewer.getControl()); 461 fCurrentPreviewViewer= fNullPreviewer; 462 fCurrentDescriptor= null; 463 464 sashForm.setWeights(new int[]{33, 67}); 465 GridData gd= new GridData(GridData.FILL_BOTH); 466 gd.widthHint= convertWidthInCharsToPixels(80); 467 sashForm.setLayoutData(gd); 468 Dialog.applyDialogFont(result); 469 return result; 470 } 471 472 private Control createNullPage(Composite parent) { 473 Composite result= new Composite(parent, SWT.NONE); 474 GridLayout layout= new GridLayout(); 475 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 476 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 477 result.setLayout(layout); 478 Label label= new Label(result, SWT.CENTER); 479 label.setText(RefactoringUIMessages.PreviewWizardPage_no_source_code_change); 480 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 481 Dialog.applyDialogFont(result); 482 return result; 483 } 484 485 488 public void setVisible(boolean visible) { 489 fCurrentSelection= null; 490 final RefactoringWizard refactoringWizard= getRefactoringWizard(); 491 if (hasChanges()) { 492 fPageContainer.showPage(fStandardPage); 493 AbstractChangeNode treeViewerInput= (AbstractChangeNode)fTreeViewer.getInput(); 494 if (visible && treeViewerInput != null) { 495 IStructuredSelection selection= (IStructuredSelection)fTreeViewer.getSelection(); 496 if (selection.isEmpty()) { 497 ITreeContentProvider provider= (ITreeContentProvider)fTreeViewer.getContentProvider(); 498 ViewerComparator comparator= fTreeViewer.getComparator(); 499 PreviewNode element= getFirstNonCompositeChange(provider, comparator, treeViewerInput); 500 if (element != null) { 501 if (refactoringWizard != null && refactoringWizard.internalGetExpandFirstNode(InternalAPI.INSTANCE)) { 502 Object [] subElements= provider.getElements(element); 503 if (subElements != null && subElements.length > 0) { 504 comparator.sort(fTreeViewer, subElements); 505 fTreeViewer.expandToLevel(element, 999); 506 } 507 } 508 fTreeViewer.setSelection(new StructuredSelection(element)); 509 } 510 } 511 } 512 ((FilterDropDownAction) fFilterDropDownAction).initialize(collectGroupCategories()); 513 super.setVisible(visible); 514 fTreeViewer.getControl().setFocus(); 515 } else { 516 fPageContainer.showPage(fNullPage); 517 super.setVisible(visible); 518 } 519 if (refactoringWizard != null) 520 refactoringWizard.internalSetPreviewShown(InternalAPI.INSTANCE, visible); 521 } 522 523 private PreviewNode getFirstNonCompositeChange(ITreeContentProvider provider, ViewerComparator comparator, AbstractChangeNode input) { 524 PreviewNode focus= input; 525 Change change= input.getChange(); 526 while (change != null && change instanceof CompositeChange) { 527 PreviewNode[] children= (PreviewNode[])provider.getElements(focus); 528 if (children == null || children.length == 0) 529 return null; 530 comparator.sort(fTreeViewer, children); 531 focus= children[0]; 532 change= (focus instanceof AbstractChangeNode) 533 ? ((AbstractChangeNode)focus).getChange() 534 : null; 535 } 536 return focus; 537 } 538 539 protected void setTreeViewerInput() { 540 if (fTreeViewer == null) 541 return; 542 PreviewNode input= null; 543 if (fTreeViewerInputChange != null) { 544 input= AbstractChangeNode.createNode(null, fTreeViewerInputChange); 545 } 546 fTreeViewer.setInput(input); 547 } 548 549 private ICheckStateListener createCheckStateListener() { 550 return new ICheckStateListener() { 551 public void checkStateChanged(CheckStateChangedEvent event){ 552 PreviewNode element= (PreviewNode)event.getElement(); 553 if (isChild(fCurrentSelection, element) || isChild(element, fCurrentSelection)) { 554 showPreview(fCurrentSelection); 555 } 556 } 557 private boolean isChild(PreviewNode element, PreviewNode child) { 558 while (child != null) { 559 if (child == element) 560 return true; 561 child= child.getParent(); 562 } 563 return false; 564 } 565 }; 566 } 567 568 private ISelectionChangedListener createSelectionChangedListener() { 569 return new ISelectionChangedListener(){ 570 public void selectionChanged(SelectionChangedEvent event) { 571 IStructuredSelection sel= (IStructuredSelection) event.getSelection(); 572 if (sel.size() == 1) { 573 PreviewNode newSelection= (PreviewNode)sel.getFirstElement(); 574 if (newSelection != fCurrentSelection) { 575 fCurrentSelection= newSelection; 576 showPreview(newSelection); 577 } 578 } else { 579 showPreview(null); 580 } 581 } 582 }; 583 } 584 585 private void showPreview(PreviewNode element) { 586 try { 587 if (element == null) { 588 showNullPreviewer(); 589 } else { 590 ChangePreviewViewerDescriptor descriptor= element.getChangePreviewViewerDescriptor(); 591 if (fCurrentDescriptor != descriptor) { 592 IChangePreviewViewer newViewer; 593 if (descriptor != null) { 594 newViewer= descriptor.createViewer(); 595 newViewer.createControl(fPreviewContainer); 596 } else { 597 newViewer= fNullPreviewer; 598 } 599 fCurrentDescriptor= descriptor; 600 element.feedInput(newViewer, fActiveGroupCategories); 601 if (fCurrentPreviewViewer != null && fCurrentPreviewViewer != fNullPreviewer) 602 fCurrentPreviewViewer.getControl().dispose(); 603 fCurrentPreviewViewer= newViewer; 604 fPreviewContainer.showPage(fCurrentPreviewViewer.getControl()); 605 } else { 606 element.feedInput(fCurrentPreviewViewer, fActiveGroupCategories); 607 } 608 } 609 } catch (CoreException e) { 610 showNullPreviewer(); 611 ExceptionHandler.handle(e, getShell(), 612 RefactoringUIMessages.PreviewWizardPage_refactoring, 613 RefactoringUIMessages.PreviewWizardPage_Internal_error); 614 } 615 } 616 617 private void showNullPreviewer() { 618 fCurrentDescriptor= null; 619 fCurrentPreviewViewer= fNullPreviewer; 620 fPreviewContainer.showPage(fCurrentPreviewViewer.getControl()); 621 } 622 623 629 public boolean hasChanges() { 630 if (fChange == null) 631 return false; 632 if (fChange instanceof CompositeChange) 633 return hasChanges((CompositeChange) fChange); 634 return true; 635 } 636 637 private boolean hasChanges(CompositeChange change) { 638 final Change[] children= change.getChildren(); 639 for (int index= 0; index < children.length; index++) { 640 if (children[index] instanceof CompositeChange) { 641 if (hasChanges((CompositeChange) children[index])) 642 return true; 643 } else 644 return true; 645 } 646 return false; 647 } 648 649 651 private Collection collectGroupCategories() { 652 Set result= new HashSet (); 653 collectGroupCategories(result, fChange); 654 return result; 655 } 656 657 private void collectGroupCategories(Set result, Change change) { 658 if (change instanceof TextEditBasedChange) { 659 TextEditBasedChangeGroup[] groups= ((TextEditBasedChange)change).getChangeGroups(); 660 for (int i= 0; i < groups.length; i++) { 661 result.addAll(groups[i].getGroupCategorySet().asList()); 662 } 663 } else if (change instanceof CompositeChange) { 664 Change[] children= ((CompositeChange)change).getChildren(); 665 for (int i= 0; i < children.length; i++) { 666 collectGroupCategories(result, children[i]); 667 } 668 } 669 } 670 671 private void setActiveGroupCategory(GroupCategory category) { 672 if (fActiveGroupCategories == null) { 673 fActiveGroupCategories= new ArrayList (1); 674 } else { 675 fActiveGroupCategories.clear(); 676 } 677 fActiveGroupCategories.add(category); 678 fTreeViewer.setGroupCategory(fActiveGroupCategories); 679 updateTreeViewerPaneTitle(); 680 } 681 682 private void updateTreeViewerPaneTitle() { 683 String derivedMessage= null; 684 String groupFilterMessage= null; 685 686 if (fDerivedFilterActive) { 687 if (fTreeViewer != null && fTreeViewer.getInput() instanceof PreviewNode) { 688 if (((PreviewNode) fTreeViewer.getInput()).hasDerived()) { 689 derivedMessage= RefactoringUIMessages.PreviewWizardPage_changes_filter_derived; 690 } 691 } 692 } 693 if (fActiveGroupCategories != null && fActiveGroupCategories.size() > 0) { 694 GroupCategory groupCategory= (GroupCategory) fActiveGroupCategories.get(0); 695 groupFilterMessage= Messages.format(RefactoringUIMessages.PreviewWizardPage_changes_filter_category, groupCategory.getName()); 696 } 697 698 String title; 699 if (groupFilterMessage == null && derivedMessage == null) { 700 title= RefactoringUIMessages.PreviewWizardPage_changes; 701 702 } else if (groupFilterMessage != null && derivedMessage != null) { 703 title= Messages.format( 704 RefactoringUIMessages.PreviewWizardPage_changes_filtered2, 705 new Object [] { groupFilterMessage, derivedMessage }); 706 707 } else if (groupFilterMessage != null) { 708 title= Messages.format( 709 RefactoringUIMessages.PreviewWizardPage_changes_filtered, 710 groupFilterMessage); 711 } else { 712 title= Messages.format( 713 RefactoringUIMessages.PreviewWizardPage_changes_filtered, 714 derivedMessage); 715 } 716 717 fTreeViewerPane.setText(title); 718 } 719 720 private void clearGroupCategories() { 721 fActiveGroupCategories= null; 722 fTreeViewer.setGroupCategory(null); 723 updateTreeViewerPaneTitle(); 724 } 725 726 private void setHideDerived(boolean hide) { 727 fDerivedFilterActive= hide; 728 fTreeViewer.setHideDerived(hide); 729 updateTreeViewerPaneTitle(); 730 } 731 732 public Change getChange() { 733 return fChange; 734 } 735 } 736 | Popular Tags |