ComponentWithBrowseButton - optional remove listener on hide
[fedora-idea.git] / platform / vcs-impl / src / com / intellij / openapi / vcs / changes / VcsCurrentRevisionProxy.java
bloba83bec77d363e65bcea6ef83fde2f76af16a2671
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.vcs.changes;
18 import org.jetbrains.annotations.Nullable;
19 import org.jetbrains.annotations.NotNull;
20 import com.intellij.openapi.vcs.VcsException;
21 import com.intellij.openapi.vcs.FilePath;
22 import com.intellij.openapi.vcs.FilePathImpl;
23 import com.intellij.openapi.vcs.diff.DiffProvider;
24 import com.intellij.openapi.vcs.history.VcsRevisionNumber;
25 import com.intellij.openapi.vfs.VirtualFile;
27 /**
28 * @author yole
30 public class VcsCurrentRevisionProxy implements ContentRevision {
31 private final DiffProvider myDiffProvider;
32 private final VirtualFile myFile;
33 private ContentRevision myVcsRevision;
35 public VcsCurrentRevisionProxy(final DiffProvider diffProvider, final VirtualFile file) {
36 myDiffProvider = diffProvider;
37 myFile = file;
40 @Nullable
41 public String getContent() throws VcsException {
42 return getVcsRevision().getContent();
45 @NotNull
46 public FilePath getFile() {
47 return new FilePathImpl(myFile);
50 @NotNull
51 public VcsRevisionNumber getRevisionNumber() {
52 try {
53 return getVcsRevision().getRevisionNumber();
55 catch(VcsException ex) {
56 return VcsRevisionNumber.NULL;
60 private ContentRevision getVcsRevision() throws VcsException {
61 if (myVcsRevision == null) {
62 final VcsRevisionNumber currentRevision = myDiffProvider.getCurrentRevision(myFile);
63 if (currentRevision == null) {
64 throw new VcsException("Failed to fetch current revision");
66 myVcsRevision = myDiffProvider.createFileContent(currentRevision, myFile);
67 if (myVcsRevision == null) {
68 throw new VcsException("Failed to create content for current revision");
71 return myVcsRevision;