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