    001package org.vishia.guiBzr;
    002
    003import java.io.File;
    004
    005import org.vishia.communication.InterProcessCommFactorySocket;
    006import org.vishia.gral.area9.GuiCallingArgs;
    007import org.vishia.gral.area9.GuiCfg;
    008import org.vishia.gral.area9.GralArea9MainCmd;
    009import org.vishia.gral.base.GralTextBox;
    010import org.vishia.gral.base.GralTextField;
    011import org.vishia.gral.base.GralWindow;
    012import org.vishia.gral.ifc.GralWindow_ifc;
    013import org.vishia.mainCmd.MainCmd_ifc;
    014import org.vishia.util.FileSystem;
    015
    016public class BzrGui extends GuiCfg
    017{
    018  /**Version, able to read as hex yyyymmdd.
    019   * Changes:
    020   * <ul>
    021   * <li>2011-05-17 new association panelOutput to the output panel for any outputs. It is used yet
    022   *     for the diff output.
    023   * <li>2011-05-01 Hartmut: Created
    024   * </ul>
    025   */
    026  @SuppressWarnings("hiding")
    027  public final static int version = 0x20110617;
    028
    029  /**The command-line-arguments may be stored in an extra class, which can arranged in any other class too.
    030   * The separation of command line argument helps to invoke the functionality with different calls,
    031   * for example calling in a GUI, calling in a command-line-batch-process or calling from ANT
    032   */
    033  static class CallingArguments extends GuiCallingArgs
    034  {
    035    /**This file contains all bzr commands and the pathes of the users sandboxes. */
    036    File fileCfg;
    037  } //class CallingArguments
    038
    039
    040
    041  final CallingArguments cargs;
    042
    043  final MainData mainData;
    044
    045  final BzrIdents idents;
    046
    047  /**This instance helps to create the Dialog Widget as part of the whole window. It is used only in the constructor.
    048   * Therewith it may be defined stack-locally. But it is better to show and explain if it is access-able at class level. */
    049  //GuiDialogZbnfControlled dialogZbnfConfigurator;
    050
    051
    052
    053  /**Panel-Management-interface for the panels. */
    054  //GuiPanelMngBuildIfc panelBuildifc;
    055
    056
    057
    058
    059
    060
    061
    062
    063
    064  //private GuiPanelMngBase panelMng;
    065
    066
    067  final GuiStatusPanel guiStatusPanel;
    068
    069  final GuiSelectPanel guiSelectPanel;
    070
    071  final GuiCommitPanel guiCommitPanel;
    072
    073  final PanelOutput panelOutput;
    074
    075  final GuiFilesDiffPanel guiFilesDiffPanel;
    076
    077  /**ctor for the main class of the application.
    078   * The main class can be created in some other kinds as done in static main too.
    079   * But it needs the {@link MainCmdWin}.
    080   * <br><br>
    081   * The ctor checks whether a gUI-configuration file is given. If not then the default configuration is used.
    082   * It is especially for the Sample.
    083   * <br><br>
    084   * The the GUI will be completed with the content of the GUI-configuration file.
    085   *
    086   * @param cargs The given calling arguments.
    087   * @param gui The GUI-organization.
    088   */
    089  BzrGui(CallingArguments cargs, GralArea9MainCmd cmdgui)
    090  { super(cargs, cmdgui, null, null, null);  //builds all graphic panels
    091    this.cargs = cargs;  //args in the correct derived type.
    092    //boolean bOk = true;
    093
    094
    095    mainData = new MainData(cmdgui, this);
    096    String sError = mainData.cfg.readConfig(cargs.fileCfg);
    097    if(sError !=null){
    098      cmdgui.writeError(sError);
    099    }
    100
    101    mainData.panelAccess = _gralMng;
    102
    103    mainData.guifc = this.gui;
    104
    105    //creates the panel classes in constructor, don't initialize the GUI yet.
    106    guiSelectPanel = new GuiSelectPanel(mainData, panelBuildIfc);
    107    guiStatusPanel = new GuiStatusPanel(mainData, panelBuildIfc);
    108    guiCommitPanel = new GuiCommitPanel(mainData, panelBuildIfc);
    109    guiFilesDiffPanel = new GuiFilesDiffPanel(mainData, panelBuildIfc);
    110
    111    panelOutput = new PanelOutput(mainData, panelBuildIfc);
    112
    113    mainData.mainAction = new MainAction(mainData, guiStatusPanel, guiCommitPanel, guiFilesDiffPanel, panelOutput);
    114
    115
    116    idents = new BzrIdents();
    117    idents.initIdents(mainData);
    118
    119
    120
    121  }
    122
    123
    124
    125  //GuiDispatchCallbackWorker configGui = new GuiDispatchCallbackWorker()
    126  //{
    127
    128    //@Override public void doBeforeDispatching(boolean onlyWakeup){
    129  /**Initializes the areas for the panels and configure the panels.
    130   * This routine can be overridden if other areas are need.
    131   */
    132  @Override protected void initGuiAreas(String sMainArea)
    133  {
    134    gui.setFrameAreaBorders(20, 80, 60, 85);
    135    gui.setStandardMenusGThread(new File("."), actionFile);
    136    //Creates a Tab-Panel:
    137    //panelMng.tabPanel = panelMng.createTabPanel(panelContent.actionPanelActivate, 0);
    138    //panelMng.tabPanel.addGridPanel("operation", "&Operation",1,1,10,10);
    139    _gralMng.selectPanel("primaryWindow");
    140    mainTabPanel = _gralMng.addTabbedPanel("mainTab", null, 0);
    141    gui.addFrameArea("A1C2", mainTabPanel); //dialogPanel);
    142
    143    try {
    144      _gralMng.setPosition(5, 0, 5, 0, 1, 'r'); //right buttom, about half less display width and hight.
    145      mainData.infoWindow = _gralMng.createWindow("windViewdiff", "view difference", GralWindow.windConcurrently | GralWindow.windResizeable);
    146      _gralMng.setPosition(0, -3, 0, 0, 0, '.');
    147      mainData.infoBox = _gralMng.addTextBox("boxViewDiff", false, null, '.');
    148      _gralMng.setPosition(0, -4, -4, -2, 0, '.');
    149      mainData.infoLine = _gralMng.addTextField("info", false, null, null);
    150
    151      mainTabPanel.addGridPanel("Select", "&Select",1,1,10,10);
    152        mainTabPanel.addGridPanel("Commit", "&Commit",1,1,10,10);
    153        mainTabPanel.addGridPanel("Log", "&Log",1,1,10,10);
    154        mainTabPanel.addGridPanel("FilesDiff", "&Files && Diff",1,1,10,10);
    155        mainTabPanel.addGridPanel("Output", "&Output",1,1,10,10);
    156
    157        guiSelectPanel.initGui();
    158        guiStatusPanel.initGui();
    159        guiCommitPanel.initGui();
    160        guiFilesDiffPanel.initGui();
    161        panelOutput.initGui();
    162      }
    163      catch(Exception exception)
    164      { //catch the last level of error. No error is reported direct on command line!
    165        mainCmd.writeError("Uncatched Exception on main level:", exception);
    166        mainCmd.writeStackTrace(exception);
    167        mainCmd.setExitErrorLevel(MainCmd_ifc.exitWithErrors);
    168      }
    169      //gui.removeDispatchListener(this);
    170
    171      //countExecution();
    172
    173    }
    174
    175  //};
    176
    177
    178  @Override
    179  protected void stepMain()
    180  {
    181    Runnable order = mainData.awaitOrderBackground(1000);
    182    if(order !=null){
    183      order.run();
    184    }
    185  }
    186
    187
    188
    189  //void stop(){} //debug helper
    190
    191
    192
    193  /**Organisation class for the GUI.
    194   */
    195  private static class CmdLineAndGui extends GralArea9MainCmd
    196  {
    197
    198
    199    /**Aggregation to given instance for the command-line-argument. The instance can be arranged anywhere else.
    200     * It is given as ctor-parameter.
    201     */
    202    final CallingArguments cargs;
    203
    204    /**ctor called in static main.
    205     * @param cargs aggregation to command-line-argument data, it will be filled here.
    206     * @param args The command-line-calling arguments from static main
    207     */
    208    public CmdLineAndGui(CallingArguments cargs, String[] args)
    209    {
    210      super(cargs, args);
    211      this.cargs = cargs;
    212      addAboutInfo("Bazaar-Gui");
    213      addAboutInfo("made by HSchorrig, 2011-04-30, 2011-05-01");
    214    }
    215
    216
    217
    218    /*---------------------------------------------------------------------------------------------*/
    219    /** Tests one argument. This method is invoked from parseArgument. It is abstract in the superclass MainCmd
    220    and must be overwritten from the user.
    221    :TODO: user, test and evaluate the content of the argument string
    222    or test the number of the argument and evaluate the content in dependence of the number.
    223
    224    @param argc String of the actual parsed argument from cmd line
    225    @param nArg number of the argument in order of the command line, the first argument is number 1.
    226    @return true is okay,
    227            false if the argument doesn't match. The parseArgument method in MainCmd throws an exception,
    228            the application should be aborted.
    229     */
    230    @Override protected boolean testArgument(String arg, int nArg)
    231    { boolean bOk = true;  //set to false if the argc is not passed
    232      try {
    233        if(arg.startsWith("-cfg=")){
    234          String sPath = FileSystem.absolutePath(getArgument(5), null);
    235          cargs.fileCfg = new File(sPath);
    236        }
    237        else if(arg.startsWith("-_"))
    238        { //accept but ignore it. Commented calling arguments.
    239        }
    240        else { bOk = super.testArgument(arg, nArg); }
    241        } catch(Exception exc){
    242      }
    243      return bOk;
    244    }
    245
    246
    247    /** Invoked from parseArguments if no argument is given. In the default implementation a help info is written
    248     * and the application is terminated. The user should overwrite this method if the call without comand line arguments
    249     * is meaningfull.
    250     *
    251     */
    252    @Override protected void callWithoutArguments()
    253    { //overwrite with empty method - if the calling without arguments
    254      //having equal rights than the calling with arguments - no special action.
    255    }
    256
    257    /*---------------------------------------------------------------------------------------------*/
    258    /**Checks the cmdline arguments relation together.
    259   If there is an inconsistents, a message should be written. It may be also a warning.
    260   :TODO: the user only should determine the specific checks, this is a sample.
    261   @return true if successfull, false if failed.
    262     */
    263    @Override protected boolean checkArguments()
    264    { boolean bOk = true;
    265    return bOk;
    266
    267    }
    268
    269    /**Initializes the Graphic.
    270     * Note: This functionality should be a part of the implementing class, because some of the methods
    271     * are designated as protected. The initializing is done only one time.
    272     * Advantage of protected methods: don't call it without the correct context.
    273     * This method is called from outside.
    274     */
    275    void XXXinitGraphic()
    276    {
    277      gui.setStandardMenusGThread(null, null);
    278    }
    279
    280  } //class CmdLineAndGui
    281
    282  /**The command-line-invocation (primary command-line-call.
    283   * @param args Some calling arguments are taken. This is the GUI-configuration especially.
    284   */
    285  public static void main(String[] args)
    286  { boolean bOk;
    287    CallingArguments cargs = new CallingArguments();
    288    //Initializes the GUI till a output window to show informations:
    289    CmdLineAndGui gui = new CmdLineAndGui(cargs, args);  //implements MainCmd, parses calling arguments
    290    bOk = gui.parseArgumentsAndInitGraphic("BzrGui", "3A3C");
    291
    292    /*
    293    try{ gui.parseArguments(); }
    294    catch(Exception exception)
    295    { gui.writeError("Cmdline argument error:", exception);
    296      gui.setExitErrorLevel(MainCmd_ifc.exitWithArgumentError);
    297      //gui.exit();
    298      bOk = false;  //not exiting, show error in GUI
    299    }
    300    */
    301    //String ipcFactory = "org.vishia.communication.InterProcessComm_Socket";
    302    //try{ ClassLoader.getSystemClassLoader().loadClass(ipcFactory, true);
    303    //}catch(ClassNotFoundException exc){
    304    //  System.out.println("class not found: " + "org.vishia.communication.InterProcessComm_Socket");
    305    //}
    306    //Loads the named class, and its base class InterProcessCommFactory.
    307    //In that kind the calling of factory methods are regarded to socket.
    308    new InterProcessCommFactorySocket();
    309    if(bOk){
    310      BzrGui main = new BzrGui(cargs, gui);
    311
    312      main.execute();
    313    }
    314    gui.exit();
    315  }
    316
    317
    318}