Example usage for org.apache.wicket Component getBehaviors

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

Introduction

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

Prototype

public <M extends Behavior> List<M> getBehaviors(Class<M> type) 

Source Link

Document

Gets the subset of the currently coupled Behavior s that are of the provided type as an unmodifiable list.

Usage

From source file:com.comcast.cdn.traffic_control.traffic_monitor.wicket.behaviors.MultiUpdatingTimerBehavior.java

License:Apache License

protected void onPostProcessTarget(final AjaxRequestTarget target) {
    final JSONObject jo = new JSONObject();
    //      final StringBuilder sb = new StringBuilder();
    //      sb.append("[");
    for (Component c : components) {
        //         sb.append("\"").append(c.getMarkupId()).append("\",");
        final JSONObject jo2 = new JSONObject();
        try {//from   w  w w  .  java  2s. c  o m
            boolean hasB = false;
            final List<UpdatingAttributeAppender> blist = c.getBehaviors(UpdatingAttributeAppender.class);
            for (UpdatingAttributeAppender b : blist) {
                jo2.put(b.getAttribute(), b.getAttributeValue(c));
                hasB = true;
            }
            if (!hasB) {
                jo2.put("v", String.valueOf(c.getDefaultModel().getObject()));
            }
            jo.put(c.getMarkupId(), jo2);
        } catch (JSONException e) {
            LOGGER.warn(e, e);
        }
    }
    target.appendJavaScript("updateAjaxComponents(" + jo.toString() + ");");
}

From source file:com.google.code.jqwicket.JQComponentOnBeforeRenderListener.java

License:Apache License

private Collection<JQBehavior> findJQueryBehaviors(Component component) {
    return new LinkedHashSet<JQBehavior>(component.getBehaviors(JQBehavior.class));
}

From source file:com.googlecode.wickedcharts.wicket6.highcharts.features.livedata.LiveDataProcessor.java

License:Apache License

private LiveDataAjaxBehavior getBehaviorFromComponent(final Component component, final LiveDataSeries series) {
    List<LiveDataAjaxBehavior> behaviors = component.getBehaviors(LiveDataAjaxBehavior.class);

    for (LiveDataAjaxBehavior behavior : behaviors) {
        if (behavior.getSeries().getWickedChartsId().equals(series.getWickedChartsId())) {
            behavior.reset();//  w ww  .jav  a2  s. co  m
            return behavior;
        }
    }

    return null;
}

From source file:com.googlecode.wicket.jquery.ui.interaction.draggable.DraggableBehavior.java

License:Apache License

/**
 * Gets a new {@link DroppableBehavior} visitor.<br/>
 * This {@link IVisitor} is responsible for register the {@link DroppableBehavior} to this {@link DraggableBehavior}
 *
 * @return a {@link IVisitor}//from  w w w  .j  av  a 2  s. c  o  m
 */
private IVisitor<Component, ?> newDroppableBehaviorVisitor() {
    return new IVisitor<Component, Void>() {

        @Override
        public void component(Component component, IVisit<Void> visit) {
            for (DroppableBehavior behavior : component.getBehaviors(DroppableBehavior.class)) {
                behavior.setDraggable(DraggableBehavior.this.component);
            }
        }
    };
}

From source file:com.googlecode.wicket.jquery.ui.JQueryDestroyListener.java

License:Apache License

/**
 * Gets a new {@link IVisitor} that will be used by {@link #onBeforeRespond(Map, AjaxRequestTarget)}
 *
 * @return the new {@code IVisitor}//from   ww w.  j  av  a 2  s  .  c  o m
 */
protected IVisitor<Component, Object> newBeforeRespondVisitor(final AjaxRequestTarget target) {
    return new IVisitor<Component, Object>() {

        @Override
        public void component(Component component, IVisit<Object> visit) {
            for (JQueryUIBehavior behavior : component.getBehaviors(JQueryUIBehavior.class)) {
                behavior.destroy(target);
            }
        }
    };
}

From source file:com.googlecode.wicket.jquery.ui.kendo.datatable.DataTableBehavior.java

License:Apache License

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

    // source ///*from   w ww .j  ava2s.c o  m*/
    Options source = new Options();
    source.set("type", Options.asString("jsonp"));
    source.set("pageSize", this.getRowCount());
    source.set("serverPaging", true);
    source.set("transport", String.format("{ \"read\": \"%s\" }", this.getSourceCallbackUrl()));
    source.set("schema", "{ \"data\": \"results\", \"total\": \"__count\" }");

    this.setOption("dataSource", source);

    // columns //
    StringBuilder builder = new StringBuilder("[ ");

    {
        List<? extends IColumn<?>> columns = this.getColumns();

        for (int i = 0; i < columns.size(); i++) {
            IColumn<?> column = columns.get(i);

            if (i > 0) {
                builder.append(", ");
            }

            if (column instanceof CommandsColumn) {
                builder.append("{ ");
                builder.append(column.toString()); //toJSON(component)

                // buttons //
                builder.append(", ");
                builder.append(Options.QUOTE).append("command").append(Options.QUOTE).append(": ");
                builder.append("[ ");

                int n = 0;
                for (ButtonAjaxBehavior behavior : component.getBehaviors(ButtonAjaxBehavior.class)) {
                    ColumnButton button = behavior.getButton();

                    if (n++ > 0) {
                        builder.append(", ");
                    }
                    builder.append("{ ");
                    builder.append("'name': '").append(button.getMarkupId()).append("', ");
                    builder.append("'text': '").append(button.toString()).append("', ");
                    //               builder.append("'className': '").append(button.toString()).append("', ");
                    builder.append("\n'click': ").append(behavior.getCallbackFunction());
                    builder.append(" }");
                }

                builder.append(" ]");
                builder.append(" }");
            } else {
                builder.append("{ ").append(column.toString()).append(" }"); //toJSON
            }
        }
    }

    builder.append(" ]");

    this.setOption("columns", builder.toString());
}

