[openrtm-commit:00672] r258 - in trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor: factory ui/editor/dnd ui/editor/editpolicy
openrtm @ openrtm.org
openrtm @ openrtm.org
2012年 2月 7日 (火) 23:48:47 JST
Author: sakamoto
Date: 2012-02-07 23:48:47 +0900 (Tue, 07 Feb 2012)
New Revision: 258
Modified:
trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/factory/ComponentCommandCreator.java
trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/dnd/ComponentFactory.java
trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/dnd/SystemDiagramDropTargetListener.java
trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/editpolicy/SystemXYLayoutEditPolicy.java
Log:
Modified for Multi DnD #2174
Modified: trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/factory/ComponentCommandCreator.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/factory/ComponentCommandCreator.java 2012-02-07 14:37:49 UTC (rev 257)
+++ trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/factory/ComponentCommandCreator.java 2012-02-07 14:48:47 UTC (rev 258)
@@ -15,6 +15,7 @@
import jp.go.aist.rtm.toolscommon.model.component.Component;
import jp.go.aist.rtm.toolscommon.model.component.ComponentSpecification;
import jp.go.aist.rtm.toolscommon.model.component.SystemDiagram;
+import static jp.go.aist.rtm.toolscommon.util.ComponentUtil.*;
public class ComponentCommandCreator {
@@ -38,8 +39,51 @@
return this.message;
}
- public CommandPair getCreateCommand(CreateRequest request,
+ public MultiCreateCommand getCreateCommand(CreateRequest request,
SystemDiagram diagram) {
+ MultiCreateCommand result = new MultiCreateCommand();
+
+ if (!List.class.isAssignableFrom((Class<?>) request.getNewObjectType())) {
+ return result;
+ }
+
+ List<?> components = (List<?>) request.getNewObject();
+ List<Component> childComponents = new ArrayList<Component>();
+ for (Object o : components) {
+ Component c = (Component) o;
+ if (c.isCompositeComponent()) {
+ childComponents.addAll(c.getAllComponents());
+ }
+ }
+
+ for (Object o : components) {
+ final Component c = (Component) o;
+ if (find(c, childComponents) != null) {
+ continue;
+ }
+ CreateRequest req = new CreateRequest() {
+ Component component = c;
+
+ @Override
+ public Object getNewObject() {
+ return component;
+ }
+
+ @Override
+ public Object getNewObjectType() {
+ return component.getClass();
+ }
+ };
+ CommandPair pair = createCommandPair(req, diagram);
+ if (pair != null) {
+ result.getCommandPairs().add(pair);
+ }
+ }
+ return result;
+ }
+
+ public CommandPair createCommandPair(CreateRequest request,
+ SystemDiagram diagram) {
CommandPair result = new CommandPair();
for (CreateComponentCommandExtension ext : creators) {
ext.setRequest(request);
@@ -125,4 +169,33 @@
creators.add(ext);
}
+ public static class MultiCreateCommand extends Command {
+ List<CommandPair> commandPairs;
+
+ public MultiCreateCommand() {
+ commandPairs = new ArrayList<CommandPair>();
+ }
+
+ public List<CommandPair> getCommandPairs() {
+ return commandPairs;
+ }
+
+ @Override
+ public boolean canExecute() {
+ for (CommandPair cp : commandPairs) {
+ if (!cp.command.canExecute()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void execute() {
+ for (CommandPair cp : commandPairs) {
+ cp.command.execute();
+ }
+ }
+ }
+
}
Modified: trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/dnd/ComponentFactory.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/dnd/ComponentFactory.java 2012-02-07 14:37:49 UTC (rev 257)
+++ trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/dnd/ComponentFactory.java 2012-02-07 14:48:47 UTC (rev 258)
@@ -1,5 +1,8 @@
package jp.go.aist.rtm.systemeditor.ui.editor.dnd;
+import java.util.ArrayList;
+import java.util.List;
+
import jp.go.aist.rtm.toolscommon.model.component.Component;
import org.eclipse.gef.requests.CreationFactory;
@@ -8,41 +11,31 @@
* ドラッグ&ドロップ時、コンポーネントを作成するファクトリ
*/
public class ComponentFactory implements CreationFactory {
- private Component component;
- /**
- * {@inheritDoc}
- */
- public Object getObjectType() {
- return component.getClass();
+ List<Component> components;
+
+ public ComponentFactory() {
+ components = new ArrayList<Component>();
}
- /**
- * コンポーネントのリモートオブジェクトを設定する
- *
- * @param remoteObject
- * コンポーネントのリモートオブジェクト
- */
- public void setComponent(Component component) {
- this.component = component;
+ public void addComponent(Component component) {
+ if (!components.contains(component)) {
+ components.add(component);
+ }
}
-
- /**
- * コンポーネントのリモートオブジェクトを設定する
- *
- * @param remoteObject
- * コンポーネントのリモートオブジェクト
- */
- protected Component getComponent() {
- return this.component;
+
+ @Override
+ public Object getObjectType() {
+ return components.getClass();
}
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("unchecked")
+
+ @Override
public Object getNewObject() {
- if (getComponent() != null) return getComponent().copy();
- return null;
+ List<Component> result = new ArrayList<Component>();
+ for (Component c : components) {
+ result.add(c.copy());
+ }
+ return (result.isEmpty()) ? null : result;
}
+
}
Modified: trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/dnd/SystemDiagramDropTargetListener.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/dnd/SystemDiagramDropTargetListener.java 2012-02-07 14:37:49 UTC (rev 257)
+++ trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/dnd/SystemDiagramDropTargetListener.java 2012-02-07 14:48:47 UTC (rev 258)
@@ -1,5 +1,9 @@
package jp.go.aist.rtm.systemeditor.ui.editor.dnd;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import jp.go.aist.rtm.nameserviceview.model.nameservice.NamingObjectNode;
import jp.go.aist.rtm.repositoryView.model.RTCRVLeafItem;
import jp.go.aist.rtm.toolscommon.model.component.Component;
@@ -21,6 +25,8 @@
public class SystemDiagramDropTargetListener extends
AbstractTransferDropTargetListener {
+ Boolean online = null;
+
/**
* コンストラクタ
*
@@ -31,6 +37,20 @@
super(viewer, LocalSelectionTransfer.getInstance());
}
+ public boolean isOnline() {
+ if (online == null) {
+ online = false;
+ if (getViewer().getRootEditPart().getContents().getModel() instanceof SystemDiagram) {
+ SystemDiagram sd = (SystemDiagram) getViewer().getRootEditPart()
+ .getContents().getModel();
+ if (SystemDiagramKind.ONLINE_LITERAL.equals(sd.getKind())) {
+ online = true;
+ }
+ }
+ }
+ return online;
+ }
+
@Override
protected void updateTargetRequest() {
((CreateRequest) getTargetRequest()).setLocation(getDropLocation());
@@ -39,28 +59,43 @@
@Override
protected Request createTargetRequest() {
ComponentFactory factory = new ComponentFactory();
- Component component = getComponent();
- setComponent(factory, component);
+ List<Component> components = getComponents();
+ setComponents(factory, components);
CreateRequest result = new CreateRequest(); // nullObjectとして返す。
result.setFactory(factory);
return result;
}
- private void setComponent(ComponentFactory factory, Component component) {
- if (component == null) return;
- factory.setComponent(component);
+ void setComponents(ComponentFactory factory, List<Component> components) {
+ if (components == null || components.isEmpty()) {
+ return;
+ }
+ for (Component c : components) {
+ factory.addComponent(c);
+ }
}
- private Component getComponent() {
+ List<Component> getComponents() {
+ List<Component> result = new ArrayList<Component>();
if (getCurrentEvent().data instanceof IStructuredSelection) {
IStructuredSelection selection = (IStructuredSelection) getCurrentEvent().data;
- Object firstElement = selection.getFirstElement();
-
- return (Component) AdapterUtil.getAdapter(firstElement,
- Component.class);
+ Iterator<?> iter = selection.iterator();
+ while (iter.hasNext()) {
+ Object obj = iter.next();
+ Component comp = (Component) AdapterUtil.getAdapter(obj,
+ Component.class);
+ if (comp == null) {
+ continue;
+ }
+ if (isOnline() && obj instanceof NamingObjectNode) {
+ result.add(comp);
+ } else if (!isOnline() && obj instanceof RTCRVLeafItem) {
+ result.add(comp);
+ }
+ }
}
- return null;
+ return result;
}
@Override
@@ -78,21 +113,16 @@
}
// オンラインエディタへは NameServiceViewから DnD可能
// オフラインエディタへは RepositoryViewから DnD可能
- boolean online = false;
- if (getViewer().getRootEditPart().getContents().getModel() instanceof SystemDiagram) {
- SystemDiagram sd = (SystemDiagram) getViewer().getRootEditPart()
- .getContents().getModel();
- if (SystemDiagramKind.ONLINE_LITERAL.equals(sd.getKind())) {
- online = true;
- }
- }
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer
.getInstance().getSelection();
- if (online && selection.getFirstElement() instanceof NamingObjectNode) {
- return true;
- } else if (!online
- && selection.getFirstElement() instanceof RTCRVLeafItem) {
- return true;
+ Iterator<?> iter = selection.iterator();
+ while (iter.hasNext()) {
+ Object obj = iter.next();
+ if (isOnline() && obj instanceof NamingObjectNode) {
+ return true;
+ } else if (!isOnline() && obj instanceof RTCRVLeafItem) {
+ return true;
+ }
}
return false;
}
Modified: trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/editpolicy/SystemXYLayoutEditPolicy.java
===================================================================
--- trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/editpolicy/SystemXYLayoutEditPolicy.java 2012-02-07 14:37:49 UTC (rev 257)
+++ trunk/rtmtools/jp.go.aist.rtm.systemeditor/src/jp/go/aist/rtm/systemeditor/ui/editor/editpolicy/SystemXYLayoutEditPolicy.java 2012-02-07 14:48:47 UTC (rev 258)
@@ -44,10 +44,10 @@
@Override
protected Command getCreateCommand(CreateRequest request) {
ComponentCommandCreator creator = new ComponentCommandCreator();
- ComponentCommandCreator.CommandPair result = creator.getCreateCommand(
- request, getHost().getModel());
+ ComponentCommandCreator.MultiCreateCommand result = creator
+ .getCreateCommand(request, getHost().getModel());
- if (result == null) {
+ if (result.getCommandPairs().isEmpty()) {
MessageDialog.openInformation(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell(), Messages
.getString("SystemXYLayoutEditPolicy.6"), creator
@@ -56,10 +56,18 @@
}
if (request.getLocation() != null) {
- result.component.setConstraint(Draw2dUtil
- .toRtcLinkRectangle((Rectangle) getConstraintFor(request)));
+ int count = 0;
+ for (ComponentCommandCreator.CommandPair pair : result
+ .getCommandPairs()) {
+ Rectangle rect = (Rectangle) getConstraintFor(request);
+ rect.x += count * 20;
+ rect.y += count * 20;
+ pair.component.setConstraint(Draw2dUtil
+ .toRtcLinkRectangle(rect));
+ count++;
+ }
}
- return result.command;
+ return result;
}
@Override
openrtm-commit メーリングリストの案内