Package net.sf.myway.edit.ui.editors.commands

Examples of net.sf.myway.edit.ui.editors.commands.LocationCommand


  protected void createEditPolicies() {
    installEditPolicy(EditPolicy.LAYOUT_ROLE, new XYLayoutEditPolicy() {
      @Override
      protected Command createChangeConstraintCommand(final EditPart child,
        final Object constraint) {
        final LocationCommand cmd = new LocationCommand();
        cmd.setModel((MapObject) child.getModel());
        final org.eclipse.draw2d.geometry.Rectangle rec = (org.eclipse.draw2d.geometry.Rectangle) constraint;
        rec.x += rec.width / 2;
        rec.y += rec.height / 2;
        cmd.setLocation(rec);
        cmd.setTarget(EditMapEditPart.this);
        return cmd;
      }

      /**
       * @see org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart)
       */
      @Override
      protected EditPolicy createChildEditPolicy(final EditPart child) {
        return new NonResizableEditPolicy() {
          /**
           * @see org.eclipse.gef.editpolicies.NonResizableEditPolicy#getCommand(org.eclipse.gef.Request)
           */
          @Override
          public Command getCommand(final Request request) {
            if (REQ_DELETE.equals(request.getType())) {
              final GroupRequest r = (GroupRequest) request;
              final DeleteObjectCommand cmd = new DeleteObjectCommand();
              cmd.setObject(((MapObjectEditPart) r.getEditParts().iterator().next()));
              cmd.setTarget(EditMapEditPart.this);
              return cmd;
            }
            return super.getCommand(request);
          }
        };
      }

      @SuppressWarnings("unchecked")
      @Override
      protected Command getCreateCommand(final CreateRequest request) {
        final Object no = request.getNewObject();
        if (no instanceof MapObject) {
          final AddObjectCommand cmd = new AddObjectCommand();
          cmd.setObject((MapObject) no);
          final FigureCanvas control = (FigureCanvas) EditMapEditPart.this.getViewer()
            .getControl();
          final Point loc = request.getLocation();
          if (control.getVerticalBar() != null)
            loc.y += control.getVerticalBar().getSelection();
          if (control.getHorizontalBar() != null)
            loc.x += control.getHorizontalBar().getSelection();
          cmd.setLocation(loc);
          cmd.setTarget(EditMapEditPart.this);
          return cmd;
        }
        if (no instanceof MapNode) {
          final List<EditPart> sel = getViewer().getSelectedEditParts();
          if (sel.isEmpty())
            return null;
          final MapObject mo = getFirstMapObject(sel);
          if (mo == null)
            return null;
          final AddNodeCommand cmd = new AddNodeCommand();
          cmd.setTarget(mo);
          cmd.setNode((MapNode) no);
          final FigureCanvas control = (FigureCanvas) EditMapEditPart.this.getViewer()
            .getControl();
          final Point loc = request.getLocation();
          if (control.getVerticalBar() != null)
            loc.y += control.getVerticalBar().getSelection();
          if (control.getHorizontalBar() != null)
            loc.x += control.getHorizontalBar().getSelection();
          cmd.setLocation(loc);
          cmd.setCoordSys(_coordinateSystem);
          return cmd;
        }
        return null;
      }

View Full Code Here


          final GroupRequest moveReq = new ChangeBoundsRequest(RequestConstants.REQ_MOVE);
          final CompoundCommand compoundCmd = new CompoundCommand("Move"); //$NON-NLS-1$
          for (int i = 0; i < objects.size(); i++) {
            final EditPart object = (EditPart) objects.get(i);
            moveReq.setEditParts(object);
            final LocationCommand cmd = (LocationCommand) object.getCommand(moveReq);
            if (cmd != null) {
              cmd.setLocation(new Point(event.keyCode == SWT.ARROW_LEFT ? -1
                : event.keyCode == SWT.ARROW_RIGHT ? 1 : 0,
                event.keyCode == SWT.ARROW_DOWN ? 1
                  : event.keyCode == SWT.ARROW_UP ? -1 : 0));
              cmd.setRelative(true);
              compoundCmd.add(cmd);
            }
          }
          getCommandStack().execute(compoundCmd);
          return true;
View Full Code Here

TOP

Related Classes of net.sf.myway.edit.ui.editors.commands.LocationCommand

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.