Ejemplo n.º 1
0
  private void initLayout(
      IModel<String> label, Form form, String valueCssClass, String inputCssClass) {
    // container
    WebMarkupContainer valueContainer = new WebMarkupContainer(ID_VALUE_CONTAINER);
    valueContainer.setOutputMarkupId(true);
    valueContainer.add(new AttributeModifier("class", valueCssClass));
    add(valueContainer);

    // feedback
    FeedbackPanel feedback = new FeedbackPanel(ID_FEEDBACK);
    feedback.setOutputMarkupId(true);
    add(feedback);

    // input
    Panel input = createInputComponent(ID_INPUT, label, form);
    input.add(new AttributeModifier("class", inputCssClass));
    if (input instanceof InputPanel) {
      initAccessBehaviour((InputPanel) input);
      feedback.setFilter(
          new ComponentFeedbackMessageFilter(((InputPanel) input).getBaseFormComponent()));
    }
    valueContainer.add(input);

    // buttons
    AjaxLink addButton =
        new AjaxLink("addButton") {

          @Override
          public void onClick(AjaxRequestTarget target) {
            addValue(target);
          }
        };
    addButton.add(
        new VisibleEnableBehaviour() {

          @Override
          public boolean isVisible() {
            return isAddButtonVisible();
          }
        });
    valueContainer.add(addButton);

    AjaxLink removeButton =
        new AjaxLink("removeButton") {

          @Override
          public void onClick(AjaxRequestTarget target) {
            removeValue(target);
          }
        };
    removeButton.add(
        new VisibleEnableBehaviour() {

          @Override
          public boolean isVisible() {
            return isRemoveButtonVisible();
          }
        });
    valueContainer.add(removeButton);
  }
Ejemplo n.º 2
0
  public ConsentWizardForm(String id, IModel interviewConsentModel) {
    super(id, interviewConsentModel);

    consentConfirmationStep = new ManualConsentStep(getStepId());
    electronicConsentStep = new ElectronicConsentStep(getStepId(), consentConfirmationStep);
    consentModeSelectionStep =
        new ConsentModeSelectionStep(getStepId(), electronicConsentStep, consentConfirmationStep);

    WizardStepPanel startStep = setupWizardFlow();

    startStep.onStepInNext(this, null);
    startStep.handleWizardState(this, null);
    add(startStep);

    createModalAdministrationPanel();

    // admin button
    AjaxLink link =
        new AjaxLink("adminLink") {
          private static final long serialVersionUID = 0L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            adminWindow.setInitialWidth(350);
            adminWindow.setInterruptState(false);
            if (getCancelLink() != null) adminWindow.setCancelState(getCancelLink().isEnabled());
            adminWindow.show(target);
          }
        };
    link.add(
        new AttributeModifier(
            "value", true, new StringResourceModel("Administration", this, null)));
    link.add(new AttributeAppender("class", new Model("ui-corner-all"), " "));
    add(link);
  }
  /**
   * Either creates a link for the action be rendered in a {@link ModalWindow}, or (if none can be
   * {@link ActionPromptProvider#getActionPrompt() provided}, or creates a link to the {@link
   * ActionPromptPage} (ie the {@link PageClassRegistry registered page} for {@link
   * PageType#ACTION_PROMPT action}s).
   *
   * <p>If the action's {@link ObjectAction#getSemantics() semantics} are {@link
   * ActionSemantics.Of#SAFE safe}, then concurrency checking is disabled; otherwise it is enforced.
   */
  protected AbstractLink newLink(
      final String linkId,
      final ObjectAdapter objectAdapter,
      final ObjectAction action,
      final ActionPromptProvider actionPromptProvider) {

    final ActionPrompt actionPrompt = actionPromptProvider.getActionPrompt();
    if (actionPrompt != null) {
      final ActionModel actionModel = ActionModel.create(objectAdapter, action);
      actionModel.setActionPrompt(actionPrompt);
      AjaxLink<Object> link =
          new AjaxLink<Object>(linkId) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {

              final ActionPanel actionPromptPanel =
                  (ActionPanel)
                      getComponentFactoryRegistry()
                          .createComponent(
                              ComponentType.ACTION_PROMPT,
                              actionPrompt.getContentId(),
                              actionModel);

              actionPrompt.setPanel(actionPromptPanel, target);
              actionPrompt.show(target);

              target.focusComponent(actionPromptPanel);
            }
          };
      link.add(new CssClassAppender("noVeil"));
      return link;

    } else {

      // use the action semantics to determine whether invoking this action will require a
      // concurrency check or not
      // if it's "safe", then we'll just continue without any checking.
      final ConcurrencyChecking concurrencyChecking =
          ConcurrencyChecking.concurrencyCheckingFor(action.getSemantics());
      final PageParameters pageParameters =
          ActionModel.createPageParameters(objectAdapter, action, concurrencyChecking);
      final Class<? extends Page> pageClass =
          getPageClassRegistry().getPageClass(PageType.ACTION_PROMPT);
      AbstractLink link = Links.newBookmarkablePageLink(linkId, pageParameters, pageClass);

      // special case handling if this a no-arg action is returning a URL
      if (action.getParameterCount() == 0) {
        addTargetBlankIfActionReturnsUrl(link, action);
      }

      return link;
    }
  }
  /** Initializes UI. */
  protected void initUI() {
    AjaxLink<Void> link =
        new AjaxLink<Void>(CKEY_LINK) {
          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            LinkButton.this.onClick(target);
          }
        };
    add(link);

    link.add(new Label(CKEY_LABEL, getDefaultModel()));
  }
