use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class ConcordanceSearchDialog method initDatabaseCombo.
/**
* 初始化记忆库下拉框 ;
*/
private void initDatabaseCombo() {
List<String> lstItem = new ArrayList<String>();
lstItem.add(Messages.getString("dialog.ConcordanceSearchDialog.lstItem"));
// int selIndex = 0;
for (int i = 0; i < lstDatabase.size(); i++) {
DatabaseModelBean model = lstDatabase.get(i);
// if (model.isDefault()) {
// selIndex = i;
// }
lstItem.add(model.getDbName());
}
cmbDatabase.setItems((String[]) lstItem.toArray(new String[lstItem.size()]));
cmbDatabase.select(0);
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class UpdateTMWizard method performFinish.
public boolean performFinish() {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final boolean isDraft = page.isDraft();
final boolean isApproved = page.isApproved();
final boolean isSignedOff = page.isSignedOff();
final boolean isTranslated = page.isTranslated();
final boolean isLocked = page.isLocked();
if (!isDraft && !isApproved && !isSignedOff && !isTranslated && !isLocked) {
MessageDialog.openInformation(getShell(), Messages.getString("wizard.UpdateTMWizard.msgTitle"), Messages.getString("wizard.UpdateTMWizard.msg"));
return false;
}
IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
final int contextSize = ps.getInt(TMPreferenceConstants.CONTEXT_MATCH);
final int tmxImportStrategy = ps.getInt(TMPreferenceConstants.TM_UPDATE);
IRunnableWithProgress progress = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
monitor.setTaskName(Messages.getString("dialog.UpdateTMDialog.jobTask1"));
monitor.beginTask(Messages.getString("dialog.UpdateTMDialog.jobTask1"), lstXLIFF.size() * 2);
for (final IFile xliffFile : lstXLIFF) {
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(xliffFile.getProject());
DatabaseModelBean modelBean = projectConfig.getDefaultTMDb();
FileEditorInput editorInput = new FileEditorInput(xliffFile);
IEditorPart editorPart = activePage.findEditor(editorInput);
// 选择所有语言
XLFHandler handler = null;
if (editorPart != null && editorPart instanceof IXliffEditor) {
// xliff 文件已用 XLIFF 编辑器打开
IXliffEditor xliffEditor = (IXliffEditor) editorPart;
handler = xliffEditor.getXLFHandler();
} else {
// xliff 文件未打开
handler = new XLFHandler();
}
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask2"));
// 修改获取系统用户方式/*System.getProperty("user.name");*/
String systemUser = PlatformUI.getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
String[] arrTempTMX = handler.generateTMXToUpdateTM(xliffFile, isApproved, isSignedOff, isTranslated, isDraft, isLocked, contextSize, systemUser);
monitor.worked(1);
if (arrTempTMX != null) {
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask3"));
// }
try {
DatabaseService.importTmxWithString(modelBean.toDbMetaData(), arrTempTMX[1], new SubProgressMonitor(monitor, 1), tmxImportStrategy, false, arrTempTMX[0]);
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateTMDialog.job.msgTitle"), msg);
}
});
canFinish = false;
return;
}
}
}
monitor.done();
// 刷新项目
ResourceUtils.refreshCurentSelectProject();
canFinish = true;
}
};
try {
getContainer().run(true, true, progress);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return canFinish;
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class ProjectSettingTMPage method createContents.
/**
* Create contents of the preference page.
* @param parent
*/
@Override
public Control createContents(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 (null == dbModel) {
return;
}
if (Constants.DBTYPE_SQLITE.equals(dbModel.getDbType())) {
String path = dbModel.getItlDBLocation() + File.separator + dbModel.getDbName();
File file = new File(path);
if (!file.exists()) {
setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.FileNotFound"));
return;
} else {
setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.title"));
}
}
if (dbModel != null && !dbModel.isHasMatch()) {
setMessage(Messages.getString("projectsetting.ProjectSettingTMPage.msg1"));
}
}
});
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("projectsetting.ProjectSettingTMPage.addBtn"));
Menu addMenu = addBtn.getMenu();
MenuItem item = new MenuItem(addMenu, 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()) {
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("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> dbList = new ArrayList<DatabaseModelBean>();
while (it.hasNext()) {
dbList.add(it.next());
}
addToCurrDbList(dbList);
}
}
});
Button createBtn = new Button(composite, SWT.NONE);
createBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.createBtn"));
createBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
NewTmDbWizard wizard = new NewTmDbWizard();
ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
if (dlg.open() == 0) {
DatabaseModelBean dbModel = wizard.getCreateDb();
List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
dbList.add(dbModel);
addToCurrDbList(dbList);
}
}
});
Button removeBtn = new Button(composite, SWT.NONE);
removeBtn.setText(Messages.getString("projectsetting.ProjectSettingTMPage.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("projectsetting.ProjectSettingTMPage.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();
ImportTmxWizard wizard = new ImportTmxWizard(dbModel);
ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard);
if (dlg.open() == 0) {
checkDbHashMatch(dbModel);
tableViewer.refresh();
}
// 刷新项目
ResourceUtils.refreshCurentSelectProject();
} else {
MessageDialog.openInformation(getShell(), Messages.getString("projectsetting.ProjectSettingTMPage.msgTitle"), Messages.getString("projectsetting.ProjectSettingTMPage.msg2"));
}
}
});
addBtn.setFocus();
Point addPoint = addBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
Point createPoint = createBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
Point remPoint = removeBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
Point importPoint = importTmxBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(addPoint.x, createPoint.x)));
GridData btnData = new GridData();
btnData.widthHint = width + 10;
addBtn.setLayoutData(btnData);
createBtn.setLayoutData(btnData);
removeBtn.setLayoutData(btnData);
importTmxBtn.setLayoutData(btnData);
return container;
}
use of net.heartsome.cat.common.bean.DatabaseModelBean 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.DatabaseModelBean 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());
}
Aggregations