@Override public void partDeactivated(IWorkbenchPart part) { disposeMenuItems(); }
public static void fillMenu(IMenuManager menu, CompilationUnitEditor editor, SurroundWithTryCatchAction surroundWithTryCatchAction, SurroundWithTryMultiCatchAction surroundWithTryMultiCatchAction) { IAction[] actions= getTemplateActions(editor); surroundWithTryCatchAction.update(editor.getSelectionProvider().getSelection()); boolean addSurroundWithTryCatchAction= surroundWithTryCatchAction.isEnabled() && !isInJavadoc(editor); boolean addSurroundWithTryMultiCatchAction= surroundWithTryMultiCatchAction.isEnabled() && !isInJavadoc(editor); if ((actions == null || actions.length == 0) && (!addSurroundWithTryCatchAction && !addSurroundWithTryMultiCatchAction)) { menu.add(NONE_APPLICABLE_ACTION); } else { if (addSurroundWithTryCatchAction) menu.add(surroundWithTryCatchAction); if (addSurroundWithTryMultiCatchAction) menu.add(surroundWithTryMultiCatchAction); menu.add(new Separator(TEMPLATE_GROUP)); for (int i= 0; actions != null && i < actions.length; i++) menu.add(actions[i]); } menu.add(new Separator(CONFIG_GROUP)); menu.add(new ConfigureTemplatesAction()); }
protected void fillMenu(IMenuManager menu) { SurroundWithTryCatchAction surroundWithTryCatch= createSurroundWithTryCatchAction(editor); SurroundWithTemplateMenuAction.fillMenu(menu, editor, surroundWithTryCatch); } }).run();
private static IAction[] getTemplateActions(JavaEditor editor) { ITextSelection textSelection= getTextSelection(editor); if (textSelection == null || textSelection.getLength() == 0) return null; ICompilationUnit cu= JavaUI.getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()); if (cu == null) return null; QuickTemplateProcessor quickTemplateProcessor= new QuickTemplateProcessor(); IInvocationContext context= new AssistContext(cu, textSelection.getOffset(), textSelection.getLength()); try { IJavaCompletionProposal[] proposals= quickTemplateProcessor.getAssists(context, null); if (proposals == null || proposals.length == 0) return null; return getActionsFromProposals(proposals, context.getSelectionOffset(), editor.getViewer()); } catch (CoreException e) { JavaPlugin.log(e); } return null; }
IAction[] actions= getTemplateActions(editor); SurroundWithTryCatchAction surroundAction= createSurroundWithTryCatchAction(editor); ActionContributionItem surroundItem= new ActionContributionItem(surroundAction); surroundItem.fill(menu, -1);
@Override public void dispose() { if (fPartService != null) { fPartService.removePartListener(fPartListener); fPartService= null; } setMenu(null); }
public static void fillMenu(IMenuManager menu, CompilationUnitEditor editor, SurroundWithTryCatchAction surroundWithTryCatchAction) { IAction[] actions= getTemplateActions(editor); surroundWithTryCatchAction.update(editor.getSelectionProvider().getSelection()); if (actions == null && !surroundWithTryCatchAction.isEnabled()) { menu.add(NONE_APPLICABLE_ACTION); } else { menu.add(surroundWithTryCatchAction); menu.add(new Separator(TEMPLATE_GROUP)); if (actions == null) { menu.add(NONE_APPLICABLE_ACTION); } else { for (int i= 0; i < actions.length; i++) { menu.add(actions[i]); } } } menu.add(new Separator(CONFIG_GROUP)); menu.add(new ConfigureTemplatesAction()); }
return null; return getActionsFromProposals(proposals, context.getSelectionOffset(), editor.getViewer()); } catch (CoreException e) { JavaPlugin.log(e);
private static boolean isInJavadoc(JavaEditor editor) { ITextSelection selection= getTextSelection(editor); if (selection == null) return false; IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput()); try { String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, selection.getOffset(), true); return contentType.equals(IJavaPartitions.JAVA_DOC); } catch (BadLocationException e) { return false; } }
public static void fillMenu(IMenuManager menu, CompilationUnitEditor editor, SurroundWithTryCatchAction surroundWithTryCatchAction, SurroundWithTryMultiCatchAction surroundWithTryMultiCatchAction) { IAction[] actions= getTemplateActions(editor); surroundWithTryCatchAction.update(editor.getSelectionProvider().getSelection()); boolean addSurroundWithTryCatchAction= surroundWithTryCatchAction.isEnabled() && !isInJavadoc(editor); boolean addSurroundWithTryMultiCatchAction= surroundWithTryMultiCatchAction.isEnabled() && !isInJavadoc(editor); if ((actions == null || actions.length == 0) && (!addSurroundWithTryCatchAction && !addSurroundWithTryMultiCatchAction)) { menu.add(NONE_APPLICABLE_ACTION); } else { if (addSurroundWithTryCatchAction) menu.add(surroundWithTryCatchAction); if (addSurroundWithTryMultiCatchAction) menu.add(surroundWithTryMultiCatchAction); menu.add(new Separator(TEMPLATE_GROUP)); for (int i= 0; actions != null && i < actions.length; i++) menu.add(actions[i]); } menu.add(new Separator(CONFIG_GROUP)); menu.add(new ConfigureTemplatesAction()); }
public void menuAboutToShow(IMenuManager manager) { manager.removeAll(); SurroundWithTemplateMenuAction.fillMenu(manager, fEditor, fSurroundWithTryCatchAction); } });
private static IAction[] getTemplateActions(JavaEditor editor) { ITextSelection textSelection= getTextSelection(editor); if (textSelection == null || textSelection.getLength() == 0) return null; ICompilationUnit cu= JavaUI.getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()); if (cu == null) return null; QuickTemplateProcessor quickTemplateProcessor= new QuickTemplateProcessor(); IInvocationContext context= new AssistContext(cu, textSelection.getOffset(), textSelection.getLength()); try { IJavaCompletionProposal[] proposals= quickTemplateProcessor.getAssists(context, null); if (proposals == null || proposals.length == 0) return null; return getActionsFromProposals(proposals, context.getSelectionOffset(), editor.getViewer()); } catch (CoreException e) { JavaPlugin.log(e); } return null; }
/** * {@inheritDoc} */ public void dispose() { if (fPartService != null) { fPartService.removePartListener(fPartListener); fPartService= null; } setMenu(null); }
private static boolean isInJavadoc(JavaEditor editor) { ITextSelection selection= getTextSelection(editor); if (selection == null) return false; IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput()); try { String contentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, selection.getOffset(), true); return contentType.equals(IJavaPartitions.JAVA_DOC); } catch (BadLocationException e) { return false; } }
IAction[] actions= getTemplateActions(editor); boolean addSurroundWith= !isInJavadoc(editor); if (addSurroundWith) { SurroundWithTryCatchAction surroundWithTryCatch= SurroundWithActionGroup.createSurroundWithTryCatchAction(editor);
@Override public void menuAboutToShow(IMenuManager manager) { manager.removeAll(); SurroundWithTemplateMenuAction.fillMenu(manager, fEditor, fSurroundWithTryCatchAction, fSurroundWithTryMultiCatchAction); } });
@Override public void dispose() { if (fPartService != null) { fPartService.removePartListener(fPartListener); fPartService= null; } setMenu(null); }
@Override public void partDeactivated(IWorkbenchPart part) { disposeMenuItems(); }