use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class DisplaysAdapter method valueChanged.
/*
* _____________________________________________________________ JavaScriptModificationlistener
*/
public void valueChanged(ModificationEvent e) {
if (!adjusting) {
try {
adjusting = true;
Object obj = null;
boolean formVariable = false;
if (dataProviderID != null) {
if (dal.getFormScope().has(dataProviderID, dal.getFormScope())) {
formVariable = true;
obj = dal.getFormScope().get(dataProviderID);
} else if (record != null) {
obj = record.getValue(dataProviderID);
if (obj == Scriptable.NOT_FOUND) {
obj = null;
}
// have to do this because for calcs in calcs. Better was to had a check for previous value.
fireModificationEvent(obj);
}
}
// do not set value for form variable except when really changed
if (!formVariable || dataProviderID == null || dataProviderID.equals(e.getName())) {
setValueToDisplays(obj);
}
} finally {
adjusting = false;
}
}
// do fire on render on all components for record change
for (IDisplayData displayData : displays) {
if (displayData instanceof ISupportOnRender && displayData instanceof IScriptableProvider) {
IScriptable so = ((IScriptableProvider) displayData).getScriptObject();
if (so instanceof AbstractRuntimeRendersupportComponent && ((ISupportOnRenderCallback) so).getRenderEventExecutor().hasRenderCallback()) {
String componentDataproviderID = ((AbstractRuntimeRendersupportComponent) so).getDataProviderID();
if (e.getRecord() != null || (e.getName() != null && e.getName().equals(componentDataproviderID))) {
((ISupportOnRender) displayData).fireOnRender(true);
}
}
}
}
}
use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class DataAdapterList method setDataRendererComponentsRenderState.
public static void setDataRendererComponentsRenderState(IDataRenderer dataRenderer, IRecordInternal rec) {
if (rec != null) {
Object[] recordStatus = null;
if (dataRenderer.getOnRenderComponent().getRenderEventExecutor().hasRenderCallback()) {
recordStatus = getRecordIndexAndSelectStatus(rec);
dataRenderer.getOnRenderComponent().getRenderEventExecutor().setRenderState(rec, ((Integer) recordStatus[0]).intValue(), ((Boolean) recordStatus[1]).booleanValue(), true);
}
@SuppressWarnings("rawtypes") Iterator compIte = dataRenderer.getComponentIterator();
Object comp;
while (compIte.hasNext()) {
comp = compIte.next();
if (comp instanceof IScriptableProvider) {
IScriptable scriptable = ((IScriptableProvider) comp).getScriptObject();
if (scriptable instanceof ISupportOnRenderCallback) {
RenderEventExecutor rendererEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
if (rendererEventExecutor != null && rendererEventExecutor.hasRenderCallback()) {
if (recordStatus == null)
recordStatus = getRecordIndexAndSelectStatus(rec);
rendererEventExecutor.setRenderState(rec, ((Integer) recordStatus[0]).intValue(), ((Boolean) recordStatus[1]).booleanValue(), true);
}
}
}
}
}
}
use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class PropertyCopy method copyElementProps.
public static void copyElementProps(IComponent org, IComponent copy) {
if (org == null || copy == null)
return;
// if (org instanceof IDelegate && copy instanceof IDelegate)
// {
// org = (JComponent)((IDelegate)org).getDelegate();
// copy = (JComponent) ((IDelegate)copy).getDelegate();
// }
copy.setLocation(org.getLocation());
copy.setSize(org.getSize());
copy.setBackground(org.getBackground());
copy.setForeground(org.getForeground());
copy.setToolTipText(org.getToolTipText());
copy.setComponentVisible(org.isVisible());
copy.setComponentEnabled(org.isEnabled());
copy.setOpaque(org.isOpaque());
copy.setFont(org.getFont());
if (org instanceof ILabel && copy instanceof ILabel) {
((ILabel) copy).setMediaIcon(((ILabel) org).getMediaIcon());
((ILabel) copy).setText(((ILabel) org).getText());
}
if (org instanceof IFieldComponent && copy instanceof IFieldComponent) {
((IFieldComponent) copy).setEditable(((IFieldComponent) org).isEditable());
}
if (org instanceof IScriptableProvider && copy instanceof IScriptableProvider) {
IScriptable source = ((IScriptableProvider) org).getScriptObject();
IScriptable destination = ((IScriptableProvider) copy).getScriptObject();
if (source instanceof IFormatScriptComponent && destination instanceof IFormatScriptComponent) {
((IFormatScriptComponent) destination).setComponentFormat(((IFormatScriptComponent) source).getComponentFormat());
}
if (source instanceof HasRuntimeReadOnly && destination instanceof HasRuntimeReadOnly) {
((HasRuntimeReadOnly) destination).setReadOnly(((HasRuntimeReadOnly) source).isReadOnly());
}
if (source instanceof HasRuntimeVisible && destination instanceof HasRuntimeVisible) {
((HasRuntimeVisible) destination).setVisible(((HasRuntimeVisible) source).isVisible());
}
if (source instanceof HasRuntimeImage && destination instanceof HasRuntimeImage) {
String imageURL = ((HasRuntimeImage) source).getImageURL();
if (imageURL != null) {
// only copy if explicitly set with a url
((HasRuntimeImage) destination).setImageURL(imageURL);
}
String rolloverImageURL = ((HasRuntimeImage) source).getRolloverImageURL();
if (rolloverImageURL != null) {
// only copy if explicitly set with a url
((HasRuntimeImage) destination).setRolloverImageURL(rolloverImageURL);
}
}
if (source instanceof IRuntimeTabPaneAlike && destination instanceof IRuntimeTabPaneAlike) {
// keep active tab when printing
((IRuntimeTabPaneAlike) destination).setTabIndex(((IRuntimeTabPaneAlike) source).getTabIndex());
}
}
if (org instanceof IProviderStylePropertyChanges && copy instanceof IProviderStylePropertyChanges) {
((IProviderStylePropertyChanges) copy).getStylePropertyChanges().setChanges(((IProviderStylePropertyChanges) org).getStylePropertyChanges().getChanges());
}
}
use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class DataRenderer method fireDataRendererOnRender.
private void fireDataRendererOnRender() {
dataRendererOnRenderWrapper.getRenderEventExecutor().fireOnRender(hasFocus());
@SuppressWarnings("rawtypes") Iterator compIte = getComponentIterator();
Object comp;
while (compIte.hasNext()) {
comp = compIte.next();
if (comp instanceof IScriptableProvider && !(comp instanceof IDisplayData) && !(comp instanceof IDisplayRelatedData)) {
IScriptable scriptable = ((IScriptableProvider) comp).getScriptObject();
if (scriptable instanceof ISupportOnRenderCallback) {
RenderEventExecutor rendererEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
boolean hasFocus = (comp instanceof Component) ? ((Component) comp).hasFocus() : false;
rendererEventExecutor.fireOnRender(hasFocus);
}
}
}
}
use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class SwingForm method registerComponentsToScope.
private int registerComponentsToScope(Scriptable fs, ElementScope es, int counter, Object[] comps, Object[] compsRenderer, Component controller, Map<String, Object[]> hmChildrenJavaMembers) {
if (comps != null) {
for (int j = 0; j < comps.length; j++) {
Object comp = comps[j];
if (comp instanceof PortalComponent) {
PortalComponent portal = (PortalComponent) comp;
counter = registerComponentsToScope(fs, es, counter, portal.getEditorComponents(), portal.getRendererComponents(), portal, hmChildrenJavaMembers);
}
String name = null;
if (comp instanceof IComponent) {
name = ((IComponent) comp).getName();
} else if (comp instanceof Component) {
name = ((Component) comp).getName();
}
Object obj = comp;
if (comp instanceof InvisibleBean) {
obj = ((InvisibleBean) comp).getDelegate();
} else if (comp instanceof VisibleBean) {
obj = ((VisibleBean) comp).getDelegate();
}
String groupName = FormElementGroup.getName((String) formController.getComponentProperty(comp, ComponentFactory.GROUPID_COMPONENT_PROPERTY));
if (obj instanceof IScriptableProvider)
obj = ((IScriptableProvider) obj).getScriptObject();
IRuntimeComponent baseMethodsObj = null;
if (obj instanceof IRuntimeComponent) {
baseMethodsObj = (IRuntimeComponent) obj;
}
JavaMembers jm = ScriptObjectRegistry.getJavaMembers(obj.getClass(), ScriptableObject.getTopLevelScope(fs));
// $NON-NLS-1$
boolean named = name != null && !name.equals("") && !name.startsWith(ComponentFactory.WEB_ID_PREFIX);
if (groupName != null || named) {
Object obj2 = null;
if (compsRenderer != null) {
obj2 = compsRenderer[j];
if (obj2 instanceof InvisibleBean) {
obj2 = ((InvisibleBean) obj2).getDelegate();
}
}
try {
Scriptable s = null;
if (obj2 != null) {
if (obj2 instanceof IScriptableProvider)
obj2 = ((IScriptableProvider) obj2).getScriptObject();
NativeJavaObject s2 = new NativeJavaObject(fs, obj2, jm);
s = new TwoNativeJavaObject(fs, obj, s2, jm, controller);
// group properties have to be set to both
if (groupName != null && obj2 instanceof IRuntimeComponent) {
if (baseMethodsObj == null) {
baseMethodsObj = (IRuntimeComponent) obj2;
} else {
RuntimeGroup runtimeGroup = new RuntimeGroup(baseMethodsObj.getName());
runtimeGroup.addScriptBaseMethodsObj(baseMethodsObj);
runtimeGroup.addScriptBaseMethodsObj((IRuntimeComponent) obj2);
baseMethodsObj = runtimeGroup;
}
}
} else {
s = new NativeJavaObject(fs, obj, jm);
}
if (named) {
es.put(name, fs, s);
es.put(counter++, fs, s);
hmChildrenJavaMembers.put(name, new Object[] { jm, obj });
}
if (groupName != null) {
Object group = es.get(groupName, fs);
if (group == Scriptable.NOT_FOUND) {
group = new NativeJavaObject(fs, new RuntimeGroup(groupName), ScriptObjectRegistry.getJavaMembers(RuntimeGroup.class, ScriptableObject.getTopLevelScope(fs)));
es.put(groupName, fs, group);
es.put(counter++, fs, group);
}
if (baseMethodsObj != null && group instanceof NativeJavaObject && ((NativeJavaObject) group).unwrap() instanceof RuntimeGroup) {
((RuntimeGroup) (((NativeJavaObject) group).unwrap())).addScriptBaseMethodsObj(baseMethodsObj);
}
}
} catch (Throwable ex) {
// incase classdefnot founds are thrown for beans,applets/plugins
Debug.error(ex);
}
}
}
}
return counter;
}
Aggregations