Search in sources :

Example 1 with KeywordColor

use of org.eclipse.titan.log.viewer.preferences.data.KeywordColor in project titan.EclipsePlug-ins by eclipse.

the class ImportExportUtils method exportKeywordColorsToXml.

protected static void exportKeywordColorsToXml(String pageID, Map<String, Object[]> settings, boolean useIndentation, OutputStream stream) throws TechnicalException {
    try {
        Document document = createDocument(pageID);
        Element root = document.getDocumentElement();
        root.setAttribute(VERSION_ATTRIBUTE_KEY, CURRENT_LV_VERSION);
        SortedMap<String, Object[]> sortedMap = new TreeMap<String, Object[]>(settings);
        for (Map.Entry<String, Object[]> entry : sortedMap.entrySet()) {
            String currentKey = entry.getKey();
            Element parent = document.createElement(currentKey);
            if (useIndentation) {
                root.appendChild(document.createTextNode(NEW_LINE + PARENT_INDENTATION));
            }
            root.appendChild(parent);
            Object[] values = entry.getValue();
            if (values instanceof String[]) {
                String[] stringValues = (String[]) values;
                for (int i = 0; i < stringValues.length; i++) {
                    addStringElement(useIndentation, document, parent, stringValues[i]);
                    addNewLineIfLast(document, parent, values, i);
                }
            } else if (values instanceof KeywordColor[]) {
                KeywordColor[] colorValues = (KeywordColor[]) values;
                for (int i = 0; i < colorValues.length; i++) {
                    addKeywordColor(useIndentation, document, parent, colorValues[i]);
                    addNewLineIfLast(document, parent, values, i);
                }
            }
        }
        // if last parent
        if (useIndentation) {
            root.appendChild(document.createTextNode(NEW_LINE));
        }
        writeDocument(stream, document);
    } catch (ParserConfigurationException e) {
        throw new TechnicalException(e);
    } catch (TransformerException e) {
        throw new TechnicalException(e);
    }
}
Also used : TechnicalException(org.eclipse.titan.log.viewer.exceptions.TechnicalException) Element(org.w3c.dom.Element) KeywordColor(org.eclipse.titan.log.viewer.preferences.data.KeywordColor) Document(org.w3c.dom.Document) TreeMap(java.util.TreeMap) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) HashMap(java.util.HashMap) Map(java.util.Map) NamedNodeMap(org.w3c.dom.NamedNodeMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap) TransformerException(javax.xml.transform.TransformerException)

Example 2 with KeywordColor

use of org.eclipse.titan.log.viewer.preferences.data.KeywordColor in project titan.EclipsePlug-ins by eclipse.

the class HighlightKeywordsPage method getCurrentPreferencesSeparated.

/**
 * Method for getting the current preferences in the preference store
 * @return map of the preferences
 */
private Map<String, Object[]> getCurrentPreferencesSeparated() {
    Map<String, Object[]> currentPrefs = new HashMap<String, Object[]>();
    String[] highlight = new String[] { String.valueOf(this.useHighLight.getBooleanValue()) };
    currentPrefs.put(PreferenceConstants.PREF_USE_HIGHLIGHT_ID, highlight);
    String[] listItems = this.highLightEditor.getElements();
    Map<String, RGB> colors = this.highLightEditor.getColors();
    KeywordColor[] values = new KeywordColor[this.highLightEditor.getElements().length];
    for (int i = 0; i < listItems.length; i++) {
        String item = listItems[i];
        RGB color = colors.get(item);
        KeywordColor keywordColor = new KeywordColor(item, color);
        values[i] = keywordColor;
    }
    currentPrefs.put(this.highLightEditor.getPreferenceName(), values);
    return currentPrefs;
}
Also used : HashMap(java.util.HashMap) KeywordColor(org.eclipse.titan.log.viewer.preferences.data.KeywordColor) RGB(org.eclipse.swt.graphics.RGB)

Aggregations

HashMap (java.util.HashMap)2 KeywordColor (org.eclipse.titan.log.viewer.preferences.data.KeywordColor)2 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 TransformerException (javax.xml.transform.TransformerException)1 RGB (org.eclipse.swt.graphics.RGB)1 TechnicalException (org.eclipse.titan.log.viewer.exceptions.TechnicalException)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1