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));
}
}
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);
}
Aggregations