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

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

Introduction

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

Prototype

public AjaxLink(final String id, final IModel<T> model) 

Source Link

Document

Construct.

Usage

From source file:com.axway.ats.testexplorer.pages.testcase.attachments.AttachmentsPanel.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
public AttachmentsPanel(String id, final String testcaseId, final PageParameters parameters) {
    super(id);//www  .  jav  a 2 s .  c om

    form = new Form<Object>("form");
    buttonPanel = new WebMarkupContainer("buttonPanel");
    noButtonPanel = new WebMarkupContainer("noButtonPanel");
    fileContentContainer = new TextArea<String>("textFile", new Model<String>(""));
    imageContainer = new WebMarkupContainer("imageFile");
    fileContentInfo = new Label("fileContentInfo", new Model<String>(""));
    buttons = getAllAttachedFiles(testcaseId);

    form.add(fileContentContainer);
    form.add(imageContainer);
    form.add(fileContentInfo);
    form.add(buttonPanel);

    add(noButtonPanel);
    add(form);

    buttonPanel.setVisible(!(buttons == null));
    fileContentContainer.setVisible(false);
    imageContainer.setVisible(false);
    fileContentInfo.setVisible(false);
    noButtonPanel.setVisible(buttons == null);

    // if noButtonPanel is visible, do not show form and vice versa
    form.setVisible(!noButtonPanel.isVisible());

    noButtonPanel.add(new Label("description", noButtonPanelInfo));

    final ListView lv = new ListView("buttons", buttons) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void populateItem(final ListItem item) {

            if (item.getIndex() % 2 != 0) {
                item.add(AttributeModifier.replace("class", "oddRow"));
            }

            final String viewedFile = buttons.get(item.getIndex());

            final String name = getFileSimpleName(buttons.get(item.getIndex()));
            final Label buttonLabel = new Label("name", name);

            Label fileSize = new Label("fileSize", getFileSize(viewedFile));

            downloadFile = new DownloadLink("download", new File(" "), "");
            downloadFile.setModelObject(new File(viewedFile));
            downloadFile.setVisible(true);

            alink = new AjaxLink("alink", item.getModel()) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onClick(AjaxRequestTarget target) {

                    fileContentInfo.setVisible(true);
                    String fileContent = new String();
                    if (!isImage(viewedFile)) {
                        fileContentContainer.setVisible(true);
                        imageContainer.setVisible(false);
                        fileContent = getFileContent(viewedFile, name);
                        fileContentContainer.setModelObject(fileContent);
                    } else {

                        PageNavigation navigation = null;
                        try {
                            navigation = ((TestExplorerSession) Session.get()).getDbReadConnection()
                                    .getNavigationForTestcase(testcaseId, getTESession().getTimeOffset());
                        } catch (DatabaseAccessException e) {
                            LOG.error("Can't get runId, suiteId and dbname for testcase with id=" + testcaseId,
                                    e);
                        }

                        String runId = navigation.getRunId();
                        String suiteId = navigation.getSuiteId();
                        String dbname = TestExplorerUtils.extractPageParameter(parameters, "dbname");

                        fileContentInfo.setDefaultModelObject("Previewing '" + name + "' image");

                        final String url = "AttachmentsServlet?&runId=" + runId + "&suiteId=" + suiteId
                                + "&testcaseId=" + testcaseId + "&dbname=" + dbname + "&fileName=" + name;
                        imageContainer.add(new AttributeModifier("src", new Model<String>(url)));
                        imageContainer.setVisible(true);
                        fileContentContainer.setVisible(false);
                    }

                    // first setting all buttons with the same state
                    String reverseButtonsState = "var cusid_ele = document.getElementsByClassName('attachedButtons'); "
                            + "for (var i = 0; i < cusid_ele.length; ++i) { " + "var item = cusid_ele[i];  "
                            + "item.style.color= \"#000000\";" + "}";
                    // setting CSS style to the pressed button and its label
                    String pressClickedButton = "var span = document.evaluate(\"//a[@class='button attachedButtons']/span[text()='"
                            + name + "']\", "
                            + "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
                            + "span.style.backgroundPosition=\"left bottom\";"
                            + "span.style.padding=\"6px 0 4px 18px\";"
                            + "var button = document.evaluate(\"//a[@class='button attachedButtons']/span[text()='"
                            + name + "']/..\", "
                            + "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;"
                            + "button.style.backgroundPosition=\"right bottom\";"
                            + "button.style.color=\"#000000\";" + "button.style.outline=\"medium none\";";

                    // I could not figure out how it works with wicket, so i did it with JS
                    target.appendJavaScript(reverseButtonsState);
                    target.appendJavaScript(pressClickedButton);

                    target.add(form);
                }
            };

            alink.add(buttonLabel);
            item.add(alink);
            item.add(downloadFile);
            item.add(fileSize);
        }
    };
    buttonPanel.add(lv);
}

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

