Search in sources :

Example 11 with Solution

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

the class NGFormManager method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (// $NON-NLS-1$
    "solution".equals(name)) {
        final Solution s = (Solution) evt.getNewValue();
        Runnable run = new Runnable() {

            @Override
            public void run() {
                boolean isReload = s != null;
                // must run on same thread
                destroySolutionSettings(isReload);
                if (isReload) {
                    makeSolutionSettings(s);
                }
            }
        };
        if (CurrentWindow.exists())
            run.run();
        else
            CurrentWindow.runForWindow(new NGClientWebsocketSessionWindows(getApplication().getWebsocketSession()), run);
    } else if (// $NON-NLS-1$
    "mode".equals(name)) {
        int oldmode = ((Integer) evt.getOldValue()).intValue();
        int newmode = ((Integer) evt.getNewValue()).intValue();
        IFormController fp = getCurrentMainShowingFormController();
        if (oldmode == IModeManager.FIND_MODE || newmode == IModeManager.FIND_MODE) {
            fp.setMode(newmode);
        }
    }
}
Also used : NGClientWebsocketSessionWindows(com.servoy.j2db.server.ngclient.eventthread.NGClientWebsocketSessionWindows) IFormController(com.servoy.j2db.IFormController) Solution(com.servoy.j2db.persistence.Solution)

Example 12 with Solution

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

the class MediaPropertyType method getMediaUrl.

public static String getMediaUrl(Object value, FlattenedSolution flattenedSolution, INGApplication application) {
    String url = null;
    Media media = null;
    if (value instanceof CharSequence) {
        value = ((CharSequence) value).toString();
    }
    if (value instanceof Integer) {
        if (((Integer) value).intValue() == 0) {
            // 0 means no media
            return null;
        }
        media = flattenedSolution.getMedia(((Integer) value).intValue());
    } else if (value instanceof String && ((String) value).toLowerCase().startsWith(MediaURLStreamHandler.MEDIA_URL_DEF)) {
        media = flattenedSolution.getMedia(((String) value).substring(MediaURLStreamHandler.MEDIA_URL_DEF.length()));
    } else {
        if (value != null) {
            media = flattenedSolution.getMedia(value.toString());
            if (media == null) {
                media = (Media) flattenedSolution.searchPersist(value.toString());
            }
        }
    }
    if (media != null) {
        url = "resources/" + MediaResourcesServlet.FLATTENED_SOLUTION_ACCESS + "/" + media.getRootObject().getName() + "/" + media.getName();
        Dimension imageSize = ImageLoader.getSize(media.getMediaData());
        boolean paramsAdded = false;
        if (imageSize != null) {
            paramsAdded = true;
            url += "?imageWidth=" + imageSize.width + "&imageHeight=" + imageSize.height;
        }
        if (application != null) {
            Solution sc = flattenedSolution.getSolutionCopy(false);
            if (sc != null && sc.getMedia(media.getName()) != null) {
                if (paramsAdded)
                    url += "&";
                else
                    url += "?";
                url += "clientnr=" + application.getWebsocketSession().getSessionKey().getClientnr() + "&lm:" + sc.getLastModifiedTime();
            }
        }
    } else if (value instanceof String && ((String) value).startsWith("resources/" + MediaResourcesServlet.FLATTENED_SOLUTION_ACCESS)) {
        url = (String) value;
    } else if (value != null) {
        Debug.warn("Invalid media value received: " + value + ", cannot resolve it.");
    }
    return url;
}
Also used : JSMedia(com.servoy.j2db.scripting.solutionmodel.JSMedia) Media(com.servoy.j2db.persistence.Media) Dimension(java.awt.Dimension) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 13 with Solution

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

the class ServoyFunctionPropertyType method toJSON.

