a bit more changes...
authortoshihiro <toshihiro>
Mon, 30 Jul 2007 10:28:49 +0000 (10:28 +0000)
committertoshihiro <toshihiro>
Mon, 30 Jul 2007 10:28:49 +0000 (10:28 +0000)
net.sourceforge.phpeclipse.ui/src/net/sourceforge/phpeclipse/ui/editor/ShowExternalPreviewAction.java

index 154ddff..8e8c9b8 100644 (file)
@@ -7,6 +7,7 @@ import net.sourceforge.phpeclipse.webbrowser.views.BrowserView;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jface.preference.IPreferenceStore;
@@ -15,6 +16,7 @@ import org.eclipse.ui.IFileEditorInput;
 import org.eclipse.ui.IViewPart;
 import org.eclipse.ui.IWorkbenchPage;
 import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.progress.WorkbenchJob;
 import org.eclipse.ui.texteditor.ITextEditor;
 import org.eclipse.ui.texteditor.TextEditorAction;
 
@@ -70,6 +72,10 @@ public class ShowExternalPreviewAction extends TextEditorAction {
 
                if (autoPreview) {
                        IWorkbenchPage page = WebUI.getActivePage();
+                       if (page == null) {
+                               // startup stage
+                               return;
+                       }
                        try {
                                // IViewPart part = page.findView(BrowserView.ID_BROWSER);
                                // if (part == null) {
@@ -79,7 +85,21 @@ public class ShowExternalPreviewAction extends TextEditorAction {
                                                IWorkbenchPage.VIEW_CREATE);
                                if (part != null) {
                                        if (bringToTopPreview) {
-                                               page.bringToTop(part);
+                                               // page.bringToTop(part);
+                                               new WorkbenchJob(getClass().getName()) {
+                                                       public IStatus runInUIThread(
+                                                                       IProgressMonitor monitor) {
+                                                               IWorkbenchPage page = WebUI.getActivePage();
+                                                               if (page != null) {
+                                                                       IViewPart part = page
+                                                                                       .findView(BrowserView.ID_BROWSER);
+                                                                       if (part != null) {
+                                                                               page.bringToTop(part);
+                                                                       }
+                                                               }
+                                                               return Status.OK_STATUS;
+                                                       }
+                                               }.schedule();
                                        }
                                        // ((BrowserView) part).refresh();
                                        String localhostURL = getLocalhostURL(null, previewFile);