Search in sources :

Example 1 with ElementBean

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);
    }
}
Also used : ElementBean(net.heartsome.cat.ts.ui.advanced.model.ElementBean) FileOutputStream(java.io.FileOutputStream)

Example 2 with ElementBean

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"));
            }
        }
    });
}
Also used : ElementBean(net.heartsome.cat.ts.ui.advanced.model.ElementBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with ElementBean

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;
}
Also used : ElementBean(net.heartsome.cat.ts.ui.advanced.model.ElementBean)

Example 4 with ElementBean

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();
}
Also used : ElementBean(net.heartsome.cat.ts.ui.advanced.model.ElementBean)

Example 5 with ElementBean

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"));
    }
}
Also used : ElementBean(net.heartsome.cat.ts.ui.advanced.model.ElementBean) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Aggregations

ElementBean (net.heartsome.cat.ts.ui.advanced.model.ElementBean)8 AutoPilot (com.ximpleware.AutoPilot)2 VTDNav (com.ximpleware.VTDNav)2 LinkedList (java.util.LinkedList)2 ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1