public JSONWriter toJSON(JSONWriter writer, String key, Object object, PropertyDescription pd, DataConversion clientConversion, FlattenedSolution fs, FormElement fe, WebFormComponent formComponent) throws JSONException {
    Map<String, Object> map = new HashMap<>();
    if (object != null && fs != null) {
        // $NON-NLS-1$
        String[] components = object.toString().split("-");
        if (components.length == 5) {
            String scriptString = null;
            // this is a uuid
            ScriptMethod sm = fs.getScriptMethod(object.toString());
            if (sm != null) {
                ISupportChilds parent = sm.getParent();
                if (parent instanceof Solution) {
                    scriptString = "scopes." + sm.getScopeName() + "." + sm.getName();
                } else if (parent instanceof Form) {
                    if (formComponent != null) {
                        // use the real, runtime form
                        scriptString = formComponent.getDataAdapterList().getForm().getForm().getName() + "." + sm.getName();
                    } else {
                        scriptString = ((Form) parent).getName() + "." + sm.getName();
                    }
                } else if (parent instanceof TableNode && fe != null) {
                    scriptString = "entity." + fe.getForm().getName() + "." + sm.getName();
                }
                object = scriptString;
            } else
                Debug.log("can't find a scriptmethod for: " + object);
        }
    }
    try {
        if (object instanceof String) {
            addScriptToMap((String) object, map);
        } else if (object instanceof NativeFunction) {
            nativeFunctionToJSON((NativeFunction) object, map);
        } else if (object instanceof FunctionWrapper && ((FunctionWrapper) object).getWrappedFunction() instanceof NativeFunction) {
            nativeFunctionToJSON((NativeFunction) ((FunctionWrapper) object).getWrappedFunction(), map);
        } else if (object instanceof Map) {
            map = new HashMap<String, Object>((Map<String, Object>) object);
            if (map.get("script") instanceof String)
                addScriptToMap((String) map.get("script"), map);
        }
    } catch (Exception ex) {
        Debug.error(ex);
    }
    return JSONUtils.toBrowserJSONFullValue(writer, key, map.size() == 0 ? null : map, null, clientConversion, null);
}
Also used : FunctionWrapper(com.servoy.j2db.scripting.FunctionWrapper) ISupportChilds(com.servoy.j2db.persistence.ISupportChilds) HashMap(java.util.HashMap) Form(com.servoy.j2db.persistence.Form) JSForm(com.servoy.j2db.scripting.solutionmodel.JSForm) NativeFunction(org.mozilla.javascript.NativeFunction) JSONException(org.json.JSONException) TableNode(com.servoy.j2db.persistence.TableNode) JSONObject(org.json.JSONObject) ScriptMethod(com.servoy.j2db.persistence.ScriptMethod) HashMap(java.util.HashMap) Map(java.util.Map) FlattenedSolution(com.servoy.j2db.FlattenedSolution) Solution(com.servoy.j2db.persistence.Solution)

Example 14 with Solution

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

the class FlattenedSolution method getMaxID.

protected int getMaxID() {
    final int[] maxId = new int[1];
    IPersistVisitor visitor = new IPersistVisitor() {

        public Object visit(IPersist o) {
            if (maxId[0] < o.getID()) {
                maxId[0] = o.getID();
            }
            return IPersistVisitor.CONTINUE_TRAVERSAL;
        }
    };
    mainSolution.acceptVisitor(visitor);
    if (modules != null) {
        for (Solution module : modules) {
            module.acceptVisitor(visitor);
        }
    }
    int max = maxId[0];
    if (loginFlattenedSolution != null) {
        int loginMax = loginFlattenedSolution.getMaxID();
        if (loginMax > max) {
            max = loginMax;
        }
    }
    return max;
}
Also used : IPersist(com.servoy.j2db.persistence.IPersist) IPersistVisitor(com.servoy.j2db.persistence.IPersistVisitor) Solution(com.servoy.j2db.persistence.Solution)

Example 15 with Solution

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

the class FlattenedSolution method setSolution.

