Search in sources :

Example 11 with ICellModifier

use of org.eclipse.jface.viewers.ICellModifier 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 12 with ICellModifier

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

the class CopyDatabaseDialog method createCopyTable.

/**
	 * Create Copy Button and CopyList
	 * 
	 * @param composite the parent composite
	 */
private void createCopyTable(Composite composite) {
    copyVolButton = new Button(composite, SWT.CHECK);
    copyVolButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    copyVolButton.setEnabled(false);
    copyVolButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent event) {
            if (copyVolButton.getSelection()) {
                copyDBVolList.setEnabled(true);
                destinationDBDirPathText.setEnabled(false);
                volumePathText.setEnabled(false);
                if (isLocalServer) {
                    dbDirPathButton.setEnabled(false);
                    dbExtPathButton.setEnabled(false);
                }
            } else {
                copyDBVolList.setEnabled(false);
                copyDBVolList.setSelection(-1);
                destinationDBDirPathText.setEnabled(true);
                volumePathText.setEnabled(true);
                if (isLocalServer) {
                    dbDirPathButton.setEnabled(true);
                    dbExtPathButton.setEnabled(true);
                }
            }
            if (validateText()) {
                setErrorMessage(null);
                getButton(IDialogConstants.OK_ID).setEnabled(true);
            } else {
                getButton(IDialogConstants.OK_ID).setEnabled(false);
            }
        }
    });
    copyVolButton.setText(Messages.btnCopyVolume);
    final String[] columnNameArr = new String[] { Messages.tblColumnCurrentVolName, Messages.tblColumnCopyNewVolName, Messages.tblColumnCopyNewDirPath };
    volumeTableViewer = CommonUITool.createCommonTableViewer(composite, null, columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    copyDBVolList = volumeTableViewer.getTable();
    copyDBVolList.setEnabled(false);
    volumeTableViewer.setColumnProperties(columnNameArr);
    CommonUITool.hackForYosemite(volumeTableViewer.getTable());
    CellEditor[] editors = new CellEditor[3];
    editors[0] = null;
    editors[1] = new TextCellEditor(copyDBVolList);
    editors[2] = new TextCellEditor(copyDBVolList);
    volumeTableViewer.setCellEditors(editors);
    volumeTableViewer.setCellModifier(new ICellModifier() {

        @SuppressWarnings("unchecked")
        public boolean canModify(Object element, String property) {
            Map<String, String> map = (Map<String, String>) element;
            String name = map.get("0");
            if (name.equals(database.getName()) && (property.equals(columnNameArr[0]) || property.equals(columnNameArr[1]))) {
                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[1])) {
                return map.get("1");
            } else if (property.equals(columnNameArr[2])) {
                return map.get("2");
            }
            return null;
        }

        @SuppressWarnings("unchecked")
        public void modify(Object element, String property, Object value) {
            Object obj = null;
            if (element instanceof Item) {
                obj = ((Item) element).getData();
            }
            if (obj == null) {
                return;
            }
            Map<String, String> map = (Map<String, String>) obj;
            if (property.equals(columnNameArr[1])) {
                if (ValidateUtil.isValidDBName(value.toString())) {
                    map.put("1", value.toString());
                } else {
                    CommonUITool.openErrorBox(getShell(), Messages.errCopyDbName);
                }
            } else if (property.equals(columnNameArr[2])) {
                if (ValidateUtil.isValidPathName(value.toString())) {
                    map.put("2", value.toString());
                } else {
                    CommonUITool.openErrorBox(getShell(), Messages.errCopyName);
                }
            }
            isIndividChanged = true;
            volumeTableViewer.refresh();
        }
    });
    overwriteButton = new Button(composite, SWT.CHECK);
    overwriteButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
    overwriteButton.setText(Messages.btnReplaceDb);
    moveButton = new Button(composite, SWT.CHECK);
    moveButton.setText(Messages.btnDeleteSrcDb);
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Item(org.eclipse.swt.widgets.Item) TableItem(org.eclipse.swt.widgets.TableItem) Button(org.eclipse.swt.widgets.Button) 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)

