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:nl.ru.cmbi.vase.web.panel.align.AlignmentTablePanel.java

License:Apache License

public AlignmentTablePanel(String id, final AlignmentDisplayPanel alignmentPanel, final VASEDataObject data) {
    super(id);/*w  ww  .j  av a 2  s.  c o m*/

    final TableData tableData = data.getTable();
    final List<ColumnInfo> columnInfos = tableData.getVisibleColumnInfos();

    add(new ListView<ColumnInfo>("header-cell", columnInfos) {

        @Override
        protected void populateItem(ListItem<ColumnInfo> item) {

            ColumnInfo ci = item.getModelObject();

            WebMarkupContainer headerDiv = new WebMarkupContainer("header-div");
            headerDiv.add(new Label("header-title", ci.getTitle()));

            Component image = new WebMarkupContainer("header-toggle-image");
            image.add(new AttributeAppender("class", new Model(tableCellClassPrefix + ci.getId()), " "));
            headerDiv.add(image);

            item.add(headerDiv);

            headerDiv.add(new AttributeModifier("onclick", String.format("orderTableBy('%s');", ci.getId())));
        }
    });

    add(new ListView("rows", Utils.listRange(0, tableData.getNumberOfRows())) {

        @Override
        protected void populateItem(ListItem item) {

            final Integer rowIndex = (Integer) item.getModelObject(),
                    residueNumber = tableData.getResidueNumber(rowIndex);

            item.add(new AttributeModifier("onclick", String.format("toggleColumn('%s');",
                    alignmentPanel.getResidueNumberClassRepresentation(residueNumber))));

            item.add(new AttributeAppender("class",
                    new Model(alignmentPanel.getColumnClassRepresentation(residueNumber)), " "));

            item.add(new ListView<ColumnInfo>("cells", columnInfos) {

                @Override
                protected void populateItem(ListItem<ColumnInfo> item) {

                    ColumnInfo ci = item.getModelObject();
                    String value = tableData.getValueAsString(ci.getId(), rowIndex);

                    Component cellText = new Label("cell-text", value);

                    cellText.add(
                            new AttributeAppender("class", new Model(tableCellClassPrefix + ci.getId()), " "));

                    item.add(cellText);
                }
            });
        }

    });
}

From source file:nl.ru.cmbi.vase.web.panel.ScatterPlotPanel.java

License:Apache License

