use of com.servoy.j2db.ui.runtime.IRuntimeComponent in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method applyStyleOnComponent.
private void applyStyleOnComponent(Component comp, Object bgColor, Object fgColor, Object compFont, Object listItemBorder) {
if (comp instanceof IScriptableProvider) {
IScriptable s = ((IScriptableProvider) comp).getScriptObject();
if (s instanceof IRuntimeComponent) {
IRuntimeComponent sbm = (IRuntimeComponent) s;
RenderableWrapper sbmRW = null;
if (s instanceof ISupportOnRenderCallback) {
IScriptRenderMethods sr = ((ISupportOnRenderCallback) s).getRenderable();
if (sr instanceof RenderableWrapper)
sbmRW = (RenderableWrapper) sr;
}
if (bgColor != null) {
if (sbmRW != null)
sbmRW.clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
String oldColor = sbm.getBgcolor();
sbm.setBgcolor(bgColor.toString());
if (sbm instanceof AbstractRuntimeBaseComponent && ((AbstractRuntimeBaseComponent) sbm).getComponent() instanceof WebDataLookupField) {
((WebDataLookupField) ((AbstractRuntimeBaseComponent) sbm).getComponent()).setListColor(PersistHelper.createColor(oldColor));
}
if (sbm.isTransparent()) {
// apply the bg color even if transparent by clearing the transparent flag in the property changes map
if (comp instanceof IProviderStylePropertyChanges && ((IProviderStylePropertyChanges) comp).getStylePropertyChanges() instanceof IStylePropertyChangesRecorder) {
((IStylePropertyChangesRecorder) (((IProviderStylePropertyChanges) comp).getStylePropertyChanges())).setTransparent(false);
}
}
} else {
if (sbmRW != null && !Utils.equalObjects(sbmRW.getOnRenderSetProperties().get(RenderableWrapper.PROPERTY_BGCOLOR), sbm.getBgcolor()))
sbmRW.clearProperty(RenderableWrapper.PROPERTY_BGCOLOR);
sbm.setBgcolor(sbm.getBgcolor());
setParentBGcolor(comp, "");
}
if (fgColor != null) {
if (sbmRW != null)
sbmRW.clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
sbm.setFgcolor(fgColor.toString());
} else {
if (sbmRW != null && !Utils.equalObjects(sbmRW.getOnRenderSetProperties().get(RenderableWrapper.PROPERTY_FGCOLOR), sbm.getFgcolor())) {
sbmRW.clearProperty(RenderableWrapper.PROPERTY_FGCOLOR);
}
sbm.setFgcolor(sbm.getFgcolor());
}
if (compFont != null) {
if (sbmRW != null && !Utils.equalObjects(sbmRW.getOnRenderSetProperties().get(RenderableWrapper.PROPERTY_FONT), sbm.getFont()))
sbmRW.clearProperty(RenderableWrapper.PROPERTY_FONT);
sbm.setFont(compFont.toString());
} else {
if (sbmRW != null)
sbmRW.clearProperty(RenderableWrapper.PROPERTY_FONT);
sbm.setFont(sbm.getFont());
}
if (listItemBorder != null) {
// TODO left / right part of this list item border should only be applied on first / last components in the row (for table view)
// like it is done in servoy.js when client side styling is used
String newBorder = listItemBorder.toString();
Border currentBorder = ComponentFactoryHelper.createBorder(sbm.getBorder());
Border marginBorder = null;
if (currentBorder instanceof EmptyBorder) {
marginBorder = currentBorder;
} else if (currentBorder instanceof CompoundBorder && ((CompoundBorder) currentBorder).getInsideBorder() instanceof EmptyBorder) {
marginBorder = ((CompoundBorder) currentBorder).getInsideBorder();
}
if (marginBorder != null) {
newBorder = ComponentFactoryHelper.createBorderString(BorderFactory.createCompoundBorder(ComponentFactoryHelper.createBorder(newBorder), marginBorder));
}
if (sbmRW != null)
sbmRW.clearProperty(RenderableWrapper.PROPERTY_BORDER);
sbm.setBorder(newBorder);
// reset size so the web size will be recalculated based on the new border
sbm.setSize(sbm.getWidth(), sbm.getHeight());
} else {
if (sbmRW != null && !Utils.equalObjects(sbmRW.getOnRenderSetProperties().get(RenderableWrapper.PROPERTY_BORDER), sbm.getBorder()))
sbmRW.clearProperty(RenderableWrapper.PROPERTY_BORDER);
sbm.setBorder(sbm.getBorder());
}
}
}
}
use of com.servoy.j2db.ui.runtime.IRuntimeComponent 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.ui.runtime.IRuntimeComponent 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.ui.runtime.IRuntimeComponent 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.ui.runtime.IRuntimeComponent 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