private void buildTable(int pageSize) {
    CellTable.Resources resources = GWT.create(TableResources.class);

    cellTable = new CellTable<SearchResultRow>(pageSize, resources);
    cellTable.setWidth("100%", true);
    // Initialize columns
    for (int i = 0; i < this.fieldDescs.size(); i++) {
      SearchResultFieldDesc desc = this.fieldDescs.get(i);
      if (desc.getTableDisplay() != TableDisplay.MANDATORY) {
        continue;
      }
      final int index = i;
      TextColumn<SearchResultRow> col =
          new TextColumn<SearchResultRow>() {
            @Override
            public String getValue(SearchResultRow data) {
              if (data == null) {
                return "";
              } else {
                return data.getField(index);
              }
            }
          };
      col.setSortable(desc.getSortable());
      cellTable.addColumn(col, desc.getTitle());
      cellTable.setColumnWidth(col, desc.getWidth());
      tableColIdx.add(i);
    }

    cellTable.setSelectionModel(selectionModel);
  }
  /** This is the entry point method. */
  @Override
  public void onModuleLoad() {
    initFetcherAPI();

    cellTable = new CellTable<PlaceRecord>(PlaceRecord.KEY_PROVIDER);
    RootPanel.get("locationContainer").add(cellTable);
    cellTable.setWidth("100%", true);
    initTableColumns();
    //
    locationService.getPlaceAddress(
        new Date(),
        new AsyncCallback<List<PlaceRecord>>() {

          @Override
          public void onFailure(Throwable caught) {
            DialogBox message = new DialogBox();
            message.setTitle("failed to get place");
            message.setText(caught.getMessage());
            message.show();
          }

          @Override
          public void onSuccess(List<PlaceRecord> records) {
            List<PlaceRecord> list = dataProvider.getList();
            for (PlaceRecord palce : records) {
              list.add(palce);
            }
            dataProvider.addDataDisplay(cellTable);
            cellTable.setPageSize(list.size());
          }
        });

    processedRow = -1;
    Timer fetchTimer =
        new Timer() {
          @Override
          public void run() {
            fetchData();
          }
        };
    fetchTimer.scheduleRepeating(REFRESH_INTERVAL);

    Timer saveTimer =
        new Timer() {
          @Override
          public void run() {
            saveData();
          }
        };
    saveTimer.scheduleRepeating(SAVE_INTERVAL);
  }
Beispiel #3
0
 public PhotoView() {
   initWidget(uiBinder.createAndBindUi(this));
   cellTable.setWidth("100%", true);
   pager.setDisplay(cellTable);
   initColumns();
   cellTable.addRangeChangeHandler(
       new RangeChangeEvent.Handler() {
         @Override
         public void onRangeChange(RangeChangeEvent event) {
           AppContext.getInstance()
               .getEventBus()
               .fireEvent(new ShowPhotoRange(event.getNewRange()));
         }
       });
 }
