Author: scabanovich
Date: 2009-11-25 12:48:09 -0500 (Wed, 25 Nov 2009)
New Revision: 18832
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/ModelObjectStorageEditorInput.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4635
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/ModelObjectStorageEditorInput.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/ModelObjectStorageEditorInput.java 2009-11-25
15:16:04 UTC (rev 18831)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/ModelObjectStorageEditorInput.java 2009-11-25
17:48:09 UTC (rev 18832)
@@ -11,8 +11,14 @@
package org.jboss.tools.common.model.ui.editor;
import java.io.*;
+
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.internal.core.JarEntryDirectory;
+import org.eclipse.jdt.internal.core.JarEntryFile;
+import org.eclipse.jdt.internal.core.JarEntryResource;
import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
import org.jboss.tools.common.core.resources.XModelObjectEditorInputFactory;
import org.eclipse.ui.*;
@@ -24,14 +30,64 @@
import org.jboss.tools.common.util.FileUtil;
public class ModelObjectStorageEditorInput extends ModelObjectEditorInput implements
IStorageEditorInput {
-
+ JarEntryFile jarEntryFile = null;
+
public ModelObjectStorageEditorInput(XModelObject object) {
super(object);
+ jarEntryFile = findJarEntryFile();
}
public IStorage getStorage() throws CoreException {
- return storage;
+ return jarEntryFile != null ? jarEntryFile : storage;
}
+
+ JarEntryFile findJarEntryFile() {
+ XModelObject o = object;
+ JarEntryFile f = null;
+ JarEntryResource current = null;
+ while(o != null && o.getFileType() != XModelObject.SYSTEM) {
+ String part = o.getFileType() == XModelObject.FILE ? FileAnyImpl.toFileName(o) :
+ o.getFileType() == XModelObject.FOLDER ?
o.getAttributeValue(XModelObjectConstants.ATTR_NAME) : null;
+ if(part != null) {
+ if(f == null) {
+ f = new JarEntryFile(part) {
+ public InputStream getContents() throws CoreException {
+ return storage.getContents();
+ }
+ };
+ current = f;
+ } else {
+ if(f == null) return null;
+ JarEntryDirectory d = new JarEntryDirectory(part);
+ current.setParent(d);
+ current = d;
+ }
+
+ }
+ o = o.getParent();
+ }
+ if(!(o instanceof JarSystemImpl)) return null;
+ String file = ((JarSystemImpl)o).getLocation();
+
+ try {
+ file = new File(file).getCanonicalPath();
+ } catch (IOException e) {
+
+ }
+
+ IFile[] fs = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(new
File(file).toURI());
+ if(fs == null || fs.length == 0) return null;
+
+ IProject p = fs[0].getProject();
+ IJavaProject jp = EclipseResourceUtil.getJavaProject(p);
+ if(jp == null) return null;
+
+ IPackageFragmentRoot root = jp.getPackageFragmentRoot(file);
+ if(root == null) return null;
+ current.setParent(root);
+
+ return f;
+ }
IStorage storage = new Storage();
@@ -104,6 +160,12 @@
public boolean equals(Object o) {
if(super.equals(o)) return true;
if(o instanceof IStorageEditorInput) {
+ try {
+ IStorage st = ((IStorageEditorInput)o).getStorage();
+ if(jarEntryFile != null && jarEntryFile.equals(st)) return true;
+ } catch (CoreException e) {
+ //ignore
+ }
String[] entryInfo =
XModelObjectEditorInput.parseJarEntryFileInput((IStorageEditorInput)o);
if(entryInfo == null) return false;
XModelObject mo = XModelObjectEditorInput.getJarEntryObject(entryInfo[0],
entryInfo[1]);