From: <tri...@us...> - 2007-08-17 13:33:07
|
Revision: 31 http://equanda.svn.sourceforge.net/equanda/?rev=31&view=rev Author: triathlon98 Date: 2007-08-17 06:33:03 -0700 (Fri, 17 Aug 2007) Log Message: ----------- 1776267 add translate maven plugin small improvements in translate tool (shortcuts etc) Modified Paths: -------------- trunk/equanda-maven-plugin/pom.xml trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/Configuration.java trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/TranslationsEditor.java Added Paths: ----------- trunk/equanda-maven-plugin/src/main/java/org/equanda/plugin/TranslatePlugin.java trunk/equanda-maven-plugin/src/site/ trunk/equanda-maven-plugin/src/site/site.xml trunk/equanda-maven-plugin/src/site/wiki/ trunk/equanda-maven-plugin/src/site/wiki/generate.wiki trunk/equanda-maven-plugin/src/site/wiki/index.wiki trunk/equanda-maven-plugin/src/site/wiki/translate.wiki trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/IniConfiguration.java Modified: trunk/equanda-maven-plugin/pom.xml =================================================================== --- trunk/equanda-maven-plugin/pom.xml 2007-08-17 11:52:06 UTC (rev 30) +++ trunk/equanda-maven-plugin/pom.xml 2007-08-17 13:33:03 UTC (rev 31) @@ -33,5 +33,9 @@ <groupId>org.equanda</groupId> <artifactId>equanda-generate</artifactId> </dependency> + <dependency> + <groupId>org.equanda</groupId> + <artifactId>equanda-tool</artifactId> + </dependency> </dependencies> </project> Added: trunk/equanda-maven-plugin/src/main/java/org/equanda/plugin/TranslatePlugin.java =================================================================== --- trunk/equanda-maven-plugin/src/main/java/org/equanda/plugin/TranslatePlugin.java (rev 0) +++ trunk/equanda-maven-plugin/src/main/java/org/equanda/plugin/TranslatePlugin.java 2007-08-17 13:33:03 UTC (rev 31) @@ -0,0 +1,186 @@ +/** + * This file is part of the equanda project. + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights and + * limitations under the License. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + */ + +package org.equanda.plugin; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.equanda.tool.translationsEditor.Configuration; +import org.equanda.tool.translationsEditor.TranslationsEditor; +import org.equanda.util.SaveException; + +/** + * Maven pugin to edit the translation files for the project. + * + * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> + * @goal translate + * @description equanda maven plugin to edit the project translations + */ +public class TranslatePlugin + extends AbstractMojo +{ + /** + * @parameter expression="om.xml" + */ + private String definition; + + /** + * @parameter expression="${basedir}/../src/main/om" + */ + private String sourceDirectory; + + /** + * @parameter expression="true" + */ + private boolean importDbKeysOnly; + + /** + * @parameter expression="true" + */ + private boolean infrastructure; + + /** + * @parameter expression="equanda-table" + */ + private String context; + + /** + * @parameter expression="equanda-table" + */ + private String keyPrefixesToKeep; + + /** + * @parameter expression="${basedir}/src/main/resources/translations.txt" + */ + private String translateTarget; + + /** + * When not specified, then not used, could be something like "en:nl" + * + * @parameter expression="" + */ + private String verifyLanguages; + + /** + * @parameter expression="1000" + */ + private int width; + + /** + * @parameter expression="600" + */ + private int height; + + public void execute() + throws MojoExecutionException + { + System.out.println( "verifyLanguages " + verifyLanguages ); + if ( null == verifyLanguages || "".equals( verifyLanguages ) ) return; + + final Object waitFor = new Object(); + Thread.currentThread().setUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() + { + public void uncaughtException( Thread thread, Throwable throwable ) + { + SaveException.saveException( throwable, "during equanda:translate" ); + waitFor.notifyAll(); + } + } ); + + try + { + System.out.println( "need to really start" ); + new TranslationsEditor( new MavenConfiguration(), waitFor ); + System.out.println( "done" ); + } + catch ( Exception ex ) + { + SaveException.saveException( ex, "problems while editing translations" ); + throw new MojoExecutionException( "problems while editing translations", ex ); + } + synchronized ( waitFor ) + { + try { waitFor.wait(); } catch ( InterruptedException ex ) {/*ignore*/} + } + } + + private class MavenConfiguration + implements Configuration + { + public String getDefinition() + { + return definition; + } + + public String getAppdir() + { + return sourceDirectory; + } + + public boolean getImportDbKeysOnly() + { + return importDbKeysOnly; + } + + public boolean getInfrastructure() + { + return infrastructure; + } + + public String getContext() + { + return context; + } + + public String getKeyPrefixesToKeep() + { + return keyPrefixesToKeep; + } + + public String getTargetFile() + { + return translateTarget; + } + + public String[] getVerifyLanguages() + { + return verifyLanguages.split( ";" ); + } + + public boolean isShowDb() + { + return true; + } + + public int getWidth() + { + return width; + } + + public int getHeight() + { + return height; + } + } +} Added: trunk/equanda-maven-plugin/src/site/site.xml =================================================================== --- trunk/equanda-maven-plugin/src/site/site.xml (rev 0) +++ trunk/equanda-maven-plugin/src/site/site.xml 2007-08-17 13:33:03 UTC (rev 31) @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project name="equanda-maven-plugin"> + <body> + <menu name="equanda-maven-plugin"> + <item name="Introduction" href="index.html"/> + <item name="Generate" href="generate.html"/> + <item name="Translate" href="translate.html"/> + </menu> + </body> +</project> \ No newline at end of file Added: trunk/equanda-maven-plugin/src/site/wiki/generate.wiki =================================================================== --- trunk/equanda-maven-plugin/src/site/wiki/generate.wiki (rev 0) +++ trunk/equanda-maven-plugin/src/site/wiki/generate.wiki 2007-08-17 13:33:03 UTC (rev 31) @@ -0,0 +1,30 @@ +h1. Generate plugin + +The generate plugin should be used to generate the sources based on the [object model description|../om.html]. + +It is for example used in the core module of the application, and there used as follows +{code} + <build> + ... + <plugins> + ... + <plugin> + <groupId>org.equanda</groupId> + <artifactId>equanda-maven-plugin</artifactId> + <configuration> + <sourceDirectory>${basedir}/../src/main/om</sourceDirectory> + <template>ejb3,import,login</template> + </configuration> + <executions> + <execution> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + </plugin> + ... + </plugins> + ... + </build> +{code} Added: trunk/equanda-maven-plugin/src/site/wiki/index.wiki =================================================================== --- trunk/equanda-maven-plugin/src/site/wiki/index.wiki (rev 0) +++ trunk/equanda-maven-plugin/src/site/wiki/index.wiki 2007-08-17 13:33:03 UTC (rev 31) @@ -0,0 +1,6 @@ +h1. equanda maven plugin + +The equanda-maven-plugin module contains several maven targets which can be used to handle some tasks which are important in the compilation and/or maintenance of the application. + +- [generate|generate.html] plugin +- [translate|translate.html] plugin Added: trunk/equanda-maven-plugin/src/site/wiki/translate.wiki =================================================================== --- trunk/equanda-maven-plugin/src/site/wiki/translate.wiki (rev 0) +++ trunk/equanda-maven-plugin/src/site/wiki/translate.wiki 2007-08-17 13:33:03 UTC (rev 31) @@ -0,0 +1,41 @@ +h1. translate plugin + +To allow easy entering of the translation string for the application, with aid about strings which are not yet translated etc, you can use the translation plugin. + +For this to work, shou should edit your .m2/settings.xml file to assure the following bit is included. +{code} + ... + <pluginGroups> + ... + <pluginGroup>org.equanda</pluginGroup> + ... + </pluginGroups> + ... +{code} + +In the pom for the core module, you should add the following (probably merging with the existing equanda-maven-plugin configuration). +{code} + <build> + ... + <plugins> + ... + <plugin> + <groupId>org.equanda</groupId> + <artifactId>equanda-maven-plugin</artifactId> + <configuration> + <sourceDirectory>${basedir}/../src/main/om</sourceDirectory> + <translateTarget>${basedir}/src/main/resources/translations.txt</translateTarget> + <verifyLanguages>en;nl</verifyLanguages> + </configuration> + </plugin> + ... + </plugins> + ... + </build> +{code} +You may want to change the configuration settings, specifically _verifyLanguages_ as this contains the languages for which translations are needed. + +You can now start the translation tool uwing the following maven command. +{code} +mvn equanda:translate +{code} Modified: trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/Configuration.java =================================================================== --- trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/Configuration.java 2007-08-17 11:52:06 UTC (rev 30) +++ trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/Configuration.java 2007-08-17 13:33:03 UTC (rev 31) @@ -26,175 +26,22 @@ import org.equanda.util.INIFile; -import java.io.File; - /** * Configuration settings for the TranslationsEditor tool * * @author Florin */ -public class Configuration +public interface Configuration { - public static final String INI_SECTION_UNI_D = "equanda"; - public static final String INI_SECTION_UNI_D_KEY_APPDIR = "appdir"; - public static final String INI_SECTION_UNI_D_KEY_DEFINITION = "definition"; - public static final String INI_SECTION_UNI_D_KEY_IMPORT_DB_KEYS_ONLY = "import-db-keys-only"; - public static final String INI_SECTION_UNI_D_KEY_INFRASTRUCTURE = "infrastructure"; - public static final String INI_SECTION_UNI_D_KEY_CONTEXT = "context"; - public static final String INI_SECTION_UNI_D_KEY_KEY_PREFIXES_TO_KEEP = "key-prefixes-to-keep"; - - public static final String INI_SECTION_CONFIG = "config"; - public static final String INI_SECTION_CONFIG_KEY_TARGET_FILE = "target-file"; - public static final String INI_SECTION_CONFIG_KEY_VERIFY_LANGUAGES = "verify-languages"; - public static final String INI_SECTION_CONFIG_KEY_SHOW_DB = "show-db"; - - public static final String INI_SECTION_GUI = "gui"; - public static final String INI_SECTION_GUI_KEY_WIDTH = "width"; - public static final String INI_SECTION_GUI_KEY_HEIGHT = "height"; - - private String definition; - private String appdir; - private boolean importDbKeysOnly; - private boolean infrastructure; - private String context; - private String keyPrefixesToKeep; - - private String targetFile; - private String[] verifyLanguages; - private boolean showDb; - - private int width; - private int height; - - public Configuration( String iniFilePath ) - throws Exception - { - INIFile ini; - ini = new INIFile( iniFilePath ); - if ( ini.isEmpty() ) throw new RuntimeException( "Ini file is empty or missing !!! file = " + iniFilePath ); - - appdir = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_APPDIR ); - definition = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_DEFINITION ); - String importDbKeysOnlyStr = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_IMPORT_DB_KEYS_ONLY ); - String infrastructureStr = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_INFRASTRUCTURE ); - context = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_CONTEXT ); - keyPrefixesToKeep = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_KEY_PREFIXES_TO_KEEP ); - - targetFile = ini.getValue( INI_SECTION_CONFIG, INI_SECTION_CONFIG_KEY_TARGET_FILE ); - String verifyLanguagesStr = ini.getValue( INI_SECTION_CONFIG, INI_SECTION_CONFIG_KEY_VERIFY_LANGUAGES ); - String showDbStr = ini.getValue( INI_SECTION_CONFIG, INI_SECTION_CONFIG_KEY_SHOW_DB ); - - String widthStr = ini.getValue( INI_SECTION_GUI, INI_SECTION_GUI_KEY_WIDTH ); - String heightStr = ini.getValue( INI_SECTION_GUI, INI_SECTION_GUI_KEY_HEIGHT ); - - showDb = true; - if ( showDbStr != null ) - { - showDb = Boolean.parseBoolean( showDbStr ); - } - - if ( showDb ) - { - if ( appdir == null ) - { - throw new RuntimeException( "Config setting equanda.appdir cannot be null!" ); - } - if ( definition == null ) - { - throw new RuntimeException( "Config setting equanda.definition cannot be null!" ); - } - if ( importDbKeysOnlyStr == null ) - { - throw new RuntimeException( "Config setting equanda.import-db-keys-only cannot be null!" ); - } - if ( infrastructureStr == null ) - { - throw new RuntimeException( "Config setting equanda.infrastructure cannot be null!" ); - } - if ( context == null ) - { - throw new RuntimeException( "Config setting equanda.context cannot be null!" ); - } - } - if ( targetFile == null ) - { - throw new RuntimeException( "Config setting config.targetFile cannot be null!" ); - } - if ( verifyLanguagesStr == null ) - { - throw new RuntimeException( - "Config setting config.verifyLanguages is missing, all languages will be checked!" ); - } - if ( widthStr == null ) - { - throw new RuntimeException( "Config setting gui.width cannot be null!" ); - } - if ( heightStr == null ) - { - throw new RuntimeException( "Config setting gui.height cannot be null!" ); - } - width = Integer.parseInt( widthStr ); - height = Integer.parseInt( heightStr ); - importDbKeysOnly = Boolean.parseBoolean( importDbKeysOnlyStr ); - infrastructure = Boolean.parseBoolean( infrastructureStr ); - if ( verifyLanguagesStr != null ) - { - verifyLanguages = verifyLanguagesStr.split( ";" ); - } - } - - public String getDefinition() - { - return definition; - } - - public String getAppdir() - { - return appdir; - } - - public boolean getImportDbKeysOnly() - { - return importDbKeysOnly; - } - - public boolean getInfrastructure() - { - return infrastructure; - } - - public String getContext() - { - return context; - } - - public String getKeyPrefixesToKeep() - { - return keyPrefixesToKeep; - } - - public String getTargetFile() - { - return targetFile; - } - - public String[] getVerifyLanguages() - { - return verifyLanguages; - } - - public boolean isShowDb() - { - return showDb; - } - - public int getWidth() - { - return width; - } - - public int getHeight() - { - return height; - } -} + String getDefinition(); + String getAppdir(); + public boolean getImportDbKeysOnly(); + public boolean getInfrastructure(); + public String getContext(); + public String getKeyPrefixesToKeep(); + public String getTargetFile(); + public String[] getVerifyLanguages(); + public boolean isShowDb(); + public int getWidth(); + public int getHeight(); +} \ No newline at end of file Added: trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/IniConfiguration.java =================================================================== --- trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/IniConfiguration.java (rev 0) +++ trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/IniConfiguration.java 2007-08-17 13:33:03 UTC (rev 31) @@ -0,0 +1,199 @@ +/** + * This file is part of the equanda project. + * + * The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF + * ANY KIND, either express or implied. See the License for the specific language governing rights and + * limitations under the License. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + */ + +package org.equanda.tool.translationsEditor; + +import org.equanda.util.INIFile; + +/** + * ... + * + * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> + */ +public class IniConfiguration + implements Configuration +{ + public static final String INI_SECTION_UNI_D = "equanda"; + public static final String INI_SECTION_UNI_D_KEY_APPDIR = "appdir"; + public static final String INI_SECTION_UNI_D_KEY_DEFINITION = "definition"; + public static final String INI_SECTION_UNI_D_KEY_IMPORT_DB_KEYS_ONLY = "import-db-keys-only"; + public static final String INI_SECTION_UNI_D_KEY_INFRASTRUCTURE = "infrastructure"; + public static final String INI_SECTION_UNI_D_KEY_CONTEXT = "context"; + public static final String INI_SECTION_UNI_D_KEY_KEY_PREFIXES_TO_KEEP = "key-prefixes-to-keep"; + + public static final String INI_SECTION_CONFIG = "config"; + public static final String INI_SECTION_CONFIG_KEY_TARGET_FILE = "target-file"; + public static final String INI_SECTION_CONFIG_KEY_VERIFY_LANGUAGES = "verify-languages"; + public static final String INI_SECTION_CONFIG_KEY_SHOW_DB = "show-db"; + + public static final String INI_SECTION_GUI = "gui"; + public static final String INI_SECTION_GUI_KEY_WIDTH = "width"; + public static final String INI_SECTION_GUI_KEY_HEIGHT = "height"; + + private String definition; + private String appdir; + private boolean importDbKeysOnly; + private boolean infrastructure; + private String context; + private String keyPrefixesToKeep; + + private String targetFile; + private String[] verifyLanguages; + private boolean showDb; + + private int width; + private int height; + + public IniConfiguration( String iniFilePath ) + throws Exception + { + INIFile ini; + ini = new INIFile( iniFilePath ); + if ( ini.isEmpty() ) throw new RuntimeException( "Ini file is empty or missing !!! file = " + iniFilePath ); + + appdir = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_APPDIR ); + definition = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_DEFINITION ); + String importDbKeysOnlyStr = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_IMPORT_DB_KEYS_ONLY ); + String infrastructureStr = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_INFRASTRUCTURE ); + context = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_CONTEXT ); + keyPrefixesToKeep = ini.getValue( INI_SECTION_UNI_D, INI_SECTION_UNI_D_KEY_KEY_PREFIXES_TO_KEEP ); + + targetFile = ini.getValue( INI_SECTION_CONFIG, INI_SECTION_CONFIG_KEY_TARGET_FILE ); + String verifyLanguagesStr = ini.getValue( INI_SECTION_CONFIG, INI_SECTION_CONFIG_KEY_VERIFY_LANGUAGES ); + String showDbStr = ini.getValue( INI_SECTION_CONFIG, INI_SECTION_CONFIG_KEY_SHOW_DB ); + + String widthStr = ini.getValue( INI_SECTION_GUI, INI_SECTION_GUI_KEY_WIDTH ); + String heightStr = ini.getValue( INI_SECTION_GUI, INI_SECTION_GUI_KEY_HEIGHT ); + + showDb = true; + if ( showDbStr != null ) + { + showDb = Boolean.parseBoolean( showDbStr ); + } + + if ( showDb ) + { + if ( appdir == null ) + { + throw new RuntimeException( "Config setting equanda.appdir cannot be null!" ); + } + if ( definition == null ) + { + throw new RuntimeException( "Config setting equanda.definition cannot be null!" ); + } + if ( importDbKeysOnlyStr == null ) + { + throw new RuntimeException( "Config setting equanda.import-db-keys-only cannot be null!" ); + } + if ( infrastructureStr == null ) + { + throw new RuntimeException( "Config setting equanda.infrastructure cannot be null!" ); + } + if ( context == null ) + { + throw new RuntimeException( "Config setting equanda.context cannot be null!" ); + } + } + if ( targetFile == null ) + { + throw new RuntimeException( "Config setting config.targetFile cannot be null!" ); + } + if ( verifyLanguagesStr == null ) + { + throw new RuntimeException( + "Config setting config.verifyLanguages is missing, all languages will be checked!" ); + } + if ( widthStr == null ) + { + throw new RuntimeException( "Config setting gui.width cannot be null!" ); + } + if ( heightStr == null ) + { + throw new RuntimeException( "Config setting gui.height cannot be null!" ); + } + width = Integer.parseInt( widthStr ); + height = Integer.parseInt( heightStr ); + importDbKeysOnly = Boolean.parseBoolean( importDbKeysOnlyStr ); + infrastructure = Boolean.parseBoolean( infrastructureStr ); + if ( verifyLanguagesStr != null ) + { + verifyLanguages = verifyLanguagesStr.split( ";" ); + } + } + + public String getDefinition() + { + return definition; + } + + public String getAppdir() + { + return appdir; + } + + public boolean getImportDbKeysOnly() + { + return importDbKeysOnly; + } + + public boolean getInfrastructure() + { + return infrastructure; + } + + public String getContext() + { + return context; + } + + public String getKeyPrefixesToKeep() + { + return keyPrefixesToKeep; + } + + public String getTargetFile() + { + return targetFile; + } + + public String[] getVerifyLanguages() + { + return verifyLanguages; + } + + public boolean isShowDb() + { + return showDb; + } + + public int getWidth() + { + return width; + } + + public int getHeight() + { + return height; + } +} Modified: trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/TranslationsEditor.java =================================================================== --- trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/TranslationsEditor.java 2007-08-17 11:52:06 UTC (rev 30) +++ trunk/equanda-tool/src/main/java/org/equanda/tool/translationsEditor/TranslationsEditor.java 2007-08-17 13:33:03 UTC (rev 31) @@ -52,7 +52,8 @@ /** * A tool to edit/import translations * - * @author Florin + * @author <a href="mailto:fl...@pa...">Florin</a> + * @author <a href="mailto:jo...@pr...">Joachim Van der Auwera</a> */ public class TranslationsEditor extends JFrame @@ -62,10 +63,10 @@ private KeyTableModel model = new KeyTableModel(); private KeyEditorPanel keyEditorPanel; private KeyTable table; - private Configuration config; private String languages[]; private ImportDialog importDialog = new ImportDialog(); private String lastTranslationSearched; + private String lastKeySearched; private OMDatabase database; public static void main( final String args[] ) @@ -82,7 +83,8 @@ { try { - new TranslationsEditor( args[ 0 ] ); + Configuration config = new IniConfiguration( args[ 0 ] ); + new TranslationsEditor( config, null ); } catch ( Exception e ) { @@ -94,18 +96,17 @@ }.start(); } - public TranslationsEditor( String iniFilePath ) + public TranslationsEditor( final Configuration config, final Object waitFor ) throws Exception { - config = new Configuration( iniFilePath ); - load(); + load( config ); Dimension frameSize = new Dimension( config.getWidth(), config.getHeight() ); //setLayout( new BorderLayout() ); //add( getButtonsPanel(), BorderLayout.NORTH ); - setJMenuBar( getTranslationsMenuBar() ); + setJMenuBar( getTranslationsMenuBar( config ) ); add( getContentPanel(), BorderLayout.CENTER ); this.setSize( frameSize ); @@ -128,7 +129,17 @@ JOptionPane.QUESTION_MESSAGE ); if ( option == JOptionPane.OK_OPTION ) { - System.exit( 0 ); + if ( waitFor == null ) + { + System.exit( 0 ); + } + else + { + synchronized ( waitFor ) + { + waitFor.notifyAll(); + } + } } else { @@ -146,7 +157,7 @@ } ); } - private JMenuBar getTranslationsMenuBar() + private JMenuBar getTranslationsMenuBar( final Configuration config ) { JMenuBar menuBar = new JMenuBar(); JMenu generalMenu = new JMenu( "General" ); @@ -176,7 +187,7 @@ { // save previous key: keyEditorPanel.save(); - importDbContent( true ); + importDbContent( config, true ); } } ); @@ -187,7 +198,7 @@ { // save previous key: keyEditorPanel.save(); - removeUnusedKeys(); + removeUnusedKeys( config ); } } ); @@ -199,7 +210,7 @@ { // save previous key: keyEditorPanel.save(); - save(); + save( config ); } } ); @@ -251,6 +262,17 @@ } ); + JMenuItem searchKeyItem = new JMenuItem( "Search key" ); + searchKeyItem.addActionListener( new ActionListener() + { + public void actionPerformed( ActionEvent e ) + { + // save previous key: + keyEditorPanel.save(); + searchKeyPart(); + } + } ); + JMenuItem searchTranslationItem = new JMenuItem( "Search in translations" ); searchTranslationItem.addActionListener( new ActionListener() { @@ -282,6 +304,8 @@ generalMenu.add( removeUnusedKeysItem ); } generalMenu.add( new JSeparator() ); + saveItem.setAccelerator( KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_S, + java.awt.Event.CTRL_MASK ) ); generalMenu.add( saveItem ); contextsMenu.add( exportContextItem ); @@ -290,7 +314,14 @@ keysMenu.add( addKeyItem ); keysMenu.add( removeKeyItem ); + searchKeyItem.setAccelerator( KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_F, + java.awt.Event.CTRL_MASK ) ); + searchMenu.add( searchKeyItem ); + searchTranslationItem.setAccelerator( KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_T, + java.awt.Event.CTRL_MASK ) ); searchMenu.add( searchTranslationItem ); + nextFaultItem.setAccelerator( KeyStroke.getKeyStroke( java.awt.event.KeyEvent.VK_N, + java.awt.Event.CTRL_MASK ) ); searchMenu.add( nextFaultItem ); menuBar.add( generalMenu ); @@ -375,6 +406,26 @@ } + private void searchKeyPart() + { + lastKeySearched = JOptionPane.showInputDialog( TranslationsEditor.this, + "Enter a key (or part of key) to be searched", + lastKeySearched ); + + if ( lastKeySearched == null || lastKeySearched.equals( "" ) ) return; + int start = table.getSelectedRow() + 1; + + for ( int i = start; i < model.getRowCount() ; i++ ) + { + Key key = model.getKeyAtIndex( i ); + if ( key.getKey().contains( lastKeySearched ) ) + { + table.changeSelection( i, 1, false, false ); + return; + } + } + } + private void gotoNextFault() { int start = table.getSelectedRow() + 1; @@ -401,7 +452,7 @@ } } - private java.util.List<String> importDbContent( boolean addToModel ) + private java.util.List<String> importDbContent( Configuration config, boolean addToModel ) { java.util.List<String> dbItems = new ArrayList<String>(); try @@ -424,56 +475,61 @@ for ( int t = 0; t < tables.getLength() ; t++ ) { OMRootTable table = (OMRootTable) tables.item( t ); - importDbKey( "table." + table.getName(), table.getName(), dbItems, addToModel ); - importDbKey( "category." + table.getCategory(), table.getCategory(), dbItems, addToModel ); + importDbKey( config, "table." + table.getName(), table.getName(), dbItems, addToModel ); + importDbKey( config, "category." + table.getCategory(), table.getCategory(), dbItems, addToModel ); for ( OMRootTable.TableType type : table.getTypes() ) { - importDbKey( "type." + table.getName() + "." + type.getName(), type.getName(), dbItems, + importDbKey( config, "type." + table.getName() + "." + type.getName(), type.getName(), dbItems, addToModel ); } for ( OMField field : table.getFields() ) { - importDbKey( "field." + table.getName() + "." + field.getName(), field.getName(), dbItems, + importDbKey( config, "field." + table.getName() + "." + field.getName(), field.getName(), dbItems, addToModel ); for ( OMChoice choice : field.getChoices() ) { if ( !choice.isFromClass() ) { - importDbKey( "choice." + table.getName() + "." + field.getName() + "." + choice.getName(), + importDbKey( config, + "choice." + table.getName() + "." + field.getName() + "." + choice.getName(), choice.getName(), dbItems, addToModel ); } } } for ( OMPage page : table.getPages() ) { - importDbKey( "page." + table.getName() + "." + page.getName(), page.getName(), dbItems, + importDbKey( config, "page." + table.getName() + "." + page.getName(), page.getName(), dbItems, addToModel ); for ( OMGroup group : page.getGroupsDeep() ) { - importDbKey( "group." + table.getName() + "." + group.getName(), group.getName(), dbItems, + importDbKey( config, "group." + table.getName() + "." + group.getName(), group.getName(), + dbItems, addToModel ); } } for ( OMSelect select : table.getSelects() ) { - importDbKey( "select." + table.getName() + "." + select.getName(), select.getName(), dbItems, + importDbKey( config, "select." + table.getName() + "." + select.getName(), select.getName(), + dbItems, addToModel ); for ( OMSelection selection : select.getSelections() ) { - importDbKey( "parameter." + table.getName() + "." + select.getName() + - "." + selection.getName(), selection.getName(), dbItems, addToModel ); + importDbKey( config, "parameter." + table.getName() + "." + select.getName() + + "." + selection.getName(), selection.getName(), dbItems, addToModel ); } } for ( OMAction action : table.getActions() ) { - importDbKey( "action." + table.getName() + "." + action.getName(), action.getName(), dbItems, + importDbKey( config, "action." + table.getName() + "." + action.getName(), action.getName(), + dbItems, addToModel ); for ( OMParameter parameter : action.getParameters() ) { - importDbKey( "param." + table.getName() + "." + action.getName() + "." + parameter.getName(), + importDbKey( config, + "param." + table.getName() + "." + action.getName() + "." + parameter.getName(), parameter.getName(), dbItems, addToModel ); } } @@ -489,7 +545,8 @@ return dbItems; } - private void importDbKey( String keyStr, String translationEn, java.util.List<String> dbItems, boolean addToModel ) + private void importDbKey( Configuration config, String keyStr, String translationEn, java.util.List<String> dbItems, + boolean addToModel ) { dbItems.add( keyStr ); if ( addToModel ) @@ -507,7 +564,7 @@ } } - private void load() + private void load( Configuration config ) throws Exception { System.out.print( "Loading translations..." ); @@ -515,19 +572,11 @@ parser.parse( new File( config.getTargetFile() ) ); languages = parser.getLanguages(); - if ( languages == null || languages.length == 0 ) - { - showError( "Invalid translations file with no languages line" ); - System.exit( 1 ); - } if ( config.getVerifyLanguages() != null ) { - model.setVerifyLanguages( config.getVerifyLanguages() ); + languages = config.getVerifyLanguages(); } - else - { - model.setVerifyLanguages( languages ); - } + model.setVerifyLanguages( languages ); for ( String language : languages ) { TreeMap<Key, Translation> mapFromParser = parser.getTranslations( language ); @@ -541,7 +590,7 @@ System.out.println( "Total: " + model.getRowCount() + " keys." ); } - private void save() + private void save( Configuration config ) { try { @@ -634,13 +683,13 @@ dialog.dispose(); } - private void removeUnusedKeys() + private void removeUnusedKeys( Configuration config ) { // save previous key: keyEditorPanel.save(); // check keys in equanda table - java.util.List<String> currentDbKeys = importDbContent( false ); + java.util.List<String> currentDbKeys = importDbContent( config, false ); int countUnused = 0; int i = 0; @@ -648,7 +697,7 @@ { Key key = model.getKeyAtIndex( i ); - if ( isKeyFromDb( key ) && !currentDbKeys.contains( key.getKey() ) ) + if ( isKeyFromDb( config, key ) && !currentDbKeys.contains( key.getKey() ) ) { model.removeKey( i ); log.info( "Removed key " + key.getKey() ); @@ -662,7 +711,7 @@ System.out.println( "Removed: " + countUnused + " keys." ); } - private boolean isKeyFromDb( Key key ) + private boolean isKeyFromDb( Configuration config, Key key ) { if ( key.getContext() == null ) return false; if ( !key.getContext().equals( config.getContext() ) ) return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |