Exemplo n.º 1
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;
  }
  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);
  }
Exemplo n.º 3
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();
 }
Exemplo n.º 4
0
 /*
  * (non-Javadoc) Method declared on IPropertySheetEntry.
  */
 public Image getImage() {
   ILabelProvider provider = descriptor.getLabelProvider();
   if (provider == null) {
     return null;
   }
   return provider.getImage(editValue);
 }
Exemplo n.º 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)
Exemplo n.º 6
0
  /**
   * 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();
    }
  }
Exemplo n.º 7
0
 /*
  * (non-Javadoc) Method declared on IPropertySheetEntry.
  */
 public String getValueAsString() {
   if (editValue == null) {
     return ""; //$NON-NLS-1$
   }
   ILabelProvider provider = descriptor.getLabelProvider();
   if (provider == null) {
     return editValue.toString();
   }
   String text = provider.getText(editValue);
   if (text == null) {
     return ""; //$NON-NLS-1$
   }
   return text;
 }
Exemplo n.º 8
0
  /*
   * (non-Javadoc)
   *
   * @see
   * org.eclipse.ui.views.properties.IPropertySheetEntry#getEditor(org.eclipse
   * .swt.widgets.Composite)
   */
  public CellEditor getEditor(Composite parent) {

    if (editor == null || editor.getControl().isDisposed()) {
      editor = descriptor.createPropertyEditor(parent);
      if (editor != null) {
        editor.addListener(cellEditorListener);
      }
    }
    // && !eq(editor.getValue(), editValue)
    if (editor != null) {
      editor.setValue(editValue);
    }
    return editor;
  }
Exemplo n.º 9
0
  public CellEditor getEditor(Composite parent) {

    if (editor == null) {
      editor = descriptor.createPropertyEditor(parent);
      if (editor != null) {
        editor.addListener(cellEditorListener);
      }
    }
    if (editor != null) {
      editor.setValue(editValue);
      setErrorText(editor.getErrorMessage());
    }
    return editor;
  }
 @Override
 public CellEditor createPropertyEditor(Composite parent) {
   return mDelegate.createPropertyEditor(parent);
 }
 @Override
 public String getCategory() {
   return mDelegate.getCategory();
 }
Exemplo n.º 12
0
 /*
  * (non-Javadoc) Method declared on IPropertySheetEntry.
  */
 public String getDisplayName() {
   return descriptor.getDisplayName();
 }
 public PropertyDescriptorWrapper(IPropertyDescriptor delegate) {
   super(delegate.getId(), delegate.getDisplayName());
   mDelegate = delegate;
 }
Exemplo n.º 14
0
  /**
   * 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;
  }
Exemplo n.º 15
0
 /*
  * (non-Javadoc) Method declared on IPropertySheetEntry.
  */
 public String getFilters()[] {
   return descriptor.getFilterFlags();
 }
Exemplo n.º 16
0
 public Object getHelpContextIds() {
   return descriptor.getHelpContextIds();
 } /* (non-Javadoc)
 @Override
 public String[] getFilterFlags() {
   return mDelegate.getFilterFlags();
 }
 @Override
 public ILabelProvider getLabelProvider() {
   return mDelegate.getLabelProvider();
 }
Exemplo n.º 19
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++;
      }
    }
  }
Exemplo n.º 20
0
 public String getDisplayName() {
   return descriptor.getDisplayName();
 } /* (non-Javadoc)
Exemplo n.º 21
0
 public String getDescription() {
   return descriptor.getDescription();
 }
Exemplo n.º 22
0
 public String getCategory() {
   return descriptor.getCategory();
 } /* (non-Javadoc)
 @Override
 public String getDescription() {
   return mDelegate.getDescription();
 }
Exemplo n.º 24
0
 public String getValueAsString() {
   if (editValue == null) return ""; // $NON-NLS-1$
   ILabelProvider provider = descriptor.getLabelProvider();
   if (provider == null) return editValue.toString();
   return provider.getText(editValue);
 }
 @Override
 public String getDisplayName() {
   return mDelegate.getDisplayName();
 }
Exemplo n.º 26
0
 /*
  * (non-Javadoc) Method declared on IPropertySheetEntry.
  */
 public Object getHelpContextIds() {
   return descriptor.getHelpContextIds();
 }
 @Override
 public Object getId() {
   return mDelegate.getId();
 }
 public ReadonlyPropertyController(IPropertyDescriptor propertyDescriptor) {
   super(propertyDescriptor, propertyDescriptor.getId());
 }
 @Override
 public boolean isCompatibleWith(IPropertyDescriptor anotherProperty) {
   return mDelegate.isCompatibleWith(anotherProperty);
 }
Exemplo n.º 30
0
 public String getFilters()[] {
   return descriptor.getFilterFlags();
 } /* (non-Javadoc)