From: <had...@us...> - 2008-10-13 17:18:26
|
Revision: 4056 http://fudaa.svn.sourceforge.net/fudaa/?rev=4056&view=rev Author: hadouxad Date: 2008-10-13 17:18:22 +0000 (Mon, 13 Oct 2008) Log Message: ----------- - Refactorisation des .close dans les finally - G?\195?\169rer la liste des noms des nodes dans un fichier a part (couples Id/nom tr?\195?\168s clair et facilement modifiable par un non informaticien) tous les noms de tous les nodes de tous les layout sont dans le meme fichier pour simplifier la recherche - Sauvegarde/chargement des variables user (modif des methodes savein de trpostuservar...) - Gestion des l?\195?\169gendes des graphes ok! recr?\195?\169e les bonens legendes avec els bonens modifs et bonens dimensions -G?\195?\169rer les ?\195?\169crasements de donn?\195?\169es Modified Paths: -------------- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/courbe/EGGraphePersist.java branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/graphe/EbliWidgetCreatorLegende.java branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/persist/EbliWidgetSerializeXml.java branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostUserVariableSaver.java branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/TrPostPersistenceManager.java Modified: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/courbe/EGGraphePersist.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/courbe/EGGraphePersist.java 2008-10-13 08:15:09 UTC (rev 4055) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/courbe/EGGraphePersist.java 2008-10-13 17:18:22 UTC (rev 4056) @@ -94,8 +94,11 @@ * Retourne la liste persistante des fichiers * @return */ - List<EGCourbePersist> getPersitantCurvesList(){ - return new XmlArrayList( new FileStreamStrategy(getDirectoryCurves())); + List<EGCourbePersist> getPersitantCurvesList(boolean init){ + List<EGCourbePersist> listPersitante=new XmlArrayList(new FileStreamStrategy(getDirectoryCurves())); + if(init) + clearDatas(listPersitante); + return listPersitante; } @@ -103,7 +106,11 @@ * Methode qui nettoie le contenu des datas */ private void clearDatas(List<EGCourbePersist> list ){ - CtuluRemoveContentDirectory.contentDirectoryRemover(getDirectoryCurves()); + //CtuluRemoveContentDirectory.contentDirectoryRemover(getDirectoryCurves()); + if(list==null) + return; + while(list.size()!=0) + list.remove(0); } @@ -122,8 +129,8 @@ if(fichierCourbes.mkdir() || fichierCourbes.isDirectory() ){ //StreamStrategy strategy = new FileStreamStrategy(fichierCourbes); // creates the list of curves: - List<EGCourbePersist> list = new ArrayList<EGCourbePersist>(); - clearDatas(list); + List<EGCourbePersist> listPersitante = getPersitantCurvesList(true); + List<EGGroupPersist> listeGroupePersistance=new ArrayList<EGGroupPersist>(grapheTopersist.getModel().getNbEGObject()); int nbEgObjects=grapheTopersist.getModel().getNbEGObject(); for(int i=0;i<nbEgObjects;i++){ @@ -134,17 +141,17 @@ for(int k=0;k<groupe.getEGChilds().length;k++){ if(groupe.getEGChilds()[k] instanceof EGCourbeChild){ //-- ajout de la courbe persitante dans un fichier avec pour groupee le i eme - list.add(new EGCourbePersist((EGCourbeChild) groupe.getEGChilds()[k],i)); + listPersitante.add(new EGCourbePersist((EGCourbeChild) groupe.getEGChilds()[k],i)); } } }else if(objet instanceof EGCourbeChild){ //le groupe d appartenance est -1 - list.add(new EGCourbePersist((EGCourbeChild) objet,-1)); + listPersitante.add(new EGCourbePersist((EGCourbeChild) objet,-1)); } } - List<EGCourbePersist> listPersitante = getPersitantCurvesList(); - listPersitante.addAll(list); + //List<EGCourbePersist> listPersitante = getPersitantCurvesList(); + //listPersitante.addAll(list); //--on enregistre des infos bidons pour l'utilisateur --// String nbCurves="Nombre courbes: "+grapheTopersist.getModel().getCourbes().length; out.writeObject(nbCurves); @@ -229,7 +236,7 @@ } //-- Etape 4: lecture des courbes --// // get the persitant list of curves: - List<EGCourbePersist> listeCourbesPersistantes = getPersitantCurvesList(); + List<EGCourbePersist> listeCourbesPersistantes = getPersitantCurvesList(false); for(EGCourbePersist cbPersist:listeCourbesPersistantes){ EGGroup container=model.getGroup(cbPersist.Idgroup); EGCourbeChild newCurve=cbPersist.generateCourbe(container); Modified: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/graphe/EbliWidgetCreatorLegende.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/graphe/EbliWidgetCreatorLegende.java 2008-10-13 08:15:09 UTC (rev 4055) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/graphe/EbliWidgetCreatorLegende.java 2008-10-13 17:18:22 UTC (rev 4056) @@ -98,9 +98,9 @@ //-- recuperation du node graphe--// EbliNode nodeGraphe=((EbliScene) parameters.get("scene")).findByWidgetId(idPossessor_); - if(nodeGraphe!=null && nodeGraphe.getCreator() instanceof EbliWidgetControllerGraphe){ + if(nodeGraphe!=null && nodeGraphe.getCreator() instanceof EbliWidgetCreatorGraphe){ //-- on recupere le graphe --// - g=((EbliWidgetControllerGraphe)nodeGraphe.getCreator()).getGraphe(); + g=((EbliWidgetCreatorGraphe)nodeGraphe.getCreator()).getGraphe(); } else g=new EGGraphe(new EGGrapheTreeModel()); Modified: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/persist/EbliWidgetSerializeXml.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/persist/EbliWidgetSerializeXml.java 2008-10-13 08:15:09 UTC (rev 4055) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/persist/EbliWidgetSerializeXml.java 2008-10-13 17:18:22 UTC (rev 4056) @@ -6,8 +6,6 @@ import java.awt.Point; import java.util.Map; -import javax.swing.UIManager; - import org.fudaa.ctulu.CtuluLibGenerator; import org.fudaa.ebli.trace.TraceLigneModel; import org.fudaa.ebli.visuallibrary.EbliNode; @@ -18,9 +16,6 @@ import org.fudaa.ebli.visuallibrary.EbliWidgetGroup; import org.fudaa.ebli.visuallibrary.creator.EbliWidgetCreator; import org.fudaa.ebli.visuallibrary.creator.EbliWidgetCreatorClassLoader; -import org.fudaa.ebli.visuallibrary.creator.EbliWidgetCreatorShape; -import org.netbeans.api.visual.widget.Widget; -import org.w3c.dom.Element; /** * Classe utilisation pour la serialization des donn\xE9es widget @@ -29,8 +24,19 @@ */ public class EbliWidgetSerializeXml { + public static class CoupleNomId { + public String id; + public String nom; + + public CoupleNomId(String _nom, String _id) { + super(); + nom = _nom; + id = _id; + } + + + } - /** * Important: l'id de la widget pour avoir des references . */ @@ -150,7 +156,7 @@ */ public EbliNode generateWidgetInScene(Map parameters, EbliScene scene) throws InstantiationException, IllegalAccessException, ClassNotFoundException{ EbliNode newNode=new EbliNodeDefault(); - newNode.setTitle(title); + newNode.setTitle((String) parameters.get("nodeName")); newNode.setPreferedLocation(new Point(x,y)); if(width>0 && height>0) newNode.setPreferedSize(new Dimension(width,height)); Modified: branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostUserVariableSaver.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostUserVariableSaver.java 2008-10-13 08:15:09 UTC (rev 4055) +++ branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostUserVariableSaver.java 2008-10-13 17:18:22 UTC (rev 4056) @@ -164,6 +164,71 @@ _db.commit(); } + /** + * Sauvegarde toutes les variabels du projet dans un objet TrPostUserVariableSaver + * @param _src + * @param _prog + * @return + */ + public static TrPostUserVariableSaver saveIn(final TrPostSourceAbstract _src,final ProgressionInterface _prog) { + if ( _src == null) { + return null; + } + + final TrPostUserVariableSaver save = new TrPostUserVariableSaver(); + save.g_ = _src.getGravity().getValue(); + + if (_src.varUserCreateData_ != null) { + final Map map = new HashMap(_src.varUserCreateData_); + // on enleve les variables import\xE9es + final Set varToRemove = new HashSet(); + for (final Iterator it = map.entrySet().iterator(); it.hasNext();) { + final Map.Entry e = (Map.Entry) it.next(); + final TrPostDataCreated created = (TrPostDataCreated) e.getValue(); + final H2dVariableType var = (H2dVariableTypeCreated) e.getKey(); + // pas de sauvegarde possible ou non basee sur une expression + if (!created.isExpr() && created.createSaver() == null) { + varToRemove.add(var); + varToRemove.addAll(TrPostDataCreatedExpr.getAllVarDependingOn(var, _src)); + } + } + if (Fu.DEBUG && FuLog.isDebug()) { + FuLog.debug("vars enlevees\n" + CtuluLibString.arrayToString(varToRemove.toArray())); + } + map.keySet().removeAll(varToRemove); + final Map exprVar = new HashMap(map.size()); + final Map otherVar = new HashMap(map.size()); + for (final Iterator it = map.entrySet().iterator(); it.hasNext();) { + final Map.Entry e = (Map.Entry) it.next(); + final TrPostDataCreated data = ((TrPostDataCreated) e.getValue()); + if (data.isExpr()) { + exprVar.put(e.getKey(), data); + } else { + otherVar.put(e.getKey(), data); + } + } + + save.varCreated_ = new H2dVariableTypeCreated[exprVar.size()]; + save.expr_ = new String[exprVar.size()]; + int idx = 0; + for (final Iterator it = exprVar.entrySet().iterator(); it.hasNext();) { + final Map.Entry e = (Map.Entry) it.next(); + save.varCreated_[idx] = (H2dVariableTypeCreated) e.getKey(); + save.expr_[idx++] = ((TrPostDataCreatedExpr) e.getValue()).getFormule(); + } + save.varCreatedSimple_ = new H2dVariableTypeCreated[otherVar.size()]; + save.saver_ = new TrPostDataCreatedSaver[otherVar.size()]; + for (final Iterator it = otherVar.entrySet().iterator(); it.hasNext();) { + final Map.Entry e = (Map.Entry) it.next(); + save.varCreatedSimple_[idx] = (H2dVariableTypeCreated) e.getKey(); + save.saver_[idx++] = ((TrPostDataCreated) e.getValue()).createSaver(); + } + + } + return save; + } + + public static void fillWithForbidden(final Collection _var, final Set _forbiddenName, final Set _forbiddenShort) { for (final Iterator iter = _var.iterator(); iter.hasNext();) { final H2dVariableType element = (H2dVariableType) iter.next(); Modified: branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/TrPostPersistenceManager.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/TrPostPersistenceManager.java 2008-10-13 08:15:09 UTC (rev 4055) +++ branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/TrPostPersistenceManager.java 2008-10-13 17:18:22 UTC (rev 4056) @@ -3,7 +3,7 @@ import java.awt.Dimension; import java.awt.Point; import java.io.File; -import java.io.FileOutputStream; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -20,20 +20,18 @@ import javax.swing.JFileChooser; import javax.swing.JInternalFrame; -import org.fudaa.ctulu.CtuluUI; import org.fudaa.ctulu.ProgressionInterface; import org.fudaa.ctulu.gui.CtuluFileChooser; import org.fudaa.ctulu.gui.CtuluLibSwing; +import org.fudaa.ebli.courbe.EGCourbePersist; import org.fudaa.ebli.ressource.EbliResource; import org.fudaa.ebli.visuallibrary.EbliNode; import org.fudaa.ebli.visuallibrary.EbliScene; import org.fudaa.ebli.visuallibrary.EbliWidgetGroup; - import org.fudaa.ebli.visuallibrary.actions.EbliWidgetGroupAction; -import org.fudaa.ebli.visuallibrary.graphe.EbliWidgetCreatorGraphe; import org.fudaa.ebli.visuallibrary.persist.EbliSceneSerializeXml; import org.fudaa.ebli.visuallibrary.persist.EbliWidgetSerializeXml; -import org.fudaa.ebli.visuallibrary.persist.ManagerWidgetPersist; +import org.fudaa.ebli.visuallibrary.persist.EbliWidgetSerializeXml.CoupleNomId; import org.fudaa.fudaa.tr.common.TrLib; import org.fudaa.fudaa.tr.common.TrResource; import org.fudaa.fudaa.tr.post.TrPostCommonImplementation; @@ -41,15 +39,15 @@ import org.fudaa.fudaa.tr.post.TrPostMultiSourceActivator; import org.fudaa.fudaa.tr.post.TrPostProjet; import org.fudaa.fudaa.tr.post.TrPostSource; +import org.fudaa.fudaa.tr.post.TrPostSourceAbstract; +import org.fudaa.fudaa.tr.post.TrPostUserVariableSaver; import org.netbeans.api.visual.widget.Widget; -import org.w3c.dom.Document; -import org.w3c.dom.Element; import com.memoire.fu.FuLog; -import com.sun.org.apache.xml.internal.serialize.OutputFormat; -import com.sun.org.apache.xml.internal.serialize.XMLSerializer; import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.io.xml.DomDriver; +import com.thoughtworks.xstream.persistence.FileStreamStrategy; +import com.thoughtworks.xstream.persistence.XmlArrayList; /** * Manager qui se charge de donner les noms standart des balises, @@ -62,606 +60,875 @@ public class TrPostPersistenceManager { - /** - * Utilis\xE9 pour l'extension de tous les fichiers, repertoire et ficheirs - * inclus. - */ - public final static String DEFAULT_EXTENSION = ".POST"; - /** - * Peut etre modifi\xE9 par l'appli appelabt si l'on veut une extension - * diff\xE9rente - */ - public static String EXTENSION = DEFAULT_EXTENSION; - /** - * Fichier qui d\xE9crit tous les contenu layout sauvegard\xE9s Et noms des balises - * importantes - */ - public final static String INFOSCENE = "InfoLayout" + EXTENSION; - public final static String BALISESCENES = "LayoutList"; + /** + * Utilis\xE9 pour l'extension de tous les fichiers, repertoire et ficheirs + * inclus. + */ + public final static String DEFAULT_EXTENSION = ".POST"; + /** + * Peut etre modifi\xE9 par l'appli appelabt si l'on veut une extension + * diff\xE9rente + */ + public static String EXTENSION = DEFAULT_EXTENSION; + /** + * Fichier qui d\xE9crit tous les contenu layout sauvegard\xE9s Et noms des balises + * importantes + */ + public final static String INFOSCENE = "InfoLayout" + EXTENSION; + public final static String BALISESCENES = "LayoutList"; - /** - * Fichier qui d\xE9crit int\xE9gralement le contenu d'une scene - */ - public final static String DESCRIPTORSCENE = "layout"; - public static String ATTRIBUTESCENE="LAYOUT"; + /** + * Fichier qui d\xE9crit int\xE9gralement le contenu d'une scene + */ + public final static String DESCRIPTORSCENE = "layout"; + public static String ATTRIBUTESCENE = "LAYOUT"; - /** - * Attributs pour le ficheirs des sources - */ - public final static String DESCRIPTORSOURCE = "sources" + EXTENSION; - public final static String BALISESOURCES = "SourcesList"; - public static String ATTRIBUTESOURCE="FICHIER"; + /** + * Attributs pour le ficheirs des sources + */ + public final static String DESCRIPTORSOURCE = "sources" + EXTENSION; + public final static String BALISESOURCES = "SourcesList"; + public static String ATTRIBUTESOURCE = "FICHIER"; + public final static String FileWidgetNames = "FramesNames"; + /** + * Le projet a persiter + */ + TrPostProjet trprojet_; - /** - * Le projet a persiter - */ - TrPostProjet trprojet_; + /** + * Nom du projet. Creation du projet sous un repertoire nomProjet.EXTENSION + */ - /** - * Nom du projet. Creation du projet sous un repertoire nomProjet.EXTENSION - */ + ProgressionInterface prog_; + File projet_; + TrPostCommonImplementation ui_; - ProgressionInterface prog_; - File projet_; - TrPostCommonImplementation ui_; + public TrPostPersistenceManager(TrPostProjet projet) { + super(); + trprojet_ = projet; + ui_ = projet.impl_; + prog_ = ui_.getMainProgression(); + } - public TrPostPersistenceManager(TrPostProjet projet) { - super(); - trprojet_=projet; - ui_ = projet.impl_; - prog_ = ui_.getMainProgression(); - - } + public void progression(String title, int progression) { + if (prog_ == null || title == null || progression > 100) + return; + if (progression == 100) { + prog_.setProgression(0); + prog_.setDesc(""); + return; + } + prog_.setDesc(EbliResource.EBLI.getString(title)); + prog_.setProgression(progression); + } + /** + * Cr\xE9\xE9 le repertoire contenant tous les fichiers de donn\xE9es. Base pour la + * cr\xE9ation des donn\xE9es. + */ + public boolean savePersistDirectory() { + // -- creation d un chooser --// + final CtuluFileChooser fileChooser = new CtuluFileChooser(true); + fileChooser.setDialogTitle(EbliResource.EBLI.getString("S\xE9lectionnez l'emplacement de votre projet")); + fileChooser.setAcceptAllFileFilterUsed(false); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + // -- init avec les param noms projet et autre --// + if (projet_ != null) { + fileChooser.setSelectedFile(projet_); + } - public void progression(String title, int progression) { - if (prog_ == null || title == null || progression > 100) - return; - if (progression == 100) { - prog_.setProgression(0); - prog_.setDesc(""); - return; - } - prog_.setDesc(EbliResource.EBLI.getString(title)); - prog_.setProgression(progression); - } + int reponse = fileChooser.showSaveDialog(CtuluLibSwing.getFrameAncestor(ui_.getParentComponent())); + if (reponse == JFileChooser.APPROVE_OPTION) { + File conteneurProjet = fileChooser.getSelectedFile(); - /** - * Cr\xE9\xE9 le repertoire contenant tous les fichiers de donn\xE9es. Base pour la - * cr\xE9ation des donn\xE9es. - */ - public boolean savePersistDirectory() { - // -- creation d un chooser --// - final CtuluFileChooser fileChooser = new CtuluFileChooser(true); - fileChooser.setDialogTitle(EbliResource.EBLI.getString("S\xE9lectionnez l'emplacement de votre projet")); - fileChooser.setAcceptAllFileFilterUsed(false); - fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - //-- init avec les param noms projet et autre --// - if(projet_!=null){ - fileChooser.setSelectedFile(projet_); + if (projet_ == null || !projet_.equals(conteneurProjet)) + projet_ = new File(GetExtensionName(conteneurProjet.getAbsolutePath())); + // creation du repertoire global contenant toutes les donn\xE9es + if (projet_.mkdir()) { + return true; + } else - } + if (projet_.isDirectory()) { + return true; + } else { + ui_.error(EbliResource.EBLI.getString("Impossible de cr\xE9er le r\xE9pertoire")); + return false; + } - int reponse = fileChooser.showSaveDialog(CtuluLibSwing.getFrameAncestor(ui_.getParentComponent())); - if (reponse == JFileChooser.APPROVE_OPTION) { - File conteneurProjet = fileChooser.getSelectedFile(); - - if(projet_==null || !projet_.equals(conteneurProjet)) - projet_ = new File(GetExtensionName(conteneurProjet.getAbsolutePath())); - // creation du repertoire global contenant toutes les donn\xE9es - if (projet_.mkdir()) { - return true; - } else - - if(projet_.isDirectory()){ - return true; - }else - { - ui_.error(EbliResource.EBLI.getString("Impossible de cr\xE9er le r\xE9pertoire")); - return false; - } + } else + return false; + } - - } else - return false; - } + /** + * Retourne un nom avec extension + * + * @param name + * @return + */ + public String GetExtensionName(String name) { + + if (name.contains(EXTENSION)) { + return name; + } else + return name + EXTENSION; + } + + /** + * Charge le repertoire contenant tous les fichiers + * + * @return + */ + public boolean loadPersistDirectory() { + // -- creation d un chooser --// + final CtuluFileChooser fileChooser = new CtuluFileChooser(true); + fileChooser.setDialogTitle(EbliResource.EBLI.getString("S\xE9lectionnez l'emplacement de votre projet")); + fileChooser.setAcceptAllFileFilterUsed(false); + fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + + // -- init avec les param noms projet et autre --// + if (projet_ != null) { + fileChooser.setSelectedFile(projet_); + + } + + int reponse = fileChooser.showOpenDialog(CtuluLibSwing.getFrameAncestor(ui_.getParentComponent())); + if (reponse == JFileChooser.APPROVE_OPTION) { + projet_ = fileChooser.getSelectedFile(); + // creation du repertoire global contenant toutes les donn\xE9es + if (projet_.isDirectory()) { + return true; + } else { + ui_.error(EbliResource.EBLI.getString("Impossible de charger le r\xE9pertoire")); + return false; + } + } else + return false; + } + + /** + * Fichier qui cree le fichier qui indique les diff\xE9rents fichiers layout a + * lire. Cela permettra pour la lecture de proposer de charger ou non certains + * layout + * + * @return + * @throws IOException + */ + public void saveDescriptorScenes(File file) { + // -- outputstream du xstream --// + ObjectOutputStream out=null; + try { + out = getParser().createObjectOutputStream(new FileWriter(file)); - /** - * Retourne un nom avec extension - * @param name - * @return - */ - public String GetExtensionName(String name){ - - if(name.contains(EXTENSION)){ - return name; - }else - return name+EXTENSION; + // -- g\xE9n\xE9ration du xml pour la scene --// + int nbFichiersToGenrate = trprojet_.impl_.getAllLayoutFille().size(); + out.writeInt(nbFichiersToGenrate); + for (int i = 0; i < nbFichiersToGenrate; i++) { + // creation du fichier de desciption des scenes + String nomFichierLayout = projet_.getAbsolutePath() + File.separator + DESCRIPTORSCENE + (i + 1) + EXTENSION; + out.writeObject(nomFichierLayout); + } + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } + finally{ + try { + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(true); + } + } + + } - /** - * Charge le repertoire contenant tous les fichiers - * @return - */ - public boolean loadPersistDirectory() { - // -- creation d un chooser --// - final CtuluFileChooser fileChooser = new CtuluFileChooser(true); - fileChooser.setDialogTitle(EbliResource.EBLI.getString("S\xE9lectionnez l'emplacement de votre projet")); - fileChooser.setAcceptAllFileFilterUsed(false); - fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); - //-- init avec les param noms projet et autre --// - if(projet_!=null){ - fileChooser.setSelectedFile(projet_); + /** + * Lis les fichiers des layouts a utiliser. + * + * @param file + * @return + * @throws IOException + * @throws ClassNotFoundException + */ + public List<String> loadDescriptorScenes(File file) { + // -- outputstream du xstream --// + List<String> listeFiles = new ArrayList<String>(); + ObjectInputStream in=null; + try { + in = getParser().createObjectInputStream(new FileReader(file)); + + // -- g\xE9n\xE9ration du xml pour la scene --// + int nbFichiersToGenrate = in.readInt(); + + for (int i = 0; i < nbFichiersToGenrate; i++) { + // creation du fichier de desciption des scenes + String nomFichierLayout = (String) in.readObject(); + listeFiles.add(nomFichierLayout); + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(false); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(false); + } + finally{ + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(false); } - - int reponse = fileChooser.showOpenDialog(CtuluLibSwing.getFrameAncestor(ui_.getParentComponent())); - if (reponse == JFileChooser.APPROVE_OPTION) { - projet_ = fileChooser.getSelectedFile(); - // creation du repertoire global contenant toutes les donn\xE9es - if (projet_.isDirectory()) { - return true; - } else { - ui_.error(EbliResource.EBLI.getString("Impossible de charger le r\xE9pertoire")); - return false; - } - } else - return false; } + + return listeFiles; + } - /** - * Fichier qui cree le fichier qui indique les diff\xE9rents fichiers layout a - * lire. Cela permettra pour la lecture de proposer de charger ou non certains - * layout - * - * @return - * @throws IOException - */ - public void saveDescriptorScenes(File file) throws IOException { - //-- outputstream du xstream --// - ObjectOutputStream out = getParser().createObjectOutputStream(new FileWriter(file)); - //-- g\xE9n\xE9ration du xml pour la scene --// - int nbFichiersToGenrate=trprojet_.impl_.getAllLayoutFille().size(); - out.writeInt(nbFichiersToGenrate); - for(int i=0;i<nbFichiersToGenrate;i++){ - //creation du fichier de desciption des scenes - String nomFichierLayout=projet_.getAbsolutePath()+File.separator+DESCRIPTORSCENE+(i+1)+EXTENSION; - out.writeObject(nomFichierLayout); - } - out.close(); + + /** + * Recuperation de la liste des variables. + * @param init: si on veut ecraser (sauvegarder) mettre le booleen a true. + * @param path + * @return + */ + List<TrPostUserVariableSaver> getPersitantVariablesList(String path,boolean init){ + + List<TrPostUserVariableSaver> liste=new XmlArrayList( new FileStreamStrategy(new File(path))); + + if(init) + clearDatas(liste); + + return liste; } - - - /** - * Lis les fichiers des layouts a utiliser. - * @param file - * @return - * @throws IOException - * @throws ClassNotFoundException - */ - public List<String> loadDescriptorScenes(File file) throws IOException, ClassNotFoundException { - //-- outputstream du xstream --// - ObjectInputStream in = getParser().createObjectInputStream(new FileReader(file)); - //-- g\xE9n\xE9ration du xml pour la scene --// - int nbFichiersToGenrate=in.readInt(); - List<String> listeFiles=new ArrayList<String>(nbFichiersToGenrate); + private void clearDatas( List<TrPostUserVariableSaver> list ){ + //CtuluRemoveContentDirectory.contentDirectoryRemover(getDirectoryCurves()); + if(list==null) + return; + while(list.size()!=0) + list.remove(0); - for(int i=0;i<nbFichiersToGenrate;i++){ - //creation du fichier de desciption des scenes - String nomFichierLayout=(String) in.readObject(); - listeFiles.add(nomFichierLayout); - } - in.close(); - return listeFiles; } - - /** - * Methode qui g\xE9n\xE8re le fichier contenant toutes les sources ouverts. - * - * @return - * @throws IOException - */ + + /** + * Methode qui g\xE9n\xE8re le fichier contenant toutes les sources ouverts. + * + * @return + * @throws IOException + */ - public void saveSource(File file) throws IOException { - //-- outputstream du xstream --// - ObjectOutputStream out = getParser().createObjectOutputStream(new FileWriter(file)); - //-- g\xE9n\xE9ration du xml pour la scene --// + public void saveSourceAndVariables(File file, String pathVariables) { + // -- outputstream du xstream --// + ObjectOutputStream out =null; + // -- g\xE9n\xE9ration du xml pour la scene --// + try { + out = getParser().createObjectOutputStream(new FileWriter(file)); out.writeInt(trprojet_.listeSrc_.size()); - + + List<TrPostUserVariableSaver>listeVar= getPersitantVariablesList(pathVariables,true); Iterator<TrPostSource> it = trprojet_.listeSrc_.iterator(); - - while (it.hasNext()) { - File f = it.next().getFile(); - out.writeObject(f.getAbsolutePath()); - } + + while (it.hasNext()) { + TrPostSource src=it.next(); + File f = src.getFile(); + out.writeObject(f.getAbsolutePath()); + + //-- sauveagrde de la variable correspondante --// + TrPostUserVariableSaver var=TrPostUserVariableSaver.saveIn((TrPostSourceAbstract) src, null); + listeVar.add(var); + } + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(true); + }finally{ + try { out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(true); } + } + } - /** - * Methode qui ouvre tous les sources et ouvre le trpostProjets correspondants - * @param file - * @throws IOException - * @throws ClassNotFoundException - */ - public void loadSource(File file) throws IOException, ClassNotFoundException { - //-- outputstream du xstream --// - ObjectInputStream in = getParser().createObjectInputStream(new FileReader(file)); - - TrPostMultiSourceActivator multiProjectActivator=new TrPostMultiSourceActivator(trprojet_); - - //-- lecture nb sources pour les sources --// - int nbSources=in.readInt(); - for(int i=0;i<nbSources;i++) { - String path=(String) in.readObject(); - if(path!=null){ - if (trprojet_.isSourceLoaded(path)) { - trprojet_.getImpl().warn(TrLib.getString("Solution d\xE9j\xE0 charg\xE9e"), - TrLib.getString("Le fichier source existe d\xE9j\xE0 et ne peut \xEAtre ajout\xE9 au projet.")); - }else{ - File f = new File(path); - // -- tentative de chargement du source dans le multi-projet --// - - multiProjectActivator.active(f, trprojet_.impl_); - // -- notify aux observers --// - //trprojet_.notifyObservers(); - - - } - } - } - in.close(); - } + /** + * Methode qui ouvre tous les sources et ouvre le trpostProjets correspondants + * + * @param file + * @throws IOException + * @throws ClassNotFoundException + */ + public void loadSourceAndVariables(File file,String pathVariables) { + // -- outputstream du xstream --// + ObjectInputStream in=null; + try { + in = getParser().createObjectInputStream(new FileReader(file)); - - /** - * Methode qui peut etre appel\xE9e pour nettoyer le projet - */ - public void clearProject(){ - int n=0; - List<TrPostSource> liste=new ArrayList<TrPostSource>(); - for(TrPostSource src:trprojet_.listeSrc_) - liste.add(src); - for(TrPostSource src:liste) - trprojet_.removeSource(src, n); - for(JInternalFrame frame:trprojet_.getImpl().getAllInternalFrames()){ - frame.dispose(); - } - } - - /** - * Methode qui tente de sauvegarder tous les fichiers: Soit tout - * les fichiers li\xE9s entre eux sont sauvegard\xE9s, soit les fichier li\xE9s ne le - * sont pas(destruction si n\xE9cessaire) - * - * @return - */ - public boolean saveProject() { - HashMap<String, Object> parametres=new HashMap<String, Object>(); - try { - progression("Cr\xE9ation du r\xE9pertoire", 10); - // -- etape 1 creation du repertoire global --// - if (savePersistDirectory()) { - - - File file; - // -- etape 2 sauvegarde du fichier contenant tous les sources ouverts - progression("Cr\xE9ation du fichier descripteur de sources", 15); - file = new File(projet_.getAbsolutePath() + File.separator + DESCRIPTORSOURCE); - saveSource(file); - - //-- etape 2.5: creation du repertoire des graphe et calques --// - String pathGraphes=projet_.getAbsolutePath() + File.separator +"Graphes"; - try{ - new File(pathGraphes).mkdir(); - }catch(Exception e){ - //pas grave on continue - FuLog.debug("Le repertoire des graphes existe deja"); - } - String pathCalques=projet_.getAbsolutePath() + File.separator +"Calques"; - try{ - new File(pathCalques).mkdir(); - }catch(Exception e){ - //pas grave on continue - FuLog.debug("Le repertoire des calques existe deja"); - } - - // -- etape 3 sauvegarde des ebliscene unitairement --// - progression("Cr\xE9ation des fichiers layout", 20); - - //-- creation des params pour les datas --// - parametres.put("path", projet_.getAbsolutePath()); - parametres.put("pathGraphes",pathGraphes); - parametres.put("pathCalques",pathCalques); - - int cpt = 1; - List<TrPostLayoutFille> listFilles=trprojet_.impl_.getAllLayoutFille(); - for(TrPostLayoutFille fille:listFilles){ - String title = fille.getTitle(); - EbliScene scene = fille.getScene(); - if(listFilles.size()!=0) - progression("Cr\xE9ation du fichier du layout " + title, 20 + 70 / listFilles.size()); - file = new File(projet_.getAbsolutePath() + File.separator + DESCRIPTORSCENE + cpt + EXTENSION); - //-- sauvegarde du persitant --// - parametres.put("dimensions", fille.getSize()); - parametres.put("location", fille.getLocation()); - parametres.put("scene", scene); - savePersitSceneXml(scene,title,file,parametres); - cpt++; + //-- recuperation du multiSourceActivator--// + TrPostMultiSourceActivator multiProjectActivator = new TrPostMultiSourceActivator(trprojet_); - } + //-- recuperation de la listed es variables persistantes --// + List<TrPostUserVariableSaver>listeVar= getPersitantVariablesList(pathVariables,false); + + // -- lecture nb sources pour les sources --// + int nbSources = in.readInt(); + for (int i = 0; i < nbSources; i++) { + String path = (String) in.readObject(); + if (path != null) { + if (trprojet_.isSourceLoaded(path)) { + trprojet_.getImpl().warn(TrLib.getString("Solution d\xE9j\xE0 charg\xE9e"), + TrLib.getString("Le fichier source existe d\xE9j\xE0 et ne peut \xEAtre ajout\xE9 au projet.")); + } else { + File f = new File(path); + // -- tentative de chargement du source dans le multi-projet --// - // -- etape finale: sauvegarde du fichier de descriptions des layout --// - progression("Cr\xE9ation du descripteur de layout", 90); - file = new File(projet_.getAbsolutePath() + File.separator + INFOSCENE); - saveDescriptorScenes(file); - progression("", 100); - ui_.message(TrResource.getS("Sauvegarde termin\xE9e"), TrResource.getS("Sauvegarde termin\xE9e avec succ\xE8s"), false); - return true; + multiProjectActivator.active(f, trprojet_.impl_); + // -- notify aux observers --// + // trprojet_.notifyObservers(); - } - return false; - } catch (IOException ie) { - ie.printStackTrace(); - ui_.error(TrResource.getS("Erreur dans la sauvegarde du projet")); - return false; - } + } + } + } + + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(false); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(false); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(false); + }finally{ + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(false); } + } + } - /** - * Methode qui charge le projet,l'ensemble des sources et toutes les widgets dans les layouts. - * @return - */ - public boolean loadProject() { - try { - progression("Lecture du r\xE9pertoire", 10); - // -- etape 1 lecture du repertoire global --// - if (loadPersistDirectory()) { - File file; - // -- etape 2 sauvegarde du fichier contenant tous les sources ouverts - progression("Chargement du fichier descripteur de sources", 15); - file = new File(projet_.getAbsolutePath() + File.separator + DESCRIPTORSOURCE); - loadSource(file); - - // -- etape finale: sauvegarde du fichier de descriptions des layout --// - progression("Cr\xE9ation du descripteur de layout", 20); - file = new File(projet_.getAbsolutePath() + File.separator + INFOSCENE); - List<String> listeFichiers=loadDescriptorScenes(file); - // -- etape finale chargement des ebliscene unitairement --// - progression("Cr\xE9ation des fichiers layout", 30); - //-- creation des params pour les datas --// - HashMap<String, Object> parametres=new HashMap<String, Object>(); - parametres.put("path", projet_.getAbsolutePath()); + /** + * Methode qui peut etre appel\xE9e pour nettoyer le projet + */ + public void clearProject() { + int n = 0; + List<TrPostSource> liste = new ArrayList<TrPostSource>(); + for (TrPostSource src : trprojet_.listeSrc_) + liste.add(src); + for (TrPostSource src : liste) + trprojet_.removeSource(src, n); + for (JInternalFrame frame : trprojet_.getImpl().getAllInternalFrames()) { + frame.dispose(); + } + } - int cpt = 1; - - for(String fichier:listeFichiers){ - file = new File(fichier); - if(listeFichiers.size()!=0) - progression("chargement du fichier " + fichier, 30 + 70 / listeFichiers.size()); - - //-- creation de la trpostlayoutFille --// - TrPostLayoutFille postFrame=new TrPostLayoutFille(trprojet_); - //-- sauvegarde du persitant --// - try { - trprojet_.getImpl().addInternalFrame(postFrame); - loadPersitSceneXml(file,postFrame,parametres); - } catch (InstantiationException e) { - // TODO Auto-generated catch block - ui_.error(TrResource.getS("Erreur dans le chargement du layout. Chargement annul\xE9 pour le fichier ")+fichier); - } catch (IllegalAccessException e) { - // TODO Auto-generated catch block - ui_.error(TrResource.getS("Erreur dans le chargement du layout. Chargement annul\xE9 pour le fichier ")+fichier); - } + /** + * Methode qui tente de sauvegarder tous les fichiers: Soit tout les fichiers + * li\xE9s entre eux sont sauvegard\xE9s, soit les fichier li\xE9s ne le sont + * pas(destruction si n\xE9cessaire) + * + * @return + */ + public boolean saveProject() { + HashMap<String, Object> parametres = new HashMap<String, Object>(); + + + + progression("Cr\xE9ation du r\xE9pertoire", 10); + // -- etape 1 creation du repertoire global --// + if (savePersistDirectory()) { - } + // -- etape 0: creation du repertoire des graphe et calques --// + String pathGraphes = projet_.getAbsolutePath() + File.separator + "Graphes"; + try { + new File(pathGraphes).mkdir(); + } catch (Exception e) { + // pas grave on continue + FuLog.debug("Le repertoire des graphes existe deja"); + } + String pathCalques = projet_.getAbsolutePath() + File.separator + "Calques"; + try { + new File(pathCalques).mkdir(); + } catch (Exception e) { + // pas grave on continue + FuLog.debug("Le repertoire des calques existe deja"); + } + String pathVariables = projet_.getAbsolutePath() + File.separator + "Variables"; + try { + new File(pathVariables).mkdir(); + } catch (Exception e) { + // pas grave on continue + FuLog.debug("Le repertoire des variables existe deja"); + } + File file; + // -- etape 2 sauvegarde du fichier contenant tous les sources ouverts + progression("Cr\xE9ation du fichier descripteur de sources", 15); + file = new File(projet_.getAbsolutePath() + File.separator + DESCRIPTORSOURCE); + saveSourceAndVariables(file,pathVariables); - - progression("", 100); - ui_.message(TrResource.getS("Chargement termin\xE9"), TrResource.getS("Chargement termin\xE9 avec succ\xE8s"), false); - - - - return true; + - } - return false; - } catch (IOException ie) { - ie.printStackTrace(); - ui_.error(TrResource.getS("Erreur dans la sauvegarde du projet")); - return false; - }catch (ClassNotFoundException ie) { - ie.printStackTrace(); - ui_.error(TrResource.getS("Erreur dans la sauvegarde du projet")); - return false; - } + // -- etape 3 sauvegarde des ebliscene unitairement --// + progression("Cr\xE9ation des fichiers layout", 20); - } + // -- creation des params pour les datas --// + parametres.put("path", projet_.getAbsolutePath()); + parametres.put("pathGraphes", pathGraphes); + parametres.put("pathCalques", pathCalques); + // -- creation de la list des noms des widgets + List<EbliWidgetSerializeXml.CoupleNomId> listeNomsComposants = new ArrayList<CoupleNomId>(); + + int cpt = 1; + List<TrPostLayoutFille> listFilles = trprojet_.impl_.getAllLayoutFille(); + for (TrPostLayoutFille fille : listFilles) { + String title = fille.getTitle(); + EbliScene scene = fille.getScene(); + if (listFilles.size() != 0) + progression("Cr\xE9ation du fichier du layout " + title, 20 + 70 / listFilles.size()); + file = new File(projet_.getAbsolutePath() + File.separator + DESCRIPTORSCENE + cpt + EXTENSION); + // -- sauvegarde du persitant --// + parametres.put("dimensions", fille.getSize()); + parametres.put("location", fille.getLocation()); + parametres.put("scene", scene); + savePersitSceneXml(scene, title, file, parametres, listeNomsComposants); + cpt++; + + } + + // -- etap 4 ecriture du fichier des noms --// + file = new File(projet_.getAbsolutePath() + File.separator + FileWidgetNames); + sauverNomsFrames(file, listeNomsComposants); + + // -- etape finale: sauvegarde du fichier de descriptions des layout + // --// + progression("Cr\xE9ation du descripteur de layout", 90); + file = new File(projet_.getAbsolutePath() + File.separator + INFOSCENE); + saveDescriptorScenes(file); + progression("", 100); + ui_.message(TrResource.getS("Sauvegarde termin\xE9e"), TrResource.getS("Sauvegarde termin\xE9e avec succ\xE8s"), false); + return true; + + } + return false; + + + } + + public void messageError(boolean save){ + if(save) + ui_.error(TrResource.getS("Erreur dans la sauvegarde du projet")); + else + ui_.error(TrResource.getS("Erreur dans le chargement du projet")); + } + + /** + * methode qui sauvegarde tous les noms des widgets dans un meme fichier + * facile d acces. + * + * @param file + * @param liste + */ + public void sauverNomsFrames(File file, List<EbliWidgetSerializeXml.CoupleNomId> liste) { + // -- outputstream du xstream --// + ObjectOutputStream out = null; + try { + out = getParser().createObjectOutputStream(new FileWriter(file)); + out.writeObject(liste); + } catch (IOException e) { + e.printStackTrace(); + } + finally { + try { + out.close(); + } catch (IOException e) { + e.printStackTrace(); + messageError(true); + } + + } + + } + + + /** + * methode qui sauvegarde tous les noms des widgets dans un meme fichier + * facile d acces. + * + * @param file + * @param liste + */ + public List<EbliWidgetSerializeXml.CoupleNomId> loadNomsFrames(File file) { + List<EbliWidgetSerializeXml.CoupleNomId> liste = null; + // -- outputstream du xstream --// + ObjectInputStream out = null; + try { + out = getParser().createObjectInputStream(new FileReader(file)); + liste = (List<CoupleNomId>) out.readObject(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } finally { + try { + out.close(); + return liste; + } catch (IOException e) { + e.printStackTrace(); + messageError(false); + } + + } + return null; + } + + /** + * Methode qui charge le projet,l'ensemble des sources et toutes les widgets + * dans les layouts. + * + * @return + */ + public boolean loadProject() { + + progression("Lecture du r\xE9pertoire", 10); + // -- etape 1 lecture du repertoire global --// + if (loadPersistDirectory()) { + File file; + String pathVariables = projet_.getAbsolutePath() + File.separator + "Variables"; + try { + new File(pathVariables).mkdir(); + } catch (Exception e) { + // pas grave on continue + FuLog.debug("Le repertoire des variables existe deja"); + } + + + // -- etape 2 sauvegarde du fichier contenant tous les sources ouverts + progression("Chargement du fichier descripteur de sources", 15); + file = new File(projet_.getAbsolutePath() + File.separator + DESCRIPTORSOURCE); + loadSourceAndVariables(file,pathVariables); + + // -- etape 3: sauvegarde du fichier de descriptions des layout + // --// + progression("Cr\xE9ation du descripteur de layout", 20); + file = new File(projet_.getAbsolutePath() + File.separator + INFOSCENE); + List<String> listeFichiers = loadDescriptorScenes(file); + + // -- etape 4 chargement des ebliscene unitairement --// + progression("Cr\xE9ation des fichiers layout", 30); + // -- creation des params pour les datas --// + HashMap<String, Object> parametres = new HashMap<String, Object>(); + parametres.put("path", projet_.getAbsolutePath()); + + + // -- etape 5 lecture de la liste des couples nomsfRAME /ID --// + file=new File(projet_.getAbsolutePath() + File.separator +FileWidgetNames); + List<EbliWidgetSerializeXml.CoupleNomId> listeCouplesNoms = loadNomsFrames(file); + + int cpt = 1; + + for (String fichier : listeFichiers) { + file = new File(fichier); + if (listeFichiers.size() != 0) + progression("chargement du fichier " + fichier, 30 + 70 / listeFichiers.size()); + + // -- creation de la trpostlayoutFille --// + TrPostLayoutFille postFrame = new TrPostLayoutFille(trprojet_); + // -- sauvegarde du persitant --// + + trprojet_.getImpl().addInternalFrame(postFrame); + loadPersitSceneXml(file, postFrame, parametres, listeCouplesNoms); + + + } + + + progression("", 100); + ui_.message(TrResource.getS("Chargement termin\xE9"), TrResource.getS("Chargement termin\xE9 avec succ\xE8s"), false); + + + + return true; + + } + return false; + + + } + + + + private XStream parser_; + + private XStream getParser() { + if (parser_ == null) + parser_ = initXmlParser(); + return parser_; + } + + /** + * Init le parser avec les alias adequats. + * + * @return + */ + private XStream initXmlParser() { + XStream xstream = new XStream(new DomDriver()); + // -- creation des alias pour que ce soit + parlant dans le xml file --// + xstream.alias("LAYOUT", EbliSceneSerializeXml.class); + xstream.alias("FRAME", EbliWidgetSerializeXml.class); + xstream.alias("FRAMESNAMES", EbliWidgetSerializeXml.CoupleNomId.class); + return xstream; + } + + /** + * Utilise xstream pour serializer les parametres scene, widget + * + * @throws IOException + */ + private void savePersitSceneXml(EbliScene scene, String title, File file, Map parametres, + List<EbliWidgetSerializeXml.CoupleNomId> listeNomsComposants) { + + // -- outputstream du xstream --// + ObjectOutputStream out=null; + try { + out = getParser().createObjectOutputStream(new FileWriter(file)); - - private XStream parser_; - - private XStream getParser(){ - if(parser_==null) - parser_=initXmlParser(); - return parser_; + + // -- g\xE9n\xE9ration du xml pour la scene --// + out.writeObject(new EbliSceneSerializeXml(scene, title, (Dimension) parametres.get("dimensions"), + (Point) parametres.get("location"))); + + // -- g\xE9n\xE9ration du xml pour les eblinode/widgets --// + // -- ACHTUNG!!! IL FAUT RECUPERER LES OBJETS VIA CHILDREN POUR PRESERVER L + // ORDRE DE SUPERPOSITION!!! --// + Iterator<Widget> it = scene.getLayerVisu().getChildren().iterator(); + + // -- creation d une liste particuliere pour les groupes--// + List<EbliWidgetSerializeXml> listeGroupes = new ArrayList<EbliWidgetSerializeXml>(); + + while (it.hasNext()) { + Widget widget = it.next(); + + if (widget instanceof EbliWidgetGroup) { + // -- cas widget group, il faut recuper ses child --// + EbliNode nodeGroupe = (EbliNode) scene.findObject(widget); + // ecriture de l objet + if (nodeGroupe != null) + listeGroupes.add(new EbliWidgetSerializeXml(nodeGroupe, parametres)); + + for (Widget child : widget.getChildren()) { + EbliNode node = (EbliNode) scene.findObject(child); + // ecriture de l objet + if (node != null) + + out.writeObject(new EbliWidgetSerializeXml(node, parametres)); + listeNomsComposants.add(new EbliWidgetSerializeXml.CoupleNomId(node.getTitle(), node.getWidget().getId())); + } + + } else { + EbliNode node = (EbliNode) scene.findObject(widget); + // ecriture de l objet + if (node != null) + out.writeObject(new EbliWidgetSerializeXml(node, parametres)); + listeNomsComposants.add(new EbliWidgetSerializeXml.CoupleNomId(node.getTitle(), node.getWidget().getId())); + } + } + + // -- ecriture des groupes --// + out.writeInt(listeGroupes.size()); + for (EbliWidgetSerializeXml serializeGroupe : listeGroupes) { + out.writeObject(serializeGroupe); + } + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(true); + }finally{ + try { + out.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + messageError(true); } - /** - * Init le parser avec les alias adequats. - * @return - */ - private XStream initXmlParser(){ - XStream xstream = new XStream(new DomDriver()); - //-- creation des alias pour que ce soit + parlant dans le xml file --// - xstream.alias("LAYOUT", EbliSceneSerializeXml.class); - xstream.alias("FRAME", EbliWidgetSerializeXml.class); - return xstream; } - /** - * Utilise xstream pour serializer les parametres scene, widget - * @throws IOException - */ - private void savePersitSceneXml(EbliScene scene,String title,File file, Map parametres) throws IOException{ + } - //-- outputstream du xstream --// - ObjectOutputStream out = getParser().createObjectOutputStream(new FileWriter(file)); + /** + * Methode qui retourne le nom correspondant de la widget + * + * @param listeCouplesNoms + * @param idWidget + * @return + */ + public String getNodeName( List<EbliWidgetSerializeXml.CoupleNomId> listeCouplesNoms, String idWidget) { + for (CoupleNomId couple : listeCouplesNoms) { + if (couple.id.equals(idWidget)) + return couple.nom; + } + return ""; + } + + /** + * Methode qui recupere les infos de la scene et la reconstruit a partir de + * celle vierge fourni en param d'entr\xE9e. + * + * @param file + * le fichier qui contient les infos xml + * @param scenToUpdate + * la scene a remplir avec les infos des fichiers xml + * @throws IOException + * @throws ClassNotFoundException + * @throws IllegalAccessException + * @throws InstantiationException + */ + private void loadPersitSceneXml(File file, TrPostLayoutFille fille, Map parametres, + List<EbliWidgetSerializeXml.CoupleNomId> listeCouplesNoms) { - //-- g\xE9n\xE9ration du xml pour la scene --// - out.writeObject(new EbliSceneSerializeXml(scene,title,(Dimension) parametres.get("dimensions"),(Point) parametres.get("location"))); + EbliScene scenToUpdate = fille.getScene(); + parametres.put("scene", scenToUpdate); + // -- inputstream du xstream --// + ObjectInputStream in = null; + try { + in = getParser().createObjectInputStream(new FileReader(file)); + - //-- g\xE9n\xE9ration du xml pour les eblinode/widgets --// - //-- ACHTUNG!!! IL FAUT RECUPERER LES OBJETS VIA CHILDREN POUR PRESERVER L ORDRE DE SUPERPOSITION!!! --// - Iterator<Widget> it= scene.getLayerVisu().getChildren().iterator(); - - //-- creation d une liste particuliere pour les groupes--// - List<EbliWidgetSerializeXml> listeGroupes=new ArrayList<EbliWidgetSerializeXml>(); - - while(it.hasNext()){ - Widget widget=it.next(); - - - if(widget instanceof EbliWidgetGroup){ - //-- cas widget group, il faut recuper ses child --// - EbliNode nodeGroupe=(EbliNode) scene.findObject(widget); - //ecriture de l objet - if(nodeGroupe !=null) - listeGroupes.add(new EbliWidgetSerializeXml(nodeGroupe,parametres)); - - for(Widget child:widget.getChildren()) { - EbliNode node=(EbliNode) scene.findObject(child); - //ecriture de l objet - if(node !=null) - out.writeObject(new EbliWidgetSerializeXml(node,parametres)); - } - - }else{ - EbliNode node=(EbliNode) scene.findObject(widget); - //ecriture de l objet - if(node !=null) - out.writeObject(new EbliWidgetSerializeXml(node,parametres)); - } - } + // -- r\xE9cup\xE9ration de la scene xml --// + EbliSceneSerializeXml sceneXml = (EbliSceneSerializeXml) in.readObject(); - //-- ecriture des groupes --// - out.writeInt(listeGroupes.size()); - for(EbliWidgetSerializeXml serializeGroupe:listeGroupes){ - out.writeObject(serializeGroupe); - } - - out.close(); + // mise a jour des infos + sceneXml.configureSceneWith(scenToUpdate); + if (sceneXml.getWidth() > 0 && sceneXml.getHeight() > 0) + fille.setSize(sceneXml.getWidth(), sceneXml.getHeight()); + fille.setTitle(sceneXml.getTitle()); + fille.setLocation(sceneXml.getX(), sceneXml.getY()); + // -- preparation de la liste de selection des frames dans le layout --// + final Set<Object> listeNodeSelect = new HashSet<Object>(); - + // -- preparation d'une structure interm\xE9diaire pour optimiser --// + // -- la complexit\xE9 de calcul des groupes (passer en complexit\xE9 lin\xE9aire) + // --// + HashMap<String, HashSet<Object>> listeGroupToPerform = new HashMap<String, HashSet<Object>>(); - } + // -- r\xE9cup\xE9ration via xml des eblinode/widgets --// + for (int i = 0; i < sceneXml.getNbFrames(); i++) { + // lecture xml de l objet + EbliWidgetSerializeXml widgetXml = (EbliWidgetSerializeXml) in.readObject(); - /** - * Methode qui recupere les infos de la scene et la reconstruit a partir de celle vierge fourni en param d'entr\xE9e. - * @param file le fichier qui contient les infos xml - * @param scenToUpdate la scene a remplir avec les infos des fichiers xml - * @throws IOException - * @throws ClassNotFoundException - * @throws IllegalAccessException - * @throws InstantiationException - */ - private void loadPersitSceneXml(File file, TrPostLayoutFille fille, Map parametres) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException{ - - EbliScene scenToUpdate=fille.getScene(); - parametres.put("scene",scenToUpdate); - - //-- inputstream du xstream --// - ObjectInputStream in = getParser().createObjectInputStream(new FileReader(file)); + // generation de la widget dans la scene + parametres.put("nodeName", getNodeName(listeCouplesNoms, widgetXml.getId())); + EbliNode node = widgetXml.generateWidgetInScene(parametres, scenToUpdate); + + // ajout des noeuds a ajouter dans la selection + if (widgetXml.isSelected()) + listeNodeSelect.add(node); + // ajout de la creation d'un groupe + if (!widgetXml.getIdGroup().equals(EbliWidgetGroup.NOGROUP)) { + // il y a un group a prendre en compte d'id + String idGroup = widgetXml.getIdGroup(); + if (listeGroupToPerform.get(idGroup) == null) { + // on init + listeGroupToPerform.put(idGroup, new HashSet<Object>()); + } + // on ajoute l'objet node pour la widget + listeGroupToPerform.get(idGroup).add(node); + } - //-- r\xE9cup\xE9ration de la scene xml --// - EbliSceneSerializeXml sceneXml = (EbliSceneSerializeXml)in.readObject(); + } - //mise a jour des infos - sceneXml.configureSceneWith(scenToUpdate); - if(sceneXml.getWidth()>0 && sceneXml.getHeight()>0) - fille.setSize(sceneXml.getWidth(),sceneXml.getHeight()); - fille.setTitle(sceneXml.getTitle()); - fille.setLocation(sceneXml.getX(),sceneXml.getY()); - - //-- preparation de la liste de selection des frames dans le layout --// - final Set<Object> listeNodeSelect = new HashSet<Object>(); - - //-- preparation d'une structure interm\xE9diaire pour optimiser --// - //-- la complexit\xE9 de calcul des groupes (passer en complexit\xE9 lin\xE9aire) --// - HashMap<String, HashSet<Object>> listeGroupToPerform=new HashMap<String, HashSet<Object>>(); - - //-- r\xE9cup\xE9ration via xml des eblinode/widgets --// - for(int i=0;i<sceneXml.getNbFrames();i++){ - - //lecture xml de l objet - EbliWidgetSerializeXml widgetXml = (EbliWidgetSerializeXml)in.readObject(); - //generation de la widget dans la scene - EbliNode node=widgetXml.generateWidgetInScene(parametres, scenToUpdate); - - //ajout des noeuds a ajouter dans la selection - if(widgetXml.isSelected()) - listeNodeSelect.add(node); - - //ajout de la creation d'un groupe - if(!widgetXml.getIdGroup().equals(EbliWidgetGroup.NOGROUP)){ - //il y a un group a prendre en compte d'id - String idGroup=widgetXml.getIdGroup(); - if(listeGroupToPerform.get(idGroup)==null){ - //on init - listeGroupToPerform.put(idGroup, new HashSet<Object>()); - } - //on ajoute l'objet node pour la widget - listeGroupToPerform.get(idGroup).add(node); - } - - } + // -- lecture des groupes --// + // -- ecriture des groupes --// + int nbGroups = in.readInt(); + HashMap<String, EbliWidgetSerializeXml> listeGroupes = new HashMap<String, EbliWidgetSerializeXml>(); - - //-- lecture des groupes --// - //-- ecriture des groupes --// - int nbGroups=in.readInt(); - HashMap<String,EbliWidgetSerializeXml> listeGroupes=new HashMap<String,EbliWidgetSerializeXml>(); - - for( int i=0;i<nbGroups;i++){ - EbliWidgetSerializeXml group=(EbliWidgetSerializeXml) in.readObject(); - listeGroupes.put(group.getId(),group); - } - - - in.close(); - scenToUpdate.refresh(); - //-- on s'occupe de grouper l'ensemble des widgets --// - for(String idGroup:listeGroupToPerform.keySet()){ - //--l'idGroup est jetable, on ne le sauvegarde pas --// - HashSet<Object> listeToGroup=listeGroupToPerform.get(idGroup); - EbliNode nodeGroup=new EbliWidgetGroupAction(scenToUpdate).performGroup(listeToGroup); - - //-- on met a jour le ebliNode avec les infos du groupe sauv\xE9 --// - EbliWidgetSerializeXml infoGroup=listeGroupes.get(idGroup); - if(infoGroup!=null){ - nodeGroup.setTitle(infoGroup.getTitle()); - nodeGroup.getWidget().setPreferredLocation(new Point(infoGroup.getX(),infoGroup.getY())); - nodeGroup.getWidget().setPreferredSize(new Dimension(infoGroup.getWidth(),infoGroup.getHeight())); - - - } - } - //-- on ajoute les noeuds selectionnes a ebliScene --// - scenToUpdate.setSelectedObjects(listeNodeSelect); - // mise a jour de la scene - scenToUpdate.refresh(); + for (int i = 0; i < nbGroups; i++) { + EbliWidgetSerializeXml group = (EbliWidgetSerializeXml) in.readObject(); + listeGroupes.put(group.getId(), group); + } + + scenToUpdate.refresh(); + // -- on s'occupe de grouper l'ensemble des widgets --// + for (String idGroup : listeGroupToPerform.keySet()) { + // --l'idGroup est jetable, on ne le sauvegarde pas --// + HashSet<Object> listeToGroup = listeGroupToPerform.get(idGroup); + EbliNode... [truncated message content] |