Java 类org.eclipse.jface.viewers.ISelectionProvider 实例源码

项目:convertigo-eclipse    文件:HtmlConnectorDesignComposite.java   
public void selectionChanged(SelectionChangedEvent event) {
    if (event.getSource() instanceof ISelectionProvider) {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        TreeObject treeObject = (TreeObject) selection.getFirstElement();
        if (treeObject != null) {
            ConnectorTreeObject connectorTreeObject = treeObject.getConnectorTreeObject();
            if (connectorTreeObject != null) {
                Connector connector =  (Connector)connectorTreeObject.getObject();
                if (connector.equals(htmlConnector)) {
                    if (treeObject instanceof TransactionTreeObject) {
                        if (!htmlConnector.isLearning())
                            toolLearn.setEnabled(true);
                    }
                    else {
                        if (!htmlConnector.isLearning())
                            toolLearn.setEnabled(false);
                    }
                }
                else {
                    if (!htmlConnector.isLearning())
                        toolLearn.setEnabled(false);
                }
            }
        }
    }
}
项目:pgcodekeeper    文件:ProjectEditorSelectionProvider.java   
/**
 * Ensures that IProject is present as first element
 * and DBPair is present as second element of the selection.
 */
private SelectionChangedEvent modifyEvent(SelectionChangedEvent event, DBPair dbPair) {
    ISelection selection = event.getSelection();
    if (selection.isEmpty()) {
        return defaultSelectionEvent;
    }
    if (!(selection instanceof IStructuredSelection)) {
        Log.log(Log.LOG_WARNING, "Cannot handle this selection type: " + selection.toString()); //$NON-NLS-1$
        // no way to deal with empty/other types of selections
        return defaultSelectionEvent;
    }

    IStructuredSelection sel = (IStructuredSelection) selection;
    List<?> elements = sel.toList();

    List<Object> newElements = new ArrayList<>(elements.size() + 2);
    newElements.add(proj);
    newElements.add(dbPair);
    newElements.addAll(elements);

    return new SelectionChangedEvent((ISelectionProvider) event.getSource(),
            new StructuredSelection(newElements));
}
项目:libraries    文件:CopyAction.java   
public CopyAction(final Display display, final ISelectionProvider selectionProvider) {
  this.display = display;
  this.selectionProvider = selectionProvider;
  setToolTipText("Copy");
  setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
  setDisabledImageDescriptor(PlatformUI
      .getWorkbench()
      .getSharedImages()
      .getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
  selectionProvider.addSelectionChangedListener(new ISelectionChangedListener() {

    @Override
    public void selectionChanged(final SelectionChangedEvent event) {
      setEnabled(!event.getSelection().isEmpty());
    }
  });
  setEnabled(!selectionProvider.getSelection().isEmpty());
}
项目:egradle    文件:GroovyBracketInsertionCompleter.java   
private void insertMultiLiner(BracketInsertion data, ISelectionProvider selectionProvider, int offset,
        IDocument document) throws BadLocationException {
    IRegion region = document.getLineInformationOfOffset(offset);
    if (region == null) {
        return;
    }
    int length = region.getLength();

    String textBeforeColumn = document.get(offset - length, length-1); //-1 to get not he bracket itself
    String relevantColumnsBefore = TextUtil.trimRightWhitespaces(textBeforeColumn);
    InsertionData result = support.prepareInsertionString(
            data.createMultiLineTemplate(SourceCodeInsertionSupport.CURSOR_VARIABLE), relevantColumnsBefore);

    document.replace(offset - 1, 1, result.getSourceCode());
    selectionProvider.setSelection(new TextSelection(offset + result.getCursorOffset() - 1, 0));

}
项目:team-explorer-everywhere    文件:AbstractCheckinControlView.java   
private void registerSubControlContextMenus() {
    final AbstractCheckinSubControl[] subControls = checkinControl.getSubControls();

    for (int i = 0; i < subControls.length; i++) {
        final MenuManager contextMenu = subControls[i].getContextMenu();
        final ISelectionProvider selectionProvider = subControls[i].getSelectionProvider();

        if (contextMenu != null && selectionProvider != null) {
            addAdditionsGroupToContextMenu(contextMenu);
            getViewSite().registerContextMenu(
                getViewSite().getId() + "." + subControls[i].getSubControlType().getID(), //$NON-NLS-1$
                contextMenu,
                selectionProvider);
        }
    }
}
项目:team-explorer-everywhere    文件:TeamExplorerBaseSection.java   
public void registerContextMenu(
    final TeamExplorerContext context,
    final Control control,
    final ISelectionProvider provider) {
    final MenuManager contextMenuManager = new MenuManager("#PopupMenu"); //$NON-NLS-1$
    contextMenuManager.setRemoveAllWhenShown(false);
    contextMenuManager.add(new Separator("group1")); //$NON-NLS-1$
    contextMenuManager.add(new Separator("group2")); //$NON-NLS-1$
    contextMenuManager.add(new Separator("group3")); //$NON-NLS-1$
    contextMenuManager.add(new Separator("group4")); //$NON-NLS-1$
    contextMenuManager.add(new Separator("group5")); //$NON-NLS-1$
    contextMenuManager.add(new Separator("group6")); //$NON-NLS-1$
    contextMenuManager.add(new Separator("group7")); //$NON-NLS-1$
    contextMenuManager.add(new Separator("group8")); //$NON-NLS-1$
    contextMenuManager.add(new Separator("group9")); //$NON-NLS-1$
    contextMenuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));

    final Menu menu = contextMenuManager.createContextMenu(control);
    control.setMenu(menu);

    context.getWorkbenchPart().getSite().registerContextMenu(EXTENSION_POINT_ID, contextMenuManager, provider);
}
项目:team-explorer-everywhere    文件:CompareChangeWithLatestVersionAction.java   
public CompareChangeWithLatestVersionAction(
    final ISelectionProvider selectionProvider,
    final TFSRepository repository,
    final CompareUIType compareUIType,
    final Shell shell) {
    super(selectionProvider, repository);

    Check.notNull(compareUIType, "compareUIType"); //$NON-NLS-1$
    Check.notNull(shell, "shell"); //$NON-NLS-1$

    this.compareUIType = compareUIType;
    this.shell = shell;

    setText(Messages.getString("CompareChangeWithLatestVersionAction.ActionText")); //$NON-NLS-1$
    setToolTipText(Messages.getString("CompareChangeWithLatestVersionAction.ActionTooltip")); //$NON-NLS-1$
    setImageDescriptor(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_COMPARE));
}
项目:team-explorer-everywhere    文件:CompareShelvedChangeWithUnmodifiedVersionAction.java   
public CompareShelvedChangeWithUnmodifiedVersionAction(
    final ISelectionProvider selectionProvider,
    final TFSRepository repository,
    final CompareUIType compareUIType,
    final String shelvesetName,
    final String shelvesetOwner,
    final Shell shell) {
    super(selectionProvider, repository);

    Check.notNull(compareUIType, "compareUIType"); //$NON-NLS-1$
    Check.notNull(shell, "shell"); //$NON-NLS-1$

    this.compareUIType = compareUIType;
    this.shell = shell;

    setShelvesetInfo(shelvesetName, shelvesetOwner);

    setText(Messages.getString("CompareShelvedChangeWithUnmodifiedVersionAction.ActionText")); //$NON-NLS-1$
    setToolTipText(Messages.getString("CompareShelvedChangeWithUnmodifiedVersionAction.ActionTooltip")); //$NON-NLS-1$
    setImageDescriptor(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_COMPARE));
}
项目:team-explorer-everywhere    文件:CompareChangeWithWorkspaceVersionAction.java   
public CompareChangeWithWorkspaceVersionAction(
    final ISelectionProvider selectionProvider,
    final TFSRepository repository,
    final CompareUIType compareUIType,
    final Shell shell) {
    super(selectionProvider, repository);

    Check.notNull(compareUIType, "compareUIType"); //$NON-NLS-1$
    Check.notNull(shell, "shell"); //$NON-NLS-1$

    this.compareUIType = compareUIType;
    this.shell = shell;

    setImageDescriptor(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_COMPARE));

    if (repository != null) {
        setRepository(repository);
    } else {
        setText(Messages.getString("CompareChangeWithWorkspaceVersionAction.ActionText")); //$NON-NLS-1$
        setToolTipText(Messages.getString("CompareChangeWithWorkspaceVersionAction.ActionTooltip")); //$NON-NLS-1$
    }
}
项目:team-explorer-everywhere    文件:ComparePendingChangeWithWorkspaceVersionAction.java   
public ComparePendingChangeWithWorkspaceVersionAction(
    final ISelectionProvider selectionProvider,
    final TFSRepository repository,
    final CompareUIType compareUIType,
    final Shell shell) {
    super(selectionProvider, repository);

    Check.notNull(compareUIType, "compareUIType"); //$NON-NLS-1$
    Check.notNull(shell, "shell"); //$NON-NLS-1$

    this.compareUIType = compareUIType;
    this.shell = shell;

    setImageDescriptor(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_COMPARE));

    if (repository != null) {
        setRepository(repository);
    } else {
        setText(Messages.getString("ComparePendingChangeWithWorkspaceVersionAction.ActionText")); //$NON-NLS-1$
        setToolTipText(Messages.getString("ComparePendingChangeWithWorkspaceVersionAction.ActionTooltip")); //$NON-NLS-1$
    }
}
项目:team-explorer-everywhere    文件:ViewPendingChangeAction.java   
public ViewPendingChangeAction(
    final ISelectionProvider selectionProvider,
    final TFSRepository repository,
    final boolean inModalContext,
    final ViewVersionType viewVersionType) {
    super(selectionProvider, repository);

    Check.notNull(viewVersionType, "viewVersionType"); //$NON-NLS-1$

    this.inModalContext = inModalContext;
    this.viewVersionType = viewVersionType;

    setText(viewVersionType.getText());
    setToolTipText(viewVersionType.getTooltipText());
    setImageDescriptor(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_VIEW));
}
项目:team-explorer-everywhere    文件:CompareShelvedChangeWithLatestVersionAction.java   
public CompareShelvedChangeWithLatestVersionAction(
    final ISelectionProvider selectionProvider,
    final TFSRepository repository,
    final CompareUIType compareUIType,
    final String shelvesetName,
    final String shelvesetOwner,
    final Shell shell) {
    super(selectionProvider, repository);

    Check.notNull(compareUIType, "compareUIType"); //$NON-NLS-1$
    Check.notNull(shell, "shell"); //$NON-NLS-1$

    this.compareUIType = compareUIType;
    this.shell = shell;

    setShelvesetInfo(shelvesetName, shelvesetOwner);

    final String text = Messages.getString("CompareShelvedChangeWithLatestVersionAction.ActionText"); //$NON-NLS-1$
    setText(text);
    setToolTipText(text);
    setImageDescriptor(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_COMPARE));
}
项目:team-explorer-everywhere    文件:CompareChangeWithPreviousVersionAction.java   
public CompareChangeWithPreviousVersionAction(
    final ISelectionProvider selectionProvider,
    final TFSRepository repository,
    final CompareUIType compareUIType,
    final Shell shell) {
    super(selectionProvider, repository);

    Check.notNull(compareUIType, "compareUIType"); //$NON-NLS-1$
    Check.notNull(shell, "shell"); //$NON-NLS-1$

    this.compareUIType = compareUIType;
    this.shell = shell;

    setText(Messages.getString("CompareChangeWithPreviousVersionAction.ActionText")); //$NON-NLS-1$
    setToolTipText(Messages.getString("CompareChangeWithPreviousVersionAction.ActionTooltip")); //$NON-NLS-1$
    setImageDescriptor(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_COMPARE));
}
项目:team-explorer-everywhere    文件:ComparePendingChangeWithLatestVersionAction.java   
public ComparePendingChangeWithLatestVersionAction(
    final ISelectionProvider selectionProvider,
    final TFSRepository repository,
    final CompareUIType compareUIType,
    final Shell shell) {
    super(selectionProvider, repository);

    Check.notNull(compareUIType, "compareUIType"); //$NON-NLS-1$
    Check.notNull(shell, "shell"); //$NON-NLS-1$

    this.compareUIType = compareUIType;
    this.shell = shell;

    final String text = Messages.getString("ComparePendingChangeWithLatestVersionAction.ActionText"); //$NON-NLS-1$
    setText(text);
    setToolTipText(text);
    setImageDescriptor(TFSCommonUIImages.getImageDescriptor(TFSCommonUIImages.IMG_COMPARE));
}
项目:team-explorer-everywhere    文件:SelectionProviderAction.java   
/**
 * Creates a new {@link SelectionProviderAction}, supplying an initial
 * {@link ISelectionProvider} to track. This {@link SelectionProviderAction}
 * is initially disabled. If subclasses wish to perform immediate
 * enablement, they must manually call {@link #selectionChanged(ISelection)}
 * in the subclass constructor.
 *
 * @param selectionProvider
 *        initial {@link ISelectionProvider} or <code>null</code>
 */
protected SelectionProviderAction(final ISelectionProvider selectionProvider) {
    /*
     * create a selection changed listener
     */
    selectionChangedListener = new ISelectionChangedListener() {
        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            SelectionProviderAction.this.selectionChanged(event);
        }
    };

    /*
     * start tracking the specified provider
     */
    setSelectionProvider(selectionProvider);
}
项目:team-explorer-everywhere    文件:VersionControlEditor.java   
/**
 * Create the menu extension points to allow plugins (including this one) to
 * add menu items.
 */
private void registerMenus(final String menuId, final Control control, final ISelectionProvider selectionProvider) {
    final MenuManager menuMgr = new MenuManager("#PopupMenu"); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown(false);
    menuMgr.add(new Separator("group0")); //$NON-NLS-1$
    menuMgr.add(new Separator("group1")); //$NON-NLS-1$
    menuMgr.add(new Separator("group2")); //$NON-NLS-1$
    menuMgr.add(new Separator("group3")); //$NON-NLS-1$
    menuMgr.add(new Separator("group4")); //$NON-NLS-1$
    menuMgr.add(new Separator("group5")); //$NON-NLS-1$
    menuMgr.add(new Separator("group6")); //$NON-NLS-1$
    menuMgr.add(new Separator("group7")); //$NON-NLS-1$
    menuMgr.add(new Separator("group8")); //$NON-NLS-1$
    menuMgr.add(new Separator("group9")); //$NON-NLS-1$

    menuMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    final Menu menu = menuMgr.createContextMenu(control);
    control.setMenu(menu);
    getSite().registerContextMenu(menuId, menuMgr, selectionProvider);
}
项目:mesfavoris    文件:ToggleLinkAction.java   
/**
 * Select the bookmark corresponding to the selection in given
 * {@link IWorkbenchPart}
 * 
 * @param part
 */
