Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / scripts / i18n / ExternalizerUI.groovy @ 187

History | View | Annotate | Download (4 kB)

1
package org.txm.scripts.i18n;
2

    
3
import java.awt.*;
4
import javax.swing.*;
5
import javax.swing.table.*
6
import java.awt.GridLayout
7
import java.awt.event.*
8

    
9
import org.txm.utils.LS;
10
/**
11
 * This replace the eclipse externalisation interface
12
 * Scan the java files for not translated Strings and update the messages.properties file
13
 * 
14
 * uses ExternalizeStringFile
15
 * @author mdecorde
16
 *
17
 */
18
class ExternalizeUI extends JPanel {
19
        ExternalizeStringFile externalizer;
20

    
21
        ExternalizeUI() {
22
                super(new FlowLayout());
23
                File userDir = new File(System.getProperty("user.home"))
24
                File srcDir = new File(userDir, "workspace43/org.txm.rcp/src/main/java")
25
                File propFile = new File(srcDir, "org/txm/rcpapplication/messages.properties")
26
                File messageFile = new File(srcDir, "org/txm/rcpapplication/Messages.java")
27

    
28
                println userDir
29
                println srcDir
30
                println propFile
31
                println messageFile
32

    
33
                String[] columnNames = ["Files in "+srcDir.getPath(), "Nb of changes"];
34

    
35

    
36
                def files = LS.list(srcDir, true, false);
37
                files = files.findAll { file -> file.getName().endsWith(".java") }
38
                files = files.sort()
39
                println files
40

    
41
                externalizer = new ExternalizeStringFile(propFile, messageFile);
42
                println "externalizer ready"
43
                def data = []
44
                def selectedFiles = []
45
                for (File file : files) {
46
                        int count = externalizer.getNbOfChanges(file)
47
                        if (count != 0)        {
48
                                selectedFiles << file
49
                                data << [file.getPath().substring(srcDir.getPath().length()), count]
50
                        }
51
                }
52
                Object[][] arrayData = data;
53
                JTable table = new JTable(arrayData, columnNames);
54
                table.getColumnModel().getColumn(0).setPreferredWidth(600);
55
                table.getColumnModel().getColumn(1).setPreferredWidth(100);
56

    
57
                table.addMouseListener(new MouseAdapter() {
58
                                        @Override
59
                                        public void mouseClicked(MouseEvent e) {
60
                                                if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1) {
61
                                                        int selectedRowIndex = table.getSelectedRow();
62
                                                        int c = externalizer.process(selectedFiles[selectedRowIndex])
63
                                                        println ""+c
64
                                                        int after = table.getValueAt(table.getSelectedRow(), 1);
65
                                                        table.setValueAt(after - c, table.getSelectedRow(), 1);
66
                                                        //show your dialog with the selected row's contents
67
                                                }
68
                                        }
69
                                });
70

    
71
                JScrollPane scrollPane = new JScrollPane(table);
72
                table.setFillsViewportHeight(true);
73

    
74
                add(scrollPane)
75

    
76
                JButton cancelButton = new JButton("CANCEL");
77
                JButton okButton = new JButton("OK + SAVE");
78
                okButton.addActionListener(new ActionListener() {
79
                        public void actionPerformed(ActionEvent e)
80
                        {
81
                                ExternalizeUI.this.doSave();
82
                                System.exit(0);
83
                        }
84
                });
85
                
86
                cancelButton.addActionListener(new ActionListener() {
87
                        public void actionPerformed(ActionEvent e)
88
                        {
89
                                println "Changes not saved: "
90
                                System.exit(0);
91
                        }
92
                });
93
                cancelButton.setSize(100, 20);
94
                okButton.setSize(100, 20);
95
                add(cancelButton)
96
                add(okButton)
97

    
98
                println "end of constructor"
99
        }
100

    
101
        public void doSave() {
102
                if (externalizer != null && externalizer.saveChanges()) {
103
                        JOptionPane.showMessageDialog(this, "Changes saved");
104
                }
105
        }
106

    
107
        /**
108
         * Create the GUI and show it.  For thread safety,
109
         * this method should be invoked from the
110
         * event-dispatching thread.
111
         */
112
        private static void createAndShowGUI() {
113
                //Create and set up the window.
114
                JFrame frame = new JFrame("ExternalizeUI");
115
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
116

    
117
                //Create and set up the content pane.
118
                ExternalizeUI newContentPane = new ExternalizeUI();
119
                newContentPane.setOpaque(true); //content panes must be opaque
120

    
121
                //                frame.addWindowListener(new java.awt.event.WindowAdapter() {
122
                //                        public void windowClosing(WindowEvent winEvt) {
123
                //                                newContentPane.doSave();
124
                //                                System.exit(0);
125
                //                        }
126
                //                });
127
                frame.setContentPane(newContentPane);
128

    
129
                println "display"
130
                //Display the window.
131
                frame.pack();
132
                frame.setVisible(true);
133
        }
134

    
135

    
136
        public static void main(String[] args) {
137
                //Schedule a job for the event-dispatching thread:
138
                //creating and showing this application's GUI.
139
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
140
                                        public void run() {
141
                                                createAndShowGUI();
142
                                        }
143
                                });
144
        }
145
}