[Jiemamy-notify:1475] commit [2700] データベース編集ダイアログ・データセットタブの表示。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 2月 21日 (土) 15:24:27 JST


Revision: 2700
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2700
Author:   daisuke_m
Date:     2009-02-21 15:24:26 +0900 (Sat, 21 Feb 2009)

Log Message:
-----------
データベース編集ダイアログ・データセットタブの表示。

Modified Paths:
--------------
    vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialog.java

Added Paths:
-----------
    vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDataSetTab.java


-------------- next part --------------
Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialog.java
===================================================================
--- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialog.java	2009-02-21 06:23:52 UTC (rev 2699)
+++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialog.java	2009-02-21 06:24:26 UTC (rev 2700)
@@ -62,6 +62,9 @@
 	@SuppressWarnings("unused")
 	private RootEditDialogDomainTab tabDomain;
 	
+	@SuppressWarnings("unused")
+	private RootEditDialogDataSetTab tabDataSet;
+	
 	/** 開始スクリプト入力欄 */
 	private TextEditTab tabBeginScript;
 	
@@ -135,15 +138,18 @@
 		// ---- B-1. Domains
 		tabDomain = new RootEditDialogDomainTab(tabFolder, SWT.NONE, rootModel);
 		
-		// ---- B-2. BeginScript
+		// ---- B-2. DataSets
+		tabDataSet = new RootEditDialogDataSetTab(tabFolder, SWT.NONE, rootModel);
+		
+		// ---- B-3. BeginScript
 		String beginScript = StringUtils.defaultIfEmpty(rootModel.getBeginScript(), "");
 		tabBeginScript = new TextEditTab(tabFolder, Messages.Tab_BeginScript, beginScript);
 		
-		// ---- B-3. EndScript
+		// ---- B-4. EndScript
 		String endScript = StringUtils.defaultIfEmpty(rootModel.getEndScript(), "");
 		tabEndScript = new TextEditTab(tabFolder, Messages.Tab_EndScript, endScript);
 		
-		// ---- B-4. Description
+		// ---- B-5. Description
 		String description = StringUtils.defaultIfEmpty(rootModel.getDescription(), "");
 		tabDescription = new TextEditTab(tabFolder, Messages.Tab_Description, description);
 		

