Search in sources :

Example 1 with MongoDBReplicaFieldModel

use of org.talend.repository.nosql.db.model.mongodb.MongoDBReplicaFieldModel in project tbd-studio-se by Talend.

the class MongoDBConnForm method addConnectionGroup.

/**
 * DOC PLV Comment method "addConnectionGroup".
 */
private void addConnectionGroup(Composite composite) {
    // create group
    // $NON-NLS-1$
    connectionGroup = Form.createGroup(composite, 4, Messages.getString("MongoDBConnForm.connection"));
    connectionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    GridLayout gpGrid = new GridLayout(4, false);
    gpGrid.marginWidth = 5;
    gpGrid.marginHeight = 5;
    connectionGroup.setLayout(gpGrid);
    Composite versionComposite = new Composite(connectionGroup, SWT.NONE);
    versionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
    GridLayout versionCompLayout = new GridLayout(4, false);
    versionCompLayout.marginWidth = 0;
    versionCompLayout.marginHeight = 0;
    versionComposite.setLayout(versionCompLayout);
    // create DB_Version Combo
    NoSQLRepositoryFactory repFactory = NoSQLRepositoryFactory.getInstance();
    List<String> dbVersions = repFactory.getDBVersions(getConnection().getDbType());
    List<String> dbVersionLabels = repositoryTranslator.getLabels(dbVersions);
    dbVersionCombo = new LabelledCombo(versionComposite, Messages.getString("MongoDBConnForm.dbVersion"), Messages.getString("MongoDBConnForm.dbVersionTip"), dbVersionLabels.toArray(new String[0]), 3, // $NON-NLS-1$ //$NON-NLS-2$
    true);
    // create replica button
    checkUseReplicaBtn = new Button(versionComposite, SWT.CHECK);
    // $NON-NLS-1$
    checkUseReplicaBtn.setText(Messages.getString("MongoDBConnForm.useReplicaBtn"));
    checkUseReplicaBtn.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, true, false, 4, 1));
    // create connection string
    Composite connstrComposite = new Composite(versionComposite, SWT.NONE);
    connstrComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
    GridLayout connstrCompLayout = new GridLayout(4, false);
    connstrCompLayout.marginWidth = 0;
    connstrCompLayout.marginHeight = 0;
    connstrComposite.setLayout(versionCompLayout);
    checkUseConnStringBtn = new Button(connstrComposite, SWT.CHECK);
    // $NON-NLS-1$
    checkUseConnStringBtn.setText(Messages.getString("MongoDBConnForm.useConnStringBtn"));
    checkUseConnStringBtn.setLayoutData(new GridData(SWT.BEGINNING, SWT.LEFT, false, false, 1, 1));
    connStringText = new Text(connstrComposite, SWT.BORDER | SWT.SINGLE);
    connStringText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    connStringText.setVisible(false);
    // create connection composite
    connComposite = new Composite(connectionGroup, SWT.NONE);
    connComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
    GridLayout connCompLayout = new GridLayout(4, false);
    connCompLayout.marginWidth = 0;
    connCompLayout.marginHeight = 0;
    connComposite.setLayout(connCompLayout);
    // $NON-NLS-1$
    serverText = new LabelledText(connComposite, Messages.getString("MongoDBConnForm.server"), 1);
    // $NON-NLS-1$
    portText = new LabelledText(connComposite, Messages.getString("MongoDBConnForm.port"), 1);
    // create replica field
    replicaComposite = new Composite(connectionGroup, SWT.NONE);
    replicaComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
    GridLayout replicaLayout = new GridLayout();
    replicaLayout.marginWidth = 0;
    replicaLayout.marginHeight = 0;
    replicaComposite.setLayout(replicaLayout);
    Composite databaseComposite = new Composite(connectionGroup, SWT.NONE);
    databaseComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 4, 1));
    GridLayout dbCompLayout = new GridLayout(4, false);
    dbCompLayout.marginWidth = 0;
    dbCompLayout.marginHeight = 0;
    databaseComposite.setLayout(dbCompLayout);
    // $NON-NLS-1$
    databaseText = new LabelledText(databaseComposite, Messages.getString("MongoDBConnForm.database"), 3, true);
    initReplicaField();
    MongoDBReplicaFieldModel model = new MongoDBReplicaFieldModel(replicaList, // $NON-NLS-1$
    Messages.getString("MongoDBConnForm.replicaView"));
    replicaTableView = new MongoDBReplicaTableView(model, replicaComposite);
    final Composite fieldTableEditorComposite = replicaTableView.getMainComposite();
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
    gridData.heightHint = 180;
    fieldTableEditorComposite.setLayoutData(gridData);
    fieldTableEditorComposite.setBackground(null);
}
Also used : LabelledCombo(org.talend.commons.ui.swt.formtools.LabelledCombo) LabelledText(org.talend.commons.ui.swt.formtools.LabelledText) MongoDBReplicaFieldModel(org.talend.repository.nosql.db.model.mongodb.MongoDBReplicaFieldModel) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) LabelledText(org.talend.commons.ui.swt.formtools.LabelledText) Text(org.eclipse.swt.widgets.Text) NoSQLRepositoryFactory(org.talend.repository.nosql.factory.NoSQLRepositoryFactory)

