use of org.eclipse.swt.events.FocusListener in project cubrid-manager by CUBRID.
the class SetAutoAddVolumeDialog method init.
/**
* Initials some values
*
*/
private void init() {
int itemsSize = RATEMAX - RATEMIN + 1;
String[] itemsOfOutRate;
itemsOfOutRate = new String[itemsSize];
for (int i = 0; i < itemsSize; i++) {
itemsOfOutRate[i] = Integer.toString(RATEMIN + i);
}
// Sets the initial value
if (getAutoAddVolumeInfo.getData().equals(OnOffType.ON.getText())) {
dataUsingAutoVolButton.setSelection(true);
dataOutRateCombo.setEnabled(true);
dataVolumeText.setEnabled(true);
dataExtPageText.setEnabled(true);
} else {
dataUsingAutoVolButton.setSelection(false);
dataOutRateCombo.setEnabled(false);
dataVolumeText.setEnabled(false);
dataExtPageText.setEnabled(false);
}
if (getAutoAddVolumeInfo.getIndex().equals(OnOffType.ON.getText())) {
indexUsingAutoVolButton.setSelection(true);
indexOutRateCombo.setEnabled(true);
indexVolumeText.setEnabled(true);
indexExtPageText.setEnabled(true);
} else {
indexUsingAutoVolButton.setSelection(false);
indexOutRateCombo.setEnabled(false);
indexVolumeText.setEnabled(false);
indexExtPageText.setEnabled(false);
}
int dataWarnOutofSpace = (int) ((Double.parseDouble(getAutoAddVolumeInfo.getData_warn_outofspace()) * 100) + 0.5);
int indexWarnOutofSpace = (int) ((Double.parseDouble(getAutoAddVolumeInfo.getIndex_warn_outofspace()) * 100) + 0.5);
if (dataWarnOutofSpace < RATEMIN) {
dataWarnOutofSpace = DEFAULT_RATE;
} else if (dataWarnOutofSpace > RATEMAX) {
dataWarnOutofSpace = RATEMAX;
}
if (indexWarnOutofSpace < RATEMIN) {
indexWarnOutofSpace = DEFAULT_RATE;
} else if (dataWarnOutofSpace > RATEMAX) {
indexWarnOutofSpace = RATEMAX;
}
dataOutRateCombo.setItems(itemsOfOutRate);
dataOutRateCombo.setText(Integer.toString(dataWarnOutofSpace));
indexOutRateCombo.setItems(itemsOfOutRate);
indexOutRateCombo.setText(Integer.toString(indexWarnOutofSpace));
BigDecimal dataExtPage = new BigDecimal(getAutoAddVolumeInfo.getData_ext_page());
BigDecimal indexExtPage = new BigDecimal(getAutoAddVolumeInfo.getIndex_ext_page());
if (dataExtPage.compareTo(BigDecimal.ZERO) <= 0) {
initDataVol = new BigDecimal(INIT_VOLUME);
dataExtPage = initDataVol.multiply(MEGABYTES).divide(pageSize, 0, BigDecimal.ROUND_HALF_UP);
} else {
initDataVol = dataExtPage.multiply(pageSize).divide(MEGABYTES, 3, BigDecimal.ROUND_HALF_UP);
}
if (indexExtPage.compareTo(BigDecimal.ZERO) <= 0) {
initIndexVol = new BigDecimal(INIT_VOLUME);
indexExtPage = initIndexVol.multiply(MEGABYTES).divide(pageSize, 0, BigDecimal.ROUND_HALF_UP);
} else {
initIndexVol = indexExtPage.multiply(pageSize).divide(MEGABYTES, 3, BigDecimal.ROUND_HALF_UP);
}
initDataExt = dataExtPage.toString();
initIndexExt = indexExtPage.toString();
dataExtPageText.setText(initDataExt);
dataVolumeText.setText(initDataVol.setScale(3).toString());
indexExtPageText.setText(initIndexExt);
indexVolumeText.setText(initIndexVol.setScale(3).toString());
dataOutRateCombo.addVerifyListener(new NumberVerifyListener());
dataOutRateCombo.addModifyListener(new DataRateModifyListener());
dataVolumeModifyListener = new VolumeModifyListener();
dataPageModifyListener = new PageModifyListener();
dataVolumeText.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent event) {
dataVolumeText.addModifyListener(dataVolumeModifyListener);
}
public void focusLost(FocusEvent event) {
dataVolumeText.removeModifyListener(dataVolumeModifyListener);
}
});
dataExtPageText.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent event) {
dataExtPageText.addModifyListener(dataPageModifyListener);
}
public void focusLost(FocusEvent event) {
dataExtPageText.removeModifyListener(dataPageModifyListener);
}
});
indexOutRateCombo.addVerifyListener(new NumberVerifyListener());
indexOutRateCombo.addModifyListener(new IndexRateModifyListener());
indexVolumeModifyListener = new VolumeModifyListener();
indexPageModifyListener = new PageModifyListener();
indexVolumeText.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent event) {
indexVolumeText.addModifyListener(indexVolumeModifyListener);
}
public void focusLost(FocusEvent event) {
indexVolumeText.removeModifyListener(indexVolumeModifyListener);
}
});
indexExtPageText.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent event) {
indexExtPageText.addModifyListener(indexPageModifyListener);
}
public void focusLost(FocusEvent event) {
indexExtPageText.removeModifyListener(indexPageModifyListener);
}
});
dataUsingAutoVolButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (dataUsingAutoVolButton.getSelection()) {
dataOutRateCombo.setEnabled(true);
dataVolumeText.setEnabled(true);
dataExtPageText.setEnabled(true);
} else {
dataOutRateCombo.setEnabled(false);
dataOutRateCombo.setText(Integer.toString(DEFAULT_RATE));
dataVolumeText.setText(initDataVol.toString());
dataExtPageText.setText(initDataExt);
enableOk();
dataVolumeText.setEnabled(false);
dataExtPageText.setEnabled(false);
}
}
});
indexUsingAutoVolButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
if (indexUsingAutoVolButton.getSelection()) {
indexOutRateCombo.setEnabled(true);
indexVolumeText.setEnabled(true);
indexExtPageText.setEnabled(true);
} else {
indexOutRateCombo.setEnabled(false);
indexOutRateCombo.setText(Integer.toString(DEFAULT_RATE));
indexVolumeText.setText(initIndexVol.toString());
indexExtPageText.setText(initIndexExt);
enableOk();
indexVolumeText.setEnabled(false);
indexExtPageText.setEnabled(false);
}
}
});
}
use of org.eclipse.swt.events.FocusListener in project tdi-studio-se by Talend.
the class TalendPaletteViewer method configListeners.
/**
* yzhang Comment method "configListeners".
*
* @param text
*/
private void configListeners(final Text text) {
text.addMouseListener(new MouseListener() {
@Override
public void mouseDoubleClick(MouseEvent e) {
}
@Override
public void mouseDown(MouseEvent e) {
if (text.getText().equals(SEARCH_COMPONENT)) {
//$NON-NLS-1$
text.setText("");
}
}
@Override
public void mouseUp(MouseEvent e) {
}
});
text.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
// text.setText(""); //$NON-NLS-1$
}
@Override
public void focusLost(FocusEvent e) {
if (text.getText() == "") {
//$NON-NLS-1$
text.setText(SEARCH_COMPONENT);
}
}
});
text.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
startFiltering(text);
}
});
}
use of org.eclipse.swt.events.FocusListener in project tdi-studio-se by Talend.
the class StyledTextHandler method addListeners.
/**
* DOC amaumont Comment method "addListeners".
*/
private void addListeners() {
styledText.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
refreshProposalSize();
}
public void focusLost(FocusEvent e) {
}
});
styledText.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
}
public void controlResized(ControlEvent e) {
refreshProposalSize();
}
});
styledText.addExtendedModifyListener(new ExtendedModifyListener() {
public void modifyText(ExtendedModifyEvent event) {
updateCellExpression();
// System.out.println("ExtendedModifyListener modify text");
}
});
styledText.getContent().addTextChangeListener(new TextChangeListener() {
public void textChanged(TextChangedEvent event) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void textChanging(TextChangingEvent event) {
// System.out.println("textChanging");
}
public void textSet(TextChangedEvent event) {
// System.out.println("textSet");
}
});
styledText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
});
styledText.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
});
styledText.addVerifyKeyListener(new VerifyKeyListener() {
public void verifyKey(VerifyEvent verifyEvent) {
if (verifyEvent.character == '\r' && contentProposalAdapter != null && contentProposalAdapter.isProposalOpened()) {
verifyEvent.doit = false;
} else {
verifyEvent.doit = true;
}
}
});
styledText.addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void mouseDown(MouseEvent e) {
highlightLineOfCursorPosition(styledText.getSelection());
}
public void mouseUp(MouseEvent e) {
}
});
}
use of org.eclipse.swt.events.FocusListener in project tdi-studio-se by Talend.
the class JSONFileStep1Form method addFields.
/*
* (non-Javadoc)
*
* @see org.talend.repository.ui.swt.utils.AbstractForm#addFields()
*/
@Override
protected void addFields() {
// Group File Location
Group group = Form.createGroup(this, 1, "File Settings", 100);
Composite compositeFileLocation = Form.startNewDimensionnedGridLayout(group, 3, WIDTH_GRIDDATA_PIXEL, 100);
GridData gridDataFileLocation = new GridData(GridData.FILL_HORIZONTAL);
gridDataFileLocation.minimumWidth = WIDTH_GRIDDATA_PIXEL;
group.setLayoutData(gridDataFileLocation);
// file Field XSD
// String[] xsdExtensions = { "*.xsd", "*.*", "*" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
// fileFieldXsd = new LabelledFileField(compositeFileLocation, Messages.getString("JSONFileStep1.filepathXsd"),
// xsdExtensions);
// checkBox IsGuess
// checkBoxIsGuess = new Button(compositeFileLocation, SWT.CHECK);
// labelIsGuess = new Label(compositeFileLocation, SWT.LEFT);
// GridData gridDataLabel = new GridData();
// gridDataLabel.horizontalSpan = 2;
// labelIsGuess.setLayoutData(gridDataLabel);
// labelIsGuess.setText(Messages.getString("JSONFileStep1.checkBoxIsGuess"));
// file Field JSON
List<String> readbyModeValues = EJsonReadbyMode.getUsableReadbyModeValues();
readbyCombo = new LabelledCombo(compositeFileLocation, "Read By", "Read By", readbyModeValues.toArray(new String[readbyModeValues.size()]), 2, true, SWT.READ_ONLY);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
String[] JSONExtensions = { "*.JSON", "*.*", "*" };
fileFieldJSON = new //$NON-NLS-1$
LabelledFileField(//$NON-NLS-1$
compositeFileLocation, //$NON-NLS-1$
"Json", JSONExtensions);
EMetadataEncoding[] values = EMetadataEncoding.values();
String[] encodingData = new String[values.length];
for (int j = 0; j < values.length; j++) {
encodingData[j] = values[j].getName();
}
//$NON-NLS-1$
encodingCombo = new LabelledCombo(compositeFileLocation, "Encoding", "Encoding", encodingData, 1, true, SWT.NONE);
Composite limitation = new Composite(compositeFileLocation, SWT.NONE);
limitation.setLayout(new GridLayout(2, false));
labelLimitation = new Label(limitation, SWT.LEFT);
//$NON-NLS-1$
labelLimitation.setText("Limit");
commonNodesLimitation = new Text(limitation, SWT.BORDER);
GridData gd = new GridData(18, 12);
commonNodesLimitation.setLayoutData(gd);
commonNodesLimitation.setText(String.valueOf(TreePopulator.getLimit()));
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, commonNodesLimitation.getText()));
commonNodesLimitation.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
String str = commonNodesLimitation.getText();
if ((!str.matches("\\d+")) || (Integer.valueOf(str) < 0)) {
//$NON-NLS-1$
commonNodesLimitation.setText(String.valueOf(treePopulator.getLimit()));
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, commonNodesLimitation.getText()));
;
} else {
limit = Integer.valueOf(str);
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, limit));
}
String tempxml = null;
if (tempJSONXsdPath != null && getConnection().getFileContent() != null && getConnection().getFileContent().length > 0) {
tempxml = getFilePath4Populate(tempJSONXsdPath);
} else {
tempxml = getFilePath4Populate(fileFieldJSON.getText());
}
switchPopulator(JSONFileStep1Form.this.wizard.getReadbyMode(), tempxml);
checkFieldsValue();
}
});
commonNodesLimitation.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
commonNodesLimitation.setText(String.valueOf(TreePopulator.getLimit()));
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, commonNodesLimitation.getText()));
}
});
// field XmaskPattern
// fieldMaskXPattern = new LabelledText(compositeFileLocation,
// Messages.getString("JSONFileStep1.maskXPattern"));
// Group Schema Viewer
group = Form.createGroup(this, 1, "Schema Viewer", 220);
Composite compositeFileViewer = Form.startNewDimensionnedGridLayout(group, 1, WIDTH_GRIDDATA_PIXEL, 220);
GridData gridData = new GridData(GridData.FILL_BOTH);
gridData.minimumWidth = WIDTH_GRIDDATA_PIXEL;
// gridData.minimumHeight = 150;
availableJSONTree = new Tree(compositeFileViewer, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
availableJSONTree.setLayoutData(gridData);
if (!isInWizard()) {
// Composite BottomButton
Composite compositeBottomButton = Form.startNewGridLayout(this, 2, false, SWT.CENTER, SWT.CENTER);
// Button Cancel
cancelButton = new UtilsButton(compositeBottomButton, "Cancel", WIDTH_BUTTON_PIXEL, HEIGHT_BUTTON_PIXEL);
}
addUtilsButtonListeners();
}
use of org.eclipse.swt.events.FocusListener in project tdi-studio-se by Talend.
the class JSONFileOutputStep1Form method addFieldsListeners.
@Override
protected void addFieldsListeners() {
jsonFilePath.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent event) {
if (jsonFilePath.getResult() == null) {
return;
}
String text = jsonFilePath.getText();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
text = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, text));
}
// getConnection().setJSONFilePath(PathUtils.getPortablePath(JSONXsdFilePath.getText()));
if (JSONFileOutputStep1Form.this.tempPath == null) {
JSONFileOutputStep1Form.this.tempPath = JSONUtil.changeJsonToXml(text);
}
File file = new File(text);
if (file.exists()) {
List<ATreeNode> treeNodes = new ArrayList<ATreeNode>();
valid = treePopulator.populateTree(JSONUtil.changeJsonToXml(text), treeNode);
checkFieldsValue();
if (!valid) {
return;
}
if (treeNodes.size() > 0) {
treeNode = treeNodes.get(0);
}
updateConnection(text);
}
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
jsonFilePath.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent event) {
String text = jsonFilePath.getText();
if (isContextMode()) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(connectionItem.getConnection(), true);
text = TalendQuoteUtils.removeQuotes(ConnectionContextHelper.getOriginalValue(contextType, text));
}
if (getConnection().getJSONFilePath() != null && !getConnection().getJSONFilePath().equals(text)) {
getConnection().getLoop().clear();
getConnection().getRoot().clear();
getConnection().getGroup().clear();
xsdPathChanged = true;
} else {
xsdPathChanged = false;
}
if (Path.fromOSString(jsonFilePath.getText()).toFile().isFile()) {
getConnection().setJSONFilePath(PathUtils.getPortablePath(jsonFilePath.getText()));
} else {
getConnection().setJSONFilePath(jsonFilePath.getText());
}
// updateConnection(text);
StringBuilder fileContent = new StringBuilder();
BufferedReader in = null;
File file = null;
if (tempJSONPath != null && getConnection().getFileContent() != null && getConnection().getFileContent().length > 0 && !isModifing) {
file = new File(tempJSONPath);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e2) {
ExceptionHandler.process(e2);
}
FileOutputStream outStream;
try {
outStream = new FileOutputStream(file);
outStream.write(getConnection().getFileContent());
outStream.close();
} catch (FileNotFoundException e1) {
ExceptionHandler.process(e1);
} catch (IOException e) {
ExceptionHandler.process(e);
}
}
} else {
file = new File(text);
}
String str;
try {
Charset guessCharset = CharsetToolkit.guessEncoding(file, 4096);
in = new BufferedReader(new InputStreamReader(new FileInputStream(file), guessCharset.displayName()));
while ((str = in.readLine()) != null) {
fileContent.append(str + "\n");
// for encoding
if (str.contains("encoding")) {
String regex = "^<\\?JSON\\s*version=\\\"[^\\\"]*\\\"\\s*encoding=\\\"([^\\\"]*)\\\"\\?>$";
Perl5Compiler compiler = new Perl5Compiler();
Perl5Matcher matcher = new Perl5Matcher();
Pattern pattern = null;
try {
pattern = compiler.compile(regex);
if (matcher.contains(str, pattern)) {
MatchResult matchResult = matcher.getMatch();
if (matchResult != null) {
encoding = matchResult.group(1);
}
}
} catch (MalformedPatternException malE) {
ExceptionHandler.process(malE);
}
}
}
fileContentText.setText(new String(fileContent));
} catch (Exception e) {
String msgError = "File" + " \"" + jsonFilePath.getText().replace("\\\\", "\\") + "\"\n";
if (e instanceof FileNotFoundException) {
msgError = msgError + "is not found";
} else if (e instanceof EOFException) {
msgError = msgError + "have an incorrect character EOF";
} else if (e instanceof IOException) {
msgError = msgError + "is locked by another soft";
} else {
msgError = msgError + "doesn't exist";
}
fileContentText.setText(msgError);
if (!isReadOnly()) {
updateStatus(IStatus.ERROR, msgError);
}
} finally {
try {
if (in != null) {
in.close();
}
} catch (Exception exception) {
ExceptionHandler.process(exception);
}
}
if (getConnection().getEncoding() == null || "".equals(getConnection().getEncoding())) {
getConnection().setEncoding(encoding);
if (encoding != null && !"".equals(encoding)) {
encodingCombo.setText(encoding);
} else {
encodingCombo.setText("UTF-8");
}
}
// }
if (file.exists()) {
valid = treePopulator.populateTree(JSONUtil.changeJsonToXml(text), treeNode);
updateConnection(text);
}
checkFieldsValue();
isModifing = true;
}
});
encodingCombo.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
getConnection().setEncoding(encodingCombo.getText());
checkFieldsValue();
}
});
commonNodesLimitation.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
String str = commonNodesLimitation.getText();
if ((!str.matches("\\d+")) || (Integer.valueOf(str) < 0)) {
commonNodesLimitation.setText(String.valueOf(treePopulator.getLimit()));
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, commonNodesLimitation.getText()));
} else {
treePopulator.setLimit(Integer.valueOf(str));
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, str));
}
if (JSONFileOutputStep1Form.this.tempPath == null) {
JSONFileOutputStep1Form.this.tempPath = JSONUtil.changeJsonToXml(jsonFilePath.getText());
}
File file = new File(JSONFileOutputStep1Form.this.tempPath);
if (file.exists()) {
valid = treePopulator.populateTree(JSONFileOutputStep1Form.this.tempPath, treeNode);
}
checkFieldsValue();
}
});
commonNodesLimitation.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
}
@Override
public void focusLost(FocusEvent e) {
commonNodesLimitation.setText(String.valueOf(TreePopulator.getLimit()));
labelLimitation.setToolTipText(MessageFormat.format(Messages.JSONLimitToolTip, commonNodesLimitation.getText()));
}
});
outputFilePath.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
getConnection().setOutputFilePath(PathUtils.getPortablePath(outputFilePath.getText()));
checkFieldsValue();
}
});
}
Aggregations