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

fr.ird.observe.client.action.tripMap.TripMapActionSupport Maven / Gradle / Ivy

package fr.ird.observe.client.action.tripMap;

/*-
 * #%L
 * ObServe Toolkit :: Common Client
 * %%
 * Copyright (C) 2008 - 2017 IRD, Ultreia.io
 * %%
 * 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
 * .
 * #L%
 */

import fr.ird.observe.client.MainUI;
import fr.ird.observe.client.action.UIActionSupport;
import fr.ird.observe.client.form.TripUI;
import fr.ird.observe.client.util.tripMap.TripMapUI;
import java.awt.event.ActionEvent;
import javax.swing.JComponent;
import javax.swing.KeyStroke;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Created by tchemit on 25/08/17.
 *
 * @author Tony Chemit - [email protected]
 */
public abstract class TripMapActionSupport extends UIActionSupport {

    /** Logger. */
    private static final Log log = LogFactory.getLog(TripMapActionSupport.class);

    private TripMapUI ui;
    protected ActionEvent e;

    protected abstract void actionPerformed(TripMapUI ui);

    TripMapActionSupport(MainUI mainUI, String actionCommandKey, String label, String shortDescription, String actionIcon, KeyStroke acceleratorKey) {
        super(mainUI, actionCommandKey, label, shortDescription, actionIcon, acceleratorKey);
    }

    public void setUi(TripMapUI ui) {
        this.ui = ui;
    }

    @Override
    public final void actionPerformed(ActionEvent e) {
        if (!canExecuteAction()) {
            return;
        }
        this.e = e;

        if (ui != null) {
            actionPerformed(ui);
            return;
        }
        TripUI source = (TripUI) e.getSource();
        actionPerformed(source.getTripMap());
    }

    private boolean canExecuteAction() {
        JComponent editor = getEditor();
        if ((editor == null || (editor.isVisible() && editor.isEnabled() && editor.isShowing()))) {
            return true;
        }
        if (log.isInfoEnabled()) {
            log.info("Disabled action: " + getActionCommandKey() + " :: " + this);
        }
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy