use of com.servoy.j2db.ui.runtime.IRuntimeComponent 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());
// }
}
}
use of com.servoy.j2db.ui.runtime.IRuntimeComponent in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method resizeColumn.
public void resizeColumn(SortableCellViewHeader headerColumn, int x) {
int totalWidthToStretch = 0;
IPersist resizedPersist = null;
for (IPersist p : elementToColumnHeader.keySet()) {
Component c = elementToColumnIdentifierComponent.get(p);
if (c instanceof IScriptableProvider && ((IScriptableProvider) c).getScriptObject() instanceof IRuntimeComponent) {
IRuntimeComponent ic = (IRuntimeComponent) ((IScriptableProvider) c).getScriptObject();
if (elementToColumnHeader.get(p).equals(headerColumn)) {
int height = ic.getHeight();
Iterator<Component> alreadyAddedComponents = cellToElement.keySet().iterator();
if (alreadyAddedComponents.hasNext()) {
Component firstAddedComponent = alreadyAddedComponents.next();
if ((firstAddedComponent instanceof IComponent))
height = ((IComponent) firstAddedComponent).getSize().height;
}
ic.setSize(ic.getWidth() + x, height);
if (ic instanceof IProviderStylePropertyChanges) {
resizedComponent = c;
// avoid the tableview to render because of this change
((IProviderStylePropertyChanges) ic).getStylePropertyChanges().setRendered();
}
resizedPersist = p;
// set width for all cell of the column
Iterator<Entry<Component, IPersist>> cellToElementIte = cellToElement.entrySet().iterator();
Entry<Component, IPersist> cellToElementEntry;
Component cellComponent;
while (cellToElementIte.hasNext()) {
cellToElementEntry = cellToElementIte.next();
cellComponent = cellToElementEntry.getKey();
if (p.equals(cellToElementEntry.getValue()) && cellComponent instanceof IScriptableProvider && ((IScriptableProvider) cellComponent).getScriptObject() instanceof IRuntimeComponent) {
IRuntimeComponent cellScriptComponent = (IRuntimeComponent) ((IScriptableProvider) cellComponent).getScriptObject();
cellScriptComponent.setSize(cellScriptComponent.getWidth() + x, cellScriptComponent.getHeight());
if (cellComponent instanceof IProviderStylePropertyChanges) {
// avoid the tableview to render because of this change
((IProviderStylePropertyChanges) cellComponent).getStylePropertyChanges().setRendered();
}
}
}
} else {
totalWidthToStretch += ic.getWidth();
}
}
}
if (shouldFillAllHorizontalSpace())
distributeExtraSpace(-x, totalWidthToStretch, resizedPersist, false);
setHeadersWidth();
}
use of com.servoy.j2db.ui.runtime.IRuntimeComponent in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method distributeExtraSpace.
private void distributeExtraSpace() {
int totalDefaultWidth = 0;
int totalWidthToStretch = 0;
int stretchedElementsCount = 0;
for (IPersist element : elementToColumnIdentifierComponent.keySet()) {
Object scriptobject = elementToColumnIdentifierComponent.get(element);
if (!((Component) scriptobject).isVisible())
continue;
if (scriptobject instanceof IScriptableProvider) {
scriptobject = ((IScriptableProvider) scriptobject).getScriptObject();
}
if (scriptobject instanceof IRuntimeComponent) {
int width = ((IRuntimeComponent) scriptobject).getWidth();
totalDefaultWidth += width;
if (element instanceof ISupportAnchors) {
int anchors = ((ISupportAnchors) element).getAnchors();
if (((anchors & IAnchorConstants.EAST) != 0) && ((anchors & IAnchorConstants.WEST) != 0)) {
totalWidthToStretch += width;
stretchedElementsCount++;
}
}
}
}
boolean shouldFillAllHorizSpace = shouldFillAllHorizontalSpace();
if (shouldFillAllHorizSpace) {
if (stretchedElementsCount > 0) {
int delta = getDisplayBodyWidthHint() - totalDefaultWidth;
distributeExtraSpace(delta, totalWidthToStretch, null, true);
setHeadersWidth();
}
}
}
use of com.servoy.j2db.ui.runtime.IRuntimeComponent in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method initializeComponent.
@SuppressWarnings("nls")
private void initializeComponent(final Component c, AbstractBase view, IPersist element) {
if (dal != null && dal.isDestroyed()) {
Debug.error("Trying to initialize a component: " + c + " of " + view + " element: " + element + " that is in a destroyed tableview", new RuntimeException());
return;
}
if (// Don't know any other place for this
view instanceof Portal && c instanceof IDisplayData) {
String id = ((IDisplayData) c).getDataProviderID();
if (id != null && !ScopesUtils.isVariableScope(id) && id.startsWith(((Portal) view).getRelationName() + '.')) {
((IDisplayData) c).setDataProviderID(id.substring(((Portal) cellview).getRelationName().length() + 1));
}
}
if (!isListViewMode() && c instanceof WebDataCheckBox) {
// $NON-NLS-1$
((WebDataCheckBox) c).setText("");
}
if (element != null) {
// apply to this cell the state of the columnIdentifier IComponent, do keep the location that is set by the tableview when creating these components the first time.
// for listview this is the location to use.
Point loc = ((IComponent) c).getLocation();
int height = ((IComponent) c).getSize().height;
PropertyCopy.copyElementProps((IComponent) elementToColumnIdentifierComponent.get(element), (IComponent) c);
if (!isListViewMode()) {
((IComponent) c).setLocation(loc);
// it shouldn't be possible to change the height
if (c instanceof IScriptableProvider) {
IScriptable so = ((IScriptableProvider) c).getScriptObject();
if (so instanceof IRuntimeComponent) {
IRuntimeComponent ic = (IRuntimeComponent) so;
if (ic.getHeight() != height) {
ic.setSize(ic.getWidth(), height);
}
}
}
}
} else {
// $NON-NLS-1$
Debug.log("Cannot find the IPersist element for cell " + c.getMarkupId());
}
if (c instanceof IDisplayData) {
IDisplayData cdd = (IDisplayData) c;
if (!(dal != null && dal.getFormScope() != null && cdd.getDataProviderID() != null && // skip for form variables
dal.getFormScope().get(cdd.getDataProviderID()) != Scriptable.NOT_FOUND)) {
cdd.setValidationEnabled(validationEnabled);
}
} else if (c instanceof IDisplayRelatedData) {
((IDisplayRelatedData) c).setValidationEnabled(validationEnabled);
} else if (c instanceof IServoyAwareBean) {
((IServoyAwareBean) c).setValidationEnabled(validationEnabled);
}
addClassToCellComponent(c);
if (// the check could be extended against IDelegate<?>
c instanceof WebDataCompositeTextField) {
Object delegate = ((WebDataCompositeTextField) c).getDelegate();
if (delegate instanceof Component) {
// make sure that this class is added accordingly in TemplateGenerator as a style selector containing relevant properties
addClassToCellComponent((Component) delegate);
}
}
if (c instanceof ISupportValueList) {
ISupportValueList idVl = (ISupportValueList) elementToColumnIdentifierComponent.get(element);
IValueList list;
if (idVl != null && (list = idVl.getValueList()) != null) {
ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
((ISupportValueList) c).setValueList(list);
}
}
}
applyClientProperties(c, element);
}
use of com.servoy.j2db.ui.runtime.IRuntimeComponent in project servoy-client by Servoy.
the class BasicFormController method getElements.
public IRuntimeComponent[] getElements() {
Object elementScope = formScope == null ? null : formScope.get("elements");
if (elementScope instanceof DefaultScope) {
Object[] values = ((DefaultScope) elementScope).getValues();
List<IRuntimeComponent> elements = new ArrayList<IRuntimeComponent>(values.length);
for (Object value : values) {
if (value instanceof Wrapper) {
value = ((Wrapper) value).unwrap();
}
if (value instanceof IRuntimeComponent) {
elements.add((IRuntimeComponent) value);
}
}
return elements.toArray(new IRuntimeComponent[elements.size()]);
}
return new IRuntimeComponent[0];
}
Aggregations