Search in sources :

Example 11 with ComboBoxCellEditor

use of org.eclipse.jface.viewers.ComboBoxCellEditor in project cubrid-manager by CUBRID.

the class TableConfigCellEditor method createControl.

public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FormLayout());
    setControl(container);
    Composite leftComposite = new Composite(container, SWT.NONE);
    leftComposite.setLayout(new GridLayout(1, false));
    FormData leftData = new FormData();
    leftData.top = new FormAttachment(0, 5);
    leftData.bottom = new FormAttachment(100, 0);
    leftData.left = new FormAttachment(0, 5);
    leftData.right = new FormAttachment(55, 0);
    leftComposite.setLayoutData(leftData);
    Group grpButtons = new Group(leftComposite, SWT.NONE);
    {
        grpButtons.setLayout(new GridLayout(4, false));
        grpButtons.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
        grpButtons.setText(Messages.grpAddRemove);
    }
    Button sqlSchemaFileButton = new Button(grpButtons, SWT.NONE);
    sqlSchemaFileButton.setText(Messages.btnAddSchemaFile);
    sqlSchemaFileButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    sqlSchemaFileButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            addFile(TableConfig.TYPE_SCHEMA);
        }
    });
    Button sqlDataFileButton = new Button(grpButtons, SWT.NONE);
    sqlDataFileButton.setText(Messages.btnAddDataFile);
    sqlDataFileButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    sqlDataFileButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            addFile(TableConfig.TYPE_DATA);
        }
    });
    Button sqlIndexFileButton = new Button(grpButtons, SWT.NONE);
    sqlIndexFileButton.setText(Messages.btnAddIndexFile);
    sqlIndexFileButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    sqlIndexFileButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            addFile(TableConfig.TYPE_INDEX);
        }
    });
    delFileButton = new Button(grpButtons, SWT.NONE);
    delFileButton.setText(Messages.btnDelFiles);
    delFileButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    delFileButton.setEnabled(false);
    delFileButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            deleteSelectedFile();
        }
    });
    sqlFileTableViewer = new TableViewer(leftComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
    sqlFileTableViewer.getTable().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 4, 1, -1, -1));
    sqlFileTableViewer.getTable().setLinesVisible(true);
    sqlFileTableViewer.getTable().setHeaderVisible(true);
    final TableViewerColumn fileNameCol = new TableViewerColumn(sqlFileTableViewer, SWT.NONE);
    fileNameCol.getColumn().setWidth(300);
    fileNameCol.getColumn().setText(Messages.columnImportFileName);
    final TableViewerColumn fileTypeCol = new TableViewerColumn(sqlFileTableViewer, SWT.NONE);
    fileTypeCol.getColumn().setWidth(100);
    fileTypeCol.getColumn().setText(Messages.columnImportFileType);
    CellEditor[] editors = new CellEditor[4];
    editors[0] = new TextCellEditor(sqlFileTableViewer.getTable());
    editors[1] = new ComboBoxCellEditor(sqlFileTableViewer.getTable(), TYPE_ITEMS, SWT.READ_ONLY);
    sqlFileTableViewer.setColumnProperties(PROPS);
    sqlFileTableViewer.setContentProvider(new SQLFileTableContentProvider());
    sqlFileTableViewer.setLabelProvider(new SQLFileTableLabelProvider());
    sqlFileTableViewer.setCellModifier(new TableConfigCellEditor(sqlFileTableViewer, this));
    sqlFileTableViewer.setCellEditors(editors);
    sqlFileTableViewer.getTable().addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            delFileButton.setEnabled(delCanEnable());
        }
    });
    Composite rightComposite = new Composite(container, SWT.NONE);
    FormData rightData = new FormData();
    rightData.top = new FormAttachment(0, 5);
    rightData.bottom = new FormAttachment(100, 0);
    rightData.left = new FormAttachment(55, 0);
    rightData.right = new FormAttachment(100, -5);
    rightComposite.setLayoutData(rightData);
    GridLayout rightCompositeLayout = new GridLayout();
    rightCompositeLayout.verticalSpacing = 10;
    rightComposite.setLayout(rightCompositeLayout);
    Group enCodingOptionGroup = new Group(rightComposite, SWT.None);
    enCodingOptionGroup.setText(Messages.grpEncodingOption);
    enCodingOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    enCodingOptionGroup.setLayout(new GridLayout(4, false));
    Label dbCharsetLabel = new Label(enCodingOptionGroup, SWT.None);
    dbCharsetLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    dbCharsetLabel.setText(Messages.lblDBCharset);
    dbCharsetCombo = new Combo(enCodingOptionGroup, SWT.BORDER);
    dbCharsetCombo.setLayoutData(CommonUITool.createGridData(1, 1, 50, 21));
    dbCharsetCombo.setEnabled(false);
    Label fileCharsetLabel = new Label(enCodingOptionGroup, SWT.None);
    fileCharsetLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    fileCharsetLabel.setText(Messages.lblFileCharset);
    fileCharsetCombo = new Combo(enCodingOptionGroup, SWT.BORDER);
    fileCharsetCombo.setLayoutData(CommonUITool.createGridData(1, 1, 50, 21));
    fileCharsetCombo.setItems(QueryOptions.getAllCharset(null));
    fileCharsetCombo.select(0);
    fileCharsetCombo.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            getImportDataWizard().getImportConfig().setFilesCharset(fileCharsetCombo.getText());
        }
    });
    Group importOptionGroup = new Group(rightComposite, SWT.None);
    importOptionGroup.setText(Messages.grpImportOptions);
    importOptionGroup.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    importOptionGroup.setLayout(new GridLayout(2, false));
    Label threadCountLabel = new Label(importOptionGroup, SWT.None);
    threadCountLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    threadCountLabel.setText(Messages.lblThreadNum);
    threadCountSpinner = new Spinner(importOptionGroup, SWT.BORDER);
    threadCountSpinner.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    threadCountSpinner.setMaximum(ImportConfig.MAX_IMPORT_THREAD_COUNT);
    threadCountSpinner.setMinimum(ImportConfig.MIN_IMPORT_THREAD_COUNT);
    threadCountSpinner.setSelection(ImportConfig.DEFAULT_IMPORT_THREAD_COUNT);
    threadCountSpinner.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            widgetDefaultSelected(e);
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            validate();
        }
    });
    Label commitCountLabel = new Label(importOptionGroup, SWT.None);
    commitCountLabel.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, 1, -1, -1));
    commitCountLabel.setText(Messages.lblCommitCount);
    commitCountSpinner = new Spinner(importOptionGroup, SWT.BORDER);
    commitCountSpinner.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 1, 1, -1, -1));
    commitCountSpinner.setMaximum(ImportConfig.MAX_IMPORT_COMMIT_COUNT);
    commitCountSpinner.setMinimum(ImportConfig.MIN_IMPORT_COMMIT_COUNT);
    commitCountSpinner.setIncrement(ImportConfig.IMPORT_COMMIT_STEP);
    commitCountSpinner.setSelection(ImportConfig.DEFAULT_IMPORT_COMMIT_COUNT);
    final Button haModeButton = new Button(rightComposite, SWT.CHECK);
    haModeButton.setText(Messages.btnInHaMode);
    haModeButton.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_END, 1, 1, -1, -1));
    haModeButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            ImportConfig importConfig = getImportDataWizard().getImportConfig();
            importConfig.setHaMode(haModeButton.getSelection());
            Collections.sort(fileList, new TableConfigComparator(getImportDataWizard().getImportConfig()));
            sqlFileTableViewer.refresh();
        }
    });
    registerContextMenu();
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Spinner(org.eclipse.swt.widgets.Spinner) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 12 with ComboBoxCellEditor

