Example usage for org.eclipse.jface.viewers TableViewer add

List of usage examples for org.eclipse.jface.viewers TableViewer add

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TableViewer add.

Prototype

public void add(Object[] elements) 

Source Link

Document

Adds the given elements to this table viewer.

Usage

From source file:org.drools.eclipse.flow.common.editor.editpart.work.HumanTaskCustomEditor.java

License:Apache License

private void createNotificationTab(TabFolder tabFolder) {
    Work work = (Work) getValue();/*  www.java2  s  .  com*/

    String notStartedNotify = (String) work.getParameter("NotStartedNotify");
    String notCompletedNotify = (String) work.getParameter("NotCompletedNotify");

    if (notStartedNotify != null) {
        String[] notifies = notStartedNotify.split(COMPONENT_SEPARATOR_ESCAPED);

        for (String notification : notifies) {
            if (notification != null && notification.length() > 0) {
                notifications.add(new Notification(notification, "not-started"));
            }
        }
    }

    if (notCompletedNotify != null) {
        String[] notifies = notCompletedNotify.split(COMPONENT_SEPARATOR_ESCAPED);

        for (String notification : notifies) {
            if (notification != null && notification.length() > 0) {
                notifications.add(new Notification(notification, "not-completed"));
            }
        }
    }

    final TabItem headersTabItem = new TabItem(tabFolder, SWT.NONE);
    headersTabItem.setText("Notifications");

    final Composite container = new Composite(tabFolder, SWT.NONE);
    final GridLayout gridLayout = new GridLayout();
    gridLayout.horizontalSpacing = 2;
    container.setLayout(gridLayout);
    headersTabItem.setControl(container);

    final TableViewer tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION);

    TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
    column.setLabelProvider(new NotificationsLabelProvider());
    column.setEditingSupport(new NotificationsEditing(tableViewer));
    column.getColumn().setText("Notifications");
    column.getColumn().setWidth(400);
    column.getColumn().setMoveable(true);

    final Label typeLabel = new Label(container, SWT.NONE);
    typeLabel.setLayoutData(new GridData());
    typeLabel.setText("Type");

    notifyTypeText = new Combo(container, SWT.NONE);
    notifyTypeText.add("not-started");
    notifyTypeText.add("not-completed");
    notifyTypeText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final Label expiresAtLabel = new Label(container, SWT.NONE);
    expiresAtLabel.setLayoutData(new GridData());
    expiresAtLabel.setText("ExpiresAt");

    notifyExpiresAtText = new Text(container, SWT.NONE);
    notifyExpiresAtText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final Label notifyFromLabel = new Label(container, SWT.NONE);
    notifyFromLabel.setLayoutData(new GridData());
    notifyFromLabel.setText("From");

    notifyFromText = new Text(container, SWT.NONE);
    notifyFromText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final Label notifyToLabel = new Label(container, SWT.NONE);
    notifyToLabel.setText("To Users");

    notifyToText = new Text(container, SWT.NONE);
    notifyToText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final Label notifyToGroupsLabel = new Label(container, SWT.NONE);
    notifyToGroupsLabel.setText("To Groups");

    notifyToGroupsText = new Text(container, SWT.NONE);
    notifyToGroupsText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final Label notifyReplyToLabel = new Label(container, SWT.NONE);
    notifyReplyToLabel.setText("Reply To");

    notifyReplyToText = new Text(container, SWT.NONE);
    notifyReplyToText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final Label subjectLabel = new Label(container, SWT.NONE);
    subjectLabel.setLayoutData(new GridData());
    subjectLabel.setText("Subject");

    notifySubjectText = new Text(container, SWT.NONE);
    notifySubjectText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    final Label bodyLabel = new Label(container, SWT.NONE);
    bodyLabel.setText("Body");

    notifyBodyText = new Text(container, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL);
    final GridData gd_bodyText = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gd_bodyText.heightHint = 100;
    notifyBodyText.setLayoutData(gd_bodyText);

    final Table table = tableViewer.getTable();
    final GridData gd_table = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1);
    gd_table.heightHint = 100;
    table.setLayoutData(gd_table);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);

    table.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items != null && items.length > 0) {
                int index = notifications.indexOf((Notification) items[0].getData());
                Notification notification = notifications.get(index);

                notifyFromText.setText(notification.getFrom());
                notifyToText.setText(notification.getTo());
                notifyToGroupsText.setText(notification.getToGroups());
                notifyReplyToText.setText(notification.getReplyTo());
                notifySubjectText.setText(notification.getSubject());
                notifyBodyText.setText(notification.getBody());
                notifyTypeText.setText(notification.getType());
                notifyExpiresAtText.setText(notification.getExpiresAt());
            } else {
                notifyFromText.setText("");
                notifyToText.setText("");
                notifyToGroupsText.setText("");
                notifyReplyToText.setText("");
                notifySubjectText.setText("");
                notifyBodyText.setText("");
                notifyTypeText.setText("");
                notifyExpiresAtText.setText("");
            }

        }

        public void widgetDefaultSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items != null && items.length > 0) {
                int index = notifications.indexOf((Notification) items[0].getData());
                Notification notification = notifications.get(index);

                notifyFromText.setText(notification.getFrom());
                notifyToText.setText(notification.getTo());
                notifyToGroupsText.setText(notification.getToGroups());
                notifyReplyToText.setText(notification.getReplyTo());
                notifySubjectText.setText(notification.getSubject());
                notifyBodyText.setText(notification.getBody());
                notifyTypeText.setText(notification.getType());
                notifyExpiresAtText.setText(notification.getExpiresAt());
            } else {
                notifyFromText.setText("");
                notifyToText.setText("");
                notifyToGroupsText.setText("");
                notifyReplyToText.setText("");
                notifySubjectText.setText("");
                notifyBodyText.setText("");
                notifyTypeText.setText("");
                notifyExpiresAtText.setText("");
            }
        }
    });

    tableViewer.setContentProvider(new NotificationsContentProvider());
    tableViewer.setInput(notifications);
    // add/delete buttons
    final Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    composite.setLayout(new RowLayout());
    final Button addButton = new Button(composite, SWT.NONE);
    addButton.setText("Add");
    addButton.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
            Notification notification = new Notification();
            notification.setFrom(notifyFromText.getText());
            notification.setTo(notifyToText.getText());
            notification.setToGroups(notifyToGroupsText.getText());
            notification.setReplyTo(notifyReplyToText.getText());
            notification.setSubject(notifySubjectText.getText());
            notification.setBody(notifyBodyText.getText());
            notification.setType(notifyTypeText.getText());
            notification.setExpiresAt(notifyExpiresAtText.getText());
            notifications.add(notification);
            tableViewer.add(notification);
            tableViewer.refresh();
            // clear fields after add operation
            notifyFromText.setText("");
            notifyToText.setText("");
            notifyToGroupsText.setText("");
            notifyReplyToText.setText("");
            notifySubjectText.setText("");
            notifyBodyText.setText("");
            notifyTypeText.setText("");
            notifyExpiresAtText.setText("");

        }

        public void widgetSelected(SelectionEvent e) {
            Notification notification = new Notification();
            notification.setFrom(notifyFromText.getText());
            notification.setTo(notifyToText.getText());
            notification.setToGroups(notifyToGroupsText.getText());
            notification.setReplyTo(notifyReplyToText.getText());
            notification.setSubject(notifySubjectText.getText());
            notification.setBody(notifyBodyText.getText());
            notification.setType(notifyTypeText.getText());
            notification.setExpiresAt(notifyExpiresAtText.getText());
            notifications.add(notification);
            tableViewer.add(notification);
            tableViewer.refresh();
            // clear fields after add operation
            notifyFromText.setText("");
            notifyToText.setText("");
            notifyToGroupsText.setText("");
            notifyReplyToText.setText("");
            notifySubjectText.setText("");
            notifyBodyText.setText("");
            notifyTypeText.setText("");
            notifyExpiresAtText.setText("");
        }
    });
    final Button deleteButton = new Button(composite, SWT.NONE);
    deleteButton.setText("Remove");
    deleteButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            TableItem[] items = table.getSelection();
            if (items != null && items.length > 0) {
                notifications.remove((Notification) items[0].getData());
                tableViewer.remove(items[0]);
                tableViewer.refresh();
            }
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            TableItem[] items = table.getSelection();
            if (items != null && items.length > 0) {
                notifications.remove((Notification) items[0].getData());
                tableViewer.remove(items[0]);
                tableViewer.refresh();
            }
        }
    });

    final Button updateButton = new Button(composite, SWT.NONE);
    updateButton.setText("Update");
    updateButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            TableItem[] items = table.getSelection();
            if (items != null && items.length > 0) {
                int index = notifications.indexOf((Notification) items[0].getData());
                Notification notification = notifications.get(index);
                notification.setFrom(notifyFromText.getText());
                notification.setTo(notifyToText.getText());
                notification.setToGroups(notifyToGroupsText.getText());
                notification.setReplyTo(notifyReplyToText.getText());
                notification.setSubject(notifySubjectText.getText());
                notification.setBody(notifyBodyText.getText());
                notification.setType(notifyTypeText.getText());
                notification.setExpiresAt(notifyExpiresAtText.getText());
                tableViewer.refresh();
                // clear fields after add operation
                notifyFromText.setText("");
                notifyToText.setText("");
                notifyToGroupsText.setText("");
                notifyReplyToText.setText("");
                notifySubjectText.setText("");
                notifyBodyText.setText("");
                notifyTypeText.setText("");
                notifyExpiresAtText.setText("");
            }
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            TableItem[] items = table.getSelection();
            if (items != null && items.length > 0) {
                int index = notifications.indexOf((Notification) items[0].getData());
                Notification notification = notifications.get(index);
                notification.setFrom(notifyFromText.getText());
                notification.setTo(notifyToText.getText());
                notification.setToGroups(notifyToGroupsText.getText());
                notification.setReplyTo(notifyReplyToText.getText());
                notification.setSubject(notifySubjectText.getText());
                notification.setBody(notifyBodyText.getText());
                notification.setType(notifyTypeText.getText());
                notification.setExpiresAt(notifyExpiresAtText.getText());
                tableViewer.refresh();
                // clear fields after add operation
                notifyFromText.setText("");
                notifyToText.setText("");
                notifyToGroupsText.setText("");
                notifyReplyToText.setText("");
                notifySubjectText.setText("");
                notifyBodyText.setText("");
                notifyTypeText.setText("");
                notifyExpiresAtText.setText("");
            }
        }
    });

    final Button clearButton = new Button(composite, SWT.NONE);
    clearButton.setText("Clear");
    clearButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent event) {
            // clear fields after add operation
            notifyFromText.setText("");
            notifyToText.setText("");
            notifyToGroupsText.setText("");
            notifyReplyToText.setText("");
            notifySubjectText.setText("");
            notifyBodyText.setText("");
            notifyTypeText.setText("");
            notifyExpiresAtText.setText("");
        }

        public void widgetDefaultSelected(SelectionEvent event) {
            // clear fields after add operation
            notifyFromText.setText("");
            notifyToText.setText("");
            notifyToGroupsText.setText("");
            notifyReplyToText.setText("");
            notifySubjectText.setText("");
            notifyBodyText.setText("");
            notifyTypeText.setText("");
            notifyExpiresAtText.setText("");
        }
    });

}

