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:org.hippoecm.frontend.plugins.gallery.GalleryWorkflowPlugin.java

License:Apache License

private Dialog createDialog() {
    List<String> galleryTypes = null;
    try {/*from  w w w.j  a v  a 2 s . c  o  m*/
        WorkflowManager manager = UserSession.get().getWorkflowManager();
        WorkflowDescriptorModel workflowDescriptorModel = (WorkflowDescriptorModel) GalleryWorkflowPlugin.this
                .getDefaultModel();
        GalleryWorkflow workflow = (GalleryWorkflow) manager.getWorkflow(workflowDescriptorModel.getObject());
        if (workflow == null) {
            GalleryWorkflowPlugin.log.error("No gallery workflow accessible");
        } else {
            galleryTypes = workflow.getGalleryTypes();
        }
    } catch (RepositoryException | RemoteException ex) {
        GalleryWorkflowPlugin.log.error(ex.getMessage(), ex);
    }

    Component typeComponent;
    if (galleryTypes != null && galleryTypes.size() > 1) {
        type = galleryTypes.get(0);
        typeComponent = new DropDownChoice<>("type", new PropertyModel<>(this, "type"), galleryTypes,
                new TypeChoiceRenderer(this)).setNullValid(false).setRequired(true);
        // needed to keep dropdown selection:
        typeComponent.add(new AjaxFormComponentUpdatingBehavior("onchange") {
            @Override
            protected void onUpdate(AjaxRequestTarget art) {
            }
        });
    } else if (galleryTypes != null && galleryTypes.size() == 1) {
        type = galleryTypes.get(0);
        typeComponent = new Label("type", type).setVisible(false);
    } else {
        type = null;
        typeComponent = new Label("type", "default").setVisible(false);
    }

    AbstractDialog dialog = newUploadDialog();
    dialog.add(typeComponent);
    return dialog;
}

From source file:org.hippoecm.frontend.plugins.yui.ajax.AjaxIndicatorBehavior.java

License:Apache License

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

From source file:org.hippoecm.frontend.plugins.yui.webapp.WebAppBehavior.java

License:Apache License

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

    component.add(new ProbeFlashBehavior() {

        @Override//from www. j a v  a  2 s . co m
        protected void handleFlash(FlashVersion flash) {
            WebAppBehavior.this.flash = flash;
        }
    });

}

From source file:org.hippoecm.frontend.service.render.AbstractRenderService.java

License:Apache License

public AbstractRenderService(IPluginContext context, IPluginConfig properties) {
    super("id", getPluginModel(context, properties));
    this.context = context;
    this.config = properties;

    setOutputMarkupId(true);/*from w w  w. j a va  2s  . c  om*/
    redraw = false;

    wicketId = "service.render";

    this.children = new LinkedHashMap<String, ExtensionPoint>();

    if (properties.getName() == null) {
        this.wicketServiceId = "service.wicket.id" + Session.get().nextSequenceValue();
    } else {
        this.wicketServiceId = properties.getName() + ".service.wicket.id";
    }

    if (properties.getString(MODEL_ID) != null) {
        modelReference = context.getService(properties.getString(MODEL_ID), IModelReference.class);
        if (modelReference != null) {
            context.registerService(new IObserver<IModelReference<?>>() {
                private static final long serialVersionUID = 1L;

                public IModelReference<?> getObservable() {
                    return modelReference;
                }

                public void onEvent(Iterator<? extends IEvent<IModelReference<?>>> event) {
                    updateModel(modelReference.getModel());
                }

            }, IObserver.class.getName());
        }
    } else {
        modelReference = null;
    }
    if (getDefaultModel() instanceof IObservable) {
        context.registerService(this, IObserver.class.getName());
    }

    String[] extensions = config.getStringArray(EXTENSIONS_ID);
    if (extensions != null) {
        for (String extension : extensions) {
            addExtensionPoint(extension);
        }
    }

    StringBuffer sb;

    cssClasses = null;
    String[] classes = config.getStringArray(CSS_ID);
    if (classes != null) {
        sb = null;
        for (String cssClass : classes) {
            if (sb == null) {
                sb = new StringBuffer(cssClass);
            } else {
                sb.append(" ").append(cssClass);
            }
        }
        if (sb != null) {
            cssClasses = sb.toString();
        }
    }

    String[] skins = config.getStringArray(SKIN_ID);
    if (skins != null) {
        for (String skin : skins) {
            final UrlResourceReference cssContributor = WebApplicationHelper
                    .createUniqueUrlResourceReference(Url.parse(skin));
            cssContributor.setContextRelative(true);
            add(new Behavior() {
                @Override
                public void renderHead(final Component component, final IHeaderResponse response) {
                    response.render(CssHeaderItem.forReference(cssContributor));
                }
            });
            context.registerService(cssContributor, IDialogService.class.getName());
        }
    }

    if (config.getString(FEEDBACK) != null) {
        context.registerService(new ContainerFeedbackMessageFilter(this), config.getString(FEEDBACK));
    } else {
        log.debug("No feedback id {} defined to register message filter", FEEDBACK);
    }

    if (config.getStringArray(BEHAVIOR) != null) {
        ServiceTracker<IBehaviorService> tracker = new ServiceTracker<IBehaviorService>(
                IBehaviorService.class) {
            private static final long serialVersionUID = 1L;

            @Override
            public void onServiceAdded(IBehaviorService service, String name) {
                String path = service.getComponentPath();
                if (path != null) {
                    Component component = get(path);
                    if (component != null) {
                        component.add(service.getBehavior());
                    } else {
                        log.warn("No component found under {}", path);
                    }
                } else {
                    add(service.getBehavior());
                }
            }

            @Override
            public void onRemoveService(IBehaviorService service, String name) {
                String path = service.getComponentPath();
                if (path != null) {
                    Component component = get(service.getComponentPath());
                    if (component != null) {
                        component.remove(service.getBehavior());
                    }
                } else {
                    remove(service.getBehavior());
                }
            }
        };

        for (String name : config.getStringArray(BEHAVIOR)) {
            context.registerTracker(tracker, name);
        }
    }
    setVisible(config.getAsBoolean(VISIBLE, true));
    context.registerService(this, config.getString("wicket.id"));
}

