@Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (part.equals(this)) return; fLastSelectionProvider= part; if (fLinking) computeAndSetInput(part); }
public void run() { if (currentCount != fComputeCount) return; final IJavaElement je= findSelectedJavaElement(part, selection); if (isIgnoringNewInput(je, part, selection)) return; // The actual computation final Object input= computeInput(je); if (input == null) return; Shell shell= getSite().getShell(); if (shell.isDisposed()) return; Display display= shell.getDisplay(); if (display.isDisposed()) return; display.asyncExec(new Runnable() { /* * @see java.lang.Runnable#run() */ public void run() { if (fComputeCount != currentCount || getViewSite().getShell().isDisposed()) return; fCurrentViewInput= je; doSetInput(input); } }); } };
@Override public final void createPartControl(Composite parent) { internalCreatePartControl(parent); inititalizeColors(); getSite().getWorkbenchWindow().getPartService().addPartListener(fPartListener); createContextMenu(); createActions(); fillActionBars(getViewSite().getActionBars()); PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), getHelpContextId()); }
@Override public void propertyChange(PropertyChangeEvent event) { String property= event.getProperty(); if (property.equals(getBackgroundColorKey()) || property.equals(getForegroundColorKey())) { inititalizeColors(); } }
@Override public void propertyChange(PropertyChangeEvent event) { if (getBackgroundColorKey().equals(event.getProperty())) inititalizeColors(); }
private void inititalizeColors() { if (getSite().getShell().isDisposed()) return; Display display= getSite().getShell().getDisplay(); if (display == null || display.isDisposed()) return; setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); ColorRegistry registry= JFaceResources.getColorRegistry(); registry.addListener(this); fBackgroundColorRGB= registry.getRGB(getBackgroundColorKey()); Color bgColor; if (fBackgroundColorRGB == null) { bgColor= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); fBackgroundColorRGB= bgColor.getRGB(); } else { bgColor= new Color(display, fBackgroundColorRGB); fBackgroundColor= bgColor; } setBackground(bgColor); }
/** * Fills the actions bars. * <p> * Subclasses may extend. * * @param actionBars the action bars */ protected void fillActionBars(IActionBars actionBars) { IToolBarManager toolBar= actionBars.getToolBarManager(); fillToolBar(toolBar); IAction action; action= getCopyToClipboardAction(); if (action != null) actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), action); action= getSelectAllAction(); if (action != null) actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), action); IHandlerService handlerService= getSite().getService(IHandlerService.class); handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkAction)); }
/** * Creates the context menu for this view. */ protected void createContextMenu() { MenuManager menuManager= new MenuManager("#PopupMenu"); //$NON-NLS-1$ menuManager.setRemoveAllWhenShown(true); menuManager.addMenuListener(this); Menu contextMenu= menuManager.createContextMenu(getControl()); getControl().setMenu(contextMenu); getSite().registerContextMenu(menuManager, getSelectionProvider()); }
ISelection methodSelection = guessMethodNamePosition(document, (ITextSelection)selection); return findSelectedJavaElement(part, methodSelection); return findJavaElement(element);
/** * Fills the actions bars. * <p> * Subclasses may extend. * * @param actionBars the action bars */ protected void fillActionBars(IActionBars actionBars) { IToolBarManager toolBar= actionBars.getToolBarManager(); fillToolBar(toolBar); IAction action; action= getCopyToClipboardAction(); if (action != null) actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), action); action= getSelectAllAction(); if (action != null) actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), action); }
protected void createActions() { super.createActions(); fSelectAllAction= new SelectAllAction(getControl(), (SelectionProvider)getSelectionProvider()); }
@Override protected void fillActionBars(IActionBars actionBars) { super.fillActionBars(actionBars); actionBars.setGlobalActionHandler(JdtActionConstants.OPEN, fOpen); fOpen.setActionDefinitionId(IJavaEditorActionDefinitionIds.OPEN_EDITOR); }
protected IJavaElement findSelectedJavaElement(IWorkbenchPart part, ISelection selection) { IJavaElement element; try { element= super.findSelectedJavaElement(part, selection); if (element == null && part instanceof JavaEditor && selection instanceof ITextSelection) { JavaEditor editor= (JavaEditor)part; ITextSelection textSelection= (ITextSelection)selection; IDocumentProvider documentProvider= editor.getDocumentProvider(); if (documentProvider == null) return null; IDocument document= documentProvider.getDocument(editor.getEditorInput()); if (document == null) return null; ITypedRegion typedRegion= TextUtilities.getPartition(document, IJavaPartitions.JAVA_PARTITIONING, textSelection.getOffset(), false); if (IJavaPartitions.JAVA_DOC.equals(typedRegion.getType())) return TextSelectionConverter.getElementAtOffset((JavaEditor)part, textSelection); else return null; } else return element; } catch (JavaModelException e) { return null; } catch (BadLocationException e) { return null; } }
/** * Computes the input for this view based on the given elements * * @param part the part that triggered the current element update, or <code>null</code> * @param selection the new selection, or <code>null</code> * @param element the new java element that will be displayed, or <code>null</code> * @param monitor a progress monitor * @return the input or <code>null</code> if the input was not computed successfully * @since 3.4 */ protected Object computeInput(IWorkbenchPart part, ISelection selection, IJavaElement element, IProgressMonitor monitor) { return computeInput(element); }
@Override protected void fillToolBar(IToolBarManager tbm) { tbm.add(fBackAction); tbm.add(fForthAction); tbm.add(new Separator()); super.fillToolBar(tbm); tbm.add(fOpenBrowserAction); }
/** * Finds and returns the Java element selected in the given part. * * @param part the workbench part for which to find the selected Java element * @param selection the selection * @return the selected Java element */ protected IJavaElement findSelectedJavaElement(IWorkbenchPart part, ISelection selection) { Object element; try { if (part instanceof JavaEditor && selection instanceof ITextSelection) { IJavaElement[] elements= TextSelectionConverter.codeResolve((JavaEditor)part, (ITextSelection)selection); if (elements != null && elements.length > 0) return elements[0]; else return null; } else if (selection instanceof IStructuredSelection) { element= SelectionUtil.getSingleElement(selection); } else { return null; } } catch (JavaModelException e) { return null; } return findJavaElement(element); }
private void inititalizeColors() { if (getSite().getShell().isDisposed()) return; Display display= getSite().getShell().getDisplay(); if (display == null || display.isDisposed()) return; setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); ColorRegistry registry= JFaceResources.getColorRegistry(); registry.addListener(this); fBackgroundColorRGB= registry.getRGB(getBackgroundColorKey()); Color bgColor; if (fBackgroundColorRGB == null) { bgColor= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); fBackgroundColorRGB= bgColor.getRGB(); } else { bgColor= new Color(display, fBackgroundColorRGB); fBackgroundColor= bgColor; } setBackground(bgColor); }
/** * Fills the actions bars. * <p> * Subclasses may extend. * * @param actionBars the action bars */ protected void fillActionBars(IActionBars actionBars) { IToolBarManager toolBar= actionBars.getToolBarManager(); fillToolBar(toolBar); IAction action; action= getCopyToClipboardAction(); if (action != null) actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), action); action= getSelectAllAction(); if (action != null) actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), action); IHandlerService handlerService= getSite().getService(IHandlerService.class); handlerService.activateHandler(IWorkbenchCommandConstants.NAVIGATE_TOGGLE_LINK_WITH_EDITOR, new ActionHandler(fToggleLinkAction)); }
/** * Creates the context menu for this view. */ protected void createContextMenu() { MenuManager menuManager= new MenuManager("#PopupMenu"); //$NON-NLS-1$ menuManager.setRemoveAllWhenShown(true); menuManager.addMenuListener(this); Menu contextMenu= menuManager.createContextMenu(getControl()); getControl().setMenu(contextMenu); getSite().registerContextMenu(menuManager, getSelectionProvider()); }
ISelection methodSelection = guessMethodNamePosition(document, (ITextSelection)selection); return findSelectedJavaElement(part, methodSelection); return findJavaElement(element);