Search in sources :

Example 1 with TableView

use of com.servoy.j2db.smart.TableView 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;
}
Also used : Function(org.mozilla.javascript.Function) Wrapper(org.mozilla.javascript.Wrapper) ListView(com.servoy.j2db.smart.ListView) JComponent(javax.swing.JComponent) PortalComponent(com.servoy.j2db.smart.dataui.PortalComponent) NativeJavaObject(org.mozilla.javascript.NativeJavaObject) CellAdapter(com.servoy.j2db.smart.dataui.CellAdapter) TwoNativeJavaMethod(com.servoy.j2db.scripting.TwoNativeJavaMethod) TableView(com.servoy.j2db.smart.TableView)

Example 2 with TableView

use of com.servoy.j2db.smart.TableView 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();
}
Also used : Wrapper(org.mozilla.javascript.Wrapper) ListView(com.servoy.j2db.smart.ListView) JComponent(javax.swing.JComponent) PortalComponent(com.servoy.j2db.smart.dataui.PortalComponent) CellAdapter(com.servoy.j2db.smart.dataui.CellAdapter) TableCellEditor(javax.swing.table.TableCellEditor) JComponent(javax.swing.JComponent) Component(java.awt.Component) PortalComponent(com.servoy.j2db.smart.dataui.PortalComponent) TableModel(javax.swing.table.TableModel) TableView(com.servoy.j2db.smart.TableView)

Aggregations

ListView (com.servoy.j2db.smart.ListView)2 TableView (com.servoy.j2db.smart.TableView)2 CellAdapter (com.servoy.j2db.smart.dataui.CellAdapter)2 PortalComponent (com.servoy.j2db.smart.dataui.PortalComponent)2 JComponent (javax.swing.JComponent)2 Wrapper (org.mozilla.javascript.Wrapper)2 TwoNativeJavaMethod (com.servoy.j2db.scripting.TwoNativeJavaMethod)1 Component (java.awt.Component)1 TableCellEditor (javax.swing.table.TableCellEditor)1 TableModel (javax.swing.table.TableModel)1 Function (org.mozilla.javascript.Function)1 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)1