/** * Creates a new TexlipseAnnotationUpdater and adds itself to the TexEditor via * <code>addPostSelectionChangedListener</code> * @param editor The TexEditor */ public TexlipseAnnotationUpdater (AbstractTextEditor editor) { //Add this listener to the current editors IPostSelectionListener (lazy update) ((IPostSelectionProvider) editor.getSelectionProvider()).addPostSelectionChangedListener(this); fEditor = editor; fEnabled = TexlipsePlugin.getDefault().getPreferenceStore().getBoolean( TexlipseProperties.TEX_EDITOR_ANNOTATATIONS); //Add a PropertyChangeListener TexlipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { String property = event.getProperty(); if (TexlipseProperties.TEX_EDITOR_ANNOTATATIONS.equals(property)) { boolean enabled = TexlipsePlugin.getDefault().getPreferenceStore().getBoolean( TexlipseProperties.TEX_EDITOR_ANNOTATATIONS); fEnabled = enabled; } } }); }
/** * 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()); } } }
/** * 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()); } } }
/** * 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) { return; } 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()); } }
/** * Sets a new {@link ISelectionProvider} for this * {@link SwitchingSelectionProvider}. Any {@link ISelectionChangedListener} * s that are registered with this {@link SwitchingSelectionProvider} will * receive {@link SelectionChangedEvent}s. The new * {@link ISelectionProvider} may be <code>null</code>. * * @param selectionProvider * a new {@link ISelectionProvider} to use (may be <code>null</code>) */ public void setSelectionProvider(final ISelectionProvider selectionProvider) { synchronized (currentWrappedProviderLock) { if (currentWrappedProvider != null) { currentWrappedProvider.removeSelectionChangedListener(selectionChangedListener); if (currentWrappedProvider instanceof IPostSelectionProvider) { ((IPostSelectionProvider) currentWrappedProvider).removePostSelectionChangedListener( postSelectionChangedListener); } } currentWrappedProvider = selectionProvider; if (selectionProvider != null) { selectionProvider.addSelectionChangedListener(selectionChangedListener); if (selectionProvider instanceof IPostSelectionProvider) { ((IPostSelectionProvider) selectionProvider).addPostSelectionChangedListener( postSelectionChangedListener); } } final ISelection selection = (selectionProvider != null ? selectionProvider.getSelection() : StructuredSelection.EMPTY); selectionChangedListener.fireChildListeners(selection); postSelectionChangedListener.fireChildListeners(selection); } }
protected void disconnect() { if(editor != null) { if (editor.getSelectionProvider() instanceof IPostSelectionProvider) { ((IPostSelectionProvider) editor.getSelectionProvider()).removePostSelectionChangedListener(this); } editor.getSite().getPage().removePartListener(partListener); editor = null; document = null; } }
private void connect() { Assert.isNotNull(fCurrentTarget); ITextViewer viewer = fCurrentTarget.getViewer(); Assert.isNotNull(viewer); fCurrentTarget.fWidget = viewer.getTextWidget(); if (fCurrentTarget.fWidget == null) leave(ILinkedModeListener.EXIT_ALL); if (fCurrentTarget.fKeyListener == null) { fCurrentTarget.fKeyListener = new KeyListener(); ((ITextViewerExtension) viewer).prependVerifyKeyListener(fCurrentTarget.fKeyListener); } else fCurrentTarget.fKeyListener.setEnabled(true); registerAutoEditVetoer(viewer); ((IPostSelectionProvider) viewer).addPostSelectionChangedListener(fSelectionListener); createAnnotationModel(); showSelection(); fCurrentTarget.fShell = fCurrentTarget.fWidget.getShell(); if (fCurrentTarget.fShell == null) leave(ILinkedModeListener.EXIT_ALL); fCurrentTarget.fShell.addShellListener(fCloser); fAssistant.install(viewer); viewer.addTextInputListener(fCloser); viewer.getDocument().addDocumentListener(fDocumentListener); }
private void disconnect() { Assert.isNotNull(fCurrentTarget); ITextViewer viewer = fCurrentTarget.getViewer(); Assert.isNotNull(viewer); viewer.getDocument().removeDocumentListener(fDocumentListener); fAssistant.uninstall(); fAssistant.removeProposalListener(fProposalListener); fCurrentTarget.fWidget = null; Shell shell = fCurrentTarget.fShell; fCurrentTarget.fShell = null; if (shell != null && !shell.isDisposed()) shell.removeShellListener(fCloser); // this one is asymmetric: we don't install the model in // connect, but leave it to its callers to ensure they // have the model installed if they need it uninstallAnnotationModel(fCurrentTarget); unregisterAutoEditVetoer(viewer); // don't remove the verify key listener to let it keep its position // in the listener queue if (fCurrentTarget.fKeyListener != null) fCurrentTarget.fKeyListener.setEnabled(false); ((IPostSelectionProvider) viewer).removePostSelectionChangedListener(fSelectionListener); redraw(); }
/** * Create the part control. * * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(Composite parent) { super.createPartControl(parent); // enable projection support (for code folder) ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer(); fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(), getSharedColors()); fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error"); fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning"); fProjectionSupport.install(); if (TexlipsePlugin.getDefault().getPreferenceStore().getBoolean(TexlipseProperties.CODE_FOLDING)) { projectionViewer.doOperation(ProjectionViewer.TOGGLE); } fAnnotationUpdater = new TexlipseAnnotationUpdater(this); ((IPostSelectionProvider) getSelectionProvider()).addPostSelectionChangedListener( new ISelectionChangedListener(){ public void selectionChanged(SelectionChangedEvent event) { //Delete all StatuslineErrors after selection changes documentModel.removeStatusLineErrorMessage(); } }); // register documentModel as documentListener // in initializeEditor this would cause NPE this.getDocumentProvider().getDocument(getEditorInput()).addDocumentListener(this.documentModel); this.documentModel.initializeModel(); this.documentModel.updateNow(); ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer instanceof ITextViewerExtension) { if (fBracketInserter == null) fBracketInserter = new BracketInserter(getSourceViewer(), this); ((ITextViewerExtension) sourceViewer).prependVerifyKeyListener(fBracketInserter); } }
/** * Installs this selection changed listener with the given selection * provider. If the selection provider is a post selection provider, * post selection changed events are the preferred choice, otherwise * normal selection changed events are requested. * * @param selectionProvider */ public void install(ISelectionProvider selectionProvider) { if (selectionProvider == null) return; if (selectionProvider instanceof IPostSelectionProvider) { IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; provider.addPostSelectionChangedListener(this); } else { selectionProvider.addSelectionChangedListener(this); } }
/** * Removes this selection changed listener from the given selection * provider. * * @param selectionProvider * the selection provider */ public void uninstall(ISelectionProvider selectionProvider) { if (selectionProvider == null) return; if (selectionProvider instanceof IPostSelectionProvider) { IPostSelectionProvider provider = (IPostSelectionProvider) selectionProvider; provider.removePostSelectionChangedListener(this); } else { selectionProvider.removeSelectionChangedListener(this); } }
public void activate(OutlinePage outlinePage) { this.outlinePage = outlinePage; treeViewer = outlinePage.getTreeViewer(); treeListener = new TreeListener(); treeViewer.addPostSelectionChangedListener(treeListener); treeViewer.addDoubleClickListener(treeListener); textViewer = outlinePage.getSourceViewer(); textListener = new TextListener(); ISelectionProvider textSelectionProvider = textViewer.getSelectionProvider(); if (textSelectionProvider instanceof IPostSelectionProvider) ((IPostSelectionProvider) textSelectionProvider).addPostSelectionChangedListener(textListener); else textSelectionProvider.addSelectionChangedListener(textListener); }
public void deactivate() { ISelectionProvider textSelectionProvider = textViewer.getSelectionProvider(); if (textSelectionProvider instanceof IPostSelectionProvider) ((IPostSelectionProvider) textSelectionProvider).removePostSelectionChangedListener(textListener); else textSelectionProvider.removeSelectionChangedListener(textListener); textListener = null; textViewer = null; treeViewer.removePostSelectionChangedListener(treeListener); treeViewer.removeDoubleClickListener(treeListener); treeViewer = null; treeListener = null; outlinePage = null; }
private void installSelectionChangedListener() { selectionChangedListener = new ISelectionChangedListener() { public void selectionChanged(final SelectionChangedEvent event) { updateStatusLine(); } }; final ISelectionProvider selectionProvider = getSelectionProvider(); if (selectionProvider instanceof IPostSelectionProvider) { final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) selectionProvider; postSelectionProvider.addPostSelectionChangedListener(selectionChangedListener); } else { getSelectionProvider().addSelectionChangedListener(selectionChangedListener); } }
private void uninstallSelectionChangedListener() { ISelectionProvider selectionProvider = getSelectionProvider(); if (selectionProvider != null) { if (selectionProvider instanceof IPostSelectionProvider) { final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider) selectionProvider; postSelectionProvider.removePostSelectionChangedListener(selectionChangedListener); } else { selectionProvider.removeSelectionChangedListener(selectionChangedListener); } } }
@Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { removePostSelectionListener(); if (selection instanceof ITextSelection && part instanceof AbstractTextEditor) { selection = new StructuredSelection(new AdaptableTextSelection(getViewer(), (ITextSelection) selection)); sourcePart = (AbstractTextEditor) part; ((IPostSelectionProvider) sourcePart.getSelectionProvider()) .addPostSelectionChangedListener(selectionChangedListener); sourcePart.getSite().getPage().addPartListener(partListener); } super.selectionChanged(part, selection); }
private void removePostSelectionListener() { if (sourcePart != null) { ((IPostSelectionProvider) sourcePart.getSelectionProvider()) .removePostSelectionChangedListener(selectionChangedListener); sourcePart = null; } }
public void install(ISelectionProvider selectionProvider) { if (selectionProvider == null) { return; } if (selectionProvider instanceof IPostSelectionProvider) { ((IPostSelectionProvider) selectionProvider).addPostSelectionChangedListener(this); } else { selectionProvider.addSelectionChangedListener(this); } }
public void uninstall(ISelectionProvider selectionProvider) { if (selectionProvider == null) { return; } if (selectionProvider instanceof IPostSelectionProvider) { ((IPostSelectionProvider) selectionProvider).removePostSelectionChangedListener(this); } else { selectionProvider.removeSelectionChangedListener(this); } }
private void setupSelectionListener(final IPostSelectionProvider postSelectionProvider) { final ISelectionChangedListener listener = new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { setSelection(event.getSelection()); } }; postSelectionProvider.addPostSelectionChangedListener(listener); totalComposite.addDisposeListener(new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { postSelectionProvider.removePostSelectionChangedListener(listener); } }); }
/** * Make this EnsembleSelectionProvider to listen to the * provided ISelectionProvider for changes. * * @see leave * @param provider */ public void follow(ISelectionProvider provider) { if (provider instanceof IPostSelectionProvider) { IPostSelectionProvider postProvider = (IPostSelectionProvider) provider; postProvider.addPostSelectionChangedListener(selectionChangedListener); } else { provider.addSelectionChangedListener(selectionChangedListener); } }
/** * Set this EnsembleSelectionProvider to no longer * follow the provided ISelectionProvider. * * @see follow * @param provider */ public void leave(ISelectionProvider provider) { provider.removeSelectionChangedListener(selectionChangedListener); if (provider instanceof IPostSelectionProvider) { IPostSelectionProvider postProvider = (IPostSelectionProvider) provider; postProvider.removePostSelectionChangedListener(selectionChangedListener); } }
/** * Installs this selection changed listener with the given selection provider. If * the selection provider is a post selection provider, post selection changed * events are the preferred choice, otherwise normal selection changed events * are requested. * * @param selectionProvider the selection provider */ public void install(ISelectionProvider selectionProvider) { if (selectionProvider == null) return; if (selectionProvider instanceof IPostSelectionProvider) { IPostSelectionProvider provider= (IPostSelectionProvider) selectionProvider; provider.addPostSelectionChangedListener(this); } else { selectionProvider.addSelectionChangedListener(this); } }
/** * Removes this selection changed listener from the given selection provider. * * @param selectionProvider the selection provider */ public void uninstall(ISelectionProvider selectionProvider) { if (selectionProvider == null) return; if (selectionProvider instanceof IPostSelectionProvider) { IPostSelectionProvider provider= (IPostSelectionProvider) selectionProvider; provider.removePostSelectionChangedListener(this); } else { selectionProvider.removeSelectionChangedListener(this); } }
/** * 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) { fireSelectionChanged(newDelegate.getSelection()); firePostSelectionChanged(newDelegate.getSelection()); return; } 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()); } }
public void setXtextEditor(final XtextEditor xtextEditor) { if (currentEditor != null) { removeTextSelectionListener(currentEditor); } if (language.equals(xtextEditor.getLanguageName())) { currentEditor = xtextEditor; ISelectionProvider selectionProvider = xtextEditor.getSelectionProvider(); if (selectionProvider instanceof IPostSelectionProvider) { ((IPostSelectionProvider) selectionProvider) .addPostSelectionChangedListener(textSelectionChangeListener); } else { selectionProvider.addSelectionChangedListener(textSelectionChangeListener); } } }
protected void removeTextSelectionListener(final XtextEditor editor) { ISelectionProvider selectionProvider = editor.getSelectionProvider(); if (selectionProvider != null) { if (selectionProvider instanceof IPostSelectionProvider) { ((IPostSelectionProvider) selectionProvider) .removePostSelectionChangedListener(textSelectionChangeListener); } else { selectionProvider.removeSelectionChangedListener(textSelectionChangeListener); } } }
/** * Add the selection changed listener * * @param selectionProvider */ private void addListener(ISelectionProvider selectionProvider, ISelectionChangedListener listener) { if (selectionProvider instanceof IPostSelectionProvider) { IPostSelectionProvider provider= (IPostSelectionProvider) selectionProvider; provider.addPostSelectionChangedListener(listener); } else { selectionProvider.addSelectionChangedListener(listener); } }
/** * Remove the selection changed listener * * @param selectionProvider */ private void removeListener(ISelectionProvider selectionProvider, ISelectionChangedListener listener) { if (selectionProvider instanceof IPostSelectionProvider) { IPostSelectionProvider provider= (IPostSelectionProvider) selectionProvider; provider.removePostSelectionChangedListener(listener); } else { selectionProvider.removeSelectionChangedListener(listener); } }
public void connect(XtextEditor editor, boolean isMarkOccurrences) { this.editor = editor; ((IPostSelectionProvider) editor.getSelectionProvider()) .addPostSelectionChangedListener(getSelectionChangedListener()); this.isMarkOccurrences = isMarkOccurrences; }
public void disconnect(XtextEditor editor) { ((IPostSelectionProvider) editor.getSelectionProvider()) .removePostSelectionChangedListener(getSelectionChangedListener()); }
@Override public void addPostSelectionChangedListener(ISelectionChangedListener listener) { super.addPostSelectionChangedListener(listener); if (getSourceViewer() != null && getSourceViewer().getSelectionProvider() instanceof IPostSelectionProvider) fPostSelectionListeners.add(listener); }