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.slf4j.Logger;
018import org.slf4j.LoggerFactory;
019
020import org.eclipse.swt.widgets.Composite;
021
022import hdf.view.Tools;
023import hdf.view.ViewProperties;
024import hdf.view.DataView.DataViewManager;
025
026/**
027 * A simple Factory class which returns concrete instances of the default
028 * TreeView.
029 *
030 * @author jhenderson
031 * @version 1.0 4/18/2018
032 */
033public class DefaultTreeViewFactory extends TreeViewFactory {
034
035    private static final Logger log = LoggerFactory.getLogger(DefaultTreeViewFactory.class);
036
037    @Override
038    public TreeView getTreeView(Composite parent, DataViewManager viewer) throws ClassNotFoundException {
039        String dataViewName = null;
040        Object[] initargs = { parent, viewer };
041        TreeView theView = null;
042
043        dataViewName = ViewProperties.DEFAULT_TREEVIEW_NAME;
044
045        Class<?> theClass = null;
046        try {
047            log.trace("getTreeView(): Class.forName({})", dataViewName);
048
049            /* Attempt to load the class by the given name */
050            theClass = Class.forName(dataViewName);
051        }
052        catch (Exception ex) {
053            log.debug("getTreeView(): unable to load default TreeView class by name({})", dataViewName);
054            theClass = null;
055        }
056
057        if (theClass == null) throw new ClassNotFoundException();
058
059        try {
060            theView = (TreeView) Tools.newInstance(theClass, initargs);
061
062            log.trace("getTreeView(): returning TreeView instance {}", theView);
063        }
064        catch (Exception ex) {
065            log.debug("getTreeView(): Error instantiating class:", ex);
066            theView = null;
067        }
068
069        return theView;
070    }
071
072}