Search in sources :

Example 1 with TreeViewerBuilder

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;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) URI(java.net.URI) TreeViewerBuilder(org.eclipse.n4js.ui.viewer.TreeViewerBuilder) Button(org.eclipse.swt.widgets.Button) ButtonFactoryUtil.createEnabledPushButton(org.eclipse.n4js.ui.preferences.external.ButtonFactoryUtil.createEnabledPushButton) ButtonFactoryUtil.createDisabledPushButton(org.eclipse.n4js.ui.preferences.external.ButtonFactoryUtil.createDisabledPushButton) Tree(org.eclipse.swt.widgets.Tree) DelegatingStyledCellLabelProvider(org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)

Example 2 with TreeViewerBuilder

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();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) TreeViewerBuilder(org.eclipse.n4js.ui.viewer.TreeViewerBuilder) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

TreeViewerBuilder (org.eclipse.n4js.ui.viewer.TreeViewerBuilder)2 URI (java.net.URI)1 DelegatingStyledCellLabelProvider (org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 ButtonFactoryUtil.createDisabledPushButton (org.eclipse.n4js.ui.preferences.external.ButtonFactoryUtil.createDisabledPushButton)1 ButtonFactoryUtil.createEnabledPushButton (org.eclipse.n4js.ui.preferences.external.ButtonFactoryUtil.createEnabledPushButton)1 SashForm (org.eclipse.swt.custom.SashForm)1 StyledText (org.eclipse.swt.custom.StyledText)1 ControlEvent (org.eclipse.swt.events.ControlEvent)1 ControlListener (org.eclipse.swt.events.ControlListener)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Text (org.eclipse.swt.widgets.Text)1 ToolBar (org.eclipse.swt.widgets.ToolBar)1 Tree (org.eclipse.swt.widgets.Tree)1