use of com.servoy.j2db.server.ngclient.INGClientWindow in project servoy-client by Servoy.
the class RuntimeWebComponent method isApiFunctionEnabled.
protected boolean isApiFunctionEnabled(String functionName) {
boolean isLocationOrSize = "getLocationX".equals(functionName) || "getLocationY".equals(functionName) || "getWidth".equals(functionName) || "getHeight".equals(functionName);
if (isLocationOrSize) {
// if parent form not visible, don't call api, let it get from the model on the server
Container parent = component.getParent();
while (parent != null) {
if (parent instanceof WebFormUI) {
boolean isFormVisible = false;
IWindow currentWindow = CurrentWindow.safeGet();
if (currentWindow instanceof INGClientWindow) {
isFormVisible = ((INGClientWindow) currentWindow).hasForm(parent.getName());
}
if (isFormVisible) {
// it is reported to be still on the client
// but do check also if it is not about to be hidden, by having
// formVisible already set to false in the controller
isFormVisible = ((WebFormUI) parent).getController().isFormVisible();
}
if (!isFormVisible) {
return false;
}
// if this form is in designer mode then it has to go to the client to get the current size/location
if (((WebFormUI) parent).getController().getDesignModeCallbacks() != null)
return true;
break;
}
parent = parent.getParent();
}
// if it is not table view (it can have columns moved/resize) and not anchored, no need to call api, let it get from the model on the server
FormElement fe = component.getFormElement();
if (fe.isLegacy() && fe.getPersistIfAvailable() instanceof ISupportAnchors && (fe.getForm().getView() != FormController.TABLE_VIEW && fe.getForm().getView() != FormController.LOCKED_TABLE_VIEW)) {
// ((ISupportAnchors)fe.getPersistIfAvailable()).getAnchors();
int anchor = Utils.getAsInteger(component.getProperty(StaticContentSpecLoader.PROPERTY_ANCHORS.getPropertyName()));
if ((anchor == 0 || anchor == (IAnchorConstants.NORTH + IAnchorConstants.WEST))) {
return false;
}
}
}
return true;
}
use of com.servoy.j2db.server.ngclient.INGClientWindow in project servoy-client by Servoy.
the class WebFormController method destroy.
@Override
public void destroy() {
if (isFormVisible() && application.isSolutionLoaded()) {
destroyOnHide = true;
} else {
try {
unload();
if (formUI != null) {
formUI.destroy();
formUI = null;
}
super.destroy();
IWindow window = CurrentWindow.safeGet();
if (window instanceof INGClientWindow && application.isSolutionLoaded()) {
((INGClientWindow) window).destroyForm(getName());
}
if (getBasicFormManager() != null)
getBasicFormManager().removeFormController(this);
} finally {
application.getFlattenedSolution().deregisterLiveForm(form, namedInstance);
}
}
}
use of com.servoy.j2db.server.ngclient.INGClientWindow in project servoy-client by Servoy.
the class FormPropertyType method toJSON.
@Override
public JSONWriter toJSON(JSONWriter writer, String key, Object sabloValue, PropertyDescription pd, DataConversion clientConversion, IBrowserConverterContext dataConverterContext) throws JSONException {
if (key != null) {
writer.key(key);
}
String formName = null;
if (sabloValue instanceof String) {
formName = (String) sabloValue;
if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof IContextProvider) {
FlattenedSolution flattenedSolution = ((IContextProvider) dataConverterContext.getWebObject()).getDataConverterContext().getApplication().getFlattenedSolution();
Form form = flattenedSolution.getForm(formName);
// form name
if (form == null) {
form = (Form) flattenedSolution.searchPersist((String) sabloValue);
}
if (form != null) {
formName = form.getName();
}
}
} else if (sabloValue instanceof CharSequence) {
formName = ((CharSequence) sabloValue).toString();
} else if (sabloValue instanceof Form) {
formName = ((Form) sabloValue).getName();
} else if (sabloValue instanceof FormController) {
formName = ((FormController) sabloValue).getName();
} else if (sabloValue instanceof FormScope) {
formName = ((FormScope) sabloValue).getFormController().getName();
} else {
formName = null;
Debug.error("Cannot handle unknown value for Form type: " + sabloValue);
}
writer.value(formName);
if (CurrentWindow.get() instanceof INGClientWindow) {
// if this is a web component that triggered it, register to only allow this form for that component
if (dataConverterContext != null && dataConverterContext.getWebObject() instanceof WebFormComponent)
((INGClientWindow) CurrentWindow.get()).registerAllowedForm(formName, ((WebFormComponent) dataConverterContext.getWebObject()).getFormElement());
else
// else register it for null then this form is allowed globally (a form in dialog of popup)
((INGClientWindow) CurrentWindow.get()).registerAllowedForm(formName, null);
}
return writer;
}
use of com.servoy.j2db.server.ngclient.INGClientWindow in project servoy-client by Servoy.
the class FormPropertyType method toTemplateJSONValue.
@Override
public JSONWriter toTemplateJSONValue(JSONWriter writer, String key, Object formElementValue, PropertyDescription pd, DataConversion browserConversionMarkers, FormElementContext formElementContext) throws JSONException {
if (formElementValue == null)
return writer;
FlattenedSolution fs = formElementContext.getFlattenedSolution();
Form form = null;
if (formElementValue instanceof Integer) {
form = fs.getForm(((Integer) formElementValue).intValue());
} else if (formElementValue instanceof String || formElementValue instanceof UUID) {
form = fs.getForm(formElementValue.toString());
if (form == null) {
form = (Form) fs.searchPersist(formElementValue.toString());
}
}
if (form != null) {
writer.key(key);
writer.value(form.getName());
if (CurrentWindow.safeGet() instanceof INGClientWindow) {
((INGClientWindow) CurrentWindow.get()).registerAllowedForm(form.getName(), formElementContext.getFormElement());
}
}
return writer;
}
use of com.servoy.j2db.server.ngclient.INGClientWindow in project servoy-client by Servoy.
the class WebFormController method recreateUI.
@Override
public boolean recreateUI() {
Form oldForm = form;
// update flattened form reference cause now we probably need to use a SM modified version
Form f = application.getFlattenedSolution().getForm(form.getName());
// don't use cached, make sure it updates the cache
form = application.getFlattenedSolution().getFlattenedForm(f, false);
INGClientWindow allWindowsProxy = new NGClientWebsocketSessionWindows(getApplication().getWebsocketSession());
if (allWindowsProxy.hasFormChangedSinceLastSendToClient(form, getName())) {
// 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 a 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> invokeLaterRunnables = new ArrayList<Runnable>();
notifyVisibleOnChildren(false, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
tabSequence = null;
f = application.getFlattenedSolution().getForm(form.getName());
form = application.getFlattenedSolution().getFlattenedForm(f);
getFormUI().init();
getApplication().recreateForm(form, getName());
if (isFormVisible) {
invokeLaterRunnables = new ArrayList<Runnable>();
notifyVisibleOnChildren(true, invokeLaterRunnables);
Utils.invokeLater(application, invokeLaterRunnables);
if (getDesignModeCallbacks() != null) {
// this form is in design mode, let the client know the ui is created:
RuntimeWebComponent[] components = getWebComponentElements();
String[] names = new String[components.length];
for (int i = 0; i < names.length; i++) {
names[i] = components[i].getComponent().getName();
}
getApplication().getWebsocketSession().getClientService(ClientDesignService.NAME).executeAsyncServiceCall("recreateUI", new Object[] { getName(), names });
}
}
} else {
// in case it's not already loaded on client side - so we can't rely on endpoint URL differeces - but it is modified by Solution Model and recreateUI is called, it's formUI needs to reinitialize as well
if ((oldForm != form || application.isInDeveloper()) && !allWindowsProxy.hasForm(getName())) {
tabSequence = null;
getFormUI().init();
Debug.trace("RecreateUI on form " + getName() + " only recreated form ui on server, because that form is not present client-side...");
} else
Debug.trace("RecreateUI on form " + getName() + " was ignored because that form was not changed or at least not since last being sent to client...");
}
application.getFlattenedSolution().deregisterLiveForm(form, namedInstance);
application.getFlattenedSolution().registerLiveForm(form, namedInstance);
return true;
}
Aggregations