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);
}
}
}
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;
}
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);
}
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;
}
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;
}
}
Aggregations