Search in sources :

Example 1 with ProgressDialog

use of org.talend.commons.ui.swt.dialogs.ProgressDialog in project tdi-studio-se by Talend.

the class MultipleThreadDynamicComposite method updateRepositoryList.

public void updateRepositoryList() {
    ProgressDialog progressDialog = new ProgressDialog(this.getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitorWrap = new EventLoopProgressMonitor(monitor);
            IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
            List<IRepositoryViewObject> repositoryObjects = getAllRepositoryMetadata();
            // + elem.getElementParameters().size();
            int total = repositoryObjects.size();
            //$NON-NLS-1$
            monitorWrap.beginTask(Messages.getString("MultipleThreadDynamicComposite.gatherInformation"), total);
            IElementParameter propertyParam = elem.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, section);
            String repositoryValue = null;
            if (propertyParam != null) {
                repositoryValue = propertyParam.getRepositoryValue();
            }
            if (repositoryObjects != null && (repositoryObjects.size() != 0)) {
                tableIdAndDbTypeMap.clear();
                tableIdAndDbSchemaMap.clear();
                for (IRepositoryViewObject curObject : repositoryObjects) {
                    Item item = curObject.getProperty().getItem();
                    if (item instanceof ConnectionItem) {
                        ConnectionItem connectionItem = (ConnectionItem) item;
                        Connection connection = connectionItem.getConnection();
                        if (connection == null || connection.isReadOnly()) {
                            continue;
                        }
                        for (Object tableObj : ConnectionHelper.getTables(connection)) {
                            org.talend.core.model.metadata.builder.connection.MetadataTable table;
                            table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
                            if (factory.getStatus(connectionItem) != ERepositoryStatus.DELETED) {
                                if (!factory.isDeleted(table)) {
                                    IMetadataTable newTable = ConvertionHelper.convert(table);
                                    // newTable);
                                    if (connection instanceof DatabaseConnection) {
                                        String dbType = ((DatabaseConnection) connection).getDatabaseType();
                                        String schema = ((DatabaseConnection) connection).getUiSchema();
                                        tableIdAndDbTypeMap.put(newTable.getId(), dbType);
                                        if (schema != null && !schema.equals("")) {
                                            //$NON-NLS-1$
                                            tableIdAndDbSchemaMap.put(newTable.getId(), schema);
                                        }
                                    }
                                }
                            }
                        }
                        monitorWrap.worked(1);
                    }
                    // hywang add for feature 6484
                    if (item instanceof FileItem) {
                        FileItem FileItem = (FileItem) item;
                        if (repositoryValue != null) {
                            if (repositoryValue.equals("RULE")) {
                                //$NON-NLS-1$
                                repositoryFileItemMap.put(FileItem.getProperty().getId(), FileItem);
                            }
                        }
                        monitorWrap.worked(1);
                    }
                    if (item instanceof LinkRulesItem) {
                        LinkRulesItem linkItem = (LinkRulesItem) item;
                        if (repositoryValue != null) {
                            if (repositoryValue.equals("RULE")) {
                                //$NON-NLS-1$
                                repositoryLinkRulesItemMap.put(linkItem.getProperty().getId(), linkItem);
                            }
                        }
                        monitorWrap.worked(1);
                    }
                }
            }
            monitorWrap.done();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
        return;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return;
    }
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) FileItem(org.talend.core.model.properties.FileItem) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 2 with ProgressDialog

use of org.talend.commons.ui.swt.dialogs.ProgressDialog in project tdi-studio-se by Talend.

the class JSONToXPathLinker method createLinks.

/**
     * DOC amaumont Comment method "createLinks".
     */
