Search in sources :

Example 1 with CubridConfProperty

use of com.cubrid.cubridmanager.ui.host.model.CubridConfProperty in project cubrid-manager by CUBRID.

the class UnifyHostConfigEditor method addCubridConfColumn.

/**
	 * addCubridConfColumn
	 */
public void addCubridConfColumn() {
    editorInput.setCubridConfPropertyCount(cubridConfTabTableViewer.getTable().getColumnCount());
    LinkedHashMap<String, CubridConfConfig> cubridConfMap = unifyHostConfigUtil.parseCommonTableValueToCubridConfConfig(cubridConfConfigListData, editorInput.getCubridConfPropertyCount());
    Point pt = cubridConfTableClickPoint;
    int selectIndex = cubridConfTabTableViewer.getTable().getSelectionIndex();
    if (selectIndex < 0) {
        return;
    }
    final TableItem item = cubridConfTabTableViewer.getTable().getItem(selectIndex);
    if (item == null) {
        return;
    }
    for (int i = 0; i < cubridConfTabTableViewer.getTable().getColumnCount(); i++) {
        Rectangle rect = item.getBounds(i);
        if (rect.contains(pt)) {
            cubridConfConfigListData.clear();
            cubridConfConfigListData.addAll(unifyHostConfigUtil.parseCubridConfConfigToCommonTableValue(cubridConfConfigDataMap));
            String serverName = cubridConfConfigListData.get(0).get(i + "");
            if (!CommonUITool.openConfirmBox(Messages.bind(Messages.unifyHostConfigEditorAddColumnConfirmMsg, "section", serverName))) {
                return;
            }
            CubridConfConfig cubridConfConfig = cubridConfMap.get(serverName);
            //new property then set parameter
            CubridConfProperty property = new CubridConfProperty();
            property.setCubridConfPropKey("[%section" + (cubridConfConfig.getPropertyList().size() + 1) + "]");
            property.setCubridConf(true);
            property.setCubridConfPropAnnotation(StringUtil.NEWLINE);
            cubridConfConfig.addCubridConfProperty(property);
            cubridConfConfigDataMap.clear();
            cubridConfConfigDataMap.putAll(cubridConfMap);
            createCubridConfTableData();
            setDirty(true);
            return;
        }
    }
}
Also used : CubridConfProperty(com.cubrid.cubridmanager.ui.host.model.CubridConfProperty) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) CubridConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridConfConfig) Point(org.eclipse.swt.graphics.Point)

Example 2 with CubridConfProperty

use of com.cubrid.cubridmanager.ui.host.model.CubridConfProperty in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseStringLineToCubridConfConfig.

/**
	 * parseStringLineToCubridConfConfig
	 * @param content
	 * @return
	 * @throws Exception
	 */
public CubridConfConfig parseStringLineToCubridConfConfig(String content) {
    CubridConfConfig config = new CubridConfConfig();
    String cubridConfRegex = "\\[.*";
    Pattern cubridConfPattern = Pattern.compile(cubridConfRegex);
    String annotationRegex = "#(\\s*).+";
    Pattern annotationPattern = Pattern.compile(annotationRegex);
    String propertyRegex = ".+=.+";
    Pattern propertyPattern = Pattern.compile(propertyRegex);
    CubridConfProperty confProp = null;
    StringBuilder annotationBuilder = new StringBuilder();
    String[] contentArray = content.split(StringUtil.NEWLINE);
    for (String lineString : contentArray) {
        Matcher cubridConfMatcher = cubridConfPattern.matcher(lineString);
        Matcher annotationMatcher = annotationPattern.matcher(lineString);
        Matcher propertyMatcher = propertyPattern.matcher(lineString);
        if (cubridConfMatcher.find()) {
            //find broker like [service] [common] [@database]
            confProp = new CubridConfProperty();
            confProp.setCubridConfPropKey(lineString);
            confProp.setCubridConf(true);
            if (annotationBuilder != null) {
                confProp.setCubridConfPropAnnotation(annotationBuilder.toString());
            }
            config.addCubridConfProperty(confProp);
            annotationBuilder = null;
        } else if (annotationMatcher.find() || lineString.equals("")) {
            //find annotation
            if (annotationBuilder == null) {
                annotationBuilder = new StringBuilder();
            }
            annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
        } else if (propertyMatcher.find()) {
            //find key and value
            if (confProp == null) {
                //if there is no cubrid conf,ignore the property
                continue;
            }
            String[] keyValueString = lineString.split("=");
            if (keyValueString.length == 2) {
                String key = keyValueString[0].trim();
                String value = keyValueString[1].trim();
                //new property then set parameter
                CubridConfProperty property = new CubridConfProperty();
                property.setCubridConfPropKey(key);
                property.setCubridConfPropValue(value);
                if (annotationBuilder != null) {
                    property.setCubridConfPropAnnotation(annotationBuilder.toString());
                }
                confProp.addCubridConfProperty(property);
                annotationBuilder = null;
            }
        } else {
            //opthers see it to bottom annotation
            annotationBuilder.append(lineString).append(StringUtil.NEWLINE);
        }
    }
    if (annotationBuilder != null) {
        config.setConfAnnotation(annotationBuilder.toString());
    }
    return config;
}
Also used : CubridConfProperty(com.cubrid.cubridmanager.ui.host.model.CubridConfProperty) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) CubridConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridConfConfig)

