Search in sources :

Example 11 with SystemDBOperator

use of net.heartsome.cat.database.SystemDBOperator in project translationstudio8 by heartsome.

the class NewTermDbWizard method performFinish.

/**
	 * (non-Javadoc)
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
@Override
public boolean performFinish() {
    final String tbxFile = importPage.getTBXFile();
    final SystemDBOperator dbOp = createDbPage.getCurrDbOp();
    if (dbOp.getDBConfig().getDefaultType().equals(Constants.DBTYPE_SQLITE)) {
        String dbName = dbOp.getMetaData().getDatabaseName();
        dbName += ".hstb";
        dbOp.getMetaData().setDatabaseName(dbName);
    }
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            importPage.performFinish(tbxFile, dbOp, monitor);
        }
    };
    try {
        getContainer().run(true, true, runnable);
    } catch (InvocationTargetException e) {
        e.printStackTrace();
        return false;
    } catch (InterruptedException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 12 with SystemDBOperator

use of net.heartsome.cat.database.SystemDBOperator in project translationstudio8 by heartsome.

the class TermDbManagerDialog method createPageContainer.

/**
	 * 创建右侧页面内容
	 * @param parent
	 *            页面容器
	 * @return ;
	 */
protected Composite createPageContainer(Composite parent) {
    Composite outer = new Composite(parent, SWT.NONE);
    GridData outerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    outerData.horizontalIndent = IDialogConstants.HORIZONTAL_MARGIN;
    outer.setLayout(new GridLayout());
    outer.setLayoutData(outerData);
    // Create an outer composite for spacing
    ScrolledComposite scrolled = new ScrolledComposite(outer, SWT.V_SCROLL | SWT.H_SCROLL);
    // always show the focus control
    scrolled.setShowFocusedControl(true);
    scrolled.setExpandHorizontal(true);
    scrolled.setExpandVertical(true);
    scrolled.setLayoutData(new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL));
    GridLayout gld = new GridLayout(1, false);
    gld.marginWidth = 0;
    gld.marginHeight = 0;
    scrolled.setLayout(gld);
    Composite result = new Composite(scrolled, SWT.NONE);
    GridData resultData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    result.setLayoutData(resultData);
    GridLayout gl_result = new GridLayout(1, false);
    gl_result.marginWidth = 0;
    gl_result.marginHeight = 0;
    result.setLayout(gl_result);
    Group parameterGroup = new Group(result, SWT.NONE);
    parameterGroup.setText(Messages.getString("dialog.TermDbManagerDialog.parameterGroup"));
    GridLayout parameterLayout = new GridLayout(4, false);
    parameterGroup.setLayout(parameterLayout);
    GridData parameterGridData = new GridData(GridData.FILL_HORIZONTAL);
    parameterGroup.setLayoutData(parameterGridData);
    Label label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblHost"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    hostText = new Text(parameterGroup, SWT.BORDER);
    hostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblPort"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    portText = new Text(parameterGroup, SWT.BORDER);
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblInstance"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    instanceText = new Text(parameterGroup, SWT.BORDER);
    instanceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    new Label(parameterGroup, SWT.NONE);
    new Label(parameterGroup, SWT.NONE);
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblLocation"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    locationText = new Text(parameterGroup, SWT.BORDER);
    locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    borwserBtn = new Button(parameterGroup, SWT.NONE);
    borwserBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 2, 1));
    borwserBtn.setText(Messages.getString("dialog.TermDbManagerDialog.borwserBtn"));
    borwserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            String path = dlg.open();
            if (path != null) {
                locationText.setText(path);
            }
        }
    });
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblUsername"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    usernameText = new Text(parameterGroup, SWT.BORDER);
    usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(parameterGroup, SWT.RIGHT);
    label.setText(Messages.getString("dialog.TermDbManagerDialog.lblPwd"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
    passwordText = new Text(parameterGroup, SWT.BORDER | SWT.PASSWORD);
    passwordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    Composite btnComposite = new Composite(parameterGroup, SWT.NONE);
    btnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1));
    GridLayout btnCompositeLayout = new GridLayout(1, false);
    btnCompositeLayout.marginHeight = 0;
    btnCompositeLayout.marginWidth = 0;
    btnComposite.setLayout(btnCompositeLayout);
    // remenmberBtn = new Button(btnComposite, SWT.CHECK|SWT.BORDER);
    // remenmberBtn.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    // remenmberBtn.setText("将本次连接信息添加到数据库类型的快捷连接方式(&R)");
    // remenmberBtn.setSelection(true);
    searchBtn = new Button(btnComposite, SWT.NONE);
    searchBtn.setText(Messages.getString("dialog.TermDbManagerDialog.searchBtn"));
    searchBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                public void run() {
                    // 输入合法性检查
                    IStatus status = validator();
                    if (status.getSeverity() != IStatus.OK) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), status.getMessage());
                        return;
                    }
                    SystemDBOperator sysDbOp = getCurrSysDbOp();
                    if (sysDbOp == null) {
                        return;
                    }
                    // 连接检查
                    if (!sysDbOp.checkDbConnection()) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), Messages.getString("dialog.TermDbManagerDialog.msg1"));
                        return;
                    }
                    // if (remenmberBtn.getSelection() == true) {
                    // 当前数据库类型下的所有服务器
                    List<DatabaseModelBean> currDbTypeServers = treeInputMap.get(getCurrDbType());
                    if (currServer.getId().equals("")) {
                        addServerWithExistCheck(currServer, currDbTypeServers);
                        getTreeViewer().refresh();
                        // 在树上选择当前操作的节点
                        selectSaveItem();
                    }
                    // ISelection selection = getTreeViewer().getSelection();
                    // if (selection.isEmpty()) {
                    // return;
                    // }
                    // } else { // 不记住信息
                    executeSearch(sysDbOp);
                // }
                }
            });
        }
    });
    Group tableComposite = new Group(result, SWT.NONE);
    tableComposite.setText(Messages.getString("dialog.TermDbManagerDialog.tableComposite"));
    tableComposite.setLayout(new GridLayout(1, false));
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    dbTableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    Table table = dbTableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    GridData tableGd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    tableGd.heightHint = 180;
    table.setLayoutData(tableGd);
    createColumn(dbTableViewer);
    if (getDialogUseFor() == TYPE_DBSELECTED) {
        dbTableViewer.addDoubleClickListener(new IDoubleClickListener() {

            public void doubleClick(DoubleClickEvent event) {
                okPressed();
            }
        });
    }
    dbTableViewer.setContentProvider(new ArrayContentProvider());
    currServerdbListInput = new WritableList(currServerdbList, DatabaseManagerDbListBean.class);
    dbTableViewer.setInput(currServerdbListInput);
    Composite composite = new Composite(tableComposite, SWT.NONE);
    GridLayout gl_composite = new GridLayout(3, false);
    gl_composite.marginHeight = 0;
    gl_composite.marginWidth = 0;
    composite.setLayout(gl_composite);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    Button btnc = new Button(composite, SWT.NONE);
    btnc.setText(Messages.getString("dialog.TermDbManagerDialog.btnc"));
    btnc.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            createNewDatabase();
        }
    });
    Button btnd_1 = new Button(composite, SWT.NONE);
    btnd_1.setText(Messages.getString("dialog.TermDbManagerDialog.btnd_1"));
    btnd_1.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                public void run() {
                    ISelection selection = getDbTableViewer().getSelection();
                    if (selection.isEmpty()) {
                        return;
                    }
                    if (MessageDialog.openConfirm(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), Messages.getString("dialog.TermDbManagerDialog.msg2"))) {
                        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                        @SuppressWarnings("unchecked") List<DatabaseManagerDbListBean> needDeletes = structuredSelection.toList();
                        SystemDBOperator dbop = getCurrSysDbOp();
                        for (int i = 0; i < needDeletes.size(); i++) {
                            try {
                                String dbName = needDeletes.get(i).getDbName();
                                dbop.dropDb(dbName);
                                dbop.removeSysDb(dbName);
                            } catch (Exception e1) {
                                logger.error(Messages.getString("dialog.TermDbManagerDialog.logger1"), e1);
                                MessageDialog.openError(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), Messages.getString("dialog.TermDbManagerDialog.msg3") + e1.getMessage());
                                break;
                            }
                            currServerdbListInput.remove(needDeletes.get(i));
                        }
                    }
                }
            });
        }
    });
    Button importBtn = new Button(composite, SWT.NONE);
    importBtn.setText(Messages.getString("dialog.TermDbManagerDialog.importBtn"));
    importBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = getDbTableViewer().getSelection();
            if (selection.isEmpty()) {
                MessageDialog.openInformation(getShell(), Messages.getString("dialog.TermDbManagerDialog.msgTitle"), Messages.getString("dialog.TermDbManagerDialog.msg4"));
                return;
            }
            IStructuredSelection stcSel = (IStructuredSelection) selection;
            DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) stcSel.getFirstElement();
            DatabaseModelBean dbModelBean = new DatabaseModelBean();
            currServer.copyToOtherIntance(dbModelBean);
            dbModelBean.setDbName(dbBean.getDbName());
            TbxImportWizard wizard = new TbxImportWizard(dbModelBean);
            TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(getShell(), wizard);
            if (dlg.open() == 0) {
                // 重新加载内容
                executeSearch(getCurrSysDbOp());
            }
        }
    });
    Point searchPoint = searchBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point createPoint = btnc.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point remPoint = btnd_1.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point importPoint = importBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(searchPoint.x, createPoint.x)));
    GridData btnData = new GridData();
    btnData.widthHint = width + 10;
    btnc.setLayoutData(btnData);
    btnd_1.setLayoutData(btnData);
    importBtn.setLayoutData(btnData);
    searchBtn.getLayoutData();
    GridData searchData = new GridData(SWT.RIGHT, SWT.CENTER, true, true, 4, 1);
    searchData.widthHint = width + 10;
    searchBtn.setLayoutData(searchData);
    scrolled.setContent(result);
    scrolled.setMinSize(getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT));
    return result;
}
Also used : Group(org.eclipse.swt.widgets.Group) IStatus(org.eclipse.core.runtime.IStatus) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TbxImportWizard(net.heartsome.cat.database.ui.tb.wizard.TbxImportWizard) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) TermDbManagerImportWizardDialog(net.heartsome.cat.database.ui.tb.wizard.TermDbManagerImportWizardDialog) DatabaseManagerDbListBean(net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) WritableList(org.eclipse.core.databinding.observable.list.WritableList) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 13 with SystemDBOperator

