use of com.twinsoft.convertigo.beans.ngx.components.UICustomAction in project convertigo by convertigo.
the class NgxUIComponentTreeObject method launchEditor.
@Override
public void launchEditor(String editorType) {
UIComponent uic = getObject();
if (uic instanceof UICustom) {
openHtmlFileEditor();
} else if (uic instanceof UIStyle) {
openCssFileEditor();
} else if (uic instanceof UICustomAction) {
String functionMarker = "function:" + ((UICustomAction) uic).getActionName();
editFunction(uic, functionMarker, "actionValue");
} else {
super.launchEditor(editorType);
}
}
use of com.twinsoft.convertigo.beans.ngx.components.UICustomAction in project convertigo by convertigo.
the class NgxUIComponentTreeObject method editFunction.
private void editFunction(final UIComponent uic, final String functionMarker, final String propertyName) {
try {
IScriptComponent main = uic.getMainScriptComponent();
if (main == null) {
return;
}
// Refresh project resources for editor
String projectName = uic.getProject().getName();
IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
project.refreshLocal(IResource.DEPTH_INFINITE, null);
// Close editor and Reopen it after file has been rewritten
String relativePath = uic.getProject().getMobileBuilder().getFunctionTempTsRelativePath(uic);
IFile file = project.getFile(relativePath);
if (!(uic instanceof UICustomAction)) {
closeComponentFileEditor(file);
}
if (main instanceof ApplicationComponent) {
if (uic.compareToTplVersion("7.5.2.0") < 0) {
ConvertigoPlugin.logError("The ability to use forms or actions inside a menu is avalaible since 7.5.2 version." + "\nPlease change your Template project for the 'mobilebuilder_tpl_7_5_2' template.", true);
return;
}
}
uic.getProject().getMobileBuilder().writeFunctionTempTsFile(uic, functionMarker);
file.refreshLocal(IResource.DEPTH_ZERO, null);
// Open file in editor
if (file.exists()) {
IEditorInput input = new ComponentFileEditorInput(file, uic);
if (input != null) {
IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
String editorId = desc.getId();
IEditorPart editorPart = activePage.openEditor(input, editorId);
addMarkers(file, editorPart);
editorPart.addPropertyListener(new IPropertyListener() {
boolean isFirstChange = false;
@Override
public void propertyChanged(Object source, int propId) {
if (source instanceof ITextEditor) {
if (propId == IEditorPart.PROP_DIRTY) {
if (!isFirstChange) {
isFirstChange = true;
return;
}
isFirstChange = false;
ITextEditor editor = (ITextEditor) source;
IDocumentProvider dp = editor.getDocumentProvider();
IDocument doc = dp.getDocument(editor.getEditorInput());
String marker = MobileBuilder.getMarker(doc.get(), functionMarker);
String content = MobileBuilder.getFormatedContent(marker, functionMarker);
FormatedContent formated = new FormatedContent(content);
NgxUIComponentTreeObject.this.setPropertyValue(propertyName, formated);
}
}
}
});
}
}
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to edit function for '" + uic.getName() + "' component!");
}
}
use of com.twinsoft.convertigo.beans.ngx.components.UICustomAction in project convertigo by convertigo.
the class NgxPickerComposite method getJsonModel.
private JSONObject getJsonModel(Map<String, Object> data, DatabaseObject databaseObject) throws Exception {
JSONObject jsonModel = new JSONObject();
Map<String, String> params;
DatabaseObject dbo;
String dataPath;
if (databaseObject == null) {
dbo = (DatabaseObject) data.get("databaseObject");
params = GenericUtils.cast(data.get("params"));
dataPath = (String) data.get("searchPath");
} else {
dbo = databaseObject;
params = new HashMap<String, String>();
dataPath = "";
}
if (dbo != null) {
// case of requestable
if (dbo instanceof RequestableObject) {
RequestableObject ro = (RequestableObject) dbo;
Project project = ro.getProject();
String responseEltName = ro.getXsdTypePrefix() + ro.getName() + "Response";
boolean isDocumentNode = JsonRoot.docNode.equals(project.getJsonRoot()) && dataPath.isEmpty();
XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(project.getName());
XmlSchemaObject xso = SchemaMeta.getXmlSchemaObject(schema, ro);
if (xso != null) {
Document document = XmlSchemaUtils.getDomInstance(xso);
// System.out.println(XMLUtils.prettyPrintDOM(document));
String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
JSONObject jsonObject = new JSONObject(jsonString);
String searchPath = "document." + responseEltName + ".response";
searchPath += isDocumentNode || !dataPath.startsWith(".document") ? dataPath : dataPath.replaceFirst("\\.document", "");
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = isDocumentNode ? new JSONObject().put("document", jsonOutput) : jsonOutput;
}
} else if (dbo instanceof DesignDocument) {
DesignDocument dd = (DesignDocument) dbo;
Connector connector = dd.getConnector();
String ddoc = params.get("ddoc");
String view = params.get("view");
String viewName = ddoc + "/" + view;
String includeDocs = params.get("include_docs");
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
if (connectorEditor == null) {
try {
connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
} catch (PartInitException e) {
ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
}
}
if (connectorEditor != null) {
// activate connector's editor
activePage.activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
((GetViewTransaction) transaction).setViewname(viewName);
((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
view_reduce.setValueOrNull(false);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalView, false);
}
}
});
} else // case of UIForm
if (dbo instanceof UIForm) {
// JSONObject jsonObject = new JSONObject("{\"controls\":{\"['area']\":{\"value\":\"\"}}}");
JSONObject jsonObject = new JSONObject(((UIForm) dbo).computeJsonModel());
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of UIACtionStack
if (dbo instanceof UIActionStack) {
JSONObject jsonObject = new JSONObject(((UIActionStack) dbo).computeJsonModel());
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of UIDynamicAction or UICustomAction
if (dbo instanceof IAction) {
JSONObject jsonObject = new JSONObject();
if (dbo instanceof UIDynamicAction) {
UIDynamicAction uida = (UIDynamicAction) dbo;
jsonObject = new JSONObject(uida.computeJsonModel());
IonBean ionBean = uida.getIonBean();
if (ionBean != null) {
String name = ionBean.getName();
if ("CallSequenceAction".equals(name)) {
String qname = ionBean.getProperty("requestable").getValue().toString();
DatabaseObject sequence = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (sequence != null) {
JSONObject targetJsonModel = getJsonModel(data, sequence);
if (jsonObject.has("out")) {
jsonObject.put("out", targetJsonModel);
}
}
} else if ("CallFullSyncAction".equals(name)) {
String qname = ionBean.getProperty("requestable").getValue().toString();
String verb = ionBean.getProperty("verb").getValue().toString();
Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (connector != null) {
XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
AbstractCouchDbTransaction act = null;
if ("all".equals(verb))
act = new AllDocsTransaction();
else if ("create".equals(verb))
act = new PutDatabaseTransaction();
else if ("destroy".equals(verb))
act = new DeleteDatabaseTransaction();
else if ("get".equals(verb))
act = new GetDocumentTransaction();
else if ("delete".equals(verb))
act = new DeleteDocumentTransaction();
else if ("delete_attachment".equals(verb))
act = new DeleteDocumentAttachmentTransaction();
else if ("post".equals(verb))
act = new PostDocumentTransaction();
else if ("put_attachment".equals(verb))
act = new PutDocumentAttachmentTransaction();
else if ("replicate_push".equals(verb))
act = new PostReplicateTransaction();
else if ("reset".equals(verb))
act = new ResetDatabaseTransaction();
else if ("view".equals(verb))
act = new GetViewTransaction();
if (act != null) {
QName typeQName = act.getComplexTypeAffectation();
XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
cleanJsonModel(jsonOutput);
jsonOutput.remove("_c8oMeta");
jsonOutput.remove("error");
jsonOutput.remove("reason");
if (jsonObject.has("out")) {
jsonObject.put("out", jsonOutput);
}
}
}
} else if ("FullSyncGetAction".equals(name)) {
String qname = ionBean.getProperty("requestable").getValue().toString();
String docid = ionBean.getProperty("_id").getValue().toString();
Connector connector = (Connector) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (connector != null) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
if (connectorEditor == null) {
try {
connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
} catch (PartInitException e) {
ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
}
}
if (connectorEditor != null) {
// activate connector's editor
activePage.activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalDocument);
Variable var_docid = ((GetDocumentTransaction) transaction).getVariable(CouchParam.docid.param());
var_docid.setValueOrNull(docid);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalDocument, false);
}
}
});
}
} else if ("FullSyncViewAction".equals(name)) {
String fsview = ionBean.getProperty("fsview").getValue().toString();
String includeDocs = ionBean.getProperty("include_docs").getValue().toString();
String reduce = ionBean.getProperty("reduce").getValue().toString();
String qname = fsview.substring(0, fsview.lastIndexOf('.'));
DesignDocument dd = (DesignDocument) Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
Connector connector = dd.getConnector();
String viewName = dd.getName() + "/" + fsview.substring(fsview.lastIndexOf('.') + 1);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ConnectorEditor connectorEditor = ConvertigoPlugin.getDefault().getConnectorEditor(connector);
if (connectorEditor == null) {
try {
connectorEditor = (ConnectorEditor) activePage.openEditor(new ConnectorEditorInput(connector), "com.twinsoft.convertigo.eclipse.editors.connector.ConnectorEditor");
} catch (PartInitException e) {
ConvertigoPlugin.logException(e, "Error while loading the connector editor '" + connector.getName() + "'");
}
}
if (connectorEditor != null) {
// activate connector's editor
activePage.activate(connectorEditor);
// set transaction's parameters
Transaction transaction = connector.getTransactionByName(CouchDbConnector.internalView);
((GetViewTransaction) transaction).setViewname(viewName);
((GetViewTransaction) transaction).setQ_include_docs(includeDocs);
Variable view_reduce = ((GetViewTransaction) transaction).getVariable(CouchParam.prefix + "reduce");
view_reduce.setValueOrNull(reduce);
// execute view transaction
connectorEditor.getDocument(CouchDbConnector.internalView, false);
}
}
});
} else if (name.startsWith("FullSync")) {
if (ionBean.getProperty("requestable") != null) {
String qname = ionBean.getProperty("requestable").getValue().toString();
DatabaseObject connector = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
if (connector != null) {
XmlSchema schema = Engine.theApp.schemaManager.getSchemaForProject(connector.getProject().getName());
AbstractCouchDbTransaction act = null;
if ("FullSyncDeleteAction".equals(name))
act = new DeleteDocumentTransaction();
else if ("FullSyncDeleteAttachmentAction".equals(name))
act = new DeleteDocumentAttachmentTransaction();
else if ("FullSyncPostAction".equals(name))
act = new PostDocumentTransaction();
else if ("FullSyncPutAttachmentAction".equals(name))
act = new PutDocumentAttachmentTransaction();
if (act != null) {
QName typeQName = act.getComplexTypeAffectation();
XmlSchemaType xmlSchemaType = schema.getTypeByName(typeQName);
Document document = XmlSchemaUtils.getDomInstance(xmlSchemaType);
String jsonString = XMLUtils.XmlToJson(document.getDocumentElement(), true, true);
JSONObject jsonOutput = new JSONObject(jsonString).getJSONObject("document");
cleanJsonModel(jsonOutput);
jsonOutput.remove("_c8oMeta");
jsonOutput.remove("error");
jsonOutput.remove("reason");
if (jsonObject.has("out")) {
jsonObject.put("out", jsonOutput);
}
}
}
}
}
}
} else if (dbo instanceof UICustomAction) {
jsonObject = new JSONObject(((UICustomAction) dbo).computeJsonModel());
}
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of UISharedComponent
if (dbo instanceof UISharedComponent) {
JSONObject jsonObject = new JSONObject(((UISharedComponent) dbo).computeJsonModel());
String searchPath = dataPath;
JSONObject jsonOutput = findJSONObject(jsonObject, searchPath);
jsonModel = jsonOutput;
} else // case of ApplicationComponent
if (dbo instanceof ApplicationComponent) {
String json = params.get("json");
jsonModel = new JSONObject(json);
} else // should not happened
{
throw new Exception("DatabaseObject " + dbo.getClass().getName() + " not supported!");
}
}
return jsonModel;
}
use of com.twinsoft.convertigo.beans.ngx.components.UICustomAction in project convertigo by convertigo.
the class NgxBuilder method getFunctionTempTsRelativePath.
@Override
public String getFunctionTempTsRelativePath(final IUIComponent uiComponent) throws EngineException {
UIComponent uic = (UIComponent) uiComponent;
IScriptComponent main = uic.getMainScriptComponent();
if (main != null) {
File tempTsDir = null;
String tempTsFileName = null;
if (main instanceof ApplicationComponent) {
UIActionStack stack = uic.getSharedAction();
tempTsDir = stack == null ? appDir : servicesDir;
tempTsFileName = stack == null ? "app.component.function.temp.ts" : "actionbeans.service.function.temp.ts";
}
if (main instanceof PageComponent) {
PageComponent page = (PageComponent) main;
String pageName = page.getName();
tempTsDir = pageDir(page);
tempTsFileName = pageName.toLowerCase() + ".function.temp.ts";
}
if (tempTsDir != null && tempTsFileName != null) {
if (uiComponent instanceof UICustomAction) {
tempTsFileName = "CTS" + ((UICustomAction) uiComponent).priority + ".temp.ts";
}
File tempTsFile = new File(tempTsDir, tempTsFileName);
return tempTsFile.getPath().replace(projectDir.getPath(), File.separator);
}
}
return null;
}
use of com.twinsoft.convertigo.beans.ngx.components.UICustomAction 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);
}
}
// 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) {
int i = tsContent.indexOf("{", index);
tsContent = tsContent.substring(0, i + 1) + System.lineSeparator() + uica.getActionCode() + System.lineSeparator() + "}" + System.lineSeparator();
}
}
}
// 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);
}
}
Aggregations