Example 13 with ICellModifier

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

the class SettingCubridHAConfPage method createControl.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new FormLayout());
    setControl(container);
    setDescription(Messages.descSettingCubridHAPage);
    Composite leftComposite = new Composite(container, SWT.NONE);
    leftComposite.setLayout(new GridLayout(4, 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(50, -5);
    leftComposite.setLayoutData(leftData);
    Label separator = new Label(container, SWT.SEPARATOR);
    FormData separatorData = new FormData();
    separatorData.top = new FormAttachment(0, 5);
    separatorData.bottom = new FormAttachment(100, -5);
    separatorData.left = new FormAttachment(50, -5);
    separatorData.right = new FormAttachment(50, 5);
    separator.setLayoutData(separatorData);
    Composite rightComposite = new Composite(container, SWT.NONE);
    rightComposite.setLayout(new GridLayout(4, false));
    FormData rightData = new FormData();
    rightData.top = new FormAttachment(0, 5);
    rightData.bottom = new FormAttachment(100, 0);
    rightData.left = new FormAttachment(50, 5);
    rightData.right = new FormAttachment(100, -5);
    rightComposite.setLayoutData(rightData);
    /*Create left widget*/
    Label hostALabel = new Label(leftComposite, SWT.None);
    hostALabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    hostALabel.setText(Messages.lblMaster);
    masterHostLabel = new Label(leftComposite, SWT.None);
    masterHostLabel.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
    masterViewer = new TableViewer(leftComposite, SWT.BORDER | SWT.FULL_SELECTION);
    masterViewer.getTable().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 4, 1, -1, -1));
    masterViewer.getTable().setLinesVisible(true);
    masterViewer.getTable().setHeaderVisible(true);
    masterViewer.setContentProvider(new TableContentProvider());
    masterViewer.setLabelProvider(new CubridConfTableProvider());
    masterViewer.setColumnProperties(PROPS);
    CellEditor[] editors = new CellEditor[2];
    editors[0] = null;
    editors[1] = new TextCellEditor(masterViewer.getTable());
    masterViewer.setCellEditors(editors);
    masterViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            if (property.equals(PROPS[1])) {
                return true;
            }
            return false;
        }

        public Object getValue(Object element, String property) {
            DataModel model = (DataModel) element;
            if (property.equals(PROPS[0])) {
                return model.getKey() == null ? "" : model.getKey();
            } else if (property.equals(PROPS[1])) {
                return model.getValue() == null ? "" : model.getValue();
            }
            return "";
        }

        public void modify(Object element, String property, Object value) {
            TableItem item = (TableItem) element;
            DataModel model = (DataModel) item.getData();
            model.setValue(value.toString());
            masterViewer.refresh(model);
            updateHAModel(masterViewer, model, false);
        }
    });
    TableColumn keyAColumn = new TableColumn(masterViewer.getTable(), SWT.LEFT);
    keyAColumn.setText(Messages.lblKey);
    keyAColumn.setWidth(160);
    TableColumn valueAColumn = new TableColumn(masterViewer.getTable(), SWT.LEFT);
    valueAColumn.setText(Messages.lblValue);
    valueAColumn.setWidth(200);
    Label masterUserLabel = new Label(leftComposite, SWT.None);
    masterUserLabel.setText(Messages.lblUser);
    masterUserLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    masterUserCombo = new Combo(leftComposite, SWT.BORDER | SWT.READ_ONLY);
    masterUserCombo.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    masterUserCombo.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            initMasterTableData();
        }
    });
    ToolBar toolBarA = new ToolBar(leftComposite, SWT.None);
    toolBarA.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_END, 2, 1, -1, -1));
    ToolItem addItemA = new ToolItem(toolBarA, SWT.None);
    addItemA.setToolTipText(Messages.itemAddParameter);
    addItemA.setImage(CubridManagerUIPlugin.getImage("/icons/replication/add_param.gif"));
    addItemA.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            addParameter(masterViewer);
        }
    });
    ToolItem editItemA = new ToolItem(toolBarA, SWT.None);
    editItemA.setToolTipText(Messages.itemEditParameter);
    editItemA.setImage(CubridManagerUIPlugin.getImage("/icons/replication/edit_param.gif"));
    editItemA.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            editParameter(masterViewer);
        }
    });
    ToolItem dropItemA = new ToolItem(toolBarA, SWT.None);
    dropItemA.setToolTipText(Messages.itemDeleteParameter);
    dropItemA.setImage(CubridManagerUIPlugin.getImage("/icons/replication/delete_param.gif"));
    dropItemA.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            dropParameter(masterViewer);
        }
    });
    /*Create right widget*/
    Label hostBLabel = new Label(rightComposite, SWT.None);
    hostBLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    hostBLabel.setText(Messages.lblSlave);
    slaveHostLabel = new Label(rightComposite, SWT.None);
    slaveHostLabel.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
    slaveViewer = new TableViewer(rightComposite, SWT.BORDER | SWT.FULL_SELECTION);
    slaveViewer.getTable().setLayoutData(CommonUITool.createGridData(GridData.FILL_BOTH, 4, 1, -1, -1));
    slaveViewer.getTable().setLinesVisible(true);
    slaveViewer.getTable().setHeaderVisible(true);
    slaveViewer.setContentProvider(new TableContentProvider());
    slaveViewer.setLabelProvider(new CubridConfTableProvider());
    slaveViewer.setColumnProperties(PROPS);
    CellEditor[] editorsB = new CellEditor[2];
    editorsB[0] = null;
    editorsB[1] = new TextCellEditor(slaveViewer.getTable());
    slaveViewer.setCellEditors(editorsB);
    slaveViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            if (property.equals(PROPS[1])) {
                return true;
            }
            return false;
        }

        public Object getValue(Object element, String property) {
            DataModel model = (DataModel) element;
            if (property.equals(PROPS[0])) {
                return model.getKey() == null ? "" : model.getKey();
            } else if (property.equals(PROPS[1])) {
                return model.getValue() == null ? "" : model.getValue();
            }
            return "";
        }

        public void modify(Object element, String property, Object value) {
            TableItem item = (TableItem) element;
            DataModel model = (DataModel) item.getData();
            model.setValue(value.toString());
            slaveViewer.refresh(model);
            updateHAModel(slaveViewer, model, false);
        }
    });
    TableColumn keyBColumn = new TableColumn(slaveViewer.getTable(), SWT.LEFT);
    keyBColumn.setText(Messages.lblKey);
    keyBColumn.setWidth(160);
    TableColumn valueBColumn = new TableColumn(slaveViewer.getTable(), SWT.LEFT);
    valueBColumn.setText(Messages.lblValue);
    valueBColumn.setWidth(200);
    Label slaveUserLabel = new Label(rightComposite, SWT.None);
    slaveUserLabel.setText(Messages.lblUser);
    slaveUserLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    slaveUserCombo = new Combo(rightComposite, SWT.BORDER | SWT.READ_ONLY);
    slaveUserCombo.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    slaveUserCombo.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            initSlaveTableData();
        }
    });
    ToolBar toolBarB = new ToolBar(rightComposite, SWT.None);
    toolBarB.setLayoutData(CommonUITool.createGridData(GridData.HORIZONTAL_ALIGN_END, 2, 1, -1, -1));
    ToolItem addItemB = new ToolItem(toolBarB, SWT.None);
    addItemB.setToolTipText(Messages.itemAddParameter);
    addItemB.setImage(CubridManagerUIPlugin.getImage("/icons/replication/add_param.gif"));
    addItemB.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            addParameter(slaveViewer);
        }
    });
    ToolItem editItemB = new ToolItem(toolBarB, SWT.None);
    editItemB.setToolTipText(Messages.itemEditParameter);
    editItemB.setImage(CubridManagerUIPlugin.getImage("/icons/replication/edit_param.gif"));
    editItemB.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            editParameter(slaveViewer);
        }
    });
    ToolItem dropItemB = new ToolItem(toolBarB, SWT.None);
    dropItemB.setToolTipText(Messages.itemDeleteParameter);
    dropItemB.setImage(CubridManagerUIPlugin.getImage("/icons/replication/delete_param.gif"));
    dropItemB.addSelectionListener(new SelectionListener() {

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

        public void widgetDefaultSelected(SelectionEvent e) {
            dropParameter(slaveViewer);
        }
    });
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) Composite(org.eclipse.swt.widgets.Composite) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableItem(org.eclipse.swt.widgets.TableItem) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) TableContentProvider(com.cubrid.common.ui.spi.TableContentProvider) ICellModifier(org.eclipse.jface.viewers.ICellModifier) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ToolBar(org.eclipse.swt.widgets.ToolBar) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) FormAttachment(org.eclipse.swt.layout.FormAttachment) ToolItem(org.eclipse.swt.widgets.ToolItem) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 14 with ICellModifier

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

