/*----------------------------------------------------------------------------
Copyright (c)2000 TogetherSoft Corporation. Patents pending. All rights reserved.
----------------------------------------------------------------------------*/

package com.togethersoft.modules.inspector.customproperties;

import com.togethersoft.openapi.ide.IdeContext;
import com.togethersoft.openapi.ide.inspector.*;
import com.togethersoft.openapi.ide.inspector.util.table.RwiElementsComponent;
import com.togethersoft.openapi.ide.inspector.util.property.*;
import com.togethersoft.openapi.ide.inspector.util.editors.SwingStringEditor;
import com.togethersoft.openapi.ide.util.UIComponentService;
import com.togethersoft.openapi.rwi.RwiElement;
import com.togethersoft.openapi.rwi.RwiProperty;
import com.togethersoft.openapi.rwi.enum.RwiPropertyEnumeration;

public class CustomPropertiesInspectorComponent extends IdeInspectorPropertySetComponent {
  public CustomPropertiesInspectorComponent(IdeContext context, RwiElement rwiElement, IdeInspector inspector) {
    super(context);
    myRwiElement = rwiElement;
    myInspector = inspector;
    setName(NAME);
    setService(UIComponentService.class, new CustomPropertiesInspectorComponentUI(inspector, this, myRwiElement));
  }

  public void update() {
    IdeInspectorProperty[] properties = getProperties();
    for (int i = 0; i < properties.length; i++) {
      removeProperty(properties[i]);
    }
    refill();
    super.update();
  }

  private void refill() {
    RwiPropertyEnumeration enum = myRwiElement.properties();  // TO DO : filter all except custom properties
    while (enum.hasMoreElements()) {
      RwiProperty currentRwiProperty = enum.nextRwiProperty();
      if (! CustomPropertiesUtil.checkPropertyName (myInspector, currentRwiProperty.getName())) continue;
      addProperty(new RwiInspectorStringProperty(myRwiElement, currentRwiProperty.getName()), null);
/*      if (currentRwiProperty.getValue().length() > 0)
        addProperty(new RwiInspectorStringProperty(myRwiElement, currentRwiProperty.getName()), null);
      else
        addProperty(new RwiInspectorBooleanProperty(myRwiElement, currentRwiProperty.getName()), null);*/
    }
  }

  private RwiElement myRwiElement;
  private IdeInspector myInspector;
  final static String NAME = "Custom properties";
}
