private void run(Shell shell, IType type) throws CoreException { final OverrideMethodDialog dialog = new OverrideMethodDialog(shell, fEditor, type, false); if (!dialog.hasMethodsToOverride()) { MessageDialog.openInformation( shell, getDialogTitle(), ActionMessages.OverrideMethodsAction_error_nothing_found); notifyResult(false); return; } if (dialog.open() != Window.OK) { notifyResult(false); return; } final Object[] selected = dialog.getResult(); if (selected == null) { notifyResult(false); return; } ArrayList<IMethodBinding> methods = new ArrayList<IMethodBinding>(); for (int i = 0; i < selected.length; i++) { Object elem = selected[i]; if (elem instanceof IMethodBinding) { methods.add((IMethodBinding) elem); } } IMethodBinding[] methodToOverride = methods.toArray(new IMethodBinding[methods.size()]); final IEditorPart editor = JavaUI.openInEditor(type.getCompilationUnit()); final IRewriteTarget target = editor != null ? (IRewriteTarget) editor.getAdapter(IRewriteTarget.class) : null; if (target != null) target.beginCompoundChange(); try { CompilationUnit astRoot = dialog.getCompilationUnit(); final ITypeBinding typeBinding = ASTNodes.getTypeBinding(astRoot, type); int insertPos = dialog.getInsertOffset(); AddUnimplementedMethodsOperation operation = (AddUnimplementedMethodsOperation) createRunnable( astRoot, typeBinding, methodToOverride, insertPos, dialog.getGenerateComment()); IRunnableContext context = JavaPlugin.getActiveWorkbenchWindow(); if (context == null) context = new BusyIndicatorRunnableContext(); PlatformUI.getWorkbench() .getProgressService() .runInUI( context, new WorkbenchRunnableAdapter(operation, operation.getSchedulingRule()), operation.getSchedulingRule()); final String[] created = operation.getCreatedMethods(); if (created == null || created.length == 0) MessageDialog.openInformation( shell, getDialogTitle(), ActionMessages.OverrideMethodsAction_error_nothing_found); } catch (InvocationTargetException exception) { ExceptionHandler.handle(exception, shell, getDialogTitle(), null); } catch (InterruptedException exception) { // Do nothing. Operation has been canceled by user. } finally { if (target != null) target.endCompoundChange(); } notifyResult(true); }
private Shell getShell() { return JavaPlugin.getActiveWorkbenchWindow().getShell(); }