Example usage for org.apache.wicket.ajax.markup.html AjaxLink setVisible

List of usage examples for org.apache.wicket.ajax.markup.html AjaxLink setVisible

Introduction

In this page you can find the example usage for org.apache.wicket.ajax.markup.html AjaxLink setVisible.

Prototype

public final Component setVisible(final boolean visible) 

Source Link

Document

Sets whether this component and any children are visible.

Usage

From source file:org.apache.syncope.console.pages.panels.UserDetailsPanel.java

License:Apache License

public UserDetailsPanel(final String id, final UserTO userTO, final Form form, final boolean resetPassword,
        final boolean templateMode) {

    super(id);/*from w  w w  . ja  v a2 s  .  c  o m*/

    // ------------------------
    // Username
    // ------------------------
    final FieldPanel<String> username = new AjaxTextFieldPanel("username", "username",
            new PropertyModel<String>(userTO, "username"));

    final WebMarkupContainer jexlHelp = JexlHelpUtil.getJexlHelpWebContainer("usernameJexlHelp");

    final AjaxLink<?> questionMarkJexlHelp = JexlHelpUtil.getAjaxLink(jexlHelp, "usernameQuestionMarkJexlHelp");
    add(questionMarkJexlHelp);
    questionMarkJexlHelp.add(jexlHelp);

    if (!templateMode) {
        username.addRequiredLabel();
        questionMarkJexlHelp.setVisible(false);
    }
    add(username);
    // ------------------------

    // ------------------------
    // Password
    // ------------------------
    final WebMarkupContainer pwdJexlHelp = JexlHelpUtil.getJexlHelpWebContainer("pwdJexlHelp");

    final AjaxLink<?> pwdQuestionMarkJexlHelp = JexlHelpUtil.getAjaxLink(pwdJexlHelp,
            "pwdQuestionMarkJexlHelp");
    add(pwdQuestionMarkJexlHelp);
    pwdQuestionMarkJexlHelp.add(pwdJexlHelp);

    FieldPanel<String> password;
    Label confirmPasswordLabel = new Label("confirmPasswordLabel", new ResourceModel("confirmPassword"));
    FieldPanel<String> confirmPassword;
    if (templateMode) {
        password = new AjaxTextFieldPanel("password", "password",
                new PropertyModel<String>(userTO, "password"));

        confirmPasswordLabel.setVisible(false);
        confirmPassword = new AjaxTextFieldPanel("confirmPassword", "confirmPassword", new Model<String>());
        confirmPassword.setEnabled(false);
        confirmPassword.setVisible(false);
    } else {
        pwdQuestionMarkJexlHelp.setVisible(false);

        password = new AjaxPasswordFieldPanel("password", "password",
                new PropertyModel<String>(userTO, "password"));
        password.setRequired(userTO.getId() == 0);
        ((PasswordTextField) password.getField()).setResetPassword(resetPassword);

        confirmPassword = new AjaxPasswordFieldPanel("confirmPassword", "confirmPassword", new Model<String>());
        if (!resetPassword) {
            confirmPassword.getField().setModelObject(userTO.getPassword());
        }
        confirmPassword.setRequired(userTO.getId() == 0);
        ((PasswordTextField) confirmPassword.getField()).setResetPassword(resetPassword);

        form.add(new EqualPasswordInputValidator(password.getField(), confirmPassword.getField()));
    }
    add(password);
    add(confirmPasswordLabel);
    add(confirmPassword);

    final WebMarkupContainer mandatoryPassword = new WebMarkupContainer("mandatory_pwd");
    mandatoryPassword.add(new Behavior() {

        private static final long serialVersionUID = 1469628524240283489L;

        @Override
        public void onComponentTag(final Component component, final ComponentTag tag) {
            if (userTO.getId() > 0) {
                tag.put("style", "display:none;");
            }
        }
    });

    add(mandatoryPassword);
    // ------------------------
}

From source file:org.apache.syncope.console.wicket.markup.html.form.MultiFieldPanel.java

License:Apache License

