1 11 package org.eclipse.ui.internal.ide.dialogs; 12 13 import org.eclipse.core.runtime.Platform; 14 import org.eclipse.jface.action.IAction; 15 import org.eclipse.ui.PlatformUI; 16 import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; 17 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 18 import org.osgi.framework.Bundle; 19 20 23 public class WelcomeItem { 24 private String text; 25 26 private int[][] boldRanges; 27 28 private int[][] helpRanges; 29 30 private String [] helpIds; 31 32 private String [] helpHrefs; 33 34 private int[][] actionRanges; 35 36 private String [] actionPluginIds; 37 38 private String [] actionClasses; 39 40 43 public WelcomeItem(String text, int[][] boldRanges, int[][] actionRanges, 44 String [] actionPluginIds, String [] actionClasses, 45 int[][] helpRanges, String [] helpIds, String [] helpHrefs) { 46 47 this.text = text; 48 this.boldRanges = boldRanges; 49 this.actionRanges = actionRanges; 50 this.actionPluginIds = actionPluginIds; 51 this.actionClasses = actionClasses; 52 this.helpRanges = helpRanges; 53 this.helpIds = helpIds; 54 this.helpHrefs = helpHrefs; 55 } 56 57 60 public int[][] getActionRanges() { 61 return actionRanges; 62 } 63 64 67 public int[][] getBoldRanges() { 68 return boldRanges; 69 } 70 71 74 public int[][] getHelpRanges() { 75 return helpRanges; 76 } 77 78 81 public String getText() { 82 return text; 83 } 84 85 88 public boolean isLinkAt(int offset) { 89 for (int i = 0; i < helpRanges.length; i++) { 91 if (offset >= helpRanges[i][0] 92 && offset < helpRanges[i][0] + helpRanges[i][1]) { 93 return true; 94 } 95 } 96 97 for (int i = 0; i < actionRanges.length; i++) { 99 if (offset >= actionRanges[i][0] 100 && offset < actionRanges[i][0] + actionRanges[i][1]) { 101 return true; 102 } 103 } 104 return false; 105 } 106 107 110 public void logActionLinkError(String actionPluginId, String actionClass) { 111 IDEWorkbenchPlugin 112 .log(IDEWorkbenchMessages.WelcomeItem_unableToLoadClass + actionPluginId + " " + actionClass); } 114 115 118 private void openHelpTopic(String topic, String href) { 119 if (href != null) { 120 PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(href); 121 } else { 122 PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(topic); 123 } 124 } 125 126 129 private void runAction(String pluginId, String className) { 130 Bundle pluginBundle = Platform.getBundle(pluginId); 131 if (pluginBundle == null) { 132 logActionLinkError(pluginId, className); 133 return; 134 } 135 Class actionClass; 136 IAction action; 137 try { 138 actionClass = pluginBundle.loadClass(className); 139 } catch (ClassNotFoundException e) { 140 logActionLinkError(pluginId, className); 141 return; 142 } 143 try { 144 action = (IAction) actionClass.newInstance(); 145 } catch (InstantiationException e) { 146 logActionLinkError(pluginId, className); 147 return; 148 } catch (IllegalAccessException e) { 149 logActionLinkError(pluginId, className); 150 return; 151 } catch (ClassCastException e) { 152 logActionLinkError(pluginId, className); 153 return; 154 } 155 action.run(); 156 } 157 158 161 public void triggerLinkAt(int offset) { 162 for (int i = 0; i < helpRanges.length; i++) { 164 if (offset >= helpRanges[i][0] 165 && offset < helpRanges[i][0] + helpRanges[i][1]) { 166 openHelpTopic(helpIds[i], helpHrefs[i]); 168 return; 169 } 170 } 171 172 for (int i = 0; i < actionRanges.length; i++) { 174 if (offset >= actionRanges[i][0] 175 && offset < actionRanges[i][0] + actionRanges[i][1]) { 176 runAction(actionPluginIds[i], actionClasses[i]); 178 return; 179 } 180 } 181 } 182 } 183 | Popular Tags |