use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.
the class NgxApplicationComponentTreeObject 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 NgxPageComponentTreeObject) {
((NgxPageComponentTreeObject) 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 NgxPageComponentTreeObject) {
((NgxPageComponentTreeObject) 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.ngx.components.ApplicationComponent in project convertigo by convertigo.
the class NgxApplicationComponentTreeObject 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.ngx.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.ngx.components.ApplicationComponent in project convertigo by convertigo.
the class NgxApplicationComponentTreeObject method editAppComponentTsFile.
public void editAppComponentTsFile() {
final ApplicationComponent application = getObject();
try {
// Refresh project resource
String projectName = application.getProject().getName();
IProject project = ConvertigoPlugin.getDefault().getProjectPluginResource(projectName);
project.refreshLocal(IResource.DEPTH_INFINITE, null);
// Close editor
String filePath = application.getProject().getMobileBuilder().getTempTsRelativePath(application);
IFile file = project.getFile(filePath);
closeComponentFileEditor(file);
// Write temporary file
application.getProject().getMobileBuilder().writeAppComponentTempTs(application);
file.refreshLocal(IResource.DEPTH_ZERO, null);
// Open file in editor
if (file.exists()) {
IEditorInput input = new ComponentFileEditorInput(file, application);
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());
FormatedContent componentScriptContent = new FormatedContent(MobileBuilder.getMarkers(doc.get()));
NgxApplicationComponentTreeObject.this.setPropertyValue("componentScriptContent", componentScriptContent);
}
}
}
});
}
}
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unable to open typescript file for page '" + application.getName() + "'!");
}
}
use of com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent 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.beans.ngx.components.ApplicationComponent in project convertigo by convertigo.
the class NgxComponentImportEventsAction 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 UIUseShared) {
UIUseShared useShared = (UIUseShared) databaseObject;
UISharedComponent sharedComp = useShared.getTargetSharedComponent();
if (sharedComp != null) {
for (UICompEvent event : sharedComp.getUICompEventList()) {
String eventName = event.getName();
if (useShared.getEvent(eventName) == null) {
if (!StringUtils.isNormalized(eventName))
throw new EngineException("event name is not normalized : \"" + eventName + "\".");
UIControlEvent uiEvent = new UIControlEvent();
uiEvent.setEventName(eventName);
uiEvent.setComment(event.getComment());
useShared.addUIComponent(uiEvent);
uiEvent.bNew = true;
uiEvent.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 event to action !");
} finally {
shell.setCursor(null);
waitCursor.dispose();
}
}
Aggregations