/**
  * Checks if is my diagram element.
  *
  * @param view the view
  * @return true, if is my diagram element
  * @generated
  */
 private boolean isMyDiagramElement(View view) {
   int visualID = UMLVisualIDRegistry.getVisualID(view);
   switch (visualID) {
     case InterfaceEditPartPCN.VISUAL_ID:
     case CommentEditPartPCN.VISUAL_ID:
     case ConstraintEditPartPCN.VISUAL_ID:
     case ComponentEditPartPCN.VISUAL_ID:
       return true;
   }
   return false;
 }
コード例 #2
0
 /** @generated */
 public IParser getParser() {
   if (parser == null) {
     parser =
         UMLParserProvider.getParser(
             UMLElementTypes.Comment_3074,
             getParserElement(),
             UMLVisualIDRegistry.getType(
                 org.eclipse.papyrus.uml.diagram.component.edit.parts.CommentBodyEditPartPCN
                     .VISUAL_ID));
   }
   return parser;
 }
コード例 #3
0
 /** @generated */
 public synchronized boolean provides(IOperation operation) {
   if (operation instanceof CreateGraphicEditPartOperation) {
     View view = ((IEditPartOperation) operation).getView();
     if (!ComponentDiagramEditPart.MODEL_ID.equals(UMLVisualIDRegistry.getModelID(view))) {
       return false;
     }
     if (isAllowCaching() && getCachedPart(view) != null) {
       return true;
     }
     IGraphicalEditPart part = createEditPart(view);
     if (part != null) {
       if (isAllowCaching()) {
         cachedPart = new WeakReference(part);
         cachedView = new WeakReference(view);
       }
       return true;
     }
   }
   return false;
 }
  /**
   * Refresh semantic.
   *
   * @generated
   */
  protected void refreshSemantic() {
    if (resolveSemanticElement() == null) {
      return;
    }
    LinkedList<IAdaptable> createdViews = new LinkedList<IAdaptable>();
    List<UMLNodeDescriptor> childDescriptors =
        UMLDiagramUpdater.getPackagePackageableElementCompartment_7002SemanticChildren(
            (View) getHost().getModel());
    LinkedList<View> orphaned = new LinkedList<View>();
    // we care to check only views we recognize as ours
    LinkedList<View> knownViewChildren = new LinkedList<View>();
    for (View v : getViewChildren()) {
      if (isMyDiagramElement(v)) {
        knownViewChildren.add(v);
      }
    }
    // alternative to #cleanCanonicalSemanticChildren(getViewChildren(), semanticChildren)
    //
    // iteration happens over list of desired semantic elements, trying to find best matching View,
    // while original CEP
    // iterates views, potentially losing view (size/bounds) information - i.e. if there are few
    // views to reference same EObject, only last one
    // to answer isOrphaned == true will be used for the domain element representation, see
    // #cleanCanonicalSemanticChildren()
    for (Iterator<UMLNodeDescriptor> descriptorsIterator = childDescriptors.iterator();
        descriptorsIterator.hasNext(); ) {
      UMLNodeDescriptor next = descriptorsIterator.next();
      String hint = UMLVisualIDRegistry.getType(next.getVisualID());
      LinkedList<View> perfectMatch =
          new LinkedList<View>(); // both semanticElement and hint match that of NodeDescriptor
      for (View childView : getViewChildren()) {
        EObject semanticElement = childView.getElement();
        if (next.getModelElement().equals(semanticElement)) {
          if (hint.equals(childView.getType())) {
            perfectMatch.add(childView);
            // actually, can stop iteration over view children here, but
            // may want to use not the first view but last one as a 'real' match (the way original
            // CEP does
            // with its trick with viewToSemanticMap inside #cleanCanonicalSemanticChildren
          }
        }
      }
      if (perfectMatch.size() > 0) {
        descriptorsIterator
            .remove(); // precise match found no need to create anything for the NodeDescriptor
        // use only one view (first or last?), keep rest as orphaned for further consideration
        knownViewChildren.remove(perfectMatch.getFirst());
      }
    }
    // those left in knownViewChildren are subject to removal - they are our diagram elements we
    // didn't find match to,
    // or those we have potential matches to, and thus need to be recreated, preserving
    // size/location information.
    orphaned.addAll(knownViewChildren);
    //
    ArrayList<CreateViewRequest.ViewDescriptor> viewDescriptors =
        new ArrayList<CreateViewRequest.ViewDescriptor>(childDescriptors.size());
    for (UMLNodeDescriptor next : childDescriptors) {
      String hint = UMLVisualIDRegistry.getType(next.getVisualID());
      IAdaptable elementAdapter = new CanonicalElementAdapter(next.getModelElement(), hint);
      CreateViewRequest.ViewDescriptor descriptor =
          new CreateViewRequest.ViewDescriptor(
              elementAdapter,
              Node.class,
              hint,
              ViewUtil.APPEND,
              false,
              host().getDiagramPreferencesHint());
      viewDescriptors.add(descriptor);
    }

    boolean changed = deleteViews(orphaned.iterator());
    //
    CreateViewRequest request = getCreateViewRequest(viewDescriptors);
    Command cmd = getCreateViewCommand(request);
    if (cmd != null && cmd.canExecute()) {
      SetViewMutabilityCommand.makeMutable(new EObjectAdapter(host().getNotationView())).execute();
      executeCommand(cmd);
      @SuppressWarnings("unchecked")
      List<IAdaptable> nl = (List<IAdaptable>) request.getNewObject();
      createdViews.addAll(nl);
    }
    if (changed || createdViews.size() > 0) {
      postProcessRefreshSemantic(createdViews);
    }
    if (createdViews.size() > 1) {
      // perform a layout of the container
      DeferredLayoutCommand layoutCmd =
          new DeferredLayoutCommand(host().getEditingDomain(), createdViews, host());
      executeCommand(new ICommandProxy(layoutCmd));
    }

    makeViewsImmutable(createdViews);
  }