Пример #1
0
 private ValueEditor<O> addValueEditor(boolean deleteVisible) {
   final ValueEditor<O> editor = getFreshValueEditor();
   currentEditors.add(editor);
   final int rowCount = tableField.getRowCount();
   tableField.setWidget(rowCount, 0, editor.asWidget());
   final DeleteButton deleteButton = new DeleteButton();
   deleteButton.addClickHandler(
       new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
           handleDelete(editor);
         }
       });
   tableField.setWidget(rowCount, 1, deleteButton);
   final FlexTable.FlexCellFormatter formatter = tableField.getFlexCellFormatter();
   formatter.setWidth(rowCount, 0, "100%");
   formatter.setVerticalAlignment(rowCount, 0, HasVerticalAlignment.ALIGN_TOP);
   formatter.setWidth(rowCount, 1, "30px");
   formatter.getElement(rowCount, 1).getStyle().setPaddingLeft(1, Style.Unit.PX);
   formatter.setVerticalAlignment(rowCount, 1, HasVerticalAlignment.ALIGN_TOP);
   editor.addDirtyChangedHandler(dirtyChangedHandler);
   editor.addValueChangeHandler(valueChangeHandler);
   deleteButton.setVisible(deleteVisible);
   return editor;
 }
Пример #2
0
  /** Popup the view source dialog, showing the given content. */
  public static void showSource(final String content, String name) {
    Constants constants = GWT.create(Constants.class);
    int windowWidth = Window.getClientWidth() / 2;
    int windowHeight = Window.getClientHeight() / 2;
    final FormStylePopup pop =
        new FormStylePopup(images.viewSource(), constants.ViewingSourceFor0(name), windowWidth);

    String[] rows = content.split("\n");

    FlexTable table = new FlexTable();
    for (int i = 0; i < rows.length; i++) {

      table.setHTML(i, 0, "<span style='color:grey;'>" + (i + 1) + ".</span>");
      table.setHTML(i, 1, "<span style='color:green;' >|</span>");
      table.setHTML(i, 2, addSyntaxHilights(rows[i]));
    }

    ScrollPanel scrollPanel = new ScrollPanel(table);

    scrollPanel.setHeight(windowHeight + "px");
    scrollPanel.setWidth(windowWidth + "px");

    pop.addRow(scrollPanel);

    LoadingPopup.close();

    pop.show();
  }
  @Test
  public void click_ClickkListener_NestedWidget() {
    // Given
    clicked = false;
    FlexTable t = new FlexTable();

    Button b = new Button("Wide Button");
    b.addClickListener(
        new ClickListener() {

          public void onClick(Widget sender) {
            clicked = !clicked;
          }
        });
    // add the button
    t.setWidget(0, 0, b);

    // Preconditions
    assertThat(clicked).isEqualTo(false);

    // When
    Browser.click(t.getWidget(0, 0));

    // Then
    assertThat(clicked).isEqualTo(true);
  }
Пример #4
0
  private FlexTable getFooter() {

    ft = new FlexTable();
    ft.addStyleName("perunFooter");

    FlexTable.FlexCellFormatter ftf = ft.getFlexCellFormatter();

    if (!voContact.getHTML().isEmpty()) {
      // show only if any contact is present
      voContact.setHTML(
          "<strong>"
              + ApplicationMessages.INSTANCE.supportContact()
              + "</strong> "
              + voContact.getHTML());
    }

    ft.setWidget(0, 0, voContact);
    ft.setWidget(0, 1, new HTML(PerunWebConstants.INSTANCE.footerPerunCopyright()));

    ftf.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);
    ftf.setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
    ftf.getElement(0, 1).setAttribute("style", "text-wrap: avoid;");
    ftf.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_RIGHT);
    ftf.setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_MIDDLE);

    return ft;
  }
Пример #5
0
  private FlexTable getCustomErrorWidget(PerunError error, String customText) {

    FlexTable ft = new FlexTable();
    ft.setSize("100%", "300px");
    ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>Error: </h2>" + customText);
    ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);

    return ft;
  }
  @Test
  public void text() {
    // Given
    FlexTable t = new FlexTable();

    // When
    t.setText(1, 1, "text");

    // Then
    assertThat(t.getText(1, 1)).isEqualTo("text");
  }
  @Test
  public void title() {
    // Given
    FlexTable t = new FlexTable();

    // When
    t.setTitle("title");

    // Then
    assertThat(t.getTitle()).isEqualTo("title");
  }
Пример #8
0
 private void ensureBlank() {
   if (currentEditors.isEmpty()
       || currentEditors.get(currentEditors.size() - 1).getValue().isPresent()) {
     addValueEditor(false);
   }
   for (int i = 0; i < tableField.getRowCount(); i++) {
     Widget deleteButton = tableField.getWidget(i, 1);
     if (i < tableField.getRowCount() - 1 && !deleteButton.isVisible()) {
       deleteButton.setVisible(true);
     }
   }
 }
Пример #9
0
  /**
   * Method to set proper CSS styles to menu widget. Should be called after any widget content
   * change
   */
  private void setStyles() {

    // set proper last item tag
    for (int i = 0; i < cellCount; i++) {
      if (i == 0) menu.getFlexCellFormatter().addStyleName(0, i, "tabMenu-first");
      menu.getFlexCellFormatter().addStyleName(0, i, "tabMenu");
      menu.getFlexCellFormatter().removeStyleName(0, i, "tabMenu-last");
      if (i == cellCount - 1) {
        menu.getFlexCellFormatter().addStyleName(0, i, "tabMenu-last");
      }
    }
  }
  @Test
  public void visible() {
    // Given
    FlexTable t = new FlexTable();
    // Preconditions
    assertThat(t.isVisible()).isEqualTo(true);

    // When
    t.setVisible(false);

    // Then
    assertThat(t.isVisible()).isEqualTo(false);
  }
  @Test
  public void html() {
    // Given
    FlexTable t = new FlexTable();

    // When
    t.setHTML(1, 1, "<h1>test</h1>");

    // Then
    assertThat(t.getHTML(1, 1)).isEqualTo("<h1>test</h1>");
    Element e = t.getCellFormatter().getElement(1, 1);
    assertThat(e.getChildCount()).isEqualTo(1);
    HeadingElement h1 = e.getChild(0).cast();
    assertThat(h1.getTagName()).isEqualTo("H1");
    assertThat(h1.getInnerText()).isEqualTo("test");
  }
