svnno****@sourc*****
svnno****@sourc*****
2009年 2月 19日 (木) 23:03:33 JST
Revision: 2691 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2691 Author: daisuke_m Date: 2009-02-19 23:03:33 +0900 (Thu, 19 Feb 2009) Log Message: ----------- テーブル編集ダイアログ・チェック制約タブの表示。 / refactor Modified Paths: -------------- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDomainTab.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialog.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogCheckTab.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java -------------- next part -------------- Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDomainTab.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDomainTab.java 2009-02-19 13:34:12 UTC (rev 2690) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDomainTab.java 2009-02-19 14:03:33 UTC (rev 2691) @@ -93,18 +93,6 @@ private AbstractTableEditor domainEditor; - private Text txtDomainName; - - private Combo cmbColumnType; - - private Text txtColumnSize; - - private Text txtDescription; - - private Button chkIsNotNull; - - private Text txtCheck; - /** * インスタンスを生成する。 @@ -230,11 +218,12 @@ switch (columnIndex) { case 0: return LabelStringUtil.getString(rootModel, domain, DisplayTarget.NAME, DisplayPlace.TABLE); + case 1: return LabelStringUtil.getString(rootModel, domain, DisplayTarget.TYPE, DisplayPlace.TABLE); default: - return ""; + return StringUtils.EMPTY; } } } @@ -247,6 +236,20 @@ private final List<DomainModel> domains; + private Text txtDomainName; + + private Combo cmbColumnType; + + private Text txtColumnSize; + + private Text txtCheckName; + + private Text txtCheckExpression; + + private Button chkIsNotNull; + + private Text txtDescription; + /** * インスタンスを生成する。 @@ -295,7 +298,6 @@ Table table = getTableViewer().getTable(); JiemamyFactory factory = jiemamy.getFactory(); DomainModel domainModel = factory.newModel(DomainModel.class); - domainModel.setName("DOMAIN_" + (domains.size() + 1)); BuiltinDataType builtinDataType = factory.newBuiltinDataType(allTypes.get(0)); @@ -372,8 +374,8 @@ domainEditor.refreshTable(); } }); - txtCheck.addFocusListener(new TextSelectionAdapter(txtCheck)); - txtCheck.addKeyListener(new KeyAdapter() { + txtCheckExpression.addFocusListener(new TextSelectionAdapter(txtCheckExpression)); + txtCheckExpression.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { @@ -387,19 +389,6 @@ protected void configureTable(final Table table) { super.configureTable(table); - table.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - int index = table.getSelectionIndex(); - if (index >= 0) { - enableEditDetailControls(index); - } else { - disableEditDetailControls(); - } - } - }); - // THINK ↓要る? // final Menu menu = new Menu(table); // table.setMenu(menu); @@ -431,18 +420,18 @@ @Override protected void configureTableViewer(TableViewer tableViewer) { tableViewer.setLabelProvider(new DomainLabelProvider()); - final DomainContentProvider domainContentProvider = new DomainContentProvider(); - tableViewer.setContentProvider(domainContentProvider); + final DomainContentProvider contentProvider = new DomainContentProvider(); + tableViewer.setContentProvider(contentProvider); tableViewer.setInput(domains); final EventBroker eventBroker = jiemamy.getEventBroker(); - eventBroker.addListener(domainContentProvider); + eventBroker.addListener(contentProvider); // THINK んーーー?? このタイミングか? tableViewer.getTable().addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { - eventBroker.removeListener(domainContentProvider); + eventBroker.removeListener(contentProvider); } }); @@ -491,8 +480,8 @@ label = new Label(cmpTypes, SWT.NULL); label.setText(Messages.Label_Domain_CheckConstraint); - txtCheck = new Text(cmpTypes, SWT.BORDER); - txtCheck.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + txtCheckExpression = new Text(cmpTypes, SWT.BORDER); + txtCheckExpression.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Composite cmpDesc = new Composite(parent, SWT.NULL); cmpDesc.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); @@ -537,17 +526,17 @@ @Override protected void disableEditDetailControls() { - txtDomainName.setText(""); - cmbColumnType.setText(""); - txtColumnSize.setText(""); - txtCheck.setText(""); - txtDescription.setText(""); + txtDomainName.setText(StringUtils.EMPTY); + cmbColumnType.setText(StringUtils.EMPTY); + txtColumnSize.setText(StringUtils.EMPTY); + txtCheckExpression.setText(StringUtils.EMPTY); + txtDescription.setText(StringUtils.EMPTY); chkIsNotNull.setSelection(false); txtDomainName.setEnabled(false); cmbColumnType.setEnabled(false); txtColumnSize.setEnabled(false); - txtCheck.setEnabled(false); + txtCheckExpression.setEnabled(false); txtDescription.setEnabled(false); chkIsNotNull.setEnabled(false); } @@ -564,14 +553,15 @@ txtDescription.setText(StringUtils.defaultIfEmpty(domain.getDescription(), "")); chkIsNotNull.setSelection(domain.getNotNull() != null); CheckConstraintModel checkConstraintModel = domain.getCheck(); - txtCheck.setText(checkConstraintModel.getExpression()); + txtCheckExpression.setText(checkConstraintModel.getExpression()); txtDomainName.setEnabled(true); cmbColumnType.setEnabled(true); txtColumnSize.setEnabled(true); txtDescription.setEnabled(true); chkIsNotNull.setEnabled(true); - txtCheck.setEnabled(true); + txtCheckExpression.setEnabled(true); + // 現在値の設定 } @Override @@ -581,7 +571,6 @@ JiemamyFactory factory = jiemamy.getFactory(); DomainModel domainModel = factory.newModel(DomainModel.class); - domainModel.setName("DOMAIN_" + (domains.size() + 1)); if (index < 0 || index > table.getItemCount()) { Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialog.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialog.java 2009-02-19 13:34:12 UTC (rev 2690) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialog.java 2009-02-19 14:03:33 UTC (rev 2691) @@ -71,11 +71,11 @@ private TableEditDialogColumnTab tabColumns; // private TableEditDialogKeyTab tabKeys; -// + + private TableEditDialogCheckTab tabChecks; + // private TableEditDialogIndexTab tabIndexes; -// -// private TableEditDialogCheckTab tabChecks; -// + // private TableEditDialogRecordTab tabRecords; private TextEditTab tabBeginScript; @@ -171,25 +171,30 @@ gd.horizontalSpan = 6; tabFolder.setLayoutData(gd); + // ---- B-1. カラム tabColumns = new TableEditDialogColumnTab(tabFolder, SWT.NULL, tableModel); + // ---- B-2. 一意 // tabKeys = new TableEditDialogKeyTab(tabFolder, SWT.NULL, tableModel); -// + + // ---- B-3. チェック制約 + tabChecks = new TableEditDialogCheckTab(tabFolder, SWT.NULL, tableModel); + + // ---- B-4. インデックス // tabIndexes = new TableEditDialogIndexTab(tabFolder, SWT.NULL, tableModel); -// -// tabChecks = new TableEditDialogCheckTab(tabFolder, SWT.NULL, tableModel); -// + + // ---- B-5. BeginScript // tabRecords = new TableEditDialogRecordTab(tabFolder, SWT.NULL, tableModel); - // ---- B-5. BeginScript + // ---- B-6. BeginScript String beginScript = StringUtils.defaultIfEmpty(tableModel.getBeginScript(), ""); tabBeginScript = new TextEditTab(tabFolder, Messages.Tab_Table_BeginScript, beginScript); - // ---- B-6. EndScript + // ---- B-7. EndScript String endScript = StringUtils.defaultIfEmpty(tableModel.getEndScript(), ""); tabEndScript = new TextEditTab(tabFolder, Messages.Tab_Table_EndScript, endScript); - // ---- B-7. Description + // ---- B-8. Description String description = StringUtils.defaultIfEmpty(tableModel.getDescription(), ""); tabDescription = new TextEditTab(tabFolder, Messages.Tab_Table_Description, description); @@ -200,7 +205,7 @@ protected void okPressed() { if (canExecuteOk()) { tableModel.setName(txtTableName.getText()); - tableModel.setLogicalName(txtLogicalName.getText()); + tableModel.setLogicalName(StringUtils.defaultIfEmpty(txtLogicalName.getText(), null)); tableModel.setBeginScript(StringUtils.defaultIfEmpty(tabBeginScript.getTextWidget().getText(), null)); tableModel.setEndScript(StringUtils.defaultIfEmpty(tabEndScript.getTextWidget().getText(), null)); tableModel.setDescription(StringUtils.defaultIfEmpty(tabDescription.getTextWidget().getText(), null)); Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogCheckTab.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogCheckTab.java 2009-02-19 13:34:12 UTC (rev 2690) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogCheckTab.java 2009-02-19 14:03:33 UTC (rev 2691) @@ -18,402 +18,450 @@ */ package org.jiemamy.eclipse.editor.dialog.table; -// -//import org.eclipse.jface.viewers.ArrayContentProvider; -//import org.eclipse.jface.viewers.BaseLabelProvider; -//import org.eclipse.jface.viewers.ITableLabelProvider; -//import org.eclipse.jface.viewers.TableViewer; -//import org.eclipse.jface.viewers.Viewer; -//import org.eclipse.swt.SWT; -//import org.eclipse.swt.events.KeyAdapter; -//import org.eclipse.swt.events.KeyEvent; -//import org.eclipse.swt.graphics.Image; -//import org.eclipse.swt.layout.GridData; -//import org.eclipse.swt.layout.GridLayout; -//import org.eclipse.swt.widgets.Composite; -//import org.eclipse.swt.widgets.Group; -//import org.eclipse.swt.widgets.Label; -//import org.eclipse.swt.widgets.TabFolder; -//import org.eclipse.swt.widgets.TabItem; -//import org.eclipse.swt.widgets.Table; -//import org.eclipse.swt.widgets.TableColumn; -//import org.eclipse.swt.widgets.Text; -// -//import org.jiemamy.eclipse.JiemamyPlugin; -//import org.jiemamy.eclipse.ui.AbstractTableEditor; -//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.attribute.constraint.CheckConstraintModel; -//import org.jiemamy.model.entity.TableModel; -// -///** -// * テーブル編集ダイアログの「CHECK制約」タブ -// * -// * @author daisuke -// */ -//public class TableEditDialogCheckTab extends AbstractTab { -// -// private TableModel tableModel; -// -// private AbstractTableEditor checkEditArea; -// -// private CheckContentProvider contentProvider; -// -// private Text txtCheckName; -// -// private Text txtCheckDefinition; -// -// -// public TableEditDialogCheckTab(TabFolder parentTabFolder, int style, TableModel tableModel) { -// super(parentTabFolder, style, "カラム"); // RESOURCE -// this.tableModel = tableModel; -// } -// -// @Override -// public Composite createTabArea(TabFolder parentTabFolder) { -// Composite composite = new Composite(parentTabFolder, SWT.NULL); -// composite.setLayout(new GridLayout(1, false)); -// composite.setLayoutData(new GridData(GridData.FILL_BOTH)); -// -// TabItem tabColumn = new TabItem(parentTabFolder, SWT.NONE); -// tabColumn.setText(JiemamyPlugin.getResourceString("dialog.table.tab.check")); -// tabColumn.setControl(composite); -// -// createColumnTab(composite); -// checkEditArea.disableEditControls(); -// -// return composite; -// } -// -// private void createColumnTab(Composite parent) { -// checkEditArea = new CheckEditTableArea(tableModel); -// checkEditArea.setAddLabel(JiemamyPlugin.getResourceString("dialog.table.check.btn.add")); -// checkEditArea.setInsertLabel(JiemamyPlugin.getResourceString("dialog.table.check.btn.insert")); -// checkEditArea.setRemoveLabel(JiemamyPlugin.getResourceString("dialog.table.check.btn.remove")); -// checkEditArea.createControlArea(parent); -// } -// -// -// /** -// * Column用ContentProvider -// * -// * @author daisuke -// */ -// private class CheckContentProvider extends ArrayContentProvider implements CommandListener { -// -// private Viewer viewer; -// -// -// public void commandExecuted(Command command) { -//// if (evt.getPropertyName().equals(TableModel.P_ENTITY_TABLE_CHECKS)) { -// checkEditArea.refreshTable(); -//// } else if (evt.getPropertyName().equals(CheckConstraintModel.P_CHECK_NAME)) { -//// checkEditArea.refreshTable(); -//// } else if (evt.getPropertyName().equals(CheckConstraintModel.P_CHECK_DEFINITION)) { -//// checkEditArea.refreshTable(); -//// } else if (evt.getSource() instanceof CheckConstraintModel) { -//// checkEditArea.refreshTable(); -//// if (evt.getPropertyName().equals(CheckConstraintModel.P_CREATE)) { -//// // nothing to do -//// } else if (evt.getPropertyName().equals(CheckConstraintModel.P_DELETE)) { -//// ((AbstractModel) evt.getSource()).removePropertyChangeListener(this); -//// } else if (evt.getPropertyName().equals(CheckConstraintModel.P_REVERT)) { -//// ((AbstractModel) evt.getSource()).addPropertyChangeListener(this); -//// } -//// } -// } -// -// @Override -// public void dispose() { -//// tableModel.removePropertyChangeListener(this); -//// for (CheckConstraintModel check : tableModel.getChecks()) { -//// ((AbstractModel) check).removePropertyChangeListener(this); -//// } -// super.dispose(); -// } -// -// /** -// * {@inheritDoc} -// */ -// public JiemamyElement getTargetModel() { -// return (JiemamyElement) viewer.getInput(); -// } -// -// @Override -// public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { -// this.viewer = viewer; -// -//// if (oldInput != null) { -//// tableModel.removePropertyChangeListener(this); -//// for (CheckConstraintModel check : tableModel.getChecks()) { -//// ((AbstractModel) check).removePropertyChangeListener(this); -//// } -//// } -//// if (newInput != null) { -//// tableModel.addPropertyChangeListener(this); -//// for (CheckConstraintModel check : tableModel.getChecks()) { -//// ((AbstractModel) check).addPropertyChangeListener(this); -//// } -//// } -// -// super.inputChanged(viewer, oldInput, newInput); -// } -// -// } -// -// private class CheckEditTableArea extends AbstractTableEditor { -// -// private TableModel tableModel; -// -// -// public CheckEditTableArea(TableModel targetModel) { -// super(); -// tableModel = targetModel; -// } -// -// @Override -// protected JiemamyElement addItem() { -// Table table = getTableViewer().getTable(); -// CheckConstraintModel check = new CheckConstraintModel(); -// -// tableModel.addCheck(check); -// -// int addedIndex = tableModel.getChecks().indexOf(check); -// table.setSelection(addedIndex); -// enableEditControls(addedIndex); -// txtCheckName.setFocus(); -// -// return check; -// } -// -// @Override -// protected void configureEditorControls() { -// txtCheckName.addFocusListener(new TextSelectionAdapter(txtCheckName)); -// txtCheckName.addKeyListener(new KeyAdapter() { -// -// @Override -// public void keyReleased(KeyEvent e) { -// updateModel(); -// checkEditArea.refreshTable(); +import java.util.List; + +import org.apache.commons.lang.StringUtils; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.BaseLabelProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +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.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TabFolder; +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.EventBroker; +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.eclipse.ui.AbstractTableEditor; +import org.jiemamy.eclipse.ui.TableEditorConfigurator; +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.attribute.constraint.CheckConstraintModel; +import org.jiemamy.model.attribute.constraint.TableCheckModel; +import org.jiemamy.model.entity.TableModel; +import org.jiemamy.utils.ListUtils; +import org.jiemamy.utils.model.TableUtil; + +/** + * テーブル編集ダイアログの「CHECK制約」タブ。 + * + * @author daisuke + */ +public class TableEditDialogCheckTab extends AbstractTab { + + private static Logger logger = LoggerFactory.getLogger(TableEditDialogCheckTab.class); + + private TableModel tableModel; + + private AbstractTableEditor checkEditor; + + + /** + * インスタンスを生成する。 + * + * @param parentTabFolder + * @param style + * @param tableModel + */ + public TableEditDialogCheckTab(TabFolder parentTabFolder, int style, TableModel tableModel) { + super(parentTabFolder, style, "チェック制約"); // RESOURCE + + this.tableModel = tableModel; + + Composite composite = new Composite(parentTabFolder, SWT.NULL); + composite.setLayout(new GridLayout(1, false)); + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + + checkEditor = new CheckTableEditor(composite, SWT.NULL); + checkEditor.configure(); + checkEditor.disableEditControls(); + checkEditor.disableEditControls(); + + getTabItem().setControl(composite); + } + + + /** + * Column用ContentProvider + * + * @author daisuke + */ + private class CheckContentProvider extends ArrayContentProvider implements CommandListener { + + private Viewer viewer; + + + public void commandExecuted(Command command) { + logger.debug("CheckContentProvider: commandExecuted"); +// if (evt.getPropertyName().equals(TableModel.P_ENTITY_TABLE_CHECKS)) { + checkEditor.refreshTable(); +// } else if (evt.getPropertyName().equals(CheckConstraintModel.P_CHECK_NAME)) { +// checkEditArea.refreshTable(); +// } else if (evt.getPropertyName().equals(CheckConstraintModel.P_CHECK_DEFINITION)) { +// checkEditArea.refreshTable(); +// } else if (evt.getSource() instanceof CheckConstraintModel) { +// checkEditArea.refreshTable(); +// if (evt.getPropertyName().equals(CheckConstraintModel.P_CREATE)) { +// // nothing to do +// } else if (evt.getPropertyName().equals(CheckConstraintModel.P_DELETE)) { +// ((AbstractModel) evt.getSource()).removePropertyChangeListener(this); +// } else if (evt.getPropertyName().equals(CheckConstraintModel.P_REVERT)) { +// ((AbstractModel) evt.getSource()).addPropertyChangeListener(this); // } -// }); -// txtCheckDefinition.addFocusListener(new TextSelectionAdapter(txtCheckDefinition)); -// txtCheckDefinition.addKeyListener(new KeyAdapter() { -// -// @Override -// public void keyReleased(KeyEvent e) { -// updateModel(); -// checkEditArea.refreshTable(); -// } -// }); -// } -// -// @Override -// protected void configureTable(final Table table) { -// super.configureTable(table); -// -// // THINK ↓要る? -//// final Menu menu = new Menu(table); -//// table.setMenu(menu); -//// menu.addMenuListener(new MenuAdapter() { -//// -//// @Override -//// public void menuShown(MenuEvent evt) { -//// for (MenuItem item : menu.getItems()) { -//// item.dispose(); -//// } -//// int index = table.getSelectionIndex(); -//// if (index == -1) { -//// return; -//// } -//// -//// MenuItem removeItem = new MenuItem(menu, SWT.PUSH); -//// removeItem.setText("&Remove"); // TODO 外部化せよ。 -//// removeItem.addSelectionListener(new SelectionAdapter() { -//// -//// @Override -//// public void widgetSelected(SelectionEvent evt) { -//// removeTableSelectionItem(); -//// } -//// }); -//// } -//// }); -// } -// -// @Override -// protected void configureTableViewer(TableViewer tableViewer) { -// tableViewer.setLabelProvider(new CheckLabelProvider()); -// contentProvider = new CheckContentProvider(); -// tableViewer.setContentProvider(contentProvider); -// tableViewer.setInput(tableModel.getChecks()); -// } -// -// @Override -// protected void createEditorControls(Composite parent) { -// Label label; -// -// Group group = new Group(parent, SWT.NULL); -// group.setText(JiemamyPlugin.getResourceString("dialog.table.check.title")); -// group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// group.setLayout(new GridLayout(1, false)); -// -// Composite cmpNames = new Composite(group, SWT.NULL); -// cmpNames.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// GridLayout layout = new GridLayout(4, false); -// layout.marginHeight = 0; -// layout.marginWidth = 0; -// cmpNames.setLayout(layout); -// -// label = new Label(cmpNames, SWT.NULL); -// label.setText(JiemamyPlugin.getResourceString("dialog.table.check.label.name")); -// -// txtCheckName = new Text(cmpNames, SWT.BORDER); -// txtCheckName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// -// label = new Label(cmpNames, SWT.NULL); -// label.setText(JiemamyPlugin.getResourceString("dialog.table.check.label.definition")); -// -// txtCheckDefinition = new Text(cmpNames, SWT.BORDER); -// txtCheckDefinition.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); -// -// return group; -// } -// -// @Override -// protected void createTableColumns(Table table) { -// TableColumn col = new TableColumn(table, SWT.LEFT); -// col.setText(JiemamyPlugin.getResourceString("dialog.table.check.tbl.header.name")); -// col.setWidth(200); -// -// col = new TableColumn(table, SWT.LEFT); -// col.setText(JiemamyPlugin.getResourceString("dialog.table.check.tbl.header.definition")); -// col.setWidth(500); -// } -// -// @Override -// protected void disableEditDetailControls() { -// txtCheckName.setText(""); -// txtCheckDefinition.setText(""); -// -// txtCheckName.setEnabled(false); -// txtCheckDefinition.setEnabled(false); -// } -// -// @Override -// protected void enableEditDetailControls(int index) { -// CheckConstraintModel check = tableModel.getCheck(index); -// -// // 現在値の設定 -// txtCheckName.setText(check.getName()); -// txtCheckDefinition.setText(check.getDefinition()); -// -// // 編集可否の設定 -// txtCheckName.setEnabled(true); -// txtCheckDefinition.setEnabled(true); -// } -// -// @Override -// protected JiemamyElement insertTableSelectionItem() { -// Table table = getTableViewer().getTable(); -// int index = table.getSelectionIndex(); -// CheckConstraintModel check = new CheckConstraintModel(); -// -// if (index < 0 || index > table.getItemCount()) { -// tableModel.addCheck(check); -// } else { -// tableModel.addCheck(index, check); // } -// -// int addedIndex = tableModel.getChecks().indexOf(check); -// table.setSelection(addedIndex); -// enableEditControls(addedIndex); -// txtCheckName.setFocus(); -// -// return check; -// } -// -// @Override -// protected void moveDownTableSelectionItem() { -// Table table = getTableViewer().getTable(); -// int index = table.getSelectionIndex(); -// if (index < 0 || index >= table.getItemCount()) { -// return; + } + + @Override + public void dispose() { + logger.debug("CheckContentProvider: disposed"); +// tableModel.removePropertyChangeListener(this); +// for (CheckConstraintModel check : tableModel.getChecks()) { +// ((AbstractModel) check).removePropertyChangeListener(this); // } -// -// tableModel.moveDownCheck(index); -// -// table.setSelection(index + 1); -// enableEditControls(index + 1); -// } -// -// @Override -// protected void moveUpTableSelectionItem() { -// Table table = getTableViewer().getTable(); -// int index = table.getSelectionIndex(); -// if (index <= 0 || index > table.getItemCount()) { -// return; + super.dispose(); + } + + public JiemamyElement getTargetModel() { + return (JiemamyElement) viewer.getInput(); + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + logger.debug("CheckContentProvider: input changed"); + logger.trace("oldInput: " + oldInput); + logger.trace("newInput: " + newInput); + + this.viewer = viewer; + +// if (oldInput != null) { +// tableModel.removePropertyChangeListener(this); +// for (CheckConstraintModel check : tableModel.getChecks()) { +// ((AbstractModel) check).removePropertyChangeListener(this); +// } // } -// -// tableModel.moveUpCheck(index); -// -// table.setSelection(index - 1); -// enableEditControls(index - 1); -// } -// -// @Override -// protected JiemamyElement removeTableSelectionItem() { -// TableViewer tableViewer = getTableViewer(); -// Table table = tableViewer.getTable(); -// int index = table.getSelectionIndex(); -// if (index < 0 || index > table.getItemCount()) { -// return null; +// if (newInput != null) { +// tableModel.addPropertyChangeListener(this); +// for (CheckConstraintModel check : tableModel.getChecks()) { +// ((AbstractModel) check).addPropertyChangeListener(this); +// } // } -// CheckConstraintModel checkToRemove = tableModel.removeCheck(table.getSelectionIndex()); -// tableViewer.remove(checkToRemove); -// table.setSelection(index); -// -// disableEditControls(); -// -// return checkToRemove; -// } -// -// private void updateModel() { -// int editIndex = getTableViewer().getTable().getSelectionIndex(); -// -// if (editIndex != -1) { -// CheckConstraintModel check = tableModel.getCheck(editIndex); -// check.setName(txtCheckName.getText()); -// check.setDefinition(txtCheckDefinition.getText()); -// } -// } -// } -// -// /** -// * Column用LabelProvider -// * -// * @author daisuke -// */ -// private class CheckLabelProvider extends BaseLabelProvider implements ITableLabelProvider { -// -// public Image getColumnImage(Object element, int columnIndex) { -// return null; -// } -// -// public String getColumnText(Object element, int columnIndex) { -// CheckConstraintModel check = (CheckConstraintModel) element; -// switch (columnIndex) { -// case 0: -// return check.getName(); + + super.inputChanged(viewer, oldInput, newInput); + } + + } + + /** + * チェック制約用LabelProvider + * + * @author daisuke + */ + private class CheckLabelProvider extends BaseLabelProvider implements ITableLabelProvider { + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + public String getColumnText(Object element, int columnIndex) { + CheckConstraintModel check = (CheckConstraintModel) element; + switch (columnIndex) { + case 0: + return check.getName(); + + case 1: + return check.getExpression(); + + default: + return StringUtils.EMPTY; + } + } + } + + private class CheckTableEditor extends AbstractTableEditor { + + private final Jiemamy jiemamy; + + private final List<TableCheckModel> checks; + + private Text txtCheckName; + + private Text txtCheckExpression; + + + public CheckTableEditor(Composite parent, int style) { + super(parent, style, new TableEditorConfigurator() { + + public String getAddLabel() { + return "追加"; // RESOURCE + } + + public String getEditorTitle() { + return "チェック制約情報"; // RESOURCE + } + + public String getInsertLabel() { + return "挿入"; // RESOURCE + } + + public String getRemoveLabel() { + return "削除"; // RESOURCE + } + }); + + jiemamy = tableModel.getJiemamy(); + checks = TableUtil.getAttributes(tableModel, TableCheckModel.class); + + assert jiemamy != null; + assert checks != null; + } + + @Override + protected JiemamyElement addItem() { + Table table = getTableViewer().getTable(); + JiemamyFactory factory = jiemamy.getFactory(); + TableCheckModel check = factory.newModel(TableCheckModel.class); + + checks.add(check); + tableModel.getAttributes().add(check); + + int addedIndex = checks.indexOf(check); + table.setSelection(addedIndex); + enableEditControls(addedIndex); + txtCheckName.setFocus(); + + return check; + } + + @Override + protected void configureEditorControls() { + txtCheckName.addFocusListener(new TextSelectionAdapter(txtCheckName)); + txtCheckName.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + updateModel(); + checkEditor.refreshTable(); + } + }); + txtCheckExpression.addFocusListener(new TextSelectionAdapter(txtCheckExpression)); + txtCheckExpression.addKeyListener(new KeyAdapter() { + + @Override + public void keyReleased(KeyEvent e) { + updateModel(); + checkEditor.refreshTable(); + } + }); + } + + @Override + protected void configureTable(final Table table) { + super.configureTable(table); + + // THINK ↓要る? +// final Menu menu = new Menu(table); +// table.setMenu(menu); +// menu.addMenuListener(new MenuAdapter() { +// +// @Override +// public void menuShown(MenuEvent evt) { +// for (MenuItem item : menu.getItems()) { +// item.dispose(); +// } +// int index = table.getSelectionIndex(); +// if (index == -1) { +// return; +// } // -// case 1: -// return check.getDefinition(); -// -// default: -// return ""; -// } -// } -// } -//} +// MenuItem removeItem = new MenuItem(menu, SWT.PUSH); +// removeItem.setText("&Remove"); // TODO 外部化せよ。 +// removeItem.addSelectionListener(new SelectionAdapter() { +// +// @Override +// public void widgetSelected(SelectionEvent evt) { +// removeTableSelectionItem(); +// } +// }); +// } +// }); + } + + @Override + protected void configureTableViewer(TableViewer tableViewer) { + tableViewer.setLabelProvider(new CheckLabelProvider()); + final CheckContentProvider contentProvider = new CheckContentProvider(); + tableViewer.setContentProvider(contentProvider); + tableViewer.setInput(checks); + + final EventBroker eventBroker = jiemamy.getEventBroker(); + eventBroker.addListener(contentProvider); + + // THINK んーーー?? このタイミングか? + tableViewer.getTable().addDisposeListener(new DisposeListener() { + + public void widgetDisposed(DisposeEvent e) { + eventBroker.removeListener(contentProvider); + } + + }); + } + + @Override + protected void createEditorControls(Composite parent) { + Label label; + + Composite cmpNames = new Composite(parent, SWT.NULL); + cmpNames.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + GridLayout layout = new GridLayout(4, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + cmpNames.setLayout(layout); + + label = new Label(cmpNames, SWT.NULL); + label.setText("制約名"); // RESOURCE + + txtCheckName = new Text(cmpNames, SWT.BORDER); + txtCheckName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + label = new Label(cmpNames, SWT.NULL); + label.setText("チェック制約式"); // RESOURCE + + txtCheckExpression = new Text(cmpNames, SWT.BORDER); + txtCheckExpression.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + } + + @Override + protected void createTableColumns(Table table) { + TableColumn colName = new TableColumn(table, SWT.LEFT); + colName.setText("制約名"); // RESOURCE + colName.setWidth(200); + + TableColumn colExpression = new TableColumn(table, SWT.LEFT); + colExpression.setText("チェック制約式"); // RESOURCE + colExpression.setWidth(500); + } + + @Override + protected void disableEditDetailControls() { + txtCheckName.setText(StringUtils.EMPTY); + txtCheckExpression.setText(StringUtils.EMPTY); + + txtCheckName.setEnabled(false); + txtCheckExpression.setEnabled(false); + } + + @Override + protected void enableEditDetailControls(int index) { + CheckConstraintModel check = checks.get(index); + + txtCheckName.setEnabled(true); + txtCheckExpression.setEnabled(true); + + // 現在値の設定 + txtCheckName.setText(StringUtils.defaultIfEmpty(check.getName(), "")); + txtCheckExpression.setText(StringUtils.defaultIfEmpty(check.getExpression(), "")); + } + + @Override + protected JiemamyElement insertTableSelectionItem() { + Table table = getTableViewer().getTable(); + int index = table.getSelectionIndex(); + + JiemamyFactory factory = jiemamy.getFactory(); + TableCheckModel checkModel = factory.newModel(TableCheckModel.class); + + if (index < 0 || index > table.getItemCount()) { + tableModel.getAttributes().add(checkModel); + checks.add(checkModel); + } else { + // FIXME attributesに対しては、indexを調整しないと。 + tableModel.getAttributes().add(index, checkModel); + checks.add(index, checkModel); + } + + int addedIndex = checks.indexOf(checkModel); + table.setSelection(addedIndex); + enableEditControls(addedIndex); + txtCheckName.setFocus(); + + return checkModel; + } + + @Override + protected void moveDownTableSelectionItem() { + Table table = getTableViewer().getTable(); + int index = table.getSelectionIndex(); + if (index < 0 || index >= table.getItemCount()) { + return; + } + + // FIXME attributesに対しては、indexを調整しないと。 + ListUtils.moveDown(tableModel.getAttributes(), index); + ListUtils.moveDown(checks, index); + + table.setSelection(index + 1); + enableEditControls(index + 1); + } + + @Override + protected void moveUpTableSelectionItem() { + Table table = getTableViewer().getTable(); + int index = table.getSelectionIndex(); + if (index <= 0 || index > table.getItemCount()) { + return; + } + + // FIXME attributesに対しては、indexを調整しないと。 + ListUtils.moveUp(tableModel.getAttributes(), index); + ListUtils.moveUp(checks, index); + + table.setSelection(index - 1); + enableEditControls(index - 1); + } + + @Override + protected JiemamyElement removeTableSelectionItem() { + TableViewer tableViewer = getTableViewer(); + Table table = tableViewer.getTable(); + int index = table.getSelectionIndex(); + if (index < 0 || index > table.getItemCount()) { + return null; + } + TableCheckModel checkToRemove = checks.remove(index); + tableModel.getAttributes().remove(checkToRemove); + tableViewer.remove(checkToRemove); + table.setSelection(index); + + disableEditControls(); + + return checkToRemove; + } + + private void updateModel() { + int editIndex = getTableViewer().getTable().getSelectionIndex(); + + if (editIndex != -1) { + CheckConstraintModel check = checks.get(editIndex); + check.setName(StringUtils.defaultIfEmpty(txtCheckName.getText(), null)); + check.setExpression(txtCheckExpression.getText()); + } + } + } +} Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java 2009-02-19 13:34:12 UTC (rev 2690) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java 2009-02-19 14:03:33 UTC (rev 2691) @@ -29,6 +29,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.SelectionAdapter; @@ -48,6 +50,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.jiemamy.EventBroker; import org.jiemamy.Jiemamy; import org.jiemamy.JiemamyFactory; import org.jiemamy.dialect.Dialect; @@ -84,7 +87,7 @@ import org.jiemamy.utils.model.TableUtil; /** - * テーブル編集ダイアログの「カラム」タブ + * テーブル編集ダイアログの「カラム」タブ。 * * @author daisuke */ @@ -92,16 +95,14 @@ private static Logger logger = LoggerFactory.getLogger(TableEditDialogColumnTab.class); - private RootModel rootModel; + private final RootModel rootModel; - private TableModel tableModel; + private final TableModel tableModel; private List<BuiltinDataTypeMold> allTypes; private AbstractTableEditor columnEditor; - private ColumnContentProvider contentProvider; - /** * インスタンスを生成する。 @@ -133,7 +134,7 @@ composite.setLayout(new GridLayout(1, false)); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - columnEditor = new ColumnTableEditor(composite, SWT.NULL, tableModel); + columnEditor = new ColumnTableEditor(composite, SWT.NULL); columnEditor.configure(); columnEditor.disableEditControls(); @@ -151,10 +152,8 @@ private Viewer viewer; - /** - * {@inheritDoc} - */ public void commandExecuted(Command command) { + logger.debug("ColumnContentProvider: commandExecuted"); // if (evt.getPropertyName().equals(TableModel.P_ENTITY_TABLE_COLUMNS)) { columnEditor.refreshTable(); // レコードの変更を反映させる。 // } else if (evt.getSource() instanceof DefinitionModel) { @@ -179,9 +178,6 @@ super.dispose(); } - /** - * {@inheritDoc} - */ public JiemamyElement getTargetModel() { return (JiemamyElement) viewer.getInput(); } @@ -267,36 +263,36 @@ private class ColumnTableEditor extends AbstractTableEditor { - private Jiemamy jiemamy; + private final Jiemamy jiemamy; - private final List<ColumnModel> columns; - private Dialect dialect; + private final List<ColumnModel> columns; + private Text txtColumnName; private Text txtColumnLogicalName; - private Text txtCheckExpression; - - private Text txtCheckName; - private Combo cmbColumnType; private Text txtColumnSize; + private Text txtCheckName; + + private Text txtCheckExpression; + private Text txtDefaultValue; - private Text txtDescription; + private Button chkIsNotNull; private Button chkIsPK; private Button chkIsUnique; - private Button chkIsNotNull; - private Button chkIsTypical; + private Text txtDescription; + /** * インスタンスを生成する。 @@ -305,7 +301,7 @@ * @param style * @param tableModel */ - public ColumnTableEditor(Composite parent, int style, TableModel tableModel) { + public ColumnTableEditor(Composite parent, int style) { super(parent, style, new TableEditorConfigurator() { public String getAddLabel() { @@ -487,19 +483,6 @@ protected void configureTable(final Table table) { super.configureTable(table); - table.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent e) { - int index = table.getSelectionIndex(); - if (index >= 0) { - enableEditDetailControls(index); - } else { - disableEditDetailControls(); - } - } - }); - // THINK ↓要る? // final Menu menu = new Menu(table); // table.setMenu(menu); @@ -531,9 +514,21 @@ @Override protected void configureTableViewer(TableViewer tableViewer) { tableViewer.setLabelProvider(new ColumnLabelProvider()); - contentProvider = new ColumnContentProvider(); + final ColumnContentProvider contentProvider = new ColumnContentProvider(); tableViewer.setContentProvider(contentProvider); tableViewer.setInput(columns); + + final EventBroker eventBroker = jiemamy.getEventBroker(); + eventBroker.addListener(contentProvider); + + // THINK んーーー?? このタイミングか? + tableViewer.getTable().addDisposeListener(new DisposeListener() { + + public void widgetDisposed(DisposeEvent e) { + eventBroker.removeListener(contentProvider); + } + + }); } @Override @@ -640,33 +635,33 @@ @Override protected void createTableColumns(Table table) { - TableColumn col = new TableColumn(table, SWT.LEFT); - col.setText(StringUtils.EMPTY); - col.setWidth(20); + TableColumn colMark = new TableColumn(table, SWT.LEFT); + colMark.setText(StringUtils.EMPTY); + colMark.setWidth(20); - col = new TableColumn(table, SWT.LEFT); - col.setText("カラム名"); // RESOURCE - col.setWidth(200); + TableColumn colName = new TableColumn(table, SWT.LEFT); + colName.setText("カラム名"); // RESOURCE + colName.setWidth(200); - col = new TableColumn(table, SWT.LEFT); - col.setText("データ型"); // RESOURCE - col.setWidth(150); + TableColumn colType = new TableColumn(table, SWT.LEFT); + colType.setText("データ型"); // RESOURCE + colType.setWidth(150); - col = new TableColumn(table, SWT.LEFT); - col.setText("デフォルト値"); // RESOURCE - col.setWidth(150); + TableColumn colDefault = new TableColumn(table, SWT.LEFT); + colDefault.setText("デフォルト値"); // RESOURCE + colDefault.setWidth(150); - col = new TableColumn(table, SWT.LEFT); - col.setText("PK"); // RESOURCE - col.setWidth(30); + TableColumn colPrimaryKey = new TableColumn(table, SWT.LEFT); + colPrimaryKey.setText("PK"); // RESOURCE + colPrimaryKey.setWidth(30); - col = new TableColumn(table, SWT.LEFT); - col.setText("一意"); // RESOURCE - col.setWidth(30); + TableColumn colUniqueKey = new TableColumn(table, SWT.LEFT); + colUniqueKey.setText("UK"); // RESOURCE + colUniqueKey.setWidth(30); - col = new TableColumn(table, SWT.LEFT); - col.setText("NN"); - col.setWidth(30); + TableColumn colNotNull = new TableColumn(table, SWT.LEFT); + colNotNull.setText("NN"); + colNotNull.setWidth(30); } @Override