From source file:com.googlecode.wicket.jquery.ui.widget.dialog.DialogBehavior.java

License:Apache License

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

    if (this.onDefaultClose != null) {
        this.setOption("close", this.onDefaultClose.getCallbackFunction());
    }/*  www .  j a va 2s .c  o m*/

    // buttons events //
    StringBuffer buttons = new StringBuffer("[ ");

    int index = 0;
    for (ButtonAjaxBehavior behavior : component.getBehaviors(ButtonAjaxBehavior.class)) {
        DialogButton button = behavior.getButton();

        if (index++ > 0) {
            buttons.append(", ");
        }
        buttons.append("{");
        buttons.append("'id': '").append(button.getMarkupId()).append("', ");
        buttons.append("'text': '").append(button.toString()).append("', ");
        if (!button.isEnabled()) {
            buttons.append("'disabled': true, ");
        }
        if (button.getIcon() != null) {
            buttons.append("icons: { primary: '").append(button.getIcon()).append("' }, ");
        }
        buttons.append("'click': function() { ").append(behavior.getCallbackScript()).append(" }");
        buttons.append("}");
    }

    buttons.append(" ]");

    this.setOption("buttons", buttons);
}

From source file:com.googlecode.wicket.kendo.ui.datatable.DataTableBehavior.java

License:Apache License

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

    List<IColumn> columns = this.columns.getObject();

    // this.setOption("edit", this.onEditAjaxBehavior.getCallbackFunction());
    this.setOption("cancel", this.onCancelAjaxBehavior.getCallbackFunction());

    // toolbar //
    if (this.hasVisibleToolbarButtons()) {
        this.setOption("toolbar", this.getVisibleToolbarButtons());
    }/* ww w .j  a  va 2s. c o  m*/

    // columns //
    this.setOption("columns",
            this.getColumnsAsString(columns, component.getBehaviors(CommandAjaxBehavior.class)));

    // schema //
    Options schema = new Options();
    schema.set("data", Options.asString("results"));
    schema.set("total", Options.asString("__count"));
    schema.set("model", this.newSchemaModelOptions(columns));

    // data-source //
    this.onConfigure(this.dataSource);
    this.setOption("dataSource", this.dataSource.getName());

    this.dataSource.set("pageSize", this.getRowCount());
    this.dataSource.set("serverPaging", true);
    this.dataSource.set("serverSorting", true);
    this.dataSource.set("serverFiltering", true);
    this.dataSource.set("schema", schema);
    this.dataSource.setTransportRead(this.getReadCallbackFunction());
    this.dataSource.setTransportCreate(this.onCreateAjaxBehavior.getCallbackFunction());
    this.dataSource.setTransportUpdate(this.onUpdateAjaxBehavior.getCallbackFunction());
    this.dataSource.setTransportDelete(this.onDeleteAjaxBehavior.getCallbackFunction());

    // ajax //
    for (ToolbarAjaxBehavior behavior : component.getBehaviors(ToolbarAjaxBehavior.class)) {
        String selector = String.format("%s .k-grid-toolbar .k-grid-%s", this.getSelector(),
                behavior.getButtonName());

        this.off(selector, "click");
        this.on(selector, "click", behavior.getCallbackFunction());
    }
}

From source file:com.googlecode.wicket.kendo.ui.KendoDestroyListener.java

License:Apache License

/**
 * Gets a new {@link IVisitor} that will be used by {@link #onBeforeRespond(Map, AjaxRequestTarget)}
 *
 * @return the new {@code IVisitor}//from w  w  w  .  j  ava2 s .c o  m
 */
protected IVisitor<Component, Object> newBeforeRespondVisitor(final AjaxRequestTarget target) {
    return new IVisitor<Component, Object>() {

        @Override
        public void component(Component component, IVisit<Object> visit) {
            for (KendoUIBehavior behavior : component.getBehaviors(KendoUIBehavior.class)) {
                behavior.destroy(target);
            }
        }
    };
}

From source file:com.pushinginertia.wicket.core.util.ComponentUtils.java

License:Open Source License

/**
 * Identifies if a component has had the given {@link AttributeModifier} added to it.
 * @param callingComponent component making the call
 * @param modifier modifier to search for
 * @return true if the modifier has been added to the component
 *//*  w w  w . j  a v a2s.  c om*/
public static boolean isAttributeModifierAdded(final Component callingComponent,
        final AttributeModifier modifier) {
    ValidateAs.notNull(callingComponent, "callingComponent");
    ValidateAs.notNull(modifier, "modifier");

    final List<AttributeModifier> behaviorList = callingComponent.getBehaviors(AttributeModifier.class);
    final String attribute = modifier.getAttribute();

    for (final AttributeModifier behavior : behaviorList) {
        if (attribute.equals(behavior.getAttribute())) {
            return modifier.equals(behavior);
        }
    }
    return false;
}