All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fujion.component.MessagePane Maven / Gradle / Ivy

/*
 * #%L
 * fujion
 * %%
 * Copyright (C) 2008 - 2017 Regenstrief Institute, Inc.
 * %%
 * 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.
 *
 * #L%
 */
package org.fujion.component;

import org.fujion.annotation.Component;
import org.fujion.annotation.Component.ChildTag;
import org.fujion.annotation.Component.ContentHandling;
import org.fujion.annotation.EventHandler;

/**
 * A pane holding a single message in a message window.
 *
 * @see org.fujion.component.MessageWindow
 */
@Component(tag = "messagepane", widgetClass = "Messagepane", content = ContentHandling.AS_CHILD, parentTag = "messagewindow", childTag = @ChildTag("*"))
public class MessagePane extends BaseUIComponent {
    
    private String title;
    
    private int duration = 8000;
    
    private String category;
    
    private boolean actionable;
    
    public MessagePane() {
        
    }
    
    /**
     * Create a message pane.
     *
     * @param title Title bar text.
     * @param category Message category.
     * @param duration Duration, in milliseconds, that the message will display.
     * @param actionable True if the message is actionable.
     */
    public MessagePane(String title, String category, int duration, boolean actionable) {
        setTitle(title);
        setCategory(category);
        setDuration(duration);
        setActionable(actionable);
    }
    
    /**
     * Returns the title bar text.
     *
     * @return The title bar text.
     */
    public String getTitle() {
        return title;
    }
    
    /**
     * Sets the title bar text.
     *
     * @param title The title bar text.
     */
    public void setTitle(String title) {
        if (!areEqual(title = nullify(title), this.title)) {
            sync("title", this.title = title);
        }
    }
    
    /**
     * Returns the duration, in milliseconds, that the message will be displayed. The default is
     * 8000 ms. A value of <=0 means infinite duration.
     *
     * @return The duration, in milliseconds, that the message will be displayed.
     */
    public int getDuration() {
        return duration;
    }
    
    /**
     * Sets the duration, in milliseconds, that the message will be displayed. A value of <=0
     * means infinite duration.
     *
     * @param duration The duration, in milliseconds, that the message will be displayed.
     */
    public void setDuration(int duration) {
        if (duration != this.duration) {
            sync("duration", this.duration = duration);
        }
    }
    
    /**
     * Returns the category of the message. This allows messages to be cleared based on their
     * category.
     *
     * @return The category of the message.
     */
    public String getCategory() {
        return category;
    }
    
    /**
     * Sets the category of the message. This allows messages to be cleared based on their category.
     *
     * @param category The category of the message.
     */
    public void setCategory(String category) {
        this.category = nullify(category);
    }
    
    /**
     * Returns true if the message is actionable. An actionable message has an action icon that,
     * when clicked, triggers an action event.
     *
     * @return True if the message is actionable.
     */
    public boolean isActionable() {
        return actionable;
    }
    
    /**
     * Set to true to make the message actionable. An actionable message has an action icon that,
     * when clicked, triggers an action event.
     *
     * @param actionable Set to true to make the message actionable.
     */
    public void setActionable(boolean actionable) {
        if (actionable != this.actionable) {
            sync("actionable", this.actionable = actionable);
        }
    }
    
    /**
     * Handles close events from the client.
     */
    @EventHandler(value = "close", syncToClient = false)
    private void _close() {
        destroy();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy