Search in sources :

Example 71 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class ChangePasswordDialog method changePassword.

/**
	 * 
	 * Execute task and change password
	 * 
	 * @param buttonId the button id
	 */
private void changePassword(final int buttonId) {
    final String password = newPasswordText.getText();
    TaskExecutor taskExcutor = new TaskExecutor() {

        public boolean exec(final IProgressMonitor monitor) {
            Display display = getShell().getDisplay();
            if (monitor.isCanceled()) {
                return false;
            }
            monitor.beginTask(Messages.changePwdTaskName, IProgressMonitor.UNKNOWN);
            for (ITask task : taskList) {
                task.execute();
                final String msg = task.getErrorMsg();
                if (openErrorBox(getShell(), msg, monitor)) {
                    return false;
                }
                if (monitor.isCanceled()) {
                    return false;
                }
                serverInfo.setUserPassword(password);
                if (serverInfo.getLoginedUserInfo() != null) {
                    serverInfo.getLoginedUserInfo().setPassword(password);
                }
                CMHostNodePersistManager.getInstance().saveServers();
            }
            if (!monitor.isCanceled()) {
                display.syncExec(new Runnable() {

                    public void run() {
                        if (CommonUITool.openConfirmBox(Messages.msgChangePassSuccess)) {
                            setReturnCode(buttonId);
                        } else {
                            setReturnCode(IDialogConstants.CANCEL_ID);
                        }
                        close();
                    }
                });
            }
            return true;
        }
    };
    ChangeCMUserPasswordTask changePasswordTask = new ChangeCMUserPasswordTask(serverInfo);
    changePasswordTask.setUserName(serverInfo.getUserName());
    changePasswordTask.setPassword(password);
    taskExcutor.addTask(changePasswordTask);
    new ExecTaskWithProgress(taskExcutor).exec(true, true);
}
Also used : TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ITask(com.cubrid.common.core.task.ITask) ChangeCMUserPasswordTask(com.cubrid.cubridmanager.core.common.task.ChangeCMUserPasswordTask) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) Display(org.eclipse.swt.widgets.Display)

Example 72 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class UserPasswordInputDialog method main.

public static void main(String[] args) {
    Display display = Display.getDefault();
    UserPasswordInputDialog dialog = new UserPasswordInputDialog(display.getActiveShell());
    dialog.open();
}
Also used : Display(org.eclipse.swt.widgets.Display)

Example 73 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class BackupDatabaseDialog method backupDb.

/**
	 *
	 * Execute task and backup database
	 *
	 * @param buttonId the button id
	 */
