KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > activities > ws > ActivityLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.activities.ws;
12
13 import org.eclipse.jface.viewers.LabelProvider;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.ui.activities.IActivity;
16 import org.eclipse.ui.activities.IActivityManager;
17 import org.eclipse.ui.activities.NotDefinedException;
18
19 /**
20  * Provides labels for <code>IActivity</code> objects. They may be passed
21  * directly or as <code>String</code> identifiers that are matched against
22  * the activity manager.
23  *
24  * @since 3.0
25  */

26 public class ActivityLabelProvider extends LabelProvider {
27
28     private IActivityManager activityManager;
29
30     /**
31      * Create a new instance of the receiver.
32      *
33      * @param activityManager
34      * @since 3.0
35      */

36     public ActivityLabelProvider(IActivityManager activityManager) {
37         this.activityManager = activityManager;
38     }
39
40     /**
41      * @param activity
42      * @return
43      */

44     private String JavaDoc getActivityText(IActivity activity) {
45         try {
46             return activity.getName();
47         } catch (NotDefinedException e) {
48             return activity.getId();
49         }
50     }
51
52     /*
53      * (non-Javadoc)
54      *
55      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
56      */

57     public Image getImage(Object JavaDoc element) {
58         return null;
59     }
60
61     /*
62      * (non-Javadoc)
63      *
64      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
65      */

66     public String JavaDoc getText(Object JavaDoc element) {
67         if (element instanceof String JavaDoc) {
68             return getActivityText(activityManager
69                     .getActivity((String JavaDoc) element));
70         } else if (element instanceof IActivity) {
71             return getActivityText((IActivity) element);
72         } else {
73             throw new IllegalArgumentException JavaDoc();
74         }
75     }
76 }
77
Popular Tags