CodeGeneration of the CustomComponent

Hi there,

Are there anyway to affect the CodeGeneration of the VisualEditor
and are there any models to describe the CodeGeneration.
I found in the VisualEditor-class the method getModelFromJava().
Are there a reverse way for the CodeGeneration?
I want to extends the ComponentModel with a lot of fields, who should add
to the custom “CustomComponent-Class”.

Greez p.walzer

For the Visual Designer part, see ComponentProperties.ComponentProperty - creating an instance of it or of one of its subclasses will automatically register the property in the editor, and you can optionally delimit to which component it applies.

Code generation in the Eclipse plug-in is mostly handled by EclipseJavaGenerator and EclipseMethodBuilder under the control of methods in JavaGenerator, and special mappings between values in the model and setter invocations in code are handled by ComponentPropertyMapper.

The other side is in EclipseJavaParser - see also JavaParser.parseComponentMethodInvocation() for the special cases if you need to add such, and override it if necessary.

I hope these pointers will help you get started with this.

Hi Henri Sara,

I tried to add a new StringComponentProperty to the Properties of the ModelFromJava, but I get a Exceptions like this

java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.e4.xwt.javabean.Controller.fireEvent(Controller.java:44)
	at org.eclipse.e4.xwt.javabean.Controller.handleEvent(Controller.java:246)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1053)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:942)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:588)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:543)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.UnsupportedOperationException
	at java.util.Collections$UnmodifiableMap.put(Unknown Source)

I add a SWT-Button to the VisualPage to test it but there is an invalid access

In the VaadinEditor I modified the createVisualEditorPage()-Method.

    void createVisualEditorPage() {
        browser = createBrowser(getContainer());
        // note that the browser is not an IEditorPart, but is treated as a
        // simple Control
        
        Button testButton = new Button(getContainer(), SWT.PUSH);
		testButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false,
				false));
		testButton.setText("Test");
		testButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				super.widgetSelected(e);
				StringComponentProperty customProperty = new ComponentProperties.StringComponentProperty("attribute");
				
//				ComponentProperty customProperty = new ComponentProperty("screen", ComponentPropertyType.STRING) {
//					@Override
//					public void setValueFromString(Component component, String value)
//							throws NoSuchMethodException, IllegalAccessException,
//							InvocationTargetException {
//						setValueFromString(component, value);
//					}
//					@Override
//					public Object getValue(Component component) {
//						return getValue(component);
//					}
//				};
				
				try {
					getModelFromJava().getProperties().put(customProperty, "screen");
				} catch (CoreException e1) {
					e1.printStackTrace();
				}
			}
		});
        
		int index = addPage(testButton);
		
		//TODO:
//        int index = addPage(browser);
        setPageText(index, "Design");
    }

How can I add this Property to the Model?

Thanks for your help.

Greez p.walzer