Example usage for org.eclipse.jface.viewers StructuredSelection equals

List of usage examples for org.eclipse.jface.viewers StructuredSelection equals

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers StructuredSelection equals.

Prototype

@Override
public boolean equals(Object o) 

Source Link

Document

Returns whether this structured selection is equal to the given object.

Usage

From source file:ccw.editors.outline.ClojureOutlinePage.java

License:Open Source License

private void selectInOutline(ISelection selection) {
    TreeViewer viewer = getTreeViewer();
    lastSelection = selection;//from  w  w w.  j  av  a2s.c om
    if (viewer != null && selection instanceof TextSelection) {
        TextSelection textSelection = (TextSelection) selection;
        int line = textSelection.getStartLine();
        StructuredSelection newSelection = findClosest(line + 1);
        ISelection oldSelection = viewer.getSelection();
        if (!newSelection.equals(oldSelection)) {
            viewer.setSelection(newSelection);
        }
    }
}

From source file:org.eclipse.cdt.mylyn.internal.ui.CDTEditorMonitor.java

License:Open Source License

/**
 * Only public for testing//  w w  w.  j  a v a  2  s.c  o m
 */
@Override
public void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection,
        boolean contributeToContext) {
    try {
        ICElement selectedElement = null;
        if (selection instanceof StructuredSelection) {
            StructuredSelection structuredSelection = (StructuredSelection) selection;

            if (structuredSelection.equals(currentSelection)) {
                return;
            }
            currentSelection = structuredSelection;

            // Object selectedObject =
            // structuredSelection.getFirstElement();
            for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
                Object selectedObject = iterator.next();
                if (selectedObject instanceof ICElement) {
                    ICElement checkedElement = checkIfAcceptedAndPromoteIfNecessary((ICElement) selectedObject);
                    if (checkedElement == null) {
                        return;
                    } else {
                        selectedElement = checkedElement;
                    }
                }
                if (selectedElement != null) {
                    super.handleElementSelection(part, selectedElement, contributeToContext);
                }
            }
        } else {
            if (part instanceof CEditor) {
                currentEditor = (CEditor) part;
                selectedElement = SelectionConverter.getElementAtOffset(currentEditor);
                if (selectedElement == null)
                    return; // nothing selected

                if (selectedElement != null) {
                    if (selectedElement.equals(lastSelectedElement)) {
                        super.handleElementEdit(part, selectedElement, contributeToContext);
                    } else if (!selectedElement.equals(lastSelectedElement)) {
                        super.handleElementSelection(part, selectedElement, contributeToContext);
                    }
                }

                ICElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(selectedElement);
                if (checkedElement == null) {
                    return;
                } else {
                    selectedElement = checkedElement;
                }
            }
        }
        if (selectedElement != null) {
            lastSelectedElement = selectedElement;
        }
    } catch (CModelException e) {
        // ignore, fine to fail to resolve an element if the model is not
        // up-to-date
    }
}

From source file:org.eclipse.dltk.internal.mylyn.DLTKEditingMonitor.java

License:Open Source License

/**
 * Only public for testing. Note: Two sequential selections on the same element are deemed to be an edit of the
 * selection as this is the best guess that can be made. See bug 252306.
 *//*from w w w  . j a v  a 2  s  .co  m*/
