Search in sources :

Example 1 with ChannelTreeLabelProvider

use of alma.acs.eventbrowser.parts.ChannelTreeProviders.ChannelTreeLabelProvider in project ACS by ACS-Community.

the class ChannelTreePart method postConstruct.

/**
	 * See http://www.vogella.com/articles/EclipseJFaceTree/article.html
	 */
@PostConstruct
public void postConstruct(Composite parent, final IEclipseContext context, EMenuService menuService, IEventBroker eventBroker) {
    try {
        eventModel = EventModel.getInstance();
    } catch (Throwable thr) {
        thr.printStackTrace();
        IStatus someStatus = statusReporter.newStatus(IStatus.ERROR, "Connection with NCs failed.", thr);
        statusReporter.report(someStatus, StatusReporter.SHOW);
        throw new RuntimeException(thr);
    }
    //		eventModel.getLogger().info("ChannelTreePart got EventModel instance.");
    statusLineWriter = new StatusLineWriter(eventBroker);
    viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.setContentProvider(new ChannelTreeContentProvider());
    viewer.setLabelProvider(new ChannelTreeLabelProvider());
    // Expand the tree. '2' means to show only the visible top-level nodes.
    viewer.setAutoExpandLevel(2);
    viewer.setComparator(new ServiceViewerComparator());
    // Provide the root node to the ContentProvider
    viewer.setInput(eventModel.getNotifyServicesRoot());
    // Expand with doubleclick
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            IStructuredSelection thisSelection = (IStructuredSelection) event.getSelection();
            Object selectedNode = thisSelection.getFirstElement();
            viewer.setExpandedState(selectedNode, !viewer.getExpandedState(selectedNode));
        }
    });
    // Attach a selection listener to our tree that will post selections to the ESelectionService
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            selectionService.setSelection(selection.size() == 1 ? selection.getFirstElement() : selection.toArray());
        }
    });
    // TODO: Take care of help system. Here's the E3 code:
    //		// Create the help context id for the viewer's control
    //		PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "alma.acs.eventbrowser.viewer");
    hookContextMenu(menuService);
    // TODO: this could be used by handlers etc, currently it's not
    context.set(ChannelTreePart.class, this);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ChannelTreeContentProvider(alma.acs.eventbrowser.parts.ChannelTreeProviders.ChannelTreeContentProvider) StatusLineWriter(alma.acs.eventbrowser.status.StatusLineWriter) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ChannelTreeLabelProvider(alma.acs.eventbrowser.parts.ChannelTreeProviders.ChannelTreeLabelProvider) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ChannelTreeContentProvider (alma.acs.eventbrowser.parts.ChannelTreeProviders.ChannelTreeContentProvider)1 ChannelTreeLabelProvider (alma.acs.eventbrowser.parts.ChannelTreeProviders.ChannelTreeLabelProvider)1 StatusLineWriter (alma.acs.eventbrowser.status.StatusLineWriter)1 PostConstruct (javax.annotation.PostConstruct)1 IStatus (org.eclipse.core.runtime.IStatus)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1