public void run(ICompilationUnit cu) { if (!ElementValidator.check(cu, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), fEditor != null)) return; try { IPreferenceStore store= PreferenceConstants.getPreferenceStore(); String[] prefOrder= JavaPreferencesSettings.getImportOrderPreference(store); int threshold= JavaPreferencesSettings.getImportNumberThreshold(store); boolean ignoreLowerCaseNames= store.getBoolean(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE);  JavaEditor javaEditor= fEditor; if (!cu.isWorkingCopy()) { IEditorPart editor= EditorUtility.openInEditor(cu); if (editor instanceof JavaEditor) { javaEditor= (JavaEditor) editor; }  cu= JavaModelUtil.toWorkingCopy(cu); }  OrganizeImportsOperation op= new OrganizeImportsOperation(cu, prefOrder, threshold, ignoreLowerCaseNames, !cu.isWorkingCopy(), true, createChooseImportQuery());  BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext(); context.run(false, true, new WorkbenchRunnableAdapter(op)); IProblem parseError= op.getParseError(); if (parseError != null) { String message= ActionMessages.getFormattedString("OrganizeImportsAction.single.error.parse", parseError.getMessage()); MessageDialog.openInformation(getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), message); if (javaEditor != null && parseError.getSourceStart() != -1) { javaEditor.selectAndReveal(parseError.getSourceStart(), parseError.getSourceEnd() - parseError.getSourceStart() + 1); } } else { if (fEditor != null) { setStatusBarMessage(getOrganizeInfo(op)); } } } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), ActionMessages.getString("OrganizeImportsAction.error.message")); } catch (InvocationTargetException e) { ExceptionHandler.handle(e, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), ActionMessages.getString("OrganizeImportsAction.error.message")); } catch (InterruptedException e) { }
protected void run(ITextSelection selection) { IWorkingCopyManager manager= JavaPlugin.getDefault().getWorkingCopyManager(); ICompilationUnit cu= manager.getWorkingCopy(fEditor.getEditorInput()); run(cu);
	public void run(ICompilationUnit cu) {		if (!ElementValidator.check(cu, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), fEditor != null)) //$NON-NLS-1$ 			return;		try {			IPreferenceStore store= PreferenceConstants.getPreferenceStore();			String[] prefOrder= JavaPreferencesSettings.getImportOrderPreference(store);			int threshold= JavaPreferencesSettings.getImportNumberThreshold(store);			boolean ignoreLowerCaseNames= store.getBoolean(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE);						JavaEditor javaEditor= fEditor;			if (!cu.isWorkingCopy()) {				IEditorPart editor= EditorUtility.openInEditor(cu);				if (editor instanceof JavaEditor) {					javaEditor= (JavaEditor) editor;				}								cu= JavaModelUtil.toWorkingCopy(cu);			}									OrganizeImportsOperation op= new OrganizeImportsOperation(cu, prefOrder, threshold, ignoreLowerCaseNames, !cu.isWorkingCopy(), true, createChooseImportQuery());					BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext();			context.run(false, true, new WorkbenchRunnableAdapter(op));			IProblem parseError= op.getParseError();			if (parseError != null) {				String message= ActionMessages.getFormattedString("OrganizeImportsAction.single.error.parse", parseError.getMessage()); //$NON-NLS-1$				MessageDialog.openInformation(getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), message); //$NON-NLS-1$ 				if (javaEditor != null && parseError.getSourceStart() != -1) {					javaEditor.selectAndReveal(parseError.getSourceStart(), parseError.getSourceEnd() - parseError.getSourceStart() + 1);				}			} else {				if (fEditor != null) {					setStatusBarMessage(getOrganizeInfo(op));				}			}		} catch (CoreException e) {				ExceptionHandler.handle(e, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), ActionMessages.getString("OrganizeImportsAction.error.message")); //$NON-NLS-1$ //$NON-NLS-2$		} catch (InvocationTargetException e) {			ExceptionHandler.handle(e, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), ActionMessages.getString("OrganizeImportsAction.error.message")); //$NON-NLS-1$ //$NON-NLS-2$		} catch (InterruptedException e) {		}	}