Example usage for org.apache.wicket Component add

List of usage examples for org.apache.wicket Component add

Introduction

In this page you can find the example usage for org.apache.wicket Component add.

Prototype

public Component add(final Behavior... behaviors) 

Source Link

Document

Adds a behavior modifier to the component.

Usage

From source file:com.doculibre.constellio.wicket.panels.search.advanced.AdvancedSearchPanel.java

License:Open Source License

public AdvancedSearchPanel(String id, final IModel simpleSearchModel) {
    super(id);/*from w  w  w .j a v a2 s  .c  om*/

    add(HeaderContributor.forJavaScript(MYPAGE_JS));

    final IModel ruleTypesModel = new LoadableDetachableModel() {

        protected Object load() {
            RecordCollectionServices recordCollectionServices = ConstellioSpringUtils
                    .getRecordCollectionServices();

            SimpleSearch search = (SimpleSearch) simpleSearchModel.getObject();
            RecordCollection recordCollection = recordCollectionServices.get(search.getCollectionName());

            List<RuleTypeChoice> choices = new ArrayList<RuleTypeChoice>();

            for (AdvancedSearchEnabledRule enabledRule : recordCollection.getAdvancedSearchEnabledRules()) {
                IndexField indexField = enabledRule.getIndexField();

                SearchRule rule = SearchRulesFactory.constructSearchRule(indexField);
                if (rule != null) {
                    SimpleParams params = rule.toSimpleParams(true);

                    RuleTypeChoice choice = new RuleTypeChoice();
                    String title = indexField.getLabel(IndexField.LABEL_TITLE,
                            ConstellioSession.get().getLocale());
                    choice.name = title != null ? title : indexField.getName();
                    choice.params = params;
                    choices.add(choice);
                }
            }

            Collections.sort(choices);

            RuleTypeChoice defaultFieldSearch = new RuleTypeChoice();
            defaultFieldSearch.name = new StringResourceModel("defaultField", AdvancedSearchPanel.this, null)
                    .getString();
            defaultFieldSearch.params = SearchRulesFactory.getDefaultFieldSearchRule().toSimpleParams(true);
            choices.add(0, defaultFieldSearch);

            return choices;
        }

    };

    IModel rulesModel = new LoadableDetachableModel() {

        @Override
        protected Object load() {
            SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject();
            SearchRule rootSearchRule = simpleSearch.getAdvancedSearchRule();

            List<SearchRule> rules;
            if (rootSearchRule == null) {
                rules = new ArrayList<SearchRule>();
            } else {
                rules = rootSearchRule.toList();
            }

            return rules;
        }
    };
    add(new ListView("rules", rulesModel) {

        @Override
        protected void populateItem(ListItem item) {
            SimpleSearch simpleSearch = (SimpleSearch) simpleSearchModel.getObject();
            final SimpleSearch clonedSimpleSearch = simpleSearch.clone();
            final SearchRule rule = (SearchRule) item.getModelObject();

            Component ruleComponent = SearchRulePanelFactory.constructPanel("rule", clonedSimpleSearch, rule,
                    ruleTypesModel);
            //int leftSpace = 25 * Math.max(0, rule.getLevel() - 1);
            int leftSpace = 25 * rule.getLevel();
            ruleComponent.add(new SimpleAttributeModifier("style", "margin-left:" + leftSpace + "px;"));
            item.add(ruleComponent);
            item.add(newDeleteButton(clonedSimpleSearch, rule));
            item.add(newAddRuleButton(clonedSimpleSearch, rule));
            item.add(newAddGroupButton(clonedSimpleSearch, rule));
        }

    });
}

From source file:com.doculibre.constellio.wicket.panels.spellchecker.SpellCheckerPanel.java

License:Open Source License

