use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class TermBaseSearchDialog method search.
/**
* 搜索术语库 ;
*/
@SuppressWarnings("unchecked")
public void search() {
updateHistory(cmbSearch, lstSearchHistory);
String searchText = cmbSearch.getText();
searchText = cleanString(searchText);
if (searchText == null || searchText.trim().equals("")) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermBaseSearchDialog.msgTitle"), Messages.getString("dialog.TermBaseSearchDialog.msg1"));
return;
}
if (lstDatabase.size() == 0) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermBaseSearchDialog.msgTitle"), Messages.getString("dialog.TermBaseSearchDialog.msg2"));
return;
}
ArrayList<String> lstSelLangs = new ArrayList<String>();
lstSelLangs.add(strSrcLang);
for (MenuItem item : menu.getItems()) {
if (item.getSelection()) {
lstSelLangs.add(item.getText());
}
}
LinkedHashMap<MetaData, HashMap<String, IdentityHashMap<String, String>>> mapResult = new LinkedHashMap<MetaData, HashMap<String, IdentityHashMap<String, String>>>();
ArrayList<DatabaseModelBean> lstDB = new ArrayList<DatabaseModelBean>();
if (cmbDatabase.getSelectionIndex() == 0) {
lstDB.addAll(lstDatabase);
} else {
DatabaseModelBean model = lstDatabase.get(cmbDatabase.getSelectionIndex() - 1);
lstDB.add(model);
}
for (DatabaseModelBean model : lstDB) {
MetaData metaData = model.toDbMetaData();
DBOperator dbop = DatabaseService.getDBOperator(metaData);
try {
dbop.start();
HashMap<String, IdentityHashMap<String, String>> mapTermBase = dbop.getTermBaseResult(searchText, !(btnIsCaseSensitive.getSelection()), btnApplyRegularExpression.getSelection(), btnIsIgnoreMark.getSelection(), strSrcLang, lstSelLangs, spiMatchQuality.getSelection());
if (mapTermBase != null && mapTermBase.size() > 0) {
mapResult.put(metaData, mapTermBase);
}
} catch (SQLException e1) {
LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger2"), e1);
} catch (ClassNotFoundException e1) {
LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.logger3"), e1);
} finally {
try {
if (dbop != null) {
dbop.end();
}
} catch (SQLException e) {
LOGGER.error("", e);
}
}
}
Rectangle rect = grid.getBounds();
grid.removeAll();
grid.pack();
grid.setHeaderVisible(true);
grid.setBounds(rect);
if (mapResult.size() == 0) {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermBaseSearchDialog.msgTitle"), Messages.getString("dialog.TermBaseSearchDialog.msg3"));
return;
}
srcCellRenderer.setStrText(searchText);
srcCellRenderer.setBlnIsCaseSensitive(btnIsCaseSensitive.getSelection());
srcCellRenderer.setBlnIsApplyRegular(btnApplyRegularExpression.getSelection());
if (mapResult.size() > 0) {
if (btnApplyRegularExpression.getSelection()) {
Iterator<Entry<MetaData, HashMap<String, IdentityHashMap<String, String>>>> iterator = mapResult.entrySet().iterator();
while (iterator.hasNext()) {
Entry<MetaData, HashMap<String, IdentityHashMap<String, String>>> entry = iterator.next();
MetaData metaData1 = entry.getKey();
HashMap<String, IdentityHashMap<String, String>> map = entry.getValue();
Iterator<Entry<String, IdentityHashMap<String, String>>> it = map.entrySet().iterator();
while (it.hasNext()) {
Entry<String, IdentityHashMap<String, String>> e = it.next();
createGridItem(metaData1, e.getValue());
}
}
} else {
LinkedHashMap<String, Object[]> map = sortMap(mapResult);
Iterator<Entry<String, Object[]>> it = map.entrySet().iterator();
while (it.hasNext()) {
Entry<String, Object[]> entry = it.next();
Object[] arrObj = entry.getValue();
createGridItem((MetaData) arrObj[0], (IdentityHashMap<String, String>) arrObj[1]);
}
}
}
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class TermBaseSearchDialog 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.TermBaseSearchDialog.logger1"), e);
} catch (ClassNotFoundException e) {
LOGGER.error(Messages.getString("dialog.TermBaseSearchDialog.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<GridColumn> lstShowColumn = new ArrayList<GridColumn>();
// 每增加一列,除标记列外的其他列的和加100,然后平均分配给各个语言列,删除一列则做相反的操作
if (itemLang.getSelection()) {
int totalWidth = 0;
boolean blnIsResetWidth = false;
for (int index = 0; index < grid.getColumnCount(); index++) {
GridColumn column = grid.getColumn(index);
if (column.getText().equals(lang) && column.getWidth() == 0) {
lstShowColumn.add(column);
blnIsResetWidth = true;
} else if (column.getWidth() > 0) {
totalWidth += column.getWidth();
lstShowColumn.add(column);
}
}
if (blnIsResetWidth) {
int width = (totalWidth + 100) / lstShowColumn.size();
for (GridColumn column : lstShowColumn) {
column.setWidth(width);
}
}
// if (grid.getItemCount() > 0) {
// search();
// }
} else {
GridColumn deleteColumn = null;
for (int index = 0; index < grid.getColumnCount(); index++) {
GridColumn column = grid.getColumn(index);
if (column.getWidth() > 0) {
lstShowColumn.add(column);
}
if (column.getText().equals(lang)) {
deleteColumn = column;
// 将删除列中的数据清空,以保证行高正常调整
for (GridItem item : grid.getItems()) {
item.setText(index, "");
}
}
}
int width = (deleteColumn.getWidth() * lstShowColumn.size() - 100) / (lstShowColumn.size() - 1);
deleteColumn.setWidth(0);
lstShowColumn.remove(deleteColumn);
for (GridColumn column : lstShowColumn) {
column.setWidth(width);
}
// search();
}
}
});
}
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class TermDbManagerDialog method addServerWithExistCheck.
/**
* 将当前操作的服务器配置信息添加到配置文件中<br>
* 在添加前,先判断该服务器是否已经存在,如果已经存在则更新
* @param currServer
* 需要处理的配置信息
* @param currDbTypeServers
* 当前数据库类型下的所有服务器,用于显示在界面上;
*/
private void addServerWithExistCheck(DatabaseModelBean currServer, List<DatabaseModelBean> currDbTypeServers) {
DatabaseModelBean bean = currServer.copyToOtherIntance(new DatabaseModelBean());
String existSerId = configer.isServerExist(bean, getCurrDbMetaData());
if (existSerId != null && !existSerId.equals("")) {
if (!bean.getId().equals(existSerId)) {
configer.deleteServerById(bean.getId());
for (DatabaseModelBean temp : currDbTypeServers) {
if (temp.getId().equals(bean.getId())) {
currDbTypeServers.remove(temp);
break;
}
}
}
bean.setId(existSerId);
currServer.setId(existSerId);
updateServer(bean, currDbTypeServers);
return;
}
configer.addServerConfig(bean);
currDbTypeServers.add(bean);
setLastSelectedServer(bean.getId());
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class NewProjectTbPage 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.NewProjectTbPage.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("newproject.NewProjectTbPage.addBtn"));
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()) {
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("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> 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.NewProjectTbPage.createBtn"));
createBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
NewTermDbWizard wizard = new NewTermDbWizard();
TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(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.NewProjectTbPage.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.NewProjectTbPage.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();
TbxImportWizard wizard = new TbxImportWizard(dbModel);
TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(getShell(), wizard);
if (dlg.open() == 0) {
checkDbHashMatch(dbModel);
tableViewer.refresh();
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("newproject.NewProjectTbPage.msgTitle"), Messages.getString("newproject.NewProjectTbPage.msg3"));
}
}
});
addBtn.setFocus();
setControl(container);
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class NewProjectTbPage method checkDbIsExist.
/**
* 检查当前库是否已经存在
* @param b
* @return ;
*/
private boolean checkDbIsExist(List<Object> curDbList, DatabaseModelBean b) {
for (int i = 0; i < curDbList.size(); i++) {
DatabaseModelBean a = (DatabaseModelBean) curDbList.get(i);
String dbname = a.getDbName();
String host = a.getHost();
String port = a.getPort();
String instance = a.getInstance();
String localPath = a.getItlDBLocation();
if (b.getDbName().equals(dbname) && b.getHost().equals(host) && b.getItlDBLocation().equals(localPath) && b.getPort().equals(port) && b.getInstance().equals(instance)) {
return true;
}
}
return false;
}
Aggregations