Author: yradtsevich
Date: 2009-08-19 09:32:30 -0400 (Wed, 19 Aug 2009)
New Revision: 17160
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreatorUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FileUtil.java
Log:
issue JBIDE-4416: Modify templates for ui:composition and ui:define
https://jira.jboss.org/jira/browse/JBIDE-4416
- part #2 has been fixed: now if the web-root folder is not found, it is assumed that the
root folder is the parent folder of the opened file.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreatorUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreatorUtil.java 2009-08-19
12:51:09 UTC (rev 17159)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreatorUtil.java 2009-08-19
13:32:30 UTC (rev 17160)
@@ -24,6 +24,7 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.VpeIncludeInfo;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.custom.VpeCustomStringStorage;
import org.jboss.tools.vpe.editor.util.FileUtil;
@@ -130,12 +131,14 @@
IEditorInput input = pageContext.getEditPart().getEditorInput();
IFile file = null;
- if(pageContext.getVisualBuilder().getCurrentIncludeInfo()==null
- || !(pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage() instanceof
IFile)) {
+ VpeIncludeInfo currentIncludeInfo
+ = pageContext.getVisualBuilder().getCurrentIncludeInfo();
+ if(currentIncludeInfo==null
+ || !(currentIncludeInfo.getStorage() instanceof IFile)) {
file = FileUtil.getFile(input, fileName);
} else {
IFile includedFile =
- (IFile) pageContext.getVisualBuilder().getCurrentIncludeInfo().getStorage();
+ (IFile) currentIncludeInfo.getStorage();
file = FileUtil.getFile(fileName, includedFile);
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FileUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FileUtil.java 2009-08-19
12:51:09 UTC (rev 17159)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/FileUtil.java 2009-08-19
13:32:30 UTC (rev 17160)
@@ -95,14 +95,18 @@
// .getWebArtifactEditForRead(includeFile.getProject());
IVirtualComponent com = ComponentCore
.createComponent(includeFile.getProject());
- if (com == null) {
- return null;
+ if (com != null) {
+ IVirtualFolder webRootFolder = com.getRootFolder().getFolder(
+ new Path("/")); //$NON-NLS-1$
+ IContainer folder = webRootFolder.getUnderlyingFolder();
+ IPath path = folder.getFullPath().append(fileName);
+ file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ } else {
+ /* Yahor Radtsevich (yradtsevich):
+ * Fix of JBIDE-4416: assume that the parent directory
+ * of the opened file is the web-root directory */
+ file = resolveRelatedPath(includeFile, fileName);
}
- IVirtualFolder webRootFolder = com.getRootFolder().getFolder(
- new Path("/")); //$NON-NLS-1$
- IContainer folder = webRootFolder.getUnderlyingFolder();
- IPath path = folder.getFullPath().append(fileName);
- file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
}
} else {
ResourceReference[] resources = RelativeFolderReferenceList
@@ -114,15 +118,24 @@
return ResourcesPlugin.getWorkspace().getRoot()
.getFileForLocation(path);
} else {
- IPath currentFolder = includeFile.getParent().getFullPath();
- IPath path = currentFolder.append(fileName);
- file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ file = resolveRelatedPath(includeFile, fileName);
}
}
return file;
}
-
+
/**
+ * Appends {@code relatedFilePath} to the parent directory of
+ * {@code baseFile}.
+ */
+ private static IFile resolveRelatedPath(IFile baseFile,
+ String relatedFilePath) {
+ IPath currentFolder = baseFile.getParent().getFullPath();
+ IPath path = currentFolder.append(relatedFilePath);
+ return ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ }
+
+ /**
* open editor
* @param file
*/