Search in sources :

Example 51 with PaintListener

use of org.eclipse.swt.events.PaintListener in project dbeaver by serge-rider.

the class DBeaverSplashHandler method initVisualization.

private void initVisualization() {
    String progressRectString = null, messageRectString = null, foregroundColorString = null, versionCoordString = null, versionInfoSizeString = null, versionInfoColorString = null;
    final IProduct product = Platform.getProduct();
    if (product != null) {
        progressRectString = product.getProperty(IProductConstants.STARTUP_PROGRESS_RECT);
        messageRectString = product.getProperty(IProductConstants.STARTUP_MESSAGE_RECT);
        foregroundColorString = product.getProperty(IProductConstants.STARTUP_FOREGROUND_COLOR);
        versionCoordString = product.getProperty("versionInfoCoord");
        versionInfoSizeString = product.getProperty("versionInfoSize");
        versionInfoColorString = product.getProperty("versionInfoColor");
    }
    setProgressRect(StringConverter.asRectangle(progressRectString, new Rectangle(275, 300, 280, 10)));
    setMessageRect(StringConverter.asRectangle(messageRectString, new Rectangle(275, 275, 280, 25)));
    final Point versionCoord = StringConverter.asPoint(versionCoordString, new Point(485, 215));
    final int versionInfoSize = StringConverter.asInt(versionInfoSizeString, 22);
    final RGB versionInfoRGB = StringConverter.asRGB(versionInfoColorString, new RGB(255, 255, 255));
    int foregroundColorInteger = 0xD2D7FF;
    try {
        if (foregroundColorString != null) {
            foregroundColorInteger = Integer.parseInt(foregroundColorString, 16);
        }
    } catch (Exception ex) {
    // ignore
    }
    setForeground(new RGB((foregroundColorInteger & 0xFF0000) >> 16, (foregroundColorInteger & 0xFF00) >> 8, foregroundColorInteger & 0xFF));
    normalFont = getContent().getFont();
    //boldFont = UIUtils.makeBoldFont(normalFont);
    FontData[] fontData = normalFont.getFontData();
    fontData[0].setStyle(fontData[0].getStyle() | SWT.BOLD);
    fontData[0].setHeight(versionInfoSize);
    boldFont = new Font(normalFont.getDevice(), fontData[0]);
    final Color versionColor = new Color(getContent().getDisplay(), versionInfoRGB);
    getContent().addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            String productVersion = "";
            if (product != null) {
                productVersion = GeneralUtils.getProductVersion().toString();
            }
            //String osVersion = Platform.getOS() + " " + Platform.getOSArch();
            if (boldFont != null) {
                e.gc.setFont(boldFont);
            }
            e.gc.setForeground(versionColor);
            e.gc.drawText(productVersion, versionCoord.x, versionCoord.y, true);
            //e.gc.drawText(osVersion, 115, 200, true);
            e.gc.setFont(normalFont);
        }
    });
}
Also used : PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) IProduct(org.eclipse.core.runtime.IProduct)

Example 52 with PaintListener

use of org.eclipse.swt.events.PaintListener in project translationstudio8 by heartsome.

the class ConversionWizardPage method createFilesGroup.

/**
	 * 创建文件列表区域
	 * @param contents
	 *            ;
	 */
