Example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow closeCurrent

List of usage examples for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow closeCurrent

Introduction

In this page you can find the example usage for org.apache.wicket.extensions.ajax.markup.html.modal ModalWindow closeCurrent.

Prototype

public static void closeCurrent(final IPartialPageRequestHandler target) 

Source Link

Document

Hides the modal window.

Usage

From source file:ro.nextreports.server.web.drilldown.DrillDownEntityPanel.java

License:Apache License

private void init() {
    add(new Label("legend", getString("ActionContributor.Drill.name")));
    add(new Label("entityName", new Model<String>(entity.getName())));

    addTable();/*from w  w  w .  ja  va 2 s.  com*/

    dialog = new ModalWindow("dialog");
    add(dialog);

    final AjaxLink addLink = new AjaxLink("addDrill") {

        @Override
        public void onClick(AjaxRequestTarget target) {

            dialog.setTitle(getString("ActionContributor.Drill.addTitle"));
            dialog.setInitialWidth(400);
            dialog.setUseInitialHeight(false);
            dialog.setContent(new AddDrillDownPanel(dialog.getContentId(), entity) {

                @Override
                public void onAddDrillDownEntity(AjaxRequestTarget target, Form form,
                        DrillDownEntity drillEntity) {
                    try {
                        ModalWindow.closeCurrent(target);
                        List<DrillDownEntity> drillEntities = getDrillDownEntities(entity);
                        drillEntities.add(drillEntity);
                        storageService.modifyEntity(entity);
                        target.add(table);
                        refreshAddLink(target);
                    } catch (Exception e) {
                        e.printStackTrace();
                        form.error(e.getMessage());
                    }
                }

                @Override
                public void onCancel(AjaxRequestTarget target) {
                    ModalWindow.closeCurrent(target);
                }

            });
            dialog.show(target);
        }

        @Override
        public boolean isEnabled() {
            List<DrillDownEntity> list = getDrillDownEntities(entity);
            if (list.size() == 0) {
                return true;
            } else {
                DrillDownEntity last = list.get(list.size() - 1);
                return (last.getUrl() == null);
            }
        }

    };
    addLink.setOutputMarkupId(true);
    add(addLink);

    add(new AjaxConfirmLink("deleteDrill") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            try {
                List<DrillDownEntity> drillEntities = getDrillDownEntities(entity);
                if (drillEntities.size() > 0) {
                    drillEntities.remove(drillEntities.size() - 1);
                    storageService.modifyEntity(entity);
                    target.add(table);
                    target.add(addLink);
                }
            } catch (Exception e) {
                e.printStackTrace();
                error(e.getMessage());
            }
        }

        @Override
        public String getMessage() {
            return getString("ActionContributor.Drill.deleteLast");
        }
    });

    add(new AjaxLink("cancel") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            EntityBrowserPanel panel = findParent(EntityBrowserPanel.class);
            panel.backwardWorkspace(target);
        }
    });
}

From source file:ro.nextreports.server.web.schedule.destination.MailPanel.java

License:Apache License

private void addTableLinks() {
    AjaxLink<String> emailLink = new AjaxLink<String>("email") {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override/*  w  w  w.ja v  a2s  . c  om*/
        public void onClick(AjaxRequestTarget target) {
            dialog.setTitle(getString("ActionContributor.Run.destination.email"));
            dialog.setInitialWidth(300);
            dialog.setUseInitialHeight(false);
            AddEmailPanel addEmailPanel = new AddEmailPanel(FormPanel.CONTENT_ID) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onAdd(AjaxRequestTarget target, Recipient recipient) {
                    ModalWindow.closeCurrent(target);
                    provider.addRecipient(recipient);
                    target.add(recipientsPanel);
                }

            };

            dialog.setContent(new FormPanel(dialog.getContentId(), addEmailPanel, true));
            dialog.show(target);
        }

    };
    add(emailLink);

    AjaxLink<String> userLink = new AjaxLink<String>("user") {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public void onClick(AjaxRequestTarget target) {
            dialog.setTitle(getString("ActionContributor.Run.destination.user"));
            dialog.setInitialWidth(300);
            dialog.setUseInitialHeight(false);
            AddEmailUserPanel addEmailUserPanel = new AddEmailUserPanel(FormPanel.CONTENT_ID) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onAdd(AjaxRequestTarget target, Recipient recipient) {
                    ModalWindow.closeCurrent(target);
                    provider.addRecipient(recipient);
                    target.add(recipientsPanel);
                }

            };
            dialog.setContent(new FormPanel(dialog.getContentId(), addEmailUserPanel, true));
            dialog.show(target);
        }

    };
    add(userLink);

    AjaxLink<String> groupLink = new AjaxLink<String>("group") {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("unchecked")
        @Override
        public void onClick(AjaxRequestTarget target) {
            dialog.setTitle(getString("ActionContributor.Run.destination.group"));
            dialog.setInitialWidth(300);
            dialog.setUseInitialHeight(false);
            AddEmailGroupPanel addEmailGroupPanel = new AddEmailGroupPanel(FormPanel.CONTENT_ID) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onAdd(AjaxRequestTarget target, Recipient recipient) {
                    ModalWindow.closeCurrent(target);
                    provider.addRecipient(recipient);
                    target.add(recipientsPanel);
                }

            };
            dialog.setContent(new FormPanel(dialog.getContentId(), addEmailGroupPanel, true));
            dialog.show(target);
        }

    };
    add(groupLink);

}

From source file:ro.nextreports.server.web.schedule.TemplatePanel.java

License:Apache License