private void selectBookmarkFromLinkedPart(IWorkbenchPart part) {
    ISelectionProvider provider = part.getSite().getSelectionProvider();
    if (provider == null) {
        updateLinkImage(true);
        return;
    }

    ISelection selection = provider.getSelection();
    if (selection == null) {
        updateLinkImage(true);
        return;
    }
    GetLinkedBookmarksOperation getLinkedBookmarksOperation = new GetLinkedBookmarksOperation(bookmarkDatabase);
    List<Bookmark> bookmarks = getLinkedBookmarksOperation.getLinkedBookmarks(part, selection);
    if (bookmarks.isEmpty()) {
        updateLinkImage(true);
        return;
    }
    updateLinkImage(false);
    Bookmark selectedBookmark = bookmarksTreeViewer.getSelectedBookmark();
    if (selectedBookmark == null || !bookmarks.contains(selectedBookmark)) {
        bookmarksTreeViewer.setSelection(new StructuredSelection(bookmarks.get(0)), true);
    }
}
项目:mesfavoris    文件:ProxySelectionProviderTest.java   
@Test
public void testSetCurrentSelectionProvider() {
    // Given
    ISelectionProvider selectionProvider = new TestSelectionProvider();
    ISelectionChangedListener listener1 = mock(ISelectionChangedListener.class);
    ISelectionChangedListener listener2 = mock(ISelectionChangedListener.class);
    proxySelectionProvider.addSelectionChangedListener(listener1);

    // When
    proxySelectionProvider.setCurrentSelectionProvider(selectionProvider);
    proxySelectionProvider.addSelectionChangedListener(listener2);
    selectionProvider.setSelection(new StructuredSelection("my selection"));

    // Then
    ArgumentCaptor<SelectionChangedEvent> captor = ArgumentCaptor.forClass(SelectionChangedEvent.class);
    verify(listener1).selectionChanged(captor.capture());
    assertThat(captor.getValue().getSelection()).isEqualTo(new StructuredSelection("my selection"));
    verify(listener2).selectionChanged(captor.capture());
    assertThat(captor.getValue().getSelection()).isEqualTo(new StructuredSelection("my selection"));

}
项目:tlaplus    文件:UIHelper.java   
/**
 * Retrieves the selection provider for files in the active editor
 * 
 * @return
 */
public static ISelectionProvider getActiveEditorFileSelectionProvider() {
    return new GenericSelectionProvider() {

        public ISelection getSelection() {
            IEditorInput input = getActiveEditor().getEditorInput();
            if (input instanceof FileEditorInput) {
                IFile resource = ((FileEditorInput) input).getFile();
                return new StructuredSelection(resource);
            }
            return null;
        }

        public void setSelection(ISelection selection) {
            throw new UnsupportedOperationException("This selection provider is read-only");
        }

    };
}
项目:tlaplus    文件:UIHelper.java   
/**
 * Tries to set the given message on the workbench's status line. This is a
 * best effort method which fails to set the status line if there is no
 * active editor present from where the statuslinemanager can be looked up.
 * 
 * @param msg
 *            The message to be shown on the status line
 */
public static void setStatusLineMessage(final String msg) {
    IStatusLineManager statusLineManager = null;
    ISelectionProvider selectionService = null;

    // First try to get the StatusLineManager from the IViewPart and only
    // resort back to the editor if a view isn't active right now.
    final IWorkbenchPart workbenchPart = getActiveWindow().getActivePage().getActivePart();
    if (workbenchPart instanceof IViewPart) {
        final IViewPart viewPart = (IViewPart) workbenchPart;
        statusLineManager = viewPart.getViewSite().getActionBars().getStatusLineManager();
        selectionService = viewPart.getViewSite().getSelectionProvider();
    } else if (getActiveEditor() != null) {
        final IEditorSite editorSite = getActiveEditor().getEditorSite();
        statusLineManager = editorSite.getActionBars().getStatusLineManager();
        selectionService = editorSite.getSelectionProvider();
    }

    if (statusLineManager != null && selectionService != null) {
        statusLineManager.setMessage(msg);
        selectionService.addSelectionChangedListener(new StatusLineMessageEraser(statusLineManager,
                selectionService));
    }
}
项目:tlaplus    文件:TLAEditor.java   
public Object getAdapter(@SuppressWarnings("rawtypes") Class required)
{
    /* adapt to projection support */
    if (projectionSupport != null)
    {
        Object adapter = projectionSupport.getAdapter(getSourceViewer(), required);
        if (adapter != null)
            return adapter;
    }

    if (ISelectionProvider.class.equals(required))
    {
        return getSelectionProvider();
    }

    return super.getAdapter(required);
}
项目:typescript.java    文件:TypeScriptEditor.java   
protected void doSelectionChanged(SelectionChangedEvent event) {
    ISelection selection = event.getSelection();
    NavigationBarItem item = null;
    Iterator iter = ((IStructuredSelection) selection).iterator();
    while (iter.hasNext()) {
        Object o = iter.next();
        if (o instanceof NavigationBarItem) {
            item = (NavigationBarItem) o;
            break;
        }
    }

    setSelection(item, !isActivePart());

    ISelectionProvider selectionProvider = getSelectionProvider();
    if (selectionProvider == null)
        return;

    ISelection textSelection = selectionProvider.getSelection();
    if (!(textSelection instanceof ITextSelection))
        return;

    fForcedMarkOccurrencesSelection = textSelection;
    updateOccurrenceAnnotations((ITextSelection) textSelection);

}
项目:Source    文件:SelectionProviderIntermediate.java   
/**
 * Sets a new selection provider to delegate to. Selection listeners registered with the previous delegate
 * are removed before.
 * 
 * @param newDelegate
 *            new selection provider
 */
public void setSelectionProviderDelegate(ISelectionProvider newDelegate) {
    if (delegate != newDelegate) {
        if (delegate != null) {
            delegate.removeSelectionChangedListener(selectionListener);
            if (delegate instanceof IPostSelectionProvider) {
                ((IPostSelectionProvider)delegate).removePostSelectionChangedListener(
                        postSelectionListener);
            }
        }
        delegate = newDelegate;
        if (newDelegate != null) {
            newDelegate.addSelectionChangedListener(selectionListener);
            if (newDelegate instanceof IPostSelectionProvider) {
                ((IPostSelectionProvider)newDelegate).addPostSelectionChangedListener(
                        postSelectionListener);
            }
            fireSelectionChanged(newDelegate.getSelection());
            firePostSelectionChanged(newDelegate.getSelection());
        }
    }
}
项目:Source    文件:SelectionProviderIntermediate.java   
/**
 * Sets a new selection provider to delegate to. Selection listeners registered with the previous delegate
 * are removed before.
 * 
 * @param newDelegate
 *            new selection provider
 */
public void setSelectionProviderDelegate(ISelectionProvider newDelegate) {
    if (delegate != newDelegate) {
        if (delegate != null) {
            delegate.removeSelectionChangedListener(selectionListener);
            if (delegate instanceof IPostSelectionProvider) {
                ((IPostSelectionProvider)delegate).removePostSelectionChangedListener(
                        postSelectionListener);
            }
        }
        delegate = newDelegate;
        if (newDelegate != null) {
            newDelegate.addSelectionChangedListener(selectionListener);
            if (newDelegate instanceof IPostSelectionProvider) {
                ((IPostSelectionProvider)newDelegate).addPostSelectionChangedListener(
                        postSelectionListener);
            }
            fireSelectionChanged(newDelegate.getSelection());
            firePostSelectionChanged(newDelegate.getSelection());
        }
    }
}
项目:statecharts    文件:RenameElementHandler.java   
@Override
public boolean isEnabled() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return false;
    }
    IWorkbenchPartSite site = window.getActivePage().getActiveEditor().getSite();
    if (site == null) {
        return false;
    }
    ISelectionProvider selectionProvider = site.getSelectionProvider();
    if (selectionProvider == null) {
        return false;
    }
    ISelection currentSelection = selectionProvider.getSelection();
    setContext(refactoring, currentSelection);
    return refactoring.isExecutable();
}
项目:hssd    文件:EntryEditorAddElement.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    return watchedExecute(() ->{
        final EntryEditor editor = getActiveEntryEditor();
        ISelectionProvider sp = editor.getSite().getSelectionProvider();
        IStructuredSelection sel = (IStructuredSelection)sp.getSelection();
        TreeNode parent = (TreeNode)sel.getFirstElement();

        String name = ElementHelper.mkName(parent, null);

        parent = ElementHelper.copyOnNeed(parent, editor);
        if(parent == null) {
            return null;
        }

        ElementHelper.addElement(parent, name);

        editor.refresh(parent, true);
        editor.markDirty();
        return null;
    });
}
项目:hssd    文件:AbstractCommandHandler.java   
protected List<EntryData> getSelectedEntries() {
    final HSSDEditor editor = getActiveHSSDEditor();
       if(editor == null) {
           return null;
       }

       ISelectionProvider sp = editor.getSite().getSelectionProvider();
       IStructuredSelection sel = (IStructuredSelection)sp.getSelection();

       List<EntryData> rv = new ArrayList<>(sel.size());
       for(Iterator<?> itr = sel.iterator(); itr.hasNext();) {
           rv.add(EntryData.of((com.insweat.hssd.lib.tree.structured.TreeNode)
                           itr.next()));
       }
       return rv;
}
项目:hssd    文件:EntryEditorInheritElements.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    return watchedExecute(()->{
        final EntryEditor editor = getActiveEntryEditor();
        ISelectionProvider sp = editor.getSite().getSelectionProvider();
        IStructuredSelection sel = (IStructuredSelection)sp.getSelection();
        TreeNode parent = (TreeNode)sel.getFirstElement();

        ValueData parentVD = ValueData.of(parent);
        if(!parentVD.valueTree().isOverridden(parent.path())) {
            return null;
        }

        if(parent.childCount() > 0 &&
                !ElementHelper.warnRemoveElements(parent, editor)) {
            return null;
        }
        ElementHelper.removeChildren(parent, true);

        editor.refresh(parent, true);
        editor.markDirty();
        return null;
    });
}
项目:PDFReporter-Studio    文件:MultiPageToolbarEditorSite.java   
/**
 * The <code>MultiPageEditorSite</code> implementation of this <code>IWorkbenchPartSite</code> method remembers the
 * selection provider, and also hooks a listener on it, which calls <code>handleSelectionChanged</code> when a
 * selection changed event occurs.
 * 
 * @param provider
 *          The selection provider.
 * @see MultiPageEditorSite#handleSelectionChanged(SelectionChangedEvent)
 */
public void setSelectionProvider(ISelectionProvider provider) {
    ISelectionProvider oldSelectionProvider = selectionProvider;
    selectionProvider = provider;
    if (oldSelectionProvider != null) {
        oldSelectionProvider.removeSelectionChangedListener(getSelectionChangedListener());
        if (oldSelectionProvider instanceof IPostSelectionProvider) {
            ((IPostSelectionProvider) oldSelectionProvider)
                    .removePostSelectionChangedListener(getPostSelectionChangedListener());
        } else {
            oldSelectionProvider.removeSelectionChangedListener(getPostSelectionChangedListener());
        }
    }
    if (selectionProvider != null) {
        selectionProvider.addSelectionChangedListener(getSelectionChangedListener());
        if (selectionProvider instanceof IPostSelectionProvider) {
            ((IPostSelectionProvider) selectionProvider).addPostSelectionChangedListener(getPostSelectionChangedListener());
        } else {
            selectionProvider.addSelectionChangedListener(getPostSelectionChangedListener());
        }
    }
}
项目:gama    文件:EditorSearchControls.java   
@Override
public void modifyText(final ModifyEvent e) {

    boolean wrap = true;
    final String text = find.getText();
    if (lastText.startsWith(text)) {
        wrap = false;
    }
    lastText = text;
    if (EMPTY.equals(text) || "".equals(text)) {
        adjustEnablement(false, null);
        final ISelectionProvider selectionProvider = editor.getSelectionProvider();
        if (selectionProvider != null) {
            final ISelection selection = selectionProvider.getSelection();
            if (selection instanceof TextSelection) {
                final ITextSelection textSelection = (ITextSelection) selection;
                selectionProvider.setSelection(new TextSelection(textSelection.getOffset(), 0));
            }
        }
    } else {
        find(true, true, wrap);
    }
}
项目:gama    文件:GamlSearchField.java   
public void search() {
    final IWorkbenchPart part = WorkbenchHelper.getActivePart();
    if (part instanceof IEditorPart) {
        final IEditorPart editor = (IEditorPart) part;
        final IWorkbenchPartSite site = editor.getSite();
        if (site != null) {
            final ISelectionProvider provider = site.getSelectionProvider();
            if (provider != null) {
                final ISelection viewSiteSelection = provider.getSelection();
                if (viewSiteSelection instanceof TextSelection) {
                    final TextSelection textSelection = (TextSelection) viewSiteSelection;
                    text.setText(textSelection.getText());
                }
            }
        }

    }
    activate(null);
    text.setFocus();

}
项目:mytourbook    文件:Util.java   
/**
 * Clear all selection providers in all workench pages.
 */
