Search in sources :

Example 66 with IProgressMonitor

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

the class ImportProjectAsWizard method performFinish.

/**
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
@Override
public boolean performFinish() {
    if (getContainer().getCurrentPage().equals(manyProjectsPage)) {
        isImportedSeveralProject = true;
        return manyProjectsPage.createProjects();
    } else {
        isImportedSeveralProject = false;
        name = mainPage.getName().trim().replace(' ', '_');
        final String technicalName = mainPage.getTechnicalName();
        final String sourcePath = mainPage.getSourcePath();
        final boolean isArchive = mainPage.isArchive();
        // see bug 4600, update the external lib path, make it possible to
        // copy external jar files into tos
        updateExternalLibPath();
        final Shell shell = getShell();
        ProgressDialog progressDialog = new ProgressDialog(shell) {

            private IProgressMonitor monitorWrap;

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitorWrap = new EventLoopProgressMonitor(monitor);
                try {
                    if (!isArchive) {
                        ImportProjectsUtilities.importProjectAs(shell, name, technicalName, sourcePath, monitorWrap);
                    } else {
                        // type.equalsIgnoreCase("archive")
                        ImportProjectsUtilities.importArchiveProjectAs(shell, name, technicalName, sourcePath, monitorWrap);
                    }
                } catch (IOException e) {
                    throw new InvocationTargetException(e);
                } catch (TarException e) {
                    throw new InvocationTargetException(e);
                }
                monitorWrap.done();
                //$NON-NLS-1$
                MessageDialog.openInformation(//$NON-NLS-1$
                shell, //$NON-NLS-1$
                Messages.getString("ImportProjectAction.messageDialogTitle.project"), //$NON-NLS-1$
                Messages.getString("ImportProjectAction.messageDialogContent.projectImportedSuccessfully"));
            }
        };
        try {
            progressDialog.executeProcess();
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getTargetException(), shell);
            return false;
        } catch (InterruptedException e) {
            IProject[] projects = org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().getProjects();
            for (IProject project : projects) {
                if (project.getName().equalsIgnoreCase(name)) {
                    try {
                        project.delete(true, true, null);
                    } catch (CoreException ee) {
                        ExceptionHandler.process(ee);
                    }
                }
            }
            return false;
        }
        return true;
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) CoreException(org.eclipse.core.runtime.CoreException) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) IOException(java.io.IOException) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProject(org.eclipse.core.resources.IProject)

Example 67 with IProgressMonitor

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

the class ErDiagramComposite method createErDiagram.

/**
     * admin Comment method "createErDiagram".
     * 
     * @return
     */
private ErDiagram createErDiagram(boolean isShowDesignerPage) {
    erDiagram = new ErDiagram();
    erDiagram.setErDiagramComposite(this);
    if (isShowDesignerPage) {
        IRunnableWithProgress progress = new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                //$NON-NLS-1$
                monitor.beginTask("", IProgressMonitor.UNKNOWN);
                try {
                    List<MetadataColumn> selectedColumns = new ArrayList<MetadataColumn>();
                    List<MetadataTable> tables = EMFRepositoryNodeManager.getInstance().getTables(getNodes(), selectedColumns);
                    erDiagram.setMetadataTables(tables);
                    List<String[]> fks = EMFRepositoryNodeManager.getInstance().getPKFromTables(tables, erDiagram.getErDiagramComposite().getDialog().getSelectedContext());
                    for (MetadataTable metadataTable : tables) {
                        Table table = new Table();
                        table.setMetadataTable(metadataTable, selectedColumns);
                        table.setErDiagram(erDiagram);
                        erDiagram.addTable(table);
                    }
                    erDiagram.setRelations(fks);
                } finally {
                    monitor.done();
                }
            }
        };
        UIUtils.runWithProgress(progress, true, dialog.getProgressMonitor(), dialog.getShell());
    } else {
        erDiagram.setMetadataTables(new ArrayList<MetadataTable>());
        erDiagram.setRelations(new ArrayList<String[]>());
    }
    return erDiagram;
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Table(org.talend.sqlbuilder.erdiagram.ui.nodes.Table) ErDiagram(org.talend.sqlbuilder.erdiagram.ui.nodes.ErDiagram) ArrayList(java.util.ArrayList) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 68 with IProgressMonitor

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

the class CreateTableCommand method execute.

@Override
public void execute() {
    for (MetadataTable metadataTable : metaTables) {
        if (!tableNames.contains(metadataTable.getSourceName())) {
            Table table = new Table();
            table.setMetadataTable(metadataTable, null);
            table.setErDiagram(erDiagram);
            erDiagram.addTable(table);
            erDiagram.getMetadataTables().add(metadataTable);
        }
    }
    IRunnableWithProgress progress = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            //$NON-NLS-1$
            monitor.beginTask("", IProgressMonitor.UNKNOWN);
            try {
                fks = EMFRepositoryNodeManager.getInstance().getPKFromTables(erDiagram.getMetadataTables(), erDiagram.getErDiagramComposite().getDialog().getSelectedContext());
            } finally {
                monitor.done();
            }
        }
    };
    ISQLBuilderDialog dialog = erDiagram.getErDiagramComposite().getDialog();
    UIUtils.runWithProgress(progress, true, dialog.getProgressMonitor(), dialog.getShell());
    erDiagram.setRelations(fks);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Table(org.talend.sqlbuilder.erdiagram.ui.nodes.Table) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ISQLBuilderDialog(org.talend.sqlbuilder.ui.ISQLBuilderDialog) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 69 with IProgressMonitor

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

the class WebServiceUIPresenter method refreshPageByWsdl.

@Override
public void refreshPageByWsdl(final String wsdlLocation) {
    webServiceUI.setErrorMessage(null);
    portTableModel.removeAll();
    functionTableModel.removeAll();
    IRunnableWithProgress retrieveData = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitor.beginTask("Retrieve WSDL parameter from net.", IProgressMonitor.UNKNOWN);
            try {
                retrieveData(wsdlLocation);
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        webServiceUI.runWithProgress(retrieveData);
        if (currentSetting.hasRpcOperation()) {
            webServiceUI.setErrorMessage(Messages.getString("WebServiceUI.NotSupportRpc"));
        }
        final List<String> ports = new ArrayList<String>(portFunctionsMap.keySet());
        portTableModel.addAll(ports);
        if (!ports.isEmpty()) {
            functionTableModel.addAll(portFunctionsMap.get(ports.get(0)));
            webServiceUI.selectFirstFunction();
        }
    } catch (InvocationTargetException e) {
        webServiceUI.setErrorMessage("Error getting service description: " + e.getCause().getMessage());
        webServiceUI.setPageComplete(false);
    } catch (InterruptedException e) {
    // ignore e.
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) WSDLException(javax.wsdl.WSDLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 70 with IProgressMonitor

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

the class OpenWSDLPage method finish.

public boolean finish() {
    // changed by hqzhang for TDI-19527, label=displayName
    final String label = item.getProperty().getDisplayName();
    item.getProperty().setLabel(label);
    IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        public void run(final IProgressMonitor monitor) throws CoreException {
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            try {
                item.setConnection(ServicesFactory.eINSTANCE.createServiceConnection());
                if (creation) {
                    item.getProperty().setId(factory.getNextId());
                    factory.create(item, getDestinationPath());
                    repositoryNode = new RepositoryNode(new RepositoryViewObject(item.getProperty()), repositoryNode.getParent(), ENodeType.REPOSITORY_ELEMENT);
                }
                ((ServiceConnection) item.getConnection()).setWSDLPath(path);
                ((ServiceConnection) item.getConnection()).getServicePort().clear();
                final IFile fileWsdl = WSDLUtils.getWsdlFile(item);
                final InputStream is;
                if (null == path) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    // create new WSDL file from template
                    TemplateProcessor.processTemplate("DATA_SERVICE_WSDL", Collections.singletonMap("serviceName", (Object) label), baos, getClass().getResourceAsStream(TEMPLATE_SERVICE_WSDL));
                    is = new ByteArrayInputStream(baos.toByteArray());
                } else {
                    //$NON-NLS-1$
                    String filenameTemplate = item.getProperty().getLabel() + '_' + item.getProperty().getVersion() + ".%d.wsdl";
                    Map<String, InputStream> wsdls = new WSDLLoader().load(path, filenameTemplate);
                    is = wsdls.remove(WSDLLoader.DEFAULT_FILENAME);
                    for (Map.Entry<String, InputStream> wsdl : wsdls.entrySet()) {
                        String filename = wsdl.getKey();
                        IFile importedWsdl = fileWsdl.getParent().getFile(new Path(filename));
                        if (!importedWsdl.exists()) {
                            importedWsdl.create(wsdl.getValue(), true, monitor);
                        } else {
                            importedWsdl.setContents(wsdl.getValue(), 0, monitor);
                        }
                        createReferenceResources(filename.substring(filename.lastIndexOf('.', filename.lastIndexOf('.') - 1) + 1));
                    }
                }
                // store WSDL in service
                if (!fileWsdl.exists()) {
                    fileWsdl.create(is, true, monitor);
                } else {
                    fileWsdl.setContents(is, 0, monitor);
                }
                // create reference to wsdl
                //$NON-NLS-1$
                createReferenceResources("wsdl");
                // path
                definition = WSDLUtils.getDefinition(fileWsdl);
                populateModelFromWsdl(factory, definition, item, repositoryNode);
                factory.save(item);
                ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
            } catch (Exception e) {
                //delete the node if any exception during the creation
                if (creation) {
                    try {
                        factory.save(item);
                        factory.deleteObjectPhysical(repositoryNode.getObject());
                    } catch (PersistenceException e1) {
                        throw getCoreException("WDSL creation failed", e1);
                    }
                }
                //throw the exception
                if (e instanceof CoreException) {
                    throw (CoreException) e;
                }
                if (e instanceof InvocationTargetException) {
                    throw getCoreException("WDSL creation failed", e.getCause());
                }
                throw getCoreException("WDSL creation failed", e);
            }
        }
    };
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    try {
        // we use the workspace scheduling rule to lock all
        ISchedulingRule schedulingRule = workspace.getRoot();
        // workspace modifications during the run.
        // the update of 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, null);
    } catch (CoreException e) {
        MessageBoxExceptionHandler.process(e);
        return false;
    }
    // open wsdl editor
    OpenWSDLEditorAction action = new OpenWSDLEditorAction();
    action.setServiceItem(item);
    action.run();
    // import schemas if required
    if (checkImport.isVisible() && checkImport.getSelection() && null != definition) {
        PublishMetadataRunnable publishMetadataRunnable = new PublishMetadataRunnable(definition, getShell());
        try {
            getContainer().run(true, true, publishMetadataRunnable);
        } catch (InvocationTargetException e) {
            Throwable cause = e.getCause();
            String message = (null != cause.getMessage()) ? cause.getMessage() : cause.getClass().getName();
            setErrorMessage("Populate schema to repository: " + message);
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    }
    return true;
}
Also used : ServiceConnection(org.talend.repository.services.model.services.ServiceConnection) IFile(org.eclipse.core.resources.IFile) OpenWSDLEditorAction(org.talend.repository.services.action.OpenWSDLEditorAction) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) WSDLLoader(org.talend.utils.wsdl.WSDLLoader) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RepositoryNode(org.talend.repository.model.RepositoryNode) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) PublishMetadataRunnable(org.talend.repository.services.action.PublishMetadataRunnable) Map(java.util.Map)

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