public MultiFieldPanel(final String id, final IModel<List<E>> model, final FieldPanel<E> panelTemplate,
        final boolean eventTemplate) {

    super(id, model);

    // -----------------------
    // Object container definition
    // -----------------------
    container = new WebMarkupContainer("multiValueContainer");
    container.setOutputMarkupId(true);//from w w w .j ava  2  s.c  o m
    add(container);
    // -----------------------

    view = new ListView<E>("view", model) {

        private static final long serialVersionUID = -9180479401817023838L;

        @Override
        protected void populateItem(final ListItem<E> item) {
            final FieldPanel<E> fieldPanel = panelTemplate.clone();

            if (eventTemplate) {
                fieldPanel.getField().add(new AjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {

                    private static final long serialVersionUID = -1107858522700306810L;

                    @Override
                    protected void onUpdate(final AjaxRequestTarget target) {
                        send(getPage(), Broadcast.BREADTH, new MultiValueSelectorEvent(target));
                    }
                });
            }

            fieldPanel.setNewModel(item);
            item.add(fieldPanel);

            AjaxLink<Void> minus = new IndicatingAjaxLink<Void>("drop") {

                private static final long serialVersionUID = -7978723352517770644L;

                @Override
                public void onClick(final AjaxRequestTarget target) {
                    //Drop current component
                    model.getObject().remove(item.getModelObject());
                    fieldPanel.getField().clearInput();
                    target.add(container);

                    if (eventTemplate) {
                        send(getPage(), Broadcast.BREADTH, new MultiValueSelectorEvent(target));
                    }
                }
            };

            item.add(minus);

            if (model.getObject().size() <= 1) {
                minus.setVisible(false);
                minus.setEnabled(false);
            } else {
                minus.setVisible(true);
                minus.setEnabled(true);
            }

            final Fragment fragment;
            if (item.getIndex() == model.getObject().size() - 1) {
                final AjaxLink<Void> plus = new IndicatingAjaxLink<Void>("add") {

                    private static final long serialVersionUID = -7978723352517770644L;

                    @Override
                    public void onClick(final AjaxRequestTarget target) {
                        //Add current component
                        model.getObject().add(null);
                        target.add(container);
                    }
                };

                fragment = new Fragment("panelPlus", "fragmentPlus", container);

                fragment.add(plus);
            } else {
                fragment = new Fragment("panelPlus", "emptyFragment", container);
            }
            item.add(fragment);
        }
    };

    container.add(view.setOutputMarkupId(true));
    setOutputMarkupId(true);
}

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();/*from ww  w  .  j a v  a  2  s . com*/

    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.dcm4chee.wizard.panel.BasicConfigurationPanel.java

License:LGPL

private AbstractColumn<ConfigTreeNode, String> getEditColumn() {
    return new AbstractColumn<ConfigTreeNode, String>(Model.of("Edit")) {

        private static final long serialVersionUID = 1L;

        public void populateItem(final Item<ICellPopulator<ConfigTreeNode>> cellItem, final String componentId,
                final IModel<ConfigTreeNode> rowModel) {

            final TreeNodeType type = rowModel.getObject().getNodeType();
            if (type == null)
                throw new RuntimeException("Error: Unknown node type, cannot create edit modal window");

            AjaxLink<Object> ajaxLink = new AjaxLink<Object>("wickettree.link") {

                private static final long serialVersionUID = 1L;

                @Override/*from  www. j  av  a2  s. c o m*/
                public void onClick(AjaxRequestTarget target) {
                    editWindow.setTitle("Device "
                            + ((DeviceModel) rowModel.getObject().getRoot().getModel()).getDeviceName());
                    setEditWindowPageCreator(rowModel, type);
                    editWindow.setWindowClosedCallback(windowClosedCallback).show(target);
                }
            };

            ajaxLink.setVisible((!type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_APPLICATION_ENTITIES)
                    && !type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_HL7_APPLICATIONS)
                    && !type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_AUDIT_LOGGERS))
                    || rowModel.getObject().getParent().getChildren().get(0).hasChildren());

            try {
                if (type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_FORWARD_OPTIONS))
                    ajaxLink.setVisible(ConfigTreeProvider.get().getUniqueAETitles().length > 0);
            } catch (ConfigurationException ce) {
                log.error("Error listing Registered AE Titles", ce);
                if (log.isDebugEnabled())
                    ce.printStackTrace();
            }

            try {
                if (type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_AUDIT_LOGGERS)
                        && ((DeviceModel) rowModel.getObject().getParent().getModel()).getDevice()
                                .getDeviceExtension(AuditLogger.class) != null)
                    ajaxLink.setVisible(false);
            } catch (ConfigurationException ce) {
                log.error("Error accessing Audit Logger", ce);
            }

            ResourceReference image;
            if (type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_CONNECTIONS)
                    || type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_APPLICATION_ENTITIES)
                    || type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_HL7_APPLICATIONS)
                    || type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_AUDIT_LOGGERS)
                    || type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_TRANSFER_CAPABILITIES)
                    || type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_FORWARD_RULES)
                    || type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_FORWARD_OPTIONS)
                    || type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_RETRIES)
                    || type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_COERCIONS))
                image = ImageManager.IMAGE_WIZARD_COMMON_ADD;
            else
                image = ImageManager.IMAGE_WIZARD_COMMON_EDIT;

            if (type.equals(ConfigTreeNode.TreeNodeType.CONTAINER_TRANSFER_CAPABILITY_TYPE))
                cellItem.add(new Label(componentId));
            else
                cellItem.add(new LinkPanel(componentId, ajaxLink, image, removeConfirmation))
                        .add(new AttributeAppender("style", Model.of("width: 50px; text-align: center;")));
        }
    };
}

