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) 

Source Link

Document

Construct.

Usage

From source file:com.senacor.wbs.web.project.LinkPanel.java

License:Apache License

public LinkPanel(String id, ResourceReference resourceReference, final TreeNode node) {
    super(id);/*from  w w  w.j  ava 2 s .  c  o m*/
    AjaxLink link = new AjaxLink("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            handle(node, target);
        }
    };
    link.add(new Image("image", resourceReference));
    add(link);
    setVisible(show());
}

From source file:com.socialsite.course.JoinCoursePanel.java

License:Open Source License

public JoinCoursePanel(final String id, final IModel<Course> model) {
    super(id, model);
    course = model.getObject();/*from w  ww .j  a va  2  s  . c o  m*/
    setOutputMarkupId(true);
    add(new AjaxLink<Void>("join") {

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

        @Override
        public void onClick(final AjaxRequestTarget target) {
            // reload
            course = courseDao.load(course.getId());
            final User user = getSessionUser();
            final CourseJoinedMsg msg = new CourseJoinedMsg();
            msg.setSender(user);
            msg.setCourse(course);
            msg.setTime(new Date());
            msg.setUsers(new HashSet<User>(user.getFriends()));
            messageDao.save(msg);
            isVisible = false;
            course.addStudents((Student) user);
            courseDao.save(course);
            target.addComponent(JoinCoursePanel.this);
            target.appendJavascript("SocialSite.Message.show('You joined the course');");
        }
    });
}

From source file:com.socialsite.course.NewCoursePanel.java

License:Open Source License

public NewCoursePanel(String id) {
    super(id);/*from  w w w  . ja v a2 s.c  o  m*/
    final ModalWindow courseModal;
    add(courseModal = new ModalWindow("coursemodal"));

    courseModal.setContent(new NewCourseModal(courseModal.getContentId()));
    courseModal.setTitle("Create new Course");
    courseModal.setCookieName("coursemodal");

    courseModal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public boolean onCloseButtonClicked(AjaxRequestTarget target) {
            return true;
        }
    });

    courseModal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public void onClose(AjaxRequestTarget target) {

        }
    });

    add(new AjaxLink<Void>("newcourse") {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void onClick(AjaxRequestTarget target) {
            courseModal.show(target);
        }
    });
}

From source file:com.socialsite.image.ImagePanel.java

License:Open Source License

/**
 * //from   w  ww  .j a  v  a 2 s .com
 * @param component
 *            component id
 * @param id
 *            id used to fetch the image
 * @param imageType
 *            type of the image (userimage , courseimage etc)
 * @param thumb
 *            will show thumb image if true
 * @param lastModified
 *            lastmodified date of the image
 */
public ImagePanel(final String component, final long id, final ImageType imageType, final Date lastModified,
        final boolean thumb, final boolean changeLink) {
    super(component);

    this.changeLink = changeLink;

    // allow the modal window to update the panel
    setOutputMarkupId(true);
    final ResourceReference imageResource = new ResourceReference(imageType.name());
    final Image userImage;
    final ValueMap valueMap = new ValueMap();
    valueMap.add("id", id + "");

    // the version is used to change the url dynamically if the image is
    // changed. This will allow the browser to cache images
    // reference http://code.google.com/speed/page-speed/docs/caching.html
    // #Use fingerprinting to dynamically enable caching.
    valueMap.add("version", lastModified.getTime() + "");
    if (thumb) {
        valueMap.add("thumb", "true");
    }
    add(userImage = new Image("userimage", imageResource, valueMap));
    userImage.setOutputMarkupId(true);

    final ModalWindow modal;
    add(modal = new ModalWindow("modal"));

    modal.setContent(new UploadPanel(modal.getContentId()) {

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

        @Override
        public String onFileUploaded(final FileUpload upload) {

            if (upload == null || upload.getSize() == 0) {
                // No image was provided
                error("Please upload an image.");
            } else if (!checkContentType(upload.getContentType())) {
                error("Only images of types png, jpg, and gif are allowed.");
            } else {
                saveImage(upload.getBytes());
            }

            return null;
        }

        @Override
        public void onUploadFinished(final AjaxRequestTarget target, final String filename,
                final String newFileUrl) {

            final ResourceReference imageResource = new ResourceReference(imageType.name());

            final ValueMap valueMap = new ValueMap();
            valueMap.add("id", id + "");
            // change the image lively
            valueMap.add("version", new Date().getTime() + "");
            if (thumb) {
                valueMap.add("thumb", "true");
            }

            userImage.setImageResourceReference(imageResource, valueMap);
            // update the image after the user changes it
            target.addComponent(userImage);
        }
    });
    modal.setTitle(" Select the image ");
    modal.setCookieName("modal");

    modal.setCloseButtonCallback(new ModalWindow.CloseButtonCallback() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public boolean onCloseButtonClicked(final AjaxRequestTarget target) {
            return true;
        }
    });

    modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        public void onClose(final AjaxRequestTarget target) {
        }
    });

    add(new AjaxLink<Void>("changeimage") {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        @Override
        public boolean isVisible() {
            if (changeLink) {
                // TODO allow admins to change the university image and
                // allow
                // staffs to change the course image
                // it. don't show it for thumb images
                return hasRole(SocialSiteRoles.OWNER) || hasRole(SocialSiteRoles.STAFF);
            }
            return false;

        }

        @Override
        public void onClick(final AjaxRequestTarget target) {
            modal.show(target);
        }
    });
}

