com.gmail.volodymyrdotsenko.jqxwicket.widgets.JQueryUIBehavior.java Source code

Java tutorial

Introduction

Here is the source code for com.gmail.volodymyrdotsenko.jqxwicket.widgets.JQueryUIBehavior.java

Source

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.gmail.volodymyrdotsenko.jqxwicket.widgets;

import org.apache.wicket.Application;
import org.apache.wicket.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gmail.volodymyrdotsenko.jqxwicket.core.JQueryBehavior;
import com.gmail.volodymyrdotsenko.jqxwicket.core.Options;
import com.gmail.volodymyrdotsenko.jqxwicket.widgets.settings.JQueryUILibrarySettings;

/**
 * Provides the base class for every jQuery behavior.
 * 
 * @author Sebastien Briquet - sebfz1
 * 
 */
public class JQueryUIBehavior extends JQueryBehavior {
    private static final long serialVersionUID = 1L;
    private static final Logger LOG = LoggerFactory.getLogger(JQueryUIBehavior.class);

    /**
     * Constructor
     * 
     * @param selector
     *            the html selector (ie: "#myId")
     * @param method
     *            the kendo-ui method
     */
    public JQueryUIBehavior(String selector, String method) {
        this(selector, method, new Options());
    }

    /**
     * Constructor
     * 
     * @param selector
     *            the html selector (ie: "#myId")
     * @param method
     *            the kendo-ui method
     * @param options
     *            the {@link Options}
     */
    public JQueryUIBehavior(String selector, String method, Options options) {
        super(selector, method, options);

        this.initReferences();

        this.setOption("theme", "\"" + JQueryUILibrarySettings.get().getStyleSheetReference().getStyle() + "\"");
    }

    /**
     * Initializes CSS & JavaScript resource references
     */
    private void initReferences() {
        JQueryUILibrarySettings settings = JQueryUILibrarySettings.get();

        if (settings.getJavaScriptReference() != null) {
            this.add(settings.getJavaScriptReference());
        }

        if (settings.getBasestyleSheetReference() != null) {
            this.add(settings.getBasestyleSheetReference());
        }

        if (settings.getStyleSheetReference() != null) {
            this.add(settings.getStyleSheetReference());
        }
    }

    // Events //

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

        if (!Application.get().getMarkupSettings().getStripWicketTags()) {
            LOG.warn(
                    "Application > MarkupSettings > StripWicketTags: setting is currently set to false. It is highly recommended to set it to true to prevent widget misbehaviors.");
        }
    }
}