use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class ImportProjectWizardPage2 method resetConfigContent.
public void resetConfigContent(IProject project) {
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
if (null == projectConfig) {
return;
}
// FIX Bug#3709 导入项目时更新库--打开XLIFF文件时无法更新同名的记忆库/术语库
// 重新加载一次数据,如果ProjectConfigerFactory缓存中含有导入项目的名称时,有bug
projectConfig.reloadConfig();
ProjectInfoBean currentProjectConfig = projectConfig.getCurrentProjectConfig();
List<DatabaseModelBean> tmDb = currentProjectConfig.getTmDb();
int index = 0;
for (DatabaseModelBean bean : tmDb) {
// update tm config
if ("SQLite".equals(bean.getDbType())) {
resetSqliteTMNameAndPath(project, bean, index);
index++;
}
}
List<DatabaseModelBean> tbDb = currentProjectConfig.getTbDb();
index = 0;
for (DatabaseModelBean bean : tbDb) {
// update tb config
if ("SQLite".equals(bean.getDbType())) {
resetSqliteTBNameAndPath(project, bean, index);
index++;
}
}
projectConfig.updateProjectConfig(currentProjectConfig);
try {
project.refreshLocal(IResource.DEPTH_ZERO, null);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class TermDbManagerImportWizardTbxPage 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.TermDbManagerImportWizardTbxPage.lblTmx"));
tbxFileText = new Text(container, SWT.BORDER | SWT.READ_ONLY);
tbxFileText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
tbxFileText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
validator();
}
});
Button tmxFileBorwserBtn = new Button(container, SWT.NONE);
tmxFileBorwserBtn.setText(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.tmxFileBorwserBtn"));
tmxFileBorwserBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dlg = new FileDialog(getShell());
String[] filterExt = { "*.tbx", "*.xlsx", "*.txt" };
dlg.setFilterExtensions(filterExt);
String path = dlg.open();
// Messages.getString("wizard.TermDbManagerImportWizardTbxPage.openFile"), SWT.OPEN);
if (path != null) {
tbxFileText.setText(path);
}
}
});
Label lblNewLabel = new Label(container, SWT.NONE);
lblNewLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
lblNewLabel.setText(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.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 addBtn = new HSDropDownButton(container, SWT.NONE);
addBtn.setText(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.button"));
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()) {
dbModel = it.next();
text.setText(f.getAbsolutePath());
}
}
});
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> 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);
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class ConcordanceSearchDialog method filterUnAvaliableDatabase.
/**
* 过滤掉系统不支持的数据库
* ;
*/
public void filterUnAvaliableDatabase() {
Set<String> sysAvailableDatabase = getSysAvailableDatabase();
List<DatabaseModelBean> rs = new ArrayList<DatabaseModelBean>(3);
for (DatabaseModelBean dmb : lstDatabase) {
if (sysAvailableDatabase.contains(dmb.getDbType())) {
//lstDatabase.remove(dmb);
rs.add(dmb);
}
}
lstDatabase = rs;
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class TmDbManagerDialog method addListeners.
/**
* Add Selection Listener to tree viewer
* @param viewer
* ;
*/
private void addListeners(final TreeViewer viewer) {
// 选择事件
viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
if (selection.isEmpty()) {
return;
}
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object obj = structuredSelection.getFirstElement();
if (obj instanceof DatabaseModelBean) {
DatabaseModelBean bean = (DatabaseModelBean) obj;
setCurrDbType(bean.getDbType());
bean.copyToOtherIntance(currServer);
SystemDBOperator dbop = getCurrSysDbOp();
if (dbop != null) {
executeSearch(dbop);
}
// 当数据库类型发生改变时重新初始化界面
initUI(false);
} else if (obj instanceof String) {
setCurrDbType((String) obj);
resetInputValue();
currServerdbListInput.clear();
initUI(true);
}
}
});
// 双击展开事件
((Tree) viewer.getControl()).addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(final SelectionEvent event) {
ISelection selection = viewer.getSelection();
if (selection.isEmpty()) {
return;
}
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object obj = structuredSelection.getFirstElement();
if (obj instanceof String) {
String type = (String) obj;
boolean expanded = viewer.getExpandedState(type);
viewer.setExpandedState(type, !expanded);
}
}
});
// 右键菜单事件,判断何时出现右键菜单
viewer.getControl().addMenuDetectListener(new MenuDetectListener() {
public void menuDetected(MenuDetectEvent e) {
ISelection selection = viewer.getSelection();
if (selection.isEmpty()) {
return;
}
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Object obj = structuredSelection.getFirstElement();
Tree tree = treeViewer.getTree();
if (obj instanceof DatabaseModelBean) {
// 将菜单挂到树上
tree.setMenu(treePopMenu);
} else {
tree.setMenu(null);
}
}
});
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class ConcordanceSearchHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
if (!isEnabled()) {
return null;
}
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (editor instanceof IXliffEditor) {
IXliffEditor xliffEditor = (IXliffEditor) editor;
String XLIFF_EDITOR_ID = "net.heartsome.cat.ts.ui.xliffeditor.nattable.editor";
IEditorPart editorRefer = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (editorRefer.getSite().getId().equals(XLIFF_EDITOR_ID)) {
// IProject project = ((FileEditorInput) editorRefer.getEditorInput()).getFile().getProject();
IFile file = ((FileEditorInput) editorRefer.getEditorInput()).getFile();
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject());
List<DatabaseModelBean> lstDatabase = projectConfig.getAllTmDbs();
if (lstDatabase.size() == 0) {
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.ConcordanceSearchHandler.msgTitle"), Messages.getString("handler.ConcordanceSearchHandler.msg"));
return null;
}
String selectText = xliffEditor.getSelectPureText();
if ((selectText == null || selectText.equals("")) && xliffEditor.getSelectedRowIds().size() == 1) {
selectText = xliffEditor.getXLFHandler().getSrcPureText(xliffEditor.getSelectedRowIds().get(0));
} else if (selectText == null) {
selectText = "";
}
String srcLang = xliffEditor.getSrcColumnName();
String tgtLang = xliffEditor.getTgtColumnName();
ConcordanceSearchDialog dialog = new ConcordanceSearchDialog(editorRefer.getSite().getShell(), file, srcLang, tgtLang, selectText.trim());
Language srcLangL = LocaleService.getLanguageConfiger().getLanguageByCode(srcLang);
Language tgtLangL = LocaleService.getLanguageConfiger().getLanguageByCode(tgtLang);
dialog.open();
if (srcLangL.isBidi() || tgtLangL.isBidi()) {
dialog.getShell().setOrientation(SWT.RIGHT_TO_LEFT);
}
if (selectText != null && !selectText.trim().equals("")) {
dialog.initGroupIdAndSearch();
IWorkbenchPartSite site = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor().getSite();
ICommandService commandService = (ICommandService) site.getService(ICommandService.class);
Command command = commandService.getCommand(ActionFactory.COPY.getCommandId());
IEvaluationService evalService = (IEvaluationService) site.getService(IEvaluationService.class);
IEvaluationContext currentState = evalService.getCurrentState();
ExecutionEvent executionEvent = new ExecutionEvent(command, Collections.EMPTY_MAP, this, currentState);
try {
command.executeWithChecks(executionEvent);
} catch (Exception e1) {
}
}
}
}
return null;
}
Aggregations