use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.
the class ColumnTypeDialog method initListener.
/**
* 初始化加载配置和保存配置按钮的监听 ;
*/
private void initListener() {
btnLoadConfiguration.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent event) {
FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
fd.setText(Messages.getString("dialog.ColumnTypeDialog.fdTitle"));
//$NON-NLS-1$ //$NON-NLS-2$
String[] extensions = { "*.ctc", "*" };
String[] names = { Messages.getString("dialog.ColumnTypeDialog.filterName1"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("dialog.ColumnTypeDialog.filterName2") };
fd.setFilterExtensions(extensions);
fd.setFilterNames(names);
fd.setFilterPath(System.getProperty("user.home"));
String name = fd.open();
if (name == null) {
return;
}
try {
VTDGen vg = new VTDGen();
if (vg.parseFile(name, true)) {
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/CSV2TBX-configuration");
ap.evalXPath();
int count = vu.getChildElementsCount();
if (count != arrCmbLangs.length) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.ColumnTypeDialog.msgTitle"), Messages.getString("dialog.ColumnTypeDialog.msg1"));
return;
}
String xpath = "/CSV2TBX-configuration/item";
ap.selectXPath(xpath);
int i = 0;
while (ap.evalXPath() != -1) {
String propLevel = vu.getCurrentElementAttribut("propLevel", "");
//$NON-NLS-1$ //$NON-NLS-2$
String propType = vu.getCurrentElementAttribut("propType", "");
//$NON-NLS-1$ //$NON-NLS-2$
String lang = vu.getCurrentElementAttribut("propLang", "");
String propName = vu.getCurrentElementAttribut("propName", "");
arrCmbPropsLevel[i].setItems(levelValues);
arrCmbPropsLevel[i].select(0);
if (!propLevel.equals("")) {
//$NON-NLS-1$
arrCmbPropsLevel[i].setText(propLevel);
if (propLevel.equals(ColProperties.conceptLevel)) {
arrCmbLangs[i].setEnabled(false);
arrCmbPropsName[i].setItems(conceptPropValues);
arrCmbPropsName[i].select(0);
arrCmbPropsType[i].setItems(conceptPropTypeValues);
arrCmbPropsType[i].select(0);
}
if (propLevel.equals(ColProperties.langLevel)) {
arrCmbLangs[i].setEnabled(true);
arrCmbPropsName[i].setItems(TranslationPropValues);
arrCmbPropsName[i].select(0);
arrCmbPropsType[i].setItems(termDescripPropTypeValues);
arrCmbPropsType[i].select(0);
}
}
// Update content for Prop Name combo
if (!propName.equals("")) {
//$NON-NLS-1$
arrCmbPropsName[i].setText(propName);
}
if (!propLevel.equals("")) {
//$NON-NLS-1$
if (propLevel.equals(ColProperties.conceptLevel)) {
arrCmbPropsType[i].setEnabled(propName.equals(ColProperties.descripName));
arrCmbPropsType[i].setItems(conceptPropTypeValues);
arrCmbPropsType[i].select(0);
}
if (propLevel.equals(ColProperties.langLevel)) {
arrCmbPropsType[i].setEnabled(!propName.equals(ColProperties.termName));
if (propName.equals(ColProperties.descripName)) {
arrCmbPropsType[i].setItems(termDescripPropTypeValues);
} else {
arrCmbPropsType[i].setItems(termTermNotePropTypeValues);
}
arrCmbPropsType[i].select(0);
}
}
// Update content for Prop Type combo
if (!propType.equals("")) {
//$NON-NLS-1$
arrCmbPropsType[i].setText(propType);
}
// Update content for Language Combo
arrCmbLangs[i].setItems(LocaleService.getLanguages());
arrCmbLangs[i].select(0);
if (!lang.equals("")) {
//$NON-NLS-1$
arrCmbLangs[i].setText(lang);
}
i++;
}
}
} catch (XPathParseException e) {
LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger1"), e);
} catch (NavException e) {
LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger1"), e);
} catch (XPathEvalException e) {
LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger1"), e);
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
btnSaveConfiguration.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
FileDialog fd = new FileDialog(getShell(), SWT.SAVE);
fd.setText(Messages.getString("dialog.ColumnTypeDialog.savefdTitle"));
//$NON-NLS-1$ //$NON-NLS-2$
String[] extensions = { "*.ctc", "*.*" };
String[] names = { Messages.getString("dialog.ColumnTypeDialog.filterName1"), //$NON-NLS-1$ //$NON-NLS-2$
Messages.getString("dialog.ColumnTypeDialog.filterName2") };
fd.setFilterExtensions(extensions);
fd.setFilterNames(names);
fd.setFilterPath(System.getProperty("user.home"));
String name = fd.open();
if (name == null) {
return;
}
try {
FileOutputStream output = new FileOutputStream(name);
//$NON-NLS-1$ //$NON-NLS-2$
output.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes("UTF-8"));
//$NON-NLS-1$ //$NON-NLS-2$
output.write("<CSV2TBX-configuration>\n".getBytes("UTF-8"));
for (int i = 0; i < arrCmbLangs.length; i++) {
String strItem = //$NON-NLS-1$
"<item propLang=\"" + arrCmbLangs[i].getText() + "\" propName=\"" + //$NON-NLS-1$
arrCmbPropsName[i].getText() + "\" propType=\"" + //$NON-NLS-1$
arrCmbPropsType[i].getText() + "\" propLevel=\"" + //$NON-NLS-1$
arrCmbPropsLevel[i].getText() + //$NON-NLS-1$
"\"/>\n";
//$NON-NLS-1$
output.write(strItem.getBytes("UTF-8"));
}
//$NON-NLS-1$ //$NON-NLS-2$
output.write("</CSV2TBX-configuration>\n".getBytes("UTF-8"));
output.close();
} catch (FileNotFoundException e1) {
LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger2"), e);
} catch (UnsupportedEncodingException e1) {
LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger2"), e);
} catch (IOException e1) {
LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger2"), e);
}
}
public void widgetDefaultSelected(SelectionEvent e) {
}
});
}
use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.
the class RTFCleanerDialog method handleFile.
/**
* 处理 RTF 文件 ;
*/
private void handleFile() {
FileDialog dialog = new FileDialog(getShell(), SWT.MULTI);
dialog.setText(Messages.getString("dialog.RTFCleanerDialog.dialogTitle"));
String[] extensions = { "*.rtf", "*" };
String[] filters = { Messages.getString("dialog.RTFCleanerDialog.filters1"), Messages.getString("dialog.RTFCleanerDialog.filters2") };
dialog.setFilterExtensions(extensions);
dialog.setFilterNames(filters);
dialog.setFilterPath(System.getProperty("user.home"));
dialog.open();
String[] arrSource = dialog.getFileNames();
if (arrSource == null || arrSource.length == 0) {
return;
}
int errors = 0;
for (int i = 0; i < arrSource.length; i++) {
//$NON-NLS-1$
File f = new File(dialog.getFilterPath() + System.getProperty("file.separator") + arrSource[i]);
Hashtable<String, String> params = new Hashtable<String, String>();
//$NON-NLS-1$
params.put("source", f.getAbsolutePath());
//$NON-NLS-1$
params.put("output", f.getAbsolutePath());
Vector<String> result = RTFCleaner.run(params);
if (!"0".equals(result.get(0))) {
//$NON-NLS-1$
String msg = MessageFormat.format(Messages.getString("dialog.RTFCleanerDialog.msg1"), arrSource[i]) + (String) result.get(1);
MessageDialog.openInformation(getShell(), Messages.getString("dialog.RTFCleanerDialog.msgTitle"), msg);
errors++;
}
}
if (errors < arrSource.length) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.RTFCleanerDialog.msgTitle"), Messages.getString("dialog.RTFCleanerDialog.msg2"));
}
}
use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.
the class PluginHelpDialog method openFile.
private void openFile() {
FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
String[] extensions = { "*.xml", "*.*" };
String[] filterNames = { Messages.getString("dialog.PluginHelpDialog.filterNames0"), Messages.getString("dialog.PluginHelpDialog.filterNames1") };
fileDialog.setFilterExtensions(extensions);
fileDialog.setFilterNames(filterNames);
fileDialog.setFilterPath(System.getProperty("user.home"));
String name = fileDialog.open();
if (name == null) {
return;
}
File file = new File(name);
getShell().setText(file.getName());
loadTree(file.getAbsolutePath());
}
use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.
the class TMX2TXTConverterDialog method selecteTMXFile.
/**
* 选择TMX文件
*/
private void selecteTMXFile() {
FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
String[] extensions = { "*.tmx", "*.*" };
fd.setFilterExtensions(extensions);
String[] names = { Messages.getString("dialog.TMX2TXTConverterDialog.TMXNames1"), Messages.getString("dialog.TMX2TXTConverterDialog.TMXNames2") };
fd.setFilterNames(names);
String file = fd.open();
if (file != null) {
tmxTxt.setText(file);
if (txtTxt.getText().equals("")) {
txtTxt.setText(file.substring(0, file.lastIndexOf(".")) + ".txt");
}
}
}
use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.
the class TMX2TXTConverterDialog method selecteTXTFile.
/**
* 选择TXT文件 ;
*/
private void selecteTXTFile() {
FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
String[] extensions = { "*.txt", "*.*" };
fd.setFilterExtensions(extensions);
String[] names = { Messages.getString("dialog.TMX2TXTConverterDialog.TXTNames1"), Messages.getString("dialog.TMX2TXTConverterDialog.TXTNames2") };
fd.setFilterNames(names);
String file = fd.open();
if (file != null) {
txtTxt.setText(file);
}
}
Aggregations