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:com.aptana.ide.search.epl.filesystem.ui.text.FileTableContentProvider.java

License:Open Source License

/**
 * @see com.aptana.ide.search.epl.filesystem.ui.text.IFileSearchContentProvider#elementsChanged(java.lang.Object[])
 *///from   w  ww . j  a va 2 s .c  om
public void elementsChanged(Object[] updatedElements) {
    TableViewer viewer = this.getViewer();

    int elementLimit = this.getElementLimit();
    boolean tableLimited = elementLimit != -1;
    for (int i = 0; i < updatedElements.length; i++) {
        if (this.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]);
        }
    }
}

From source file:com.aptana.ide.search.MatchesContentProvider.java

License:Open Source License

/**
 * handles updates//from w  w w .j ava2  s .  co  m
 * @param updatedElements
 * updates elements 
 */
public void elementsChanged(Object[] updatedElements) {
    StructuredViewer viewer2 = this.aptanaFileSearchPage.getViewer();
    TableViewer viewer = (TableViewer) viewer2;
    int elementLimit = this.getElementLimit();
    boolean tableLimited = getElementLimit() == -1;
    AbstractTextSearchResult input = this.aptanaFileSearchPage.getInput();
    for (int i = 0; i < updatedElements.length; i++) {
        Object element = updatedElements[i];

        Match[] matchs = (Match[]) this.mmap.get(element);
        if (matchs == null) {
            matchs = AptanaFileSearchPage.NO_MATCH;
        }
        if (input.getMatchCount(element) > 0) {
            Match[] matches = input.getMatches(element);
            HashSet set = new HashSet(Arrays.asList(matches));
            for (int a = 0; a < matchs.length; a++) {
                Match m = matchs[a];
                if (!set.contains(m)) {
                    viewer.remove(m);
                } else {
                    set.remove(m);
                }
            }
            this.mmap.put(element, matches);
            for (Iterator iterator = set.iterator(); iterator.hasNext();) {
                Match name = (Match) iterator.next();
                if (!tableLimited || (viewer.getTable().getItemCount() < elementLimit)) {
                    viewer.add(name);
                } else {
                    break;
                }
            }
        } else {
            viewer.remove(matchs);
        }
    }
}

From source file:com.aptana.ide.search.ui.filesystem.MatchesContentProvider.java

License:Open Source License

/**
 * handles updates//from w  w w . j av  a  2 s  .  c om
 * 
 * @param updatedElements
 *            updates elements
 */
public void elementsChanged(Object[] updatedElements) {
    StructuredViewer viewer2 = this.aptanaFileSearchPage.getViewer();
    TableViewer viewer = (TableViewer) viewer2;
    int elementLimit = getElementLimit();
    boolean tableLimited = getElementLimit() == -1;
    AbstractTextSearchResult input = this.aptanaFileSearchPage.getInput();
    for (Object element : updatedElements) {
        Match[] matchs = this.mmap.get(element);
        if (matchs == null) {
            matchs = AptanaFileSystemSearchPage.NO_MATCH;
        }
        if (input.getMatchCount(element) > 0) {
            Match[] matches = input.getMatches(element);
            Set<Match> set = new HashSet<Match>(Arrays.asList(matches));
            for (Match m : matches) {
                if (!set.contains(m)) {
                    viewer.remove(m);
                } else {
                    set.remove(m);
                }
            }
            this.mmap.put(element, matches);
            for (Match name : set) {
                if (!tableLimited || (viewer.getTable().getItemCount() < elementLimit)) {
                    viewer.add(name);
                } else {
                    break;
                }
            }
        } else {
            viewer.remove(matchs);
        }
    }
}

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

License:Open Source License

