public MachineTableForm(String id) {
    super(id);
    this.selectedMachine = new LinkedList<Machine>();

    CheckGroup machineCheck = new CheckGroup("selected_machine", this.selectedMachine);
    this.add(machineCheck);

    Application app = (Application) this.getApplication();
    MachineList list = app.getMachineList();
    List<Machine> machinelist = list.getList();

    PropertyListView listview =
        new PropertyListView("machine_list", machinelist) {

          @Override
          protected void populateItem(ListItem item) {
            final Machine machine = (Machine) item.getModelObject();
            item.add(
                new Link("editlink") {
                  @Override
                  public void onClick() {
                    setResponsePage(new MachineEdit(machine));
                  }
                });
            item.add(new Check("selected", item.getModel()));
            item.add(new Label("kind", machine.getKind()));
            item.add(new Label("number", machine.getNumber().toString()));
            item.add(new Label("expense", machine.getExpense().toString()));
            item.add(new Label("productperday", machine.getProductperday().toString()));
          }
        };
    machineCheck.add(listview);
  }
Beispiel #2
0
  /**
   * Constructor
   *
   * @param id Wicket identifiant
   * @param checks List of checks
   * @param model Model of the default object
   */
  public ButtonCheckSet(
      String id, IModel<List<? extends ButtonElement<T>>> checks, IModel<Collection<T>> model) {
    super(id);

    checkGroup =
        new CheckGroup<T>("buttonCheckSetGroup", model) {
          private static final long serialVersionUID = 8265281439115476364L;

          /**
           * {@inheritDoc}
           *
           * @see
           *     org.apache.wicket.markup.html.form.CheckGroup#onSelectionChanged(java.util.Collection)
           */
          @Override
          protected void onSelectionChanged(final Collection<? extends T> newSelection) {
            ButtonCheckSet.this.onSelectionChanged(newSelection);
          }
        };
    ;
    checkGroup.setOutputMarkupId(true);
    checkGroup.setRenderBodyOnly(false);
    add(checkGroup);

    ListView<? extends ButtonElement<T>> view =
        new ListView<ButtonElement<T>>("buttonCheckSetView", checks) {
          private static final long serialVersionUID = 1L;

          /**
           * {@inheritDoc}
           *
           * @see
           *     org.apache.wicket.markup.html.list.ListView#populateItem(org.apache.wicket.markup.html.list.ListItem)
           */
          @Override
          protected void populateItem(ListItem<ButtonElement<T>> item) {
            ButtonElement<T> buttonElement = item.getModelObject();

            Check<T> check = newCheck("buttonCheck", buttonElement.getModel(), checkGroup);
            check.setLabel(buttonElement.getLabel());
            check.setOutputMarkupId(true);

            SimpleFormComponentLabel label =
                new SimpleFormComponentLabel("buttonCheckLabel", check);

            item.add(check);
            item.add(label);
          }
        };
    checkGroup.add(view);
  }
  /** @return */
  private CheckGroup<Process> newProcessCheckGroup() {
    CheckGroup<Process> checkGroup = new CheckGroup<>("processGroup", new ArrayList<Process>());
    checkGroup.add(
        new AjaxFormChoiceComponentUpdatingBehavior() {

          private static final long serialVersionUID = -6392535303739708646L;

          @Override
          protected void onUpdate(AjaxRequestTarget target) {
            updateDeleteSelectedButton(target);
          }
        });
    return checkGroup;
  }
  private <S extends Serializable> CheckGroup<S> newCheckGroup(
      final String id, List<S> candidateChoices) {
    CheckGroup<S> checkGroupComponent = new CheckGroup<S>(id);
    ListView<S> listView =
        new ListView<S>("loop", candidateChoices) {
          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(ListItem<S> item) {
            item.add(new Check<S>("check", new Model<S>(item.getModelObject())));
          }
        };
    checkGroupComponent.add(listView);
    return checkGroupComponent;
  }
  /**
   * Constructor building the page
   *
   * @param parameters
   */
  public ProcessManagementPage(final PageParameters parameters) {

    super(parameters);

    final ProcessProvider processProvider = new ProcessProvider();

    final Form<Process> deleteForm = new Form<>("deleteForm");
    add(deleteForm);

    filterPanel =
        new ProcessManagementPanel("filter") {

          @Override
          public void applyClicked(AjaxRequestTarget target, Form<?> form) {
            processProvider.setFilter(this.getFilter());
            target.add(processesContainer);
          }

          @Override
          public void resetClicked(AjaxRequestTarget target, Form<?> form) {
            processProvider.setFilter(new ProcessesFilterStructure());
            target.add(processesContainer);
          }
        };
    deleteForm.add(filterPanel);

    // add checkgroup for selecting multiple processes
    deleteForm.add(processGroup = newProcessCheckGroup());

    // add the container holding list of existing processes
    processGroup.add(processesContainer.setOutputMarkupId(true));

    processesContainer.add(new CheckGroupSelector("processGroupSelector", processGroup));

    DataView<Process> processes =
        new DataView<Process>("processes", processProvider, itemsPerPage) {

          private static final long serialVersionUID = 789669450347695209L;

          @Override
          protected void populateItem(final Item<Process> item) {
            final Process Process = item.getModelObject();

            item.add(new Check<>("processCheck", item.getModel(), processGroup));

            item.add(new Label("name", new PropertyModel<String>(Process, "name")));

            item.add(new Label("description", new PropertyModel<String>(Process, "description")));

            item.add(
                new DateLabel(
                    "startDate",
                    new PropertyModel<Date>(Process, "startDate"),
                    new PatternDateConverter("dd.MM.yyyy", true)));

            item.add(
                new DateLabel(
                    "endDate",
                    new PropertyModel<Date>(Process, "endDate"),
                    new PatternDateConverter("dd.MM.yyyy", true)));

            // add button to show AddEditPage
            item.add(
                new BookmarkablePageLink<ProcessAddEditPage>(
                    "edit", ProcessAddEditPage.class, ProcessAddEditPage.linkToEdit(Process)));
          }
        };
    // add list of processes to container
    processesContainer.add(processes);

    // add button to create new Process
    processesContainer.add(
        new BookmarkablePageLink<ProcessAddEditPage>("addProcessLink", ProcessAddEditPage.class));

    // add links for table pagination
    processesContainer.add(new BootstrapAjaxPagingNavigator("navigatorHead", processes));
    processesContainer.add(new BootstrapAjaxPagingNavigator("navigatorFoot", processes));

    // add button to delete selected products
    processesContainer.add(deleteSelectedButton = newDeleteSelectedButton(processGroup));

    // add confirmation modal for deleting products
    add(deleteConfirmationModal = newDeleteConfirmationModal());
  }
  @Override
  protected void onInitialize() {
    super.onInitialize();

    // Shared models
    final LoadableDetachableModel<QueueHelper> utilModel = QueueModelsUtil.ofQueueUtil(targetClass);
    final LoadableDetachableModel<Integer> sizeModel = QueueModelsUtil.ofAllQueuesSize(utilModel);

    // Navigation and tools
    final WebMarkupContainer navLinksContainer =
        new WebMarkupContainer("navLinksContainer", sizeModel) {
          @Override
          public boolean isVisible() {
            boolean isVisible = ((Integer) getDefaultModelObject()) != 0;
            return isVisible;
          }
        };
    navLinksContainer.setOutputMarkupId(true);

    // Links to each queue list
    RefreshingView<Integer> linksRepeater =
        new RefreshingView<Integer>("linksRepeater") {
          @Override
          protected Iterator<IModel<Integer>> getItemModels() {
            return QueueModelsUtil.ofAllQueues(utilModel);
          }

          @Override
          protected void populateItem(Item<Integer> item) {
            Integer targetClass = item.getModelObject();
            ExternalLink navLink =
                new ExternalLink("navLink", "#" + QueueHelper.codeNameMap.get(targetClass));
            navLink.setBody(QueueModelsUtil.ofQueueLocalizedSize(utilModel, targetClass));
            item.add(navLink);
          }
        };
    navLinksContainer.add(linksRepeater);

    // All queues
    final WebMarkupContainer queuesContainer =
        new WebMarkupContainer("queuesContainer", sizeModel) {
          @Override
          public boolean isVisible() {
            boolean isVisible = ((Integer) getDefaultModelObject()) != 0;
            return isVisible;
          }
        };
    queuesContainer.setOutputMarkupId(true);

    // From to get selected check boxes
    Form<Void> editForm = new Form<Void>("editForm");

    // Feedback panel
    FeedbackPanel feedback = new FeedbackPanel("feedback");
    editForm.add(feedback);

    // Group to collect identifier of all selected items
    final CheckGroup<String> selectedGroup =
        new CheckGroup<String>("selectedGroup", new ArrayList<String>());
    editForm.add(selectedGroup);
    // Remove button
    AjaxFallbackButton removeItems =
        new AjaxFallbackButton("removeItems", editForm) {
          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Collection<String> modelObject = selectedGroup.getModelObject();
            FCPServer fcp = utilModel.getObject().getFCPServer();
            for (String id : modelObject) {
              try {
                fcp.removeGlobalRequestBlocking(id);
                logger.debug("Successfully removed item with identifier: " + id);
              } catch (MessageInvalidException e) {
                String message = localize(L10N_REMOVE_FAILED);
                message += "(" + id + ")";
                form.error(message);
                logger.debug(message);
              } catch (DatabaseDisabledException e) {
                // Cannot happen. QueueUtil has been instantiated
                // already -> Database is active
              }
            }
            // Make sure that model is up-to-date
            utilModel.detach();
            if (target != null) {
              target.add(navLinksContainer, queuesContainer);
            }
          }
        };
    editForm.add(removeItems);
    // Change priority
    List<Short> priorities =
        Arrays.asList((short) 0, (short) 1, (short) 2, (short) 3, (short) 4, (short) 5, (short) 6);
    IChoiceRenderer<Short> priorityRenderer =
        new IChoiceRenderer<Short>() {
          @Override
          public Object getDisplayValue(Short object) {
            return localize(L10N_PRIO_PREFIX + object);
          }

          @Override
          public String getIdValue(Short object, int index) {
            return String.valueOf(object);
          }
        };
    final DropDownChoice<Short> prioritySelect =
        new DropDownChoice<Short>(
            "prioritySelect", Model.of((short) 0), priorities, priorityRenderer);
    editForm.add(prioritySelect);

    AjaxFallbackButton changePriority =
        new AjaxFallbackButton("changePriority", editForm) {
          @Override
          protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
            Collection<String> modelObject = selectedGroup.getModelObject();
            FCPServer fcp = utilModel.getObject().getFCPServer();
            for (String id : modelObject) {
              try {
                fcp.modifyGlobalRequestBlocking(id, null, prioritySelect.getModelObject());
                logger.debug("Successfully change priority of item with identifier: " + id);
              } catch (DatabaseDisabledException e) {
                // Cannot happen.
              }
            }
            utilModel.detach();
            if (target != null) {
              target.add(navLinksContainer, queuesContainer);
            }
          }
        };
    editForm.add(changePriority);

    queuesContainer.add(editForm);
    // All queues
    RefreshingView<Integer> queuesRepeater =
        new RefreshingView<Integer>("queuesRepeater") {
          @Override
          protected Iterator<IModel<Integer>> getItemModels() {
            return QueueModelsUtil.ofAllQueues(utilModel);
          }

          @Override
          protected void populateItem(Item<Integer> item) {
            int targetClass = item.getModelObject();
            String itemTitle = QueueHelper.codeNameMap.get(targetClass);
            // Outer container
            WebMarkupContainer queueContainer = new WebMarkupContainer("queueContainer");
            item.add(queueContainer);
            // Title and anchor
            Label title =
                new Label(
                    "queueTitle", QueueModelsUtil.ofQueueLocalizedSize(utilModel, targetClass));
            Label queueAnchor = new Label("queueAnchor");
            queueAnchor
                .setDefaultModel(Model.of("<a name=\"" + itemTitle + "\"></a>"))
                .setEscapeModelStrings(false);
            queueAnchor.setRenderBodyOnly(true);
            queueContainer.add(title, queueAnchor);
            // Queue itself
            RequestStatusView queue =
                new RequestStatusView("queue", utilModel, item.getModelObject());
            queue.setReuseItems(true);
            queueContainer.add(queue);
          }
        };
    selectedGroup.add(queuesRepeater);
    add(navLinksContainer, queuesContainer);
  }
  @Override
  public void onInitialize() {
    super.onInitialize();

    // unpack model
    final ImportWizardModel importWizardModel = this.model.getObject();

    final CheckGroup<ProcessedGradeItem> group =
        new CheckGroup<ProcessedGradeItem>("group", new ArrayList<ProcessedGradeItem>());

    final Form<?> form =
        new Form("form") {
          private static final long serialVersionUID = 1L;

          @Override
          protected void onSubmit() {
            boolean validated = true;

            final List<ProcessedGradeItem> selectedGradeItems =
                (List<ProcessedGradeItem>) group.getModelObject();
            log.debug("Processed items: " + selectedGradeItems.size());

            // this has an odd model so we need to have the validation in the onSubmit.
            if (selectedGradeItems.size() == 0) {
              validated = false;
              error(getString("importExport.selection.noneselected"));
            }

            if (validated) {

              // clear any previous errors
              final ImportExportPage page = (ImportExportPage) getPage();
              page.clearFeedback();

              // Process the selected items into the create/update lists
              final List<ProcessedGradeItem> itemsToUpdate =
                  filterListByStatus(
                      selectedGradeItems,
                      Arrays.asList(
                          ProcessedGradeItemStatus.STATUS_UPDATE,
                          ProcessedGradeItemStatus.STATUS_NA));
              final List<ProcessedGradeItem> itemsToCreate =
                  filterListByStatus(
                      selectedGradeItems, Arrays.asList(ProcessedGradeItemStatus.STATUS_NEW));

              log.debug("Filtered Update items: " + itemsToUpdate.size());
              log.debug("Filtered Create items: " + itemsToCreate.size());

              final List<ProcessedGradeItem> gbItemsToCreate = new ArrayList<ProcessedGradeItem>();
              itemsToCreate.forEach(
                  item -> {
                    // Don't want comment items here
                    if (!"N/A".equals(item.getItemPointValue())) {
                      gbItemsToCreate.add(item);
                    }
                  });

              log.debug("Actual items to create: " + gbItemsToCreate.size());

              // repaint panel
              Component newPanel = null;
              importWizardModel.setSelectedGradeItems(selectedGradeItems);
              importWizardModel.setGbItemsToCreate(gbItemsToCreate);
              importWizardModel.setItemsToCreate(itemsToCreate);
              importWizardModel.setItemsToUpdate(itemsToUpdate);
              if (gbItemsToCreate.size() > 0) {
                importWizardModel.setStep(1);
                importWizardModel.setTotalSteps(gbItemsToCreate.size());
                newPanel =
                    new CreateGradeItemStep(
                        GradeItemImportSelectionStep.this.panelId, Model.of(importWizardModel));
              } else {
                newPanel =
                    new GradeImportConfirmationStep(
                        GradeItemImportSelectionStep.this.panelId, Model.of(importWizardModel));
              }
              newPanel.setOutputMarkupId(true);
              GradeItemImportSelectionStep.this.replaceWith(newPanel);
            }
          }
        };
    add(form);
    form.add(group);

    final Button backButton =
        new Button("backbutton") {
          private static final long serialVersionUID = 1L;

          @Override
          public void onSubmit() {

            // clear any previous errors
            final ImportExportPage page = (ImportExportPage) getPage();
            page.clearFeedback();

            final Component newPanel =
                new GradeImportUploadStep(GradeItemImportSelectionStep.this.panelId);
            newPanel.setOutputMarkupId(true);
            GradeItemImportSelectionStep.this.replaceWith(newPanel);
          }
        };
    backButton.setDefaultFormProcessing(false);
    group.add(backButton);

    group.add(new Button("nextbutton"));

    group.add(new CheckGroupSelector("groupselector"));
    final ListView<ProcessedGradeItem> gradeList =
        new ListView<ProcessedGradeItem>("grades", importWizardModel.getProcessedGradeItems()) {
          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(final ListItem<ProcessedGradeItem> item) {

            final Check<ProcessedGradeItem> checkbox = new Check<>("checkbox", item.getModel());
            final Label itemTitle =
                new Label(
                    "itemTitle", new PropertyModel<String>(item.getDefaultModel(), "itemTitle"));
            final Label itemPointValue =
                new Label(
                    "itemPointValue",
                    new PropertyModel<String>(item.getDefaultModel(), "itemPointValue"));
            final Label itemStatus = new Label("itemStatus");

            item.add(checkbox);
            item.add(itemTitle);
            item.add(itemPointValue);
            item.add(itemStatus);

            // Use the status code to look up the text representation
            final PropertyModel<ProcessedGradeItemStatus> statusProp =
                new PropertyModel<ProcessedGradeItemStatus>(item.getDefaultModel(), "status");
            final ProcessedGradeItemStatus status = statusProp.getObject();

            // For external items, set a different label and disable the control
            if (status.getStatusCode() == ProcessedGradeItemStatus.STATUS_EXTERNAL) {
              itemStatus.setDefaultModel(
                  new StringResourceModel(
                      "importExport.status." + status.getStatusCode(),
                      statusProp,
                      null,
                      status.getStatusValue()));
              item.setEnabled(false);
              item.add(new AttributeModifier("class", "external"));
            } else {

              itemStatus.setDefaultModel(
                  new ResourceModel("importExport.status." + status.getStatusCode()));

              // if no changes, grey it out and remove checkbox
              if (status.getStatusCode() == ProcessedGradeItemStatus.STATUS_NA) {
                checkbox.setVisible(false);
                item.add(new AttributeAppender("class", Model.of("no_changes"), " "));
              }
            }

            final String naString =
                getString("importExport.selection.pointValue.na", new Model(), "N/A");
            if (naString.equals(item.getModelObject().getItemPointValue())) {
              item.add(new AttributeAppender("class", Model.of("comment"), " "));
            }

            // add an additional row for the comments for each
            final PropertyModel<String> commentLabelProp =
                new PropertyModel<String>(item.getDefaultModel(), "commentLabel");
            final PropertyModel<ProcessedGradeItemStatus> commentStatusProp =
                new PropertyModel<ProcessedGradeItemStatus>(
                    item.getDefaultModel(), "commentStatus");
            final String commentLabel = commentLabelProp.getObject();
            final ProcessedGradeItemStatus commentStatus = commentStatusProp.getObject();

            item.add(
                new Behavior() {
                  private static final long serialVersionUID = 1L;

                  @Override
                  public void afterRender(final Component component) {
                    super.afterRender(component);
                    if (commentLabel != null) {
                      String rowClass = "comment";
                      String statusValue =
                          getString("importExport.status." + commentStatus.getStatusCode());
                      if (commentStatus.getStatusCode()
                          == ProcessedGradeItemStatus.STATUS_EXTERNAL) {
                        rowClass += " external";
                        statusValue =
                            new StringResourceModel(
                                    "importExport.status." + commentStatus.getStatusCode(),
                                    commentStatusProp,
                                    null,
                                    commentStatus.getStatusValue())
                                .getString();
                      }
                      if (commentStatus.getStatusCode() == ProcessedGradeItemStatus.STATUS_NA) {
                        rowClass += " no_changes";
                      }

                      component
                          .getResponse()
                          .write(
                              "<tr class=\""
                                  + rowClass
                                  + "\">"
                                  + "<td></td>"
                                  + "<td class=\"item_title\">"
                                  + commentLabel
                                  + "</td>"
                                  + "<td class=\"item_points\">"
                                  + naString
                                  + "</td>"
                                  + "<td class=\"item_status\">"
                                  + statusValue
                                  + "</td>"
                                  + "</tr>");
                    }
                  }
                });
          }
        };

    gradeList.setReuseItems(true);
    group.add(gradeList);
  }