Eclipseplugins
pAWriteTrigger.java
1 package com.proalpha.pds.templates.jet.trunk;
2 
3 import com.openedge.pdt.core.template.TemplateGenerationException;
4 import com.proalpha.pds.templates.jet.IpaTemplateGenerator;
5 import com.proalpha.pds.templates.data.GeneratorSettingsConstans;
6 
7 import java.util.Map;
8 import java.util.Map;
9 import java.util.Date;
10 import java.text.SimpleDateFormat;
11 import com.proalpha.pds.templates.helper.CodeFormatter;
12 
13 public class pAWriteTrigger implements IpaTemplateGenerator
14 {
15  protected static String nl;
16  public static synchronized pAWriteTrigger create(String lineSeparator)
17  {
18  nl = lineSeparator;
19  pAWriteTrigger result = new pAWriteTrigger();
20  nl = null;
21  return result;
22  }
23 
24  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
25  protected final String TEXT_1 = "&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r2 GUI" + NL + "&ANALYZE-RESUME" + NL;
26  protected final String TEXT_2 = NL + "&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DECLARATIONS V-table-Win " + NL + "" + NL + "/* _UIB-CODE-BLOCK-END */ " + NL + "&ANALYZE-RESUME" + NL + NL;
27  protected final String TEXT_3 = NL + "&ANALYZE-SUSPEND _UIB-CODE-BLOCK _XFTR \"Update Information\" Procedure _INLINE" + NL + "/* Actions: ? ? ? ? adm/support/proc/ds_pa_01.w */" + NL + "" + NL + "/* _UIB-CODE-BLOCK-END */" + NL + "&ANALYZE-RESUME" + NL + "" + NL + "&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS Procedure" + NL + "/******************************************************************************/" + NL + "/* @COPYRIGHT@ */" + NL + "/* Project: proALPHA */" + NL + "/* */";
28  protected final String TEXT_4 = NL;
29  protected final String TEXT_5 = NL + "/* */";
30  protected final String TEXT_6 = NL + "/* Current: @PAVERSION@ as of @PADATE@/@PALASTAUTHOR@ */" + NL + "/* */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* DESCRIPTION */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* */";
31  protected final String TEXT_7 = NL + "/* */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* PARAMETERS */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* Name Description */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* HISTORY */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* @FILEHISTORY@ */" + NL + "/******************************************************************************/";
32  protected final String TEXT_8 = NL + NL + "trigger procedure for write of ";
33  protected final String TEXT_9 = " old buffer old_";
34  protected final String TEXT_10 = "." + NL + "" + NL + "/* Procedure information */" + NL + "" + NL + "&GLOBAL-DEFINE pa-Autor ";
35  protected final String TEXT_11 = NL + "&GLOBAL-DEFINE pa-Version @PAVERSION@" + NL + "&GLOBAL-DEFINE pa-Datum @PADATE@" + NL + "&GLOBAL-DEFINE pa-Letzter @PALASTAUTHOR@" + NL + "" + NL + "&GLOBAL-DEFINE pa-GenVersion OEA" + NL + "&GLOBAL-DEFINE pa-ProgrammTyp Trigger" + NL + "&GLOBAL-DEFINE pa-XBasisName ";
36  protected final String TEXT_12 = NL + NL + "/* Type specific global definitions (prior to parameter definition!) ---------*/" + NL + "" + NL + "&GLOBAL-DEFINE pa-TriggerFunktion WRITE" + NL + "&GLOBAL-DEFINE pa-TriggerTabelle ";
37  protected final String TEXT_13 = NL + NL + "/* Globals -------------------------------------------------------------------*/" + NL + "" + NL + "{adm/template/incl/dt_trg10.df}" + NL + "" + NL + "/* SCOPEDs ------------------------------------------------------------------*/" + NL + "" + NL + "/* Variables -----------------------------------------------------------------*/" + NL + "/*----------------------------------------------------------------------------*/" + NL + "" + NL + "/* Buffers -------------------------------------------------------------------*/" + NL + "" + NL + "" + NL + "/* _UIB-CODE-BLOCK-END */" + NL + "&ANALYZE-RESUME" + NL + "" + NL + "" + NL + "&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK" + NL + "" + NL + "/* ******************** Preprocessor Definitions ******************** */" + NL + "" + NL + "&Scoped-define PROCEDURE-TYPE Procedure" + NL + "" + NL + "/* _UIB-PREPROCESSOR-BLOCK-END */" + NL + "&ANALYZE-RESUME" + NL + "" + NL + "" + NL + "/* *********************** Procedure Settings ************************ */" + NL + "" + NL + "&ANALYZE-SUSPEND _PROCEDURE-SETTINGS" + NL + "/* Settings for THIS-PROCEDURE" + NL + " Type: Procedure" + NL + " Allow:" + NL + " Frames: 0" + NL + " Add Fields to: Neither" + NL + " Other Settings: CODE-ONLY" + NL + " */" + NL + "&ANALYZE-RESUME _END-PROCEDURE-SETTINGS" + NL + "" + NL + "/* ************************* Create Window ************************** */" + NL + "" + NL + "&ANALYZE-SUSPEND _CREATE-WINDOW" + NL + "/* DESIGN Window definition (used by the UIB)" + NL + " CREATE WINDOW Procedure ASSIGN" + NL + " HEIGHT = 10" + NL + " WIDTH = 50." + NL + "/* END WINDOW DEFINITION */" + NL + " */" + NL + "&ANALYZE-RESUME" + NL + "" + NL + "" + NL + "&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB Procedure" + NL + "/* ************************* Included-Libraries *********************** */" + NL + "" + NL + "{adm/method/incl/dm_trg00.lib}" + NL + "" + NL + "/* _UIB-CODE-BLOCK-END */" + NL + "&ANALYZE-RESUME" + NL + "" + NL + "&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK Procedure" + NL + "" + NL + "/*----------------------------------------------------------------------------*/" + NL + "/* Processing */" + NL + "/*----------------------------------------------------------------------------*/" + NL + "" + NL + "/* Common pre-processing */" + NL + "" + NL + "{adm/template/incl/dt_trg10.if}" + NL + "" + NL + "/* Check integrity */" + NL;
38  protected final String TEXT_14 = NL + "/* checks covering other companies */" + NL + "" + NL + "for each S_Firma" + NL + " fields (Firma)" + NL + " where S_Firma.Firma begins ";
39  protected final String TEXT_15 = ".Firma" + NL + " and {firma/";
40  protected final String TEXT_16 = " S_Firma.Firma} = ";
41  protected final String TEXT_17 = ".Firma" + NL + " no-lock" + NL + " on error undo, throw:" + NL + "" + NL + "end." + NL;
42  protected final String TEXT_18 = NL + NL + "/* Processing */" + NL;
43  protected final String TEXT_19 = NL + NL + "/* Processing covering other companies */" + NL + "" + NL + "for each S_Firma" + NL + " fields (Firma)" + NL + " where S_Firma.Firma begins ";
44  protected final String TEXT_20 = NL + NL + "/* address usage within other modules */" + NL;
45  protected final String TEXT_21 = NL + NL + "/* set creation/update information */" + NL + "" + NL + "{adm/template/incl/dt_trg01.if" + NL + "}" + NL;
46  protected final String TEXT_22 = NL + "/* set creation/update information */" + NL + "" + NL + "{adm/template/incl/dt_trg01.if" + NL + " &DATETIMEFIELDS = \"yes\"" + NL + "}";
47  protected final String TEXT_23 = NL + NL + "{adm/template/incl/dt_trg01.if" + NL + " &ENGLISHFIELDNAMES = \"yes\"" + NL + "}";
48  protected final String TEXT_24 = NL + "/* Common post-processing */" + NL + "" + NL + "{adm/template/incl/dt_trg20.if}" + NL + "" + NL + "/* Cleanup with optional \"finally\"-Block */" + NL + "" + NL + "" + NL + "/* _UIB-CODE-BLOCK-END */" + NL + "&ANALYZE-RESUME";
49 
50 /* (non-javadoc)
51  * @see ITemplateGenerator#generate(Object)
52  */
53 public String generate(Map<String, Object> wizardSettings) throws TemplateGenerationException
54  {
55  final StringBuffer stringBuffer = new StringBuffer();
56  String author = (String)wizardSettings.get(GeneratorSettingsConstans.AUTHOR);
57  String description = (String)wizardSettings.get(GeneratorSettingsConstans.DESCRIPTION);
58  String fileName = (String)wizardSettings.get(GeneratorSettingsConstans.FILE_NAME);
59  String product = (String)wizardSettings.get(GeneratorSettingsConstans.PRODUCT);
60  String productDesc = (String)wizardSettings.get(GeneratorSettingsConstans.PRODUCT_DESCRIPTION);
61  String module = (String)wizardSettings.get("Module");
62  String moduleDesc = (String)wizardSettings.get(GeneratorSettingsConstans.MODULE_DESCRIPTION);
63  String version = (String)wizardSettings.get(GeneratorSettingsConstans.VERSION);
64  String xbasename = fileName.replace(".","_");
65  Date date = new Date();
66  SimpleDateFormat year = new SimpleDateFormat("yyyy");
67  SimpleDateFormat today = new SimpleDateFormat("dd.MM.yyyy");
68  stringBuffer.append(TEXT_1);
69  if ((fileName.endsWith(".p")) || (fileName.endsWith(".w") || (fileName.endsWith(".cls"))))
70 {
71  stringBuffer.append(TEXT_2);
72  }
73  stringBuffer.append(TEXT_3);
74  stringBuffer.append(TEXT_4);
75  stringBuffer.append(CodeFormatter.SingleLineComment("Name : " + fileName));
76  stringBuffer.append(TEXT_4);
77  stringBuffer.append(CodeFormatter.SingleLineComment("Product: " + product + " - " + productDesc ));
78  stringBuffer.append(TEXT_4);
79  stringBuffer.append(CodeFormatter.SingleLineComment("Module : " + module + " - " + moduleDesc ));
80  stringBuffer.append(TEXT_5);
81  stringBuffer.append(TEXT_4);
82  stringBuffer.append(CodeFormatter.SingleLineComment("Created: " + version + " as of " + today.format(date) + "/" + author));
83  stringBuffer.append(TEXT_6);
84  stringBuffer.append(TEXT_4);
85  stringBuffer.append(CodeFormatter.MultiLineComment(description));
86  stringBuffer.append(TEXT_7);
87 
88 String TableName = (String)wizardSettings.get(GeneratorSettingsConstans.TABLE_NAME);
89 
90  stringBuffer.append(TEXT_8);
91  stringBuffer.append(TableName);
92  stringBuffer.append(TEXT_9);
93  stringBuffer.append(TableName);
94  stringBuffer.append(TEXT_10);
95  stringBuffer.append(author);
96  stringBuffer.append(TEXT_11);
97  stringBuffer.append(xbasename);
98  stringBuffer.append(TEXT_12);
99  stringBuffer.append(TableName);
100  stringBuffer.append(TEXT_13);
101  if (wizardSettings.get(GeneratorSettingsConstans.HAS_COMPANY).equals("true")) {
102  stringBuffer.append(TEXT_14);
103  stringBuffer.append(TableName);
104  stringBuffer.append(TEXT_15);
105  stringBuffer.append( wizardSettings.get(GeneratorSettingsConstans.COMPANY_INCLUDE) );
106  stringBuffer.append(TEXT_16);
107  stringBuffer.append(TableName);
108  stringBuffer.append(TEXT_17);
109  }
110  stringBuffer.append(TEXT_18);
111  if (wizardSettings.get(GeneratorSettingsConstans.HAS_COMPANY).equals("true")) {
112  stringBuffer.append(TEXT_19);
113  stringBuffer.append(TableName);
114  stringBuffer.append(TEXT_15);
115  stringBuffer.append( wizardSettings.get(GeneratorSettingsConstans.COMPANY_INCLUDE) );
116  stringBuffer.append(TEXT_16);
117  stringBuffer.append(TableName);
118  stringBuffer.append(TEXT_17);
119  }
120  stringBuffer.append(TEXT_20);
121  if (wizardSettings.get(GeneratorSettingsConstans.CHANGE_LOG_GERMAN).equals("true")) {
122  stringBuffer.append(TEXT_21);
123  }
124  if (wizardSettings.get(GeneratorSettingsConstans.CHANGE_LOG_ENGLISH).equals("true")) {
125  if (wizardSettings.get(GeneratorSettingsConstans.CHANGE_LOG_DATETIME).equals("true")) {
126  stringBuffer.append(TEXT_22);
127  }else{
128  stringBuffer.append(TEXT_23);
129  }
130  }
131  stringBuffer.append(TEXT_24);
132  stringBuffer.append(TEXT_4);
133  return stringBuffer.toString();
134  }
135 }