use of org.eclipse.swt.events.VerifyListener 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.VerifyListener in project dbeaver by serge-rider.
the class BitStringInlineEditor method createControl.
@Override
protected Text createControl(Composite editPlaceholder) {
final boolean inline = valueController.getEditType() == IValueController.EditType.INLINE;
final Text editor = new Text(valueController.getEditPlaceholder(), inline ? SWT.BORDER : SWT.NONE);
editor.setEditable(!valueController.isReadOnly());
final int precision = valueController.getValueType().getPrecision();
editor.setTextLimit(precision <= 1 ? 1 : precision);
editor.addVerifyListener(new VerifyListener() {
@Override
public void verifyText(VerifyEvent e) {
for (int i = 0; i < e.text.length(); i++) {
char ch = e.text.charAt(i);
if (ch != '0' && ch != '1') {
e.doit = false;
return;
}
}
e.doit = true;
}
});
return editor;
}
use of org.eclipse.swt.events.VerifyListener 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.VerifyListener in project cubrid-manager by CUBRID.
the class ConnectionComposite method createBrokerInfoGroup.
private void createBrokerInfoGroup(Composite composite) {
Group brokerInfoGroup = new Group(composite, SWT.NONE);
brokerInfoGroup.setText(Messages.grpBrokerInfo);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
brokerInfoGroup.setLayoutData(gridData);
brokerInfoGroup.setLayout(createGridLayout(3));
Label brokerIpLabel = new Label(brokerInfoGroup, SWT.LEFT);
brokerIpLabel.setText(Messages.lblLoginServerName);
brokerIpLabel.setLayoutData(createGridData(1, 1, -1, -1));
brokerIpText = new Text(brokerInfoGroup, SWT.LEFT | SWT.BORDER);
brokerIpText.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 2, 1, 100, -1));
brokerIpText.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent event) {
brokerIpText.selectAll();
}
});
Label brokerPortLabel = new Label(brokerInfoGroup, SWT.LEFT);
brokerPortLabel.setText(Messages.lblLoginBrokerPort);
brokerPortLabel.setLayoutData(createGridData(1, 1, -1, -1));
VerifyListener verifyListener = new VerifyListener() {
public void verifyText(VerifyEvent event) {
Pattern pattern = Pattern.compile("[0-9]*");
Matcher matcher = pattern.matcher(event.text);
if (matcher.matches()) {
event.doit = true;
} else if (event.text.length() > 0) {
event.doit = false;
} else {
event.doit = true;
}
}
};
Composite portAndShardComp = new Composite(brokerInfoGroup, SWT.NONE);
portAndShardComp.setLayout(createGridLayout(3, 0, 0));
portAndShardComp.setLayoutData(createGridData(FILL_HORIZONTAL, 2, 1, -1, -1));
if (isMultiBroker) {
brokerPortCombo = new Combo(portAndShardComp, SWT.LEFT | SWT.BORDER);
brokerPortCombo.setLayoutData(createGridData(GridData.BEGINNING, 1, 1, 100, -1));
brokerPortCombo.addVerifyListener(verifyListener);
} else {
brokerPortText = new Text(portAndShardComp, SWT.LEFT | SWT.BORDER);
brokerPortText.setLayoutData(createGridData(BEGINNING, 1, 1, 100, -1));
brokerPortText.addVerifyListener(verifyListener);
}
btnShard = new Button(portAndShardComp, SWT.CHECK);
btnShard.setLayoutData(createGridData(BEGINNING, 1, 1, -1, -1));
btnShard.setText(com.cubrid.common.ui.query.Messages.shardBrokerLabel);
btnShard.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (btnShard.getSelection()) {
openWarningBox(shardBrokerAlert);
}
btnShardId.setEnabled(btnShard.getSelection());
}
});
btnShardId = new Button(portAndShardComp, SWT.PUSH);
btnShardId.setLayoutData(createGridData(HORIZONTAL_ALIGN_END, 1, 1, -1, -1));
btnShardId.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
dialog.setDatabaseInfo(dbInfo);
dialog.setShardId(curShardId);
dialog.setShardVal(curShardVal);
dialog.setShardQueryType(shardQueryType);
if (dialog.open() == OK_ID) {
curShardId = dialog.getShardId();
curShardVal = dialog.getShardVal();
shardQueryType = dialog.getShardQueryType();
if (dbInfo != null) {
dbInfo.setCurrentShardId(curShardId);
dbInfo.setCurrentShardVal(curShardVal);
dbInfo.setShardQueryType(shardQueryType);
}
updateShardIdButtonText();
}
}
});
updateShardIdButtonText();
Label charsetLabel = new Label(brokerInfoGroup, SWT.LEFT);
charsetLabel.setText(com.cubrid.common.ui.query.Messages.lblCharSet);
charsetLabel.setLayoutData(createGridData(1, 1, -1, -1));
charsetCombo = new Combo(brokerInfoGroup, SWT.LEFT | SWT.BORDER);
charsetCombo.setLayoutData(createGridData(FILL_HORIZONTAL, 2, 1, 100, -1));
Label jdbcLabel = new Label(brokerInfoGroup, SWT.LEFT);
jdbcLabel.setText(Messages.lblDbJdbcVersion);
jdbcLabel.setLayoutData(createGridData(1, 1, -1, -1));
jdbcCombo = new Combo(brokerInfoGroup, SWT.LEFT | SWT.READ_ONLY | SWT.BORDER);
jdbcCombo.setLayoutData(createGridData(FILL_HORIZONTAL, 1, 1, 100, -1));
Button btnOpen = new Button(brokerInfoGroup, SWT.NONE);
btnOpen.setText(Messages.btnBrowse);
btnOpen.setLayoutData(createGridData(1, 1, 80, -1));
btnOpen.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
JdbcManageDialog dialog = new JdbcManageDialog(getShell());
if (dialog.open() == OK_ID) {
String jdbcVersion = dialog.getSelectedJdbcVersion();
if (isBlank(jdbcVersion)) {
jdbcVersion = jdbcCombo.getText();
}
resetJdbcCombo(jdbcVersion);
}
}
});
// JDBC attributes
Label attrLabel = new Label(brokerInfoGroup, SWT.LEFT);
attrLabel.setText(Messages.lblJdbcAttr);
attrLabel.setLayoutData(createGridData(1, 1, -1, -1));
attrText = new Text(brokerInfoGroup, SWT.LEFT | SWT.BORDER);
attrText.setEditable(false);
attrText.setLayoutData(createGridData(FILL_HORIZONTAL, 1, 1, 100, -1));
Button btnAttr = new Button(brokerInfoGroup, SWT.NONE);
btnAttr.setText(Messages.btnJdbcAttr);
btnAttr.setLayoutData(createGridData(1, 1, 80, -1));
btnAttr.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
JdbcOptionDialog dialog = new JdbcOptionDialog(getShell(), attrText.getText());
if (dialog.open() == OK_ID) {
attrText.setText(dialog.getJdbcOptions());
}
}
});
}
use of org.eclipse.swt.events.VerifyListener in project cubrid-manager by CUBRID.
the class BrokersParameterPropertyPage method initial.
/**
* Initializes the parameters of this dialog
*/
private void initial() {
oldConfParaMap = node.getServer().getServerInfo().getBrokerConfParaMap();
Map<String, String> map = null;
if (oldConfParaMap != null) {
map = oldConfParaMap.get(ConfConstants.BROKER_SECTION_NAME);
}
if (map != null) {
Iterator<Map.Entry<String, String>> it = map.entrySet().iterator();
Map<String, String> defaultMap = new HashMap<String, String>();
defaultValueMap.put(ConfConstants.BROKER_SECTION_NAME, defaultMap);
while (it.hasNext()) {
Map.Entry<String, String> entry = it.next();
defaultMap.put(entry.getKey(), entry.getValue());
}
if (null == defaultMap.get(ConfConstants.MASTER_SHM_ID)) {
masterShmIdTxt.setText("");
} else {
masterShmIdTxt.setText(defaultMap.get(ConfConstants.MASTER_SHM_ID));
}
if (null == defaultMap.get(ConfConstants.ADMIN_LOG_FILE)) {
adminlogTxt.setText("");
} else {
adminlogTxt.setText(defaultMap.get(ConfConstants.ADMIN_LOG_FILE));
}
if (isSupportEnableAccessControl) {
if (null == defaultMap.get(ConfConstants.ENABLE_ACCESS_CONTROL)) {
enableAccessControlCombo.select(1);
} else {
enableAccessControlCombo.setText(defaultMap.get(ConfConstants.ENABLE_ACCESS_CONTROL));
}
if (null == defaultMap.get(ConfConstants.ACCESS_CONTROL_FILE)) {
accessControlFileTxt.setText("");
} else {
accessControlFileTxt.setText(defaultMap.get(ConfConstants.ACCESS_CONTROL_FILE));
}
}
}
brokerList = new ArrayList<Map<String, String>>();
if (oldConfParaMap == null) {
return;
}
// set the broker list
String[][] supportedBrokerParams = ConfConstants.getBrokerParameters(serverInfo);
for (Map.Entry<String, Map<String, String>> brokerPara : oldConfParaMap.entrySet()) {
if (brokerPara.getKey().equals(ConfConstants.BROKER_SECTION_NAME)) {
continue;
}
String name = brokerPara.getKey();
Map<String, String> pair = brokerPara.getValue();
String port = pair.get(ConfConstants.BROKER_PORT);
Map<String, String> dataMap = new HashMap<String, String>();
dataMap.put("0", name);
dataMap.put("1", port);
for (int i = 0; i < supportedBrokerParams.length; i++) {
String paramKey = supportedBrokerParams[i][0];
String value = pair.get(paramKey);
dataMap.put(paramKey, value);
}
brokerList.add(dataMap);
}
brokersTableViewer.setInput(brokerList);
// initialize refresh
BrokerIntervalSettingManager manager = BrokerIntervalSettingManager.getInstance();
serverName = node.getServer().getLabel();
brokerEnvName = node.getLabel();
BrokerIntervalSetting setting = manager.getBrokerIntervalSetting(serverName, brokerEnvName);
oldIntervalSettingMap = new HashMap<String, BrokerIntervalSetting>();
newIntervalSettingMap = new HashMap<String, BrokerIntervalSetting>();
if (null != setting) {
boolean isOn = setting.isOn();
refreshBtn.setSelection(isOn);
intervalTxt.setText(setting.getInterval());
intervalTxt.setEnabled(isOn);
oldIntervalSettingMap.put(serverName + "_" + brokerEnvName, setting);
}
for (Map<String, String> dataMap : brokerList) {
String brokername = dataMap.get("0");
setting = manager.getBrokerIntervalSetting(serverName, brokername);
if (null != setting) {
oldIntervalSettingMap.put(serverName + "_" + brokername, setting);
}
}
for (Map.Entry<String, BrokerIntervalSetting> entry : oldIntervalSettingMap.entrySet()) {
String aSettingName = entry.getKey();
BrokerIntervalSetting aSetting = new BrokerIntervalSetting();
String aBrokerName = entry.getValue().getBrokerName();
String aServerName = entry.getValue().getServerName();
String aInterval = entry.getValue().getInterval();
boolean aOn = entry.getValue().isOn();
aSetting.setBrokerName(aBrokerName);
aSetting.setServerName(aServerName);
aSetting.setInterval(aInterval);
aSetting.setOn(aOn);
newIntervalSettingMap.put(aSettingName, aSetting);
}
// add Listener
refreshBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
BrokerIntervalSetting brokerEnvSetting = newIntervalSettingMap.get(serverName + "_" + brokerEnvName);
if (refreshBtn.getSelection()) {
intervalTxt.setEnabled(true);
brokerEnvSetting.setOn(true);
} else {
intervalTxt.setEnabled(false);
brokerEnvSetting.setOn(false);
}
}
});
intervalTxt.addVerifyListener(new VerifyListener() {
public void verifyText(VerifyEvent event) {
if (!"".equals(event.text) && !ValidateUtil.isNumber(event.text)) {
event.doit = false;
return;
}
}
});
intervalTxt.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent event) {
String newInterval = intervalTxt.getText().trim();
BrokerIntervalSetting brokerEnvSetting = newIntervalSettingMap.get(serverName + "_" + brokerEnvName);
brokerEnvSetting.setInterval(newInterval);
}
});
}
Aggregations