Author: chatellier Date: 2011-06-14 13:21:14 +0000 (Tue, 14 Jun 2011) New Revision: 3392 Log: Improve official vcs and community csv display. Add drag and drop support between trees. Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTranferable.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTransferHandler.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTree.java Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeCellRenderer.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeModel.java isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2011-06-14 13:20:31 UTC (rev 3391) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/ScriptAction.java 2011-06-14 13:21:14 UTC (rev 3392) @@ -40,6 +40,7 @@ import java.lang.reflect.Method; import java.net.URI; import java.util.ArrayList; +import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -54,6 +55,7 @@ import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -75,6 +77,7 @@ import fr.ifremer.isisfish.datastore.SimulatorStorage; import fr.ifremer.isisfish.equation.Language; import fr.ifremer.isisfish.ui.WelcomePanelUI; +import fr.ifremer.isisfish.ui.script.model.ScriptTree; import fr.ifremer.isisfish.ui.script.model.ScriptTreeModel; import fr.ifremer.isisfish.ui.util.ErrorHelper; import fr.ifremer.isisfish.ui.vcs.UpdateDialogUI; @@ -142,10 +145,15 @@ * Post init, must be called after ui building. */ public void postInit() { - + + ScriptTree scriptTree = this.scriptUI.getScriptTree(); + // add listeners - this.scriptUI.getTree().addTreeSelectionListener(this); + scriptTree.addTreeSelectionListener(this); this.scriptUI.getEditor().addCaretListener(this); + + // expand official VCS tree node + scriptTree.expandRow(0); } /** @@ -153,7 +161,7 @@ */ protected void setButton() { - File selectedFile = (File)scriptUI.getTree().getLastSelectedPathComponent(); + File selectedFile = (File)scriptUI.getScriptTree().getLastSelectedPathComponent(); if (selectedFile != null) { scriptUI.setSingleFileSelected(selectedFile.isFile()); @@ -163,25 +171,6 @@ scriptUI.setSingleFileSelected(false); scriptUI.setJavaFileSelected(false); } - - /*buttonScriptExport.setEnabled(tree.getSelectionValue() != null); - miExport.setEnabled(tree.getSelectionValue() != null); - buttonScriptCommit.setEnabled(fileSelected); - miCommitVCS.setEnabled(fileSelected); - miDiffVCS.setEnabled(fileSelected); - //buttonScriptUpdate.setEnabled(fileSelected); - buttonScriptSave.setEnabled(fileSelected); - miSave.setEnabled(fileSelected); - buttonScriptCut.setEnabled(fileSelected); - miCut.setEnabled(fileSelected); - buttonScriptCopy.setEnabled(fileSelected); - miCopy.setEnabled(fileSelected); - buttonScriptPaste.setEnabled(fileSelected); - miPaste.setEnabled(fileSelected); - buttonScriptCheck.setEnabled(isJavaScript); - miCheckSyntax.setEnabled(isJavaScript); - buttonScriptEval.setEnabled(isJavaScript); - miEvaluate.setEnabled(isJavaScript);*/ } protected void setStatusMessage(String msg) { @@ -231,10 +220,10 @@ File scriptFile = newScript(equationModelTypePath + fileName, scriptType); // creation successful if (scriptFile != null) { - ScriptTreeModel model = (ScriptTreeModel) scriptUI.getTree().getModel(); + ScriptTreeModel model = scriptUI.getScriptTreeModel(); model.fileAdded(scriptFile); TreePath treePath = model.getTreePathFor(scriptFile); - scriptUI.getTree().setSelectionPath(treePath); + scriptUI.getScriptTree().setSelectionPath(treePath); } } } @@ -397,8 +386,9 @@ @Override public void valueChanged(TreeSelectionEvent e) { if (e.getNewLeadSelectionPath() != null) { - File selectedFile = (File)e.getNewLeadSelectionPath().getLastPathComponent(); - if (selectedFile.isFile()) { + Object selectedNode = e.getNewLeadSelectionPath().getLastPathComponent(); + if (selectedNode instanceof File && ((File)selectedNode).isFile()) { + File selectedFile = (File)selectedNode; // load file into current action codeStorage loadScript(selectedFile); scriptUI.getEditor().open(selectedFile); @@ -460,8 +450,7 @@ script = SensitivityStorage.getSensitivity(file.getName()); break; case SensitivityExport: - script = SensitivityExportStorage.getSensitivityExport(file - .getName()); + script = SensitivityExportStorage.getSensitivityExport(file.getName()); break; default: log.fatal("ScriptType unknown: " + file.getName()); @@ -501,7 +490,7 @@ scriptUI.getEditor().save(); // notify tree to refresh - ScriptTreeModel model = (ScriptTreeModel) scriptUI.getTree().getModel(); + ScriptTreeModel model = scriptUI.getScriptTreeModel(); model.fileModified(codeStorage.getFile()); } catch (Exception eee) { returnError(_("isisfish.error.script.save", codeStorage.getFile(), @@ -547,7 +536,7 @@ */ public void exportScript() { - TreePath[] selectedFilesPath = scriptUI.getTree().getSelectionPaths(); + TreePath[] selectedFilesPath = scriptUI.getScriptTree().getSelectionPaths(); // first step : acquire list of files required int prefixLength = IsisFish.config.getDatabaseDirectory() @@ -1024,8 +1013,7 @@ try { // TODO change this, need to be called before // effective deletion - ((ScriptTreeModel) scriptUI.getTree().getModel()) - .fileDeleted(codeStorage.getFile()); + scriptUI.getScriptTreeModel().fileDeleted(codeStorage.getFile()); //TODO desactive editor //TODO Review this because after delete fi file saw previously @@ -1098,7 +1086,11 @@ SimulatorStorage.SIMULATOR_TEMPLATE), EquationModel( FormuleStorage.getFormuleDirectory(), - FormuleStorage.FORMULE_TEMPLATE); + FormuleStorage.FORMULE_TEMPLATE), + + CommunitySimulator( + SimulatorStorage.getCommunitySimulatorDirectory(), + SimulatorStorage.SIMULATOR_TEMPLATE); protected File module; protected String templatePath; @@ -1205,4 +1197,25 @@ // selection pas vide si dot = mark scriptUI.setTextSelected(e.getDot() != e.getMark()); } + + /** + * Move files. + * (called by drag and drop handler). + * + * @param directory directory to moves files to + * @param filesToMove files to move to directory + */ + public void moveFiles(File directory, Collection<File> filesToMove) { + + ScriptTreeModel model = scriptUI.getScriptTreeModel(); + for (File fileToMove : filesToMove) { + model.fileDeleted(fileToMove); + try { + FileUtils.moveFileToDirectory(fileToMove, directory, false); + } catch (IOException ex) { + throw new IsisFishRuntimeException("Can't move file", ex); + } + model.fileAdded(fileToMove); + } + } } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx 2011-06-14 13:20:31 UTC (rev 3391) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/ScriptUI.jaxx 2011-06-14 13:21:14 UTC (rev 3392) @@ -31,7 +31,9 @@ java.awt.Font </import> <script><![CDATA[ - getScriptAction().postInit(); + protected void $afterCompleteSetup() { + getScriptAction().postInit(); + } ]]></script> <Boolean id="fileSelected" javaBean="false" /> @@ -98,8 +100,9 @@ </JPanel> <JSplitPane oneTouchExpandable="true" dividerLocation="250" orientation="HORIZONTAL" constraints='BorderLayout.CENTER'> <JScrollPane> - <JTree id="tree" name="tree" rootVisible="false" - model='{new fr.ifremer.isisfish.ui.script.model.ScriptTreeModel()}' + <fr.ifremer.isisfish.ui.script.model.ScriptTreeModel id="scriptTreeModel" /> + <fr.ifremer.isisfish.ui.script.model.ScriptTree id="scriptTree" constructorParams='this' + rootVisible="false" model='{scriptTreeModel}' cellRenderer='{new fr.ifremer.isisfish.ui.script.model.ScriptTreeCellRenderer()}' /> </JScrollPane> <JSplitPane oneTouchExpandable="true" resizeWeight="0.75" orientation="VERTICAL"> Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTranferable.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTranferable.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTranferable.java 2011-06-14 13:21:14 UTC (rev 3392) @@ -0,0 +1,118 @@ +/* + * #%L + * Isis-Fish + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.ui.script.model; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.File; +import java.io.IOException; +import java.util.List; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Represent transfered data. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ By : $Author$ + */ +public class ScriptTranferable implements Transferable { + + /** log */ + private static Log log = LogFactory.getLog(ScriptTranferable.class); + + /** Data transfer mime type */ + protected static final String MIMETYPE = DataFlavor.javaJVMLocalObjectMimeType + + ";class=" + File.class.getName(); + + /** Data instance */ + protected static DataFlavor myData; + + /** Files to transfer. Chosen implementation must be serializable. */ + protected List<File> filesToTransfer; + + /** + * Constructor. + * + * @param filesToTransfer files to transfer + */ + public ScriptTranferable(List<File> filesToTransfer) { + + // save task + this.filesToTransfer = filesToTransfer; + + // build new DataFlavor + try { + myData = new DataFlavor(MIMETYPE); + } catch (ClassNotFoundException e) { + if (log.isErrorEnabled()) { + log.error("Class not found", e); + } + } + } + + /* + * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor) + */ + @Override + public Object getTransferData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException { + + List<File> filesToTransfer = null; + + if (flavor == null) { + throw new IOException("flavor is null"); + } + + if (flavor.equals(myData)) { + filesToTransfer = this.filesToTransfer; + } else { + throw new UnsupportedFlavorException(flavor); + } + + return filesToTransfer; + } + + /* + * @see java.awt.datatransfer.Transferable#getTransferDataFlavors() + */ + @Override + public DataFlavor[] getTransferDataFlavors() { + return new DataFlavor[] { myData }; + } + + /* + * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor) + */ + @Override + public boolean isDataFlavorSupported(DataFlavor flavor) { + return flavor.equals(myData); + } +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTranferable.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTransferHandler.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTransferHandler.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTransferHandler.java 2011-06-14 13:21:14 UTC (rev 3392) @@ -0,0 +1,172 @@ +/* + * #%L + * jTimer + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, CodeLutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.ui.script.model; + +import java.awt.datatransfer.DataFlavor; +import java.awt.datatransfer.Transferable; +import java.awt.datatransfer.UnsupportedFlavorException; +import java.io.File; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import javax.swing.JComponent; +import javax.swing.TransferHandler; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import fr.ifremer.isisfish.ui.script.ScriptUI; + +/** + * Transfer handler used to transfer tasks in table. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ By : $Author$ + */ +public class ScriptTransferHandler extends TransferHandler { + + /** serialVersionUID. */ + private static final long serialVersionUID = 5433321973795969278L; + + /** log. */ + private static Log log = LogFactory.getLog(ScriptTransferHandler.class); + + protected ScriptUI scriptUI; + + /** + * Constructor. + * + * @param scriptUI scriptUI + */ + public ScriptTransferHandler(ScriptUI scriptUI) { + this.scriptUI = scriptUI; + } + + @Override + public boolean canImport(JComponent cp, DataFlavor[] df) { + + for (DataFlavor dataFlavor : df) { + if (dataFlavor.equals(ScriptTranferable.myData)) { + return true; + } + } + + return false; + } + + @Override + public boolean importData(JComponent component, Transferable transferable) { + + boolean confirmImport = false; + + /*if (transferable.isDataFlavorSupported(FactorTranferable.myData)) { + try { + + FactorTree factorTree = (FactorTree) component; + FactorGroup selectedFactorGroup = factorTree.getSelectedFactorGroup(); + + if (selectedFactorGroup != null) { + Object myObject = transferable.getTransferData(FactorTranferable.myData); + List<Factor> movedFactors = (List<Factor>) myObject; + } + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Exception while transfering task", e); + } + } catch (UnsupportedFlavorException e) { + if (log.isErrorEnabled()) { + log.error("Exception while transfering task", e); + } + } + }*/ + + confirmImport = true; + + return confirmImport; + + } + + /** + * Get selected task in tree, and build Transferable object for it. + * + * @param cp component + * @return transferable instance for selected task + */ + @Override + protected Transferable createTransferable(JComponent cp) { + + Transferable transferable = null; + + ScriptTree scriptTree = (ScriptTree) cp; + // only task can be moved ! + List<File> selectedFiles = scriptTree.getSelectedFiles(); + if (CollectionUtils.isNotEmpty(selectedFiles)) { + List<File> files = new LinkedList<File>(selectedFiles); + transferable = new ScriptTranferable(files); + } + + return transferable; + } + + @Override + protected void exportDone(JComponent cp, Transferable transferable, int type) { + if (log.isDebugEnabled()) { + log.debug("Transfert done"); + } + + if (type == TransferHandler.MOVE) { + + try { + ScriptTree factorTree = (ScriptTree) cp; + // elements here, task can be move to directory only + File directory = factorTree.getSelectedDirectory(); + + if (directory != null) { + Object myObject = transferable.getTransferData(ScriptTranferable.myData); + List<File> movedFiles = (List<File>) myObject; + scriptUI.getScriptAction().moveFiles(directory, movedFiles); + } + } catch (IOException e) { + if (log.isErrorEnabled()) { + log.error("Exception while transfering task", e); + } + } catch (UnsupportedFlavorException e) { + if (log.isErrorEnabled()) { + log.error("Exception while transfering task", e); + } + } + } + } + + @Override + public int getSourceActions(JComponent component) { + return MOVE; + } +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTransferHandler.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTree.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTree.java (rev 0) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTree.java 2011-06-14 13:21:14 UTC (rev 3392) @@ -0,0 +1,114 @@ +/* + * #%L + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-2.0.html>. + * #L% + */ + +package fr.ifremer.isisfish.ui.script.model; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JTree; +import javax.swing.tree.TreePath; + +import fr.ifremer.isisfish.ui.script.ScriptUI; + +/** + * Factor tree. + * + * Add drag and drop support. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class ScriptTree extends JTree { + + /** serialVersionUID. */ + private static final long serialVersionUID = 1999481128072081972L; + + /** + * Constructor (add drag and drop). + * + * @param scriptUI script ui + */ + public ScriptTree(ScriptUI scriptUI) { + // enable drag n drop + setDragEnabled(true); + setTransferHandler(new ScriptTransferHandler(scriptUI)); + } + + /** + * Return selected files (only files not directories). + * + * @return selected files + */ + public List<File> getSelectedFiles() { + + List<File> selectedFiles = new ArrayList<File>(); + + TreePath[] selectedPaths = getSelectionModel().getSelectionPaths(); + if (selectedPaths != null) { + for (TreePath selectedPath : selectedPaths) { + if (selectedPath != null) { + Object[] pathWay = selectedPath.getPath(); + + File selectedFile = (File)pathWay[pathWay.length - 1]; + if (selectedFile.isFile()) { + selectedFiles.add(selectedFile); + } + } + } + } + + return selectedFiles; + } + + /** + * Return selected directory. + * + * @return selected directory + */ + public File getSelectedDirectory() { + + File selectedDirectory = null; + + TreePath[] selectedPaths = getSelectionModel().getSelectionPaths(); + if (selectedPaths != null) { + for (TreePath selectedPath : selectedPaths) { + if (selectedPath != null) { + Object[] pathWay = selectedPath.getPath(); + + File selectedFile = (File)pathWay[pathWay.length - 1]; + if (selectedFile.isDirectory()) { + selectedDirectory = selectedFile; + break; + } + } + } + } + + return selectedDirectory; + } +} Property changes on: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTree.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeCellRenderer.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeCellRenderer.java 2011-06-14 13:20:31 UTC (rev 3391) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeCellRenderer.java 2011-06-14 13:21:14 UTC (rev 3392) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2009 - 2010 Ifremer, CodeLutin + * Copyright (C) 2009 - 2011 Ifremer, CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -25,6 +25,8 @@ package fr.ifremer.isisfish.ui.script.model; +import static org.nuiton.i18n.I18n._; + import java.awt.Color; import java.awt.Component; import java.io.File; @@ -58,7 +60,7 @@ /** Class logger. */ private static Log log = LogFactory.getLog(ScriptTreeCellRenderer.class); - + /* * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean) */ @@ -68,10 +70,14 @@ boolean hasFocus) { JLabel c = (JLabel)super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); - - if (value instanceof File) { + + if (value == IsisFish.vcs) { + c.setText(_("isisfish.ui.script.officialvcs")); + } else if (value == IsisFish.communityVcs) { + c.setText(_("isisfish.ui.script.communityvcs")); + } else if (value instanceof File) { File file = (File)value; - + try { if (file.isFile()) { if (IsisFish.vcs.getLocalStatus(file) == Status.STATUS_MODIFIED) { @@ -96,7 +102,12 @@ log.error("Can't get file status", e); } } - c.setText(file.getName()); + + String prefix = ""; + if (file.isDirectory() && file.getParentFile().equals(IsisFish.communityVcs.getLocalRepository())) { + prefix = "Community "; + } + c.setText(prefix + file.getName()); } return c; Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeModel.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeModel.java 2011-06-14 13:20:31 UTC (rev 3391) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/script/model/ScriptTreeModel.java 2011-06-14 13:21:14 UTC (rev 3392) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2009 - 2010 Ifremer, CodeLutin + * Copyright (C) 2009 - 2011 Ifremer, CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -28,7 +28,9 @@ import java.io.File; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; @@ -47,10 +49,19 @@ import fr.ifremer.isisfish.datastore.SensitivityExportStorage; import fr.ifremer.isisfish.datastore.SensitivityStorage; import fr.ifremer.isisfish.datastore.SimulatorStorage; +import fr.ifremer.isisfish.vcs.VCS; /** * Tree model for scripts edition. * + * Tree model is structured as this : + * <pre> + * - root + * - vcs + * - categories + * - files + * </pre> + * * @author chatellier * @version $Revision$ * @@ -61,11 +72,15 @@ /** Class logger. */ private static Log log = LogFactory.getLog(ScriptTreeModel.class); - + protected TreeModelSupport modelSupport; - public List<File> rootFiles; + /** VCS list. */ + protected List<VCS> vcsList = new ArrayList<VCS>(); + /** Categories files for VCS. */ + protected Map<VCS, List<File>> rootFiles; + /** Add node operation */ public static final int OPERATION_ADD = 0; /** Modify node operation */ @@ -76,15 +91,25 @@ public ScriptTreeModel() { modelSupport = new TreeModelSupport(this); - rootFiles = new ArrayList<File>(); - rootFiles.add(AnalysePlanStorage.getAnalysePlanDirectory()); - rootFiles.add(ExportStorage.getExportDirectory()); - rootFiles.add(FormuleStorage.getFormuleDirectory()); - rootFiles.add(RuleStorage.getRuleDirectory()); - rootFiles.add(ScriptStorage.getScriptDirectory()); - rootFiles.add(SensitivityExportStorage.getSensitivityExportDirectory()); - rootFiles.add(SensitivityStorage.getSensitivityDirectory()); - rootFiles.add(SimulatorStorage.getSimulatorDirectory()); + rootFiles = new HashMap<VCS, List<File>>(); + List<File> offFiles = new ArrayList<File>(); + offFiles.add(AnalysePlanStorage.getAnalysePlanDirectory()); + offFiles.add(ExportStorage.getExportDirectory()); + offFiles.add(FormuleStorage.getFormuleDirectory()); + offFiles.add(RuleStorage.getRuleDirectory()); + offFiles.add(ScriptStorage.getScriptDirectory()); + offFiles.add(SensitivityExportStorage.getSensitivityExportDirectory()); + offFiles.add(SensitivityStorage.getSensitivityDirectory()); + offFiles.add(SimulatorStorage.getSimulatorDirectory()); + + List<File> comFiles = new ArrayList<File>(); + comFiles.add(SimulatorStorage.getCommunitySimulatorDirectory()); + + rootFiles.put(IsisFish.vcs, offFiles); + rootFiles.put(IsisFish.communityVcs, comFiles); + + vcsList.add(IsisFish.vcs); + vcsList.add(IsisFish.communityVcs); } /* @@ -103,10 +128,11 @@ Object result = null; - if (parent == rootFiles) { - result = rootFiles.get(index); - } - else { + if (parent == vcsList) { + result = vcsList.get(index); + } else if (parent instanceof VCS) { + result = rootFiles.get(parent).get(index); + } else { File parentFile = (File)parent; File[] filesArray = parentFile.listFiles(); List<File> files = getVersionnableSortedFiles(filesArray); @@ -121,12 +147,13 @@ */ @Override public int getChildCount(Object parent) { - + int count = 0; - if (parent == rootFiles) { - count = rootFiles.size(); - } - else { + if (parent == vcsList) { + count = vcsList.size(); + } else if (parent instanceof VCS) { + count = rootFiles.get(parent).size(); + } else { File parentFile = (File)parent; File[] filesArray = parentFile.listFiles(); if ( filesArray != null) { @@ -143,10 +170,11 @@ @Override public int getIndexOfChild(Object parent, Object child) { int index = 0; - if (parent == rootFiles) { - index = rootFiles.indexOf(child); - } - else { + if (parent == vcsList) { + index = vcsList.indexOf(child); + } else if (parent instanceof VCS) { + index = rootFiles.get(parent).indexOf(child); + } else { File parentFile = (File)parent; File[] filesArray = parentFile.listFiles(); List<File> files = getVersionnableSortedFiles(filesArray); @@ -160,7 +188,7 @@ */ @Override public Object getRoot() { - return rootFiles; + return vcsList; } /* @@ -168,7 +196,13 @@ */ @Override public boolean isLeaf(Object node) { - return getChildCount(node) == 0; + boolean result = false; + + if (node instanceof File) { + result = ((File)node).isFile(); + } + + return result; } /* @@ -198,6 +232,8 @@ for (File fileArray : filesArray) { if (IsisFish.vcs.isVersionnableFile(fileArray)) { files.add(fileArray); + } else if (IsisFish.communityVcs.isVersionnableFile(fileArray)) { + files.add(fileArray); } } Collections.sort(files); @@ -305,7 +341,7 @@ * @return tree path */ public TreePath getTreePathFor(File file) { - TreePath path = new TreePath(rootFiles); + TreePath path = new TreePath(vcsList); path = getRecursiveTreePath(file, path); return path; } Modified: isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties =================================================================== --- isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties 2011-06-14 13:20:31 UTC (rev 3391) +++ isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_en_GB.properties 2011-06-14 13:21:14 UTC (rev 3392) @@ -962,6 +962,8 @@ isisfish.tripType.duration=Duration isisfish.tripType.minTime=Minimum time between trips isisfish.tripType.name=Name +isisfish.ui.script.communityvcs=Community VCS +isisfish.ui.script.officialvcs=Official VCS isisfish.vcs.ask.passphrase=Enter your pass phrase (if your private key have one). isisfish.vcs.ask.passphrase.title=Ask your pass phrase isisfish.vcs.commit=vcs.commit Modified: isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties =================================================================== --- isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties 2011-06-14 13:20:31 UTC (rev 3391) +++ isis-fish/branches/3.3.1/src/main/resources/i18n/isis-fish_fr_FR.properties 2011-06-14 13:21:14 UTC (rev 3392) @@ -962,6 +962,8 @@ isisfish.tripType.duration=Durée isisfish.tripType.minTime=Temps minimal entre deux voyages isisfish.tripType.name=Nom +isisfish.ui.script.communityvcs=VCS Communauté +isisfish.ui.script.officialvcs=VCS Officiel isisfish.vcs.ask.passphrase=Entrez votre passphrase (si votre clef ssh en contient une). isisfish.vcs.ask.passphrase.title=Demande de passe phrase isisfish.vcs.commit=Message de sauvegarde