コード例 #1
0
  @Override
  protected Command getDirectEditCommand(DirectEditRequest request) {
    // TODO put "http://vespucci.editor" in some constant
    // Make sure that XXXEditPart is an instanceof GraphicalEditPart
    // so that it support resolveSemanticElement()
    // Furthermore make sure that the resolveSemanticElement() is from type
    // Shape
    if (getHost() instanceof GraphicalEditPart
        && ((GraphicalEditPart) getHost()).resolveSemanticElement() instanceof Shape) {
      // we need infos about the EMF meta modell so we refer to the
      // Singelton that save Vespucci_modelPackage
      EPackage epackage =
          org.eclipse.emf.ecore.EPackage.Registry.INSTANCE.getEPackage("http://vespucci.editor");
      Vespucci_modelPackage vesPackage = (Vespucci_modelPackage) epackage;
      if ((((GraphicalEditPart) getHost()).resolveSemanticElement())
          .eClass()
          .getEAllStructuralFeatures()
          .contains(vesPackage.getShape_Query())) {

        // get the old query
        // String name = (String)writer.eGet(LibraryPackage.eINSTANCE.getWriter_Name());

        Object oldQuery =
            (((GraphicalEditPart) getHost()).resolveSemanticElement())
                .eGet(vesPackage.getShape_Query());
        @SuppressWarnings("unchecked")
        SetRequest sr =
            new SetRequest(
                ((GraphicalEditPart) getHost()).resolveSemanticElement(),
                vesPackage.getShape_Query(),
                QueryBuilder.createQueryForAMapOfIResource(
                    request.getExtendedData(), (String) oldQuery));

        org.eclipse.gmf.runtime.common.core.command.ICommand com = new SetValueCommand(sr);
        // return the edit Request in a Proxy so it can be handled
        return new org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy(com);

        // create a Request for the Query edit
        // @SuppressWarnings("unchecked")
        // EditQueryRequest editRequest = new EditQueryRequest(
        // ((GraphicalEditPart) getHost()).resolveSemanticElement(),
        // vesPackage.getShape_Query(), request.getExtendedData());
        // ICommand com = new EditQueryCommand(editRequest);
        // return new
        // org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy(com);
      }
      return null;
    }
    return null;
  }
コード例 #2
0
 @Override
 protected Request createTargetRequest() {
   // DirectEditRequest request = new DirectEditRequest();
   EPackage epackage =
       org.eclipse.emf.ecore.EPackage.Registry.INSTANCE.getEPackage("http://vespucci.editor");
   Vespucci_modelPackage vesPackage = (Vespucci_modelPackage) epackage;
   IElementType elementType =
       ElementTypeRegistry.getInstance().getElementType(vesPackage.getEnsemble());
   // TODO is there a way to get VespucciElementTypes.Ensemble_2001 over a methode call?
   elementType = VespucciElementTypes.Ensemble_2001;
   // Get the selected edit part
   EditPart epart = getTargetEditPart();
   if (epart == null)
     return new CreateViewRequest(new CreateViewRequest.ViewDescriptor(null, null));
   // GraphicalEditPart p = (GraphicalEditPart) epart;
   DiagramEditPart p = (DiagramEditPart) epart;
   CreateViewRequest request =
       CreateViewRequestFactory.getCreateShapeRequest(elementType, p.getDiagramPreferencesHint());
   request.setType(REQ_DROPNEWENSEMBLE);
   return request;
 }