Search in sources :

Example 56 with DatabaseModelBean

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);
    }
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean)

Example 57 with DatabaseModelBean

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;
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Point(org.eclipse.swt.graphics.Point)

Example 58 with DatabaseModelBean

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);
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ImportTmxWizard(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Table(org.eclipse.swt.widgets.Table) TmDbManagerDialog(net.heartsome.cat.database.ui.tm.dialog.TmDbManagerDialog) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) SQLException(java.sql.SQLException) NewTmDbWizard(net.heartsome.cat.database.ui.tm.wizard.NewTmDbWizard) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ImportTmxWizardDialog(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizardDialog) TableViewer(org.eclipse.jface.viewers.TableViewer) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) Map(java.util.Map)

Example 59 with DatabaseModelBean

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));
}
Also used : ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Image(org.eclipse.swt.graphics.Image) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 60 with DatabaseModelBean

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;
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean)

Aggregations

DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)71 ArrayList (java.util.ArrayList)27 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)16 SQLException (java.sql.SQLException)15 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 MenuItem (org.eclipse.swt.widgets.MenuItem)12 List (java.util.List)11 Point (org.eclipse.swt.graphics.Point)11 File (java.io.File)10 GridData (org.eclipse.swt.layout.GridData)10 GridLayout (org.eclipse.swt.layout.GridLayout)10 Button (org.eclipse.swt.widgets.Button)10 Composite (org.eclipse.swt.widgets.Composite)10 Label (org.eclipse.swt.widgets.Label)10 Menu (org.eclipse.swt.widgets.Menu)10 Iterator (java.util.Iterator)8 Map (java.util.Map)8 MetaData (net.heartsome.cat.common.bean.MetaData)8 HSDropDownButton (net.heartsome.cat.common.ui.HSDropDownButton)8