Search in sources :

Example 1 with CubridBrokerProperty

use of com.cubrid.common.ui.spi.model.CubridBrokerProperty in project cubrid-manager by CUBRID.

the class BrokerConfPersistUtil method readBrokerConfig.

/**
	 * parse a CubridBrokerConfig model to a document string
	 *
	 * @param config CubridBrokerConfig
	 * @return String
	 */
public String readBrokerConfig(BrokerConfig config) {
    StringBuilder contents = new StringBuilder();
    for (CubridBrokerProperty cubridBrokerProperty : config.getPropertyList()) {
        String annotation = cubridBrokerProperty.getCubridBrokerPropAnnotation();
        if (annotation != null) {
            contents.append(annotation);
        }
        //if is cubrid broker set broker name
        if (cubridBrokerProperty.isCubridBroker()) {
            contents.append(cubridBrokerProperty.getCubridBrokerPropKey()).append(StringUtil.NEWLINE);
        }
        //loop properies
        for (CubridBrokerProperty property : cubridBrokerProperty.getPropertyList()) {
            annotation = property.getCubridBrokerPropAnnotation();
            if (annotation != null) {
                contents.append(annotation);
            }
            contents.append(property.getCubridBrokerPropKey()).append("=").append(property.getCubridBrokerPropValue()).append(StringUtil.NEWLINE);
        }
    }
    //add bottom annotation
    if (config.getConfAnnotation() != null) {
        contents.append(config.getConfAnnotation());
    }
    return contents.toString();
}
Also used : CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty)

Example 2 with CubridBrokerProperty

use of com.cubrid.common.ui.spi.model.CubridBrokerProperty in project cubrid-manager by CUBRID.

the class UnifyHostConfigEditor method addBrokerConfColumn.

/**
	 * addBrokerConfColumn
	 */
public void addBrokerConfColumn() {
    editorInput.setBrokerConfPropertyCount(brokerConfTabTableViewer.getTable().getColumnCount());
    LinkedHashMap<String, BrokerConfig> brokerConfMap = unifyHostConfigUtil.parseCommonTableValueToCubridBrokerConfig(cubridBrokerConfListData, editorInput.getBrokerConfPropertyCount());
    Point pt = cubridBrokerTableClickPoint;
    int selectIndex = brokerConfTabTableViewer.getTable().getSelectionIndex();
    if (selectIndex < 0) {
        return;
    }
    final TableItem item = brokerConfTabTableViewer.getTable().getItem(selectIndex);
    if (item == null) {
        return;
    }
    for (int i = 0; i < brokerConfTabTableViewer.getTable().getColumnCount(); i++) {
        Rectangle rect = item.getBounds(i);
        if (rect.contains(pt)) {
            cubridBrokerConfListData.clear();
            cubridBrokerConfListData.addAll(unifyHostConfigUtil.parseCubridBrokerConfigToCommonTableValue(cubridBrokerConfigDataMap));
            String serverName = cubridBrokerConfListData.get(0).get(i + "");
            if (!CommonUITool.openConfirmBox(Messages.bind(Messages.unifyHostConfigEditorAddColumnConfirmMsg, "broker", serverName))) {
                return;
            }
            BrokerConfig cubridBrokerConfig = brokerConfMap.get(serverName);
            //new property then set parameter
            CubridBrokerProperty property = new CubridBrokerProperty();
            property.setCubridBrokerPropKey("[%broker" + (cubridBrokerConfig.getPropertyList().size() + 1) + "]");
            property.setCubridBroker(true);
            property.setCubridBrokerPropAnnotation(StringUtil.NEWLINE);
            cubridBrokerConfig.addCubridBrokerProperty(property);
            cubridBrokerConfigDataMap.clear();
            cubridBrokerConfigDataMap.putAll(brokerConfMap);
            createBrokerConfTableData();
            setDirty(true);
            return;
        }
    }
}
Also used : BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) TableItem(org.eclipse.swt.widgets.TableItem) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty) Point(org.eclipse.swt.graphics.Point)

Example 3 with CubridBrokerProperty

use of com.cubrid.common.ui.spi.model.CubridBrokerProperty in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseCommonTableValueToCubridBrokerConfig.

/**
	 * parse common table value to broker config model list
	 * @param dataList
	 * @return
	 */
public LinkedHashMap<String, BrokerConfig> parseCommonTableValueToCubridBrokerConfig(List<Map<String, String>> dataList, int tableColumnCount) {
    LinkedHashMap<String, BrokerConfig> cubridBrokerConfigMap = new LinkedHashMap<String, BrokerConfig>();
    Map<String, String> serverNameMap = null;
    Map<String, String> brokerNameMap = 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 (cubridBrokerConfigMap.get(serverName) == null) {
                    BrokerConfig config = new BrokerConfig();
                    cubridBrokerConfigMap.put(serverName, config);
                }
            }
        } else if (i == 1) {
            //second data is server name
            brokerNameMap = dataList.get(i);
            for (int j = 1; j < brokerNameMap.size(); j++) {
                String brokerName = brokerNameMap.get(j + "");
                if (brokerName == null || "".equals(brokerName)) {
                    continue;
                }
                String annotation = brokerNameMap.get(j + UnifyHostConfigEditor.ANNOTATION);
                CubridBrokerProperty brokerConf = new CubridBrokerProperty();
                brokerConf.setCubridBrokerPropKey(brokerName);
                brokerConf.setCubridBrokerPropAnnotation(annotation);
                brokerConf.setCubridBroker(true);
                String serverName = serverNameMap.get(j + "");
                BrokerConfig config = cubridBrokerConfigMap.get(serverName);
                config.addCubridBrokerProperty(brokerConf);
            }
        } 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 brokerName = brokerNameMap.get(j + "");
                    String serverName = serverNameMap.get(j + "");
                    BrokerConfig config = cubridBrokerConfigMap.get(serverName);
                    CubridBrokerProperty brokerConf = getCubridBrokerPropertyByBrokerName(config, brokerName);
                    if (brokerConf != null) {
                        CubridBrokerProperty brokerProp = new CubridBrokerProperty();
                        brokerConf.addCubridBrokerProperty(brokerProp);
                        brokerProp.setCubridBrokerPropKey(propName);
                        brokerProp.setCubridBrokerPropValue(propValue);
                        String annotation = valueMap.get(Integer.toString(j) + UnifyHostConfigEditor.ANNOTATION);
                        brokerProp.setCubridBrokerPropAnnotation(annotation);
                    }
                }
            }
        }
    }
    return cubridBrokerConfigMap;
}
Also used : BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with CubridBrokerProperty

use of com.cubrid.common.ui.spi.model.CubridBrokerProperty in project cubrid-manager by CUBRID.

the class UnifyHostConfigUtil method parseCubridBrokerConfigToCommonTableValue.

/**
	 * parse broker data to table value
	 * @param Map<String, CubridConfConfig> cubridBrokerConfigDataMap
	 */