public ScatterPlotPanel(String id,

        final ScatterPlotOptions options) {

    super(id);//  ww w . ja v a  2 s.co m

    // Add extra space for titles:
    if (!options.getXAxisTitle().isEmpty())
        pixMargeLeft = 60;
    if (!options.getYAxisTitle().isEmpty())
        pixMargeDown = 50;

    double plotPixWidth = options.getImagePixWidth() - pixMargeLeft - pixMargeRight,
            plotPixHeight = options.getImagePixHeight() - pixMargeDown - pixMargeUp;

    final double // data-to-pixels ratio:
    pixXScaling = plotPixWidth / (options.getMaxX() - options.getMinX()),
            pixYScaling = plotPixHeight / (options.getMaxY() - options.getMinY()),

            // position of the origin in pixels:
            pixOriginYPos = options.getImagePixHeight() + options.getMinY() * pixYScaling,
            pixOriginXPos = -options.getMinX() * pixXScaling;

    WebMarkupContainer svg = new WebMarkupContainer("svg");
    svg.add(new AttributeModifier("width", String.valueOf(options.getImagePixWidth())));
    svg.add(new AttributeModifier("height", String.valueOf(options.getImagePixHeight())));
    add(svg);

    // move everything to the right and up to make it fit in:
    // (locale must be english for the svg transform attributes)
    WebMarkupContainer transformGroup = new WebMarkupContainer("transformgroup");
    transformGroup.add(new AttributeModifier("transform",
            String.format(Locale.ENGLISH, "translate(%.1f %.1f)", pixMargeLeft, -pixMargeDown)));
    svg.add(transformGroup);

    double yAxisXpos = pixOriginXPos, xAxisYpos = pixOriginYPos;

    Component xAxis = new Label("x-axis");
    xAxis.add(new AttributeModifier("x1", "0"));
    xAxis.add(new AttributeModifier("x2", String.valueOf(plotPixWidth)));
    xAxis.add(new AttributeModifier("y1", String.valueOf(xAxisYpos)));
    xAxis.add(new AttributeModifier("y2", String.valueOf(xAxisYpos)));
    transformGroup.add(xAxis);

    WebMarkupContainer xTitle = new WebMarkupContainer("x-title");
    xTitle.add(new Label("x-text", options.getXAxisTitle()));
    xTitle.add(new AttributeModifier("transform", String.format(Locale.ENGLISH, "translate(%.1f %.1f)",
            pixOriginXPos + pixTitleSpacing, pixOriginYPos + pixTitleSpacing)));
    transformGroup.add(xTitle);

    Component yAxis = new Label("y-axis");
    yAxis.add(new AttributeModifier("x1", String.valueOf(yAxisXpos)));
    yAxis.add(new AttributeModifier("x2", String.valueOf(yAxisXpos)));
    yAxis.add(new AttributeModifier("y1", String.valueOf(pixOriginYPos - plotPixHeight)));
    yAxis.add(new AttributeModifier("y2", String.valueOf(pixOriginYPos)));
    transformGroup.add(yAxis);

    WebMarkupContainer yTitle = new WebMarkupContainer("y-title");
    yTitle.add(new Label("y-text", options.getYAxisTitle()));
    yTitle.add(
            new AttributeModifier("transform", String.format(Locale.ENGLISH, "translate(%.1f %.1f) rotate(-90)",
                    pixOriginXPos - pixTitleSpacing, pixOriginYPos - pixTitleSpacing)));
    transformGroup.add(yTitle);

    ListView<Integer> dots = new ListView<Integer>("dots", Utils.listRange(0, options.getXValues().size())) {

        @Override
        protected void populateItem(ListItem item) {

            final Integer index = (Integer) item.getModelObject();

            double x = options.getXValues().get(index).doubleValue(),
                    y = options.getYValues().get(index).doubleValue(),

                    pxX = x * pixXScaling + pixOriginXPos, pxY = pixOriginYPos - y * pixYScaling;

            DotComponent dot = new DotComponent("dot", x, y, index);

            dot.add(new AttributeModifier("cx", String.valueOf(pxX)));
            dot.add(new AttributeModifier("cy", String.valueOf(pxY)));

            dot.setTooltip(String.format("%s:%s, %s:%s",

                    options.getXAxisTitle(), ScatterPlotPanel.this.xScaleRepresentation(dot.getXValue()),
                    options.getYAxisTitle(), ScatterPlotPanel.this.yScaleRepresentation(dot.getYValue())));

            ScatterPlotPanel.this.onDotCreate(dot);
            item.add(dot);
        }
    };
    transformGroup.add(dots);

    ListView<Double> xScales = new ListView<Double>("xscale",
            getScalePositions(options.getMinX(), options.getMaxX(), options.getXStepSize())) {

        @Override
        protected void populateItem(ListItem item) {

            Double x = (Double) item.getModelObject(),

                    pxX = x * pixXScaling + pixOriginXPos;

            item.add(new AttributeModifier("transform",
                    String.format(Locale.ENGLISH, "translate(%.1f %.1f)", pxX, pixOriginYPos)));

            item.add(new Label("xscale-number", ScatterPlotPanel.this.xScaleRepresentation(x)));
        }
    };
    transformGroup.add(xScales);

    ListView<Double> yScales = new ListView<Double>("yscale",
            getScalePositions(options.getMinY(), options.getMaxY(), options.getYStepSize())) {

        @Override
        protected void populateItem(ListItem item) {

            Double y = (Double) item.getModelObject(),

                    pxY = pixOriginYPos - y * pixYScaling;

            item.add(new AttributeModifier("transform",
                    String.format(Locale.ENGLISH, "translate(%.1f %.1f)", pixOriginXPos, pxY)));

            item.add(new Label("yscale-number", ScatterPlotPanel.this.yScaleRepresentation(y)));
        }
    };
    transformGroup.add(yScales);
}

From source file:ontopoly.jquery.DraggableBehavior.java

License:Apache License

@Override
protected void onBind() {
    super.onBind();
    Component c = getComponent();
    c.setOutputMarkupId(true);//from   ww  w . j av a  2  s.c o m
    c.add(new AttributeAppender("class", new Model<String>("dg_" + id), " "));
}

From source file:ontopoly.jquery.DroppableBehavior.java

License:Apache License

