Author: dmaliarevich
Date: 2010-08-05 12:13:03 -0400 (Thu, 05 Aug 2010)
New Revision: 23943
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/dialog/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-6735 , properties file loading was updated, unicode
codes shoud be parsed correctly, swtbot test was updated.
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/dialog/ExternalizeStringsWizardPage.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/dialog/ExternalizeStringsWizardPage.java 2010-08-05
15:59:18 UTC (rev 23942)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/dialog/ExternalizeStringsWizardPage.java 2010-08-05
16:13:03 UTC (rev 23943)
@@ -13,10 +13,13 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import org.eclipse.core.resources.IFile;
@@ -66,6 +69,7 @@
import org.jboss.tools.common.model.project.IModelNature;
import org.jboss.tools.common.model.ui.ModelUIImages;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.jst.jsp.editor.IVisualContext;
import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
import org.jboss.tools.jst.jsp.jspeditor.SourceEditorPageContext;
@@ -105,9 +109,9 @@
private Status propsKeyStatus;
private Status propsValueStatus;
private Status rbComboStatus;
-
private Table tagsTable;
+
public ExternalizeStringsWizardPage(String pageName, StructuredTextEditor editor,
BundleMap bm) {
/*
* Setting dialog Title, Description, Image.
@@ -417,9 +421,13 @@
/*
* Read the file content
*/
+ String encoding = FileUtil.getEncoding(file);
BufferedReader in = new BufferedReader(new InputStreamReader(
- file.getContents()));
- String line = in.readLine();
+ file.getContents(), encoding));
+ Properties properties = new Properties();
+ properties.load(in);
+ in.close();
+ in = null;
/*
* Clear the table
*/
@@ -427,22 +435,16 @@
/*
* Fill in new values
*/
- int i = 0;
- while (line != null) {
+ int k = 0;
+ Set<String> keys = properties.stringPropertyNames();
+ List<String> keysList = new ArrayList<String>(keys);
+ Collections.sort(keysList);
+ for (String key : keysList) {
TableItem tableItem = null;
- String[] propertie = null;
- if (line.trim().length() > 0) {
- tableItem = new TableItem(tagsTable, SWT.BORDER, i);
- propertie = line.trim().split("="); //$NON-NLS-1$
- if (propertie.length < 3) {
- tableItem.setText(propertie);
- i++;
- }
- }
- line = in.readLine();
+ tableItem = new TableItem(tagsTable, SWT.BORDER, k);
+ k++;
+ tableItem.setText(new String[] {key, properties.getProperty(key)});
}
- in.close();
- in = null;
} catch (CoreException e) {
VpePlugin.getDefault().logError(
"Could not load file content for '" + file + "'", e);
//$NON-NLS-1$ //$NON-NLS-2$
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-08-05
15:59:18 UTC (rev 23942)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.bot.test/src/org/jboss/tools/vpe/ui/bot/test/wizard/ExternalizeStringsDialogTest.java 2010-08-05
16:13:03 UTC (rev 23943)
@@ -11,10 +11,13 @@
package org.jboss.tools.vpe.ui.bot.test.wizard;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
+import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.jboss.tools.vpe.messages.VpeUIMessages;
import org.jboss.tools.vpe.ui.bot.test.VPEAutoTestCase;
import org.jboss.tools.ui.bot.ext.SWTTestExt;
@@ -34,21 +37,33 @@
private final String COMPLEX_VALUE_RESULT = "!! HELLO ~ Input User, Name.Page
?" + //$NON-NLS-1$
" and some more text @ \\# vc \\$ % yy^ &*(ghg ) _l-kk+mmm\\/fdg\\
;.df:,ee {df}df[ty]"; //$NON-NLS-1$
+ private boolean isUnusedDialogOpened = false;
+
public ExternalizeStringsDialogTest() {
super();
}
@Override
protected void closeUnuseDialogs() {
+ try {
+ SWTBotShell dlgShell = bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE);
+ dlgShell.setFocus();
+ dlgShell.close();
+ } catch (WidgetNotFoundException e) {
+ e.printStackTrace();
+ } finally {
+ isUnusedDialogOpened = false;
+ }
}
@Override
protected boolean isUnuseDialogOpened() {
- return false;
+ return isUnusedDialogOpened;
}
public void testExternalizeStringsDialog() throws Throwable {
+ isUnusedDialogOpened = false;
/*
* Open simple html file in order to get the VPE toolbar
*/
@@ -65,6 +80,7 @@
bot.toolbarButtonWithTooltip(VpeUIMessages.EXTERNALIZE_STRINGS).click();
bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).setFocus();
bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).activate();
+ isUnusedDialogOpened = true;
/*
* Check properties key and value fields
*/
@@ -100,18 +116,23 @@
*/
SWTBotTable table = bot.table();
assertNotNull("Table should exist", table); //$NON-NLS-1$
+ bot.sleep(10000);
+ /*
+ * The list should be sorted in the alphabetical order.
+ */
assertEquals(INCORRECT_TABLE_VALUE, "header", table.cell(0, 0));
//$NON-NLS-1$
assertEquals(INCORRECT_TABLE_VALUE, "Hello Demo Application", table.cell(0,
1)); //$NON-NLS-1$
- assertEquals(INCORRECT_TABLE_VALUE, "prompt_message", table.cell(1, 0));
//$NON-NLS-1$
- assertEquals(INCORRECT_TABLE_VALUE, "Name:", table.cell(1, 1));
//$NON-NLS-1$
- assertEquals(INCORRECT_TABLE_VALUE, "hello_message", table.cell(2, 0));
//$NON-NLS-1$
- assertEquals(INCORRECT_TABLE_VALUE, "Hello", table.cell(2, 1));
//$NON-NLS-1$
+ assertEquals(INCORRECT_TABLE_VALUE, "hello_message", table.cell(1, 0));
//$NON-NLS-1$
+ assertEquals(INCORRECT_TABLE_VALUE, "Hello", table.cell(1, 1));
//$NON-NLS-1$
+ assertEquals(INCORRECT_TABLE_VALUE, "prompt_message", table.cell(2, 0));
//$NON-NLS-1$
+ assertEquals(INCORRECT_TABLE_VALUE, "Name:", table.cell(2, 1));
//$NON-NLS-1$
/*
* Press OK and replace the text in the editor
*/
assertTrue("(OK) button should be enabled.", //$NON-NLS-1$
bot.button(WidgetVariables.OK_BUTTON).isEnabled());
bot.button(WidgetVariables.OK_BUTTON).click();
+ isUnusedDialogOpened = false;
/*
* Check replaced text
*/
@@ -129,6 +150,7 @@
}
public void testExternalizeStringsDialogInXhtml() throws Throwable {
+ isUnusedDialogOpened = false;
/*
* Open simple html file in order to get the VPE toolbar
*/
@@ -145,6 +167,7 @@
bot.toolbarButtonWithTooltip(VpeUIMessages.EXTERNALIZE_STRINGS).click();
bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).setFocus();
bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).activate();
+ isUnusedDialogOpened = true;
/*
* Check properties key and value fields
@@ -181,16 +204,20 @@
*/
SWTBotTable table = bot.table();
assertNotNull("Table should exist", table); //$NON-NLS-1$
- assertEquals(INCORRECT_TABLE_VALUE, "prompt", table.cell(0, 0));
//$NON-NLS-1$
- assertEquals(INCORRECT_TABLE_VALUE, "Your Name\\:", table.cell(0, 1));
//$NON-NLS-1$
- assertEquals(INCORRECT_TABLE_VALUE, "greeting", table.cell(1, 0));
//$NON-NLS-1$
- assertEquals(INCORRECT_TABLE_VALUE, "Hello", table.cell(1, 1));
//$NON-NLS-1$
/*
+ * The list should be sorted in the alphabetical order.
+ */
+ assertEquals(INCORRECT_TABLE_VALUE, "greeting", table.cell(0, 0));
//$NON-NLS-1$
+ assertEquals(INCORRECT_TABLE_VALUE, "Hello", table.cell(0, 1));
//$NON-NLS-1$
+ assertEquals(INCORRECT_TABLE_VALUE, "prompt", table.cell(1, 0));
//$NON-NLS-1$
+ assertEquals(INCORRECT_TABLE_VALUE, "Your Name:", table.cell(1, 1));
//$NON-NLS-1$
+ /*
* Press OK and replace the text in the editor
*/
assertTrue("(OK) button should be enabled.", //$NON-NLS-1$
bot.button(WidgetVariables.OK_BUTTON).isEnabled());
bot.button(WidgetVariables.OK_BUTTON).click();
+ isUnusedDialogOpened = false;
/*
* Check replaced text
*/
@@ -208,6 +235,7 @@
}
public void testNewFileInExternalizeStringsDialog() throws Throwable {
+ isUnusedDialogOpened = false;
/*
* Open simple html file in order to get the VPE toolbar
*/
@@ -224,7 +252,7 @@
bot.toolbarButtonWithTooltip(VpeUIMessages.EXTERNALIZE_STRINGS).click();
bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).setFocus();
bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).activate();
-
+ isUnusedDialogOpened = true;
/*
* Enable next page and check it
*/
@@ -250,6 +278,7 @@
assertTrue("(OK) button should be enabled.", //$NON-NLS-1$
bot.button(WidgetVariables.OK_BUTTON).isEnabled());
bot.button(WidgetVariables.OK_BUTTON).click();
+ isUnusedDialogOpened = false;
/*
* Check that the text was replaced
*/
@@ -267,6 +296,7 @@
}
public void testEmptySelectionInExternalizeStringsDialog() throws Throwable {
+ isUnusedDialogOpened = false;
/*
* Open simple html file in order to get the VPE toolbar
*/
@@ -289,6 +319,7 @@
bot.toolbarButtonWithTooltip(VpeUIMessages.EXTERNALIZE_STRINGS).click();
bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).setFocus();
bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).activate();
+ isUnusedDialogOpened = true;
/*
* Check that the property value text is empty
*/
@@ -301,6 +332,7 @@
* Close the dialog
*/
bot.shell(VpeUIMessages.EXTERNALIZE_STRINGS_DIALOG_TITLE).close();
+ isUnusedDialogOpened = false;
/*
* Type some text outside the tag
*/