From source file:org.dcm4chee.wizard.panel.BasicConfigurationPanel.java

License:LGPL

private AbstractColumn<ConfigTreeNode, String> getEmptyModelColumn() {
    return new AbstractColumn<ConfigTreeNode, String>(Model.of("")) {

        private static final long serialVersionUID = 1L;

        public void populateItem(final Item<ICellPopulator<ConfigTreeNode>> cellItem, final String componentId,
                final IModel<ConfigTreeNode> rowModel) {

            final TreeNodeType type = rowModel.getObject().getNodeType();
            if (type == null)
                throw new RuntimeException("Error: Unknown node type, cannot create edit modal window");

            if (!type.equals(ConfigTreeNode.TreeNodeType.DEVICE)
                    || !getDicomConfigurationManager().getConnectedDeviceUrls()
                            .containsKey(rowModel.getObject().getName())
                    || !((WizardApplication) getApplication()).getDicomConfigurationManager()
                            .isReload(rowModel.getObject().getName())) {
                cellItem.add(new Label(componentId));
                return;
            }/*from w w  w  . j  a  v  a 2s  .  c o  m*/

            AjaxLink<Object> reloadWarningLink = new AjaxLink<Object>("wickettree.link") {

                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget arg0) {
                }
            };

            reloadWarningLink
                    .setVisible(((WizardApplication) getApplication()).getDicomConfigurationManager()
                            .isReload(rowModel.getObject().getName()))
                    .setEnabled(false)
                    .add(new AttributeAppender("title", new ResourceModel("dicom.reload.warning.tooltip")));

            cellItem.add(new LinkPanel(componentId, reloadWarningLink, ImageManager.IMAGE_WIZARD_RELOAD_WARNING,
                    null)).add(new AttributeAppender("style", Model.of("width: 50px; text-align: center;")));
        }
    };
}

From source file:org.efaps.ui.wicket.pages.error.ErrorPage.java

License:Apache License

/**
 * Constructor adding all Components.//  w w w  . ja  v a2  s  .co m
 *
 * @param _exception Excpetion that was thrown
 */
