Author: vrubezhny
Date: 2008-06-26 14:09:01 -0400 (Thu, 26 Jun 2008)
New Revision: 8958
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/BundleBasenameHyperlink.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-2389 It's impossible go to the message bundle
by OpenOn
Issue is fixed
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/BundleBasenameHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/BundleBasenameHyperlink.java 2008-06-26
15:44:55 UTC (rev 8957)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/BundleBasenameHyperlink.java 2008-06-26
18:09:01 UTC (rev 8958)
@@ -10,6 +10,9 @@
******************************************************************************/
package org.jboss.tools.jsf.text.ext.hyperlink;
+import java.util.ArrayList;
+import java.util.HashSet;
+
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
@@ -20,16 +23,22 @@
import org.eclipse.jface.text.IRegion;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.ide.IDE;
+import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.model.util.XModelObjectLoaderUtil;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
+import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.jsf.model.pv.JSFProjectsRoot;
+import org.jboss.tools.jsf.model.pv.JSFProjectsTree;
+import org.jboss.tools.jsf.text.ext.JSFExtensionsPlugin;
+import org.jboss.tools.jst.web.model.pv.WebProjectNode;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.Text;
-import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
-import org.jboss.tools.jsf.text.ext.JSFExtensionsPlugin;
-import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
-import org.jboss.tools.common.text.ext.util.Utils;
-
/**
* @author Jeremy
*/
@@ -39,8 +48,11 @@
try {
String fileName = getBundleBasename(region);
IFile fileToOpen = getFileToOpen(fileName, "properties");
- IWorkbenchPage workbenchPage =
JSFExtensionsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
- IDE.openEditor(workbenchPage,fileToOpen,true);
+ if (fileToOpen != null) {
+ IWorkbenchPage workbenchPage =
JSFExtensionsPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ IDE.openEditor(workbenchPage,fileToOpen,true);
+ } else
+ openFileFailed();
} catch (CoreException x) {
// could not open editor
openFileFailed();
@@ -57,10 +69,185 @@
}
}
+ private String[] getBundles() {
+ XModelObject fcObject = EclipseResourceUtil.createObjectForResource(getFile());
+ if (fcObject == null)
+ return null;
+
+ XModel fcObjectModel = fcObject.getModel();
+ if (fcObjectModel == null)
+ return null;
+
+ JSFProjectsRoot jsfProjectsRoot = JSFProjectsTree.getProjectsRoot(fcObjectModel);
+ if (jsfProjectsRoot == null)
+ return null;
+
+ XModelObject rbObjects = jsfProjectsRoot.getChildByPath("Resource Bundles");
+ if (!(rbObjects instanceof WebProjectNode))
+ return null;
+
+ ((WebProjectNode)rbObjects).invalidate();
+
+ ArrayList<String> bundlesPaths = new ArrayList<String>();
+ XModelObject[] bundles = ((WebProjectNode)rbObjects).getTreeChildren();
+ for (int i = 0; bundles != null && i < bundles.length; i++) {
+ String res = XModelObjectLoaderUtil.getResourcePath(bundles[i]);
+ if (res != null) {
+ res = res.substring(1, res.length() - 11).replace('/', '.');
+ bundlesPaths.add(res);
+ }
+ }
+
+ return (bundlesPaths.size() == 0 ?
+ null : bundlesPaths.toArray(new String[0]));
+ }
+
+ private String[] getOrderedLocales() {
+ HashSet<String> allLocales = new HashSet<String>();
+ ArrayList<String> supportedLocales = new ArrayList<String>();
+ ArrayList<String> langs = new ArrayList<String>();
+
+ XModelObject fcObject = EclipseResourceUtil.createObjectForResource(getFile());
+ if (fcObject == null)
+ return null;
+
+ XModelObject lcObject = (fcObject != null ?
+ fcObject.getChildByPath("application/Locale Config") : null);
+
+ String defLocale = (lcObject != null ?
+ lcObject.getAttributeValue("default-locale") : null);
+ if (defLocale != null && defLocale.trim().length() > 0) {
+ String locale = defLocale.trim().replace('-', '_');
+ if (!allLocales.contains(locale)) {
+ allLocales.add(locale);
+ supportedLocales.add(locale); // Add locale in form <lang>_<country>
+ }
+
+ if (locale.indexOf('_') != -1) {
+ locale = locale.replace('_', '-');
+ if (!allLocales.contains(locale)) {
+ allLocales.add(locale);
+ supportedLocales.add(locale); // Add locale in form <lang>-<country>
+ }
+
+ locale = locale.substring(0, locale.indexOf('-'));
+ if (!allLocales.contains(locale)) {
+ allLocales.add(locale);
+ supportedLocales.add(locale); // Add locale in form <lang>
+ }
+ }
+ }
+
+ java.util.Locale defJavaLocale = java.util.Locale.getDefault();
+ if (defJavaLocale != null) {
+ if (defJavaLocale.getLanguage() != null &&
defJavaLocale.getLanguage().length() > 0) {
+ if (defJavaLocale.getCountry() != null && defJavaLocale.getCountry().length()
> 0) {
+
+ // Add locale in form <lang>_<country>
+ String locale = defJavaLocale.getLanguage() + '_' +
defJavaLocale.getCountry();
+ if (!allLocales.contains(locale)) {
+ allLocales.add(locale);
+ supportedLocales.add(locale);
+ }
+ // Add locale in form <lang>-<country>
+ locale = defJavaLocale.getLanguage() + '-' + defJavaLocale.getCountry();
+ if (!allLocales.contains(locale)) {
+ allLocales.add(locale);
+ supportedLocales.add(locale);
+ }
+ }
+
+ String locale = defJavaLocale.getLanguage();
+ if (!allLocales.contains(locale)) {
+ allLocales.add(locale);
+ langs.add(locale); // Add locale in form <lang> to the langs
+ }
+ }
+ }
+
+ XModelObject[] lcChildren = (lcObject != null ?
+ lcObject.getChildren() : null);
+
+ for (int i = 0; lcChildren != null && i < lcChildren.length; i++) {
+ String supLocale = lcChildren[i].getAttributeValue("supported-locale");
+ if (supLocale != null && supLocale.trim().length() > 0) {
+ String locale = supLocale.trim().replace('-', '_');
+
+ if (!allLocales.contains(locale)) {
+ allLocales.add(locale);
+ supportedLocales.add(locale); // Add locale in form <lang>_<country>
+ }
+
+ if (locale.indexOf('_') != -1) {
+ locale = locale.replace('_', '-');
+ if (!allLocales.contains(locale)) {
+ allLocales.add(locale);
+ supportedLocales.add(locale); // Add locale in form <lang>-<country>
+ }
+
+ locale = locale.substring(0, locale.indexOf('-'));
+ if (!allLocales.contains(locale)) {
+ allLocales.add(locale);
+ langs.add(locale); // Add locale in form <lang> to the langs
+ }
+ }
+ }
+ }
+
+ // Add all the collected locales in form <lang> and an empty locale
+ supportedLocales.addAll(langs);
+ supportedLocales.add("");
+ return supportedLocales.toArray(new String[0]);
+ }
+
private IFile getFileToOpen(String fileName, String fileExt) {
+ if (fileName == null)
+ return null;
+
+ String[] orderedLocales = getOrderedLocales();
+ String[] bundles = getBundles();
+
+ for (int l = 0; orderedLocales != null && l < orderedLocales.length; l++) {
+ String name = fileName + (orderedLocales[l].length() == 0 ? "" :
+ "_" + orderedLocales[l]);
+
+ for (int i = 0; bundles != null && i < bundles.length; i++) {
+ if (bundles[i].equals(name)) {
+ IFile file = findFile(name.replace('.','/')+
+ (fileExt != null ? "." + fileExt : ""));
+ if (file != null)
+ return file;
+ }
+ }
+ }
+ return null;
+ }
+
+ private IFile findFile(String name) {
IFile documentFile = getFile();
try {
IProject project = documentFile.getProject();
+
+ if(project == null || !project.isOpen()) return null;
+ if(!project.hasNature(JavaCore.NATURE_ID)) return null;
+ IJavaProject javaProject = JavaCore.create(project);
+ IClasspathEntry[] es = javaProject.getResolvedClasspath(true);
+ for (int i = 0; i < es.length; i++) {
+ if(es[i].getEntryKind() != IClasspathEntry.CPE_SOURCE) continue;
+ IFile file = (IFile)project.getFile(es[i].getPath().removeFirstSegments(1) +
"/" + name);
+ if(file != null && file.exists()) return file;
+ }
+ return null;
+ } catch (CoreException x) {
+ JSFExtensionsPlugin.log("", x);
+ return null;
+ }
+ }
+
+ private IFile getFileToOpenOld(String fileName, String fileExt) {
+ IFile documentFile = getFile();
+ try {
+ IProject project = documentFile.getProject();
String name = fileName.replace('.','/')+ (fileExt != null ?
"." + fileExt : "");