Example usage for org.apache.wicket.markup.html.list ListView setOutputMarkupId

List of usage examples for org.apache.wicket.markup.html.list ListView setOutputMarkupId

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.list ListView setOutputMarkupId.

Prototype

public final Component setOutputMarkupId(final boolean output) 

Source Link

Document

Sets whether or not component will output id attribute into the markup.

Usage

From source file:org.apache.syncope.client.console.widgets.ProgressesPanel.java

License:Apache License

public ProgressesPanel(final String id, final Date lastUpdate, final List<ProgressBean> progressBeans) {
    super(id);/*  w  w w. j  a  v a2  s.c o  m*/

    add(new Label("lastUpdate", SyncopeConsoleSession.get().getDateFormat().format(lastUpdate)));

    ListView<ProgressBean> progresses = new ListView<ProgressBean>("progresses", progressBeans) {

        private static final long serialVersionUID = -9180479401817023838L;

        @Override
        protected void populateItem(final ListItem<ProgressBean> item) {
            item.add(new ProgressPanel("progress", item.getModelObject()));
        }
    };
    progresses.setOutputMarkupId(true);
    add(progresses);
}

From source file:org.apache.syncope.console.pages.ConnectorModalPage.java

License:Apache License

public ConnectorModalPage(final PageReference pageRef, final ModalWindow window,
        final ConnInstanceTO connInstanceTO) {

    super();//from w w w .  j  a v a 2 s  .  co  m

    // general data setup
    selectedCapabilities = new ArrayList<ConnectorCapability>(
            connInstanceTO.getId() == 0 ? EnumSet.noneOf(ConnectorCapability.class)
                    : connInstanceTO.getCapabilities());

    mapConnBundleTOs = new HashMap<String, Map<String, Map<String, ConnBundleTO>>>();
    for (ConnBundleTO connBundleTO : restClient.getAllBundles()) {
        // by location
        if (!mapConnBundleTOs.containsKey(connBundleTO.getLocation())) {
            mapConnBundleTOs.put(connBundleTO.getLocation(), new HashMap<String, Map<String, ConnBundleTO>>());
        }
        final Map<String, Map<String, ConnBundleTO>> byLocation = mapConnBundleTOs
                .get(connBundleTO.getLocation());

        // by name
        if (!byLocation.containsKey(connBundleTO.getBundleName())) {
            byLocation.put(connBundleTO.getBundleName(), new HashMap<String, ConnBundleTO>());
        }
        final Map<String, ConnBundleTO> byName = byLocation.get(connBundleTO.getBundleName());

        // by version
        if (!byName.containsKey(connBundleTO.getVersion())) {
            byName.put(connBundleTO.getVersion(), connBundleTO);
        }
    }

    bundleTO = getSelectedBundleTO(connInstanceTO);
    properties = fillProperties(bundleTO, connInstanceTO);

    // form - first tab
    final Form<ConnInstanceTO> connectorForm = new Form<ConnInstanceTO>(FORM);
    connectorForm.setModel(new CompoundPropertyModel<ConnInstanceTO>(connInstanceTO));
    connectorForm.setOutputMarkupId(true);
    add(connectorForm);

    propertiesContainer = new WebMarkupContainer("container");
    propertiesContainer.setOutputMarkupId(true);
    connectorForm.add(propertiesContainer);

    final Form<ConnInstanceTO> connectorPropForm = new Form<ConnInstanceTO>("connectorPropForm");
    connectorPropForm.setModel(new CompoundPropertyModel<ConnInstanceTO>(connInstanceTO));
    connectorPropForm.setOutputMarkupId(true);
    propertiesContainer.add(connectorPropForm);

    final AjaxTextFieldPanel displayName = new AjaxTextFieldPanel("displayName", "display name",
            new PropertyModel<String>(connInstanceTO, "displayName"));
    displayName.setOutputMarkupId(true);
    displayName.addRequiredLabel();
    connectorForm.add(displayName);

    final AjaxDropDownChoicePanel<String> location = new AjaxDropDownChoicePanel<String>("location", "location",
            new Model<String>(bundleTO == null ? null : bundleTO.getLocation()));
    ((DropDownChoice<String>) location.getField()).setNullValid(true);
    location.setStyleSheet("long_dynamicsize");
    location.setChoices(new ArrayList<String>(mapConnBundleTOs.keySet()));
    location.setRequired(true);
    location.addRequiredLabel();
    location.setOutputMarkupId(true);
    location.setEnabled(connInstanceTO.getId() == 0);
    location.getField().setOutputMarkupId(true);
    connectorForm.add(location);

    final AjaxDropDownChoicePanel<String> connectorName = new AjaxDropDownChoicePanel<String>("connectorName",
            "connectorName", new Model<String>(bundleTO == null ? null : bundleTO.getBundleName()));
    ((DropDownChoice<String>) connectorName.getField()).setNullValid(true);
    connectorName.setStyleSheet("long_dynamicsize");
    connectorName.setChoices(bundleTO == null ? new ArrayList<String>()
            : new ArrayList<String>(mapConnBundleTOs.get(connInstanceTO.getLocation()).keySet()));
    connectorName.setRequired(true);
    connectorName.addRequiredLabel();
    connectorName.setEnabled(connInstanceTO.getLocation() != null);
    connectorName.setOutputMarkupId(true);
    connectorName.setEnabled(connInstanceTO.getId() == 0);
    connectorName.getField().setOutputMarkupId(true);
    connectorForm.add(connectorName);

    final AjaxDropDownChoicePanel<String> version = new AjaxDropDownChoicePanel<String>("version", "version",
            new Model<String>(bundleTO == null ? null : bundleTO.getVersion()));
    version.setStyleSheet("long_dynamicsize");
    version.setChoices(bundleTO == null ? new ArrayList<String>()
            : new ArrayList<String>(mapConnBundleTOs.get(connInstanceTO.getLocation())
                    .get(connInstanceTO.getBundleName()).keySet()));
    version.setRequired(true);
    version.addRequiredLabel();
    version.setEnabled(connInstanceTO.getBundleName() != null);
    version.setOutputMarkupId(true);
    version.addRequiredLabel();
    version.getField().setOutputMarkupId(true);
    connectorForm.add(version);

    final SpinnerFieldPanel<Integer> connRequestTimeout = new SpinnerFieldPanel<Integer>("connRequestTimeout",
            "connRequestTimeout", Integer.class,
            new PropertyModel<Integer>(connInstanceTO, "connRequestTimeout"), 0, null);
    connRequestTimeout.getField().add(new RangeValidator<Integer>(0, Integer.MAX_VALUE));
    connectorForm.add(connRequestTimeout);

    if (connInstanceTO.getPoolConf() == null) {
        connInstanceTO.setPoolConf(new ConnPoolConfTO());
    }
    final SpinnerFieldPanel<Integer> poolMaxObjects = new SpinnerFieldPanel<Integer>("poolMaxObjects",
            "poolMaxObjects", Integer.class,
            new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxObjects"), 0, null);
    poolMaxObjects.getField().add(new RangeValidator<Integer>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMaxObjects);
    final SpinnerFieldPanel<Integer> poolMinIdle = new SpinnerFieldPanel<Integer>("poolMinIdle", "poolMinIdle",
            Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "minIdle"), 0, null);
    poolMinIdle.getField().add(new RangeValidator<Integer>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMinIdle);
    final SpinnerFieldPanel<Integer> poolMaxIdle = new SpinnerFieldPanel<Integer>("poolMaxIdle", "poolMaxIdle",
            Integer.class, new PropertyModel<Integer>(connInstanceTO.getPoolConf(), "maxIdle"), 0, null);
    poolMaxIdle.getField().add(new RangeValidator<Integer>(0, Integer.MAX_VALUE));
    connectorForm.add(poolMaxIdle);
    final SpinnerFieldPanel<Long> poolMaxWait = new SpinnerFieldPanel<Long>("poolMaxWait", "poolMaxWait",
            Long.class, new PropertyModel<Long>(connInstanceTO.getPoolConf(), "maxWait"), 0L, null);
    poolMaxWait.getField().add(new RangeValidator<Long>(0L, Long.MAX_VALUE));
    connectorForm.add(poolMaxWait);
    final SpinnerFieldPanel<Long> poolMinEvictableIdleTime = new SpinnerFieldPanel<Long>(
            "poolMinEvictableIdleTime", "poolMinEvictableIdleTime", Long.class,
            new PropertyModel<Long>(connInstanceTO.getPoolConf(), "minEvictableIdleTimeMillis"), 0L, null);
    poolMinEvictableIdleTime.getField().add(new RangeValidator<Long>(0L, Long.MAX_VALUE));
    connectorForm.add(poolMinEvictableIdleTime);

    // form - first tab - onchange()
    location.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            ((DropDownChoice<String>) location.getField()).setNullValid(false);
            connInstanceTO.setLocation(location.getModelObject());
            target.add(location);

            connectorName.setChoices(
                    new ArrayList<String>(mapConnBundleTOs.get(location.getModelObject()).keySet()));
            connectorName.setEnabled(true);
            connectorName.getField().setModelValue(null);
            target.add(connectorName);

            version.setChoices(new ArrayList<String>());
            version.getField().setModelValue(null);
            version.setEnabled(false);
            target.add(version);

            properties.clear();
            target.add(propertiesContainer);
        }
    });
    connectorName.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            ((DropDownChoice<String>) connectorName.getField()).setNullValid(false);
            connInstanceTO.setBundleName(connectorName.getModelObject());
            target.add(connectorName);

            List<String> versions = new ArrayList<String>(mapConnBundleTOs.get(location.getModelObject())
                    .get(connectorName.getModelObject()).keySet());
            version.setChoices(versions);
            version.setEnabled(true);
            if (versions.size() == 1) {
                selectVersion(target, connInstanceTO, version, versions.get(0));
                version.getField().setModelObject(versions.get(0));
            } else {
                version.getField().setModelValue(null);
                properties.clear();
                target.add(propertiesContainer);
            }
            target.add(version);
        }
    });
    version.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

        private static final long serialVersionUID = -1107858522700306810L;

        @Override
        protected void onUpdate(final AjaxRequestTarget target) {
            selectVersion(target, connInstanceTO, version, version.getModelObject());
        }
    });

    // form - second tab (properties)
    final ListView<ConnConfProperty> connPropView = new AltListView<ConnConfProperty>("connectorProperties",
            new PropertyModel<List<ConnConfProperty>>(this, "properties")) {

        private static final long serialVersionUID = 9101744072914090143L;

        @Override
        @SuppressWarnings({ "unchecked", "rawtypes" })
        protected void populateItem(final ListItem<ConnConfProperty> item) {
            final ConnConfProperty property = item.getModelObject();

            final Label label = new Label("connPropAttrSchema",
                    StringUtils.isBlank(property.getSchema().getDisplayName()) ? property.getSchema().getName()
                            : property.getSchema().getDisplayName());
            item.add(label);

            final FieldPanel field;
            boolean required = false;
            boolean isArray = false;
            if (property.getSchema().isConfidential()
                    || Constants.GUARDED_STRING.equalsIgnoreCase(property.getSchema().getType())
                    || Constants.GUARDED_BYTE_ARRAY.equalsIgnoreCase(property.getSchema().getType())) {

                field = new AjaxPasswordFieldPanel("panel", label.getDefaultModelObjectAsString(),
                        new Model<String>());

                ((PasswordTextField) field.getField()).setResetPassword(false);

                required = property.getSchema().isRequired();
            } else {
                Class<?> propertySchemaClass;

                try {
                    propertySchemaClass = ClassUtils.forName(property.getSchema().getType(),
                            ClassUtils.getDefaultClassLoader());
                    if (ClassUtils.isPrimitiveOrWrapper(propertySchemaClass)) {
                        propertySchemaClass = org.apache.commons.lang3.ClassUtils
                                .primitiveToWrapper(propertySchemaClass);
                    }
                } catch (Exception e) {
                    LOG.error("Error parsing attribute type", e);
                    propertySchemaClass = String.class;
                }
                if (ClassUtils.isAssignable(Number.class, propertySchemaClass)) {
                    field = new SpinnerFieldPanel<Number>("panel", label.getDefaultModelObjectAsString(),
                            (Class<Number>) propertySchemaClass, new Model<Number>(), null, null);

                    required = property.getSchema().isRequired();
                } else if (ClassUtils.isAssignable(Boolean.class, propertySchemaClass)) {
                    field = new AjaxCheckBoxPanel("panel", label.getDefaultModelObjectAsString(),
                            new Model<Boolean>());
                } else {
                    field = new AjaxTextFieldPanel("panel", label.getDefaultModelObjectAsString(),
                            new Model<String>());

                    required = property.getSchema().isRequired();
                }

                if (propertySchemaClass.isArray()) {
                    isArray = true;
                }
            }

            field.setTitle(property.getSchema().getHelpMessage());

            if (required) {
                field.addRequiredLabel();
            }

            if (isArray) {
                if (property.getValues().isEmpty()) {
                    property.getValues().add(null);
                }

                item.add(new MultiFieldPanel<String>("panel",
                        new PropertyModel<List<String>>(property, "values"), field));
            } else {
                field.setNewModel(property.getValues());
                item.add(field);
            }

            final AjaxCheckBoxPanel overridable = new AjaxCheckBoxPanel("connPropAttrOverridable",
                    "connPropAttrOverridable", new PropertyModel<Boolean>(property, "overridable"));

            item.add(overridable);
            connInstanceTO.getConfiguration().add(property);
        }
    };
    connPropView.setOutputMarkupId(true);
    connectorPropForm.add(connPropView);

    final AjaxLink<String> check = new IndicatingAjaxLink<String>("check", new ResourceModel("check")) {

        private static final long serialVersionUID = -7978723352517770644L;

        @Override
        public void onClick(final AjaxRequestTarget target) {
            connInstanceTO.setBundleName(bundleTO.getBundleName());
            connInstanceTO.setVersion(bundleTO.getVersion());
            connInstanceTO.setConnectorName(bundleTO.getConnectorName());

            if (restClient.check(connInstanceTO)) {
                info(getString("success_connection"));
            } else {
                error(getString("error_connection"));
            }

            feedbackPanel.refresh(target);
        }
    };
    connectorPropForm.add(check);

    // form - third tab (capabilities)
    final IModel<List<ConnectorCapability>> capabilities = new LoadableDetachableModel<List<ConnectorCapability>>() {

        private static final long serialVersionUID = 5275935387613157437L;

        @Override
        protected List<ConnectorCapability> load() {
            return Arrays.asList(ConnectorCapability.values());
        }
    };
    CheckBoxMultipleChoice<ConnectorCapability> capabilitiesPalette = new CheckBoxMultipleChoice<ConnectorCapability>(
            "capabilitiesPalette", new PropertyModel<List<ConnectorCapability>>(this, "selectedCapabilities"),
            capabilities);
    connectorForm.add(capabilitiesPalette);

    // form - submit / cancel buttons
    final AjaxButton submit = new IndicatingAjaxButton(APPLY, new Model<String>(getString(SUBMIT))) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            final ConnInstanceTO conn = (ConnInstanceTO) form.getModelObject();

            conn.setConnectorName(bundleTO.getConnectorName());
            conn.setBundleName(bundleTO.getBundleName());
            conn.setVersion(bundleTO.getVersion());
            conn.getConfiguration().clear();
            conn.getConfiguration().addAll(connPropView.getModelObject());

            // Set the model object's capabilities to capabilitiesPalette's converted Set
            conn.getCapabilities()
                    .addAll(selectedCapabilities.isEmpty() ? EnumSet.noneOf(ConnectorCapability.class)
                            : EnumSet.copyOf(selectedCapabilities));

            // Reset pool configuration if all fields are null
            if (conn.getPoolConf() != null && conn.getPoolConf().getMaxIdle() == null
                    && conn.getPoolConf().getMaxObjects() == null && conn.getPoolConf().getMaxWait() == null
                    && conn.getPoolConf().getMinEvictableIdleTimeMillis() == null
                    && conn.getPoolConf().getMinIdle() == null) {

                conn.setPoolConf(null);
            }

            try {
                if (connInstanceTO.getId() == 0) {
                    restClient.create(conn);
                } else {
                    restClient.update(conn);
                }

                ((Resources) pageRef.getPage()).setModalResult(true);
                window.close(target);
            } catch (SyncopeClientException e) {
                error(getString(Constants.ERROR) + ": " + e.getMessage());
                feedbackPanel.refresh(target);
                ((Resources) pageRef.getPage()).setModalResult(false);
                LOG.error("While creating or updating connector {}", conn, e);
            }
        }

        @Override
        protected void onError(final AjaxRequestTarget target, final Form<?> form) {

            feedbackPanel.refresh(target);
        }
    };
    String roles = connInstanceTO.getId() == 0 ? xmlRolesReader.getAllAllowedRoles("Connectors", "create")
            : xmlRolesReader.getAllAllowedRoles("Connectors", "update");
    MetaDataRoleAuthorizationStrategy.authorize(submit, ENABLE, roles);
    connectorForm.add(submit);

    final IndicatingAjaxButton cancel = new IndicatingAjaxButton(CANCEL, new ResourceModel(CANCEL)) {

        private static final long serialVersionUID = -958724007591692537L;

        @Override
        protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
            window.close(target);
        }
    };
    cancel.setDefaultFormProcessing(false);
    connectorForm.add(cancel);
}

