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

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

Introduction

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

Prototype

public void remove(final Object... elementsOrTreePaths) 

Source Link

Document

Removes the given elements from this viewer.

Usage

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

License:Open Source License

private void removeKeywordFromViewer(TreeViewer viewer, String kw) {
    if (keywords.remove(kw)) {
        if (flatKeywordGroup.isFlat())
            viewer.remove(kw);
        else {//from w ww.j  a  v a2  s. c o  m
            Object[] expandedElements = viewer.getExpandedElements();
            viewer.setInput(keywords);
            viewer.setExpandedElements(expandedElements);
        }
    }
}

From source file:com.kdmanalytics.toif.ui.views.FindingContentProvider.java

License:Open Source License

/** Update the information for the specified resource. Tell the view about
 * the changes.//  w ww.j  a v  a 2  s.c  om
 * 
 * @param resource
 */
public void update(final TreeViewer viewer, final IFile file) {
    if (file == null)
        return;
    if (file.getProject() != this.currentProject)
        return;

    // Ensure we are running on the UI thread
    Display.getDefault().syncExec(new Runnable() {
        public void run() {
            // Get old findings
            List<IFindingEntry> oldFindings = findings.get(file);
            if (oldFindings == null)
                oldFindings = new LinkedList<IFindingEntry>();
            // Get new findings
            List<FindingEntry> newFindings = updateFindings(file);

            if (!equals(oldFindings, newFindings)) {
                findings.remove(file);
                if (oldFindings != null) {
                    for (IFindingEntry finding : oldFindings) {
                        viewer.remove(finding);
                    }
                }
                viewer.refresh();
                for (FindingEntry finding : newFindings) {
                    addEntry(finding);
                }

            }
        }

        /** Determine if lists are equal by sorting them and then comparing
         * them.
         * 
         * @param list1
         * @param newFindings
         * @return
         */
        private boolean equals(List<IFindingEntry> list1, List<FindingEntry> newFindings) {
            if (list1 == null && newFindings == null)
                return true;
            if (list1 == null)
                return false;
            if (newFindings == null)
                return false;

            List<FindingEntry> c1 = new LinkedList<FindingEntry>();
            List<FindingEntry> c2 = new LinkedList<FindingEntry>();

            for (IFindingEntry entry : list1) {
                if (entry instanceof FindingEntry) {
                    c1.add((FindingEntry) entry);
                } else {
                    Collection<IFindingEntry> children = ((FindingGroup) entry).getFindingEntries();
                    for (IFindingEntry child : children) {
                        c1.add((FindingEntry) child);
                    }
                }
            }

            for (IFindingEntry entry : newFindings) {
                if (entry instanceof FindingEntry) {
                    c2.add((FindingEntry) entry);
                } else {
                    Collection<IFindingEntry> children = ((FindingGroup) entry).getFindingEntries();
                    for (IFindingEntry child : children) {
                        c2.add((FindingEntry) child);
                    }
                }
            }

            if (c1.size() != c2.size())
                return false;

            Collections.sort(c1);
            Collections.sort(c2);
            return c1.equals(c2);
        }
    });
}

From source file:de.walware.statet.r.internal.ui.search.RElementSearchResultTreeContentProvider.java

License:Open Source License

protected void doRemove(final TreeViewer viewer, final Object element) {
    final Object parent = getParent(element);
    final SortedListSet<Object> children = this.levelChildren.get(parent);
    if (children == null) {
        return;//from   w  w w.j  a  v a  2  s  . c  om
    }
    if (children.removeE(element) >= 0) {
        if (children.isEmpty() && parent != null) {
            doRemove(viewer, parent);
        } else if (viewer != null) {
            viewer.remove(element);
        }
    }
}

From source file:net.tourbook.ui.views.tagging.TVITagViewTag.java

License:Open Source License

