public void resetPropertyValue() {
   if (parent == null) // root does not have a default value
   return;
   //	Use our parent's values to reset our values.
   boolean change = false;
   Object[] objects = parent.getValues();
   for (int i = 0; i < objects.length; i++) {
     IPropertySource source = getPropertySource(objects[i]);
     if (source.isPropertySet(descriptor.getId())) {
       source.resetPropertyValue(descriptor.getId());
       change = true;
     }
   }
   if (change) refreshValues();
 }
  /**
   * Return the unsorted intersection of all the <code>IPropertyDescriptor</code>s for the objects.
   *
   * @return List
   */
  private List computeMergedPropertyDescriptors() {
    if (values.length == 0) {
      return new ArrayList(0);
    }

    IPropertySource firstSource = getPropertySource(values[0]);
    if (firstSource == null) {
      return new ArrayList(0);
    }

    if (values.length == 1) {
      return Arrays.asList(firstSource.getPropertyDescriptors());
    }

    // get all descriptors from each object
    Map[] propertyDescriptorMaps = new Map[values.length];
    for (int i = 0; i < values.length; i++) {
      Object object = values[i];
      IPropertySource source = getPropertySource(object);
      if (source == null) {
        // if one of the selected items is not a property source
        // then we show no properties
        return new ArrayList(0);
      }
      // get the property descriptors keyed by id
      propertyDescriptorMaps[i] = computePropertyDescriptorsFor(source);
    }

    // intersect
    Map intersection = propertyDescriptorMaps[0];
    for (int i = 1; i < propertyDescriptorMaps.length; i++) {
      // get the current ids
      Object[] ids = intersection.keySet().toArray();
      for (int j = 0; j < ids.length; j++) {
        Object object = propertyDescriptorMaps[i].get(ids[j]);
        if (object == null
            ||
            // see if the descriptors (which have the same id) are
            // compatible
            !((IPropertyDescriptor) intersection.get(ids[j]))
                .isCompatibleWith((IPropertyDescriptor) object)) {
          intersection.remove(ids[j]);
        }
      }
    }

    // sorting is handled in the PropertySheetViewer, return unsorted (in
    // the original order)
    ArrayList result = new ArrayList(intersection.size());
    IPropertyDescriptor[] firstDescs = firstSource.getPropertyDescriptors();
    for (int i = 0; i < firstDescs.length; i++) {
      IPropertyDescriptor desc = firstDescs[i];
      if (intersection.containsKey(desc.getId())) {
        result.add(desc);
      }
    }
    return result;
  }
 /**
  * Update our value objects. We ask our parent for the property values based on our descriptor.
  */
 private void refreshValues() {
   // get our parent's value objects
   Object[] sources = parent.getValues();
   // loop through the objects getting our property value from each
   Object[] newValues = new Object[sources.length];
   for (int i = 0; i < sources.length; i++) {
     IPropertySource source = parent.getPropertySource(sources[i]);
     newValues[i] = source.getPropertyValue(descriptor.getId());
   } // set our new values
   setValues(newValues);
 } /* (non-Javadoc)
  public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
    super.createControls(parent, tabbedPropertySheetPage);

    parent.setLayout(new GridLayout(2, false));

    IPropertyDescriptor pd = getPropertyDesriptor(JRDesignGenericElement.PROPERTY_EVALUATION_TIME);
    IPropertyDescriptor gpd =
        getPropertyDesriptor(JRDesignGenericElement.PROPERTY_EVALUATION_GROUP_NAME);
    getWidgetFactory().createCLabel(parent, pd.getDisplayName());
    widgets.put(pd.getId(), new SPEvaluationTime(parent, this, pd, gpd));

    createWidget4Property(parent, MGenericElement.PROPERTY_NAME);
    createWidget4Property(parent, MGenericElement.PROPERTY_NAMESPACE);
  }
  /**
   * Update our child entries. This implementation tries to reuse child entries if possible (if the
   * id of the new descriptor matches the descriptor id of the old entry).
   */
  private void refreshChildEntries() {
    if (childEntries == null) // no children to refresh
    return;
    // get the current descriptors
    List descriptors = computeMergedPropertyDescriptors();
    // cache old entries by their descriptor id
    Map entryCache = new HashMap(childEntries.length * 2 + 1);
    for (int i = 0; i < childEntries.length; i++) {
      entryCache.put(childEntries[i].getDescriptor().getId(), childEntries[i]);
    } // create a list of entries to dispose
    List entriesToDispose = new ArrayList(Arrays.asList(childEntries));
    // rebuild child entries using old when possible
    childEntries = new PropertySheetEntry[descriptors.size()];
    boolean entriesChanged = descriptors.size() != entryCache.size();
    for (int i = 0; i < descriptors.size(); i++) {
      IPropertyDescriptor d = (IPropertyDescriptor) descriptors.get(i);
      // see if we have an entry matching this descriptor
      PropertySheetEntry entry = (PropertySheetEntry) entryCache.get(d.getId());
      if (entry != null) { // reuse old entry
        entry.setDescriptor(d);
        entriesToDispose.remove(entry);
      } else { // create new entry
        entry = new PropertySheetEntry();
        entry.setDescriptor(d);
        entry.setParent(this);
        entry.setPropertySourceProvider(propertySourceProvider);
        entriesChanged = true;
      }
      entry.refreshValues();
      childEntries[i] = entry;
    }

    if (entriesChanged) fireChildEntriesChanged();
    // Dispose of entries which are no longer needed
    for (int i = 0; i < entriesToDispose.size(); i++) {
      ((IPropertySheetEntry) entriesToDispose.get(i)).dispose();
    }
  }
 @Override
 public Object getId() {
   return mDelegate.getId();
 }
 public PropertyDescriptorWrapper(IPropertyDescriptor delegate) {
   super(delegate.getId(), delegate.getDisplayName());
   mDelegate = delegate;
 }
  /**
   * Return the sorted intersection of all the <code>IPropertyDescriptor</code>s for the objects.
   */
  private List computeMergedPropertyDescriptors() {
    if (values.length == 0) return new ArrayList(0);

    // get all descriptors from each object
    Map[] propertyDescriptorMaps = new Map[values.length];
    for (int i = 0; i < values.length; i++) {
      Object object = values[i];
      IPropertySource source = getPropertySource(object);
      if (source == null) {
        // if one of the selected items is not a property source
        // then we show no properties
        return new ArrayList(0);
      }
      // get the property descriptors keyed by id
      propertyDescriptorMaps[i] = computePropertyDescriptorsFor(source);
    }

    // intersect
    Map intersection = propertyDescriptorMaps[0];
    for (int i = 1; i < propertyDescriptorMaps.length; i++) {
      // get the current ids
      Object[] ids = intersection.keySet().toArray();
      for (int j = 0; j < ids.length; j++) {
        Object object = propertyDescriptorMaps[i].get(ids[j]);
        if (object == null
            || // see if the descriptors (which have the same id) are compatible
            !((IPropertyDescriptor) intersection.get(ids[j]))
                .isCompatibleWith((IPropertyDescriptor) object)) intersection.remove(ids[j]);
      }
    }

    // Sort the descriptors
    List descriptors = new ArrayList(intersection.values());
    Collections.sort(
        descriptors,
        new Comparator() {
          Collator coll = Collator.getInstance(Locale.getDefault());

          public int compare(Object a, Object b) {
            IPropertyDescriptor d1, d2;
            String dname1, dname2;
            d1 = (IPropertyDescriptor) a;
            dname1 = d1.getDisplayName();
            d2 = (IPropertyDescriptor) b;
            dname2 = d2.getDisplayName();
            return coll.compare(dname1, dname2);
          }
        });
    IPropertyDescriptor idDescriptor = null;
    for (Iterator iter = descriptors.iterator(); iter.hasNext(); ) {
      IPropertyDescriptor element = (IPropertyDescriptor) iter.next();
      String id = (String) element.getId();
      if ("id".equals(id)) {
        idDescriptor = element;
        break;
      }
      if ("name".equals(id)) {
        idDescriptor = element;
        break;
      }
      if ("property".equals(id)) {
        idDescriptor = element;
        break;
      }
    }

    if (idDescriptor != null) {
      descriptors.remove(idDescriptor);
      descriptors.add(0, idDescriptor);
    }

    return descriptors;
  }
 public ReadonlyPropertyController(IPropertyDescriptor propertyDescriptor) {
   super(propertyDescriptor, propertyDescriptor.getId());
 }
  @Override
  protected void createColumns() {
    int bounds = 100;
    int column = 0;
    clearColumns();

    List list = propertySources;
    if (list.isEmpty() && exemplar != null) {
      list = new ArrayList();
      list.add(exemplar);
    }

    boolean usePropertySourceProviderIfItHasNicerRenderers = false;
    if (usePropertySourceProviderIfItHasNicerRenderers) {
      SortedMap<String, TableViewerColumn> headers = new TreeMap<String, TableViewerColumn>();
      for (Object object : list) {
        final IPropertySource propertySource = PropertySources.asPropertySource(object);
        IPropertyDescriptor[] descriptors = propertySource.getPropertyDescriptors();
        if (descriptors != null) {
          for (final IPropertyDescriptor descriptor : descriptors) {
            final Object id = descriptor.getId();
            String header = PropertyDescriptors.getReadablePropertyName(descriptor);
            TableViewerColumn col = headers.get(header);
            if (col == null) {
              col = createTableViewerColumn(header, bounds, column++);
              headers.put(header, col);

              IPropertySourceProvider propertySourceProvider =
                  new IPropertySourceProvider() {
                    @Override
                    public IPropertySource getPropertySource(Object object) {
                      return PropertySources.asPropertySource(object);
                    }
                  };
              col.setLabelProvider(new PropertyColumnLabelProvider(propertySourceProvider, id));
            }
          }
        }
      }
    } else {
      SortedMap<String, Function1> headers = new TreeMap<String, Function1>();
      for (Object object : list) {
        final IPropertySource propertySource = PropertySources.asPropertySource(object);
        IPropertyDescriptor[] descriptors = propertySource.getPropertyDescriptors();
        if (descriptors != null) {
          for (final IPropertyDescriptor descriptor : descriptors) {
            final Object id = descriptor.getId();
            String name = PropertyDescriptors.getReadablePropertyName(descriptor);
            Function1 function =
                new Function1WithReturnType() {
                  @Override
                  public Object apply(Object object) {
                    IPropertySource property = PropertySources.asPropertySource(object);
                    if (property != null) {
                      return property.getPropertyValue(id);
                    }
                    return null;
                  }

                  @Override
                  public Class<?> getReturnType() {
                    return PropertyDescriptors.getPropertyType(descriptor);
                  }
                };
            headers.put(name, function);
          }
        }
      }
      int idx = 0;
      boolean pickedSortColumn = false;
      Set<Entry<String, Function1>> entrySet = headers.entrySet();
      for (Entry<String, Function1> entry : entrySet) {
        String header = entry.getKey();
        if (!pickedSortColumn && isDefaultSortColumn(header)) {
          setDefaultSortColumnIndex(idx);
          pickedSortColumn = true;
        }
        Function1 function = entry.getValue();
        addFunction(function);
        TableViewerColumn col = createTableViewerColumn(header, bounds, column++);
        col.setLabelProvider(createColumnLabelProvider(header, function));
        idx++;
      }
    }
  }