From source file:org.dcm4chee.web.war.tc.TCLinksView.java

License:LGPL

public TCLinksView(final String id, IModel<? extends TCObject> model,
        final TCAttributeVisibilityStrategy attrVisibility, final boolean editing) {
    super(id, model);

    this.editing = editing;

    final TCModalDialog removeDlg = TCModalDialog.getOkCancel("remove-link-dialog",
            TCUtilities.getLocalizedString("tc.links.removedialog.msg"), null);
    removeDlg.setInitialHeight(100);//  w w w .j  a v a  2s  .  c  o m
    removeDlg.setInitialWidth(420);
    removeDlg.setUseInitialHeight(true);
    add(removeDlg);

    final WebMarkupContainer links = new WebMarkupContainer("links");
    links.setOutputMarkupId(true);
    links.add(new ListView<TCLink>("link", new ListModel<TCLink>() {
        @Override
        public List<TCLink> getObject() {
            List<TCLink> list = new ArrayList<TCLink>(getTC().getLinks());
            for (Iterator<TCLink> it = list.iterator(); it.hasNext();) {
                TCLink link = it.next();
                if (!link.isPermitted() || link.getLinkedCase() == null) {
                    it.remove();
                }
            }
            return list;
        }
    }) {
        @Override
        protected void populateItem(final ListItem<TCLink> item) {
            final TCLink link = item.getModelObject();
            final TCEditableObject tc = link.getLinkedCase();

            //relationship
            item.add(new Label("link-relationship", link.getLinkRelationship().toString())
                    .add(new AttributeAppender("style", true,
                            new Model<String>(!isShownInDialog() ? "float:right" : ""), ";")));

            //title link
            item.add(new AjaxLink<Void>("link-title-link") {
                @Override
                public boolean isEnabled() {
                    return !editing;
                }

                @Override
                public void onClick(AjaxRequestTarget target) {
                    try {
                        if (!openLinkInDialog(target, link)) {
                            PageParameters params = new PageParameters();
                            params.put("uid", link.getLinkedCaseUID());
                            setResponsePage(new TCCaseViewPage(params));
                        }
                    } catch (Exception e) {
                        log.error("Unable to open teaching-file link!", e);
                    }
                }
            }.add(new Label("link-title", new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    if (!attrVisibility.isAttributeVisible(TCAttribute.Title)) {
                        return TCUtilities.getLocalizedString("tc.case.text") + " "
                                + link.getLinkedCase().getId();
                    }
                    return link.getLinkedCase().getTitle();
                }
            }) {
                @Override
                protected void onComponentTag(ComponentTag tag) {
                    super.onComponentTag(tag);
                    if (!editing) {
                        tag.put("onmouseout", "$(this).siblings('img').hide();");
                        tag.put("onmouseover", "$(this).siblings('img').show();");
                    }
                }
            }).add(new Image("link-follow-image", ImageManager.IMAGE_TC_EYE_MONO)
                    .add(new AttributeAppender("style", true, new Model<String>("display:none"), ";")))
                    .add(new TCToolTipAppender("tc.case.open.text") {
                        @Override
                        public boolean isEnabled(Component c) {
                            return !editing;
                        }
                    }));

            //image link
            item.add(new TCWadoImage("link-image", new Model<TCImageViewImage>() {
                @Override
                public TCImageViewImage getObject() {
                    List<TCReferencedImage> refImages = tc.getReferencedImages();
                    return refImages != null && !refImages.isEmpty() ? refImages.get(0) : null;
                }
            }, TCWadoImageSize.createWidthInstance(64)) {
                @Override
                protected LocalizedImageResource createEmptyImage() {
                    LocalizedImageResource emptyImage = new LocalizedImageResource(this);
                    emptyImage.setResourceReference(ImageManager.IMAGE_TC_IMAGE_SQUARE);
                    return emptyImage;
                }
            });

            //abstract
            item.add(new TCMultiLineLabel("link-abstract", new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    if (!attrVisibility.isAttributeVisible(TCAttribute.Abstract)) {
                        return TCUtilities.getLocalizedString("tc.obfuscation.text");
                    }
                    return link.getLinkedCase().getAbstr();
                }
            }, new AutoClampSettings(40)).setEscapeModelStrings(false));

            //comment
            item.add(new TCMultiLineLabel("link-comment", new AbstractReadOnlyModel<String>() {
                @Override
                public String getObject() {
                    StringBuilder comment = new StringBuilder();
                    comment.append(TCUtilities.getLocalizedString("tc.links.comment.text"));
                    comment.append("&nbsp;");
                    comment.append(link.getLinkComment());
                    return comment.toString();
                }
            }) {
                @Override
                public boolean isVisible() {
                    return link.getLinkComment() != null && !link.getLinkComment().isEmpty();
                }

            }.setEscapeModelStrings(false).setOutputMarkupPlaceholderTag(true));

            //actions
            final WebMarkupContainer actions = new WebMarkupContainer("link-actions");
            actions.setOutputMarkupId(true);
            actions.setOutputMarkupPlaceholderTag(true);
            actions.add(new AjaxLink<Void>("link-remove-btn") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    try {
                        if (editing) {
                            removeDlg.setCallback(new ModalDialogCallbackAdapter() {
                                @Override
                                public void dialogAcknowledged(AjaxRequestTarget target) {
                                    getEditableTC().removeLink(link);
                                    target.addComponent(links);
                                }
                            });

                            removeDlg.show(target);
                        }
                    } catch (Exception e) {
                        log.error("Removing link from teaching-file failed!", e);
                    }
                }

                @Override
                public boolean isVisible() {
                    return editing;
                }
            }.add(new TCHoverImage("link-remove-image", ImageManager.IMAGE_TC_CANCEL_MONO,
                    ImageManager.IMAGE_TC_CANCEL).add(new ImageSizeBehaviour(20, 20, "vertical-align: middle;"))
                            .add(new TooltipBehaviour("tc.links.", "remove"))));

            item.add(new AttributeModifier("onmouseover", true,
                    new Model<String>("$('#" + actions.getMarkupId(true) + "').show();")));
            item.add(new AttributeModifier("onmouseout", true,
                    new Model<String>("$('#" + actions.getMarkupId(true) + "').hide();")));

            item.add(actions);
        }
    });

    add(links);

    final WebMarkupContainer search = new WebMarkupContainer("link-search") {
        @Override
        public boolean isVisible() {
            return editing;
        }
    };

    search.add(new Image("link-search-info-img", ImageManager.IMAGE_TC_INFO) {
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);

            tag.put("title", TCUtilities.getLocalizedString("tc.links.info.text"));
        }
    }.add(new ImageSizeBehaviour(16, 16, "vertical-align:middle;margin:5px;")));

    final ListModel<Instance> searchModel = new ListModel<Instance>(new ArrayList<Instance>());
    final WebMarkupContainer searchResults = new WebMarkupContainer("link-search-case-results");

    // link case search result
    search.add(
            new Label("link-search-case-label", TCUtilities.getLocalizedString("tc.links.search.case.text")));

    // link relationship
    final TCAjaxComboBox<TCLinkRelationship> relationshipCBox = new TCAjaxComboBox<TCLinkRelationship>(
            "link-search-relationship-select", Arrays.asList(TCLinkRelationship.values()),
            TCLinkRelationship.RELATES_TO) {
        private final int MAX_RESULTS = 20;
        final EnumSet<TCLinkRelationship> patientCases = EnumSet.of(TCLinkRelationship.ANTERIOR,
                TCLinkRelationship.POSTERIOR);
        final EnumSet<TCLinkRelationship> searchCases = EnumSet.complementOf(patientCases);

        @Override
        protected TCLinkRelationship convertValue(String value) throws Exception {
            return TCLinkRelationship.valueOfLocalized(value);
        }

        @Override
        protected void valueChanged(TCLinkRelationship value, TCLinkRelationship oldValue,
                AjaxRequestTarget target) {
            boolean changedToSearchCases = patientCases.contains(oldValue) && searchCases.contains(value);
            boolean changedToPatientCases = patientCases.contains(value) && searchCases.contains(oldValue);

            if (changedToSearchCases || changedToPatientCases) {
                if (target != null) {
                    target.addComponent(searchField);
                    target.appendJavascript("$('#" + searchField.getMarkupId(true) + "').textfield();");
                }

                if (changedToPatientCases) {
                    try {
                        TCEditableObject tc = getEditableTC();
                        if (tc == null) {
                            log.warn("Unable to create/add teaching-file link: Teaching-File not editable!");
                        } else {
                            List<Instance> result = Collections.emptyList();
                            TCQueryLocal dao = (TCQueryLocal) JNDIUtils.lookup(TCQueryLocal.JNDI_NAME);

                            List<String> roles = StudyPermissionHelper.get().applyStudyPermissions()
                                    ? StudyPermissionHelper.get().getDicomRoles()
                                    : null;

                            result = dao.findInstancesOfPatient(tc.getPatientId(), tc.getPatientIdIssuer(),
                                    roles, WebCfgDelegate.getInstance().getTCRestrictedSourceAETList());

                            if (result.size() > MAX_RESULTS) {
                                result = result.subList(0, MAX_RESULTS);
                            }

                            String iuid = tc.getInstanceUID();
                            for (Iterator<Instance> it = result.iterator(); it.hasNext();) {
                                if (iuid.equals(it.next().getSOPInstanceUID())) {
                                    it.remove();
                                    break;
                                }
                            }

                            searchModel.setObject(result);

                            if (selectedUID != null) {
                                boolean containsSelectedUID = false;
                                for (Instance i : result) {
                                    if (selectedUID.equals(i.getSOPInstanceUID())) {
                                        containsSelectedUID = true;
                                        break;
                                    }
                                }
                                if (!containsSelectedUID) {
                                    selectedUID = null;
                                }
                            }

                            if (target != null) {
                                target.addComponent(searchResults);
                                target.addComponent(linkBtn);
                                target.appendJavascript("$('#" + linkBtn.getMarkupId(true) + "').button();");
                                target.appendJavascript(
                                        "$('#" + searchResults.getMarkupId(true) + "').menu();");
                            }
                        }
                    } catch (Exception e) {
                        log.error(null, e);
                    }
                }
            }
        }
    };
    search.add(new Label("link-search-relationship-label",
            TCUtilities.getLocalizedString("tc.links.search.relationship.text")));
    search.add(relationshipCBox);

    final ListView<Instance> searchResultsList = new ListView<Instance>("link-search-case-results-list",
            searchModel) {
        @Override
        protected void populateItem(final ListItem<Instance> item) {
            final Instance i = item.getModelObject();
            String title = i.getAttributes(false).getString(Tag.ContentLabel);
            item.setOutputMarkupId(true);
            item.add(new AjaxLink<Void>("link-search-case-results-list-item") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    selectedUID = i.getSOPInstanceUID();

                    String markupId = item.getMarkupId(true);
                    StringBuffer sbuf = new StringBuffer();
                    sbuf.append("$('#").append(markupId)
                            .append("').siblings().removeClass('ui-state-active');");
                    sbuf.append("$('#").append(markupId).append("').removeClass('ui-state-default');");
                    sbuf.append("$('#").append(markupId).append("').addClass('ui-state-active');");

                    target.addComponent(linkBtn);
                    target.appendJavascript(sbuf.toString());
                    target.appendJavascript("$('#" + linkBtn.getMarkupId(true) + "').button();");
                }
            }.add(new Label("link-search-case-results-item-text", title)));

            if (selectedUID != null && selectedUID.equals(i.getSOPInstanceUID())) {
                item.add(new AttributeAppender("class", true, new Model<String>("ui-state-active"), " "));
            }
        }
    };
    searchResultsList.setOutputMarkupId(true);
    searchResults.setOutputMarkupId(true);
    searchResults.add(searchResultsList);

    search.add(searchResults);

    // link case search/input
    search.add((searchField = new SelfUpdatingTextField("link-search-case-input", "") {
        private final int MAX_RESULTS = 50;
        private volatile String currentSearchString = null;
        private TCQueryFilter filter = new TCQueryFilter();
        private IAjaxCallDecorator cursorDecorator = new TCMaskingAjaxDecorator(false, true);

        @Override
        protected Duration getThrottleDelay() {
            return Duration.milliseconds(300);
        }

        @Override
        protected String getUpdateEvent() {
            return "onkeyup";
        }

        @Override
        protected IAjaxCallDecorator getUpdateDecorator() {
            return cursorDecorator;
        }

        @Override
        public boolean isVisible() {
            TCLinkRelationship relationship = relationshipCBox.getModelObject();
            return !TCLinkRelationship.ANTERIOR.equals(relationship)
                    && !TCLinkRelationship.POSTERIOR.equals(relationship);
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);

            tag.put("autocomplete", "off");
            tag.put("placeholder", TCUtilities.getLocalizedString("tc.links.search.hint.text"));
        }

        @Override
        protected void textUpdated(String text, AjaxRequestTarget target) {
            boolean search = false;
            synchronized (this) {
                if (!stringEqualsIgnoreCase(currentSearchString, text)) {
                    currentSearchString = text;
                    search = true;
                }
            }
            if (search) {
                selectedUID = null;

                searchImpl(currentSearchString, target);
            }
        }

        private void searchImpl(final String searchString, AjaxRequestTarget target) {
            try {
                List<Instance> result = Collections.emptyList();
                if (searchString != null && !searchString.isEmpty()) {
                    filter.setTitle(searchString);

                    TCQueryLocal dao = (TCQueryLocal) JNDIUtils.lookup(TCQueryLocal.JNDI_NAME);

                    List<String> roles = StudyPermissionHelper.get().applyStudyPermissions()
                            ? StudyPermissionHelper.get().getDicomRoles()
                            : null;

                    result = dao.findMatchingInstances(filter, roles,
                            WebCfgDelegate.getInstance().getTCRestrictedSourceAETList(), false);
                }

                if (stringEqualsIgnoreCase(currentSearchString, searchString)) {
                    if (result.size() > MAX_RESULTS) {
                        result = result.subList(0, MAX_RESULTS);
                    }

                    String iuid = getEditableTC().getInstanceUID();
                    for (Iterator<Instance> it = result.iterator(); it.hasNext();) {
                        if (iuid.equals(it.next().getSOPInstanceUID())) {
                            it.remove();
                            break;
                        }
                    }

                    searchModel.setObject(result);

                    if (target != null) {
                        target.addComponent(searchResults);
                        target.addComponent(linkBtn);
                        target.appendJavascript("$('#" + linkBtn.getMarkupId(true) + "').button();");
                        target.appendJavascript("$('#" + searchResults.getMarkupId(true) + "').menu();");
                    }
                }
            } catch (Exception e) {
                log.error(null, e);
            }
        }

        private boolean stringEqualsIgnoreCase(String s1, String s2) {
            return s1 == s2 || (s1 != null && s2 != null && s1.equalsIgnoreCase(s2));
        }
    }).setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true));

    // link comment
    final TextArea<String> commentArea = new SelfUpdatingTextArea("link-search-comment-area",
            new Model<String>());
    search.add(new Label("link-search-comment-label", TCUtilities.getLocalizedString("tc.links.comment.text")));
    search.add(commentArea);

    // link button
    search.add(linkBtn = new AjaxLink<Void>("link-link-btn") {
        @Override
        public boolean isEnabled() {
            return selectedUID != null && relationshipCBox.getModelObject() != null;
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            try {
                if (selectedUID == null) {
                    log.warn("Unable to create/add teaching-file link: No case selected!");
                } else if (relationshipCBox.getModelObject() == null) {
                    log.warn("Unable to create/add teaching-file link: No link relationship selected!");
                } else {
                    TCEditableObject tc = getEditableTC();
                    if (tc == null) {
                        log.warn("Unable to create/add teaching-file link: Teaching-File not editable!");
                    } else {
                        tc.addLink(new TCLink(tc.getInstanceUID(), selectedUID,
                                relationshipCBox.getModelObject(), commentArea.getModelObject()));
                    }
                }
            } catch (Exception e) {
                log.error("Unable to create/add teaching-file link!", e);
            } finally {
                target.addComponent(links);
            }
        }

        @Override
        protected IAjaxCallDecorator getAjaxCallDecorator() {
            return new TCMaskingAjaxDecorator(false, true);
        }
    }.add(new Label("link-link-btn-text", TCUtilities.getLocalizedString("tc.links.link.text")))
            .setOutputMarkupId(true));

    add(search);

    add(new HeaderContributor(new IHeaderContributor() {
        public void renderHead(IHeaderResponse response) {
            response.renderOnDomReadyJavascript("$('#" + searchResults.getMarkupId(true) + "').menu();");
        }
    }));
}

From source file:org.dcm4chee.web.war.tc.TCViewOverviewTab.java

License:LGPL

@SuppressWarnings("serial")
public TCViewOverviewTab(final String id, IModel<TCEditableObject> model,
        TCAttributeVisibilityStrategy attrVisibilityStrategy) {
    super(id, model, attrVisibilityStrategy);

    tcId = getTC().getId();/* www .j a v a 2 s  . co  m*/

    AttributeModifier readonlyModifier = new AttributeAppender("readonly", true, new Model<String>("readonly"),
            " ") {
        @Override
        public boolean isEnabled(Component component) {
            return !isEditing();
        }
    };

    // TITLE
    final WebMarkupContainer titleRow = new WebMarkupContainer("tc-view-overview-title-row");
    titleRow.add(new Label("tc-view-overview-title-label", new InternalStringResourceModel("tc.title.text")));
    titleRow.add(new SelfUpdatingTextField("tc-view-overview-title-text", new Model<String>() {
        @Override
        public String getObject() {
            if (!getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Title)) {
                return TCUtilities.getLocalizedString("tc.case.text") + " " + getTC().getId();
            }
            return getStringValue(TCQueryFilterKey.Title);
        }

        @Override
        public void setObject(String text) {
            if (isEditing()) {
                getTC().setTitle(text);
            }
        }
    }).add(readonlyModifier));

    // ABSTRACT
    final WebMarkupContainer abstractRow = new WebMarkupContainer("tc-view-overview-abstract-row");
    abstractRow.add(
            new Label("tc-view-overview-abstract-label", new InternalStringResourceModel("tc.abstract.text")));
    abstractRow.add(new SelfUpdatingTextArea("tc-view-overview-abstract-area", new Model<String>() {
        @Override
        public String getObject() {
            if (!getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Abstract)) {
                return TCUtilities.getLocalizedString("tc.obfuscation.text");
            }
            return getStringValue(TCQueryFilterKey.Abstract);
        }

        @Override
        public void setObject(String text) {
            if (isEditing()) {
                getTC().setAbstract(text);
            }
        }
    }).add(readonlyModifier).setOutputMarkupId(true).setMarkupId("tc-view-overview-abstract-area"));

    // URL
    final WebMarkupContainer urlRow = new WebMarkupContainer("tc-view-overview-url-row");
    urlRow.add(new WebMarkupContainer("tc-view-overview-url-label")
            .add(new ExternalLink("tc-view-url-link", getTC().getURL())
                    .add(new Label("tc-view-url-link-title", new InternalStringResourceModel("tc.url.text")))
                    .add(new Image("tc-view-url-link-follow-image", ImageManager.IMAGE_TC_EXTERNAL))
                    .add(new TCToolTipAppender("tc.case.url.text"))));
    urlRow.add(new TextArea<String>("tc-view-overview-url-text", new Model<String>() {
        @Override
        public String getObject() {
            TCObject tc = getTC();
            return tc != null ? tc.getURL() : null;
        }
    }).add(new AttributeAppender("readonly", true, new Model<String>("readonly"), " ")));

    // AUTHOR NAME
    final WebMarkupContainer authorNameRow = new WebMarkupContainer("tc-view-overview-authorname-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.AuthorName);
        }
    };
    authorNameRow.add(new Label("tc-view-overview-authorname-label",
            new InternalStringResourceModel("tc.author.name.text")));
    authorNameRow.add(new SelfUpdatingTextField("tc-view-overview-authorname-text", new Model<String>() {
        @Override
        public String getObject() {
            if (!getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.AuthorName)) {
                return TCUtilities.getLocalizedString("tc.obfuscation.text");
            }
            return getStringValue(TCQueryFilterKey.AuthorName);
        }

        @Override
        public void setObject(String text) {
            if (isEditing()) {
                getTC().setAuthorName(text);
            }
        }
    }).add(readonlyModifier));

    // AUTHOR AFFILIATION
    final WebMarkupContainer authorAffiliationRow = new WebMarkupContainer(
            "tc-view-overview-authoraffiliation-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.AuthorAffiliation);
        }
    };
    authorAffiliationRow.add(new Label("tc-view-overview-authoraffiliation-label",
            new InternalStringResourceModel("tc.author.affiliation.text")));
    authorAffiliationRow
            .add(new SelfUpdatingTextField("tc-view-overview-authoraffiliation-text", new Model<String>() {
                @Override
                public String getObject() {
                    if (!getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.AuthorAffiliation)) {
                        return TCUtilities.getLocalizedString("tc.obfuscation.text");
                    }
                    return getStringValue(TCQueryFilterKey.AuthorAffiliation);
                }

                @Override
                public void setObject(String text) {
                    if (isEditing()) {
                        getTC().setAuthorAffiliation(text);
                    }
                }
            }).add(readonlyModifier));

    // AUTHOR CONTACT
    final WebMarkupContainer authorContactRow = new WebMarkupContainer("tc-view-overview-authorcontact-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.AuthorContact);
        }
    };
    authorContactRow.add(new Label("tc-view-overview-authorcontact-label",
            new InternalStringResourceModel("tc.author.contact.text")));
    authorContactRow.add(new SelfUpdatingTextArea("tc-view-overview-authorcontact-area", new Model<String>() {
        @Override
        public String getObject() {
            if (!getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.AuthorContact)) {
                return TCUtilities.getLocalizedString("tc.obfuscation.text");
            }
            return getStringValue(TCQueryFilterKey.AuthorContact);
        }

        @Override
        public void setObject(String text) {
            if (isEditing()) {
                getTC().setAuthorContact(text);
            }
        }
    }).add(readonlyModifier));

    // KEYWORDS
    final boolean keywordCodeInput = isEditing()
            && TCKeywordCatalogueProvider.getInstance().hasCatalogue(TCQueryFilterKey.Keyword);
    final KeywordsListModel keywordsModel = new KeywordsListModel();
    final WebMarkupContainer keywordCodesContainer = new WebMarkupContainer(
            "tc-view-overview-keyword-input-container");
    final ListView<ITextOrCode> keywordCodesView = new ListView<ITextOrCode>(
            "tc-view-overview-keyword-input-view", keywordsModel) {
        @Override
        protected void populateItem(final ListItem<ITextOrCode> item) {
            final int index = item.getIndex();

            AjaxLink<String> addBtn = new AjaxLink<String>("tc-view-overview-keyword-input-add") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    keywordsModel.addKeyword();
                    target.addComponent(keywordCodesContainer);
                }
            };
            addBtn.add(new Image("tc-view-overview-keyword-input-add-img", ImageManager.IMAGE_COMMON_ADD)
                    .add(new ImageSizeBehaviour("vertical-align: middle;")));
            addBtn.add(new TooltipBehaviour("tc.view.overview.keyword.", "add"));
            addBtn.setOutputMarkupId(true);
            addBtn.setVisible(index == 0);

            AjaxLink<String> removeBtn = new AjaxLink<String>("tc-view-overview-keyword-input-remove") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    keywordsModel.removeKeyword(item.getModelObject());
                    target.addComponent(keywordCodesContainer);
                }
            };
            removeBtn.add(new Image("tc-view-overview-keyword-input-remove-img", ImageManager.IMAGE_TC_CANCEL)
                    .add(new ImageSizeBehaviour("vertical-align: middle;")));
            removeBtn.add(new TooltipBehaviour("tc.view.overview.keyword.", "remove"));
            removeBtn.setOutputMarkupId(true);
            removeBtn.setVisible(index > 0);

            TCInput keywordInput = TCUtilities.createInput("tc-view-overview-keyword-input",
                    TCQueryFilterKey.Keyword, item.getModelObject(), false);
            keywordInput.addChangeListener(new ValueChangeListener() {
                @Override
                public void valueChanged(ITextOrCode[] values) {
                    keywordsModel.setKeywordAt(index, values != null && values.length > 0 ? values[0] : null);
                }
            });

            item.setOutputMarkupId(true);
            item.add(keywordInput.getComponent());
            item.add(addBtn);
            item.add(removeBtn);

            if (index > 0) {
                item.add(new AttributeModifier("style", true,
                        new Model<String>("border-top: 4px solid transparent")) {
                    @Override
                    protected String newValue(String currentValue, String newValue) {
                        if (currentValue == null) {
                            return newValue;
                        } else if (newValue == null) {
                            return currentValue;
                        } else {
                            return currentValue + ";" + newValue;
                        }
                    }
                });
            }
        }
    };
    keywordCodesView.setOutputMarkupId(true);
    keywordCodesContainer.setOutputMarkupId(true);
    keywordCodesContainer.setVisible(isEditing());
    keywordCodesContainer.add(keywordCodesView);
    final WebMarkupContainer keywordRow = new WebMarkupContainer("tc-view-overview-keyword-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Keyword);
        }
    };
    keywordRow.add(
            new Label("tc-view-overview-keyword-label", new InternalStringResourceModel("tc.keyword.text")));
    keywordRow.add(keywordCodesContainer);
    keywordRow.add(new SelfUpdatingTextArea("tc-view-overview-keyword-area", new Model<String>() {
        @Override
        public String getObject() {
            if (!getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Keyword)) {
                return TCUtilities.getLocalizedString("tc.obfuscation.text");
            }
            return getShortStringValue(TCQueryFilterKey.Keyword);
        }

        @Override
        public void setObject(String text) {
            if (isEditing()) {
                String[] strings = text != null ? text.trim().split(";") : null;
                List<ITextOrCode> keywords = null;

                if (strings != null && strings.length > 0) {
                    keywords = new ArrayList<ITextOrCode>(strings.length);
                    for (String s : strings) {
                        keywords.add(TextOrCode.text(s));
                    }
                }

                getTC().setKeywords(keywords);
            }
        }
    }) {
        @Override
        public boolean isVisible() {
            return !keywordCodeInput;
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            tag.put("title", getStringValue(TCQueryFilterKey.Keyword)); //$NON-NLS-1$
        }
    }.add(readonlyModifier).setOutputMarkupId(true).setMarkupId("tc-view-overview-keyword-area"));

    // ANATOMY
    anatomyInput = TCUtilities.createInput("tc-view-overview-anatomy-input", TCQueryFilterKey.Anatomy,
            getTC().getValue(TCQueryFilterKey.Anatomy), true);
    anatomyInput.getComponent().setVisible(isEditing());
    anatomyInput.addChangeListener(new ValueChangeListener() {
        @Override
        public void valueChanged(ITextOrCode[] values) {
            getTC().setAnatomy(values != null && values.length > 0 ? values[0] : null);
        }
    });
    final WebMarkupContainer anatomyRow = new WebMarkupContainer("tc-view-overview-anatomy-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Anatomy);
        }
    };
    anatomyRow.add(
            new Label("tc-view-overview-anatomy-label", new InternalStringResourceModel("tc.anatomy.text")));
    anatomyRow.add(anatomyInput.getComponent());
    anatomyRow.add(new TextField<String>("tc-view-overview-anatomy-value-label", new Model<String>() {
        public String getObject() {
            return getShortStringValue(TCQueryFilterKey.Anatomy);
        }
    }) {
        private static final long serialVersionUID = 3465370488528419531L;

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            tag.put("title", getStringValue(TCQueryFilterKey.Anatomy)); //$NON-NLS-1$
        }

        @Override
        public boolean isVisible() {
            return !isEditing();
        }
    }.add(readonlyModifier));

    // PATHOLOGY
    pathologyInput = TCUtilities.createInput("tc-view-overview-pathology-input", TCQueryFilterKey.Pathology,
            getTC().getValue(TCQueryFilterKey.Pathology), true);
    pathologyInput.getComponent().setVisible(isEditing());
    pathologyInput.addChangeListener(new ValueChangeListener() {
        @Override
        public void valueChanged(ITextOrCode[] values) {
            getTC().setPathology(values != null && values.length > 0 ? values[0] : null);
        }
    });
    final WebMarkupContainer pathologyRow = new WebMarkupContainer("tc-view-overview-pathology-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Pathology);
        }
    };
    pathologyRow.add(new Label("tc-view-overview-pathology-label",
            new InternalStringResourceModel("tc.pathology.text")));
    pathologyRow.add(pathologyInput.getComponent());
    pathologyRow.add(new TextField<String>("tc-view-overview-pathology-value-label", new Model<String>() {
        public String getObject() {
            return getShortStringValue(TCQueryFilterKey.Pathology);
        }
    }) {
        private static final long serialVersionUID = 3465370488528419531L;

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            tag.put("title", getStringValue(TCQueryFilterKey.Pathology)); //$NON-NLS-1$
        }

        @Override
        public boolean isVisible() {
            return !isEditing();
        }
    }.add(readonlyModifier));

    // CATEGORY
    final TCComboBox<TCQueryFilterValue.Category> categoryCBox = TCUtilities
            .createEnumComboBox("tc-view-overview-category-select", new Model<Category>() {
                @Override
                public Category getObject() {
                    return getTC().getCategory();
                }

                @Override
                public void setObject(Category value) {
                    getTC().setCategory(value);
                }
            }, Arrays.asList(TCQueryFilterValue.Category.values()), true, "tc.category",
                    NullDropDownItem.Undefined, null);
    final WebMarkupContainer categoryRow = new WebMarkupContainer("tc-view-overview-category-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Category);
        }
    };
    categoryCBox.setVisible(isEditing());
    categoryRow.add(
            new Label("tc-view-overview-category-label", new InternalStringResourceModel("tc.category.text")));
    categoryRow.add(categoryCBox);
    categoryRow.add(new TextField<String>("tc-view-overview-category-value-label", new Model<String>() {
        @Override
        public String getObject() {
            return getStringValue(TCQueryFilterKey.Category);
        }
    }).add(readonlyModifier).setVisible(!isEditing()));

    // LEVEL
    final TCComboBox<TCQueryFilterValue.Level> levelCBox = TCUtilities
            .createEnumComboBox("tc-view-overview-level-select", new Model<Level>() {
                @Override
                public Level getObject() {
                    return getTC().getLevel();
                }

                @Override
                public void setObject(Level level) {
                    getTC().setLevel(level);
                }
            }, Arrays.asList(TCQueryFilterValue.Level.values()), true, "tc.level", NullDropDownItem.Undefined,
                    null);
    final WebMarkupContainer levelRow = new WebMarkupContainer("tc-view-overview-level-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Level);
        }
    };
    levelCBox.setVisible(isEditing());
    levelRow.add(new Label("tc-view-overview-level-label", new InternalStringResourceModel("tc.level.text")));
    levelRow.add(new TextField<String>("tc-view-overview-level-value-label", new Model<String>() {
        @Override
        public String getObject() {
            return getStringValue(TCQueryFilterKey.Level);
        }
    }).add(readonlyModifier).setVisible(!isEditing()));
    levelRow.add(levelCBox);

    // PATIENT SEX
    final TCComboBox<TCQueryFilterValue.PatientSex> patientSexCBox = TCUtilities
            .createEnumComboBox("tc-view-overview-patientsex-select", new Model<PatientSex>() {
                @Override
                public PatientSex getObject() {
                    return getTC().getPatientSex();
                }

                @Override
                public void setObject(PatientSex value) {
                    getTC().setPatientSex(value);
                }
            }, Arrays.asList(TCQueryFilterValue.PatientSex.values()), true, "tc.patientsex",
                    NullDropDownItem.Undefined, null);
    final WebMarkupContainer patientSexRow = new WebMarkupContainer("tc-view-overview-patientsex-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.PatientSex);
        }
    };
    patientSexCBox.setVisible(isEditing());
    patientSexRow.add(new Label("tc-view-overview-patientsex-label",
            new InternalStringResourceModel("tc.patient.sex.text")));
    patientSexRow.add(new TextField<String>("tc-view-overview-patientsex-value-label", new Model<String>() {
        public String getObject() {
            return getStringValue(TCQueryFilterKey.PatientSex);
        }
    }).add(readonlyModifier).setVisible(!isEditing()));
    patientSexRow.add(patientSexCBox);

    // PATIENT AGE
    final TCSpinner<Integer> patientAgeYearSpinner = TCSpinner
            .createYearSpinner("tc-view-overview-patientage-years-input", new Model<Integer>() {
                @Override
                public Integer getObject() {
                    return TCPatientAgeUtilities.toYears(getTC().getPatientAge());
                }

                @Override
                public void setObject(Integer years) {
                    getTC().setPatientAge(TCPatientAgeUtilities.toDays(years,
                            TCPatientAgeUtilities.toRemainingMonths(getTC().getPatientAge())));
                }
            }, null);
    final TCSpinner<Integer> patientAgeMonthSpinner = TCSpinner
            .createMonthSpinner("tc-view-overview-patientage-months-input", new Model<Integer>() {
                @Override
                public Integer getObject() {
                    return TCPatientAgeUtilities.toRemainingMonths(getTC().getPatientAge());
                }

                @Override
                public void setObject(Integer months) {
                    getTC().setPatientAge(TCPatientAgeUtilities
                            .toDays(TCPatientAgeUtilities.toYears(getTC().getPatientAge()), months));
                }
            }, null);
    final WebMarkupContainer patientAgeRow = new WebMarkupContainer("tc-view-overview-patientage-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.PatientAge);
        }
    };
    patientAgeYearSpinner.setVisible(isEditing());
    patientAgeMonthSpinner.setVisible(isEditing());
    patientAgeRow.add(new Label("tc-view-overview-patientage-label",
            new InternalStringResourceModel("tc.patient.age.text")));
    patientAgeRow.add(new TextField<String>("tc-view-overview-patientage-value-label", new Model<String>() {
        public String getObject() {
            return TCPatientAgeUtilities.format(getTC().getPatientAge());
        }
    }).add(readonlyModifier).setVisible(!isEditing()));
    patientAgeRow.add(patientAgeYearSpinner);
    patientAgeRow.add(patientAgeMonthSpinner);

    // PATIENT SPECIES
    List<String> ethnicGroups = WebCfgDelegate.getInstance().getTCEthnicGroups();
    boolean ethnicGroupsAvailable = ethnicGroups != null && !ethnicGroups.isEmpty();
    SelfUpdatingTextField patientSpeciesField = new SelfUpdatingTextField(
            "tc-view-overview-patientrace-value-label", new Model<String>() {
                @Override
                public String getObject() {
                    return getStringValue(TCQueryFilterKey.PatientSpecies);
                }

                @Override
                public void setObject(String text) {
                    if (isEditing()) {
                        getTC().setPatientSpecies(text);
                    }
                }
            });
    final WebMarkupContainer patientSpeciesRow = new WebMarkupContainer("tc-view-overview-patientrace-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.PatientSpecies);
        }
    };
    patientSpeciesRow.add(new Label("tc-view-overview-patientrace-label",
            new InternalStringResourceModel("tc.patient.species.text")));
    patientSpeciesRow.add(patientSpeciesField);
    patientSpeciesRow
            .add(TCUtilities.createEditableComboBox("tc-view-overview-patientrace-select", new Model<String>() {
                @Override
                public String getObject() {
                    return getTC().getValueAsLocalizedString(TCQueryFilterKey.PatientSpecies,
                            TCViewOverviewTab.this);
                }

                @Override
                public void setObject(String value) {
                    getTC().setValue(TCQueryFilterKey.PatientSpecies, value);
                }
            }, ethnicGroups, NullDropDownItem.Undefined, null).add(readonlyModifier)
                    .setVisible(isEditing() && ethnicGroupsAvailable));

    patientSpeciesField.setVisible(!isEditing() || !ethnicGroupsAvailable);
    if (!isEditing()) {
        patientSpeciesField.add(readonlyModifier);
    }

    // MODALITIES
    final WebMarkupContainer modalitiesRow = new WebMarkupContainer("tc-view-overview-modalities-row") {
        @Override
        public boolean isVisible() {
            return getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.AcquisitionModality);
        }
    };
    modalitiesRow.add(new Label("tc-view-overview-modalities-label",
            new InternalStringResourceModel("tc.modalities.text")));
    modalitiesRow.add(new SelfUpdatingTextField("tc-view-overview-modalities-text", new Model<String>() {
        @Override
        public String getObject() {
            return getStringValue(TCQueryFilterKey.AcquisitionModality);
        }

        @Override
        public void setObject(String value) {
            if (isEditing()) {
                String[] modalities = value != null ? value.trim().split(";") : null;
                getTC().setValue(TCQueryFilterKey.AcquisitionModality,
                        modalities != null ? Arrays.asList(modalities) : null);
            }
        }
    }).add(readonlyModifier));

    // FINDING
    findingInput = TCUtilities.createInput("tc-view-overview-finding-input", TCQueryFilterKey.Finding,
            getTC().getValue(TCQueryFilterKey.Finding), true);
    findingInput.getComponent().setVisible(isEditing());
    findingInput.addChangeListener(new ValueChangeListener() {
        @Override
        public void valueChanged(ITextOrCode[] values) {
            getTC().setFinding(values != null && values.length > 0 ? values[0] : null);
        }
    });
    final WebMarkupContainer findingRow = new WebMarkupContainer("tc-view-overview-finding-row") {
        @Override
        public boolean isVisible() {
            return TCKeywordCatalogueProvider.getInstance().hasCatalogue(TCQueryFilterKey.Finding)
                    && getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Finding);
        }
    };
    findingRow.add(
            new Label("tc-view-overview-finding-label", new InternalStringResourceModel("tc.finding.text")));
    findingRow.add(findingInput.getComponent());
    findingRow.add(new TextField<String>("tc-view-overview-finding-value-label", new Model<String>() {
        @Override
        public String getObject() {
            return getShortStringValue(TCQueryFilterKey.Finding);
        }
    }) {
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            tag.put("title", getStringValue(TCQueryFilterKey.Finding)); //$NON-NLS-1$
        }

        @Override
        public boolean isVisible() {
            return !isEditing();
        }
    });

    // DIAGNOSIS
    diagnosisInput = TCUtilities.createInput("tc-view-overview-diag-input", TCQueryFilterKey.Diagnosis,
            getTC().getValue(TCQueryFilterKey.Diagnosis), true);
    diagnosisInput.getComponent().setVisible(isEditing());
    diagnosisInput.addChangeListener(new ValueChangeListener() {
        @Override
        public void valueChanged(ITextOrCode[] values) {
            getTC().setDiagnosis(values != null && values.length > 0 ? values[0] : null);
        }
    });
    final WebMarkupContainer diagRow = new WebMarkupContainer("tc-view-overview-diag-row") {
        @Override
        public boolean isVisible() {
            return TCKeywordCatalogueProvider.getInstance().hasCatalogue(TCQueryFilterKey.Diagnosis)
                    && getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Diagnosis);
        }
    };
    diagRow.add(new Label("tc-view-overview-diag-label", new InternalStringResourceModel("tc.diagnosis.text")));
    diagRow.add(diagnosisInput.getComponent());
    diagRow.add(new TextField<String>("tc-view-overview-diag-value-label", new Model<String>() {
        @Override
        public String getObject() {
            return getShortStringValue(TCQueryFilterKey.Diagnosis);
        }
    }) {
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            tag.put("title", getStringValue(TCQueryFilterKey.Diagnosis)); //$NON-NLS-1$
        }

        @Override
        public boolean isVisible() {
            return !isEditing();
        }
    });

    // DIAGNOSIS CONFIRMED
    final WebMarkupContainer diagConfirmedRow = new WebMarkupContainer("tc-view-overview-diagconfirmed-row") {
        @Override
        public boolean isVisible() {
            return TCKeywordCatalogueProvider.getInstance().hasCatalogue(TCQueryFilterKey.Diagnosis)
                    && getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.Diagnosis);
        }
    };
    diagConfirmedRow.add(new Label("tc-view-overview-diagconfirmed-label",
            new InternalStringResourceModel("tc.diagnosis.confirmed.text")));
    diagConfirmedRow.add(new CheckBox("tc-view-overview-diagconfirmed-input", new Model<Boolean>() {
        @Override
        public Boolean getObject() {
            YesNo yesno = getTC().getDiagnosisConfirmed();
            if (yesno != null && YesNo.Yes.equals(yesno)) {
                return true;
            } else {
                return false;
            }
        }

        @Override
        public void setObject(Boolean value) {
            if (value != null && value == true) {
                getTC().setDiagnosisConfirmed(YesNo.Yes);
            } else {
                getTC().setDiagnosisConfirmed(null);
            }
        }
    }).setEnabled(isEditing()));

    // DIFFERENTIAL DIAGNOSIS
    diffDiagnosisInput = TCUtilities.createInput("tc-view-overview-diffdiag-input",
            TCQueryFilterKey.DifferentialDiagnosis, getTC().getValue(TCQueryFilterKey.DifferentialDiagnosis),
            true);
    diffDiagnosisInput.getComponent().setVisible(isEditing());
    diffDiagnosisInput.addChangeListener(new ValueChangeListener() {
        @Override
        public void valueChanged(ITextOrCode[] values) {
            getTC().setDiffDiagnosis(values != null && values.length > 0 ? values[0] : null);
        }
    });
    final WebMarkupContainer diffDiagRow = new WebMarkupContainer("tc-view-overview-diffdiag-row") {
        @Override
        public boolean isVisible() {
            return TCKeywordCatalogueProvider.getInstance().hasCatalogue(TCQueryFilterKey.DifferentialDiagnosis)
                    && getAttributeVisibilityStrategy().isAttributeVisible(TCAttribute.DifferentialDiagnosis);
        }
    };
    diffDiagRow.add(new Label("tc-view-overview-diffdiag-label",
            new InternalStringResourceModel("tc.diffdiagnosis.text")));
    diffDiagRow.add(diffDiagnosisInput.getComponent());
    diffDiagRow.add(new TextField<String>("tc-view-overview-diffdiag-value-label", new Model<String>() {
        @Override
        public String getObject() {
            return getShortStringValue(TCQueryFilterKey.DifferentialDiagnosis);
        }
    }) {
        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            tag.put("title", getStringValue(TCQueryFilterKey.DifferentialDiagnosis)); //$NON-NLS-1$
        }

        @Override
        public boolean isVisible() {
            return !isEditing();
        }
    });

    // IMAGE COUNT
    final WebMarkupContainer imageCountRow = new WebMarkupContainer("tc-view-overview-imagecount-row");
    imageCountRow.add(new Label("tc-view-overview-imagecount-label",
            new InternalStringResourceModel("tc.view.images.count.text")));
    imageCountRow.add(new TextField<String>("tc-view-overview-imagecount-value-label", new Model<String>() {
        public String getObject() {
            return getTC().getReferencedImages() != null
                    ? Integer.toString(getTC().getReferencedImages().size())
                    : "0";
        }
    }).add(new AttributeAppender("readonly", true, new Model<String>("readonly"), " ")));

    add(titleRow);
    add(abstractRow);
    add(urlRow);
    add(authorNameRow);
    add(authorAffiliationRow);
    add(authorContactRow);
    add(keywordRow);
    add(anatomyRow);
    add(pathologyRow);
    add(findingRow);
    add(diffDiagRow);
    add(diagRow);
    add(diagConfirmedRow);
    add(categoryRow);
    add(levelRow);
    add(patientSexRow);
    add(patientAgeRow);
    add(patientSpeciesRow);
    add(modalitiesRow);
    add(imageCountRow);
}