Пример #12
0
 private void removeEditor(ValueEditor<O> editor) {
   int index = currentEditors.indexOf(editor);
   if (index == -1) {
     return;
   }
   currentEditors.remove(editor);
   tableField.removeRow(index);
 }
Пример #13
0
  /**
   * Method which adds any kind of widget into TabMenu on specific position (replace any content on
   * this position)
   *
   * @param position position in menu starting from 0
   * @param widget widget to put in menu
   */
  public void addWidget(int position, Widget widget) {

    if (position <= cellCount) {
      menu.setWidget(0, position, widget);
      if (position == cellCount) {
        cellCount++; // if new
        setStyles();
      }
    } else {
      // TODO not allowed
    }
  }
Пример #14
0
  private FlexTable getErrorWidget(PerunError error) {

    String text = "Request timeout exceeded.";
    String errorInfo = "";
    if (error != null) {
      if (error.getName().equalsIgnoreCase("VoNotExistsException")) {
        text =
            "Virtual organization with such name doesn't exists. Please check URL and try again.";
      } else if (error.getName().equalsIgnoreCase("GroupNotExistsException")) {
        text = "Group with such name doesn't exists. Please check URL and try again.";
      } else {
        text = "Error: " + error.getName();
      }
      errorInfo = error.getErrorInfo();
    }

    FlexTable ft = new FlexTable();
    ft.setSize("100%", "300px");
    ft.setHTML(0, 0, new Image(LargeIcons.INSTANCE.errorIcon()) + "<h2>" + text + "</h2>");
    ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
    ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_BOTTOM);

    ft.setHTML(1, 0, "<p>" + errorInfo);
    ft.getFlexCellFormatter().setHorizontalAlignment(1, 0, HasHorizontalAlignment.ALIGN_CENTER);
    ft.getFlexCellFormatter().setVerticalAlignment(1, 0, HasVerticalAlignment.ALIGN_TOP);

    return ft;
  }
Пример #15
0
  public VersionBrowser(
      ClientFactory clientFactory, EventBus eventBus, String uuid, boolean isPackage) {
    this.clientFactory = clientFactory;
    this.eventBus = eventBus;
    this.uuid = uuid;
    this.isPackage = isPackage;

    HorizontalPanel wrapper = new HorizontalPanel();

    ClickHandler clickHandler =
        new ClickHandler() {

          public void onClick(ClickEvent event) {
            clickLoadHistory();
          }
        };
    layout = new FlexTable();
    ClickableLabel vh = new ClickableLabel(constants.VersionHistory1(), clickHandler);
    layout.setWidget(0, 0, vh);
    layout.getCellFormatter().setStyleName(0, 0, "metadata-Widget"); // NON-NLS
    FlexCellFormatter formatter = layout.getFlexCellFormatter();
    formatter.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_LEFT);

    refresh = new ImageButton(images.refresh());

    refresh.addClickHandler(clickHandler);

    layout.setWidget(0, 1, refresh);
    formatter.setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_RIGHT);

    wrapper.setStyleName("version-browser-Border");

    wrapper.add(layout);

    layout.setWidth("100%");
    wrapper.setWidth("100%");

    initWidget(wrapper);
  }
  @Test
  public void innerFlexTable() {
    FlexTable t = new FlexTable();
    Label label1 = new Label("1st label");
    t.setWidget(0, 0, label1);
    FlexTable innerTable = new FlexTable();
    innerTable.setWidget(0, 4, new Label());
    innerTable.setWidget(0, 6, new TextBox());
    t.setWidget(0, 1, innerTable);
    Label label2 = new Label("2nd label");
    t.setWidget(0, 2, label2);

    assertThat(t.getWidget(0, 0)).isEqualTo(label1);
    assertThat(t.getWidget(0, 2)).isEqualTo(label2);
  }
Пример #17
0
 public ValueListEditorImpl(ValueEditorFactory<O> valueEditorFactory) {
   this.valueEditorFactory = valueEditorFactory;
   HTMLPanel rootElement = ourUiBinder.createAndBindUi(this);
   initWidget(rootElement);
   valueChangeHandler =
       new ValueChangeHandler<Optional<O>>() {
         @Override
         public void onValueChange(ValueChangeEvent<Optional<O>> event) {
           handleValueEditorValueChanged();
         }
       };
   dirtyChangedHandler =
       new DirtyChangedHandler() {
         @Override
         public void handleDirtyChanged(DirtyChangedEvent event) {
           handleValueEditorDirtyChanged(event);
         }
       };
   tableField.setBorderWidth(0);
   tableField.setCellPadding(0);
   tableField.setCellSpacing(0);
   ensureBlank();
 }
