Author: dmaliarevich
Date: 2011-03-23 14:46:48 -0400 (Wed, 23 Mar 2011)
New Revision: 29980
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsWizard.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizard.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardRegisterBundlePage.java
Log:
https://issues.jboss.org/browse/JBIDE-7004 , registering bundle functionality was added.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsWizard.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsWizard.java 2011-03-23
17:14:09 UTC (rev 29979)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeAllStringsWizard.java 2011-03-23
18:46:48 UTC (rev 29980)
@@ -18,9 +18,12 @@
import java.util.Properties;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.bundle.BundleMap;
import org.jboss.tools.jst.jsp.bundle.BundleMap.BundleEntry;
@@ -49,9 +52,9 @@
@Override
public void addPages() {
super.addPages();
- page1 = new
ExternalizeAllStringsSelectBundlePage("ExternalizeAllStringsSelectBundlePage");
- page2 = new
ExternalizeAllStringsKeysListPage("ExternalizeAllStringsKeysListPage");
- page3 = new
ExternalizeStringsWizardRegisterBundlePage("ExternalizeStringsWizardRegisterBundlePage");
+ page1 = new
ExternalizeAllStringsSelectBundlePage("ExternalizeAllStringsSelectBundlePage");
//$NON-NLS-1$
+ page2 = new
ExternalizeAllStringsKeysListPage("ExternalizeAllStringsKeysListPage");
//$NON-NLS-1$
+ page3 = new
ExternalizeStringsWizardRegisterBundlePage("ExternalizeStringsWizardRegisterBundlePage");
//$NON-NLS-1$
/*
* Add all the pages to the wizard
*/
@@ -75,7 +78,8 @@
* Exit when the file is null
*/
if (bundleFile == null) {
- JspEditorPlugin.getDefault().logError("Cannot externalize all string, because
bundle file is not found");
+ JspEditorPlugin.getDefault().logError(
+ "Cannot externalize all string, because bundle file is not found");
//$NON-NLS-1$
return false;
}
if (bundleFile.exists()) {
@@ -88,19 +92,95 @@
JspEditorPlugin.getDefault().logError(e);
}
if (out.checkError()) {
- JspEditorPlugin.getDefault().logError("Error while writing to the properties
file");
+ JspEditorPlugin.getDefault().logError(
+ "Error while writing to the properties file"); //$NON-NLS-1$
}
out.close();
out = null;
}
- page2.replaceAllStrings(findBundlePrefix());
+ String bundleName = page3.getBundleName();
+ String bundlePrefix = findBundlePrefix();
+ /*
+ * When no registered bundles found for entered properties file
+ * the wizard will generate its own bundler prefix and path.
+ */
+ if (Constants.EMPTY.equalsIgnoreCase(bundlePrefix)) {
+ /*
+ * In such a case there was no matching bundle prefix in the bundle map
+ * and user has entered its own bundle prefix.
+ * Thus this new name should be registered on the page depending on the
+ * choice where to register the bundle.
+ * Otherwise already found prefix is used without any additional registration.
+ */
+ String bundlePath;
+ String var;
+ /*
+ * Get the source folders for the project
+ */
+ String userDefinedPath = bundleFile.getAbsolutePath().replaceAll("\\\\",
"/"); //$NON-NLS-1$ //$NON-NLS-2$
+ String srcPath = userDefinedPath;
+ IResource[] src =
EclipseUtil.getJavaSourceRoots(ExternalizeStringsUtils.getProject(editor));
+ if (src != null) {
+ if (src.length > 1) {
+ for (IResource res : src) {
+ srcPath = res.getFullPath().toString();
+ if (userDefinedPath.indexOf(srcPath) > -1) {
+ break;
+ }
+ }
+ } else if (src.length == 1) {
+ srcPath = src[0].getFullPath().toString();
+ }
+ }
+ /*
+ * After the source folder has been found --
+ * generate the bundle path.
+ */
+ int srcPathIndex = userDefinedPath.indexOf(srcPath);
+ if (srcPathIndex > -1) {
+ /*
+ * User has selected the folder in the projects's source path.
+ * Replace the beginning
+ */
+ bundlePath = userDefinedPath.substring(srcPathIndex + srcPath.length() +
1).replaceAll("/", "\\."); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ /*
+ * User defined path is different from the source folder.
+ * Thus base-name would be incorrect.
+ */
+ bundlePath = userDefinedPath;
+ }
+ int pos = bundlePath.indexOf(Constants.PROPERTIES_EXTENTION);
+ if (pos > -1) {
+ bundlePath = bundlePath.substring(0, pos);
+ }
+
+ if (!Constants.EMPTY.equalsIgnoreCase(bundleName)) {
+ /*
+ * Get the name from the last page
+ */
+ var = bundleName;
+ } else {
+ /*
+ * var = file name from page1
+ */
+ var = bundlePath.substring(bundlePath.lastIndexOf("/") + 1); //$NON-NLS-1$
+ bundleName = var;
+ }
+ if (page3.isInFacesConfig()) {
+ ExternalizeStringsUtils.registerInFacesConfig(editor, bundlePath, var);
+ } else if (page3.isViaLoadBundle()) {
+ ExternalizeStringsUtils.registerViaLoadBundle(editor, bundlePath, var);
+ }
+ }
+ page2.replaceAllStrings(bundleName);
return true;
}
public String findBundlePrefix() {
String bundlePrefix = Constants.EMPTY;
if (page1.getBundleFile() != null) {
- String ap = page1.getBundleFile().getAbsolutePath();
+ String ap = getUserDefinedFile().getAbsolutePath();
for (BundleEntry be : bm.getBundles()) {
IFile bf = bm.getBundleFile(be.uri);
if (ap.equalsIgnoreCase(bf.getLocation().toOSString())) {
@@ -124,4 +204,10 @@
public void setPage3BundleName() {
page3.setBundleName(findBundlePrefix());
}
+ protected IProject getProject() {
+ return ExternalizeStringsUtils.getProject(editor);
+ }
+ protected File getUserDefinedFile() {
+ return page1.getBundleFile();
+ }
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java 2011-03-23
17:14:09 UTC (rev 29979)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsUtils.java 2011-03-23
18:46:48 UTC (rev 29980)
@@ -30,6 +30,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ColumnLayoutData;
import org.eclipse.jface.viewers.ColumnWeightData;
@@ -47,20 +48,33 @@
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.eclipse.wst.sse.ui.internal.provisional.extensions.ISourceEditingTextTools;
+import org.eclipse.wst.xml.core.internal.document.AttrImpl;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.eclipse.wst.xml.ui.internal.provisional.IDOMSourceEditingTextTools;
+import org.jboss.tools.common.meta.action.XActionInvoker;
+import org.jboss.tools.common.meta.action.impl.handlers.DefaultCreateHandler;
import org.jboss.tools.common.model.XModel;
+import org.jboss.tools.common.model.XModelException;
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.project.IModelNature;
+import org.jboss.tools.common.model.ui.editors.dnd.DropURI;
+import org.jboss.tools.common.model.ui.views.palette.PaletteInsertHelper;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.model.util.ModelFeatureFactory;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jst.jsp.JspEditorPlugin;
import org.jboss.tools.jst.jsp.bundle.BundleMap;
import org.jboss.tools.jst.jsp.editor.IVisualContext;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
import org.jboss.tools.jst.jsp.jspeditor.SourceEditorPageContext;
+import org.jboss.tools.jst.jsp.jspeditor.dnd.JSPPaletteInsertHelper;
+import org.jboss.tools.jst.jsp.jspeditor.dnd.PaletteTaglibInserter;
import org.jboss.tools.jst.jsp.messages.JstUIMessages;
import org.jboss.tools.jst.jsp.util.Constants;
import org.jboss.tools.jst.jsp.util.FaceletsUtil;
@@ -68,8 +82,10 @@
import org.jboss.tools.jst.web.project.list.IWebPromptingProvider;
import org.jboss.tools.jst.web.project.list.WebPromptingProvider;
import org.jboss.tools.jst.web.tld.TaglibData;
+import org.jboss.tools.jst.web.tld.URIConstants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
@@ -414,4 +430,159 @@
*/
return result;
}
+
+ public static void registerInFacesConfig(ITextEditor editor, String bundlePath, String
var) {
+ /*
+ * Register new bundle in the faces-config.xml
+ * We should write only correct base-name.
+ * If it is not -- then just skip it. But such a situation
+ * should never happen.
+ */
+ IProject project = getProject(editor);
+ if (project != null) {
+ XModel model = EclipseResourceUtil.getModelNature(project).getModel();
+ XModelObject facesConfig = ExternalizeStringsUtils.findFacesConfig(model);
+ XModelObject application = facesConfig.getChildByPath("application");
//$NON-NLS-1$
+ XModelObject resourceBundle =
facesConfig.getModel().createModelObject("JSFResourceBundle", null);
//$NON-NLS-1$
+ resourceBundle.setAttributeValue("base-name", bundlePath); //$NON-NLS-1$
+ resourceBundle.setAttributeValue("var", var); //$NON-NLS-1$
+ try {
+ DefaultCreateHandler.addCreatedObject(application, resourceBundle, 0);
+ } catch (XModelException e) {
+ JspEditorPlugin.getDefault().logError(
+ "Could not add <resource-bundle> to the faces-config.xml", e);
//$NON-NLS-1$
+ }
+ /*
+ * When the faces-config.xml is opened in the editor the following
+ * action should be called to ensure that changes have been applied.
+ */
+ XActionInvoker.invoke("SaveActions.Save", facesConfig, new Properties());
//$NON-NLS-1$
+ }
+ }
+
+
+ public static void registerViaLoadBundle(ITextEditor editor, String bundlePath, String
var) {
+ /*
+ * Add <f:loadBundle> tag to the current page.
+ * Insert the tag inside <f:view> or <html>.
+ */
+ String jsfCoreTaglibPrefix = registerMessageTaglib(editor);
+ IStructuredModel model = null;
+ IModelManager manager = StructuredModelManager.getModelManager();
+ if (manager != null) {
+ try {
+ model = manager.getModelForEdit(getFile(editor));
+ } catch (IOException e) {
+ JspEditorPlugin.getDefault().logError(e);
+ } catch (CoreException e) {
+ JspEditorPlugin.getDefault().logError(e);
+ }
+ if (model instanceof IDOMModel) {
+ IDOMModel domModel = (IDOMModel) model;
+ IDOMDocument document = domModel.getDocument();
+ NodeList viewList = document.getElementsByTagName(jsfCoreTaglibPrefix +
":view"); //$NON-NLS-1$
+ NodeList subviewList = document.getElementsByTagName(jsfCoreTaglibPrefix +
":subview"); //$NON-NLS-1$
+ NodeList htmlList = document.getElementsByTagName("html"); //$NON-NLS-1$
+ IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ Node node = null;
+ if (viewList.getLength() > 0) {
+ /*
+ * Add loadBundle right after f:view declaration
+ */
+ node = viewList.item(0);
+ } else if (subviewList.getLength() > 0) {
+ /*
+ * There is no f:view, may be f:subwiew
+ */
+ node = subviewList.item(0);
+ } else {
+ /*
+ * Register at least somewhere
+ */
+ node = htmlList.item(0);
+ }
+ if (node != null) {
+ /*
+ * Create f:loadBundle element
+ */
+ Document srcDoc = node.getOwnerDocument();
+ Element loadBundle = srcDoc.createElement(
+ jsfCoreTaglibPrefix + Constants.COLON + "loadBundle"); //$NON-NLS-1$
+ loadBundle.setAttribute("var", var); //$NON-NLS-1$
+ loadBundle.setAttribute("basename", bundlePath); //$NON-NLS-1$
+ Node firstChild = node.getFirstChild();
+ if (firstChild != null) {
+ firstChild.insertBefore(loadBundle, node);
+ }
+ }
+ }
+ } else {
+ JspEditorPlugin.getDefault().logWarning(
+ JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_CANNOT_ADD_LOAD_BUNDLE_TAG);
+ }
+ }
+
+ /**
+ * Register Message Taglibs on page
+ */
+ public static String registerMessageTaglib(ITextEditor editor) {
+ List<TaglibData> taglibs = null;
+ String jsfCoreTaglibPrefix = "f"; //$NON-NLS-1$
+ if (editor instanceof JSPMultiPageEditor) {
+ StructuredTextEditor ed = ((JSPMultiPageEditor) editor).getSourceEditor();
+ if (ed instanceof JSPTextEditor) {
+ IVisualContext context = ((JSPTextEditor) ed).getPageContext();
+ if (context instanceof SourceEditorPageContext) {
+ SourceEditorPageContext sourcePageContext = (SourceEditorPageContext) context;
+ taglibs = sourcePageContext.getTagLibs();
+ if (null == taglibs) {
+ JspEditorPlugin.getDefault().logError(
+ JstUIMessages.CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT);
+ } else {
+ boolean isJsfCoreTaglibRegistered = false;
+ for (TaglibData tl : taglibs) {
+ if (DropURI.JSF_CORE_URI.equalsIgnoreCase(tl.getUri())) {
+ isJsfCoreTaglibRegistered = true;
+ jsfCoreTaglibPrefix = tl.getPrefix();
+ break;
+ }
+ }
+ if (!isJsfCoreTaglibRegistered) {
+ /*
+ * Register the required taglib
+ */
+ PaletteTaglibInserter PaletteTaglibInserter = new PaletteTaglibInserter();
+ Properties p = new Properties();
+ p.put("selectionProvider", editor.getSelectionProvider());
//$NON-NLS-1$
+ p.setProperty(URIConstants.LIBRARY_URI, DropURI.JSF_CORE_URI);
+ p.setProperty(URIConstants.LIBRARY_VERSION, ""); //$NON-NLS-1$
+ p.setProperty(URIConstants.DEFAULT_PREFIX, jsfCoreTaglibPrefix);
+ p.setProperty(JSPPaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, "true");
//$NON-NLS-1$
+ p.setProperty(JSPPaletteInsertHelper.PROPOPERTY_REFORMAT_BODY, "yes");
//$NON-NLS-1$
+ p.setProperty(PaletteInsertHelper.PROPOPERTY_START_TEXT,
+ "<%@ taglib
uri=\"http://java.sun.com/jsf/core\"
prefix=\"f\" %>\\n"); //$NON-NLS-1$
+ PaletteTaglibInserter.inserTaglib(ed.getTextViewer().getDocument(), p);
+ }
+ }
+ }
+ }
+ }
+ return jsfCoreTaglibPrefix;
+ }
+
+ public static IFile getFile(ITextEditor editor) {
+ if (editor.getEditorInput() instanceof IFileEditorInput) {
+ return ((IFileEditorInput)editor.getEditorInput()).getFile();
+ }
+ return null;
+ }
+
+ public static IProject getProject(ITextEditor editor) {
+ IFile file = getFile(editor);
+ if (file != null) {
+ return file.getProject();
+ }
+ return null;
+ }
+
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizard.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizard.java 2011-03-23
17:14:09 UTC (rev 29979)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizard.java 2011-03-23
18:46:48 UTC (rev 29980)
@@ -195,9 +195,9 @@
*/
if (page1.isNewFile() && !page3.isUserDefined()) {
var = page3.getBundleName();
- if (getProject()!=null) {
- IProject project = getProject();
- String userDefinedPath = page2.getContainerFullPath().toString();
+ IProject project = ExternalizeStringsUtils.getProject(editor);
+ if (project != null) {
+ String userDefinedPath = getUserDefinedPath().toString();
/*
* Get the source folders for the project
*/
@@ -286,8 +286,10 @@
Object selectedElement = structuredSelection.getFirstElement();
if (selectedElement instanceof Node) {
Node node = (Node) selectedElement;
- registerMessageTaglib();
- String jsfCoreTaglibPrefix = "f"; //$NON-NLS-1$
+ String jsfCoreTaglibPrefix =
ExternalizeStringsUtils.registerMessageTaglib(editor);
+ /*
+ * Create f:loadBundle element
+ */
Element loadBundle = node.getOwnerDocument().createElement(
jsfCoreTaglibPrefix + Constants.COLON + "loadBundle"); //$NON-NLS-1$
loadBundle.setAttribute("var", var); //$NON-NLS-1$
@@ -323,53 +325,6 @@
page1.replaceText(replacement);
return true;
}
- /**
- * Register Message Taglibs on page
- */
- protected void registerMessageTaglib(){
- List<TaglibData> taglibs = null;
- String jsfCoreTaglibPrefix = "f"; //$NON-NLS-1$
- if (editor instanceof JSPMultiPageEditor) {
- StructuredTextEditor ed = ((JSPMultiPageEditor) editor).getSourceEditor();
- if (ed instanceof JSPTextEditor) {
- IVisualContext context = ((JSPTextEditor) ed).getPageContext();
- if (context instanceof SourceEditorPageContext) {
- SourceEditorPageContext sourcePageContext = (SourceEditorPageContext) context;
- taglibs = sourcePageContext.getTagLibs();
- if (null == taglibs) {
- JspEditorPlugin.getDefault().logError(
- JstUIMessages.CANNOT_LOAD_TAGLIBS_FROM_PAGE_CONTEXT);
- } else {
- boolean isJsfCoreTaglibRegistered = false;
- for (TaglibData tl : taglibs) {
- if (DropURI.JSF_CORE_URI.equalsIgnoreCase(tl.getUri())) {
- isJsfCoreTaglibRegistered = true;
- jsfCoreTaglibPrefix = tl.getPrefix();
- break;
- }
- }
- if (!isJsfCoreTaglibRegistered) {
- /*
- * Register the required taglib
- */
- PaletteTaglibInserter PaletteTaglibInserter = new PaletteTaglibInserter();
- Properties p = new Properties();
- p.put("selectionProvider", getSelectionProvider()); //$NON-NLS-1$
- p.setProperty(URIConstants.LIBRARY_URI, DropURI.JSF_CORE_URI);
- p.setProperty(URIConstants.LIBRARY_VERSION, ""); //$NON-NLS-1$
- p.setProperty(URIConstants.DEFAULT_PREFIX, jsfCoreTaglibPrefix);
- p.setProperty(JSPPaletteInsertHelper.PROPOPERTY_ADD_TAGLIB, "true");
//$NON-NLS-1$
- p.setProperty(JSPPaletteInsertHelper.PROPOPERTY_REFORMAT_BODY, "yes");
//$NON-NLS-1$
- p.setProperty(PaletteInsertHelper.PROPOPERTY_START_TEXT,
- "<%@ taglib
uri=\"http://java.sun.com/jsf/core\"
prefix=\"f\" %>\\n"); //$NON-NLS-1$
- PaletteTaglibInserter.inserTaglib(ed.getTextViewer().getDocument(), p);
- }
- }
- }
- }
- }
-
- }
private IDocument getDocument(){
IDocumentProvider prov = editor.getDocumentProvider();
@@ -385,8 +340,8 @@
*/
private IPath getContainerFullPath(){
IPath containerFullPath = null;
- if (editor.getEditorInput() instanceof IFileEditorInput) {
- IProject project =
((IFileEditorInput)editor.getEditorInput()).getFile().getProject();
+ IProject project = ExternalizeStringsUtils.getProject(editor);
+ if (project != null) {
IResource[] src = EclipseUtil.getJavaSourceRoots(project);
if (src.length > 0) {
containerFullPath = src[0].getFullPath();
@@ -401,15 +356,14 @@
return containerFullPath;
}
- protected String getFileName(){
- return editor.getEditorInput().getName();
+ protected IPath getUserDefinedPath() {
+ return page2.getContainerFullPath();
}
- protected IProject getProject(){
- IProject project = null;
- if (editor.getEditorInput() instanceof IFileEditorInput) {
- project = ((IFileEditorInput)editor.getEditorInput()).getFile().getProject();
- }
- return project;
+ protected String getFileName() {
+ return editor.getEditorInput().getName();
}
+ protected IProject getProject() {
+ return ExternalizeStringsUtils.getProject(editor);
+ }
}
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardRegisterBundlePage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardRegisterBundlePage.java 2011-03-23
17:14:09 UTC (rev 29979)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardRegisterBundlePage.java 2011-03-23
18:46:48 UTC (rev 29980)
@@ -52,6 +52,7 @@
private Button userDefined;
private Label bundleLabel;
private Text bundleName;
+ private Group group;
/**
* Instantiates a new externalize strings wizard register bundle page.
@@ -101,7 +102,7 @@
/*
* Group with a place for bundle
*/
- Group group = new Group(composite, SWT.SHADOW_ETCHED_IN);
+ group = new Group(composite, SWT.SHADOW_ETCHED_IN);
group.setLayout(new GridLayout(1, true));
group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
group.setText(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_SAVE_RESOURCE_BUNDLE);
@@ -205,12 +206,18 @@
* Update bundle name field.
*/
private void updateBundleNameField() {
- if (isUserDefined()) {
- bundleLabel.setEnabled(false);
- bundleName.setEnabled(false);
- } else {
- bundleLabel.setEnabled(true);
- bundleName.setEnabled(true);
+ /*
+ * While externalizing all strings - this update is unnecessary.
+ * It will be done in setBundleName() method.
+ */
+ if (getWizard() instanceof ExternalizeStringsWizard) {
+ if (isUserDefined()) {
+ bundleLabel.setEnabled(false);
+ bundleName.setEnabled(false);
+ } else {
+ bundleLabel.setEnabled(true);
+ bundleName.setEnabled(true);
+ }
}
}
@@ -221,31 +228,40 @@
*/
private boolean isSourceFolderSelected() {
boolean sourceFolderSelected = false;
+ IProject project = null;
+ String userDefinedPath = Constants.EMPTY;
if (getWizard() instanceof ExternalizeStringsWizard) {
- ExternalizeStringsWizard wiz = (ExternalizeStringsWizard) getWizard();
- if (wiz.getProject()!=null) {
- IProject project = wiz.getProject();
- WizardNewFileCreationPage page2 = (WizardNewFileCreationPage)wiz.getPage(
- ExternalizeStringsWizard.EXTERNALIZE_STRINGS_DIALOG_NEW_FILE_PAGE);
- String userDefinedPath = page2.getContainerFullPath().toString();
- /*
- * Get the source folders for the project
- */
- IResource[] src = EclipseUtil.getJavaSourceRoots(project);
- /*
- * When there are multiple source folders --
- * match user defined folder to them.
- */
- String srcPath = Constants.EMPTY;
- for (IResource res : src) {
- srcPath = res.getFullPath().toString();
- if (userDefinedPath.indexOf(srcPath) > -1) {
- sourceFolderSelected = true;
- break;
- }
- }
+ ExternalizeStringsWizard wiz = (ExternalizeStringsWizard) getWizard();
+ project = wiz.getProject();
+ if (project != null) {
+ userDefinedPath = wiz.getUserDefinedPath().toString();
}
+ } else if (getWizard() instanceof ExternalizeAllStringsWizard) {
+ ExternalizeAllStringsWizard wiz = (ExternalizeAllStringsWizard) getWizard();
+ project = wiz.getProject();
+ if (project != null) {
+ userDefinedPath = wiz.getUserDefinedFile().getAbsolutePath().toString();
+ }
}
+ if ((project != null)
+ && !Constants.EMPTY.equalsIgnoreCase(userDefinedPath)) {
+ /*
+ * Get the source folders for the project
+ */
+ IResource[] src = EclipseUtil.getJavaSourceRoots(project);
+ /*
+ * When there are multiple source folders --
+ * match user defined folder to them.
+ */
+ String srcPath = Constants.EMPTY;
+ for (IResource res : src) {
+ srcPath = res.getFullPath().toString();
+ if (userDefinedPath.indexOf(srcPath) > -1) {
+ sourceFolderSelected = true;
+ break;
+ }
+ }
+ }
return sourceFolderSelected;
}
@@ -272,8 +288,17 @@
public void setBundleName(String bn) {
if (bundleName != null) {
- bundleName.setText(bn);
+ if (!Constants.EMPTY.equalsIgnoreCase(bn)) {
+ bundleName.setText(bn);
+ bundleName.setEditable(false);
+ bundleLabel.setEnabled(false);
+ group.setEnabled(false);
+ } else {
+ bundleName.setText(Constants.EMPTY);
+ bundleName.setEditable(true);
+ bundleLabel.setEnabled(true);
+ group.setEnabled(true);
+ }
}
}
-
}