Search in sources :

Example 11 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.

the class AnalysisXmlConvertConfigDialg method createRootTxt.

private void createRootTxt(Composite tparent) {
    Composite composite = new Composite(tparent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);
    GridLayoutFactory.fillDefaults().spacing(0, 1).numColumns(5).applyTo(composite);
    Label analysisXmlLbl = new Label(composite, SWT.NONE);
    analysisXmlLbl.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.analysisXmlLbl"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(analysisXmlLbl);
    Composite browseCmp = new Composite(composite, SWT.NONE);
    GridDataFactory.fillDefaults().indent(6, SWT.DEFAULT).grab(true, false).span(4, SWT.DEFAULT).applyTo(browseCmp);
    GridLayoutFactory.fillDefaults().numColumns(2).extendedMargins(0, 0, 0, 0).applyTo(browseCmp);
    analysisTxt = new Text(browseCmp, SWT.BORDER);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(analysisTxt);
    Button browseBtn = new Button(browseCmp, SWT.NONE);
    browseBtn.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.browseBtn"));
    Label rootLbl = new Label(composite, SWT.NONE);
    rootLbl.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.rootLbl"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(rootLbl);
    rootTxt = new Text(composite, SWT.BORDER);
    GridDataFactory.fillDefaults().indent(6, SWT.DEFAULT).hint(100, SWT.DEFAULT).applyTo(rootTxt);
    // 显示一个图标与“被保存到:”
    Label iconLbl = new Label(composite, SWT.NONE);
    iconLbl.setImage(icon);
    GridDataFactory.fillDefaults().indent(4, SWT.DEFAULT).applyTo(iconLbl);
    Label textLbl = new Label(composite, SWT.NONE);
    textLbl.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.textLbl"));
    rootTipLbl = new Label(composite, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.LEFT, SWT.CENTER).applyTo(rootTipLbl);
    rootTxt.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            String tipText = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootTxt.getText().trim().toLowerCase() + ".xml").toOSString();
            rootTipLbl.setText(tipText);
            rootTipLbl.pack();
            rootTipLbl.setToolTipText(tipText);
        }
    });
    // 在添加状态下,当根元素文本框失去焦点后,验证是否为空,验证是否重复
    rootTxt.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {

        public void focusLost(FocusEvent e) {
            String rootStr = rootTxt.getText().trim().toLowerCase();
            if ("".equals(rootStr)) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msgTitle"), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msg1"));
            } else {
                // 提示文件是否重复
                String configXmlLoaction = root.getLocation().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
                File xmlConfigFile = new File(configXmlLoaction);
                if (xmlConfigFile.exists()) {
                    String configXmlFullPath = root.getFullPath().append(ADConstants.AD_xmlConverterConfigFolder).append("config_" + rootStr + ".xml").toOSString();
                    MessageDialog.openInformation(getShell(), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msgTitle"), MessageFormat.format(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.msg2"), configXmlFullPath));
                }
            }
            super.focusLost(e);
        }
    });
    browseBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
            String[] extensions = { "*.xml", "*" };
            String[] names = { Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.filterXML"), Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.filterAll") };
            fd.setText(Messages.getString("dialogs.AnalysisXmlConvertConfigDialg.fdTitle"));
            fd.setFilterExtensions(extensions);
            fd.setFilterNames(names);
            String xmlLocation = fd.open();
            analysisTxt.setText(xmlLocation);
            // 解析XML文件并且填充到列表
            analysisXml(xmlLocation);
        }
    });
    analysisTxt.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            analysisXml(analysisTxt.getText());
            super.focusLost(e);
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FocusEvent(org.eclipse.swt.events.FocusEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FocusAdapter(org.eclipse.swt.events.FocusAdapter) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 12 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.

the class ImportDocxDialog method initListener.

/**
	 * 初始化按钮监听 ;
	 */
private void initListener() {
    browseXLIFFBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), false, IResource.FILE) {

                // 打开对话框时展开树形目录
                public void create() {
                    super.create();
                    super.getTreeViewer().expandAll();
                }
            };
            dialog.setTitle(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg0"));
            dialog.setMessage(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg1"));
            dialog.setDoubleClickSelects(true);
            dialog.setAllowMultiple(false);
            try {
                dialog.setInput(EFS.getStore(root.getLocationURI()));
            } catch (CoreException e1) {
                LOGGER.error(Messages.getString("ImportDocxDialog.LOGGER.logger1"), e1);
            }
            dialog.addFilter(new ViewerFilter() {

                @SuppressWarnings("restriction")
                @Override
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    if (element instanceof LocalFile) {
                        LocalFile folder = (LocalFile) element;
                        if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata")) {
                            return false;
                        }
                        if (lstProject.contains(folder.toString())) {
                            return true;
                        }
                        String xliffFolderPath = folder.toString();
                        for (String projectPath : lstProject) {
                            String path1 = projectPath + System.getProperty("file.separator") + Constant.FOLDER_XLIFF;
                            if (xliffFolderPath.startsWith(path1)) {
                                return true;
                            }
                        }
                    }
                    return false;
                }
            });
            dialog.create();
            dialog.open();
            if (dialog.getResult() != null) {
                Object obj = dialog.getFirstResult();
                IFile file = root.getFileForLocation(Path.fromOSString(obj.toString()));
                xliffPathTxt.setText(file.getFullPath().toOSString());
                xliffFullPath = ResourceUtils.iFileToOSPath(file);
            }
        }
    });
    browseDocxBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell());
            dialog.setText(Messages.getString("ImportDocxDialog.browseDocx.title"));
            dialog.setFilterExtensions(new String[] { "*.docx", "*.*" });
            dialog.setFilterNames(new String[] { Messages.getString(Messages.getString("ImportDocxDialog.browseDocx.filter")) });
            String fileSep = System.getProperty("file.separator");
            if (docxPathTxt.getText() != null && !docxPathTxt.getText().trim().equals("")) {
                dialog.setFilterPath(docxPathTxt.getText().substring(0, docxPathTxt.getText().lastIndexOf(fileSep)));
                dialog.setFileName(docxPathTxt.getText().substring(docxPathTxt.getText().lastIndexOf(fileSep) + 1));
            } else {
                dialog.setFilterPath(System.getProperty("user.home"));
            }
            String path = dialog.open();
            if (path != null) {
                docxPathTxt.setText(path);
            }
        }
    });
}
Also used : LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Viewer(org.eclipse.jface.viewers.Viewer) FileFolderSelectionDialog(net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 13 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.

the class ImportExternalDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new GridLayout(1, false));
    GridDataFactory.fillDefaults().hint(500, 180).grab(true, true).applyTo(composite);
    Group groupXLIFF = new Group(composite, SWT.None);
    groupXLIFF.setLayoutData(new GridData(GridData.FILL_BOTH));
    groupXLIFF.setLayout(new GridLayout(3, false));
    groupXLIFF.setText(Messages.getString("ImportDocxDialog.XLIFFgroup"));
    Label lblXLIFF = new Label(groupXLIFF, SWT.None);
    lblXLIFF.setText(Messages.getString("ImportDocxDialog.lable.xliff"));
    xliffPathTxt = new Text(groupXLIFF, SWT.BORDER);
    xliffPathTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    xliffPathTxt.setEditable(false);
    if (xliffRelativePath != null) {
        xliffPathTxt.setText(xliffRelativePath);
    }
    browseXLIFFBtn = new Button(groupXLIFF, SWT.None);
    browseXLIFFBtn.setText(Messages.getString("ImportDocxDialog.browseXLIFFBtn"));
    browseXLIFFBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), false, IResource.FILE) {

                // 打开对话框时展开树形目录
                public void create() {
                    super.create();
                    super.getTreeViewer().expandAll();
                }
            };
            dialog.setTitle(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg0"));
            dialog.setMessage(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg1"));
            dialog.setDoubleClickSelects(true);
            dialog.setAllowMultiple(false);
            try {
                dialog.setInput(EFS.getStore(root.getLocationURI()));
            } catch (CoreException e1) {
                LOGGER.error(Messages.getString("ImportDocxDialog.LOGGER.logger1"), e1);
            }
            dialog.addFilter(new ViewerFilter() {

                @SuppressWarnings("restriction")
                @Override
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    if (element instanceof LocalFile) {
                        LocalFile folder = (LocalFile) element;
                        if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata")) {
                            return false;
                        }
                        if (lstProject.contains(folder.toString())) {
                            return true;
                        }
                        String xliffFolderPath = folder.toString();
                        for (String projectPath : lstProject) {
                            String path1 = projectPath + System.getProperty("file.separator") + Constant.FOLDER_XLIFF;
                            if (xliffFolderPath.startsWith(path1)) {
                                return true;
                            }
                        }
                    }
                    return false;
                }
            });
            dialog.create();
            if (Window.OK == dialog.open()) {
                if (dialog.getResult() != null) {
                    Object obj = dialog.getFirstResult();
                    IFile file = root.getFileForLocation(Path.fromOSString(obj.toString()));
                    xliffPathTxt.setText(file.getFullPath().toOSString());
                    xliffFullPath = ResourceUtils.iFileToOSPath(file);
                }
                getButton(IDialogConstants.OK_ID).setEnabled(!docxPathTxt.getText().isEmpty());
            }
        }
    });
    Group groupExternal = new Group(composite, SWT.NONE);
    groupExternal.setText(Messages.getString("ImportDocxDialog.label.docx.title"));
    groupExternal.setLayout(new GridLayout(3, false));
    groupExternal.setLayoutData(new GridData(GridData.FILL_BOTH));
    Label lblRTF = new Label(groupExternal, SWT.None);
    lblRTF.setText(Messages.getString("ImportDocxDialog.label.docx"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).grab(false, false).applyTo(lblRTF);
    docxPathTxt = new Text(groupExternal, SWT.BORDER);
    docxPathTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    docxPathTxt.setEditable(false);
    browseDocxBtn = new Button(groupExternal, SWT.None);
    browseDocxBtn.setText(Messages.getString("ImportDocxDialog.browseDocxBtn"));
    browseDocxBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell());
            dialog.setText(Messages.getString("ImportDocxDialog.browseDocx.title"));
            dialog.setFilterExtensions(new String[] { "*.docx;", "*.*" });
            dialog.setFilterPath(dialogSetting.get("defaultPath"));
            String path = dialog.open();
            if (path != null) {
                if (testFileType(path)) {
                    dialogSetting.put("defaultPath", path.substring(0, path.lastIndexOf(File.separator)));
                    docxPathTxt.setText(path);
                    getButton(IDialogConstants.OK_ID).setEnabled(true && (!xliffPathTxt.getText().isEmpty()));
                } else {
                    getButton(IDialogConstants.OK_ID).setEnabled(false);
                }
            }
        }
    });
    txtImportType = new Label(composite, SWT.READ_ONLY);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BOTTOM).span(1, 3).grab(true, true).applyTo(txtImportType);
    return composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Viewer(org.eclipse.jface.viewers.Viewer) GridLayout(org.eclipse.swt.layout.GridLayout) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileFolderSelectionDialog(net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 14 with FileDialog

use of org.eclipse.swt.widgets.FileDialog in project translationstudio8 by heartsome.

the class CSVSettingDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridLayoutFactory.fillDefaults().numColumns(1).extendedMargins(5, 5, 5, 5).applyTo(tparent);
    int height = 160;
    if (isTBXConverter) {
        height = 230;
    }
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(320, height).grab(true, true).applyTo(tparent);
    Composite cmpSelFile = new Composite(tparent, SWT.None);
    GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).extendedMargins(0, 0, 0, 0).applyTo(cmpSelFile);
    GridDataFactory.fillDefaults().applyTo(cmpSelFile);
    new Label(cmpSelFile, SWT.None).setText(Messages.getString("dialog.CSVSettingDialog.lblFile"));
    txtCSV = new Text(cmpSelFile, SWT.BORDER);
    txtCSV.setEditable(false);
    txtCSV.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    btnBrowse = new Button(cmpSelFile, SWT.None);
    btnBrowse.setText(Messages.getString("dialog.CSVSettingDialog.btnBrowse"));
    btnBrowse.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            dialog.setText(Messages.getString("dialog.CSVSettingDialog.dialogTitle"));
            String[] extensions = { "*.csv", "*.txt", "*" };
            String[] filters = { Messages.getString("dialog.CSVSettingDialog.filters1"), Messages.getString("dialog.CSVSettingDialog.filters2"), Messages.getString("dialog.CSVSettingDialog.filters3") };
            dialog.setFilterExtensions(extensions);
            dialog.setFilterNames(filters);
            String fileSep = System.getProperty("file.separator");
            if (txtCSV.getText() != null && !txtCSV.getText().trim().equals("")) {
                dialog.setFilterPath(txtCSV.getText().substring(0, txtCSV.getText().lastIndexOf(fileSep)));
                dialog.setFileName(txtCSV.getText().substring(txtCSV.getText().lastIndexOf(fileSep) + 1));
            } else {
                dialog.setFilterPath(System.getProperty("user.home"));
            }
            String name = dialog.open();
            if (name != null) {
                txtCSV.setText(name);
            }
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    Composite cmpContent = new Composite(tparent, SWT.NONE);
    cmpContent.setLayout(new GridLayout(2, false));
    cmpContent.setLayoutData(new GridData(GridData.FILL_BOTH));
    createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbColSeparator"));
    cmbColSeparator = new Combo(cmpContent, SWT.NONE);
    cmbColSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    cmbColSeparator.setItems(arrColSeparator);
    cmbColSeparator.select(1);
    createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbTextDelimiter"));
    cmbTextDelimiter = new Combo(cmpContent, SWT.NONE);
    cmbTextDelimiter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    cmbTextDelimiter.setItems(arrTextDelimiter);
    cmbTextDelimiter.setText("\"");
    cmbTextDelimiter.setTextLimit(1);
    createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbEncoding"));
    cmbEncoding = new Combo(cmpContent, SWT.READ_ONLY);
    cmbEncoding.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    String[] arrEncoding = LocaleService.getPageCodes();
    cmbEncoding.setItems(arrEncoding);
    cmbEncoding.select(indexOf(arrEncoding, "UTF-8"));
    if (isTBXConverter) {
        createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbLang"));
        cmbLang = new TableComboViewer(cmpContent, SWT.READ_ONLY | SWT.BORDER);
        TableCombo tableCombo = cmbLang.getTableCombo();
        tableCombo.setShowTableLines(false);
        tableCombo.setShowTableHeader(false);
        tableCombo.setDisplayColumnIndex(-1);
        tableCombo.setShowImageWithinSelection(true);
        tableCombo.setShowColorWithinSelection(false);
        tableCombo.setShowFontWithinSelection(false);
        tableCombo.setVisibleItemCount(20);
        cmbLang.getTableCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        ArrayList<Language> languages = new ArrayList<Language>(LocaleService.getDefaultLanguage().values());
        Collections.sort(languages, new Comparator<Language>() {

            public int compare(Language o1, Language o2) {
                return o1.toString().compareTo(o2.toString());
            }
        });
        cmbLang.setContentProvider(new ArrayContentProvider());
        cmbLang.setLabelProvider(new LanguageLabelProvider());
        cmbLang.setInput(languages);
        cmbLang.getTableCombo().select(0);
        createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbXCSTemplate"));
        cmbXCSTemplate = new Combo(cmpContent, SWT.READ_ONLY);
        cmbXCSTemplate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        if (xcsTemplates.length > 0) {
            cmbXCSTemplate.setItems(xcsTemplates);
            cmbXCSTemplate.select(0);
        }
    }
    return tparent;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LanguageLabelProvider(net.heartsome.cat.ts.ui.composite.LanguageLabelProvider) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) TableCombo(org.eclipse.nebula.widgets.tablecombo.TableCombo) Combo(org.eclipse.swt.widgets.Combo) TableComboViewer(org.eclipse.nebula.jface.tablecomboviewer.TableComboViewer) GridLayout(org.eclipse.swt.layout.GridLayout) Language(net.heartsome.cat.common.locale.Language) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableCombo(org.eclipse.nebula.widgets.tablecombo.TableCombo) FileDialog(org.eclipse.swt.widgets.FileDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 15 with FileDialog

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) {
        }
    });
}
Also used : NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) VTDNav(com.ximpleware.VTDNav) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

FileDialog (org.eclipse.swt.widgets.FileDialog)214 File (java.io.File)91 Button (org.eclipse.swt.widgets.Button)61 SelectionEvent (org.eclipse.swt.events.SelectionEvent)58 GridLayout (org.eclipse.swt.layout.GridLayout)57 GridData (org.eclipse.swt.layout.GridData)56 Composite (org.eclipse.swt.widgets.Composite)55 Text (org.eclipse.swt.widgets.Text)50 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)48 Label (org.eclipse.swt.widgets.Label)47 IOException (java.io.IOException)31 Group (org.eclipse.swt.widgets.Group)24 Shell (org.eclipse.swt.widgets.Shell)23 ModifyListener (org.eclipse.swt.events.ModifyListener)21 ArrayList (java.util.ArrayList)19 ModifyEvent (org.eclipse.swt.events.ModifyEvent)19 IPath (org.eclipse.core.runtime.IPath)18 Path (org.eclipse.core.runtime.Path)16 Combo (org.eclipse.swt.widgets.Combo)16 SelectionListener (org.eclipse.swt.events.SelectionListener)15