OmegaT の翻訳状況(Statistics)を Excel で表示します。
Fix #50102
@@ -16,12 +16,18 @@ | ||
16 | 16 | |
17 | 17 | package jp.sourceforge.users.yutang.omegat.plugin.stats2excel; |
18 | 18 | |
19 | +import java.lang.reflect.InvocationTargetException; | |
20 | +import java.util.Comparator; | |
21 | +import java.util.ResourceBundle; | |
22 | +import org.apache.lucene.util.StringHelper; | |
19 | 23 | import org.omegat.core.Core; |
20 | 24 | import org.omegat.core.CoreEvents; |
21 | 25 | import org.omegat.core.events.IProjectEventListener.PROJECT_CHANGE_TYPE.*; |
26 | +import org.omegat.util.Log; | |
22 | 27 | import static org.omegat.util.Platform.OsType.WIN32; |
23 | 28 | import static org.omegat.util.Platform.OsType.WIN64; |
24 | 29 | import static org.omegat.util.Platform.getOsType; |
30 | +import org.omegat.util.StaticUtils; | |
25 | 31 | |
26 | 32 | /** |
27 | 33 | * open Statistics with Excel from standard Tools menu |
@@ -30,18 +36,28 @@ | ||
30 | 36 | */ |
31 | 37 | public class Stats2Excel { |
32 | 38 | |
33 | - public static void loadPlugins() { | |
39 | + private static String __VERSION_KEY = "version"; | |
40 | + | |
41 | + public static void loadPlugins() throws InvocationTargetException { | |
34 | 42 | try { |
35 | - if (isWindows()) { | |
36 | - // Not initialize in console mode. | |
37 | - CoreEvents.registerApplicationEventListener(StatsController.getInstance()); | |
38 | - } else { | |
39 | - Core.pluginLoadingError("Plugin Stats2Excel cannot be loaded " | |
40 | - + "because only Windows platform is supported"); | |
43 | + final String OMT_VERSION = ResourceBundle.getBundle( | |
44 | + "org/omegat/Version").getString(__VERSION_KEY); | |
45 | + if (! isAvailableOmTVersion(OMT_VERSION)) { | |
46 | + throw new RuntimeException(L10n.getLoadingErrorVersionTooOld()); | |
41 | 47 | } |
48 | + | |
49 | + if (! isWindows()) { | |
50 | + throw new RuntimeException(L10n.getLoadingErrorWrongPlatform()); | |
51 | + } | |
52 | + | |
53 | + // Not initialize in console mode. | |
54 | + CoreEvents.registerApplicationEventListener( | |
55 | + StatsController.getInstance()); | |
42 | 56 | } catch (Throwable ex) { |
43 | - Core.pluginLoadingError("Plugin Stats2Excel cannot be loaded " | |
44 | - + "because this version of OmegaT is not supported"); | |
57 | + String msg = StaticUtils.format(L10n.getLoadingErrorFormat(), | |
58 | + ex.getMessage()); | |
59 | + Log.logErrorRB(msg); | |
60 | + Core.pluginLoadingError(msg); | |
45 | 61 | } |
46 | 62 | } |
47 | 63 |
@@ -58,4 +74,9 @@ | ||
58 | 74 | return false; |
59 | 75 | } |
60 | 76 | |
77 | + private static boolean isAvailableOmTVersion(String version) { | |
78 | + Comparator<String> comp = StringHelper.getVersionComparator(); | |
79 | + return (comp.compare(version, "3.0.7") >= 0); | |
80 | + } | |
81 | + | |
61 | 82 | } |
\ No newline at end of file |
@@ -26,7 +26,7 @@ | ||
26 | 26 | |
27 | 27 | private static final String APP_NAME = "Stats2Excel"; |
28 | 28 | private static final String APP_VERSION = "0.1"; |
29 | - private static final String APP_BUILD = "20131201"; | |
29 | + private static final String APP_BUILD = "20131203"; | |
30 | 30 | private static final String APP_AUTHOR = "Yu Tang"; |
31 | 31 | |
32 | 32 | public static void main(String[] args) { |
@@ -42,4 +42,18 @@ | ||
42 | 42 | return bundle.getString("S2E_EXCEL_WINDOW_TITLE"); |
43 | 43 | } |
44 | 44 | |
45 | + // Error | |
46 | + | |
47 | + public static String getLoadingErrorFormat() { | |
48 | + return bundle.getString("S2E_LOADING_ERROR_FORMAT"); | |
49 | + } | |
50 | + | |
51 | + public static String getLoadingErrorVersionTooOld() { | |
52 | + return bundle.getString("S2E_LOADING_ERROR_VERSION_TOO_OLD"); | |
53 | + } | |
54 | + | |
55 | + public static String getLoadingErrorWrongPlatform() { | |
56 | + return bundle.getString("S2E_LOADING_ERROR_WRONG_PLATFORM"); | |
57 | + } | |
58 | + | |
45 | 59 | } |
@@ -88,28 +88,27 @@ | ||
88 | 88 | } |
89 | 89 | |
90 | 90 | service = Executors.newSingleThreadScheduledExecutor(); |
91 | + service.scheduleWithFixedDelay(new Runnable() { | |
91 | 92 | |
92 | - service.scheduleWithFixedDelay(new Runnable() { | |
93 | - | |
94 | - @Override | |
95 | - public void run() { | |
96 | - try { | |
97 | - if (ExcelModel.activate()) { | |
98 | - service.shutdown(); | |
99 | - service = null; | |
100 | - } | |
101 | - } catch (IOException ex) { | |
102 | - Log.log(ex); | |
103 | - setText(ex.getLocalizedMessage()); | |
93 | + @Override | |
94 | + public void run() { | |
95 | + try { | |
96 | + if (ExcelModel.activate()) { | |
104 | 97 | service.shutdown(); |
105 | - service =null; | |
106 | - } catch (InterruptedException ex) { | |
107 | - Log.log(ex); | |
108 | - setText(ex.getLocalizedMessage()); | |
109 | - service.shutdown(); | |
110 | - service =null; | |
98 | + service = null; | |
111 | 99 | } |
100 | + } catch (IOException ex) { | |
101 | + Log.log(ex); | |
102 | + setText(ex.getLocalizedMessage()); | |
103 | + service.shutdown(); | |
104 | + service =null; | |
105 | + } catch (InterruptedException ex) { | |
106 | + Log.log(ex); | |
107 | + setText(ex.getLocalizedMessage()); | |
108 | + service.shutdown(); | |
109 | + service =null; | |
112 | 110 | } |
111 | + } | |
113 | 112 | }, 0, 500, TimeUnit.MILLISECONDS); |
114 | 113 | } |
115 | 114 |