@Override
protected void buttonPressed(int buttonId) {
    switch (buttonId) {
    case LOAD://from  w ww.ja v a 2 s . co  m
        if (dirty && !AcousticMessageDialog.openQuestion(getShell(),
                Messages.MigrateDialog_load_migration_policy, Messages.MigrateDialog_abandon_current_policy))
            return;
        List<MigrationPolicy> set = dbManager.obtainObjects(MigrationPolicy.class);
        if (!set.isEmpty()) {
            List<MigrationPolicy> policies = new ArrayList<MigrationPolicy>(set);
            ListDialog dialog = new ListDialog(getShell()) {
                @Override
                public void create() {
                    super.create();
                    getTableViewer().addSelectionChangedListener(new ISelectionChangedListener() {
                        public void selectionChanged(SelectionChangedEvent event) {
                            updateDeleteButton();
                        }
                    });
                }

                @Override
                protected void createButtonsForButtonBar(Composite parent) {
                    createButton(parent, 9999, Messages.MigrateDialog_remove, false);
                    super.createButtonsForButtonBar(parent);
                }

                @Override
                protected void buttonPressed(int buttonId) {
                    if (buttonId == 9999) {
                        TableViewer tableViewer = getTableViewer();
                        IStructuredSelection selection = tableViewer.getStructuredSelection();
                        if (!selection.isEmpty()) {
                            MigrationPolicy policy = (MigrationPolicy) selection.getFirstElement();
                            tableViewer.remove(policy);
                            List<Object> toBeDeleted = new ArrayList<Object>(policy.getRule().length + 1);
                            toBeDeleted.addAll(Arrays.asList(policy.getRule()));
                            toBeDeleted.add(policy);
                            dbManager.safeTransaction(toBeDeleted, null);
                            updateDeleteButton();
                            return;
                        }
                    } else
                        super.buttonPressed(buttonId);
                }

                private void updateDeleteButton() {
                    getButton(9999).setEnabled(!getTableViewer().getSelection().isEmpty());
                }
            };
            dialog.setContentProvider(ArrayContentProvider.getInstance());
            dialog.setLabelProvider(ZColumnLabelProvider.getDefaultInstance());
            dialog.setMessage(Messages.MigrateDialog_available_policies);
            dialog.setTitle(Messages.MigrateDialog_migration_policies);
            dialog.setInput(policies);
            if (dialog.open() == ListSelectionDialog.OK) {
                Object[] result = dialog.getResult();
                if (result != null && result.length > 0) {
                    MigrationPolicy policy = (MigrationPolicy) result[0];
                    rules = new ArrayList<MigrationRule>(Arrays.asList(policy.getRule()));
                    fileEditor.setText(policy.getTargetCatalog());
                    String fsp = policy.getFileSeparatorPolicy();
                    fileSepearatorPolicy = MigrationPolicy_type.fileSeparatorPolicy_tOSLASH.equals(fsp) ? 1
                            : MigrationPolicy_type.fileSeparatorPolicy_tOBACKSLASH.equals(fsp) ? 2 : 0;
                    fileSeparatorCombo.select(fileSepearatorPolicy);
                    viewer.setInput(rules);
                    updateButtons();
                    dirty = false;
                }
            }
        }
        return;
    case SAVE:
        File file = new File(fileEditor.getText());
        String filename = file.getName();
        if (filename.endsWith(BatchConstants.CATEXTENSION))
            filename = filename.substring(0, filename.length() - BatchConstants.CATEXTENSION.length());
        InputDialog dialog = new InputDialog(getShell(), Messages.MigrateDialog_save_migration_policy,
                Messages.MigrateDialog_specify_name, filename, null);
        if (dialog.open() == InputDialog.OK) {
            String name = dialog.getValue();
            fileSepearatorPolicy = fileSeparatorCombo.getSelectionIndex();
            String fsp = convertFileSeparatorPolicy();
            MigrationPolicy policy;
            set = dbManager.obtainObjects(MigrationPolicy.class, "name", name, QueryField.EQUALS); //$NON-NLS-1$
            List<Object> toBeDeleted = null;
            if (!set.isEmpty()) {
                if (AcousticMessageDialog.openQuestion(getShell(), Messages.MigrateDialog_save_migration_policy,
                        Messages.MigrateDialog_policy_already_exists))
                    return;
                policy = set.get(0);
                toBeDeleted = new ArrayList<Object>(Arrays.asList(policy.getRule()));
                policy.setTargetCatalog(targetCatalog);
                policy.setRule(rules.toArray(new MigrationRule[rules.size()]));
                policy.setFileSeparatorPolicy(fsp);
            } else {
                policy = new MigrationPolicyImpl(name, fsp, fileEditor.getText());
                policy.setRule(rules.toArray(new MigrationRule[rules.size()]));
            }
            List<Object> toBeStored = new ArrayList<Object>(rules.size() + 1);
            toBeStored.addAll(rules);
            toBeStored.add(policy);
            dbManager.safeTransaction(toBeDeleted, toBeStored);
            dirty = false;
        }
        return;
    }
    super.buttonPressed(buttonId);
}

