function updatestateorder(this,oppoint)
% updatestateorder - Updates the state order used for linearizations if the
% user does a linearization.

%  Author(s): John Glass
%  Revised:
% Copyright 1986-2004 The MathWorks, Inc.
% $Revision: 1.1.6.1 $ $Date: 2004/08/01 00:12:03 $

%% Set the state ordering cell array
StateOrderList = cell(length(oppoint.States),1);
for ct = 1:length(oppoint.States)
    if isa(oppoint.States(ct),'opcond.StatePointSimMech')
        StateOrderList{ct} = oppoint.States(ct).SimMechBlock;
    else
        StateOrderList{ct} = oppoint.States(ct).Block;
    end
end

%% Sort the state order
OldStateOrderList = this.StateOrderList;

%% Loop over the state objects
ind = [];indState = [1:length(StateOrderList)]';
for ct = 1:length(OldStateOrderList)
    stateind = find(strcmp(OldStateOrderList(ct),StateOrderList));
    indState(stateind) = 0;
    ind = [ind;stateind];
end

%% Write the state order list back to the operating point task
OldStates = StateOrderList(ind);
NewStates = StateOrderList(find(indState ~= 0));
this.StateOrderList = [OldStates;NewStates];

%% Get the handle to the options dialog if it has to be updated.
dlg = jDialogs.LinOptionsDialog(this);
dlg.SyncStateOrder(this.StateOrderList);