private Composite createFilesGroup(Composite contents) {
    Composite filesComposite = new Composite(contents, SWT.NONE);
    GridLayout gd = new GridLayout(2, false);
    gd.marginWidth = 0;
    filesComposite.setLayout(gd);
    filesComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    filesTable = new Table(filesComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
    tableData.heightHint = 100;
    filesTable.setLayoutData(tableData);
    filesTable.setLinesVisible(true);
    filesTable.setHeaderVisible(true);
    filesTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            doSelectedEvent();
        }
    });
    tableViewer = new TableViewer(filesTable);
    lineNumColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    lineNumColumn.setText(Messages.getString("wizard.ConversionWizardPage.lineNumColumn"));
    sourceColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    sourceColumn.setText(Messages.getString("wizard.ConversionWizardPage.sourceColumn"));
    formatColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    formatColumn.setText(Messages.getString("wizard.ConversionWizardPage.formatColumn"));
    srcEncColumn = new TableViewerColumn(tableViewer, SWT.NONE).getColumn();
    srcEncColumn.setText(Messages.getString("wizard.ConversionWizardPage.srcEncColumn"));
    IValueProperty[] valueProperties = BeanProperties.values(ConversionConfigBean.class, new String[] { "index", "source", "fileType", "srcEncoding" });
    ViewerSupport.bind(tableViewer, new WritableList(conversionConfigBeans, ConversionConfigBean.class), valueProperties);
    filesComposite.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent arg0) {
            int width = filesTable.getClientArea().width;
            lineNumColumn.setWidth(width * 1 / 10);
            sourceColumn.setWidth(width * 5 / 10);
            formatColumn.setWidth(width * 3 / 10);
            srcEncColumn.setWidth(width * 1 / 10);
        }
    });
    Composite opComp = new Composite(filesComposite, SWT.NONE);
    GridLayout opCompGl = new GridLayout();
    opCompGl.marginWidth = 0;
    opCompGl.marginLeft = 0;
    opCompGl.marginTop = 0;
    opCompGl.marginHeight = 0;
    opComp.setLayout(opCompGl);
    GridData gd_opComp = new GridData();
    gd_opComp.verticalAlignment = SWT.TOP;
    opComp.setLayoutData(gd_opComp);
    Button addBt = new Button(opComp, SWT.NONE);
    addBt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    addBt.setText(Messages.getString("wizard.ConversionWizardPage.addbutton"));
    addBt.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), true, IResource.FILE) {

                // 打开对话框时展开树形目录
                public void create() {
                    super.create();
                    super.getTreeViewer().expandAll();
                }
            };
            dialog.setMessage(Messages.getString("wizard.ConversionWizardPage.selectfiledialog.message"));
            dialog.setTitle(Messages.getString("wizard.ConversionWizardPage.selectfiledialog.title"));
            dialog.setDoubleClickSelects(true);
            try {
                dialog.setInput(EFS.getStore(ResourcesPlugin.getWorkspace().getRoot().getLocationURI()));
            } catch (CoreException e1) {
                LOGGER.error("", e1);
                e1.printStackTrace();
            }
            dialog.addFilter(new ViewerFilter() {

                @Override
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    if (element instanceof LocalFile) {
                        LocalFile folder = (LocalFile) element;
                        if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata")) {
                            return false;
                        }
                        String projectPath = currentProject.getLocation().toOSString();
                        if (projectPath.equals(folder.toString())) {
                            return true;
                        }
                        String xliffFolderPath = folder.toString();
                        String path1 = projectPath + File.separator + Constant.FOLDER_SRC;
                        if (xliffFolderPath.startsWith(path1)) {
                            for (ConversionConfigBean bean : conversionConfigBeans) {
                                if (xliffFolderPath.indexOf(bean.getSource()) != -1) {
                                    return false;
                                }
                            }
                            return true;
                        }
                    }
                    return false;
                }
            });
            dialog.create();
            dialog.open();
            if (dialog.getResult() != null) {
                Object[] selectFiles = dialog.getResult();
                for (Object selectedFile : selectFiles) {
                    LocalFile folder = (LocalFile) selectedFile;
                    ConverterViewModel model = new ConverterViewModel(Activator.getContext(), Converter.DIRECTION_POSITIVE);
                    Object adapter = Platform.getAdapterManager().getAdapter(ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(Path.fromOSString(folder.toString())), IConversionItem.class);
                    IConversionItem sourceItem = null;
                    if (adapter instanceof IConversionItem) {
                        sourceItem = (IConversionItem) adapter;
                    }
                    // 记住所选择的文件
                    model.setConversionItem(sourceItem);
                    ConversionConfigBean bean = model.getConfigBean();
                    // 初始化源文件路径
                    bean.setSource(ResourceUtils.toWorkspacePath(folder.toString()));
                    // 初始化源语言
                    bean.setSrcLang(srcLang);
                    bean.setTgtLangList(targetlanguage);
                    if (targetlanguage != null && targetlanguage.size() > 0) {
                        List<Language> lang = new ArrayList<Language>();
                        lang.add(targetlanguage.get(0));
                        bean.setHasSelTgtLangList(lang);
                    }
                    bean.setReplaceTarget(isReplaceTarget);
                    bean.setInitSegmenter(srxFile.getText());
                    conversionConfigBeans.add(bean);
                    converterViewModels.add(model);
                }
                loadFiles();
                validate();
                tableViewer.refresh();
            }
        }
    });
    Button removeBt = new Button(opComp, SWT.NONE);
    removeBt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    removeBt.setText(Messages.getString("wizard.ConversionWizardPage.removebutton"));
    removeBt.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (conversionConfigBeans.size() == 0) {
                return;
            }
            ISelection sel = tableViewer.getSelection();
            if (sel.isEmpty()) {
                MessageDialog.openError(getShell(), Messages.getString("wizard.ConversionWizardPage.removebutton.msg1.title"), Messages.getString("wizard.ConversionWizardPage.removebutton.msg1"));
                return;
            }
            if (sel instanceof IStructuredSelection) {
                IStructuredSelection ssel = (IStructuredSelection) sel;
                Object[] objs = ssel.toArray();
                int index = conversionConfigBeans.indexOf(ssel.getFirstElement());
                index -= ssel.size();
                index = index < 0 ? 0 : index;
                for (Object obj : objs) {
                    int i = conversionConfigBeans.indexOf(obj);
                    conversionConfigBeans.remove(i);
                    converterViewModels.remove(i);
                }
                loadFiles();
                tableViewer.refresh();
                if (!conversionConfigBeans.isEmpty()) {
                    tableViewer.getTable().select(index);
                    doSelectedEvent();
                }
                validate();
            }
        }
    });
    return filesComposite;
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Language(net.heartsome.cat.common.locale.Language) ConversionConfigBean(net.heartsome.cat.convert.ui.model.ConversionConfigBean) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) WritableList(org.eclipse.core.databinding.observable.list.WritableList) List(java.util.List) ArrayList(java.util.ArrayList) IValueProperty(org.eclipse.core.databinding.property.value.IValueProperty) FileFolderSelectionDialog(net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Table(org.eclipse.swt.widgets.Table) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) WritableList(org.eclipse.core.databinding.observable.list.WritableList) GridData(org.eclipse.swt.layout.GridData) ConverterViewModel(net.heartsome.cat.convert.ui.model.ConverterViewModel) TableViewer(org.eclipse.jface.viewers.TableViewer) IConversionItem(net.heartsome.cat.convert.ui.model.IConversionItem)

Example 53 with PaintListener

use of org.eclipse.swt.events.PaintListener in project dbeaver by dbeaver.

the class ProgressEditorPart method createProgressPane.

private void createProgressPane(final Composite parent) {
    progressCanvas = new Canvas(parent, SWT.NONE);
    progressCanvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            e.gc.drawText("Connecting to datasource '" + getEditorInput().getDatabaseObject().getName() + "'...", 5, 5, true);
        }
    });
    InitNodeService loadingService = new InitNodeService();
    LoadingJob<IDatabaseEditorInput> loadJob = LoadingJob.createService(loadingService, new InitNodeVisualizer(loadingService));
    loadJob.schedule();
}
Also used : IDatabaseEditorInput(org.jkiss.dbeaver.ui.editors.IDatabaseEditorInput) PaintEvent(org.eclipse.swt.events.PaintEvent) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas)

Example 54 with PaintListener

use of org.eclipse.swt.events.PaintListener in project dbeaver by dbeaver.

the class ViewValuePanel method createContents.

@Override
public Control createContents(IResultSetPresentation presentation, Composite parent) {
    this.presentation = presentation;
    viewPlaceholder = new Composite(parent, SWT.NONE);
    viewPlaceholder.setLayout(new FillLayout());
    viewPlaceholder.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (viewPlaceholder.getChildren().length == 0) {
                String hidePanelCmd = ActionUtils.findCommandDescription(ResultSetCommandHandler.CMD_TOGGLE_PANELS, ViewValuePanel.this.presentation.getController().getSite(), true);
                UIUtils.drawMessageOverControl(viewPlaceholder, e, "Select a cell to view/edit value", 0);
                UIUtils.drawMessageOverControl(viewPlaceholder, e, "Press " + hidePanelCmd + " to hide this panel", 20);
            }
        }
    });
    if (this.presentation instanceof ISelectionProvider) {
        final ISelectionProvider selectionProvider = (ISelectionProvider) this.presentation;
        final ISelectionChangedListener selectionListener = new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                if (ViewValuePanel.this.presentation.getController().getVisiblePanel() == ViewValuePanel.this) {
                    refreshValue(false);
                }
            }
        };
        selectionProvider.addSelectionChangedListener(selectionListener);
        viewPlaceholder.addDisposeListener(new DisposeListener() {

            @Override
            public void widgetDisposed(DisposeEvent e) {
                selectionProvider.removeSelectionChangedListener(selectionListener);
            }
        });
    }
    return viewPlaceholder;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) PaintListener(org.eclipse.swt.events.PaintListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) DisposeEvent(org.eclipse.swt.events.DisposeEvent)

Example 55 with PaintListener

use of org.eclipse.swt.events.PaintListener in project dbeaver by dbeaver.

the class ViewValuePanel method viewValue.

private void viewValue(boolean forceRefresh) {
    if (valueSaving) {
        return;
    }
    if (valueManager == null || valueEditor == null) {
        forceRefresh = true;
    }
    if (forceRefresh) {
        cleanupPanel();
        // Create a new one
        valueManager = previewController.getValueManager();
        try {
            valueEditor = valueManager.createEditor(previewController);
        } catch (Throwable e) {
            DBUserInterface.getInstance().showError("Value preview", "Can't create value viewer", e);
            return;
        }
        if (valueEditor != null) {
            try {
                valueEditor.createControl();
            } catch (Exception e) {
                log.error(e);
            }
            Control control = valueEditor.getControl();
            if (control != null) {
                UIUtils.addFocusTracker(presentation.getController().getSite(), VALUE_VIEW_CONTROL_ID, control);
                presentation.getController().lockActionsByFocus(control);
            }
            referenceValueEditor = new ReferenceValueEditor(previewController, valueEditor);
            if (referenceValueEditor.isReferenceValue()) {
                GridLayout gl = new GridLayout(1, false);
                viewPlaceholder.setLayout(gl);
                valueEditor.getControl().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
                referenceValueEditor.createEditorSelector(viewPlaceholder);
            } else {
                viewPlaceholder.setLayout(new FillLayout());
            }
        } else {
            final Composite placeholder = UIUtils.createPlaceholder(viewPlaceholder, 1);
            placeholder.setBackground(placeholder.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
            placeholder.addPaintListener(new PaintListener() {

                @Override
                public void paintControl(PaintEvent e) {
                    Rectangle bounds = placeholder.getBounds();
                    String message = "No editor for [" + previewController.getValueType().getTypeName() + "]";
                    Point ext = e.gc.textExtent(message);
                    e.gc.drawText(message, (bounds.width - ext.x) / 2, bounds.height / 3 + 20);
                }
            });
            referenceValueEditor = null;
        }
        viewPlaceholder.layout();
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(false);
    }
    if (valueEditor != null) {
        try {
            Object newValue = previewController.getValue();
            if (newValue instanceof DBDValue) {
                // Do not check for difference
                valueEditor.primeEditorValue(newValue);
            } else {
                Object oldValue = null;
                try {
                    if (previewController.getExecutionContext() != null) {
                        oldValue = valueEditor.extractEditorValue();
                    }
                } catch (Throwable e) {
                // Some error extracting current value
                // This may happen if we were disconnected
                }
                if (!CommonUtils.equalObjects(oldValue, newValue)) {
                    valueEditor.primeEditorValue(newValue);
                }
            }
        } catch (DBException e) {
            log.error(e);
        }
        valueEditor.setDirty(false);
    }
    if (valueEditor instanceof BaseValueEditor) {
        ((BaseValueEditor) valueEditor).setAutoSaveEnabled(true);
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) PaintEvent(org.eclipse.swt.events.PaintEvent) Composite(org.eclipse.swt.widgets.Composite) PaintListener(org.eclipse.swt.events.PaintListener) Rectangle(org.eclipse.swt.graphics.Rectangle) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor) DBException(org.jkiss.dbeaver.DBException) BaseValueEditor(org.jkiss.dbeaver.ui.data.editors.BaseValueEditor) Control(org.eclipse.swt.widgets.Control) GridLayout(org.eclipse.swt.layout.GridLayout) DBDValue(org.jkiss.dbeaver.model.data.DBDValue) GridData(org.eclipse.swt.layout.GridData)

Aggregations

PaintListener (org.eclipse.swt.events.PaintListener)89 PaintEvent (org.eclipse.swt.events.PaintEvent)88 Canvas (org.eclipse.swt.widgets.Canvas)32 Composite (org.eclipse.swt.widgets.Composite)29 MouseEvent (org.eclipse.swt.events.MouseEvent)26 GridData (org.eclipse.swt.layout.GridData)26 Rectangle (org.eclipse.swt.graphics.Rectangle)25 Point (org.eclipse.swt.graphics.Point)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 MouseAdapter (org.eclipse.swt.events.MouseAdapter)15 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 DisposeEvent (org.eclipse.swt.events.DisposeEvent)14 DisposeListener (org.eclipse.swt.events.DisposeListener)14 FillLayout (org.eclipse.swt.layout.FillLayout)14 Control (org.eclipse.swt.widgets.Control)14 ControlEvent (org.eclipse.swt.events.ControlEvent)13 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 Event (org.eclipse.swt.widgets.Event)11 GC (org.eclipse.swt.graphics.GC)10 Button (org.eclipse.swt.widgets.Button)10