Search in sources :

Example 1 with ShardIdSelectionDialog

use of com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog in project cubrid-manager by CUBRID.

the class ConnectionComposite method createBrokerInfoGroup.

private void createBrokerInfoGroup(Composite composite) {
    Group brokerInfoGroup = new Group(composite, SWT.NONE);
    brokerInfoGroup.setText(Messages.grpBrokerInfo);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    brokerInfoGroup.setLayoutData(gridData);
    brokerInfoGroup.setLayout(createGridLayout(3));
    Label brokerIpLabel = new Label(brokerInfoGroup, SWT.LEFT);
    brokerIpLabel.setText(Messages.lblLoginServerName);
    brokerIpLabel.setLayoutData(createGridData(1, 1, -1, -1));
    brokerIpText = new Text(brokerInfoGroup, SWT.LEFT | SWT.BORDER);
    brokerIpText.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 2, 1, 100, -1));
    brokerIpText.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent event) {
            brokerIpText.selectAll();
        }
    });
    Label brokerPortLabel = new Label(brokerInfoGroup, SWT.LEFT);
    brokerPortLabel.setText(Messages.lblLoginBrokerPort);
    brokerPortLabel.setLayoutData(createGridData(1, 1, -1, -1));
    VerifyListener verifyListener = new VerifyListener() {

        public void verifyText(VerifyEvent event) {
            Pattern pattern = Pattern.compile("[0-9]*");
            Matcher matcher = pattern.matcher(event.text);
            if (matcher.matches()) {
                event.doit = true;
            } else if (event.text.length() > 0) {
                event.doit = false;
            } else {
                event.doit = true;
            }
        }
    };
    Composite portAndShardComp = new Composite(brokerInfoGroup, SWT.NONE);
    portAndShardComp.setLayout(createGridLayout(3, 0, 0));
    portAndShardComp.setLayoutData(createGridData(FILL_HORIZONTAL, 2, 1, -1, -1));
    if (isMultiBroker) {
        brokerPortCombo = new Combo(portAndShardComp, SWT.LEFT | SWT.BORDER);
        brokerPortCombo.setLayoutData(createGridData(GridData.BEGINNING, 1, 1, 100, -1));
        brokerPortCombo.addVerifyListener(verifyListener);
    } else {
        brokerPortText = new Text(portAndShardComp, SWT.LEFT | SWT.BORDER);
        brokerPortText.setLayoutData(createGridData(BEGINNING, 1, 1, 100, -1));
        brokerPortText.addVerifyListener(verifyListener);
    }
    btnShard = new Button(portAndShardComp, SWT.CHECK);
    btnShard.setLayoutData(createGridData(BEGINNING, 1, 1, -1, -1));
    btnShard.setText(com.cubrid.common.ui.query.Messages.shardBrokerLabel);
    btnShard.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            if (btnShard.getSelection()) {
                openWarningBox(shardBrokerAlert);
            }
            btnShardId.setEnabled(btnShard.getSelection());
        }
    });
    btnShardId = new Button(portAndShardComp, SWT.PUSH);
    btnShardId.setLayoutData(createGridData(HORIZONTAL_ALIGN_END, 1, 1, -1, -1));
    btnShardId.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
            dialog.setDatabaseInfo(dbInfo);
            dialog.setShardId(curShardId);
            dialog.setShardVal(curShardVal);
            dialog.setShardQueryType(shardQueryType);
            if (dialog.open() == OK_ID) {
                curShardId = dialog.getShardId();
                curShardVal = dialog.getShardVal();
                shardQueryType = dialog.getShardQueryType();
                if (dbInfo != null) {
                    dbInfo.setCurrentShardId(curShardId);
                    dbInfo.setCurrentShardVal(curShardVal);
                    dbInfo.setShardQueryType(shardQueryType);
                }
                updateShardIdButtonText();
            }
        }
    });
    updateShardIdButtonText();
    Label charsetLabel = new Label(brokerInfoGroup, SWT.LEFT);
    charsetLabel.setText(com.cubrid.common.ui.query.Messages.lblCharSet);
    charsetLabel.setLayoutData(createGridData(1, 1, -1, -1));
    charsetCombo = new Combo(brokerInfoGroup, SWT.LEFT | SWT.BORDER);
    charsetCombo.setLayoutData(createGridData(FILL_HORIZONTAL, 2, 1, 100, -1));
    Label jdbcLabel = new Label(brokerInfoGroup, SWT.LEFT);
    jdbcLabel.setText(Messages.lblDbJdbcVersion);
    jdbcLabel.setLayoutData(createGridData(1, 1, -1, -1));
    jdbcCombo = new Combo(brokerInfoGroup, SWT.LEFT | SWT.READ_ONLY | SWT.BORDER);
    jdbcCombo.setLayoutData(createGridData(FILL_HORIZONTAL, 1, 1, 100, -1));
    Button btnOpen = new Button(brokerInfoGroup, SWT.NONE);
    btnOpen.setText(Messages.btnBrowse);
    btnOpen.setLayoutData(createGridData(1, 1, 80, -1));
    btnOpen.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            JdbcManageDialog dialog = new JdbcManageDialog(getShell());
            if (dialog.open() == OK_ID) {
                String jdbcVersion = dialog.getSelectedJdbcVersion();
                if (isBlank(jdbcVersion)) {
                    jdbcVersion = jdbcCombo.getText();
                }
                resetJdbcCombo(jdbcVersion);
            }
        }
    });
    // JDBC attributes
    Label attrLabel = new Label(brokerInfoGroup, SWT.LEFT);
    attrLabel.setText(Messages.lblJdbcAttr);
    attrLabel.setLayoutData(createGridData(1, 1, -1, -1));
    attrText = new Text(brokerInfoGroup, SWT.LEFT | SWT.BORDER);
    attrText.setEditable(false);
    attrText.setLayoutData(createGridData(FILL_HORIZONTAL, 1, 1, 100, -1));
    Button btnAttr = new Button(brokerInfoGroup, SWT.NONE);
    btnAttr.setText(Messages.btnJdbcAttr);
    btnAttr.setLayoutData(createGridData(1, 1, 80, -1));
    btnAttr.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            JdbcOptionDialog dialog = new JdbcOptionDialog(getShell(), attrText.getText());
            if (dialog.open() == OK_ID) {
                attrText.setText(dialog.getJdbcOptions());
            }
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Pattern(java.util.regex.Pattern) JdbcOptionDialog(com.cubrid.common.ui.common.dialog.JdbcOptionDialog) VerifyListener(org.eclipse.swt.events.VerifyListener) Composite(org.eclipse.swt.widgets.Composite) Matcher(java.util.regex.Matcher) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Messages.shardValLabel(com.cubrid.common.ui.query.Messages.shardValLabel) Messages.autoCommitLabel(com.cubrid.common.ui.query.Messages.autoCommitLabel) Label(org.eclipse.swt.widgets.Label) Messages.shardIdLabel(com.cubrid.common.ui.query.Messages.shardIdLabel) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) FocusEvent(org.eclipse.swt.events.FocusEvent) Button(org.eclipse.swt.widgets.Button) CommonUITool.createGridData(com.cubrid.common.ui.spi.util.CommonUITool.createGridData) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) JdbcManageDialog(com.cubrid.common.ui.common.dialog.JdbcManageDialog) VerifyEvent(org.eclipse.swt.events.VerifyEvent)

