Search in sources :

Example 31 with DatabaseModelBean

use of net.heartsome.cat.common.bean.DatabaseModelBean 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)

Example 32 with DatabaseModelBean

use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.

the class TmDbManagerDialog method createPageContainer.

/**
	 * 创建右侧页面内容
	 * @param parent
	 *            页面容器
	 * @return ;
	 */
protected Composite createPageContainer(Composite parent) {
    Composite outer = new Composite(parent, SWT.NONE);
    GridData outerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    outerData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
    outer.setLayout(new GridLayout());
    outer.setLayoutData(outerData);
    // Create an outer composite for spacing
    ScrolledComposite scrolled = new ScrolledComposite(outer, SWT.V_SCROLL | SWT.H_SCROLL);
    // always show the focus control
    scrolled.setShowFocusedControl(true);
    scrolled.setExpandHorizontal(true);
    scrolled.setExpandVertical(true);
    scrolled.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
    GridLayout gld = new GridLayout(1, false);
    gld.marginWidth = 0;
    gld.marginHeight = 0;
    scrolled.setLayout(gld);
    Composite result = new Composite(scrolled, SWT.NONE);
    GridData resultData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    result.setLayoutData(resultData);
    GridLayout gl_result = new GridLayout(1, false);
    gl_result.marginWidth = 0;
    gl_result.marginHeight = 0;
    result.setLayout(gl_result);
    Group parameterGroup = new Group(result, SWT.NONE);
    parameterGroup.setText(Messages.getString("dialog.TmDbManagerDialog.parameterGroup"));
    GridLayout parameterLayout = new GridLayout(4, false);
    parameterGroup.setLayout(parameterLayout);
    GridData parameterGridData = new GridData(GridData.FILL_HORIZONTAL);
    parameterGroup.setLayoutData(parameterGridData);
    Label label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblHost"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    hostText = new Text(parameterGroup, SWT.BORDER);
    hostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblPort"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    portText = new Text(parameterGroup, SWT.BORDER);
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblInstance"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    instanceText = new Text(parameterGroup, SWT.BORDER);
    instanceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(parameterGroup, SWT.NONE);
    new Label(parameterGroup, SWT.NONE);
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblLocation"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    locationText = new Text(parameterGroup, SWT.BORDER);
    locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    borwserBtn = new Button(parameterGroup, SWT.NONE);
    borwserBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
    borwserBtn.setText(Messages.getString("dialog.TmDbManagerDialog.borwserBtn"));
    borwserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            String path = dlg.open();
            if (path != null) {
                locationText.setText(path);
            }
        }
    });
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblUsername"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    usernameText = new Text(parameterGroup, SWT.BORDER);
    usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TmDbManagerDialog.lblPwd"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    passwordText = new Text(parameterGroup, SWT.BORDER | SWT.PASSWORD);
    passwordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Composite btnComposite = new Composite(parameterGroup, SWT.NONE);
    btnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
    GridLayout btnCompositeLayout = new GridLayout(1, false);
    btnCompositeLayout.marginHeight = 0;
    btnCompositeLayout.marginWidth = 0;
    btnComposite.setLayout(btnCompositeLayout);
    // remenmberBtn = new Button(btnComposite, SWT.CHECK|SWT.BORDER);
    // remenmberBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    // remenmberBtn.setText("将本次连接信息添加到数据库类型的快捷连接方式(&R)");
    // remenmberBtn.setSelection(true);
    searchBtn = new Button(btnComposite, SWT.NONE);
    searchBtn.setText(Messages.getString("dialog.TmDbManagerDialog.searchBtn"));
    searchBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                public void run() {
                    // 输入合法性检查
                    IStatus status = validator();
                    if (status.getSeverity() != IStatus.OK) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), status.getMessage());
                        return;
                    }
                    SystemDBOperator sysDbOp = getCurrSysDbOp();
                    if (sysDbOp == null) {
                        return;
                    }
                    // 连接检查
                    if (!sysDbOp.checkDbConnection()) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg1"));
                        return;
                    }
                    // if (remenmberBtn.getSelection() == true) {
                    // 当前数据库类型下的所有服务器
                    List<DatabaseModelBean> currDbTypeServers = treeInputMap.get(getCurrDbType());
                    if (currServer.getId().equals("")) {
                        addServerWithExistCheck(currServer, currDbTypeServers);
                        getTreeViewer().refresh();
                        // 在树上选择当前操作的节点
                        selectSaveItem();
                    }
                    // ISelection selection = getTreeViewer().getSelection();
                    // if (selection.isEmpty()) {
                    // return;
                    // }
                    // } else { // 不记住信息
                    executeSearch(sysDbOp);
                // }
                }
            });
        }
    });
    Group tableComposite = new Group(result, SWT.NONE);
    tableComposite.setText(Messages.getString("dialog.TmDbManagerDialog.tableComposite"));
    tableComposite.setLayout(new GridLayout(1, false));
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    dbTableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    Table table = dbTableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    GridData tableGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    tableGd.heightHint = 180;
    table.setLayoutData(tableGd);
    createColumn(dbTableViewer);
    if (getDialogUseFor() == TYPE_DBSELECTED) {
        dbTableViewer.addDoubleClickListener(new IDoubleClickListener() {

            public void doubleClick(DoubleClickEvent event) {
                okPressed();
            }
        });
    }
    dbTableViewer.setContentProvider(new ArrayContentProvider());
    currServerdbListInput = new WritableList(currServerdbList, DatabaseManagerDbListBean.class);
    dbTableViewer.setInput(currServerdbListInput);
    Composite composite = new Composite(tableComposite, SWT.NONE);
    GridLayout gl_composite = new GridLayout(3, false);
    gl_composite.marginHeight = 0;
    gl_composite.marginWidth = 0;
    composite.setLayout(gl_composite);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    Button btnc = new Button(composite, SWT.NONE);
    btnc.setText(Messages.getString("dialog.TmDbManagerDialog.btnc"));
    btnc.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            createNewDatabase();
        }
    });
    Button btnd_1 = new Button(composite, SWT.NONE);
    btnd_1.setText(Messages.getString("dialog.TmDbManagerDialog.btnd_1"));
    btnd_1.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                public void run() {
                    ISelection selection = getDbTableViewer().getSelection();
                    if (selection.isEmpty()) {
                        return;
                    }
                    if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg2"))) {
                        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                        @SuppressWarnings("unchecked") List<DatabaseManagerDbListBean> needDeletes = structuredSelection.toList();
                        SystemDBOperator dbop = getCurrSysDbOp();
                        for (int i = 0; i < needDeletes.size(); i++) {
                            try {
                                String dbName = needDeletes.get(i).getDbName();
                                dbop.dropDb(dbName);
                                dbop.removeSysDb(dbName);
                            } catch (Exception e1) {
                                logger.error(Messages.getString("dialog.TmDbManagerDialog.logger1"), e1);
                                MessageDialog.openError(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg3") + e1.getMessage());
                                break;
                            }
                            currServerdbListInput.remove(needDeletes.get(i));
                        }
                    }
                }
            });
        }
    });
    Button importBtn = new Button(composite, SWT.NONE);
    importBtn.setText(Messages.getString("dialog.TmDbManagerDialog.importBtn"));
    importBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = getDbTableViewer().getSelection();
            if (selection.isEmpty()) {
                MessageDialog.openError(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg4"));
                return;
            }
            IStructuredSelection stcSel = (IStructuredSelection) selection;
            DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) stcSel.getFirstElement();
            DatabaseModelBean dbModelBean = new DatabaseModelBean();
            currServer.copyToOtherIntance(dbModelBean);
            dbModelBean.setDbName(dbBean.getDbName());
            ImportTmxWizard wizard = new ImportTmxWizard(dbModelBean);
            ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard) {

                // robert help 2012-09-06
                @Override
                protected Control createHelpControl(Composite parent) {
                    // ROBERTHELP 记忆库管理-导入TMX
                    String language = CommonFunction.getSystemLanguage();
                    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s03.html#create-tm-wizard-import-tmx", language);
                    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
                    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
                    ((GridLayout) parent.getLayout()).numColumns++;
                    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
                    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
                    toolBar.setCursor(cursor);
                    toolBar.addDisposeListener(new DisposeListener() {

                        public void widgetDisposed(DisposeEvent e) {
                            cursor.dispose();
                        }
                    });
                    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
                    helpItem.setImage(helpImage);
                    //$NON-NLS-1$
                    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
                    helpItem.addSelectionListener(new SelectionAdapter() {

                        public void widgetSelected(SelectionEvent e) {
                            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                        }
                    });
                    return toolBar;
                }
            };
            dlg.setHelpAvailable(true);
            if (dlg.open() == 0) {
                // 重新加载内容
                executeSearch(getCurrSysDbOp());
            }
        }
    });
    Point searchPoint = searchBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point createPoint = btnc.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point remPoint = btnd_1.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point importPoint = importBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(searchPoint.x, createPoint.x)));
    GridData btnData = new GridData();
    btnData.widthHint = width + 10;
    btnc.setLayoutData(btnData);
    btnd_1.setLayoutData(btnData);
    importBtn.setLayoutData(btnData);
    searchBtn.getLayoutData();
    GridData searchData = new GridData(SWT.RIGHT, SWT.CENTER, true, true, 4, 1);
    searchData.widthHint = width + 10;
    searchBtn.setLayoutData(searchData);
    scrolled.setContent(result);
    scrolled.setMinSize(getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
    return result;
}
Also used : Group(org.eclipse.swt.widgets.Group) DisposeListener(org.eclipse.swt.events.DisposeListener) IStatus(org.eclipse.core.runtime.IStatus) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) ImportTmxWizard(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ToolItem(org.eclipse.swt.widgets.ToolItem) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) DatabaseManagerDbListBean(net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) WritableList(org.eclipse.core.databinding.observable.list.WritableList) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ToolBar(org.eclipse.swt.widgets.ToolBar) ImportTmxWizardDialog(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizardDialog) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 33 with DatabaseModelBean

