use of com.servoy.j2db.scripting.IScriptable in project servoy-client by Servoy.
the class WebCellAdapter method valueChanged.
public void valueChanged(ModificationEvent e) {
MainPage mp = view.findParent(MainPage.class);
if (mp != null)
mp.touch();
IRecord record = e.getRecord();
Iterator iterator = ((MarkupContainer) view.getTable()).iterator();
while (iterator.hasNext()) {
Object next = iterator.next();
if (next instanceof ListItem) {
ListItem li = (ListItem) next;
Object modelObject = li.getModelObject();
if (record == null || modelObject == record) {
boolean hasOnRender = false;
Iterator iterator2 = li.iterator();
while (iterator2.hasNext()) {
ArrayList<Object> cellDisplays = new ArrayList<Object>();
Object cell = iterator2.next();
cell = CellContainer.getContentsForCell((Component) cell);
if (cell instanceof WebCellBasedViewListViewItem) {
Iterator listItemIte = ((WebCellBasedViewListViewItem) cell).iterator();
while (listItemIte.hasNext()) {
Object listItemDisplay = listItemIte.next();
if (listItemDisplay instanceof WrapperContainer) {
listItemDisplay = ((WrapperContainer) listItemDisplay).getDelegate();
}
cellDisplays.add(listItemDisplay);
}
} else {
cellDisplays.add(cell);
}
for (Object cellDisplay : cellDisplays) {
if (cellDisplay instanceof IProviderStylePropertyChanges && cellDisplay instanceof IDisplayData && ((IDisplayData) cellDisplay).getDataProviderID() == dataprovider) {
// only test if it is not already changed
view.checkForValueChanges(cellDisplay);
// do fire on render on all components for record change
if (cellDisplay instanceof ISupportOnRender && cellDisplay instanceof IScriptableProvider) {
IScriptable so = ((IScriptableProvider) cellDisplay).getScriptObject();
if (so instanceof AbstractRuntimeRendersupportComponent && ((ISupportOnRenderCallback) so).getRenderEventExecutor().hasRenderCallback()) {
String componentDataproviderID = ((AbstractRuntimeRendersupportComponent) so).getDataProviderID();
if (record != null || (e.getName() != null && e.getName().equals(componentDataproviderID))) {
((ISupportOnRender) cellDisplay).fireOnRender(true);
hasOnRender = true;
}
}
}
}
}
}
if (record != null || (!hasOnRender && !canChangeValue(e)))
break;
}
}
}
}
use of com.servoy.j2db.scripting.IScriptable in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method createComponents.
private void createComponents(final IApplication app, final Form form, final AbstractBase view, final IDataProviderLookup dataProviderLookup, final IScriptExecuter el, final int viewStartY, final int viewEndY, final ItemAdd output) {
List<IPersist> elements = ComponentFactory.sortElementsOnPositionAndGroup(view.getAllObjectsAsList());
int startX = 0;
for (int i = 0; i < elements.size(); i++) {
IPersist element = elements.get(i);
if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
if (!isListViewMode()) {
if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
if (isInView(cellview, ((GraphicalComponent) element).getLabelFor())) {
labelsFor.put(((GraphicalComponent) element).getLabelFor(), element);
}
continue;
}
}
Point l = ((IFormElement) element).getLocation();
if (l == null) {
// unknown where to add
continue;
}
if (l.y >= viewStartY && l.y < viewEndY) {
IComponent c = ComponentFactory.createComponent(app, form, element, dataProviderLookup, el, false);
if (cellview instanceof Portal && c instanceof IScriptableProvider) {
IScriptable s = ((IScriptableProvider) c).getScriptObject();
if (s instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) s).getRenderEventExecutor() != null)
ComponentFactoryHelper.addPortalOnRenderCallback((Portal) cellview, ((ISupportOnRenderCallback) s).getRenderEventExecutor(), element, fc != null ? fc.getScriptExecuter() : null);
}
initializeComponent((Component) c, view, element);
output.add(element, (Component) c);
if (!isListViewMode()) {
// reset location.x as defined in this order, elements are ordered by location.x which is modified in drag-n-drop
Point loc = c.getLocation();
if (loc != null) {
c.setLocation(new Point(startX, loc.y));
}
Dimension csize = c.getSize();
startX += (csize != null) ? csize.width : ((IFormElement) element).getSize().width;
}
}
}
}
}
use of com.servoy.j2db.scripting.IScriptable in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method initializeComponent.
@SuppressWarnings("nls")
private void initializeComponent(final Component c, AbstractBase view, IPersist element) {
if (dal != null && dal.isDestroyed()) {
Debug.error("Trying to initialize a component: " + c + " of " + view + " element: " + element + " that is in a destroyed tableview", new RuntimeException());
return;
}
if (// Don't know any other place for this
view instanceof Portal && c instanceof IDisplayData) {
String id = ((IDisplayData) c).getDataProviderID();
if (id != null && !ScopesUtils.isVariableScope(id) && id.startsWith(((Portal) view).getRelationName() + '.')) {
((IDisplayData) c).setDataProviderID(id.substring(((Portal) cellview).getRelationName().length() + 1));
}
}
if (!isListViewMode() && c instanceof WebDataCheckBox) {
// $NON-NLS-1$
((WebDataCheckBox) c).setText("");
}
if (element != null) {
// apply to this cell the state of the columnIdentifier IComponent, do keep the location that is set by the tableview when creating these components the first time.
// for listview this is the location to use.
Point loc = ((IComponent) c).getLocation();
int height = ((IComponent) c).getSize().height;
PropertyCopy.copyElementProps((IComponent) elementToColumnIdentifierComponent.get(element), (IComponent) c);
if (!isListViewMode()) {
((IComponent) c).setLocation(loc);
// it shouldn't be possible to change the height
if (c instanceof IScriptableProvider) {
IScriptable so = ((IScriptableProvider) c).getScriptObject();
if (so instanceof IRuntimeComponent) {
IRuntimeComponent ic = (IRuntimeComponent) so;
if (ic.getHeight() != height) {
ic.setSize(ic.getWidth(), height);
}
}
}
}
} else {
// $NON-NLS-1$
Debug.log("Cannot find the IPersist element for cell " + c.getMarkupId());
}
if (c instanceof IDisplayData) {
IDisplayData cdd = (IDisplayData) c;
if (!(dal != null && dal.getFormScope() != null && cdd.getDataProviderID() != null && // skip for form variables
dal.getFormScope().get(cdd.getDataProviderID()) != Scriptable.NOT_FOUND)) {
cdd.setValidationEnabled(validationEnabled);
}
} else if (c instanceof IDisplayRelatedData) {
((IDisplayRelatedData) c).setValidationEnabled(validationEnabled);
} else if (c instanceof IServoyAwareBean) {
((IServoyAwareBean) c).setValidationEnabled(validationEnabled);
}
addClassToCellComponent(c);
if (// the check could be extended against IDelegate<?>
c instanceof WebDataCompositeTextField) {
Object delegate = ((WebDataCompositeTextField) c).getDelegate();
if (delegate instanceof Component) {
// make sure that this class is added accordingly in TemplateGenerator as a style selector containing relevant properties
addClassToCellComponent((Component) delegate);
}
}
if (c instanceof ISupportValueList) {
ISupportValueList idVl = (ISupportValueList) elementToColumnIdentifierComponent.get(element);
IValueList list;
if (idVl != null && (list = idVl.getValueList()) != null) {
ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
((ISupportValueList) c).setValueList(list);
}
}
}
applyClientProperties(c, element);
}
use of com.servoy.j2db.scripting.IScriptable in project servoy-client by Servoy.
the class WebEventExecutor method handleEvent.
/**
* @param type
* @param target
* @param comp
* @param webModifiers
* @param mouseLocation
* @param page
*/
private void handleEvent(EventType type, AjaxRequestTarget target, Component comp, int webModifiers, Point mouseLocation, Point absoluteMouseLocation, Page page) {
// process model changes from web components
WebClientSession.get().getWebClient().executeEvents();
Component renderScriptProvider = comp;
ISupplyFocusChildren<?> componentWithChildren = renderScriptProvider.findParent(ISupplyFocusChildren.class);
if (componentWithChildren != null)
renderScriptProvider = (Component) componentWithChildren;
if (renderScriptProvider instanceof WrapperContainer)
renderScriptProvider = ((WrapperContainer) renderScriptProvider).getDelegate();
RenderEventExecutor renderEventExecutor = null;
if (renderScriptProvider instanceof IScriptableProvider) {
IScriptable s = ((IScriptableProvider) renderScriptProvider).getScriptObject();
if (s instanceof ISupportOnRenderCallback) {
renderEventExecutor = ((ISupportOnRenderCallback) s).getRenderEventExecutor();
if (!renderEventExecutor.hasRenderCallback())
renderEventExecutor = null;
}
}
if (type == EventType.focusGained || type == EventType.action || type == EventType.focusLost) {
if (type == EventType.focusGained || type == EventType.action) {
((MainPage) page).setFocusedComponent(comp);
} else {
((MainPage) page).setFocusedComponent(null);
}
if (renderEventExecutor != null) {
renderEventExecutor.setRenderStateChanged();
// if component's onRender did not change any properties, don't add it to the target
if (renderScriptProvider instanceof ISupportOnRender && WebOnRenderHelper.doRender((ISupportOnRender) renderScriptProvider)) {
target.addComponent(renderScriptProvider);
}
}
}
if (type == EventType.focusLost || setSelectedIndex(comp, target, convertModifiers(webModifiers), type == EventType.focusGained || type == EventType.action)) {
if (skipFireFocusGainedCommand && type.equals(JSEvent.EventType.focusGained)) {
skipFireFocusGainedCommand = false;
} else {
switch(type) {
case action:
fireActionCommand(false, comp, convertModifiers(webModifiers), mouseLocation);
break;
case focusGained:
fireEnterCommands(false, comp, convertModifiers(webModifiers));
break;
case focusLost:
fireLeaveCommands(comp, false, convertModifiers(webModifiers));
break;
case doubleClick:
fireDoubleclickCommand(false, comp, convertModifiers(webModifiers), mouseLocation);
break;
case rightClick:
// if right click, mark the meta flag as it is on the smart client
fireRightclickCommand(false, comp, convertModifiers(webModifiers | 8), null, mouseLocation, absoluteMouseLocation);
break;
case none:
case dataChange:
case form:
case onDrag:
case onDragOver:
case onDrop:
}
}
}
}
use of com.servoy.j2db.scripting.IScriptable in project servoy-client by Servoy.
the class FormController method getJSApplicationNames.
/**
* @param src
* @param function
* @param useFormAsEventSourceEventually
*/
@Override
protected FormAndComponent getJSApplicationNames(Object source, Function function, boolean useFormAsEventSourceEventually) {
Object src = source;
if (src == null) {
Object window = application.getRuntimeWindowManager().getCurrentWindowWrappedObject();
if (window != null) {
src = ((Window) window).getFocusOwner();
while (src != null && !(src instanceof IComponent)) {
src = ((Component) src).getParent();
}
// Test if this component really comes from the the controllers UI.
if (src instanceof Component) {
Container container = ((Component) src).getParent();
while (container != null && !(container instanceof IFormUIInternal<?>)) {
container = container.getParent();
}
if (container != getFormUI()) {
// if not then this is not the trigger element for this form.
src = null;
}
}
}
}
Scriptable thisObject = null;
if (src instanceof IComponent && src instanceof IScriptableProvider) {
// $NON-NLS-1$
Object esObj = formScope.get("elements", formScope);
if (esObj != Scriptable.NOT_FOUND) {
ElementScope es = (ElementScope) esObj;
String name = ((IComponent) src).getName();
if (name != null && name.length() != 0) {
Object o = es.get(name, es);
if (o instanceof Scriptable) {
thisObject = (Scriptable) o;
}
}
if (thisObject == null) {
if (name == null || name.length() == 0) {
name = ComponentFactory.WEB_ID_PREFIX + System.currentTimeMillis();
// Check Web components always have a name! Because name can't be set
((IComponent) src).setName(name);
}
IScriptable scriptObject = ((IScriptableProvider) src).getScriptObject();
if (scriptObject != null) {
try {
Context.enter();
JavaMembers jm = ScriptObjectRegistry.getJavaMembers(scriptObject.getClass(), ScriptableObject.getTopLevelScope(formScope));
thisObject = new NativeJavaObject(formScope, scriptObject, jm);
es.setLocked(false);
es.put(name, es, thisObject);
es.setLocked(true);
} finally {
Context.exit();
}
}
}
}
}
if (src == null && useFormAsEventSourceEventually)
src = formScope;
return new FormAndComponent(src, getName());
}
Aggregations