Search in sources :

Example 1 with KeyEvent

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

the class ColumnsMappingDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    DBPDataSource targetDataSource = settings.getTargetDataSource(mapping);
    getShell().setText("Map columns of " + mapping.getTargetName());
    boldFont = UIUtils.makeBoldFont(parent.getFont());
    Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(1, false));
    composite.setLayoutData(new GridData(GridData.FILL_BOTH));
    new Label(composite, SWT.NONE).setText("Source entity: " + DBUtils.getObjectFullName(mapping.getSource(), DBPEvaluationContext.UI) + " [" + mapping.getSource().getDataSource().getContainer().getName() + "]");
    new Label(composite, SWT.NONE).setText("Target entity: " + mapping.getTargetName() + " [" + (targetDataSource == null ? "?" : targetDataSource.getContainer().getName()) + "]");
    mappingViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 600;
    gd.heightHint = 300;
    mappingViewer.getTable().setLayoutData(gd);
    mappingViewer.getTable().setLinesVisible(true);
    mappingViewer.getTable().setHeaderVisible(true);
    mappingViewer.setContentProvider(new ListContentProvider());
    mappingViewer.getTable().addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            if (e.character == SWT.DEL) {
                for (TableItem item : mappingViewer.getTable().getSelection()) {
                    DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
                    attribute.setMappingType(DatabaseMappingType.skip);
                }
                updateStatus(Status.OK_STATUS);
                mappingViewer.refresh();
            } else if (e.character == SWT.SPACE) {
                for (TableItem item : mappingViewer.getTable().getSelection()) {
                    DatabaseMappingAttribute attribute = (DatabaseMappingAttribute) item.getData();
                    attribute.setMappingType(DatabaseMappingType.existing);
                    try {
                        attribute.updateMappingType(VoidProgressMonitor.INSTANCE);
                    } catch (DBException e1) {
                        updateStatus(GeneralUtils.makeExceptionStatus(e1));
                    }
                }
                mappingViewer.refresh();
            }
        }
    });
    {
        TableViewerColumn columnSource = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnSource.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) cell.getElement();
                cell.setText(DBUtils.getObjectFullName(attrMapping.getSource(), DBPEvaluationContext.UI));
                if (attrMapping.getIcon() != null) {
                    cell.setImage(DBeaverIcons.getImage(attrMapping.getIcon()));
                }
            }
        });
        columnSource.getColumn().setText("Source Column");
        columnSource.getColumn().setWidth(170);
    }
    {
        TableViewerColumn columnSourceType = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnSourceType.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                cell.setText(((DatabaseMappingAttribute) cell.getElement()).getSourceType());
            }
        });
        columnSourceType.getColumn().setText("Source Type");
        columnSourceType.getColumn().setWidth(100);
    }
    {
        TableViewerColumn columnTarget = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnTarget.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) cell.getElement();
                cell.setText(mapping.getTargetName());
                if (mapping.mappingType == DatabaseMappingType.unspecified) {
                    cell.setBackground(DBeaverUI.getSharedTextColors().getColor(SharedTextColors.COLOR_WARNING));
                } else {
                    cell.setBackground(null);
                }
                cell.setFont(boldFont);
            }
        });
        columnTarget.getColumn().setText("Target Column");
        columnTarget.getColumn().setWidth(170);
        columnTarget.setEditingSupport(new EditingSupport(mappingViewer) {

            @Override
            protected CellEditor getCellEditor(Object element) {
                try {
                    java.util.List<String> items = new ArrayList<>();
                    DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) element;
                    if (mapping.getParent().getMappingType() == DatabaseMappingType.existing && mapping.getParent().getTarget() instanceof DBSEntity) {
                        DBSEntity parentEntity = (DBSEntity) mapping.getParent().getTarget();
                        for (DBSEntityAttribute attr : CommonUtils.safeCollection(parentEntity.getAttributes(VoidProgressMonitor.INSTANCE))) {
                            items.add(attr.getName());
                        }
                    }
                    items.add(DatabaseMappingAttribute.TARGET_NAME_SKIP);
                    CustomComboBoxCellEditor editor = new CustomComboBoxCellEditor(mappingViewer.getTable(), items.toArray(new String[items.size()]), SWT.DROP_DOWN);
                    updateStatus(Status.OK_STATUS);
                    return editor;
                } catch (DBException e) {
                    updateStatus(GeneralUtils.makeExceptionStatus(e));
                    return null;
                }
            }

            @Override
            protected boolean canEdit(Object element) {
                return true;
            }

            @Override
            protected Object getValue(Object element) {
                return ((DatabaseMappingAttribute) element).getTargetName();
            }

            @Override
            protected void setValue(Object element, Object value) {
                try {
                    String name = CommonUtils.toString(value);
                    DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
                    if (DatabaseMappingAttribute.TARGET_NAME_SKIP.equals(name)) {
                        attrMapping.setMappingType(DatabaseMappingType.skip);
                    } else {
                        if (attrMapping.getParent().getMappingType() == DatabaseMappingType.existing && attrMapping.getParent().getTarget() instanceof DBSEntity) {
                            DBSEntity parentEntity = (DBSEntity) attrMapping.getParent().getTarget();
                            for (DBSEntityAttribute attr : CommonUtils.safeCollection(parentEntity.getAttributes(VoidProgressMonitor.INSTANCE))) {
                                if (name.equalsIgnoreCase(attr.getName())) {
                                    attrMapping.setTarget(attr);
                                    attrMapping.setMappingType(DatabaseMappingType.existing);
                                    return;
                                }
                            }
                        }
                        attrMapping.setMappingType(DatabaseMappingType.create);
                        attrMapping.setTargetName(name);
                    }
                    updateStatus(Status.OK_STATUS);
                } catch (DBException e) {
                    updateStatus(GeneralUtils.makeExceptionStatus(e));
                } finally {
                    mappingViewer.refresh();
                }
            }
        });
    }
    {
        TableViewerColumn columnTargetType = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnTargetType.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) cell.getElement();
                DBPDataSource dataSource = settings.getTargetDataSource(attrMapping);
                cell.setText(attrMapping.getTargetType(dataSource));
                cell.setFont(boldFont);
            }
        });
        columnTargetType.getColumn().setText("Target Type");
        columnTargetType.getColumn().setWidth(100);
        columnTargetType.setEditingSupport(new EditingSupport(mappingViewer) {

            @Override
            protected CellEditor getCellEditor(Object element) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
                Set<String> types = new LinkedHashSet<>();
                DBPDataSource dataSource = settings.getTargetDataSource(attrMapping);
                if (dataSource instanceof DBPDataTypeProvider) {
                    for (DBSDataType type : ((DBPDataTypeProvider) dataSource).getLocalDataTypes()) {
                        types.add(type.getName());
                    }
                }
                types.add(attrMapping.getTargetType(dataSource));
                return new CustomComboBoxCellEditor(mappingViewer.getTable(), types.toArray(new String[types.size()]), SWT.BORDER);
            }

            @Override
            protected boolean canEdit(Object element) {
                return true;
            }

            @Override
            protected Object getValue(Object element) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
                return attrMapping.getTargetType(settings.getTargetDataSource(attrMapping));
            }

            @Override
            protected void setValue(Object element, Object value) {
                DatabaseMappingAttribute attrMapping = (DatabaseMappingAttribute) element;
                attrMapping.setTargetType(CommonUtils.toString(value));
                mappingViewer.refresh(element);
            }
        });
    }
    {
        TableViewerColumn columnType = new TableViewerColumn(mappingViewer, SWT.LEFT);
        columnType.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DatabaseMappingAttribute mapping = (DatabaseMappingAttribute) cell.getElement();
                String text = "";
                switch(mapping.getMappingType()) {
                    case unspecified:
                        text = "?";
                        break;
                    case existing:
                        text = "existing";
                        break;
                    case create:
                        text = "new";
                        break;
                    case skip:
                        text = "skip";
                        break;
                }
                cell.setText(text);
            }
        });
        columnType.getColumn().setText("Mapping");
        columnType.getColumn().setWidth(60);
    }
    mappingViewer.setInput(attributeMappings);
    return parent;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DBException(org.jkiss.dbeaver.DBException) KeyAdapter(org.eclipse.swt.events.KeyAdapter) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) CustomComboBoxCellEditor(org.jkiss.dbeaver.ui.controls.CustomComboBoxCellEditor) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) Composite(org.eclipse.swt.widgets.Composite) DBSDataType(org.jkiss.dbeaver.model.struct.DBSDataType) DBPDataSource(org.jkiss.dbeaver.model.DBPDataSource) DBSEntityAttribute(org.jkiss.dbeaver.model.struct.DBSEntityAttribute) GridData(org.eclipse.swt.layout.GridData) DBPDataTypeProvider(org.jkiss.dbeaver.model.DBPDataTypeProvider) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity)

Example 2 with KeyEvent

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

the class TextCellEditor method createControl.

/**
     * Create the control to be used when editing.
     * 
     * @param table table is the parent control
     */
private void createControl(JaretTable table) {
    if (_text == null) {
        _table = table;
        if (!_multi) {
            _text = new Text(table, SWT.BORDER);
        } else {
            _text = new Text(table, SWT.BORDER | SWT.MULTI | SWT.WRAP);
        }
        _text.addKeyListener(new KeyListener() {

            public void keyPressed(KeyEvent event) {
                if ((event.stateMask & SWT.ALT) != 0 && event.keyCode == SWT.CR) {
                    event.doit = false;
                    _text.insert("\n");
                } else if (event.keyCode == SWT.TAB) {
                    event.doit = false;
                    stopEditing(true);
                    _table.forceFocus();
                    _table.focusRight();
                } else if (event.keyCode == SWT.CR) {
                    event.doit = false;
                    stopEditing(true);
                    _table.forceFocus();
                    _table.focusDown();
                } else if (event.keyCode == SWT.ESC) {
                    event.doit = false;
                    stopEditing(false);
                    _column.setValue(_row, _oldVal);
                    _table.forceFocus();
                } else {
                    if (_multi) {
                        // TODO
                        if (true || _text.getLineCount() * _text.getLineHeight() < _text.getSize().y) {
                            Point newSize = new Point(_text.getSize().x, getPreferredHeight());
                            _text.setSize(newSize);
                        }
                    }
                }
            }

            public void keyReleased(KeyEvent arg0) {
            }
        });
        _text.addFocusListener(this);
    }
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Text(org.eclipse.swt.widgets.Text) KeyListener(org.eclipse.swt.events.KeyListener) Point(org.eclipse.swt.graphics.Point)

Example 3 with KeyEvent

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

the class DoubleCellEditor method createControl.

/**
     * Create and setup the control.
     * 
     * @param table parent for the control
     */
private void createControl(JaretTable table) {
    if (_text == null) {
        _table = table;
        _text = new Text(table, SWT.BORDER | SWT.RIGHT);
        _doubleField = new DoubleField();
        _doubleField.setText(_text);
        _text.addKeyListener(new KeyListener() {

            public void keyPressed(KeyEvent event) {
                if (event.keyCode == SWT.TAB) {
                    event.doit = false;
                    stopEditing(true);
                    _table.forceFocus();
                    _table.focusRight();
                } else if (event.keyCode == SWT.CR) {
                    event.doit = false;
                    stopEditing(true);
                    _table.forceFocus();
                    _table.focusDown();
                } else if (event.keyCode == SWT.ESC) {
                    event.doit = false;
                    stopEditing(false);
                    _column.setValue(_row, _oldVal);
                    _table.forceFocus();
                }
            }

            public void keyReleased(KeyEvent arg0) {
            }
        });
        _text.addFocusListener(this);
    }
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) Text(org.eclipse.swt.widgets.Text) KeyListener(org.eclipse.swt.events.KeyListener) DoubleField(de.jaret.util.ui.DoubleField)

Example 4 with KeyEvent

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

the class BrowserViewPart method createSearchArea.

private Composite createSearchArea(Composite parent) {
    GridLayout gridLayout = new GridLayout(3, false);
    parent.setLayout(gridLayout);
    GridData gd_seachArea = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    parent.setLayoutData(gd_seachArea);
    keyWordForSearch = new Text(parent, SWT.SEARCH);
    GridData gd_keyWordForSearch = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    gd_keyWordForSearch.heightHint = 20;
    keyWordForSearch.setLayoutData(gd_keyWordForSearch);
    keyWordForSearch.setText("");
    font = keyWordForSearch.getFont();
    FontData fontData = font.getFontData()[0];
    fontData.setStyle(fontData.getStyle());
    fontData.setHeight(12);
    font = new Font(Display.getDefault(), fontData);
    keyWordForSearch.setFont(font);
    keyWordForSearch.addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        // TODO Auto-generated method stub
        }

        @Override
        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub
            if (e.keyCode == SWT.CR || e.keyCode == SWT.LF) {
                refreshKeyWordSearch(true);
            }
        }
    });
    Button searchBtn = new Button(parent, SWT.NONE);
    searchBtn.setText(Messages.getString("Websearch.browserViewPart.searchBtnLbl"));
    searchBtn.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    searchBtn.addSelectionListener(new SelectionAdapter() {

        /**
			 * (non-Javadoc)
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
			 */
        @Override
        public void widgetSelected(SelectionEvent e) {
            refreshKeyWordSearch(true);
        }
    });
    Button settingBtn = new Button(parent, SWT.NONE);
    settingBtn.setText(Messages.getString("Websearch.browserViewPart.settingBtnLbl"));
    settingBtn.setLayoutData(new GridData(GridData.FILL_VERTICAL));
    settingBtn.addSelectionListener(new SelectionAdapter() {

        /**
			 * (non-Javadoc)
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
			 */
        @Override
        public void widgetSelected(SelectionEvent e) {
            PreferenceUtil.openPreferenceDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), WebSearchPreferencePage.ID);
        }
    });
    return parent;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) FontData(org.eclipse.swt.graphics.FontData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text) KeyListener(org.eclipse.swt.events.KeyListener) Font(org.eclipse.swt.graphics.Font)

Example 5 with KeyEvent

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

the class TextCellEditor method activateCell.

@Override
protected Control activateCell(final Composite parent, Object originalCanonicalValue, Character initialEditValue) {
    text = createTextControl(parent);
    // If we have an initial value, then 
    if (initialEditValue != null) {
        selectionMode = EditorSelectionEnum.END;
        text.setText(initialEditValue.toString());
        selectText();
    } else {
        setCanonicalValue(originalCanonicalValue);
    }
    if (!isEditable()) {
        text.setEditable(false);
    }
    text.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if ((event.keyCode == SWT.CR && event.stateMask == 0) || (event.keyCode == SWT.KEYPAD_CR && event.stateMask == 0)) {
                commit(MoveDirectionEnum.NONE);
            } else if (event.keyCode == SWT.ESC && event.stateMask == 0) {
                close();
            }
        }
    });
    text.addTraverseListener(new TraverseListener() {

        public void keyTraversed(TraverseEvent event) {
            boolean committed = false;
            if (event.keyCode == SWT.TAB && event.stateMask == SWT.SHIFT) {
                committed = commit(MoveDirectionEnum.LEFT);
            } else if (event.keyCode == SWT.TAB && event.stateMask == 0) {
                committed = commit(MoveDirectionEnum.RIGHT);
            }
            if (!committed) {
                event.doit = false;
            }
        }
    });
    text.forceFocus();
    return text;
}
Also used : KeyEvent(org.eclipse.swt.events.KeyEvent) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) KeyAdapter(org.eclipse.swt.events.KeyAdapter)

Aggregations

KeyEvent (org.eclipse.swt.events.KeyEvent)98 KeyAdapter (org.eclipse.swt.events.KeyAdapter)63 GridData (org.eclipse.swt.layout.GridData)54 GridLayout (org.eclipse.swt.layout.GridLayout)42 Composite (org.eclipse.swt.widgets.Composite)42 SelectionEvent (org.eclipse.swt.events.SelectionEvent)41 Text (org.eclipse.swt.widgets.Text)34 KeyListener (org.eclipse.swt.events.KeyListener)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)32 Label (org.eclipse.swt.widgets.Label)29 ModifyEvent (org.eclipse.swt.events.ModifyEvent)22 ModifyListener (org.eclipse.swt.events.ModifyListener)22 Point (org.eclipse.swt.graphics.Point)21 Button (org.eclipse.swt.widgets.Button)21 MouseEvent (org.eclipse.swt.events.MouseEvent)20 TableViewer (org.eclipse.jface.viewers.TableViewer)19 StyledText (org.eclipse.swt.custom.StyledText)13 FocusEvent (org.eclipse.swt.events.FocusEvent)13 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)12 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)12