package com.simonepezzano.hshare.preferences;
import hshare.Activator;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import com.simonepezzano.hshare.HLog;
import com.simonepezzano.hshare.views.IHShareView;
import com.simonepezzano.hshare.views.MainView;
/**
* Class used to initialize default preference values.
*/
public class PreferenceInitializer extends AbstractPreferenceInitializer {
public void initializeDefaultPreferences() {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
store.setDefault(PreferenceConstants.P_IPURLSERVICE, "http://whatismyip.com/automation/n09230945.asp");
store.setDefault(PreferenceConstants.P_LISTENINGPORT, 5595);
store.addPropertyChangeListener(new IPropertyChangeListener(){
public void propertyChange(PropertyChangeEvent event) {
String property = event.getProperty();
if(property.equals(PreferenceConstants.P_LISTENINGPORT)||
property.equals(PreferenceConstants.P_IPURLSERVICE)
)
PlatformUI.getWorkbench().getDisplay().asyncExec(new UpdateConnInfo());
}
});
}
class UpdateConnInfo implements Runnable{
public void run() {
try {
IHShareView hsv = (IHShareView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(MainView.ID);
hsv.updateData();
} catch (PartInitException e) {
HLog.facelogger.error("Unable to refresh connection info",e);
}
}
}
}