private void initComponents() {
    searchTxtField.setOutputMarkupId(true);
    searchButton.setOutputMarkupId(true);

    IModel suggestedSearchKeyListModel = new LoadableDetachableModel() {
        @Override/*from w  w  w. j  a  v a  2 s.  c  om*/
        protected Object load() {
            ListOrderedMap suggestedSearch = getSuggestedSearch();
            return suggestedSearch.keyList();
        }
    };

    // Tags <li>
    add(new ListView("suggestion", suggestedSearchKeyListModel) {
        @SuppressWarnings("unchecked")
        @Override
        protected void populateItem(ListItem item) {
            ListOrderedMap suggestedSearch = getSuggestedSearch();
            String originalWord = (String) item.getModelObject();
            List<String> suggestionsForWord = (List<String>) suggestedSearch.get(originalWord);

            boolean hasSuggestionForWord = suggestionsForWord != null && !suggestionsForWord.isEmpty();
            boolean hasManySuggestionsForWord = hasSuggestionForWord && suggestionsForWord.size() > 1;

            final int wordIndex = item.getIndex();
            // <li> suggested word
            Component suggestedWordComponent;
            if (hasSuggestionForWord) {
                suggestedWordComponent = new Label("motSuggere", originalWord);
                suggestedWordComponent.add(new SimpleAttributeModifier("id", "mot" + wordIndex));
            } else {
                suggestedWordComponent = new WebMarkupContainer("motSuggere");
                suggestedWordComponent.setVisible(false);
            }
            if (hasManySuggestionsForWord) {
                suggestedWordComponent.add(new SimpleAttributeModifier("rel", "suggestion" + item.getIndex()));
            }
            item.add(suggestedWordComponent);
            suggestedWordComponent.add(getLaunchSuggestedSearchOnclickModifier());

            // <li> vide pour avoir une flche en cas de suggestions multiples
            //WebMarkupContainer flecheMotSuggereContainer = new WebMarkupContainer("flecheMotSuggere");
            //flecheMotSuggereContainer.setVisible(plusieursMotsSuggeres);
            //flecheMotSuggereContainer.add(new SimpleAttributeModifier("rel", "suggestion" + item.getIndex()));
            //item.add(flecheMotSuggereContainer);

            // <li> si pas de suggestion
            Component noSuggestionWordComponent;
            if (!hasSuggestionForWord) {
                noSuggestionWordComponent = new Label("motNonSuggere", originalWord);
            } else {
                noSuggestionWordComponent = new WebMarkupContainer("motNonSuggere");
                noSuggestionWordComponent.setVisible(false);
            }
            item.add(noSuggestionWordComponent);
            noSuggestionWordComponent.add(getLaunchSuggestedSearchOnclickModifier());
        }
    });

    // Tags <div>
    add(new ListView("autresSuggestionsMot", suggestedSearchKeyListModel) {
        @SuppressWarnings("unchecked")
        @Override
        protected void populateItem(ListItem item) {
            ListOrderedMap suggestedSearch = getSuggestedSearch();
            String originalWord = (String) item.getModelObject();
            List<String> suggestedWords = (List<String>) suggestedSearch.get(originalWord);

            boolean hasSuggestedWord = suggestedWords != null && !suggestedWords.isEmpty();
            boolean hasManySuggestedWords = hasSuggestedWord && suggestedWords.size() > 1;

            final int wordIndex = item.getIndex();
            if (hasManySuggestedWords) {
                item.add(new SimpleAttributeModifier("id", "suggestion" + wordIndex));
                item.add(new ListView("lienRemplacerMot", suggestedWords) {
                    @Override
                    protected void populateItem(ListItem item) {
                        String suggestedWord = (String) item.getModelObject();

                        WebMarkupContainer lien = new WebMarkupContainer("lien");
                        item.add(lien);
                        lien.add(new Label("libelle", suggestedWord));

                        StringBuffer jsReplaceWord = new StringBuffer("remplacerMot('");
                        jsReplaceWord.append(JavascriptUtils.escapeQuotes(suggestedWord));
                        jsReplaceWord.append("', ");
                        jsReplaceWord.append(wordIndex);
                        jsReplaceWord.append(");");
                        if (!hasManySuggestions()) {
                            jsReplaceWord.append(getLaunchSuggestedSearchJSCall());
                        }
                        lien.add(new SimpleAttributeModifier("onclick", jsReplaceWord));
                    }
                });
            } else {
                item.setVisible(false);
            }
        }
    });
}

