List of usage examples for org.eclipse.jface.viewers TableViewer remove
@Override public void remove(Object[] elements)
From source file:de.walware.ecommons.workbench.search.ui.TextSearchResultMatchTableContentProvider.java
License:Open Source License
@Override public void elementsChanged(final Object[] elements) { if (!this.active) { return;/*from w w w . java 2 s . c o m*/ } final ExtTextSearchResult<E, M> result = getInput(); final int limit = getElementLimit(); final TableViewer viewer = getViewer(); final List<M> toAdd = new ArrayList<M>(); final List<M> toUpdate = new ArrayList<M>(); final List<M> toRemove = new ArrayList<M>(); for (int i = 0; i < elements.length; i++) { final E element = (E) elements[i]; final M[] matches = result.getPickedMatches(element); final SortedListSet<M> currentElementMatches = this.currentMatches.subList(element); for (int j = 0; j < matches.length; j++) { final M match = matches[j]; int k; if ((this.currentMatches.size() < limit)) { k = currentElementMatches.addE(match); if (k >= 0) { toAdd.add(match); } else { toUpdate.add(match); k = -(k + 1); } } else { k = currentElementMatches.indexOf(match); if (k >= 0) { toUpdate.add(match); } else { k = -(k + 1); } } while (k > j) { toRemove.add(currentElementMatches.remove(j)); k--; } } while (currentElementMatches.size() > matches.length) { currentElementMatches.remove(matches.length); } } viewer.getTable().setRedraw(false); try { viewer.remove(toRemove.toArray()); viewer.refresh(toUpdate.toArray(), true); viewer.add(toAdd.toArray()); } finally { viewer.getTable().setRedraw(true); } }
From source file:de.walware.ecommons.workbench.search.ui.TextSearchResultTableContentProvider.java
License:Open Source License
@Override public void elementsChanged(final Object[] elements) { if (!this.active) { return;/*from w w w. ja v a 2 s . com*/ } final ExtTextSearchResult<E, M> result = getInput(); final int limit = getElementLimit(); final TableViewer viewer = getViewer(); viewer.getTable().setRedraw(false); try { // final List<E> toAdd= new ArrayList<E>(); final List<E> toUpdate = new ArrayList<E>(); // final List<E> toRemove= new ArrayList<E>(); for (int i = 0; i < elements.length; i++) { final E element = (E) elements[i]; if (result.hasPickedMatches(element)) { if (this.currentElements.size() < limit) { final int idx = this.currentElements.addE(element); if (idx >= 0) { viewer.insert(element, idx); // toAdd.add(element); } else { toUpdate.add(element); } } else if (this.currentElements.contains(element)) { toUpdate.add(element); } } else { final int idx = this.currentElements.removeE(element); if (idx >= 0) { viewer.remove(element); // toRemove.add(element); } } } // viewer.remove(toRemove.toArray()); // viewer.add(toAdd.toArray()); viewer.refresh(toUpdate.toArray(), true); } finally { viewer.getTable().setRedraw(true); } }
From source file:eu.geclipse.batch.ui.internal.adapters.QueueAdapter.java
License:Open Source License
/** * Delete a selected Virtual Organizations (VO) name. * /*from w w w .j av a 2 s .c o m*/ * @param tableViewer The {@link TableViewer} that contains all allowed VO's for the {@link QueueType}. */ public void deleteAllowedVo(final TableViewer tableViewer) { IStructuredSelection structSelection = (IStructuredSelection) tableViewer.getSelection(); if (structSelection != null) { Iterator<?> it = structSelection.iterator(); /* * Iterate over the selections and delete them from the model. */ while (it.hasNext()) { Object feature = it.next(); try { /* Delete only Multi-Valued Elements */ if (!this.adapterRefreshed) { this.allowedVOs.getVOName().remove(feature); if (this.allowedVOs.getVOName().size() == 0) { EcoreUtil.remove(this.allowedVOs); } contentChanged(); } else { tableViewer.remove(feature); } } //end try catch (Exception e) { Activator.logException(e); } /* * Refresh the table viewer and notify the editor that the page content has * changed. */ tableViewer.refresh(); } // end While } // end_if }
From source file:eu.geclipse.jsdl.ui.adapters.jsdl.ResourcesTypeAdapter.java
License:Open Source License
protected void performDelete(final TableViewer viewer) { IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection(); if (structSelection != null) { Iterator<?> it = structSelection.iterator(); /*/*from w w w . j a v a 2 s . c o m*/ * Iterate over the selections and delete them from the model. */ while (it.hasNext()) { Object feature = it.next(); try { /* Delete only Multi-Valued Elements */ if (!this.adapterRefreshed) { /* * Check the instance of the Selection. */ if (feature instanceof String) { /* * If this feature is an instance of String then, this * is a CandidateHosts instance. Therefore, remove the * CandidataHosts instance. */ this.candidateHosts.getHostName().remove(feature); if (this.candidateHosts.getHostName().size() == 0) { EcoreUtil.remove(this.candidateHosts); checkResourcesElement(); } } /* * Then this is a FileSystem instance, so we have to remove * the instance from the parent( ResourceType ) object. */ else { this.resourcesType.getFileSystem().remove(feature); if (this.resourcesType.getFileSystem().size() == 0) { EcoreUtil.remove(this.fileSystemType); checkResourcesElement(); } } contentChanged(); } else { viewer.remove(feature); } } //end try catch (Exception e) { Activator.logException(e); } /* * Refresh the table viewer and notify the editor that the page content has * changed. */ viewer.refresh(); } // end While } // end_if }
From source file:eu.geclipse.jsdl.ui.internal.pages.sections.CandidateHostsSection.java
License:Open Source License
protected void performDelete(final TableViewer viewer) { IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection(); if (structSelection != null) { Iterator<?> it = structSelection.iterator(); /*/*from w w w . j a va 2 s . co m*/ * Iterate over the selections and delete them from the model. */ while (it.hasNext()) { Object feature = it.next(); try { /* Delete only Multi-Valued Elements */ if (!this.adapterRefreshed) { /* * Check the instance of the Selection. */ if (feature instanceof String) { /* * If this feature is an instance of String then, this * is a CandidateHosts instance. Therefore, remove the * CandidataHosts instance. */ this.candidateHosts.getHostName().remove(feature); if (this.candidateHosts.getHostName().size() == 0) { EcoreUtil.remove(this.candidateHosts); checkResourcesElement(); } } contentChanged(); } else { viewer.remove(feature); } } //end try catch (Exception e) { Activator.logException(e); } /* * Refresh the table viewer and notify the editor that the page content has * changed. */ viewer.refresh(); } // end While } // end_if }
From source file:eu.geclipse.jsdl.ui.internal.pages.sections.JobIdentificationSection.java
License:Open Source License
protected void performDelete(final TableViewer viewer) { IStructuredSelection structSelection = (IStructuredSelection) viewer.getSelection(); if (structSelection != null) { Iterator<?> it = structSelection.iterator(); /*// w ww . j a v a 2 s. c o m * Iterate over the selections and delete them from the model. */ while (it.hasNext()) { Object feature = it.next(); try { /* Delete only Multi-Valued Elements */ if (!this.adapterRefreshed) { /* * Check the instance of the Selection. */ if (feature instanceof String) { /* * If this feature is an instance of String then, this is a * CandidateHosts instance. Therefore, remove the CandidataHosts * instance. */ if (viewer == this.annotationsViewer) { this.jobIdentificationType.getJobAnnotation().remove(feature); } else { this.jobIdentificationType.getJobProject().remove(feature); } } contentChanged(); } else { viewer.remove(feature); } } // end try catch (Exception e) { Activator.logException(e); } /* * Refresh the table viewer and notify the editor that the page content * has changed. */ viewer.refresh(); } // end While } // end_if }
From source file:eu.numberfour.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/*from ww w.j a v a 2 s . com*/ 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. && Arrays2.transform(manager.getAllWorkingSets(), ws -> ws.getName()).contains(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:ext.org.eclipse.jdt.internal.ui.search.JavaSearchTableContentProvider.java
License:Open Source License
@Override public void elementsChanged(Object[] updatedElements) { if (getSearchResult() == null) return;/*from w w w . j a v a 2 s.c o m*/ 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--; } } } else { removed.add(updatedElements[i]); } } viewer.add(added.toArray()); viewer.update(updated.toArray(), new String[] { SearchLabelProvider.PROPERTY_MATCH_COUNT }); viewer.remove(removed.toArray()); }
From source file:net.rim.ejde.internal.ui.editors.model.BlackBerryProjectPropertiesPage.java
License:Open Source License
/** * Removes the currently selected table item from the viewer and updates controls accordingly * * @param viewer/*from ww w . j ava 2 s. c om*/ * @param actionButtons * @param updateUIOnly * <code>true</code> only update UI but not remove items from the table; <code>false</code> update UI and remove * items from the table; */ public void removeSelectedTableItem(TableViewer viewer, Map<Action, Button> actionButtons, boolean updateUIOnly) { StructuredSelection selection = (StructuredSelection) viewer.getSelection(); Table table = viewer.getTable(); int selectionIndex = table.getSelectionIndex(); Boolean entryRemoved = false; if (!updateUIOnly) { for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { Object selectedElement = iter.next(); if (selectedElement != null) { viewer.remove(selectedElement); if (!entryRemoved) { entryRemoved = true; } } } } if (updateUIOnly || entryRemoved) { int itemCount = table.getItemCount(); if (itemCount != 0) { table.select(itemCount - 1 > selectionIndex ? selectionIndex : itemCount - 1); if (actionButtons.containsKey(Action.MOVE_DOWN)) { if (selectionIndex == itemCount - 1) { actionButtons.get(Action.MOVE_DOWN).setEnabled(false); } actionButtons.get(Action.MOVE_UP).setEnabled(itemCount > 1 ? true : false); } // Used to fire any selection events viewer.setSelection(viewer.getSelection()); } else { if (actionButtons.containsKey(Action.EDIT)) { actionButtons.get(Action.EDIT).setEnabled(false); } if (actionButtons.containsKey(Action.REMOVE)) { actionButtons.get(Action.REMOVE).setEnabled(false); } if (actionButtons.containsKey(Action.MOVE_UP)) { actionButtons.get(Action.MOVE_UP).setEnabled(false); } if (actionButtons.containsKey(Action.MOVE_DOWN)) { actionButtons.get(Action.MOVE_DOWN).setEnabled(false); } if (actionButtons.containsKey(Action.SELECT_ALL)) { actionButtons.get(Action.SELECT_ALL).setEnabled(false); } if (actionButtons.containsKey(Action.SELECT_NONE)) { actionButtons.get(Action.SELECT_NONE).setEnabled(false); } } // Enable any disabled add buttons - icon scenarios where only 2 icons can be added. if (actionButtons.containsKey(Action.ADD)) { actionButtons.get(Action.ADD).setEnabled(true); } if (actionButtons.containsKey(Action.ADD_FROM_PROJECT)) { actionButtons.get(Action.ADD_FROM_PROJECT).setEnabled(true); } if (actionButtons.containsKey(Action.ADD_FROM_EXTERNAL)) { actionButtons.get(Action.ADD_FROM_EXTERNAL).setEnabled(true); } if (table.getColumnCount() > 1) { table.getColumn(1).pack(); } } }
From source file:org.drools.eclipse.flow.common.editor.editpart.work.EmailCustomEditor.java
License:Apache License
public void createHeadersTab(TabFolder tabFolder) { final TabItem headersTabItem = new TabItem(tabFolder, SWT.NONE); headersTabItem.setText("Header"); final Composite container = new Composite(tabFolder, SWT.NONE); final GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2;/*w w w .ja v a 2 s .c om*/ gridLayout.horizontalSpacing = 2; container.setLayout(gridLayout); headersTabItem.setControl(container); final Label recipientsLabel = new Label(container, SWT.NONE); final GridData gd_recipientsLabel = new GridData(); recipientsLabel.setLayoutData(gd_recipientsLabel); recipientsLabel.setText("Recipients"); new Label(container, SWT.NONE); // create main table final TableViewer tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION); // // Type column // TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); // column.setLabelProvider(new TypeLabelProvider()); // column.setEditingSupport(new TypeEditing(tableViewer)); // column.getColumn().setWidth(70); // column.getColumn().setText("Type"); // column.getColumn().setMoveable(true); // // // Display Name column // column = new TableViewerColumn(tableViewer, SWT.NONE); // column.setLabelProvider(new DisplayNameLabelProvider()); // column.setEditingSupport(new DisplayNameEditing(tableViewer)); // column.getColumn().setWidth(200); // column.getColumn().setText("Display Name"); // column.getColumn().setMoveable(true); // Email column TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE); column.setLabelProvider(new EmailLabelProvider()); column.setEditingSupport(new EmailEditing(tableViewer)); column.getColumn().setText("Email Address"); column.getColumn().setWidth(200); column.getColumn().setMoveable(true); final Table table = tableViewer.getTable(); final GridData gd_table = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); gd_table.heightHint = 128; table.setLayoutData(gd_table); table.setLinesVisible(true); table.setHeaderVisible(true); tableViewer.setContentProvider(new RecipientsContentProvider()); tableViewer.setInput(recipients); // 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) { Recipient recipient = new Recipient(); recipients.add(recipient); tableViewer.add(recipient); tableViewer.refresh(); } public void widgetSelected(SelectionEvent e) { Recipient recipient = new Recipient(); recipients.add(recipient); tableViewer.add(recipient); tableViewer.refresh(); } }); 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) { recipients.remove((Recipient) items[0].getData()); tableViewer.remove(items[0]); tableViewer.refresh(); } } public void widgetDefaultSelected(SelectionEvent event) { TableItem[] items = table.getSelection(); if (items != null && items.length > 0) { recipients.remove((Recipient) items[0].getData()); tableViewer.remove(items[0]); tableViewer.refresh(); } } }); // from label and text field final Label fromLabel = new Label(container, SWT.NONE); fromLabel.setLayoutData(new GridData()); fromLabel.setText("From"); fromText = new Text(container, SWT.BORDER); fromText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); }