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 hdf.view.DataView.DataViewManager;
017import hdf.view.Tools;
018import hdf.view.ViewProperties;
019
020import org.slf4j.Logger;
021import org.slf4j.LoggerFactory;
022
023import org.eclipse.swt.widgets.Composite;
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    {
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)
058            throw new ClassNotFoundException();
059
060        try {
061            theView = (TreeView)Tools.newInstance(theClass, initargs);
062
063            log.trace("getTreeView(): returning TreeView instance {}", theView);
064        }
065        catch (Exception ex) {
066            log.debug("getTreeView(): Error instantiating class:", ex);
067            theView = null;
068        }
069
070        return theView;
071    }
072}