Search in sources :

Example 76 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.

the class JSONFileSchema2TreeLinker method createLinks.

public void createLinks() {
    removeAllLinks();
    getBackgroundRefresher().refreshBackground();
    ProgressDialog progressDialog = new ProgressDialog(getSource().getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) {
            TreeItem root = jsonViewer.getTree().getItem(0);
            // if (getManager().getFoxComponent().istFileOutputMSXML()) {
            // List<FOXTreeNode> treeData = getManager().getTreeData(getManager().getCurrentSchema());
            // if (treeData != null && treeData.size() > 0) {
            // FOXTreeNode rootTreeData = treeData.get(0);
            // for (TreeItem item : xmlViewer.getTree().getItems()) {
            // if (rootTreeData == item.getData()) {
            // root = item;
            // break;
            // }
            // }
            // }
            // }
            List<TreeItem> allItems = TreeUtils.collectAllItems(root);
            monitorWrap = new EventLoopProgressMonitor(monitor);
            String taskName = "Loop links creation ...";
            int totalWork = allItems.size();
            //$NON-NLS-1$
            monitorWrap.beginTask(taskName, totalWork);
            for (int i = 0; i < totalWork; i++) {
                if (monitorWrap.isCanceled()) {
                    return;
                }
                TreeItem treeItem = allItems.get(i);
                FOXTreeNode node = (FOXTreeNode) treeItem.getData();
                if (node.getColumn() == null) {
                    //$NON-NLS-1$
                    continue;
                }
                createLoopLinks(node.getColumn().getLabel(), treeItem, monitorWrap, i == totalWork - 1);
                monitorWrap.worked(1);
            }
            monitorWrap.done();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeItem(org.eclipse.swt.widgets.TreeItem) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 77 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method updateRunJobContext.

protected void updateRunJobContext() {
    final JobContextManager manager = (JobContextManager) getProcess().getContextManager();
    if (manager.isModified()) {
        final Map<String, String> nameMap = manager.getNameMap();
        // gcui:add a progressDialog.
        Shell shell = null;
        Display display = PlatformUI.getWorkbench().getDisplay();
        if (display != null) {
            shell = display.getActiveShell();
        }
        if (shell == null) {
            display = Display.getCurrent();
            if (display == null) {
                display = Display.getDefault();
            }
            if (display != null) {
                shell = display.getActiveShell();
            }
        }
        ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
        IRunnableWithProgress runnable = new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) {
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("AbstractMultiPageTalendEditor_pleaseWait"), IProgressMonitor.UNKNOWN);
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
                        factory.executeRepositoryWorkUnit(new //$NON-NLS-1$
                        RepositoryWorkUnit<Object>(//$NON-NLS-1$
                        "..", //$NON-NLS-1$
                        this) {

                            @Override
                            protected void run() throws LoginException, PersistenceException {
                                try {
                                    IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
                                    Set<String> curContextVars = getCurrentContextVariables(manager);
                                    IProcess2 process2 = getProcess();
                                    String jobId = process2.getProperty().getId();
                                    IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
                                    List<IProcess2> processes = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
                                    // gcui:if nameMap is empty it do nothing.
                                    if (!nameMap.isEmpty()) {
                                        UpdateRunJobComponentContextHelper.updateItemRunJobComponentReference(factory, nameMap, jobId, curContextVars);
                                        UpdateRunJobComponentContextHelper.updateOpenedJobRunJobComponentReference(processes, nameMap, jobId, curContextVars);
                                    }
                                    // add for bug 9564
                                    List<IRepositoryViewObject> all = factory.getAll(ERepositoryObjectType.PROCESS, true);
                                    List<ProcessItem> allProcess = new ArrayList<ProcessItem>();
                                    for (IRepositoryViewObject repositoryObject : all) {
                                        Item item = repositoryObject.getProperty().getItem();
                                        if (item instanceof ProcessItem) {
                                            ProcessItem processItem = (ProcessItem) item;
                                            allProcess.add(processItem);
                                        }
                                    }
                                    UpdateRunJobComponentContextHelper.updateRefJobRunJobComponentContext(factory, allProcess, process2);
                                } catch (PersistenceException e) {
                                    // e.printStackTrace();
                                    ExceptionHandler.process(e);
                                }
                                manager.setModified(false);
                            }
                        });
                    }
                });
                monitor.done();
                if (monitor.isCanceled()) {
                    try {
                        //$NON-NLS-1$
                        throw new InterruptedException("Save Fail");
                    } catch (InterruptedException e) {
                        ExceptionHandler.process(e);
                    }
                }
            }
        };
        try {
            progressDialog.run(true, true, runnable);
        } catch (InvocationTargetException e1) {
            ExceptionHandler.process(e1);
        } catch (InterruptedException e1) {
            ExceptionHandler.process(e1);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) Shell(org.eclipse.swt.widgets.Shell) IEditorReference(org.eclipse.ui.IEditorReference) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) JobContextManager(org.talend.core.model.context.JobContextManager) Display(org.eclipse.swt.widgets.Display)

