diff options
author | pfullbright | 2009-01-29 00:02:11 +0000 |
---|---|---|
committer | pfullbright | 2009-01-29 00:02:11 +0000 |
commit | 009834095f222995ebf4fb51713f7c9e8677b998 (patch) | |
tree | 6856cef21cf9101b365f57d47af594d1c22ccd6d /jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse | |
parent | db2996076008f95c87a8f3409b16f1135c4d2e83 (diff) | |
download | webtools.dali-009834095f222995ebf4fb51713f7c9e8677b998.tar.gz webtools.dali-009834095f222995ebf4fb51713f7c9e8677b998.tar.xz webtools.dali-009834095f222995ebf4fb51713f7c9e8677b998.zip |
Library provider integration
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse')
3 files changed, 1193 insertions, 322 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java index 47c9f95c89..b53bbab9a7 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JptUiMessages.java @@ -52,6 +52,7 @@ public class JptUiMessages { public static String EnumComboViewer_defaultWithDefault; public static String Error_openingEditor; public static String General_browse; + public static String General_revert; public static String General_deselectAll; public static String General_selectAll; public static String GenerateDDLWizard_title; diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java index daace812e2..4e97bd3fc2 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/properties/JpaProjectPropertiesPage.java @@ -10,25 +10,77 @@ package org.eclipse.jpt.ui.internal.properties; import java.lang.reflect.InvocationTargetException; - +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.IncrementalProjectBuilder; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jpt.core.JpaDataSource; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.internal.JpaModelManager; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; -import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProvider; +import org.eclipse.jpt.core.internal.JptCoreMessages; +import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry; +import org.eclipse.jpt.db.ConnectionAdapter; +import org.eclipse.jpt.db.ConnectionListener; import org.eclipse.jpt.db.ConnectionProfile; +import org.eclipse.jpt.db.ConnectionProfileListener; +import org.eclipse.jpt.db.Database; import org.eclipse.jpt.db.JptDbPlugin; +import org.eclipse.jpt.db.Schema; import org.eclipse.jpt.db.ui.internal.DTPUiTools; -import org.eclipse.jpt.ui.JptUiPlugin; import org.eclipse.jpt.ui.internal.JpaHelpContextIds; import org.eclipse.jpt.ui.internal.JptUiMessages; +import org.eclipse.jpt.ui.internal.swt.BooleanButtonModelAdapter; +import org.eclipse.jpt.ui.internal.swt.ComboModelAdapter; +import org.eclipse.jpt.ui.internal.util.ControlEnabler; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.StringConverter; import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; +import org.eclipse.jpt.utility.internal.model.value.AspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.BufferedWritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.CachingTransformationPropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.CollectionListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.CompositeCollectionValueModel; +import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; +import org.eclipse.jpt.utility.internal.model.value.ListPropertyValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyCollectionValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationWritablePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.BufferedWritablePropertyValueModel.Trigger; +import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.model.listener.ChangeListener; +import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; +import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.model.value.CollectionValueModel; +import org.eclipse.jpt.utility.model.value.ListValueModel; +import org.eclipse.jpt.utility.model.value.PropertyValueModel; +import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; +import org.eclipse.jst.common.project.facet.ui.libprov.FacetLibraryPropertyPage; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -42,81 +94,246 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Link; import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; import org.eclipse.wst.common.project.facet.core.IFacetedProject; +import org.eclipse.wst.common.project.facet.core.IProjectFacet; +import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; public class JpaProjectPropertiesPage - extends DataModelPropertyPage - implements JpaFacetDataModelProperties + extends FacetLibraryPropertyPage { public static final String PROP_ID= "org.eclipse.jpt.ui.jpaProjectPropertiesPage"; //$NON-NLS-1$ - private PlatformGroup platformGroup; - - private ConnectionGroup connectionGroup; - - private PersistentClassManagementGroup persistentClassManagementGroup; - - - /** - * Constructor for SamplePropertyPage. - */ + + private WritablePropertyValueModel<IProject> projectHolder; + + private PropertyValueModel<JpaProject> jpaProjectHolder; + + private Trigger trigger; + + private PropertyChangeListener validationListener; + + private BufferedWritablePropertyValueModel<String> platformIdModel; + + private BufferedWritablePropertyValueModel<String> connectionModel; + + private ListValueModel<String> connectionChoicesModel; + + private PropertyValueModel<ConnectionProfile> connectionProfileModel; + + private BufferedWritablePropertyValueModel<Boolean> overrideDefaultSchemaModel; + + private BufferedWritablePropertyValueModel<String> defaultSchemaModel; + + private WritablePropertyValueModel<String> combinedDefaultSchemaModel; + + private ListValueModel<String> schemaChoicesModel; + + private BufferedWritablePropertyValueModel<Boolean> discoverAnnotatedClassesModel; + + private WritablePropertyValueModel<Boolean> listAnnotatedClassesModel; + + public JpaProjectPropertiesPage() { - super(DataModelFactory.createDataModel(new JpaFacetDataModelProvider())); + super(); + this.projectHolder = new SimplePropertyValueModel<IProject>(); + this.jpaProjectHolder = initializeJpaProjectHolder(); + this.trigger = new Trigger(); + this.validationListener = initializeValidationListener(); + this.platformIdModel = initializePlatformIdModel(); + this.connectionModel = initializeConnectionModel(); + this.connectionChoicesModel = initializeConnectionChoicesModel(); + this.connectionProfileModel = initializeConnectionProfileModel(); + this.overrideDefaultSchemaModel = initializeOverrideDefaultSchemaModel(); + this.defaultSchemaModel = initializeDefaultSchemaModel(); + this.combinedDefaultSchemaModel = initializeCombinedDefaultSchemaModel(); + this.schemaChoicesModel = initializeSchemaChoicesModel(); + this.discoverAnnotatedClassesModel = initializeDiscoverAnnotatedClassesModel(); + this.listAnnotatedClassesModel = initializeListAnnotatedClassesModel(); } - - + + + protected PropertyValueModel<JpaProject> initializeJpaProjectHolder() { + return new JpaProjectHolder(this.projectHolder); + } + + protected PropertyChangeListener initializeValidationListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + if (! JpaProjectPropertiesPage.this.getControl().isDisposed()) { + updateValidation(); + } + } + }; + } + + protected BufferedWritablePropertyValueModel<String> initializePlatformIdModel() { + BufferedWritablePropertyValueModel<String> model = + new BufferedWritablePropertyValueModel( + new PlatformIdModel(this.jpaProjectHolder), this.trigger); + model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); + return model; + } + + protected BufferedWritablePropertyValueModel<String> initializeConnectionModel() { + BufferedWritablePropertyValueModel<String> model = + new BufferedWritablePropertyValueModel( + new ConnectionModel(this.jpaProjectHolder), this.trigger); + model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); + return model; + } + + protected ListValueModel<String> initializeConnectionChoicesModel() { + return new SortedListValueModelAdapter( + new CollectionListValueModelAdapter( + new ConnectionChoicesModel(this.projectHolder))); + } + + protected PropertyValueModel<ConnectionProfile> initializeConnectionProfileModel() { + return new CachingTransformationPropertyValueModel<String, ConnectionProfile>(this.connectionModel) { + @Override + protected ConnectionProfile transform_(String value) { + return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(value); + } + }; + } + + protected BufferedWritablePropertyValueModel<Boolean> initializeOverrideDefaultSchemaModel() { + BufferedWritablePropertyValueModel<Boolean> model = + new BufferedWritablePropertyValueModel( + new OverrideDefaultSchemaModel(this.jpaProjectHolder), + this.trigger); + model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); + return model; + + } + + protected BufferedWritablePropertyValueModel<String> initializeDefaultSchemaModel() { + return new BufferedWritablePropertyValueModel( + new DefaultSchemaModel(this.jpaProjectHolder), + new DefaultSchemaTrigger(this.trigger, this.overrideDefaultSchemaModel)); + } + + protected WritablePropertyValueModel<String> initializeCombinedDefaultSchemaModel() { + WritablePropertyValueModel<String> model = + new CombinedDefaultSchemaModel( + this.defaultSchemaModel, + this.overrideDefaultSchemaModel, + new DefaultDefaultSchemaModel(this.connectionProfileModel)); + model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); + return model; + } + + protected ListValueModel<String> initializeSchemaChoicesModel() { + Collection<CollectionValueModel> cvms = new ArrayList<CollectionValueModel>(); + cvms.add(new PropertyCollectionValueModelAdapter(this.defaultSchemaModel)); + cvms.add(new SchemaChoicesModel(this.connectionProfileModel)); + return new SortedListValueModelAdapter( + new CompositeCollectionValueModel<CollectionValueModel, String>(cvms) { + @Override + public Iterator<String> iterator() { + Set<String> uniqueValues = new HashSet<String>(); + for (String each : CollectionTools.iterable(super.iterator())) { + if (each != null) { + uniqueValues.add(each); + } + } + return uniqueValues.iterator(); + } + }); + } + + protected BufferedWritablePropertyValueModel<Boolean> initializeDiscoverAnnotatedClassesModel() { + BufferedWritablePropertyValueModel<Boolean> model = + new BufferedWritablePropertyValueModel( + new DiscoverAnnotatedClassesModel(this.jpaProjectHolder), this.trigger); + model.addPropertyChangeListener(PropertyValueModel.VALUE, this.validationListener); + return model; + } + + protected WritablePropertyValueModel<Boolean> initializeListAnnotatedClassesModel() { + return new TransformationWritablePropertyValueModel<Boolean, Boolean>( + this.discoverAnnotatedClassesModel) { + @Override + protected Boolean transform_(Boolean value) { + return ! value; + } + + @Override + protected Boolean reverseTransform_(Boolean value) { + return ! value; + } + }; + } + + protected JpaProject getJpaProject() { + return this.jpaProjectHolder.getValue(); + } + + protected String getConnectionName() { + return this.connectionModel.getValue(); + } + + protected ConnectionProfile getConnectionProfile() { + // we just use the connection profile to log in, so go to the db plug-in + return JptDbPlugin.instance().getConnectionProfileFactory(). + buildConnectionProfile(getConnectionName()); + } + + protected Boolean getOverrideDefaultSchema() { + return this.overrideDefaultSchemaModel.getValue(); + } + + protected List<String> getDefaultSchemaChoices() { + return CollectionTools.list(this.schemaChoicesModel.iterator()); + } + + protected String getDefaultSchema() { + return this.defaultSchemaModel.getValue(); + } + + @Override + public IProjectFacetVersion getProjectFacetVersion() { + final IProjectFacet jsfFacet = ProjectFacetsManager.getProjectFacet( "jpt.jpa" ); + final IFacetedProject fproj = getFacetedProject(); + return fproj.getInstalledVersion( jsfFacet ); + } + @Override - protected Composite createTopLevelComposite(Composite parent) { + protected Control createPageContents(Composite parent) { + this.projectHolder.setValue(getProject()); + Composite composite = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); + layout.marginWidth = 0; + layout.marginHeight = 0; composite.setLayout(layout); + + new PlatformGroup(composite); + + Control libraryProviderComposite = super.createPageContents(composite); + libraryProviderComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + new ConnectionGroup(composite); + new PersistentClassManagementGroup(composite); - platformGroup = new PlatformGroup(composite); - connectionGroup = new ConnectionGroup(composite); - persistentClassManagementGroup = new PersistentClassManagementGroup(composite); - - setRuntime(); - - Dialog.applyDialogFont(parent); + Dialog.applyDialogFont(composite); PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE); - + + updateValidation(); + return composite; } - - private void setRuntime() { - if (getJpaProject() == null) { - return; - } - IFacetedProject facetedProject = null; - try { - facetedProject = ProjectFacetsManager.create(getJpaProject().getProject()); - } - catch (CoreException ce) { - JptUiPlugin.log(ce); - return; - } - IRuntime runtime = facetedProject.getPrimaryRuntime(); - model.setProperty(JpaFacetDataModelProperties.RUNTIME, runtime); - } - - @Override - protected String[] getValidationPropertyNames() { - return new String[] { - JpaFacetDataModelProperties.PLATFORM_ID, - JpaFacetDataModelProperties.CONNECTION, - JpaFacetDataModelProperties.USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, - JpaFacetDataModelProperties.USER_OVERRIDE_DEFAULT_SCHEMA, - JpaFacetDataModelProperties.DISCOVER_ANNOTATED_CLASSES - }; - } - - protected JpaProject getJpaProject() { - return (JpaProject) this.getElement().getAdapter(JpaProject.class); + + Button createButton(Composite container, int span, String text, int style) { + Button button = new Button(container, SWT.NONE | style); + button.setText(text); + GridData gd = new GridData(); + gd.horizontalSpan = span; + button.setLayoutData(gd); + return button; } - + Combo createCombo(Composite container, int span, boolean fillHorizontal) { Combo combo = new Combo(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); GridData gd; @@ -130,144 +347,837 @@ public class JpaProjectPropertiesPage combo.setLayoutData(gd); return combo; } - - Button createButton(Composite container, int span, String text, int style) { - Button button = new Button(container, SWT.NONE | style); - button.setText(text); - GridData gd = new GridData(); - gd.horizontalSpan = span; - button.setLayoutData(gd); - return button; + + @Override + public boolean performOk() { + super.performOk(); + + final IWorkspaceRunnable wr = new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) + throws CoreException { + performOkInternal(monitor); + } + }; + + IRunnableWithProgress op = new IRunnableWithProgress() { + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + try { + IWorkspace ws = ResourcesPlugin.getWorkspace(); + ws.run(wr, ws.getRoot(), IWorkspace.AVOID_UPDATE, monitor); + } + catch(CoreException e) { + throw new InvocationTargetException(e); + } + } + }; + + try { + new ProgressMonitorDialog(getShell()).run(true, false, op); + } + catch (InterruptedException e) { + return false; + } + catch (InvocationTargetException e) { + final Throwable te = e.getTargetException(); + throw new RuntimeException(te); + } + + return true; } - + + private void performOkInternal(IProgressMonitor monitor) + throws CoreException { + if (this.platformIdModel.isBuffering()) { + this.trigger.accept(); + JpaModelManager.instance().rebuildJpaProject(getProject()); + getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor); + } + else if (this.connectionModel.isBuffering() + || this.defaultSchemaModel.isBuffering() + || this.discoverAnnotatedClassesModel.isBuffering()) { + this.trigger.accept(); + getProject().build(IncrementalProjectBuilder.FULL_BUILD, monitor); + } + } + @Override protected void performDefaults() { - platformGroup.performDefaults(); - connectionGroup.performDefaults(); - persistentClassManagementGroup.performDefaults(); + super.performDefaults(); + this.trigger.reset(); } - + @Override - public boolean performOk() { - JpaProject jpaProject = this.getJpaProject(); - if (jpaProject == null) { - return true; // the facet has been uninstalled during our trip to the properties + protected IStatus performValidation() { + Map<Integer, List<IStatus>> statuses = new HashMap<Integer, List<IStatus>>(); + statuses.put(IStatus.ERROR, new ArrayList<IStatus>()); + statuses.put(IStatus.WARNING, new ArrayList<IStatus>()); + statuses.put(IStatus.INFO, new ArrayList<IStatus>()); + statuses.put(IStatus.OK, CollectionTools.list(Status.OK_STATUS)); + + /* validate platform */ + // user is unable to unset the platform, so no validation necessary + + /* library provider */ + IStatus lpStatus = super.performValidation(); + statuses.get(lpStatus.getSeverity()).add(lpStatus); + + /* validate connection */ + String connectionName = getConnectionName(); + ConnectionProfile connectionProfile = getConnectionProfile(); + if (! StringTools.stringIsEmpty(connectionName)) { + if (connectionProfile == null) { + statuses.get(IStatus.ERROR).add( + buildErrorStatus( + NLS.bind( + JptCoreMessages.VALIDATE_CONNECTION_INVALID, + connectionName))); + } + if (! connectionProfile.isActive()) { + statuses.get(IStatus.INFO).add( + buildInfoStatus( + JptCoreMessages.VALIDATE_CONNECTION_NOT_CONNECTED)); + } } - - boolean change = false; - boolean platformChange = false; - - IProject project = jpaProject.getProject(); - - String platform = this.model.getStringProperty(JpaFacetDataModelProperties.PLATFORM_ID); - if ( ! platform.equals(jpaProject.getJpaPlatform().getId())) { - change = true; - platformChange = true; - JptCorePlugin.setJpaPlatformId(project, platform); + + /* default schema */ + if (getOverrideDefaultSchema()) { + String defaultSchema = getDefaultSchema(); + if (StringTools.stringIsEmpty(defaultSchema)) { + statuses.get(IStatus.ERROR).add( + buildErrorStatus( + JptCoreMessages.VALIDATE_DEFAULT_SCHEMA_NOT_SPECIFIED)); + } + else if (connectionProfile != null + && connectionProfile.isConnected() + && ! getDefaultSchemaChoices().contains(defaultSchema)) { + statuses.get(IStatus.WARNING).add( + buildWarningStatus( + NLS.bind( + JptCoreMessages.VALIDATE_CONNECTION_DOESNT_CONTAIN_SCHEMA, + defaultSchema))); + } } - - String connection = this.model.getStringProperty(JpaFacetDataModelProperties.CONNECTION); - if ( ! connection.equals(jpaProject.getDataSource().getConnectionProfileName())) { - change = true; - jpaProject.getDataSource().setConnectionProfileName(connection); - JptCorePlugin.setConnectionProfileName(project, connection); + + if (! statuses.get(IStatus.ERROR).isEmpty()) { + return statuses.get(IStatus.ERROR).get(0); + } + else if (! statuses.get(IStatus.WARNING).isEmpty()) { + return statuses.get(IStatus.WARNING).get(0); + } + else if (! statuses.get(IStatus.INFO).isEmpty()) { + return statuses.get(IStatus.INFO).get(0); } + else { + return statuses.get(IStatus.OK).get(0); + } + } + + private IStatus buildInfoStatus(String message) { + return buildStatus(IStatus.INFO, message); + } + + private IStatus buildWarningStatus(String message) { + return buildStatus(IStatus.WARNING, message); + } + + private IStatus buildErrorStatus(String message) { + return buildStatus(IStatus.ERROR, message); + } + + private IStatus buildStatus(int severity, String message) { + return new Status(severity, JptCorePlugin.PLUGIN_ID, message); + } + + + private static abstract class BasePropertyAspectAdapter<S, V> + extends AspectAdapter<S> + implements WritablePropertyValueModel<V> + { + /** + * Cache the current value so we can pass an old value when we fire a + * property change event + */ + protected V value; - String userOverrideDefaultSchema = null; - if (this.model.getBooleanProperty(JpaFacetDataModelProperties.USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA)) { - userOverrideDefaultSchema = this.model.getStringProperty(JpaFacetDataModelProperties.USER_OVERRIDE_DEFAULT_SCHEMA); + + protected BasePropertyAspectAdapter(PropertyValueModel<S> subjectHolder) { + super(subjectHolder); + this.value = null; } - String projectUserOverrideDefaultSchema = jpaProject.getUserOverrideDefaultSchema(); - if (! StringTools.stringsAreEqualIgnoreCase(userOverrideDefaultSchema, projectUserOverrideDefaultSchema)) { - change = true; - jpaProject.setUserOverrideDefaultSchema(userOverrideDefaultSchema); - JptCorePlugin.setUserOverrideDefaultSchemaName(project, userOverrideDefaultSchema); + + + // ************ WritablePropertyValueModel impl ************************ + + @Override + public V getValue() { + return this.value; } - - boolean discover = this.model.getBooleanProperty(JpaFacetDataModelProperties.DISCOVER_ANNOTATED_CLASSES); - if (discover != jpaProject.discoversAnnotatedClasses()) { - change = true; - jpaProject.setDiscoversAnnotatedClasses(discover); - JptCorePlugin.setDiscoverAnnotatedClasses(project, discover); + + public final void setValue(V value) { + if (this.subject != null) { + setValue_(value); + } } - - if (platformChange) { - JpaModelManager.instance().rebuildJpaProject(project); + + protected void setValue_(V value) { + throw new UnsupportedOperationException("setValue"); } - if (change) { - buildProject(project); + + + // ************ AspectAdapter impl ************************************* + + @Override + protected Class<? extends ChangeListener> getListenerClass() { + return PropertyChangeListener.class; + } + + @Override + protected String getListenerAspectName() { + return VALUE; + } + + @Override + protected boolean hasListeners() { + return hasAnyPropertyChangeListeners(VALUE); + } + + @Override + protected void fireAspectChange(Object oldValue, Object newValue) { + firePropertyChanged(VALUE, oldValue, newValue); + } + + @Override + protected void engageSubject_() { + this.value = buildValue(); + } + + @Override + protected void disengageSubject_() { + this.value = null; + } + + @Override + public void toString(StringBuilder sb) { + sb.append(this.getValue()); + } + + + // ************ internal *********************************************** + + protected V buildValue() { + if (this.subject != null) { + return buildValue_(); + } + return null; + } + + protected abstract V buildValue_(); + + protected void valueChanged() { + V oldValue = this.getValue(); + this.value = buildValue(); + this.fireAspectChange(oldValue, this.getValue()); } - return true; } - - private static void buildProject(final IProject project) { - IRunnableWithProgress r= new IRunnableWithProgress() { - public void run(IProgressMonitor pm) throws InvocationTargetException { - try { - project.build(IncrementalProjectBuilder.FULL_BUILD, pm); - } - catch (CoreException ce) { - JptUiPlugin.log(ce); + + + private abstract static class BaseCollectionAspectAdapter<S, E> + extends AspectAdapter<S> + implements CollectionValueModel<E> + { + protected BaseCollectionAspectAdapter(PropertyValueModel<? extends S> subjectHolder) { + super(subjectHolder); + } + + + // ************ ListValueModel impl ************************************ + + public Iterator<E> iterator() { + return this.subject == null ? EmptyIterator.<E>instance() : this.iterator_(); + } + + public int size() { + return this.subject == null ? 0 : this.size_(); + } + + + // ************ AspectAdapter impl ************************************* + + @Override + protected Object getValue() { + return this.iterator(); + } + + @Override + protected Class<? extends ChangeListener> getListenerClass() { + return CollectionChangeListener.class; + } + + @Override + protected String getListenerAspectName() { + return VALUES; + } + + @Override + protected boolean hasListeners() { + return this.hasAnyCollectionChangeListeners(VALUES); + } + + @Override + protected void fireAspectChange(Object oldValue, Object newValue) { + this.fireCollectionChanged(VALUES); + } + + + // ************ internal *********************************************** + + protected Iterator<E> iterator_() { + throw new UnsupportedOperationException(); + } + + protected int size_() { + return CollectionTools.size(this.iterator()); + } + + protected void collectionChanged() { + this.fireCollectionChanged(VALUES); + } + } + + + private static class JpaProjectHolder + extends BasePropertyAspectAdapter<IProject, JpaProject> + { + /** + * Listens to the preferences to determine if the project's platform + * has changed, and is therefore a new JPA project + */ + private IPreferenceChangeListener platformChangeListener; + + + private JpaProjectHolder(PropertyValueModel<IProject> projectHolder) { + super(projectHolder); + this.platformChangeListener = buildPlatformChangeListener(); + } + + + // ************ initialization ***************************************** + + private IPreferenceChangeListener buildPlatformChangeListener() { + return new IPreferenceChangeListener() { + public void preferenceChange(PreferenceChangeEvent event) { + if (JptCorePlugin.JPA_PLATFORM.equals(event.getKey())) { + JpaProjectHolder.this.valueChanged(); + } } - } - }; - try { - PlatformUI.getWorkbench().getProgressService().run(true, false, r); + }; + } + + + // ************ AspectAdapter impl ************************************* + + @Override + protected void engageSubject_() { + IEclipsePreferences preferences = JptCorePlugin.getProjectPreferences(this.subject); + preferences.addPreferenceChangeListener(this.platformChangeListener); + super.engageSubject_(); + } + + @Override + protected void disengageSubject_() { + IEclipsePreferences preferences = JptCorePlugin.getProjectPreferences(this.subject); + preferences.removePreferenceChangeListener(this.platformChangeListener); + super.disengageSubject_(); + } + + + // ************ internal *********************************************** + + @Override + protected JpaProject buildValue_() { + return JptCorePlugin.getJpaProject(this.subject); } - catch (InterruptedException ie) { /* nothing to do */ } - catch (InvocationTargetException ie) { /* nothing to do */ } } - - - private final class PlatformGroup + + + private static class PlatformIdModel + extends BasePropertyAspectAdapter<JpaProject, String> { - final Combo platformCombo; + private PlatformIdModel(PropertyValueModel<JpaProject> jpaProjectHolder) { + super(jpaProjectHolder); + } - public PlatformGroup(Composite composite) { + // ************ WritablePropertyValueModel impl ************************ + + @Override + public void setValue_(String newPlatformId) { + JptCorePlugin.setJpaPlatformId(this.subject.getProject(), newPlatformId); + } + + + // ************ internal *********************************************** + + @Override + protected String buildValue_() { + return JptCorePlugin.getJpaPlatformId(this.subject.getProject()); + } + } + + + private final class PlatformGroup + { + private PlatformGroup(Composite composite) { Group group = new Group(composite, SWT.NONE); group.setText(JptUiMessages.JpaFacetWizardPage_platformLabel); group.setLayout(new GridLayout()); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // TODO - // PlatformUI.getWorkbench().getHelpSystem().setHelp(group, IDaliHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_DATABASE); - platformCombo = createCombo(group, 1, true); - synchHelper.synchCombo(platformCombo, PLATFORM_ID, null); - platformCombo.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - JpaProjectPropertiesPage.this.connectionGroup.updateConnectLink(); + Combo platformCombo = createCombo(group, 1, true); + + ComboModelAdapter.adapt( + buildPlatformChoicesListValueModel(), + JpaProjectPropertiesPage.this.platformIdModel, + platformCombo, + buildPlatformLabelConverter()); + } + + + private ListValueModel<String> buildPlatformChoicesListValueModel() { + return new SimpleListValueModel( + CollectionTools.list(JpaPlatformRegistry.instance().jpaPlatformIds())); + } + + private StringConverter<String> buildPlatformLabelConverter() { + return new StringConverter<String>() { + public String convertToString(String platformId) { + return JpaPlatformRegistry.instance().getJpaPlatformLabel(platformId); + } + }; + } + } + + + private static class ConnectionModel + extends BasePropertyAspectAdapter<JpaProject, String> + { + private PropertyChangeListener connectionChangeListener; + + + private ConnectionModel(PropertyValueModel<JpaProject> jpaProjectHolder) { + super(jpaProjectHolder); + this.connectionChangeListener = buildConnectionChangeListener(); + } + + + // ************ initialization ***************************************** + + private PropertyChangeListener buildConnectionChangeListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + ConnectionModel.this.valueChanged(); + } + }; + } + + + // ************ WritablePropertyValueModel impl ************************ + + @Override + public void setValue_(String newConnection) { + JptCorePlugin.setConnectionProfileName(this.subject.getProject(), newConnection); + } + + + // ************ AspectAdapter impl ************************************* + + @Override + protected void engageSubject_() { + JpaDataSource dataSource = this.subject.getDataSource(); + dataSource.addPropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener); + super.engageSubject_(); + } + + @Override + protected void disengageSubject_() { + JpaDataSource dataSource = this.subject.getDataSource(); + dataSource.removePropertyChangeListener(JpaDataSource.CONNECTION_PROFILE_NAME_PROPERTY, this.connectionChangeListener); + super.disengageSubject_(); + } + + + // ************ internal *********************************************** + + @Override + protected String buildValue_() { + return JptCorePlugin.getConnectionProfileName(this.subject.getProject()); + } + } + + + private static class ConnectionChoicesModel + extends BaseCollectionAspectAdapter<IProject, String> + { + private ConnectionProfileListener connectionProfileListener; + + + private ConnectionChoicesModel(PropertyValueModel<IProject> subjectHolder) { + super(subjectHolder); + this.connectionProfileListener = buildConnectionProfileListener(); + } + + + // ************ initialization ***************************************** + + private ConnectionProfileListener buildConnectionProfileListener() { + return new ConnectionProfileListener() { + public void connectionProfileAdded(String name) { + collectionChanged(); + } + + public void connectionProfileRemoved(String name) { + collectionChanged(); + } + + public void connectionProfileRenamed(String oldName, String newName) { + // ignore this event for now. connecting a profile actually + // throws a connection renamed event, which messes up the + // list selection. there shouldn't be a connection renamed + // within the scope of this dialog anyhow. + // collectionChanged(); + } + }; + } + + + // ************ AspectAdapter impl ************************************* + + @Override + protected void engageSubject_() { + JptDbPlugin.instance().getConnectionProfileFactory(). + addConnectionProfileListener(this.connectionProfileListener); + } + + @Override + protected void disengageSubject_() { + JptDbPlugin.instance().getConnectionProfileFactory(). + removeConnectionProfileListener(this.connectionProfileListener); + } + + + // ************ internal *********************************************** + + @Override + protected Iterator<String> iterator_() { + return JptDbPlugin.instance().getConnectionProfileFactory().connectionProfileNames(); + } + } + + + private static class OverrideDefaultSchemaModel + extends BasePropertyAspectAdapter<JpaProject, Boolean> + { + // the superclass "value" is the *cached* value + private Boolean actualValue; + + + private OverrideDefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectHolder) { + super(jpaProjectHolder); + } + + + // ************ WritablePropertyValueModel impl ************************ + + @Override + public Boolean getValue() { + Boolean value = super.getValue(); + return (value == null) ? Boolean.FALSE : value; + } + + @Override + public void setValue_(Boolean newValue) { + this.actualValue = newValue; + valueChanged(); + } + + + // ************ AspectAdapter impl ************************************* + + @Override + protected void engageSubject_() { + this.actualValue = this.buildActualValue_(); + super.engageSubject_(); + } + + @Override + protected void disengageSubject_() { + this.actualValue = null; + super.disengageSubject_(); + } + + + // ************ internal *********************************************** + + @Override + protected Boolean buildValue_() { + return this.actualValue; + } + + protected Boolean buildActualValue_() { + return ! StringTools.stringIsEmpty(this.subject.getUserOverrideDefaultSchema()); + } + } + + + private static class DefaultSchemaModel + extends PropertyAspectAdapter<JpaProject, String> + { + private DefaultSchemaModel(PropertyValueModel<JpaProject> jpaProjectModel) { + super(jpaProjectModel, JpaProject.USER_OVERRIDE_DEFAULT_SCHEMA_PROPERTY); + } + + + // ************ WritablePropertyValueModel impl ************************ + + @Override + public void setValue_(String newSchema) { + this.subject.setUserOverrideDefaultSchema(newSchema); + } + + + // ************ internal *********************************************** + + @Override + protected String buildValue_() { + return this.subject.getUserOverrideDefaultSchema(); + } + } + + + private static class DefaultDefaultSchemaModel + extends BasePropertyAspectAdapter<ConnectionProfile, String> + { + private ConnectionListener connectionListener; + + + private DefaultDefaultSchemaModel( + PropertyValueModel<ConnectionProfile> connectionProfileModel) { + super(connectionProfileModel); + this.connectionListener = buildConnectionListener(); + } + + + // ************ initialization ***************************************** + + private ConnectionListener buildConnectionListener() { + return new ConnectionAdapter() { + @Override + public void opened(ConnectionProfile profile) { + if (profile.equals(DefaultDefaultSchemaModel.this.subject)) { + valueChanged(); + } + } + @Override + public void schemaChanged(ConnectionProfile profile, Schema schema) { + if (profile.equals(DefaultDefaultSchemaModel.this.subject)) { + valueChanged(); + } + } + }; + } + + + // ************ AspectAdapter impl ************************************* + + @Override + protected void engageSubject_() { + this.subject.addConnectionListener(this.connectionListener); + super.engageSubject_(); + } + + @Override + protected void disengageSubject_() { + this.subject.removeConnectionListener(this.connectionListener); + super.disengageSubject_(); + } + + + // ************ internal *********************************************** + + @Override + protected String buildValue_() { + Database db = this.subject.getDatabase(); + if (db == null) { + return null; + } + Schema schema = db.getDefaultSchema(); + return (schema == null) ? null : schema.getIdentifier(); + } + } + + + private static class CombinedDefaultSchemaModel + extends ListPropertyValueModelAdapter<String> + implements WritablePropertyValueModel<String> + { + private WritablePropertyValueModel<String> defaultSchemaModel; + + private PropertyValueModel<Boolean> overrideDefaultSchemaModel; + + private PropertyValueModel<String> defaultDefaultSchemaModel; + + + private CombinedDefaultSchemaModel( + WritablePropertyValueModel<String> defaultSchemaModel, + PropertyValueModel<Boolean> overrideDefaultSchemaModel, + PropertyValueModel<String> defaultDefaultSchemaModel) { + super( + new CompositeListValueModel( + CollectionTools.list( + new PropertyListValueModelAdapter<String>(defaultSchemaModel), + new PropertyListValueModelAdapter<Boolean>(overrideDefaultSchemaModel), + new PropertyListValueModelAdapter<String>(defaultDefaultSchemaModel) + ))); + this.defaultSchemaModel = defaultSchemaModel; + this.overrideDefaultSchemaModel = overrideDefaultSchemaModel; + this.defaultDefaultSchemaModel = defaultDefaultSchemaModel; + } + + + // ************ ListPropertyValueModelAdapter impl ********************* + + @Override + protected String buildValue() { + if (this.overrideDefaultSchemaModel.getValue()) { + return this.defaultSchemaModel.getValue(); + } + else { + return this.defaultDefaultSchemaModel.getValue(); + } + } + + + // ************ WritablePropertyValueModel impl ************************ + + public void setValue(String value) { + if (this.overrideDefaultSchemaModel.getValue()) { + this.defaultSchemaModel.setValue(value); + } + propertyChanged(); + } + } + + + private static class DefaultSchemaTrigger + extends Trigger + { + private Trigger parentTrigger; + + private PropertyValueModel<Boolean> overrideDefaultSchemaModel; + + + private DefaultSchemaTrigger( + Trigger parentTrigger, + PropertyValueModel<Boolean> overrideDefaultSchemaModel) { + super(); + this.parentTrigger = parentTrigger; + this.parentTrigger.addPropertyChangeListener( + VALUE, + new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + respondToParent(); + } + }); + this.overrideDefaultSchemaModel = overrideDefaultSchemaModel; + this.overrideDefaultSchemaModel.addPropertyChangeListener( + VALUE, + new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + respondToOverride(); } }); - - performDefaults(); } - void performDefaults() { - if (getJpaProject() == null) { - return; + + protected void respondToParent() { + if (this.parentTrigger.isAccepted()) { + if (this.overrideDefaultSchemaModel.getValue()) { + accept(); + } + } + else if (this.parentTrigger.isReset()) { + reset(); + } + } + + protected void respondToOverride() { + if (! this.overrideDefaultSchemaModel.getValue()) { + reset(); } - String platformId = getJpaProject().getJpaPlatform().getId(); - model.setProperty(PLATFORM_ID, platformId); } } - private final class ConnectionGroup + private static class SchemaChoicesModel + extends BaseCollectionAspectAdapter<ConnectionProfile, String> { - final Combo connectionCombo; - - private Link connectionLink; + private ConnectionListener connectionListener; - private Link connectLink; - private final Button overrideDefaultSchemaButton; + private SchemaChoicesModel(PropertyValueModel<ConnectionProfile> subjectHolder) { + super(subjectHolder); + this.connectionListener = buildConnectionListener(); + } + + + // ************ initialization ***************************************** + + private ConnectionListener buildConnectionListener() { + return new ConnectionAdapter() { + @Override + public void opened(ConnectionProfile profile) { + if (profile.equals(SchemaChoicesModel.this.subject)) { + collectionChanged(); + } + } + @Override + public void schemaChanged(ConnectionProfile profile, Schema schema) { + if (profile.equals(SchemaChoicesModel.this.subject)) { + collectionChanged(); + } + } + }; + } + + + // ************ AspectAdapter impl ************************************* + + @Override + protected void engageSubject_() { + this.subject.addConnectionListener(this.connectionListener); + } + + @Override + protected void disengageSubject_() { + this.subject.removeConnectionListener(this.connectionListener); + } + - private final Label defaultSchemaLabel; + // ************ internal *********************************************** - private final Combo defaultSchemaCombo; + @Override + protected Iterator<String> iterator_() { + return (this.subject.getDatabase() == null) ? + EmptyIterator.<String>instance() : + this.subject.getDatabase().sortedSchemaIdentifiers(); + } + } + + + private final class ConnectionGroup + { + private Link connectLink; public ConnectionGroup(Composite composite) { @@ -276,18 +1186,16 @@ public class JpaProjectPropertiesPage group.setLayout(new GridLayout(3, false)); group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - connectionCombo = createCombo(group, 3, true); PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.PROPERTIES_JAVA_PERSISTENCE_CONNECTION); - synchHelper.synchCombo(connectionCombo, CONNECTION, null); - connectionCombo.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - updateConnectLink(); - } - }); - connectionLink = new Link(group, SWT.NONE); + Combo connectionCombo = createCombo(group, 3, true); + + ComboModelAdapter.adapt( + JpaProjectPropertiesPage.this.connectionChoicesModel, + JpaProjectPropertiesPage.this.connectionModel, + connectionCombo); + + Link connectionLink = new Link(group, SWT.NONE); GridData data = new GridData(GridData.END, GridData.CENTER, false, false); data.horizontalSpan = 2; connectionLink.setLayoutData(data); @@ -306,7 +1214,7 @@ public class JpaProjectPropertiesPage data.horizontalSpan = 2; connectLink.setLayoutData(data); connectLink.setText(JptUiMessages.JpaFacetWizardPage_connectLink); - connectLink.setEnabled(false); + updateConnectLink(); connectLink.addSelectionListener( new SelectionAdapter() { @Override @@ -315,73 +1223,92 @@ public class JpaProjectPropertiesPage } }); - overrideDefaultSchemaButton = createButton(group, 3, JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, SWT.CHECK); - synchHelper.synchCheckbox(overrideDefaultSchemaButton, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, new Control[0]); + PropertyChangeListener linkUpdateListener = new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent event) { + updateConnectLink(); + } + }; + JpaProjectPropertiesPage.this.connectionModel.addPropertyChangeListener( + PropertyValueModel.VALUE, + linkUpdateListener); + - defaultSchemaLabel = new Label(group, SWT.LEFT); + Button overrideDefaultSchemaButton = createButton( + group, 3, + JptUiMessages.JpaFacetWizardPage_overrideDefaultSchemaLabel, + SWT.CHECK); + + BooleanButtonModelAdapter.adapt( + JpaProjectPropertiesPage.this.overrideDefaultSchemaModel, + overrideDefaultSchemaButton); + + Label defaultSchemaLabel = new Label(group, SWT.LEFT); defaultSchemaLabel.setText(JptUiMessages.JpaFacetWizardPage_defaultSchemaLabel); GridData gd = new GridData(); gd.horizontalSpan = 1; defaultSchemaLabel.setLayoutData(gd); - defaultSchemaCombo = createCombo(group, 1, true); - synchHelper.synchCombo( - defaultSchemaCombo, USER_OVERRIDE_DEFAULT_SCHEMA, - new Control[] {defaultSchemaLabel}); + Combo defaultSchemaCombo = createCombo(group, 1, true); - performDefaults(); + ComboModelAdapter.adapt( + JpaProjectPropertiesPage.this.schemaChoicesModel, + JpaProjectPropertiesPage.this.combinedDefaultSchemaModel, + defaultSchemaCombo); + + new ControlEnabler( + JpaProjectPropertiesPage.this.overrideDefaultSchemaModel, + defaultSchemaLabel, defaultSchemaCombo); } - void openNewConnectionWizard() { + private void openNewConnectionWizard() { String connectionName = DTPUiTools.createNewConnectionProfile(); if (connectionName != null) { - model.setProperty(CONNECTION, connectionName); + JpaProjectPropertiesPage.this.connectionModel.setValue(connectionName); } } - void openConnectionProfile() { - ConnectionProfile cp = this.getConnectionProfile(); + private void openConnectionProfile() { + ConnectionProfile cp = JpaProjectPropertiesPage.this.getConnectionProfile(); if (cp != null) { cp.connect(); } - model.setBooleanProperty(CONNECTION_ACTIVE, (cp != null) && cp.isActive()); - this.updateConnectLink(cp); - return; + updateConnectLink(); } - void updateConnectLink(ConnectionProfile cp) { - connectLink.setEnabled((cp != null) && cp.isDisconnected()); + private void updateConnectLink() { + ConnectionProfile cp = getConnectionProfile(); + this.connectLink.setEnabled((cp != null) && cp.isDisconnected()); } - - void updateConnectLink() { - this.updateConnectLink(this.getConnectionProfile()); + } + + + private class DiscoverAnnotatedClassesModel + extends PropertyAspectAdapter<JpaProject, Boolean> + { + private DiscoverAnnotatedClassesModel(PropertyValueModel<JpaProject> jpaProjectModel) { + super(jpaProjectModel, JpaProject.DISCOVERS_ANNOTATED_CLASSES_PROPERTY); } - ConnectionProfile getConnectionProfile() { - // we just use the connection profile to log in, so go to the db plug-in - return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(model.getStringProperty(CONNECTION)); + + // ************ WritablePropertyValueModel impl ************************ + + @Override + protected void setValue_(Boolean newValue) { + this.subject.setDiscoversAnnotatedClasses(newValue); } - - void performDefaults() { - if (getJpaProject() == null) { - return; - } - model.setProperty(CONNECTION, getJpaProject().getDataSource().getConnectionProfileName()); - - String defaultSchema = getJpaProject().getUserOverrideDefaultSchema(); - model.setProperty(USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, Boolean.valueOf(defaultSchema != null)); - model.setProperty(USER_OVERRIDE_DEFAULT_SCHEMA, defaultSchema); + + + // ************ internal *********************************************** + + @Override + protected Boolean buildValue_() { + return this.subject.discoversAnnotatedClasses(); } } - - + + private final class PersistentClassManagementGroup { - final Button discoverClassesButton; - - final Button listClassesButton; - - public PersistentClassManagementGroup(Composite composite) { Group group = new Group(composite, SWT.NONE); group.setText(JptUiMessages.JpaFacetWizardPage_persistentClassManagementLabel); @@ -389,21 +1316,17 @@ public class JpaProjectPropertiesPage group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH); - discoverClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_discoverClassesButton, SWT.RADIO); - synchHelper.synchRadio(discoverClassesButton, DISCOVER_ANNOTATED_CLASSES, null); + Button discoverClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_discoverClassesButton, SWT.RADIO); - listClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton, SWT.RADIO); - synchHelper.synchRadio(listClassesButton, LIST_ANNOTATED_CLASSES, null); + BooleanButtonModelAdapter.adapt( + JpaProjectPropertiesPage.this.discoverAnnotatedClassesModel, + discoverClassesButton); - performDefaults(); - } - - void performDefaults() { - if (getJpaProject() == null) { - return; - } - boolean discoverClasses = getJpaProject().discoversAnnotatedClasses(); - model.setProperty(DISCOVER_ANNOTATED_CLASSES, Boolean.valueOf(discoverClasses)); + Button listClassesButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_listClassesButton, SWT.RADIO); + + BooleanButtonModelAdapter.adapt( + JpaProjectPropertiesPage.this.listAnnotatedClassesModel, + listClassesButton); } } -}
\ No newline at end of file +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java index 7f1d0d3e40..dec0687556 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/wizards/JpaFacetWizardPage.java @@ -10,9 +10,7 @@ package org.eclipse.jpt.ui.internal.wizards; import org.eclipse.core.runtime.IStatus; -import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.preference.PreferenceDialog; import org.eclipse.jpt.core.internal.facet.JpaFacetDataModelProperties; import org.eclipse.jpt.db.ConnectionProfile; import org.eclipse.jpt.db.JptDbPlugin; @@ -21,7 +19,8 @@ import org.eclipse.jpt.ui.JptUiPlugin; import org.eclipse.jpt.ui.internal.JpaHelpContextIds; import org.eclipse.jpt.ui.internal.JptUiIcons; import org.eclipse.jpt.ui.internal.JptUiMessages; -import org.eclipse.jpt.ui.internal.prefs.JpaPreferencePage; +import org.eclipse.jst.common.project.facet.core.libprov.LibraryInstallDelegate; +import org.eclipse.jst.common.project.facet.ui.libprov.LibraryProviderFrameworkUi; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -35,8 +34,8 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Link; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PreferencesUtil; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.frameworks.datamodel.DataModelEvent; +import org.eclipse.wst.common.frameworks.datamodel.IDataModelListener; import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectEvent; import org.eclipse.wst.common.project.facet.core.events.IFacetedProjectListener; @@ -46,6 +45,7 @@ import org.eclipse.wst.web.ui.internal.wizards.DataModelFacetInstallPage; public class JpaFacetWizardPage extends DataModelFacetInstallPage implements JpaFacetDataModelProperties { + public JpaFacetWizardPage() { super("jpt.jpa.facet.install.page"); //$NON-NLS-1$ setTitle(JptUiMessages.JpaFacetWizardPage_title); @@ -53,7 +53,6 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage setImageDescriptor(JptUiPlugin.getImageDescriptor(JptUiIcons.JPA_WIZ_BANNER)); } - @Override protected Composite createTopLevelComposite(Composite parent) { Composite composite = new Composite(parent, SWT.NULL); @@ -61,8 +60,8 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage composite.setLayout(layout); new PlatformGroup(composite); - new ConnectionGroup(composite); new ClasspathConfigGroup(composite); + new ConnectionGroup(composite); new PersistentClassManagementGroup(composite); new OrmXmlGroup(composite); @@ -121,9 +120,8 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage DB_DRIVER_JARS, USER_WANTS_TO_OVERRIDE_DEFAULT_SCHEMA, USER_OVERRIDE_DEFAULT_SCHEMA, - USE_SERVER_JPA_IMPLEMENTATION, - JPA_LIBRARY, - DISCOVER_ANNOTATED_CLASSES + DISCOVER_ANNOTATED_CLASSES, + LIBRARY_PROVIDER_DELEGATE }; } @@ -133,7 +131,13 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage return false; } else { - return (model.validate().getSeverity() != IStatus.ERROR); + IStatus status =model.validate(); + if( status.getSeverity() == IStatus.ERROR){ + setErrorMessage( status.getMessage() ); + return false; + }; + setErrorMessage(null); + return true; } } @@ -162,8 +166,34 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage synchHelper.synchCombo(platformCombo, PLATFORM_ID, null); } } - - + + + private final class ClasspathConfigGroup + { + public ClasspathConfigGroup(Composite composite) { + + final LibraryInstallDelegate librariesInstallDelegate + = (LibraryInstallDelegate) getDataModel().getProperty(LIBRARY_PROVIDER_DELEGATE); + + getDataModel().addListener( + new IDataModelListener() { + public void propertyChanged(DataModelEvent event) { + if (event.getPropertyName().equals(JpaFacetDataModelProperties.PLATFORM_ID)) { + librariesInstallDelegate.refresh(); + } + } + }); + + final Composite librariesComposite + = (Composite) LibraryProviderFrameworkUi.createInstallLibraryPanel( + composite, librariesInstallDelegate, + JptUiMessages.JpaFacetWizardPage_jpaImplementationLabel ); + librariesComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + PlatformUI.getWorkbench().getHelpSystem().setHelp(librariesComposite, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH); + } + } + + private final class ConnectionGroup { private final Combo connectionCombo; @@ -288,91 +318,8 @@ public class JpaFacetWizardPage extends DataModelFacetInstallPage return JptDbPlugin.instance().getConnectionProfileFactory().buildConnectionProfile(model.getStringProperty(CONNECTION)); } } - - - private final class ClasspathConfigGroup - { - private final Button useServerLibButton; - - private final Button specifyLibButton; - - private final Combo jpaLibCombo; - - private final Link jpaPrefsLink; - - private final Link userLibsLink; - - - public ClasspathConfigGroup(Composite composite) { - Group group = new Group(composite, SWT.NONE); - group.setText(JptUiMessages.JpaFacetWizardPage_jpaImplementationLabel); - group.setLayout(new GridLayout(2, false)); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - PlatformUI.getWorkbench().getHelpSystem().setHelp(group, JpaHelpContextIds.NEW_JPA_PROJECT_CONTENT_PAGE_CLASSPATH); - - useServerLibButton = createButton(group, 2, JptUiMessages.JpaFacetWizardPage_userServerLibLabel, SWT.RADIO); - synchHelper.synchRadio(useServerLibButton, USE_SERVER_JPA_IMPLEMENTATION, null); - - specifyLibButton = createButton(group, 1, JptUiMessages.JpaFacetWizardPage_specifyLibLabel, SWT.RADIO); - synchHelper.synchRadio(specifyLibButton, USE_USER_JPA_LIBRARY, null); - - jpaLibCombo = createCombo(group, 1, true); - synchHelper.synchCombo(jpaLibCombo, JPA_LIBRARY, null); - - jpaPrefsLink = new Link(group, SWT.NONE); - GridData data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - jpaPrefsLink.setLayoutData(data); - jpaPrefsLink.setText(JptUiMessages.JpaFacetWizardPage_jpaPrefsLink); - jpaPrefsLink.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - promptToConfigJpaPrefs(); - } - } - ); - - userLibsLink = new Link(group, SWT.NONE); - data = new GridData(GridData.END, GridData.CENTER, false, false); - data.horizontalSpan = 2; - userLibsLink.setLayoutData(data); - userLibsLink.setText(JptUiMessages.JpaFacetWizardPage_userLibsLink); - userLibsLink.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - promptToConfigUserLibraries(); - } - } - ); - } - - private void promptToConfigJpaPrefs() { - PreferenceDialog dlg = - PreferencesUtil.createPreferenceDialogOn( - getShell(), - JpaPreferencePage.ID, - new String[] {JpaPreferencePage.ID}, - null); - dlg.open(); - model.notifyPropertyChange(JPA_LIBRARY, IDataModel.VALID_VALUES_CHG); - model.notifyPropertyChange(JPA_LIBRARY, IDataModel.DEFAULT_CHG); - } - - private void promptToConfigUserLibraries() { - PreferenceDialog dlg = - PreferencesUtil.createPreferenceDialogOn( - getShell(), - JavaUI.ID_USER_LIBRARY_PREFERENCE_PAGE, - new String[] {JavaUI.ID_USER_LIBRARY_PREFERENCE_PAGE}, - null); - dlg.open(); - model.notifyPropertyChange(JPA_LIBRARY, IDataModel.VALID_VALUES_CHG); - } - } - - + + private final class PersistentClassManagementGroup { private final Button discoverClassesButton; |