From source file:com.evolveum.midpoint.gui.impl.page.admin.configuration.component.StringPropertyNotificationPanel.java

License:Apache License

private void initLayout(final IModel<Object> model, final Form form) {
    WebMarkupContainer labelContainer = new WebMarkupContainer(ID_LABEL_CONTAINER);
    labelContainer.setOutputMarkupId(true);
    labelContainer.add(new VisibleEnableBehaviour() {
        private static final long serialVersionUID = 1L;

        @Override//from  w w  w.ja  v a2 s .co  m
        public boolean isVisible() {
            return labelContainerVisible;
        }
    });
    add(labelContainer);

    final IModel<String> label = name;
    Label displayName = new Label(ID_LABEL, label);
    displayName.add(new AttributeModifier("style", new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return "text-decoration: none;";
        }
    }));
    labelContainer.add(displayName);

    final IModel<String> helpText = getPageBase().createStringResource(name.getObject() + ".help", "");
    Label help = new Label(ID_HELP);
    help.add(AttributeModifier.replace("title", helpText));
    help.add(new InfoTooltipBehavior());
    help.add(new VisibleEnableBehaviour() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return StringUtils.isNotEmpty(helpText.getObject())
                    && !((name.getObject() + ".help").equals(helpText.getObject()));
        }
    });
    labelContainer.add(help);
    Component panel = null;
    if (type.equals(String.class)) {
        panel = new TextPanel(ID_VALUE, getModel(), String.class);
    } else if (type.equals(Boolean.class)) {
        panel = new TriStateComboPanel(ID_VALUE, (IModel) getModel());
    } else {
        throw new IllegalStateException(
                "Unsupported type " + getModel().getObject().getClass().getName() + " for Model");
    }
    panel.add(new AttributeModifier("class", new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            return getInputCssClass();
        }
    }));
    add(panel);
}

From source file:com.evolveum.midpoint.web.component.assignment.AssignmentEditorPanel.java

License:Apache License

private void addAjaxOnBlurUpdateBehaviorToComponent(final Component component) {
    component.setOutputMarkupId(true);//from  w  w w  . j  a v  a  2  s.c  o m
    component.add(new AjaxFormComponentUpdatingBehavior("onBlur") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
        }
    });
}

From source file:com.evolveum.midpoint.web.component.data.column.InlineMenuButtonColumn.java

License:Apache License

@Override
public void populateItem(final Item<ICellPopulator<T>> cellItem, String componentId, final IModel<T> rowModel) {
    Component panel = getPanel(componentId, rowModel, getNumberOfButtons(false), false);
    panel.add(new VisibleBehaviour(() -> isPanelVisible(false)));
    cellItem.add(panel);//from   ww w  .  j a  va  2s.c om
}

From source file:com.evolveum.midpoint.web.component.data.column.InlineMenuButtonColumn.java

License:Apache License

@Override
public Component getHeader(String componentId) {

    Component headerPanel = getPanel(componentId, null, getNumberOfButtons(true), true);
    headerPanel.add(new VisibleBehaviour(() -> isPanelVisible(true)));
    return headerPanel;
}

From source file:com.evolveum.midpoint.web.component.data.TablePanel.java

License:Apache License

private void addVisibleBehaviour(Component comp, final IModel<Boolean> model) {
    comp.add(new VisibleEnableBehaviour() {

        @Override//w ww.j  a va  2s .c  om
        public boolean isVisible() {
            return model.getObject();
        }
    });
}

From source file:com.evolveum.midpoint.web.component.refresh.AutoRefreshPanel.java

License:Apache License

public void startRefreshing(final Refreshable refreshable, AjaxRequestTarget target) {
    stopRefreshing(refreshable, target);
    int refreshInterval = refreshable.getRefreshInterval();
    getModel().getObject().setInterval(refreshInterval);

    Component parent = refreshable.getRefreshingBehaviorParent();
    RemovableAjaxTimerBehavior refreshingBehavior = new RemovableAjaxTimerBehavior(parent, refreshInterval) {
        @Override/*from   w  w  w  .j  a  v a  2  s. c o  m*/
        protected void handleOnTimer(AjaxRequestTarget target1) {
            refreshable.refresh(target1);
        }
    };
    parent.add(refreshingBehavior);
}