private void backupDb(final int buttonId) {
    isCanFinished = true;
    TaskJobExecutor taskExcutor = new TaskJobExecutor() {

        private String backupVolInfo;

        public IStatus exec(final IProgressMonitor monitor) {
            Display display = Display.getDefault();
            display.syncExec(new Runnable() {

                public void run() {
                    getShell().setVisible(false);
                }
            });
            if (monitor.isCanceled()) {
                cancel();
                display.syncExec(new Runnable() {

                    public void run() {
                        setReturnCode(buttonId);
                        close();
                    }
                });
                return Status.CANCEL_STATUS;
            }
            for (ITask task : taskList) {
                if (!(task instanceof GetBackupVolInfoTask) || database.getRunningType() != DbRunningType.CS) {
                    task.execute();
                    final String msg = task.getErrorMsg();
                    if (msg != null && msg.length() > 0 && !monitor.isCanceled() && !isCanceled()) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                getShell().setVisible(true);
                            }
                        });
                        return new Status(IStatus.ERROR, CubridManagerUIPlugin.PLUGIN_ID, msg);
                    }
                }
                if (isCanceled()) {
                    return Status.CANCEL_STATUS;
                }
                if (task instanceof CheckDirTask) {
                    CheckDirTask checkDirTask = (CheckDirTask) task;
                    final String[] dirs = checkDirTask.getNoExistDirectory();
                    if (dirs != null && dirs.length > 0) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                CreateDirDialog dialog = new CreateDirDialog(getShell());
                                dialog.setDirs(dirs);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof CheckFileTask) {
                    CheckFileTask checkFileTask = (CheckFileTask) task;
                    final String[] files = checkFileTask.getExistFiles();
                    if (files != null && files.length > 0) {
                        display.syncExec(new Runnable() {

                            public void run() {
                                OverrideFileDialog dialog = new OverrideFileDialog(getShell());
                                dialog.setFiles(files);
                                if (dialog.open() != IDialogConstants.OK_ID) {
                                    isCanFinished = false;
                                    getShell().setVisible(true);
                                }
                            }
                        });
                    }
                } else if (task instanceof GetBackupVolInfoTask && database.getRunningType() == DbRunningType.STANDALONE) {
                    GetBackupVolInfoTask getBackupVolInfoTask = (GetBackupVolInfoTask) task;
                    backupVolInfo = getBackupVolInfoTask.getDbBackupVolInfo();
                }
                if (!isCanFinished) {
                    return Status.CANCEL_STATUS;
                }
                if (monitor.isCanceled()) {
                    cancel();
                    Display.getDefault().syncExec(new Runnable() {

                        public void run() {
                            close();
                        }
                    });
                    return Status.CANCEL_STATUS;
                }
            }
            return Status.OK_STATUS;
        }

        public void done(IJobChangeEvent event) {
            if (event.getResult() == Status.OK_STATUS) {
                Display.getDefault().syncExec(new Runnable() {

                    public void run() {
                        if (database.getRunningType() == DbRunningType.CS) {
                            Display.getDefault().syncExec(new Runnable() {

                                public void run() {
                                    CommonUITool.openInformationBox(getShell(), Messages.titleSuccess, Messages.msgBackupSuccess);
                                }
                            });
                        } else {
                            if (backupVolInfo != null && backupVolInfo.length() > 0) {
                                Display.getDefault().syncExec(new Runnable() {

                                    public void run() {
                                        BackupDbVolumeInfoDialog backupDbResultInfoDialog = new BackupDbVolumeInfoDialog(getShell());
                                        backupDbResultInfoDialog.setResultInfoStr(backupVolInfo);
                                        backupDbResultInfoDialog.open();
                                    }
                                });
                            }
                        }
                        close();
                    }
                });
            }
        }
    };
    String backupDir = backupDirText.getText();
    CheckDirTask checkDirTask = new CheckDirTask(database.getServer().getServerInfo());
    checkDirTask.setDirectory(new String[] { backupDir });
    CheckFileTask checkFileTask = new CheckFileTask(database.getServer().getServerInfo());
    String fileName = backupDirText.getText() + database.getServer().getServerInfo().getPathSeparator() + volumeNameText.getText();
    checkFileTask.setFile(new String[] { fileName });
    String databaseName = databaseNameText.getText();
    String level = backupLevelCombo.getText().replaceAll("Level", "");
    String volName = volumeNameText.getText();
    boolean isRemoveLog = archiveLogButton.getSelection();
    boolean isCheckDbCons = consistentButton.getSelection();
    boolean isZip = useCompressButton.getSelection();
    boolean isSafeReplication = safeBackupButton.getSelection();
    int threadNum = spnThreadNum.getSelection();
    BackupDbTask backupDbTask = new BackupDbTask(database.getServer().getServerInfo());
    backupDbTask.setDbName(databaseName);
    backupDbTask.setLevel(level);
    backupDbTask.setVolumeName(volName);
    backupDbTask.setBackupDir(backupDir);
    backupDbTask.setRemoveLog(isRemoveLog);
    backupDbTask.setCheckDatabaseConsist(isCheckDbCons);
    backupDbTask.setThreadCount(String.valueOf(threadNum));
    backupDbTask.setZiped(isZip);
    backupDbTask.setSafeReplication(isSafeReplication);
    GetBackupVolInfoTask getBackupVolInfoTask = new GetBackupVolInfoTask(database.getServer().getServerInfo());
    getBackupVolInfoTask.setDbName(databaseName);
    taskExcutor.addTask(checkDirTask);
    taskExcutor.addTask(checkFileTask);
    taskExcutor.addTask(backupDbTask);
    taskExcutor.addTask(getBackupVolInfoTask);
    JobFamily jobFamily = new JobFamily();
    String serverName = database.getServer().getName();
    String dbName = database.getName();
    jobFamily.setServerName(serverName);
    jobFamily.setDbName(dbName);
    String jobName = Messages.msgBackupDBRearJobName + " - " + dbName + "@" + serverName;
    taskExcutor.schedule(jobName, jobFamily, true, Job.SHORT);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TaskJobExecutor(com.cubrid.common.ui.spi.progress.TaskJobExecutor) ITask(com.cubrid.common.core.task.ITask) GetBackupVolInfoTask(com.cubrid.cubridmanager.core.cubrid.database.task.GetBackupVolInfoTask) BackupDbTask(com.cubrid.cubridmanager.core.cubrid.database.task.BackupDbTask) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CheckDirTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckDirTask) CheckFileTask(com.cubrid.cubridmanager.core.cubrid.database.task.CheckFileTask) Display(org.eclipse.swt.widgets.Display)

