Search in sources :

Example 6 with SystemDBOperator

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

the class DatabaseService method getSystemSuportDbMetaData.

/**
	 * 获取系统支持数据库的元数据
	 * @return ;
	 */
public static Map<String, MetaData> getSystemSuportDbMetaData() {
    Map<String, MetaData> map = new HashMap<String, MetaData>();
    List<SystemDBOperator> sysDbOp = getSystemDbOperaterList();
    for (int i = 0; i < sysDbOp.size(); i++) {
        SystemDBOperator dbOp = sysDbOp.get(i);
        map.put(dbOp.getMetaData().getDbType(), dbOp.getMetaData());
    }
    return map;
}
Also used : SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) HashMap(java.util.HashMap) MetaData(net.heartsome.cat.common.bean.MetaData)

Example 7 with SystemDBOperator

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

the class DatabaseService method getSysDbOperateByMetaData.

/**
	 * 通过数据库元数据库获取数据库连接,主要取数据库类型
	 * @param metaData
	 * @return ;
	 */
public static SystemDBOperator getSysDbOperateByMetaData(MetaData metaData) {
    @SuppressWarnings({ "rawtypes", "unchecked" }) ServiceTracker tracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
    tracker.open();
    try {
        Object[] services = tracker.getServices();
        for (Object i : services) {
            DBServiceProvider serviceProvider = (DBServiceProvider) i;
            SystemDBOperator temp = serviceProvider.getOperateDBInstance();
            if (temp == null) {
                continue;
            }
            MetaData tempMetaData = temp.getMetaData();
            if (tempMetaData.getDbType().equals(metaData.getDbType())) {
                tempMetaData.setDatabaseName(metaData.getDatabaseName());
                tempMetaData.setDataPath(metaData.getDataPath());
                tempMetaData.setInstance(metaData.getInstance());
                tempMetaData.setPassword(metaData.getPassword());
                tempMetaData.setPort(metaData.getPort());
                tempMetaData.setServerName(metaData.getServerName());
                tempMetaData.setTB(metaData.isTB());
                tempMetaData.setTM(metaData.isTM());
                tempMetaData.setUserName(metaData.getUserName());
                return temp;
            }
        }
    } finally {
        tracker.close();
    }
    return null;
}
Also used : DBServiceProvider(net.heartsome.cat.database.DBServiceProvider) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) ServiceTracker(org.osgi.util.tracker.ServiceTracker) MetaData(net.heartsome.cat.common.bean.MetaData)

Example 8 with SystemDBOperator

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

the class DatabaseService method getSystemDbOperaterList.

/**
	 * 根据当前系统支持的数据库类型,获取所有的库处理对象,<br>
	 * 该库处理对象是对服务器中的数据库进行管理,包括创建,删除等一系列操作.参见{@link SystemDBOperator} *
	 * @return 返回当前系统所支持的库处理对象集;
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static List<SystemDBOperator> getSystemDbOperaterList() {
    List<SystemDBOperator> list = new ArrayList<SystemDBOperator>();
    ServiceTracker operateDbTracker = new ServiceTracker(Activator.context, DBServiceProvider.class.getName(), null);
    operateDbTracker.open();
    try {
        Object[] services = operateDbTracker.getServices();
        for (Object i : services) {
            DBServiceProvider temp = (DBServiceProvider) i;
            list.add(temp.getOperateDBInstance());
        }
    } finally {
        operateDbTracker.close();
    }
    if (list.size() == 0) {
        return list;
    }
    int size = list.size();
    SystemDBOperator[] temp = new SystemDBOperator[size];
    for (SystemDBOperator op : list) {
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_INTERNALDB)) {
            temp[size - 1] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_MYSQL)) {
            temp[size - 5] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_MSSQL2005)) {
            temp[size - 4] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_POSTGRESQL)) {
            temp[size - 2] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_Oracle)) {
            temp[size - 3] = op;
        }
        if (op.getDBConfig().getDefaultType().equals(Constants.DBTYPE_SQLITE)) {
            temp[0] = op;
        }
    }
    return Arrays.asList(temp);
}
Also used : SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) DBServiceProvider(net.heartsome.cat.database.DBServiceProvider) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ArrayList(java.util.ArrayList)

Example 9 with SystemDBOperator

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

the class TmDbManagerDialog 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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.msgTitle"), status.getMessage());
                        return;
                    }
                    SystemDBOperator sysDbOp = getCurrSysDbOp();
                    if (sysDbOp == null) {
                        return;
                    }
                    // 连接检查
                    if (!sysDbOp.checkDbConnection()) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.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.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.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.TmDbManagerDialog.logger1"), e1);
                                MessageDialog.openError(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg3") + e1.getMessage());
                                break;
                            }
                            currServerdbListInput.remove(needDeletes.get(i));
                        }
                    }
                }
            });
        }
    });
    Button importBtn = new Button(composite, SWT.NONE);
    importBtn.setText(Messages.getString("dialog.TmDbManagerDialog.importBtn"));
    importBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ISelection selection = getDbTableViewer().getSelection();
            if (selection.isEmpty()) {
                MessageDialog.openError(getShell(), Messages.getString("dialog.TmDbManagerDialog.msgTitle"), Messages.getString("dialog.TmDbManagerDialog.msg4"));
                return;
            }
            IStructuredSelection stcSel = (IStructuredSelection) selection;
            DatabaseManagerDbListBean dbBean = (DatabaseManagerDbListBean) stcSel.getFirstElement();
            DatabaseModelBean dbModelBean = new DatabaseModelBean();
            currServer.copyToOtherIntance(dbModelBean);
            dbModelBean.setDbName(dbBean.getDbName());
            ImportTmxWizard wizard = new ImportTmxWizard(dbModelBean);
            ImportTmxWizardDialog dlg = new ImportTmxWizardDialog(getShell(), wizard) {

                // robert help 2012-09-06
                @Override
                protected Control createHelpControl(Composite parent) {
                    // ROBERTHELP 记忆库管理-导入TMX
                    String language = CommonFunction.getSystemLanguage();
                    final String helpUrl = MessageFormat.format("/net.heartsome.cat.ts.ui.help/html/{0}/ch05s03.html#create-tm-wizard-import-tmx", language);
                    Image helpImage = JFaceResources.getImage(DLG_IMG_HELP);
                    ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
                    ((GridLayout) parent.getLayout()).numColumns++;
                    toolBar.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
                    final Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
                    toolBar.setCursor(cursor);
                    toolBar.addDisposeListener(new DisposeListener() {

                        public void widgetDisposed(DisposeEvent e) {
                            cursor.dispose();
                        }
                    });
                    ToolItem helpItem = new ToolItem(toolBar, SWT.NONE);
                    helpItem.setImage(helpImage);
                    //$NON-NLS-1$
                    helpItem.setToolTipText(JFaceResources.getString("helpToolTip"));
                    helpItem.addSelectionListener(new SelectionAdapter() {

                        public void widgetSelected(SelectionEvent e) {
                            PlatformUI.getWorkbench().getHelpSystem().displayHelpResource(helpUrl);
                        }
                    });
                    return toolBar;
                }
            };
            dlg.setHelpAvailable(true);
            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) DisposeListener(org.eclipse.swt.events.DisposeListener) IStatus(org.eclipse.core.runtime.IStatus) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) ImportTmxWizard(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Image(org.eclipse.swt.graphics.Image) Cursor(org.eclipse.swt.graphics.Cursor) DisposeEvent(org.eclipse.swt.events.DisposeEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) 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) ToolItem(org.eclipse.swt.widgets.ToolItem) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) 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) ToolBar(org.eclipse.swt.widgets.ToolBar) ImportTmxWizardDialog(net.heartsome.cat.database.ui.tm.wizard.ImportTmxWizardDialog) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 10 with SystemDBOperator

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

the class NewTermDbBaseInfoPage 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.NewTermDbBaseInfoPage.dbGroup1"));
    Label label = new Label(dbGroup1, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTermDbBaseInfoPage.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.NewTermDbBaseInfoPage.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.NewTermDbBaseInfoPage.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("tb.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.NewTermDbBaseInfoPage.dbGroup"));
    label = new Label(dbGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTermDbBaseInfoPage.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.NewTermDbBaseInfoPage.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.NewTermDbBaseInfoPage.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.NewTermDbBaseInfoPage.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.NewTermDbBaseInfoPage.authorityGroup"));
    label = new Label(authorityGroup, SWT.RIGHT);
    label.setLayoutData(gdLabel);
    label.setText(Messages.getString("wizard.NewTermDbBaseInfoPage.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.NewTermDbBaseInfoPage.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