Exemple #11
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);
  }
Exemple #12
0
  @Override
  protected synchronized void onNodeChanged(AbstractNode node) {
    if (form != null && !form.isDisposed()) {
      try {
        form.dispose();
      } catch (Exception e) {
        // ignore any expose exceptions
      }
    }
    form = null;

    if (parent.isDisposed()) return;

    parent.setLayout(new GridLayout());
    // parent.setLayout(new GridLayout(1, false));
    parent.setLayoutData(new GridData(GridData.FILL_BOTH));

    form = toolkit.createForm(parent);
    form.setLayoutData(new GridData(GridData.FILL_BOTH));
    form.setText(EditorMessages.propertiesDetailsTitle);
    toolkit.decorateFormHeading(form);

    form.getBody().setLayout(new GridLayout(2, false));

    Composite sbody = form.getBody();

    if (node != null) {
      final IMessageManager mmng = form.getMessageManager();

      form.setText(node.getPatternName());

      IPropertyDescriptor idDescriptor = null;
      IPropertyDescriptor descriptionDescriptor = null;

      IPropertyDescriptor[] propertyDescriptors = node.getPropertyDescriptors();

      for (int i = 0; i < 2; i++) {
        for (IPropertyDescriptor descriptor : propertyDescriptors) {
          final Object id = descriptor.getId();
          if ("AbstractNode.Id".equals(id)) {
            idDescriptor = descriptor;
          } else if (NODE_DESCRIPTION.equals(id)) {
            descriptionDescriptor = descriptor;
          } else {
            String propertyName = getPropertyName(id);
            boolean mandatory =
                descriptor instanceof ExpressionPropertyDescriptor
                    || isMandatory(node, propertyName);
            if ((mandatory && i == 0) || (!mandatory && i == 1)) {
              createDecoratedTextField(descriptor, toolkit, sbody, mmng);
            }
          }
        }
      }

      if (idDescriptor != null || descriptionDescriptor != null) {
        if (idDescriptor != null) {
          createDecoratedTextField(idDescriptor, toolkit, sbody, mmng);
        }
        if (descriptionDescriptor != null) {
          createDecoratedTextField(descriptionDescriptor, toolkit, sbody, mmng);
        }
      }

      // ref ECLIPSE-1012: unsaved nodes may be disposed
      // mmng.update();
    } else {
      form.setText(EditorMessages.propertiesDetailsTitle);
    }

    layoutForm();
  }