001: /*
002: * Copyright (C) 2001, 2002 Robert MacGrogan
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: *
019: * $Archive: SourceJammer$
020: * $FileName: MoveCopyFileAction.java$
021: * $FileID: 4080$
022: *
023: * Last change:
024: * $AuthorName: Rob MacGrogan$
025: * $Date: 6/24/03 12:53 AM$
026: * $Comment: Moved message box/error dialog methods to MessageBoxUtil.$
027: */
028:
029: package org.sourcejammer.client.gui.action;
030:
031: import java.awt.event.ActionEvent;
032: import javax.swing.*;
033: import javax.swing.tree.*;
034:
035: import org.sourcejammer.client.gui.CommandCentral;
036: import org.sourcejammer.client.gui.MessageBoxUtil;
037: import org.sourcejammer.client.gui.ProjectTreeNode;
038: import org.sourcejammer.client.gui.dialog.CopyMoveDialog;
039: import org.sourcejammer.client.gui.icons.IconBank;
040: import org.sourcejammer.client.plugin.EventTimingType;
041: import org.sourcejammer.client.DisplayTextLibrary;
042: import org.sourcejammer.client.SourceJammerClient;
043: import org.sourcejammer.client.gui.dialog.ClickValues;
044: import org.sourcejammer.client.gui.NoSelectionException;
045: import org.sourcejammer.project.NodeDoesNotExistException;
046: import org.sourcejammer.project.view.NodeInfo;
047: import org.sourcejammer.project.view.SJRequest;
048: import org.sourcejammer.util.SourceJammerConnectionException;
049: import org.sourcejammer.client.gui.GUICommandException;
050: import org.sourcejammer.client.gui.GuiUtil;
051:
052: /**
053: * Title: $FileName: MoveCopyFileAction.java$
054: * @version $VerNum: 5$
055: * @author $AuthorName: Rob MacGrogan$<br><br>
056: *
057: * $Description: $<br>
058: * $KeyWordsOff: $<br>
059: */
060: public class MoveCopyFileAction extends AbstractAction {
061:
062: public MoveCopyFileAction() {
063: super (DisplayTextLibrary
064: .displayText(DisplayTextLibrary.ACT_MOVE_COPY_FILE),
065: IconBank.getInstance().getIcon(IconBank.BLANK_TOOL));
066: }
067:
068: public void actionPerformed(ActionEvent ev) {
069: try {
070: CommandCentral cmd = CommandCentral.getInstance();
071: SJRequest request = cmd.getBaseRequest();
072:
073: SourceJammerClient.getInstance().getFileListeners()
074: .notifyFileMoveCopy(request, ev,
075: EventTimingType.BEFORE_EVENT, null);
076:
077: String[] saSelectedFiles = cmd.getSelectedFileNames();
078: CopyMoveDialog dialog = new CopyMoveDialog(cmd
079: .getRootAppFrame(), saSelectedFiles, true);
080:
081: int iButtonClick = -1;
082: boolean bShowDialog = true;
083: long lSelectedProjectID = -1;
084: while (bShowDialog) {
085: iButtonClick = dialog.showDialog(cmd.getRootAppFrame());
086: if (iButtonClick == ClickValues.CANCEL_BUTTON_CLICKED) {
087: bShowDialog = false;
088: } else {
089: try {
090: lSelectedProjectID = dialog
091: .getDestinationProjectID();
092: bShowDialog = false;
093: } catch (NoSelectionException ex) {
094: MessageBoxUtil.displayErrorMessage(ex
095: .getMessage(), true);
096: bShowDialog = true;
097: }
098: }
099: }//end while.
100:
101: if (lSelectedProjectID > -1) {
102: //We've got a selection.
103: String moveCopy = dialog.getMoveCopyType();
104: boolean isCopy = moveCopy.equals(CopyMoveDialog.COPY);
105: moveCopy(isCopy, lSelectedProjectID, saSelectedFiles,
106: request);
107:
108: //Now update target project tree node.
109: JTree dialogTree = dialog.getTree();
110: TreePath path = dialogTree.getSelectionPath();
111: ProjectTreeNode targetNode = (ProjectTreeNode) path
112: .getLastPathComponent();
113: GuiUtil.refreshTreeNodeContents(targetNode);
114:
115: //Update current tree node if this is a move.
116: if (!isCopy) {
117: ActionCentral.getInstance().fireActionThisThread(
118: Actions.act_REFRESH_PROJECT);
119: }
120: }
121:
122: SourceJammerClient.getInstance().getFileListeners()
123: .notifyFileMoveCopy(request, null,
124: EventTimingType.AFTER_EVENT, null);
125:
126: } catch (Exception ex) {
127: MessageBoxUtil.displayErrorMessage(ex.getMessage(), true);
128: }
129: }
130:
131: private void moveCopy(boolean isCopy, long toProjectID,
132: String[] fileNames, SJRequest request)
133: throws NodeDoesNotExistException, GUICommandException,
134: SourceJammerConnectionException {
135: CommandCentral central = CommandCentral.getInstance();
136: ProjectTreeNode parent = central.getCurrentTreeNode();
137: long fromProjectID = parent.getUniqueID();
138:
139: for (int i = 0; i < fileNames.length; i++) {
140: NodeInfo flInfo = central
141: .getSelectedFileNodeInfo(fileNames[i]);
142: if (isCopy) {
143: central.copyFile(flInfo, fromProjectID, toProjectID,
144: request);
145: } else {
146: central.moveFile(flInfo, fromProjectID, toProjectID,
147: request);
148: }
149: }
150: }
151: }
|