If we want display the generated XWT page outside of a CDO context, this code could help (cf N. Fauvergue) | |
* Update the properties view with the given selection. | |
* | |
* @param selection | |
* the given selection. | |
*/ | |
private void updatePropertiesView(final ISelection selection) { | |
if (!PlatformUI.isWorkbenchRunning()) { | |
// no update of property view outside of workbench | |
return; | |
} | |
if (selection instanceof StructuredSelection) { | |
final StructuredSelection structuredSelection = (StructuredSelection) selection; | |
final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); | |
final IPropertySheetPage propertySheetPage = getPropertySheetPage(page); | |
if (propertySheetPage != null) { | |
StructuredSelection selectionForPropertySheet = null; | |
final IWorkbenchPart activePart = page.getActivePart(); | |
final Object firstElement = structuredSelection.getFirstElement(); | |
if (firstElement instanceof MergeViewerItem) { | |
final MergeViewerItem mergeViewerItem = (MergeViewerItem) firstElement; | |
final MergeViewerSide side = mergeViewerItem.getSide(); | |
final Object newSelectedObject = mergeViewerItem.getSideValue(side); | |
if (propertySheetPage instanceof ExtendedPropertySheetPage) { | |
((ExtendedPropertySheetPage) propertySheetPage).setPropertySourceProvider(adapterFactoryContentProvider); | |
} | |
getControl().addDisposeListener(new DisposeListener() { | |
public void widgetDisposed(DisposeEvent e) { | |
if (propertySheetPage instanceof ExtendedPropertySheetPage && null != propertySheetPage.getControl() && !propertySheetPage.getControl().isDisposed()) { | |
((ExtendedPropertySheetPage) propertySheetPage).selectionChanged(activePart, null); | |
((ExtendedPropertySheetPage) propertySheetPage).setPropertySourceProvider(null); | |
} | |
} | |
}); | |
if (newSelectedObject != null) { | |
if (newSelectedObject instanceof EObject) { | |
manageReadOnly((EObject) newSelectedObject, side); | |
} | |
if (null != propertySheetPage.getControl() && !propertySheetPage.getControl().isDisposed()) { | |
selectionForPropertySheet = new StructuredSelection(newSelectedObject); | |
propertySheetPage.selectionChanged(activePart, selectionForPropertySheet); | |
} | |
} | |
} | |
if (selectionForPropertySheet == null && null != propertySheetPage.getControl() && !propertySheetPage.getControl().isDisposed()) { | |
selectionForPropertySheet = new StructuredSelection(new Object()); | |
propertySheetPage.selectionChanged(activePart, selectionForPropertySheet); | |
} | |
} | |
} | |
} | |
//To get the property view | |
/** | |
* Returns the property sheet page. | |
* | |
* @return the property sheet page. | |
*/ | |
private IPropertySheetPage getPropertySheetPage(final IWorkbenchPage activePage) { | |
IPropertySheetPage propertyPage = null; | |
if (activePage != null) { | |
final IViewPart view = activePage.findView("org.eclipse.ui.views.PropertySheet"); //$NON-NLS-1$ | |
if (view != null) { | |
if (view instanceof PropertySheet) { | |
final PropertySheet propertySheet = (PropertySheet) view; | |
final IPage currentPage = propertySheet.getCurrentPage(); | |
final IEditorPart activeEditor = activePage.getActiveEditor(); | |
final IPropertySheetPage adapter = (IPropertySheetPage) Platform.getAdapterManager().getAdapter(activeEditor, IPropertySheetPage.class); | |
if (null != activeEditor && null != adapter) { | |
propertySheet.partActivated(activePage.getActivePart()); | |
propertyPage = adapter; | |
} else if (currentPage instanceof ExtendedPropertySheetPage) { | |
propertyPage = (ExtendedPropertySheetPage) currentPage; | |
} | |
} | |
} | |
} | |
return propertyPage; | |
} | |