@@ -171,6 +171,50 @@ function fontWeight(uiElement, weight)
171
171
% "Clear" the temporary JS variable
172
172
win .executeJS(' W = undefined' );
173
173
end % getParentNodeID
174
+
175
+ function [ID_obj ] = getTableCellID(hTable , r , c )
176
+ % This method returns one or more ID objects, corresponding to specific cells in a
177
+ % uitable, as defined by the cells' row and column indices.
178
+ %% Constants:
179
+ TABLE_CLASS_NAME = ' matlab.ui.control.Table' ;
180
+ CELL_ID_PREFIX = {' variableeditor_views_editors_UITableEditor_' };
181
+ %% Input tests:
182
+ assert( isa(hTable , TABLE_CLASS_NAME ) && ishandle(hTable ), ' Invalid uitable handle!' );
183
+ nR = numel(r ); nC = numel(c );
184
+ assert( nR == nC , ' The number of elements in r and c must be the same!' );
185
+ sz = size(hTable .Data );
186
+ assert( all(r <= sz(1 )), ' One or more requested rows are out-of-bounds!' );
187
+ assert( all(c <= sz(2 )), ' One or more requested columns are out-of-bounds!' );
188
+ %% Computing the offset
189
+ % If there's more than one uitable in the figure, IDs are assigned
190
+ % consecutively. For example, in the case of a 3x3 and 4x4 arrays,
191
+ % where the smaller table was created first, IDs will assigned as follows:
192
+ %
193
+ % [ 0 1 2 [ 9 10 11 12
194
+ % 3 4 5 13 14 15 16
195
+ % 6 7 8] 17 18 19 20
196
+ % 21 22 23 24]
197
+ %
198
+ % ... which is why if want to change the 2nd table we need to offset the
199
+ % IDs by the total amount of elements in all preceding arrays, which is 9.
200
+ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201
+ % Get siblings (flipping to negate that newer children appear first)
202
+ hC = flip(hTable .Parent .Children );
203
+ % Find which of them is a table:
204
+ hC = hC( arrayfun(@(x )isa(x , TABLE_CLASS_NAME ), hC ) );
205
+ % Find the position of the current table in the list, and count the elements of
206
+ % all preceding tables:
207
+ offset = sum(arrayfun(@(x )numel(x .Data ), hC(1 : find(hC == hTable )-1 )));
208
+ % Compute indices, r and c are reversed due to row-major ordering of the IDs
209
+ idx = sub2ind(sz , c , r ) + offset - 1 ; % -1 because JS IDs are 0-based
210
+ idc = strcat(CELL_ID_PREFIX , num2str(idx(: )));
211
+ % Preallocation:
212
+ ID_obj(nR ,1 ) = WidgetID ;
213
+ % ID array population:
214
+ for indI = 1 : numel(idx )
215
+ ID_obj(indI ) = WidgetID(mlapptools .DEF_ID_ATTRIBUTE , idc{indI } );
216
+ end
217
+ end % getTableCellID
174
218
175
219
function [win , widgetID ] = getWebElements(uiElement )
176
220
% A method for obtaining the webwindow handle and the widget ID corresponding
@@ -488,7 +532,7 @@ function unlockUIFig(hUIFig)
488
532
ww = arrayfun(@mlapptools .getWebWindow , hUIFigs );
489
533
warning(warnState ); % Restore warning state
490
534
hFig = hFigs(hWebwindow == ww );
491
- end % figFromWebwindow
535
+ end % figFromWebwindow
492
536
493
537
function [ID_obj ] = getWidgetID(win , data_tag )
494
538
% This method returns a structure containing some uniquely-identifying information
@@ -667,6 +711,12 @@ function waitTillWebwindowLoaded(hWebwindow, hFig)
667
711
hWebwindow .executeJS(' require(["dojo/ready"], function(ready){});' );
668
712
end
669
713
end % waitTillWebwindowLoaded
714
+
715
+ function htmlRootPath = getFullPathFromWW(win )
716
+ % Get a local href value, e.g. from an included main.css
717
+ href = win .executeJS(' document.body.getElementsByTagName("link")[0].href' );
718
+ htmlRootPath = win .executeJS([' var link = document.createElement("a"); link.href = ' href ' ;' ]);
719
+ end
670
720
671
721
end % Private Static Methods
672
722
0 commit comments