use of com.servoy.j2db.persistence.Style in project servoy-client by Servoy.
the class FlattenedSolution method setSolutionAndModules.
protected void setSolutionAndModules(String mainSolutionName, Solution[] mods) throws RemoteException {
// name -> solution
Map<String, Solution> modulesMap = new HashMap<String, Solution>();
for (Solution module : mods) {
if (module != null) {
if (mainSolutionName.equals(module.getName())) {
mainSolution = module;
} else if (!modulesMap.containsKey(module.getName())) {
modulesMap.put(module.getName(), module);
}
}
}
if (mainSolution != null) {
if (mainSolution.getChangeHandler() != null) {
mainSolution.getChangeHandler().addIPersistListener(this);
}
for (Solution module : modulesMap.values()) {
combineServerProxies(mainSolution.getServerProxies(), module.getServerProxies());
}
}
modules = getDependencyGraphOrderedModules(modulesMap.values(), mainSolution);
flushAllCachedData();
getAllStyles();
for (Solution s : modules) {
HashMap<String, Style> modStyles = s.getSerializableRuntimeProperty(Solution.PRE_LOADED_STYLES);
if (modStyles != null) {
synchronized (modStyles) {
Map<String, Style> allStyles = getAllStyles();
synchronized (// the two syncs should not cause deadlock because the module's lock is always acquired first (so another thread cannot come and do it backwards)
allStyles) {
allStyles.putAll(modStyles);
}
}
}
if (s.getChangeHandler() != null) {
s.getChangeHandler().addIPersistListener(this);
}
}
// everything loaded, let the index be created.
if (index != null) {
index.destroy();
index = null;
}
}
use of com.servoy.j2db.persistence.Style in project servoy-client by Servoy.
the class FlattenedSolution method loadStyleForForm.
/**
* Load style for form, look for extend forms in flattenedSolution when possible
* @param flattenedSolution may be null, fallback to f.getSolution() plus repo load
* @param f
*/
public static Style loadStyleForForm(FlattenedSolution flattenedSolution, Form form) {
try {
String style_name = form.getStyleName();
if (!(form instanceof FlattenedForm)) {
Form extendedForm;
int extended_form_id = form.getExtendsID();
List<RootObjectReference> modulesMetaData = null;
// We keep track of visited forms, to avoid infinite loop.
Set<Integer> visited = new HashSet<Integer>();
while (style_name == null && extended_form_id > 0) {
visited.add(new Integer(extended_form_id));
// if this is hit here with a normal (not flattened form) that has an extend.
// and that form is a solution modal form. the f.getSolution() doesn't have to find it.
// because f.getSolution() is the copy solution thats inside the FlattenedSolution.
// that one doesn't have any other forms. But normally all forms should be flattened.
extendedForm = flattenedSolution == null ? form.getSolution().getForm(extended_form_id) : flattenedSolution.getForm(extended_form_id);
if (// check for module form
flattenedSolution == null && extendedForm == null) {
if (modulesMetaData == null) {
modulesMetaData = form.getSolution().getRepository().getActiveSolutionModuleMetaDatas(form.getSolution().getID());
}
for (RootObjectReference moduleMetaData : modulesMetaData) {
Solution module = (Solution) form.getSolution().getRepository().getActiveRootObject(moduleMetaData.getMetaData().getRootObjectId());
extendedForm = module.getForm(extended_form_id);
if (extendedForm != null) {
break;
}
}
}
if (extendedForm == null) {
// in case referring to no longer existing form
break;
}
style_name = extendedForm.getStyleName();
extended_form_id = extendedForm.getExtendsID();
if (visited.contains(new Integer(extended_form_id))) {
// in case of cycle in form inheritance hierarchy
break;
}
}
}
if (style_name == null)
return null;
// preload the style at the server
Style s = (Style) form.getSolution().getRepository().getActiveRootObject(style_name, IRepository.STYLES);
return s;
} catch (Exception e) {
Debug.error(e);
}
return null;
}
use of com.servoy.j2db.persistence.Style in project servoy-client by Servoy.
the class FlattenedSolution method createStyle.
public Style createStyle(String name, String content) {
if (mainSolution == null) {
if (loginFlattenedSolution == null) {
return null;
}
return loginFlattenedSolution.createStyle(name, content);
}
// $NON-NLS-1$ //$NON-NLS-2$
if (getAllStyles().containsKey(name) && !deletedStyles.contains(name))
throw new RuntimeException("Style with name '" + name + "' already exists");
if (user_created_styles == null)
user_created_styles = new HashMap<String, Style>();
// $NON-NLS-1$ //$NON-NLS-2$
if (user_created_styles.containsKey(name))
throw new RuntimeException("Style with name '" + name + "' already exists");
RootObjectMetaData rootObjectMetaData = new RootObjectMetaData(-1, UUID.randomUUID(), name, IRepository.STYLES, 1, 1);
rootObjectMetaData.setName(name);
Style style = new Style(mainSolution.getRepository(), rootObjectMetaData);
style.setContent(content);
user_created_styles.put(name, style);
deletedStyles.remove(name);
return style;
}
use of com.servoy.j2db.persistence.Style in project servoy-client by Servoy.
the class WebClient method closeSolution.
@SuppressWarnings("nls")
@Override
public boolean closeSolution(boolean force, Object[] args) {
if (getSolution() == null || closing)
return true;
try {
RequestCycle rc = RequestCycle.get();
closing = true;
MainPage mp = MainPage.getRequestMainPage();
if (mp == null) {
mp = getMainPage();
}
// generate requests on all other reachable browser tabs/browser windows that are open in this client;
// so that they can show the "page expired" page (even if AJAX timer is not enabled)
List<String> triggerReqScripts = getTriggerReqOnOtherPagesJS(rc, mp);
MainPage.ShowUrlInfo showUrlInfo = mp.getShowUrlInfo();
// if this page is showing in a div dialog (or is about to be closed as it was in one), the page redirect needs to happen inside root page, not in iframe
boolean shownInDialog = mp.isShowingInDialog() || mp.isClosingAsDivPopup();
boolean retval = super.closeSolution(force, args);
if (retval) {
// reset path to templates such as servoy_webclient_default.css in case session/client are reused for another solution
if (rc != null)
putClientProperty(WEBCONSTANTS.WEBCLIENT_TEMPLATES_DIR, null);
else {
// for example when being closed from admin page
invokeLater(new Runnable() {
@Override
public void run() {
putClientProperty(WEBCONSTANTS.WEBCLIENT_TEMPLATES_DIR, null);
}
});
}
if (rc != null && rc.getRequestTarget() instanceof AjaxRequestTarget) {
// the idea of this line is to block all possible showurl calls generated by any RedirectAjaxRequestTargets arriving (after the solution is closed) on the page,
// page that might want to actually show some (possibly external and slow) other page instead of page expired
((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript("getRootServoyFrame().Servoy.redirectingOnSolutionClose = true;");
if (triggerReqScripts != null) {
for (String js : triggerReqScripts) {
((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(js);
}
}
}
// close all windows
getRuntimeWindowManager().closeFormInWindow(null, true);
Collection<Style> userStyles = getFlattenedSolution().flushUserStyles();
if (userStyles != null) {
for (Style style : userStyles) {
ComponentFactory.flushStyle(this, style);
}
}
getRuntimeProperties().put(IServiceProvider.RT_VALUELIST_CACHE, null);
getRuntimeProperties().put(IServiceProvider.RT_OVERRIDESTYLE_CACHE, null);
// what page should be shown next in browser?
if (rc != null) {
boolean showDefault = true;
boolean urlShown = false;
if (showUrlInfo != null) {
showDefault = !"_self".equals(showUrlInfo.getTarget()) && !"_top".equals(showUrlInfo.getTarget());
String url = "/";
if (showUrlInfo.getUrl() != null) {
url = showUrlInfo.getUrl();
}
if (rc.getRequestTarget() instanceof AjaxRequestTarget) {
showUrlInfo.setOnRootFrame(true);
showUrlInfo.setUseIFrame(false);
String show = MainPage.getShowUrlScript(showUrlInfo, getSettings());
if (show != null) {
urlShown = true;
((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(show);
// extra call to make sure that it is removed for the next time.
mp.getShowUrlScript();
}
} else {
rc.setRequestTarget(new RedirectRequestTarget(url));
}
}
if (showDefault) {
if (Session.exists() && RequestCycle.get() != null) {
if (getPreferedSolutionNameToLoadOnInit() == null) {
if ((urlShown || shownInDialog) && rc.getRequestTarget() instanceof AjaxRequestTarget) {
// if this page is shown in a dialog then try to get the parent so that the page map is not included in the url
MainPage page = mp;
while ((page.isShowingInDialog() || page.isClosingAsDivPopup()) && page.getCallingContainer() != null) {
page = page.getCallingContainer();
}
CharSequence urlFor = page.urlFor(SelectSolution.class, null);
((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(MainPage.getShowUrlScript(new ShowUrlInfo(urlFor.toString(), "_self", null, 0, true, false), getSettings()));
} else {
mp.setResponsePage(SelectSolution.class);
}
} else {
// if solution browsing is false, make sure that the credentials are kept
if (!Utils.getAsBoolean(Settings.getInstance().getProperty("servoy.allowSolutionBrowsing", "true"))) {
WebClientSession.get().keepCredentials(getPreferedSolutionNameToLoadOnInit());
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("s", getPreferedSolutionNameToLoadOnInit());
map.put("m", getPreferedSolutionMethodNameToCall());
if (getPreferedSolutionMethodArguments() != null && getPreferedSolutionMethodArguments().length > 0) {
map.put("a", getPreferedSolutionMethodArguments()[0]);
}
if ((urlShown || shownInDialog) && rc.getRequestTarget() instanceof AjaxRequestTarget) {
CharSequence urlFor = mp.urlFor(SolutionLoader.class, new PageParameters(map));
((AjaxRequestTarget) rc.getRequestTarget()).appendJavascript(MainPage.getShowUrlScript(new ShowUrlInfo(urlFor.toString(), "_self", null, 0, true, false), getSettings()));
} else {
rc.setResponsePage(SolutionLoader.class, new PageParameters(map), null);
}
}
}
}
}
}
return retval;
} finally {
closing = false;
}
}
use of com.servoy.j2db.persistence.Style in project servoy-client by Servoy.
the class DebugUtils method getScopesAndFormsToReload.
public static Set<IFormController>[] getScopesAndFormsToReload(final ClientState clientState, Collection<IPersist> changes) {
Set<IFormController> scopesToReload = new HashSet<IFormController>();
final Set<IFormController> formsToReload = new HashSet<IFormController>();
final SpecProviderState specProviderState = WebComponentSpecProvider.getSpecProviderState();
final Set<Form> formsUpdated = new HashSet<Form>();
for (IPersist persist : changes) {
clientState.getFlattenedSolution().updatePersistInSolutionCopy(persist);
if (persist instanceof ScriptMethod) {
if (persist.getParent() instanceof Form) {
Form form = (Form) persist.getParent();
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
for (IFormController formController : cachedFormControllers) {
scopesToReload.add(formController);
}
} else if (persist.getParent() instanceof Solution) {
LazyCompilationScope scope = clientState.getScriptEngine().getScopesScope().getGlobalScope(((ScriptMethod) persist).getScopeName());
scope.remove((IScriptProvider) persist);
scope.put((IScriptProvider) persist, (IScriptProvider) persist);
} else if (persist.getParent() instanceof TableNode) {
clientState.getFoundSetManager().reloadFoundsetMethod(((TableNode) persist.getParent()).getDataSource(), (IScriptProvider) persist);
}
if (clientState instanceof DebugJ2DBClient) {
// ((DebugJ2DBClient)clientState).clearUserWindows(); no need for this as window API was refactored and it allows users to clean up dialogs
((DebugSwingFormMananger) ((DebugJ2DBClient) clientState).getFormManager()).fillScriptMenu();
}
} else if (persist instanceof ScriptVariable) {
ScriptVariable sv = (ScriptVariable) persist;
if (persist.getParent() instanceof Solution) {
clientState.getScriptEngine().getScopesScope().getGlobalScope(sv.getScopeName()).put(sv);
}
if (persist.getParent() instanceof Form) {
Form form = (Form) persist.getParent();
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
for (IFormController formController : cachedFormControllers) {
FormScope scope = formController.getFormScope();
scope.put(sv);
}
}
} else if (persist.getAncestor(IRepository.FORMS) != null) {
final Form form = (Form) persist.getAncestor(IRepository.FORMS);
if (form != null && form.isFormComponent().booleanValue()) {
// if the changed form is a reference form we need to check if that is referenced by a loaded form..
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
for (IFormController fc : cachedFormControllers) {
fc.getForm().acceptVisitor(new IPersistVisitor() {
@Override
public Object visit(IPersist o) {
if (o instanceof WebComponent) {
WebComponent wc = (WebComponent) o;
WebObjectSpecification spec = FormTemplateGenerator.getWebObjectSpecification(wc);
Collection<PropertyDescription> properties = spec != null ? spec.getProperties(FormComponentPropertyType.INSTANCE) : null;
if (properties != null && properties.size() > 0) {
Form persistForm = (Form) wc.getAncestor(IRepository.FORMS);
for (PropertyDescription pd : properties) {
Form frm = FormComponentPropertyType.INSTANCE.getForm(wc.getProperty(pd.getName()), clientState.getFlattenedSolution());
if (frm != null && (form.equals(frm) || FlattenedForm.hasFormInHierarchy(frm, form) || isReferenceFormUsedInForm(clientState, form, frm)) && !formsUpdated.contains(persistForm)) {
formsUpdated.add(persistForm);
List<IFormController> cfc = clientState.getFormManager().getCachedFormControllers(persistForm);
for (IFormController formController : cfc) {
formsToReload.add(formController);
}
}
}
}
}
return IPersistVisitor.CONTINUE_TRAVERSAL;
}
});
}
} else if (!formsUpdated.contains(form)) {
formsUpdated.add(form);
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers(form);
for (IFormController formController : cachedFormControllers) {
formsToReload.add(formController);
}
}
if (persist instanceof Form && clientState.getFormManager() instanceof DebugUtils.DebugUpdateFormSupport) {
((DebugUtils.DebugUpdateFormSupport) clientState.getFormManager()).updateForm((Form) persist);
}
} else if (persist instanceof ScriptCalculation) {
ScriptCalculation sc = (ScriptCalculation) persist;
if (((RemoteDebugScriptEngine) clientState.getScriptEngine()).recompileScriptCalculation(sc)) {
List<String> al = new ArrayList<String>();
al.add(sc.getDataProviderID());
try {
String dataSource = clientState.getFoundSetManager().getDataSource(sc.getTable());
((FoundSetManager) clientState.getFoundSetManager()).getRowManager(dataSource).clearCalcs(null, al);
((FoundSetManager) clientState.getFoundSetManager()).flushSQLSheet(dataSource);
} catch (Exception e) {
Debug.error(e);
}
}
// if (clientState instanceof DebugJ2DBClient)
// {
// ((DebugJ2DBClient)clientState).clearUserWindows(); no need for this as window API was refactored and it allows users to clean up dialogs
// }
} else if (persist instanceof Relation) {
((FoundSetManager) clientState.getFoundSetManager()).flushSQLSheet((Relation) persist);
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
try {
String primary = ((Relation) persist).getPrimaryDataSource();
for (IFormController formController : cachedFormControllers) {
if (primary.equals(formController.getDataSource())) {
final IFormController finalController = formController;
final Relation finalRelation = (Relation) persist;
formController.getForm().acceptVisitor(new IPersistVisitor() {
@Override
public Object visit(IPersist o) {
if (o instanceof Tab && Utils.equalObjects(finalRelation.getName(), ((Tab) o).getRelationName())) {
formsToReload.add(finalController);
return o;
}
if (o instanceof Field && ((Field) o).getValuelistID() > 0) {
ValueList vl = clientState.getFlattenedSolution().getValueList(((Field) o).getValuelistID());
if (vl != null && Utils.equalObjects(finalRelation.getName(), vl.getRelationName())) {
formsToReload.add(finalController);
return o;
}
}
if (o instanceof WebComponent) {
WebComponent webComponent = (WebComponent) o;
WebObjectSpecification spec = specProviderState == null ? null : specProviderState.getWebComponentSpecification(webComponent.getTypeName());
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(RelationPropertyType.INSTANCE);
for (PropertyDescription pd : properties) {
if (Utils.equalObjects(webComponent.getFlattenedJson().opt(pd.getName()), finalRelation.getName())) {
formsToReload.add(finalController);
return o;
}
}
}
}
return CONTINUE_TRAVERSAL;
}
});
}
}
} catch (Exception e) {
Debug.error(e);
}
} else if (persist instanceof ValueList) {
ComponentFactory.flushValueList(clientState, (ValueList) persist);
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
for (IFormController formController : cachedFormControllers) {
final IFormController finalController = formController;
final ValueList finalValuelist = (ValueList) persist;
formController.getForm().acceptVisitor(new IPersistVisitor() {
@Override
public Object visit(IPersist o) {
if (o instanceof Field && ((Field) o).getValuelistID() > 0 && ((Field) o).getValuelistID() == finalValuelist.getID()) {
formsToReload.add(finalController);
return o;
}
if (o instanceof WebComponent) {
WebComponent webComponent = (WebComponent) o;
WebObjectSpecification spec = specProviderState == null ? null : specProviderState.getWebComponentSpecification(webComponent.getTypeName());
if (spec != null) {
Collection<PropertyDescription> properties = spec.getProperties(ValueListPropertyType.INSTANCE);
for (PropertyDescription pd : properties) {
if (Utils.equalObjects(webComponent.getFlattenedJson().opt(pd.getName()), finalValuelist.getUUID().toString())) {
formsToReload.add(finalController);
return o;
}
}
}
}
return CONTINUE_TRAVERSAL;
}
});
}
} else if (persist instanceof Style) {
ComponentFactory.flushStyle(null, ((Style) persist));
List<IFormController> cachedFormControllers = clientState.getFormManager().getCachedFormControllers();
String styleName = ((Style) persist).getName();
for (IFormController formController : cachedFormControllers) {
if (styleName.equals(formController.getForm().getStyleName())) {
formsToReload.add(formController);
}
}
}
}
return new Set[] { scopesToReload, formsToReload };
}
Aggregations