Beispiel #4
0
  private void setupTestDataGrid() {
    testDataGrid = new CellTable<TaskDataDto>();
    testDataGrid.setWidth("500px");
    testDataGrid.setEmptyTableWidget(new Label("No Tests"));

    // Add a selection model so we can select cells.
    final SelectionModel<TaskDataDto> selectionModel =
        new MultiSelectionModel<TaskDataDto>(
            new ProvidesKey<TaskDataDto>() {
              @Override
              public Object getKey(TaskDataDto item) {
                return item.getTaskName();
              }
            });
    testDataGrid.setSelectionModel(
        selectionModel, DefaultSelectionEventManager.<TaskDataDto>createCheckboxManager());

    // Checkbox column. This table will uses a checkbox column for selection.
    // Alternatively, you can call dataGrid.setSelectionEnabled(true) to enable mouse selection.
    Column<TaskDataDto, Boolean> checkColumn =
        new Column<TaskDataDto, Boolean>(new CheckboxCell(true, false)) {
          @Override
          public Boolean getValue(TaskDataDto object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
          }
        };
    testDataGrid.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    testDataGrid.setColumnWidth(checkColumn, 40, Style.Unit.PX);

    testDataGrid.addColumn(
        new TextColumn<TaskDataDto>() {
          @Override
          public String getValue(TaskDataDto object) {
            return object.getTaskName();
          }
        },
        "Tests");
    testDataGrid.setRowData(Collections.EMPTY_LIST);
  }
  public Widget draw() {

    this.titleWidget.setText(
        Utils.getStrippedStringWithEllipsis(group.getName()) + ": " + "ext sources");

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

    // HORIZONTAL MENU
    TabMenu menu = new TabMenu();
    menu.addWidget(UiElements.getRefreshButton(this));

    // get VO resources
    final GetGroupExtSources extSources = new GetGroupExtSources(groupId);

    // refresh table event
    final JsonCallbackEvents events = JsonCallbackEvents.refreshTableEvents(extSources);

    // create ext source button
    CustomButton addButton =
        TabMenu.getPredefinedButton(
            ButtonType.ADD,
            true,
            ButtonTranslation.INSTANCE.addExtSource(),
            new ClickHandler() {
              public void onClick(ClickEvent event) {
                session
                    .getTabManager()
                    .addTabToCurrentTab(new AddGroupExtSourceTabItem(groupId), true);
              }
            });
    if (session.isVoAdmin(voId)) {
      menu.addWidget(addButton);
    }

    final CustomButton removeButton =
        TabMenu.getPredefinedButton(
            ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeExtSource());
    removeButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            final ArrayList<ExtSource> extSourcesToRemove = extSources.getTableSelectedList();
            String text =
                "Following external sources will be removed from Group. You won't be able to import members from them anymore.";
            UiElements.showDeleteConfirm(
                extSourcesToRemove,
                text,
                new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent clickEvent) {
                    // TODO - SHOULD HAVE ONLY ONE CALLBACK TO CORE !!
                    for (int i = 0; i < extSourcesToRemove.size(); i++) {
                      RemoveExtSource request;
                      if (i == extSourcesToRemove.size() - 1) {
                        request =
                            new RemoveExtSource(
                                JsonCallbackEvents.disableButtonEvents(removeButton, events));
                      } else {
                        request =
                            new RemoveExtSource(
                                JsonCallbackEvents.disableButtonEvents(removeButton));
                      }
                      request.removeGroupExtSource(groupId, extSourcesToRemove.get(i).getId());
                    }
                  }
                });
          }
        });
    if (session.isVoAdmin(voId)) {
      menu.addWidget(removeButton);
    }

    // authorization - enable buttons for vo admin only.
    if (!session.isVoAdmin(voId)) {
      addButton.setEnabled(false);
      removeButton.setEnabled(false);
      extSources.setCheckable(false);
    }

    menu.addFilterWidget(
        new ExtendedSuggestBox(extSources.getOracle()),
        new PerunSearchEvent() {
          @Override
          public void searchFor(String text) {
            extSources.filterTable(text);
          }
        },
        "Filter external sources by name or type");

    // add menu to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");

    CellTable<ExtSource> table = extSources.getTable();

    if (session.isVoAdmin(voId)) {
      removeButton.setEnabled(false);
      JsonUtils.addTableManagedButton(extSources, table, removeButton);
    }

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

    vp.add(sp);

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

    this.contentWidget.setWidget(vp);

    return getWidget();
  }
  /**
   * The table that holds the basic friends list.
   *
   * @param result
   */
  private void setTable(GetLogResult result) {
    if (cellTable.getColumnCount() == 4) {
      dataList.clear();
      dataList = dataProvider.getList();
      for (GetLogType friend : result.getResults()) dataList.add(friend);
    } else {
      TextColumn<GetLogType> victimColumn =
          new TextColumn<GetLogType>() {
            @Override
            public String getValue(GetLogType log) {
              if (log.getFbVictimName() != null) return log.getFbVictimName();
              else return "";
            }
          };
      victimColumn.setSortable(true);

      TextColumn<GetLogType> commentPermalink =
          new TextColumn<GetLogType>() {
            @Override
            public String getValue(GetLogType log) {
              if (log.getFbCommentPermalink() != null) return log.getFbCommentPermalink();
              else return "";
            }
          };
      commentPermalink.setSortable(true);

      TextColumn<GetLogType> comment =
          new TextColumn<GetLogType>() {
            @Override
            public String getValue(GetLogType log) {
              if (log.getFbComment() != null) return log.getFbComment();
              else return "";
            }
          };
      comment.setSortable(true);

      TextColumn<GetLogType> date =
          new TextColumn<GetLogType>() {
            @Override
            public String getValue(GetLogType log) {
              if (log.getDate() != null) return log.getDate().toString();
              else return "";
            }
          };
      date.setSortable(true);

      cellTable.addColumn(victimColumn, "Name");
      cellTable.addColumn(commentPermalink, "Comment Link");
      cellTable.addColumn(comment, "Comment Text");
      cellTable.addColumn(date, "Time");

      // Fix column sizes for stupid facebook
      cellTable.setWidth("675px", true);
      cellTable.setColumnWidth(victimColumn, 10.0, Unit.PCT);
      cellTable.setColumnWidth(commentPermalink, 40.0, Unit.PCT);
      cellTable.setColumnWidth(comment, 40.0, Unit.PCT);
      cellTable.setColumnWidth(date, 10.0, Unit.PCT);

      // Attach provider
      dataProvider.addDataDisplay(cellTable);
      dataList = dataProvider.getList();
      for (GetLogType friend : result.getResults()) dataList.add(friend);

      // Set row count
      cellTable.setRowCount(dataList.size());
      cellTable.setPageSize(20);

      ListHandler<GetLogType> columnSortHandler = new ListHandler<GetLogType>(dataList);
      columnSortHandler.setComparator(
          victimColumn,
          new Comparator<GetLogType>() {

            @Override
            public int compare(GetLogType o1, GetLogType o2) {
              if (o1 == o2) {
                return 0;
              }

              // Compare the name columns.
              if (o1 != null) {
                return (o2 != null) ? o1.getFbVictimName().compareTo(o2.getFbVictimName()) : 1;
              }
              return -1;
            }
          });

      columnSortHandler.setComparator(
          commentPermalink,
          new Comparator<GetLogType>() {

            @Override
            public int compare(GetLogType o1, GetLogType o2) {
              if (o1 == o2) {
                return 0;
              }

              // Compare the role columns.
              if (o1 != null) {
                return (o2 != null)
                    ? o1.getFbCommentPermalink().compareTo(o2.getFbCommentPermalink())
                    : 1;
              }
              return -1;
            }
          });

      columnSortHandler.setComparator(
          comment,
          new Comparator<GetLogType>() {
            @Override
            public int compare(GetLogType o1, GetLogType o2) {
              if (o1 == o2) {
                return 0;
              }

              // Compare the role columns.
              if (o1 != null) {
                return (o2 != null) ? o1.getFbComment().compareTo(o2.getFbComment()) : 1;
              }
              return -1;
            }
          });

      columnSortHandler.setComparator(
          date,
          new Comparator<GetLogType>() {

            @Override
            public int compare(GetLogType o1, GetLogType o2) {
              if (o1 == o2) {
                return 0;
              }

              // Compare the role columns.
              if (o1 != null) {
                return (o2 != null) ? o1.getDate().compareTo(o2.getDate()) : 1;
              }
              return -1;
            }
          });

      cellTable.addColumnSortHandler(columnSortHandler);
      cellTable.getColumnSortList().push(date);
      cellTable.setPageSize(5000);
    }
  }
  public DialogListaPontoEncontro(
      final InfoCaronaServerAsync controller, final String idSessao, final String idCarona) {
    novosPontos = "";
    listaNovosPontosEncontros = new ArrayList<InfoPontoEncontro>();
    this.idCarona = idCarona;
    this.controller = controller;

    setText("Pontos de Encontro - ID: " + idCarona);
    setAnimationEnabled(true);
    setGlassEnabled(true);
    center();

    VerticalPanel panelListaPontoEncontro = new VerticalPanel();
    tabelaPontoEncontro = new CellTable<InfoPontoEncontro>();
    tabelaPontoEncontro.setWidth("400px");
    dataProvider = new ListDataProvider<InfoPontoEncontro>();

    SimplePager.Resources pagerResources = GWT.create(SimplePager.Resources.class);
    SimplePager pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 0, true);
    pager.setDisplay(tabelaPontoEncontro);
    pager.setPageSize(5);

    TextColumn<InfoPontoEncontro> colunaIdPontoEncontro =
        new TextColumn<InfoPontoEncontro>() {
          @Override
          public String getValue(InfoPontoEncontro pontoEncontro) {
            return pontoEncontro.getIdPontoEncontro();
          }
        };

    TextColumn<InfoPontoEncontro> colunaPontosEncontro =
        new TextColumn<InfoPontoEncontro>() {
          @Override
          public String getValue(InfoPontoEncontro pontoEncontro) {
            return pontoEncontro.getPontoEncontro();
          }
        };

    tabelaPontoEncontro.addColumn(colunaPontosEncontro, "Pontos de Encontro");
    listaPontoEncontros = new ArrayList<InfoPontoEncontro>();
    populaTabela();

    HorizontalPanel hPanel01 = new HorizontalPanel();
    final TextBox boxNovoPontoEncontro = new TextBox();
    boxNovoPontoEncontro.setWidth("200px");
    boxNovoPontoEncontro.setStyleName("boxModificada");

    Button buttonAdicionarOutroPontoEncontro = new Button();
    buttonAdicionarOutroPontoEncontro.setStyleName("botaoModificado");
    buttonAdicionarOutroPontoEncontro.setTitle("Adicionar Sugestão");
    buttonAdicionarOutroPontoEncontro.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            if (boxNovoPontoEncontro.getText().trim().equals("")) {
              DialogMensagemUsuario dialogErro =
                  new DialogMensagemUsuario("Falhou", "Ponto de Encontro Inválido");
              dialogErro.show();
            } else {
              novosPontos += boxNovoPontoEncontro.getText().trim() + ";";
              InfoPontoEncontro novoPontoEncontro =
                  new InfoPontoEncontro("00", boxNovoPontoEncontro.getText().trim());
              boxNovoPontoEncontro.setText("");

              listaNovosPontosEncontros.add(novoPontoEncontro);
              listaPontoEncontros = new ArrayList<InfoPontoEncontro>();

              for (InfoPontoEncontro novoPonto : listaNovosPontosEncontros) {
                listaPontoEncontros.add(novoPonto);
              }

              populaTabela();
            }
          }
        });

    Image imageFiltro = new Image("imagens/adicionar.png");
    imageFiltro.setSize("15px", "15px");
    buttonAdicionarOutroPontoEncontro.getElement().appendChild(imageFiltro.getElement());

    Button buttonSalvarNovosPontos = new Button("Salvar");
    buttonSalvarNovosPontos.setStyleName("botaoModificado");
    buttonSalvarNovosPontos.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            controller.cadastrarNovosPontosEncontro(
                idSessao,
                idCarona,
                novosPontos,
                new AsyncCallback<String>() {

                  @Override
                  public void onFailure(Throwable caught) {
                    DialogMensagemUsuario dialogSucess =
                        new DialogMensagemUsuario("Erro", caught.getMessage());
                    dialogSucess.show();
                  }

                  @Override
                  public void onSuccess(String result) {
                    DialogMensagemUsuario dialogSucess =
                        new DialogMensagemUsuario(
                            "ID: " + result, "Pontos de Encontro Cadastrados com Sucesso!");
                    dialogSucess.show();
                    hide();
                  }
                });
          }
        });

    Button buttonFechar = new Button("Fechar");
    buttonFechar.setStyleName("botaoModificado");

    buttonFechar.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            hide();
          }
        });

    colunaPontosEncontro.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);

    hPanel01.setCellVerticalAlignment(boxNovoPontoEncontro, HasVerticalAlignment.ALIGN_BOTTOM);
    hPanel01.setCellVerticalAlignment(buttonSalvarNovosPontos, HasVerticalAlignment.ALIGN_TOP);
    hPanel01.setCellVerticalAlignment(
        buttonAdicionarOutroPontoEncontro, HasVerticalAlignment.ALIGN_TOP);
    hPanel01.setCellVerticalAlignment(buttonFechar, HasVerticalAlignment.ALIGN_TOP);
    hPanel01.setCellHorizontalAlignment(boxNovoPontoEncontro, HasHorizontalAlignment.ALIGN_CENTER);
    hPanel01.setCellHorizontalAlignment(
        buttonSalvarNovosPontos, HasHorizontalAlignment.ALIGN_CENTER);
    hPanel01.setCellHorizontalAlignment(
        buttonAdicionarOutroPontoEncontro, HasHorizontalAlignment.ALIGN_CENTER);
    hPanel01.setCellHorizontalAlignment(buttonFechar, HasHorizontalAlignment.ALIGN_CENTER);
    hPanel01.setWidth("100%");
    hPanel01.setSpacing(6);

    hPanel01.add(boxNovoPontoEncontro);
    hPanel01.add(buttonAdicionarOutroPontoEncontro);
    hPanel01.add(buttonSalvarNovosPontos);
    hPanel01.add(buttonFechar);

    panelListaPontoEncontro.add(tabelaPontoEncontro);
    panelListaPontoEncontro.add(pager);
    panelListaPontoEncontro.add(hPanel01);

    panelListaPontoEncontro.setCellVerticalAlignment(
        tabelaPontoEncontro, HasVerticalAlignment.ALIGN_MIDDLE);
    panelListaPontoEncontro.setCellVerticalAlignment(pager, HasVerticalAlignment.ALIGN_MIDDLE);

    panelListaPontoEncontro.setCellHorizontalAlignment(
        tabelaPontoEncontro, HasHorizontalAlignment.ALIGN_CENTER);
    panelListaPontoEncontro.setCellHorizontalAlignment(pager, HasHorizontalAlignment.ALIGN_CENTER);
    panelListaPontoEncontro.setSpacing(8);

    setWidget(panelListaPontoEncontro);
  }
  public Widget draw() {

    titleWidget.setText(Utils.getStrippedStringWithEllipsis(group.getName()) + ": settings");

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

    final TabMenu menu = new TabMenu();

    // Adds menu to the main panel
    vp.add(menu);
    vp.setCellHeight(menu, "30px");

    // IDS
    final Map<String, Integer> ids = new HashMap<String, Integer>();
    ids.put("group", groupId);

    // define GET ATTRIBUTES callback
    final GetAttributesV2 jsonCallback = new GetAttributesV2();
    jsonCallback.setIds(ids);
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
      jsonCallback.setCheckable(false);
    final CellTable<Attribute> table = jsonCallback.getEmptyTable();
    table.setWidth("100%");
    table.addStyleName("perun-table");
    ScrollPanel sp = new ScrollPanel(table);
    sp.addStyleName("perun-tableScrollPanel");
    session.getUiElements().resizePerunTable(sp, 350, this);
    vp.add(sp);

    // define GET RES. REQ ATTRIBUTES callback
    final GetResourceRequiredAttributesV2 reqAttrs =
        new GetResourceRequiredAttributesV2(
            null, JsonCallbackEvents.passDataToAnotherCallback(jsonCallback));

    // GROUP RESOURCES LISTBOX
    final ListBoxWithObjects<Resource> resourceDropDown = new ListBoxWithObjects<Resource>();
    resourceDropDown.setTitle(
        "By selecting a resource you will switch to either group-resource or member-resource setting (you must pick member too)");

    // fill table with group attributes on page load
    if (lastSelectedMemberId == 0 && lastSelectedResourceId == 0) {
      jsonCallback.retrieveData();
    } else {
      // load attrs by listbox selection after calls are done
      Scheduler.get()
          .scheduleFixedPeriod(
              new Scheduler.RepeatingCommand() {
                @Override
                public boolean execute() {
                  // load proper table if something was selected
                  if (resCallDone && memCallDone) {
                    // trigger change event
                    DomEvent.fireNativeEvent(Document.get().createChangeEvent(), resourceDropDown);
                    return false;
                  }
                  return true;
                }
              },
              200);
    }

    // fill resources listbox
    if (resources == null) {
      // get assigned resources
      GetAssignedResources resources =
          new GetAssignedResources(
              groupId,
              PerunEntity.GROUP,
              new JsonCallbackEvents() {
                public void onFinished(JavaScriptObject jso) {
                  ArrayList<Resource> resources = JsonUtils.jsoAsList(jso);
                  resourceDropDown.clear();
                  if (resources != null && !resources.isEmpty()) {
                    resources = new TableSorter<Resource>().sortByName(resources);
                    resourceDropDown.addNotSelectedOption();
                    for (int i = 0; i < resources.size(); i++) {
                      resourceDropDown.addItem(resources.get(i));
                      if (lastSelectedResourceId == resources.get(i).getId()) {
                        resourceDropDown.setSelected(resources.get(i), true);
                      }
                    }
                  } else {
                    resourceDropDown.addItem("No resources available");
                  }
                  resCallDone = true;
                }

                public void onError(PerunError error) {
                  resourceDropDown.clear();
                  resourceDropDown.addItem("Error while loading");
                  resCallDone = true;
                }

                public void onLoadingStart() {
                  resCallDone = false;
                  resourceDropDown.clear();
                  resourceDropDown.addItem("Loading...");
                }
              });
      resources.retrieveData();

    } else {
      // use predefined resources
      resourceDropDown.addNotSelectedOption();
      resources = new TableSorter<Resource>().sortByName(resources);
      resourceDropDown.addAllItems(resources);
    }

    // GROUP MEMBERS LISTBOX
    final ListBoxWithObjects<RichMember> membersDropDown = new ListBoxWithObjects<RichMember>();
    membersDropDown.setTitle(
        "By selecting a member you will switch to either member or member-resource settings (you must pick resource too)");

    // fill members listbox
    GetGroupRichMembers members =
        new GetGroupRichMembers(
            groupId,
            new JsonCallbackEvents() {
              public void onFinished(JavaScriptObject jso) {
                ArrayList<RichMember> mems = JsonUtils.jsoAsList(jso);
                membersDropDown.clear();
                if (mems != null && !mems.isEmpty()) {
                  mems = new TableSorter<RichMember>().sortByName(mems);
                  membersDropDown.addNotSelectedOption();
                  for (int i = 0; i < mems.size(); i++) {
                    membersDropDown.addItem(mems.get(i));
                    if (mems.get(i).getId() == lastSelectedMemberId) {
                      membersDropDown.setSelected(mems.get(i), true);
                    }
                  }
                } else {
                  membersDropDown.addItem("No members available");
                }
                memCallDone = true;
              }

              public void onError(PerunError error) {
                membersDropDown.clear();
                membersDropDown.addItem("Error while loading");
                memCallDone = true;
              }

              public void onLoadingStart() {
                memCallDone = false;
                membersDropDown.clear();
                membersDropDown.addItem("Loading...");
              }
            });
    members.retrieveData();

    // CHECKBOXES "FOR ALL MEMBERS"
    final CheckBox memChb = new CheckBox();
    memChb.setText("To all members");
    memChb.setVisible(false);
    memChb.setTitle("Uses this setting for all members of this group.");
    memChb.setValue(false);

    // SAVE CHANGES BUTTON
    final CustomButton saveChangesButton =
        TabMenu.getPredefinedButton(
            ButtonType.SAVE, ButtonTranslation.INSTANCE.saveChangesInAttributes());
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
      saveChangesButton.setEnabled(false);

    // click handler to save group and member-user attributes
    final ClickHandler saveAttrsClickHandler =
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();

            if (UiElements.cantSaveEmptyListDialogBox(list)) {

              // refresh table and disable button a event for GetAttributes
              final JsonCallbackEvents events =
                  JsonCallbackEvents.disableButtonEvents(
                      saveChangesButton, JsonCallbackEvents.refreshTableEvents(jsonCallback));

              if (memChb.getValue() == true) {
                // to all members selected
                UiElements.generateInfo(
                    WidgetTranslation.INSTANCE.saveConfirmTitle(),
                    "Same value(s) for selected attribute(s) will be set to ALL members of group.",
                    new ClickHandler() {
                      public void onClick(ClickEvent event) {
                        ArrayList<RichMember> memList = membersDropDown.getAllObjects();
                        for (int i = 0; i < memList.size(); i++) {
                          SetAttributes request = new SetAttributes();
                          if (i == memList.size() - 1) {
                            request.setEvents(events);
                          } else {
                            request.setEvents(
                                JsonCallbackEvents.disableButtonEvents(saveChangesButton));
                          }
                          Map<String, Integer> ids = new HashMap<String, Integer>();
                          ids.put("member", memList.get(i).getId());
                          ids.put("workWithUserAttributes", 1);
                          request.setAttributes(ids, list);
                        }
                      }
                    });
              } else {
                // just one group / memeber
                SetAttributes request = new SetAttributes(events);
                request.setAttributes(jsonCallback.getIds(), list);
              }
            }
          }
        };

    // click handler to save required attributes
    final ClickHandler saveReqAttrsClickHandler =
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            // check if not empty
            if (UiElements.cantSaveEmptyListDialogBox(list)) {

              // refresh table and disable button a event for GetResourceRequiredAttributes
              final JsonCallbackEvents events =
                  JsonCallbackEvents.disableButtonEvents(
                      saveChangesButton,
                      new JsonCallbackEvents() {
                        public void onFinished(JavaScriptObject jso) {
                          jsonCallback.clearTable();
                          // set back resourceToGetServicesFrom
                          Map<String, Integer> ids = reqAttrs.getIds();
                          if (ids.containsKey("resource")) {
                            ids.put("resourceToGetServicesFrom", ids.get("resource"));
                          }
                          if (ids.containsKey("user")) {
                            ids.put("workWithUserAttributes", 1);
                          }
                          if (ids.containsKey("resource") && ids.containsKey("group")) {
                            ids.put("workWithGroupAttributes", 1);
                          }
                          reqAttrs.setIds(ids);
                          reqAttrs.retrieveData();
                        }
                      });

              final SetAttributes request = new SetAttributes();

              if (memChb.getValue() == true) {
                // to all members selected
                UiElements.generateInfo(
                    WidgetTranslation.INSTANCE.saveConfirmTitle(),
                    "Same value(s) for selected attribute(s) will be set to ALL members of group.",
                    new ClickHandler() {
                      public void onClick(ClickEvent event) {
                        ArrayList<RichMember> memList = membersDropDown.getAllObjects();
                        for (int i = 0; i < memList.size(); i++) {
                          if (i == 0) {
                            events.onLoadingStart();
                          } // trigger disable button if first
                          Map<String, Integer> ids = new HashMap<String, Integer>();
                          ids.put("member", memList.get(i).getId());
                          ids.put("user", memList.get(i).getUserId());
                          ids.put("resource", resourceDropDown.getSelectedObject().getId());
                          ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
                          if (i == memList.size() - 1) {
                            request.setEvents(events);
                          } // set events to last to get refresh and button enable
                          request.setAttributes(ids, list);
                        }
                      }
                    });
              } else {
                // group or member
                request.setEvents(events); // disable button events
                request.setAttributes(reqAttrs.getIds(), list);
              }
            }
          }
        };

    // REMOVE BUTTON
    final CustomButton removeButton =
        TabMenu.getPredefinedButton(
            ButtonType.REMOVE, ButtonTranslation.INSTANCE.removeAttributes());
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
      removeButton.setEnabled(false);

    // click handler to remove group and member-user attributes
    final ClickHandler removeAttrsClickHandler =
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {

              // refresh table and disable button a event for GetAttributes
              final JsonCallbackEvents events =
                  JsonCallbackEvents.disableButtonEvents(
                      removeButton, JsonCallbackEvents.refreshTableEvents(jsonCallback));

              final RemoveAttributes request = new RemoveAttributes();

              if (memChb.getValue() == true) {
                // to all members selected
                UiElements.generateInfo(
                    WidgetTranslation.INSTANCE.deleteConfirmTitle(),
                    "Selected attribute(s) will be removed from ALL members of group.",
                    new ClickHandler() {
                      public void onClick(ClickEvent event) {
                        ArrayList<RichMember> memList = membersDropDown.getAllObjects();
                        for (int i = 0; i < memList.size(); i++) {
                          if (i == 0) {
                            events.onLoadingStart();
                          } // trigger disable button if first
                          Map<String, Integer> ids = new HashMap<String, Integer>();
                          ids.put("member", memList.get(i).getId());
                          ids.put("workWithUserAttributes", 1);
                          if (i == memList.size() - 1) {
                            request.setEvents(events);
                          } // set events to last to get refresh and button enable
                          request.removeAttributes(ids, list);
                        }
                      }
                    });
              } else {
                // just one group / memeber
                request.setEvents(events); // disable button events
                request.removeAttributes(jsonCallback.getIds(), list);
              }
            }
          }
        };

    // click handler to remove ResourceRequiredAttributes
    final ClickHandler removeReqAttrsClickHandler =
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            final ArrayList<Attribute> list = jsonCallback.getTableSelectedList();
            if (UiElements.cantSaveEmptyListDialogBox(list)) {

              // refresh table and disable button a event for GetAttributes
              final JsonCallbackEvents events =
                  JsonCallbackEvents.disableButtonEvents(
                      removeButton,
                      new JsonCallbackEvents() {
                        public void onFinished(JavaScriptObject jso) {
                          jsonCallback.clearTable();
                          // set back resourceToGetServicesFrom
                          Map<String, Integer> ids = reqAttrs.getIds();
                          if (ids.containsKey("resource")) {
                            ids.put("resourceToGetServicesFrom", ids.get("resource"));
                          }
                          if (ids.containsKey("user")) {
                            ids.put("workWithUserAttributes", 1);
                          }
                          if (ids.containsKey("resource") && ids.containsKey("group")) {
                            ids.put("workWithGroupAttributes", 1);
                          }
                          reqAttrs.setIds(ids);
                          reqAttrs.retrieveData();
                        }
                      });

              final RemoveAttributes request = new RemoveAttributes();

              if (memChb.getValue() == true) {
                // to all members selected
                UiElements.generateInfo(
                    WidgetTranslation.INSTANCE.deleteConfirmTitle(),
                    "Selected attribute(s) will be removed from ALL members of group.",
                    new ClickHandler() {
                      @Override
                      public void onClick(ClickEvent event) {
                        ArrayList<RichMember> memList = membersDropDown.getAllObjects();
                        for (int i = 0; i < memList.size(); i++) {
                          if (i == 0) {
                            events.onLoadingStart();
                          } // trigger disable button if first
                          Map<String, Integer> ids = new HashMap<String, Integer>();
                          ids.put("member", memList.get(i).getId());
                          ids.put("user", memList.get(i).getUserId());
                          ids.put("resource", resourceDropDown.getSelectedObject().getId());
                          ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
                          if (i == memList.size() - 1) {
                            request.setEvents(events);
                          } // set events to last to get refresh and button enable
                          request.removeAttributes(ids, list);
                        }
                      }
                    });
              } else {
                // just one group / member
                request.setEvents(events); // disable button events
                request.removeAttributes(reqAttrs.getIds(), list);
              }
            }
          }
        };

    // SET NEW ATTR BUTTON
    final CustomButton setNewAttributeButton =
        TabMenu.getPredefinedButton(ButtonType.ADD, ButtonTranslation.INSTANCE.setNewAttributes());
    if (!session.isGroupAdmin(groupId) && !session.isVoAdmin(group.getVoId()))
      setNewAttributeButton.setEnabled(false);
    // click handler
    setNewAttributeButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            ids.clear();
            if (resourceDropDown.getSelectedIndex() > 0) {
              if (membersDropDown.getSelectedIndex() > 0) {
                ids.put("member", membersDropDown.getSelectedObject().getId());
                ids.put("user", membersDropDown.getSelectedObject().getUserId());
                ids.put("resource", resourceDropDown.getSelectedObject().getId());
                ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
              } else {
                ids.put("resource", resourceDropDown.getSelectedObject().getId());
                ids.put("group", groupId);
                ids.put("workWithGroupAttributes", 1);
              }
            } else {
              if (membersDropDown.getSelectedIndex() > 0) {
                ids.put("member", membersDropDown.getSelectedObject().getId());
                ids.put("user", membersDropDown.getSelectedObject().getUserId());
              } else {
                ids.put("group", groupId);
              }
            }
            session
                .getTabManager()
                .addTabToCurrentTab(new SetNewAttributeTabItem(ids, jsonCallback.getList()), true);
          }
        });

    // ClickHandlersRegistration - save onClicks for GetAttributes
    final ArrayList<HandlerRegistration> clickHandlers = new ArrayList<HandlerRegistration>();
    clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler));
    clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler));

    // DEFINE CHANGE HANDLER FOR ALL DROP DOWNS
    ChangeHandler changeHandler =
        new ChangeHandler() {
          public void onChange(ChangeEvent event) {

            int resIndex = resourceDropDown.getSelectedIndex();
            int memIndex = membersDropDown.getSelectedIndex();

            // no resource or member selected
            if (resIndex == 0 && memIndex == 0) {
              lastSelectedMemberId = 0;
              lastSelectedResourceId = 0;
              memChb.setValue(false);
              memChb.setVisible(false);
              jsonCallback.clearTable();
              ids.clear();
              ids.put("group", groupId);
              jsonCallback.setIds(ids);
              jsonCallback.retrieveData();
              for (HandlerRegistration handler : clickHandlers) {
                if (handler != null) {
                  handler.removeHandler();
                }
              }
              clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler));
              clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler));
            }
            // no resource but member selected
            if (resIndex == 0 && memIndex > 0) {
              lastSelectedMemberId = membersDropDown.getSelectedObject().getId();
              lastSelectedResourceId = 0;
              memChb.setValue(false);
              memChb.setVisible(true);
              jsonCallback.clearTable();
              ids.clear();
              ids.put("member", membersDropDown.getSelectedObject().getId());
              ids.put("workWithUserAttributes", 1);
              jsonCallback.setIds(ids);
              jsonCallback.retrieveData();
              for (HandlerRegistration handler : clickHandlers) {
                if (handler != null) {
                  handler.removeHandler();
                }
              }
              clickHandlers.add(saveChangesButton.addClickHandler(saveAttrsClickHandler));
              clickHandlers.add(removeButton.addClickHandler(removeAttrsClickHandler));
            }
            // resource and no member selected
            if (resIndex > 0 && memIndex == 0) {
              lastSelectedMemberId = 0;
              lastSelectedResourceId = resourceDropDown.getSelectedObject().getId();
              memChb.setValue(false);
              memChb.setVisible(false);
              jsonCallback.clearTable();
              ids.clear();
              ids.put("group", groupId);
              ids.put("resource", resourceDropDown.getSelectedObject().getId());
              ids.put("resourceToGetServicesFrom", ids.get("resource"));
              ids.put("workWithGroupAttributes", 1);
              reqAttrs.setIds(ids);
              reqAttrs.retrieveData();
              // set ids back to make saveChanges work
              ids.remove("resourceToGetServicesFrom");
              reqAttrs.setIds(ids);
              for (HandlerRegistration handler : clickHandlers) {
                if (handler != null) {
                  handler.removeHandler();
                }
              }
              clickHandlers.add(saveChangesButton.addClickHandler(saveReqAttrsClickHandler));
              clickHandlers.add(removeButton.addClickHandler(removeReqAttrsClickHandler));
            }
            // resource and member selected
            if (resIndex > 0 && memIndex > 0) {
              lastSelectedMemberId = membersDropDown.getSelectedObject().getId();
              lastSelectedResourceId = resourceDropDown.getSelectedObject().getId();
              memChb.setValue(false);
              memChb.setVisible(true);
              jsonCallback.clearTable();
              ids.clear();
              ids.put("resource", resourceDropDown.getSelectedObject().getId());
              ids.put("resourceToGetServicesFrom", ids.get("resource"));
              ids.put("member", membersDropDown.getSelectedObject().getId());
              ids.put("workWithUserAttributes", 1);
              reqAttrs.setIds(ids);
              reqAttrs.retrieveData();
              // set ids back to make saveChanges work
              ids.clear();
              ids.put("member", membersDropDown.getSelectedObject().getId());
              ids.put("user", membersDropDown.getSelectedObject().getUser().getId());
              ids.put("facility", resourceDropDown.getSelectedObject().getFacilityId());
              ids.put("resource", resourceDropDown.getSelectedObject().getId());
              reqAttrs.setIds(ids);
              for (HandlerRegistration handler : clickHandlers) {
                if (handler != null) {
                  handler.removeHandler();
                }
              }
              clickHandlers.add(saveChangesButton.addClickHandler(saveReqAttrsClickHandler));
              clickHandlers.add(removeButton.addClickHandler(removeReqAttrsClickHandler));
            }
          }
        };

    // ADD CHANGE HANDLERS TO DROP-DOWN MENUS
    resourceDropDown.addChangeHandler(changeHandler);
    membersDropDown.addChangeHandler(changeHandler);

    // PUT ELEMENTS IN MENU
    menu.addWidget(saveChangesButton);
    // menu.addWidget(resChb);
    menu.addWidget(memChb);
    menu.addWidget(setNewAttributeButton);
    menu.addWidget(removeButton);
    menu.addWidget(new HTML("<strong>Resources:</strong>"));
    menu.addWidget(resourceDropDown);
    menu.addWidget(new HTML("<strong>Members:</strong>"));
    menu.addWidget(membersDropDown);

    this.contentWidget.setWidget(vp);

    return getWidget();
  }
