use of net.heartsome.cat.ts.ui.advanced.model.ElementBean in project translationstudio8 by heartsome.
the class XmlConvertManagerDialog method createConfigXML.
/**
* 创建新的配置文件
* @param configXMLLocation
* ;
*/
protected void createConfigXML(String configXMLLocation) {
// 先创建一个空文本
try {
FileOutputStream outPut = new FileOutputStream(configXMLLocation);
StringBuffer configDataSB = new StringBuffer();
configDataSB.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
configDataSB.append("<!DOCTYPE ini-file PUBLIC \"-//HEARTSOME//Converters 2.0.0//EN\" \"configuration.dtd\">\n");
configDataSB.append("<ini-file>\n");
ElementBean bean;
for (int i = 0; i < elementsList.size(); i++) {
configDataSB.append("\t<tag ");
bean = elementsList.get(i);
// 添加元素类型
configDataSB.append(MessageFormat.format("hard-break=\"{0}\" ", bean.getType()));
// 添加可翻译属性
String attributes = bean.getTransAttribute();
if (!"".equals(attributes) && attributes != null) {
configDataSB.append(MessageFormat.format("attributes=\"{0}\" ", attributes));
}
// 添加内联类型
String inlineType = bean.getInlineType();
if (!"".equals(inlineType) && inlineType != null) {
configDataSB.append(MessageFormat.format("ctype=\"{0}\" ", inlineType));
}
// 添加可保留空格属性
String remainSpace = bean.getRemainSpace();
if (!"".equals(remainSpace) && remainSpace != null) {
configDataSB.append(MessageFormat.format("keep-format=\"{0}\" ", remainSpace));
}
// 添加元素名
configDataSB.append(MessageFormat.format(">{0}</tag>\n", bean.getName()));
}
configDataSB.append("</ini-file>");
outPut.write(configDataSB.toString().getBytes("UTF-8"));
outPut.close();
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of net.heartsome.cat.ts.ui.advanced.model.ElementBean in project translationstudio8 by heartsome.
the class XmlConvertManagerDialog method initListener.
/**
* 给增删改三个按钮添加点击事件 ;
*/
protected void initListener() {
addBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AddOrEditElementOfXmlConvertDialog dialog = new AddOrEditElementOfXmlConvertDialog(getShell(), true, elementsList);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
refreshTable(dialog.getCurrentElement());
}
}
});
editBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
editElement();
}
});
deleteBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = tableViewer.getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
if (MessageDialog.openConfirm(getShell(), Messages.getString("dialogs.XmlConvertManagerDialog.msgTitle1"), Messages.getString("dialogs.XmlConvertManagerDialog.msg1"))) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
@SuppressWarnings("unchecked") Iterator<ElementBean> iter = structuredSelection.iterator();
ElementBean bean = new ElementBean();
while (iter.hasNext()) {
bean = iter.next();
elementsList.remove(bean);
}
refreshTable(null);
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("dialogs.XmlConvertManagerDialog.msgTitle2"), Messages.getString("dialogs.XmlConvertManagerDialog.msg2"));
}
}
});
}
use of net.heartsome.cat.ts.ui.advanced.model.ElementBean in project translationstudio8 by heartsome.
the class AddOrEditElementOfXmlConvertDialog method validrepeat.
/**
* 验证所要添加的元素名是否重复 返回重复元素的下标值,若返回-1,则标志不重复
* @return ;
*/
public int validrepeat(String elementName) {
Iterator<ElementBean> iter = elementsList.iterator();
ElementBean bean;
while (iter.hasNext()) {
bean = iter.next();
if (elementName.equals(bean.getName())) {
return elementsList.indexOf(bean);
}
}
return -1;
}
use of net.heartsome.cat.ts.ui.advanced.model.ElementBean in project translationstudio8 by heartsome.
the class AddOrEditElementOfXmlConvertDialog method okPressed.
@Override
protected void okPressed() {
String elementName = nameTxt.getText().trim();
// 添加
if (isAdd) {
int index = -1;
// 验证是否为空
if (validNameNull(elementName)) {
return;
} else {
ElementBean element = new ElementBean(elementName, typeCmb.getText(), inlineCmb.getText(), transAtrriTxt.getText().trim(), remainSpaceCmb.getText());
// 验证添加的元素名是否重复
if ((index = validrepeat(elementName)) != -1) {
boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("dialogs.AddOrEditElementOfXmlConvertDialog.msgTitle1"), MessageFormat.format(Messages.getString("dialogs.AddOrEditElementOfXmlConvertDialog.msg1"), elementName));
if (response) {
elementsList.set(index, element);
} else {
return;
}
} else {
// 没有重复。则添加
elementsList.add(element);
}
currentElement = element;
}
} else {
// 验证是否为空
if (validNameNull(elementName)) {
return;
} else {
int index = elementsList.indexOf(currentElement);
ElementBean element = new ElementBean(elementName, typeCmb.getText(), inlineCmb.getText(), transAtrriTxt.getText().trim(), remainSpaceCmb.getText());
elementsList.set(index, element);
currentElement = element;
}
}
super.okPressed();
}
use of net.heartsome.cat.ts.ui.advanced.model.ElementBean in project translationstudio8 by heartsome.
the class XmlConvertManagerDialog method editElement.
/**
* 编辑选中的元素 ;
*/
protected void editElement() {
ISelection selection = tableViewer.getSelection();
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
@SuppressWarnings("unchecked") Iterator<ElementBean> iter = structuredSelection.iterator();
ElementBean bean = iter.next();
AddOrEditElementOfXmlConvertDialog dialog = new AddOrEditElementOfXmlConvertDialog(getShell(), false, elementsList);
dialog.create();
dialog.setInitEditData(bean);
int result = dialog.open();
if (result == IDialogConstants.OK_ID) {
refreshTable(dialog.getCurrentElement());
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("dialogs.XmlConvertManagerDialog.msgTitle2"), Messages.getString("dialogs.XmlConvertManagerDialog.msg3"));
}
}
Aggregations