Search in sources :

Example 6 with CellAdapter

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;
}
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 7 with CellAdapter

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();
}
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

CellAdapter (com.servoy.j2db.smart.dataui.CellAdapter)7 Component (java.awt.Component)6 JComponent (javax.swing.JComponent)6 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)4 IComponent (com.servoy.j2db.ui.IComponent)4 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)4 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)4 JTextComponent (javax.swing.text.JTextComponent)4 Point (java.awt.Point)3 ListView (com.servoy.j2db.smart.ListView)2 TableView (com.servoy.j2db.smart.TableView)2 PortalComponent (com.servoy.j2db.smart.dataui.PortalComponent)2 EventObject (java.util.EventObject)2 TableColumn (javax.swing.table.TableColumn)2 Wrapper (org.mozilla.javascript.Wrapper)2 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)1 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)1 FixedJTable (com.servoy.j2db.gui.FixedJTable)1 ITable (com.servoy.j2db.persistence.ITable)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1