]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/winterwell.markdown/src/winterwell/markdown/commands/OpenGfmView.java
migrated to svn revision 33108
[simantics/platform.git] / bundles / winterwell.markdown / src / winterwell / markdown / commands / OpenGfmView.java
1 package winterwell.markdown.commands;
2
3 import org.eclipse.core.commands.AbstractHandler;
4 import org.eclipse.core.commands.ExecutionEvent;
5 import org.eclipse.core.commands.ExecutionException;
6 import org.eclipse.jface.dialogs.MessageDialog;
7 import org.eclipse.swt.widgets.Display;
8 import org.eclipse.ui.IViewPart;
9 import org.eclipse.ui.IWorkbenchPage;
10 import org.eclipse.ui.PartInitException;
11 import org.eclipse.ui.PlatformUI;
12
13 import winterwell.markdown.LogUtil;
14
15 public class OpenGfmView extends AbstractHandler {
16
17         @Override
18         public Object execute(final ExecutionEvent event) throws ExecutionException {
19                 try {
20                 IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
21                 String gfmViewId = "code.satyagraha.gfm.viewer.views.GfmView";
22                 IViewPart gfmView = activePage.showView(gfmViewId);
23                 activePage.activate(gfmView);
24                 } catch (PartInitException e) {
25                         showError(e);
26             } catch (Exception e) {
27                 showError(e);
28             }           
29                 return null;
30         }
31
32         private void showError(Exception e) {
33                 String title = "Exception while opening GitHub Flavored Markdown View";
34                 String message = title+" (code.satyagraha.gfm.viewer.views.GfmView)"
35                                 +"\nCheck Error Log View and continue at https://github.com/winterstein/Eclipse-Markdown-Editor-Plugin/issues/42"
36                                 +"\n\nYou can also right-click file in Project Explorer"
37                                 +"\n and select \"Show in GFM view\".";
38                 LogUtil.error(message, e);
39                 MessageDialog.openError(Display.getDefault().getActiveShell(), title , message);
40         }
41 }