Search in sources :

Example 6 with ViewerSorter

use of org.eclipse.jface.viewers.ViewerSorter in project bndtools by bndtools.

the class ResolutionFailurePanel method copyUnresolvedToClipboard.

//    private void switchFailureViewMode() {
//        Object input = unresolvedViewer.getInput();
//        unresolvedViewer.setInput(null);
//        setFailureViewMode();
//        unresolvedViewer.setInput(input);
//        unresolvedViewer.expandToLevel(2);
//    }
private void copyUnresolvedToClipboard() {
    StringBuilder builder = new StringBuilder();
    Object input = unresolvedViewer.getInput();
    if (input == null)
        return;
    ITreeContentProvider contentProvider = (ITreeContentProvider) unresolvedViewer.getContentProvider();
    Object[] roots = contentProvider.getElements(input);
    ViewerSorter sorter = unresolvedViewer.getSorter();
    if (sorter != null)
        Arrays.sort(roots, new SorterComparatorAdapter(unresolvedViewer, sorter));
    for (Object root : roots) {
        appendLabels(root, contentProvider, builder, 0);
    }
    /*
         * TODO if (result != null) { StringBuilder buffer = new StringBuilder(); List<Reason> unresolved =
         * result.getUnresolved(); if (unresolved != null) for (Iterator<Reason> iter = unresolved.iterator();
         * iter.hasNext(); ) { Reason reason = iter.next();
         * buffer.append(unresolvedLabelProvider.getLabel(reason.getRequirement ()).getString()); buffer.append('\t');
         * buffer.append(unresolvedLabelProvider .getLabel(reason.getResource())); if (iter.hasNext())
         * buffer.append('\n'); } }
         */
    Clipboard clipboard = new Clipboard(composite.getDisplay());
    TextTransfer transfer = TextTransfer.getInstance();
    clipboard.setContents(new Object[] { builder.toString() }, new Transfer[] { transfer });
    clipboard.dispose();
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Clipboard(org.eclipse.swt.dnd.Clipboard) SorterComparatorAdapter(bndtools.model.obr.SorterComparatorAdapter) TextTransfer(org.eclipse.swt.dnd.TextTransfer)

Example 7 with ViewerSorter

use of org.eclipse.jface.viewers.ViewerSorter in project bndtools by bndtools.

the class ResolutionFailurePanel method appendLabels.

private void appendLabels(Object unresolvedTreeElem, ITreeContentProvider contentProvider, StringBuilder builder, int indent) {
    for (int i = 0; i < indent; i++) builder.append("..");
    //        builder.append(getClipboardContent(unresolvedTreeElem)).append('\n');
    Object[] children = contentProvider.getChildren(unresolvedTreeElem);
    if (children == null)
        return;
    ViewerSorter sorter = unresolvedViewer.getSorter();
    if (sorter != null)
        Arrays.sort(children, new SorterComparatorAdapter(unresolvedViewer, sorter));
    for (Object child : children) {
        appendLabels(child, contentProvider, builder, indent + 1);
    }
}
Also used : ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SorterComparatorAdapter(bndtools.model.obr.SorterComparatorAdapter)

Example 8 with ViewerSorter

use of org.eclipse.jface.viewers.ViewerSorter in project bndtools by bndtools.

the class PackageInfoDialog method createDialogArea.

/**
     * Create contents of the dialog.
     *
     * @param parent
     */
@SuppressWarnings("unused")
@Override
protected Control createDialogArea(Composite parent) {
    setMessage(Messages.PackageInfoDialog_Message);
    setTitle(Messages.PackageInfoDialog_Title);
    Composite container = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 10;
    layout.marginWidth = 10;
    composite.setLayout(layout);
    table = new Table(composite, SWT.BORDER | SWT.CHECK | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    GridData gd_table = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 2);
    gd_table.heightHint = 100;
    table.setLayoutData(gd_table);
    table.setLinesVisible(true);
    TableColumn tblclmnPackage = new TableColumn(table, SWT.NONE);
    tblclmnPackage.setWidth(267);
    tblclmnPackage.setText(Messages.PackageInfoDialog_ExportedPackage);
    TableColumn tblclmnVersion = new TableColumn(table, SWT.NONE);
    tblclmnVersion.setWidth(77);
    tblclmnVersion.setText(Messages.PackageInfoDialog_Version);
    Button btnCheckAll = new Button(composite, SWT.NONE);
    btnCheckAll.setText(Messages.PackageInfoDialog_btnCheckAll_text);
    btnCheckAll.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
    btnCheckAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selection.clear();
            selection.addAll(packages);
            viewer.setCheckedElements(selection.toArray());
            validate();
        }
    });
    Button btnUncheckAll = new Button(composite, SWT.NONE);
    btnUncheckAll.setText(Messages.PackageInfoDialog_btnUncheckAll_text_1);
    btnUncheckAll.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false, 1, 1));
    btnUncheckAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            selection.clear();
            viewer.setCheckedElements(selection.toArray());
            validate();
        }
    });
    final Button btnAlwaysGenerate = new Button(composite, SWT.CHECK);
    btnAlwaysGenerate.setText(Messages.PackageInfoDialog_AlwaysGenerate);
    viewer = new CheckboxTableViewer(table);
    TableViewerColumn tblViewerClmnPackage = new TableViewerColumn(viewer, tblclmnPackage);
    tblViewerClmnPackage.setLabelProvider(new PackageNameLabelProvider(table.getDisplay()));
    TableViewerColumn tblViewerClmnVersion = new TableViewerColumn(viewer, tblclmnVersion);
    tblViewerClmnVersion.setLabelProvider(new PackageVersionLabelProvider());
    tblViewerClmnVersion.setEditingSupport(new VersionEditingSupport(viewer));
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    viewer.setSorter(new ViewerSorter() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            FileVersionTuple f1 = (FileVersionTuple) e1;
            FileVersionTuple f2 = (FileVersionTuple) e2;
            return f1.compareTo(f2);
        }
    });
    viewer.setInput(packages);
    viewer.setCheckedElements(selection.toArray());
    new Label(composite, SWT.NONE);
    btnAlwaysGenerate.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            dontAsk = btnAlwaysGenerate.getSelection();
        }
    });
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            FileVersionTuple pkg = (FileVersionTuple) event.getElement();
            if (event.getChecked())
                selection.add(pkg);
            else
                selection.remove(pkg);
            validate();
        }
    });
    return container;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Label(org.eclipse.swt.widgets.Label) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Viewer(org.eclipse.jface.viewers.Viewer) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 9 with ViewerSorter

