Search in sources :

Example 16 with Job

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

the class ExchangeLoginTask method run.

/* (non-Javadoc)
     * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
     */
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    if (!PluginChecker.isExchangeSystemLoaded() || TalendPropertiesUtil.isHideExchange()) {
        return;
    }
    Job job = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    "Check Exchange") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // check for Talendforge
            IPreferenceStore prefStore = PlatformUI.getPreferenceStore();
            boolean checkTisVersion = prefStore.getBoolean(ITalendCorePrefConstants.EXCHANGE_CHECK_TIS_VERSION);
            IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
            if (!checkTisVersion && brandingService.isPoweredbyTalend()) {
                int count = prefStore.getInt(TalendForgeDialog.LOGINCOUNT);
                if (count < 0) {
                    count = 1;
                }
                ExchangeUser exchangeUser = ProjectManager.getInstance().getCurrentProject().getExchangeUser();
                //$NON-NLS-1$
                boolean isExchangeLogon = exchangeUser.getLogin() != null && !exchangeUser.getLogin().equals("");
                boolean isUserPassRight = true;
                if (isExchangeLogon) {
                    IExchangeService service = (IExchangeService) GlobalServiceRegister.getDefault().getService(IExchangeService.class);
                    if (service.checkUserAndPass(exchangeUser.getUsername(), exchangeUser.getPassword()) != null) {
                        isUserPassRight = false;
                    }
                }
                if (!isExchangeLogon || !isUserPassRight) {
                    if ((count + 1) % 4 == 0) {
                        // if (Platform.getOS().equals(Platform.OS_LINUX)) {
                        // TalendForgeDialog tfDialog = new TalendForgeDialog(this.getShell(), project);
                        // tfDialog.open();
                        // } else {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                Project project = ProjectManager.getInstance().getCurrentProject();
                                String userEmail = null;
                                if (project.getAuthor() != null) {
                                    userEmail = project.getAuthor().getLogin();
                                }
                                TalendForgeDialog tfDialog = new TalendForgeDialog(DisplayUtils.getDefaultShell(), userEmail);
                                tfDialog.setBlockOnOpen(true);
                                tfDialog.open();
                            }
                        });
                    }
                    prefStore.setValue(TalendForgeDialog.LOGINCOUNT, count + 1);
                }
            }
            return org.eclipse.core.runtime.Status.OK_STATUS;
        }
    };
    job.setSystem(true);
    job.setUser(false);
    job.setPriority(Job.INTERACTIVE);
    // start as soon as possible
    job.schedule();
}
Also used : IBrandingService(org.talend.core.ui.branding.IBrandingService) ExchangeUser(org.talend.core.model.properties.ExchangeUser) Project(org.talend.core.model.general.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IExchangeService(org.talend.core.service.IExchangeService) Job(org.eclipse.core.runtime.jobs.Job) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) TalendForgeDialog(org.talend.registration.wizards.register.TalendForgeDialog)

Example 17 with Job

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

the class TalendEditorPaletteFactory method getRelatedComponentNamesFromHelp.

protected static Set<String> getRelatedComponentNamesFromHelp(final String keyword) {
    if (keyword == null || keyword.isEmpty()) {
        return null;
    }
    // This method will cost lots of time to complete when it is called the first time
    final List<SearchHit> querySearchResult = new ArrayList<SearchHit>();
    if (searchInHelpJob != null && searchInHelpJob.getState() != Job.NONE) {
        searchInHelpJob.cancel();
    }
    searchInHelpJob = new Job(SEARCHING_FROM_HELP) {

        @SuppressWarnings("restriction")
        @Override
        protected IStatus run(IProgressMonitor monitor) {
            String helpKeyword = keyword;
            try {
                TalendPaletteSearchIndex searchIndex = TalendPaletteSearchIndex.getInstance();
                LocalSearchManager localSearchManager = BaseHelpSystem.getLocalSearchManager();
                // if not work or null, maybe should throw a warn to inform user and help us trace
                // if (searchIndex != null && localSearchManager != null) {
                localSearchManager.ensureIndexUpdated(monitor, searchIndex);
                //$NON-NLS-1$
                final String WHITESPACE = " ";
                //$NON-NLS-1$//$NON-NLS-2$
                helpKeyword = helpKeyword + WHITESPACE + "OR" + WHITESPACE + helpKeyword + "*";
                ISearchQuery searchQuery = new SearchQuery(helpKeyword, false, new ArrayList<String>(), Platform.getNL());
                searchIndex.search(searchQuery, new ISearchHitCollector() {

                    @Override
                    public void addQTCException(QueryTooComplexException exception) throws QueryTooComplexException {
                    // nothing need to do
                    }

                    @Override
                    public void addHits(List<SearchHit> hits, String wordsSearched) {
                        querySearchResult.addAll(hits);
                    }
                });
            // }
            } catch (Throwable e) {
                CommonExceptionHandler.process(e, Priority.WARN);
            }
            return Status.OK_STATUS;
        }

        @Override
        public boolean belongsTo(Object family) {
            return family.equals(FederatedSearchJob.FAMILY);
        }
    };
    try {
        searchInHelpJob.setPriority(Job.INTERACTIVE);
        searchInHelpJob.schedule();
        searchInHelpJob.join();
    } catch (Throwable e) {
        CommonExceptionHandler.process(e, Priority.WARN);
    }
    Set<String> componentNames = new LinkedHashSet<String>();
    // the limitation has been moved to it's caller
    // int limit = PaletteSettingsPreferencePage.getPaletteSearchResultLimitFromHelp();
    // int i = 1;
    Iterator<SearchHit> iter = querySearchResult.iterator();
    while (iter.hasNext()) {
        // if (limit < i) {
        // break;
        // }
        SearchHit result = iter.next();
        String label = result.getLabel();
        if (label == null || label.trim().length() == 0) {
            continue;
        }
        componentNames.add(label);
    // i++;
    }
    return componentNames;
}
Also used : ISearchQuery(org.eclipse.help.internal.search.ISearchQuery) SearchQuery(org.eclipse.help.internal.search.SearchQuery) LinkedHashSet(java.util.LinkedHashSet) IStatus(org.eclipse.core.runtime.IStatus) SearchHit(org.eclipse.help.internal.search.SearchHit) ArrayList(java.util.ArrayList) LocalSearchManager(org.eclipse.help.internal.search.LocalSearchManager) ISearchHitCollector(org.eclipse.help.internal.search.ISearchHitCollector) QueryTooComplexException(org.eclipse.help.internal.search.QueryTooComplexException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) FederatedSearchJob(org.eclipse.help.internal.search.federated.FederatedSearchJob) Job(org.eclipse.core.runtime.jobs.Job) ISearchQuery(org.eclipse.help.internal.search.ISearchQuery)

