use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class TemplateGenerator method createFieldHTML.
private static void createFieldHTML(Field field, Form form, StringBuffer html, TextualCSS css, int startY, int endY, boolean enableAnchoring, IServiceProvider sp) {
boolean addWrapperDiv = enableAnchoring && WebAnchoringHelper.needsWrapperDivForAnchoring(field);
TextualStyle styleObj = css.addStyle('#' + ComponentFactory.getWebID(form, field));
boolean[] userCssClassAdded = new boolean[] { false };
Properties minSizeStyle = styleObj;
if (addWrapperDiv) {
// Anchoring fields (<input>s, <textarea>s) with { left: 0px; right: 0px; } pair
// or { top: 0px; bottom: 0px; } does not work. Thus we add a dummy wrapper <div>
// which accepts this kind of anchoring, and we place the field inside the <div>
// with { width: 100%; height: 100%; }, which works fine.
String wrapperId = ComponentFactory.getWebID(form, field) + WRAPPER_SUFFIX;
TextualStyle wrapperStyle = css.addStyle('#' + wrapperId);
wrapperStyle.setProperty("overflow", "visible");
minSizeStyle = wrapperStyle;
html.append("<div ");
html.append(getWicketIDParameter(form, field, "", WRAPPER_SUFFIX));
html.append(getJavaScriptIDParameter(form, field, "", WRAPPER_SUFFIX));
if (field.getDisplayType() == Field.COMBOBOX) {
html.append(getCssClassForElement(field, userCssClassAdded, COMBOBOX_CLASS));
}
html.append(getCssClassForElement(field, userCssClassAdded, ""));
html.append(">");
}
Insets padding = (Insets) DEFAULT_FIELD_PADDING.clone();
Insets border = (Insets) DEFAULT_FIELD_BORDER_SIZE.clone();
if (field.getDisplayType() == Field.COMBOBOX || field.getDisplayType() == Field.LIST_BOX || field.getDisplayType() == Field.MULTISELECT_LISTBOX) {
padding = DEFAULT_LABEL_PADDING;
}
BorderAndPadding ins = applyBaseComponentProperties(field, form, styleObj, padding, border, sp);
Pair<IStyleSheet, IStyleRule> pairStyle = ComponentFactory.getCSSPairStyleForForm(sp, form);
IStyleSheet ss = pairStyle != null ? pairStyle.getLeft() : null;
// By default no css class applied.
String cssClass = "";
switch(field.getDisplayType()) {
case Field.PASSWORD:
{
if (ins == null) {
ins = new BorderAndPadding(DEFAULT_FIELD_BORDER_SIZE, DEFAULT_FIELD_PADDING);
}
html.append("<input ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append("type='password' ");
if (field.getSelectOnEnter()) {
// $NON-NLS-1$
html.append("onfocus='Servoy.Utils.doSelect(this)'");
}
html.append("/>");
}
break;
case Field.RTF_AREA:
{
applyScrolling(styleObj, field);
html.append("<div ");
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(">RTF field not supported in webclient</div>");
}
break;
case Field.HTML_AREA:
if (!field.getEditable()) {
applyScrolling(styleObj, field);
html.append("<div ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append(">non editable HTML field</div>");
boolean hasFontFamily = styleObj.containsKey("font-family");
boolean hasFontSize = styleObj.containsKey("font-size");
if (hasFontFamily || hasFontSize) {
for (String dfe : DEFAULT_FONT_ELEMENTS) {
TextualStyle htmlAreaFont = css.addStyle('#' + ComponentFactory.getWebID(form, field) + " " + dfe);
if (hasFontFamily)
htmlAreaFont.setProperty("font-family", styleObj.getProperty("font-family"));
if (hasFontSize)
htmlAreaFont.setProperty("font-size", styleObj.getProperty("font-size"));
}
}
break;
} else {
String editorId = "editor_" + ComponentFactory.getWebID(form, field);
html.append("<div ");
html.append(getWicketIDParameter(form, field));
html.append("><textarea id='");
html.append(editorId);
html.append("' name='");
html.append(editorId);
html.append("' ");
html.append(getWicketIDParameter(form, field, "editor_", ""));
html.append(" rows=\"20\" cols=\"75\"></textarea></div>");
styleObj.setProperty("padding", "0px");
styleObj.setProperty("overflow", "hidden");
}
break;
case Field.TEXT_AREA:
{
if (ins == null) {
ins = new BorderAndPadding(DEFAULT_FIELD_BORDER_SIZE, DEFAULT_FIELD_PADDING);
}
applyScrolling(styleObj, field);
html.append("<textarea ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append("></textarea>");
}
break;
case Field.CHECKS:
case Field.RADIOS:
boolean isRadio = (field.getDisplayType() == Field.RADIOS);
String selector = (isRadio ? "radio" : "check");
cssClass = (isRadio ? "radio" : "check");
IValueList val = null;
ValueList valuelist = null;
if (field.getValuelistID() > 0 && sp != null) {
valuelist = sp.getFlattenedSolution().getValueList(field.getValuelistID());
}
boolean addSingle = ComponentFactory.isSingleValue(valuelist);
// If we have multiple checkboxes, then the default is "field".
if (field.getValuelistID() > 0 && !addSingle && !isRadio)
cssClass = "radioCheckField";
// If we have a style for the form, apply "check" class if present, default to "field" if "check" class is not present.
if (ss != null) {
cssClass = "radioCheckField";
String lookUpValue = selector;
IStyleRule s = ss.getCSSRule(lookUpValue);
if (s.getAttributeCount() == 0) {
if ((field.getStyleClass() != null) && (field.getStyleClass().trim().length() > 0)) {
lookUpValue += '.' + field.getStyleClass().trim();
s = ss.getCSSRule(lookUpValue);
if (s.getAttributeCount() > 0)
cssClass = selector;
}
} else {
cssClass = selector;
}
}
if ((field.getValuelistID() > 0 || isRadio) && !addSingle) {
applyScrolling(styleObj, field);
html.append("<div ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, cssClass));
html.append(">Multi checkboxes</div>");
} else {
html.append("<div ");
html.append(getCssClassForElement(field, userCssClassAdded, cssClass));
html.append(getWicketIDParameter(form, field));
html.append(" tabIndex=\"-1\" ");
//
html.append(">");
html.append("<table cellspacing='0' cellpadding='0' border='0' width='100%' height='100%'><tr><td id='check_td' style='vertical-align: middle;'><input onmousedown='radioCheckInputMouseDown=true' onmouseup='radioCheckInputMousedDown=false' onmouseout='radioCheckInputMouseDown=false' class='radioCheckInput' style='border-width: 0px; padding: " + (isRadio ? "0px" : "3px") + //
"; margin: 0px; vertical-align: middle;' ");
html.append(getWicketIDParameter(form, field, "check_", ""));
html.append(getDataProviderIDParameter(field));
if (isRadio) {
html.append("type='radio' ");
} else {
html.append("type='checkbox' ");
}
html.append("/>");
html.append("<label style='border-width: 0px; padding-top: " + (isRadio ? "0px" : "2px") + "; padding-left: 3px; margin: 0px; vertical-align: middle;");
html.append("' ");
html.append(getWicketIDParameter(form, field, "text_", ""));
html.append(">");
html.append("</label>");
html.append("</td></tr></table></div>");
}
break;
case Field.COMBOBOX:
{
ins = null;
// if (ins == null)
// {
// ins = new BorderAndPadding(DEFAULT_FIELD_BORDER_SIZE,DEFAULT_FIELD_PADDING);
// }
html.append("<select ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append(">Combobox</select>");
}
break;
case Field.MULTISELECT_LISTBOX:
case Field.LIST_BOX:
{
ins = null;
html.append("<select ");
if (field.getDisplayType() == Field.MULTISELECT_LISTBOX) {
html.append("multiple=\"multiple\"");
}
html.append(getWicketIDParameter(form, field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "listbox"));
html.append(">Listbox</select>");
}
break;
case Field.CALENDAR:
case Field.SPINNER:
createCompositeFieldHTML(html, form, field, styleObj, userCssClassAdded);
break;
case Field.IMAGE_MEDIA:
{
applyScrolling(styleObj, field);
// in tableview position is not set
styleObj.setProperty("position", "relative");
html.append("<div ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, "field"));
html.append('>');
TextualStyle inline2 = new TextualStyle();
// inline2.setProperty("top", "1px");
// inline2.setProperty("left", "1px");
// inline2.setProperty("position", "absolute");
// inline2.setProperty("cursor", "pointer");
// inline2.setProperty("background-color", "gray");
inline2.setProperty("z-index", "1");
html.append("<img ");
html.append(inline2.toString());
html.append(" border=0 servoy:id='save_icon' src='#' class='image-media-save' alt='Save' />");
html.append("<img ");
// inline2.setProperty("left", "17px");
html.append(inline2.toString());
html.append(" border=0 servoy:id='upload_icon' src='#' class='image-media-upload' alt='Upload' />");
html.append("<img ");
// inline2.setProperty("left", "33px");
html.append(inline2.toString());
html.append(" border=0 servoy:id='remove_icon' src='#' class='image-media-remove' alt='Remove' />");
// html.append("<a ");
// html.append(inline2.toString());
// html.append(" servoy:id='upload' href='#' border=0><img servoy:id='upload_icon' src='#' alt='' /></a>");
// html.append("<a ");
// inline2.setProperty("left","16px");
// html.append(inline2.toString());
// html.append(" servoy:id='save' href='#' border=0><img servoy:id='save_icon' src='#' alt='' /></a>");
TextualStyle inline = new TextualStyle();
inline.setProperty("top", "0px");
inline.setProperty("left", "0px");
inline.setProperty("position", "absolute");
if (field.getOnActionMethodID() < 1) {
inline.setProperty("cursor", "default");
}
html.append("<input ");
html.append(inline.toString());
html.append(getWicketIDParameter(form, field));
html.append(getJavaScriptIDParameter(form, field));
html.append("value='");
if (field.getName() != null)
html.append(field.getName());
html.append("' ");
html.append("type='image' ");
html.append(" src='#' alt='' ");
html.append(" onclick='return false;' ");
html.append("/>");
// html.append("<img ");
// html.append(inline.toString());
// html.append(" src='#' alt='' ");
// html.append(getWicketIDParameter(field));
// html.append(" />");
html.append("</div>");
}
break;
default:
case Field.TYPE_AHEAD:
case Field.TEXT_FIELD:
{
if (ins == null) {
ins = new BorderAndPadding(DEFAULT_FIELD_BORDER_SIZE, DEFAULT_FIELD_PADDING);
}
html.append("<input ");
html.append(getWicketIDParameter(form, field));
// html.append(getJavaScriptIDParameter(field));
html.append(getDataProviderIDParameter(field));
html.append(getCssClassForElement(field, userCssClassAdded, field.getValuelistID() > 0 ? "field typeahead" : "field"));
html.append("type='text' ");
if (field.getSelectOnEnter()) {
// $NON-NLS-1$
html.append("onfocus='Servoy.Utils.doSelect(this)'");
}
html.append("/>");
}
break;
}
if (field.getHorizontalAlignment() != -1) {
if (// all who's actual implementation is based on WebDataCompositeTextField
isCompositeTextField(field.getDisplayType())) {
TextualStyle childTextCSS = css.addStyle('#' + ComponentFactory.getWebID(form, field) + WebDataCompositeTextField.AUGMENTED_FIELD_ID);
applyTextProperties(field, childTextCSS);
} else {
applyTextProperties(field, styleObj);
}
}
Insets borderAndPadding = ins == null ? new Insets(0, 0, 0, 0) : ins.getSum();
WebAnchoringHelper.addMinSize(field.getAnchors(), sp, minSizeStyle, new Dimension(field.getSize().width - borderAndPadding.left - borderAndPadding.right, field.getSize().height - borderAndPadding.top - borderAndPadding.bottom), field);
if (addWrapperDiv) {
html.append("</div>");
styleObj.setProperty("width", "100%");
styleObj.setProperty("height", "100%");
styleObj.setProperty("position", "absolute");
} else {
applyLocationAndSize(field, styleObj, ins, startY, endY, form.getSize().width, enableAnchoring, isListViewBodyElement(form, field.getLocation()) ? new Point(-3, 0) : null);
}
}
use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class TemplateGenerator method createGraphicalComponentHTML.
private static void createGraphicalComponentHTML(GraphicalComponent label, Form form, StringBuffer html, TextualCSS css, int startY, int endY, boolean enableAnchoring, IServiceProvider sp) {
String styleName = "#";
Insets border = null;
if (ComponentFactory.isButton(label) && !hasHTMLText(label.getText())) {
// styleName = "input.";
border = DEFAULT_BUTTON_BORDER_SIZE;
}
TextualStyle styleObj = css.addStyle(styleName + ComponentFactory.getWebID(form, label));
BorderAndPadding ins = applyBaseComponentProperties(label, form, styleObj, (Insets) DEFAULT_LABEL_PADDING.clone(), border, sp);
// fix the background img, see ComponentFactory.createGraphicalComponent
// background image through css will only be used when repeat or position are set (or linear gradient is used).
// if both are not specified then it is used as the MEDIA of the label/button, so bck_img is removed from the css.
boolean keepBgImageStyle = false;
for (String attribute : ServoyStyleSheet.BACKGROUND_IMAGE_CSS) {
if (attribute.equals(CSS.Attribute.BACKGROUND_IMAGE.toString())) {
if (styleObj.getProperty(attribute) == null) {
keepBgImageStyle = false;
break;
} else if (!styleObj.getProperty(attribute).contains(MediaURLStreamHandler.MEDIA_URL_DEF)) {
keepBgImageStyle = true;
break;
}
} else if (styleObj.getProperty(attribute) != null) {
keepBgImageStyle = true;
break;
}
}
if (!keepBgImageStyle) {
styleObj.remove(CSS.Attribute.BACKGROUND_IMAGE.toString());
}
applyTextProperties(label, styleObj);
Field labelForField = null;
String labelFor = label.getLabelFor();
if (labelFor != null) {
Iterator<IPersist> fields = form.getObjects(IRepository.FIELDS);
while (fields.hasNext()) {
Field fld = (Field) fields.next();
if (labelFor.equals(fld.getName())) {
labelForField = fld;
break;
}
}
}
int labelHAlign = label.getHorizontalAlignment();
int labelVAlign = label.getVerticalAlignment();
Pair<IStyleSheet, IStyleRule> styleInfo = ComponentFactory.getStyleForBasicComponent(sp, label, form);
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (labelHAlign == -1)
labelHAlign = ss.getHAlign(s);
if (labelVAlign == -1)
labelVAlign = ss.getVAlign(s);
}
// Defaults are mapped to CENTER (or MIDDLE for vertical) to keep behavior from Smart client.
if (labelHAlign == -1)
labelHAlign = ISupportTextSetup.CENTER;
if (labelVAlign == -1)
labelVAlign = ISupportTextSetup.CENTER;
boolean isButton = ComponentFactory.isButton(label);
boolean[] userCssClassAdded = new boolean[] { false };
TextualStyle wrapperStyle = null;
Properties minSizeStyle = styleObj;
if (isButton && enableAnchoring) {
// Anchoring <button> with { left: 0px; right: 0px; } pair
// or { top: 0px; bottom: 0px; } does not work. Thus we add a dummy wrapper <div>
// which accepts this kind of anchoring, and we place the button inside the <div>
// with { width: 100%; height: 100%; }, which works fine.
String wrapperId = ComponentFactory.getWebID(form, label) + WRAPPER_SUFFIX;
wrapperStyle = css.addStyle(styleName + wrapperId);
minSizeStyle = wrapperStyle;
html.append("<div ");
html.append(getCssClassForElement(label, userCssClassAdded, ""));
html.append(getWicketIDParameter(form, label, "", WRAPPER_SUFFIX));
html.append(getJavaScriptIDParameter(form, label, "", WRAPPER_SUFFIX));
html.append(">");
}
Insets buttonBorder = null;
if (isButton) {
html.append("<button type='submit' ");
html.append(" style=\"white-space: nowrap;\" ");
html.append(getWicketIDParameter(form, label));
html.append(getDataProviderIDParameter(label));
html.append(getCssClassForElement(label, userCssClassAdded, "button"));
html.append(">");
html.append("</button>");
// buttons are border-box by default!!
buttonBorder = ins.getBorder();
ins = null;
} else {
if (labelForField != null) {
html.append("<label ");
// Needed for FF to accept a <div> inside a <label>.
styleObj.setProperty("display", "block");
} else {
html.append("<div ");
}
// we want to wrap only if there is no html content in the label text
if (label.getText() != null && !HtmlUtils.hasUsefulHtmlContent(label.getText())) {
html.append(" style=\"white-space: nowrap;\"");
}
html.append(getWicketIDParameter(form, label));
html.append(getDataProviderIDParameter(label));
html.append(getCssClassForElement(label, userCssClassAdded, "label"));
html.append('>');
boolean hasHtml = hasHTMLText(label.getText());
if (hasHtml && (label.getOnActionMethodID() != 0)) {
html.append("<servoy:remove>");
}
html.append(getSafeText(label.getText()));
if (hasHtml && (label.getOnActionMethodID() != 0)) {
html.append("</servoy:remove>");
}
if (labelForField != null) {
html.append("</label>");
} else {
html.append("</div>");
}
if (label.getOnActionMethodID() > 0)
styleObj.setProperty("cursor", "pointer");
}
Insets borderAndPadding = ins == null ? new Insets(0, 0, 0, 0) : ins.getSum();
WebAnchoringHelper.addMinSize(label.getAnchors(), sp, minSizeStyle, new Dimension(label.getSize().width - borderAndPadding.left - borderAndPadding.right, label.getSize().height - borderAndPadding.top - borderAndPadding.bottom), label);
if (isButton && enableAnchoring) {
html.append("</div>");
styleObj.setProperty("width", "100%");
styleObj.setProperty("height", "100%");
styleObj.setProperty("position", "absolute");
applyLocationAndSize(label, wrapperStyle, ins, startY, endY, form.getSize().width, enableAnchoring, isListViewBodyElement(form, label.getLocation()) ? new Point(-3, 0) : null);
} else {
applyLocationAndSize(label, styleObj, ins, startY, endY, form.getSize().width, enableAnchoring, isListViewBodyElement(form, label.getLocation()) ? new Point(-3, 0) : null);
}
if (label.getRolloverCursor() == Cursor.HAND_CURSOR) {
styleObj.setProperty("cursor", "pointer");
}
int height = label.getSize().height;
// See: http://doctype.com/html-button-tag-renders-strangely-firefox
if (isButton) {
int bottomPadding = 0;
if (labelVAlign != ISupportTextSetup.CENTER) {
bottomPadding = height;
if (buttonBorder != null)
bottomPadding -= buttonBorder.top + buttonBorder.bottom;
}
styleObj.setProperty("padding-bottom", bottomPadding + "px");
}
}
use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class ComponentFactory method getCSSPairStyleForForm.
public static Pair<IStyleSheet, IStyleRule> getCSSPairStyleForForm(IServiceProvider sp, Form form) {
IStyleSheet styleSheet = getCSSStyleForForm(sp, form);
IStyleRule styleRule = getCSSRuleForForm(sp, form);
if (styleSheet != null && styleRule != null) {
return new Pair<IStyleSheet, IStyleRule>(styleSheet, styleRule);
}
return null;
}
use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class ComponentFactory method createGraphicalComponent.
private static IComponent createGraphicalComponent(IApplication application, Form form, GraphicalComponent label, IScriptExecuter el, IDataProviderLookup dataProviderLookup) {
int style_halign = -1;
int style_valign = -1;
int textTransform = 0;
int mediaid = 0;
Pair<IStyleSheet, IStyleRule> styleInfo = getStyleForBasicComponent(application, label, form);
if (styleInfo != null) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
style_valign = ss.getVAlign(s);
style_halign = ss.getHAlign(s);
boolean parseMedia = true;
// anything else then then the css through the templategenerator is used. (See TemplateGenerator.createGraphicalComponentHTML)
if (application.getApplicationType() == IApplication.WEB_CLIENT) {
parseMedia = s.getValue(CSS.Attribute.BACKGROUND_REPEAT.toString()) == null && s.getValue(CSS.Attribute.BACKGROUND_POSITION.toString()) == null;
}
if (parseMedia) {
Object mediaUrl = s.getValue(CSS.Attribute.BACKGROUND_IMAGE.toString());
if (mediaUrl != null && mediaUrl.toString() != null) {
String mediaUrlString = mediaUrl.toString();
int start = mediaUrlString.indexOf(MediaURLStreamHandler.MEDIA_URL_DEF);
if (start != -1) {
String name = mediaUrlString.substring(start + MediaURLStreamHandler.MEDIA_URL_DEF.length());
if (name.endsWith("')") || name.endsWith("\")"))
name = name.substring(0, name.length() - 2);
if (name.endsWith(")"))
name = name.substring(0, name.length() - 1);
Media media = application.getFlattenedSolution().getMedia(name);
if (media != null) {
mediaid = media.getID();
}
}
}
}
String transform = s.getValue(CSS.Attribute.TEXT_TRANSFORM.toString());
if (transform != null) {
if ("uppercase".equals(transform)) {
textTransform = ILabel.UPPERCASE;
} else if ("lowercase".equals(transform)) {
textTransform = ILabel.LOWERCASE;
} else if ("capitalize".equals(transform)) {
textTransform = ILabel.CAPITALIZE;
}
}
}
}
ILabel l;
AbstractRuntimeLabel<? extends ILabel> scriptable;
IStylePropertyChangesRecorder jsChangeRecorder = application.getItemFactory().createChangesRecorder();
if (ComponentFactory.isButton(label)) {
IButton button;
if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
scriptable = new RuntimeScriptButton(jsChangeRecorder, application);
button = application.getItemFactory().createScriptButton((RuntimeScriptButton) scriptable, getWebID(form, label));
} else {
scriptable = new RuntimeDataButton(jsChangeRecorder, application);
button = application.getItemFactory().createDataButton((RuntimeDataButton) scriptable, getWebID(form, label));
IDataProvider dp = null;
try {
dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
((IDisplayData) button).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
((IDisplayTagText) button).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
((IDisplayData) button).setNeedEntireState(label.getDisplaysTags());
}
((AbstractRuntimeButton<IButton>) scriptable).setComponent(button, label);
button.setMediaOption(label.getMediaOptions());
if (label.getRolloverImageMediaID() > 0) {
try {
button.setRolloverIcon(label.getRolloverImageMediaID());
button.setRolloverEnabled(true);
} catch (Exception ex) {
Debug.error(ex);
}
}
l = button;
} else {
if (label.getDataProviderID() == null && !label.getDisplaysTags()) {
scriptable = new RuntimeScriptLabel(jsChangeRecorder, application);
l = application.getItemFactory().createScriptLabel((RuntimeScriptLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
} else {
scriptable = new RuntimeDataLabel(jsChangeRecorder, application);
l = application.getItemFactory().createDataLabel((RuntimeDataLabel) scriptable, getWebID(form, label), (label.getOnActionMethodID() > 0));
IDataProvider dp = null;
try {
dp = dataProviderLookup == null ? null : dataProviderLookup.getDataProvider(label.getDataProviderID());
} catch (RepositoryException e) {
Debug.error(e);
}
((IDisplayData) l).setDataProviderID(dp == null ? label.getDataProviderID() : dp.getDataProviderID());
((IDisplayTagText) l).setTagText(application.getI18NMessageIfPrefixed(label.getText()));
((IDisplayData) l).setNeedEntireState(label.getDisplaysTags());
}
((AbstractHTMLSubmitRuntimeLabel<ILabel>) scriptable).setComponent(l, label);
l.setMediaOption(label.getMediaOptions());
if (label.getRolloverImageMediaID() > 0) {
try {
l.setRolloverIcon(label.getRolloverImageMediaID());
} catch (Exception ex) {
Debug.error(ex);
}
}
}
String mnemonic = application.getI18NMessageIfPrefixed(label.getMnemonic());
if (mnemonic != null && mnemonic.length() > 0) {
l.setDisplayedMnemonic(mnemonic.charAt(0));
}
l.setTextTransform(textTransform);
if (el != null && (label.getOnActionMethodID() > 0 || label.getOnDoubleClickMethodID() > 0 || label.getOnRightClickMethodID() > 0)) {
l.addScriptExecuter(el);
if (label.getOnActionMethodID() > 0)
l.setActionCommand(Integer.toString(label.getOnActionMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onActionMethodID")));
if (label.getOnDoubleClickMethodID() > 0)
l.setDoubleClickCommand(Integer.toString(label.getOnDoubleClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onDoubleClickMethodID")));
if (label.getOnRightClickMethodID() > 0)
l.setRightClickCommand(Integer.toString(label.getOnRightClickMethodID()), Utils.parseJSExpressions(label.getFlattenedMethodArguments("onRightClickMethodID")));
}
if (label.getLabelFor() == null || (form.getView() != FormController.TABLE_VIEW && form.getView() != FormController.LOCKED_TABLE_VIEW)) {
int onRenderMethodID = label.getOnRenderMethodID();
AbstractBase onRenderPersist = label;
if (onRenderMethodID <= 0) {
onRenderMethodID = form.getOnRenderMethodID();
onRenderPersist = form;
}
if (onRenderMethodID > 0) {
RenderEventExecutor renderEventExecutor = scriptable.getRenderEventExecutor();
renderEventExecutor.setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(onRenderPersist.getFlattenedMethodArguments("onRenderMethodID")));
IForm rendererForm = application.getFormManager().getForm(form.getName());
IScriptExecuter rendererScriptExecuter = rendererForm instanceof FormController ? ((FormController) rendererForm).getScriptExecuter() : null;
renderEventExecutor.setRenderScriptExecuter(rendererScriptExecuter);
}
}
l.setRotation(label.getRotation());
l.setFocusPainted(label.getShowFocus());
l.setCursor(Cursor.getPredefinedCursor(label.getRolloverCursor()));
try {
int halign = label.getHorizontalAlignment();
if (halign != -1) {
l.setHorizontalAlignment(halign);
} else if (style_halign != -1) {
l.setHorizontalAlignment(style_halign);
}
} catch (RuntimeException e) {
// just ignore...Debug.error(e);
}
int valign = label.getVerticalAlignment();
if (valign != -1) {
l.setVerticalAlignment(valign);
} else if (style_valign != -1) {
l.setVerticalAlignment(style_valign);
}
try {
if (!label.getDisplaysTags()) {
l.setText(application.getI18NMessageIfPrefixed(label.getText()));
}
} catch (RuntimeException e1) {
// ignore
}
l.setToolTipText(application.getI18NMessageIfPrefixed(label.getToolTipText()));
if (label.getImageMediaID() > 0) {
try {
l.setMediaIcon(label.getImageMediaID());
} catch (Exception e) {
Debug.error(e);
}
} else if (mediaid > 0) {
try {
l.setMediaIcon(mediaid);
} catch (Exception e) {
Debug.error(e);
}
}
if (label.getDataProviderID() != null) {
scriptable.setComponentFormat(ComponentFormat.getComponentFormat(label.getFormat(), label.getDataProviderID(), dataProviderLookup, application));
}
applyBasicComponentProperties(application, l, label, styleInfo);
Border border = null;
Insets insets = null;
if (label.getBorderType() != null) {
border = ComponentFactoryHelper.createBorder(label.getBorderType());
}
if (label.getMargin() != null) {
insets = label.getMargin();
}
if (styleInfo != null && (border == null || insets == null)) {
IStyleSheet ss = styleInfo.getLeft();
IStyleRule s = styleInfo.getRight();
if (ss != null && s != null) {
if (border == null && ss.hasBorder(s)) {
border = ss.getBorder(s);
}
if (insets == null && ss.hasMargin(s)) {
insets = ss.getMargin(s);
}
}
}
if (border != null && insets != null) {
l.setBorder(BorderFactory.createCompoundBorder(border, BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right)));
} else if (border == null && insets != null && l instanceof IButton) {
((IButton) l).setMargin(insets);
} else // supports setMargin, then fake the margins through empty border. (issue 166391)
if (border == null && insets != null) {
l.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
}
if (l instanceof IAnchoredComponent) {
((IAnchoredComponent) l).setAnchors(label.getAnchors());
}
return l;
}
use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class FormController method createDataRenderers.
private void createDataRenderers(int viewType) throws Exception {
int v = viewType;
if (getDataSource() == null) {
// form not based on any datasource
v = LOCKED_RECORD_VIEW;
}
application.getDataRenderFactory().prepareRenderers(application, form);
Part bodyPart = null;
Map<Part, IDataRenderer> part_panels = new LinkedHashMap<Part, IDataRenderer>();
Iterator<Part> e2 = form.getParts();
while (e2.hasNext()) {
Part part = e2.next();
Color partColor = ComponentFactory.getPartBackground(application, part, form);
// extract the body (bgcolor)
if (part.getPartType() == Part.BODY) {
bodyPart = part;
bgColor = partColor;
Pair<IStyleSheet, IStyleRule> partStyle = ComponentFactory.getStyleForBasicComponent(application, part, form);
bodyRule = partStyle != null ? partStyle.getRight() : null;
}
if (part.getPartType() == Part.BODY && v == FormController.LOCKED_TABLE_VIEW) {
// don't create part, view == part
continue;
}
IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, part), part.toString(), application, (part.getPartType() == Part.BODY));
dr.initDragNDrop(this, form.getPartStartYPos(part.getID()));
dataRenderers[part.getPartType()] = dr;
dr.setName(part.toString());
part_panels.put(part, dr);
if (part.getPartType() == Part.BODY) {
int onRenderMethodID = form.getOnRenderMethodID();
if (onRenderMethodID > 0) {
dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
}
}
dr.setBackground(partColor);
}
tabSequence.clear();
application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), tabSequence);
if (bodyPart != null && (v == FormController.LOCKED_LIST_VIEW || v == IForm.LIST_VIEW)) {
IDataRenderer dr = application.getDataRenderFactory().getEmptyDataRenderer(ComponentFactory.getWebID(form, bodyPart), bodyPart.toString(), application, true);
int onRenderMethodID = form.getOnRenderMethodID();
if (onRenderMethodID > 0) {
dr.getOnRenderComponent().getRenderEventExecutor().setRenderCallback(Integer.toString(onRenderMethodID), Utils.parseJSExpressions(form.getFlattenedMethodArguments("onRenderMethodID")));
dr.getOnRenderComponent().getRenderEventExecutor().setRenderScriptExecuter(getScriptExecuter());
}
// apply bgcolor to renderer
if (bgColor != null) {
dr.setBackground(bgColor);
}
dataRenderers[FORM_RENDERER] = dr;
dr.setName(bodyPart.toString());
part_panels = new LinkedHashMap<Part, IDataRenderer>();
part_panels.put(bodyPart, dr);
application.getDataRenderFactory().completeRenderers(application, form, scriptExecuter, part_panels, form.getSize().width, false, containerImpl.getUndoManager(), null);
}
// apply security
int access = application.getFlattenedSolution().getSecurityAccess(form.getUUID(), form.getImplicitSecurityNoRights() ? IRepository.IMPLICIT_FORM_NO_ACCESS : IRepository.IMPLICIT_FORM_ACCESS);
if (access != -1) {
boolean b_accessible = ((access & IRepository.ACCESSIBLE) != 0);
if (!b_accessible) {
for (IDataRenderer dataRenderer : dataRenderers) {
if (dataRenderer != null) {
Iterator<? extends IComponent> componentIterator = dataRenderer.getComponentIterator();
while (componentIterator.hasNext()) {
IComponent c = componentIterator.next();
if (c instanceof ISupportSecuritySettings) {
if (!b_accessible)
((ISupportSecuritySettings) c).setAccessible(b_accessible);
}
}
}
}
}
}
}
Aggregations