public void createLinks() {
    removeAllLinks();
    getBackgroundRefresher().refreshBackground();
    ProgressDialog progressDialog = new ProgressDialog(getTree().getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) {
            TableItem[] loopTableItems = loopTableEditorView.getTable().getItems();
            TableItem[] fieldsTableItems = fieldsTableEditorView.getTable().getItems();
            monitorWrap = new EventLoopProgressMonitor(monitor);
            String taskName = "Loop links creation ...";
            int totalWork = loopTableItems.length + fieldsTableItems.length;
            monitorWrap.beginTask(taskName, totalWork);
            List<JSONXPathLoopDescriptor> xpathLoopDescriptorList = loopTableEditorView.getModel().getBeansList();
            for (int i = 0; i < loopTableItems.length; i++) {
                if (monitorWrap.isCanceled()) {
                    return;
                }
                TableItem tableItem = loopTableItems[i];
                JSONXPathLoopDescriptor xpathLoopDescriptor = xpathLoopDescriptorList.get(i);
                String originalValue = xpathLoopDescriptor.getAbsoluteXPathQuery();
                if (xpathLoopDescriptor.getConnection() != null) {
                    ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(xpathLoopDescriptor.getConnection(), xpathLoopDescriptor.getConnection().getContextName());
                    if (contextType != null) {
                        originalValue = ConnectionContextHelper.getOriginalValue(contextType, xpathLoopDescriptor.getAbsoluteXPathQuery());
                        originalValue = TalendQuoteUtils.removeQuotes(originalValue);
                    }
                }
                if (originalValue != null) {
                    createLoopLinks(originalValue, tableItem, monitorWrap);
                }
                monitorWrap.worked(1);
            }
            List<SchemaTarget> schemaTargetList = fieldsTableEditorView.getModel().getBeansList();
            createFieldsLinkWithProgressMonitor(monitorWrap, schemaTargetList.size() + loopTableItems.length, schemaTargetList, 0, fieldsTableItems.length);
            monitorWrap.done();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
    // Nothing to do
    }
}
Also used : JSONXPathLoopDescriptor(org.talend.repository.model.json.JSONXPathLoopDescriptor) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) TableItem(org.eclipse.swt.widgets.TableItem) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) SchemaTarget(org.talend.repository.model.json.SchemaTarget) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 3 with ProgressDialog

use of org.talend.commons.ui.swt.dialogs.ProgressDialog in project tdi-studio-se by Talend.

the class JSONFileSchema2TreeLinker method createLinks.

public void createLinks() {
    removeAllLinks();
    getBackgroundRefresher().refreshBackground();
    ProgressDialog progressDialog = new ProgressDialog(getSource().getShell(), 1000) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) {
            TreeItem root = jsonViewer.getTree().getItem(0);
            // if (getManager().getFoxComponent().istFileOutputMSXML()) {
            // List<FOXTreeNode> treeData = getManager().getTreeData(getManager().getCurrentSchema());
            // if (treeData != null && treeData.size() > 0) {
            // FOXTreeNode rootTreeData = treeData.get(0);
            // for (TreeItem item : xmlViewer.getTree().getItems()) {
            // if (rootTreeData == item.getData()) {
            // root = item;
            // break;
            // }
            // }
            // }
            // }
            List<TreeItem> allItems = TreeUtils.collectAllItems(root);
            monitorWrap = new EventLoopProgressMonitor(monitor);
            String taskName = "Loop links creation ...";
            int totalWork = allItems.size();
            //$NON-NLS-1$
            monitorWrap.beginTask(taskName, totalWork);
            for (int i = 0; i < totalWork; i++) {
                if (monitorWrap.isCanceled()) {
                    return;
                }
                TreeItem treeItem = allItems.get(i);
                FOXTreeNode node = (FOXTreeNode) treeItem.getData();
                if (node.getColumn() == null) {
                    //$NON-NLS-1$
                    continue;
                }
                createLoopLinks(node.getColumn().getLabel(), treeItem, monitorWrap, i == totalWork - 1);
                monitorWrap.worked(1);
            }
            monitorWrap.done();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TreeItem(org.eclipse.swt.widgets.TreeItem) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 4 with ProgressDialog

use of org.talend.commons.ui.swt.dialogs.ProgressDialog 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)

Example 5 with ProgressDialog

use of org.talend.commons.ui.swt.dialogs.ProgressDialog 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)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 ProgressDialog (org.talend.commons.ui.swt.dialogs.ProgressDialog)11 EventLoopProgressMonitor (org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor)8 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)3 Item (org.talend.core.model.properties.Item)3 TreeItem (org.eclipse.swt.widgets.TreeItem)2 TarException (org.eclipse.ui.internal.wizards.datatransfer.TarException)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 List (java.util.List)1 ZipException (java.util.zip.ZipException)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 EList (org.eclipse.emf.common.util.EList)1