private void init() {

    validator = createValidator();//from  w  w  w  . j  a v a2s .  c  o m

    add(new Label("templateLabel", getString("ActionContributor.Run.template.name")));

    ChoiceRenderer<ReportRuntimeTemplate> nameRenderer = new ChoiceRenderer<ReportRuntimeTemplate>("name") {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getDisplayValue(ReportRuntimeTemplate template) {
            if (template == null) {
                return getString("nullValid");
            }
            return template.getName();
        }

    };

    final DropDownChoice<ReportRuntimeTemplate> templateChoice = new DropDownChoice<ReportRuntimeTemplate>(
            "template", new PropertyModel<ReportRuntimeTemplate>(this, "template"),
            new LoadableDetachableModel<List<ReportRuntimeTemplate>>() {

                @Override
                protected List<ReportRuntimeTemplate> load() {
                    List<ReportRuntimeTemplate> templates = new ArrayList<ReportRuntimeTemplate>();
                    try {
                        templates = reportService.getReportTemplatesById(report.getId());
                    } catch (Exception e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        error(e.getMessage());
                    }
                    return templates;
                }
            }, nameRenderer);

    templateChoice.setNullValid(true);

    templateChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            if (template != null) {
                new ChangeValuesTemplateEvent(templateChoice, report, template.getReportRuntime(),
                        template.getShortcutType(), target).fire();
                runtimeModel.setShortcutType(template.getShortcutType());
                target.add(shortcutChoice);

                // when a template is changed then the shortcut is changed
                ShortcutType shortcutType = runtimeModel.getShortcutType();
                new ChangeShortcutTemplateEvent(shortcutChoice, shortcutType, target).fire();

                timeType = TimeShortcutType.getTypeName(runtimeModel.getShortcutType().getTimeType());
                boolean visible = (runtimeModel.getShortcutType().getType() == -1);
                shortcutLastContainer.setVisible(visible);
                target.add(shortcutLastContainer);
            } else {
                runtimeModel.setShortcutType(ShortcutType.NONE);
                shortcutLastContainer.setVisible(false);
                target.add(shortcutChoice);
                target.add(shortcutLastContainer);
            }
        }
    });
    add(templateChoice);

    final TextField<String> nameField = new TextField<String>("name",
            new PropertyModel<String>(this, "runtimeModel.templateName"));
    nameField.setRequired(false);
    nameField.setEnabled(false);
    nameField.setOutputMarkupId(true);
    nameField.setLabel(Model.of(getString("ActionContributor.Run.template.info")));
    add(nameField);

    add(new Label("saveTemplateLabel", getString("ActionContributor.Run.template.save")));
    final CheckBox saveTemplate = new CheckBox("saveTemplate",
            new PropertyModel<Boolean>(this, "runtimeModel.saveTemplate"));
    saveTemplate.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            boolean save = runtimeModel.isSaveTemplate();
            nameField.setEnabled(save);
            nameField.setRequired(save);
            if (save) {
                nameField.add(validator);
            } else {
                nameField.remove(validator);
            }
            target.add(nameField);
        }
    });
    add(saveTemplate);

    WebMarkupContainer shortcutContainer = new WebMarkupContainer("shortcutContainer");
    boolean visible = ReportUtil.hasIntervalParameters(storageService.getSettings(), report);
    shortcutContainer.setVisible(visible);
    add(shortcutContainer);

    shortcutContainer.add(new Label("withShortcut", getString("ActionContributor.Run.template.interval")));

    ChoiceRenderer<ShortcutType> shortcutRenderer = new ChoiceRenderer<ShortcutType>("name") {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getDisplayValue(ShortcutType shortcut) {
            return getString(
                    "ActionContributor.Run.template.interval." + ShortcutType.getName(shortcut.getType()));
        }

    };
    shortcutChoice = new DropDownChoice<ShortcutType>("shortcutType",
            new PropertyModel<ShortcutType>(this, "runtimeModel.shortcutType"), ShortcutType.getTypes(),
            shortcutRenderer);
    shortcutChoice.setNullValid(false);
    shortcutChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            ShortcutType shortcutType = runtimeModel.getShortcutType();
            new ChangeShortcutTemplateEvent(shortcutChoice, shortcutType, target).fire();
            boolean visible = (runtimeModel.getShortcutType().getType() == -1);
            shortcutLastContainer.setVisible(visible);
            target.add(shortcutLastContainer);
        }
    });
    shortcutChoice.setOutputMarkupId(true);
    shortcutContainer.add(shortcutChoice);

    shortcutLastContainer = new WebMarkupContainer("shortcutLastContainer");
    shortcutLastContainer.setVisible(false);
    shortcutLastContainer.setOutputMarkupPlaceholderTag(true);
    shortcutContainer.add(shortcutLastContainer);

    timeUnitsField = new TextField<Integer>("timeUnits",
            new PropertyModel<Integer>(this, "runtimeModel.shortcutType.timeUnits"));
    timeUnitsField.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            new ChangeShortcutTemplateEvent(shortcutChoice, runtimeModel.getShortcutType(), target).fire();
        }
    });
    timeUnitsField.setRequired(false);
    shortcutLastContainer.add(timeUnitsField);

    ChoiceRenderer<String> timeTypeRenderer = new ChoiceRenderer<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Object getDisplayValue(String type) {
            return getString(type.toLowerCase());
        }

    };
    timeTypeChoice = new DropDownChoice<String>("timeType", new PropertyModel<String>(this, "timeType"),
            TimeShortcutType.getTypeNames(), timeTypeRenderer);
    timeTypeChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        protected void onUpdate(AjaxRequestTarget target) {
            runtimeModel.getShortcutType().setTimeType(TimeShortcutType.getTypeUnit(timeType));
            new ChangeShortcutTemplateEvent(shortcutChoice, runtimeModel.getShortcutType(), target).fire();
        }
    });
    shortcutLastContainer.add(timeTypeChoice);

    if (runtimeModel.getShortcutType().getType() == -1) {
        shortcutLastContainer.setVisible(true);
    }

    add(new AjaxLink<Void>("removeTemplate") {

        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            ModalWindow dialog = findParent(BasePage.class).getDialog();
            dialog.setTitle(getString("ActionContributor.Run.template.remove"));
            dialog.setInitialWidth(350);
            dialog.setInitialHeight(200);
            dialog.setResizable(true);

            final ManageTemplatesPanel panel = new ManageTemplatesPanel(dialog.getContentId(), report) {

                private static final long serialVersionUID = 1L;

                @Override
                public void onDelete(AjaxRequestTarget target, List<ReportRuntimeTemplate> selected) {
                    ModalWindow.closeCurrent(target);
                    if (selected.size() == 0) {
                        return;
                    }
                    List<String> ids = new ArrayList<String>();
                    for (ReportRuntimeTemplate rt : selected) {
                        ids.add(rt.getId());
                    }
                    try {
                        storageService.removeEntitiesById(ids);
                    } catch (NotFoundException e) {
                        e.printStackTrace();
                        LOG.error(e.getMessage(), e);
                        error(e.getMessage());
                    }
                    template = null;
                    target.add(templateChoice);
                }

                @Override
                public void onCancel(AjaxRequestTarget target) {
                    ModalWindow.closeCurrent(target);
                }

            };
            dialog.setContent(panel);
            dialog.show(target);
        }

    });
}

