Search in sources :

Example 1 with XtceSubSystemNode

use of org.yamcs.studio.core.ui.XtceSubSystemNode in project yamcs-studio by yamcs.

the class AddToStackWizardPage1 method createControl.

@Override
public void createControl(Composite parent) {
    var composite = new Composite(parent, SWT.NONE);
    setControl(composite);
    var gl = new GridLayout();
    gl.marginHeight = 0;
    gl.marginWidth = 0;
    composite.setLayout(gl);
    // grid for expand+filter box
    var gl2 = new GridLayout(3, false);
    gl2.marginHeight = 0;
    gl2.marginWidth = 0;
    var row = new Composite(composite, SWT.NONE);
    row.setLayout(gl2);
    row.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    // add expand all / collapse all button
    var expandAll = new Button(row, SWT.ARROW | SWT.DOWN);
    var expandAllData = new GridData(SWT.NONE);
    expandAll.setLayoutData(expandAllData);
    expandAll.setText("Expand All");
    expandAll.setToolTipText("Expand All");
    expandAll.setVisible(false);
    expandAllData.exclude = true;
    var collapseAll = new Button(row, SWT.ARROW | SWT.RIGHT);
    var collapseAllData = new GridData(SWT.NONE);
    collapseAll.setLayoutData(collapseAllData);
    collapseAll.setText("Collapse All");
    collapseAll.setToolTipText("Collapse All");
    collapseAll.setVisible(true);
    // add filter box
    var searchbox = new Text(row, SWT.SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
    searchbox.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    expandAll.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            commandsTreeTable.expandAll();
            expandAll.setVisible(false);
            collapseAll.setVisible(true);
            expandAllData.exclude = true;
            collapseAllData.exclude = false;
            expandAll.pack();
            collapseAll.pack();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            commandsTreeTable.expandAll();
            expandAll.setVisible(false);
            collapseAll.setVisible(true);
            expandAllData.exclude = true;
            collapseAllData.exclude = false;
            expandAll.pack();
            collapseAll.pack();
        }
    });
    collapseAll.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            commandsTreeTable.collapseAll();
            expandAll.setVisible(true);
            collapseAll.setVisible(false);
            expandAllData.exclude = false;
            collapseAllData.exclude = true;
            expandAll.pack();
            collapseAll.pack();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            commandsTreeTable.collapseAll();
            expandAll.setVisible(true);
            collapseAll.setVisible(false);
            expandAllData.exclude = false;
            collapseAllData.exclude = true;
            expandAll.pack();
            collapseAll.pack();
        }
    });
    // build tree table
    ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources(), composite);
    level0Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level0s.png"));
    level1Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level1s.png"));
    level2Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level2s.png"));
    level3Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level3s.png"));
    level4Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level4s.png"));
    level5Image = resourceManager.createImage(RCPUtils.getImageDescriptor(AddToStackWizardPage1.class, "icons/level5s.png"));
    var treeWrapper = new Composite(composite, SWT.NONE);
    tcl = new TreeColumnLayout();
    var gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 800;
    gd.heightHint = 500;
    treeWrapper.setLayoutData(gd);
    treeWrapper.setLayout(tcl);
    commandsTreeTable = new TreeViewer(treeWrapper, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    commandsTreeTable.getTree().setHeaderVisible(true);
    commandsTreeTable.getTree().setLinesVisible(true);
    // column xtce path
    var pathColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    pathColumn.getColumn().setText(COL_PATH);
    pathColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof XtceSubSystemNode) {
                var node = (XtceSubSystemNode) element;
                return node.getName();
            } else {
                var node = (XtceCommandNode) element;
                return node.getCommandInfo().getName();
            }
        }
    });
    tcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(300));
    // column significance
    var significanceColumn = new TreeViewerColumn(commandsTreeTable, SWT.NONE);
    significanceColumn.getColumn().setText(COL_SIGN);
    significanceColumn.getColumn().setToolTipText("Significance Level");
    significanceColumn.getColumn().setAlignment(SWT.CENTER);
    significanceColumn.setLabelProvider(new CenteredImageLabelProvider() {

        @Override
        public Image getImage(Object element) {
            if (element instanceof XtceCommandNode) {
                var node = (XtceCommandNode) element;
                var cmd = node.getCommandInfo();
                if (cmd.getSignificance() == null) {
                    return level0Image;
                }
                switch(cmd.getSignificance().getConsequenceLevel()) {
                    case NONE:
                        return level0Image;
                    case WATCH:
                        return level1Image;
                    case WARNING:
                        return level2Image;
                    case DISTRESS:
                        return level3Image;
                    case CRITICAL:
                        return level4Image;
                    case SEVERE:
                        return level5Image;
                    default:
                        return null;
                }
            }
            return null;
        }
    });
    tcl.setColumnData(significanceColumn.getColumn(), new ColumnPixelData(50));
    // on item selection update significance message and page completion status
    commandsTreeTable.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            setMessage(null);
            return;
        }
        var selectedElement = sel.getFirstElement();
        if (selectedElement instanceof XtceCommandNode) {
            var cmd = ((XtceCommandNode) sel.getFirstElement()).getCommandInfo();
            // setMessage(getMessage(cmd));
            command.setMetaCommand(cmd);
            setPageComplete(true);
        } else {
            setPageComplete(false);
        }
    });
    var commandTreeContentProvider = new CommandTreeContentProvider();
    commandsTreeTable.setContentProvider(commandTreeContentProvider);
    commandsTreeTable.setInput(commandTreeContentProvider);
    YamcsPlugin.getMissionDatabase().getCommands().forEach(cmd -> {
        if (!cmd.hasAbstract() || !cmd.getAbstract()) {
            // add aliases columns
            for (var alias : cmd.getAliasList()) {
                var namespace = alias.getNamespace();
                if (!namespaces.contains(namespace) && !namespace.startsWith("/")) {
                    namespaces.add(namespace);
                    addAliasColumn(namespace);
                }
            }
            commandTreeContentProvider.addElement(cmd.getQualifiedName(), cmd);
        }
    });
    commandsTreeTable.expandAll();
    var filter = new CommandTreeViewerFilter(commandTreeContentProvider);
    commandsTreeTable.addFilter(filter);
    searchbox.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent ke) {
            if (ke.keyCode == SWT.ARROW_DOWN) {
                var items = commandsTreeTable.getTree().getItems();
                if (items.length > 0) {
                    IStructuredSelection sel = new StructuredSelection(items[0].getData());
                    commandsTreeTable.setSelection(sel);
                    commandsTreeTable.getTree().setFocus();
                }
            } else {
                filter.setSearchTerm(searchbox.getText());
                commandsTreeTable.refresh();
                commandsTreeTable.expandAll();
            }
        }
    });
    commandsTreeTable.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            String n1;
            String n2;
            if (o1 instanceof XtceSubSystemNode) {
                n1 = ((XtceSubSystemNode) o1).getName();
            } else {
                n1 = ((XtceCommandNode) o1).getCommandInfo().getQualifiedName();
            }
            if (o2 instanceof XtceSubSystemNode) {
                n2 = ((XtceSubSystemNode) o2).getName();
            } else {
                n2 = ((XtceCommandNode) o2).getCommandInfo().getQualifiedName();
            }
            return n1.compareTo(n2);
        }
    });
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) KeyAdapter(org.eclipse.swt.events.KeyAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) KeyEvent(org.eclipse.swt.events.KeyEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) XtceSubSystemNode(org.yamcs.studio.core.ui.XtceSubSystemNode) Composite(org.eclipse.swt.widgets.Composite) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) Text(org.eclipse.swt.widgets.Text) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) CenteredImageLabelProvider(org.yamcs.studio.core.utils.CenteredImageLabelProvider) GridData(org.eclipse.swt.layout.GridData) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)1 ResourceManager (org.eclipse.jface.resource.ResourceManager)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 Image (org.eclipse.swt.graphics.Image)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