the class ShardBrokerPropertiesPanel method linkEditorForTable.

/**
	 * Links the editable column of table
	 */
private void linkEditorForTable() {
    paraTableViewer.setColumnProperties(columnNameArrs);
    CellEditor[] editors = new CellEditor[3];
    editors[0] = null;
    editors[1] = null;
    editors[2] = new TextCellEditor(paraTable);
    paraTableViewer.setCellEditors(editors);
    paraTableViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) element;
            String para = map.get("0");
            if (property.equals(columnNameArrs[2]) && (!CubridShardConfParaConstants.SHARD_CONNECTION_FILE.equals(para) && !CubridShardConfParaConstants.SHARD_KEY_FILE.equals(para) && !CubridShardConfParaConstants.APPL_SERVER_SHM_ID.equals(para))) {
                return true;
            }
            return false;
        }

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

        @SuppressWarnings("unchecked")
        public void modify(Object element, String property, Object value) {
            Object obj = null;
            if (element instanceof Item) {
                obj = ((Item) element).getData();
            }
            if (obj == null) {
                return;
            }
            Map<String, String> map = (Map<String, String>) obj;
            String paramName = map.get("0");
            String type = map.get("1");
            boolean isValid = true;
            String valueStr = value.toString().trim();
            if (!StringUtil.isEmpty(valueStr)) {
                if (type.indexOf("int") >= 0) {
                    if (!ValidateUtil.isInteger(value.toString())) {
                        isValid = false;
                    } else {
                        int intValue = Integer.parseInt(value.toString());
                        int start = type.indexOf("(");
                        int end = type.indexOf(")");
                        if (start > 0) {
                            String valueRange = type.substring(start + 1, end);
                            String[] values = valueRange.split("~");
                            int min = Integer.parseInt(values[0]);
                            int max = Integer.parseInt(values[1]);
                            if (intValue < min || intValue > max || intValue < 1) {
                                isValid = false;
                            }
                        }
                    }
                } else if (type.startsWith("string")) {
                    int start = type.indexOf("(");
                    int end = type.indexOf(")");
                    if (start > 0) {
                        String valueStrs = type.substring(start + 1, end);
                        String[] values = valueStrs.split("\\|");
                        boolean isExist = false;
                        for (String val : values) {
                            if (valueStr.equals(val)) {
                                isExist = true;
                                break;
                            }
                        }
                        if (!isExist) {
                            isValid = false;
                        }
                    }
                }
                if (!isValid) {
                    CommonUITool.openErrorBox(Messages.bind(Messages.errParameterValue, new Object[] { paramName }));
                }
                if (isValid && paramName.equalsIgnoreCase(CubridShardConfParaConstants.MIN_NUM_APPL_SERVER)) {
                    int intValue = Integer.parseInt(value.toString());
                    Map<String, String> dataMap = parameterList.get(9);
                    String maxNumApplServer = dataMap.get("2");
                    if (maxNumApplServer.trim().length() > 0 && intValue > Integer.parseInt(maxNumApplServer.trim())) {
                        isValid = false;
                        CommonUITool.openErrorBox(Messages.bind(Messages.errMinNumApplServerValue, new Object[] { paramName }));
                    }
                }
                if (isValid && paramName.equalsIgnoreCase(CubridShardConfParaConstants.MAX_NUM_APPL_SERVER)) {
                    int intValue = Integer.parseInt(value.toString());
                    Map<String, String> dataMap = parameterList.get(10);
                    String minNumApplServer = dataMap.get("2");
                    if (minNumApplServer.trim().length() > 0 && intValue < Integer.parseInt(minNumApplServer.trim())) {
                        isValid = false;
                        CommonUITool.openErrorBox(Messages.bind(Messages.errMaxNumApplServeValue, new Object[] { paramName }));
                    }
                }
                if (isValid && paramName.equalsIgnoreCase(CubridShardConfParaConstants.BROKER_PORT)) {
                    Map<String, String> dataMap = parameterList.get(8);
                    String metadataShmId = dataMap.get("2");
                    if (valueStr.equals(metadataShmId)) {
                        isValid = false;
                        CommonUITool.openErrorBox(Messages.bind(Messages.errShmIdExist, new Object[] { paramName }));
                    }
                    dataMap = parameterList.get(7);
                    dataMap.put("2", value.toString());
                }
                if (isValid && paramName.equalsIgnoreCase(CubridShardConfParaConstants.METADATA_SHM_ID)) {
                    Map<String, String> dataMap = parameterList.get(7);
                    String metadataShmId = dataMap.get("2");
                    if (valueStr.equals(metadataShmId)) {
                        isValid = false;
                        CommonUITool.openErrorBox(Messages.bind(Messages.errShmIdExist, new Object[] { paramName }));
                    }
                }
            }
            if (isValid) {
                map.put("2", value.toString());
            }
            paraTableViewer.refresh();
            // Notice the upper layer
            modifyListener.modifyText(null);
        }
    });
}
Also used : Item(org.eclipse.swt.widgets.Item) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with ICellModifier

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

