@Override
  public void onClick(AjaxRequestTarget target) {
    final List<DataAccessRule> selection = rules.getSelection();
    if (selection.size() == 0) return;

    dialog.setTitle(new ParamResourceModel("confirmRemoval", this));

    // if there is something to cancel, let's warn the user about what
    // could go wrong, and if the user accepts, let's delete what's needed
    dialog.showOkCancel(
        target,
        new GeoServerDialog.DialogDelegate() {
          protected Component getContents(String id) {
            // show a confirmation panel for all the objects we have to remove
            return new ConfirmRemovalDataAccessRulePanel(id, selection) {
              @Override
              protected StringResourceModel canRemove(DataAccessRule data) {
                return SelectionDataRuleRemovalLink.this.canRemove(data);
              }
            };
          }

          protected boolean onSubmit(AjaxRequestTarget target, Component contents) {
            // cascade delete the whole selection
            Catalog catalog = GeoServerApplication.get().getCatalog();
            CascadeDeleteVisitor visitor = new CascadeDeleteVisitor(catalog);
            DataAccessRuleDAO dao = DataAccessRuleDAO.get();
            for (DataAccessRule rule : selection) {
              dao.removeRule(rule);
            }
            try {
              dao.storeRules();
            } catch (IOException e) {
              e.printStackTrace();
            }

            // the deletion will have changed what we see in the page
            // so better clear out the selection
            rules.clearSelection();
            return true;
          }

          @Override
          public void onClose(AjaxRequestTarget target) {
            // if the selection has been cleared out it's sign a deletion
            // occurred, so refresh the table
            if (rules.getSelection().size() == 0) {
              setEnabled(false);
              target.addComponent(SelectionDataRuleRemovalLink.this);
              target.addComponent(rules);
            }
          }
        });
  }
  @Override
  public void onClick(AjaxRequestTarget target) {
    // see if the user selected anything
    final List<Script> selection = tablePanel.getSelection();
    if (selection.size() == 0) return;

    dialog.setTitle(new ParamResourceModel("confirmRemoval", this));

    // if there is something to cancel, let's warn the user about what
    // could go wrong, and if the user accepts, let's delete what's needed
    dialog.showOkCancel(
        target,
        new GeoServerDialog.DialogDelegate() {
          private static final long serialVersionUID = 9062725459934129182L;

          protected Component getContents(String id) {
            // show a confirmation panel for all the objects we have to remove
            return new Label(id, "Do you want to delete these scripts?");
          }

          protected boolean onSubmit(AjaxRequestTarget target, Component contents) {
            for (Script script : selection) {
              Resource file = script.getResource();
              file.delete();
              if (script.getType().equalsIgnoreCase(ScriptType.APP.getLabel())) {
                file.parent().delete();
              }
            }

            // the deletion will have changed what we see in the page
            // so better clear out the selection
            tablePanel.clearSelection();
            return true;
          }

          @Override
          public void onClose(AjaxRequestTarget target) {
            // if the selection has been cleared out it's sign a deletion
            // occurred, so refresh the table
            if (tablePanel.getSelection().size() == 0) {
              setEnabled(false);
              target.add(ScriptSelectionRemovalLink.this);
              target.add(tablePanel);
            }
          }
        });
  }
  @Override
  public void onClick(AjaxRequestTarget target) {
    final List<GeoServerUserGroup> selection = groups.getSelection();
    if (selection.size() == 0) return;

    dialog.setTitle(new ParamResourceModel("confirmRemoval", this));

    // if there is something to cancel, let's warn the user about what
    // could go wrong, and if the user accepts, let's delete what's needed
    dialog.showOkCancel(
        target,
        delegate =
            new GeoServerDialog.DialogDelegate() {
              protected Component getContents(String id) {
                // show a confirmation panel for all the objects we have to remove
                Model<Boolean> model =
                    new Model<Boolean>(SelectionGroupRemovalLink.this.disassociateRoles);
                return removePanel =
                    new ConfirmRemovalGroupPanel(id, model, selection) {
                      @Override
                      protected IModel<String> canRemove(GeoServerUserGroup group) {
                        return SelectionGroupRemovalLink.this.canRemove(group);
                      }
                    };
              }

              protected boolean onSubmit(AjaxRequestTarget target, Component contents) {

                GeoServerUserGroupStore ugStore = null;
                try {
                  GeoServerUserGroupService ugService =
                      GeoServerApplication.get()
                          .getSecurityManager()
                          .loadUserGroupService(userGroupsServiceName);
                  ugStore = new UserGroupStoreValidationWrapper(ugService.createStore());
                  for (GeoServerUserGroup group : removePanel.getRoots()) {
                    ugStore.removeGroup(group);
                  }
                  ugStore.store();
                } catch (IOException ex) {
                  try {
                    ugStore.load();
                  } catch (IOException ex2) {
                  }
                  ;
                  throw new RuntimeException(ex);
                }

                GeoServerRoleStore gaStore = null;
                if (disassociateRoles) {
                  try {
                    gaStore =
                        GeoServerApplication.get()
                            .getSecurityManager()
                            .getActiveRoleService()
                            .createStore();
                    gaStore = new RoleStoreValidationWrapper(gaStore);
                    for (GeoServerUserGroup group : removePanel.getRoots()) {
                      List<GeoServerRole> list = new ArrayList<GeoServerRole>();
                      list.addAll(gaStore.getRolesForGroup(group.getGroupname()));
                      for (GeoServerRole role : list)
                        gaStore.disAssociateRoleFromGroup(role, group.getGroupname());
                    }
                    gaStore.store();
                  } catch (IOException ex) {
                    try {
                      gaStore.load();
                    } catch (IOException ex2) {
                    }
                    ;
                    throw new RuntimeException(ex);
                  }
                }

                // the deletion will have changed what we see in the page
                // so better clear out the selection
                groups.clearSelection();
                return true;
              }

              @Override
              public void onClose(AjaxRequestTarget target) {
                // if the selection has been cleared out it's sign a deletion
                // occurred, so refresh the table
                if (groups.getSelection().size() == 0) {
                  setEnabled(false);
                  target.addComponent(SelectionGroupRemovalLink.this);
                  target.addComponent(groups);
                }
              }
            });
  }