public Widget draw() {

    titleWidget.setText(
        Utils.getStrippedStringWithEllipsis(facility.getName())
            + " ("
            + facility.getType()
            + "): create resource");

    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");

    // form inputs
    final ExtendedTextBox nameTextBox = new ExtendedTextBox();
    final TextBox descriptionTextBox = new TextBox();

    final ListBoxWithObjects<VirtualOrganization> vosDropDown =
        new ListBoxWithObjects<VirtualOrganization>();

    // send button
    final CustomButton createButton =
        TabMenu.getPredefinedButton(ButtonType.CREATE, ButtonTranslation.INSTANCE.createResource());

    // local events fills the listbox of Vos and Slds
    JsonCallbackEvents event =
        new JsonCallbackEvents() {
          @Override
          public void onFinished(JavaScriptObject jso) {
            // fill VOs listbox
            vosDropDown.clear();
            ArrayList<VirtualOrganization> vos = JsonUtils.jsoAsList(jso);
            vos = new TableSorter<VirtualOrganization>().sortByName(vos);
            for (VirtualOrganization vo : vos) {
              vosDropDown.addItem(vo);
            }
            if (!vos.isEmpty()) createButton.setEnabled(true);
          }

          @Override
          public void onLoadingStart() {
            vosDropDown.clear();
            vosDropDown.addItem("Loading...");
            createButton.setEnabled(false);
          }

          @Override
          public void onError(PerunError error) {
            vosDropDown.clear();
            vosDropDown.addItem("Error while loading");
            createButton.setEnabled(false);
          }
        };
    // load available VOs
    final GetVos vos = new GetVos(event);
    vos.setForceAll(true);
    vos.retrieveData();

    // layout
    FlexTable layout = new FlexTable();
    layout.setStyleName("inputFormFlexTable");
    FlexCellFormatter cellFormatter = layout.getFlexCellFormatter();

    // Add some standard form options
    layout.setHTML(0, 0, "Name:");
    layout.setWidget(0, 1, nameTextBox);
    layout.setHTML(1, 0, "Description:");
    layout.setWidget(1, 1, descriptionTextBox);
    layout.setHTML(2, 0, "VO:");
    layout.setWidget(2, 1, vosDropDown);
    layout.setHTML(3, 0, "Facility:");
    layout.setHTML(3, 1, facility.getName() + " (" + facility.getType() + ")");

    for (int i = 0; i < layout.getRowCount(); i++) {
      cellFormatter.addStyleName(i, 0, "itemName");
    }

    layout.setWidth("350px");

    TabMenu menu = new TabMenu();

    final ExtendedTextBox.TextBoxValidator validator =
        new ExtendedTextBox.TextBoxValidator() {
          @Override
          public boolean validateTextBox() {
            if (nameTextBox.getTextBox().getText().trim().isEmpty()) {
              nameTextBox.setError("Name can't be empty.");
              return false;
            }
            nameTextBox.setOk();
            return true;
          }
        };
    nameTextBox.setValidator(validator);

    createButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {

            // loads new tab when creating successful, also disable button
            JsonCallbackEvents localEvents =
                new JsonCallbackEvents() {
                  public void onLoadingStart() {
                    (JsonCallbackEvents.disableButtonEvents(createButton)).onLoadingStart();
                  }

                  public void onFinished(JavaScriptObject jso) {
                    (JsonCallbackEvents.disableButtonEvents(createButton)).onFinished(jso);
                    Resource res = (Resource) jso;
                    session
                        .getTabManager()
                        .addTabToCurrentTab(
                            new CreateFacilityResourceManageServicesTabItem(facility, res), true);
                  }

                  public void onError(PerunError error) {
                    (JsonCallbackEvents.disableButtonEvents(createButton)).onError(error);
                  }
                };
            if (validator.validateTextBox()) {
              // request
              CreateResource request = new CreateResource(localEvents);
              request.createResource(
                  nameTextBox.getTextBox().getText().trim(),
                  descriptionTextBox.getText().trim(),
                  facility.getId(),
                  vosDropDown.getSelectedObject().getId());
            }
          }
        });

    menu.addWidget(createButton);

    final TabItem tab = this;
    menu.addWidget(
        TabMenu.getPredefinedButton(
            ButtonType.CANCEL,
            "",
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent clickEvent) {
                session.getTabManager().closeTab(tab, false);
              }
            }));

    vp.add(layout);
    vp.add(menu);
    vp.setCellHorizontalAlignment(menu, HasHorizontalAlignment.ALIGN_RIGHT);

    this.contentWidget.setWidget(vp);

    return getWidget();
  }
