svnno****@sourc*****
svnno****@sourc*****
2009年 2月 16日 (月) 23:56:02 JST
Revision: 2677 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2677 Author: daisuke_m Date: 2009-02-16 23:56:02 +0900 (Mon, 16 Feb 2009) Log Message: ----------- DatabaseEditDialog整備。 / refactor Modified Paths: -------------- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/EventBrokerImpl.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/DatabaseEditDialogDomainTab.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/AbstractJmConnectionEditPart.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/AbstractJmNodeEditPart.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/RootEditPart.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/outlinetree/AbstractModelTreeEditPart.java zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/editcommand/CommandListener.java -------------- next part -------------- Modified: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-02-16 13:20:48 UTC (rev 2676) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-02-16 14:56:02 UTC (rev 2677) @@ -128,7 +128,7 @@ /** * {@inheritDoc} */ - public void commandProcess(Command command) { + public void commandExecuted(Command command) { commandList.add(command); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/EventBrokerImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/EventBrokerImpl.java 2009-02-16 13:20:48 UTC (rev 2676) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/EventBrokerImpl.java 2009-02-16 14:56:02 UTC (rev 2677) @@ -65,7 +65,7 @@ logger.info("target : " + command.getTarget()); for (CommandListener l : listeners) { if (strategy.needToDispatch(l, command)) { - l.commandProcess(command); + l.commandExecuted(command); logger.debug("Listener is kicked: " + l.toString()); } } Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-02-16 13:20:48 UTC (rev 2676) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-02-16 14:56:02 UTC (rev 2677) @@ -310,7 +310,7 @@ /** * {@inheritDoc} */ - public void commandProcess(Command command) { + public void commandExecuted(Command command) { commandList.add(command); } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/DatabaseEditDialogDomainTab.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/DatabaseEditDialogDomainTab.java 2009-02-16 13:20:48 UTC (rev 2676) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/DatabaseEditDialogDomainTab.java 2009-02-16 14:56:02 UTC (rev 2677) @@ -1,10 +1,10 @@ package org.jiemamy.eclipse.editor.dialog.root; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import java.util.Collection; import java.util.List; +import org.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang.StringUtils; import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.ILabelProviderListener; @@ -12,6 +12,8 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; import org.eclipse.swt.events.KeyAdapter; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.MenuAdapter; @@ -34,8 +36,11 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.Text; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.jiemamy.JiemamyFactory; +import org.jiemamy.dialect.Dialect; import org.jiemamy.eclipse.Images; import org.jiemamy.eclipse.JiemamyPlugin; import org.jiemamy.eclipse.editor.DisplayPlace; @@ -44,6 +49,8 @@ import org.jiemamy.eclipse.ui.AbstractTableViewerEditArea; import org.jiemamy.eclipse.ui.helper.TextSelectionAdapter; import org.jiemamy.eclipse.ui.tab.AbstractTab; +import org.jiemamy.editcommand.Command; +import org.jiemamy.editcommand.CommandListener; import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.constraint.CheckConstraintModel; @@ -57,16 +64,19 @@ import org.jiemamy.utils.CollectionsUtil; import org.jiemamy.utils.ListUtils; import org.jiemamy.utils.model.DomainUtil; +import org.jiemamy.utils.model.RootModelUtil; /** - * データベース編集ダイアログの「ドメイン」タブ + * データベース編集ダイアログの「ドメイン」タブ。 * * @author daisuke */ public class DatabaseEditDialogDomainTab extends AbstractTab { - private RootModel rootModel; + private static Logger logger = LoggerFactory.getLogger(DatabaseEditDialogDomainTab.class); + private final RootModel rootModel; + private AbstractTableViewerEditArea domainEditArea; private Text txtDomainName; @@ -75,14 +85,10 @@ private Text txtColumnSize; -// private Text txtDefaultValue; - private Text txtDescription; private Button chkIsNotNull; -// private Button chkIsUnique; - private Text txtCheck; @@ -92,7 +98,6 @@ * @param rootModel */ public DatabaseEditDialogDomainTab(RootModel rootModel) { - super(); this.rootModel = rootModel; } @@ -125,14 +130,30 @@ * * @author daisuke */ - private class DomainContentProvider extends ArrayContentProvider implements PropertyChangeListener { + private class DomainContentProvider extends ArrayContentProvider implements CommandListener { - @SuppressWarnings("unused") private Viewer viewer; + public void commandExecuted(Command command) { + logger.debug("DomainContentProvider: commandExecuted"); +// if (evt.getPropertyName().equals(RootModel.P_DB_DOMAINS)) { + domainEditArea.refreshTable(); // レコードの変更を反映させる。 +// } else if (evt.getSource() instanceof DefinitionModel) { +// domainEditArea.refreshTable(); // レコードの変更を反映させる。 +// if (evt.getPropertyName().equals(DefinitionModel.P_CREATE)) { +// // nothing to do +// } else if (evt.getPropertyName().equals(DefinitionModel.P_DELETE)) { +// ((DefinitionModel) evt.getSource()).removePropertyChangeListener(this); +// } else if (evt.getPropertyName().equals(DefinitionModel.P_REVERT)) { +// ((DefinitionModel) evt.getSource()).addPropertyChangeListener(this); +// } +// } + } + @Override public void dispose() { + logger.debug("DomainContentProvider: disposed"); // rootModel.removePropertyChangeListener(this); // for (DomainModel domain : rootModel.getDomains()) { // domain.removePropertyChangeListener(this); @@ -140,8 +161,15 @@ super.dispose(); } + public JiemamyElement getTargetModel() { + return (JiemamyElement) viewer.getInput(); + } + @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + logger.debug("DomainContentProvider: input changed"); + logger.trace("oldInput: " + oldInput); + logger.trace("newInput: " + newInput); this.viewer = viewer; if (oldInput != null) { // rootModel.removePropertyChangeListener(this); @@ -159,21 +187,6 @@ super.inputChanged(viewer, oldInput, newInput); } - public void propertyChange(PropertyChangeEvent evt) { -// if (evt.getPropertyName().equals(RootModel.P_DB_DOMAINS)) { -// domainEditArea.refreshTable(); // レコードの変更を反映させる。 -// } else if (evt.getSource() instanceof DefinitionModel) { -// domainEditArea.refreshTable(); // レコードの変更を反映させる。 -// if (evt.getPropertyName().equals(DefinitionModel.P_CREATE)) { -// // nothing to do -// } else if (evt.getPropertyName().equals(DefinitionModel.P_DELETE)) { -// ((DefinitionModel) evt.getSource()).removePropertyChangeListener(this); -// } else if (evt.getPropertyName().equals(DefinitionModel.P_REVERT)) { -// ((DefinitionModel) evt.getSource()).addPropertyChangeListener(this); -// } -// } - } - } private class DomainEditTableArea extends AbstractTableViewerEditArea { @@ -313,11 +326,21 @@ @Override protected void configureTableViewer() { TableViewer tableViewer = getTableViewer(); -// tableViewer.setCellModifier(new RecordCellModifier(tableViewer)); tableViewer.setLabelProvider(new DomainLabelProvider()); - tableViewer.setContentProvider(new DomainContentProvider()); -// tableViewer.setSorter(new ViewerSorter()); + final DomainContentProvider domainContentProvider = new DomainContentProvider(); + tableViewer.setContentProvider(domainContentProvider); tableViewer.setInput(rootModel.getDomains()); + + rootModel.getJiemamy().getEventBroker().addListener(domainContentProvider); + + // THINK んーーー?? このタイミングか? + tableViewer.getTable().addDisposeListener(new DisposeListener() { + + public void widgetDisposed(DisposeEvent e) { + rootModel.getJiemamy().getEventBroker().removeListener(domainContentProvider); + } + + }); } @Override @@ -355,12 +378,18 @@ cmbColumnType = new Combo(cmpTypes, SWT.READ_ONLY); cmbColumnType.setVisibleItemCount(20); -// for (PrimitiveDataType primitiveType : rootModel.getDialect().getTypeMappings().values()) { -// cmbColumnType.add(primitiveType.getName()); -// } - cmbColumnType.add("TODO1"); // TODO - cmbColumnType.add("TODO2"); + Dialect dialect; + try { + dialect = RootModelUtil.getDialect(rootModel); + } catch (ClassNotFoundException e) { + // THINK どうにか。。。w + dialect = JiemamyPlugin.getDialectResolver().getAllInstance().get(0); + } + for (String primitiveType : dialect.getAllDataTypes()) { + cmbColumnType.add(primitiveType); + } + label = new Label(cmpTypes, SWT.NULL); label.setText(Messages.Label_Domain_DataTypeSize); @@ -397,10 +426,6 @@ chkIsNotNull = new Button(cmpChecks, SWT.CHECK); chkIsNotNull.setText(Messages.Label_Domain_NotNullConstraint); -// if (!rootModel.getDialect().getColumnOptions().isEmpty()) { -// createColumnOptionControls(cmpChecks); -// } - return group; } @@ -411,19 +436,15 @@ colName.setWidth(100); TableColumn colType = new TableColumn(table, SWT.LEFT); - colType.setText(Messages.Column_Domain_DataType); // RESOURCE + colType.setText(Messages.Column_Domain_DataType); colType.setWidth(150); -// TableColumn colDefaultValue = new TableColumn(table, SWT.LEFT); -// colDefaultValue.setText("dialog.db.domain.tbl.header.defaultValue"); // RESOURCE -// colDefaultValue.setWidth(100); - TableColumn colNotNull = new TableColumn(table, SWT.LEFT); - colNotNull.setText(Messages.Column_Domain_NotNullConstraint); // RESOURCE + colNotNull.setText(Messages.Column_Domain_NotNullConstraint); colNotNull.setWidth(50); TableColumn colUnique = new TableColumn(table, SWT.LEFT); - colUnique.setText(Messages.Column_Domain_CheckConstraint); // RESOURCE + colUnique.setText(Messages.Column_Domain_CheckConstraint); colUnique.setWidth(50); } @@ -443,11 +464,6 @@ txtCheck.setEnabled(false); txtDescription.setEnabled(false); chkIsNotNull.setEnabled(false); - -// for (Map.Entry<DialectOption, DialectOptionUI> entry : domainOptionUIs.entrySet()) { -// entry.getValue().setEnabled(false); -// entry.getValue().setModel(null); -// } } @Override @@ -457,9 +473,9 @@ txtDomainName.setText(domain.getName()); // cmbColumnType.setText(rootModel.getDialect().convertToPrimitiveType(columnType).getIdentifier()); - txtColumnSize - .setText(String.valueOf(domain.getDataType().getAdapter(SizedDataTypeAdapter.class).getSize())); - txtDescription.setText(domain.getDescription()); + txtColumnSize.setText(ObjectUtils.toString(domain.getDataType().getAdapter(SizedDataTypeAdapter.class) + .getSize(), "")); + txtDescription.setText(StringUtils.defaultIfEmpty(domain.getDescription(), "")); chkIsNotNull.setSelection(DomainUtil.hasConstraint(domain, NotNullConstraintModel.class)); List<ValueConstraintModel> constraints = domain.getConstraints(); for (ValueConstraintModel valueConstraintModel : constraints) { @@ -476,16 +492,6 @@ txtDescription.setEnabled(true); chkIsNotNull.setEnabled(true); txtCheck.setEnabled(true); - -// if (domainOptions != null) { -// for (DialectOption columnOption : domainOptions) { -// DialectOptionUI ui = domainOptionUIs.get(columnOption); -// if (index > -1) { -// ui.setModel(rootModel.getDomain(index)); -// } -// ui.setEnabled(true); -// } -// } } @Override @@ -552,21 +558,6 @@ return domainToRemove; } - private void createColumnOptionControls(Composite parent) { - int domainEditIndex = getTableViewer().getTable().getSelectionIndex(); -// domainOptions = rootModel.getDialect().getColumnOptions(); -// if (domainOptions != null) { -// for (DialectOption columnOption : domainOptions) { -// DialectOptionUI ui = new DialectOptionUI(columnOption); -// if (domainEditIndex > -1) { -// ui.setModel(rootModel.getDomain(domainEditIndex)); -// } -// ui.createControl(parent); -// domainOptionUIs.put(columnOption, ui); -// } -// } - } - private void updateModel() { int domainEditIndex = getTableViewer().getTable().getSelectionIndex(); int selectionInedx = cmbColumnType.getSelectionIndex(); @@ -599,10 +590,6 @@ NotNullConstraintModel nnConstraint = factory.newModel(NotNullConstraintModel.class); domain.getConstraints().add(nnConstraint); } - -// for (Map.Entry<DialectOption, DialectOptionUI> entry : domainOptionUIs.entrySet()) { -// entry.getValue().setDataControlToModel(); -// } } } } @@ -626,17 +613,11 @@ ImageRegistry ir = JiemamyPlugin.getDefault().getImageRegistry(); DomainModel domain = (DomainModel) element; - switch (columnIndex) { - case 3: - return DomainUtil.hasConstraint(domain, NotNullConstraintModel.class) ? ir.get(Images.CHECK_ON) - : ir.get(Images.CHECK_OFF); - - case 4: - // THINK Domainにuniqueはあるか? - - default: - return null; + if (columnIndex == 3) { + boolean notNull = DomainUtil.hasConstraint(domain, NotNullConstraintModel.class); + return ir.get(notNull ? Images.CHECK_ON : Images.CHECK_OFF); } + return null; } public String getColumnText(Object element, int columnIndex) { Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/AbstractJmConnectionEditPart.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/AbstractJmConnectionEditPart.java 2009-02-16 13:20:48 UTC (rev 2676) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/AbstractJmConnectionEditPart.java 2009-02-16 14:56:02 UTC (rev 2677) @@ -68,7 +68,7 @@ /** * {@inheritDoc} */ - public void commandProcess(Command command) { + public void commandExecuted(Command command) { refreshVisuals(); } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/AbstractJmNodeEditPart.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/AbstractJmNodeEditPart.java 2009-02-16 13:20:48 UTC (rev 2676) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/AbstractJmNodeEditPart.java 2009-02-16 14:56:02 UTC (rev 2677) @@ -80,7 +80,7 @@ /** * {@inheritDoc} */ - public void commandProcess(Command command) { + public void commandExecuted(Command command) { refreshVisuals(); } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/RootEditPart.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/RootEditPart.java 2009-02-16 13:20:48 UTC (rev 2676) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/RootEditPart.java 2009-02-16 14:56:02 UTC (rev 2677) @@ -86,7 +86,7 @@ /** * {@inheritDoc} */ - public void commandProcess(Command command) { + public void commandExecuted(Command command) { refreshChildren(); // JiemamyValidatorUtil.validate(getResource(), (RootModel) getModel()); } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/outlinetree/AbstractModelTreeEditPart.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/outlinetree/AbstractModelTreeEditPart.java 2009-02-16 13:20:48 UTC (rev 2676) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/outlinetree/AbstractModelTreeEditPart.java 2009-02-16 14:56:02 UTC (rev 2677) @@ -44,7 +44,7 @@ /** * {@inheritDoc} */ - public void commandProcess(Command command) { + public void commandExecuted(Command command) { refreshChildren(); } Modified: zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/editcommand/CommandListener.java =================================================================== --- zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/editcommand/CommandListener.java 2009-02-16 13:20:48 UTC (rev 2676) +++ zeus/trunk/jiemamy-spec-core/src/main/java/org/jiemamy/editcommand/CommandListener.java 2009-02-16 14:56:02 UTC (rev 2677) @@ -33,7 +33,7 @@ * * @param command */ - void commandProcess(Command command); + void commandExecuted(Command command); /** * 監視対象を返す。