Author: dmaliarevich
Date: 2010-10-25 10:15:48 -0400 (Mon, 25 Oct 2010)
New Revision: 26031
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/ExternalizeStringsWizardPage.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/wizard/ExternalizeStringsDialogTest.java
Log:
https://jira.jboss.org/browse/JBIDE-7380 , Externalize String Dialog suggests to use
already defined key from the bundle is the same value has been already externalized. JUnit
was updated.
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 2010-10-25
13:27:36 UTC (rev 26030)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizard.java 2010-10-25
14:15:48 UTC (rev 26031)
@@ -98,39 +98,41 @@
@Override
public boolean performFinish() {
- IFile bundleFile = null;
- if (page1.isNewFile()) {
- bundleFile = page2.createNewFile();
- } else {
- bundleFile = page1.getBundleFile();
- }
- /*
- * Exit when the file is null
- */
- if (bundleFile == null) {
- return false;
- }
- /*
- * Add "key=value" to the bundle file that is already exists.
- * When the file is new key and value will be written to the file content
- * via getInitialContent() method of the page2 during the file creation.
- */
- if (bundleFile.exists() && !page1.isNewFile()) {
+ if (!page1.isDuplicatedKeyValue()) {
+ IFile bundleFile = null;
+ if (page1.isNewFile()) {
+ bundleFile = page2.createNewFile();
+ } else {
+ bundleFile = page1.getBundleFile();
+ }
/*
- *
https://jira.jboss.org/browse/JBIDE-7218
- * Add only one line before adding the value.
+ * Exit when the file is null
*/
- String writeToFile = "\n" + page1.getKeyValuePair(); //$NON-NLS-1$
- InputStream is = new ByteArrayInputStream(writeToFile.getBytes());
- try {
- bundleFile.appendContents(is, false, true, null);
- is.close();
- is = null;
- } catch (CoreException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
+ if (bundleFile == null) {
+ return false;
}
+ /*
+ * Add "key=value" to the bundle file that is already exists.
+ * When the file is new key and value will be written to the file content
+ * via getInitialContent() method of the page2 during the file creation.
+ */
+ if (bundleFile.exists() && !page1.isNewFile()) {
+ /*
+ *
https://jira.jboss.org/browse/JBIDE-7218
+ * Add only one line before adding the value.
+ */
+ String writeToFile = "\n" + page1.getKeyValuePair(); //$NON-NLS-1$
+ InputStream is = new ByteArrayInputStream(writeToFile.getBytes());
+ try {
+ bundleFile.appendContents(is, false, true, null);
+ is.close();
+ is = null;
+ } catch (CoreException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
/*
* Replace text in the editor
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java 2010-10-25
13:27:36 UTC (rev 26030)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java 2010-10-25
14:15:48 UTC (rev 26031)
@@ -110,6 +110,7 @@
private Status propsKeyStatus;
private Status propsValueStatus;
private Status duplicateKeyStatus;
+ private Status duplicateValueStatus;
private Table tagsTable;
/**
@@ -145,6 +146,7 @@
propsKeyStatus = new Status(IStatus.OK, JspEditorPlugin.PLUGIN_ID, Constants.EMPTY);
propsValueStatus = new Status(IStatus.OK, JspEditorPlugin.PLUGIN_ID, Constants.EMPTY);
duplicateKeyStatus = new Status(IStatus.OK, JspEditorPlugin.PLUGIN_ID,
Constants.EMPTY);
+ duplicateValueStatus = new Status(IStatus.OK, JspEditorPlugin.PLUGIN_ID,
Constants.EMPTY);
}
public void createControl(Composite parent) {
@@ -349,52 +351,69 @@
}
}
/*
- * Check the initial key value
- * If there is the error - add sequence number to the key
+ * Check the initial value status
+ * When the same value is already externalized --
+ * suggest to use already created key as well.
*/
- updateDuplicateKeyStatus();
- while (!duplicateKeyStatus.isOK()) {
- int index = propsKey.getText().lastIndexOf('_');
- String newKey = Constants.EMPTY;
- if (index != -1) {
+ updatePropertiesValueStatus();
+ updateDuplicateValueStatus();
+ if (propsValueStatus.isOK()) {
+ if (!duplicateValueStatus.isOK()
+ && JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_VALUE_EXISTS
+ .equalsIgnoreCase(duplicateValueStatus.getMessage())) {
+ applyStatus(this, new IStatus[] {duplicateValueStatus});
+ } else {
/*
- * String sequence at the end should be checked.
- * If it is a sequence number - it should be increased by 1.
- * If not - new number should be added.
+ * Check the initial key status
+ * If there is the error - add sequence number to the key
*/
- String numberString = propsKey.getText().substring(index + 1);
- int number;
- try {
- number = Integer.parseInt(numberString);
- number++;
- newKey = propsKey.getText().substring(0, index + 1) + number;
- } catch (NumberFormatException e) {
- newKey = propsKey.getText() + "_1"; //$NON-NLS-1$
+ updateDuplicateKeyStatus();
+ while (!duplicateKeyStatus.isOK()) {
+ int index = propsKey.getText().lastIndexOf('_');
+ String newKey = Constants.EMPTY;
+ if (index != -1) {
+ /*
+ * String sequence at the end should be checked.
+ * If it is a sequence number - it should be increased by 1.
+ * If not - new number should be added.
+ */
+ String numberString = propsKey.getText().substring(index + 1);
+ int number;
+ try {
+ number = Integer.parseInt(numberString);
+ number++;
+ newKey = propsKey.getText().substring(0, index + 1) + number;
+ } catch (NumberFormatException e) {
+ newKey = propsKey.getText() + "_1"; //$NON-NLS-1$
+ }
+ } else {
+ /*
+ * If the string has no sequence number - add it.
+ */
+ newKey = propsKey.getText() + "_1"; //$NON-NLS-1$
+ }
+ /*
+ * Set the new key text
+ */
+ propsKey.setText(newKey);
+ updateDuplicateKeyStatus();
}
- } else {
/*
- * If the string has no sequence number - add it.
+ *
https://jira.jboss.org/browse/JBIDE-6945
+ * Set the greeting message only.
+ * All the validation will take place in the fields' listeners
+ * after user enters some new values.
*/
- newKey = propsKey.getText() + "_1"; //$NON-NLS-1$
+ setMessage(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_ENTER_KEY_NAME,
+ IMessageProvider.INFORMATION);
}
- /*
- * Set the new key text
- */
- propsKey.setText(newKey);
- updateDuplicateKeyStatus();
+ } else {
+ applyStatus(this, new IStatus[] {propsValueStatus});
}
/*
- *
https://jira.jboss.org/browse/JBIDE-6945
- * Set the greeting message only.
- * All the validation will take place in the fields' listeners
- * after user enters some new values.
- */
- setMessage(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_ENTER_KEY_NAME,
- IMessageProvider.INFORMATION);
- /*
* Update the Buttons state.
* When all the fields are correct --
- * then user should be abke to press OK
+ * then user should be able to press OK
*/
setPageComplete(isPageComplete());
/*
@@ -442,21 +461,41 @@
* @param key the key name
* @return <code>true</code> if there is a key with the specified name
*/
- private boolean isDuplicatedKey(String key) {
- boolean isDupliacted = false;
+ private boolean isKeyDuplicated(String key) {
+ boolean isDuplicated = false;
if ((tagsTable.getItemCount() > 0) && (null != key) && !isNewFile())
{
TableItem[] items = tagsTable.getItems();
for (TableItem tableItem : items) {
if (key.equalsIgnoreCase(tableItem.getText(0))) {
- isDupliacted = true;
+ isDuplicated = true;
break;
}
}
}
- return isDupliacted;
+ return isDuplicated;
}
/**
+ * Checks values in the selected resource bundle.
+ *
+ * @param value the text string to externalize
+ * @return <code>true</code> if there is a key with the specified name
+ */
+ private boolean isValueDuplicated(String value) {
+ boolean isDuplicated = false;
+ if ((tagsTable.getItemCount() > 0) && (null != value) &&
!isNewFile()) {
+ TableItem[] items = tagsTable.getItems();
+ for (TableItem tableItem : items) {
+ if (value.equalsIgnoreCase(tableItem.getText(1))) {
+ isDuplicated = true;
+ break;
+ }
+ }
+ }
+ return isDuplicated;
+ }
+
+ /**
* Update resource bundle table according to the selected file:
* it fills key and value columns.
*
@@ -605,7 +644,7 @@
* Update duplicate key status.
*/
private void updateDuplicateKeyStatus() {
- if (isDuplicatedKey(propsKey.getText())) {
+ if (isKeyDuplicated(propsKey.getText())) {
duplicateKeyStatus = new Status(
IStatus.ERROR,
JspEditorPlugin.PLUGIN_ID,
@@ -614,6 +653,20 @@
duplicateKeyStatus = new Status(IStatus.OK, JspEditorPlugin.PLUGIN_ID,
Constants.EMPTY);
}
}
+
+ /**
+ * Update duplicate key status.
+ */
+ private void updateDuplicateValueStatus() {
+ if (isValueDuplicated(propsValue.getText())) {
+ duplicateValueStatus = new Status(
+ IStatus.WARNING,
+ JspEditorPlugin.PLUGIN_ID,
+ JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_VALUE_EXISTS);
+ } else {
+ duplicateValueStatus = new Status(IStatus.OK, JspEditorPlugin.PLUGIN_ID,
Constants.EMPTY);
+ }
+ }
private void updatePropertiesValueStatus() {
String text = propsValue.getText();
@@ -655,10 +708,17 @@
updatePropertiesKeyStatus();
updatePropertiesValueStatus();
updateDuplicateKeyStatus();
+ updateDuplicateValueStatus();
/*
* Apply status to the dialog
*/
- applyStatus(this, new IStatus[] {propsKeyStatus, propsValueStatus,
duplicateKeyStatus});
+ if (!duplicateValueStatus.isOK()) {
+ applyStatus(this, new IStatus[] { propsKeyStatus, propsValueStatus,
+ duplicateValueStatus});
+ } else {
+ applyStatus(this, new IStatus[] { propsKeyStatus, propsValueStatus,
+ duplicateKeyStatus});
+ }
/*
* Set page complete
*/
@@ -677,7 +737,6 @@
severeStatus = severeStatus.getSeverity() >= status.getSeverity()
? severeStatus : status;
}
-
String message = severeStatus.getMessage();
switch (severeStatus.getSeverity()) {
case IStatus.OK:
@@ -850,6 +909,21 @@
}
/**
+ * Use existed key-value pair from the properties file
+ * without writing any data to the file.
+ *
+ * @return
+ */
+ public boolean isDuplicatedKeyValue() {
+ boolean exists = false;
+ if (isValueDuplicated(propsValue.getText())
+ && isKeyDuplicated(propsKey.getText())) {
+ exists = true;
+ }
+ return exists;
+ }
+
+ /**
* Generate properties key.
* Replaces all non-word characters with
* underline character.
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2010-10-25
13:27:36 UTC (rev 26030)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/JstUIMessages.java 2010-10-25
14:15:48 UTC (rev 26031)
@@ -143,6 +143,7 @@
public static String EXTERNALIZE_STRINGS_DIALOG_RB_IS_MISSING;
public static String EXTERNALIZE_STRINGS_DIALOG_WRONG_SELECTION;
public static String EXTERNALIZE_STRINGS_DIALOG_WRONG_SELECTED_TEXT;
+ public static String EXTERNALIZE_STRINGS_DIALOG_VALUE_EXISTS;
public static String EXTERNALIZE_STRINGS_DIALOG_PLEASE_SELECT_BUNDLE;
public static String EXTERNALIZE_STRINGS_DIALOG_SELECTED_TEXT_IS_EMPTY;
public static String EXTERNALIZE_STRINGS_DIALOG_KEY_MUST_BE_SET;
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2010-10-25
13:27:36 UTC (rev 26030)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/messages/messages.properties 2010-10-25
14:15:48 UTC (rev 26031)
@@ -122,6 +122,7 @@
EXTERNALIZE_STRINGS_DIALOG_RB_IS_MISSING=Could not initialize resource bundles!
EXTERNALIZE_STRINGS_DIALOG_WRONG_SELECTION=Wrong selection! Please select correct
string.
EXTERNALIZE_STRINGS_DIALOG_WRONG_SELECTED_TEXT=Wrong selected text. Please select correct
string.
+EXTERNALIZE_STRINGS_DIALOG_VALUE_EXISTS=Such a string is already externalized.\n Use
stored key or specify the new one.
EXTERNALIZE_STRINGS_DIALOG_PLEASE_SELECT_BUNDLE=- Please select bundle -
EXTERNALIZE_STRINGS_DIALOG_SELECTED_TEXT_IS_EMPTY=Selected text is empty
EXTERNALIZE_STRINGS_DIALOG_KEY_MUST_BE_SET=Key must be set
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/wizard/ExternalizeStringsDialogTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/wizard/ExternalizeStringsDialogTest.java 2010-10-25
13:27:36 UTC (rev 26030)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/wizard/ExternalizeStringsDialogTest.java 2010-10-25
14:15:48 UTC (rev 26031)
@@ -181,17 +181,77 @@
isUnusedDialogOpened = true;
/*
- * Check generated property key
+ * Check the generated property key.
+ * It should be as is.
+ * The dialog should use the stored key-pair value.
+ * OK button should be enabled.
+ * No modifications to the properties file should be made.
*/
SWTBotText defKeyText = bot.textWithLabelInGroup(
JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPERTIES_KEY,
JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPS_STRINGS_GROUP);
assertNotNull("Cannot find 'Property Key' text field", defKeyText);
//$NON-NLS-1$
- assertText("User_1",defKeyText); //$NON-NLS-1$
+ assertText("User",defKeyText); //$NON-NLS-1$
- bot.button(WidgetVariables.CANCEL_BUTTON).click();
+ bot.button(WidgetVariables.OK_BUTTON).click();
isUnusedDialogOpened = false;
+ editor.close();
+ /*
+ * Check that properties file hasn't been modified.
+ */
+ SWTBotEditor editor2 = SWTTestExt.eclipse.openFile(
+ JBT_TEST_PROJECT_NAME, "JavaSource", "demo", //$NON-NLS-1$
//$NON-NLS-2$
+ "Messages.properties"); //$NON-NLS-1$
+ editor2.toTextEditor().selectLine(3);
+ String line = editor2.toTextEditor().getSelection();
+ assertEquals("'Messages.properties' was updated incorrectly",
"User=User", line); //$NON-NLS-1$ //$NON-NLS-2$
+ /*
+ * Change the property value to the new one, let say 'User1'.
+ * And externalize the same string again.
+ */
+ bot.cTabItem("Source").activate(); //$NON-NLS-1$
+ editor2.toTextEditor().typeText(3,9, "1"); //$NON-NLS-1$
+ editor2.saveAndClose();
+ editor = SWTTestExt.packageExplorer.openFile(JBT_TEST_PROJECT_NAME,
+ "WebContent", "pages", TEST_PAGE); //$NON-NLS-1$ //$NON-NLS-2$
+ editor.setFocus();
+ /*
+ * Select some text
+ */
+ editor.toTextEditor().selectRange(7, 18, 4);
+ assertEquals("Replaced text is incorrect", "User",
editor.toTextEditor().getSelection()); //$NON-NLS-1$ //$NON-NLS-2$
+ /*
+ * Get toolbar button
+ */
+ assertTrue(TOOLBAR_ICON_ENABLED, bot
+ .toolbarButtonWithTooltip(TOOL_TIP)
+ .isEnabled());
+ bot.toolbarButtonWithTooltip(TOOL_TIP).click();
+ bot.shell(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).setFocus();
+ bot.shell(JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).activate();
+ isUnusedDialogOpened = true;
+ /*
+ * The value has been changed and now unique.
+ * But the same key is in the bundle.
+ * Thus the dialog should suggest "User_1" as a key value.
+ */
+ defKeyText = bot.textWithLabelInGroup(
+ JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPERTIES_KEY,
+ JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_PROPS_STRINGS_GROUP);
+ assertNotNull("Cannot find 'Property Key' text field", defKeyText);
//$NON-NLS-1$
+ assertText("User_1",defKeyText); //$NON-NLS-1$
+ bot.button(WidgetVariables.OK_BUTTON).click();
+ isUnusedDialogOpened = false;
+ /*
+ * Check that the new key has been added.
+ */
+ editor2 = SWTTestExt.eclipse.openFile(
+ JBT_TEST_PROJECT_NAME, "JavaSource", "demo", //$NON-NLS-1$
//$NON-NLS-2$
+ "Messages.properties"); //$NON-NLS-1$
+ editor2.toTextEditor().selectLine(4);
+ line = editor2.toTextEditor().getSelection();
+ assertEquals("'Messages.properties' was updated incorrectly",
"User_1=User", line); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testExternalizeStringsDialogInXhtml() throws Throwable {