Search in sources :

Example 1 with IDataRenderer

use of com.servoy.j2db.ui.IDataRenderer in project servoy-client by Servoy.

the class FormController method recreateUI.

@Override
public boolean recreateUI() {
    // should return false if executing from the form's execute function but
    // can happen if it is a none component thing
    // so no onfocus/ondatachange/onaction
    // of a component on the form but
    // onshow/onload that should be allowed
    // if (isFormExecutingFunction()) return false;
    // hide all visible children; here is an example that explains why it's needed:
    // parent form has tabpanel with child1 and child2; child2 is visible (second tab)
    // if you recreateUI on parent, child1 would turn out visible after recreateUI without and hide event on child2 if we wouldn't do the notifyVisible below;
    // but also when you would afterwards change tab to child2 it's onShow won't be called because it thinks it's still visible which is strange;
    List<Runnable> ilr = new ArrayList<Runnable>();
    notifyVisibleOnChildren(false, ilr);
    Utils.invokeLater(application, ilr);
    getFormUI().touch();
    Rectangle scrollPosition = null;
    if (view != null)
        scrollPosition = view.getVisibleRect();
    getFormUI().setDesignMode(null);
    Form f = application.getFlattenedSolution().getForm(form.getName());
    // don't use case, make sure it updates the cache
    form = application.getFlattenedSolution().getFlattenedForm(f, false);
    initStylesAndBorder();
    int v = currentViewType;
    currentViewType = -1;
    setView(v);
    if (isFormVisible) {
        // first push the latest data in the regenerated ui.
        valueChanged(null);
        List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
        IDataRenderer[] array = getDataRenderers();
        for (IDataRenderer dataRenderer : array) {
            if (dataRenderer != null) {
                dataRenderer.notifyVisible(true, invokeLaterRunnables);
            }
        }
        Utils.invokeLater(application, invokeLaterRunnables);
    }
    if (designMode != null) {
        application.invokeLater(new Runnable() {

            public void run() {
                getFormUI().setDesignMode(designMode);
            }
        });
    }
    getFormUI().uiRecreated();
    // make sure this form is seen as new.
    application.getFlattenedSolution().deregisterLiveForm(form, namedInstance);
    application.getFlattenedSolution().registerLiveForm(form, namedInstance);
    if (view != null && scrollPosition != null)
        view.setVisibleRect(scrollPosition);
    return true;
}
Also used : IDataRenderer(com.servoy.j2db.ui.IDataRenderer) Form(com.servoy.j2db.persistence.Form) FlattenedForm(com.servoy.j2db.persistence.FlattenedForm) ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle)

Example 2 with IDataRenderer

use of com.servoy.j2db.ui.IDataRenderer in project servoy-client by Servoy.

the class FormController method createDataRenderers.

