svnno****@sourc*****
svnno****@sourc*****
2009年 2月 21日 (土) 22:43:00 JST
Revision: 2701 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2701 Author: daisuke_m Date: 2009-02-21 22:43:00 +0900 (Sat, 21 Feb 2009) Log Message: ----------- 外部キー編集用ダイアログの表示。 Modified Paths: -------------- artemis/trunk/jiemamy-core/pom.xml artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/KeyConstraintUtil.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/test/TestModelBuilder2Test.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/ForeignKeyEditPart.java vesta/trunk/org.jiemamy.eclipse.dialect.mysql/.classpath vesta/trunk/org.jiemamy.eclipse.dialect.mysql/META-INF/MANIFEST.MF vesta/trunk/org.jiemamy.eclipse.dialect.mysql/build.properties Added Paths: ----------- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/foreignkey/ForeignKeyEditDialog.java -------------- next part -------------- Modified: artemis/trunk/jiemamy-core/pom.xml =================================================================== --- artemis/trunk/jiemamy-core/pom.xml 2009-02-21 06:24:26 UTC (rev 2700) +++ artemis/trunk/jiemamy-core/pom.xml 2009-02-21 13:43:00 UTC (rev 2701) @@ -87,7 +87,12 @@ <version>1.1.102</version> <scope>test</scope> </dependency> - <dependency> + <dependency> + <groupId>com.thoughtworks.xstream</groupId> + <artifactId>xstream</artifactId> + <version>1.3.1</version> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.5.5</version> Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/KeyConstraintUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/KeyConstraintUtil.java 2009-02-21 06:24:26 UTC (rev 2700) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/model/KeyConstraintUtil.java 2009-02-21 13:43:00 UTC (rev 2701) @@ -20,6 +20,9 @@ import java.util.List; +import org.apache.commons.lang.StringUtils; + +import org.jiemamy.ReferenceResolver; import org.jiemamy.model.attribute.ColumnModel; import org.jiemamy.model.attribute.ColumnRef; import org.jiemamy.model.attribute.constraint.KeyConstraintModel; @@ -80,6 +83,16 @@ keyColumns.removeAll(toRemove); } + public static String toStringKeyColumns(KeyConstraintModel keyModel) { + ReferenceResolver resolver = keyModel.getJiemamy().getReferenceResolver(); + List<ColumnRef> keyColumns = keyModel.getKeyColumns(); + List<String> columnNames = CollectionsUtil.newArrayList(keyColumns.size()); + for (ColumnRef columnRef : keyColumns) { + columnNames.add(resolver.resolve(columnRef).getName()); + } + return StringUtils.join(columnNames, ", "); + } + private KeyConstraintUtil() { } } Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/test/TestModelBuilder2Test.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/test/TestModelBuilder2Test.java 2009-02-21 06:24:26 UTC (rev 2700) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/test/TestModelBuilder2Test.java 2009-02-21 13:43:00 UTC (rev 2701) @@ -22,8 +22,15 @@ import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; +import java.io.File; import java.util.Collection; +import java.util.UUID; +import com.thoughtworks.xstream.XStream; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.CharEncoding; +import org.apache.commons.lang.ClassUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -152,4 +159,16 @@ assertThat(problems.size(), is(0)); } + @Test + public void xstream() throws Exception { + Jiemamy jiemamy = testModelBuilder2.getJiemamy(); + RootModel rootModel = jiemamy.getFactory().getRootModel(); + XStream xstream = new XStream(); + xstream.addImmutableType(UUID.class); + xstream.useAttributeFor("id", UUID.class); + String xml = xstream.toXML(rootModel); + FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) + ".xml"), + xml, CharEncoding.UTF_8); + } + } Added: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/foreignkey/ForeignKeyEditDialog.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/foreignkey/ForeignKeyEditDialog.java (rev 0) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/foreignkey/ForeignKeyEditDialog.java 2009-02-21 13:43:00 UTC (rev 2701) @@ -0,0 +1,332 @@ +package org.jiemamy.eclipse.editor.dialog.foreignkey; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.Jiemamy; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.constraint.Deferrability; +import org.jiemamy.model.attribute.constraint.ForeignKeyModel; +import org.jiemamy.model.attribute.constraint.LocalKeyModel; +import org.jiemamy.model.attribute.constraint.Deferrability.InitiallyCheckTime; +import org.jiemamy.model.attribute.constraint.ForeignKeyModel.MatchType; +import org.jiemamy.model.attribute.constraint.ForeignKeyModel.ReferentialAction; +import org.jiemamy.model.entity.TableModel; +import org.jiemamy.utils.model.AttributeUtil; +import org.jiemamy.utils.model.ForeignKeyUtil; +import org.jiemamy.utils.model.KeyConstraintUtil; +import org.jiemamy.utils.model.TableUtil; + +/** + * 外部キー設定ダイアログ + * + * @author takezoe + * @author daisuke + */ +public class ForeignKeyEditDialog extends Dialog { + + private static final Logger logger = LoggerFactory.getLogger(ForeignKeyEditDialog.class); + + private ForeignKeyModel foreignKeyModel; + + private List<ColumnModel> sourceColumns; + + private List<LocalKeyModel> referenceKeys; + + private List<Combo> fkColumnCombos; + + private List<Label> pkColumnLabels; + + private Text txtKeyName; + + private Combo cmbReferenceKey; + + private Button chkDeferrable; + + private Button radImmediate; + + private Button radDeferred; + + private Combo cmbMatchType; + + private Combo cmbOnDelete; + + private Combo cmbOnUpdate; + + private Jiemamy jiemamy; + + + /** + * コンストラクタ。 + * + * @param shell + * @param foreignKeyModel + */ + public ForeignKeyEditDialog(Shell shell, ForeignKeyModel foreignKeyModel) { + super(shell); + setShellStyle(getShellStyle() | SWT.RESIZE); + this.foreignKeyModel = foreignKeyModel; + jiemamy = foreignKeyModel.getJiemamy(); + TableModel sourceTableModel = AttributeUtil.getBelongingTable(foreignKeyModel); + TableModel targetTableModel = (TableModel) ForeignKeyUtil.getReferenceEntity(this.foreignKeyModel); + sourceColumns = TableUtil.getColumns(sourceTableModel); + referenceKeys = TableUtil.getAttributes(targetTableModel, LocalKeyModel.class); + + fkColumnCombos = new ArrayList<Combo>(referenceKeys.size()); + pkColumnLabels = new ArrayList<Label>(referenceKeys.size()); + } + + /** + * {@inheritDoc} + */ + @Override + public int open() { + int result = super.open(); + txtKeyName.setText(StringUtils.defaultIfEmpty(foreignKeyModel.getName(), "")); + + MatchType matchType = foreignKeyModel.getMatchType(); + cmbMatchType.setText(matchType == null ? "" : matchType.name().replace('_', ' ')); + + ReferentialAction onDelete = foreignKeyModel.getOnDelete(); + cmbOnDelete.setText(onDelete == null ? "" : onDelete.name().replace('_', ' ')); + + ReferentialAction onUpdate = foreignKeyModel.getOnUpdate(); + cmbOnUpdate.setText(onUpdate == null ? "" : onUpdate.name().replace('_', ' ')); + + Deferrability deferrability = foreignKeyModel.getDeferrability(); + chkDeferrable.setSelection(deferrability == null ? false : deferrability.isDeferrable()); + if (chkDeferrable.getSelection()) { + radImmediate.setSelection(deferrability.getInitiallyCheckTime() == InitiallyCheckTime.IMMEDIATE); + radDeferred.setSelection(deferrability.getInitiallyCheckTime() == InitiallyCheckTime.DEFERRED); + } + return result; + } + + @Override + protected void constrainShellSize() { + Shell shell = getShell(); + shell.pack(); + shell.setSize(400, shell.getSize().y); + } + + @Override + protected Control createDialogArea(Composite parent) { + getShell().setText(Messages.Dialog_Title); + + Composite composite = new Composite(parent, SWT.NULL); + composite.setLayout(new GridLayout(5, false)); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + Label label; + GridData gd; + + label = new Label(composite, SWT.NULL); + label.setText("制約名"); // RESOURCE + + txtKeyName = new Text(composite, SWT.BORDER); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 4; + txtKeyName.setLayoutData(gd); + + label = new Label(composite, SWT.NULL); + label.setText("参照キー"); // RESOURCE + + cmbReferenceKey = new Combo(composite, SWT.READ_ONLY); + cmbReferenceKey.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + for (LocalKeyModel referenceKey : referenceKeys) { + cmbReferenceKey.add(KeyConstraintUtil.toStringKeyColumns(referenceKey)); + } + + chkDeferrable = new Button(composite, SWT.CHECK); + chkDeferrable.setText("遅延可能"); // RESOURCE + chkDeferrable.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent evt) { + if (chkDeferrable.getSelection()) { + radImmediate.setEnabled(true); + radDeferred.setEnabled(true); + } else { + radImmediate.setEnabled(false); + radImmediate.setSelection(true); + radDeferred.setEnabled(false); + radDeferred.setSelection(false); + } + } + }); + + radImmediate = new Button(composite, SWT.RADIO); + radImmediate.setText("即時評価"); // RESOURCE + + radDeferred = new Button(composite, SWT.RADIO); + radDeferred.setText("遅延評価"); // RESOURCE + + final Group group = new Group(composite, SWT.NULL); + group.setText("マッピング"); + group.setLayout(new GridLayout(3, false)); + gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan = 5; + group.setLayoutData(gd); + + if (true) { + label = new Label(group, SWT.NULL); + label.setText("参照するカラムがありましぇん(´・ω・`)"); + } else { + // ヘッダ + label = new Label(group, SWT.BORDER); + label.setText("参照元"); // RESOURCE + label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + label.setAlignment(SWT.CENTER); + + label = new Label(group, SWT.NULL); + label.setText("=>"); + + label = new Label(group, SWT.BORDER); + label.setText("参照先"); // RESOURCE + label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + label.setAlignment(SWT.CENTER); + + cmbReferenceKey.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + logger.debug("cmbReferenceKey selected"); + // TODO +// Control[] children = group.getChildren(); +// for (Control control : children) { +// control.dispose(); +// } +// for (ColumnRef columnRef : referenceKeys.get(cmbReferenceKey.getSelectionIndex()).getKeyColumns()) { +// ReferenceResolver resolver = jiemamy.getReferenceResolver(); +// ColumnModel columnModel = resolver.resolve(columnRef); +// Combo cmbKeyColumn = new Combo(group, SWT.READ_ONLY); +// cmbKeyColumn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); +// for (ColumnModel column : sourceColumns) { +// cmbKeyColumn.add(column.getName()); +// } +// cmbKeyColumn.setText(mapping.getConstraintColumnName()); +// cmbKeyColumn.setVisibleItemCount(20); +// fkColumnCombos.add(cmbKeyColumn); +// +// Label label = new Label(group, SWT.NULL); +// label.setText("=>"); +// +// Label lblReferenceColumn = new Label(group, SWT.BORDER); +// lblReferenceColumn.setText(mapping.getReferenceColumnName()); +// lblReferenceColumn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); +// pkColumnLabels.add(lblReferenceColumn); +// } + } + }); + } + + final Composite option = new Composite(composite, 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"); // 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().replace('_', ' ')); + } + + label = new Label(option, SWT.NULL); + label.setText("ON UPDATE"); // 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().replace('_', ' ')); + } + + label = new Label(option, SWT.NULL); + label.setText("マッチ型"); // RESOURCE + cmbMatchType = new Combo(option, SWT.READ_ONLY); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.horizontalSpan = 3; + cmbMatchType.setLayoutData(gd); + cmbMatchType.add(""); + for (MatchType matchType : MatchType.values()) { + cmbMatchType.add(matchType.name().replace('_', ' ')); + } + + return composite; + } + + @Override + protected void okPressed() { + foreignKeyModel.setName(StringUtils.defaultIfEmpty(txtKeyName.getText(), null)); + + // TODO +// if (sourceColumns.isEmpty() == false) { +// for (int i = 0; i < fkColumnCombos.size(); i++) { +// ForeignKeyMapping mapping = foreignKeyModel.getMapping(i); +// int index = fkColumnCombos.get(i).getSelectionIndex(); +// if (index == -1) { +// continue; +// } +// ColumnModel constraintColumn = sourceColumns.get(index); +// mapping.setConstraintColumn(constraintColumn); +// } +// } + + try { + foreignKeyModel.setMatchType(MatchType.valueOf(cmbMatchType.getText())); + } catch (IllegalArgumentException e) { + logger.warn(cmbMatchType.getText() + " is not MatchType element."); + foreignKeyModel.setMatchType(null); + } + try { + foreignKeyModel.setOnDelete(ReferentialAction.valueOf(cmbOnDelete.getText())); + } catch (IllegalArgumentException e) { + logger.warn(cmbOnDelete.getText() + " is not ReferentialAction element."); + foreignKeyModel.setOnDelete(null); + } + try { + foreignKeyModel.setOnUpdate(ReferentialAction.valueOf(cmbOnUpdate.getText())); + } catch (IllegalArgumentException e) { + logger.warn(cmbOnUpdate.getText() + " is not ReferentialAction element."); + foreignKeyModel.setOnUpdate(null); + } + + if (chkDeferrable.getSelection()) { + Deferrability deferrability = foreignKeyModel.getDeferrability(); + if (deferrability == null) { + deferrability = jiemamy.getFactory().newModel(Deferrability.class); + foreignKeyModel.setDeferrability(deferrability); + } + deferrability.setDeferrable(true); + if (radImmediate.getSelection()) { + deferrability.setInitiallyCheckTime(InitiallyCheckTime.IMMEDIATE); + } else if (radDeferred.getSelection()) { + deferrability.setInitiallyCheckTime(InitiallyCheckTime.DEFERRED); + } + + } + + super.okPressed(); + } +} Property changes on: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/foreignkey/ForeignKeyEditDialog.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/ForeignKeyEditPart.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/ForeignKeyEditPart.java 2009-02-21 06:24:26 UTC (rev 2700) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/ForeignKeyEditPart.java 2009-02-21 13:43:00 UTC (rev 2701) @@ -24,6 +24,7 @@ import org.eclipse.draw2d.PolylineConnection; import org.eclipse.draw2d.PolylineDecoration; import org.eclipse.draw2d.PositionConstants; +import org.eclipse.jface.dialogs.Dialog; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.slf4j.Logger; @@ -31,6 +32,7 @@ import org.jiemamy.eclipse.editor.DisplayPlace; import org.jiemamy.eclipse.editor.DisplayTarget; +import org.jiemamy.eclipse.editor.dialog.foreignkey.ForeignKeyEditDialog; import org.jiemamy.eclipse.editor.editpart.DoubleClickSupport; import org.jiemamy.eclipse.editor.editpart.EditDialogSupport; import org.jiemamy.eclipse.editor.utils.LabelStringUtil; @@ -84,22 +86,22 @@ ConnectionAdapter connection = getModel(); ForeignKeyModel fkModel = connection.unwrap(); -// ForeignKeyEditDialog dialog = new ForeignKeyEditDialog(getViewer().getControl().getShell(), fkModel); + ForeignKeyEditDialog dialog = new ForeignKeyEditDialog(getViewer().getControl().getShell(), fkModel); // // // 編集前のスナップショットを保存 // Memento beforeEditMemento = dialog.createMemento(); // -// if (dialog.open() == Dialog.OK) { + if (dialog.open() == Dialog.OK) { // // 編集後のスナップショットを保存 // Memento afterEditMemento = dialog.createMemento(); // // GraphicalViewer viewer = (GraphicalViewer) getViewer(); // viewer.getEditDomain().getCommandStack().execute( // new EditForeignKeyModelCommand(fkModel, beforeEditMemento, afterEditMemento)); -// } else { + } else { // // 編集前にロールバック // dialog.setMemento(beforeEditMemento); -// } + } } /** Modified: vesta/trunk/org.jiemamy.eclipse.dialect.mysql/.classpath =================================================================== --- vesta/trunk/org.jiemamy.eclipse.dialect.mysql/.classpath 2009-02-21 06:24:26 UTC (rev 2700) +++ vesta/trunk/org.jiemamy.eclipse.dialect.mysql/.classpath 2009-02-21 13:43:00 UTC (rev 2701) @@ -21,6 +21,7 @@ <classpathentry exported="true" kind="lib" path="lib/stax-1.2.0.jar" sourcepath="lib/sources/stax-1.2.0-sources.jar"/> <classpathentry exported="true" kind="lib" path="lib/stax-api-1.0.1.jar" sourcepath="lib/sources/stax-api-1.0.1-sources.jar"/> <classpathentry exported="true" kind="lib" path="lib/wstx-asl-3.2.7.jar" sourcepath="lib/sources/wstx-asl-3.2.7-sources.jar"/> + <classpathentry kind="lib" path="lib/jiemamy-dialect-mysql-0.2.0-SNAPSHOT.jar" sourcepath="lib/sources/jiemamy-dialect-mysql-0.2.0-SNAPSHOT-sources.jar"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="output" path="target/classes"/> Modified: vesta/trunk/org.jiemamy.eclipse.dialect.mysql/META-INF/MANIFEST.MF =================================================================== --- vesta/trunk/org.jiemamy.eclipse.dialect.mysql/META-INF/MANIFEST.MF 2009-02-21 06:24:26 UTC (rev 2700) +++ vesta/trunk/org.jiemamy.eclipse.dialect.mysql/META-INF/MANIFEST.MF 2009-02-21 13:43:00 UTC (rev 2701) @@ -18,6 +18,7 @@ lib/javassist-3.8.0.GA.jar, lib/jcl-over-slf4j-1.5.5.jar, lib/jiemamy-core-0.2.0-SNAPSHOT.jar, + lib/jiemamy-dialect-mysql-0.2.0-SNAPSHOT.jar, lib/jiemamy-spec-core-0.2.0-SNAPSHOT.jar, lib/logback-classic-0.9.9.jar, lib/logback-core-0.9.9.jar, Modified: vesta/trunk/org.jiemamy.eclipse.dialect.mysql/build.properties =================================================================== --- vesta/trunk/org.jiemamy.eclipse.dialect.mysql/build.properties 2009-02-21 06:24:26 UTC (rev 2700) +++ vesta/trunk/org.jiemamy.eclipse.dialect.mysql/build.properties 2009-02-21 13:43:00 UTC (rev 2701) @@ -16,6 +16,7 @@ lib/javassist-3.8.0.GA.jar,\ lib/jcl-over-slf4j-1.5.5.jar,\ lib/jiemamy-core-0.2.0-SNAPSHOT.jar,\ + lib/jiemamy-dialect-mysql-0.2.0-SNAPSHOT.jar,\ lib/jiemamy-spec-core-0.2.0-SNAPSHOT.jar,\ lib/logback-classic-0.9.9.jar,\ lib/logback-core-0.9.9.jar,\