use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class ProjectSettingTMPage method changeDefaultDatabaseSet.
/**
* 修改导入项目时,其他不可用的数据库设置为默认库 ;
*/
public void changeDefaultDatabaseSet() {
List<DatabaseModelBean> unAvailableDatabase = getUnAvailableDatabase();
if (unAvailableDatabase.isEmpty()) {
return;
}
for (DatabaseModelBean dmb : unAvailableDatabase) {
dmb.setDefault(false);
}
List<DatabaseModelBean> availableDatabase = getAvailableDatabase();
if (!availableDatabase.isEmpty()) {
availableDatabase.get(0).setDefault(true);
}
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class ProjectSettingTMPage method checkDbIsExist.
/**
* 检查当前库是否已经存在
* @param b
* @return ;
*/
public boolean checkDbIsExist(List<DatabaseModelBean> curDbList, DatabaseModelBean b) {
for (int i = 0; i < curDbList.size(); i++) {
DatabaseModelBean a = curDbList.get(i);
String dbname = a.getDbName();
String host = a.getHost();
String port = a.getPort();
String instance = a.getInstance();
if (b.getDbName().equals(dbname) && b.getHost().equals(host) && b.getPort().equals(port) && b.getInstance().equals(instance)) {
return true;
}
}
return false;
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class NewProjectTmPage 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.NewProjectTmPage.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("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("newproject.NewProjectTmPage.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>(1);
dbList.add(dbModel);
addToCurrDbList(dbList);
}
}
});
Button removeBtn = new Button(composite, SWT.NONE);
removeBtn.setText(Messages.getString("newproject.NewProjectTmPage.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.NewProjectTmPage.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, "M");
tableViewer.refresh();
}
} else {
MessageDialog.openInformation(getShell(), Messages.getString("newproject.NewProjectTmPage.msgTitle"), Messages.getString("newproject.NewProjectTmPage.msg3"));
}
}
});
addBtn.setFocus();
setControl(container);
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class NewProjectTmPage method createColumn.
/**
* 创建Table列
* @param viewer
* ;
*/
private void createColumn(final TableViewer viewer) {
String[] clmnTitles = { Messages.getString("newproject.NewProjectTmPage.clmnTitles1"), Messages.getString("newproject.NewProjectTmPage.clmnTitles2"), Messages.getString("newproject.NewProjectTmPage.clmnTitles3"), Messages.getString("newproject.NewProjectTmPage.clmnTitles4"), Messages.getString("newproject.NewProjectTmPage.clmnTitles5") };
int[] clmnBounds = { 100, 100, 200, 90, 70 };
TableViewerColumn col = createTableViewerColumn(viewer, clmnTitles[0], clmnBounds[0], 0);
col.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
DatabaseModelBean dbModel = (DatabaseModelBean) element;
return dbModel.getDbName();
}
});
col = createTableViewerColumn(viewer, clmnTitles[1], clmnBounds[1], 1);
col.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
DatabaseModelBean dbModel = (DatabaseModelBean) element;
if (dbModel.getDbType().equals(Constants.DBTYPE_SQLITE)) {
return Messages.getString("tm.dbtype.sqlite");
}
return dbModel.getDbType();
}
});
col = createTableViewerColumn(viewer, clmnTitles[2], clmnBounds[2], 2);
col.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
DatabaseModelBean dbModel = (DatabaseModelBean) element;
if (dbModel.getDbType().equals(Constants.DBTYPE_INTERNALDB) || dbModel.getDbType().equals(Constants.DBTYPE_SQLITE)) {
return dbModel.getItlDBLocation();
}
return dbModel.getHost();
}
});
col = createTableViewerColumn(viewer, clmnTitles[3], clmnBounds[3], 3);
col.setLabelProvider(new ColumnLabelProvider() {
public String getText(Object element) {
DatabaseModelBean dbModel = (DatabaseModelBean) element;
if (dbModel.isHasMatch()) {
return Messages.getString("newproject.NewProjectTmPage.yes");
} else {
return Messages.getString("newproject.NewProjectTmPage.no");
}
}
});
col = createTableViewerColumn(viewer, clmnTitles[4], clmnBounds[4], 4);
col.setLabelProvider(new ColumnLabelProvider() {
public Image getImage(Object element) {
DatabaseModelBean dbModel = (DatabaseModelBean) element;
if (dbModel.isDefault()) {
return checkedImage;
} else {
return uncheckedImage;
}
}
public String getText(Object element) {
return null;
}
});
col.setEditingSupport(new ReadableEditingSupport(viewer));
}
use of net.heartsome.cat.common.bean.DatabaseModelBean in project translationstudio8 by heartsome.
the class NewProjectTmPage 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