use of com.twinsoft.convertigo.beans.ngx.components.UISharedComponent in project convertigo by convertigo.
the class NgxUIComponentTreeObject method treeObjectRemoved.
@Override
public void treeObjectRemoved(TreeObjectEvent treeObjectEvent) {
super.treeObjectRemoved(treeObjectEvent);
TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
Set<Object> done = checkDone(treeObjectEvent);
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject deletedTreeObject = (DatabaseObjectTreeObject) treeObject;
DatabaseObject deletedObject = deletedTreeObject.getObject();
try {
if (deletedTreeObject != null && this.equals(deletedTreeObject.getParentDatabaseObjectTreeObject())) {
UIComponent parentDbo = getObject();
if (deletedObject instanceof UIUseShared) {
UIUseShared use = (UIUseShared) deletedObject;
String compQName = use.getSharedComponentQName();
String useQNname = parentDbo.getQName() + "." + deletedObject.getName();
ComponentRefManager.get(Mode.use).removeConsumer(compQName, useQNname);
}
UIActionStack uisa = parentDbo.getSharedAction();
UISharedComponent uisc = parentDbo.getSharedComponent();
if (uisa != null) {
notifyDataseObjectPropertyChanged(uisa, "", null, null, done);
} else if (uisc != null) {
notifyDataseObjectPropertyChanged(uisc, "", null, null, done);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.twinsoft.convertigo.beans.ngx.components.UISharedComponent 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.UISharedComponent 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();
}
}
use of com.twinsoft.convertigo.beans.ngx.components.UISharedComponent in project convertigo by convertigo.
the class NgxComponentImportVariablesAction 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 + "\".");
UIUseVariable uiVariable = new UIUseVariable();
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.ngx.components.UISharedComponent in project convertigo by convertigo.
the class ApplicationComponentEditor method highlightPoint.
private void highlightPoint(int x, int y) {
x = c8oBrowser.fixDPI(x);
y = c8oBrowser.fixDPI(y);
Node node = browser.mainFrame().get().inspect(x, y).node().orElse(null);
while (!(node == null || node instanceof Element)) {
node = node.parent().orElse(null);
}
if (node == null) {
return;
}
Object shadowHost = c8oBrowser.executeFunctionAndReturnValue("_c8o_getShadowHost", node);
if (shadowHost != null && shadowHost instanceof Element) {
node = (Element) shadowHost;
}
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 UISharedComponent) {
UISharedComponent uisc = (UISharedComponent) databaseObject;
if (uisc != null) {
databaseObject = uisc;
}
} else 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();
if (databaseObject instanceof MobileComponent && !databaseObject.equals(exHighlightMobileComponent)) {
if (dragStartMobileComponent != null) {
DatabaseObject ancestor = databaseObject;
while (dragStartMobileComponent != ancestor && ancestor != null) {
ancestor = ancestor.getParent();
}
if (dragStartMobileComponent == ancestor) {
return;
}
}
c8oBrowser.getDisplay().asyncExec(() -> ConvertigoPlugin.getDefault().getProjectExplorerView().objectSelected(new CompositeEvent(databaseObject)));
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);
}
}
}
}
Aggregations