Search in sources :

Example 1 with WebCellBasedViewListViewItem

use of com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.WebCellBasedViewListViewItem in project servoy-client by Servoy.

the class WebCellAdapter method valueChanged.

public void valueChanged(ModificationEvent e) {
    MainPage mp = view.findParent(MainPage.class);
    if (mp != null)
        mp.touch();
    IRecord record = e.getRecord();
    Iterator iterator = ((MarkupContainer) view.getTable()).iterator();
    while (iterator.hasNext()) {
        Object next = iterator.next();
        if (next instanceof ListItem) {
            ListItem li = (ListItem) next;
            Object modelObject = li.getModelObject();
            if (record == null || modelObject == record) {
                boolean hasOnRender = false;
                Iterator iterator2 = li.iterator();
                while (iterator2.hasNext()) {
                    ArrayList<Object> cellDisplays = new ArrayList<Object>();
                    Object cell = iterator2.next();
                    cell = CellContainer.getContentsForCell((Component) cell);
                    if (cell instanceof WebCellBasedViewListViewItem) {
                        Iterator listItemIte = ((WebCellBasedViewListViewItem) cell).iterator();
                        while (listItemIte.hasNext()) {
                            Object listItemDisplay = listItemIte.next();
                            if (listItemDisplay instanceof WrapperContainer) {
                                listItemDisplay = ((WrapperContainer) listItemDisplay).getDelegate();
                            }
                            cellDisplays.add(listItemDisplay);
                        }
                    } else {
                        cellDisplays.add(cell);
                    }
                    for (Object cellDisplay : cellDisplays) {
                        if (cellDisplay instanceof IProviderStylePropertyChanges && cellDisplay instanceof IDisplayData && ((IDisplayData) cellDisplay).getDataProviderID() == dataprovider) {
                            // only test if it is not already changed
                            view.checkForValueChanges(cellDisplay);
                            // do fire on render on all components for record change
                            if (cellDisplay instanceof ISupportOnRender && cellDisplay instanceof IScriptableProvider) {
                                IScriptable so = ((IScriptableProvider) cellDisplay).getScriptObject();
                                if (so instanceof AbstractRuntimeRendersupportComponent && ((ISupportOnRenderCallback) so).getRenderEventExecutor().hasRenderCallback()) {
                                    String componentDataproviderID = ((AbstractRuntimeRendersupportComponent) so).getDataProviderID();
                                    if (record != null || (e.getName() != null && e.getName().equals(componentDataproviderID))) {
                                        ((ISupportOnRender) cellDisplay).fireOnRender(true);
                                        hasOnRender = true;
                                    }
                                }
                            }
                        }
                    }
                }
                if (record != null || (!hasOnRender && !canChangeValue(e)))
                    break;
            }
        }
    }
}
Also used : MarkupContainer(org.apache.wicket.MarkupContainer) ISupportOnRender(com.servoy.j2db.ui.ISupportOnRender) IRecord(com.servoy.j2db.dataprocessing.IRecord) ArrayList(java.util.ArrayList) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) WebCellBasedViewListViewItem(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.WebCellBasedViewListViewItem) IScriptable(com.servoy.j2db.scripting.IScriptable) WrapperContainer(com.servoy.j2db.server.headlessclient.WrapperContainer) Iterator(java.util.Iterator) IProviderStylePropertyChanges(com.servoy.j2db.ui.IProviderStylePropertyChanges) IDisplayData(com.servoy.j2db.dataprocessing.IDisplayData) ListItem(org.apache.wicket.markup.html.list.ListItem) Component(org.apache.wicket.Component) AbstractRuntimeRendersupportComponent(com.servoy.j2db.ui.scripting.AbstractRuntimeRendersupportComponent) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) MainPage(com.servoy.j2db.server.headlessclient.MainPage)

Example 2 with WebCellBasedViewListViewItem

use of com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.WebCellBasedViewListViewItem in project servoy-client by Servoy.

the class WebEventExecutor method setSelectedIndex.

/**
 * @param component
 */
