use of com.twinsoft.convertigo.beans.ngx.components.UIActionStack in project convertigo by convertigo.
the class NgxBuilder method writeFunctionTempTsFile.
@Override
public void writeFunctionTempTsFile(final IUIComponent uiComponent, String functionMarker) throws EngineException {
UIComponent uic = (UIComponent) uiComponent;
try {
IScriptComponent main = uic.getMainScriptComponent();
if (main != null) {
String tempTsFileName = null, tsContent = null;
File tempTsDir = null;
UIActionStack sharedAction = null;
if (main instanceof ApplicationComponent) {
sharedAction = uic.getSharedAction();
tempTsDir = sharedAction == null ? appDir : servicesDir;
tempTsFileName = sharedAction == null ? "app.component.function.temp.ts" : "actionbeans.service.function.temp.ts";
File appTsFile = sharedAction == null ? new File(appDir, "app.component.ts") : new File(servicesDir, "actionbeans.service.ts");
synchronized (writtenFiles) {
if (writtenFiles.contains(appTsFile)) {
File appTsFileTmp = toTmpFile(appTsFile);
if (appTsFileTmp.exists()) {
appTsFile = appTsFileTmp;
}
}
}
tsContent = FileUtils.readFileToString(appTsFile, "UTF-8");
}
if (main instanceof PageComponent) {
PageComponent page = (PageComponent) main;
String pageName = page.getName();
tempTsDir = pageDir(page);
tempTsFileName = pageName.toLowerCase() + ".function.temp.ts";
if (page.isEnabled()) {
File pageTsFile = new File(tempTsDir, pageName.toLowerCase() + ".ts");
synchronized (writtenFiles) {
if (writtenFiles.contains(pageTsFile)) {
File pageTsFileTmp = toTmpFile(pageTsFile);
if (pageTsFileTmp.exists()) {
pageTsFile = pageTsFileTmp;
}
}
}
tsContent = FileUtils.readFileToString(pageTsFile, "UTF-8");
} else {
tsContent = getPageTsContent(page);
}
}
if (main instanceof UISharedComponent) {
UISharedComponent comp = (UISharedComponent) main;
String compName = comp.getName();
tempTsDir = compDir(comp);
tempTsFileName = compName.toLowerCase() + ".function.temp.ts";
boolean isEnabled = true;
if (isEnabled) {
File compTsFile = new File(tempTsDir, compName.toLowerCase() + ".ts");
synchronized (writtenFiles) {
if (writtenFiles.contains(compTsFile)) {
File compTsFileTmp = toTmpFile(compTsFile);
if (compTsFileTmp.exists()) {
compTsFile = compTsFileTmp;
}
}
}
tsContent = FileUtils.readFileToString(compTsFile, "UTF-8");
} else {
tsContent = getCompTsContent(comp);
}
}
// Replace all Begin_c8o_XXX, End_c8o_XXX except for functionMarker
Pattern pattern = Pattern.compile("/\\*Begin_c8o_(.+)\\*/");
Matcher matcher = pattern.matcher(tsContent);
while (matcher.find()) {
String markerId = matcher.group(1);
if (!markerId.equals(functionMarker)) {
String beginMarker = "/*Begin_c8o_" + markerId + "*/";
String endMarker = "/*End_c8o_" + markerId + "*/";
tsContent = tsContent.replace(beginMarker, "//---" + markerId + "---");
tsContent = tsContent.replace(endMarker, "//---" + markerId + "---");
}
}
// CustomAction : reduce code lines (action's function only)
if (tempTsDir != null && tempTsFileName != null) {
if (uiComponent instanceof UICustomAction) {
UICustomAction uica = (UICustomAction) uic;
tempTsFileName = "CTS" + uica.priority + ".temp.ts";
int index = tsContent.indexOf("export class ");
if (index != -1) {
String classType = uica.getMainClassType();
String sImport = "";
if (main instanceof ApplicationComponent) {
if (uic.getSharedAction() == null) {
sImport = "import { " + classType + " } from './app.component';";
}
} else if (main instanceof PageComponent) {
sImport = "import { " + classType + " } from './" + classType.toLowerCase() + "';";
} else if (main instanceof UISharedComponent) {
sImport = "import { " + classType + " } from './" + classType.toLowerCase() + "';";
}
int i = tsContent.indexOf("{", index);
tsContent = tsContent.substring(0, i + 1) + System.lineSeparator() + uica.getActionCode() + System.lineSeparator() + "}" + System.lineSeparator();
tsContent = tsContent.replace("@Component", sImport + System.lineSeparator() + "@Component");
tsContent = tsContent.replace("export class " + classType + " ", "export class _Type_ ");
}
}
}
// Write file (do not need delay)
tsContent = LsPattern.matcher(tsContent).replaceAll(System.lineSeparator());
File tempTsFile = new File(tempTsDir, tempTsFileName);
FileUtils.write(tempTsFile, tsContent, "UTF-8");
}
} catch (Exception e) {
throw new EngineException("Unable to write function temp ts file", e);
}
}
use of com.twinsoft.convertigo.beans.ngx.components.UIActionStack in project convertigo by convertigo.
the class NgxUIComponentTreeObject method treeObjectAdded.
@Override
public void treeObjectAdded(TreeObjectEvent treeObjectEvent) {
super.treeObjectAdded(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
Set<Object> done = checkDone(treeObjectEvent);
String propertyName = (String) treeObjectEvent.propertyName;
propertyName = ((propertyName == null) ? "" : propertyName);
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
DatabaseObject dbo = doto.getObject();
try {
if (this.equals(treeObject)) {
UIActionStack uisa = ((UIComponent) dbo).getSharedAction();
UISharedComponent uisc = ((UIComponent) dbo).getSharedComponent();
if (uisa != null && !uisa.equals(getObject())) {
notifyDataseObjectPropertyChanged(uisa, "", null, null, done);
}
if (uisc != null && !uisc.equals(getObject())) {
notifyDataseObjectPropertyChanged(uisc, "", null, null, done);
}
} else {
if (dbo instanceof UIActionStack) {
handleSharedActionChanged((UIActionStack) dbo, done);
} else if (dbo instanceof UISharedComponent) {
handleSharedComponentChanged((UISharedComponent) dbo, done);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.twinsoft.convertigo.beans.ngx.components.UIActionStack in project convertigo by convertigo.
the class NgxPickerComposite method lookupModelData.
private Map<String, Object> lookupModelData(TVObject tvObject) {
Map<String, Object> data = new HashMap<String, Object>();
Map<String, String> params = new HashMap<String, String>();
DatabaseObject dbo = null;
String searchPath = "";
Object object = tvObject.getObject();
JSONObject infos = tvObject.getInfos();
if (object != null) {
try {
if (object instanceof RequestableObject) {
dbo = (RequestableObject) object;
searchPath = "";
} else if (object instanceof DesignDocument) {
dbo = (DesignDocument) object;
DesignDocument dd = (DesignDocument) dbo;
params.put("ddoc", dd.getName());
params.put("view", tvObject.getParent().getName());
params.put("include_docs", infos.has("include_docs") ? infos.getString("include_docs") : "false");
searchPath = tvObject.getName().startsWith("get") ? ".rows.value" : "";
} else if (object instanceof UIControlDirective) {
dbo = (UIControlDirective) object;
do {
UIControlDirective directive = (UIControlDirective) dbo;
String rootDboName = "";
if (directive.getPage() != null) {
rootDboName = directive.getPage().getName();
} else if (directive.getMenu() != null) {
rootDboName = directive.getMenu().getName();
}
MobileSmartSourceType msst = directive.getSourceSmartType();
MobileSmartSource mss = msst.getSmartSource();
if (mss != null) {
dbo = mss.getDatabaseObject(rootDboName);
params.putAll(mss.getParameters());
searchPath = mss.getModelPath().replaceAll("\\?\\.", ".") + searchPath;
} else {
dbo = null;
}
} while (dbo != null && dbo instanceof UIControlDirective);
} else if (object instanceof UIForm) {
dbo = (UIForm) object;
searchPath = "";
} else if (object instanceof ApplicationComponent) {
dbo = (ApplicationComponent) object;
params.put("json", infos.toString());
searchPath = "";
} else if (object instanceof UIActionStack) {
dbo = (UIActionStack) object;
searchPath = "";
} else if (object instanceof IAction) {
if (object instanceof UIDynamicAction) {
dbo = (UIDynamicAction) object;
searchPath = "";
} else if (object instanceof UICustomAction) {
dbo = (UICustomAction) object;
searchPath = "";
}
} else if (object instanceof UISharedComponent) {
dbo = (UISharedComponent) object;
searchPath = "";
}
} catch (Exception e) {
e.printStackTrace();
}
}
data.put("databaseObject", dbo);
data.put("params", params);
data.put("searchPath", searchPath);
return data;
}
Aggregations