1 11 package org.eclipse.pde.internal.ui.editor; 12 import java.io.File ; 13 import java.io.IOException ; 14 import java.io.PrintWriter ; 15 import java.io.StringWriter ; 16 import java.util.ArrayList ; 17 18 import org.eclipse.core.filesystem.EFS; 19 import org.eclipse.core.filesystem.IFileStore; 20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.core.resources.IMarker; 22 import org.eclipse.core.resources.IProject; 23 import org.eclipse.core.resources.IResource; 24 import org.eclipse.core.runtime.CoreException; 25 import org.eclipse.core.runtime.IProgressMonitor; 26 import org.eclipse.core.runtime.NullProgressMonitor; 27 import org.eclipse.jface.action.IAction; 28 import org.eclipse.jface.action.IMenuListener; 29 import org.eclipse.jface.action.IMenuManager; 30 import org.eclipse.jface.action.IStatusLineManager; 31 import org.eclipse.jface.action.MenuManager; 32 import org.eclipse.jface.dialogs.IDialogSettings; 33 import org.eclipse.jface.text.IDocument; 34 import org.eclipse.jface.text.ITextSelection; 35 import org.eclipse.jface.text.source.IAnnotationModel; 36 import org.eclipse.jface.viewers.IPostSelectionProvider; 37 import org.eclipse.jface.viewers.ISelection; 38 import org.eclipse.jface.viewers.ISelectionChangedListener; 39 import org.eclipse.jface.viewers.ISelectionProvider; 40 import org.eclipse.jface.viewers.IStructuredSelection; 41 import org.eclipse.jface.viewers.SelectionChangedEvent; 42 import org.eclipse.pde.core.IBaseModel; 43 import org.eclipse.pde.core.IWritable; 44 import org.eclipse.pde.internal.core.IWorkspaceModel; 45 import org.eclipse.pde.internal.core.plugin.IWritableDelimiter; 46 import org.eclipse.pde.internal.core.util.XMLComponentRegistry; 47 import org.eclipse.pde.internal.ui.IPDEUIConstants; 48 import org.eclipse.pde.internal.ui.PDEPlugin; 49 import org.eclipse.pde.internal.ui.PDEUIMessages; 50 import org.eclipse.pde.internal.ui.editor.context.IInputContextListener; 51 import org.eclipse.pde.internal.ui.editor.context.InputContext; 52 import org.eclipse.pde.internal.ui.editor.context.InputContextManager; 53 import org.eclipse.pde.internal.ui.editor.plugin.MissingResourcePage; 54 import org.eclipse.pde.internal.ui.editor.plugin.OverviewPage; 55 import org.eclipse.pde.internal.ui.util.PDEModelUtility; 56 import org.eclipse.search.ui.text.ISearchEditorAccess; 57 import org.eclipse.search.ui.text.Match; 58 import org.eclipse.swt.dnd.Clipboard; 59 import org.eclipse.swt.dnd.TextTransfer; 60 import org.eclipse.swt.dnd.Transfer; 61 import org.eclipse.swt.widgets.Display; 62 import org.eclipse.swt.widgets.Menu; 63 import org.eclipse.ui.IEditorActionBarContributor; 64 import org.eclipse.ui.IEditorInput; 65 import org.eclipse.ui.IEditorPart; 66 import org.eclipse.ui.IEditorSite; 67 import org.eclipse.ui.IFileEditorInput; 68 import org.eclipse.ui.IStorageEditorInput; 69 import org.eclipse.ui.IURIEditorInput; 70 import org.eclipse.ui.IWorkbenchPart; 71 import org.eclipse.ui.PartInitException; 72 import org.eclipse.ui.actions.ActionFactory; 73 import org.eclipse.ui.forms.editor.FormEditor; 74 import org.eclipse.ui.forms.editor.IFormPage; 75 import org.eclipse.ui.forms.widgets.FormToolkit; 76 import org.eclipse.ui.ide.IDE; 77 import org.eclipse.ui.ide.IGotoMarker; 78 import org.eclipse.ui.part.MultiPageEditorPart; 79 import org.eclipse.ui.part.MultiPageEditorSite; 80 import org.eclipse.ui.views.contentoutline.IContentOutlinePage; 81 82 87 public abstract class PDEFormEditor extends FormEditor 88 implements 89 IInputContextListener, 90 IGotoMarker, ISearchEditorAccess { 91 96 public class PDEFormEditorChangeListener implements 97 ISelectionChangedListener { 98 99 107 public void install(ISelectionProvider selectionProvider) { 108 if (selectionProvider == null) { 109 return; 110 } 111 112 if (selectionProvider instanceof IPostSelectionProvider) { 113 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; 114 provider.addPostSelectionChangedListener(this); 115 } else { 116 selectionProvider.addSelectionChangedListener(this); 117 } 118 } 119 120 123 public void selectionChanged(SelectionChangedEvent event) { 124 if (PDEPlugin.getDefault().getPreferenceStore().getBoolean( 125 "ToggleLinkWithEditorAction.isChecked")) if (getFormOutline() != null) { 127 getFormOutline().setSelection(event.getSelection()); 128 } 129 } 130 131 137 public void uninstall(ISelectionProvider selectionProvider) { 138 if (selectionProvider == null) { 139 return; 140 } 141 142 if (selectionProvider instanceof IPostSelectionProvider) { 143 IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; 144 provider.removePostSelectionChangedListener(this); 145 } else { 146 selectionProvider.removeSelectionChangedListener(this); 147 } 148 } 149 150 } 151 152 private static final String F_DIALOG_EDITOR_SECTION_KEY = "pde-form-editor"; 154 159 private PDEFormEditorChangeListener fEditorSelectionChangedListener; 160 private Clipboard clipboard; 161 private Menu fContextMenu; 162 protected InputContextManager fInputContextManager; 163 private ISortableContentOutlinePage fFormOutline; 164 private PDEMultiPageContentOutline fContentOutline; 165 private String fLastActivePageId; 166 private boolean fLastDirtyState; 167 private boolean fError; 168 169 private static class PDEMultiPageEditorSite extends MultiPageEditorSite { 170 public PDEMultiPageEditorSite(MultiPageEditorPart multiPageEditor, 171 IEditorPart editor) { 172 super(multiPageEditor, editor); 173 } 174 public IEditorActionBarContributor getActionBarContributor() { 175 PDEFormEditor editor = (PDEFormEditor) getMultiPageEditor(); 176 PDEFormEditorContributor contributor = editor.getContributor(); 177 return contributor.getSourceContributor(); 178 } 179 180 public IWorkbenchPart getPart() { 181 return getMultiPageEditor(); 182 } 183 } 184 185 public PDEFormEditor() { 186 PDEPlugin.getDefault().getLabelProvider().connect(this); 187 XMLComponentRegistry.Instance().connect(this); 188 fInputContextManager = createInputContextManager(); 189 } 190 191 195 protected IEditorSite createSite(IEditorPart editor) { 196 return new PDEMultiPageEditorSite(this, editor); 197 } 198 public IProject getCommonProject() { 199 return fInputContextManager.getCommonProject(); 200 } 201 public IBaseModel getAggregateModel() { 202 if (fInputContextManager != null) 203 return fInputContextManager.getAggregateModel(); 204 return null; 205 } 206 protected abstract InputContextManager createInputContextManager(); 207 215 public boolean hasInputContext(String contextId) { 216 return fInputContextManager.hasContext(contextId); 217 } 218 public InputContextManager getContextManager() { 219 return fInputContextManager; 220 } 221 protected void createInputContexts(InputContextManager contextManager) { 222 IEditorInput input = getEditorInput(); 223 if (input instanceof IFileEditorInput) { 224 createResourceContexts(contextManager, (IFileEditorInput) input); 226 } else if (input instanceof SystemFileEditorInput) { 227 createSystemFileContexts(contextManager, 229 (SystemFileEditorInput) input); 230 } else if (input instanceof IStorageEditorInput) { 231 createStorageContexts(contextManager, (IStorageEditorInput) input); 232 } else if (input instanceof IURIEditorInput) { 233 IURIEditorInput uriEditorInput= (IURIEditorInput) input; 234 try { 235 IFileStore store= EFS.getStore(uriEditorInput.getURI()); 236 if (!EFS.SCHEME_FILE.equals(store.getFileSystem().getScheme())) 237 return; 238 } catch (CoreException e) { 239 return; 240 } 241 File file = new File (uriEditorInput.getURI()); 242 SystemFileEditorInput sinput = new SystemFileEditorInput(file); 243 createSystemFileContexts(contextManager, sinput); 244 } 245 } 246 protected abstract void createResourceContexts( 247 InputContextManager contexts, IFileEditorInput input); 248 protected abstract void createSystemFileContexts( 249 InputContextManager contexts, SystemFileEditorInput input); 250 protected abstract void createStorageContexts(InputContextManager contexts, 251 IStorageEditorInput input); 252 257 protected FormToolkit createToolkit(Display display) { 258 return new FormToolkit(PDEPlugin.getDefault().getFormColors(display)); 260 } 261 264 protected void createPages() { 265 clipboard = new Clipboard(getContainer().getDisplay()); 266 MenuManager manager = new MenuManager(); 267 IMenuListener listener = new IMenuListener() { 268 public void menuAboutToShow(IMenuManager manager) { 269 contextMenuAboutToShow(manager); 270 } 271 }; 272 manager.setRemoveAllWhenShown(true); 273 manager.addMenuListener(listener); 274 fContextMenu = manager.createContextMenu(getContainer()); 275 getContainer().setMenu(fContextMenu); 276 createInputContexts(fInputContextManager); 277 super.createPages(); 278 fInputContextManager.addInputContextListener(this); 279 String pageToShow = computeInitialPageId(); 280 if (pageToShow != null) 281 setActivePage(pageToShow); 282 updateTitle(); 283 PDEModelUtility.connect(this); 284 } 285 286 289 protected void pageChange(int newPageIndex) { 290 super.pageChange(newPageIndex); 291 IFormPage page = getActivePageInstance(); 292 updateContentOutline(page); 293 if (page != null) { 294 fLastActivePageId = page.getId(); 295 } 296 } 297 298 301 public void setFocus() { 302 super.setFocus(); 303 IFormPage page = getActivePageInstance(); 304 if ((page != null) && 307 (page instanceof PDEFormPage)) { 308 ((PDEFormPage)page).updateFormSelection(); 309 } 310 } 311 312 public Clipboard getClipboard() { 313 return clipboard; 314 } 315 protected void contextMenuAboutToShow(IMenuManager manager) { 316 PDEFormEditorContributor contributor = getContributor(); 317 IFormPage page = getActivePageInstance(); 318 if (page instanceof PDEFormPage) 319 ((PDEFormPage) page).contextMenuAboutToShow(manager); 320 if (contributor != null) 321 contributor.contextMenuAboutToShow(manager); 322 } 323 324 public PDEFormEditorContributor getContributor() { 325 return (PDEFormEditorContributor) getEditorSite().getActionBarContributor(); 326 } 327 328 protected String computeInitialPageId() { 329 String firstPageId = null; 330 String storedFirstPageId = loadDefaultPage(); 331 if (storedFirstPageId != null) 332 firstPageId = storedFirstPageId; 333 String invalidContextId = getFirstInvalidContextId(); 336 if (invalidContextId != null) 337 return invalidContextId; 338 return firstPageId; 339 } 340 341 private String getFirstInvalidContextId() { 342 InputContext[] invalidContexts = fInputContextManager 343 .getInvalidContexts(); 344 if (invalidContexts.length == 0) 345 return null; 346 for (int i = 0; i < invalidContexts.length; i++) { 348 if (invalidContexts[i].isPrimary()) 349 return invalidContexts[i].getId(); 350 } 351 return invalidContexts[0].getId(); 353 } 354 355 public String getTitle() { 356 if (fInputContextManager == null) 357 return super.getTitle(); 358 InputContext context = fInputContextManager.getPrimaryContext(); 359 if (context == null) 360 return super.getTitle(); 361 return context.getInput().getName(); 362 } 363 364 public void updateTitle() { 365 firePropertyChange(IWorkbenchPart.PROP_TITLE); 366 } 367 368 public String getTitleProperty() { 369 return ""; } 371 372 377 public void doSave(IProgressMonitor monitor) { 378 commitPages(true); 379 fInputContextManager.save(monitor); 380 editorDirtyStateChanged(); 381 } 382 383 386 public void doRevert() { 387 IFormPage formPage = getActivePageInstance(); 388 if ((formPage != null) && 391 (formPage instanceof PDEFormPage)) { 392 formPage.getManagedForm().commit(true); 393 } 394 boolean reverted = doRevertSourcePages(); 398 if (reverted == false) { 403 reverted = doRevertFormPage(); 404 } 405 if (reverted) { 408 editorDirtyStateChanged(); 409 } 410 } 411 412 415 private boolean doRevertFormPage() { 416 boolean reverted = false; 417 IBaseModel model = getAggregateModel(); 418 if (model instanceof IWorkspaceModel) { 419 IWorkspaceModel workspaceModel = (IWorkspaceModel)model; 420 workspaceModel.reload(); 421 reverted = true; 422 } 423 return reverted; 424 } 425 426 429 private boolean doRevertSourcePages() { 430 boolean reverted = false; 431 IFormPage[] pages = getPages(); 432 for (int i = 0; i < pages.length; i++) { 433 if (pages[i] instanceof PDESourcePage) { 434 PDESourcePage sourcePage = (PDESourcePage)pages[i]; 435 sourcePage.getInputContext().flushEditorInput(); 443 sourcePage.doRevertToSaved(); 445 reverted = true; 446 } 447 } 448 return reverted; 449 } 450 451 public void doRevert(IEditorInput input) { 452 IFormPage currentPage = getActivePageInstance(); 453 if (currentPage != null && currentPage instanceof PDEFormPage) 454 ((PDEFormPage) currentPage).cancelEdit(); 455 InputContext context = fInputContextManager.getContext(input); 456 IFormPage page = findPage(context.getId()); 457 if (page!=null && page instanceof PDESourcePage) { 458 PDESourcePage spage = (PDESourcePage) page; 459 spage.doRevertToSaved(); 460 } 461 editorDirtyStateChanged(); 462 } 463 464 467 public String getContextIDForSaveAs() { 468 return null; 471 } 472 473 478 public void doSaveAs() { 479 try { 480 String contextID = getContextIDForSaveAs(); 483 getContextManager().saveAs(getProgressMonitor(), 485 contextID); 486 IEditorInput input = 488 getContextManager().findContext( 489 contextID).getInput(); 490 setInputWithNotify(input); 492 setPartName(input.getName()); 495 firePropertyChange(PROP_DIRTY); 497 } catch (InterruptedException e) { 498 } catch (Exception e) { 500 String title = PDEUIMessages.PDEFormEditor_errorTitleProblemSaveAs; 501 String message = PDEUIMessages.PDEFormEditor_errorMessageSaveNotCompleted; 502 if (e.getMessage() != null) { 503 message = message + ' ' + e.getMessage(); 504 } 505 PDEPlugin.logException(e, title, message); 506 } 507 } 508 509 514 public boolean isSaveAsAllowed() { 515 return false; 516 } 517 518 521 private void storeDefaultPage() { 522 IEditorInput input = getEditorInput(); 523 String pageId = fLastActivePageId; 524 if (pageId == null) 525 return; 526 if (input instanceof IFileEditorInput) { 527 setPropertyEditorPageKey((IFileEditorInput)input, pageId); 530 } else if (input instanceof IStorageEditorInput) { 531 setDialogEditorPageKey(pageId); 534 } 535 } 536 537 540 protected void setDialogEditorPageKey(String pageID) { 541 IDialogSettings section = getSettingsSection(); 547 section.put(getEditorID(), pageID); 548 } 549 550 553 protected String getDialogEditorPageKey() { 554 IDialogSettings section = getSettingsSection(); 560 return section.get(getEditorID()); 561 } 562 563 566 protected abstract String getEditorID(); 567 568 572 protected void setPropertyEditorPageKey(IFileEditorInput input, String pageId) { 573 IFile file = input.getFile(); 576 try { 577 file.setPersistentProperty( 579 IPDEUIConstants.PROPERTY_EDITOR_PAGE_KEY, 580 pageId); 581 } catch (CoreException e) { 582 } 584 } 585 586 589 private String loadDefaultPage() { 590 IEditorInput input = getEditorInput(); 591 if (input instanceof IFileEditorInput) { 592 return getPropertyEditorPageKey((IFileEditorInput)input); 595 } else if (input instanceof IStorageEditorInput) { 596 return getDialogEditorPageKey(); 599 } 600 return null; 601 } 602 603 607 protected String getPropertyEditorPageKey(IFileEditorInput input) { 608 IFile file = input.getFile(); 611 try { 613 return file.getPersistentProperty( 614 IPDEUIConstants.PROPERTY_EDITOR_PAGE_KEY); 615 } catch (CoreException e) { 616 return null; 617 } 618 } 619 620 public void dispose() { 621 storeDefaultPage(); 622 if (fEditorSelectionChangedListener != null) { 623 fEditorSelectionChangedListener.uninstall(getSite().getSelectionProvider()); 624 fEditorSelectionChangedListener= null; 625 } 626 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 628 XMLComponentRegistry.Instance().disconnect(this); 629 PDEModelUtility.disconnect(this); 630 if (clipboard != null) { 631 clipboard.dispose(); 632 clipboard = null; 633 } 634 super.dispose(); 635 fInputContextManager.dispose(); 636 fInputContextManager = null; 637 } 638 public boolean isDirty() { 639 fLastDirtyState = computeDirtyState(); 640 return fLastDirtyState; 641 } 642 643 private boolean computeDirtyState() { 644 IFormPage page = getActivePageInstance(); 645 if ((page != null && page.isDirty()) 646 || (fInputContextManager != null && fInputContextManager.isDirty())) 647 return true; 648 return super.isDirty(); 649 } 650 651 public boolean getLastDirtyState() { 652 return fLastDirtyState; 653 } 654 655 public void fireSaveNeeded(String contextId, boolean notify) { 656 if (contextId == null) 657 return; 658 InputContext context = fInputContextManager.findContext(contextId); 659 if (context != null) 660 fireSaveNeeded(context.getInput(), notify); 661 } 662 public void fireSaveNeeded(IEditorInput input, boolean notify) { 663 if (notify) 664 editorDirtyStateChanged(); 665 if (isDirty()) 666 validateEdit(input); 667 } 668 public void editorDirtyStateChanged() { 669 super.editorDirtyStateChanged(); 670 PDEFormEditorContributor contributor = getContributor(); 671 if (contributor != null) 672 contributor.updateActions(); 673 } 674 private void validateEdit(IEditorInput input) { 675 final InputContext context = fInputContextManager.getContext(input); 676 if (!context.validateEdit()) { 677 getSite().getShell().getDisplay().asyncExec(new Runnable () { 678 public void run() { 679 doRevert(context.getInput()); 680 context.setValidated(false); 681 } 682 }); 683 } 684 } 685 686 689 private IDialogSettings getSettingsSection() { 690 IDialogSettings root = PDEPlugin.getDefault().getDialogSettings(); 694 IDialogSettings section = root.getSection(F_DIALOG_EDITOR_SECTION_KEY); 696 if (section == null) { 698 section = root.addNewSection(F_DIALOG_EDITOR_SECTION_KEY); 699 } 700 return section; 701 } 702 703 public void gotoMarker(IMarker marker) { 704 IResource resource = marker.getResource(); 705 InputContext context = fInputContextManager.findContext(resource); 706 if (context == null) 707 return; 708 IFormPage page = getActivePageInstance(); 709 if (!context.getId().equals(page.getId())) 710 page = setActivePage(context.getId()); 711 IDE.gotoMarker(page, marker); 712 } 713 714 public void openToSourcePage(Object object, int offset, int length) { 715 InputContext context = getInputContext(object); 716 if (context != null) { 717 PDESourcePage page = (PDESourcePage)setActivePage(context.getId()); 718 if (page != null) 719 page.selectAndReveal(offset, length); 720 } 721 } 722 723 public void setSelection(ISelection selection) { 724 getSite().getSelectionProvider().setSelection(selection); 725 getContributor().updateSelectableActions(selection); 726 } 727 public ISelection getSelection() { 728 return getSite().getSelectionProvider().getSelection(); 729 } 730 public Object getAdapter(Class key) { 731 if (key.equals(IContentOutlinePage.class)) { 732 return getContentOutline(); 733 } 734 if (key.equals(IGotoMarker.class)) { 735 return this; 736 } 737 if (key.equals(ISearchEditorAccess.class)) { 738 return this; 739 } 740 return super.getAdapter(key); 741 } 742 public Menu getContextMenu() { 743 return fContextMenu; 744 } 745 public PDEMultiPageContentOutline getContentOutline() { 746 if (fContentOutline == null || fContentOutline.isDisposed()) { 747 fContentOutline = new PDEMultiPageContentOutline(this); 748 updateContentOutline(getActivePageInstance()); 749 } 750 return fContentOutline; 751 } 752 753 757 protected ISortableContentOutlinePage getFormOutline() { 758 if (fFormOutline == null) { 759 fFormOutline = createContentOutline(); 760 if (fFormOutline != null) { 761 fEditorSelectionChangedListener = new PDEFormEditorChangeListener(); 762 fEditorSelectionChangedListener.install(getSite() 763 .getSelectionProvider()); 764 } 765 } 766 return fFormOutline; 767 } 768 abstract protected ISortableContentOutlinePage createContentOutline(); 769 770 private void updateContentOutline(IFormPage page) { 771 if (fContentOutline == null) 772 return; 773 ISortableContentOutlinePage outline = null; 774 if (page instanceof PDESourcePage) { 775 outline = ((PDESourcePage) page).getContentOutline(); 776 } else { 777 outline = getFormOutline(); 778 if (outline != null && outline instanceof FormOutlinePage) 779 ((FormOutlinePage) outline).refresh(); 780 } 781 fContentOutline.setPageActive(outline); 782 } 783 784 787 public IFormPage setActivePage(String pageId) { 788 IFormPage page = super.setActivePage(pageId); 789 if (page != null) 790 updateContentOutline(page); 791 return page; 792 } 793 794 IFormPage[] getPages() { 795 ArrayList formPages = new ArrayList (); 796 for (int i = 0; i < pages.size(); i++) { 797 Object page = pages.get(i); 798 if (page instanceof IFormPage) 799 formPages.add(page); 800 } 801 return (IFormPage[]) formPages.toArray(new IFormPage[formPages.size()]); 802 } 803 protected void performGlobalAction(String id) { 804 ISelection selection = getSelection(); 806 boolean handled = ((PDEFormPage) getActivePageInstance()) 807 .performGlobalAction(id); 808 if (!handled) { 809 IFormPage page = getActivePageInstance(); 810 if (page instanceof PDEFormPage) { 811 if (id.equals(ActionFactory.UNDO.getId())) { 812 fInputContextManager.undo(); 813 return; 814 } 815 if (id.equals(ActionFactory.REDO.getId())) { 816 fInputContextManager.redo(); 817 return; 818 } 819 if (id.equals(ActionFactory.CUT.getId()) 820 || id.equals(ActionFactory.COPY.getId())) { 821 copyToClipboard(selection); 822 return; 823 } 824 } 825 } 826 } 827 828 831 private void copyToClipboard(ISelection selection) { 832 Object [] objects = null; 833 String textVersion = null; 834 if (selection instanceof IStructuredSelection) { 835 IStructuredSelection ssel = (IStructuredSelection) selection; 836 if (ssel == null || ssel.size() == 0) 837 return; 838 objects = ssel.toArray(); 839 StringWriter writer = new StringWriter (); 840 PrintWriter pwriter = new PrintWriter (writer); 841 Class objClass = null; 842 for (int i = 0; i < objects.length; i++) { 843 Object obj = objects[i]; 844 if (objClass == null) 845 objClass = obj.getClass(); 846 else if (objClass.equals(obj.getClass()) == false) 847 return; 848 if (obj instanceof IWritable) { 849 if ((i != 0) && 852 (obj instanceof IWritableDelimiter)) { 853 ((IWritableDelimiter)obj).writeDelimeter(pwriter); 854 } 855 ((IWritable) obj).write("", pwriter); } else if (obj instanceof String ) { 857 pwriter.println((String )obj); 859 } 860 } 861 pwriter.flush(); 862 textVersion = writer.toString(); 863 try { 864 pwriter.close(); 865 writer.close(); 866 } catch (IOException e) { 867 } 868 } else if (selection instanceof ITextSelection) { 869 textVersion = ((ITextSelection) selection).getText(); 870 } 871 if ((textVersion == null || textVersion.length() == 0) && objects == null) 872 return; 873 Object []o = null; 875 Transfer[] t = null; 876 if (objects == null ) { 877 o = new Object [] {textVersion}; 878 t = new Transfer[] {TextTransfer.getInstance()}; 879 } else if (textVersion == null || textVersion.length() == 0) { 880 o = new Object [] {objects}; 881 t = new Transfer[] {ModelDataTransfer.getInstance()}; 882 } else { 883 o = new Object [] {objects, textVersion}; 884 t = new Transfer[] {ModelDataTransfer.getInstance(), TextTransfer.getInstance()}; 885 } 886 clipboard.setContents(o, t); 887 } 888 public boolean canPasteFromClipboard() { 889 IFormPage page = getActivePageInstance(); 890 if (page instanceof PDEFormPage) { 891 return ((PDEFormPage) page).canPaste(getClipboard()); 892 } 893 return false; 894 } 895 public boolean canCopy(ISelection selection) { 896 if (selection == null) 897 return false; 898 if (selection instanceof IStructuredSelection) 899 return !selection.isEmpty(); 900 if (selection instanceof ITextSelection) { 901 ITextSelection textSelection = (ITextSelection) selection; 902 return textSelection.getLength() > 0; 903 } 904 return false; 905 } 906 void updateUndo(IAction undoAction, IAction redoAction) { 907 IModelUndoManager undoManager = fInputContextManager.getUndoManager(); 908 if (undoManager != null) 909 undoManager.setActions(undoAction, redoAction); 910 } 911 912 915 public void synchronizeOutlinePage() { 916 IFormPage page = getActivePageInstance(); 918 919 if (page instanceof PDESourcePage) { 920 ((PDESourcePage) page).synchronizeOutlinePage(); 922 } else { 923 if (getFormOutline() != null) { 927 getFormOutline().setSelection(getSelection()); 928 } 929 } 930 } 931 932 935 public IDocument getDocument(Match match) { 936 InputContext context = getInputContext(match.getElement()); 937 return context == null ? null : context.getDocumentProvider().getDocument(context.getInput()); 938 } 939 940 943 public IAnnotationModel getAnnotationModel(Match match) { 944 InputContext context = getInputContext(match.getElement()); 945 return context == null ? null : context.getDocumentProvider().getAnnotationModel(context.getInput()); 946 } 947 948 protected abstract InputContext getInputContext(Object object); 949 950 protected final void addPages() { 951 fError = getAggregateModel() == null; 952 if (fError) { 953 try { 954 addPage(new MissingResourcePage(this)); 955 } catch (PartInitException e) { 956 PDEPlugin.logException(e); 957 } 958 } else 959 addEditorPages(); 960 } 961 962 protected abstract void addEditorPages(); 963 964 public final void contextAdded(InputContext context) { 965 if (fError) { 966 removePage(0); 967 addPages(); 968 if (!fError) 969 setActivePage(OverviewPage.PAGE_ID); 970 } else 971 editorContextAdded(context); 972 } 973 974 public abstract void editorContextAdded(InputContext context); 975 976 979 protected IProgressMonitor getProgressMonitor() { 980 IProgressMonitor monitor = null; 981 IStatusLineManager manager = getStatusLineManager(); 982 if (manager != null) { 983 monitor = manager.getProgressMonitor(); 984 } 985 if (monitor == null) { 986 monitor = new NullProgressMonitor(); 987 } 988 return monitor; 989 } 990 991 994 protected IStatusLineManager getStatusLineManager() { 995 return getEditorSite().getActionBars().getStatusLineManager(); 996 } 997 998 } 999 | Popular Tags |