private void refreshFlatTours(final TreeViewer tagViewer, final ArrayList<TourData> modifiedTours,
        final boolean isAddMode) {

    final ArrayList<TreeViewerItem> unfetchedChildren = getUnfetchedChildren();
    if (unfetchedChildren == null) {
        // children are not fetched
        return;/*from   ww  w  . j  a va  2 s.c o m*/
    }

    if (isAddMode) {

        // this tag was added to tours

        final ArrayList<TreeViewerItem> tagChildren = readTagChildren_Tours(
                getTourIdWhereClause(modifiedTours));

        // update model
        unfetchedChildren.addAll(tagChildren);

        // update viewer
        tagViewer.add(this, tagChildren.toArray());

    } else {

        // this tag was remove from tours

        final HashMap<Long, TVITagViewTour> removedTours = new HashMap<Long, TVITagViewTour>();

        // loop all tour items
        for (final TreeViewerItem treeItem : unfetchedChildren) {

            if (treeItem instanceof TVITagViewTour) {

                final TVITagViewTour tourItem = (TVITagViewTour) treeItem;
                final long itemTourId = tourItem.getTourId();

                // find tour item in the modified tours
                for (final TourData tourData : modifiedTours) {
                    if (tourData.getTourId().longValue() == itemTourId) {

                        // tree tour item was found in the modified tours

                        // remove the item outside of the for loop
                        removedTours.put(itemTourId, tourItem);

                        break;
                    }
                }
            }
        }

        final Collection<TVITagViewTour> removedTourItems = removedTours.values();

        // update model
        unfetchedChildren.removeAll(removedTours.values());

        // update viewer
        tagViewer.remove(removedTourItems.toArray());
    }
}

From source file:net.tourbook.ui.views.tourCatalog.ActionRemoveComparedTours.java

License:Open Source License

/**
 * @param selection//from  w w w . j av a  2 s .c  o  m
 * @param removedTours
 * @return Returns <code>true</code> when the tours are removed
 */