Пример #18
0
  public void onModuleLoad() {
    // Create table for stock data.
    stocksFlexTable.setText(0, 0, "Symbol");
    stocksFlexTable.setText(0, 1, "Price");
    stocksFlexTable.setText(0, 2, "Change");
    stocksFlexTable.setText(0, 3, "Remove");

    // Assemble Add Stock panel.
    addPanel.add(newSymbolTextBox);
    addPanel.add(addStockButton);

    // Assemble Main panel.
    mainPanel.add(stocksFlexTable);
    mainPanel.add(addPanel);
    mainPanel.add(lastUpdateLabel);

    // Associate the Main panel with the HTML host page.
    RootPanel.get("stockList").add(mainPanel);

    // Move cursor focus to the input box.
    newSymbolTextBox.setFocus(true);

    initHandlers();
  }
  @Test
  public void setText_setWidget() {
    // Tables have no explicit size -- they resize automatically on demand.
    FlexTable t = new FlexTable();

    // Put some text at the table's extremes. This forces the table to be
    // 3 by 3.
    t.setText(0, 0, "upper-left corner");
    t.setText(2, 2, "bottom-right corner");

    // Let's put a button in the middle...
    Button b = new Button("Wide Button");
    t.setWidget(1, 0, b);

    // ...and set it's column span so that it takes up the whole row.
    t.getFlexCellFormatter().setColSpan(1, 0, 3);

    // Then
    assertThat(t.getRowCount()).isEqualTo(3);
    assertThat(t.getText(2, 2)).isEqualTo("bottom-right corner");
    assertThat(t.getWidget(1, 0)).isSameAs(b);
  }
Пример #20
0
 private void clearInternal() {
   tableField.removeAllRows();
   currentEditors.clear();
   dirty = false;
 }
Пример #21
0
  /**
   * Prepares the GUI
   *
   * @param entity PerunEntity GROUP or VO
   * @param applicationType INITIAL | EXTENSION
   */
  protected void prepareGui(PerunEntity entity, String applicationType) {

    // trigger email verification as first if present in URL

    if (Location.getParameterMap().keySet().contains("m")
        && Location.getParameterMap().keySet().contains("i")) {

      String verifyI = Location.getParameter("i");
      String verifyM = Location.getParameter("m");

      if (verifyI != null && !verifyI.isEmpty() && verifyM != null && !verifyM.isEmpty()) {

        final SimplePanel verifContent = new SimplePanel();
        leftMenu.addItem(
            ApplicationMessages.INSTANCE.emailValidationMenuItem(),
            SmallIcons.INSTANCE.documentSignatureIcon(),
            verifContent);

        ValidateEmail request =
            new ValidateEmail(
                verifyI,
                verifyM,
                new JsonCallbackEvents() {
                  @Override
                  public void onLoadingStart() {
                    verifContent.clear();
                    verifContent.add(new AjaxLoaderImage());
                  }

                  @Override
                  public void onFinished(JavaScriptObject jso) {

                    BasicOverlayType obj = jso.cast();
                    if (obj.getBoolean() == true) {

                      verifContent.clear();
                      FlexTable ft = new FlexTable();
                      ft.setSize("100%", "300px");
                      ft.setHTML(
                          0,
                          0,
                          new Image(LargeIcons.INSTANCE.acceptIcon())
                              + "<h2>"
                              + ApplicationMessages.INSTANCE.emailValidationSuccess()
                              + "</h2>");
                      ft.getFlexCellFormatter()
                          .setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                      ft.getFlexCellFormatter()
                          .setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                      verifContent.add(ft);

                    } else {

                      verifContent.clear();
                      FlexTable ft = new FlexTable();
                      ft.setSize("100%", "300px");
                      ft.setHTML(
                          0,
                          0,
                          new Image(LargeIcons.INSTANCE.deleteIcon())
                              + "<h2>"
                              + ApplicationMessages.INSTANCE.emailValidationFail()
                              + "</h2>");
                      ft.getFlexCellFormatter()
                          .setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
                      ft.getFlexCellFormatter()
                          .setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
                      verifContent.add(ft);
                    }
                  }

                  @Override
                  public void onError(PerunError error) {
                    ((AjaxLoaderImage) verifContent.getWidget()).loadingError(error);
                  }
                });
        request.retrieveData();

        leftMenu.addLogoutItem();

        return;
      }
    }

    // group and extension is not allowed
    if (group != null && applicationType.equalsIgnoreCase("EXTENSION")) {

      RootLayoutPanel panel = RootLayoutPanel.get();
      panel.clear();
      FlexTable ft = new FlexTable();
      ft.setSize("100%", "300px");
      ft.setHTML(
          0,
          0,
          new Image(LargeIcons.INSTANCE.errorIcon())
              + "<h2>Error: "
              + ApplicationMessages.INSTANCE.groupMembershipCantBeExtended(
                  group.getName(), vo.getName())
              + "</h2>");
      ft.getFlexCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
      ft.getFlexCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
      panel.add(ft);
      return;
    }

    // application form page
    ApplicationFormPage formPage = new ApplicationFormPage(vo, group, applicationType);
    // even user "not yet in perun" can have some applications sent (therefore display by session
    // info)
    UsersApplicationsPage appsPage = new UsersApplicationsPage();

    // if rt test
    if ("true".equals(Location.getParameter("rttest"))) {
      TestRtReportingTabItem tabItem = new TestRtReportingTabItem();
      Widget rtTab = tabItem.draw();
      leftMenu.addItem("RT test", SmallIcons.INSTANCE.settingToolsIcon(), rtTab);
    }

    // proper menu text
    String appMenuText = ApplicationMessages.INSTANCE.applicationFormForVo(vo.getName());
    if (group != null) {
      appMenuText = ApplicationMessages.INSTANCE.applicationFormForGroup(group.getName());
    }
    if (applicationType.equalsIgnoreCase("EXTENSION")) {
      appMenuText = ApplicationMessages.INSTANCE.membershipExtensionForVo(vo.getName());
      if (group != null) {
        appMenuText = ApplicationMessages.INSTANCE.membershipExtensionForGroup(group.getName());
      }
    }

    // load list of applications first if param in session
    if ("apps".equals(Location.getParameter("page"))) {
      Anchor a =
          leftMenu.addItem(
              ApplicationMessages.INSTANCE.applications(),
              SmallIcons.INSTANCE.applicationFromStorageIcon(),
              appsPage);
      leftMenu.addItem(appMenuText, SmallIcons.INSTANCE.applicationFormIcon(), formPage);
      a.fireEvent(new ClickEvent() {});
      // appsPage.menuClick(); // load list of apps
    } else {
      Anchor a = leftMenu.addItem(appMenuText, SmallIcons.INSTANCE.applicationFormIcon(), formPage);
      leftMenu.addItem(
          ApplicationMessages.INSTANCE.applications(),
          SmallIcons.INSTANCE.applicationFromStorageIcon(),
          appsPage);
      a.fireEvent(new ClickEvent() {});
      // formPage.menuClick(); // load application form
    }

    leftMenu.addLogoutItem();
  }
Пример #22
0
  /**
   * Returns widget with authors management for publication
   *
   * @return widget
   */
  private Widget loadAuthorsSubTab() {

    DisclosurePanel dp = new DisclosurePanel();
    dp.setWidth("100%");
    dp.setOpen(true);
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    dp.setContent(vp);

    FlexTable header = new FlexTable();
    header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.userGreenIcon()));
    header.setHTML(0, 1, "<h3>Authors / Reported by</h3>");
    dp.setHeader(header);

    // menu
    TabMenu menu = new TabMenu();

    // callback
    final FindAuthorsByPublicationId call = new FindAuthorsByPublicationId(publication.getId());
    call.setCheckable(false);

    if (!publication.getLocked()) {
      // editable if not locked
      vp.add(menu);
      vp.setCellHeight(menu, "30px");
      call.setCheckable(true);
    }

    final CustomButton addButton =
        new CustomButton(
            "Add myself", "Add you as author of publication", SmallIcons.INSTANCE.addIcon());
    addButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(call);
            CreateAuthorship request =
                new CreateAuthorship(JsonCallbackEvents.disableButtonEvents(addButton, events));
            request.createAuthorship(publicationId, session.getActiveUser().getId());
          }
        });
    menu.addWidget(addButton);

    CustomButton addOthersButton =
        new CustomButton("Add others", "Add more authors", SmallIcons.INSTANCE.addIcon());
    addOthersButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            session
                .getTabManager()
                .addTabToCurrentTab(
                    new AddAuthorTabItem(publication, JsonCallbackEvents.refreshTableEvents(call)),
                    true);
          }
        });
    menu.addWidget(addOthersButton);

    // fill table
    CellTable<Author> table = call.getEmptyTable();
    call.retrieveData();

    final CustomButton removeButton =
        TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove select author(s) from publication");
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(call, table, removeButton);
    menu.addWidget(removeButton);

    removeButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            final ArrayList<Author> list = call.getTableSelectedList();
            String text =
                "Following users will be removed from publication's authors. They will lose any benefit granted by publication's rank.";
            UiElements.showDeleteConfirm(
                list,
                text,
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < list.size(); i++) {
                      // calls the request
                      if (i == list.size() - 1) {
                        DeleteAuthorship request =
                            new DeleteAuthorship(
                                JsonCallbackEvents.disableButtonEvents(
                                    removeButton, JsonCallbackEvents.refreshTableEvents(call)));
                        request.deleteAuthorship(publicationId, list.get(i).getId());
                      } else {
                        DeleteAuthorship request = new DeleteAuthorship();
                        request.deleteAuthorship(publicationId, list.get(i).getId());
                      }
                    }
                  }
                });
          }
        });

    ScrollPanel sp = new ScrollPanel();
    sp.add(table);
    table.addStyleName("perun-table");
    sp.addStyleName("perun-tableScrollPanel");

    vp.add(sp);

    return dp;
  }
Пример #23
0
  /**
   * Returns thanks management widget for publication
   *
   * @return widget
   */
  private Widget loadThanksSubTab() {

    DisclosurePanel dp = new DisclosurePanel();
    dp.setWidth("100%");
    dp.setOpen(true);
    VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");
    dp.setContent(vp);

    FlexTable header = new FlexTable();
    header.setWidget(0, 0, new Image(LargeIcons.INSTANCE.smallBusinessIcon()));
    header.setHTML(0, 1, "<h3>Acknowledgement</h3>");
    dp.setHeader(header);

    // menu
    TabMenu menu = new TabMenu();

    // callback
    final FindThanksByPublicationId thanksCall = new FindThanksByPublicationId(publicationId);
    thanksCall.setCheckable(false);

    if (!publication.getLocked()) {
      // editable if not locked
      vp.add(menu);
      vp.setCellHeight(menu, "30px");
      thanksCall.setCheckable(true);
    }

    CellTable<Thanks> table = thanksCall.getTable();

    menu.addWidget(
        TabMenu.getPredefinedButton(
            ButtonType.ADD,
            "Add acknowledgement to publication",
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                session
                    .getTabManager()
                    .addTabToCurrentTab(
                        new CreateThanksTabItem(
                            publication, JsonCallbackEvents.refreshTableEvents(thanksCall)),
                        true);
              }
            }));

    final CustomButton removeButton =
        TabMenu.getPredefinedButton(ButtonType.REMOVE, "Remove acknowledgement from publication");
    removeButton.setEnabled(false);
    JsonUtils.addTableManagedButton(thanksCall, table, removeButton);
    menu.addWidget(removeButton);

    removeButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            final ArrayList<Thanks> list = thanksCall.getTableSelectedList();
            String text = "Following acknowledgements will be removed from publication.";
            UiElements.showDeleteConfirm(
                list,
                text,
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < list.size(); i++) {
                      // calls the request
                      if (i == list.size() - 1) {
                        DeleteThanks request =
                            new DeleteThanks(
                                JsonCallbackEvents.disableButtonEvents(
                                    removeButton,
                                    JsonCallbackEvents.refreshTableEvents(thanksCall)));
                        request.deleteThanks(list.get(i).getId());
                      } else {
                        DeleteThanks request =
                            new DeleteThanks(JsonCallbackEvents.disableButtonEvents(removeButton));
                        request.deleteThanks(list.get(i).getId());
                      }
                    }
                  }
                });
          }
        });

    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel();
    sp.add(table);
    sp.addStyleName("perun-tableScrollPanel");

    vp.add(sp);

    return dp;
  }
