Search in sources :

Example 1 with ModifiablePropertyValueModel

use of org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel in project jbosstools-hibernate by jbosstools.

the class HibernatePropertiesComposite method initializeLayout.

@Override
protected void initializeLayout(Composite container) {
    GridLayout gl = new GridLayout(3, false);
    container.setLayout(gl);
    this.helper = new DriverClassHelpers();
    final SimpleListValueModel<String> lvmDialect = new SimpleListValueModel<String>(Arrays.asList(this.helper.getDialectNames()));
    PropertyValueModel<BasicHibernateProperties> p = (PropertyValueModel<BasicHibernateProperties>) getSubjectHolder();
    List<String> drivers = new ArrayList<String>();
    BasicHibernateProperties props = p.getValue();
    if (props != null) {
        String dialectClass = this.helper.getDialectClass(props.getDialect());
        String[] driverClasses = this.helper.getDriverClasses(dialectClass);
        drivers.addAll(Arrays.asList(driverClasses));
    }
    final SimpleListValueModel<String> lvmDriver = new SimpleListValueModel<String>(drivers);
    List<String> urls = new ArrayList<String>();
    if (props != null) {
        String driverClass = props.getDriver();
        String[] connectionURLS = this.helper.getConnectionURLS(driverClass);
        urls.addAll(Arrays.asList(connectionURLS));
    }
    final SimpleListValueModel<String> lvmUrl = new SimpleListValueModel<String>(urls);
    ModifiablePropertyValueModel<String> dialectHolder = buildDialectHolder();
    final ModifiablePropertyValueModel<String> driverHolder = buildDriverHolder();
    final ModifiablePropertyValueModel<String> urlHolder = buildUrlHolder();
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    this.addLabel(container, HibernateConsoleMessages.ConsoleConfigurationPropertySource_config_file + ':');
    this.cfgFile = this.addText(container, buildConfigFileHolder());
    Button b = this.addButton(container, HibernateConsoleMessages.CodeGenerationSettingsTab_setup, createSetupAction());
    cfgFile.setLayoutData(gd);
    // Button b = addButton(section, HibernateConsoleMessages.CodeGenerationSettingsTab_setup, createSetupAction());
    // this.cfgFile = addLabeledText(container,
    // HibernateConsoleMessages.ConsoleConfigurationPropertySource_config_file + ':', buildConfigFileHolder(),
    // b, null);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_database_dialect);
    Control c = this.addEditableCombo(container, lvmDialect, dialectHolder, TransformerTools.<String>objectToStringTransformer(), (String) null);
    gd.horizontalSpan = 2;
    c.setLayoutData(gd);
    // addLabeledEditableCombo(
    // section,
    // HibernateConsoleMessages.NewConfigurationWizardPage_database_dialect,
    // lvmDialect,
    // dialectHolder,
    // StringConverter.Default.<String>instance(),
    // null);
    this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_driver_class);
    c = this.addEditableCombo(container, lvmDriver, driverHolder, TransformerTools.<String>objectToStringTransformer(), (String) null);
    c.setLayoutData(gd);
    // addLabeledEditableCombo(
    // section,
    // HibernateConsoleMessages.NewConfigurationWizardPage_driver_class,
    // lvmDriver,
    // driverHolder,
    // StringConverter.Default.<String>instance(),
    // null);
    this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_connection_url);
    c = this.addEditableCombo(container, lvmUrl, urlHolder, TransformerTools.<String>objectToStringTransformer(), (String) null);
    c.setLayoutData(gd);
    // addLabeledEditableCombo(
    // section,
    // HibernateConsoleMessages.NewConfigurationWizardPage_connection_url,
    // lvmUrl,
    // urlHolder,
    // StringConverter.Default.<String>instance(),
    // null);
    dialectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, SWTListenerTools.wrap(new PropertyChangeListener() {

        @Override
        public void propertyChanged(PropertyChangeEvent event) {
            String dialectClass = HibernatePropertiesComposite.this.helper.getDialectClass((String) event.getNewValue());
            String[] driverClasses = HibernatePropertiesComposite.this.helper.getDriverClasses(dialectClass);
            // save value
            String driver = driverHolder.getValue();
            lvmDriver.clear();
            lvmDriver.addAll(Arrays.asList(driverClasses));
            // restore value
            driverHolder.setValue(driver);
        }
    }));
    driverHolder.addPropertyChangeListener(PropertyValueModel.VALUE, SWTListenerTools.wrap(new PropertyChangeListener() {

        @Override
        public void propertyChanged(PropertyChangeEvent event) {
            String driverClass = (String) event.getNewValue();
            String[] connectionURLS = HibernatePropertiesComposite.this.helper.getConnectionURLS(driverClass);
            // save value
            String url = urlHolder.getValue();
            lvmUrl.clear();
            lvmUrl.addAll(Arrays.asList(connectionURLS));
            // restore value
            urlHolder.setValue(url);
        }
    }));
    this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_default_schema);
    c = this.addText(container, buildSchemaDefaultHolder());
    c.setLayoutData(gd);
    // addLabeledText(
    // section,
    // HibernateConsoleMessages.NewConfigurationWizardPage_default_schema,
    // buildSchemaDefaultHolder());
    this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_default_catalog);
    c = this.addText(container, buildCatalogDefaultHolder());
    c.setLayoutData(gd);
    // addLabeledText(
    // section,
    // HibernateConsoleMessages.NewConfigurationWizardPage_default_catalog,
    // buildCatalogDefaultHolder());
    this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_user_name);
    c = this.addText(container, buildUsernameHolder());
    c.setLayoutData(gd);
    // addLabeledText(
    // section,
    // HibernateConsoleMessages.NewConfigurationWizardPage_user_name,
    // buildUsernameHolder());
    this.addLabel(container, HibernateConsoleMessages.NewConfigurationWizardPage_password);
    c = this.addText(container, buildPasswordHolder());
    c.setLayoutData(gd);
// addLabeledText(
// section,
// HibernateConsoleMessages.NewConfigurationWizardPage_password,
// buildPasswordHolder());
}
Also used : PropertyChangeEvent(org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent) PropertyChangeListener(org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener) ArrayList(java.util.ArrayList) SimpleListValueModel(org.eclipse.jpt.common.utility.internal.model.value.SimpleListValueModel) ModifiablePropertyValueModel(org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel) PropertyValueModel(org.eclipse.jpt.common.utility.model.value.PropertyValueModel) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) BasicHibernateProperties(org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties) DriverClassHelpers(org.hibernate.eclipse.console.utils.DriverClassHelpers)

Aggregations

ArrayList (java.util.ArrayList)1 SimpleListValueModel (org.eclipse.jpt.common.utility.internal.model.value.SimpleListValueModel)1 PropertyChangeEvent (org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent)1 PropertyChangeListener (org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener)1 ModifiablePropertyValueModel (org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel)1 PropertyValueModel (org.eclipse.jpt.common.utility.model.value.PropertyValueModel)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Control (org.eclipse.swt.widgets.Control)1 DriverClassHelpers (org.hibernate.eclipse.console.utils.DriverClassHelpers)1 BasicHibernateProperties (org.jboss.tools.hibernate.jpt.core.internal.context.basic.BasicHibernateProperties)1