From source file:ro.nextreports.server.web.schedule.time.IntervalFieldPanel.java

License:Apache License

@SuppressWarnings("unchecked")
public IntervalFieldPanel(String id, final IModel model, final String entityType, final String intType,
        boolean required) {
    super(id, model);

    String text = getLabelText(entityType);

    intervalText = new TextField<String>("intervalText", model);
    intervalText.setOutputMarkupId(true);
    if (required) {
        intervalText.setRequired(true);/*from   w  w w .j a va 2  s . com*/
        intervalText.setLabel(new Model<String>(text));
    }

    // validators to respect the pattern
    if (SelectIntervalPanel.DAY_ENTITY.equals(entityType)) {
        String day = "(0[1-9]|[1-9]|[12][0-9]|3[01])";
        String pattern = day + "{1}(," + day + ")*|" + day + "{1}(-" + day + "){0,1}";
        intervalText.add(new PatternValidator(pattern));
    } else if (SelectIntervalPanel.HOUR_ENTITY.equals(entityType)) {
        String hour = "(0[0-9]|[0-9]|1[0-9]|2[0-3])";
        String pattern = hour + "{1}(," + hour + ")*|" + hour + "{1}(-" + hour + "){0,1}";
        intervalText.add(new PatternValidator(pattern));
    } else if (SelectIntervalPanel.MONTH_ENTITY.equals(entityType)) {
        String month = "(0[1-9]|[1-9]|1[0-2])";
        String pattern = month + "{1}(," + month + ")*|" + month + "{1}(-" + month + "){0,1}";
        intervalText.add(new PatternValidator(pattern));
    } else if (SelectIntervalPanel.DAY_OF_WEEK_ENTITY.equals(entityType)) {
        String weekDay = "(Sun|Mon|Tue|Wed|Thu|Fri|Sat)";
        String pattern = weekDay + "{1}(," + weekDay + ")*|" + weekDay + "{1}(-" + weekDay + "){0,1}";
        intervalText.add(new PatternValidator(pattern));
    }
    // validator to respect the order and uniqness
    intervalText.add(new IntervalFieldStringValidator(entityType));

    add(intervalText);

    modal = new ModalWindow("modal");
    add(modal);

    add(setLink = new AjaxLink("set") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            final TimeValues timeValues = getTimeValues(intervalText.getModelObject());
            modal.setTitle(new Model<String>(getString("select") + " " + getLabelText(entityType)));
            modal.setInitialWidth(450);
            modal.setInitialHeight(300);
            modal.setContent(new SelectIntervalPanel(modal.getContentId(), entityType, intType, timeValues) {
                protected void onCancel(AjaxRequestTarget target) {
                    ModalWindow.closeCurrent(target);
                }

                @SuppressWarnings("unchecked")
                protected void onSet(AjaxRequestTarget target) {
                    ModalWindow.closeCurrent(target);
                    //System.out.println("entityType=" + entityType + "  intervalType=" + timeValues.getIntervalType() + "  values=" + timeValues.getDiscreteValues());
                    String interval = getTimeEntity(entityType, timeValues);
                    model.setObject(interval);
                    //System.out.println("*** interval=" + interval);
                    target.add(intervalText);
                }
            });
            modal.show(target);
        }
    });
}

