KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > compare > internal > patch > DiffProject


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.compare.internal.patch;
12
13 import java.util.*;
14
15 import org.eclipse.core.resources.IFile;
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.ui.model.IWorkbenchAdapter;
20
21 /**
22  * A diff project represents a project that was read from a workspace patch.
23  * It contains the set of file diffs that were associated with the project
24  * in the patch file.
25  */

26 public class DiffProject {
27
28     private IProject fProject;
29     private Set fDiffs= new HashSet();
30
31     /**
32      * Create a diff project for the given workspace project.
33      * @param project a workspace project
34      */

35     public DiffProject(IProject project) {
36         this.fProject= project;
37     }
38
39     /**
40      * Add the file diff to this project.
41      * @param diff the file diff.
42      */

43     void add(FileDiff diff) {
44         fDiffs.add(diff);
45         if (diff.getProject() != this)
46             diff.setProject(this);
47     }
48
49     
50     /**
51      * Return the workspace project associated with this diff project.
52      * @return the workspace project associated with this project
53      */

54     public IProject getProject() {
55         return this.fProject;
56     }
57
58     /**
59      * Return the name of this project.
60      * @return the name of this project
61      */

62     public String JavaDoc getName() {
63         return fProject.getName();
64     }
65
66     /**
67      * Return the file at the given path relative to this project.
68      * @param path the relative path
69      * @return the file at the given path relative to this project
70      */

71     public IFile getFile(IPath path) {
72         return fProject.getFile(path);
73     }
74
75     public ImageDescriptor getImageDescriptor() {
76         Object JavaDoc o= fProject.getAdapter(IWorkbenchAdapter.class);
77         if (o instanceof IWorkbenchAdapter) {
78             ImageDescriptor id= ((IWorkbenchAdapter) o).getImageDescriptor(fProject);
79             return id;
80         }
81         return null;
82     }
83
84     /**
85      * Remove the file diff from this project.
86      * @param diff the diff to be removed
87      */

88     public void remove(FileDiff diff) {
89         fDiffs.remove(diff);
90     }
91
92     /**
93      * Return whether this project contains the given diff.
94      * @param diff a file diff
95      * @return whether this project contains the given diff
96      */

97     public boolean contains(FileDiff diff) {
98         return fDiffs.contains(diff);
99     }
100
101     /**
102      * Return the file diffs associated with this project.
103      * @return the file diffs associated with this project
104      */

105     public FileDiff[] getFileDiffs() {
106         return (FileDiff[]) fDiffs.toArray(new FileDiff[fDiffs.size()]);
107     }
108 }
109
Popular Tags