## UI Core

Plug-in "org.eclipse.modisco.infra.browser.uicore" contains the core parts of the browser, that can be integrated in any tree viewer. It provides a tree content provider, a label provider, and a customization manager.

`CustomizableModelContentProvider` and `CustomizableModelLabelProvider` are abstract classes that must be sub-classed, providing an instance of a `CustomizationManager`.

The `CustomizationManager` class is the entry point for customizing the way things look and behave in the browser, through:

- Browser customizations ("uiCustom" files)
- Facets ("facetSet" files)
- APIs to control options that would appear in the MoDisco Browser's toolbar (sort instances, show empty links, etc.)

If parameters are modified in `CustomizationManager` after the `TreeViewer` was displayed, the viewer must be refreshed explicitly to account for these changes.

You may also want to override method `getRootElements` in `CustomizableModelContentProvider`, to provide the `EObject`s you want to display at the root of the tree.

Pay attention to the fact that the elements in the JFace model are not directly `EObject`s, but objects internal to the browser. So, don't redefine the `getElements` method to return `EObject`s, since that wouldn't work.

### EObject from selection

If you want to get an `EObject` from a selection, you must use an adapter like this:

    EObject eObject = (EObject) Platform.getAdapterManager().getAdapter(selectedElement, EObject.class);

### Selection from EObject

To select an EObject in a TreeViewer created using UiCore, you can't just create a StructuredSelection(eObject), since the TreeViewer is composed of elements that encapsulate the EObjects.

Instead, you can retrieve the wrapping element by doing something like this:

     public Object findElementForEObject(EObject eObjectToFind, TreeViewer treeViewer) {
       ITreeContentProvider contentProvider = (ITreeContentProvider) treeViewer
           .getContentProvider();
       Object[] elements = contentProvider.getElements(treeViewer.getInput());
       LinkedList<Object> elementsToHandle = new LinkedList<Object>();
       for (Object element : elements) {
         elementsToHandle.add(element);
       }
       while (!elementsToHandle.isEmpty()) {
         Object e = elementsToHandle.removeFirst();
         EObject eObject = (EObject) Platform.getAdapterManager().getAdapter(e, EObject.class);
         if (eObject != null && eObject.equals(eObjectToFind)) {
           return e;
         }
         if (contentProvider.hasChildren(e)) {
           Object[] children = contentProvider.getChildren(e);
           if (children != null) {
             for (Object child : children) {
               elementsToHandle.addLast(child);
             }
           }
         }
       }
       return null;
     }

### Context menu / Selection provider

If you need to use a selection provider, for example if you want to add a context menu on your UiCore viewer, you can use `UnwrappingSelectionProvider` :

    getSite().registerContextMenu(MENU_ID, contextMenu, new UnwrappingSelectionProvider(treeViewer));

`UnwrappingSelectionProvider` also offers static methods should you need them:

- `ISelection unwrapSelection(ISelection selection)`
- `Object unwrapElement(Object element)`