Example usage for org.eclipse.jface.viewers.deferred DeferredContentProvider DeferredContentProvider

List of usage examples for org.eclipse.jface.viewers.deferred DeferredContentProvider DeferredContentProvider

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers.deferred DeferredContentProvider DeferredContentProvider.

Prototype

public DeferredContentProvider(Comparator sortOrder) 

Source Link

Document

Create a DeferredContentProvider with the given sort order.

Usage

From source file:com.bdaum.zoom.ui.internal.dialogs.SetPersonDialog.java

License:Open Source License

@Override
protected Control createDialogArea(final Composite parent) {
    Composite area = (Composite) super.createDialogArea(parent);
    Composite composite = new Composite(area, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    composite.setLayout(new GridLayout());
    composite.setLayout(new GridLayout(2, false));
    viewer = new TableViewer(composite,
            SWT.BORDER | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.SINGLE | SWT.VIRTUAL);
    TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.NONE);
    col1.getColumn().setWidth(200);/*from  ww  w. jav  a  2  s .  c o  m*/
    col1.getColumn().setText(Messages.AlbumSelectionDialog_name);
    col1.setLabelProvider(new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof SmartCollectionImpl)
                return ((SmartCollectionImpl) element).getName();
            return element.toString();
        }

        public Image getImage(Object element) {
            if (element instanceof SmartCollectionImpl) {
                String id = ((SmartCollectionImpl) element).getStringId();
                Image face = faces.get(id);
                if (face == null)
                    faces.put(id, face = UiUtilities.getFace(getShell().getDisplay(),
                            (SmartCollectionImpl) element, 24, 4, parent.getBackground()));
                return face;
            }
            return null;
        }

        @Override
        protected Rectangle getIconBounds() {
            return Icons.person64.getImage().getBounds();
        }
    });
    TableViewerColumn col2 = new TableViewerColumn(viewer, SWT.NONE);
    col2.getColumn().setWidth(250);
    col2.getColumn().setText(Messages.AlbumSelectionDialog_description);
    col2.setLabelProvider(new ZColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof SmartCollectionImpl)
                return ((SmartCollectionImpl) element).getDescription();
            return element.toString();
        }
    });
    viewer.setContentProvider(new DeferredContentProvider(new Comparator<SmartCollection>() {
        @Override
        public int compare(SmartCollection e1, SmartCollection e2) {
            return e1.getName().compareTo(e2.getName());
        }
    }));
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.heightHint = 500;
    viewer.getControl().setLayoutData(layoutData);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (cntrlDwn) {
                SmartCollectionImpl sm = (SmartCollectionImpl) viewer.getStructuredSelection()
                        .getFirstElement();
                if (sm != null) {
                    CollectionEditDialog dialog = new CollectionEditDialog(getShell(), sm,
                            Messages.AlbumSelectionDialog_edit_person,
                            Messages.AlbumSelectionDialog_person_album_msg, false, true, false, false);
                    if (dialog.open() == Window.OK) {
                        final SmartCollectionImpl album = dialog.getResult();
                        if (album != null) {
                            Set<Object> toBeDeleted = new HashSet<Object>();
                            List<Object> toBeStored = new ArrayList<Object>();
                            Utilities.updateCollection(dbManager, sm, album, toBeDeleted, toBeStored);
                            dbManager.safeTransaction(toBeDeleted, toBeStored);
                        }
                        viewer.update(sm, null);
                    }
                }
                cntrlDwn = false;
            }
            validate();
        }
    });
    viewer.getControl().addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.CTRL)
                cntrlDwn = true;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.keyCode == SWT.CTRL)
                cntrlDwn = false;
        }
    });
    return area;
}

From source file:org.eclipse.ecf.internal.presence.ui.dialogs.ChatRoomSelectionDialog.java

License:Open Source License

