001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.ide.elixir.version;
053:
054: import java.io.File;
055: import java.io.IOException;
056: import javax.swing.JMenuItem;
057: import com.elixirtech.tree.TNode;
058: import org.acm.seguin.util.FileSettings;
059: import org.acm.seguin.util.MissingSettingsException;
060: import org.acm.seguin.version.VersionControl;
061: import org.acm.seguin.version.VersionControlCache;
062:
063: /**
064: * Interact with version control
065: *
066: *@author Chris Seguin
067: *@created July 12, 1999
068: */
069: public class ElixirContainsThread extends Thread {
070: // Instance Variables
071: private VersionControl delegate;
072: private ElixirVersionControl evc;
073: private JMenuItem menu;
074: private TNode parent;
075:
076: /**
077: * Constructor
078: *
079: *@param initMenuItem The menu item
080: *@param initParent The initial parent
081: *@param initDelegate The delegate
082: *@param initEVC Description of Parameter
083: */
084: public ElixirContainsThread(JMenuItem initMenuItem,
085: TNode initParent, VersionControl initDelegate,
086: ElixirVersionControl initEVC) {
087: menu = initMenuItem;
088: parent = initParent;
089: delegate = initDelegate;
090: evc = initEVC;
091: }
092:
093: /**
094: * Determines if the file is under souce control
095: *
096: *@param name the name of the file
097: *@return true if it is under source control
098: */
099: private boolean isUnderSourceControl(String name) {
100: if (name == null) {
101: return false;
102: }
103:
104: try {
105: FileSettings bundle = FileSettings
106: .getRefactorySettings("vss");
107:
108: int index = 1;
109: while (true) {
110: String next = bundle.getString("extension." + index);
111: System.out.println("\t\tComparing: [" + name
112: + "] to [" + next + "]");
113: if (name.endsWith(next)) {
114: System.out.println("\t\tFound it");
115: return true;
116: }
117: index++;
118: }
119: } catch (MissingSettingsException mse) {
120: // Finished
121: }
122:
123: return false;
124: }
125:
126: /**
127: * Description of the Method
128: */
129: private void add() {
130: menu.setText("Add");
131: menu.setEnabled(false);
132: menu.addActionListener(new AddListener(evc, parent
133: .getFullName(), parent.getName()));
134: }
135:
136: /**
137: * Description of the Method
138: */
139: private void checkIn() {
140: VersionControlCache cache = VersionControlCache.getCache();
141: String filename = parent.getFullName();
142: menu.setText("Check In");
143: menu
144: .setEnabled(cache.lookup(filename) == VersionControlCache.CHECK_IN);
145: menu.addActionListener(new CheckInListener(evc, filename,
146: parent.getName()));
147: }
148:
149: /**
150: * Sets the menu up to say that it is being checked out
151: */
152: private void checkOut() {
153: boolean enabled = true;
154: String filename = parent.getFullName();
155: VersionControlCache cache = VersionControlCache.getCache();
156:
157: if (cache.isInCache(filename)) {
158: enabled = (cache.lookup(filename) == VersionControlCache.CHECK_OUT);
159: } else {
160: cache.add(filename, VersionControlCache.CHECK_OUT);
161: }
162:
163: menu.setText("Check Out");
164: menu.setEnabled(enabled);
165: menu.addActionListener(new CheckOutListener(evc, filename,
166: parent.getName()));
167: }
168:
169: /**
170: * Is this file contained in visual source safe?
171: *
172: *@param filename The full path of the file in question
173: *@return Returns true if it is in source safe
174: */
175: public int contains(String filename) {
176: // Start with the cache
177: VersionControlCache cache = VersionControlCache.getCache();
178: if (cache.isInCache(filename)) {
179: return cache.lookup(filename);
180: }
181:
182: boolean way = delegate.contains(filename);
183: int result;
184:
185: if (way) {
186: result = VersionControlCache.CHECK_IN;
187: } else {
188: result = VersionControlCache.ADD;
189: }
190:
191: cache.add(filename, result);
192: return result;
193: }
194:
195: /**
196: * Actually do the work
197: */
198: public void run() {
199: String name = parent.getName();
200:
201: if (!isUnderSourceControl(name)) {
202: menu.setText("Not under source control");
203: menu.setEnabled(false);
204: return;
205: }
206:
207: System.out.println("Full Name: " + parent.getFullName());
208: File file = new File(parent.getFullName());
209: if (!file.canWrite()) {
210: checkOut();
211: } else if (contains(parent.getFullName()) == VersionControlCache.ADD) {
212: add();
213: } else {
214: checkIn();
215: }
216:
217: menu.repaint();
218: }
219: }
220: // EOF
|