Exemplo n.º 1
0
  void show(ServiceInstance service) {
    detectUpdates(false);
    _target = service;

    //
    // If it's not a template instance, it's shown using
    // ServiceEditor.show()
    //
    assert getDescriptor().template.length() > 0;

    ServiceInstanceDescriptor descriptor = (ServiceInstanceDescriptor) service.getDescriptor();
    Coordinator coordinator = service.getCoordinator();
    boolean isEditable = service.isEphemeral() || !coordinator.substitute();

    Utils.Resolver resolver = isEditable ? null : ((TreeNode) service.getParent()).getResolver();

    //
    // Need to make control enabled before changing it
    //
    _template.setEnabled(true);

    ServiceTemplates serviceTemplates = service.getRoot().getServiceTemplates();
    _template.setModel(serviceTemplates.createComboBoxModel());

    ServiceTemplate t = (ServiceTemplate) serviceTemplates.findChild(descriptor.template);
    assert t != null;
    _template.setSelectedItem(t);

    ListDataListener templateListener =
        new ListDataListener() {
          @Override
          public void contentsChanged(ListDataEvent e) {
            updated();

            ServiceTemplate t = (ServiceTemplate) _template.getModel().getSelectedItem();

            TemplateDescriptor td = (TemplateDescriptor) t.getDescriptor();

            //
            // Replace parameters but keep existing values
            //
            _parameters.set(
                td.parameters,
                makeParameterValues(_parameters.getValues(), td.parameters),
                td.parameterDefaults,
                null);
          }

          @Override
          public void intervalAdded(ListDataEvent e) {}

          @Override
          public void intervalRemoved(ListDataEvent e) {}
        };

    _template.getModel().addListDataListener(templateListener);
    _template.setEnabled(isEditable);

    TemplateDescriptor td = (TemplateDescriptor) t.getDescriptor();
    _parameters.set(td.parameters, descriptor.parameterValues, td.parameterDefaults, resolver);

    _propertySets.setList(
        java.util.Arrays.asList(descriptor.propertySet.references), getDetailResolver());
    _propertySets.setEditable(isEditable);

    _properties.setProperties(
        descriptor.propertySet.properties, null, null, getDetailResolver(), isEditable);

    _applyButton.setEnabled(service.isEphemeral());
    _discardButton.setEnabled(service.isEphemeral());
    detectUpdates(true);
    if (service.isEphemeral()) {
      updated();
    }
  }