Search in sources :

Example 1 with VetoDragException

use of com.allen_sauer.gwt.dnd.client.VetoDragException in project activityinfo by bedatadriven.

the class DropPanelDropController method previewDropNewWidget.

private void previewDropNewWidget(final DragContext context) throws VetoDragException {
    final Template template = ((DnDLabel) context.draggable).getTemplate();
    if (template instanceof FieldTemplate) {
        final FormField formField = ((FieldTemplate) template).create();
        vetoDropIfNeeded(context);
        FormClass formClass = formDesigner.getModel().getFormClassByElementId(resourceId);
        formDesigner.getFormFieldWidgetFactory().createWidget(formClass, formField, new FieldUpdater() {

            @Override
            public void onInvalid(String errorMessage) {
            }

            @Override
            public void update(Object value) {
                formDesigner.getSavedGuard().setSaved(false);
            }
        }).then(new Function<FormFieldWidget, Void>() {

            @Nullable
            @Override
            public Void apply(@Nullable FormFieldWidget formFieldWidget) {
                final FieldWidgetContainer fieldWidgetContainer = new FieldWidgetContainer(formDesigner, formFieldWidget, formField, resourceId);
                containerMap.put(formField.getId(), fieldWidgetContainer);
                drop(fieldWidgetContainer, context, formField);
                initFieldProperties(fieldWidgetContainer, formField);
                return null;
            }
        });
    } else if (template instanceof SectionTemplate) {
        final FormSection formSection = ((SectionTemplate) template).create();
        vetoDropIfNeeded(context);
        FieldsHolderWidgetContainer widgetContainer = FieldsHolderWidgetContainer.section(formDesigner, formSection, resourceId);
        // parent drop container
        containerMap.put(resourceId, widgetContainer);
        drop(widgetContainer, context, formSection);
    } else if (template instanceof LabelTemplate) {
        final FormLabel formLabel = ((LabelTemplate) template).create();
        final LabelWidgetContainer fieldWidgetContainer = new LabelWidgetContainer(formDesigner, formLabel, resourceId);
        containerMap.put(formLabel.getId(), fieldWidgetContainer);
        drop(fieldWidgetContainer, context, formLabel);
    } else if (template instanceof SubFormTemplate) {
        final FormField formField = ((SubFormTemplate) template).create();
        vetoDropIfNeeded(context);
        FormClass subForm = formDesigner.getModel().registerNewSubform(formField.getId(), ((SubFormTemplate) template).getKind());
        subForm.setDatabaseId(formDesigner.getRootFormClass().getDatabaseId());
        subForm.setParentFormId(formDesigner.getRootFormClass().getId());
        subForm.setLabel(formField.getLabel());
        SubFormReferenceType type = (SubFormReferenceType) formField.getType();
        type.setClassId(subForm.getId());
        final FieldsHolderWidgetContainer widgetContainer = FieldsHolderWidgetContainer.subform(formDesigner, formField, subForm, formField.getId());
        // parent drop container
        containerMap.put(formField.getId(), widgetContainer);
        drop(widgetContainer.asWidget(), context);
        int widgetIndex = dropTarget.getWidgetIndex(widgetContainer.asWidget());
        formDesigner.getModel().getElementContainer(resourceId).insertElement(widgetIndex, formField);
        formDesigner.getEventBus().fireEvent(new PanelUpdatedEvent(widgetContainer, PanelUpdatedEvent.EventType.ADDED));
        formDesigner.getDragController().makeDraggable(widgetContainer.asWidget(), widgetContainer.getDragHandle());
        removePositioner();
    }
    // forbid drop of source control widget
    throw new VetoDragException();
}
Also used : FieldUpdater(org.activityinfo.ui.client.component.form.field.FieldUpdater) VetoDragException(com.allen_sauer.gwt.dnd.client.VetoDragException) LabelWidgetContainer(org.activityinfo.ui.client.component.formdesigner.container.LabelWidgetContainer) SubFormReferenceType(org.activityinfo.model.type.subform.SubFormReferenceType) FormFieldWidget(org.activityinfo.ui.client.component.form.field.FormFieldWidget) PanelUpdatedEvent(org.activityinfo.ui.client.component.formdesigner.event.PanelUpdatedEvent) FieldWidgetContainer(org.activityinfo.ui.client.component.formdesigner.container.FieldWidgetContainer) FieldsHolderWidgetContainer(org.activityinfo.ui.client.component.formdesigner.container.FieldsHolderWidgetContainer) Nullable(javax.annotation.Nullable)

