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);
}
}
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());
}
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());
}
}
}
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);
}
});
}
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());
}
}
Aggregations