Author: mareshkau
Date: 2009-11-23 13:23:29 -0500 (Mon, 23 Nov 2009)
New Revision: 18790
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/FaceletSourceTagHyperlink.java
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE4509Test.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4635
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/FaceletSourceTagHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/FaceletSourceTagHyperlink.java 2009-11-23
17:43:57 UTC (rev 18789)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/FaceletSourceTagHyperlink.java 2009-11-23
18:23:29 UTC (rev 18790)
@@ -10,14 +10,30 @@
******************************************************************************/
package org.jboss.tools.common.text.ext.hyperlink.xml;
+import java.util.zip.ZipEntry;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IStorage;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.JarEntryFile;
+import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.jdt.internal.ui.javaeditor.JarEntryEditorInput;
import org.eclipse.jface.text.IRegion;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
+import org.jboss.tools.common.text.ext.ExtensionsPlugin;
import org.jboss.tools.common.text.ext.hyperlink.LinkHyperlink;
+
/**
* @author mareshkau
*
@@ -48,9 +64,86 @@
openFileFailed();
}
}
- } else {
- super.doHyperlink(region);
+ return;
+ }
+ else if(editorPart.getEditorInput() instanceof IStorageEditorInput) {
+ IStorageEditorInput modelObjectStorageEditorInput =
+ (IStorageEditorInput) editorPart.getEditorInput();
+ try {
+
+ IStorage storage = modelObjectStorageEditorInput.getStorage();
+ if(storage!=null && getFilePath(region)!=null) {
+ if(openOnFromModelEditorIntup(storage.getFullPath(), getFilePath(region))){
+ return;
+ }
+ }
+ } catch (CoreException e) {
+ ExtensionsPlugin.getDefault().logError(e);
+ }
+ }
+ super.doHyperlink(region);
+ }
+ /**
+ *
+ * @param xmodelPaht it's path to file in jar archive on which we are trying to make
open on
+ * Example 'JBIDE3247/FileSystems/lib-mydomain.jar/META-INF/custom.taglib.xml'
+ * @param fileToOpen jar archive relative name for which we are trying to make open on
+ * Example '/inputCurrency.xhtml's
+ */
+ private boolean openOnFromModelEditorIntup(IPath xmodelPath, String fileToOpen) {
+ if(xmodelPath==null || fileToOpen==null) {
+ return false;
}
+ String projectName = xmodelPath.segment(0);
+ IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
+ JarEntryEditorInput editorInputToOpenEditor=seachResourceInClassPath(project,new
Path(fileToOpen.substring(1)),xmodelPath);
+ if(editorInputToOpenEditor==null) {
+ return false;
+ }
+ IEditorPart openedEditor = openFileInEditor(editorInputToOpenEditor,
+ editorInputToOpenEditor.getName());
+ if(openedEditor==null) {
+ openFileFailed();
+ return false;
+ }
+ return true;
}
-
+ /**
+ *
+ * @param project project from which we are going to open File
+ * @param classPathResource resource relativy to class path
+ * @param xmodelPath xmodel path to file
+ * @return
+ */
+ private static JarEntryEditorInput seachResourceInClassPath(IProject project, IPath
classPathResource, IPath xmodelPath) {
+ IJavaProject javaProject = JavaCore.create(project);
+ try {
+ for (IPackageFragmentRoot fragmentRoot : javaProject.getAllPackageFragmentRoots()) {
+ if(fragmentRoot instanceof JarPackageFragmentRoot) {
+ JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot)
fragmentRoot;
+ ZipEntry zipEntry =
jarPackageFragmentRoot.getJar().getEntry(classPathResource.toString());
+ //the name of jar file shoul be in xmodel path
+ //for now if model have following
+ if(zipEntry!=null&&xmodelPath.toString().contains(fragmentRoot.getElementName())){
+ JarEntryFile fileInJar = new
JarEntryFile(classPathResource.lastSegment());
+ Object parent = null;
+ String parentName =classPathResource.removeLastSegments(1).toString();
+ if(parentName.length()==0) {
+ parent = jarPackageFragmentRoot;
+ }else{
+ parent =
jarPackageFragmentRoot.getPackageFragment(classPathResource.removeLastSegments(1).toString());
+ }
+ fileInJar.setParent(parent);
+ JarEntryEditorInput jarEditorInput = new JarEntryEditorInput(fileInJar);
+ return jarEditorInput;
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ ExtensionsPlugin.getDefault().logError(e);
+ } catch (CoreException e) {
+ ExtensionsPlugin.getDefault().logError(e);
+ }
+ return null;
+ }
}
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE4509Test.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE4509Test.java 2009-11-23
17:43:57 UTC (rev 18789)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/jbide/JBIDE4509Test.java 2009-11-23
18:23:29 UTC (rev 18790)
@@ -36,8 +36,10 @@
import org.eclipse.ui.part.MultiPageEditorPart;
import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.wst.sse.ui.StructuredTextEditor;
+import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
import org.jboss.tools.jsf.vpe.jsf.test.JsfAllTests;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
import org.jboss.tools.vpe.ui.test.TestUtil;
import org.jboss.tools.vpe.ui.test.VpeTest;
@@ -96,6 +98,17 @@
IEditorInput editorInput = new FileEditorInput(file);
JBIDE4509Test.checkOpenOnInEditor(editorInput, getEditorId(file.getName()), 22, 23,
"IfHandler.java"); //$NON-NLS-1$
}
+ //test for
https://jira.jboss.org/jira/browse/JBIDE-4635
+ public void testJBIDE4635OpenOn() throws Throwable{
+ IProject project =
ResourcesPlugin.getWorkspace().getRoot().getProject(JsfAllTests.IMPORT_JBIDE3247_PROJECT_NAME);
+ IFile file = (IFile) project.findMember("WebContent/pages/index.xhtml");
//$NON-NLS-1$
+ IEditorInput editorInput = new FileEditorInput(file);
+ JBIDE4509Test.checkOpenOnInEditor(editorInput, getEditorId(file.getName()), 11, 11,
"mareshkau.taglib.xml"); //$NON-NLS-1$
+ IEditorPart activeEditor = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ JBIDE4509Test.checkOpenOnInEditor(activeEditor.getEditorInput(),getEditorId(activeEditor.getEditorInput().getName()),
+ 8,23,"echo.xhtml"); //$NON-NLS-1$
+ }
/**
* Function for checking openOn functionality in jar file;
*
@@ -138,12 +151,21 @@
* @author mareshkau
*/
private static final void checkOpenOnInEditor(IEditorInput editorInput,String
editorId,int lineNumber, int lineOffset, String openedOnFileName) throws Throwable {
- MultiPageEditorPart editorPart = (MultiPageEditorPart) PlatformUI
+ IEditorPart editorPart = PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.openEditor(editorInput, editorId);
- IEditorPart[] editorParts = editorPart.findEditors(editorInput);
- editorPart.setActiveEditor(editorParts[0]);
- StructuredTextEditor textEditor = (StructuredTextEditor) editorParts[0];
+ StructuredTextEditor textEditor = null;
+ if(editorPart instanceof MultiPageEditorPart){
+ IEditorPart[] editorParts =
((MultiPageEditorPart)editorPart).findEditors(editorInput);
+ ((MultiPageEditorPart)editorPart).setActiveEditor(editorParts[0]);
+ textEditor = (StructuredTextEditor) editorParts[0];
+ } else if(editorPart instanceof JSPMultiPageEditor) {
+ textEditor = ((JSPMultiPageEditor)editorPart).getSourceEditor();
+ } else if(editorPart instanceof EditorPartWrapper) {
+ IEditorPart[] editorParts =
((MultiPageEditorPart)((EditorPartWrapper)editorPart).getEditor()).findEditors(editorInput);
+ ((MultiPageEditorPart)((EditorPartWrapper)editorPart).getEditor()).setActiveEditor(editorParts[1]);
+ textEditor = (StructuredTextEditor) editorParts[1];
+ }
int openOnPosition = TestUtil.getLinePositionOffcet(textEditor
.getTextViewer(),lineNumber, lineOffset);
// hack to get hyperlinks detectors, no other was have been founded
@@ -172,6 +194,7 @@
}
+
private static final String getEditorId(String filename) {
IWorkbench workbench = PlatformUI.getWorkbench();
IEditorRegistry editorRegistry = workbench.getEditorRegistry();