private void createDataRenderers(int viewType) throws Exception {
    int v = viewType;
    if (getDataSource() == null) {
        // form not based on any datasource
        v = LOCKED_RECORD_VIEW;
    }
    application.getDataRenderFactory().prepareRenderers(application, form);
    Part bodyPart = null;
    Map<Part, IDataRenderer> part_panels = new LinkedHashMap<Part, IDataRenderer>();
    Iterator<Part> e2 = form.getParts();
    while (e2.hasNext()) {
        Part part = e2.next();
        Color partColor = ComponentFactory.getPartBackground(application, part, form);
        // extract the body (bgcolor)
        if (part.getPartType() == Part.BODY) {
            bodyPart = part;
            bgColor = partColor;
            Pair<IStyleSheet, IStyleRule> partStyle = ComponentFactory.getStyleForBasicComponent(application, part, form);
            bodyRule = partStyle != null ? partStyle.getRight() : null;
        }
        if (part.getPartType() == Part.BODY && v == FormController.LOCKED_TABLE_VIEW) {
            // don't create part, view == part
            continue;
        }
        IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, part), part.toString(), application, (part.getPartType() == Part.BODY));
        dr.initDragNDrop(this, form.getPartStartYPos(part.getID()));
        dataRenderers[part.getPartType()] = dr;
        dr.setName(part.toString());
        part_panels.put(part, dr);
        if (part.getPartType() == Part.BODY) {
            int onRenderMethodID = form.getOnRenderMethodID();
            if (onRenderMethodID > 0) {
                dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
                dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
            }
        }
        dr.setBackground(partColor);
    }
    tabSequence.clear();
    application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), tabSequence);
    if (bodyPart != null && (v == FormController.LOCKED_LIST_VIEW || v == IForm.LIST_VIEW)) {
        IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, bodyPart), bodyPart.toString(), application, true);
        int onRenderMethodID = form.getOnRenderMethodID();
        if (onRenderMethodID > 0) {
            dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
            dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
        }
        // apply bgcolor to renderer
        if (bgColor != null) {
            dr.setBackground(bgColor);
        }
        dataRenderers[FORM_RENDERER] = dr;
        dr.setName(bodyPart.toString());
        part_panels = new LinkedHashMap<Part, IDataRenderer>();
        part_panels.put(bodyPart, dr);
        application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), null);
    }
    // apply security
    int access = application.getFlattenedSolution().getSecurityAccess(form.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
    if (access != -1) {
        boolean b_accessible = ((access & IRepository.ACCESSIBLE) != 0);
        if (!b_accessible) {
            for (IDataRenderer dataRenderer : dataRenderers) {
                if (dataRenderer != null) {
                    Iterator<? extends IComponent> componentIterator = dataRenderer.getComponentIterator();
                    while (componentIterator.hasNext()) {
                        IComponent c = componentIterator.next();
                        if (c instanceof ISupportSecuritySettings) {
                            if (!b_accessible)
                                ((ISupportSecuritySettings) c).setAccessible(b_accessible);
                        }
                    }
                }
            }
        }
    }
}
Also used : IStyleSheet(com.servoy.j2db.util.IStyleSheet) IComponent(com.servoy.j2db.ui.IComponent) Color(java.awt.Color) LinkedHashMap(java.util.LinkedHashMap) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) Part(com.servoy.j2db.persistence.Part) IStyleRule(com.servoy.j2db.util.IStyleRule) ISupportSecuritySettings(com.servoy.j2db.ui.ISupportSecuritySettings)

Example 3 with IDataRenderer

use of com.servoy.j2db.ui.IDataRenderer in project servoy-client by Servoy.

the class FormController method refreshAllPartRenderers.

@Override
protected void refreshAllPartRenderers(IRecordInternal[] records) {
    if (!isFormVisible || application.isShutDown())
        return;
    // don't do anything yet when there are records but the selection is invalid
    if (formModel.getSize() > 0 && (formModel.getSelectedIndex() < 0 || formModel.getSelectedIndex() >= formModel.getSize()))
        return;
    // let the ui know that it will be touched, so that locks can be taken if needed.
    getFormUI().touch();
    boolean executeOnRecordSelect = false;
    IRecordInternal[] state = records;
    if (state == null) {
        if (formModel != null) {
            state = new IRecordInternal[] { formModel.getPrototypeState() };
        } else {
            state = new IRecordInternal[] { new PrototypeState(null) };
        }
    }
    if (dataRenderers[FORM_EDITOR] != null && !(records == null && formModel != null && formModel.getRawSize() > 0) && isStateChanged(state)) {
        lastState = state;
        executeOnRecordSelect = true;
    }
    for (int i = FORM_RENDERER + 1; i < dataRenderers.length; i++) {
        IDataRenderer dataRenderer = dataRenderers[i];
        if (dataRenderer != null) {
            for (IRecordInternal r : state) dataRenderer.refreshRecord(r);
        }
    }
    if (executeOnRecordSelect) {
        // do this at the end because dataRenderer.refreshRecord(state) will update selection
        // for related tabs - and we should execute js code after they have been updated
        executeOnRecordSelect();
    }
}
Also used : IDataRenderer(com.servoy.j2db.ui.IDataRenderer) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) PrototypeState(com.servoy.j2db.dataprocessing.PrototypeState)

Example 4 with IDataRenderer

use of com.servoy.j2db.ui.IDataRenderer in project servoy-client by Servoy.

the class FormController method propagateFindMode.

/*
	 * _____________________________________________________________ The methods below belong to this class
	 */
