use of com.servoy.j2db.persistence.WebComponent in project servoy-client by Servoy.
the class JSBaseContainer method removeWebComponent.
/**
* Removes a JSWebComponent that has the specified name. Returns true if removal was successful, false otherwise.
*
* @sample
* var form = solutionModel.getForm('myform');
* form.removeWebComponent('mybean')
*
* @param name the specified name of the JSWebComponent to be removed
*
* @return true if the JSWebComponent has been removed; false otherwise
*/
@ServoyClientSupport(mc = false, ng = true, wc = false, sc = false)
@JSFunction
public boolean removeWebComponent(String name) {
if (name == null)
return false;
checkModification();
Iterator<WebComponent> webComponents = getContainer().getWebComponents();
while (webComponents.hasNext()) {
WebComponent webComponent = webComponents.next();
if (name.equals(webComponent.getName())) {
getContainer().removeChild(webComponent);
return true;
}
}
return false;
}
use of com.servoy.j2db.persistence.WebComponent in project servoy-client by Servoy.
the class JSNGWebComponent method getJSONProperty.
@Override
public Object getJSONProperty(String propertyName) {
WebComponent webComponent = getBaseComponent(false);
JSONObject json = webComponent.getFlattenedJson();
if (json == null)
return Context.getUndefinedValue();
Object value;
WebObjectSpecification spec = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(webComponent.getTypeName());
if (spec != null) {
Pair<PropertyDescription, String> propAndName = getPropertyDescriptionAndName(propertyName, spec);
if (!json.has(propAndName.getRight()) && propAndName.getLeft() != null && propAndName.getLeft().hasDefault()) {
value = propAndName.getLeft().getDefaultValue();
} else {
value = json.opt(propAndName.getRight());
}
value = fromDesignToRhinoValue(value, propAndName.getLeft(), application, this, propertyName);
// JSONArray and JSONObject are automatically wrapped when going to Rhino through ServoyWrapFactory, so no need to treat them specially here
} else {
value = json.opt(propertyName);
}
// so we need to make sure we always return a JSONObject.
if (value instanceof ServoyJSONObject) {
value = new JSONObject((ServoyJSONObject) value, ((ServoyJSONObject) value).keySet().toArray(new String[0]));
} else if (value instanceof ServoyJSONArray) {
ServoyJSONArray sArray = (ServoyJSONArray) value;
JSONArray array = new JSONArray();
for (int i = 0; i < sArray.length(); i++) {
array.put(i, sArray.get(i));
}
value = sArray;
}
return value == null ? Context.getUndefinedValue() : ServoyJSONObject.jsonNullToNull(value);
}
use of com.servoy.j2db.persistence.WebComponent in project servoy-client by Servoy.
the class JSNGWebComponent method isJSONPropertySet.
@Override
public boolean isJSONPropertySet(String propertyName) {
WebComponent webComponent = getBaseComponent(false);
JSONObject json = webComponent.getFlattenedJson();
return json != null && json.has(propertyName);
}
use of com.servoy.j2db.persistence.WebComponent in project servoy-client by Servoy.
the class JSNGWebComponent method resetHandler.
@Override
public void resetHandler(String handlerName) {
WebComponent webComponent = getBaseComponent(false);
WebObjectSpecification spec = WebComponentSpecProvider.getSpecProviderState().getWebComponentSpecification(webComponent.getTypeName());
if (spec != null) {
String name = handlerName;
if (spec.getHandler(name) == null) {
name = name + "MethodID";
}
if (spec.getHandler(name) != null) {
webComponent.clearProperty(name);
getBaseComponent(true).putMethodParameters(name, null, null);
} else {
int i = name.indexOf('.');
if (i > 0) {
String firstPart = name.substring(0, i);
PropertyDescription property = spec.getProperty(firstPart);
if (property != null && property.getType() instanceof IFormComponentType) {
// undefined means remove the property
Object convertedValue = fromRhinoToDesignValue(Context.getUndefinedValue(), property, application, this, handlerName);
webComponent.setProperty(firstPart, convertedValue);
return;
}
}
Debug.log("Error: component " + webComponent.getTypeName() + " does not declare a handler named " + handlerName + ".");
}
}
}
use of com.servoy.j2db.persistence.WebComponent in project servoy-client by Servoy.
the class JSBaseContainer method newWebComponent.
/**
* Creates a new JSWebComponent (spec based component) object on the RESPONSIVE form.
*
* @sample
* var form = solutionModel.newForm('newForm1', 'db:/server1/table1', null, true, 800, 600);
* var container = myForm.getLayoutContainer("row1")
* var bean = container.newWebComponent('bean','mypackage-testcomponent',1);
*
* @param name the specified name of the JSWebComponent object
* @param type the webcomponent name as it appears in the spec
* @param position the position of JSWebComponent object in its parent container
*
* @return a JSWebComponent object
*/
@ServoyClientSupport(mc = false, ng = true, wc = false, sc = false)
@JSFunction
public JSWebComponent newWebComponent(String name, String type, int position) {
checkModification();
try {
AbstractContainer container = getContainer();
Form form = (Form) container.getAncestor(IRepository.FORMS);
if (form.isResponsiveLayout()) {
if (name == null) {
String componentName = type;
int index = componentName.indexOf("-");
if (index != -1) {
componentName = componentName.substring(index + 1);
}
// $NON-NLS-1$//$NON-NLS-2$
componentName = componentName.replaceAll("-", "_");
// $NON-NLS-1$
name = componentName + "_" + id.incrementAndGet();
IJSParent<?> parent = this;
while (!(parent instanceof JSForm)) {
parent = parent.getJSParent();
}
if (parent instanceof JSForm) {
while (findComponent((JSForm) parent, name) != null) {
name = componentName + "_" + id.incrementAndGet();
}
}
}
WebComponent webComponent = container.createNewWebComponent(IdentDocumentValidator.checkName(name), type);
webComponent.setLocation(new Point(position, position));
return createWebComponent(this, webComponent, application, true);
} else {
throw new RuntimeException("Form " + form.getName() + " is not responsive. Cannot create component without specifying the location and size.");
}
} catch (RepositoryException e) {
throw new RuntimeException(e);
}
}
Aggregations