import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
-
public class BrowserUtil {
- public static void showPreview(IFile previewFile, boolean forceDBGPreview, String postFix) {
- if (previewFile == null) {
- // should never happen
- return;
- }
- String extension = previewFile.getFileExtension().toLowerCase();
- boolean autoPreview = forceDBGPreview;
- boolean bringToTopPreview = true;
- boolean showHTMLFilesLocal = false;
- boolean showXMLFilesLocal = false;
- boolean isHTMLFileName = false;
- boolean isXMLFileName = false;
- if (!forceDBGPreview) {
- autoPreview = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
-
- bringToTopPreview = ProjectPrefUtil
- .getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
- showHTMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL);
- showXMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_XML_FILES_LOCAL);
- isHTMLFileName = "html".equals(extension) || "htm".equals(extension) || "xhtml".equals(extension);
- isXMLFileName = "xml".equals(extension) || "xsd".equals(extension) || "dtd".equals(extension);
- }
- if (autoPreview) {
- String localhostURL;
- if (showHTMLFilesLocal && isHTMLFileName) {
- localhostURL = previewFile.getLocation().toString();
- } else if (showXMLFilesLocal && isXMLFileName) {
- localhostURL = previewFile.getLocation().toString();
- } else if ((localhostURL = ShowExternalPreviewAction.getLocalhostURL(null, previewFile)) == null) {
- return;
- }
- localhostURL += postFix;
-
- try {
- IWorkbenchPage page = WebUI.getActivePage();
- IViewPart part = page.findView(BrowserView.ID_BROWSER);
- if (part == null) {
- part = page.showView(BrowserView.ID_BROWSER);
- } else {
- if (bringToTopPreview) {
- page.bringToTop(part);
- }
- }
- ((BrowserView) part).setUrl(localhostURL);
-
- } catch (Exception e) {
-// PHPeclipsePlugin.log(e);
- }
- }
- }
+ public static void showPreview(IFile previewFile, boolean forceDBGPreview, String postFix) {
+ if (previewFile == null) {
+ // should never happen
+ return;
+ }
+ String extension = previewFile.getFileExtension().toLowerCase();
+ boolean autoPreview = forceDBGPreview;
+ boolean bringToTopPreview = true;
+ boolean showHTMLFilesLocal = false;
+ boolean showXMLFilesLocal = false;
+ boolean isHTMLFileName = false;
+ boolean isXMLFileName = false;
+ if (!forceDBGPreview) {
+ autoPreview = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_AUTO_PREVIEW_DEFAULT);
+
+ bringToTopPreview = ProjectPrefUtil
+ .getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_BRING_TO_TOP_PREVIEW_DEFAULT);
+ showHTMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_HTML_FILES_LOCAL);
+ showXMLFilesLocal = ProjectPrefUtil.getPreviewBooleanValue(previewFile, IPreferenceConstants.PHP_SHOW_XML_FILES_LOCAL);
+ isHTMLFileName = "html".equals(extension) || "htm".equals(extension) || "xhtml".equals(extension);
+ isXMLFileName = "xml".equals(extension) || "xsd".equals(extension) || "dtd".equals(extension);
+ }
+ if (autoPreview) {
+ String localhostURL;
+ if (showHTMLFilesLocal && isHTMLFileName) {
+ localhostURL = previewFile.getLocation().toString();
+ } else if (showXMLFilesLocal && isXMLFileName) {
+ localhostURL = previewFile.getLocation().toString();
+ } else if ((localhostURL = ShowExternalPreviewAction.getLocalhostURL(null, previewFile)) == null) {
+ return;
+ }
+ localhostURL += postFix;
+
+ try {
+ IWorkbenchPage page = WebUI.getActivePage();
+ IViewPart part = page.showView(BrowserView.ID_BROWSER, null, IWorkbenchPage.VIEW_VISIBLE);
+ // if (part == null) {
+ // part = page.showView(BrowserView.ID_BROWSER);
+ // } else {
+ if (part != null) {
+ if (bringToTopPreview) {
+ page.bringToTop(part);
+ }
+ ((BrowserView) part).setUrl(localhostURL);
+ }
+ // }
+
+ } catch (Exception e) {
+ // PHPeclipsePlugin.log(e);
+ }
+ }
+ }
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package net.sourceforge.phpdt.internal.ui.viewsupport;
+
+import java.util.List;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * A specialized content provider to show a list of editor parts.
+ */
+public class ListContentProvider implements IStructuredContentProvider {
+ List fContents;
+
+ public ListContentProvider() {
+ }
+
+ public Object[] getElements(Object input) {
+ if (fContents != null && fContents == input)
+ return fContents.toArray();
+ return new Object[0];
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput instanceof List)
+ fContents= (List)newInput;
+ else
+ fContents= null;
+ // we use a fixed set.
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isDeleted(Object o) {
+ return fContents != null && !fContents.contains(o);
+ }
+}