JavaPlugin.log(e); ErrorDialog.openError(getShell(), JavaEditorMessages.getString("AddImportOnSelection.error.title"), null, e.getStatus());
ExceptionHandler.handle(e, getShell(), JavaEditorMessages.getString("AddImportOnSelection.error.title"), null);
	public void run() {		ICompilationUnit cu= getCompilationUnit();		if (cu != null) {			ISelection s= fEditor.getSelectionProvider().getSelection();			IDocument doc= fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());			ITextSelection selection= (ITextSelection) s;						if (doc != null) {				try {					int nameStart= getNameStart(doc, selection.getOffset());					int nameEnd= getNameEnd(doc, selection.getOffset() + selection.getLength());					int len= nameEnd - nameStart;										String name= doc.get(nameStart, len).trim();					String simpleName= Signature.getSimpleName(name);					String containerName= Signature.getQualifier(name);															IImportDeclaration existingImport= JavaModelUtil.findImport(cu, simpleName);					if (existingImport != null) {						if (!existingImport.getElementName().equals(name)) {							getShell().getDisplay().beep();						}						return;					}													IJavaSearchScope searchScope= SearchEngine.createJavaSearchScope(new IJavaElement[] { cu.getJavaProject() });										TypeInfo[] types= findAllTypes(simpleName, searchScope, null);					if (types.length== 0) {						getShell().getDisplay().beep();						return;					}										TypeInfo chosen= selectResult(types, containerName, getShell());					if (chosen == null) {						return;					}					IType type= chosen.resolveType(searchScope);					if (type == null) {						JavaPlugin.logErrorMessage("AddImportOnSelectionAction: Failed to resolve TypeRef: " + chosen.toString()); //$NON-NLS-1$						MessageDialog.openError(getShell(), JavaEditorMessages.getString("AddImportOnSelection.error.title"), JavaEditorMessages.getString("AddImportOnSelection.error.notresolved.message")); //$NON-NLS-1$ //$NON-NLS-2$						return;					}					removeQualification(doc, nameStart, chosen);										CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings();					AddImportsOperation op= new AddImportsOperation(cu, new IJavaElement[] { type }, settings, false);					ProgressMonitorDialog dialog= new ProgressMonitorDialog(getShell());					try {						dialog.run(false, true, new WorkbenchRunnableAdapter(op));					} catch (InvocationTargetException e) {						JavaPlugin.log(e);						MessageDialog.openError(getShell(), JavaEditorMessages.getString("AddImportOnSelection.error.title"), e.getTargetException().getMessage()); //$NON-NLS-1$					} catch (InterruptedException e) {						// Do nothing. Operation has been canceled.					}					return;				} catch (CoreException e) {					JavaPlugin.log(e);					ErrorDialog.openError(getShell(), JavaEditorMessages.getString("AddImportOnSelection.error.title"), null, e.getStatus()); //$NON-NLS-1$				} catch (BadLocationException e) {					JavaPlugin.log(e);					MessageDialog.openError(getShell(), JavaEditorMessages.getString("AddImportOnSelection.error.title"), e.getMessage()); //$NON-NLS-1$				}			}		}			}