01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.tests.macro;
11:
12: import org.eclipse.core.resources.IResource;
13: import org.eclipse.jdt.core.IClasspathContainer;
14: import org.eclipse.jdt.core.IJavaElement;
15: import org.eclipse.pde.core.IIdentifiable;
16: import org.eclipse.pde.core.plugin.IPluginModelBase;
17: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
18: import org.eclipse.swt.custom.CTabFolder;
19: import org.eclipse.swt.widgets.Button;
20: import org.eclipse.swt.widgets.TabFolder;
21: import org.eclipse.swt.widgets.TableItem;
22: import org.eclipse.swt.widgets.TreeItem;
23: import org.eclipse.swt.widgets.Widget;
24: import org.eclipse.ui.IPluginContribution;
25:
26: public class DefaultWidgetResolver implements IWidgetResolver {
27: public String getUniqueId(Widget widget) {
28: Object data = widget.getData();
29:
30: // direct resolution (widget-independent)
31: if (data instanceof IPluginContribution)
32: return ((IPluginContribution) data).getLocalId();
33:
34: // widget-specific resolution
35: if (widget instanceof TreeItem || widget instanceof TableItem) {
36: if (data instanceof IJavaElement)
37: return ((IJavaElement) data).getPath().toString();
38: if (data instanceof IResource)
39: return ((IResource) data).getFullPath().toString();
40: if (data instanceof IClasspathContainer)
41: return ((IClasspathContainer) data).getPath()
42: .toString();
43: if (data instanceof IPluginModelBase)
44: return ((IPluginModelBase) data).getPluginBase()
45: .getId();
46: if (data instanceof IFeatureModel)
47: return ((IFeatureModel) data).getFeature().getId();
48: if (data instanceof IIdentifiable)
49: return ((IIdentifiable) data).getId();
50: }
51: if (widget instanceof Button) {
52: if (data instanceof Integer)
53: return "ButtonId=" + ((Integer) data).intValue();
54: }
55: if (widget instanceof TabFolder || widget instanceof CTabFolder) {
56: }
57: return null;
58: }
59: }
|