001package org.vishia.guiViewCfg;
002
003import java.io.File;
004
005
006import org.vishia.communication.InterProcessCommFactorySocket;
007import org.vishia.gral.area9.GralArea9MainCmd;
008import org.vishia.gral.area9.GuiCallingArgs;
009import org.vishia.gral.area9.GuiCfg;
010import org.vishia.gral.base.GralWidget;
011//import org.vishia.gral.gui.GuiDispatchCallbackWorker;
012import org.vishia.gral.ifc.GralUserAction;
013import org.vishia.util.Assert;
014
015/**Class contains main, it is able to use for a GUI without any programming in Java.*/
016public class ViewCfg extends GuiCfg 
017{
018  
019  /**Version and history
020   * <ul>
021   * <li>2012-20-22 Hartmut chg now works yet.
022   * <li>2010-06-00 Hartmut created
023   * </ul>
024   */
025  public static final int version = 0x20120222;
026  
027  private final OamShowValues oamShowValues;
028          
029  /**Composition of a class, that reads the oam output values from the target
030   * and writes into variables, which are displayed.
031   */
032  //private final OamOutFileReader oamOutValues;
033  
034  private final boolean showValuesOk;
035  
036  private final OamRcvValue oamRcvUdpValue;
037  
038  /**Composition of a class, that reads the oam messages from the target
039   * and writes into the dayly list and into files.
040   */
041  //private final MsgReceiver msgReceiver;
042  
043  
044  /**The command-line-arguments may be stored in an extra class, which can arranged in any other class too. 
045   * The separation of command line argument helps to invoke the functionality with different calls, 
046   * for example calling in a GUI, calling in a command-line-batch-process or calling from ANT 
047   */
048  static class CallingArguments extends GuiCallingArgs
049  {
050    /**Name of the config-file for the Gui-appearance. */
051    String sFileGui;
052        
053    /**Directory where sFileCfg is placed, with / on end. The current dir if sFileCfg is given without path. */
054    String sParamBin;
055    
056    String sFileCtrlValues;
057    
058    /**File with the values from the S7 to show. */
059    String sFileOamValues;
060    
061    /**File with the values from the S7 to show. */
062    String sFileOamUcell;
063    
064    String sFileCfg;
065    
066  } //class CallingArguments
067  
068  
069  
070  final CallingArguments callingArguments;
071
072  
073  
074  
075  /**This instance helps to create the Dialog Widget as part of the whole window. It is used only in the constructor.
076   * Therewith it may be defined stack-locally. But it is better to show and explain if it is access-able at class level. */
077  //GuiDialogZbnfControlled dialogZbnfConfigurator;   
078  
079  
080  
081  
082  
083  
084  
085  
086  
087  private final GralUserAction actionKeyboard = new GralUserAction()
088  { @Override
089  public boolean userActionGui(String sCmd, GralWidget widgetInfos, Object... values)
090    {
091                if(sCmd != null){  
092                        //String sCmd1 = "TouchInputPc.exe";
093                        mainCmd.executeCmdLine(widgetInfos.sCmd, 0, null, null);
094        return true;
095                } else return false;
096    }
097  };
098  
099  
100  
101  
102  /**Organisation class for the GUI.
103   */
104  private static class CmdLineAndGui extends GralArea9MainCmd
105  {
106
107    
108    /**Aggregation to given instance for the command-line-argument. The instance can be arranged anywhere else.
109     * It is given as ctor-parameter.
110     */
111    final CallingArguments cargs;
112    
113    /**ctor called in static main.
114     * @param cargs aggregation to command-line-argument data, it will be filled here.
115     * @param args The command-line-calling arguments from static main
116     */
117    public CmdLineAndGui(CallingArguments cargs, String[] args)
118    { 
119      super(cargs, args);
120      super.addAboutInfo("ViewCfg");
121      super.addAboutInfo("made by HSchorrig, 2010-06-07, 2011-09-03");
122      //super.addStandardHelpInfo();
123      this.cargs = cargs;
124    }
125
126
127    
128    /*---------------------------------------------------------------------------------------------*/
129    /** Tests one argument. This method is invoked from parseArgument. It is abstract in the superclass MainCmd
130        and must be overwritten from the user.
131        :TODO: user, test and evaluate the content of the argument string
132        or test the number of the argument and evaluate the content in dependence of the number.
133  
134        @param argc String of the actual parsed argument from cmd line
135        @param nArg number of the argument in order of the command line, the first argument is number 1.
136        @return true is okay,
137                false if the argument doesn't match. The parseArgument method in MainCmd throws an exception,
138                the application should be aborted.
139    */
140    @Override protected boolean testArgument(String arg, int nArg)
141    { boolean bOk = true;  //set to false if the argc is not passed
142      try {
143        if(arg.startsWith("-parambin=")) 
144              { cargs.sParamBin = getArgument(10);   //an example for default output
145              }
146              else if(arg.startsWith("-ctrlbin=")) 
147              { cargs.sFileCtrlValues = getArgument(9);   //an example for default output
148              }
149              else if(arg.startsWith("-oambin=")) 
150              { cargs.sFileOamValues = getArgument(8);   //an example for default output
151              }
152              else { bOk = super.testArgument(arg, nArg); }
153      } catch(Exception exc){
154      }
155      return bOk;
156    }
157  
158
159    
160  } //class CmdLineAndGui
161
162  
163  
164  /**ctor for the main class of the application. 
165   * The main class can be created in some other kinds as done in static main too.
166   * But it needs the {@link MainCmdWin}.
167   * <br><br>
168   * The ctor checks whether a gUI-configuration file is given. If not then the default configuratin is used.
169   * It is especially for the Sample.
170   * <br><br>
171   * The the GUI will be completed with the content of the GUI-configuration file.  
172   *   
173   * @param cargs The given calling arguments.
174   * @param gui The GUI-organization.
175   */
176  ViewCfg(CallingArguments cargs, GralArea9MainCmd cmdgui) 
177  { super(cargs, cmdgui, null, null, null);
178    this.callingArguments = cargs;
179    
180    oamShowValues = new OamShowValues(cmdgui, guiAccess);
181    showValuesOk = oamShowValues.readVariableCfg();
182    
183    //oamOutValues = new OamOutFileReader(cargs.sFileOamValues, cargs.sFileOamUcell, gui, oamShowValues);
184    
185    oamRcvUdpValue = new OamRcvValue(oamShowValues, cmdgui);
186    
187    //msgReceiver = new MsgReceiver(console, dlgAccess, cargs.sTimeZone);
188    
189          oamShowValues.setFieldsToShow(panelBuildIfc.getShowFields());
190
191    //msgReceiver.test(); //use it after initGuiDialog!
192    
193  }
194  
195  
196  @Override protected void initMain()
197  {
198    super.initMain();  //starts initializing of graphic. Do it after reading some configurations.
199    //msgReceiver.start();
200    oamRcvUdpValue.start();
201
202  }
203  
204
205  @Override protected void stepMain()
206  {
207    try{
208        //oamOutValues.checkData();
209      //msgReceiver.testAndReceive();
210      oamRcvUdpValue.sendRequest();
211    } catch(Exception exc){
212      //tread-Problem: console.writeError("unexpected Exception", exc);
213      System.out.println(Assert.exceptionInfo("ViewCfg - unexpected Exception; ", exc, 0, 7));
214      exc.printStackTrace();
215    }
216
217  }
218  
219  
220  
221  
222  /**The command-line-invocation (primary command-line-call. 
223   * @param args Some calling arguments are taken. This is the GUI-configuration especially.   
224   */
225  public static void main(String[] args)
226  { boolean bOk = true;
227    CallingArguments cargs = new CallingArguments();
228    //Initializes the GUI till a output window to show informations:
229    CmdLineAndGui cmdgui = new CmdLineAndGui(cargs, args);  //implements MainCmd, parses calling arguments
230    //Initializes the graphic window and parse the parameter of args (command line parameter).
231    //Parameter errors will be output in the graphic window in its given output area.
232    bOk = cmdgui.parseArgumentsAndInitGraphic("ViewCfg", "3A3C");
233    
234    if(bOk){
235      //String ipcFactory = "org.vishia.communication.InterProcessComm_Socket";
236        //try{ ClassLoader.getSystemClassLoader().loadClass(ipcFactory, true);
237        //}catch(ClassNotFoundException exc){
238        //      System.out.println("class not found: " + "org.vishia.communication.InterProcessComm_Socket");
239        //}
240      //Loads the named class, and its base class InterProcessCommFactory. 
241      //In that kind the calling of factory methods are regarded to socket.
242        new InterProcessCommFactorySocket();
243        
244      ViewCfg main = new ViewCfg(cargs, cmdgui);
245  
246      main.execute();
247      
248      main.oamRcvUdpValue.stopThread();
249    }    
250    cmdgui.exit();
251  }
252
253  void stop(){} //debug helper
254
255}