Added: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDataSetTab.java
===================================================================
--- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDataSetTab.java	                        (rev 0)
+++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDataSetTab.java	2009-02-21 06:24:26 UTC (rev 2700)
@@ -0,0 +1,445 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2009/02/18
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.eclipse.editor.dialog.root;
+
+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.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+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.RootModel;
+import org.jiemamy.model.dataset.DataSetModel;
+import org.jiemamy.utils.ListUtils;
+
+/**
+ * データベース編集ダイアログの「データセット」タブ。
+ * 
+ * @author daisuke
+ */
+public class RootEditDialogDataSetTab extends AbstractTab {
+	
+	private static Logger logger = LoggerFactory.getLogger(RootEditDialogDataSetTab.class);
+	
+	private RootModel rootModel;
+	
+	private AbstractTableEditor dataSetEditor;
+	
+
+	/**
+	 * インスタンスを生成する。
+	 * 
+	 * @param parentTabFolder
+	 * @param style
+	 * @param rootModel
+	 */
+	public RootEditDialogDataSetTab(TabFolder parentTabFolder, int style, RootModel rootModel) {
+		super(parentTabFolder, style, "データセット"); // RESOURCE
+		
+		this.rootModel = rootModel;
+		
+		Composite composite = new Composite(parentTabFolder, SWT.NULL);
+		composite.setLayout(new GridLayout(1, false));
+		composite.setLayoutData(new GridData(GridData.FILL_BOTH));
+		
+		dataSetEditor = new DataSetTableEditor(composite, SWT.NULL);
+		dataSetEditor.configure();
+		dataSetEditor.disableEditControls();
+		
+		getTabItem().setControl(composite);
+	}
+	
+
+	/**
+	 * DataSet用ContentProvider
+	 * 
+	 * @author daisuke
+	 */
+	private class DataSetContentProvider extends ArrayContentProvider implements CommandListener {
+		
+		private Viewer viewer;
+		
+
+		public void commandExecuted(Command command) {
+			logger.debug("DataSetContentProvider: commandExecuted");
+//			if (evt.getPropertyName().equals(TableModel.P_ENTITY_TABLE_CHECKS)) {
+			dataSetEditor.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() {
+			logger.debug("DataSetContentProvider: disposed");
+//			tableModel.removePropertyChangeListener(this);
+//			for (CheckConstraintModel check : tableModel.getChecks()) {
+//				((AbstractModel) check).removePropertyChangeListener(this);
+//			}
+			super.dispose();
+		}
+		
+		public JiemamyElement getTargetModel() {
+			return (JiemamyElement) viewer.getInput();
+		}
+		
+		@Override
+		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+			logger.debug("DataSetContentProvider: 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);
+//				}
+//			}
+//			if (newInput != null) {
+//				tableModel.addPropertyChangeListener(this);
+//				for (CheckConstraintModel check : tableModel.getChecks()) {
+//					((AbstractModel) check).addPropertyChangeListener(this);
+//				}
+//			}
+			
+			super.inputChanged(viewer, oldInput, newInput);
+		}
+		
+	}
+	
+	/**
+	 * DataSet用LabelProvider
+	 * 
+	 * @author daisuke
+	 */
+	private class DataSetLabelProvider extends BaseLabelProvider implements ITableLabelProvider {
+		
+		public Image getColumnImage(Object element, int columnIndex) {
+			return null;
+		}
+		
+		public String getColumnText(Object element, int columnIndex) {
+			DataSetModel dataSet = (DataSetModel) element;
+			switch (columnIndex) {
+				case 0:
+					return dataSet.getName();
+					
+				default:
+					return StringUtils.EMPTY;
+			}
+		}
+	}
+	
+	private class DataSetTableEditor extends AbstractTableEditor {
+		
+		private final Jiemamy jiemamy;
+		
+		private final List<DataSetModel> dataSets;
+		
+		private Text txtDataSetName;
+		
+		private Button btnEdit;
+		
+
+		public DataSetTableEditor(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 = rootModel.getJiemamy();
+			dataSets = rootModel.getDataSets();
+			
+			assert jiemamy != null;
+			assert dataSets != null;
+		}
+		
+		@Override
+		protected JiemamyElement addItem() {
+			Table table = getTableViewer().getTable();
+			JiemamyFactory factory = jiemamy.getFactory();
+			DataSetModel dataSet = factory.newModel(DataSetModel.class);
+			
+			dataSets.add(dataSet);
+			
+			int addedIndex = dataSets.indexOf(dataSet);
+			table.setSelection(addedIndex);
+			enableEditControls(addedIndex);
+			txtDataSetName.setFocus();
+			
+			return dataSet;
+		}
+		
+		@Override
+		protected void configureEditorControls() {
+			txtDataSetName.addFocusListener(new TextSelectionAdapter(txtDataSetName));
+			txtDataSetName.addKeyListener(new KeyAdapter() {
+				
+				@Override
+				public void keyReleased(KeyEvent e) {
+					updateModel();
+					dataSetEditor.refreshTable();
+				}
+			});
+			btnEdit.addSelectionListener(new SelectionAdapter() {
+				
+				@Override
+				public void widgetSelected(SelectionEvent e) {
+					// UNDONE
+					logger.info("edit data set");
+				}
+			});
+		}
+		
+		@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 DataSetLabelProvider());
+			final DataSetContentProvider contentProvider = new DataSetContentProvider();
+			tableViewer.setContentProvider(contentProvider);
+			tableViewer.setInput(dataSets);
+			
+			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(3, false);
+			layout.marginHeight = 0;
+			layout.marginWidth = 0;
+			cmpNames.setLayout(layout);
+			
+			label = new Label(cmpNames, SWT.NULL);
+			label.setText("データセット名"); // RESOURCE
+			
+			txtDataSetName = new Text(cmpNames, SWT.BORDER);
+			txtDataSetName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+			
+			btnEdit = new Button(cmpNames, SWT.PUSH);
+			btnEdit.setText("編集"); // RESOURCE
+		}
+		
+		@Override
+		protected void createTableColumns(Table table) {
+			TableColumn colName = new TableColumn(table, SWT.LEFT);
+			colName.setText("データセット名"); // RESOURCE
+			colName.setWidth(200);
+		}
+		
+		@Override
+		protected void disableEditDetailControls() {
+			txtDataSetName.setText(StringUtils.EMPTY);
+			btnEdit.setText(StringUtils.EMPTY);
+			
+			txtDataSetName.setEnabled(false);
+			btnEdit.setEnabled(false);
+		}
+		
+		@Override
+		protected void enableEditDetailControls(int index) {
+			DataSetModel dataSet = dataSets.get(index);
+			
+			txtDataSetName.setEnabled(true);
+			btnEdit.setEnabled(true);
+			
+			// 現在値の設定
+			txtDataSetName.setText(StringUtils.defaultIfEmpty(dataSet.getName(), ""));
+		}
+		
+		@Override
+		protected JiemamyElement insertTableSelectionItem() {
+			Table table = getTableViewer().getTable();
+			int index = table.getSelectionIndex();
+			
+			JiemamyFactory factory = jiemamy.getFactory();
+			DataSetModel checkModel = factory.newModel(DataSetModel.class);
+			
+			if (index < 0 || index > table.getItemCount()) {
+				dataSets.add(checkModel);
+			} else {
+				dataSets.add(index, checkModel);
+			}
+			
+			int addedIndex = dataSets.indexOf(checkModel);
+			table.setSelection(addedIndex);
+			enableEditControls(addedIndex);
+			txtDataSetName.setFocus();
+			
+			return checkModel;
+		}
+		
+		@Override
+		protected void moveDownTableSelectionItem() {
+			Table table = getTableViewer().getTable();
+			int index = table.getSelectionIndex();
+			if (index < 0 || index >= table.getItemCount()) {
+				return;
+			}
+			
+			ListUtils.moveDown(dataSets, 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;
+			}
+			
+			ListUtils.moveUp(dataSets, 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;
+			}
+			DataSetModel checkToRemove = dataSets.remove(index);
+			tableViewer.remove(checkToRemove);
+			table.setSelection(index);
+			
+			disableEditControls();
+			
+			return checkToRemove;
+		}
+		
+		private void updateModel() {
+			int editIndex = getTableViewer().getTable().getSelectionIndex();
+			
+			if (editIndex != -1) {
+				DataSetModel check = dataSets.get(editIndex);
+				check.setName(StringUtils.defaultIfEmpty(txtDataSetName.getText(), null));
+			}
+		}
+	}
+}


Property changes on: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDataSetTab.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



Jiemamy-notify メーリングリストの案内
Back to archive index