diff options
author | tle | 2008-03-25 21:20:54 +0000 |
---|---|---|
committer | tle | 2008-03-25 21:20:54 +0000 |
commit | 95262959db79e6dab6c3790f26a11d73e40d8a73 (patch) | |
tree | e8124590a6ad95b96d15b54575d5a875df869867 | |
parent | 65e732e686cc0421e8d64304c43cbb28c9ae919f (diff) | |
download | webtools.dali-95262959db79e6dab6c3790f26a11d73e40d8a73.tar.gz webtools.dali-95262959db79e6dab6c3790f26a11d73e40d8a73.tar.xz webtools.dali-95262959db79e6dab6c3790f26a11d73e40d8a73.zip |
Entity Caching - patch from Pascal
11 files changed, 467 insertions, 194 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties index 1569d66b17..24f49adfb1 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/property_files/eclipselink_ui.properties @@ -52,10 +52,10 @@ PersistenceXmlCachingTab_sectionTitle = Persistence Unit Caching PersistenceXmlCachingTab_sectionDescription = Configure the session or entity specific EclipseLink caching properties. PersistenceXmlCachingTab_defaultCacheTypeLabel = Default Cache Type: PersistenceXmlCachingTab_cacheTypeLabel = Cache Type: -PersistenceXmlCachingTab_defaultSharedCacheLabel = Default Shared Cache: +PersistenceXmlCachingTab_defaultSharedCacheLabel = Default Shared Cache PersistenceXmlCachingTab_sharedCacheLabel = Shared Cache: -PersistenceXmlCachingTab_defaultSharedCacheLabelDefault = Default Shared Cache ({0}) +PersistenceXmlCachingTab_defaultSharedCacheLabelDefault = Shared Cache ({0}) CacheTypeComposite_full = Full CacheTypeComposite_hard_weak = HardWeak diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EntityDialog.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EntityDialog.java index 9006ee5567..3b0a649ed4 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EntityDialog.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/EntityDialog.java @@ -3,7 +3,7 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation *******************************************************************************/ @@ -60,33 +60,25 @@ public class EntityDialog extends Dialog Composite composite = (Composite) super.createDialogArea(parent); GridLayout gridLayout = (GridLayout) composite.getLayout(); gridLayout.numColumns = 2; - + Label nameLabel = new Label(composite, SWT.LEFT); nameLabel.setText(EclipseLinkUiMessages.EntityDialog_name); GridData gridData = new GridData(); nameLabel.setLayoutData(gridData); - + this.nameCombo = new Combo(composite, SWT.LEFT); gridData = new GridData(); gridData.grabExcessHorizontalSpace = true; gridData.horizontalAlignment = SWT.FILL; this.nameCombo.setLayoutData(gridData); - + populateNameCombo(); return composite; } protected void populateNameCombo() { - // TODO - // Iterator<Entity> entities = this.jpaProject.entities(); - // for (Iterator<Entity> stream = CollectionTools.sort( entities); - // stream.hasNext(); ) { - // this.nameCombo.add( stream.next().getSpecifiedName()); - // } - if (getEntity() != null) { - if (getEntity().getSpecifiedName() != null) { - this.nameCombo.setText(getEntity().getSpecifiedName()); - } + if (selectedName != null) { + this.nameCombo.setText(selectedName); } } @@ -102,6 +94,10 @@ public class EntityDialog extends Dialog return this.selectedName; } + public void setSelectedName(String selectedName) { + this.selectedName = selectedName; + } + @Override public boolean close() { this.selectedName = this.nameCombo.getText(); diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/CacheSizeComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/CacheSizeComposite.java new file mode 100644 index 0000000000..7369beed4a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/CacheSizeComposite.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.eclipselink.ui.internal.caching; + +import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; +import org.eclipse.jpt.ui.internal.widgets.AbstractPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * CacheSizeComposite + */ +public class CacheSizeComposite extends AbstractPane<EntityCaching> +{ + /** + * Creates a new <code>CacheTypeComposite</code>. + * + * @param parentController + * The parent container of this one + * @param parent + * The parent container + */ + public CacheSizeComposite(AbstractPane<EntityCaching> parentComposite, + Composite parent) { + + super(parentComposite, parent); + } + + private WritablePropertyValueModel<Integer> buildCacheSizeHolder() { + return new PropertyAspectAdapter<EntityCaching, Integer>(getSubjectHolder(), Caching.CACHE_SIZE_PROPERTY) { + @Override + protected Integer buildValue_() { + Integer value = subject.getCacheSize(); + + if (value == null) { + value = -1; + } + + return value; + } + + @Override + protected void setValue_(Integer value) { + if (value == -1) { + value = null; + } + subject.setCacheSize(value); + } + }; + } + + @Override + protected void initializeLayout(Composite container) { + + buildLabeledSpinner( + container, + "Cache Size:", + buildCacheSizeHolder(), + -1, + -1, + Integer.MAX_VALUE, + null // TODO + ); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/CacheTypeComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/CacheTypeComposite.java index 42b3a9a09d..297bc8a274 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/CacheTypeComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/CacheTypeComposite.java @@ -3,48 +3,41 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation *******************************************************************************/ package org.eclipse.jpt.eclipselink.ui.internal.caching; import java.util.Collection; - import org.eclipse.jpt.eclipselink.core.internal.context.caching.CacheType; import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.AbstractPane; import org.eclipse.jpt.ui.internal.widgets.EnumFormComboViewer; -import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.swt.widgets.Composite; /** * CacheTypeComposite */ -public class CacheTypeComposite extends AbstractFormPane<Caching> +public class CacheTypeComposite extends AbstractPane<EntityCaching> { - private EntityListComposite entitiesComposite; - /** * Creates a new <code>CacheTypeComposite</code>. - * + * * @param parentController * The parent container of this one * @param parent * The parent container */ - public CacheTypeComposite( - AbstractFormPane<? extends Caching> parentComposite, - Composite parent, - EntityListComposite entitiesComposite) { + public CacheTypeComposite(AbstractPane<EntityCaching> parentComposite, + Composite parent) { super(parentComposite, parent); - this.entitiesComposite = entitiesComposite; } - private EnumFormComboViewer<Caching, CacheType> buildCacheTypeCombo(Composite container) { - return new EnumFormComboViewer<Caching, CacheType>(this, container) { + private EnumFormComboViewer<EntityCaching, CacheType> buildCacheTypeCombo(Composite container) { + return new EnumFormComboViewer<EntityCaching, CacheType>(this, container) { @Override protected void addPropertyNames(Collection<String> propertyNames) { super.addPropertyNames(propertyNames); @@ -68,27 +61,16 @@ public class CacheTypeComposite extends AbstractFormPane<Caching> @Override protected CacheType getValue() { - String entityName = CacheTypeComposite.this.getSelection(); - if (!StringTools.stringIsEmpty(entityName)) { - return this.subject().getCacheType(entityName); - } - return null; + return this.subject().getCacheType(); } @Override protected void setValue(CacheType value) { - String entityName = CacheTypeComposite.this.getSelection(); - if (!StringTools.stringIsEmpty(entityName)) { - this.subject().setCacheType(value, entityName); - } + this.subject().setCacheType(value); } }; } - protected String getSelection() { - return (String) this.entitiesComposite.listPane().getSelectionModel().selectedValue(); - } - @Override protected void initializeLayout(Composite container) { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/DefaultCacheSizeComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/DefaultCacheSizeComposite.java new file mode 100644 index 0000000000..3f2d5bfd75 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/DefaultCacheSizeComposite.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.eclipselink.ui.internal.caching; + +import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; +import org.eclipse.jpt.ui.internal.widgets.AbstractPane; +import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * CacheSizeComposite + */ +public class DefaultCacheSizeComposite extends AbstractPane<Caching> +{ + /** + * Creates a new <code>CacheTypeComposite</code>. + * + * @param parentController + * The parent container of this one + * @param parent + * The parent container + */ + public DefaultCacheSizeComposite(AbstractPane<Caching> parentComposite, + Composite parent) { + + super(parentComposite, parent); + } + + private WritablePropertyValueModel<Integer> buildCacheSizeHolder() { + return new PropertyAspectAdapter<Caching, Integer>(getSubjectHolder(), Caching.CACHE_SIZE_PROPERTY) { + @Override + protected Integer buildValue_() { + Integer value = subject.getDefaultCacheSize(); + + if (value == null) { + value = -1; + } + + return value; + } + + @Override + protected void setValue_(Integer value) { + if (value == -1) { + value = null; + } + subject.setCacheSizeDefault(value); + } + }; + } + + @Override + protected void initializeLayout(Composite container) { + + buildLabeledSpinner( + container, + "Default Cache Size:", + buildCacheSizeHolder(), + -1, + -1, + Integer.MAX_VALUE, + null // TODO + ); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/DefaultSharedCacheComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/DefaultSharedCacheComposite.java index b7129cd86f..9f5a660de6 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/DefaultSharedCacheComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/DefaultSharedCacheComposite.java @@ -3,7 +3,7 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. - * + * * Contributors: * Oracle - initial API and implementation *******************************************************************************/ @@ -20,22 +20,22 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Composite; /** - * DefaultShareCacheComposite + * DefaultShareCacheComposite */ public class DefaultSharedCacheComposite extends AbstractFormPane<Caching> { /** * Creates a new <code>DefaultShareCacheComposite</code>. - * + * * @param parentController * The parent container of this one * @param parent * The parent container */ public DefaultSharedCacheComposite( - AbstractFormPane<? extends Caching> parentComposite, + AbstractFormPane<? extends Caching> parentComposite, Composite parent) { - + super(parentComposite, parent); } @@ -50,6 +50,18 @@ public class DefaultSharedCacheComposite extends AbstractFormPane<Caching> protected void setValue_(Boolean value) { subject.setSharedCacheDefault(value); } + + @Override + protected void subjectChanged() { + Object oldValue = this.value(); + super.subjectChanged(); + Object newValue = this.value(); + + // Make sure the default value is appended to the text + if (oldValue == newValue && newValue == null) { + this.fireAspectChange(Boolean.TRUE, newValue); + } + } }; } diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCaching.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCaching.java new file mode 100644 index 0000000000..8cffdab24f --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCaching.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.ui.internal.caching; + +import org.eclipse.jpt.eclipselink.core.internal.context.caching.CacheType; +import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.utility.internal.model.AbstractModel; + +/** + * @version 2.0 + * @since 2.0 + */ +public class EntityCaching extends AbstractModel { + + private Caching caching; + private String entityName; + + /** + * Creates a new <code>EntityCaching</code>. + * + * @param caching + * @param entityName + */ + public EntityCaching(Caching caching, String entityName) { + super(); + this.caching = caching; + this.entityName = entityName; + } + + public boolean entityNameIsValid() { + return !StringTools.stringIsEmpty(this.entityName); + } + + public Integer getCacheSize() { + return this.caching.getCacheSize(this.entityName); + } + + public CacheType getCacheType() { + return this.caching.getCacheType(this.entityName); + } + + public CacheType getDefaultCacheType() { + return this.caching.getDefaultCacheType(); + } + + public String getEntityName() { + return this.entityName; + } + + public Boolean getSharedCache() { + return this.caching.getSharedCache(this.entityName); + } + + public Boolean getSharedCacheDefault() { + return this.caching.getSharedCacheDefault(); + } + + public void setCacheSize(Integer cachingSize) { + this.caching.setCacheSize(cachingSize, this.entityName); + } + + public void setCacheType(CacheType cacheType) { + this.caching.setCacheType(cacheType, this.entityName); + } + + public void setSharedCache(Boolean sharedCache) { + this.caching.setSharedCache(sharedCache, this.entityName); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCachingPropertyComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCachingPropertyComposite.java new file mode 100644 index 0000000000..49de503f33 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityCachingPropertyComposite.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2008 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.eclipselink.ui.internal.caching; + +import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; +import org.eclipse.jpt.ui.internal.widgets.AbstractPane; +import org.eclipse.jpt.utility.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Composite; + +/** + * @version 2.0 + * @since 2.0 + */ +public class EntityCachingPropertyComposite extends AbstractPane<EntityCaching> { + + /** + * Creates a new <code>EntityCachingPropertyComposite</code>. + * + * @param parentPane The parent container of this one + * @param subjectHolder The holder of this pane's subject + * @param parent The parent container + */ + public EntityCachingPropertyComposite(AbstractPane<Caching> parentComposite, + PropertyValueModel<EntityCaching> subjectHolder, + Composite parent) { + + super(parentComposite, subjectHolder, parent); + } + + /* + * (non-Javadoc) + */ + @Override + protected void initializeLayout(Composite container) { + + // Cache Type + new CacheTypeComposite(this, container); + + // Cache Size + new CacheSizeComposite(this, container); + + // Share Cache + new ShareCacheComposite(this, container); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityListComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityListComposite.java index 927dee3582..de15b4b542 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityListComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/EntityListComposite.java @@ -3,25 +3,26 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. -* +* * Contributors: * Oracle - initial API and implementation *******************************************************************************/ package org.eclipse.jpt.eclipselink.ui.internal.caching; import java.util.ListIterator; - import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.window.Window; import org.eclipse.jpt.core.JpaProject; -import org.eclipse.jpt.core.context.Entity; import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; import org.eclipse.jpt.eclipselink.ui.internal.EntityDialog; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.util.PaneEnabler; +import org.eclipse.jpt.ui.internal.widgets.AbstractPane; import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.internal.model.value.TransformationListValueModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; import org.eclipse.jpt.utility.model.value.ListValueModel; import org.eclipse.jpt.utility.model.value.PropertyValueModel; @@ -31,58 +32,99 @@ import org.eclipse.swt.widgets.Composite; /** * EntityListComposite */ -public class EntityListComposite extends AbstractFormPane<Caching> +public class EntityListComposite extends AbstractPane<Caching> { - private AddRemoveListPane<Caching> listPane; - - public EntityListComposite( - AbstractFormPane<Caching> parentComposite, - PropertyValueModel<Caching> subjectHolder, - Composite parent) { + public EntityListComposite(AbstractPane<Caching> parentComposite, + Composite parent) { - super(parentComposite, subjectHolder, parent); + super(parentComposite, parent); } - + @Override - protected void initializeLayout(Composite composite) { + protected void initializeLayout(Composite container) { - int groupBoxMargin = this.groupBoxMargin(); + container = this.buildTitledPane( + container, + "Entity Caching" // TODO + ); - WritablePropertyValueModel<Entity> entityHolder = this.buildEntityHolder(); + WritablePropertyValueModel<EntityCaching> entityHolder = this.buildEntityHolder(); // Entities add/remove list pane - this.listPane = new AddRemoveListPane<Caching>( + AddRemoveListPane<Caching> listPane = new AddRemoveListPane<Caching>( this, - this.buildSubPane(composite, 0, groupBoxMargin, 0, groupBoxMargin), + container, this.buildEntitiesAdapter(), - this.buildEntitiesListHolder(), + this.buildEntityCachingListHolder(), entityHolder, this.buildEntityLabelProvider(), - null // EclipseLinkHelpContextIds.CACHING_ENTITIES + null // EclipseLinkHelpContextIds.CACHING_ENTITIES + ); + + // Entity Caching property pane + EntityCachingPropertyComposite pane = new EntityCachingPropertyComposite( + this, + entityHolder, + container + ); + + this.installPaneEnabler(entityHolder, pane); + } + + private void installPaneEnabler(WritablePropertyValueModel<EntityCaching> entityHolder, + EntityCachingPropertyComposite pane) { + + new PaneEnabler( + this.buildPaneEnablerHolder(entityHolder), + pane ); + } + private PropertyValueModel<Boolean> buildPaneEnablerHolder(WritablePropertyValueModel<EntityCaching> entityHolder) { + return new TransformationPropertyValueModel<EntityCaching, Boolean>(entityHolder) { + @Override + protected Boolean transform_(EntityCaching value) { + return value.entityNameIsValid(); + } + }; } private AddRemoveListPane.Adapter buildEntitiesAdapter() { return new AddRemoveListPane.AbstractAdapter() { public void addNewItem(ObjectListSelectionModel listSelectionModel) { - EntityDialog dialog = new EntityDialog(getControl().getShell(), EntityListComposite.this.jpaProject()); - addEntityFromDialog(dialog, listSelectionModel); + addEntityFromDialog(listSelectionModel); + } + + @Override + public boolean hasOptionalButton() { + return true; + } + + @Override + public String optionalButtonText() { + return "Edit..."; // TOOD + } + + @Override + public void optionOnSelection(ObjectListSelectionModel listSelectionModel) { + editEntityFromDialog(listSelectionModel); } public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { Caching caching = subject(); - String[] selections = (String[]) listSelectionModel.selectedValues(); - for(String name: selections) { - caching.removeEntity(name); + for (Object item : listSelectionModel.selectedValues()) { + EntityCaching entityCaching = (EntityCaching) item; + caching.removeEntity(entityCaching.getEntityName()); } } }; } - private void addEntityFromDialog(EntityDialog dialog, - ObjectListSelectionModel listSelectionModel) { + private void addEntityFromDialog(ObjectListSelectionModel listSelectionModel) { + + EntityDialog dialog = new EntityDialog(getControl().getShell(), jpaProject()); + if (dialog.open() == Window.OK) { String name = dialog.getSelectedName(); String entity = this.subject().addEntity(name); @@ -91,29 +133,48 @@ public class EntityListComposite extends AbstractFormPane<Caching> } } + private void editEntityFromDialog(ObjectListSelectionModel listSelectionModel) { + + EntityCaching entityCaching = (EntityCaching) listSelectionModel.selectedValue(); + + EntityDialog dialog = new EntityDialog(shell(), jpaProject()); + dialog.setSelectedName(entityCaching.getEntityName()); + + if (dialog.open() == Window.OK) { + String name = dialog.getSelectedName(); + this.subject().removeEntity(entityCaching.getEntityName()); + String entity = this.subject().addEntity(name); + + listSelectionModel.setSelectedValue(entity); + } + } + private ILabelProvider buildEntityLabelProvider() { return new LabelProvider() { @Override public String getText(Object element) { - if (element != null) { - return element.toString(); - } - return ""; + EntityCaching entityCaching = (EntityCaching) element; + return entityCaching.getEntityName(); } }; } - - public AddRemoveListPane<Caching> listPane() { - return this.listPane; - } - private WritablePropertyValueModel<Entity> buildEntityHolder() { - return new SimplePropertyValueModel<Entity>(); + private WritablePropertyValueModel<EntityCaching> buildEntityHolder() { + return new SimplePropertyValueModel<EntityCaching>(); } - + private JpaProject jpaProject() { // TODO - return null; + return null; + } + + private ListValueModel<EntityCaching> buildEntityCachingListHolder() { + return new TransformationListValueModelAdapter<String, EntityCaching>(buildEntitiesListHolder()) { + @Override + protected EntityCaching transformItem(String item) { + return new EntityCaching(subject(), item); + } + }; } private ListValueModel<String> buildEntitiesListHolder() { diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/PersistenceUnitCachingComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/PersistenceUnitCachingComposite.java index 5b29e6b726..6a6c25000c 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/PersistenceUnitCachingComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/PersistenceUnitCachingComposite.java @@ -3,7 +3,7 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. -* +* * Contributors: * Oracle - initial API and implementation *******************************************************************************/ @@ -14,9 +14,7 @@ import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.eclipse.ui.forms.widgets.Section; @@ -25,21 +23,10 @@ import org.eclipse.ui.forms.widgets.Section; */ public class PersistenceUnitCachingComposite extends AbstractFormPane<Caching> { - private DefaultCacheTypeComposite defaultCacheTypeComposite; - private DefaultSharedCacheComposite defaultShareCacheComposite; -// private SelectableSpinner defaultCacheSizeSpinner; - - private CacheTypeComposite cacheTypeComposite; - private ShareCacheComposite shareCacheComposite; -// private SelectableSpinner cacheSizeSpinner; + public PersistenceUnitCachingComposite(AbstractFormPane<Caching> subjectHolder, + Composite container) { - private EntityListComposite entitiesComposite; - - public PersistenceUnitCachingComposite( - AbstractFormPane<Caching> subjectHolder, - Composite container) { - - super(subjectHolder, container, false); + super(subjectHolder, container); } @Override @@ -47,70 +34,29 @@ public class PersistenceUnitCachingComposite extends AbstractFormPane<Caching> Section section = getWidgetFactory().createSection(parent, SWT.FLAT | ExpandableComposite.TITLE_BAR| Section.DESCRIPTION); section.setText(EclipseLinkUiMessages.PersistenceXmlCachingTab_sectionTitle); section.setDescription(EclipseLinkUiMessages.PersistenceXmlCachingTab_sectionDescription); - - Composite composite = getWidgetFactory().createComposite(section); - composite.setLayout(new GridLayout(1, false)); - section.setClient(composite); + section.setLayoutData(new GridData(GridData.FILL_BOTH)); - this.updateGridData(composite); - this.updateGridData(composite.getParent()); - - // Default Cache Type: - this.defaultCacheTypeComposite = new DefaultCacheTypeComposite(this, composite); - - // Default Shared Cache: - this.defaultShareCacheComposite = new DefaultSharedCacheComposite(this, composite); - - // Default Cache Size: - Label defaultCacheSizeLabel = getWidgetFactory().createLabel(composite, "Default Cache Size:"); + Composite composite = buildSubPane(section); + section.setClient(composite); -// this.defaultCacheSizeSpinner = new SelectableSpinner(defaultCachingComposite, this.commandStack, this.getWidgetFactory()); - - // listComposite - Composite listComposite = getWidgetFactory().createComposite(composite); - GridData gridData = new GridData(); - gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - listComposite.setLayoutData(gridData); - listComposite.setLayout(new GridLayout(2, false)); + // Default pane + int groupBoxMargin = groupBoxMargin(); - // EntitiesList - this.entitiesComposite = new EntityListComposite(this, this.getSubjectHolder(), listComposite); - - Composite cachingComposite = getWidgetFactory().createComposite(composite); - gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - cachingComposite.setLayoutData(gridData); - cachingComposite.setLayout(new GridLayout(1, false)); + Composite defaultPane = buildSubPane( + composite, + 0, groupBoxMargin, 0, groupBoxMargin + ); - // Cache Type: - this.cacheTypeComposite = new CacheTypeComposite(this, cachingComposite, this.entitiesComposite); + // Default Cache Type + new DefaultCacheTypeComposite(this, defaultPane); - // Share Cache: - this.shareCacheComposite = new ShareCacheComposite(this, cachingComposite, this.entitiesComposite); - - // Cache Size: - Label cacheSizeLabel = getWidgetFactory().createLabel(cachingComposite, "Cache Size:"); - gridData = new GridData(); - cacheSizeLabel.setLayoutData(gridData); + // Default Cache Size + new DefaultCacheSizeComposite(this, defaultPane); -// this.cacheSizeSpinner = new SelectableSpinner(cachingComposite, this.commandStack, this.getWidgetFactory()); - } + // Default Shared Cache + new DefaultSharedCacheComposite(this, defaultPane); - private void updateGridData(Composite container) { - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - container.setLayoutData(gridData); + // EntitiesList + new EntityListComposite(this, composite); } - - -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/ShareCacheComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/ShareCacheComposite.java index a0691c8ac2..56dc9e642d 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/ShareCacheComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/caching/ShareCacheComposite.java @@ -3,7 +3,7 @@ * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. -* +* * Contributors: * Oracle - initial API and implementation *******************************************************************************/ @@ -11,8 +11,8 @@ package org.eclipse.jpt.eclipselink.ui.internal.caching; import org.eclipse.jpt.eclipselink.core.internal.context.caching.Caching; import org.eclipse.jpt.eclipselink.ui.internal.EclipseLinkUiMessages; -import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.jpt.ui.internal.widgets.AbstractPane; +import org.eclipse.jpt.ui.internal.widgets.TriStateCheckBox; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.jpt.utility.model.value.PropertyValueModel; @@ -21,11 +21,11 @@ import org.eclipse.osgi.util.NLS; import org.eclipse.swt.widgets.Composite; /** - * ShareCacheComposite + * ShareCacheComposite */ -public class ShareCacheComposite extends AbstractFormPane<Caching> +public class ShareCacheComposite extends AbstractPane<EntityCaching> { - private EntityListComposite entitiesComposite; + private TriStateCheckBox shareCacheCheckBox; /** * Creates a new <code>ShareCacheComposite</code>. @@ -33,13 +33,10 @@ public class ShareCacheComposite extends AbstractFormPane<Caching> * @param parentController The parent container of this one * @param parent The parent container */ - public ShareCacheComposite( - AbstractFormPane<? extends Caching> parentComposite, - Composite parent, - EntityListComposite entitiesComposite) { - + public ShareCacheComposite(AbstractPane<EntityCaching> parentComposite, + Composite parent) { + super(parentComposite, parent); - this.entitiesComposite = entitiesComposite; } private PropertyValueModel<String> buildSharedCacheStringHolder() { @@ -59,37 +56,35 @@ public class ShareCacheComposite extends AbstractFormPane<Caching> } private WritablePropertyValueModel<Boolean> buildSharedCacheHolder() { - return new PropertyAspectAdapter<Caching, Boolean>(getSubjectHolder(), Caching.SHARED_CACHE_PROPERTY) { + return new PropertyAspectAdapter<EntityCaching, Boolean>(getSubjectHolder(), Caching.SHARED_CACHE_PROPERTY) { @Override protected Boolean buildValue_() { - String entityName = ShareCacheComposite.this.getSelection(); - if (!StringTools.stringIsEmpty(entityName)) { - return this.subject.getSharedCache(entityName); - } - return null; + return this.subject.getSharedCache(); } @Override protected void setValue_(Boolean value) { - String entityName = ShareCacheComposite.this.getSelection(); - if (!StringTools.stringIsEmpty(entityName)) { - this.subject.setSharedCache(value, entityName); + this.subject.setSharedCache(value); + } + + @Override + protected void subjectChanged() { + Object oldValue = this.value(); + super.subjectChanged(); + Object newValue = this.value(); + + // Make sure the default value is appended to the text + if (oldValue == newValue && newValue == null) { + this.fireAspectChange(Boolean.TRUE, newValue); } } }; } - protected String getSelection() { - if (this.entitiesComposite == null) { - return null; - } - return (String) this.entitiesComposite.listPane().getSelectionModel().selectedValue(); - } - @Override protected void initializeLayout(Composite container) { - this.buildTriStateCheckBoxWithDefault( + shareCacheCheckBox = this.buildTriStateCheckBoxWithDefault( container, EclipseLinkUiMessages.PersistenceXmlCachingTab_sharedCacheLabel, this.buildSharedCacheHolder(), @@ -98,4 +93,10 @@ public class ShareCacheComposite extends AbstractFormPane<Caching> // EclipseLinkHelpContextIds.CACHING_SHARED_CACHE ); } -} + + @Override + public void enableWidgets(boolean enabled) { + super.enableWidgets(enabled); + shareCacheCheckBox.setEnabled(enabled); + } +}
\ No newline at end of file |