public void run(ICompilationUnit cu) { if (!ElementValidator.check(cu, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), fEditor != null)) return; if (!ActionUtil.isProcessable(getShell(), cu)) return;  try { IPreferenceStore store= PreferenceConstants.getPreferenceStore(); String[] prefOrder= JavaPreferencesSettings.getImportOrderPreference(store); int threshold= JavaPreferencesSettings.getImportNumberThreshold(store); boolean ignoreLowerCaseNames= store.getBoolean(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE);  if (fEditor == null && EditorUtility.isOpenInEditor(cu) == null) { IEditorPart editor= EditorUtility.openInEditor(cu); if (editor instanceof JavaEditor) { fEditor= (JavaEditor) editor; } } OrganizeImportsOperation op= new OrganizeImportsOperation(cu, prefOrder, threshold, ignoreLowerCaseNames, !cu.isWorkingCopy(), true, createChooseImportQuery());  IRewriteTarget target= null; if (fEditor != null) { target= (IRewriteTarget) fEditor.getAdapter(IRewriteTarget.class); if (target != null) { target.beginCompoundChange(); } }  BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext(); try { PlatformUI.getWorkbench().getProgressService().runInUI(context, new WorkbenchRunnableAdapter(op, op.getScheduleRule()), op.getScheduleRule()); 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 (fEditor != null && parseError.getSourceStart() != -1) { fEditor.selectAndReveal(parseError.getSourceStart(), parseError.getSourceEnd() - parseError.getSourceStart() + 1); } } else { if (fEditor != null) { setStatusBarMessage(getOrganizeInfo(op)); } } } catch (InvocationTargetException e) { ExceptionHandler.handle(e, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), ActionMessages.getString("OrganizeImportsAction.error.message")); } catch (InterruptedException e) { } finally { if (target != null) { target.endCompoundChange(); } } } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), ActionMessages.getString("OrganizeImportsAction.error.message"));
public void run(ITextSelection selection) { ICompilationUnit cu= getCompilationUnit(fEditor); if (cu != null) { run(cu);
	public void run(ICompilationUnit cu) {		if (!ElementValidator.check(cu, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), fEditor != null)) //$NON-NLS-1$ 			return;		if (!ActionUtil.isProcessable(getShell(), cu))			return;					try {			IPreferenceStore store= PreferenceConstants.getPreferenceStore();			String[] prefOrder= JavaPreferencesSettings.getImportOrderPreference(store);			int threshold= JavaPreferencesSettings.getImportNumberThreshold(store);			boolean ignoreLowerCaseNames= store.getBoolean(PreferenceConstants.ORGIMPORTS_IGNORELOWERCASE);						if (fEditor == null && EditorUtility.isOpenInEditor(cu) == null) {				IEditorPart editor= EditorUtility.openInEditor(cu);				if (editor instanceof JavaEditor) {					fEditor= (JavaEditor) editor;				}						}			OrganizeImportsOperation op= new OrganizeImportsOperation(cu, prefOrder, threshold, ignoreLowerCaseNames, !cu.isWorkingCopy(), true, createChooseImportQuery());					IRewriteTarget target= null;			if (fEditor != null) {				target= (IRewriteTarget) fEditor.getAdapter(IRewriteTarget.class);				if (target != null) {					target.beginCompoundChange();				}			}						BusyIndicatorRunnableContext context= new BusyIndicatorRunnableContext();			try {				PlatformUI.getWorkbench().getProgressService().runInUI(context,					new WorkbenchRunnableAdapter(op, op.getScheduleRule()),					op.getScheduleRule());				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 (fEditor != null && parseError.getSourceStart() != -1) {						fEditor.selectAndReveal(parseError.getSourceStart(), parseError.getSourceEnd() - parseError.getSourceStart() + 1);					}				} else {					if (fEditor != null) {						setStatusBarMessage(getOrganizeInfo(op));					}				}			} 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) {			} finally {				if (target != null) {					target.endCompoundChange();				}			}		} catch (CoreException e) {				ExceptionHandler.handle(e, getShell(), ActionMessages.getString("OrganizeImportsAction.error.title"), ActionMessages.getString("OrganizeImportsAction.error.message")); //$NON-NLS-1$ //$NON-NLS-2$		}	}