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