public void setSolution(SolutionMetaData sol, boolean loadLoginSolution, boolean loadMainSolution, IActiveSolutionHandler activeSolutionHandler) throws RepositoryException, RemoteException {
    // $NON-NLS-1$
    if (sol == null)
        throw new IllegalArgumentException("use close method!");
    isLoadingSolution = true;
    try {
        copySolution = null;
        persistFactory = null;
        mainSolution = null;
        user_created_styles = null;
        all_styles = null;
        if (index != null) {
            index.destroy();
            index = null;
        }
        mainSolutionMetaData = sol;
        if (loadLoginSolution) {
            // get login solution
            Solution[] loginSolutionAndModules = activeSolutionHandler.loadLoginSolutionAndModules(mainSolutionMetaData);
            if (loginSolutionAndModules != null && loginSolutionAndModules.length > 0) {
                if (loginFlattenedSolution == null) {
                    loginFlattenedSolution = new ExtendsConfiguratingFlattenedSolution();
                }
                loginFlattenedSolution.setSolutionAndModules(loginSolutionAndModules[0].getName(), loginSolutionAndModules);
                loginFlattenedSolution.setParentSolution(this);
            }
        }
        // get regular solution if available
        if (// local or already access to repository
        loadMainSolution && activeSolutionHandler.haveRepositoryAccess()) {
            // Note: referencedModules includes main solution
            List<RootObjectReference> referencedModules = activeSolutionHandler.getRepository().getActiveSolutionModuleMetaDatas(mainSolutionMetaData.getRootObjectId());
            if (referencedModules != null && referencedModules.size() != 0) {
                List<RootObjectMetaData> solutionAndModuleMetaDatas = new ArrayList<RootObjectMetaData>();
                for (RootObjectReference moduleReference : referencedModules) {
                    RootObjectMetaData moduleMetaData = moduleReference.getMetaData();
                    if (moduleMetaData == null) {
                        // $NON-NLS-1$
                        throw new RepositoryException(Messages.getString("servoy.client.module.notfound", new Object[] { moduleReference.toString() }));
                    }
                    solutionAndModuleMetaDatas.add(moduleMetaData);
                }
                Solution[] mods = activeSolutionHandler.loadActiveSolutions(solutionAndModuleMetaDatas.toArray(new RootObjectMetaData[solutionAndModuleMetaDatas.size()]));
                setSolutionAndModules(mainSolutionMetaData.getName(), mods);
            }
        }
    } finally {
        isLoadingSolution = false;
    }
}
Also used : RootObjectMetaData(com.servoy.j2db.persistence.RootObjectMetaData) RootObjectReference(com.servoy.j2db.persistence.RootObjectReference) ArrayList(java.util.ArrayList) RepositoryException(com.servoy.j2db.persistence.RepositoryException) JSONObject(org.json.JSONObject) IRootObject(com.servoy.j2db.persistence.IRootObject) Solution(com.servoy.j2db.persistence.Solution)

Aggregations

Solution (com.servoy.j2db.persistence.Solution)59 FlattenedSolution (com.servoy.j2db.FlattenedSolution)17 Form (com.servoy.j2db.persistence.Form)16 ScriptMethod (com.servoy.j2db.persistence.ScriptMethod)14 RepositoryException (com.servoy.j2db.persistence.RepositoryException)12 ArrayList (java.util.ArrayList)9 RemoteException (java.rmi.RemoteException)8 HashMap (java.util.HashMap)8 FlattenedForm (com.servoy.j2db.persistence.FlattenedForm)7 IPersist (com.servoy.j2db.persistence.IPersist)6 TableNode (com.servoy.j2db.persistence.TableNode)6 ServoyException (com.servoy.j2db.util.ServoyException)6 JSONObject (org.json.JSONObject)6 IFormController (com.servoy.j2db.IFormController)5 Map (java.util.Map)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 JavaScriptException (org.mozilla.javascript.JavaScriptException)5 IRepository (com.servoy.j2db.persistence.IRepository)4 List (java.util.List)4 ApplicationException (com.servoy.j2db.ApplicationException)3