From source file:com.socialsite.university.JoinUniversityPanel.java

License:Open Source License

public JoinUniversityPanel(final String id, final IModel<University> model) {
    super(id);//from ww w.  j ava2s  . c om
    setOutputMarkupId(true);
    university = model.getObject();
    add(new AjaxLink<Void>("join") {

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

        @Override
        public void onClick(final AjaxRequestTarget target) {
            final Staff staff = (Staff) getSessionUser();
            final StaffRequestMsg msg = new StaffRequestMsg(staff);
            msg.setTime(new Date());
            msg.addUser(university.getAdmin());
            msg.setUniversity(university);
            staffRequestMsgDao.save(msg);
            isVisible = false;
            target.addComponent(JoinUniversityPanel.this);
            target.appendJavascript("SocialSite.Message.show('Your request has been sent to the admin');");
        }
    });
}

From source file:com.swordlord.gozer.components.wicket.action.button.GWAjaxLinkAction.java

License:Open Source License

public GWAjaxLinkAction(String id, GozerController gc, GWContext context, DataBinding binding,
        PackageResourceReference resource) {
    super(id);/* ww  w  .  j  a  va  2s  . c  om*/

    _gc = gc;
    _binding = binding;
    _context = context;

    _image = new Image("image", resource);

    _link = new AjaxLink<Object>("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            onLinkClick(target);
        }
    };

    _link.add(_image);

    add(_link);
}

From source file:com.swordlord.gozer.components.wicket.action.button.modal.GWModalAction.java

License:Open Source License

public GWModalAction(String id, GozerController gc, GWContext context, DataBinding binding,
        PackageResourceReference resource) {
    super(id);/*from  ww w  . j  ava2  s.c o  m*/

    _gc = gc;
    _binding = binding;
    _context = context;

    AjaxLink<?> link = new AjaxLink<Object>("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            // add some checks!!
            GozerModalWindow window = getModalWindow();

            // HACK:
            // Oh my, what a hack... clean this up...
            if (window != null) {
                boolean bIsOK = isOK();

                if (bIsOK) {
                    DataViewBase dv = _binding.getDataBindingManager()
                            .getDataView(_binding.getDataBindingMember());
                    window.setSelectedRow(dv.getCurrentRow());
                }
                window.close(target, bIsOK);
            }
        }
    };

    _image = new Image("image", resource);

    link.add(_image);

    add(link);
}

From source file:com.swordlord.gozer.components.wicket.graph.common.GWChartPanel.java

License:Open Source License

protected DynamicImageMap constructImageMap(ChartImage image, String mapName) {
    DynamicImageMap imageMap = new DynamicImageMap("imageMap", mapName);
    EntityCollection entities = image.getRenderingInfo().getEntityCollection();
    if (entities != null) {
        int count = entities.getEntityCount();
        for (int i = count - 1; i >= 0; i--) {
            final ChartEntity entity = entities.getEntity(i);
            imageMap.addArea(entity.getShapeType(), entity.getShapeCoords(), entity.getToolTipText(),
                    new AjaxLink<Object>("link") {
                        private static final long serialVersionUID = -7982198051678987986L;

                        @Override
                        public void onClick(AjaxRequestTarget target) {
                            onClickCallback(target, entity);
                        }/*from  w w w .j av a  2  s  .  c om*/
                    });
        }
    }
    return imageMap;
}

From source file:com.swordlord.gozer.ui.modal.action.ModalAction.java

License:Open Source License

public ModalAction(String id, PackageResourceReference resource, final ModalWindowEx mw) {
    super(id);/*w  w  w. j  av  a 2  s . c o  m*/

    AjaxLink<?> link = new AjaxLink<Object>("link") {
        @Override
        public void onClick(AjaxRequestTarget target) {
            // HACK:
            // Oh my, what a hack... clean this up...
            if (mw != null) {
                boolean bIsOK = isOK();

                if (bIsOK) {
                    //window.setSelectedRow(dv.getCurrentRow());
                }
                mw.close(target, bIsOK);
            }
        }
    };

    _image = new Image("image", resource);

    link.add(_image);

    add(link);
}

From source file:com.ttdev.wicketpagetest.sample.guice.AjaxPage.java

License:Open Source License

public AjaxPage() {
    AjaxLink<Void> calcNext = new AjaxLink<Void>("calcNext") {

        private static final long serialVersionUID = 1L;

        @Override/*  ww w  .  j  a  v  a  2s . c  o m*/
        public void onClick(AjaxRequestTarget target) {
            current = service.calcNext(current);
            target.add(currentLabel);
        }
    };
    add(calcNext);
    currentLabel = new Label("current", new PropertyModel<Integer>(this, "current"));
    add(currentLabel);
    currentLabel.setOutputMarkupId(true);
}