use of org.eclipse.swt.events.KeyAdapter 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;
}
use of org.eclipse.swt.events.KeyAdapter 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;
}
use of org.eclipse.swt.events.KeyAdapter in project translationstudio8 by heartsome.
the class NatCombo method createTextControl.
private void createTextControl() {
text = new Text(this, HorizontalAlignmentEnum.getSWTStyle(cellStyle));
text.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
text.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
text.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
text.setLayoutData(gridData);
text.forceFocus();
text.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.ARROW_DOWN || event.keyCode == SWT.ARROW_UP) {
showDropdownControl();
int selectionIndex = dropdownList.getSelectionIndex();
selectionIndex += event.keyCode == SWT.ARROW_DOWN ? 1 : -1;
if (selectionIndex < 0) {
selectionIndex = 0;
}
dropdownList.select(selectionIndex);
text.setText(dropdownList.getSelection()[0]);
}
}
});
iconImage = GUIHelper.getImage("down_2");
final Canvas iconCanvas = new Canvas(this, SWT.NONE) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
Rectangle iconImageBounds = iconImage.getBounds();
return new Point(iconImageBounds.width + 2, iconImageBounds.height + 2);
}
};
gridData = new GridData(GridData.BEGINNING, SWT.FILL, false, true);
iconCanvas.setLayoutData(gridData);
iconCanvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent event) {
GC gc = event.gc;
Rectangle iconCanvasBounds = iconCanvas.getBounds();
Rectangle iconImageBounds = iconImage.getBounds();
int horizontalAlignmentPadding = CellStyleUtil.getHorizontalAlignmentPadding(HorizontalAlignmentEnum.CENTER, iconCanvasBounds, iconImageBounds.width);
int verticalAlignmentPadding = CellStyleUtil.getVerticalAlignmentPadding(VerticalAlignmentEnum.MIDDLE, iconCanvasBounds, iconImageBounds.height);
gc.drawImage(iconImage, horizontalAlignmentPadding, verticalAlignmentPadding);
Color originalFg = gc.getForeground();
gc.setForeground(GUIHelper.COLOR_WIDGET_BORDER);
gc.drawRectangle(0, 0, iconCanvasBounds.width - 1, iconCanvasBounds.height - 1);
gc.setForeground(originalFg);
}
});
iconCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
showDropdownControl();
}
});
}
use of org.eclipse.swt.events.KeyAdapter in project translationstudio8 by heartsome.
the class XLIFFEditorImplWithNatTable method addFilterComposite.
/**
* 添加填充过滤器面板内容的面板
* @param parent
* @return 过滤器面板;
*/
private void addFilterComposite(Composite main) {
Composite top = new Composite(main, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).margins(0, 0).applyTo(top);
top.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// 输入行号进行定位
final String rowLocationStr = Messages.getString("editor.XLIFFEditorImplWithNatTable.rowLocationStr");
Text txtRowLocation = new Text(top, SWT.BORDER);
txtRowLocation.setText(rowLocationStr);
int width = 40;
if (Util.isLinux()) {
width = 35;
}
GridDataFactory.swtDefaults().hint(width, SWT.DEFAULT).applyTo(txtRowLocation);
txtRowLocation.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
Text text = (Text) e.widget;
if (rowLocationStr.equals(text.getText())) {
text.setText("");
}
}
@Override
public void focusLost(FocusEvent e) {
Text text = (Text) e.widget;
if ("".equals(text.getText())) {
text.setText(rowLocationStr);
}
}
});
txtRowLocation.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent event) {
if (event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {
String rowNumString = ((Text) event.widget).getText().trim();
if (rowNumString != null && !"".equals(rowNumString)) {
int rowPosition;
try {
rowPosition = Integer.parseInt(rowNumString) - 1;
jumpToRow(rowPosition, false);
updateStatusLine();
} catch (NumberFormatException e) {
Text text = (Text) event.widget;
text.setText("");
}
}
}
}
});
txtRowLocation.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent event) {
if (event.keyCode == 0 && event.stateMask == 0) {
// 文本框得到焦点时
} else if (Character.isDigit(event.character) || event.character == '\b' || event.keyCode == 127) {
// 输入数字,或者按下Backspace、Delete键
if ("".equals(((Text) event.widget).getText().trim()) && event.character == '0') {
event.doit = false;
} else {
event.doit = true;
}
} else {
event.doit = false;
}
}
});
cmbFilter = new Combo(top, SWT.BORDER | SWT.READ_ONLY);
cmbFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// TODO 完善过滤器初始化数据。
// cmbFilter.add("所有文本段");
// cmbFilter.add("未翻译文本段");
// cmbFilter.add("已翻译文本段");
// cmbFilter.add("未批准文本段");
// cmbFilter.add("已批准文本段");
// cmbFilter.add("有批注文本段");
// cmbFilter.add("锁定文本段");
// cmbFilter.add("未锁定文本段");
// cmbFilter.add("重复文本段");
// cmbFilter.add("疑问文本段");
// cmbFilter.add("上下文匹配文本段");
// cmbFilter.add("完全匹配文本段");
// cmbFilter.add("模糊匹配文本段");
// cmbFilter.add("快速翻译文本段");
// cmbFilter.add("自动繁殖文本段");
// cmbFilter.add("错误标记文本段");
// cmbFilter.add("术语不一致文本段");
// cmbFilter.add("译文不一致文本段");
// cmbFilter.add("带修订标记文本段");
final Set<String> filterNames = XLFHandler.getFilterNames();
for (String filterName : filterNames) {
cmbFilter.add(filterName);
}
// 添加选项改变监听
cmbFilter.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Fixed Bug #2243 by Jason 当鼠标焦点在源文单元框中使用过滤器,对过滤后的译文进行操作会提示该行锁定不能操作
// ActiveCellEditor.commit();
HsMultiActiveCellEditor.commit(true);
Combo cmbFilter = (Combo) e.widget;
boolean isUpdated = handler.doFilter(cmbFilter.getText(), langFilterCondition);
if (isUpdated) {
if (table != null) {
bodyLayer.getSelectionLayer().clear();
if (bodyLayer.selectionLayer.getRowCount() > 0) {
// 默认选中第一行
HsMultiActiveCellEditor.commit(true);
bodyLayer.selectionLayer.doCommand(new SelectCellCommand(bodyLayer.getSelectionLayer(), getTgtColumnIndex(), isHorizontalLayout ? 0 : 1, false, false));
HsMultiCellEditorControl.activeSourceAndTargetCell(XLIFFEditorImplWithNatTable.this);
}
table.setFocus();
}
// 自动调整 NatTable 大小 ;
autoResize();
// 更新状态栏
updateStatusLine();
NattableUtil.refreshCommand(XLIFFEditorSelectionPropertyTester.PROPERTY_NAMESPACE, XLIFFEditorSelectionPropertyTester.PROPERTY_ENABLED);
}
}
});
Button btnSaveFilter = new Button(top, SWT.NONE);
// TODO 考虑换成图片显示。
btnSaveFilter.setText(Messages.getString("editor.XLIFFEditorImplWithNatTable.btnAddFilter"));
btnSaveFilter.setToolTipText(Messages.getString("editor.XLIFFEditorImplWithNatTable.btnAddFilterTooltip"));
btnSaveFilter.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CustomFilterDialog dialog = new CustomFilterDialog(table.getShell(), cmbFilter);
dialog.open();
// int res = dialog.open();
// if (res == CustomFilterDialog.OK) {
// cmbFilter.select(cmbFilter.getItemCount() - 1); // 选中最后一行数据
// cmbFilter.notifyListeners(SWT.Selection, null);
// }
}
});
// 默认选中第一行数据
cmbFilter.select(0);
cmbFilter.notifyListeners(SWT.Selection, null);
// 更新nattable的列名为语言对
renameColumn();
top.pack();
}
use of org.eclipse.swt.events.KeyAdapter in project tdi-studio-se by Talend.
the class JSONFileOutputStep3Form method addFieldsListeners.
@Override
protected void addFieldsListeners() {
metadataNameText.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
MetadataToolHelper.validateSchema(metadataNameText.getText());
metadataTable.setLabel(metadataNameText.getText());
checkFieldsValue();
}
});
metadataNameText.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
MetadataToolHelper.checkSchema(getShell(), e);
}
});
metadataCommentText.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
metadataTable.setComment(metadataCommentText.getText());
}
});
tableEditorView.getMetadataEditor().addAfterOperationListListener(new IListenableListListener() {
public void handleEvent(ListenableListEvent event) {
checkFieldsValue();
}
});
}
Aggregations