Пример #1
0
  protected void bindNestedPojoProperty(
      FormToolkit toolkit,
      final IMessageManager mmng,
      final IPropertyDescriptor complexProperty,
      Composite parent,
      Object value,
      PropertyDescriptor property,
      Class<?> complexType) {
    String labelText;
    String propertyName = property.getName();
    Class<?> propertyType = property.getPropertyType();
    labelText = capitalize(splitCamelCase(propertyName));
    if (complexProperty instanceof ComplexUnionPropertyDescriptor) {
      // lets fix up the background colour!
      Label label = new Label(parent, SWT.NONE);
      label.setText(labelText);
    } else {
      Label label = toolkit.createLabel(parent, labelText);
    }

    Control widget;
    Class refType = isBeanRef(value, propertyName);
    IObservable observable;
    if (boolean.class.isAssignableFrom(propertyType)
        || Boolean.class.isAssignableFrom(propertyType)) {
      Button checkbox = new Button(parent, SWT.CHECK | SWT.BORDER);
      widget = checkbox;
      ISWTObservableValue textValue = Forms.observe(checkbox);
      observable = textValue;
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          textValue,
          checkbox);
    } else if (refType != null) {
      Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER);
      String[] beanRefs = getBeanRefs(refType);
      combo.setItems(beanRefs);
      toolkit.adapt(combo, true, true);
      widget = combo;

      ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
      observable = comboValue;
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          comboValue,
          combo);
    } else if (isEndpointUri(value, propertyName)) {
      Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER);
      combo.setItems(getEndpointUris());
      toolkit.adapt(combo, true, true);
      widget = combo;

      ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
      observable = comboValue;
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          comboValue,
          combo);
    } else if (Enum.class.isAssignableFrom(propertyType)) {
      ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY | SWT.BORDER);
      combo.setContentProvider(ArrayContentProvider.getInstance());
      combo.setInput(getEnumValues((Class<? extends Enum>) propertyType));

      IViewerObservableValue comboValue = ViewersObservables.observeSingleSelection(combo);
      observable = comboValue;
      Control control = combo.getControl();
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          comboValue,
          control);

      toolkit.adapt(control, true, true);
      widget = control;

    } else {
      Text text = toolkit.createText(parent, "");
      widget = text;
      // text.setToolTipText(tooltip);
      ISWTObservableValue textValue = Forms.observe(text);
      observable = textValue;
      Forms.bindPojoProperty(
          bindingContext,
          mmng,
          value,
          propertyName,
          isMandatory(value, propertyName),
          labelText,
          textValue,
          text);
    }
    widget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (observable != null && node != null) {
      observable.addChangeListener(
          new IChangeListener() {

            @Override
            public void handleChange(ChangeEvent event) {
              // lets notify the node that its changed
              String id = complexProperty.getId().toString();
              fireNodePropertyChangedEvent(id);
            }
          });
    }
  }