Ejemplo n.º 5
0
 public ButtonFragment(String id, IModel<Button> model) {
   super(id, "buttonFragment", SortableList.this, model);
   final Button button = model.getObject();
   AjaxLink<Void> ajaxLink =
       new AjaxLink<Void>("button") {
         @Override
         public void onClick(AjaxRequestTarget target) {
           button.callback(target);
         }
       };
   Image image = new Image("buttonImg", button.getImage());
   image.setVisible(button.getImage() != null);
   ajaxLink.add(image);
   ajaxLink.add(new Label("buttonLabel", button.getTitle()));
   add(ajaxLink);
 }
Ejemplo n.º 6
0
 public void updateCommentsCount() {
   viewComments.addOrReplace(
       commentsCount =
           new Label(
               "commentsCount",
               String.valueOf(activeInterviewService.getInterviewComments().size())));
   commentsCount.setOutputMarkupId(true);
 }
Ejemplo n.º 7
0
  public InstrumentWizardForm(String id, IModel<InstrumentType> instrumentTypeModel) {
    super(id, instrumentTypeModel);

    // Add Interrupt button.
    add(createInterrupt());

    InstrumentType type = (InstrumentType) instrumentTypeModel.getObject();
    log.debug("instrumentType={}", type.getName());

    observedContraIndicationStep = new ObservedContraIndicationStep(getStepId());
    askedContraIndicationStep = new AskedContraIndicationStep(getStepId());
    instrumentSelectionStep = new InstrumentSelectionStep(getStepId(), instrumentTypeModel);
    noInstrumentAvailableStep = new NoInstrumentAvailableStep(getStepId());
    inputParametersStep = new InputParametersStep(getStepId());
    instrumentLaunchStep = new InstrumentLaunchStep(getStepId());
    conclusionStep = new ConclusionStep(getStepId());
    warningStep = new WarningsStep(getStepId());
    outputParametersStep = new OutputParametersStep(getStepId(), conclusionStep, warningStep);

    warningStep.setNextStep(conclusionStep);
    warningStep.setPreviousStep(outputParametersStep);

    createModalAdministrationPanel();

    // admin button
    AjaxLink link =
        new AjaxLink("adminLink") {
          private static final long serialVersionUID = 0L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            adminWindow.setInterruptState(getInterruptLink().isEnabled());
            if (getCancelLink() != null) adminWindow.setCancelState(getCancelLink().isEnabled());
            adminWindow.show(target);
          }
        };
    link.add(
        new AttributeModifier(
            "value", true, new StringResourceModel("Administration", this, null)));
    link.add(new AttributeAppender("class", new Model("ui-corner-all"), " "));
    add(link);
  }
