1 11 package org.eclipse.compare; 12 13 import java.lang.reflect.InvocationTargetException ; 14 import java.util.*; 15 16 import org.eclipse.compare.contentmergeviewer.IFlushable; 17 import org.eclipse.compare.internal.*; 18 import org.eclipse.compare.structuremergeviewer.*; 19 import org.eclipse.core.resources.IFile; 20 import org.eclipse.core.runtime.*; 21 import org.eclipse.core.runtime.jobs.Job; 22 import org.eclipse.jface.action.*; 23 import org.eclipse.jface.dialogs.ErrorDialog; 24 import org.eclipse.jface.dialogs.IDialogConstants; 25 import org.eclipse.jface.operation.IRunnableWithProgress; 26 import org.eclipse.jface.preference.IPreferenceStore; 27 import org.eclipse.jface.resource.ImageDescriptor; 28 import org.eclipse.jface.text.IFindReplaceTarget; 29 import org.eclipse.jface.util.IPropertyChangeListener; 30 import org.eclipse.jface.util.PropertyChangeEvent; 31 import org.eclipse.jface.viewers.*; 32 import org.eclipse.osgi.util.NLS; 33 import org.eclipse.swt.SWT; 34 import org.eclipse.swt.custom.BusyIndicator; 35 import org.eclipse.swt.events.DisposeEvent; 36 import org.eclipse.swt.events.DisposeListener; 37 import org.eclipse.swt.graphics.Image; 38 import org.eclipse.swt.widgets.Composite; 39 import org.eclipse.swt.widgets.Control; 40 import org.eclipse.ui.*; 41 import org.eclipse.ui.part.*; 42 import org.eclipse.ui.services.IServiceLocator; 43 44 45 103 public abstract class CompareEditorInput implements IEditorInput, IPropertyChangeNotifier, IRunnableWithProgress, ICompareContainer { 104 105 private static final boolean DEBUG= false; 106 107 110 public static final String DIRTY_STATE= "DIRTY_STATE"; 112 119 public static final String PROP_TITLE= ICompareUIConstants.PROP_TITLE; 120 121 127 public static final String PROP_TITLE_IMAGE= ICompareUIConstants.PROP_TITLE_IMAGE; 128 129 136 public static final String PROP_SELECTED_EDITION= ICompareUIConstants.PROP_SELECTED_EDITION; 137 138 private static final String COMPARE_EDITOR_IMAGE_NAME= "eview16/compare_view.gif"; private static Image fgTitleImage; 140 141 private Splitter fComposite; 142 private CompareConfiguration fCompareConfiguration; 143 private CompareViewerPane fStructureInputPane; 144 private CompareViewerSwitchingPane fStructurePane1; 145 private CompareViewerSwitchingPane fStructurePane2; 146 private CompareViewerSwitchingPane fContentInputPane; 147 private CompareViewerPane fFocusPane; 148 private String fMessage; 149 private Object fInput; 150 private String fTitle; 151 private ListenerList fListenerList= new ListenerList(); 152 private CompareNavigator fNavigator; 153 private boolean fDirty= false; 154 private ArrayList fDirtyViewers= new ArrayList(); 155 private IPropertyChangeListener fDirtyStateListener; 156 157 boolean fStructureCompareOnSingleClick= true; 158 159 private ICompareContainer fContainer; 160 private boolean fContainerProvided; 161 162 private String fHelpContextId; 163 private InternalOutlineViewerCreator fOutlineView; 164 private ICompareAsText fCompareAsText; 165 166 private class InternalOutlineViewerCreator extends OutlineViewerCreator { 167 private OutlineViewerCreator getWrappedCreator() { 168 if (fContentInputPane != null) { 169 Viewer v = fContentInputPane.getViewer(); 170 if (v != null) { 171 return (OutlineViewerCreator)Utilities.getAdapter(v, OutlineViewerCreator.class); 172 } 173 } 174 return null; 175 } 176 public Viewer findStructureViewer(Viewer oldViewer, 177 ICompareInput input, Composite parent, 178 CompareConfiguration configuration) { 179 OutlineViewerCreator creator = getWrappedCreator(); 180 if (creator != null) 181 return creator.findStructureViewer(oldViewer, input, parent, configuration); 182 return null; 183 } 184 185 public boolean hasViewerFor(Object input) { 186 OutlineViewerCreator creator = getWrappedCreator(); 187 return (creator != null); 188 } 189 190 public Object getInput() { 191 OutlineViewerCreator creator = getWrappedCreator(); 192 if (creator != null) 193 return creator.getInput(); 194 return null; 195 } 196 } 197 198 private class CompareAsText implements ICompareAsText { 199 public void compareAsText(Object input) { 200 internalCompareAsText(input); 201 } 202 } 203 204 211 public CompareEditorInput(CompareConfiguration configuration) { 212 fCompareConfiguration= configuration; 213 Assert.isNotNull(configuration); 214 215 fDirtyStateListener= new IPropertyChangeListener() { 216 public void propertyChange(PropertyChangeEvent e) { 217 String propertyName= e.getProperty(); 218 if (CompareEditorInput.DIRTY_STATE.equals(propertyName)) { 219 boolean changed= false; 220 Object newValue= e.getNewValue(); 221 if (newValue instanceof Boolean ) 222 changed= ((Boolean )newValue).booleanValue(); 223 setDirty(e.getSource(), changed); 224 } 225 } 226 }; 227 228 IPreferenceStore ps= configuration.getPreferenceStore(); 229 if (ps != null) 230 fStructureCompareOnSingleClick= ps.getBoolean(ComparePreferencePage.OPEN_STRUCTURE_COMPARE); 231 232 fContainer = configuration.getContainer(); 233 configuration.setContainer(this); 234 } 235 236 void internalCompareAsText(Object input) { 237 Set set = (Set)getCompareConfiguration().getProperty(ICompareAsText.PROP_TEXT_INPUTS); 238 if (set == null) { 239 set = new HashSet(); 240 getCompareConfiguration().setProperty(ICompareAsText.PROP_TEXT_INPUTS, set); 241 } 242 set.add(input); 243 if (fContentInputPane.getInput().equals(input)) { 244 fContentInputPane.setInput(null); 246 fContentInputPane.setInput(input); 247 } 248 } 249 250 private boolean structureCompareOnSingleClick() { 251 return fStructureCompareOnSingleClick; 252 } 253 254 private boolean isShowStructureInOutlineView() { 255 Object object= getCompareConfiguration().getProperty(CompareConfiguration.USE_OUTLINE_VIEW); 256 return (object instanceof Boolean && ((Boolean )object).booleanValue()); 257 } 258 259 262 public Object getAdapter(Class adapter) { 263 if (ICompareNavigator.class.equals(adapter) || CompareNavigator.class.equals(adapter)) { 264 return getNavigator(); 265 } 266 if (adapter == IShowInSource.class) { 267 final IFile file = (IFile)Utilities.getAdapter(this, IFile.class); 268 if (file != null) 269 return new IShowInSource() { 270 public ShowInContext getShowInContext() { 271 return new ShowInContext(new FileEditorInput(file), StructuredSelection.EMPTY); 272 } 273 }; 274 } 275 if (adapter == OutlineViewerCreator.class) { 276 synchronized (this) { 277 if (fOutlineView == null) 278 fOutlineView = new InternalOutlineViewerCreator(); 279 return fOutlineView; 280 } 281 } 282 if (adapter == ICompareAsText.class) { 283 if (fCompareAsText == null) 284 fCompareAsText = new CompareAsText(); 285 return fCompareAsText; 286 } 287 if (adapter == IFindReplaceTarget.class) { 288 if (fContentInputPane != null) { 289 Viewer v = fContentInputPane.getViewer(); 290 if (v != null) { 291 return Utilities.getAdapter(v, IFindReplaceTarget.class); 292 } 293 } 294 } 295 296 return null; 297 } 298 299 public synchronized ICompareNavigator getNavigator() { 300 if (fNavigator == null) 301 fNavigator= new CompareEditorInputNavigator( 302 new Object [] { 303 fStructureInputPane, 304 fStructurePane1, 305 fStructurePane2, 306 fContentInputPane 307 } 308 ); 309 return fNavigator; 310 } 311 312 315 public ImageDescriptor getImageDescriptor() { 316 return null; 317 } 318 319 322 public String getToolTipText() { 323 return getTitle(); 324 } 325 326 329 public String getName() { 330 return getTitle(); 331 } 332 333 338 public IPersistableElement getPersistable() { 339 return null; 340 } 341 342 348 public boolean exists() { 349 return false; 350 } 351 352 355 protected void setMessage(String message) { 356 fMessage= message; 357 } 358 359 362 public String getMessage() { 363 return fMessage; 364 } 365 366 372 public String getTitle() { 373 if (fTitle == null) 374 return Utilities.getString("CompareEditorInput.defaultTitle"); return fTitle; 376 } 377 378 384 public void setTitle(String title) { 385 String oldTitle = fTitle; 386 fTitle= title; 387 Utilities.firePropertyChange(fListenerList, this, PROP_TITLE, oldTitle, title); 388 } 389 390 398 public Image getTitleImage() { 399 if (fgTitleImage == null) { 400 fgTitleImage= CompareUIPlugin.getImageDescriptor(COMPARE_EDITOR_IMAGE_NAME).createImage(); 401 CompareUI.disposeOnShutdown(fgTitleImage); 402 } 403 return fgTitleImage; 404 } 405 406 412 public CompareConfiguration getCompareConfiguration() { 413 return fCompareConfiguration; 414 } 415 416 424 public void contributeToToolBar(ToolBarManager toolBarManager) { 425 ResourceBundle bundle= CompareUI.getResourceBundle(); 426 ChangePropertyAction ignoreWhitespace= ChangePropertyAction.createIgnoreWhiteSpaceAction(bundle, getCompareConfiguration()); 427 toolBarManager.getControl().addDisposeListener(ignoreWhitespace); 428 ChangePropertyAction showPseudoConflicts= ChangePropertyAction.createShowPseudoConflictsAction(bundle, getCompareConfiguration()); 429 toolBarManager.getControl().addDisposeListener(showPseudoConflicts); 430 toolBarManager.add(new Separator()); 431 toolBarManager.add(ignoreWhitespace); 432 toolBarManager.add(showPseudoConflicts); 433 } 434 435 447 public void run(IProgressMonitor monitor) throws InterruptedException , InvocationTargetException { 448 fInput= prepareInput(monitor); 449 } 450 451 472 protected abstract Object prepareInput(IProgressMonitor monitor) 473 throws InvocationTargetException , InterruptedException ; 474 475 483 public Object getCompareResult() { 484 return fInput; 485 } 486 487 499 public Control createContents(Composite parent) { 500 501 fComposite= new Splitter(parent, SWT.VERTICAL); 502 fComposite.setData(this); 503 504 Control outline= createOutlineContents(fComposite, SWT.HORIZONTAL); 505 506 fContentInputPane= new CompareViewerSwitchingPane(fComposite, SWT.BORDER | SWT.FLAT) { 507 protected Viewer getViewer(Viewer oldViewer, Object input) { 508 if (input instanceof ICompareInput) 509 return findContentViewer(oldViewer, (ICompareInput)input, this); 510 return null; 511 } 512 }; 513 if (fFocusPane == null) 514 fFocusPane= fContentInputPane; 515 if (outline != null) 516 fComposite.setVisible(outline, false); 517 fComposite.setVisible(fContentInputPane, true); 518 519 if (fStructureInputPane != null) 520 fComposite.setWeights(new int[] { 30, 70 }); 521 522 fComposite.layout(); 523 524 feedInput(); 525 526 fComposite.addDisposeListener(new DisposeListener() { 527 public void widgetDisposed(DisposeEvent e) { 528 handleDispose(); 529 } 530 }); 531 if (fHelpContextId != null) 532 PlatformUI.getWorkbench().getHelpSystem().setHelp(fComposite, fHelpContextId); 533 contentsCreated(); 534 return fComposite; 535 } 536 537 546 protected void handleDispose() { 547 fContainerProvided = false; 548 fContainer = null; 549 fCompareConfiguration.dispose(); 550 } 551 552 560 protected void contentsCreated() { 561 } 563 564 570 public Control createOutlineContents(Composite parent, int direction) { 571 final Splitter h= new Splitter(parent, direction); 572 573 fStructureInputPane= createStructureInputPane(h); 574 if (hasChildren(getCompareResult())) 575 fFocusPane= fStructureInputPane; 576 577 fStructurePane1= new CompareViewerSwitchingPane(h, SWT.BORDER | SWT.FLAT, true) { 578 protected Viewer getViewer(Viewer oldViewer, Object input) { 579 if (input instanceof ICompareInput) 580 return findStructureViewer(oldViewer, (ICompareInput)input, this); 581 return null; 582 } 583 }; 584 h.setVisible(fStructurePane1, false); 585 586 fStructurePane2= new CompareViewerSwitchingPane(h, SWT.BORDER | SWT.FLAT, true) { 587 protected Viewer getViewer(Viewer oldViewer, Object input) { 588 if (input instanceof ICompareInput) 589 return findStructureViewer(oldViewer, (ICompareInput)input, this); 590 return null; 591 } 592 }; 593 h.setVisible(fStructurePane2, false); 594 595 fStructureInputPane.addOpenListener( 597 new IOpenListener() { 598 public void open(OpenEvent oe) { 599 feed1(oe.getSelection()); 600 } 601 } 602 ); 603 fStructureInputPane.addSelectionChangedListener( 604 new ISelectionChangedListener() { 605 public void selectionChanged(SelectionChangedEvent e) { 606 ISelection s= e.getSelection(); 607 if (s == null || s.isEmpty()) 608 feed1(s); 609 if (isEditionSelectionDialog()) 610 firePropertyChange(new PropertyChangeEvent(this, PROP_SELECTED_EDITION, null, getSelectedEdition())); 611 } 612 } 613 ); 614 fStructureInputPane.addDoubleClickListener( 615 new IDoubleClickListener() { 616 public void doubleClick(DoubleClickEvent event) { 617 feedDefault1(event.getSelection()); 618 } 619 } 620 ); 621 622 fStructurePane1.addSelectionChangedListener( 623 new ISelectionChangedListener() { 624 public void selectionChanged(SelectionChangedEvent e) { 625 feed2(e.getSelection()); 626 } 627 } 628 ); 629 630 fStructurePane2.addSelectionChangedListener( 631 new ISelectionChangedListener() { 632 public void selectionChanged(SelectionChangedEvent e) { 633 feed3(e.getSelection()); 634 } 635 } 636 ); 637 638 return h; 639 } 640 641 649 protected CompareViewerPane createStructureInputPane( 650 final Composite parent) { 651 return new CompareViewerSwitchingPane(parent, SWT.BORDER | SWT.FLAT, true) { 652 protected Viewer getViewer(Viewer oldViewer, Object input) { 653 if (CompareEditorInput.this.hasChildren(input)) { 654 return createDiffViewer(this); 655 } 656 if (input instanceof ICompareInput) 657 return findStructureViewer(oldViewer, (ICompareInput)input, this); 658 return null; 659 } 660 }; 661 } 662 663 boolean hasChildren(Object input) { 664 if (input instanceof IDiffContainer) { 665 IDiffContainer dn= (IDiffContainer) input; 666 return (dn.hasChildren()); 667 } 668 return false; 669 } 670 671 private void feedInput() { 672 if (fStructureInputPane != null 673 && (fInput instanceof ICompareInput 674 || isCustomStructureInputPane())) { 675 if (hasChildren(fInput) || isCustomStructureInputPane()) { 676 fStructureInputPane.setInput(fInput); 678 } else if (!structureCompareOnSingleClick() || isShowStructureInOutlineView()) { 679 internalSetContentPaneInput(fInput); 682 if (hasUnusableContentViewer() 684 || (structureCompareOnSingleClick() 685 && isShowStructureInOutlineView() 686 && !hasOutlineViewer(fInput))) { 687 fStructureInputPane.setInput(fInput); 688 } 689 } else { 690 fStructureInputPane.setInput(fInput); 691 } 692 ISelection sel= fStructureInputPane.getSelection(); 693 if (sel == null || sel.isEmpty()) 694 feed1(sel); } 696 } 697 698 private boolean hasOutlineViewer(Object input) { 699 if (!isShowStructureInOutlineView()) 700 return false; 701 OutlineViewerCreator creator = (OutlineViewerCreator)getAdapter(OutlineViewerCreator.class); 702 if (creator != null) 703 return creator.hasViewerFor(input); 704 return false; 705 } 706 707 private boolean hasUnusableContentViewer() { 708 return fContentInputPane.isEmpty() || fContentInputPane.getViewer() instanceof BinaryCompareViewer; 709 } 710 711 private boolean isCustomStructureInputPane() { 712 return !(fStructureInputPane instanceof CompareViewerSwitchingPane); 713 } 714 715 private void feed1(final ISelection selection) { 716 BusyIndicator.showWhile(fComposite.getDisplay(), 717 new Runnable () { 718 public void run() { 719 if (selection == null || selection.isEmpty()) { 720 Object input= fStructureInputPane.getInput(); 721 if (input != null) 722 internalSetContentPaneInput(input); 723 fStructurePane2.setInput(null); fStructurePane1.setInput(null); 725 } else { 726 Object input= getElement(selection); 727 internalSetContentPaneInput(input); 728 if (structureCompareOnSingleClick() || hasUnusableContentViewer()) 729 fStructurePane1.setInput(input); 730 fStructurePane2.setInput(null); if (fStructurePane1.getInput() != input) 732 fStructurePane1.setInput(null); 733 } 734 } 735 } 736 ); 737 } 738 739 private void feedDefault1(final ISelection selection) { 740 BusyIndicator.showWhile(fComposite.getDisplay(), 741 new Runnable () { 742 public void run() { 743 if (!selection.isEmpty()) 744 fStructurePane1.setInput(getElement(selection)); 745 } 746 } 747 ); 748 } 749 750 private void feed2(final ISelection selection) { 751 BusyIndicator.showWhile(fComposite.getDisplay(), 752 new Runnable () { 753 public void run() { 754 if (selection.isEmpty()) { 755 Object input= fStructurePane1.getInput(); 756 internalSetContentPaneInput(input); 757 fStructurePane2.setInput(null); 758 } else { 759 Object input= getElement(selection); 760 internalSetContentPaneInput(input); 761 fStructurePane2.setInput(input); 762 } 763 } 764 } 765 ); 766 } 767 768 private void feed3(final ISelection selection) { 769 BusyIndicator.showWhile(fComposite.getDisplay(), 770 new Runnable () { 771 public void run() { 772 if (selection.isEmpty()) 773 internalSetContentPaneInput(fStructurePane2.getInput()); 774 else 775 internalSetContentPaneInput(getElement(selection)); 776 } 777 } 778 ); 779 780 } 781 782 private void internalSetContentPaneInput(Object input) { 783 Object oldInput = fContentInputPane.getInput(); 784 fContentInputPane.setInput(input); 785 if (fOutlineView != null) 786 fOutlineView.fireInputChange(oldInput, input); 787 } 788 789 797 private static Object getElement(ISelection selection) { 798 if (selection instanceof IStructuredSelection) { 799 IStructuredSelection ss= (IStructuredSelection) selection; 800 if (ss.size() == 1) 801 return ss.getFirstElement(); 802 } 803 return null; 804 } 805 806 814 public void setFocus() { 815 if (fFocusPane != null) { 816 fFocusPane.setFocus(); 817 } else if (fComposite != null) 818 fComposite.setFocus(); 819 } 820 821 831 public Viewer createDiffViewer(Composite parent) { 832 return new DiffTreeViewer(parent, fCompareConfiguration); 833 } 834 835 851 public Viewer findStructureViewer(Viewer oldViewer, ICompareInput input, Composite parent) { 852 return CompareUI.findStructureViewer(oldViewer, input, parent, fCompareConfiguration); 853 } 854 855 871 public Viewer findContentViewer(Viewer oldViewer, ICompareInput input, Composite parent) { 872 873 Viewer newViewer= CompareUI.findContentViewer(oldViewer, input, parent, fCompareConfiguration); 874 875 boolean isNewViewer= newViewer != oldViewer; 876 if (DEBUG) System.out.println("CompareEditorInput.findContentViewer: " + isNewViewer); 878 if (isNewViewer && newViewer instanceof IPropertyChangeNotifier) { 879 final IPropertyChangeNotifier dsp= (IPropertyChangeNotifier) newViewer; 880 dsp.addPropertyChangeListener(fDirtyStateListener); 881 882 Control c= newViewer.getControl(); 883 c.addDisposeListener( 884 new DisposeListener() { 885 public void widgetDisposed(DisposeEvent e) { 886 dsp.removePropertyChangeListener(fDirtyStateListener); 887 } 888 } 889 ); 890 } 891 892 return newViewer; 893 } 894 895 906 public boolean isSaveNeeded() { 907 return fDirty || fDirtyViewers.size() > 0; 908 } 909 910 919 public boolean isDirty() { 920 return isSaveNeeded(); 921 } 922 923 929 public void setDirty(boolean dirty) { 930 boolean oldDirty = fDirty || fDirtyViewers.size() > 0; 931 fDirty= dirty; 932 if (!fDirty) 933 fDirtyViewers.clear(); 934 if (oldDirty != dirty) 935 Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, new Boolean (oldDirty), new Boolean (dirty)); 936 } 937 938 private void setDirty(Object source, boolean dirty) { 939 Assert.isNotNull(source); 940 boolean oldDirty= fDirty || fDirtyViewers.size() > 0; 941 if (dirty) 942 fDirtyViewers.add(source); 943 else 944 fDirtyViewers.remove(source); 945 boolean newDirty= fDirty || fDirtyViewers.size() > 0; 946 if (DEBUG) System.out.println("setDirty("+source+", "+dirty+"): " + newDirty); if (oldDirty != newDirty) 948 Utilities.firePropertyChange(fListenerList, this, DIRTY_STATE, new Boolean (oldDirty), new Boolean (newDirty)); 949 } 950 951 954 public void addPropertyChangeListener(IPropertyChangeListener listener) { 955 if (listener != null) 956 fListenerList.add(listener); 957 } 958 959 962 public void removePropertyChangeListener(IPropertyChangeListener listener) { 963 if (listener != null) 964 fListenerList.remove(listener); 965 } 966 967 975 public void save(IProgressMonitor pm) { 976 } 978 979 989 public void saveChanges(IProgressMonitor monitor) throws CoreException { 990 991 flushViewers(monitor); 992 993 save(monitor); 994 } 995 996 1001 protected void flushViewers(IProgressMonitor monitor) { 1002 flushViewer(fStructureInputPane, monitor); 1004 flushViewer(fStructurePane1, monitor); 1005 flushViewer(fStructurePane2, monitor); 1006 flushViewer(fContentInputPane, monitor); 1007 } 1008 1009 private static void flushViewer(CompareViewerPane pane, IProgressMonitor pm) { 1010 if (pane != null) { 1011 IFlushable flushable = (IFlushable)Utilities.getAdapter(pane, IFlushable.class); 1012 if (flushable != null) 1013 flushable.flush(pm); 1014 } 1015 } 1016 1017 1020 public void addCompareInputChangeListener(ICompareInput input, 1021 ICompareInputChangeListener listener) { 1022 if (fContainer == null) { 1023 input.addCompareInputChangeListener(listener); 1024 } else { 1025 fContainer.addCompareInputChangeListener(input, listener); 1026 } 1027 } 1028 1029 1032 public void removeCompareInputChangeListener(ICompareInput input, 1033 ICompareInputChangeListener listener) { 1034 if (fContainer == null) { 1035 input.removeCompareInputChangeListener(listener); 1036 } else { 1037 fContainer.removeCompareInputChangeListener(input, listener); 1038 } 1039 } 1040 1041 1044 public void registerContextMenu(MenuManager menu, ISelectionProvider selectionProvider) { 1045 if (fContainer != null) 1046 fContainer.registerContextMenu(menu, selectionProvider); 1047 } 1048 1049 1052 public void setStatusMessage(String message) { 1053 if (!fContainerProvided) { 1054 IActionBars actionBars= getActionBars(); 1056 if (actionBars != null) { 1057 IStatusLineManager slm= actionBars.getStatusLineManager(); 1058 if (slm != null) { 1059 slm.setMessage(message); 1060 } 1061 } 1062 } else if (fContainer != null) { 1063 fContainer.setStatusMessage(message); 1064 } 1065 } 1066 1067 1070 public IActionBars getActionBars() { 1071 IActionBars actionBars = fContainer.getActionBars(); 1072 if (actionBars == null && !fContainerProvided) { 1073 return Utilities.findActionBars(fComposite); 1075 } 1076 return actionBars; 1077 } 1078 1079 1082 public IServiceLocator getServiceLocator() { 1083 IServiceLocator serviceLocator = fContainer.getServiceLocator(); 1084 if (serviceLocator == null && !fContainerProvided) { 1085 return Utilities.findSite(fComposite); 1087 } 1088 return serviceLocator; 1089 } 1090 1091 1094 public IWorkbenchPart getWorkbenchPart() { 1095 if (fContainer != null) 1096 return fContainer.getWorkbenchPart(); 1097 return null; 1098 } 1099 1100 1103 public void run(boolean fork, boolean cancelable, 1104 IRunnableWithProgress runnable) throws InvocationTargetException , 1105 InterruptedException { 1106 if (fContainer != null) 1107 fContainer.run(fork, cancelable, runnable); 1108 } 1109 1110 public void runAsynchronously(IRunnableWithProgress runnable) { 1111 if (fContainer != null) 1112 fContainer.runAsynchronously(runnable); 1113 } 1114 1115 1120 public void setContainer(ICompareContainer container) { 1121 Assert.isNotNull(container); 1122 this.fContainer = container; 1123 fContainerProvided = true; 1124 } 1125 1126 1132 public final ICompareContainer getContainer() { 1133 return fContainer; 1134 } 1135 1136 1142 protected void firePropertyChange(PropertyChangeEvent event) { 1143 Utilities.firePropertyChange(fListenerList, event); 1144 } 1145 1146 1156 public boolean canRunAsJob() { 1157 return false; 1158 } 1159 1160 1169 public boolean belongsTo(Object family) { 1170 return family == this; 1171 } 1172 1173 1185 public boolean isEditionSelectionDialog() { 1186 return false; 1187 } 1188 1189 1199 public String getOKButtonLabel() { 1200 if (isEditable()) 1201 return CompareMessages.CompareDialog_commit_button; 1202 if (isEditionSelectionDialog()) 1203 return CompareMessages.CompareEditorInput_0; 1204 return IDialogConstants.OK_LABEL; 1205 } 1206 1207 1214 public String getCancelButtonLabel() { 1215 return IDialogConstants.CANCEL_LABEL; 1216 } 1217 1218 private boolean isEditable() { 1219 return getCompareConfiguration().isLeftEditable() 1220 || getCompareConfiguration().isRightEditable(); 1221 } 1222 1223 1233 public boolean okPressed() { 1234 if (isEditable()) { 1235 if (!saveChanges()) 1236 return false; 1237 } 1238 return true; 1239 } 1240 1241 1246 public void cancelPressed() { 1247 } 1249 1250 private boolean saveChanges() { 1251 try { 1252 PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() { 1253 public void run(IProgressMonitor monitor) throws InvocationTargetException , InterruptedException { 1254 try { 1255 saveChanges(monitor); 1256 } catch (CoreException e) { 1257 throw new InvocationTargetException (e); 1258 } 1259 } 1260 1261 }); 1262 return true; 1263 } catch (InterruptedException x) { 1264 } catch (OperationCanceledException x) { 1266 } catch (InvocationTargetException x) { 1268 ErrorDialog.openError(fComposite.getShell(), CompareMessages.CompareDialog_error_title, null, 1269 new Status(IStatus.ERROR, CompareUIPlugin.PLUGIN_ID, 0, 1270 NLS.bind(CompareMessages.CompareDialog_error_message, x.getTargetException().getMessage()), x.getTargetException())); 1271 } 1272 return false; 1273 } 1274 1275 1282 public Object getSelectedEdition() { 1283 if (fStructureInputPane != null) { 1284 ISelection selection = fStructureInputPane.getSelection(); 1285 if (selection instanceof IStructuredSelection) { 1286 IStructuredSelection ss = (IStructuredSelection) selection; 1287 if (!ss.isEmpty()) 1288 return ss.getFirstElement(); 1289 1290 } 1291 } 1292 return null; 1293 } 1294 1295 1300 public void setHelpContextId(String helpContextId) { 1301 this.fHelpContextId = helpContextId; 1302 } 1303 1304} 1305 1306 | Popular Tags |