From source file:com.evolveum.midpoint.web.component.search.SearchPanel.java

License:Apache License

private void initPopover() {
    WebMarkupContainer popover = new WebMarkupContainer(ID_POPOVER);
    popover.setOutputMarkupId(true);//from  w  ww.  ja va2s .  com
    add(popover);

    final WebMarkupContainer propList = new WebMarkupContainer(ID_PROP_LIST);
    propList.setOutputMarkupId(true);
    popover.add(propList);

    ListView properties = new ListView<Property>(ID_PROPERTIES,
            new PropertyModel<List<Property>>(moreDialogModel, MoreDialogDto.F_PROPERTIES)) {

        @Override
        protected void populateItem(final ListItem<Property> item) {
            CheckBox check = new CheckBox(ID_CHECK,
                    new PropertyModel<Boolean>(item.getModel(), Property.F_SELECTED));
            check.add(new AjaxFormComponentUpdatingBehavior("change") {

                @Override
                protected void onUpdate(AjaxRequestTarget target) {
                    //nothing, just update model.
                }
            });
            item.add(check);

            AjaxLink propLink = new AjaxLink(ID_PROP_LINK) {

                @Override
                public void onClick(AjaxRequestTarget target) {
                    addOneItemPerformed(item.getModelObject(), target);
                }
            };
            item.add(propLink);

            Label name = new Label(ID_PROP_NAME, new PropertyModel<>(item.getModel(), Property.F_NAME));
            name.setRenderBodyOnly(true);
            propLink.add(name);

            item.add(new VisibleEnableBehaviour() {

                @Override
                public boolean isVisible() {
                    Property property = item.getModelObject();

                    Search search = SearchPanel.this.getModelObject();
                    if (!search.getAvailableDefinitions().contains(property.getDefinition())) {
                        return false;
                    }

                    MoreDialogDto dto = moreDialogModel.getObject();
                    String nameFilter = dto.getNameFilter();

                    String propertyName = property.getName().toLowerCase();
                    if (StringUtils.isNotEmpty(nameFilter)
                            && !propertyName.contains(nameFilter.toLowerCase())) {
                        return false;
                    }

                    return true;
                }
            });
        }
    };
    propList.add(properties);

    TextField addText = new TextField(ID_ADD_TEXT,
            new PropertyModel(moreDialogModel, MoreDialogDto.F_NAME_FILTER));
    addText.add(new Behavior() {
        @Override
        public void bind(Component component) {
            super.bind(component);

            component.add(AttributeModifier.replace("onkeydown",
                    Model.of("if(event.keyCode == 13) {event.preventDefault();}")));
        }
    });

    popover.add(addText);
    addText.add(new AjaxFormComponentUpdatingBehavior("keyup") {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(propList);
        }
    });
    popover.add(addText);

    AjaxButton add = new AjaxButton(ID_ADD, createStringResource("SearchPanel.add")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            addItemPerformed(target);
        }
    };
    popover.add(add);

    AjaxButton close = new AjaxButton(ID_CLOSE, createStringResource("SearchPanel.close")) {

        @Override
        public void onClick(AjaxRequestTarget target) {
            closeMorePopoverPerformed(target);
        }
    };
    popover.add(close);
}

From source file:com.evolveum.midpoint.web.component.search.TextPopupPanel.java

License:Apache License

private void initLayout() {
    final TextField input = initTextField();

    input.add(new AjaxFormComponentUpdatingBehavior("blur") {

        @Override//www . j  ava 2  s. c  o  m
        protected void onUpdate(AjaxRequestTarget target) {
            //nothing to do, just update model data
        }
    });
    input.add(new Behavior() {

        @Override
        public void bind(Component component) {
            super.bind(component);

            component.add(AttributeModifier.replace("onkeydown",
                    Model.of("if(event.keyCode == 13) {event.preventDefault();}")));
        }
    });
    input.setOutputMarkupId(true);
    add(input);
}