Search in sources :

Example 81 with Table

use of org.eclipse.swt.widgets.Table in project cubrid-manager by CUBRID.

the class SchemaInfoEditorPart method createFKTable.

/**
	 * Create foreign key information table
	 * 
	 */
private void createFKTable() {
    Label fkLabel = new Label(topComposite, SWT.LEFT | SWT.WRAP);
    fkLabel.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    fkLabel.setText(Messages.lblFK);
    fkTableView = new TableViewer(topComposite, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    Table fkTable = fkTableView.getTable();
    {
        createContextMenu(fkTable);
        final GridData gdFkTable = new GridData(SWT.FILL, SWT.FILL, true, true);
        fkTable.setLayoutData(gdFkTable);
        fkTable.setLinesVisible(true);
        fkTable.setHeaderVisible(true);
        CommonUITool.hackForYosemite(fkTable);
        TableColumn tblCol = new TableColumn(fkTable, SWT.NONE);
        tblCol.setWidth(160);
        tblCol.setText(Messages.tblColumnFK);
        tblCol = new TableColumn(fkTable, SWT.NONE);
        tblCol.setWidth(119);
        tblCol.setText(Messages.tblColumnColumnName);
        tblCol = new TableColumn(fkTable, SWT.NONE);
        tblCol.setWidth(93);
        tblCol.setText(Messages.tblColumnForeignTable);
        tblCol = new TableColumn(fkTable, SWT.NONE);
        tblCol.setWidth(143);
        tblCol.setText(Messages.tblColumnForeignColumnName);
        tblCol = new TableColumn(fkTable, SWT.NONE);
        tblCol.setWidth(84);
        tblCol.setText(Messages.tblColumnUpdateRule);
        tblCol = new TableColumn(fkTable, SWT.NONE);
        tblCol.setWidth(86);
        tblCol.setText(Messages.tblColumnDeleteRule);
        tblCol = new TableColumn(fkTable, SWT.NONE);
        tblCol.setWidth(100);
        tblCol.setText(Messages.tblColumnCacheColumn);
    }
    fkTableView.setContentProvider(new FKTableViewerContentProvider());
    fkTableView.setLabelProvider(new FKTableViewerLabelProvider(database));
    fkTableView.setInput(schemaInfo);
    int colNum = fkTable.getColumnCount();
    for (int i = 0; i < colNum; i++) {
        setTableEditor(fkTable, i);
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) TableViewer(org.eclipse.jface.viewers.TableViewer) TableColumn(org.eclipse.swt.widgets.TableColumn) Point(org.eclipse.swt.graphics.Point)

Example 82 with Table

use of org.eclipse.swt.widgets.Table in project cubrid-manager by CUBRID.

the class TableEditorPart method changePartitionTabButtonStatus.

/**
	 * Change the partition tab's button state.
	 */
private void changePartitionTabButtonStatus() {
    Table partitionTable = partitionTableView.getTable();
    int selectedCount = partitionTable.getSelectionCount();
    int itemCount = partitionTable.getItemCount();
    boolean canAdd = getPartitonType() != PartitionType.HASH;
    addPartitionBtn.setEnabled(canAdd);
    boolean canModify = (itemCount > 0 && getPartitonType() == PartitionType.HASH) || (selectedCount > 0 && getPartitonType() != null);
    editPartitionBtn.setEnabled(canModify);
    delPartitionBtn.setEnabled(canModify);
}
Also used : Table(org.eclipse.swt.widgets.Table) Constraint(com.cubrid.common.core.common.model.Constraint)

Example 83 with Table

use of org.eclipse.swt.widgets.Table in project cubrid-manager by CUBRID.

the class AttributeCellModifier method modify.

public void modify(Object element, String property, Object value) {
    // FIXME move this logic to core module
    final TableItem item = (TableItem) element;
    if (item == null) {
        return;
    }
    DBAttribute attr = (DBAttribute) item.getData();
    String attrName = attr.getName();
    DBAttribute oldAttribute = null;
    if (editor.getOldSchemaInfo() != null) {
        oldAttribute = editor.getOldSchemaInfo().getDBAttributeByName(attrName, false);
    }
    if (StringUtil.isEqual(property, IAttributeColumn.COL_PK)) {
        SchemaInfo schemaInfo = editor.getNewSchemaInfo();
        if (schemaInfo == null) {
            return;
        }
        boolean on = ((Boolean) value).booleanValue();
        if (on) {
            Constraint constraint = schemaInfo.getPK();
            if (constraint == null) {
                constraint = new Constraint("pk", Constraint.ConstraintType.PRIMARYKEY.getText());
                schemaInfo.addConstraint(constraint);
            }
            constraint.addAttribute(attr.getName());
        } else {
            Constraint constraint = schemaInfo.getPK();
            if (constraint == null) {
                return;
            }
            List<String> columns = constraint.getAttributes();
            if (columns == null || columns.size() == 0) {
                return;
            }
            boolean isContain = columns.remove(attr.getName());
            /*For bug TOOLS-3972 The collumn's setting in Edit Table Inconsistent with the setting in Set Primary Key*/
            if (isContain && columns.size() == 0) {
                schemaInfo.removeConstraintByName(constraint.getName(), constraint.getType());
            }
            /*For bug TOOLS-3046 : deal with edit column*/
            if (oldAttribute != null && isContain) {
                attr.setNotNull(false);
                editor.changeForEditElement(attrName, attr, oldAttribute);
            }
        }
        editor.makeChangeLogForIndex(attrName, attr, oldAttribute);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NAME)) {
        String newName = (String) value;
        SchemaInfo schemaInfo = editor.getNewSchemaInfo();
        if (schemaInfo == null) {
            // TODO Improve error message
            CommonUITool.openErrorBox(Messages.errEmptyNameOnEditTableColumn);
            return;
        }
        if (!StringUtil.isEmpty(newName) && !ValidateUtil.isValidIdentifier(newName)) {
            CommonUITool.openErrorBox(Messages.errColumnName);
            return;
        }
        List<DBAttribute> lastAttrs = schemaInfo.getAttributes();
        if (StringUtil.isEmpty(newName) && lastAttrs.contains(attr)) {
            CommonUITool.openErrorBox(Messages.errEmptyNameOnEditTableColumn);
            return;
        }
        for (DBAttribute lastAttr : lastAttrs) {
            if (StringUtil.isEqualIgnoreCase(lastAttr.getName(), newName) && attr != lastAttr) {
                CommonUITool.openErrorBox(Messages.errSameNameOnEditTableColumn);
                return;
            }
        }
        if (!StringUtil.isEqualIgnoreCase(attr.getName(), newName)) {
            replaceNewConstraintAttributeName(schemaInfo, attr.getName(), newName);
            DBAttribute newAttribute = attr.clone();
            if (newAttribute != null) {
                newAttribute.setName(newName);
            }
            if (attr != null) {
                attr.setName(newName);
            }
            if (!hasAddedToSchemaInfo(attr)) {
                attr.setName(newName);
                if (!StringUtil.isEmpty(newName)) {
                    if (!lastAttrs.contains(newAttribute)) {
                        newAttribute.setInherit(editor.getNewSchemaInfo().getClassname());
                        schemaInfo.addAttribute(newAttribute);
                        editor.removeElementByName(newName);
                    }
                    editor.addNewAttrLog(newName, newAttribute.isClassAttribute());
                    if (!StringUtil.isEmpty(newAttribute.getName())) {
                        editor.makeChangeLogForIndex(attrName, newAttribute, oldAttribute);
                    }
                }
            } else {
                editor.changeForEditElement(attrName, newAttribute, oldAttribute);
            }
        }
        DBAttribute lastDBAttribute = null;
        if (lastAttrs.size() > 0) {
            Table columnsTable = editor.getColumnsTable();
            lastDBAttribute = (DBAttribute) columnsTable.getItem(columnsTable.getItemCount() - 1).getData();
        }
        if (!StringUtil.isEmpty(newName) && (lastDBAttribute == null || !StringUtil.isEmpty(lastDBAttribute.getName()))) {
            editor.addNewColumn();
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DATATYPE)) {
        String dataTypeRaw = (String) value;
        if (dataTypeRaw != null && dataTypeRaw.trim().toLowerCase().startsWith("enum")) {
            int sp = dataTypeRaw.indexOf("(");
            if (sp != -1) {
                String dataType = dataTypeRaw.substring(0, sp).toLowerCase().trim();
                attr.setType(dataType);
                String enumeration = dataTypeRaw.substring(sp).trim();
                attr.setEnumeration(enumeration);
            }
        } else {
            attr.setType(dataTypeRaw);
        }
        if (!DataType.isIntegerType(attr.getType())) {
            attr.setAutoIncrement(null);
        }
        if (!DataType.canUseCollation(attr.getType())) {
            attr.setCollation("");
        }
        editor.changeForEditElement(attrName, attr, oldAttribute);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_DEFAULT)) {
        String defaultVal = (String) value;
        boolean isStringType = DataType.isStringType(attr.getType());
        boolean isEmpty = StringUtil.isEmpty(defaultVal);
        boolean isNull = false;
        if (defaultVal == null || DataType.NULL_EXPORT_FORMAT.equals(defaultVal) || DataType.VALUE_NULL.equals(defaultVal) || (isEmpty && !isStringType)) {
            isNull = true;
        }
        if (isNull) {
            attr.setDefault(null);
        } else {
            if (attr.getAutoIncrement() != null) {
                attr.setDefault(null);
                CommonUITool.openErrorBox(Messages.errCanNotSetDefaultOnAI);
                return;
            }
            boolean isConfirmReset = "".equals(defaultVal) && oldAttribute != null && !"".equals(oldAttribute.getDefault());
            if (isConfirmReset) {
                String confirmResetDef = Messages.confirmResetDef;
                if (CommonUITool.openConfirmBox(confirmResetDef)) {
                    attr.setDefault(null);
                } else {
                    attr.setDefault(defaultVal);
                }
            } else {
                attr.setDefault(defaultVal);
            }
        }
        editor.changeForEditElement(attrName, attr, oldAttribute);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_AUTO_INCREMENT)) {
        DBAttribute aiAttr = editor.getNewSchemaInfo().getAutoIncrementColumn();
        if (aiAttr != null && aiAttr != attr) {
            attr.setAutoIncrement(null);
            return;
        }
        String param = (String) value;
        if (StringUtil.isNotEmpty(param)) {
            if (!param.matches("\\s*[0-9]+\\s*,\\s*[0-9]+\\s*")) {
                CommonUITool.openErrorBox(Messages.errInvalidAutoIncrForm);
                return;
            }
            String defaultValue = attr.getDefault();
            if (StringUtil.isNotEmpty(defaultValue)) {
                CommonUITool.openErrorBox(Messages.errCanNotSetAIOnDefault);
                return;
            }
            String[] params = param.split(",");
            String startVal = params[0].trim();
            String incrVal = params[1].trim();
            SchemaInfo schemaInfo = editor.getNewSchemaInfo();
            SerialInfo serial = new SerialInfo();
            serial.setOwner(schemaInfo.getOwner());
            serial.setClassName(schemaInfo.getClassname());
            serial.setAttName(attrName);
            serial.setCacheCount("1");
            serial.setCurrentValue(startVal);
            serial.setCyclic(false);
            serial.setIncrementValue(incrVal);
            serial.setMaxValue(String.valueOf(Integer.MAX_VALUE));
            serial.setMinValue(startVal);
            serial.setStartedValue(startVal);
            if (attr.getAutoIncrement() != null && schemaInfo != null && schemaInfo.getAutoIncrementColumn() != null && schemaInfo.getAutoIncrementColumn().getAutoIncrement() != null) {
                String oldAI = attr.getAutoIncrement().getTableAutoIncrementString();
                String newAI = serial.getTableAutoIncrementString();
                if (StringUtil.isEqual(oldAI, newAI)) {
                    return;
                }
            }
            attr.setAutoIncrement(serial);
        } else {
            attr.setAutoIncrement(null);
        }
        editor.changeForEditElement(attrName, attr, oldAttribute);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_NOT_NULL)) {
        boolean on = ((Boolean) value).booleanValue();
        attr.setNotNull(on);
        editor.changeForEditElement(attrName, attr, oldAttribute);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_UK)) {
        boolean on = ((Boolean) value).booleanValue();
        if (on && attr.isShared()) {
            CommonUITool.openErrorBox(Messages.errCanNotUseUkAndSharedOnce);
            return;
        }
        attr.setUnique(on);
        editor.changeForEditElement(attrName, attr, oldAttribute);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_SHARED)) {
        boolean on = ((Boolean) value).booleanValue();
        String defaultValue = attr.getDefault();
        if (on && StringUtil.isEmpty(defaultValue)) {
            CommonUITool.openErrorBox(Messages.msgInputSharedValue);
            return;
        }
        if (on && attr.isUnique()) {
            CommonUITool.openErrorBox(Messages.errCanNotUseUkAndSharedOnce);
            return;
        }
        attr.setShared(on);
        editor.changeForEditElement(attrName, attr, oldAttribute);
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_COLLATION)) {
        String orignCollation = attr.getCollation();
        Integer selection = StringUtil.intValue(value.toString(), 0);
        if (selection > -1) {
            String newCollation = editor.getCollationArray()[selection];
            if (!StringUtil.isEqualNotIgnoreNull(orignCollation, newCollation)) {
                attr.setCollation(newCollation);
            }
        }
    } else if (StringUtil.isEqual(property, IAttributeColumn.COL_MEMO)) {
        attr.setDescription((String) value);
    }
    editor.loadColumnData();
}
Also used : Table(org.eclipse.swt.widgets.Table) Constraint(com.cubrid.common.core.common.model.Constraint) TableItem(org.eclipse.swt.widgets.TableItem) Constraint(com.cubrid.common.core.common.model.Constraint) DBAttribute(com.cubrid.common.core.common.model.DBAttribute) List(java.util.List) SerialInfo(com.cubrid.common.core.common.model.SerialInfo) SchemaInfo(com.cubrid.common.core.common.model.SchemaInfo)

