use of com.servoy.j2db.smart.dataui.CellAdapter in project servoy-client by Servoy.
the class TwoNativeJavaObject method get.
/*
* (non-Javadoc)
*
* @see org.mozilla.javascript.NativeJavaObject#get(java.lang.String, org.mozilla.javascript.Scriptable)
*/
@Override
public Object get(String name, Scriptable start) {
Object returnObject = null;
try {
returnObject = super.get(name, start);
} finally {
if (returnObject instanceof Function) {
// $NON-NLS-1$
if ("replaceSelectedText".equals(name))
return returnObject;
if (// $NON-NLS-1$
!"requestFocus".equals(name)) {
executingFunction = name;
TwoNativeJavaMethod methodWrapper = (TwoNativeJavaMethod) methodWrappers.get(returnObject);
if (methodWrapper == null) {
methodWrapper = new TwoNativeJavaMethod(javaObject2, (Function) returnObject, listView);
methodWrappers.put(returnObject, methodWrapper);
}
returnObject = methodWrapper;
} else {
final JComponent uiComponent = (JComponent) ((javaObject instanceof Wrapper) ? ((Wrapper) javaObject).unwrap() : javaObject);
if (listView instanceof TableView) {
final TableView tv = (TableView) listView;
tv.requestFocus();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final int selectedRow = tv.getSelectedRow();
for (int i = 0; i < tv.getColumnCount(); i++) {
if (((CellAdapter) tv.getCellEditor(selectedRow, i)).getEditor() == uiComponent) {
final int currentColumn = i;
tv.setColumnSelectionInterval(currentColumn, currentColumn);
tv.editCellAt(selectedRow, currentColumn);
break;
}
}
}
});
} else if (listView instanceof ListView) {
if (listView.isEnabled()) {
// if list is not enabled, all controls are disabled or readonly, no sense to start edit and request focus
// also when clicking and disabled we don't do anything
((ListView) listView).editCellAt((((ListView) listView).getSelectedIndex()));
uiComponent.requestFocus();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (!((ListView) listView).isEditing())
((ListView) listView).editCellAt((((ListView) listView).getSelectedIndex()));
}
});
}
} else if (listView instanceof PortalComponent) {
((PortalComponent) listView).editCellFor(uiComponent);
}
}
} else {
javaObject2.get(name, start);
}
}
return returnObject;
}
use of com.servoy.j2db.smart.dataui.CellAdapter in project servoy-client by Servoy.
the class TwoNativeJavaObject method unwrap.
@Override
public Object unwrap() {
// else debugger can block. If scripts will get its own thread this has to be invokeLater()
if (SwingUtilities.isEventDispatchThread()) {
// state. For example popupmenu tries to show an popup on the components location.
if (// $NON-NLS-1$ //$NON-NLS-2$
executingFunction == null || executingFunction.startsWith("getLocation") || executingFunction.startsWith("getWidth")) {
final JComponent uiComponent = (JComponent) ((javaObject instanceof Wrapper) ? ((Wrapper) javaObject).unwrap() : javaObject);
if (listView instanceof TableView) {
TableView tv = (TableView) listView;
TableCellEditor cellEditor = tv.getCellEditor();
if (!(cellEditor instanceof CellAdapter && ((CellAdapter) cellEditor).getEditor() == uiComponent)) {
int selectedRow = tv.getSelectedRow();
for (int i = 0; i < tv.getColumnCount(); i++) {
if (((CellAdapter) tv.getCellEditor(selectedRow, i)).getEditor() == uiComponent) {
TableModel tm = tv.getModel();
if (tm != null && tm.getRowCount() > 0) {
if (tv.isCellEditable(selectedRow, i)) {
tv.setColumnSelectionInterval(i, i);
tv.editCellAt(selectedRow, i);
} else {
// bounds can be modified even if readonly when moving columns
((Component) uiComponent).setBounds(tv.getCellRect(selectedRow, i, false));
}
}
break;
}
}
}
} else if (listView instanceof ListView) {
((ListView) listView).editCellAt((((ListView) listView).getSelectedIndex()));
} else if (listView instanceof PortalComponent) {
((PortalComponent) listView).editCellFor(uiComponent);
}
} else
executingFunction = null;
}
return super.unwrap();
}
Aggregations