Search in sources :

Example 46 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.

the class GenericTextEditor method openDialogBox.

@Override
protected Object openDialogBox(Control cellEditorWindow) {
    if (dialogCompositeClass != TextEditorComposite.class) {
        return super.openDialogBox(cellEditorWindow);
    }
    try {
        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        if (activePage == null) {
            return null;
        }
        String propertyName = (String) propertyDescriptor.getId();
        java.beans.PropertyDescriptor[] propertyDescriptors = databaseObjectTreeObject.databaseObjectBeanInfo.getPropertyDescriptors();
        java.beans.PropertyDescriptor propertyDescriptor = null;
        for (java.beans.PropertyDescriptor pd : propertyDescriptors) {
            if (propertyName.equals(pd.getName())) {
                propertyDescriptor = pd;
                break;
            }
        }
        String extension = (propertyDescriptor != null && propertyDescriptor.getValue(MySimpleBeanInfo.GENERIC_EDITOR_EXTENSION) != null) ? propertyDescriptor.getValue(MySimpleBeanInfo.GENERIC_EDITOR_EXTENSION).toString() : "txt";
        DatabaseObject dbo = databaseObjectTreeObject.getObject();
        IFile file = databaseObjectTreeObject.getProjectTreeObject().getFile("_private/editor/" + dbo.getShortQName() + "/" + propertyName + "." + extension);
        SwtUtils.fillFile(file, getValue().toString());
        FileInPlaceEditorInput input = new FileInPlaceEditorInput(file);
        IEditorPart editor = activePage.openEditor(input, "org.eclipse.ui.genericeditor.GenericEditor");
        editor.addPropertyListener((Object source, int propId) -> {
            if (propId == IEditorPart.PROP_DIRTY && !((IEditorPart) source).isDirty()) {
                try (InputStream is = file.getContents()) {
                    setNewValue(IOUtils.toString(is, "UTF-8"));
                } catch (Exception e) {
                    Engine.logStudio.error("Failed to save " + file.getName(), e);
                }
            }
        });
    } catch (PartInitException e) {
        Engine.logStudio.error("failed to open editor", e);
    }
    return null;
}
Also used : FileInPlaceEditorInput(org.eclipse.ui.part.FileInPlaceEditorInput) IFile(org.eclipse.core.resources.IFile) InputStream(java.io.InputStream) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PartInitException(org.eclipse.ui.PartInitException)

Example 47 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.

