View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: ConnectionGroupWrapper.java
13   * Created: 2005-05-21
14   * Author: fox
15   * $Id: OutlineLabelProvider.java 2770 2009-04-21 19:17:34Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.ui.outline;
19  
20  import java.util.Collection;
21  
22  import org.eclipse.jface.viewers.LabelProvider;
23  import org.eclipse.swt.graphics.Image;
24  
25  import pl.edu.agh.cast.model.visual.backward.Node;
26  import pl.edu.agh.cast.util.Images;
27  import pl.edu.agh.cast.util.Messages;
28  
29  /**
30   * {@link LabelProvider} for outline view.
31   *
32   * @author AGH CAST Team
33   */
34  public class OutlineLabelProvider extends LabelProvider {
35  
36  	private static OutlineLabelProvider instance = new OutlineLabelProvider();
37  
38  	/**
39  	 * Default constructor.
40  	 */
41  	protected OutlineLabelProvider() {
42  	}
43  
44  	/**
45  	 * Returns single, shared instance of {@link OutlineLabelProvider}.
46  	 *
47  	 * @return single, shared instance of {@link OutlineLabelProvider}
48  	 */
49  	public static OutlineLabelProvider getInstance() {
50  		return instance;
51  	}
52  
53  	/**
54  	 * {@inheritDoc}
55  	 *
56  	 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
57  	 */
58  	@Override
59  	public String getText(Object element) {
60  		if (element instanceof Collection<?>) {
61  			return Messages.OutlineLabelProvider_0;
62  		}
63  		if (element instanceof Node) {
64  			return ((Node)element).getId();
65  		}
66  		if (element instanceof ConnectionGroupWrapper) {
67  			return ((ConnectionGroupWrapper)element).getTargetNode().getId();
68  		}
69  		return element.toString();
70  	}
71  
72  	/**
73  	 * {@inheritDoc}
74  	 *
75  	 * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
76  	 */
77  	@Override
78  	public Image getImage(Object element) {
79  		if (element instanceof Collection<?>) {
80  			return Images.getInstance().get(Images.FILE);
81  		}
82  		if (element instanceof ConnectionGroupWrapper) {
83  			return Images.getInstance().get(Images.CONNECTION);
84  		}
85  		if (element instanceof Node) {
86  			return Images.getInstance().get(Images.NODE);
87  		}
88  		return null;
89  	}
90  
91  }