Search in sources :

Example 46 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project yamcs-studio by yamcs.

the class AddParameterPage 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;
    gl.numColumns = 2;
    gl.makeColumnsEqualWidth = false;
    composite.setLayout(gl);
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    var tableWrapper1 = new Composite(composite, SWT.NONE);
    contentProvider = new ParameterContentProvider();
    trcl = new TreeColumnLayout();
    tableWrapper1.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper1.setLayout(trcl);
    treeViewer = new TreeViewer(tableWrapper1, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    treeViewer.getTree().setHeaderVisible(true);
    treeViewer.getTree().setLinesVisible(true);
    // column container
    var pathColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
    pathColumn.getColumn().setText(COL_NAMESPACE);
    pathColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var namespace = (String) element;
            return namespace.substring(namespace.lastIndexOf("/") + 1);
        }
    });
    trcl.setColumnData(pathColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    treeViewer.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            contentProvider.setNamespace(null);
            return;
        }
        contentProvider.setNamespace((String) sel.getFirstElement());
    });
    treeViewer.setContentProvider(new NamespaceContentProvider());
    treeViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            var n1 = (String) o1;
            var n2 = (String) o2;
            return n1.compareTo(n2);
        }
    });
    var tableWrapper2 = new Composite(composite, SWT.NONE);
    tcl = new TableColumnLayout();
    tableWrapper2.setLayoutData(new GridData(GridData.FILL_BOTH));
    tableWrapper2.setLayout(tcl);
    tableViewer = new TableViewer(tableWrapper2, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    tableViewer.getTable().setHeaderVisible(true);
    tableViewer.getTable().setLinesVisible(true);
    var nameColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    nameColumn.getColumn().setText(COL_NAME);
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var obj = (ParameterInfo) element;
            return obj.getQualifiedName();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(COLUMN_WIDTH));
    tableViewer.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.isEmpty()) {
            setParameter(new ArrayList<>());
            return;
        }
        var parameters = new ArrayList<ParameterInfo>();
        for (var obj : sel.toArray()) {
            parameters.add((ParameterInfo) obj);
        }
        setParameter(parameters);
        setPageComplete(true);
    });
    tableViewer.setContentProvider(contentProvider);
    tableViewer.setInput(contentProvider);
    YamcsPlugin.getMissionDatabase().getParameters().forEach(pmtr -> {
        for (var alias : pmtr.getAliasList()) {
            var namespace = alias.getNamespace();
            if (!namespace.startsWith("/")) {
                return;
            }
            if (!parameterInfos.containsKey(namespace)) {
                parameterInfos.put(namespace, new ArrayList<>());
            }
            parameterInfos.get(namespace).add(pmtr);
            var parentns = namespace.substring(0, namespace.lastIndexOf("/"));
            while (!parentns.isEmpty()) {
                if (!parameterInfos.containsKey(parentns)) {
                    parameterInfos.put(parentns, new ArrayList<>());
                }
                parentns = parentns.substring(0, parentns.lastIndexOf("/"));
            }
        }
    });
    treeViewer.setInput(parameterInfos.keySet());
    tableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            var n1 = (ParameterInfo) o1;
            var n2 = (ParameterInfo) o2;
            return n1.getQualifiedName().compareTo(n2.getQualifiedName());
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) ArrayList(java.util.ArrayList) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 47 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator 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)

Example 48 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project yamcs-studio by yamcs.

the class ConnectionsDialog method createServerPanel.

