Search in sources :

Example 46 with FormController

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

the class DataProviderEditor method setValue.

public void setValue(Object v) {
    value = (String) v;
    FormManager fm = (FormManager) application.getFormManager();
    FormController fc = fm.getCurrentMainShowingFormController();
    if (fc != null) {
        Form form = fc.getForm();
        if (form != null) {
            try {
                IDataProvider dp = application.getFlattenedSolution().getDataproviderLookup(null, form).getDataProvider(value);
                showDataEx(dp);
            } catch (Exception ex) {
                Debug.error(ex);
            }
        }
    }
}
Also used : FormController(com.servoy.j2db.FormController) FormManager(com.servoy.j2db.FormManager) Form(com.servoy.j2db.persistence.Form) IDataProvider(com.servoy.j2db.persistence.IDataProvider)

Example 47 with FormController

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

the class FormFrame method setTitle.

/**
 * @see java.awt.Dialog#setTitle(java.lang.String)
 */
@Override
public void setTitle(String rawTitle) {
    FormController fp = mainContainer.getController();
    String title = rawTitle;
    if (title == null)
        title = fp.getForm().getTitleText();
    if (title == null)
        title = fp.getName();
    title = application.getI18NMessageIfPrefixed(title);
    if (title != null) {
        String name2 = Text.processTags(title, fp.getTagResolver());
        if (name2 != null)
            title = name2;
    }
    super.setTitle(title);
}
Also used : FormController(com.servoy.j2db.FormController)

Example 48 with FormController

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

the class WebForm method formMethodExecution.

/*
	 * @see com.servoy.j2db.ISupportFormExecutionState#formMethodExecution()
	 */
@Override
public FormExecutionState formMethodExecution() {
    FormController fc = getController();
    IBasicFormManager formManager = fc.getBasicFormManager();
    if (formManager != null) {
        IBasicMainContainer currentContainer = formManager.getCurrentContainer();
        MainPage formPage = getMainPage();
        if (currentContainer != formPage) {
            FormExecutionState formExecutionState = new FormExecutionState();
            formExecutionState.mainContainer = currentContainer;
            formExecutionState.mainContainerName = currentContainer.getContainerName();
            ((WebFormManager) formManager).setCurrentContainer(formPage, getContainerName());
            return formExecutionState;
        }
    }
    return null;
}
Also used : FormController(com.servoy.j2db.FormController) IBasicMainContainer(com.servoy.j2db.IBasicMainContainer) IBasicFormManager(com.servoy.j2db.IBasicFormManager) ISupportFormExecutionState(com.servoy.j2db.ISupportFormExecutionState) FormExecutionState(com.servoy.j2db.FormExecutionState)

Example 49 with FormController

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

the class SortableCellViewHeaderGroup method sort.

