/*
* Gruntspud
*
* Copyright (C) 2002 Brett Smith.
*
* Written by: Brett Smith <t_magicthize@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License
* as published by the Free Software Foundation; either version 2 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package gruntspud.actions;
import gruntspud.CVSCommandHandler;
import gruntspud.CVSFileNode;
import gruntspud.Constants;
import gruntspud.GruntspudContext;
import gruntspud.ResourceUtil;
import gruntspud.ui.OptionDialog;
import gruntspud.ui.OutputOptionWrapperPanel;
import gruntspud.ui.UIUtil;
import gruntspud.ui.commandoptions.AdvancedAddOptionsPane;
import gruntspud.ui.view.ViewManager;
import java.awt.event.ActionEvent;
import java.util.ResourceBundle;
import javax.swing.JComponent;
import org.netbeans.lib.cvsclient.command.Command;
import org.netbeans.lib.cvsclient.command.add.AddCommand;
/**
* Action that adds the current selection to CVS
*
* @author magicthize
*/
public class AddAction extends DefaultGruntspudAction {
static ResourceBundle res = ResourceBundle.getBundle("gruntspud.actions.ResourceBundle");
/**
* Constructor for the AddAction object
*
* @param context context
*/
public AddAction(GruntspudContext context) {
super(res, "addAction", context);
putValue(GruntspudAction.ICON, UIUtil.getCachedIcon(Constants.ICON_TOOL_ADD));
putValue(DefaultGruntspudAction.SMALL_ICON, UIUtil.getCachedIcon(Constants.ICON_TOOL_SMALL_ADD));
setUpdatesFiles(true);
}
/**
* Constructor that allows action to be built from a resource bundle
*
* @param bundle resource bundle
* @param actionPrefix prefix in resource bundle for actions properties
* @param context context
*/
public AddAction(ResourceBundle bundle, String actionPrefix, GruntspudContext context) {
super(bundle, actionPrefix, context);
setUpdatesFiles(true);
}
/* (non-Javadoc)
* @see gruntspud.actions.GruntspudAction#checkAvailable()
*/
public boolean checkAvailable() {
ViewManager vm = getContext().getViewManager();
CVSFileNode[] sel = vm.getSelectedNodes();
return !CVSCommandHandler.getInstance().isCommandRunning()
&& vm.isHomeExists()
&& (sel != null)
&& (sel.length > 0)
&& ((vm.getSelectedInCVSCount() == 0) || ((vm.getSelectedInCVSCount() == vm.getSelectedNonExistantCount()) && ((sel.length - vm
.getSelectedInCVSCount()) == (sel.length - vm
.getSelectedNonExistantCount()))))
&& (vm.getSelectedHaveRootCount() == sel.length)
&& ((vm.getSelectedFileCount() == sel.length) || ((vm.getSelectedFileCount() == 0) && (vm
.getSelectedDirectoryCount() > 0)));
}
/* (non-Javadoc)
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(final ActionEvent evt) {
final JComponent parent = getContext().getHost().getMainComponent();
final CVSFileNode[] sel = getContext().getViewManager().getSelectedNodes();
OptionDialog.Option ok = new OptionDialog.Option(res.getString("addAction.optionDialog.option.ok.text"), res.getString(
"addAction.optionDialog.option.ok.toolTipText"),
ResourceUtil.getResourceMnemonic(res, "addAction.optionDialog.option.ok.mnemonic"));
OptionDialog.Option cancel = new OptionDialog.Option(res.getString("addAction.optionDialog.option.cancel.text"), res
.getString("addAction.optionDialog.option.cancel.toolTipText"),
ResourceUtil.getResourceMnemonic(res, "addAction.optionDialog.option.cancel.mnemonic"));
// if(sel.length == 1 && !sel[0].isLeaf()) {
final AdvancedAddOptionsPane addOptions = new AdvancedAddOptionsPane(getContext(), sel);
if (!isBypassOptions(evt.getModifiers())) {
OptionDialog.Option opt = OptionDialog.showOptionDialog("add", getContext(), parent, new OptionDialog.Option[]{ok,
cancel},
new OutputOptionWrapperPanel(getContext(), addOptions, this, "add"), res.getString(
"addAction.optionDialog.title"), ok,
new OptionDialog.Callback() {
public boolean canClose(OptionDialog dialog, OptionDialog.Option option) {
return addOptions.validateTabs();
}
});
if (opt != ok) {
return;
}
}
else {
if (!addOptions.validateTabs())
return;
}
AdvancedAddOptionsPane.AddNodeSelection selectedToAdd = addOptions.getSelection();
AddCommand cmd = new AddCommand();
CVSCommandHandler
.getInstance()
.runCommandGroup(parent, getContext(), null, new Command[]{cmd}, selectedToAdd.getNodes(),
selectedToAdd.getTypes(), false, null, null, this,
getEnabledOptionalListeners());
// }
// else {
// final AddOptionsPane addOptions = new AddOptionsPane(getContext(), sel);
// if (!isBypassOptions(evt.getModifiers())) {
// OptionDialog.Option opt = OptionDialog.showOptionDialog("add", getContext(), parent, new OptionDialog.Option[]{ok,
// cancel},
// new OutputOptionWrapperPanel(getContext(), addOptions, this, "add"), res.getString(
// "addAction.optionDialog.title"), ok,
// new OptionDialog.Callback() {
// public boolean canClose(OptionDialog dialog, OptionDialog.Option option) {
// return addOptions.validateTabs();
// }
// });
//
// if (opt != ok) {
// return;
// }
//
// }
// else {
// if (!addOptions.validateTabs())
// return;
// }
//
// addOptions.applyTabs();
//
// CVSSubstType[] types = addOptions.getTypes();
// AddCommand cmd = new AddCommand();
// CVSCommandHandler
// .getInstance()
// .runCommandGroup(parent, getContext(), null, new Command[]{cmd}, sel, types, false, null, null, this,
// getEnabledOptionalListeners());
// }
}
}
|