Example 2 with MongoDBReplicaFieldModel

use of org.talend.repository.nosql.db.model.mongodb.MongoDBReplicaFieldModel in project tbd-studio-se by Talend.

the class MongoDBConnForm method saveReplicaModel.

private void saveReplicaModel() {
    try {
        MongoDBReplicaFieldModel model = (MongoDBReplicaFieldModel) replicaTableView.getExtendedTableModel();
        getConnection().getAttributes().put(IMongoDBAttributes.REPLICA_SET, model.getBeanListString());
    } catch (JSONException e) {
    // 
    }
}
Also used : MongoDBReplicaFieldModel(org.talend.repository.nosql.db.model.mongodb.MongoDBReplicaFieldModel) JSONException(org.talend.utils.json.JSONException)

Example 3 with MongoDBReplicaFieldModel

use of org.talend.repository.nosql.db.model.mongodb.MongoDBReplicaFieldModel in project tbd-studio-se by Talend.

the class MongoDBReplicaTableView method initToolBar.

@Override
protected ExtendedToolbarView initToolBar() {
    return new ExtendedToolbarView(getMainComposite(), SWT.NONE, getExtendedTableViewer()) {

        @Override
        protected AddPushButtonForExtendedTable createAddPushButton() {
            return new AddPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {

                @Override
                protected Object getObjectToAdd() {
                    HashMap<String, Object> hpt = getModel().createReplicaType();
                    hpt.put(IMongoConstants.REPLICA_HOST_KEY, IMongoConstants.DEFAULT_HOST);
                    hpt.put(IMongoConstants.REPLICA_PORT_KEY, IMongoConstants.DEFAULT_PORT);
                    return hpt;
                }
            };
        }

        @Override
        protected PastePushButton createPastePushButton() {
            return new PastePushButtonForExtendedTable(toolbar, extendedTableViewer) {

                @Override
                protected Command getCommandToExecute(ExtendedTableModel extendedTableModel, Integer indexWhereInsert) {
                    return new ExtendedTablePasteCommand(extendedTableModel, indexWhereInsert) {

                        @Override
                        public List<HashMap<String, Object>> createPastableBeansList(ExtendedTableModel extendedTableModel, List copiedObjectsList) {
                            List list = new ArrayList();
                            MongoDBReplicaFieldModel fieldsModel = (MongoDBReplicaFieldModel) extendedTableModel;
                            for (Object current : copiedObjectsList) {
                                if (current instanceof HashMap) {
                                    Map<String, Object> original = (HashMap<String, Object>) current;
                                    Map<String, Object> copy = fieldsModel.createReplicaType();
                                    copy.putAll(original);
                                    list.add(copy);
                                }
                            }
                            return list;
                        }
                    };
                }
            };
        }
    };
}
Also used : MongoDBReplicaFieldModel(org.talend.repository.nosql.db.model.mongodb.MongoDBReplicaFieldModel) AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) HashMap(java.util.HashMap) ExtendedTablePasteCommand(org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTablePasteCommand) ArrayList(java.util.ArrayList) PastePushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable) ArrayList(java.util.ArrayList) List(java.util.List) ExtendedTableModel(org.talend.commons.ui.swt.extended.table.ExtendedTableModel) ExtendedToolbarView(org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView)

Aggregations

MongoDBReplicaFieldModel (org.talend.repository.nosql.db.model.mongodb.MongoDBReplicaFieldModel)3 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Text (org.eclipse.swt.widgets.Text)1 ExtendedToolbarView (org.talend.commons.ui.swt.advanced.dataeditor.ExtendedToolbarView)1 AddPushButtonForExtendedTable (org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable)1 PastePushButtonForExtendedTable (org.talend.commons.ui.swt.advanced.dataeditor.button.PastePushButtonForExtendedTable)1 ExtendedTablePasteCommand (org.talend.commons.ui.swt.advanced.dataeditor.commands.ExtendedTablePasteCommand)1 ExtendedTableModel (org.talend.commons.ui.swt.extended.table.ExtendedTableModel)1 LabelledCombo (org.talend.commons.ui.swt.formtools.LabelledCombo)1 LabelledText (org.talend.commons.ui.swt.formtools.LabelledText)1 NoSQLRepositoryFactory (org.talend.repository.nosql.factory.NoSQLRepositoryFactory)1 JSONException (org.talend.utils.json.JSONException)1