Search in sources :

Example 36 with DatabaseObject

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

the class Get method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    // Load the plugin.xml where the representation of the context menu is described
    getPluginDocument();
    String[] qnames = request.getParameterValues("qnames[]");
    String[] folderTypes = request.getParameterValues("folderTypes[]");
    String refQnameFolder = request.getParameter("refQnameFolder");
    // Create the response : success or fail
    Element eResponse = document.createElement("response");
    Element eRoot = document.getDocumentElement();
    eRoot.appendChild(eResponse);
    // Select (folder + database object) or (multiple folders) = no menu generated
    if (folderTypes != null && (qnames != null || folderTypes.length > 1)) {
        // It is not really an error but it's ok
        noEntryMessage(eResponse);
        return;
    }
    Element eContextMenu = null;
    // Generate the menu for database objects
    if (qnames != null) {
        List<Node> menus = new ArrayList<>(qnames.length);
        for (String qname : qnames) {
            // Create menu for the dbo
            DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
            if (dbo != null) {
                Element menu = createDboMenu(dbo, document);
                menus.add(menu);
            } else {
                eResponse.setAttribute("state", "error");
                eResponse.setAttribute("message", "One of the qname is invalid.");
                return;
            }
        }
        // Generate the new menu with all generated menus
        eContextMenu = generateFilteredMenu(document, menus);
    } else // Generate the menu for folders
    if (folderTypes != null && !refQnameFolder.isEmpty()) {
        DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(refQnameFolder);
        // Generate the menu if we found the related dbo
        boolean generateMenu = dbo != null;
        // In case of Screen Class, if the Criteria folder is selected
        if (generateMenu && dbo instanceof ScreenClass && "Criteria".equals(folderTypes[0])) {
            ScreenClass sc = (ScreenClass) dbo;
            // Generate the menu "New->Criteria" if it is not the default Screen Class
            generateMenu = sc.getDepth() != 0;
        }
        if (generateMenu) {
            eContextMenu = document.createElement("menu");
            String folderTypeValue = folderNameToTypeValue.get(folderTypes[0]);
            if (folderTypeValue != null) {
                // Get the object contribution related to the folder
                Element eObjectContribution = (Element) xpathApi.selectNode(pluginDocument, "/plugin/extension[@point='org.eclipse.ui.popupMenus']/objectContribution[@objectClass='com.twinsoft.convertigo.eclipse.views.projectexplorer.model.ObjectsFolderTreeObject']");
                // Search the action of the folder
                List<Node> nActions = xpathApi.selectList(eObjectContribution, "/*");
                boolean foundAction = false;
                for (int i = 0; !foundAction && i < nActions.size(); ++i) {
                    Element eAction = (Element) nActions.get(i);
                    /*
						 *  If we have the right action, we add it to the menu and stop looping.
						 *  In the Studio, we display other actions as disabled but here we only
						 *  display the specific action. In face we can only have one action
						 *  so it is useless to display the others.
						 */
                    if (foundAction = evaluateFolderCondition(folderTypeValue, eAction)) {
                        String menubarPath = eAction.getAttribute("menubarPath");
                        // Create the action
                        Element eNewAction = createElementActionBaseAttr(document, eAction.getAttribute("id"), eAction.getAttribute("label"), eAction.getAttribute("class"), true, menubarPath);
                        // Create the sub menu
                        int index = menubarPath.indexOf("/");
                        createSubMenu(menubarPath, index, document, eContextMenu, eNewAction, eObjectContribution.getAttribute("id"));
                    }
                }
            }
        }
    }
    // Create response
    if (eContextMenu != null && eContextMenu.hasChildNodes()) {
        eResponse.setAttribute("state", "success");
        eResponse.setAttribute("message", "Context menu has been generated.");
        eRoot.appendChild(eContextMenu);
    } else {
        noEntryMessage(eResponse);
    }
}
Also used : ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) List(java.util.List) ArrayList(java.util.ArrayList)

Example 37 with DatabaseObject

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

the class CanCreateDbo method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String qname = request.getParameter("qname");
    String folderType = request.getParameter("folderType");
    String beanClassNameToCreate = request.getParameter("beanClass");
    DatabaseObject parentDbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
    Class<? extends DatabaseObject> beanClassToCreate = GenericUtils.cast(Class.forName(beanClassNameToCreate));
    Class<? extends DatabaseObject> databaseObjectClass = Get.folderNameToBeanClass.get(folderType);
    // Create response
    boolean canCreate = DatabaseObjectsManager.acceptDatabaseObjects(parentDbo, beanClassToCreate, databaseObjectClass);
    Element response = document.createElement("response");
    response.setAttribute("state", Boolean.toString(canCreate));
    document.getDocumentElement().appendChild(response);
}
Also used : Element(org.w3c.dom.Element) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 38 with DatabaseObject

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

the class Get method createCategories.

private void createCategories(Document document, DatabaseObject dbo, Class<? extends DatabaseObject> databaseObjectClass, Element root) throws Exception {
    Element response = document.createElement("response");
    try {
        List<String> defaultDboList = new ArrayList<>();
        Class<? extends DatabaseObject> parentObjectClass = dbo.getClass();
        Map<String, DboCategoryData> categoryNameToDboCategory = new HashMap<>();
        DboExplorerManager manager = Engine.theApp.getDboExplorerManager();
        for (DboGroup group : manager.getGroups()) {
            for (DboCategory category : group.getCategories()) {
                for (DboBeans beansCategory : category.getBeans()) {
                    for (DboBean bean : beansCategory.getBeans()) {
                        // Skip if bean is disabled
                        if (!bean.isEnable()) {
                            continue;
                        }
                        String className = bean.getClassName();
                        try {
                            Class<DatabaseObject> beanClass = GenericUtils.cast(Class.forName(className));
                            DboCategoryInfo dboCategoryInfo = DatabaseObject.getDboGroupInfo(beanClass);
                            if (dboCategoryInfo == null) {
                                continue;
                            }
                            // If one of these cases, do not add the category
                            if (dbo instanceof ScreenClass) {
                                ScreenClass sc = (ScreenClass) dbo;
                                // Do not show Criteria category if it is the default Screen Class
                                if (sc.getDepth() == 0 && dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Criteria.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof CicsConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof JavelinConnector) {
                                // Do not show ScreenClass category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof SqlConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof HtmlConnector) {
                                // Do not show Pool and ScreenClass categories
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class)) || dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof HttpConnector) {
                                // Do not show Pool category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof SiteClipperConnector) {
                                // Do not show Pool and ScreenClass categories
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Pool.class)) || dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(ScreenClass.class))) {
                                    continue;
                                }
                            } else if (dbo instanceof Transaction) {
                                // Do not show Statement category
                                if (dboCategoryInfo.equals(DatabaseObject.getDboGroupInfo(Statement.class))) {
                                    continue;
                                }
                            }
                            if (bean.isDefault()) {
                                defaultDboList.add(className);
                            }
                            // The bean should derived from
                            // DatabaseObject...
                            boolean isDatabaseObject = (DatabaseObject.class.isAssignableFrom(beanClass));
                            if (isDatabaseObject) {
                                // ... and should derived from the specified class
                                boolean isFromSpecifiedClass = (databaseObjectClass == null || (databaseObjectClass != null && databaseObjectClass.isAssignableFrom(beanClass)));
                                if (isFromSpecifiedClass) {
                                    // Check parent
                                    boolean bFound = DatabaseObjectsManager.checkParent(parentObjectClass, bean);
                                    if (bFound) {
                                        String technology = DboUtils.getTechnology(dbo, beanClass);
                                        // Check technology if needed
                                        if (technology != null) {
                                            Collection<String> acceptedTechnologies = bean.getEmulatorTechnologies();
                                            if (!acceptedTechnologies.isEmpty() && !acceptedTechnologies.contains(technology)) {
                                                continue;
                                            }
                                        }
                                        String beanInfoClassName = className + "BeanInfo";
                                        Class<BeanInfo> beanInfoClass = GenericUtils.cast(Class.forName(beanInfoClassName));
                                        if (beanInfoClass != null) {
                                            String categoryName = dboCategoryInfo.getCategoryName();
                                            // Create category
                                            DboCategoryData dboCategoryData = categoryNameToDboCategory.get(categoryName);
                                            if (dboCategoryData == null) {
                                                dboCategoryData = new DboCategoryData(dboCategoryInfo.getCategoryId(), categoryName, dboCategoryInfo.getIconClassCSS());
                                                categoryNameToDboCategory.put(categoryName, dboCategoryData);
                                            }
                                            // Beans name
                                            String beansName = beansCategory.getName();
                                            if (beansName.length() == 0) {
                                                beansName = categoryName;
                                            }
                                            // Create beans
                                            DboBeansData dboBeansData = dboCategoryData.getDboBeans(beansName);
                                            if (dboBeansData == null) {
                                                dboBeansData = new DboBeansData(beansName);
                                                dboCategoryData.addDboBeans(beansName, dboBeansData);
                                            }
                                            // Create bean
                                            DboBeanData dboBeanData = new DboBeanData(beanInfoClass.getConstructor().newInstance());
                                            dboBeansData.addDboBean(dboBeanData);
                                        } else {
                                            String message = java.text.MessageFormat.format("The \"{0}\" does not exist.", new Object[] { beanInfoClassName });
                                            throw new Exception(message);
                                        }
                                    }
                                }
                            } else {
                                String message = java.text.MessageFormat.format("The \"{0}\" class is not a Convertigo database object.", new Object[] { className });
                                throw new Exception(message);
                            }
                        } catch (ClassNotFoundException e) {
                            String message = java.text.MessageFormat.format("Unable to analyze the \"{0}\" class.\n\nClass not found: {1}", new Object[] { className, e.getMessage() });
                            throw new Exception(message);
                        } catch (Throwable e) {
                            String message = java.text.MessageFormat.format("Unable to analyze the \"{0}\" Convertigo database object.", new Object[] { className });
                            throw new Exception(message);
                        }
                    }
                }
            }
        }
        // Find the default selected bean for each categories
        for (DboCategoryData dboCategory : categoryNameToDboCategory.values()) {
            boolean defaultDboFound = false;
            List<DboBeanData> dboBeansList = dboCategory.getAllDboBean(true);
            // By default, we chose the first bean as default selected bean
            DboBeanData defaultSelectedBean = dboBeansList.get(0);
            // Find the default selected bean
            for (int i = 0; i < dboBeansList.size() && !defaultDboFound; ++i) {
                Class<DatabaseObject> beanClass = dboBeansList.get(i).getBeanClass();
                // Another bean is set as default selected bean
                if (defaultDboFound = defaultDboList.contains(beanClass.getName())) {
                    defaultSelectedBean = dboBeansList.get(i);
                }
            }
            defaultSelectedBean.setSelectedByDefault(true);
        }
        // XmlLize
        for (DboCategoryData dboCategory : categoryNameToDboCategory.values()) {
            response.appendChild(dboCategory.toXml(document));
        }
    } catch (Exception e) {
        throw new Exception("Unable to load database objects properties.");
    }
    root.appendChild(response);
}
Also used : HttpConnector(com.twinsoft.convertigo.beans.connectors.HttpConnector) HashMap(java.util.HashMap) ScreenClass(com.twinsoft.convertigo.beans.core.ScreenClass) Element(org.w3c.dom.Element) BeanInfo(java.beans.BeanInfo) ArrayList(java.util.ArrayList) DboCategory(com.twinsoft.convertigo.engine.dbo_explorer.DboCategory) DboBeansData(com.twinsoft.convertigo.beans.dbo_explorer.DboBeansData) DboBeanData(com.twinsoft.convertigo.beans.dbo_explorer.DboBeanData) SqlConnector(com.twinsoft.convertigo.beans.connectors.SqlConnector) DboCategoryInfo(com.twinsoft.convertigo.beans.core.DatabaseObject.DboCategoryInfo) SiteClipperConnector(com.twinsoft.convertigo.beans.connectors.SiteClipperConnector) DboCategoryData(com.twinsoft.convertigo.beans.dbo_explorer.DboCategoryData) DboGroup(com.twinsoft.convertigo.engine.dbo_explorer.DboGroup) DboExplorerManager(com.twinsoft.convertigo.engine.dbo_explorer.DboExplorerManager) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DboBeans(com.twinsoft.convertigo.engine.dbo_explorer.DboBeans) HtmlConnector(com.twinsoft.convertigo.beans.connectors.HtmlConnector) JavelinConnector(com.twinsoft.convertigo.beans.connectors.JavelinConnector) Transaction(com.twinsoft.convertigo.beans.core.Transaction) CicsConnector(com.twinsoft.convertigo.beans.connectors.CicsConnector) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DboBean(com.twinsoft.convertigo.engine.dbo_explorer.DboBean)

Example 39 with DatabaseObject

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

the class Get method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String qname = request.getParameter("qname");
    String folderType = request.getParameter("folderType");
    DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
    Class<? extends DatabaseObject> databaseObjectClass = folderNameToBeanClass.get(folderType);
    createCategories(document, dbo, databaseObjectClass, document.getDocumentElement());
}
Also used : DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

Example 40 with DatabaseObject

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

the class Save method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    String qname = request.getParameter("qname");
    DatabaseObject dbo = Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname);
    Element response = document.createElement("response");
    if (dbo != null) {
        try {
            Engine.theApp.databaseObjectsManager.exportProject(dbo.getProject());
            response.setAttribute("status", "success");
            response.setAttribute("message", "Successfully saved project.");
        } catch (EngineException e) {
            throw e;
        }
    } else {
        throw new EngineException("The project does not exist.");
    }
    document.getDocumentElement().appendChild(response);
}
Also used : Element(org.w3c.dom.Element) EngineException(com.twinsoft.convertigo.engine.EngineException) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject)

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