Search in sources :

Example 1 with HALEContextProvider

use of eu.esdihumboldt.hale.ui.HALEContextProvider in project hale by halestudio.

the class NewRelationPage method createViewer.

/**
 * @see ViewerWizardSelectionPage#createViewer(Composite)
 */
@Override
protected Pair<StructuredViewer, Control> createViewer(Composite parent) {
    PatternFilter filter = new PatternFilter();
    filter.setIncludeLeadingWildcard(true);
    FilteredTree tree = new FilteredTree(parent, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    viewer = tree.getViewer();
    viewer.setContentProvider(new FunctionWizardNodeContentProvider(getContainer(), initialSelection, selectionMatcher));
    viewer.setLabelProvider(new FunctionWizardNodeLabelProvider());
    // no input needed, but we have to set something
    viewer.setInput(Boolean.TRUE);
    // set focus on viewer control to prevent odd behavior
    viewer.getControl().setFocus();
    // expand selection
    viewer.expandAll();
    // selection context
    contextProvider = new HALEContextProvider(viewer, null);
    // help update on page shown
    if (getContainer() instanceof IPageChangeProvider) {
        ((IPageChangeProvider) getContainer()).addPageChangedListener(changeListener = new IPageChangedListener() {

            @Override
            public void pageChanged(PageChangedEvent event) {
                if (event.getSelectedPage() == NewRelationPage.this) {
                    // update the help button
                    if (getContainer() instanceof HaleWizardDialog) {
                        ((HaleWizardDialog) getContainer()).setHelpButtonEnabled(getHelpContext() != null);
                    }
                }
            }
        });
    }
    // help update on selection change
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IContext context = getHelpContext();
            // update the help button
            if (getContainer() instanceof HaleWizardDialog) {
                ((HaleWizardDialog) getContainer()).setHelpButtonEnabled(context != null);
            }
            // update the help
            if (context != null) {
                TrayDialog trayDialog = (TrayDialog) getContainer();
                if (trayDialog.getTray() != null) {
                    // if the tray is already open, update the help
                    performHelp();
                }
            }
        }
    });
    // load page configuration
    // XXX would be better if called from outside
    ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
    restore(ps.getConfigurationService());
    return new Pair<StructuredViewer, Control>(viewer, tree);
}
Also used : PatternFilter(org.eclipse.ui.dialogs.PatternFilter) IContext(org.eclipse.help.IContext) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) IPageChangeProvider(org.eclipse.jface.dialogs.IPageChangeProvider) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) PageChangedEvent(org.eclipse.jface.dialogs.PageChangedEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TrayDialog(org.eclipse.jface.dialogs.TrayDialog) HALEContextProvider(eu.esdihumboldt.hale.ui.HALEContextProvider) IPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog) Pair(eu.esdihumboldt.util.Pair)

Aggregations

HALEContextProvider (eu.esdihumboldt.hale.ui.HALEContextProvider)1 ProjectService (eu.esdihumboldt.hale.ui.service.project.ProjectService)1 HaleWizardDialog (eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)1 Pair (eu.esdihumboldt.util.Pair)1 IContext (org.eclipse.help.IContext)1 IPageChangeProvider (org.eclipse.jface.dialogs.IPageChangeProvider)1 IPageChangedListener (org.eclipse.jface.dialogs.IPageChangedListener)1 PageChangedEvent (org.eclipse.jface.dialogs.PageChangedEvent)1 TrayDialog (org.eclipse.jface.dialogs.TrayDialog)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 FilteredTree (org.eclipse.ui.dialogs.FilteredTree)1 PatternFilter (org.eclipse.ui.dialogs.PatternFilter)1