@Override
public void propagateFindMode(boolean findMode) {
    if (!findMode) {
        application.getFoundSetManager().getEditRecordList().prepareForSave(true);
    }
    if (isReadOnly()) {
        if (view != null) {
            view.setEditable(findMode);
        }
    }
    for (IDataRenderer dataRenderer : dataRenderers) {
        if (dataRenderer != null) {
            // see web cell based view that is used as a tableview and portal.
            if (dataRenderer instanceof IDisplay) {
                ((IDisplay) dataRenderer).setValidationEnabled(!findMode);
            } else {
                DataAdapterList dal = dataRenderer.getDataAdapterList();
                // disables related data en does getText instead if getValue on fields
                dal.setFindMode(findMode);
                dataRenderer.setAllNonFieldsEnabled(!findMode);
            }
        // }
        // else
        // {
        // //dataRenderers[i].setUIEnabled(!findMode);
        // }
        }
    }
}
Also used : IDataRenderer(com.servoy.j2db.ui.IDataRenderer) DataAdapterList(com.servoy.j2db.dataprocessing.DataAdapterList) IDisplay(com.servoy.j2db.dataprocessing.IDisplay)

Example 5 with IDataRenderer

use of com.servoy.j2db.ui.IDataRenderer in project servoy-client by Servoy.

the class FormDataTransferHandler method createScriptEvent.

@Override
protected JSDNDEvent createScriptEvent(EventType type, ICompositeDragNDrop ddComponent, Object event) {
    JSDNDEvent jsEvent = super.createScriptEvent(type, ddComponent, event);
    if (ddComponent instanceof IFormDataDragNDrop) {
        IFormDataDragNDrop formDataDDComponent = (IFormDataDragNDrop) ddComponent;
        jsEvent.setFormName(formDataDDComponent.getDragFormName());
        Point location = getEventXY(event);
        if (location != null) {
            Object dragSource = ddComponent.getDragSource(location);
            if (dragSource instanceof IDataRenderer) {
                IDataRenderer dr = (IDataRenderer) dragSource;
                FormController fc = dr.getDataAdapterList().getFormController();
                jsEvent.setSource(fc.getFormScope());
            } else if (dragSource instanceof IComponent) {
                jsEvent.setSource(dragSource);
                if (dragSource != null) {
                    String name = ((IComponent) dragSource).getName();
                    if (name != null && name.startsWith(ComponentFactory.WEB_ID_PREFIX)) {
                        name = null;
                    }
                    jsEvent.setElementName(name);
                }
            }
            IRecordInternal dragRecord = formDataDDComponent.getDragRecord(location);
            if (dragRecord instanceof Record)
                jsEvent.setRecord((Record) dragRecord);
        }
    }
    return jsEvent;
}
Also used : FormController(com.servoy.j2db.FormController) IDataRenderer(com.servoy.j2db.ui.IDataRenderer) IRecordInternal(com.servoy.j2db.dataprocessing.IRecordInternal) IComponent(com.servoy.j2db.ui.IComponent) Record(com.servoy.j2db.dataprocessing.Record) Point(java.awt.Point)

Aggregations

IDataRenderer (com.servoy.j2db.ui.IDataRenderer)19 Point (java.awt.Point)10 IComponent (com.servoy.j2db.ui.IComponent)8 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)6 FormController (com.servoy.j2db.FormController)5 Part (com.servoy.j2db.persistence.Part)5 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)4 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)4 Component (java.awt.Component)4 JComponent (javax.swing.JComponent)4 NativeJavaObject (org.mozilla.javascript.NativeJavaObject)4 ScriptableObject (org.mozilla.javascript.ScriptableObject)4 Record (com.servoy.j2db.dataprocessing.Record)3 BaseComponent (com.servoy.j2db.persistence.BaseComponent)3 Form (com.servoy.j2db.persistence.Form)3 WebCellBasedView (com.servoy.j2db.server.headlessclient.dataui.WebCellBasedView)3 PortalComponent (com.servoy.j2db.smart.dataui.PortalComponent)3 IStyleRule (com.servoy.j2db.util.IStyleRule)3 IStyleSheet (com.servoy.j2db.util.IStyleSheet)3 ArrayList (java.util.ArrayList)3