Java tutorial
/* * Copyright 2014 yui_inoue. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.mycompany; import org.apache.wicket.Component; import org.apache.wicket.ajax.AbstractAjaxTimerBehavior; import org.apache.wicket.ajax.AbstractDefaultAjaxBehavior; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.image.Image; import org.apache.wicket.markup.html.panel.Panel; import org.apache.wicket.model.IModel; import org.apache.wicket.util.time.Duration; /** * A~@\tAjaxLink<br> * * <em>???F?i</em><br> * ?X?V?sAjaxLink???A<br> * Y?X?VN??A<br> * NNbN????B<br> * NNbN?A????s?B<br> * <ol type="1"> * <li>NNbN</li> * <li>NDisable</li> * <li>NeLXg\?</li> * <li>indicator\?</li> * <li>NNbN???s</li> * <li>^C}?[N</li> * <li>?o</li> * <li>indicator\?</li> * <li>NeLXg\?</li> * <li>NEnable</li> * </ol> * @version 1.0.0 * @since 2014/06/12 * @author IM yui_inoue */ public class AjaxCanNotRollLinkPanel extends Panel { /** * N */ private AjaxLink update; /** * NeLXg */ private Label updateLabel; /** * indicator */ private Image indicator; /** * ?X?V?Component */ private Component targetComponent; /** * N? {@link Duration} */ private Duration waitTime; /** * Construct * * @param id * {@link Panel#Panel(java.lang.String, org.apache.wicket.model.IModel)}id * @param label N\ * @param targetComponent ?X?V?Component * @param waitTime N? {@link Duration} * @see Panel */ public AjaxCanNotRollLinkPanel(String id, String label, Component targetComponent, Duration waitTime) { super(id); this.targetComponent = targetComponent; this.waitTime = waitTime; init(label); } /** * Construct * * @param id * {@link Panel#Panel(java.lang.String, org.apache.wicket.model.IModel)}id * @param model * {@link Panel#Panel(java.lang.String, org.apache.wicket.model.IModel)}model * @param label N\ * @param targetComponent ?X?V?Component * @param waitTime N? {@link Duration} * @see Panel */ public AjaxCanNotRollLinkPanel(String id, IModel<?> model, String label, Component targetComponent, Duration waitTime) { super(id, model); this.targetComponent = targetComponent; this.waitTime = waitTime; init(label); } /** * Panel?? * * @param label N\ */ private void init(String label) { updateLabel = new Label("updateLabel", label); updateLabel.setOutputMarkupId(true); indicator = new Image("indicator", AbstractDefaultAjaxBehavior.INDICATOR); indicator.setOutputMarkupId(true); indicator.setVisible(false); update = new AjaxLink("update") { @Override public void onClick(AjaxRequestTarget target) { onClickEvent(target); } }; update.setOutputMarkupId(true); update.add(updateLabel); update.add(indicator); add(update); } /** * NNbNCxg<br> * * NgpsC^?[oJA???<br> * NNbN???Override?superL?<br> * gp?F<br> * <code> * new AjaxCanNotRollLinkPanel(?`) { * @Override * protected void onClickEvent(AjaxRequestTarget target) { * super.onClickEvent(target); * NbN??L?q * } * }); * </code> * @param target Override?gp~ */ protected void onClickEvent(AjaxRequestTarget target) { update.setEnabled(false); updateLabel.setVisible(false); indicator.setVisible(true); this.add(new AbstractAjaxTimerBehavior(waitTime) { @Override protected void onTimer(AjaxRequestTarget target) { update.setEnabled(true); updateLabel.setVisible(true); indicator.setVisible(false); this.stop(); target.add(this.getComponent()); } }); target.add(targetComponent); } }