License:Apache License

private Component createRowLink(String id, final IModel<SelectableBean<AssignmentEditorDto>> rowModel) {
    AjaxLink<SelectableBean<AssignmentEditorDto>> button = new AjaxLink<SelectableBean<AssignmentEditorDto>>(id,
            rowModel) {//from   w ww  . ja  v a2 s .  c om

        @Override
        public IModel<?> getBody() {
            AssignmentEditorDto dto = (AssignmentEditorDto) rowModel.getObject();
            String name = StringUtils.isNotEmpty(dto.getNameForTargetObject()) ? dto.getNameForTargetObject()
                    : dto.getName();
            return new Model<>(name);
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            LOGGER.trace("{} CLICK: {}", this, rowModel.getObject());
            toggleRow(rowModel);
            target.add(this);
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            if (rowModel.getObject().isSelected()) {
                tag.put("class", "list-group-item active");
                tag.put("style", "background-color: #eee; border-color: #d6d6d6; color: #000;");
            } else {
                tag.put("class", "list-group-item");
            }
            String description = ((AssignmentEditorDto) rowModel.getObject()).getDescription();
            if (description != null) {
                tag.put("title", description);
            }
        }
    };
    button.add(new VisibleEnableBehaviour() {
        @Override
        public boolean isVisible() {
            return ((AssignmentEditorDto) rowModel.getObject()).getStatus() != UserDtoStatus.DELETE;
        }
    });
    button.setOutputMarkupId(true);
    return button;
}

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

License:Apache License

private Component createParamLink(String id, IModel<String> itemModel) {
    AjaxLink<String> button = new AjaxLink<String>(id, itemModel) {

        @Override/*from w ww  .j a va 2 s  .  c o m*/
        public IModel<?> getBody() {
            return new Model<String>(getModel().getObject());
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            LOGGER.trace("{} CLICK param: {}", this, getModel().getObject());
            toggleParam(getModel().getObject());
            target.add(SimpleParametricRoleSelector.this);
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            String param = getModel().getObject();
            if (param.equals(selectedParam)) {
                tag.put("class", "list-group-item active");
            } else {
                tag.put("class", "list-group-item");
            }
        }
    };
    button.setOutputMarkupId(true);
    return button;
}

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

License:Apache License

private Component createRoleLink(String id, IModel<PrismObject<R>> model) {
    AjaxLink<PrismObject<R>> button = new AjaxLink<PrismObject<R>>(id, model) {

        @Override//from  w w  w .  j  av a2 s .  c o  m
        public IModel<?> getBody() {
            return new Model<String>(getModel().getObject().asObjectable().getName().getOrig());
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            LOGGER.trace("{} CLICK: {}", this, getModel().getObject());
            toggleRole(getModel().getObject());
            target.add(this);
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            PrismObject<R> role = getModel().getObject();
            if (isSelected(role)) {
                tag.put("class", "list-group-item active");
            } else {
                tag.put("class", "list-group-item");
            }
            String description = role.asObjectable().getDescription();
            if (description != null) {
                tag.put("title", description);
            }
        }
    };
    button.setOutputMarkupId(true);
    return button;
}

From source file:com.evolveum.midpoint.web.page.admin.resources.CapabilitiesPanel.java

License:Apache License

private void createCapabilityButton(String id) {
    AjaxLink<Boolean> button = new AjaxLink<Boolean>(id, new PropertyModel<Boolean>(getModel(), id)) {

        @Override// w  w w . j  a  v a2 s .c o  m
        public void onClick(AjaxRequestTarget target) {
            // TODO:
        }

    };

    button.add(new AttributeModifier("class",
            button.getModelObject() ? "btn btn-app btn-resource-capability bg-light-blue"
                    : "btn btn-app btn-resource-capability bg-gray text-light-blue"));

    button.add(new Label("label", new ResourceModel("CapabilitiesType." + id)));

    add(button);
}

