Statistics
| Revision:

root / tmp / org.txm.translate.rcp / src / org / txm / rcp / translate / i18n / ExternalizerUI.groovy @ 1317

History | View | Annotate | Download (4 kB)

1 1223 mdecorde
package org.txm.rcp.translate.i18n;
2 1223 mdecorde
3 1223 mdecorde
import java.awt.*;
4 1223 mdecorde
import javax.swing.*;
5 1223 mdecorde
import javax.swing.table.*
6 1223 mdecorde
import java.awt.GridLayout
7 1223 mdecorde
import java.awt.event.*
8 1223 mdecorde
9 1223 mdecorde
import org.txm.utils.LS;
10 1223 mdecorde
/**
11 1223 mdecorde
 * This replace the eclipse externalisation interface
12 1223 mdecorde
 * Scan the java files for not translated Strings and update the messages.properties file
13 1223 mdecorde
 *
14 1223 mdecorde
 * uses ExternalizeStringFile
15 1223 mdecorde
 * @author mdecorde
16 1223 mdecorde
 *
17 1223 mdecorde
 */
18 1223 mdecorde
class ExternalizeUI extends JPanel {
19 1223 mdecorde
        ExternalizeStringFile externalizer;
20 1223 mdecorde
21 1223 mdecorde
        ExternalizeUI() {
22 1223 mdecorde
                super(new FlowLayout());
23 1223 mdecorde
                File userDir = new File(System.getProperty("user.home"))
24 1223 mdecorde
                File srcDir = new File(userDir, "workspace47/org.txm.rcp/src/main/java")
25 1223 mdecorde
                File propFile = new File(srcDir, "org/txm/rcp/messages.properties")
26 1223 mdecorde
                File messageFile = new File(srcDir, "org/txm/rcp/Messages.java")
27 1223 mdecorde
28 1223 mdecorde
                println userDir
29 1223 mdecorde
                println srcDir
30 1223 mdecorde
                println propFile
31 1223 mdecorde
                println messageFile
32 1223 mdecorde
33 1223 mdecorde
                String[] columnNames = ["Files in "+srcDir.getPath(), "Nb of changes"];
34 1223 mdecorde
35 1223 mdecorde
36 1223 mdecorde
                def files = LS.list(srcDir, true, false);
37 1223 mdecorde
                files = files.findAll { file -> file.getName().endsWith(".java") }
38 1223 mdecorde
                files = files.sort()
39 1223 mdecorde
                println files
40 1223 mdecorde
41 1223 mdecorde
                externalizer = new ExternalizeStringFile(propFile, messageFile);
42 1223 mdecorde
                println "externalizer ready"
43 1223 mdecorde
                def data = []
44 1223 mdecorde
                def selectedFiles = []
45 1223 mdecorde
                for (File file : files) {
46 1223 mdecorde
                        int count = externalizer.getNbOfChanges(file)
47 1223 mdecorde
                        if (count != 0)        {
48 1223 mdecorde
                                selectedFiles << file
49 1223 mdecorde
                                data << [file.getPath().substring(srcDir.getPath().length()), count]
50 1223 mdecorde
                        }
51 1223 mdecorde
                }
52 1223 mdecorde
                Object[][] arrayData = data;
53 1223 mdecorde
                JTable table = new JTable(arrayData, columnNames);
54 1223 mdecorde
                table.getColumnModel().getColumn(0).setPreferredWidth(600);
55 1223 mdecorde
                table.getColumnModel().getColumn(1).setPreferredWidth(100);
56 1223 mdecorde
57 1223 mdecorde
                table.addMouseListener(new MouseAdapter() {
58 1223 mdecorde
                                        @Override
59 1223 mdecorde
                                        public void mouseClicked(MouseEvent e) {
60 1223 mdecorde
                                                if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 1) {
61 1223 mdecorde
                                                        int selectedRowIndex = table.getSelectedRow();
62 1223 mdecorde
                                                        int c = externalizer.process(selectedFiles[selectedRowIndex])
63 1223 mdecorde
                                                        println ""+c
64 1223 mdecorde
                                                        int after = table.getValueAt(table.getSelectedRow(), 1);
65 1223 mdecorde
                                                        table.setValueAt(after - c, table.getSelectedRow(), 1);
66 1223 mdecorde
                                                        //show your dialog with the selected row's contents
67 1223 mdecorde
                                                }
68 1223 mdecorde
                                        }
69 1223 mdecorde
                                });
70 1223 mdecorde
71 1223 mdecorde
                JScrollPane scrollPane = new JScrollPane(table);
72 1223 mdecorde
                table.setFillsViewportHeight(true);
73 1223 mdecorde
74 1223 mdecorde
                add(scrollPane)
75 1223 mdecorde
76 1223 mdecorde
                JButton cancelButton = new JButton("CANCEL");
77 1223 mdecorde
                JButton okButton = new JButton("OK + SAVE");
78 1223 mdecorde
                okButton.addActionListener(new ActionListener() {
79 1223 mdecorde
                        public void actionPerformed(ActionEvent e)
80 1223 mdecorde
                        {
81 1223 mdecorde
                                ExternalizeUI.this.doSave();
82 1223 mdecorde
                                System.exit(0);
83 1223 mdecorde
                        }
84 1223 mdecorde
                });
85 1223 mdecorde
86 1223 mdecorde
                cancelButton.addActionListener(new ActionListener() {
87 1223 mdecorde
                        public void actionPerformed(ActionEvent e)
88 1223 mdecorde
                        {
89 1223 mdecorde
                                println "Changes not saved: "
90 1223 mdecorde
                                System.exit(0);
91 1223 mdecorde
                        }
92 1223 mdecorde
                });
93 1223 mdecorde
                cancelButton.setSize(100, 20);
94 1223 mdecorde
                okButton.setSize(100, 20);
95 1223 mdecorde
                add(cancelButton)
96 1223 mdecorde
                add(okButton)
97 1223 mdecorde
98 1223 mdecorde
                println "end of constructor"
99 1223 mdecorde
        }
