/**
   * Gets the target component's name for this jbi.xml file.
   *
   * @param jbiXmlFile a jbi.xml file
   * @return the component name, or null if it could be found
   */
  private String getComponentId(File jbiXmlFile) {

    String result = null;
    if ("jbi".equals(jbiXmlFile.getParentFile().getName())) {
      File propertiesFile =
          new File(
              jbiXmlFile.getParentFile().getParentFile().getParentFile().getParentFile(),
              PetalsSPPropertiesManager.PROPERTIES_FILENAME);

      Properties prop = PetalsSPPropertiesManager.getProperties(propertiesFile);
      result = prop.getProperty(PetalsSPPropertiesManager.COMPONENT_DEPLOYMENT_ID);
    }

    return result;
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.jface.preference.PreferencePage
   * #createContents(org.eclipse.swt.widgets.Composite)
   */
  @Override
  protected Control createContents(Composite parent) {

    Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(new GridData(GridData.FILL_BOTH));

    new Label(container, SWT.NONE).setText("Component Name:");
    this.componentNameText = new Text(container, SWT.SINGLE | SWT.BORDER);
    this.componentNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(container, SWT.NONE).setText("Component Deployment ID:");
    this.componentIdText = new Text(container, SWT.SINGLE | SWT.BORDER);
    this.componentIdText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(container, SWT.NONE).setText("Component Version:");
    this.componentVersionText = new Text(container, SWT.SINGLE | SWT.BORDER);
    this.componentVersionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    new Label(container, SWT.NONE).setText("Function:");
    this.componentFunctionText = new Text(container, SWT.SINGLE | SWT.BORDER);
    this.componentFunctionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    this.selectedProject = (IProject) getElement();
    Properties projectProperties = PetalsSPPropertiesManager.getProperties(this.selectedProject);
    String componentName =
        projectProperties.getProperty(PetalsSPPropertiesManager.COMPONENT_NAME, "");
    this.componentNameText.setText(componentName);

    String componentId =
        projectProperties.getProperty(PetalsSPPropertiesManager.COMPONENT_DEPLOYMENT_ID, "");
    this.componentIdText.setText(componentId);

    String componentVersion =
        projectProperties.getProperty(PetalsSPPropertiesManager.COMPONENT_VERSION, "");
    this.componentVersionText.setText(componentVersion);

    String suType = projectProperties.getProperty(PetalsSPPropertiesManager.COMPONENT_FUNCTION, "");
    this.componentFunctionText.setText(suType);

    return container;
  }
  /*
   * (non-Javadoc)
   * @see org.eclipse.jface.preference.PreferencePage#performApply()
   */
  @Override
  protected void performApply() {

    String componentName = this.componentNameText.getText();
    String componentId = this.componentIdText.getText();
    String componentVersion = this.componentVersionText.getText();
    String suType = this.componentFunctionText.getText();

    Properties projectProperties = new Properties();
    projectProperties.put(PetalsSPPropertiesManager.COMPONENT_FUNCTION, suType);
    projectProperties.put(PetalsSPPropertiesManager.COMPONENT_NAME, componentName);
    projectProperties.put(PetalsSPPropertiesManager.COMPONENT_DEPLOYMENT_ID, componentId);
    projectProperties.put(PetalsSPPropertiesManager.COMPONENT_VERSION, componentVersion);
    try {
      PetalsSPPropertiesManager.saveProperties(projectProperties, this.selectedProject);

    } catch (Exception e) {
      MessageDialog.openError(
          getShell(), "Error", "An error occurred while saving the properties.");
      PetalsServicesPlugin.log(e, IStatus.ERROR);
    }
  }