From source file:org.devproof.portal.core.module.mount.panel.MountInputPanel.java

License:Apache License

private ListView<MountPoint> createMountUrlListView() {
    ListView<MountPoint> listView = newMountUrlListView();
    listView.setOutputMarkupId(true);
    listView.setReuseItems(true);//from   www.  ja  va 2 s.  c  o  m
    return listView;
}

From source file:org.geoserver.qos.web.OperatingInfoModalPanel.java

License:Open Source License

public OperatingInfoModalPanel(String id, IModel<OperatingInfo> model) {
    super(id, model);

    final WebMarkupContainer form = new WebMarkupContainer("opInfoForm");
    form.setOutputMarkupId(true);/*from  ww w .j  a  v  a  2s  . c  o m*/
    add(form);

    // pre init non nullable objects
    if (model.getObject().getOperationalStatus() == null)
        model.getObject().setOperationalStatus(new ReferenceType());
    if (model.getObject().getByDaysOfWeek() == null)
        model.getObject().setByDaysOfWeek(new ArrayList<>());

    final DropDownChoice<String> titleSelect = new DropDownChoice<String>("titleSelect",
            new PropertyModel<String>(model, "operationalStatus.href"),
            QosData.instance().getOperationalStatusList(), new ChoiceRenderer<String>() {
                @Override
                public Object getDisplayValue(String object) {
                    if (object == null)
                        return null;
                    return object.split("#")[1];
                }

                @Override
                public String getIdValue(String object, int index) {
                    return object;
                }
            }) {
        @Override
        protected void onSelectionChanged(String newSelection) {
            super.onSelectionChanged(newSelection);
        }
    };
    form.add(titleSelect);

    final TextField<String> titleInput = new TextField<String>("titleInput",
            new PropertyModel<>(model, "operationalStatus.title"));
    // titleInput.setRequired(true);
    form.add(titleInput);

    timeListContainer = new WebMarkupContainer("timeListContainer");
    timeListContainer.setOutputMarkupId(true);
    form.add(timeListContainer);

    // ModalWindow timeModal
    timeModal = new ModalWindow("timeModal");
    add(timeModal);

    final ListView<OperatingInfoTime> timeListView = new ListView<OperatingInfoTime>("timeList",
            model.getObject().getByDaysOfWeek()) {
        @Override
        protected void populateItem(ListItem<OperatingInfoTime> item) {
            OperatingInfoTimeModalPanel timePanel = new OperatingInfoTimeModalPanel("timePanel",
                    item.getModel());
            // set on delete callback
            timePanel.setOnDelete(x -> {
                model.getObject().getByDaysOfWeek().remove(x.getModel());
                x.getTarget().add(timeListContainer);
            });
            item.add(timePanel);
        }
    };
    timeListView.setOutputMarkupId(true);
    timeListContainer.add(timeListView);

    final AjaxButton addTimeLink = new AjaxButton("addTime") {
    };
    timeListContainer.add(addTimeLink);
    addTimeLink.add(new AjaxFormSubmitBehavior("click") {
        @Override
        protected void onAfterSubmit(final AjaxRequestTarget target) {
            model.getObject().getByDaysOfWeek().add(new OperatingInfoTime());
            target.add(timeListContainer);
        }
    });

    final AjaxSubmitLink deleteLink = new AjaxSubmitLink("deleteLink") {
        @Override
        public void onAfterSubmit(AjaxRequestTarget target, Form<?> form) {
            delete(target);
        }
    };
    form.add(deleteLink);
}

