Search in sources :

Example 1 with CategorisedPrioritisedConfigurationElementTreeContentProvider

use of org.bndtools.utils.eclipse.CategorisedPrioritisedConfigurationElementTreeContentProvider in project bndtools by bndtools.

the class AbstractTemplateSelectionWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    setControl(container);
    container.setLayout(new GridLayout(1, false));
    new Label(container, SWT.NONE).setText("Select Template:");
    tree = new Tree(container, SWT.BORDER | SWT.FULL_SELECTION);
    GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_table.heightHint = 100;
    tree.setLayoutData(gd_table);
    viewer = new TreeViewer(tree);
    Label lblNewLabel = new Label(container, SWT.NONE);
    lblNewLabel.setText("Description:");
    Composite cmpDescription = new Composite(container, SWT.BORDER);
    cmpDescription.setBackground(tree.getBackground());
    txtDescription = new ScrolledFormText(cmpDescription, SWT.V_SCROLL | SWT.H_SCROLL, false);
    FormText formText = new FormText(txtDescription, SWT.NO_FOCUS);
    txtDescription.setFormText(formText);
    txtDescription.setBackground(tree.getBackground());
    formText.setBackground(tree.getBackground());
    formText.setForeground(tree.getForeground());
    formText.setFont("fixed", JFaceResources.getTextFont());
    formText.setFont("italic", JFaceResources.getFontRegistry().getItalic(""));
    GridData gd_cmpDescription = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd_cmpDescription.heightHint = 100;
    cmpDescription.setLayoutData(gd_cmpDescription);
    GridLayout layout_cmpDescription = new GridLayout(1, false);
    cmpDescription.setLayout(layout_cmpDescription);
    GridData gd_txtDescription = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_txtDescription.heightHint = 100;
    txtDescription.setLayoutData(gd_txtDescription);
    viewer.setContentProvider(new CategorisedPrioritisedConfigurationElementTreeContentProvider(true));
    viewer.setLabelProvider(new ConfigElementLabelProvider(parent.getDisplay(), "icons/template.gif"));
    loadData();
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            Object selected = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (selected instanceof IConfigurationElement)
                setSelectionFromConfigElement((IConfigurationElement) selected);
            else
                setSelectionFromConfigElement(null);
            updateUI();
        }
    });
    txtDescription.getFormText().addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        public void linkActivated(HyperlinkEvent event) {
            IWorkbenchBrowserSupport browserSupport = PlatformUI.getWorkbench().getBrowserSupport();
            try {
                IWebBrowser externalBrowser = browserSupport.getExternalBrowser();
                externalBrowser.openURL(new URL((String) event.getHref()));
            } catch (PartInitException e) {
                logger.logError("Error opening external browser.", e);
            } catch (MalformedURLException e) {
            // Ignore
            }
        }
    });
    updateUI();
}
Also used : MalformedURLException(java.net.MalformedURLException) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) CategorisedPrioritisedConfigurationElementTreeContentProvider(org.bndtools.utils.eclipse.CategorisedPrioritisedConfigurationElementTreeContentProvider) ScrolledFormText(org.eclipse.ui.forms.widgets.ScrolledFormText) FormText(org.eclipse.ui.forms.widgets.FormText) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) ScrolledFormText(org.eclipse.ui.forms.widgets.ScrolledFormText) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) URL(java.net.URL) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ConfigElementLabelProvider(org.bndtools.core.ui.ConfigElementLabelProvider) Tree(org.eclipse.swt.widgets.Tree) IWorkbenchBrowserSupport(org.eclipse.ui.browser.IWorkbenchBrowserSupport) PartInitException(org.eclipse.ui.PartInitException) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Aggregations

MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ConfigElementLabelProvider (org.bndtools.core.ui.ConfigElementLabelProvider)1 CategorisedPrioritisedConfigurationElementTreeContentProvider (org.bndtools.utils.eclipse.CategorisedPrioritisedConfigurationElementTreeContentProvider)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Tree (org.eclipse.swt.widgets.Tree)1 PartInitException (org.eclipse.ui.PartInitException)1 IWebBrowser (org.eclipse.ui.browser.IWebBrowser)1 IWorkbenchBrowserSupport (org.eclipse.ui.browser.IWorkbenchBrowserSupport)1 HyperlinkAdapter (org.eclipse.ui.forms.events.HyperlinkAdapter)1 HyperlinkEvent (org.eclipse.ui.forms.events.HyperlinkEvent)1 FormText (org.eclipse.ui.forms.widgets.FormText)1 ScrolledFormText (org.eclipse.ui.forms.widgets.ScrolledFormText)1