Search in sources :

Example 1 with EventLoopProgressMonitor

use of org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor 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 2 with EventLoopProgressMonitor

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

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

use of org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor 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 5 with EventLoopProgressMonitor

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

the class SchemaXMLLinker method createLinks.

/**
     * amaumont Comment 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 = xmlViewer.getTree().getItem(0);
            //
            List<HL7TreeNode> mappableNodes = new ArrayList<HL7TreeNode>();
            if (getManager().getHl7Component().isHL7Output()) {
                if (getManager() instanceof HL7OutputManager) {
                    //$NON-NLS-1$
                    mappableNodes = ((HL7OutputManager) getManager()).getTreeData("");
                    createLoopLinks(mappableNodes);
                    xmlViewer.refresh();
                    getBackgroundRefresher().refreshBackground();
                }
            } else {
                List<TreeItem> allItems = TreeUtils.collectAllItems(root);
                monitorWrap = new EventLoopProgressMonitor(monitor);
                //$NON-NLS-1$
                String taskName = Messages.getString("XmlToXPathLinker.Loop");
                int totalWork = allItems.size();
                monitorWrap.beginTask(taskName, totalWork);
                for (int i = 0; i < totalWork; i++) {
                    if (monitorWrap.isCanceled()) {
                        return;
                    }
                    TreeItem treeItem = allItems.get(i);
                    HL7TreeNode node = (HL7TreeNode) treeItem.getData();
                    if (node.getColumn() == null) {
                        continue;
                    }
                    // add now parameter for bug 9279
                    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) {
        // Nothing to do
        ExceptionHandler.process(e);
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) ArrayList(java.util.ArrayList) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) HL7TreeNode(org.talend.designer.hl7.ui.data.HL7TreeNode) HL7OutputManager(org.talend.designer.hl7.managers.HL7OutputManager)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)9 EventLoopProgressMonitor (org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor)9 ProgressDialog (org.talend.commons.ui.swt.dialogs.ProgressDialog)8 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 TreeItem (org.eclipse.swt.widgets.TreeItem)2 TarException (org.eclipse.ui.internal.wizards.datatransfer.TarException)2 SchemaTarget (org.talend.repository.model.json.SchemaTarget)2 FileNotFoundException (java.io.FileNotFoundException)1 MessageFormat (java.text.MessageFormat)1 Date (java.util.Date)1 ZipException (java.util.zip.ZipException)1 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 Display (org.eclipse.swt.widgets.Display)1