use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class WebForm method registerComponentsToScope.
private int registerComponentsToScope(Scriptable fs, ElementScope es, int counter, Object[] comps, Map<String, Object[]> hmChildrenJavaMembers, Object parent) {
if (comps != null) {
for (Object comp : comps) {
if (comp instanceof WebCellBasedView) {
WebCellBasedView portal = (WebCellBasedView) comp;
counter = registerComponentsToScope(fs, es, counter, portal.getComponents(), hmChildrenJavaMembers, comp);
}
String name = null;
if (comp instanceof WrapperContainer) {
comp = ((WrapperContainer) comp).getDelegate();
}
if (comp instanceof IComponent) {
name = ((IComponent) comp).getName();
} else if (comp instanceof java.awt.Component) {
name = ((java.awt.Component) comp).getName();
}
if (comp instanceof WebImageBeanHolder) {
comp = ((WebImageBeanHolder) comp).getDelegate();
} else if (comp instanceof WebBeanHolder) {
comp = ((WebBeanHolder) comp).getDelegate();
}
String groupName = FormElementGroup.getName((String) formController.getComponentProperty(comp, ComponentFactory.GROUPID_COMPONENT_PROPERTY));
Object scriptable = comp;
if (comp instanceof IScriptableProvider)
scriptable = ((IScriptableProvider) comp).getScriptObject();
JavaMembers jm = ScriptObjectRegistry.getJavaMembers(scriptable.getClass(), ScriptableObject.getTopLevelScope(fs));
// $NON-NLS-1$
boolean named = name != null && !name.equals("") && !name.startsWith(ComponentFactory.WEB_ID_PREFIX);
if (groupName != null || named) {
try {
Scriptable s;
if (parent instanceof WebCellBasedView) {
s = new CellNativeJavaObject(fs, comp, jm, (WebCellBasedView) parent);
} else {
s = new NativeJavaObject(fs, scriptable, jm);
}
if (named) {
es.put(name, fs, s);
es.put(counter++, fs, s);
hmChildrenJavaMembers.put(name, new Object[] { jm, scriptable });
}
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 (scriptable instanceof IRuntimeComponent && group instanceof NativeJavaObject && ((NativeJavaObject) group).unwrap() instanceof RuntimeGroup) {
((RuntimeGroup) (((NativeJavaObject) group).unwrap())).addScriptBaseMethodsObj((IRuntimeComponent) scriptable);
}
}
} catch (Throwable ex) {
// incase classdefnot founds are thrown for beans,applets/plugins
Debug.error(ex);
}
}
}
}
return counter;
}
use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class RecordItemModel method setValue.
/**
* @param obj
* @param dataProviderID
* @param prevValue
*/
public void setValue(Component component, String dataProviderID, Object value) {
Object obj = value;
String compDpid = getDataProviderID(component);
boolean ownComponentsValue = compDpid != null && dataProviderID.endsWith(compDpid);
Object prevValue = null;
if (ownComponentsValue && component instanceof IResolveObject) {
obj = ((IResolveObject) component).resolveRealValue(obj);
}
if (component instanceof IDisplayData) {
obj = Utils.removeJavascripLinkFromDisplay((IDisplayData) component, new Object[] { obj });
}
WebForm webForm = component.findParent(WebForm.class);
IRecordInternal record = (IRecordInternal) RecordItemModel.this.getObject();
// use UI converter to convert from UI value to record value
if (!(record instanceof FindState)) {
obj = ComponentFormat.applyUIConverterFromObject(component, obj, dataProviderID, webForm.getController().getApplication().getFoundSetManager());
}
FormScope fs = webForm.getController().getFormScope();
try {
Pair<String, String> scope = ScopesUtils.getVariableScope(dataProviderID);
if (scope.getLeft() != null) {
if (record == null) {
webForm.getController().getApplication().getScriptEngine().getSolutionScope().getScopesScope().getGlobalScope(scope.getLeft()).put(scope.getRight(), obj);
} else {
// does an additional fire in foundset!
prevValue = record.getParentFoundSet().setDataProviderValue(dataProviderID, obj);
}
} else if (fs.has(dataProviderID, fs)) {
prevValue = fs.get(dataProviderID);
fs.put(dataProviderID, obj);
} else {
if (record != null && record.startEditing()) {
try {
prevValue = record.getValue(dataProviderID);
record.setValue(dataProviderID, obj);
} catch (IllegalArgumentException e) {
Debug.trace(e);
((WebClientSession) Session.get()).getWebClient().handleException(null, new ApplicationException(ServoyException.INVALID_INPUT, e));
Object stateValue = record.getValue(dataProviderID);
if (!Utils.equalObjects(prevValue, stateValue)) {
// reset display to changed value in validator method
obj = stateValue;
}
if (ownComponentsValue) {
((IDisplayData) component).setValueValid(false, prevValue);
}
return;
}
if (ownComponentsValue && record instanceof FindState && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IFormatScriptComponent && ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat() != null) {
((FindState) record).setFormat(dataProviderID, ((IFormatScriptComponent) ((IScriptableProvider) component).getScriptObject()).getComponentFormat().parsedFormat);
}
}
}
// then dont call notify
if (ownComponentsValue) {
((IDisplayData) component).notifyLastNewValueWasChange(prevValue, obj);
}
} finally {
// then touch the lastInvalidValue
if (ownComponentsValue) {
if (((IDisplayData) component).isValueValid()) {
lastInvalidValue = NONE;
} else {
lastInvalidValue = obj;
}
}
}
return;
}
use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class DesignModeBehavior method respond.
/**
* @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(org.apache.wicket.ajax.AjaxRequestTarget)
*/
@Override
protected void respond(AjaxRequestTarget target) {
Request request = RequestCycle.get().getRequest();
String action = request.getParameter(DraggableBehavior.PARAM_ACTION);
String id = extractId(request.getParameter(DraggableBehavior.PARAM_DRAGGABLE_ID));
if (id != null) {
final String finalId = id.endsWith(TemplateGenerator.WRAPPER_SUFFIX) ? id.substring(0, id.length() - 8) : id;
MarkupContainer comp = (MarkupContainer) getComponent();
Component child = (Component) comp.visitChildren(Component.class, new IVisitor<Component>() {
public Object component(Component component) {
String markupId = component.getMarkupId();
if (finalId.equals(markupId))
return component;
return IVisitor.CONTINUE_TRAVERSAL;
}
});
if (action != null) {
int height = stripUnitPart(request.getParameter(PARAM_RESIZE_HEIGHT));
int width = stripUnitPart(request.getParameter(PARAM_RESIZE_WIDTH));
int x = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_X));
int y = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_Y));
if (action.equals(ACTION_SELECT)) {
if (!(child instanceof IComponent))
onSelectComponents.clear();
else {
boolean isSelectionRemove = false;
if (!Boolean.parseBoolean(request.getParameter(PARAM_IS_CTRL_KEY)))
onSelectComponents.clear();
else {
isSelectionRemove = onSelectComponents.remove(child) != null;
}
IComponent[] param = onSelectComponents.keySet().toArray(new IComponent[isSelectionRemove ? onSelectComponents.size() : onSelectComponents.size() + 1]);
if (!isSelectionRemove)
param[onSelectComponents.size()] = (IComponent) child;
Object ret = callback.executeOnSelect(getJSEvent(EventType.action, 0, new Point(x, y), param));
if (ret instanceof Boolean && !((Boolean) ret).booleanValue()) {
onSelectComponents.clear();
} else {
if (!isSelectionRemove)
onSelectComponents.put((IComponent) child, id);
StringBuilder idsArray = new StringBuilder("new Array(");
Iterator<String> idsIte = onSelectComponents.values().iterator();
while (idsIte.hasNext()) {
idsArray.append('\'').append(idsIte.next()).append('\'');
if (idsIte.hasNext())
idsArray.append(',');
}
idsArray.append(')');
target.appendJavascript("Servoy.ClientDesign.attachElements(" + idsArray.toString() + ");");
}
if (Boolean.parseBoolean(request.getParameter(PARAM_IS_RIGHTCLICK))) {
callback.executeOnRightClick(getJSEvent(EventType.rightClick, 0, new Point(x, y), param));
} else if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
callback.executeOnDblClick(getJSEvent(EventType.doubleClick, 0, new Point(x, y), param));
}
}
WebEventExecutor.generateResponse(target, getComponent().getPage());
target.appendJavascript("Servoy.ClientDesign.clearClickTimer();");
return;
}
if (child instanceof IComponent) {
if (!onSelectComponents.containsKey(child)) {
onSelectComponents.put((IComponent) child, id);
}
if (action.equals(ACTION_RESIZE)) {
if (width != -1 && height != -1) {
if (child instanceof ISupportWebBounds) {
Insets paddingAndBorder = ((ISupportWebBounds) child).getPaddingAndBorder();
if (paddingAndBorder != null) {
height += paddingAndBorder.bottom + paddingAndBorder.top;
width += paddingAndBorder.left + paddingAndBorder.right;
}
}
if (child instanceof IScriptableProvider) {
((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setSize(width, height);
((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x, y);
}
if (child instanceof IProviderStylePropertyChanges)
((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
}
callback.executeOnResize(getJSEvent(EventType.onDrop, 0, new Point(x, y), new IComponent[] { (IComponent) child }));
} else if (action.equals(DraggableBehavior.ACTION_DRAG_START)) {
Object onDragAllowed = callback.executeOnDrag(getJSEvent(EventType.onDrag, 0, new Point(x, y), onSelectComponents.keySet().toArray(new IComponent[onSelectComponents.size()])));
if ((onDragAllowed instanceof Boolean && !((Boolean) onDragAllowed).booleanValue()) || (onDragAllowed instanceof Number && ((Number) onDragAllowed).intValue() == DRAGNDROP.NONE)) {
onDragComponent = null;
} else {
onDragComponent = (IComponent) child;
}
WebEventExecutor.generateResponse(target, getComponent().getPage());
return;
} else {
if (child == onDragComponent) {
if (x != -1 && y != -1) {
((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x, y);
if (child instanceof IProviderStylePropertyChanges) {
// test if it is wrapped
if ((child).getParent() instanceof WrapperContainer) {
// call for the changes on the wrapper container so that it will copy the right values over
WrapperContainer wrapper = (WrapperContainer) (child).getParent();
wrapper.getStylePropertyChanges().getChanges();
wrapper.getStylePropertyChanges().setRendered();
}
((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
}
}
callback.executeOnDrop(getJSEvent(EventType.onDrop, 0, new Point(x, y), onSelectComponents.keySet().toArray(new IComponent[onSelectComponents.size()])));
}
if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
callback.executeOnDblClick(getJSEvent(EventType.doubleClick, 0, new Point(x, y), new IComponent[] { (IComponent) child }));
}
}
}
}
}
WebEventExecutor.generateResponse(target, getComponent().getPage());
target.appendJavascript("Servoy.ClientDesign.reattach();");
}
use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class DesignModeBehavior method setSelectedComponents.
public void setSelectedComponents(String[] selectedComponentsNames) {
onSelectComponents.clear();
if (selectedComponentsNames != null && selectedComponentsNames.length > 0) {
IComponent c;
String compId;
boolean webAnchorsEnabled = Utils.getAsBoolean(((WebClientSession) Session.get()).getWebClient().getRuntimeProperties().get("enableAnchors"));
boolean editable;
for (String selectedComponentName : selectedComponentsNames) {
c = getWicketComponentForName(selectedComponentName);
editable = false;
if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeInputComponent) {
editable = ((IRuntimeInputComponent) ((IScriptableProvider) c).getScriptObject()).isEditable();
}
if (webAnchorsEnabled && c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeComponent && needsWrapperDivForAnchoring(((IRuntimeComponent) ((IScriptableProvider) c).getScriptObject()).getElementType(), editable)) {
compId = ((Component) c).getMarkupId() + TemplateGenerator.WRAPPER_SUFFIX;
} else {
compId = ((Component) c).getMarkupId();
}
onSelectComponents.put(c, compId);
}
}
}
use of com.servoy.j2db.scripting.IScriptableProvider in project servoy-client by Servoy.
the class ComponentFactory method applyBasicComponentProperties.
public static void applyBasicComponentProperties(IApplication application, IComponent c, BaseComponent bc, Pair<IStyleSheet, IStyleRule> styleInfo) {
// flag for border set by style config
boolean isBorderStyle = false;
// by default it is not transparent
c.setOpaque(true);
// apply any style
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
if (s.hasAttribute(CSS.Attribute.COLOR.toString())) {
Color cfg = ss.getForeground(s);
if (cfg != null)
c.setForeground(cfg);
}
Object sbackground_color = s.getValue(CSS.Attribute.BACKGROUND_COLOR.toString());
if (sbackground_color != null) {
if (IStyleSheet.COLOR_TRANSPARENT.equals(sbackground_color.toString())) {
c.setOpaque(false);
} else {
Color cbg = ss.getBackground(s);
if (cbg != null)
c.setBackground(cbg);
}
}
// else c.setOpaque(false); // no background-color means transparent
if (ss.hasFont(s)) {
Font f = ss.getFont(s);
if (f != null)
c.setFont(f);
}
if (ss.hasBorder(s)) {
Border b = ss.getBorder(s);
if (b != null) {
c.setBorder(b);
isBorderStyle = true;
}
}
if (ss.hasMargin(s)) {
Insets i = ss.getMargin(s);
if (i != null && c instanceof IButton)
((IButton) c).setMargin(i);
}
}
}
// We intentionally leave the location setting to DataRenderers, since thats the context and might substract part heights from location!
java.awt.Dimension dim = bc.getSize();
if (dim != null)
c.setSize(bc.getSize());
javax.swing.border.Border border = ComponentFactoryHelper.createBorder(bc.getBorderType());
if ((c instanceof JCheckBox || /* DataCheckBox */
c instanceof JRadioButton) && (border != null || isBorderStyle)) {
((AbstractButton) c).setBorderPainted(true);
if (c instanceof JCheckBox) {
((JCheckBox) c).setBorderPaintedFlat(false);
}
}
if (border != null) {
if (border instanceof TitledBorder && Utils.isAppleMacOS()) {
// apple bug.. i have to set the font again (as new!!)
TitledBorder tb = (TitledBorder) border;
Font f = tb.getTitleFont();
if (f != null) {
tb.setTitleFont(new Font(f.getName(), f.getStyle(), f.getSize()));
}
c.setBorder(border);
} else {
c.setBorder(border);
}
}
// if (c instanceof IDelegate)
// {
// c = (JComponent)((IDelegate)c).getDelegate();
// }
String fontString = bc.getFontType();
if (fontString != null) {
Font f = PersistHelper.createFont(fontString);
if (f != null)
c.setFont(f);
}
java.awt.Color bg = bc.getBackground();
if (bg != null)
c.setBackground(bg);
java.awt.Color fg = bc.getForeground();
if (fg != null)
c.setForeground(fg);
String name = bc.getName();
if (name != null)
c.setName(name);
// only use component property value if it is "checked" to be transparent
if (bc.getTransparent())
c.setOpaque(false);
c.setComponentEnabled(bc.getEnabled());
c.setComponentVisible(bc.getVisible());
if (Utils.isSwingClient(application.getApplicationType())) {
// special code for smart client LAFs, like BizLaf
String delegateStyleClassNamePropertyKey = application.getSettings().getProperty("servoy.smartclient.componentStyleClassDelegatePropertyKey");
if (delegateStyleClassNamePropertyKey != null && c instanceof JComponent) {
if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeComponent) {
// special case since putClientProperty can delegate properties but cannot be overridden we relay on the scripting equivalent
((IRuntimeComponent) ((IScriptableProvider) c).getScriptObject()).putClientProperty(delegateStyleClassNamePropertyKey, bc.getStyleClass());
} else {
((JComponent) c).putClientProperty(delegateStyleClassNamePropertyKey, bc.getStyleClass());
}
}
}
}
Aggregations