KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > part > MultiEditorInput


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.ui.part;
12
13 import java.util.Arrays JavaDoc;
14
15 import org.eclipse.core.runtime.Assert;
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.ui.IEditorInput;
18 import org.eclipse.ui.IPersistableElement;
19
20 /**
21  * Implements an input for a <code>MultiEditor</code>.
22  *
23  * This class is intended to be instantiated by clients but is
24  * not intended to be subclassed.
25  */

26 public class MultiEditorInput implements IEditorInput {
27
28     IEditorInput input[];
29
30     String JavaDoc editors[];
31
32     /**
33      * Constructs a new MultiEditorInput.
34      */

35     public MultiEditorInput(String JavaDoc[] editorIDs, IEditorInput[] innerEditors) {
36         Assert.isNotNull(editorIDs);
37         Assert.isNotNull(innerEditors);
38         editors = editorIDs;
39         input = innerEditors;
40     }
41
42     /**
43      * Returns an array with the input of all inner editors.
44      */

45     public IEditorInput[] getInput() {
46         return input;
47     }
48
49     /**
50      * Retunrs an array with the id of all inner editors.
51      */

52     public String JavaDoc[] getEditors() {
53         return editors;
54     }
55
56     /*
57      * @see IEditorInput#exists()
58      */

59     public boolean exists() {
60         return true;
61     }
62
63     /*
64      * @see IEditorInput#getImageDescriptor()
65      */

66     public ImageDescriptor getImageDescriptor() {
67         return null;
68     }
69
70     /*
71      * @see IEditorInput#getName()
72      */

73     public String JavaDoc getName() {
74         String JavaDoc name = ""; //$NON-NLS-1$
75
for (int i = 0; i < (input.length - 1); i++) {
76             name = name + input[i].getName() + "/"; //$NON-NLS-1$
77
}
78         name = name + input[input.length - 1].getName();
79         return name;
80     }
81
82     /*
83      * @see IEditorInput#getPersistable()
84      */

85     public IPersistableElement getPersistable() {
86         return null;
87     }
88
89     /*
90      * @see IEditorInput#getToolTipText()
91      */

92     public String JavaDoc getToolTipText() {
93         return getName();
94     }
95
96     /*
97      * @see IAdaptable#getAdapter(Class)
98      */

99     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
100         return null;
101     }
102     
103     
104     /* (non-Javadoc)
105      * @see java.lang.Object#equals(java.lang.Object)
106      */

107     public boolean equals(Object JavaDoc obj) {
108         if (this == obj) {
109             return true;
110         }
111         if (!(obj instanceof MultiEditorInput)) {
112             return false;
113         }
114         MultiEditorInput other = (MultiEditorInput) obj;
115         return Arrays.equals(this.editors, other.editors) && Arrays.equals(this.input, other.input);
116     }
117     
118     
119     /* (non-Javadoc)
120      * @see java.lang.Object#hashCode()
121      */

122     public int hashCode() {
123         int hash = 0;
124         for (int i = 0; i < editors.length; i++) {
125             hash = hash * 37 + editors[i].hashCode();
126         }
127         for (int i = 0; i < input.length; i++) {
128             hash = hash * 37 + input[i].hashCode();
129         }
130         return hash;
131     }
132 }
133
Popular Tags