From source file:org.geoserver.qos.web.QosAdminPanel.java

License:Open Source License

protected void initCommonComponents() {
    /** CheckBox activatedCheck */
    final CheckBox activatedCheck = new CheckBox("createExtendedCapabilities",
            new PropertyModel<Boolean>(config, "activated"));
    add(activatedCheck);//from   ww w .j  av  a2 s. com

    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);
    add(container);

    configs = new WebMarkupContainer("configs");
    configs.setOutputMarkupId(true);
    configs.setVisible(activatedCheck.getModelObject());
    container.add(configs);

    activatedCheck.add(new OnChangeAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            configs.setVisible(activatedCheck.getModelObject());
            target.add(container);
        }
    });

    if (config.getWmsQosMetadata() == null)
        config.setWmsQosMetadata(new QosMainMetadata());
    if (config.getWmsQosMetadata().getOperatingInfo() == null)
        config.getWmsQosMetadata().setOperatingInfo(new ArrayList<>());
    final ListView<OperatingInfo> opInfoListView = new ListView<OperatingInfo>("opInfoListView",
            config.getWmsQosMetadata().getOperatingInfo()) {
        @Override
        protected void populateItem(ListItem<OperatingInfo> item) {
            OperatingInfoModalPanel opPanel = new OperatingInfoModalPanel("opinfo", item.getModel());
            // onDelete
            opPanel.setOnDelete(x -> {
                config.getWmsQosMetadata().getOperatingInfo().remove(x.getModel());
                x.getTarget().add(configs);
            });
            item.add(opPanel);
        }
    };
    opInfoListView.setOutputMarkupId(true);
    configs.add(opInfoListView);

    final AjaxButton addOpInfoButton = new AjaxButton("addOpInfo") {
    };
    configs.add(addOpInfoButton);
    addOpInfoButton.add(new AjaxFormSubmitBehavior("click") {
        @Override
        protected void onAfterSubmit(final AjaxRequestTarget target) {
            config.getWmsQosMetadata().getOperatingInfo().add(new OperatingInfo());
            target.add(configs);
        }
    });

    //
    if (config.getWmsQosMetadata().getOperationAnomalyFeed() == null) {
        config.getWmsQosMetadata().setOperationAnomalyFeed(new ArrayList<>());
    }
    final WebMarkupContainer anomalyDiv = new WebMarkupContainer("anomalyDiv");
    anomalyDiv.setOutputMarkupId(true);
    configs.add(anomalyDiv);

    final ListView<ReferenceType> anomalyListView = new ListView<ReferenceType>("anomalyListView",
            config.getWmsQosMetadata().getOperationAnomalyFeed()) {
        @Override
        protected void populateItem(ListItem<ReferenceType> item) {
            OperationAnomalyFeedPanel anomalyPanel = new OperationAnomalyFeedPanel("anomalyPanel",
                    item.getModel());
            // onDelete
            anomalyPanel.setOnDelete(x -> {
                config.getWmsQosMetadata().getOperationAnomalyFeed().remove(x.getModel());
                x.getTarget().add(anomalyDiv);
            });
            item.add(anomalyPanel);
        }
    };
    anomalyDiv.add(anomalyListView);

    final AjaxButton anomalyButton = new AjaxButton("addAnomaly") {
    };
    anomalyDiv.add(anomalyButton);
    anomalyButton.add(new AjaxFormSubmitBehavior("click") {
        @Override
        protected void onAfterSubmit(final AjaxRequestTarget target) {
            config.getWmsQosMetadata().getOperationAnomalyFeed().add(new ReferenceType());
            target.add(anomalyDiv);
        }
    });

    // Statements
    if (config.getWmsQosMetadata().getStatements() == null) {
        config.getWmsQosMetadata().setStatements(new ArrayList<>());
    }
    final QosStatementListPanel statPanel = new QosStatementListPanel("statemenstDiv",
            new ListModel<>(config.getWmsQosMetadata().getStatements()));
    configs.add(statPanel);

    initRepresentativeOperations(mainModel);
}

