use of com.servoy.j2db.ui.IComponent 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.IComponent in project servoy-client by Servoy.
the class DesignModeBehavior method getJSEvent.
private JSEvent getJSEvent(EventType type, int modifiers, Point point, IComponent[] selected) {
JSEvent event = new JSEvent();
event.setFormName(controller.getName());
event.setType(type);
event.setModifiers(modifiers);
event.setLocation(point);
List<Object> selection = new ArrayList<Object>();
if (selected != null) {
for (IComponent component : selected) {
if (component instanceof IScriptableProvider) {
selection.add(0, ((IScriptableProvider) component).getScriptObject());
} else {
selection.add(0, component);
}
}
}
event.setData(selection.toArray());
// event.setSource(e)
return event;
}
use of com.servoy.j2db.ui.IComponent in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method createScriptEvent.
public JSDNDEvent createScriptEvent(EventType type, IComponent dragSource, Point xy, int modifiers) {
JSDNDEvent jsEvent = new JSDNDEvent();
jsEvent.setType(type);
jsEvent.setFormName(getDragFormName());
if (dragSource instanceof IDataRenderer) {
IDataRenderer dr = (IDataRenderer) dragSource;
FormController fct = dr.getDataAdapterList().getFormController();
jsEvent.setSource(fct.getFormScope());
} else {
jsEvent.setSource(dragSource);
if (dragSource != null) {
if (dragSource instanceof Component) {
WebCellBasedViewListItem listItem = ((Component) dragSource).findParent(WebCellBasedViewListItem.class);
if (listItem != null) {
IRecordInternal dragRecord = listItem.getModelObject();
if (dragRecord instanceof Record)
jsEvent.setRecord((Record) dragRecord);
}
}
String dragSourceName = dragSource.getName();
if (dragSourceName == null)
dragSourceName = dragSource.getId();
jsEvent.setElementName(dragSourceName);
}
}
if (xy != null)
jsEvent.setLocation(xy);
jsEvent.setModifiers(modifiers);
return jsEvent;
}
use of com.servoy.j2db.ui.IComponent 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.IComponent in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method createComponents.
private void createComponents(final IApplication app, final Form form, final AbstractBase view, final IDataProviderLookup dataProviderLookup, final IScriptExecuter el, final int viewStartY, final int viewEndY, final ItemAdd output) {
List<IPersist> elements = ComponentFactory.sortElementsOnPositionAndGroup(view.getAllObjectsAsList());
int startX = 0;
for (int i = 0; i < elements.size(); i++) {
IPersist element = elements.get(i);
if (element instanceof Field || element instanceof GraphicalComponent || element instanceof Bean) {
if (!isListViewMode()) {
if (element instanceof GraphicalComponent && ((GraphicalComponent) element).getLabelFor() != null) {
if (isInView(cellview, ((GraphicalComponent) element).getLabelFor())) {
labelsFor.put(((GraphicalComponent) element).getLabelFor(), element);
}
continue;
}
}
Point l = ((IFormElement) element).getLocation();
if (l == null) {
// unknown where to add
continue;
}
if (l.y >= viewStartY && l.y < viewEndY) {
IComponent c = ComponentFactory.createComponent(app, form, element, dataProviderLookup, el, false);
if (cellview instanceof Portal && c instanceof IScriptableProvider) {
IScriptable s = ((IScriptableProvider) c).getScriptObject();
if (s instanceof ISupportOnRenderCallback && ((ISupportOnRenderCallback) s).getRenderEventExecutor() != null)
ComponentFactoryHelper.addPortalOnRenderCallback((Portal) cellview, ((ISupportOnRenderCallback) s).getRenderEventExecutor(), element, fc != null ? fc.getScriptExecuter() : null);
}
initializeComponent((Component) c, view, element);
output.add(element, (Component) c);
if (!isListViewMode()) {
// reset location.x as defined in this order, elements are ordered by location.x which is modified in drag-n-drop
Point loc = c.getLocation();
if (loc != null) {
c.setLocation(new Point(startX, loc.y));
}
Dimension csize = c.getSize();
startX += (csize != null) ? csize.width : ((IFormElement) element).getSize().width;
}
}
}
}
}
Aggregations