use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean 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 + "\".");
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.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class UIDynamicElement method getEventNames.
protected String[] getEventNames() {
IonBean ionBean = getIonBean();
String[] eventNames = new String[0];
if (ionBean != null) {
eventNames = ionBean.getEvents().keySet().toArray(new String[0]);
Arrays.sort(eventNames);
}
return eventNames;
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class UIDynamicElement method initAttrClasses.
@Override
protected StringBuilder initAttrClasses() {
StringBuilder attrclasses = super.initAttrClasses();
IonBean ionBean = getIonBean();
if (ionBean != null) {
for (IonProperty property : ionBean.getProperties().values()) {
// String name = property.getName();
String attr = property.getAttr();
Object value = property.getValue();
// case value is set
if (!value.equals(false)) {
String smartValue = property.getSmartValue();
if (attr.equals("class")) {
attrclasses.append(attrclasses.length() > 0 ? " " : "").append(smartValue);
}
}
}
}
return attrclasses;
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class NgxUIComponentTreeObject method setPropertyValue.
@Override
public void setPropertyValue(Object id, Object value) {
DatabaseObject dbo = getObject();
if (dbo instanceof UIDynamicElement) {
IonBean ionBean = ((UIDynamicElement) dbo).getIonBean();
if (ionBean != null) {
if (ionBean.hasProperty((String) id)) {
if (value != null) {
if (value instanceof String) {
value = new MobileSmartSourceType((String) value);
}
Object oldValue = ionBean.getPropertyValue((String) id);
if (!value.equals(oldValue)) {
ionBean.setPropertyValue((String) id, value);
TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
hasBeenModified(true);
viewer.update(this, null);
TreeObjectEvent treeObjectEvent = new TreeObjectEvent(this, (String) id, oldValue, value);
ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent);
return;
}
}
}
}
}
if (dbo instanceof UIAppGuard) {
UIAppGuard dboGuard = (UIAppGuard) dbo;
if ("guardType".equals(id)) {
String guardType = (String) value;
if (!guardType.equals(dboGuard.getGuardType().name())) {
if (dboGuard.getApplication().hasGuard(AppGuardType.valueOf(guardType))) {
return;
}
}
}
}
super.setPropertyValue(id, value);
}
use of com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean in project convertigo by convertigo.
the class NgxUIComponentTreeObject method getDynamicPropertyDescriptors.
@Override
protected List<PropertyDescriptor> getDynamicPropertyDescriptors() {
List<PropertyDescriptor> l = super.getDynamicPropertyDescriptors();
DatabaseObject dbo = getObject();
if (dbo instanceof UIDynamicElement) {
IonBean ionBean = ((UIDynamicElement) dbo).getIonBean();
if (ionBean != null) {
for (IonProperty property : ionBean.getProperties().values()) {
String id = property.getName();
String displayName = property.getLabel();
String editor = property.getEditor();
Object[] values = property.getValues();
int len = values.length;
if (property.isHidden()) {
continue;
}
PropertyDescriptor propertyDescriptor = null;
if (editor.isEmpty()) {
if (len == 0) {
propertyDescriptor = new TextPropertyDescriptor(id, displayName);
} else if (len == 1) {
propertyDescriptor = new PropertyDescriptor(id, displayName);
} else {
boolean isEditable = values[len - 1].equals(true);
int size = isEditable ? len - 1 : len;
String[] tags = new String[size];
for (int i = 0; i < size; i++) {
Object value = values[i];
tags[i] = value.equals(false) ? "not set" : value.toString();
}
// propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, !isEditable);
propertyDescriptor = new NgxSmartSourcePropertyDescriptor(id, displayName, tags, !isEditable);
((NgxSmartSourcePropertyDescriptor) propertyDescriptor).databaseObjectTreeObject = this;
}
} else {
if (editor.equals("StringComboBoxPropertyDescriptor")) {
try {
Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
Method getTags = c.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
String[] tags = (String[]) getTags.invoke(null, new Object[] { this, id });
propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, true);
} catch (Exception e) {
e.printStackTrace();
}
} else {
propertyDescriptor = new PropertyDescriptor(id, displayName) {
@Override
public CellEditor createPropertyEditor(Composite parent) {
CellEditor cellEditor = null;
try {
Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
cellEditor = (CellEditor) c.getConstructor(Composite.class).newInstance(parent);
if (cellEditor instanceof AbstractDialogCellEditor) {
((AbstractDialogCellEditor) cellEditor).databaseObjectTreeObject = NgxUIComponentTreeObject.this;
((AbstractDialogCellEditor) cellEditor).propertyDescriptor = this;
}
} catch (Exception e) {
e.printStackTrace();
}
return cellEditor;
}
};
}
}
propertyDescriptor.setCategory(property.getCategory());
propertyDescriptor.setDescription(cleanDescription(property.getDescription()));
propertyDescriptor.setValidator(getValidator(id));
l.add(propertyDescriptor);
}
}
}
return l;
}
Aggregations