Search in sources :

Example 81 with Display

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

the class ConnectDatabaseExecutor method internalConnect.

private boolean internalConnect(String brokerIP, String brokerPort, String dbName, String userName, String password, String charset, String jdbcAttrs, String driverVersion, boolean autoCommit, boolean isShard) {
    Display display = Display.getDefault();
    CUBRIDConnectionProxy connection = null;
    try {
        connection = (CUBRIDConnectionProxy) JDBCConnectionManager.getConnection(brokerIP, brokerPort, dbName, userName, password, charset, jdbcAttrs, driverVersion, autoCommit, isShard);
        if (connection == null) {
            display.syncExec(new Runnable() {

                public void run() {
                    CommonUITool.openErrorBox(Messages.msgConnectBrokerFailure);
                }
            });
            return false;
        }
        String jdbcVersion = connection.getJdbcVersion();
        jdbcVersion = jdbcVersion == null ? "" : jdbcVersion.replaceAll("CUBRID-JDBC-", "");
        if (jdbcVersion.lastIndexOf(".") > 0) {
            jdbcVersion = jdbcVersion.substring(0, jdbcVersion.lastIndexOf("."));
        }
        String dbVersion = connection.getMetaData().getDatabaseProductVersion();
        dbVersion = dbVersion == null ? "" : dbVersion;
        String minorDbVersion = dbVersion;
        if (minorDbVersion.lastIndexOf(".") > 0) {
            minorDbVersion = minorDbVersion.substring(0, minorDbVersion.lastIndexOf("."));
        }
        if (CompatibleUtil.compareVersion(jdbcVersion, minorDbVersion) == 0) {
            return true;
        } else {
            final String finalDbVersion = dbVersion;
            display.syncExec(new Runnable() {

                public void run() {
                    isConnectSuccess = CommonUITool.openConfirmBox(Messages.bind(Messages.tipNoSupportJdbcVersion, finalDbVersion));
                }
            });
            return isConnectSuccess;
        }
    } catch (final SQLException e) {
        LOGGER.error(e.getMessage(), e);
        display.syncExec(new Runnable() {

            public void run() {
                CommonUITool.openErrorBox(Messages.bind(Messages.errCommonTip, e.getErrorCode(), e.getMessage()));
            }
        });
        return false;
    } catch (final Exception e) {
        display.syncExec(new Runnable() {

            public void run() {
                CommonUITool.openErrorBox(e.getMessage());
            }
        });
        return false;
    } finally {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                LOGGER.error(e.getMessage());
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) CUBRIDConnectionProxy(com.cubrid.jdbc.proxy.driver.CUBRIDConnectionProxy) SQLException(java.sql.SQLException) Display(org.eclipse.swt.widgets.Display)

Example 82 with Display

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

the class StartDatabaseAction method doRun.

public void doRun(ISchemaNode[] schemaArray) {
    if (schemaArray == null || schemaArray.length == 0) {
        return;
    }
    List<ISchemaNode> startList = new ArrayList<ISchemaNode>();
    /*Judge start job is running*/
    for (ISchemaNode node : schemaArray) {
        if (!isSupported(node)) {
            setEnabled(false);
            return;
        }
        CubridDatabase database = node.getDatabase();
        final JobFamily jobFamily = new JobFamily();
        String serverName = database.getServer().getName();
        String dbName = database.getName();
        jobFamily.setServerName(serverName);
        jobFamily.setDbName(dbName);
        Job[] jobs = Job.getJobManager().find(jobFamily);
        if (jobs.length > 0) {
            CommonUITool.openWarningBox(Messages.bind(Messages.msgStartDbWithJob, dbName));
            continue;
        }
        startList.add(database);
    }
    CubridNavigatorView navigationView = CubridNavigatorView.findNavigationView();
    if (navigationView != null && startList.size() > 0) {
        final TreeViewer treeViewer = navigationView.getViewer();
        TaskExecutor taskExcutor = new TaskExecutor() {

            public boolean exec(final IProgressMonitor monitor) {
                Display display = Display.getDefault();
                if (monitor.isCanceled()) {
                    return false;
                }
                for (int i = 0; i < taskList.size(); i++) {
                    ITask task = taskList.get(i);
                    final CubridDatabase database = (CubridDatabase) task.getData("dbName");
                    if (!isSupported(database)) {
                        continue;
                    }
                    monitor.subTask(Messages.bind(Messages.startDbTaskName, database.getName()));
                    task.execute();
                    if (openErrorBox(shell, task.getErrorMsg(), monitor) || monitor.isCanceled()) {
                        return false;
                    }
                    openWarningBox(shell, task.getWarningMsg(), monitor);
                    if (monitor.isCanceled()) {
                        return false;
                    }
                    database.removeAllChild();
                    if (database.getLoader() != null) {
                        database.getLoader().setLoaded(false);
                    }
                    database.setRunningType(DbRunningType.CS);
                    display.syncExec(new Runnable() {

                        public void run() {
                            treeViewer.refresh(database, true);
                        }
                    });
                    if (monitor.isCanceled()) {
                        return false;
                    }
                }
                return true;
            }
        };
        for (ISchemaNode schemaNode : startList) {
            CubridDatabase database = schemaNode.getDatabase();
            if (!isSupported(database)) {
                setEnabled(false);
                return;
            }
            ServerInfo serverInfo = database.getServer().getServerInfo();
            CommonUpdateTask task = new CommonUpdateTask(CommonTaskName.START_DB_TASK_NAME, serverInfo, CommonSendMsg.getCommonDatabaseSendMsg());
            task.setDbName(database.getLabel());
            task.putData("dbName", database);
            taskExcutor.addTask(task);
        }
        new ExecTaskWithProgress(taskExcutor).busyCursorWhile();
        ActionManager.getInstance().fireSelectionChanged(getSelection());
    }
}
Also used : ITask(com.cubrid.common.core.task.ITask) ISchemaNode(com.cubrid.common.ui.spi.model.ISchemaNode) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) ArrayList(java.util.ArrayList) JobFamily(com.cubrid.common.ui.spi.progress.JobFamily) CubridNavigatorView(com.cubrid.common.ui.common.navigator.CubridNavigatorView) TaskExecutor(com.cubrid.common.ui.spi.progress.TaskExecutor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExecTaskWithProgress(com.cubrid.common.ui.spi.progress.ExecTaskWithProgress) CommonUpdateTask(com.cubrid.cubridmanager.core.common.task.CommonUpdateTask) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase) Job(org.eclipse.core.runtime.jobs.Job) Display(org.eclipse.swt.widgets.Display)