From source file:com.evolveum.midpoint.web.page.admin.resources.ResourceContentTabPanel.java

License:Apache License

private void initLayout(final IModel<PrismObject<ResourceType>> model, final PageBase parentPage) {
    setOutputMarkupId(true);/*from   w  ww  .  ja v  a2 s .  c  o  m*/

    final Form mainForm = new Form(ID_MAIN_FORM);
    mainForm.setOutputMarkupId(true);
    mainForm.addOrReplace(initTable(model));
    add(mainForm);

    AutoCompleteTextPanel<String> intent = new AutoCompleteTextPanel<String>(ID_INTENT,
            new PropertyModel<String>(resourceContentSearch, "intent"), String.class) {
        private static final long serialVersionUID = 1L;

        @Override
        public Iterator<String> getIterator(String input) {
            RefinedResourceSchema refinedSchema = null;
            try {
                refinedSchema = RefinedResourceSchema.getRefinedSchema(model.getObject(),
                        parentPage.getPrismContext());

            } catch (SchemaException e) {
                return new ArrayList<String>().iterator();
            }
            return RefinedResourceSchema.getIntentsForKind(refinedSchema, getKind()).iterator();

        }

    };
    intent.getBaseFormComponent().add(new OnChangeAjaxBehavior() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.add(get(ID_REAL_OBJECT_CLASS));
            updateResourceContentSearch();
            mainForm.addOrReplace(initTable(model));
            target.add(mainForm);

        }
    });
    intent.setOutputMarkupId(true);
    intent.add(new VisibleEnableBehaviour() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return !isUseObjectClass();
        }
    });
    add(intent);

    Label realObjectClassLabel = new Label(ID_REAL_OBJECT_CLASS, new AbstractReadOnlyModel<String>() {
        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            RefinedObjectClassDefinition ocDef;
            try {
                RefinedResourceSchema refinedSchema = RefinedResourceSchema.getRefinedSchema(model.getObject(),
                        parentPage.getPrismContext());
                if (refinedSchema == null) {
                    return "NO SCHEMA DEFINED";
                }
                ocDef = refinedSchema.getRefinedDefinition(getKind(), getIntent());
                if (ocDef != null) {
                    return ocDef.getObjectClassDefinition().getTypeName().getLocalPart();
                }
            } catch (SchemaException e) {
            }

            return "NOT FOUND";
        }
    });
    realObjectClassLabel.setOutputMarkupId(true);
    add(realObjectClassLabel);

    AutoCompleteQNamePanel objectClassPanel = new AutoCompleteQNamePanel(ID_OBJECT_CLASS,
            new PropertyModel<QName>(resourceContentSearch, "objectClass")) {
        private static final long serialVersionUID = 1L;

        @Override
        public Collection<QName> loadChoices() {
            return createObjectClassChoices(model);
        }

        @Override
        protected void onChange(AjaxRequestTarget target) {
            LOGGER.trace("Object class panel update: {}", isUseObjectClass());
            updateResourceContentSearch();
            mainForm.addOrReplace(initTable(model));
            target.add(mainForm);
        }

    };

    objectClassPanel.add(new VisibleEnableBehaviour() {
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            return isUseObjectClass();
        }
    });
    add(objectClassPanel);

    AjaxLink<Boolean> repoSearch = new AjaxLink<Boolean>(ID_REPO_SEARCH,
            new PropertyModel<Boolean>(resourceContentSearch, "resourceSearch")) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            isRepoSearch = true;
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT)
                    .setResourceSearch(Boolean.FALSE);
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT)
                    .setResourceSearch(Boolean.FALSE);

            resourceContentSearch.getObject().setResourceSearch(Boolean.FALSE);
            updateResourceContentSearch();
            mainForm.addOrReplace(initRepoContent(model));
            target.add(getParent().addOrReplace(mainForm));
            target.add(this);
            target.add(getParent().get(ID_RESOURCE_SEARCH)
                    .add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            if (!getModelObject().booleanValue())
                add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
        }
    };
    add(repoSearch);

    AjaxLink<Boolean> resourceSearch = new AjaxLink<Boolean>(ID_RESOURCE_SEARCH,
            new PropertyModel<Boolean>(resourceContentSearch, "resourceSearch")) {
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            isRepoSearch = false;
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_REPOSITORY_CONTENT)
                    .setResourceSearch(Boolean.TRUE);
            getContentStorage(kind, SessionStorage.KEY_RESOURCE_PAGE_RESOURCE_CONTENT)
                    .setResourceSearch(Boolean.TRUE);
            updateResourceContentSearch();
            resourceContentSearch.getObject().setResourceSearch(Boolean.TRUE);
            mainForm.addOrReplace(initResourceContent(model));
            target.add(getParent().addOrReplace(mainForm));
            target.add(this.add(AttributeModifier.append("class", " active")));
            target.add(getParent().get(ID_REPO_SEARCH)
                    .add(AttributeModifier.replace("class", "btn btn-sm btn-default")));
        }

        @Override
        protected void onBeforeRender() {
            super.onBeforeRender();
            getModelObject().booleanValue();
            if (getModelObject().booleanValue())
                add(AttributeModifier.replace("class", "btn btn-sm btn-default active"));
        }
    };
    add(resourceSearch);

}

