1 11 package org.eclipse.ui.cheatsheets; 12 13 import java.net.URL ; 14 15 import org.eclipse.help.ui.internal.views.HelpTray; 16 import org.eclipse.help.ui.internal.views.IHelpPartPage; 17 import org.eclipse.help.ui.internal.views.ReusableHelpPart; 18 import org.eclipse.jface.action.Action; 19 import org.eclipse.jface.dialogs.TrayDialog; 20 import org.eclipse.swt.widgets.Display; 21 import org.eclipse.swt.widgets.Shell; 22 import org.eclipse.ui.IWorkbenchPage; 23 import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetElement; 24 import org.eclipse.ui.internal.cheatsheets.registry.CheatSheetRegistryReader; 25 import org.eclipse.ui.internal.cheatsheets.state.DefaultStateManager; 26 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetHelpPart; 27 import org.eclipse.ui.internal.cheatsheets.views.CheatSheetView; 28 import org.eclipse.ui.internal.cheatsheets.views.ViewUtilities; 29 30 39 public final class OpenCheatSheetAction extends Action { 40 private String id; 41 private String name; 42 private URL url; 43 private String xml; 44 private String basePath; 45 46 56 public OpenCheatSheetAction(String id) { 57 if (id == null) { 58 throw new IllegalArgumentException (); 59 } 60 this.id = id; 61 } 62 63 73 public OpenCheatSheetAction(String id, String name, URL url) { 74 if (id == null || name == null || url == null) { 75 throw new IllegalArgumentException (); 76 } 77 this.id = id; 78 this.name = name; 79 this.url = url; 80 } 81 82 97 public OpenCheatSheetAction(String id, String name, String xml, URL baseURL) { 98 if (id == null || name == null || xml == null) { 99 throw new IllegalArgumentException (); 100 } 101 this.id = id; 102 this.name = name; 103 this.xml = xml; 104 if (baseURL !=null) { 105 basePath = baseURL.toExternalForm(); 106 } 107 } 108 109 110 117 public void run() { 118 Shell shell = Display.getDefault().getActiveShell(); 119 Object data = shell.getData(); 120 if (!shell.isFocusControl() && data instanceof TrayDialog) { 122 TrayDialog dialog = (TrayDialog)data; 123 HelpTray tray = (HelpTray)dialog.getTray(); 124 if (tray == null) { 125 tray = new HelpTray(); 126 dialog.openTray(tray); 127 } 128 ReusableHelpPart helpPart = tray.getHelpPart(); 129 IHelpPartPage page = helpPart.createPage(CheatSheetHelpPart.ID, null, null); 130 page.setVerticalSpacing(0); 131 page.setHorizontalMargin(0); 132 CheatSheetElement contentElement = CheatSheetRegistryReader.getInstance().findCheatSheet(id); 133 helpPart.addPart(CheatSheetHelpPart.ID, new CheatSheetHelpPart(helpPart.getForm().getForm().getBody(), helpPart.getForm().getToolkit(), page.getToolBarManager(), contentElement, new DefaultStateManager())); 134 page.addPart(CheatSheetHelpPart.ID, true); 135 helpPart.addPage(page); 136 helpPart.showPage(CheatSheetHelpPart.ID); 137 } 138 else { 139 CheatSheetView view = ViewUtilities.showCheatSheetView(); 140 if (view == null) { 141 return; 142 } 143 if(url != null) { 146 view.setInput(id, name, url); 147 } else if (xml != null) { 148 view.setInputFromXml(id, name, xml, basePath); 149 } else { 150 view.setInput(id); 151 } 152 IWorkbenchPage page = view.getSite().getWorkbenchWindow().getActivePage(); 153 page.bringToTop(view); 154 } 155 } 156 } 157 | Popular Tags |