Example 18 with Job

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

the class LoginProjectPage method fetchLicense.

private Job fetchLicense(Project proj) {
    String url = getAdminURL();
    String userId = loginHelper.getCurrentSelectedConnBean().getUser();
    String key = loginHelper.getLicenseMapKey(url, proj.getLabel(), userId);
    String license = null;
    try {
        license = loginHelper.getLicense(key);
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    Job fetchJob = null;
    if (license == null || license.isEmpty()) {
        fetchJob = fetchLicenseJobMap.get(proj);
        boolean createJob = true;
        if (fetchJob != null) {
            if (fetchJob.getResult() == null) {
                // just wait finish, click refresh may clear all running jobs
                createJob = false;
            } else {
                createJob = true;
            }
        }
        if (createJob) {
            fetchJob = createFetchLicenseJob(proj);
            fetchJob.setUser(false);
            fetchJob.schedule();
        }
    }
    return fetchJob;
}
Also used : PersistenceException(org.talend.commons.exception.PersistenceException) Job(org.eclipse.core.runtime.jobs.Job)

Example 19 with Job

use of org.eclipse.core.runtime.jobs.Job 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 20 with Job

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

the class ConfigureCpuProfilerAction method run.

/*
     * @see Action#run()
     */
@Override
public void run() {
    // get the profiled packages
    final Job getProfiledPackagesJob = new Job(Messages.getProfiledPackagesJobLabel) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            IActiveJvm jvm = cpuSection.getJvm();
            if (jvm == null) {
                return Status.CANCEL_STATUS;
            }
            try {
                packages = jvm.getCpuProfiler().getProfiledPackages();
            } catch (JvmCoreException e) {
                Activator.log(Messages.getProfiledPackagesFailedMsg, e);
            }
            return Status.OK_STATUS;
        }
    };
    getProfiledPackagesJob.schedule();
    // open CPU profiler configuration dialog
    Job openDialogJob = new Job(Messages.openDialogJobLabel) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            try {
                getProfiledPackagesJob.join();
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        openDialog();
                    }
                });
            } catch (InterruptedException e) {
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    openDialogJob.schedule();
}
Also used : IActiveJvm(org.talend.designer.runtime.visualization.IActiveJvm) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Aggregations

Job (org.eclipse.core.runtime.jobs.Job)82 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)57 IStatus (org.eclipse.core.runtime.IStatus)20 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)17 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)17 JobFamily (com.cubrid.common.ui.spi.progress.JobFamily)14 IOException (java.io.IOException)14 Status (org.eclipse.core.runtime.Status)12 File (java.io.File)11 CoreException (org.eclipse.core.runtime.CoreException)8 ArrayList (java.util.ArrayList)7 IFile (org.eclipse.core.resources.IFile)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 TreeViewer (org.eclipse.jface.viewers.TreeViewer)5 ExecTaskWithProgress (com.cubrid.common.ui.spi.progress.ExecTaskWithProgress)4 TaskExecutor (com.cubrid.common.ui.spi.progress.TaskExecutor)4 AzureCmdException (com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 Shell (org.eclipse.swt.widgets.Shell)4