private boolean removeComparedTours(final IStructuredSelection selection,
        final SelectionRemovedComparedTours removedTours) {

    // confirm removal
    if (MessageDialog.openConfirm(fTourView.getSite().getShell(),
            Messages.tourCatalog_view_dlg_delete_comparedTour_title,
            Messages.tourCatalog_view_dlg_delete_comparedTour_msg) == false) {

        return false;
    }

    final TreeViewer tourViewer = fTourView.getTourViewer();
    final ArrayList<Long> removedComparedTours = removedTours.removedComparedTours;

    // loop: selected items
    for (final Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {
        final Object element = iterator.next();
        if (element instanceof TVICatalogComparedTour) {

            final TVICatalogComparedTour compTourItem = (TVICatalogComparedTour) element;
            final long compId = compTourItem.getCompId();

            if (TourCompareManager.removeComparedTourFromDb(compId)) {

                // update model: remove compared tour
                compTourItem.remove();

                // update viewer: remove item
                tourViewer.remove(compTourItem);

                // update selection
                removedComparedTours.add(compId);
            }
        }
    }

    return true;
}

From source file:net.tourbook.ui.views.tourCatalog.ActionRemoveComparedTours.java

License:Open Source License

/**
 * @param selection//from  w w w  .  ja va 2s.c om
 * @param removedTours
 * @return Returns <code>true</code> when the tours are deleted
 */
private boolean removeRefTours(final IStructuredSelection selection,
        final SelectionRemovedComparedTours removedTours) {

    // confirm deletion
    if (MessageDialog.openConfirm(Display.getCurrent().getActiveShell(),
            Messages.tourCatalog_view_dlg_delete_refTour_title,
            Messages.tourCatalog_view_dlg_delete_refTour_msg) == false) {
        return false;
    }

    final TreeViewer tourViewer = fTourView.getTourViewer();
    final ArrayList<Long> removedComparedTours = removedTours.removedComparedTours;
    final ArrayList<Long> modifiedRefTours = new ArrayList<Long>();

    for (final Iterator<?> iterator = selection.iterator(); iterator.hasNext();) {

        final Object element = iterator.next();
        if (element instanceof TVICatalogRefTourItem) {

            /*
             * remove all compared tours from the current reference tour
             */

            final TVICatalogRefTourItem refTourItem = (TVICatalogRefTourItem) element;
            final Collection<StoredComparedTour> storedCompTours = TourCompareManager
                    .getComparedToursFromDb(refTourItem.refId).values();

            for (final StoredComparedTour storedComparedTour : storedCompTours) {

                final long compId = (storedComparedTour).comparedId;

                TourCompareManager.removeComparedTourFromDb(compId);

                // change selection
                removedComparedTours.add(compId);
            }

            /*
             * remove the reference tour from the tour and persist it
             */
            final EntityManager em = TourDatabase.getInstance().getEntityManager();
            final TourReference refTour = em.find(TourReference.class, refTourItem.refId);

            if (refTour != null) {

                // get the ref tour from the database
                final TourData tourData = refTour.getTourData();

                if (tourData.getTourReferences().remove(refTour)) {
                    TourDatabase.saveTour(tourData, false);

                    modifiedRefTours.add(tourData.getTourId());
                }

                // remove the ref tour from the fDataModel
                refTourItem.remove();

                // remove the ref tour from the tree
                tourViewer.remove(refTourItem);
            }

            em.close();
        }
    }

    if (modifiedRefTours.size() > 0) {
        TourManager.fireEventWithCustomData(TourEventId.UPDATE_UI, new SelectionTourIds(modifiedRefTours),
                null);
    }

    return true;
}

From source file:org.eclipse.cdt.cpp.ui.internal.editor.contentoutliner.CppContentOutlinePage.java

License:Open Source License

private void hackRedraw() {
    TreeViewer treeViewer = getTreeViewer();
    Tree tree = treeViewer.getTree();/* w  w w.j  a  v  a 2s.c o  m*/

    TreeItem[] items = tree.getItems();
    ArrayList newItems = _elementRoot.getAssociated(_elementRoot.getDataStore().getContentsRelation());
    if (newItems.size() > 0) {
        for (int i = 0; i < items.length; i++) {
            TreeItem item = items[i];
            Object data = item.getData();
            DataElement oldElement = (DataElement) data;

            if (newItems.size() > i) {
                DataElement newElement = (DataElement) newItems.get(i);
                if (oldElement != newElement) {
                    item.setData(newElement);
                    DataElementLabelProvider provider = (DataElementLabelProvider) treeViewer
                            .getLabelProvider();
                    // need to really do an update though to register properly
                    item.setText(provider.getText(newElement));
                    item.setImage(provider.getImage(newElement));
                    treeViewer.refresh(newElement);
                }
            } else {
                if (oldElement.isDeleted()) {
                    treeViewer.remove(oldElement);
                }
            }
        }

        for (int j = items.length; j < newItems.size(); j++) {
            DataElement newElement = (DataElement) newItems.get(j);
            TreeItem item = new TreeItem(tree, SWT.NONE);
            item.setData(newElement);

            DataElementLabelProvider provider = (DataElementLabelProvider) treeViewer.getLabelProvider();
            // need to really do an update though to register properly
            item.setText(provider.getText(newElement));
            item.setImage(provider.getImage(newElement));
            treeViewer.refresh(newElement);

        }
    }

}

From source file:org.eclipse.cdt.debug.internal.ui.views.AbstractDebugEventHandler.java

License:Open Source License

/**
 * Helper method to remove the given element from the tree viewer - 
 * must be called in UI thread.//from   ww  w.java 2s.  c  om
 */
protected void remove(Object element) {
    TreeViewer viewer = getTreeViewer();
    if (isAvailable() && viewer != null) {
        getView().showViewer();
        viewer.remove(element);
    }
}

From source file:org.eclipse.cdt.internal.ui.callhierarchy.CHRemoveFromView.java

License:Open Source License

@Override
public void run() {
    TreeViewer tree = fView.getTreeViewer();
    ITreeSelection selection = (ITreeSelection) tree.getSelection();
    tree.setSelection(null); // should stay before removal
    tree.remove(selection.toArray());
}

From source file:org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationView.java

License:Open Source License

/**
 * The given launch configuration has been added. Add it to the tree.
 * @param configuration the added configuration
 *///w  w w.  j av a2s . c  o m
private void handleConfigurationAdded(ILaunchConfiguration configuration, ILaunchConfiguration from) {
    TreeViewer viewer = getTreeViewer();
    if (viewer != null) {
        try {
            viewer.getControl().setRedraw(false);
            viewer.add(configuration.getType(), configuration);
            // if moved, remove original now
            if (from != null) {
                viewer.remove(from);
            }
            if (isAutoSelect()) {
                viewer.setSelection(new StructuredSelection(configuration), true);
            }
            updateFilterLabel();
        } catch (CoreException e) {
        } finally {
            viewer.getControl().setRedraw(true);
        }
    }
}