use of com.twinsoft.convertigo.beans.mobile.components.UICompVariable in project convertigo by convertigo.
the class SharedComponentWizard method createCompVariable.
private UICompVariable createCompVariable(String varName, String varValue) throws Exception {
UICompVariable compVariable = new UICompVariable();
compVariable.setName(varName);
compVariable.setVariableValue(varValue);
compVariable.hasChanged = true;
compVariable.bNew = true;
return compVariable;
}
use of com.twinsoft.convertigo.beans.mobile.components.UICompVariable in project convertigo by convertigo.
the class SharedComponentWizard method scanForVariables.
private void scanForVariables(final UIComponent origin) throws Exception {
final Set<String> identifierSet = new HashSet<String>();
try {
new WalkHelper() {
private void addDeclaration(String var_name, String var_value) {
if (var_name != null && !var_name.isEmpty() && !main_map.containsKey(var_name)) {
main_map.put(var_name, var_value == null ? "''" : var_value);
}
}
private void getMainDeclarations() {
try {
List<String> declarations = new ArrayList<String>();
String c8o_Declarations = "", markerId = "";
if (isInPage(origin)) {
markerId = "PageDeclaration";
String c8o_UserCustoms = origin.getPage().getScriptContent().getString();
c8o_Declarations = Ionic3Builder.getMarker(c8o_UserCustoms, markerId);
} else if (isInSharedComponent(origin)) {
markerId = "SharedCompDeclaration";
UISharedComponent uisc = origin.getSharedComponent();
for (UICompVariable var : uisc.getVariables()) {
c8o_Declarations += "let " + var.getVariableName() + " = " + var.getVariableValue() + ";" + System.lineSeparator();
}
} else if (isInApplication(origin)) {
markerId = "AppDeclaration";
String c8o_UserCustoms = origin.getApplication().getComponentScriptContent().getString();
c8o_Declarations = Ionic3Builder.getMarker(c8o_UserCustoms, markerId);
}
if (!c8o_Declarations.isEmpty()) {
for (String line : Arrays.asList(c8o_Declarations.split(System.lineSeparator()))) {
line = line.trim();
if (!line.isEmpty() && line.indexOf(markerId) == -1) {
declarations.add(line);
}
}
}
for (String line : declarations) {
// "(((\\w+)\\s(\\w+)([^\\=]+))(\\=([^\\=]+))?)"
Matcher matcher = d_var.matcher(line);
while (matcher.find()) {
String var_name = matcher.group(4);
String var_value = matcher.group(7);
if (var_value != null) {
var_value = var_value.trim();
if (var_value.charAt(var_value.length() - 1) == ';') {
var_value = var_value.substring(0, var_value.length() - 1);
}
var_value = escapeString(var_value);
}
addDeclaration(var_name, var_value);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
private boolean isInForDirective(UIComponent uic) {
return getForDirective(uic) != null;
}
private UIControlDirective getForDirective(UIComponent uic) {
DatabaseObject databaseObject = uic;
while (databaseObject != null && (!(databaseObject instanceof UIControlDirective) || !AttrDirective.ForEach.name().equals(((UIControlDirective) databaseObject).getDirectiveName()))) {
databaseObject = databaseObject.getParent();
}
if (databaseObject == null)
return null;
else
return (UIControlDirective) databaseObject;
}
private void getForDirectiveVariables(UIComponent uic) {
UIComponent uicomponent = uic;
while (isInForDirective(uicomponent)) {
UIControlDirective uicd = getForDirective(uicomponent);
if (!uic.equals(uicd)) {
String item = "item" + uicd.priority;
addDeclaration(item, "[]");
addMapVariable(item, item, "this._params_." + item);
addMapVariable(item, uicd.toString() + " : found variable which stands for the iterator's item");
String itemName = uicd.getDirectiveItemName();
addDeclaration(itemName, "{}");
addMapVariable(itemName, itemName, "this._params_." + itemName);
addMapVariable(itemName, uicd.toString() + " : found variable which stands for the customized iterator's item");
String indexName = uicd.getDirectiveIndexName();
addDeclaration(indexName, "0");
addMapVariable(indexName, indexName, "this._params_." + indexName);
addMapVariable(indexName, uicd.toString() + " : found variable which stands for the customized iterator's index");
String expression = uicd.getDirectiveExpression();
if (!expression.isEmpty()) {
Matcher matcher = null;
List<String> list = Arrays.asList(expression.split("\\;"));
for (String s : list) {
matcher = d_var_let.matcher(s);
while (matcher.find()) {
String expvar = matcher.group(3);
addDeclaration(expvar, "''");
addMapVariable(expvar, expvar, "this._params_." + expvar);
addMapVariable(expvar, uicd.toString() + " : found variable used by the customized iterator's expression");
}
matcher = d_var_as.matcher(s);
while (matcher.find()) {
String expvar = matcher.group(4);
addDeclaration(expvar, "''");
addMapVariable(expvar, expvar, "this._params_." + expvar);
addMapVariable(expvar, uicd.toString() + " : found variable used by the customized iterator's expression");
}
}
}
}
DatabaseObject dbo = uicd.getParent();
uicomponent = dbo instanceof UIComponent ? (UIComponent) dbo : null;
}
}
private boolean checkVariable(String name) {
if (name == null || name.isEmpty())
return false;
if (identifierSet.contains(name)) {
return false;
}
if ("global".equals(name))
return false;
if ("router".equals(name))
return false;
return true;
}
private void addMapVariable(String name, String target, String replacement) {
if (checkVariable(name)) {
String normalized_name = StringUtils.normalize(name);
String var_name = normalized_name;
if (ovarMap.containsKey(var_name)) {
// System.out.println("var_name: "+ var_name + " already in ovarMap");
} else {
ovarMap.put(var_name, new HashMap<String, String>());
}
ovarMap.get(var_name).put(target, replacement.replace("_params_." + name, "_params_.") + var_name);
}
}
private void addMapVariable(String name, String infos) {
if (checkVariable(name)) {
String normalized_name = StringUtils.normalize(name);
String var_name = normalized_name;
if (infoMap.containsKey(var_name)) {
// System.out.println("var_name: "+ var_name + " already in infoMap");
} else {
infoMap.put(var_name, infos);
}
}
}
private void scanSmartSource(UIComponent uic, String p_name, MobileSmartSourceType msst) throws Exception {
boolean extended = !forTemplate(uic);
String s = null;
if (Mode.SCRIPT.equals(msst.getMode())) {
s = msst.getValue(extended);
}
if (Mode.SOURCE.equals(msst.getMode())) {
s = msst.getSmartSource().toJsonString();
}
if (s != null) {
String infos = uic.toString() + " : found variable used by '" + p_name + "' property";
Matcher matcher = p_var.matcher(s);
while (matcher.find()) {
String group1 = matcher.group(1);
String group2 = matcher.group(2);
// String group3 = matcher.group(3);
String group4 = matcher.group(4);
String name = group4;
String target = group1;
String replacement = group2 + "._params_." + name;
if (isInControlEvent(uic)) {
if (forTemplate(uic)) {
replacement = "_params_." + name;
} else {
replacement = "scope._params_." + name;
}
}
addMapVariable(name, target, replacement);
addMapVariable(name, infos);
}
}
}
@Override
public void init(DatabaseObject databaseObject) throws Exception {
getMainDeclarations();
if (isInForDirective(origin)) {
getForDirectiveVariables(origin);
}
super.init(databaseObject);
}
@Override
protected void walk(DatabaseObject databaseObject) throws Exception {
if (databaseObject instanceof UIComponent) {
UIComponent uic = (UIComponent) databaseObject;
if (uic.isEnabled() && !isInControlEvent(uic)) {
if (databaseObject instanceof UIDynamicElement) {
String identifier = ((UIDynamicElement) databaseObject).getIdentifier();
if (!identifier.isEmpty()) {
identifierSet.add(identifier);
}
}
for (java.beans.PropertyDescriptor pd : CachedIntrospector.getBeanInfo(databaseObject).getPropertyDescriptors()) {
if (pd.getPropertyEditorClass() != null) {
if (pd.getPropertyEditorClass().getSimpleName().equals("MobileSmartSourcePropertyDescriptor")) {
Method getter = pd.getReadMethod();
Object value = getter.invoke(databaseObject, new Object[] {});
if (value != null && value instanceof MobileSmartSourceType) {
MobileSmartSourceType msst = (MobileSmartSourceType) value;
if (Mode.SCRIPT.equals(msst.getMode()) || Mode.SOURCE.equals(msst.getMode())) {
scanSmartSource(uic, pd.getName(), msst);
}
}
}
}
}
if (databaseObject instanceof UIDynamicElement) {
UIDynamicElement uide = (UIDynamicElement) databaseObject;
IonBean ionBean = uide.getIonBean();
if (ionBean != null) {
for (IonProperty property : ionBean.getProperties().values()) {
Object p_value = property.getValue();
if (!p_value.equals(false)) {
MobileSmartSourceType msst = property.getSmartType();
if (Mode.SCRIPT.equals(msst.getMode()) || Mode.SOURCE.equals(msst.getMode())) {
scanSmartSource(uide, property.getName(), msst);
}
}
}
}
}
super.walk(databaseObject);
}
}
}
}.init(origin);
} catch (Exception e) {
throw new Exception("Unable to scan for variables", e);
}
}
use of com.twinsoft.convertigo.beans.mobile.components.UICompVariable 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.UICompVariable 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