public ErrorPage(final Exception _exception) {
    super();

    ErrorPage.LOG.error("ErrorPage was called", _exception);

    String errorMessage = _exception.getMessage();
    String errorAction = "";
    String errorKey = "";
    String errorId = "";
    String errorAdvanced = "";

    add(DateLabel.forDateStyle("date", Model.of(new Date()), "FF"));

    if (_exception instanceof EFapsException) {
        final EFapsException eFapsException = (EFapsException) _exception;
        errorKey = eFapsException.getClassName().getName() + "." + eFapsException.getId();
        errorId = DBProperties.getProperty(errorKey + ".Id");
        errorMessage = DBProperties.getProperty(errorKey + ".Message");
        errorAction = DBProperties.getProperty(errorKey + ".Action");
        if (eFapsException.getArgs() != null) {
            errorMessage = MessageFormat.format(errorMessage, eFapsException.getArgs());
        }
    } else {
        if (errorMessage == null) {
            errorMessage = _exception.toString();
        }
    }

    final StackTraceElement[] traceElements = _exception.getStackTrace();
    for (int i = 0; i < traceElements.length; i++) {
        errorAdvanced += traceElements[i].toString() + "\n";
    }

    // set the title for the Page
    add(new Label("pageTitle", DBProperties.getProperty("ErrorPage.Titel")));

    add(new Label("dateLabel", DBProperties.getProperty("ErrorPage.Date.Label")));

    add(new Label("errorIDLabel", DBProperties.getProperty("ErrorPage.Id.Label")));
    add(new Label("errorID", errorId));

    add(new Label("errorMsgLabel", DBProperties.getProperty("ErrorPage.Message.Label")));
    add(new MultiLineLabel("errorMsg", errorMessage));

    final WebMarkupContainer advanced = new WebMarkupContainer("advanced");

    final AjaxLink<Object> ajaxlink = new AjaxLink<Object>("openclose") {

        private static final long serialVersionUID = 1L;

        private boolean expanded = false;

        @Override
        public void onClick(final AjaxRequestTarget _target) {
            this.expanded = !this.expanded;
            String text;
            if (this.expanded) {
                text = "less";
            } else {
                text = "more";
            }
            advanced.setVisible(this.expanded);

            final Label label = new Label("opencloseLabel", text);

            label.setOutputMarkupId(true);

            replace(label);

            _target.add(label);
            _target.add(advanced);

        }
    };
    this.add(ajaxlink);

    ajaxlink.add(new Label("opencloseLabel", "more").setOutputMarkupId(true));

    try {
        if (!(errorAdvanced.length() > 0) && Context.getThreadContext().getPerson()
                .isAssigned(Role.get(KernelSettings.USER_ROLE_ADMINISTRATION))) {
            ajaxlink.setVisible(false);
        }
    } catch (final EFapsException e) {
        ErrorPage.LOG.error("Catched Exception", _exception);
    }

    this.add(advanced);
    advanced.setVisible(false);
    advanced.setOutputMarkupPlaceholderTag(true);

    advanced.add(new MultiLineLabel("advancedMsg", errorAdvanced));

    add(new Label("errorActLabel", DBProperties.getProperty("ErrorPage.Action.Label")));
    add(new Label("errorAct", errorAction));

}

From source file:org.geoserver.importer.web.ImportDataPage.java

License:Open Source License

