@Override
  public void initColumns(ExtendedPagedTable<ProcessInstanceSummary> extendedPagedTable) {

    Column checkColumn = initChecksColumn();
    Column processInstanceIdColumn = initProcessInstanceIdColumn();
    Column processNameColumn = initProcessNameColumn();
    Column processInitiatorColumn = initInitiatorColumn();
    Column processVersionColumn = initProcessVersionColumn();
    Column processStateColumn = initProcessStateColumn();
    Column startTimeColumn = initStartDateColumn();
    Column descriptionColumn = initDescriptionColumn();
    actionsColumn = initActionsColumn();

    List<ColumnMeta<ProcessInstanceSummary>> columnMetas =
        new ArrayList<ColumnMeta<ProcessInstanceSummary>>();
    columnMetas.add(new ColumnMeta<ProcessInstanceSummary>(checkColumn, constants.Select()));
    columnMetas.add(
        new ColumnMeta<ProcessInstanceSummary>(processInstanceIdColumn, constants.Id()));
    columnMetas.add(new ColumnMeta<ProcessInstanceSummary>(processNameColumn, constants.Name()));
    columnMetas.add(
        new ColumnMeta<ProcessInstanceSummary>(
            descriptionColumn, constants.Process_Instance_Description()));
    columnMetas.add(
        new ColumnMeta<ProcessInstanceSummary>(processInitiatorColumn, constants.Initiator()));
    columnMetas.add(
        new ColumnMeta<ProcessInstanceSummary>(processVersionColumn, constants.Version()));
    columnMetas.add(new ColumnMeta<ProcessInstanceSummary>(processStateColumn, constants.State()));
    columnMetas.add(
        new ColumnMeta<ProcessInstanceSummary>(startTimeColumn, constants.Start_Date()));
    columnMetas.add(new ColumnMeta<ProcessInstanceSummary>(actionsColumn, constants.Actions()));
    extendedPagedTable.addColumns(columnMetas);
  }
  private void initBulkActions(
      final ExtendedPagedTable<ProcessInstanceSummary> extendedPagedTable) {
    bulkAbortNavLink = new AnchorListItem(constants.Bulk_Abort());
    bulkSignalNavLink = new AnchorListItem(constants.Bulk_Signal());

    final ButtonGroup bulkActions =
        new ButtonGroup() {
          {
            add(
                new org.gwtbootstrap3.client.ui.Button(constants.Bulk_Actions()) {
                  {
                    setDataToggle(Toggle.DROPDOWN);
                  }
                });
            add(
                new DropDownMenu() {
                  {
                    setPull(Pull.RIGHT);
                    add(bulkAbortNavLink);
                    add(bulkSignalNavLink);
                  }
                });
          }
        };

    bulkAbortNavLink.setIcon(IconType.BAN);
    bulkAbortNavLink.setIconFixedWidth(true);
    bulkAbortNavLink.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            presenter.bulkAbort(selectedProcessInstances);
            selectedProcessInstances.clear();
            extendedPagedTable.redraw();
          }
        });

    bulkSignalNavLink.setIcon(IconType.BELL);
    bulkSignalNavLink.setIconFixedWidth(true);
    bulkSignalNavLink.addClickHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            presenter.bulkSignal(selectedProcessInstances);
            selectedProcessInstances.clear();
            extendedPagedTable.redraw();
          }
        });

    extendedPagedTable.getRightActionsToolbar().add(bulkActions);

    controlBulkOperations();
  }
  private Column initActionsColumn() {
    List<HasCell<ProcessInstanceSummary, ?>> cells =
        new LinkedList<HasCell<ProcessInstanceSummary, ?>>();

    cells.add(
        new SignalActionHasCell(
            constants.Signal(),
            new Delegate<ProcessInstanceSummary>() {
              @Override
              public void execute(ProcessInstanceSummary processInstance) {

                PlaceRequest placeRequestImpl = new DefaultPlaceRequest("Signal Process Popup");
                placeRequestImpl.addParameter(
                    "processInstanceId", Long.toString(processInstance.getProcessInstanceId()));

                placeManager.goTo(placeRequestImpl);
              }
            }));

    cells.add(
        new AbortActionHasCell(
            constants.Abort(),
            new Delegate<ProcessInstanceSummary>() {
              @Override
              public void execute(ProcessInstanceSummary processInstance) {
                if (Window.confirm("Are you sure that you want to abort the process instance?")) {
                  presenter.abortProcessInstance(processInstance.getProcessInstanceId());
                }
              }
            }));

    CompositeCell<ProcessInstanceSummary> cell = new CompositeCell<ProcessInstanceSummary>(cells);
    Column<ProcessInstanceSummary, ProcessInstanceSummary> actionsColumn =
        new Column<ProcessInstanceSummary, ProcessInstanceSummary>(cell) {
          @Override
          public ProcessInstanceSummary getValue(ProcessInstanceSummary object) {
            return object;
          }
        };
    return actionsColumn;
  }
 private void makeMenuBar() {
   menus =
       MenuFactory.newTopLevelMenu(constants.Bulk_Actions())
           .withItems(getBulkActions())
           .endMenu()
           .newTopLevelMenu(constants.Refresh())
           .respondsWith(
               new Command() {
                 @Override
                 public void execute() {
                   view.getShowAllLink().setStyleName("active");
                   view.getShowCompletedLink().setStyleName("");
                   view.getShowAbortedLink().setStyleName("");
                   view.getShowRelatedToMeLink().setStyleName("");
                   refreshActiveProcessList();
                   clearSearchEvent.fire(new ClearSearchEvent());
                   view.setCurrentFilter("");
                   view.displayNotification(constants.Process_Instances_Refreshed());
                 }
               })
           .endMenu()
           .build();
 }
 public void initExtraButtons(
     final ExtendedPagedTable<ProcessInstanceSummary> extendedPagedTable) {
   Button newInstanceButton = new Button();
   newInstanceButton.setTitle(constants.New_Instance());
   newInstanceButton.setIcon(IconType.PLUS);
   newInstanceButton.setTitle(Constants.INSTANCE.New_Instance());
   newInstanceButton.addClickHandler(
       new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
           newProcessInstancePopup.show();
         }
       });
   extendedPagedTable.getRightActionsToolbar().add(newInstanceButton);
 }
  public void bulkAbort(List<ProcessInstanceVariableSummary> processInstances) {
    if (processInstances != null) {
      if (Window.confirm("Are you sure that you want to abort the selected process instances?")) {
        List<Long> ids = new ArrayList<Long>();
        for (ProcessInstanceVariableSummary selected : processInstances) {

          ids.add(selected.getProcessInstanceId());

          view.displayNotification(
              constants.Aborting_Process_Instance() + "(id=" + selected.getId() + ")");
        }
        abortProcessInstance(ids);
      }
    }
  }
  public void bulkSignal(List<ProcessInstanceVariableSummary> processInstances) {
    StringBuilder processIdsParam = new StringBuilder();
    if (processInstances != null) {

      for (ProcessInstanceVariableSummary selected : processInstances) {}

      // remove last ,
      if (processIdsParam.length() > 0) {
        processIdsParam.deleteCharAt(processIdsParam.length() - 1);
      }
    } else {
      processIdsParam.append("-1");
    }
    PlaceRequest placeRequestImpl = new DefaultPlaceRequest("Signal Process Popup");
    placeRequestImpl.addParameter("processInstanceId", processIdsParam.toString());

    placeManager.goTo(placeRequestImpl);
    view.displayNotification(constants.Signaling_Process_Instance());
  }
  @Override
  public void init(ProcessDefinitionListPresenter presenter) {
    this.presenter = presenter;

    listContainer.add(processdefListGrid);
    listContainer.add(pager);

    processdefListGrid.setHeight("350px");

    // Set the message to display when the table is empty.
    processdefListGrid.setEmptyTableWidget(new Label(constants.No_Process_Definitions_Available()));

    // Attach a column sort handler to the ListDataProvider to sort the list.
    sortHandler = new ListHandler<ProcessSummary>(presenter.getDataProvider().getList());
    processdefListGrid.addColumnSortHandler(sortHandler);

    // Create a Pager to control the table.

    pager.setDisplay(processdefListGrid);
    pager.setPageSize(10);

    // Add a selection model so we can select cells.
    final MultiSelectionModel<ProcessSummary> selectionModel =
        new MultiSelectionModel<ProcessSummary>();
    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          public void onSelectionChange(SelectionChangeEvent event) {
            selectedProcessDef = selectionModel.getSelectedSet();
            for (ProcessSummary pd : selectedProcessDef) {
              processSelection.fire(new ProcessDefSelectionEvent(pd.getId()));
            }
          }
        });

    processdefListGrid.setSelectionModel(
        selectionModel, DefaultSelectionEventManager.<ProcessSummary>createCheckboxManager());

    initTableColumns(selectionModel);

    presenter.addDataDisplay(processdefListGrid);
  }
 @Override
 public void init() {
   processIdLabel.setText(constants.Process_Definition_Id());
   processNameLabel.setText(constants.Process_Definition_Name());
   deploymentIdLabel.setText(constants.Deployment_Name());
 }
 @WorkbenchPartTitle
 public String getTitle() {
   return constants.Process_Instances();
 }
  private List<? extends MenuItem> getBulkActions() {
    List<MenuItem> bulkActions = new ArrayList<MenuItem>(2);
    bulkActions.add(
        MenuFactory.newSimpleItem(constants.Bulk_Signal())
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    StringBuffer processIdsParam = new StringBuffer();
                    if (view.getSelectedProcessInstances() != null) {

                      for (ProcessInstanceSummary selected : view.getSelectedProcessInstances()) {
                        if (selected.getState() != ProcessInstance.STATE_ACTIVE) {
                          view.displayNotification(
                              constants.Signaling_Process_Instance_Not_Allowed()
                                  + "(id="
                                  + selected.getId()
                                  + ")");
                          continue;
                        }
                        processIdsParam.append(selected.getId() + ",");
                        view.getProcessInstanceListGrid()
                            .getSelectionModel()
                            .setSelected(selected, false);
                      }
                      // remove last ,
                      if (processIdsParam.length() > 0) {
                        processIdsParam.deleteCharAt(processIdsParam.length() - 1);
                      }
                    } else {
                      processIdsParam.append("-1");
                    }
                    PlaceRequest placeRequestImpl = new DefaultPlaceRequest("Signal Process Popup");
                    placeRequestImpl.addParameter("processInstanceId", processIdsParam.toString());

                    placeManager.goTo(placeRequestImpl);
                    view.displayNotification(constants.Signaling_Process_Instance());
                  }
                })
            .endMenu()
            .build()
            .getItems()
            .get(0));

    bulkActions.add(
        MenuFactory.newSimpleItem(constants.Bulk_Abort())
            .respondsWith(
                new Command() {
                  @Override
                  public void execute() {
                    if (view.getSelectedProcessInstances() != null) {
                      List<Long> ids = new ArrayList<Long>();
                      for (ProcessInstanceSummary selected : view.getSelectedProcessInstances()) {
                        if (selected.getState() != ProcessInstance.STATE_ACTIVE) {
                          view.displayNotification(
                              constants.Aborting_Process_Instance_Not_Allowed()
                                  + "(id="
                                  + selected.getId()
                                  + ")");
                          continue;
                        }
                        ids.add(selected.getId());

                        view.getProcessInstanceListGrid()
                            .getSelectionModel()
                            .setSelected(selected, false);
                        view.displayNotification(
                            constants.Aborting_Process_Instance()
                                + "(id="
                                + selected.getId()
                                + ")");
                      }
                      abortProcessInstance(ids);
                    }
                  }
                })
            .endMenu()
            .build()
            .getItems()
            .get(0));

    return bulkActions;
  }
  @Override
  public void initSelectionModel() {

    final ExtendedPagedTable extendedPagedTable = getListGrid();
    extendedPagedTable.setEmptyTableCaption(constants.No_Process_Instances_Found());
    extendedPagedTable.getRightActionsToolbar().clear();
    initExtraButtons(extendedPagedTable);
    initBulkActions(extendedPagedTable);
    selectionModel = new NoSelectionModel<ProcessInstanceSummary>();
    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          @Override
          public void onSelectionChange(SelectionChangeEvent event) {

            boolean close = false;
            if (selectedRow == -1) {
              extendedPagedTable.setRowStyles(selectedStyles);
              selectedRow = extendedPagedTable.getKeyboardSelectedRow();
              extendedPagedTable.redraw();

            } else if (extendedPagedTable.getKeyboardSelectedRow() != selectedRow) {
              extendedPagedTable.setRowStyles(selectedStyles);
              selectedRow = extendedPagedTable.getKeyboardSelectedRow();
              extendedPagedTable.redraw();
            } else {
              close = true;
            }

            selectedItem = selectionModel.getLastSelectedObject();

            PlaceStatus status =
                placeManager.getStatus(new DefaultPlaceRequest("Process Instance Details Multi"));

            if (status == PlaceStatus.CLOSE) {
              placeManager.goTo("Process Instance Details Multi");
              processInstanceSelected.fire(
                  new ProcessInstanceSelectionEvent(
                      selectedItem.getDeploymentId(),
                      selectedItem.getProcessInstanceId(),
                      selectedItem.getProcessId(),
                      selectedItem.getProcessName(),
                      selectedItem.getState()));
            } else if (status == PlaceStatus.OPEN && !close) {
              processInstanceSelected.fire(
                  new ProcessInstanceSelectionEvent(
                      selectedItem.getDeploymentId(),
                      selectedItem.getProcessInstanceId(),
                      selectedItem.getProcessId(),
                      selectedItem.getProcessName(),
                      selectedItem.getState()));
            } else if (status == PlaceStatus.OPEN && close) {
              placeManager.closePlace("Process Instance Details Multi");
            }
          }
        });

    noActionColumnManager =
        DefaultSelectionEventManager.createCustomManager(
            new DefaultSelectionEventManager.EventTranslator<ProcessInstanceSummary>() {

              @Override
              public boolean clearCurrentSelection(CellPreviewEvent<ProcessInstanceSummary> event) {
                return false;
              }

              @Override
              public DefaultSelectionEventManager.SelectAction translateSelectionEvent(
                  CellPreviewEvent<ProcessInstanceSummary> event) {
                NativeEvent nativeEvent = event.getNativeEvent();
                if (BrowserEvents.CLICK.equals(nativeEvent.getType())) {
                  // Ignore if the event didn't occur in the correct column.
                  if (extendedPagedTable.getColumnIndex(actionsColumn) == event.getColumn()) {
                    return DefaultSelectionEventManager.SelectAction.IGNORE;
                  }
                  // Extension for checkboxes
                  Element target = nativeEvent.getEventTarget().cast();
                  if ("input".equals(target.getTagName().toLowerCase())) {
                    final InputElement input = target.cast();
                    if ("checkbox".equals(input.getType().toLowerCase())) {
                      // Synchronize the checkbox with the current selection state.
                      if (!selectedProcessInstances.contains(event.getValue())) {
                        selectedProcessInstances.add(event.getValue());
                        input.setChecked(true);
                      } else {
                        selectedProcessInstances.remove(event.getValue());
                        input.setChecked(false);
                      }
                      controlBulkOperations();
                      return DefaultSelectionEventManager.SelectAction.IGNORE;
                    }
                  }
                }

                return DefaultSelectionEventManager.SelectAction.DEFAULT;
              }
            });

    extendedPagedTable.setSelectionModel(selectionModel, noActionColumnManager);
    extendedPagedTable.setRowStyles(selectedStyles);
  }
  @Override
  public void init(final ProcessInstanceListPresenter presenter) {
    final List<String> bannedColumns = new ArrayList<String>();
    bannedColumns.add(constants.Select());
    bannedColumns.add(constants.Id());
    bannedColumns.add(constants.Name());
    bannedColumns.add(constants.Process_Instance_Description());
    bannedColumns.add(constants.Actions());
    final List<String> initColumns = new ArrayList<String>();
    initColumns.add(constants.Select());
    initColumns.add(constants.Id());
    initColumns.add(constants.Name());
    initColumns.add(constants.Process_Instance_Description());
    initColumns.add(constants.Version());
    initColumns.add(constants.Actions());
    initColumns.add(constants.Version());

    final Button button = new Button();
    button.setText("+");
    button.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            Command addNewGrid =
                new Command() {
                  @Override
                  public void execute() {
                    HashMap<String, Object> newTabFormValues = newTabFilterPopup.getFormValues();
                    final String key = getValidKeyForAdditionalListGrid("ProcessInstancesGrid_");
                    filterPagedTable.saveNewTabSettings(key, newTabFormValues);
                    final ExtendedPagedTable<ProcessInstanceSummary> extendedPagedTable =
                        createGridInstance(
                            new GridGlobalPreferences(key, initColumns, bannedColumns), key);

                    extendedPagedTable.setDataProvider(presenter.getDataProvider());

                    filterPagedTable.createNewTab(
                        extendedPagedTable,
                        key,
                        button,
                        new Command() {
                          @Override
                          public void execute() {
                            currentListGrid = extendedPagedTable;
                            applyFilterOnPresenter(key);
                          }
                        });
                    applyFilterOnPresenter(newTabFormValues);
                  }
                };
            createFilterForm();
            newTabFilterPopup.show(addNewGrid, getMultiGridPreferencesStore());
          }
        });

    super.init(
        presenter,
        new GridGlobalPreferences("ProcessInstancesGrid", initColumns, bannedColumns),
        button);
  }
  private void initTableColumns(final SelectionModel<ProcessSummary> selectionModel) {
    // Checkbox column. This table will uses a checkbox column for selection.
    // Alternatively, you can call dataGrid.setSelectionEnabled(true) to enable
    // mouse selection.

    Column<ProcessSummary, Boolean> checkColumn =
        new Column<ProcessSummary, Boolean>(new CheckboxCell(true, false)) {
          @Override
          public Boolean getValue(ProcessSummary object) {
            // Get the value from the selection model.
            return selectionModel.isSelected(object);
          }
        };

    processdefListGrid.addColumn(checkColumn, SafeHtmlUtils.fromSafeConstant("<br/>"));
    processdefListGrid.setColumnWidth(checkColumn, "40px");

    // Id.
    Column<ProcessSummary, String> processIdColumn =
        new Column<ProcessSummary, String>(new EditTextCell()) {
          @Override
          public String getValue(ProcessSummary object) {
            return object.getId();
          }
        };
    processIdColumn.setSortable(true);
    sortHandler.setComparator(
        processIdColumn,
        new Comparator<ProcessSummary>() {
          public int compare(ProcessSummary o1, ProcessSummary o2) {
            return Long.valueOf(o1.getId()).compareTo(Long.valueOf(o2.getId()));
          }
        });
    processdefListGrid.addColumn(
        processIdColumn, new ResizableHeader(constants.Id(), processdefListGrid, processIdColumn));

    // Process Id String.
    Column<ProcessSummary, String> processNameColumn =
        new Column<ProcessSummary, String>(new EditTextCell()) {
          @Override
          public String getValue(ProcessSummary object) {
            return object.getName();
          }
        };
    processNameColumn.setSortable(true);
    sortHandler.setComparator(
        processNameColumn,
        new Comparator<ProcessSummary>() {
          public int compare(ProcessSummary o1, ProcessSummary o2) {
            return o1.getName().compareTo(o2.getName());
          }
        });
    processdefListGrid.addColumn(
        processNameColumn,
        new ResizableHeader(constants.Name(), processdefListGrid, processNameColumn));

    // Process PKG.
    Column<ProcessSummary, String> processPkgColumn =
        new Column<ProcessSummary, String>(new EditTextCell()) {
          @Override
          public String getValue(ProcessSummary object) {
            return object.getPackageName();
          }
        };
    processPkgColumn.setSortable(true);
    sortHandler.setComparator(
        processPkgColumn,
        new Comparator<ProcessSummary>() {
          public int compare(ProcessSummary o1, ProcessSummary o2) {
            return o1.getPackageName().compareTo(o2.getPackageName());
          }
        });
    processdefListGrid.addColumn(
        processPkgColumn,
        new ResizableHeader(constants.Package(), processdefListGrid, processPkgColumn));

    // Process Session Id.
    Column<ProcessSummary, Number> processSessionIdColumn =
        new Column<ProcessSummary, Number>(new NumberCell()) {
          @Override
          public Number getValue(ProcessSummary object) {
            return object.getSessionId();
          }
        };
    processSessionIdColumn.setSortable(true);
    sortHandler.setComparator(
        processSessionIdColumn,
        new Comparator<ProcessSummary>() {
          public int compare(ProcessSummary o1, ProcessSummary o2) {
            return (o1.getSessionId() == o2.getSessionId()) ? 0 : 1;
          }
        });
    processdefListGrid.addColumn(
        processSessionIdColumn,
        new ResizableHeader("Session Id", processdefListGrid, processSessionIdColumn));
    processdefListGrid.setColumnWidth(processSessionIdColumn, "90px");

    // Version Type
    Column<ProcessSummary, String> versionColumn =
        new Column<ProcessSummary, String>(new EditTextCell()) {
          @Override
          public String getValue(ProcessSummary object) {
            return object.getVersion();
          }
        };
    versionColumn.setSortable(true);
    sortHandler.setComparator(
        versionColumn,
        new Comparator<ProcessSummary>() {
          public int compare(ProcessSummary o1, ProcessSummary o2) {
            return o1.getVersion().compareTo(o2.getVersion());
          }
        });
    processdefListGrid.addColumn(
        versionColumn, new ResizableHeader(constants.Version(), processdefListGrid, versionColumn));
    processdefListGrid.setColumnWidth(versionColumn, "90px");

    // actions (icons)
    List<HasCell<ProcessSummary, ?>> cells = new LinkedList<HasCell<ProcessSummary, ?>>();

    cells.add(
        new StartActionHasCell(
            "Start process",
            new Delegate<ProcessSummary>() {
              @Override
              public void execute(ProcessSummary process) {
                PlaceRequest placeRequestImpl = new DefaultPlaceRequest("Form Display");
                System.out.println("Opening form for process id = " + process.getId());
                placeRequestImpl.addParameter("processId", process.getId());
                placeRequestImpl.addParameter("sessionId", String.valueOf(process.getSessionId()));
                placeManager.goTo(placeRequestImpl);
              }
            }));

    cells.add(
        new DetailsActionHasCell(
            "Details",
            new Delegate<ProcessSummary>() {
              @Override
              public void execute(ProcessSummary process) {

                PlaceRequest placeRequestImpl =
                    new DefaultPlaceRequest(constants.Process_Definition_Details());
                placeRequestImpl.addParameter("processId", process.getId());
                placeRequestImpl.addParameter(
                    "sessionId", Integer.toString(process.getSessionId()));
                placeManager.goTo(placeRequestImpl);
              }
            }));

    CompositeCell<ProcessSummary> cell = new CompositeCell<ProcessSummary>(cells);
    Column<ProcessSummary, ProcessSummary> actionsColumn =
        new Column<ProcessSummary, ProcessSummary>(cell) {
          @Override
          public ProcessSummary getValue(ProcessSummary object) {
            return object;
          }
        };
    processdefListGrid.addColumn(actionsColumn, "Actions");
    processdefListGrid.setColumnWidth(actionsColumn, "70px");
  }
 @WorkbenchPartTitle
 public String getTitle() {
   return constants.Process_Definitions();
 }