Example 74 with Display

use of org.eclipse.swt.widgets.Display 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 75 with Display

use of org.eclipse.swt.widgets.Display in project cubrid-manager by CUBRID.

the class CopyToClipboardAction method doRun.

/**
	 * Do run
	 * 
	 * @param objects
	 */
protected void doRun(final Object[] objects) {
    final int len = objects.length;
    final Display display = PlatformUI.getWorkbench().getDisplay();
    BusyIndicator.showWhile(display, new Runnable() {

        public void run() {
            IEditorPart ep = null;
            if (isCopyToEditor) {
                IWorkbenchPage activePage = LayoutUtil.getActivePage();
                ep = activePage.getActiveEditor();
                if (!(ep instanceof QueryEditorPart)) {
                    ep = openNewQueryEditor();
                }
                if (!(ep instanceof QueryEditorPart)) {
                    ep = null;
                }
            }
            StringBuffer allTableSql = new StringBuffer();
            for (int i = 0; i < len; i++) {
                DefaultSchemaNode table = (DefaultSchemaNode) objects[i];
                String sql = getStmtSQL(table, ep);
                if (sql != null && sql.trim().length() > 0) {
                    allTableSql.append(sql);
                    allTableSql.append(StringUtil.NEWLINE);
                    allTableSql.append(StringUtil.NEWLINE);
                }
            }
            if (allTableSql.length() > 0) {
                if (isCopyToEditor) {
                    if (ep instanceof QueryEditorPart) {
                        ((QueryEditorPart) ep).setQuery(allTableSql.toString(), true, false, false);
                    }
                } else {
                    CommonUITool.copyContentToClipboard(allTableSql.toString());
                }
            }
        }
    });
}
Also used : QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart) DefaultSchemaNode(com.cubrid.common.ui.spi.model.DefaultSchemaNode) Display(org.eclipse.swt.widgets.Display)

Aggregations

Display (org.eclipse.swt.widgets.Display)485 Shell (org.eclipse.swt.widgets.Shell)184 Point (org.eclipse.swt.graphics.Point)76 Test (org.junit.Test)63 FillLayout (org.eclipse.swt.layout.FillLayout)62 Color (org.eclipse.swt.graphics.Color)52 Button (org.eclipse.swt.widgets.Button)50 Rectangle (org.eclipse.swt.graphics.Rectangle)48 GridLayout (org.eclipse.swt.layout.GridLayout)43 Composite (org.eclipse.swt.widgets.Composite)43 GridData (org.eclipse.swt.layout.GridData)39 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)32 Image (org.eclipse.swt.graphics.Image)32 Label (org.eclipse.swt.widgets.Label)32 SWT (org.eclipse.swt.SWT)29 InvocationTargetException (java.lang.reflect.InvocationTargetException)28 StyledText (org.eclipse.swt.custom.StyledText)24 Text (org.eclipse.swt.widgets.Text)24 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)23 Font (org.eclipse.swt.graphics.Font)23