Search in sources :

Example 1 with ExportDatabaseBean

use of net.heartsome.cat.database.bean.ExportDatabaseBean in project translationstudio8 by heartsome.

the class ExportTbxDialog method okPressed.

@Override
protected void okPressed() {
    String encoding = "UTF-8";
    if (hasChangedCodingCbtn.getSelection()) {
        encoding = this.encodingComboViewer.getCombo().getText();
    }
    String exportPath = this.tbxFileText.getText();
    ExportFilterBean filterBean = null;
    if (hasFilterChangedBtn.getSelection()) {
        IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
        filterBean = (ExportFilterBean) sel.getFirstElement();
        if (filterBean.equals(filterList.get(0))) {
            filterBean = null;
        }
    }
    if (this.dbList.size() == 0) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg3"));
        return;
    }
    for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
        ExportDatabaseBean dbBean = iterator.next();
        if (dbBean.getHasSelectedLangs().size() < 2) {
            String dbType = dbBean.getDbBean().getDbType();
            String name = dbBean.getDbBean().getDatabaseName();
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTbxDialog.msg4"), dbType, name));
            return;
        }
    }
    if (exportPath == null || exportPath.equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg5"));
        return;
    }
    if (this.dbList.size() > 1) {
        File f = new File(exportPath);
        if (!f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg7"));
            return;
        }
    }
    if (this.dbList.size() == 1) {
        File f = new File(exportPath);
        if (f.isDirectory()) {
            MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), Messages.getString("dialog.ExportTbxDialog.msg8"));
            return;
        }
    }
    if (this.dbList.size() == 1) {
        dbList.get(0).setExportFilePath(exportPath);
        File file = new File(exportPath);
        if (file.exists()) {
            if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTbxDialog.msg6"), exportPath))) {
                return;
            }
        }
    } else {
        for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
            ExportDatabaseBean db = iterator.next();
            String databaseName = db.getDbBean().getDatabaseName();
            String path = exportPath + System.getProperty("file.separator") + databaseName + db.getDbBean().getDbType() + ".tbx";
            File file = new File(path);
            if (file.exists()) {
                if (!MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), MessageFormat.format(Messages.getString("dialog.ExportTbxDialog.msg6"), path))) {
                    return;
                }
            }
            db.setExportFilePath(path);
        }
    }
    final ExportAbstract exportor = new ExportTbxImpl(this.dbList, filterBean, encoding);
    Job job = new Job(Messages.getString("dialog.ExportTbxDialog.job")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            final String result = DatabaseService.executeExport(exportor, monitor);
            Display.getDefault().syncExec(new Runnable() {

                public void run() {
                    MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTbxDialog.msgTitle"), result);
                }
            });
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
    super.okPressed();
}
Also used : JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) ExportFilterBean(net.heartsome.cat.database.bean.ExportFilterBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ExportTbxImpl(net.heartsome.cat.document.ExportTbxImpl) ExportAbstract(net.heartsome.cat.document.ExportAbstract) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 2 with ExportDatabaseBean

use of net.heartsome.cat.database.bean.ExportDatabaseBean in project translationstudio8 by heartsome.

the class ExportTbxImpl method executeExport.

/**
	 * (non-Javadoc)
	 * @see net.heartsome.cat.document.ExportAbstract#executeExport(org.eclipse.core.runtime.IProgressMonitor)
	 */
@Override
public String executeExport(IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    String whereResult = "";
    if (this.filterBean != null) {
        StringBuffer whereBf = new StringBuffer();
        String connector = this.filterBean.getFilterConnector();
        List<ExportFilterComponentBean> filterOptions = this.filterBean.getFilterOption();
        whereBf.append(" AND ");
        for (Iterator<ExportFilterComponentBean> iterator = filterOptions.iterator(); iterator.hasNext(); ) {
            ExportFilterComponentBean filterBean = iterator.next();
            whereBf.append("PURE ");
            whereBf.append("LIKE ");
            whereBf.append("'%" + filterBean.getFilterVlaue() + "%' ");
            whereBf.append(connector + " ");
        }
        whereResult = whereBf.toString();
        whereResult = whereResult.substring(0, whereResult.lastIndexOf(connector));
    }
    monitor.beginTask("", dbList.size());
    for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
        ExportDatabaseBean db = iterator.next();
        String srcLang = db.getSrcLang();
        List<String> needLang = db.getHasSelectedLangs();
        DBOperator dbOp = DatabaseService.getDBOperator(db.getDbBean());
        try {
            dbOp.start();
            output = new FileOutputStream(db.getExportFilePath());
            writeHeader(srcLang);
            writeString("<text>\n<body>\n");
            List<Integer> tPkId = dbOp.getAfterFilterTermEntryPK(whereResult, needLang);
            // Fix Bug #2361 TBX文件导出问题--语言不能正确过滤导出 by Jason
            tPkId = dbOp.validateTermEntryPk(tPkId, needLang, srcLang);
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
            subMonitor.beginTask(Messages.getString("document.ExportTbxImpl.task1") + db.getDbBean().getDatabaseName(), tPkId.size());
            subMonitor.setTaskName(Messages.getString("document.ExportTbxImpl.task1") + db.getDbBean().getDatabaseName());
            for (int i = 0; i < tPkId.size(); i++) {
                // long l = System.currentTimeMillis();
                if (monitor.isCanceled()) {
                    clearResource();
                    return USER_CANCEL;
                }
                int termEntryPK = tPkId.get(i);
                String termEntry = dbOp.retrieveTermEntry(termEntryPK);
                if (termEntry != null && !termEntry.equals("")) {
                    writeString(termEntry);
                }
                subMonitor.worked(1);
            }
            writeString("</body>\n</text>\n</martif>\n");
        } catch (SQLException e) {
            logger.error(DBOP_ERROR, e);
            e.printStackTrace();
            clearResource();
            return DBOP_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
        } catch (ClassNotFoundException e) {
            logger.error(JDBC_ERROR, e);
            e.printStackTrace();
            clearResource();
            return JDBC_ERROR + db.getDbBean().getDbType();
        } catch (IOException e) {
            logger.error(FILE_ERROR, e);
            e.printStackTrace();
            clearResource();
            return FILE_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
        } finally {
            try {
                output.close();
                if (dbOp != null) {
                    dbOp.end();
                }
            } catch (SQLException e) {
                logger.error(RELEASE_DB_ERROR, e);
            } catch (IOException e) {
                logger.error(RELEASE_FILE_ERROR, e);
            }
        }
        filterLangSet(db.getExportFilePath(), srcLang, needLang);
    }
    monitor.done();
    return SUCCESS;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) IOException(java.io.IOException) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) ExportFilterComponentBean(net.heartsome.cat.database.bean.ExportFilterComponentBean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileOutputStream(java.io.FileOutputStream)

Example 3 with ExportDatabaseBean

use of net.heartsome.cat.database.bean.ExportDatabaseBean in project translationstudio8 by heartsome.

the class ExportTmxImpl method clearResource.

/**
	 * 清除所有已经生成的文件 ;
	 */
private void clearResource() {
    for (Iterator<ExportDatabaseBean> tempIt = dbList.iterator(); tempIt.hasNext(); ) {
        ExportDatabaseBean tempDb = tempIt.next();
        String path = tempDb.getExportFilePath();
        File file = new File(path);
        if (file.exists()) {
            file.delete();
        }
    }
}
Also used : File(java.io.File) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean)