Пример #24
0
 /** Clear all menu content (discard all widgets) !! */
 public void clear() {
   menu.clear();
 }
  public Widget draw() {

    titleWidget.setText(def.getName());
    final TabItem tab = this;

    // create main panel for content
    final FlexTable mainPage = new FlexTable();
    mainPage.setWidth("100%");

    final ExtendedTextBox description = new ExtendedTextBox();
    description.setWidth("100%");
    description.getTextBox().setText(def.getDescription());
    final ExtendedTextBox.TextBoxValidator validator =
        new ExtendedTextBox.TextBoxValidator() {
          @Override
          public boolean validateTextBox() {
            if (description.getTextBox().getText().trim().isEmpty()) {
              description.setError("Description can't be empty.");
              return false;
            }
            description.setOk();
            return true;
          }
        };

    final ExtendedTextBox displayName = new ExtendedTextBox();
    displayName.setWidth("100%");
    displayName.getTextBox().setText(def.getDisplayName());
    final ExtendedTextBox.TextBoxValidator validatorName =
        new ExtendedTextBox.TextBoxValidator() {
          @Override
          public boolean validateTextBox() {
            if (displayName.getTextBox().getText().trim().isEmpty()) {
              displayName.setError("Display name can't be empty.");
              return false;
            }
            displayName.setOk();
            return true;
          }
        };

    description.setValidator(validator);
    displayName.setValidator(validatorName);

    FlexTable attributeDetailTable = new FlexTable();
    attributeDetailTable.setStyleName("inputFormFlexTable");

    final CustomButton updateButton =
        TabMenu.getPredefinedButton(ButtonType.SAVE, "Save attribute details");
    updateButton.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {

            final ArrayList<AttributeRights> list = new ArrayList<AttributeRights>();
            for (AttributeRights r : rights) {
              if (r.getRole().equalsIgnoreCase("SELF")) {
                list.add(getRightsFromWidgets(selfRead, selfWrite, r));
              } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                list.add(getRightsFromWidgets(voRead, voWrite, r));
              } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                list.add(getRightsFromWidgets(groupRead, groupWrite, r));
              } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                list.add(getRightsFromWidgets(facilityRead, facilityWrite, r));
              }
            }

            if ((!def.getDescription().equals(description.getTextBox().getText().trim())
                || !def.getDisplayName().equals(displayName.getTextBox().getText().trim()))) {

              if (!validator.validateTextBox() || !validatorName.validateTextBox()) return;

              def.setDescription(description.getTextBox().getText().trim());
              def.setDisplayName(displayName.getTextBox().getText().trim());

              UpdateAttribute request =
                  new UpdateAttribute(
                      JsonCallbackEvents.disableButtonEvents(
                          updateButton,
                          new JsonCallbackEvents() {
                            @Override
                            public void onFinished(JavaScriptObject jso) {

                              // after update - update rights
                              SetAttributeRights request =
                                  new SetAttributeRights(
                                      JsonCallbackEvents.disableButtonEvents(
                                          updateButton,
                                          new JsonCallbackEvents() {
                                            @Override
                                            public void onFinished(JavaScriptObject jso) {
                                              enableDisableWidgets(true);
                                            }

                                            @Override
                                            public void onLoadingStart() {
                                              enableDisableWidgets(false);
                                            }

                                            @Override
                                            public void onError(PerunError error) {
                                              enableDisableWidgets(true);
                                            }
                                          }));
                              request.setAttributeRights(list);
                            }
                          }));
              request.updateAttribute(def);
            } else {

              // after update - update rights
              SetAttributeRights request =
                  new SetAttributeRights(
                      JsonCallbackEvents.disableButtonEvents(
                          updateButton,
                          new JsonCallbackEvents() {
                            @Override
                            public void onFinished(JavaScriptObject jso) {
                              enableDisableWidgets(true);
                            }

                            @Override
                            public void onLoadingStart() {
                              enableDisableWidgets(false);
                            }

                            @Override
                            public void onError(PerunError error) {
                              enableDisableWidgets(true);
                            }
                          }));
              request.setAttributeRights(list);
            }
          }
        });

    attributeDetailTable.setHTML(0, 0, "Display name:");
    attributeDetailTable.setWidget(0, 1, displayName);
    attributeDetailTable.setHTML(1, 0, "Description:");
    attributeDetailTable.setWidget(1, 1, description);
    for (int i = 0; i < attributeDetailTable.getRowCount(); i++) {
      attributeDetailTable.getFlexCellFormatter().setStyleName(i, 0, "itemName");
    }

    final FlexTable rightsTable = new FlexTable();
    rightsTable.setStyleName("inputFormFlexTable");

    rightsTable.setHTML(0, 1, "<strong>SELF</strong>");
    rightsTable.setHTML(0, 2, "<strong>VO</strong>");
    rightsTable.setHTML(0, 3, "<strong>GROUP</strong>");
    rightsTable.setHTML(0, 4, "<strong>FACILITY</strong>");

    rightsTable.setHTML(1, 0, "<strong>READ</strong>");
    rightsTable.setHTML(2, 0, "<strong>WRITE</strong>");

    rightsTable.setWidget(1, 1, selfRead);
    rightsTable.setWidget(2, 1, selfWrite);
    rightsTable.setWidget(1, 2, voRead);
    rightsTable.setWidget(2, 2, voWrite);
    rightsTable.setWidget(1, 3, groupRead);
    rightsTable.setWidget(2, 3, groupWrite);
    rightsTable.setWidget(1, 4, facilityRead);
    rightsTable.setWidget(2, 4, facilityWrite);

    rightsTable.addStyleName("centeredTable");

    TabMenu menu = new TabMenu();
    menu.addWidget(updateButton);

    menu.addWidget(
        TabMenu.getPredefinedButton(
            ButtonType.CLOSE,
            "",
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent event) {
                session.getTabManager().closeTab(tab, false);
              }
            }));

    GetAttributeRights rightsCall =
        new GetAttributeRights(
            def.getId(),
            new JsonCallbackEvents() {
              @Override
              public void onFinished(JavaScriptObject jso) {
                rights = JsonUtils.jsoAsList(jso);
                for (AttributeRights r : rights) {
                  if (r.getRole().equalsIgnoreCase("SELF")) {
                    setRightsToWidgets(selfRead, selfWrite, r);
                  } else if (r.getRole().equalsIgnoreCase("VOADMIN")) {
                    setRightsToWidgets(voRead, voWrite, r);
                  } else if (r.getRole().equalsIgnoreCase("GROUPADMIN")) {
                    setRightsToWidgets(groupRead, groupWrite, r);
                  } else if (r.getRole().equalsIgnoreCase("FACILITYADMIN")) {
                    setRightsToWidgets(facilityRead, facilityWrite, r);
                  }
                }
                enableDisableWidgets(true);
                rightsTable.setVisible(true);
              }

              @Override
              public void onError(PerunError error) {
                enableDisableWidgets(true);
                rightsTable.setVisible(false);
              }

              @Override
              public void onLoadingStart() {
                enableDisableWidgets(false);
                rightsTable.setVisible(false);
              }
            });
    rightsCall.retrieveData();

    // create new instance for jsonCall
    final GetServicesByAttrDefinition services = new GetServicesByAttrDefinition(def.getId());
    services.setCheckable(false);

    CellTable<Service> attrDefTable =
        services.getTable(
            new FieldUpdater<Service, String>() {
              @Override
              public void update(int index, Service object, String value) {
                session.getTabManager().addTab(new ServiceDetailTabItem(object));
              }
            });
    attrDefTable.setStyleName("perun-table");
    ScrollPanel scrollTable = new ScrollPanel(attrDefTable);
    scrollTable.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(scrollTable, 350, this);

    // set content to page

    mainPage.setWidget(0, 0, menu);
    mainPage.getFlexCellFormatter().setColSpan(0, 0, 2);

    mainPage.setWidget(1, 0, attributeDetailTable);
    mainPage.setWidget(1, 1, rightsTable);
    mainPage.getFlexCellFormatter().setWidth(1, 0, "50%");
    mainPage.getFlexCellFormatter().setWidth(1, 1, "50%");

    HTML title = new HTML("<p>Required by service</p>");
    title.setStyleName("subsection-heading");
    mainPage.setWidget(2, 0, title);
    mainPage.getFlexCellFormatter().setColSpan(2, 0, 2);

    // put page into scroll panel
    mainPage.setWidget(3, 0, scrollTable);
    mainPage.getFlexCellFormatter().setColSpan(3, 0, 2);
    mainPage.getFlexCellFormatter().setHeight(3, 0, "100%");

    this.contentWidget.setWidget(mainPage);

    return getWidget();
  }
  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();
  }
