Search in sources :

Example 16 with DatabaseModelBean

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

the class ImportProjectWizardPage2 method resetConfigContent.

public void resetConfigContent(IProject project) {
    ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
    if (null == projectConfig) {
        return;
    }
    // FIX Bug#3709 导入项目时更新库--打开XLIFF文件时无法更新同名的记忆库/术语库
    // 重新加载一次数据,如果ProjectConfigerFactory缓存中含有导入项目的名称时,有bug
    projectConfig.reloadConfig();
    ProjectInfoBean currentProjectConfig = projectConfig.getCurrentProjectConfig();
    List<DatabaseModelBean> tmDb = currentProjectConfig.getTmDb();
    int index = 0;
    for (DatabaseModelBean bean : tmDb) {
        // update tm config
        if ("SQLite".equals(bean.getDbType())) {
            resetSqliteTMNameAndPath(project, bean, index);
            index++;
        }
    }
    List<DatabaseModelBean> tbDb = currentProjectConfig.getTbDb();
    index = 0;
    for (DatabaseModelBean bean : tbDb) {
        // update tb config
        if ("SQLite".equals(bean.getDbType())) {
            resetSqliteTBNameAndPath(project, bean, index);
            index++;
        }
    }
    projectConfig.updateProjectConfig(currentProjectConfig);
    try {
        project.refreshLocal(IResource.DEPTH_ZERO, null);
    } catch (CoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) CoreException(org.eclipse.core.runtime.CoreException) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean)

Example 17 with DatabaseModelBean

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

the class TermDbManagerImportWizardTbxPage 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(3, false));
    Label lblTmx = new Label(container, SWT.NONE);
    lblTmx.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblTmx.setText(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.lblTmx"));
    tbxFileText = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    tbxFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tbxFileText.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            validator();
        }
    });
    Button tmxFileBorwserBtn = new Button(container, SWT.NONE);
    tmxFileBorwserBtn.setText(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.tmxFileBorwserBtn"));
    tmxFileBorwserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dlg = new FileDialog(getShell());
            String[] filterExt = { "*.tbx", "*.xlsx", "*.txt" };
            dlg.setFilterExtensions(filterExt);
            String path = dlg.open();
            // Messages.getString("wizard.TermDbManagerImportWizardTbxPage.openFile"), SWT.OPEN);
            if (path != null) {
                tbxFileText.setText(path);
            }
        }
    });
    Label lblNewLabel = new Label(container, SWT.NONE);
    lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblNewLabel.setText(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.lblNewLabel"));
    text = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    text.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            validator();
        }
    });
    HSDropDownButton addBtn = new HSDropDownButton(container, SWT.NONE);
    addBtn.setText(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.button"));
    Menu addMenu = addBtn.getMenu();
    MenuItem item = new MenuItem(addMenu, SWT.PUSH);
    item.setText(Messages.getString("tb.dialog.addTb.DropDownButton.AddFileTb"));
    item.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialg = new FileDialog(getShell());
            fileDialg.setFilterExtensions(new String[] { "*.hstb", "*.*" });
            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.convertFile2TbModel(f, false);
            } catch (Exception e1) {
                MessageDialog.openError(getShell(), Messages.getString("tb.dialog.addFileTb.errorTitle"), e1.getMessage());
            }
            if (r == null) {
                return;
            }
            Iterator<DatabaseModelBean> it = r.keySet().iterator();
            if (it.hasNext()) {
                dbModel = it.next();
                text.setText(f.getAbsolutePath());
            }
        }
    });
    MenuItem serverItem = new MenuItem(addMenu, SWT.PUSH);
    serverItem.setText(Messages.getString("tb.dialog.addTb.DropDownButton.AddServerTb"));
    serverItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TermDbManagerDialog dialog = new TermDbManagerDialog(getShell());
            dialog.setDialogUseFor(TermDbManagerDialog.TYPE_DBSELECTED);
            if (dialog.open() == Window.OK) {
                Iterator<DatabaseModelBean> it = dialog.getHasSelectedDatabase().keySet().iterator();
                List<DatabaseModelBean> list = new ArrayList<DatabaseModelBean>();
                while (it.hasNext()) {
                    list.add(it.next());
                }
                if (list.size() > 0) {
                    // 只取第一个.
                    dbModel = list.get(0);
                    text.setText(dbModel.getDbName());
                }
            }
        }
    });
    setControl(container);
}
Also used : HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) MenuItem(org.eclipse.swt.widgets.MenuItem) ImportException(net.heartsome.cat.common.core.exception.ImportException) TermDbManagerDialog(net.heartsome.cat.database.ui.tb.dialog.TermDbManagerDialog) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) Map(java.util.Map)

