use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.
the class Get method getServiceResult.
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
String projectName = request.getParameter("projectName");
Element root = document.getDocumentElement();
root.setAttribute("name", projectName);
ProjectUtils.getFullProjectDOM(document, projectName, new StreamSource(getClass().getResourceAsStream("cleanDOM.xsl")));
final Map<String, DatabaseObject> map = getDatabaseObjectByQName(request);
map.clear();
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(projectName);
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
map.put(databaseObject.getQName(), databaseObject);
super.walk(databaseObject);
}
}.init(project);
}
use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.
the class CreateNgxApplicationTranslationsFileAction 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.engine.helpers.WalkHelper 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.engine.helpers.WalkHelper in project convertigo by convertigo.
the class MobileSmartSource method findDatabaseObject.
private DatabaseObject findDatabaseObject(final String dboName, final long priority) throws Exception {
Project project = Engine.theApp.databaseObjectsManager.getOriginalProjectByName(getProjectName());
DatabaseObject root = null;
if (dboName != null) {
ApplicationComponent app = (ApplicationComponent) project.getMobileApplication().getApplicationComponent();
try {
root = app.getPageComponentByName(dboName);
} catch (Exception e1) {
try {
root = app.getMenuComponentByName(dboName);
} catch (Exception e2) {
try {
root = app;
} catch (Exception e3) {
;
}
}
}
}
if (root == null) {
root = project;
}
final List<DatabaseObject> list = new ArrayList<DatabaseObject>();
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (databaseObject.priority == priority) {
list.add(databaseObject);
}
if (list.isEmpty()) {
super.walk(databaseObject);
}
}
}.init(root);
return list.isEmpty() ? null : list.get(0);
}
use of com.twinsoft.convertigo.engine.helpers.WalkHelper in project convertigo by convertigo.
the class UIDynamicAnimate method getAnimatableId.
private String getAnimatableId() {
if (!identifiable.isEmpty()) {
String p_name = identifiable.substring(0, identifiable.indexOf('.'));
Project project = this.getProject();
if (project != null) {
Project p = null;
try {
// p = p_name.equals(project.getName()) ? project: Engine.theApp.databaseObjectsManager.getOriginalProjectByName(p_name);
p = Engine.theApp.referencedProjectManager.importProjectFrom(project, p_name);
} catch (Exception e) {
Engine.logBeans.warn("(UIDynamicAnimate) For \"" + this.toString() + "\", targeted project \"" + p_name + "\" is missing !");
}
if (p != null) {
Map<String, DatabaseObject> map = new HashMap<String, DatabaseObject>();
try {
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
map.put(databaseObject.getQName(), databaseObject);
super.walk(databaseObject);
}
}.init(p);
DatabaseObject animatable = map.get(identifiable);
if (animatable != null && animatable instanceof UIElement) {
return ((UIElement) animatable).getIdentifier();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return "";
}
Aggregations