use of org.eclipse.jface.viewers.ComboBoxCellEditor in project cubrid-manager by CUBRID.

the class TableEditorPart method createGeneralTabItem.

/**
	 * Create general tab item
	 *
	 * @param tabFolder the object of TabFolder
	 */
private void createGeneralTabItem(final TabFolder tabFolder) {
    final TabItem generalTabItem = new TabItem(tabFolder, SWT.NONE);
    generalTabItem.setText(Messages.infoGeneralTab);
    final Composite compositeGenaral = new Composite(tabFolder, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    compositeGenaral.setLayout(gridLayout);
    generalTabItem.setControl(compositeGenaral);
    final Group group = new Group(compositeGenaral, SWT.NONE);
    group.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    group.setLayout(gridLayout);
    group.setText(Messages.lblTableInfo);
    final Label tableNameLabel = new Label(group, SWT.NONE);
    tableNameLabel.setData(Messages.dataNewKey, null);
    tableNameLabel.setText(Messages.lblTableName);
    tableNameComp = new Composite(group, SWT.NONE);
    {
        GridLayout gl = new GridLayout();
        gl.numColumns = 5;
        gl.marginWidth = 0;
        tableNameComp.setLayout(gl);
        tableNameComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        tableNameText = new Text(tableNameComp, SWT.BORDER);
        tableNameText.setTextLimit(ValidateUtil.MAX_SCHEMA_NAME_LENGTH);
        {
            GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
            gd.widthHint = 200;
            tableNameText.setLayoutData(gd);
        }
        tableNameText.addModifyListener(new ModifyListener() {

            public void modifyText(ModifyEvent event) {
                if (tableNameText.getText().length() == 0) {
                    CommonUITool.hideErrorBaloon(errorBaloon);
                } else if (verifyTableName()) {
                    String tableName = tableNameText.getText();
                    newSchemaInfo.setClassname(tableName);
                }
            }
        });
        tableNameText.addFocusListener(new FocusAdapter() {

            public void focusLost(FocusEvent e) {
                CommonUITool.hideErrorBaloon(errorBaloon);
            }
        });
        final Label ownerLabel = new Label(tableNameComp, SWT.NONE);
        ownerLabel.setText(Messages.lblOwner);
        ownerCombo = new Combo(tableNameComp, SWT.READ_ONLY);
        {
            GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
            gd.widthHint = 100;
            ownerCombo.setLayoutData(gd);
        }
        ownerCombo.setVisibleItemCount(10);
        fillOwnerCombo();
        if (supportCharset) {
            final Label collationLabel = new Label(tableNameComp, SWT.NONE);
            collationLabel.setText(Messages.lblCollation);
            collationCombo = new Combo(tableNameComp, SWT.READ_ONLY);
            {
                GridData gd = new GridData(SWT.LEFT, SWT.CENTER, false, false);
                gd.widthHint = 100;
                collationCombo.setLayoutData(gd);
            }
            collationCombo.setVisibleItemCount(10);
            fillCollationCombo();
            String collation = collationCombo.getText();
            newSchemaInfo.setCollation(collation);
            collationCombo.addSelectionListener(new SelectionListener() {

                public void widgetSelected(SelectionEvent e) {
                    String collation = collationCombo.getText();
                    newSchemaInfo.setCollation(collation);
                }

                public void widgetDefaultSelected(SelectionEvent e) {
                }
            });
            if (!isNewTableFlag && newSchemaInfo.getCollation() != null) {
                collationCombo.setText(newSchemaInfo.getCollation());
            }
        } else {
            new Label(tableNameComp, SWT.NONE);
            new Label(tableNameComp, SWT.NONE);
        }
    }
    final Label tableDescLabel = new Label(group, SWT.NONE);
    tableDescLabel.setText(Messages.lblTableDesc);
    tableDescText = new Text(group, SWT.BORDER);
    tableDescText.setTextLimit(512);
    tableDescText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    if (newSchemaInfo != null && newSchemaInfo.getDescription() != null) {
        tableDescText.setText(newSchemaInfo.getDescription());
    }
    tableDescText.addFocusListener(new FocusAdapter() {

        public void focusGained(FocusEvent e) {
            if (!isSupportTableComment) {
                CommonUITool.showErrorBaloon(group, tableDescText, errorBaloon, "", Messages.errNotSupportTableCommentNotice);
                tableDescText.setFocus();
            }
        }

        public void focusLost(FocusEvent e) {
            CommonUITool.hideErrorBaloon(errorBaloon);
        }
    });
    tableDescText.setEditable(isSupportTableComment);
    if (database == null) {
        return;
    }
    if (CompatibleUtil.isSupportReuseOID(database.getDatabaseInfo())) {
        reuseOIDBtn = new Button(group, SWT.CHECK);
        reuseOIDBtn.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
        reuseOIDBtn.setText(Messages.btnReuseOid);
        if (!isNewTableFlag) {
            reuseOIDBtn.setEnabled(false);
        }
    }
    final Label columnsLabel = new Label(compositeGenaral, SWT.NONE);
    columnsLabel.setText(Messages.lblColumn);
    // create attribute table
    columnTableView = new TableViewer(compositeGenaral, SWT.FULL_SELECTION | SWT.BORDER);
    columnTableView.setUseHashlookup(true);
    columnTableView.setColumnProperties(columnProperites);
    columnsTable = columnTableView.getTable();
    //columnsTable.pack();
    final GridData gdColumnsTable = new GridData(SWT.FILL, SWT.FILL, true, true);
    gdColumnsTable.heightHint = 189;
    columnsTable.setLayoutData(gdColumnsTable);
    columnsTable.setLinesVisible(true);
    columnsTable.setHeaderVisible(true);
    // The empty column
    final TableColumn emptyColumn = new TableColumn(columnsTable, SWT.NONE);
    emptyColumn.setWidth(0);
    // The flag column
    final TableColumn flagColumn = new TableColumn(columnsTable, SWT.RIGHT_TO_LEFT);
    flagColumn.setWidth(28);
    // NAME
    final TableColumn nameColumn = new TableColumn(columnsTable, SWT.NONE);
    nameColumn.setWidth(140);
    nameColumn.setText(Messages.tblColumnName);
    // DATATYPE
    final TableColumn dataTypeColumn = new TableColumn(columnsTable, SWT.NONE);
    dataTypeColumn.setWidth(120);
    dataTypeColumn.setText(Messages.tblColumnDataType);
    // DEFAULT
    final TableColumn defaultColumn = new TableColumn(columnsTable, SWT.NONE);
    defaultColumn.setWidth(98);
    defaultColumn.setText(Messages.tblColumnDefault);
    defaultColumn.setToolTipText(Messages.tblColumnDefaultHint);
    // AUTO INCREMENT
    final TableColumn autoIncrTableColumn = new TableColumn(columnsTable, SWT.NONE);
    autoIncrTableColumn.setAlignment(SWT.LEFT);
    autoIncrTableColumn.setWidth(100);
    autoIncrTableColumn.setText(Messages.tblColumnAutoIncr);
    autoIncrTableColumn.setToolTipText(Messages.tblColumnAutoIncrHint);
    // NOT NULL
    final TableColumn notNullColumn = new TableColumn(columnsTable, SWT.NONE);
    notNullColumn.setWidth(65);
    notNullColumn.setText(Messages.tblColumnNotNull);
    notNullColumn.setAlignment(SWT.LEFT);
    notNullColumn.setToolTipText(Messages.tblColumnNotNullHint);
    // PK
    final TableColumn pkColumn = new TableColumn(columnsTable, SWT.NONE);
    pkColumn.setAlignment(SWT.CENTER);
    pkColumn.setWidth(90);
    pkColumn.setText(Messages.tblColumnPK);
    // UK
    final TableColumn uniqueColumn = new TableColumn(columnsTable, SWT.NONE);
    uniqueColumn.setWidth(55);
    uniqueColumn.setText(Messages.tblColumnUnique);
    uniqueColumn.setAlignment(SWT.LEFT);
    uniqueColumn.setToolTipText(Messages.tblColumnUniqueHint);
    // SHARED
    sharedColumn = new TableColumn(columnsTable, SWT.NONE);
    sharedColumn.setWidth(65);
    sharedColumn.setText(Messages.tblColumnShared);
    sharedColumn.setAlignment(SWT.LEFT);
    sharedColumn.setToolTipText(Messages.tblColumnSharedHint);
    if (supportCharset) {
        final TableColumn collationColumn = new TableColumn(columnsTable, SWT.NONE);
        collationColumn.setWidth(120);
        collationColumn.setText(Messages.tblColumnColumnCollation);
        collationColumn.setAlignment(SWT.LEFT);
    }
    final TableColumn descColumn = new TableColumn(columnsTable, SWT.NONE);
    descColumn.setWidth(180);
    descColumn.setText(Messages.tblColumnColumnDesc);
    descColumn.setAlignment(SWT.LEFT);
    boolean canEdit = true;
    if (!editor.isNewTableFlag() && !editor.isSupportChange()) {
        canEdit = false;
    }
    attrContentProvider = new AttributeContentProvider();
    attrLabelProvider = new AttributeLabelProvider(database.getDatabaseInfo(), newSchemaInfo, canEdit, editorAdaptor);
    columnTableView.setContentProvider(attrContentProvider);
    columnTableView.setLabelProvider(attrLabelProvider);
    CellEditor[] cellEditor = new CellEditor[columnProperites.length];
    {
        int index = 0;
        // Empty
        cellEditor[index++] = null;
        // Flag
        cellEditor[index++] = null;
        // NAME
        cellEditor[index++] = new TextCellEditor(columnsTable);
        // DATATYPE
        cellEditor[index++] = new DataTypeCellEditor((Composite) columnsTable, listDataTypes(), editorAdaptor);
        // DEFAULT
        cellEditor[index++] = new TextCellEditor(columnsTable);
        // AUTO INCREMENT
        cellEditor[index++] = new AutoIncrementCellEditor(columnsTable, editorAdaptor);
        // NOT NULL
        cellEditor[index++] = new CheckboxCellEditor(columnsTable);
        // PK
        cellEditor[index++] = new CheckboxCellEditor(columnsTable);
        // UK
        cellEditor[index++] = new CheckboxCellEditor(columnsTable);
        // SHARD
        cellEditor[index++] = new CheckboxCellEditor(columnsTable);
        // COLLATION
        if (supportCharset) {
            cellEditor[index++] = new ComboBoxCellEditor(columnsTable, getCollationArray(), SWT.READ_ONLY);
        }
        // MEMO
        cellEditor[index++] = new TextCellEditor(columnsTable);
    }
    columnTableView.setCellEditors(cellEditor);
    columnTableView.setCellModifier(new AttributeCellModifier(editorAdaptor));
    loadColumnData();
    CommonUITool.hackForYosemite(columnsTable);
    // Create button
    final Composite btnRowComposite = new Composite(compositeGenaral, SWT.NONE);
    btnRowComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    {
        GridLayout layout = new GridLayout();
        layout.numColumns = 2;
        layout.marginWidth = 5;
        btnRowComposite.setLayout(layout);
    }
    final Composite optComposite = new Composite(btnRowComposite, SWT.NONE);
    optComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    {
        GridLayout layout = new GridLayout();
        layout.numColumns = 1;
        layout.marginWidth = 0;
        optComposite.setLayout(layout);
    }
    final Composite btnComposite = new Composite(btnRowComposite, SWT.NONE);
    btnComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
    {
        GridLayout layout = new GridLayout();
        layout.marginRight = 0;
        layout.numColumns = 6;
        layout.marginWidth = 0;
        btnComposite.setLayout(layout);
    }
    final Button setPkButton = new Button(btnComposite, SWT.NONE);
    setPkButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
    setPkButton.setText(Messages.btnPK);
    setPkButton.addSelectionListener(new PkBtnListenerOnGeneTab(isNewTableFlag));
    final GridData gdUpDown = new GridData(60, SWT.DEFAULT);
    upColumnBtn = new Button(btnComposite, SWT.NONE);
    upColumnBtn.setLayoutData(gdUpDown);
    upColumnBtn.setEnabled(false);
    upColumnBtn.setText(Messages.btnUp);
    upColumnBtn.addSelectionListener(new UpBtnListenerOnGeneTab());
    downColumnBtn = new Button(btnComposite, SWT.DOWN);
    downColumnBtn.setLayoutData(gdUpDown);
    downColumnBtn.setEnabled(false);
    downColumnBtn.setText(Messages.btnDown);
    downColumnBtn.addSelectionListener(new DownBtnListenerOnGeneTab());
    final Button addButton = new Button(btnComposite, SWT.NONE);
    final GridData gdAddButton = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    gdAddButton.horizontalIndent = 10;
    addButton.setLayoutData(gdAddButton);
    addButton.setText(Messages.btnAddColumn);
    addButton.addSelectionListener(new AddBtnListenerOnGeneTab());
    deleteColumnBtn = new Button(btnComposite, SWT.NONE);
    final GridData gdDeleteButton = new GridData(SWT.LEFT, SWT.CENTER, false, false);
    gdDeleteButton.horizontalIndent = 10;
    deleteColumnBtn.setLayoutData(gdDeleteButton);
    deleteColumnBtn.setEnabled(false);
    deleteColumnBtn.setText(Messages.btnDelColumn);
    deleteColumnBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            deleteColumn();
        }
    });
    columnsTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            handleSelectionChangeInColumnTable();
        }
    });
    buildColumnTableMenu();
}
Also used : Group(org.eclipse.swt.widgets.Group) FocusAdapter(org.eclipse.swt.events.FocusAdapter) ModifyListener(org.eclipse.swt.events.ModifyListener) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) CheckboxCellEditor(org.eclipse.jface.viewers.CheckboxCellEditor) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) FocusEvent(org.eclipse.swt.events.FocusEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) TabItem(org.eclipse.swt.widgets.TabItem) GridData(org.eclipse.swt.layout.GridData) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 13 with ComboBoxCellEditor

