use of com.servoy.j2db.server.headlessclient.dataui.WebDataCalendar in project servoy-client by Servoy.
the class DesignModeBehavior method renderHead.
/**
* @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#renderHead(org.apache.wicket.markup.html.IHeaderResponse)
*/
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
YUILoader.renderResize(response);
final ArrayList<Component> markupIds = new ArrayList<Component>();
final ArrayList<Component> dropMarkupIds = new ArrayList<Component>();
((MarkupContainer) getComponent()).visitChildren(IComponent.class, new IVisitor<Component>() {
public Object component(Component component) {
if (!(component instanceof WebDataRenderer)) {
markupIds.add(component);
if (component instanceof ITabPanel || component instanceof WebDataCalendar) {
return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
} else if (component instanceof WebDataRenderer) {
dropMarkupIds.add(component);
}
return IVisitor.CONTINUE_TRAVERSAL;
}
});
if (markupIds.size() > 0) {
boolean webAnchorsEnabled = Utils.getAsBoolean(((WebClientSession) Session.get()).getWebClient().getRuntimeProperties().get("enableAnchors"));
// WebClientSession webClientSession = (WebClientSession)getSession();
// WebClient webClient = webClientSession.getWebClient();
ArrayList<String> selectedComponentsId = new ArrayList<String>();
StringBuilder sb = new StringBuilder(markupIds.size() * 10);
sb.append("Servoy.ClientDesign.attach({");
for (int i = 0; i < markupIds.size(); i++) {
Component component = markupIds.get(i);
Object clientdesign_handles = null;
if (component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IRuntimeComponent) {
IRuntimeComponent sbmc = (IRuntimeComponent) ((IScriptableProvider) component).getScriptObject();
// skip, elements with no name are not usable in CD
if (sbmc.getName() == null)
continue;
clientdesign_handles = sbmc.getClientProperty(CLIENTDESIGN.HANDLES);
Object clientdesign_selectable = sbmc.getClientProperty(CLIENTDESIGN.SELECTABLE);
// skip
if (clientdesign_selectable != null && !Utils.getAsBoolean(clientdesign_selectable))
continue;
}
// $NON-NLS-1$
String padding = "0px 0px 0px 0px";
if (component instanceof ISupportWebBounds) {
Insets p = ((ISupportWebBounds) component).getPaddingAndBorder();
if (p != null)
padding = "0px " + (p.left + p.right) + "px " + (p.bottom + p.top) + "px 0px";
}
boolean editable = false;
if (component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IRuntimeInputComponent) {
editable = ((IRuntimeInputComponent) ((IScriptableProvider) component).getScriptObject()).isEditable();
}
String compId;
if (webAnchorsEnabled && component instanceof IScriptableProvider && ((IScriptableProvider) component).getScriptObject() instanceof IRuntimeComponent && needsWrapperDivForAnchoring(((IRuntimeComponent) ((IScriptableProvider) component).getScriptObject()).getElementType(), editable)) {
compId = component.getMarkupId() + TemplateGenerator.WRAPPER_SUFFIX;
} else {
compId = component.getMarkupId();
}
sb.append(compId);
if (component instanceof IComponent) {
Iterator<IComponent> selectedComponentsIte = onSelectComponents.keySet().iterator();
IComponent c;
while (selectedComponentsIte.hasNext()) {
c = selectedComponentsIte.next();
if (c.getName().equals(((IComponent) component).getName())) {
onSelectComponents.put(c, compId);
selectedComponentsId.add(compId);
break;
}
}
}
sb.append(":['");
sb.append(padding);
sb.append("'");
if (clientdesign_handles instanceof Object[]) {
sb.append(",[");
Object[] array = (Object[]) clientdesign_handles;
for (Object element : array) {
sb.append('\'');
sb.append(ScriptRuntime.escapeString(element.toString()));
sb.append("',");
}
// rollback last comma
sb.setLength(sb.length() - 1);
sb.append("]");
}
sb.append("],");
}
// rollback last comma
sb.setLength(sb.length() - 1);
sb.append("},'" + getCallbackUrl() + "')");
if (selectedComponentsId.size() > 0) {
for (int i = 0; i < selectedComponentsId.size(); i++) {
sb.append(";Servoy.ClientDesign.selectedElementId[").append(i).append("]='").append(selectedComponentsId.get(i)).append("';");
}
sb.append("Servoy.ClientDesign.reattach();");
}
response.renderOnDomReadyJavascript(sb.toString());
// if (dropMarkupIds.size() > 0)
// {
// StringBuilder attachDrop = new StringBuilder();
// attachDrop.append("attachDrop([");
// for (int i = 0; i < dropMarkupIds.size(); i++)
// {
// Component component = dropMarkupIds.get(i);
// attachDrop.append("'");
// attachDrop.append(component.getMarkupId());
// attachDrop.append("',");
// }
// attachDrop.setLength(attachDrop.length() - 1);
// attachDrop.append("])");
// response.renderOnDomReadyJavascript(attachDrop.toString());
// }
}
}
Aggregations