From source file:com.evolveum.midpoint.web.page.self.UserViewTabPanel.java

License:Apache License

private Component createRelationLink(String id, IModel<QName> model) {
    AjaxLink<QName> button = new AjaxLink<QName>(id, model) {

        @Override/*from   w w  w. ja  v a2s. c  o  m*/
        public IModel<String> getBody() {
            QName relation = model.getObject();
            if (relation == null) {
                return createStringResource("RelationTypes.ANY");
            }
            RelationDefinitionType def = WebComponentUtil.getRelationDefinition(model.getObject());
            if (def != null) {
                DisplayType display = def.getDisplay();
                if (display != null) {
                    PolyStringType label = display.getLabel();
                    if (PolyStringUtils.isNotEmpty(label)) {
                        return getPageBase().createStringResource(label);
                    }
                }
            }
            return Model.of(model.getObject().getLocalPart());
        }

        @Override
        public void onClick(AjaxRequestTarget target) {
            selectedRelation = model.getObject();
            target.add(UserViewTabPanel.this);
        }

        @Override
        protected void onComponentTag(ComponentTag tag) {
            super.onComponentTag(tag);
            QName relation = model.getObject();
            if (relation == null && selectedRelation == null
                    || relation != null && relation.equals(selectedRelation)) {
                tag.put("class", "list-group-item active");
            } else {
                tag.put("class", "list-group-item");
            }
        }
    };
    button.setOutputMarkupId(true);
    return button;
}

From source file:com.francetelecom.clara.cloud.presentation.applications.ApplicationActionPanel.java

License:Apache License

private void initComponent() {
    AjaxLink<Application> deleteBtn = new AjaxLink<Application>("app-delete", getModel()) {
        private static final long serialVersionUID = -3624723770141461652L;

        @Override// w w w.  ja  va2 s. c o m
        public void onClick(AjaxRequestTarget target) {
            parentPage.deleteApplication(target, getModelObject());
        }

        @Override
        protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
            attributes.getAjaxCallListeners()
                    .add(new DeleteConfirmationDecorator(WicketUtils
                            .getStringResourceModel(this, "portal.application.action.delete.confirm",
                                    new Model<String[]>(new String[] { getModelObject().getLabel() }))
                            .getObject()));

        }

        @Override
        public boolean isVisible() {
            return canBeDeleted;
        }
    };

    WebMarkupContainer deleteDisabledSpan = new WebMarkupContainer("app-delete-disable");
    if (canBeDeleted) {
        deleteDisabledSpan.setVisible(false);
    }
    add(deleteDisabledSpan);

    deleteSpan = new WebMarkupContainer("deleteImg");
    deleteBtn.add(deleteSpan);
    add(deleteBtn);

    Link<Application> editBtn = new Link<Application>("app-edit", getModel()) {

        private static final long serialVersionUID = -5024306917768033030L;

        @Override
        public void onClick() {
            PageParameters params = new PageParameters();
            params.set("appUid", getModelObject().getUID());
            params.set("edit", "1");

            SelectedAppPage appPage = new SelectedAppPage(params);
            setResponsePage(appPage);
        }

        @Override
        public boolean isVisible() {
            return getModelObject().isEditable();
        }
    };
    editBtn.add(new AttributeAppender("title", new ResourceModel("portal.application.action.modify")));

    WebMarkupContainer editDisabledSpan = new WebMarkupContainer("app-edit-disable");
    if (getModelObject().isEditable()) {
        editDisabledSpan.setVisible(false);
    }
    add(editDisabledSpan);

    editSpan = new WebMarkupContainer("editImg");
    editBtn.add(editSpan);
    add(editBtn);
}

