Search in sources :

Example 86 with TreePath

use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.

the class GalleryTreeViewer method editElement.

public void editElement(Object element, int column) {
    if (element instanceof TreePath) {
        setSelection(new TreeSelection((TreePath) element));
        GalleryItem[] items = gallery.getSelection();
        if (items.length == 1) {
            ViewerRow row = getViewerRowFromItem(items[0]);
            if (row != null) {
                ViewerCell cell = row.getCell(column);
                if (cell != null) {
                    getControl().setRedraw(false);
                    triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
                    getControl().setRedraw(true);
                }
            }
        }
    } else {
        super.editElement(element, column);
    }
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ViewerRow(org.eclipse.jface.viewers.ViewerRow) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 87 with TreePath

use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.

the class ObjectTree method enableDropSupport.

/**
 * Enable drop support in object tree
 */
public // SubtreeType infrastructure
void enableDropSupport(// SubtreeType infrastructure
final ObjectBrowser obj) {
    final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
    objectTree.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(objectTree) {

        int operation = 0;

        @Override
        public boolean performDrop(Object data) {
            TreeSelection selection = (TreeSelection) data;
            List<?> movableSelection = selection.toList();
            for (int i = 0; i < movableSelection.size(); i++) {
                AbstractObject movableObject = (AbstractObject) movableSelection.get(i);
                TreePath path = selection.getPaths()[0];
                AbstractObject parent = (AbstractObject) path.getSegment(path.getSegmentCount() - 2);
                obj.performObjectMove((AbstractObject) getCurrentTarget(), parent, movableObject, operation == DND.DROP_MOVE ? true : false);
            }
            return true;
        }

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            this.operation = operation;
            if ((target == null) || !LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
                return false;
            IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
            if (selection.isEmpty())
                return false;
            for (final Object object : selection.toList()) {
                SubtreeType subtree = null;
                if ((object instanceof AbstractObject)) {
                    if (obj.isValidSelectionForMove(SubtreeType.INFRASTRUCTURE))
                        subtree = SubtreeType.INFRASTRUCTURE;
                    else if (obj.isValidSelectionForMove(SubtreeType.TEMPLATES))
                        subtree = SubtreeType.TEMPLATES;
                    else if (obj.isValidSelectionForMove(SubtreeType.BUSINESS_SERVICES))
                        subtree = SubtreeType.BUSINESS_SERVICES;
                    else if (obj.isValidSelectionForMove(SubtreeType.DASHBOARDS))
                        subtree = SubtreeType.DASHBOARDS;
                    else if (obj.isValidSelectionForMove(SubtreeType.MAPS))
                        subtree = SubtreeType.MAPS;
                    else if (obj.isValidSelectionForMove(SubtreeType.POLICIES))
                        subtree = SubtreeType.POLICIES;
                }
                if (subtree == null)
                    return false;
                Set<Integer> filter;
                switch(subtree) {
                    case INFRASTRUCTURE:
                        filter = ObjectSelectionDialog.createContainerSelectionFilter();
                        break;
                    case TEMPLATES:
                        filter = ObjectSelectionDialog.createTemplateGroupSelectionFilter();
                        break;
                    case BUSINESS_SERVICES:
                        filter = ObjectSelectionDialog.createBusinessServiceSelectionFilter();
                        break;
                    case DASHBOARDS:
                        if (object instanceof DashboardGroup)
                            filter = ObjectSelectionDialog.createDashboardGroupSelectionFilter();
                        else
                            filter = ObjectSelectionDialog.createDashboardSelectionFilter();
                        break;
                    case MAPS:
                        filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
                        break;
                    case POLICIES:
                        filter = ObjectSelectionDialog.createPolicyGroupSelectionFilter();
                        break;
                    default:
                        filter = null;
                        break;
                }
                if ((filter == null) || !filter.contains(((AbstractObject) target).getObjectClass()) || target.equals(object))
                    return false;
            }
            return true;
        }
    });
}
Also used : DashboardGroup(org.netxms.client.objects.DashboardGroup) Set(java.util.Set) HashSet(java.util.HashSet) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SubtreeType(org.netxms.ui.eclipse.objectbrowser.api.SubtreeType) TreePath(org.eclipse.jface.viewers.TreePath) TransferData(org.eclipse.swt.dnd.TransferData) TreeSelection(org.eclipse.jface.viewers.TreeSelection) AbstractObject(org.netxms.client.objects.AbstractObject) LocalSelectionTransfer(org.eclipse.jface.util.LocalSelectionTransfer) Transfer(org.eclipse.swt.dnd.Transfer) AbstractObject(org.netxms.client.objects.AbstractObject) List(java.util.List)

