From: <had...@us...> - 2008-10-21 15:38:09
|
Revision: 4088 http://fudaa.svn.sourceforge.net/fudaa/?rev=4088&view=rev Author: hadouxad Date: 2008-10-21 15:38:05 +0000 (Tue, 21 Oct 2008) Log Message: ----------- - Gestion des path relatifs et absolu du setup.POST ce qui permet de d?\195?\169placer le r?\195?\169pertoire projet ou l'on souhaite! cela fonctionne toujours! - Gestion des noms explicites pour les variables - Correction bug: cas ou les l?\195?\169gendes sont enregistr?\195?\169es dans le fichier xml avant les calques/graphes, ca plantait car les l?\195?\169gendes ont besoin des graphes/calques pour se construire - Tests sous linux ok - Proposition de sauvegarde lors de la fermeture du logiciel Modified Paths: -------------- 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/TrPostCommonImplementation.java branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostProjet.java branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/TrPostPersistenceManager.java Added Paths: ----------- branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/VariablesStreamStrategy.java 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-21 12:36:25 UTC (rev 4087) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/persist/EbliWidgetSerializeXml.java 2008-10-21 15:38:05 UTC (rev 4088) @@ -14,6 +14,7 @@ import org.fudaa.ebli.visuallibrary.EbliWidget; import org.fudaa.ebli.visuallibrary.EbliWidgetBordureSingle; import org.fudaa.ebli.visuallibrary.EbliWidgetGroup; +import org.fudaa.ebli.visuallibrary.calque.EbliWidgetCreatorLegende; import org.fudaa.ebli.visuallibrary.creator.EbliWidgetCreator; import org.fudaa.ebli.visuallibrary.creator.EbliWidgetCreatorClassLoader; @@ -182,6 +183,23 @@ return newNode; } + + public boolean isLinked(){ + String className=type; + if(type==null) + return true; + if (className.startsWith("class ")) ; + className = className.substring("class ".length()); + + if( className.equals(EbliWidgetCreatorLegende.class.getName())) + return true; + else + if( className.equals(org.fudaa.ebli.visuallibrary.graphe.EbliWidgetCreatorLegende.class.getName())) + return true; + return false; + + } + public String getTitle() { return title; } Modified: branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostCommonImplementation.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostCommonImplementation.java 2008-10-21 12:36:25 UTC (rev 4087) +++ branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostCommonImplementation.java 2008-10-21 15:38:05 UTC (rev 4088) @@ -122,14 +122,17 @@ public boolean saveAndCloseProjet(final ProgressionInterface _interface) { if (c_ != null) { - if (c_.isModified()) { - final int i = CtuluLibDialog.confirmExitIfProjectisModified(getFrame()); - if (i == JOptionPane.CANCEL_OPTION) { - return false; - } else if (i != JOptionPane.NO_OPTION) { - c_.save(this, _interface); + + // -- enregistrement sauce widget --// + final int i = CtuluLibDialog.confirmExitIfProjectisModified(getFrame()); + if (i == JOptionPane.CANCEL_OPTION) { + return false; + } + if (i != JOptionPane.NO_OPTION) { + c_.getManager().saveProject(false); + //c_.save(this, _interface); } - } + c_.close(); c_ = null; SwingUtilities.invokeLater(new Runnable() { @@ -143,6 +146,9 @@ } }); } + + + return true; } Modified: branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostProjet.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostProjet.java 2008-10-21 12:36:25 UTC (rev 4087) +++ branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/TrPostProjet.java 2008-10-21 15:38:05 UTC (rev 4088) @@ -81,6 +81,7 @@ import com.memoire.bu.BuScrollPane; import com.memoire.bu.BuTable; import com.memoire.bu.BuVerticalLayout; +import com.memoire.fu.FuLib; import com.memoire.fu.FuLog; /** @@ -1259,6 +1260,16 @@ if(src.getId()==null){ String uniqueId=CtuluLibGenerator.getInstance().deliverUniqueStringId(src.getFile().getName()); src.setId(uniqueId); + }else{ + + //-- on teste si l'id de base est 'parlant' => contient le nom du ficheir --// + String nameFormate=FuLib.clean(src.getFile().getName()); + String id=src.getId(); + if(!id.startsWith(nameFormate)){ + String uniqueId=CtuluLibGenerator.getInstance().deliverUniqueStringId(src.getFile().getName()); + src.setId(uniqueId); + } + } return src.getId(); 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-21 12:36:25 UTC (rev 4087) +++ branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/TrPostPersistenceManager.java 2008-10-21 15:38:05 UTC (rev 4088) @@ -219,8 +219,10 @@ in = getParser().createObjectInputStream(new FileReader(fichierSetup)); // -- Recuperation du path du projet --// - final String pathProjet = (String) in.readObject(); - if (pathProjet == null) { + final String pathRelatifProjet = (String) in.readObject(); + final String pathAbsoluProjet = (String) in.readObject(); + + if (pathRelatifProjet == null) { try { in.close(); return false; @@ -230,7 +232,15 @@ messageError(false); } } - projet_ = new File(pathProjet); + + //-- tetative de recollage du path relatif avec le path du fichier du chooser --// + File fichierDirectory=CtuluLibFile.getAbsolutePathnameTo(fichierSetup, new File(pathRelatifProjet)); + + if(fichierDirectory!=null && fichierDirectory.canRead()){ + projet_=fichierDirectory; + } + else + projet_ = new File(pathAbsoluProjet); try { in.close(); return true; @@ -380,7 +390,7 @@ */ List<TrPostUserVariableSaver> getPersitantVariablesList(final String path, final boolean init) { - final List<TrPostUserVariableSaver> liste = new XmlArrayList(new FileStreamStrategy(new File(path))); + final List<TrPostUserVariableSaver> liste = new XmlArrayList(new VariablesStreamStrategy(new File(path),trprojet_.listeSrc_)); if (init) clearDatas(liste); @@ -407,7 +417,13 @@ try { final File fichier = new File(projet + File.separator + setupProject); out = getParser().createObjectOutputStream(new FileWriter(fichier)); + + //--enregistrement du path relatif --// + File pathRelatif=CtuluLibFile.getRelativePathnameTo(fichier, projet_); + out.writeObject(pathRelatif.getPath()); + //-- enregistrement du path absolu --// out.writeObject(projet); + } catch (final IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -996,6 +1012,8 @@ // --// final HashMap<String, HashSet<Object>> listeGroupToPerform = new HashMap<String, HashSet<Object>>(); + List<EbliWidgetSerializeXml> listeWidgetLinked=new ArrayList<EbliWidgetSerializeXml>(); + // -- r\xE9cup\xE9ration via xml des eblinode/widgets --// for (int i = 0; i < sceneXml.getNbFrames(); i++) { @@ -1005,7 +1023,8 @@ // generation de la widget dans la scene parametres.put("nodeName", getNodeName(listeCouplesNoms, widgetXml.getId())); final EbliNode node = widgetXml.generateWidgetInScene(parametres, scenToUpdate); - + + if(!widgetXml.isLinked()){ // ajout des noeuds a ajouter dans la selection if (widgetXml.isSelected()) listeNodeSelect.add(node); @@ -1021,8 +1040,36 @@ listeGroupToPerform.get(idGroup).add(node); } + + } + else{ + //-- on ajoute la widget liee a la liste des widget a cree au final--// + listeWidgetLinked.add(widgetXml); + } + } + //--On executre les widgets liees --// + for (EbliWidgetSerializeXml widgetXml:listeWidgetLinked) { + // generation de la widget dans la scene + parametres.put("nodeName", getNodeName(listeCouplesNoms, widgetXml.getId())); + final 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 + final 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 --// final int nbGroups = in.readInt(); Added: branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/VariablesStreamStrategy.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/VariablesStreamStrategy.java (rev 0) +++ branches/Prepro-0.92-SNAPSHOT/fudaa/src/org/fudaa/fudaa/tr/post/persist/VariablesStreamStrategy.java 2008-10-21 15:38:05 UTC (rev 4088) @@ -0,0 +1,226 @@ +package org.fudaa.fudaa.tr.post.persist; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.fudaa.fudaa.tr.post.TrPostSource; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.StreamException; +import com.thoughtworks.xstream.persistence.FileStreamStrategy; +import com.thoughtworks.xstream.persistence.StreamStrategy; + + +/** + * Classe qui surcharge FileStreamStrategy de xstream pour g\xE9rer les noms des ficheirs \xE0 sa propre sauce. + * Les fichiers seront de la forme nomFIchier_KEY.xml + * @author Adrien Hadoux + * + */ +public class VariablesStreamStrategy implements StreamStrategy{ + + + List<TrPostSource> listeSourcesAssociees_; + private final FilenameFilter filter; + + private final XStream xstream; + + private final File baseDirectory; + + public VariablesStreamStrategy(File baseDirectory,List<TrPostSource> listeSourcesAssociees) { + this(baseDirectory, new XStream(),listeSourcesAssociees); + } + + public VariablesStreamStrategy(File baseDirectory, XStream xstream,List<TrPostSource> listeSourcesAssociees) { + + listeSourcesAssociees_=listeSourcesAssociees; + + this.baseDirectory = baseDirectory; + this.xstream = xstream; + this.filter = new FilenameFilter() { + public boolean accept(File dir, String name) { + return new File(dir, name).isFile() && isValid(dir, name); + } + }; + } +// public VariablesStreamStrategy(File baseDirectory,List<TrPostSource> listeSourcesAssociees) { +// super(baseDirectory); +// // TODO Auto-generated constructor stub +// listeSourcesAssociees_=listeSourcesAssociees; +// } + + /** + * Il faut extraire la clef du nom du fichier. + * Les fichiers seront toujours de la forme + * nomFIchier_KEY.xml + */ + + protected String extractKey(String name) { + // TODO Auto-generated method stub + String val=name.substring(name.lastIndexOf("_"), name.length() - 4); + return val; + + } + + /** + * Genere le nom du fichier a partir du nom de la source associ\xE9e a la variable et de l'indice + */ + + protected String getName(Object key) { + // TODO Auto-generated method stub + int value= Integer.parseInt(key.toString()); + + String val=listeSourcesAssociees_.get(value).getId()+"_"+key.toString()+".xml"; + + return val; + //return super.getName(key); + } + + + + + + protected boolean isValid(File dir, String name) { + return name.endsWith(".xml"); + } + + + + class XmlMapEntriesIterator implements Iterator { + + private File[] files = baseDirectory.listFiles(filter); + + private int position = -1; + + private File current = null; + + public boolean hasNext() { + return position + 1 < files.length; + } + + public void remove() { + if (current == null) { + throw new IllegalStateException(); + } + // removes without loading + current.delete(); + } + + public Object next() { + return new Map.Entry() { + + private File file = current = files[++position]; + + private String key = extractKey(file.getName()); + + public Object getKey() { + return key; + } + + public Object getValue() { + return readFile(file); + } + + public Object setValue(Object value) { + return put(key, value); + } + + public boolean equals(Object obj) { + if (!(obj instanceof Entry)) { + return false; + } + Entry e2 = (Entry) obj; + // TODO local cache value instead of calling getValue twice + return (key == null ? e2.getKey() == null : key.equals(e2 + .getKey())) + && (getValue() == null ? e2.getValue() == null + : getValue().equals(e2.getValue())); + } + + }; + } + + } + + private void writeFile(File file, Object value) { + try { + OutputStream os = new FileOutputStream(file); + try { + this.xstream.toXML(value, os); + } finally { + os.close(); + } + } catch (IOException e) { + throw new StreamException(e); + } + } + + private File getFile(String filename) { + return new File(this.baseDirectory, filename); + } + + private Object readFile(File file) { + try { + InputStream is = new FileInputStream(file); + try { + return this.xstream.fromXML(is); + } finally { + is.close(); + } + } catch (FileNotFoundException e) { + // not found... file.exists might generate a sync problem + return null; + } catch (IOException e) { + throw new StreamException(e); + } + } + + + public Object put(Object key, Object value) { + Object oldValue = get(key); + String filename = getName(key); + writeFile(new File(baseDirectory, filename), value); + return oldValue; + } + + public Iterator iterator() { + return new XmlMapEntriesIterator(); + } + + public int size() { + return baseDirectory.list(filter).length; + } + + public boolean containsKey(Object key) { + // faster lookup + File file = getFile(getName(key)); + return file.exists(); + } + + public Object get(Object key) { + return readFile(getFile(getName(key))); + } + + public Object remove(Object key) { + // faster lookup + File file = getFile(getName(key)); + Object value = null; + if (file.exists()) { + value = readFile(file); + file.delete(); + } + return value; + } + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |