1 | package org.greenstone.admin.guiext.mat;
|
---|
2 |
|
---|
3 | import java.awt.Graphics;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import javax.swing.JOptionPane;
|
---|
7 | import javax.swing.JScrollPane;
|
---|
8 | import javax.swing.JTextArea;
|
---|
9 | import javax.swing.SwingUtilities;
|
---|
10 |
|
---|
11 | import org.tmatesoft.svn.core.SVNCancelException;
|
---|
12 | import org.tmatesoft.svn.core.wc.ISVNEventHandler;
|
---|
13 | import org.tmatesoft.svn.core.wc.SVNEvent;
|
---|
14 | import org.tmatesoft.svn.core.wc.SVNStatusType;
|
---|
15 | import org.tmatesoft.svn.core.wc.SVNEventAction;
|
---|
16 |
|
---|
17 |
|
---|
18 | public class MatUpdateEventHandler extends Thread implements ISVNEventHandler, Runnable {
|
---|
19 |
|
---|
20 | JTextArea messageArea = new JTextArea();
|
---|
21 | String localDirectory;
|
---|
22 | String extensionName;
|
---|
23 | public MatUpdateEventHandler(JTextArea messgaeTextArea, String dir, String extensionName) {
|
---|
24 |
|
---|
25 |
|
---|
26 | messageArea = messgaeTextArea;
|
---|
27 | messageArea.setEditable(false);
|
---|
28 | messageArea.setLineWrap(true);
|
---|
29 | messageArea.setWrapStyleWord(true);
|
---|
30 |
|
---|
31 | localDirectory = dir;
|
---|
32 | this.extensionName = extensionName;
|
---|
33 |
|
---|
34 | }
|
---|
35 |
|
---|
36 | public MatUpdateEventHandler() {
|
---|
37 | // TODO Auto-generated constructor stub
|
---|
38 | }
|
---|
39 |
|
---|
40 | public void handleEvent(SVNEvent event, double progress) {
|
---|
41 | /*
|
---|
42 | * Gets the current action. An action is represented by SVNEventAction.
|
---|
43 | * In case of an update an action can be determined via comparing
|
---|
44 | * SVNEvent.getAction() and SVNEventAction.UPDATE_-like constants.
|
---|
45 | */
|
---|
46 |
|
---|
47 | //System.out.println(" event occurs");
|
---|
48 | SVNEventAction action = event.getAction();
|
---|
49 | String pathChangeType = " ";
|
---|
50 | if (action == SVNEventAction.UPDATE_ADD) {
|
---|
51 | /*
|
---|
52 | * the item was added
|
---|
53 | */
|
---|
54 | pathChangeType = "A";
|
---|
55 | } else if (action == SVNEventAction.UPDATE_DELETE) {
|
---|
56 | /*
|
---|
57 | * the item was deleted
|
---|
58 | */
|
---|
59 | pathChangeType = "D";
|
---|
60 | } else if (action == SVNEventAction.UPDATE_UPDATE) {
|
---|
61 | /*
|
---|
62 | * Find out in details what state the item is (after having been
|
---|
63 | * updated).
|
---|
64 | *
|
---|
65 | * Gets the status of file/directory item contents. It is
|
---|
66 | * SVNStatusType who contains information on the state of an item.
|
---|
67 | */
|
---|
68 | SVNStatusType contentsStatus = event.getContentsStatus();
|
---|
69 | if (contentsStatus == SVNStatusType.CHANGED) {
|
---|
70 | /*
|
---|
71 | * the item was modified in the repository (got the changes
|
---|
72 | * from the repository
|
---|
73 | */
|
---|
74 | pathChangeType = "U";
|
---|
75 | }else if (contentsStatus == SVNStatusType.CONFLICTED) {
|
---|
76 | /*
|
---|
77 | * The file item is in a state of Conflict. That is, changes
|
---|
78 | * received from the repository during an update, overlap with
|
---|
79 | * local changes the user has in his working copy.
|
---|
80 | */
|
---|
81 | pathChangeType = "C";
|
---|
82 | } else if (contentsStatus == SVNStatusType.MERGED) {
|
---|
83 | /*
|
---|
84 | * The file item was merGed (those changes that came from the
|
---|
85 | * repository did not overlap local changes and were merged
|
---|
86 | * into the file).
|
---|
87 | */
|
---|
88 | pathChangeType = "G";
|
---|
89 | }
|
---|
90 | } else if (action == SVNEventAction.UPDATE_EXTERNAL) {
|
---|
91 | /*for externals definitions*/
|
---|
92 | System.out.println("Fetching external item into '"
|
---|
93 | + event.getFile().getAbsolutePath() + "'");
|
---|
94 | System.out.println("External at revision " + event.getRevision());
|
---|
95 | return;
|
---|
96 | } else if (action == SVNEventAction.UPDATE_COMPLETED) {
|
---|
97 | /*
|
---|
98 | * Updating the working copy is completed. Prints out the revision.
|
---|
99 | */
|
---|
100 | //System.out.println("At revision " + event.getRevision());
|
---|
101 | messageArea.append("At revision " + event.getRevision()+"\n");
|
---|
102 | messageArea.append("The extension ("+ extensionName +") has been downloaded to the local folder: \n"+ localDirectory +"\n");
|
---|
103 | messageArea.setSelectionEnd(messageArea.getDocument().getLength());
|
---|
104 | return;
|
---|
105 | } else if (action == SVNEventAction.ADD){
|
---|
106 | System.out.println("A " + event.getURL().getPath());
|
---|
107 | return;
|
---|
108 | } else if (action == SVNEventAction.DELETE){
|
---|
109 | System.out.println("D " + event.getURL().getPath());
|
---|
110 | return;
|
---|
111 | } else if (action == SVNEventAction.LOCKED){
|
---|
112 | System.out.println("L " + event.getURL().getPath());
|
---|
113 | return;
|
---|
114 | } else if (action == SVNEventAction.LOCK_FAILED){
|
---|
115 | System.out.println("failed to lock " + event.getURL().getPath());
|
---|
116 | return;
|
---|
117 | }
|
---|
118 |
|
---|
119 | /*
|
---|
120 | * Now getting the status of properties of an item. SVNStatusType also
|
---|
121 | * contains information on the properties state.
|
---|
122 | */
|
---|
123 | SVNStatusType propertiesStatus = event.getPropertiesStatus();
|
---|
124 | /*
|
---|
125 | * At first consider properties are normal (unchanged).
|
---|
126 | */
|
---|
127 | String propertiesChangeType = " ";
|
---|
128 | if (propertiesStatus == SVNStatusType.CHANGED) {
|
---|
129 | /*
|
---|
130 | * Properties were updated.
|
---|
131 | */
|
---|
132 | propertiesChangeType = "U";
|
---|
133 | } else if (propertiesStatus == SVNStatusType.CONFLICTED) {
|
---|
134 | /*
|
---|
135 | * Properties are in conflict with the repository.
|
---|
136 | */
|
---|
137 | propertiesChangeType = "C";
|
---|
138 | } else if (propertiesStatus == SVNStatusType.MERGED) {
|
---|
139 | /*
|
---|
140 | * Properties that came from the repository were merged with the
|
---|
141 | * local ones.
|
---|
142 | */
|
---|
143 | propertiesChangeType = "G";
|
---|
144 | }
|
---|
145 |
|
---|
146 | /*
|
---|
147 | * Gets the status of the lock.
|
---|
148 | */
|
---|
149 | String lockLabel = " ";
|
---|
150 | SVNStatusType lockType = event.getLockStatus();
|
---|
151 |
|
---|
152 | if (lockType == SVNStatusType.LOCK_UNLOCKED) {
|
---|
153 | /*
|
---|
154 | * The lock is broken by someone.
|
---|
155 | */
|
---|
156 | lockLabel = "B";
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | String content = pathChangeType
|
---|
161 | + propertiesChangeType
|
---|
162 | + lockLabel
|
---|
163 | + " "
|
---|
164 | + event.getURL().getPath()+"\n";
|
---|
165 |
|
---|
166 | messageArea.append(content);
|
---|
167 | messageArea.setSelectionEnd(messageArea.getDocument().getLength());
|
---|
168 | }
|
---|
169 |
|
---|
170 | public void checkCancelled() throws SVNCancelException { }
|
---|
171 |
|
---|
172 | }
|
---|