svnno****@sourc*****
svnno****@sourc*****
2009年 4月 15日 (水) 19:11:53 JST
Revision: 3293 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3293 Author: daisuke_m Date: 2009-04-15 19:11:53 +0900 (Wed, 15 Apr 2009) Log Message: ----------- ReferenceResolver#canResolve(ElementReference) を追加。 javadoc / refactor Modified Paths: -------------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/ReferenceResolverImpl.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/RootModelImplTest.java artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/internal/enhance/ViewFactoryExtensionEnhancer2.java hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/foreignkey/ForeignKeyEditDialog.java leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/ReflectionUtil.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/ReferenceResolver.java -------------- next part -------------- Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/ReferenceResolverImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/ReferenceResolverImpl.java 2009-04-15 10:00:16 UTC (rev 3292) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/ReferenceResolverImpl.java 2009-04-15 10:11:53 UTC (rev 3293) @@ -173,12 +173,17 @@ elementMapping.put(id, model); } + public boolean canResolve(ElementReference<?> reference) { + assert elementMapping != null; + return elementMapping.containsKey(reference.getReferenceId()); + } + @SuppressWarnings("unchecked") public <T extends JiemamyElement>T resolve(ElementReference<T> reference) { assert elementMapping != null; Validate.notNull(reference); - if (elementMapping.containsKey(reference.getReferenceId()) == false) { + if (canResolve(reference) == false) { throw new ReferenceResolveException(reference); } Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/RootModelImplTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/RootModelImplTest.java 2009-04-15 10:00:16 UTC (rev 3292) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/RootModelImplTest.java 2009-04-15 10:11:53 UTC (rev 3293) @@ -21,23 +21,15 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.CoreMatchers.sameInstance; import static org.junit.Assert.assertThat; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.jiemamy.Jiemamy; import org.jiemamy.JiemamyFactory; -import org.jiemamy.internal.builder.DataTypeBuilderImpl; import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.constraint.ForeignKey; -import org.jiemamy.model.datatype.DataTypeCategory; -import org.jiemamy.model.datatype.DomainModel; -import org.jiemamy.model.entity.TableModel; -import org.jiemamy.utils.model.AttributeUtil; /** * {@link RootModelImpl}のテストクラス。 Modified: artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/internal/enhance/ViewFactoryExtensionEnhancer2.java =================================================================== --- artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/internal/enhance/ViewFactoryExtensionEnhancer2.java 2009-04-15 10:00:16 UTC (rev 3292) +++ artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/internal/enhance/ViewFactoryExtensionEnhancer2.java 2009-04-15 10:11:53 UTC (rev 3293) @@ -58,7 +58,11 @@ Class<?> clazz = (Class<?>) invocation.getArguments()[0]; Jiemamy jiemamy = (Jiemamy) invocation.getArguments()[1]; UUID id = (UUID) invocation.getArguments()[2]; - return VE.newInstance(clazz, jiemamy, id); + Object enhancedResult = VE.newInstance(clazz, jiemamy, id); + if (enhancedResult == null) { + return invocation.proceed(); + } + return enhancedResult; } Modified: hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/foreignkey/ForeignKeyEditDialog.java =================================================================== --- hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/foreignkey/ForeignKeyEditDialog.java 2009-04-15 10:00:16 UTC (rev 3292) +++ hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/foreignkey/ForeignKeyEditDialog.java 2009-04-15 10:11:53 UTC (rev 3293) @@ -74,42 +74,57 @@ */ public class ForeignKeyEditDialog extends JiemamyEditDialog<ForeignKey> { + private static Logger logger = LoggerFactory.getLogger(ForeignKeyEditDialog.class); + + /** ダイアログのデフォルトサイズ */ private static final Point DEFAULT_SIZE = new Point((int) (250 * 1.618), 250); - private static Logger logger = LoggerFactory.getLogger(ForeignKeyEditDialog.class); - + /** 制約を受けるテーブルのカラムのリスト */ private List<ColumnModel> sourceColumns; + /** 参照キー(制約をするテーブルのキー)の候補リスト */ private List<LocalKeyConstraint> referenceKeys; + /** 制約を受けるカラムを選択するコンボボックスのリスト */ private List<Combo> keyColumnCombos; + /** 制約するカラムを表示するラベルのリスト */ private List<Label> referenceColumnLabels; + /** キー名入力テキストエリア */ private Text txtKeyName; + /** 参照キー(制約をするテーブルのキー)を選択するコンボボックス */ private Combo cmbReferenceKey; + /** 遅延可能チェックボックス */ private Button chkDeferrable; + /** 即時評価ラジオボタン */ private Button radImmediate; + /** 遅延評価ラジオボタン */ private Button radDeferred; + /** マッチ型選択コンボボックス */ private Combo cmbMatchType; + /** ON DELETE選択コンボボックス */ private Combo cmbOnDelete; + /** ON UPDATE選択コンボボックス */ private Combo cmbOnUpdate; + /** マッピング設定エリアグループ */ + private Group grpMapping; + + /** ダイアログエリア全体 */ + private Composite dialogArea; + private Jiemamy jiemamy; - private Group grpMapping; - private final JiemamyFacade jiemamyFacade; - private Composite composite; - /** * コンストラクタ。 @@ -148,16 +163,16 @@ create(); logger.debug(LogMarker.LIFECYCLE, "set current value to controls"); - txtKeyName.setText(StringUtils.defaultIfEmpty(foreignKey.getName(), "")); + txtKeyName.setText(StringUtils.defaultIfEmpty(foreignKey.getName(), StringUtils.EMPTY)); MatchType matchType = foreignKey.getMatchType(); - cmbMatchType.setText(matchType == null ? "" : matchType.name()); + cmbMatchType.setText(matchType == null ? StringUtils.EMPTY : matchType.name()); ReferentialAction onDelete = foreignKey.getOnDelete(); - cmbOnDelete.setText(onDelete == null ? "" : onDelete.name()); + cmbOnDelete.setText(onDelete == null ? StringUtils.EMPTY : onDelete.name()); ReferentialAction onUpdate = foreignKey.getOnUpdate(); - cmbOnUpdate.setText(onUpdate == null ? "" : onUpdate.name()); + cmbOnUpdate.setText(onUpdate == null ? StringUtils.EMPTY : onUpdate.name()); Deferrability deferrability = foreignKey.getDeferrability(); @@ -186,8 +201,8 @@ cmbReferenceKey.setText(KeyConstraintUtil.toStringKeyColumns(referenceKeyConstraint)); } - assert composite != null; - createMappingControls(composite); + assert dialogArea != null; + createMappingComponents(dialogArea); return super.open(); } @@ -207,25 +222,25 @@ logger.debug(LogMarker.LIFECYCLE, "createDialogArea"); getShell().setText(Messages.Dialog_Title); - composite = (Composite) super.createDialogArea(parent); - composite.setLayout(new GridLayout(5, false)); + dialogArea = (Composite) super.createDialogArea(parent); + dialogArea.setLayout(new GridLayout(5, false)); Label label; GridData gd; - label = new Label(composite, SWT.NULL); + label = new Label(dialogArea, SWT.NULL); label.setText("制約名(&N):"); // RESOURCE - txtKeyName = new Text(composite, SWT.BORDER); + txtKeyName = new Text(dialogArea, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 4; txtKeyName.setLayoutData(gd); txtKeyName.addFocusListener(new TextSelectionAdapter(txtKeyName)); - label = new Label(composite, SWT.NULL); + label = new Label(dialogArea, SWT.NULL); label.setText("参照キー(&K):"); // RESOURCE - cmbReferenceKey = new Combo(composite, SWT.READ_ONLY); // TODO CComboにしてPKラベルを表示 + cmbReferenceKey = new Combo(dialogArea, SWT.READ_ONLY); // TODO CComboにしてPKラベルを表示 cmbReferenceKey.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); for (LocalKeyConstraint referenceKey : referenceKeys) { StringBuilder sb = new StringBuilder(); @@ -242,58 +257,22 @@ @Override public void widgetSelected(SelectionEvent evt) { logger.debug(LogMarker.LIFECYCLE, "cmbReferenceKey selected"); - createMappingControls(grpMapping); + createMappingComponents(grpMapping); } }); - chkDeferrable = new Button(composite, SWT.CHECK); - chkDeferrable.setText("遅延可能(&A)"); // RESOURCE - chkDeferrable.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent evt) { - if (chkDeferrable.getSelection()) { - radImmediate.setEnabled(true); - radDeferred.setEnabled(true); - } else { - radImmediate.setEnabled(false); - radDeferred.setEnabled(false); - } - } - }); + createDeferrabilityComponents(dialogArea); - radImmediate = new Button(composite, SWT.RADIO); - radImmediate.setText("即時評価(&I)"); // RESOURCE - - radDeferred = new Button(composite, SWT.RADIO); - radDeferred.setText("遅延評価(&R)"); // RESOURCE - - final Composite option = new Composite(composite, SWT.NULL); + final Composite option = new Composite(dialogArea, SWT.NULL); option.setLayout(new GridLayout(4, false)); gd = new GridData(GridData.FILL_BOTH); gd.horizontalSpan = 5; option.setLayoutData(gd); - label = new Label(option, SWT.NULL); - label.setText("ON DELETE(&D)"); // RESOURCE - cmbOnDelete = new Combo(option, SWT.READ_ONLY); - cmbOnDelete.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - cmbOnDelete.add(""); - for (ReferentialAction referentialAction : ReferentialAction.values()) { - cmbOnDelete.add(referentialAction.name()); - } + createReferentialActionComponents(option); label = new Label(option, SWT.NULL); - label.setText("ON UPDATE(&U)"); // RESOURCE - cmbOnUpdate = new Combo(option, SWT.READ_ONLY); - cmbOnUpdate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - cmbOnUpdate.add(""); - for (ReferentialAction referentialAction : ReferentialAction.values()) { - cmbOnUpdate.add(referentialAction.name()); - } - - label = new Label(option, SWT.NULL); label.setText("マッチ型(&M)"); // RESOURCE cmbMatchType = new Combo(option, SWT.READ_ONLY); gd = new GridData(GridData.FILL_HORIZONTAL); @@ -304,7 +283,7 @@ cmbMatchType.add(matchType.name()); } - return composite; + return dialogArea; } @Override @@ -382,7 +361,31 @@ return true; } - private void createMappingControls(final Composite composite) { + private void createDeferrabilityComponents(Composite parent) { + chkDeferrable = new Button(parent, SWT.CHECK); + chkDeferrable.setText("遅延可能(&A)"); // RESOURCE + chkDeferrable.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent evt) { + if (chkDeferrable.getSelection()) { + radImmediate.setEnabled(true); + radDeferred.setEnabled(true); + } else { + radImmediate.setEnabled(false); + radDeferred.setEnabled(false); + } + } + }); + + radImmediate = new Button(parent, SWT.RADIO); + radImmediate.setText("即時評価(&I)"); // RESOURCE + + radDeferred = new Button(parent, SWT.RADIO); + radDeferred.setText("遅延評価(&R)"); // RESOURCE + } + + private void createMappingComponents(final Composite parent) { keyColumnCombos.clear(); referenceColumnLabels.clear(); @@ -390,7 +393,7 @@ GridData gd; if (grpMapping == null || grpMapping.isDisposed()) { - grpMapping = new Group(composite, SWT.NULL); + grpMapping = new Group(parent, SWT.NULL); grpMapping.setText("マッピング"); // RESOURCE grpMapping.setLayout(new GridLayout(3, false)); gd = new GridData(GridData.FILL_BOTH); @@ -406,7 +409,7 @@ gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 3; label.setLayoutData(gd); - label.setText("参照するカラムがありません"); + label.setText("参照するカラムがありません"); // RESOURCE } else { for (Control control : grpMapping.getChildren()) { control.dispose(); @@ -419,7 +422,7 @@ label.setAlignment(SWT.CENTER); label = new Label(grpMapping, SWT.NULL); - label.setText("=>"); + label.setText("=>"); // $NON-NLS-1$ label = new Label(grpMapping, SWT.BORDER); label.setText("参照先"); // RESOURCE @@ -447,7 +450,7 @@ keyColumnCombos.add(cmbKeyColumn); label = new Label(grpMapping, SWT.NULL); - label.setText("=>"); + label.setText("=>"); // $NON-NLS-1$ ColumnModel referenceColumnModel = resolver.resolve(referenceColumnRef); Label lblReferenceColumn = new Label(grpMapping, SWT.BORDER); @@ -457,7 +460,28 @@ } getShell().pack(true); - composite.layout(false); + parent.layout(false); } } + + private void createReferentialActionComponents(Composite parent) { + Label label; + label = new Label(parent, SWT.NULL); + label.setText("ON DELETE(&D)"); // RESOURCE + cmbOnDelete = new Combo(parent, SWT.READ_ONLY); + cmbOnDelete.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + cmbOnDelete.add(StringUtils.EMPTY); + for (ReferentialAction referentialAction : ReferentialAction.values()) { + cmbOnDelete.add(referentialAction.name()); + } + + label = new Label(parent, SWT.NULL); + label.setText("ON UPDATE(&U)"); // RESOURCE + cmbOnUpdate = new Combo(parent, SWT.READ_ONLY); + cmbOnUpdate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + cmbOnUpdate.add(StringUtils.EMPTY); + for (ReferentialAction referentialAction : ReferentialAction.values()) { + cmbOnUpdate.add(referentialAction.name()); + } + } } Modified: leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/ReflectionUtil.java =================================================================== --- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/ReflectionUtil.java 2009-04-15 10:00:16 UTC (rev 3292) +++ leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/ReflectionUtil.java 2009-04-15 10:11:53 UTC (rev 3293) @@ -241,7 +241,7 @@ * * @param clazz クラスの{@link Class}オブジェクト * @param name フィールド名 - * @return {@code name}で指定されたこのクラスの{@link Field}オブジェクト + * @return {@code name}で指定されたこのクラスの{@link Field}オブジェクト. 例外が発生した場合は{@code null} * @see Class#getDeclaredField(String) */ public static Field getDeclaredFieldNoException(final Class<?> clazz, final String name) { Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/ReferenceResolver.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/ReferenceResolver.java 2009-04-15 10:00:16 UTC (rev 3292) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/ReferenceResolver.java 2009-04-15 10:11:53 UTC (rev 3293) @@ -40,6 +40,15 @@ void add(JiemamyElement model); /** + * モデルの参照オブジェクトからモデルの実体を解決できるかどうか調べる。 + * + * @param reference モデルの参照オブジェクト + * @return 解決できる場合は{@code true}、そうでない場合は{@code false} + * @since 0.2 + */ + boolean canResolve(ElementReference<?> reference); + + /** * モデルの参照オブジェクトからモデルの実体を解決する。 * * @param <T> モデルの実態の型 @@ -50,5 +59,4 @@ * @since 0.2 */ <T extends JiemamyElement>T resolve(ElementReference<T> reference); - }