Search in sources :

Example 21 with MetaData

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

the class NewTmDbBaseInfoPage method saveToServerConfigFile.

private void saveToServerConfigFile(SystemDBOperator dbOp) {
    DatabaseConfiger cf = new DatabaseConfiger();
    DatabaseModelBean bean = new DatabaseModelBean();
    MetaData md = dbOp.getMetaData();
    bean.metaDatatToBean(md);
    // 判断当前服务器是否已经存在
    String serverId = cf.isServerExist(bean, md);
    if (serverId == null || serverId.equals("")) {
        // 不存在
        cf.addServerConfig(bean);
    } else {
        bean.setId(serverId);
        cf.updateServerConfigById(serverId, bean);
    }
}
Also used : MetaData(net.heartsome.cat.common.bean.MetaData) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) DatabaseConfiger(net.heartsome.cat.database.ui.core.DatabaseConfiger)

Example 22 with MetaData

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

the class TmDbManagerDialog method updateServer.

/**
	 * 更新当前操作的服务器配置信息到配置文件中
	 * @param currServer
	 *            需要处理的服务器配置信息
	 * @param currDbTypeServers
	 *            当前数据库类型下的所有服务器,用于显示在界面上;
	 */
private void updateServer(DatabaseModelBean currServer, List<DatabaseModelBean> currDbTypeServers) {
    MetaData metaDataWithCheck = dbMetaDataMap.get(currServer.getDbType());
    DatabaseModelBean hasChanged = configIsChanged(currDbTypeServers, currServer, metaDataWithCheck);
    if (hasChanged != null) {
        currServer.copyToOtherIntance(hasChanged);
        configer.updateServerConfigById(hasChanged.getId(), hasChanged);
    }
    setLastSelectedServer(currServer.getId());
}
Also used : MetaData(net.heartsome.cat.common.bean.MetaData) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean)

Example 23 with MetaData

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

the class ListPropCol method setValue.

/**
	 * 处理添加/删除标记以及保存修改后的值(只保存在表格中)
	 * @see de.jaret.util.ui.table.model.PropCol#setValue(de.jaret.util.ui.table.model.IRow, java.lang.Object)
	 */
@SuppressWarnings("rawtypes")
public void setValue(IRow row, Object value) {
    Object oldValue = getValue(row);
    if (isRealModification(oldValue, value)) {
        try {
            Object base = row;
            for (int i = 0; i < _propPath.length - 1; i++) {
                String propName = _propPath[i];
                Method getter = base.getClass().getMethod("get" + propName, new Class[] {});
                base = getter.invoke(base, new Object[] {});
            }
            if (_accessor == null) {
                Class<?> clazz;
                if (value == null) {
                    clazz = getContentClass(row);
                } else {
                    if (value instanceof Enum) {
                        clazz = ((Enum) value).getDeclaringClass();
                    } else {
                        clazz = value.getClass();
                    }
                    if (clazz.equals(Boolean.class)) {
                        clazz = Boolean.TYPE;
                    } else if (clazz.equals(Integer.class)) {
                        clazz = Integer.TYPE;
                    } else if (clazz.equals(Double.class)) {
                        clazz = Double.TYPE;
                    }
                }
                if (index >= 0 && base instanceof XPropRow) {
                    XPropRow propRow = (XPropRow) base;
                    List<String> list = propRow.getLstTarget();
                    list.set(index, (String) value);
                    Method setter = base.getClass().getMethod("set" + _propPath[_propPath.length - 1], new Class[] { list.getClass() });
                    setter.invoke(base, new Object[] { list });
                } else {
                    //						添加/删除标记
                    if (index < 0 && base instanceof XPropRow) {
                        XPropRow propRow = (XPropRow) base;
                        HashMap<String, String> map = (HashMap<String, String>) propRow.getDataMap();
                        boolean blnIsAddTag = (Boolean) value;
                        MetaData metaData = (MetaData) propRow.getData("metaData");
                        DBOperator dbop = DatabaseService.getDBOperator(metaData);
                        try {
                            dbop.start();
                            dbop.addOrRemoveFlag(blnIsAddTag, map.get("id"));
                            dbop.commit();
                        } catch (SQLException e1) {
                            try {
                                dbop.rollBack();
                            } catch (SQLException e) {
                                String text = blnIsAddTag ? Messages.getString("dialog.ListPropCol.logger1") : Messages.getString("dialog.ListPropCol.logger2");
                                LOGGER.error(text + Messages.getString("dialog.ListPropCol.logger3"), e);
                            }
                        } catch (ClassNotFoundException e1) {
                            try {
                                dbop.rollBack();
                            } catch (SQLException e) {
                                LOGGER.error(Messages.getString("dialog.ListPropCol.logger4"), e);
                            }
                        } finally {
                            try {
                                if (dbop != null) {
                                    dbop.end();
                                }
                            } catch (SQLException e) {
                                LOGGER.error("", e);
                            }
                        }
                    }
                    Method setter = base.getClass().getMethod("set" + _propPath[_propPath.length - 1], new Class[] { clazz });
                    setter.invoke(base, new Object[] { value });
                }
            } else {
                _accessor.setValue(base, value);
            }
            fireValueChanged(row, this, oldValue, value);
        } catch (Exception e) {
            LOGGER.error("", e);
            e.printStackTrace();
            throw new RuntimeException("Could not set value " + e.getLocalizedMessage());
        }
    }
}
Also used : HashMap(java.util.HashMap) SQLException(java.sql.SQLException) DBOperator(net.heartsome.cat.database.DBOperator) Method(java.lang.reflect.Method) SQLException(java.sql.SQLException) MetaData(net.heartsome.cat.common.bean.MetaData)

Example 24 with MetaData

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

the class ConcordanceSearchDialog method initLanguageMenu.

/**
	 * 初始化语言菜单 ;
	 */
private void initLanguageMenu() {
    Set<String> set = new HashSet<String>();
    for (DatabaseModelBean model : lstDatabase) {
        MetaData metaData = model.toDbMetaData();
        DBOperator dbop = DatabaseService.getDBOperator(metaData);
        if (null == dbop) {
            continue;
        }
        try {
            dbop.start();
            set.addAll(dbop.getLanguages());
        } catch (SQLException e) {
            LOGGER.error(Messages.getString("dialog.ConcordanceSearchDialog.logger1"), e);
        } catch (ClassNotFoundException e) {
            LOGGER.error(Messages.getString("dialog.ConcordanceSearchDialog.logger1"), e);
        } finally {
            try {
                if (dbop != null) {
                    dbop.end();
                }
            } catch (SQLException e) {
                LOGGER.error("", e);
            }
        }
    }
    set.remove(strSrcLang);
    set.remove(strTgtLang);
    lstLangs = new ArrayList<String>(set);
    Collections.sort(lstLangs);
    // cmbLang.setItems((String[]) langs.toArray(new String[langs.size()]));
    menu = new Menu(getShell(), SWT.POP_UP);
    if (strTgtLang != null) {
        MenuItem itemTgt = new MenuItem(menu, SWT.CHECK);
        itemTgt.setText(strTgtLang);
        itemTgt.setSelection(true);
        itemTgt.setEnabled(false);
    }
    for (final String lang : lstLangs) {
        final MenuItem itemLang = new MenuItem(menu, SWT.CHECK);
        itemLang.setText(lang);
        itemLang.addListener(SWT.Selection, new Listener() {

            public void handleEvent(Event event) {
                ArrayList<IColumn> lstShowColumn = new ArrayList<IColumn>();
                // }
                if (itemLang.getSelection()) {
                    // int totalWidth = 0;
                    boolean blnIsResetWidth = false;
                    // tableModel.getColumnCount()
                    for (int index = 1; index < tableModel.getColumnCount(); index++) {
                        IColumn column = tableModel.getColumn(index);
                        int width = jTable.getTableViewState().getColumnWidth(column);
                        if (column.getHeaderLabel().equals(lang) && width == 0) {
                            jTable.getTableViewState().setColumnVisible(column, true);
                            jTable.updateColumnList();
                            jTable.redraw();
                            // jTable.getTableViewState().setColumnWidth(column, width0);
                            lstShowColumn.add(column);
                            blnIsResetWidth = true;
                        } else if (width > 0) {
                            // totalWidth += width;
                            lstShowColumn.add(column);
                        // jTable.columnWidthChanged(column, width0);
                        }
                    }
                    if (blnIsResetWidth) {
                        int width = totalWidth / lstShowColumn.size() + 1;
                        for (int colNum = 1; colNum < jTable.getColumnCount(); colNum++) {
                            jTable.getTableViewState().setColumnWidth(jTable.getColumn(colNum), width);
                        }
                    // for (IColumn column : lstShowColumn) {
                    // // jTable.getTableViewState().setColumnVisible(column, true);
                    // jTable.getTableViewState().setColumnWidth(column, width);
                    // }
                    }
                // initGroupIdAndSearch();
                } else {
                    // int totalWidth = 0;
                    IColumn deleteColumn = null;
                    for (int index = 1; index < jTable.getColumnCount(); index++) {
                        IColumn column = jTable.getColumn(index);
                        int width = jTable.getTableViewState().getColumnWidth(column);
                        if (width > 0) {
                            // totalWidth += width;
                            lstShowColumn.add(column);
                        }
                        if (column.getHeaderLabel().equals(lang)) {
                            deleteColumn = column;
                        // 将删除列中的数据清空,以保证行高正常调整
                        // for (GridItem item : tableModel.getRowCount()) {
                        // item.setText(index, "");
                        // }
                        }
                    }
                    // int width = (jTable.getTableViewState().getColumnWidth(deleteColumn) * lstShowColumn.size() -
                    // 100)
                    // / (lstShowColumn.size() - 1);
                    int width = totalWidth / (lstShowColumn.size() - 1) + 1;
                    jTable.getTableViewState().setColumnWidth(deleteColumn, 0);
                    jTable.getTableViewState().setColumnVisible(deleteColumn, false);
                    lstShowColumn.remove(deleteColumn);
                    for (IColumn column : lstShowColumn) {
                        jTable.getTableViewState().setColumnWidth(column, width);
                    }
                // initGroupIdAndSearch();
                }
            }
        });
    }
    btnSelectLang.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            Rectangle rect = btnSelectLang.getBounds();
            Point pt = btnSelectLang.toDisplay(new Point(event.x, event.y + rect.height));
            // Point pt = btnSelectLang.toDisplay(new Point(event.x + rect.width, event.y + rect.height));
            menu.setOrientation(getShell().getOrientation());
            menu.setLocation(pt.x, pt.y);
            menu.setVisible(true);
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) SelectionListener(org.eclipse.swt.events.SelectionListener) Listener(org.eclipse.swt.widgets.Listener) IExpansionListener(org.eclipse.ui.forms.events.IExpansionListener) KeyListener(org.eclipse.swt.events.KeyListener) SQLException(java.sql.SQLException) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) DBOperator(net.heartsome.cat.database.DBOperator) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) IColumn(de.jaret.util.ui.table.model.IColumn) MetaData(net.heartsome.cat.common.bean.MetaData) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) Event(org.eclipse.swt.widgets.Event) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Menu(org.eclipse.swt.widgets.Menu) HashSet(java.util.HashSet)

Example 25 with MetaData

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

the class TermDbManagerDialog method resetInputValue.

/**
	 * 当选择数据库类型节点时,重置所有输入 ;
	 */
private void resetInputValue() {
    MetaData metaData = dbMetaDataMap.get(getCurrDbType());
    currServer.setId("");
    currServer.setDbType(metaData.getDbType());
    currServer.setItlDBLocation("");
    if (metaData.dataPathSupported()) {
        currServer.setItlDBLocation(metaData.getDataPath());
    }
    currServer.setHost("");
    if (metaData.serverNameSupported()) {
        currServer.setHost(metaData.getServerName());
    }
    currServer.setInstance("");
    if (metaData.instanceSupported()) {
        currServer.setInstance(metaData.getInstance());
    }
    currServer.setPort("");
    if (metaData.portSupported()) {
        currServer.setPort(metaData.getPort());
    }
    currServer.setUserName("");
    if (metaData.userNameSupported()) {
        currServer.setUserName(metaData.getUserName());
    }
    currServer.setPassword("");
    if (metaData.passwordSupported()) {
        currServer.setPassword(metaData.getPassword());
    }
}
Also used : MetaData(net.heartsome.cat.common.bean.MetaData)

Aggregations

MetaData (net.heartsome.cat.common.bean.MetaData)40 SQLException (java.sql.SQLException)21 ArrayList (java.util.ArrayList)14 Properties (java.util.Properties)13 Connection (java.sql.Connection)11 PreparedStatement (java.sql.PreparedStatement)11 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)8 DBOperator (net.heartsome.cat.database.DBOperator)8 Statement (java.sql.Statement)6 ResultSet (java.sql.ResultSet)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Entry (java.util.Map.Entry)5 Point (org.eclipse.swt.graphics.Point)5 MenuItem (org.eclipse.swt.widgets.MenuItem)5 List (java.util.List)4 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)4 File (java.io.File)2 HashSet (java.util.HashSet)2 IdentityHashMap (java.util.IdentityHashMap)2