Example 84 with Table

use of org.eclipse.swt.widgets.Table in project cubrid-manager by CUBRID.

the class TableEditorPart method createPartitionTabItem.

private void createPartitionTabItem(final TabFolder tabFolder) {
    loadPartitionInfoList();
    final TabItem partTabItem = new TabItem(tabFolder, SWT.NONE);
    final Composite parentComp = new Composite(tabFolder, SWT.NONE);
    {
        GridLayout gd = new GridLayout();
        parentComp.setLayout(gd);
    }
    partTabItem.setControl(parentComp);
    partTabItem.setText(Messages.tabItemPartition);
    partitionTableView = new TableViewer(parentComp, SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    final Table partitionTable = partitionTableView.getTable();
    {
        partitionTable.setLayout(TableViewUtil.createTableViewLayout(new int[] { 20, 15, 10, 20, 25, 10 }));
        GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
        gd.heightHint = 350;
        partitionTable.setLayoutData(gd);
    }
    partitionTable.setHeaderVisible(true);
    partitionTable.setLinesVisible(true);
    CommonUITool.hackForYosemite(partitionTable);
    TableViewUtil.createTableColumn(partitionTable, SWT.CENTER, Messages.tblColTableName);
    TableViewUtil.createTableColumn(partitionTable, SWT.CENTER, Messages.tblColPartitionName);
    TableViewUtil.createTableColumn(partitionTable, SWT.CENTER, Messages.tblColType);
    TableViewUtil.createTableColumn(partitionTable, SWT.CENTER, Messages.tblColExpr);
    TableViewUtil.createTableColumn(partitionTable, SWT.CENTER, Messages.tblColExprValue);
    TableViewUtil.createTableColumn(partitionTable, SWT.CENTER, Messages.tblColRows);
    partitionTableView.setLabelProvider(new PartitionTableLabelProvider());
    partitionTableView.setContentProvider(new PartitionContentProvider());
    partitionTableView.setInput(partitionInfoList);
    partitionTableView.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            editPartition();
        }
    });
    tabFolder.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            if (tabFolder.getSelection()[0].getText().equals(Messages.tabItemPartition)) {
                partitionTableView.refresh();
            }
        }
    });
    createPartitionTabButtons(parentComp);
}
Also used : PartitionContentProvider(com.cubrid.common.ui.cubrid.table.control.PartitionContentProvider) TabItem(org.eclipse.swt.widgets.TabItem) PartitionTableLabelProvider(com.cubrid.common.ui.cubrid.table.control.PartitionTableLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 85 with Table

use of org.eclipse.swt.widgets.Table in project cubrid-manager by CUBRID.

the class TableEditorPart method createPartitionTabButtons.

/**
	 * Create Partition tab buttons
	 *
	 * @param parent Composite
	 */
private void createPartitionTabButtons(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);
    {
        GridLayout gl = new GridLayout();
        gl.numColumns = 5;
        composite.setLayout(gl);
        composite.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
    }
    addPartitionBtn = new Button(composite, SWT.PUSH);
    {
        GridData gd = new GridData(SWT.NONE);
        gd.horizontalIndent = 10;
        addPartitionBtn.setLayoutData(gd);
    }
    addPartitionBtn.setText(Messages.btnAddPartition);
    addPartitionBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            String tableName = tableNameText.getText();
            if (tableName.trim().length() == 0) {
                CommonUITool.openErrorBox(getSite().getShell(), Messages.msgNoTableName);
                return;
            }
            newSchemaInfo.setClassname(tableName);
            Wizard wizard = new CreatePartitionWizard(database.getDatabaseInfo(), newSchemaInfo, partitionInfoList, isNewTableFlag, null);
            CMWizardDialog dialog = new CMWizardDialog(getSite().getShell(), wizard);
            dialog.setPageSize(600, 400);
            if (dialog.open() != IDialogConstants.OK_ID) {
                return;
            }
            partitionTableView.refresh();
            changePartitionTabButtonStatus();
        }
    });
    editPartitionBtn = new Button(composite, SWT.PUSH);
    {
        GridData gd = new GridData(SWT.NONE);
        gd.horizontalIndent = 10;
        editPartitionBtn.setLayoutData(gd);
    }
    editPartitionBtn.setText(Messages.btnEditPartition);
    editPartitionBtn.setEnabled(false);
    editPartitionBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            editPartition();
        }
    });
    delPartitionBtn = new Button(composite, SWT.PUSH);
    {
        GridData gd = new GridData(SWT.NONE);
        gd.horizontalIndent = 10;
        delPartitionBtn.setLayoutData(gd);
    }
    delPartitionBtn.setText(Messages.btnDelPartition);
    delPartitionBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            String confirmMsg = Messages.msgDelPartition;
            if (getPartitonType() == PartitionType.HASH) {
                confirmMsg = Messages.msgDelHashPartition;
            }
            boolean deleteConfirm = CommonUITool.openConfirmBox(getSite().getShell(), confirmMsg);
            if (!deleteConfirm) {
                return;
            }
            if (getPartitonType() == PartitionType.HASH) {
                partitionInfoList.clear();
            } else {
                IStructuredSelection selection = (IStructuredSelection) partitionTableView.getSelection();
                if (selection == null || selection.isEmpty()) {
                    return;
                }
                partitionInfoList.removeAll(selection.toList());
                if (getPartitonType() == PartitionType.RANGE) {
                    CreatePartitionWizard.resetRangePartitionInfoList(partitionInfoList);
                }
            }
            partitionTableView.refresh();
            changePartitionTabButtonStatus();
        }
    });
    final Table partitionTable = partitionTableView.getTable();
    partitionTable.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            changePartitionTabButtonStatus();
        }
    });
    changePartitionTabButtonStatus();
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) CreatePartitionWizard(com.cubrid.common.ui.cubrid.table.control.CreatePartitionWizard) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Wizard(org.eclipse.jface.wizard.Wizard) CreatePartitionWizard(com.cubrid.common.ui.cubrid.table.control.CreatePartitionWizard) CMWizardDialog(com.cubrid.common.ui.spi.dialog.CMWizardDialog)

Aggregations

Table (org.eclipse.swt.widgets.Table)770 GridData (org.eclipse.swt.layout.GridData)368 Composite (org.eclipse.swt.widgets.Composite)325 TableColumn (org.eclipse.swt.widgets.TableColumn)324 TableViewer (org.eclipse.jface.viewers.TableViewer)303 GridLayout (org.eclipse.swt.layout.GridLayout)255 TableItem (org.eclipse.swt.widgets.TableItem)210 SelectionEvent (org.eclipse.swt.events.SelectionEvent)204 Label (org.eclipse.swt.widgets.Label)179 Button (org.eclipse.swt.widgets.Button)161 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)145 Point (org.eclipse.swt.graphics.Point)138 Text (org.eclipse.swt.widgets.Text)102 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)96 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)95 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)89 FillLayout (org.eclipse.swt.layout.FillLayout)87 Shell (org.eclipse.swt.widgets.Shell)82 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)81 Event (org.eclipse.swt.widgets.Event)80