Search in sources :

Example 6 with INatExample

use of org.eclipse.nebula.widgets.nattable.examples.INatExample in project nebula.widgets.nattable by eclipse.

the class NavLabelProvider method getText.

@Override
public String getText(Object element) {
    String str = (String) element;
    if (!this.contentProvider.hasChildren(element)) {
        INatExample example = TabbedNatExampleRunner.getExample(str);
        return example.getName();
    }
    int lastSlashIndex = str.lastIndexOf('/');
    if (lastSlashIndex < 0) {
        return format(str);
    } else {
        return format(str.substring(lastSlashIndex + 1));
    }
}
Also used : INatExample(org.eclipse.nebula.widgets.nattable.examples.INatExample)

Example 7 with INatExample

use of org.eclipse.nebula.widgets.nattable.examples.INatExample in project nebula.widgets.nattable by eclipse.

the class TabbedNatExampleRunner method openExampleInTab.

private static void openExampleInTab(final String examplePath) {
    final INatExample example = getExample(examplePath);
    if (example == null) {
        return;
    }
    final String exampleName = example.getName();
    final CTabItem tabItem = new CTabItem(tabFolder, SWT.CLOSE);
    tabItem.setText(exampleName);
    tabItem.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            // Stop
            example.onStop();
            Control exampleControl = exampleControlMap.get(example);
            if (exampleControl != null && !exampleControl.isDisposed()) {
                exampleControl.dispose();
            }
            exampleControlMap.remove(example);
            examplePathMap.remove(examplePath);
            link.dispose();
        }
    });
    final Composite tabComposite = new Composite(tabFolder, SWT.NONE);
    tabComposite.setLayout(new GridLayout(1, false));
    // Create example control
    final Control exampleControl = example.createExampleControl(tabComposite);
    exampleControl.setLayoutData(new GridData(GridData.FILL_BOTH));
    exampleControlMap.put(example, exampleControl);
    // Description
    final String description = example.getDescription();
    if (description != null && description.length() > 0) {
        final Group descriptionGroup = new Group(tabComposite, SWT.NONE);
        descriptionGroup.setText("Description");
        descriptionGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        descriptionGroup.setLayout(new FillLayout());
        final Label descriptionLabel = new Label(descriptionGroup, SWT.WRAP);
        descriptionLabel.setText(description);
    }
    link = new Link(tabComposite, SWT.NONE);
    link.setText("<a href=\"" + examplePath + "\">View source</a>");
    final SelectionAdapter linkSelectionListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            String path = event.text;
            if (path.startsWith("/" + INatExample.TUTORIAL_EXAMPLES_PREFIX)) {
                path = path.replace("/" + INatExample.TUTORIAL_EXAMPLES_PREFIX, INatExample.BASE_PATH + "/");
            } else if (path.startsWith("/" + INatExample.CLASSIC_EXAMPLES_PREFIX)) {
                path = path.replace("/" + INatExample.CLASSIC_EXAMPLES_PREFIX, INatExample.CLASSIC_BASE_PATH + "/");
            }
            String source = getResourceAsString(path + ".java");
            if (source != null) {
                viewSource(exampleName, source);
            }
        }
    };
    link.addSelectionListener(linkSelectionListener);
    tabItem.setControl(tabComposite);
    // Start
    example.onStart();
    tabFolder.setSelection(tabItem);
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) FillLayout(org.eclipse.swt.layout.FillLayout) DisposeEvent(org.eclipse.swt.events.DisposeEvent) CTabItem(org.eclipse.swt.custom.CTabItem) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) INatExample(org.eclipse.nebula.widgets.nattable.examples.INatExample) Link(org.eclipse.swt.widgets.Link)

Aggregations

INatExample (org.eclipse.nebula.widgets.nattable.examples.INatExample)7 GridLayout (org.eclipse.swt.layout.GridLayout)3 IOException (java.io.IOException)2 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)2 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)2 TreePath (org.eclipse.jface.viewers.TreePath)2 TreeSelection (org.eclipse.jface.viewers.TreeSelection)2 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 GridData (org.eclipse.swt.layout.GridData)2 Control (org.eclipse.swt.widgets.Control)2 LinkedHashSet (java.util.LinkedHashSet)1 StringTokenizer (java.util.StringTokenizer)1 PostConstruct (javax.annotation.PostConstruct)1 MPart (org.eclipse.e4.ui.model.application.ui.basic.MPart)1 MPartStack (org.eclipse.e4.ui.model.application.ui.basic.MPartStack)1 NavContentProvider (org.eclipse.nebula.widgets.nattable.examples.runner.NavContentProvider)1 NavLabelProvider (org.eclipse.nebula.widgets.nattable.examples.runner.NavLabelProvider)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1