use of org.eclipse.swt.events.FocusEvent in project dbeaver by serge-rider.
the class PrefPageProjectSettings method createContents.
@Override
protected Control createContents(final Composite parent) {
Composite composite = UIUtils.createPlaceholder(parent, 1, 5);
{
UIUtils.createControlLabel(composite, "Resource locations");
resourceTable = new Table(composite, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
resourceTable.setLayoutData(new GridData(GridData.FILL_BOTH));
resourceTable.setHeaderVisible(true);
resourceTable.setLinesVisible(true);
UIUtils.createTableColumn(resourceTable, SWT.LEFT, "Resource");
UIUtils.createTableColumn(resourceTable, SWT.LEFT, "Folder");
resourceTable.setHeaderVisible(true);
resourceTable.setLayoutData(new GridData(GridData.FILL_BOTH));
handlerTableEditor = new TableEditor(resourceTable);
handlerTableEditor.verticalAlignment = SWT.TOP;
handlerTableEditor.horizontalAlignment = SWT.RIGHT;
handlerTableEditor.grabHorizontal = true;
handlerTableEditor.grabVertical = true;
resourceTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent e) {
disposeOldEditor();
final TableItem item = resourceTable.getItem(new Point(0, e.y));
if (item == null) {
return;
}
int columnIndex = UIUtils.getColumnAtPos(item, e.x, e.y);
if (columnIndex <= 0) {
return;
}
if (columnIndex == 1) {
final String resourcePath = item.getText(1);
if (project != null) {
final IFolder folder = project.getFolder(resourcePath);
ContainerSelectionDialog dialog = new ContainerSelectionDialog(resourceTable.getShell(), folder, true, "Select " + item.getText(0) + " root folder");
dialog.showClosedProjects(false);
dialog.setValidator(new ISelectionValidator() {
@Override
public String isValid(Object selection) {
if (selection instanceof IPath) {
final File file = ((IPath) selection).toFile();
if (file.isHidden() || file.getName().startsWith(".")) {
return "Can't use hidden folders";
}
final String[] segments = ((IPath) selection).segments();
if (!project.getName().equals(segments[0])) {
return "Can't store resources in another project";
}
}
return null;
}
});
if (dialog.open() == IDialogConstants.OK_ID) {
final Object[] result = dialog.getResult();
if (result.length == 1 && result[0] instanceof IPath) {
final IPath plainPath = ((IPath) result[0]).removeFirstSegments(1).removeTrailingSeparator();
item.setText(1, plainPath.toString());
}
}
} else {
final Text editor = new Text(resourceTable, SWT.NONE);
editor.setText(resourcePath);
editor.selectAll();
handlerTableEditor.setEditor(editor, item, 1);
editor.setFocus();
editor.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
item.setText(1, editor.getText());
}
});
}
}
}
});
}
performDefaults();
return composite;
}
use of org.eclipse.swt.events.FocusEvent in project translationstudio8 by heartsome.
the class NatTable method initInternalListener.
protected void initInternalListener() {
modeSupport = new ModeSupport(this);
modeSupport.registerModeEventHandler(Mode.NORMAL_MODE, new ConfigurableModeEventHandler(modeSupport, this));
modeSupport.switchMode(Mode.NORMAL_MODE);
addPaintListener(this);
addFocusListener(new FocusListener() {
public void focusLost(final FocusEvent arg0) {
redraw();
}
public void focusGained(final FocusEvent arg0) {
redraw();
}
});
addListener(SWT.Resize, new Listener() {
public void handleEvent(final Event e) {
doCommand(new ClientAreaResizeCommand(NatTable.this));
}
});
}
use of org.eclipse.swt.events.FocusEvent in project translationstudio8 by heartsome.
the class AddOrEditXmlConvertConfigDialog method createRootTxt.
/**
* 创建xml根,与存储目录
* @param tparent
* ;
*/
private void createRootTxt(Composite tparent) {
Composite composite = new Composite(tparent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);
GridLayoutFactory.fillDefaults().spacing(0, SWT.DEFAULT).numColumns(5).applyTo(composite);
Label rootLbl = new Label(composite, SWT.NONE);
rootLbl.setText(Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.rootLbl"));
rootTxt = new Text(composite, SWT.BORDER);
GridDataFactory.fillDefaults().indent(6, SWT.DEFAULT).hint(100, SWT.DEFAULT).applyTo(rootTxt);
// 显示一个图标与“被保存到:”
Label iconLbl = new Label(composite, SWT.NONE);
iconLbl.setImage(icon);
GridDataFactory.fillDefaults().indent(4, SWT.DEFAULT).applyTo(iconLbl);
Label textLbl = new Label(composite, SWT.NONE);
textLbl.setText(Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.textLbl"));
rootTipLbl = new Label(composite, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.LEFT, SWT.CENTER).applyTo(rootTipLbl);
rootTxt.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
String tipText = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootTxt.getText().trim() + ".xml").toOSString();
rootTipLbl.setText(tipText);
rootTipLbl.pack();
rootTipLbl.setToolTipText(tipText);
}
});
// 在添加状态下,当根元素文本框失去焦点后,验证是否为空,验证是否重复
rootTxt.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
String rootStr = rootTxt.getText().trim();
if (isAdd || (!rootStr.equals(curRootStr))) {
if ("".equals(rootStr)) {
MessageDialog.openWarning(getShell(), Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.msgTitle1"), Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.msg1"));
} else {
// 提示文件是否重复
String configXmlLoaction = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
File xmlConfigFile = new File(configXmlLoaction);
if (xmlConfigFile.exists()) {
String configXmlFullPath = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
MessageDialog.openWarning(getShell(), Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.msgTitle1"), MessageFormat.format(Messages.getString("dialogs.AddOrEditXmlConvertConfigDialog.msg2"), configXmlFullPath));
}
}
super.focusLost(e);
}
}
});
}
use of org.eclipse.swt.events.FocusEvent in project translationstudio8 by heartsome.
the class AnalysisXmlConvertConfigDialg method createRootTxt.
private void createRootTxt(Composite tparent) {
Composite composite = new Composite(tparent, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);
GridLayoutFactory.fillDefaults().spacing(0, 1).numColumns(5).applyTo(composite);
Label analysisXmlLbl = new Label(composite, SWT.NONE);
analysisXmlLbl.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.analysisXmlLbl"));
GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(analysisXmlLbl);
Composite browseCmp = new Composite(composite, SWT.NONE);
GridDataFactory.fillDefaults().indent(6, SWT.DEFAULT).grab(true, false).span(4, SWT.DEFAULT).applyTo(browseCmp);
GridLayoutFactory.fillDefaults().numColumns(2).extendedMargins(0, 0, 0, 0).applyTo(browseCmp);
analysisTxt = new Text(browseCmp, SWT.BORDER);
GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(analysisTxt);
Button browseBtn = new Button(browseCmp, SWT.NONE);
browseBtn.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.browseBtn"));
Label rootLbl = new Label(composite, SWT.NONE);
rootLbl.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.rootLbl"));
GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(rootLbl);
rootTxt = new Text(composite, SWT.BORDER);
GridDataFactory.fillDefaults().indent(6, SWT.DEFAULT).hint(100, SWT.DEFAULT).applyTo(rootTxt);
// 显示一个图标与“被保存到:”
Label iconLbl = new Label(composite, SWT.NONE);
iconLbl.setImage(icon);
GridDataFactory.fillDefaults().indent(4, SWT.DEFAULT).applyTo(iconLbl);
Label textLbl = new Label(composite, SWT.NONE);
textLbl.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.textLbl"));
rootTipLbl = new Label(composite, SWT.NONE);
GridDataFactory.fillDefaults().grab(true, false).align(SWT.LEFT, SWT.CENTER).applyTo(rootTipLbl);
rootTxt.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
String tipText = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootTxt.getText().trim().toLowerCase() + ".xml").toOSString();
rootTipLbl.setText(tipText);
rootTipLbl.pack();
rootTipLbl.setToolTipText(tipText);
}
});
// 在添加状态下,当根元素文本框失去焦点后,验证是否为空,验证是否重复
rootTxt.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {
public void focusLost(FocusEvent e) {
String rootStr = rootTxt.getText().trim().toLowerCase();
if ("".equals(rootStr)) {
MessageDialog.openInformation(getShell(), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msgTitle"), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msg1"));
} else {
// 提示文件是否重复
String configXmlLoaction = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
File xmlConfigFile = new File(configXmlLoaction);
if (xmlConfigFile.exists()) {
String configXmlFullPath = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
MessageDialog.openInformation(getShell(), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msgTitle"), MessageFormat.format(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msg2"), configXmlFullPath));
}
}
super.focusLost(e);
}
});
browseBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
String[] extensions = { "*.xml", "*" };
String[] names = { Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.filterXML"), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.filterAll") };
fd.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.fdTitle"));
fd.setFilterExtensions(extensions);
fd.setFilterNames(names);
String xmlLocation = fd.open();
analysisTxt.setText(xmlLocation);
// 解析XML文件并且填充到列表
analysisXml(xmlLocation);
}
});
analysisTxt.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
analysisXml(analysisTxt.getText());
super.focusLost(e);
}
});
}
use of org.eclipse.swt.events.FocusEvent in project translationstudio8 by heartsome.
the class CustomFilterDialog method setGray.
/**
* 为Text控件增加灰色提醒,获得焦点时自动清除灰色提醒
* @param text
* Text控件
* @param initTxt
* 灰色提醒字符串
*/
private void setGray(final Text text, final String initTxt) {
text.setForeground(gray);
text.setText(initTxt);
text.addFocusListener(new FocusListener() {
public void focusLost(FocusEvent arg0) {
if (text.getText().trim().equals("")) {
if (!text.getForeground().equals(gray)) {
text.setForeground(gray);
}
text.setText(initTxt);
} else {
if (!text.getForeground().equals(black)) {
text.setForeground(black);
}
}
}
public void focusGained(FocusEvent arg0) {
if (text.getText().trim().equals(initTxt)) {
text.setText("");
text.setForeground(black);
} else {
if (!text.getForeground().equals(black)) {
text.setForeground(black);
}
}
}
});
}
Aggregations