use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class CreateMobileApplicationTranslationsFileAction 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();
List<String> textList = new ArrayList<String>();
if ((databaseObject != null) && (databaseObject instanceof ApplicationComponent)) {
ApplicationComponent application = (ApplicationComponent) databaseObject;
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
String text = null;
if (databaseObject instanceof PageComponent) {
PageComponent page = (PageComponent) databaseObject;
text = page.getTitle();
} else if (databaseObject instanceof UIUseShared) {
UIUseShared uius = (UIUseShared) databaseObject;
UISharedComponent uisc = uius.getTargetSharedComponent();
if (uisc != null && !uius.isRecursive()) {
super.walk(uisc);
}
} else if (databaseObject instanceof UIText) {
UIText uiText = (UIText) databaseObject;
MobileSmartSourceType msst = uiText.getTextSmartType();
if (Mode.PLAIN.equals(msst.getMode())) {
text = msst.getValue();
}
}
if (text != null && !textList.contains(text)) {
textList.add(text);
}
super.walk(databaseObject);
}
}.init(application);
MobileApplicationTranslationsDialog dlg = new MobileApplicationTranslationsDialog(shell);
int ret = dlg.open();
if (ret != Window.OK) {
return;
}
Locale from = dlg.getLocaleFrom();
Locale to = dlg.getLocaleTo();
boolean auto = dlg.isAuto();
File i18nDir = new File(application.getProject().getDirPath(), "DisplayObjects/mobile/assets/i18n");
// store source file
File source = new File(i18nDir, from.getLanguage() + ".json");
TranslateUtils.storeTranslations(textList, source);
ConvertigoPlugin.logDebug(source.getName() + " file successfully created or updated.");
// store target file
if (!to.equals(from)) {
File target = new File(i18nDir, to.getLanguage() + ".json");
// translate with google api
if (auto) {
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
dialog.run(true, false, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("translating", IProgressMonitor.UNKNOWN);
Translator translator = TranslateUtils.newTranslator();
try {
translator.translate(from, source, to, target);
ConvertigoPlugin.logDebug(target.getName() + " file successfully translated.");
} catch (Exception e) {
ConvertigoPlugin.logError(e.getMessage(), false);
try {
TranslateUtils.storeTranslations(textList, target);
} catch (Exception ex) {
}
}
monitor.done();
}
});
} else // do not translate
{
TranslateUtils.storeTranslations(textList, target);
}
ConvertigoPlugin.logDebug(target.getName() + " file successfully created or updated.");
}
// regenerate app templates
try {
application.markApplicationAsDirty();
for (PageComponent page : application.getPageComponentList()) {
if (page.isEnabled()) {
page.markPageAsDirty();
}
}
} catch (Throwable t) {
}
ConvertigoPlugin.logInfo("Translations file(s) successfully created or updated.", true);
}
}
} catch (Throwable e) {
ConvertigoPlugin.logException(e, "Unable to create the Mobile application translations file(s)!");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class Ionic3Builder method appContributorsChanged.
@Override
public void appContributorsChanged(final IApplicationComponent appComponent) throws EngineException {
ApplicationComponent app = (ApplicationComponent) appComponent;
if (app != null && initDone) {
synchronized (app) {
writeAppPackageJson(app);
writeAppPluginsConfig(app);
writeAppServiceTs(app);
writeAppModuleTs(app);
moveFiles();
Engine.logEngine.trace("(MobileBuilder) Handled 'appContributorsChanged'");
}
}
}
use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class Ionic3Builder method updateSourceFiles.
private void updateSourceFiles() throws EngineException {
try {
MobileApplication mobileApplication = project.getMobileApplication();
if (mobileApplication != null) {
ApplicationComponent application = (ApplicationComponent) mobileApplication.getApplicationComponent();
if (application != null) {
String appTplVersion = application.requiredTplVersion();
if (compareVersions(tplVersion, appTplVersion) >= 0) {
for (PageComponent page : getEnabledPages(application)) {
writePageSourceFiles(page);
}
writeAppSourceFiles(application);
removeUselessPages(application);
Engine.logEngine.trace("(MobileBuilder) Application source files updated for ionic project '" + project.getName() + "'");
} else {
cleanDirectories();
throw new EngineException("Template project minimum " + appTplVersion + " is required for this project.\n" + "You can change template by configuring the 'Template project' property of your project's 'Application' object.\n" + "Then, be sure to update the project node modules packages (Application Right Click->Update packages and execute) \n");
}
}
}
} catch (EngineException e) {
throw e;
} catch (Exception e) {
throw new EngineException("Unable to update application source files for ionic project '" + project.getName() + "'", e);
}
}
use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class Ionic3Builder method init.
@Override
protected synchronized void init() throws EngineException {
if (initDone) {
return;
}
ApplicationComponent application = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
String tplName = application.getTplProjectName();
if (!project.getName().equals(tplName)) {
try {
Engine.theApp.referencedProjectManager.getReferenceFromProject(project, tplName);
Engine.theApp.referencedProjectManager.importProjectFrom(project, tplName);
} catch (Exception e) {
throw new EngineException("Failed to import referenced template: " + tplName + " :" + e.getMessage(), e);
}
}
ionicTplDir = application.getIonicTplDir();
if (!ionicTplDir.exists()) {
throw new EngineException("Missing template project '" + application.getTplProjectName() + "'\nThe template folder should be in: " + ionicTplDir.getPath());
}
if (Engine.isStudioMode()) {
File devicePref = new File(Engine.USER_WORKSPACE_PATH, "studio/device-" + project.getName() + ".json");
if (devicePref.exists()) {
try {
JSONObject device = new JSONObject(FileUtils.readFileToString(devicePref, "UTF-8"));
buildMode = MobileBuilderBuildMode.get(device.getString("buildMode"));
} catch (Exception e) {
}
}
}
if (isIonicTemplateBased()) {
if (eventHelper == null) {
eventHelper = new EventHelper();
}
setNeedPkgUpdate(false);
// Clean directories
cleanDirectories();
// Copy template directory to working directory
copyTemplateFiles();
// Copy template assets to build directory
copyAssetsToBuildDir();
// Modify configuration files
updateConfigurationFiles();
// Tpl version
updateTplVersion();
// PWA
configurePwaApp(application);
// Write source files (based on bean components)
updateSourceFiles();
// Studio mode : start worker for build process
if (Engine.isStudioMode() || Engine.isCliMode()) {
if (pushedFiles == null) {
pushedFiles = new HashMap<String, CharSequence>();
}
if (queue == null) {
queue = new LinkedBlockingQueue<Map<String, CharSequence>>();
}
if (worker == null) {
worker = new MbWorker(queue);
if (Engine.isStudioMode()) {
worker.start();
} else {
worker.process();
}
}
}
initDone = true;
Engine.logEngine.debug("(MobileBuilder) Initialized builder for ionic project '" + project.getName() + "'");
}
}
use of com.twinsoft.convertigo.beans.mobile.components.ApplicationComponent in project convertigo by convertigo.
the class Ionic3Builder method appTemplateChanged.
@Override
public void appTemplateChanged(final IApplicationComponent appComponent) throws EngineException {
ApplicationComponent app = (ApplicationComponent) appComponent;
if (app != null && initDone) {
synchronized (app) {
writeAppTemplate(app);
moveFiles();
Engine.logEngine.trace("(MobileBuilder) Handled 'appTemplateChanged'");
}
}
}
Aggregations