Example 2 with ShardIdSelectionDialog

use of com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog in project cubrid-manager by CUBRID.

the class CopyQueryEditorAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    IEditorPart editor = window.getActivePage().getActiveEditor();
    if (editor instanceof QueryEditorPart) {
        QueryUnit queryUnit = new QueryUnit();
        QueryEditorPart qep = (QueryEditorPart) editor;
        CubridDatabase database = qep.getSelectedDatabase();
        if (database != null) {
            queryUnit.setDatabase(database);
        }
        // [TOOLS-2425]Support shard broker
        if (database != null) {
            DatabaseInfo dbInfo = database.getDatabaseInfo();
            if (dbInfo != null && dbInfo.isShard()) {
                ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(Display.getDefault().getActiveShell());
                dialog.setDatabaseInfo(dbInfo);
                dialog.setShardId(0);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    dbInfo.setCurrentShardId(dialog.getShardId());
                }
            }
        }
        try {
            IEditorPart newEditor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
            if (newEditor != null && database != null) {
                ((QueryEditorPart) newEditor).connect(database);
            }
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 3 with ShardIdSelectionDialog

use of com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog in project cubrid-manager by CUBRID.

the class DatabaseQueryNewAction method run.

/**
	 * @see org.eclipse.jface.action.Action#run()
	 */
public void run() {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null) {
        return;
    }
    Object[] obj = this.getSelectedObj();
    CubridDatabase[] cubridDatabases = handleSelectionObj(obj);
    if (cubridDatabases.length == 0) {
        return;
    }
    /*Limit max number one time*/
    if (cubridDatabases.length > LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM) {
        CommonUITool.openConfirmBox(Messages.bind(Messages.msgMaxOpenNum, LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM));
        List<CubridDatabase> list = new ArrayList<CubridDatabase>(LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM);
        for (int i = 0; i < LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM; i++) {
            list.add(cubridDatabases[i]);
        }
        cubridDatabases = new CubridDatabase[LayoutUtil.MAX_OPEN_QUERY_EDITOR_NUM];
        list.toArray(cubridDatabases);
    }
    // [TOOLS-2425]Support shard broker
    // it is used in order to check first shard database when you open several editor of databases.
    int count = cubridDatabases.length;
    for (CubridDatabase database : cubridDatabases) {
        QueryUnit queryUnit = new QueryUnit();
        queryUnit.setDatabase(database);
        // [TOOLS-2425]Support shard broker
        DatabaseInfo dbInfo = database.getDatabaseInfo();
        if (dbInfo == null) {
            continue;
        }
        int shardId = 0;
        int shardVal = 0;
        int shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_VAL;
        if (count == 1) {
            // [TOOLS-2425]Support shard broker
            if (dbInfo != null && dbInfo.isShard()) {
                ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
                dialog.setDatabaseInfo(dbInfo);
                dialog.setShardId(shardId);
                dialog.setShardVal(shardVal);
                dialog.setShardQueryType(shardQueryType);
                if (dialog.open() == IDialogConstants.OK_ID) {
                    shardId = dialog.getShardId();
                    shardVal = dialog.getShardVal();
                    shardQueryType = dialog.getShardQueryType();
                }
            }
        }
        try {
            IEditorPart editor = window.getActivePage().openEditor(queryUnit, QueryEditorPart.ID);
            if (editor != null && database != null) {
                QueryEditorPart editorPart = (QueryEditorPart) editor;
                editorPart.connect(database);
                // [TOOLS-2425]Support shard broker
                if (dbInfo.isShard()) {
                    editorPart.setShardId(shardId);
                    editorPart.setShardVal(shardVal);
                    editorPart.setShardQueryType(shardQueryType);
                    editorPart.changeQueryEditorPartNameWithShard();
                }
            }
        } catch (PartInitException e) {
            LOGGER.error(e.getMessage());
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ArrayList(java.util.ArrayList) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) PartInitException(org.eclipse.ui.PartInitException) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 4 with ShardIdSelectionDialog

use of com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog in project cubrid-manager by CUBRID.

the class QueryNewAction method openQueryEditor.

/**
	 * Open new query editor.
	 *
	 * @param database of query editor.
	 * @throws PartInitException when open editor error.
	 */
private void openQueryEditor(CubridDatabase database) throws PartInitException {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    if (database == null) {
        window.getActivePage().openEditor(new QueryUnit(), QueryEditorPart.ID);
        return;
    }
    CubridDatabase cdb = database;
    if (database == null || !database.isLogined()) {
        LoginQueryEditorDialog dialog = new LoginQueryEditorDialog(getShell());
        dialog.setSelectedConnName(getInitConnectionName(database));
        if (dialog.open() != IDialogConstants.OK_ID) {
            return;
        }
        cdb = DatabaseNavigatorMenu.SELF_DATABASE;
    }
    // [TOOLS-2425]Support shard broker
    boolean isShrd = false;
    int shardId = 0;
    int shardVal = 0;
    int shardQueryType = DatabaseInfo.SHARD_QUERY_TYPE_ID;
    if (cdb != null) {
        DatabaseInfo dbInfo = cdb.getDatabaseInfo();
        if (dbInfo != null && dbInfo.isShard()) {
            isShrd = true;
            ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
            dialog.setDatabaseInfo(dbInfo);
            dialog.setShardId(0);
            dialog.setShardVal(0);
            dialog.setShardQueryType(shardQueryType);
            if (dialog.open() == IDialogConstants.OK_ID) {
                shardId = dialog.getShardId();
                shardVal = dialog.getShardVal();
                shardQueryType = dialog.getShardQueryType();
            }
        }
    }
    QueryUnit input = new QueryUnit();
    input.setDatabase(cdb);
    IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
    if (editor != null) {
        QueryEditorPart editorPart = (QueryEditorPart) editor;
        editorPart.connect(cdb);
        // [TOOLS-2425]Support shard broker
        if (isShrd) {
            editorPart.setShardId(shardId);
            editorPart.setShardVal(shardVal);
            editorPart.setShardQueryType(shardQueryType);
            editorPart.changeQueryEditorPartNameWithShard();
        }
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) LoginQueryEditorDialog(com.cubrid.cubridquery.ui.common.dialog.LoginQueryEditorDialog) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Example 5 with ShardIdSelectionDialog

use of com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog in project cubrid-manager by CUBRID.

the class QueryNewCustomAction method openQueryEditor.

/**
	 * Open new query editor.
	 * 
	 * @param database of query editor.
	 * @throws PartInitException when open editor error.
	 */
private void openQueryEditor(CubridDatabase database) throws PartInitException {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null || window.getActivePage() == null) {
        return;
    }
    CubridDatabase cdb = DatabaseNavigatorMenu.NULL_DATABASE;
    LoginQueryEditorDialog loginDialog = new LoginQueryEditorDialog(getShell());
    loginDialog.setSelectedConnName(getInitConnectionName(database));
    if (loginDialog.open() == IDialogConstants.OK_ID) {
        cdb = DatabaseNavigatorMenu.SELF_DATABASE;
    } else {
        return;
    }
    // [TOOLS-2425]Support shard broker
    if (cdb != null) {
        DatabaseInfo dbInfo = cdb.getDatabaseInfo();
        if (dbInfo != null && dbInfo.isShard()) {
            ShardIdSelectionDialog dialog = new ShardIdSelectionDialog(getShell());
            dialog.setDatabaseInfo(dbInfo);
            dialog.setShardId(0);
            dialog.setShardVal(0);
            dialog.setShardQueryType(dbInfo.getShardQueryType());
            if (dialog.open() == IDialogConstants.OK_ID) {
                dbInfo.setCurrentShardId(dialog.getShardId());
            }
        }
    }
    QueryUnit input = new QueryUnit();
    input.setDatabase(cdb);
    IEditorPart editor = window.getActivePage().openEditor(input, QueryEditorPart.ID);
    if (editor != null) {
        ((QueryEditorPart) editor).connect(cdb);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) QueryEditorPart(com.cubrid.common.ui.query.editor.QueryEditorPart) QueryUnit(com.cubrid.common.ui.query.editor.QueryUnit) LoginQueryEditorDialog(com.cubrid.cubridquery.ui.common.dialog.LoginQueryEditorDialog) DatabaseInfo(com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo) ShardIdSelectionDialog(com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog) IEditorPart(org.eclipse.ui.IEditorPart) CubridDatabase(com.cubrid.common.ui.spi.model.CubridDatabase)

Aggregations

ShardIdSelectionDialog (com.cubrid.common.ui.common.dialog.ShardIdSelectionDialog)7 DatabaseInfo (com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo)6 CubridDatabase (com.cubrid.common.ui.spi.model.CubridDatabase)5 QueryEditorPart (com.cubrid.common.ui.query.editor.QueryEditorPart)4 QueryUnit (com.cubrid.common.ui.query.editor.QueryUnit)4 IEditorPart (org.eclipse.ui.IEditorPart)4 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)4 PartInitException (org.eclipse.ui.PartInitException)3 LoginQueryEditorDialog (com.cubrid.cubridquery.ui.common.dialog.LoginQueryEditorDialog)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 JdbcManageDialog (com.cubrid.common.ui.common.dialog.JdbcManageDialog)1 JdbcOptionDialog (com.cubrid.common.ui.common.dialog.JdbcOptionDialog)1 PstmtSQLDialog (com.cubrid.common.ui.cubrid.table.dialog.PstmtSQLDialog)1 Messages.autoCommitLabel (com.cubrid.common.ui.query.Messages.autoCommitLabel)1 Messages.shardIdLabel (com.cubrid.common.ui.query.Messages.shardIdLabel)1 Messages.shardValLabel (com.cubrid.common.ui.query.Messages.shardValLabel)1 EditorToolBar (com.cubrid.common.ui.query.control.EditorToolBar)1 CubridNodeChangedEvent (com.cubrid.common.ui.spi.event.CubridNodeChangedEvent)1 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1