@Override
public void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection,
        boolean contributeToContext) {
    try {
        IModelElement selectedElement = null;
        if (selection instanceof StructuredSelection) {
            StructuredSelection structuredSelection = (StructuredSelection) selection;

            if (structuredSelection.equals(currentSelection)) {
                return;
            }
            currentSelection = structuredSelection;

            for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
                Object selectedObject = iterator.next();
                if (selectedObject instanceof IModelElement) {
                    IModelElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(
                            (IModelElement) selectedObject);
                    if (checkedElement == null) {
                        return;
                    } else {
                        selectedElement = checkedElement;
                    }
                }
                if (selectedElement != null) {
                    super.handleElementSelection(part, selectedElement, contributeToContext);
                }
            }
        } else {
            if (selection instanceof TextSelection && part instanceof IEditorPart) {
                currentEditor = (IEditorPart) part;
                TextSelection textSelection = (TextSelection) selection;
                selectedElement = SelectionConverter.resolveEnclosingElement(currentEditor, textSelection);
                if (selectedElement instanceof IPackageDeclaration) {
                    // HACK: ignoring these selections
                    return;
                }
                IModelElement[] resolved = SelectionConverter.codeResolve(currentEditor);
                if (resolved != null && resolved.length == 1 && !resolved[0].equals(selectedElement)) {
                    lastResolvedElement = resolved[0];
                }

                boolean selectionResolved = false;
                if (selectedElement instanceof IMethod && lastSelectedElement instanceof IMethod) {
                    // navigation between two elements
                    if (lastResolvedElement != null && lastSelectedElement != null
                            && lastResolvedElement.equals(selectedElement)
                            && !lastSelectedElement.equals(lastResolvedElement)) {
                        super.handleNavigation(part, selectedElement, DLTKReferencesProvider.ID,
                                contributeToContext);
                        selectionResolved = true;
                    } else if (lastSelectedElement != null && lastSelectedElement.equals(lastResolvedElement)
                            && !lastSelectedElement.equals(selectedElement)) {
                        super.handleNavigation(part, selectedElement, DLTKReferencesProvider.ID,
                                contributeToContext);
                        selectionResolved = true;
                    }
                } else if (selectedElement != null && lastSelectedElement != null
                        && !lastSelectedElement.equals(selectedElement)) {
                    if (lastSelectedElement.getElementName().equals(selectedElement.getElementName())) {
                        // navigation between two elements
                        if (selectedElement instanceof IMethod && lastSelectedElement instanceof IMethod) {
                            super.handleNavigation(part, selectedElement, DLTKImplementorsProvider.ID,
                                    contributeToContext);
                            selectionResolved = true;
                        } else if (selectedElement instanceof IType && lastSelectedElement instanceof IType) {
                            super.handleNavigation(part, selectedElement, DLTKImplementorsProvider.ID,
                                    contributeToContext);
                            selectionResolved = true;
                        }
                    }
                }
                if (selectedElement != null) {
                    // selection of an element
                    if (!selectionResolved && selectedElement.equals(lastSelectedElement)) {
                        super.handleElementEdit(part, selectedElement, contributeToContext);
                    } else if (!selectedElement.equals(lastSelectedElement)) {
                        super.handleElementSelection(part, selectedElement, contributeToContext);
                    }
                }

                IModelElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(selectedElement);
                if (checkedElement == null) {
                    return;
                } else {
                    selectedElement = checkedElement;
                }
            }
        }
        if (selectedElement != null) {
            lastSelectedElement = selectedElement;
        }
    } catch (ModelException e) {
        // ignore, fine to fail to resolve an element if the model is not up-to-date
    } catch (Throwable t) {
        StatusHandler.log(new Status(IStatus.ERROR, DLTKUiBridgePlugin.ID_PLUGIN,
                "Failed to update model based on selection", t)); //$NON-NLS-1$
    }
}

From source file:org.eclipse.jubula.client.alm.mylyn.ui.bridge.monitor.UserInteractionMonitor.java

License:Open Source License

/** {@inheritDoc} */
protected void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection,
        boolean contributeToContext) {
    if (selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        if (structuredSelection.equals(m_oldSelection)) {
            return;
        }/*from  w w  w  .  j a va 2  s.  c om*/
        m_oldSelection = structuredSelection;
        if (structuredSelection != null) {
            for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
                Object selectedObject = iterator.next();
                if (selectedObject instanceof INodePO || selectedObject instanceof IReusedProjectPO) {
                    super.handleElementSelection(part, selectedObject, contributeToContext);
                }
            }
        }
    }
}

From source file:org.eclipse.mylyn.internal.cdt.ui.CDTEditorMonitor.java

License:Open Source License

/**
 * Only public for testing//from  w w w  . j  a v  a 2 s  .  c  o m
 */
