001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.part;
011:
012: import java.util.Arrays;
013:
014: import org.eclipse.core.runtime.Assert;
015: import org.eclipse.jface.resource.ImageDescriptor;
016: import org.eclipse.ui.IEditorInput;
017: import org.eclipse.ui.IPersistableElement;
018:
019: /**
020: * Implements an input for a <code>MultiEditor</code>.
021: *
022: * This class is intended to be instantiated by clients but is
023: * not intended to be subclassed.
024: */
025: public class MultiEditorInput implements IEditorInput {
026:
027: IEditorInput input[];
028:
029: String editors[];
030:
031: /**
032: * Constructs a new MultiEditorInput.
033: */
034: public MultiEditorInput(String[] editorIDs,
035: IEditorInput[] innerEditors) {
036: Assert.isNotNull(editorIDs);
037: Assert.isNotNull(innerEditors);
038: editors = editorIDs;
039: input = innerEditors;
040: }
041:
042: /**
043: * Returns an array with the input of all inner editors.
044: */
045: public IEditorInput[] getInput() {
046: return input;
047: }
048:
049: /**
050: * Retunrs an array with the id of all inner editors.
051: */
052: public String[] getEditors() {
053: return editors;
054: }
055:
056: /*
057: * @see IEditorInput#exists()
058: */
059: public boolean exists() {
060: return true;
061: }
062:
063: /*
064: * @see IEditorInput#getImageDescriptor()
065: */
066: public ImageDescriptor getImageDescriptor() {
067: return null;
068: }
069:
070: /*
071: * @see IEditorInput#getName()
072: */
073: public String getName() {
074: String name = ""; //$NON-NLS-1$
075: for (int i = 0; i < (input.length - 1); i++) {
076: name = name + input[i].getName() + "/"; //$NON-NLS-1$
077: }
078: name = name + input[input.length - 1].getName();
079: return name;
080: }
081:
082: /*
083: * @see IEditorInput#getPersistable()
084: */
085: public IPersistableElement getPersistable() {
086: return null;
087: }
088:
089: /*
090: * @see IEditorInput#getToolTipText()
091: */
092: public String getToolTipText() {
093: return getName();
094: }
095:
096: /*
097: * @see IAdaptable#getAdapter(Class)
098: */
099: public Object getAdapter(Class adapter) {
100: return null;
101: }
102:
103: /* (non-Javadoc)
104: * @see java.lang.Object#equals(java.lang.Object)
105: */
106: public boolean equals(Object obj) {
107: if (this == obj) {
108: return true;
109: }
110: if (!(obj instanceof MultiEditorInput)) {
111: return false;
112: }
113: MultiEditorInput other = (MultiEditorInput) obj;
114: return Arrays.equals(this .editors, other.editors)
115: && Arrays.equals(this .input, other.input);
116: }
117:
118: /* (non-Javadoc)
119: * @see java.lang.Object#hashCode()
120: */
121: public int hashCode() {
122: int hash = 0;
123: for (int i = 0; i < editors.length; i++) {
124: hash = hash * 37 + editors[i].hashCode();
125: }
126: for (int i = 0; i < input.length; i++) {
127: hash = hash * 37 + input[i].hashCode();
128: }
129: return hash;
130: }
131: }
|