}
Component rootComponent = SwingUtilities.getRoot(component);
// If we are in an ArrayField, then we need to go from there
if (rootComponent == null) {
ArrayField af = ArrayFieldCellHelper.getArrayField(component);
if (af != null) {
rootComponent = SwingUtilities.getRoot(af);
}
}
// If our frame is not visible, then we can't set the focus yet. We just flag our form
// to set the focus once it becomes visible. CraigM: 26/02/2008.
if (rootComponent instanceof JFrame && ((JFrame)rootComponent).isVisible() == false) {
JPanel form = UIutils.getForm((JFrame)rootComponent);
if (form != null) {
form.putClientProperty(QQ_INITIAL_FOCUS_COMPONENT, component);
form.putClientProperty(QQ_INITIAL_FOCUS_ROW, row);
return;
}
}
// TF:10/7/07: Added in the application traversal type for the Forte-style focus manager
// Since this pending action only ever occurs as the result of the application requesting
// the focus to change, we set a flag to indicate that this is the case.
ForteKeyboardFocusManager.setApplicationTraversal();
// TF:11/03/2009:DET-82:In forte, you could try to focus on an array field, and either provide a row
// in which case the focus would go to the first row or the row'th row if specified.
if (component instanceof JComponent) {
ArrayField af;
if (component instanceof ArrayField) {
af = (ArrayField)component;
// Now set the component to the first visible column on the designated row
component = ArrayFieldCellHelper.getArrayEditorComponent(af, row, 0);
if (component == null) {
// We cannot find the first visible component, do nothing
return;
}
}
else {
af = ArrayFieldCellHelper.getArrayField(component);
}
if (af != null) {
int col = ArrayFieldCellHelper.getArrayFieldColumn((JComponent)component);
//PM:23/11/07 correct for invisible columns
ArrayColumn ac = (ArrayColumn)((ArrayColumnModel)af.getColumnModel()).getRealColumn(col);
col = ((ArrayColumnModel)af.getColumnModel()).getColumnIndex(ac.getIdentifier());
// If an explicit focus request occurs on an empty array field that allows append, then create
// a new row (that's what Forte did). CraigM 16/10/2007.
if (af.getRowCount() == 0 && af.isAllowsAppend()) {
af.appendRow(col);
}
else if (row >= af.getRowCount()) {
// TF:11/03/2009:A request has been made to focus to a non-existant row, do nothing
return;
}
// CraigM:01/05/2008 - Let all other swing event happen before requesting the focus in here
final ArrayField afFinal = af;
final int colFinal = col;
// CraigM:25/06/2008 - Switched from SwingUtilities.invokeLater
UIutils.invokeOnGuiThread(new Runnable() {
public void run() {
// CraigM:09/07/2008 - Now ArrayField has been fixed, we can just change the selection
afFinal.changeSelection(row, colFinal, false, false);
}
});
} else {
// TF:27/11/07:(Credit to java almanac...) If we can't set the focus in the window, it's possibly
// because we're not focusable, such as a grid field. In this case we want to set the focus to our