From source file:com.google.dart.tools.internal.search.ui.text.FileTableContentProvider.java

License:Open Source License

@Override
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]);
                }/*from w w  w.j  a  va2 s  .  co m*/
            }
        } else {
            viewer.remove(updatedElements[i]);
        }
    }
}

From source file:com.google.dart.tools.search.internal.ui.text.FileTableContentProvider.java

License:Open Source License

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]);
            }//  w w w .  j a v  a  2  s .  co m
        } else
            viewer.remove(updatedElements[i]);
    }
}

From source file:com.google.dart.tools.ui.internal.search.DartSearchTableContentProvider.java

License:Open Source License

@Override
public void elementsChanged(Object[] updatedElements) {
    if (getSearchResult() == null) {
        return;//from   w w  w  . ja  v a2 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:com.nextep.designer.synch.ui.dialogs.TableSelectionDialog.java

License:Open Source License

private Collection<IVersionable<?>> transferSelection(TableViewer sourceViewer, TableViewer targetViewer) {
    final ISelection s = sourceViewer.getSelection();
    final Collection<IVersionable<?>> transferredElts = new ArrayList<IVersionable<?>>();
    if (s != null && !s.isEmpty() && s instanceof IStructuredSelection) {
        final IStructuredSelection sel = (IStructuredSelection) s;
        Iterator<?> it = sel.iterator();
        while (it.hasNext()) {
            IVersionable<?> v = (IVersionable<?>) it.next();
            targetViewer.add(v);//  w  w w.  j a  v  a 2  s.  co  m
            sourceViewer.remove(v);
            transferredElts.add(v);
        }
    }
    return transferredElts;
}

From source file:de.marw.cdt.cmake.core.ui.DefinesViewer.java

License:Open Source License

private void handleDefineDelButton(TableViewer tableViewer) {
    final IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    final Shell shell = tableViewer.getControl().getShell();
    if (MessageDialog.openQuestion(shell, "CMake-Define deletion confirmation",
            "Are you sure to delete the selected CMake-defines?")) {
        @SuppressWarnings("unchecked")
        ArrayList<CmakeDefine> defines = (ArrayList<CmakeDefine>) tableViewer.getInput();
        defines.removeAll(selection.toList());
        tableViewer.remove(selection.toArray());// updates the display
    }/*from www . ja va2s.co  m*/
}

From source file:de.marw.cdt.cmake.core.ui.UnDefinesViewer.java

License:Open Source License

private void handleUnDefineDelButton(TableViewer tableViewer) {
    final IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
    final Shell shell = tableViewer.getControl().getShell();
    if (MessageDialog.openQuestion(shell, "CMake-Undefine deletion confirmation",
            "Are you sure to delete the selected CMake-undefines?")) {
        @SuppressWarnings("unchecked")
        ArrayList<String> undefines = (ArrayList<String>) tableViewer.getInput();
        undefines.removeAll(selection.toList());
        tableViewer.remove(selection.toArray());// updates the display
    }//from  w w w .jav a2 s  .c o  m
}