@Override
public void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection,
        boolean contributeToContext) {
    try {
        ICElement selectedElement = null;
        if (selection instanceof StructuredSelection) {
            StructuredSelection structuredSelection = (StructuredSelection) selection;

            if (structuredSelection.equals(currentSelection)) {
                return;
            }
            currentSelection = structuredSelection;

            // Object selectedObject =
            // structuredSelection.getFirstElement();
            for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
                Object selectedObject = iterator.next();
                if (selectedObject instanceof ICElement) {
                    ICElement checkedElement = checkIfAcceptedAndPromoteIfNecessary((ICElement) selectedObject);
                    if (checkedElement == null) {
                        return;
                    } else {
                        selectedElement = checkedElement;
                    }
                }
                if (selectedElement != null) {
                    super.handleElementSelection(part, selectedElement, contributeToContext);
                }
            }
        } else {
            if (part instanceof CEditor) {
                currentEditor = (CEditor) part;
                selectedElement = SelectionConverter.getElementAtOffset(currentEditor);
                if (selectedElement == null) {
                    return; // nothing selected
                }

                if (selectedElement != null) {
                    if (selectedElement.equals(lastSelectedElement)) {
                        super.handleElementEdit(part, selectedElement, contributeToContext);
                    } else if (!selectedElement.equals(lastSelectedElement)) {
                        super.handleElementSelection(part, selectedElement, contributeToContext);
                    }
                }

                ICElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(selectedElement);
                if (checkedElement == null) {
                    return;
                } else {
                    selectedElement = checkedElement;
                }
            }
        }
        if (selectedElement != null) {
            lastSelectedElement = selectedElement;
        }
    } catch (CModelException e) {
        // ignore, fine to fail to resolve an element if the model is not
        // up-to-date
    }
}

From source file:org.eclipse.mylyn.internal.java.ui.JavaEditingMonitor.java

License:Open Source License

/**
 * Only public for testing. Note: Two sequential selections on the same element are deemed to be an edit of the
 * selection as this is the best guess that can be made. See bug 252306.
 *///  www  .j a va2  s  .c  o m
@Override
public void handleWorkbenchPartSelection(IWorkbenchPart part, ISelection selection,
        boolean contributeToContext) {
    try {
        IJavaElement selectedElement = null;
        if (selection instanceof StructuredSelection) {
            StructuredSelection structuredSelection = (StructuredSelection) selection;

            if (structuredSelection.equals(currentSelection)) {
                return;
            }
            currentSelection = structuredSelection;

            for (Iterator<?> iterator = structuredSelection.iterator(); iterator.hasNext();) {
                Object selectedObject = iterator.next();
                if (selectedObject instanceof IJavaElement) {
                    IJavaElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(
                            (IJavaElement) selectedObject);
                    if (checkedElement == null) {
                        return;
                    } else {
                        selectedElement = checkedElement;
                    }
                }
                if (selectedElement != null) {
                    super.handleElementSelection(part, selectedElement, contributeToContext);
                }
            }
        } else {
            if (selection instanceof TextSelection && part instanceof JavaEditor) {
                currentEditor = (JavaEditor) part;
                TextSelection textSelection = (TextSelection) selection;
                selectedElement = SelectionConverter.resolveEnclosingElement(currentEditor, textSelection);
                if (selectedElement instanceof IPackageDeclaration) {
                    // HACK: ignoring these selections
                    return;
                }
                IJavaElement[] resolved = SelectionConverter.codeResolve(currentEditor);
                if (resolved != null && resolved.length == 1 && !resolved[0].equals(selectedElement)) {
                    lastResolvedElement = resolved[0];
                }

                boolean selectionResolved = false;
                if (selectedElement instanceof IMethod && lastSelectedElement instanceof IMethod) {
                    // navigation between two elements
                    if (lastResolvedElement != null && lastSelectedElement != null
                            && lastResolvedElement.equals(selectedElement)
                            && !lastSelectedElement.equals(lastResolvedElement)) {
                        super.handleNavigation(part, selectedElement, JavaReferencesProvider.ID,
                                contributeToContext);
                        selectionResolved = true;
                    } else if (lastSelectedElement != null && lastSelectedElement.equals(lastResolvedElement)
                            && !lastSelectedElement.equals(selectedElement)) {
                        super.handleNavigation(part, selectedElement, JavaReferencesProvider.ID,
                                contributeToContext);
                        selectionResolved = true;
                    }
                } else if (selectedElement != null && lastSelectedElement != null
                        && !lastSelectedElement.equals(selectedElement)) {
                    if (lastSelectedElement.getElementName().equals(selectedElement.getElementName())) {
                        // navigation between two elements
                        if (selectedElement instanceof IMethod && lastSelectedElement instanceof IMethod) {
                            super.handleNavigation(part, selectedElement, JavaImplementorsProvider.ID,
                                    contributeToContext);
                            selectionResolved = true;
                        } else if (selectedElement instanceof IType && lastSelectedElement instanceof IType) {
                            super.handleNavigation(part, selectedElement, JavaImplementorsProvider.ID,
                                    contributeToContext);
                            selectionResolved = true;
                        }
                    }
                }
                if (selectedElement != null) {
                    // selection of an element
                    if (!selectionResolved && selectedElement.equals(lastSelectedElement)) {
                        super.handleElementEdit(part, selectedElement, contributeToContext);
                    } else if (!selectedElement.equals(lastSelectedElement)) {
                        super.handleElementSelection(part, selectedElement, contributeToContext);
                    }
                }

                IJavaElement checkedElement = checkIfAcceptedAndPromoteIfNecessary(selectedElement);
                if (checkedElement == null) {
                    return;
                } else {
                    selectedElement = checkedElement;
                }
            }
        }
        if (selectedElement != null) {
            lastSelectedElement = selectedElement;
        }
    } catch (JavaModelException e) {
        // ignore, fine to fail to resolve an element if the model is not up-to-date
    } catch (Throwable t) {
        StatusHandler.log(new Status(IStatus.ERROR, JavaUiBridgePlugin.ID_PLUGIN,
                "Failed to update model based on selection", t)); //$NON-NLS-1$
    }
}

From source file:org.talend.dataprofiler.core.ui.views.DQRespositoryView.java

License:Open Source License

/**
 * DOC Zqin Comment method "showSelectedElements".
 * //from ww  w.java  2s.c o m
 * MOD 2009-01-07 mzhao for feature:0005664
 * 
 * @param newTree
 */
public void showSelectedElements(Object selectedElement) {
    try {
        // MOD by zshen for bug 12940 refresh the viewer to collapse all the element.
        StructuredSelection structSel = new StructuredSelection(selectedElement);
        getCommonViewer().setSelection(structSel);

        // If not select,unfold tree structure to this column.
        StructuredSelection selectionTarge = (StructuredSelection) getCommonViewer().getSelection();
        if (!selectionTarge.equals(structSel)) {
            getCommonViewer().refresh();
            StructuredSelection recursiveExpandTree = recursiveExpandTree(selectedElement);
            if (recursiveExpandTree != null) {
                structSel = recursiveExpandTree;
            }
            getCommonViewer().setSelection(structSel);
        }
        this.setFocus();
    } catch (Exception e) {
        log.error(e, e);
    }
}

From source file:org.talend.designer.core.ui.editor.TalendTabbedPropertySheetPage.java

License:Open Source License

@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    ISelection newSelection;//w w  w  .  j a  va 2 s.  c  om
    if (part instanceof AbstractMultiPageTalendEditor) {
        AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) part;
        newSelection = mpte.getTalendEditor().getViewer().getSelection();
        if (selection instanceof StructuredSelection) {
            StructuredSelection structSel = (StructuredSelection) newSelection;
            if (structSel.size() != 1) {
                return;
            }
            if (structSel.getFirstElement() instanceof EditPart) {
                if (structSel.equals(oldSelection)) {
                    // if (getCurrentTab() != null) {
                    // getCurrentTab().setInput(part, selection);
                    // }
                } else {
                    super.selectionChanged(part, selection);
                }
                oldSelection = structSel;
            }
        }
    } else if (part instanceof ContentOutline) {
        ContentOutline outline = (ContentOutline) part;
        newSelection = outline.getSelection();
        if (selection instanceof StructuredSelection) {
            StructuredSelection structSel = (StructuredSelection) newSelection;
            if (structSel.size() != 1) {
                return;
            }
            if (structSel.getFirstElement() instanceof NodeTreeEditPart) {
                if (structSel.equals(oldSelection)) {
                    // this.getCurrentTab().setInput(part, selection);
                } else {
                    super.selectionChanged(part, selection);
                }
                oldSelection = structSel;
            }
        }
    }
}