Esempio n. 1
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() {

    this.titleWidget.setText(
        Utils.getStrippedStringWithEllipsis(service.getName()) + ": exec services");

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

    TabMenu menu = new TabMenu();
    vp.add(menu);
    vp.setCellHeight(menu, "30px");

    final ListExecServices callback = new ListExecServices(serviceId);
    CellTable<ExecService> table =
        callback.getTable(
            new FieldUpdater<ExecService, String>() {
              public void update(int index, ExecService object, String value) {
                // manage details of exec services (dependency, status, update values?)
                session.getTabManager().addTab(new ViewExecServiceTabItem(object));
              }
            });

    // refresh event after deletion
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(callback);

    menu.addWidget(
        TabMenu.getPredefinedButton(
            ButtonType.CREATE,
            ButtonTranslation.INSTANCE.createExecService(),
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent clickEvent) {
                session.getTabManager().addTabToCurrentTab(new AddExecServiceTabItem(service));
              }
            }));

    final CustomButton deleteButton =
        TabMenu.getPredefinedButton(
            ButtonType.REMOVE, ButtonTranslation.INSTANCE.deleteSelectedExecServices());
    menu.addWidget(deleteButton);
    deleteButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            final ArrayList<ExecService> execToRemove = callback.getTableSelectedList();
            UiElements.showDeleteConfirm(
                execToRemove,
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE
                    for (int i = 0; i < execToRemove.size(); i++) {
                      if (i == execToRemove.size() - 1) {
                        DeleteExecService request =
                            new DeleteExecService(
                                JsonCallbackEvents.disableButtonEvents(deleteButton, events));
                        request.deleteExecService(execToRemove.get(i).getId());
                      } else {
                        DeleteExecService request =
                            new DeleteExecService(
                                JsonCallbackEvents.disableButtonEvents(deleteButton));
                        request.deleteExecService(execToRemove.get(i).getId());
                      }
                    }
                  }
                });
          }
        });

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

    session.getUiElements().resizePerunTable(sp, 350, this);

    final CustomButton enable =
        TabMenu.getPredefinedButton(ButtonType.ENABLE, "Enable selected exec service(s)");
    final CustomButton disable =
        TabMenu.getPredefinedButton(ButtonType.DISABLE, "Disable selected exec service(s)");

    menu.addWidget(enable);
    menu.addWidget(disable);

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

            ArrayList<ExecService> list = callback.getTableSelectedList();
            for (int i = 0; i < list.size(); i++) {

              ExecService e = list.get(i);
              if (i < list.size() - 1) {
                // any call
                if (!e.isEnabled()) {
                  UpdateExecService request =
                      new UpdateExecService(JsonCallbackEvents.disableButtonEvents(enable));
                  e.setEnabled(true);
                  request.updateExecService(e);
                }
              } else {
                // last call
                if (!e.isEnabled()) {
                  UpdateExecService request =
                      new UpdateExecService(JsonCallbackEvents.disableButtonEvents(enable, events));
                  e.setEnabled(true);
                  request.updateExecService(e);
                }
              }
            }
          }
        });

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

            ArrayList<ExecService> list = callback.getTableSelectedList();
            for (int i = 0; i < list.size(); i++) {

              ExecService e = list.get(i);
              if (i < list.size() - 1) {
                // any call
                if (e.isEnabled()) {
                  UpdateExecService request =
                      new UpdateExecService(JsonCallbackEvents.disableButtonEvents(disable));
                  e.setEnabled(false);
                  request.updateExecService(e);
                }
              } else {
                // last call
                if (e.isEnabled()) {
                  UpdateExecService request =
                      new UpdateExecService(
                          JsonCallbackEvents.disableButtonEvents(disable, events));
                  e.setEnabled(false);
                  request.updateExecService(e);
                }
              }
            }
          }
        });

    deleteButton.setEnabled(false);
    enable.setEnabled(false);
    disable.setEnabled(false);
    JsonUtils.addTableManagedButton(callback, table, deleteButton);
    JsonUtils.addTableManagedButton(callback, table, enable);
    JsonUtils.addTableManagedButton(callback, table, disable);

    vp.add(sp);
    vp.setCellHeight(sp, "100%");

    // add tabs to the main panel
    this.contentWidget.setWidget(vp);

    return getWidget();
  }
 /**
  * Tab with ExecServices management for selected service
  *
  * @param service service to get ExecServices for
  */
 public ServiceExecServicesTabItem(Service service) {
   this.service = service;
   this.serviceId = service.getId();
 }
Esempio n. 4
0
 /** Retrieve data from RPC */
 public void retrieveData() {
   JsonClient js = new JsonClient();
   js.retrieveData(JSON_URL, "facility=" + facilityId + "&service=" + service.getId(), this);
 }