From source file:org.hippoecm.frontend.translation.components.folder.service.SiblingLocator.java

License:Apache License

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

From source file:org.isisaddons.wicket.wizard.cpt.ui.WizardPropertiesForm.java

License:Apache License

private void addPropertyToForm(final EntityModel entityModel, final ObjectAssociation association,
        final WebMarkupContainer container) {
    final OneToOneAssociation otoa = (OneToOneAssociation) association;
    final PropertyMemento pm = new PropertyMemento(otoa);

    final ScalarModel scalarModel = entityModel.getPropertyModel(pm);
    final Component component = getComponentFactoryRegistry().addOrReplaceComponent(container, ID_PROPERTY,
            ComponentType.SCALAR_NAME_AND_VALUE, scalarModel);

    if (!renderedFirstField) {
        component.add(new CssClassAppender("first-field"));
        renderedFirstField = true;//  ww w  . j  a  v  a 2 s  . c om
    }
}

From source file:org.isisaddons.wicket.wizard.cpt.ui.WizardPropertiesForm.java

License:Apache License

private static void addClassForSpan(final Component component, final int numGridCols) {
    component.add(new CssClassAppender("span" + numGridCols));
}

From source file:org.obiba.onyx.wicket.reusable.AddCommentWindow.java

License:Open Source License

@Override
public AddCommentWindow setContent(Component component) {
    component.add(
            new AttributeModifier("class", true, new Model<String>("obiba-content add-comment-panel-content")));
    super.setContent(component);
    return this;
}

From source file:org.obiba.onyx.wicket.reusable.FeedbackWindow.java

License:Open Source License

@Override
public FeedbackWindow setContent(Component component) {
    FeedbackPanel feedbackPanel = (FeedbackPanel) component;
    FeedbackMessage feedbackMessage = (feedbackPanel.getFeedbackMessagesModel().getObject()).get(0);

    component.add(new AttributeModifier("class", true, new Model<String>("feedback")));

    if (feedbackMessage != null) {
        String messageLevel = feedbackMessage.getLevelAsString();
        setType(Dialog.Type.valueOf(messageLevel));
        setTitle(new StringResourceModel("Dialog." + messageLevel.toLowerCase(), this, null));
    }//from   w  ww. ja  v a2s  .  c  o  m
    return (FeedbackWindow) super.setContent(component);
}

From source file:org.objetdirect.wickext.core.commons.WickextPluginInstantiationListener.java

License:Open Source License

/**
 * Imports needed resources and outputs JavaScript code for the 
 * instantiated component.//from   w  w  w.ja  v  a 2s.  c o m
 */
public void onInstantiation(final Component component) {
    if (component instanceof WickextPlugin) {
        // manages the instantiated plugin (e.g. imports linked
        // resources and appends the JavaScript statements)
        manage(component);
        // if it's a UI component, we import jquery ui core libs
        // and css
        // resource are imported has header contributors
        final WickextPlugin wickextPlugin = (WickextPlugin) component;
        manageUi(component, wickextPlugin);
        component.add(new HeaderContributor((wickextPlugin).getHeaderContribution()));
        final JsQuery jsQuery = new JsQuery(component);
        component.add(new HeaderContributor(new IHeaderContributor() {

            private static final long serialVersionUID = 1L;

            public void renderHead(IHeaderResponse response) {
                jsQuery.setStatement(wickextPlugin.statement());
                jsQuery.renderHead(response);
            }

        }));
    }
    //      List<IBehavior> behaviors = component.getBehaviors();
    //      for (IBehavior behavior : behaviors) {
    //         if (behavior instanceof WickextPlugin) {
    //            manage(component);
    //            manageUi(component, (WickextPlugin) behavior);
    //            component.add(new HeaderContributor(((WickextPlugin) behavior).getHeaderContribution()));
    //            JSQuery componentJs = new JSQuery(component);
    //            component.add(new HeaderContributor(componentJs));            
    //         }
    //      }
}