Example #1
0
  protected void encodeMarkup(FacesContext facesContext, DataGrid grid) throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    String clientId = grid.getClientId(facesContext);
    boolean hasPaginator = grid.isPaginator();
    String paginatorPosition = grid.getPaginatorPosition();
    String styleClass =
        grid.getStyleClass() == null
            ? DataGrid.CONTAINER_CLASS
            : DataGrid.CONTAINER_CLASS + " " + grid.getStyleClass();

    writer.startElement("div", grid);
    writer.writeAttribute("id", clientId, "id");
    writer.writeAttribute("class", styleClass, "styleClass");

    if (hasPaginator && !paginatorPosition.equalsIgnoreCase("bottom")) {
      encodePaginatorContainer(facesContext, clientId + "_paginatorTop");
    }

    encodeTable(facesContext, grid, false);

    if (hasPaginator && !paginatorPosition.equalsIgnoreCase("top")) {
      encodePaginatorContainer(facesContext, clientId + "_paginatorBottom");
    }

    writer.endElement("div");
  }
  // used to wrap every access to the dataGrid in a transaction
  private <T> T doWithinBackingTransactionIfNeeded(Callable<T> command) {
    boolean inTopLevel = false;
    boolean commandFinished = false;

    try {
      if (!dataGrid.inTransaction()) {
        dataGrid.beginTransaction();
        inTopLevel = true;
      }

      T result = command.call();
      commandFinished = true;

      return result;
    } catch (Exception e) {
      throw new PersistenceException(e);
    } finally {
      if (inTopLevel) {
        try {
          if (commandFinished) {
            dataGrid.commitTransaction();
          } else {
            dataGrid.rollbackTransaction();
          }
        } catch (Exception e) {
          throw new PersistenceException(e);
        }
      }
    }
  }
  private boolean initializeOutstanding2(
      DataGrid grid,
      boolean ascend,
      boolean caseOn,
      BuySellType buySellType,
      BuySellType editOutstandingOrderBuySellType,
      IOpenCloseRelationSite openCloseRelationSite,
      Order mapOrder) {
    Boolean isSpot =
        openCloseRelationSite.getOrderType() == null
            ? null
            : openCloseRelationSite.getOrderType().isSpot();
    this.setOutstandingOrders(
        buySellType,
        mapOrder,
        isSpot,
        openCloseRelationSite.isMakeLimitOrder(),
        openCloseRelationSite.isDelivery());
    HashMap<Guid, RelationOrder> editOutstandingOrders =
        this.getEditOutstandingOrders(editOutstandingOrderBuySellType, mapOrder);
    boolean hasChange = this.hasChange(grid, editOutstandingOrders);

    if (hasChange) {
      this.unbindOutstanding();
      this._outstandingKey = Guid.newGuid().toString();
      this._bindingSourceForOutstanding = new tradingConsole.ui.grid.BindingSource();

      boolean isMakeOrder2 =
          this._settingsManager.get_Customer().get_SingleAccountOrderType() == 2
              || this._settingsManager.get_Customer().get_MultiAccountsOrderType() == 2;

      RelationOrder.initialize(
          isMakeOrder2,
          grid,
          this._outstandingKey,
          editOutstandingOrders.values(),
          this._bindingSourceForOutstanding,
          openCloseRelationSite,
          editOutstandingOrderBuySellType);

      int column = this._bindingSourceForOutstanding.getColumnByName(OutstandingOrderColKey.IsBuy);
      if (column != -1) {
        grid.sortColumn(column, false, ascend);
        TableColumnChooser.hideColumn(grid, column);
      }
    } else {
      this._outstandingKey = grid.get_BindingSource().get_DataSourceKey();
      this._outstandingOrders.clear();
      for (int row = 0; row < grid.getRowCount(); row++) {
        RelationOrder relationOrder = (RelationOrder) (grid.getObject(row));
        this._outstandingOrders.put(relationOrder.get_OpenOrderId(), relationOrder);
      }
    }

    return hasChange;
  }
Example #4
0
  public void decode(FacesContext facesContext, UIComponent component) {
    Map<String, String> params = facesContext.getExternalContext().getRequestParameterMap();
    DataGrid grid = (DataGrid) component;
    String clientId = grid.getClientId(facesContext);
    boolean isAjaxPaging = params.containsKey(clientId + "_ajaxPaging");

    if (isAjaxPaging) {
      grid.setFirst(Integer.valueOf(params.get(clientId + "_first")));
      grid.setRows(Integer.valueOf(params.get(clientId + "_rows")));
      grid.setPage(Integer.valueOf(params.get(clientId + "_page")));
    }
  }