protected Control createDialogArea(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout());
    main.setLayoutData(new GridData(GridData.FILL_BOTH));

    TableViewer viewer = new TableViewer(main,
            SWT.VIRTUAL | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    Table table = viewer.getTable();/*from  www .  j  ava2s.  c om*/

    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    TableColumn tc = new TableColumn(table, SWT.NONE);
    tc.setText(Messages.ChatRoomSelectionDialog_ROOM_NAME_COLUMN);
    //      tc.pack();
    //      int width = tc.getWidth();
    tc.setWidth(X_INITIAL_SIZE / 3);
    tc = new TableColumn(table, SWT.NONE);
    tc.setText(Messages.ChatRoomSelectionDialog_SUBJECT_COLUMN);
    tc.pack();
    int width;
    width = tc.getWidth();
    tc.setWidth(width + (width / 4));
    tc = new TableColumn(table, SWT.NONE);
    tc.setText(Messages.ChatRoomSelectionDialog_DESCRIPTION_COLUMN);
    tc.pack();
    width = tc.getWidth();
    tc.setWidth(width + (width / 4));
    tc = new TableColumn(table, SWT.NONE);
    tc.setText(Messages.ChatRoomSelectionDialog_MEMBERS_COLUMN);
    tc.pack();
    tc = new TableColumn(table, SWT.NONE);
    tc.setText(Messages.ChatRoomSelectionDialog_MODERATED_COLUMN);
    tc.pack();
    tc = new TableColumn(table, SWT.NONE);
    tc.setText(Messages.ChatRoomSelectionDialog_PERSISTENT_COLUMN);
    tc.pack();
    tc = new TableColumn(table, SWT.NONE);
    tc.setText(Messages.ChatRoomSelectionDialog_ACCOUNT_COLUMN);
    tc.pack();

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            IStructuredSelection ss = (IStructuredSelection) ((selection instanceof IStructuredSelection)
                    ? selection
                    : null);
            Object firstElement = (ss == null) ? null : ss.getFirstElement();
            if (!event.getSelection().isEmpty() && !loadingRoom.equals(firstElement)) {
                ChatRoomSelectionDialog.this.getButton(Window.OK).setEnabled(true);
            }
        }

    });

    viewer.setContentProvider(new DeferredContentProvider(new Comparator() {
        public int compare(Object r1, Object r2) {
            Room room1 = (Room) r1;
            Room room2 = (Room) r2;
            return room1.getRoomInfo().getName().compareTo(room2.getRoomInfo().getName());
        }
    }));
    viewer.setLabelProvider(new ChatRoomLabelProvider());

    rooms.addAll(Arrays.asList(new Room[] { loadingRoom }));

    viewer.setInput(rooms);

    this.setTitle(Messages.ChatRoomSelectionDialog_TITLE);
    this.setMessage(Messages.ChatRoomSelectionDialog_MESSAGE);

    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent e) {
            IStructuredSelection s = (IStructuredSelection) e.getSelection();
            Object o = s.getFirstElement();
            if (o instanceof Room) {
                selectedRoom = (Room) o;
            }
        }

    });

    viewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            if (selectedRoom != null) {
                ChatRoomSelectionDialog.this.okPressed();
            }
        }

    });

    startRetrieveJob();

    applyDialogFont(parent);
    return parent;
}

From source file:org.eclipse.jface.tests.viewers.interactive.ConcurrentTableTestView.java

License:Open Source License

@Override
public void createPartControl(Composite temp) {
    Composite parent = new Composite(temp, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;//from  w  w  w.j a  v a  2s.  co  m

    parent.setLayout(layout);

    // Create the table
    table = new TableViewer(parent, SWT.VIRTUAL);
    contentProvider = new DeferredContentProvider(comparator);
    table.setContentProvider(contentProvider);

    GridData data = new GridData(GridData.FILL_BOTH);
    table.getControl().setLayoutData(data);
    table.setInput(model);

    // Create the buttons
    Composite buttonBar = new Composite(parent, SWT.NONE);
    buttonBar.setLayoutData(new GridData(GridData.FILL_BOTH));
    GridLayout buttonBarLayout = new GridLayout();
    buttonBarLayout.numColumns = 1;
    buttonBar.setLayout(buttonBarLayout);
    updateCount = new Label(buttonBar, SWT.NONE);
    updateCount.setLayoutData(new GridData(GridData.FILL_BOTH));

    slowComparisons = new Button(buttonBar, SWT.CHECK);
    slowComparisons.setLayoutData(new GridData(GridData.FILL_BOTH));
    slowComparisons.setText("Slow comparisons");
    slowComparisons.setSelection(enableSlowComparisons);
    slowComparisons.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            enableSlowComparisons = slowComparisons.getSelection();
            super.widgetSelected(e);
        }
    });

    final Button limitSize = new Button(buttonBar, SWT.CHECK);
    limitSize.setLayoutData(new GridData(GridData.FILL_BOTH));
    limitSize.setText("Limit table size to 400");
    limitSize.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (limitSize.getSelection()) {
                contentProvider.setLimit(400);
            } else {
                contentProvider.setLimit(-1);
            }
            super.widgetSelected(e);
        }
    });

    Button resetCountButton = new Button(buttonBar, SWT.PUSH);
    resetCountButton.setLayoutData(new GridData(GridData.FILL_BOTH));
    resetCountButton.setText("Reset comparison count");
    resetCountButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            comparator.comparisons = 0;
            scheduleComparisonUpdate();
        }
    });

    Button testButton = new Button(buttonBar, SWT.PUSH);
    testButton.setLayoutData(new GridData(GridData.FILL_BOTH));
    testButton.setText("add 100000 elements");
    testButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            addRandomElements(100000);
        }
    });

    Button removeButton = new Button(buttonBar, SWT.PUSH);
    removeButton.setLayoutData(new GridData(GridData.FILL_BOTH));
    removeButton.setText("remove all");
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            clear();
        }
    });
}