KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > 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.versioning.system.cvss.ui.actions.diff;
21
22 import org.netbeans.api.diff.StreamSource;
23 import org.netbeans.api.diff.DiffView;
24 import org.netbeans.modules.versioning.system.cvss.*;
25 import org.netbeans.lib.cvsclient.admin.Entry;
26 import org.openide.util.NbBundle;
27
28 import java.io.File JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.util.*;
31 import java.text.MessageFormat JavaDoc;
32
33 /**
34  * Represents on DIFF setup.
35  *
36  * @author Maros Sandor
37  */

38 public final class Setup {
39
40     public static final int DIFFTYPE_LOCAL = 0;
41     public static final int DIFFTYPE_REMOTE = 1;
42     public static final int DIFFTYPE_ALL = 2;
43     
44     public static final String JavaDoc REVISION_CURRENT = VersionsCache.REVISION_CURRENT;
45     public static final String JavaDoc REVISION_HEAD = VersionsCache.REVISION_HEAD;
46     
47     private final File JavaDoc baseFile;
48     private final String JavaDoc firstRevision;
49     private final String JavaDoc secondRevision;
50
51     private DiffStreamSource firstSource;
52     private DiffStreamSource secondSource;
53
54     private DiffView view;
55
56     private String JavaDoc title;
57
58     public Setup(File JavaDoc baseFile, int type) {
59         this.baseFile = baseFile;
60         FileInformation info = CvsVersioningSystem.getInstance().getStatusCache().getStatus(baseFile);
61         int status = info.getStatus();
62         Entry entry = info.getEntry(baseFile);
63         String JavaDoc revision = entry != null ? entry.getRevision() : null;
64         if (revision != null && revision.charAt(0) == '-') revision = revision.substring(1);
65
66         ResourceBundle loc = NbBundle.getBundle(Setup.class);
67         String JavaDoc firstTitle;
68         String JavaDoc secondTitle;
69         if (type == DIFFTYPE_ALL && status == FileInformation.STATUS_VERSIONED_MERGE) {
70             firstRevision = REVISION_HEAD;
71             firstTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_RemoteModified"), new Object JavaDoc [] { revision });
72         } else if (
73                 status == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY ||
74                 status == FileInformation.STATUS_VERSIONED_ADDEDLOCALLY ||
75                 status == FileInformation.STATUS_VERSIONED_NEWINREPOSITORY
76         ) {
77             firstRevision = null;
78             firstTitle = loc.getString("MSG_DiffPanel_NoBaseRevision");
79         } else {
80             firstRevision = revision;
81             firstTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_BaseRevision"), new Object JavaDoc [] { revision });
82         }
83
84         if (status == FileInformation.STATUS_VERSIONED_CONFLICT) {
85             secondRevision = REVISION_CURRENT;
86             secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_LocalConflict"), new Object JavaDoc [] { revision });
87         } else if (status == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY || status == FileInformation.STATUS_VERSIONED_ADDEDLOCALLY) {
88             secondRevision = REVISION_CURRENT;
89             secondTitle = loc.getString("MSG_DiffPanel_LocalNew");
90         } else if (status == FileInformation.STATUS_VERSIONED_DELETEDLOCALLY || status == FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY) {
91             secondRevision = null;
92             secondTitle = loc.getString("MSG_DiffPanel_LocalDeleted");
93         } else if (status == FileInformation.STATUS_VERSIONED_NEWINREPOSITORY) {
94             secondRevision = REVISION_HEAD;
95             secondTitle = loc.getString("MSG_DiffPanel_RemoteNew");
96         } else if (status == FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY) {
97             secondRevision = null;
98             secondTitle = loc.getString("MSG_DiffPanel_RemoteDeleted");
99         } else if (status == FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY) {
100             secondRevision = REVISION_HEAD;
101             secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_RemoteModified"), new Object JavaDoc [] { revision });
102         } else if (type == DIFFTYPE_REMOTE) {
103             secondRevision = REVISION_HEAD;
104             secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_RemoteModified"), new Object JavaDoc [] { revision });
105         } else {
106             secondRevision = REVISION_CURRENT;
107             secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_LocalModified"), new Object JavaDoc [] { revision });
108         }
109
110         firstSource = new DiffStreamSource(baseFile, firstRevision, firstTitle);
111         secondSource = new DiffStreamSource(baseFile, secondRevision, secondTitle);
112         title = "<html>" + CvsVersioningSystem.getInstance().getAnnotator().annotateNameHtml(baseFile, info); // NOI18N
113
}
114
115     /**
116      * Text file setup for arbitrary revisions.
117      * @param firstRevision first revision or <code>null</code> for inital.
118      * @param secondRevision second revision
119      */

120     public Setup(File JavaDoc baseFile, String JavaDoc firstRevision, String JavaDoc secondRevision) {
121         this.baseFile = baseFile;
122         this.firstRevision = firstRevision;
123         this.secondRevision = secondRevision;
124         firstSource = new DiffStreamSource(baseFile, firstRevision, firstRevision);
125         secondSource = new DiffStreamSource(baseFile, secondRevision, secondRevision);
126     }
127
128     public File JavaDoc getBaseFile() {
129         return baseFile;
130     }
131
132     public void setView(DiffView view) {
133         this.view = view;
134     }
135
136     public DiffView getView() {
137         return view;
138     }
139
140     public StreamSource getFirstSource() {
141         return firstSource;
142     }
143
144     public StreamSource getSecondSource() {
145         return secondSource;
146     }
147
148     public String JavaDoc toString() {
149         return title;
150     }
151
152     static String JavaDoc getDisplayedRevision(File JavaDoc baseFile, String JavaDoc revision) {
153         if (revision == REVISION_CURRENT) {
154             FileInformation info = CvsVersioningSystem.getInstance().getStatusCache().getStatus(baseFile);
155             return NbBundle.getMessage(Setup.class, "MSG_LocalRevision", info.getEntry(baseFile).getRevision());
156         } else {
157             return revision;
158         }
159     }
160
161     /**
162      * Loads data over network
163      * @param group that carries shared state. Note that this group must not be executed later on.
164      */

165     void initSources(ExecutorGroup group) throws IOException JavaDoc {
166         if (firstSource != null) firstSource.init(group);
167         if (secondSource != null) secondSource.init(group);
168     }
169 }
170
Popular Tags