private Composite createServerPanel(Composite parent, ResourceManager resourceManager) {
    var serverPanel = new Composite(parent, SWT.NONE);
    var gd = new GridData(GridData.FILL_BOTH);
    serverPanel.setLayoutData(gd);
    var tcl = new TableColumnLayout();
    serverPanel.setLayout(tcl);
    var serverImage = resourceManager.createImage(getImageDescriptor(ConnectionsDialog.class, "icons/obj16/server.gif"));
    connViewer = new TableViewer(serverPanel, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    connViewer.getTable().setHeaderVisible(true);
    connViewer.getTable().setLinesVisible(true);
    var urlColumn = new TableViewerColumn(connViewer, SWT.NONE);
    urlColumn.getColumn().setText("Server URL");
    urlColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public Image getImage(Object element) {
            return serverImage;
        }

        @Override
        public String getText(Object element) {
            var conf = (YamcsConfiguration) element;
            return conf.getURL();
        }
    });
    tcl.setColumnData(urlColumn.getColumn(), new ColumnPixelData(200));
    var instanceColumn = new TableViewerColumn(connViewer, SWT.NONE);
    instanceColumn.getColumn().setText("Instance");
    instanceColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var conf = (YamcsConfiguration) element;
            return conf.getInstance();
        }
    });
    tcl.setColumnData(instanceColumn.getColumn(), new ColumnPixelData(90));
    var userColumn = new TableViewerColumn(connViewer, SWT.NONE);
    userColumn.getColumn().setText("User");
    userColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var conf = (YamcsConfiguration) element;
            if (conf.getAuthType() != AuthType.KERBEROS) {
                return conf.getUser();
            } else {
                return null;
            }
        }
    });
    tcl.setColumnData(userColumn.getColumn(), new ColumnPixelData(90));
    var nameColumn = new TableViewerColumn(connViewer, SWT.NONE);
    nameColumn.getColumn().setText("Comment");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            var conf = (YamcsConfiguration) element;
            return conf.getComment();
        }
    });
    tcl.setColumnData(nameColumn.getColumn(), new ColumnPixelData(200));
    IContentProvider contentProvider = (IStructuredContentProvider) inputElement -> connections.toArray();
    connViewer.setContentProvider(contentProvider);
    connViewer.setInput(contentProvider);
    connViewer.addSelectionChangedListener(evt -> {
        var sel = (IStructuredSelection) evt.getSelection();
        if (sel.getFirstElement() != null) {
            var conf = (YamcsConfiguration) sel.getFirstElement();
            yamcsInstanceText.setText(forceString(conf.getInstance()));
            yamcsURLText.setText(forceString(conf.getURL()));
            // / caCertFileText.setText(forceString(conf.getCaCertFile()));
            commentText.setText(forceString(conf.getComment()));
            var authType = (conf.getAuthType() == null) ? AuthType.STANDARD : conf.getAuthType();
            if (authType == AuthType.STANDARD) {
                authTypeCombo.select(0);
                yamcsUserText.setText(forceString(conf.getUser()));
            } else if (authType == AuthType.KERBEROS) {
                authTypeCombo.select(1);
                yamcsUserText.setText("");
            } else {
                throw new IllegalArgumentException("Unexpected auth type " + authType);
            }
            updateState();
        }
    });
    connViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            var c1 = (YamcsConfiguration) o1;
            var c2 = (YamcsConfiguration) o2;
            if (c1.getURL() != null && c2.getURL() != null) {
                return c1.getURL().compareTo(c2.getURL());
            } else {
                return 0;
            }
        }
    });
    return serverPanel;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IContentProvider(org.eclipse.jface.viewers.IContentProvider) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 49 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project hale by halestudio.

the class InstanceValidationReportDetailsPage method createControls.

/**
 * @see CustomReportDetailsPage#createControls(Composite)
 */
@Override
public Control createControls(Composite parent) {
    // filtered tree sets itself GridData, so set layout to gridlayout
    parent.setLayout(GridLayoutFactory.fillDefaults().create());
    // create pattern filter for FilteredTree
    PatternFilter filter = new TreePathPatternFilter();
    filter.setIncludeLeadingWildcard(true);
    // create FilteredTree
    FilteredTree filteredTree = new TreePathFilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, filter, true);
    treeViewer = filteredTree.getViewer();
    // set content provider
    contentProvider = new InstanceValidationReportDetailsContentProvider();
    treeViewer.setContentProvider(contentProvider);
    // set label provider
    treeViewer.setLabelProvider(new InstanceValidationReportDetailsLabelProvider(contentProvider));
    // set comparator
    treeViewer.setComparator(new ViewerComparator() {

        /**
         * @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
         */
        @Override
        public int category(Object element) {
            if (element instanceof QName || element instanceof Definition<?>)
                // Path
                return 0;
            else if (element instanceof String)
                // Category
                return 1;
            else
                // InstanceValidationMessage
                return 2;
        }
    });
    // add menu on right-click
    MenuManager menuMgr = new MenuManager();
    Menu menu = menuMgr.createContextMenu(treeViewer.getTree());
    menuMgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            if (getValidSelection() == null)
                return;
            // selection is valid, offer link to transformed data view
            manager.add(new ShowExampleAction());
        }
    });
    // remove previous menus
    menuMgr.setRemoveAllWhenShown(true);
    // add menu to tree
    treeViewer.getTree().setMenu(menu);
    treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            showSelectionInDataView();
        }
    });
    Image noReportBaseImage = InstanceValidationUIPlugin.getDefault().getImageRegistry().get(InstanceValidationUIPlugin.IMG_INSTANCE_VALIDATION);
    reportImage = new DecorationOverlayIcon(noReportBaseImage, PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_DEC_FIELD_WARNING), IDecoration.BOTTOM_LEFT).createImage();
    return filteredTree;
}
Also used : DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) PatternFilter(org.eclipse.ui.dialogs.PatternFilter) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) QName(javax.xml.namespace.QName) Definition(eu.esdihumboldt.hale.common.schema.model.Definition) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) TreePathFilteredTree(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathFilteredTree) Image(org.eclipse.swt.graphics.Image) IMenuListener(org.eclipse.jface.action.IMenuListener) TreePathPatternFilter(eu.esdihumboldt.hale.ui.util.viewer.tree.TreePathPatternFilter) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) IMenuManager(org.eclipse.jface.action.IMenuManager)

