public boolean isAuthorized() {

    if (session.isFacilityAdmin(facility.getId())) {
      return true;
    } else {
      return false;
    }
  }
예제 #2
0
 /** Retrieve data from RPC */
 public void retrieveData() {
   String param = "";
   if (service != null) {
     param = "service=" + service.getId();
   } else if (facility != null) {
     param = "facility=" + facility.getId();
   }
   JsonClient js = new JsonClient();
   js.retrieveData(JSON_URL, param, this);
 }
  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();
  }
 /** @param facility facility which should have resource added */
 public CreateFacilityResourceTabItem(Facility facility) {
   this.facility = facility;
   this.facilityId = facility.getId();
 }
예제 #5
0
 /**
  * Compares to another object
  *
  * @param o Object to compare
  * @return true, if they are the same
  */
 public final boolean equals(Facility o) {
   return o.getId() == this.getId();
 }
예제 #6
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();
  }
예제 #7
0
 /**
  * Creates a tab instance
  *
  * @param facility
  */
 public FacilityDetailTabItem(Facility facility) {
   this.facility = facility;
   this.facilityId = facility.getId();
   this.tabPanel = new TabPanelForTabItems(this);
 }