KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > ui > diff > Setup


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.subversion.ui.diff;
21
22 import org.netbeans.api.diff.StreamSource;
23 import org.netbeans.api.diff.DiffView;
24 import org.netbeans.modules.subversion.*;
25 import org.openide.util.NbBundle;
26
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29 import java.util.*;
30 import java.text.MessageFormat JavaDoc;
31
32 /**
33  * Represents on DIFF setup.
34  *
35  * @author Maros Sandor
36  */

37 public final class Setup {
38
39     /**
40      * What was locally changed? The right pane contains local file.
41      *
42      * <p>Local addition, removal or change is displayed in
43      * the right pane as addition, removal or change respectively
44      * (i.e. not reversed as removal, addition or change).
45      *
46      * <pre>
47      * diff from-BASE to-LOCAL
48      * </pre>
49      */

50     public static final int DIFFTYPE_LOCAL = 0;
51
52     /**
53      * What was remotely changed? The right pane contains remote file.
54      *
55      * <p>Remote addition, removal or change is displayed in
56      * the right pane as addition, removal or change respectively
57      * (i.e. not reversed as removal, addition or change).
58      *
59      * <pre>
60      * diff from-BASE to-HEAD
61      * </pre>
62      */

63     public static final int DIFFTYPE_REMOTE = 1;
64
65     /**
66      * What was locally changed comparing to recent head?
67      * The Right pane contains local file.
68      *
69      * <p> Local addition, removal or change is displayed in
70      * the right pane as addition, removal or change respectively
71      * (i.e. not reversed as removal, addition or change).
72      *
73      * <pre>
74      * diff from-HEAD to-LOCAL
75      * </pre>
76      */

77     public static final int DIFFTYPE_ALL = 2;
78     
79     public static final String JavaDoc REVISION_PRISTINE = "PRISTINE"; // NOI18N
80
public static final String JavaDoc REVISION_BASE = "BASE"; // NOI18N
81
public static final String JavaDoc REVISION_CURRENT = "LOCAL"; // NOI18N
82
public static final String JavaDoc REVISION_HEAD = "HEAD"; // NOI18N
83

84     private final File JavaDoc baseFile;
85     private final String JavaDoc firstRevision;
86     private final String JavaDoc secondRevision;
87
88     private DiffStreamSource firstSource;
89     private DiffStreamSource secondSource;
90
91     private DiffView view;
92
93     private String JavaDoc title;
94
95     public Setup(File JavaDoc baseFile, int type) {
96         this.baseFile = baseFile;
97         FileInformation info = Subversion.getInstance().getStatusCache().getStatus(baseFile);
98         int status = info.getStatus();
99         
100         ResourceBundle loc = NbBundle.getBundle(Setup.class);
101         String JavaDoc firstTitle;
102         String JavaDoc secondTitle;
103
104         // the first source
105

106         switch (type) {
107             case DIFFTYPE_LOCAL:
108             case DIFFTYPE_REMOTE:
109
110                 // from-BASE
111

112                 if (match(status, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY
113                 | FileInformation.STATUS_VERSIONED_ADDEDLOCALLY)) {
114                     firstRevision = REVISION_BASE;
115                     firstTitle = loc.getString("MSG_DiffPanel_LocalNew");
116                 } else if (match (status, FileInformation.STATUS_VERSIONED_NEWINREPOSITORY)) {
117                     firstRevision = null;
118                     firstTitle = NbBundle.getMessage(Setup.class, "LBL_Diff_NoLocalFile"); // NOI18N
119
} else if (match(status, FileInformation.STATUS_VERSIONED_DELETEDLOCALLY
120                 | FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY)) {
121                     firstRevision = REVISION_BASE;
122                     firstTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_BaseRevision"), new Object JavaDoc [] { firstRevision });
123                 } else {
124                     firstRevision = REVISION_BASE;
125                     firstTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_BaseRevision"), new Object JavaDoc [] { firstRevision });
126                 }
127
128                 break;
129
130             case DIFFTYPE_ALL:
131
132                 // from-HEAD
133

134                 if (match (status, FileInformation.STATUS_VERSIONED_NEWINREPOSITORY)) {
135                     firstRevision = REVISION_HEAD;
136                     firstTitle = loc.getString("MSG_DiffPanel_RemoteNew");
137                 } else if (match (status, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY
138                                  | FileInformation.STATUS_VERSIONED_ADDEDLOCALLY)) {
139                     firstRevision = null;
140                     firstTitle = loc.getString("MSG_DiffPanel_NoBaseRevision");
141                 } else if (match(status, FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY)) {
142                     firstRevision = null;
143                     firstTitle = loc.getString("MSG_DiffPanel_RemoteDeleted");
144                 } else {
145                     firstRevision = REVISION_HEAD;
146                     firstTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_RemoteModified"), new Object JavaDoc [] { firstRevision });
147                 }
148                 break;
149
150             default:
151                 throw new IllegalArgumentException JavaDoc("Unknow diff type: " + type); // NOI18N
152
}
153
154
155         // the second source
156

157         switch (type) {
158             case DIFFTYPE_LOCAL:
159             case DIFFTYPE_ALL:
160
161                 // to-LOCAL
162

163                 if (match(status, FileInformation.STATUS_VERSIONED_CONFLICT)) {
164                     secondRevision = REVISION_CURRENT;
165                     secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_LocalConflict"), new Object JavaDoc [] { secondRevision });
166                 } else if (match(status, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY
167                 | FileInformation.STATUS_VERSIONED_ADDEDLOCALLY)) {
168                     secondRevision = REVISION_CURRENT;
169                     secondTitle = loc.getString("MSG_DiffPanel_LocalNew");
170                 } else if (match (status, FileInformation.STATUS_VERSIONED_NEWINREPOSITORY)) {
171                     secondRevision = null;
172                     secondTitle = NbBundle.getMessage(Setup.class, "LBL_Diff_NoLocalFile"); // NOI18N
173
} else if (match(status, FileInformation.STATUS_VERSIONED_DELETEDLOCALLY
174                 | FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY)) {
175                     secondRevision = null;
176                     secondTitle = loc.getString("MSG_DiffPanel_LocalDeleted");
177                 } else {
178                     secondRevision = REVISION_CURRENT;
179                     secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_LocalModified"), new Object JavaDoc [] { secondRevision });
180                 }
181                 break;
182
183             case DIFFTYPE_REMOTE:
184
185                 // to-HEAD
186

187                 if (match(status, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY
188                 | FileInformation.STATUS_VERSIONED_ADDEDLOCALLY)) {
189                     secondRevision = null;
190                     secondTitle = loc.getString("MSG_DiffPanel_LocalNew");
191                 } else if (match(status, FileInformation.STATUS_VERSIONED_NEWINREPOSITORY)) {
192                     secondRevision = REVISION_HEAD;
193                     secondTitle = loc.getString("MSG_DiffPanel_RemoteNew");
194                 } else if (match(status, FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY)) {
195                     secondRevision = null;
196                     secondTitle = loc.getString("MSG_DiffPanel_RemoteDeleted");
197                 } else {
198                     secondRevision = REVISION_HEAD;
199                     secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_RemoteModified"), new Object JavaDoc [] { secondRevision });
200                 }
201                 break;
202
203             default:
204                 throw new IllegalArgumentException JavaDoc("Unknow diff type: " + type); // NOI18N
205
}
206
207         firstSource = new DiffStreamSource(baseFile, firstRevision, firstTitle);
208         secondSource = new DiffStreamSource(baseFile, secondRevision, secondTitle);
209         title = "<html>" + Subversion.getInstance().getAnnotator().annotateNameHtml(baseFile, info); // NOI18N
210
}
211
212     /**
213      * Text file setup for arbitrary revisions.
214      * @param firstRevision first revision or <code>null</code> for inital.
215      * @param secondRevision second revision
216      */

217     public Setup(File JavaDoc baseFile, String JavaDoc firstRevision, String JavaDoc secondRevision) {
218         this.baseFile = baseFile;
219         this.firstRevision = firstRevision;
220         this.secondRevision = secondRevision;
221         firstSource = new DiffStreamSource(baseFile, firstRevision, firstRevision);
222         secondSource = new DiffStreamSource(baseFile, secondRevision, secondRevision);
223     }
224
225     public File JavaDoc getBaseFile() {
226         return baseFile;
227     }
228
229     public void setView(DiffView view) {
230         this.view = view;
231     }
232
233     public DiffView getView() {
234         return view;
235     }
236
237     public StreamSource getFirstSource() {
238         return firstSource;
239     }
240
241     public StreamSource getSecondSource() {
242         return secondSource;
243     }
244
245     public String JavaDoc toString() {
246         return title;
247     }
248
249     /**
250      * Loads data over network
251      * @param group that carries shared state. Note that this group must not be executed later on.
252      */

253     void initSources() throws IOException JavaDoc {
254         if (firstSource != null) firstSource.init();
255         if (secondSource != null) secondSource.init();
256     }
257
258     private static boolean match(int status, int mask) {
259         return (status & mask) != 0;
260     }
261 }
262
Popular Tags