use of org.eclipse.jface.viewers.ViewerSorter in project bndtools by bndtools.

the class WorkspacePreviewPage method createControl.

@Override
public void createControl(Composite parent) {
    setTitle("Preview Changes");
    //$NON-NLS-1$
    setImageDescriptor(Plugin.imageDescriptorFromPlugin("icons/bndtools-wizban.png"));
    imgAdded = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/incoming.gif").createImage(parent.getDisplay());
    imgOverwrite = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/conflict.gif").createImage(parent.getDisplay());
    imgError = AbstractUIPlugin.imageDescriptorFromPlugin(Plugin.PLUGIN_ID, "icons/error_obj.gif").createImage(parent.getDisplay());
    int columns = 4;
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(columns, false);
    composite.setLayout(layout);
    setControl(composite);
    Label lblTitle = new Label(composite, SWT.NONE);
    lblTitle.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, columns, 1));
    // Table
    tblOutputs = new Table(composite, SWT.BORDER | SWT.CHECK);
    tblOutputs.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, columns, 1));
    vwrOutputs = new CheckboxTableViewer(tblOutputs);
    vwrOutputs.setContentProvider(ArrayContentProvider.getInstance());
    vwrOutputs.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            StyledString label;
            Image icon;
            String path = (String) cell.getElement();
            String error = resourceErrors.get(path);
            if (error != null) {
                label = new StyledString(path, ItalicStyler.INSTANCE_ERROR);
                icon = imgError;
            } else {
                label = new StyledString(path);
                icon = existingFiles.contains(path) ? imgOverwrite : imgAdded;
            }
            cell.setText(path);
            cell.setStyleRanges(label.getStyleRanges());
            cell.setImage(icon);
        }
    });
    vwrOutputs.setSorter(new ViewerSorter(Collator.getInstance()));
    // Details display
    final Label lblDetails = new Label(composite, SWT.NONE);
    lblDetails.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, columns, 1));
    lblDetails.setText(MSG_NOTHING_SELECTED);
    // Button Panel
    Label spacer1 = new Label(composite, SWT.NONE);
    spacer1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Button btnSelectNonConflict = new Button(composite, SWT.PUSH);
    btnSelectNonConflict.setText("Select Non-Conflicting");
    btnSelectNonConflict.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            modifyLock.modifyOperation(new Runnable() {

                @Override
                public void run() {
                    checkedPaths.clear();
                    for (Entry<String, Resource> entry : templateOutputs.entries()) {
                        String path = entry.getKey();
                        if (!existingFiles.contains(path))
                            checkedPaths.add(path);
                    }
                    vwrOutputs.setCheckedElements(checkedPaths.toArray());
                }
            });
        }
    });
    Button btnSelectAll = new Button(composite, SWT.PUSH);
    btnSelectAll.setText("Select All");
    btnSelectAll.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            vwrOutputs.setAllChecked(true);
        }
    });
    Button btnSelectNone = new Button(composite, SWT.PUSH);
    btnSelectNone.setText("Select None");
    btnSelectNone.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            vwrOutputs.setAllChecked(false);
        }
    });
    // Listeners
    vwrOutputs.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) vwrOutputs.getSelection();
            if (sel.isEmpty()) {
                lblDetails.setText(MSG_NOTHING_SELECTED);
            } else {
                String path = (String) sel.getFirstElement();
                String resourceError = resourceErrors.get(path);
                if (resourceError != null) {
                    lblDetails.setText(resourceError);
                } else if (existingFiles.contains(path)) {
                    lblDetails.setText("This file already exists and will be overwritten");
                } else {
                    lblDetails.setText("This file will be created");
                }
            }
        }
    });
    vwrOutputs.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(final CheckStateChangedEvent event) {
            modifyLock.ifNotModifying(new Runnable() {

                @Override
                public void run() {
                    final String updatedPath = (String) event.getElement();
                    if (event.getChecked()) {
                        checkedPaths.add(updatedPath);
                        // Check any directories that are parents of this path
                        modifyLock.modifyOperation(new Runnable() {

                            @Override
                            public void run() {
                                for (Entry<String, Resource> entry : templateOutputs.entries()) {
                                    String path = entry.getKey();
                                    if (path.endsWith("/") && updatedPath.startsWith(path)) {
                                        checkedPaths.add(path);
                                        vwrOutputs.setChecked(path, true);
                                    }
                                }
                            }
                        });
                    } else {
                        checkedPaths.remove(updatedPath);
                        // Uncheck any paths that are descendants of this path
                        if (updatedPath.endsWith("/")) {
                            modifyLock.modifyOperation(new Runnable() {

                                @Override
                                public void run() {
                                    for (Entry<String, Resource> entry : templateOutputs.entries()) {
                                        String path = entry.getKey();
                                        if (path.startsWith(updatedPath)) {
                                            checkedPaths.remove(path);
                                            vwrOutputs.setChecked(path, false);
                                        }
                                    }
                                }
                            });
                        }
                    }
                }
            });
        }
    });
}
Also used : CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) Label(org.eclipse.swt.widgets.Label) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Resource(org.bndtools.templating.Resource) StyledString(org.eclipse.jface.viewers.StyledString) ViewerCell(org.eclipse.jface.viewers.ViewerCell) GridData(org.eclipse.swt.layout.GridData) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 10 with ViewerSorter

use of org.eclipse.jface.viewers.ViewerSorter in project ACS by ACS-Community.

the class LostSourcesPart method createPartControl.

public void createPartControl(Composite parent) {
    listViewer = new ListViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    listViewer.setContentProvider(LostSourcesContainer.getInstance());
    listViewer.setSorter(new ViewerSorter());
    listViewer.setInput(null);
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter)

Aggregations

ViewerSorter (org.eclipse.jface.viewers.ViewerSorter)11 GridData (org.eclipse.swt.layout.GridData)6 Composite (org.eclipse.swt.widgets.Composite)6 Label (org.eclipse.swt.widgets.Label)6 Viewer (org.eclipse.jface.viewers.Viewer)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 TableViewer (org.eclipse.jface.viewers.TableViewer)4 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 Image (org.eclipse.swt.graphics.Image)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Button (org.eclipse.swt.widgets.Button)3 Table (org.eclipse.swt.widgets.Table)3 TableColumn (org.eclipse.swt.widgets.TableColumn)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 SorterComparatorAdapter (bndtools.model.obr.SorterComparatorAdapter)2 IMenuListener (org.eclipse.jface.action.IMenuListener)2 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)2 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)2 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)2