function DialogPanel = getDialogSchema(this, manager)
%  BUILD  Construct the dialog panel

%  Author(s): John Glass
%  Revised:
%  Copyright 1986-2004 The MathWorks, Inc.

import com.mathworks.toolbox.slcontrol.ModelLinearizationProject.*

%% Add the settings pane to the frame
DialogPanel = ModelLinearizationSettingsPanel;

%% Make the panel visible
DialogPanel.setVisible(1);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Linear Analysis Button
%% Set the action callback for the linearization button and store its
%% handle
LinearizeButtonUDD = DialogPanel.getLinearizeButton;
set(LinearizeButtonUDD,'ActionPerformedCallback',{@LocalLinearizeModelCallback,this})
this.LinearizeButtonUDD = LinearizeButtonUDD;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Configure the operation condition selection panel
this.ConfigureOperatingConditionSelectionPanel(DialogPanel);                           
                                
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Configure the analysis result summary panel
ConfigureAnalysisResultsPanel(this,DialogPanel)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% IO Table Model
%% Set the action callback for the analysis IO table model and store its
%% handle
AnalysisIOTableModelUDD = DialogPanel.IOPanel.IOTableModel;
set(AnalysisIOTableModelUDD,'TableChangedCallback',{@LocalUpdateSetIOTableData,this})
this.AnalysisIOTableModelUDD = AnalysisIOTableModelUDD;

%% Set the table data for the linearization ios
table_data = this.getIOTableData;
AnalysisIOTableModelUDD.data = table_data;

%% Create the cell attributes
import com.mathworks.toolbox.slcontrol.AdvTableObjects.*;
cellAtt = DefaultCellAttribute(size(table_data,1),6);
this.AnalysisIOTableModelUDD.cellAtt = cellAtt;

%% Create a table model event to update the table
evt = javax.swing.event.TableModelEvent(this.AnalysisIOTableModelUDD);
this.AnalysisIOTableModelUDD.fireTableChanged(evt);
set(AnalysisIOTableModelUDD,'TableChangedCallback',{@LocalUpdateSetIOTableData,this})
this.AnalysisIOTableModelUDD = AnalysisIOTableModelUDD;

%% Configure the highlight signal button
h = handle(DialogPanel.IOPanel.getHighlightButton, 'callbackproperties');
h.ActionPerformedCallback = {@LocalHighlightSignal this};

%% Configure the delete point button
h = handle(DialogPanel.IOPanel.getDeletePointButton, 'callbackproperties');
h.ActionPerformedCallback = {@LocalDeletePoint this};

%% Configure the refresh signal button
h = handle(DialogPanel.IOPanel.getRefreshSignalButton, 'callbackproperties');
h.ActionPerformedCallback = {@LocalRefreshSignalNames this};

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Local Functions 
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LocalHighlightSignal - Callback to highlight a signal
function LocalHighlightSignal(es,ed,this)

%% Get the selected row
row = this.Dialog.IOPanel.IOTable.getSelectedRow+1;
 
if row > 0
    %% Get the block and port handle
    block = this.IOData(row).Block;
    port_number = this.IOData(row).PortNumber;
    try
        ph = get_param(block,'PortHandles');
        port = ph.Outport(port_number);
        hilite_system(port,'find');pause(1);hilite_system(port,'none')
    catch
        str = sprintf('The block %s is no longer in the model',block);
        errordlg(str,'Simulink Control Design')
    end
else
    str = sprintf('Please select a linearization point.');
    warndlg(str,'Simulink Control Design')
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LocalDeletePoint - Callback to delete a linearization point
function LocalDeletePoint(es,ed,this)

%% Get the selected row
row = this.Dialog.IOPanel.IOTable.getSelectedRow+1;
 
if row > 0
    this.IOData(row) = [];
    setlinio(this.model,this.IOData);
    this.AnalysisIOTableModelUDD.data = this.getIOTableData;

    %% Create a table model event to update the table
    evt = javax.swing.event.TableModelEvent(this.AnalysisIOTableModelUDD);
    this.AnalysisIOTableModelUDD.fireTableChanged(evt);
    %% Set the project dirty flag
    this.up.Dirty = 1;
else
    str = sprintf('Please select a linearization point.');
    warndlg(str,'Simulink Control Design')
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LocalRefreshSignalNames - Callback to refresh the signal names
function LocalRefreshSignalNames(es,ed,this)

%% Sync the signal names
table_data = this.getIOTableData;
this.AnalysisIOTableModelUDD.data = table_data;

%% Create the cell attributes
import com.mathworks.toolbox.slcontrol.AdvTableObjects.*;
cellAtt = DefaultCellAttribute(size(table_data,1),6);
this.AnalysisIOTableModelUDD.cellAtt = cellAtt;

%% Create a table model event to update the table
evt = javax.swing.event.TableModelEvent(this.AnalysisIOTableModelUDD);
this.AnalysisIOTableModelUDD.fireTableChanged(evt);
%% Set the project dirty flag
this.up.Dirty = 1;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LocalLinearizeModelCallback - Callback for the linearize button to 
%% activate the linearization process.
function LocalLinearizeModelCallback(es,ed,this)

%% Call the linearize model method
this.LinearizeModel;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LocalUpdateSetIOTableData - Callback for the updating the IO table data
function LocalUpdateSetIOTableData(es,ed,this)

%% Make sure the model is loaded
if ~isempty(find_system('SearchDepth',0,'CaseSensitive','off','Name',this.model))
    %% Set the IO Table data
    this.setIOTableData(this.AnalysisIOTableModelUDD.data);
end