From source file:com.francetelecom.clara.cloud.presentation.designer.services.cfjavaprocessing.LogicalCfJavaProcessingServicePanel.java

License:Apache License

private void initComponents() {

    getServiceForm().add(new CacheActivatedImage("cfjavaprocessing-icon",
            new ResourceModel("cfjavaprocessing.icon").getObject()));
    // Online help link
    String completeHelpUrl = "";
    try {//from  w  w  w  .ja  v  a 2s  . c  o m
        completeHelpUrl = new StringResourceModel("portal.designer.logical.service.online_manual.baseUrl", null)
                .getString()
                + new StringResourceModel(
                        "portal.designer.logical.service.online_manual." + getLogicalModelType(), null)
                                .getString();
    } catch (Exception e) {
        //do nothing
    }
    ExternalLink onlineHelpLink = new ExternalLink("onlineHelpLink", completeHelpUrl);
    getServiceForm().add(onlineHelpLink);
    if (completeHelpUrl.isEmpty()) {
        onlineHelpLink.setVisible(false);
    }

    // FUNCTIONNAL PARAMETERS
    RequiredTextField<String> label = new RequiredTextField<String>("label");
    label.setLabel(new StringResourceModel("portal.designer.service.cfjava.label", null));
    label.add(new PropertyValidator<>());
    getServiceForm().add(label);

    RequiredTextField<String> groupId = new RequiredTextField<String>("softwareReference.groupId");
    groupId.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.groupId", null));
    groupId.add(new PropertyValidator<>());
    getServiceForm().add(groupId);

    RequiredTextField<String> artifactId = new RequiredTextField<String>("softwareReference.artifactId");
    artifactId.setLabel(
            new StringResourceModel("portal.designer.service.cfjava.softwareReference.artifactId", null));
    artifactId.add(new PropertyValidator<>());
    getServiceForm().add(artifactId);

    RequiredTextField<String> version = new RequiredTextField<String>("softwareReference.version");
    version.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.version", null));
    version.add(new PropertyValidator<>());
    getServiceForm().add(version);

    RequiredTextField<String> extension = new RequiredTextField<String>("softwareReference.extension");
    if (getServiceForm().getModelObject().getSoftwareReference() == null) {
        getServiceForm().getModelObject().setSoftwareReference(new MavenReference("", "", "", "war"));
    }
    extension.setLabel(
            new StringResourceModel("portal.designer.service.cfjava.softwareReference.extension", null));
    extension.add(new PropertyValidator<>());
    getServiceForm().add(extension);
    /*List<String> extensionList = new ArrayList<String>();
    extensionList.add("jar");
    extensionList.add("war");
    extensionList.add("ear");
    DropDownChoice<String> extension = new DropDownChoice<String>("softwareReference.extension", extensionList);
    extension.setLabel(new StringResourceModel("portal.designer.service.cfjava.softwareReference.extension",null));
    extension.add(new PropertyValidator<>());
    getServiceForm().add(extension);*/

    TextField<String> classifier = new TextField<String>("softwareReference.classifier", String.class);
    classifier.setLabel(
            new StringResourceModel("portal.designer.service.cfjava.softwareReference.classifier", null));
    classifier.add(new PropertyValidator<>());
    getServiceForm().add(classifier);

    CheckBox optionalSoftwareReference = new CheckBox("optionalSoftwareReference");
    optionalSoftwareReference.setLabel(
            new StringResourceModel("portal.designer.service.cfjava.optionalSoftwareReference", null));
    getServiceForm().add(optionalSoftwareReference);

    TextField<Integer> minMemoryMbHint = new TextField<Integer>("minMemoryMbHint");
    minMemoryMbHint.setLabel(new StringResourceModel("portal.designer.service.cfjava.minMemoryMbHint", null));
    minMemoryMbHint.add(new AttributeModifier("class", "small"));
    minMemoryMbHint.add(new PropertyValidator<>());
    getServiceForm().add(minMemoryMbHint);

    final TextField<String> iconUrl = new TextField<String>("iconUrl");
    iconUrl.setLabel(new StringResourceModel("portal.designer.service.cfjava.iconUrl", null));
    //iconUrl.add(new AttributeModifier("title", new StringResourceModel("portal.designer.service.cfjava.iconUrl.help",null)));
    //Add Wicket validation for URL
    iconUrl.add(new UrlValidator());
    iconUrl.add(new PropertyValidator<>());
    iconUrl.add(new OnChangeAjaxBehavior() {

        /**
        * 
        */
        private static final long serialVersionUID = 1L;

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // Important, DO NOT DELETE
            // By Calling OnChangeAjaxBehavior, we update iconUrl field model to can push button preview with updated model

        }

        @Override
        protected void onError(AjaxRequestTarget target, RuntimeException e) {
            iconUrl.updateModel(); // The feedback is handle when click on preview button so we need to updateModel when there is an error
        }
    });
    getServiceForm().add(iconUrl);
    getServiceForm().add(new CacheActivatedImage("imageHelp.iconUrl", getString("image.help")));

    WebMarkupContainer imageContainer = new WebMarkupContainer("imageContainer");

    final WebMarkupContainer icon = new WebMarkupContainer("icon");
    icon.setOutputMarkupId(true);
    icon.setOutputMarkupPlaceholderTag(true);
    if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) {
        setDefaultIconAndUpdateFeedBack(icon, null, "");
    } else {
        setCustomIconAndUpdateFeedBack(icon, iconUrl, null);
    }
    imageContainer.add(icon);

    final Label feedback = new Label("feedbackError", new Model<String>(""));
    feedback.setOutputMarkupId(true);
    imageContainer.add(feedback);

    AjaxLink preview = new AjaxLink("preview", new Model()) {
        @Override
        public void onClick(AjaxRequestTarget target) {
            try {

                //If null or empty when click on preview button, clean feedBack and display default image
                if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) {
                    setDefaultIconAndCleanFeedBack(icon, feedback);
                } // Else try to display custom image
                else {
                    //Construct URL to test integrity of what user typing
                    URL url = new URL(iconUrl.getModelObject().toString());
                    if (iconUrl.getModelObject() != null) {
                        setCustomIconAndUpdateFeedBack(icon, iconUrl, feedback);
                    }
                }
            } catch (MalformedURLException e) {
                setDefaultIconAndUpdateFeedBack(icon, feedback, e.getMessage());
                e.printStackTrace();
            }
            target.add(icon);
            target.add(feedback);
        }
    };
    imageContainer.add(preview);
    getServiceForm().add(imageContainer);

}

