| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2000, 2008 IBM Corporation and others. |
| 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
| 7 | * |
| 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | * Gunnar Wagenknecht - fix for bug 21756 [PropertiesView] property view sorting |
| 11 | *******************************************************************************/ |
| 12 | |
| 13 | package org.eclipse.ui.views.properties; |
| 14 | |
| 15 | import org.eclipse.help.IContext; |
| 16 | |
| 17 | import org.eclipse.swt.dnd.Clipboard; |
| 18 | import org.eclipse.swt.dnd.DND; |
| 19 | import org.eclipse.swt.dnd.DragSource; |
| 20 | import org.eclipse.swt.dnd.DragSourceAdapter; |
| 21 | import org.eclipse.swt.dnd.DragSourceEvent; |
| 22 | import org.eclipse.swt.dnd.DragSourceListener; |
| 23 | import org.eclipse.swt.dnd.TextTransfer; |
| 24 | import org.eclipse.swt.dnd.Transfer; |
| 25 | import org.eclipse.swt.events.HelpEvent; |
| 26 | import org.eclipse.swt.events.HelpListener; |
| 27 | import org.eclipse.swt.widgets.Composite; |
| 28 | import org.eclipse.swt.widgets.Control; |
| 29 | import org.eclipse.swt.widgets.Menu; |
| 30 | import org.eclipse.swt.widgets.Shell; |
| 31 | import org.eclipse.swt.widgets.Tree; |
| 32 | |
| 33 | import org.eclipse.core.runtime.IAdaptable; |
| 34 | |
| 35 | import org.eclipse.jface.action.Action; |
| 36 | import org.eclipse.jface.action.IMenuManager; |
| 37 | import org.eclipse.jface.action.IStatusLineManager; |
| 38 | import org.eclipse.jface.action.IToolBarManager; |
| 39 | import org.eclipse.jface.action.MenuManager; |
| 40 | import org.eclipse.jface.action.Separator; |
| 41 | import org.eclipse.jface.internal.ConfigureColumnsDialog; |
| 42 | import org.eclipse.jface.viewers.CellEditor; |
| 43 | import org.eclipse.jface.viewers.ISelection; |
| 44 | import org.eclipse.jface.viewers.ISelectionChangedListener; |
| 45 | import org.eclipse.jface.viewers.IStructuredSelection; |
| 46 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
| 47 | import org.eclipse.jface.window.SameShellProvider; |
| 48 | |
| 49 | import org.eclipse.ui.IActionBars; |
| 50 | import org.eclipse.ui.IPartListener; |
| 51 | import org.eclipse.ui.ISaveablePart; |
| 52 | import org.eclipse.ui.ISharedImages; |
| 53 | import org.eclipse.ui.IWorkbenchPart; |
| 54 | import org.eclipse.ui.PlatformUI; |
| 55 | import org.eclipse.ui.help.IContextComputer; |
| 56 | import org.eclipse.ui.help.IWorkbenchHelpSystem; |
| 57 | import org.eclipse.ui.internal.views.ViewsPlugin; |
| 58 | import org.eclipse.ui.internal.views.properties.PropertiesMessages; |
| 59 | import org.eclipse.ui.part.CellEditorActionHandler; |
| 60 | import org.eclipse.ui.part.Page; |
| 61 | |
| 62 | /** |
| 63 | * The standard implementation of property sheet page which presents |
| 64 | * a table of property names and values obtained from the current selection |
| 65 | * in the active workbench part. |
| 66 | * <p> |
| 67 | * This page obtains the information about what properties to display from |
| 68 | * the current selection (which it tracks). |
| 69 | * </p> |
| 70 | * <p> |
| 71 | * The model for this page is a hierarchy of <code>IPropertySheetEntry</code>. |
| 72 | * The page may be configured with a custom model by setting the root entry. |
| 73 | * <p> |
| 74 | * If no root entry is set then a default model is created which uses the |
| 75 | * <code>IPropertySource</code> interface to obtain the properties of |
| 76 | * the current selection. This requires that the selected objects provide an |
| 77 | * <code>IPropertySource</code> adapter (or implement |
| 78 | * <code>IPropertySource</code> directly). This restiction can be overcome |
| 79 | * by providing this page with an <code>IPropertySourceProvider</code>. If |
| 80 | * supplied, this provider will be used by the default model to obtain a |
| 81 | * property source for the current selection |
| 82 | * </p> |
| 83 | * <p> |
| 84 | * This class may be instantiated; it is not intended to be subclassed. |
| 85 | * </p> |
| 86 | * |
| 87 | * @see IPropertySource |
| 88 | * @noextend This class is not intended to be subclassed by clients. |
| 89 | */ |
| 90 | public class PropertySheetPage extends Page implements IPropertySheetPage, IAdaptable { |
| 91 | /** |
| 92 | * Help context id |
| 93 | * (value <code>"org.eclipse.ui.property_sheet_page_help_context"</code>). |
| 94 | */ |
| 95 | public static final String HELP_CONTEXT_PROPERTY_SHEET_PAGE = "org.eclipse.ui.property_sheet_page_help_context"; //$NON-NLS-1$ |
| 96 | |
| 97 | private PropertySheetViewer viewer; |
| 98 | |
| 99 | private PropertySheetSorter sorter; |
| 100 | |
| 101 | private IPropertySheetEntry rootEntry; |
| 102 | |
| 103 | private IPropertySourceProvider provider; |
| 104 | |
| 105 | private DefaultsAction defaultsAction; |
| 106 | |
| 107 | private FilterAction filterAction; |
| 108 | |
| 109 | private CategoriesAction categoriesAction; |
| 110 | |
| 111 | private CopyPropertyAction copyAction; |
| 112 | |
| 113 | private ICellEditorActivationListener cellEditorActivationListener; |
| 114 | |
| 115 | private CellEditorActionHandler cellEditorActionHandler; |
| 116 | |
| 117 | private Clipboard clipboard; |
| 118 | |
| 119 | private IWorkbenchPart sourcePart; |
| 120 | |
| 121 | /** |
| 122 | * Part listener which cleans up this page when the source part is closed. |
| 123 | * This is hooked only when there is a source part. |
| 124 | * |
| 125 | * @since 3.2 |
| 126 | */ |
| 127 | private class PartListener implements IPartListener { |
| 128 | public void partActivated(IWorkbenchPart part) { |
| 129 | } |
| 130 | |
| 131 | public void partBroughtToTop(IWorkbenchPart part) { |
| 132 | } |
| 133 | |
| 134 | public void partClosed(IWorkbenchPart part) { |
| 135 | if (sourcePart == part) { |
| 136 | sourcePart = null; |
| 137 | if (viewer != null && !viewer.getControl().isDisposed()) { |
| 138 | viewer.setInput(new Object[0]); |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | public void partDeactivated(IWorkbenchPart part) { |
| 144 | } |
| 145 | |
| 146 | public void partOpened(IWorkbenchPart part) { |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | private PartListener partListener = new PartListener(); |
| 151 | |
| 152 | private Action columnsAction; |
| 153 | |
| 154 | /** |
| 155 | * Creates a new property sheet page. |
| 156 | */ |
| 157 | public PropertySheetPage() { |
| 158 | super(); |
| 159 | } |
| 160 | |
| 161 | /* (non-Javadoc) |
| 162 | * Method declared on <code>IPage</code>. |
| 163 | */ |
| 164 | public void createControl(Composite parent) { |
| 165 | // create a new viewer |
| 166 | viewer = new PropertySheetViewer(parent); |
| 167 | viewer.setSorter(sorter); |
| 168 | |
| 169 | // set the model for the viewer |
| 170 | if (rootEntry == null) { |
| 171 | // create a new root |
| 172 | PropertySheetEntry root = new PropertySheetEntry(); |
| 173 | if (provider != null) { |
| 174 | // set the property source provider |
| 175 | root.setPropertySourceProvider(provider); |
| 176 | } |
| 177 | rootEntry = root; |
| 178 | } |
| 179 | viewer.setRootEntry(rootEntry); |
| 180 | viewer.addActivationListener(getCellEditorActivationListener()); |
| 181 | // add a listener to track when the entry selection changes |
| 182 | viewer.addSelectionChangedListener(new ISelectionChangedListener() { |
| 183 | public void selectionChanged(SelectionChangedEvent event) { |
| 184 | handleEntrySelection(event.getSelection()); |
| 185 | } |
| 186 | }); |
| 187 | initDragAndDrop(); |
| 188 | makeActions(); |
| 189 | |
| 190 | // Create the popup menu for the page. |
| 191 | MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$ |
| 192 | menuMgr.add(copyAction); |
| 193 | menuMgr.add(new Separator()); |
| 194 | menuMgr.add(defaultsAction); |
| 195 | Menu menu = menuMgr.createContextMenu(viewer.getControl()); |
| 196 | viewer.getControl().setMenu(menu); |
| 197 | |
| 198 | // Set help on the viewer |
| 199 | viewer.getControl().addHelpListener(new HelpListener() { |
| 200 | /* |
| 201 | * @see HelpListener#helpRequested(HelpEvent) |
| 202 | */ |
| 203 | public void helpRequested(HelpEvent e) { |
| 204 | // Get the context for the selected item |
| 205 | IStructuredSelection selection = (IStructuredSelection) viewer |
| 206 | .getSelection(); |
| 207 | if (!selection.isEmpty()) { |
| 208 | IPropertySheetEntry entry = (IPropertySheetEntry) selection |
| 209 | .getFirstElement(); |
| 210 | Object helpContextId = entry.getHelpContextIds(); |
| 211 | if (helpContextId != null) { |
| 212 | IWorkbenchHelpSystem helpSystem = PlatformUI.getWorkbench().getHelpSystem(); |
| 213 | |
| 214 | // Since 2.0 the only valid type for helpContextIds |
| 215 | // is a String (a single id). |
| 216 | if (helpContextId instanceof String) { |
| 217 | helpSystem.displayHelp((String) helpContextId); |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | // For backward compatibility we have to handle |
| 222 | // and array of contexts (Strings and/or IContexts) |
| 223 | // or a context computer. |
| 224 | Object context= getFirstContext(helpContextId, e); |
| 225 | if (context instanceof IContext) { |
| 226 | helpSystem.displayHelp((IContext) context); |
| 227 | } else if (context instanceof String) { |
| 228 | helpSystem.displayHelp((String) context); |
| 229 | } |
| 230 | return; |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | // No help for the selection so show page help |
| 235 | PlatformUI.getWorkbench().getHelpSystem().displayHelp(HELP_CONTEXT_PROPERTY_SHEET_PAGE); |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Returns the first help context. |
| 240 | * |
| 241 | * @param helpContext the help context which is either an array of contexts (strings |
| 242 | * and/or {@linkplain IContext}s) or an {@link IContextComputer} |
| 243 | * |
| 244 | * @param e the help event |
| 245 | * @return the first context which is either a <code>String</code>, {@link IContext} or |
| 246 | * <code>null</code> if none |
| 247 | * @deprecated As of 2.0, nested contexts are no longer supported by the help support |
| 248 | * system |
| 249 | */ |
| 250 | private Object getFirstContext(Object helpContext, HelpEvent e) { |
| 251 | Object[] contexts; |
| 252 | if (helpContext instanceof IContextComputer) { |
| 253 | // get local contexts |
| 254 | contexts= ((IContextComputer)helpContext) |
| 255 | .getLocalContexts(e); |
| 256 | } else { |
| 257 | contexts= (Object[])helpContext; |
| 258 | } |
| 259 | |
| 260 | if (contexts.length > 0) |
| 261 | return contexts[0]; |
| 262 | return null; |
| 263 | } |
| 264 | }); |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * The <code>PropertySheetPage</code> implementation of this <code>IPage</code> method |
| 269 | * disposes of this page's entries. |
| 270 | */ |
| 271 | public void dispose() { |
| 272 | super.dispose(); |
| 273 | if (sourcePart != null) { |
| 274 | sourcePart.getSite().getPage().removePartListener(partListener); |
| 275 | } |
| 276 | if (rootEntry != null) { |
| 277 | rootEntry.dispose(); |
| 278 | rootEntry = null; |
| 279 | } |
| 280 | if (clipboard != null) { |
| 281 | clipboard.dispose(); |
| 282 | clipboard = null; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * The <code>PropertySheetPage</code> implementation of this <code>IAdaptable</code> method |
| 288 | * handles the <code>ISaveablePart</code> adapter by delegating to the source part. |
| 289 | * |
| 290 | * @since 3.2 |
| 291 | */ |
| 292 | public Object getAdapter(Class adapter) { |
| 293 | if (ISaveablePart.class.equals(adapter)) { |
| 294 | return getSaveablePart(); |
| 295 | } |
| 296 | return null; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Returns an <code>ISaveablePart</code> that delegates to the source part |
| 301 | * for the current page if it implements <code>ISaveablePart</code>, or |
| 302 | * <code>null</code> otherwise. |
| 303 | * |
| 304 | * @return an <code>ISaveablePart</code> or <code>null</code> |
| 305 | * @since 3.2 |
| 306 | */ |
| 307 | protected ISaveablePart getSaveablePart() { |
| 308 | if (sourcePart instanceof ISaveablePart) { |
| 309 | return (ISaveablePart) sourcePart; |
| 310 | } |
| 311 | return null; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Returns the cell editor activation listener for this page |
| 316 | * @return ICellEditorActivationListener the cell editor activation listener for this page |
| 317 | */ |
| 318 | private ICellEditorActivationListener getCellEditorActivationListener() { |
| 319 | if (cellEditorActivationListener == null) { |
| 320 | cellEditorActivationListener = new ICellEditorActivationListener() { |
| 321 | public void cellEditorActivated(CellEditor cellEditor) { |
| 322 | if (cellEditorActionHandler != null) { |
| 323 | cellEditorActionHandler.addCellEditor(cellEditor); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | public void cellEditorDeactivated(CellEditor cellEditor) { |
| 328 | if (cellEditorActionHandler != null) { |
| 329 | cellEditorActionHandler.removeCellEditor(cellEditor); |
| 330 | } |
| 331 | } |
| 332 | }; |
| 333 | } |
| 334 | return cellEditorActivationListener; |
| 335 | } |
| 336 | |
| 337 | /* (non-Javadoc) |
| 338 | * Method declared on IPage (and Page). |
| 339 | */ |
| 340 | public Control getControl() { |
| 341 | if (viewer == null) { |
| 342 | return null; |
| 343 | } |
| 344 | return viewer.getControl(); |
| 345 | } |
| 346 | |
| 347 | /** |
| 348 | * Handles a selection change in the entry table. |
| 349 | * |
| 350 | * @param selection the new selection |
| 351 | */ |
| 352 | public void handleEntrySelection(ISelection selection) { |
| 353 | if (defaultsAction != null) { |
| 354 | if (selection.isEmpty()) { |
| 355 | defaultsAction.setEnabled(false); |
| 356 | return; |
| 357 | } |
| 358 | // see if item is editable |
| 359 | boolean editable = viewer.getActiveCellEditor() != null; |
| 360 | defaultsAction.setEnabled(editable); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | /** |
| 365 | * Adds drag and drop support. |
| 366 | */ |
| 367 | protected void initDragAndDrop() { |
| 368 | int operations = DND.DROP_COPY; |
| 369 | Transfer[] transferTypes = new Transfer[] { TextTransfer.getInstance() }; |
| 370 | DragSourceListener listener = new DragSourceAdapter() { |
| 371 | public void dragSetData(DragSourceEvent event) { |
| 372 | performDragSetData(event); |
| 373 | } |
| 374 | |
| 375 | public void dragFinished(DragSourceEvent event) { |
| 376 | //Nothing to do here |
| 377 | } |
| 378 | }; |
| 379 | DragSource dragSource = new DragSource( |
| 380 | viewer.getControl(), operations); |
| 381 | dragSource.setTransfer(transferTypes); |
| 382 | dragSource.addDragListener(listener); |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * The user is attempting to drag. Add the appropriate |
| 387 | * data to the event. |
| 388 | * @param event The event sent from the drag and drop support. |
| 389 | */ |
| 390 | void performDragSetData(DragSourceEvent event) { |
| 391 | // Get the selected property |
| 392 | IStructuredSelection selection = (IStructuredSelection) viewer |
| 393 | .getSelection(); |
| 394 | if (selection.isEmpty()) { |
| 395 | return; |
| 396 | } |
| 397 | // Assume single selection |
| 398 | IPropertySheetEntry entry = (IPropertySheetEntry) selection |
| 399 | .getFirstElement(); |
| 400 | |
| 401 | // Place text as the data |
| 402 | StringBuffer buffer = new StringBuffer(); |
| 403 | buffer.append(entry.getDisplayName()); |
| 404 | buffer.append("\t"); //$NON-NLS-1$ |
| 405 | buffer.append(entry.getValueAsString()); |
| 406 | |
| 407 | event.data = buffer.toString(); |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Make action objects. |
| 412 | */ |
| 413 | private void makeActions() { |
| 414 | ISharedImages sharedImages = PlatformUI.getWorkbench() |
| 415 | .getSharedImages(); |
| 416 | |
| 417 | // Restore Default Value |
| 418 | defaultsAction = new DefaultsAction(viewer, "defaults"); //$NON-NLS-1$ |
| 419 | defaultsAction.setText(PropertiesMessages.Defaults_text); |
| 420 | defaultsAction.setToolTipText(PropertiesMessages.Defaults_toolTip); |
| 421 | defaultsAction |
| 422 | .setImageDescriptor(ViewsPlugin.getViewImageDescriptor("elcl16/defaults_ps.gif")); //$NON-NLS-1$ |
| 423 | defaultsAction |
| 424 | .setDisabledImageDescriptor(ViewsPlugin.getViewImageDescriptor("dlcl16/defaults_ps.gif")); //$NON-NLS-1$ |
| 425 | defaultsAction.setEnabled(false); |
| 426 | |
| 427 | // Show Advanced Properties |
| 428 | filterAction = new FilterAction(viewer, "filter"); //$NON-NLS-1$ |
| 429 | filterAction.setText(PropertiesMessages.Filter_text); |
| 430 | filterAction.setToolTipText(PropertiesMessages.Filter_toolTip); |
| 431 | filterAction |
| 432 | .setImageDescriptor(ViewsPlugin.getViewImageDescriptor("elcl16/filter_ps.gif")); //$NON-NLS-1$ |
| 433 | filterAction.setChecked(false); |
| 434 | |
| 435 | // Show Categories |
| 436 | categoriesAction = new CategoriesAction(viewer, "categories"); //$NON-NLS-1$ |
| 437 | categoriesAction.setText(PropertiesMessages.Categories_text); |
| 438 | categoriesAction.setToolTipText(PropertiesMessages.Categories_toolTip); |
| 439 | categoriesAction |
| 440 | .setImageDescriptor(ViewsPlugin.getViewImageDescriptor("elcl16/tree_mode.gif")); //$NON-NLS-1$ |
| 441 | categoriesAction.setChecked(true); |
| 442 | |
| 443 | // Columns... |
| 444 | columnsAction = new Action(PropertiesMessages.Columns_text){ |
| 445 | public void run() { |
| 446 | Tree tree = (Tree) viewer.getControl(); |
| 447 | new ConfigureColumnsDialog(new SameShellProvider(tree), tree).open(); |
| 448 | } |
| 449 | }; |
| 450 | columnsAction.setToolTipText(PropertiesMessages.Columns_toolTip); |
| 451 | |
| 452 | // Copy |
| 453 | Shell shell = viewer.getControl().getShell(); |
| 454 | clipboard = new Clipboard(shell.getDisplay()); |
| 455 | copyAction = new CopyPropertyAction(viewer, "copy", clipboard); //$NON-NLS-1$ |
| 456 | copyAction.setText(PropertiesMessages.CopyProperty_text); |
| 457 | copyAction.setImageDescriptor(sharedImages |
| 458 | .getImageDescriptor(ISharedImages.IMG_TOOL_COPY)); |
| 459 | } |
| 460 | |
| 461 | /* (non-Javadoc) |
| 462 | * Method declared on IPage (and Page). |
| 463 | */ |
| 464 | public void makeContributions(IMenuManager menuManager, |
| 465 | IToolBarManager toolBarManager, IStatusLineManager statusLineManager) { |
| 466 | |
| 467 | // add actions to the tool bar |
| 468 | toolBarManager.add(categoriesAction); |
| 469 | toolBarManager.add(filterAction); |
| 470 | toolBarManager.add(defaultsAction); |
| 471 | |
| 472 | // add actions to the menu |
| 473 | menuManager.add(categoriesAction); |
| 474 | menuManager.add(filterAction); |
| 475 | menuManager.add(columnsAction); |
| 476 | |
| 477 | // set status line manager into the viewer |
| 478 | viewer.setStatusLineManager(statusLineManager); |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * Updates the model for the viewer. |
| 483 | * <p> |
| 484 | * Note that this means ensuring that the model reflects the state |
| 485 | * of the current viewer input. |
| 486 | * </p> |
| 487 | */ |
| 488 | public void refresh() { |
| 489 | if (viewer == null) { |
| 490 | return; |
| 491 | } |
| 492 | // calling setInput on the viewer will cause the model to refresh |
| 493 | viewer.setInput(viewer.getInput()); |
| 494 | } |
| 495 | |
| 496 | /* (non-Javadoc) |
| 497 | * Method declared on ISelectionListener. |
| 498 | */ |
| 499 | public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
| 500 | if (viewer == null) { |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | if (sourcePart != null) { |
| 505 | sourcePart.getSite().getPage().removePartListener(partListener); |
| 506 | sourcePart = null; |
| 507 | } |
| 508 | |
| 509 | // change the viewer input since the workbench selection has changed. |
| 510 | if (selection instanceof IStructuredSelection) { |
| 511 | sourcePart = part; |
| 512 | viewer.setInput(((IStructuredSelection) selection).toArray()); |
| 513 | } |
| 514 | |
| 515 | if (sourcePart != null) { |
| 516 | sourcePart.getSite().getPage().addPartListener(partListener); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | /** |
| 521 | * The <code>PropertySheetPage</code> implementation of this <code>IPage</code> method |
| 522 | * calls <code>makeContributions</code> for backwards compatibility with |
| 523 | * previous versions of <code>IPage</code>. |
| 524 | * <p> |
| 525 | * Subclasses may reimplement. |
| 526 | * </p> |
| 527 | */ |
| 528 | public void setActionBars(IActionBars actionBars) { |
| 529 | super.setActionBars(actionBars); |
| 530 | cellEditorActionHandler = new CellEditorActionHandler(actionBars); |
| 531 | cellEditorActionHandler.setCopyAction(copyAction); |
| 532 | } |
| 533 | |
| 534 | /** |
| 535 | * Sets focus to a part in the page. |
| 536 | */ |
| 537 | public void setFocus() { |
| 538 | viewer.getControl().setFocus(); |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Sets the given property source provider as |
| 543 | * the property source provider. |
| 544 | * <p> |
| 545 | * Calling this method is only valid if you are using |
| 546 | * this page's default root entry. |
| 547 | * </p> |
| 548 | * @param newProvider the property source provider |
| 549 | */ |
| 550 | public void setPropertySourceProvider(IPropertySourceProvider newProvider) { |
| 551 | provider = newProvider; |
| 552 | if (rootEntry instanceof PropertySheetEntry) { |
| 553 | ((PropertySheetEntry) rootEntry) |
| 554 | .setPropertySourceProvider(provider); |
| 555 | // the following will trigger an update |
| 556 | viewer.setRootEntry(rootEntry); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Sets the given entry as the model for the page. |
| 562 | * |
| 563 | * @param entry the root entry |
| 564 | */ |
| 565 | public void setRootEntry(IPropertySheetEntry entry) { |
| 566 | rootEntry = entry; |
| 567 | if (viewer != null) { |
| 568 | // the following will trigger an update |
| 569 | viewer.setRootEntry(rootEntry); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * Sets the sorter used for sorting categories and entries in the viewer |
| 575 | * of this page. |
| 576 | * <p> |
| 577 | * The default sorter sorts categories and entries alphabetically. |
| 578 | * </p> |
| 579 | * @param sorter the sorter to set (<code>null</code> will reset to the |
| 580 | * default sorter) |
| 581 | * @since 3.1 |
| 582 | */ |
| 583 | protected void setSorter(PropertySheetSorter sorter) { |
| 584 | this.sorter = sorter; |
| 585 | if (viewer != null) { |
| 586 | viewer.setSorter(sorter); |
| 587 | |
| 588 | // the following will trigger an update |
| 589 | if(null != viewer.getRootEntry()) { |
| 590 | viewer.setRootEntry(rootEntry); |
| 591 | } |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | } |