/** {@inheritDoc} */ public void run(IAction action) { IWorkbenchPart activePart = JavaPlugin.getActivePage().getActivePart(); if (!(activePart instanceof CompilationUnitEditor)) return; final CompilationUnitEditor editor = (CompilationUnitEditor) activePart; new JDTQuickMenuCreator(editor) { @Override protected void fillMenu(IMenuManager menu) { SurroundWithTryCatchAction surroundWithTryCatch = createSurroundWithTryCatchAction(editor); SurroundWithTemplateMenuAction.fillMenu(menu, editor, surroundWithTryCatch); } }.createMenu(); }
/** * The menu to show in the workbench menu * * @param menu the menu to fill entries into it */ protected void fillMenu(Menu menu) { IWorkbenchPart activePart = JavaPlugin.getActivePage().getActivePart(); if (!(activePart instanceof CompilationUnitEditor)) { ActionContributionItem item = new ActionContributionItem(NONE_APPLICABLE_ACTION); item.fill(menu, -1); return; } CompilationUnitEditor editor = (CompilationUnitEditor) activePart; if (editor.isBreadcrumbActive()) { ActionContributionItem item = new ActionContributionItem(NONE_APPLICABLE_ACTION); item.fill(menu, -1); return; } IAction[] actions = getTemplateActions(editor); boolean addSurroundWith = !isInJavadoc(editor); if (addSurroundWith) { SurroundWithTryCatchAction surroundAction = createSurroundWithTryCatchAction(editor); ActionContributionItem surroundItem = new ActionContributionItem(surroundAction); surroundItem.fill(menu, -1); } boolean hasTemplateActions = actions != null && actions.length > 0; if (!hasTemplateActions && !addSurroundWith) { ActionContributionItem item = new ActionContributionItem(NONE_APPLICABLE_ACTION); item.fill(menu, -1); } else if (hasTemplateActions) { if (addSurroundWith) { Separator templateGroup = new Separator(TEMPLATE_GROUP); templateGroup.fill(menu, -1); } for (int i = 0; i < actions.length; i++) { ActionContributionItem item = new ActionContributionItem(actions[i]); item.fill(menu, -1); } } Separator configGroup = new Separator(CONFIG_GROUP); configGroup.fill(menu, -1); ActionContributionItem configAction = new ActionContributionItem(new ConfigureTemplatesAction()); configAction.fill(menu, -1); }
private boolean computeSmartMode() { IWorkbenchPage page = JavaPlugin.getActivePage(); if (page != null) { IEditorPart part = page.getActiveEditor(); if (part instanceof ITextEditorExtension3) { ITextEditorExtension3 extension = (ITextEditorExtension3) part; return extension.getInsertMode() == ITextEditorExtension3.SMART_INSERT; } else if (part != null && EditorUtility.isCompareEditorInput(part.getEditorInput())) { ITextEditorExtension3 extension = (ITextEditorExtension3) part.getAdapter(ITextEditorExtension3.class); if (extension != null) return extension.getInsertMode() == ITextEditorExtension3.SMART_INSERT; } } return false; }