Example 3 with CubridConfProperty

use of com.cubrid.cubridmanager.ui.host.model.CubridConfProperty in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseCubridConfConfigToDocumnetString.

/**
	 *  parse a CubridConfConfig model to a document string
	 * @param config CubridBrokerConfig
	 * @return String
	 */
public String parseCubridConfConfigToDocumnetString(CubridConfConfig config) {
    StringBuilder contents = new StringBuilder();
    for (CubridConfProperty cubridConfConfig : config.getPropertyList()) {
        String annotation = cubridConfConfig.getCubridConfPropAnnotation();
        if (annotation != null) {
            contents.append(annotation);
        }
        //if is cubrid conf set broker name
        if (cubridConfConfig.isCubridConf()) {
            contents.append(cubridConfConfig.getCubridConfPropKey()).append(StringUtil.NEWLINE);
        }
        //loop properies
        for (CubridConfProperty property : cubridConfConfig.getPropertyList()) {
            annotation = property.getCubridConfPropAnnotation();
            if (annotation != null) {
                contents.append(annotation);
            }
            contents.append(property.getCubridConfPropKey()).append("=").append(property.getCubridConfPropValue()).append(StringUtil.NEWLINE);
        }
    }
    //add bottom annotation
    if (config.getConfAnnotation() != null) {
        contents.append(config.getConfAnnotation());
    }
    return contents.toString();
}
Also used : CubridConfProperty(com.cubrid.cubridmanager.ui.host.model.CubridConfProperty)

Example 4 with CubridConfProperty

use of com.cubrid.cubridmanager.ui.host.model.CubridConfProperty in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseCommonTableValueToCubridConfConfig.

/**
	 * parse common table value to cubrid config model list
	 * @param dataList
	 * @return
	 */
public LinkedHashMap<String, CubridConfConfig> parseCommonTableValueToCubridConfConfig(List<Map<String, String>> dataList, int tableColumnCount) {
    LinkedHashMap<String, CubridConfConfig> cubridConfConfigMap = new LinkedHashMap<String, CubridConfConfig>();
    Map<String, String> serverNameMap = null;
    Map<String, String> cubridConfNameMap = null;
    for (int i = 0; i < dataList.size(); i++) {
        if (i == 0) {
            //first data is server name
            serverNameMap = dataList.get(i);
            for (int j = 1; j < serverNameMap.size(); j++) {
                String serverName = serverNameMap.get(j + "");
                if (serverName == null || "".equals(serverName)) {
                    continue;
                }
                if (cubridConfConfigMap.get(serverName) == null) {
                    CubridConfConfig config = new CubridConfConfig();
                    cubridConfConfigMap.put(serverName, config);
                }
            }
        } else if (i == 1) {
            //second data is server name
            cubridConfNameMap = dataList.get(i);
            for (int j = 1; j < cubridConfNameMap.size(); j++) {
                String cubridConfName = cubridConfNameMap.get(j + "");
                if (cubridConfName == null || "".equals(cubridConfName)) {
                    continue;
                }
                String annotation = cubridConfNameMap.get(j + UnifyHostConfigEditor.ANNOTATION);
                CubridConfProperty cubridConfProperty = new CubridConfProperty();
                cubridConfProperty.setCubridConfPropKey(cubridConfName);
                cubridConfProperty.setCubridConfPropAnnotation(annotation);
                cubridConfProperty.setCubridConf(true);
                String serverName = serverNameMap.get(j + "");
                CubridConfConfig config = cubridConfConfigMap.get(serverName);
                config.addCubridConfProperty(cubridConfProperty);
            }
        } else {
            Map<String, String> valueMap = dataList.get(i);
            String propName = "";
            String propValue = "";
            for (int j = 0; j < tableColumnCount; j++) {
                String value = valueMap.get(Integer.toString(j));
                if (j == 0) {
                    propName = value;
                    continue;
                }
                propValue = value;
                if (propValue != null && !"".equals(propValue)) {
                    String cubridConfName = cubridConfNameMap.get(j + "");
                    String serverName = serverNameMap.get(j + "");
                    CubridConfConfig config = cubridConfConfigMap.get(serverName);
                    CubridConfProperty cubridConf = getCubridConfPropertyByCubridConfName(config, cubridConfName);
                    if (cubridConf != null) {
                        CubridConfProperty cubridConfProp = new CubridConfProperty();
                        cubridConf.addCubridConfProperty(cubridConfProp);
                        cubridConfProp.setCubridConfPropKey(propName);
                        cubridConfProp.setCubridConfPropValue(propValue);
                        String annotation = valueMap.get(Integer.toString(j) + UnifyHostConfigEditor.ANNOTATION);
                        cubridConfProp.setCubridConfPropAnnotation(annotation);
                    }
                }
            }
        }
    }
    return cubridConfConfigMap;
}
Also used : CubridConfProperty(com.cubrid.cubridmanager.ui.host.model.CubridConfProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CubridConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridConfConfig) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with CubridConfProperty

