Skip to content

Commit

Permalink
fixed row name in arrays xml
Browse files Browse the repository at this point in the history
  • Loading branch information
Liew Jun Tung committed May 28, 2015
1 parent c00db6c commit 14e5d92
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 71 deletions.
2 changes: 1 addition & 1 deletion plugin/src/org/pandawarrior/androidXMLConverter/GUI.form
Expand Up @@ -12,7 +12,7 @@
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="400" height="-1"/>
<preferred-size width="200" height="200"/>
<preferred-size width="480" height="300"/>
</grid>
</constraints>
<properties/>
Expand Down
47 changes: 30 additions & 17 deletions plugin/src/org/pandawarrior/androidXMLConverter/GUI.java
Expand Up @@ -38,10 +38,11 @@ public class GUI extends DialogWrapper {
private JRadioButton arraysXmlRadioButton;
private String currentFolder;
private String selected;
private final static String ERROR_MSG1 = "Error! Your csv file might have a data that is empty. use 'null' or ' ' to replace it.";
public GUI(Project project, String initialFolder) {
super(project, true);
this.setTitle("Android Parser");
this.setSize(450, 300);
this.setSize(480, 300);
this.setResizable(true);
// setContentPane(rootPane);
// setVisible(true);
Expand All @@ -64,13 +65,19 @@ public void actionPerformed(ActionEvent e) {
xcOKButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String folder = xcReadField.getText();
String csv = xcWriteField.getText();
readXML(folder, csv);
xcReadField.setText("");
xcWriteField.setText("");
xcLabel.setText("SUCCESS!");
xcLabel.setForeground(JBColor.GREEN);
try {
String folder = xcReadField.getText();
String csv = xcWriteField.getText();
readXML(folder, csv);
xcReadField.setText("");
xcWriteField.setText("");
xcLabel.setText("SUCCESS!");
xcLabel.setForeground(JBColor.GREEN);
}catch (ArrayIndexOutOfBoundsException e1){
xcLabel.setText(ERROR_MSG1);
xcLabel.setForeground(JBColor.RED);
}

}
});
cxReadBtn.addActionListener(new ActionListener() {
Expand All @@ -88,13 +95,19 @@ public void actionPerformed(ActionEvent e) {
cxOKButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String csv = cxReadField.getText();
String folder = cxWriteField.getText();
writeXML(folder, csv);
cxReadField.setText("");
cxWriteField.setText("");
cxLabel.setText("SUCCESS!");
cxLabel.setForeground(JBColor.GREEN);
try {
String csv = cxReadField.getText();
String folder = cxWriteField.getText();
writeXML(folder, csv);
cxReadField.setText("");
cxWriteField.setText("");
cxLabel.setText("SUCCESS!");
cxLabel.setForeground(JBColor.GREEN);
} catch (ArrayIndexOutOfBoundsException e1){
cxLabel.setText(ERROR_MSG1);
cxLabel.setForeground(JBColor.RED);
}

}
});
stringsXmlRadioButton.setSelected(true);
Expand Down Expand Up @@ -160,7 +173,7 @@ private String chooseCSV() {
}
}

private void writeXML(final String folder, final String csv){
private void writeXML(final String folder, final String csv) throws ArrayIndexOutOfBoundsException{
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Expand All @@ -176,7 +189,7 @@ public void run() {

}

private void readXML(final String folder, final String csv){
private void readXML(final String folder, final String csv) throws ArrayIndexOutOfBoundsException{
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Expand Down
Expand Up @@ -131,25 +131,28 @@ class WriteXml {
def xml = new MarkupBuilder(stringWriter)
def mainDictValue = it.value
def fileName = it.key
def rowName
String dir = "${destination}/res/${fileName}/"
File file = new File(dir, "${type}.xml")
File folder = new File(dir)

if (!folder.exists()) {
folder.mkdirs()
}
rowName = type == ARRAY_FILE ? "string-array" : type

xml.resources {
mainDictValue.each {
def key = it.key
def value = it.value.collect()
if (fileName.equals("values") && transDict[key].equals("false")) {
"${type}"(name: key, translatable: transDict[key]) {
"${rowName}"(name: key, translatable: transDict[key]) {
value.each {
item(it)
}
}
} else if (transDict[key].equals("true")) {
"${type}"(name: key) {
"${rowName}"(name: key) {
value.each {
if (!it.equals("null") || !it.equals(" ")) {
item(it)
Expand Down
51 changes: 0 additions & 51 deletions xml_csv_parse/src/test/groovy/org/pandawarrior/ReadXmlTest.groovy

This file was deleted.

0 comments on commit 14e5d92

Please sign in to comment.