protected final void sort(final String name, final WebCellBasedView view, int modifiers) {
    direction = Utils.getAsBoolean(sorted.get(name));
    direction = !direction;
    FormController fc = null;
    try {
        Iterator<IPersist> it = cellview.getAllObjects();
        while (it.hasNext()) {
            IPersist element = it.next();
            if (element instanceof ISupportName && element instanceof ISupportDataProviderID) {
                if (name.equals(ComponentFactory.getWebID(form, element))) {
                    IFoundSetInternal fs = ((FoundSetListWrapper) listView.getList()).getFoundSet();
                    if (fs != null) {
                        WebForm wf = listView.findParent(WebForm.class);
                        if (wf != null)
                            fc = wf.getController();
                        GraphicalComponent gc = (GraphicalComponent) view.labelsFor.get(((ISupportName) element).getName());
                        int labelForOnActionMethodId = 0;
                        if (gc != null) {
                            labelForOnActionMethodId = gc.getOnActionMethodID();
                        }
                        if (fc != null && labelForOnActionMethodId > 0) {
                            // execute on action
                            JSEvent event = new JSEvent();
                            event.setType(JSEvent.EventType.action);
                            event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
                            event.setFormName(view.getDataAdapterList().getFormController().getName());
                            event.setModifiers(modifiers);
                            event.setElementName(gc.getName());
                            fc.executeFunction(String.valueOf(labelForOnActionMethodId), // $NON-NLS-1$
                            Utils.arrayMerge((new Object[] { event }), Utils.parseJSExpressions(gc.getFlattenedMethodArguments("onActionMethodID"))), true, null, false, // $NON-NLS-1$
                            "onActionMethodID");
                        }
                        String id = ((ISupportDataProviderID) element).getDataProviderID();
                        if (id != null) {
                            if (cellview instanceof Portal && !ScopesUtils.isVariableScope(id)) {
                                int idx = id.lastIndexOf('.');
                                if (idx > 0) {
                                    id = id.substring(idx + 1);
                                }
                            }
                            IDataProvider dataProvider = null;
                            if (fc != null) {
                                dataProvider = fs.getFoundSetManager().getApplication().getFlattenedSolution().getDataproviderLookup(fs.getFoundSetManager(), fc.getForm()).getDataProvider(id);
                            }
                            if (!(fc != null && labelForOnActionMethodId > 0)) {
                                // in case there is no onAction definned
                                if (cellview instanceof Portal || fc == null || fc.getForm().getOnSortCmdMethodID() == 0) {
                                    List<String> sortingProviders = null;
                                    try {
                                        sortingProviders = DBValueList.getShowDataproviders(fs.getFoundSetManager().getApplication().getFlattenedSolution().getValueList(((ISupportDataProviderID) element).getValuelistID()), (Table) fs.getTable(), dataProvider == null ? id : dataProvider.getDataProviderID(), fs.getFoundSetManager());
                                    } catch (RepositoryException ex) {
                                        Debug.error(ex);
                                    }
                                    if (sortingProviders == null) {
                                        // no related sort, use sort on dataProviderID instead
                                        sortingProviders = Collections.singletonList(dataProvider == null ? id : dataProvider.getDataProviderID());
                                    }
                                    List<SortColumn> list = (modifiers & Event.SHIFT_MASK) != 0 ? fs.getSortColumns() : new ArrayList<SortColumn>();
                                    for (String sortingProvider : sortingProviders) {
                                        FoundSetManager fsm = (FoundSetManager) fs.getFoundSetManager();
                                        SortColumn sc = fsm.getSortColumn(fs.getTable(), sortingProvider, false);
                                        if (sc != null && sc.getColumn().getDataProviderType() != IColumnTypes.MEDIA) {
                                            for (SortColumn oldColumn : list) {
                                                if (oldColumn.equalsIgnoreSortorder(sc)) {
                                                    sc = oldColumn;
                                                    break;
                                                }
                                            }
                                            if (!list.contains(sc))
                                                list.add(sc);
                                            sc.setSortOrder(direction ? SortColumn.ASCENDING : SortColumn.DESCENDING);
                                        }
                                        fs.sort(list, false);
                                    }
                                } else if (fc != null && fc.getForm().getOnSortCmdMethodID() != -1) {
                                    JSEvent event = new JSEvent();
                                    event.setType(JSEvent.EventType.none);
                                    event.setName(RepositoryHelper.getDisplayName(StaticContentSpecLoader.PROPERTY_ONSORTCMDMETHODID.getPropertyName(), Form.class));
                                    event.setFormName(view.getDataAdapterList().getFormController().getName());
                                    event.setModifiers(modifiers);
                                    fc.executeFunction(String.valueOf(fc.getForm().getOnSortCmdMethodID()), Utils.arrayMerge((new Object[] { dataProvider == null ? id : dataProvider.getDataProviderID(), Boolean.valueOf(direction), event }), // $NON-NLS-1$
                                    Utils.parseJSExpressions(fc.getForm().getFlattenedMethodArguments("onSortCmdMethodID"))), true, null, false, // $NON-NLS-1$
                                    "onSortCmdMethodID");
                                }
                            }
                            if ((modifiers & Event.SHIFT_MASK) == 0) {
                                sorted.clear();
                            }
                            sorted.put(name, new Boolean(direction));
                            listView.setCurrentPage(0);
                        }
                    }
                    break;
                }
            }
        }
        listView.modelChanged();
    } catch (Exception e) {
        if (fc != null) {
            if (e instanceof ServoyException) {
                ((ServoyException) e).setContext(fc.toString());
            } else {
                ServoyException se = new ServoyException();
                se.initCause(e);
                se.setContext(fc.toString());
                e = se;
            }
        }
        Debug.error("error sorting foundset: " + sorted, e);
    }
}
Also used : Form(com.servoy.j2db.persistence.Form) WebForm(com.servoy.j2db.server.headlessclient.WebForm) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) WebForm(com.servoy.j2db.server.headlessclient.WebForm) ISupportName(com.servoy.j2db.persistence.ISupportName) FoundSetListWrapper(com.servoy.j2db.dataprocessing.FoundSetListWrapper) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IDataProvider(com.servoy.j2db.persistence.IDataProvider) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) ServoyException(com.servoy.j2db.util.ServoyException) Portal(com.servoy.j2db.persistence.Portal) FormController(com.servoy.j2db.FormController) FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) JSEvent(com.servoy.j2db.scripting.JSEvent) Table(com.servoy.j2db.persistence.Table) ISupportDataProviderID(com.servoy.j2db.persistence.ISupportDataProviderID) RepositoryException(com.servoy.j2db.persistence.RepositoryException) ServoyException(com.servoy.j2db.util.ServoyException) RepositoryException(com.servoy.j2db.persistence.RepositoryException) IPersist(com.servoy.j2db.persistence.IPersist)