Example 88 with TreePath

use of org.eclipse.jface.viewers.TreePath in project n4js by eclipse.

the class N4JSProjectInWorkingSetDropAdapterAssistant method handleDrop.

@Override
public IStatus handleDrop(CommonDropAdapter dropAdapter, DropTargetEvent dropTargetEvent, Object target) {
    WorkingSet oldTarget = (WorkingSet) target;
    WorkingSetManager manager = oldTarget.getWorkingSetManager();
    List<WorkingSet> allItems = newArrayList(manager.getAllWorkingSets());
    List<WorkingSet> visibleItems = newArrayList(manager.getWorkingSets());
    WorkingSetDiffBuilder diffBuilder = new WorkingSetDiffBuilder(manager);
    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
    if (selection instanceof ITreeSelection) {
        ManualAssociationWorkingSet oldSource = null;
        for (TreePath path : ((ITreeSelection) selection).getPaths()) {
            IProject project = ((IAdaptable) path.getLastSegment()).getAdapter(IProject.class);
            if (project != null) {
                if (!(target instanceof ManualAssociationWorkingSet)) {
                    return CANCEL_STATUS;
                }
                if (!ManualAssociationAwareWorkingSetManager.class.getName().equals(manager.getId())) {
                    return CANCEL_STATUS;
                }
                if (!workingSetContains(oldTarget, project) && !OTHERS_WORKING_SET_ID.equals(oldTarget.getId())) {
                    Collection<String> projectNames = newHashSet(((ManualAssociationWorkingSet) oldTarget).getAssociatedProjectNames());
                    projectNames.add(project.getName());
                    ManualAssociationWorkingSet newTarget = new ManualAssociationWorkingSet(projectNames, oldTarget.getId(), manager);
                    int allIndex = indexOfById(oldTarget, allItems);
                    allItems.remove(allIndex);
                    allItems.add(allIndex, newTarget);
                    int visibleIndex = indexOfById(oldTarget, visibleItems);
                    if (visibleIndex >= 0) {
                        visibleItems.remove(visibleIndex);
                        visibleItems.add(visibleIndex, newTarget);
                    }
                    diffBuilder.edit(oldTarget, newTarget);
                    oldTarget = newTarget;
                }
                // Check if our top-level element is a working set so that we can perform a move
                if (path.getFirstSegment() instanceof ManualAssociationWorkingSet) {
                    if (oldSource == null) {
                        oldSource = ((ManualAssociationWorkingSet) path.getFirstSegment());
                    }
                    if (oldSource != null && !OTHERS_WORKING_SET_ID.equals(oldSource.getId())) {
                        Collection<String> projectNames = newHashSet(oldSource.getAssociatedProjectNames());
                        projectNames.remove(project.getName());
                        ManualAssociationWorkingSet newSource = new ManualAssociationWorkingSet(projectNames, oldSource.getId(), manager);
                        int allIndex = indexOfById(oldSource, allItems);
                        allItems.remove(allIndex);
                        allItems.add(allIndex, newSource);
                        int visibleIndex = indexOfById(oldSource, visibleItems);
                        if (visibleIndex >= 0) {
                            visibleItems.remove(visibleIndex);
                            visibleItems.add(visibleIndex, newSource);
                        }
                        diffBuilder.edit(oldSource, newSource);
                        oldSource = newSource;
                    }
                }
            } else if (path.getLastSegment() instanceof WorkingSet) {
                WorkingSet movedWorkingSet = (WorkingSet) path.getLastSegment();
                int sourceVisibleIndex = indexOfById(movedWorkingSet, visibleItems);
                int sourceAllIndex = indexOfById(movedWorkingSet, allItems);
                if (sourceVisibleIndex == -1 || sourceAllIndex == -1) {
                    return CANCEL_STATUS;
                }
                final Object currentTarget = getCommonDropAdapter().getCurrentTarget();
                if (currentTarget instanceof WorkingSet) {
                    int targetVisibleIndex = indexOfById((WorkingSet) currentTarget, visibleItems);
                    int targetAllIndex = indexOfById((WorkingSet) currentTarget, allItems);
                    if (targetVisibleIndex == -1 || targetAllIndex == -1) {
                        return CANCEL_STATUS;
                    }
                    if (getCommonDropAdapter().getCurrentLocation() == ViewerDropAdapter.LOCATION_AFTER) {
                        targetVisibleIndex++;
                        targetAllIndex++;
                    }
                    WorkingSet visibleRemoved = visibleItems.remove(sourceVisibleIndex);
                    visibleItems.add(sourceVisibleIndex >= targetVisibleIndex ? targetVisibleIndex : targetVisibleIndex - 1, visibleRemoved);
                    WorkingSet allRemoved = allItems.remove(sourceAllIndex);
                    allItems.add(sourceAllIndex >= targetAllIndex ? targetAllIndex : targetAllIndex - 1, allRemoved);
                } else {
                    return CANCEL_STATUS;
                }
            }
        }
    } else if (selection instanceof IStructuredSelection) {
        for (Object item : ((IStructuredSelection) selection).toArray()) {
            IProject project = ((IAdaptable) item).getAdapter(IProject.class);
            if (project != null && !workingSetContains(oldTarget, project) && !OTHERS_WORKING_SET_ID.equals(oldTarget.getId())) {
                Collection<String> projectNames = newHashSet(((ManualAssociationWorkingSet) oldTarget).getAssociatedProjectNames());
                projectNames.add(project.getName());
                ManualAssociationWorkingSet newTarget = new ManualAssociationWorkingSet(projectNames, oldTarget.getId(), manager);
                allItems.remove(oldTarget);
                allItems.add(newTarget);
                if (visibleItems.remove(oldTarget)) {
                    visibleItems.add(newTarget);
                }
                diffBuilder.edit(oldTarget, newTarget);
                oldTarget = newTarget;
            }
        }
    }
    WorkingSet[] newItems = Iterables.toArray(visibleItems, WorkingSet.class);
    WorkingSet[] newAllItems = Iterables.toArray(allItems, WorkingSet.class);
    Diff<WorkingSet> diff = diffBuilder.build(newItems, newAllItems);
    if (!diff.isEmpty()) {
        manager.updateState(diff);
        manager.saveState(new NullProgressMonitor());
        workingSetManagerBroker.refreshNavigator();
    }
    return OK_STATUS;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ManualAssociationAwareWorkingSetManager(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager) WorkingSetManager(org.eclipse.n4js.ui.workingsets.WorkingSetManager) IProject(org.eclipse.core.resources.IProject) ITreeSelection(org.eclipse.jface.viewers.ITreeSelection) WorkingSetDiffBuilder(org.eclipse.n4js.ui.workingsets.WorkingSetDiffBuilder) TreePath(org.eclipse.jface.viewers.TreePath) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet) ISelection(org.eclipse.jface.viewers.ISelection) Collection(java.util.Collection) WorkingSet(org.eclipse.n4js.ui.workingsets.WorkingSet) ManualAssociationWorkingSet(org.eclipse.n4js.ui.workingsets.ManualAssociationAwareWorkingSetManager.ManualAssociationWorkingSet)

