/*
 * Copyright 2000-2016 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.debugger.ui.tree.render;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.JDOMExternalizerUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;

public final class BasicRendererProperties implements Cloneable {
  private static final Logger LOG = Logger.getInstance("#com.intellij.debugger.ui.tree.render.BasicRendererProperties");

  private static final @NonNls String NAME_OPTION = "NAME";
  private String myName;

  private static final @NonNls String ENABLED_OPTION = "ENABLED";
  private boolean myEnabled;

  private static final @NonNls String CLASSNAME_OPTION = "QUALIFIED_NAME";
  private String myClassName;

  private static final @NonNls String SHOW_TYPE_OPTION = "SHOW_TYPE";
  private boolean myShowType = true;

  public String getName() {
    return myName;
  }

  public void setName(final String name) {
    myName = name;
  }

  public boolean isEnabled() {
    return myEnabled;
  }

  public void setEnabled(final boolean enabled) {
    myEnabled = enabled;
  }

  public String getClassName() {
    return myClassName;
  }

  public void setClassName(final String className) {
    myClassName = className;
  }

  public boolean isShowType() {
    return myShowType;
  }

  public void setShowType(boolean showType) {
    myShowType = showType;
  }

  public void readExternal(Element element) {
    myName = null;
    myClassName = null;
    for (Element option : element.getChildren("option")) {
      final String optionName = option.getAttributeValue("name");
      if (NAME_OPTION.equals(optionName)) {
        myName = option.getAttributeValue("value");
      }
      else if (ENABLED_OPTION.equals(optionName)) {
        // default is false
        myEnabled = Boolean.parseBoolean(option.getAttributeValue("value"));
      }
      else if (CLASSNAME_OPTION.equals(optionName)) {
        myClassName = option.getAttributeValue("value");
      }
      else if (SHOW_TYPE_OPTION.equals(optionName)) {
        // default is true
        myShowType = !"false".equalsIgnoreCase(option.getAttributeValue("value"));
      }
    }
  }

  public void writeExternal(Element element) {
    if (myName != null) {
      JDOMExternalizerUtil.writeField(element, NAME_OPTION, myName);
    }
    if (myEnabled) {
      // default is false
      //noinspection ConstantConditions
      JDOMExternalizerUtil.writeField(element, ENABLED_OPTION, Boolean.toString(myEnabled));
    }
    if (myClassName != null) {
      JDOMExternalizerUtil.writeField(element, CLASSNAME_OPTION, myClassName);
    }
    if (!myShowType) {
      // default is true
      //noinspection ConstantConditions
      JDOMExternalizerUtil.writeField(element, SHOW_TYPE_OPTION, Boolean.toString(myShowType));
    }
  }

  @Override
  public BasicRendererProperties clone()  {
    try {
      return (BasicRendererProperties)super.clone();
    }
    catch (CloneNotSupportedException e) {
      LOG.error(e);
    }
    return null;
  }
}

@@ -2162,30 +2162,15 @@
     
-if (NAME_OPTION.equals
+switch 
 (opt
@@ -2169,36 +2169,63 @@
 tch (optionName)
-)
  %7B%0A
+        case NAME_OPTION:%0A  
         myName =
@@ -2270,62 +2270,50 @@
     
-%7D%0A      else if (ENABLED_OPTION.equals(optionName)) %7B%0A
+    break;%0A        case ENABLED_OPTION:%0A  
     
@@ -2348,41 +2348,25 @@
     
-myEnabled = Boolean.parseBoolean(
+  String value = 
 opti
@@ -2390,33 +2390,32 @@
 lue(%22value%22)
-)
 ;%0A      
 %7D%0A      else
@@ -2406,64 +2406,148 @@
     
-%7D%0A      else if (CLASSNAME_OPTION.equals(optionName)) %7B%0A
+    if (value != null) %7B%0A            myEnabled = Boolean.parseBoolean(value);%0A          %7D%0A          break;%0A        case CLASSNAME_OPTION:%0A  
     
@@ -2609,64 +2609,52 @@
     
-%7D%0A      else if (SHOW_TYPE_OPTION.equals(optionName)) %7B%0A
+    break;%0A        case SHOW_TYPE_OPTION:%0A  
     
@@ -2672,24 +2672,26 @@
 ult is true%0A
+  
         mySh
@@ -2757,24 +2757,41 @@
 (%22value%22));%0A
+          break;%0A
       %7D%0A    

use switch, do not set enabled if attribute is null