use of org.eclipse.n4js.ui.viewer.TreeViewerBuilder in project n4js by eclipse.
the class ExternalLibraryPreferencePage method createContents.
@Override
protected Control createContents(final Composite parent) {
final Composite control = new Composite(parent, NONE);
control.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).create());
control.setLayoutData(fillDefaults().align(FILL, FILL).create());
viewer = new TreeViewerBuilder(singletonList(""), contentProvider.get()).setVirtual(true).setHeaderVisible(false).setHasBorder(true).setColumnWeights(asList(1)).setLabelProvider(new DelegatingStyledCellLabelProvider(new BuiltInLibrariesLabelProvider())).build(control);
setViewerInput();
final Composite subComposite = new Composite(control, NONE);
subComposite.setLayout(GridLayoutFactory.fillDefaults().create());
subComposite.setLayoutData(fillDefaults().align(END, TOP).create());
createEnabledPushButton(subComposite, "Add...", createSelectionListener(this::handleAddButtonSelectionListener));
final Button remove = createDisabledPushButton(subComposite, "Remove", createSelectionListener(this::handleRemoveButtonSelection));
createPlaceHolderLabel(subComposite);
final Button moveUp = createDisabledPushButton(subComposite, "Up", createSelectionListener(this::handleMoveUpButtonSelection));
final Button moveDown = createDisabledPushButton(subComposite, "Down", createSelectionListener(this::handleMoveDownButtonSelection));
createPlaceHolderLabel(subComposite);
createPlaceHolderLabel(subComposite);
createEnabledPushButton(subComposite, "Install npm...", new InstallNpmDependencyButtonListener(this::intallAndUpdate, () -> getPackageNameToInstallValidator(), () -> getPackageVersionValidator(), statusHelper));
createEnabledPushButton(subComposite, "Uninstall npm...", new UninstallNpmDependencyButtonListener(this::unintallAndUpdate, () -> getPackageNameToUninstallValidator(), statusHelper, this::getSelectedNpm));
createEnabledPushButton(subComposite, "Run maintenance actions...", new MaintenanceActionsButtonListener(this::runMaintananceActions));
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final /* @Nullable */
SelectionChangedEvent event) {
final Tree tree = viewer.getTree();
final TreeItem[] selection = tree.getSelection();
if (!Arrays2.isEmpty(selection) && 1 == selection.length && selection[0].getData() instanceof URI) {
final URI uri = (URI) selection[0].getData();
if (BUILT_IN_LIBS.containsKey(uri)) {
remove.setEnabled(false);
moveUp.setEnabled(false);
moveDown.setEnabled(false);
} else {
final int selectionIndex = tree.indexOf(selection[0]);
final int itemCount = tree.getItemCount();
remove.setEnabled(true);
if (selectionIndex > 0) {
moveUp.setEnabled(!BUILT_IN_LIBS.containsKey(tree.getItem(selectionIndex - 1).getData()));
} else {
moveUp.setEnabled(0 != selectionIndex);
}
moveDown.setEnabled(selectionIndex != itemCount - 1);
}
} else {
remove.setEnabled(false);
moveUp.setEnabled(false);
moveDown.setEnabled(false);
}
}
});
return control;
}
use of org.eclipse.n4js.ui.viewer.TreeViewerBuilder in project n4js by eclipse.
the class TestResultsView method createPartControl.
/**
* This is a callback that will allow us to create the viewer and initialize it.
*/
@Override
public void createPartControl(final Composite parent) {
GridLayout gl;
GridData gd;
gl = new GridLayout(2, false);
gl.marginWidth = 0;
gl.marginHeight = 0;
gl.marginTop = 4;
parent.setLayout(gl);
toolBar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT);
gd = new GridData();
gd.grabExcessHorizontalSpace = false;
gd.horizontalAlignment = SWT.CENTER;
toolBar.setLayoutData(gd);
progressBar = new TestProgressBar(parent, SWT.BORDER);
gd = new GridData();
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
progressBar.setLayoutData(gd);
final SashForm sash = new SashForm(parent, SWT.NONE);
gd = new GridData();
gd.horizontalSpan = 2;
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
gd.verticalAlignment = SWT.FILL;
sash.setLayoutData(gd);
testTreeViewer = new TreeViewerBuilder(newArrayList("Test", "Status", "Duration"), new TestTreeViewerContentProvider()).setLinesVisible(false).setLabelProvider(new TestTreeViewerLabelProvider()).setColumnWeights(asList(5, 2, 1)).build(sash);
installToolTipSupport(testTreeViewer.getTree());
testTreeViewer.setInput(getViewSite());
stackTrace = new Text(sash, SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
sash.addControlListener(new ControlListener() {
@Override
public void controlResized(ControlEvent e) {
final Point size = parent.getSize();
final int orientation = size.x > size.y ? SWT.HORIZONTAL : SWT.VERTICAL;
if (orientation != sash.getOrientation()) {
sash.setOrientation(orientation);
}
}
@Override
public void controlMoved(ControlEvent e) {
// ignore
}
});
createActions();
hookContextMenu();
hookDoubleClickAction();
hookSingleClickAction();
contributeToActionBars();
refreshActions();
}
Aggregations