Search in sources :

Example 1 with ImportTmxWizard

use of net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard in project translationstudio8 by heartsome.

the class ProjectSettingTMPage method createContents.

/**
	 * Create contents of the preference page.
	 * @param parent
	 */
@Override
public Control createContents(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(1, false));
    tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
    Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tableViewer.setContentProvider(new ArrayContentProvider());
    createColumn(tableViewer);
    tableViewer.setInput(curDbList);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            DatabaseModelBean dbModel = (DatabaseModelBean) selection.getFirstElement();
            if (null == dbModel) {
                return;
            }
            if (Constants.DBTYPE_SQLITE.equals(dbModel.getDbType())) {
                String path = dbModel.getItlDBLocation() + File.separator + dbModel.getDbName();
                File file = new File(path);
                if (!file.exists()) {
                    setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.FileNotFound"));
                    return;
                } else {
                    setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.title"));
                }
            }
            if (dbModel != null && !dbModel.isHasMatch()) {
                setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.msg1"));
            }
        }
    });
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    composite.setLayout(new GridLayout(5, false));
    new Label(composite, SWT.NONE);
    HSDropDownButton addBtn = new HSDropDownButton(composite, SWT.NONE);
    addBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.addBtn"));
    Menu addMenu = addBtn.getMenu();
    MenuItem item = new MenuItem(addMenu, SWT.PUSH);
    item.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddFileTm"));
    item.addSelectionListener(new SelectionAdapter() {

        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, false);
            } 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();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                dbList.add(selectedVal);
                addToCurrDbList(dbList);
            }
        }
    });
    MenuItem serverItem = new MenuItem(addMenu, 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) {
                Iterator<DatabaseModelBean> it = dialog.getHasSelectedDatabase().keySet().iterator();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                while (it.hasNext()) {
                    dbList.add(it.next());
                }
                addToCurrDbList(dbList);
            }
        }
    });
    Button createBtn = new Button(composite, SWT.NONE);
    createBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.createBtn"));
    createBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            NewTmDbWizard wizard = new NewTmDbWizard();
            ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
            if (dlg.open() == 0) {
                DatabaseModelBean dbModel = wizard.getCreateDb();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                dbList.add(dbModel);
                addToCurrDbList(dbList);
            }
        }
    });
    Button removeBtn = new Button(composite, SWT.NONE);
    removeBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.removeBtn"));
    removeBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            removeForCurrDbList((IStructuredSelection) tableViewer.getSelection());
        }
    });
    Button importTmxBtn = new Button(composite, SWT.NONE);
    importTmxBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.importTmxBtn"));
    importTmxBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            Iterator<?> it = selection.iterator();
            if (it.hasNext()) {
                DatabaseModelBean dbModel = (DatabaseModelBean) it.next();
                ImportTmxWizard wizard = new ImportTmxWizard(dbModel);
                ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
                if (dlg.open() == 0) {
                    checkDbHashMatch(dbModel);
                    tableViewer.refresh();
                }
                // 刷新项目
                ResourceUtils.refreshCurentSelectProject();
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("projectsetting.ProjectSettingTMPage.msgTitle"), Messages.getString("projectsetting.ProjectSettingTMPage.msg2"));
            }
        }
    });
    addBtn.setFocus();
    Point addPoint = addBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point createPoint = createBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point remPoint = removeBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point importPoint = importTmxBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(addPoint.x, createPoint.x)));
    GridData btnData = new GridData();
    btnData.widthHint = width + 10;
    addBtn.setLayoutData(btnData);
    createBtn.setLayoutData(btnData);
    removeBtn.setLayoutData(btnData);
    importTmxBtn.setLayoutData(btnData);
    return container;
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ImportTmxWizard(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) 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) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Table(org.eclipse.swt.widgets.Table) TmDbManagerDialog(net.heartsome.cat.database.ui.tm.dialog.TmDbManagerDialog) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException) Point(org.eclipse.swt.graphics.Point) NewTmDbWizard(net.heartsome.cat.database.ui.tm.wizard.NewTmDbWizard) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ImportTmxWizardDialog(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizardDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) Map(java.util.Map)

