Exposing properties of subcomponents in a custom component

Following code gives me a custom version of the TreeView component. If I don’t provide a TreeComponentBeanInfo Class, the new component works fine in the designer and client scopes and all the properties of the TreeView are correctly exposed.

public class TreeComponent extends PMITreeView {
    public TreeComponent() {
        super();
    }
}

If I provide the TreeComponentBeanInfo class, is there a way to get the TreeView properties exposed without having to individually specify bean style getters and setters in the class TreeComponent and then add them to the BeanInfo class?

A walk by Love Canal suggested an answer which seems to work:

public class ChartComponentBeanInfo extends PMIEasyChartBeanInfo {
    public ChartComponentBeanInfo() {
        //super(ChartComponent.class, DynamicPropertyProviderCustomizer.VALUE_DESCRIPTOR, StyleCustomizer.VALUE_DESCRIPTOR);
        super();
    }

    @Override
    protected void initProperties() throws IntrospectionException {
        super.initProperties();
        addProp("title", "Title", "The title of the chart", CAT_DATA, PREFERRED_MASK | BOUND_MASK);
    }

But as a lady in a small town in the interior of Brazil said to her husband about me: Esse gringo aqui fala muito bem, mas ele nao intende nada. In other words, I’m not sure where this might bite me.

You can import PMITreeView’s beaninfo for your subclass. Here’s the BeanInfo code for the NoteChart class for your edification, and likely pre-emption of your next question. (-:[code]/* Filename: NoteChartBeanInfo.java

  • Created on Jan 3, 2015
  • Author: Phil Turmel pturmel@automation-pros.com
  • Copyright Automation Professionals, LLC 2015
  • Project: NoteChart_Designer
    */
    package com.automation_pros.notechart.beaninfos;

import java.awt.Image;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.SimpleBeanInfo;

import javax.swing.ImageIcon;

import com.automation_pros.notechart.components.NoteChart;
import com.inductiveautomation.factorypmi.designer.beaninfo.PMIChartBeanInfo;
import com.inductiveautomation.factorypmi.designer.property.customizers.ChartCustomizer;
import com.inductiveautomation.vision.api.designer.beans.CommonBeanInfo;
import com.inductiveautomation.vision.api.designer.beans.CustomizerDescriptor;
import com.inductiveautomation.vision.api.designer.beans.VisionBeanDescriptor;

public class NoteChartBeanInfo extends CommonBeanInfo {

public NoteChartBeanInfo() {
	super(NoteChart.class, new CustomizerDescriptor[] {
		ChartCustomizer.VALUE_DESCRIPTOR });
	getBeanDescriptor().setValue("dbl-click-customizer", ChartCustomizer.VALUE_DESCRIPTOR.getValueName());
}

@Override
protected void initProperties() throws IntrospectionException {
	// Adds common properties
	super.initProperties();

	// Remove properties that NoteChart will define differently from CommonBeanInfo
	removeProp("opaque");

	// Add all notechart-specific properties
	addProp("notes", "Notes", "Dataset of text annotations to display",
			CAT_DATA, PREFERRED_MASK | BOUND_MASK);
	addProp("altNotes", "Alternate Notes", "Dataset of alternate annotations for live modifications",
			CAT_DATA, PREFERRED_MASK | BOUND_MASK);
	addProp("samples", "Pen Value Samples", "Dataset of pen values at the Trace timestamp (when visible)",
			CAT_DATA, PREFERRED_MASK | BOUND_MASK);
	addProp("traceTS", "Trace Timestamp", "Timestamp for the selected annotation, or independent trace if no selection",
			CAT_DATA, PREFERRED_MASK | BOUND_MASK);
	addProp("selectedNote", "Selected Note", "Row Number of the selected Note within the Notes dataset",
			CAT_DATA, PREFERRED_MASK | BOUND_MASK);
	addProp("selectedAltNote", "Selected Alternate Note", "Row Number of the selected Alternate Note within the Alternate Notes dataset",
			CAT_DATA, PREFERRED_MASK | BOUND_MASK);
	addProp("noteFont", "Annotation Font", "Font for all text annotations",
			CAT_APPEARANCE, PREFERRED_MASK);
	addProp("noteColor", "Annotation Color", "Color of text annotations that lack a specified color",
			CAT_APPEARANCE, NO_MASK);
	addProp("noteStroke", "Annotation Stroke", "Line Style for all unselected text annotations",
			CAT_APPEARANCE, EXPERT_MASK);
	addProp("selNoteColor", "Selected Annotation Color", "Color for a selected annotation",
			CAT_APPEARANCE, NO_MASK);
	addProp("selNoteStroke", "Selected Annotation Stroke", "Line Style for a selected annotation",
			CAT_APPEARANCE, EXPERT_MASK);
	addProp("prioThreshold", "Priority Threshold", "Maximum Number of Notes to Display without priority filtering",
			CAT_BEHAVIOR, EXPERT_MASK);
	addProp("enableNoteSelect", "Enable Note Selection", "Annotations can clicked (at their text) to set selectedNote or selectedAltNote",
			CAT_BEHAVIOR, EXPERT_MASK);

	/* Hide properties from PMIChart that NoteChart can't use.  They
	 * would show up from getAdditionalBeanInfo().
	 */
	addProp("chartType", "Must be an XY Chart", "", CAT_BEHAVIOR, HIDDEN_MASK);
	addProp("subplotMode", "Must be Combined Domain", "", CAT_BEHAVIOR, HIDDEN_MASK);
}

@Override
public Image getIcon(int kind) {
	switch (kind) {
		case BeanInfo.ICON_COLOR_16x16:
		case BeanInfo.ICON_MONO_16x16:
			return new ImageIcon(getClass().getResource("/images/note-chart_16.png")).getImage();
		case SimpleBeanInfo.ICON_COLOR_32x32:
		case SimpleBeanInfo.ICON_MONO_32x32:
			return new ImageIcon(getClass().getResource("/images/note-chart_32.png")).getImage();
	}
	return null;
}

@Override
protected void initDesc() {
	VisionBeanDescriptor bean = getBeanDescriptor();
	bean.setName("Classic Note Chart");
	bean.setDisplayName("Classic Note Chart");
	bean.setShortDescription("A component that displays time-series Plots with annotation marks.");
	BeanInfo superbi = new PMIChartBeanInfo();
	BeanDescriptor superbean = superbi.getBeanDescriptor();
	bean.setValue("vision-extension-functions", superbean.getValue("vision-extension-functions"));
}

@Override
public BeanInfo[] getAdditionalBeanInfo() {
	BeanInfo[] superbi = { new PMIChartBeanInfo() };
	return superbi;
}

}[/code]

:smiley: magic, thanks Phil.

The tag drop works on the client, but it doesn’t work in the designer. I’ll take it as an exercise to see if I can figure out why.