Search in sources :

Example 91 with IProgressMonitor

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

the class NewJvmConnectionWizard method addActiveJvm.

/**
     * Adds the active JVM.
     * 
     * @return The active JVM
     */
private IActiveJvm addActiveJvm() {
    final boolean isHostAndPortSelected = page.isHostAndPortSelected();
    final String hostName = page.getRemoteHost();
    final int port = page.getPort();
    final String userName = page.getUserName();
    final String password = page.getPassword();
    final String jmxUrl = page.getJmxUrl();
    try {
        final IActiveJvm[] result = new IActiveJvm[1];
        IRunnableWithProgress op = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    int period = Activator.getDefault().getPreferenceStore().getInt(IConstants.UPDATE_PERIOD);
                    if (isHostAndPortSelected) {
                        IHost host = JvmModel.getInstance().addHost(hostName);
                        result[0] = host.addRemoteActiveJvm(port, userName, password, period);
                    } else {
                        result[0] = JvmModel.getInstance().addHostAndJvm(jmxUrl, userName, password, period);
                    }
                } catch (JvmCoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        new ProgressMonitorDialog(getShell()).run(true, true, op);
        return result[0];
    } catch (InvocationTargetException e) {
        openErrorDialog(e);
        return null;
    } catch (InterruptedException e) {
        return null;
    }
}
Also used : IActiveJvm(org.talend.designer.runtime.visualization.IActiveJvm) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IHost(org.talend.designer.runtime.visualization.IHost) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) JvmCoreException(org.talend.designer.runtime.visualization.JvmCoreException)

Example 92 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor 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 93 with IProgressMonitor

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

the class StandAloneTalendJavaEditor method refreshName.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.ui.IUIRefresher#refreshName()
     */
@Override
public void refreshName() {
    ICompilationUnit unit = (ICompilationUnit) this.getInputJavaElement();
    String newName = item.getProperty().getLabel();
    try {
        boolean noError = true;
        // String newName2 = newName + SuffixConstants.SUFFIX_STRING_java;
        //$NON-NLS-1$
        String newName2 = newName + ".java";
        if (item instanceof RoutineItem && !unit.getElementName().equals(newName2)) {
            JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
            processor.setNewElementName(newName2);
            RenameRefactoring ref = new RenameRefactoring(processor);
            final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
            IRunnableWithProgress r = new IRunnableWithProgress() {

                @Override
                public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                operation.run(monitor);
                            } catch (CoreException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                    });
                }
            };
            PlatformUI.getWorkbench().getProgressService().run(true, true, r);
            RefactoringStatus conditionStatus = operation.getConditionStatus();
            if (conditionStatus != null && conditionStatus.hasError()) {
                //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                String errorMessage = "Rename " + unit.getElementName() + " to " + newName + " has errors!";
                RefactoringStatusEntry[] entries = conditionStatus.getEntries();
                for (RefactoringStatusEntry entry : entries) {
                    //$NON-NLS-1$
                    errorMessage += "\n>>>" + entry.getMessage();
                }
                //$NON-NLS-1$
                MessageDialog.openError(this.getSite().getShell(), "Warning", errorMessage);
                noError = false;
            }
        }
        if (noError) {
            doSave(null);
        }
        setName();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RoutineItem(org.talend.core.model.properties.RoutineItem) PerformRefactoringOperation(org.eclipse.ltk.core.refactoring.PerformRefactoringOperation) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RenameCompilationUnitProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameCompilationUnitProcessor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) JavaRenameProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor)

Example 94 with IProgressMonitor

use of org.eclipse.core.runtime.IProgressMonitor 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 95 with IProgressMonitor

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

the class AbstractJobSettingsPage method save.

protected void save() {
    List<String> checkedObjects = new ArrayList<String>();
    List<IRepositoryViewObject> allProcess = null;
    try {
        allProcess = ProxyRepositoryFactory.getInstance().getAll(ERepositoryObjectType.PROCESS);
    } catch (PersistenceException e1) {
        ExceptionHandler.process(e1);
    }
    for (IRepositoryViewObject object : allProcess) {
        if (isStatUseProjectSetting(object)) {
            if (!checkedObjects.contains(object.getProperty().getId())) {
                checkedObjects.add(object.getProperty().getId());
                if (!checkedNodeObject.contains(object)) {
                    checkedNodeObject.add(object);
                }
            }
        }
    }
    List<IProcess2> allOpenedProcessList = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(getEditors());
    if (allOpenedProcessList != null) {
        for (int i = 0; i < allOpenedProcessList.size(); i++) {
            if (checkedObjects.contains(allOpenedProcessList.get(i).getProperty().getId())) {
                openedProcessList.add(allOpenedProcessList.get(i));
            }
        }
    }
    //
    final IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask(getTaskMessages(), (checkedNodeObject.size()) * 100);
            final Map<String, Set<String>> contextVars = DetectContextVarsUtils.detectByPropertyType(elem, true);
            // must init this
            addContextModel = false;
            if (!contextVars.isEmpty()) {
                // boolean showDialog = false;
                Set<String> contextSet = new HashSet<String>();
                for (String key : contextVars.keySet()) {
                    contextSet = contextVars.get(key);
                    break;
                }
                Connection connection = null;
                IElementParameter ptParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
                if (ptParam != null) {
                    IElementParameter propertyElem = ptParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName());
                    Object proValue = propertyElem.getValue();
                    if (proValue instanceof String && ((String) proValue).equalsIgnoreCase(EmfComponent.REPOSITORY)) {
                        IElementParameter repositoryElem = ptParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                        String value = (String) repositoryElem.getValue();
                        ConnectionItem connectionItem = UpdateRepositoryUtils.getConnectionItemByItemId(value);
                        connection = connectionItem.getConnection();
                        if (connection != null && connection.isContextMode()) {
                            addContextModel = true;
                        // ContextItem contextItem =
                        // ContextUtils.getContextItemById(connection.getContextId());
                        // for (IProcess process : openedProcessList) {
                        // Set<String> addedContext =
                        // ConnectionContextHelper.checkAndAddContextVariables(contextItem,
                        // contextSet, process.getContextManager(), false);
                        // if (addedContext != null && !addedContext.isEmpty()) {
                        // showDialog = true;
                        // break;
                        // }
                        // }
                        }
                    }
                }
                if (addContextModel) {
                    // if the context is not existed in job, will add or not.
                    Display disp = Display.getCurrent();
                    if (disp == null) {
                        disp = Display.getDefault();
                    }
                    if (disp != null) {
                        disp.syncExec(new Runnable() {

                            @Override
                            public void run() {
                                showContextAndCheck(contextVars);
                            }
                        });
                    } else {
                        showContextAndCheck(contextVars);
                    }
                }
            }
            monitor.worked(10);
            IWorkspaceRunnable workspaceRunnable = new IWorkspaceRunnable() {

                @Override
                public void run(IProgressMonitor monitor) throws CoreException {
                    for (IRepositoryViewObject object : checkedNodeObject) {
                        saveProcess(object, addContextModel, contextVars, monitor);
                    }
                }
            };
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                workspace.run(workspaceRunnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
            monitor.done();
        }
    };
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IElementParameter(org.talend.core.model.process.IElementParameter) HashSet(java.util.HashSet) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Display(org.eclipse.swt.widgets.Display)

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