www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+xregdatagui/AbstractListView.m
classdef AbstractListView < xregdatagui.AbstractDataView %xregdatagui.abstractlistview class % xregdatagui.AbstractListView extends xregdatagui.abstractdataview. % % xregdatagui.AbstractListView properties: % Parent - Property is of type 'MATLAB array' % Position - Property is of type 'rect' % Enable - Property is of type 'on/off' % Visible - Property is of type 'on/off' % Userdata - Property is of type 'MATLAB array' % Tag - Property is of type 'string' % MessageService - Property is of type 'handle' (read only) % Container - Property is of type 'handle' % UIContextMenu - Property is of type 'MATLAB array' % Listeners - Property is of type 'handle vector' (read only) % ListHandle - Property is of type 'MATLAB array' (read only) % COMListeners - Property is of type 'handle vector' (read only) % ContainerListeners - Property is of type 'handle vector' (read only) % Strings - Property is of type 'MATLAB array' % Widths - Property is of type 'MATLAB array' % % xregdatagui.AbstractListView methods: % disableCOMListeners - disable listeners for table % enableCOMListeners - enable listeners for table % pCreateListview - function to create listviews for derived classes % pGetListviewIndex - gets the currently selected index from the listview % pdmsDataTypeChangedUpdate - event handler for the dmsDataTypeChanged event % preferredSplitDirection - A short description of the function % Copyright 2015-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (AbortSet, SetObservable) %STRINGS Property is of type 'MATLAB array' Strings; %WIDTHS Property is of type 'MATLAB array' Widths = zeros(1,0); %Type expression type Type end properties (SetAccess=protected, AbortSet) %LISTHANDLE Property is of type 'MATLAB array' (read only) ListHandle = []; end properties (SetAccess=protected, AbortSet) %COMLISTENERS Property is of type 'handle vector' (read only) COMListeners = []; %CONTAINERLISTENERS Property is of type 'handle vector' (read only) ContainerListeners = []; end methods % constructor block function obj = AbstractListView(varargin) %ABSTRACTLISTVIEW constructor % OUT = ABSTRACTLISTVIEW(IN) % Call the inherited constructor obj@xregdatagui.AbstractDataView(varargin{ : }); % converted super class constructor call % Construct the display obj.pCreateListview; end % abstractlistview end % constructor block methods function set.Strings(obj,s) obj.Strings = s; pSetStrings(obj) end function set.Widths(obj,w) obj.Widths = w; pSetWidths(obj) end end % set and get functions methods % public methods %---------------------------------------- function disableCOMListeners(obj) %DISABLECOMLISTENERS disable listeners for table % disableCOMListeners(obj) if ~isempty(obj.COMListeners) set(obj.COMListeners, 'enable', 'off'); end end % disableCOMListeners %---------------------------------------- function enableCOMListeners(obj) %ENABLECOMLISTENERS enable listeners for table % enableCOMListeners(obj) if ~isempty(obj.COMListeners) set(obj.COMListeners, 'enable', 'on'); end end % enableCOMListeners %---------------------------------------- function pCreateListview(obj) %PCREATELISTVIEW function to create listviews for derived classes % PCREATELISTVIEW(OBJ) control = mbcwidgets.List('Parent',obj.Parent,... 'IconTransparentColor',[0 255 0],... 'IconLocation',xregrespath,... 'UIContextMenu',obj.UIContextMenu,... 'Editable',true,... 'SelectionMode','MultiRow'); control.Peer.setColumnData(obj.Strings); control.Peer.setColumnWidths(obj.Widths); control.Peer.setEditableColumns(0); obj.ListHandle = control; obj.ContentHandle = control; createActions(obj) end % pCreateListview function updateListview(obj,~,~) %updateListview update listview [Data,OK] = getDisplayData(obj); Icons(1:length(OK),1) = {'ticksmall.bmp'}; Icons(~OK) = {'errorsmall.bmp'}; obj.ListHandle.setData(Data,Icons); end %---------------------------------------- function pUpdateDisplay(obj) %PUPDATEDISPLAY complete update of the view display % PUPDATEDISPLAY(OBJ) if hasData(obj.MessageService) % Simulate a data type changed update obj.pdmsDataTypeChangedUpdate; % Check the class of the current data object if obj.MessageService.isaSSF obj.updateListview; end end end % pUpdateDisplay function createActions(obj) %createActions create actions for list obj.Options.Actions = [mbcgui.actions.StatefulAction(@obj.onEditAction,'&Edit...','Edit',[]); mbcgui.actions.StatefulAction(@obj.onAddAction,'&Add...','Add',[]); mbcgui.actions.StatefulAction(@obj.onRemoveAction,'&Delete...','Delete',[])]; obj.COMListeners = [handle.listener(obj.ListHandle,'ActionPerformed',@obj.onActionPerformed) handle.listener(obj.ListHandle,'KeyTyped',@obj.onKeyTyped) handle.listener(obj.ListHandle,'ValueChanged',@obj.onEditListview)]; % view needs its own context menu as it is not part of a MultiView obj.UIContextMenu = uicontextmenu('Parent',ancestor(obj.Parent,'figure')); set(obj.ListHandle,'UIContextMenu',obj.UIContextMenu); createMenuItem(obj.Options,obj.UIContextMenu); end function onEditAction(obj,~,~) %onEditAction exit current expression through action menus index= obj.pGetListviewIndex; if isempty(index) return end editExpressionDialog(obj,index) end function onAddAction(obj,~,~) %onAddAction add a new expression through action menus addExpressionDialog(obj); end function onRemoveAction(obj,~,~) %onAddAction add a new expression through action menus removeExpressionDialog(obj); end function editExpressionDialog(obj,index) %editExpressionDlg edit expression dialog if nargin<2 index= obj.pGetListviewIndex(false); end % Get the current data object ssf = obj.MessageService.SweepsetFilter; % Run the equation editor f = ancestor(obj.Parent,'figure'); [OK, newExpression,out2,out3] = equationEditDlg(ssf,f , 'type', obj.Type, 'index', index); % Did the user click OK if OK && ~isempty(newExpression) % Modify the expression modifyExpression(obj,index, newExpression,out2,out3); end end function addExpressionDialog(obj) %addExpressionDialog add expression dialog ssf = obj.MessageService.SweepsetFilter; fig = ancestor(obj.Parent,'figure'); [OK, ssf] = equationEditDlg(ssf, fig, 'type', obj.Type,'list','on'); % Did the user click OK if OK obj.MessageService.flushEventQueue(ssf); end end function removeExpressionDialog(obj,index) %removeExpressionDialog check whether user wants to delete item if nargin<2 % get items to select (maybe more than one) index= obj.pGetListviewIndex(true); end if isempty(index) return end Data = obj.ListHandle.Data; List = strjoin( Data(index,1)',' , '); resp = questdlg(sprintf('Do you want to delete %s',List),'Delete expressions','Yes','No','Yes'); if strcmp(resp,'Yes') removeExpression(obj,index); end end function onEditListview(obj,~, evt) %onEditListview edit expression from listview % is overloading for sweepnotes % Get the currently selected item index = evt.data.Rows; if ~isempty(index) && ~isempty(evt.data.NewValue) modifyExpression(obj, index, evt.data.NewValue); end end % onEditListview % ------------------------------------------------------------------------------ function onActionPerformed(obj,~, evt) %onActionPerformed Double click listview items to edit in a dialog % Get the currently selected item index = evt.data.SelectedRows; % Could anything have been clicked? if isempty(index) || ~obj.Options.Actions(2).Enabled return end editExpressionDialog(obj,index); end % onActionPerformed % ------------------------------------------------------------------------------ function onKeyTyped(obj,~, evt) %onKeyTyped Keys pressed in the listview % % DELETE - to delete a filter % INSERT - to insert a new filter if ~evt.data.Modifiers % Get the current data object % Which key was pressed switch evt.data.KeyCode case mbcgui.util.KeyCode.DELETE % Get the currently selected items index = evt.data.Rows; if ~isempty(index) % Remove them removeExpressionDialog(obj, index); end case mbcgui.util.KeyCode.INSERT if obj.Options.Actions(1).Enabled % Get the current data object addExpressionDialog(obj); end end end end % onKeyUp %---------------------------------------- function index = pGetListviewIndex(obj, multiSelect) %PGETLISTVIEWINDEX gets the currently selected index from the listview % OUT = PGETLISTVIEWINDEX(IN) Listbox = obj.ListHandle; if nargin < 2 multiSelect = false; end index = Listbox.getSelectedRows; if length(index) > 1 && ~multiSelect index = index(1); end end % pGetListviewIndex %---------------------------------------- function pdmsDataTypeChangedUpdate(obj, ~,~) %PDMSDATATYPECHANGEDUPDATE event handler for the dmsDataTypeChanged event % PDMSDATATYPECHANGEDUPDATE(OBJ, src, EVENT) % Find the ssfFiltersChanged listener ssfListeners = obj.MessageService.findListeners(obj.Listeners, 'SweepsetFilter'); % What sort of data and is it read-only? NOT_AN_SSF = ~obj.MessageService.IsaSSF; IS_READ_ONLY = obj.MessageService.IsReadOnly; % If the dataObject isn't a sweepsetfilter then... if NOT_AN_SSF % Clear the view obj.ListHandle.Peer.setData([]); % Turn off the sweepsetfilter listener [ssfListeners.Enabled]=deal(false); else % Turn on the sweepsetfilter listener [ssfListeners.Enabled]=deal(true); end % If the dataObject isn't a sweepsetfilter or it is read only if NOT_AN_SSF || IS_READ_ONLY obj.Options.Enabled = false; % Turn off all the COM Listeners obj.disableCOMListeners; % Turn off the label editing obj.ListHandle.Editable= false; else obj.Options.Enabled = true; % Turn on all the COM Listeners obj.enableCOMListeners; % Turn on the label editing obj.ListHandle.Editable= true; end end % pdmsDataTypeChangedUpdate end % public methods methods (Hidden) % possibly private or hidden %---------------------------------------- function pPostSetDmsIsReadOnly(obj, ~,~) %PPOSTSETDMSISREADONLY data set to read-only % PPOSTSETDMSISREADONLY(OBJ,SRC, EVENT) if obj.MessageService.isReadOnly || ~obj.MessageService.isaSSF % Turn off all the COM Listeners for Read-Only or non-ssf data obj.Options.Enabled = false; obj.disableCOMListeners; % Turn off the label editing obj.ListHandle.Editable = false; else obj.Options.Enabled = true; % Turn on all the COM Listeners obj.enableCOMListeners; % Turn on the label editing obj.ListHandle.Editable = true; end end % pPostSetDmsIsReadOnly function pSetStrings(obj) %pSetStrings set strings in listview numCols = length(obj.Strings); numWidths = length(obj.Widths); if ~isempty(obj.ListHandle) obj.ListHandle.Peer.setColumnData(obj.Strings); end if numCols>numWidths && ~isempty(obj.Widths) obj.Widths(end+1:numCols+1)=obj.Widths(end); pSetWidths(obj) elseif numCols<numWidths obj.Widths(numCols+1:end)=[]; pSetWidths(obj) end end % i_postSetStrings %------------------------------------------------------------------------ function pSetWidths(obj) %pSetWidths set widths in listview if ~isempty(obj.ListHandle) obj.ListHandle.Peer.setColumnWidths(obj.Widths); end end % i_postSetWidths end % possibly private or hidden methods (Abstract) %specific expression implementations must be defined in subclasses [Data,OK] = getDisplayData(obj); removeExpression(obj,index) modifyExpression(obj,index,newExpression,newUnits,newColor) end end % classdef