use of com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction in project convertigo by convertigo.
the class MobilePickerContentProvider method addGlobals.
private void addGlobals(TVObject tvi, Object object) {
if (object != null) {
Map<String, UIDynamicAction> globals = null;
if (object instanceof ApplicationComponent) {
globals = new HashMap<>();
getGlobalActions(object, globals);
}
if (globals != null) {
try {
JSONObject jsonFSSA = new JSONObject().put("FullSyncSyncAction", new JSONObject().put("progress", new JSONObject().put("changed", "").put("continuous", "").put("finished", "").put("pull", "").put("current", "").put("total", "").put("status", "").put("taskInfo", "").put("raw", "")));
JSONObject jsonInfos = new JSONObject();
for (String key : globals.keySet()) {
if ("FullSyncSyncAction".equals(key)) {
jsonInfos.put(key, jsonFSSA.get(key));
} else {
jsonInfos.put(key, "");
}
}
SourceData sd = null;
try {
sd = Filter.Global.toSourceData(new JSONObject());
} catch (Exception e) {
e.printStackTrace();
}
tvi.add(new TVObject("sharedObject", object, sd, jsonInfos));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
use of com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction in project convertigo by convertigo.
the class MobilePickerComposite method lookupModelData.
private Map<String, Object> lookupModelData(TVObject tvObject) {
Map<String, Object> data = new HashMap<String, Object>();
Map<String, String> params = new HashMap<String, String>();
DatabaseObject dbo = null;
String searchPath = "";
Object object = tvObject.getObject();
JSONObject infos = tvObject.getInfos();
if (object != null) {
try {
if (object instanceof RequestableObject) {
dbo = (RequestableObject) object;
searchPath = "";
} else if (object instanceof DesignDocument) {
dbo = (DesignDocument) object;
DesignDocument dd = (DesignDocument) dbo;
params.put("ddoc", dd.getName());
params.put("view", tvObject.getParent().getName());
params.put("include_docs", infos.has("include_docs") ? infos.getString("include_docs") : "false");
searchPath = tvObject.getName().startsWith("get") ? ".rows.value" : "";
} else if (object instanceof UIControlDirective) {
dbo = (UIControlDirective) object;
do {
UIControlDirective directive = (UIControlDirective) dbo;
String rootDboName = "";
if (directive.getPage() != null) {
rootDboName = directive.getPage().getName();
} else if (directive.getMenu() != null) {
rootDboName = directive.getMenu().getName();
}
MobileSmartSourceType msst = directive.getSourceSmartType();
MobileSmartSource mss = msst.getSmartSource();
if (mss != null) {
dbo = mss.getDatabaseObject(rootDboName);
params.putAll(mss.getParameters());
searchPath = mss.getModelPath().replaceAll("\\?\\.", ".") + searchPath;
} else {
dbo = null;
}
} while (dbo != null && dbo instanceof UIControlDirective);
} else if (object instanceof UIForm) {
dbo = (UIForm) object;
searchPath = "";
} else if (object instanceof ApplicationComponent) {
dbo = (ApplicationComponent) object;
params.put("json", infos.toString());
searchPath = "";
} else if (object instanceof UIActionStack) {
dbo = (UIActionStack) object;
searchPath = "";
} else if (object instanceof IAction) {
if (object instanceof UIDynamicAction) {
dbo = (UIDynamicAction) object;
searchPath = "";
} else if (object instanceof UICustomAction) {
dbo = (UICustomAction) object;
searchPath = "";
}
} else if (object instanceof UISharedComponent) {
dbo = (UISharedComponent) object;
searchPath = "";
}
} catch (Exception e) {
e.printStackTrace();
}
}
data.put("databaseObject", dbo);
data.put("params", params);
data.put("searchPath", searchPath);
return data;
}
use of com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction 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.UIDynamicAction in project convertigo by convertigo.
the class MobileSharedComponentExtractAction method isAllowed.
private boolean isAllowed(TreeObject treeObject) {
if (treeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
if (doto.isEnabled() && !doto.hasAncestorDisabled()) {
DatabaseObject dbo = doto.getObject();
if (dbo instanceof UIElement) {
UIElement uie = (UIElement) dbo;
boolean isUIDynamicAction = uie instanceof UIDynamicAction;
boolean isInForm = uie.getUIForm() != null && !uie.equals(uie.getUIForm());
if (!isUIDynamicAction && !isInForm) {
return true;
}
}
}
}
return false;
}
use of com.twinsoft.convertigo.beans.mobile.components.UIDynamicAction 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