From source file:ro.nextreports.server.web.security.SecurityPanel.java

License:Apache License

public SecurityPanel(String id, final Entity entity) {
    super(id, new Model<Entity>(entity));

    add(new Label("path", StorageUtil.getPathWithoutRoot(entity.getPath())));
    final FeedbackPanel feedbackPanel = new FeedbackPanel("feedback");
    feedbackPanel.setOutputMarkupId(true);
    add(feedbackPanel);//from w  w w  .  j a v a 2s .  com

    List<IColumn<AclEntry, String>> columns = new ArrayList<IColumn<AclEntry, String>>();
    columns.add(new NameColumn());
    columns.add(new ActionsColumn());
    columns.add(new TypeColumn());
    columns.add(new BooleanImagePropertyColumn<AclEntry>(new Model<String>(getString("Permission.read")),
            "read", "read"));
    columns.add(new BooleanImagePropertyColumn<AclEntry>(new Model<String>(getString("Permission.execute")),
            "execute", "execute"));
    columns.add(new BooleanImagePropertyColumn<AclEntry>(new Model<String>(getString("Permission.write")),
            "write", "write"));
    columns.add(new BooleanImagePropertyColumn<AclEntry>(new Model<String>(getString("Permission.delete")),
            "delete", "delete"));
    columns.add(new BooleanImagePropertyColumn<AclEntry>(new Model<String>(getString("Permission.security")),
            "security", "security"));

    AclEntryDataProvider dataProvider = new AclEntryDataProvider(entity.getId());
    table = new BaseTable<AclEntry>("table", columns, dataProvider, 300);
    table.setOutputMarkupId(true);
    add(table);

    dialog = new ModalWindow("dialog");
    add(dialog);

    add(new AjaxLink("addUser") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            AclEntry aclEntry = new AclEntry(AclEntry.USER_TYPE);
            List<String> notGrantedUsers;
            try {
                notGrantedUsers = getNotGrantedUsersById(entity.getId(), aclEntry);
            } catch (Exception e) {
                // TODO
                e.printStackTrace();
                error(e.getMessage());
                return;
            }

            if (notGrantedUsers.isEmpty()) {
                error(getString("SecurityPanel.allUsersGranted"));
                target.add(feedbackPanel);
                return;
            }

            dialog.setTitle(getString("SecurityPanel.addUser"));
            dialog.setInitialWidth(300);
            dialog.setUseInitialHeight(false);
            // TODO duplication code with modify user
            dialog.setContent(new UserAclEntryPanel(dialog.getContentId(), entity, aclEntry, notGrantedUsers) {

                @Override
                public void onUserAclEntry(AjaxRequestTarget target, AclEntry aclEntry, boolean recursive) {
                    try {
                        ModalWindow.closeCurrent(target);
                        securityService.grantUser(entity.getPath(), aclEntry.getName(),
                                aclEntry.getPermissions(), recursive);
                        target.add(table);
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        error(e.getMessage());
                    }
                }

                @Override
                public void onCancel(AjaxRequestTarget target) {
                    ModalWindow.closeCurrent(target);
                }

            });
            dialog.show(target);
        }

    });

    add(new AjaxLink("addGroup") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            AclEntry aclEntry = new AclEntry(AclEntry.GROUP_TYPE);
            List<String> notGrantedGroups;
            try {
                notGrantedGroups = getNotGrantedGroups(entity.getPath(), aclEntry);
            } catch (Exception e) {
                // TODO
                e.printStackTrace();
                error(e.getMessage());
                return;
            }

            if (notGrantedGroups.isEmpty()) {
                error(getString("SecurityPanel.allGroupsGranted"));
                target.add(feedbackPanel);
                return;
            }

            dialog.setTitle(getString("SecurityPanel.addGroup"));
            dialog.setInitialWidth(300);
            dialog.setUseInitialHeight(false);
            // TODO duplication code with modify group
            dialog.setContent(
                    new GroupAclEntryPanel(dialog.getContentId(), entity, aclEntry, notGrantedGroups) {

                        @Override
                        public void onGroupAclEntry(AjaxRequestTarget target, AclEntry aclEntry,
                                boolean recursive) {
                            try {
                                ModalWindow.closeCurrent(target);
                                securityService.grantGroup(entity.getPath(), aclEntry.getName(),
                                        aclEntry.getPermissions(), recursive);
                                target.add(table);
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                                error(e.getMessage());
                            }
                        }

                        @Override
                        public void onCancel(AjaxRequestTarget target) {
                            ModalWindow.closeCurrent(target);
                        }

                    });
            dialog.show(target);
        }

    });

    add(new AjaxLink("cancel") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            onCancel(target);
        }
    });
}