use of net.heartsome.cat.database.SystemDBOperator in project translationstudio8 by heartsome.

the class TermDbManagerDialog method searchCurrServerDatabase.

private List<DatabaseManagerDbListBean> searchCurrServerDatabase(SystemDBOperator sysDbOp, DatabaseModelBean currServer) {
    List<DatabaseManagerDbListBean> temp = new ArrayList<DatabaseManagerDbListBean>();
    // 检查是否创建了系统库
    if (!sysDbOp.checkSysDb()) {
        // MessageDialog.openInformation(getShell(), "提示信息",
        // "当前服务器上没有创建任何库");
        setLastSelectedServer(null);
        return null;
    }
    // 检查是否创建了库
    List<String> dbNames = sysDbOp.getSysDbNames(Constants.DB_TYPE_TB);
    if (dbNames.size() == 0) {
        // MessageDialog.openInformation(getShell(), "提示信息",
        // "当前服务器上没有创建任何库");
        setLastSelectedServer(null);
        return null;
    }
    // 获取数据库相关资料,封装了库名称和语言
    MetaData metaData = currServer.toDbMetaData();
    DBOperator dbop = DatabaseService.getDBOperator(metaData);
    for (int i = 0; i < dbNames.size(); i++) {
        DatabaseManagerDbListBean bean = new DatabaseManagerDbListBean();
        String dbName = dbNames.get(i);
        bean.setIndex(i + 1 + "");
        bean.setDbName(dbName);
        metaData.setDatabaseName(dbName);
        dbop.setMetaData(metaData);
        String lang = "";
        try {
            dbop.start();
            List<String> langs = dbop.getLanguages();
            for (int j = 0; j < langs.size(); j++) {
                lang += langs.get(j);
                if (j != langs.size() - 1) {
                    lang += ", ";
                }
            }
        } catch (Exception e1) {
            logger.error("", e1);
            continue;
        } finally {
            try {
                if (dbop != null) {
                    dbop.end();
                }
            } catch (SQLException e) {
                logger.error("", e);
            }
        }
        if (lang.equals("")) {
            bean.setLangs(Messages.getString("dialog.TermDbManagerDialog.msg10"));
        } else {
            bean.setLangs(lang);
        }
        temp.add(bean);
    }
    return temp;
}
Also used : SQLException(java.sql.SQLException) DatabaseManagerDbListBean(net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean) MetaData(net.heartsome.cat.common.bean.MetaData) ArrayList(java.util.ArrayList) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) DBOperator(net.heartsome.cat.database.DBOperator) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException)

Example 14 with SystemDBOperator

use of net.heartsome.cat.database.SystemDBOperator in project translationstudio8 by heartsome.

the class TermDbManagerDialog 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);
            }
        }
    });
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) MenuDetectEvent(org.eclipse.swt.events.MenuDetectEvent) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree) MenuDetectListener(org.eclipse.swt.events.MenuDetectListener)

Example 15 with SystemDBOperator

use of net.heartsome.cat.database.SystemDBOperator in project translationstudio8 by heartsome.

the class NewTmDbBaseInfoPage 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));
    setControl(container);
    int labelWidth = 100;
    GridData gdLabel = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gdLabel.widthHint = labelWidth;
    Group dbGroup1 = new Group(container, SWT.NONE);
    dbGroup1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
    dbGroup1.setLayout(new GridLayout(2, false));
    dbGroup1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
    dbGroup1.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.dbGroup1"));
    Label label = new Label(dbGroup1, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.lblType"));
    dbTypeComboViewer = new ComboViewer(dbGroup1, SWT.READ_ONLY);
    Combo combo = dbTypeComboViewer.getCombo();
    combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    // //
    label = new Label(dbGroup1, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.dbNameText"));
    dbNameText = new Text(dbGroup1, SWT.BORDER);
    dbNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(dbGroup1, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.instanceText"));
    instanceText = new Text(dbGroup1, SWT.BORDER);
    instanceText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    dbTypeComboViewer.setContentProvider(new ArrayContentProvider());
    dbTypeComboViewer.setInput(dbTypeList);
    dbTypeComboViewer.setLabelProvider(new LabelProvider() {

        public String getText(Object element) {
            SystemDBOperator dbOp = (SystemDBOperator) element;
            String dbType = dbOp.getDBConfig().getDefaultType();
            if (dbType.equals(Constants.DBTYPE_MYSQL)) {
                dbType = Constants.DBTYPE_MYSQL_FOR_UI;
            } else if (dbType.equals(Constants.DBTYPE_MSSQL2005)) {
                dbType = Constants.DBTYPE_MSSQL2005_FOR_UI;
            } else if (dbType.equals(Constants.DBTYPE_SQLITE)) {
                dbType = Messages.getString("tm.dbtype.sqlite");
            }
            return dbType;
        }
    });
    dbTypeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            ISelection selection = event.getSelection();
            if (selection != null && selection instanceof IStructuredSelection) {
                IStructuredSelection sel = (IStructuredSelection) selection;
                Object selObj = sel.getFirstElement();
                if (selObj != null && selObj instanceof SystemDBOperator) {
                    SystemDBOperator selDbOp = (SystemDBOperator) selObj;
                    dbTypeChangeEvent(selDbOp);
                }
            }
        }
    });
    Group dbGroup = new Group(container, SWT.NONE);
    dbGroup.setLayout(new GridLayout(5, false));
    dbGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
    dbGroup.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.dbGroup"));
    label = new Label(dbGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.hostText"));
    hostText = new Text(dbGroup, SWT.BORDER);
    hostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(dbGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.portText"));
    portText = new Text(dbGroup, SWT.BORDER);
    new Label(dbGroup, SWT.NONE);
    label = new Label(dbGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.locationText"));
    locationText = new Text(dbGroup, SWT.BORDER);
    locationText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    locationText.setEnabled(false);
    borwserBtn = new Button(dbGroup, SWT.NONE);
    borwserBtn.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.borwserBtn"));
    borwserBtn.setEnabled(false);
    borwserBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            DirectoryDialog dlg = new DirectoryDialog(getShell());
            String path = dlg.open();
            if (path != null) {
                locationText.setText(path);
            }
        }
    });
    Group authorityGroup = new Group(container, SWT.NONE);
    authorityGroup.setLayout(new GridLayout(2, false));
    authorityGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));
    authorityGroup.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.authorityGroup"));
    label = new Label(authorityGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.usernameText"));
    usernameText = new Text(authorityGroup, SWT.BORDER);
    usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    label = new Label(authorityGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTmDbBaseInfoPage.passwordText"));
    passwordText = new Text(authorityGroup, SWT.BORDER | SWT.PASSWORD);
    passwordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    initDataBindings();
    if (this.dbOp != null) {
        dbTypeComboViewer.setSelection(new StructuredSelection(this.dbOp));
    } else {
        dbTypeComboViewer.setSelection(new StructuredSelection(dbTypeList.get(0)));
    }
    IStatus state = validator();
    if (!state.isOK()) {
        setErrorMessage(state.getMessage());
        setPageComplete(false);
    }
}
Also used : Group(org.eclipse.swt.widgets.Group) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)17 IStatus (org.eclipse.core.runtime.IStatus)6 ISelection (org.eclipse.jface.viewers.ISelection)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6 SelectionEvent (org.eclipse.swt.events.SelectionEvent)6 SQLException (java.sql.SQLException)4 DatabaseModelBean (net.heartsome.cat.common.bean.DatabaseModelBean)4 MetaData (net.heartsome.cat.common.bean.MetaData)4 DatabaseManagerDbListBean (net.heartsome.cat.database.ui.bean.DatabaseManagerDbListBean)4 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)4 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)4 Point (org.eclipse.swt.graphics.Point)4 GridData (org.eclipse.swt.layout.GridData)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 Button (org.eclipse.swt.widgets.Button)4 Composite (org.eclipse.swt.widgets.Composite)4 DirectoryDialog (org.eclipse.swt.widgets.DirectoryDialog)4 Group (org.eclipse.swt.widgets.Group)4