Author: scabanovich
Date: 2009-11-26 07:21:21 -0500 (Thu, 26 Nov 2009)
New Revision: 18849
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/core/resources/XModelObjectEditorInput.java
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/core/resources/XModelObjectEditorInput.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/core/resources/XModelObjectEditorInput.java 2009-11-26
11:08:29 UTC (rev 18848)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/core/resources/XModelObjectEditorInput.java 2009-11-26
12:21:21 UTC (rev 18849)
@@ -10,6 +10,7 @@
******************************************************************************/
package org.jboss.tools.common.core.resources;
+import java.io.File;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URI;
@@ -19,12 +20,17 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.internal.core.JarEntryFile;
+import org.eclipse.jdt.internal.core.JarEntryResource;
+import org.eclipse.jdt.internal.ui.javaeditor.JarEntryEditorInput;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.*;
import org.eclipse.ui.editors.text.ILocationProvider;
import org.eclipse.ui.internal.part.NullEditorInput;
import org.eclipse.ui.part.FileEditorInput;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
import org.jboss.tools.common.model.filesystems.impl.*;
import org.jboss.tools.common.model.project.IModelNature;
import org.jboss.tools.common.model.util.*;
@@ -210,6 +216,31 @@
}
private static IEditorInput convertStorageEditorInput(IStorageEditorInput input) {
+ if(input instanceof JarEntryEditorInput) {
+ JarEntryEditorInput j = (JarEntryEditorInput)input;
+ JarEntryFile file = (JarEntryFile)j.getStorage();
+ String jarFile = file.getPackageFragmentRoot().getPath().toString();
+ String entry = file.getName();
+ JarEntryResource r = file;
+ while(r != null && r.getParent() instanceof JarEntryResource) {
+ r = (JarEntryResource)r.getParent();
+ entry = r.getName() + "/" + entry;
+ }
+ if(r != null && r.getParent() instanceof IPackageFragment) {
+ IPackageFragment pf = (IPackageFragment)r.getParent();
+ while(pf != null) {
+ String p = pf.getElementName();
+ entry = p + "/" + entry;
+ if(pf.getParent() instanceof IPackageFragment) {
+ pf = (IPackageFragment)pf.getParent();
+ } else {
+ pf = null;
+ }
+ }
+ }
+ IEditorInput result = createJarEntryEditorInput(jarFile, entry);
+ if(result != null) return result;
+ }
String[] entryInfo = parseJarEntryFileInput(input);
if(entryInfo == null) return input;
String jarFile = entryInfo[0];
@@ -245,6 +276,18 @@
if(f == null) return null;
IProject p = f.getProject();
IModelNature n = EclipseResourceUtil.getModelNature(p);
+ if(n == null) return null;
+ XModelObject[] fs = FileSystemsHelper.getFileSystems(n.getModel()).getChildren();
+ for (XModelObject s: fs) {
+ if(s instanceof JarSystemImpl) {
+ JarSystemImpl j = (JarSystemImpl)s;
+ String loc = j.getLocation();
+ if(new File(loc).equals(new File(jarFile))) {
+ XModelObject result = s.getChildByPath(entry);
+ if(result != null) return result;
+ }
+ }
+ }
return (n == null) ? null : n.getModel().getByPath("/" + entry);
//$NON-NLS-1$
}
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-26
11:08:29 UTC (rev 18848)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/ModelObjectStorageEditorInput.java 2009-11-26
12:21:21 UTC (rev 18849)
@@ -11,14 +11,18 @@
package org.jboss.tools.common.model.ui.editor;
import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
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.eclipse.jdt.internal.core.PackageFragment;
import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
import org.jboss.tools.common.core.resources.XModelObjectEditorInputFactory;
import org.eclipse.ui.*;
@@ -45,6 +49,7 @@
XModelObject o = object;
JarEntryFile f = null;
JarEntryResource current = null;
+ String packageName = "";
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;
@@ -58,6 +63,11 @@
current = f;
} else {
if(f == null) return null;
+ if(packageName.length() > 0) {
+ packageName = part + "." + packageName;
+ } else {
+ packageName = part;
+ }
JarEntryDirectory d = new JarEntryDirectory(part);
current.setParent(d);
current = d;
@@ -68,13 +78,7 @@
}
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;
@@ -84,7 +88,18 @@
IPackageFragmentRoot root = jp.getPackageFragmentRoot(file);
if(root == null) return null;
- current.setParent(root);
+
+ try {
+ file = new File(file).getCanonicalPath();
+ } catch (IOException e) {
+
+ }
+ if(current != null && !"META-INF".equalsIgnoreCase(current.getName())
&& packageName.length() > 0) {
+ IPackageFragment pf = root.getPackageFragment(packageName);
+ f.setParent(pf);
+ } else {
+ current.setParent(root);
+ }
return f;
}