[jbosstools-commits] JBoss Tools SVN: r39786 - trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Mar 22 19:59:45 EDT 2012


Author: akazakov
Date: 2012-03-22 19:59:44 -0400 (Thu, 22 Mar 2012)
New Revision: 39786

Modified:
   trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseUIUtil.java
Log:
https://issues.jboss.org/browse/JBIDE-11385 Invalid thread access in CDICoreValidator

Modified: trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseUIUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseUIUtil.java	2012-03-22 23:37:30 UTC (rev 39785)
+++ trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/util/EclipseUIUtil.java	2012-03-22 23:59:44 UTC (rev 39786)
@@ -14,6 +14,7 @@
 import java.util.Set;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.util.SafeRunnable;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.IFileEditorInput;
@@ -21,35 +22,58 @@
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.common.CommonPlugin;
 
 /**
  * @author Alexey Kazakov
  */
 public class EclipseUIUtil {
 
+	private static class SafeRunnableForActivePage extends SafeRunnable {
+
+		public ITextEditor activeEditor;
+
+		/*
+		 * (non-Javadoc)
+		 * @see org.eclipse.core.runtime.ISafeRunnable#run()
+		 */
+		@Override
+		public void run() throws Exception {
+			IWorkbenchWindow window = PlatformUI.getWorkbench()
+					.getActiveWorkbenchWindow();
+			if (window != null) {
+				IWorkbenchPage page = window.getActivePage();
+				if (page != null) {
+					IEditorPart editor = page.getActiveEditor();
+					if (editor instanceof IEditorWrapper) {
+						editor = ((IEditorWrapper) editor).getEditor();
+					}
+					if (editor instanceof ITextEditor) {
+						activeEditor = (ITextEditor) editor;
+					} else {
+						activeEditor = editor == null ? null : (ITextEditor)editor.getAdapter(ITextEditor.class);
+					}
+				}
+			}
+		}
+
+		/* (non-Javadoc)
+		 * @see org.eclipse.jface.util.SafeRunnable#handleException(java.lang.Throwable)
+		 */
+		@Override
+		public void handleException(Throwable e) {
+			CommonPlugin.getDefault().logError(e);
+		}
+	}
+
 	/**
 	 * Returns the active text editor.
-	 * 
 	 * @return
 	 */
 	public static ITextEditor getActiveEditor() {
-		IWorkbenchWindow window = PlatformUI.getWorkbench()
-				.getActiveWorkbenchWindow();
-		if (window != null) {
-			IWorkbenchPage page = window.getActivePage();
-			if (page != null) {
-				IEditorPart editor = page.getActiveEditor();
-				if (editor instanceof IEditorWrapper) {
-					editor = ((IEditorWrapper) editor).getEditor();
-				}
-				if (editor instanceof ITextEditor) {
-					return (ITextEditor) editor;
-				} else {
-					return  editor == null ? null : (ITextEditor)editor.getAdapter(ITextEditor.class);
-				}
-			}
-		}
-		return null;
+		SafeRunnableForActivePage sr = new SafeRunnableForActivePage();
+		SafeRunnable.run(sr);
+		return sr.activeEditor;
 	}
 
 	/**
@@ -74,23 +98,37 @@
 	}
 
 	/**
-	 * Returns all the modified but not saved files which are opened with all the editors.  
+	 * Returns all the modified but not saved files which are opened with all the editors.
 	 * @return
 	 */
 	public static Set<IFile> getDirtyFiles() {
-		Set<IFile> dirtyFiles = new HashSet<IFile>();
+		final Set<IFile> dirtyFiles = new HashSet<IFile>();
 		IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
 		for (IWorkbenchWindow window : windows) {
-			IWorkbenchPage page = window.getActivePage();
+			final IWorkbenchPage page = window.getActivePage();
 			if (page != null) {
-				IEditorPart[] editors = page.getDirtyEditors();
-				for (IEditorPart editor : editors) {
-					IEditorInput input = editor.getEditorInput();
-					if(input instanceof IFileEditorInput) {
-						IFile file = ((IFileEditorInput)input).getFile();
-						dirtyFiles.add(file);
+				SafeRunnable sr = new SafeRunnable() {
+					@Override
+					public void run() throws Exception {
+						IEditorPart[] editors = page.getDirtyEditors();
+						for (IEditorPart editor : editors) {
+							IEditorInput input = editor.getEditorInput();
+							if(input instanceof IFileEditorInput) {
+								IFile file = ((IFileEditorInput)input).getFile();
+								dirtyFiles.add(file);
+							}
+						}
 					}
-				}
+
+					/* (non-Javadoc)
+					 * @see org.eclipse.jface.util.SafeRunnable#handleException(java.lang.Throwable)
+					 */
+					@Override
+					public void handleException(Throwable e) {
+						CommonPlugin.getDefault().logError(e);
+					}
+				};
+				SafeRunnable.run(sr);
 			}
 		}
 		return dirtyFiles;



More information about the jbosstools-commits mailing list