public List<Map<String, String>> parseCubridBrokerConfigToCommonTableValue(Map<String, BrokerConfig> cubridBrokerConfigDataMap) {
    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> brokerMap = new HashMap<String, String>();
    //first row as server name
    result.add(serverMap);
    serverMap.put("0", UnifyHostConfigEditor.SERVERNAMECOLUMNTITLE);
    int index = 1;
    for (Entry<String, BrokerConfig> entry : cubridBrokerConfigDataMap.entrySet()) {
        BrokerConfig cubridBrokerConfig = entry.getValue();
        for (CubridBrokerProperty cubridBroker : cubridBrokerConfig.getPropertyList()) {
            //server name
            serverMap.put("" + index, entry.getKey());
            if (cubridBroker.getCubridBrokerPropAnnotation() != null) {
                //set annotation
                serverMap.put(Integer.toString(index) + UnifyHostConfigEditor.ANNOTATION, cubridBroker.getCubridBrokerPropAnnotation());
            }
            index++;
        }
    }
    //second row as broker name
    result.add(brokerMap);
    brokerMap.put("0", UnifyHostConfigEditor.BROKERNAMECOLUMNTITLE);
    index = 1;
    for (Entry<String, BrokerConfig> entry : cubridBrokerConfigDataMap.entrySet()) {
        BrokerConfig cubridBrokerConfig = entry.getValue();
        for (CubridBrokerProperty cubridBroker : cubridBrokerConfig.getPropertyList()) {
            //broker name
            brokerMap.put("" + index, cubridBroker.getCubridBrokerPropKey());
            if (cubridBroker.getCubridBrokerPropAnnotation() != null) {
                //set annotation
                brokerMap.put(Integer.toString(index) + UnifyHostConfigEditor.ANNOTATION, cubridBroker.getCubridBrokerPropAnnotation());
            }
            index++;
        }
    }
    for (Entry<String, BrokerConfig> entry : cubridBrokerConfigDataMap.entrySet()) {
        String serviceName = entry.getKey();
        BrokerConfig cubridBrokerConfig = entry.getValue();
        for (CubridBrokerProperty cubridBroker : cubridBrokerConfig.getPropertyList()) {
            String brokerName = cubridBroker.getCubridBrokerPropKey();
            for (CubridBrokerProperty prop : cubridBroker.getPropertyList()) {
                String properKey = prop.getCubridBrokerPropKey();
                if (!propList.contains(properKey)) {
                    //a new property
                    propList.add(properKey);
                    dataMap = new HashMap<String, String>();
                    result.add(dataMap);
                    dataMap.put("0", prop.getCubridBrokerPropKey());
                    if (prop.getCubridBrokerPropValue() != null) {
                        dataMap.put("0", prop.getCubridBrokerPropKey());
                    }
                    String indexString = getMapKeyByValue(serverMap, brokerMap, serviceName, brokerName);
                    if (indexString != null) {
                        dataMap.put(indexString, prop.getCubridBrokerPropValue());
                        if (prop.getCubridBrokerPropAnnotation() != null) {
                            dataMap.put(indexString + UnifyHostConfigEditor.ANNOTATION, prop.getCubridBrokerPropAnnotation());
                        }
                    }
                } else {
                    Map<String, String> oneRowData = getRowData(result, properKey);
                    String indexString = getMapKeyByValue(serverMap, brokerMap, serviceName, brokerName);
                    String value = prop.getCubridBrokerPropValue();
                    String annotation = prop.getCubridBrokerPropAnnotation();
                    if (oneRowData != null && indexString != null && value != null) {
                        oneRowData.put(indexString, value);
                        if (annotation != null) {
                            oneRowData.put(indexString + UnifyHostConfigEditor.ANNOTATION, annotation);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 5 with CubridBrokerProperty

use of com.cubrid.common.ui.spi.model.CubridBrokerProperty in project cubrid-manager by CUBRID.

the class BrokerConfPersistUtil method parseCommonTableValueToBrokerConfig.

/**
	 * parse common table value to broker config model
	 *
	 * @param dataList
	 * @return
	 */
public BrokerConfig parseCommonTableValueToBrokerConfig(List<Map<String, String>> dataList, int tableColumnCount) {
    BrokerConfig config = new BrokerConfig();
    Map<String, String> brokerNameMap = null;
    for (int i = 0; i < dataList.size(); i++) {
        if (i == 0) {
            //first data is broker name
            brokerNameMap = dataList.get(i);
            for (int j = 1; j < brokerNameMap.size(); j++) {
                String brokerName = brokerNameMap.get(Integer.toString(j));
                if (StringUtil.isEmpty(brokerName)) {
                    continue;
                }
                String annotation = brokerNameMap.get(Integer.toString(j) + ANNOTATION);
                CubridBrokerProperty brokerConf = new CubridBrokerProperty();
                brokerConf.setCubridBrokerPropKey(brokerName);
                brokerConf.setCubridBrokerPropAnnotation(annotation);
                brokerConf.setCubridBroker(true);
                config.addCubridBrokerProperty(brokerConf);
            }
        } 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 (StringUtil.isNotEmpty(propValue)) {
                    String brokerName = brokerNameMap.get(Integer.toString(j));
                    CubridBrokerProperty brokerConf = getCubridBrokerPropertyByBrokerName(config, brokerName);
                    if (brokerConf != null) {
                        CubridBrokerProperty brokerProp = new CubridBrokerProperty();
                        brokerConf.addCubridBrokerProperty(brokerProp);
                        brokerProp.setCubridBrokerPropKey(propName);
                        brokerProp.setCubridBrokerPropValue(propValue);
                        String annotation = valueMap.get(Integer.toString(j) + ANNOTATION);
                        brokerProp.setCubridBrokerPropAnnotation(annotation);
                    }
                }
            }
        }
    }
    return config;
}
Also used : BrokerConfig(com.cubrid.common.ui.spi.model.BrokerConfig) CubridBrokerProperty(com.cubrid.common.ui.spi.model.CubridBrokerProperty)

Aggregations

CubridBrokerProperty (com.cubrid.common.ui.spi.model.CubridBrokerProperty)7 BrokerConfig (com.cubrid.common.ui.spi.model.BrokerConfig)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 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