Search in sources :

Example 1 with ControlEditor

use of org.eclipse.swt.custom.ControlEditor in project dbeaver by serge-rider.

the class ProgressLoaderVisualizer method showProgress.

private void showProgress() {
    if (progressOverlay == null) {
        // Start progress visualization
        cancelButton = new Button(progressPane, SWT.PUSH);
        cancelButton.setText("Cancel");
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.verticalIndent = DBeaverIcons.getImage(UIIcon.PROGRESS0).getBounds().height * 2;
        cancelButton.setLayoutData(gd);
        cancelButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                cancelButton.setText("Canceled");
                cancelButton.setEnabled(false);
                Point buttonSize = cancelButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                progressOverlay.minimumWidth = buttonSize.x;
                progressOverlay.minimumHeight = buttonSize.y;
                progressOverlay.layout();
                try {
                    loadService.cancel();
                } catch (InvocationTargetException e1) {
                    log.error(e1.getTargetException());
                }
            }
        });
        painListener = new PaintListener() {

            @Override
            public void paintControl(PaintEvent e) {
                Image image = DBeaverIcons.getImage(PROGRESS_IMAGES[drawCount % PROGRESS_IMAGES.length]);
                Rectangle buttonBounds = cancelButton.getBounds();
                Rectangle imageBounds = image.getBounds();
                e.gc.drawImage(image, (buttonBounds.x + buttonBounds.width / 2) - imageBounds.width / 2, buttonBounds.y - imageBounds.height - 5);
                long elapsedTime = System.currentTimeMillis() - loadStartTime;
                String elapsedString = elapsedTime > 10000 ? String.valueOf(elapsedTime / 1000) : String.valueOf(((double) (elapsedTime / 100)) / 10);
                String statusMessage = CommonUtils.truncateString(progressMessage.replaceAll("\\s", " "), 64);
                String status = statusMessage + " - " + elapsedString + "s";
                Point statusSize = e.gc.textExtent(status);
                int statusX = (buttonBounds.x + buttonBounds.width / 2) - statusSize.x / 2;
                int statusY = buttonBounds.y - imageBounds.height - 10 - statusSize.y;
                e.gc.setForeground(progressPane.getForeground());
                e.gc.setBackground(progressPane.getBackground());
                e.gc.fillRectangle(statusX - 2, statusY - 2, statusSize.x + 4, statusSize.y + 4);
                e.gc.drawText(status, statusX, statusY, true);
                e.gc.setForeground(shadowColor);
                e.gc.drawRoundRectangle(statusX - 3, statusY - 3, statusSize.x + 5, statusSize.y + 5, 5, 5);
            }
        };
        progressPane.addPaintListener(painListener);
        progressOverlay = new ControlEditor(progressPane);
        Point buttonSize = cancelButton.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        progressOverlay.minimumWidth = buttonSize.x;
        progressOverlay.minimumHeight = buttonSize.y;
        progressOverlay.setEditor(cancelButton);
    }
    drawCount++;
    progressOverlay.layout();
    progressPane.redraw();
}
Also used : ControlEditor(org.eclipse.swt.custom.ControlEditor) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) InvocationTargetException(java.lang.reflect.InvocationTargetException) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with ControlEditor

use of org.eclipse.swt.custom.ControlEditor in project cubrid-manager by CUBRID.

the class QueryExecuter method makeResult.

/**
	 * Make query editor result panel,including table panel and sql text and
	 * message text
	 *
	 * @param resultTbl the Table.
	 * @param sqlText the Text.
	 * @param messageText the StyledText.
	 */