the class NgxUIComponentTreeObject 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 !");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else // 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 UIUseVariable) {
                                    UIUseVariable uicv = (UIUseVariable) 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 UICompEvent has been renamed
        if (databaseObject instanceof UICompEvent) {
            UICompEvent event = (UICompEvent) databaseObject;
            UISharedComponent comp = event.getSharedComponent();
            if (comp != null) {
                // rename control event for UseShared
                if (getObject() instanceof UIUseShared) {
                    UIUseShared uus = (UIUseShared) getObject();
                    if (uus.getSharedComponentQName().equals(comp.getQName())) {
                        boolean isLocalProject = event.getProject().equals(uus.getProject());
                        boolean isSameValue = event.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 UIControlEvent) {
                                    UIControlEvent uice = (UIControlEvent) component;
                                    if (uice.getEventName().equals(oldValue)) {
                                        try {
                                            uice.setEventName((String) newValue);
                                            uice.hasChanged = true;
                                            hasBeenModified(true);
                                            viewer.refresh();
                                            markMainAsDirty(uus);
                                            notifyDataseObjectPropertyChanged(uice, "eventName", oldValue, newValue, new HashSet<Object>());
                                            break;
                                        } catch (EngineException e) {
                                            ConvertigoPlugin.logException(e, "Unable to refactor the references of '" + newValue + "' event 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 !");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : UICompEvent(com.twinsoft.convertigo.beans.ngx.components.UICompEvent) IonBean(com.twinsoft.convertigo.beans.ngx.components.dynamic.IonBean) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) EngineException(com.twinsoft.convertigo.engine.EngineException) UIControlVariable(com.twinsoft.convertigo.beans.ngx.components.UIControlVariable) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) UIControlEvent(com.twinsoft.convertigo.beans.ngx.components.UIControlEvent) Iterator(java.util.Iterator) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UIUseVariable(com.twinsoft.convertigo.beans.ngx.components.UIUseVariable) HashSet(java.util.HashSet) UICompVariable(com.twinsoft.convertigo.beans.ngx.components.UICompVariable) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) UIStackVariable(com.twinsoft.convertigo.beans.ngx.components.UIStackVariable) RequestableVariable(com.twinsoft.convertigo.beans.variables.RequestableVariable) UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UIDynamicAction(com.twinsoft.convertigo.beans.ngx.components.UIDynamicAction) UIDynamicInvoke(com.twinsoft.convertigo.beans.ngx.components.UIDynamicInvoke) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 48 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.

the class NgxUIComponentTreeObject method treeObjectPropertyChanged.

@Override
public void treeObjectPropertyChanged(TreeObjectEvent treeObjectEvent) {
    super.treeObjectPropertyChanged(treeObjectEvent);
    TreeObject treeObject = (TreeObject) treeObjectEvent.getSource();
    Set<Object> done = checkDone(treeObjectEvent);
    String propertyName = (String) treeObjectEvent.propertyName;
    propertyName = ((propertyName == null) ? "" : propertyName);
    Object oldValue = treeObjectEvent.oldValue;
    Object newValue = treeObjectEvent.newValue;
    refactorSmartSources(treeObjectEvent);
    if (treeObject instanceof DatabaseObjectTreeObject) {
        DatabaseObjectTreeObject doto = (DatabaseObjectTreeObject) treeObject;
        DatabaseObject dbo = doto.getObject();
        try {
            if (this.equals(treeObject)) {
                if (propertyName.equals("scriptContent")) {
                    if (!newValue.equals(oldValue)) {
                        markMainTsAsDirty();
                        markMainAsDirty(getObject(), done);
                    }
                } else {
                    if (propertyName.equals("sharedcomponent")) {
                        if (!newValue.equals(oldValue)) {
                            if (!((String) newValue).isBlank()) {
                                ComponentRefManager.get(Mode.use).addConsumer((String) newValue, dbo.getQName());
                            }
                        }
                    }
                    markMainAsDirty(getObject(), done);
                }
                UIActionStack uisa = ((UIComponent) dbo).getSharedAction();
                UISharedComponent uisc = ((UIComponent) dbo).getSharedComponent();
                if (uisa != null && !uisa.equals(getObject())) {
                    notifyDataseObjectPropertyChanged(uisa, "", null, null, done);
                }
                if (uisc != null && !uisc.equals(getObject())) {
                    notifyDataseObjectPropertyChanged(uisc, "", null, null, done);
                }
            } else {
                if (propertyName.equals("name")) {
                    handlesBeanNameChanged(treeObjectEvent);
                }
                if (dbo instanceof UIActionStack) {
                    handleSharedActionChanged((UIActionStack) dbo, done);
                } else if (dbo instanceof UISharedComponent) {
                    if (getObject() instanceof UIUseShared) {
                        UIUseShared uiUse = (UIUseShared) getObject();
                        String useQName = uiUse.getQName();
                        String compQName = dbo.getQName();
                        if (ComponentRefManager.get(Mode.use).getAllConsumers(compQName).contains(useQName)) {
                            ((NgxBuilder) uiUse.getProject().getMobileBuilder()).updateConsumer();
                        }
                    }
                    handleSharedComponentChanged((UISharedComponent) dbo, done);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : UIActionStack(com.twinsoft.convertigo.beans.ngx.components.UIActionStack) UIUseShared(com.twinsoft.convertigo.beans.ngx.components.UIUseShared) UIComponent(com.twinsoft.convertigo.beans.ngx.components.UIComponent) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) UISharedComponent(com.twinsoft.convertigo.beans.ngx.components.UISharedComponent) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 49 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.

the class MobileUIComponentTreeObject method unformatStyleContent.

private String unformatStyleContent(UIStyle ms, String s) {
    String unformated = s;
    DatabaseObject parentDbo = ms.getParent();
    if (parentDbo != null && parentDbo instanceof UIElement) {
        try {
            unformated = unformated.replaceFirst("^\\.class\\d+\\s?\\{\\r?\\n?", "");
            unformated = unformated.substring(0, unformated.lastIndexOf("}"));
        } catch (Exception e) {
            unformated = s;
            e.printStackTrace();
        }
    }
    ;
    return unformated;
}
Also used : UIElement(com.twinsoft.convertigo.beans.mobile.components.UIElement) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) CoreException(org.eclipse.core.runtime.CoreException) EngineException(com.twinsoft.convertigo.engine.EngineException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 50 with DatabaseObject

use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.

the class MobileUIComponentTreeObject 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 MobileSmartSourcePropertyDescriptor(id, displayName, tags, !isEditable);
                        ((MobileSmartSourcePropertyDescriptor) 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 = MobileUIComponentTreeObject.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.mobile.components.dynamic.IonProperty) PropertyDescriptor(org.eclipse.ui.views.properties.PropertyDescriptor) StringComboBoxPropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) TextPropertyDescriptor(org.eclipse.ui.views.properties.TextPropertyDescriptor) MobileSmartSourcePropertyDescriptor(com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) Composite(org.eclipse.swt.widgets.Composite) IonBean(com.twinsoft.convertigo.beans.mobile.components.dynamic.IonBean) CellEditor(org.eclipse.jface.viewers.CellEditor) AbstractDialogCellEditor(com.twinsoft.convertigo.eclipse.property_editors.AbstractDialogCellEditor) UIDynamicElement(com.twinsoft.convertigo.beans.mobile.components.UIDynamicElement) 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

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)296 TreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.TreeObject)98 DatabaseObjectTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.DatabaseObjectTreeObject)97 EngineException (com.twinsoft.convertigo.engine.EngineException)88 Shell (org.eclipse.swt.widgets.Shell)46 ProjectExplorerView (com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView)45 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)43 Cursor (org.eclipse.swt.graphics.Cursor)42 Display (org.eclipse.swt.widgets.Display)42 Sequence (com.twinsoft.convertigo.beans.core.Sequence)41 Project (com.twinsoft.convertigo.beans.core.Project)38 CoreException (org.eclipse.core.runtime.CoreException)36 IOException (java.io.IOException)35 Step (com.twinsoft.convertigo.beans.core.Step)33 ActionModel (com.twinsoft.convertigo.engine.studio.ActionModel)33 TreeParent (com.twinsoft.convertigo.eclipse.views.projectexplorer.TreeParent)31 Element (org.w3c.dom.Element)30 ObjectsFolderTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject)27 StepTreeObject (com.twinsoft.convertigo.eclipse.views.projectexplorer.model.StepTreeObject)27 PartInitException (org.eclipse.ui.PartInitException)26