Search in sources :

Example 66 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.

the class TransactionInfoDialog method execTask.

/**
	 *
	 * Execute tasks
	 *
	 * @param buttonId the button id
	 * @param tasks the tasks array
	 * @param cancelable whether it is cancelable
	 * @param shell the shell
	 */
public void execTask(final int buttonId, final SocketTask[] tasks, boolean cancelable, Shell shell) {
    final Display display = shell.getDisplay();
    isRunning = false;
    try {
        new ProgressMonitorDialog(getShell()).run(true, cancelable, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                // FIXME more simple
                monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    return;
                }
                isRunning = true;
                Thread thread = new Thread() {

                    public void run() {
                        while (!monitor.isCanceled() && isRunning) {
                            try {
                                sleep(1);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (monitor.isCanceled()) {
                            for (SocketTask t : tasks) {
                                if (t != null) {
                                    t.cancel();
                                }
                            }
                        }
                    }
                };
                thread.start();
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                for (SocketTask task : tasks) {
                    if (task != null) {
                        task.execute();
                        final String msg = task.getErrorMsg();
                        if (monitor.isCanceled()) {
                            isRunning = false;
                            return;
                        }
                        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                            display.syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openErrorBox(getShell(), msg);
                                }
                            });
                            isRunning = false;
                            return;
                        }
                    }
                    if (monitor.isCanceled()) {
                        isRunning = false;
                        return;
                    }
                }
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                if (!monitor.isCanceled()) {
                    display.syncExec(new Runnable() {

                        public void run() {
                            if (buttonId > 0) {
                                setReturnCode(buttonId);
                                close();
                            }
                        }
                    });
                }
                isRunning = false;
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 67 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.

the class LockInfoDialog method execTask.

/**
	 * 
	 * Execute the task
	 * 
	 * @param buttonId the button id
	 * @param tasks the task array
	 * @param cancelable whether it is cancelable
	 * @param shell the shell
	 */
