001/*****************************************************************************
002 * Copyright by The HDF Group.                                               *
003 * Copyright by the Board of Trustees of the University of Illinois.         *
004 * All rights reserved.                                                      *
005 *                                                                           *
006 * This file is part of the HDF Java Products distribution.                  *
007 * The full copyright notice, including terms governing use, modification,   *
008 * and redistribution, is contained in the files COPYING and Copyright.html. *
009 * COPYING can be found at the root of the source code distribution tree.    *
010 * Or, see https://support.hdfgroup.org/products/licenses.html               *
011 * If you do not have access to either file, you may request a copy from     *
012 * help@hdfgroup.org.                                                        *
013 ****************************************************************************/
014
015package hdf.view.TreeView;
016
017import org.eclipse.swt.widgets.Composite;
018
019import hdf.view.Tools;
020import hdf.view.ViewProperties;
021import hdf.view.DataView.DataViewManager;
022
023/**
024 * A simple Factory class which returns concrete instances of the default
025 * TreeView.
026 *
027 * @author jhenderson
028 * @version 1.0 4/18/2018
029 */
030public class DefaultTreeViewFactory extends TreeViewFactory {
031
032    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DefaultTreeViewFactory.class);
033
034    @Override
035    public TreeView getTreeView(Composite parent, DataViewManager viewer) throws ClassNotFoundException {
036        String dataViewName = null;
037        Object[] initargs = { parent, viewer };
038        TreeView theView = null;
039
040        dataViewName = ViewProperties.DEFAULT_TREEVIEW_NAME;
041
042        Class<?> theClass = null;
043        try {
044            log.trace("getTreeView(): Class.forName({})", dataViewName);
045
046            /* Attempt to load the class by the given name */
047            theClass = Class.forName(dataViewName);
048        }
049        catch (Exception ex) {
050            log.debug("getTreeView(): unable to load default TreeView class by name({})", dataViewName);
051            theClass = null;
052        }
053
054        if (theClass == null) throw new ClassNotFoundException();
055
056        try {
057            theView = (TreeView) Tools.newInstance(theClass, initargs);
058
059            log.trace("getTreeView(): returning TreeView instance {}", theView);
060        }
061        catch (Exception ex) {
062            log.debug("getTreeView(): Error instantiating class:", ex);
063            theView = null;
064        }
065
066        return theView;
067    }
068
069}