Example 18 with DatabaseModelBean

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

the class ConcordanceSearchDialog method filterUnAvaliableDatabase.

/**
	 * 过滤掉系统不支持的数据库
	 *  ;
	 */
public void filterUnAvaliableDatabase() {
    Set<String> sysAvailableDatabase = getSysAvailableDatabase();
    List<DatabaseModelBean> rs = new ArrayList<DatabaseModelBean>(3);
    for (DatabaseModelBean dmb : lstDatabase) {
        if (sysAvailableDatabase.contains(dmb.getDbType())) {
            //lstDatabase.remove(dmb);
            rs.add(dmb);
        }
    }
    lstDatabase = rs;
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ArrayList(java.util.ArrayList)

Example 19 with DatabaseModelBean

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

the class TmDbManagerDialog method addListeners.

/**
	 * Add Selection Listener to tree viewer
	 * @param viewer
	 *            ;
	 */
private void addListeners(final TreeViewer viewer) {
    // 选择事件
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof DatabaseModelBean) {
                DatabaseModelBean bean = (DatabaseModelBean) obj;
                setCurrDbType(bean.getDbType());
                bean.copyToOtherIntance(currServer);
                SystemDBOperator dbop = getCurrSysDbOp();
                if (dbop != null) {
                    executeSearch(dbop);
                }
                // 当数据库类型发生改变时重新初始化界面
                initUI(false);
            } else if (obj instanceof String) {
                setCurrDbType((String) obj);
                resetInputValue();
                currServerdbListInput.clear();
                initUI(true);
            }
        }
    });
    // 双击展开事件
    ((Tree) viewer.getControl()).addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(final SelectionEvent event) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof String) {
                String type = (String) obj;
                boolean expanded = viewer.getExpandedState(type);
                viewer.setExpandedState(type, !expanded);
            }
        }
    });
    // 右键菜单事件,判断何时出现右键菜单
    viewer.getControl().addMenuDetectListener(new MenuDetectListener() {

        public void menuDetected(MenuDetectEvent e) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            Tree tree = treeViewer.getTree();
            if (obj instanceof DatabaseModelBean) {
                // 将菜单挂到树上
                tree.setMenu(treePopMenu);
            } else {
                tree.setMenu(null);
            }
        }
    });
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener)

Example 20 with DatabaseModelBean

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

the class ConcordanceSearchHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    if (!isEnabled()) {
        return null;
    }
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (editor instanceof IXliffEditor) {
        IXliffEditor xliffEditor = (IXliffEditor) editor;
        String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
        IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
        if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
            // IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
            IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
            ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
            List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
            if (lstDatabase.size() == 0) {
                MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.ConcordanceSearchHandler.msgTitle"), Messages.getString("handler.ConcordanceSearchHandler.msg"));
                return null;
            }
            String selectText = xliffEditor.getSelectPureText();
            if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
                selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
            } else if (selectText == null) {
                selectText = "";
            }
            String srcLang = xliffEditor.getSrcColumnName();
            String tgtLang = xliffEditor.getTgtColumnName();
            ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file, srcLang, tgtLang, selectText.trim());
            Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
            Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
            dialog.open();
            if (srcLangL.isBidi() || tgtLangL.isBidi()) {
                dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
            }
            if (selectText != null && !selectText.trim().equals("")) {
                dialog.initGroupIdAndSearch();
                IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
                ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
                Command command = commandService.getCommand(ActionFactory.COPY.getCommandId());
                IEvaluationService evalService = (IEvaluationService) site.getService(IEvaluationService.class);
                IEvaluationContext currentState = evalService.getCurrentState();
                ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
                try {
                    command.executeWithChecks(executionEvent);
                } catch (Exception e1) {
                }
            }
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ConcordanceSearchDialog(net.heartsome.cat.database.ui.tm.dialog.ConcordanceSearchDialog) IEvaluationContext(org.eclipse.core.expressions.IEvaluationContext) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) ICommandService(org.eclipse.ui.commands.ICommandService) ExecutionException(org.eclipse.core.commands.ExecutionException) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) Language(net.heartsome.cat.common.locale.Language) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) Command(org.eclipse.core.commands.Command) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IEvaluationService(org.eclipse.ui.services.IEvaluationService)

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