diff options
author | kmoore | 2008-02-07 15:34:56 +0000 |
---|---|---|
committer | kmoore | 2008-02-07 15:34:56 +0000 |
commit | 07a1d93353211cdd7b9364113b0b6e5c9b472bfe (patch) | |
tree | 43774f3a69adda579111f87136bb2164181e9457 /jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui | |
parent | d052222116056e51bbdf2179878ccfb17f779a04 (diff) | |
download | webtools.dali-07a1d93353211cdd7b9364113b0b6e5c9b472bfe.tar.gz webtools.dali-07a1d93353211cdd7b9364113b0b6e5c9b472bfe.tar.xz webtools.dali-07a1d93353211cdd7b9364113b0b6e5c9b472bfe.zip |
213467 - committing a patch from Pascal
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui')
24 files changed, 1531 insertions, 772 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java index 2ae25fd3a3..429262f8c8 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/JptUiMappingsMessages.java @@ -15,7 +15,6 @@ public class JptUiMappingsMessages extends NLS { private static final String BUNDLE_NAME = "jpt_ui_mappings"; //$NON-NLS-1$ - public static String AbstractJoinColumnStateObject_NameNotSpecified; public static String Boolean_True; @@ -150,6 +149,10 @@ public class JptUiMappingsMessages extends NLS public static String AttributeOverridesComposite_attributeOverrides; public static String AttributeOverridesComposite_overrideDefault; + + public static String OverridesComposite_association; + public static String OverridesComposite_attribute; + public static String OverridesComposite_noName; public static String OverridesComposite_joinColumn; public static String InheritanceComposite_default; diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/AbstractDatabaseObjectCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/AbstractDatabaseObjectCombo.java index 0ecc98494b..a47f0272ef 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/AbstractDatabaseObjectCombo.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/AbstractDatabaseObjectCombo.java @@ -206,11 +206,17 @@ public abstract class AbstractDatabaseObjectCombo<T extends IJpaNode> extends Ab * Returns the JPA project's connection profile, which is never * <code>null</code>. * - * @return The connection set in the project's properties or a <code>null</code> - * connection + * @return The connection set in the project's properties or <code>null</code> + * if it could not being retrieved */ protected final ConnectionProfile connectionProfile() { - return jpaProject().connectionProfile(); + IJpaProject jpaProject = jpaProject(); + + if (jpaProject != null) { + return jpaProject.connectionProfile(); + } + + return null; } /** @@ -237,7 +243,12 @@ public abstract class AbstractDatabaseObjectCombo<T extends IJpaNode> extends Ab @Override protected void disengageListeners(T subject) { super.disengageListeners(subject); - jpaProject().connectionProfile().removeConnectionListener(this.connectionListener); + + IJpaProject jpaProject = jpaProject(); + + if (jpaProject != null) { + jpaProject.connectionProfile().removeConnectionListener(this.connectionListener); + } } /* @@ -271,7 +282,12 @@ public abstract class AbstractDatabaseObjectCombo<T extends IJpaNode> extends Ab @Override protected void engageListeners(T subject) { super.engageListeners(subject); - jpaProject().connectionProfile().addConnectionListener(this.connectionListener); + + IJpaProject jpaProject = jpaProject(); + + if (jpaProject != null) { + jpaProject.connectionProfile().addConnectionListener(this.connectionListener); + } } public final CCombo getCombo() { @@ -347,7 +363,9 @@ public abstract class AbstractDatabaseObjectCombo<T extends IJpaNode> extends Ab populateDefaultValue(); - if (connectionProfile().isConnected() && (subject() != null)) { + ConnectionProfile connectionProfile = connectionProfile(); + + if ((connectionProfile != null) && connectionProfile.isConnected()) { for (Iterator<String> iter = CollectionTools.sort(values()); iter.hasNext(); ) { combo.add(iter.next()); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialogPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialogPane.java index d08f38b8e9..c8a81d9d09 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialogPane.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnDialogPane.java @@ -71,13 +71,23 @@ public class AbstractJoinColumnDialogPane<T extends AbstractJoinColumnStateObjec private ModifyListener buildNameComboListener() { return new ModifyListener() { + + private boolean isDefaultName(int selectedIndex, String value) { + return (selectedIndex == 0) && value.equals(subject().defaultName()); + } + public void modifyText(ModifyEvent e) { + if (!isPopulating()) { setPopulating(true); + try { Combo combo = (Combo) e.widget; - subject().setName(combo.getText()); - subject().setDefaultNameSelected(combo.getSelectionIndex() == 0); + String name = combo.getText(); + boolean defaultName = isDefaultName(combo.getSelectionIndex(), name); + + subject().setName(name); + subject().setDefaultNameSelected(defaultName); } finally { setPopulating(false); @@ -89,13 +99,23 @@ public class AbstractJoinColumnDialogPane<T extends AbstractJoinColumnStateObjec private ModifyListener buildReferencedColumnNameComboListener() { return new ModifyListener() { + + private boolean isDefaultReferencedColumnName(int selectedIndex, String value) { + return (selectedIndex == 0) && value.equals(subject().defaultReferencedColumnName()); + } + public void modifyText(ModifyEvent e) { + if (!isPopulating()) { setPopulating(true); + try { Combo combo = (Combo) e.widget; - subject().setReferencedColumnName(combo.getText()); - subject().setDefaultReferencedColumnNameSelected(combo.getSelectionIndex() == 0); + String referencedColumnName = combo.getText(); + boolean defaultReferencedColumnName = isDefaultReferencedColumnName(combo.getSelectionIndex(), referencedColumnName); + + subject().setReferencedColumnName(referencedColumnName); + subject().setDefaultReferencedColumnNameSelected(defaultReferencedColumnName); } finally { setPopulating(false); @@ -112,6 +132,7 @@ public class AbstractJoinColumnDialogPane<T extends AbstractJoinColumnStateObjec protected void doPopulate() { super.doPopulate(); populateNameCombo(); + populateReferencedNameCombo(); } protected final Combo getNameCombo() { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnStateObject.java index 68bfeb0ee4..af2d6aaa4a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnStateObject.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/AbstractJoinColumnStateObject.java @@ -134,8 +134,10 @@ public abstract class AbstractJoinColumnStateObject extends AbstractNode this.joinColumn = joinColumn; if (joinColumn != null) { - this.defaultNameSelected = joinColumn.getSpecifiedName() == null; - this.name = joinColumn.getName(); + this.name = joinColumn.getName(); + this.defaultNameSelected = joinColumn.getSpecifiedName() == null; + this.referencedColumnName = joinColumn.getReferencedColumnName(); + this.defaultReferencedColumnNameSelected = joinColumn.getSpecifiedReferencedColumnName() == null; } } @@ -175,6 +177,41 @@ public abstract class AbstractJoinColumnStateObject extends AbstractNode this.validator = validator; } + /** + * Updates the given join column with the values contained in this state + * object. + * + * @param joinColumn The join column to update + */ + public void updateJoinColumn(IAbstractJoinColumn joinColumn) { + + // Name + if (defaultNameSelected) { + + if (joinColumn.getSpecifiedName() != null) { + joinColumn.setSpecifiedName(null); + } + } + else if (joinColumn.getSpecifiedName() == null || + !joinColumn.getSpecifiedName().equals(name)){ + + joinColumn.setSpecifiedName(name); + } + + // Referenced Column Name + if (defaultReferencedColumnNameSelected) { + + if (joinColumn.getSpecifiedReferencedColumnName() != null) { + joinColumn.setSpecifiedReferencedColumnName(null); + } + } + else if (joinColumn.getSpecifiedReferencedColumnName() == null || + !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); + } + } + /* * (non-Javadoc) */ diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java index 4e31e6d2ed..ea27d6772f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/ColumnComposite.java @@ -112,7 +112,8 @@ public class ColumnComposite extends AbstractFormPane<IColumn> @Override protected IJpaProject jpaProject() { - return subject().jpaProject(); + IColumn subject = subject(); + return (subject != null) ? subject.jpaProject() : null; } @Override @@ -196,7 +197,8 @@ public class ColumnComposite extends AbstractFormPane<IColumn> @Override protected IJpaProject jpaProject() { - return subject().jpaProject(); + IColumn subject = subject(); + return (subject != null) ? subject.jpaProject() : null; } @Override diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnComposite.java index 1543c24584..db628f7c66 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnComposite.java @@ -31,6 +31,7 @@ import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionMod import org.eclipse.osgi.util.NLS; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; @@ -39,13 +40,15 @@ import org.eclipse.swt.widgets.Group; * Here the layout of this pane: * <pre> * ----------------------------------------------------------------------------- - * | | - * | x Override Default | - * | | - * | ------------------------------------------------------------------------- | + * | - Join Columns ---------------------------------------------------------- | * | | | | - * | | AddRemoveListPane | | + * | | x Override Default | | * | | | | + * | | --------------------------------------------------------------------- | | + * | | | | | | + * | | | AddRemoveListPane | | | + * | | | | | | + * | | --------------------------------------------------------------------- | | * | ------------------------------------------------------------------------- | * -----------------------------------------------------------------------------</pre> * @@ -60,6 +63,7 @@ import org.eclipse.swt.widgets.Group; */ public class JoinColumnComposite extends AbstractFormPane<ISingleRelationshipMapping> { + private AddRemoveListPane<ISingleRelationshipMapping> joinColumnsListPane; private Button overrideDefaultJoinColumnsCheckBox; /** @@ -68,8 +72,8 @@ public class JoinColumnComposite extends AbstractFormPane<ISingleRelationshipMap * @param parentPane The parent container of this one * @param parent The parent container */ - protected JoinColumnComposite(AbstractFormPane<? extends ISingleRelationshipMapping> parentPane, - Composite parent) { + public JoinColumnComposite(AbstractFormPane<? extends ISingleRelationshipMapping> parentPane, + Composite parent) { super(parentPane, parent); } @@ -98,26 +102,18 @@ public class JoinColumnComposite extends AbstractFormPane<ISingleRelationshipMap private void addJoinColumn(JoinColumnInRelationshipMappingStateObject stateObject) { - int index = subject().specifiedJoinColumnsSize(); - - IJoinColumn joinColumn = subject().addSpecifiedJoinColumn(index); - joinColumn.setSpecifiedName(stateObject.getName()); - joinColumn.setSpecifiedReferencedColumnName(stateObject.getReferencedColumnName()); + ISingleRelationshipMapping subject = subject(); + int index = subject.specifiedJoinColumnsSize(); - if (!stateObject.isDefaultTableSelected()) { - // Not checking this for name and referenced column name because - // there is no default option when you are adding a second join - // column. There is always at least 1 join column (the default) - joinColumn.setSpecifiedTable(stateObject.getTable()); - } + IJoinColumn joinColumn = subject.addSpecifiedJoinColumn(index); + stateObject.updateJoinColumn(joinColumn); } private PostExecution<JoinColumnInRelationshipMappingDialog> buildAddJoinColumnPostExecution() { return new PostExecution<JoinColumnInRelationshipMappingDialog>() { public void execute(JoinColumnInRelationshipMappingDialog dialog) { if (dialog.wasConfirmed()) { - JoinColumnInRelationshipMappingStateObject stateObject = dialog.subject(); - addJoinColumn(stateObject); + addJoinColumn(dialog.subject()); } } }; @@ -231,42 +227,19 @@ public class JoinColumnComposite extends AbstractFormPane<ISingleRelationshipMap }; } - private SelectionAdapter buildOverrideDefaultJoinColumnsSelectionListener() { + private SelectionListener buildOverrideDefaultJoinColumnsSelectionListener() { return new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - - if (isPopulating()) { - return; - } - - if (overrideDefaultJoinColumnsCheckBox.getSelection()) { - IJoinColumn defaultJoinColumn = subject().getDefaultJoinColumn();//TODO could be null, disable override default check box? - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - IJoinColumn joinColumn = subject().addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName(columnName); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - else { - for (int index = subject().specifiedJoinColumnsSize(); --index >= 0; ) { - subject().removeSpecifiedJoinColumn(index); - } - } + updateJoinColumns(); } }; } private WritablePropertyValueModel<Boolean> buildOverrideDefaultJoinsColumnHolder() { - // TODO return new SimplePropertyValueModel<Boolean>(); } - private Composite buildPane(Composite container, int groupBoxMargin) { - return buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); - } - private ListValueModel<IJoinColumn> buildSortedJoinColumnsListHolder() { return new SortedListValueModelAdapter<IJoinColumn>( buildJoinColumnsListHolder() @@ -279,7 +252,12 @@ public class JoinColumnComposite extends AbstractFormPane<ISingleRelationshipMap @Override protected void doPopulate() { super.doPopulate(); - overrideDefaultJoinColumnsCheckBox.setSelection(subject() != null && subject().containsSpecifiedJoinColumns()); + + ISingleRelationshipMapping subject = subject(); + boolean enabled = (subject != null) && subject.containsSpecifiedJoinColumns(); + + overrideDefaultJoinColumnsCheckBox.setSelection(enabled); + joinColumnsListPane.enableWidgets(enabled); } private void editJoinColumn(ObjectListSelectionModel listSelectionModel) { @@ -298,11 +276,15 @@ public class JoinColumnComposite extends AbstractFormPane<ISingleRelationshipMap @Override protected void initializeLayout(Composite container) { - int groupBoxMargin = groupBoxMargin(); + // Join Columns group + Group groupPane = buildTitledPane( + container, + JptUiMappingsMessages.JoinColumnComposite_joinColumn + ); // Override Default Join Columns check box overrideDefaultJoinColumnsCheckBox = buildCheckBox( - buildPane(container, groupBoxMargin), + buildSubPane(groupPane, 8), JptUiMappingsMessages.JoinColumnComposite_overrideDefaultJoinColumns, buildOverrideDefaultJoinsColumnHolder() ); @@ -311,16 +293,10 @@ public class JoinColumnComposite extends AbstractFormPane<ISingleRelationshipMap buildOverrideDefaultJoinColumnsSelectionListener() ); - // Join Columns group - Group joinColumnsGroup = buildTitledPane( - container, - JptUiMappingsMessages.JoinColumnComposite_joinColumn - ); - // Join Columns list pane - new AddRemoveListPane<ISingleRelationshipMapping>( + joinColumnsListPane = new AddRemoveListPane<ISingleRelationshipMapping>( this, - joinColumnsGroup, + groupPane, buildJoinColumnsAdapter(), buildSortedJoinColumnsListHolder(), buildJoinColumnHolder(), @@ -339,63 +315,45 @@ public class JoinColumnComposite extends AbstractFormPane<ISingleRelationshipMap } private void updateJoinColumn(JoinColumnInRelationshipMappingStateObject stateObject) { + stateObject.updateJoinColumn(stateObject.getJoinColumn()); + } - IJoinColumn joinColumn = stateObject.getJoinColumn(); - String name = stateObject.getName(); - String referencedColumnName = stateObject.getReferencedColumnName(); - String table = stateObject.getTable(); - - // Name - if (stateObject.isDefaultNameSelected()) { - - if (joinColumn.getSpecifiedName() != null) { - joinColumn.setSpecifiedName(null); - } - } - else if (joinColumn.getSpecifiedName() == null || - !joinColumn.getSpecifiedName().equals(name)){ + private void updateJoinColumns() { - joinColumn.setSpecifiedName(name); + if (isPopulating()) { + return; } - // Referenced Column Name - if (stateObject.isDefaultReferencedColumnNameSelected()) { + ISingleRelationshipMapping subject = subject(); + boolean selected = overrideDefaultJoinColumnsCheckBox.getSelection(); + joinColumnsListPane.enableWidgets(selected); + setPopulating(true); - if (joinColumn.getSpecifiedReferencedColumnName() != null) { - joinColumn.setSpecifiedReferencedColumnName(null); - } - } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || - !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + try { + // Add a join column by creating a specified one using the default + // one if it exists + if (selected) { - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } + IJoinColumn defaultJoinColumn = subject.getDefaultJoinColumn();//TODO could be null, disable override default check box? - // Specified Table - if (stateObject.isDefaultTableSelected()) { + if (defaultJoinColumn != null) { + String columnName = defaultJoinColumn.getDefaultName(); + String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - if (joinColumn.getSpecifiedTable() != null) { - joinColumn.setSpecifiedTable(null); + IJoinColumn joinColumn = subject.addSpecifiedJoinColumn(0); + joinColumn.setSpecifiedName(columnName); + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); + } + } + // Remove all the specified join columns + else { + for (int index = subject.specifiedJoinColumnsSize(); --index >= 0; ) { + subject.removeSpecifiedJoinColumn(index); + } } } - else if (joinColumn.getSpecifiedTable() == null || - !joinColumn.getSpecifiedTable().equals(table)){ - - joinColumn.setSpecifiedTable(table); - } - - // Insertable - Boolean insertable = stateObject.getInsertable(); - - if (joinColumn.getInsertable() != insertable) { - joinColumn.setSpecifiedInsertable(insertable); - } - - // Updatable - Boolean updatable = stateObject.getUpdatable(); - - if (joinColumn.getUpdatable() != updatable) { - joinColumn.setSpecifiedUpdatable(updatable); + finally { + setPopulating(false); } } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialogPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialogPane.java index d1ce28dda8..bbc2018654 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialogPane.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnDialogPane.java @@ -113,13 +113,24 @@ public class JoinColumnDialogPane extends AbstractJoinColumnDialogPane<JoinColum private ModifyListener buildTableComboSelectionListener() { return new ModifyListener() { + + private boolean isDefaultTable(int selectedIndex, String value) { + return (selectedIndex == 0) && value.equals(subject().defaultTableName()); + } + public void modifyText(ModifyEvent e) { + if (!isPopulating()) { setPopulating(true); + try { Combo combo = (Combo) e.widget; - subject().setTable(combo.getText()); - subject().setDefaultTableSelected(combo.getSelectionIndex() == 0); + String table = combo.getText(); + boolean defaultTable = isDefaultTable(combo.getSelectionIndex(), table); + + subject().setTable(table); + subject().setDefaultTableSelected(defaultTable); + populateNameCombo(); } finally { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnStateObject.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnStateObject.java index 543593ef83..407150599b 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnStateObject.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnStateObject.java @@ -21,9 +21,9 @@ import org.eclipse.jpt.db.internal.Table; @SuppressWarnings("nls") public abstract class JoinColumnStateObject extends AbstractJoinColumnStateObject { - private Boolean defaultInsertable; + private Boolean defaultInsertableSelected; private boolean defaultTableSelected; - private Boolean defaultUpdatable; + private Boolean defaultUpdatableSelected; private Boolean insertable; private String table; private Boolean updatable; @@ -52,11 +52,25 @@ public abstract class JoinColumnStateObject extends AbstractJoinColumnStateObjec public abstract String defaultTableName(); public Boolean getDefaultInsertable() { - return defaultInsertable; + + IJoinColumn joinColumn = getJoinColumn(); + + if (joinColumn != null) { + return joinColumn.getDefaultInsertable(); + } + + return null; } public Boolean getDefaultUpdatable() { - return defaultUpdatable; + + IJoinColumn joinColumn = getJoinColumn(); + + if (joinColumn != null) { + return joinColumn.getDefaultUpdatable(); + } + + return null; } public Boolean getInsertable() { @@ -107,16 +121,16 @@ public abstract class JoinColumnStateObject extends AbstractJoinColumnStateObjec if (abstractJoinColumn != null) { IJoinColumn joinColumn = (IJoinColumn) abstractJoinColumn; - defaultTableSelected = joinColumn.getSpecifiedTable() == null; - table = joinColumn.getTable(); - insertable = joinColumn.getInsertable(); - updatable = joinColumn.getUpdatable(); - defaultInsertable = joinColumn.getDefaultInsertable(); - defaultUpdatable = joinColumn.getDefaultInsertable(); + defaultInsertableSelected = joinColumn.getSpecifiedInsertable() == null; + defaultTableSelected = joinColumn.getSpecifiedTable() == null; + defaultUpdatableSelected = joinColumn.getSpecifiedUnique() == null; + insertable = joinColumn.getInsertable(); + table = joinColumn.getTable(); + updatable = joinColumn.getUpdatable(); } else { - defaultInsertable = Boolean.TRUE; - defaultUpdatable = Boolean.TRUE; + defaultInsertableSelected = Boolean.FALSE; + defaultUpdatableSelected = Boolean.FALSE; } } @@ -148,8 +162,10 @@ public abstract class JoinColumnStateObject extends AbstractJoinColumnStateObjec public String specifiedTableName() { - if (getJoinColumn() != null) { - return getJoinColumn().getSpecifiedTable(); + IJoinColumn joinColumn = getJoinColumn(); + + if (joinColumn != null) { + return joinColumn.getSpecifiedTable(); } return null; @@ -158,4 +174,49 @@ public abstract class JoinColumnStateObject extends AbstractJoinColumnStateObjec public String tableName() { return (specifiedTableName() == null) ? defaultTableName() : specifiedTableName(); } + + /* + * (non-Javadoc) + */ + @Override + public void updateJoinColumn(IAbstractJoinColumn abstractJoinColumn) { + + IJoinColumn joinColumn = (IJoinColumn) abstractJoinColumn; + super.updateJoinColumn(abstractJoinColumn); + + // Specified Table + if (defaultTableSelected) { + + if (joinColumn.getSpecifiedTable() != null) { + joinColumn.setSpecifiedTable(null); + } + } + else if (joinColumn.getSpecifiedTable() == null || + !joinColumn.getSpecifiedTable().equals(table)){ + + joinColumn.setSpecifiedTable(table); + } + + // Insertable + if (defaultInsertableSelected) { + + if (joinColumn.getSpecifiedInsertable() != null) { + joinColumn.setSpecifiedInsertable(null); + } + } + else if (joinColumn.getSpecifiedInsertable() != insertable){ + joinColumn.setSpecifiedInsertable(insertable); + } + + // Updatable + if (defaultUpdatableSelected) { + + if (joinColumn.getSpecifiedUpdatable() != null) { + joinColumn.setSpecifiedUpdatable(null); + } + } + else if (joinColumn.getSpecifiedUpdatable() != insertable){ + joinColumn.setSpecifiedUpdatable(insertable); + } + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnsComposite.java index 015cf7546a..b1d5141f51 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnsComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinColumnsComposite.java @@ -49,14 +49,25 @@ import org.eclipse.swt.widgets.Composite; */ public class JoinColumnsComposite<T extends IJpaNode> extends AbstractFormPane<T> { + /** + * The editor used to perform the common behaviors defined in the list pane. + */ private IJoinColumnsEditor<T> joinColumnsEditor; /** + * Keeps track of the list pane in order to update its enablement state when + * required. + */ + private AddRemoveListPane<T> joinColumnsListPane; + + /** * Creates a new <code>JoinColumnsComposite</code>. * * @param parentPane The parent controller of this one * @param parent The parent container * @param widgetFactory The factory used to create various common widgets + * @param joinColumnsEditor The editor used to perform the common behaviors + * defined in the list pane */ public JoinColumnsComposite(AbstractFormPane<? extends T> parentPane, Composite parent, @@ -74,6 +85,8 @@ public class JoinColumnsComposite<T extends IJpaNode> extends AbstractFormPane<T * @param subjectHolder The holder of this pane's subject * @param parent The parent container * @param widgetFactory The factory used to create various common widgets + * @param joinColumnsEditor The editor used to perform the common behaviors + * defined in the list pane */ public JoinColumnsComposite(AbstractFormPane<?> parentPane, PropertyValueModel<? extends T> subjectHolder, @@ -209,13 +222,22 @@ public class JoinColumnsComposite<T extends IJpaNode> extends AbstractFormPane<T * (non-Javadoc) */ @Override + public void enableWidgets(boolean enabled) { + super.enableWidgets(enabled); + joinColumnsListPane.enableWidgets(enabled); + } + + /* + * (non-Javadoc) + */ + @Override protected void initializeLayout(Composite container) { } private void initializeLayout2() { // Join Columns list pane - new AddRemoveListPane<T>( + joinColumnsListPane = new AddRemoveListPane<T>( this, getControl(), buildJoinColumnsAdapter(), diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java index a734b1a4a7..2ad978f105 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/JoinTableComposite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 Oracle. All rights reserved. + * Copyright (c) 2005, 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. @@ -42,20 +42,26 @@ import org.eclipse.swt.widgets.Group; * | Name: | |v| | * | --------------------------------------------------------------- | * | | - * | x Override Default Join Columns | - * | | - * | ------------------------------------------------------------------------- | + * | - Join Columns ---------------------------------------------------------- | * | | | | - * | | JoinColumnsComposite | | + * | | x Override Default | | * | | | | + * | | --------------------------------------------------------------------- | | + * | | | | | | + * | | | JoinColumnsComposite | | | + * | | | | | | + * | | --------------------------------------------------------------------- | | * | ------------------------------------------------------------------------- | * | | - * | x Override Default Inverse Join Columns | - * | | - * | ------------------------------------------------------------------------- | + * | - Inverse Join Columns -------------------------------------------------- | * | | | | - * | | JoinColumnsComposite | | + * | | x Override Default | | * | | | | + * | | --------------------------------------------------------------------- | | + * | | | | | | + * | | | JoinColumnsComposite | | | + * | | | | | | + * | | --------------------------------------------------------------------- | | * | ------------------------------------------------------------------------- | * -----------------------------------------------------------------------------</pre> * @@ -69,6 +75,8 @@ import org.eclipse.swt.widgets.Group; */ public class JoinTableComposite extends AbstractFormPane<IJoinTable> { + private JoinColumnsComposite<IJoinTable> inverseJoinColumnsComposite; + private JoinColumnsComposite<IJoinTable> joinColumnsComposite; private Button overrideDefaultInverseJoinColumnsCheckBox; private Button overrideDefaultJoinColumnsCheckBox; @@ -108,10 +116,11 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> private void addInverseJoinColumnFromDialog(JoinColumnInJoinTableStateObject stateObject) { - int index = subject().specifiedInverseJoinColumnsSize(); - IJoinColumn joinColumn = subject().addSpecifiedInverseJoinColumn(index); - joinColumn.setSpecifiedName(stateObject.getName()); - joinColumn.setSpecifiedReferencedColumnName(stateObject.getReferencedColumnName()); + IJoinTable subject = subject(); + int index = subject.specifiedInverseJoinColumnsSize(); + + IJoinColumn joinColumn = subject.addSpecifiedInverseJoinColumn(index); + stateObject.updateJoinColumn(joinColumn); } private void addJoinColumn(IJoinTable joinTable) { @@ -122,10 +131,11 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> private void addJoinColumnFromDialog(JoinColumnInJoinTableStateObject stateObject) { - int index = subject().specifiedJoinColumnsSize(); + IJoinTable subject = subject(); + int index = subject.specifiedJoinColumnsSize(); + IJoinColumn joinColumn = subject().addSpecifiedJoinColumn(index); - joinColumn.setSpecifiedName(stateObject.getName()); - joinColumn.setSpecifiedReferencedColumnName(stateObject.getReferencedColumnName()); + stateObject.updateJoinColumn(joinColumn); } private PostExecution<InverseJoinColumnDialog> buildAddInverseJoinColumnPostExecution() { @@ -177,7 +187,6 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> } private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder() { - // TODO return new SimplePropertyValueModel<Boolean>(); } @@ -185,23 +194,7 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> return new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - Button button = (Button) e.widget; - IJoinTable joinTable = subject(); - - if (button.getSelection()) { - IJoinColumn defaultJoinColumn = joinTable.getDefaultInverseJoinColumn(); //TODO null check, override default button disabled - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - IJoinColumn joinColumn = joinTable.addSpecifiedInverseJoinColumn(0); - joinColumn.setSpecifiedName(columnName); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - else { - for (int index = joinTable.specifiedInverseJoinColumnsSize(); --index >= 0; ) { - joinTable.removeSpecifiedJoinColumn(index); - } - } + updateInverseJoinColumns(); } }; } @@ -210,32 +203,15 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> return new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - Button button = (Button) e.widget; - IJoinTable joinTable = subject(); - - if (button.getSelection()) { - IJoinColumn defaultJoinColumn = joinTable.getDefaultJoinColumn(); //TODO null check, override default button disabled - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - IJoinColumn joinColumn = joinTable.addSpecifiedJoinColumn(0); - joinColumn.setSpecifiedName(columnName); - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - else { - for (int index = joinTable.specifiedJoinColumnsSize(); --index >= 0; ) { - joinTable.removeSpecifiedJoinColumn(index); - } - } + updateJoinColumns(); } }; } private Composite buildPane(Composite container, int groupBoxMargin) { - return buildSubPane(container, groupBoxMargin, 0, groupBoxMargin, 0, groupBoxMargin); + return buildSubPane(container, 0, groupBoxMargin, 10, groupBoxMargin); } - private TableCombo<IJoinTable> buildTableCombo(Composite container) { return new TableCombo<IJoinTable>(this, container) { @@ -289,6 +265,24 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> }; } + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + super.doPopulate(); + + IJoinTable subject = subject(); + boolean enabled = (subject != null) && subject.containsSpecifiedJoinColumns(); + boolean inverseEnabled = (subject != null) && subject.containsSpecifiedInverseJoinColumns(); + + overrideDefaultJoinColumnsCheckBox.setSelection(enabled); + overrideDefaultInverseJoinColumnsCheckBox.setSelection(enabled); + + joinColumnsComposite.enableWidgets(enabled); + inverseJoinColumnsComposite.enableWidgets(inverseEnabled); + } + private void editInverseJoinColumn(IJoinColumn joinColumn) { InverseJoinColumnDialog dialog = @@ -306,32 +300,7 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> } private void editJoinColumn(JoinColumnInJoinTableStateObject stateObject) { - - IJoinColumn joinColumn = stateObject.getJoinColumn(); - String name = stateObject.getName(); - String referencedColumnName = stateObject.getReferencedColumnName(); - - if (stateObject.isDefaultNameSelected()) { - if (joinColumn.getSpecifiedName() != null) { - joinColumn.setSpecifiedName(null); - } - } - else if (joinColumn.getSpecifiedName() == null || - !joinColumn.getSpecifiedName().equals(name)){ - - joinColumn.setSpecifiedName(name); - } - - if (stateObject.isDefaultReferencedColumnNameSelected()) { - if (joinColumn.getSpecifiedReferencedColumnName() != null) { - joinColumn.setSpecifiedReferencedColumnName(null); - } - } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || - !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ - - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } + stateObject.updateJoinColumn(stateObject.getJoinColumn()); } /* @@ -352,9 +321,15 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> IJpaHelpContextIds.MAPPING_JOIN_TABLE_NAME ); + // Join Columns group pane + Group joinColumnGroupPane = buildTitledPane( + container, + JptUiMappingsMessages.JoinTableComposite_joinColumn + ); + // Override Default Join Columns check box overrideDefaultJoinColumnsCheckBox = buildCheckBox( - buildPane(container, groupBoxMargin), + buildSubPane(joinColumnGroupPane, 8), JptUiMappingsMessages.JoinTableComposite_overrideDefaultJoinColumns, buildOverrideDefaultHolder() ); @@ -363,21 +338,21 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> buildOverrideDefaultSelectionListener() ); - // Join Columns widgets - Group joinColumnGroupPane = buildTitledPane( - container, - JptUiMappingsMessages.JoinTableComposite_joinColumn - ); - - new JoinColumnsComposite<IJoinTable>( + joinColumnsComposite = new JoinColumnsComposite<IJoinTable>( this, joinColumnGroupPane, buildJoinColumnsEditor() ); + // Inverse Join Columns group pane + Group inverseJoinColumnGroupPane = buildTitledPane( + container, + JptUiMappingsMessages.JoinTableComposite_inverseJoinColumn + ); + // Override Default Inverse Join Columns check box overrideDefaultInverseJoinColumnsCheckBox = buildCheckBox( - buildPane(container, groupBoxMargin), + buildSubPane(inverseJoinColumnGroupPane, 8), JptUiMappingsMessages.JoinTableComposite_overrideDefaultInverseJoinColumns, buildOverrideDefaultHolder() ); @@ -386,19 +361,89 @@ public class JoinTableComposite extends AbstractFormPane<IJoinTable> buildOverrideDefaultInverseSelectionListener() ); - // Inverse Join Columns widgets - Group inverseJoinColumnGroupPane = buildTitledPane( - container, - JptUiMappingsMessages.JoinTableComposite_inverseJoinColumn - ); - - new JoinColumnsComposite<IJoinTable>( + inverseJoinColumnsComposite = new JoinColumnsComposite<IJoinTable>( this, inverseJoinColumnGroupPane, buildInverseJoinColumnsEditor() ); } + private void updateInverseJoinColumns() { + + if (isPopulating()) { + return; + } + + IJoinTable subject = subject(); + boolean selected = overrideDefaultInverseJoinColumnsCheckBox.getSelection(); + joinColumnsComposite.enableWidgets(selected); + setPopulating(true); + + try { + // Add a join column by creating a specified one using the default + // one if it exists + if (selected) { + + IJoinColumn defaultJoinColumn = subject.getDefaultInverseJoinColumn(); //TODO null check, override default button disabled + + if (defaultJoinColumn != null) { + String columnName = defaultJoinColumn.getDefaultName(); + String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); + + IJoinColumn joinColumn = subject.addSpecifiedInverseJoinColumn(0); + joinColumn.setSpecifiedName(columnName); + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); + } + } + else { + for (int index = subject.specifiedInverseJoinColumnsSize(); --index >= 0; ) { + subject.removeSpecifiedInverseJoinColumn(index); + } + } + } + finally { + setPopulating(false); + } + } + + private void updateJoinColumns() { + + if (isPopulating()) { + return; + } + + IJoinTable subject = subject(); + boolean selected = overrideDefaultJoinColumnsCheckBox.getSelection(); + joinColumnsComposite.enableWidgets(selected); + setPopulating(true); + + try { + // Add a join column by creating a specified one using the default + // one if it exists + if (selected) { + + IJoinColumn defaultJoinColumn = subject.getDefaultJoinColumn(); //TODO null check, override default button disabled + + if (defaultJoinColumn != null) { + String columnName = defaultJoinColumn.getDefaultName(); + String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); + + IJoinColumn joinColumn = subject.addSpecifiedJoinColumn(0); + joinColumn.setSpecifiedName(columnName); + joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); + } + } + else { + for (int index = subject.specifiedJoinColumnsSize(); --index >= 0; ) { + subject.removeSpecifiedJoinColumn(index); + } + } + } + finally { + setPopulating(false); + } + } + private class InverseJoinColumnsProvider implements IJoinColumnsEditor<IJoinTable> { public void addJoinColumn(IJoinTable subject) { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrderingComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrderingComposite.java index 25db9fe883..b6592cb502 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrderingComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OrderingComposite.java @@ -170,7 +170,7 @@ public class OrderingComposite extends AbstractFormPane<IMultiRelationshipMappin // No Ordering radio button buildRadioButton( - orderByGroup, + buildSubPane(orderByGroup, 8), JptUiMappingsMessages.OrderByComposite_noOrdering, buildNoOrderingHolder(), IJpaHelpContextIds.MAPPING_ORDER_BY_NO_ORDERING diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java index 2f5e5dbd20..3ea2452958 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/OverridesComposite.java @@ -9,8 +9,10 @@ ******************************************************************************/ package org.eclipse.jpt.ui.internal.mappings.details; +import java.util.ArrayList; import java.util.ListIterator; -import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jpt.core.internal.context.base.IAssociationOverride; import org.eclipse.jpt.core.internal.context.base.IAttributeOverride; import org.eclipse.jpt.core.internal.context.base.IColumn; @@ -20,27 +22,29 @@ import org.eclipse.jpt.core.internal.context.base.IOverride; import org.eclipse.jpt.ui.internal.IJpaHelpContextIds; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; import org.eclipse.jpt.ui.internal.mappings.details.JoinColumnsComposite.IJoinColumnsEditor; -import org.eclipse.jpt.ui.internal.swt.ListBoxModelAdapter; +import org.eclipse.jpt.ui.internal.util.ControlSwitcher; +import org.eclipse.jpt.ui.internal.util.ControlVisibilityEnabler; import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; +import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; import org.eclipse.jpt.ui.internal.widgets.PostExecution; +import org.eclipse.jpt.ui.internal.widgets.AddRemovePane.Adapter; 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.Transformer; import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; import org.eclipse.jpt.utility.internal.model.value.ListValueModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; 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.TransformationPropertyValueModel; import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; +import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Control; import org.eclipse.ui.part.PageBook; /** @@ -51,15 +55,15 @@ import org.eclipse.ui.part.PageBook; * | - Attribute Overrides --------------------------------------------------- | * | | --------------------------------------------------------------------- | | * | | | | | | - * | | | | | | + * | | | AddRemoveListPane | | | * | | | | | | * | | --------------------------------------------------------------------- | | * | | | | - * | | x Override Default | | + * | | x Override Default | | * | | | | * | | --------------------------------------------------------------------- | | * | | | | | | - * | | | JoinColumnsComposite | | | + * | | | PageBook (JoinColumnsComposite or ColumnComposite) | | | * | | | | | | * | | --------------------------------------------------------------------- | | * | ------------------------------------------------------------------------- | @@ -67,13 +71,21 @@ import org.eclipse.ui.part.PageBook; * * @see IEntity * @see EntityComposite - The parent container + * @see ColumnComposite * @see JoinColumnsComposite * * @version 2.0 * @since 1.0 */ +@SuppressWarnings("nls") public class OverridesComposite extends AbstractFormPane<IEntity> { + private ColumnComposite columnComposite; + private JoinColumnsComposite<IAssociationOverride> joinColumnsComposite; + private Composite joinColumnsGroupPane; + private Button overrideDefaultButton; + private WritablePropertyValueModel<IOverride> overrideHolder; + /** * Creates a new <code>OverridesComposite</code>. * @@ -114,8 +126,7 @@ public class OverridesComposite extends AbstractFormPane<IEntity> int index = associationOverride.specifiedJoinColumnsSize(); IJoinColumn joinColumn = associationOverride.addSpecifiedJoinColumn(index); - joinColumn.setSpecifiedName(stateObject.getName()); - joinColumn.setSpecifiedReferencedColumnName(stateObject.getReferencedColumnName()); + stateObject.updateJoinColumn(joinColumn); } private PostExecution<JoinColumnInAssociationOverrideDialog> buildAddJoinColumnPostExecution() { @@ -128,15 +139,29 @@ public class OverridesComposite extends AbstractFormPane<IEntity> }; } - private WritablePropertyValueModel<IAssociationOverride> buildAssociationOverrideHolder() { - return new SimplePropertyValueModel<IAssociationOverride>(); + private PropertyValueModel<IAssociationOverride> buildAssociationOverrideHolder(PropertyValueModel<IOverride> overrideHolder) { + return new TransformationPropertyValueModel<IOverride, IAssociationOverride>(overrideHolder) { + @Override + protected IAssociationOverride transform_(IOverride value) { + return (value instanceof IAssociationOverride) ? (IAssociationOverride) value : null; + } + }; + } + + private PropertyValueModel<IAttributeOverride> buildAttributeOverrideHolder(PropertyValueModel<IOverride> overrideHolder) { + return new TransformationPropertyValueModel<IOverride, IAttributeOverride>(overrideHolder) { + @Override + protected IAttributeOverride transform_(IOverride value) { + return (value instanceof IAttributeOverride) ? (IAttributeOverride) value : null; + } + }; } - private PropertyValueModel<IColumn> buildColumnHolder() { - return new TransformationPropertyValueModel<IEntity, IColumn>(getSubjectHolder()) { + private PropertyValueModel<IColumn> buildColumnHolder(PropertyValueModel<IAttributeOverride> attributeOverrideHolder) { + return new TransformationPropertyValueModel<IAttributeOverride, IColumn>(attributeOverrideHolder) { @Override - protected IColumn transform_(IEntity value) { - return null; //TODO + protected IColumn transform_(IAttributeOverride value) { + return value.getColumn(); } }; } @@ -155,98 +180,139 @@ public class OverridesComposite extends AbstractFormPane<IEntity> return new JoinColumnsProvider(); } - private ListValueModel<IAssociationOverride> buildOverrideAttributesListHolder() { - return new ListAspectAdapter<IEntity, IAssociationOverride>( - getSubjectHolder(), - IEntity.DEFAULT_ASSOCIATION_OVERRIDES_LIST, - IEntity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST) - { + private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder() { + return new SimplePropertyValueModel<Boolean>(); + } + + private SelectionListener buildOverrideDefaultSelectionListener() { + return new SelectionAdapter(){ @Override - protected ListIterator<IAssociationOverride> listIterator_() { - return subject.associationOverrides(); + public void widgetSelected(SelectionEvent e) { + if (!isPopulating()) { + Button button = (Button) e.widget; + overrideDefaultButtonSelected(button.getSelection()); + } } }; } - private StringConverter<IAssociationOverride> buildOverrideAttributesStringConverter() { - return new StringConverter<IAssociationOverride>() { - public String convertToString(IAssociationOverride item) { - return item.getName(); + private PropertyValueModel<Boolean> buildOverrideDefaultVisibilityHolder() { + return new TransformationPropertyValueModel<IOverride, Boolean>(overrideHolder) { + @Override + protected Boolean transform(IOverride value) { + return (value != null); } }; } - private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder() { - return new PropertyAspectAdapter<IEntity, Boolean>(getSubjectHolder(), "") { + private String buildOverrideDisplayString(IOverride override) { + + IEntity subject = subject(); + String overrideType; + int index = 0; + + // Retrieve the index and type + if (override instanceof IAssociationOverride) { + index = CollectionTools.indexOf(subject.associationOverrides(), override); + overrideType = JptUiMappingsMessages.OverridesComposite_association; + } + else { + index = CollectionTools.indexOf(subject.attributeOverrides(), override); + overrideType = JptUiMappingsMessages.OverridesComposite_attribute; + } + + // Format the name + String name = override.getName(); + + if (StringTools.stringIsEmpty(name)) { + name = JptUiMappingsMessages.OverridesComposite_noName; + } + else { + name = name.trim(); + } + + // Format: <name> (Association <index>), we show the index since + // it's possible to have one than one override with the same name + StringBuilder sb = new StringBuilder(); + sb.append(name); + sb.append(" ("); + sb.append(overrideType); + sb.append(" "); + sb.append(index + 1); + sb.append(") "); + return sb.toString(); + } + + private WritablePropertyValueModel<IOverride> buildOverrideHolder() { + return new SimplePropertyValueModel<IOverride>(); + } + + private ILabelProvider buildOverrideLabelProvider() { + return new LabelProvider() { @Override - protected Boolean buildValue_() { - return true; + public String getText(Object element) { + return buildOverrideDisplayString((IOverride) element); } + }; + } - @Override - protected void setValue_(Boolean value) { - // Not done here + private Adapter buildOverridesAdapter() { + return new AddRemoveListPane.AbstractAdapter() { + + public void addNewItem(ObjectListSelectionModel listSelectionModel) { + } + + public void removeSelectedItems(ObjectListSelectionModel listSelectionModel) { + removeOverrides(listSelectionModel); } }; } - private SelectionListener buildOverrideDefaultSelectionListener() { - return new SelectionAdapter(){ + private ListValueModel<IOverride> buildOverridesListHolder() { + // TODO: Use an aggregate/composite ListValueModel + return new ListAspectAdapter<IEntity, IOverride>( + getSubjectHolder(), + IEntity.DEFAULT_ASSOCIATION_OVERRIDES_LIST, + IEntity.DEFAULT_ATTRIBUTE_OVERRIDES_LIST, + IEntity.SPECIFIED_ASSOCIATION_OVERRIDES_LIST, + IEntity.SPECIFIED_ATTRIBUTE_OVERRIDES_LIST) + { @Override - public void widgetSelected(SelectionEvent e) { - Button button = (Button) e.widget; - overrideDefaultButtonSelected(button.getSelection()); + protected ListIterator<IOverride> listIterator_() { + ArrayList<IOverride> list = new ArrayList<IOverride>(); + CollectionTools.addAll(list, subject.associationOverrides()); + CollectionTools.addAll(list, subject.attributeOverrides()); + return list.listIterator(); } }; } - private PageBook buildOverridePageBook(Composite parent) { - return new PageBook(parent, SWT.NONE); + private Composite buildPane(Composite container, int groupBoxMargin) { + return buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin); } - private ListValueModel<IAssociationOverride> buildSortedOverrideAttributesListHolder() { - return new SortedListValueModelAdapter<IAssociationOverride>( - buildOverrideAttributesListHolder() - ); + private Transformer<IOverride, Control> buildPaneTransformer() { + return new Transformer<IOverride, Control>() { + public Control transform(IOverride override) { + + if (override instanceof IAttributeOverride) { + return columnComposite.getControl(); + } + + if (override instanceof IAssociationOverride) { + return joinColumnsGroupPane; + } + + return null; + } + }; } -// public void doPopulate(EObject obj) { -// this.entity = (IEntity) obj; -// if (this.entity == null) { -// this.selectedOverride = null; -// this.columnComposite.populate(null); -// this.joinColumnsComposite.populate(null); -// this.listViewer.setInput(null); -// return; -// } -// -// if (this.listViewer.getInput() != entity) { -// this.listViewer.setInput(entity); -// } -// if (!this.subject().getAttributeOverrides().isEmpty()) { -// if (this.listViewer.getSelection().isEmpty()) { -// IOverride override = this.subject().getAttributeOverrides().get(0); -// this.listViewer.setSelection(new StructuredSelection(override)); -// } -// else { -// Object selection = ((StructuredSelection) this.listViewer.getSelection()).getFirstElement(); -// if (selection instanceof IAttributeOverride) { -// this.overridePageBook.showPage(this.columnComposite.getControl()); -// this.columnComposite.enableWidgets(true); -// this.columnComposite.populate(((IAttributeOverride) selection).getColumn()); -// } -// else { -// this.overridePageBook.showPage(this.joinColumnsComposite.getControl()); -// this.joinColumnsComposite.enableWidgets(true); -// this.joinColumnsComposite.populate(new JoinColumnsOwner((IAssociationOverride) selection)); -// } -// } -// } -// else { -// this.columnComposite.populate(null); -// this.ge.enableWidgets(false); -// } -// } + private ListValueModel<IOverride> buildSortedOverridesListHolder() { + return new SortedListValueModelAdapter<IOverride>( + buildOverridesListHolder() + ); + } private void editJoinColumn(IJoinColumn joinColumn) { @@ -257,34 +323,16 @@ public class OverridesComposite extends AbstractFormPane<IEntity> } private void editJoinColumn(JoinColumnInAssociationOverrideStateObject stateObject) { + stateObject.updateJoinColumn(stateObject.getJoinColumn()); + } - IJoinColumn joinColumn = stateObject.getJoinColumn(); - String name = stateObject.getName(); - String referencedColumnName = stateObject.getReferencedColumnName(); - - // Name - if (stateObject.isDefaultNameSelected()) { - if (joinColumn.getSpecifiedName() != null) { - joinColumn.setSpecifiedName(null); - } - } - else if (joinColumn.getSpecifiedName() == null || - !joinColumn.getSpecifiedName().equals(name)){ - - joinColumn.setSpecifiedName(name); - } - - // Referenced Column Name - if (stateObject.isDefaultReferencedColumnNameSelected()) { - if (joinColumn.getSpecifiedReferencedColumnName() != null) { - joinColumn.setSpecifiedReferencedColumnName(null); - } - } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || - !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)) { - - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } + /* + * (non-Javadoc) + */ + @Override + protected void initialize() { + super.initialize(); + overrideHolder = buildOverrideHolder(); } /* @@ -293,30 +341,28 @@ public class OverridesComposite extends AbstractFormPane<IEntity> @Override protected void initializeLayout(Composite container) { - WritablePropertyValueModel<IAssociationOverride> associationOverrideHolder = - buildAssociationOverrideHolder(); + int groupBoxMargin = groupBoxMargin(); - // Attribute Overrides group pane + // Overrides group pane container = buildTitledPane( container, JptUiMappingsMessages.AttributeOverridesComposite_attributeOverrides ); - List list = buildList( - container, + // Overrides list pane + new AddRemoveListPane<IEntity>( + this, + buildSubPane(container, 8), + buildOverridesAdapter(), + buildSortedOverridesListHolder(), + overrideHolder, + buildOverrideLabelProvider(), IJpaHelpContextIds.ENTITY_ATTRIBUTE_OVERRIDES ); - ListBoxModelAdapter.adapt( - buildSortedOverrideAttributesListHolder(), - associationOverrideHolder, - list, - buildOverrideAttributesStringConverter() - ); - // Override Default check box - Button overrideDefaultButton = buildCheckBox( - container, + overrideDefaultButton = buildCheckBox( + buildPane(container, groupBoxMargin), JptUiMappingsMessages.AttributeOverridesComposite_overrideDefault, buildOverrideDefaultHolder() ); @@ -325,94 +371,120 @@ public class OverridesComposite extends AbstractFormPane<IEntity> buildOverrideDefaultSelectionListener() ); - // Override sub-pane -// PageBook overridePane = buildOverridePageBook(container); + installOverrideDefaultControlVisibilityEnabler(overrideDefaultButton); - // Join Columns widgets - Group joinColumnGroupPane = buildTitledPane( - container, + // The pane responsible to show either the Join Columns or the Column pane + PageBook pageBook = buildPageBook(container); + + // Join Columns group pane (for IOverrideAssociation) + joinColumnsGroupPane = buildTitledPane( + pageBook, JptUiMappingsMessages.OverridesComposite_joinColumn ); -// overridePane.showPage(joinColumnGroupPane); - - JoinColumnsComposite<IAssociationOverride> joinColumnsComposite = - new JoinColumnsComposite<IAssociationOverride>( - this, - associationOverrideHolder, - joinColumnGroupPane, - buildJoinColumnsEditor() - ); + // Join Columns list pane (for IOverrideAssociation) + joinColumnsComposite = new JoinColumnsComposite<IAssociationOverride>( + this, + buildAssociationOverrideHolder(overrideHolder), + joinColumnsGroupPane, + buildJoinColumnsEditor() + ); - // Column widgets - new ColumnComposite( + // Column widgets (for IOverrideAttribute) + columnComposite = new ColumnComposite( this, - buildColumnHolder(), - joinColumnGroupPane + buildColumnHolder(buildAttributeOverrideHolder(overrideHolder)), + pageBook ); -// overridePane.showPage(joinColumnsComposite.getControl()); + // Hide both panes, the ControlSwitcher will show the right pane based on + // on the selected IOverride + joinColumnsGroupPane.setVisible(false); + columnComposite.setVisible(false); + joinColumnsComposite.enableWidgets(false); + columnComposite.enableWidgets(false); + installControlSwitcher(overrideHolder, pageBook); + } + + private void installControlSwitcher(PropertyValueModel<IOverride> overrideHolder, + PageBook pageBook) { + + new ControlSwitcher<IOverride>( + overrideHolder, + buildPaneTransformer(), + pageBook + ); + } + + private void installOverrideDefaultControlVisibilityEnabler(Button overrideDefaultCheckBox) { + + new ControlVisibilityEnabler( + buildOverrideDefaultVisibilityHolder(), + overrideDefaultCheckBox + ); } private void overrideDefaultButtonSelected(boolean selected) { - IEntity entity = subject(); - IOverride override = null; + IEntity subject = subject(); + IOverride override = overrideHolder.value(); - if (selected) { - if (override instanceof IAttributeOverride) { - int index = entity.specifiedAttributeOverridesSize(); - IAttributeOverride attributeOverride = entity.addSpecifiedAttributeOverride(index); - attributeOverride.setName(override.getName()); - attributeOverride.getColumn().setSpecifiedName(((IAttributeOverride) override).getColumn().getName()); + joinColumnsComposite.enableWidgets(selected); + columnComposite.enableWidgets(selected); + + setPopulating(true); + + try { + // Add a new override + if (selected) { + + if (override instanceof IAttributeOverride) { + int index = subject.specifiedAttributeOverridesSize(); + IAttributeOverride attributeOverride = subject.addSpecifiedAttributeOverride(index); + attributeOverride.setName(override.getName()); + attributeOverride.getColumn().setSpecifiedName(((IAttributeOverride) override).getColumn().getName()); + } + else { + int index = subject.specifiedAssociationOverridesSize(); + IAssociationOverride associationOverride = subject.addSpecifiedAssociationOverride(index); + associationOverride.setName(override.getName()); + //attributeOverride.getColumn().setSpecifiedName(this.attributeOverride.getColumn().getName()); + } } + // Remove the specified overrides else { - int index = entity.specifiedAssociationOverridesSize(); - IAssociationOverride associationOverride = entity.addSpecifiedAssociationOverride(index); - associationOverride.setName(override.getName()); - //attributeOverride.getColumn().setSpecifiedName(this.attributeOverride.getColumn().getName()); + + if (override instanceof IAttributeOverride) { + subject.removeSpecifiedAttributeOverride((IAttributeOverride) override); + } + else { + subject.removeSpecifiedAssociationOverride((IAssociationOverride) override); + } } } - else { + finally { + setPopulating(false); + } + } + + private void removeOverrides(ObjectListSelectionModel listSelectionModel) { + + IEntity subject = subject(); + Object[] selectedItems = listSelectionModel.selectedValues(); + + for (int index = selectedItems.length; --index >= 0; ) { + + IOverride override = (IOverride) selectedItems[index]; + if (override instanceof IAttributeOverride) { - int index = CollectionTools.indexOf(entity.specifiedAttributeOverrides(), override); - this.subject().removeSpecifiedAttributeOverride(index); + subject.removeSpecifiedAttributeOverride((IAttributeOverride) override); } - else { - int index = CollectionTools.indexOf(entity.specifiedAssociationOverrides(), override); - this.subject().removeSpecifiedAssociationOverride(index); + else if (override instanceof IAssociationOverride) { + subject.removeSpecifiedAssociationOverride((IAssociationOverride) override); } } } - protected void overridesListSelectionChanged(SelectionChangedEvent event) { -// if (((StructuredSelection) event.getSelection()).isEmpty()) { -// this.columnComposite.populate(null); -// this.columnComposite.enableWidgets(false); -// this.overrideDefaultButton.setSelection(false); -// this.overrideDefaultButton.setEnabled(false); -// } -// else { -// this.selectedOverride = getSelectedOverride(); -// if (this.selectedOverride instanceof IAttributeOverride) { -// boolean specifiedOverride = this.subject().getSpecifiedAttributeOverrides().contains(this.selectedOverride); -// this.overrideDefaultButton.setSelection(specifiedOverride); -// this.overridePageBook.showPage(this.columnComposite.getControl()); -// this.columnComposite.populate(((IAttributeOverride) this.selectedOverride).getColumn()); -// this.columnComposite.enableWidgets(specifiedOverride); -// this.overrideDefaultButton.setEnabled(true); -// } -// else { -// boolean specifiedOverride = this.subject().getSpecifiedAssociationOverrides().contains(this.selectedOverride); -// this.overrideDefaultButton.setSelection(specifiedOverride); -// this.overridePageBook.showPage(this.joinColumnsComposite.getControl()); -// this.joinColumnsComposite.populate(new JoinColumnsOwner((IAssociationOverride) getSelectedOverride())); -// this.joinColumnsComposite.enableWidgets(specifiedOverride); -// this.overrideDefaultButton.setEnabled(true); -// } -// } - } - private class JoinColumnsProvider implements IJoinColumnsEditor<IAssociationOverride> { public void addJoinColumn(IAssociationOverride subject) { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java index 176a424d8e..82749a5454 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsComposite.java @@ -32,6 +32,7 @@ import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionMod import org.eclipse.osgi.util.NLS; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; @@ -40,13 +41,15 @@ import org.eclipse.swt.widgets.Group; * Here the layout of this pane: * <pre> * ----------------------------------------------------------------------------- - * | | - * | x Override Default Join Columns | - * | | - * | - Primary Key Join Columns ---------------------------------------------- | + * | - Join Columns ---------------------------------------------------------- | * | | | | - * | | AddRemoveListPane | | + * | | x Override Default | | * | | | | + * | | --------------------------------------------------------------------- | | + * | | | | | | + * | | | AddRemoveListPane | | | + * | | | | | | + * | | --------------------------------------------------------------------- | | * | ------------------------------------------------------------------------- | * -----------------------------------------------------------------------------</pre> * @@ -58,6 +61,7 @@ import org.eclipse.swt.widgets.Group; */ public class PrimaryKeyJoinColumnsComposite extends AbstractFormPane<IEntity> { + private AddRemoveListPane<IEntity> joinColumnsListPane; private Button overrideDefaultJoinColumnsCheckBox; /** @@ -88,11 +92,11 @@ public class PrimaryKeyJoinColumnsComposite extends AbstractFormPane<IEntity> private void addJoinColumn(PrimaryKeyJoinColumnStateObject stateObject) { - int index = subject().specifiedPrimaryKeyJoinColumnsSize(); + IEntity subject = subject(); + int index = subject.specifiedPrimaryKeyJoinColumnsSize(); - IPrimaryKeyJoinColumn joinColumn = subject().addSpecifiedPrimaryKeyJoinColumn(index); - joinColumn.setSpecifiedName(stateObject.getName()); - joinColumn.setSpecifiedReferencedColumnName(stateObject.getReferencedColumnName()); + IPrimaryKeyJoinColumn joinColumn = subject.addSpecifiedPrimaryKeyJoinColumn(index); + stateObject.updateJoinColumn(joinColumn); } private void addPrimaryKeyJoinColumn() { @@ -110,8 +114,12 @@ public class PrimaryKeyJoinColumnsComposite extends AbstractFormPane<IEntity> }; } - String buildDefaultJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { - return NLS.bind(JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, joinColumn.getName(), joinColumn.getReferencedColumnName()); + private String buildDefaultJoinColumnLabel(IPrimaryKeyJoinColumn joinColumn) { + return NLS.bind( + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_mappingBetweenTwoParamsDefault, + joinColumn.getName(), + joinColumn.getReferencedColumnName() + ); } private PostExecution<PrimaryKeyJoinColumnDialog> buildEditPrimaryKeyJoinColumnPostExecution() { @@ -219,36 +227,19 @@ public class PrimaryKeyJoinColumnsComposite extends AbstractFormPane<IEntity> } private WritablePropertyValueModel<Boolean> buildOverrideDefaultJoinColumnHolder() { - // TODO return new SimplePropertyValueModel<Boolean>(); } - private SelectionAdapter buildOverrideDefaultJoinColumnSelectionListener() { + private SelectionListener buildOverrideDefaultJoinColumnSelectionListener() { return new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - Button button = (Button) e.widget; - IEntity entity = subject(); - - if (button.getSelection()) { - IPrimaryKeyJoinColumn defaultJoinColumn = entity.getDefaultPrimaryKeyJoinColumn(); //TODO sometimes null - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - IPrimaryKeyJoinColumn pkJoinColumn = entity.addSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumn.setSpecifiedName(columnName); - pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } - else { - for (int index = entity.specifiedPrimaryKeyJoinColumnsSize(); --index >= 0; ) { - entity.removeSpecifiedPrimaryKeyJoinColumn(index); - } - } + updateJoinColumns(); } }; } - private ListValueModel/*<IPrimaryKeyJoinColumn>*/ buildSortedJoinColumnsListHolder() { + private ListValueModel<IPrimaryKeyJoinColumn> buildSortedJoinColumnsListHolder() { return new SortedListValueModelAdapter<IPrimaryKeyJoinColumn>( buildJoinColumnsListHolder() ); @@ -260,39 +251,16 @@ public class PrimaryKeyJoinColumnsComposite extends AbstractFormPane<IEntity> @Override protected void doPopulate() { super.doPopulate(); - overrideDefaultJoinColumnsCheckBox.setSelection(subject().specifiedPrimaryKeyJoinColumnsSize() > 0); - } - private void editJoinColumn(PrimaryKeyJoinColumnStateObject stateObject) { - - IPrimaryKeyJoinColumn joinColumn = stateObject.getJoinColumn(); + IEntity entity = subject(); + boolean enabled = (entity != null) && (entity.specifiedPrimaryKeyJoinColumnsSize() > 0); - String name = stateObject.getName(); - String referencedColumnName = stateObject.getReferencedColumnName(); - - // Name - if (stateObject.isDefaultNameSelected()) { - if (joinColumn.getSpecifiedName() != null) { - joinColumn.setSpecifiedName(null); - } - } - else if (joinColumn.getSpecifiedName() == null || - !joinColumn.getSpecifiedName().equals(name)){ - - joinColumn.setSpecifiedName(name); - } - - // Referenced Column Name - if (stateObject.isDefaultReferencedColumnNameSelected()) { - if (joinColumn.getSpecifiedReferencedColumnName() != null) { - joinColumn.setSpecifiedReferencedColumnName(null); - } - } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || - !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ + overrideDefaultJoinColumnsCheckBox.setSelection(enabled); + joinColumnsListPane.enableWidgets(enabled); + } - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } + private void editJoinColumn(PrimaryKeyJoinColumnStateObject stateObject) { + stateObject.updateJoinColumn(stateObject.getJoinColumn()); } private void editPrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { @@ -309,11 +277,15 @@ public class PrimaryKeyJoinColumnsComposite extends AbstractFormPane<IEntity> @Override protected void initializeLayout(Composite container) { - int groupBoxMargin = groupBoxMargin(); + // Primary Key Join Columns group pane + Group groupPane = buildTitledPane( + container, + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn + ); // Override Default Join Columns check box overrideDefaultJoinColumnsCheckBox = buildCheckBox( - buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin), + buildSubPane(groupPane, 8), JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns, buildOverrideDefaultJoinColumnHolder()); @@ -321,16 +293,10 @@ public class PrimaryKeyJoinColumnsComposite extends AbstractFormPane<IEntity> buildOverrideDefaultJoinColumnSelectionListener() ); - // Primary Key Join Columns group pane - Group pkJoinColumnsGroup = buildTitledPane( - container, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn - ); - // Primary Key Join Columns list pane - new AddRemoveListPane<IEntity>( + joinColumnsListPane = new AddRemoveListPane<IEntity>( this, - pkJoinColumnsGroup, + groupPane, buildJoinColumnsAdapter(), buildSortedJoinColumnsListHolder(), buildJoinColumnHolder(), @@ -338,4 +304,39 @@ public class PrimaryKeyJoinColumnsComposite extends AbstractFormPane<IEntity> IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS ); } + + private void updateJoinColumns() { + + IEntity subject = subject(); + boolean selected = overrideDefaultJoinColumnsCheckBox.getSelection(); + joinColumnsListPane.enableWidgets(selected); + setPopulating(true); + + try { + // Add a join column by creating a specified one using the default + // one if it exists + if (selected) { + + IPrimaryKeyJoinColumn defaultJoinColumn = subject.getDefaultPrimaryKeyJoinColumn(); //TODO sometimes null + + if (defaultJoinColumn != null) { + String columnName = defaultJoinColumn.getDefaultName(); + String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); + + IPrimaryKeyJoinColumn pkJoinColumn = subject.addSpecifiedPrimaryKeyJoinColumn(0); + pkJoinColumn.setSpecifiedName(columnName); + pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); + } + } + // Remove all the specified join columns + else { + for (int index = subject.specifiedPrimaryKeyJoinColumnsSize(); --index >= 0; ) { + subject.removeSpecifiedPrimaryKeyJoinColumn(index); + } + } + } + finally { + setPopulating(false); + } + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java index 89d700b53e..0813df7a29 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/PrimaryKeyJoinColumnsInSecondaryTableComposite.java @@ -22,8 +22,6 @@ import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; import org.eclipse.jpt.ui.internal.widgets.AddRemovePane; import org.eclipse.jpt.ui.internal.widgets.PostExecution; -import org.eclipse.jpt.utility.internal.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; import org.eclipse.jpt.utility.internal.model.value.ListValueModel; import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; @@ -33,21 +31,27 @@ import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueM import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; /** * Here the layout of this pane: * <pre> * ----------------------------------------------------------------------------- - * | | - * | x Override Default | - * | | - * | - Primary Key Join Columns ---------------------------------------------- | + * | - Join Columns ---------------------------------------------------------- | * | | | | - * | | AddRemoveListPane | | + * | | x Override Default | | * | | | | + * | | --------------------------------------------------------------------- | | + * | | | | | | + * | | | AddRemoveListPane | | | + * | | | | | | + * | | --------------------------------------------------------------------- | | * | ------------------------------------------------------------------------- | * -----------------------------------------------------------------------------</pre> * @@ -60,6 +64,9 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory; */ public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractFormPane<ISecondaryTable> { + private AddRemoveListPane<ISecondaryTable> joinColumnsListPane; + private Button overrideDefaultJoinColumnsCheckBox; + /** * Creates a new <code>PrimaryKeyJoinColumnsInSecondaryTableComposite</code>. * @@ -94,8 +101,7 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractForm int index = secondaryTable.specifiedPrimaryKeyJoinColumnsSize(); IPrimaryKeyJoinColumn joinColumn = secondaryTable.addSpecifiedPrimaryKeyJoinColumn(index); - joinColumn.setSpecifiedName(stateObject.getName()); - joinColumn.setSpecifiedReferencedColumnName(stateObject.getReferencedColumnName()); + stateObject.updateJoinColumn(joinColumn); } private void addPrimaryKeyJoinColumn() { @@ -167,7 +173,16 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractForm } private WritablePropertyValueModel<Boolean> buildOverrideDefaultHolder() { - return new OverrideDefaultValueModel(getSubjectHolder()); + return new SimplePropertyValueModel<Boolean>(); + } + + private SelectionListener buildOverrideDefaultJoinColumnSelectionListener() { + return new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateJoinColumns(); + } + }; } private AddRemovePane.Adapter buildPrimaryKeyJoinColumnAdapter() { @@ -220,6 +235,20 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractForm ); } + /* + * (non-Javadoc) + */ + @Override + protected void doPopulate() { + super.doPopulate(); + + ISecondaryTable subject = subject(); + boolean enabled = (subject != null) && subject.specifiedPrimaryKeyJoinColumnsSize() > 0; + + overrideDefaultJoinColumnsCheckBox.setSelection(enabled); + joinColumnsListPane.enableWidgets(enabled); + } + private void editPrimaryKeyJoinColumn(ObjectListSelectionModel listSelectionModel) { IPrimaryKeyJoinColumn joinColumn = (IPrimaryKeyJoinColumn) listSelectionModel.selectedValue(); @@ -231,33 +260,7 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractForm } private void editPrimaryKeyJoinColumn(PrimaryKeyJoinColumnInSecondaryTableStateObject stateObject) { - IPrimaryKeyJoinColumn joinColumn = stateObject.getJoinColumn(); - String name = stateObject.getName(); - String referencedColumnName = stateObject.getReferencedColumnName(); - - // Name - if (stateObject.isDefaultNameSelected()) { - if (joinColumn.getSpecifiedName() != null) { - joinColumn.setSpecifiedName(null); - } - } - else if (joinColumn.getSpecifiedName() == null || - !joinColumn.getSpecifiedName().equals(name)){ - - joinColumn.setSpecifiedName(name); - } - - // Referenced Column Name - if (stateObject.isDefaultReferencedColumnNameSelected()) { - if (joinColumn.getSpecifiedReferencedColumnName() != null) { - joinColumn.setSpecifiedReferencedColumnName(null); - } - } - else if (joinColumn.getSpecifiedReferencedColumnName() == null || - !joinColumn.getSpecifiedReferencedColumnName().equals(referencedColumnName)){ - - joinColumn.setSpecifiedReferencedColumnName(referencedColumnName); - } + stateObject.updateJoinColumn(stateObject.getJoinColumn()); } /* @@ -266,39 +269,37 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractForm @Override protected void initializeLayout(Composite container) { - int groupBoxMargin = groupBoxMargin(); + // Primary Key Join Columns group pane + Group groupPane = buildTitledPane( + container, + JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn + ); // Override Default check box - Button overrideDefaultButton = buildCheckBox( - buildSubPane(container, 0, groupBoxMargin, 0, groupBoxMargin), + overrideDefaultJoinColumnsCheckBox = buildCheckBox( + buildSubPane(groupPane, 8), JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_overrideDefaultPrimaryKeyJoinColumns, buildOverrideDefaultHolder() ); - installOverrideDefaultButtonEnabler(overrideDefaultButton); - - // Primary Key Join Columns group pane - container = buildTitledPane( - container, - JptUiMappingsMessages.PrimaryKeyJoinColumnsComposite_primaryKeyJoinColumn + overrideDefaultJoinColumnsCheckBox.addSelectionListener( + buildOverrideDefaultJoinColumnSelectionListener() ); - // Primary Key Join Columns add/remove list pane - AddRemoveListPane<ISecondaryTable> pkJoinColumnListPane = new AddRemoveListPane<ISecondaryTable>( + installOverrideDefaultButtonEnabler(overrideDefaultJoinColumnsCheckBox); + + // Primary Key Join Columns list pane + joinColumnsListPane = new AddRemoveListPane<ISecondaryTable>( this, - container, + groupPane, buildPrimaryKeyJoinColumnAdapter(), buildSortedPrimaryKeyJoinColumnListHolder(), buildPrimaryKeyJoinColumnHolder(), - buildJoinColumnsListLabelProvider() - ); - - helpSystem().setHelp( - pkJoinColumnListPane.getControl(), + buildJoinColumnsListLabelProvider(), IJpaHelpContextIds.MAPPING_JOIN_TABLE_COLUMNS ); - installPrimaryKeyJoinColumnListPaneEnabler(pkJoinColumnListPane); + installPrimaryKeyJoinColumnListPaneEnabler(joinColumnsListPane); } private void installOverrideDefaultButtonEnabler(Button overrideDefaultButton) { @@ -325,80 +326,32 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractForm } } - private class OverrideDefaultValueModel extends TransformationPropertyValueModel<ISecondaryTable, Boolean> - implements WritablePropertyValueModel<Boolean> - { - OverrideDefaultValueModel(PropertyValueModel<ISecondaryTable> valueHolder) { - super(valueHolder); - engageListChangeListener(valueHolder); - } - - private void engageListChangeListener(PropertyValueModel<ISecondaryTable> valueHolder) { - new ListAspectAdapter<ISecondaryTable, IPrimaryKeyJoinColumn>(valueHolder, ISecondaryTable.SPECIFIED_PRIMARY_KEY_JOIN_COLUMNS_LIST) { - @Override - protected void itemsAdded(ListChangeEvent e) { - super.itemsAdded(e); - valueChanged(e); - } - - @Override - protected void itemsMoved(ListChangeEvent e) { - super.itemsMoved(e); - valueChanged(e); - } - - @Override - protected void itemsRemoved(ListChangeEvent e) { - super.itemsRemoved(e); - valueChanged(e); - } + private void updateJoinColumns() { - @Override - protected void itemsReplaced(ListChangeEvent e) { - super.itemsReplaced(e); - valueChanged(e); - } + if (isPopulating()) { + return; + } - @Override - protected void listChanged(ListChangeEvent e) { - super.listChanged(e); - valueChanged(e); - } + ISecondaryTable secondaryTable = subject(); + boolean selected = overrideDefaultJoinColumnsCheckBox.getSelection(); + joinColumnsListPane.enableWidgets(selected); + setPopulating(true); - @Override - protected void listCleared(ListChangeEvent e) { - super.listCleared(e); - valueChanged(e); - } + try { + // Add a join column by creating a specified one using the default + // one if it exists + if (selected) { - @Override - protected ListIterator<IPrimaryKeyJoinColumn> listIterator_() { - return subject.specifiedPrimaryKeyJoinColumns(); - } + IPrimaryKeyJoinColumn defaultJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn();//TODO possibly null - @Override - protected int size_() { - return subject.specifiedPrimaryKeyJoinColumnsSize(); - } + if (defaultJoinColumn != null) { + String columnName = defaultJoinColumn.getDefaultName(); + String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - private void valueChanged(ListChangeEvent e) { - PropertyChangeEvent event = new PropertyChangeEvent(e.getSource(), e.aspectName(), null, subject); - OverrideDefaultValueModel.this.valueChanged(event); + IPrimaryKeyJoinColumn pkJoinColumn = secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); + pkJoinColumn.setSpecifiedName(columnName); + pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); } - }; - } - - public void setValue(Boolean value) { - ISecondaryTable secondaryTable = subject(); - - if (value) { - IPrimaryKeyJoinColumn defaultJoinColumn = secondaryTable.getDefaultPrimaryKeyJoinColumn();//TODO possibly null - String columnName = defaultJoinColumn.getDefaultName(); - String referencedColumnName = defaultJoinColumn.getDefaultReferencedColumnName(); - - IPrimaryKeyJoinColumn pkJoinColumn = secondaryTable.addSpecifiedPrimaryKeyJoinColumn(0); - pkJoinColumn.setSpecifiedName(columnName); - pkJoinColumn.setSpecifiedReferencedColumnName(referencedColumnName); } else { for (int index = secondaryTable.specifiedPrimaryKeyJoinColumnsSize(); --index >= 0; ) { @@ -406,10 +359,8 @@ public class PrimaryKeyJoinColumnsInSecondaryTableComposite extends AbstractForm } } } - - @Override - protected Boolean transform_(ISecondaryTable value) { - return value.specifiedPrimaryKeyJoinColumnsSize() > 0; + finally { + setPopulating(false); } } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java index f6e09f16ad..30b52d0e19 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableGeneratorComposite.java @@ -126,13 +126,10 @@ public class TableGeneratorComposite extends GeneratorComposite<ITableGenerator> @Override protected Iterator<String> values() { - Table table = table(); - - if (table != null) { - return table.columnNames(); + if (subject() == null) { + return EmptyIterator.instance(); } - - return EmptyIterator.instance(); + return super.values(); } }; } @@ -185,13 +182,10 @@ public class TableGeneratorComposite extends GeneratorComposite<ITableGenerator> @Override protected Iterator<String> values() { - Table table = table(); - - if (table != null) { - return table.columnNames(); + if (subject() == null) { + return EmptyIterator.instance(); } - - return EmptyIterator.instance(); + return super.values(); } }; } @@ -253,6 +247,9 @@ public class TableGeneratorComposite extends GeneratorComposite<ITableGenerator> @Override protected Iterator<String> values() { + if (subject() == null) { + return EmptyIterator.instance(); + } String schemaName = subject().getSchema(); Database database = database(); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlEnabler.java index 29465b0394..dab406b30b 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlEnabler.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlEnabler.java @@ -22,7 +22,7 @@ import org.eclipse.swt.widgets.Control; * @version 2.0 * @since 2.0 */ -public class ControlEnabler extends AbstractControlEnabler +public class ControlEnabler extends StateController { /** * Creates a new <code>ControlEnabler</code> with a default value of @@ -153,7 +153,11 @@ public class ControlEnabler extends AbstractControlEnabler }); } + /** + * This holder holds onto a <code>Control</code> and update its enabled state. + */ private static class ControlHolder implements IControlHolder { + private final Control control; ControlHolder(Control control) { @@ -161,10 +165,10 @@ public class ControlEnabler extends AbstractControlEnabler this.control = control; } - public void setEnabled(boolean enabled) { + public void updateState(boolean state) { if (!this.control.isDisposed()) { - this.control.setEnabled(enabled); + this.control.setEnabled(state); } } } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java new file mode 100644 index 0000000000..e70c010f7d --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlSwitcher.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import org.eclipse.jpt.utility.internal.Transformer; +import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; +import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.part.PageBook; + +/** + * This controller is responsible to switch the active page based on a value. A + * <code>Transformer</code> is used to transformed that value into a + * <code>Control</code>. + * + * @version 2.0 + * @since 2.0 + */ +public final class ControlSwitcher<T> +{ + /** + * The widget that is used to show the active <code>Control</code>. + */ + private PageBook pageBook; + + /** + * The <code>Transformer</code> used to transform the value into a + * <code>Control</code>. + */ + private Transformer<T, Control> paneTransformer; + + /** + * Creates a new <code>ControlSwitcher</code>. + * + * @param switchHolder The holder of the value that will be used to retrieve + * the right <code>Control</code> when passed to the given transformer + * @param paneTransformer The <code>Transformer</code> used to transform the value into a + * <code>Control</code> + * @param pageBook The <code>Transformer</code> used to transform the value + * into a <code>Control</code> + */ + public ControlSwitcher(PropertyValueModel<T> switchHolder, + Transformer<T, Control> paneTransformer, + PageBook pageBook) + { + super(); + initialize(switchHolder, paneTransformer, pageBook); + } + + @SuppressWarnings("unchecked") + private PropertyChangeListener buildPropertyChangeListener() { + return new PropertyChangeListener() { + public void propertyChanged(PropertyChangeEvent e) { + switchPanes((T) e.newValue()); + } + }; + } + + /** + * Initializes this <code>ControlSwitcher</code>. + * + * @param switchHolder The holder of the value that will be used to retrieve + * the right <code>Control</code> when passed to the given transformer + * @param paneTransformer The <code>Transformer</code> used to transform the value into a + * <code>Control</code> + * @param pageBook The <code>Transformer</code> used to transform the value + * into a <code>Control</code> + */ + private void initialize(PropertyValueModel<T> switchHolder, + Transformer<T, Control> paneTransformer, + PageBook pageBook) + { + this.pageBook = pageBook; + this.paneTransformer = paneTransformer; + + switchHolder.addPropertyChangeListener( + PropertyValueModel.VALUE, + buildPropertyChangeListener() + ); + + switchPanes(switchHolder.value()); + } + + /** + * Switches the active page by transforming the given value into its + * corresponding pane. + * + * @param value The state passed to the transformer in order to retrieve the + * new pane + */ + private void switchPanes(T value) { + + if (pageBook.isDisposed()) { + return; + } + + Control pane = paneTransformer.transform(value); + + if (pane == null) { + pageBook.showPage(new Label(pageBook, SWT.SEPARATOR)); + } + else { + pageBook.showPage(pane); + } + + pageBook.setVisible(pane != null); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlVisibilityEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlVisibilityEnabler.java new file mode 100644 index 0000000000..0994308e12 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlVisibilityEnabler.java @@ -0,0 +1,174 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import java.util.Collection; +import java.util.Iterator; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; +import org.eclipse.swt.widgets.Control; + +/** + * This <code>ControlVisibilityEnabler</code> keeps the "visible" state of a + * collection of controls in synch with the provided boolean holder. + * + * @version 2.0 + * @since 2.0 + */ +public class ControlVisibilityEnabler extends StateController +{ + /** + * Creates a new <code>ControlVisibilityEnabler</code> with a default value + * of <code>false</code> (i.e. not visible). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls The collection of controls whose "visible" state is + * kept in sync with the boolean holder's value + */ + public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<? extends Control> controls) { + + this(booleanHolder, controls, false); + } + + /** + * Creates a new <code>ControlVisibilityEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls The collection of controls whose "visible" state is + * kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<? extends Control> controls, + boolean defaultValue) { + + this(booleanHolder, controls.iterator(), defaultValue); + } + + /** + * Creates a new <code>ControlVisibilityEnabler</code> with a default value of + * <code>false</code> (i.e. not visible). + * + * @param booleanHolder A value model on the underlying boolean model + * @param control The control whose "visible" state is + * kept in sync with the boolean holder's value + */ + public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Control control) { + + this(booleanHolder, control, false); + } + + /** + * Creates a new <code>ControlVisibilityEnabler</code> with a default value of + * <code>false</code> (i.e. not visible). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls The collection of controls whose "visible" state is + * kept in sync with the boolean holder's value + */ + public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Control... controls) { + + this(booleanHolder, CollectionTools.iterator(controls), false); + } + + /** + * Creates a new <code>ControlVisibilityEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param control The control whose "visible" state is kept in sync with the + * boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Control control, + boolean defaultValue) { + + this(booleanHolder, CollectionTools.singletonIterator(control), false); + } + + /** + * Creates a new <code>ControlVisibilityEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls The collection of controls whose "visible" state is kept + * in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Control[] controls, + boolean defaultValue) { + + this(booleanHolder, CollectionTools.iterator(controls), defaultValue); + } + + /** + * Creates a new <code>ControlVisibilityEnabler</code> with a default value + * of <code>false</code> (i.e. not visible). + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls An iterator on the collection of controls whose "visible" + * state is kept in sync with the boolean holder's value + */ + public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<? extends Control> controls) { + + this(booleanHolder, controls, false); + } + + /** + * Creates a new <code>ControlVisibilityEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param controls An iterator on the collection of controls whose "visible" + * state is kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public ControlVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<? extends Control> controls, + boolean defaultValue) { + + super(booleanHolder, wrap(controls), defaultValue); + } + + private static Collection<IControlHolder> wrap(Iterator<? extends Control> controls) { + return CollectionTools.collection(new TransformationIterator<Control, IControlHolder>(controls) { + @Override + protected IControlHolder transform(Control control) { + return new ControlHolder(control); + } + }); + } + + /** + * This holder holds onto a <code>Control</code> and update its visible state. + */ + private static class ControlHolder implements IControlHolder { + private final Control control; + + ControlHolder(Control control) { + super(); + this.control = control; + } + + public void updateState(boolean state) { + if (!this.control.isDisposed()) { + this.control.setVisible(state); + } + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneEnabler.java index d30451fb20..44390e721a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneEnabler.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneEnabler.java @@ -22,7 +22,7 @@ import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; * @version 2.0 * @since 2.0 */ -public class PaneEnabler extends AbstractControlEnabler +public class PaneEnabler extends StateController { /** * Creates a new <code>PaneEnabler</code> with a default value of @@ -153,6 +153,10 @@ public class PaneEnabler extends AbstractControlEnabler }); } + /** + * This holder holds onto an <code>AbstractPane</code> and update its enabled + * state. + */ private static class PaneHolder implements IControlHolder { private final AbstractPane<?> pane; @@ -161,8 +165,8 @@ public class PaneEnabler extends AbstractControlEnabler this.pane = pane; } - public void setEnabled(boolean enabled) { - this.pane.enableWidgets(enabled); + public void updateState(boolean state) { + this.pane.enableWidgets(state); } } -} +}
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneVisibilityEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneVisibilityEnabler.java new file mode 100644 index 0000000000..bc7e292c79 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/PaneVisibilityEnabler.java @@ -0,0 +1,172 @@ +/******************************************************************************* + * 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.ui.internal.util; + +import java.util.Collection; +import java.util.Iterator; +import org.eclipse.jpt.ui.internal.widgets.AbstractPane; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; +import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; + +/** + * This <code>PaneVisibilityEnabler</code> keeps the "visible" state of a + * collection of controls in synch with the provided boolean holder. + * + * @version 2.0 + * @since 2.0 + */ +public class PaneVisibilityEnabler extends StateController +{ + /** + * Creates a new <code>PaneVisibilityEnabler</code> with a default value of + * <code>false</code> (i.e. not visible). + * + * @param booleanHolder A value model on the underlying boolean model + * @param pane The pane whose "visible" state is kept in sync with the + * boolean holder's value + */ + public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + AbstractPane<?> pane) { + + this(booleanHolder, pane, false); + } + + /** + * Creates a new <code>PaneVisibilityEnabler</code> with a default value of + * <code>false</code> (i.e. not visible). + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes The collection of panes whose "visible" state is kept in sync + * with the boolean holder's value + */ + public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + AbstractPane<?>... panes) { + + this(booleanHolder, CollectionTools.collection(panes), false); + } + + /** + * Creates a new <code>PaneVisibilityEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param pane The pane whose "visible" state is kept in sync with the + * boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + AbstractPane<?> pane, + boolean defaultValue) { + + this(booleanHolder, CollectionTools.singletonIterator(pane), false); + } + + /** + * Creates a new <code>PaneVisibilityEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes The collection of panes whose "visible" state is kept in sync + * with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + AbstractPane<?>[] panes, + boolean defaultValue) { + + this(booleanHolder, CollectionTools.iterator(panes), defaultValue); + } + + /** + * Creates a new <code>PaneVisibilityEnabler</code> with a default value of + * <code>false</code> (i.e. not visible). + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes The collection of panes whose "visible" state is kept in sync + * with the boolean holder's value + */ + public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<? extends AbstractPane<?>> panes) { + + this(booleanHolder, panes, false); + } + + /** + * Creates a new <code>PaneVisibilityEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes The collection of panes whose "visible" state is kept in sync + * with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Collection<? extends AbstractPane<?>> panes, + boolean defaultValue) { + + this(booleanHolder, panes.iterator(), defaultValue); + } + + /** + * Creates a new <code>PaneVisibilityEnabler</code> with a default value of + * <code>false</code> (i.e. not visible). + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes An iterator on the collection of panes whose "visible" state + * is kept in sync with the boolean holder's value + */ + public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<? extends AbstractPane<?>> panes) { + + this(booleanHolder, panes, false); + } + + /** + * Creates a new <code>PaneVisibilityEnabler</code>. + * + * @param booleanHolder A value model on the underlying boolean model + * @param panes An iterator on the collection of panes whose "visible" state + * is kept in sync with the boolean holder's value + * @param defaultValue The value to use when the underlying model is + * <code>null</code> + */ + public PaneVisibilityEnabler(PropertyValueModel<Boolean> booleanHolder, + Iterator<? extends AbstractPane<?>> panes, + boolean defaultValue) { + + super(booleanHolder, wrap(panes), defaultValue); + } + + private static Collection<IControlHolder> wrap(Iterator<? extends AbstractPane<?>> panes) { + return CollectionTools.collection(new TransformationIterator<AbstractPane<?>, IControlHolder>(panes) { + @Override + protected IControlHolder transform(AbstractPane<?> pane) { + return new PaneHolder(pane); + } + }); + } + + /** + * This holder holds onto an <code>AbstractPane</code> and update its visible + * state. + */ + private static class PaneHolder implements IControlHolder { + private final AbstractPane<?> pane; + + PaneHolder(AbstractPane<?> pane) { + super(); + this.pane = pane; + } + + public void updateState(boolean state) { + this.pane.setVisible(state); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/AbstractControlEnabler.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/StateController.java index 2e19c58c62..48f29541d5 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/AbstractControlEnabler.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/StateController.java @@ -13,26 +13,29 @@ import java.util.Collection; import java.util.Iterator; import org.eclipse.core.runtime.Assert; import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.iterators.CloneIterator; import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; /** - * A <code>ControlEnabler</code> keeps the "enabled" state of a collection of - * widgets in synch with the provided boolean holder. + * A <code>StateController</code> keeps the state of a collection of widgets in + * synch with the provided boolean holder. * - * @see BaseControllerEnabler * @see ControlEnabler + * @see ControlVisibilityEnabler + * @see PaneEnabler + * @see PaneVisibilityEnabler * * @version 2.0 * @since 2.0 */ @SuppressWarnings("nls") -class AbstractControlEnabler +abstract class StateController { /** - * A listener that allows us to synchronize the controlHolders with changes made - * to the underlying boolean model. + * A listener that allows us to synchronize the controlHolders with changes + * made to the underlying boolean model. */ private PropertyChangeListener booleanChangeListener; @@ -42,144 +45,147 @@ class AbstractControlEnabler private PropertyValueModel<Boolean> booleanHolder; /** - * The collection of <code>IControlHolder</code>s whose "enabled" state is - * kept in sync with the boolean holder's value. + * The collection of <code>IControlHolder</code>s whose state is kept in sync + * with the boolean holder's value. */ private Collection<IControlHolder> controlHolders; /** - * The default setting for the "enabled" state; for when the underlying model - * is <code>null</code>. The default [default value] is <code>false<code> - * (i.e. the controlHolders are disabled). + * The default setting for the state; for when the underlying model is + * <code>null</code>. The default [default value] is <code>false<code>. */ private boolean defaultValue; /** - * Creates a new <code>AbstractControlEnabler</code>. + * Creates a new <code>StateController</code>. */ - AbstractControlEnabler() { + StateController() { super(); initialize(); } /** - * Creates a new <code>AbstractControlEnabler</code> with a default value of - * <code>false</code> (i.e. disabled). + * Creates a new <code>StateController</code> with a default value of + * <code>false</code>. * * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders The collection of controlHolders whose "enabled" state is - * kept in sync with the boolean holder's value + * @param controlHolders The collection of <code>IControlHolder</code>s whose + * state is kept in sync with the boolean holder's value */ - AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, - Collection<IControlHolder> controlHolders) { + StateController(PropertyValueModel<Boolean> booleanHolder, + Collection<IControlHolder> controlHolders) { this(booleanHolder, controlHolders, false); } /** - * Creates a new <code>ControlEnabler</code>. + * Creates a new <code>StateController</code> with a default value of + * <code>false</code>. * * @param booleanHolder A value model on the underlying boolean model * @param controlHolders The collection of <code>IControlHolder</code>s whose - * "enabled" state is kept in sync with the boolean holder's value + * state is kept in sync with the boolean holder's value * @param defaultValue The value to use when the underlying model is * <code>null</code> */ - AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, - Collection<IControlHolder> controlHolders, - boolean defaultValue) { + StateController(PropertyValueModel<Boolean> booleanHolder, + Collection<IControlHolder> controlHolders, + boolean defaultValue) { this(); initialize(booleanHolder, controlHolders, defaultValue); } /** - * Creates a new <code>ControlEnabler</code> with a default value of - * <code>false</code> (i.e. disabled). + * Creates a new <code>StateController</code> with a default value of + * <code>false</code>. * * @param booleanHolder A value model on the underlying boolean model - * @param controlHolder The <code>IControlHolder</code> whose "enabled" state - * is kept in sync with the boolean holder's value + * @param controlHolder The <code>IControlHolder</code> whose state is kept + * in sync with the boolean holder's value */ - AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, - IControlHolder controlHolder) { + StateController(PropertyValueModel<Boolean> booleanHolder, + IControlHolder controlHolder) { this(booleanHolder, controlHolder, false); } /** - * Creates a new <code>ControlEnabler</code> with a default value of - * <code>false</code> (i.e. disabled). + * Creates a new <code>StateController</code> with a default value of + * <code>false</code>. * * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders The collection of controlHolders whose "enabled" + * @param controlHolders The collection of <code>IControlHolder</code>s whose * state is kept in sync with the boolean holder's value */ - AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, - IControlHolder... controlHolders) { + StateController(PropertyValueModel<Boolean> booleanHolder, + IControlHolder... controlHolders) { this(booleanHolder, CollectionTools.collection(controlHolders), false); } /** - * Creates a new <code>ControlEnabler</code>. + * Creates a new <code>StateController</code> with a default value of + * <code>false</code>. * * @param booleanHolder A value model on the underlying boolean model - * @param controlHolder The <code>IControlHolder</code>s whose "enabled" state - * is kept in sync with the boolean holder's value + * @param controlHolder The <code>IControlHolder</code> whose state is kept + * in sync with the boolean holder's value * @param defaultValue The value to use when the underlying model is * <code>null</code> */ - AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, - IControlHolder controlHolder, - boolean defaultValue) { + StateController(PropertyValueModel<Boolean> booleanHolder, + IControlHolder controlHolder, + boolean defaultValue) { this(booleanHolder, new IControlHolder[] { controlHolder }, false); } /** - * Creates a new <code>ControlEnabler</code>. + * Creates a new <code>StateController</code>. * * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders The collection of controlHolders whose "enabled" state is - * kept in sync with the boolean holder's value + * @param controlHolders The collection of <code>IControlHolder</code>s whose + * state is kept in sync with the boolean holder's value * @param defaultValue The value to use when the underlying model is * <code>null</code> */ - AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, - IControlHolder[] controlHolders, - boolean defaultValue) { + StateController(PropertyValueModel<Boolean> booleanHolder, + IControlHolder[] controlHolders, + boolean defaultValue) { this(); this.initialize(booleanHolder, CollectionTools.collection(controlHolders), defaultValue); } /** - * Creates a new <code>ControlEnabler</code> with a default value of - * <code>false</code> (i.e. disabled). + * Creates a new <code>StateController</code> with a default value of + * <code>false</code>. * * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders An iterator on the collection of controlHolders whose - * "enabled" state is kept in sync with the boolean holder's value + * @param controlHolders An iterator on the collection of + * <code>IControlHolder</code>s whose state is kept in sync with the boolean + * holder's value */ - AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, - Iterator<IControlHolder> controlHolders) { + StateController(PropertyValueModel<Boolean> booleanHolder, + Iterator<IControlHolder> controlHolders) { this(booleanHolder, CollectionTools.collection(controlHolders), false); } /** - * Creates a new <code>ControlEnabler</code>. + * Creates a new <code>StateController</code>. * * @param booleanHolder A value model on the underlying boolean model - * @param controlHolders An iterator on the collection of controlHolders whose - * "enabled" state is kept in sync with the boolean holder's value + * @param controlHolders An iterator on the collection of + * <code>IControlHolder</code>s whose state is kept in sync with the boolean + * holder's value * @param defaultValue The value to use when the underlying model is * <code>null</code> */ - AbstractControlEnabler(PropertyValueModel<Boolean> booleanHolder, - Iterator<IControlHolder> controlHolders, - boolean defaultValue) { + StateController(PropertyValueModel<Boolean> booleanHolder, + Iterator<IControlHolder> controlHolders, + boolean defaultValue) { this(); initialize(booleanHolder, CollectionTools.collection(controlHolders), defaultValue); @@ -206,7 +212,7 @@ class AbstractControlEnabler private PropertyChangeListener buildBooleanChangeListener() { return new PropertyChangeListener() { public void propertyChanged(PropertyChangeEvent event) { - updateEnableState(booleanValue(booleanHolder.value())); + updateState(booleanValue(booleanHolder.value())); } @Override @@ -220,22 +226,22 @@ class AbstractControlEnabler * Returns an <code>Iterator</code> over the collection of * <code>IControlHolder</code>s. * - * @return The iteration of controlHolders + * @return The iteration of <code>IControlHolder</code>s */ - final Iterator<IControlHolder> controlHolders() { - return this.controlHolders.iterator(); + protected final Iterator<IControlHolder> controlHolders() { + return new CloneIterator<IControlHolder>(this.controlHolders); } /** - * Initializes this <code>ControlEnabler</code> by building the - * appropriate listeners. + * Initializes this <code>StateController</code> by building the appropriate + * listeners. */ protected void initialize() { this.booleanChangeListener = this.buildBooleanChangeListener(); } /** - * Initializes this <code>ControlEnabler</code> with the given state. + * Initializes this <code>StateController</code> with the given state. * * @param booleanHolder A value model on the underlying boolean model * @param controlHolders A <code>IControlHolder</code>s whose enablement state @@ -250,35 +256,46 @@ class AbstractControlEnabler Assert.isNotNull(booleanHolder, "The holder of the boolean value cannot be null"); Assert.isNotNull(controlHolders, "The collection of ControlHolders cannot be null"); - this.controlHolders = new ArrayList<IControlHolder>(controlHolders); - this.defaultValue = defaultValue; - this.booleanHolder = booleanHolder; - this.booleanHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.booleanChangeListener); - this.updateEnableState(); + this.controlHolders = new ArrayList<IControlHolder>(controlHolders); + this.defaultValue = defaultValue; + this.booleanHolder = booleanHolder; + + this.booleanHolder.addPropertyChangeListener( + PropertyValueModel.VALUE, + this.booleanChangeListener + ); + + this.updateState(); } /** - * Updates the enablement state of the controlHolders. + * Updates the state of the control holders. */ - protected void updateEnableState() { - this.updateEnableState(booleanValue(booleanHolder.value())); + protected void updateState() { + this.updateState(booleanValue(booleanHolder.value())); } /** - * Updates the enable state of the <code>IControlHolder</code>s. + * Updates the state of the <code>Control</code>s. * - * @param enabledState The new enable state the widgets need to have + * @param state The new state the widgets need to have */ - protected void updateEnableState(boolean enabled) { + protected void updateState(boolean state) { for (IControlHolder controlHolder : this.controlHolders) { - controlHolder.setEnabled(enabled); + controlHolder.updateState(state); } } /** - * This holder of the actual widget. + * The holder of the actual widget. */ static interface IControlHolder { - void setEnabled(boolean enabled); + + /** + * Updates the state of the wrapped control. + * + * @param state The new state the control should have + */ + void updateState(boolean state); } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java index 1b653732a2..07dcd3df3f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AbstractPane.java @@ -56,6 +56,7 @@ import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.eclipse.ui.forms.widgets.Hyperlink; import org.eclipse.ui.forms.widgets.Section; import org.eclipse.ui.help.IWorkbenchHelpSystem; +import org.eclipse.ui.part.PageBook; /** * The abstract definition of a pane which holds onto a <code>PropertyValueModel</code> @@ -501,24 +502,16 @@ public abstract class AbstractPane<T extends Model> return viewer; } + /** + * Creates the main container of this pane. The layout and layout data are + * automatically set. + * + * @param parent The parent container + * @return The newly created <code>Composite</code> that will holds all the + * widgets created by this pane through {@link #initializeLayout(Composite)} + */ protected Composite buildContainer(Composite parent) { - Composite container = this.buildPane(parent); - - GridLayout layout = new GridLayout(1, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginTop = 0; - layout.marginLeft = 0; - layout.marginBottom = 0; - layout.marginRight = 0; - container.setLayout(layout); - - GridData gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL; - gridData.grabExcessHorizontalSpace = true; - container.setLayoutData(gridData); - - return container; + return this.buildSubPane(parent); } /** @@ -1119,6 +1112,29 @@ public abstract class AbstractPane<T extends Model> } /** + * Creates a new <code>PageBook</code> and set the proper layout and layout + * data. + * + * @param container The parent container + * @return The newly created <code>PageBook</code> + */ + protected final PageBook buildPageBook(Composite container) { + + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + layout.marginTop = 0; + layout.marginLeft = 0; + layout.marginBottom = 0; + layout.marginRight = 0; + + PageBook pageBook = new PageBook(container, SWT.NULL); + pageBook.setLayout(layout); + pageBook.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + return pageBook; + } + + /** * Creates a new container without specifying any layout manager. * * @param container The parent of the new container @@ -1143,7 +1159,12 @@ public abstract class AbstractPane<T extends Model> container = this.widgetFactory.createComposite(container); container.setLayout(layout); - container.setLayoutData(new GridData(GridData.FILL_BOTH)); + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + gridData.horizontalAlignment = SWT.FILL; + gridData.verticalAlignment = SWT.TOP; + container.setLayoutData(gridData); return container; } @@ -1265,7 +1286,7 @@ public abstract class AbstractPane<T extends Model> } /** - * Creates a new <code>Section</code> with flat style. A sub-pane is + * Creates a new <code>Section</code> with flat style. A sub-pane is * automatically added as its client and is the returned <code>Composite</code>. * * @param container The container of the new widget @@ -1283,7 +1304,7 @@ public abstract class AbstractPane<T extends Model> container, sectionText, type, - new SimplePropertyValueModel<Boolean>(Boolean.TRUE) + new SimplePropertyValueModel<Boolean>(Boolean.FALSE) ); } @@ -1846,8 +1867,14 @@ public abstract class AbstractPane<T extends Model> * @category Layout */ public void enableWidgets(boolean enabled) { - for (AbstractPane<?> subPane : this.subPanes) { - subPane.enableWidgets(enabled); + + if (!container.isDisposed()) { + + container.setEnabled(enabled); + + for (AbstractPane<?> subPane : this.subPanes) { + subPane.enableWidgets(enabled); + } } } @@ -2242,6 +2269,17 @@ public abstract class AbstractPane<T extends Model> } /** + * Either show or hides this pane. + * + * @param visible The new visibility state + */ + public void setVisible(boolean visible) { + if (!this.container.isDisposed()) { + this.container.setVisible(visible); + } + } + + /** * Returns the nearest <code>Shell</code> displaying the main widget of this * pane. * diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveListPane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveListPane.java index 953248882e..1715a13c98 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveListPane.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemoveListPane.java @@ -199,11 +199,7 @@ public class AddRemoveListPane<T extends Model> extends AddRemovePane<T> ILabelProvider labelProvider, String helpId) { - list = buildList(container, buildSelectedItemHolder()); - - if (helpId != null) { - helpSystem().setHelp(list, helpId); - } + list = buildList(container, buildSelectedItemHolder(), helpId); ListBoxModelAdapter<Object> listModel = ListBoxModelAdapter.adapt( (ListValueModel<Object>) listHolder, diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java index 3c7f03ecd1..5470430daf 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/widgets/AddRemovePane.java @@ -16,14 +16,16 @@ import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; +import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; /** - * The abstract definition of a pane that has add/remove buttons, up/down - * buttons and an option button that is kept in sync with the selected items. + * The abstract definition of a pane that has buttons for adding, removing and + * possibly editing the items. + * + * @see AddRemoveListPane * * @version 1.0 * @since 2.0 @@ -234,6 +236,7 @@ public abstract class AddRemovePane<T extends Model> extends AbstractPane<T> private Runnable buildOptionalAction() { return new Runnable() { public void run() { + AddRemovePane.this.editItem(); } }; } @@ -275,6 +278,13 @@ public abstract class AddRemovePane<T extends Model> extends AbstractPane<T> return new ObjectListSelectionModel(new ListModelAdapter(listModel)); } + /** + * @category Option + */ + protected void editItem() { + this.adapter.optionOnSelection(getSelectionModel()); + } + /* * (non-Javadoc) */ @@ -304,6 +314,19 @@ public abstract class AddRemovePane<T extends Model> extends AbstractPane<T> return selectionModel; } + /** + * Initializes this add/remove pane. + * + * @param adapter This <code>Adapter</code> is used to dictacte the behavior + * of this <code>AddRemovePane</code> and by delegating to it some of the + * behavior + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + * + * @category Initialization + */ @SuppressWarnings("unchecked") protected void initialize(Adapter adapter, ListValueModel<?> listHolder, @@ -317,19 +340,23 @@ public abstract class AddRemovePane<T extends Model> extends AbstractPane<T> this.selectionModel = new ObjectListSelectionModel(new ListModelAdapter(listHolder)); } + /** + * Initializes the pane containing the buttons (Add, optional (if required) + * and Remove). + * + * @param container The parent container + * @param helpId The topic help ID to be registered with the buttons + * + * @category Layout + */ protected void initializeButtonPane(Composite container, String helpId) { - container = buildPane(container); + container = buildSubPane(container); - GridLayout layout = new GridLayout(1, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - layout.marginTop = 0; - layout.marginLeft = 0; - layout.marginBottom = 0; - layout.marginRight = 0; - container.setLayout(layout); - container.setLayoutData(new GridData()); + GridData gridData = new GridData(); + gridData.grabExcessVerticalSpace = true; + gridData.verticalAlignment = SWT.TOP; + container.setLayoutData(gridData); // Add button addButton = buildAddButton(container); @@ -354,13 +381,23 @@ public abstract class AddRemovePane<T extends Model> extends AbstractPane<T> helpSystem().setHelp(optionalButton, helpId); } } - -// upButton = buildUpButton((adapter instanceof UpDownAdapter) ? (UpDownAdapter) adapter : null); -// downButton = buildDownButton((adapter instanceof UpDownAdapter) ? (UpDownAdapter) adapter : null); -// gotoButton = buildGotoButton(); -// component = buildComponent(); } + /** + * Initializes this add/remove pane by creating the widgets. The subclass is + * required to build the main widget. + * + * @param adapter This <code>Adapter</code> is used to dictacte the behavior + * of this <code>AddRemovePane</code> and by delegating to it some of the + * behavior + * @param listHolder The <code>ListValueModel</code> containing the items + * @param selectedItemHolder The holder of the selected item, if more than + * one item or no items are selected, then <code>null</code> will be passed + * @param labelProvider The renderer used to format the list holder's items + * @param helpId The topic help ID to be registered with this pane + * + * @category Layout + */ protected void initializeLayout(Adapter adapter, ListValueModel<?> listHolder, WritablePropertyValueModel<?> selectedItemHolder, @@ -379,8 +416,8 @@ public abstract class AddRemovePane<T extends Model> extends AbstractPane<T> enableWidgets(subject() != null); } - /* - * (non-Javadoc) + /** + * {@inheritDoc} */ @Override protected void initializeLayout(Composite container) { @@ -400,6 +437,8 @@ public abstract class AddRemovePane<T extends Model> extends AbstractPane<T> * @param labelProvider The renderer used to format the list holder's items * @param helpId The topic help ID to be registered with this pane or * <code>null</code> if it was not specified + * + * @category Layout */ protected abstract void initializeMainComposite(Composite container, Adapter adapter, @@ -429,13 +468,11 @@ public abstract class AddRemovePane<T extends Model> extends AbstractPane<T> * @category UpdateButtons */ protected void updateButtons() { - if (container.isDisposed()) { - return; + if (!container.isDisposed()) { + updateAddButton(addButton); + updateRemoveButton(removeButton); + updateOptionalButton(optionalButton); } - - updateAddButton(addButton); - updateRemoveButton(removeButton); - updateOptionalButton(optionalButton); } /** |