Example 2 with VetoDragException

use of com.allen_sauer.gwt.dnd.client.VetoDragException in project activityinfo by bedatadriven.

the class DragMonitor method dragEnd.

public void dragEnd() {
    try {
        if (!widgetAdded && dragContext != null && dragContext.draggable instanceof DnDLabel) {
            DropControllerExtended dropController = formDesigner.getDropControllerRegistry().getRootDropController();
            // force to create positioner
            dropController.onEnter(dragContext);
            // set it to end
            dropController.setPositionerToEnd();
            // drop
            dropController.onPreviewDrop(dragContext);
        }
    } catch (VetoDragException e) {
    // do nothing
    } finally {
        reset();
    }
}
Also used : VetoDragException(com.allen_sauer.gwt.dnd.client.VetoDragException) DnDLabel(org.activityinfo.ui.client.component.formdesigner.palette.DnDLabel) DropControllerExtended(org.activityinfo.ui.client.component.formdesigner.drop.DropControllerExtended)

Example 3 with VetoDragException

use of com.allen_sauer.gwt.dnd.client.VetoDragException in project activityinfo by bedatadriven.

the class DropPanelDropController method vetoDropIfNeeded.

private void vetoDropIfNeeded(DragContext context) throws VetoDragException {
    // DnDLabel then drop is always allowed
    if (context.draggable instanceof DnDLabel && ((DnDLabel) context.draggable).getTemplate() instanceof FieldTemplate) {
        return;
    }
    if (isField(context.selectedWidgets.get(0))) {
        // field is moved
        // Once placed, fields can only be moved within the same form/subform
        ResourceId targetFormId = getId(dropTarget, FormDesignerConstants.OWNER_ID);
        ResourceId dataFieldId = getId(context.draggable, FormDesignerConstants.DATA_FIELD_ID);
        FormClass targetForm = formDesigner.getModel().getFormClass(targetFormId);
        if (hasField(targetForm, dataFieldId)) {
            return;
        } else {
            throw new VetoDragException();
        }
    }
    if (formDesigner.getModel().getElementContainer(resourceId) instanceof FormSection || formDesigner.getModel().isSubform(formDesigner.getModel().getElementContainer(resourceId).getId())) {
        // nested FormSection/SubForm brings higher complexity without comparative value.
        throw new VetoDragException();
    }
}
Also used : VetoDragException(com.allen_sauer.gwt.dnd.client.VetoDragException) ResourceId(org.activityinfo.model.resource.ResourceId)

Aggregations

VetoDragException (com.allen_sauer.gwt.dnd.client.VetoDragException)3 Nullable (javax.annotation.Nullable)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)1 FieldUpdater (org.activityinfo.ui.client.component.form.field.FieldUpdater)1 FormFieldWidget (org.activityinfo.ui.client.component.form.field.FormFieldWidget)1 FieldWidgetContainer (org.activityinfo.ui.client.component.formdesigner.container.FieldWidgetContainer)1 FieldsHolderWidgetContainer (org.activityinfo.ui.client.component.formdesigner.container.FieldsHolderWidgetContainer)1 LabelWidgetContainer (org.activityinfo.ui.client.component.formdesigner.container.LabelWidgetContainer)1 DropControllerExtended (org.activityinfo.ui.client.component.formdesigner.drop.DropControllerExtended)1 PanelUpdatedEvent (org.activityinfo.ui.client.component.formdesigner.event.PanelUpdatedEvent)1 DnDLabel (org.activityinfo.ui.client.component.formdesigner.palette.DnDLabel)1