fixing potential NPE
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 4 Mar 2020 07:18:29 +0000 (08:18 +0100)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 4 Mar 2020 07:18:29 +0000 (08:18 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/CdmDataSourceLabelProvider.java

index dcf51b0f55769c4d402218ee6612c74e8d0fdc48..ebe80af796f9c66ff1df57c61472a4290eb4597f 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
@@ -27,26 +27,28 @@ import eu.etaxonomy.taxeditor.store.CdmStore;
  * @created 14.04.2009
  */
 public class CdmDataSourceLabelProvider extends LabelProvider implements ITableLabelProvider {
-       
+
        /** {@inheritDoc} */
-       public Image getColumnImage(Object element, int columnIndex) {
+       @Override
+    public Image getColumnImage(Object element, int columnIndex) {
                if(columnIndex == 0){
                        ICdmSource dataSource = ((CdmMetaDataAwareDataSourceContainer) element).getCdmSource();
-                       
+
                        String key = isCurrentDataSource(dataSource) ? ImageResources.IMG_DATASOURCE_CONNECTED : ImageResources.IMG_DATASOURCE_DISCONNECTED;
-                       
+
                        return ImageResources.getImage(key);
                }
-               
+
                return null;
        }
 
        /** {@inheritDoc} */
-       public String getColumnText(Object element, int columnIndex) {
+       @Override
+    public String getColumnText(Object element, int columnIndex) {
                CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) element;
-                               
+
                ICdmSource dataSource = container.getCdmSource();
-                               
+
                switch (columnIndex){
                        case 1:
                                return dataSource.getName();
@@ -59,11 +61,11 @@ public class CdmDataSourceLabelProvider extends LabelProvider implements ITableL
                        case 3:
                                return container.isRunning() ? "Yes" : "No";
                        case 4:
-                               if(dataSource instanceof ICdmDataSource) {
+                               if(dataSource instanceof ICdmDataSource && ((ICdmDataSource)dataSource).getDatabaseType() != null) {
                                        return ((ICdmDataSource)dataSource).getDatabaseType().getName();
                                } else {
                                        return "";
-                               }                               
+                               }
                        case 5:
                                if(dataSource instanceof ICdmDataSource) {
                                        return ((ICdmDataSource)dataSource).getDatabase();
@@ -84,7 +86,7 @@ public class CdmDataSourceLabelProvider extends LabelProvider implements ITableL
                }
                return CdmMetaDataAwareDataSourceContainer.DEFAULT_ENTRY;
        }
-       
+
        private boolean isCurrentDataSource(ICdmSource dataSource){
                ICdmSource currentDataSource = CdmStore.getActiveCdmSource();
                return currentDataSource != null && currentDataSource.getName().equals(dataSource.getName());