Search in sources :

Example 1 with ConfigElementLabelProvider

use of org.bndtools.core.ui.ConfigElementLabelProvider in project bndtools by bndtools.

the class RunExportSelectionPage method createControl.

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    setControl(container);
    container.setLayout(new GridLayout(1, false));
    table = new Table(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    viewer = new TableViewer(table);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setLabelProvider(new ConfigElementLabelProvider(table.getDisplay(), null));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection sel = viewer.getSelection();
            if (sel.isEmpty())
                setSelectedNode(null);
            else {
                IConfigurationElement elem = (IConfigurationElement) ((IStructuredSelection) sel).getFirstElement();
                IWizardNode node = nodeCache.get(elem);
                if (node == null) {
                    node = new RunExportWizardNode(getShell(), elem, model, bndProject);
                    nodeCache.put(elem, node);
                }
                setSelectedNode(node);
            }
        }
    });
    viewer.addOpenListener(new IOpenListener() {

        public void open(OpenEvent event) {
            IWizardPage nextPage = getNextPage();
            if (nextPage != null)
                getContainer().showPage(nextPage);
        }
    });
    viewer.setInput(elements);
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IWizardNode(org.eclipse.jface.wizard.IWizardNode) GridLayout(org.eclipse.swt.layout.GridLayout) IOpenListener(org.eclipse.jface.viewers.IOpenListener) GridData(org.eclipse.swt.layout.GridData) ConfigElementLabelProvider(org.bndtools.core.ui.ConfigElementLabelProvider) ISelection(org.eclipse.jface.viewers.ISelection) IWizardPage(org.eclipse.jface.wizard.IWizardPage) TableViewer(org.eclipse.jface.viewers.TableViewer) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Example 2 with ConfigElementLabelProvider

use of org.bndtools.core.ui.ConfigElementLabelProvider 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

ConfigElementLabelProvider (org.bndtools.core.ui.ConfigElementLabelProvider)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 CategorisedPrioritisedConfigurationElementTreeContentProvider (org.bndtools.utils.eclipse.CategorisedPrioritisedConfigurationElementTreeContentProvider)1 IOpenListener (org.eclipse.jface.viewers.IOpenListener)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 OpenEvent (org.eclipse.jface.viewers.OpenEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 IWizardNode (org.eclipse.jface.wizard.IWizardNode)1 IWizardPage (org.eclipse.jface.wizard.IWizardPage)1 Label (org.eclipse.swt.widgets.Label)1 Table (org.eclipse.swt.widgets.Table)1