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

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

Introduction

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

Prototype

@Override
    public void remove(Object[] elements) 

Source Link

Usage

From source file:org.eclipse.linuxtools.internal.docker.ui.launch.RunImageLabelsTab.java

License:Open Source License

private SelectionListener onRemoveLabelVariable(final TableViewer labelVariablesTableViewer) {
    return new SelectionAdapter() {

        @Override//  ww  w .j  a va2s .c  om
        public void widgetSelected(final SelectionEvent e) {
            final IStructuredSelection selection = labelVariablesTableViewer.getStructuredSelection();
            for (@SuppressWarnings("unchecked")
            Iterator<LabelVariableModel> iterator = selection.iterator(); iterator.hasNext();) {
                LabelVariableModel m = iterator.next();
                model.removeLabelVariable(m);
                labelVariablesTableViewer.remove(m);
                labelVariablesTableViewer.refresh();
            }
            updateLaunchConfigurationDialog();
        }
    };
}

From source file:org.eclipse.linuxtools.internal.docker.ui.wizards.ConfigureLabelsPage.java

License:Open Source License

private SelectionListener onRemoveLabelVariable(final TableViewer labelVariablesTableViewer) {
    return new SelectionAdapter() {

        @Override/*from   w  w  w.j a  v  a  2 s  . c o  m*/
        public void widgetSelected(final SelectionEvent e) {
            final IStructuredSelection selection = labelVariablesTableViewer.getStructuredSelection();
            for (@SuppressWarnings("unchecked")
            Iterator<LabelVariableModel> iterator = selection.iterator(); iterator.hasNext();) {
                LabelVariableModel m = iterator.next();
                model.removeLabelVariable(m);
                labelVariablesTableViewer.remove(m);
                labelVariablesTableViewer.refresh();
            }
        }
    };
}

From source file:org.eclipse.n4js.ui.workingsets.WorkingSetManualAssociationWizard.java

License:Open Source License

