DeleteLocalFileAction.java :  » Source-Control » sourcejammer » org » sourcejammer » client » gui » action » Java Open Source

Java Open Source » Source Control » sourcejammer 
sourcejammer » org » sourcejammer » client » gui » action » DeleteLocalFileAction.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: DeleteLocalFileAction.java$
 * $FileID: 4077$
 *
 * Last change:
 * $AuthorName: Rob MacGrogan$
 * $Date: 6/24/03 12:56 AM$
 * $Comment: Moved message box/error dialog methods to MessageBoxUtil.$
 */
package org.sourcejammer.client.gui.action;

import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;

import javax.swing.AbstractAction;
import javax.swing.JOptionPane;

import org.sourcejammer.client.DisplayTextLibrary;
import org.sourcejammer.client.filesys.FileSysUtil;
import org.sourcejammer.client.gui.CommandCentral;
import org.sourcejammer.client.gui.MessageBoxUtil;
import org.sourcejammer.client.gui.ProjectTreeNode;
import org.sourcejammer.client.gui.conf.ExcludeFilesByNameFilter;
import org.sourcejammer.client.gui.conf.GuiConf;
import org.sourcejammer.client.gui.dialog.AddFilesDialog;
import org.sourcejammer.client.gui.dialog.ClickValues;
import org.sourcejammer.client.gui.icons.IconBank;
import org.sourcejammer.client.gui.process.ProcessCentral;
import org.sourcejammer.client.gui.process.info.AddFileProcessInfo;
import org.sourcejammer.project.view.NodeName;
import org.sourcejammer.util.AppConfig;
import org.sourcejammer.util.BadMethodArgumentException;

/**
 * Title: $FileName: DeleteLocalFileAction.java$
 * @version $VerNum: 4$
 * @author $AuthorName: Rob MacGrogan$<br><br>
 * 
 * $Description: Deletes selected local files.$<br>
 * $KeyWordsOff: $<br>
 */
public class DeleteLocalFileAction extends AbstractAction {

  public DeleteLocalFileAction(){
    super(DisplayTextLibrary.displayText(DisplayTextLibrary.act_DELETE_LOCAL_FILE),
          IconBank.getInstance().getIcon(IconBank.BLANK_TOOL));
  }

  /**
   * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
   */
  public void actionPerformed(ActionEvent ev) {
    CommandCentral oCommand = CommandCentral.getInstance();
    try {
      GuiConf oConf = oCommand.getGuiConf();
      ProjectTreeNode ndProject = oCommand.getCurrentTreeNode();
      NodeName oCurrName = ndProject.getNodeName();
      File flDefaultDir = oConf.getDefaultWorkingDirectory(oCurrName);

      if (flDefaultDir != null){
        if (! flDefaultDir.exists()){
          throw new IOException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_DIR_NO_EXIST));
        }

        //Get Selected files.
        String[] saSelectedFiles = oCommand.getSelectedFileNames();

        //Prompt user.
        String[] messages = DisplayTextLibrary.getInstance().getDisplayTextArray(DisplayTextLibrary.MSG_CONFIRM_DELETE_LOCAL_FILE);
        int iResponse = JOptionPane.showConfirmDialog(oCommand.getRootAppFrame(),
                                messages,
                                DisplayTextLibrary.displayText(DisplayTextLibrary.LBL_WARNING),
                                JOptionPane.YES_NO_OPTION,
                                JOptionPane.WARNING_MESSAGE);
        boolean bProcede = true;
        if (iResponse == JOptionPane.YES_OPTION){
          bProcede = true;
        }
        else {
          bProcede = false;
        }
        if(bProcede){
          AddFileProcessInfo info = new AddFileProcessInfo();
          info.setSelectedFiles(saSelectedFiles);
          info.setDefaultDirectory(flDefaultDir);
          ProcessCentral.getInstance().fireProcess(ProcessCentral.prs_DELETE_LOCAL_FILE, info);
        }
      }
      else {
        throw new BadMethodArgumentException(DisplayTextLibrary.displayText(DisplayTextLibrary.ERR_NO_DEFAULT_DIR));
      }
    }
    catch (Exception ex){
      ex.printStackTrace();
      MessageBoxUtil.displayErrorMessage(ex.getMessage(), true);
    }
  }

}
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.