public static void clearSelection() {

    final IWorkbenchWindow wbWin = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (wbWin != null) {

        final IWorkbenchPage[] wbPages = wbWin.getPages();
        for (final IWorkbenchPage wbPage : wbPages) {

            final IWorkbenchPart wbWinPagePart = wbPage.getActivePart();
            if (wbWinPagePart != null) {

                final IWorkbenchPartSite site = wbWinPagePart.getSite();
                if (site != null) {

                    final ISelectionProvider selectionProvider = site.getSelectionProvider();

                    if (selectionProvider instanceof PostSelectionProvider) {
                        ((PostSelectionProvider) selectionProvider).clearSelection();
                    }
                }
            }
        }
    }
}
项目:eclipse-batch-editor    文件:BatchBracketInsertionCompleter.java   
@Override
public void keyReleased(KeyEvent e) {
    InsertClosingBracketsSupport insertClosingBracketsSupport = getInsertionSupport(e);
    if (insertClosingBracketsSupport == null) {
        return;
    }
    /*
     * do not use last caret start - because the listener ordering could be
     * different
     */
    ISelectionProvider selectionProvider = this.batchEditor.getSelectionProvider();
    if (selectionProvider == null) {
        return;
    }
    ISelection selection = selectionProvider.getSelection();
    if (!(selection instanceof ITextSelection)) {
        return;
    }
    boolean enabled = getPreferences().getBooleanPreference(P_EDITOR_AUTO_CREATE_END_BRACKETSY);
    if (!enabled) {
        return;
    }
    ITextSelection textSelection = (ITextSelection) selection;
    int offset = textSelection.getOffset();

    try {
        IDocument document = this.batchEditor.getDocument();
        if (document == null) {
            return;
        }
        insertClosingBracketsSupport.insertClosingBrackets(document, selectionProvider, offset);
    } catch (BadLocationException e1) {
        /* ignore */
        return;
    }

}
项目:eclipse-batch-editor    文件:BatchBracketInsertionCompleter.java   
@Override
protected void insertClosingBrackets(IDocument document, ISelectionProvider selectionProvider, int offset)
        throws BadLocationException {
    document.replace(offset - 1, 1, "[ ]");
    selectionProvider.setSelection(new TextSelection(offset + 1, 0));

}
项目:eclipse-batch-editor    文件:BatchBracketInsertionCompleter.java   
@Override
protected void insertClosingBrackets(IDocument document, ISelectionProvider selectionProvider, int offset)
        throws BadLocationException {
    document.replace(offset - 1, 1, "{ }");
    selectionProvider.setSelection(new TextSelection(offset + 1, 0));

}
项目:eZooKeeper    文件:BaseAction.java   
public BaseAction(InputType inputType, ISelectionProvider selectionProvider) {
    // setActionDefinitionId(getClass().getName());
    _InputType = inputType;

    setSelectionProvider(selectionProvider);

    // ISelectionService selectionService = getSelectionService();
    // selectionService.addPostSelectionListener(_SelectionServiceSelectionListener);
}
项目:eZooKeeper    文件:BaseAction.java   
/**
 * Sets the selectionProvider.
 * 
 * @param selectionProvider the selectionProvider to set
 */
