1 11 12 package org.eclipse.ui.views.contentoutline; 13 14 import org.eclipse.jface.viewers.ISelection; 15 import org.eclipse.jface.viewers.ISelectionChangedListener; 16 import org.eclipse.jface.viewers.ISelectionProvider; 17 import org.eclipse.jface.viewers.SelectionChangedEvent; 18 import org.eclipse.swt.widgets.Composite; 19 import org.eclipse.ui.IEditorPart; 20 import org.eclipse.ui.IWorkbenchPage; 21 import org.eclipse.ui.IWorkbenchPart; 22 import org.eclipse.ui.PlatformUI; 23 import org.eclipse.ui.internal.views.ViewsPlugin; 24 import org.eclipse.ui.internal.views.contentoutline.ContentOutlineMessages; 25 import org.eclipse.ui.part.IContributedContentsView; 26 import org.eclipse.ui.part.IPage; 27 import org.eclipse.ui.part.IPageBookViewPage; 28 import org.eclipse.ui.part.IPageSite; 29 import org.eclipse.ui.part.MessagePage; 30 import org.eclipse.ui.part.PageBook; 31 import org.eclipse.ui.part.PageBookView; 32 33 67 public class ContentOutline extends PageBookView implements ISelectionProvider, 68 ISelectionChangedListener { 69 70 71 72 75 public static final String PREFIX = PlatformUI.PLUGIN_ID + "."; 77 81 public static final String CONTENT_OUTLINE_VIEW_HELP_CONTEXT_ID = PREFIX 82 + "content_outline_context"; 84 87 private String defaultText =ContentOutlineMessages.ContentOutline_noOutline; 88 89 92 public ContentOutline() { 93 super(); 94 } 95 96 99 public void addSelectionChangedListener(ISelectionChangedListener listener) { 100 getSelectionProvider().addSelectionChangedListener(listener); 101 } 102 103 106 protected IPage createDefaultPage(PageBook book) { 107 MessagePage page = new MessagePage(); 108 initPage(page); 109 page.createControl(book); 110 page.setMessage(defaultText); 111 return page; 112 } 113 114 118 public void createPartControl(Composite parent) { 119 super.createPartControl(parent); 120 PlatformUI.getWorkbench().getHelpSystem().setHelp(getPageBook(), 121 CONTENT_OUTLINE_VIEW_HELP_CONTEXT_ID); 122 } 123 124 127 protected PageRec doCreatePage(IWorkbenchPart part) { 128 Object obj = ViewsPlugin.getAdapter(part, IContentOutlinePage.class, false); 130 if (obj instanceof IContentOutlinePage) { 131 IContentOutlinePage page = (IContentOutlinePage) obj; 132 if (page instanceof IPageBookViewPage) { 133 initPage((IPageBookViewPage) page); 134 } 135 page.createControl(getPageBook()); 136 return new PageRec(part, page); 137 } 138 return null; 140 } 141 142 145 protected void doDestroyPage(IWorkbenchPart part, PageRec rec) { 146 IContentOutlinePage page = (IContentOutlinePage) rec.page; 147 page.dispose(); 148 rec.dispose(); 149 } 150 151 154 public Object getAdapter(Class key) { 155 if (key == IContributedContentsView.class) { 156 return new IContributedContentsView() { 157 public IWorkbenchPart getContributingPart() { 158 return getContributingEditor(); 159 } 160 }; 161 } 162 return super.getAdapter(key); 163 } 164 165 168 protected IWorkbenchPart getBootstrapPart() { 169 IWorkbenchPage page = getSite().getPage(); 170 if (page != null) { 171 return page.getActiveEditor(); 172 } 173 174 return null; 175 } 176 177 184 private IWorkbenchPart getContributingEditor() { 185 return getCurrentContributingPart(); 186 } 187 188 191 public ISelection getSelection() { 192 return getSelectionProvider().getSelection(); 194 } 195 196 200 protected boolean isImportant(IWorkbenchPart part) { 201 return (part instanceof IEditorPart); 203 } 204 205 209 public void partBroughtToTop(IWorkbenchPart part) { 210 partActivated(part); 211 } 212 213 216 public void removeSelectionChangedListener( 217 ISelectionChangedListener listener) { 218 getSelectionProvider().removeSelectionChangedListener(listener); 219 } 220 221 224 public void selectionChanged(SelectionChangedEvent event) { 225 getSelectionProvider().selectionChanged(event); 226 } 227 228 231 public void setSelection(ISelection selection) { 232 getSelectionProvider().setSelection(selection); 233 } 234 235 241 protected void showPageRec(PageRec pageRec) { 242 IPageSite pageSite = getPageSite(pageRec.page); 243 ISelectionProvider provider = pageSite.getSelectionProvider(); 244 if (provider == null && (pageRec.page instanceof IContentOutlinePage)) { 245 pageSite.setSelectionProvider((IContentOutlinePage) pageRec.page); 248 } 249 super.showPageRec(pageRec); 250 } 251 } 252 | Popular Tags |