function create(obj)
% create
% -------------------------------------------------------------------------
% Abstract: This method creates all parts of the main obj display
%

% Copyright 2019 The MathWorks, Inc.
%
% Auth/Revision:
%   MathWorks Consulting
%   $Author: rjackey $
%   $Revision: 249 $  $Date: 2016-08-24 08:48:10 -0400 (Wed, 24 Aug 2016) $
% ---------------------------------------------------------------------


%% Create QSP Menus

ItemTypes = {
    'Dataset',                          'OptimizationData'
    'Parameter',                        'Parameters'
    'Task',                             'Task'
    'Virtual Subject(s)',               'VirtualPopulation'    
    'Acceptance Criteria',              'VirtualPopulationData'
    'Target Statistics',                'VirtualPopulationGenerationData'
    'Simulation',                       'Simulation'
    'Optimization',                     'Optimization'
    'Cohort Generation',                'CohortGeneration'
    'Virtual Population Generation',    'VirtualPopulationGeneration'
    };

% QSP Top Menu
obj.h.QSPMenu.Menu = uimenu(...
    'Parent', obj.Figure,...
    'Label', 'QSP');

% Add item submenu
obj.h.QSPMenu.Add = uimenu(...
    'Parent', obj.h.QSPMenu.Menu,...
    'Label', 'Add New Item');
for idx=1:size(ItemTypes,1)
    obj.h.QSPMenu.AddItem(idx) = uimenu(...
        'Parent', obj.h.QSPMenu.Add,...
        'Label', ItemTypes{idx,1},...
        'Callback', @(h,e)onAddItem(obj,ItemTypes{idx,2}));
end

% Remove selected item
obj.h.QSPMenu.Remove = uimenu(...
    'Parent', obj.h.QSPMenu.Menu,...
    'Label', 'Delete Selected Item',...
    'Callback', @(h,e)onRemoveItem(obj));

% Restore selected deleted item
obj.h.QSPMenu.Restore = uimenu(...
    'Parent', obj.h.QSPMenu.Menu,...
    'Label', 'Restore Selected Item',...
    'Callback', @(h,e)onRestoreItem(obj));

% Help menu
obj.h.HelpMenu = uimenu(...
    'Parent', obj.Figure, ...
    'Label', 'Help');

obj.h.AboutDlg = uimenu(...
    'Parent', obj.h.HelpMenu, ...
    'Label', 'About', ...
    'Callback', @(h,e) onHelpAbout(obj));

obj.h.SubmitLink = uimenu(...
    'Parent', obj.h.HelpMenu, ...
    'Label', 'Submit bug or query', ...    
    'Callback', @(h,e) web(['https://docs.google.com/forms/d/e/1FAIpQLScJ4L2C5YIJ1hKK_Ar-XrbmYsh3vKjwqs3j2_KxhgygcR_qqw/viewform?usp=pp_url&entry.1094397833=R2018a&entry.16100672=' obj.Version]));

%% Tree context menus

% For Session
obj.h.TreeMenu.Branch.Session = uicontextmenu('Parent', obj.Figure);
uimenu(...
    'Parent', obj.h.TreeMenu.Branch.Session,...
    'Label', 'Close',...
    'Callback', @(h,e)onCloseSession(obj));
obj.h.TreeMenu.Branch.SessionSave = uimenu(...
    'Parent', obj.h.TreeMenu.Branch.Session,...
    'Label', 'Save',...
    'Separator', 'on',...
    'Callback', @(h,e)onSave(obj));
uimenu(...
    'Parent', obj.h.TreeMenu.Branch.Session,...
    'Label', 'SaveAs',...
    'Callback', @(h,e)onSaveAs(obj));



% For most branches/leaves
for idx=1:size(ItemTypes,1)
    ThisItemType = strrep(ItemTypes{idx,1},'Settings: ','');
    % For branches
    obj.h.TreeMenu.Branch.(ItemTypes{idx,2}) = uicontextmenu('Parent', obj.Figure);
    uimenu(...
        'Parent', obj.h.TreeMenu.Branch.(ItemTypes{idx,2}),...
        'Label', ['Add new ' ThisItemType],...
        'Callback', @(h,e)onAddItem(obj,ItemTypes{idx,2}));
    % For Leaves
    obj.h.TreeMenu.Leaf.(ItemTypes{idx,2}) = uicontextmenu('Parent', obj.Figure);
    uimenu(...
        'Parent', obj.h.TreeMenu.Leaf.(ItemTypes{idx,2}),...
        'Label', ['Duplicate this ' ThisItemType],...
        'Callback', @(h,e)onDuplicateItem(obj));
    uimenu(...
        'Parent', obj.h.TreeMenu.Leaf.(ItemTypes{idx,2}),...
        'Label', ['Delete this ' ThisItemType],...
        'Separator', 'on',...
        'Callback', @(h,e)onRemoveItem(obj));
end

% For Deleted Items
obj.h.TreeMenu.Branch.Deleted = uicontextmenu('Parent', obj.Figure);
uimenu(...
    'Parent', obj.h.TreeMenu.Branch.Deleted,...
    'Label', 'Empty Deleted Items',...
    'Callback', @(h,e)onEmptyDeletedItems(obj,true));
obj.h.TreeMenu.Leaf.Deleted = uicontextmenu('Parent', obj.Figure);
uimenu(...
    'Parent', obj.h.TreeMenu.Leaf.Deleted,...
    'Label', 'Restore',...
    'Callback', @(h,e)onRestoreItem(obj));
uimenu(...
    'Parent', obj.h.TreeMenu.Leaf.Deleted,...
    'Label', 'Permanently Delete',...
    'Separator', 'on',...
    'Callback', @(h,e)onEmptyDeletedItems(obj,false));


%% Create the layout

% The horizontal layout, making left/right panes
obj.h.HLayout = uix.HBoxFlex(...
    'Parent',obj.Figure,...
    'Spacing',8);

% The Left Panel
obj.h.LeftPanel = uix.BoxPanel(...
    'Parent',obj.h.HLayout,...
    'FontSize',10,...
    'Title','Session Explorer',...
    'Padding',2);

% The Right panel that will contain any right pane contents
obj.h.RightPanel = uix.Panel('Parent',obj.h.HLayout);

% Adjust sizes
obj.h.HLayout.Widths = [-1 -3];


%% Create the Session Explorer Pane

% Listbox for session pieces
obj.h.SessionTree = uix.widget.Tree(...
    'Parent',obj.h.LeftPanel,...
    'FontSize',8,...
    'RootVisible','off',...
    'SelectionChangeFcn',@(h,e)onSelectionChanged(obj,h,e),...
    'DndEnabled','on',...
    'NodeDroppedCallback', @(h,e) onNodeDrop(obj,h,e),...
    'SelectionType', 'discontiguous');

% Adjust sizes
obj.h.LeftVLayout.Heights = [-1 25];


%% Set up the ViewPaneManager on the right pane

% Where to place views?
obj.ViewPaneParent = obj.h.RightPanel;

% What packages do the data objects and viewers use?
obj.DataPackage = 'QSP';
obj.ViewPackage = 'QSPViewer';





