Search in sources :

Example 6 with ProgressDialog

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

the class AbstractPreferenceComposite method addButtonListeners.

private void addButtonListeners() {
    reloadBtn.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            onReloadButtonClick();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    saveBtn.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            onSaveButtonClick();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }
    });
    if (hasRunJobNode(false) && needApplyToChildren()) {
        applyToChildrenJob.addSelectionListener(new SelectionListener() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see
                 * org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetDefaultSelected(SelectionEvent e) {
            }

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                // zli for bug 12335
                final ProgressDialog progress = new ProgressDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()) {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                        IEditorReference[] editorReferences = activePage.getEditorReferences();
                        CorePlugin defaultPlugin = CorePlugin.getDefault();
                        IDesignerCoreService designerCoreService = defaultPlugin.getDesignerCoreService();
                        List<IProcess2> openedProcessList = designerCoreService.getOpenedProcess(RepositoryUpdateManager.getEditors());
                        List<String> activeProcessId = new ArrayList<String>();
                        for (IProcess process : openedProcessList) {
                            activeProcessId.add(process.getId());
                        }
                        final int rate = 1 / openedProcessList.size() - activeProcessId.size();
                        for (INode runjobNode : tRunJobNodes) {
                            String id = (String) runjobNode.getElementParameter(EParameterName.PROCESS_TYPE_PROCESS.getName()).getValue();
                            String version = (String) runjobNode.getElementParameter(EParameterName.PROCESS_TYPE_VERSION.getName()).getValue();
                            if ("".equals(id) || id == null) {
                                //$NON-NLS-1$
                                MessageDialog.openWarning(getShell(), //$NON-NLS-1$
                                Messages.getString("AbstractPreferenceComposite.warning", runjobNode.getUniqueName()), Messages.getString("AbstractPreferenceComposite.jobAssigned", //$NON-NLS-1$
                                runjobNode.getUniqueName()));
                                return;
                            }
                            if (activeProcessId.contains(id)) {
                                IEditorPart activeEditorPart = activePage.getActiveEditor();
                                for (IEditorReference editorReference : editorReferences) {
                                    IEditorPart editorPart = editorReference.getEditor(false);
                                    if ((editorPart != activeEditorPart) && (editorPart instanceof MultiPageTalendEditor)) {
                                        IElement element = ((MultiPageTalendEditor) editorPart).getProcess();
                                        StatsAndLogsViewHelper.applySettings(elem, element, AbstractPreferenceComposite.this);
                                    }
                                }
                            } else {
                                try {
                                    SubProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1 * UpdatesConstants.SCALE, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                                    subMonitor.beginTask(UpdatesConstants.EMPTY, 1 * rate);
                                    IRepositoryViewObject lastVersion = DesignerPlugin.getDefault().getProxyRepositoryFactory().getLastVersion(id);
                                    if (lastVersion != null) {
                                        Item item = lastVersion.getProperty().getItem();
                                        IProcess processFromItem = designerCoreService.getProcessFromItem(item);
                                        if (processFromItem instanceof Process) {
                                            Process process = (Process) processFromItem;
                                            StatsAndLogsViewHelper.applySettings(elem, process, AbstractPreferenceComposite.this);
                                            IProxyRepositoryFactory factory = defaultPlugin.getProxyRepositoryFactory();
                                            Property property = factory.getUptodateProperty(process.getProperty());
                                            process.setProperty(property);
                                            subMonitor.subTask(RepositoryUpdateManager.getUpdateJobInfor(process.getProperty()));
                                            ProcessType processType = process.saveXmlFile();
                                            Item item2 = process.getProperty().getItem();
                                            if (item2 instanceof JobletProcessItem) {
                                                ((JobletProcessItem) item2).setJobletProcess((JobletProcess) processType);
                                            } else {
                                                ((ProcessItem) item2).setProcess(processType);
                                            }
                                            factory.save(item2);
                                            subMonitor.done();
                                        }
                                    }
                                } catch (PersistenceException e1) {
                                    e1.printStackTrace();
                                } catch (IOException e2) {
                                    e2.printStackTrace();
                                }
                            }
                            applySettingsToSubJob(id, version);
                        }
                    }
                };
                try {
                    progress.executeProcess();
                } catch (InvocationTargetException e1) {
                    e1.printStackTrace();
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            }

            /**
                 * yzhang Comment method "applySettingsToSubJob".
                 * 
                 * @param id
                 * @param version
                 */
            private void applySettingsToSubJob(String id, String version) {
                final ProcessItem processItem = ItemCacheManager.getProcessItem(id, version);
                if (processItem == null) {
                    return;
                }
                ProcessType processType = processItem.getProcess();
                EList<ElementParameterType> parameters = processType.getParameters().getElementParameter();
                StatsAndLogsViewHelper.applySettings(parameters, elem);
                List<NodeType> nodes = findRunJobNode(processType.getNode());
                for (NodeType nodeType : nodes) {
                    EList<ElementParameterType> list = nodeType.getElementParameter();
                    ElementParameterType idParam = getElementParameterType(list, //$NON-NLS-1$
                    PROCESS + ":" + EParameterName.PROCESS_TYPE_PROCESS.getName());
                    ElementParameterType versionParam = getElementParameterType(list, //$NON-NLS-1$
                    PROCESS + ":" + EParameterName.PROCESS_TYPE_VERSION.getName());
                    String subId = idParam.getValue();
                    String subVersion = versionParam.getValue();
                    applySettingsToSubJob(subId, subVersion);
                }
            }
        });
    }
}
Also used : INode(org.talend.core.model.process.INode) MultiPageTalendEditor(org.talend.designer.core.ui.MultiPageTalendEditor) IProcess(org.talend.core.model.process.IProcess) Process(org.talend.designer.core.ui.editor.process.Process) JobletProcess(org.talend.designer.joblet.model.JobletProcess) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) JobletProcess(org.talend.designer.joblet.model.JobletProcess) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IEditorReference(org.eclipse.ui.IEditorReference) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IElement(org.talend.core.model.process.IElement) IEditorPart(org.eclipse.ui.IEditorPart) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) CorePlugin(org.talend.core.CorePlugin) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 7 with ProgressDialog

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