From source file:org.geoserver.status.monitoring.web.SystemStatusMonitorPanel.java

License:Open Source License

public SystemStatusMonitorPanel(String id) {
    super(id);/*from  w  ww . j  a v a  2 s .co m*/

    /*
     * Configure panel
     */

    final SystemInfoCollector systemInfoCollector = GeoServerExtensions.bean(SystemInfoCollector.class);
    final IModel<Date> timeMdl = Model.of(new Date());
    final IModel<List<MetricValue>> metricMdl = Model.ofList(Collections.emptyList());

    Label time = DateLabel.forDatePattern("time", timeMdl, datePattern);
    time.setOutputMarkupId(true);
    add(time);

    ListView<MetricValue> list = new ListView<MetricValue>("metrics", metricMdl) {
        private static final long serialVersionUID = -5654700538264617274L;

        private int counter;

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            counter = 0;
        }

        @Override
        protected void populateItem(ListItem<MetricValue> item) {
            item.add(new Label("info", new PropertyModel<MetricValue>(item.getModel(), "description")),
                    new Label("value", new PropertyModel<MetricValue>(item.getModel(), "valueUnit")));
            if (counter % 2 == 0) {
                item.add(new AttributeModifier("class", "odd"));
            } else {
                item.add(new AttributeModifier("class", "even"));
            }
            counter++;
        }
    };
    list.setOutputMarkupId(true);
    add(list);

    /*
     * Refresh every seconds
     */
    add(new AjaxSelfUpdatingTimerBehavior(Duration.seconds(1)) {
        private static final long serialVersionUID = -7009847252782601466L;

        @Override
        public void onConfigure(org.apache.wicket.Component component) {
            Metrics metrics = systemInfoCollector.retrieveAllSystemInfo();
            metricMdl.setObject(metrics.getMetrics());
            timeMdl.setObject(new Date());
        }

    });
}