Example 4 with ExportDatabaseBean

use of net.heartsome.cat.database.bean.ExportDatabaseBean in project translationstudio8 by heartsome.

the class ExportTmxImpl method executeExport.

/**
	 * (non-Javadoc)
	 * @see net.heartsome.cat.document.ExportAbstract#executeExport()
	 */
@Override
public String executeExport(IProgressMonitor monitor) {
    String mTuFilter = "";
    String textDataFilter = "";
    String mNoteFilter = "";
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask("", dbList.size());
    for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
        ExportDatabaseBean db = iterator.next();
        String srcLang = db.getSrcLang();
        DBOperator dbOp = DatabaseService.getDBOperator(db.getDbBean());
        // 过滤条件
        if (this.filterBean != null) {
            mTuFilter = dbOp.generationExportTMXFilter("MTU", this.filterBean);
            textDataFilter = dbOp.generationExportTMXFilter("TEXTDATA", this.filterBean);
            mNoteFilter = dbOp.generationExportTMXFilter("MNOTE", this.filterBean);
        }
        try {
            dbOp.start();
            output = new FileOutputStream(db.getExportFilePath());
            if (encoding.equalsIgnoreCase("UTF-16LE")) {
                output.write(0xFF);
                output.write(0xFE);
            } else if (encoding.equalsIgnoreCase("UTF-16BE")) {
                output.write(0xFE);
                output.write(0xFF);
            }
            List<Integer> filterTu = dbOp.getAfterFilterTuPk(mTuFilter, mNoteFilter, textDataFilter);
            writeHeader(srcLang);
            writeString("<body>\n");
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
            subMonitor.beginTask(Messages.getString("document.ExportTmxImpl.task1") + db.getDbBean().getDatabaseName(), filterTu.size());
            subMonitor.setTaskName(Messages.getString("document.ExportTmxImpl.task1") + db.getDbBean().getDatabaseName());
            for (int i = 0; i < filterTu.size(); i++) {
                // long l = System.currentTimeMillis();
                if (monitor.isCanceled()) {
                    clearResource();
                    break;
                }
                int tuPk = filterTu.get(i);
                String tuNodeContent = dbOp.retrieveTu(tuPk, db.getHasSelectedLangs(), isToplevelTmx, isTagLevelTmx);
                if (tuNodeContent != null && !tuNodeContent.equals("")) {
                    writeString(tuNodeContent);
                }
                subMonitor.worked(1);
            }
            //$NON-NLS-1$
            writeString("</body>\n");
            //$NON-NLS-1$	
            writeString("</tmx>\n");
            subMonitor.done();
        } catch (SQLException e) {
            logger.error(DBOP_ERROR, e);
            e.printStackTrace();
            clearResource();
            return DBOP_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
        } catch (ClassNotFoundException e) {
            logger.error(JDBC_ERROR, e);
            e.printStackTrace();
            clearResource();
            return JDBC_ERROR + db.getDbBean().getDbType();
        } catch (IOException e) {
            logger.error(FILE_ERROR, e);
            e.printStackTrace();
            clearResource();
            return FILE_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
        } finally {
            try {
                output.close();
                if (dbOp != null) {
                    dbOp.end();
                }
            } catch (SQLException e) {
                logger.error(RELEASE_DB_ERROR, e);
            } catch (IOException e) {
                logger.error(RELEASE_FILE_ERROR, e);
            }
        }
    }
    if (monitor.isCanceled()) {
        return USER_CANCEL;
    }
    monitor.done();
    return SUCCESS;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) IOException(java.io.IOException) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FileOutputStream(java.io.FileOutputStream)

