1 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 ; 28 import java.io.IOException ; 29 import java.util.*; 30 import java.text.MessageFormat ; 31 32 37 public final class Setup { 38 39 50 public static final int DIFFTYPE_LOCAL = 0; 51 52 63 public static final int DIFFTYPE_REMOTE = 1; 64 65 77 public static final int DIFFTYPE_ALL = 2; 78 79 public static final String REVISION_PRISTINE = "PRISTINE"; public static final String REVISION_BASE = "BASE"; public static final String REVISION_CURRENT = "LOCAL"; public static final String REVISION_HEAD = "HEAD"; 84 private final File baseFile; 85 private final String firstRevision; 86 private final String secondRevision; 87 88 private DiffStreamSource firstSource; 89 private DiffStreamSource secondSource; 90 91 private DiffView view; 92 93 private String title; 94 95 public Setup(File 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 firstTitle; 102 String secondTitle; 103 104 106 switch (type) { 107 case DIFFTYPE_LOCAL: 108 case DIFFTYPE_REMOTE: 109 110 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"); } 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 [] { firstRevision }); 123 } else { 124 firstRevision = REVISION_BASE; 125 firstTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_BaseRevision"), new Object [] { firstRevision }); 126 } 127 128 break; 129 130 case DIFFTYPE_ALL: 131 132 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 [] { firstRevision }); 147 } 148 break; 149 150 default: 151 throw new IllegalArgumentException ("Unknow diff type: " + type); } 153 154 155 157 switch (type) { 158 case DIFFTYPE_LOCAL: 159 case DIFFTYPE_ALL: 160 161 163 if (match(status, FileInformation.STATUS_VERSIONED_CONFLICT)) { 164 secondRevision = REVISION_CURRENT; 165 secondTitle = MessageFormat.format(loc.getString("MSG_DiffPanel_LocalConflict"), new Object [] { 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"); } 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 [] { secondRevision }); 180 } 181 break; 182 183 case DIFFTYPE_REMOTE: 184 185 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 [] { secondRevision }); 200 } 201 break; 202 203 default: 204 throw new IllegalArgumentException ("Unknow diff type: " + type); } 206 207 firstSource = new DiffStreamSource(baseFile, firstRevision, firstTitle); 208 secondSource = new DiffStreamSource(baseFile, secondRevision, secondTitle); 209 title = "<html>" + Subversion.getInstance().getAnnotator().annotateNameHtml(baseFile, info); } 211 212 217 public Setup(File baseFile, String firstRevision, String 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 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 toString() { 246 return title; 247 } 248 249 253 void initSources() throws IOException { 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 |