Search in sources :

Example 1 with AbstractEditListModel

use of com.servoy.j2db.util.editlist.AbstractEditListModel in project servoy-client by Servoy.

the class PortalComponent method setRecord.

public void setRecord(IRecordInternal state, boolean stopEditing) {
    if (stopEditing) {
        stopUIEditing(true);
    }
    IFoundSetInternal relatedFoundSet = state == null ? null : state.getRelatedFoundSet(relationName, getDefaultSort());
    // if is same changes are seen by model listener
    if (currentData == relatedFoundSet)
        return;
    if (currentData != null) {
        currentData.removeTableModelListener(this);
        ListSelectionModel lsm = currentData.getSelectionModel();
        lsm.removeListSelectionListener(this);
    }
    currentData = (ISwingFoundSet) relatedFoundSet;
    ISupportOnRenderCallback portalRenderComponent = null;
    if (table != null) {
        if (currentData == null) {
            // safety
            table.removeEditor();
            table.setSelectionModel(EMPTY_SELECTION);
            table.setModel(EMPTY_DATA);
        } else {
            ListSelectionModel lsm = currentData.getSelectionModel();
            int selected = currentData.getSelectedIndex();
            table.setSelectionModel(lsm);
            table.setModel((IFoundSetInternal) currentData);
            currentData.setSelectedIndex(selected);
            currentData.addTableModelListener(this);
            lsm.addListSelectionListener(this);
            valueChanged(null, stopEditing);
        }
        portalRenderComponent = table.getOnRenderComponent();
    } else {
        if (currentData == null) {
            list.setSelectionModel(EMPTY_SELECTION);
            list.setModel(new AbstractEditListModel() {

                public Object getElementAt(int i) {
                    return null;
                }

                public int getSize() {
                    return 0;
                }
            });
        } else {
            list.setSelectionModel(EMPTY_SELECTION);
            ListSelectionModel lsm = currentData.getSelectionModel();
            list.setModel(currentData);
            list.setSelectionModel(lsm);
            currentData.addTableModelListener(this);
            lsm.addListSelectionListener(this);
            valueChanged(null, stopEditing);
        }
        portalRenderComponent = list.getOnRender();
    }
    scriptable.setFoundset(currentData);
    if (currentData != null && portalRenderComponent != null && portalRenderComponent.getRenderEventExecutor().hasRenderCallback()) {
        portalRenderComponent.getRenderEventExecutor().setRenderState(null, -1, false, true);
        portalRenderComponent.getRenderEventExecutor().fireOnRender(false);
    }
}
Also used : IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) AbstractEditListModel(com.servoy.j2db.util.editlist.AbstractEditListModel) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) ListSelectionModel(javax.swing.ListSelectionModel) ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback)

Aggregations

IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)1 ISupportOnRenderCallback (com.servoy.j2db.ui.ISupportOnRenderCallback)1 AbstractEditListModel (com.servoy.j2db.util.editlist.AbstractEditListModel)1 DefaultListSelectionModel (javax.swing.DefaultListSelectionModel)1 ListSelectionModel (javax.swing.ListSelectionModel)1