use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.

the class TmDbManagerDialog method executeSelectDatabase.

/**
	 * 当使用该对话框作为数据库选择时 ;
	 */
private void executeSelectDatabase() {
    ISelection selection = getDbTableViewer().getSelection();
    if (selection.isEmpty()) {
        return;
    }
    hasSelected = new HashMap<DatabaseModelBean, String>();
    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
    Iterator<?> it = structuredSelection.iterator();
    while (it.hasNext()) {
        DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) it.next();
        DatabaseModelBean dbModelBean = new DatabaseModelBean();
        currServer.copyToOtherIntance(dbModelBean);
        dbModelBean.setDbName(dbBean.getDbName());
        // Fix Bug #3290 导出TMX/TBX--导出内容异常 去掉语言前后的空格
        hasSelected.put(dbModelBean, dbBean.getLangs().replace(" ", ""));
    }
}
Also used : DatabaseManagerDbListBean(net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 34 with DatabaseModelBean

use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.

the class TbDbOperatorManager method loadTmDbConn.

/**
	 * 加载连接 ;
	 */
private void loadTmDbConn() {
    // 加载连接前先释放已经存在连接
    releaseTmDbConn();
    if (projConfiger != null) {
        List<DatabaseModelBean> tmDbConfigList = projConfiger.getTermBaseDbs(false);
        for (int i = 0; i < tmDbConfigList.size(); i++) {
            DatabaseModelBean dmb = tmDbConfigList.get(i);
            DBOperator db = DatabaseService.getDBOperator(dmb.toDbMetaData());
            if (null == db) {
                continue;
            }
            try {
                db.start();
            } catch (Exception e) {
                logger.error(MessageFormat.format(Messages.getString("tb.TbDbOperatorManager.logger1"), dmb.getDbType(), dmb.getDbName()), e);
                continue;
            }
            this.dbOpList.add(db);
        }
    }
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) DBOperator(net.heartsome.cat.database.DBOperator) SQLException(java.sql.SQLException)

Example 35 with DatabaseModelBean

use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.

the class Utils method convertFile2TbModel.

public static Map<DatabaseModelBean, String> convertFile2TbModel(File f, boolean loadLang) throws Exception {
    String path = f.getParent();
    String name = f.getName();
    System.out.println(path + " " + name);
    DatabaseModelBean selectedVal = new DatabaseModelBean();
    selectedVal.setDbName(name);
    selectedVal.setDbType(Constants.DBTYPE_SQLITE);
    selectedVal.setItlDBLocation(path);
    String lang = "";
    DBOperator dbOp = DatabaseService.getDBOperator(selectedVal.toDbMetaData());
    Statement stmt = null;
    ResultSet rs = null;
    try {
        dbOp.start();
        stmt = dbOp.getConnection().createStatement();
        rs = stmt.executeQuery("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name");
        List<String> tables = new ArrayList<String>();
        while (rs.next()) {
            String tname = rs.getString(1);
            if (tname.toUpperCase().startsWith("MATRIX_")) {
                continue;
            } else {
                tables.add(tname);
            }
        }
        List<String> l = Arrays.asList("BATTRIBUTE", "BMARTIFHEADER", "BNODE", "BREFOBJECTLIST", "BTERMENTRY", "LANG", "MEXTRA", "MHEADER", "MHEADERNODE", "MNOTE", "MPROP", "MTU", "TEXTDATA");
        if (!tables.containsAll(l)) {
            String message = Messages.getString("tb.dialog.addFileTb.error.msg1");
            throw new Exception(message);
        }
        if (loadLang) {
            List<String> langs = dbOp.getLanguages();
            for (int j = 0; j < langs.size(); j++) {
                lang += langs.get(j);
                if (j != langs.size() - 1) {
                    lang += ",";
                }
            }
        }
        Map<DatabaseModelBean, String> result = new HashMap<DatabaseModelBean, String>();
        result.put(selectedVal, lang);
        return result;
    } catch (Exception ex) {
        LOGGER.error("", ex);
        String message = Messages.getString("tb.dialog.addFileTb.error.msg2");
        message = MessageFormat.format(message, name);
        throw new Exception(message);
    } finally {
        try {
            if (dbOp != null) {
                dbOp.end();
            }
        } catch (SQLException ex) {
            LOGGER.error("", ex);
        }
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) Statement(java.sql.Statement) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) DBOperator(net.heartsome.cat.database.DBOperator) SQLException(java.sql.SQLException)

Aggregations

DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)71 ArrayList (java.util.ArrayList)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 SQLException (java.sql.SQLException)15 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 MenuItem (org.eclipse.swt.widgets.MenuItem)12 List (java.util.List)11 Point (org.eclipse.swt.graphics.Point)11 File (java.io.File)10 GridData (org.eclipse.swt.layout.GridData)10 GridLayout (org.eclipse.swt.layout.GridLayout)10 Button (org.eclipse.swt.widgets.Button)10 Composite (org.eclipse.swt.widgets.Composite)10 Label (org.eclipse.swt.widgets.Label)10 Menu (org.eclipse.swt.widgets.Menu)10 Iterator (java.util.Iterator)8 Map (java.util.Map)8 MetaData (net.heartsome.cat.common.bean.MetaData)8 HSDropDownButton (net.heartsome.cat.common.ui.HSDropDownButton)8