Search in sources :

Example 11 with IonBean

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();
    }
}
Also used : IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) EngineException(com.twinsoft.convertigo.engine.EngineException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) UIControlVariable(com.twinsoft.convertigo.beans.ngx.components.UIControlVariable) Cursor(org.eclipse.swt.graphics.Cursor) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) PageComponent(com.twinsoft.convertigo.beans.ngx.components.PageComponent) Shell(org.eclipse.swt.widgets.Shell) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) UICompVariable(com.twinsoft.convertigo.beans.ngx.components.UICompVariable) ProjectExplorerView(com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView) IScriptComponent(com.twinsoft.convertigo.beans.ngx.components.IScriptComponent) ApplicationComponent(com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) UIStackVariable(com.twinsoft.convertigo.beans.ngx.components.UIStackVariable) Sequence(com.twinsoft.convertigo.beans.core.Sequence) EngineException(com.twinsoft.convertigo.engine.EngineException) Project(com.twinsoft.convertigo.beans.core.Project) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) UIDynamicInvoke(com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject) DatabaseObjectTreeObject(com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject) Display(org.eclipse.swt.widgets.Display)

Example 12 with IonBean

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;
}
Also used : IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean)

Example 13 with IonBean

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;
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) JSONObject(org.codehaus.jettison.json.JSONObject)

Example 14 with IonBean

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);
}
Also used : UIAppGuard(com.twinsoft.convertigo.beans.ngx.components.UIAppGuard) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) MobileSmartSourceType(com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType) TreeViewer(org.eclipse.jface.viewers.TreeViewer) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIDynamicElement(com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TreeObjectEvent(com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeObjectEvent)

Example 15 with IonBean

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;
}
Also used : IonProperty(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty) NgxSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) PropertyDescriptor(org.eclipse.ui.views.properties.PropertyDescriptor) StringComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) Composite(org.eclipse.swt.widgets.Composite) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) CellEditor(org.eclipse.jface.viewers.CellEditor) AbstractDialogCellEditor(com.twinsoft.convertigo.eclipse.property_editors.AbstractDialogCellEditor) UIDynamicElement(com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement) NgxSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) Method(java.lang.reflect.Method) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) AbstractDialogCellEditor(com.twinsoft.convertigo.eclipse.property_editors.AbstractDialogCellEditor) StringComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor)

Aggregations

IonBean (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean)23 DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)9 EngineException (com.twinsoft.convertigo.engine.EngineException)9 IonProperty (com.twinsoft.convertigo.beans.ngx.components.dynamic.IonProperty)8 JSONObject (org.codehaus.jettison.json.JSONObject)8 JSONException (org.codehaus.jettison.json.JSONException)6 UIDynamicAction (com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction)4 HashMap (java.util.HashMap)4 UIActionStack (com.twinsoft.convertigo.beans.ngx.components.UIActionStack)3 UISharedComponent (com.twinsoft.convertigo.beans.ngx.components.UISharedComponent)3 UIUseShared (com.twinsoft.convertigo.beans.ngx.components.UIUseShared)3 File (java.io.File)3 Project (com.twinsoft.convertigo.beans.core.Project)2 ApplicationComponent (com.twinsoft.convertigo.beans.ngx.components.ApplicationComponent)2 MobileSmartSourceType (com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType)2 UICompVariable (com.twinsoft.convertigo.beans.ngx.components.UICompVariable)2 UIControlVariable (com.twinsoft.convertigo.beans.ngx.components.UIControlVariable)2 UIDynamicElement (com.twinsoft.convertigo.beans.ngx.components.UIDynamicElement)2 UIDynamicInvoke (com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke)2 UIStackVariable (com.twinsoft.convertigo.beans.ngx.components.UIStackVariable)2