protected void initUI(StyleInfo style) {
    IModel<StyleInfo> styleModel =
        new CompoundPropertyModel(
            style != null
                ? new StyleDetachableModel(style)
                : getCatalog().getFactory().createStyle());

    styleForm =
        new Form("form", styleModel) {
          @Override
          protected void onSubmit() {
            super.onSubmit();
            onStyleFormSubmit();
          }
        };
    styleForm.setMarkupId("mainForm");
    add(styleForm);

    styleForm.add(nameTextField = new TextField("name"));
    nameTextField.setRequired(true);

    DropDownChoice<WorkspaceInfo> wsChoice =
        new DropDownChoice("workspace", new WorkspacesModel(), new WorkspaceChoiceRenderer());
    wsChoice.setNullValid(true);
    if (!isAuthenticatedAsAdmin()) {
      wsChoice.setNullValid(false);
      wsChoice.setRequired(true);
    }

    styleForm.add(wsChoice);
    styleForm.add(editor = new CodeMirrorEditor("SLD", new PropertyModel(this, "rawSLD")));
    // force the id otherwise this blasted thing won't be usable from other forms
    editor.setTextAreaMarkupId("editor");
    editor.setOutputMarkupId(true);
    editor.setRequired(true);
    styleForm.add(editor);

    if (style != null) {
      try {
        setRawSLD(readFile(style));
      } catch (IOException e) {
        // ouch, the style file is gone! Register a generic error message
        Session.get()
            .error(new ParamResourceModel("sldNotFound", this, style.getFilename()).getString());
      }
    }

    // style copy functionality
    styles =
        new DropDownChoice(
            "existingStyles", new Model(), new StylesModel(), new StyleChoiceRenderer());
    styles.setOutputMarkupId(true);
    styles.add(
        new AjaxFormComponentUpdatingBehavior("onchange") {

          @Override
          protected void onUpdate(AjaxRequestTarget target) {
            styles.validate();
            copyLink.setEnabled(styles.getConvertedInput() != null);
            target.addComponent(copyLink);
          }
        });
    styleForm.add(styles);
    copyLink = copyLink();
    copyLink.setEnabled(false);
    styleForm.add(copyLink);

    uploadForm = uploadForm(styleForm);
    uploadForm.setMultiPart(true);
    uploadForm.setMaxSize(Bytes.megabytes(1));
    uploadForm.setMarkupId("uploadForm");
    add(uploadForm);

    uploadForm.add(fileUploadField = new FileUploadField("filename"));

    add(validateLink());
    Link cancelLink =
        new Link("cancel") {
          @Override
          public void onClick() {
            setResponsePage(StylePage.class);
          }
        };
    add(cancelLink);
  }
 @Override
 protected void onDetach() {
   listener.onDetach(this);
   super.onDetach();
 }
 @Override
 protected void onInitialize() {
   super.onInitialize();
   listener.onInitialize(this);
 }
 @Override
 protected void onConfigure() {
   super.onConfigure();
   listener.onConfigure(this);
 }
  Component chooserButton(Form form) {
    AjaxSubmitLink link =
        new AjaxSubmitLink("chooser") {
          @Override
          protected void onSubmit(AjaxRequestTarget target, Form form) {
            dialog.setTitle(new ParamResourceModel("chooseFile", this));
            dialog.showOkCancel(
                target,
                new GeoServerDialog.DialogDelegate() {

                  @Override
                  protected Component getContents(String id) {
                    // use what the user currently typed
                    File file = null;
                    if (!fileField.getInput().trim().equals("")) {
                      file = new File(fileField.getInput());
                      if (!file.exists()) file = null;
                    }

                    GeoServerFileChooser chooser =
                        new GeoServerFileChooser(id, new Model(file)) {
                          @Override
                          protected void fileClicked(File file, AjaxRequestTarget target) {
                            SpatialFilePanel.this.file = file.getAbsolutePath();

                            fileField.clearInput();
                            fileField.setModelObject(file.getAbsolutePath());

                            target.addComponent(fileField);
                            dialog.close(target);
                          }
                        };
                    // chooser.setFilter(new Model(new ExtensionFile"(".shp")));
                    return chooser;
                  }

                  @Override
                  protected boolean onSubmit(AjaxRequestTarget target, Component contents) {
                    GeoServerFileChooser chooser = (GeoServerFileChooser) contents;
                    file = ((File) chooser.getDefaultModelObject()).getAbsolutePath();

                    // clear the raw input of the field won't show the new model value
                    fileField.clearInput();
                    // fileField.setModelObject(file);

                    target.addComponent(fileField);
                    return true;
                  }

                  @Override
                  public void onClose(AjaxRequestTarget target) {
                    // update the field with the user chosen value
                    target.addComponent(fileField);
                  }
                });
          }
        };
    // otherwise the link won't trigger when the form contents are not valid
    link.setDefaultFormProcessing(false);
    return link;
  }