From source file:org.eclipse.cdt.utils.ui.controls.ControlFactory.java

License:Open Source License

/**
 *   Create this group's list viewer./*w ww.  j a  v  a2s .  c o m*/
 */
public static TableViewer createTableViewer(Composite parent, String[] opt_list, int width, int height,
        int style) {
    TableViewer listViewer = new TableViewer(parent, SWT.BORDER | style);
    GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    data.widthHint = width;
    data.heightHint = height;
    listViewer.getTable().setLayoutData(data);
    if (null != opt_list)
        listViewer.add(opt_list);
    return listViewer;
}

From source file:org.eclipse.dltk.internal.ui.search.DLTKSearchTableContentProvider.java

License:Open Source License

public void elementsChanged(Object[] updatedElements) {
    if (fResult == null)
        return;//  w ww .j  a  v a  2  s  .c  o m
    int addCount = 0;
    int removeCount = 0;
    int addLimit = getAddLimit();

    TableViewer viewer = (TableViewer) getPage().getViewer();
    Set<Object> updated = new HashSet<Object>();
    Set<Object> added = new HashSet<Object>();
    Set<Object> removed = new HashSet<Object>();
    for (int i = 0; i < updatedElements.length; i++) {
        if (getPage().getDisplayedMatchCount(updatedElements[i]) > 0) {
            if (viewer.testFindItem(updatedElements[i]) != null)
                updated.add(updatedElements[i]);
            else {
                if (addLimit > 0) {
                    added.add(updatedElements[i]);
                    addLimit--;
                    addCount++;
                }
            }
        } else {
            removed.add(updatedElements[i]);
            removeCount++;
        }
    }

    viewer.add(added.toArray());
    viewer.update(updated.toArray(), new String[] { SearchLabelProvider.PROPERTY_MATCH_COUNT });
    viewer.remove(removed.toArray());
}