Пример #27
0
  /**
   * Prepares the widgets from the items as A DISPLAY FOR THE USER DEPRECATED: Use
   * GetFormItemsWithPrefilledValues instead
   *
   * @param items
   * @deprecated
   */
  public void prepareApplicationForm(final ArrayList<ApplicationFormItem> items) {

    FlexTable ft = new FlexTable();
    FlexCellFormatter fcf = ft.getFlexCellFormatter();
    String locale = "en";

    if (LocaleInfo.getCurrentLocale().getLocaleName().equals("default")) {
      locale = "en";
    } else {
      locale = "cs";
    }

    int i = 0;
    for (final ApplicationFormItem item : items) {

      String value = "";
      if (item.getShortname().equals("affiliation")
          || item.getShortname().equals("mail")
          || item.getShortname().equals("displayName")) {
        value = "from federation";
      }

      RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, value, locale);
      this.applFormGenerators.add(gen);

      if (!gen.isVisible()) {
        continue;
      }

      ItemTexts itemTexts = item.getItemTexts(locale);

      // WITH LABEL (input box ...)
      if (gen.isLabelShown()) {

        // 0 = label
        ft.setHTML(i, 0, "<strong>" + gen.getLabelOrShortname() + "</strong>");

        // 1 = widget
        Widget w = gen.getWidget();
        w.setTitle(itemTexts.getHelp());
        ft.setWidget(i, 1, w);

        // ELSE HTML COMMENT
      } else {

        ft.setWidget(i, 0, gen.getWidget());

        // colspan = 2
        fcf.setColSpan(i, 0, 2);
      }

      // format
      fcf.setHeight(i, 0, "35px");
      fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_TOP);
      fcf.setVerticalAlignment(i, 1, HasVerticalAlignment.ALIGN_MIDDLE);

      i++;
    }

    contents.setWidget(ft);
  }
