1 | /*
|
---|
2 | * ====================================================================
|
---|
3 | * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
|
---|
4 | *
|
---|
5 | * This software is licensed as described in the file COPYING, which
|
---|
6 | * you should have received as part of this distribution. The terms
|
---|
7 | * are also available at http://svnkit.com/license.html
|
---|
8 | * If newer versions of this license are posted there, you may use a
|
---|
9 | * newer version instead, at your option.
|
---|
10 | * ====================================================================
|
---|
11 | */
|
---|
12 | package org.greenstone.admin.gui;
|
---|
13 |
|
---|
14 | import java.awt.Graphics;
|
---|
15 | import java.util.List;
|
---|
16 |
|
---|
17 | import javax.swing.JOptionPane;
|
---|
18 | import javax.swing.JScrollPane;
|
---|
19 | import javax.swing.JTextArea;
|
---|
20 | import javax.swing.SwingUtilities;
|
---|
21 |
|
---|
22 | import org.tmatesoft.svn.core.SVNCancelException;
|
---|
23 | import org.tmatesoft.svn.core.wc.ISVNEventHandler;
|
---|
24 | import org.tmatesoft.svn.core.wc.SVNEvent;
|
---|
25 | import org.tmatesoft.svn.core.wc.SVNStatusType;
|
---|
26 | import org.tmatesoft.svn.core.wc.SVNEventAction;
|
---|
27 |
|
---|
28 | /*
|
---|
29 | * This class is an implementation of ISVNEventHandler intended for processing
|
---|
30 | * events generated by do*() methods of an SVNUpdateClient object. An instance
|
---|
31 | * of this handler will be provided to an SVNUpdateClient. When calling, for
|
---|
32 | * example, SVNWCClient.doUpdate(..) on some path, that method will generate an
|
---|
33 | * event for each 'update'/'add'/'delete'/.. action it will perform upon every
|
---|
34 | * path being updated. And this event is passed to
|
---|
35 | *
|
---|
36 | * ISVNEventHandler.handleEvent(SVNEvent event, double progress)
|
---|
37 | *
|
---|
38 | * to notify the handler. The event contains detailed information about the
|
---|
39 | * path, action performed upon the path and some other.
|
---|
40 | */
|
---|
41 | public class UpdateEventHandler extends Thread implements ISVNEventHandler, Runnable {
|
---|
42 | /*
|
---|
43 | * progress is currently reserved for future purposes and now is always
|
---|
44 | * ISVNEventHandler.UNKNOWN
|
---|
45 | */
|
---|
46 |
|
---|
47 | JTextArea messageArea = new JTextArea();
|
---|
48 | String localDirectory;
|
---|
49 | String extensionName;
|
---|
50 | public UpdateEventHandler(JTextArea messgaeTextArea, String dir, String extensionName) {
|
---|
51 |
|
---|
52 |
|
---|
53 | messageArea = messgaeTextArea;
|
---|
54 | messageArea.setEditable(false);
|
---|
55 | messageArea.setLineWrap(true);
|
---|
56 | messageArea.setWrapStyleWord(true);
|
---|
57 |
|
---|
58 | localDirectory = dir;
|
---|
59 | this.extensionName = extensionName;
|
---|
60 |
|
---|
61 | }
|
---|
62 |
|
---|
63 | public UpdateEventHandler() {
|
---|
64 | // TODO Auto-generated constructor stub
|
---|
65 | }
|
---|
66 |
|
---|
67 | public void handleEvent(SVNEvent event, double progress) {
|
---|
68 | /*
|
---|
69 | * Gets the current action. An action is represented by SVNEventAction.
|
---|
70 | * In case of an update an action can be determined via comparing
|
---|
71 | * SVNEvent.getAction() and SVNEventAction.UPDATE_-like constants.
|
---|
72 | */
|
---|
73 |
|
---|
74 | //System.out.println(" event occurs");
|
---|
75 | SVNEventAction action = event.getAction();
|
---|
76 | String pathChangeType = " ";
|
---|
77 | if (action == SVNEventAction.UPDATE_ADD) {
|
---|
78 | /*
|
---|
79 | * the item was added
|
---|
80 | */
|
---|
81 | pathChangeType = "A";
|
---|
82 | } else if (action == SVNEventAction.UPDATE_DELETE) {
|
---|
83 | /*
|
---|
84 | * the item was deleted
|
---|
85 | */
|
---|
86 | pathChangeType = "D";
|
---|
87 | } else if (action == SVNEventAction.UPDATE_UPDATE) {
|
---|
88 | /*
|
---|
89 | * Find out in details what state the item is (after having been
|
---|
90 | * updated).
|
---|
91 | *
|
---|
92 | * Gets the status of file/directory item contents. It is
|
---|
93 | * SVNStatusType who contains information on the state of an item.
|
---|
94 | */
|
---|
95 | SVNStatusType contentsStatus = event.getContentsStatus();
|
---|
96 | if (contentsStatus == SVNStatusType.CHANGED) {
|
---|
97 | /*
|
---|
98 | * the item was modified in the repository (got the changes
|
---|
99 | * from the repository
|
---|
100 | */
|
---|
101 | pathChangeType = "U";
|
---|
102 | }else if (contentsStatus == SVNStatusType.CONFLICTED) {
|
---|
103 | /*
|
---|
104 | * The file item is in a state of Conflict. That is, changes
|
---|
105 | * received from the repository during an update, overlap with
|
---|
106 | * local changes the user has in his working copy.
|
---|
107 | */
|
---|
108 | pathChangeType = "C";
|
---|
109 | } else if (contentsStatus == SVNStatusType.MERGED) {
|
---|
110 | /*
|
---|
111 | * The file item was merGed (those changes that came from the
|
---|
112 | * repository did not overlap local changes and were merged
|
---|
113 | * into the file).
|
---|
114 | */
|
---|
115 | pathChangeType = "G";
|
---|
116 | }
|
---|
117 | } else if (action == SVNEventAction.UPDATE_EXTERNAL) {
|
---|
118 | /*for externals definitions*/
|
---|
119 | System.out.println("Fetching external item into '"
|
---|
120 | + event.getFile().getAbsolutePath() + "'");
|
---|
121 | System.out.println("External at revision " + event.getRevision());
|
---|
122 | return;
|
---|
123 | } else if (action == SVNEventAction.UPDATE_COMPLETED) {
|
---|
124 | /*
|
---|
125 | * Updating the working copy is completed. Prints out the revision.
|
---|
126 | */
|
---|
127 | //System.out.println("At revision " + event.getRevision());
|
---|
128 | messageArea.append("At revision " + event.getRevision()+"\n");
|
---|
129 | messageArea.append("The extension ("+ extensionName +") has been downloaded to the local folder: "+ localDirectory +"\n");
|
---|
130 | messageArea.setSelectionEnd(messageArea.getDocument().getLength());
|
---|
131 | return;
|
---|
132 | } else if (action == SVNEventAction.ADD){
|
---|
133 | System.out.println("A " + event.getURL().getPath());
|
---|
134 | return;
|
---|
135 | } else if (action == SVNEventAction.DELETE){
|
---|
136 | System.out.println("D " + event.getURL().getPath());
|
---|
137 | return;
|
---|
138 | } else if (action == SVNEventAction.LOCKED){
|
---|
139 | System.out.println("L " + event.getURL().getPath());
|
---|
140 | return;
|
---|
141 | } else if (action == SVNEventAction.LOCK_FAILED){
|
---|
142 | System.out.println("failed to lock " + event.getURL().getPath());
|
---|
143 | return;
|
---|
144 | }
|
---|
145 |
|
---|
146 | /*
|
---|
147 | * Now getting the status of properties of an item. SVNStatusType also
|
---|
148 | * contains information on the properties state.
|
---|
149 | */
|
---|
150 | SVNStatusType propertiesStatus = event.getPropertiesStatus();
|
---|
151 | /*
|
---|
152 | * At first consider properties are normal (unchanged).
|
---|
153 | */
|
---|
154 | String propertiesChangeType = " ";
|
---|
155 | if (propertiesStatus == SVNStatusType.CHANGED) {
|
---|
156 | /*
|
---|
157 | * Properties were updated.
|
---|
158 | */
|
---|
159 | propertiesChangeType = "U";
|
---|
160 | } else if (propertiesStatus == SVNStatusType.CONFLICTED) {
|
---|
161 | /*
|
---|
162 | * Properties are in conflict with the repository.
|
---|
163 | */
|
---|
164 | propertiesChangeType = "C";
|
---|
165 | } else if (propertiesStatus == SVNStatusType.MERGED) {
|
---|
166 | /*
|
---|
167 | * Properties that came from the repository were merged with the
|
---|
168 | * local ones.
|
---|
169 | */
|
---|
170 | propertiesChangeType = "G";
|
---|
171 | }
|
---|
172 |
|
---|
173 | /*
|
---|
174 | * Gets the status of the lock.
|
---|
175 | */
|
---|
176 | String lockLabel = " ";
|
---|
177 | SVNStatusType lockType = event.getLockStatus();
|
---|
178 |
|
---|
179 | if (lockType == SVNStatusType.LOCK_UNLOCKED) {
|
---|
180 | /*
|
---|
181 | * The lock is broken by someone.
|
---|
182 | */
|
---|
183 | lockLabel = "B";
|
---|
184 | }
|
---|
185 |
|
---|
186 | /*
|
---|
187 | System.out.println(pathChangeType
|
---|
188 | + propertiesChangeType
|
---|
189 | + lockLabel
|
---|
190 | + " "
|
---|
191 | + event.getURL().getPath());
|
---|
192 | */
|
---|
193 | /*
|
---|
194 |
|
---|
195 | try{
|
---|
196 | this.sleep(500);
|
---|
197 | }catch(Exception ex){
|
---|
198 | ex.printStackTrace();
|
---|
199 | }
|
---|
200 |
|
---|
201 | */
|
---|
202 |
|
---|
203 | String content = pathChangeType
|
---|
204 | + propertiesChangeType
|
---|
205 | + lockLabel
|
---|
206 | + " "
|
---|
207 | + event.getURL().getPath()+"\n";
|
---|
208 |
|
---|
209 |
|
---|
210 |
|
---|
211 |
|
---|
212 | //jp.update(messageArea.getGraphics());
|
---|
213 | //jp.showMessageDialog(messageArea, content);
|
---|
214 | //messageArea.setDocument(messageArea.getDocument());
|
---|
215 | /*
|
---|
216 | FlipTask ft = new FlipTask();
|
---|
217 | ft.texts = content;
|
---|
218 | ft.doInBackground();
|
---|
219 | */
|
---|
220 |
|
---|
221 | //messageArea.setAutoscrolls(true);
|
---|
222 | messageArea.append(content);
|
---|
223 | messageArea.setSelectionEnd(messageArea.getDocument().getLength());
|
---|
224 | /*
|
---|
225 | System.out.println(messageArea.getDocument().getLength());
|
---|
226 |
|
---|
227 | SwingUtilities.invokeLater(new Runnable() {
|
---|
228 | public void run() {
|
---|
229 | messageArea.paintAll(messageArea.getGraphics());
|
---|
230 | messageArea.setCaretPosition(messageArea.getDocument().getLength());
|
---|
231 |
|
---|
232 | }
|
---|
233 | });
|
---|
234 | */
|
---|
235 | //messageArea.setCaretPosition(0);
|
---|
236 |
|
---|
237 | //.update(messageArea.getGraphics());
|
---|
238 |
|
---|
239 |
|
---|
240 |
|
---|
241 |
|
---|
242 |
|
---|
243 |
|
---|
244 |
|
---|
245 |
|
---|
246 |
|
---|
247 |
|
---|
248 |
|
---|
249 |
|
---|
250 |
|
---|
251 |
|
---|
252 |
|
---|
253 |
|
---|
254 |
|
---|
255 |
|
---|
256 |
|
---|
257 |
|
---|
258 |
|
---|
259 | //messageArea.paintAll(g);
|
---|
260 |
|
---|
261 |
|
---|
262 |
|
---|
263 | }
|
---|
264 |
|
---|
265 |
|
---|
266 |
|
---|
267 |
|
---|
268 | /*
|
---|
269 | * Should be implemented to check if the current operation is cancelled. If
|
---|
270 | * it is, this method should throw an SVNCancelException.
|
---|
271 | */
|
---|
272 | public void checkCancelled() throws SVNCancelException { }
|
---|
273 |
|
---|
274 | /*
|
---|
275 |
|
---|
276 | private class FlipTask extends SwingWorker{
|
---|
277 | @Override
|
---|
278 | protected Void doInBackground() {
|
---|
279 |
|
---|
280 | publish(new UpdateEventHandler(heads, total));
|
---|
281 |
|
---|
282 | return null;
|
---|
283 | }
|
---|
284 |
|
---|
285 | @Override
|
---|
286 | protected void process(List<FlipPair> pairs) {
|
---|
287 | FlipPair pair = pairs.get(pairs.size() - 1);
|
---|
288 | headsText.setText(String.format("%d", pair.heads));
|
---|
289 | totalText.setText(String.format("%d", pair.total));
|
---|
290 | devText.setText(String.format("%.10g",
|
---|
291 | ((double) pair.heads)/((double) pair.total) - 0.5));
|
---|
292 | }
|
---|
293 | }
|
---|
294 | */
|
---|
295 | }
|
---|