Search in sources :

Example 46 with CellEditor

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

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

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

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

the class BrokerParameterDialog method linkEditorForTable.

/**
	 * Makes a certain column of table can be edited
	 */
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 ParameterCellModifier());
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 50 with CellEditor

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

the class UserAuthDbInfoPage method setCellEditors.

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

Aggregations

CellEditor (org.eclipse.jface.viewers.CellEditor)72 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)47 ICellModifier (org.eclipse.jface.viewers.ICellModifier)21 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 GridData (org.eclipse.swt.layout.GridData)21 Composite (org.eclipse.swt.widgets.Composite)19 ComboBoxCellEditor (org.eclipse.jface.viewers.ComboBoxCellEditor)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 Map (java.util.Map)16 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)16 HashMap (java.util.HashMap)14 TableViewer (org.eclipse.jface.viewers.TableViewer)14 Label (org.eclipse.swt.widgets.Label)14 Item (org.eclipse.swt.widgets.Item)12 Button (org.eclipse.swt.widgets.Button)11 TableItem (org.eclipse.swt.widgets.TableItem)11 Text (org.eclipse.swt.widgets.Text)9 ArrayList (java.util.ArrayList)8 SelectionListener (org.eclipse.swt.events.SelectionListener)8 Group (org.eclipse.swt.widgets.Group)8