use of com.cubrid.cubridmanager.ui.host.model.CubridConfProperty in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseCubridConfConfigToCommonTableValue.

/**
	 * parse cubrid data to table value
	 * @param Map<String, CubridConfConfig> cubridConfConfigDataMap
	 */
public List<Map<String, String>> parseCubridConfConfigToCommonTableValue(Map<String, CubridConfConfig> cubridConfConfigDataMap) {
    List<Map<String, String>> result = new ArrayList<Map<String, String>>();
    //mark property in the list
    List<String> propList = new ArrayList<String>();
    Map<String, String> dataMap = null;
    Map<String, String> serverMap = new HashMap<String, String>();
    Map<String, String> cubridMap = new HashMap<String, String>();
    //first row as server name
    result.add(serverMap);
    serverMap.put("0", UnifyHostConfigEditor.SERVERNAMECOLUMNTITLE);
    int index = 1;
    for (Entry<String, CubridConfConfig> entry : cubridConfConfigDataMap.entrySet()) {
        CubridConfConfig cubridConfConfig = entry.getValue();
        for (CubridConfProperty cubridConfProperty : cubridConfConfig.getPropertyList()) {
            //server name
            serverMap.put("" + index, entry.getKey());
            if (cubridConfProperty.getCubridConfPropAnnotation() != null) {
                //set annotation
                serverMap.put(Integer.toString(index) + UnifyHostConfigEditor.ANNOTATION, cubridConfProperty.getCubridConfPropAnnotation());
            }
            index++;
        }
    }
    //second row as broker name
    result.add(cubridMap);
    cubridMap.put("0", UnifyHostConfigEditor.CUBRIDNAMECOLUMNTITLE);
    index = 1;
    for (Entry<String, CubridConfConfig> entry : cubridConfConfigDataMap.entrySet()) {
        CubridConfConfig cubridConfConfig = entry.getValue();
        for (CubridConfProperty cubridConfProperty : cubridConfConfig.getPropertyList()) {
            //cubrid name
            cubridMap.put("" + index, cubridConfProperty.getCubridConfPropKey());
            if (cubridConfProperty.getCubridConfPropAnnotation() != null) {
                //set annotation
                cubridMap.put(Integer.toString(index) + UnifyHostConfigEditor.ANNOTATION, cubridConfProperty.getCubridConfPropAnnotation());
            }
            index++;
        }
    }
    for (Entry<String, CubridConfConfig> entry : cubridConfConfigDataMap.entrySet()) {
        String serviceName = entry.getKey();
        CubridConfConfig cubridConfConfig = entry.getValue();
        for (CubridConfProperty cubridConfProperty : cubridConfConfig.getPropertyList()) {
            String cubridName = cubridConfProperty.getCubridConfPropKey();
            for (CubridConfProperty prop : cubridConfProperty.getPropertyList()) {
                String properKey = prop.getCubridConfPropKey();
                if (!propList.contains(properKey)) {
                    //a new property
                    propList.add(properKey);
                    dataMap = new HashMap<String, String>();
                    result.add(dataMap);
                    dataMap.put("0", prop.getCubridConfPropKey());
                    if (prop.getCubridConfPropValue() != null) {
                        dataMap.put("0", prop.getCubridConfPropKey());
                    }
                    String indexString = getMapKeyByValue(serverMap, cubridMap, serviceName, cubridName);
                    if (indexString != null) {
                        dataMap.put(indexString, prop.getCubridConfPropValue());
                        if (prop.getCubridConfPropAnnotation() != null) {
                            dataMap.put(indexString + UnifyHostConfigEditor.ANNOTATION, prop.getCubridConfPropAnnotation());
                        }
                    }
                } else {
                    Map<String, String> oneRowData = getRowData(result, properKey);
                    String indexString = getMapKeyByValue(serverMap, cubridMap, serviceName, cubridName);
                    String value = prop.getCubridConfPropValue();
                    String annotation = prop.getCubridConfPropAnnotation();
                    if (oneRowData != null && indexString != null && value != null) {
                        oneRowData.put(indexString, value);
                        if (annotation != null) {
                            oneRowData.put(indexString + UnifyHostConfigEditor.ANNOTATION, annotation);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : CubridConfProperty(com.cubrid.cubridmanager.ui.host.model.CubridConfProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) CubridConfConfig(com.cubrid.cubridmanager.ui.host.model.CubridConfConfig)

Aggregations

CubridConfProperty (com.cubrid.cubridmanager.ui.host.model.CubridConfProperty)5 CubridConfConfig (com.cubrid.cubridmanager.ui.host.model.CubridConfConfig)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Point (org.eclipse.swt.graphics.Point)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 TableItem (org.eclipse.swt.widgets.TableItem)1