100 1223 mdecorde
101 1223 mdecorde
        public void doSave() {
102 1223 mdecorde
                if (externalizer != null && externalizer.saveChanges()) {
103 1223 mdecorde
                        JOptionPane.showMessageDialog(this, "Changes saved");
104 1223 mdecorde
                }
105 1223 mdecorde
        }
106 1223 mdecorde
107 1223 mdecorde
        /**
108 1223 mdecorde
         * Create the GUI and show it.  For thread safety,
109 1223 mdecorde
         * this method should be invoked from the
110 1223 mdecorde
         * event-dispatching thread.
111 1223 mdecorde
         */
112 1223 mdecorde
        private static void createAndShowGUI() {
113 1223 mdecorde
                //Create and set up the window.
114 1223 mdecorde
                JFrame frame = new JFrame("ExternalizeUI");
115 1223 mdecorde
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
116 1223 mdecorde
117 1223 mdecorde
                //Create and set up the content pane.
118 1223 mdecorde
                ExternalizeUI newContentPane = new ExternalizeUI();
119 1223 mdecorde
                newContentPane.setOpaque(true); //content panes must be opaque
120 1223 mdecorde
121 1223 mdecorde
                //                frame.addWindowListener(new java.awt.event.WindowAdapter() {
122 1223 mdecorde
                //                        public void windowClosing(WindowEvent winEvt) {
123 1223 mdecorde
                //                                newContentPane.doSave();
124 1223 mdecorde
                //                                System.exit(0);
125 1223 mdecorde
                //                        }
126 1223 mdecorde
                //                });
127 1223 mdecorde
                frame.setContentPane(newContentPane);
128 1223 mdecorde
129 1223 mdecorde
                println "display"
130 1223 mdecorde
                //Display the window.
131 1223 mdecorde
                frame.pack();
132 1223 mdecorde
                frame.setVisible(true);
133 1223 mdecorde
        }
134 1223 mdecorde
135 1223 mdecorde
136 1223 mdecorde
        public static void main(String[] args) {
137 1223 mdecorde
                //Schedule a job for the event-dispatching thread:
138 1223 mdecorde
                //creating and showing this application's GUI.
139 1223 mdecorde
                javax.swing.SwingUtilities.invokeLater(new Runnable() {
140 1223 mdecorde
                                        public void run() {
141 1223 mdecorde
                                                createAndShowGUI();
142 1223 mdecorde
                                        }
143 1223 mdecorde
                                });
144 1223 mdecorde
        }
145 1223 mdecorde
}