Author: dmaliarevich
Date: 2010-10-25 13:12:07 -0400 (Mon, 25 Oct 2010)
New Revision: 26038
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java
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 , Validation was added. JUnit was updated.
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
16:52:44 UTC (rev 26037)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/i18n/ExternalizeStringsWizardPage.java 2010-10-25
17:12:07 UTC (rev 26038)
@@ -357,10 +357,22 @@
*/
updatePropertiesValueStatus();
updateDuplicateValueStatus();
+ /*
+ * When selected text is fine perform further validation
+ */
if (propsValueStatus.isOK()) {
- if (!duplicateValueStatus.isOK()
- && JstUIMessages.EXTERNALIZE_STRINGS_DIALOG_VALUE_EXISTS
- .equalsIgnoreCase(duplicateValueStatus.getMessage())) {
+ /*
+ * Check the bundle for the value in it.
+ * if so -- show the warning and set correct key.
+ */
+ if (!duplicateValueStatus.isOK()) {
+ /*
+ * Set the same key value
+ */
+ propsKey.setText(getValueForKey(propsValue.getText()));
+ /*
+ * Set the new warning message
+ */
applyStatus(this, new IStatus[] {duplicateValueStatus});
} else {
/*
@@ -408,6 +420,9 @@
IMessageProvider.INFORMATION);
}
} else {
+ /*
+ * Set the message about wrong selected text.
+ */
applyStatus(this, new IStatus[] {propsValueStatus});
}
/*
@@ -495,7 +510,29 @@
return isDuplicated;
}
+
/**
+ * Returns the key for the specified value
+ * from the visual table.
+ *
+ * @param value - the value
+ * @return the key or empty string
+ */
+ private String getValueForKey(String value) {
+ String key = Constants.EMPTY;
+ if ((tagsTable.getItemCount() > 0) && (null != value) &&
!isNewFile()) {
+ TableItem[] items = tagsTable.getItems();
+ for (TableItem tableItem : items) {
+ if (value.equalsIgnoreCase(tableItem.getText(1))) {
+ key = tableItem.getText(0);
+ break;
+ }
+ }
+ }
+ return key;
+ }
+
+ /**
* Update resource bundle table according to the selected file:
* it fills key and value columns.
*
@@ -712,7 +749,9 @@
/*
* Apply status to the dialog
*/
- if (!duplicateValueStatus.isOK()) {
+ if (!duplicateValueStatus.isOK()
+ && getValueForKey(propsValue.getText())
+ .equalsIgnoreCase(propsKey.getText())) {
applyStatus(this, new IStatus[] { propsKeyStatus, propsValueStatus,
duplicateValueStatus});
} else {
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
16:52:44 UTC (rev 26037)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/wizard/ExternalizeStringsDialogTest.java 2010-10-25
17:12:07 UTC (rev 26038)
@@ -163,7 +163,6 @@
SWTBotEditor editor = SWTTestExt.packageExplorer.openFile(JBT_TEST_PROJECT_NAME,
"WebContent", "pages", TEST_PAGE); //$NON-NLS-1$ //$NON-NLS-2$
editor.setFocus();
-
/*
* Select some text
*/
@@ -205,7 +204,6 @@
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.
@@ -241,6 +239,17 @@
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$
+ assertTrue("(OK) button should be enabled.", //$NON-NLS-1$
+ bot.button(WidgetVariables.OK_BUTTON).isEnabled());
+ /*
+ * Change the key to validate duplicate key situation
+ */
+ defKeyText.setText("User"); //$NON-NLS-1$
+ assertTrue("(OK) button should be disabled.", //$NON-NLS-1$
+ !bot.button(WidgetVariables.OK_BUTTON).isEnabled());
+ defKeyText.setText("User_1"); //$NON-NLS-1$
+ assertTrue("(OK) button should be enabled.", //$NON-NLS-1$
+ bot.button(WidgetVariables.OK_BUTTON).isEnabled());
bot.button(WidgetVariables.OK_BUTTON).click();
isUnusedDialogOpened = false;
/*