use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class MobileApplicationComponentTreeObject method activeEditor.
public ApplicationComponentEditor activeEditor(boolean autoLaunch) {
ApplicationComponentEditor editorPart = null;
ApplicationComponent application = (ApplicationComponent) getObject();
synchronized (application) {
String tpl = application.getTplProjectName();
try {
if (StringUtils.isBlank(tpl) || Engine.theApp.databaseObjectsManager.getOriginalProjectByName(tpl, false) == null) {
throw new InvalidParameterException("The value '" + tpl + "' of the property 'Template project' from '" + application.getQName() + "' is incorrect.");
}
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 ApplicationComponentEditorInput)) {
if (((ApplicationComponentEditorInput) editorInput).is(application)) {
editorPart = (ApplicationComponentEditor) editorRef.getEditor(false);
}
}
} catch (PartInitException e) {
}
}
if (editorPart != null) {
activePage.activate(editorPart);
} else {
IEditorPart editor = activePage.openEditor(new ApplicationComponentEditorInput(application, autoLaunch), "com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditor");
if (editor instanceof ApplicationComponentEditor) {
editorPart = (ApplicationComponentEditor) editor;
} else {
ConvertigoPlugin.logWarning("The Application Component Editor won't open, please see the error log.");
}
}
}
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Error while loading the page editor '" + application.getName() + "'");
}
}
return editorPart;
}
use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class MobileApplicationComponentTreeObject method treeObjectPropertyChanged.
@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
super.treeObjectPropertyChanged(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
Set<Object> done = checkDone(treeObjectEvent);
String propertyName = (String) treeObjectEvent.propertyName;
propertyName = ((propertyName == null) ? "" : propertyName);
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
DatabaseObject dbo = doto.getObject();
try {
ApplicationComponent ac = getObject();
// for Page or Menu or Route
if (ac.equals(dbo.getParent())) {
markApplicationAsDirty(done);
} else // for any component inside a route
if (ac.equals(dbo.getParent().getParent())) {
markApplicationAsDirty(done);
} else // for any UI component inside a menu or a stack
if (dbo instanceof UIComponent) {
UIComponent uic = (UIComponent) dbo;
UIDynamicMenu menu = uic.getMenu();
if (menu != null) {
if (ac.equals(menu.getParent())) {
if (propertyName.equals("FormControlName") || uic.isFormControlAttribute()) {
if (!newValue.equals(oldValue)) {
try {
String oldSmart = ((MobileSmartSourceType) oldValue).getSmartValue();
String newSmart = ((MobileSmartSourceType) newValue).getSmartValue();
if (uic.getUIForm() != null) {
String form = uic.getUIForm().getFormGroupName();
if (menu.updateSmartSource(form + "\\?\\.controls\\['" + oldSmart + "'\\]", form + "?.controls['" + newSmart + "']")) {
this.viewer.refresh();
}
}
} catch (Exception e) {
}
}
}
markApplicationAsDirty(done);
}
}
} else // for this application
if (this.equals(doto)) {
if (propertyName.equals("isPWA")) {
if (!newValue.equals(oldValue)) {
markPwaAsDirty();
}
} else if (propertyName.equals("componentScriptContent")) {
if (!newValue.equals(oldValue)) {
markComponentTsAsDirty();
markApplicationAsDirty(done);
}
} else if (propertyName.equals("useClickForTap")) {
for (TreeObject to : this.getChildren()) {
if (to instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
for (TreeObject cto : ofto.getChildren()) {
if (cto instanceof MobilePageComponentTreeObject) {
((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
}
}
}
}
}
markApplicationAsDirty(done);
} else if (propertyName.equals("tplProjectName")) {
// close app editor and reinitialize builder
Project project = ac.getProject();
closeAllEditors(false);
MobileBuilder.releaseBuilder(project);
MobileBuilder.initBuilder(project);
IProject iproject = ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName());
iproject.refreshLocal(IResource.DEPTH_INFINITE, null);
// force app sources regeneration
for (TreeObject to : this.getChildren()) {
if (to instanceof ObjectsFolderTreeObject) {
ObjectsFolderTreeObject ofto = (ObjectsFolderTreeObject) to;
if (ofto.folderType == ObjectsFolderTreeObject.FOLDER_TYPE_PAGES) {
for (TreeObject cto : ofto.getChildren()) {
if (cto instanceof MobilePageComponentTreeObject) {
((MobilePageComponentTreeObject) cto).markPageAsDirty(done);
}
}
}
}
}
markApplicationAsDirty(done);
// delete node modules and alert user
final File nodeModules = new File(project.getDirPath(), "/_private/ionic/node_modules");
if (nodeModules.exists()) {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(ConvertigoPlugin.getMainShell());
dialog.open();
dialog.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("deleting node modules", IProgressMonitor.UNKNOWN);
String alert = "template changed!";
if (com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(nodeModules)) {
alert = "You have just changed the template.\nPackages have been deleted and will be reinstalled next time you run your application again.";
} else {
alert = "You have just changed the template: packages could not be deleted!\nDo not forget to reinstall the packages before running your application again, otherwise it may be corrupted!";
}
monitor.done();
ConvertigoPlugin.infoMessageBox(alert);
}
});
}
} else {
markApplicationAsDirty(done);
}
}
} catch (Exception e) {
}
}
}
use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class MobileApplicationTreeObject method treeObjectPropertyChanged.
@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
super.treeObjectPropertyChanged(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
String propertyName = (String) treeObjectEvent.propertyName;
propertyName = ((propertyName == null) ? "" : propertyName);
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
DatabaseObject dbo = doto.getObject();
try {
if (this.equals(doto)) {
if (propertyName.equals("applicationName")) {
if (!newValue.equals(oldValue)) {
ApplicationComponent app = (ApplicationComponent) ((MobileApplication) dbo).getApplicationComponent();
app.markPwaAsDirty();
}
}
}
} catch (Exception e) {
}
}
}
use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class ApplicationComponentEditor method launchBuilder.
public void launchBuilder(boolean forceInstall, boolean forceClean) {
final MobileBuilderBuildMode buildMode = this.buildMode;
final int buildCount = ++this.buildCount;
final boolean isDark = SwtUtils.isDark();
// Close editors (*.temp.ts) to avoid npm error at build launch
ConvertigoPlugin.getDisplay().syncExec(new Runnable() {
public void run() {
try {
ApplicationComponent mc = 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(mc) || ((ComponentFileEditorInput) editorInput).isChildOf(mc)) {
activePage.closeEditor(editorRef.getEditor(false), false);
}
}
} catch (Exception e) {
}
}
}
} catch (Throwable t) {
}
}
});
// Launch build
Engine.execute(() -> {
try {
String loader = IOUtils.toString(getClass().getResourceAsStream("loader.html"), "UTF-8");
if (isDark) {
loader = loader.replace("lightblue", "rgb(47,47,47); color: white");
}
c8oBrowser.setText(loader);
} catch (Exception e1) {
throw new RuntimeException(e1);
}
Project project = applicationEditorInput.application.getProject();
File ionicDir = new File(project.getDirPath(), "_private/ionic");
File nodeModules = new File(ionicDir, "node_modules");
String nodeVersion = ProcessUtils.getNodeVersion(project);
File 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();
MobileBuilder mb = project.getMobileBuilder();
if (forceInstall || !nodeModules.exists() || mb.getNeedPkgUpdate()) {
boolean[] running = { true };
try {
new File(ionicDir, "package-lock.json").delete();
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...");
long start = System.currentTimeMillis();
ProcessBuilder pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "install", ionicDir.toString(), "--no-shrinkwrap", "--no-package-lock");
pb.redirectErrorStream(true);
pb.directory(ionicDir);
Process p = pb.start();
Engine.execute(() -> {
try {
File staging = new File(nodeModules, ".staging");
while (running[0] && !staging.exists()) {
appendOutput("Resolving dependencies … (" + Math.round(System.currentTimeMillis() - start) / 1000 + " sec)");
Thread.sleep(1000);
}
while (running[0] && staging.exists()) {
appendOutput("Collecting node_modules: " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)) + " (" + Math.round(System.currentTimeMillis() - start) / 1000 + " sec)");
Engine.logStudio.info("Installing, node_module size is now : " + FileUtils.byteCountToDisplaySize(FileUtils.sizeOfAsBigInteger(nodeModules)));
Thread.sleep(1000);
}
} catch (Exception e) {
appendOutput("Something wrong during the install: " + e);
}
});
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);
Object mutex = new Object();
mb.setBuildMutex(mutex);
mb.setAppBuildMode(buildMode);
try {
ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName()).refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException ce) {
}
try {
mb.startBuild();
File displayObjectsMobile = new File(project.getDirPath(), "DisplayObjects/mobile");
displayObjectsMobile.mkdirs();
appendOutput("removing previous build directory");
for (File f : displayObjectsMobile.listFiles()) {
if (!f.getName().equals("assets")) {
com.twinsoft.convertigo.engine.util.FileUtils.deleteQuietly(f);
}
}
appendOutput("previous build directory removed");
this.applicationEditorInput.application.checkFolder();
try {
File watchJS = new File(project.getDirPath(), "_private/ionic/node_modules/@ionic/app-scripts/dist/watch.js");
if (watchJS.exists()) {
int ms = ConvertigoPlugin.getMobileBuilderThreshold();
String txt = FileUtils.readFileToString(watchJS, "UTF-8");
String ntxt = txt.replaceAll("var BUILD_UPDATE_DEBOUNCE_MS = \\d+;", "var BUILD_UPDATE_DEBOUNCE_MS = " + ms + ";");
if (!txt.equals(ntxt))
;
{
FileUtils.writeStringToFile(watchJS, ntxt, "UTF-8");
}
}
} catch (Exception e) {
Engine.logStudio.warn("Failed to update DEBOUNCE", e);
}
File assets = new File(displayObjectsMobile, "assets");
if (assets.exists() && assets.isDirectory()) {
appendOutput("Handle application assets");
Engine.logStudio.info("Handle application assets");
File privAssets = new File(ionicDir, "src/assets");
FileUtils.deleteDirectory(privAssets);
FileUtils.copyDirectory(assets, privAssets);
}
ProcessBuilder pb = ProcessUtils.getNpmProcessBuilder(path, "npm", "run", buildMode.command(), "--nobrowser");
if (!MobileBuilderBuildMode.production.equals(buildMode)) {
List<String> cmd = pb.command();
synchronized (usedPort) {
cmd.add("--port");
cmd.add("" + (portNode = NetworkUtils.nextAvailable(8100, usedPort)));
cmd.add("--livereload-port");
cmd.add("" + (portReload = NetworkUtils.nextAvailable(35729, usedPort)));
cmd.add("--dev-logger-port");
cmd.add("" + (portLogger = NetworkUtils.nextAvailable(53703, usedPort)));
}
}
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);
if (line.matches(".*build .*finished.*")) {
synchronized (mutex) {
mutex.notify();
}
mb.buildFinished();
}
Matcher m = pIsServerRunning.matcher(line);
if (m.matches()) {
JSONObject envJSON = new JSONObject();
envJSON.put("remoteBase", EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL) + "/projects/" + project.getName() + "/_private");
FileUtils.write(new File(displayObjectsMobile, "env.json"), envJSON.toString(4), "UTF-8");
baseUrl = m.group(1);
synchronized (mutex) {
mutex.notify();
}
mb.buildFinished();
doLoad();
}
}
}
if (buildCount == this.buildCount) {
if (MobileBuilderBuildMode.production.equals(buildMode)) {
String SERVER_C8O_URL = EnginePropertiesManager.getProperty(PropertyName.APPLICATION_SERVER_CONVERTIGO_URL);
baseUrl = SERVER_C8O_URL + "/projects/" + project.getName() + "/DisplayObjects/mobile/index.html";
doLoad();
toast("Application in production mode");
}
appendOutput("\\o/");
} else {
appendOutput("previous build canceled !");
}
} catch (Exception e) {
appendOutput(":( " + e);
} finally {
synchronized (mutex) {
mutex.notify();
}
mb.setBuildMutex(null);
mb.buildFinished();
try {
ConvertigoPlugin.getDefault().getProjectPluginResource(project.getName()).refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException ce) {
}
}
});
}
use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class MobilePickerContentProvider method addActions.
private void addActions(TVObject tvi, Object object) {
if (object != null) {
List<? extends UIComponent> list = null;
if (object instanceof ApplicationComponent) {
ApplicationComponent app = (ApplicationComponent) object;
list = app.getUIAppEventList();
list.addAll(GenericUtils.cast(app.getUIEventSubscriberList()));
list.addAll(GenericUtils.cast(app.getSharedActionList()));
} else if (object instanceof UIActionStack) {
if (tvi != null && "actions".equals(tvi.getName())) {
list = new ArrayList<>(Arrays.asList((UIActionStack) object));
} else {
list = ((UIActionStack) object).getUIComponentList();
}
} else if (object instanceof UISharedComponent) {
list = ((UISharedComponent) object).getUIComponentList();
} else if (object instanceof PageComponent) {
list = ((PageComponent) object).getUIComponentList();
} else if (object instanceof UIComponent) {
list = ((UIComponent) object).getUIComponentList();
}
if (list != null) {
TVObject tvEvents = null, tvControls = null;
if (tvi != null && "actions".equals(tvi.getName())) {
tvEvents = tvi.children.get(0);
tvControls = tvi.children.get(1);
}
for (UIComponent uic : list) {
// do not add to prevent selection on itself or children
if (uic.equals(selected)) {
return;
}
// do not add if not parent of selected (popped picker only)
boolean showInPicker = true;
if (selected != null && selected instanceof UIComponent) {
String selectedQName = ((UIComponent) selected).getQName();
String uicQName = uic.getQName() + ".";
if (!selectedQName.startsWith(uicQName)) {
showInPicker = false;
}
}
if (showInPicker) {
if (uic instanceof UIAppEvent || uic instanceof UIPageEvent || uic instanceof UIEventSubscriber) {
TVObject tve = tvEvents == null ? tvi.add(new TVObject(uic.toString(), uic, null)) : tvEvents.add(new TVObject(uic.toString(), uic, null));
addActions(tve, uic);
} else if (uic instanceof UIActionEvent || uic instanceof UIControlEvent) {
TVObject tve = tvControls == null ? tvi.add(new TVObject(uic.toString(), uic, null)) : tvControls.add(new TVObject(uic.toString(), uic, null));
addActions(tve, uic);
} else if (uic instanceof IAction || uic instanceof UIActionStack) {
SourceData sd = null;
try {
sd = Filter.Action.toSourceData(new JSONObject().put("priority", uic.priority));
} catch (JSONException e) {
e.printStackTrace();
}
TVObject tuic = tvi.add(new TVObject(uic.toString(), uic, sd));
addActions(tuic, uic);
} else {
addActions(tvi, uic);
}
// } else {
// addActions(tvi, uic);
}
}
}
}
}
Aggregations