@Override
public void addPages() {
    addPage(new WizardPage("") {

        private Text nameText;
        private final Collection<IProject> workspaceProjects = newTreeSet(PROJECT_NAME_COMPARATOR);
        private final Collection<IProject> workingSetProjects = newTreeSet(PROJECT_NAME_COMPARATOR);

        @Override/*  w ww  . j  a v  a  2s .  c om*/
        public void createControl(Composite parent) {

            final Composite composite = new Composite(parent, NONE);
            composite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).create());
            composite.setLayoutData(fillDefaults().align(FILL, FILL).grab(true, true).create());

            new Label(composite, NONE).setText("Working set name:");
            nameText = new Text(composite, BORDER);
            nameText.setLayoutData(fillDefaults().align(FILL, CENTER).grab(true, false).create());

            Composite tableComposite = new Composite(composite, NONE);
            tableComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).create());
            tableComposite.setLayoutData(fillDefaults().align(FILL, FILL).grab(true, true).span(2, 1).create());

            Group workspaceGroup = new Group(tableComposite, SHADOW_IN);
            workspaceGroup.setText("Available workspace projects");
            workspaceGroup.setLayout(GridLayoutFactory.fillDefaults().create());
            workspaceGroup.setLayoutData(fillDefaults().align(FILL, FILL).grab(true, true).create());

            final TableViewer allProjectsViewer = new TableViewerBuilder(singletonList("")).setHasBorder(true)
                    .setHeaderVisible(false).setLinesVisible(false).setMultipleSelection(true)
                    .setColumnWidthsInPixel(Ints.asList(350)).setLabelProvider(labelProvider)
                    .build(workspaceGroup);

            Composite buttonComposite = new Composite(tableComposite, NONE);
            buttonComposite.setLayout(GridLayoutFactory.fillDefaults().create());
            // buttonComposite.setLayoutData(fillDefaults().align(CENTER, CENTER).grab(false, false).create());

            final Button addButton = new Button(buttonComposite, PUSH);
            addButton.setImage(ImageRef.RIGHT_ARROW.asImage().orNull());
            addButton.setToolTipText("Add all selected workspace projects");
            addButton.setEnabled(false);

            final Button removeButton = new Button(buttonComposite, PUSH);
            removeButton.setImage(ImageRef.LEFT_ARROW.asImage().orNull());
            removeButton.setToolTipText("Remove all selected working set element projects");
            removeButton.setEnabled(false);

            Group workingSetGroup = new Group(tableComposite, SHADOW_IN);
            workingSetGroup.setText("Associated working set projects");
            workingSetGroup.setLayout(GridLayoutFactory.fillDefaults().create());
            workingSetGroup.setLayoutData(fillDefaults().align(FILL, FILL).grab(true, true).create());

            final TableViewer associatedProjectsViewer = new TableViewerBuilder(singletonList(""))
                    .setHasBorder(true).setHeaderVisible(false).setLinesVisible(false)
                    .setMultipleSelection(true).setColumnWidthsInPixel(Ints.asList(350))
                    .setLabelProvider(labelProvider).build(workingSetGroup);

            addButton.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    IStructuredSelection selection = allProjectsViewer.getStructuredSelection();
                    if (selection != null && !selection.isEmpty()) {
                        final IProject[] projects = Arrays2.filter(selection.toArray(), IProject.class);
                        allProjectsViewer.remove(projects);
                        associatedProjectsViewer.add(projects);
                        workspaceProjects.removeAll(Arrays.asList(projects));
                        workingSetProjects.addAll(Arrays.asList(projects));
                        setPageComplete(validatePage());
                    }
                }
            });

            removeButton.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    IStructuredSelection selection = associatedProjectsViewer.getStructuredSelection();
                    if (selection != null && !selection.isEmpty()) {
                        final IProject[] projects = Arrays2.filter(selection.toArray(), IProject.class);
                        associatedProjectsViewer.remove(projects);
                        allProjectsViewer.add(projects);
                        workingSetProjects.removeAll(Arrays.asList(projects));
                        workspaceProjects.addAll(Arrays.asList(projects));
                        setPageComplete(validatePage());
                    }
                }
            });

            associatedProjectsViewer.addSelectionChangedListener(event -> {
                final IStructuredSelection selection = associatedProjectsViewer.getStructuredSelection();
                removeButton.setEnabled(null != selection && !selection.isEmpty());
            });

            allProjectsViewer.addSelectionChangedListener(event -> {
                final IStructuredSelection selection = allProjectsViewer.getStructuredSelection();
                addButton.setEnabled(null != selection && !selection.isEmpty());
            });

            setPageComplete(false);
            setControl(composite);

            final Optional<WorkingSet> editedWorkingSet = getEditedWorkingSet();
            workspaceProjects.addAll(Arrays.asList(ResourcesPlugin.getWorkspace().getRoot().getProjects()));
            if (editedWorkingSet.isPresent()) {
                final ManualAssociationWorkingSet workingSet = (ManualAssociationWorkingSet) editedWorkingSet
                        .get();
                workingSetRef.set(workingSet);
                nameText.setText(workingSet.getName());
                nameText.selectAll();
                workingSetProjects.addAll(workingSet.getAssociatedProjects());
                workspaceProjects.removeAll(workingSetProjects);
                originalName.set(workingSet.getName());
            }

            composite.getDisplay().asyncExec(() -> {
                setTitle(TITLE);
                setDescription(DESCRIPTION);
                allProjectsViewer.setInput(workspaceProjects);
                associatedProjectsViewer.setInput(workingSetProjects);
            });

            nameText.addModifyListener(e -> setPageComplete(validatePage()));

        }

        @Override
        public void setVisible(boolean visible) {
            if (visible) {
                Rectangle location = UIUtils.getConstrainedShellBounds(getShell(), SHELL_SIZE);
                getShell().setBounds(location);
            }
            super.setVisible(visible);
        }

        @SuppressWarnings("null")
        private boolean validatePage() {

            String errorMessage = null;

            final String name = nameText.getText();
            final WorkingSetManager manager = getManager();

            if (manager == null) {
                errorMessage = "No active working set manager is available.";
            }

            if (errorMessage == null) {
                if (name == null || name.trim().length() == 0) {
                    errorMessage = "Working set name should be specified.";
                }
            }

            if (errorMessage == null) {
                if (!name.equals(originalName.get())
                        // This case ID and name are equal. Intentionally name.
                        && getAllWorkingSets().stream().anyMatch(ws -> ws.getName().equals(name))) {
                    errorMessage = "A working set already exists with name '" + name + "'.";
                }
            }

            if (errorMessage != null) {
                workingSetRef.set(null);
            } else {
                final Iterable<String> projectNames = from(workingSetProjects).transform(p -> p.getName());
                workingSetRef.set(new ManualAssociationWorkingSet(projectNames, name, manager));
            }

            setMessage(errorMessage, ERROR);
            return errorMessage == null;
        }

    });
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.dialogs.ExtendedFeatureEditorDialog.java

License:Open Source License

private void setAddButtonListener(final Button addButton, final TableViewer choiceTableViewer,
        final TableViewer featureTableViewer, final Text choiceText) {
    addButton.addSelectionListener(new SelectionAdapter() {
        // event is null when choiceTableViewer is double clicked
        @Override/*from   w w  w .  j  a  v a  2s  .  c  om*/
        public void widgetSelected(final SelectionEvent event) {
            if (choiceTableViewer != null) {
                final IStructuredSelection selection = (IStructuredSelection) choiceTableViewer.getSelection();
                final Iterator<?> i = selection.iterator();
                while (i.hasNext()) {
                    final Object value = i.next();
                    if (!values.getChildren().contains(value)) {
                        values.getChildren().add(value);
                        choiceTableViewer.remove(value);
                    }
                }
                featureTableViewer.setSelection(selection);
            } else if (choiceText != null) {

                // Object value = EcoreUtil.createFromString((EDataType)
                // eClassifier, choiceText.getText());
                // values.getChildren().add(value);
                // choiceText.setText(StringUtil.EMPTY_STRING);
                // featureTableViewer.setSelection(new
                // StructuredSelection(value));

                // Ignore

            }
        }
    });
}

From source file:org.eclipse.team.svn.ui.panel.local.AddToSVNPanel.java

License:Open Source License

public void updateResources() {
    HashSet<IResource> toDeleteSet = new HashSet<IResource>();
    toDeleteSet.addAll(Arrays.asList(this.resources));
    HashSet<IResource> newResourcesSet = new HashSet<IResource>();
    newResourcesSet.addAll(Arrays.asList(FileUtility.getResourcesRecursive(this.resources,
            IStateFilter.SF_UNVERSIONED, IResource.DEPTH_ZERO)));
    List<IResource> ignored = Arrays.asList(
            FileUtility.getResourcesRecursive(this.resources, IStateFilter.SF_IGNORED, IResource.DEPTH_ZERO));
    if (ignored.size() != 0) {
        this.actionTookEffect = true;
    }//from   w w  w  .  j  a  va  2 s  .c  o m
    newResourcesSet.removeAll(Arrays.asList(
            FileUtility.getResourcesRecursive(this.resources, IStateFilter.SF_IGNORED, IResource.DEPTH_ZERO)));
    for (int i = 0; i < this.resources.length; i++) {
        if (!this.resources[i].exists()) {
            newResourcesSet.remove(this.resources[i]);
            this.actionTookEffect = true;
        }
    }
    final IResource[] newResources = newResourcesSet.toArray(new IResource[newResourcesSet.size()]);
    toDeleteSet.removeAll(newResourcesSet);
    final IResource[] toDeleteResources = toDeleteSet.toArray(new IResource[toDeleteSet.size()]);

    if (!this.paneParticipantHelper.isParticipantPane()) {
        final TableViewer tableViewer = this.selectionComposite.getTableViewer();
        UIMonitorUtility.getDisplay().syncExec(new Runnable() {
            public void run() {
                AddToSVNPanel.this.selectionComposite.setResources(newResources);
                if (!tableViewer.getTable().isDisposed()) {
                    tableViewer.remove(toDeleteResources);
                    tableViewer.refresh();
                    AddToSVNPanel.this.selectionComposite.fireSelectionChanged();
                }
            }
        });
    }

    this.resources = newResources;
}

