CheckOutFileProcess.java :  » Source-Control » sourcejammer » org » sourcejammer » client » gui » process » Java Open Source

Java Open Source » Source Control » sourcejammer 
sourcejammer » org » sourcejammer » client » gui » process » CheckOutFileProcess.java
/*
 *  Copyright (C) 2001, 2002 Robert MacGrogan
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *
 * $Archive: SourceJammer$
 * $FileName: CheckOutFileProcess.java$
 * $FileID: 4132$
 *
 * Last change:
 * $AuthorName: Rob MacGrogan$
 * $Date: 8/7/03 1:21 PM$
 * $Comment: Bug fix: Check in from check out report was failing
 *          with null pointer. Now passing NodeInfo to CommandCentral checkin
 *          and force check in methods.$
 */

package org.sourcejammer.client.gui.process;

import org.sourcejammer.client.DisplayTextLibrary;
import org.sourcejammer.client.SourceJammerClient;
import org.sourcejammer.client.gui.CommandCentral;
import org.sourcejammer.client.gui.GUICommandException;
import org.sourcejammer.client.gui.MessageBoxUtil;
import org.sourcejammer.client.gui.process.info.CheckOutFileProcessInfo;
import org.sourcejammer.client.plugin.EventTimingType;
import org.sourcejammer.project.view.NodeInfo;
import org.sourcejammer.project.view.SJRequest;
import org.sourcejammer.util.SourceJammerConnectionException;

import java.awt.Cursor;
import java.io.File;
import java.io.IOException;

import javax.swing.JOptionPane;

import org.sourcejammer.client.gui.action.ActionCentral;


/**
 * Title: $FileName: CheckOutFileProcess.java$
 * @version $VerNum: 8$
 * @author $AuthorName: Rob MacGrogan$<br><br>
 * 
 * $Description: $
 * $KeyWordsOff: $
 */
public class CheckOutFileProcess extends AbstractProcess {

  private static final int FORCE_CHECK_IN = 0;
  private static final int SKIP = 1;
  private static final int CHECK_OUT = 2;
  
  

  public CheckOutFileProcess() {
  }
  public void process(Object info) {
    CommandCentral oCommand = CommandCentral.getInstance();
    try{
      if (info instanceof CheckOutFileProcessInfo){
        CheckOutFileProcessInfo oInfo = (CheckOutFileProcessInfo)info;
        oCommand.getRootAppFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        String[] sa = oInfo.getFileNames();
        for (int i = 0; i < sa.length; i++){
          
          long lFileID = oInfo.getParentProjectTreeNode().getFileUniqueIDFromName(sa[i]);
          if (checkLocalFileStatus(sa[i], oInfo.getTargetDirectory(), lFileID, oInfo.getRequest() )){
            oCommand.checkOutFile(lFileID, sa[i], oInfo.getTargetDirectory(), oInfo.getEolType(), oInfo.getRequest());
          }
        }
        ActionCentral.getInstance().fireActionInvokeLater(ActionCentral.act_REFRESH_PROJECT);
        
        //Notify
        SourceJammerClient.getInstance().getFileListeners()
                .notifyFileCheckedOut(oInfo.getRequest(), null, EventTimingType.AFTER_EVENT, null);
        
        oCommand.getRootAppFrame().setCursor(Cursor.getDefaultCursor());
      }
    }
    catch (Exception ex){
      ex.printStackTrace();
      MessageBoxUtil.displayErrorMessage(ex.getMessage());
    }
    finally {
      CommandCentral.getInstance().getRootAppFrame().setCursor(Cursor.getDefaultCursor());
    }
  }
  
  private boolean checkLocalFileStatus(String fileName, File targetDir, long fileID,
                                    SJRequest request)
          throws IOException, SourceJammerConnectionException, 
                  GUICommandException{
    boolean procede = true;
    boolean fileChanged = CommandCentral.getInstance().hasLocalFileChanged(fileName, targetDir);
    if (fileChanged){
      //prompt user for how to procede.
      int iAction = showFileChangedDialog(fileName);
      if (iAction == FORCE_CHECK_IN){
        NodeInfo fileNode = CommandCentral.getInstance().getSelectedFileNodeInfo(fileName);
        CommandCentral.getInstance().forceCheckIn(fileNode, targetDir, "", 
              SourceJammerClient.getInstance().getOnCheckInFileAction(), request);
      }
      else if (iAction == SKIP){
        procede = false;
      }
    }
    else{
      procede = true;
    }
    return procede;
  }

  private int showFileChangedDialog(String fileName){
    String[] initialMessage = DisplayTextLibrary.getInstance().getDisplayTextArray(DisplayTextLibrary.MSG_FILE_CHANGED);
    int initialMessageLen = initialMessage.length;
    String[] message = new String[initialMessageLen + 3];
    
    System.arraycopy(initialMessage, 0, message, 0, initialMessageLen);
    
    message[initialMessageLen] = fileName;
    message[initialMessageLen + 1] = " ";
    message[initialMessageLen + 2] = DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_HOW_PROCEDE);

    String[] options = {DisplayTextLibrary.displayText(DisplayTextLibrary.BTN_FORCE_CHECK_IN),
                        DisplayTextLibrary.displayText(DisplayTextLibrary.BTN_SKIP),
                        DisplayTextLibrary.displayText(DisplayTextLibrary.BTN_CHECK_OUT)};
                        
    int iResponse = JOptionPane.showOptionDialog(CommandCentral.getInstance().getRootAppFrame(),
                            message,
                            DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_HOW_PROCEDE),
                            JOptionPane.DEFAULT_OPTION,
                            JOptionPane.WARNING_MESSAGE,
                            null,
                            options,
                            DisplayTextLibrary.displayText(DisplayTextLibrary.BTN_UNDO));
    return iResponse;
  }
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.