Пример #2
0
  private void createDecoratedTextField(
      final IPropertyDescriptor descriptor,
      FormToolkit toolkit,
      Composite parent,
      final IMessageManager mmng) {

    final Object id = descriptor.getId();
    String labelText = descriptor.getDisplayName();
    String tooltip = Tooltips.tooltip(id.toString());
    GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    boolean isDescription = NODE_DESCRIPTION.equals(id);
    Control widget;

    boolean isComplexProperty = descriptor instanceof ComplexPropertyDescriptor;
    boolean isUnionProperty = descriptor instanceof ComplexUnionPropertyDescriptor;
    if (isComplexProperty) {
      widget =
          bindNestedComplexProperties(
              toolkit,
              parent,
              mmng,
              (ComplexPropertyDescriptor) descriptor,
              id,
              labelText,
              tooltip);
    } else {
      Label label = toolkit.createLabel(parent, labelText);
      label.setToolTipText(tooltip);

      if (isDescription) {
        label.setLayoutData(gd);
      }
      if (isUnionProperty) {
        widget =
            bindNestedComplexUnionProperties(
                toolkit,
                parent,
                mmng,
                id,
                labelText,
                tooltip,
                (ComplexUnionPropertyDescriptor) descriptor);
      } else if (descriptor instanceof ExpressionPropertyDescriptor) {
        // lets create a composite and add a text are and a combo box
        // ExpandableComposite composite =
        // toolkit.createExpandableComposite(parent, SWT.HORIZONTAL);
        Composite composite = toolkit.createComposite(parent);
        GridLayout layout = new GridLayout(3, false);
        zeroMargins(layout);
        composite.setLayout(layout);
        widget = composite;

        Text text = toolkit.createText(composite, "", SWT.BORDER);
        text.setToolTipText(tooltip);

        gd = new GridData(GridData.FILL_HORIZONTAL);
        // gd.horizontalAlignment = GridData.HORIZONTAL_ALIGN_BEGINNING;
        // gd.horizontalAlignment = SWT.LEFT;
        // gd.verticalIndent = 0;
        // gd.verticalAlignment = GridData.FILL;
        text.setLayoutData(gd);
        ISWTObservableValue textValue = Forms.observe(text);

        // NOTE this code only works if the LanguageExpressionBean is
        // not
        // replaced under our feet!
        final LanguageExpressionBean expression =
            LanguageExpressionBean.bindToNodeProperty(node, id);
        final String expressionPropertyName = "expression";
        Forms.bindBeanProperty(
            bindingContext,
            mmng,
            expression,
            expressionPropertyName,
            isMandatory(expression, expressionPropertyName),
            expressionPropertyName,
            textValue,
            text);

        String languageLabel = EditorMessages.propertiesLanguageTitle;
        toolkit.createLabel(composite, languageLabel);
        // toolkit.createSeparator(composite, SWT.SEPARATOR);

        Combo combo = new Combo(composite, SWT.NONE | SWT.BORDER);
        combo.setItems(new Languages().languageArray());
        toolkit.adapt(combo, true, true);

        ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
        Forms.bindBeanProperty(
            bindingContext,
            mmng,
            expression,
            "language",
            isMandatory(expression, "language"),
            languageLabel,
            comboValue,
            combo);

        String language = expression.getLanguage();
        if (language == null) {
          language = CamelModelHelper.getDefaultLanguageName();
          expression.setLanguage(language);
        }

        // now lets forward property events to the node
        expression.addPropertyChangeListener(
            new PropertyChangeListener() {
              /*
               * (non-Javadoc)
               *
               * @see
               * java.beans.PropertyChangeListener#propertyChange(java
               * .beans .PropertyChangeEvent)
               */
              @Override
              public void propertyChange(PropertyChangeEvent event) {
                node.firePropertyChange(id.toString(), null, expression);
              }
            });
      } else {
        String propertyName = getPropertyName(id);
        Class refType = isBeanRef(node, propertyName);
        if (refType != null) {
          Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER);
          String[] beanRefs = getBeanRefs(refType);
          combo.setItems(beanRefs);
          toolkit.adapt(combo, true, true);
          widget = combo;

          ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              comboValue,
              combo);
        } else if (isEndpointUri(node, propertyName)) {
          Combo combo = new Combo(parent, SWT.NONE | SWT.BORDER);
          combo.setItems(getEndpointUris());
          toolkit.adapt(combo, true, true);
          widget = combo;

          ISWTObservableValue comboValue = WidgetProperties.selection().observe(combo);
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              comboValue,
              combo);
        } else if (descriptor instanceof BooleanPropertyDescriptor) {
          Button checkbox = new Button(parent, SWT.CHECK);
          widget = checkbox;
          ISWTObservableValue textValue = Forms.observe(checkbox);
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              textValue,
              checkbox);
        } else if (descriptor instanceof ListPropertyDescriptor) {
          if (CamelModelHelper.isPropertyListOFSetHeaders(id)) {
            Control control = bindSetHeaderTable(toolkit, parent, id);
            widget = control;
          } else {
            Control control = bindListOfValues(toolkit, parent, id);
            widget = control;
          }
        } else if (descriptor instanceof EnumPropertyDescriptor) {
          EnumPropertyDescriptor enumProperty = (EnumPropertyDescriptor) descriptor;
          ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY | SWT.BORDER);
          combo.setContentProvider(ArrayContentProvider.getInstance());
          combo.setInput(getEnumValues(enumProperty.getEnumType()));

          IViewerObservableValue comboValue = ViewersObservables.observeSingleSelection(combo);
          Control control = combo.getControl();
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              comboValue,
              control);

          toolkit.adapt(control, true, true);
          widget = control;
        } else {
          Text text;
          if (isDescription) {
            text =
                toolkit.createText(
                    parent, "", SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL);
          } else {
            text = toolkit.createText(parent, "", SWT.BORDER);
          }
          text.setToolTipText(tooltip);
          widget = text;
          ISWTObservableValue textValue = Forms.observe(text);
          Forms.bindBeanProperty(
              bindingContext,
              mmng,
              node,
              propertyName,
              isMandatory(node, propertyName),
              labelText,
              textValue,
              text);
        }
      }
    }
    boolean isComplexOrUnion = isComplexProperty || isUnionProperty;
    if (isDescription || isComplexOrUnion) {
      gd = new GridData(GridData.FILL_BOTH);
      gd.heightHint = 90;
      gd.grabExcessVerticalSpace = true;
      gd.grabExcessHorizontalSpace = true;
      if (isComplexOrUnion) {
        gd.heightHint = -1;
      }
      if (isComplexProperty) {
        gd.horizontalSpan = 2;
      }

    } else {
      gd = new GridData(GridData.FILL_HORIZONTAL);
    }
    gd.widthHint = 250;
    widget.setLayoutData(gd);
  }