Пример #28
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();
  }
Пример #29
0
  /**
   * Prepares the widgets from the items as A FORM FOR SETTINGS
   *
   * @param items
   */
  public void prepareSettings(final ArrayList<ApplicationFormItem> items) {

    // refresh table events
    final JsonCallbackEvents refreshEvents =
        new JsonCallbackEvents() {
          public void onFinished(JavaScriptObject jso) {
            prepareSettings(items);
          }
        };

    FlexTable ft = new FlexTable();
    ft.addStyleName("borderTable");
    ft.setWidth("100%");
    ft.setCellPadding(8);
    FlexCellFormatter fcf = ft.getFlexCellFormatter();

    ft.setHTML(0, 0, "<strong>Short name</strong>");
    ft.setHTML(0, 1, "<strong>Type</strong>");
    ft.setHTML(0, 2, "<strong>Preview</strong>");
    ft.setHTML(0, 3, "<strong>Edit</strong>");

    fcf.setStyleName(0, 0, "GPBYFDEFD");
    fcf.setStyleName(0, 1, "GPBYFDEFD");
    fcf.setStyleName(0, 2, "GPBYFDEFD");
    fcf.setStyleName(0, 3, "GPBYFDEFD");

    String locale = "en";

    if (LocaleInfo.getCurrentLocale().getLocaleName().equals("default")
        || LocaleInfo.getCurrentLocale().getLocaleName().equals("en")) {
      locale = "en";
    } else {
      locale = "cs";
    }

    int i = 1;
    for (final ApplicationFormItem item : items) {

      final int index = i - 1;

      // not yet set locale on config page
      RegistrarFormItemGenerator gen = new RegistrarFormItemGenerator(item, locale);

      // 0 = label
      String label = "";
      if (gen.isLabelShown()) {
        label = item.getShortname();
      }
      if (item.isRequired() == true) {
        label += "*";
      }
      ft.setHTML(i, 0, label);

      // 1 = type
      ft.setHTML(i, 1, item.getType());

      // 2 = preview
      Widget w = gen.getWidget();
      ft.setWidget(i, 2, w);

      // 3 = EDIT
      FlexTable editTable = new FlexTable();
      editTable.setStyleName("noBorder");
      ft.setWidget(i, 3, editTable);

      // color for items with unsaved changes
      if (item.wasEdited() == true) {
        ft.getFlexCellFormatter().setStyleName(i, 0, "log-changed");
        ft.getFlexCellFormatter().setStyleName(i, 1, "log-changed");
        ft.getFlexCellFormatter().setStyleName(i, 2, "log-changed");
        ft.getFlexCellFormatter().setStyleName(i, 3, "log-changed");
      }

      // mark row for deletion
      if (item.isForDelete()) {

        ft.getFlexCellFormatter().setStyleName(i, 0, "log-error");
        ft.getFlexCellFormatter().setStyleName(i, 1, "log-error");
        ft.getFlexCellFormatter().setStyleName(i, 2, "log-error");
        ft.getFlexCellFormatter().setStyleName(i, 3, "log-error");

        // undelete button
        CustomButton undelete =
            new CustomButton(
                ButtonTranslation.INSTANCE.undeleteFormItemButton(),
                ButtonTranslation.INSTANCE.undeleteFormItem(),
                SmallIcons.INSTANCE.arrowLeftIcon(),
                new ClickHandler() {
                  public void onClick(ClickEvent event) {
                    items.get(index).setForDelete(false);
                    // refresh
                    prepareSettings(items);
                  }
                });

        FlexTable undelTable = new FlexTable();
        undelTable.setStyleName("noBorder");
        undelTable.setHTML(
            0, 0, "<strong><span style=\"color:red;\">MARKED FOR DELETION</span></strong>");
        undelTable.setWidget(0, 1, undelete);
        ft.setWidget(i, 3, undelTable);
      }

      // color for new items to be saved
      if (item.getId() == 0) {
        ft.getFlexCellFormatter().setStyleName(i, 0, "log-success");
        ft.getFlexCellFormatter().setStyleName(i, 1, "log-success");
        ft.getFlexCellFormatter().setStyleName(i, 2, "log-success");
        ft.getFlexCellFormatter().setStyleName(i, 3, "log-success");
      }

      // up
      PushButton upButton =
          new PushButton(
              new Image(SmallIcons.INSTANCE.arrowUpIcon()),
              new ClickHandler() {

                public void onClick(ClickEvent event) {

                  if (index - 1 < 0) return;

                  // move it
                  items.remove(index);
                  items.add(index - 1, item);
                  item.setOrdnum(item.getOrdnum() - 1);

                  item.setEdited(true);

                  // refresh
                  prepareSettings(items);
                }
              });
      editTable.setWidget(0, 0, upButton);
      upButton.setTitle(ButtonTranslation.INSTANCE.moveFormItemUp());

      // down
      PushButton downButton =
          new PushButton(
              new Image(SmallIcons.INSTANCE.arrowDownIcon()),
              new ClickHandler() {

                public void onClick(ClickEvent event) {

                  if (index + 1 >= items.size()) return;

                  // move it
                  items.remove(index);
                  items.add(index + 1, item);
                  item.setOrdnum(item.getOrdnum() + 1);

                  item.setEdited(true);

                  // refresh
                  prepareSettings(items);
                }
              });
      editTable.setWidget(0, 1, downButton);
      downButton.setTitle(ButtonTranslation.INSTANCE.moveFormItemDown());

      // edit
      CustomButton editButton =
          new CustomButton(
              ButtonTranslation.INSTANCE.editFormItemButton(),
              ButtonTranslation.INSTANCE.editFormItem(),
              SmallIcons.INSTANCE.applicationFormEditIcon());
      editButton.addClickHandler(
          new ClickHandler() {
            public void onClick(ClickEvent event) {
              session
                  .getTabManager()
                  .addTabToCurrentTab(new EditFormItemTabItem(item, refreshEvents));
            }
          });
      editTable.setWidget(0, 2, editButton);

      // remove
      CustomButton removeButton =
          new CustomButton(
              ButtonTranslation.INSTANCE.deleteButton(),
              ButtonTranslation.INSTANCE.deleteFormItem(),
              SmallIcons.INSTANCE.deleteIcon());
      removeButton.addClickHandler(
          new ClickHandler() {

            public void onClick(ClickEvent event) {
              HTML text =
                  new HTML(
                      "<p>Deleting of form items is <strong>NOT RECOMMENDED!</strong><p>You will loose access to data users submitted in older applications within this form item!<p>Do you want to continue?");
              Confirm c =
                  new Confirm(
                      "Delete confirm",
                      text,
                      new ClickHandler() {
                        public void onClick(ClickEvent event) {
                          // mark for deletion when save changes
                          items.get(index).setForDelete(true);
                          // remove if newly created
                          if (items.get(index).getId() == 0) {
                            items.remove(index);
                          }
                          // refresh
                          prepareSettings(items);
                        }
                      },
                      true);
              c.setNonScrollable(true);
              c.show();
            }
          });
      editTable.setWidget(0, 3, removeButton);

      // format
      fcf.setHeight(i, 0, "28px");
      fcf.setVerticalAlignment(i, 0, HasVerticalAlignment.ALIGN_MIDDLE);
      fcf.setVerticalAlignment(i, 1, HasVerticalAlignment.ALIGN_MIDDLE);
      fcf.setVerticalAlignment(i, 2, HasVerticalAlignment.ALIGN_MIDDLE);

      i++;
    }

    contents.setWidget(ft);
  }