Example #5
0
  private void setupSessionDataGrid() {
    sessionsDataGrid = new DataGrid<SessionDataDto>();
    sessionsDataGrid.setPageSize(15);
    sessionsDataGrid.setEmptyTableWidget(new Label("No Sessions"));

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

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

    sessionsDataGrid.addColumn(
        new TextColumn<SessionDataDto>() {
          @Override
          public String getValue(SessionDataDto object) {
            return object.getName();
          }
        },
        "Name");

    sessionsDataGrid.addColumn(
        new TextColumn<SessionDataDto>() {
          @Override
          public String getValue(SessionDataDto object) {
            return object.getStartDate();
          }
        },
        "Start Date");

    sessionsDataGrid.addColumn(
        new TextColumn<SessionDataDto>() {
          @Override
          public String getValue(SessionDataDto object) {
            return object.getEndDate();
          }
        },
        "End Date");

    sessionDataProvider.addDataDisplay(sessionsDataGrid);
  }
  public static void initialize(DataGrid grid) {
    // grid.setRedraw(false);
    // grid.reset();
    grid.setShowVerticalLines(false);
    grid.setBackground(GridFixedBackColor.account);
    grid.setForeground(GridBackColor.account);
    // grid.setBorderStyle(BorderStyle.account);
    // grid.setRowLabelWidth(RowLabelWidth.account);
    // grid.setSelectionBackground(SelectionBackground.account);
    // grid.setCurrentCellColor(CurrentCellColor.account);
    // grid.setCurrentCellBorder(CurrentCellBorder.account);

    // grid.setRedraw(true);
    // grid.doLayout();
  }
Example #7
0
 @UiHandler("showCheckedSessionsButton")
 void handleShowCheckedSessionsButtonClick(ClickEvent e) {
   Set<SessionDataDto> sessionDataDtoSet =
       ((MultiSelectionModel<SessionDataDto>) sessionsDataGrid.getSelectionModel())
           .getSelectedSet();
   filterSessions(sessionDataDtoSet);
 }
  public static void initialize(
      DataGrid grid,
      String dataSourceKey,
      Collection dataSource,
      tradingConsole.ui.grid.BindingSource bindingSource,
      boolean isAllowEditIsBuy,
      int dQMaxMove,
      int stepSize) {
    grid.setShowVerticalLines(false);
    grid.setBackground(GridFixedBackColor.account);
    grid.setForeground(GridBackColor.account);
    // grid.setSelectionBackground(SelectionBackground.account);

    TradingConsole.bindingManager.bind(
        dataSourceKey,
        dataSource,
        bindingSource,
        MakeOrderAccount.getPropertyDescriptors(isAllowEditIsBuy, dQMaxMove, stepSize));
    grid.setModel(bindingSource);
    TradingConsole.bindingManager.setHeader(
        dataSourceKey,
        SwingConstants.CENTER,
        25,
        GridFixedForeColor.account,
        Color.white,
        HeaderFont.account);
    TradingConsole.bindingManager.setGrid(
        dataSourceKey,
        18,
        Color.black,
        Color.lightGray,
        Color.blue,
        true,
        true,
        GridFont.account,
        false,
        true,
        true);

    if (isAllowEditIsBuy) {
      String[] listStrings = new String[] {Language.Buy, Language.Sell};
      ListComboBoxCellEditor listComboBoxCellEditor = new ListComboBoxCellEditor(listStrings);
      int column = bindingSource.getColumnByName(MakeOrderAccountGridColKey.IsBuyForCombo);
      grid.getColumnModel().getColumn(column).setCellEditor(listComboBoxCellEditor);
    }
  }
 private boolean hasChange(DataGrid grid, HashMap<Guid, RelationOrder> relationOrders) {
   if (grid.get_BindingSource() == null || grid.getRowCount() != relationOrders.size()) {
     return true;
   } else {
     int openOrderSummaryColumn = -1;
     for (int column = 0; column < grid.getColumnModel().getColumnCount(); column++) {
       if (grid.getColumnModel()
           .getColumn(column)
           .getIdentifier()
           .equals(OutstandingOrderColKey.OpenOrderSummary)) {
         openOrderSummaryColumn = column;
         break;
       }
     }
     for (int row = 0; row < grid.getRowCount(); row++) {
       RelationOrder realtionOrder = (RelationOrder) grid.getObject(row);
       Guid openOrderId = realtionOrder.get_OpenOrderId();
       RelationOrder realtionOrder2 = relationOrders.get(openOrderId);
       if (realtionOrder2 == null
           || realtionOrder2.getAvailableCloseLot().compareTo(realtionOrder.getAvailableCloseLot())
               != 0
           || (openOrderSummaryColumn > -1
               && !realtionOrder2
                   .get_OpenOrderSummary()
                   .equals(grid.getValueAt(row, openOrderSummaryColumn).toString()))) {
         return true;
       }
     }
   }
   return false;
 }
