use of com.twinsoft.convertigo.beans.mobile.components.UIUseShared 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.UIUseShared in project convertigo by convertigo.
the class ApplicationComponentEditor method highlightComponent.
public void highlightComponent(MobileComponent mobileComponent, boolean selectPage) {
C8oBrowser.run(() -> {
if (selectPage && mobileComponent instanceof UIComponent) {
PageComponent pageComponent = ((UIComponent) mobileComponent).getPage();
if (pageComponent != null) {
selectPage(pageComponent.getSegment());
}
}
Document doc = browser.mainFrame().get().document().get();
MobileComponent mc = mobileComponent;
if (mc instanceof UIUseShared) {
UISharedComponent uisc = ((UIUseShared) mc).getTargetSharedComponent();
if (uisc != null) {
try {
mc = uisc.getUIComponentList().get(0);
} catch (IndexOutOfBoundsException ioobe) {
}
}
}
while (doc.findElementsByClassName("class" + mc.priority).isEmpty()) {
DatabaseObject parent = mc.getParent();
if (parent instanceof MobileComponent) {
mc = (MobileComponent) parent;
} else {
return;
}
}
c8oBrowser.executeJavaScriptAndReturnValue("_c8o_highlight_class('class" + mc.priority + "');");
});
}
use of com.twinsoft.convertigo.beans.mobile.components.UIUseShared in project convertigo by convertigo.
the class ApplicationComponentEditor method highlightPoint.
private void highlightPoint(int x, int y) {
Node node = browser.mainFrame().get().inspect(x, y).node().get();
while (!(node == null || node instanceof Element)) {
node = node.parent().orElse(null);
}
while (node != null) {
Element element = (Element) node;
if (element.equals(exHighlightElement)) {
return;
}
exHighlightElement = element;
String classes = element.attributeValue("class");
Matcher mPriority = pPriority.matcher(classes);
if (mPriority.find()) {
try {
node = null;
long priority = Long.parseLong(mPriority.group(1));
new WalkHelper() {
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (databaseObject instanceof UIUseShared) {
UISharedComponent uisc = ((UIUseShared) databaseObject).getTargetSharedComponent();
if (uisc != null) {
databaseObject = uisc;
}
} else if (databaseObject instanceof UIDynamicInvoke) {
UIDynamicInvoke uidi = (UIDynamicInvoke) databaseObject;
UIActionStack uisa = uidi.getTargetSharedAction();
if (uisa != null) {
if (!uidi.isRecursive()) {
databaseObject = uisa;
}
}
}
if (databaseObject.priority == priority) {
throw new DatabaseObjectFoundException(databaseObject);
}
super.walk(databaseObject);
}
}.init(applicationEditorInput.application);
} catch (DatabaseObjectFoundException e) {
DatabaseObject databaseObject = e.getDatabaseObject();
c8oBrowser.getDisplay().asyncExec(() -> ConvertigoPlugin.getDefault().getProjectExplorerView().objectSelected(new CompositeEvent(databaseObject)));
if (databaseObject instanceof MobileComponent && !databaseObject.equals(exHighlightMobileComponent)) {
highlightComponent(exHighlightMobileComponent = (MobileComponent) databaseObject, false);
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
node = node.parent().orElse(null);
while (!(node == null || node instanceof Element)) {
node = node.parent().orElse(null);
}
}
}
}
use of com.twinsoft.convertigo.beans.mobile.components.UIUseShared in project convertigo by convertigo.
the class MobileComponentImportVariablesAction 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 + "\".");
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);
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.mobile.components.UIUseShared in project convertigo by convertigo.
the class MobileUIComponentTreeObject method handlesBeanNameChanged.
protected void handlesBeanNameChanged(TreeObjectEvent treeObjectEvent) {
DatabaseObjectTreeObject treeObject = (DatabaseObjectTreeObject) treeObjectEvent.getSource();
DatabaseObject databaseObject = (DatabaseObject) treeObject.getObject();
Object oldValue = treeObjectEvent.oldValue;
Object newValue = treeObjectEvent.newValue;
int update = treeObjectEvent.update;
if (update != TreeObjectEvent.UPDATE_NONE) {
// Case a UIStackVariable has been renamed
if (databaseObject instanceof UIStackVariable) {
UIStackVariable variable = (UIStackVariable) databaseObject;
UIActionStack stack = variable.getSharedAction();
if (stack != null) {
// rename variable for InvokeAction
if (getObject() instanceof UIDynamicInvoke) {
UIDynamicInvoke udi = (UIDynamicInvoke) getObject();
if (udi.getSharedActionQName().equals(stack.getQName())) {
boolean isLocalProject = variable.getProject().equals(udi.getProject());
boolean isSameValue = variable.getName().equals(oldValue);
boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
if (!isSameValue && shouldUpdate) {
Iterator<UIComponent> it = udi.getUIComponentList().iterator();
while (it.hasNext()) {
UIComponent component = (UIComponent) it.next();
if (component instanceof UIControlVariable) {
UIControlVariable uicv = (UIControlVariable) component;
if (uicv.getName().equals(oldValue)) {
try {
uicv.setName((String) newValue);
uicv.hasChanged = true;
hasBeenModified(true);
viewer.refresh();
markMainAsDirty(udi);
notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
break;
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for InvokeAction !");
}
}
}
}
}
}
}
}
}
// Case a UICompVariable has been renamed
if (databaseObject instanceof UICompVariable) {
UICompVariable variable = (UICompVariable) databaseObject;
UISharedComponent comp = variable.getSharedComponent();
if (comp != null) {
// rename variable for UseShared
if (getObject() instanceof UIUseShared) {
UIUseShared uus = (UIUseShared) getObject();
if (uus.getSharedComponentQName().equals(comp.getQName())) {
boolean isLocalProject = variable.getProject().equals(uus.getProject());
boolean isSameValue = variable.getName().equals(oldValue);
boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
if (!isSameValue && shouldUpdate) {
Iterator<UIComponent> it = uus.getUIComponentList().iterator();
while (it.hasNext()) {
UIComponent component = (UIComponent) it.next();
if (component instanceof UIControlVariable) {
UIControlVariable uicv = (UIControlVariable) component;
if (uicv.getName().equals(oldValue)) {
try {
uicv.setName((String) newValue);
uicv.hasChanged = true;
hasBeenModified(true);
viewer.refresh();
markMainAsDirty(uus);
notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
break;
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for UseShared !");
}
}
}
}
}
}
}
}
} else // Case a RequestableVariable has been renamed
if (databaseObject instanceof RequestableVariable) {
RequestableVariable variable = (RequestableVariable) databaseObject;
DatabaseObject parent = variable.getParent();
if (getObject() instanceof UIDynamicAction) {
UIDynamicAction uia = (UIDynamicAction) getObject();
IonBean ionBean = uia.getIonBean();
if (ionBean != null) {
// rename variable for CallSequenceAction
if (ionBean.getName().equals("CallSequenceAction")) {
Object p_val = ionBean.getProperty("requestable").getValue();
if (!p_val.equals(false)) {
if (parent.getQName().equals(p_val.toString())) {
boolean isLocalProject = variable.getProject().equals(uia.getProject());
boolean isSameValue = variable.getName().equals(oldValue);
boolean shouldUpdate = (update == TreeObjectEvent.UPDATE_ALL) || ((update == TreeObjectEvent.UPDATE_LOCAL) && (isLocalProject));
if (!isSameValue && shouldUpdate) {
Iterator<UIComponent> it = uia.getUIComponentList().iterator();
while (it.hasNext()) {
UIComponent component = (UIComponent) it.next();
if (component instanceof UIControlVariable) {
UIControlVariable uicv = (UIControlVariable) component;
if (uicv.getName().equals(oldValue)) {
try {
uicv.setName((String) newValue);
uicv.hasChanged = true;
hasBeenModified(true);
viewer.refresh();
markMainAsDirty(uia);
notifyDataseObjectPropertyChanged(uicv, "name", oldValue, newValue, new HashSet<Object>());
break;
} catch (EngineException e) {
ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' variable for CallSequenceAction !");
}
}
}
}
}
}
}
}
}
}
}
}
}
Aggregations