Beispiel #9
0
  public EnumEditor(Asset a, int visibleLines) {
    data = (RuleContentText) a.getContent();

    if (data.content == null) {
      data.content = "";
    }

    cellTable = new CellTable<EnumRow>();
    cellTable.setWidth("100%");

    panel = new VerticalPanel();

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

    for (String line : array) {
      EnumRow enumRow = new EnumRow(line);

      dataProvider.getList().add(enumRow);
    }

    DeleteButtonCell deleteButton = new DeleteButtonCell();
    Column<EnumRow, String> delete =
        new Column<EnumRow, String>(deleteButton) {
          @Override
          public String getValue(EnumRow enumRow1) {
            return "";
          }
        };

    Column<EnumRow, String> columnFirst =
        new Column<EnumRow, String>(new EditTextCell()) {

          @Override
          public String getValue(EnumRow enumRow) {
            return enumRow.getFactName();
          }
        };
    Column<EnumRow, String> columnSecond =
        new Column<EnumRow, String>(new EditTextCell()) {

          @Override
          public String getValue(EnumRow enumRow) {
            return enumRow.getFieldName();
          }
        };
    Column<EnumRow, String> columnThird =
        new Column<EnumRow, String>(new EditTextCell()) {

          @Override
          public String getValue(EnumRow enumRow) {
            return enumRow.getContext();
          }
        };
    columnFirst.setFieldUpdater(
        new FieldUpdater<EnumRow, String>() {

          public void update(int index, EnumRow object, String value) {
            object.setFactName(value);
          }
        });
    columnSecond.setFieldUpdater(
        new FieldUpdater<EnumRow, String>() {

          public void update(int index, EnumRow object, String value) {

            object.setFieldName(value);
          }
        });
    columnThird.setFieldUpdater(
        new FieldUpdater<EnumRow, String>() {

          public void update(int index, EnumRow object, String value) {

            object.setContext(value);
          }
        });

    cellTable.addColumn(delete);
    cellTable.addColumn(columnFirst, "Fact");
    cellTable.addColumn(columnSecond, "Field");
    cellTable.addColumn(columnThird, "Context");

    // Connect the table to the data provider.
    dataProvider.addDataDisplay(cellTable);

    delete.setFieldUpdater(
        new FieldUpdater<EnumRow, String>() {

          public void update(int index, EnumRow object, String value) {
            dataProvider.getList().remove(object);
          }
        });

    Button addButton =
        new Button(
            "+",
            new ClickHandler() {
              public void onClick(ClickEvent clickEvent) {
                EnumRow enumRow = new EnumRow("");
                dataProvider.getList().add(enumRow);
              }
            });

    panel.add(cellTable);
    panel.add(addButton);
    initWidget(panel);
  }