Ejemplo n.º 8
0
  private AjaxLink createInterrupt() {
    AjaxLink link =
        new AjaxLink("interrupt") {
          private static final long serialVersionUID = 0L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            onInterrupt(target);
          }

          @Override
          public boolean isVisible() {
            IStageExecution exec =
                activeInterviewService.getStageExecution((Stage) stageModel.getObject());
            return exec.getActionDefinition(ActionType.INTERRUPT) != null;
          }
        };
    link.add(
        new AttributeModifier(
            "value", true, new StringResourceModel("Interrupt", InstrumentWizardForm.this, null)));

    return link;
  }
  private void initButtons(WebMarkupContainer buttonGroup, final ListItem<T> item) {
    AjaxLink add =
        new AjaxLink(ID_ADD) {

          @Override
          public void onClick(AjaxRequestTarget target) {
            addValuePerformed(target);
          }
        };
    add.add(
        new VisibleEnableBehaviour() {

          @Override
          public boolean isVisible() {
            return isAddButtonVisible(item);
          }
        });
    buttonGroup.add(add);

    AjaxLink remove =
        new AjaxLink(ID_REMOVE) {

          @Override
          public void onClick(AjaxRequestTarget target) {
            removeValuePerformed(target, item);
          }
        };
    remove.add(
        new VisibleEnableBehaviour() {

          @Override
          public boolean isVisible() {
            return isRemoveButtonVisible();
          }
        });
    buttonGroup.add(remove);
  }
Ejemplo n.º 10
0
  private void updateClearLink(InputFieldVisibility visibility) {
    final MarkupContainer formComponent = (MarkupContainer) getComponentForRegular();
    formComponent.setOutputMarkupId(true); // enable ajax link

    final AjaxLink<Void> ajaxLink =
        new AjaxLink<Void>(ID_SCALAR_IF_REGULAR_CLEAR) {
          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            setEnabled(false);
            ScalarModel model = IsisBlobOrClobPanelAbstract.this.getModel();
            model.setObject(null);
            target.add(formComponent);
          }
        };
    ajaxLink.setOutputMarkupId(true);
    formComponent.addOrReplace(ajaxLink);

    final T blob = getBlob(getModel());
    formComponent
        .get(ID_SCALAR_IF_REGULAR_CLEAR)
        .setVisible(blob != null && visibility == InputFieldVisibility.VISIBLE);
  }
Ejemplo n.º 11
0
  private Fragment getResurceFragment(final TopologyNode node, final PageReference pageRef) {
    final Fragment fragment = new Fragment("actions", "resourceActions", this);

    final AjaxLink<String> delete =
        new IndicatingAjaxLink<String>("delete") {

          private static final long serialVersionUID = 3776750333491622263L;

          @Override
          public void onClick(final AjaxRequestTarget target) {
            try {
              resourceRestClient.delete(node.getKey().toString());
              target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey()));
              info(getString(Constants.OPERATION_SUCCEEDED));
            } catch (SyncopeClientException e) {
              error(getString(Constants.ERROR) + ": " + e.getMessage());
              LOG.error("While deleting resource {}", node.getKey(), e);
            }
            ((BasePage) getPage()).getNotificationPanel().refresh(target);
          }
        };
    fragment.add(delete);

    delete.add(new ConfirmationModalBehavior());

    MetaDataRoleAuthorizationStrategy.authorize(
        delete, ENABLE, StandardEntitlement.RESOURCE_DELETE);

    final AjaxLink<String> edit =
        new IndicatingAjaxLink<String>("edit") {

          private static final long serialVersionUID = 3776750333491622263L;

          @Override
          public void onClick(final AjaxRequestTarget target) {
            final ResourceTO modelObject = resourceRestClient.read(node.getKey().toString());

            final IModel<ResourceTO> model = new CompoundPropertyModel<>(modelObject);
            resourceModal.setFormModel(model);

            target.add(
                resourceModal.setContent(
                    new ResourceModal<>(resourceModal, pageRef, model, false)));

            resourceModal.header(
                new Model<>(MessageFormat.format(getString("resource.edit"), node.getKey())));

            MetaDataRoleAuthorizationStrategy.authorize(
                resourceModal.addSumbitButton(), ENABLE, StandardEntitlement.RESOURCE_UPDATE);

            resourceModal.show(true);
          }
        };
    fragment.add(edit);
    MetaDataRoleAuthorizationStrategy.authorize(edit, ENABLE, StandardEntitlement.RESOURCE_UPDATE);

    final AjaxLink<String> propagation =
        new IndicatingAjaxLink<String>("propagation") {

          private static final long serialVersionUID = 3776750333491622263L;

          @Override
          @SuppressWarnings("unchecked")
          public void onClick(final AjaxRequestTarget target) {
            target.add(
                taskModal.setContent(new PropagationTasks(pageRef, node.getKey().toString())));
            taskModal.header(new ResourceModel("task.propagation.list", "Propagation tasks"));
            taskModal.show(true);
          }
        };
    fragment.add(propagation);
    MetaDataRoleAuthorizationStrategy.authorize(propagation, ENABLE, StandardEntitlement.TASK_LIST);

    final AjaxLink<String> synchronization =
        new IndicatingAjaxLink<String>("synchronization") {

          private static final long serialVersionUID = 3776750333491622263L;

          @Override
          public void onClick(final AjaxRequestTarget target) {
            target.add(taskModal.setContent(new SyncTasks(pageRef, node.getKey().toString())));
            taskModal.header(
                new ResourceModel("task.synchronization.list", "Synchronization tasks"));
            taskModal.show(true);
          }
        };
    fragment.add(synchronization);
    MetaDataRoleAuthorizationStrategy.authorize(
        synchronization, ENABLE, StandardEntitlement.TASK_LIST);

    final AjaxLink<String> push =
        new IndicatingAjaxLink<String>("push") {

          private static final long serialVersionUID = 3776750333491622263L;

          @Override
          public void onClick(final AjaxRequestTarget target) {
            target.add(taskModal.setContent(new PushTasks(pageRef, node.getKey().toString())));
            taskModal.header(new ResourceModel("task.push.list", "Push tasks"));
            taskModal.show(true);
          }
        };
    fragment.add(push);
    MetaDataRoleAuthorizationStrategy.authorize(push, ENABLE, StandardEntitlement.TASK_LIST);

    return fragment;
  }
