use of com.servoy.j2db.server.headlessclient.WrapperContainer in project servoy-client by Servoy.
the class WebCellAdapter method valueChanged.
public void valueChanged(ModificationEvent e) {
MainPage mp = view.findParent(MainPage.class);
if (mp != null)
mp.touch();
IRecord record = e.getRecord();
Iterator iterator = ((MarkupContainer) view.getTable()).iterator();
while (iterator.hasNext()) {
Object next = iterator.next();
if (next instanceof ListItem) {
ListItem li = (ListItem) next;
Object modelObject = li.getModelObject();
if (record == null || modelObject == record) {
boolean hasOnRender = false;
Iterator iterator2 = li.iterator();
while (iterator2.hasNext()) {
ArrayList<Object> cellDisplays = new ArrayList<Object>();
Object cell = iterator2.next();
cell = CellContainer.getContentsForCell((Component) cell);
if (cell instanceof WebCellBasedViewListViewItem) {
Iterator listItemIte = ((WebCellBasedViewListViewItem) cell).iterator();
while (listItemIte.hasNext()) {
Object listItemDisplay = listItemIte.next();
if (listItemDisplay instanceof WrapperContainer) {
listItemDisplay = ((WrapperContainer) listItemDisplay).getDelegate();
}
cellDisplays.add(listItemDisplay);
}
} else {
cellDisplays.add(cell);
}
for (Object cellDisplay : cellDisplays) {
if (cellDisplay instanceof IProviderStylePropertyChanges && cellDisplay instanceof IDisplayData && ((IDisplayData) cellDisplay).getDataProviderID() == dataprovider) {
// only test if it is not already changed
view.checkForValueChanges(cellDisplay);
// do fire on render on all components for record change
if (cellDisplay instanceof ISupportOnRender && cellDisplay instanceof IScriptableProvider) {
IScriptable so = ((IScriptableProvider) cellDisplay).getScriptObject();
if (so instanceof AbstractRuntimeRendersupportComponent && ((ISupportOnRenderCallback) so).getRenderEventExecutor().hasRenderCallback()) {
String componentDataproviderID = ((AbstractRuntimeRendersupportComponent) so).getDataProviderID();
if (record != null || (e.getName() != null && e.getName().equals(componentDataproviderID))) {
((ISupportOnRender) cellDisplay).fireOnRender(true);
hasOnRender = true;
}
}
}
}
}
}
if (record != null || (!hasOnRender && !canChangeValue(e)))
break;
}
}
}
}
use of com.servoy.j2db.server.headlessclient.WrapperContainer in project servoy-client by Servoy.
the class WebEventExecutor method generateDragAttach.
/**
* @param component2
* @param response
*/
@SuppressWarnings("nls")
public static void generateDragAttach(Component component, IHeaderResponse response) {
DraggableBehavior draggableBehavior = null;
Component behaviorComponent = component;
if ((behaviorComponent instanceof IComponent) && !(behaviorComponent instanceof IFormDataDragNDrop)) {
behaviorComponent = (Component) component.findParent(IFormDataDragNDrop.class);
}
if (behaviorComponent != null) {
Iterator<IBehavior> behaviors = behaviorComponent.getBehaviors().iterator();
Object behavior;
while (behaviors.hasNext()) {
behavior = behaviors.next();
if (behavior instanceof DraggableBehavior) {
draggableBehavior = (DraggableBehavior) behavior;
break;
}
}
}
if (draggableBehavior == null)
return;
boolean bUseProxy = draggableBehavior.isUseProxy();
boolean bResizeProxyFrame = draggableBehavior.isResizeProxyFrame();
boolean bXConstraint = draggableBehavior.isXConstraint();
boolean bYConstraint = draggableBehavior.isYConstraint();
CharSequence dragUrl = draggableBehavior.getCallbackUrl();
String jsCode = null;
if (behaviorComponent instanceof IFormDataDragNDrop) {
final StringBuilder sbAttachDrag = new StringBuilder(100);
sbAttachDrag.append("Servoy.DD.attachDrag([");
final StringBuilder sbAttachDrop = new StringBuilder(100);
sbAttachDrop.append("Servoy.DD.attachDrop([");
final boolean hasDragEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDragMethodID() > 0 || ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDragOverMethodID() > 0;
final boolean hasDropEvent = ((IFormDataDragNDrop) behaviorComponent).getDragNDropController().getForm().getOnDropMethodID() > 0;
if (component instanceof WebDataRenderer || component instanceof WebCellBasedView) {
if (hasDragEvent)
sbAttachDrag.append('\'').append(component.getMarkupId()).append("',");
if (hasDropEvent)
sbAttachDrop.append('\'').append(component.getMarkupId()).append("',");
if (component instanceof WebDataRenderer) {
Iterator<? extends Component> dataRendererIte = ((WebDataRenderer) component).iterator();
Object dataRendererChild;
while (dataRendererIte.hasNext()) {
dataRendererChild = dataRendererIte.next();
if (dataRendererChild instanceof IWebFormContainer)
continue;
if (dataRendererChild instanceof WrapperContainer)
dataRendererChild = ((WrapperContainer) dataRendererChild).getDelegate();
if (dataRendererChild instanceof IComponent && ((IComponent) dataRendererChild).isEnabled()) {
updateDragAttachOutput(dataRendererChild, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
}
}
} else if (component instanceof WebCellBasedView) {
ListView<IRecordInternal> table = ((WebCellBasedView) component).getTable();
table.visitChildren(new IVisitor<Component>() {
public Object component(Component comp) {
if (comp instanceof IComponent && comp.isEnabled()) {
updateDragAttachOutput(comp, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
}
return null;
}
});
}
} else if (component != null && component.isEnabled()) {
updateDragAttachOutput(component, sbAttachDrag, sbAttachDrop, hasDragEvent, hasDropEvent);
}
if (sbAttachDrag.length() > 25) {
sbAttachDrag.setLength(sbAttachDrag.length() - 1);
sbAttachDrag.append("],'");
sbAttachDrag.append(dragUrl);
sbAttachDrag.append("', ");
sbAttachDrag.append(bUseProxy);
sbAttachDrag.append(", ");
sbAttachDrag.append(bResizeProxyFrame);
sbAttachDrag.append(", ");
sbAttachDrag.append(bXConstraint);
sbAttachDrag.append(", ");
sbAttachDrag.append(bYConstraint);
sbAttachDrag.append(");");
jsCode = sbAttachDrag.toString();
}
if (sbAttachDrop.length() > 25) {
sbAttachDrop.setLength(sbAttachDrop.length() - 1);
sbAttachDrop.append("],'");
sbAttachDrop.append(dragUrl);
sbAttachDrop.append("');");
if (jsCode != null)
jsCode += '\n' + sbAttachDrop.toString();
else
jsCode = sbAttachDrop.toString();
}
if (jsCode != null) {
if (response == null) {
jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode).append("</script>\n")).toString();
Response cyleResponse = RequestCycle.get().getResponse();
cyleResponse.write(jsCode);
} else
response.renderOnDomReadyJavascript(jsCode);
}
} else // default handling
{
jsCode = "Servoy.DD.attachDrag(['" + component.getMarkupId() + "'],'" + dragUrl + "', " + bUseProxy + ", " + bResizeProxyFrame + ", " + bXConstraint + ", " + bYConstraint + ")";
if (response == null) {
jsCode = (new StringBuilder().append("\n<script type=\"text/javascript\">\n").append(jsCode).append("</script>\n")).toString();
Response cyleResponse = RequestCycle.get().getResponse();
cyleResponse.write(jsCode);
} else
response.renderOnDomReadyJavascript(jsCode);
}
}
use of com.servoy.j2db.server.headlessclient.WrapperContainer in project servoy-client by Servoy.
the class WebEventExecutor method handleEvent.
/**
* @param type
* @param target
* @param comp
* @param webModifiers
* @param mouseLocation
* @param page
*/
private void handleEvent(EventType type, AjaxRequestTarget target, Component comp, int webModifiers, Point mouseLocation, Point absoluteMouseLocation, Page page) {
// process model changes from web components
WebClientSession.get().getWebClient().executeEvents();
Component renderScriptProvider = comp;
ISupplyFocusChildren<?> componentWithChildren = renderScriptProvider.findParent(ISupplyFocusChildren.class);
if (componentWithChildren != null)
renderScriptProvider = (Component) componentWithChildren;
if (renderScriptProvider instanceof WrapperContainer)
renderScriptProvider = ((WrapperContainer) renderScriptProvider).getDelegate();
RenderEventExecutor renderEventExecutor = null;
if (renderScriptProvider instanceof IScriptableProvider) {
IScriptable s = ((IScriptableProvider) renderScriptProvider).getScriptObject();
if (s instanceof ISupportOnRenderCallback) {
renderEventExecutor = ((ISupportOnRenderCallback) s).getRenderEventExecutor();
if (!renderEventExecutor.hasRenderCallback())
renderEventExecutor = null;
}
}
if (type == EventType.focusGained || type == EventType.action || type == EventType.focusLost) {
if (type == EventType.focusGained || type == EventType.action) {
((MainPage) page).setFocusedComponent(comp);
} else {
((MainPage) page).setFocusedComponent(null);
}
if (renderEventExecutor != null) {
renderEventExecutor.setRenderStateChanged();
// if component's onRender did not change any properties, don't add it to the target
if (renderScriptProvider instanceof ISupportOnRender && WebOnRenderHelper.doRender((ISupportOnRender) renderScriptProvider)) {
target.addComponent(renderScriptProvider);
}
}
}
if (type == EventType.focusLost || setSelectedIndex(comp, target, convertModifiers(webModifiers), type == EventType.focusGained || type == EventType.action)) {
if (skipFireFocusGainedCommand && type.equals(JSEvent.EventType.focusGained)) {
skipFireFocusGainedCommand = false;
} else {
switch(type) {
case action:
fireActionCommand(false, comp, convertModifiers(webModifiers), mouseLocation);
break;
case focusGained:
fireEnterCommands(false, comp, convertModifiers(webModifiers));
break;
case focusLost:
fireLeaveCommands(comp, false, convertModifiers(webModifiers));
break;
case doubleClick:
fireDoubleclickCommand(false, comp, convertModifiers(webModifiers), mouseLocation);
break;
case rightClick:
// if right click, mark the meta flag as it is on the smart client
fireRightclickCommand(false, comp, convertModifiers(webModifiers | 8), null, mouseLocation, absoluteMouseLocation);
break;
case none:
case dataChange:
case form:
case onDrag:
case onDragOver:
case onDrop:
}
}
}
}
use of com.servoy.j2db.server.headlessclient.WrapperContainer in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method getCellToFocus.
/**
* @param columnIdentifierComponent
* @return
*/
private Component getCellToFocus(final Component columnIdentifierComponent) {
Component cell = null;
// this means that the given column of the cell view wants to be focused =>
// we must focus the cell component that is part of the currently selected record
int selectedIndex = currentData.getSelectedIndex();
if (selectedIndex < 0 && currentData.getSize() > 0) {
selectedIndex = 0;
}
if (selectedIndex >= 0) {
// we found a record to use - now we must locate the cell component inside this record
ListItem<IRecordInternal> li = (ListItem<IRecordInternal>) table.get(Integer.toString(selectedIndex));
if (li != null) {
Iterator<? extends Component> cells = li.iterator();
while (cells.hasNext()) {
Component someCell = cells.next();
if (isListViewMode()) {
if (someCell instanceof WebCellBasedViewListItem) {
someCell = ((WebCellBasedViewListItem) someCell).getListContainer();
}
if (someCell instanceof MarkupContainer) {
for (int i = 0; i < ((MarkupContainer) someCell).size(); i++) {
Component currentComponent = ((MarkupContainer) someCell).get(i);
if (currentComponent instanceof WrapperContainer)
currentComponent = ((WrapperContainer) currentComponent).getDelegate();
IPersist element = cellToElement.get(currentComponent);
if (element != null && elementToColumnIdentifierComponent.get(element) == columnIdentifierComponent) {
return currentComponent;
}
}
}
} else {
someCell = CellContainer.getContentsForCell(someCell);
IPersist element = cellToElement.get(someCell);
if (element != null && elementToColumnIdentifierComponent.get(element) == columnIdentifierComponent) {
cell = someCell;
break;
}
}
}
}
}
return cell;
}
use of com.servoy.j2db.server.headlessclient.WrapperContainer in project servoy-client by Servoy.
the class WebEventExecutor method generateResponse.
@SuppressWarnings("nls")
public static void generateResponse(final AjaxRequestTarget target, Page page) {
WebClientSession webClientSession = WebClientSession.get();
if (target != null && page instanceof MainPage && webClientSession != null && webClientSession.getWebClient() != null && webClientSession.getWebClient().getSolution() != null) {
if (target instanceof CloseableAjaxRequestTarget && ((CloseableAjaxRequestTarget) target).isClosed()) {
return;
}
// do executed the events for before generating the response.
webClientSession.getWebClient().executeEvents();
if (webClientSession.getWebClient() == null || webClientSession.getWebClient().getSolution() == null) {
// how can web client be null here ?
return;
}
final MainPage mainPage = ((MainPage) page);
if (mainPage.getPageMap() instanceof ModifiedAccessStackPageMap) {
// at every request mark the pagemap as dirty so lru eviction really works
((ModifiedAccessStackPageMap) mainPage.getPageMap()).flagDirty();
}
// If the main form is switched then do a normal redirect.
if (mainPage.isMainFormSwitched()) {
mainPage.versionPush();
RequestCycle.get().setResponsePage(page);
} else {
page.visitChildren(WebTabPanel.class, new Component.IVisitor<WebTabPanel>() {
public Object component(WebTabPanel component) {
component.initalizeFirstTab();
return IVisitor.CONTINUE_TRAVERSAL;
}
});
mainPage.addWebAnchoringInfoIfNeeded();
final Set<WebCellBasedView> tableViewsToRender = new HashSet<WebCellBasedView>();
final List<String> valueChangedIds = new ArrayList<String>();
final List<String> invalidValueIds = new ArrayList<String>();
final Map<WebCellBasedView, List<Integer>> tableViewsWithChangedRowIds = new HashMap<WebCellBasedView, List<Integer>>();
// first, get all invalidValue & valueChanged components
page.visitChildren(IProviderStylePropertyChanges.class, new Component.IVisitor<Component>() {
public Object component(Component component) {
if (component instanceof IDisplayData && !((IDisplayData) component).isValueValid()) {
invalidValueIds.add(component.getMarkupId());
}
if (((IProviderStylePropertyChanges) component).getStylePropertyChanges().isValueChanged()) {
if (component.getParent().isVisibleInHierarchy()) {
// the component will get added to the target & rendered only if it's parent is visible in hierarchy because changed flag is also set (see the visitor below)
// so we will only list these components if they are visible otherwise ajax timer could end up sending hundreds of id's that don't actually render every 5 seconds
// because the valueChanged flag is cleared only by onRender
valueChangedIds.add(component.getMarkupId());
if (component instanceof MarkupContainer) {
((MarkupContainer) component).visitChildren(IDisplayData.class, new IVisitor<Component>() {
public Object component(Component comp) {
// labels/buttons that don't display data are not changed
if (!(comp instanceof ILabel)) {
valueChangedIds.add(comp.getMarkupId());
}
return CONTINUE_TRAVERSAL;
}
});
}
}
}
return CONTINUE_TRAVERSAL;
}
});
// add changed components to target; if a component is changed, the change check won't go deeper in hierarchy
page.visitChildren(IProviderStylePropertyChanges.class, new Component.IVisitor<Component>() {
public Object component(Component component) {
if (((IProviderStylePropertyChanges) component).getStylePropertyChanges().isChanged()) {
if (component.getParent().isVisibleInHierarchy()) {
target.addComponent(component);
generateDragAttach(component, target.getHeaderResponse());
WebForm parentForm = component.findParent(WebForm.class);
boolean isDesignMode = parentForm != null && parentForm.isDesignMode();
if (!component.isVisible() || (component instanceof WrapperContainer && !((WrapperContainer) component).getDelegate().isVisible())) {
((IProviderStylePropertyChanges) component).getStylePropertyChanges().setRendered();
if (isDesignMode) {
target.appendJavascript("Servoy.ClientDesign.hideSelected('" + component.getMarkupId() + "')");
}
} else {
if (isDesignMode) {
target.appendJavascript("Servoy.ClientDesign.refreshSelected('" + component.getMarkupId() + "')");
}
// some components need to perform js layout tasks when their markup is replaced when using anchored layout
mainPage.getPageContributor().markComponentForAnchorLayoutIfNeeded(component);
}
ListItem<IRecordInternal> row = component.findParent(ListItem.class);
if (row != null) {
WebCellBasedView wcbv = row.findParent(WebCellBasedView.class);
if (wcbv != null) {
if (tableViewsWithChangedRowIds.get(wcbv) == null) {
tableViewsWithChangedRowIds.put(wcbv, new ArrayList<Integer>());
}
List<Integer> ids = tableViewsWithChangedRowIds.get(wcbv);
int changedRowIdx = wcbv.indexOf(row);
if (changedRowIdx >= 0 && !ids.contains(changedRowIdx)) {
ids.add(changedRowIdx);
}
}
}
}
return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
} else if (component instanceof WebCellBasedView)
tableViewsToRender.add((WebCellBasedView) component);
return component.isVisible() ? IVisitor.CONTINUE_TRAVERSAL : IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
});
page.visitChildren(IComponentToRequestAttacher.class, new Component.IVisitor<Component>() {
public Object component(Component component) {
((IComponentToRequestAttacher) component).attachComponents(target);
return IVisitor.CONTINUE_TRAVERSAL;
}
});
final List<String> visibleEditors = new ArrayList<String>();
page.visitChildren(WebDataHtmlArea.class, new Component.IVisitor<Component>() {
public Object component(Component component) {
visibleEditors.add(((WebDataHtmlArea) component).getEditorID());
return IVisitor.CONTINUE_TRAVERSAL;
}
});
StringBuffer argument = new StringBuffer();
for (String id : visibleEditors) {
argument.append("\"");
argument.append(id);
argument.append("\"");
if (visibleEditors.indexOf(id) != visibleEditors.size() - 1) {
argument.append(",");
}
}
target.prependJavascript("Servoy.HTMLEdit.removeInvalidEditors(" + argument + ");");
String rowSelectionScript, columnResizeScript;
for (final WebCellBasedView wcbv : tableViewsToRender) {
if (wcbv.isScrollMode())
wcbv.scrollViewPort(target);
wcbv.updateRowSelection(target);
List<Integer> changedIds = tableViewsWithChangedRowIds.get(wcbv);
List<Integer> selectedIndexesChanged = wcbv.getIndexToUpdate(false);
List<Integer> mergedIds = selectedIndexesChanged != null ? selectedIndexesChanged : new ArrayList<Integer>();
if (changedIds != null) {
for (Integer id : changedIds) {
if (!mergedIds.contains(id)) {
mergedIds.add(id);
}
}
}
rowSelectionScript = wcbv.getRowSelectionScript(mergedIds);
wcbv.clearSelectionByCellActionFlag();
if (rowSelectionScript != null)
target.appendJavascript(rowSelectionScript);
columnResizeScript = wcbv.getColumnResizeScript();
if (columnResizeScript != null)
target.appendJavascript(columnResizeScript);
}
// double check if the page contributor is changed, because the above IStylePropertyChanges ischanged could have altered it.
if (mainPage.getPageContributor().getStylePropertyChanges().isChanged()) {
target.addComponent((Component) mainPage.getPageContributor());
}
if (invalidValueIds.size() == 0) {
// $NON-NLS-1$
target.appendJavascript("setValidationFailed(null);");
} else {
// $NON-NLS-1$
target.appendJavascript("setValidationFailed('" + invalidValueIds.get(0) + "');");
}
Component comp = mainPage.getAndResetToFocusComponent();
if (comp != null) {
if (comp instanceof WebDataHtmlArea) {
target.appendJavascript("tinyMCE.activeEditor.focus()");
} else {
target.focusComponent(comp);
}
} else if (mainPage.getAndResetMustFocusNull()) {
// This is needed for example when showing a non-modal dialog in IE7 (or otherwise
// the new window would be displayed in the background).
target.focusComponent(null);
}
if (valueChangedIds.size() > 0) {
argument = new StringBuffer();
for (String id : valueChangedIds) {
argument.append("\"");
argument.append(id);
argument.append("\"");
if (valueChangedIds.indexOf(id) != valueChangedIds.size() - 1) {
argument.append(",");
}
}
target.prependJavascript("storeValueAndCursorBeforeUpdate(" + argument + ");");
target.appendJavascript("restoreValueAndCursorAfterUpdate();");
}
// if we have admin info, show it
String adminInfo = mainPage.getAdminInfo();
if (adminInfo != null) {
adminInfo = Utils.stringReplace(adminInfo, "\r", "");
adminInfo = Utils.stringReplace(adminInfo, "\n", "\\n");
target.appendJavascript("alert('" + adminInfo + "');");
}
// If we have a status text, set it.
String statusText = mainPage.getStatusText();
if (statusText != null) {
target.appendJavascript("setStatusText('" + statusText + "');");
}
String show = mainPage.getShowUrlScript();
if (show != null) {
target.appendJavascript(show);
}
mainPage.renderJavascriptChanges(target);
if (((WebClientInfo) webClientSession.getClientInfo()).getProperties().isBrowserInternetExplorer() && ((WebClientInfo) webClientSession.getClientInfo()).getProperties().getBrowserVersionMajor() < 9) {
target.appendJavascript("Servoy.Utils.checkWebFormHeights();");
}
try {
if (isStyleSheetLimitForIE(page.getSession())) {
target.appendJavascript("testStyleSheets();");
}
} catch (Exception e) {
// cannot retrieve session/clientinfo/properties?
Debug.error(e);
target.appendJavascript("testStyleSheets();");
}
}
}
}
Aggregations