Example 89 with TreePath

use of org.eclipse.jface.viewers.TreePath in project polymap4-core by Polymap4.

the class NavigatorContentServiceContentProvider method getParents.

public TreePath[] getParents(Object anElement) {
    List paths = new ArrayList();
    TreePathCompiler compiler = new TreePathCompiler(anElement);
    Set compilers = findPaths(compiler);
    for (Iterator iter = compilers.iterator(); iter.hasNext(); ) {
        TreePathCompiler c = (TreePathCompiler) iter.next();
        paths.add(c.createParentPath());
    }
    return (TreePath[]) paths.toArray(new TreePath[paths.size()]);
}
Also used : Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) TreePath(org.eclipse.jface.viewers.TreePath) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList)

Example 90 with TreePath

use of org.eclipse.jface.viewers.TreePath in project polymap4-core by Polymap4.

the class NavigatorSaveablesService method computeSaveables.

/**
 * helper to compute the saveables for which elements are part of the tree.
 * Must be called from a synchronized method.
 *
 * @return the saveables
 */
private Saveable[] computeSaveables() {
    ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
    boolean isTreepathContentProvider = contentProvider instanceof ITreePathContentProvider;
    Object viewerInput = viewer.getInput();
    List result = new ArrayList();
    Set roots = new HashSet(Arrays.asList(contentProvider.getElements(viewerInput)));
    SaveablesProvider[] saveablesProviders = getSaveablesProviders();
    for (int i = 0; i < saveablesProviders.length; i++) {
        SaveablesProvider saveablesProvider = saveablesProviders[i];
        Saveable[] saveables = saveablesProvider.getSaveables();
        for (int j = 0; j < saveables.length; j++) {
            Saveable saveable = saveables[j];
            Object[] elements = saveablesProvider.getElements(saveable);
            // the saveable is added to the result if at least one of the
            // elements representing the saveable appears in the tree, i.e.
            // if its parent chain leads to a root node.
            boolean foundRoot = false;
            for (int k = 0; !foundRoot && k < elements.length; k++) {
                Object element = elements[k];
                if (roots.contains(element)) {
                    result.add(saveable);
                    foundRoot = true;
                } else if (isTreepathContentProvider) {
                    ITreePathContentProvider treePathContentProvider = (ITreePathContentProvider) contentProvider;
                    TreePath[] parentPaths = treePathContentProvider.getParents(element);
                    for (int l = 0; !foundRoot && l < parentPaths.length; l++) {
                        TreePath parentPath = parentPaths[l];
                        for (int m = 0; !foundRoot && m < parentPath.getSegmentCount(); m++) {
                            if (roots.contains(parentPath.getSegment(m))) {
                                result.add(saveable);
                                foundRoot = true;
                            }
                        }
                    }
                } else {
                    while (!foundRoot && element != null) {
                        if (roots.contains(element)) {
                            // found a parent chain leading to a root. The
                            // saveable is part of the tree.
                            result.add(saveable);
                            foundRoot = true;
                        } else {
                            element = contentProvider.getParent(element);
                        }
                    }
                }
            }
        }
    }
    return (Saveable[]) result.toArray(new Saveable[result.size()]);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Saveable(org.eclipse.ui.Saveable) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) TreePath(org.eclipse.jface.viewers.TreePath) ITreePathContentProvider(org.eclipse.jface.viewers.ITreePathContentProvider) ArrayList(java.util.ArrayList) List(java.util.List) SaveablesProvider(org.eclipse.ui.navigator.SaveablesProvider) HashSet(java.util.HashSet)

Aggregations

TreePath (org.eclipse.jface.viewers.TreePath)104 TreeSelection (org.eclipse.jface.viewers.TreeSelection)55 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ArrayList (java.util.ArrayList)20 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)18 XSDComponent (org.eclipse.xsd.XSDComponent)14 Test (org.junit.Test)14 Iterator (java.util.Iterator)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)12 HashSet (java.util.HashSet)10 Set (java.util.Set)10 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)10 List (java.util.List)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 IProject (org.eclipse.core.resources.IProject)5 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5