public ImportDataPage(PageParameters params) {
    Form form = new Form("form");
    add(form);//  w  w w . j  ava 2  s. c o  m

    sourceList = new AjaxRadioPanel<Source>("sources", Arrays.asList(Source.values()), Source.SPATIAL_FILES) {
        @Override
        protected void onRadioSelect(AjaxRequestTarget target, Source newSelection) {
            updateSourcePanel(newSelection, target);
        }

        @Override
        protected AjaxRadio<Source> newRadioCell(RadioGroup<Source> group, ListItem<Source> item) {
            AjaxRadio<Source> radio = super.newRadioCell(group, item);
            if (!item.getModelObject().isAvailable()) {
                radio.setEnabled(false);
            }
            return radio;
        }

        @Override
        protected Component createLabel(String id, ListItem<Source> item) {
            return new SourceLabelPanel(id, item.getModelObject());
        }
    };

    form.add(sourceList);

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

    Catalog catalog = GeoServerApplication.get().getCatalog();

    // workspace chooser
    workspace = new WorkspaceDetachableModel(catalog.getDefaultWorkspace());
    workspaceChoice = new DropDownChoice("workspace", workspace, new WorkspacesModel(),
            new WorkspaceChoiceRenderer());
    workspaceChoice.setOutputMarkupId(true);
    workspaceChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            updateTargetStore(target);
        }
    });
    workspaceChoice.setNullValid(true);
    form.add(workspaceChoice);

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

    workspaceNameTextField = new TextField("workspaceName", new Model());
    workspaceNameTextField.setOutputMarkupId(true);
    boolean defaultWorkspace = catalog.getDefaultWorkspace() != null;
    workspaceNameTextField.setVisible(!defaultWorkspace);
    workspaceNameTextField.setRequired(!defaultWorkspace);
    workspaceNameContainer.add(workspaceNameTextField);

    //store chooser
    WorkspaceInfo ws = (WorkspaceInfo) workspace.getObject();
    store = new StoreModel(ws != null ? catalog.getDefaultDataStore(ws) : null);
    storeChoice = new DropDownChoice("store", store, new EnabledStoresModel(workspace),
            new StoreChoiceRenderer()) {
        protected String getNullValidKey() {
            return ImportDataPage.class.getSimpleName() + "." + super.getNullValidKey();
        };
    };
    storeChoice.setOutputMarkupId(true);

    storeChoice.setNullValid(true);
    form.add(storeChoice);

    form.add(statusLabel = new Label("status", new Model()).setOutputMarkupId(true));
    form.add(new AjaxSubmitLink("next", form) {
        @Override
        protected void disableLink(ComponentTag tag) {
            super.disableLink(tag);
            tag.setName("a");
            tag.addBehavior(new SimpleAttributeModifier("class", "disabled"));
        }

        protected void onError(AjaxRequestTarget target, Form<?> form) {
            target.addComponent(feedbackPanel);
        }

        protected void onSubmit(AjaxRequestTarget target, final Form<?> form) {

            //update status to indicate we are working
            statusLabel.add(new SimpleAttributeModifier("class", "working-link"));
            statusLabel.setDefaultModelObject("Working");
            target.addComponent(statusLabel);

            //enable cancel and disable this
            Component cancel = form.get("cancel");
            cancel.setEnabled(true);
            target.addComponent(cancel);

            setEnabled(false);
            target.addComponent(this);

            final AjaxSubmitLink self = this;

            final Long jobid;
            try {
                jobid = createContext();
            } catch (Exception e) {
                error(e);
                LOGGER.log(Level.WARNING, "Error creating import", e);
                resetButtons(form, target);
                return;
            }

            cancel.setDefaultModelObject(jobid);
            this.add(new AbstractAjaxTimerBehavior(Duration.seconds(3)) {
                protected void onTimer(AjaxRequestTarget target) {
                    Importer importer = ImporterWebUtils.importer();
                    Task<ImportContext> t = importer.getTask(jobid);

                    if (t.isDone()) {
                        try {
                            if (t.getError() != null) {
                                error(t.getError());
                            } else if (t.isCancelled()) {
                                //do nothing
                            } else {
                                ImportContext imp = t.get();

                                //check the import for actual things to do
                                boolean proceed = !imp.getTasks().isEmpty();

                                if (proceed) {
                                    imp.setArchive(false);
                                    importer.changed(imp);

                                    PageParameters pp = new PageParameters();
                                    pp.put("id", imp.getId());

                                    setResponsePage(ImportPage.class, pp);
                                } else {
                                    info("No data to import was found");
                                    importer.delete(imp);
                                }
                            }
                        } catch (Exception e) {
                            error(e);
                            LOGGER.log(Level.WARNING, "", e);
                        } finally {
                            stop();

                            //update the button back to original state
                            resetButtons(form, target);

                            target.addComponent(feedbackPanel);
                        }
                        return;
                    }

                    ProgressMonitor m = t.getMonitor();
                    String msg = m.getTask() != null ? m.getTask().toString() : "Working";

                    statusLabel.setDefaultModelObject(msg);
                    target.addComponent(statusLabel);
                };
            });
        }
    });

    form.add(new AjaxLink<Long>("cancel", new Model<Long>()) {
        protected void disableLink(ComponentTag tag) {
            super.disableLink(tag);
            ImporterWebUtils.disableLink(tag);
        };

        @Override
        public void onClick(AjaxRequestTarget target) {
            Importer importer = ImporterWebUtils.importer();
            Long jobid = getModelObject();
            Task<ImportContext> task = importer.getTask(jobid);
            if (task != null && !task.isDone() && !task.isCancelled()) {
                task.getMonitor().setCanceled(true);
                task.cancel(false);
                try {
                    task.get();
                } catch (Exception e) {
                }
            }

            setEnabled(false);

            Component next = getParent().get("next");
            next.setEnabled(true);

            target.addComponent(this);
            target.addComponent(next);
        }
    }.setOutputMarkupId(true).setEnabled(false));

    importTable = new ImportContextTable("imports", new ImportContextProvider(true) {
        @Override
        protected List<org.geoserver.web.wicket.GeoServerDataProvider.Property<ImportContext>> getProperties() {
            return Arrays.asList(ID, STATE, UPDATED);
        }
    }, true) {
        protected void onSelectionUpdate(AjaxRequestTarget target) {
            removeImportLink.setEnabled(!getSelection().isEmpty());
            target.addComponent(removeImportLink);
        };
    };
    importTable.setOutputMarkupId(true);
    importTable.setFilterable(false);
    importTable.setSortable(false);
    form.add(importTable);

    form.add(removeImportLink = new AjaxLink("remove") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            Importer importer = ImporterWebUtils.importer();
            for (ImportContext c : importTable.getSelection()) {
                try {
                    importer.delete(c);
                } catch (IOException e) {
                    LOGGER.log(Level.WARNING, "Error deleting context", c);
                }
            }
            importTable.clearSelection();
            target.addComponent(importTable);
        }
    });
    removeImportLink.setOutputMarkupId(true).setEnabled(false);

    AjaxLink jobLink = new AjaxLink("jobs") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            dialog.showOkCancel(target, new DialogDelegate() {
                @Override
                protected boolean onSubmit(AjaxRequestTarget target, Component contents) {
                    return true;
                }

                @Override
                protected Component getContents(String id) {
                    return new JobQueuePanel(id);
                }
            });
        }
    };
    jobLink.setVisible(ImporterWebUtils.isDevMode());
    form.add(jobLink);

    add(dialog = new GeoServerDialog("dialog"));
    dialog.setInitialWidth(600);
    dialog.setInitialHeight(400);
    dialog.setMinimalHeight(150);

    updateSourcePanel(Source.SPATIAL_FILES, null);
    updateTargetStore(null);
}

From source file:org.headsupdev.agile.app.ci.Tests.java

License:Open Source License

public void layout() {
    super.layout();
    add(CSSPackageResource.getHeaderContribution(getClass(), "ci.css"));

    Project project = getProject();/*from  w w w  .  j a va2  s. c  om*/
    long id = getPageParameters().getLong("id");
    if (project == null || id < 0) {
        notFoundError();
        return;
    }

    Build build = CIApplication.getBuild(id, getProject());
    addLink(new BookmarkableMenuLink(getPageClass("builds/"), getProjectPageParameters(), "history"));
    addLink(new BookmarkableMenuLink(getPageClass("builds/view"), getPageParameters(), "view"));

    buildId = build.getId();
    add(new Label("project", build.getProject().getAlias()));
    add(new Label("tests", String.valueOf(build.getTests())));
    add(new Label("failures", String.valueOf(build.getFailures())));
    add(new Label("errors", String.valueOf(build.getErrors())));

    List<TestResultSet> sets = new LinkedList<TestResultSet>(build.getTestResults());
    Collections.sort(sets, new Comparator<TestResultSet>() {
        public int compare(TestResultSet t1, TestResultSet t2) {
            return t1.getName().compareToIgnoreCase(t2.getName());
        }
    });
    add(new ListView<TestResultSet>("set", sets) {
        protected void populateItem(ListItem<TestResultSet> listItem) {
            final TestResultSet set = listItem.getModelObject();

            listItem.add(new Label("name", set.getName()));
            String icon;
            if (set.getErrors() > 0) {
                icon = "error.png";
            } else if (set.getFailures() > 0) {
                icon = "failed.png";
            } else {
                icon = "passed.png";
            }
            listItem.add(new Image("status", new ResourceReference(View.class, icon)));

            listItem.add(new Label("tests", String.valueOf(set.getTests())));
            listItem.add(new Label("failures", String.valueOf(set.getFailures())));
            listItem.add(new Label("errors", String.valueOf(set.getErrors())));

            final WebMarkupContainer log = new WebMarkupContainer("log");
            log.add(new Label("output", new Model<String>() {
                String output = null;

                @Override
                public String getObject() {
                    if (output == null) {
                        output = set.getOutput();
                    }

                    return output;
                }
            }));
            listItem.add(log.setOutputMarkupId(true).setVisible(false).setOutputMarkupPlaceholderTag(true));

            AjaxLink logLink = new AjaxLink("log-link") {
                public void onClick(AjaxRequestTarget target) {
                    log.setVisible(!log.isVisible());
                    target.addComponent(log);
                }
            };
            logLink.add(new Image("log-icon", new ResourceReference(Tests.class, "log.png")));
            listItem.add(logLink.setVisible(set.getOutput() != null));

            listItem.add(new Label("time", new FormattedDurationModel(set.getDuration())));

            List<TestResult> results = new LinkedList<TestResult>(set.getResults());
            Collections.sort(results, new Comparator<TestResult>() {
                public int compare(TestResult r1, TestResult r2) {
                    if (r1.getStatus() == r2.getStatus()) {
                        return r1.getName().compareToIgnoreCase(r2.getName());
                    }

                    return r2.getStatus() - r1.getStatus();
                }
            });
            listItem.add(new ListView<TestResult>("test", results) {
                protected void populateItem(final ListItem<TestResult> listItem) {
                    AttributeModifier rowColor = new AttributeModifier("class", true, new Model<String>() {
                        public String getObject() {
                            if (listItem.getIndex() % 2 == 1) {
                                return "odd";
                            }

                            return "even";
                        }
                    });
                    final TestResult result = listItem.getModelObject();

                    WebMarkupContainer row1 = new WebMarkupContainer("row1");
                    row1.add(rowColor);
                    listItem.add(row1);

                    String icon;
                    switch (result.getStatus()) {
                    case TestResult.STATUS_ERROR:
                        icon = "error.png";
                        break;
                    case TestResult.STATUS_FAILED:
                        icon = "failed.png";
                        break;
                    default:
                        icon = "passed.png";
                    }
                    row1.add(new Image("status", new ResourceReference(View.class, icon)));

                    if (result.getMessage() != null && result.getMessage().length() > 0) {
                        if (result.getStatus() == TestResult.STATUS_FAILED) {
                            row1.add(new Label("name",
                                    result.getName() + " (failed: " + result.getMessage() + ")"));
                        } else {
                            row1.add(new Label("name",
                                    result.getName() + " (error: " + result.getMessage() + ")"));
                        }
                    } else {
                        row1.add(new Label("name", result.getName()));
                    }

                    boolean showOutput = result.getStatus() == TestResult.STATUS_ERROR
                            || result.getStatus() == TestResult.STATUS_FAILED;
                    showOutput = showOutput && result.getOutput() != null;

                    final WebMarkupContainer row2 = new WebMarkupContainer("row2");
                    row2.add(rowColor);
                    row2.add(new Label("output", new Model<String>() {
                        @Override
                        public String getObject() {
                            return result.getOutput();
                        }
                    }));
                    listItem.add(row2.setVisible(false).setOutputMarkupPlaceholderTag(true));

                    AjaxLink logLink = new AjaxLink("log-link") {
                        public void onClick(AjaxRequestTarget target) {
                            row2.setVisible(!row2.isVisible());
                            target.addComponent(row2);
                        }
                    };
                    logLink.add(new Image("log-icon", new ResourceReference(Tests.class, "log.png")));
                    row1.add(logLink.setVisible(showOutput));
                    row1.add(new Label("time", new FormattedDurationModel(result.getDuration())));
                }
            });
        }
    });
}