@SuppressWarnings("nls")
public static boolean setSelectedIndex(Component component, AjaxRequestTarget target, int modifiers, boolean bHandleMultiselect) {
    WebForm parentForm = component.findParent(WebForm.class);
    WebCellBasedView tableView = null;
    if (parentForm != null) {
        int parentFormViewType = parentForm.getController().getForm().getView();
        if (parentFormViewType == FormController.TABLE_VIEW || parentFormViewType == FormController.LOCKED_TABLE_VIEW || parentFormViewType == IForm.LIST_VIEW || parentFormViewType == FormController.LOCKED_LIST_VIEW) {
            tableView = component.findParent(WebCellBasedView.class);
            if (tableView == null) {
                // the component is not part of the table view (it is on other form part), so ignore selection change
                return true;
            } else
                tableView.setSelectionMadeByCellAction();
            if (parentFormViewType == IForm.LIST_VIEW || parentFormViewType == FormController.LOCKED_LIST_VIEW) {
                if (component instanceof WebCellBasedViewListViewItem) {
                    ((WebCellBasedViewListViewItem) component).markSelected(target);
                } else {
                    WebCellBasedViewListViewItem listViewItem = component.findParent(WebCellBasedView.WebCellBasedViewListViewItem.class);
                    if (listViewItem != null) {
                        listViewItem.markSelected(target);
                    }
                }
            }
        }
    }
    // search for recordItem model
    Component recordItemModelComponent = component;
    IModel<?> someModel = recordItemModelComponent.getDefaultModel();
    while (!(someModel instanceof RecordItemModel)) {
        recordItemModelComponent = recordItemModelComponent.getParent();
        if (recordItemModelComponent == null)
            break;
        someModel = recordItemModelComponent.getDefaultModel();
    }
    if (someModel instanceof RecordItemModel) {
        if (!(component instanceof WebCellBasedViewListViewItem)) {
            // update the last rendered value for the events component (if updated)
            ((RecordItemModel) someModel).updateRenderedValue(component);
        }
        IRecordInternal rec = (IRecordInternal) someModel.getObject();
        if (rec != null) {
            int index;
            IFoundSetInternal fs = rec.getParentFoundSet();
            if (someModel instanceof FoundsetRecordItemModel) {
                index = ((FoundsetRecordItemModel) someModel).getRowIndex();
            } else {
                // this is used only on "else", because a "plugins.rawSQL.flushAllClientsCache" could result in index = -1 although the record has not changed (but record & underlying row instances changed)
                index = fs.getRecordIndex(rec);
            }
            if (fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect()) {
                // set the selected record
                ClientProperties clp = ((WebClientInfo) Session.get().getClientInfo()).getProperties();
                String navPlatform = clp.getNavigatorPlatform();
                int controlMask = (navPlatform != null && navPlatform.toLowerCase().indexOf("mac") != -1) ? Event.META_MASK : Event.CTRL_MASK;
                boolean toggle = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & controlMask) != 0);
                boolean extend = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & Event.SHIFT_MASK) != 0);
                boolean isRightClick = (modifiers != MODIFIERS_UNSPECIFIED) && ((modifiers & Event.ALT_MASK) != 0);
                if (!isRightClick) {
                    if (!toggle && !extend && tableView != null && tableView.getDragNDropController() != null && Arrays.binarySearch(((FoundSet) fs).getSelectedIndexes(), index) > -1) {
                        return true;
                    }
                    if (toggle || extend) {
                        if (bHandleMultiselect) {
                            if (toggle) {
                                int[] selectedIndexes = ((FoundSet) fs).getSelectedIndexes();
                                ArrayList<Integer> selectedIndexesA = new ArrayList<Integer>();
                                Integer selectedIndex = new Integer(index);
                                for (int selected : selectedIndexes) selectedIndexesA.add(new Integer(selected));
                                if (selectedIndexesA.indexOf(selectedIndex) != -1) {
                                    if (selectedIndexesA.size() > 1) {
                                        ((ISwingFoundSet) fs).getSelectionModel().removeSelectionInterval(selectedIndex, selectedIndex);
                                    }
                                } else {
                                    ((ISwingFoundSet) fs).getSelectionModel().addSelectionInterval(selectedIndex, selectedIndex);
                                }
                            } else if (extend) {
                                int anchor = ((FoundSet) fs).getSelectedIndex();
                                int min = Math.min(anchor, index);
                                int max = Math.max(anchor, index);
                                ((ISwingFoundSet) fs).getSelectionModel().setSelectionInterval(min, max);
                            }
                        }
                    } else if (index != -1 || fs.getSize() == 0) {
                        fs.setSelectedIndex(index);
                    }
                }
            } else if (!isIndexSelected(fs, index))
                fs.setSelectedIndex(index);
            if (!isIndexSelected(fs, index) && !(fs instanceof FoundSet && ((FoundSet) fs).isMultiSelect())) {
                // setSelectedIndex failed, probably due to validation failed, do a blur()
                if (target != null)
                    target.appendJavascript("var toBlur = document.getElementById(\"" + component.getMarkupId() + "\");if (toBlur) toBlur.blur();");
                return false;
            }
        }
    }
    return true;
}
Also used : WebClientInfo(org.apache.wicket.protocol.http.request.WebClientInfo) ClientProperties(org.apache.wicket.protocol.http.ClientProperties) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) ArrayList(java.util.ArrayList) IFoundSet(com.servoy.j2db.dataprocessing.IFoundSet) FoundSet(com.servoy.j2db.dataprocessing.FoundSet) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) WebCellBasedViewListViewItem(com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.WebCellBasedViewListViewItem) Point(java.awt.Point) ISwingFoundSet(com.servoy.j2db.dataprocessing.ISwingFoundSet) IComponent(com.servoy.j2db.ui.IComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) Component(org.apache.wicket.Component) FormComponent(org.apache.wicket.markup.html.form.FormComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Aggregations

WebCellBasedViewListViewItem (com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView.WebCellBasedViewListViewItem)2 ArrayList (java.util.ArrayList)2 Component (org.apache.wicket.Component)2 FoundSet (com.servoy.j2db.dataprocessing.FoundSet)1 IDisplayData (com.servoy.j2db.dataprocessing.IDisplayData)1 IFoundSet (com.servoy.j2db.dataprocessing.IFoundSet)1 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 IRecord (com.servoy.j2db.dataprocessing.IRecord)1 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)1 ISwingFoundSet (com.servoy.j2db.dataprocessing.ISwingFoundSet)1 IScriptable (com.servoy.j2db.scripting.IScriptable)1 IScriptableProvider (com.servoy.j2db.scripting.IScriptableProvider)1 MainPage (com.servoy.j2db.server.headlessclient.MainPage)1 WebForm (com.servoy.j2db.server.headlessclient.WebForm)1 WrapperContainer (com.servoy.j2db.server.headlessclient.WrapperContainer)1 IComponent (com.servoy.j2db.ui.IComponent)1 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)1 IProviderStylePropertyChanges (com.servoy.j2db.ui.IProviderStylePropertyChanges)1 ISupportOnRender (com.servoy.j2db.ui.ISupportOnRender)1 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)1