Example #10
0
  protected void encodeTable(FacesContext facesContext, DataGrid grid, boolean hidden)
      throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    String clientId = grid.getClientId(facesContext);
    int columns = grid.getColumns();
    int rowIndex = grid.getFirst();
    int numberOfRowsToRender =
        (grid.getRows() != 0 ? grid.getRows() : grid.getRowCount()) / columns;

    writer.startElement("table", grid);
    writer.writeAttribute("id", clientId + "_table", "id");
    writer.writeAttribute("class", DataGrid.TABLE_CLASS, null);
    if (hidden) writer.writeAttribute("style", "display:none", null);

    writer.startElement("tbody", null);

    for (int i = 0; i < numberOfRowsToRender; i++) {
      writer.startElement("tr", null);
      writer.writeAttribute("class", DataGrid.TABLE_ROW_CLASS, null);

      for (int j = 0; j < columns; j++) {
        grid.setRowIndex(rowIndex);

        writer.startElement("td", null);
        writer.writeAttribute("class", DataGrid.TABLE_COLUMN_CLASS, null);
        if (grid.isRowAvailable()) {
          renderChildren(facesContext, grid);
          rowIndex++;
        }
        writer.endElement("td");
      }

      writer.endElement("tr");

      if (!grid.isRowAvailable()) break;
    }

    grid.setRowIndex(-1); // cleanup

    writer.endElement("tbody");
    writer.endElement("table");
  }
  // only correct if invoked within a backing transaction.  Also this code
  // assumes a single global commit lock. Otherwise the counter might be set
  // backwards by a late-running thread.
  private void updatePersistentInstanceCounters() {
    Transaction current = FenixFramework.getTransaction();

    Set<DomainClassInfo> infos = current.getFromContext(KEY_INSTANTIATED_CLASSES);

    if (infos != null) {
      for (DomainClassInfo info : infos) {
        String key = makeKeyForMaxCounter(info);
        Integer max = (Integer) dataGrid.get(key);

        int newCounterValue = info.getLastKey();

        if (max == null || max < newCounterValue) {
          dataGrid.put(key, newCounterValue);
          logger.debug(
              "Update persistent counter for class {}: {}", info.domainClassName, newCounterValue);
        }
      }
    }
  }
Example #12
0
 private void markChange(InputItem rec) {
   if (!changedRecs.containsKey(rec.getId())) {
     changedRecs.put(rec.getId(), rec);
     if (!separator.isVisible()) {
       md.info(
           MDS, "Some data has been changed. Click 'Save' or 'Cancel' when editing is finished.");
       editMode(true);
     }
     dataGrid.redraw();
   }
 }
Example #13
0
  public void updatePlace(TrendsPlace place) {
    if (this.place != null) return;

    this.place = place;
    final TrendsPlace finalPlace = this.place;
    if (place.getSelectedSessionIds().isEmpty()) {

      sessionsDataGrid
          .getSelectionModel()
          .addSelectionChangeHandler(new SessionSelectChangeHandler());

      selectTests = true;
      testDataGrid.getSelectionModel().addSelectionChangeHandler(new TestSelectChangeHandler());

      TaskDataTreeViewModel viewModel = (TaskDataTreeViewModel) taskDetailsTree.getTreeViewModel();
      viewModel
          .getSelectionModel()
          .addSelectionChangeHandler(new TaskPlotSelectionChangedHandler());

      metricPanel.addSelectionListener(new MetricsSelectionChangedHandler());

      chooseTab(place.getToken());
      return;
    }

    SessionDataService.Async.getInstance()
        .getBySessionIds(
            0,
            place.getSelectedSessionIds().size(),
            place.getSelectedSessionIds(),
            new AsyncCallback<PagedSessionDataDto>() {
              @Override
              public void onFailure(Throwable caught) {
                caught.printStackTrace();
              }

              @Override
              public void onSuccess(PagedSessionDataDto result) {
                for (SessionDataDto session : result.getSessionDataDtoList()) {
                  sessionsDataGrid.getSelectionModel().setSelected(session, true);
                }
                sessionsDataGrid
                    .getSelectionModel()
                    .addSelectionChangeHandler(new SessionSelectChangeHandler());
                sessionsDataGrid
                    .getSelectionModel()
                    .setSelected(result.getSessionDataDtoList().iterator().next(), true);
                chooseTab(finalPlace.getToken());
              }
            });
    History.newItem(NameTokens.EMPTY);
  }
