01: /*******************************************************************************
02: * Copyright (c) 2003, 2006 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.ui.internal.activities.ws;
11:
12: import org.eclipse.jface.viewers.LabelProvider;
13: import org.eclipse.swt.graphics.Image;
14: import org.eclipse.ui.activities.IActivity;
15: import org.eclipse.ui.activities.IActivityManager;
16: import org.eclipse.ui.activities.NotDefinedException;
17:
18: /**
19: * Provides labels for <code>IActivity</code> objects. They may be passed
20: * directly or as <code>String</code> identifiers that are matched against
21: * the activity manager.
22: *
23: * @since 3.0
24: */
25: public class ActivityLabelProvider extends LabelProvider {
26:
27: private IActivityManager activityManager;
28:
29: /**
30: * Create a new instance of the receiver.
31: *
32: * @param activityManager
33: * @since 3.0
34: */
35: public ActivityLabelProvider(IActivityManager activityManager) {
36: this .activityManager = activityManager;
37: }
38:
39: /**
40: * @param activity
41: * @return
42: */
43: private String getActivityText(IActivity activity) {
44: try {
45: return activity.getName();
46: } catch (NotDefinedException e) {
47: return activity.getId();
48: }
49: }
50:
51: /*
52: * (non-Javadoc)
53: *
54: * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
55: */
56: public Image getImage(Object element) {
57: return null;
58: }
59:
60: /*
61: * (non-Javadoc)
62: *
63: * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
64: */
65: public String getText(Object element) {
66: if (element instanceof String) {
67: return getActivityText(activityManager
68: .getActivity((String) element));
69: } else if (element instanceof IActivity) {
70: return getActivityText((IActivity) element);
71: } else {
72: throw new IllegalArgumentException();
73: }
74: }
75: }
|