From source file:org.eclipse.dltk.mod.internal.ui.search.DLTKSearchTableContentProvider.java

License:Open Source License

public void elementsChanged(Object[] updatedElements) {
    if (fResult == null)
        return;/*from w  w w .j a  v a 2  s  . co m*/
    int addCount = 0;
    int removeCount = 0;
    TableViewer viewer = (TableViewer) getPage().getViewer();
    Set updated = new HashSet();
    Set added = new HashSet();
    Set removed = new HashSet();
    for (int i = 0; i < updatedElements.length; i++) {
        if (getPage().getDisplayedMatchCount(updatedElements[i]) > 0) {
            if (viewer.testFindItem(updatedElements[i]) != null)
                updated.add(updatedElements[i]);
            else
                added.add(updatedElements[i]);
            addCount++;
        } else {
            removed.add(updatedElements[i]);
            removeCount++;
        }
    }

    viewer.add(added.toArray());
    viewer.update(updated.toArray(), new String[] { SearchLabelProvider.PROPERTY_MATCH_COUNT });
    viewer.remove(removed.toArray());
}

From source file:org.eclipse.e4mf.edit.ui.provider.NotifyChangedToViewerRefresh.java

License:Open Source License

public void refreshTableViewer(TableViewer viewer, Object object, int eventType, Object feature,
        Object oldValue, Object newValue, int index) {
    switch (eventType) {
    case Notification.ADD: {
        viewer.insert(newValue, index);//  ww  w. j  a va2 s . co m
        break;
    }
    case Notification.ADD_MANY: {
        if (index == -1) {
            viewer.add(((Collection<?>) newValue).toArray());
        } else {
            for (Object value : (Collection<?>) newValue) {
                viewer.insert(value, index++);
            }
        }
        break;
    }
    case Notification.REMOVE: {
        viewer.remove(oldValue);
        break;
    }
    case Notification.REMOVE_MANY: {
        viewer.remove(((Collection<?>) oldValue).toArray());
        break;
    }
    case Notification.MOVE:
    case Notification.UNSET:
    case Notification.SET:
    default: {
        refreshStructuredViewer(viewer, object, eventType, feature, oldValue, newValue, index);
        break;
    }
    }
}

