Search in sources :

Example 1 with ListView

use of com.servoy.j2db.smart.ListView in project servoy-client by Servoy.

the class CellAdapter method testCalc.

private boolean testCalc(final String possibleCalcDataprovider, final IRecordInternal state, final int row, final int column, final ISwingFoundSet foundset) {
    if (state != null && state.getRawData() != null && !(state instanceof PrototypeState || state instanceof FindState) && state.getRawData().containsCalculation(possibleCalcDataprovider) && state.getRawData().mustRecalculate(possibleCalcDataprovider, true)) {
        IApplication app = dal.getApplication();
        convertAndSetValue(((IDisplayData) renderer), state.getRawData().getValue(possibleCalcDataprovider));
        // $NON-NLS-1$
        final String key = row + "_" + possibleCalcDataprovider;
        if (!rowAndDataprovider.contains(key)) {
            rowAndDataprovider.add(key);
            app.getScheduledExecutor().execute(new Runnable() {

                public void run() {
                    state.getValue(possibleCalcDataprovider);
                    application.invokeLater(new Runnable() {

                        public void run() {
                            rowAndDataprovider.remove(key);
                            foundset.fireTableModelEvent(row, row, column, TableModelEvent.UPDATE);
                            Container parent = table.getParent();
                            while (parent != null && !(parent instanceof ListView)) {
                                parent = parent.getParent();
                            }
                            if (parent instanceof ListView) {
                                ((ListView) parent).repaint();
                            }
                        }
                    });
                }
            });
        }
        return true;
    }
    return false;
}
Also used : IApplication(com.servoy.j2db.IApplication) Container(java.awt.Container) FindState(com.servoy.j2db.dataprocessing.FindState) ListView(com.servoy.j2db.smart.ListView) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Example 2 with ListView

use of com.servoy.j2db.smart.ListView 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 3 with ListView

use of com.servoy.j2db.smart.ListView 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)3 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 IApplication (com.servoy.j2db.IApplication)1 FindState (com.servoy.j2db.dataprocessing.FindState)1 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)1 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)1 TwoNativeJavaMethod (com.servoy.j2db.scripting.TwoNativeJavaMethod)1 Component (java.awt.Component)1 Container (java.awt.Container)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