示例#2
0
  public Widget draw() {

    // show only part of title
    titleWidget.setText(Utils.getStrippedStringWithEllipsis(publication.getTitle()));

    // MAIN PANEL
    ScrollPanel sp = new ScrollPanel();
    sp.addStyleName("perun-tableScrollPanel");

    VerticalPanel vp = new VerticalPanel();
    vp.addStyleName("perun-table");
    sp.add(vp);

    // resize perun table to correct size on screen
    session.getUiElements().resizePerunTable(sp, 350, this);

    // content
    final FlexTable ft = new FlexTable();
    ft.setStyleName("inputFormFlexTable");

    if (publication.getLocked() == false) {

      ft.setHTML(1, 0, "Id / Origin:");
      ft.setHTML(2, 0, "Title:");
      ft.setHTML(3, 0, "Year:");
      ft.setHTML(4, 0, "Category:");
      ft.setHTML(5, 0, "Rank:");
      ft.setHTML(6, 0, "ISBN / ISSN:");
      ft.setHTML(7, 0, "DOI:");
      ft.setHTML(8, 0, "Full cite:");
      ft.setHTML(9, 0, "Created by:");
      ft.setHTML(10, 0, "Created date:");

      for (int i = 0; i < ft.getRowCount(); i++) {
        ft.getFlexCellFormatter().setStyleName(i, 0, "itemName");
      }
      ft.getFlexCellFormatter().setWidth(1, 0, "100px");

      final ListBoxWithObjects<Category> listbox = new ListBoxWithObjects<Category>();
      // fill listbox
      JsonCallbackEvents events =
          new JsonCallbackEvents() {
            public void onFinished(JavaScriptObject jso) {
              for (Category cat : JsonUtils.<Category>jsoAsList(jso)) {
                listbox.addItem(cat);
                // if right, selected
                if (publication.getCategoryId() == cat.getId()) {
                  listbox.setSelected(cat, true);
                }
              }
            }
          };
      FindAllCategories categories = new FindAllCategories(events);
      categories.retrieveData();

      final TextBox rank = new TextBox();
      rank.setWidth("30px");
      rank.setMaxLength(4);
      rank.setText(String.valueOf(publication.getRank()));

      final TextBox title = new TextBox();
      title.setMaxLength(1024);
      title.setText(publication.getTitle());
      title.setWidth("500px");
      final TextBox year = new TextBox();
      year.setText(String.valueOf(publication.getYear()));
      year.setMaxLength(4);
      year.setWidth("30px");
      final TextBox isbn = new TextBox();
      isbn.setText(publication.getIsbn());
      isbn.setMaxLength(32);
      final TextBox doi = new TextBox();
      doi.setText(publication.getDoi());
      doi.setMaxLength(256);
      final TextArea main = new TextArea();
      main.setText(publication.getMain());
      main.setSize("500px", "70px");
      // set max length
      main.getElement().setAttribute("maxlength", "4000");

      ft.setHTML(
          1,
          1,
          publication.getId()
              + " / <Strong>Ext. Id: </strong>"
              + publication.getExternalId()
              + " <Strong>System: </strong>"
              + publication.getPublicationSystemName());
      ft.setWidget(2, 1, title);
      ft.setWidget(3, 1, year);
      ft.setWidget(4, 1, listbox);
      if (session.isPerunAdmin()) {
        // only perunadmin can change rank
        ft.setWidget(5, 1, rank);
      } else {
        ft.setHTML(5, 1, "" + publication.getRank());
      }
      ft.setWidget(6, 1, isbn);
      ft.setWidget(7, 1, doi);
      ft.setWidget(8, 1, main);
      ft.setHTML(9, 1, String.valueOf(publication.getCreatedBy()));
      ft.setHTML(
          10,
          1,
          DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM)
              .format(new Date((long) publication.getCreatedDate())));

      // update button

      final CustomButton change =
          TabMenu.getPredefinedButton(ButtonType.SAVE, "Save changes in publication details");
      change.addClickHandler(
          new ClickHandler() {

            public void onClick(ClickEvent event) {

              Publication pub = JsonUtils.clone(publication).cast();

              if (!JsonUtils.checkParseInt(year.getText())) {
                JsonUtils.cantParseIntConfirm("YEAR", year.getText());
              } else {
                pub.setYear(Integer.parseInt(year.getText()));
              }
              if (session.isPerunAdmin()) {
                pub.setRank(Double.parseDouble(rank.getText()));
              }
              pub.setCategoryId(listbox.getSelectedObject().getId());
              pub.setTitle(title.getText());
              pub.setMain(main.getText());
              pub.setIsbn(isbn.getText());
              pub.setDoi(doi.getText());

              UpdatePublication upCall =
                  new UpdatePublication(
                      JsonCallbackEvents.disableButtonEvents(
                          change,
                          new JsonCallbackEvents() {
                            public void onFinished(JavaScriptObject jso) {
                              // refresh page content
                              Publication p = jso.cast();
                              publication = p;
                              draw();
                            }
                          }));
              upCall.updatePublication(pub);
            }
          });

      ft.setWidget(0, 0, change);

    } else {

      ft.getFlexCellFormatter().setColSpan(0, 0, 2);
      ft.setWidget(
          0,
          0,
          new HTML(
              new Image(SmallIcons.INSTANCE.lockIcon())
                  + " <strong>Publication is locked. Ask administrator to perform any changes for you at [email protected].</strong>"));

      ft.setHTML(1, 0, "Id / Origin:");
      ft.setHTML(2, 0, "Title:");
      ft.setHTML(3, 0, "Year:");
      ft.setHTML(4, 0, "Category:");
      ft.setHTML(5, 0, "Rank:");
      ft.setHTML(6, 0, "ISBN / ISSN:");
      ft.setHTML(7, 0, "DOI:");
      ft.setHTML(8, 0, "Full cite:");
      ft.setHTML(9, 0, "Created by:");
      ft.setHTML(10, 0, "Created date:");

      for (int i = 0; i < ft.getRowCount(); i++) {
        ft.getFlexCellFormatter().setStyleName(i, 0, "itemName");
      }
      ft.getFlexCellFormatter().setWidth(1, 0, "100px");

      ft.setHTML(
          1,
          1,
          publication.getId()
              + " / <Strong>Ext. Id: </strong>"
              + publication.getExternalId()
              + " <Strong>System: </strong>"
              + publication.getPublicationSystemName());
      ft.setHTML(2, 1, publication.getTitle());
      ft.setHTML(3, 1, String.valueOf(publication.getYear()));
      ft.setHTML(4, 1, publication.getCategoryName());
      ft.setHTML(5, 1, String.valueOf(publication.getRank()) + " (default is 0)");
      ft.setHTML(6, 1, publication.getIsbn());
      ft.setHTML(7, 1, publication.getDoi());
      ft.setHTML(8, 1, publication.getMain());
      ft.setHTML(9, 1, String.valueOf(publication.getCreatedBy()));
      ft.setHTML(
          10,
          1,
          DateTimeFormat.getFormat(DateTimeFormat.PredefinedFormat.DATE_TIME_MEDIUM)
              .format(new Date((long) publication.getCreatedDate())));
    }

    // LOCK / UNLOCK button for PerunAdmin

    if (session.isPerunAdmin()) {
      final CustomButton lock;
      if (publication.getLocked()) {
        lock =
            new CustomButton(
                "Unlock",
                "Allow editing of publication details (for users).",
                SmallIcons.INSTANCE.lockOpenIcon());
        ft.setWidget(0, 0, lock);
        ft.getFlexCellFormatter().setColSpan(0, 0, 1);
        ft.setWidget(
            0, 1, new HTML(new Image(SmallIcons.INSTANCE.lockIcon()) + " Publication is locked."));
      } else {
        lock =
            new CustomButton(
                "Lock",
                "Deny editing of publication details (for users).",
                SmallIcons.INSTANCE.lockIcon());
        ft.setWidget(0, 1, lock);
      }
      lock.addClickHandler(
          new ClickHandler() {
            public void onClick(ClickEvent event) {
              UpdatePublication upCall =
                  new UpdatePublication(
                      JsonCallbackEvents.disableButtonEvents(
                          lock,
                          new JsonCallbackEvents() {
                            public void onFinished(JavaScriptObject jso) {
                              // refresh page content
                              Publication p = jso.cast();
                              publication = p;
                              draw();
                            }
                          }));
              Publication p = JsonUtils.clone(publication).cast();
              p.setLocked(!publication.getLocked());
              upCall.updatePublication(p);
            }
          });
    }

    DisclosurePanel dp = new DisclosurePanel();
    dp.setWidth("100%");
    dp.setContent(ft);
    dp.setOpen(true);

    FlexTable detailsHeader = new FlexTable();
    detailsHeader.setWidget(0, 0, new Image(LargeIcons.INSTANCE.bookIcon()));
    detailsHeader.setHTML(0, 1, "<h3>Details</h3>");
    dp.setHeader(detailsHeader);

    vp.add(dp);
    vp.add(loadAuthorsSubTab());
    vp.add(loadThanksSubTab());

    this.contentWidget.setWidget(sp);

    return getWidget();
  }