@Override
protected void onBind() {
    super.onBind();
    Component c = getComponent();
    c.setOutputMarkupId(true);// w w w .j  a  va  2s.c  o m
    c.add(new AttributeAppender("class", new Model<String>("do_" + id), " "));
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

@Subscribe
public void playCardFromHand(final AjaxRequestTarget target, final PlayCardFromHandCometChannel event) {
    final MagicCard mc = event.getMagicCard();

    Component me;

    if (event.getPlayerName().equals(this.session.getPlayer().getName())) {
        me = this.parentPlaceholder;
    } else {/*from ww  w  .j  a va 2s. c  om*/
        me = this.opponentParentPlaceholder;
    }

    me.add(new DisplayNoneBehavior());
    target.prependJavaScript("notify|jQuery('#" + me.getMarkupId() + "').fadeOut(500, notify);");

    BattlefieldService.updateCardsAndRestoreStateInBattlefield(target, this.persistenceService,
            event.getGameId(), mc, true);
    target.appendJavaScript(BattlefieldService.REACTIVATE_BATTLEFIELD_JAVASCRIPT);
    target.appendJavaScript(
            "jQuery('#" + me.getMarkupId() + "').fadeIn(500); jQuery('#cardInBattlefieldContextMenu"
                    + mc.getUuidObject().toString().replace("-", "_")
                    + "').popmenu({ 'background': 'black', 'focusColor': '#BBBBBB' }); ");
}

From source file:org.alienlabs.hatchetharry.view.page.HomePage.java

License:Open Source License

@Subscribe
public void reorderCardsInBattlefield(final AjaxRequestTarget target, final ReorderCardCometChannel event) {
    HomePage.LOGGER.info("reorderCardsInBattlefield");

    final List<MagicCard> allCardsAndTokensInBattlefieldForAGameAndAPlayer = this.persistenceService
            .getAllCardsAndTokensInBattlefieldForAGameAndAPlayer(event.getGameId(), event.getPlayerId(),
                    event.getDeckId());/*w  ww  . jav  a2  s .c  om*/

    HomePage.LOGGER.info("requesting side: " + event.getPlayerSide() + ", this side: "
            + this.session.getPlayer().getSide().getSideName());

    Component me;

    if (event.getPlayerSide().equals(this.session.getPlayer().getSide().getSideName())) {
        final WebMarkupContainer listViewForSide1 = this
                .generateCardListViewForSide1(allCardsAndTokensInBattlefieldForAGameAndAPlayer);
        me = this.parentPlaceholder;
        me.add(new DisplayNoneBehavior());
        target.prependJavaScript("notify|jQuery('#" + me.getMarkupId() + "').fadeOut(250, notify);");
        target.add(listViewForSide1);
    } else {
        final WebMarkupContainer listViewForSide2 = this
                .generateCardListViewForSide2(allCardsAndTokensInBattlefieldForAGameAndAPlayer);
        me = this.opponentParentPlaceholder;
        me.add(new DisplayNoneBehavior());
        target.prependJavaScript("notify|jQuery('#" + me.getMarkupId() + "').fadeOut(250, notify);");
        target.add(listViewForSide2);
    }

    BattlefieldService.updateCardsAndRestoreStateInBattlefield(target, this.persistenceService,
            event.getGameId(), null, false);

    target.appendJavaScript("jQuery('#" + me.getMarkupId()
            + "').fadeIn(250); jQuery('.cardInBattlefieldContextMenu').each(function(index, value) { jQuery(this).popmenu({ 'background': 'black', 'focusColor': '#BBBBBB' }); }); ");
}

From source file:org.apache.isis.viewer.wicket.ui.components.actionmenu.serviceactions.CssMenuItem.java

License:Apache License

private void addCssClassAttributesIfRequired(final Component linkComponent) {
    if (!hasSubMenuItems()) {
        return;//from  w  w w.  ja  v  a  2 s .co  m
    }
    if (this.hasParent()) {
        linkComponent.add(new CssClassAppender("parent"));
    } else {
        linkComponent.add(new CssClassAppender("top-parent"));
    }
}

From source file:org.apache.isis.viewer.wicket.ui.components.collectioncontents.multiple.CollectionContentsMultipleViewsPanel.java

License:Apache License

private void addUnderlyingViews() {
    final EntityCollectionModel model = getModel();

    final List<ComponentFactory> componentFactories = selectorHelper.getComponentFactories();

    final CollectionSelectorPanel selectorDropdownPanelIfAny = CollectionSelectorProvider.Util
            .getCollectionSelectorProvider(this);
    final String selected;
    if (selectorDropdownPanelIfAny != null) {
        selected = selectorHelper.honourViewHintElseDefault(selectorDropdownPanelIfAny);
    } else {//from ww  w .j  a va 2  s .  c  o  m
        selected = componentFactories.get(0).getName();
    }

    // create all, hide the one not selected
    int i = 0;
    int selectedIdx = 0;
    underlyingViews = new Component[MAX_NUM_UNDERLYING_VIEWS];
    final EntityCollectionModel emptyModel = model.asDummy();
    for (ComponentFactory componentFactory : componentFactories) {
        final String underlyingId = underlyingIdPrefix + "-" + i;

        final boolean isSelected = selected.equals(componentFactory.getName());
        final Component underlyingView = componentFactory.createComponent(underlyingId,
                isSelected ? model : emptyModel);
        if (isSelected) {
            selectedIdx = i;
        }
        underlyingViews[i++] = underlyingView;
        this.addOrReplace(underlyingView);
    }

    // hide any unused placeholders
    while (i < MAX_NUM_UNDERLYING_VIEWS) {
        String underlyingId = underlyingIdPrefix + "-" + i;
        permanentlyHide(underlyingId);
        i++;
    }

    this.setOutputMarkupId(true);

    for (i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) {
        Component component = underlyingViews[i];
        if (component != null) {
            if (i != selectedIdx) {
                component.add(new CssClassAppender(INVISIBLE_CLASS));
            } else {
                selectedComponent = component;
            }
        }
    }
}

From source file:org.apache.isis.viewer.wicket.ui.components.collectioncontents.multiple.CollectionContentsMultipleViewsPanel.java

License:Apache License

protected static void applyCssVisibility(final Component component, final boolean visible) {
    if (component == null) {
        return;//from ww  w .ja  v  a  2s .co  m
    }
    AttributeModifier modifier = visible ? new CssClassRemover(INVISIBLE_CLASS)
            : new CssClassAppender(INVISIBLE_CLASS);
    component.add(modifier);
}

From source file:org.apache.isis.viewer.wicket.ui.components.entity.selector.links.EntityLinksSelectorPanel.java

License:Apache License

private void addUnderlyingViews(final String underlyingIdPrefix, final EntityModel model,
        final ComponentFactory factory) {
    final List<ComponentFactory> componentFactories = findOtherComponentFactories(model, factory);

    final int selected = honourViewHintElseDefault(componentFactories, model);

    final EntityLinksSelectorPanel selectorPanel = this;

    // create all, hide the one not selected
    final Component[] underlyingViews = new Component[MAX_NUM_UNDERLYING_VIEWS];
    int i = 0;/*from  w ww. j  av  a 2 s. c o  m*/
    final EntityModel emptyModel = dummyOf(model);
    for (ComponentFactory componentFactory : componentFactories) {
        final String underlyingId = underlyingIdPrefix + "-" + i;

        Component underlyingView = componentFactory.createComponent(underlyingId,
                i == selected ? model : emptyModel);
        underlyingViews[i++] = underlyingView;
        selectorPanel.addOrReplace(underlyingView);
    }

    // hide any unused placeholders
    while (i < MAX_NUM_UNDERLYING_VIEWS) {
        String underlyingId = underlyingIdPrefix + "-" + i;
        permanentlyHide(underlyingId);
        i++;
    }

    // selector
    if (componentFactories.size() <= 1) {
        permanentlyHide(ID_VIEWS);
    } else {
        final Model<ComponentFactory> componentFactoryModel = new Model<>();

        selectorPanel.selectedComponentFactory = componentFactories.get(selected);
        componentFactoryModel.setObject(selectorPanel.selectedComponentFactory);

        final WebMarkupContainer views = new WebMarkupContainer(ID_VIEWS);

        final Label viewButtonTitle = new Label(ID_VIEW_BUTTON_TITLE, "Hidden");
        views.addOrReplace(viewButtonTitle);

        final Label viewButtonIcon = new Label(ID_VIEW_BUTTON_ICON, "");
        views.addOrReplace(viewButtonIcon);

        final WebMarkupContainer container = new WebMarkupContainer(ID_VIEW_LIST);

        views.addOrReplace(container);
        views.setOutputMarkupId(true);

        this.setOutputMarkupId(true);

        final ListView<ComponentFactory> listView = new ListView<ComponentFactory>(ID_VIEW_ITEM,
                componentFactories) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void populateItem(ListItem<ComponentFactory> item) {

                final int underlyingViewNum = item.getIndex();

                final ComponentFactory componentFactory = item.getModelObject();
                final AbstractLink link = new AjaxLink<Void>(ID_VIEW_LINK) {
                    private static final long serialVersionUID = 1L;

                    @Override
                    public void onClick(AjaxRequestTarget target) {
                        EntityLinksSelectorPanel linksSelectorPanel = EntityLinksSelectorPanel.this;
                        linksSelectorPanel.setViewHintAndBroadcast(underlyingViewNum, target);

                        final EntityModel dummyModel = dummyOf(model);
                        for (int i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) {
                            final Component component = underlyingViews[i];
                            if (component == null) {
                                continue;
                            }
                            final boolean isSelected = i == underlyingViewNum;
                            applyCssVisibility(component, isSelected);
                            component.setDefaultModel(isSelected ? model : dummyModel);
                        }

                        selectorPanel.selectedComponentFactory = componentFactory;
                        selectorPanel.selectedComponent = underlyingViews[underlyingViewNum];
                        selectorPanel.onSelect(target);
                        target.add(selectorPanel, views);
                    }

                    @Override
                    protected void onComponentTag(ComponentTag tag) {
                        super.onComponentTag(tag);
                        Buttons.fixDisabledState(this, tag);
                    }
                };

                IModel<String> title = nameFor(componentFactory);
                Label viewItemTitleLabel = new Label(ID_VIEW_ITEM_TITLE, title);
                link.add(viewItemTitleLabel);

                Label viewItemIcon = new Label(ID_VIEW_ITEM_ICON, "");
                link.add(viewItemIcon);

                boolean isEnabled = componentFactory != selectorPanel.selectedComponentFactory;
                if (!isEnabled) {
                    viewButtonTitle.setDefaultModel(title);
                    IModel<String> cssClass = cssClassFor(componentFactory, viewButtonIcon);
                    viewButtonIcon
                            .add(AttributeModifier.replace("class", "ViewLinkItem " + cssClass.getObject()));
                    link.setVisible(false);
                } else {
                    IModel<String> cssClass = cssClassFor(componentFactory, viewItemIcon);
                    viewItemIcon.add(new CssClassAppender(cssClass));
                }

                item.add(link);
            }

            private IModel<String> cssClassFor(final ComponentFactory componentFactory, Label viewIcon) {
                IModel<String> cssClass = null;
                if (componentFactory instanceof CollectionContentsAsFactory) {
                    CollectionContentsAsFactory collectionContentsAsFactory = (CollectionContentsAsFactory) componentFactory;
                    cssClass = collectionContentsAsFactory.getCssClass();
                    viewIcon.setDefaultModelObject("");
                    viewIcon.setEscapeModelStrings(true);
                }
                if (cssClass == null) {
                    String name = componentFactory.getName();
                    cssClass = Model.of(StringExtensions.asLowerDashed(name));
                    // Small hack: if there is no specific CSS class then we assume that background-image is used
                    // the span.ViewItemLink should have some content to show it
                    // FIX: find a way to do this with CSS (width and height don't seems to help)
                    viewIcon.setDefaultModelObject("&#160;&#160;&#160;&#160;&#160;");
                    viewIcon.setEscapeModelStrings(false);
                }
                return cssClass;
            }

            private IModel<String> nameFor(final ComponentFactory componentFactory) {
                IModel<String> name = null;
                if (componentFactory instanceof CollectionContentsAsFactory) {
                    CollectionContentsAsFactory collectionContentsAsFactory = (CollectionContentsAsFactory) componentFactory;
                    name = collectionContentsAsFactory.getTitleLabel();
                }
                if (name == null) {
                    name = Model.of(componentFactory.getName());
                }
                return name;
            }
        };
        container.add(listView);
        addOrReplace(views);
    }

    for (i = 0; i < MAX_NUM_UNDERLYING_VIEWS; i++) {
        Component component = underlyingViews[i];
        if (component != null) {
            if (i != selected) {
                component.add(new CssClassAppender(INVISIBLE_CLASS));
            } else {
                selectedComponent = component;
            }
        }
    }
}