From source file:sf.wicketlearningapplication.pages.BugForm.java

License:Creative Commons License

BugForm(final String id, final IModel<Bug> model) {
    super(id, model);

    final boolean isInEditMode = model != null;
    if (!isInEditMode) {
        setModel(new CompoundPropertyModel<Bug>(new Bug()));
    }/*  w  w w  .j  a  v  a  2 s .c o  m*/

    final TextField<String> summary = new RequiredTextField<String>("summary");
    summary.add(StringValidator.maximumLength(256));
    add(summary);

    final List<Severity> severities = Arrays.asList(Severity.values());
    final DropDownChoice<Severity> severity = new DropDownChoice<Severity>("severity", severities);
    severity.setRequired(true);
    add(severity);

    final TextField<Date> dueByDate = new TextField<Date>("dueByDate");
    dueByDate.add(new DatePicker());
    dueByDate.add(DateValidator.minimum(new Date()));
    add(dueByDate);

    final TextField<Integer> estimatedHours = new TextField<Integer>("estimatedHours", Integer.class);
    estimatedHours.add(new MinimumValidator<Integer>(0));
    add(estimatedHours);

    final List<User> users = new UserDao(entityManagerFactory).findAll();
    final DropDownChoice<User> owner = new DropDownChoice<User>("owner", users,
            new ChoiceRenderer<User>("name", "id"));
    add(owner);

    if (isInEditMode) {
        AjaxFormValidatingBehavior.addToAllFormComponents(this, "onblur");

        final IndicatingAjaxButton saveButton = new IndicatingAjaxButton("save", BugForm.this) {

            private static final long serialVersionUID = 7949306415616423528L;

            @Override
            protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
                ModalWindow.closeCurrent(target);
                final BugDao bugDao = new BugDao(entityManagerFactory);
                bugDao.save((Bug) form.getModelObject());
            }

        };
        add(saveButton);
    } else {
        final Button createButton = new Button("save", new Model<String>("Create")) {

            private static final long serialVersionUID = 7949306415616423528L;

            @Override
            public void onSubmit() {
                final Bug bug = (Bug) getForm().getModelObject();
                final BugDao bugDao = new BugDao(entityManagerFactory);
                bugDao.save(bug);
                BugForm.this.setModel(new CompoundPropertyModel<Bug>(new Bug()));
            }

        };
        add(createButton);
    }

}