1 19 20 package org.netbeans.modules.versioning.system.cvss; 21 22 import org.openide.util.actions.SystemAction; 23 import org.openide.util.NbBundle; 24 import org.openide.util.Utilities; 25 import org.openide.util.Lookup; 26 import org.openide.util.lookup.Lookups; 27 import org.openide.nodes.Node; 28 import org.netbeans.modules.versioning.system.cvss.ui.actions.status.StatusAction; 29 import org.netbeans.modules.versioning.system.cvss.ui.actions.checkout.CheckoutAction; 30 import org.netbeans.modules.versioning.system.cvss.ui.actions.project.UpdateWithDependenciesAction; 31 import org.netbeans.modules.versioning.system.cvss.ui.actions.project.AddToRepositoryAction; 32 import org.netbeans.modules.versioning.system.cvss.ui.actions.ignore.IgnoreAction; 33 import org.netbeans.modules.versioning.system.cvss.ui.actions.log.AnnotationsAction; 34 import org.netbeans.modules.versioning.system.cvss.ui.actions.log.SearchHistoryAction; 35 import org.netbeans.modules.versioning.system.cvss.ui.actions.diff.DiffAction; 36 import org.netbeans.modules.versioning.system.cvss.ui.actions.diff.ResolveConflictsAction; 37 import org.netbeans.modules.versioning.system.cvss.ui.actions.diff.ExportDiffAction; 38 import org.netbeans.modules.versioning.system.cvss.ui.actions.tag.*; 39 import org.netbeans.modules.versioning.system.cvss.ui.actions.commit.CommitAction; 40 import org.netbeans.modules.versioning.system.cvss.ui.actions.commit.ExcludeFromCommitAction; 41 import org.netbeans.modules.versioning.system.cvss.ui.actions.update.UpdateAction; 42 import org.netbeans.modules.versioning.system.cvss.ui.actions.update.GetCleanAction; 43 import org.netbeans.modules.versioning.system.cvss.ui.actions.ChangeCVSRootAction; 44 import org.netbeans.modules.versioning.system.cvss.ui.history.ViewRevisionAction; 45 import org.netbeans.modules.versioning.system.cvss.util.Utils; 46 import org.netbeans.modules.versioning.spi.VCSContext; 47 import org.netbeans.modules.versioning.spi.VCSAnnotator; 48 import org.netbeans.modules.versioning.util.FlatFolder; 49 import org.netbeans.lib.cvsclient.admin.Entry; 50 import org.netbeans.api.project.Project; 51 52 import javax.swing.*; 53 import java.util.*; 54 import java.util.List ; 55 import java.util.logging.Logger ; 56 import java.util.logging.Level ; 57 import java.util.regex.Pattern ; 58 import java.text.MessageFormat ; 59 import java.io.File ; 60 import java.awt.*; 61 import java.lang.reflect.Field ; 62 import org.netbeans.modules.versioning.util.SystemActionBridge; 63 64 70 public class Annotator { 71 72 private static MessageFormat uptodateFormat = getFormat("uptodateFormat"); private static MessageFormat newLocallyFormat = getFormat("newLocallyFormat"); private static MessageFormat addedLocallyFormat = getFormat("addedLocallyFormat"); private static MessageFormat modifiedLocallyFormat = getFormat("modifiedLocallyFormat"); private static MessageFormat removedLocallyFormat = getFormat("removedLocallyFormat"); private static MessageFormat deletedLocallyFormat = getFormat("deletedLocallyFormat"); private static MessageFormat newInRepositoryFormat = getFormat("newInRepositoryFormat"); private static MessageFormat modifiedInRepositoryFormat = getFormat("modifiedInRepositoryFormat"); private static MessageFormat removedInRepositoryFormat = getFormat("removedInRepositoryFormat"); private static MessageFormat conflictFormat = getFormat("conflictFormat"); private static MessageFormat mergeableFormat = getFormat("mergeableFormat"); private static MessageFormat excludedFormat = getFormat("excludedFormat"); 85 private static final int STATUS_TEXT_ANNOTABLE = FileInformation.STATUS_NOTVERSIONED_EXCLUDED | 86 FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY | FileInformation.STATUS_VERSIONED_UPTODATE | 87 FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY | FileInformation.STATUS_VERSIONED_CONFLICT | FileInformation.STATUS_VERSIONED_MERGE | 88 FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY | FileInformation.STATUS_VERSIONED_DELETEDLOCALLY | 89 FileInformation.STATUS_VERSIONED_ADDEDLOCALLY; 90 91 private static final Pattern lessThan = Pattern.compile("<"); 93 private final FileStatusCache cache; 94 95 private String lastAnnotationsFormat; 96 private MessageFormat lastMessageFormat; 97 private String lastEmptyAnnotation; 98 99 Annotator(CvsVersioningSystem cvs) { 100 cache = cvs.getStatusCache(); 101 initDefaults(); 102 } 103 104 private void initDefaults() { 105 Field [] fields = Annotator.class.getDeclaredFields(); 106 for (int i = 0; i < fields.length; i++) { 107 String name = fields[i].getName(); 108 if (name.endsWith("Format")) { initDefaultColor(name.substring(0, name.length() - 6)); 110 } 111 } 112 } 113 114 private void initDefaultColor(String name) { 115 String color = System.getProperty("cvs.color." + name); if (color == null) return; 117 setAnnotationColor(name, color); 118 } 119 120 128 private void setAnnotationColor(String name, String colorString) { 129 try { 130 Field field = Annotator.class.getDeclaredField(name + "Format"); MessageFormat format = new MessageFormat ("<font color=\"" + colorString + "\">{0}</font><font color=\"#999999\">{1}</font>"); field.set(null, format); 133 } catch (Exception e) { 134 throw new IllegalArgumentException ("Invalid color name"); } 136 } 137 138 149 public String annotateNameHtml(String name, FileInformation info, File file) { 150 name = htmlEncode(name); 151 int status = info.getStatus(); 152 String textAnnotation; 153 boolean annotationsVisible = CvsModuleConfig.getDefault().getPreferences().getBoolean(CvsModuleConfig.PROP_ANNOTATIONS_VISIBLE, false); 154 if (annotationsVisible && file != null && (status & STATUS_TEXT_ANNOTABLE) != 0) { 155 textAnnotation = formatAnnotation(info, file); 156 if (textAnnotation.equals(lastEmptyAnnotation)) textAnnotation = ""; } else { 158 textAnnotation = ""; } 160 if (textAnnotation.length() > 0) { 161 textAnnotation = NbBundle.getMessage(Annotator.class, "textAnnotation", textAnnotation); 162 } 163 164 switch (status) { 165 case FileInformation.STATUS_UNKNOWN: 166 case FileInformation.STATUS_NOTVERSIONED_NOTMANAGED: 167 return name; 168 case FileInformation.STATUS_VERSIONED_UPTODATE: 169 return uptodateFormat.format(new Object [] { name, textAnnotation }); 170 case FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY: 171 return modifiedLocallyFormat.format(new Object [] { name, textAnnotation }); 172 case FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY: 173 return newLocallyFormat.format(new Object [] { name, textAnnotation }); 174 case FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY: 175 return removedLocallyFormat.format(new Object [] { name, textAnnotation }); 176 case FileInformation.STATUS_VERSIONED_DELETEDLOCALLY: 177 return deletedLocallyFormat.format(new Object [] { name, textAnnotation }); 178 case FileInformation.STATUS_VERSIONED_NEWINREPOSITORY: 179 return newInRepositoryFormat.format(new Object [] { name, textAnnotation }); 180 case FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY: 181 return modifiedInRepositoryFormat.format(new Object [] { name, textAnnotation }); 182 case FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY: 183 return removedInRepositoryFormat.format(new Object [] { name, textAnnotation }); 184 case FileInformation.STATUS_VERSIONED_ADDEDLOCALLY: 185 return addedLocallyFormat.format(new Object [] { name, textAnnotation }); 186 case FileInformation.STATUS_VERSIONED_MERGE: 187 return mergeableFormat.format(new Object [] { name, textAnnotation }); 188 case FileInformation.STATUS_VERSIONED_CONFLICT: 189 return conflictFormat.format(new Object [] { name, textAnnotation }); 190 case FileInformation.STATUS_NOTVERSIONED_EXCLUDED: 191 return excludedFormat.format(new Object [] { name, textAnnotation }); 192 default: 193 throw new IllegalArgumentException ("Unknown status: " + status); } 195 } 196 197 private String formatAnnotation(FileInformation info, File file) { 198 updateMessageFormat(); 199 200 String statusString = ""; int status = info.getStatus(); 202 if (status != FileInformation.STATUS_VERSIONED_UPTODATE) { 203 statusString = info.getShortStatusText(); 204 } 205 206 String revisionString = ""; String binaryString = ""; Entry entry = info.getEntry(file); 209 if (entry != null) { 210 revisionString = entry.getRevision(); 211 binaryString = entry.getOptions(); 212 if ("-kb".equals(binaryString) == false) { binaryString = ""; } 215 } 216 String stickyString = Utils.getSticky(file); 217 if (stickyString != null) { 218 stickyString = stickyString.substring(1); 219 } else { 220 stickyString = ""; } 222 223 Object [] arguments = new Object [] { 224 revisionString, 225 statusString, 226 stickyString, 227 binaryString 228 }; 229 return lastMessageFormat.format(arguments, new StringBuffer (), null).toString().trim(); 230 } 231 232 private void updateMessageFormat() { 233 String taf = CvsModuleConfig.getDefault().getPreferences().get(CvsModuleConfig.PROP_ANNOTATIONS_FORMAT, CvsModuleConfig.DEFAULT_ANNOTATIONS_FORMAT); 234 if (lastMessageFormat == null || !taf.equals(lastAnnotationsFormat)) { 235 for (;;) { lastAnnotationsFormat = taf; 237 taf = taf.replaceAll("\\{revision}", "{0}").replaceAll("\\{status}", "{1}").replaceAll("\\{tag}", "{2}").replaceAll("\\{binary}", "{3}"); try { 239 lastMessageFormat = new MessageFormat (taf); 240 lastEmptyAnnotation = lastMessageFormat.format(new Object [] { "", "", "", "" }); break; 242 } catch (Exception e) { 243 Logger.getLogger(Annotator.class.getName()).log(Level.SEVERE, lastAnnotationsFormat, e); 244 taf = CvsModuleConfig.DEFAULT_ANNOTATIONS_FORMAT; 245 } 246 } 247 } 248 } 249 250 private String annotateFolderNameHtml(String name, FileInformation info, File file) { 251 name = htmlEncode(name); 252 int status = info.getStatus(); 253 String textAnnotation; 254 boolean annotationsVisible = CvsModuleConfig.getDefault().getPreferences().getBoolean(CvsModuleConfig.PROP_ANNOTATIONS_VISIBLE, false); 255 if (annotationsVisible && file != null && (status & FileInformation.STATUS_MANAGED) != 0) { 256 textAnnotation = formatAnnotation(info, file); 257 if (textAnnotation.equals(lastEmptyAnnotation)) textAnnotation = ""; } else { 259 textAnnotation = ""; } 261 if (textAnnotation.length() > 0) { 262 textAnnotation = NbBundle.getMessage(Annotator.class, "textAnnotation", textAnnotation); 263 } 264 265 switch (status) { 266 case FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY: 267 case FileInformation.STATUS_VERSIONED_DELETEDLOCALLY: 268 case FileInformation.STATUS_VERSIONED_NEWINREPOSITORY: 269 case FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY: 270 case FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY: 271 case FileInformation.STATUS_NOTVERSIONED_NOTMANAGED: 272 case FileInformation.STATUS_VERSIONED_MERGE: 273 case FileInformation.STATUS_UNKNOWN: 274 case FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY: 275 case FileInformation.STATUS_VERSIONED_CONFLICT: 276 return name; 277 case FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY: 278 case FileInformation.STATUS_VERSIONED_ADDEDLOCALLY: 279 case FileInformation.STATUS_VERSIONED_UPTODATE: 280 return uptodateFormat.format(new Object [] { name, textAnnotation }); 281 case FileInformation.STATUS_NOTVERSIONED_EXCLUDED: 282 return excludedFormat.format(new Object [] { name, textAnnotation }); 283 default: 284 throw new IllegalArgumentException ("Unknown status: " + status); } 286 } 287 288 private String htmlEncode(String name) { 289 if (name.indexOf('<') == -1) return name; 290 return lessThan.matcher(name).replaceAll("<"); } 292 293 public String annotateNameHtml(File file, FileInformation info) { 294 return annotateNameHtml(file.getName(), info, file); 295 } 296 297 public String annotateNameHtml(String name, VCSContext context, int includeStatus) { 298 FileInformation mostImportantInfo = null; 299 File mostImportantFile = null; 300 boolean folderAnnotation = false; 301 302 for (File file : context.getRootFiles()) { 303 FileInformation info = cache.getStatus(file); 304 int status = info.getStatus(); 305 if ((status & includeStatus) == 0) continue; 306 307 if (isMoreImportant(info, mostImportantInfo)) { 308 mostImportantInfo = info; 309 mostImportantFile = file; 310 folderAnnotation = file.isDirectory(); 311 } 312 } 313 314 if (folderAnnotation == false && context.getRootFiles().size() > 1) { 315 folderAnnotation = !org.netbeans.modules.versioning.util.Utils.shareCommonDataObject(context.getRootFiles().toArray(new File [context.getRootFiles().size()])); 316 } 317 318 if (mostImportantInfo == null) return null; 319 return folderAnnotation ? 320 annotateFolderNameHtml(name, mostImportantInfo, mostImportantFile) : 321 annotateNameHtml(name, mostImportantInfo, mostImportantFile); 322 } 323 324 private boolean isMoreImportant(FileInformation a, FileInformation b) { 325 if (b == null) return true; 326 if (a == null) return false; 327 return Utils.getComparableStatus(a.getStatus()) < Utils.getComparableStatus(b.getStatus()); 328 } 329 330 337 Image annotateFolderIcon(Set roots, Image icon) { 338 CvsModuleConfig config = CvsModuleConfig.getDefault(); 339 boolean allExcluded = true; 340 boolean modified = false; 341 342 Map<File , FileInformation> map = cache.getAllModifiedFiles(); 343 Map<File , FileInformation> modifiedFiles = new HashMap<File , FileInformation>(); 344 for (Iterator i = map.keySet().iterator(); i.hasNext();) { 345 File file = (File ) i.next(); 346 FileInformation info = (FileInformation) map.get(file); 347 if (!info.isDirectory() && (info.getStatus() & FileInformation.STATUS_LOCAL_CHANGE) != 0) modifiedFiles.put(file, info); 348 } 349 350 for (Iterator i = roots.iterator(); i.hasNext();) { 351 File file = (File ) i.next(); 352 if (file instanceof FlatFolder) { 353 for (Iterator j = modifiedFiles.keySet().iterator(); j.hasNext();) { 354 File mf = (File ) j.next(); 355 if (mf.getParentFile().equals(file)) { 356 FileInformation info = (FileInformation) modifiedFiles.get(mf); 357 if (info.isDirectory()) continue; 358 int status = info.getStatus(); 359 if (status == FileInformation.STATUS_VERSIONED_CONFLICT) { 360 Image badge = Utilities.loadImage("org/netbeans/modules/versioning/system/cvss/resources/icons/conflicts-badge.png", true); return Utilities.mergeImages(icon, badge, 16, 9); 362 } 363 modified = true; 364 allExcluded &= config.isExcludedFromCommit(mf); 365 } 366 } 367 } else { 368 for (Iterator j = modifiedFiles.keySet().iterator(); j.hasNext();) { 369 File mf = (File ) j.next(); 370 if (Utils.isParentOrEqual(file, mf)) { 371 FileInformation info = (FileInformation) modifiedFiles.get(mf); 372 int status = info.getStatus(); 373 if (status == FileInformation.STATUS_VERSIONED_CONFLICT) { 374 Image badge = Utilities.loadImage("org/netbeans/modules/versioning/system/cvss/resources/icons/conflicts-badge.png", true); return Utilities.mergeImages(icon, badge, 16, 9); 376 } 377 modified = true; 378 allExcluded &= config.isExcludedFromCommit(mf); 379 } 380 } 381 } 382 } 383 384 if (modified && !allExcluded) { 385 Image badge = Utilities.loadImage("org/netbeans/modules/versioning/system/cvss/resources/icons/modified-badge.png", true); return Utilities.mergeImages(icon, badge, 16, 9); 387 } else { 388 return null; 389 } 390 } 391 392 400 public static Action [] getActions(VCSContext ctx, VCSAnnotator.ActionDestination destination) { 401 ResourceBundle loc = NbBundle.getBundle(Annotator.class); 402 Node [] nodes = ctx.getNodes(); 403 File [] files = ctx.getRootFiles().toArray(new File [ctx.getRootFiles().size()]); 404 Lookup context = ctx.getNodes() != null ? Lookups.fixed(ctx.getNodes()) : null; 405 boolean noneVersioned = isNothingVersioned(files); 406 boolean onlyFolders = onlyFolders(files); 407 boolean onlyProjects = onlyProjects(ctx.getNodes()); 408 409 List <Action> actions = new ArrayList<Action>(20); 410 if (destination == VCSAnnotator.ActionDestination.MainMenu) { 411 actions.add(SystemAction.get(CheckoutAction.class)); 412 actions.add(SystemAction.get(AddToRepositoryAction.class)); 413 actions.add(new ChangeCVSRootAction(loc.getString("CTL_MenuItem_ChangeCVSRoot"), ctx)); 414 actions.add(null); 415 actions.add(SystemAction.get(UpdateWithDependenciesAction.class)); 416 actions.add(null); 417 actions.add(SystemAction.get(StatusAction.class)); 418 actions.add(SystemAction.get(DiffAction.class)); 419 actions.add(SystemAction.get(UpdateAction.class)); 420 actions.add(SystemAction.get(CommitAction.class)); 421 actions.add(null); 422 actions.add(SystemAction.get(ExportDiffAction.class)); 423 actions.add(null); 424 actions.add(SystemAction.get(TagAction.class)); 425 actions.add(new BranchesMenu()); 426 actions.add(null); 427 actions.add(SystemAction.get(AnnotationsAction.class)); 428 actions.add(new ViewRevisionAction(ctx)); 429 actions.add(SystemAction.get(SearchHistoryAction.class)); 430 actions.add(null); 431 actions.add(SystemAction.get(GetCleanAction.class)); 432 actions.add(SystemAction.get(ResolveConflictsAction.class)); 433 actions.add(SystemAction.get(IgnoreAction.class)); 434 actions.add(new ExcludeFromCommitAction(ctx)); 435 } else { 436 if (noneVersioned) { 437 actions.add(SystemActionBridge.createAction(SystemAction.get(AddToRepositoryAction.class).createContextAwareInstance(context), loc.getString("CTL_PopupMenuItem_Import"), context)); 438 } else { 439 actions.add(SystemActionBridge.createAction(SystemAction.get(StatusAction.class), loc.getString("CTL_PopupMenuItem_Status"), context)); 440 actions.add(SystemActionBridge.createAction(SystemAction.get(DiffAction.class), loc.getString("CTL_PopupMenuItem_Diff"), context)); 441 actions.add(SystemActionBridge.createAction(SystemAction.get(UpdateAction.class), loc.getString("CTL_PopupMenuItem_Update"), context)); 442 if (onlyProjects) { 443 actions.add(new SystemActionBridge(SystemAction.get(UpdateWithDependenciesAction.class), loc.getString("CTL_PopupMenuItem_UpdateWithDeps"))); 444 } 445 actions.add(SystemActionBridge.createAction(SystemAction.get(CommitAction.class), loc.getString("CTL_PopupMenuItem_Commit"), context)); 446 actions.add(null); 447 actions.add(SystemActionBridge.createAction(SystemAction.get(TagAction.class), loc.getString("CTL_PopupMenuItem_Tag"), context)); 448 actions.add(null); 449 actions.add(SystemActionBridge.createAction(SystemAction.get(BranchAction.class), loc.getString("CTL_PopupMenuItem_Branch"), context)); 450 actions.add(SystemActionBridge.createAction(SystemAction.get(SwitchBranchAction.class), loc.getString("CTL_PopupMenuItem_SwitchBranch"), context)); 451 actions.add(SystemActionBridge.createAction(SystemAction.get(MergeBranchAction.class), loc.getString("CTL_PopupMenuItem_MergeBranch"), context)); 452 actions.add(null); 453 if (!onlyFolders) { 454 actions.add(SystemActionBridge.createAction(SystemAction.get(AnnotationsAction.class), 455 ((AnnotationsAction)SystemAction.get(AnnotationsAction.class)).visible(nodes) ? 456 loc.getString("CTL_PopupMenuItem_HideAnnotations") : 457 loc.getString("CTL_PopupMenuItem_ShowAnnotations"), context)); 458 } 459 actions.add(new ViewRevisionAction(loc.getString("CTL_PopupMenuItem_ViewRevision"), ctx)); actions.add(SystemActionBridge.createAction(SystemAction.get(SearchHistoryAction.class), loc.getString("CTL_PopupMenuItem_SearchHistory"), context)); 461 actions.add(null); 462 actions.add(SystemActionBridge.createAction(SystemAction.get(GetCleanAction.class), loc.getString("CTL_PopupMenuItem_GetClean"), context)); 463 actions.add(SystemActionBridge.createAction(SystemAction.get(ResolveConflictsAction.class), loc.getString("CTL_PopupMenuItem_ResolveConflicts"), context)); 464 if (!onlyProjects) { 465 actions.add(SystemActionBridge.createAction(SystemAction.get(IgnoreAction.class), 466 ((IgnoreAction)SystemAction.get(IgnoreAction.class)).getActionStatus(nodes) == IgnoreAction.UNIGNORING ? 467 loc.getString("CTL_PopupMenuItem_Unignore") : 468 loc.getString("CTL_PopupMenuItem_Ignore"), context)); 469 } 470 actions.add(new ExcludeFromCommitAction(ctx)); 471 } 472 } 473 return actions.toArray(new Action[actions.size()]); 474 } 475 476 private static boolean isNothingVersioned(File [] files) { 477 FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); 478 for (File file : files) { 479 if ((cache.getStatus(file).getStatus() & FileInformation.STATUS_MANAGED) != 0) return false; 480 } 481 return true; 482 } 483 484 private static boolean onlyProjects(Node[] nodes) { 485 if (nodes == null) return false; 486 for (Node node : nodes) { 487 if (node.getLookup().lookup(Project.class) == null) return false; 488 } 489 return true; 490 } 491 492 private static boolean onlyFolders(File [] files) { 493 FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); 494 for (int i = 0; i < files.length; i++) { 495 if (files[i].isFile()) return false; 496 if (!files[i].exists() && !cache.getStatus(files[i]).isDirectory()) return false; 497 } 498 return true; 499 } 500 501 private static MessageFormat getFormat(String key) { 502 String format = NbBundle.getMessage(Annotator.class, key); 503 return new MessageFormat (format); 504 } 505 506 private static final int STATUS_BADGEABLE = FileInformation.STATUS_VERSIONED_UPTODATE | FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY; 507 508 public Image annotateIcon(Image icon, VCSContext context) { 509 boolean folderAnnotation = false; 510 for (File file : context.getRootFiles()) { 511 if (file.isDirectory()) { 512 folderAnnotation = true; 513 break; 514 } 515 } 516 517 if (folderAnnotation == false && context.getRootFiles().size() > 1) { 518 folderAnnotation = !org.netbeans.modules.versioning.util.Utils.shareCommonDataObject(context.getRootFiles().toArray(new File [context.getRootFiles().size()])); 519 } 520 521 if (folderAnnotation == false) { 522 return null; 523 } 524 525 FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); 526 boolean isVersioned = false; 527 for (Iterator<File > i = context.getRootFiles().iterator(); i.hasNext();) { 528 File file = i.next(); 529 if ((cache.getStatus(file).getStatus() & STATUS_BADGEABLE) != 0) { 530 isVersioned = true; 531 break; 532 } 533 } 534 if (!isVersioned) return null; 535 536 537 538 539 540 CvsModuleConfig config = CvsModuleConfig.getDefault(); 541 boolean allExcluded = true; 542 boolean modified = false; 543 544 Map<File , FileInformation> map = cache.getAllModifiedFiles(); 545 Map<File , FileInformation> modifiedFiles = new HashMap<File , FileInformation>(); 546 for (Map.Entry<File , FileInformation> entry : map.entrySet()) { 547 FileInformation info = entry.getValue(); 548 if (!info.isDirectory() && (info.getStatus() & FileInformation.STATUS_LOCAL_CHANGE) != 0) modifiedFiles.put(entry.getKey(), info); 549 } 550 551 for (Iterator<File > i = context.getRootFiles().iterator(); i.hasNext();) { 552 File file = i.next(); 553 if (file instanceof FlatFolder) { 554 for (Iterator<File > j = modifiedFiles.keySet().iterator(); j.hasNext();) { 555 File mf = j.next(); 556 if (mf.getParentFile().equals(file)) { 557 FileInformation info = modifiedFiles.get(mf); 558 if (info.isDirectory()) continue; 559 int status = info.getStatus(); 560 if (status == FileInformation.STATUS_VERSIONED_CONFLICT) { 561 Image badge = Utilities.loadImage("org/netbeans/modules/versioning/system/cvss/resources/icons/conflicts-badge.png", true); return Utilities.mergeImages(icon, badge, 16, 9); 563 } 564 modified = true; 565 allExcluded &= config.isExcludedFromCommit(mf); 566 } 567 } 568 } else { 569 for (Iterator<File > j = modifiedFiles.keySet().iterator(); j.hasNext();) { 570 File mf = j.next(); 571 if (Utils.isParentOrEqual(file, mf)) { 572 FileInformation info = modifiedFiles.get(mf); 573 int status = info.getStatus(); 574 if (status == FileInformation.STATUS_VERSIONED_CONFLICT) { 575 Image badge = Utilities.loadImage("org/netbeans/modules/versioning/system/cvss/resources/icons/conflicts-badge.png", true); return Utilities.mergeImages(icon, badge, 16, 9); 577 } 578 modified = true; 579 allExcluded &= config.isExcludedFromCommit(mf); 580 } 581 } 582 } 583 } 584 585 if (modified && !allExcluded) { 586 Image badge = Utilities.loadImage("org/netbeans/modules/versioning/system/cvss/resources/icons/modified-badge.png", true); return Utilities.mergeImages(icon, badge, 16, 9); 588 } else { 589 return null; 590 } 591 } 592 } 593 | Popular Tags |