From source file:org.headsupdev.agile.web.components.filters.ApplicationFilterPanel.java

License:Open Source License

protected void layoutFilter() {

    FilterBorder filter = new FilterBorder("filter");
    add(filter);/*from w  w  w  . j a  v a2s.  c o  m*/

    final Form filterForm = new Form("filterform") {
        @Override
        protected void onSubmit() {
            super.onSubmit();

            saveFilters();
        }
    };
    filter.add(filterForm.setOutputMarkupId(true));
    Button cancelButton = new Button("cancelbutton");
    filterForm.add(cancelButton);
    cancelButton.add(new AttributeModifier("onclick", true, new Model<String>() {
        public String getObject() {
            return "filterbuttonAnimator.reverse();";
        }
    }));

    Button applyButton = new Button("applybutton");
    filterForm.add(applyButton);
    applyButton.add(new AttributeModifier("onclick", true, new Model<String>() {
        public String getObject() {
            return "filterbuttonAnimator.reverse();";
        }
    }));

    final ListView<String> appListView = new ListView<String>("applist", allApps) {
        protected void populateItem(final ListItem<String> listItem) {
            final String appId = listItem.getModelObject();

            listItem.add(new Label("app-label", appId));
            listItem.add(new CheckBox("app-check", new Model<Boolean>() {
                public Boolean getObject() {
                    return appsVisible.get(appId);
                }

                public void setObject(Boolean b) {
                    appsVisible.put(appId, b);
                    onFilterUpdated();
                }
            }));
        }
    };
    filterForm.add(appListView.setOutputMarkupId(true));
}