Example 2 with ImportTmxWizard

use of net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard 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 3 with ImportTmxWizard

use of net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard in project translationstudio8 by heartsome.

the class NewProjectTmPage method createControl.

/**
	 * Create contents of the wizard.
	 * @param parent
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(1, false));
    tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
    Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tableViewer.setContentProvider(new ArrayContentProvider());
    createColumn(tableViewer);
    tableViewer.setInput(curDbList);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            DatabaseModelBean dbModel = (DatabaseModelBean) selection.getFirstElement();
            if (dbModel != null && !dbModel.isHasMatch()) {
                setMessage(Messages.getString("newproject.NewProjectTmPage.msg1"));
            } else {
                setMessage(null);
            }
        }
    });
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    composite.setLayout(new GridLayout(5, false));
    new Label(composite, SWT.NONE);
    HSDropDownButton addBtn = new HSDropDownButton(composite, SWT.NONE);
    addBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.addBtn"));
    Menu addMenu = addBtn.getMenu();
    MenuItem item = new MenuItem(addMenu, SWT.PUSH);
    item.setText(Messages.getString("tm.dialog.addTm.DropDownButton.AddFileTm"));
    item.addSelectionListener(new SelectionAdapter() {

        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, false);
            } 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();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                dbList.add(selectedVal);
                addToCurrDbList(dbList);
            }
        }
    });
    MenuItem serverItem = new MenuItem(addMenu, 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) {
                Iterator<DatabaseModelBean> it = dialog.getHasSelectedDatabase().keySet().iterator();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                while (it.hasNext()) {
                    dbList.add(it.next());
                }
                addToCurrDbList(dbList);
            }
        }
    });
    Button createBtn = new Button(composite, SWT.NONE);
    createBtn.setText(Messages.getString("newproject.NewProjectTmPage.createBtn"));
    createBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            NewTmDbWizard wizard = new NewTmDbWizard();
            ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
            if (dlg.open() == 0) {
                DatabaseModelBean dbModel = wizard.getCreateDb();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>(1);
                dbList.add(dbModel);
                addToCurrDbList(dbList);
            }
        }
    });
    Button removeBtn = new Button(composite, SWT.NONE);
    removeBtn.setText(Messages.getString("newproject.NewProjectTmPage.removeBtn"));
    removeBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            removeForCurrDbList((IStructuredSelection) tableViewer.getSelection());
        }
    });
    Button importTmxBtn = new Button(composite, SWT.NONE);
    importTmxBtn.setText(Messages.getString("newproject.NewProjectTmPage.importTmxBtn"));
    importTmxBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            Iterator<?> it = selection.iterator();
            if (it.hasNext()) {
                DatabaseModelBean dbModel = (DatabaseModelBean) it.next();
                ImportTmxWizard wizard = new ImportTmxWizard(dbModel);
                ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
                if (dlg.open() == 0) {
                    checkDbHashMatch(dbModel, "M");
                    tableViewer.refresh();
                }
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("newproject.NewProjectTmPage.msgTitle"), Messages.getString("newproject.NewProjectTmPage.msg3"));
            }
        }
    });
    addBtn.setFocus();
    setControl(container);
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ImportTmxWizard(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Table(org.eclipse.swt.widgets.Table) TmDbManagerDialog(net.heartsome.cat.database.ui.tm.dialog.TmDbManagerDialog) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) SQLException(java.sql.SQLException) NewTmDbWizard(net.heartsome.cat.database.ui.tm.wizard.NewTmDbWizard) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ImportTmxWizardDialog(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizardDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) Map(java.util.Map)

Aggregations

SQLException (java.sql.SQLException)3 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)3 ImportTmxWizard (net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard)3 ImportTmxWizardDialog (net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizardDialog)3 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Button (org.eclipse.swt.widgets.Button)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 Table (org.eclipse.swt.widgets.Table)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2