the class ShardKeysPanel method linkEditorForKeyListTable.

/**
	 * Links the editable column of table
	 */
private void linkEditorForKeyListTable() {
    keyListTableViewer.setColumnProperties(keyListColumnNameArrs);
    CellEditor[] editors = new CellEditor[3];
    editors[0] = new TextCellEditor(keyListTable);
    keyListTableViewer.setCellEditors(editors);
    keyListTableViewer.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;
            return map.get("0");
        }

        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())) {
                for (Map<String, String> paras : keyList) {
                    if (paras == obj) {
                        continue;
                    }
                    if (paras.get("0").equals(value)) {
                        isValid = false;
                        CommonUITool.openErrorBox(Messages.bind(Messages.errShardKeyNameExist, new Object[] { value.toString() }));
                        break;
                    }
                }
            }
            if (isValid) {
                map.put("0", value.toString());
                currentShardKey.setName(value.toString());
                keyInfoGroup.setText("Key Info: " + value);
            }
            keyListTableViewer.refresh();
            // 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) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ICellModifier (org.eclipse.jface.viewers.ICellModifier)23 CellEditor (org.eclipse.jface.viewers.CellEditor)21 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)21 Item (org.eclipse.swt.widgets.Item)13 GridData (org.eclipse.swt.layout.GridData)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 Composite (org.eclipse.swt.widgets.Composite)10 TableItem (org.eclipse.swt.widgets.TableItem)10 GridLayout (org.eclipse.swt.layout.GridLayout)8 TableViewer (org.eclipse.jface.viewers.TableViewer)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 Label (org.eclipse.swt.widgets.Label)6 TableColumn (org.eclipse.swt.widgets.TableColumn)6 TreeViewer (org.eclipse.jface.viewers.TreeViewer)5 ToolItem (org.eclipse.swt.widgets.ToolItem)5 TreeColumn (org.eclipse.swt.widgets.TreeColumn)5 TreeItem (org.eclipse.swt.widgets.TreeItem)5 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)4 SelectionListener (org.eclipse.swt.events.SelectionListener)4