/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.colar.netbeans.fan.wizard;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import javax.swing.JComponent;
import net.colar.netbeans.fan.platform.FanPlatform;
import net.colar.netbeans.fan.platform.FanPlatformSettings;
import org.netbeans.spi.options.OptionsPanelController;
import org.openide.util.HelpCtx;
import org.openide.util.Lookup;

/**
 * Controller for Fan options panel.
 * @author tcolar
 */
public class FanGlobalSettingsController extends OptionsPanelController
{

	private FanGlobalSettingsPanel panel;
	private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
	private boolean changed;

	public void update()
	{
		panel.setFanHome(FanPlatformSettings.getInstance().get(FanPlatformSettings.PREF_FAN_HOME));
		panel.setDebugPort(FanPlatformSettings.getInstance().get(FanPlatformSettings.PREF_DEBUG_PORT,"8000"));
		panel.setRunOptions(FanPlatformSettings.getInstance().get(FanPlatformSettings.PREF_RUN_OPTIONS,"-Xmx128m"));
		changed();
	}

	public void applyChanges()
	{
		String home = panel.getFanHome();
		String debugPort = panel.getDebugPort();
		String runOptions = panel.getRunOptions();
		FanPlatformSettings.getInstance().put(FanPlatformSettings.PREF_FAN_HOME, home);
		FanPlatformSettings.getInstance().put(FanPlatformSettings.PREF_DEBUG_PORT, debugPort);
		FanPlatformSettings.getInstance().put(FanPlatformSettings.PREF_RUN_OPTIONS, runOptions);
		// reread the plaform settings
		FanPlatform.getInstance(false).update();
		changed = false;
	}

	public void cancel()
	{
		// need not do anything special, if no changes have been persisted yet
	}

	public boolean isValid()
	{
		return getPanel().valid();
	}

	public boolean isChanged()
	{
		return changed;
	}

	public HelpCtx getHelpCtx()
	{
		return null;
	}

	public JComponent getComponent(Lookup masterLookup)
	{
		return getPanel();
	}

	public void addPropertyChangeListener(PropertyChangeListener l)
	{
		pcs.addPropertyChangeListener(l);
	}

	public void removePropertyChangeListener(PropertyChangeListener l)
	{
		pcs.removePropertyChangeListener(l);
	}

	private FanGlobalSettingsPanel getPanel()
	{
		if (panel == null)
		{
			panel = new FanGlobalSettingsPanel(this);
		}
		return panel;
	}

	void changed()
	{
		if (!changed)
		{
			changed = true;
			pcs.firePropertyChange(OptionsPanelController.PROP_CHANGED, false, true);
		}
		pcs.firePropertyChange(OptionsPanelController.PROP_VALID, null, null);
	}
}

@@ -1580,27 +1580,161 @@
 form
-.getInstance(false)
+ platform = FanPlatform.getInstance(true);%0A                if (null == platform) %7B%0A                    return;%0A                %7D%0A                platform
 .upd

Check for null FanPlatform