Search in sources :

Example 31 with ProgressMonitorDialog

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

the class DatabaseStatusEditor method execTask.

/**
	 *
	 * Execute the tasks
	 *
	 * @param buttonId the button id
	 * @param tasks the tasks array
	 * @param cancelable whether can be cancelled
	 */
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 {
                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 32 with ProgressMonitorDialog

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

the class VolumeInformationEditor 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 {
                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 33 with ProgressMonitorDialog

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

the class UnifyHostConfigEditor method loadData.

/**
	 * load edit data
	 */
public void loadData() {
    if (editorInput.getTaskCountValue() == 0) {
        return;
    }
    try {
        ProgressMonitorDialog progress = new ProgressMonitorDialog(getSite().getShell());
        progress.setCancelable(false);
        progress.run(true, true, new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException {
                monitor.beginTask(Messages.unifyHostConfigEditorLoadingDataMsg, editorInput.getTaskCountValue());
                unifyHostConfigUtil = new UnifyHostConfigUtil();
                for (CubridServer cubridServer : editorInput.getCubridServers()) {
                    if (editorInput.isEditCubridConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "cubrid.conf", cubridServer.getName()));
                        GetCubridConfParameterTask getCubridConfParameterTask = new GetCubridConfParameterTask(cubridServer.getServerInfo());
                        getCubridConfParameterTask.execute();
                        if (getCubridConfParameterTask.isSuccess()) {
                            List<String> contentsList = getCubridConfParameterTask.getConfContents();
                            StringBuilder contentBuilder = new StringBuilder();
                            for (String content : contentsList) {
                                contentBuilder.append(content).append(StringUtil.NEWLINE);
                            }
                            CubridConfConfig cubridConfConfig = unifyHostConfigUtil.parseStringLineToCubridConfConfig(contentBuilder.toString());
                            cubridConfConfigDataMap.put(cubridServer.getName(), cubridConfConfig);
                            monitor.worked(1);
                        }
                    }
                    if (editorInput.isEditBrokerConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "broker", cubridServer.getName()));
                        GetBrokerConfParameterTask getBrokerConfParameterTask = new GetBrokerConfParameterTask(cubridServer.getServerInfo());
                        getBrokerConfParameterTask.execute();
                        if (getBrokerConfParameterTask.isSuccess()) {
                            List<String> contentsList = getBrokerConfParameterTask.getConfContents();
                            StringBuilder contentBuilder = new StringBuilder();
                            for (String content : contentsList) {
                                contentBuilder.append(content).append(StringUtil.NEWLINE);
                            }
                            BrokerConfig cubridBrokerConfig = cubridBrokerConfUtil.parseStringLineToBrokerConfig(contentBuilder.toString());
                            cubridBrokerConfigDataMap.put(cubridServer.getName(), cubridBrokerConfig);
                            monitor.worked(1);
                        }
                    }
                    if (editorInput.isEditCMConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "cm.conf", cubridServer.getName()));
                        GetCMConfParameterTask getCMConfParameterTask = new GetCMConfParameterTask(cubridServer.getServerInfo());
                        getCMConfParameterTask.execute();
                        if (getCMConfParameterTask.isSuccess()) {
                            List<String> contentsList = getCMConfParameterTask.getConfContents();
                            StringBuilder contentBuilder = new StringBuilder();
                            for (String content : contentsList) {
                                contentBuilder.append(content).append(StringUtil.NEWLINE);
                            }
                            CubridCMConfConfig cubridCMConfConfig = unifyHostConfigUtil.parseStringLineToCubridCMConfConfig(contentBuilder.toString());
                            cubridConfCMConfigDataMap.put(cubridServer.getName(), cubridCMConfConfig);
                        //								System.out.println(contentBuilder.toString());
                        }
                        monitor.worked(1);
                    }
                    if (editorInput.isEditHAConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "cubrid_ha.conf", cubridServer.getName()));
                        monitor.worked(1);
                    }
                    if (editorInput.isEditACLConf()) {
                        monitor.subTask(Messages.bind(Messages.unifyHostConfigEditorLoadingDataMsg2, "acl", cubridServer.getName()));
                        monitor.worked(1);
                    }
                }
            }
        });
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) GetCubridConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCubridConfParameterTask) CubridServer(com.cubrid.common.ui.spi.model.CubridServer) UnifyHostConfigUtil(com.cubrid.cubridmanager.ui.spi.util.UnifyHostConfigUtil) InvocationTargetException(java.lang.reflect.InvocationTargetException) CubridConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridConfConfig) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) GetCMConfParameterTask(com.cubrid.cubridmanager.core.common.task.GetCMConfParameterTask) List(java.util.List) ArrayList(java.util.ArrayList) GetBrokerConfParameterTask(com.cubrid.cubridmanager.core.broker.task.GetBrokerConfParameterTask) CubridCMConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridCMConfConfig)

Example 34 with ProgressMonitorDialog

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

the class BackupErrLogDialog method connect.

/**
	 * connect
	 * 
	 * @param buttonId int
	 * @param tasks SocketTask[]
	 * @param cancelable boolean
	 * @param shell Shell
	 */
public void connect(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 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(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 35 with ProgressMonitorDialog

use of org.eclipse.jface.dialogs.ProgressMonitorDialog in project dbeaver by serge-rider.

the class DBeaverUI method runInProgressDialog.

/**
     * Runs task in Eclipse progress dialog.
     * NOTE: this call can't be canceled if it will block in IO
     */
public static void runInProgressDialog(final DBRRunnableWithProgress runnable) throws InvocationTargetException {
    try {
        IRunnableContext runnableContext;
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
        if (workbenchWindow != null) {
            runnableContext = new ProgressMonitorDialog(workbench.getActiveWorkbenchWindow().getShell());
        } else {
            runnableContext = workbench.getProgressService();
        }
        runnableContext.run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                runnable.run(RuntimeUtils.makeMonitor(monitor));
            }
        });
    } catch (InterruptedException e) {
    // do nothing
    }
}
Also used : IRunnableContext(org.eclipse.jface.operation.IRunnableContext) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)315 InvocationTargetException (java.lang.reflect.InvocationTargetException)250 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)241 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)207 CoreException (org.eclipse.core.runtime.CoreException)79 IOException (java.io.IOException)68 ArrayList (java.util.ArrayList)66 Shell (org.eclipse.swt.widgets.Shell)55 PartInitException (org.eclipse.ui.PartInitException)49 List (java.util.List)44 HashMap (java.util.HashMap)41 IResource (org.eclipse.core.resources.IResource)38 WorkspaceModifyOperation (org.eclipse.ui.actions.WorkspaceModifyOperation)37 LinkedHashMap (java.util.LinkedHashMap)34 Display (org.eclipse.swt.widgets.Display)32 EventObject (java.util.EventObject)30 BasicCommandStack (org.eclipse.emf.common.command.BasicCommandStack)30 Resource (org.eclipse.emf.ecore.resource.Resource)30 IFile (org.eclipse.core.resources.IFile)25 File (java.io.File)23