Search in sources :

Example 1 with ReportTreeContentProvider

use of eu.esdihumboldt.hale.ui.views.report.properties.details.tree.ReportTreeContentProvider in project hale by halestudio.

the class DefaultReportDetailsPage method createControls.

/**
 * @see CustomReportDetailsPage#createControls(Composite)
 */
@Override
public Control createControls(Composite parent) {
    // filtered tree sets itself GridData, so set layout to gridlayout
    parent.setLayout(GridLayoutFactory.fillDefaults().create());
    // create pattern filter for FilteredTree
    PatternFilter filter = new PatternFilter();
    // create FilteredTree
    FilteredTree filteredTree = new FilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    treeViewer = filteredTree.getViewer();
    // set content provider
    treeViewer.setContentProvider(new ReportTreeContentProvider());
    // set label provider
    treeViewer.setLabelProvider(new ReportTreeLabelProvider() {

        @Override
        public MessageType getMessageType(Message message) {
            // the current message type
            return messageType;
        }
    });
    // add menu on right-click
    MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            if (treeViewer.getSelection() instanceof IStructuredSelection) {
                IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
                Object o = selection.getFirstElement();
                if (o instanceof Message) {
                    Message m = (Message) o;
                    // check if a stacktrace exists
                    if (m.getStackTrace() != null && !m.getStackTrace().equals("")) {
                        // add Action to the menu
                        manager.add(new ShowStackTraceAction("Show Stack Trace", null, m));
                    }
                }
            }
        }
    });
    // remove previous menus
    menuMgr.setRemoveAllWhenShown(true);
    // add menu to viewer
    treeViewer.getTree().setMenu(menu);
    // open stacktrace on double click
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            TreeSelection o = (TreeSelection) event.getSelection();
            if (o.getFirstElement() instanceof Message) {
                Message m = (Message) o.getFirstElement();
                DefaultReportDetailsPage.this.onDoubleClick(m);
            }
        }
    });
    return filteredTree;
}
Also used : ReportTreeLabelProvider(eu.esdihumboldt.hale.ui.views.report.properties.details.tree.ReportTreeLabelProvider) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) Message(eu.esdihumboldt.hale.common.core.report.Message) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ReportTreeContentProvider(eu.esdihumboldt.hale.ui.views.report.properties.details.tree.ReportTreeContentProvider) IMenuListener(org.eclipse.jface.action.IMenuListener) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IMenuManager(org.eclipse.jface.action.IMenuManager)

Aggregations

Message (eu.esdihumboldt.hale.common.core.report.Message)1 ReportTreeContentProvider (eu.esdihumboldt.hale.ui.views.report.properties.details.tree.ReportTreeContentProvider)1 ReportTreeLabelProvider (eu.esdihumboldt.hale.ui.views.report.properties.details.tree.ReportTreeLabelProvider)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 MenuManager (org.eclipse.jface.action.MenuManager)1 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)1 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 TreeSelection (org.eclipse.jface.viewers.TreeSelection)1 Menu (org.eclipse.swt.widgets.Menu)1 FilteredTree (org.eclipse.ui.dialogs.FilteredTree)1 PatternFilter (org.eclipse.ui.dialogs.PatternFilter)1