/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License.
*/
@NbBundle.Messages({ "Annotator.variable.repositoryState=stands for repository state", "Annotator.variable.trackingStatus=number of incoming and outgoing changes", "Annotator.variable.branch=stands for the current branch label"
}) privatestaticfinal LabelVariables PROJECT_ANNOTATION_VARIABLES = new LabelVariables( new LabelVariable("repository_state", "{repository_state}", Bundle.Annotator_variable_repositoryState()), new LabelVariable("branch", "{branch}", Bundle.Annotator_variable_branch()), new LabelVariable(LABEL_VARIABLE_TRACKING, "{tracking_status}", Bundle.Annotator_variable_trackingStatus()));
public Annotator() {
cache = Git.getInstance().getFileStatusCache();
}
privatestaticboolean isMoreImportant (FileInformation a, FileInformation b) { if (b == null) returntrue; if (a == null) returnfalse; return a.getComparableStatus() < b.getComparableStatus();
}
private Image annotateFileIcon (VCSContext context, Image icon) throws IllegalArgumentException {
FileInformation mostImportantInfo = null; for (final File file : context.getRootFiles()) {
FileInformation info = cache.getStatus(file); if (!info.containsStatus(STATUS_IS_IMPORTANT)) { continue;
} if (isMoreImportant(info, mostImportantInfo)) {
mostImportantInfo = info;
}
} if(mostImportantInfo == null) returnnull;
String tooltip = null;
String statusText = mostImportantInfo.getStatusText(FileInformation.Mode.HEAD_VS_WORKING_TREE); if (mostImportantInfo.containsStatus(Status.NOTVERSIONED_EXCLUDED)) { // File is IGNORED
tooltip = getAnnotationProvider().EXCLUDED_FILE_TOOLTIP.getFormat().format(new Object[] { statusText });
} elseif (mostImportantInfo.getStatus().equals(EnumSet.of(Status.NEW_HEAD_INDEX, Status.REMOVED_INDEX_WORKING_TREE))) { // ADDED to index but REMOVED in WT
tooltip = getAnnotationProvider().UP_TO_DATE_FILE_TOOLTIP.getFormat().format(new Object[]{statusText});
} elseif (mostImportantInfo.getStatus().equals(EnumSet.of(Status.MODIFIED_HEAD_INDEX, Status.MODIFIED_INDEX_WORKING_TREE))) { // MODIFIED in index, MODIFIED in WT, but in WT same as HEAD
tooltip = getAnnotationProvider().UP_TO_DATE_FILE_TOOLTIP.getFormat().format(new Object[]{statusText});
} elseif (mostImportantInfo.containsStatus(Status.REMOVED_HEAD_WORKING_TREE)) { // DELETED in WT
tooltip = getAnnotationProvider().REMOVED_FILE_TOOLTIP.getFormat().format(new Object[] { statusText });
} elseif (mostImportantInfo.getStatus().equals(EnumSet.of(Status.NEW_INDEX_WORKING_TREE, Status.REMOVED_HEAD_INDEX))) { // recreated in WT
tooltip = getAnnotationProvider().UP_TO_DATE_FILE_TOOLTIP.getFormat().format(new Object[]{statusText});
} elseif (mostImportantInfo.getStatus().equals(EnumSet.of(Status.NEW_INDEX_WORKING_TREE, Status.REMOVED_HEAD_INDEX, Status.MODIFIED_HEAD_WORKING_TREE))) { // recreated in WT and modified
tooltip = getAnnotationProvider().MODIFIED_FILE_TOOLTIP.getFormat().format(new Object[] { statusText });
} elseif (mostImportantInfo.containsStatus(Status.NEW_INDEX_WORKING_TREE)) { // NEW in WT and unversioned
tooltip = getAnnotationProvider().NEW_FILE_TOOLTIP.getFormat().format(new Object[] { statusText });
} elseif (mostImportantInfo.containsStatus(Status.NEW_HEAD_INDEX)) { // ADDED to index
tooltip = getAnnotationProvider().ADDED_FILE_TOOLTIP.getFormat().format(new Object[] { statusText });
} elseif (mostImportantInfo.containsStatus(Status.MODIFIED_HEAD_WORKING_TREE)) {
tooltip = getAnnotationProvider().MODIFIED_FILE_TOOLTIP.getFormat().format(new Object[] { statusText });
} elseif (mostImportantInfo.containsStatus(Status.UPTODATE)) {
tooltip = null;
} elseif (mostImportantInfo.containsStatus(Status.IN_CONFLICT)) {
tooltip = getAnnotationProvider().CONFLICT_FILE_TOOLTIP.getFormat().format(new Object[] { statusText });
} elseif (mostImportantInfo.containsStatus(Status.NOTVERSIONED_NOTMANAGED)) {
tooltip = null;
} elseif (mostImportantInfo.containsStatus(Status.UNKNOWN)) {
tooltip = null;
} else { thrownew IllegalStateException("Unknown status: " + mostImportantInfo.getStatus()); //NOI18N
} return tooltip != null ? ImageUtilities.addToolTipToImage(icon, tooltip) : null;
}
@NbBundle.Messages({ "# {0} - branch name", "MSG_Annotator.tooltip.branch=On branch \"{0}\".", "MSG_Annotator.tooltip.branch.withTracking=On branch \"{0}\": {1}.", "MSG_Annotator.tooltip.nobranch=Not on a branch (detached HEAD state)."
}) private Image annotateFolderIcon(VCSContext context, Image icon) {
File root = null; for (Iterator i = context.getRootFiles().iterator(); i.hasNext();) {
File file = (File) i.next(); // There is an assumption here that annotateName was already // called and FileStatusCache.getStatus was scheduled if // FileStatusCache.getCachedStatus returned null.
FileInformation info = cache.getStatus(file); if (info.containsStatus(STATUS_BADGEABLE)) {
root = file; break;
}
} if (root == null) { returnnull;
}
String branchLabel = null;
Set<File> roots = context.getRootFiles();
Set<File> repositories = GitUtils.getRepositoryRoots(roots);
File repository = repositories.isEmpty() ? null : repositories.iterator().next(); if (repository != null && (roots.size() > 1 || root.equals(repository))) { // project node or repository root
RepositoryInfo info = RepositoryInfo.getInstance(repository);
addFileWithRepositoryAnnotation(info, root);
GitBranch branch = info.getActiveBranch(); if (branch != null) {
String branchName = branch.getName();
branchLabel = tooltipBranch; if (branchName == GitBranch.NO_BRANCH) { // do not use equals
branchLabel += Bundle.MSG_Annotator_tooltip_nobranch();
} else {
RepositoryInfo.TrackingInfo tracking = info.getTracking(); if (tracking.isKnown()) {
branchLabel += Bundle.MSG_Annotator_tooltip_branch_withTracking(branchName, tracking.getDescription());
} else {
branchLabel += Bundle.MSG_Annotator_tooltip_branch(branchName);
}
}
}
}
Image retval = icon; if (branchLabel != null) {
retval = ImageUtilities.addToolTipToImage(retval, branchLabel);
}
Image badge = null; if (cache.containsFiles(context, EnumSet.of(Status.IN_CONFLICT), false)) {
badge = ImageUtilities.assignToolTipToImage(ImageUtilities.loadImage(badgeConflicts, true), toolTipConflict);
} elseif (cache.containsFiles(context, FileInformation.STATUS_LOCAL_CHANGES, false)) {
badge = ImageUtilities.assignToolTipToImage(ImageUtilities.loadImage(badgeModified, true), toolTipModified);
} if (badge != null) {
retval = ImageUtilities.mergeImages(retval, badge, 16, 9);
} return retval;
}
privatefinal Map<RepositoryInfo, Set<File>> filesWithRepositoryAnnotations = new WeakHashMap<RepositoryInfo, Set<File>>(3);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.