Example 5 with ExportDatabaseBean

use of net.heartsome.cat.database.bean.ExportDatabaseBean in project translationstudio8 by heartsome.

the class ExportTmxDialog method createDialogArea.

/**
	 * Create contents of the dialog.
	 * @param parent
	 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new GridLayout(1, false));
    Group dbListGroup = new Group(container, SWT.NONE);
    GridLayout glDbListGroup = new GridLayout(2, false);
    glDbListGroup.horizontalSpacing = 0;
    glDbListGroup.marginHeight = 0;
    glDbListGroup.marginWidth = 0;
    dbListGroup.setLayout(glDbListGroup);
    dbListGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    dbListGroup.setText(Messages.getString("dialog.ExportTmxDialog.dbListGroup"));
    Composite leftComposite = new Composite(dbListGroup, SWT.NONE);
    GridLayout glLeftComposite = new GridLayout(1, false);
    glLeftComposite.verticalSpacing = 0;
    glLeftComposite.marginHeight = 0;
    leftComposite.setLayout(glLeftComposite);
    leftComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
    // 列表和语言设置
    Composite dbListComposite = new Composite(leftComposite, SWT.NONE);
    GridLayout glTopLeftComposite = new GridLayout(1, false);
    glTopLeftComposite.marginHeight = 0;
    glTopLeftComposite.marginWidth = 0;
    dbListComposite.setLayout(glTopLeftComposite);
    dbListComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    dbListViewer = new TableViewer(dbListComposite, SWT.BORDER | SWT.FULL_SELECTION);
    Table table = dbListViewer.getTable();
    GridData gd_table = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gd_table.heightHint = 100;
    table.setLayoutData(gd_table);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    dbListViewer.setContentProvider(new ArrayContentProvider());
    dbListViewer.setInput(dbList);
    createColumn(dbListViewer);
    dbListViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            currentDatabase = (ExportDatabaseBean) selection.getFirstElement();
            loadData();
        }
    });
    Composite langSetComposite = new Composite(leftComposite, SWT.NONE);
    GridLayout gl_langSetComposite = new GridLayout(2, false);
    gl_langSetComposite.marginWidth = 0;
    langSetComposite.setLayout(gl_langSetComposite);
    langSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    Label langSelLabel = new Label(langSetComposite, SWT.NONE);
    langSelLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    langSelLabel.setText(Messages.getString("dialog.ExportTmxDialog.langSelLabel"));
    hasSelLangListViewer = new ListViewer(langSetComposite, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    org.eclipse.swt.widgets.List list = hasSelLangListViewer.getList();
    GridData glLangList = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1);
    glLangList.heightHint = 76;
    list.setLayoutData(glLangList);
    hasSelLangListViewer.setContentProvider(new ArrayContentProvider());
    hasSelLangListViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("unchecked")
        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty()) {
                return;
            }
            if (currentDatabase != null) {
                currentDatabase.getHasSelectedLangs().clear();
                currentDatabase.getHasSelectedLangs().addAll(sel.toList());
                List<String> canSelSrcLangs = new ArrayList<String>();
                canSelSrcLangs.add("*all*");
                canSelSrcLangs.addAll(sel.toList());
                currentDatabase.setCanSelSrcLangs(canSelSrcLangs);
                srcLangcomboViewer.setInput(canSelSrcLangs);
                if (canSelSrcLangs.contains(currentDatabase.getSrcLang())) {
                    String srcLang = currentDatabase.getSrcLang();
                    if (srcLang != null && !srcLang.equals("")) {
                        for (int i = 0; i < canSelSrcLangs.size(); i++) {
                            if (canSelSrcLangs.get(i).equals(srcLang)) {
                                srcLangcomboViewer.getCombo().select(i);
                                break;
                            }
                        }
                    }
                } else {
                    srcLangcomboViewer.getCombo().select(0);
                }
            }
        }
    });
    Label srcLangSelLabel = new Label(langSetComposite, SWT.NONE);
    srcLangSelLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    srcLangSelLabel.setBounds(0, 0, 79, 19);
    srcLangSelLabel.setText(Messages.getString("dialog.ExportTmxDialog.srcLangSelLabel"));
    srcLangcomboViewer = new ComboViewer(langSetComposite, SWT.NONE | SWT.READ_ONLY);
    Combo combo = srcLangcomboViewer.getCombo();
    GridData gd_combo = new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1);
    gd_combo.widthHint = 197;
    combo.setLayoutData(gd_combo);
    srcLangcomboViewer.setContentProvider(new ArrayContentProvider());
    srcLangcomboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty()) {
                return;
            }
            if (currentDatabase != null) {
                currentDatabase.setSrcLang((String) sel.getFirstElement());
            }
        }
    });
    // 操作库列的按钮区域
    Composite rightComposite = new Composite(dbListGroup, SWT.NONE);
    GridLayout gl_rightComposite = new GridLayout(1, false);
    gl_rightComposite.marginRight = 5;
    gl_rightComposite.marginHeight = 0;
    gl_rightComposite.marginWidth = 0;
    rightComposite.setLayout(gl_rightComposite);
    rightComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    HSDropDownButton addDbBtn = new HSDropDownButton(rightComposite, SWT.None);
    addDbBtn.setBounds(0, 0, 104, 31);
    addDbBtn.setText(Messages.getString("dialog.ExportTmxDialog.AddDbBtn"));
    Menu menu = addDbBtn.getMenu();
    MenuItem fileItem = new MenuItem(menu, SWT.PUSH);
    fileItem.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddFileTm"));
    fileItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialg = new FileDialog(getShell());
            fileDialg.setFilterExtensions(new String[] { "*.hstm", "*.*" });
            String result = fileDialg.open();
            if (result == null) {
                return;
            }
            File f = new File(result);
            if (!f.exists()) {
                return;
            }
            Map<DatabaseModelBean, String> r = null;
            try {
                r = Utils.convertFile2TmModel(f, true);
            } catch (Exception e1) {
                MessageDialog.openError(getShell(), Messages.getString("tm.dialog.addFileTm.errorTitle"), e1.getMessage());
            }
            if (r == null) {
                return;
            }
            Iterator<DatabaseModelBean> it = r.keySet().iterator();
            if (it.hasNext()) {
                DatabaseModelBean selectedVal = it.next();
                ExportDatabaseBean bean = new ExportDatabaseBean(selectedVal.toDbMetaData(), r.get(selectedVal));
                if (!dbList.contains(bean)) {
                    // 实现: 重写equals方法
                    dbList.add(bean);
                    bean.setIndex(dbList.size() + "");
                }
                dbListViewer.getTable().removeAll();
                dbListViewer.setInput(dbList);
                if (dbList.size() != 0) {
                    deleteDbBtn.setEnabled(true);
                    browserBtn.setEnabled(true);
                    selectCurrentDb(currentDatabase);
                } else {
                    deleteDbBtn.setEnabled(false);
                    browserBtn.setEnabled(false);
                }
            }
        }
    });
    MenuItem serverItem = new MenuItem(menu, SWT.PUSH);
    serverItem.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddServerTm"));
    serverItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TmDbManagerDialog dialog = new TmDbManagerDialog(getShell());
            dialog.setDialogUseFor(TmDbManagerDialog.TYPE_DBSELECTED);
            if (dialog.open() == Window.OK) {
                Map<DatabaseModelBean, String> selDb = dialog.getHasSelectedDatabase();
                Iterator<Entry<DatabaseModelBean, String>> entryIt = selDb.entrySet().iterator();
                while (entryIt.hasNext()) {
                    Entry<DatabaseModelBean, String> entry = entryIt.next();
                    ExportDatabaseBean bean = new ExportDatabaseBean(entry.getKey().toDbMetaData(), entry.getValue());
                    if (!dbList.contains(bean)) {
                        // 实现: 重写equals方法
                        dbList.add(bean);
                        bean.setIndex(dbList.size() + "");
                    }
                }
                dbListViewer.getTable().removeAll();
                dbListViewer.setInput(dbList);
            }
            if (dbList.size() != 0) {
                deleteDbBtn.setEnabled(true);
                browserBtn.setEnabled(true);
                selectCurrentDb(currentDatabase);
            } else {
                deleteDbBtn.setEnabled(false);
                browserBtn.setEnabled(false);
            }
        }
    });
    deleteDbBtn = new Button(rightComposite, SWT.NONE);
    deleteDbBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    deleteDbBtn.setBounds(0, 0, 104, 31);
    deleteDbBtn.setText(Messages.getString("dialog.ExportTmxDialog.deleteDbBtn"));
    deleteDbBtn.setEnabled(false);
    deleteDbBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) dbListViewer.getSelection();
            if (sel.isEmpty()) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg1"));
                return;
            }
            dbList.removeAll(sel.toList());
            dbListViewer.remove(sel.toArray());
            if (dbList.size() != 0) {
                deleteDbBtn.setEnabled(true);
                browserBtn.setEnabled(true);
                selectCurrentDb(currentDatabase);
            } else {
                currentDatabase = null;
                deleteDbBtn.setEnabled(false);
                browserBtn.setEnabled(false);
            }
        }
    });
    // 过虑规则
    Composite filterSetComposite = new Composite(container, SWT.NONE);
    GridLayout glFilterSetComposite = new GridLayout(4, false);
    glFilterSetComposite.marginWidth = 0;
    glFilterSetComposite.marginHeight = 0;
    filterSetComposite.setLayout(glFilterSetComposite);
    filterSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    hasfilterCbtn = new Button(filterSetComposite, SWT.CHECK);
    hasfilterCbtn.setText(Messages.getString("dialog.ExportTmxDialog.hasfilterCbtn"));
    hasfilterCbtn.setSelection(false);
    hasfilterCbtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            // TODO 实现选择改变
            filterComboViewer.getCombo().setEnabled(hasfilterCbtn.getSelection());
            filterSetBtn.setEnabled(hasfilterCbtn.getSelection());
            deleteFilterBtn.setEnabled(hasfilterCbtn.getSelection());
        }
    });
    filterComboViewer = new ComboViewer(filterSetComposite, SWT.NONE);
    Combo filterCombo = filterComboViewer.getCombo();
    filterCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    filterCombo.setEnabled(hasfilterCbtn.getSelection());
    filterComboViewer.setContentProvider(new ArrayContentProvider());
    filterComboViewer.setLabelProvider(new FilterLabelProvider());
    filterComboViewer.setInput(filterList);
    // 有一个空的过滤器
    filterCombo.select(0);
    filterSetBtn = new Button(filterSetComposite, SWT.NONE);
    filterSetBtn.setText(Messages.getString("dialog.ExportTmxDialog.filterSetBtn"));
    filterSetBtn.setEnabled(hasfilterCbtn.getSelection());
    filterSetBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
            ExportFilterBean bean = (ExportFilterBean) sel.getFirstElement();
            if (bean.equals(filterList.get(0))) {
                // 0位置的始终存在 Empty
                // 新建
                filterSetting(null);
            } else {
                // 编辑
                filterSetting(bean);
            }
        }
    });
    deleteFilterBtn = new Button(filterSetComposite, SWT.NONE);
    deleteFilterBtn.setText(Messages.getString("dialog.ExportTmxDialog.deleteFilterBtn"));
    deleteFilterBtn.setEnabled(hasfilterCbtn.getSelection());
    deleteFilterBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection sel = (IStructuredSelection) filterComboViewer.getSelection();
            ExportFilterBean bean = (ExportFilterBean) sel.getFirstElement();
            if (bean.equals(filterList.get(0))) {
                // 总是存在一个空的filter,显示为"无"
                return;
            }
            if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.ExportTmxDialog.msgTitle"), Messages.getString("dialog.ExportTmxDialog.msg2"))) {
                filterStore.deleteFilterRuleByName(bean.getFilterName(), "TMX");
                int i = filterList.indexOf(bean);
                filterList.remove(i);
                filterComboViewer.setInput(filterList);
                filterComboViewer.getCombo().select(0);
            }
        }
    });
    isTopLevelTmxCbtn = new Button(container, SWT.CHECK);
    isTopLevelTmxCbtn.setText(Messages.getString("dialog.ExportTmxDialog.isTopLevelTmxCbtn"));
    isTopLevelTmxCbtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            boolean temp = isTopLevelTmxCbtn.getSelection();
            if (temp) {
                isTagCbtn.setSelection(false);
                isTagCbtn.setEnabled(false);
            } else {
                isTagCbtn.setEnabled(true);
            }
        }
    });
    isTagCbtn = new Button(container, SWT.CHECK);
    isTagCbtn.setText(Messages.getString("dialog.ExportTmxDialog.isTagCbtn"));
    isTagCbtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            boolean temp = isTagCbtn.getSelection();
            if (temp) {
                isTopLevelTmxCbtn.setSelection(false);
                isTopLevelTmxCbtn.setEnabled(false);
            } else {
                isTopLevelTmxCbtn.setEnabled(true);
            }
        }
    });
    isTopLevelTmxCbtn.setSelection(true);
    isTagCbtn.setEnabled(false);
    Composite encodingComposite = new Composite(container, SWT.NONE);
    GridLayout glEncodingComposite = new GridLayout(2, false);
    glEncodingComposite.marginWidth = 0;
    glEncodingComposite.marginHeight = 0;
    encodingComposite.setLayout(glEncodingComposite);
    encodingComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    hasChangedCodingCbtn = new Button(encodingComposite, SWT.CHECK);
    hasChangedCodingCbtn.setText(Messages.getString("dialog.ExportTmxDialog.hasChangedCodingCbtn"));
    hasChangedCodingCbtn.setSelection(false);
    hasChangedCodingCbtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            encodingComboViewer.getCombo().setEnabled(hasChangedCodingCbtn.getSelection());
        }
    });
    encodingComboViewer = new ComboViewer(encodingComposite, SWT.NONE | SWT.READ_ONLY);
    Combo encodingCombo = encodingComboViewer.getCombo();
    GridData gdEncodingCombo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gdEncodingCombo.widthHint = 279;
    encodingCombo.setLayoutData(gdEncodingCombo);
    encodingCombo.setEnabled(hasChangedCodingCbtn.getSelection());
    encodingComboViewer.setContentProvider(new ArrayContentProvider());
    encodingComboViewer.setInput(pageCodes);
    Composite tmxFileSetComposite = new Composite(container, SWT.NONE);
    GridLayout glTmxFileSetComposite = new GridLayout(3, false);
    glTmxFileSetComposite.marginWidth = 0;
    glTmxFileSetComposite.marginHeight = 0;
    tmxFileSetComposite.setLayout(glTmxFileSetComposite);
    tmxFileSetComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Label tmxFileLabel = new Label(tmxFileSetComposite, SWT.NONE);
    tmxFileLabel.setText(Messages.getString("dialog.ExportTmxDialog.tmxFileLabel"));
    tmxFileText = new Text(tmxFileSetComposite, SWT.BORDER);
    tmxFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tmxFileText.setEnabled(false);
    browserBtn = new Button(tmxFileSetComposite, SWT.NONE);
    browserBtn.setText(Messages.getString("dialog.ExportTmxDialog.browserBtn"));
    browserBtn.setEnabled(false);
    browserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (dbList.size() > 1) {
                DirectoryDialog dlg = new DirectoryDialog(getParentShell());
                String filePath = dlg.open();
                if (filePath != null) {
                    tmxFileText.setText(filePath);
                }
            } else {
                FileDialog dlg = new FileDialog(getShell(), SWT.SAVE);
                String[] filterExt = { "*.tmx" };
                dlg.setFilterExtensions(filterExt);
                String filePath = dlg.open();
                if (filePath != null) {
                    tmxFileText.setText(filePath);
                }
            }
        }
    });
    return container;
}
Also used : Group(org.eclipse.swt.widgets.Group) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Combo(org.eclipse.swt.widgets.Combo) ExportFilterBean(net.heartsome.cat.database.bean.ExportFilterBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExportDatabaseBean(net.heartsome.cat.database.bean.ExportDatabaseBean) GridLayout(org.eclipse.swt.layout.GridLayout) Entry(java.util.Map.Entry) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) ListViewer(org.eclipse.jface.viewers.ListViewer) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Text(org.eclipse.swt.widgets.Text) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) Map(java.util.Map)

Aggregations

ExportDatabaseBean (net.heartsome.cat.database.bean.ExportDatabaseBean)10 File (java.io.File)6 ExportFilterBean (net.heartsome.cat.database.bean.ExportFilterBean)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)2 HSDropDownButton (net.heartsome.cat.common.ui.HSDropDownButton)2 DBOperator (net.heartsome.cat.database.DBOperator)2 ExportAbstract (net.heartsome.cat.document.ExportAbstract)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2