Search in sources :

Example 26 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 27 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 28 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)

Example 29 with ICellModifier

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

Example 30 with ICellModifier

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

the class RenameDatabaseDialog method createNewDatabaseInfoComp.

/**
	 * 
	 * Create database name group
	 * 
	 * @param parent the parent composite
	 */
private void createNewDatabaseInfoComp(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    comp.setLayoutData(gridData);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    comp.setLayout(layout);
    Label databaseNameLabel = new Label(comp, SWT.LEFT | SWT.WRAP);
    databaseNameLabel.setText(Messages.lblNewDbName);
    gridData = new GridData();
    gridData.widthHint = 150;
    databaseNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    databaseNameText = new Text(comp, SWT.BORDER);
    databaseNameText.setTextLimit(ValidateUtil.MAX_DB_NAME_LENGTH);
    databaseNameText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 2, 1, -1, -1));
    exVolumePathButton = new Button(comp, SWT.LEFT | SWT.RADIO);
    exVolumePathButton.setText(Messages.btnExtendedVolumePath);
    exVolumePathButton.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1));
    exVolumePathButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (exVolumePathButton.getSelection()) {
                exVolumePathText.setEditable(true);
                renameVolumeButton.setSelection(false);
                volumeTable.setEnabled(false);
                if (selectVolumeDirectoryButton != null) {
                    ServerInfo serverInfo = database.getServer().getServerInfo();
                    selectVolumeDirectoryButton.setEnabled(serverInfo != null && serverInfo.isLocalServer());
                }
            } else {
                exVolumePathText.setEditable(false);
                volumeTable.setEnabled(true);
                if (selectVolumeDirectoryButton != null) {
                    selectVolumeDirectoryButton.setEnabled(false);
                }
            }
        }
    });
    exVolumePathButton.setSelection(true);
    boolean isLocalServer = database.getServer().getServerInfo().isLocalServer();
    exVolumePathText = new Text(comp, SWT.BORDER);
    exVolumePathText.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, isLocalServer ? 1 : 2, 1, -1, -1));
    if (isLocalServer) {
        selectVolumeDirectoryButton = new Button(comp, SWT.NONE);
        selectVolumeDirectoryButton.setText(Messages.btnBrowse);
        selectVolumeDirectoryButton.setLayoutData(CommonUITool.createGridData(1, 1, 80, -1));
        selectVolumeDirectoryButton.addSelectionListener(new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
                String text = exVolumePathText.getText();
                if (text == null || text.trim().length() == 0) {
                    text = CubridManagerUIPlugin.getPluginDialogSettings().get(KEY_EXTENDED_VOLUME_PATH + database.getId());
                }
                if (text == null || text.trim().length() == 0) {
                    text = extVolumePath;
                }
                DirectoryDialog dlg = new DirectoryDialog(getShell());
                if (text != null) {
                    dlg.setFilterPath(text);
                }
                dlg.setText(Messages.msgSelectDir);
                dlg.setMessage(Messages.msgSelectDir);
                String dir = dlg.open();
                if (dir != null) {
                    exVolumePathText.setText(dir);
                    CubridManagerUIPlugin.getPluginDialogSettings().put(KEY_EXTENDED_VOLUME_PATH + database.getId(), dir);
                }
            }
        });
        selectVolumeDirectoryButton.setEnabled(true);
    }
    renameVolumeButton = new Button(comp, SWT.LEFT | SWT.RADIO);
    renameVolumeButton.setText(Messages.btnRenameIndiVolume);
    renameVolumeButton.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
    renameVolumeButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            if (renameVolumeButton.getSelection()) {
                volumeTable.setEnabled(true);
            } else {
                volumeTable.setEnabled(false);
            }
        }
    });
    final String[] columnNameArr = new String[] { Messages.tblColumnCurrVolName, Messages.tblColumnNewVolName, Messages.tblColumnCurrDirPath, Messages.tblColumnNewDirPath };
    volumeTableViewer = CommonUITool.createCommonTableViewer(comp, new TableViewerSorter(), columnNameArr, CommonUITool.createGridData(GridData.FILL_BOTH, 3, 1, -1, 200));
    volumeTable = volumeTableViewer.getTable();
    volumeTable.setEnabled(false);
    volumeTableViewer.setColumnProperties(columnNameArr);
    CellEditor[] editors = new CellEditor[4];
    editors[0] = null;
    editors[1] = new TextCellEditor(volumeTable);
    editors[2] = null;
    editors[3] = new TextCellEditor(volumeTable);
    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 (property.equals(columnNameArr[0]) || property.equals(columnNameArr[2])) {
                return false;
            } else if (property.equals(columnNameArr[1]) && name.equals(database.getName())) {
                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[3])) {
                return map.get("3");
            }
            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])) {
                map.put("1", value.toString());
            } else if (property.equals(columnNameArr[3])) {
                map.put("3", value.toString());
            }
            volumeTableViewer.refresh();
        }
    });
    forceDelBackupVolumeButton = new Button(comp, SWT.LEFT | SWT.CHECK);
    forceDelBackupVolumeButton.setText(Messages.btnForceDelBackupVolume);
    forceDelBackupVolumeButton.setLayoutData(CommonUITool.createGridData(GridData.FILL_HORIZONTAL, 3, 1, -1, -1));
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ServerInfo(com.cubrid.cubridmanager.core.common.model.ServerInfo) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Item(org.eclipse.swt.widgets.Item) GridLayout(org.eclipse.swt.layout.GridLayout) TableViewerSorter(com.cubrid.common.ui.spi.TableViewerSorter) 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) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

ICellModifier (org.eclipse.jface.viewers.ICellModifier)45 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)42 CellEditor (org.eclipse.jface.viewers.CellEditor)30 GridData (org.eclipse.swt.layout.GridData)29 Composite (org.eclipse.swt.widgets.Composite)26 TableItem (org.eclipse.swt.widgets.TableItem)26 GridLayout (org.eclipse.swt.layout.GridLayout)23 TableViewer (org.eclipse.jface.viewers.TableViewer)22 TableColumn (org.eclipse.swt.widgets.TableColumn)20 SelectionEvent (org.eclipse.swt.events.SelectionEvent)18 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)17 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)17 Item (org.eclipse.swt.widgets.Item)16 SelectionListener (org.eclipse.swt.events.SelectionListener)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)10 Button (org.eclipse.swt.widgets.Button)9 Label (org.eclipse.swt.widgets.Label)9 Table (org.eclipse.swt.widgets.Table)9