Example #14
0
  public void encodePartially(FacesContext facesContext, UIComponent component) throws IOException {
    DataGrid grid = (DataGrid) component;

    ServletResponse response = (ServletResponse) facesContext.getExternalContext().getResponse();
    response.setContentType("text/xml");

    ResponseWriter writer = facesContext.getResponseWriter();
    try {
      writer.write("<?xml version=\"1.0\" encoding=\"" + response.getCharacterEncoding() + "\"?>");
      writer.write("<partial-response>");

      // Tab content
      writer.write("<table>");
      RendererUtils.startCDATA(facesContext);

      encodeTable(facesContext, grid, (grid.isPaginator() && grid.isEffect()));

      RendererUtils.endCDATA(facesContext);
      writer.write("</table>");

      // State
      writer.write("<state>");
      RendererUtils.startCDATA(facesContext);

      StateManager stateManager = facesContext.getApplication().getStateManager();
      stateManager.writeState(facesContext, stateManager.saveView(facesContext));

      RendererUtils.endCDATA(facesContext);
      writer.write("</state>");

      writer.write("</partial-response>");
    } catch (IOException exception) {
      exception.printStackTrace();
    }

    facesContext.responseComplete();
  }
  @Override
  public DataGrid process(DataGrid grid) {
    if (grid.isPresenceAbsence()) return grid;

    ArrayList<DataLocation> locations = grid.getOrderedDataLocations();
    int qIndex = (int) Math.floor((1 - paramValues[0] / 100.0) * locations.size());
    double maxValue = locations.get(qIndex).value;

    double[][] values =
        MappingProject.grid.getEmptyGrid(); // filled with 0s und NoData where applicable

    int replaced = 0;
    for (int l = 0; l < locations.size(); l++) {
      if (locations.get(l).value <= maxValue) {
        values[locations.get(l).x][locations.get(l).y] = locations.get(l).value;
      } else {
        values[locations.get(l).x][locations.get(l).y] = maxValue;
        replaced++;
      }
    }
    // System.out.println("    Replaced "+replaced+" out of "+locations.size()+ " non-zero cells
    // with max value: " +maxValue);
    return new DataGrid(values, maxValue, grid.getMin(), grid.getNoDataValue());
  }
 public void clear() {
   projectInfo.removeAllData();
   dataPart.removeAllData();
   commentsGrid.removeAllData();
 }