Example 78 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method generateCode.

/**
     * DOC bqian Comment method "generateCode".
     */
protected void generateCode() {
    final IProcess2 process = getProcess();
    if (!(process.getProperty().getItem() instanceof ProcessItem)) {
        // shouldn't work for joblet
        return;
    }
    if (process.getGeneratingNodes().size() != 0) {
        Job job = new //$NON-NLS-1$
        AccessingEmfJob(//$NON-NLS-1$
        "Generating code") {

            @Override
            protected IStatus doRun(IProgressMonitor monitor) {
                try {
                    ProcessorUtilities.generateCode(process, process.getContextManager().getDefaultContext(), false, false, true, ProcessorUtilities.GENERATE_WITH_FIRST_CHILD);
                } catch (ProcessorException e) {
                    ExceptionHandler.process(e);
                }
                return Status.OK_STATUS;
            }
        };
        job.setUser(true);
        job.setPriority(Job.BUILD);
        // start as soon as possible
        job.schedule();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProcessorException(org.talend.designer.runprocess.ProcessorException) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) AccessingEmfJob(org.talend.core.model.utils.AccessingEmfJob) IProcess2(org.talend.core.model.process.IProcess2) AccessingEmfJob(org.talend.core.model.utils.AccessingEmfJob) Job(org.eclipse.core.runtime.jobs.Job)

Example 79 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.

the class NewProcessWizard method performFinish.

/**
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
@Override
public boolean performFinish() {
    RepositoryWorkUnit<Object> workUnit = new RepositoryWorkUnit<Object>(this.getWindowTitle(), this) {

        @Override
        protected void run() throws LoginException, PersistenceException {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IWorkspaceRunnable operation = new IWorkspaceRunnable() {

                @Override
                public void run(IProgressMonitor monitor) throws CoreException {
                    createProcessItem();
                }
            };
            try {
                workspace.run(operation, null);
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    };
    workUnit.setAvoidUnloadResources(true);
    repositoryFactory.executeRepositoryWorkUnit(workUnit);
    return processItem != null;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit)

Example 80 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.

the class JavaProcessor method initCodePath.

public void initCodePath(IContext c) throws ProcessorException {
    if (buildChildrenJobs != null) {
        buildChildrenJobs.clear();
    }
    ITalendProcessJavaProject tProcessJavaProject = getTalendJavaProject();
    IProgressMonitor monitor = new NullProgressMonitor();
    IFolder srcFolder = null;
    IFolder resourcesFolder = null;
    IFolder outputFolder = null;
    if (isTestJob) {
        srcFolder = tProcessJavaProject.getTestSrcFolder();
        resourcesFolder = tProcessJavaProject.getTestResourcesFolder();
        outputFolder = tProcessJavaProject.getTestOutputFolder();
    } else {
        srcFolder = tProcessJavaProject.getSrcFolder();
        resourcesFolder = tProcessJavaProject.getResourcesFolder();
        outputFolder = tProcessJavaProject.getOutputFolder();
    }
    /*
         * assume the job is "TestJob 0.1", project is "Test" .
         */
    String jobClassPackageFolder = null;
    String jobClassFilePath = null;
    // only for "standard" job
    if (isStandardJob()) {
        Item item = property.getItem();
        // test/testjob_0_1
        jobClassPackageFolder = JavaResourcesHelper.getJobClassPackageFolder(item, isTestJob);
        // test/testjob_0_1/TestJob.java
        jobClassFilePath = JavaResourcesHelper.getJobClassFilePath(item, filenameFromLabel, isTestJob);
        // test.testjob_0_1.TestJob
        this.mainClass = JavaResourcesHelper.getJobPackagedClass(item, filenameFromLabel, isTestJob);
    } else {
        // for shadow process, or preview process
        // test/shadowfileinputtodelimitedoutput_0_1, test/preview_data
        jobClassPackageFolder = JavaResourcesHelper.getProjectFolderName(property) + JavaUtils.PATH_SEPARATOR + JavaResourcesHelper.getJobFolderName(process.getName(), process.getVersion());
        // test/shadowfileinputtodelimitedoutput_0_1/ShadowFileInputToDelimitedOutput.java,
        // test/preview_data/Preview_Data.java
        jobClassFilePath = jobClassPackageFolder + JavaUtils.PATH_SEPARATOR + (filenameFromLabel ? JavaResourcesHelper.escapeFileName(process.getName()) : process.getId()) + JavaUtils.JAVA_EXTENSION;
        // test.shadowfileinputtodelimitedoutput_0_1.ShadowFileInputToDelimitedOutput,
        // test.preview_data.Preview_Data
        this.mainClass = new Path(jobClassFilePath).removeFileExtension().toString().replace('/', '.');
    }
    // create job packages, src/main/java/test/testjob_0_1
    // or test job packages, src/main/java/test/testjob_0_1/testjunitjob_0_1
    tProcessJavaProject.createSubFolder(monitor, srcFolder, jobClassPackageFolder);
    // src/main/java/test/testjob_0_1/TestJob.java
    // or src/main/java/test/testjob_0_1/testjunitjob_0_1/TestjunitJob.java
    this.codePath = srcFolder.getProjectRelativePath().append(jobClassFilePath);
    // target/classes/test/testjob_0_1
    // or target/test-classes/test/testjob_0_1/testjunitjob_0_1
    IFolder jobClassFolder = outputFolder.getFolder(jobClassPackageFolder);
    // TestJob
    String jobName = new Path(jobClassFilePath).removeFileExtension().lastSegment();
    // target/classes/test/testjob_0_1/TestJob
    // or target/test-classes/test/testjob_0_1/testjunitjob_0_1/TestjunitJob
    this.compiledCodePath = jobClassFolder.getProjectRelativePath().append(jobName);
    if (isTestJob) {
        // test/testjob_0_1/datas
        IPath dataPath = new Path(jobClassPackageFolder).append(JavaUtils.JAVA_DATAS_DIRECTORY);
        this.dataFilePath = resourcesFolder.getFolder(dataPath).getProjectRelativePath();
    }
    /*
         * for context.
         */
    // test/testjob_0_1/contexts
    // or test/testjob_0_1/testjunitjob_0_1/contexts
    IPath jobContextFolderPath = new Path(jobClassPackageFolder).append(JavaUtils.JAVA_CONTEXTS_DIRECTORY);
    // src/main/resources/test/testjob_0_1/contexts
    // or src/test/resources/test/testjob_0_1/testjunitjob_0_1/contexts
    tProcessJavaProject.createSubFolder(monitor, resourcesFolder, jobContextFolderPath.toString());
    // for example, Default
    String contextFileName = JavaResourcesHelper.getJobContextFileName(c);
    // test/testjob_0_1/contexts/Default.properties
    // or test/testjob_0_1/testjunitjob_0_1/contexts/Default.properties
    IPath jobContextPath = jobContextFolderPath.append(contextFileName);
    // src/main/resources/test/testjob_0_1/contexts/Default.properties
    // or src/test/resources/test/testjob_0_1/testjunitjob_0_1/contexts/Default.properties
    this.contextPath = resourcesFolder.getFile(jobContextPath).getProjectRelativePath();
    // target/classes/test/testjob_0_1/contexts/Default.properties
    // or target/test-classes/test/testjob_0_1/testjunitjob_0_1/contexts/Default.properties
    this.compiledContextPath = outputFolder.getFile(jobContextPath).getProjectRelativePath();
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)530 InvocationTargetException (java.lang.reflect.InvocationTargetException)181 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)162 CoreException (org.eclipse.core.runtime.CoreException)134 Job (org.eclipse.core.runtime.jobs.Job)133 IStatus (org.eclipse.core.runtime.IStatus)110 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)83 Status (org.eclipse.core.runtime.Status)81 ArrayList (java.util.ArrayList)80 IOException (java.io.IOException)69 IFile (org.eclipse.core.resources.IFile)60 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)58 File (java.io.File)56 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)54 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)50 ITask (com.cubrid.common.core.task.ITask)49 IProject (org.eclipse.core.resources.IProject)43 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)37 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)37 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)37