public void execTask(final int buttonId, final SocketTask[] tasks, boolean cancelable, Shell shell) {
    final Display display = shell.getDisplay();
    isRunning = false;
    try {
        new ProgressMonitorDialog(getShell()).run(true, cancelable, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    return;
                }
                isRunning = true;
                Thread thread = new Thread() {

                    public void run() {
                        while (!monitor.isCanceled() && isRunning) {
                            try {
                                sleep(1);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (monitor.isCanceled()) {
                            for (SocketTask task : tasks) {
                                if (task != null) {
                                    task.cancel();
                                }
                            }
                        }
                    }
                };
                thread.start();
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                for (SocketTask task : tasks) {
                    if (task != null) {
                        task.execute();
                        final String msg = task.getErrorMsg();
                        if (monitor.isCanceled()) {
                            isRunning = false;
                            return;
                        }
                        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                            showErrorMessage(display, msg);
                            isRunning = false;
                            return;
                        }
                    }
                    if (monitor.isCanceled()) {
                        isRunning = false;
                        return;
                    }
                }
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                if (!monitor.isCanceled()) {
                    display.syncExec(new Runnable() {

                        public void run() {
                            if (buttonId > 0) {
                                setReturnCode(buttonId);
                                close();
                            }
                        }
                    });
                }
                isRunning = false;
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 68 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.

the class OpenJobAutomationInfoPartProgress method loadJobAutomationInfoList.

/**
	 * load loadJobAutomationInfoList list
	 *
	 * @return Catalog
	 */
public void loadJobAutomationInfoList() {
    Display display = Display.getDefault();
    display.syncExec(new Runnable() {

        public void run() {
            try {
                new ProgressMonitorDialog(null).run(true, false, OpenJobAutomationInfoPartProgress.this);
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
            }
        }
    });
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display)

Example 69 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project cubrid-manager by CUBRID.

the class VolumeFolderInfoEditor method execTask.

/**
	 * execute the task
	 *
	 * @param buttonId int
	 * @param tasks SocketTask[]
	 * @param cancelable boolean
	 */
public void execTask(final int buttonId, final SocketTask[] tasks, boolean cancelable) {
    final Shell shell = parentComp.getShell();
    final Display display = shell.getDisplay();
    isRunning = false;
    try {
        new ProgressMonitorDialog(shell).run(true, cancelable, new IRunnableWithProgress() {

            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                // FIXME more simple
                monitor.beginTask(com.cubrid.common.ui.spi.Messages.msgRunning, IProgressMonitor.UNKNOWN);
                if (monitor.isCanceled()) {
                    return;
                }
                isRunning = true;
                Thread thread = new Thread() {

                    public void run() {
                        while (!monitor.isCanceled() && isRunning) {
                            try {
                                sleep(1);
                            } catch (InterruptedException e) {
                            }
                        }
                        if (monitor.isCanceled()) {
                            for (SocketTask t : tasks) {
                                if (t != null) {
                                    t.cancel();
                                }
                            }
                        }
                    }
                };
                thread.start();
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                for (SocketTask task : tasks) {
                    if (task != null) {
                        task.execute();
                        final String msg = task.getErrorMsg();
                        if (monitor.isCanceled()) {
                            isRunning = false;
                            return;
                        }
                        if (msg != null && msg.length() > 0 && !monitor.isCanceled()) {
                            display.syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openErrorBox(shell, msg);
                                }
                            });
                            isRunning = false;
                            return;
                        }
                    }
                    if (monitor.isCanceled()) {
                        isRunning = false;
                        return;
                    }
                }
                if (monitor.isCanceled()) {
                    isRunning = false;
                    return;
                }
                isRunning = false;
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SocketTask(com.cubrid.cubridmanager.core.common.socket.SocketTask) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) Display(org.eclipse.swt.widgets.Display) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 70 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project tdi-studio-se by Talend.

the class ComponentsPreferencePage method performOk.

@Override
public boolean performOk() {
    boolean flag = super.performOk();
    String newPath = CodeGeneratorActivator.getDefault().getPreferenceStore().getString(IComponentPreferenceConstant.USER_COMPONENTS_FOLDER);
    if ("".equals(oldPath)) {
        //$NON-NLS-1$
        oldPath = null;
    }
    if ("".equals(newPath)) {
        //$NON-NLS-1$
        newPath = null;
    }
    DesignerPlugin.getDefault().getPreferenceStore().setValue(TalendDesignerPrefConstants.COMPONENT_ASSIST, enableComponentAssistCheckBoxField.getBooleanValue());
    TalendEditorComponentCreationUtil.updateAssistListener();
    if (this.oldPath != newPath) {
        final IRunnableWithProgress runnable = new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                //$NON-NLS-1$
                monitor.beginTask("Loading user component ......", 100);
                Display display = Display.getCurrent();
                if (display == null) {
                    display = Display.getDefault();
                }
                if (display != null) {
                    display.syncExec(new Runnable() {

                        @Override
                        public void run() {
                            // install the new components via P2
                            ComponentsInstallComponent component = LocalComponentInstallHelper.getComponent();
                            if (component != null) {
                                String newPath = CodeGeneratorActivator.getDefault().getPreferenceStore().getString(IComponentPreferenceConstant.USER_COMPONENTS_FOLDER);
                                if (newPath != null && StringUtils.isNotEmpty(newPath.trim())) {
                                    File componentFolder = new File(newPath.trim());
                                    if (componentFolder.exists()) {
                                        try {
                                            component.setComponentFolder(componentFolder);
                                            if (component.install()) {
                                                String installedMessages = component.getInstalledMessages();
                                                //$NON-NLS-1$
                                                String title = Messages.getString("ComponentsPreferencePage_SuccessTitle");
                                                if (component.needRelaunch()) {
                                                    String warningMessage = Messages.getString(//$NON-NLS-1$
                                                    "ComponentsPreferencePage_SuccessMessage1") + //$NON-NLS-1$
                                                    Messages.getString("ComponentsPreferencePage_SuccessMessage2");
                                                    boolean confirm = MessageDialog.openConfirm(getShell(), title, installedMessages + '\n' + '\n' + warningMessage);
                                                    if (confirm) {
                                                        PlatformUI.getWorkbench().restart();
                                                    }
                                                } else {
                                                    MessageDialog.openInformation(getShell(), title, installedMessages);
                                                }
                                            }
                                        } finally {
                                            // after install, clear the setting for service.
                                            component.setComponentFolder(null);
                                        }
                                    }
                                }
                            }
                            // components will be reloaded when refreshTemplates;
                            // IComponentsFactory components = ComponentsFactoryProvider.getInstance();
                            // components.loadUserComponentsFromComponentsProviderExtension();
                            CorePlugin.getDefault().getLibrariesService().resetModulesNeeded();
                            monitor.worked(50);
                            // ComponentUtilities.updatePalette();
                            ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
                            service.refreshTemplates();
                        }
                    });
                }
            }
        };
        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(null);
        try {
            dialog.run(true, true, runnable);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
            ExceptionHandler.process(e);
        }
        this.oldPath = newPath;
    }
    return flag;
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ComponentsInstallComponent(org.talend.commons.runtime.service.ComponentsInstallComponent) File(java.io.File) Display(org.eclipse.swt.widgets.Display)

Aggregations

ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)88 InvocationTargetException (java.lang.reflect.InvocationTargetException)81 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)74 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)74 ArrayList (java.util.ArrayList)27 Display (org.eclipse.swt.widgets.Display)22 CoreException (org.eclipse.core.runtime.CoreException)17 PersistenceException (org.talend.commons.exception.PersistenceException)17 List (java.util.List)15 Shell (org.eclipse.swt.widgets.Shell)12 PartInitException (org.eclipse.ui.PartInitException)12 IFile (org.eclipse.core.resources.IFile)11 SQLException (java.sql.SQLException)10 IOException (java.io.IOException)9 HashMap (java.util.HashMap)9 SocketTask (com.cubrid.cubridmanager.core.common.socket.SocketTask)8 File (java.io.File)8 Item (org.talend.core.model.properties.Item)8 IProject (org.eclipse.core.resources.IProject)7 TableItem (org.eclipse.swt.widgets.TableItem)7