[Jiemamy-notify:1489] commit [2712] CreateNodeCommandをファサードに対応してみた。

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 2月 23日 (月) 02:00:34 JST


Revision: 2712
          http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2712
Author:   shin1
Date:     2009-02-23 02:00:34 +0900 (Mon, 23 Feb 2009)

Log Message:
-----------
CreateNodeCommandをファサードに対応してみた。
が、Undoがまだ動作しない(CommandProcessor#process()内でInvocationTargetExceptionが投げられてしまう)

Modified Paths:
--------------
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/JiemamyFacadeImpl.java
    artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/CommandProcessorImpl.java
    artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/JiemamyViewFacadeImpl.java
    vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/command/CreateNodeCommand.java

Added Paths:
-----------
    artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/
    artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/AddProfileToDiaglamCommand.java
    artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/DeleteProfileFromDiaglamCommand.java


-------------- next part --------------
Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/JiemamyFacadeImpl.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/JiemamyFacadeImpl.java	2009-02-22 15:39:20 UTC (rev 2711)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/JiemamyFacadeImpl.java	2009-02-22 17:00:34 UTC (rev 2712)
@@ -76,7 +76,7 @@
 	}
 	
 	public void redo() {
-		if (redoStack.isEmpty() == false) {
+		if (redoStack.isEmpty()) {
 			return;
 		}
 		Command command = redoStack.pop();
@@ -84,7 +84,7 @@
 	}
 	
 	public void undo() {
-		if (undoStack.isEmpty() == false) {
+		if (undoStack.isEmpty()) {
 			return;
 		}
 		Command command = undoStack.pop();

Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/CommandProcessorImpl.java
===================================================================
--- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/CommandProcessorImpl.java	2009-02-22 15:39:20 UTC (rev 2711)
+++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/CommandProcessorImpl.java	2009-02-22 17:00:34 UTC (rev 2712)
@@ -65,7 +65,8 @@
  */
 public class CommandProcessorImpl implements CommandProcessor {
 	
-	final EventBroker eventBroker;
+	/** サブクラスからも見える必要がある。 */
+	protected final EventBroker eventBroker;
 	
 
 	/**
@@ -169,7 +170,7 @@
 		// 実行時に無理矢理ディスパッチする…。
 		Method method;
 		try {
-			method = CommandProcessorImpl.class.getMethod("process", command.getClass());
+			method = getClass().getMethod("process", command.getClass());
 			method.invoke(this, command);
 		} catch (SecurityException e) {
 			throw new JiemamyRuntimeException(e);

Modified: artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/JiemamyViewFacadeImpl.java
===================================================================
--- artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/JiemamyViewFacadeImpl.java	2009-02-22 15:39:20 UTC (rev 2711)
+++ artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/JiemamyViewFacadeImpl.java	2009-02-22 17:00:34 UTC (rev 2712)
@@ -18,6 +18,13 @@
  */
 package org.jiemamy;
 
+import java.util.Map;
+
+import org.jiemamy.editcommand.AddProfileToDiaglamCommand;
+import org.jiemamy.editcommand.Command;
+import org.jiemamy.editcommand.CommandProcessor;
+import org.jiemamy.editcommand.CommandProcessorImpl;
+import org.jiemamy.editcommand.DeleteProfileFromDiaglamCommand;
 import org.jiemamy.editcommand.impl.ModifyModelPropertyCommand;
 import org.jiemamy.model.DiagramPresentationModel;
 import org.jiemamy.model.DiagramPresentations;
@@ -26,12 +33,16 @@
 import org.jiemamy.model.node.NodeAdapter;
 
 /**
- * TODO for daisuke
+ * j-view用のコマンド実行ファサードクラス。
  * 
  * @author daisuke
+ * @author shin1ogawa
  */
 public class JiemamyViewFacadeImpl extends JiemamyFacadeImpl {
 	
+	private final CommandProcessor commandProcessor;
+	
+
 	/**
 	 * インスタンスを生成する。
 	 * 
@@ -39,9 +50,24 @@
 	 */
 	public JiemamyViewFacadeImpl(Jiemamy jiemamy) {
 		super(jiemamy);
+		// j-viewを対象としたコマンドを実行できるCommandProcessorの実装クラスをインスタンス化する。
+		commandProcessor = new ViewCommandProcessor(jiemamy.getEventBroker());
 	}
 	
 	/**
+	 * TODO for shin1ogawa
+	 * 
+	 * @param diagramIndex ダイアグラムエディタのインデックス(エディタ内のタブインデックス)
+	 * @param nodeAdapter ノードに対応する{@link NodeAdapter}
+	 * @param nodeProfile 追加する{@link NodeProfile}
+	 */
+	public void addNodeProfile(int diagramIndex, final NodeAdapter nodeAdapter, final NodeProfile nodeProfile) {
+		final Command command = new AddProfileToDiaglamCommand(getRootModel(), diagramIndex, nodeAdapter, nodeProfile);
+		command.execute(commandProcessor, undoStack);
+		redoStack.push(command);
+	}
+	
+	/**
 	 * TODO for daisuke
 	 * 
 	 * @param diagramIndex
@@ -51,14 +77,71 @@
 	public void changeNodeConstraint(int diagramIndex, NodeAdapter nodeAdapter, JmRectangle constraint) {
 		DiagramPresentations diagramPresentations = getRootModel().getAdapter(DiagramPresentations.class);
 		DiagramPresentationModel diagramPresentationModel = diagramPresentations.get(diagramIndex);
+		Map<NodeAdapter, NodeProfile> figureProfiles = diagramPresentationModel.getFigureProfiles();
+		if (figureProfiles.containsKey(nodeAdapter) == false) {
+			NodeProfile profile = jiemamy.getFactory().newModel(NodeProfile.class);
+			figureProfiles.put(nodeAdapter, profile);
+		}
+		NodeProfile nodeProfile = figureProfiles.get(nodeAdapter);
+		ModifyModelPropertyCommand redoCommand = new ModifyModelPropertyCommand(nodeProfile, "layout", constraint);
+		redoCommand.execute(commandProcessor, undoStack);
+		redoStack.push(redoCommand);
+	}
+	
+	/**
+	 * TODO for shin1ogawa
+	 * 
+	 * @param diagramIndex ダイアグラムエディタのインデックス(エディタ内のタブインデックス)
+	 * @param nodeAdapter ノードに対応する{@link NodeAdapter}
+	 */
+	public void deleteNodeProfile(int diagramIndex, final NodeAdapter nodeAdapter) {
+		final Command command = new DeleteProfileFromDiaglamCommand(getRootModel(), diagramIndex, nodeAdapter);
+		command.execute(commandProcessor, undoStack);
+		redoStack.push(command);
+	}
+	
+
+	/**
+	 * TODO for shin1ogawa
+	 * 
+	 * @author shin1ogawa
+	 */
+	public static class ViewCommandProcessor extends CommandProcessorImpl {
 		
-		NodeProfile nodeProfile = diagramPresentationModel.getFigureProfiles().get(nodeAdapter);
-		try {
-			new ModifyModelPropertyCommand(nodeProfile, "layout", constraint).execute(processor);
-		} catch (Exception e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
+		/**
+		 * インスタンスを生成する。
+		 * 
+		 * @param eventBroker
+		 */
+		public ViewCommandProcessor(EventBroker eventBroker) {
+			super(eventBroker);
 		}
+		
+		/**
+		 * TODO for shin1ogawa
+		 * 
+		 * @param command
+		 */
+		public void process(AddProfileToDiaglamCommand command) {
+			DiagramPresentationModel diagramPresentationModel =
+					command.getRoot().getAdapter(DiagramPresentations.class).get(command.getDiagramIndex());
+			diagramPresentationModel.getFigureProfiles().put(command.getNodeAdapter(), command.getNodeProfile());
+			eventBroker.fireCommandProcess(command);
+		}
+		
+		/**
+		 * TODO for shin1ogawa
+		 * 
+		 * @param command
+		 */
+		public void process(DeleteProfileFromDiaglamCommand command) {
+			DiagramPresentationModel diagramPresentationModel =
+					command.getRoot().getAdapter(DiagramPresentations.class).get(command.getDiagramIndex());
+			NodeProfile nodeProfile = diagramPresentationModel.getFigureProfiles().get(command.getNodeAdapter());
+			command.setNodeProfile(nodeProfile);
+			diagramPresentationModel.getFigureProfiles().remove(command.getNodeAdapter());
+			eventBroker.fireCommandProcess(command);
+		}
+		
 	}
-	
 }

Added: artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/AddProfileToDiaglamCommand.java
===================================================================
--- artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/AddProfileToDiaglamCommand.java	                        (rev 0)
+++ artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/AddProfileToDiaglamCommand.java	2009-02-22 17:00:34 UTC (rev 2712)
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2009/02/22
+ *
+ * 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.editcommand;
+
+import org.jiemamy.editcommand.impl.AbstractCommand;
+import org.jiemamy.model.DiagramPresentations;
+import org.jiemamy.model.JiemamyElement;
+import org.jiemamy.model.NodeProfile;
+import org.jiemamy.model.RootModel;
+import org.jiemamy.model.node.NodeAdapter;
+
+/**
+ * {@link RootModel}に登録された{@link DiagramPresentations}アダプタに{@link NodeProfile}を追加するコマンド。
+ * 
+ * @author shin1ogawa
+ * @see DeleteProfileFromDiaglamCommand
+ */
+public class AddProfileToDiaglamCommand extends AbstractCommand {
+	
+	final RootModel root;
+	
+	final NodeAdapter nodeAdapter;
+	
+	final NodeProfile nodeProfile;
+	
+	final int diagramIndex;
+	
+
+	/**
+	 * インスタンスを生成する。
+	 * 
+	 * @param root {@link DiagramPresentations}がアダプトされた{@link RootModel}
+	 * @param diagramIndex ダイアグラムエディタのタブインデックス
+	 * @param nodeAdapter ノードを識別するための{@link NodeAdapter}
+	 * @param nodeProfile ノードの見た目の情報を保持する{@link NodeProfile}
+	 */
+	public AddProfileToDiaglamCommand(RootModel root, int diagramIndex, NodeAdapter nodeAdapter, NodeProfile nodeProfile) {
+		super();
+		this.root = root;
+		this.diagramIndex = diagramIndex;
+		this.nodeAdapter = nodeAdapter;
+		this.nodeProfile = nodeProfile;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public Command execute(CommandProcessor processor) {
+		processor.process(this);
+		return new DeleteProfileFromDiaglamCommand(root, getDiagramIndex(), nodeAdapter);
+	}
+	
+	/**
+	 * @return the diagramIndex
+	 */
+	public int getDiagramIndex() {
+		return diagramIndex;
+	}
+	
+	/**
+	 * @return ノードを識別するための{@link NodeAdapter}
+	 */
+	public NodeAdapter getNodeAdapter() {
+		return nodeAdapter;
+	}
+	
+	/**
+	 * @return ノードの見た目の情報を保持する{@link NodeProfile}
+	 */
+	public NodeProfile getNodeProfile() {
+		return nodeProfile;
+	}
+	
+	/**
+	 * @return {@link DiagramPresentations}がアダプトされた{@link RootModel}
+	 */
+	public RootModel getRoot() {
+		return root;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public JiemamyElement getTarget() {
+		return getRoot();
+	}
+	
+}


Property changes on: artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/AddProfileToDiaglamCommand.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Added: artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/DeleteProfileFromDiaglamCommand.java
===================================================================
--- artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/DeleteProfileFromDiaglamCommand.java	                        (rev 0)
+++ artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/DeleteProfileFromDiaglamCommand.java	2009-02-22 17:00:34 UTC (rev 2712)
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2009/02/22
+ *
+ * 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.editcommand;
+
+import org.jiemamy.editcommand.impl.AbstractCommand;
+import org.jiemamy.model.DiagramPresentations;
+import org.jiemamy.model.JiemamyElement;
+import org.jiemamy.model.NodeProfile;
+import org.jiemamy.model.RootModel;
+import org.jiemamy.model.node.NodeAdapter;
+
+/**
+ * {@link RootModel}に登録された{@link DiagramPresentations}アダプタから{@link NodeProfile}を削除するコマンド。
+ * 
+ * @author shin1ogawa
+ * @see AddProfileToDiaglamCommand
+ */
+public class DeleteProfileFromDiaglamCommand extends AbstractCommand {
+	
+	final RootModel root;
+	
+	final NodeAdapter nodeAdapter;
+	
+	private NodeProfile nodeProfile;
+	
+	final int diagramIndex;
+	
+
+	/**
+	 * インスタンスを生成する。
+	 * 
+	 * @param root {@link DiagramPresentations}がアダプトされた{@link RootModel}
+	 * @param diagramIndex ダイアグラムエディタのタブインデックス
+	 * @param nodeAdapter ノードを識別するための{@link NodeAdapter}
+	 */
+	public DeleteProfileFromDiaglamCommand(RootModel root, int diagramIndex, NodeAdapter nodeAdapter) {
+		super();
+		this.root = root;
+		this.diagramIndex = diagramIndex;
+		this.nodeAdapter = nodeAdapter;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public Command execute(CommandProcessor processor) {
+		processor.process(this);
+		return new AddProfileToDiaglamCommand(root, getDiagramIndex(), nodeAdapter, getNodeProfile());
+	}
+	
+	/**
+	 * @return the diagramIndex
+	 */
+	public int getDiagramIndex() {
+		return diagramIndex;
+	}
+	
+	/**
+	 * @return ノードを識別するための{@link NodeAdapter}
+	 */
+	public NodeAdapter getNodeAdapter() {
+		return nodeAdapter;
+	}
+	
+	/**
+	 * @return ノードの見た目の情報を保持する{@link NodeProfile}
+	 */
+	public NodeProfile getNodeProfile() {
+		return nodeProfile;
+	}
+	
+	/**
+	 * @return {@link DiagramPresentations}がアダプトされた{@link RootModel}
+	 */
+	public RootModel getRoot() {
+		return root;
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	public JiemamyElement getTarget() {
+		return getRoot();
+	}
+	
+	/**
+	 * @param ノードの見た目の情報を保持する{@link NodeProfile}
+	 */
+	public void setNodeProfile(NodeProfile nodeProfile) {
+		this.nodeProfile = nodeProfile;
+	}
+	
+}


Property changes on: artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/editcommand/DeleteProfileFromDiaglamCommand.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/command/CreateNodeCommand.java
===================================================================
--- vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/command/CreateNodeCommand.java	2009-02-22 15:39:20 UTC (rev 2711)
+++ vesta/trunk/org.jiemamy.eclipse/src/main/java/org/jiemamy/eclipse/editor/command/CreateNodeCommand.java	2009-02-22 17:00:34 UTC (rev 2712)
@@ -18,17 +18,14 @@
  */
 package org.jiemamy.eclipse.editor.command;
 
-import java.util.Map;
-
 import org.eclipse.draw2d.geometry.Rectangle;
 import org.eclipse.gef.commands.Command;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import org.jiemamy.JiemamyFacadeImpl;
-import org.jiemamy.JiemamyFactory;
+import org.jiemamy.JiemamyViewFacadeImpl;
 import org.jiemamy.Migration;
 import org.jiemamy.eclipse.utils.ConvertUtil;
-import org.jiemamy.model.DiagramPresentationModel;
-import org.jiemamy.model.DiagramPresentations;
 import org.jiemamy.model.JiemamyElement;
 import org.jiemamy.model.NodeProfile;
 import org.jiemamy.model.RootModel;
@@ -40,13 +37,15 @@
  */
 public class CreateNodeCommand extends Command {
 	
+	private static Logger logger = LoggerFactory.getLogger(CreateNodeCommand.class);
+	
 	private RootModel rootModel;
 	
 	private JiemamyElement model;
 	
 	private Rectangle rectangle;
 	
-	private JiemamyFacadeImpl jiemamyFacade;
+	private JiemamyViewFacadeImpl jiemamyFacade;
 	
 
 	/**
@@ -59,7 +58,7 @@
 		this.rootModel = rootModel;
 		this.model = model;
 		this.rectangle = rectangle;
-		jiemamyFacade = new JiemamyFacadeImpl(model.getJiemamy());
+		jiemamyFacade = new JiemamyViewFacadeImpl(model.getJiemamy());
 	}
 	
 	/**
@@ -67,25 +66,15 @@
 	 */
 	@Override
 	public void execute() {
-		DiagramPresentations diagramPresentations = rootModel.getAdapter(DiagramPresentations.class);
-		DiagramPresentationModel presentation = diagramPresentations.get(Migration.DIAGRAM_INDEX);
-		NodeAdapter nodeAdapter;
-		if (model instanceof NodeAdapter) {
-			nodeAdapter = (NodeAdapter) model;
-		} else {
-			nodeAdapter = model.getAdapter(NodeAdapter.class);
-		}
-		Map<NodeAdapter, NodeProfile> figureProfiles = presentation.getFigureProfiles();
-		if (figureProfiles.containsKey(nodeAdapter) == false) {
-			JiemamyFactory factory = model.getJiemamy().getFactory();
-			NodeProfile profile = factory.newModel(NodeProfile.class);
-			figureProfiles.put(nodeAdapter, profile);
-		}
-		presentation.getFigureProfiles().get(nodeAdapter).setLayout(ConvertUtil.convert(rectangle));
-		// Command経由でモデルを追加するサンプル。
 		if (model instanceof EntityModel) {
 			EntityModel entityModel = (EntityModel) model;
 			jiemamyFacade.addEntity(entityModel);
+			NodeProfile nodeProfile = model.getJiemamy().getFactory().newModel(NodeProfile.class);
+			NodeAdapter nodeAdapter = model.getAdapter(NodeAdapter.class);
+			jiemamyFacade.addNodeProfile(Migration.DIAGRAM_INDEX, nodeAdapter, nodeProfile);
+			jiemamyFacade.changeNodeConstraint(Migration.DIAGRAM_INDEX, nodeAdapter, ConvertUtil.convert(rectangle));
+		} else {
+			logger.debug("EntitiModel以外は未実装状態");
 		}
 	}
 	
@@ -95,5 +84,7 @@
 	@Override
 	public void undo() {
 		jiemamyFacade.undo();
+		jiemamyFacade.undo();
+		jiemamyFacade.undo();
 	}
 }



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