waiting for current folder viewer to expand
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm writing some code to expand the current folder viewer and I've found that expanding the folders, equivalent to clicking on the plus buttons, is a non-blocking call. The children of the folder are not valid until the folder has expanded. I'd like to put in some call that waits until the expansion is done but I'm not exactly sure how to proceed. Below is some code that will create a testing folder structure. The second part of code makes the expansion requests and indicates the failure point.
%create lots of folders in a folder called 'test_root' in the current directory
root = cd;
mkdir(cd,'test_root')
cd test_root
for i = 1:50
root2 = cd;
name = sprintf('test%d',i);
mkdir(cd,name);
cd(name)
for j = 1:20
root3 = cd;
name = sprintf('test%d',j);
mkdir(cd,name);
cd(name)
for k = 1:5
root4 = cd;
name = sprintf('test%d',k);
mkdir(cd,name);
end
cd(root3)
end
cd(root2)
end
cd(root)
cd test_root
%-------------------------------------------------------
%Now for expansion testing
h = com.mathworks.mde.explorer.Explorer.getInstance;
table = h.getTable;
table.collapseAll;
pause(1)
r = table.getRowAt(0);
%n1 will be at 1 for non-expanded folders
n1 = r.getChildrenCount;
r.setExpanded(true);
%'x' says true, even though r2 will be null
%suggests that the property value does not wait until expansion finishes
x = r.isExpanded;
%Setting the pause value longer allows the expansion to occur
%and for r2 to be valid
pause(0.001);
%r2 = [] if we ask for it before rendering has completed
%I'm not sure if r2 is valid after the first folder has been rendered, or if all folders need to be rendered before r2 is valid
%in the latter case r2 could be used to signal that expansion is done
r2 = r.getChildAt(1);
%If we go too quickly, n2 will still be at 1
n2 = r.getChildrenCount;
I can probably put together a hack based on getting the directory listing (e.g. dir) and waiting until the # of children equals the returned value, but I was hoping someone with more Java experience might have some insight into how to look for events that would notify the user that rendering has completed (or even better, if someone has actually has knowledge of this interface and could comment accordingly).
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!