|
Lines 13-19
Link Here
|
| 13 |
import java.io.IOException; |
13 |
import java.io.IOException; |
| 14 |
import java.io.InputStream; |
14 |
import java.io.InputStream; |
| 15 |
import java.util.Hashtable; |
15 |
import java.util.Hashtable; |
| 16 |
import java.util.Vector; |
|
|
| 17 |
|
16 |
|
| 18 |
import javax.xml.parsers.ParserConfigurationException; |
17 |
import javax.xml.parsers.ParserConfigurationException; |
| 19 |
import javax.xml.parsers.SAXParser; |
18 |
import javax.xml.parsers.SAXParser; |
|
Lines 23-43
Link Here
|
| 23 |
import org.eclipse.core.runtime.IPath; |
22 |
import org.eclipse.core.runtime.IPath; |
| 24 |
import org.eclipse.core.runtime.Path; |
23 |
import org.eclipse.core.runtime.Path; |
| 25 |
import org.eclipse.hyades.test.common.util.XMLUtil; |
24 |
import org.eclipse.hyades.test.common.util.XMLUtil; |
| 26 |
import org.eclipse.jface.action.ActionContributionItem; |
25 |
import org.eclipse.jface.action.ContributionManager; |
| 27 |
import org.eclipse.jface.action.CoolBarManager; |
26 |
import org.eclipse.jface.action.CoolBarManager; |
| 28 |
import org.eclipse.jface.action.IAction; |
|
|
| 29 |
import org.eclipse.jface.action.IContributionItem; |
| 30 |
import org.eclipse.jface.action.IMenuManager; |
27 |
import org.eclipse.jface.action.IMenuManager; |
| 31 |
import org.eclipse.jface.action.IToolBarManager; |
28 |
import org.eclipse.jface.action.IToolBarManager; |
| 32 |
import org.eclipse.jface.action.MenuManager; |
29 |
import org.eclipse.jface.action.MenuManager; |
| 33 |
import org.eclipse.jface.action.ToolBarManager; |
30 |
import org.eclipse.jface.action.ToolBarManager; |
| 34 |
import org.eclipse.jface.window.ApplicationWindow; |
31 |
import org.eclipse.jface.window.ApplicationWindow; |
| 35 |
import org.eclipse.jface.window.Window; |
|
|
| 36 |
import org.eclipse.jface.wizard.IWizardPage; |
32 |
import org.eclipse.jface.wizard.IWizardPage; |
| 37 |
import org.eclipse.jface.wizard.WizardDialog; |
33 |
import org.eclipse.jface.wizard.WizardDialog; |
| 38 |
import org.eclipse.osgi.util.NLS; |
34 |
import org.eclipse.osgi.util.NLS; |
| 39 |
import org.eclipse.swt.custom.CTabFolder; |
35 |
import org.eclipse.swt.SWT; |
| 40 |
import org.eclipse.swt.custom.CTabItem; |
|
|
| 41 |
import org.eclipse.swt.graphics.Point; |
36 |
import org.eclipse.swt.graphics.Point; |
| 42 |
import org.eclipse.swt.graphics.Rectangle; |
37 |
import org.eclipse.swt.graphics.Rectangle; |
| 43 |
import org.eclipse.swt.widgets.Button; |
38 |
import org.eclipse.swt.widgets.Button; |
|
Lines 46-57
Link Here
|
| 46 |
import org.eclipse.swt.widgets.CoolBar; |
41 |
import org.eclipse.swt.widgets.CoolBar; |
| 47 |
import org.eclipse.swt.widgets.Display; |
42 |
import org.eclipse.swt.widgets.Display; |
| 48 |
import org.eclipse.swt.widgets.Event; |
43 |
import org.eclipse.swt.widgets.Event; |
| 49 |
import org.eclipse.swt.widgets.Item; |
|
|
| 50 |
import org.eclipse.swt.widgets.Menu; |
44 |
import org.eclipse.swt.widgets.Menu; |
| 51 |
import org.eclipse.swt.widgets.MenuItem; |
45 |
import org.eclipse.swt.widgets.MenuItem; |
| 52 |
import org.eclipse.swt.widgets.Shell; |
46 |
import org.eclipse.swt.widgets.Shell; |
| 53 |
import org.eclipse.swt.widgets.TabFolder; |
|
|
| 54 |
import org.eclipse.swt.widgets.TabItem; |
| 55 |
import org.eclipse.swt.widgets.ToolBar; |
47 |
import org.eclipse.swt.widgets.ToolBar; |
| 56 |
import org.eclipse.swt.widgets.ToolItem; |
48 |
import org.eclipse.swt.widgets.ToolItem; |
| 57 |
import org.eclipse.swt.widgets.Widget; |
49 |
import org.eclipse.swt.widgets.Widget; |
|
Lines 59-839
Link Here
|
| 59 |
import org.eclipse.tptp.test.auto.gui.internal.AutoGUIUtil; |
51 |
import org.eclipse.tptp.test.auto.gui.internal.AutoGUIUtil; |
| 60 |
import org.eclipse.tptp.test.auto.gui.internal.GlobalConstants; |
52 |
import org.eclipse.tptp.test.auto.gui.internal.GlobalConstants; |
| 61 |
import org.eclipse.tptp.test.auto.gui.internal.GuiPlugin; |
53 |
import org.eclipse.tptp.test.auto.gui.internal.GuiPlugin; |
| 62 |
import org.eclipse.tptp.test.auto.gui.internal.core.IWidgetId; |
54 |
import org.eclipse.tptp.test.auto.gui.internal.macroobject.IMacroObjectIdentifier; |
| 63 |
import org.eclipse.tptp.test.auto.gui.internal.core.VerificationMetaData; |
55 |
import org.eclipse.tptp.test.auto.gui.internal.macroobject.MacroObjectIdentifier; |
| 64 |
import org.eclipse.tptp.test.auto.gui.internal.core.WidgetIdentifier; |
56 |
import org.eclipse.tptp.test.auto.gui.internal.uiobject.IUIObjectIdentifier; |
| 65 |
import org.eclipse.tptp.test.auto.gui.internal.resolvers.PrimitiveWidgetId; |
57 |
import org.eclipse.tptp.test.auto.gui.internal.uiobject.PrimitiveUIObjectIdentifier; |
|
|
58 |
import org.eclipse.tptp.test.auto.gui.internal.uiobject.resolver.delegate.NonTrivialUIObjectResolverDelegate; |
| 59 |
import org.eclipse.tptp.test.auto.gui.internal.util.XMLDefaultHandler; |
| 66 |
import org.eclipse.ui.IEditorPart; |
60 |
import org.eclipse.ui.IEditorPart; |
|
|
61 |
import org.eclipse.ui.IEditorReference; |
| 67 |
import org.eclipse.ui.IPartListener; |
62 |
import org.eclipse.ui.IPartListener; |
| 68 |
import org.eclipse.ui.IPluginContribution; |
|
|
| 69 |
import org.eclipse.ui.IViewPart; |
63 |
import org.eclipse.ui.IViewPart; |
| 70 |
import org.eclipse.ui.IViewReference; |
64 |
import org.eclipse.ui.IViewReference; |
| 71 |
import org.eclipse.ui.IWorkbench; |
65 |
import org.eclipse.ui.IWorkbench; |
| 72 |
import org.eclipse.ui.IWorkbenchPage; |
66 |
import org.eclipse.ui.IWorkbenchPage; |
| 73 |
import org.eclipse.ui.IWorkbenchPart; |
67 |
import org.eclipse.ui.IWorkbenchPart; |
| 74 |
import org.eclipse.ui.IWorkbenchPartSite; |
|
|
| 75 |
import org.eclipse.ui.IWorkbenchWindow; |
68 |
import org.eclipse.ui.IWorkbenchWindow; |
|
|
69 |
import org.eclipse.ui.PartInitException; |
| 76 |
import org.eclipse.ui.intro.IIntroManager; |
70 |
import org.eclipse.ui.intro.IIntroManager; |
| 77 |
import org.eclipse.ui.intro.IIntroPart; |
71 |
import org.eclipse.ui.intro.IIntroPart; |
|
|
72 |
import org.eclipse.ui.testing.IWorkbenchPartTestable; |
| 78 |
import org.w3c.dom.Node; |
73 |
import org.w3c.dom.Node; |
| 79 |
import org.xml.sax.SAXException; |
74 |
import org.xml.sax.SAXException; |
| 80 |
|
75 |
|
| 81 |
/** |
76 |
/** |
| 82 |
* A helper class that is used while recording a macro. <b>Important: </b> This |
77 |
* A helper class that is used while recording a macro. <b>Important: </b> This class uses internal classes. |
| 83 |
* class uses internal classes. |
78 |
* |
|
|
79 |
* @author Alexander Nyssen (moved everything related to resolving/deresolving out of here |
| 84 |
*/ |
80 |
*/ |
| 85 |
public class MacroUtil |
81 |
public class MacroUtil { |
| 86 |
{ |
82 |
|
| 87 |
private static Hashtable workbenchPartListeners; |
|
|
| 88 |
private static WorkbenchPartListener workbenchPartLisntener; |
| 89 |
|
| 90 |
/** The parser used to parse XML fragments */ |
83 |
/** The parser used to parse XML fragments */ |
| 91 |
private static SAXParser parser; |
84 |
private static SAXParser parser; |
| 92 |
|
85 |
|
| 93 |
static |
86 |
private static Hashtable workbenchPartListeners = new Hashtable(); |
| 94 |
{ |
87 |
private static IPartListener workbenchPartListener = new IPartListener() { |
| 95 |
workbenchPartListeners = new Hashtable(); |
88 |
|
| 96 |
} |
89 |
public void partActivated(IWorkbenchPart part) { |
| 97 |
|
90 |
/* Doesn't need to be implemented */ |
| 98 |
/** |
91 |
} |
| 99 |
* Returns the path where counters of the given event are stored, or null if |
92 |
|
| 100 |
* we are not keeping records of the given event. |
93 |
public void partBroughtToTop(IWorkbenchPart part) { |
| 101 |
* |
94 |
/* Doesn't need to be implemented */ |
| 102 |
* @param event |
95 |
} |
| 103 |
* @return |
96 |
|
| 104 |
*/ |
97 |
/** |
| 105 |
public static WidgetIdentifier getWidgetIdentifier(Widget widget) |
98 |
* This method will generate a close workbench part command. We can't determine for sure through events reported by a display of when a |
| 106 |
{ |
99 |
* workbench part is closed. This part listener is a work around that allows us to capture close events on workbench parts. |
| 107 |
IWidgetId widgetId = null; |
100 |
* |
| 108 |
if (widget instanceof MenuItem) |
101 |
* @param part |
| 109 |
{ |
102 |
* The part is closed. |
|
|
103 |
*/ |
| 104 |
public void partClosed(IWorkbenchPart part) { |
| 105 |
Macro currentMacro = MacroManager.getInstance().getCurrentMacro(); |
| 106 |
Event event = new Event(); |
| 107 |
|
| 108 |
event.type = EventConstants.EVENT_TYPE__WORKBENCH_PART_CLOSED; |
| 109 |
event.data = part; |
| 110 |
event.display = part.getSite().getShell().getDisplay(); |
| 111 |
if (currentMacro != null) { |
| 112 |
try { |
| 113 |
currentMacro.addEvent(event); |
| 114 |
} |
| 115 |
catch (Exception e) { |
| 116 |
/* Ignore the error. It doesn't generate the command */ |
| 117 |
e.printStackTrace(); |
| 118 |
} |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
public void partDeactivated(IWorkbenchPart part) { |
| 123 |
/* Doesn't need to be implemented */ |
| 124 |
} |
| 125 |
|
| 126 |
public void partOpened(IWorkbenchPart part) { |
| 127 |
/* Doesn't need to be implemented */ |
| 128 |
} |
| 129 |
}; |
| 130 |
|
| 131 |
private static IWorkbenchWindow findHookTarget(Widget widget) { |
| 132 |
if (widget instanceof MenuItem) { |
| 110 |
MenuItem menuItem = (MenuItem) widget; |
133 |
MenuItem menuItem = (MenuItem) widget; |
| 111 |
widgetId = determineItemId (menuItem); |
|
|
| 112 |
IViewPart view = null; |
134 |
IViewPart view = null; |
| 113 |
if (onMenubar(menuItem)) |
135 |
if ((view = onWorkbenchPartToolbar(menuItem)) != null) { |
| 114 |
{ |
136 |
// TODO: check if the toolbar manager has to be used to find the hook target... |
| 115 |
return new WidgetIdentifier(new Path(MacroConstants.MENUS_VALUE), new Path(widgetId.toString()), widgetId.getResolverId()); //$NON-NLS-1$ |
137 |
/* The context id should be the workbench part toolbar */ |
| 116 |
} |
|
|
| 117 |
else if ((view = onWorkbenchPartToolbar(menuItem)) != null) |
| 118 |
{ |
| 119 |
/* The context id should be the workbench part toolbar */ |
| 120 |
IToolBarManager toolbarManager = view.getViewSite().getActionBars().getToolBarManager(); |
138 |
IToolBarManager toolbarManager = view.getViewSite().getActionBars().getToolBarManager(); |
| 121 |
if (toolbarManager == null || !(toolbarManager instanceof ToolBarManager)) |
139 |
if (toolbarManager == null || !(toolbarManager instanceof ToolBarManager)) |
| 122 |
return null; |
140 |
return null; |
| 123 |
|
141 |
|
| 124 |
view.setFocus(); |
142 |
// CHECK: setting the focus does not seem to be necessary to find a hook target |
| 125 |
WidgetIdentifier contextId = getControlIdentifier(((ToolBarManager)toolbarManager).getControl()); |
143 |
// -> wihtout it, this method is side effect free |
| 126 |
return new WidgetIdentifier(new Path(MacroConstants.LOCAL_TOOLBAR_MENU_VALUE).append(contextId.getFullyQualifiedPath()), new Path(widgetId.toString()), widgetId.getResolverId()); //$NON-NLS-1$ |
144 |
// view.setFocus(); |
|
|
145 |
return findHookTarget(((ToolBarManager) toolbarManager).getControl()); |
| 127 |
} |
146 |
} |
| 128 |
Control c = widget.getDisplay().getFocusControl(); |
147 |
Control c = widget.getDisplay().getFocusControl(); |
| 129 |
WidgetIdentifier ci = getControlIdentifier(c); |
148 |
return findHookTarget(c); |
| 130 |
if (ci == null) |
|
|
| 131 |
return null; |
| 132 |
return new WidgetIdentifier(new Path(MacroConstants.POPUP_VALUE).append(ci.getFullyQualifiedPath()), new Path(widgetId.toString()), widgetId.getResolverId()); //$NON-NLS-1$ |
| 133 |
} |
149 |
} |
| 134 |
else if (widget instanceof ToolItem) |
150 |
else if (widget instanceof ToolItem) { |
| 135 |
{ |
|
|
| 136 |
ToolItem toolItem = (ToolItem) widget; |
151 |
ToolItem toolItem = (ToolItem) widget; |
| 137 |
widgetId = determineItemId (toolItem); |
|
|
| 138 |
|
| 139 |
/* Check to see if this toolbar belongs to the global toolbar of the workbench */ |
| 140 |
if (onToolbar(toolItem)) |
| 141 |
return new WidgetIdentifier(new Path(MacroConstants.TOOLBAR_VALUE), new Path(widgetId.toString()), widgetId.getResolverId()); //$NON-NLS-1$ |
| 142 |
|
152 |
|
| 143 |
/* Local toolbar somewhere - locate the parent first */ |
153 |
/* Local toolbar somewhere - locate the parent first */ |
| 144 |
ToolBar toolBar = toolItem.getParent(); |
154 |
ToolBar toolBar = toolItem.getParent(); |
| 145 |
WidgetIdentifier controlId = getControlIdentifier(toolBar); |
155 |
return findHookTarget(toolBar); |
| 146 |
if (controlId != null) |
|
|
| 147 |
{ |
| 148 |
IPath localPath = controlId.getFullyQualifiedPath(); |
| 149 |
return new WidgetIdentifier(new Path(MacroConstants.LOCAL_TOOLBAR_VALUE).append(localPath), new Path(widgetId.toString()), widgetId.getResolverId()); |
| 150 |
} |
| 151 |
} |
| 152 |
else if (widget instanceof Shell) |
| 153 |
{ |
| 154 |
widgetId = getShellId((Shell) widget, null); |
| 155 |
return new WidgetIdentifier(new Path(MacroConstants.SHELL_VALUE), new Path(widgetId.toString()), widgetId.getResolverId()); |
| 156 |
} |
| 157 |
else if (widget instanceof Control) |
| 158 |
{ |
| 159 |
return getControlIdentifier((Control) widget); |
| 160 |
} |
| 161 |
else if (widget instanceof Menu) |
| 162 |
{ |
| 163 |
widgetId = getActionId((Menu) widget); |
| 164 |
return new WidgetIdentifier(new Path(MacroConstants.MENUS_VALUE), new Path(widgetId.toString()), widgetId.getResolverId()); |
| 165 |
} |
156 |
} |
| 166 |
return null; |
157 |
else if (widget instanceof Control) { |
| 167 |
} |
158 |
Shell shell = ((Control) widget).getShell(); |
| 168 |
|
159 |
Object data = shell.getData(); |
| 169 |
|
160 |
if (data instanceof IWorkbenchWindow) { |
| 170 |
public static IWidgetId getShellId(Shell shell, String resolverId) |
161 |
IWorkbenchWindow window = (IWorkbenchWindow) data; |
| 171 |
{ |
162 |
return window; |
| 172 |
IWidgetId widgetId = MacroManager.getInstance().resolveWidget(shell.getParent(), shell, resolverId, newCounter()); |
|
|
| 173 |
if (widgetId != null) |
| 174 |
return widgetId; |
| 175 |
return getDefaultShellId(shell); |
| 176 |
} |
| 177 |
|
| 178 |
public static IWidgetId getDefaultShellId(Shell shell) |
| 179 |
{ |
| 180 |
Object data = shell.getData(); |
| 181 |
String id = ""; |
| 182 |
if (data instanceof WizardDialog) |
| 183 |
{ |
| 184 |
id = data.getClass().getName().toString(); |
| 185 |
} |
| 186 |
else if (data instanceof Window) |
| 187 |
{ |
| 188 |
id = data.getClass().getName().toString(); |
| 189 |
} |
| 190 |
|
| 191 |
PrimitiveWidgetId widgetId = new PrimitiveWidgetId(); |
| 192 |
widgetId.setId(id); |
| 193 |
return widgetId; |
| 194 |
} |
| 195 |
|
| 196 |
public static WidgetIdentifier getControlIdentifier(Control control) |
| 197 |
{ |
| 198 |
Shell shell = control.getShell(); |
| 199 |
Object data = shell.getData(); |
| 200 |
if (data instanceof WizardDialog) |
| 201 |
{ |
| 202 |
// in wizard |
| 203 |
WizardDialog wd = (WizardDialog) data; |
| 204 |
IWizardPage page = wd.getCurrentPage(); |
| 205 |
if (page == null) |
| 206 |
return null; |
| 207 |
Control pageControl = page.getControl(); |
| 208 |
IWidgetId relativePath = computeRelativePath((Composite) pageControl, null, control); |
| 209 |
if (relativePath != null) |
| 210 |
{ |
| 211 |
IPath path = new Path(MacroConstants.WIZARD_PAGE_VALUE).append(page.getName()); |
| 212 |
return new WidgetIdentifier(path, new Path(relativePath.toString()), relativePath.getResolverId()); |
| 213 |
} |
| 214 |
// check for wizard buttons |
| 215 |
if (control instanceof Button) |
| 216 |
{ |
| 217 |
relativePath = computeRelativePath(shell, (Composite) pageControl, control); |
| 218 |
return new WidgetIdentifier(new Path(MacroConstants.WIZARD_VALUE), new Path(relativePath.toString()), relativePath.getResolverId()); |
| 219 |
} |
163 |
} |
| 220 |
return null; |
164 |
return null; |
| 221 |
} |
165 |
} |
| 222 |
else if (data instanceof IWorkbenchWindow) |
166 |
return null; |
| 223 |
{ |
167 |
} |
| 224 |
|
168 |
|
| 225 |
IWorkbenchWindow window = (IWorkbenchWindow) data; |
169 |
protected static void hookWorkbenchPartListener(Widget widget) { |
| 226 |
IWorkbenchPage page = window.getActivePage(); |
170 |
IWorkbenchWindow workbenchWindow = findHookTarget(widget); |
|
|
171 |
if (workbenchWindow != null) { |
| 172 |
IWorkbenchPage page = workbenchWindow.getActivePage(); |
| 227 |
|
173 |
|
| 228 |
/** |
174 |
/** |
| 229 |
* Ali M.: Under some situations, the part that is returned by the |
175 |
* Ali M.: Under some situations, the part that is returned by the 'getActivePart' method is the old active part. Although the control |
| 230 |
* 'getActivePart' method is the old active part. Although the |
176 |
* object is coming from the newly active part, the part that is retrieved below will be from the old active part. This will cause |
| 231 |
* control object is coming from the newly active part, the part |
177 |
* MacroUtil.getControlIdentifier to return null when attempting to retrieve the widget id in the wrong context. One situation that this |
| 232 |
* that is retrieved below will be from the old active part. This |
178 |
* fails under is when: - Macro recorder start while the test suite editor is active - A hook is inserted - The package view is focused |
| 233 |
* will cause MacroUtil.getControlIdentifier to return null when |
179 |
* (not activated and focused but just focused) |
| 234 |
* attempting to retrieve the widget id in the wrong context. One |
|
|
| 235 |
* situation that this fails under is when: - Macro recorder start |
| 236 |
* while the test suite editor is active - A hook is inserted - The |
| 237 |
* package view is focused (not activated and focused but just |
| 238 |
* focused) |
| 239 |
* |
180 |
* |
| 240 |
* To resolve this issue, I have registered a part listener when the |
181 |
* To resolve this issue, I have registered a part listener when the client starts recording. When there is a new active part detected, an |
| 241 |
* client starts recording. When there is a new active part |
182 |
* event is created and fired to the usual onEvent handler in MacroManager. See MacroManager.hookPartListener. |
| 242 |
* detected, an event is created and fired to the usual onEvent |
|
|
| 243 |
* handler in MacroManager. See MacroManager.hookPartListener. |
| 244 |
*/ |
183 |
*/ |
| 245 |
IWorkbenchPart part = page.getActivePart(); |
184 |
IWorkbenchPart part = page.getActivePart(); |
| 246 |
IWorkbenchPartSite site = part.getSite(); |
185 |
/* |
| 247 |
|
186 |
* Ali M.: Register a dispose listener with this workbench part if we have not already done so. This is so that close commands can be |
| 248 |
|
187 |
* generated. |
| 249 |
/* Ali M.: Register a dispose listener with this workbench part if we have not |
188 |
*/ |
| 250 |
* already done so. This is so that close commands can be generated. */ |
189 |
if (workbenchPartListeners.get(page) == null) { |
| 251 |
if (workbenchPartListeners.get(page) == null) |
190 |
page.addPartListener(workbenchPartListener); |
| 252 |
{ |
191 |
workbenchPartListeners.put(page, |
| 253 |
if (workbenchPartLisntener == null) |
192 |
workbenchPartListener); |
| 254 |
workbenchPartLisntener = new WorkbenchPartListener(); |
193 |
} |
| 255 |
|
|
|
| 256 |
page.addPartListener(workbenchPartLisntener); |
| 257 |
workbenchPartListeners.put(page, workbenchPartLisntener); |
| 258 |
} |
| 259 |
|
| 260 |
IPath path; |
| 261 |
|
| 262 |
if (part instanceof IViewPart) |
| 263 |
{ |
| 264 |
path = new Path(MacroConstants.VIEW_VALUE).append(site.getId()); |
| 265 |
} |
| 266 |
else if (part instanceof IEditorPart) |
| 267 |
{ |
| 268 |
String inputName = ((IEditorPart) part).getEditorInput().getName(); |
| 269 |
path = new Path(MacroConstants.EDITOR_VALUE).append(site.getId()).append(inputName); |
| 270 |
} |
| 271 |
else |
| 272 |
{ |
| 273 |
return null; |
| 274 |
} |
| 275 |
|
| 276 |
Composite paneComposite = MacroObjectLocator.getWorkbenchPartControl(part); |
| 277 |
|
| 278 |
/* If the control we are looking for is a local tool bar, go up one level */ |
| 279 |
if (part instanceof IViewPart && control instanceof ToolBar) |
| 280 |
paneComposite = paneComposite.getParent(); |
| 281 |
IWidgetId relativePath = computeRelativePath(paneComposite, null, control); |
| 282 |
|
| 283 |
if (relativePath != null) |
| 284 |
{ |
| 285 |
return new WidgetIdentifier(path, new Path(relativePath.toString()), relativePath.getResolverId()); |
| 286 |
} |
| 287 |
} |
| 288 |
else |
| 289 |
{ |
| 290 |
/* unknown shell - fetch controls starting from the shell */ |
| 291 |
IWidgetId relativePath = computeRelativePath(shell, null, control); |
| 292 |
if (relativePath == null) |
| 293 |
return null; |
| 294 |
return new WidgetIdentifier(new Path(MacroConstants.SHELL_VALUE), new Path(relativePath.toString()), relativePath.getResolverId()); |
| 295 |
} |
194 |
} |
| 296 |
return null; |
|
|
| 297 |
} |
| 298 |
|
| 299 |
private static IWidgetId computeRelativePath(Composite parent, Composite skip, Control control) |
| 300 |
{ |
| 301 |
int[] counter = newCounter(); |
| 302 |
Vector indices = new Vector(); |
| 303 |
boolean result = computeControlIndex(parent, skip, control, counter, indices); |
| 304 |
if (!result && skip == null) |
| 305 |
return null; |
| 306 |
|
| 307 |
int index = result ? ((Integer)indices.get(0)).intValue() : 0; |
| 308 |
IWidgetId widgetId = MacroManager.getInstance().resolveWidget(control, null, newCounter()); |
| 309 |
if (widgetId != null) |
| 310 |
return widgetId; |
| 311 |
return computeDefaultControlId(control, index); |
| 312 |
} |
195 |
} |
| 313 |
|
196 |
|
| 314 |
|
197 |
public static int[] newCounter() { |
| 315 |
public static int[] newCounter() |
|
|
| 316 |
{ |
| 317 |
int[] inx = new int[1]; |
198 |
int[] inx = new int[1]; |
| 318 |
inx[0] = 0; |
199 |
inx[0] = 0; |
| 319 |
return inx; |
200 |
return inx; |
| 320 |
} |
201 |
} |
| 321 |
|
|
|
| 322 |
|
| 323 |
/** |
| 324 |
* Determines the index of the desiredControl relative to the parent control sent in. The |
| 325 |
* Index is stored in index[0]. |
| 326 |
* |
| 327 |
* @param parent The parent control |
| 328 |
* @param skip Indicates whether a composite should be skipped |
| 329 |
* @param desiredControl The desired control |
| 330 |
* @param index The current index calculated thus far (stored in index[0]. The type of this |
| 331 |
* parameter is an int array because its value needs to be preserved between recursive calls. |
| 332 |
* |
| 333 |
* @return true if the index was found; false otherwise. |
| 334 |
*/ |
| 335 |
private static boolean computeControlIndex(Composite parent, Composite skip, Control desiredControl, int[] index, Vector indices) |
| 336 |
{ |
| 337 |
return recursiveSearch(parent, skip, desiredControl, null, null, index, new Vector(), indices) != null; |
| 338 |
} |
| 339 |
|
202 |
|
| 340 |
|
203 |
public static boolean isInputControl(Control control) { |
| 341 |
|
|
|
| 342 |
public static Control recursiveSearch(Composite parent, Composite skip, Control desiredControl, WidgetIdentifier id, String widgetClassName, int[] index, Vector matches, Vector indices) |
| 343 |
{ |
| 344 |
boolean searchForControl = id == null; |
| 345 |
Control[] children = parent.getChildren(); |
| 346 |
boolean[] checkTypeAndEquality; |
| 347 |
Control searchResult; |
| 348 |
boolean isTabFolder, isCTabFolder; |
| 349 |
|
| 350 |
for (int i = 0; i < children.length; i++) |
| 351 |
{ |
| 352 |
Control child = children[i]; |
| 353 |
|
| 354 |
if (!child.isVisible()) |
| 355 |
{ |
| 356 |
/* If the control is of the same type, then we'll need to increment the index */ |
| 357 |
if ((widgetClassName != null && child.getClass().getName().equals(widgetClassName)) || (desiredControl != null && desiredControl.getClass().getName().equals(child.getClass().getName()))) |
| 358 |
index[0]++; |
| 359 |
|
| 360 |
continue; |
| 361 |
} |
| 362 |
|
| 363 |
checkTypeAndEquality = searchForControl ? checkTypeAndEqual(desiredControl, child, index) : checkTypeAndId (child, id, widgetClassName, index); |
| 364 |
if (checkTypeAndEquality[0]) |
| 365 |
{ |
| 366 |
if (checkTypeAndEquality[1]) |
| 367 |
{ |
| 368 |
addMatch (matches, indices, child, index[0]); |
| 369 |
} |
| 370 |
|
| 371 |
/* Defect 111371 -- We need to step through the items of a tab */ |
| 372 |
isTabFolder = child instanceof TabFolder; |
| 373 |
isCTabFolder = child instanceof CTabFolder; |
| 374 |
if (isTabFolder || isCTabFolder) |
| 375 |
{ |
| 376 |
Object[] tabItems = isTabFolder ? (Object[])((TabFolder)child).getItems() : ((CTabFolder)child).getItems(); |
| 377 |
if (tabItems != null) |
| 378 |
{ |
| 379 |
for (int j = 0; j < tabItems.length; j++) |
| 380 |
{ |
| 381 |
Control tabItemControl = isTabFolder ? ((TabItem)tabItems[j]).getControl() : ((CTabItem)tabItems[j]).getControl(); |
| 382 |
|
| 383 |
if (tabItemControl == null) |
| 384 |
continue; |
| 385 |
|
| 386 |
checkTypeAndEquality = searchForControl ? checkTypeAndEqual (tabItemControl, desiredControl, index) : checkTypeAndId (tabItemControl, id, widgetClassName, index); |
| 387 |
if (checkTypeAndEquality[0] && checkTypeAndEquality[1]) |
| 388 |
{ |
| 389 |
addMatch (matches, indices, tabItemControl, index[0]); |
| 390 |
} |
| 391 |
if ((searchResult = recursiveSearch(tabItemControl, skip, desiredControl, id, widgetClassName, index, matches, indices)) != null) |
| 392 |
{ |
| 393 |
addMatch (matches, indices, searchResult, index[0]); |
| 394 |
} |
| 395 |
} |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
} |
| 400 |
|
| 401 |
if ((searchResult = recursiveSearch (child, skip, desiredControl, id, widgetClassName, index, matches, indices)) != null) |
| 402 |
{ |
| 403 |
addMatch (matches, indices, searchResult, index[0]); |
| 404 |
} |
| 405 |
} |
| 406 |
|
| 407 |
if (matches.size() > 0) |
| 408 |
return (Control)matches.get(0); |
| 409 |
|
| 410 |
return null; |
| 411 |
} |
| 412 |
|
| 413 |
private static void addMatch (Vector container, Vector indices, Object item, int index) |
| 414 |
{ |
| 415 |
if (!container.contains(item)) |
| 416 |
{ |
| 417 |
container.add(item); |
| 418 |
indices.add(new Integer(index)); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
private static Control recursiveSearch(Control currentSearchPoint, Composite skip, Control desiredControl, WidgetIdentifier desiredId, String desiredWidgetClassName, int[] index, Vector matches, Vector indices) |
| 423 |
{ |
| 424 |
Control searchResult = null; |
| 425 |
if (currentSearchPoint instanceof Composite && !(skip != null && currentSearchPoint.equals(skip)) && currentSearchPoint.isVisible()) |
| 426 |
{ |
| 427 |
searchResult = recursiveSearch((Composite) currentSearchPoint, skip, desiredControl, desiredId, desiredWidgetClassName, index, matches, indices); |
| 428 |
} |
| 429 |
|
| 430 |
return searchResult; |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
/** |
| 435 |
* A helper method used to indicate whether expected is of the same type as actual. The |
| 436 |
* return value also indicates if expected == actual. |
| 437 |
* |
| 438 |
* @param expected The expected control |
| 439 |
* @param actual The actual control that 'expected' is checked against |
| 440 |
* @param counter A counter that is used for indexing. |
| 441 |
* |
| 442 |
* @return This method has the side affect of incrementing counter if the class types |
| 443 |
* of the two controls are the same. The return value indicates type and whether expected == actual. |
| 444 |
*/ |
| 445 |
private static boolean[] checkTypeAndEqual (Control expected, Control actual, int[] counter) |
| 446 |
{ |
| 447 |
boolean[] typeAndEqualCheck = new boolean[2]; |
| 448 |
if (expected.getClass().equals(actual.getClass())) |
| 449 |
{ |
| 450 |
typeAndEqualCheck[0] = true; |
| 451 |
|
| 452 |
// same type - increment counter |
| 453 |
counter[0]++; |
| 454 |
if (expected.equals(actual)) |
| 455 |
{ |
| 456 |
// bingo |
| 457 |
typeAndEqualCheck[1] = true; |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
return typeAndEqualCheck; |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
public static boolean[] checkTypeAndId (Control presentControl, WidgetIdentifier desiredId, String desiredWidgetClassName, int[] counter) |
| 466 |
{ |
| 467 |
boolean[] checkTypeAndEqualId = new boolean[2]; |
| 468 |
|
| 469 |
if (desiredWidgetClassName == null || presentControl.getClass().getName().equals(desiredWidgetClassName)) |
| 470 |
{ |
| 471 |
// same type - increment counter |
| 472 |
if (!presentControl.isVisible()) |
| 473 |
return checkTypeAndEqualId; |
| 474 |
|
| 475 |
checkTypeAndEqualId[0] = true; |
| 476 |
counter[0]++; |
| 477 |
if (MacroObjectLocator.foundWidget(presentControl, desiredId.getResolverId(), desiredId.getObjectId().toString()) || computeDefaultControlId(presentControl, counter[0]).equals(desiredId.getObjectId().toString())) |
| 478 |
{ |
| 479 |
checkTypeAndEqualId[1] = true; |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
return checkTypeAndEqualId; |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
private static IWidgetId computeDefaultControlId(Control control, int controlIndex) |
| 488 |
{ |
| 489 |
PrimitiveWidgetId primitiveWidgetId = new PrimitiveWidgetId(); |
| 490 |
primitiveWidgetId.setId(control.getClass().getName() + "#" + controlIndex); |
| 491 |
return primitiveWidgetId; |
| 492 |
} |
| 493 |
|
| 494 |
|
| 495 |
public static boolean isInputControl(Control control) |
| 496 |
{ |
| 497 |
return true; |
204 |
return true; |
| 498 |
} |
205 |
} |
| 499 |
|
206 |
|
| 500 |
/** |
|
|
| 501 |
* @param menuItem |
| 502 |
* @return |
| 503 |
*/ |
| 504 |
private static boolean onMenubar(MenuItem menuItem) |
| 505 |
{ |
| 506 |
Menu parent = menuItem.getParent(); |
| 507 |
MenuItem parentItem = parent.getParentItem(); |
| 508 |
|
| 509 |
if (parentItem != null) |
| 510 |
{ |
| 511 |
return onMenubar(parentItem); |
| 512 |
} |
| 513 |
|
| 514 |
Shell theShell = parent.getShell(); |
| 515 |
return parent == theShell.getMenuBar(); |
| 516 |
} |
| 517 |
|
| 518 |
private static boolean onToolbar(ToolItem toolItem) |
| 519 |
{ |
| 520 |
ToolBar toolBar = toolItem.getParent(); |
| 521 |
Shell shell = toolBar.getShell(); |
| 522 |
Object data = shell.getData(); |
| 523 |
if (data instanceof ApplicationWindow) |
| 524 |
{ |
| 525 |
ApplicationWindow window = (ApplicationWindow) data; |
| 526 |
ToolBarManager mng = window.getToolBarManager(); |
| 527 |
if (mng != null) |
| 528 |
{ |
| 529 |
if (mng.getControl() != null && mng.getControl() == toolBar) |
| 530 |
return true; |
| 531 |
} |
| 532 |
CoolBarManager cmng = window.getCoolBarManager(); |
| 533 |
if (cmng != null) |
| 534 |
{ |
| 535 |
CoolBar cbar = cmng.getControl(); |
| 536 |
Composite parent = toolBar.getParent(); |
| 537 |
while (parent != null) |
| 538 |
{ |
| 539 |
if (parent == cbar) |
| 540 |
return true; |
| 541 |
parent = parent.getParent(); |
| 542 |
} |
| 543 |
} |
| 544 |
} |
| 545 |
return false; |
| 546 |
} |
| 547 |
|
| 548 |
private static IViewPart onWorkbenchPartToolbar(MenuItem menuItem) |
| 549 |
{ |
| 550 |
IWorkbenchPage[] pages = GuiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getPages(); |
| 551 |
|
| 552 |
/* For evey page */ |
| 553 |
for (int i = 0; i < pages.length; i++) |
| 554 |
{ |
| 555 |
IViewReference[] viewReferences = pages[i].getViewReferences(); |
| 556 |
|
| 557 |
/* For evey opened view */ |
| 558 |
for (int j = 0; j < viewReferences.length; j++) |
| 559 |
{ |
| 560 |
IViewPart viewPart = viewReferences[j].getView(false); |
| 561 |
if (viewPart == null) |
| 562 |
continue; |
| 563 |
|
| 564 |
IMenuManager menuManager = viewPart.getViewSite().getActionBars().getMenuManager(); |
| 565 |
if (menuManager != null && menuManager instanceof MenuManager && searchForMenuItem(((MenuManager)menuManager).getMenu(), menuItem)) |
| 566 |
return viewPart; |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
return null; |
| 571 |
} |
| 572 |
|
| 573 |
private static boolean searchForMenuItem(Menu menu, MenuItem menuItem) |
| 574 |
{ |
| 575 |
if (menu == null) |
| 576 |
return false; |
| 577 |
|
| 578 |
MenuItem[] items = menu.getItems(); |
| 579 |
for (int i = 0; i < items.length; i++) |
| 580 |
{ |
| 581 |
if (items[i] == menuItem) |
| 582 |
return true; |
| 583 |
Menu cascadeMenu = items[i].getMenu(); |
| 584 |
if (cascadeMenu != null && searchForMenuItem (cascadeMenu, menuItem)) |
| 585 |
return true; |
| 586 |
} |
| 587 |
|
| 588 |
return false; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
/** |
| 593 |
* @param toolItem |
| 594 |
* @return |
| 595 |
*/ |
| 596 |
private static String getDisplayName(ToolItem toolItem) |
| 597 |
{ |
| 598 |
String name = toolItem.getText(); |
| 599 |
|
| 600 |
if (name != null && !name.equals(MacroConstants.EMPTY_STRING)) |
| 601 |
{ |
| 602 |
return name; |
| 603 |
} |
| 604 |
|
| 605 |
name = toolItem.getToolTipText(); |
| 606 |
|
| 607 |
if (name != null) |
| 608 |
{ |
| 609 |
return name; |
| 610 |
} |
| 611 |
|
| 612 |
return "unknown"; //$NON-NLS-1$ |
| 613 |
} |
| 614 |
|
| 615 |
/** |
| 616 |
* Returns an identifier for the given MenuItem, based on its user-readable |
| 617 |
* strings |
| 618 |
* |
| 619 |
* @param menuItem |
| 620 |
* @return |
| 621 |
*/ |
| 622 |
private static String getDisplayName(MenuItem menuItem) |
| 623 |
{ |
| 624 |
if (menuItem.getParent() == null || menuItem.getParent().getParentItem() == null) |
| 625 |
{ |
| 626 |
return removeChar(menuItem.getText(), '&'); |
| 627 |
} |
| 628 |
|
| 629 |
return getDisplayName(menuItem.getParent()) + "/" //$NON-NLS-1$ |
| 630 |
+ removeChar(menuItem.getText(), '&'); |
| 631 |
} |
| 632 |
|
| 633 |
/** |
| 634 |
* Returns an identifier for the given Menu, based on its user-readable |
| 635 |
* strings |
| 636 |
* |
| 637 |
* @param menu |
| 638 |
* @return |
| 639 |
*/ |
| 640 |
private static String getDisplayName(Menu menu) |
| 641 |
{ |
| 642 |
|
| 643 |
MenuItem parentItem = menu.getParentItem(); |
| 644 |
|
| 645 |
if (parentItem == null) |
| 646 |
{ |
| 647 |
return MacroConstants.EMPTY_STRING; |
| 648 |
} |
| 649 |
|
| 650 |
return getDisplayName(parentItem); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
/** |
| 655 |
* Defect #: 112668 This method is invoked to retrieve the id of a menu item. |
| 656 |
* Here's the policy that it employs: |
| 657 |
* <ol> |
| 658 |
* <li> Use the contributed widget resolvers </li> |
| 659 |
* <li> If failed, default to what was being used before </li> |
| 660 |
* </ol> |
| 661 |
* |
| 662 |
* @param item The menu item |
| 663 |
* @return The id of the passed item. |
| 664 |
*/ |
| 665 |
public static IWidgetId determineItemId (Item item) |
| 666 |
{ |
| 667 |
IWidgetId menuItemIdObj = MacroManager.getInstance().resolveWidget(item, null, newCounter()); |
| 668 |
|
| 669 |
/* Give a chance for contributors to resolve the menu item */ |
| 670 |
if (menuItemIdObj != null) |
| 671 |
return menuItemIdObj; |
| 672 |
|
| 673 |
if (item instanceof ToolItem) |
| 674 |
{ |
| 675 |
return getActionId((ToolItem)item); |
| 676 |
} |
| 677 |
else if (item instanceof MenuItem) |
| 678 |
{ |
| 679 |
return getActionId((MenuItem)item); |
| 680 |
} |
| 681 |
else if (item instanceof IContributionItem) |
| 682 |
{ |
| 683 |
return getActionId((IContributionItem)item); |
| 684 |
} |
| 685 |
return null; |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
/** |
| 690 |
* Walks through all parent menus of the menuItem and returns an index of format |
| 691 |
* <num>|<num>|<num>|... For example assuming menuItem is |
| 692 |
* placed as follows: |
| 693 |
* |
| 694 |
* item 1 |
| 695 |
* |_item 2 |
| 696 |
* | |_item 4 |
| 697 |
* |_item 3 |
| 698 |
* |_menuItem |
| 699 |
* |
| 700 |
* then its respective index will be 1|2|1 |
| 701 |
* |
| 702 |
* @param menuItem The menu item whose index will be determined |
| 703 |
* @return The index of the menu item as described above. |
| 704 |
*/ |
| 705 |
public static String findMenuItemIndex(MenuItem menuItem, String menuInx) |
| 706 |
{ |
| 707 |
if (menuItem == null) |
| 708 |
return menuInx; |
| 709 |
|
| 710 |
if (menuInx.length() > 0) |
| 711 |
menuInx = "|" + menuInx; |
| 712 |
menuInx = menuItem.getParent().indexOf(menuItem) + menuInx; |
| 713 |
return findMenuItemIndex(menuItem.getParent().getParentItem(), menuInx); |
| 714 |
} |
| 715 |
|
| 716 |
|
| 717 |
/* |
207 |
/* |
| 718 |
* (non-Javadoc) |
208 |
* (non-Javadoc) |
| 719 |
* |
209 |
* |
| 720 |
* @see org.eclipse.instrumentation.IDataProvider#getDefaultValue(org.eclipse.core.runtime.IPath) |
210 |
* @see org.eclipse.instrumentation.IDataProvider#getDefaultValue(org.eclipse.core.runtime.IPath) |
| 721 |
*/ |
211 |
*/ |
| 722 |
public Object getDefaultValue(IPath node) |
212 |
public Object getDefaultValue(IPath node) { |
| 723 |
{ |
|
|
| 724 |
return null; |
213 |
return null; |
| 725 |
} |
214 |
} |
| 726 |
|
215 |
|
| 727 |
private MenuItem getMenuItem(Menu menu, IPath menuPath) |
216 |
private MenuItem getMenuItem(Menu menu, IPath menuPath) { |
| 728 |
{ |
217 |
if (menuPath.isEmpty()) { |
| 729 |
if (menuPath.isEmpty()) |
|
|
| 730 |
{ |
| 731 |
return null; |
218 |
return null; |
| 732 |
} |
219 |
} |
| 733 |
|
220 |
|
| 734 |
String toFind = menuPath.segment(0); |
221 |
String toFind = menuPath.segment(0); |
| 735 |
MenuItem[] items = menu.getItems(); |
222 |
MenuItem[] items = menu.getItems(); |
| 736 |
|
223 |
|
| 737 |
for (int idx = 0; idx < items.length; idx++) |
224 |
for (int idx = 0; idx < items.length; idx++) { |
| 738 |
{ |
|
|
| 739 |
MenuItem item = items[idx]; |
225 |
MenuItem item = items[idx]; |
| 740 |
|
226 |
|
| 741 |
String itemName = removeChar(item.getText(), '&'); |
227 |
String itemName = removeChar(item.getText(), |
|
|
228 |
'&'); |
| 742 |
|
229 |
|
| 743 |
if (itemName.equals(toFind)) |
230 |
if (itemName.equals(toFind)) { |
| 744 |
{ |
231 |
return getMenuItem(item, |
| 745 |
return getMenuItem(item, menuPath.removeFirstSegments(1)); |
232 |
menuPath.removeFirstSegments(1)); |
| 746 |
} |
233 |
} |
| 747 |
} |
234 |
} |
| 748 |
|
235 |
|
| 749 |
return null; |
236 |
return null; |
| 750 |
} |
237 |
} |
| 751 |
|
238 |
|
| 752 |
private MenuItem getMenuItem(MenuItem menu, IPath menuPath) |
239 |
private MenuItem getMenuItem(MenuItem menu, IPath menuPath) { |
| 753 |
{ |
240 |
if (menuPath.isEmpty()) { |
| 754 |
if (menuPath.isEmpty()) |
|
|
| 755 |
{ |
| 756 |
return menu; |
241 |
return menu; |
| 757 |
} |
242 |
} |
| 758 |
|
243 |
|
| 759 |
Menu subMenu = menu.getMenu(); |
244 |
Menu subMenu = menu.getMenu(); |
| 760 |
if (subMenu == null) |
245 |
if (subMenu == null) { |
| 761 |
{ |
|
|
| 762 |
return null; |
246 |
return null; |
| 763 |
} |
247 |
} |
| 764 |
|
248 |
|
| 765 |
return getMenuItem(subMenu, menuPath); |
249 |
return getMenuItem(subMenu, |
|
|
250 |
menuPath); |
| 766 |
|
251 |
|
| 767 |
} |
252 |
} |
| 768 |
|
253 |
|
| 769 |
public static String removeChar(String input, char toRemove) |
254 |
public static void forceMenuClosed(Menu menu) { |
| 770 |
{ |
255 |
Event e = new Event(); |
| 771 |
StringBuffer buf = new StringBuffer(input.length()); |
256 |
e.type = SWT.Hide; |
| 772 |
|
257 |
e.widget = menu; |
| 773 |
int last = 0; |
258 |
|
| 774 |
for (int pos = input.indexOf(toRemove); pos != -1; pos = input.indexOf(toRemove, last)) |
259 |
menu.notifyListeners(e.type, e); |
| 775 |
{ |
260 |
processDisplayEvents(menu.getDisplay()); |
| 776 |
buf.append(input.substring(last, pos)); |
261 |
} |
| 777 |
last = pos + 1; |
|
|
| 778 |
} |
| 779 |
|
| 780 |
buf.append(input.substring(last, input.length())); |
| 781 |
|
262 |
|
| 782 |
return buf.toString(); |
263 |
public static void forceMenuOpen(Menu menu) { |
|
|
264 |
Event e = new Event(); |
| 265 |
e.type = SWT.Show; |
| 266 |
e.widget = menu; |
| 267 |
|
| 268 |
menu.notifyListeners(e.type, e); |
| 269 |
processDisplayEvents(menu.getDisplay()); |
| 783 |
} |
270 |
} |
| 784 |
|
271 |
|
| 785 |
public static String getAttribute(Node node, String name) |
272 |
public static String getAttribute(Node node, String name) { |
| 786 |
{ |
|
|
| 787 |
Node value = node.getAttributes().getNamedItem(name); |
273 |
Node value = node.getAttributes().getNamedItem(name); |
| 788 |
if (value != null) |
274 |
if (value != null) |
| 789 |
return value.getNodeValue(); |
275 |
return value.getNodeValue(); |
| 790 |
return null; |
276 |
return null; |
| 791 |
} |
277 |
} |
| 792 |
|
278 |
|
| 793 |
|
|
|
| 794 |
/** |
279 |
/** |
| 795 |
* Adds an XML element to the string buffer passed in. |
280 |
* Adds an XML element to the string buffer passed in. |
| 796 |
* |
281 |
* |
| 797 |
* @param stringBuffer The string buffer that the element will be written to |
282 |
* @param stringBuffer |
| 798 |
* @param indent The number of indents that should be prefixed to the element written |
283 |
* The string buffer that the element will be written to |
| 799 |
* @param elementName The element name |
284 |
* @param indent |
| 800 |
* @param close Indicates whether this element should be closed or not. If set, |
285 |
* The number of indents that should be prefixed to the element written |
| 801 |
* a forward slash is added before theelement is ended. |
286 |
* @param elementName |
| 802 |
* @param end Indicates if the element should be ended with a closed angle bracket. |
287 |
* The element name |
| 803 |
* For example elements requring attributes are not ended. |
288 |
* @param close |
| 804 |
*/ |
289 |
* Indicates whether this element should be closed or not. If set, a forward slash is added before theelement is ended. |
| 805 |
public static void addElement (StringBuffer stringBuffer, int indent, String elementName, boolean close, boolean end) |
290 |
* @param end |
| 806 |
{ |
291 |
* Indicates if the element should be ended with a closed angle bracket. For example elements requring attributes are not ended. |
| 807 |
addIndent(stringBuffer, indent); |
292 |
*/ |
|
|
293 |
public static void addElement(StringBuffer stringBuffer, int indent, String elementName, boolean close, boolean end) { |
| 294 |
addIndent(stringBuffer, |
| 295 |
indent); |
| 808 |
stringBuffer.append(MacroConstants.OPEN_ANGLE_BRACKET); |
296 |
stringBuffer.append(MacroConstants.OPEN_ANGLE_BRACKET); |
| 809 |
stringBuffer.append(close ? MacroConstants.FORWARD_SLASH : MacroConstants.EMPTY_STRING); |
297 |
stringBuffer.append(close |
|
|
298 |
? MacroConstants.FORWARD_SLASH |
| 299 |
: MacroConstants.EMPTY_STRING); |
| 810 |
stringBuffer.append(elementName); |
300 |
stringBuffer.append(elementName); |
| 811 |
stringBuffer.append(end ? MacroConstants.CLOSE_ANGLE_BRACKET + GlobalConstants.LINE_SEPARATOR: MacroConstants.EMPTY_STRING); |
301 |
stringBuffer.append(end |
|
|
302 |
? MacroConstants.CLOSE_ANGLE_BRACKET + GlobalConstants.LINE_SEPARATOR |
| 303 |
: MacroConstants.EMPTY_STRING); |
| 812 |
} |
304 |
} |
| 813 |
|
305 |
|
| 814 |
|
|
|
| 815 |
/** |
306 |
/** |
| 816 |
* Adds XML attributes to the string buffer passed in. Attributes with a null value will |
307 |
* Adds XML attributes to the string buffer passed in. Attributes with a null value will not be written. |
| 817 |
* not be written. |
|
|
| 818 |
* |
308 |
* |
| 819 |
* Pre-condition: |
309 |
* Pre-condition: |
| 820 |
* <ul> |
310 |
* <ul> |
| 821 |
* <li> attributes and attributeValues must be valid (i.e. non-null) </li> |
311 |
* <li> attributes and attributeValues must be valid (i.e. non-null) </li> |
| 822 |
* <li> attributes and attributeValues length must be the same </li> |
312 |
* <li> attributes and attributeValues length must be the same </li> |
| 823 |
* </ul> |
313 |
* </ul> |
| 824 |
* |
314 |
* |
| 825 |
* @param stringBuffer The string buffer that the attributes will be written to |
315 |
* @param stringBuffer |
| 826 |
* @param attributeNames The attribute names |
316 |
* The string buffer that the attributes will be written to |
| 827 |
* @param attributeValues The attribute values |
317 |
* @param attributeNames |
| 828 |
* @param close If set, a forward slash is added after the attributes. |
318 |
* The attribute names |
| 829 |
* @param end If set, a closed angle bracket is added after the attributes |
319 |
* @param attributeValues |
| 830 |
*/ |
320 |
* The attribute values |
| 831 |
public static void addAttribute(StringBuffer stringBuffer, String[] attributeNames, String[] attributeValues, boolean close, boolean end) |
321 |
* @param close |
| 832 |
{ |
322 |
* If set, a forward slash is added after the attributes. |
| 833 |
for (int i = 0; i < attributeValues.length; i++) |
323 |
* @param end |
| 834 |
{ |
324 |
* If set, a closed angle bracket is added after the attributes |
| 835 |
if (attributeValues[i] == null) |
325 |
*/ |
| 836 |
{ |
326 |
public static void addAttribute(StringBuffer stringBuffer, String[] attributeNames, String[] attributeValues, boolean close, boolean end) { |
|
|
327 |
for (int i = 0; i < attributeValues.length; i++) { |
| 328 |
if (attributeValues[i] == null) { |
| 837 |
continue; |
329 |
continue; |
| 838 |
} |
330 |
} |
| 839 |
stringBuffer.append(MacroConstants.SINGLE_SPACE); |
331 |
stringBuffer.append(MacroConstants.SINGLE_SPACE); |
|
Lines 843-868
Link Here
|
| 843 |
stringBuffer.append(XMLUtil.useXMLSymbols(attributeValues[i])); |
335 |
stringBuffer.append(XMLUtil.useXMLSymbols(attributeValues[i])); |
| 844 |
stringBuffer.append(MacroConstants.DOUBLE_QUOTE); |
336 |
stringBuffer.append(MacroConstants.DOUBLE_QUOTE); |
| 845 |
} |
337 |
} |
| 846 |
|
338 |
|
| 847 |
stringBuffer.append(close ? MacroConstants.FORWARD_SLASH : MacroConstants.EMPTY_STRING); |
339 |
stringBuffer.append(close |
| 848 |
stringBuffer.append(end ? MacroConstants.CLOSE_ANGLE_BRACKET + GlobalConstants.LINE_SEPARATOR : MacroConstants.EMPTY_STRING); |
340 |
? MacroConstants.FORWARD_SLASH |
|
|
341 |
: MacroConstants.EMPTY_STRING); |
| 342 |
stringBuffer.append(end |
| 343 |
? MacroConstants.CLOSE_ANGLE_BRACKET + GlobalConstants.LINE_SEPARATOR |
| 344 |
: MacroConstants.EMPTY_STRING); |
| 849 |
} |
345 |
} |
| 850 |
|
346 |
|
| 851 |
|
347 |
public static void addIndent(StringBuffer stringBuffer, int indent) { |
| 852 |
public static void addIndent (StringBuffer stringBuffer, int indent) |
348 |
for (int i = 0; i < indent; i++) { |
| 853 |
{ |
|
|
| 854 |
for (int i = 0; i < indent; i++) |
| 855 |
{ |
| 856 |
stringBuffer.append("\t"); |
349 |
stringBuffer.append("\t"); |
| 857 |
} |
350 |
} |
| 858 |
} |
351 |
} |
| 859 |
|
352 |
|
| 860 |
|
353 |
public static boolean isIgnorableEvent(Event e) { |
| 861 |
public static boolean isIgnorableEvent(Event e) |
|
|
| 862 |
{ |
| 863 |
Shell shell = e.display.getActiveShell(); |
354 |
Shell shell = e.display.getActiveShell(); |
| 864 |
if (shell != null) |
355 |
if (shell != null) { |
| 865 |
{ |
|
|
| 866 |
Boolean ivalue = (Boolean) shell.getData(MacroManager.IGNORE); |
356 |
Boolean ivalue = (Boolean) shell.getData(MacroManager.IGNORE); |
| 867 |
if (ivalue != null && ivalue.equals(Boolean.TRUE)) |
357 |
if (ivalue != null && ivalue.equals(Boolean.TRUE)) |
| 868 |
return true; |
358 |
return true; |
|
Lines 870-1313
Link Here
|
| 870 |
return false; |
360 |
return false; |
| 871 |
} |
361 |
} |
| 872 |
|
362 |
|
| 873 |
public static Control getFirstChild(IWorkbenchPart part) |
363 |
public static Control getFirstChild(IWorkbenchPart part) { |
| 874 |
{ |
364 |
Composite partControl = getWorkbenchPartControl(part); |
| 875 |
Composite partControl = MacroObjectLocator.getWorkbenchPartControl(part); |
|
|
| 876 |
return partControl.getChildren()[0]; |
365 |
return partControl.getChildren()[0]; |
| 877 |
} |
366 |
} |
| 878 |
|
367 |
|
| 879 |
/** |
368 |
/** |
| 880 |
* Given a context id, return the focus type. |
369 |
* We have to use internal APIs here to get the controls of a part |
| 881 |
* |
|
|
| 882 |
* @param contextId |
| 883 |
* The id of the context |
| 884 |
* @return The type of the context (i.e. focus type). -1 is returned if the |
| 885 |
* focus type is not recognized. |
| 886 |
*/ |
370 |
*/ |
| 887 |
public static byte findFocusType(String contextId) |
371 |
public static Composite getWorkbenchPartControl(IWorkbenchPart part) { |
| 888 |
{ |
372 |
IWorkbenchPartTestable testable = (IWorkbenchPartTestable) part.getSite().getAdapter(IWorkbenchPartTestable.class); |
| 889 |
if (contextId.startsWith(MacroConstants.VIEW_VALUE + "/")) |
373 |
return testable.getControl().getParent(); |
| 890 |
return VerificationMetaData.VIEW; |
|
|
| 891 |
else if (contextId.startsWith(MacroConstants.EDITOR_VALUE + "/")) |
| 892 |
return VerificationMetaData.EDITOR; |
| 893 |
else if (contextId.startsWith(MacroConstants.SHELL_VALUE + "/")) |
| 894 |
return VerificationMetaData.SHELL; |
| 895 |
|
| 896 |
return -1; |
| 897 |
} |
| 898 |
|
| 899 |
/** |
| 900 |
* Return the class name containing the verification point that this meta |
| 901 |
* data points to. |
| 902 |
* |
| 903 |
* @param metaData |
| 904 |
* The verification point's meta data |
| 905 |
* @return The class name. null is returned if it can't be determined |
| 906 |
*/ |
| 907 |
public static String getClassName(VerificationMetaData metaData) |
| 908 |
{ |
| 909 |
String className = metaData.getResource(); |
| 910 |
|
| 911 |
if (className == null || className.length() <= 0) |
| 912 |
return null; |
| 913 |
|
| 914 |
int index = className.lastIndexOf('.'); |
| 915 |
if (index != -1) |
| 916 |
return className.substring(index + 1, className.length()); |
| 917 |
return className; |
| 918 |
} |
374 |
} |
| 919 |
|
375 |
|
| 920 |
/** |
376 |
/** |
| 921 |
* Find the method name corresponding the verification hook |
377 |
* If str.length() is greater than bound, then the first bound letters of str is returned followed by "..."; otherwise str is returned. |
| 922 |
* |
378 |
* |
| 923 |
* @param metaData |
379 |
* @param str |
| 924 |
* @return |
380 |
* The string to bound |
| 925 |
*/ |
381 |
* @param bound |
| 926 |
public static String findMethodName(VerificationMetaData metaData) |
382 |
* The bound |
| 927 |
{ |
|
|
| 928 |
String methodName = metaData.getHook(); |
| 929 |
|
| 930 |
if (methodName == null || methodName.length() <= 0) |
| 931 |
return null; |
| 932 |
|
| 933 |
int index = methodName.indexOf(':'); |
| 934 |
if (index != -1) |
| 935 |
return methodName.substring(0, index); |
| 936 |
|
| 937 |
return methodName; |
| 938 |
} |
| 939 |
|
| 940 |
/** |
| 941 |
* Find the parameter types of the verificaiton hook |
| 942 |
* |
| 943 |
* @param metaData |
| 944 |
* @return |
| 945 |
*/ |
| 946 |
public static Class[] findParameterType(VerificationMetaData metaData) |
| 947 |
{ |
| 948 |
Class param = null; |
| 949 |
if (metaData.getFocusType() == VerificationMetaData.EDITOR) |
| 950 |
param = IEditorPart.class; |
| 951 |
else if (metaData.getFocusType() == VerificationMetaData.VIEW) |
| 952 |
param = IViewPart.class; |
| 953 |
else if (metaData.getFocusType() == VerificationMetaData.SHELL) |
| 954 |
param = Shell.class; |
| 955 |
|
| 956 |
if (param != null) |
| 957 |
return new Class[] { param }; |
| 958 |
|
| 959 |
return null; |
| 960 |
} |
| 961 |
|
| 962 |
|
| 963 |
/** |
| 964 |
* If str.length() is greater than bound, then the first bound letters |
| 965 |
* of str is returned followed by "..."; otherwise str is returned. |
| 966 |
* |
| 967 |
* @param str The string to bound |
| 968 |
* @param bound The bound |
| 969 |
* @return A bounded version of str |
383 |
* @return A bounded version of str |
| 970 |
*/ |
384 |
*/ |
| 971 |
public static String boundSize(String str, int bound) |
385 |
public static String boundSize(String str, int bound) { |
| 972 |
{ |
|
|
| 973 |
if (str == null || str.length() <= bound) |
386 |
if (str == null || str.length() <= bound) |
| 974 |
return str; |
387 |
return str; |
| 975 |
|
388 |
|
| 976 |
return str.substring(0, bound) + "..."; |
389 |
return str.substring(0, |
|
|
390 |
bound) + "..."; |
| 977 |
} |
391 |
} |
| 978 |
|
|
|
| 979 |
|
392 |
|
| 980 |
|
|
|
| 981 |
/** |
393 |
/** |
| 982 |
* "Cleans" up the descriptive fields. For example, it removes the '&' sign that is usually included |
394 |
* "Cleans" up the descriptive fields. For example, it removes the '&' sign that is usually included as part of button labels. |
| 983 |
* as part of button labels. |
|
|
| 984 |
* |
395 |
* |
| 985 |
* @param descriptiveField The descriptive field |
396 |
* @param descriptiveField |
|
|
397 |
* The descriptive field |
| 986 |
* @return A "cleaned" up version of the descriptive field. |
398 |
* @return A "cleaned" up version of the descriptive field. |
| 987 |
*/ |
399 |
*/ |
| 988 |
public static String normalizeDescriptiveField(String descriptiveField) |
400 |
public static String normalizeDescriptiveField(String descriptiveField) { |
| 989 |
{ |
|
|
| 990 |
if (descriptiveField == null || descriptiveField.length() <= 0) |
401 |
if (descriptiveField == null || descriptiveField.length() <= 0) |
| 991 |
return descriptiveField; |
402 |
return descriptiveField; |
| 992 |
|
403 |
|
| 993 |
/* This array holds character array that are of length two. The first item is the unwanted character and the second |
404 |
/* |
| 994 |
* item is the replacement character. */ |
405 |
* This array holds character array that are of length two. The first item is the unwanted character and the second item is the replacement |
| 995 |
final char[][] UNWANTED_CHARACTERS = new char[][] {new char[]{'&', 0}, new char[]{'\t', ' '}, new char[]{'\n', ' '}, new char[]{'\r', ' '}}; |
406 |
* character. |
|
|
407 |
*/ |
| 408 |
final char[][] UNWANTED_CHARACTERS = |
| 409 |
new char[][] {new char[] {'&', 0}, new char[] {'\t', ' '}, new char[] {'\n', ' '}, new char[] {'\r', ' '}}; |
| 996 |
String cleanDescription = ""; |
410 |
String cleanDescription = ""; |
| 997 |
char currentCharacter; |
411 |
char currentCharacter; |
| 998 |
boolean isUnwantedChar; |
412 |
boolean isUnwantedChar; |
| 999 |
for (int i = 0, descriptionLength = descriptiveField.length(); i < descriptionLength; i++) |
413 |
for (int i = 0, descriptionLength = descriptiveField.length(); i < descriptionLength; i++) { |
| 1000 |
{ |
|
|
| 1001 |
currentCharacter = descriptiveField.charAt(i); |
414 |
currentCharacter = descriptiveField.charAt(i); |
| 1002 |
isUnwantedChar = false; |
415 |
isUnwantedChar = false; |
| 1003 |
|
416 |
|
| 1004 |
for (int j = 0; j < UNWANTED_CHARACTERS.length; j++) |
417 |
for (int j = 0; j < UNWANTED_CHARACTERS.length; j++) { |
| 1005 |
{ |
418 |
if (currentCharacter == UNWANTED_CHARACTERS[j][0]) { |
| 1006 |
if (currentCharacter == UNWANTED_CHARACTERS[j][0]) |
|
|
| 1007 |
{ |
| 1008 |
if (UNWANTED_CHARACTERS[j][1] > 0) |
419 |
if (UNWANTED_CHARACTERS[j][1] > 0) |
| 1009 |
cleanDescription += UNWANTED_CHARACTERS[j][1]; |
420 |
cleanDescription += UNWANTED_CHARACTERS[j][1]; |
| 1010 |
|
421 |
|
| 1011 |
isUnwantedChar = true; |
422 |
isUnwantedChar = true; |
| 1012 |
break; |
423 |
break; |
| 1013 |
} |
424 |
} |
| 1014 |
} |
425 |
} |
| 1015 |
|
426 |
|
| 1016 |
if (!isUnwantedChar) |
427 |
if (!isUnwantedChar) |
| 1017 |
cleanDescription += currentCharacter; |
428 |
cleanDescription += currentCharacter; |
| 1018 |
} |
429 |
} |
| 1019 |
|
430 |
|
| 1020 |
return cleanDescription; |
431 |
return cleanDescription; |
| 1021 |
} |
432 |
} |
| 1022 |
|
433 |
|
| 1023 |
public static void closeWelcomePage() |
434 |
public static void closeWelcomePage() { |
| 1024 |
{ |
|
|
| 1025 |
IIntroManager introManager = GuiPlugin.getDefault().getWorkbench().getIntroManager(); |
435 |
IIntroManager introManager = GuiPlugin.getDefault().getWorkbench().getIntroManager(); |
| 1026 |
IIntroPart introPart = introManager.getIntro(); |
436 |
IIntroPart introPart = introManager.getIntro(); |
| 1027 |
if (introPart != null) |
437 |
if (introPart != null) |
| 1028 |
introManager.closeIntro(introPart); |
438 |
introManager.closeIntro(introPart); |
| 1029 |
} |
439 |
} |
| 1030 |
|
440 |
|
| 1031 |
|
441 |
public static void maximizeWorkbench() { |
| 1032 |
public static void maximizeWorkbench() |
|
|
| 1033 |
{ |
| 1034 |
IWorkbench workbench = GuiPlugin.getDefault().getWorkbench(); |
442 |
IWorkbench workbench = GuiPlugin.getDefault().getWorkbench(); |
| 1035 |
Shell workbenchShell = workbench.getActiveWorkbenchWindow().getShell(); |
443 |
Shell workbenchShell = workbench.getActiveWorkbenchWindow().getShell(); |
| 1036 |
Rectangle clientArea = workbench.getDisplay().getClientArea(); |
444 |
Rectangle clientArea = workbench.getDisplay().getClientArea(); |
| 1037 |
workbenchShell.setLocation (0, 0); |
445 |
workbenchShell.setLocation(0, |
|
|
446 |
0); |
| 1038 |
workbenchShell.setSize(new Point(clientArea.width, clientArea.height)); |
447 |
workbenchShell.setSize(new Point(clientArea.width, clientArea.height)); |
| 1039 |
workbenchShell.redraw(); |
448 |
workbenchShell.redraw(); |
| 1040 |
} |
449 |
} |
| 1041 |
public static void clearWorkbenchPartListeners() |
|
|
| 1042 |
{ |
| 1043 |
workbenchPartListeners.clear(); |
| 1044 |
} |
| 1045 |
|
| 1046 |
|
| 1047 |
private static class WorkbenchPartListener implements IPartListener |
| 1048 |
{ |
| 1049 |
|
450 |
|
| 1050 |
public void partActivated(IWorkbenchPart part) |
451 |
public static void clearWorkbenchPartListeners() { |
| 1051 |
{ |
452 |
workbenchPartListeners.clear(); |
| 1052 |
/* Doesn't need to be implemented */ |
|
|
| 1053 |
} |
| 1054 |
|
| 1055 |
public void partBroughtToTop(IWorkbenchPart part) |
| 1056 |
{ |
| 1057 |
/* Doesn't need to be implemented */ |
| 1058 |
} |
| 1059 |
|
| 1060 |
/** |
| 1061 |
* This method will generate a close workbench part command. We can't determine for sure through |
| 1062 |
* events reported by a display of when a workbench part is closed. This part listener is |
| 1063 |
* a work around that allows us to capture close events on workbench parts. |
| 1064 |
* |
| 1065 |
* @param part The part is closed. |
| 1066 |
*/ |
| 1067 |
public void partClosed(IWorkbenchPart part) |
| 1068 |
{ |
| 1069 |
Macro currentMacro = MacroManager.getInstance().getCurrentMacro(); |
| 1070 |
Event event = new Event(); |
| 1071 |
|
| 1072 |
event.type = Macro.WORKBENCH_PART_CLOSED; |
| 1073 |
event.data = part; |
| 1074 |
event.display = part.getSite().getShell().getDisplay(); |
| 1075 |
if (currentMacro != null) |
| 1076 |
{ |
| 1077 |
try |
| 1078 |
{ |
| 1079 |
currentMacro.addEvent(event); |
| 1080 |
} |
| 1081 |
catch (Exception e) |
| 1082 |
{ |
| 1083 |
/* Ignore the error. It doesn't generate the command */ |
| 1084 |
e.printStackTrace(); |
| 1085 |
} |
| 1086 |
} |
| 1087 |
} |
| 1088 |
|
| 1089 |
public void partDeactivated(IWorkbenchPart part) |
| 1090 |
{ |
| 1091 |
/* Doesn't need to be implemented */ |
| 1092 |
} |
| 1093 |
|
| 1094 |
public void partOpened(IWorkbenchPart part) |
| 1095 |
{ |
| 1096 |
/* Doesn't need to be implemented */ |
| 1097 |
} |
| 1098 |
|
| 1099 |
} |
453 |
} |
| 1100 |
|
454 |
|
| 1101 |
public static WidgetIdentifier getCustomEventIdentifier(Event event) |
455 |
public static IMacroObjectIdentifier getCustomEventIdentifier(Event event) { |
| 1102 |
{ |
456 |
if (event.type == EventConstants.EVENT_TYPE__WORKBENCH_PART_CLOSED) { |
| 1103 |
if (event.type == Macro.WORKBENCH_PART_CLOSED) |
457 |
IWorkbenchPart part = (IWorkbenchPart) event.data; |
| 1104 |
{ |
|
|
| 1105 |
IWorkbenchPart part = (IWorkbenchPart)event.data; |
| 1106 |
String partId = part.getSite().getId(); |
458 |
String partId = part.getSite().getId(); |
| 1107 |
|
459 |
|
| 1108 |
/* The path to the context */ |
460 |
/* The path to the context */ |
| 1109 |
IPath contextId = null; |
461 |
IPath contextId = null; |
| 1110 |
IPath partIdPath = null; |
462 |
IPath partIdPath = null; |
| 1111 |
if (part instanceof IViewPart) |
463 |
if (part instanceof IViewPart) { |
| 1112 |
{ |
|
|
| 1113 |
contextId = new Path(MacroConstants.VIEW_VALUE); |
464 |
contextId = new Path(MacroConstants.VIEW_VALUE); |
| 1114 |
partIdPath = new Path(partId); |
465 |
partIdPath = new Path(partId); |
| 1115 |
} |
466 |
} |
| 1116 |
else if (part instanceof IEditorPart) |
467 |
else if (part instanceof IEditorPart) { |
| 1117 |
{ |
|
|
| 1118 |
contextId = new Path(MacroConstants.EDITOR_VALUE); |
468 |
contextId = new Path(MacroConstants.EDITOR_VALUE); |
| 1119 |
partIdPath = new Path(partId).append(((IEditorPart)part).getEditorInput().getName()); |
469 |
partIdPath = new Path(partId).append(((IEditorPart) part).getEditorInput().getName()); |
|
|
470 |
} |
| 471 |
|
| 472 |
if (contextId != null && partId != null) { |
| 473 |
return new MacroObjectIdentifier(contextId.toString(), new PrimitiveUIObjectIdentifier(partIdPath.toString(), null)); |
| 1120 |
} |
474 |
} |
| 1121 |
|
|
|
| 1122 |
if (contextId != null && partId != null) |
| 1123 |
return new WidgetIdentifier (contextId, partIdPath, null); |
| 1124 |
} |
475 |
} |
| 1125 |
return null; |
476 |
return null; |
| 1126 |
} |
477 |
} |
| 1127 |
|
478 |
|
| 1128 |
|
|
|
| 1129 |
/* Returns an identifier for the verification hook context */ |
| 1130 |
public static WidgetIdentifier getVerificationContextIdentifier(Event event) |
| 1131 |
{ |
| 1132 |
/* See if the context is an editor or a view */ |
| 1133 |
Control control = null; |
| 1134 |
if (event.widget instanceof Control) |
| 1135 |
{ |
| 1136 |
control = (Control)event.widget; |
| 1137 |
WidgetIdentifier widgetId = getControlIdentifier(control); |
| 1138 |
if (widgetId != null) |
| 1139 |
{ |
| 1140 |
String firstSegment = new Path(widgetId.getContextId().toString()).segment(0); |
| 1141 |
if (firstSegment.equals(MacroConstants.VIEW_VALUE) || firstSegment.equals(MacroConstants.EDITOR_VALUE)) |
| 1142 |
return widgetId; |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
/* It's not an editor or a view. See if it's a shell */ |
| 1147 |
Shell shellFound = null; |
| 1148 |
if (event.widget instanceof Shell) |
| 1149 |
shellFound = (Shell) event.widget; |
| 1150 |
else if (control != null) |
| 1151 |
shellFound = control.getShell(); |
| 1152 |
|
| 1153 |
/* Make sure that the shell is not the workbench shell */ |
| 1154 |
if (shellFound == null || GuiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell().equals(shellFound)) |
| 1155 |
return null; |
| 1156 |
|
| 1157 |
IWidgetId shellPath = getShellId(shellFound, null); |
| 1158 |
if (shellPath.toString().length() <= 0) |
| 1159 |
return null; |
| 1160 |
|
| 1161 |
return new WidgetIdentifier (new Path(MacroConstants.SHELL_VALUE).append(shellPath.toString()), null, shellPath.getResolverId()); |
| 1162 |
} |
| 1163 |
|
| 1164 |
|
| 1165 |
/** |
479 |
/** |
| 1166 |
* This method is provided to close any nested shells that a test case may have |
480 |
* This method is provided to close any nested shells that a test case may have activated. |
| 1167 |
* activated. |
|
|
| 1168 |
*/ |
481 |
*/ |
| 1169 |
public static void closeSecondaryShells(final Display display) |
482 |
public static void closeSecondaryShells(final Display display) { |
| 1170 |
{ |
483 |
display.syncExec(new Runnable() { |
| 1171 |
display.syncExec(new Runnable(){ |
484 |
|
| 1172 |
public void run() |
485 |
public void run() { |
| 1173 |
{ |
|
|
| 1174 |
Shell[] shells = display.getShells(); |
486 |
Shell[] shells = display.getShells(); |
| 1175 |
for (int i = 0; i < shells.length; i++) |
487 |
for (int i = 0; i < shells.length; i++) { |
| 1176 |
{ |
|
|
| 1177 |
if (!shells[i].isDisposed() && shells[i].getData(GlobalConstants.OPENED_SHELL_INDICATOR) == null) |
488 |
if (!shells[i].isDisposed() && shells[i].getData(GlobalConstants.OPENED_SHELL_INDICATOR) == null) |
| 1178 |
shells[i].close(); |
489 |
shells[i].close(); |
| 1179 |
} |
490 |
} |
| 1180 |
} |
491 |
} |
| 1181 |
}); |
492 |
}); |
| 1182 |
} |
493 |
} |
| 1183 |
|
494 |
|
| 1184 |
public static void processDisplayEvents(Display display) |
495 |
public static void processDisplayEvents(Display display) { |
| 1185 |
{ |
496 |
for (int i = 0;; i++) { |
| 1186 |
for (int i = 0;;i++) |
|
|
| 1187 |
{ |
| 1188 |
if (!display.readAndDispatch()) |
497 |
if (!display.readAndDispatch()) |
| 1189 |
break; |
498 |
break; |
| 1190 |
} |
499 |
} |
| 1191 |
} |
500 |
} |
| 1192 |
|
501 |
|
| 1193 |
|
502 |
public static XMLDefaultHandler createXMLDocument(InputStream is) throws CoreException, SAXException, IOException { |
| 1194 |
public static XMLDefaultHandler createXMLDocument (InputStream is) throws CoreException, SAXException, IOException |
|
|
| 1195 |
{ |
| 1196 |
XMLDefaultHandler handler = null; |
503 |
XMLDefaultHandler handler = null; |
| 1197 |
try |
504 |
try { |
| 1198 |
{ |
|
|
| 1199 |
SAXParser parser = getParser(); |
505 |
SAXParser parser = getParser(); |
| 1200 |
handler = new XMLDefaultHandler(); |
506 |
handler = new XMLDefaultHandler(); |
| 1201 |
parser.parse(is, handler); |
507 |
parser.parse(is, |
|
|
508 |
handler); |
| 1202 |
} |
509 |
} |
| 1203 |
finally |
510 |
finally { |
| 1204 |
{ |
511 |
try { |
| 1205 |
try |
|
|
| 1206 |
{ |
| 1207 |
is.close(); |
512 |
is.close(); |
| 1208 |
} |
513 |
} |
| 1209 |
catch (IOException e) |
514 |
catch (IOException e) { |
| 1210 |
{ |
|
|
| 1211 |
} |
515 |
} |
| 1212 |
} |
516 |
} |
| 1213 |
|
517 |
|
| 1214 |
return handler; |
518 |
return handler; |
| 1215 |
} |
519 |
} |
| 1216 |
|
520 |
|
| 1217 |
private static SAXParser getParser() throws CoreException |
521 |
private static SAXParser getParser() throws CoreException { |
| 1218 |
{ |
522 |
if (parser == null) { |
| 1219 |
if (parser == null) |
523 |
try { |
| 1220 |
{ |
|
|
| 1221 |
try |
| 1222 |
{ |
| 1223 |
return SAXParserFactory.newInstance().newSAXParser(); |
524 |
return SAXParserFactory.newInstance().newSAXParser(); |
| 1224 |
} |
525 |
} |
| 1225 |
catch (ParserConfigurationException e) |
526 |
catch (ParserConfigurationException e) { |
| 1226 |
{ |
527 |
AutoGUIUtil.throwCoreException(NLS.bind(AutoGUIMessages.AUTO_GUI_ERROR_MACRO_PARSING, |
| 1227 |
AutoGUIUtil.throwCoreException(NLS.bind(AutoGUIMessages.AUTO_GUI_ERROR_MACRO_PARSING, e.getLocalizedMessage()), 0, e); |
528 |
e.getLocalizedMessage()), |
| 1228 |
} |
529 |
0, |
| 1229 |
catch (SAXException e) |
530 |
e); |
| 1230 |
{ |
531 |
} |
| 1231 |
AutoGUIUtil.throwCoreException(NLS.bind(AutoGUIMessages.AUTO_GUI_ERROR_MACRO_PARSING, e.getLocalizedMessage()), 0, e); |
532 |
catch (SAXException e) { |
|
|
533 |
AutoGUIUtil.throwCoreException(NLS.bind(AutoGUIMessages.AUTO_GUI_ERROR_MACRO_PARSING, |
| 534 |
e.getLocalizedMessage()), |
| 535 |
0, |
| 536 |
e); |
| 1232 |
} |
537 |
} |
| 1233 |
} |
538 |
} |
| 1234 |
return parser; |
539 |
return parser; |
| 1235 |
} |
540 |
} |
| 1236 |
|
541 |
|
| 1237 |
|
542 |
public static String removeChar(String input, char toRemove) { |
| 1238 |
private static PrimitiveWidgetId getActionId(IContributionItem contrib) |
543 |
StringBuffer buf = new StringBuffer(input.length()); |
| 1239 |
{ |
544 |
|
| 1240 |
String id = null; |
545 |
int last = 0; |
| 1241 |
PrimitiveWidgetId widgetId = new PrimitiveWidgetId(); |
546 |
for (int pos = input.indexOf(toRemove); pos != -1; pos = input.indexOf(toRemove, |
| 1242 |
|
547 |
last)) { |
| 1243 |
if (contrib instanceof IPluginContribution) |
548 |
buf.append(input.substring(last, |
| 1244 |
{ |
549 |
pos)); |
| 1245 |
id = ((IPluginContribution) contrib).getLocalId(); |
550 |
last = pos + 1; |
| 1246 |
} |
551 |
} |
| 1247 |
id = id == null ? contrib.getId() : id; |
552 |
|
| 1248 |
if (id != null) |
553 |
buf.append(input.substring(last, |
| 1249 |
{ |
554 |
input.length())); |
| 1250 |
widgetId.setId("contribid/" + id); //$NON-NLS-1$ |
555 |
|
| 1251 |
} |
556 |
return buf.toString(); |
| 1252 |
else |
557 |
} |
| 1253 |
{ |
558 |
|
| 1254 |
if (contrib instanceof ActionContributionItem) |
559 |
/** |
| 1255 |
{ |
560 |
* @param menuItem |
| 1256 |
ActionContributionItem actionItem = (ActionContributionItem) contrib; |
561 |
* @return |
| 1257 |
id = actionItem.getId(); |
562 |
*/ |
| 1258 |
if (id != null) |
563 |
public static boolean onMenubar(MenuItem menuItem) { |
| 1259 |
{ |
564 |
Menu parent = menuItem.getParent(); |
| 1260 |
widgetId.setId("actionid/" + id); //$NON-NLS-1$ |
565 |
MenuItem parentItem = parent.getParentItem(); |
| 1261 |
} |
566 |
|
| 1262 |
else |
567 |
if (parentItem != null) { |
| 1263 |
{ |
568 |
return onMenubar(parentItem); |
| 1264 |
IAction action = actionItem.getAction(); |
569 |
} |
| 1265 |
id = action.getActionDefinitionId(); |
570 |
|
| 1266 |
if (id != null) |
571 |
Shell theShell = parent.getShell(); |
| 1267 |
{ |
572 |
return parent == theShell.getMenuBar(); |
| 1268 |
widgetId.setId("defid/" + id); //$NON-NLS-1$ |
573 |
} |
| 1269 |
} |
574 |
|
| 1270 |
else |
575 |
public static ContributionManager onToolbar(ToolItem toolItem) { |
| 1271 |
{ |
576 |
ToolBar toolBar = toolItem.getParent(); |
| 1272 |
widgetId.setId("actionclass/" + action.getClass().getName()); //$NON-NLS-1$ |
577 |
Shell shell = toolBar.getShell(); |
| 1273 |
} |
578 |
Object data = shell.getData(); |
|
|
579 |
if (data instanceof ApplicationWindow) { |
| 580 |
ApplicationWindow window = (ApplicationWindow) data; |
| 581 |
ToolBarManager mng = window.getToolBarManager(); |
| 582 |
if (mng != null) { |
| 583 |
if (mng.getControl() != null && mng.getControl() == toolBar) |
| 584 |
return mng; |
| 585 |
} |
| 586 |
CoolBarManager cmng = window.getCoolBarManager(); |
| 587 |
if (cmng != null) { |
| 588 |
CoolBar cbar = cmng.getControl(); |
| 589 |
Composite parent = toolBar.getParent(); |
| 590 |
while (parent != null) { |
| 591 |
if (parent == cbar) |
| 592 |
return cmng; |
| 593 |
parent = parent.getParent(); |
| 1274 |
} |
594 |
} |
| 1275 |
} |
595 |
} |
| 1276 |
else |
596 |
} |
| 1277 |
{ |
597 |
return null; |
| 1278 |
widgetId.setId("contribclass/" + contrib.getClass().getName()); //$NON-NLS-1$ |
598 |
} |
|
|
599 |
|
| 600 |
public static IViewPart onWorkbenchPartToolbar(MenuItem menuItem) { |
| 601 |
IWorkbenchPage[] pages = GuiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getPages(); |
| 602 |
|
| 603 |
/* For evey page */ |
| 604 |
for (int i = 0; i < pages.length; i++) { |
| 605 |
IViewReference[] viewReferences = pages[i].getViewReferences(); |
| 606 |
|
| 607 |
/* For evey opened view */ |
| 608 |
for (int j = 0; j < viewReferences.length; j++) { |
| 609 |
IViewPart viewPart = viewReferences[j].getView(false); |
| 610 |
if (viewPart == null) |
| 611 |
continue; |
| 612 |
|
| 613 |
IMenuManager menuManager = viewPart.getViewSite().getActionBars().getMenuManager(); |
| 614 |
if (menuManager != null && menuManager instanceof MenuManager && searchForMenuItem(((MenuManager) menuManager).getMenu(), |
| 615 |
menuItem)) |
| 616 |
return viewPart; |
| 1279 |
} |
617 |
} |
| 1280 |
} |
618 |
} |
| 1281 |
|
619 |
|
| 1282 |
return widgetId; |
620 |
return null; |
| 1283 |
} |
621 |
} |
| 1284 |
|
622 |
|
|
|
623 |
private static boolean searchForMenuItem(Menu menu, MenuItem menuItem) { |
| 624 |
if (menu == null) |
| 625 |
return false; |
| 626 |
|
| 627 |
MenuItem[] items = menu.getItems(); |
| 628 |
for (int i = 0; i < items.length; i++) { |
| 629 |
if (items[i] == menuItem) |
| 630 |
return true; |
| 631 |
Menu cascadeMenu = items[i].getMenu(); |
| 632 |
if (cascadeMenu != null && searchForMenuItem(cascadeMenu, |
| 633 |
menuItem)) |
| 634 |
return true; |
| 635 |
} |
| 1285 |
|
636 |
|
|
|
637 |
return false; |
| 638 |
} |
| 639 |
|
| 1286 |
/** |
640 |
/** |
| 1287 |
* @param widget |
641 |
* @param wd |
|
|
642 |
* @param control |
| 1288 |
* @return |
643 |
* @return |
| 1289 |
*/ |
644 |
*/ |
| 1290 |
public static IWidgetId getActionId(Widget widget) |
645 |
public static boolean onWizardDialog(WizardDialog wd, Button control) { |
| 1291 |
{ |
646 |
// see if we have a button on the wizard page or on the wizard dialog (i.e. wizard) |
| 1292 |
Object data = widget.getData(); |
647 |
IWizardPage page = wd.getCurrentPage(); |
| 1293 |
PrimitiveWidgetId widgetId = new PrimitiveWidgetId(); |
648 |
Shell shell = control.getShell(); |
| 1294 |
if (data != null && (data instanceof IContributionItem)) |
649 |
Control pageControl = page.getControl(); |
| 1295 |
{ |
650 |
IUIObjectIdentifier relativePath = NonTrivialUIObjectResolverDelegate.computeRelativePath( |
| 1296 |
widgetId = getActionId((IContributionItem) data); |
651 |
(Composite) pageControl, |
| 1297 |
if (!widgetId.toString().equals(MacroConstants.EMPTY_STRING)) |
652 |
null, |
| 1298 |
{ |
653 |
control); |
| 1299 |
if (widget instanceof MenuItem) |
654 |
if (relativePath != null) { |
| 1300 |
{ |
655 |
return false; |
| 1301 |
String menuInx = findMenuItemIndex((MenuItem)widget, ""); |
656 |
} |
| 1302 |
widgetId.setId(widgetId.toString() + menuInx); |
657 |
// check for wizard buttons |
|
|
658 |
if (control instanceof Button) { |
| 659 |
relativePath = NonTrivialUIObjectResolverDelegate.computeRelativePath( |
| 660 |
shell, |
| 661 |
(Composite) pageControl, |
| 662 |
control); |
| 663 |
return true; |
| 664 |
} |
| 665 |
return false; |
| 666 |
|
| 667 |
} |
| 668 |
|
| 669 |
/** |
| 670 |
* Used to located the editor part with the passed id. |
| 671 |
* |
| 672 |
* @param shell |
| 673 |
* The current shell |
| 674 |
* @param id |
| 675 |
* The id of the editor part |
| 676 |
* @param line |
| 677 |
* The line number of the script (used to indicate the line number if we throw a core exception. Mark as -1 if a script is not being |
| 678 |
* used) |
| 679 |
* @param input |
| 680 |
* If not null, then it attempts to match the input of the identified editor with the input that is passed it. |
| 681 |
* |
| 682 |
* @return The editor part with the passed 'id' |
| 683 |
* |
| 684 |
* @throws CoreException |
| 685 |
* If the editor part cannot be located. |
| 686 |
*/ |
| 687 |
public static IEditorPart locateEditor(Shell shell, String id, String input) throws CoreException { |
| 688 |
Object data = shell.getData(); |
| 689 |
IEditorPart editor = null; |
| 690 |
|
| 691 |
try { |
| 692 |
if (data instanceof IWorkbenchWindow) { |
| 693 |
IWorkbenchWindow window = (IWorkbenchWindow) data; |
| 694 |
IWorkbenchPage page = window.getActivePage(); |
| 695 |
|
| 696 |
if (page != null) { |
| 697 |
IEditorReference[] erefs = page.getEditorReferences(); |
| 698 |
|
| 699 |
for (int i = 0; i < erefs.length; i++) { |
| 700 |
IEditorReference eref = erefs[i]; |
| 701 |
if (eref.getId().equals(id)) { |
| 702 |
// check the input |
| 703 |
IEditorPart part = eref.getEditor(true); |
| 704 |
if (input == null) { |
| 705 |
editor = part; |
| 706 |
break; |
| 707 |
} |
| 708 |
else if (part.getEditorInput().getName().equals(input)) { |
| 709 |
editor = part; |
| 710 |
break; |
| 711 |
} |
| 712 |
} |
| 713 |
} |
| 714 |
} |
| 715 |
} |
| 716 |
} |
| 717 |
catch (Throwable t) { |
| 718 |
|
| 719 |
} |
| 720 |
if (editor != null) { |
| 721 |
editor.getSite().getPage().activate(editor); |
| 722 |
return editor; |
| 723 |
} |
| 724 |
|
| 725 |
AutoGUIUtil.throwCoreException(NLS.bind(AutoGUIMessages.AUTO_GUI_ERROR_MACRO_EDITOR, |
| 726 |
id)); |
| 727 |
return null; |
| 728 |
} |
| 729 |
|
| 730 |
/** |
| 731 |
* Used to located the view part with the passed id. |
| 732 |
* |
| 733 |
* @param shell |
| 734 |
* The current shell |
| 735 |
* @param id |
| 736 |
* The id of the view part |
| 737 |
* @param line |
| 738 |
* The line number of the script (used to indicate the line number if we throw a core exception. Mark as -1 if a script is not being |
| 739 |
* used) |
| 740 |
* |
| 741 |
* @return The view part with the passed 'id' |
| 742 |
* |
| 743 |
* @throws CoreException |
| 744 |
* If the view part cannot be located. |
| 745 |
*/ |
| 746 |
public static IViewPart locateView(Shell shell, String id) throws CoreException { |
| 747 |
try { |
| 748 |
Object data = shell.getData(); |
| 749 |
|
| 750 |
if (data instanceof IWorkbenchWindow) { |
| 751 |
IWorkbenchWindow window = (IWorkbenchWindow) data; |
| 752 |
IWorkbenchPage page = window.getActivePage(); |
| 753 |
if (page != null) { |
| 754 |
IViewPart view = page.findView(id); |
| 755 |
|
| 756 |
if (view == null) { |
| 757 |
try { |
| 758 |
view = page.showView(id); |
| 759 |
|
| 760 |
} |
| 761 |
catch (PartInitException pie) { |
| 762 |
/* Do a thorough search */ |
| 763 |
IWorkbenchWindow[] windows = GuiPlugin.getDefault().getWorkbench().getWorkbenchWindows(); |
| 764 |
|
| 765 |
/* For every workbench window */ |
| 766 |
for (int i = 0; i < windows.length && view == null; i++) { |
| 767 |
/* For every page of a workbench window */ |
| 768 |
IWorkbenchPage[] pages = windows[i].getPages(); |
| 769 |
for (int j = 0; j < pages.length && view == null; j++) { |
| 770 |
view = pages[j].findView(id); |
| 771 |
|
| 772 |
} |
| 773 |
} |
| 774 |
// need to mke sure that even if it is found in another page, we show it. |
| 775 |
|
| 776 |
} |
| 777 |
} |
| 778 |
// added for defcet 175320 in order to ensure the page is |
| 779 |
// given focus no matter where it is found |
| 780 |
page.showView(id); |
| 781 |
return view; |
| 1303 |
} |
782 |
} |
| 1304 |
} |
783 |
} |
| 1305 |
} |
784 |
} |
| 1306 |
else |
785 |
catch (Throwable t) { |
| 1307 |
{ |
786 |
/* The next line will throw an exception */ |
| 1308 |
widgetId.setId("readablename/" + ((widget instanceof MenuItem) ? getDisplayName((MenuItem)widget) : getDisplayName((ToolItem)widget))); //$NON-NLS-1$ |
|
|
| 1309 |
} |
787 |
} |
| 1310 |
|
788 |
AutoGUIUtil.throwCoreException(NLS.bind(AutoGUIMessages.AUTO_GUI_ERROR_MACRO_VIEW, |
| 1311 |
return widgetId; |
789 |
id)); |
|
|
790 |
return null; |
| 1312 |
} |
791 |
} |
|
|
792 |
|
| 1313 |
} |
793 |
} |