www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/+cgtools/AbstractFilteredProjectView.m

    classdef AbstractFilteredProjectView < mbcgui.widget.BasicContainer
    %cgtools.AbstractFilteredProjectView class
    %   cgtools.AbstractFilteredProjectView extends mbcgui.widget.BasicContainer.
    %
    %    cgtools.AbstractFilteredProjectView 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'
    %       UIContextMenu - Property is of type 'MATLAB array'
    %       Project - Property is of type 'MATLAB array'
    %       Items - Property is of type 'MATLAB array'
    %       Names - Property is of type 'MATLAB array' (read only)
    %       Types - Property is of type 'MATLAB array' (read only)
    %       Icons - Property is of type 'MATLAB array' (read only)
    %       List - Property is of type 'handle' (read only)
    %       Filter - Property is of type 'handle' (read only)
    %       CurrentProjectLabel - Property is of type 'handle' (read only)
    %
    %    cgtools.AbstractFilteredProjectView methods:
    %       clearFilter - Reset the item filter.
    %       selectRows - select rows in filtered list
    
    %  Copyright 2005-2016 The MathWorks, Inc.
    
    properties (Dependent,SetObservable)
        %PROJECT Property is of type 'MATLAB array'
        Project = []; 
    end
    
    properties (AbortSet, SetObservable)
        %UICONTEXTMENU Property is of type 'MATLAB array'
        UIContextMenu = [];
        %ITEMS Property is of type 'MATLAB array'
        Items = [];
    end
    
    properties (SetAccess=protected, AbortSet, SetObservable)
        %NAMES Property is of type 'MATLAB array' (read only)
        Names = [];
        %TYPES Property is of type 'MATLAB array' (read only)
        Types = [];
        %ICONS Property is of type 'MATLAB array' (read only)
        Icons = [];
        %LIST Property is of type 'handle' (read only)
        List = [];
        %FILTER Property is of type 'handle' (read only)
        Filter = [];
        %CURRENTPROJECTLABEL Property is of type 'handle' (read only)
        CurrentProjectLabel = [];
    end
    
    properties (Access=private)
        %pProject storage for project dependent property
        pProject = [];
     end
    
    events (NotifyAccess=protected)
        SelectedItemsChanged
    end  % events
    
    methods  % constructor block
        function obj = AbstractFilteredProjectView( varargin )
        %ABSTRACTFILTEREDPROJECTVIEW  Class constructor
        
        % Call the inherited constructor
        obj@mbcgui.widget.BasicContainer(varargin{ : }); % converted super class constructor call
        
        toppanel = mbcgui.container.layoutpanel(...
            'Parent', obj.Parent, ...
            'Visible', obj.Visible, ...
            'BorderType', 'beveledout');
        
        projectname = uicontrol( 'Parent', toppanel,...
            'Style', 'text',...
            'HorizontalAlignment', 'left',...
            'String', '' );
        obj.CurrentProjectLabel = xregGui.labelcontrol( 'Parent', toppanel,...
            'String', 'Current project: ',...
            'Enable', 'off',...
            'ControlSizeMode', 'relative',...
            'LabelSizeMode', 'absolute',...
            'LabelSize', 100,...
            'ControlSize', 1,...
            'Control', projectname );
        
        obj.Filter = mbcwidgets.itemfilter( 'Parent', toppanel,...
            'AllTypes', obj.pGetAllTypes );
        toplayout = xreggridbaglayout( toppanel,...
            'Border', [10 0 0 10],...
            'Gapy', 10,...
            'Dimension', [2 2],...
            'ColSizes', [600 -1],...
            'RowSizes', [25 80],...
            'MergeBlocks', {[2 2], [1 2]},...
            'Elements', {obj.CurrentProjectLabel, []; obj.Filter, []} );
        set(toppanel, 'LayoutComponent', {toplayout});
        
        obj.addListeners( handle.listener(obj.Filter, 'FilterChanged', {@updatelist, obj}) );
        
        obj.List = mbcwidgets.Table1D( 'list',...
            'Parent', obj.Parent,...
            'UIContextMenu', obj.UIContextMenu,...
            'SelectionMode', 'MultiRow',...
            'ColumnWidth', 200,...
            'SelectionChangedCallback', {@listselectionchanged, obj});
        obj.List.Peer.setColumnData( obj.pGetColumnData() );
        obj.List.Peer.setBorder( [] );
        
        obj.ContentHandle = xreggridbaglayout( obj.Parent,...
            'Border', [0 0 0 0],...
            'Dimension', [2 1],...
            'RowSizes', [90 -1],...
            'Elements', {toppanel; obj.List} );
        
        obj.pUpdate();
        end  % abstractfilteredprojectview
        
    end  % constructor block
    
    methods
        function set.Project(obj,proj)
        
        obj.pProject = proj;
        if isempty( proj )
            set( obj.CurrentProjectLabel.Control, 'String', '' );
            set( obj.CurrentProjectLabel, 'Enable', 'off' );
            setEnable( obj.Filter, 'off' );
        else
            set( obj.CurrentProjectLabel.Control, 'String', proj.projectfile );
            set( obj.CurrentProjectLabel, 'Enable', 'on' );
            setEnable( obj.Filter, 'on' );
        end
        obj.pUpdate();
        end  % projectchanged
        
        
        function proj = get.Project(obj)
        proj = obj.pProject;
        end
    end

    methods (Abstract,Access=protected)
        alltypes = pGetAllTypes(obj)
        colnames = pGetColumnData(obj)
        [pItems, names, icons, typestr] = pGetItemsByType(obj, typestr )
    end
    
    methods  % public methods
        %----------------------------------------
        function clearFilter(obj)
        %CLEARFILTER Reset the item filter.
        %   CLEARFILTER(OBJ)
        
        obj.Filter.clear();
        
        end  % clearFilter
        
        %----------------------------------------
        function selectRows(obj,rows)
        %selectRows select rows in filtered list
        %   selectRows(obj,rows)
        
        selectRows(obj.List,rows);
        pSendSelectedItemsChangedEvent(obj,rows)
        
        end  % selectRows
    end
    
    methods (Access=protected)

        %----------------------------------------
        function pSendSelectedItemsChangedEvent(obj,selectedrows)
        %PSENDSELECTEDITEMSCHANGEDEVENT A short description of the function.
        %   PSENDSELECTEDITEMSCHANGEDEVENT(OBJ, ROWINDICES)
        
        data.NumberSelectedItems = length(selectedrows);
        data.Selected.Items = obj.Items( selectedrows );
        data.Selected.Items = obj.Items( selectedrows );
        data.Selected.Names = obj.Names( selectedrows );
        data.Selected.Types = obj.Types( selectedrows );
        data.Selected.Icons = obj.Icons( selectedrows );
        
        evtData = xregEventData(data);
        notify( obj, 'SelectedItemsChanged', evtData )
        
        end  % pSendSelectedItemsChangedEvent
        
        %----------------------------------------
        function pUpdate(obj)
        %PUPDATE Refresh the view.
        %   PUPDATE(OBJ)
        
        [pItems, names, icons, typestrs, otherinfo] = obj.pGetItemsByType( get( obj.Filter, 'SelectedType' ) );
        
        if obj.Filter.MatchCase
            matchfunction = @regexp;
        else
            matchfunction = @regexpi;
        end
        
        % now apply the filter expression.
        if ~isempty( obj.Filter.FilterString )
            idx = ~cellfun( @isempty, matchfunction( names, obj.Filter.FilterString, 'once' ) );
            pItems  = pItems( idx );
            names   = names( idx );
            icons   = icons( idx );
            typestrs = typestrs( idx );
            otherinfo = otherinfo( idx );
        end
        
        % store the items we are showing.
        obj.Items = pItems;
        obj.Names = names;
        obj.Types = typestrs;
        obj.Icons = icons;
        
        % update the list with the new data
        values = cell( length( names ), 2 );
        for n = 1:length( names )
            values{n,1} = names{n};
            values{n,2} = typestrs{n};
            values{n,3} = otherinfo{n};
        end
        obj.List.Peer.setData(values, icons) ;
        obj.List.Peer.clearSelection();
        obj.pSendSelectedItemsChangedEvent( [] );
        
        end  % pUpdate
        
    end  % public methods
    
end  % classdef

function updatelist( ~, ~, obj )
obj.pUpdate();
end  % updatelist


function listselectionchanged( ~, evt, obj )
obj.pSendSelectedItemsChangedEvent( evt.data.SelectedDataRows );
end  % listselectionchanged