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: ProcessCentral.java$
021: * $FileID: 4126$
022: *
023: * Last change:
024: * $AuthorName: Rob MacGrogan$
025: * $Date: 9/5/03 12:25 PM$
026: * $Comment: Added share file process.$
027: */
028:
029: package org.sourcejammer.client.gui.process;
030:
031: import java.util.Hashtable;
032: import java.util.Vector;
033:
034: /**
035: * Title: $FileName: ProcessCentral.java$<br>
036: * @author $AuthorName: Rob MacGrogan$
037: * @version $VerNum: 6$<br><br>
038: *
039: * $Description: $<br>
040: * $KeyWordsOff: $<br>
041: */
042: public class ProcessCentral implements ProcessContainer, Processes {
043:
044: private static ProcessCentral instance = null;
045: private FireProcessThread thread = null;
046: private Hashtable mhshProcess = new Hashtable();
047:
048: static {
049: instance = new ProcessCentral();
050: }
051:
052: public static ProcessCentral getInstance() {
053: return instance;
054: }
055:
056: private ProcessCentral() {
057: thread = new FireProcessThread();
058: thread.start();
059: registerProcess(new AddFileProcess(), prs_ADD_FILES);
060: registerProcess(new CheckOutFileProcess(), prs_CHECK_OUT);
061: registerProcess(new CheckInFilesProcess(), prs_CHECK_IN);
062: registerProcess(new GetFilesProcess(), prs_GET_FILES);
063: registerProcess(new GetFileVersionProcess(),
064: prs_GET_FILE_VERSION);
065: registerProcess(new GetLabeledVersionProcess(), prs_GET_LABEL);
066: registerProcess(new GetProjectProcess(), prs_GET_PROJECT);
067: registerProcess(new VisualDiffProcess(), prs_VIEW_DIFF);
068: registerProcess(new ViewFileProcess(), prs_VIEW_FILE);
069: registerProcess(new ForceCheckInProcess(), prs_FORCE_CHECK_IN);
070: registerProcess(new CheckOutReportProcess(),
071: prs_CHECK_OUT_REPORT);
072: registerProcess(new RefreshProjectProcess(),
073: prs_REFRESH_PROJECT);
074: registerProcess(new GetChangeListProcess(), prs_GET_CHANGE_LIST);
075: registerProcess(new RebuildLabelProcess(), prs_REBUILD_LABEL);
076: registerProcess(new MakeLabelProcess(), prs_MAKE_LABEL);
077: registerProcess(new RebuildFileViewProcess(),
078: prs_REBUILD_FILE_VIEW);
079: registerProcess(new DeleteLocalFileProcess(),
080: prs_DELETE_LOCAL_FILE);
081: registerProcess(new MoveCopyProjectProcess(),
082: prs_MOVE_COPY_PROJECT_PROCESS);
083: registerProcess(new ShareProjectProcess(), prs_SHARE_PROJECT);
084: registerProcess(new RemoveProjectShareProcess(),
085: prs_REMOVE_PROJECT_SHARE);
086: registerProcess(new BranchProjectProcess(), prs_BRANCH_PROJECT);
087: registerProcess(new ShareFileProcess(), prs_SHARE_FILE);
088: }
089:
090: public void registerProcess(SJProcess process, Integer identifier) {
091: mhshProcess.put(identifier, process);
092: }
093:
094: public void fireProcess(Integer identifier) {
095: fireProcess(identifier, null, 0, 100, 1);
096: }
097:
098: public void fireProcess(Integer identifier, Object info) {
099: fireProcess(identifier, info, 0, 100, 1);
100: }
101:
102: public synchronized void fireProcess(Integer identifier,
103: Object info, int minVal, int maxVal, int increment) {
104: ProcessInfo pInfo = new ProcessInfo();
105: pInfo.setContainer(this );
106: pInfo.setIncrement(increment);
107: pInfo.setInfoObject(info);
108: pInfo.setMaximum(maxVal);
109: pInfo.setMinimum(minVal);
110: ProcessAndInfo procAndInfo = new ProcessAndInfo();
111: procAndInfo.setInfo(pInfo);
112: SJProcess proc = (SJProcess) mhshProcess.get(identifier);
113: procAndInfo.setProcess(proc);
114: thread.addProcess(procAndInfo);
115: notifyAll();
116: }
117:
118: public void incrementProgressBar() {
119: }
120:
121: public void incrementProgressBar(int i) {
122: }
123:
124: protected synchronized void waitTillNotified()
125: throws InterruptedException {
126: wait();
127: }
128:
129: protected synchronized void initializeThreadIfNeeded() {
130: if (thread == null || !thread.isRunning()) {
131: thread = new FireProcessThread();
132: thread.start();
133: }
134: }
135:
136: protected class ProcessAndInfo {
137: SJProcess mProc = null;
138: ProcessInfo info = null;
139:
140: public ProcessAndInfo() {
141: }
142:
143: public void setProcess(SJProcess p) {
144: mProc = p;
145: }
146:
147: public void setInfo(ProcessInfo o) {
148: info = o;
149: }
150:
151: public SJProcess getProcess() {
152: return mProc;
153: }
154:
155: public ProcessInfo getInfo() {
156: return info;
157: }
158: }//end ProcessAndInfo
159:
160: protected class FireProcessThread extends Thread {
161:
162: Vector mvecProcesses = new Vector();
163:
164: public FireProcessThread() {
165: this .setDaemon(true);
166: }
167:
168: private boolean mbRunning = false;
169:
170: public void addProcess(ProcessAndInfo p) {
171: mvecProcesses.add(p);
172: }
173:
174: public void run() {
175: try {
176: mbRunning = true;
177: while (true) {
178: while (mvecProcesses.size() > 0) {
179: ProcessAndInfo p = (ProcessAndInfo) mvecProcesses
180: .remove(0);
181: p.getProcess().fireProcess(p.getInfo());
182: }
183: try {
184: ProcessCentral.getInstance().waitTillNotified();
185: } catch (InterruptedException ex) {
186: //Just continue.
187: }
188: }
189: } catch (Exception ex) {
190: System.out.println("Exception in FireProcessThread.");
191: ex.printStackTrace();
192: } finally {
193: mbRunning = false;
194: }
195: }//end run()
196:
197: public boolean isRunning() {
198: return mbRunning;
199: }
200: }//end FireActionThread
201:
202: /**
203: * @see java.lang.Object#finalize()
204: */
205: protected void finalize() throws Throwable {
206: try {
207: thread.interrupt();
208: thread = null;
209: } finally {
210: super.finalize();
211: }
212: }
213:
214: }
|