Search in sources :

Example 36 with GraphicalViewer

use of org.eclipse.gef.GraphicalViewer in project yamcs-studio by yamcs.

the class ExecutePythonScriptAction method run.

@Override
public void run() {
    if (code == null) {
        try {
            ScriptStoreFactory.initPythonInterpreter();
        } catch (Exception e) {
            final String message = "Failed to initialize PythonInterpreter";
            OPIBuilderPlugin.getLogger().log(Level.WARNING, message, e);
            // $NON-NLS-1$
            ConsoleService.getInstance().writeError(message + "\n" + e);
        }
        // read file
        IPath absolutePath = getAbsolutePath();
        state = new PySystemState();
        // Add the path of script to python module search path
        if (!isEmbedded() && absolutePath != null && !absolutePath.isEmpty()) {
            // If it is a workspace file.
            if (ResourceUtil.isExistingWorkspaceFile(absolutePath)) {
                IPath folderPath = absolutePath.removeLastSegments(1);
                String sysLocation = ResourceUtil.workspacePathToSysPath(folderPath).toOSString();
                state.path.append(new PyString(sysLocation));
            } else if (ResourceUtil.isExistingLocalFile(absolutePath)) {
                IPath folderPath = absolutePath.removeLastSegments(1);
                state.path.append(new PyString(folderPath.toOSString()));
            }
        }
        interpreter = new PythonInterpreter(null, state);
        GraphicalViewer viewer = getWidgetModel().getRootDisplayModel().getViewer();
        if (viewer != null) {
            Object obj = viewer.getEditPartRegistry().get(getWidgetModel());
            if (obj != null && obj instanceof AbstractBaseEditPart) {
                displayEditpart = (DisplayEditpart) (viewer.getContents());
                widgetEditPart = (AbstractBaseEditPart) obj;
            }
        }
    }
    Job job = new Job("Execute Python Script") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            String taskName = isEmbedded() ? "Execute Python Script" : "Connecting to " + getAbsolutePath();
            monitor.beginTask(taskName, IProgressMonitor.UNKNOWN);
            runTask();
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
}
Also used : PySystemState(org.python.core.PySystemState) PyString(org.python.core.PyString) PythonInterpreter(org.python.util.PythonInterpreter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GraphicalViewer(org.eclipse.gef.GraphicalViewer) IPath(org.eclipse.core.runtime.IPath) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PyObject(org.python.core.PyObject) PyString(org.python.core.PyString) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

GraphicalViewer (org.eclipse.gef.GraphicalViewer)36 ArrayList (java.util.ArrayList)11 List (java.util.List)10 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)10 EditPart (org.eclipse.gef.EditPart)8 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)8 ProcessPart (org.talend.designer.core.ui.editor.process.ProcessPart)7 NodePart (org.talend.designer.core.ui.editor.nodes.NodePart)6 IGraphicalNode (org.talend.core.ui.process.IGraphicalNode)5 AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)4 ZoomManager (org.eclipse.gef.editparts.ZoomManager)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IProcess (org.talend.core.model.process.IProcess)4 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)4 NodeContainerPart (org.talend.designer.core.ui.editor.nodecontainer.NodeContainerPart)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 Process (org.talend.designer.core.ui.editor.process.Process)4 SubjobContainerPart (org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 PlatformObject (org.eclipse.core.runtime.PlatformObject)3