From source file:org.eclipse.ecf.internal.example.collab.ui.LineChatClientView.java

License:Open Source License

protected boolean changeUserInTree(final IUser userdata) {
    for (int i = 0; i < users.size(); i++) {
        final IUser user = (IUser) users.get(i);
        if (user.getID().equals(userdata.getID())) {
            Display.getDefault().asyncExec(new Runnable() {
                public void run() {
                    if (!teamChat.isDisposed()) {
                        final TableViewer view = teamChat.getTableViewer();
                        view.remove(user);
                        users.remove(user);
                        view.add(userdata);
                        users.add(userdata);
                    }/*  ww  w  .  ja  va  2s .c om*/
                }
            });
            return true;
        }
    }
    return false;
}

From source file:org.eclipse.emf.ecp.internal.ui.view.emf.NotifyChangedToViewerRefresh.java

License:Open Source License

public void refreshTableViewer(TableViewer viewer, Object object, int eventType, Object feature,
        Object oldValue, Object newValue, int index) {
    switch (eventType) {
    case Notification.ADD: {
        viewer.insert(newValue, index);// w w  w .  j  av a2s.co  m
        break;
    }
    case Notification.ADD_MANY: {
        if (index == -1) {
            viewer.add(((Collection<?>) newValue).toArray());
        } else {
            for (final Object value : (Collection<?>) newValue) {
                viewer.insert(value, index++);
            }
        }
        break;
    }
    case Notification.REMOVE: {
        viewer.remove(oldValue);
        break;
    }
    case Notification.REMOVE_MANY: {
        viewer.remove(((Collection<?>) oldValue).toArray());
        break;
    }
    case Notification.MOVE:
    case Notification.UNSET:
    case Notification.SET:
    default: {
        refreshStructuredViewer(viewer, object, eventType, feature, oldValue, newValue, index);
        break;
    }
    }
}

