net.gvcc.jgoffice.dbnavigatorbar.NavigatorButton.java Source code

Java tutorial

Introduction

Here is the source code for net.gvcc.jgoffice.dbnavigatorbar.NavigatorButton.java

Source

/*
 * Copyright (C) 2013 SGV
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.gvcc.jgoffice.dbnavigatorbar;

import net.gvcc.jgoffice.dbnavigatorbar.interfaces.INavigatorAction;
import com.vaadin.server.ThemeResource;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.themes.Reindeer;

public class NavigatorButton extends Button implements INavigatorAction, ClickListener {

    private static final long serialVersionUID = 1L;
    private NavigatorButtons button;
    private INavigatorAction buttonAction;

    public NavigatorButton(NavigatorButtons button, ThemeResource icon) {
        super();

        this.button = button;
        this.setStyleName(Reindeer.BUTTON_LINK);
        this.setWidth("-1px");
        this.setHeight("-1px");
        this.setImmediate(true);
        this.setIcon(icon);
        this.addClickListener(this);

        setButtonCaption();
    }

    public NavigatorButton(NavigatorButtons button, boolean visible, ThemeResource icon) {
        this(button, icon);
        this.setVisible(visible);
    }

    public final void setButtonCaption() {
        switch (button) {
        case FIRST:
            this.setCaption("First");
            break;
        case PREVIOUS:
            this.setCaption("Previous");
            break;
        case NEXT:
            this.setCaption("Next");
            break;
        case LAST:
            this.setCaption("Last");
            break;
        case INSERT:
            this.setCaption("Insert");
            break;
        case DELETE:
            this.setCaption("Delete");
            break;
        case POST:
            this.setCaption("Post");
            break;
        case EDIT:
            this.setCaption("Edit");
            break;
        case REFRESH:
            this.setCaption("Refresh");
            break;
        case CANCEL:
            this.setCaption("Cancel");
            break;
        default:
            break;
        }
    }

    public NavigatorButtons getButton() {
        return button;
    }

    public void setButton(NavigatorButtons button) {
        this.button = button;
    }

    public INavigatorAction getButtonAction() {
        return buttonAction;
    }

    public void setButtonAction(INavigatorAction buttonAction) {
        this.buttonAction = buttonAction;
    }

    public void setactive(boolean status) {
        this.setEnabled(status);
    }

    @Override
    public void navigatorActionPerformed() {

    }

    @Override
    public void buttonClick(ClickEvent event) {
        this.buttonAction.navigatorActionPerformed();
    }

}