Author: tchemit Date: 2009-07-31 01:04:45 +0200 (Fri, 31 Jul 2009) New Revision: 1649 Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/AbstractI18nProject.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/AbstractI18nProjectProvider.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProject.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectConfigurePanelUI.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectFactory.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectProvider.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProject.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProjectConfigurePanelUI.jaxx trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProjectProvider.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProject.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProjectConfigurePanelUI.jaxx trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProjectProvider.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/I18nEditorUIHandler.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/ProjectUI.jaxx trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/ProjectUIModel.java trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/tabs/PersistPanelUI.jaxx trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/tabs/SelectBundlesPanelUI.jaxx Log: make ProjectUIModel neutral from project definition Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/AbstractI18nProject.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/AbstractI18nProject.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/AbstractI18nProject.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -18,6 +18,8 @@ */ package org.nuiton.i18n.editor.project; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -43,113 +45,109 @@ */ public class AbstractI18nProject implements I18nProject { - public static final Log log = LogFactory.getLog(AbstractI18nProject.class); + public static final String NAME_PROPERTY_NAME = "name"; + public static final String URLS_PROPERTY_NAME = "urls"; + public static final String STORE_PROJECT_PROPERTY_NAME = "storeProject"; + public static final String STORE_FILE_PROPERTY_NAME = "storeFile"; public static final Locale[] EMPTY_LOCALE_ARRAY = new Locale[0]; public static final String EMPTY_STRING = ""; public static final String[] EMPTY_STRING_ARRAY = new String[0]; - /** - * le nom du projet - */ - protected final String name; - /** - * les urls des fichiers de traduction a charger - */ - protected URL[] urls; - /** - * les definitions de bundles du projet - */ + public static final Log log = LogFactory.getLog(AbstractI18nProject.class); + /** le nom du projet */ + protected String name; + /** les urls des fichiers de traduction a charger */ + protected List<URL> urls; + /** les definitions de bundles du projet */ protected I18nBundle[] i18nBundles; - /** - * le fichier où conserver le projet (si null, on ne persiste pas le projet) - */ - protected File storeFile; - /** - * un drapeau pour savoir si le modele a ete charge - */ + /** le fichier où conserver le projet (si null, on ne persiste pas le projet) */ + protected File storeFile = new File(""); + /** un drapeau pour savoir si on persiste le projet */ + protected boolean storeProject; + /** un drapeau pour savoir si le modele a ete charge */ boolean loaded; - /** - * Les locales selectionnees dans ce projet - */ - protected final List<Locale> selectedBundles; - /** - * les paquetages selectionnes dans ce projet - */ - protected final List<String> selectedPackages; - /** - * le dictionnaire des fichiers de traductions charges - */ - protected final Map<String, Properties> resources; + /** Les locales selectionnees dans ce projet */ + protected List<Locale> selectedBundles; + /** les paquetages selectionnes dans ce projet */ + protected List<String> selectedPackages; + /** le dictionnaire des fichiers de traductions charges */ + protected Map<String, Properties> resources; + /** pour propager les changements du modele */ + protected PropertyChangeSupport pcs; - protected AbstractI18nProject(String name, URL... urls) { - this.name = name; - this.urls = urls; + protected AbstractI18nProject() { this.resources = new LinkedHashMap<String, Properties>(); this.selectedBundles = new ArrayList<Locale>(); this.selectedPackages = new ArrayList<String>(); + this.pcs = new PropertyChangeSupport(this); } - /** - * @return le nom du projet - */ @Override public String getName() { return name; } - /** - * @return les paquetages du projet - */ @Override - public String[] getPackages() { - return I18nBundleFactory.getBundleNames(i18nBundles); + public List<URL> getUrls() { + return urls; } - /** - * @return les locales du projet - */ @Override - public Locale[] getBundles() { - return I18nBundleFactory.getLocales(i18nBundles); + public boolean isStoreProject() { + return storeProject; } - /** - * @return les paquetages selectionnes - */ @Override - public List<String> getSelectedPackages() { - return selectedPackages; + public File getStoreFile() { + return storeFile; } - /** - * @return les locales selectionnees - */ @Override - public List<Locale> getSelectedBundles() { - return selectedBundles; + public void setName(String name) { + String oldValue = this.name; + this.name = name; + firePropertyChange(NAME_PROPERTY_NAME, oldValue, name); } - /** - * @return les urls du projet - */ @Override - public URL[] getURLs() { - return urls; + public void setUrls(List<URL> urls) { + this.urls = urls; } @Override - public File getStoreFile() { - return storeFile; + public void setStoreProject(boolean storeProject) { + boolean oldValue = this.storeProject; + this.storeProject = storeProject; + firePropertyChange(STORE_PROJECT_PROPERTY_NAME, oldValue, storeProject); } @Override public void setStoreFile(File storeFile) { + File oldValue = this.storeFile; this.storeFile = storeFile; + firePropertyChange(STORE_FILE_PROPERTY_NAME, oldValue, storeFile); } - /** - * @return les clefs de traductions pour les packages selectionnee et les locales selectionnes - */ @Override + public String[] getPackages() { + return I18nBundleFactory.getBundleNames(i18nBundles); + } + + @Override + public Locale[] getBundles() { + return I18nBundleFactory.getLocales(i18nBundles); + } + + @Override + public List<String> getSelectedPackages() { + return selectedPackages; + } + + @Override + public List<Locale> getSelectedBundles() { + return selectedBundles; + } + + @Override public String[] getKeys() { if (!loaded) { return EMPTY_STRING_ARRAY; @@ -176,13 +174,6 @@ return r.toArray(new String[r.size()]); } - /** - * Supprime une traduction pour une clef donnee dans une langue et un paquetage donne. - * - * @param packageName le paquetage ou supprimer la clef - * @param locale la locale de la traduction - * @param key la clef de traduction - */ @Override public void deleteKey(String packageName, Locale locale, String key) { checkLoaded(); @@ -192,11 +183,6 @@ } } - /** - * @param packageName - * @param key la clef de traductions - * @return les traductions pour les packages, locales et clef selectionnees - */ @Override public Map<Locale, String> getValues(String packageName, String key) { if (!loaded) { @@ -228,12 +214,6 @@ return r; } - /** - * @param key la clef de traductions - * @param locale la locale - * @param packageName le nom du package - * @return les traductions - */ @Override public String getValue(String packageName, Locale locale, String key) { if (!loaded) { @@ -248,14 +228,6 @@ } - /** - * Ajouter une traduction dans le projet. - * - * @param packageName le paquetage ou ajouter la clef - * @param locale la locale de la traduction - * @param key la clef de traduction - * @param value la traduction - */ @Override public void addValue(String packageName, Locale locale, String key, String value) { checkLoaded(); @@ -265,14 +237,6 @@ } } - /** - * Mettre a jour une traduction dans le projet. - * - * @param packageName le paquetage ou ajouter la clef - * @param locale la locale de la traduction - * @param key la clef de traduction - * @param value la traduction - */ @Override public void updateValue(String packageName, Locale locale, String key, String value) { checkLoaded(); @@ -282,21 +246,29 @@ } } - /** - * Chargement des traductions du projet. - * - * @throws IOException - */ @Override + public void copyDefinitionTo(I18nProject project) { + // check we are on the same type of project + if (project.getClass() != getClass()) { + throw new IllegalArgumentException("copyDefinitionTo method must use same project type, but was not! (required : " + getClass() + ", but find " + project.getClass() + 3); + } + project.setName(name); + project.setUrls(urls); + project.setStoreProject(storeProject); + // always clean storeFile (could be init in project from ui, but only keep it if necessary) + project.setStoreFile(storeProject ? storeFile : null); + } + + @Override public void load() throws IOException { try { - synchronized (this.resources) { + synchronized (this) { resources.clear(); selectedBundles.clear(); selectedPackages.clear(); // detections des bundles i18n a partir des urls donnees - List<I18nBundle> tmp = I18nBundleFactory.detectBundles(urls); + List<I18nBundle> tmp = I18nBundleFactory.detectBundles(urls.toArray(new URL[urls.size()])); i18nBundles = tmp.toArray(new I18nBundle[tmp.size()]); selectedBundles.addAll(Arrays.asList(getBundles())); @@ -316,26 +288,15 @@ } } - /** - * Enregistrement des traductions du projet. - * - * @throws IOException - */ @Override public void store() throws IOException { checkLoaded(); } @Override - public void storeDefinition() throws IOException { + public void saveDefinition() throws IOException { Properties p = new Properties(); - p.setProperty("name", name); - p.setProperty("class", getClass().getName()); - StringBuilder buffer = new StringBuilder(); - for (URL u : urls) { - buffer.append(',').append(u.toString()); - } - p.setProperty("urls", buffer.substring(1)); + fillDefinition(p); FileOutputStream stream = null; try { stream = new FileOutputStream(getStoreFile()); @@ -349,6 +310,69 @@ } @Override + public void fillDefinition(Properties p) { + p.setProperty("name", name); + p.setProperty("class", getClass().getName()); + StringBuilder buffer = new StringBuilder(); + for (URL u : urls) { + buffer.append(',').append(u.toString()); + } + p.setProperty("urls", buffer.substring(1)); + } + + @Override + public String toString() { + return super.toString() + "<name: " + name + ">"; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + if (log.isDebugEnabled()) { + log.debug(this + " / " + listener); + } + pcs.addPropertyChangeListener(listener); + } + + @Override + public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + if (log.isDebugEnabled()) { + log.debug(this + " / " + propertyName + " : " + listener); + } + pcs.addPropertyChangeListener(propertyName, listener); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + if (log.isDebugEnabled()) { + log.debug(this + " / " + listener); + } + pcs.removePropertyChangeListener(listener); + } + + @Override + public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) { + if (log.isDebugEnabled()) { + log.debug(this + " / " + propertyName + " : " + listener); + } + pcs.removePropertyChangeListener(propertyName, listener); + } + + @Override + public void removePropertyChangeListeners() { + for (PropertyChangeListener l : pcs.getPropertyChangeListeners()) { + pcs.removePropertyChangeListener(l); + } + } + + @Override + public void fireAllProperties() { + firePropertyChange(NAME_PROPERTY_NAME, null, name); + firePropertyChange(URLS_PROPERTY_NAME, null, urls); + firePropertyChange(STORE_PROJECT_PROPERTY_NAME, null, storeProject); + firePropertyChange(STORE_FILE_PROPERTY_NAME, null, storeFile); + } + + @Override protected void finalize() throws Throwable { super.finalize(); i18nBundles = null; @@ -357,9 +381,8 @@ selectedPackages.clear(); } - @Override - public String toString() { - return super.toString() + "<name: " + name + ">"; + protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) { + pcs.firePropertyChange(propertyName, oldValue, newValue); } protected I18nBundle getI18nBundle(String packageName) { Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/AbstractI18nProjectProvider.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/AbstractI18nProjectProvider.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/AbstractI18nProjectProvider.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -26,6 +26,8 @@ import java.util.Map; import java.util.Map.Entry; import org.nuiton.i18n.I18n; +import org.nuiton.i18n.editor.project.impl.DirectoryI18nProject; +import org.nuiton.i18n.editor.ui.project.ProjectUIModel; /** * @@ -36,8 +38,6 @@ public abstract class AbstractI18nProjectProvider<P extends I18nProject> implements I18nProjectProvider<P> { public static final String CLASS_PARAMETER = "class"; - public static final String NAME_PARAMETER = "name"; - public static final String URLS_PARAMETER = "urls"; protected final Class<P> type; protected final String label; protected final String description; @@ -66,7 +66,6 @@ return I18n._(description); } - @Override public Map<String, Class<?>> getAuthorizedParameters() { if (authorizedParameters == null) { @@ -75,7 +74,15 @@ return authorizedParameters; } - public <T extends Object> T getParameter(Class<T> returnType, String propertyName, Map<String, Object> parameters) { + @Override + public P newProject(ProjectUIModel model) { + I18nProject project = model.getProject(); + P p = newProject(); + project.copyDefinitionTo(p); + return p; + } + + public <T extends Object> T getParameter(Class<T> returnType, String propertyName, Map<String, Object> parameters, boolean mustExist) { Map<String, Class<?>> map = getAuthorizedParameters(); // check name if (!map.containsKey(propertyName)) { @@ -92,6 +99,9 @@ return (T) e.getValue(); } } - throw new IllegalArgumentException("could not find property " + propertyName + ".\nKnown properties in :\n" + parameters.keySet()); + if (mustExist) { + throw new IllegalArgumentException("could not find property " + propertyName + ".\nKnown properties in :\n" + parameters.keySet()); + } + return null; } } Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProject.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProject.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProject.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -18,12 +18,14 @@ */ package org.nuiton.i18n.editor.project; +import java.beans.PropertyChangeListener; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Properties; /** * @@ -31,60 +33,79 @@ */ public interface I18nProject { + ///////////////////////////////////////////////////////////////////// + // definition accessor ////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////// /** * @return le nom du projet */ - public String getName(); + String getName(); /** - * @return les paquetages du projet + * @return les urls du projet */ - public String[] getPackages(); + List<URL> getUrls(); /** - * @return les locales du projet + * + * @return <code>true</code> si la definition du projet est persiste */ - public Locale[] getBundles(); + boolean isStoreProject(); /** - * @return les paquetages selectionnes + * + * @return le chemin du fichier ou persister la definition du projet + * + * Note : n'est pris en compte uniquement si {@link #isStoreProject()} est + * vrai. */ - public List<String> getSelectedPackages(); + File getStoreFile(); + ///////////////////////////////////////////////////////////////////// + // definition mutator ////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////// + void setName(String name); + + void setUrls(List<URL> urls); + + void setStoreProject(boolean storeProject); + + void setStoreFile(File storeFile); + + ///////////////////////////////////////////////////////////////////// + // runtime accessor ///////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////// /** - * @return les locales selectionnees + * @return les paquetages du projet */ - public List<Locale> getSelectedBundles(); + String[] getPackages(); /** - * @return les urls du projet + * @return les locales du projet */ - public URL[] getURLs(); + Locale[] getBundles(); - public File getStoreFile(); + /** + * @return les paquetages selectionnes + */ + List<String> getSelectedPackages(); - public void setStoreFile(File storeFile); - /** - * @return les clefs de traductions pour les packages selectionnee et les locales selectionnes + * @return les locales selectionnees */ - public String[] getKeys(); + List<Locale> getSelectedBundles(); /** - * Supprime une traduction pour une clef donnee dans une langue et un paquetage donne. - * - * @param packageName le paquetage ou supprimer la clef - * @param locale la locale de la traduction - * @param key la clef de traduction + * @return les clefs de traductions pour les packages selectionnee et les locales selectionnes */ - public void deleteKey(String packageName, Locale locale, String key); + String[] getKeys(); /** * @param packageName * @param key la clef de traductions * @return les traductions pour les packages, locales et clef selectionnees */ - public Map<Locale, String> getValues(String packageName, String key); + Map<Locale, String> getValues(String packageName, String key); /** * @param key la clef de traductions @@ -92,9 +113,25 @@ * @param packageName le nom du package * @return les traductions */ - public String getValue(String packageName, Locale locale, String key); + String getValue(String packageName, Locale locale, String key); /** + * Copy roject definition to the given project. + * + * @param project the destination project + */ + void copyDefinitionTo(I18nProject project); + + /** + * Supprime une traduction pour une clef donnee dans une langue et un paquetage donne. + * + * @param packageName le paquetage ou supprimer la clef + * @param locale la locale de la traduction + * @param key la clef de traduction + */ + void deleteKey(String packageName, Locale locale, String key); + + /** * Ajouter une traduction dans le projet. * * @param packageName le paquetage ou ajouter la clef @@ -102,7 +139,7 @@ * @param key la clef de traduction * @param value la traduction */ - public void addValue(String packageName, Locale locale, String key, String value); + void addValue(String packageName, Locale locale, String key, String value); /** * Mettre a jour une traduction dans le projet. @@ -112,21 +149,50 @@ * @param key la clef de traduction * @param value la traduction */ - public void updateValue(String packageName, Locale locale, String key, String value); + void updateValue(String packageName, Locale locale, String key, String value); /** * Chargement des traductions du projet. * * @throws IOException */ - public void load() throws IOException; + void load() throws IOException; /** * Enregistrement des traductions du projet. * * @throws IOException */ - public void store() throws IOException; + void store() throws IOException; - public void storeDefinition() throws IOException; + /** + * Sauvegarde la definition du projet. + * + * @throws IOException pour tout pb lors de la sauvegarde + */ + void saveDefinition() throws IOException; + + /** + * Remplit un dictionnaire avec les proprietes de la definition du projet. + * + * @param p le dictionnaire des proprietes de la definition du projet + */ + void fillDefinition(Properties p); + + ///////////////////////////////////////////////////////////////////// + // property change listeners //////////////////////////////////////// + ///////////////////////////////////////////////////////////////////// + void addPropertyChangeListener(PropertyChangeListener listener); + + void addPropertyChangeListener(String propertyName, PropertyChangeListener listener); + + void removePropertyChangeListener(PropertyChangeListener listener); + + void removePropertyChangeListener(String propertyName, PropertyChangeListener listener); + + void removePropertyChangeListeners(); + + void fireAllProperties(); + + } Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectConfigurePanelUI.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectConfigurePanelUI.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectConfigurePanelUI.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -24,13 +24,17 @@ /** * Le contrat a respecter pour configurer un type de projet. * + * @param <P> le type de projet + * * @author chemit */ -public interface I18nProjectConfigurePanelUI extends JAXXObject { +public interface I18nProjectConfigurePanelUI<P extends I18nProject> extends JAXXObject { /** * * @return l'instance partagee du modele de creation de projet */ ProjectUIModel getModel(); + + P getProject(); } Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectFactory.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectFactory.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectFactory.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -149,7 +149,7 @@ * @return le provideur pour le le type de projet donne, ou <code>null</code> * si aucun provideur ne prend en charge ce type de projet. */ - protected static <P extends I18nProject> I18nProjectProvider<P> getProvider(Class<P> projectClass) { + public static <P extends I18nProject> I18nProjectProvider<P> getProvider(Class<P> projectClass) { for (I18nProjectProvider<?> p : getProviders()) { if (p.getType() == projectClass) { Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectProvider.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectProvider.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/I18nProjectProvider.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -57,6 +57,7 @@ */ Map<String, Class<?>> getAuthorizedParameters(); + P newProject(); /** * * @param params les paramètres pour instancier le projet @@ -93,7 +94,7 @@ * * @return le type de l'ui pour configurer ce type de projet */ - Class<? extends I18nProjectConfigurePanelUI> getUIClass(); + Class<? extends I18nProjectConfigurePanelUI<?>> getUIClass(); /** * Valide dans l'ui de creation de projet la partie specifique a Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProject.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProject.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProject.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -18,8 +18,10 @@ */ package org.nuiton.i18n.editor.project.impl; +import java.io.File; import org.nuiton.i18n.editor.project.AbstractI18nProject; -import java.net.URL; +import java.util.Properties; +import org.nuiton.i18n.editor.project.I18nProject; /** * @@ -27,7 +29,39 @@ */ public class DirectoryI18nProject extends AbstractI18nProject { - public DirectoryI18nProject(String name, URL[] urls) { - super(name, urls); + public static final String DIRECTORY_SOURCE_PROPERTY_NAME = "directorySource"; + /** la source pour un projet de type directory */ + protected File directorySource = new File(""); + + public DirectoryI18nProject() { + super(); } + + public File getDirectorySource() { + return directorySource; + } + + public void setDirectorySource(File directorySource) { + File oldValue = this.directorySource; + this.directorySource = directorySource; + firePropertyChange(DIRECTORY_SOURCE_PROPERTY_NAME, oldValue, directorySource); + } + + @Override + public void fillDefinition(Properties p) { + super.fillDefinition(p); + p.setProperty(DIRECTORY_SOURCE_PROPERTY_NAME, directorySource.getAbsolutePath()); + } + + @Override + public void copyDefinitionTo(I18nProject project) { + super.copyDefinitionTo(project); + ((DirectoryI18nProject) project).setDirectorySource(directorySource); + } + + @Override + public void fireAllProperties() { + super.fireAllProperties(); + firePropertyChange(DIRECTORY_SOURCE_PROPERTY_NAME, null, directorySource); + } } Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProjectConfigurePanelUI.jaxx =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProjectConfigurePanelUI.jaxx 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProjectConfigurePanelUI.jaxx 2009-07-30 23:04:45 UTC (rev 1649) @@ -22,12 +22,13 @@ --> <Table fill='both' constraints='DirectoryI18nProject.class.getName()' - implements='org.nuiton.i18n.editor.project.I18nProjectConfigurePanelUI'> + implements='org.nuiton.i18n.editor.project.I18nProjectConfigurePanelUI<DirectoryI18nProject>'> <script><![CDATA[ import jaxx.runtime.SwingUtil; import org.nuiton.i18n.editor.*; +import org.nuiton.i18n.editor.project.I18nProject; import org.nuiton.i18n.editor.project.impl.*; import org.nuiton.i18n.editor.ui.project.*; @@ -35,18 +36,30 @@ protected ProjectUIModel model = getContextValue(ProjectUIModel.class); +protected DirectoryI18nProject project = model.getProject(DirectoryI18nProject.class); + @Override public ProjectUIModel getModel() { return model; } +@Override +public DirectoryI18nProject getProject() { + return project; + //I18nProject p = model.getProject(); + //if (p instanceof DirectoryI18nProject) { + // return (DirectoryI18nProject) p; + //} + //return null; +} + public void chooseDirectorySource() { File f = model.chooseDirectory( this, _("i18neditor.title.choose.directory.source"), _("i18neditor.action.choose.directory.source.description"), - model.getJarSource()); - model.setDirectorySource(f); + getProject().getDirectorySource()); + getProject().setDirectorySource(f); } ]]> </script> @@ -58,8 +71,8 @@ </row> <row> <cell columns="2"> - <JTextField text='{SwingUtil.getStringValue(model.getProjectName())}' - onKeyReleased='model.setProjectName(((JTextField)event.getSource()).getText())'/> + <JTextField text='{SwingUtil.getStringValue(getProject().getName())}' + onKeyReleased='getProject().setName(((JTextField)event.getSource()).getText())'/> </cell> </row> <row> @@ -70,8 +83,8 @@ <row> <cell weightx='1' fill="both"> <JTextField id="directorySourceFile" - text='{SwingUtil.getStringValue(model.getDirectorySource()+"")}' - onKeyReleased='model.setDirectorySource(new File(((JTextField)event.getSource()).getText()))'/> + text='{SwingUtil.getStringValue(getProject().getDirectorySource()+"")}' + onKeyReleased='getProject().setDirectorySource(new File(((JTextField)event.getSource()).getText()))'/> </cell> <cell anchor="east"> <JButton actionIcon="fileChooser" Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProjectProvider.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProjectProvider.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/DirectoryI18nProjectProvider.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -18,6 +18,7 @@ */ package org.nuiton.i18n.editor.project.impl; +import java.io.File; import java.io.IOException; import org.nuiton.i18n.editor.project.AbstractI18nProjectProvider; import java.net.URL; @@ -44,62 +45,80 @@ @Override protected Map<String, Class<?>> initAuthorizedParameters() { Map<String, Class<?>> result = new TreeMap<String, Class<?>>(); - result.put(NAME_PARAMETER, String.class); - result.put(URLS_PARAMETER, URL[].class); + result.put(DirectoryI18nProject.NAME_PROPERTY_NAME, String.class); + result.put(DirectoryI18nProject.URLS_PROPERTY_NAME, List.class); + result.put(DirectoryI18nProject.DIRECTORY_SOURCE_PROPERTY_NAME, File.class); return result; } @Override - public DirectoryI18nProject newProject(Map<String, Object> params) { - String name = getParameter(String.class, NAME_PARAMETER, params); - URL[] urls = getParameter(URL[].class, URLS_PARAMETER, params); - return new DirectoryI18nProject(name, urls); + public DirectoryI18nProject newProject() { + return new DirectoryI18nProject(); } @Override - public DirectoryI18nProject newProject(ProjectUIModel model) { - DirectoryI18nProject p = new DirectoryI18nProject(model.getProjectName(), model.getSelectedBundles().toArray(new URL[model.getSelectedBundles().size()])); - if (model.isStoreProject()) { - p.setStoreFile(model.getStoreFile()); - } + public DirectoryI18nProject newProject(Map<String, Object> params) { + // mandatory parameters + String name = getParameter(String.class, DirectoryI18nProject.NAME_PROPERTY_NAME, params, true); + List<URL> urls = getParameter(List.class, DirectoryI18nProject.URLS_PROPERTY_NAME, params, true); + + // optional parameters + File directorySource = getParameter(File.class, DirectoryI18nProject.DIRECTORY_SOURCE_PROPERTY_NAME, params, false); + + DirectoryI18nProject p = new DirectoryI18nProject(); + p.setName(name); + p.setUrls(urls); + p.setDirectorySource(directorySource); return p; } @Override public DirectoryI18nProject newProject(Properties properties) { Map<String, Object> params = new TreeMap<String, Object>(); - params.put(NAME_PARAMETER, properties.getProperty(NAME_PARAMETER)); - String tmp = properties.getProperty(URLS_PARAMETER); + String tmp; + + // name + tmp = properties.getProperty(DirectoryI18nProject.NAME_PROPERTY_NAME); + params.put(DirectoryI18nProject.NAME_PROPERTY_NAME, tmp); + + // urls + tmp = properties.getProperty(DirectoryI18nProject.URLS_PROPERTY_NAME); String[] urlsStr = tmp.split(","); List<URL> urls = new ArrayList<URL>(); for (String u : urlsStr) { URL url = ConverterUtil.convert(URL.class, u); urls.add(url); } + params.put(DirectoryI18nProject.URLS_PROPERTY_NAME, urls); - params.put(URLS_PARAMETER, urls.toArray(new URL[urls.size()])); - + // directorySource + tmp = properties.getProperty(DirectoryI18nProject.DIRECTORY_SOURCE_PROPERTY_NAME); + File directorySource = new File(tmp); + params.put(DirectoryI18nProject.DIRECTORY_SOURCE_PROPERTY_NAME, directorySource); DirectoryI18nProject p = newProject(params); return p; } @Override public List<URL> detectBundles(ProjectUIModel model) throws IOException { + //TODO throw new UnsupportedOperationException("Not supported yet."); } @Override public boolean validateUIModel(ProjectUIModel model) { - return model.getDirectorySource() != null && model.getDirectorySource().exists() && model.getProjectName() != null && !model.getProjectName().isEmpty(); + DirectoryI18nProject project = (DirectoryI18nProject) model.getProject(); + return project.getDirectorySource() != null && project.getDirectorySource().exists() && project.getName() != null && !project.getName().isEmpty(); } @Override public boolean validateDefinition(Properties properties) { + //TODO throw new UnsupportedOperationException("Not supported yet."); } @Override - public Class<? extends I18nProjectConfigurePanelUI> getUIClass() { + public Class<? extends I18nProjectConfigurePanelUI<?>> getUIClass() { return DirectoryI18nProjectConfigurePanelUI.class; } } Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProject.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProject.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProject.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -18,18 +18,69 @@ */ package org.nuiton.i18n.editor.project.impl; +import java.io.File; +import java.util.Properties; import org.nuiton.i18n.editor.project.AbstractI18nProject; -import java.net.URL; +import org.nuiton.i18n.editor.project.I18nProject; /** * * @author chemit */ -public class JarI18nProject extends AbstractI18nProject{ +public class JarI18nProject extends AbstractI18nProject { - public JarI18nProject(String name, URL[] urls) { - super(name, urls); + public static final String JAR_SOURCE_PROPERTY_NAME = "jarSource"; + public static final String UNIQUE_JAR_DEFINITION_PROPERTY_NAME = "uniqueJarDefinition"; + /** la source pour un projet de type jar */ + protected File jarSource = new File(""); + /** + * un drapeau (pour les projets de type jar) pour savoir si on utilise le + * système i18n avec nom unique. + */ + protected boolean uniqueJarDefinition; + + public JarI18nProject() { + super(); } + public File getJarSource() { + return jarSource; + } + public void setJarSource(File jarSource) { + File oldValue = this.jarSource; + this.jarSource = jarSource; + firePropertyChange(JAR_SOURCE_PROPERTY_NAME, oldValue, jarSource); + } + + public boolean isUniqueJarDefinition() { + return uniqueJarDefinition; + } + + public void setUniqueJarDefinition(boolean uniqueJarDefinition) { + boolean oldValue = this.uniqueJarDefinition; + this.uniqueJarDefinition = uniqueJarDefinition; + firePropertyChange(UNIQUE_JAR_DEFINITION_PROPERTY_NAME, oldValue, uniqueJarDefinition); + } + + @Override + public void fillDefinition(Properties p) { + super.fillDefinition(p); + p.setProperty(JAR_SOURCE_PROPERTY_NAME, jarSource.getAbsolutePath()); + p.setProperty(UNIQUE_JAR_DEFINITION_PROPERTY_NAME, Boolean.valueOf(uniqueJarDefinition).toString()); + } + + @Override + public void copyDefinitionTo(I18nProject project) { + super.copyDefinitionTo(project); + ((JarI18nProject) project).setJarSource(jarSource); + ((JarI18nProject) project).setUniqueJarDefinition(uniqueJarDefinition); + } + + @Override + public void fireAllProperties() { + super.fireAllProperties(); + firePropertyChange(JAR_SOURCE_PROPERTY_NAME, null, jarSource); + firePropertyChange(UNIQUE_JAR_DEFINITION_PROPERTY_NAME, null, uniqueJarDefinition); + } } Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProjectConfigurePanelUI.jaxx =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProjectConfigurePanelUI.jaxx 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProjectConfigurePanelUI.jaxx 2009-07-30 23:04:45 UTC (rev 1649) @@ -22,12 +22,13 @@ --> <Table fill='both' constraints='JarI18nProject.class.getName()' - implements='org.nuiton.i18n.editor.project.I18nProjectConfigurePanelUI'> + implements='org.nuiton.i18n.editor.project.I18nProjectConfigurePanelUI<JarI18nProject>'> <script><![CDATA[ import jaxx.runtime.SwingUtil; import org.nuiton.i18n.editor.*; +import org.nuiton.i18n.editor.project.I18nProject; import org.nuiton.i18n.editor.project.impl.*; import org.nuiton.i18n.editor.ui.project.*; @@ -35,20 +36,32 @@ protected ProjectUIModel model = getContextValue(ProjectUIModel.class); +protected JarI18nProject project = model.getProject(JarI18nProject.class); + @Override public ProjectUIModel getModel() { return model; } +@Override +public JarI18nProject getProject() { + return project; + //I18nProject p = model.getProject(); + //if (p instanceof JarI18nProject) { + // return (JarI18nProject) p; + //} + //return null; +} + public void chooseJarSource() { File f = model.chooseFile ( this, _("i18neditor.title.choose.jar.source"), _("i18neditor.action.choose.jar.source"), - model.getJarSource(), + getProject().getJarSource(), "^.+\\.jar$", _("i18neditor.action.choose.jar.source.description")); - model.setJarSource(f); + getProject().setJarSource(f); } ]]> </script> @@ -60,8 +73,8 @@ </row> <row> <cell columns="2"> - <JTextField text='{SwingUtil.getStringValue(model.getProjectName())}' - onKeyReleased='model.setProjectName(((JTextField)event.getSource()).getText())'/> + <JTextField text='{SwingUtil.getStringValue(getProject().getName())}' + onKeyReleased='getProject().setName(((JTextField)event.getSource()).getText())'/> </cell> </row> <row> @@ -72,8 +85,8 @@ <row> <cell weightx='1' fill="both"> <JTextField id="jarSourceFile" - text='{SwingUtil.getStringValue(model.getJarSource()+"")}' - onKeyReleased='model.setJarSource(new File(((JTextField)event.getSource()).getText()))'/> + text='{SwingUtil.getStringValue(getProject().getJarSource()+"")}' + onKeyReleased='getProject().setJarSource(new File(((JTextField)event.getSource()).getText()))'/> </cell> <cell anchor="east"> <JButton actionIcon="fileChooser" @@ -85,8 +98,8 @@ <JCheckBox id='uniqueJarDefinition' text='i18neditor.createproject.uniqueJarDefinition' toolTipText='i18neditor.createproject.uniqueJarDefinition.tip' - selected='{model.isUniqueJarDefinition()}' - onItemStateChanged='model.setUniqueJarDefinition(event.getStateChange() == ItemEvent.SELECTED)'/> + selected='{getProject().isUniqueJarDefinition()}' + onItemStateChanged='getProject().setUniqueJarDefinition(event.getStateChange() == ItemEvent.SELECTED)'/> </cell> </row> </Table> Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProjectProvider.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProjectProvider.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/project/impl/JarI18nProjectProvider.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -18,6 +18,7 @@ */ package org.nuiton.i18n.editor.project.impl; +import java.io.File; import java.io.IOException; import org.nuiton.i18n.editor.project.AbstractI18nProjectProvider; import java.net.URL; @@ -54,43 +55,65 @@ @Override protected Map<String, Class<?>> initAuthorizedParameters() { Map<String, Class<?>> result = new TreeMap<String, Class<?>>(); - result.put(NAME_PARAMETER, String.class); - result.put(URLS_PARAMETER, URL[].class); + result.put(JarI18nProject.NAME_PROPERTY_NAME, String.class); + result.put(JarI18nProject.URLS_PROPERTY_NAME, List.class); + result.put(JarI18nProject.JAR_SOURCE_PROPERTY_NAME, File.class); + result.put(JarI18nProject.UNIQUE_JAR_DEFINITION_PROPERTY_NAME, Boolean.class); return result; } @Override - public JarI18nProject newProject(Map<String, Object> params) { - String name = getParameter(String.class, NAME_PARAMETER, params); - URL[] urls = getParameter(URL[].class, URLS_PARAMETER, params); - JarI18nProject p = new JarI18nProject(name, urls); - return p; + public JarI18nProject newProject() { + return new JarI18nProject(); } @Override - public JarI18nProject newProject(ProjectUIModel model) { - JarI18nProject p = new JarI18nProject(model.getProjectName(), - model.getSelectedBundles().toArray(new URL[model.getSelectedBundles().size()])); - if (model.isStoreProject()) { - p.setStoreFile(model.getStoreFile()); - } + public JarI18nProject newProject(Map<String, Object> params) { + + // mandatory parameters + String name = getParameter(String.class, JarI18nProject.NAME_PROPERTY_NAME, params, true); + List<URL> urls = getParameter(List.class, JarI18nProject.URLS_PROPERTY_NAME, params, true); + + // optional parameters + File jarSource = getParameter(File.class, JarI18nProject.JAR_SOURCE_PROPERTY_NAME, params, false); + Boolean uniqueJarDefinition = getParameter(Boolean.class, JarI18nProject.UNIQUE_JAR_DEFINITION_PROPERTY_NAME, params, false); + JarI18nProject p = new JarI18nProject(); + p.setName(name); + p.setUrls(urls); + p.setJarSource(jarSource); + p.setUniqueJarDefinition(uniqueJarDefinition != null && uniqueJarDefinition); return p; } @Override public JarI18nProject newProject(Properties properties) { Map<String, Object> params = new TreeMap<String, Object>(); - params.put(NAME_PARAMETER, properties.getProperty(NAME_PARAMETER)); - String tmp = properties.getProperty(URLS_PARAMETER); + String tmp; + + // name + tmp = properties.getProperty(JarI18nProject.NAME_PROPERTY_NAME); + params.put(JarI18nProject.NAME_PROPERTY_NAME, tmp); + + // urls + tmp = properties.getProperty(JarI18nProject.URLS_PROPERTY_NAME); String[] urlsStr = tmp.split(","); List<URL> urls = new ArrayList<URL>(); for (String u : urlsStr) { URL url = ConverterUtil.convert(URL.class, u); urls.add(url); } + params.put(JarI18nProject.URLS_PROPERTY_NAME, urls); - params.put(URLS_PARAMETER, urls.toArray(new URL[urls.size()])); + // jarSource + tmp = properties.getProperty(JarI18nProject.JAR_SOURCE_PROPERTY_NAME); + File jarSource = new File(tmp); + params.put(JarI18nProject.JAR_SOURCE_PROPERTY_NAME, jarSource); + // uniqueJarDefinition + tmp = properties.getProperty(JarI18nProject.UNIQUE_JAR_DEFINITION_PROPERTY_NAME, "false"); + Boolean uniqueJarDefinition = Boolean.valueOf(tmp); + params.put(JarI18nProject.UNIQUE_JAR_DEFINITION_PROPERTY_NAME, uniqueJarDefinition); + JarI18nProject p = newProject(params); return p; } @@ -98,10 +121,11 @@ @Override public List<URL> detectBundles(ProjectUIModel model) throws IOException { List<URL> urls = new ArrayList<URL>(); - URL source = model.getJarSource().toURI().toURL(); + JarI18nProject project = (JarI18nProject) model.getProject(); + URL source = project.getJarSource().toURI().toURL(); URLClassLoader loader = new URLClassLoader(new URL[]{source}); log.info("jar source : " + source); - if (model.isUniqueJarDefinition()) { + if (project.isUniqueJarDefinition()) { // on recherche l'unique bundle dans META-INF/ List<URL> defs = Resource.getURLs("META-INF/.*-i18n-definition\\.properties", loader); log.info("detected unique bundle definition " + defs); @@ -125,7 +149,8 @@ @Override public boolean validateUIModel(ProjectUIModel model) { - return model.getJarSource() != null && model.getJarSource().exists() && model.getProjectName() != null && !model.getProjectName().isEmpty(); + JarI18nProject project = (JarI18nProject) model.getProject(); + return project.getJarSource() != null && project.getJarSource().exists() && project.getName() != null && !project.getName().isEmpty(); } @Override @@ -135,14 +160,14 @@ if (!properties.containsKey(CLASS_PARAMETER)) { throw new IllegalStateException("could not find property " + CLASS_PARAMETER); } - if (!properties.containsKey(NAME_PARAMETER)) { - throw new IllegalStateException("could not find property " + NAME_PARAMETER); + if (!properties.containsKey(JarI18nProject.NAME_PROPERTY_NAME)) { + throw new IllegalStateException("could not find property " + JarI18nProject.NAME_PROPERTY_NAME); } - if (!properties.containsKey(URLS_PARAMETER)) { - throw new IllegalStateException("could not find property " + URLS_PARAMETER); + if (!properties.containsKey(JarI18nProject.URLS_PROPERTY_NAME)) { + throw new IllegalStateException("could not find property " + JarI18nProject.URLS_PROPERTY_NAME); } // verifie que les urls existent - String tmp = properties.getProperty(URLS_PARAMETER); + String tmp = properties.getProperty(JarI18nProject.URLS_PROPERTY_NAME); String[] urlsStr = tmp.split(","); for (String u : urlsStr) { int lastIndex = u.lastIndexOf("/"); @@ -155,7 +180,7 @@ } @Override - public Class<? extends I18nProjectConfigurePanelUI> getUIClass() { + public Class<? extends I18nProjectConfigurePanelUI<?>> getUIClass() { return JarI18nProjectConfigurePanelUI.class; } } Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/I18nEditorUIHandler.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/I18nEditorUIHandler.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/I18nEditorUIHandler.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -98,7 +98,6 @@ openProjectUI(ui, project); } - return ui; } @@ -492,7 +491,7 @@ I18nEditorConfig.Option.CONFIG_FILE, I18nEditorConfig.Option.PROJECTS_DIRECTORY, I18nEditorConfig.Option.TMP_DIRECTORY); - + model.addCategory( n_("i18neditor.config.category.ui"), n_("i18neditor.config.category.ui.description"), @@ -624,13 +623,13 @@ ProjectUIModel model = ui.getModel(); I18nProject project = null; - I18nProjectProvider<? extends I18nProject> type = model.getType(); + I18nProjectProvider<?> type = model.getType(); project = I18nProjectFactory.newProject(type.getType(), model); - rootContext.getContextValue(I18nEditorConfig.class).getProjects().add(model.getProjectName()); + rootContext.getContextValue(I18nEditorConfig.class).getProjects().add(project.getName()); try { - if (model.isStoreProject()) { + if (project.isStoreProject()) { // on enregistre le projet - project.storeDefinition(); + project.saveDefinition(); } project.load(); I18nEditorContext.PROJECT_DEF.setContextValue(rootContext, project); Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/ProjectUI.jaxx =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/ProjectUI.jaxx 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/ProjectUI.jaxx 2009-07-30 23:04:45 UTC (rev 1649) @@ -145,13 +145,14 @@ SELECT_BUNDLES.getBundlesModel().setUrls(model.detectBundles()); return; } - if (newStep == ProjectStep.PERSIST) { + //if (newStep == ProjectStep.PERSIST) { // positionnement de fichier de sauvegarde - if (model.isStoreProject()) { - model.setStoreFile(new java.io.File(config.getProjectsDirectory(), model.getProjectName() + ".i18nproject")); - } - return; - } + //TODO depend du statut du model (create or update) + //if (model.getProject().isStoreProject()) { + // model.getProject().setStoreFile(new java.io.File(config.getProjectsDirectory(), model.getProject().getName() + ".i18nproject")); + //} + //return; + //} } @Override Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/ProjectUIModel.java =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/ProjectUIModel.java 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/ProjectUIModel.java 2009-07-30 23:04:45 UTC (rev 1649) @@ -19,18 +19,24 @@ package org.nuiton.i18n.editor.ui.project; import java.awt.Component; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.Set; import jaxx.runtime.JAXXContext; import jaxx.runtime.swing.wizard.WizardModel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.i18n.editor.I18nEditorConfig; import org.nuiton.i18n.editor.project.I18nProject; +import org.nuiton.i18n.editor.project.I18nProjectFactory; import org.nuiton.i18n.editor.project.I18nProjectProvider; import org.nuiton.util.FileUtil; @@ -43,63 +49,53 @@ /** to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(ProjectUIModel.class); - public static final String PROJECT_NAME_PROPERTY_NAME = "projectName"; public static final String TYPE_PROPERTY_NAME = "type"; - public static final String JAR_SOURCE_PROPERTY_NAME = "jarSource"; - public static final String DIRECTORY_SOURCE_PROPERTY_NAME = "directorySource"; - public static final String SELECTED_BUNDLES_PROPERTY_NAME = "selectedBundles"; - public static final String UNIQUE_JAR_DEFINITION_PROPERTY_NAME = "uniqueJarDefinition"; - public static final String STORE_FILE_PROPERTY_NAME = "storeFile"; - public static final String STORE_PROJECT_PROPERTY_NAME = "storeProject"; + public static final String PROJECT_PROPERTY_NAME = "project"; +// public static final String PROJECT_NAME_PROPERTY_NAME = "projectName"; +// public static final String JAR_SOURCE_PROPERTY_NAME = "jarSource"; +// public static final String DIRECTORY_SOURCE_PROPERTY_NAME = "directorySource"; +// public static final String SELECTED_BUNDLES_PROPERTY_NAME = "selectedBundles"; +// public static final String UNIQUE_JAR_DEFINITION_PROPERTY_NAME = "uniqueJarDefinition"; +// public static final String STORE_FILE_PROPERTY_NAME = "storeFile"; +// public static final String STORE_PROJECT_PROPERTY_NAME = "storeProject"; public static final String VALID_PROPERTY_NAME = "valid"; - /** - * Le type de projet - */ - protected I18nProjectProvider<? extends I18nProject> type; - /** - * le nom du projet - */ - protected String projectName; - /** - * la source pour un projet de type jar - */ - protected File jarSource = new File(""); - /** - * la source pour un projet de type directory - */ - protected File directorySource = new File(""); - /** - * un drapeau (pour les projets de type jar) pour savoir si on utilise le - * système i18n avec nom unique. - */ - protected boolean uniqueJarDefinition; - /** - * la configuration de l'application - */ + /** le dictionnaire des differents projects possible indexes par leur provideur */ + protected Map<I18nProjectProvider<?>, I18nProject> projects; + /** Le provideur du projet en cours d'edition */ + protected I18nProjectProvider<?> type; + /** le projet en cours d'edition */ + protected I18nProject project; + /** la configuration de l'application */ protected I18nEditorConfig config; - /** - * le fichier ou persister le projet (si null pas persiste) - */ - protected File storeFile = new File(""); - /** - * un drapeau pour savoir si on persiste le projet - */ - protected boolean storeProject = true; - /** - * les etapes a exclure - */ - protected List<ProjectStep> excludeSteps; - /** - * les bundles selectionnes - */ - protected List<URL> selectedBundles = new ArrayList<URL>(); + /** un drapeau pour savoir si on est en mode creation ou pas */ + protected boolean create; public ProjectUIModel() { super(ProjectStep.class, ProjectStep.CHOOSE_PROJECT_TYPE, ProjectStep.CONFIGURE_PROJECT, ProjectStep.SELECT_BUNDLES, + ProjectStep.PERSIST, ProjectStep.RESUME); + this.projects = new HashMap<I18nProjectProvider<?>, I18nProject>(); + // init map of different types of projects + Set<I18nProjectProvider<?>> providers = I18nProjectFactory.getProviders(); + for (I18nProjectProvider<?> p : providers) { + I18nProject newProject = p.newProject(); + this.projects.put(p, newProject); + // the model listens every modification of each project + // and at each time revalidate the model + newProject.addPropertyChangeListener(new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + validate(); + } + }); + } + if (!providers.isEmpty()) { + setType(providers.iterator().next()); + } } /** @@ -109,20 +105,21 @@ */ public void init(JAXXContext context) { - ProjectUIModel incomingModel = context.getContextValue(ProjectUIModel.class, "incoming"); - config = context.getContextValue(I18nEditorConfig.class); - if (incomingModel != null) { + //TODO instead of seeking an ui model, must seek fro an incoming project... + I18nProject incomingProject = context.getContextValue(I18nProject.class, "incoming"); + setCreate(incomingProject==null); + + if (incomingProject != null) { + if (log.isDebugEnabled()) { - log.debug("from a incoming model " + incomingModel); + log.debug("from a incoming project " + incomingProject); } - - // on initialie a partir d'un autre modèle - incomingModel.copyTo(this); - - return; + I18nProjectProvider<?> provider = I18nProjectFactory.getProvider(incomingProject.getClass()); + setType(provider); + incomingProject.copyDefinitionTo(project); } } @@ -130,12 +127,12 @@ public void start() { super.start(); firePropertyChange(TYPE_PROPERTY_NAME, null, type); - firePropertyChange(PROJECT_NAME_PROPERTY_NAME, null, projectName); - firePropertyChange(JAR_SOURCE_PROPERTY_NAME, null, jarSource); - firePropertyChange(DIRECTORY_SOURCE_PROPERTY_NAME, null, directorySource); - firePropertyChange(SELECTED_BUNDLES_PROPERTY_NAME, null, selectedBundles); - firePropertyChange(STORE_PROJECT_PROPERTY_NAME, null, storeProject); - firePropertyChange(STORE_FILE_PROPERTY_NAME, null, storeFile); + firePropertyChange(PROJECT_PROPERTY_NAME, null, project); +// if (type != null && project != null) { +// // ask to provider to fire every thing on the project ? +// //TODO no! the project fire will do it in each specicialized project's ui +// project.fireAllProperties(); +// } } @Override @@ -169,112 +166,62 @@ validate = type.validateUIModel(this); break; case SELECT_BUNDLES: - validate = !selectedBundles.isEmpty(); + validate = !project.getUrls().isEmpty(); break; case PERSIST: - validate = !storeProject || (storeFile != null && !storeFile.exists()); + boolean storeProject = project.isStoreProject(); + if (storeProject) { + File storeFile = project.getStoreFile(); + if (create) { + validate = storeFile != null && !storeFile.exists(); + } else { + validate = storeFile != null && storeFile.exists(); + } + } break; case RESUME: - validate = true; +// validate = true; break; } } return validate; } - public I18nProjectProvider<? extends I18nProject> getType() { + public I18nProjectProvider<?> getType() { return type; } - public String getProjectName() { - return projectName; + public I18nProject getProject() { + return project; } - public File getDirectorySource() { - return directorySource; + public <T extends I18nProject> T getProject(Class<T> projectClass) { + I18nProjectProvider<T> projectType = I18nProjectFactory.getProvider(projectClass); + if (!projects.containsKey(projectType)) { + throw new IllegalArgumentException(projectType + " is not a registred type"); + } + return (T) projects.get(projectType); } - public File getJarSource() { - return jarSource; + public boolean isCreate() { + return create; } - public List<URL> getSelectedBundles() { - return selectedBundles; + public void setCreate(boolean create) { + this.create = create; } - public boolean isUniqueJarDefinition() { - return uniqueJarDefinition; - } - - public boolean isStoreProject() { - return storeProject; - } - - public File getStoreFile() { - return storeFile; - } - - public void setType(I18nProjectProvider<? extends I18nProject> type) { - I18nProjectProvider<?> oldValue = this.type; + public void setType(I18nProjectProvider<?> type) { + I18nProjectProvider<?> oldType = this.type; this.type = type; - firePropertyChange(TYPE_PROPERTY_NAME, oldValue, type); - if (oldValue != type) { - updateUniverse(); - } + firePropertyChange(TYPE_PROPERTY_NAME, oldType, type); + I18nProject oldProject = this.project; + I18nProject newProject = projects.get(type); + this.project = newProject; + firePropertyChange(PROJECT_PROPERTY_NAME, oldProject, newProject); validate(); } - public void setDirectorySource(File directorySource) { - File oldValue = this.directorySource; - this.directorySource = directorySource; - firePropertyChange(DIRECTORY_SOURCE_PROPERTY_NAME, oldValue, directorySource); - validate(); - } - - public void setJarSource(File jarSource) { - File oldValue = this.jarSource; - this.jarSource = jarSource; - firePropertyChange(JAR_SOURCE_PROPERTY_NAME, oldValue, jarSource); - validate(); - } - - public void setProjectName(String projectName) { - String oldValue = this.projectName; - this.projectName = projectName; - firePropertyChange(PROJECT_NAME_PROPERTY_NAME, oldValue, projectName); - validate(); - } - - public void setUniqueJarDefinition(boolean uniqueJarDefinition) { - boolean oldValue = this.uniqueJarDefinition; - this.uniqueJarDefinition = uniqueJarDefinition; - firePropertyChange(UNIQUE_JAR_DEFINITION_PROPERTY_NAME, oldValue, uniqueJarDefinition); - validate(); - } - - public void setSelectedBundles(List<URL> selectedBundles) { -// List<URL> oldValues = this.selectedBundles; - this.selectedBundles = selectedBundles; - firePropertyChange(SELECTED_BUNDLES_PROPERTY_NAME, null, selectedBundles); - validate(); - } - - public void setStoreProject(boolean storeProject) { - boolean oldValue = this.storeProject; - this.storeProject = storeProject; - firePropertyChange(STORE_PROJECT_PROPERTY_NAME, oldValue, storeProject); - } - - public void setStoreFile(File storeFile) { - File oldValue = this.storeFile; - this.storeFile = storeFile; - firePropertyChange(STORE_FILE_PROPERTY_NAME, oldValue, storeFile); - } - - public void setExcludeSteps(List<ProjectStep> excludeSteps) { - this.excludeSteps = excludeSteps; - } - /** * Choisir un fichier via un sélecteur graphique de fichiers. * @@ -355,10 +302,4 @@ } return urls; } - - protected void copyTo(ProjectUIModel dst) { - dst.setType(getType()); - dst.setJarSource(getJarSource()); - dst.setDirectorySource(getDirectorySource()); - } } Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/tabs/PersistPanelUI.jaxx =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/tabs/PersistPanelUI.jaxx 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/tabs/PersistPanelUI.jaxx 2009-07-30 23:04:45 UTC (rev 1649) @@ -27,10 +27,28 @@ import jaxx.runtime.SwingUtil; import org.nuiton.i18n.editor.*; +import org.nuiton.i18n.editor.project.I18nProject; +import org.nuiton.i18n.editor.project.AbstractI18nProject; import org.nuiton.i18n.editor.ui.project.*; import java.io.File; +protected final I18nEditorConfig config = getContextValue(I18nEditorConfig.class); + +protected final PropertyChangeListener storeProjectPropertyChangeListener = new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + Boolean oldValue = (Boolean) evt.getOldValue(); + Boolean newValue = (Boolean) evt.getNewValue(); + if (newValue != null && newValue) { + if (getProject().getStoreFile() == null || getProject().getStoreFile().getParentFile() == null) { + getProject().setStoreFile(new File(config.getProjectsDirectory(), model.getProject().getName() + ".i18nproject")); + } + } + } +}; + public void chooseProjectDirectory() { File f = model.chooseDirectory ( this, @@ -40,15 +58,62 @@ changeDirectory(f); } +public I18nProject getProject() { + return model.getProject(); +} + protected void changeDirectory(File f) { - model.setStoreFile(new File(f, model.getProjectName() + ".i18nproject")); + getProject().setStoreFile(new File(f, getProject().getName() + ".i18nproject")); } void $afterCompleteSetup() { if (getStep()!=null) { setDescriptionText(_(getStep().getDescription())); } + model.addPropertyChangeListener(ProjectUIModel.PROJECT_PROPERTY_NAME, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + I18nProject oldProject = (I18nProject) evt.getOldValue(); + if (oldProject!=null) { + oldProject.removePropertyChangeListener(AbstractI18nProject.STORE_PROJECT_PROPERTY_NAME, storeProjectPropertyChangeListener); + } + I18nProject newProject = (I18nProject) evt.getNewValue(); + if (newProject!=null) { + newProject.addPropertyChangeListener(AbstractI18nProject.STORE_PROJECT_PROPERTY_NAME, storeProjectPropertyChangeListener); + } + if (log.isDebugEnabled()) { + log.debug("update binding for changed project " + newProject); + } + SwingUtil.applyDataBinding(PersistPanelUI.this, + "storeProject.selected", + "storeFilePanel.visible", + "directoryText.text", + "storeFilePath.text"); + } + }); } + +@Override +public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) { + for (PropertyChangeListener l : getPropertyChangeListeners(propertyName)) { + if (l == listener) { + // already registred listener + if (log.isDebugEnabled()) { + log.debug("already registred listener for property " + propertyName + " : " + listener); + } + return; + } + } + super.addPropertyChangeListener(propertyName, listener); +} + +protected String getStoreDirectory(File storeFile) { + if (storeFile == null || storeFile.getParentFile() == null) { + return ""; + } + return storeFile.getParentFile().getAbsolutePath(); +} ]]> </script> @@ -57,14 +122,16 @@ <JPanel constraints='BorderLayout.NORTH' layout='{new BorderLayout()}' border='{BorderFactory.createTitledBorder("")}'> - <JCheckBox constraints='BorderLayout.CENTER' + <JCheckBox id='storeProject' + constraints='BorderLayout.CENTER' text='i18neditor.createproject.doPersist' - selected='{model.isStoreProject()}' - onStateChanged='getModel().setStoreProject(((JCheckBox)event.getSource()).isSelected())'/> + selected='{getProject().isStoreProject()}' + onStateChanged='getProject().setStoreProject(((JCheckBox)event.getSource()).isSelected())'/> </JPanel> - <Table constraints='BorderLayout.CENTER' - visible='{model.isStoreProject()}'> + <Table id='storeFilePanel' + constraints='BorderLayout.CENTER' + visible='{getProject().isStoreProject()}'> <row> <cell weightx='1' fill="both"> <Table fill='both'> @@ -76,26 +143,27 @@ <row> <cell weightx='1' fill="horizontal"> <JTextField id='directoryText' - text='{model.getStoreFile().getParent()+ ""}' - visible='{model.isStoreProject()}' + text='{getStoreDirectory(getProject().getStoreFile())}' onKeyReleased='changeDirectory(new File(((JTextField)event.getSource()).getText()))'/> + <!--visible='{model.getProject().isStoreProject()}'--> </cell> <cell anchor="east"> <JButton actionIcon='fileChooser' - visible='{model.isStoreProject()}' onActionPerformed="chooseProjectDirectory()"/> + <!--visible='{model.getProject().isStoreProject()}'--> </cell> </row> <row> <cell columns='2'> - <JLabel text='i18neditor.createproject.storeProject.path' - visible='{model.isStoreProject()}'/> + <JLabel text='i18neditor.createproject.storeProject.path'/> + <!--visible='{model.getProject().isStoreProject()}'/>--> </cell> </row> <row> <cell columns='2'> - <JLabel text='{model.getStoreFile() + ""}' - visible='{model.isStoreProject()}'/> + <JLabel id='storeFilePath' + text='{getProject().getStoreFile() + ""}'/> + <!--visible='{model.getProject().isStoreProject()}'/>--> </cell> </row> </Table> Modified: trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/tabs/SelectBundlesPanelUI.jaxx =================================================================== --- trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/tabs/SelectBundlesPanelUI.jaxx 2009-07-27 20:29:29 UTC (rev 1648) +++ trunk/nuiton-i18n-editor/src/main/java/org/nuiton/i18n/editor/ui/project/tabs/SelectBundlesPanelUI.jaxx 2009-07-30 23:04:45 UTC (rev 1649) @@ -38,9 +38,8 @@ ]]> </script> - <!-- le modèles des activités dont on a pu calculé un point gps --> <SelectBundlesTableModel id='bundlesModel' - onTableChanged='model.setSelectedBundles(bundlesModel.getUrls())'/> + onTableChanged='model.getProject().setUrls(bundlesModel.getUrls())'/> <Table id='content' constraints='BorderLayout.CENTER' fill='both' weightx='1' weighty='1'> <row>