Example #17
0
  @UiHandler("getHyperlink")
  void getHyperlink(ClickEvent event) {
    MultiSelectionModel<SessionDataDto> sessionModel =
        (MultiSelectionModel) sessionsDataGrid.getSelectionModel();
    MultiSelectionModel<TaskDataDto> testModel =
        (MultiSelectionModel) testDataGrid.getSelectionModel();

    Set<SessionDataDto> sessions = sessionModel.getSelectedSet();

    Set<TaskDataDto> tests = testModel.getSelectedSet();

    Set<MetricNameDto> metrics = metricPanel.getSelected();

    TaskDataTreeViewModel taskDataTreeViewModel =
        (TaskDataTreeViewModel) taskDetailsTree.getTreeViewModel();
    Set<PlotNameDto> trends = taskDataTreeViewModel.getSelectionModel().getSelectedSet();

    HashSet<String> sessionsIds = new HashSet<String>();
    HashSet<TestsMetrics> testsMetricses = new HashSet<TestsMetrics>(tests.size());
    HashMap<String, TestsMetrics> map = new HashMap<String, TestsMetrics>(tests.size());

    for (SessionDataDto session : sessions) {
      sessionsIds.add(session.getSessionId());
    }

    for (TaskDataDto taskDataDto : tests) {
      TestsMetrics testsMetrics =
          new TestsMetrics(taskDataDto.getTaskName(), new HashSet<String>(), new HashSet<String>());
      testsMetricses.add(testsMetrics);
      map.put(taskDataDto.getTaskName(), testsMetrics);
    }

    for (MetricNameDto metricNameDto : metrics) {
      map.get(metricNameDto.getTests().getTaskName()).getMetrics().add(metricNameDto.getName());
    }

    for (PlotNameDto plotNameDto : trends) {
      map.get(plotNameDto.getTest().getTaskName()).getTrends().add(plotNameDto.getPlotName());
    }

    TrendsPlace newPlace =
        new TrendsPlace(
            mainTabPanel.getSelectedIndex() == 0
                ? NameTokens.SUMMARY
                : mainTabPanel.getSelectedIndex() == 1 ? NameTokens.TRENDS : NameTokens.METRICS);

    newPlace.setSelectedSessionIds(sessionsIds);
    newPlace.setSelectedTestsMetrics(testsMetricses);
    newPlace.setSessionTrends(sessionPlotPanel.getSelected());

    String linkText =
        Window.Location.getHost()
            + Window.Location.getPath()
            + Window.Location.getQueryString()
            + "#"
            + new JaggerPlaceHistoryMapper().getToken(newPlace);
    linkText = URL.encode(linkText);

    // create a dialog for copy link
    final DialogBox dialog = new DialogBox(false, true);
    dialog.setText("Share link");
    dialog.setModal(true);
    dialog.setAutoHideEnabled(true);
    dialog.setPopupPosition(event.getClientX(), event.getClientY());

    final TextArea textArea = new TextArea();
    textArea.setText(linkText);
    textArea.setWidth("300px");
    textArea.setHeight("40px");
    // select text
    Scheduler.get()
        .scheduleDeferred(
            new Scheduler.ScheduledCommand() {
              @Override
              public void execute() {
                textArea.setVisible(true);
                textArea.setFocus(true);
                textArea.selectAll();
              }
            });

    dialog.add(textArea);

    dialog.show();
  }
Example #18
0
 @UiHandler("uncheckSessionsButton")
 void handleUncheckSessionsButtonClick(ClickEvent e) {
   MultiSelectionModel model = (MultiSelectionModel<?>) sessionsDataGrid.getSelectionModel();
   model.clear();
 }
Example #19
0
  protected void encodeScript(FacesContext facesContext, DataGrid grid) throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    String clientId = grid.getClientId(facesContext);
    String widgetVar = createUniqueWidgetVar(facesContext, grid);

    UIComponent form = ComponentUtils.findParentForm(facesContext, grid);
    if (form == null) {
      throw new FacesException("DataGrid : \"" + clientId + "\" must be inside a form element");
    }

    writer.startElement("script", null);
    writer.writeAttribute("type", "text/javascript", null);

    writer.write(widgetVar + " = new PrimeFaces.widget.DataGrid('" + clientId + "',{");
    writer.write("url:'" + getActionURL(facesContext) + "'");
    writer.write(",formId:'" + form.getClientId(facesContext) + "'");

    if (grid.isPaginator()) {
      writer.write(",paginator:new YAHOO.widget.Paginator({");
      writer.write("rowsPerPage:" + grid.getRows());
      writer.write(",totalRecords:" + grid.getRowCount());
      writer.write(",initialPage:" + grid.getPage());

      if (grid.getPageLinks() != 10) writer.write(",pageLinks:" + grid.getPageLinks());
      if (grid.getPaginatorTemplate() != null)
        writer.write(",template:'" + grid.getPaginatorTemplate() + "'");
      if (grid.getRowsPerPageTemplate() != null)
        writer.write(",rowsPerPageOptions : [" + grid.getRowsPerPageTemplate() + "]");
      if (grid.getFirstPageLinkLabel() != null)
        writer.write(",firstPageLinkLabel:'" + grid.getFirstPageLinkLabel() + "'");
      if (grid.getPreviousPageLinkLabel() != null)
        writer.write(",previousPageLinkLabel:'" + grid.getPreviousPageLinkLabel() + "'");
      if (grid.getNextPageLinkLabel() != null)
        writer.write(",nextPageLinkLabel:'" + grid.getNextPageLinkLabel() + "'");
      if (grid.getLastPageLinkLabel() != null)
        writer.write(",lastPageLinkLabel:'" + grid.getLastPageLinkLabel() + "'");
      if (grid.getCurrentPageReportTemplate() != null)
        writer.write(",pageReportTemplate:'" + grid.getCurrentPageReportTemplate() + "'");
      if (!grid.isPaginatorAlwaysVisible()) writer.write(",alwaysVisible:false");

      String paginatorPosition = grid.getPaginatorPosition();
      String paginatorContainer = null;
      if (paginatorPosition.equals("both"))
        paginatorContainer = clientId + "_paginatorTop','" + clientId + "_paginatorBottom";
      else if (paginatorPosition.equals("top")) paginatorContainer = clientId + "_paginatorTop";
      else if (paginatorPosition.equals("bottom"))
        paginatorContainer = clientId + "_paginatorBottom";

      writer.write(",containers:['" + paginatorContainer + "']");

      writer.write("})");

      if (grid.isEffect()) {
        writer.write(",effect:true");
        writer.write(",effectSpeed:'" + grid.getEffectSpeed() + "'");
      }
    }

    writer.write("});");

    writer.endElement("script");
  }