From source file:org.hippoecm.frontend.editor.builder.RenderPluginEditorPlugin.java

License:Apache License

public RenderPluginEditorPlugin(final IPluginContext context, final IPluginConfig config) {
    super(context, config);

    renderContext = new RenderContext(context, config);
    builderContext = new BuilderContext(context, config);
    final boolean editable = (builderContext.getMode() == Mode.EDIT);

    final WebMarkupContainer container = new WebMarkupContainer("head");
    container.setOutputMarkupId(true);/*from ww w.  java 2 s. c  o m*/
    add(container);

    add(CssClass.append(new AbstractReadOnlyModel<String>() {
        @Override
        public String getObject() {
            return builderContext.hasFocus() ? "active" : StringUtils.EMPTY;
        }
    }));

    // add transitions from parent container
    container.add(new RefreshingView<ILayoutTransition>("transitions") {

        @Override
        protected Iterator<IModel<ILayoutTransition>> getItemModels() {
            final Iterator<ILayoutTransition> transitionIter = getTransitionIterator();
            return new Iterator<IModel<ILayoutTransition>>() {

                public boolean hasNext() {
                    return transitionIter.hasNext();
                }

                public IModel<ILayoutTransition> next() {
                    return new Model<>(transitionIter.next());
                }

                public void remove() {
                    transitionIter.remove();
                }

            };
        }

        @Override
        protected void populateItem(Item<ILayoutTransition> item) {
            final ILayoutTransition transition = item.getModelObject();
            AjaxLink<Void> link = new AjaxLink<Void>("link") {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    layoutContext.apply(transition);
                }

                @Override
                protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
                    super.updateAjaxAttributes(attributes);
                    attributes.getAjaxCallListeners().add(new EventStoppingDecorator());
                }

            };
            link.setVisible(editable);

            final String name = transition.getName();
            final Icon icon = getTransitionIconByName(name);

            link.add(CssClass.append(name));
            link.add(TitleAttribute.append(name));
            link.add(HippoIcon.fromSprite("icon", icon));
            item.add(link);
        }

    });

    final AjaxLink removeLink = new AjaxLink("remove") {

        @Override
        public void onClick(AjaxRequestTarget target) {
            if (validateDelete()) {
                builderContext.delete();
            }
        }

        @Override
        protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
            super.updateAjaxAttributes(attributes);
            attributes.getAjaxCallListeners().add(new EventStoppingDecorator());
        }

    };
    removeLink.setVisible(editable);
    removeLink.add(HippoIcon.fromSprite("icon", Icon.TIMES_CIRCLE));
    container.add(removeLink);

    if (editable) {
        add(new AjaxEventBehavior("onclick") {

            @Override
            protected void onEvent(AjaxRequestTarget target) {
                builderContext.focus();
            }

            @Override
            protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
                super.updateAjaxAttributes(attributes);
                attributes.getAjaxCallListeners().add(new EventStoppingDecorator());
            }
        });

        builderContext.addBuilderListener(new IBuilderListener() {

            public void onBlur() {
                AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
                if (target != null) {
                    target.add(RenderPluginEditorPlugin.this);
                }
            }

            public void onFocus() {
                AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
                if (target != null) {
                    target.add(RenderPluginEditorPlugin.this);
                }
            }
        });
    }
}