From source file:org.eclipse.wst.common.ui.internal.search.SearchResultTableContentProvider.java

License:Open Source License

public void elementsChanged(Object[] updatedElements) {
    TableViewer viewer = getViewer();
    // cs : I've comment 'tableLimited' related code out for now.  We need to review the changes to the base class and react accordingly.
    // Even more importantly we need to discuss with the base guys to get API lined up for this (see bug 163177).
    //boolean tableLimited= SearchPreferencePage.isTableLimited();
    for (int i = 0; i < updatedElements.length; i++) {
        if (fResult.getMatchCount(updatedElements[i]) > 0) {
            if (viewer.testFindItem(updatedElements[i]) != null)
                viewer.update(updatedElements[i], null);
            else {
                //if (!tableLimited || viewer.getTable().getItemCount() < SearchPreferencePage.getTableLimit())
                viewer.add(updatedElements[i]);
            }/* w  w  w .  java2  s  . c om*/
        } else
            viewer.remove(updatedElements[i]);
    }
}

From source file:org.eclipse.wst.jsdt.internal.ui.search.JavaSearchTableContentProvider.java

License:Open Source License

public void elementsChanged(Object[] updatedElements) {
    if (getSearchResult() == null)
        return;/*from ww  w  .j a va  2 s.  c  o m*/

    int addCount = 0;
    int removeCount = 0;
    int addLimit = getAddLimit();

    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 {
                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.xtend.shared.ui.editor.search.view.XtendXpandTableContentProvider.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w  w w.  j  a v  a 2s . com*/
 */
public void elementsChanged(Object[] updatedElements) {
    TableViewer viewer = getViewer();
    int elementLimit = 1000; // getElementLimit();
    boolean tableLimited = elementLimit != -1;
    for (Object element : updatedElements) {
        if (result.getMatchCount(element) > 0) {
            if (viewer.testFindItem(element) != null) {
                viewer.update(element, null);
            } else {
                if (!tableLimited || viewer.getTable().getItemCount() < elementLimit) {
                    viewer.add(element);
                }
            }
        } else {
            viewer.remove(element);
        }
    }
}

From source file:org.fusesource.ide.zk.core.viewers.TableViewerType.java

License:Apache License

@Override
public void removeElement(StructuredViewer viewer, Object element) {
    TableViewer tableViewer = (TableViewer) viewer;
    tableViewer.remove(element);
}

From source file:org.jboss.tools.seam.ui.search.SeamTableContentProvider.java

License:Open Source License

/**
 * (non-Javadoc)// w w  w .  j a  va2  s.  co  m
 * @see org.eclipse.search.internal.ui.text.IFileSearchContentProvider#elementsChanged(java.lang.Object[])
 */
public void elementsChanged(Object[] updatedElements) {
    TableViewer viewer = getViewer();
    int elementLimit = getElementLimit();
    boolean tableLimited = elementLimit != -1;
    for (int i = 0; i < updatedElements.length; i++) {
        if (fResult.getMatchCount(updatedElements[i]) > 0) {
            if (viewer.testFindItem(updatedElements[i]) != null)
                viewer.update(updatedElements[i], null);
            else {
                if (!tableLimited || viewer.getTable().getItemCount() < elementLimit)
                    viewer.add(updatedElements[i]);
            }
        } else
            viewer.remove(updatedElements[i]);
    }
}