Community
Participate
Working Groups
There are a couple of changes desirable to make the PropertySheetPage, PropertySheetViewer as well as the ColorCellEditor more flexible: * make the class org.eclipse.ui.views.properties.PropertySheetViewer public (it is currently only package visible) * make the method PropertySheetViewer.updateEntry(IPropertySheetEntry, TreeItem) at least protected (now private). The same with PropertySheetViewer.updateCategories(...) & updateChildrenOf(...) - probably ALL methods in this class should be protected, not private! * In method org.eclipse.ui.views.properties.PropertySheet.createDefaultPage (PageBook book): do NOT create the PropertySheetPage using new, rather create it in an additional method such as: protected PropertySheetPage createPropertySheetPage() { return new PropertySheetPage(); } that can be overriden. And along similar lines: * In DialogCellEditor.createControl(...). the layout should NOT directly be created as it is now ("editor.setLayout(new DialogCellLayout());"), but rather it should be created using a create-Method as above. * the private class DialogCellLayout should also be made visible (i.e. public or at least protected). Reason for all the above: I needed e.g. a ColorPropertyDescriptor, that also allows the selection of "no color". The monster below is what I had to come up with, to approximate that. I am still not happy with it, but it's my current trade-off between having to duplicate the entire PropertySheet and PropertyDescriptor and DialogCellEditor hierarchy and hooking into the existing code: /** * @author Michael Moser (mmo@zurich.ibm.com) * @since Nov 4, 2005 */ package leonardo.utils; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.ColorCellEditor; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.views.properties.ColorPropertyDescriptor; /** * The standard {@link org.eclipse.ui.views.properties.ColorPropertyDescriptor} * does not allow the selection of "no color". This class provides that possibility. */ public class ExtendedColorPropertyDescriptor extends ColorPropertyDescriptor { final String noColorString; public ExtendedColorPropertyDescriptor(final Object id, final String displayName, final String noColorString) { super(id, displayName); this.noColorString = noColorString; } /** * The <code>ColorPropertyDescriptor</code> implementation of this * <code>IPropertyDescriptor</code> method creates and returns a new * <code>ColorCellEditor</code>. * <p> * The editor is configured with the current validator if there is one. * </p> */ public CellEditor createPropertyEditor(final Composite parent) { final CellEditor editor = new ColorCellEditor(parent) { Composite labels; // Caution: this must NOT be initialized! The // below createContents()- method is called as // part of the constructor and will set the value! protected Control createContents(Composite cell) { return (this.labels = (Composite) super.createContents(cell)); } protected Button createButton(final Composite editor) { editor.setLayout(new FillLayout()); final Composite comp = new Composite (editor, SWT.NONE); comp.setLayout(new FillLayout()); final Button noneButton = new Button (comp, SWT.DOWN); noneButton.setText("none"); noneButton.setFont(editor.getFont()); noneButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(final SelectionEvent event) { markDirty(); doSetValue (null); fireApplyEditorValue(); } }); return super.createButton(comp); } protected void doSetValue(final Object value) { System.out.println("doSetValue:" + value); if ((value == null) || (value instanceof RGB)) { super.doSetValue(value); // } else { // ignore... } } /** * This is based on the intimate insider knowledge, that * the content (see above) contains two labels, one to display * the selected color as a blob and the second to display the * RGB values. When null (= "no color") was selected we * set appropriate values. */ protected void updateContents(final Object value) { try { if (value != null) { super.updateContents (value); } else { if (this.labels == null) { throw new Exception("updateContents(): labels==null!"); } final Control[] children = labels.getChildren(); if (children.length != 2) { throw new Exception("updateContents(): !=2 children!"); } final Label colLabel = (Label)children[0]; final Label rgbLabel = (Label)children[1]; colLabel.setImage(null); colLabel.setText(""); rgbLabel.setText (noColorString); } } catch (Exception ex) { System.err.println ("ColorCellEditor does not have the expected widget structure - using a new or different version?"); ex.printStackTrace(); } } }; if (getValidator() != null) editor.setValidator(getValidator()); return editor; } } to be used e.g. like: class Foo implements IPropertySource { // ... private static final IPropertyDescriptor[] descriptors = new IPropertyDescriptor[] { new ExtendedColorPropertyDescriptor ("Foo.FillColor", "Fill-Color", "no fill color"); // ... more could follow here... }; public IPropertyDescriptor[] getPropertyDescriptors() { return descriptors; } // ... }
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.