From source file:com.francetelecom.clara.cloud.presentation.designer.services.jeeprocessing.LogicalJeeProcessingServicePanel.java

License:Apache License

private void initComponents() {

    getServiceForm().add(new CacheActivatedImage("logicalJeeProcessingPanelIcon",
            new ResourceModel("jeeProcessing-icon").getObject()));
    // Online help link
    String completeHelpUrl = "";
    try {/* w ww .  j a v a 2s  .  com*/
        completeHelpUrl = new StringResourceModel("portal.designer.logical.service.online_manual.baseUrl", null)
                .getString()
                + new StringResourceModel(
                        "portal.designer.logical.service.online_manual." + getLogicalModelType(), null)
                                .getString();
    } catch (Exception e) {
        //do nothing
    }
    ExternalLink onlineHelpLink = new ExternalLink("onlineHelpLink", completeHelpUrl);
    getServiceForm().add(onlineHelpLink);
    if (completeHelpUrl.isEmpty()) {
        onlineHelpLink.setVisible(false);
    }

    // FUNCTIONNAL PARAMETERS
    RequiredTextField<String> label = new RequiredTextField<String>("label");
    label.setLabel(new StringResourceModel("portal.designer.service.jee.label", null));
    label.add(new PropertyValidator<>());
    getServiceForm().add(label);

    RequiredTextField<String> groupId = new RequiredTextField<String>("softwareReference.groupId");
    groupId.setLabel(new StringResourceModel("portal.designer.service.jee.softwareReference.groupId", null));
    groupId.add(new PropertyValidator<>());
    getServiceForm().add(groupId);

    RequiredTextField<String> artifactId = new RequiredTextField<String>("softwareReference.artifactId");
    artifactId.setLabel(
            new StringResourceModel("portal.designer.service.jee.softwareReference.artifactId", null));
    artifactId.add(new PropertyValidator<>());
    getServiceForm().add(artifactId);

    RequiredTextField version = new RequiredTextField("softwareReference.version");
    version.setLabel(new StringResourceModel("portal.designer.service.jee.softwareReference.version", null));
    version.add(new PropertyValidator<>());
    getServiceForm().add(version);

    TextField classifier = new TextField("softwareReference.classifier", String.class);
    classifier.setLabel(
            new StringResourceModel("portal.designer.service.jee.softwareReference.classifier", null));
    classifier.add(new PropertyValidator<>());
    getServiceForm().add(classifier);

    CheckBox optionalSoftwareReference = new CheckBox("optionalSoftwareReference");
    optionalSoftwareReference
            .setLabel(new StringResourceModel("portal.designer.service.jee.optionalSoftwareReference", null));
    getServiceForm().add(optionalSoftwareReference);

    TextField minMemoryMbHint = new TextField("minMemoryMbHint");
    minMemoryMbHint.setLabel(new StringResourceModel("portal.designer.service.jee.minMemoryMbHint", null));
    minMemoryMbHint.add(new AttributeModifier("class", "small"));
    minMemoryMbHint.add(new PropertyValidator<>());
    getServiceForm().add(minMemoryMbHint);

    final TextField<String> iconUrl = new TextField<String>("iconUrl");
    iconUrl.setLabel(new StringResourceModel("portal.designer.service.jee.iconUrl", null));
    //iconUrl.add(new AttributeModifier("title", new StringResourceModel("portal.designer.service.jee.iconUrl.help",null)));
    //Add Wicket validation for URL
    iconUrl.add(new UrlValidator());
    iconUrl.add(new PropertyValidator<>());
    iconUrl.add(new OnChangeAjaxBehavior() {

        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            // Important, DO NOT DELETE
            // By Calling OnChangeAjaxBehavior, we update iconUrl field model to can push button preview with updated model

        }

        @Override
        protected void onError(AjaxRequestTarget target, RuntimeException e) {
            iconUrl.updateModel(); // The feedback is handle when click on preview button so we need to updateModel when there is an error
        }
    });
    getServiceForm().add(iconUrl);
    getServiceForm()
            .add(new CacheActivatedImage("imageHelp.iconUrl", new ResourceModel("image.help").getObject()));

    WebMarkupContainer imageContainer = new WebMarkupContainer("imageContainer");

    final WebMarkupContainer icon = new WebMarkupContainer("icon");
    icon.setOutputMarkupId(true);
    icon.setOutputMarkupPlaceholderTag(true);
    if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) {
        setDefaultIconAndUpdateFeedBack(icon, null, "");
    } else {
        setCustomIconAndUpdateFeedBack(icon, iconUrl, null);
    }
    imageContainer.add(icon);

    final Label feedback = new Label("feedbackError", new Model<String>(""));
    feedback.setOutputMarkupId(true);
    imageContainer.add(feedback);

    AjaxLink preview = new AjaxLink("preview", new Model()) {
        @Override
        public void onClick(AjaxRequestTarget target) {
            try {

                //If null or empty when click on preview button, clean feedBack and display default image
                if (iconUrl.getModelObject() == null || iconUrl.getModelObject().equals("")) {
                    setDefaultIconAndCleanFeedBack(icon, feedback);
                } // Else try to display custom image
                else {
                    //Construct URL to test integrity of what user typing
                    URL url = new URL(iconUrl.getModelObject().toString());
                    if (iconUrl.getModelObject() != null) {
                        setCustomIconAndUpdateFeedBack(icon, iconUrl, feedback);
                    }
                }
            } catch (MalformedURLException e) {
                setDefaultIconAndUpdateFeedBack(icon, feedback, e.getMessage());
                logger.info("Exception while getting new icon", e);
            }
            target.add(icon);
            target.add(feedback);
        }
    };
    imageContainer.add(preview);
    getServiceForm().add(imageContainer);

}