Example 50 with FormController

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

the class WebFormManager method reload.

public void reload(FormController[] fcontrollers) {
    HashSet<MainPage> mainPages = new HashSet<MainPage>();
    for (FormController fc : fcontrollers) {
        WebForm formUI = (WebForm) fc.getFormUI();
        MainPage mp = formUI.findParent(MainPage.class);
        if (mp != null && mainPages.add(mp)) {
            mp.setVersioned(false);
            mp.setMainPageSwitched();
        }
    }
    String navigatorName = null;
    Set<MainPage> parents = new HashSet<MainPage>();
    for (FormController fp : fcontrollers) {
        if (fp != null) {
            boolean formVisible = fp.isFormVisible();
            IFoundSetInternal foundset = fp.getFormModel();
            WebForm wf = (WebForm) fp.getFormUI();
            MarkupContainer wfParent = wf.getParent();
            boolean refresh = false;
            // datasource has changed, but foundset has not
            if (foundset != null && !Utils.equalObjects(foundset.getDataSource(), fp.getDataSource())) {
                try {
                    foundset = (getApplication()).getFoundSetManager().getSharedFoundSet(fp.getDataSource());
                    foundset.loadAllRecords();
                    refresh = true;
                } catch (ServoyException e) {
                    // $NON-NLS-1$
                    Debug.error("Failed to reload foundset.", e);
                }
            }
            MainPage page = wf.findParent(MainPage.class);
            try {
                if (page != null) {
                    page.setTempRemoveMainForm(true);
                }
                fp.destroy();
            } finally {
                if (page != null) {
                    page.setTempRemoveMainForm(false);
                }
            }
            while (wfParent != null && !(wfParent instanceof IWebFormContainer) && !(wfParent.getParent() instanceof MainPage) && !(wfParent.getParent() instanceof WebForm)) {
                wfParent = wfParent.getParent();
            }
            if (wfParent instanceof IWebFormContainer) {
                if (formVisible) {
                    FormController fc = leaseFormPanel(fp.getName());
                    if (fc != null) {
                        // form was deleted in developer?
                        fc.loadData(foundset, null);
                        if (refresh)
                            fc.recreateUI();
                        List<Runnable> runnables = new ArrayList<Runnable>();
                        ((IWebFormContainer) wfParent).notifyVisible(true, runnables);
                        Utils.invokeLater(getApplication(), runnables);
                    }
                }
            } else if (wfParent != null) {
                WebForm parentWF = wfParent.findParent(WebForm.class);
                if (parentWF != null) {
                    if (!Arrays.asList(fcontrollers).contains(parentWF.getController()))
                        parentWF.getController().destroy();
                } else {
                    MainPage parent = wfParent.findParent(MainPage.class);
                    if (parent != null && !parents.contains(parent)) {
                        parents.add(parent);
                        if (parent.getNavigator() == fp) {
                            navigatorName = fp.getName();
                            FormController navigator = getFormController(navigatorName, parent);
                            if (navigator != null) {
                                List<Runnable> invokeLaterRunnables = new ArrayList<Runnable>();
                                navigator.notifyVisible(true, invokeLaterRunnables);
                                Utils.invokeLater(getApplication(), invokeLaterRunnables);
                                parent.setNavigator(navigator);
                            // parent.triggerBrowserRequestIfNeeded(); // FIXME: this is needed here but currently does nothing because the request target is not yet set
                            }
                        }
                        FormController previousMainShowingForm = (parent != null ? parent.getController() : null);
                        if (previousMainShowingForm != null) {
                            FormController previousNavigator = parent.getNavigator();
                            parent.setController(null);
                            // navigator is not re-applied so apply it manually
                            int navigatorID = previousMainShowingForm.getForm().getNavigatorID();
                            if (navigatorID == Form.NAVIGATOR_IGNORE || (previousNavigator != null && previousNavigator.getForm().getID() == navigatorID)) {
                                parent.setNavigator(previousNavigator);
                            } else if (navigatorID > 0) {
                                Form newNavigator = application.getFlattenedSolution().getForm(navigatorID);
                                if (newNavigator != null) {
                                    parent.setNavigator(leaseFormPanel(newNavigator.getName()));
                                }
                            }
                            showFormInMainPanel(previousMainShowingForm.getName(), parent, null, true, null);
                        // parent.triggerBrowserRequestIfNeeded(); // FIXME: this is needed here but currently does nothing because the request target is not yet set
                        }
                    }
                }
            }
        }
    }
    for (MainPage mainPage : mainPages) {
        mainPage.setVersioned(true);
    }
}
Also used : FormController(com.servoy.j2db.FormController) BasicFormController(com.servoy.j2db.BasicFormController) MarkupContainer(org.apache.wicket.MarkupContainer) Form(com.servoy.j2db.persistence.Form) SwingForm(com.servoy.j2db.smart.SwingForm) IFoundSetInternal(com.servoy.j2db.dataprocessing.IFoundSetInternal) ArrayList(java.util.ArrayList) ServoyException(com.servoy.j2db.util.ServoyException) IWebFormContainer(com.servoy.j2db.server.headlessclient.dataui.IWebFormContainer) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

