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

package com.togethersoft.modules.inspector.customproperties;

import com.togethersoft.openapi.ide.IdeScript;
import com.togethersoft.openapi.ide.IdeContext;
import com.togethersoft.openapi.ide.inspector.*;
import com.togethersoft.openapi.ide.inspector.util.*;
import com.togethersoft.openapi.ide.util.UIComponentService;
import com.togethersoft.openapi.rwi.RwiElement;
import com.togethersoft.openapi.util.RwiElementsUtil;

public class ActivateScript implements IdeScript, IdeInspectorBuilder {
  public void run(IdeContext context) {
    IdeInspectorManager manager = IdeInspectorManagerAccess.getInspectorManager();
    manager.addInspectorBuilder(this);
  }

  public IdeInspector buildInspector(IdeContext context, IdeInspector inspector) {
    IdeInspectorComponent component = inspector.findComponent(CustomPropertiesInspectorComponent.NAME);
    if(component == null) {
      RwiElement[] rwiElements = RwiElementsUtil.getRwiElements(context);
      if (rwiElements.length == 1) {
        inspector.addComponent(new CustomPropertiesInspectorComponent(
          context, rwiElements[0], inspector), null, ComponentWeight.OTHER
        );
      }
    }
    return inspector;
  }
}