use of org.eclipse.jface.viewers.ComboBoxCellEditor in project cubrid-manager by CUBRID.

the class CreateViewDialog method createGeneralComposite.

/**
	 * create General Composite
	 *
	 * @return composite
	 */
private Composite createGeneralComposite() {
    final Composite composite = new Composite(tabFolder, SWT.NONE);
    {
        final GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 2;
        gridLayout.makeColumnsEqualWidth = true;
        composite.setLayout(gridLayout);
    }
    final Group group = new Group(composite, SWT.NONE);
    {
        GridData gdGroup = new GridData(SWT.FILL, SWT.CENTER, true, false);
        gdGroup.horizontalSpan = 2;
        group.setLayoutData(gdGroup);
        final GridLayout gridLayout1 = new GridLayout();
        gridLayout1.numColumns = 2;
        group.setLayout(gridLayout1);
    }
    final Label tableNameLabel = new Label(group, SWT.SHADOW_IN);
    tableNameLabel.setText(Messages.lblViewName);
    tableText = new Text(group, SWT.BORDER);
    tableText.setTextLimit(ValidateUtil.MAX_SCHEMA_NAME_LENGTH);
    final GridData gdTableText = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gdTableText.horizontalIndent = 30;
    tableText.setLayoutData(gdTableText);
    if (isCommentSupport) {
        final Label viewDescriptionLabel = new Label(group, SWT.SHADOW_IN);
        viewDescriptionLabel.setText(Messages.lblViewDescription);
        viewDescriptionText = new Text(group, SWT.BORDER);
        viewDescriptionText.setTextLimit(ValidateUtil.MAX_DB_OBJECT_COMMENT);
        final GridData gdViewDescription = new GridData(SWT.FILL, SWT.CENTER, true, false);
        gdViewDescription.horizontalIndent = 30;
        viewDescriptionText.setLayoutData(gdViewDescription);
        viewDescriptionText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent event) {
                if (getButton(IDialogConstants.OK_ID) != null) {
                    getButton(IDialogConstants.OK_ID).setEnabled(true);
                }
            }
        });
    }
    final Label ownerLabel = new Label(group, SWT.NONE);
    ownerLabel.setText(Messages.lblViewOwnerName);
    ownerCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    final GridData gdCombo = new GridData(SWT.FILL, SWT.CENTER, true, false);
    gdCombo.horizontalIndent = 30;
    ownerCombo.setLayoutData(gdCombo);
    ownerCombo.setVisibleItemCount(10);
    ownerCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent event) {
            if (getButton(IDialogConstants.OK_ID) != null) {
                getButton(IDialogConstants.OK_ID).setEnabled(true);
            }
        }
    });
    final Label querySQLLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
    querySQLLabel.setText(Messages.lblQueryList);
    querySQLLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    final Label sqlDescLabel = new Label(composite, SWT.LEFT | SWT.WRAP);
    sqlDescLabel.setText(Messages.lblSelectQueryList);
    sqlDescLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    final String[] columnNameArr1 = new String[] { "col1" };
    queryTableViewer = CommonUITool.createCommonTableViewer(composite, null, columnNameArr1, CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, 100));
    queryTableViewer.getTable().setHeaderVisible(false);
    queryTableViewer.setInput(queryListData);
    queryTableViewer.getTable().addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent event) {
        }

        public void widgetSelected(SelectionEvent event) {
            int index = queryTableViewer.getTable().getSelectionIndex();
            String value = queryListData.get(index).get("0");
            if (value != null) {
                querydescText.setText(formatSql(value));
            }
            setButtonStatus();
        }
    });
    queryTableViewer.getTable().getColumn(0).setWidth(200);
    querydescText = new Text(composite, SWT.LEFT | SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
    querydescText.setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 1, 1, -1, 200));
    barComp = new Composite(composite, SWT.NONE);
    {
        final GridData gdbarComp = new GridData(GridData.FILL_HORIZONTAL);
        gdbarComp.horizontalSpan = 2;
        barComp.setLayoutData(gdbarComp);
        GridLayout layout = new GridLayout();
        layout.marginWidth = 10;
        layout.marginHeight = 10;
        barComp.setLayout(layout);
    }
    final Label columnsLabel = new Label(composite, SWT.NONE);
    columnsLabel.setText(Messages.lblTableNameColumns);
    final String[] columnNameArr = isCommentSupport ? new String[] { Messages.tblColViewName, Messages.tblColViewDataType, Messages.tblColViewDefaultType, Messages.tblColViewDefaultValue, Messages.tblColViewMemo } : new String[] { Messages.tblColViewName, Messages.tblColViewDataType, Messages.tblColViewDefaultType, Messages.tblColViewDefaultValue };
    viewColTableViewer = createCommonTableViewer(composite, null, columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 2, 4, -1, 200));
    viewColTableViewer.setInput(viewColListData);
    viewColTableViewer.setColumnProperties(columnNameArr);
    CellEditor[] editors = new CellEditor[5];
    editors[0] = new TextCellEditor(viewColTableViewer.getTable());
    editors[1] = null;
    editors[2] = new ComboBoxCellEditor(viewColTableViewer.getTable(), defaultType, SWT.READ_ONLY);
    editors[3] = new TextCellEditor(viewColTableViewer.getTable());
    if (isCommentSupport) {
        editors[4] = new TextCellEditor(viewColTableViewer.getTable());
    }
    viewColTableViewer.setCellEditors(editors);
    viewColTableViewer.setCellModifier(new ICellModifier() {

        @SuppressWarnings("unchecked")
        public boolean canModify(Object element, String property) {
            if (isPropertyQuery || property.equals(columnNameArr[1])) {
                return false;
            }
            Map<String, String> map = (Map<String, String>) element;
            if (property.equals(columnNameArr[3])) {
                String defaultTypeStr = map.get("2");
                if (defaultTypeStr == null || defaultType[0].equals(defaultTypeStr)) {
                    return false;
                }
            }
            return true;
        }

        @SuppressWarnings("unchecked")
        public Object getValue(Object element, String property) {
            Map<String, String> map = (Map<String, String>) element;
            if (property.equals(columnNameArr[0])) {
                return map.get("0");
            } else if (property.equals(columnNameArr[2])) {
                String str = map.get("2");
                int index = 0;
                if (str != null) {
                    for (int i = 0; defaultType != null && i < defaultType.length; i++) {
                        if (str.equals(defaultType[i])) {
                            index = i;
                            break;
                        }
                    }
                }
                return Integer.valueOf(index);
            } else if (property.equals(columnNameArr[3])) {
                String type = map.get("1");
                String value = map.get("3");
                if (value == null) {
                    value = "";
                }
                if (type != null && (type.startsWith(DataType.DATATYPE_CHAR) || type.startsWith(DataType.DATATYPE_STRING) || type.startsWith(DataType.DATATYPE_VARCHAR)) && (value.startsWith("'") && value.endsWith("'") && value.length() > 1)) {
                    value = value.substring(1, value.length() - 1);
                }
                return value;
            } else if (isCommentSupport && property.equals(columnNameArr[4])) {
                return map.get("4");
            }
            return null;
        }

        @SuppressWarnings("unchecked")
        public void modify(Object element, String property, Object value) {
            Object elementData = null;
            if (element instanceof Item) {
                elementData = ((Item) element).getData();
            }
            Map<String, String> map = (Map<String, String>) elementData;
            if (map == null) {
                return;
            }
            String type = map.get("1");
            if (property.equals(columnNameArr[0])) {
                map.put("0", value.toString());
            } else if (property.equals(columnNameArr[2])) {
                int index = Integer.parseInt(value.toString());
                if (index == 0) {
                    map.put("3", "");
                }
                map.put("2", defaultType[index]);
            } else if (property.equals(columnNameArr[3])) {
                String val = FieldHandlerUtils.getValidDefaultValue(value, type);
                if (val != null) {
                    map.put("3", val);
                }
            } else if (isCommentSupport && property.equals(columnNameArr[4])) {
                map.put("4", value.toString());
            }
            viewColTableViewer.refresh();
            valid();
        }
    });
    return composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Label(org.eclipse.swt.widgets.Label) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) Item(org.eclipse.swt.widgets.Item) TabItem(org.eclipse.swt.widgets.TabItem) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) Map(java.util.Map) HashMap(java.util.HashMap) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 14 with ComboBoxCellEditor

