@Override public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(selection)); } catch (JavaModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.isExceptionToBeLogged(e)) JavaPlugin.log(e); setEnabled(false); } }
/** * Note: This constructor is for internal use only. Clients should not call this * constructor. * * @param editor the compilation unit editor */ public AddUnimplementedConstructorsAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(checkEnabledEditor()); }
@Override public void run(IStructuredSelection selection) { Shell shell= getShell(); try { IType type= getSelectedType(selection); if (type == null) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_not_applicable); return; } if (type.isAnnotation()) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_annotation_not_applicable); return; } else if (type.isInterface()) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_interface_not_applicable); return; } else if (type.isEnum()) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_enum_not_applicable); return; } run(shell, type, false); } catch (CoreException e) { ExceptionHandler.handle(e, shell, getDialogTitle(), null); } }
@Override public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(fEditor)) return; try { Shell shell= getShell(); IType type= SelectionConverter.getTypeAtOffset(fEditor); if (type != null) run(shell, type, true); else MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_not_applicable); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); } }
private void run(Shell shell, IType type, boolean activatedFromEditor) throws CoreException { if (!ElementValidator.check(type, getShell(), getDialogTitle(), activatedFromEditor)) { notifyResult(false); return; if (!ActionUtil.isEditable(fEditor, getShell(), type)) { notifyResult(false); return; Object[] constructors= provider.getElements(null); if (constructors.length == 0) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_error_nothing_found); notifyResult(false); return; Object[] elements= dialog.getResult(); if (elements == null) { notifyResult(false); return; AddUnimplementedConstructorsOperation operation= (AddUnimplementedConstructorsOperation) createRunnable(astRoot, typeBinding, selected, insertPos, dialog.getGenerateComment(), dialog.getVisibilityModifier(), dialog.isOmitSuper()); IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow(); if (context == null) String[] created= operation.getCreatedConstructors(); if (created == null || created.length == 0) MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_error_nothing_found); } catch (InvocationTargetException e) { ExceptionHandler.handle(e, shell, getDialogTitle(), null); } catch (InterruptedException e) {
fAddDelegateMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_DELEGATE_METHODS); fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(site); fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS); fAddGetterSetter.update(selection); fAddDelegateMethods.update(selection); fAddUnimplementedConstructors.update(selection); fGenerateConstructorUsingFields.update(selection); fHashCodeEquals.update(selection);
editor.setAction("AddDelegateMethods", fAddDelegateMethods); //$NON-NLS-1$ fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(editor); fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS); editor.setAction("AddUnimplementedConstructors", fAddUnimplementedConstructors); //$NON-NLS-1$
protected IMethod[] createInheritedConstructors(ICompilationUnit cu, IType type, IProgressMonitor monitor) throws CoreException { cu.reconcile(ICompilationUnit.NO_AST, false, null, null); Set handleIds = getHandleIds(type); ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setResolveBindings(true); parser.setSource(cu); CompilationUnit unit = (CompilationUnit) parser.createAST(new SubProgressMonitor(monitor, 1)); ITypeBinding binding = getBinding(type, unit); if (binding != null) { IWorkspaceRunnable operation = AddUnimplementedConstructorsAction.createRunnable(unit, binding, null, -1, true, Modifier.PUBLIC, true); operation.run(monitor); cu.commitWorkingCopy(false, monitor); } return getTypeMethods(type, handleIds); }
private void run(Shell shell, IType type, boolean activatedFromEditor) throws CoreException { if (!ElementValidator.check(type, getShell(), getDialogTitle(), activatedFromEditor)) { notifyResult(false); return; if (!ActionUtil.isEditable(fEditor, getShell(), type)) { notifyResult(false); return; Object[] constructors= provider.getElements(null); if (constructors.length == 0) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_error_nothing_found); notifyResult(false); return; Object[] elements= dialog.getResult(); if (elements == null) { notifyResult(false); return; AddUnimplementedConstructorsOperation operation= (AddUnimplementedConstructorsOperation) createRunnable(astRoot, typeBinding, selected, insertPos, dialog.getGenerateComment(), dialog.getVisibilityModifier(), dialog.isOmitSuper()); IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow(); if (context == null) String[] created= operation.getCreatedConstructors(); if (created == null || created.length == 0) MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_error_nothing_found); } catch (InvocationTargetException e) { ExceptionHandler.handle(e, shell, getDialogTitle(), null); } catch (InterruptedException e) {
public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(fEditor)) return; try { Shell shell= getShell(); IType type= SelectionConverter.getTypeAtOffset(fEditor); if (type != null) run(shell, type, true); else MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_not_applicable); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); } }
fAddDelegateMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_DELEGATE_METHODS); fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(site); fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS); fAddGetterSetter.update(selection); fAddDelegateMethods.update(selection); fAddUnimplementedConstructors.update(selection); fGenerateConstructorUsingFields.update(selection); fHashCodeEquals.update(selection);
editor.setAction("AddDelegateMethods", fAddDelegateMethods); //$NON-NLS-1$ fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(editor); fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS); editor.setAction("AddUnimplementedConstructors", fAddUnimplementedConstructors); //$NON-NLS-1$
private void run(Shell shell, IType type, boolean activatedFromEditor) throws CoreException { if (!ElementValidator.check(type, getShell(), getDialogTitle(), activatedFromEditor)) { notifyResult(false); return; if (!ActionUtil.isEditable(fEditor, getShell(), type)) { notifyResult(false); return; Object[] constructors= provider.getElements(null); if (constructors.length == 0) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_error_nothing_found); notifyResult(false); return; Object[] elements= dialog.getResult(); if (elements == null) { notifyResult(false); return; AddUnimplementedConstructorsOperation operation= (AddUnimplementedConstructorsOperation) createRunnable(astRoot, typeBinding, selected, insertPos, dialog.getGenerateComment(), dialog.getVisibilityModifier(), dialog.isOmitSuper()); IRunnableContext context= JavaPlugin.getActiveWorkbenchWindow(); if (context == null) String[] created= operation.getCreatedConstructors(); if (created == null || created.length == 0) MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_error_nothing_found); } catch (InvocationTargetException e) { ExceptionHandler.handle(e, shell, getDialogTitle(), null); } catch (InterruptedException e) {
public void run(IStructuredSelection selection) { Shell shell= getShell(); try { IType type= getSelectedType(selection); if (type == null) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_not_applicable); return; } if (type.isAnnotation()) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_annotation_not_applicable); return; } else if (type.isInterface()) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_interface_not_applicable); return; } else if (type.isEnum()) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_enum_not_applicable); return; } run(shell, type, false); } catch (CoreException e) { ExceptionHandler.handle(e, shell, getDialogTitle(), null); } }
@Override public void run(ITextSelection selection) { if (!ActionUtil.isProcessable(fEditor)) return; try { Shell shell= getShell(); IType type= SelectionConverter.getTypeAtOffset(fEditor); if (type != null) run(shell, type, true); else MessageDialog.openInformation(shell, getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_not_applicable); } catch (JavaModelException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), getDialogTitle(), null); } }
fAddDelegateMethods.setActionDefinitionId(IJavaEditorActionDefinitionIds.CREATE_DELEGATE_METHODS); fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(site); fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS); fAddGetterSetter.update(selection); fAddDelegateMethods.update(selection); fAddUnimplementedConstructors.update(selection); fGenerateConstructorUsingFields.update(selection); fHashCodeEquals.update(selection);
@Override public void selectionChanged(IStructuredSelection selection) { try { setEnabled(canEnable(selection)); } catch (JavaModelException e) { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253 if (JavaModelUtil.isExceptionToBeLogged(e)) JavaPlugin.log(e); setEnabled(false); } }
/** * Note: This constructor is for internal use only. Clients should not call this * constructor. * * @param editor the compilation unit editor * * @noreference This constructor is not intended to be referenced by clients. */ public AddUnimplementedConstructorsAction(CompilationUnitEditor editor) { this(editor.getEditorSite()); fEditor= editor; setEnabled(checkEnabledEditor()); }
editor.setAction("AddDelegateMethods", fAddDelegateMethods); //$NON-NLS-1$ fAddUnimplementedConstructors= new AddUnimplementedConstructorsAction(editor); fAddUnimplementedConstructors.setActionDefinitionId(IJavaEditorActionDefinitionIds.ADD_UNIMPLEMENTED_CONTRUCTORS); editor.setAction("AddUnimplementedConstructors", fAddUnimplementedConstructors); //$NON-NLS-1$
@Override public void run(IStructuredSelection selection) { Shell shell= getShell(); try { IType type= getSelectedType(selection); if (type == null) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_not_applicable); return; } if (type.isAnnotation()) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_annotation_not_applicable); return; } else if (type.isInterface()) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_interface_not_applicable); return; } else if (type.isEnum()) { MessageDialog.openInformation(getShell(), getDialogTitle(), ActionMessages.AddUnimplementedConstructorsAction_enum_not_applicable); return; } run(shell, type, false); } catch (CoreException e) { ExceptionHandler.handle(e, shell, getDialogTitle(), null); } }