Remove System.out.println from RevWalkFilterTest
[jgit.git] / org.spearce.egit.ui / src / org / spearce / egit / ui / internal / EditableRevision.java
blobee064efdf19adf676361a17b33b72040b2d1da29
1 /*
2 * Copyright (C) 2009, Yann Simon <yann.simon.fr@gmail.com>
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
21 * written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org.spearce.egit.ui.internal;
40 import java.io.ByteArrayInputStream;
41 import java.io.InputStream;
43 import org.eclipse.compare.IContentChangeListener;
44 import org.eclipse.compare.IContentChangeNotifier;
45 import org.eclipse.compare.IEditableContent;
46 import org.eclipse.compare.ISharedDocumentAdapter;
47 import org.eclipse.compare.ITypedElement;
48 import org.eclipse.compare.internal.ContentChangeNotifier;
49 import org.eclipse.core.runtime.CoreException;
50 import org.eclipse.core.runtime.Platform;
51 import org.eclipse.team.core.history.IFileRevision;
52 import org.eclipse.team.internal.ui.history.FileRevisionTypedElement;
53 import org.eclipse.team.internal.ui.synchronize.EditableSharedDocumentAdapter;
55 /**
56 * @author simon
59 public class EditableRevision extends FileRevisionTypedElement implements
60 ITypedElement, IEditableContent, IContentChangeNotifier {
62 private byte[] modifiedContent;
64 private ContentChangeNotifier fChangeNotifier;
66 private EditableSharedDocumentAdapter sharedDocumentAdapter;
68 /**
69 * @param fileRevision
71 public EditableRevision(IFileRevision fileRevision) {
72 super(fileRevision);
75 public boolean isEditable() {
76 return true;
79 public ITypedElement replace(ITypedElement dest, ITypedElement src) {
80 return null;
83 @Override
84 public InputStream getContents() throws CoreException {
85 if (modifiedContent != null) {
86 return new ByteArrayInputStream(modifiedContent);
88 return super.getContents();
91 public void setContent(byte[] newContent) {
92 modifiedContent = newContent;
93 fireContentChanged();
96 /**
97 * @return the modified content
99 public byte[] getModifiedContent() {
100 return modifiedContent;
103 public Object getAdapter(Class adapter) {
104 if (adapter == ISharedDocumentAdapter.class) {
105 return getSharedDocumentAdapter();
107 return Platform.getAdapterManager().getAdapter(this, adapter);
110 private synchronized ISharedDocumentAdapter getSharedDocumentAdapter() {
111 if (sharedDocumentAdapter == null)
112 sharedDocumentAdapter = new EditableSharedDocumentAdapter(
113 new EditableSharedDocumentAdapter.ISharedDocumentAdapterListener() {
114 public void handleDocumentConnected() {
117 public void handleDocumentFlushed() {
120 public void handleDocumentDeleted() {
123 public void handleDocumentSaved() {
126 public void handleDocumentDisconnected() {
129 return sharedDocumentAdapter;
132 public void addContentChangeListener(IContentChangeListener listener) {
133 if (fChangeNotifier == null)
134 fChangeNotifier = new ContentChangeNotifier(this);
135 fChangeNotifier.addContentChangeListener(listener);
138 public void removeContentChangeListener(IContentChangeListener listener) {
139 if (fChangeNotifier != null) {
140 fChangeNotifier.removeContentChangeListener(listener);
141 if (fChangeNotifier.isEmpty())
142 fChangeNotifier = null;
147 * Notifies all registered <code>IContentChangeListener</code>s of a content
148 * change.
150 protected void fireContentChanged() {
151 if (fChangeNotifier == null || fChangeNotifier.isEmpty()) {
152 return;
154 fChangeNotifier.fireContentChanged();