    001package org.vishia.guiBzr;
    002
    003import java.io.File;
    004
    005import org.vishia.gral.base.GralPanelContent;
    006import org.vishia.gral.base.GralTable;
    007import org.vishia.gral.base.GralWidget;
    008import org.vishia.gral.base.GralWindow;
    009import org.vishia.gral.ifc.GralMngBuild_ifc;
    010import org.vishia.gral.ifc.GralMng_ifc;
    011import org.vishia.gral.ifc.GralWindow_ifc;
    012import org.vishia.gral.ifc.GralUserAction;
    013import org.vishia.gral.ifc.GralTableLine_ifc;
    014import org.vishia.gral.widget.GralSwitchExclusiveButtonMng;
    015import org.vishia.util.FileSystem;
    016import org.vishia.util.KeyCode;
    017
    018/**This class contains all data and methods of the status (select) panel.
    019 *
    020 * @author Hartmut Schorrig
    021 *
    022 */
    023public class GuiStatusPanel
    024{
    025
    026  private static class SelectInfoBoxWidgds
    027  {
    028    final GralPanelContent box;
    029    final DataCmpn data;
    030    GralWidget widgdTextRevision, widgdTextStatus;
    031
    032    SelectInfoBoxWidgds(GralPanelContent box, DataCmpn data)
    033    { this.box = box; this.data = data; }
    034
    035  }
    036
    037  /**Aggregation to the main data of the GUI. */
    038  final MainData mainData;
    039
    040  /**Aggregation to the build interface of the manager where the panel is member of. */
    041  final GralMngBuild_ifc panelBuildifc;
    042
    043
    044  /**Widget to select the project path.
    045   * The project is a user-project which contains one or more source archive-sandboxes.
    046   *
    047   * */
    048  GralWidget widgdProjektpath;
    049
    050
    051  /**A Panel which contains the table to select some projectPaths. */
    052  private GralWindow selectorProjectPath;
    053
    054  /**The table (list) which contains the selectable project paths. */
    055  private GralTable selectorProjectPathTable;
    056
    057
    058  /**Any component has its PanelManager. It is one line with some widgets.
    059   */
    060  private final GralPanelContent[] bzrComponentBox = new GralPanelContent[100];
    061
    062  private GralWindow_ifc testDialogBox;
    063
    064
    065  /**Instance for some buttons to exclude switch on only for one button.
    066   * GUI-concept: This is an alternative to TODO
    067   *
    068   */
    069  private GralSwitchExclusiveButtonMng switchExcluder;
    070
    071  /**Save the switchButtons to remove it when the widget is removed. */
    072  private GralWidget[] switchButtons;
    073
    074
    075  public GuiStatusPanel(MainData mainData, GralMngBuild_ifc panelBuildifc)
    076  {
    077    this.panelBuildifc = panelBuildifc;
    078    this.mainData = mainData;
    079  }
    080
    081  /**Initializes the graphic.
    082   * It will be called in the GUI-Thread.
    083   */
    084  void initGui()
    085  { int xposProjectPath = 0, yposProjectPath=5;
    086
    087    panelBuildifc.selectPanel("Select-old");
    088    panelBuildifc.setPositionSize(yposProjectPath, xposProjectPath, -3, 70, 'r');
    089    //widgdProjektpath = panelBuildifc.addTextField("projectPath", true, "Project path", 't');
    090    widgdProjektpath = panelBuildifc.addFileSelectField("projectPath", null, "D:/:/", "Project path", "t");
    091    panelBuildifc.setPositionSize(-1, -1, -2, 2, 'r');
    092    panelBuildifc.addButton("selectProjectPath", selectProjectPath, "c", "f", "?");
    093    ///
    094    //WidgetDescriptor widgdRefresh = new WidgetDescriptor("refresh", 'B');
    095    //widgdRefresh.setAction(refreshProjectBzrComponents);
    096    panelBuildifc.setPositionSize(-1, -1, -3, 10, 'r');
    097    panelBuildifc.addButton("Brefresh", refreshProjectBzrComponents, "c", "d", "Get/Refresh");
    098
    099    String[] lines = {"1", "2"};
    100
    101    //testDialogBox = panelBuildifc.createInfoBox( "Title", lines, true);
    102    //testDialogBox = new InfoBox(mainData.guifc.getitsGraphicFrame(), "Title", lines, true);
    103
    104    panelBuildifc.setPositionSize(yposProjectPath, xposProjectPath, 20, 60, 'r');
    105    selectorProjectPath = panelBuildifc.createWindow("sel", null, GralWindow.windConcurrently);
    106    int[] columnWidths = {40, 10};
    107    panelBuildifc.setPositionSize(0, 0, 10, 60, 'd');
    108    selectorProjectPathTable = panelBuildifc.addTable("selectProjectPath", 20, columnWidths);
    109    selectorProjectPathTable.setActionChange(actionSelectorProjectPathTable);
    110    panelBuildifc.setPositionSize(20, 0, -3, 10, 'r');
    111    panelBuildifc.addButton("closeProjectBzrComponents", actionCloseProjectBzrComponents, "ok");
    112    String sPrjPath = null;
    113    for(String sPrjPath1: mainData.cfg.listSwPrjs){
    114      if(sPrjPath ==null){ sPrjPath = sPrjPath1; } //The first is offered.
    115      GralTableLine_ifc<Object> line = selectorProjectPathTable.insertLine(sPrjPath1, 0, null, null);
    116      line.setCellText(sPrjPath1, 0);
    117    }
    118    if(sPrjPath==null){
    119      sPrjPath = "??no project directories found.";
    120    }
    121    //Test only in one Project
    122    widgdProjektpath.setValue(GralMng_ifc.cmdInsert, 0,sPrjPath);
    123    mainData.currPrj = new DataProject(FileSystem.absolutePath(sPrjPath, null));
    124
    125  }
    126
    127
    128  /**Removes all existing GUI-container for selection and info of the components.
    129   * It is called if a new project is selected.
    130   */
    131  private void cleanComponentsInfoSelectBoxes()
    132  {
    133    if(bzrComponentBox !=null){
    134      panelBuildifc.selectPanel("Select");
    135      for(int ii=0; ii< bzrComponentBox.length; ++ii){
    136        GralPanelContent item = bzrComponentBox[ii];
    137        if(item !=null){
    138          bzrComponentBox[ii] = null;
    139          panelBuildifc.remove(item);
    140        }
    141      }
    142    }
    143  }
    144
    145
    146  /**Builds all select and info GUI-components for all source-components of the given project.
    147   *
    148   */
    149  private void buildComponentsInfoSelectBoxes()
    150  {
    151    String sProjectPath = widgdProjektpath.getValue();
    152    sProjectPath = "d:/Bzr/D/vishia";
    153    //
    154    mainData.getterStatus.getBzrLocations(FileSystem.absolutePath(sProjectPath, null));
    155    //
    156    cleanComponentsInfoSelectBoxes();
    157    switchExcluder = new GralSwitchExclusiveButtonMng();
    158    switchButtons = new GralWidget[mainData.currPrj.data.length];
    159    //
    160    //Only one of the switch buttons are checked. If another button is pressed, it should be deselect.
    161    //The switchExcluder helps to do so.
    162    //It contains a special method, which captures the text of the last pressed switch button.
    163    for(int ixCmpn = 0; ixCmpn < mainData.currPrj.data.length; ++ixCmpn){
    164      createComponentsInfoSelectBox(ixCmpn);
    165    }
    166  }
    167
    168
    169
    170  private void createComponentsInfoSelectBox(int iComponent)
    171  { int yPosComponents = 10 + 2* iComponent;
    172    if(bzrComponentBox[iComponent]!=null){
    173      panelBuildifc.remove(bzrComponentBox[iComponent]);
    174    }
    175    DataCmpn data = mainData.currPrj.data[iComponent];
    176    String sName = data.getBzrLocationDir().getName();
    177    String sNamePanel = "BzrStatusSelect-"+sName;
    178    panelBuildifc.selectPanel("Select");
    179    panelBuildifc.setPositionSize(yPosComponents, 1, 2, 70, 'r');
    180    GralPanelContent box;
    181    bzrComponentBox[iComponent] = box = panelBuildifc.createCompositeBox(sNamePanel);
    182    SelectInfoBoxWidgds widgds = new SelectInfoBoxWidgds(box,data);
    183    panelBuildifc.selectPanel(sNamePanel);
    184    panelBuildifc.setPositionSize(0, 0, 2, 2, 'r');
    185    if(switchButtons[iComponent] !=null){
    186      switchExcluder.remove(switchButtons[iComponent]);
    187    }
    188    GralWidget widgdButton = panelBuildifc.addSwitchButton("selectMain", actionSelectCmpn, "", data.sNameCmpn, "", "wh", "rd");
    189    switchExcluder.add(widgdButton);
    190    widgdButton.setContentInfo(widgds);
    191    switchButtons[iComponent] = widgdButton;
    192    panelBuildifc.setPositionSize(0, 6, 2, 15, 'r');
    193    panelBuildifc.addText(sName, 'B', 0);
    194    widgds.widgdTextRevision = panelBuildifc.addText("Rev. unknown", 'B', 0x808080);
    195    widgds.widgdTextStatus = panelBuildifc.addText("- select it", 'B', 0x808080);
    196
    197  }
    198
    199
    200  private void setInfoWidgetsInSelectBox(SelectInfoBoxWidgds widgds)
    201  {
    202    panelBuildifc.selectPanel(widgds.box.name);
    203    panelBuildifc.remove(widgds.widgdTextRevision);
    204    panelBuildifc.remove(widgds.widgdTextStatus);
    205    panelBuildifc.setPositionSize(0, 21, 2, 15, 'r');
    206    String sRev = "Rev. ";
    207    if(widgds.data.revisionWorkingTreeTop.nr == widgds.data.revisionSbox.nr){
    208      sRev = "Rev. " + widgds.data.revisionSbox.nr + " uptodate ";
    209    } else {
    210      sRev = "Rev. " + widgds.data.revisionSbox.nr + " / "+ widgds.data.revisionWorkingTreeTop.nr;
    211    }
    212    widgds.widgdTextRevision = panelBuildifc.addText(sRev, 'B', 0x0);
    213    String sBzrStatus = widgds.data.uBzrStatusOutput.toString();
    214    boolean isModified = sBzrStatus.indexOf("modified:") >=0;
    215    boolean hasNew = sBzrStatus.indexOf("non-versioned:") >=0;
    216    if(isModified){
    217      //bzrComponentBox[iComponent].setPosition(0, 40, 2, 10, 'r');
    218      widgds.widgdTextStatus = panelBuildifc.addText("- modified", 'B', 0xff0000);
    219    } else if(hasNew){
    220      //bzrComponentBox[iComponent].setPosition(0, 40, 2, 10, 'r');
    221      widgds.widgdTextStatus = panelBuildifc.addText("- new Files", 'B', 0xff0000);
    222    } else {
    223      widgds.widgdTextStatus = panelBuildifc.addText("- no changes", 'B', 0x00ff00);
    224    }
    225    panelBuildifc.repaintCurrentPanel();
    226  }
    227
    228
    229
    230  private final GralUserAction selectProjectPath = new GralUserAction()
    231  {
    232    @Override public boolean userActionGui(int key, GralWidget widgetInfos, Object... values)
    233    {
    234      //testDialogBox.open();
    235      selectorProjectPath.setWindowVisible(true);
    236      return true;
    237    }
    238  };
    239
    240
    241
    242  /**Action if a line is confirmed.
    243   * If a line is confirmed, the path is set to {@link #widgdProjektpath}.
    244   * If the top line is leaved, the table will be closed.
    245   *
    246   */
    247  private final GralUserAction actionSelectorProjectPathTable = new GralUserAction()
    248  {
    249    @Override
    250    public boolean userActionGui(int key, GralWidget widgetInfos, Object... values)
    251    { boolean bDone = true;
    252      if(key == KeyCode.enter){
    253        GralTableLine_ifc line = (GralTableLine_ifc)values[0];
    254        String sPath = line.getCellText(0);
    255        widgdProjektpath.setValue(GralMng_ifc.cmdInsert, 0, sPath);
    256        buildComponentsInfoSelectBoxes();
    257        selectorProjectPath.setWindowVisible(false);
    258      } else { bDone = false; }
    259      return bDone;
    260    }
    261  };
    262
    263
    264  private final GralUserAction actionCloseProjectBzrComponents = new GralUserAction()
    265  {
    266    @Override
    267    public boolean userActionGui(int key, GralWidget widgetInfos, Object... values)
    268    {
    269      selectorProjectPath.setWindowVisible(false);
    270      return true;
    271    }
    272  };
    273
    274
    275  private final GralUserAction refreshProjectBzrComponents = new GralUserAction()
    276  {
    277    @Override
    278    public boolean userActionGui(int key, GralWidget widgetInfos, Object... values)
    279    { buildComponentsInfoSelectBoxes();
    280      return true;
    281    }
    282  };
    283
    284
    285
    286  private final GralUserAction actionSelectCmpn = new GralUserAction()
    287  {
    288    @Override
    289    public boolean userActionGui(int key, GralWidget widgd, Object... values)
    290    {
    291      mainData.currCmpn = mainData.currPrj.selectComponent(widgd.getDataPath());
    292      //
    293      //gets the status of the components archive in the GUI-action,
    294      //because the appearance of the GUI should be updated:
    295      mainData.getterStatus.captureStatus(mainData.currCmpn);
    296      //
    297      //Build the GUI widgets for this project new:
    298      //it is an example for dynamic GUI appearance.
    299      //Here it may be possible too to set only other information to the given widgets.
    300      SelectInfoBoxWidgds widgds = (SelectInfoBoxWidgds)widgd.getContentInfo();
    301      setInfoWidgetsInSelectBox(widgds);
    302      //
    303      //Gets all information about files in background.
    304      //It is necessary in another panel (Files & Diff).
    305      mainData.addOrderBackground(mainData.mainAction.initNewComponent);
    306
    307      //call the exclusion of the other button:
    308      switchExcluder.switchAction.userActionGui(key, widgd, values);
    309      return true;
    310    }
    311  };
    312
    313
    314  void stop(){}
    315}