use of org.eclipse.jface.viewers.ComboBoxCellEditor in project cubrid-manager by CUBRID.

the class UserAuthDbInfoPage method setCellEditors.

/**
	 * 
	 * Set cell editors
	 */
private void setCellEditors() {
    authTableViewer.setCellEditors(null);
    Table authTable = authTableViewer.getTable();
    CellEditor[] editors = new CellEditor[5];
    editors[0] = null;
    editors[1] = new ComboBoxCellEditor(authTable, allowConnected, SWT.READ_ONLY);
    editors[2] = new TextCellEditor(authTable);
    editors[3] = new TextCellEditor(authTable);
    if (allBrokerPorts != null && allBrokerPorts.length > 0) {
        editors[4] = new ComboBoxCellEditor(authTable, allBrokerPorts, SWT.READ_ONLY);
    } else {
        editors[4] = new TextCellEditor(authTable);
    }
    authTableViewer.setCellEditors(editors);
}
Also used : Table(org.eclipse.swt.widgets.Table) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 15 with ComboBoxCellEditor

use of org.eclipse.jface.viewers.ComboBoxCellEditor in project cubrid-manager by CUBRID.

the class ShardKeysPanel method linkEditorForKeyInfoTable.

/**
	 * Links the editable column of table
	 */
private void linkEditorForKeyInfoTable() {
    keyInfoTableViewer.setColumnProperties(keyInfoColumnNameArrs);
    CellEditor[] editors = new CellEditor[3];
    editors[0] = new TextCellEditor(keyInfoTable);
    editors[1] = new TextCellEditor(keyInfoTable);
    String[] shardIds = new String[shardIdList.size()];
    shardIds = shardIdList.toArray(shardIds);
    shardIdCellEditor = new ComboBoxCellEditor(keyInfoTable, shardIds, SWT.READ_ONLY) {

        {
            if (!shardIdList.isEmpty()) {
                this.doSetValue(shardIdList.get(0));
            }
        }

        protected void doSetValue(Object value) {
            for (int i = 0; i < shardIdList.size(); i++) {
                if (shardIdList.get(i).equals((String) value)) {
                    super.doSetValue(i);
                }
            }
        }

        protected Object doGetValue() {
            int selection = ((Integer) super.doGetValue()).intValue();
            if (selection == -1) {
                return "";
            }
            return shardIdList.get(selection);
        }
    };
    editors[2] = shardIdCellEditor;
    keyInfoTableViewer.setCellEditors(editors);
    keyInfoTableViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            return true;
        }

        @SuppressWarnings("unchecked")
        public Object getValue(Object element, String property) {
            Map<String, String> map = (Map<String, String>) element;
            if (property.equals(keyInfoColumnNameArrs[0])) {
                return map.get("0");
            } else if (property.equals(keyInfoColumnNameArrs[1])) {
                return map.get("1");
            } else if (property.equals(keyInfoColumnNameArrs[2])) {
                return map.get("2");
            }
            return null;
        }

        public void modify(Object element, String property, Object value) {
            Object obj = null;
            if (element instanceof Item) {
                obj = ((Item) element).getData();
            }
            if (obj == null) {
                return;
            }
            @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) obj;
            boolean isValid = true;
            if (!StringUtil.isEmpty(value.toString())) {
                if (isValid && !ValidateUtil.isInteger(value.toString())) {
                    isValid = false;
                    CommonUITool.openErrorBox(Messages.errShardKeyParameterNotNumeric);
                }
                if (isValid) {
                    if (property.equals(keyInfoColumnNameArrs[0])) {
                        map.put("0", value.toString());
                    } else if (property.equals(keyInfoColumnNameArrs[1])) {
                        map.put("1", value.toString());
                    } else if (property.equals(keyInfoColumnNameArrs[2])) {
                        map.put("2", value.toString());
                    }
                }
            }
            keyInfoTableViewer.refresh();
            saveShardKey();
            // Notice the upper layer
            modifyListener.modifyText(null);
        }
    });
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ToolItem(org.eclipse.swt.widgets.ToolItem) Item(org.eclipse.swt.widgets.Item) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) ICellModifier(org.eclipse.jface.viewers.ICellModifier) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)25 CellEditor (org.eclipse.jface.viewers.CellEditor)15 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)13 CCombo (org.eclipse.swt.custom.CCombo)10 Composite (org.eclipse.swt.widgets.Composite)8 CellEditorValueAdapter (org.talend.commons.ui.runtime.swt.tableviewer.behavior.CellEditorValueAdapter)8 TableViewerCreatorColumn (org.talend.commons.ui.swt.tableviewer.TableViewerCreatorColumn)8 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 List (java.util.List)6 GridData (org.eclipse.swt.layout.GridData)6 GridLayout (org.eclipse.swt.layout.GridLayout)6 Label (org.eclipse.swt.widgets.Label)6 HashMap (java.util.HashMap)5 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)5 Button (org.eclipse.swt.widgets.Button)4 Text (org.eclipse.swt.widgets.Text)4 IBeanPropertyAccessors (org.talend.commons.utils.data.bean.IBeanPropertyAccessors)4 IConnection (org.talend.core.model.process.IConnection)4