Search in sources :

Example 1 with PluginConfigBean

use of net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean in project translationstudio8 by heartsome.

the class PluginConfigurationDialog method editPuginConfig.

public void editPuginConfig() {
    ISelection selection = tableViewer.getSelection();
    if (selection != null && !selection.isEmpty() && selection instanceof StructuredSelection) {
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        Iterator<PluginConfigBean> it = structuredSelection.iterator();
        if (it.hasNext()) {
            PluginConfigBean configBean = it.next();
            PluginConfigManageDialog dialog = new PluginConfigManageDialog(getShell(), false);
            dialog.create();
            dialog.setEditInitData(configBean);
            int result = dialog.open();
            if (result == IDialogConstants.OK_ID) {
                refreshTable(dialog.getCurPluginBean());
            }
        }
    } else {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.PluginConfigurationDialog.msgTitle"), Messages.getString("dialog.PluginConfigurationDialog.msg1"));
    }
}
Also used : PluginConfigBean(net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean) ISelection(org.eclipse.jface.viewers.ISelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 2 with PluginConfigBean

use of net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean in project translationstudio8 by heartsome.

the class PluginConfigManage method getPluginCofigData.

/**
	 * 从插件配置文件中获取插件配置的相关信息
	 * @return ;
	 */
public List<PluginConfigBean> getPluginCofigData() {
    System.out.println(pluginXmlLocation);
    List<PluginConfigBean> dataList = new LinkedList<PluginConfigBean>();
    File pluginXMl = new File(pluginXmlLocation);
    if (!pluginXMl.exists()) {
        return dataList;
    }
    VTDGen vg = new VTDGen();
    vg.parseFile(pluginXmlLocation, true);
    VTDNav vn = vg.getNav();
    AutoPilot ap = new AutoPilot(vn);
    try {
        ap.selectXPath("/shortcuts/plugin");
        PluginConfigBean bean;
        while (ap.evalXPath() != -1) {
            String id = "";
            String name = "";
            String commandLine = "";
            String output = "";
            String input = "";
            String shortcutKey = "";
            String outputPath = "";
            int index = -1;
            if ((index = vn.getAttrVal("id")) != -1) {
                id = vn.toString(index);
            }
            if ((index = vn.getText()) != -1) {
                name = vn.toString(index);
            }
            if ((index = vn.getAttrVal("command")) != -1) {
                commandLine = vn.toString(index);
            }
            if ((index = vn.getAttrVal("output")) != -1) {
                output = vn.toString(index);
            }
            if ((index = vn.getAttrVal("input")) != -1) {
                input = vn.toString(index);
            }
            if ((index = vn.getAttrVal("shortcut-key")) != -1) {
                shortcutKey = vn.toString(index);
            }
            if ((index = vn.getAttrVal("outputpath")) != -1) {
                outputPath = vn.toString(index);
            }
            bean = new PluginConfigBean(id, name, commandLine, input, output, outputPath, shortcutKey);
            dataList.add(bean);
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return dataList;
}
Also used : PluginConfigBean(net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean) AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen) IFile(org.eclipse.core.resources.IFile) File(java.io.File) VTDNav(com.ximpleware.VTDNav) LinkedList(java.util.LinkedList)

Example 3 with PluginConfigBean

use of net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean in project translationstudio8 by heartsome.

the class PluginConfigManageDialog method okPressed.

@Override
protected void okPressed() {
    String id = "" + System.currentTimeMillis();
    String name = nameTxt.getText().trim();
    String command = commandTxt.getText().trim();
    if ("".equals(name) || name == null) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.PluginConfigManageDialog.msgTitle"), Messages.getString("dialog.PluginConfigManageDialog.msg1"));
        return;
    }
    if ("".equals(command) || command == null) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.PluginConfigManageDialog.msgTitle"), Messages.getString("dialog.PluginConfigManageDialog.msg2"));
        return;
    }
    String input = "";
    String output = "";
    if (inputUpdateFileBtn.getSelection()) {
        input = PluginConstants.EXCHANGEFILE;
    } else if (inputUpdateDocuBtn.getSelection()) {
        input = PluginConstants.DOCUMENT;
    } else if (inputBlankBtn.getSelection()) {
        input = PluginConstants.NONE;
    }
    if (outputSegemntBtn.getSelection()) {
        output = PluginConstants.SEGMENT;
    } else if (outputDocumentBtn.getSelection()) {
        output = PluginConstants.DOCUMENT;
    } else if (outputBlankBtn.getSelection()) {
        output = PluginConstants.NONE;
    }
    String shortcutKey = keyTxt.getText().trim();
    String outputPath = switchTxt.getText().trim();
    PluginConfigBean pluginBean = new PluginConfigBean(id, name, command, input, output, outputPath, shortcutKey);
    if (isAdd) {
        if (!addPluginData(pluginBean)) {
            return;
        } else {
            manage.addPluginMenu(pluginBean);
        }
    } else {
        // 修改之后的数据,ID是不能变的。
        pluginBean.setId(curPluginBean.getId());
        // 执行修改操作
        editPlugindata(pluginBean);
    }
    curPluginBean = pluginBean;
    super.okPressed();
}
Also used : PluginConfigBean(net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean)

Example 4 with PluginConfigBean

use of net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean in project translationstudio8 by heartsome.

the class PluginConfigurationDialog method deletePluginData.

private void deletePluginData() {
    ISelection selection = tableViewer.getSelection();
    if (selection != null && !selection.isEmpty() && selection instanceof StructuredSelection) {
        boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("dialog.PluginConfigurationDialog.msgTitle2"), Messages.getString("dialog.PluginConfigurationDialog.msg2"));
        if (!response) {
            return;
        }
        StructuredSelection structuredSelection = (StructuredSelection) selection;
        @SuppressWarnings("unchecked") Iterator<PluginConfigBean> it = structuredSelection.iterator();
        VTDGen vg = new VTDGen();
        vg.parseFile(pluginXmlLocation, true);
        VTDNav vn = vg.getNav();
        AutoPilot ap = new AutoPilot(vn);
        try {
            XMLModifier xm = new XMLModifier(vn);
            while (it.hasNext()) {
                PluginConfigBean configBean = it.next();
                String xpath = manage.buildXpath(configBean);
                ap.selectXPath(xpath);
                while (ap.evalXPath() != -1) {
                    xm.remove();
                    manage.deletePluginMenu(configBean.getId());
                }
                ap.resetXPath();
            }
            FileOutputStream fos = new FileOutputStream(pluginXmlLocation);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            // 写入文件
            xm.output(bos);
            bos.close();
            fos.close();
            refreshTable(null);
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    } else {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.PluginConfigurationDialog.msgTitle"), Messages.getString("dialog.PluginConfigurationDialog.msg3"));
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) VTDGen(com.ximpleware.VTDGen) PluginConfigBean(net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) ISelection(org.eclipse.jface.viewers.ISelection) VTDNav(com.ximpleware.VTDNav) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

PluginConfigBean (net.heartsome.cat.ts.ui.plugin.bean.PluginConfigBean)4 AutoPilot (com.ximpleware.AutoPilot)2 VTDGen (com.ximpleware.VTDGen)2 VTDNav (com.ximpleware.VTDNav)2 ISelection (org.eclipse.jface.viewers.ISelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 XMLModifier (com.ximpleware.XMLModifier)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 LinkedList (java.util.LinkedList)1 IFile (org.eclipse.core.resources.IFile)1