1 11 package org.eclipse.ui.views.properties; 12 13 import org.eclipse.jface.viewers.ISelection; 14 import org.eclipse.swt.widgets.Composite; 15 import org.eclipse.ui.ISaveablePart; 16 import org.eclipse.ui.ISelectionListener; 17 import org.eclipse.ui.IViewSite; 18 import org.eclipse.ui.IWorkbenchPage; 19 import org.eclipse.ui.IWorkbenchPart; 20 import org.eclipse.ui.PartInitException; 21 import org.eclipse.ui.internal.views.ViewsPlugin; 22 import org.eclipse.ui.part.IContributedContentsView; 23 import org.eclipse.ui.part.IPage; 24 import org.eclipse.ui.part.IPageBookViewPage; 25 import org.eclipse.ui.part.PageBook; 26 import org.eclipse.ui.part.PageBookView; 27 28 62 public class PropertySheet extends PageBookView implements ISelectionListener { 63 66 public static final String HELP_CONTEXT_PROPERTY_SHEET_VIEW = IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW; 67 68 71 private ISelection bootstrapSelection; 72 73 76 public PropertySheet() { 77 super(); 78 } 79 80 84 protected IPage createDefaultPage(PageBook book) { 85 PropertySheetPage page = new PropertySheetPage(); 86 initPage(page); 87 page.createControl(book); 88 return page; 89 } 90 91 95 public void createPartControl(Composite parent) { 96 super.createPartControl(parent); 97 getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem() 98 .setHelp(getPageBook(), 99 IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW); 100 } 101 102 105 public void dispose() { 106 super.dispose(); 108 109 getSite().getPage().removeSelectionListener(this); 111 } 112 113 116 protected PageRec doCreatePage(IWorkbenchPart part) { 117 IPropertySheetPage page = (IPropertySheetPage) ViewsPlugin.getAdapter(part, 119 IPropertySheetPage.class, false); 120 if (page != null) { 121 if (page instanceof IPageBookViewPage) { 122 initPage((IPageBookViewPage) page); 123 } 124 page.createControl(getPageBook()); 125 return new PageRec(part, page); 126 } 127 128 return null; 130 } 131 132 135 protected void doDestroyPage(IWorkbenchPart part, PageRec rec) { 136 IPropertySheetPage page = (IPropertySheetPage) rec.page; 137 page.dispose(); 138 rec.dispose(); 139 } 140 141 146 protected IWorkbenchPart getBootstrapPart() { 147 IWorkbenchPage page = getSite().getPage(); 148 if (page != null) { 149 bootstrapSelection = page.getSelection(); 150 return page.getActivePart(); 151 } 152 return null; 153 } 154 155 158 public void init(IViewSite site) throws PartInitException { 159 site.getPage().addSelectionListener(this); 160 super.init(site); 161 } 162 163 167 protected boolean isImportant(IWorkbenchPart part) { 168 return part != this; 169 } 170 171 176 public void partActivated(IWorkbenchPart part) { 177 IContributedContentsView view = (IContributedContentsView) ViewsPlugin.getAdapter(part, 180 IContributedContentsView.class, true); 181 IWorkbenchPart source = null; 182 if (view != null) { 183 source = view.getContributingPart(); 184 } 185 if (source != null) { 186 super.partActivated(source); 187 } else { 188 super.partActivated(part); 189 } 190 191 if (bootstrapSelection != null) { 193 IPropertySheetPage page = (IPropertySheetPage) getCurrentPage(); 194 if (page != null) { 195 page.selectionChanged(part, bootstrapSelection); 196 } 197 bootstrapSelection = null; 198 } 199 } 200 201 205 public void selectionChanged(IWorkbenchPart part, ISelection sel) { 206 if (part == this || sel == null) { 208 return; 209 } 210 211 IPropertySheetPage page = (IPropertySheetPage) getCurrentPage(); 213 if (page != null) { 214 page.selectionChanged(part, sel); 215 } 216 } 217 218 225 protected Object getViewAdapter(Class key) { 226 if (ISaveablePart.class.equals(key)) { 227 return getSaveablePart(); 228 } 229 return super.getViewAdapter(key); 230 } 231 232 240 protected ISaveablePart getSaveablePart() { 241 IWorkbenchPart part = getCurrentContributingPart(); 242 if (part instanceof ISaveablePart) { 243 return (ISaveablePart) part; 244 } 245 return null; 246 } 247 } 248 | Popular Tags |