Ejemplo n.º 12
0
  public PageLogin() {
    if (SecurityUtils.getPrincipalUser() != null) {
      MidPointApplication app = getMidpointApplication();
      setResponsePage(app.getHomePage());
    }

    BookmarkablePageLink<String> link =
        new BookmarkablePageLink<>(ID_FORGET_PASSWORD, PageForgotPassword.class);
    link.add(
        new VisibleEnableBehaviour() {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean isVisible() {
            OperationResult parentResult =
                new OperationResult(OPERATION_LOAD_RESET_PASSWORD_POLICY);

            SecurityPolicyType securityPolicy = null;
            try {
              securityPolicy =
                  getModelInteractionService().getSecurityPolicy(null, null, parentResult);
            } catch (ObjectNotFoundException | SchemaException e) {
              LOGGER.warn("Cannot read credentials policy: " + e.getMessage(), e);
            }

            boolean linkIsVisible = false;

            if (securityPolicy == null) {
              return linkIsVisible;
            }

            CredentialsPolicyType creds = securityPolicy.getCredentials();

            if (creds != null
                && ((creds.getSecurityQuestions() != null
                        && creds.getSecurityQuestions().getQuestionNumber() != null)
                    || (securityPolicy.getCredentialsReset() != null))) {
              linkIsVisible = true;
            }

            return linkIsVisible;
          }
        });
    add(link);

    AjaxLink<String> registration =
        new AjaxLink<String>(ID_SELF_REGISTRATION) {

          @Override
          public void onClick(AjaxRequestTarget target) {
            setResponsePage(PageSelfRegistration.class);
          }
        };
    registration.add(
        new VisibleEnableBehaviour() {
          private static final long serialVersionUID = 1L;

          @Override
          public boolean isVisible() {
            OperationResult parentResult = new OperationResult(OPERATION_LOAD_REGISTRATION_POLICY);

            RegistrationsPolicyType registrationPolicies = null;
            try {
              Task task = createAnonymousTask(OPERATION_LOAD_REGISTRATION_POLICY);
              registrationPolicies =
                  getModelInteractionService().getRegistrationPolicy(null, task, parentResult);
            } catch (ObjectNotFoundException | SchemaException e) {
              LOGGER.warn("Cannot read credentials policy: " + e.getMessage(), e);
            }

            boolean linkIsVisible = false;
            if (registrationPolicies != null
                && registrationPolicies.getSelfRegistration() != null) {
              linkIsVisible = true;
            }

            return linkIsVisible;
          }
        });
    add(registration);
  }
Ejemplo n.º 13
0
  protected void initLayout() {
    final ValueModel valueModel = model.getObject();
    FieldDisplayType display = valueModel.getDefaultDisplay();

    // todo help
    Label label =
        new Label("label", new StringResourceModel(display.getLabel(), null, display.getLabel()));
    label.add(
        new AttributeModifier(
            "style",
            new AbstractReadOnlyModel<String>() {

              @Override
              public String getObject() {
                if (valueModel.getVisibleValueIndex() > 0) {
                  return "visibility: hidden;";
                }
                return null;
              }
            }));

    if (StringUtils.isNotEmpty(display.getTooltip())) {
      label.add(
          new AttributeModifier(
              "title", new StringResourceModel(display.getTooltip(), null, display.getTooltip())));
    }
    add(label);

    FieldToken fieldToken = valueModel.getField().getToken();
    UiWidget widget = initWidget(fieldToken.getWidget(), display.getProperty());
    add(widget);

    FeedbackPanel feedback = new FeedbackPanel("feedback");
    feedback.setFilter(new ComponentFeedbackMessageFilter(widget.getBaseFormComponent()));
    feedback.setOutputMarkupId(true);
    add(feedback);

    AjaxLink addButton =
        new AjaxLink("addButton") {

          @Override
          public void onClick(AjaxRequestTarget target) {
            addValue(target);
          }
        };
    addButton.add(
        new VisibleEnableBehaviour() {

          @Override
          public boolean isVisible() {
            return valueModel.isAddButtonVisible();
          }
        });
    add(addButton);

    AjaxLink removeButton =
        new AjaxLink("removeButton") {

          @Override
          public void onClick(AjaxRequestTarget target) {
            removeValue(target);
          }
        };
    removeButton.add(
        new VisibleEnableBehaviour() {

          @Override
          public boolean isVisible() {
            return valueModel.isRemoveButtonVisible();
          }
        });
    add(removeButton);
  }
