Search in sources :

Example 61 with DatabaseModelBean

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

the class DatabaseConfiger method getAllServerConfig.

/**
	 * 获取数据库服务器配置文件中保存的所有服务器信息
	 * @return Map<数据库类型,List<数据库配置信息> 参考{@link DatabaseModelBean};
	 */
public Map<String, List<DatabaseModelBean>> getAllServerConfig() {
    Map<String, List<DatabaseModelBean>> map = new HashMap<String, List<DatabaseModelBean>>();
    try {
        AutoPilot tempAp = new AutoPilot(vu.getVTDNav());
        tempAp.selectXPath("/servers/server");
        while (tempAp.evalXPath() != -1) {
            String type = vu.getCurrentElementAttribut("type", "");
            if (map.containsKey(type)) {
                continue;
            } else {
                map.put(type, getServersConfigByType(type));
            }
        }
    } catch (XPathParseException e) {
        logger.error("", e);
    } catch (XPathEvalException e) {
        logger.error("", e);
    } catch (NavException e) {
        logger.error("", e);
    }
    return map;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) HashMap(java.util.HashMap) AutoPilot(com.ximpleware.AutoPilot) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 62 with DatabaseModelBean

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

the class NewTmDbWizard method getCreateDb.

public DatabaseModelBean getCreateDb() {
    DatabaseModelBean db = createDbPage.getDbModel();
    if (db.getDbType().equals(Constants.DBTYPE_SQLITE)) {
        String dbName = db.getDbName();
        dbName += ".hstm";
        db.setDbName(dbName);
    }
    return db;
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean)

Example 63 with DatabaseModelBean

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

the class TmDbManagerImportWizardTmxPage 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.TmDbManagerImportWizardTmxPage.lblTmx"));
    tmxFileText = new Text(container, SWT.BORDER | SWT.READ_ONLY);
    tmxFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    tmxFileText.addModifyListener(new ModifyListener() {

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

        public void widgetSelected(SelectionEvent e) {
            FileDialog dlg = new FileDialog(getShell());
            String[] filterExt = { "*.tmx;*.xlsx;*.txt" };
            dlg.setFilterExtensions(filterExt);
            String path = dlg.open();
            // Messages.getString("wizard.TmDbManagerImportWizardTmxPage.openFile"), SWT.OPEN);
            if (path != null) {
                tmxFileText.setText(path);
            }
        }
    });
    Label label = new Label(container, SWT.NONE);
    label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    label.setText(Messages.getString("wizard.TmDbManagerImportWizardTmxPage.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 selectedBtn = new HSDropDownButton(container, SWT.NONE);
    selectedBtn.setText(Messages.getString("wizard.TmDbManagerImportWizardTmxPage.button"));
    Menu selectMenu = selectedBtn.getMenu();
    MenuItem item = new MenuItem(selectMenu, 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()) {
                dbModel = it.next();
                text.setText(f.getAbsolutePath());
            }
        }
    });
    MenuItem serverItem = new MenuItem(selectMenu, 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> 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);
    initValue();
}
Also used : HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) TmDbManagerDialog(net.heartsome.cat.database.ui.tm.dialog.TmDbManagerDialog) 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) 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 64 with DatabaseModelBean

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

the class TmDbManagerDialog method selectSaveItem.

/**
	 * 选择当前选中的内容 ;
	 */
private void selectSaveItem() {
    if (getCurrDbType() != null) {
        boolean expanded = getTreeViewer().getExpandedState(getCurrDbType());
        if (!expanded) {
            getTreeViewer().setExpandedState(getCurrDbType(), !expanded);
        }
        DatabaseModelBean lastSelectItem = findServerBean(getCurrDbType(), getLastSelectedServer());
        if (lastSelectItem != null) {
            getTreeViewer().setSelection(new StructuredSelection(lastSelectItem), true);
            getTreeViewer().getControl().setFocus();
        } else {
            getTreeViewer().setSelection(new StructuredSelection(getCurrDbType()), true);
            getTreeViewer().getControl().setFocus();
        }
    }
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 65 with DatabaseModelBean

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

the class TmDbManagerDialog method initTreePopMenu.

/**
	 * 初始化树右键菜单 ;
	 */
private void initTreePopMenu() {
    MenuManager menuManager = new MenuManager("");
    menuManager.add(new Action(Messages.getString("dialog.TmDbManagerDialog.deleteAction")) {

        @Override
        public void run() {
            ISelection selection = getTreeViewer().getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
            Object obj = structuredSelection.getFirstElement();
            if (obj instanceof DatabaseModelBean) {
                List<DatabaseModelBean> currDbTypeServers = treeInputMap.get(currDbType);
                configer.deleteServerById(((DatabaseModelBean) obj).getId());
                int i = currDbTypeServers.indexOf(obj);
                currDbTypeServers.remove(i);
                getTreeViewer().refresh();
                if (currDbTypeServers.size() != 0) {
                    if (i > currDbTypeServers.size() - 1) {
                        setLastSelectedServer(currDbTypeServers.get(i - 1).getId());
                    } else {
                        setLastSelectedServer(currDbTypeServers.get(i).getId());
                    }
                    initUI(false);
                } else {
                    setLastSelectedServer(null);
                    initUI(true);
                }
                selectSaveItem();
            }
        }
    });
    Tree tree = treeViewer.getTree();
    this.treePopMenu = menuManager.createContextMenu(tree);
}
Also used : Action(org.eclipse.jface.action.Action) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) MenuManager(org.eclipse.jface.action.MenuManager) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) WritableList(org.eclipse.core.databinding.observable.list.WritableList) List(java.util.List) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

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