Author: scabanovich
Date: 2012-01-10 17:20:21 -0500 (Tue, 10 Jan 2012)
New Revision: 37750
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/ModelObjectJarEntryEditorInput.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/ModelObjectStorageEditorInput.java
Log:
JBIDE-9420
https://issues.joss.org/browse/JBIDE-9420
In storage editor inputs, handle not only jar entries, but also files from external class
folders.
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 2012-01-10
22:12:02 UTC (rev 37749)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/core/resources/XModelObjectEditorInput.java 2012-01-10
22:20:21 UTC (rev 37750)
@@ -30,6 +30,7 @@
import org.eclipse.ui.part.FileEditorInput;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.XModelObjectConstants;
import org.jboss.tools.common.model.filesystems.FileSystemsHelper;
import org.jboss.tools.common.model.filesystems.impl.*;
import org.jboss.tools.common.model.project.IModelNature;
@@ -297,21 +298,18 @@
if(model == null) return null;
XModelObject[] fs = FileSystemsHelper.getFileSystems(model).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 && entry != null) {
- int q = entry.indexOf('/');
- int d = entry.indexOf('.');
- if(q > d && d >= 0) {
- String entry1 = entry.substring(0, q).replace('.', '/') +
entry.substring(q);
- result = s.getChildByPath(entry1);
- }
+ String loc = Paths.expand(s.get(XModelObjectConstants.ATTR_NAME_LOCATION),
model.getProperties());
+ if(new File(loc).equals(new File(jarFile))) {
+ XModelObject result = s.getChildByPath(entry);
+ if(result == null && entry != null) {
+ int q = entry.indexOf('/');
+ int d = entry.indexOf('.');
+ if(q > d && d >= 0) {
+ String entry1 = entry.substring(0, q).replace('.', '/') +
entry.substring(q);
+ result = s.getChildByPath(entry1);
}
- if(result != null) return result;
}
+ 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/ModelObjectJarEntryEditorInput.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/ModelObjectJarEntryEditorInput.java 2012-01-10
22:12:02 UTC (rev 37749)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/ModelObjectJarEntryEditorInput.java 2012-01-10
22:20:21 UTC (rev 37750)
@@ -35,6 +35,9 @@
}
public boolean equals(Object o) {
+ if(o == this) {
+ return true;
+ }
if(o instanceof IStorageEditorInput) {
IStorageEditorInput input = (IStorageEditorInput)o;
IStorage storage = null;
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 2012-01-10
22:12:02 UTC (rev 37749)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/editor/ModelObjectStorageEditorInput.java 2012-01-10
22:20:21 UTC (rev 37750)
@@ -11,16 +11,19 @@
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.IJarEntryResource;
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.eclipse.jdt.internal.core.NonJavaResource;
import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
import org.jboss.tools.common.core.resources.XModelObjectEditorInputFactory;
import org.eclipse.ui.*;
@@ -30,10 +33,11 @@
import org.jboss.tools.common.model.filesystems.impl.*;
import org.jboss.tools.common.model.ui.ModelUIPlugin;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.model.util.Paths;
import org.jboss.tools.common.util.FileUtil;
public class ModelObjectStorageEditorInput extends ModelObjectEditorInput implements
IStorageEditorInput {
- JarEntryFile jarEntryFile = null;
+ IJarEntryResource jarEntryFile = null;
public ModelObjectStorageEditorInput(XModelObject object) {
super(object);
@@ -44,15 +48,25 @@
return jarEntryFile != null ? jarEntryFile : storage;
}
- JarEntryFile findJarEntryFile() {
+ @SuppressWarnings("rawtypes")
+ public Object getAdapter(Class adapter) {
+ if(adapter == IFile.class) return null;
+ return super.getAdapter(adapter);
+ }
+
+ IJarEntryResource findJarEntryFile() {
XModelObject o = object;
JarEntryFile f = null;
JarEntryResource current = null;
String packageName = "";
+ List<String> parts = new ArrayList<String>();
+ List<XModelObject> os = new ArrayList<XModelObject>();
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) {
+ parts.add(0, part);
+ os.add(0, o);
if(f == null) {
f = new JarEntryFile(part) {
public InputStream getContents() throws CoreException {
@@ -61,7 +75,6 @@
};
current = f;
} else {
- if(f == null) return null;
if(packageName.length() > 0) {
packageName = part + "." + packageName;
} else {
@@ -75,8 +88,8 @@
}
o = o.getParent();
}
- if(!(o instanceof JarSystemImpl)) return null;
- String file = ((JarSystemImpl)o).getLocation();
+// if(!(o instanceof JarSystemImpl)) return null;
+ String file = Paths.expand(o.get(XModelObjectConstants.ATTR_NAME_LOCATION),
o.getModel().getProperties());
IProject p = EclipseResourceUtil.getProject(o);
IJavaProject jp = EclipseResourceUtil.getJavaProject(p);
@@ -111,6 +124,21 @@
f.setParent(pf);
} else {
current.setParent(root);
+ if(!(o instanceof JarSystemImpl)) {
+ Object q = root;
+ NonJavaResource nj = null;
+ for (int i = 0; i < parts.size(); i++) {
+ IResource ri = (IResource)os.get(i).getAdapter(IResource.class);
+ if(ri == null) {
+ return f;
+ }
+ nj = new NonJavaResource(q, ri);
+ q = nj;
+ }
+ if(nj != null) {
+ return nj;
+ }
+ }
}
return f;