Author: snjeza
Date: 2012-03-20 15:51:55 -0400 (Tue, 20 Mar 2012)
New Revision: 39674
Modified:
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.java
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesReadyPage.java
Log:
JBIDE-11285 - Welcome content of project examples broken/inconsistent (displayed in
internal web browser or not displayed)
Modified:
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java
===================================================================
---
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2012-03-20
18:31:19 UTC (rev 39673)
+++
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/ProjectExamplesActivator.java 2012-03-20
19:51:55 UTC (rev 39674)
@@ -53,6 +53,7 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.Job;
@@ -68,6 +69,8 @@
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IPerspectiveDescriptor;
import org.eclipse.ui.IPerspectiveRegistry;
@@ -94,6 +97,7 @@
import org.eclipse.ui.internal.cheatsheets.views.CheatSheetView;
import org.eclipse.ui.internal.cheatsheets.views.ViewUtilities;
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
+import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.util.PrefUtil;
import org.eclipse.ui.internal.wizards.newresource.ResourceMessages;
@@ -135,6 +139,7 @@
private static final String PERIOD_CHEATSHEET_XML = "/.cheatsheet.xml";
//$NON-NLS-1$
private static final String README_MD = "/readme.md"; //$NON-NLS-1$
private static final String README_TXT = "/readme.txt"; //$NON-NLS-1$
+ private static final String README_MDU = "/README.md"; //$NON-NLS-1$
// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.project.examples";
//$NON-NLS-1$
@@ -336,7 +341,7 @@
return projects.toArray(new IProject[0]);
}
- protected static String replace(String name, ProjectExample project) {
+ public static String replace(String name, ProjectExample project) {
List<String> includedProjects = project.getIncludedProjects();
if (includedProjects != null) {
int i = 0;
@@ -479,7 +484,13 @@
view.getCheatSheetViewer().setInput(id, id, finalURL, new DefaultStateManager(),
false);
} else {
try {
- if (finalURL.toString().endsWith(README_MD) ||
finalURL.toString().endsWith(README_TXT)) {
+ if (finalURL.toString().endsWith(".htm") ||
finalURL.toString().endsWith(".html")) {
+ IWorkbenchBrowserSupport browserSupport =
ProjectExamplesActivator.getDefault().getWorkbench().getBrowserSupport();
+ IWebBrowser browser =
browserSupport.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR |
IWorkbenchBrowserSupport.NAVIGATION_BAR,
+ null, null, null);
+ browser.openURL(finalURL);
+ } else {
+ boolean txtFile = finalURL.toString().endsWith(".md") ||
finalURL.toString().endsWith(".txt");
IWorkbenchPage page =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IFile[] files = null;
@@ -491,8 +502,12 @@
}
if (files.length > 0) {
try {
- IFileEditorInput input = new FileEditorInput(files[0]);
- IDE.openEditor(page, input, EditorsUI.DEFAULT_TEXT_EDITOR_ID);
+ if (txtFile) {
+ IFileEditorInput input = new FileEditorInput(files[0]);
+ IDE.openEditor(page, input, EditorsUI.DEFAULT_TEXT_EDITOR_ID);
+ } else {
+ IDE.openEditor(page, files[0]);
+ }
} catch (PartInitException e) {
ProjectExamplesActivator.log(e);
}
@@ -500,21 +515,22 @@
IFileStore store = EFS.getLocalFileSystem().getStore(
new Path(finalURL.getPath()));
try {
- IDE.openEditor(page, new FileStoreEditorInput(store),
+ FileStoreEditorInput input = new FileStoreEditorInput(store);
+ if (txtFile) {
+ IDE.openEditor(page, input,
EditorsUI.DEFAULT_TEXT_EDITOR_ID);
+ } else {
+ IDE.openEditor(page, input,
+ getEditorId(store));
+ }
} catch (PartInitException e) {
ProjectExamplesActivator.log(e);
}
}
- } else {
- IWorkbenchBrowserSupport browserSupport =
ProjectExamplesActivator.getDefault().getWorkbench().getBrowserSupport();
- IWebBrowser browser =
browserSupport.createBrowser(IWorkbenchBrowserSupport.LOCATION_BAR |
IWorkbenchBrowserSupport.NAVIGATION_BAR,
- null, null, null);
- browser.openURL(finalURL);
- }
- } catch (PartInitException e) {
- ProjectExamplesActivator.log(e);
+ }
+ } catch (PartInitException e) {
+ ProjectExamplesActivator.log(e);
}
}
}
@@ -526,7 +542,72 @@
}
}
- private static void fixWelcome(ProjectExample project) {
+ private static String getEditorId(IFileStore fileStore) throws PartInitException {
+ String name = fileStore.fetchInfo().getName();
+ if (name == null) {
+ throw new IllegalArgumentException();
+ }
+
+ IContentType contentType= null;
+ try {
+ InputStream is = null;
+ try {
+ is = fileStore.openInputStream(EFS.NONE, null);
+ contentType= Platform.getContentTypeManager().findContentTypeFor(is, name);
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ } catch (CoreException ex) {
+ // continue without content type
+ } catch (IOException ex) {
+ // continue without content type
+ }
+
+ IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry();
+
+ return getEditorDescriptor(name, editorReg, editorReg.getDefaultEditor(name,
contentType)).getId();
+ }
+
+ private static IEditorDescriptor getEditorDescriptor(String name,
+ IEditorRegistry editorReg, IEditorDescriptor defaultDescriptor)
+ throws PartInitException {
+
+ if (defaultDescriptor != null) {
+ return defaultDescriptor;
+ }
+
+ IEditorDescriptor editorDesc = defaultDescriptor;
+
+ // next check the OS for in-place editor (OLE on Win32)
+ if (editorReg.isSystemInPlaceEditorAvailable(name)) {
+ editorDesc = editorReg
+ .findEditor(IEditorRegistry.SYSTEM_INPLACE_EDITOR_ID);
+ }
+
+ // next check with the OS for an external editor
+ if (editorDesc == null
+ && editorReg.isSystemExternalEditorAvailable(name)) {
+ editorDesc = editorReg
+ .findEditor(IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID);
+ }
+
+ // next lookup the default text editor
+ if (editorDesc == null) {
+ editorDesc = editorReg
+ .findEditor(IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID);
+ }
+
+ // if no valid editor found, bail out
+ if (editorDesc == null) {
+ throw new PartInitException(
+ IDEWorkbenchMessages.IDE_noFileEditorFound);
+ }
+
+ return editorDesc;
+ }
+ public static void fixWelcome(ProjectExample project) {
if (project == null || project.isWelcome()) {
return;
}
@@ -564,6 +645,10 @@
ProjectExampleUtil.EDITOR)) {
return;
}
+ if (checkCheatsheet(project, eclipseProject, README_MDU,
+ ProjectExampleUtil.EDITOR)) {
+ return;
+ }
if (checkCheatsheet(project, eclipseProject, README_TXT,
ProjectExampleUtil.EDITOR)) {
return;
Modified:
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.java
===================================================================
---
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.java 2012-03-20
18:31:19 UTC (rev 39673)
+++
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesJob.java 2012-03-20
19:51:55 UTC (rev 39674)
@@ -66,7 +66,8 @@
return Status.CANCEL_STATUS;
}
if (importProjectExample.importProject(project, project.getFile(), propertiesMap,
monitor)) {
- importProjectExample.fix(project, monitor);
+ importProjectExample.fix(project, monitor);
+ ProjectExamplesActivator.fixWelcome(project);
} else {
return Status.CANCEL_STATUS;
}
Modified:
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesReadyPage.java
===================================================================
---
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesReadyPage.java 2012-03-20
18:31:19 UTC (rev 39673)
+++
branches/jbosstools-3.3.0.Beta1/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/wizard/NewProjectExamplesReadyPage.java 2012-03-20
19:51:55 UTC (rev 39674)
@@ -67,7 +67,9 @@
if (projectExample.isWelcome()) {
showReadme.setEnabled(true);
showReadme.setSelection(true);
- showReadme.setText("Show '" + projectExample.getWelcomeURL() +
"' for further instructions");
+ String urlString = projectExample.getWelcomeURL();
+ String welcomeURL = ProjectExamplesActivator.replace(urlString, projectExample);
+ showReadme.setText("Show '" + welcomeURL + "' for further
instructions");
} else {
showReadme.setEnabled(false);
showReadme.setSelection(false);