Ejemplo n.º 14
0
  public AjaxPagingPanel(String id, final SearchCriteria criteria) {
    super(id);

    globalContainer = new WebMarkupContainer("globalContainer");
    add(globalContainer.setOutputMarkupId(true));

    next =
        new AjaxLink("next") {
          @Override
          public void onClick(AjaxRequestTarget art) {
            criteria.next();
            refreshPaging(art, criteria);
          }

          @Override
          public boolean isEnabled() {
            return !criteria.isLastPage();
          }
        };
    globalContainer.add(next.setOutputMarkupId(true));

    prev =
        new AjaxLink("prev") {
          @Override
          public void onClick(AjaxRequestTarget art) {
            criteria.prev();
            refreshPaging(art, criteria);
          }

          @Override
          public boolean isEnabled() {
            return !criteria.isFirstPage();
          }
        };
    globalContainer.add(prev.setOutputMarkupId(true));

    snext =
        new AjaxLink("snext") {
          @Override
          public void onClick(AjaxRequestTarget art) {
            criteria.snext();
            refreshPaging(art, criteria);
          }

          @Override
          public boolean isEnabled() {
            return !criteria.isLastPage();
          }
        };
    globalContainer.add(snext.setOutputMarkupId(true));

    sprev =
        new AjaxLink("sprev") {
          @Override
          public void onClick(AjaxRequestTarget art) {
            criteria.sprev();
            refreshPaging(art, criteria);
          }

          @Override
          public boolean isEnabled() {
            return !criteria.isFirstPage();
          }
        };
    globalContainer.add(sprev.setOutputMarkupId(true));

    numbers =
        new ListView("numbers", criteria.getNumbers()) {

          @Override
          protected void populateItem(ListItem li) {
            final long pageNum = (Long) li.getModelObject();
            final Label number = new Label("number", pageNum + "");
            final AjaxLink numberLink =
                new AjaxLink("numberLink") {
                  @Override
                  public void onClick(AjaxRequestTarget art) {
                    criteria.toPage(pageNum);
                    refreshPaging(art, criteria);
                  }
                };
            if (pageNum != criteria.getCurrent()) {
              numberLink.setEnabled(true);
              li.add(AttributeModifier.remove("class"));
            } else {
              numberLink.setEnabled(false);
              li.add(AttributeModifier.append("class", "active"));
            }
            numberLink.add(number);
            li.add(numberLink);
          }
        };
    globalContainer.add(numbers.setOutputMarkupId(true));
  }
