Author: dazarov
Date: 2008-05-29 11:08:15 -0400 (Thu, 29 May 2008)
New Revision: 8443
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ConnectionCommand.java
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ReconnectSourceLinkCommand.java
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ReconnectTargetLinkCommand.java
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/PagesNodeEditPolicy.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/PagesEditPart.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1189
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ConnectionCommand.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ConnectionCommand.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ConnectionCommand.java 2008-05-29
15:08:15 UTC (rev 8443)
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.ui.pages.editor.commands;
+
+import org.eclipse.gef.commands.Command;
+import org.jboss.tools.seam.ui.pages.editor.dnd.DndHelper;
+import org.jboss.tools.seam.ui.pages.editor.ecore.pages.Link;
+import org.jboss.tools.seam.ui.pages.editor.ecore.pages.PagesElement;
+import org.jboss.tools.seam.ui.pages.editor.edit.PagesEditPart;
+
+
+public class ConnectionCommand extends Command {
+ protected PagesEditPart oldSource;
+ protected String oldSourceTerminal;
+ protected PagesEditPart oldTarget;
+ protected String oldTargetTerminal;
+ protected PagesEditPart source;
+ protected String sourceTerminal;
+ protected PagesEditPart target;
+ protected String targetTerminal;
+ protected Link link;
+
+ public ConnectionCommand() {
+ super("connection command");
+ }
+
+ public boolean canExecute() {
+ if (target == null)
+ return false;
+ if (target.getModel() == null)
+ return false;
+ return DndHelper
+ .isDropEnabled(((PagesElement) target.getModel()).getData());
+ }
+
+ public void execute() {
+ DndHelper.drop(((PagesElement) target.getModel()).getData());
+ }
+
+ public String getLabel() {
+ return "connection command";
+ }
+
+ public PagesEditPart getSource() {
+ return source;
+ }
+
+ public java.lang.String getSourceTerminal() {
+ return sourceTerminal;
+ }
+
+ public PagesEditPart getTarget() {
+ return target;
+ }
+
+ public String getTargetTerminal() {
+ return targetTerminal;
+ }
+
+ public Link getLink() {
+ return link;
+ }
+
+ public void setSource(PagesEditPart newSource) {
+ source = newSource;
+ }
+
+ public void setSourceTerminal(String newSourceTerminal) {
+ sourceTerminal = newSourceTerminal;
+ }
+
+ public void setTarget(PagesEditPart newTarget) {
+ target = newTarget;
+ }
+
+ public void setTargetTerminal(String newTargetTerminal) {
+ targetTerminal = newTargetTerminal;
+ }
+
+ public void setLink(Link l) {
+ link = l;
+ }
+
+ public boolean canUndo() {
+ return false;
+ }
+
+}
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ReconnectSourceLinkCommand.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ReconnectSourceLinkCommand.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ReconnectSourceLinkCommand.java 2008-05-29
15:08:15 UTC (rev 8443)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.ui.pages.editor.commands;
+
+import org.eclipse.gef.commands.Command;
+import org.jboss.tools.seam.ui.pages.editor.dnd.DndHelper;
+import org.jboss.tools.seam.ui.pages.editor.ecore.pages.Link;
+
+
+public class ReconnectSourceLinkCommand extends Command{
+
+ static Link child = null;
+
+ public ReconnectSourceLinkCommand(){
+ super("ReconnectSourceLinkCommand");
+ }
+
+ public void setLink(Link child){
+ ReconnectSourceLinkCommand.child= child;
+ }
+ public boolean canExecute(){
+ return DndHelper.isDropEnabled(child.getData());
+ }
+
+ public void execute(){
+ if(child != null)DndHelper.drop(child.getData());
+ child = null;
+ }
+
+ public boolean canUndo() {
+ return false;
+ }
+}
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ReconnectTargetLinkCommand.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ReconnectTargetLinkCommand.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/commands/ReconnectTargetLinkCommand.java 2008-05-29
15:08:15 UTC (rev 8443)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.ui.pages.editor.commands;
+
+import org.eclipse.gef.commands.Command;
+import org.jboss.tools.seam.ui.pages.editor.dnd.DndHelper;
+import org.jboss.tools.seam.ui.pages.editor.ecore.pages.PagesElement;
+
+
+public class ReconnectTargetLinkCommand extends Command{
+
+ PagesElement child = null;
+
+ public ReconnectTargetLinkCommand(){
+ super("ReconnectTargetLinkCommand");
+ }
+
+ public void setChild(PagesElement child){
+ this.child= child;
+ }
+
+ public boolean canExecute(){
+ return DndHelper.isDropEnabled(child.getData());
+ }
+
+ public void execute(){
+ DndHelper.drop(child.getData());
+ }
+
+ public boolean canUndo() {
+ return false;
+ }
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/PagesEditPart.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/PagesEditPart.java 2008-05-29
14:57:32 UTC (rev 8442)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/PagesEditPart.java 2008-05-29
15:08:15 UTC (rev 8443)
@@ -22,6 +22,7 @@
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.*;
+import org.jboss.tools.seam.ui.pages.editor.ecore.pages.PagesElement;
import org.jboss.tools.seam.ui.pages.editor.figures.NodeFigure;
abstract public class PagesEditPart extends
@@ -42,6 +43,10 @@
super.activate();
}
+ public PagesElement getElementModel(){
+ return (PagesElement)getModel();
+ }
+
/**
*
* @return
@@ -56,8 +61,8 @@
*/
protected void createEditPolicies() {
// installEditPolicy(EditPolicy.COMPONENT_ROLE, new JSFElementEditPolicy());
-// installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE,
-// new JSFNodeEditPolicy());
+ installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE,
+ new PagesNodeEditPolicy());
}
/**
@@ -125,6 +130,15 @@
public void propertyChange(PropertyChangeEvent evt) {
refreshVisuals();
}
+
+ /**
+ *
+ * @param c
+ * @return
+ */
+ final protected String mapConnectionAnchorToTerminal(ConnectionAnchor c) {
+ return getNodeFigure().getConnectionAnchorName(c);
+ }
/**
*
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/PagesNodeEditPolicy.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/PagesNodeEditPolicy.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui.pages/src/org/jboss/tools/seam/ui/pages/editor/edit/PagesNodeEditPolicy.java 2008-05-29
15:08:15 UTC (rev 8443)
@@ -0,0 +1,126 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.ui.pages.editor.edit;
+
+import org.eclipse.draw2d.Connection;
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.PolylineConnection;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.GraphicalNodeEditPolicy;
+import org.eclipse.gef.requests.CreateConnectionRequest;
+import org.eclipse.gef.requests.ReconnectRequest;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.seam.ui.pages.editor.commands.ConnectionCommand;
+import org.jboss.tools.seam.ui.pages.editor.dnd.DndHelper;
+import org.jboss.tools.seam.ui.pages.editor.figures.FigureFactory;
+import org.jboss.tools.seam.ui.pages.editor.figures.NodeFigure;
+
+public class PagesNodeEditPolicy extends
+ GraphicalNodeEditPolicy {
+
+ /**
+ *
+ */
+ protected Connection createDummyConnection(Request req) {
+ PolylineConnection dummyConn = FigureFactory.createNewLink(null);
+ return dummyConn;
+ }
+
+ /**
+ *
+ */
+ protected Command getConnectionCompleteCommand(
+ CreateConnectionRequest request) {
+ if (getPagesEditPart() instanceof PageEditPart) {
+ if (!DndHelper
+ .isDropEnabled((XModelObject) ((PageEditPart) getPagesEditPart())
+ .getPageModel().getData()))
+ return null;
+ } else if (getPagesEditPart() instanceof PagesEditPart) {
+ if (!DndHelper
+ .isDropEnabled((XModelObject) ((PagesEditPart) getPagesEditPart())
+ .getElementModel().getData()))
+ return null;
+ }
+ ConnectionCommand command = (ConnectionCommand) request
+ .getStartCommand();
+ command.setTarget((PagesEditPart) getPagesEditPart());
+ ConnectionAnchor ancor = getPagesEditPart().getTargetConnectionAnchor(
+ request);
+ if (ancor == null)
+ return null;
+ command.setTargetTerminal(getPagesEditPart()
+ .mapConnectionAnchorToTerminal(ancor));
+ return command;
+ }
+
+ /**
+ *
+ */
+ protected Command getConnectionCreateCommand(CreateConnectionRequest request) {
+ if (getPagesEditPart() instanceof PageEditPart) {
+ if (!DndHelper
+ .drag((XModelObject) ((PageEditPart) getPagesEditPart())
+ .getPageModel().getData()))
+ return null;
+ } else if (getPagesEditPart() instanceof PagesEditPart) {
+ /*if (((PagesEditPart) getPagesEditPart()).getElementModel()
+ .getPageList().size() > 1)
+ return null;*/
+ if (!DndHelper
+ .drag((XModelObject) ((PagesEditPart) getPagesEditPart())
+ .getElementModel().getData()))
+ return null;
+ }
+ ConnectionCommand command = new ConnectionCommand();
+ command.setLink(null);
+ command.setSource((PageEditPart) getPagesEditPart());
+ ConnectionAnchor ancor = getPagesEditPart().getSourceConnectionAnchor(
+ request);
+ command.setSourceTerminal(getPagesEditPart()
+ .mapConnectionAnchorToTerminal(ancor));
+ request.setStartCommand(command);
+ return command;
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected PagesEditPart getPagesEditPart() {
+ return (PagesEditPart) getHost();
+ }
+
+ /**
+ *
+ */
+ protected Command getReconnectTargetCommand(ReconnectRequest request) {
+ return null;
+ }
+
+ /**
+ *
+ */
+ protected Command getReconnectSourceCommand(ReconnectRequest request) {
+ return null;
+ }
+
+ /**
+ *
+ * @return
+ */
+ protected NodeFigure getNodeFigure() {
+ return (NodeFigure) ((GraphicalEditPart) getHost()).getFigure();
+ }
+
+}
\ No newline at end of file