    001package org.vishia.guiBzr;
    002
    003import java.io.File;
    004import java.util.ArrayList;
    005import java.util.LinkedList;
    006import java.util.List;
    007
    008import org.vishia.gral.base.GralTable;
    009import org.vishia.gral.base.GralWidget;
    010import org.vishia.gral.ifc.GralButtonKeyMenu;
    011import org.vishia.gral.ifc.GralMngBuild_ifc;
    012import org.vishia.gral.ifc.GralTableLine_ifc;
    013import org.vishia.gral.ifc.GralUserAction;
    014import org.vishia.gral.ifc.GralWidget_ifc;
    015import org.vishia.util.FileSystem;
    016import org.vishia.util.KeyCode;
    017import org.vishia.util.StringFormatter;
    018import org.vishia.util.FileSystem.FileAndBasePath;
    019
    020/**The panel which contains a table to select SVM archive locations
    021 * @author Hartmut Schorrig
    022 * @since 2013.03-29
    023 *
    024 */
    025public class GuiSelectPanel
    026{
    027
    028  String sWorkingTreeBaseDir = "D:/Bzr/D";
    029
    030  String sArchiveTreeBaseDir = "D:/Bzr/Archive";
    031
    032  String sRemoteArchiveTreeBaseDir = "A:/Bzr/Archive";
    033
    034  StringFormatter formatter = new StringFormatter();
    035
    036  /**TODO only private local using here, it should be a part of DataProject.
    037   *
    038   */
    039  //List<File> listBzrDirs = new LinkedList<File>();
    040
    041  List<FileAndBasePath> listBzrDirs = new ArrayList<FileAndBasePath>();
    042
    043
    044  /**Aggregation to the main data of the GUI. */
    045  final MainData mainData;
    046
    047  /**Aggregation to the build interface of the manager where the panel is member of. */
    048  final GralMngBuild_ifc mng;
    049
    050  GralTable tableSelect;
    051
    052  /**Widget to select the project path.
    053   * The project is a user-project which contains one or more source archive-sandboxes.
    054   *
    055   * */
    056  GralWidget widgdProjektpath;
    057
    058  public GuiSelectPanel(MainData mainData, GralMngBuild_ifc panelBuildifc)
    059  {
    060    this.mng = panelBuildifc;
    061    this.mainData = mainData;
    062  }
    063
    064
    065  /**Initializes the graphic.
    066   * It will be called in the GUI-Thread.
    067   */
    068  void initGui(){
    069    mng.selectPanel("Select");
    070    mng.setPosition(0,2,0,30,0,'r',0);
    071    mng.addText("Component");
    072    mng.addText("Working Tree");
    073    mng.addText("Archive Tree");
    074    mng.addText("Remote Tree");
    075    mng.setPosition(2,-3,0,0,0,'.',0);
    076    int[] columns = {30,30,30,30};
    077    tableSelect = mng.addTable("selectTable", 100, columns);
    078    tableSelect.specifyActionOnLineSelected(actionOnSelectedLine);
    079    mng.setPosition(-3,0,0,9,0,'.',1);
    080    //
    081    String fnkey = "cleanSelectTable";
    082    GralButtonKeyMenu fn = mainData.panels.idents.get(fnkey);
    083    mng.addButton(fnkey+"-button", fn.action, fn.buttontext);
    084    //
    085    fnkey = "statusCmpn";
    086    fn = mainData.panels.idents.get(fnkey);
    087    mng.addButton(fnkey+"-button", fn.action, fn.buttontext);
    088    //
    089    fnkey = "revertAll";
    090    fn = mainData.panels.idents.get(fnkey);
    091    mng.addButton(fnkey+"-button", fn.action, fn.buttontext);
    092  }
    093
    094
    095
    096  /**Searches all locations of source-archives in the current project folder and all sub folders.
    097   * A project means a software project with some sources consisting of some Components with its own archives.
    098   * @calls {@link #captureStatus(DataCmpn)} for all found software-archives.
    099   * @param sProjectPath Path to the project folder.
    100   *
    101   */
    102  void getBzrLocations()
    103  {
    104    listBzrDirs.clear();
    105    try{
    106      File baseDirAllCmpn = new File(sWorkingTreeBaseDir);
    107      FileSystem.addFilesWithBasePath(baseDirAllCmpn, "/**/.bzr", listBzrDirs);
    108      //FileSystem.addFileToList(sWorkingTreeBaseDir + "/**/.bzr", listBzrDirs);
    109    } catch(Exception exc){
    110
    111    }
    112    int zCmpn = listBzrDirs.size();
    113    mainData.currPrj.init(zCmpn);
    114    //int ixCmpn = 0;
    115    tableSelect.clearTable();
    116    File dirBaseArchive = new File(sArchiveTreeBaseDir);
    117    File dirBaseRemoteArchive = new File(sRemoteArchiveTreeBaseDir);
    118    if(!dirBaseRemoteArchive.exists()){
    119      dirBaseRemoteArchive = null;
    120    }
    121    for(FileAndBasePath entrylist: listBzrDirs){
    122      File fileBzr = entrylist.file;
    123      File dirArchive = new File(dirBaseArchive, entrylist.localPath);
    124      File dirRemoteArchive = dirBaseRemoteArchive == null ? null : new File(dirBaseRemoteArchive, entrylist.localPath);
    125      File dirWorkingTree = fileBzr.getParentFile();
    126      String nameCmpn = dirWorkingTree.getName();
    127      String[] cellTexts = new String[4];
    128      cellTexts[0] = entrylist.localPath;
    129      cellTexts[1] = "?";
    130      cellTexts[2] = "?";
    131      cellTexts[3] = "?";
    132      DataCmpn dataCmpn = new DataCmpn(dirWorkingTree, dirArchive, dirRemoteArchive);
    133      tableSelect.addLine(nameCmpn, cellTexts, dataCmpn);
    134    }
    135  }
    136
    137
    138
    139
    140
    141
    142
    143
    144  GralUserAction actionRefreshSelectTable = new GralUserAction("actionRefreshSelection"){
    145    @Override public boolean exec(int actionCode, GralWidget_ifc widgi, Object... oArgs){
    146      if(KeyCode.isControlFunctionMouseUpOrMenu(actionCode)){
    147        getBzrLocations();
    148      }
    149      return true;
    150    }
    151  };
    152
    153
    154
    155  /**Gets the status for the Component of the actual line, refresh the line. */
    156  GralUserAction actionGetStatus = new GralUserAction("actionGetStatus"){
    157    @Override public boolean exec(int actionCode, GralWidget_ifc widgi, Object... oArgs){
    158      if(KeyCode.isControlFunctionMouseUpOrMenu(actionCode)){
    159        if(mainData.currTableline !=null){
    160          mainData.getterStatus.captureStatusAllArchives(mainData.currCmpn);
    161
    162          formatter.reset();
    163          String sDate = formatter.convertTimestampToday(mainData.currCmpn.revisionWorkingTreeTop.date);
    164          if(mainData.currCmpn.revisionWorkingTreeTop.nr !=null){
    165            formatter.add(sDate).add(": rev=").add(mainData.currCmpn.revisionWorkingTreeTop.nr);
    166          } else {
    167            formatter.add("not found");
    168          }
    169          mainData.currTableline.setCellText(formatter.getContent(), 1);
    170
    171          formatter.reset();
    172          if(mainData.currCmpn.revisionArchive.nr !=null){
    173            sDate = formatter.convertTimestampToday(mainData.currCmpn.revisionArchive.date);
    174            formatter.add(sDate).add(": rev=").add(mainData.currCmpn.revisionArchive.nr);
    175            mainData.currTableline.setCellText(formatter.getContent(), 2);
    176          } else {
    177            mainData.currTableline.setCellText("not available", 2);
    178          }
    179
    180          if(mainData.currCmpn.dirRemoteArchive !=null){
    181            formatter.reset();
    182            sDate = formatter.convertTimestampToday(mainData.currCmpn.revisionRemoteArchive.date);
    183            formatter.add(sDate).add(": rev=").add(mainData.currCmpn.revisionRemoteArchive.nr);
    184            mainData.currTableline.setCellText(formatter.getContent(), 3);
    185          } else {
    186            mainData.currTableline.setCellText("not available", 3);
    187          }
    188        }
    189        return true;
    190      } else return false;
    191    }
    192  };
    193
    194
    195
    196  GralUserAction actionOnSelectedLine = new GralUserAction("actionRefreshSelectCmpn"){
    197    @Override public boolean exec(int actionCode, GralWidget_ifc widgi, Object... oArgs){
    198      assert(oArgs.length >=1 && oArgs[0] instanceof GralTableLine_ifc);
    199      mainData.currTableline = (GralTableLine_ifc)oArgs[0];
    200      mainData.currCmpn = (DataCmpn)mainData.currTableline.getUserData();
    201      return true;
    202    }
    203  };
    204
    205
    206}