Ejemplo n.º 15
0
  private Fragment getConnectorFragment(final TopologyNode node, final PageReference pageRef) {
    final Fragment fragment = new Fragment("actions", "connectorActions", this);

    final AjaxLink<String> delete =
        new IndicatingAjaxLink<String>("delete") {

          private static final long serialVersionUID = 3776750333491622263L;

          @Override
          public void onClick(final AjaxRequestTarget target) {
            try {
              connectorRestClient.delete(Long.class.cast(node.getKey()));
              target.appendJavaScript(String.format("jsPlumb.remove('%s');", node.getKey()));
              info(getString(Constants.OPERATION_SUCCEEDED));
            } catch (SyncopeClientException e) {
              error(getString(Constants.ERROR) + ": " + e.getMessage());
              LOG.error("While deleting resource {}", node.getKey(), e);
            }
            ((BasePage) getPage()).getNotificationPanel().refresh(target);
          }
        };

    fragment.add(delete);
    delete.add(new ConfirmationModalBehavior());

    MetaDataRoleAuthorizationStrategy.authorize(
        delete, ENABLE, StandardEntitlement.CONNECTOR_DELETE);

    final AjaxLink<String> create =
        new IndicatingAjaxLink<String>("create") {

          private static final long serialVersionUID = 3776750333491622263L;

          @Override
          public void onClick(final AjaxRequestTarget target) {
            final ResourceTO modelObject = new ResourceTO();
            modelObject.setConnector(Long.class.cast(node.getKey()));
            modelObject.setConnectorDisplayName(node.getDisplayName());

            final IModel<ResourceTO> model = new CompoundPropertyModel<>(modelObject);
            resourceModal.setFormModel(model);

            target.add(
                resourceModal.setContent(new ResourceModal<>(resourceModal, pageRef, model, true)));

            resourceModal.header(
                new Model<>(MessageFormat.format(getString("resource.new"), node.getKey())));

            MetaDataRoleAuthorizationStrategy.authorize(
                resourceModal.addSumbitButton(), ENABLE, StandardEntitlement.RESOURCE_CREATE);

            resourceModal.show(true);
          }
        };
    fragment.add(create);

    MetaDataRoleAuthorizationStrategy.authorize(
        create, ENABLE, StandardEntitlement.RESOURCE_CREATE);

    final AjaxLink<String> edit =
        new IndicatingAjaxLink<String>("edit") {

          private static final long serialVersionUID = 3776750333491622263L;

          @Override
          public void onClick(final AjaxRequestTarget target) {
            final ConnInstanceTO modelObject =
                connectorRestClient.read(Long.class.cast(node.getKey()));

            final IModel<ConnInstanceTO> model = new CompoundPropertyModel<>(modelObject);
            resourceModal.setFormModel(model);

            target.add(resourceModal.setContent(new ConnectorModal(resourceModal, pageRef, model)));

            resourceModal.header(
                new Model<>(MessageFormat.format(getString("connector.edit"), node.getKey())));

            MetaDataRoleAuthorizationStrategy.authorize(
                resourceModal.addSumbitButton(), ENABLE, StandardEntitlement.CONNECTOR_UPDATE);

            resourceModal.show(true);
          }
        };
    fragment.add(edit);

    MetaDataRoleAuthorizationStrategy.authorize(edit, ENABLE, StandardEntitlement.CONNECTOR_UPDATE);

    return fragment;
  }
  private void setupComponents() {

    setPageTitle(ResourceUtils.getModel("pageTitle.weatherDefinitionsList"));

    add(new ButtonPageMenu("leftMenu", ListsLeftPageMenu.values()));

    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupPlaceholderTag(true);

    final ListModelWithResearchGroupCriteria<Weather> model =
        new ListModelWithResearchGroupCriteria<Weather>() {

          private static final long serialVersionUID = 1L;

          @Override
          protected List<Weather> loadList(ResearchGroup group) {
            if (group == null || group.getResearchGroupId() == CoreConstants.DEFAULT_ITEM_ID)
              return facade.getDefaultRecords();
            else {
              return facade.getRecordsByGroup(group.getResearchGroupId());
            }
          }
        };

    List<ResearchGroup> groups;
    final boolean isAdmin = security.isAdmin();
    final boolean isExperimenter = security.userIsExperimenter();
    if (isAdmin) {
      ResearchGroup defaultGroup =
          new ResearchGroup(
              CoreConstants.DEFAULT_ITEM_ID,
              EEGDataBaseSession.get().getLoggedUser(),
              ResourceUtils.getString("label.defaultWeather"),
              "-");
      groups = researchGroupFacade.getAllRecords();
      groups.add(0, defaultGroup);
    } else
      groups =
          researchGroupFacade.getResearchGroupsWhereMember(
              EEGDataBaseSession.get().getLoggedUser());

    PropertyListView<Weather> weathers =
        new PropertyListView<Weather>("weathers", model) {

          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(final ListItem<Weather> item) {
            item.add(new Label("weatherId"));
            item.add(new Label("title"));
            item.add(new Label("description"));

            PageParameters parameters =
                PageParametersUtils.getDefaultPageParameters(item.getModelObject().getWeatherId())
                    .add(
                        PageParametersUtils.GROUP_PARAM,
                        (model.getCriteriaModel().getObject() == null)
                            ? CoreConstants.DEFAULT_ITEM_ID
                            : model.getCriteriaModel().getObject().getResearchGroupId());

            item.add(new BookmarkablePageLink<Void>("edit", WeatherFormPage.class, parameters));
            item.add(
                new AjaxLink<Void>("delete") {

                  private static final long serialVersionUID = 1L;

                  @Override
                  public void onClick(AjaxRequestTarget target) {

                    int id = item.getModelObject().getWeatherId();
                    ResearchGroup group = model.getCriteriaModel().getObject();

                    if (facade.canDelete(id)) {
                      if (group != null) {
                        int groupId = group.getResearchGroupId();

                        if (groupId
                            == CoreConstants
                                .DEFAULT_ITEM_ID) { // delete default weather if it's from default
                          // group
                          if (!facade.hasGroupRel(
                              id)) { // delete only if it doesn't have group relationship
                            facade.delete(item.getModelObject());
                            setResponsePage(ListWeatherDefinitiosPage.class);
                          } else {
                            getFeedback().error(ResourceUtils.getString("text.itemInUse"));
                          }
                        } else {
                          WeatherGroupRel h = facade.getGroupRel(id, groupId);
                          if (!facade.isDefault(id)) { // delete only non default weather
                            facade.delete(item.getModelObject());
                          }
                          facade.deleteGroupRel(h);
                          setResponsePage(ListWeatherDefinitiosPage.class);
                        }
                      }

                    } else {
                      getFeedback().error(ResourceUtils.getString("text.itemInUse"));
                    }

                    target.add(container);
                    target.add(getFeedback());
                  }

                  @Override
                  protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                    super.updateAjaxAttributes(attributes);

                    AjaxCallListener ajaxCallListener = new AjaxCallListener();
                    ajaxCallListener.onPrecondition(
                        "return confirm('Are you sure you want to delete item?');");
                    attributes.getAjaxCallListeners().add(ajaxCallListener);
                  }
                }.setVisibilityAllowed(isAdmin || isExperimenter));
          }
        };
    container.add(weathers);

    AjaxLink<Void> link =
        new AjaxLink<Void>("addWeatherLink") {

          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            int researchGroupId =
                (model.getCriteriaModel().getObject() == null)
                    ? CoreConstants.DEFAULT_ITEM_ID
                    : model.getCriteriaModel().getObject().getResearchGroupId();
            setResponsePage(
                WeatherFormPage.class,
                PageParametersUtils.getPageParameters(
                    PageParametersUtils.GROUP_PARAM, researchGroupId));
          }
        };
    link.setVisibilityAllowed(isAdmin || isExperimenter);

    add(
        new ResearchGroupSelectForm(
            "form",
            model.getCriteriaModel(),
            new ListModel<ResearchGroup>(groups),
            container,
            isAdmin));
    add(link, container);
  }
Ejemplo n.º 17
0
  protected void populateCell(
      WebMarkupContainer cellContainer, final AssignmentEditorDto assignment) {
    AjaxLink inner =
        new AjaxLink(ID_INNER) {
          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            assignmentDetailsPerformed(assignment, ajaxRequestTarget);
          }
        };
    cellContainer.add(inner);

    Label nameLabel = new Label(ID_INNER_LABEL, assignment.getName());
    inner.add(nameLabel);

    AjaxLink detailsLink =
        new AjaxLink(ID_DETAILS_LINK) {
          @Override
          public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            assignmentDetailsPerformed(assignment, ajaxRequestTarget);
          }
        };
    cellContainer.add(detailsLink);

    Label detailsLinkLabel =
        new Label(
            ID_DETAILS_LINK_LABEL, pageBase.createStringResource("MultiButtonPanel.detailsLink"));
    detailsLinkLabel.setRenderBodyOnly(true);
    detailsLink.add(detailsLinkLabel);

    AjaxLink detailsLinkIcon =
        new AjaxLink(ID_DETAILS_LINK_ICON) {
          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget target) {}
        };
    detailsLink.add(detailsLinkIcon);

    AjaxLink addToCartLink =
        new AjaxLink(ID_ADD_TO_CART_LINK) {
          @Override
          public void onClick(AjaxRequestTarget ajaxRequestTarget) {
            addAssignmentPerformed(assignment, ajaxRequestTarget);
          }
        };
    cellContainer.add(addToCartLink);

    AjaxLink addToCartLinkIcon =
        new AjaxLink(ID_ADD_TO_CART_LINK_ICON) {
          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget target) {}
        };
    addToCartLink.add(addToCartLinkIcon);

    WebMarkupContainer icon = new WebMarkupContainer(ID_TYPE_ICON);
    icon.add(new AttributeAppender("class", getIconClass(assignment.getType())));
    cellContainer.add(icon);
  }