Search in sources :

Example 1 with AbstractRunnableAction

use of com.twinsoft.convertigo.engine.studio.AbstractRunnableAction in project convertigo by convertigo.

the class CallDblkAction method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    HttpSession session = request.getSession();
    CheStudio cheStudio = CallAction.getStudio(session);
    if (cheStudio == null || cheStudio.isActionDone()) {
        String qname = request.getParameter("qname");
        if (qname != null) {
            // Create sutdio
            cheStudio = new CheStudio(document);
            session.setAttribute(CallAction.PARAM_CHE_STUDIO, cheStudio);
            cheStudio.addSelectedObject(Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(qname));
            // Equivalent of com.twinsoft.convertigo.eclipse.views.projectexplorer.ProjectExplorerView#makeActions
            // Get the right action
            WrapDatabaseObject treeObject = (WrapDatabaseObject) cheStudio.getFirstSelectedTreeObject();
            AbstractRunnableAction runnableAction = null;
            if (treeObject.instanceOf(Connector.class)) {
                runnableAction = new LaunchConnectorEditorAction(cheStudio);
                session.setAttribute(CallAction.PARAM_LAST_ACTION, LaunchConnectorEditorAction.class.getName());
            } else if (treeObject.instanceOf(Sequence.class)) {
                runnableAction = new LaunchSequenceEditorAction(cheStudio);
                session.setAttribute(CallAction.PARAM_LAST_ACTION, LaunchSequenceEditorAction.class.getName());
            } else if (treeObject.instanceOf(Step.class)) {
                // showStepInPickerAction.run();
                if (treeObject instanceof IEditableTreeViewWrap) {
                    runnableAction = new LauncEditableEditorAction(cheStudio);
                    session.setAttribute(CallAction.PARAM_LAST_ACTION, LauncEditableEditorAction.class.getName());
                }
            } else if (treeObject instanceof IEditableTreeViewWrap) {
                runnableAction = new LauncEditableEditorAction(cheStudio);
                session.setAttribute(CallAction.PARAM_LAST_ACTION, LauncEditableEditorAction.class.getName());
            }
            // Execute action if found
            if (runnableAction != null) {
                synchronized (cheStudio) {
                    final AbstractRunnableAction localAction = runnableAction;
                    final CheStudio localCheStudio = cheStudio;
                    Engine.execute(() -> {
                        try {
                            localCheStudio.runAction(localAction);
                        } catch (Exception e) {
                            synchronized (localCheStudio) {
                                currentException = e;
                                localCheStudio.notify();
                            }
                        }
                    });
                    cheStudio.wait();
                }
            }
        }
    } else {
        if (CallAction.isCurrentAction(LaunchConnectorEditorAction.class, session)) {
            synchronized (cheStudio) {
                cheStudio.setDocument(document);
                cheStudio.notify();
                cheStudio.wait();
            }
        } else if (CallAction.isCurrentAction(LaunchSequenceEditorAction.class, session)) {
            synchronized (cheStudio) {
                cheStudio.setDocument(document);
                cheStudio.notify();
                cheStudio.wait();
            }
        }
    }
    if (currentException != null) {
        throw currentException;
    }
}
Also used : CheStudio(com.twinsoft.convertigo.engine.studio.CheStudio) LauncEditableEditorAction(com.twinsoft.convertigo.engine.studio.views.projectexplorer.actions.LauncEditableEditorAction) IEditableTreeViewWrap(com.twinsoft.convertigo.engine.studio.views.projectexplorer.model.IEditableTreeViewWrap) HttpSession(javax.servlet.http.HttpSession) WrapDatabaseObject(com.twinsoft.convertigo.engine.studio.views.projectexplorer.model.WrapDatabaseObject) LaunchConnectorEditorAction(com.twinsoft.convertigo.engine.studio.views.projectexplorer.actions.LaunchConnectorEditorAction) Sequence(com.twinsoft.convertigo.beans.core.Sequence) LaunchSequenceEditorAction(com.twinsoft.convertigo.engine.studio.views.projectexplorer.actions.LaunchSequenceEditorAction) AbstractRunnableAction(com.twinsoft.convertigo.engine.studio.AbstractRunnableAction)

Example 2 with AbstractRunnableAction

use of com.twinsoft.convertigo.engine.studio.AbstractRunnableAction in project convertigo by convertigo.

the class CallAction method getServiceResult.

@Override
protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    HttpSession session = request.getSession();
    CheStudio cheStudio = getStudio(session);
    if (cheStudio == null || cheStudio.isActionDone()) {
        String[] qnames = request.getParameterValues("qnames[]");
        String action = request.getParameter("action");
        if (qnames != null && action != null) {
            cheStudio = new CheStudio(document);
            session.setAttribute(PARAM_CHE_STUDIO, cheStudio);
            // Remove duplicates
            Set<String> uniqueQnames = new HashSet<>(Arrays.asList(qnames));
            // Get all dbos from the qnames
            Iterator<String> uniqueQnamesIt = uniqueQnames.iterator();
            while (uniqueQnamesIt.hasNext()) {
                String uniqueQname = (String) uniqueQnamesIt.next();
                // Add the dbo
                cheStudio.addSelectedObject(Engine.theApp.databaseObjectsManager.getDatabaseObjectByQName(uniqueQname));
            }
            String actionClassName = action.replace("com.twinsoft.convertigo.eclipse.popup.actions", "com.twinsoft.convertigo.engine.studio.popup.actions");
            session.setAttribute(PARAM_LAST_ACTION, actionClassName);
            try {
                Constructor<?> c = Class.forName(actionClassName).getConstructor(WrapStudio.class);
                synchronized (cheStudio) {
                    // Create a new instance of the action then run it
                    AbstractRunnableAction runnableAction = (AbstractRunnableAction) c.newInstance(cheStudio);
                    final CheStudio localCheStudio = cheStudio;
                    Engine.execute(() -> {
                        try {
                            localCheStudio.runAction(runnableAction);
                        } catch (Exception e) {
                            synchronized (localCheStudio) {
                                currentException = e;
                                localCheStudio.notify();
                            }
                        }
                    });
                    cheStudio.wait();
                }
            } catch (ClassNotFoundException e) {
                // We don't forget to delete it from the session to start a new action the next time
                session.removeAttribute(PARAM_CHE_STUDIO);
                session.removeAttribute(PARAM_LAST_ACTION);
                // Action not defined
                String actionName = actionClassName.substring(actionClassName.lastIndexOf(".") + 1, actionClassName.length());
                throw new Exception("The action " + actionName + " is not defined yet.");
            }
        }
    } else {
        if (isCurrentAction(DatabaseObjectDeleteAction.class, session)) {
            synchronized (cheStudio) {
                // Setting the new Document is important, else it will keep the old reference of the document
                cheStudio.setDocument(document);
                String response = request.getParameter("response");
                if (response != null) {
                    int intResponse = Integer.parseInt(response);
                    cheStudio.setResponse(intResponse);
                }
                cheStudio.wait();
            }
        } else {
            synchronized (cheStudio) {
                cheStudio.setDocument(document);
                cheStudio.notify();
                cheStudio.wait();
            }
        }
    }
    if (currentException != null) {
        throw currentException;
    }
}
Also used : CheStudio(com.twinsoft.convertigo.engine.studio.CheStudio) HttpSession(javax.servlet.http.HttpSession) AbstractRunnableAction(com.twinsoft.convertigo.engine.studio.AbstractRunnableAction) HashSet(java.util.HashSet)

Aggregations

AbstractRunnableAction (com.twinsoft.convertigo.engine.studio.AbstractRunnableAction)2 CheStudio (com.twinsoft.convertigo.engine.studio.CheStudio)2 HttpSession (javax.servlet.http.HttpSession)2 Sequence (com.twinsoft.convertigo.beans.core.Sequence)1 LauncEditableEditorAction (com.twinsoft.convertigo.engine.studio.views.projectexplorer.actions.LauncEditableEditorAction)1 LaunchConnectorEditorAction (com.twinsoft.convertigo.engine.studio.views.projectexplorer.actions.LaunchConnectorEditorAction)1 LaunchSequenceEditorAction (com.twinsoft.convertigo.engine.studio.views.projectexplorer.actions.LaunchSequenceEditorAction)1 IEditableTreeViewWrap (com.twinsoft.convertigo.engine.studio.views.projectexplorer.model.IEditableTreeViewWrap)1 WrapDatabaseObject (com.twinsoft.convertigo.engine.studio.views.projectexplorer.model.WrapDatabaseObject)1 HashSet (java.util.HashSet)1