Author: dazarov
Date: 2011-07-08 16:16:59 -0400 (Fri, 08 Jul 2011)
New Revision: 32775
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/CDISeamResourceLoadingHyperlink.java
Log:
https://issues.jboss.org/browse/JBIDE-8202
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/CDISeamResourceLoadingHyperlink.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/CDISeamResourceLoadingHyperlink.java 2011-07-08
17:23:50 UTC (rev 32774)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/CDISeamResourceLoadingHyperlink.java 2011-07-08
20:16:59 UTC (rev 32775)
@@ -10,13 +10,21 @@
******************************************************************************/
package org.jboss.tools.cdi.seam.text.ext.hyperlink;
+import java.util.Set;
+
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.IEditorPart;
import org.jboss.tools.cdi.seam.text.ext.CDISeamExtMessages;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.common.text.ext.util.Utils;
public class CDISeamResourceLoadingHyperlink extends AbstractHyperlink{
private IRegion region;
@@ -42,9 +50,80 @@
@Override
public IFile getReadyToOpenFile(){
- return getFileFromProject(path);
+ IFile result = getFileFromProject(path);
+ if(result != null && result.exists())
+ return result;
+
+ if(file == null || !file.isAccessible()) return null;
+
+ path = findAndReplaceElVariable(path);
+
+ IProject project = file.getProject();
+ String name = Utils.trimFilePath(path);
+ IPath currentPath = file.getLocation().removeLastSegments(1);
+ IResource member = null;
+
+ if (name.startsWith("/")) { //$NON-NLS-1$
+ member = findByAbsolutePath(project, name);
+ } else {
+ member = findByRelativePath(project, currentPath, name);
+ if (member == null && name.length() > 0) {
+ member = findByAbsolutePath(project, "/" + name); //$NON-NLS-1$
+ }
+ }
+ if (member != null && (member instanceof IFile)) {
+ if (((IFile) member).exists())
+ return (IFile) member;
+ }
+ return null;
}
+
+ private IFile findByRelativePath(IProject project, IPath basePath, String path) {
+ if (path == null || path.trim().length() == 0)
+ return null;
+
+ path = findAndReplaceElVariable(path);
+
+ IPath projectPath = project.getLocation();
+ IFile member = null;
+ Set<IFolder> sources = EclipseResourceUtil.getSourceFolders(file.getProject());
+ for (IFolder source : sources) {
+ //IPath sourcePath = source.getLocation();
+
+ // Look in source environment
+ IPath webRootPath = source.getFullPath();//projectPath.append(sourcePath);
+ IPath relativePath = Utils.getRelativePath(webRootPath, basePath);
+ IPath filePath = relativePath.append(path);
+ member = project.getFolder(webRootPath).getFile(filePath);
+ if (member.exists()) {
+ return member;
+ }
+
+ }
+ return null;
+ }
+
+ private IFile findByAbsolutePath(IProject project, String path) {
+
+ path = findAndReplaceElVariable(path);
+
+ IFile member = null;
+
+ Set<IFolder> sources = EclipseResourceUtil.getSourceFolders(file.getProject());
+ for (IFolder source : sources) {
+ IPath sourcePath = source.getFullPath();
+
+ // Look in source environment
+ member = project.getFolder(sourcePath).getFile(path);
+ if(member.exists()) {
+ return member;
+ }
+
+ }
+ return null;
+ }
+
@Override
protected void doHyperlink(IRegion region) {
IFile file = getReadyToOpenFile();