Search in sources :

Example 96 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project tdi-studio-se by Talend.

the class ImportItemWizardPage method performFinish.

public boolean performFinish() {
    final List<ItemRecord> itemRecords = new ArrayList<ItemRecord>();
    final List<ItemRecord> checkedItemRecords = getCheckedElements();
    itemRecords.addAll(checkedItemRecords);
    itemRecords.addAll(getHadoopSubrecords(itemRecords));
    for (ItemRecord itemRecord : itemRecords) {
        Item item = itemRecord.getProperty().getItem();
        if (item instanceof JobletProcessItem) {
            needToRefreshPalette = true;
        }
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        if (item.getState().isLocked()) {
            try {
                factory.unlock(item);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            } catch (LoginException e) {
                ExceptionHandler.process(e);
            }
        }
        ERepositoryStatus status = factory.getStatus(item);
        if (status != null && status == ERepositoryStatus.LOCK_BY_USER) {
            try {
                factory.unlock(item);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            } catch (LoginException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    try {
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IPath destinationPath = null;
                String contentType = "";
                if (rNode != null && rNode.getType().equals(ENodeType.SIMPLE_FOLDER)) {
                    destinationPath = RepositoryNodeUtilities.getPath(rNode);
                    contentType = rNode.getContentType().name();
                }
                repositoryUtil.setErrors(false);
                repositoryUtil.clear();
                repositoryUtil.importItemRecords(manager, itemRecords, monitor, overwrite, destinationPath, contentType);
                if (repositoryUtil.hasErrors()) {
                    throw new InvocationTargetException(new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), //$NON-NLS-1$
                    "Import errors")));
                }
            }
        };
        new ProgressMonitorDialog(getShell()).run(true, true, iRunnableWithProgress);
    } catch (InvocationTargetException e) {
        Throwable targetException = e.getTargetException();
        if (repositoryUtil.getRoutineExtModulesMap().isEmpty()) {
            if (targetException instanceof CoreException) {
                //$NON-NLS-1$
                MessageDialog.openWarning(//$NON-NLS-1$
                getShell(), //$NON-NLS-1$
                Messages.getString("ImportItemWizardPage.ImportSelectedItems"), //$NON-NLS-1$
                Messages.getString("ImportItemWizardPage.ErrorsOccured"));
            }
        }
    } catch (InterruptedException e) {
    //
    }
    ResourcesManager curManager = this.manager;
    if (curManager instanceof ProviderManager) {
        curManager.closeResource();
    }
    selectedItems = null;
    itemRecords.clear();
    return true;
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) IPath(org.eclipse.core.runtime.IPath) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) JobletDocumentationItem(org.talend.core.model.properties.JobletDocumentationItem) JobDocumentationItem(org.talend.core.model.properties.JobDocumentationItem) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) TreeItem(org.eclipse.swt.widgets.TreeItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 97 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project tdi-studio-se by Talend.

the class PaletteSettingPage method okPressed.

protected void okPressed() {
    ProgressMonitorDialog pmd = new ProgressMonitorDialog(DisplayUtils.getDefaultShell());
    IRunnableWithProgress rwp = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
            try {
                prf.saveProject(project);
                ShowStandardAction.getInstance().doRun();
                if (needCodeGen) {
                    Job refreshTemplates = CorePlugin.getDefault().getCodeGeneratorService().refreshTemplates();
                    refreshTemplates.addJobChangeListener(new JobChangeAdapter() {

                        @Override
                        public void done(IJobChangeEvent event) {
                            CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
                        }
                    });
                }
            // ComponentUtilities.updatePalette();
            } catch (Exception ex) {
                ExceptionHandler.process(ex);
            }
        }
    };
    try {
        pmd.run(true, false, rwp);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) Job(org.eclipse.core.runtime.jobs.Job) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 98 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project tdi-studio-se by Talend.

the class MavenVersionManagementProjectSettingPage method updateItemsVersion.

protected void updateItemsVersion() {
    List<ItemVersionObject> JobsOpenedInEditor = new ArrayList<ItemVersionObject>();
    List<ItemVersionObject> closedJobs = new ArrayList<ItemVersionObject>();
    boolean hasJobOpenedInEditor = false;
    StringBuilder builder = new StringBuilder();
    for (ItemVersionObject object : checkedObjects) {
        if (RepositoryManager.isOpenedItemInEditor(object.getRepositoryNode().getObject())) {
            hasJobOpenedInEditor = true;
            JobsOpenedInEditor.add(object);
            //$NON-NLS-1$
            builder.append(object.getRepositoryNode().getObject().getLabel() + ", ");
        } else {
            closedJobs.add(object);
        }
    }
    if (builder.length() > 0) {
        builder.delete(builder.length() - 2, builder.length());
    }
    if (hasJobOpenedInEditor) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.WarningTitle2"), //$NON-NLS-1$
        Messages.getString("VersionManagementDialog.openedInEditorMessage", builder.toString()));
        IWorkbenchWindow workBench = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (workBench != null) {
            IWorkbenchPage page = workBench.getActivePage();
            IEditorReference[] editorRefs = page.getEditorReferences();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreUIService.class)) {
                IDesignerCoreUIService service = (IDesignerCoreUIService) GlobalServiceRegister.getDefault().getService(IDesignerCoreUIService.class);
                if (service != null) {
                    for (IEditorReference editorRef : editorRefs) {
                        IEditorPart editor = editorRef.getEditor(false);
                        if (editor instanceof IMultiPageTalendEditor) {
                            IProcess2 process = ((IMultiPageTalendEditor) editor).getProcess();
                            String version = null;
                            for (ItemVersionObject object : JobsOpenedInEditor) {
                                if (object.getItem().getProperty().getId().equals(process.getId())) {
                                    version = object.getNewVersion();
                                    break;
                                }
                            }
                            if (version != null) {
                                String jobDefaultVersion = MavenVersionUtils.getDefaultVersion(process.getProperty().getVersion());
                                if (version.equals(jobDefaultVersion)) {
                                    // if default, set null to remove key from property.
                                    version = null;
                                }
                                Command command = service.crateMavenDeploymentValueChangeCommand(process, MavenConstants.NAME_USER_VERSION, version);
                                if (process instanceof IGEFProcess) {
                                    service.executeCommand((IGEFProcess) process, command);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    final IWorkspaceRunnable runnable = new IWorkspaceRunnable() {

        @Override
        public void run(final IProgressMonitor monitor) throws CoreException {
            RepositoryWorkUnit<Object> rwu = new //$NON-NLS-1$
            RepositoryWorkUnit<Object>(//$NON-NLS-1$
            project, //$NON-NLS-1$
            "Update items Maven version") {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    //$NON-NLS-1$
                    monitor.beginTask("Update items Maven version", closedJobs.size());
                    for (ItemVersionObject object : closedJobs) {
                        final Item item = object.getItem();
                        Property itemProperty = item.getProperty();
                        MavenVersionUtils.setItemMavenVersion(itemProperty, object.getNewVersion());
                        monitor.subTask(itemProperty.getLabel());
                        FACTORY.save(project, itemProperty);
                        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 ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, iRunnableWithProgress);
    } catch (InvocationTargetException | InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IMultiPageTalendEditor(org.talend.designer.core.IMultiPageTalendEditor) Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IEditorReference(org.eclipse.ui.IEditorReference) Property(org.talend.core.model.properties.Property) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) IEditorPart(org.eclipse.ui.IEditorPart) InvocationTargetException(java.lang.reflect.InvocationTargetException) IGEFProcess(org.talend.core.ui.process.IGEFProcess) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Command(org.eclipse.gef.commands.Command) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ItemVersionObject(org.talend.repository.model.ItemVersionObject) ItemVersionObject(org.talend.repository.model.ItemVersionObject)

Example 99 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project tdi-studio-se by Talend.

the class StatusManagerSettingPage method updateItemsVersion.

private void updateItemsVersion() {
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            //$NON-NLS-1$
            monitor.beginTask("", getModifiedVersionItems().size() * 100);
            Set<ERepositoryObjectType> types = new HashSet<ERepositoryObjectType>();
            for (RepositoryObject object : getModifiedVersionItems()) {
                // IRepositoryViewObject repositoryObject = object.getRepositoryNode().getObject();
                if (object != null && object.getProperty() != null) {
                    if (object.getStatusCode().equals(object.getProperty().getStatusCode())) {
                        final Item item = object.getProperty().getItem();
                        item.getProperty().setOldStatusCode(object.getStatusCode());
                        // types.add(object.getRepositoryNode().getObjectType());
                        try {
                            // }
                            if (object != null) {
                                // obj.setVersion(object.getNewVersion());
                                FACTORY.save(project, object.getProperty());
                            } else {
                            // FACTORY.save(project, item.getProperty());
                            }
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                    }
                }
                monitor.worked(100);
            }
            // RepositoryManager.refresh(types);
            monitor.done();
        }
    };
    // final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(null);
    final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
    try {
        dialog.run(false, false, runnable);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Item(org.talend.core.model.properties.Item) TableItem(org.eclipse.swt.widgets.TableItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RepositoryObject(org.talend.core.model.repository.RepositoryObject) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) PersistenceException(org.talend.commons.exception.PersistenceException) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) HashSet(java.util.HashSet)

Example 100 with InvocationTargetException

use of java.lang.reflect.InvocationTargetException in project tdi-studio-se by Talend.

the class ExtractDocumentationAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
protected void doRun() {
    RepositoryNode node = (RepositoryNode) ((IStructuredSelection) getSelection()).getFirstElement();
    final Item item = node.getObject().getProperty().getItem();
    if (item == null) {
        return;
    }
    String initialFileName = null;
    String initialExtension = null;
    if (item instanceof DocumentationItem) {
        DocumentationItem documentationItem = (DocumentationItem) item;
        initialFileName = documentationItem.getName();
        if (documentationItem.getExtension() != null) {
            initialExtension = documentationItem.getExtension();
        }
    } else if (item instanceof LinkDocumentationItem) {
        // link documenation
        LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
        if (!LinkUtils.validateLink(linkDocItem.getLink())) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), Messages.getString(//$NON-NLS-1$
            "ExtractDocumentationAction.fileErrorTitle"), //$NON-NLS-1$
            Messages.getString("ExtractDocumentationAction.fileErrorMessages"));
            return;
        }
        initialFileName = linkDocItem.getName();
        if (linkDocItem.getExtension() != null) {
            initialExtension = linkDocItem.getExtension();
        }
    }
    if (initialFileName != null) {
        FileDialog fileDlg = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
        if (initialExtension != null) {
            //$NON-NLS-1$
            initialFileName = initialFileName + LinkUtils.DOT + initialExtension;
            //$NON-NLS-1$ //$NON-NLS-2$
            fileDlg.setFilterExtensions(new String[] { "*." + initialExtension, "*.*" });
        }
        fileDlg.setFileName(initialFileName);
        String filename = fileDlg.open();
        if (filename != null) {
            final File file = new File(filename);
            ProgressDialog progressDialog = new ProgressDialog(Display.getCurrent().getActiveShell()) {

                @Override
                public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                    try {
                        if (item instanceof DocumentationItem) {
                            DocumentationItem documentationItem = (DocumentationItem) item;
                            documentationItem.getContent().setInnerContentToFile(file);
                        } else if (item instanceof LinkDocumentationItem) {
                            // link documenation
                            LinkDocumentationItem linkDocItem = (LinkDocumentationItem) item;
                            ByteArray byteArray = LinkDocumentationHelper.getLinkItemContent(linkDocItem);
                            if (byteArray != null) {
                                byteArray.setInnerContentToFile(file);
                            }
                        }
                    } catch (IOException ioe) {
                        MessageBoxExceptionHandler.process(ioe);
                    }
                }
            };
            try {
                progressDialog.executeProcess();
            } catch (InvocationTargetException e) {
                ExceptionHandler.process(e);
            } catch (InterruptedException e) {
            // Nothing to do
            }
        }
    }
}
Also used : LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) IOException(java.io.IOException) RepositoryNode(org.talend.repository.model.RepositoryNode) BinRepositoryNode(org.talend.repository.model.BinRepositoryNode) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Item(org.talend.core.model.properties.Item) DocumentationItem(org.talend.core.model.properties.DocumentationItem) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ByteArray(org.talend.core.model.properties.ByteArray) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)4781 Method (java.lang.reflect.Method)2031 IOException (java.io.IOException)550 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)492 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)407 ArrayList (java.util.ArrayList)402 List (java.util.List)248 CoreException (org.eclipse.core.runtime.CoreException)247 File (java.io.File)238 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)236 Constructor (java.lang.reflect.Constructor)233 Field (java.lang.reflect.Field)220 Test (org.junit.Test)209 Map (java.util.Map)205 HashMap (java.util.HashMap)202 DBException (org.jkiss.dbeaver.DBException)169 IStatus (org.eclipse.core.runtime.IStatus)136 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)97 Arrays (java.util.Arrays)96 Status (org.eclipse.core.runtime.Status)94