www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/+project/NotesList.m
classdef NotesList < mbcgui.multiview.View %NotesList list of notes/history for project view % Copyright 2015-2016 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (SetAccess=private) %List list of projet notes List end methods function obj = NotesList(varargin) %NotesList constructor obj@mbcgui.multiview.View(varargin{:}); createLayout(obj) addMessageServiceListener(obj, 'NodeUpdated',@obj.onNodeUpdated) end function update(obj) %update update notes list ms = obj.MessageService; historyArray = history(ms.Project); n = length(historyArray); ind = getEditableNoteIndices(ms.Project); lockNodes = ismember(1:n,ind); prfs = getpref(mbcprefs('mbc'),'mdevproject'); colstoshow = prfs.NotesListColumns; Data = cell(n,7); Icon = cell(n,1); for i = 1:length(historyArray) H = historyArray(i); usr = H.User; Data(i,:) = {H.Action, getusername(usr),getcompany(usr),getdepartment(usr),... getcontact(usr),datestr(H.Date,1),datestr(H.Date,16)}; lockNode = ~ismember(i, ind); if lockNode Icon{i} = 'note_lock.bmp'; else Icon{i} = 'note.bmp'; end end cols = {'Note' 'User' 'Company' 'Department' 'Contact Information' 'Date' 'Time'}; widths = [400 100 100 100 100 75 75]; obj.List.ColumnHeaders = cols(colstoshow); obj.List.ColumnWidths = widths(colstoshow); obj.List.Data = Data(:,colstoshow); obj.List.EditableColumns = 1; obj.List.EditableRows = lockNodes(:); obj.List.Icons = Icon; end end methods (Access=private) function createLayout(obj) %createLayout create ui noteList= mbcwidgets.List('Parent',obj.Parent,... 'UserData','noteList',... 'ValueChangedCallback',@obj.onEditName,... 'KeyTypedCallback',@obj.onKeyTyped,... 'Editable',true,... 'EditableColumns',1,... 'IconLocation',xregrespath,... 'Grid',true,... 'IconTransparentColor',[0 255 0],... 'UIContextMenu',[],... 'SelectionMode','SingleRow'); obj.List = noteList; obj.ContentHandle = noteList; end function onNodeUpdated(obj,~,~) %onNodeUpdated MessageService.NodeUpdated event handling update(obj) end function onEditName(obj,~,evt) %onEditName edit notes name ms = obj.MessageService; ind = evt.data.Rows; newNote = evt.data.NewValue; editInd = getEditableNoteIndices(ms.Project); if ismember(ind, editInd) usr = initfromprefs(mbcuser); historyArray = history(ms.Project); historyArray(ind) = struct('User', usr, 'Action', newNote, 'Date', now); history(ms.Project,historyArray); end update(obj) selectRows(obj.List,ind); end function onKeyTyped(obj,~,evt) %onKeyTyped key event in notes ms = obj.MessageService; if evt.data.Modifiers==0 switch evt.data.KeyCode case mbcgui.util.KeyCode.INSERT ms.Actions.NewNote.execute() case mbcgui.util.KeyCode.DELETE if isscalar(evt.data.Rows) historyArray = history(ms.Project); historyArray(evt.data.Rows) = []; history(ms.Project,historyArray); update(obj) end end end end end end