001:/*
002: * Copyright (c) 2000, Jacob Smullyan.
003: *
004: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
005: * for the latest version.
006: *
007: * SkunkDAV is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License as published
009: * by the Free Software Foundation; either version 2, or (at your option)
010: * any later version.
011: *
012: * SkunkDAV is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with SkunkDAV; see the file COPYING. If not, write to the Free
019: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
020: * 02111-1307, USA.
021:*/
022:
023:package org.skunk.dav.client.gui.action;
024:
025:import java.awt.event.ActionEvent;
026:import java.io.File;
027:import java.net.URLDecoder;
028:import javax.swing.AbstractAction;
029:import javax.swing.JFileChooser;
030:import javax.swing.JOptionPane;
031:import org.skunk.assert.Assertion;
032:import org.skunk.dav.client.DAVConstants;
033:import org.skunk.dav.client.DAVFile;
034:import org.skunk.dav.client.gui.DAVFileChooser;
035:import org.skunk.dav.client.gui.DAVTreeNode;
036:import org.skunk.dav.client.gui.Explorer;
037:import org.skunk.dav.client.gui.ResourceManager;
038:import org.skunk.dav.client.gui.ServerData;
039:import org.skunk.trace.Debug;
040:
041:
042:public class CopyAction extends AbstractAction
043:{
044: private Explorer ex;
045: private DAVTreeNode node;
046: private DAVFile file;
047: private String destinationURL;
048:
049: public CopyAction(Explorer ex, DAVTreeNode node,
050: DAVFile file, String destinationURL)
051: {
052: this .ex=ex;
053: this .node=node;
054: this .file=file;
055: this .destinationURL=destinationURL;
056: }
057:
058: public CopyAction(Explorer ex, DAVFile file)
059: {
060: this (ex, null, file, null);
061: }
062:
063: public CopyAction(Explorer ex)
064: {
065: this (ex, null, null, null);
066: }
067:
068: public void actionPerformed(ActionEvent ae)
069: {
070: DAVTreeNode localNode;
071: DAVFile localFile=(file!=null)
072: ? file
073: : ex.getSelectedTableFile();
074: if (localFile==null)
075: {
076: DAVFileChooser.ChoiceStruct choice=ex.chooseFile(null,
077: getDialogTitle(),
078: false,
079: null);
080: if (choice==null)
081: {
082: Debug.trace(this , Debug.DP3, "user aborted copy");
083: return;
084: }
085: DAVTreeNode leafNode=choice.getSelectedLeaf();
086: if (leafNode==null)
087: {
088: Debug.trace(this , Debug.DP3, "user aborted copy");
089: return;
090: }
091:
092: localFile=leafNode.getDAVFile();
093: if (localFile==null)
094: {
095: Debug.trace(this , Debug.DP3, "selected node has null file: {0}",
096: leafNode);
097: return;
098: }
099: //user may have navigated to any node; need to find which one
100: //corresponds to the DAVFile
101: localNode=ex.getNodeForFile(localFile);
102: }
103: else
104: {
105: localNode=(node!=null)
106: ? node
107: : ex.getSelectedNode();
108: Assertion.assert((localNode!=null), "node is not null");
109: }
110: String localDestinationURL=(destinationURL!=null)
111: ? destinationURL
112: : obtainDestination(URLDecoder.decode(localFile.getFileName()), localNode);
113: if (localDestinationURL!=null)
114: execute(ex, localNode, localFile, localDestinationURL);
115: }
116:
117: protected void execute(Explorer ex, DAVTreeNode node, DAVFile file, String destinationURL)
118: {
119: ex.copy(node, file, destinationURL);
120: }
121:
122: protected String getDialogTitle()
123: {
124: return ResourceManager.getMessage(ResourceManager.COPY_DIALOG_TITLE);
125: }
126:
127: protected Explorer getExplorer()
128: {
129: return ex;
130: }
131:
132: protected String obtainDestination(String filename, DAVTreeNode node)
133: {
134: String title=getDialogTitle();
135: DAVFileChooser.ChoiceStruct choice=ex.chooseFile(node, title, true, filename);
136: if (choice==null)
137: return null;
138: DAVTreeNode parentNode=choice.getParentNode();
139: String newName=choice.getFilename();
140: if (parentNode==null || newName==null)
141: return null;
142: String destination=new StringBuffer()
143: .append(parentNode.getDAVFile().getFullNameWithProtocol())
144: .append(newName)
145: .toString();
146:
147: Debug.trace(this , Debug.DP3, "returning from obtainDestination(): {0}",
148: destination);
149: return destination;
150: }
151:}
152:
153:/* $Log: CopyAction.java,v $
154:/* Revision 1.11 2001/07/18 03:23:07 smulloni
155:/* added URL decoding to filename display in the table model and copy/move/rename dialogs;
156:/* not in the PropertiesDialog table, however.
157:/*
158:/* Revision 1.10 2001/01/03 20:11:31 smulloni
159:/* the DAVFileChooser now replaces JFileChooser for remote file access.
160:/* DAVMethod now has a protocol property.
161:/*
162:/* Revision 1.9 2000/12/19 22:36:05 smulloni
163:/* adjustments to preamble.
164:/*
165:/* Revision 1.8 2000/12/03 23:53:26 smulloni
166:/* added license and copyright preamble to java files.
167:/*
168:/* Revision 1.7 2000/11/10 22:40:09 smullyan
169:/* added icon to table for resource type; fixes to copy and move; disabling of
170:/* menu items that are inappropriate.
171:/*
172:/* Revision 1.6 2000/11/09 23:35:01 smullyan
173:/* log added to every Java file, with the help of python. Lock stealing
174:/* implemented, and treatment of locks made more robust.
175:/* */
|