the class Schema2XMLLinker 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) {
            List<FOXTreeNode> treeData = getManager().getTreeData(getManager().getCurrentSchema());
            createLoopLinks(treeData);
            getBackgroundRefresher().refreshBackground();
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        // Nothing to do
        ExceptionHandler.process(e);
    }
}
Also used : FOXTreeNode(org.talend.metadata.managment.ui.wizard.metadata.xml.node.FOXTreeNode) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with ProgressDialog

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

Example 9 with ProgressDialog

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

the class JSONToXPathLinker method handleListenableListAfterTableViewerRefreshedEvent.

public void handleListenableListAfterTableViewerRefreshedEvent(final ListenableListEvent<SchemaTarget> event) {
    if (event.type == ListenableListEvent.TYPE.ADDED) {
        ProgressDialog progressDialog = new ProgressDialog(getTree().getShell(), 1000) {

            private IProgressMonitor monitorWrap;

            @Override
            public void run(IProgressMonitor monitor) {
                monitorWrap = new EventLoopProgressMonitor(monitor);
                List<SchemaTarget> addedObjects = new ArrayList<SchemaTarget>(event.addedObjects);
                JSONToXPathLinker.this.createFieldsLinkWithProgressMonitor(monitorWrap, addedObjects.size(), addedObjects, event.index, addedObjects.size());
                monitorWrap.done();
            }
        };
        try {
            progressDialog.executeProcess();
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        // Nothing to do
        }
        getBackgroundRefresher().refreshBackground();
    } else if (event.type == ListenableListEvent.TYPE.SWAPED) {
        getBackgroundRefresher().refreshBackground();
    } else if (event.type == TYPE.REMOVED) {
        getBackgroundRefresher().refreshBackground();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ArrayList(java.util.ArrayList) 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)

Example 10 with ProgressDialog

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

the class ImportDemoProjectItemsPage method performFinish.

public boolean performFinish() {
    List<DemoProjectBean> checkedElements = getCheckedElements();
    final List<ResourcesManager> finalCheckManagers = getResourceManagers(checkedElements);
    String warnMessage = populateExistItemRecords(finalCheckManagers);
    if (!warnMessage.equals("")) {
        MessageDialog dialog = new MessageDialog(getShell(), Messages.getString("ImportDemoProjectPage.overwrite"), null, warnMessage, MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
        dialog.open();
        int result = dialog.getReturnCode();
        if (result != MessageDialog.OK) {
            return false;
        }
    }
    ProgressDialog progressDialog = new ProgressDialog(getShell()) {

        private IProgressMonitor monitorWrap;

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            monitorWrap = new EventLoopProgressMonitor(monitor);
            try {
                for (ResourcesManager resManager : finalCheckManagers) {
                    List<ImportItem> projectRecords = importManager.populateImportingItems(resManager, true, monitorWrap);
                    // clearOverWriteErrorMessages(projectRecords, overwrite);
                    importManager.importItemRecords(monitorWrap, resManager, projectRecords, true, projectRecords.toArray(new ImportItem[0]), null);
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
            monitorWrap.done();
            if (monitor.isCanceled()) {
                MessageDialog.openInformation(getShell(), Messages.getString("ImportDemoProjectAction.messageDialogTitle.demoProjectCancel"), Messages.getString("ImportDemoProjectAction.messageDialogContent.demoProjectImportedIncompletely"));
                return;
            } else {
                MessageDialog.openInformation(getShell(), //$NON-NLS-1$
                Messages.getString("ImportDemoProjectAction.messageDialogTitle.demoProject"), //$NON-NLS-1$
                Messages.getString("ImportDemoProjectAction.messageDialogContent.demoProjectImportedSuccessfully"));
            }
        }
    };
    try {
        progressDialog.executeProcess();
    } catch (InvocationTargetException e) {
        MessageBoxExceptionHandler.process(e.getTargetException(), getShell());
    } catch (InterruptedException e) {
    // Nothing to do
    }
    return true;
}
Also used : ImportItem(org.talend.repository.items.importexport.handlers.model.ImportItem) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) ProgressDialog(org.talend.commons.ui.swt.dialogs.ProgressDialog) ZipException(java.util.zip.ZipException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ResourcesManager(org.talend.repository.items.importexport.manager.ResourcesManager) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

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