public void makeResult(final TableSelectSupport tableSelectSupport, StyledText messageText, boolean multiQueryResult) {
    this.selectableSupport = tableSelectSupport;
    this.tblResult = tableSelectSupport.getTable();
    logMessageText = messageText;
    int[] queryInfoRange = new int[2];
    int[] queryRange = new int[2];
    StringBuilder resultMessage = new StringBuilder();
    resultMessage.append(getQueryMsg() == null ? "" : getQueryMsg().trim());
    queryInfoRange[0] = 0;
    queryInfoRange[1] = resultMessage.length();
    resultMessage.append(StringUtil.NEWLINE).append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT).append(StringUtil.NEWLINE);
    queryRange[0] = resultMessage.length();
    resultMessage.append(query);
    queryRange[1] = query.length();
    ServerInfo serverInfo = database.getServer() == null ? null : database.getServer().getServerInfo();
    String fontString = QueryOptions.getFontString(serverInfo);
    Font tmpFont = ResourceManager.getFont(fontString);
    if (tmpFont == null) {
        String[] fontData = QueryOptions.getDefaultFont();
        tmpFont = ResourceManager.getFont(fontData[0], Integer.valueOf(fontData[1]), Integer.valueOf(fontData[2]));
    }
    font = tmpFont;
    tblResult.setFont(font);
    int[] fontColor = QueryOptions.getFontColor(serverInfo);
    color = ResourceManager.getColor(fontColor[0], fontColor[1], fontColor[2]);
    tblResult.setForeground(color);
    // Set font and foreground
    selectableSupport.getTableCursor().setFont(font);
    selectableSupport.getTableCursor().setForeground(color);
    selectableSupport.setShowDetailOperator(this);
    tblResult.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent e) {
            selectableSupport.redrawMoreButton();
        }
    });
    if (queryEditor != null) {
        if (!multiQueryResult) {
            createContextMenuItems();
        }
        editor = new ControlEditor(selectableSupport.getTableCursor());
        editor.horizontalAlignment = SWT.LEFT;
        editor.grabHorizontal = true;
        editor.grabVertical = true;
        bindEvents();
        addTableItemToolTips();
    }
    makeColumn();
    makeItem();
    if (!StringUtil.isEmpty(queryPlanLog)) {
        resultMessage.append(StringUtil.NEWLINE).append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
        resultMessage.append(StringUtil.NEWLINE).append(queryPlanLog);
    }
    if (!StringUtil.isEmpty(statsLog)) {
        resultMessage.append(StringUtil.NEWLINE).append(Messages.queryStat).append(":");
        resultMessage.append(StringUtil.NEWLINE).append(QueryUtil.SPLIT_LINE_FOR_QUERY_RESULT);
        resultMessage.append(StringUtil.NEWLINE).append(statsLog);
    }
    messageText.setText(resultMessage.toString());
    // Styled Query info
    StyleRange queryInfoStyle = new StyleRange();
    queryInfoStyle.start = queryInfoRange[0];
    queryInfoStyle.length = queryInfoRange[1];
    queryInfoStyle.fontStyle = SWT.NORMAL;
    queryInfoStyle.foreground = ResourceManager.getColor(SWT.COLOR_BLUE);
    messageText.setStyleRange(queryInfoStyle);
    StyleRange queryStyle = new StyleRange();
    queryStyle.start = queryRange[0];
    queryStyle.length = queryRange[1];
    queryStyle.fontStyle = SWT.BOLD;
    messageText.setStyleRange(queryStyle);
    // styled log text
    updateStyledLogTextForStatistics(messageText);
    updateStyledLogTextForPlan(messageText);
    updateStyledLogTextForTrace(messageText);
}
Also used : ControlEditor(org.eclipse.swt.custom.ControlEditor) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) StyleRange(org.eclipse.swt.custom.StyleRange) Font(org.eclipse.swt.graphics.Font)

Aggregations

ControlEditor (org.eclipse.swt.custom.ControlEditor)2 PaintEvent (org.eclipse.swt.events.PaintEvent)2 PaintListener (org.eclipse.swt.events.PaintListener)2 ServerInfo (com.cubrid.cubridmanager.core.common.model.ServerInfo)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 StyleRange (org.eclipse.swt.custom.StyleRange)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Font (org.eclipse.swt.graphics.Font)1 Image (org.eclipse.swt.graphics.Image)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1