Example 50 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project hale by halestudio.

the class ReportList method createViewControl.

/**
 * Create contents of the view part.
 *
 * @param parent parent element
 */
@Override
public void createViewControl(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    TreeColumnLayout layout = new TreeColumnLayout();
    composite.setLayout(layout);
    {
        _treeViewer = new TreeViewer(composite, SWT.BORDER);
        final Tree tree = _treeViewer.getTree();
        tree.setHeaderVisible(false);
        tree.setLinesVisible(false);
        // create column for reports
        TreeViewerColumn col1 = new TreeViewerColumn(_treeViewer, SWT.NONE);
        // add the label provider
        col1.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelProvider()));
        // and layout
        layout.setColumnData(col1.getColumn(), new ColumnWeightData(3));
        // create column for reports
        TreeViewerColumn col2 = new TreeViewerColumn(_treeViewer, SWT.NONE);
        // add the label provider
        col2.setLabelProvider(new TreeColumnViewerLabelProvider(new ReportListLabelDateProvider()));
        // create column for reports
        layout.setColumnData(col2.getColumn(), new ColumnWeightData(1));
        new ReportListMenu(getSite(), _treeViewer);
    }
    createActions();
    initializeToolBar();
    initializeMenu();
    // set label provider
    // _treeViewer.setLabelProvider(new ReportListLabelProvider());
    // set content provider
    _treeViewer.setContentProvider(new ReportListContentProvider());
    // disable this if it uses too much memory
    // but should maintain the list much faster
    _treeViewer.setUseHashlookup(true);
    // order the sessions from latest to oldest
    _treeViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof ReportSession && e2 instanceof ReportSession) {
                long first = ((ReportSession) e1).getId();
                long second = ((ReportSession) e2).getId();
                if (first > second) {
                    return -1;
                } else if (first < second) {
                    return 1;
                } else {
                    return 0;
                }
            } else if (e1 instanceof Report<?> && e2 instanceof Report<?>) {
                Report<?> first = (Report<?>) e1;
                Report<?> second = (Report<?>) e2;
                if (first.getStartTime() == null && second.getStartTime() == null) {
                    return 0;
                } else if (first.getStartTime() == null) {
                    return 1;
                } else if (second.getStartTime() == null) {
                    return -1;
                } else if (first.getStartTime().getTime() > second.getStartTime().getTime()) {
                    return -1;
                } else if (first.getStartTime().getTime() < second.getStartTime().getTime()) {
                    return 1;
                } else {
                    return 0;
                }
            }
            return 0;
        }
    });
    // set selection provider
    getSite().setSelectionProvider(_treeViewer);
    _treeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            OpenPropertiesHandler.unpinAndOpenPropertiesView(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
        }
    });
    // load all added reports
    this.loadReports();
}
Also used : TreeColumnViewerLabelProvider(org.eclipse.jface.viewers.TreeColumnViewerLabelProvider) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) Report(eu.esdihumboldt.hale.common.core.report.Report) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Tree(org.eclipse.swt.widgets.Tree) ReportSession(eu.esdihumboldt.hale.common.core.report.ReportSession)

Aggregations

ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)110 Viewer (org.eclipse.jface.viewers.Viewer)64 Composite (org.eclipse.swt.widgets.Composite)59 TableViewer (org.eclipse.jface.viewers.TableViewer)50 GridData (org.eclipse.swt.layout.GridData)50 GridLayout (org.eclipse.swt.layout.GridLayout)34 Label (org.eclipse.swt.widgets.Label)29 LabelProvider (org.eclipse.jface.viewers.LabelProvider)23 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)18 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)17 Button (org.eclipse.swt.widgets.Button)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)15 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)15