svnno****@sourc*****
svnno****@sourc*****
2009年 2月 24日 (火) 22:28:20 JST
Revision: 2728 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2728 Author: daisuke_m Date: 2009-02-24 22:28:20 +0900 (Tue, 24 Feb 2009) Log Message: ----------- ダイアグラム上で、データ型の表示に対応。 / refactor Modified Paths: -------------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/TableEditPart.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/ColumnFigure.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/CompartmentFigure.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/TableFigure.java vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/utils/LabelStringUtil.java -------------- next part -------------- Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java 2009-02-24 12:55:39 UTC (rev 2727) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/DefaultDataTypeResolver.java 2009-02-24 13:28:20 UTC (rev 2728) @@ -85,6 +85,7 @@ tokens.add(Separator.LEFT_PAREN); tokens.add(new Literal(prec)); if (scale != null) { + tokens.add(Separator.COMMA); tokens.add(new Literal(scale)); } tokens.add(Separator.RIGHT_PAREN); Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java 2009-02-24 12:55:39 UTC (rev 2727) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/formatter/DefaultSqlFormatter.java 2009-02-24 13:28:20 UTC (rev 2728) @@ -30,10 +30,10 @@ public class DefaultSqlFormatter implements SqlFormatter { /** 空白文字 */ - private static final String WHITESPACE = " "; + public static final String WHITESPACE = " "; - private static boolean isSeparator(Token token) { + public static boolean isSeparator(Token token) { return token instanceof Separator; } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/TableEditPart.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/TableEditPart.java 2009-02-24 12:55:39 UTC (rev 2727) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/editpart/diagram/TableEditPart.java 2009-02-24 13:28:20 UTC (rev 2728) @@ -160,10 +160,7 @@ tableFigure.removeAllColumns(); for (ColumnModel column : TableUtil.getColumns(tableModel)) { - ColumnFigure[] columnFigure = createColumnFigure(column); - if (columnFigure != null && columnFigure.length > 0) { - tableFigure.add(columnFigure); - } + tableFigure.add(createColumnFigure(column)); } } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/ColumnFigure.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/ColumnFigure.java 2009-02-24 12:55:39 UTC (rev 2727) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/ColumnFigure.java 2009-02-24 13:28:20 UTC (rev 2728) @@ -65,8 +65,12 @@ if (underline && getText().length() != 0) { Rectangle bounds = getBounds(); - graphics.drawLine(bounds.x + 1 + HORIZONTAL_MARGIN, bounds.y + bounds.height - 2, bounds.x + bounds.width - - 2 - HORIZONTAL_MARGIN, bounds.y + bounds.height - 2); + + int x1 = bounds.x + 1 + HORIZONTAL_MARGIN; + int x2 = bounds.x + bounds.width - 2 - HORIZONTAL_MARGIN; + int y = bounds.y + bounds.height - 2; + + graphics.drawLine(x1, y, x2, y); } } } Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/CompartmentFigure.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/CompartmentFigure.java 2009-02-24 12:55:39 UTC (rev 2727) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/CompartmentFigure.java 2009-02-24 13:28:20 UTC (rev 2728) @@ -23,6 +23,7 @@ /** * {@link TableFigure}に包含されるFigure(ビュー)。 + * * @author daisuke */ public class CompartmentFigure extends Figure { Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/TableFigure.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/TableFigure.java 2009-02-24 12:55:39 UTC (rev 2727) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/figure/TableFigure.java 2009-02-24 13:28:20 UTC (rev 2728) @@ -21,6 +21,7 @@ import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.Figure; import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Label; import org.eclipse.draw2d.LineBorder; import org.eclipse.draw2d.ToolbarLayout; import org.eclipse.jface.resource.ImageRegistry; @@ -29,19 +30,20 @@ import org.jiemamy.eclipse.Images; import org.jiemamy.eclipse.JiemamyPlugin; import org.jiemamy.eclipse.utils.SwtColorUtil; +import org.jiemamy.model.entity.TableModel; /** - * TableのFigure。 + * {@link TableModel}のFigure。 * * @author daisuke */ public class TableFigure extends EntityFigure { - private ColumnLayoutFigure columnFigure; + private ColumnLayoutFigure columnFigure = new ColumnLayoutFigure(); - private CompartmentFigure columnNameFigure; + private CompartmentFigure columnNameFigure = new CompartmentFigure(); - private CompartmentFigure columnTypeFigure; + private CompartmentFigure columnTypeFigure = new CompartmentFigure(); private FigureType nextFigure = FigureType.NAME; @@ -52,19 +54,17 @@ public TableFigure() { super(ColorConstants.tooltipBackground); - columnFigure = new ColumnLayoutFigure(); - columnNameFigure = new CompartmentFigure(); - columnTypeFigure = new CompartmentFigure(); - + Label entityNameLabel = getEntityNameLabel(); ImageRegistry ir = JiemamyPlugin.getDefault().getImageRegistry(); - getEntityNameLabel().setIcon(ir.get(Images.LABEL_TABLE)); + entityNameLabel.setIcon(ir.get(Images.LABEL_TABLE)); + setLayoutManager(new ToolbarLayout()); setBorder(new LineBorder(ColorConstants.black, 1)); setBackgroundColor(getDefaultColor()); setOpaque(true); - add(getEntityNameLabel()); + add(entityNameLabel); add(columnFigure); columnFigure.add(columnNameFigure); @@ -74,35 +74,21 @@ /** * フィギュアを追加する。 * - *<p> 配列0に左(カラム名)、配列1に右(型)のFigureを渡す。</p> + * <p>配列[0]に左(カラム名)、配列[1]に右(型)のFigureを渡す。</p> * * @param figures 追加するフィギュアの配列 + * @throws IllegalArgumentException 配列のサイズが2ではない場合 */ public void add(ColumnFigure[] figures) { if (figures.length != 2) { throw new IllegalArgumentException(); } - add(figures[0]); - add(figures[1]); + columnNameFigure.add(figures[0]); + columnTypeFigure.add(figures[1]); } @Override - public void add(IFigure figure, Object constraint, int index) { - if (figure instanceof ColumnFigure) { - if (nextFigure == FigureType.NAME) { - columnNameFigure.add(figure); - nextFigure = FigureType.DATA_TYPE; - } else if (nextFigure == FigureType.DATA_TYPE) { - columnTypeFigure.add(figure); - nextFigure = FigureType.NAME; - } - } else { - super.add(figure, constraint, index); - } - } - - @Override public void remove(IFigure figure) { if (figure instanceof ColumnFigure) { columnNameFigure.remove(figure); Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/utils/LabelStringUtil.java =================================================================== --- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/utils/LabelStringUtil.java 2009-02-24 12:55:39 UTC (rev 2727) +++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/utils/LabelStringUtil.java 2009-02-24 13:28:20 UTC (rev 2728) @@ -18,8 +18,13 @@ */ package org.jiemamy.eclipse.editor.utils; +import java.util.List; + +import org.jiemamy.ReferenceResolver; +import org.jiemamy.dialect.Dialect; import org.jiemamy.eclipse.editor.DisplayPlace; import org.jiemamy.eclipse.editor.DisplayTarget; +import org.jiemamy.formatter.DefaultSqlFormatter; import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; import org.jiemamy.model.attribute.ColumnModel; @@ -27,6 +32,10 @@ import org.jiemamy.model.datatype.DataType; import org.jiemamy.model.datatype.DomainModel; import org.jiemamy.model.entity.EntityModel; +import org.jiemamy.model.sql.Separator; +import org.jiemamy.model.sql.Token; +import org.jiemamy.utils.model.DataTypeUtil; +import org.jiemamy.utils.model.RootModelUtil; /** * TODO for daisuke @@ -46,8 +55,24 @@ */ public static String getString(RootModel rootModel, DataType dataType, DisplayTarget displayTarget, DisplayPlace place) { - // TODO Auto-generated method stub - return null; + ReferenceResolver resolver = rootModel.getJiemamy().getReferenceResolver(); + try { + Dialect dialect = RootModelUtil.getDialect(rootModel); + List<Token> tokens = dialect.getDataTypeResolver().resolveDataType(dataType, resolver); + StringBuilder sb = new StringBuilder(); + Token lastToken = null; + for (Token token : tokens) { + if ((DefaultSqlFormatter.isSeparator(lastToken) == false && DefaultSqlFormatter.isSeparator(token) == false) + || lastToken == null || lastToken.equals(Separator.COMMA)) { + sb.append(DefaultSqlFormatter.WHITESPACE); + } + sb.append(token); + lastToken = token; + } + return sb.toString(); + } catch (ClassNotFoundException e) { + return DataTypeUtil.toBuiltinDataType(dataType, resolver).getTypeName(); + } } /**