r213 - in trunk: coser-business/src/main/java/fr/ifremer/coser/bean coser-business/src/main/java/fr/ifremer/coser/services coser-ui/src/main/java/fr/ifremer/coser/ui coser-ui/src/main/java/fr/ifremer/coser/ui/control
Author: chatellier Date: 2010-11-15 17:27:03 +0000 (Mon, 15 Nov 2010) New Revision: 213 Log: Ajout de la sauvegarde/relecture des control Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Control.java trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Project.java trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Selection.java trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Control.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Control.java 2010-11-15 16:57:53 UTC (rev 212) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Control.java 2010-11-15 17:27:03 UTC (rev 213) @@ -25,6 +25,8 @@ package fr.ifremer.coser.bean; +import java.util.Properties; + /** * Control entity. * @@ -39,4 +41,29 @@ /** serialVersionUID. */ private static final long serialVersionUID = 3693938021315541627L; + protected String comment; + + public String getComment() { + return comment; + } + + public void setComment(String comment) { + String oldValue = this.comment; + this.comment = comment; + getPropertyChangeSupport().firePropertyChange("comment", oldValue, comment); + } + + public Properties toProperties() { + Properties props = new Properties(); + if (comment != null) { + props.setProperty("control.comment", comment); + } + return props; + } + + public void fromProperties(Properties props) { + if (props.containsKey("control.comment")) { + setComment(props.getProperty("control.comment")); + } + } } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Project.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Project.java 2010-11-15 16:57:53 UTC (rev 212) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Project.java 2010-11-15 17:27:03 UTC (rev 213) @@ -213,8 +213,21 @@ public Properties toProperties() { Properties props = new Properties(); - props.setProperty("project.author", author); - props.setProperty("project.comment", comment); + if (author != null) { + props.setProperty("project.author", author); + } + if (comment != null) { + props.setProperty("project.comment", comment); + } return props; } + + public void fromProperties(Properties props) { + if (props.containsKey("project.author")) { + setAuthor(props.getProperty("project.author")); + } + if (props.containsKey("control.comment")) { + setComment(props.getProperty("control.comment")); + } + } } Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Selection.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Selection.java 2010-11-15 16:57:53 UTC (rev 212) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/bean/Selection.java 2010-11-15 17:27:03 UTC (rev 213) @@ -124,7 +124,9 @@ } public void setComment(String comment) { + String oldValue = this.comment; this.comment = comment; + getPropertyChangeSupport().firePropertyChange("comment", oldValue, comment); } public Properties toProperties() { Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-11-15 16:57:53 UTC (rev 212) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/ProjectService.java 2010-11-15 17:27:03 UTC (rev 213) @@ -231,7 +231,7 @@ IOUtils.closeQuietly(outputStream); } - // init additional structures + // init additional structures (load empty control) project.setSelections(new HashMap<String, Selection>()); control.setHistoryCommand(new ArrayList<Command>()); project.setControl(control); @@ -290,7 +290,6 @@ // relecture des informations de la selection (properties) File propertiesFile = new File(selectionDirectory, "selection.properties"); - InputStream inputStream = null; try { Properties props = new Properties(); @@ -314,6 +313,25 @@ } project.setSelections(selections); + // relecture des informations du projet (properties) + File propertiesFile = new File(projectDirectory, "project.properties"); + InputStream inputStream = null; + try { + Properties props = new Properties(); + inputStream = new FileInputStream(propertiesFile); + props.load(inputStream); + project.fromProperties(props); + + if (log.isDebugEnabled()) { + log.debug("Read project properties file : " + propertiesFile); + } + } catch (IOException ex) { + throw new CoserBusinessException("Can't read project properties file", ex); + } + finally { + IOUtils.closeQuietly(inputStream); + } + return project; } @@ -405,6 +423,27 @@ List<Command> commands = loadHistoryCommands(historyFile); control.setHistoryCommand(commands); + // relecture des informations du control (properties) + File propertiesFile = new File(controlDirectory, "control.properties"); + if (propertiesFile.exists()) { // si on a vraiment pas sauver le control ... + InputStream inputStream = null; + try { + Properties props = new Properties(); + inputStream = new FileInputStream(propertiesFile); + props.load(inputStream); + control.fromProperties(props); + + if (log.isDebugEnabled()) { + log.debug("Read control properties file : " + propertiesFile); + } + } catch (IOException ex) { + throw new CoserBusinessException("Can't read control properties file", ex); + } + finally { + IOUtils.closeQuietly(inputStream); + } + } + project.setControl(control); return project; @@ -471,6 +510,8 @@ String projectName = project.getName(); File projectDirectory = new File(projectsDirectory, projectName); + Control control = project.getControl(); + // creation du dossier de control (il peut deja exister) File controlDirectory = new File(projectDirectory, CoserConstants.STORAGE_CONTROL_DIRECTORY); controlDirectory.mkdirs(); @@ -485,11 +526,11 @@ if (log.isDebugEnabled()) { log.debug("Saving control file : " + controlFile); } - DataStorage content = getProjectContent(project, project.getControl(), category, false); + DataStorage content = getProjectContent(project, control, category, false); importService.storeData(project, content, controlFile); // save deleted content (if needed) - DataStorage contentDeleted = getProjectContent(project, project.getControl(), category, true); + DataStorage contentDeleted = getProjectContent(project, control, category, true); // if more content than header if (contentDeleted.size() > 1) { File deletedDataFile = new File(controlDirectory, @@ -500,7 +541,25 @@ } } } - + + // sauvegarde des informations du control (properties) + File propertiesFile = new File(controlDirectory, "control.properties"); + Properties props = control.toProperties(); + OutputStream outputStream = null; + try { + outputStream = new FileOutputStream(propertiesFile); + props.store(outputStream, null); + + if (log.isDebugEnabled()) { + log.debug("Saving control properties file : " + propertiesFile); + } + } catch (IOException ex) { + throw new CoserBusinessException("Can't save control properties file", ex); + } + finally { + IOUtils.closeQuietly(outputStream); + } + // sauvegarde de l'historique des commandes File historyFile = new File(controlDirectory, CoserConstants.STORAGE_HISTORY_FILENAME + CoserConstants.STORAGE_HISTORY_SELECTION_EXTENSION); Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-11-15 16:57:53 UTC (rev 212) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/CoserFrameHandler.java 2010-11-15 17:27:03 UTC (rev 213) @@ -349,6 +349,7 @@ ControlView controlView = new ControlView(view); controlView.setHandler(new ControlHandler()); + controlView.setControl(project.getControl()); // restore session size SwingSession session = (SwingSession)view.getContextValue(SwingSession.class); Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-11-15 16:57:53 UTC (rev 212) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlHandler.java 2010-11-15 17:27:03 UTC (rev 213) @@ -68,6 +68,7 @@ import fr.ifremer.coser.CoserConstants.Category; import fr.ifremer.coser.CoserConstants.ValidationLevel; import fr.ifremer.coser.CoserException; +import fr.ifremer.coser.bean.Control; import fr.ifremer.coser.bean.Project; import fr.ifremer.coser.control.ValidationError; import fr.ifremer.coser.data.AbstractDataEntity; Modified: trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx =================================================================== --- trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2010-11-15 16:57:53 UTC (rev 212) +++ trunk/coser-ui/src/main/java/fr/ifremer/coser/ui/control/ControlView.jaxx 2010-11-15 17:27:03 UTC (rev 213) @@ -35,6 +35,7 @@ ]]></script> <ControlHandler id="handler" javaBean="null" /> + <fr.ifremer.coser.bean.Control id="control" javaBean="null" /> <row> <cell fill="horizontal" insets="0" anchor="west" columns="2"> @@ -137,9 +138,12 @@ </JScrollPane> <JPanel layout="{new BorderLayout()}"> - <JLabel text="coser.ui.control.comment" constraints="{BorderLayout.NORTH}"/> - <JScrollPane constraints="{BorderLayout.CENTER}"> - <JTextArea rows="3" /> + <JLabel text="coser.ui.control.comment" constraints="BorderLayout.NORTH"/> + <JScrollPane constraints="BorderLayout.CENTER"> + <JTextArea id="controlComment" rows="3" text="{getControl().getComment()}" /> + <javax.swing.text.Document javaBean="controlComment.getDocument()" + onInsertUpdate='getControl().setComment(controlComment.getText()); saveButton.setEnabled(true)' + onRemoveUpdate='getControl().setComment(controlComment.getText()); saveButton.setEnabled(true)' /> </JScrollPane> </JPanel> </JSplitPane>
participants (1)
-
chatellierï¼ users.labs.libre-entreprise.org