From source file:org.hippoecm.frontend.dialog.AbstractDialog.java

License:Apache License

public AbstractDialog(IModel<T> model) {
    super("form", model);

    container = new Container(IDialogService.DIALOG_WICKET_ID);
    container.add(this);

    feedback = newFeedbackPanel("feedback");
    IFeedbackMessageFilter filter = feedback.getFilter();

    if (filter == null) {
        // make sure the feedback filters out messages unrelated to this dialog
        feedback.setFilter(new ContainerFeedbackMessageFilter(this));
    } else if (!(filter instanceof ContainerFeedbackMessageFilter)) {
        log.warn(/*w w  w  . j a  va 2  s. co  m*/
                "The dialog '{}' uses a feedback panel with a filter that does not extend ContainerFeedbackMessageFilter."
                        + "As a result, this dialog may show unrelated feedback messages.",
                getClass());
    }

    feedback.setOutputMarkupId(true);
    add(feedback);

    buttons = new LinkedList<>();
    ListView<ButtonWrapper> buttonsView = new ListView<ButtonWrapper>("buttons", buttons) {
        @Override
        protected void populateItem(ListItem<ButtonWrapper> item) {
            final Button button = item.getModelObject().getButton();
            if (StringUtils.isNotEmpty(buttonCssClass)) {
                button.add(CssClass.append(buttonCssClass));
            }
            item.add(button);
        }
    };
    buttonsView.setReuseItems(true);
    buttonsView.setOutputMarkupId(true);
    add(buttonsView);

    ok = new ButtonWrapper(new ResourceModel("ok")) {
        @Override
        protected void onSubmit() {
            handleSubmit();
        }

        @Override
        protected void onUpdateAjaxAttributes(final AjaxRequestAttributes attributes) {
            attributes.setChannel(ajaxChannel);
        }
    };
    ok.setKeyType(KeyType.Enter);
    buttons.add(ok);

    cancel = new ButtonWrapper(new ResourceModel("cancel")) {

        @Override
        protected void onSubmit() {
            cancelled = true;
            onCancel();
            closeDialog();
        }

        @Override
        protected Button decorate(final Button button) {
            button.add(new AjaxEventBehavior("onclick") {

                @Override
                protected void onComponentTag(final ComponentTag tag) {
                    super.onComponentTag(tag);
                    tag.put("type", "button");
                }

                @Override
                protected void onEvent(final AjaxRequestTarget target) {
                    onSubmit();
                }
            });
            button.setDefaultFormProcessing(false);
            return super.decorate(button);
        }
    };
    cancel.setKeyType(KeyType.Escape);
    buttons.add(cancel);

    if (isFullscreenEnabled()) {
        final AjaxButton goFullscreen = new AjaxButton(DialogConstants.BUTTON,
                new AbstractReadOnlyModel<String>() {
                    @Override
                    public String getObject() {
                        return getString(fullscreen ? "exit-fullscreen" : "fullscreen");
                    }
                }) {
            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                target.appendJavaScript(getFullscreenScript());
                target.add(this); //update button label
                fullscreen = !fullscreen;
            }
        };
        addButton(goFullscreen);
    }

    if (addAjaxIndicator()) {
        add(indicator = new AjaxIndicatorAppender() {
            @Override
            protected CharSequence getIndicatorUrl() {
                return RequestCycle.get()
                        .urlFor(new ResourceReferenceRequestHandler(DialogConstants.AJAX_LOADER_GIF));
            }
        });
    }
}