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

it.tidalwave.integritychecker.archive.createconfirmation.ui.netbeans.ScanArchiveCreationConfirmationActor Maven / Gradle / Ivy

/*
 * #%L
 * *********************************************************************************************************************
 * 
 * SolidBlue - open source safe data
 * http://solidblue.tidalwave.it - hg clone https://bitbucket.org/tidalwave/solidblue-src
 * %%
 * Copyright (C) 2011 - 2014 Tidalwave s.a.s. (http://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.
 * 
 * *********************************************************************************************************************
 * 
 * $Id$
 * 
 * *********************************************************************************************************************
 * #L%
 */
package it.tidalwave.integritychecker.archive.createconfirmation.ui.netbeans;

import javax.annotation.Nonnull;
import java.nio.file.Path;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
import it.tidalwave.messagebus.annotation.ListensTo;
import it.tidalwave.actor.annotation.Actor;
import static org.openide.NotifyDescriptor.*;
import static it.tidalwave.integritychecker.archive.ScanArchive.*;
import static it.tidalwave.integritychecker.archive.createconfirmation.ui.netbeans.Bundle.*;

/***********************************************************************************************************************
 *
 * This actor processes a {@link ScanArchiveCreationConfirmationRequest}. If the related folder has been previously
 * scanned, the request is confirmed; otherwise, an explicit confirmation is asked the user for.
 * 
 * @author  Fabrizio Giudici
 * @version $Id$
 *
 **********************************************************************************************************************/
@Actor
public class ScanArchiveCreationConfirmationActor 
  {
    @NbBundle.Messages
      ({
        "newScanArchiveConfirmation=The selected folder was never scanned before. Do you want to create a new scan archive for it?"
      }) 
            
    void onScanArchiveCreationConfirmationRequest (final @ListensTo @Nonnull ScanArchiveCreationConfirmationRequest request)
      {
        request.confirmIf(archiveFolderAlreadyExists(request.getFolder()) || userConfirms());
      }
    
    private boolean userConfirms()
      {
        // FIXME: decouple the UI implementation
        final NotifyDescriptor nd = new NotifyDescriptor(newScanArchiveConfirmation(), "", YES_NO_OPTION, QUESTION_MESSAGE, null, NO_OPTION);
        return DialogDisplayer.getDefault().notify(nd) == YES_OPTION;
      }

    private boolean archiveFolderAlreadyExists (final @Nonnull Path folder) 
      {
        return folder.resolve(ARCHIVE_FOLDER_NAME).toFile().exists();
      }
  }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy