This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 228178 - Enum-Property doesn't list its Elements
Summary: Enum-Property doesn't list its Elements
Status: NEW
Alias: None
Product: guibuilder
Classification: Unclassified
Component: Binding (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: issues@guibuilder
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-02 18:30 UTC by MrMacSpooky
Modified: 2013-05-31 15:37 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description MrMacSpooky 2013-04-02 18:30:29 UTC
It might be difficult to explain.

I was writing some library-stuff and because most applications has some persistent settings, I tried to generalize this.

First I invented an Interface:


public interface Configurable<T extends Enum<T> & Configurable<T>> {

	void resetValue();
	void setValue(String value);
	String getValue();

}


The Idea is, that the Application uses one or more Enums which implements this Interface:

public enum Settings implements Configurable<Settings> {

		val1("value1", false)
	,	val2("value2", true)


	;

	private Settings(String defaultValue, Boolean isCrypted) {
	}

	@Override
	public void resetValue() {
	}

	@Override
	public void setValue(String value) {
	}

	@Override
	public String getValue() {
	}
}

The Code needed for Using the Enum is not shown - it's in another Class (the 'Core' - handling the 'persistence').

The Next Step is using a JTextField which is bound to a specific Enum, this, too, is library-Stuff and must be generalized.

For that I Defined:

public class ConfigurationTextField <T extends Enum<T> & Configurable<T>> extends JTextField {

	private T configurationEnum;

	public T getConfigurationEnum() {
		return configurationEnum;
	}

	public void setConfigurationEnum(T configurationEnum) {
		this.configurationEnum = configurationEnum;
	}
...
}

So far so good.

Now I put this new TextField on a JFrame. In its property-Window, Page 'Code' I set 'Type Parameters' to '<Settings>'. I compiled Project - no errors, no warnings.

In the Properties-Page the Property is listed - it offers a ComboBox to choose: just <nothing>.

It would be nice, if IDE could resolve these Enums.

Goal is: User may define more 'Configurable-Enums', and if it's needed, he may bind this specific setting to an editable component.

Using Generics should prevent implementing the interface other than in enums which implement this one. No Implementaion on Classes, no Implementaions to other Enums.
Comment 1 Tomas Pavek 2013-05-31 15:37:50 UTC
The GUI builder currently does not consider type parameters for determining the property type. In fact it has no understanding of the generics. Would need to detect that the property type is parametrized and that it is the same parameter that is used for the class, then find the actual type in the 'Type Parameters' code property and use it as the actual property type instead of Object. It makes some sense and could be possible, but I guess it would not be easy to implement.