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); } } } } }
/** * 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)); }
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()); }
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)); }
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); } } }
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); }
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)); }
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)); }
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$ } }
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$ } }
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)); }
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)); }
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)); }
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)); }
/** * 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); }
/** * 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); }
/** * 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); } }
@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")); }
/** * 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"); } }; }
/** * 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)); } }
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); }
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); }
/** * 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()); } } }
@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(); }
@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; }); }
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; }
@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; }); }
/** * 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()); } } }
@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); } }
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(); }
/** * 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(); } } } } } }
@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; } }
@Override protected void insertClosingBrackets(IDocument document, ISelectionProvider selectionProvider, int offset) throws BadLocationException { document.replace(offset - 1, 1, "[ ]"); selectionProvider.setSelection(new TextSelection(offset + 1, 0)); }
@Override protected void insertClosingBrackets(IDocument document, ISelectionProvider selectionProvider, int offset) throws BadLocationException { document.replace(offset - 1, 1, "{ }"); selectionProvider.setSelection(new TextSelection(offset + 1, 0)); }
public BaseAction(InputType inputType, ISelectionProvider selectionProvider) { // setActionDefinitionId(getClass().getName()); _InputType = inputType; setSelectionProvider(selectionProvider); // ISelectionService selectionService = getSelectionService(); // selectionService.addPostSelectionListener(_SelectionServiceSelectionListener); }
/** * 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(); }
protected final ISelection getCurrentSelection() { ISelectionProvider selectionProvider = getSelectionProvider(); if (selectionProvider != null) { return selectionProvider.getSelection(); } return null; // ISelectionService selectionService = getSelectionService(); // return selectionService.getSelection(); }
@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 (); } }
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 ); }