Search in sources :

Example 21 with Item

use of org.eclipse.swt.widgets.Item 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 22 with Item

use of org.eclipse.swt.widgets.Item 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 23 with Item

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

the class ShardConnectionPanel method addNewItem.

/**
	 * add a new item into table result
	 * 
	 * @return a new added TableItem
	 */
private void addNewItem() {
    /* Get Max index */
    int maxIndex = -1;
    Item[] allItems = connectionTable.getItems();
    for (Item it : allItems) {
        if (it.getText() != null) {
            int index = StringUtil.intValue(it.getText(), -1);
            if (index > maxIndex) {
                maxIndex = index;
            }
        }
    }
    maxIndex++;
    Map<String, String> dataMap = new HashMap<String, String>();
    dataMap.put("0", String.valueOf(maxIndex));
    dataMap.put("1", "");
    dataMap.put("2", "");
    parameterList.add(dataMap);
    connectionTableViewer.refresh();
    setTableColor();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ToolItem(org.eclipse.swt.widgets.ToolItem) Item(org.eclipse.swt.widgets.Item) HashMap(java.util.HashMap)

Example 24 with Item

use of org.eclipse.swt.widgets.Item 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 25 with Item

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

the class ShardKeysPanel method linkEditorForKeyInfoTable.

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

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

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

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

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

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

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

Aggregations

Item (org.eclipse.swt.widgets.Item)38 TableItem (org.eclipse.swt.widgets.TableItem)20 HashMap (java.util.HashMap)16 Map (java.util.Map)14 ICellModifier (org.eclipse.jface.viewers.ICellModifier)13 CellEditor (org.eclipse.jface.viewers.CellEditor)12 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)11 GridData (org.eclipse.swt.layout.GridData)11 Tree (org.eclipse.swt.widgets.Tree)10 TreeItem (org.eclipse.swt.widgets.TreeItem)9 Point (org.eclipse.swt.graphics.Point)8 GridLayout (org.eclipse.swt.layout.GridLayout)8 Button (org.eclipse.swt.widgets.Button)8 Table (org.eclipse.swt.widgets.Table)8 ArrayList (java.util.ArrayList)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 Composite (org.eclipse.swt.widgets.Composite)7 Widget (org.eclipse.swt.widgets.Widget)7 LinkDescriptor (org.talend.commons.ui.swt.drawing.link.LinkDescriptor)7 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)6