use of org.eclipse.swt.events.FocusAdapter in project cogtool by cogtool.
the class ActionSet method createTransitionName.
private Text createTransitionName(Composite parent, String txt) {
final Text name = new Text(parent, SWT.BORDER);
final NameInfo info = new NameInfo(txt);
// Note that we have to use a VerifyListener to prevent editing the
// contents of the Text, as SWT has made the rather surprising decision
// that setting its editable field to false also
// takes away our ability to select and navigate in the field, and copy
// its contents. Grr.
name.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent evt) {
// the user's trying to modify an already populated Text. Yuk.
switch(transitionNameState) {
case NORMAL:
info.fullName = evt.text;
evt.text = SWTStringUtil.insertEllipsis(info.fullName, name.getSize().x, StringUtil.EQUAL, name.getFont());
break;
case HAS_FOCUS:
evt.doit = false;
break;
case GAINING_FOCUS:
break;
}
}
});
name.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent evt) {
transitionNameState = TransitionNameState.GAINING_FOCUS;
name.setText(info.fullName);
transitionNameState = TransitionNameState.HAS_FOCUS;
}
@Override
public void focusLost(FocusEvent evt) {
transitionNameState = TransitionNameState.NORMAL;
name.setText(info.fullName);
}
});
name.setText(txt);
return name;
}
use of org.eclipse.swt.events.FocusAdapter in project dbeaver by serge-rider.
the class CustomCheckboxCellEditor method createControl.
@Override
protected Control createControl(Composite parent) {
checkBox = new Button(parent, SWT.CHECK);
checkBox.setFont(parent.getFont());
checkBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
applyEditorValue();
// This is needed for MacOS
fireApplyEditorValue();
}
});
checkBox.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
CustomCheckboxCellEditor.this.focusLost();
}
});
return checkBox;
}
use of org.eclipse.swt.events.FocusAdapter 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.FocusAdapter 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.FocusAdapter in project translationstudio8 by heartsome.
the class EquivalentPage method validEquiTxt.
/**
* 验证用户输入的加权系数的正确性
* @param equiTxt
*/
private void validEquiTxt(final Text equiTxt) {
final String defaultStr = "0.50";
equiTxt.setText(defaultStr);
equiTxt.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
String textStr = equiTxt.getText().trim();
if (textStr == null || textStr.trim().length() == 0) {
equiTxt.setText(defaultStr);
} else {
String regular = "1\\.(0){0,2}|0\\.\\d{0,2}";
if (!textStr.matches(regular)) {
MessageDialog.openInformation(getShell(), Messages.getString("preference.EquivalentPage.msgTitle"), Messages.getString("preference.EquivalentPage.msg5"));
equiTxt.setText(defaultStr);
}
}
}
});
}
Aggregations