Example #20
0
  private void createDataGrid() {
    dataGrid = new DataGrid<InputItem>(1024 * 1024, ZicoDataGridResources.INSTANCE, KEY_PROVIDER);
    selectionModel = new SingleSelectionModel<InputItem>(KEY_PROVIDER);
    dataGrid.setSelectionModel(selectionModel);

    recordStore = new ListDataProvider<InputItem>(KEY_PROVIDER);
    recordStore.addDataDisplay(dataGrid);

    sortHandler = new ColumnSortEvent.ListHandler<InputItem>(recordStore.getList());

    Column<InputItem, InputItem> colId = new IdentityColumn<InputItem>(ID_CELL);
    dataGrid.addColumn(colId, new ResizableHeader<InputItem>("#", dataGrid, colId));
    dataGrid.setColumnWidth(colId, 35, Style.Unit.PX);

    final EditTextCell cellName = new EditTextCell();
    Column<InputItem, String> colName =
        new Column<InputItem, String>(cellName) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getName();
          }
        };
    colName.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getName())) {
              markChange(rec);
              rec.setName(value);
              cellName.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colName, new ResizableHeader<InputItem>("Name", dataGrid, colName));
    dataGrid.setColumnWidth(colName, 128, Style.Unit.PX);

    colName.setSortable(true);
    sortHandler.setComparator(
        colName,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });

    //        final SelectCell<String,Integer> cellActive = new SelectCell<String,Integer>(
    //                ZicoWidgets.<String,Integer>map("NO",0,"YES",1));
    //        Column<InputItem,Integer> colActive = new Column<InputItem, Integer>(cellActive) {
    //            @Override
    //            public Integer getValue(InputItem rec) {
    //                return rec.getActive();
    //            }
    //        };
    //        colActive.setFieldUpdater(new FieldUpdater<InputItem, Integer>() {
    //            @Override
    //            public void update(int index, InputItem rec, Integer value) {
    //                if (rec.getActive() != value) {
    //                    markChange(rec);
    //                    rec.setActive(value);
    //                    cellActive.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        dataGrid.addColumn(colActive, new ResizableHeader<InputItem>("Active", dataGrid,
    // colActive));
    //        dataGrid.setColumnWidth(colActive, 128, Style.Unit.PX);

    //        final DatePickerCell cellTstart = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstart = new Column<InputItem, Date>(cellTstart) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstart());
    //            }
    //        };
    //        colTstart.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstart()) {
    //                    markChange(rec);
    //                    rec.setTstart(t);
    //                    cellTstart.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstart.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstart, new ResizableHeader<InputItem>("TStart", dataGrid,
    // colTstart));
    //        dataGrid.setColumnWidth(colTstart, 100, Style.Unit.PX);

    //        final DatePickerCell cellTstop = new DatePickerCell(ClientUtil.TSTAMP_FORMAT0);
    //        Column<InputItem,Date> colTstop = new Column<InputItem, Date>(cellTstop) {
    //            @Override
    //            public Date getValue(InputItem rec) {
    //                return ClientUtil.unix2date(rec.getTstop());
    //            }
    //        };
    //        colTstop.setFieldUpdater(new FieldUpdater<InputItem, Date>() {
    //            @Override
    //            public void update(int index, InputItem rec, Date value) {
    //                long t = ClientUtil.date2unix(value);
    //                if (t != rec.getTstop()) {
    //                    markChange(rec);
    //                    rec.setTstop(t);
    //                    cellTstop.clearViewData(rec.getId());
    //                }
    //            }
    //        });
    //        colTstop.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
    //        dataGrid.addColumn(colTstop, new ResizableHeader<InputItem>("TStop", dataGrid,
    // colTstop));
    //        dataGrid.setColumnWidth(colTstop, 100, Style.Unit.PX);

    Column<InputItem, Integer> colInput =
        new Column<InputItem, Integer>(cellInput) {
          @Override
          public Integer getValue(InputItem iitem) {
            return iitem.getInputId();
          }
        };
    colInput.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem rec, Integer value) {
            if (rec.getInputId() != value) {
              markChange(rec);
              rec.setInputId(value);
              cellInput.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colInput, new ResizableHeader<InputItem>("Input", dataGrid, colInput));
    dataGrid.setColumnWidth(colInput, 128, Style.Unit.PX);

    Column<InputItem, Integer> colTxForm =
        new Column<InputItem, Integer>(cellTxForm) {
          @Override
          public Integer getValue(InputItem rec) {
            return rec.getTxFormid();
          }
        };
    colTxForm.setFieldUpdater(
        new FieldUpdater<InputItem, Integer>() {
          @Override
          public void update(int index, InputItem iitem, Integer value) {
            if (iitem.getTxFormid() != value) {
              markChange(iitem);
              iitem.setTxFormid(value);
              cellTxForm.clearViewData(iitem.getId());
            }
          }
        });
    dataGrid.addColumn(colTxForm, new ResizableHeader<InputItem>("TxForm", dataGrid, colTxForm));
    dataGrid.setColumnWidth(colTxForm, 128, Style.Unit.PX);

    final EditTextCell cellComment = new EditTextCell();
    Column<InputItem, String> colComment =
        new Column<InputItem, String>(cellComment) {
          @Override
          public String getValue(InputItem rec) {
            return rec.getComment();
          }
        };
    colComment.setFieldUpdater(
        new FieldUpdater<InputItem, String>() {
          @Override
          public void update(int index, InputItem rec, String value) {
            if (!value.equals(rec.getComment())) {
              markChange(rec);
              rec.setComment(value);
              cellComment.clearViewData(rec.getId());
            }
          }
        });
    dataGrid.addColumn(colComment, new ResizableHeader<InputItem>("Comment", dataGrid, colComment));

    colComment.setSortable(true);
    sortHandler.setComparator(
        colComment,
        new Comparator<InputItem>() {
          @Override
          public int compare(InputItem o1, InputItem o2) {
            return o1.getComment().compareTo(o2.getComment());
          }
        });

    dataGrid.addCellPreviewHandler(
        new CellPreviewEvent.Handler<InputItem>() {
          @Override
          public void onCellPreview(CellPreviewEvent<InputItem> event) {
            NativeEvent nev = event.getNativeEvent();
            String eventType = nev.getType();
            if (BrowserEvents.CONTEXTMENU.equals(eventType)) {
              selectionModel.setSelected(event.getValue(), true);
              if (event.getValue() != null) {
                contextMenu.setPopupPosition(
                    event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                contextMenu.show();
              }
            }
          }
        });

    dataGrid.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);
    dataGrid.addDomHandler(
        new DoubleClickHandler() {
          @Override
          public void onDoubleClick(DoubleClickEvent event) {
            event.preventDefault();
          }
        },
        DoubleClickEvent.getType());
    dataGrid.addDomHandler(
        new ContextMenuHandler() {
          @Override
          public void onContextMenu(ContextMenuEvent event) {
            event.preventDefault();
          }
        },
        ContextMenuEvent.getType());
  }
  public Widget draw() {

    // contentWidget.setSize("100%", "100%");

    DockLayoutPanel ft = new DockLayoutPanel(Style.Unit.PX);
    contentWidget.setWidget(ft);

    final DataGrid gridTable = new DataGrid();
    gridTable.setSize("100%", "100%");

    final ArrayList<Attribute> vosList = new ArrayList<Attribute>();
    final GetAttributesV2 getVos =
        new GetAttributesV2(
            new JsonCallbackEvents() {
              public void onFinished(JavaScriptObject jso) {
                vosList.addAll(
                    new TableSorter<Attribute>()
                        .sortByAttrNameTranslation(JsonUtils.<Attribute>jsoAsList(jso)));
                gridTable.setRowData(vosList);
                gridTable.redraw();
              }
            });
    getVos.getUserAttributes(3411);
    getVos.retrieveData();

    gridTable.setSelectionModel(
        new MultiSelectionModel<Attribute>(new GeneralKeyProvider<Attribute>()));
    final SelectionModel<Attribute> selectionModel = gridTable.getSelectionModel();
    gridTable.setKeyboardSelectionPolicy(
        HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.DISABLED);

    Column<Attribute, Boolean> checkBoxColumn =
        new Column<Attribute, Boolean>(new CheckboxCell(true, true)) {
          @Override
          public Boolean getValue(Attribute object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
          }
        };
    checkBoxColumn.setFieldUpdater(
        new FieldUpdater<Attribute, Boolean>() {
          @Override
          public void update(int i, Attribute Attribute, Boolean aBoolean) {
            selectionModel.setSelected(Attribute, aBoolean);
          }
        });

    // Checkbox column header
    CheckboxCell cb = new CheckboxCell();
    Header<Boolean> checkBoxHeader =
        new Header<Boolean>(cb) {
          public Boolean getValue() {
            return false; // return true to see a checked checkbox.
          }
        };
    checkBoxHeader.setUpdater(
        new ValueUpdater<Boolean>() {
          public void update(Boolean value) {
            // sets selected to all, if value = true, unselect otherwise
            for (Attribute obj : vosList) {
              selectionModel.setSelected(obj, value);
            }
          }
        });

    gridTable.addColumn(checkBoxColumn, checkBoxHeader, checkBoxHeader);
    gridTable.setColumnWidth(checkBoxColumn, 40.0, Style.Unit.PX);

    TextColumn<Attribute> idColumn =
        new TextColumn<Attribute>() {
          @Override
          public String getValue(Attribute object) {
            return String.valueOf(object.getId());
          }
        };

    if (JsonUtils.isExtendedInfoVisible()) {
      gridTable.addColumn(idColumn, "Id", "Id");
      gridTable.setColumnWidth(idColumn, "90px");
    }

    // Name column
    Column<Attribute, Attribute> nameColumn = JsonUtils.addColumn(new PerunAttributeNameCell());

    // Description column
    Column<Attribute, Attribute> descriptionColumn =
        JsonUtils.addColumn(new PerunAttributeDescriptionCell());

    // Value column
    Column<Attribute, Attribute> valueColumn =
        JsonUtils.addColumn(
            new PerunAttributeValueCell(),
            new FieldUpdater<Attribute, Attribute>() {
              public void update(int index, Attribute object, Attribute value) {
                object = value;
                selectionModel.setSelected(object, object.isAttributeValid());
              }
            });

    ColumnSortEvent.ListHandler<Attribute> columnSortHandler =
        new ColumnSortEvent.ListHandler<Attribute>(vosList);
    gridTable.addColumnSortHandler(columnSortHandler);

    // Sorting name column
    nameColumn.setSortable(true);
    columnSortHandler.setComparator(
        nameColumn, new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_NAME));

    // Sorting description column
    descriptionColumn.setSortable(true);
    columnSortHandler.setComparator(
        descriptionColumn,
        new AttributeComparator<Attribute>(AttributeComparator.Column.TRANSLATED_DESCRIPTION));

    // Add sorting
    gridTable.addColumnSortHandler(columnSortHandler);

    // updates the columns size
    gridTable.setColumnWidth(nameColumn, 200.0, Style.Unit.PX);
    gridTable.setColumnWidth(valueColumn, 420.0, Style.Unit.PX);

    gridTable.addColumn(nameColumn, "Name");
    gridTable.addColumn(valueColumn, "Value");
    gridTable.addColumn(descriptionColumn, "Description");

    TabMenu tabMenu = new TabMenu();

    tabMenu.addWidget(
        TabMenu.getPredefinedButton(
            ButtonType.ADD,
            "",
            new ClickHandler() {
              @Override
              public void onClick(ClickEvent clickEvent) {
                session.getTabManager().addTabToCurrentTab(new TestDataGridTabItem(), true);
              }
            }));

    ft.addNorth(tabMenu, 50);
    ft.add(gridTable);

    return getWidget();
  }