From source file:org.hippoecm.frontend.editor.plugins.field.FieldPluginEditor.java

License:Apache License

public FieldPluginEditor(String id, IModel<IPluginConfig> model, final boolean editable) {
    super(id, model);

    setOutputMarkupId(true);/*from  w w w.j  a  va2s. co m*/

    cssProvider = new CssProvider();

    final IModel<String> captionModel = new KeyMapModel(model, "caption");
    final IModel<String> hintModel = new KeyMapModel(model, "hint");

    if (editable) {
        add(new TextFieldWidget("caption-editor", captionModel));
        add(new TextAreaWidget("hint-editor", hintModel));
    } else {
        add(new Label("caption-editor", captionModel));
        add(new Label("hint-editor", hintModel));
    }
    add(new RefreshingView<String>("css") {

        @Override
        protected Iterator<IModel<String>> getItemModels() {
            return cssProvider.iterator();
        }

        @Override
        protected void populateItem(final Item<String> item) {
            if (editable) {
                item.add(new TextFieldWidget("editor", item.getModel()));
            } else {
                item.add(new Label("editor", item.getModel()));
            }
            item.add(new AjaxLink<Void>("remove") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    cssProvider.remove(item.getIndex());
                    target.add(FieldPluginEditor.this);
                }
            }.setVisible(editable));
        }
    });

    final AjaxLink<Void> addCssLink = new AjaxLink<Void>("add-css") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            cssProvider.addNew();
            target.add(FieldPluginEditor.this);
        }
    };
    addCssLink.setVisible(editable);
    addCssLink.add(HippoIcon.fromSprite("icon", Icon.PLUS));
    add(addCssLink);
}