Search in sources :

Example 26 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project tesb-studio-se by Talend.

the class SchemaTool method populateSchema.

private static IStatus populateSchema(Shell shell, IWizardContainer container, Definition definition) {
    IRunnableWithProgress runnable;
    try {
        Class<? extends IRunnableWithProgress> forName = Class.forName("org.talend.repository.services.action.PublishMetadataRunnable").asSubclass(IRunnableWithProgress.class);
        Constructor<? extends IRunnableWithProgress> constructor = forName.getConstructor(Definition.class, Shell.class);
        runnable = constructor.newInstance(definition, shell);
    } catch (Exception e) {
        String message = (null != e.getMessage()) ? e.getMessage() : e.getClass().getName();
        return WebServiceComponentPlugin.getStatus("Can't create populate action: " + message, e);
    }
    try {
        container.run(true, true, runnable);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        String message = (null != cause.getMessage()) ? cause.getMessage() : cause.getClass().getName();
        return WebServiceComponentPlugin.getStatus("Populate schema to repository: " + message, e);
    } catch (InterruptedException e) {
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 27 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project tesb-studio-se by Talend.

the class ServiceExportWizard method performFinish.

@Override
public boolean performFinish() {
    final String destinationValue = mainPage.getDestinationValue();
    // TESB-7319: add confirm dialog
    if (new File(destinationValue).exists()) {
        boolean openQuestion = MessageDialog.openQuestion(getShell(), Messages.ServiceExportWizard_destinationExistTitle, Messages.ServiceExportWizard_destinationExistMessage);
        if (!openQuestion) {
            return false;
        }
    }
    // END TESB-7319
    Map<ExportChoice, Object> exportChoiceMap = mainPage.getExportChoiceMap();
    try {
        if (mainPage.isAddMavenScript()) {
            ServiceExportWithMavenManager mavenManager = new ServiceExportWithMavenManager(exportChoiceMap, IContext.DEFAULT, JobScriptsManager.LAUNCHER_ALL, IProcessor.NO_STATISTICS, IProcessor.NO_TRACES);
            IRunnableWithProgress action = new ExportServiceWithMavenAction(mavenManager, exportChoiceMap, serviceItem, destinationValue);
            getContainer().run(false, true, action);
        } else {
            IRunnableWithProgress action = new ExportServiceAction(serviceItem, destinationValue, exportChoiceMap);
            getContainer().run(true, true, action);
        }
        mainPage.finish();
    } catch (InvocationTargetException e) {
        MessageBoxExceptionHandler.process(e.getCause(), getShell());
        return false;
    } catch (InterruptedException e) {
        return false;
    }
    return true;
}
Also used : ExportServiceAction(org.talend.repository.services.ui.action.ExportServiceAction) ExportServiceWithMavenAction(org.talend.repository.services.ui.action.ExportServiceWithMavenAction) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) ServiceExportWithMavenManager(org.talend.repository.services.ui.scriptmanager.ServiceExportWithMavenManager) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 28 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.

the class JobScriptsExportWizardPage method finish.

// protected String getDestinationValueSU() {
//        return this.suDestinationFilePath != null ? this.suDestinationFilePath : ""; //$NON-NLS-1$
//
// }
/**
     * The Finish button was pressed. Try to do the required work now and answer a boolean indicating success. If false
     * is returned then the wizard will not close.
     * 
     * @returns boolean
     */
@Override
public boolean finish() {
    // TODO
    if (treeViewer != null) {
        treeViewer.removeCheckStateListener(checkStateListener);
    }
    saveWidgetValues();
    if (manager == null) {
        manager = createJobScriptsManager();
    }
    if (!ensureTargetIsValid()) {
        return false;
    }
    if (ensureLog4jSettingIsValid()) {
        MessageDialog dialog = new MessageDialog(getShell(), "Question", null, Messages.getString("Log4jSettingPage.IlleagalBuild"), MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
        dialog.open();
        int result = dialog.getReturnCode();
        if (result != MessageDialog.OK) {
            return false;
        }
    }
    JobExportType jobExportType = getCurrentExportType1();
    if (JobExportType.POJO.equals(jobExportType)) {
        IRunnableWithProgress worker = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                buildJobWithMaven(JobExportType.POJO, monitor);
            }
        };
        try {
            getContainer().run(false, true, worker);
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    } else {
        List<ContextParameterType> contextEditableResultValuesList = null;
        if (manager != null) {
            contextEditableResultValuesList = manager.getContextEditableResultValuesList();
        }
        if (nodes.length == 1) {
            RepositoryNode node = nodes[0];
            if (node.getType() == ENodeType.SYSTEM_FOLDER) {
                manager.setTopFolderName(ProjectManager.getInstance().getCurrentProject().getLabel());
            } else {
                manager.setTopFolderName(getDefaultFileNameWithType());
            }
        } else {
            manager.setTopFolderName(getDefaultFileNameWithType());
        }
        // for feature:11976, recover back the old default manager value with ContextParameters
        if (contextEditableResultValuesList == null) {
            manager.setContextEditableResultValuesList(new ArrayList<ContextParameterType>());
        } else {
            manager.setContextEditableResultValuesList(contextEditableResultValuesList);
        }
        manager.setMultiNodes(isMultiNodes());
        // achen modify to fix bug 0006222
        IRunnableWithProgress worker = new JobExportAction(Arrays.asList(getCheckNodes()), getSelectedJobVersion(), manager, originalRootFolderName, getProcessType());
        try {
            getContainer().run(false, true, worker);
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    }
    // see bug 7181
    if (zipOption != null && zipOption.equals("true")) {
        // unzip
        try {
            String zipFile;
            if (manager != null) {
                zipFile = manager.getDestinationPath();
            } else {
                zipFile = getDestinationValue();
                int separatorIndex = zipFile.lastIndexOf(File.separator);
                if (separatorIndex == -1) {
                    //$NON-NLS-1$
                    String userDir = System.getProperty("user.dir");
                    zipFile = userDir + File.separator + zipFile;
                }
            }
            // Added by Marvin Wang on Feb.1, 2012 for bug TDI-18824
            File file = new File(zipFile);
            if (file.exists()) {
                ZipToFile.unZipFile(zipFile, file.getParentFile().getAbsolutePath());
            }
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e, getShell());
            return false;
        }
    }
    if (treeViewer != null) {
        treeViewer.dispose();
    }
    // end
    return true;
}
Also used : JobExportAction(org.talend.repository.ui.wizards.exportjob.action.JobExportAction) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Point(org.eclipse.swt.graphics.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobExportType(org.talend.repository.ui.wizards.exportjob.JavaJobScriptsExportWSWizardPage.JobExportType) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) ZipToFile(org.talend.repository.ui.utils.ZipToFile) File(java.io.File) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 29 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress 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 30 with IRunnableWithProgress

use of org.eclipse.jface.operation.IRunnableWithProgress in project tdi-studio-se by Talend.

the class RepositoryWebService method addListenerForWSDLCom.

private void addListenerForWSDLCom() {
    refreshbut.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell().getShell());
            IRunnableWithProgress runnable = new IRunnableWithProgress() {

                public void run(final IProgressMonitor monitor) {
                    //$NON-NLS-1$
                    monitor.beginTask("Retrieve WSDL parameter from net.", IProgressMonitor.UNKNOWN);
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            getDataFromNet();
                        }
                    });
                    monitor.done();
                }
            };
            try {
                progressDialog.run(true, true, runnable);
            } catch (InvocationTargetException e1) {
                ExceptionHandler.process(e1);
            } catch (InterruptedException e1) {
                ExceptionHandler.process(e1);
            } catch (WebServiceCancelException e1) {
                return;
            }
            if (currentPortName != null) {
                connection.setPortName(currentPortName.getPortName());
            } else if (currentPortName == null && allPortNames != null) {
                currentPortName = allPortNames.get(0);
                connection.setPortName(currentPortName.getPortName());
            }
            listTable.setSelection(listTable.getItem(0));
            if (currentFunction != null) {
                connection.setMethodName(currentFunction.getName());
                connection.setServerNameSpace(currentFunction.getServerNameSpace());
                connection.setServerName(currentFunction.getServerName());
                connection.setPortNameSpace(currentFunction.getServerNameSpace());
            }
            // listTable.select(0);
            isFirst = false;
        }
    });
    // TableItem firstItem = listTable.getItem(0);
    // currentFunction = firstItem.getData();
    listTable = listTableView.getTable();
    portListTable = portListTableView.getTable();
    listTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] item = listTable.getSelection();
            currentFunction = (Function) item[0].getData();
            if (currentFunction != null) {
                connection.setServerName(currentFunction.getServerName());
                connection.setServerNameSpace(currentFunction.getServerNameSpace());
                connection.setMethodName(currentFunction.getName());
            }
            // if select the same as before ,don't change it
            // IElementParameter METHODPara = connector.getElementParameter("METHOD"); //$NON-NLS-1$
            // Object obj = METHODPara.getValue();
            // if (currentFunction.getName().equals(obj.toString())) {
            // return;
            // }
            List<ParameterInfo> listIn = currentFunction.getInputParameters();
            List<ParameterInfo> listOut = currentFunction.getOutputParameters();
        }
    });
    portListTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] item = portListTable.getSelection();
            currentPortName = (PortNames) item[0].getData();
            connection.setPortName(currentPortName.getPortName());
        }
    });
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Function(org.talend.designer.webservice.ws.wsdlinfo.Function) PortNames(org.talend.designer.webservice.ws.wsdlinfo.PortNames) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)177 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)167 InvocationTargetException (java.lang.reflect.InvocationTargetException)160 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)83 CoreException (org.eclipse.core.runtime.CoreException)56 ArrayList (java.util.ArrayList)42 IStatus (org.eclipse.core.runtime.IStatus)39 Status (org.eclipse.core.runtime.Status)36 IFile (org.eclipse.core.resources.IFile)27 File (java.io.File)24 IOException (java.io.IOException)24 PartInitException (org.eclipse.ui.PartInitException)24 List (java.util.List)19 IProject (org.eclipse.core.resources.IProject)19 PersistenceException (org.talend.commons.exception.PersistenceException)19 Shell (org.eclipse.swt.widgets.Shell)18 Display (org.eclipse.swt.widgets.Display)17 IResource (org.eclipse.core.resources.IResource)16 IPath (org.eclipse.core.runtime.IPath)15 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)12