diff options
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui')
18 files changed, 1099 insertions, 488 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaHelpContextIds.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaHelpContextIds.java index 03912a24df..431612e2ba 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaHelpContextIds.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/JpaHelpContextIds.java @@ -80,9 +80,11 @@ public interface JpaHelpContextIds { public static final String MAPPING_SEQUENCE_GENERATOR_NAME = PREFIX + "mapping_sequenceGeneratorName"; public static final String MAPPING_SEQUENCE_GENERATOR_SEQUENCE = PREFIX + "mapping_sequenceGeneratorSequence"; public static final String MAPPING_TABLE_GENERATOR = PREFIX + "mapping_tableGenerator"; + public static final String MAPPING_TABLE_GENERATOR_CATALOG = PREFIX + "mapping_tableGeneratorCatalog"; public static final String MAPPING_TABLE_GENERATOR_NAME = PREFIX + "mapping_tableGeneratorName"; public static final String MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN = PREFIX + "mapping_tableGeneratorPrimaryKeyColumn"; public static final String MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN_VALUE = PREFIX + "mapping_tableGeneratorPrimaryKeyColumnValue"; + public static final String MAPPING_TABLE_GENERATOR_SCHEMA = PREFIX + "mapping_tableGeneratorSchema"; public static final String MAPPING_TABLE_GENERATOR_TABLE= PREFIX + "mapping_tableGeneratorTable"; public static final String MAPPING_TABLE_GENERATOR_VALUE_COLUMN = PREFIX + "mapping_tableGeneratorValueColumn"; public static final String MAPPING_TARGET_ENTITY = PREFIX + "mapping_targetEntity"; 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 d020ea8b8e..3acf4ac8df 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 @@ -40,6 +40,7 @@ public class JptUiMappingsMessages extends NLS { public static String CascadeComposite_refresh; public static String CascadeComposite_remove; public static String CatalogChooser_label; + public static String ColumnComposite_columnDefinition; public static String ColumnComposite_columnSection; public static String ColumnComposite_defaultEmpty; public static String ColumnComposite_defaultWithOneParam; @@ -59,6 +60,8 @@ public class JptUiMappingsMessages extends NLS { public static String ColumnComposite_updatableWithDefault; public static String DefaultBasicMappingUiProvider_Default; public static String DefaultEmbeddedMappingUiProvider_Default; + public static String DefaultWithoutValue; + public static String DefaultWithValue; public static String DiscriminatorColumnComposite_column; public static String DiscriminatorColumnComposite_defaultEmpty; public static String DiscriminatorColumnComposite_discriminatorType; @@ -81,6 +84,8 @@ public class JptUiMappingsMessages extends NLS { public static String GeneratedValueComposite_sequence; public static String GeneratedValueComposite_strategy; public static String GeneratedValueComposite_table; + public static String GeneratorComposite_allocationSize; + public static String GeneratorComposite_initialValue; public static String IdClassComposite_label; public static String IdMappingComposite_pk_generation; public static String IdMappingComposite_primaryKeyGeneration; @@ -234,10 +239,12 @@ public class JptUiMappingsMessages extends NLS { public static String TableComposite_defaultEmpty; public static String TableComposite_defaultWithOneParam; public static String TableComposite_tableSection; + public static String TableGeneratorComposite_catalog; public static String TableGeneratorComposite_default; public static String TableGeneratorComposite_name; public static String TableGeneratorComposite_pkColumn; public static String TableGeneratorComposite_pkColumnValue; + public static String TableGeneratorComposite_schema; public static String TableGeneratorComposite_table; public static String TableGeneratorComposite_tableGenerator; public static String TableGeneratorComposite_valueColumn; diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/ColumnCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/ColumnCombo.java index 02baad36a1..1ce1f4e1e8 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/ColumnCombo.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/ColumnCombo.java @@ -19,7 +19,8 @@ import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; /** - * This database object combo handles showing a table's columns. + * This database object combo handles showing a single or multiple tables' + * columns. * * @version 2.0 * @since 2.0 @@ -66,6 +67,11 @@ public abstract class ColumnCombo<T extends JpaNode> extends AbstractDatabaseObj super(subjectHolder, parent, widgetFactory); } + /** + * Returns the databas tables that is used to retrieve the column names. + * + * @return The table of which its columns are displayed in the combo + */ protected abstract Table table(); /* @@ -75,8 +81,8 @@ public abstract class ColumnCombo<T extends JpaNode> extends AbstractDatabaseObj protected void tableChanged(Table table) { super.tableChanged(table); - if (table == table()) { - this.doPopulate(); + if ((subject() != null) && (table() == table)) { + doPopulate(); } } @@ -86,12 +92,16 @@ public abstract class ColumnCombo<T extends JpaNode> extends AbstractDatabaseObj @Override protected Iterator<String> values() { + if (subject() == null) { + return EmptyIterator.instance(); + } + Table table = table(); if (table != null) { return table.columnNames(); } - return EmptyIterator.instance(); + return EmptyIterator.<String>instance(); } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/TableCombo.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/TableCombo.java index 932ea78caa..005333ac50 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/TableCombo.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/db/TableCombo.java @@ -9,10 +9,14 @@ ******************************************************************************/ package org.eclipse.jpt.ui.internal.mappings.db; +import java.util.Iterator; import org.eclipse.jpt.core.JpaNode; +import org.eclipse.jpt.db.Database; +import org.eclipse.jpt.db.Schema; import org.eclipse.jpt.db.Table; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.internal.widgets.AbstractPane; +import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; @@ -64,7 +68,12 @@ public abstract class TableCombo<T extends JpaNode> extends AbstractDatabaseObje super(subjectHolder, parent, widgetFactory); } - protected abstract Table table(); + /** + * Retrieves the name of the schema from where the table is located. + * + * @return The table's schema name + */ + protected abstract String schemaName(); /* * (non-Javadoc) @@ -77,4 +86,33 @@ public abstract class TableCombo<T extends JpaNode> extends AbstractDatabaseObje this.doPopulate(); } } + + /** + * Returns the selected database table. + * + * @return The selected table + */ + protected abstract Table table(); + + /* + * (non-Javadoc) + */ + @Override + protected Iterator<String> values() { + + if (subject() != null) { + Database database = database(); + String schemaName = schemaName(); + + if ((schemaName != null) && (database != null)) { + Schema schema = database.schemaNamed(schemaName); + + if (schema != null) { + return schema.tableNames(); + } + } + } + + return EmptyIterator.instance(); + } }
\ No newline at end of file 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 5a42df30ca..5bdf39d4fc 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 @@ -13,7 +13,6 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import org.eclipse.jpt.core.context.Column; -import org.eclipse.jpt.core.context.NamedColumn; import org.eclipse.jpt.db.Table; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.internal.JpaHelpContextIds; @@ -21,6 +20,8 @@ import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo; import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; import org.eclipse.jpt.ui.internal.util.ControlEnabler; +import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater; +import org.eclipse.jpt.ui.internal.util.LabeledLabel; import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; import org.eclipse.jpt.ui.internal.widgets.TriStateCheckBox; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; @@ -29,9 +30,12 @@ import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueM import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Spinner; +import org.eclipse.swt.widgets.Text; /** * Here the layout of this pane: @@ -58,15 +62,18 @@ import org.eclipse.swt.widgets.Spinner; * | | * | x Nullable | * | | - * | --------------- | - * | Length: | |I| | - * | --------------- | - * | --------------- | - * | Precision: | |I| | - * | --------------- | - * | --------------- | - * | Scale: | |I| | - * | --------------- | + * | --------------- | + * | Length: | I |I| Default (XXX) | + * | --------------- | + * | --------------- | + * | Precision: | I |I| Default (XXX) | + * | --------------- | + * | --------------- | + * | Scale: | I |I| Default (XXX) | + * | --------------- | + * | ---------------------------------------------------- | + * | Column Definition: | I | | + * | ---------------------------------------------------- | * -----------------------------------------------------------------------------</pre> * * @see Column @@ -77,8 +84,6 @@ import org.eclipse.swt.widgets.Spinner; * @see IdMappingComposite - A container of this pane * @see VersionMappingComposite - A container of this pane * - * @TODO repopulate this panel based on the Entity table changing - * * @version 2.0 * @since 1.0 */ @@ -139,8 +144,23 @@ public class ColumnComposite extends AbstractFormPane<Column> @Override protected void addPropertyNames(Collection<String> propertyNames) { super.addPropertyNames(propertyNames); - propertyNames.add(NamedColumn.DEFAULT_NAME_PROPERTY); - propertyNames.add(NamedColumn.SPECIFIED_NAME_PROPERTY); + propertyNames.add(Column.DEFAULT_NAME_PROPERTY); + propertyNames.add(Column.SPECIFIED_NAME_PROPERTY); + propertyNames.add(Column.DEFAULT_TABLE_PROPERTY); + propertyNames.add(Column.SPECIFIED_TABLE_PROPERTY); + } + + @Override + protected void propertyChanged(String propertyName) { + + if (propertyName == Column.DEFAULT_TABLE_PROPERTY || + propertyName == Column.SPECIFIED_TABLE_PROPERTY) { + + doPopulate(); + } + else { + super.propertyChanged(propertyName); + } } @Override @@ -165,20 +185,136 @@ public class ColumnComposite extends AbstractFormPane<Column> }; } - private WritablePropertyValueModel<Boolean> buildInsertableHolder() { - return new PropertyAspectAdapter<Column, Boolean>( - getSubjectHolder(), - Column.DEFAULT_INSERTABLE_PROPERTY, - Column.SPECIFIED_INSERTABLE_PROPERTY) - { + private WritablePropertyValueModel<String> buildColumnDefinitionHolder() { + return new PropertyAspectAdapter<Column, String>(getSubjectHolder(), Column.COLUMN_DEFINITION_PROPERTY) { @Override - protected Boolean buildValue_() { - return subject.getSpecifiedInsertable(); + protected String buildValue_() { + return subject.getColumnDefinition(); } @Override - protected void setValue_(Boolean value) { - subject.setSpecifiedInsertable(value); + protected void setValue_(String value) { + if (value.length() == 0) { + value = null; + } + subject.setColumnDefinition(value); + } + }; + } + + private WritablePropertyValueModel<Integer> buildDefaultLengthHolder() { + return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.DEFAULT_LENGTH_PROPERTY) { + @Override + protected Integer buildValue_() { + return subject.getDefaultLength(); + } + + @Override + protected void subjectChanged() { + Object oldValue = this.value(); + super.subjectChanged(); + Object newValue = this.value(); + + // Make sure the default value is appended to the text + if (oldValue == newValue && newValue == null) { + this.fireAspectChange(Integer.MIN_VALUE, newValue); + } + } + }; + } + + private Control buildDefaultLengthLabel(Composite container) { + + Label label = buildLabel( + container, + JptUiMappingsMessages.DefaultWithoutValue + ); + + new LabeledControlUpdater( + new LabeledLabel(label), + buildDefaultLengthLabelHolder() + ); + + return label; + } + + private PropertyValueModel<String> buildDefaultLengthLabelHolder() { + + return new TransformationPropertyValueModel<Integer, String>(buildDefaultLengthHolder()) { + + @Override + protected String transform(Integer value) { + + Integer defaultValue = (subject() != null) ? subject().getDefaultLength() : + Column.DEFAULT_LENGTH; + + return NLS.bind( + JptUiMappingsMessages.DefaultWithValue, + defaultValue + ); + } + }; + } + + private WritablePropertyValueModel<Integer> buildDefaultPrecisionHolder() { + return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.DEFAULT_PRECISION_PROPERTY) { + @Override + protected Integer buildValue_() { + return subject.getDefaultPrecision(); + } + + @Override + protected void subjectChanged() { + Object oldValue = this.value(); + super.subjectChanged(); + Object newValue = this.value(); + + // Make sure the default value is appended to the text + if (oldValue == newValue && newValue == null) { + this.fireAspectChange(Integer.MIN_VALUE, newValue); + } + } + }; + } + + private Control buildDefaultPrecisionLabel(Composite container) { + + Label label = buildLabel( + container, + JptUiMappingsMessages.DefaultWithoutValue + ); + + new LabeledControlUpdater( + new LabeledLabel(label), + buildDefaultPrecisionLabelHolder() + ); + + return label; + } + + private PropertyValueModel<String> buildDefaultPrecisionLabelHolder() { + + return new TransformationPropertyValueModel<Integer, String>(buildDefaultPrecisionHolder()) { + + @Override + protected String transform(Integer value) { + + Integer defaultValue = (subject() != null) ? subject().getDefaultPrecision() : + Column.DEFAULT_PRECISION; + + return NLS.bind( + JptUiMappingsMessages.DefaultWithValue, + defaultValue + ); + } + }; + } + + private WritablePropertyValueModel<Integer> buildDefaultScaleHolder() { + return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.DEFAULT_SCALE_PROPERTY) { + @Override + protected Integer buildValue_() { + return subject.getDefaultScale(); } @Override @@ -195,6 +331,53 @@ public class ColumnComposite extends AbstractFormPane<Column> }; } + private Control buildDefaultScaleLabel(Composite container) { + + Label label = buildLabel( + container, + JptUiMappingsMessages.DefaultWithoutValue + ); + + new LabeledControlUpdater( + new LabeledLabel(label), + buildDefaultScaleLabelHolder() + ); + + return label; + } + + private PropertyValueModel<String> buildDefaultScaleLabelHolder() { + + return new TransformationPropertyValueModel<Integer, String>(buildDefaultScaleHolder()) { + + @Override + protected String transform(Integer value) { + + Integer defaultValue = (subject() != null) ? subject().getDefaultScale() : + Column.DEFAULT_SCALE; + + return NLS.bind( + JptUiMappingsMessages.DefaultWithValue, + defaultValue + ); + } + }; + } + + private WritablePropertyValueModel<Boolean> buildInsertableHolder() { + return new PropertyAspectAdapter<Column, Boolean>(getSubjectHolder(), Column.SPECIFIED_INSERTABLE_PROPERTY) { + @Override + protected Boolean buildValue_() { + return subject.getSpecifiedInsertable(); + } + + @Override + protected void setValue_(Boolean value) { + subject.setSpecifiedInsertable(value); + } + }; + } + private PropertyValueModel<String> buildInsertableStringHolder() { return new TransformationPropertyValueModel<Boolean, String>(buildInsertableHolder()) { @@ -224,12 +407,7 @@ public class ColumnComposite extends AbstractFormPane<Column> } private WritablePropertyValueModel<Integer> buildLengthHolder() { - - return new PropertyAspectAdapter<Column, Integer>( - getSubjectHolder(), - Column.DEFAULT_UPDATABLE_PROPERTY, - Column.SPECIFIED_UPDATABLE_PROPERTY) - { + return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.SPECIFIED_LENGTH_PROPERTY) { @Override protected Integer buildValue_() { return subject.getSpecifiedLength(); @@ -237,6 +415,9 @@ public class ColumnComposite extends AbstractFormPane<Column> @Override protected void setValue_(Integer value) { + if (value == -1) { + value = null; + } subject.setSpecifiedLength(value); } }; @@ -273,9 +454,7 @@ public class ColumnComposite extends AbstractFormPane<Column> } private PropertyValueModel<String> buildNullableStringHolder() { - return new TransformationPropertyValueModel<Boolean, String>(buildNullableHolder()) { - @Override protected String transform(Boolean value) { @@ -301,12 +480,7 @@ public class ColumnComposite extends AbstractFormPane<Column> } private WritablePropertyValueModel<Integer> buildPrecisionHolder() { - - return new PropertyAspectAdapter<Column, Integer>( - getSubjectHolder(), - Column.DEFAULT_PRECISION_PROPERTY, - Column.SPECIFIED_PRECISION_PROPERTY) - { + return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.SPECIFIED_PRECISION_PROPERTY) { @Override protected Integer buildValue_() { return subject.getSpecifiedPrecision(); @@ -314,18 +488,16 @@ public class ColumnComposite extends AbstractFormPane<Column> @Override protected void setValue_(Integer value) { + if (value == -1) { + value = null; + } subject.setSpecifiedPrecision(value); } }; } private WritablePropertyValueModel<Integer> buildScaleHolder() { - - return new PropertyAspectAdapter<Column, Integer>( - getSubjectHolder(), - Column.DEFAULT_SCALE_PROPERTY, - Column.SPECIFIED_SCALE_PROPERTY) - { + return new PropertyAspectAdapter<Column, Integer>(getSubjectHolder(), Column.SPECIFIED_SCALE_PROPERTY) { @Override protected Integer buildValue_() { return subject.getSpecifiedScale(); @@ -333,6 +505,9 @@ public class ColumnComposite extends AbstractFormPane<Column> @Override protected void setValue_(Integer value) { + if (value == -1) { + value = null; + } subject.setSpecifiedScale(value); } }; @@ -355,6 +530,11 @@ public class ColumnComposite extends AbstractFormPane<Column> } @Override + protected String schemaName() { + return null; + } + + @Override protected void setValue(String value) { subject().setSpecifiedTable(value); } @@ -559,37 +739,58 @@ public class ColumnComposite extends AbstractFormPane<Column> widgets.add(nullableCheckBox.getCheckBox()); // Length widgets - Spinner lengthSpinner = buildLabeledSpinnerWithDefault( + Spinner lengthSpinner = buildLabeledSpinner( container, JptUiMappingsMessages.ColumnComposite_length, buildLengthHolder(), - Column.DEFAULT_LENGTH, + -1, + -1, + Integer.MAX_VALUE, + buildDefaultLengthLabel(container), JpaHelpContextIds.MAPPING_COLUMN_LENGTH ); widgets.add(lengthSpinner); + updateGridData(container, lengthSpinner); // Precision widgets - Spinner precisionSpinner = buildLabeledSpinnerWithDefault( + Spinner precisionSpinner = buildLabeledSpinner( container, JptUiMappingsMessages.ColumnComposite_precision, buildPrecisionHolder(), - Column.DEFAULT_PRECISION, + -1, + -1, + Integer.MAX_VALUE, + buildDefaultPrecisionLabel(container), JpaHelpContextIds.MAPPING_COLUMN_PRECISION ); widgets.add(precisionSpinner); + updateGridData(container, precisionSpinner); // Scale widgets - Spinner scaleSpinner = buildLabeledSpinnerWithDefault( + Spinner scaleSpinner = buildLabeledSpinner( container, JptUiMappingsMessages.ColumnComposite_scale, buildScaleHolder(), - Column.DEFAULT_SCALE, + -1, + -1, + Integer.MAX_VALUE, + buildDefaultScaleLabel(container), JpaHelpContextIds.MAPPING_COLUMN_SCALE ); widgets.add(scaleSpinner); + updateGridData(container, scaleSpinner); + + // Column Definition widgets + Text columnDefinitionText = buildLabeledText( + container, + JptUiMappingsMessages.ColumnComposite_columnDefinition, + buildColumnDefinitionHolder() + ); + + widgets.add(columnDefinitionText); installControlEnabler(widgets); } @@ -635,4 +836,35 @@ public class ColumnComposite extends AbstractFormPane<Column> private void installControlEnabler(Collection<Control> widgets) { new ControlEnabler(enablementHolder, widgets); } + + /** + * Changes the layout of the given container by changing which widget will + * grab the excess of horizontal space. By default, the center control grabs + * the excess space, we change it to be the right control. + * + * @param container The container containing the controls needing their + * <code>GridData</code> to be modified from the default values + * @param spinner The spinner that got created + */ + private void updateGridData(Composite container, Spinner spinner) { + + // It is possible the spinner's parent is not the container of the + // label, spinner and right control (a pane is sometimes required for + // painting the spinner's border) + Composite paneContainer = spinner.getParent(); + + while (container != paneContainer.getParent()) { + paneContainer = paneContainer.getParent(); + } + + Control[] controls = paneContainer.getChildren(); + + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = false; + gridData.horizontalAlignment = GridData.BEGINNING; + controls[1].setLayoutData(gridData); + + controls[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + removeAlignRight(controls[2]); + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GenerationComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GenerationComposite.java index 7fb6e508b7..b1bc1ab258 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GenerationComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GenerationComposite.java @@ -216,10 +216,10 @@ public class GenerationComposite extends AbstractFormPane<IdMapping> generatedValueComposite.getControl().setLayoutData(gridData); // Table Generator pane - initializeTableGeneratorPane(buildSubPane(container, 5)); + initializeTableGeneratorPane(buildSubPane(container, 10)); // Sequence Generator pane - initializeSequenceGeneratorPane(buildSubPane(container, 5)); + initializeSequenceGeneratorPane(buildSubPane(container, 10)); } private void initializeSequenceGeneratorPane(Composite container) { diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorComposite.java index 833976c717..b98c282dd7 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorComposite.java @@ -12,11 +12,20 @@ package org.eclipse.jpt.ui.internal.mappings.details; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.context.Generator; import org.eclipse.jpt.core.context.GeneratorHolder; +import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.util.LabeledControlUpdater; +import org.eclipse.jpt.ui.internal.util.LabeledLabel; import org.eclipse.jpt.ui.internal.widgets.AbstractPane; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; +import org.eclipse.jpt.utility.internal.model.value.TransformationPropertyValueModel; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Spinner; /** * This is the generic pane for a generator. @@ -29,6 +38,7 @@ import org.eclipse.swt.widgets.Composite; * @version 2.0 * @since 1.0 */ +@SuppressWarnings("nls") public abstract class GeneratorComposite<T extends Generator> extends AbstractPane<GeneratorHolder> { /** @@ -43,6 +53,139 @@ public abstract class GeneratorComposite<T extends Generator> extends AbstractPa super(parentPane, parent); } + private WritablePropertyValueModel<Integer> buildAllocationSizeHolder() { + return new PropertyAspectAdapter<Generator, Integer>(buildGeneratorHolder(), Generator.SPECIFIED_ALLOCATION_SIZE_PROPERTY) { + @Override + protected Integer buildValue_() { + Integer value = subject.getSpecifiedAllocationSize(); + if (value == null) { + return -1; + } + return value; + } + + @Override + public void setValue(Integer value) { + if ((subject == null) && (value == -1)) { + return; + } + setValue_(value); + } + + @Override + protected void setValue_(Integer value) { + if (value == -1) { + value = null; + } + retrieveGenerator(subject()).setSpecifiedAllocationSize(value); + } + }; + } + + private WritablePropertyValueModel<Integer> buildDefaultAllocationSizeHolder() { + return new PropertyAspectAdapter<Generator, Integer>(buildGeneratorHolder(), Generator.DEFAULT_ALLOCATION_SIZE_PROPERTY) { + @Override + protected Integer buildValue_() { + return subject.getDefaultAllocationSize(); + } + + @Override + protected void subjectChanged() { + Object oldValue = this.value(); + super.subjectChanged(); + Object newValue = this.value(); + + // Make sure the default value is appended to the text + if (oldValue == newValue && newValue == null) { + this.fireAspectChange(Integer.MIN_VALUE, newValue); + } + } + }; + } + + private Control buildDefaultAllocationSizeLabel(Composite container) { + + Label label = buildLabel( + container, + JptUiMappingsMessages.DefaultWithoutValue + ); + + new LabeledControlUpdater( + new LabeledLabel(label), + buildDefaultAllocationSizeLabelHolder() + ); + + return label; + } + + private PropertyValueModel<String> buildDefaultAllocationSizeLabelHolder() { + + return new TransformationPropertyValueModel<Integer, String>(buildDefaultAllocationSizeHolder()) { + + @Override + protected String transform(Integer value) { + + if (value != null) { + return NLS.bind(JptUiMappingsMessages.DefaultWithValue, value); + } + + return ""; + } + }; + } + + private WritablePropertyValueModel<Integer> buildDefaultInitialValueHolder() { + return new PropertyAspectAdapter<Generator, Integer>(buildGeneratorHolder(), Generator.DEFAULT_INITIAL_VALUE_PROPERTY) { + @Override + protected Integer buildValue_() { + return subject.getDefaultInitialValue(); + } + + @Override + protected void subjectChanged() { + Object oldValue = this.value(); + super.subjectChanged(); + Object newValue = this.value(); + + // Make sure the default value is appended to the text + if (oldValue == newValue && newValue == null) { + this.fireAspectChange(Integer.MIN_VALUE, newValue); + } + } + }; + } + + private Control buildDefaultInitialValueLabel(Composite container) { + + Label label = buildLabel( + container, + JptUiMappingsMessages.DefaultWithoutValue + ); + + new LabeledControlUpdater( + new LabeledLabel(label), + buildDefaultInitialValueLabelHolder() + ); + + return label; + } + + private PropertyValueModel<String> buildDefaultInitialValueLabelHolder() { + + return new TransformationPropertyValueModel<Integer, String>(buildDefaultInitialValueHolder()) { + + @Override + protected String transform(Integer value) { + + if (value != null) { + return NLS.bind(JptUiMappingsMessages.DefaultWithValue, value); + } + + return ""; + } + }; + } + /** * Creates the new <code>IGenerator</code>. * @@ -69,9 +212,51 @@ public abstract class GeneratorComposite<T extends Generator> extends AbstractPa @Override public void setValue(String value) { - if ((subject != null) || (value.length() != 0)) { - retrieveGenerator(subject()).setName(value); + if ((subject == null) && (value.length() == 0)) { + return; + } + setValue_(value); + } + + @Override + protected void setValue_(String value) { + if (value.length() == 0) { + value = null; + } + retrieveGenerator(subject()).setName(value); + } + }; + } + + private WritablePropertyValueModel<Integer> buildInitialValueHolder() { + return new PropertyAspectAdapter<Generator, Integer>(buildGeneratorHolder(), Generator.SPECIFIED_INITIAL_VALUE_PROPERTY) { + @Override + protected Integer buildValue_() { + Integer value = subject.getSpecifiedInitialValue(); + + if (value == null) { + return -1; + } + + return value; + } + + @Override + public void setValue(Integer value) { + if ((subject == null) && (value == -1)) { + return; + } + setValue_(value); + } + + @Override + protected void setValue_(Integer value) { + + if (value == -1) { + value = null; } + + retrieveGenerator(subject()).setSpecifiedInitialValue(value); } }; } @@ -96,6 +281,51 @@ public abstract class GeneratorComposite<T extends Generator> extends AbstractPa protected abstract T generator(GeneratorHolder subject); /** + * Creates the labeled spinner responsible to edit the allocation size. The + * default value will be shown after the spinner. A value of -1 means the + * default value and the model has <code>null</code>. + * + * @param container The parent container + */ + protected void initializeAllocationSizeWidgets(Composite container) { + + Spinner spinner = buildLabeledSpinner( + container, + JptUiMappingsMessages.GeneratorComposite_allocationSize, + buildAllocationSizeHolder(), + -1, + -1, + Integer.MAX_VALUE, + buildDefaultAllocationSizeLabel(container) + ); + + updateGridData(container, spinner); + } + + /** + * Creates the labeled spinner responsible to edit the initial value. The + * default value will be shown after the spinner. A value of -1 means the + * default value and the model has <code>null</code>. + * + * @param container The parent container + */ + protected void initializeInitialValueWidgets(Composite container) { + + Spinner spinner = buildLabeledSpinner( + container, + JptUiMappingsMessages.GeneratorComposite_initialValue, + buildInitialValueHolder(), + -1, + -1, + Integer.MAX_VALUE, + buildDefaultInitialValueLabel(container) + ); + + + updateGridData(container, spinner); + } + + /** * Retrieves the JPA project. * * @return The JPA project or <code>null</code> if the subject is <code>null</code> @@ -128,4 +358,35 @@ public abstract class GeneratorComposite<T extends Generator> extends AbstractPa return generator; } + + /** + * Changes the layout of the given container by changing which widget will + * grab the excess of horizontal space. By default, the center control grabs + * the excess space, we change it to be the right control. + * + * @param container The container containing the controls needing their + * <code>GridData</code> to be modified from the default values + * @param spinner The spinner that got created + */ + private void updateGridData(Composite container, Spinner spinner) { + + // It is possible the spinner's parent is not the container of the + // label, spinner and right control (a pane is sometimes required for + // painting the spinner's border) + Composite paneContainer = spinner.getParent(); + + while (container != paneContainer.getParent()) { + paneContainer = paneContainer.getParent(); + } + + Control[] controls = paneContainer.getChildren(); + + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = false; + gridData.horizontalAlignment = GridData.BEGINNING; + controls[1].setLayoutData(gridData); + + controls[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + removeAlignRight(controls[2]); + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorsComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorsComposite.java index b15b897230..6f7bdb5c81 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorsComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/GeneratorsComposite.java @@ -20,7 +20,6 @@ import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; /** -/** * Here the layout of this pane: * <pre> * ----------------------------------------------------------------------------- @@ -144,14 +143,14 @@ public class GeneratorsComposite extends AbstractPane<GeneratorHolder> // Sequence Generator sub-section container = buildCollapsableSubSection( - container, + buildSubPane(container, 10), JptUiMappingsMessages.IdMappingComposite_sequenceGenerator, sequenceGeneratorExpansionStateHolder ); // Sequence Generator check box Button sequenceGeneratorCheckBox = buildCheckBox( - container, + buildSubPane(container, 5), JptUiMappingsMessages.IdMappingComposite_sequenceGenerator, buildSequenceGeneratorBooleanHolder(), JpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR @@ -174,7 +173,7 @@ public class GeneratorsComposite extends AbstractPane<GeneratorHolder> ); Button tableGeneratorCheckBox = buildCheckBox( - container, + buildSubPane(container, 5), JptUiMappingsMessages.IdMappingComposite_tableGenerator, buildTableGeneratorBooleanHolder(), JpaHelpContextIds.MAPPING_TABLE_GENERATOR 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 0e8d96eadd..3edb4ddf2d 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 @@ -29,9 +29,12 @@ import org.eclipse.swt.widgets.Composite; * Here the layout of this pane: * <pre> * ----------------------------------------------------------------------------- - * | ------------------------------------------------------------------ | - * | Table: | TableCombo |v| | - * | ------------------------------------------------------------------ | + * | ------------------------------------------------------ | + * | Table: | TableCombo |v| | + * | ------------------------------------------------------ | + * | ------------------------------------------------------ | + * | Column Definition: | I | | + * | ------------------------------------------------------ | * | | * | x Insertable | * | | @@ -75,6 +78,23 @@ public class JoinColumnDialogPane extends BaseJoinColumnDialogPane<JoinColumnSta propertyNames.add(JoinColumnStateObject.TABLE_PROPERTY); } + private WritablePropertyValueModel<String> buildColumnDefinitionHolder() { + return new PropertyAspectAdapter<JoinColumnStateObject, String>(getSubjectHolder(), JoinColumnStateObject.COLUMN_DEFINITION_PROPERTY) { + @Override + protected String buildValue_() { + return subject.getColumnDefinition(); + } + + @Override + protected void setValue_(String value) { + if (value.length() == 0) { + value = null; + } + subject.setColumnDefinition(value); + } + }; + } + /* * (non-Javadoc) */ @@ -339,6 +359,13 @@ public class JoinColumnDialogPane extends BaseJoinColumnDialogPane<JoinColumnSta private void initializeDetailsPane(Composite container) { + // Column Definition widgets + buildLabeledText( + container, + JptUiMappingsMessages.ColumnComposite_columnDefinition, + buildColumnDefinitionHolder() + ); + // Insertable check box buildTriStateCheckBoxWithDefault( buildSubPane(container, 4), 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 d396a35428..7bd1f3843c 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,12 +21,14 @@ import org.eclipse.jpt.db.Table; @SuppressWarnings("nls") public abstract class JoinColumnStateObject extends BaseJoinColumnStateObject { + private String columnDefinition; private Boolean insertable; private Boolean nullable; private String table; private Boolean unique; private Boolean updatable; + public static final String COLUMN_DEFINITION_PROPERTY = "columnDefinition"; public static final String INSERTABLE_PROPERTY = "insertable"; public static final String NULLABLE_PROPERTY = "nullable"; public static final String TABLE_PROPERTY = "table"; @@ -42,9 +44,12 @@ public abstract class JoinColumnStateObject extends BaseJoinColumnStateObject public JoinColumnStateObject(Object owner, JoinColumn joinColumn) { super(owner, joinColumn); } - public abstract String defaultTableName(); + public String getColumnDefinition() { + return columnDefinition; + } + public Boolean getDefaultInsertable() { JoinColumn joinColumn = getJoinColumn(); @@ -147,14 +152,21 @@ public abstract class JoinColumnStateObject extends BaseJoinColumnStateObject if (abstractJoinColumn != null) { JoinColumn joinColumn = (JoinColumn) abstractJoinColumn; - table = joinColumn.getSpecifiedTable(); - insertable = joinColumn.getSpecifiedInsertable(); - nullable = joinColumn.getSpecifiedNullable(); - unique = joinColumn.getSpecifiedUnique(); - updatable = joinColumn.getSpecifiedUpdatable(); + table = joinColumn.getSpecifiedTable(); + insertable = joinColumn.getSpecifiedInsertable(); + nullable = joinColumn.getSpecifiedNullable(); + unique = joinColumn.getSpecifiedUnique(); + updatable = joinColumn.getSpecifiedUpdatable(); + columnDefinition = joinColumn.getColumnDefinition(); } } + public void setColumnDefinition(String columnDefinition) { + String oldColumnDefinition = this.columnDefinition; + this.columnDefinition = columnDefinition; + firePropertyChanged(COLUMN_DEFINITION_PROPERTY, oldColumnDefinition, columnDefinition); + } + public void setInsertable(Boolean insertable) { Boolean oldInsertable = this.insertable; this.insertable = insertable; @@ -234,5 +246,10 @@ public abstract class JoinColumnStateObject extends BaseJoinColumnStateObject if (joinColumn.getSpecifiedNullable() != nullable){ joinColumn.setSpecifiedNullable(nullable); } + + // Column Definition + if (valuesAreDifferent(columnDefinition, joinColumn.getColumnDefinition())) { + joinColumn.setColumnDefinition(columnDefinition); + } } }
\ No newline at end of file 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 171b79d95f..07b1a54881 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 @@ -3,19 +3,17 @@ * 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.mappings.details; import java.util.Collection; -import java.util.Iterator; import java.util.ListIterator; import org.eclipse.jpt.core.context.JoinColumn; import org.eclipse.jpt.core.context.JoinTable; import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.db.Schema; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.internal.JpaHelpContextIds; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; @@ -23,7 +21,6 @@ import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; import org.eclipse.jpt.ui.internal.mappings.details.JoinColumnsComposite.IJoinColumnsEditor; import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; import org.eclipse.jpt.ui.internal.widgets.PostExecution; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; @@ -233,6 +230,11 @@ public class JoinTableComposite extends AbstractFormPane<JoinTable> } @Override + protected String schemaName() { + return subject().getSchema(); + } + + @Override protected void setValue(String value) { subject().setSpecifiedName(value); } @@ -242,25 +244,10 @@ public class JoinTableComposite extends AbstractFormPane<JoinTable> return subject().getDbTable(); } - private Schema tableSchema() { - return database().schemaNamed(subject().getSchema()); - } - @Override protected String value() { return subject().getSpecifiedName(); } - - @Override - protected Iterator<String> values() { - Schema schema = tableSchema(); - - if (schema != null) { - return schema.tableNames(); - } - - return EmptyIterator.instance(); - } }; } @@ -282,6 +269,10 @@ public class JoinTableComposite extends AbstractFormPane<JoinTable> inverseJoinColumnsComposite.enableWidgets(inverseEnabled); } + private void editInverseJoinColumn(InverseJoinColumnInJoinTableStateObject stateObject) { + stateObject.updateJoinColumn(stateObject.getJoinColumn()); + } + private void editInverseJoinColumn(JoinColumn joinColumn) { InverseJoinColumnInJoinTableDialog dialog = @@ -302,10 +293,6 @@ public class JoinTableComposite extends AbstractFormPane<JoinTable> stateObject.updateJoinColumn(stateObject.getJoinColumn()); } - private void editInverseJoinColumn(InverseJoinColumnInJoinTableStateObject stateObject) { - stateObject.updateJoinColumn(stateObject.getJoinColumn()); - } - /* * (non-Javadoc) */ diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SequenceGeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SequenceGeneratorComposite.java index 0e78286b0c..1b587a45e1 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SequenceGeneratorComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/SequenceGeneratorComposite.java @@ -32,6 +32,12 @@ import org.eclipse.swt.widgets.Composite; * | ----------------------------------------------------- | * | Sequence Generator: | SequenceCombo | | * | ----------------------------------------------------- | + * | ------------- | + * | Allocation Size: | I |I| | + * | ------------- | + * | ------------- | + * | Initial Value: | |I| | + * | ------------- | * -----------------------------------------------------------------------------</pre> * * @see IdMapping @@ -159,6 +165,12 @@ public class SequenceGeneratorComposite extends GeneratorComposite<SequenceGener buildSequenceNameCombo(container), JpaHelpContextIds.MAPPING_SEQUENCE_GENERATOR_SEQUENCE ); + + // Allocation Size widgets + initializeAllocationSizeWidgets(container); + + // Initial Value widgets + initializeInitialValueWidgets(container); } /* diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java index d4f52090a6..59584d0d17 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/mappings/details/TableComposite.java @@ -3,16 +3,14 @@ * 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.mappings.details; import java.util.Collection; -import java.util.Iterator; import org.eclipse.jpt.core.context.Table; -import org.eclipse.jpt.db.Schema; import org.eclipse.jpt.ui.WidgetFactory; import org.eclipse.jpt.ui.internal.JpaHelpContextIds; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; @@ -20,7 +18,6 @@ import org.eclipse.jpt.ui.internal.mappings.db.CatalogCombo; import org.eclipse.jpt.ui.internal.mappings.db.SchemaCombo; import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; import org.eclipse.jpt.ui.internal.widgets.AbstractFormPane; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; @@ -157,6 +154,11 @@ public class TableComposite extends AbstractFormPane<Table> } @Override + protected String schemaName() { + return subject().getSchema(); + } + + @Override protected void setValue(String value) { subject().setSpecifiedName(value); } @@ -166,25 +168,10 @@ public class TableComposite extends AbstractFormPane<Table> return subject().getDbTable(); } - private Schema tableSchema() { - return database().schemaNamed(subject().getSchema()); - } - @Override protected String value() { return subject().getSpecifiedName(); } - - @Override - protected Iterator<String> values() { - Schema schema = tableSchema(); - - if (schema != null) { - return schema.tableNames(); - } - - return EmptyIterator.instance(); - } }; } 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 684e6b441e..35e362c163 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 @@ -10,19 +10,17 @@ package org.eclipse.jpt.ui.internal.mappings.details; import java.util.Collection; -import java.util.Iterator; import org.eclipse.jpt.core.JpaProject; import org.eclipse.jpt.core.context.GeneratorHolder; import org.eclipse.jpt.core.context.TableGenerator; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.Schema; import org.eclipse.jpt.db.Table; import org.eclipse.jpt.ui.internal.JpaHelpContextIds; import org.eclipse.jpt.ui.internal.mappings.JptUiMappingsMessages; +import org.eclipse.jpt.ui.internal.mappings.db.CatalogCombo; import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo; +import org.eclipse.jpt.ui.internal.mappings.db.SchemaCombo; import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.swt.widgets.Composite; @@ -35,22 +33,38 @@ import org.eclipse.swt.widgets.Composite; * | Name: | I | | * | ----------------------------------------------- | * | ----------------------------------------------- | - * | Table: | I |v| | + * | Table: | TableCombo | | * | ----------------------------------------------- | * | ----------------------------------------------- | - * | Primary Key Column: | I |v| | + * | Catalog: | CatalogCombo | | * | ----------------------------------------------- | * | ----------------------------------------------- | - * | Value Column: | I |v| | + * | Schema: | SchemaCombo | | * | ----------------------------------------------- | * | ----------------------------------------------- | - * | Primary Key Column Value: | I |v| | + * | Primary Key Column: | ColumnCombo | | * | ----------------------------------------------- | + * | ----------------------------------------------- | + * | Value Column: | ColumnCombo | | + * | ----------------------------------------------- | + * | ----------------------------------------------- | + * | Primary Key Column Value: | ColumnCombo | | + * | ----------------------------------------------- | + * | ------------- | + * | Allocation Size: | I |I| Default (XXX) | + * | ------------- | + * | ------------- | + * | Initial Value: | I |I| Default (XXX) | + * | ------------- | * -----------------------------------------------------------------------------</pre> * * @see IdMapping * @see TableGenerator * @see GenerationComposite - The parent container + * @see CatalogCombo + * @see ColumnCombo + * @see SchemaCombo + * @see TableCombo * * @version 2.0 * @since 1.0 @@ -69,6 +83,51 @@ public class TableGeneratorComposite extends GeneratorComposite<TableGenerator> super(parentPane, parent); } + private CatalogCombo<TableGenerator> buildCatalogCombo(Composite container) { + + return new CatalogCombo<TableGenerator>(this, buildTableGeneratorHolder(), container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(TableGenerator.DEFAULT_CATALOG_PROPERTY); + propertyNames.add(TableGenerator.SPECIFIED_CATALOG_PROPERTY); + } + + @Override + protected void buildSubject() { + TableGeneratorComposite.this.buildGenerator( + TableGeneratorComposite.this.subject() + ); + } + + @Override + protected String defaultValue() { + return subject().getDefaultCatalog(); + } + + @Override + protected boolean isBuildSubjectAllowed() { + return true; + } + + @Override + protected JpaProject jpaProject() { + return TableGeneratorComposite.this.jpaProject(); + } + + @Override + protected void setValue(String value) { + subject().setSpecifiedCatalog(value); + } + + @Override + protected String value() { + return subject().getSpecifiedCatalog(); + } + }; + } + /* * (non-Javadoc) */ @@ -124,14 +183,6 @@ public class TableGeneratorComposite extends GeneratorComposite<TableGenerator> protected String value() { return subject().getSpecifiedPkColumnName(); } - - @Override - protected Iterator<String> values() { - if ((subject() == null) || (table() == null)) { - return EmptyIterator.instance(); - } - return table().columnNames(); - } }; } @@ -182,13 +233,50 @@ public class TableGeneratorComposite extends GeneratorComposite<TableGenerator> protected String value() { return subject().getSpecifiedPkColumnValue(); } + }; + } + + private SchemaCombo<TableGenerator> buildSchemaCombo(Composite container) { + + return new SchemaCombo<TableGenerator>(this, buildTableGeneratorHolder(), container) { + + @Override + protected void addPropertyNames(Collection<String> propertyNames) { + super.addPropertyNames(propertyNames); + propertyNames.add(TableGenerator.DEFAULT_SCHEMA_PROPERTY); + propertyNames.add(TableGenerator.SPECIFIED_SCHEMA_PROPERTY); + } + + @Override + protected void buildSubject() { + TableGeneratorComposite.this.buildGenerator( + TableGeneratorComposite.this.subject() + ); + } + + @Override + protected String defaultValue() { + return subject().getDefaultSchema(); + } + + @Override + protected boolean isBuildSubjectAllowed() { + return true; + } + + @Override + protected JpaProject jpaProject() { + return TableGeneratorComposite.this.jpaProject(); + } + + @Override + protected void setValue(String value) { + subject().setSpecifiedSchema(value); + } @Override - protected Iterator<String> values() { - if ((subject() == null) || (table() == null)) { - return EmptyIterator.instance(); - } - return table().columnNames(); + protected String value() { + return subject().getSpecifiedSchema(); } }; } @@ -236,6 +324,11 @@ public class TableGeneratorComposite extends GeneratorComposite<TableGenerator> } @Override + protected String schemaName() { + return subject().getSchema(); + } + + @Override protected void setValue(String value) { subject().setSpecifiedTable(value); } @@ -249,27 +342,6 @@ public class TableGeneratorComposite extends GeneratorComposite<TableGenerator> protected String value() { return subject().getSpecifiedTable(); } - - @Override - protected Iterator<String> values() { - - if (subject() == null) { - return EmptyIterator.instance(); - } - - String schemaName = subject().getSchema(); - Database database = database(); - - if ((schemaName != null) && (database != null)) { - Schema schema = database.schemaNamed(schemaName); - - if (schema != null) { - return schema.tableNames(); - } - } - - return EmptyIterator.instance(); - } }; } @@ -320,14 +392,6 @@ public class TableGeneratorComposite extends GeneratorComposite<TableGenerator> protected String value() { return subject().getSpecifiedValueColumnName(); } - - @Override - protected Iterator<String> values() { - if ((subject() == null) || (table() == null)) { - return EmptyIterator.instance(); - } - return table().columnNames(); - } }; } @@ -361,6 +425,22 @@ public class TableGeneratorComposite extends GeneratorComposite<TableGenerator> JpaHelpContextIds.MAPPING_TABLE_GENERATOR_TABLE ); + // Schema widgets + buildLabeledComposite( + container, + JptUiMappingsMessages.TableGeneratorComposite_schema, + buildSchemaCombo(container), + JpaHelpContextIds.MAPPING_TABLE_GENERATOR_SCHEMA + ); + + // Catalog widgets + buildLabeledComposite( + container, + JptUiMappingsMessages.TableGeneratorComposite_catalog, + buildCatalogCombo(container), + JpaHelpContextIds.MAPPING_TABLE_GENERATOR_CATALOG + ); + // Primary Key Column widgets buildLabeledComposite( container, @@ -384,6 +464,12 @@ public class TableGeneratorComposite extends GeneratorComposite<TableGenerator> buildPkColumnValueCombo(container), JpaHelpContextIds.MAPPING_TABLE_GENERATOR_PRIMARY_KEY_COLUMN_VALUE ); + + // Allocation Size widgets + initializeAllocationSizeWidgets(container); + + // Initial Value widgets + initializeInitialValueWidgets(container); } /* diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmTableGeneratorComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmTableGeneratorComposite.java index 9459977fc2..8b63870b6d 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmTableGeneratorComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/orm/details/OrmTableGeneratorComposite.java @@ -10,17 +10,13 @@ package org.eclipse.jpt.ui.internal.orm.details; import java.util.Collection; -import java.util.Iterator; import org.eclipse.jpt.core.context.orm.OrmTableGenerator; -import org.eclipse.jpt.db.Database; -import org.eclipse.jpt.db.Schema; import org.eclipse.jpt.db.Table; import org.eclipse.jpt.ui.internal.JpaHelpContextIds; import org.eclipse.jpt.ui.internal.mappings.db.ColumnCombo; import org.eclipse.jpt.ui.internal.mappings.db.TableCombo; import org.eclipse.jpt.ui.internal.orm.JptUiOrmMessages; import org.eclipse.jpt.ui.internal.widgets.AbstractPane; -import org.eclipse.jpt.utility.internal.iterators.EmptyIterator; import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; @@ -113,14 +109,6 @@ public class OrmTableGeneratorComposite extends AbstractPane<OrmTableGenerator> protected String value() { return subject().getSpecifiedPkColumnName(); } - - @Override - protected Iterator<String> values() { - if ((subject() == null) || (table() == null)) { - return EmptyIterator.instance(); - } - return table().columnNames(); - } }; } @@ -154,14 +142,6 @@ public class OrmTableGeneratorComposite extends AbstractPane<OrmTableGenerator> protected String value() { return subject().getSpecifiedPkColumnValue(); } - - @Override - protected Iterator<String> values() { - if ((subject() == null) || (table() == null)) { - return EmptyIterator.instance(); - } - return table().columnNames(); - } }; } @@ -182,6 +162,11 @@ public class OrmTableGeneratorComposite extends AbstractPane<OrmTableGenerator> } @Override + protected String schemaName() { + return subject().getSchema(); + } + + @Override protected void setValue(String value) { subject().setSpecifiedTable(value); } @@ -195,27 +180,6 @@ public class OrmTableGeneratorComposite extends AbstractPane<OrmTableGenerator> protected String value() { return subject().getSpecifiedTable(); } - - @Override - protected Iterator<String> values() { - - if (subject() == null) { - return EmptyIterator.instance(); - } - - String schemaName = subject().getSchema(); - Database database = database(); - - if ((schemaName != null) && (database != null)) { - Schema schema = database.schemaNamed(schemaName); - - if (schema != null) { - return schema.tableNames(); - } - } - - return EmptyIterator.instance(); - } }; } @@ -249,14 +213,6 @@ public class OrmTableGeneratorComposite extends AbstractPane<OrmTableGenerator> protected String value() { return subject().getSpecifiedValueColumnName(); } - - @Override - protected Iterator<String> values() { - if ((subject() == null) || (table() == null)) { - return EmptyIterator.instance(); - } - return table().columnNames(); - } }; } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java index 6a1bf82d98..5bbcb64b6a 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/util/ControlAligner.java @@ -11,6 +11,7 @@ package org.eclipse.jpt.ui.internal.util; import java.util.ArrayList; import java.util.Collection; +import java.util.Iterator; import org.eclipse.core.runtime.Assert; import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.swt.SWT; @@ -89,7 +90,7 @@ public final class ControlAligner /** * The length of the widest control. If the length was not calculated, then - * this value is -1. + * this value is 0. */ private int maximumWidth; @@ -148,7 +149,7 @@ public final class ControlAligner wrapper.addListener(listener); wrappers.add(wrapper); - revalidate(); + revalidate(false); } /** @@ -170,7 +171,7 @@ public final class ControlAligner wrappers.add(wrapper); if (!controlAligner.wrappers.isEmpty()) { - revalidate(); + revalidate(false); } } @@ -194,7 +195,7 @@ public final class ControlAligner } autoValidate = oldAutoValidate; - revalidate(); + revalidate(false); } /** @@ -217,7 +218,7 @@ public final class ControlAligner } autoValidate = oldAutoValidate; - revalidate(); + revalidate(false); } /** @@ -255,6 +256,32 @@ public final class ControlAligner } /** + * Calculates the width taken by the widgets and returns the maximum width. + * + * @param recalculateSize <code>true</code> to recalculate the preferred size + * of all the wrappers contained within them rather than using the cached + * size; <code>false</code> to use the cached size + */ + private int calculateWidth(boolean recalculateSize) { + + int width = 0; + + for (Wrapper wrapper : wrappers) { + Point size = wrapper.cachedSize(); + + // The size has not been calculated yet + if (recalculateSize || (size.x == 0)) { + size = wrapper.calculateSize(); + } + + // Only keep the greatest width + width = Math.max(size.x, width); + } + + return width; + } + + /** * Reports a bound property change. * * @param oldValue the old value of the property (as an int) @@ -274,11 +301,27 @@ public final class ControlAligner } /** + * Disposes this <code>ControlAligner</code>, this can improve the speed of + * disposing a pane. When a pane is disposed, this aligner doesn't need to + * revalidate its size upon dispose of its widgets. + */ + public void dispose() { + + for (Iterator<Wrapper> iter = wrappers.iterator(); iter.hasNext(); ) { + Wrapper wrapper = iter.next(); + wrapper.removeListener(listener); + iter.remove(); + } + + this.wrappers.clear(); + } + + /** * Returns the length of the widest control. If the length was not - * calculated, then this value is -1. + * calculated, then this value is 0. * - * @return The width of the widest control or -1 if the length has not - * been calculated yet + * @return The width of the widest control or 0 if the length has not been + * calculated yet */ public int getMaximumWidth() { return maximumWidth; @@ -290,7 +333,7 @@ public final class ControlAligner private void initialize() { this.autoValidate = true; - this.maximumWidth = -1; + this.maximumWidth = 0; this.listener = new ListenerHandler(); this.wrappers = new ArrayList<Wrapper>(); } @@ -304,7 +347,7 @@ public final class ControlAligner Wrapper wrapper = retrieveWrapper(source); - if (!wrapper.isLocked()) { + if (!wrapper.locked()) { Point size = wrapper.cachedSize(); size.x = size.y = 0; wrapper.setSize(DEFAULT_SIZE); @@ -314,26 +357,17 @@ public final class ControlAligner /** * Updates the maximum length based on the widest control. This methods * does not update the width of the controls. + * + * @param recalculateSize <code>true</code> to recalculate the preferred size + * of all the wrappers contained within them rather than using the cached + * size; <code>false</code> to use the cached size */ - private void recalculateWidth() { - - int width = -1; - - for (Wrapper wrapper : wrappers) { - Point size = wrapper.cachedSize(); + private void recalculateWidth(boolean recalculateSize) { - // The size has not been calculated yet - if (size.y == 0) { - size = wrapper.size(); - } - - // Only keep the greatest width - width = Math.max(size.x, width); - } - - locked = true; + int width = calculateWidth(recalculateSize); try { + locked = true; setMaximumWidth(width); } finally { @@ -357,7 +391,7 @@ public final class ControlAligner wrapper.removeListener(listener); wrappers.remove(wrapper); - revalidate(); + revalidate(true); } /** @@ -376,7 +410,7 @@ public final class ControlAligner wrapper.removeListener(listener); wrappers.remove(wrapper); - revalidate(); + revalidate(true); } /** @@ -414,12 +448,16 @@ public final class ControlAligner * If the count of control is greater than one and {@link #isAutoValidate()} * returns <code>true</code>, then the size of all the registered * <code>Control</code>s will be udpated. + * + * @param recalculateSize <code>true</code> to recalculate the preferred size + * of all the wrappers contained within them rather than using the cached + * size; <code>false</code> to use the cached size */ - private void revalidate() { + private void revalidate(boolean recalculateSize) { if (autoValidate) { - recalculateWidth(); - revalidateImp(); + recalculateWidth(recalculateSize); + updateWrapperSize(recalculateSize); } } @@ -471,51 +509,23 @@ public final class ControlAligner } // Now revalidate all the Controls and ControlAligners - revalidate(); - } - - /** - * Updates the size of every control based on the maximum width. - */ - private void revalidateImp() { - - for (Wrapper wrapper : wrappers) { - Point size = wrapper.cachedSize(); - size = new Point(maximumWidth, size.y); - wrapper.setSize(size); - } + revalidate(true); } /** * Sets the length of the widest control. If the length was not calulcated, - * then this value is -1. + * then this value is 0. * * @param maximumWidth The width of the widest control */ private void setMaximumWidth(int maximumWidth) { - int oldMaximumWidth = getMaximumWidth(); + int oldMaximumWidth = this.maximumWidth; this.maximumWidth = maximumWidth; controlResized(oldMaximumWidth, maximumWidth); } /** - * Returns the size by determining which control has the greatest - * width. - * - * @return The size of this <code>ControlAligner</code>, which is - * {@link #getMaximumWidth()} for the width - */ - private Point size() { - -// if (maximumWidth == -1) { -// recalculateWidth(); -// } - - return new Point(maximumWidth, 0); - } - - /** * Returns a string representation of this <code>ControlAligner</code>. * * @return Information about this object @@ -532,10 +542,30 @@ public final class ControlAligner } /** + * Updates the size of every <code>Wrapper</code> based on the maximum width. + * + * @param forceRevalidate <code>true</code> to revalidate the wrapper's size + * even though its current size might be the same as the maximum width; + * <code>false</code> to only revalidate the wrappers with a different width + */ + private void updateWrapperSize(boolean forceRevalidate) { + + for (Wrapper wrapper : wrappers) { + Point cachedSize = wrapper.cachedSize(); + + // No need to change the size of the wrapper since it's always using + // the maximum width + if (forceRevalidate || (cachedSize.x != maximumWidth)) { + Point size = new Point(maximumWidth, cachedSize.y); + wrapper.setSize(size); + } + } + } + + /** * This <code>Wrapper</code> encapsulates a {@link ControlAligner}. */ - private class ControlAlignerWrapper implements Wrapper - { + private class ControlAlignerWrapper implements Wrapper { /** * The cached size, which is {@link ControlAligner#maximumWidth}. */ @@ -556,7 +586,6 @@ public final class ControlAligner */ private ControlAlignerWrapper(ControlAligner controlAligner) { super(); - this.controlAligner = controlAligner; this.cachedSize = new Point(controlAligner.maximumWidth, 0); } @@ -572,13 +601,38 @@ public final class ControlAligner * (non-Javadoc) */ public Point cachedSize() { + cachedSize.x = controlAligner.maximumWidth; return cachedSize; } /* * (non-Javadoc) */ - public boolean isLocked() { + public Point calculateSize() { + + Point size = new Point(controlAligner.calculateWidth(false), 0); + + if (size.x != SWT.DEFAULT) { + cachedSize.x = size.x; + } + else { + cachedSize.x = 0; + } + + if (size.y != SWT.DEFAULT) { + cachedSize.y = size.y; + } + else { + cachedSize.y = 0; + } + + return size; + } + + /* + * (non-Javadoc) + */ + public boolean locked() { return controlAligner.locked; } @@ -595,25 +649,17 @@ public final class ControlAligner public void setSize(Point size) { if (size == DEFAULT_SIZE) { - controlAligner.maximumWidth = -1; + controlAligner.maximumWidth = 0; } else if (controlAligner.maximumWidth != size.x) { controlAligner.maximumWidth = size.x; - controlAligner.revalidateImp(); + controlAligner.updateWrapperSize(true); } } /* * (non-Javadoc) */ - public Point size() { - cachedSize.x = controlAligner.maximumWidth; - return controlAligner.size(); - } - - /* - * (non-Javadoc) - */ public Object source() { return controlAligner; } @@ -636,12 +682,11 @@ public final class ControlAligner /** * This <code>Wrapper</code> encapsulates a {@link Control}. */ - private class ControlWrapper implements Wrapper - { + private class ControlWrapper implements Wrapper { /** * The cached size, which is control's size. */ - private final Point cachedSize; + private Point cachedSize; /** * The control to be encapsulated by this <code>Wrapper</code>. @@ -681,15 +726,38 @@ public final class ControlAligner /* * (non-Javadoc) */ - public boolean isLocked() { - return false; + public Point calculateSize() { + + cachedSize = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); + + // Update right away the control's GridData + GridData gridData = (GridData) control.getLayoutData(); + + if (gridData == null) { + gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + control.setLayoutData(gridData); + } + + gridData.widthHint = cachedSize.x; + gridData.heightHint = cachedSize.y; + + // Make sure the size is not -1 + if (cachedSize.x == SWT.DEFAULT) { + cachedSize.x = 0; + } + + if (cachedSize.y == SWT.DEFAULT) { + cachedSize.y = 0; + } + + return cachedSize; } /* * (non-Javadoc) */ - public boolean isVisible() { - return control.isVisible(); + public boolean locked() { + return false; } /* @@ -712,20 +780,27 @@ public final class ControlAligner } // Update the GridData with the new size - GridData data = (GridData) control.getLayoutData(); + GridData gridData = (GridData) control.getLayoutData(); - if (data == null) { - data = new GridData(); - data.horizontalAlignment = SWT.FILL; - control.setLayoutData(data); + if (gridData == null) { + gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); + control.setLayoutData(gridData); } - data.widthHint = size.x; - data.heightHint = size.y; + gridData.widthHint = size.x; + gridData.heightHint = size.y; // Force the control to be resized, and tell its parent to layout // its widgets if (size.x > 0) { +// locked = true; +// try { +//// control.getParent().layout(new Control[] { control }); +// control.getParent().layout(true); +// } +// finally { +// locked = false; +// } Rectangle bounds = control.getBounds(); // Only update the control's width if it's @@ -734,7 +809,7 @@ public final class ControlAligner locked = true; try { - control.setBounds(bounds.x, bounds.y, size.x, bounds.height); +// control.setBounds(bounds.x, bounds.y, size.x, size.y); control.getParent().layout(true); } finally @@ -748,17 +823,7 @@ public final class ControlAligner /* * (non-Javadoc) */ - public Point size() { - Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); - cachedSize.x = size.x; - cachedSize.y = size.y; - return size; - } - - /* - * (non-Javadoc) - */ - public Object source() { + public Control source() { return control; } @@ -781,8 +846,7 @@ public final class ControlAligner * The listener added to each of the control that is notified in order to * revalidate the preferred size. */ - private class ListenerHandler implements Listener - { + private class ListenerHandler implements Listener { public void handleEvent(Event event) { ControlAligner.this.revalidate(event); } @@ -792,8 +856,7 @@ public final class ControlAligner * This <code>Wrapper</code> helps to encapsulate heterogeneous objects and * apply the same behavior on them. */ - private interface Wrapper - { + private interface Wrapper { /** * Adds the given <code>Listener</code> to wrapped object in order to * receive notification when its property changed. @@ -811,13 +874,20 @@ public final class ControlAligner Point cachedSize(); /** + * Calculates the preferred size the wrapped object would take by itself. + * + * @return The calculated size + */ + Point calculateSize(); + + /** * Prevents infinite recursion when recalculating the preferred width. * This happens in an hierarchy of <code>ControlAligner</code>s. * * @return <code>true</code> to prevent this <code>Wrapper</code> from * being invalidated; otherwise <code>false</code> */ - boolean isLocked(); + boolean locked(); /** * Removes the given <code>Listener</code>. @@ -834,13 +904,6 @@ public final class ControlAligner void setSize(Point size); /** - * Returns the preferred size of the wrapped source. - * - * @return The preferred size - */ - Point size(); - - /** * Returns the encapsulated object. * * @return The object that is been wrapped 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 346798f628..8eb7925a84 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 @@ -31,7 +31,6 @@ import org.eclipse.jpt.ui.internal.util.SWTUtil; import org.eclipse.jpt.utility.internal.ClassTools; import org.eclipse.jpt.utility.internal.StringConverter; import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationWritablePropertyValueModel; import org.eclipse.jpt.utility.model.Model; import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; @@ -40,8 +39,6 @@ import org.eclipse.jpt.utility.model.value.PropertyValueModel; import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; @@ -393,6 +390,11 @@ public abstract class AbstractPane<T extends Model> helpSystem().setHelp(button, helpId); } + GridData gridData = new GridData(); + gridData.grabExcessHorizontalSpace = false; + gridData.horizontalAlignment = GridData.FILL; + button.setLayoutData(gridData); + return button; } @@ -1333,25 +1335,25 @@ public abstract class AbstractPane<T extends Model> // Right control if (rightControl == null) { Composite spacer = this.buildPane(container); - spacer.setLayout(buildSpacerLayout()); - this.rightControlAligner.add(spacer); + spacer.setLayout(this.buildSpacerLayout()); + rightControl = spacer; } else { - gridData = new GridData(); - gridData.horizontalAlignment = GridData.FILL_HORIZONTAL; - gridData.grabExcessHorizontalSpace = false; - - rightControl.setLayoutData(gridData); rightControl.setParent(container); - this.rightControlAligner.add(rightControl); - // Register the help id for the right control if (helpId != null) { helpSystem().setHelp(rightControl, helpId); } } + gridData = new GridData(); + gridData.horizontalAlignment = GridData.FILL_HORIZONTAL; + gridData.grabExcessHorizontalSpace = false; + + rightControl.setLayoutData(gridData); + this.rightControlAligner.add(rightControl); + return container; } @@ -1532,11 +1534,9 @@ public abstract class AbstractPane<T extends Model> Control rightCentrol, String helpId) { - Label label = this.buildLabel(container, labelText); - return this.buildLabeledComposite( container, - label, + this.buildLabel(container, labelText), centerControl, rightCentrol, helpId @@ -2223,6 +2223,9 @@ public abstract class AbstractPane<T extends Model> labelText, numberHolder, defaultValue, + 0, + Integer.MAX_VALUE, + null, null ); } @@ -2234,9 +2237,7 @@ public abstract class AbstractPane<T extends Model> * @param labelText The label's text * @param numberHolder The holder of the integer value * @param defaultValue The value shown when the holder has <code>null</code> - * @param minimumValue The minimum value that the spinner will allow - * @param maximumValue The maximum value that the spinner will allow - * @param helpId The topic help ID to be registered for the spinner + * @param rightControl The widget to be placed to the right of spinner * @return The newly created <code>Spinner</code> * * @category Layout @@ -2245,29 +2246,18 @@ public abstract class AbstractPane<T extends Model> String labelText, WritablePropertyValueModel<Integer> numberHolder, int defaultValue, - int minimumValue, - int maximumValue, - String helpId) { + Control rightControl) { - Spinner spinner = this.buildSpinner( - parent, + return this.buildLabeledSpinner( + container, + labelText, numberHolder, defaultValue, - minimumValue, - maximumValue - ); - - buildLabeledComposite( - parent, - labelText, - (spinner.getParent() != parent) ? spinner.getParent() : spinner, - helpId + 0, + Integer.MAX_VALUE, + rightControl, + null ); - - GridData gridData = (GridData) spinner.getLayoutData(); - gridData.horizontalAlignment = GridData.BEGINNING; - - return spinner; } /** @@ -2277,7 +2267,9 @@ public abstract class AbstractPane<T extends Model> * @param labelText The label's text * @param numberHolder The holder of the integer value * @param defaultValue The value shown when the holder has <code>null</code> - * @param helpId The topic help ID to be registered for the spinner + * @param minimumValue The minimum value that the spinner will allow + * @param maximumValue The maximum value that the spinner will allow + * @param rightControl The widget to be placed to the right of spinner * @return The newly created <code>Spinner</code> * * @category Layout @@ -2286,15 +2278,18 @@ public abstract class AbstractPane<T extends Model> String labelText, WritablePropertyValueModel<Integer> numberHolder, int defaultValue, - String helpId) { + int minimumValue, + int maximumValue, + Control rightControl) { return this.buildLabeledSpinner( parent, labelText, numberHolder, defaultValue, - 0, - Integer.MAX_VALUE, + minimumValue, + maximumValue, + rightControl, null ); } @@ -2308,26 +2303,41 @@ public abstract class AbstractPane<T extends Model> * @param defaultValue The value shown when the holder has <code>null</code> * @param minimumValue The minimum value that the spinner will allow * @param maximumValue The maximum value that the spinner will allow + * @param rightControl The widget to be placed to the right of spinner + * @param helpId The topic help ID to be registered for the spinner * @return The newly created <code>Spinner</code> * * @category Layout */ - protected final Spinner buildLabeledSpinnerWithDefault(Composite parent, - String labelText, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - int minimumValue, - int maximumValue) { + protected final Spinner buildLabeledSpinner(Composite parent, + String labelText, + WritablePropertyValueModel<Integer> numberHolder, + int defaultValue, + int minimumValue, + int maximumValue, + Control rightControl, + String helpId) { - return this.buildLabeledSpinnerWithDefault( + Spinner spinner = this.buildSpinner( parent, - labelText, numberHolder, defaultValue, minimumValue, - maximumValue, - null + maximumValue ); + + buildLabeledComposite( + parent, + labelText, + (spinner.getParent() != parent) ? spinner.getParent() : spinner, + rightControl, + helpId + ); + + GridData gridData = (GridData) spinner.getLayoutData(); + gridData.horizontalAlignment = GridData.BEGINNING; + + return spinner; } /** @@ -2344,41 +2354,24 @@ public abstract class AbstractPane<T extends Model> * * @category Layout */ - protected final Spinner buildLabeledSpinnerWithDefault(Composite parent, - String labelText, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - int minimumValue, - int maximumValue, - String helpId) { - - WritablePropertyValueModel<Integer> numberHolderWrapper = new TransformationWritablePropertyValueModel<Integer, Integer>(numberHolder) { - @Override - protected Integer reverseTransform_(Integer value) { - return (value == -1) ? null : value; - } - - @Override - protected Integer transform(Integer value) { - return (value == null) ? -1 : value; - } - }; + protected final Spinner buildLabeledSpinner(Composite parent, + String labelText, + WritablePropertyValueModel<Integer> numberHolder, + int defaultValue, + int minimumValue, + int maximumValue, + String helpId) { - Spinner spinner = this.buildLabeledSpinner( + return this.buildLabeledSpinner( parent, labelText, - numberHolderWrapper, + numberHolder, defaultValue, - -1, - maximumValue, + 0, + Integer.MAX_VALUE, + null, helpId ); - - spinner.setData("defaultValue", defaultValue); - spinner.setData("usingDefault", numberHolder.value() == null); - spinner.addFocusListener(buildSpinnerFocusListener()); - - return spinner; } /** @@ -2393,20 +2386,21 @@ public abstract class AbstractPane<T extends Model> * * @category Layout */ - protected final Spinner buildLabeledSpinnerWithDefault(Composite parent, - String labelText, - WritablePropertyValueModel<Integer> numberHolder, - int defaultValue, - String helpId) { + protected final Spinner buildLabeledSpinner(Composite parent, + String labelText, + WritablePropertyValueModel<Integer> numberHolder, + int defaultValue, + String helpId) { - return this.buildLabeledSpinnerWithDefault( + return this.buildLabeledSpinner( parent, labelText, numberHolder, defaultValue, 0, Integer.MAX_VALUE, - helpId + null, + null ); } @@ -3029,16 +3023,14 @@ public abstract class AbstractPane<T extends Model> } /** - * Creates the layout responsible to compute the size of the - * <code>Composite</code> created for the right widget, it helps to align all - * the center widgets. + * Creates the layout responsible to compute the size of the spacer created + * for the right control when none was given. The spacer helps to align all + * the right controls. * * @category Layout */ private Layout buildSpacerLayout() { - return new Layout() { - @Override protected Point computeSize(Composite composite, int widthHint, @@ -3141,67 +3133,6 @@ public abstract class AbstractPane<T extends Model> return spinner; } - /** - * Creates the listener responsible to show the default value in the spinner - * when the focus is lost and the value is -1. If the spinner gains the focus - * and the default - * - * @return - * - * @category Layout - */ - private FocusListener buildSpinnerFocusListener() { - - return new FocusListener() { - - public void focusGained(FocusEvent e) { - - if (!isPopulating()) { - Spinner spinner = (Spinner) e.widget; - Boolean usingDefault = (Boolean) spinner.getData("usingDefault"); - - if (usingDefault) { - setPopulating(true); - - try { - spinner.setSelection(-1); - spinner.setData("usingDefault", Boolean.TRUE); - } - finally { - setPopulating(false); - } - } - else { - spinner.setData("usingDefault", Boolean.FALSE); - } - } - } - - public void focusLost(FocusEvent e) { - - if (!isPopulating()) { - Spinner spinner = (Spinner) e.widget; - - if (spinner.getSelection() == -1) { - setPopulating(true); - - try { - Integer defaultValue = (Integer) spinner.getData("defaultValue"); - spinner.setSelection(defaultValue); - spinner.setData("usingDefault", Boolean.TRUE); - } - finally { - setPopulating(false); - } - } - else { - spinner.setData("usingDefault", Boolean.FALSE); - } - } - } - }; - } - private PropertyChangeListener buildSubjectChangeListener() { return new SWTPropertyChangeListenerWrapper(this.buildSubjectChangeListener_()); } @@ -3755,6 +3686,9 @@ public abstract class AbstractPane<T extends Model> */ protected void doDispose() { this.log(Tracing.UI_LAYOUT, " ->doDispose()"); + + this.leftControlAligner.dispose(); + this.rightControlAligner.dispose(); } /** 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 c24cd6ab70..bf21fd3780 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 @@ -305,14 +305,7 @@ public class AddRemoveListPane<T extends Model> extends AddRemovePane<T> private Composite buildTableContainer(Composite container) { container = buildPane(container, buildTableContainerLayout()); - - GridData gridData = new GridData(); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.horizontalAlignment = SWT.FILL; - gridData.verticalAlignment = SWT.FILL; - container.setLayoutData(gridData); - + container.setLayoutData(new GridData(GridData.FILL_BOTH)); return container; } |