예제 #1
0
 /**
  * The value of the given child entry has changed. Therefore we must set this change into our
  * value objects.
  *
  * <p>We must inform our parent so that it can update its value objects
  *
  * <p>Subclasses may override to set the property value in some custom way.
  *
  * @param the child entry that changed its value
  */
 protected void valueChanged(PropertySheetEntry child) {
   for (int i = 0; i < values.length; i++) {
     IPropertySource source = getPropertySource(values[i]);
     source.setPropertyValue(child.getDescriptor().getId(), child.getEditValue(i));
   } // inform our parent
   if (parent != null) parent.valueChanged(this);
 }
예제 #2
0
  /**
   * The <code>PropertySheetEntry</code> implmentation of this method declared on<code>
   * IPropertySheetEntry</code> will obtain an editable value for the given objects and update the
   * child entries.
   *
   * <p>Updating the child entries will typically call this method on the child entries and thus the
   * entire entry tree is updated
   *
   * @param objects the new values for this entry
   */
  public void setValues(Object[] objects) {
    values = objects;
    sources = new HashMap(values.length * 2 + 1);

    if (values.length == 0) {
      editValue = null;
    } else {
      // set the first value object as the entry's value
      Object newValue = values[0];

      // see if we should convert the value to an editable value
      IPropertySource source = getPropertySource(newValue);
      if (source != null) {
        newValue = source.getEditableValue();
        if (newValue instanceof AuroraComponent) {
          if (lastAc != null) lastAc.removePropertyChangeListener(pcListener);
          lastAc = (AuroraComponent) newValue;
          lastAc.addPropertyChangeListener(pcListener);
        }
      }
      editValue = newValue;
    }

    // update our child entries
    refreshChildEntries();

    // inform listeners that our value changed
    fireValueChanged();
  }
예제 #3
0
 /**
  * Returns the edit value for the object at the given index.
  *
  * @param index the value object index
  * @return the edit value for the object at the given index
  */
 protected Object getEditValue(int index) {
   Object value = values[index];
   IPropertySource source = getPropertySource(value);
   if (source != null) {
     value = source.getEditableValue();
   }
   return value;
 } /* (non-Javadoc)
예제 #4
0
  /**
   * 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;
  }
예제 #5
0
 /**
  * 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)
예제 #6
0
 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();
 }
예제 #7
0
 /**
  * The <code>PropertySheetEntry</code> implmentation of this method declared on<code>
  * IPropertySheetEntry</code> will obtain an editable value for the given objects and update the
  * child entries.
  *
  * <p>Updating the child entries will typically call this method on the child entries and thus the
  * entire entry tree is updated
  *
  * @param objects the new values for this entry
  */
 public void setValues(Object[] objects) {
   values = objects;
   sources = new HashMap(values.length * 2 + 1);
   if (values.length == 0) editValue = null;
   else {
     // set the first value object as the entry's value
     Object newValue = values[0];
     // see if we should convert the value to an editable value
     IPropertySource source = getPropertySource(newValue);
     if (source != null) newValue = source.getEditableValue();
     editValue = newValue;
   } // update our child entries
   refreshChildEntries();
   // inform listeners that our value changed
   fireValueChanged();
 }
예제 #8
0
 /**
  * Returns an map of property descritptors (keyed on id) for the given property source.
  *
  * @source a property source for which to obtain descriptors
  * @return a table of decriptors keyed on their id
  */
 private Map computePropertyDescriptorsFor(IPropertySource source) {
   IPropertyDescriptor[] descriptors = source.getPropertyDescriptors();
   Map result = new HashMap(descriptors.length * 2 + 1);
   for (int i = 0; i < descriptors.length; i++) {
     result.put(descriptors[i].getId(), descriptors[i]);
   }
   return result;
 }
예제 #9
0
  public ComboboxFigure(Composite parent, final IPropertySource propertySource) {
    super();
    Combo cb = new Combo(parent, SWT.DROP_DOWN);
    cb.setVisible(false);
    cb.setBounds(-100, -100, 10, 10);
    Point p = cb.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    cb.dispose();
    mComboHeight = p.y;

    setLayoutManager(new XYLayout());
    Rectangle[] bounds =
        calculateBounds(
            (Rectangle) propertySource.getPropertyValue(InstallOptionsWidget.PROPERTY_BOUNDS));
    mComboFigure =
        new ComboFigure(parent, new CustomPropertySourceWrapper(propertySource, bounds[0]));
    mListFigure =
        new ListFigure(
            parent, new CustomPropertySourceWrapper(propertySource, bounds[1]), SWT.SINGLE);
    mListFigure.setBorder(new LineBorder(ColorManager.getColor(ColorManager.BLACK)));
    mListFigure.setVisible(mShowDropdown);
    add(mComboFigure);
    add(mListFigure);
  }
 @Override
 public boolean isMultiLine() {
   return Boolean.TRUE.equals(mSource.getPropertyValue(InstallOptionsModel.PROPERTY_MULTILINE));
 }
 @Override
 protected void init(IPropertySource propertySource) {
   super.init(propertySource);
   mSource = propertySource;
   setTxtColor((RGB) propertySource.getPropertyValue(InstallOptionsModel.PROPERTY_TXTCOLOR));
 }
예제 #12
0
  @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++;
      }
    }
  }