public final void setSelectionProvider(ISelectionProvider selectionProvider) {

    if (_SelectionProvider != null) {

        if (_SelectionProviderSelectionChangedListener != null) {
            _SelectionProvider.removeSelectionChangedListener(_SelectionProviderSelectionChangedListener);

        }
        if (_SelectionProvider instanceof Viewer) {
            unhookViewer((Viewer) _SelectionProvider);
        }
    }

    _SelectionProvider = selectionProvider;

    if (_SelectionProvider != null) {

        if (_SelectionProviderSelectionChangedListener == null) {
            _SelectionProviderSelectionChangedListener = new SelectionProviderSelectionChangedListener();
        }

        _SelectionProvider.addSelectionChangedListener(_SelectionProviderSelectionChangedListener);

        if (_SelectionProvider instanceof Viewer) {
            hookViewer((Viewer) _SelectionProvider);
        }
    }

    updateState();
}
项目:eZooKeeper    文件:BaseAction.java   
protected final ISelection getCurrentSelection() {
    ISelectionProvider selectionProvider = getSelectionProvider();
    if (selectionProvider != null) {
        return selectionProvider.getSelection();
    }

    return null;

    // ISelectionService selectionService = getSelectionService();
    // return selectionService.getSelection();
}
项目:neoscada    文件:ChartActionBarContributor.java   
@Override
public void update ()
{
    final ISelectionProvider selectionProvider = this.activeEditorPart instanceof ISelectionProvider ? (ISelectionProvider)this.activeEditorPart : this.activeEditorPart.getSite ().getSelectionProvider ();

    if ( selectionProvider != null )
    {
        final ISelection selection = selectionProvider.getSelection ();
        final IStructuredSelection structuredSelection = selection instanceof IStructuredSelection ? (IStructuredSelection)selection : StructuredSelection.EMPTY;

        this.deleteAction.updateSelection ( structuredSelection );
        this.cutAction.updateSelection ( structuredSelection );
        this.copyAction.updateSelection ( structuredSelection );
        this.pasteAction.updateSelection ( structuredSelection );

        if ( this.validateAction != null )
        {
            this.validateAction.updateSelection ( structuredSelection );
        }

        if ( this.controlAction != null )
        {
            this.controlAction.updateSelection ( structuredSelection );
        }

        if ( this.saveAsAction != null )
        {
            this.saveAsAction.selectionChanged ( structuredSelection );
        }
    }

    this.undoAction.update ();
    this.redoAction.update ();

    if ( this.loadResourceAction != null )
    {
        this.loadResourceAction.update ();
    }
}
项目:neoscada    文件:MonitorsViewTable.java   
protected void hookContextMenu ( final Control control, final ISelectionProvider selectionProvider, final IViewSite viewSite )
{
    final MenuManager menuMgr = new MenuManager ( "#PopupMenu" ); //$NON-NLS-1$
    menuMgr.setRemoveAllWhenShown ( true );
    menuMgr.addMenuListener ( new IMenuListener () {
        @Override
        public void menuAboutToShow ( final IMenuManager manager )
        {
            fillContextMenu ( manager );
        }
    } );
    final Menu menu = menuMgr.createContextMenu ( control );
    control.setMenu ( menu );
    viewSite.registerContextMenu ( menuMgr, selectionProvider );
}