Example 83 with Display

use of org.eclipse.swt.widgets.Display in project dbeaver by serge-rider.

the class DBeaverIcons method getViewMenuImage.

public static synchronized Image getViewMenuImage() {
    if (viewMenuImage == null) {
        Display d = Display.getCurrent();
        Image viewMenu = new Image(d, 16, 16);
        Image viewMenuMask = new Image(d, 16, 16);
        Display display = Display.getCurrent();
        GC gc = new GC(viewMenu);
        GC maskgc = new GC(viewMenuMask);
        gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
        gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        int[] shapeArray = new int[] { 6, 3, 15, 3, 11, 7, 10, 7 };
        gc.fillPolygon(shapeArray);
        gc.drawPolygon(shapeArray);
        Color black = display.getSystemColor(SWT.COLOR_BLACK);
        Color white = display.getSystemColor(SWT.COLOR_WHITE);
        maskgc.setBackground(black);
        maskgc.fillRectangle(0, 0, 16, 16);
        maskgc.setBackground(white);
        maskgc.setForeground(white);
        maskgc.fillPolygon(shapeArray);
        maskgc.drawPolygon(shapeArray);
        gc.dispose();
        maskgc.dispose();
        ImageData data = viewMenu.getImageData();
        data.transparentPixel = data.getPixel(0, 0);
        viewMenuImage = new Image(d, viewMenu.getImageData(), viewMenuMask.getImageData());
        viewMenu.dispose();
        viewMenuMask.dispose();
    }
    return viewMenuImage;
}
Also used : ImageData(org.eclipse.swt.graphics.ImageData) Color(org.eclipse.swt.graphics.Color) Image(org.eclipse.swt.graphics.Image) DBPImage(org.jkiss.dbeaver.model.DBPImage) GC(org.eclipse.swt.graphics.GC) Display(org.eclipse.swt.widgets.Display)

Example 84 with Display

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

the class RecordAction method runWithEvent.

/**
	 * Shifting the recordFlag and return the the interface of Recordable.
	 * 
	 * @param event the SWT event which triggered this action being run
	 */
public void runWithEvent(final Event event) {
    recordFlag = recorder.getRecordFlag();
    recordFlag = !recordFlag;
    recorder.setRecordFlag(recordFlag);
    final Display display = Display.getDefault();
    Runnable runnable = new Runnable() {

        boolean state = false;

        public void run() {
            if (state) {
                ((ToolItem) (event.widget)).setImage(CubridManagerUIPlugin.getImage("icons/monitor/record_bright.png"));
            } else {
                ((ToolItem) (event.widget)).setImage(CubridManagerUIPlugin.getImage("icons/monitor/record_dim.png"));
            }
            state = !state;
            if (recordFlag) {
                display.timerExec(800, this);
            } else {
                display.timerExec(-1, this);
                ((ToolItem) (event.widget)).setImage(CubridManagerUIPlugin.getImage("icons/monitor/prepare_record.png"));
            }
        }
    };
    if (recordFlag) {
        this.setImageDescriptor(CubridManagerUIPlugin.getImageDescriptor("icons/monitor/record_bright.png"));
        this.setToolTipText(recordTooltip);
        display.timerExec(20, runnable);
    } else {
        this.setImageDescriptor(CubridManagerUIPlugin.getImageDescriptor("icons/monitor/prepare_record.png"));
        this.setToolTipText(prepareTooltip);
    }
}
Also used : ToolItem(org.eclipse.swt.widgets.ToolItem) Display(org.eclipse.swt.widgets.Display)

Example 85 with Display

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

the class FontGroup method updateColorImage.

/**
	 * Update the image being displayed on the button using the current color
	 * setting.
	 */
private void updateColorImage() {
    Display display = fontColorLbl.getDisplay();
    Color fColor = new Color(display, chosenRgb);
    fontColorLbl.setBackground(fColor);
}
Also used : Color(org.eclipse.swt.graphics.Color) 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