From source file:org.eclipse.equinox.examples.app.selector.ApplicationView.java

License:Open Source License

public Object addingService(ServiceReference reference) {
    if (!"any.thread".equals(reference.getProperty("eclipse.application.type")))
        return null;

    final ApplicationInfo info = new ApplicationInfo(reference, this);
    final TableViewer updateViewer = getViewer();
    if (updateViewer != null) {
        if (PlatformUI.getWorkbench().getDisplay().isDisposed())
            return info;
        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
            public void run() {
                updateViewer.add(info);
            }/* ww w .  j  a v a  2s .  com*/
        });
    }
    return info;
}

From source file:org.eclipse.imp.lpg.search.LPGSearchTableContentProvider.java

License:Open Source License

public void elementsChanged(Object[] updatedElements) {
    if (fResult == null)
        return;//from w ww. j a  va  2  s.co  m
    int addCount = 0;
    int removeCount = 0;
    TableViewer viewer = (TableViewer) getPage().getViewer();
    Set updated = new HashSet();
    Set added = new HashSet();
    Set removed = new HashSet();
    for (int i = 0; i < updatedElements.length; i++) {
        if (getPage().getDisplayedMatchCount(updatedElements[i]) > 0) {
            if (viewer.testFindItem(updatedElements[i]) != null)
                updated.add(updatedElements[i]);
            else
                added.add(updatedElements[i]);
            addCount++;
        } else {
            removed.add(updatedElements[i]);
            removeCount++;
        }
    }

    viewer.add(added.toArray());
    viewer.update(updated.toArray(), null /*new String[] { SearchLabelProvider.PROPERTY_MATCH_COUNT } */);
    viewer.remove(removed.toArray());
}

From source file:org.eclipse.jface.snippets.viewers.Snippet045TableViewerFillFromBackgroundThread.java

License:Open Source License

public Snippet045TableViewerFillFromBackgroundThread(final Shell shell) {
    final TableViewer v = new TableViewer(shell, SWT.BORDER | SWT.FULL_SELECTION);
    v.setLabelProvider(new MyLabelProvider());
    v.setContentProvider(ArrayContentProvider.getInstance());

    TableColumn column = new TableColumn(v.getTable(), SWT.NONE);
    column.setWidth(200);/*from  w  w  w.  ja v a 2  s . c o m*/
    column.setText("Column 1");

    column = new TableColumn(v.getTable(), SWT.NONE);
    column.setWidth(200);
    column.setText("Column 2");

    final List<MyModel> model = new ArrayList<>();
    model.add(new MyModel(0));
    model.add(new MyModel(0));
    model.add(new MyModel(0));
    v.setInput(model);
    v.setComparator(new ViewerComparator() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            MyModel m1 = (MyModel) e1;
            MyModel m2 = (MyModel) e2;
            return m2.counter - m1.counter;
        }

    });
    v.getTable().setLinesVisible(true);
    v.getTable().setHeaderVisible(true);

    TimerTask task = new TimerTask() {

        @Override
        public void run() {
            shell.getDisplay().syncExec(() -> {
                MyModel el = new MyModel(++COUNTER);
                v.add(el);
                model.add(el);
            });
        }
    };

    Timer timer = new Timer(true);
    timer.scheduleAtFixedRate(task, 3000, 1000);
}