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

it.tidalwave.bluebill.mobile.observation.ui.ReportUserNotificationWithFeedback Maven / Gradle / Ivy

The newest version!
/***********************************************************************************************************************
 *
 * blueBill Mobile - Android - open source birding
 * Copyright (C) 2009-2011 by Tidalwave s.a.s. (http://www.tidalwave.it)
 *
 ***********************************************************************************************************************
 *
 * 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.
 *
 ***********************************************************************************************************************
 *
 * WWW: http://bluebill.tidalwave.it/mobile
 * SCM: https://java.net/hg/bluebill-mobile~android-src
 *
 **********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.observation.ui;

import it.tidalwave.netbeans.util.Locator;
import java.util.concurrent.ExecutorService;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import it.tidalwave.mobile.util.ProgressListener;
import it.tidalwave.mobile.util.ProgressListenerSupport;
import it.tidalwave.util.ui.UserNotificationWithFeedback;
import it.tidalwave.bluebill.mobile.observation.report.CsvReportGenerator;
import it.tidalwave.bluebill.mobile.observation.report.KmlReportGenerator;
import it.tidalwave.bluebill.mobile.observation.report.ReportFactory;
import it.tidalwave.bluebill.mobile.observation.report.ReportFactoryProvider;
import it.tidalwave.mobile.util.ExceptionReporter;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import static org.openide.util.NbBundle.*;
import static lombok.AccessLevel.*;

/***********************************************************************************************************************
 *
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@NotThreadSafe @Slf4j @ToString
public abstract class ReportUserNotificationWithFeedback extends UserNotificationWithFeedback 
  {
    private final static Class _ = ReportUserNotificationWithFeedback.class;
    
    private static final ProgressListener DEFAULT_PROGRESS_LISTENER = new ProgressListenerSupport(); 
 
    @Nonnull
    protected ProgressListener progressListener = DEFAULT_PROGRESS_LISTENER; 
    
    @Nonnull
    private ReportFactoryProvider reportFactoryProvider = Locator.find(ReportFactoryProvider.class);
            
    @Getter(PROTECTED)
    private ReportFactory reportFactory;
    
    // FIXME: discover them by Lookup and put in a list; then setXXXAttachment() takes an index and enable them by index
    private final KmlReportGenerator kmlReportGenerator = new KmlReportGenerator();
    
    private final CsvReportGenerator csvReportGenerator = new CsvReportGenerator();
    
    @Nonnull
    private final ExecutorService executorService = Locator.find(ExecutorService.class);

    /*******************************************************************************************************************
     *
     * 
     * 
     ******************************************************************************************************************/
    @Getter
    private final List options = Collections.unmodifiableList(Arrays.asList
      (
        getMessage(_, "attachKML"),
        getMessage(_, "attachCSV")
      ));

    /*******************************************************************************************************************
     *
     * 
     * 
     ******************************************************************************************************************/
    public ReportUserNotificationWithFeedback (final @Nonnull String title)
      {
        super(title, "", new Feedback());  
        reportFactory = reportFactoryProvider.createReportFactory();
      }

    /*******************************************************************************************************************
     *
     * 
     * 
     ******************************************************************************************************************/
    public void setKmlAttachment (final boolean kmlAttachment)
      {
        log.info("setKmlAttachment({})", kmlAttachment);
        
        if (kmlAttachment)
          {
            reportFactory = reportFactory.with(kmlReportGenerator);
          }
        else
          {
            reportFactory = reportFactory.without(kmlReportGenerator);
          }
      }

    /*******************************************************************************************************************
     *
     * 
     * 
     ******************************************************************************************************************/
    public void setCsvAttachment (final boolean csvAttachment)
      {
        log.info("setCsvAttachment({})", csvAttachment);        
          
        if (csvAttachment)
          {
            reportFactory = reportFactory.with(csvReportGenerator);
          }
        else
          {
            reportFactory = reportFactory.without(csvReportGenerator);
          }
      }

    /*******************************************************************************************************************
     *
     * 
     * 
     ******************************************************************************************************************/
    // FIXME: the ProgressListener has no meaning here, as we're a question feedback...
    public void setProgressListener (final @Nonnull ProgressListener progressListener) 
      {
        this.progressListener = progressListener;
      }

    /*******************************************************************************************************************
     *
     * 
     * 
     ******************************************************************************************************************/
    @Override
    public void confirm()
//    public void onConfirm()
      {
        executorService.submit(new Runnable()  // FIXME: perhaps it should be the subclass to decide?
          {
            @Override
            public void run()
              {
                try
                  {
                    onConfirmInBackground();
                  }
                catch (Throwable t)
                  {
                    ExceptionReporter.reportException(t);                         
                  }
              }
          });
      }
    
    /*******************************************************************************************************************
     *
     * 
     * 
     ******************************************************************************************************************/
    protected abstract void onConfirmInBackground()
      throws Exception;
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy