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

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

Introduction

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

Prototype

public MarkupContainer add(final Component... children) 

Source Link

Document

Adds the child component(s) to this container.

Usage

From source file:org.geoserver.web.wicket.GeoServerTablePanel.java

License:Open Source License

protected ListView buildLinksListView(final GeoServerDataProvider<T> dataProvider) {
    return new ListView("sortableLinks", dataProvider.getVisibleProperties()) {

        @Override//  w w w  . ja  va 2  s .  co m
        protected void populateItem(ListItem item) {
            Property<T> property = (Property<T>) item.getModelObject();

            // build a sortable link if the property is sortable, a label otherwise
            IModel titleModel = getPropertyTitle(property);
            if (sortable && property.getComparator() != null) {
                Fragment f = new Fragment("header", "sortableHeader", item);
                AjaxLink link = sortLink(dataProvider, item);
                link.add(new Label("label", titleModel));
                f.add(link);
                item.add(f);
            } else {
                item.add(new Label("header", titleModel));
            }
        }

    };
}

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();/* ww w.j a v  a2 s  .c o m*/
    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);// w ww. j a  v a  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.builder.SectionView.java

License:Apache License

@Override
public void populateItem(Item<T> item) {
    final T type = item.getModelObject();
    AjaxLink<Void> link = new AjaxLink<Void>("template") {
        @Override/*from   w w w  . j  a va2  s. c om*/
        public void onClick(AjaxRequestTarget target) {
            onClickItem(type);
        }
    };
    link.add(new Label("template-name", getNameModel(type)));
    link.add(HippoIcon.fromSprite("icon", Icon.GEAR));
    item.add(link);
}

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

License:Apache License

public TemplateListPlugin(IPluginContext context, IPluginConfig config) {
    super(context, config);

    final IEditor.Mode mode = IEditor.Mode.fromString(getPluginConfig().getString("mode"), IEditor.Mode.VIEW);
    Fragment fragment = new Fragment("fragment", mode.toString(), this);
    add(fragment);/*  w  w w  .j  av a  2 s .c  o  m*/

    if (mode == IEditor.Mode.EDIT) {
        final ITemplateEngine engine = context.getService(config.getString(ITemplateEngine.ENGINE),
                ITemplateEngine.class);
        final List<String> editableTypes = engine.getEditableTypes();
        if (editableTypes instanceof IObservable) {
            context.registerService(new IObserver<IObservable>() {

                public IObservable getObservable() {
                    return (IObservable) editableTypes;
                }

                public void onEvent(Iterator<? extends IEvent<IObservable>> events) {
                    redraw();
                }

            }, IObserver.class.getName());
        }

        ITypeDescriptor containingType = TemplateListPlugin.this.getModelObject();
        String typeName = containingType.getName();
        final String prefix = typeName.substring(0, typeName.indexOf(':'));

        final List<Section> sections = new ArrayList<>(5);
        sections.add(new CategorySection(engine, editableTypes, "primitive") {
            @Override
            boolean isTypeInCategory(ITypeDescriptor descriptor) {
                return !descriptor.isNode() && !descriptor.isMixin();
            }
        });
        sections.add(new CategorySection(engine, editableTypes, "compound") {
            @Override
            boolean isTypeInCategory(ITypeDescriptor descriptor) {
                return descriptor.isNode() && !hasPrefix(descriptor, prefix) && !descriptor.isMixin();
            }
        });
        sections.add(new CategorySection(engine, editableTypes, "custom") {
            @Override
            boolean isTypeInCategory(ITypeDescriptor descriptor) {
                return descriptor.isNode() && hasPrefix(descriptor, prefix) && !descriptor.isMixin();
            }
        });
        sections.add(new CategorySection(engine, editableTypes, "mixins") {
            @Override
            boolean isTypeInCategory(ITypeDescriptor descriptor) {
                return descriptor.isMixin();
            }
        });
        sections.add(new InheritedFieldSection(context, config));
        active = sections.get(0);

        fragment.add(new ListView<Section>("categories", sections) {

            @Override
            protected void populateItem(ListItem<Section> item) {
                final Section section = item.getModelObject();

                item.add(CssClass.append(new AbstractReadOnlyModel<String>() {
                    @Override
                    public String getObject() {
                        return active == section ? "category-selected" : StringUtils.EMPTY;
                    }
                }));

                MarkupContainer container = new WebMarkupContainer("container") {
                    @Override
                    public boolean isVisible() {
                        return active == section;
                    }
                };

                SectionView<?> templateView = section.createView("templates");
                container.add(templateView);
                item.add(container);

                AjaxLink<Void> link = new AjaxLink<Void>("link") {
                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        active = section;
                        redraw();
                    }
                };
                link.add(new Label("category", section.getTitleModel()));
                link.add(CssClass.append(new LoadableDetachableModel<String>() {
                    @Override
                    protected String load() {
                        return active == section ? "focus" : StringUtils.EMPTY;
                    }
                }));
                link.add(HippoIcon.fromSprite("categoryIcon", new AbstractReadOnlyModel<Icon>() {
                    @Override
                    public Icon getObject() {
                        return active == section ? Icon.CARET_DOWN : Icon.CARET_RIGHT;
                    }
                }, IconSize.S));
                item.add(link);
            }
        });
    }
}

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);//  www  . jav a  2s.  c  om

    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);
}

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

License:Apache License

protected Component createAddLink() {
    if (canAddItem()) {
        final AjaxLink link = new AjaxLink("add") {
            @Override/*from w w  w .  j a v a  2s  .c  o  m*/
            public void onClick(AjaxRequestTarget target) {
                target.focusComponent(this);
                NodeFieldPlugin.this.onAddItem(target);
            }
        };

        final Label addLink = new Label("add-label", getString("add-label"));
        link.add(addLink);

        final HippoIcon addIcon = HippoIcon.fromSprite("add-icon", Icon.PLUS);
        link.add(addIcon);

        return link;
    } else {
        return new Label("add").setVisible(false);
    }
}

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

License:Apache License

protected Component createAddLink() {
    if (canAddItem()) {
        final AjaxLink link = new AjaxLink("add") {
            @Override// w  w w . j  a  v  a  2 s . com
            public void onClick(AjaxRequestTarget target) {
                target.focusComponent(this);
                PropertyFieldPlugin.this.onAddItem(target);
            }
        };

        final Label addLink = new Label("add-label", getString("add-label"));
        link.add(addLink);

        final HippoIcon addIcon = HippoIcon.fromSprite("add-icon", Icon.PLUS);
        link.add(addIcon);

        return link;
    } else {
        return new Label("add").setVisible(false);
    }
}

From source file:org.hippoecm.frontend.editor.plugins.linkpicker.MirrorTemplatePlugin.java

License:Apache License

private void addOpenLink() {
    AjaxLink openLink = new AjaxLink("openLink") {

        @Override//  ww  w  . j  a  v a  2  s.  com
        public boolean isVisible() {
            return hasFilledDocbase();
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            open();
        }
    };
    openLink.add(new Label("value", getLocalizedNameModel()));
    openLink.add(TitleAttribute.set(getPathModel()));
    openLink.setOutputMarkupId(true);
    fragment.add(openLink);
}

From source file:org.hippoecm.frontend.editor.workflow.dialog.SelectLayoutStep.java

License:Apache License

public SelectLayoutStep(final IModel<String> layoutModel, final ILayoutProvider layouts) {
    super(new ResourceModel("select-layout-title"), new ResourceModel("select-layout-summary"));

    this.layoutProvider = layouts;

    setOutputMarkupId(true);/*from   w  ww.jav  a 2 s .  c  o m*/

    add(new IFormValidator() {
        @Override
        public FormComponent<?>[] getDependentFormComponents() {
            return new FormComponent<?>[0];
        }

        @Override
        public void validate(final Form<?> form) {
            if (layoutModel.getObject() == null) {
                error(getString("layoutstep.selection.empty"));
            } else {
                clearErrors();
            }
        }
    });

    add(new ListView<String>("layouts", (layoutProvider == null ? null : layoutProvider.getLayouts())) {

        @Override
        protected void populateItem(ListItem<String> item) {
            final String layout = item.getModelObject();
            AjaxLink<Void> link = new AjaxLink<Void>("link") {
                @Override
                public void onClick(AjaxRequestTarget target) {
                    clearErrors();
                    layoutModel.setObject(layout);
                    target.add(SelectLayoutStep.this);
                }
            };
            ILayoutDescriptor descriptor = layoutProvider.getDescriptor(layout);
            link.add(new CachingImage("preview", descriptor.getIcon()));
            link.add(new Label("layout", descriptor.getName()));
            item.add(link);

            item.add(CssClass.append((new LoadableDetachableModel<String>() {
                @Override
                protected String load() {
                    return layout.equals(layoutModel.getObject()) ? "selected" : StringUtils.EMPTY;
                }
            })));
        }
    });
}