use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.
the class NgxComponentImportVariablesAction method run.
public void run() {
Display display = Display.getDefault();
Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
Shell shell = getParentShell();
shell.setCursor(waitCursor);
try {
ProjectExplorerView explorerView = getProjectExplorerView();
if (explorerView != null) {
TreeObject treeObject = explorerView.getFirstSelectedTreeObject();
Object databaseObject = treeObject.getObject();
if (databaseObject != null) {
if (databaseObject instanceof UIDynamicAction) {
UIDynamicAction dynAction = (UIDynamicAction) databaseObject;
IonBean ionBean = ((UIDynamicAction) dynAction).getIonBean();
if (ionBean != null) {
// Case of CallSequenceAction
if (ionBean.getName().equals("CallSequenceAction")) {
Object value = ionBean.getProperty("requestable").getValue();
if (!value.equals(false)) {
String target = value.toString();
if (!target.isEmpty()) {
try {
String projectName = target.substring(0, target.indexOf('.'));
String sequenceName = target.substring(target.indexOf('.') + 1);
Project p = Engine.theApp.databaseObjectsManager.getProjectByName(projectName);
Sequence sequence = p.getSequenceByName(sequenceName);
int size = sequence.numberOfVariables();
for (int i = 0; i < size; i++) {
RequestableVariable variable = (RequestableVariable) sequence.getVariable(i);
if (variable != null) {
String variableName = variable.getName();
if (dynAction.getVariable(variableName) == null) {
if (!StringUtils.isNormalized(variableName))
throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
UIControlVariable uiVariable = new UIControlVariable();
uiVariable.setName(variableName);
uiVariable.setComment(variable.getDescription());
uiVariable.setVarSmartType(new MobileSmartSourceType(variable.getDefaultValue().toString()));
dynAction.addUIComponent(uiVariable);
uiVariable.bNew = true;
uiVariable.hasChanged = true;
dynAction.hasChanged = true;
}
}
}
} catch (Exception e) {
}
}
}
} else // Case of InvokeAction
if (ionBean.getName().equals("InvokeAction")) {
UIDynamicInvoke dynInvoke = (UIDynamicInvoke) databaseObject;
UIActionStack stack = dynInvoke.getTargetSharedAction();
if (stack != null) {
for (UIStackVariable variable : stack.getVariables()) {
String variableName = variable.getName();
if (dynAction.getVariable(variableName) == null) {
if (!StringUtils.isNormalized(variableName))
throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
UIControlVariable uiVariable = new UIControlVariable();
uiVariable.setName(variableName);
uiVariable.setComment(variable.getComment());
MobileSmartSourceType msst = new MobileSmartSourceType();
msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
msst.setSmartValue(variable.getVariableValue());
uiVariable.setVarSmartType(msst);
dynAction.addUIComponent(uiVariable);
uiVariable.bNew = true;
uiVariable.hasChanged = true;
dynAction.hasChanged = true;
}
}
}
}
if (dynAction.hasChanged) {
IScriptComponent main = dynAction.getMainScriptComponent();
if (main != null) {
if (main instanceof ApplicationComponent) {
((ApplicationComponent) main).markApplicationAsDirty();
}
if (main instanceof PageComponent) {
((PageComponent) main).markPageAsDirty();
}
}
explorerView.reloadTreeObject(treeObject);
StructuredSelection structuredSelection = new StructuredSelection(treeObject);
ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
}
}
} else if (databaseObject instanceof UIUseShared) {
UIUseShared useShared = (UIUseShared) databaseObject;
UISharedComponent sharedComp = useShared.getTargetSharedComponent();
if (sharedComp != null) {
for (UICompVariable variable : sharedComp.getVariables()) {
String variableName = variable.getName();
if (useShared.getVariable(variableName) == null) {
if (!StringUtils.isNormalized(variableName))
throw new EngineException("Variable name is not normalized : \"" + variableName + "\".");
UIUseVariable uiVariable = new UIUseVariable();
uiVariable.setName(variableName);
uiVariable.setComment(variable.getComment());
MobileSmartSourceType msst = new MobileSmartSourceType();
msst.setMode(MobileSmartSourceType.Mode.SCRIPT);
msst.setSmartValue(variable.getVariableValue());
uiVariable.setVarSmartType(msst);
useShared.addUIComponent(uiVariable);
uiVariable.bNew = true;
uiVariable.hasChanged = true;
useShared.hasChanged = true;
}
}
if (useShared.hasChanged) {
IScriptComponent main = useShared.getMainScriptComponent();
if (main != null) {
if (main instanceof ApplicationComponent) {
((ApplicationComponent) main).markApplicationAsDirty();
}
if (main instanceof PageComponent) {
((PageComponent) main).markPageAsDirty();
}
}
explorerView.reloadTreeObject(treeObject);
StructuredSelection structuredSelection = new StructuredSelection(treeObject);
ConvertigoPlugin.getDefault().getPropertiesView().selectionChanged((IWorkbenchPart) explorerView, structuredSelection);
}
}
}
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to add variables to action !");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.
the class ApplicationComponentEditor method launchBuilder.
public void launchBuilder(boolean forceInstall, boolean forceClean) {
final int buildCount = ++this.buildCount;
// Close editors (*.temp.ts) to avoid npm error at build launch
ConvertigoPlugin.getDisplay().syncExec(new Runnable() {
public void run() {
try {
ApplicationComponent app = applicationEditorInput.application;
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (activePage != null) {
IEditorReference[] editorRefs = activePage.getEditorReferences();
for (int i = 0; i < editorRefs.length; i++) {
IEditorReference editorRef = (IEditorReference) editorRefs[i];
try {
IEditorInput editorInput = editorRef.getEditorInput();
if (editorInput != null && editorInput instanceof ComponentFileEditorInput) {
if (((ComponentFileEditorInput) editorInput).is(app) || ((ComponentFileEditorInput) editorInput).isChildOf(app)) {
activePage.closeEditor(editorRef.getEditor(false), false);
}
}
} catch (Exception e) {
}
}
}
} catch (Throwable t) {
}
}
});
// Launch build
Engine.execute(() -> {
initLoader();
project = applicationEditorInput.application.getProject();
ionicDir = new File(project.getDirPath(), "_private/ionic");
nodeModules = new File(ionicDir, "node_modules");
String nodeVersion = ProcessUtils.getNodeVersion(project);
nodeDir = ProcessUtils.getDefaultNodeDir();
try {
nodeDir = ProcessUtils.getNodeDir(nodeVersion, (r, t, x) -> {
appendOutput("Downloading nodejs " + nodeVersion + ": " + Math.round((r * 100f) / t) + "%");
});
} catch (Exception e1) {
}
{
String versions = "Will use nodejs " + ProcessUtils.getNodeVersion(nodeDir) + " and npm " + ProcessUtils.getNpmVersion(nodeDir);
appendOutput(versions);
Engine.logStudio.info(versions);
}
String path = nodeDir.getAbsolutePath();
terminateNode(false);
MobileBuilder mb = project.getMobileBuilder();
if (forceInstall || !nodeModules.exists() || mb.getNeedPkgUpdate()) {
boolean[] running = { true };
try {
if (forceClean) {
appendOutput("...", "...", "Removing existing node_modules... This can take several seconds...");
Engine.logStudio.info("Removing existing node_modules... This can take several seconds...");
com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules);
}
appendOutput("Installing node_modules... This can take several minutes depending on your network connection speed...");
Engine.logStudio.info("Installing node_modules... This can take several minutes depending on your network connection speed...");
if (!nodeModules.exists()) {
File packageLockTpl = new File(ionicDir, "package-lock-tpl.json");
if (packageLockTpl.exists()) {
com.twinsoft.convertigo.engine.util.FileUtils.copyFile(packageLockTpl, new File(ionicDir, "package-lock.json"));
}
}
ProcessBuilder pb = ProcessUtils.getNpmProcessBuilder(path + File.pathSeparator + ionicDir.toString(), "npm", "install", "--legacy-peer-deps", "--loglevel", "info");
pb.redirectErrorStream(true);
pb.directory(ionicDir);
Process p = pb.start();
processes.add(p);
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
line = pRemoveEchap.matcher(line).replaceAll("");
if (StringUtils.isNotBlank(line)) {
Engine.logStudio.info(line);
appendOutput(line);
}
}
Engine.logStudio.info(line);
appendOutput("\\o/");
} catch (Exception e) {
appendOutput(":( " + e);
}
running[0] = false;
}
mb.setNeedPkgUpdate(false);
build(path, buildCount, mb);
});
}
use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.
the class ApplicationComponentEditor method init.
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
setSite(site);
setInput(input);
applicationEditorInput = (ApplicationComponentEditorInput) input;
ApplicationComponent application = applicationEditorInput.application;
Project project = application.getProject();
datasetDir = new File(project.getDirPath(), "dataset");
datasetDir.mkdirs();
devicePref = new File(Engine.USER_WORKSPACE_PATH, "studio/device-" + project.getName() + ".json");
setPartName(project.getName() + " [A: " + application.getName() + "]");
terminateNode(false);
}
use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.
the class ComponentManager method makeComponents.
private synchronized List<Component> makeComponents() {
if (components != null) {
return components;
}
components = new ArrayList<Component>(10);
try {
String group;
// Add Customs
group = GROUP_CUSTOMS;
components.add(getDboComponent(UIElement.class, group));
components.add(getDboComponent(UIAttribute.class, group));
components.add(getDboComponent(UIAnimation.class, group));
components.add(getDboComponent(UICustom.class, group));
components.add(getDboComponent(UIText.class, group));
components.add(getDboComponent(UIStyle.class, group));
components.add(getDboComponent(UITheme.class, group));
// Add shared components
group = GROUP_SHARED_COMPONENTS;
// components.add(getDboComponent(UISharedComponent.class,group)); // deprecated
components.add(getDboComponent(UISharedRegularComponent.class, group));
components.add(getDboComponent(UIUseShared.class, group));
components.add(getDboComponent(UICompVariable.class, group));
components.add(getDboComponent(UIUseVariable.class, group));
components.add(getDboComponent(UICompEvent.class, group));
// Add shared actions
group = GROUP_SHARED_ACTIONS;
components.add(getDboComponent(UIActionStack.class, group));
components.add(getDboComponent(UIStackVariable.class, group));
// Add Controls
group = GROUP_CONTROLS;
components.add(getDboComponent(UIControlEvent.class, group));
components.add(getDboComponent(UIAppEvent.class, group));
components.add(getDboComponent(UIPageEvent.class, group));
components.add(getDboComponent(UISharedComponentEvent.class, group));
components.add(getDboComponent(UIAppGuard.class, group));
components.add(getDboComponent(UIEventSubscriber.class, group));
components.add(getDboComponent(UIActionErrorEvent.class, group));
components.add(getDboComponent(UIActionFailureEvent.class, group));
components.add(getDboComponent(UIActionFinallyEvent.class, group));
components.add(getDboComponent(UIActionLoopEvent.class, group));
components.add(getDboComponent(UIActionCaseEvent.class, group));
components.add(getDboComponent(UIActionCaseDefaultEvent.class, group));
components.add(getDboComponent(UIActionElseEvent.class, group));
components.add(getDboComponent(UIControlDirective.class, group));
// Add Actions
group = GROUP_ACTIONS;
components.add(getDboComponent(UIControlVariable.class, group));
components.add(getDboComponent(UICustomAction.class, group));
components.add(getDboComponent(UICustomAsyncAction.class, group));
components.add(getDboComponent(UIForm.class, "Forms"));
// components.add(getDboComponent(UIFormControlValidator.class,"Forms"));
// components.add(getDboComponent(UIFormCustomValidator.class,"Forms"));
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
for (final IonBean bean : instance.bCache.values()) {
components.add(new Component() {
@Override
public boolean isAllowedIn(DatabaseObject parent) {
if (bean.getTag().equals("ion-menu")) {
return parent instanceof ApplicationComponent;
}
if (bean.getClassName().startsWith("com.twinsoft.convertigo.beans.ngx.components.UIDynamicMenuItem")) {
if (parent instanceof UIComponent) {
if (parent instanceof UIDynamicMenuItem)
return false;
UIDynamicMenu menu = ((UIComponent) parent).getMenu();
return menu != null;
}
}
Class<?> dboClass;
try {
dboClass = Class.forName(bean.getClassName());
if (acceptDatabaseObjects(parent, dboClass)) {
return isTplCompatible(parent, createBean());
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public String getLabel() {
return bean.getLabel();
}
@Override
public String getImagePath() {
return bean.getIconColor32Path();
}
@Override
public String getGroup() {
return bean.getGroup();
}
@Override
public String getDescription() {
return bean.getDescription();
}
@Override
public String getName() {
return bean.getName();
}
@Override
public String getTag() {
return bean.getTag();
}
@Override
public String getPropertiesDescription() {
String propertiesDescription = "";
List<IonProperty> properties = new ArrayList<IonProperty>();
properties.addAll(bean.getProperties().values());
Collections.sort(properties, new Comparator<IonProperty>() {
@Override
public int compare(IonProperty p1, IonProperty p2) {
return p1.getLabel().compareTo(p2.getLabel());
}
});
for (IonProperty ionProperty : properties) {
if (!ionProperty.isHidden()) {
propertiesDescription += "<li><i>" + ionProperty.getLabel() + "</i>";
propertiesDescription += "</br>" + ionProperty.getDescription() + "</li>";
}
}
Class<?> dboClass;
try {
dboClass = Class.forName(bean.getClassName());
BeanInfo beanInfo = Introspector.getBeanInfo(dboClass);
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
propertyDescriptors = propertyDescriptors.clone();
Arrays.sort(propertyDescriptors, (o1, o2) -> {
if (o1.isExpert() == o2.isExpert()) {
return o1.getDisplayName().compareTo(o2.getDisplayName());
} else if (o1.isExpert()) {
return 1;
} else {
return -1;
}
});
for (PropertyDescriptor dbopd : propertyDescriptors) {
if (!dbopd.isHidden() && !Boolean.TRUE.equals(dbopd.getValue("disable"))) {
propertiesDescription += "<li><i>" + dbopd.getDisplayName() + "</i>";
propertiesDescription += "</br>" + dbopd.getShortDescription().replace("|", "") + "</li>";
}
}
} catch (Exception e) {
e.printStackTrace();
}
return propertiesDescription.isEmpty() ? "" : "<ul>" + propertiesDescription + "</ul>";
}
@Override
protected DatabaseObject createBean() {
DatabaseObject dbo = bean.createBean();
return dbo;
}
@Override
protected JSONObject getHint() {
return bean.getHint();
}
});
}
Collections.sort(components, new Comparator<Component>() {
@Override
public int compare(Component c1, Component c2) {
return c1.getLabel().compareTo(c2.getLabel());
}
});
return components = Collections.unmodifiableList(components);
}
use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.
the class NgxBuilder method addPage.
private void addPage(PageComponent page) throws EngineException {
MobileApplication mobileApplication = project.getMobileApplication();
if (mobileApplication != null) {
ApplicationComponent application = (ApplicationComponent) mobileApplication.getApplicationComponent();
if (application != null) {
writePageSourceFiles(page);
writeAppSourceFiles(application);
}
}
}
Aggregations