Project

General

Profile

Download (2.14 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.store.datasource.view;
12

    
13
import org.eclipse.jface.viewers.ITableLabelProvider;
14
import org.eclipse.jface.viewers.LabelProvider;
15
import org.eclipse.swt.graphics.Image;
16

    
17
import eu.etaxonomy.cdm.database.ICdmDataSource;
18
import eu.etaxonomy.taxeditor.store.datasource.CdmDataSourceRepository;
19
import eu.etaxonomy.taxeditor.store.model.ImageResources;
20

    
21
/**
22
 * @author n.hoffmann
23
 * @created 14.04.2009
24
 * @version 1.0
25
 */
26
public class CdmDataSourceLabelProvider extends LabelProvider implements ITableLabelProvider {
27

    
28
	/*
29
	 * (non-Javadoc)
30
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int)
31
	 */
32
	public Image getColumnImage(Object element, int columnIndex) {
33
		// No image at the moment.
34
		// TODO display image in colum 0 if the datasource is connected
35
		if(columnIndex == 0){
36
			ICdmDataSource dataSource = (ICdmDataSource) element;
37
			String key = isCurrentDataSource(dataSource) ? ImageResources.IMG_DATASOURCE_CONNECTED : ImageResources.IMG_DATASOURCE_DISCONNECTED;
38
			
39
			return ImageResources.getImage(key);
40
		}
41
		
42
		return null;
43
	}
44

    
45
	/*
46
	 * (non-Javadoc)
47
	 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int)
48
	 */
49
	public String getColumnText(Object element, int columnIndex) {
50
		ICdmDataSource dataSource = (ICdmDataSource) element;
51
		switch (columnIndex){
52
//			case 0:
53
//				return isCurrentDataSource(dataSource) ? "Y" : "N"; 
54
			case 1:
55
				return dataSource.getName();
56
			case 2:
57
				if(dataSource.getServer() != null){
58
					// true for h2 databases
59
					return dataSource.getServer();
60
				}
61
				return "local";
62
			case 3:
63
				return dataSource.getDatabaseType().getName();
64
		}
65
		return null;
66
	}
67
	
68
	private boolean isCurrentDataSource(ICdmDataSource dataSource){
69
		String current = CdmDataSourceRepository.getDefault().getCurrentDataSource().getName();
70
		return current.equals(dataSource.getName());
71
	}
72
}
(2-2/3)