Пример #30
0
  public Widget draw() {

    this.titleWidget.setText(Utils.getStrippedStringWithEllipsis(facility.getName()));

    // main widget panel
    final VerticalPanel vp = new VerticalPanel();
    vp.setSize("100%", "100%");

    AbsolutePanel dp = new AbsolutePanel();
    final FlexTable menu = new FlexTable();
    menu.setCellSpacing(5);

    // Add facility information
    menu.setWidget(0, 0, new Image(LargeIcons.INSTANCE.databaseServerIcon()));
    Label facilityName = new Label();
    facilityName.setText(Utils.getStrippedStringWithEllipsis(facility.getName(), 40));
    facilityName.setStyleName("now-managing");
    facilityName.setTitle(facility.getName());
    menu.setWidget(0, 1, facilityName);

    menu.setHTML(0, 2, "&nbsp;");
    menu.getFlexCellFormatter().setWidth(0, 2, "25px");

    int column = 3;

    final JsonCallbackEvents events =
        new JsonCallbackEvents() {
          public void onFinished(JavaScriptObject jso) {
            new GetEntityById(
                    PerunEntity.FACILITY,
                    facilityId,
                    new JsonCallbackEvents() {
                      public void onFinished(JavaScriptObject jso) {
                        facility = jso.cast();
                        open();
                        draw();
                      }
                    })
                .retrieveData();
          }
        };

    CustomButton change =
        new CustomButton(
            "",
            ButtonTranslation.INSTANCE.editFacilityDetails(),
            SmallIcons.INSTANCE.applicationFormEditIcon());
    change.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            // prepare confirm content
            session
                .getTabManager()
                .addTabToCurrentTab(new EditFacilityDetailsTabItem(facility, events));
          }
        });
    menu.setWidget(0, column, change);

    column++;

    menu.setHTML(0, column, "&nbsp;");
    menu.getFlexCellFormatter().setWidth(0, column, "25px");
    column++;

    if (JsonUtils.isExtendedInfoVisible()) {
      menu.setHTML(
          0,
          column,
          "<strong>ID:</strong><br/><span class=\"inputFormInlineComment\">"
              + facility.getId()
              + "</span>");
      column++;
      menu.setHTML(0, column, "&nbsp;");
      menu.getFlexCellFormatter().setWidth(0, column, "25px");
      column++;
    }

    menu.setHTML(
        0,
        column,
        "<strong>Description:</strong><br/><span class=\"inputFormInlineComment\">"
            + facility.getDescription()
            + "&nbsp;</span>");

    dp.add(menu);
    vp.add(dp);
    vp.setCellHeight(dp, "30px");

    // TAB PANEL

    tabPanel.clear();
    tabPanel.add(new FacilityResourcesTabItem(facility), "Resources");
    tabPanel.add(new FacilityAllowedGroupsTabItem(facility), "Allowed Groups");
    tabPanel.add(new FacilityStatusTabItem(facility), "Services status");
    tabPanel.add(new FacilitySettingsTabItem(facility), "Services settings");
    tabPanel.add(new FacilityDestinationsTabItem(facility), "Services destinations");
    tabPanel.add(new FacilityHostsTabItem(facility), "Hosts");
    tabPanel.add(new FacilityManagersTabItem(facility), "Managers");
    tabPanel.add(new FacilitySecurityTeamsTabItem(facility), "Security teams");
    tabPanel.add(new FacilityBlacklistTabItem(facility), "Blacklist");
    tabPanel.add(new FacilityOwnersTabItem(facility), "Owners");

    // Resize must be called after page fully displays
    Scheduler.get()
        .scheduleDeferred(
            new Command() {
              @Override
              public void execute() {
                tabPanel.finishAdding();
              }
            });

    vp.add(tabPanel);

    this.contentWidget.setWidget(vp);
    return getWidget();
  }