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: CheckOutFileProcess.java$
021: * $FileID: 4132$
022: *
023: * Last change:
024: * $AuthorName: Rob MacGrogan$
025: * $Date: 8/7/03 1:21 PM$
026: * $Comment: Bug fix: Check in from check out report was failing
027: * with null pointer. Now passing NodeInfo to CommandCentral checkin
028: * and force check in methods.$
029: */
030:
031: package org.sourcejammer.client.gui.process;
032:
033: import org.sourcejammer.client.DisplayTextLibrary;
034: import org.sourcejammer.client.SourceJammerClient;
035: import org.sourcejammer.client.gui.CommandCentral;
036: import org.sourcejammer.client.gui.GUICommandException;
037: import org.sourcejammer.client.gui.MessageBoxUtil;
038: import org.sourcejammer.client.gui.process.info.CheckOutFileProcessInfo;
039: import org.sourcejammer.client.plugin.EventTimingType;
040: import org.sourcejammer.project.view.NodeInfo;
041: import org.sourcejammer.project.view.SJRequest;
042: import org.sourcejammer.util.SourceJammerConnectionException;
043:
044: import java.awt.Cursor;
045: import java.io.File;
046: import java.io.IOException;
047:
048: import javax.swing.JOptionPane;
049:
050: import org.sourcejammer.client.gui.action.ActionCentral;
051:
052: /**
053: * Title: $FileName: CheckOutFileProcess.java$
054: * @version $VerNum: 8$
055: * @author $AuthorName: Rob MacGrogan$<br><br>
056: *
057: * $Description: $
058: * $KeyWordsOff: $
059: */
060: public class CheckOutFileProcess extends AbstractProcess {
061:
062: private static final int FORCE_CHECK_IN = 0;
063: private static final int SKIP = 1;
064: private static final int CHECK_OUT = 2;
065:
066: public CheckOutFileProcess() {
067: }
068:
069: public void process(Object info) {
070: CommandCentral oCommand = CommandCentral.getInstance();
071: try {
072: if (info instanceof CheckOutFileProcessInfo) {
073: CheckOutFileProcessInfo oInfo = (CheckOutFileProcessInfo) info;
074: oCommand.getRootAppFrame().setCursor(
075: Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
076: String[] sa = oInfo.getFileNames();
077: for (int i = 0; i < sa.length; i++) {
078:
079: long lFileID = oInfo.getParentProjectTreeNode()
080: .getFileUniqueIDFromName(sa[i]);
081: if (checkLocalFileStatus(sa[i], oInfo
082: .getTargetDirectory(), lFileID, oInfo
083: .getRequest())) {
084: oCommand.checkOutFile(lFileID, sa[i], oInfo
085: .getTargetDirectory(), oInfo
086: .getEolType(), oInfo.getRequest());
087: }
088: }
089: ActionCentral.getInstance().fireActionInvokeLater(
090: ActionCentral.act_REFRESH_PROJECT);
091:
092: //Notify
093: SourceJammerClient.getInstance().getFileListeners()
094: .notifyFileCheckedOut(oInfo.getRequest(), null,
095: EventTimingType.AFTER_EVENT, null);
096:
097: oCommand.getRootAppFrame().setCursor(
098: Cursor.getDefaultCursor());
099: }
100: } catch (Exception ex) {
101: ex.printStackTrace();
102: MessageBoxUtil.displayErrorMessage(ex.getMessage());
103: } finally {
104: CommandCentral.getInstance().getRootAppFrame().setCursor(
105: Cursor.getDefaultCursor());
106: }
107: }
108:
109: private boolean checkLocalFileStatus(String fileName,
110: File targetDir, long fileID, SJRequest request)
111: throws IOException, SourceJammerConnectionException,
112: GUICommandException {
113: boolean procede = true;
114: boolean fileChanged = CommandCentral.getInstance()
115: .hasLocalFileChanged(fileName, targetDir);
116: if (fileChanged) {
117: //prompt user for how to procede.
118: int iAction = showFileChangedDialog(fileName);
119: if (iAction == FORCE_CHECK_IN) {
120: NodeInfo fileNode = CommandCentral.getInstance()
121: .getSelectedFileNodeInfo(fileName);
122: CommandCentral.getInstance().forceCheckIn(
123: fileNode,
124: targetDir,
125: "",
126: SourceJammerClient.getInstance()
127: .getOnCheckInFileAction(), request);
128: } else if (iAction == SKIP) {
129: procede = false;
130: }
131: } else {
132: procede = true;
133: }
134: return procede;
135: }
136:
137: private int showFileChangedDialog(String fileName) {
138: String[] initialMessage = DisplayTextLibrary.getInstance()
139: .getDisplayTextArray(
140: DisplayTextLibrary.MSG_FILE_CHANGED);
141: int initialMessageLen = initialMessage.length;
142: String[] message = new String[initialMessageLen + 3];
143:
144: System.arraycopy(initialMessage, 0, message, 0,
145: initialMessageLen);
146:
147: message[initialMessageLen] = fileName;
148: message[initialMessageLen + 1] = " ";
149: message[initialMessageLen + 2] = DisplayTextLibrary
150: .displayText(DisplayTextLibrary.LBL_HOW_PROCEDE);
151:
152: String[] options = {
153: DisplayTextLibrary
154: .displayText(DisplayTextLibrary.BTN_FORCE_CHECK_IN),
155: DisplayTextLibrary
156: .displayText(DisplayTextLibrary.BTN_SKIP),
157: DisplayTextLibrary
158: .displayText(DisplayTextLibrary.BTN_CHECK_OUT) };
159:
160: int iResponse = JOptionPane
161: .showOptionDialog(
162: CommandCentral.getInstance().getRootAppFrame(),
163: message,
164: DisplayTextLibrary
165: .displayText(DisplayTextLibrary.LBL_HOW_PROCEDE),
166: JOptionPane.DEFAULT_OPTION,
167: JOptionPane.WARNING_MESSAGE,
168: null,
169: options,
170: DisplayTextLibrary
171: .displayText(DisplayTextLibrary.BTN_UNDO));
172: return iResponse;
173: }
174:
175: }
|