Search in sources :

Example 86 with IProgressMonitor

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

the class VersionManagementPage method updateItemsVersion.

@Override
protected void updateItemsVersion() {
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor monitor) throws CoreException {
            RepositoryWorkUnit<Object> rwu = new RepositoryWorkUnit<Object>(project, "Update items version") {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    //$NON-NLS-1$
                    monitor.beginTask("Update items version", checkedObjects.size());
                    Map<String, String> versions = new HashMap<String, String>();
                    for (int i = 0; i < checkedObjects.size(); i++) {
                        ItemVersionObject object = checkedObjects.get(i);
                        versions.put(object.getItem().getProperty().getId(), object.getOldVersion());
                    }
                    for (ItemVersionObject object : checkedObjects) {
                        IRepositoryViewObject repositoryObject = object.getRepositoryNode().getObject();
                        if (repositoryObject != null && repositoryObject.getProperty() != null) {
                            if (!object.getNewVersion().equals(repositoryObject.getVersion())) {
                                final Item item = object.getItem();
                                Property itemProperty = item.getProperty();
                                itemProperty.setVersion(object.getNewVersion());
                                monitor.subTask(itemProperty.getLabel());
                                try {
                                    // for bug 12853 ,version management doesn't work for joblet because eResource
                                    // is null
                                    IRepositoryViewObject obj = null;
                                    if (itemProperty.eResource() == null) {
                                        ItemState state = item.getState();
                                        if (state != null && state.getPath() != null) {
                                            obj = FACTORY.getLastVersion(project, itemProperty.getId(), state.getPath(), object.getRepositoryNode().getObjectType());
                                        } else {
                                            obj = FACTORY.getLastVersion(project, itemProperty.getId());
                                        }
                                    }
                                    if (obj != null) {
                                        // obj.setVersion(object.getNewVersion());
                                        FACTORY.save(project, obj.getProperty());
                                        builder.addOrUpdateItem(obj.getProperty().getItem(), true);
                                    } else {
                                        String id = itemProperty.getId();
                                        FACTORY.save(project, itemProperty);
                                        if (versionLatest.getSelection()) {
                                            builder.updateItemVersion(item, object.getOldVersion(), id, versions, true);
                                        }
                                        builder.addOrUpdateItem(item, true);
                                    }
                                } catch (PersistenceException e) {
                                    ExceptionHandler.process(e);
                                }
                            }
                        }
                        monitor.worked(1);
                    }
                    try {
                        FACTORY.saveProject(project);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                }
            };
            rwu.setAvoidUnloadResources(true);
            rwu.executeRun();
            monitor.done();
        }
    };
    IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            try {
                ISchedulingRule schedulingRule = workspace.getRoot();
                // the update the project files need to be done in the workspace runnable to avoid all notification
                // of changes before the end of the modifications.
                workspace.run(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
            } catch (CoreException e) {
                ExceptionHandler.process(e);
            }
        }
    };
    // final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(null);
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) HashMap(java.util.HashMap) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ItemState(org.talend.core.model.properties.ItemState) IWorkspace(org.eclipse.core.resources.IWorkspace) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject) Property(org.talend.core.model.properties.Property)

Example 87 with IProgressMonitor

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

the class GuessSchemaController method useMockJob.

