use of com.servoy.j2db.ui.IProviderStylePropertyChanges in project servoy-client by Servoy.
the class DesignModeBehavior method respond.
/**
* @see org.apache.wicket.ajax.AbstractDefaultAjaxBehavior#respond(org.apache.wicket.ajax.AjaxRequestTarget)
*/
@Override
protected void respond(AjaxRequestTarget target) {
Request request = RequestCycle.get().getRequest();
String action = request.getParameter(DraggableBehavior.PARAM_ACTION);
String id = extractId(request.getParameter(DraggableBehavior.PARAM_DRAGGABLE_ID));
if (id != null) {
final String finalId = id.endsWith(TemplateGenerator.WRAPPER_SUFFIX) ? id.substring(0, id.length() - 8) : id;
MarkupContainer comp = (MarkupContainer) getComponent();
Component child = (Component) comp.visitChildren(Component.class, new IVisitor<Component>() {
public Object component(Component component) {
String markupId = component.getMarkupId();
if (finalId.equals(markupId))
return component;
return IVisitor.CONTINUE_TRAVERSAL;
}
});
if (action != null) {
int height = stripUnitPart(request.getParameter(PARAM_RESIZE_HEIGHT));
int width = stripUnitPart(request.getParameter(PARAM_RESIZE_WIDTH));
int x = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_X));
int y = stripUnitPart(request.getParameter(DraggableBehavior.PARAM_Y));
if (action.equals(ACTION_SELECT)) {
if (!(child instanceof IComponent))
onSelectComponents.clear();
else {
boolean isSelectionRemove = false;
if (!Boolean.parseBoolean(request.getParameter(PARAM_IS_CTRL_KEY)))
onSelectComponents.clear();
else {
isSelectionRemove = onSelectComponents.remove(child) != null;
}
IComponent[] param = onSelectComponents.keySet().toArray(new IComponent[isSelectionRemove ? onSelectComponents.size() : onSelectComponents.size() + 1]);
if (!isSelectionRemove)
param[onSelectComponents.size()] = (IComponent) child;
Object ret = callback.executeOnSelect(getJSEvent(EventType.action, 0, new Point(x, y), param));
if (ret instanceof Boolean && !((Boolean) ret).booleanValue()) {
onSelectComponents.clear();
} else {
if (!isSelectionRemove)
onSelectComponents.put((IComponent) child, id);
StringBuilder idsArray = new StringBuilder("new Array(");
Iterator<String> idsIte = onSelectComponents.values().iterator();
while (idsIte.hasNext()) {
idsArray.append('\'').append(idsIte.next()).append('\'');
if (idsIte.hasNext())
idsArray.append(',');
}
idsArray.append(')');
target.appendJavascript("Servoy.ClientDesign.attachElements(" + idsArray.toString() + ");");
}
if (Boolean.parseBoolean(request.getParameter(PARAM_IS_RIGHTCLICK))) {
callback.executeOnRightClick(getJSEvent(EventType.rightClick, 0, new Point(x, y), param));
} else if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
callback.executeOnDblClick(getJSEvent(EventType.doubleClick, 0, new Point(x, y), param));
}
}
WebEventExecutor.generateResponse(target, getComponent().getPage());
target.appendJavascript("Servoy.ClientDesign.clearClickTimer();");
return;
}
if (child instanceof IComponent) {
if (!onSelectComponents.containsKey(child)) {
onSelectComponents.put((IComponent) child, id);
}
if (action.equals(ACTION_RESIZE)) {
if (width != -1 && height != -1) {
if (child instanceof ISupportWebBounds) {
Insets paddingAndBorder = ((ISupportWebBounds) child).getPaddingAndBorder();
if (paddingAndBorder != null) {
height += paddingAndBorder.bottom + paddingAndBorder.top;
width += paddingAndBorder.left + paddingAndBorder.right;
}
}
if (child instanceof IScriptableProvider) {
((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setSize(width, height);
((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x, y);
}
if (child instanceof IProviderStylePropertyChanges)
((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
}
callback.executeOnResize(getJSEvent(EventType.onDrop, 0, new Point(x, y), new IComponent[] { (IComponent) child }));
} else if (action.equals(DraggableBehavior.ACTION_DRAG_START)) {
Object onDragAllowed = callback.executeOnDrag(getJSEvent(EventType.onDrag, 0, new Point(x, y), onSelectComponents.keySet().toArray(new IComponent[onSelectComponents.size()])));
if ((onDragAllowed instanceof Boolean && !((Boolean) onDragAllowed).booleanValue()) || (onDragAllowed instanceof Number && ((Number) onDragAllowed).intValue() == DRAGNDROP.NONE)) {
onDragComponent = null;
} else {
onDragComponent = (IComponent) child;
}
WebEventExecutor.generateResponse(target, getComponent().getPage());
return;
} else {
if (child == onDragComponent) {
if (x != -1 && y != -1) {
((IRuntimeComponent) ((IScriptableProvider) child).getScriptObject()).setLocation(x, y);
if (child instanceof IProviderStylePropertyChanges) {
// test if it is wrapped
if ((child).getParent() instanceof WrapperContainer) {
// call for the changes on the wrapper container so that it will copy the right values over
WrapperContainer wrapper = (WrapperContainer) (child).getParent();
wrapper.getStylePropertyChanges().getChanges();
wrapper.getStylePropertyChanges().setRendered();
}
((IProviderStylePropertyChanges) child).getStylePropertyChanges().setRendered();
}
}
callback.executeOnDrop(getJSEvent(EventType.onDrop, 0, new Point(x, y), onSelectComponents.keySet().toArray(new IComponent[onSelectComponents.size()])));
}
if (Boolean.parseBoolean(request.getParameter(PARAM_IS_DBLCLICK))) {
callback.executeOnDblClick(getJSEvent(EventType.doubleClick, 0, new Point(x, y), new IComponent[] { (IComponent) child }));
}
}
}
}
}
WebEventExecutor.generateResponse(target, getComponent().getPage());
target.appendJavascript("Servoy.ClientDesign.reattach();");
}
Aggregations