function Panel = getDialogSchema(this, manager)

import javax.swing.*;

%% Create the node panel and components
Panel = localBuildPanel(manager.Figure,this,manager);

%% Populate the view combo
viewnodenames = get(this.up.getChildren,{'Label'});
set(this.Handles.COMBselectView,'String',viewnodenames,...
    'Value',find(strcmp(this.Label,viewnodenames)))

%% Show the panel
figure(double(manager.Figure))

% Temporary listeners to update table visibility when the enclosing panel
% visibility is modified
p = handle(Panel);
this.addListeners(handle.listener(p,p.findprop('Visible'),'PropertyPostSet',...
    {@localSetVisible p}));


function f = localBuildPanel(thisfig,h,manager)
%% Create and position the components on the panel
 
%% Build upper combo and label
f = uipanel('Parent',thisfig,'Units','Normalized');
TXTselectView = uicontrol('Style','text','Parent',f,'Units',...
    'Characters','String','Select view','HorizontalAlignment','Left');
h.Handles.COMBselectView = uicontrol('Style','popup','Parent',...
    f,'Units','Characters','String',{'test'},'BackgroundColor',[1 1 1],'Callback',...
    {@localViewCombCallback h manager}); 

%% Build time series panel
h.Handles.PNLTs = uipanel('Parent',f,'Units','Characters','Title', ...
    'Define Displayed Time Series');
h.Handles.BTNEditView = uicontrol('Style','pushbutton','Parent', ...
    f,'Units','Characters','String','Edit View...',...
    'Callback',{@localEditView h});
h.tspanel;

%% Resize behavior
set(f,'ResizeFcn',{@localFigResize h.Handles.PNLTs ...
    h.Handles.COMBselectView TXTselectView  h.Handles.BTNEditView});


function localSetVisible(es,ed,h)

children = h.find('-depth',inf,'-isa','uicontainer');
if ~isempty(children)
   set(children,'Visible',get(h,'Visible'));
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Resize functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  

function localFigResize(es,ed,PNLTs,COMBselectView,TXTselectView,EDITBTN)

%% Resize callback for view panel

%% No-op if the panel is inivible or if there is no eventData passed with
%% the firing resize event
if strcmp(get(es,'Visible'),'off') && isempty(ed)
    return
end

margin = 2;

% If userdata is not empty this is just a unit change issued by
% tsgetposition or tssetposition - no op
if ~isempty(get(es,'Userdata'))
    return
end

%% Components and panels are repositioned relative to the main panel
pos = hgconvertunits(ancestor(es,'figure'),get(es,'Position'),get(es,'Units'),...
    'characters',get(es,'Parent'));

%% Set the time series selector size
set(TXTselectView,'Position',[2 max(1,pos(4)-3.3) 14 2]);
set(COMBselectView,'Position',[16 max(1,pos(4)-3) max(1,pos(3)-18) 2])

%% Set the time series panel to take up all the space horizonatally
%% the top 50 characters the available vertical space
set(PNLTs,'Position',[margin max(1,pos(4)-34) max(1,pos(3)-2*margin) 30])
btnSize = get(EDITBTN,'Extent');
BtnSize = [max(1,pos(3)-18) max(1,pos(4)-36) 15 1.5];
set(EDITBTN,'Position',BtnSize);


function localViewCombCallback(eventSrc,eventData,h,manager)

%% Find the view node corresponding to the selected combo item
combpos = get(eventSrc,'Value');
combvals = get(eventSrc,'String');
Iold = find(strcmp(combvals,h.Label));
Inew = find(strcmp(get(h.up.getviews,{'Label'}),combvals(combpos)));

%% Programatically hit the corresponding node
if ~isempty(Inew)
    manager.Tree.setSelectedNode(h.up.getviews(Inew(1)).getTreeNodeInterface)
end

%% Set the combo back to its former value so that the Dialog panel remains
%% in sync with its corresponding node. This creates the illusion that the
%% view selection panel is independent of the selected node
set(eventSrc,'value',Iold(1))


function localEditView(eventSrc,eventData,this)
%% Edit view button callback which detaches Opens the PlotTool 

%% Property Editor
if ~isempty(this.Plot)
    propedit(this.Plot.AxesGrid.Parent);
else
    errordlg('No plot has been created to edit','Time Series Tools','modal')
end