private void useMockJob() {
    /*
         * get the select node,it's the input node of the process. then transfer selected context varriable to
         * openContextChooseDialog, added by hyWang
         */
    final IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    final Shell parentShell = this.composite.getShell();
    final Node inputNode = (Node) this.curParameter.getElement();
    if (connParameters == null) {
        initConnectionParameters();
    }
    final String tmpMemoSql = this.memoSQL;
    final DatabaseConnection connt = TracesConnectionUtils.createConnection(connParameters);
    IMetadataConnection iMetadataConnection = null;
    boolean isStatus = false;
    try {
        if (connt != null) {
            iMetadataConnection = ConvertionHelper.convert(connt);
            isStatus = checkConnection(iMetadataConnection);
        }
        if (isStatus) {
            if (EDatabaseTypeName.GENERAL_JDBC.getDisplayName().equals(iMetadataConnection.getDbType())) {
                info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverClass(), iMetadataConnection.getDriverJarPath(), iMetadataConnection.getAdditionalParams());
            } else if (EDatabaseTypeName.HIVE.getDisplayName().equals(iMetadataConnection.getDbType())) {
                String jobTracker = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL)));
                String nameNode = TalendTextUtils.removeQuotes(String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL)));
                String thrifturi = null;
                if (HiveModeInfo.get(iMetadataConnection.getDbVersionString()) == HiveModeInfo.EMBEDDED) {
                    thrifturi = "thrift://" + iMetadataConnection.getServerName() + ":" + iMetadataConnection.getPort();
                }
                info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), jobTracker, nameNode, thrifturi, iMetadataConnection.getDriverJarPath());
                String hiveServerVersion = String.valueOf(iMetadataConnection.getParameter(ConnParameterKeys.HIVE_SERVER_VERSION));
                //$NON-NLS-1$
                String driverClass = "";
                if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServerVersion)) {
                    driverClass = EDatabase4DriverClassName.HIVE2.getDriverClass();
                } else {
                    driverClass = EDatabase4DriverClassName.HIVE.getDriverClass();
                }
                info.setDriverClassName(driverClass);
            } else {
                info = new DbInfo(iMetadataConnection.getDbType(), iMetadataConnection.getUsername(), iMetadataConnection.getPassword(), iMetadataConnection.getDbVersionString(), iMetadataConnection.getUrl(), iMetadataConnection.getDriverJarPath());
            }
            final Property property = GuessSchemaProcess.getNewmockProperty();
            List<IContext> allcontexts = inputNode.getProcess().getContextManager().getListContext();
            OpenContextChooseComboDialog dialog = new OpenContextChooseComboDialog(parentShell, allcontexts);
            dialog.create();
            dialog.getShell().setText(CONTEXT_CHOOSE_DIALOG_TITLE);
            IContext selectContext = null;
            // job only have defoult context,or the query isn't context mode
            if (allcontexts.size() == 1 || TalendTextUtils.isCommonString(tmpMemoSql)) {
                selectContext = inputNode.getProcess().getContextManager().getDefaultContext();
            } else if (Window.OK == dialog.open()) {
                selectContext = dialog.getSelectedContext();
            }
            final IContext context = selectContext;
            if (context != null) {
                //
                final ProgressMonitorDialog pmd = new ProgressMonitorDialog(this.composite.getShell());
                pmd.run(true, true, new IRunnableWithProgress() {

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

                            @Override
                            public void run() {
                                runShadowProcess(property, inputNode, context, switchParam);
                            }
                        });
                    }
                });
            }
        } else {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    //$NON-NLS-1$
                    String pid = "org.talend.sqlbuilder";
                    //$NON-NLS-1$
                    String mainMsg = Messages.getString("GuessSchemaController.connectionFailed");
                    ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
                    if (dialog.getCodeOfButton() == Window.OK) {
                        openParamemerDialog(composite.getShell(), part.getProcess().getContextManager());
                    }
                }
            });
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
// else {
// try {
// pmd2.run(true, true, new IRunnableWithProgress() {
// public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
// Display.getDefault().asyncExec(new Runnable() {
//
// public void run() {
// String pid = SqlBuilderPlugin.PLUGIN_ID;
//                    String mainMsg = Messages.getString("GuessSchemaController.connectionFailed"); //$NON-NLS-1$
// ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite
// .getShell(), pid, mainMsg, connParameters.getConnectionComment());
// if (dialog.getCodeOfButton() == Window.OK) {
// openParamemerDialog(composite.getShell(), part.getTalendEditor().getProcess().getContextManager());
// }
// }
// });
// }
// });
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) IContext(org.talend.core.model.process.IContext) Node(org.talend.designer.core.ui.editor.nodes.Node) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) ProcessorException(org.talend.designer.runprocess.ProcessorException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) OpenContextChooseComboDialog(org.talend.designer.core.ui.editor.properties.controllers.uidialog.OpenContextChooseComboDialog) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property)

Example 88 with IProgressMonitor

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

the class JobHierarchyLifeCycle method ensureRefreshedTypeHierarchy.

public void ensureRefreshedTypeHierarchy(final IProcess2 element, IRunnableContext context) throws InvocationTargetException, InterruptedException {
    if (element == null) {
        freeHierarchy();
        return;
    }
    // boolean hierachyCreationNeeded = (fHierarchy == null || !element.equals(inputProcess));
    boolean hierachyCreationNeeded = true;
    if (hierachyCreationNeeded || fHierarchyRefreshNeeded) {
        IRunnableWithProgress op = new IRunnableWithProgress() {

            public void run(IProgressMonitor pm) throws InvocationTargetException, InterruptedException {
                try {
                    doHierarchyRefresh(element, pm);
                } catch (JavaModelException e) {
                    throw new InvocationTargetException(e);
                } catch (OperationCanceledException e) {
                    throw new InterruptedException();
                }
            }
        };
        fHierarchyRefreshNeeded = true;
        context.run(true, true, op);
        fHierarchyRefreshNeeded = false;
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JavaModelException(org.eclipse.jdt.core.JavaModelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 89 with IProgressMonitor

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

the class DeleteAllJobWhenStartUp method earlyStartup.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IStartup#earlyStartup()
     */
@Override
public void earlyStartup() {
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        return;
    }
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject codeProject = root.getProject(TalendMavenConstants.PROJECT_NAME);
    if (!codeProject.exists() || !codeProject.isAccessible()) {
        return;
    }
    final IWorkspaceRunnable op = new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
            ITalendProcessJavaProject talendJavaProject = processService.getTalendProcessJavaProject();
            if (talendJavaProject != null) {
                IJavaProject jProject = talendJavaProject.getJavaProject();
                if (!jProject.isOpen()) {
                    jProject.open(monitor);
                }
                // empty the src/main/java...
                IFolder srcFolder = talendJavaProject.getSrcFolder();
                talendJavaProject.cleanFolder(monitor, srcFolder);
                // contexts
                IFolder resourcesFolder = talendJavaProject.getResourcesFolder();
                emptyContexts(monitor, resourcesFolder, talendJavaProject);
                // empty the outputs, target
                IFolder targetFolder = talendJavaProject.getTargetFolder();
                talendJavaProject.cleanFolder(monitor, targetFolder);
                // empty the src/test/java
                IFolder testSrcFolder = talendJavaProject.getTestSrcFolder();
                talendJavaProject.cleanFolder(monitor, testSrcFolder);
                // empty the src/test/java (main for contexts)
                IFolder testResourcesFolder = talendJavaProject.getTestResourcesFolder();
                talendJavaProject.cleanFolder(monitor, testResourcesFolder);
                // empty temp
                IFolder tempFolder = talendJavaProject.getTempFolder();
                talendJavaProject.cleanFolder(monitor, tempFolder);
                // empty lib/...
                IFolder libFolder = talendJavaProject.getLibFolder();
                talendJavaProject.cleanFolder(monitor, libFolder);
                // rules
                IFolder rulesResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_RULES_DIRECTORY);
                talendJavaProject.cleanFolder(monitor, rulesResFolder);
                // sqltempalte
                IFolder sqlTemplateResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_SQLPATTERNS_DIRECTORY);
                talendJavaProject.cleanFolder(monitor, sqlTemplateResFolder);
            }
        }

        ;
    };
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        ISchedulingRule schedulingRule = workspace.getRoot();
        // the update the project files need to be done in the workspace runnable to avoid all
        // notification
        // of changes before the end of the modifications.
        workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
    } catch (CoreException e) {
        if (e.getCause() != null) {
            ExceptionHandler.process(e.getCause());
        } else {
            ExceptionHandler.process(e);
        }
    }
    executed = true;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 90 with IProgressMonitor

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

the class OpenDeclarationAction method searchSource.

/**
     * Searches the source for the given class name with progress monitor.
     * 
     * @return The source
     * @throws InterruptedException if operation is canceled
     */
private IType searchSource() throws InterruptedException {
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
    dialog.setOpenOnRun(false);
    // search source corresponding to the class name
    final IType[] source = new IType[1];
    IRunnableWithProgress op = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            if (!searchEngineInitialized) {
                monitor.subTask(Messages.searchingSoruceMsg);
                searchEngineInitialized = true;
            }
            // open progress monitor dialog when it takes long time
            new Timer().schedule(new TimerTask() {

                @Override
                public void run() {
                    Display.getDefault().syncExec(new Runnable() {

                        @Override
                        public void run() {
                            dialog.open();
                        }
                    });
                }
            }, 400);
            if (className == null) {
                return;
            }
            try {
                source[0] = doSearchSource(className);
            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            }
            if (monitor.isCanceled()) {
                throw new InterruptedException();
            }
        }
    };
    try {
        dialog.run(true, true, op);
    } catch (InvocationTargetException e) {
        Activator.log(IStatus.ERROR, NLS.bind(Messages.searchClassFailedMsg, className), e);
    }
    return source[0];
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Timer(java.util.Timer) TimerTask(java.util.TimerTask) CoreException(org.eclipse.core.runtime.CoreException) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IType(org.eclipse.jdt.core.IType) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

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