FormController (com.servoy.j2db.FormController)70 FormManager (com.servoy.j2db.FormManager)15 Form (com.servoy.j2db.persistence.Form)13 IFoundSetInternal (com.servoy.j2db.dataprocessing.IFoundSetInternal)12 RepositoryException (com.servoy.j2db.persistence.RepositoryException)10 Point (java.awt.Point)10 IRecordInternal (com.servoy.j2db.dataprocessing.IRecordInternal)9 ArrayList (java.util.ArrayList)9 IFormController (com.servoy.j2db.IFormController)8 BasicFormController (com.servoy.j2db.BasicFormController)7 IForm (com.servoy.j2db.IForm)7 WebForm (com.servoy.j2db.server.headlessclient.WebForm)7 FlattenedSolution (com.servoy.j2db.FlattenedSolution)6 IFormUIInternal (com.servoy.j2db.IFormUIInternal)5 IDataProvider (com.servoy.j2db.persistence.IDataProvider)5 List (java.util.List)5 ApplicationException (com.servoy.j2db.ApplicationException)4 IMainContainer (com.servoy.j2db.IMainContainer)4 PrototypeState (com.servoy.j2db.dataprocessing.PrototypeState)4 IDataRenderer (com.servoy.j2db.ui.IDataRenderer)4