Skip to main content
summaryrefslogtreecommitdiffstats
blob: f16a52dc442173b3f69fd97d994aa53e2e7e8733 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ote.ui.test.manager.core;

import java.io.File;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.osee.framework.ui.ws.AWorkspace;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IPersistableElement;

public class TestManagerEditorInput implements IFileEditorInput, IPersistableElement {

   private static final String FACTORY_ID = TestManagerEditorInputFactory.class.getCanonicalName();
   private final IFile iFile;

   public TestManagerEditorInput(File file) {
      this(AWorkspace.fileToIFile(file));
   }

   public TestManagerEditorInput(IFile iFile) {
      super();
      this.iFile = iFile;
   }

   /*
    * @see java.lang.Object#equals(java.lang.Object)
    */
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      }

      if (iFile != null && o instanceof TestManagerEditorInput) {
         TestManagerEditorInput input = (TestManagerEditorInput) o;
         return iFile.equals(input.getFile());
      }
      return false;
   }

   /*
    * @see org.eclipse.ui.IEditorInput#exists()
    */
   @Override
   public boolean exists() {
      return true;
   }

   /*
    * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
    */
   @Override
   public Object getAdapter(Class adapter) {
      return iFile.getAdapter(adapter);
   }

   @Override
   public String getFactoryId() {
      return FACTORY_ID;
   }

   @Override
   public IFile getFile() {
      return iFile;
   }

   /*
    * @see org.eclipse.ui.IEditorInput#getImageDescriptor()
    */
   @Override
   public ImageDescriptor getImageDescriptor() {
      return null;
   }

   // /*
   // * @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object)
   // */
   // public IPath getPath(Object element) {
   // if (element instanceof NonExistingFileEditorInput) {
   // NonExistingFileEditorInput input= (NonExistingFileEditorInput) element;
   // return Path.fromOSString(input.fFile.getAbsolutePath());
   // }
   // return null;
   // }

   /*
    * @see org.eclipse.ui.IEditorInput#getName()
    */
   @Override
   public String getName() {
      return iFile.getName();
   }

   /*
    * @see org.eclipse.ui.IEditorInput#getPersistable()
    */
   @Override
   public IPersistableElement getPersistable() {
      return this;
   }

   @Override
   public IStorage getStorage() throws CoreException {
      return new IStorage() {

         @Override
         public Object getAdapter(Class adapter) {
            return iFile.getAdapter(adapter);
         }

         @Override
         public InputStream getContents() throws CoreException {
            return iFile.getContents();
         }

         @Override
         public IPath getFullPath() {
            return iFile.getFullPath();
         }

         @Override
         public String getName() {
            return iFile.getName();
         }

         @Override
         public boolean isReadOnly() {
            return false;
         }

      };
   }

   /*
    * @see org.eclipse.ui.IEditorInput#getToolTipText()
    */
   @Override
   public String getToolTipText() {
      return iFile.getName();
   }

   /*
    * @see java.lang.Object#hashCode()
    */
   @Override
   public int hashCode() {
      return iFile.hashCode();
   }

   @Override
   public void saveState(IMemento memento) {
      if (iFile != null && iFile.getLocation().toFile().exists()) {
         memento.putString("path", iFile.getLocation().toFile().getAbsolutePath());
      }
   }
}

Back to the top