@Override
    public void update(ViewerCell cell) {
      EObject o = (EObject) cell.getElement();

      String label = ""; // $NON-NLS-1$
      Image img = null;
      AbstractComponentEditor elementEditor = getEditor().getEditor(o.eClass());
      if (elementEditor != null) {
        label = elementEditor.getDetailLabel(o);
        label = label == null ? elementEditor.getLabel(o) : label;
        img = elementEditor.getImage(o, composite.getDisplay());
      }

      List<String> parentPath = new ArrayList<String>();
      while (o.eContainer() != null) {
        o = o.eContainer();
        elementEditor = getEditor().getEditor(o.eClass());
        if (elementEditor != null) {
          parentPath.add(0, elementEditor.getLabel(o));
        }
      }

      String parentString = ""; // $NON-NLS-1$
      for (String p : parentPath) {
        parentString += "/" + p; // $NON-NLS-1$
      }

      StyledString s = new StyledString(label);
      s.append(" - " + parentString, StyledString.DECORATIONS_STYLER); // $NON-NLS-1$
      cell.setStyleRanges(s.getStyleRanges());
      cell.setText(s.getString());
      cell.setImage(img);
    }
  /**
   * @see
   *     com.metamatrix.modeler.core.metamodel.aspect.sql.SqlAspect#getName(org.eclipse.emf.ecore.EObject)
   */
  public String getName(final EObject eObject) {
    CoreArgCheck.isInstanceOf(XmlElement.class, eObject);

    IPath path = new Path(getShortName(eObject));
    EObject parent = eObject.eContainer();
    SqlAspect parentAspect = AspectManager.getSqlAspect(parent);
    while (parentAspect != null) {
      if (parent instanceof XmlDocument) {
        // XmlDocumentSqlAspect now implements SqlTableAspect AND SqlColumnAspect
        break;
      }
      if (parentAspect instanceof SqlColumnAspect) {
        String name = null;
        if (parentAspect instanceof AbstractXmlDocumentEntitySqlAspect) {
          name = ((AbstractXmlDocumentEntitySqlAspect) parentAspect).getShortName(parent);
        } else {
          name = parentAspect.getName(parent);
        }
        path = new Path("").append(name).append(path); // $NON-NLS-1$
      } else if (parentAspect instanceof SqlTableAspect) {
        break;
      }
      // Walk up to the parent ...
      parent = parent.eContainer();
      parentAspect = AspectManager.getSqlAspect(parent);
    }

    return path.toString().replace(IPath.SEPARATOR, '.');
  }
Beispiel #3
0
  /**
   * first container of type {@link ActorClass}
   *
   * @param obj
   * @return ActorClass container
   */
  private ActorClass getActorClass(EObject obj) {
    EObject ctx = obj.eContainer();
    while (!(ctx instanceof ActorClass) && ctx.eContainer() != null) ctx = ctx.eContainer();
    if (ctx instanceof ActorClass) return (ActorClass) ctx;

    return null;
  }
  /** @generated NOT */
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {
    /*
     * changes: Liest aus einem Request die ID des Helpers und
     * erstellt anhand dessen die HelperUnit
     */
    CreateElementRequest request = ((CreateElementRequest) getRequest());
    String helperId =
        (String) request.getParameters().get(comrel.diagram.part.ComrelPaletteFactory.UNIT_ID);
    comrel.ComrelFactory factory = comrel.ComrelFactory.eINSTANCE;
    EObject container = ((CreateElementRequest) getRequest()).getContainer();
    while (container.eContainer() != null) {
      container = container.eContainer();
    }
    CompositeRefactoring cr = (CompositeRefactoring) container;
    comrel.MultiFilterHelper helper = cr.getMultiFilterHelper(helperId);
    if (helper != null && !cr.getHelper().contains(helper)) {
      cr.getHelper().add(helper);
    }
    comrel.MultiFilterUnit newElement;
    if (helper != null) {
      newElement = factory.createMultiFilterUnit(helper);
    } else {
      newElement = factory.createMultiFilterUnit();
    }
    /* end of change */

    CartesianQueuedUnit owner = (CartesianQueuedUnit) getElementToEdit();
    owner.getHelperUnits().add(newElement);

    doConfigure(newElement, monitor, info);

    ((CreateElementRequest) getRequest()).setNewElement(newElement);
    return CommandResult.newOKCommandResult(newElement);
  }
Beispiel #5
0
  /**
   * first container of type {@link StateGraph} ({@link State}, {@link StateMachine})
   *
   * @param obj
   * @return StateGraph Container
   */
  private StateGraph getStateGraph(EObject obj) {
    EObject ctx = obj.eContainer();
    while (!(ctx instanceof StateGraph) && ctx.eContainer() != null) ctx = ctx.eContainer();
    if (ctx instanceof StateGraph) return (StateGraph) ctx;

    return null;
  }
 /**
  * The fully qualified name of the closest named parent.
  *
  * @param o
  * @return
  */
 QualifiedName getParentsFullyQualifiedName(EObject o) {
   for (EObject tmp = o.eContainer(); tmp != null; tmp = tmp.eContainer()) {
     QualifiedName n = getFullyQualifiedName(tmp);
     if (n != null) return n;
   }
   return null;
 }
  /** @generated NOT */
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {
    /*
     * changes: Liest aus einem Request die ID des ModelRefactorings und
     * erstellt anhand dessen die AtomicUnit
     */
    CreateElementRequest request = ((CreateElementRequest) getRequest());
    String refId =
        (String) request.getParameters().get(comrel.diagram.part.ComrelPaletteFactory.UNIT_ID);
    comrel.ComrelFactory factory = ComrelFactory.eINSTANCE;
    EObject container = ((CreateElementRequest) getRequest()).getContainer();
    while (container.eContainer() != null) {
      container = container.eContainer();
    }
    CompositeRefactoring cr = (CompositeRefactoring) container;
    comrel.ModelRefactoring refactoring = cr.getEmfRefactoringAsModelRefactoring(refId);
    if (refactoring != null && !cr.getModelRefactorings().contains(refactoring)) {
      cr.getModelRefactorings().add(refactoring);
    }
    comrel.AtomicUnit newElement = factory.createAtomicUnit(refactoring);
    /* end of change */

    SingleQueuedUnit owner = (SingleQueuedUnit) getElementToEdit();
    owner.setRefactoringUnit(newElement);

    doConfigure(newElement, monitor, info);

    ((CreateElementRequest) getRequest()).setNewElement(newElement);
    return CommandResult.newOKCommandResult(newElement);
  }
 protected String toString(IEObjectRegion region) {
   EObject obj = region.getSemanticElement();
   StringBuilder builder =
       new StringBuilder(Strings.padEnd(toClassWithName(obj), textWidth, ' ') + " ");
   EObject element = region.getGrammarElement();
   if (element instanceof AbstractElement)
     builder.append(grammarToString.apply((AbstractElement) element));
   else if (element instanceof AbstractRule) builder.append(((AbstractRule) element).getName());
   else builder.append(": ERROR: No grammar element.");
   List<String> segments = Lists.newArrayList();
   EObject current = obj;
   while (current.eContainer() != null) {
     EObject container = current.eContainer();
     EStructuralFeature containingFeature = current.eContainingFeature();
     StringBuilder segment = new StringBuilder();
     segment.append(toClassWithName(container));
     segment.append("/");
     segment.append(containingFeature.getName());
     if (containingFeature.isMany()) {
       int index = ((List<?>) container.eGet(containingFeature)).indexOf(current);
       segment.append("[" + index + "]");
     }
     current = container;
     segments.add(segment.toString());
   }
   if (!segments.isEmpty()) {
     builder.append(" path:");
     builder.append(Joiner.on("=").join(segments));
   }
   return builder.toString();
 }
 @Override
 protected JvmIdentifiableElement getReferencedElement(EObject owner, EReference reference) {
   if (reference == XbasePackage.Literals.XCONSTRUCTOR_CALL__CONSTRUCTOR
       && owner.eContainer() instanceof AnonymousClass) {
     return anonymousClassUtil.getSuperType((AnonymousClass) owner.eContainer());
   }
   return super.getReferencedElement(owner, reference);
 }
 private boolean isStatechartDefinitionChild(EObject element) {
   while (element.eContainer() != null) {
     if (element.eContainer() instanceof StatechartSpecification) {
       return true;
     }
     element = element.eContainer();
   }
   return false;
 }
Beispiel #11
0
 private void setContainmentLink(EObject eObject) {
   if (eObject.eContainer() != null) {
     EObject eContainer = eObject.eContainer();
     EReference eReference = eObject.eContainmentFeature();
     int position =
         eReference.isMany() ? position = getContainmentPosition(eContainer, eObject) : 0;
     addLink(eContainer, eObject, eReference, position);
   }
 }
Beispiel #12
0
 public void collectContainers(final EObject obj, final List<EObject> containerList) {
   containerList.add(obj);
   EObject _eContainer = obj == null ? (EObject) null : obj.eContainer();
   boolean _notEquals = (!Objects.equal(_eContainer, null));
   if (_notEquals) {
     EObject _eContainer_1 = obj.eContainer();
     this.collectContainers(_eContainer_1, containerList);
   }
 }
 private LinkedList<EObject> allContainers(EObject eObject) {
   final LinkedList<EObject> allContainers = Lists.newLinkedList();
   allContainers.add(eObject);
   EObject currentContainer = eObject.eContainer();
   final Resource resource = eObject.eResource();
   while (currentContainer != null && resource == currentContainer.eResource()) {
     allContainers.addFirst(currentContainer);
     currentContainer = currentContainer.eContainer();
   }
   return allContainers;
 }
 private EObject getNamedEObject(EObject model) {
   EObject curObj = model;
   while (curObj.eContainer() != null) {
     if (curObj.eClass().getEStructuralFeature("name") != null) {
       return model;
     } else {
       curObj = curObj.eContainer();
     }
   }
   return null;
 }
Beispiel #15
0
 /** Return the number of containers of eObject, 0 if eObject is a root. */
 public static int getContainmentDepth(EObject eObject) {
   int depth = 0;
   for (EObject eContainer = eObject.eContainer();
       eContainer != null;
       eContainer = eContainer.eContainer()) {
     depth++;
     if (depth > 100000) {
       return depth;
     }
   }
   return depth;
 }
 protected IScope internalGetScope(
     IScope parent, IScope globalScope, EObject context, EReference reference) {
   IScope result = parent;
   if (context.eContainer() == null) {
     if (parent != globalScope)
       throw new IllegalStateException("the parent should be the global scope");
     result = getResourceScope(globalScope, context.eResource(), reference);
   } else {
     result = internalGetScope(parent, globalScope, context.eContainer(), reference);
   }
   return getLocalElementsScope(result, globalScope, context, reference);
 }
 // DS-1534
 @SuppressWarnings("unchecked")
 private List<EditPart> getEditPartsForElement(EObject item) {
   if (item == null) {
     return Collections.EMPTY_LIST;
   }
   String id = ((XMLResource) item.eResource()).getID(item);
   List<EditPart> editParts = viewer.findEditPartsForElement(id, EditPart.class);
   if (editParts.isEmpty() && item.eContainer() != null) {
     return getEditPartsForElement(item.eContainer());
   }
   return editParts;
 }
  private XmlDocument getXmlDocument(EObject xmlElement) {
    EObject container = xmlElement.eContainer();
    EObject document = null;
    // append parent information in front of the eObject name
    while (container != null) {
      document = container;
      container = container.eContainer();
    }

    CoreArgCheck.isInstanceOf(XmlDocument.class, document, null);
    return (XmlDocument) document;
  }
Beispiel #19
0
  public static ArrayList<Variable> allVisibleVariables(EObject container) {
    ArrayList<Variable> result = new ArrayList<Variable>();

    if (container instanceof LocalVariable) {
      if (container.eContainer() instanceof Stream) {
        return allVisibleVariables(container.eContainer());
      }
    }

    // Add the variables of the block if we are in a block
    ActionBlock b = findContainingActionBlock(container);
    if (b != null) {
      for (Action a : b.getActions()) {
        if (a == container || a.eContents().contains(container))
          continue; // ignore variables defined after the current statement
        if (a instanceof Variable) result.add((Variable) a);
      }

      result.addAll(allVisibleVariables(b.eContainer()));

      return result;
    }

    // Add the variables of the state if we are in a state
    State s = findContainingState(container);
    if (s != null) {
      result.addAll(allProperties(s));
      return result;
    }

    // Add parameters of the function if we are in a function
    Function f = findContainingFunction(container);
    if (f != null) {
      result.addAll(f.getParameters());
      result.addAll(allVisibleVariables(f.eContainer()));
    }

    Stream stream = findContainingStream(container);
    if (stream != null) {
      result.addAll(stream.getSelection());
    }

    // Only the variables of the thing if we are in a thing:
    Thing t = findContainingThing(container);
    if (t != null) {
      // Properties from the thing
      result.addAll(allProperties(t));
      return result;
    }

    return result;
  }
  @Override
  public MWindow getTopLevelWindowFor(MUIElement element) {
    EObject eObj = (EObject) element;
    while (eObj != null && !(eObj.eContainer() instanceof MApplication)) {
      eObj = eObj.eContainer();
    }

    if (eObj instanceof MWindow) {
      return (MWindow) eObj;
    }

    return null; // Ooops!
  }
 private List<Type> getTypeProposals(CollaborationUse cu) {
   EObject root = cu.eContainer();
   while (root.eContainer() != null) {
     root = root.eContainer();
   }
   if (false == root instanceof org.eclipse.uml2.uml.Package) {
     return Collections.<Type>emptyList();
   }
   List<Type> types = new LinkedList<Type>();
   for (Type next : ((org.eclipse.uml2.uml.Package) root).getOwnedTypes()) {
     types.add(next);
   }
   return types;
 }
 private Region getOutermostParentRegion(EObject element) {
   while (!(element.eContainer() instanceof Statechart)) {
     EObject container = element.eContainer();
     if (container instanceof State) {
       State parentState = (State) container;
       if (parentState.equals(subdiagram.getElement())) {
         return (Region) element;
       }
       element = parentState.getParentRegion();
     } else {
       element = element.eContainer();
     }
   }
   return null;
 }
Beispiel #23
0
 public static List<TemplateParameter> getAllTemplateParameters(EObject eObject) {
   List<TemplateParameter> result = null;
   EObject eContainer = eObject.eContainer();
   if (eContainer != null) {
     result = getAllTemplateParameters(eContainer);
   }
   if (eObject instanceof TemplateableElement) {
     TemplateableElement unspecializedTemplateableElement = (TemplateableElement) eObject;
     if (eObject instanceof Type) {
       eObject = getUnspecializedTemplateableElement((Type) eObject);
     }
     TemplateSignature templateSignature =
         unspecializedTemplateableElement.getOwnedTemplateSignature();
     if (templateSignature != null) {
       List<TemplateParameter> templateParameters = templateSignature.getParameter();
       if (templateParameters.size() > 0) {
         if (result == null) {
           result = new ArrayList<TemplateParameter>();
         }
         result.addAll(templateParameters);
       }
     }
   }
   return result;
 }
 public String[] getStack() {
   org.eclipse.emf.ecore.EObject next = interpreterDelegate.getNextObjectToInterprete();
   java.util.List<org.eclipse.emf.ecore.EObject> parents =
       new java.util.ArrayList<org.eclipse.emf.ecore.EObject>();
   org.eclipse.emf.ecore.EObject current = next;
   while (current != null) {
     parents.add(current);
     current = current.eContainer();
   }
   String[] stack = new String[parents.size()];
   int i = parents.size();
   for (org.eclipse.emf.ecore.EObject parent : parents) {
     String serializedStackElement =
         org.feature.multi.perspective.mapping.viewmapping.resource.mtext.util.MtextStringUtil
             .encode(
                 ',',
                 new String[] {
                   parent.eClass().getName(),
                   Integer.toString(stackFrameID),
                   parent.eResource().getURI().toString(),
                   Integer.toString(getLine(parent)),
                   Integer.toString(getCharStart(parent)),
                   Integer.toString(getCharEnd(parent))
                 });
     stack[--i] = serializedStackElement;
     stackFrameMap.put(stackFrameID++, parent);
   }
   return stack;
 }
Beispiel #25
0
 /**
  * Return the ConstrainingNode node for EObject creating any parent ConstrainingNodes that are
  * required to ensure that the returned ConstrainingNode is installed in the root.
  */
 public @NonNull ConstrainingNode getConstrainingNode(@NonNull EObject eObject) {
   URI uri = getURI(eObject);
   ConstrainingNode constrainingNode = allConstrainingNodes.get(uri);
   if (constrainingNode == null) {
     EObject eContainer = eObject.eContainer();
     if (eContainer == null) {
       RootConstrainingNode rootConstrainingNode = createRootConstrainingNode();
       rootNode.getConstrainingNodes().add(rootConstrainingNode);
       constrainingNode = rootConstrainingNode;
     }
     //			else if (eObject instanceof EClass) {
     //				constrainingNode = ValidationFactory.eINSTANCE.createLeafConstrainingNode();
     //			ConstrainingNode parentConstrainingNode = getConstrainingNode(eContainer);
     //				parentConstrainingNode.getChildren().add(constrainingNode);
     //			}
     else {
       constrainingNode = createConstrainingNode();
       ConstrainingNode parentConstrainingNode = getConstrainingNode(eContainer);
       parentConstrainingNode.getChildren().add(constrainingNode);
     }
     constrainingNode.setConstrainingObject(eObject);
     constrainingNode.setLabel(validityManager.getLabel(eObject));
     constrainingNode.setEnabled(true);
     allConstrainingNodes.put(uri, constrainingNode);
   }
   return constrainingNode;
 }
  public static void addTableForSpecifiedDataPackage(
      DatabaseConnection dbconn, MetadataTable dbtable)
      throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
    // if the database connection is contextmodel, need to get the original value of every parameter
    IMetadataConnection imetadataConnection = ConvertionHelper.convert(dbconn);
    DatabaseConnection conn = (DatabaseConnection) imetadataConnection.getCurrentConnection();
    Collection<orgomg.cwm.objectmodel.core.Package> newDataPackage =
        EcoreUtil.copyAll(dbconn.getDataPackage());
    ConnectionHelper.addPackages(newDataPackage, conn);

    // String catalog = "";
    // fixed bug TDI-19395
    String catalog = imetadataConnection.getDatabase();
    String schema = "";
    EObject container = dbtable.eContainer();
    if (container != null) {
      if (container instanceof Schema) {
        schema = ((Schema) container).getName();
        EObject c = container.eContainer();
        if (c != null && c instanceof Catalog) {
          catalog = ((Catalog) c).getName();
        }
      } else if (container instanceof Catalog) {
        catalog = ((Catalog) container).getName();
      }
    }
    boolean isAccess =
        EDatabaseTypeName.ACCESS.getDisplayName().equals(imetadataConnection.getDbType());
    if (!isAccess) {
      schema = ExtractMetaDataUtils.getInstance().getMeataConnectionSchema(imetadataConnection);
    }
    addTableForTemCatalogOrSchema(catalog, schema, dbconn, dbtable, imetadataConnection);
  }
 public String getParentLabel(EObject eObject) {
   EObject eContainer = eObject.eContainer();
   if (!(eContainer instanceof EPackage)) return "";
   String parentLabel = getParentLabel(eContainer);
   if ("".equals(parentLabel)) return labelProvider.getText(eContainer);
   else return parentLabel + "." + labelProvider.getText(eContainer);
 }
  protected Collection<String> getSuggestedSignatures(Object object) {
    // Get all .itf in project and MindPath
    List<String> suggestedSignatures = getInterfacesInProject();

    // Get imports list
    if (object instanceof EObject) {
      EObject parent = (EObject) object;
      while (parent != null && !(parent instanceof AdlDefinition)) {
        parent = parent.eContainer();
      }
      if (parent != null) {
        // To avoid concurrent modifications
        List<String> toRemove = new ArrayList<String>();
        List<String> toAdd = new ArrayList<String>();

        EList<ImportDefinition> imports = ((AdlDefinition) parent).getImports();
        // We can use simple name for all .itf already imported
        // And add it at the beggining of the list
        for (ImportDefinition imp : imports) {
          String name = imp.getImportName();
          for (String signature : suggestedSignatures) {
            if (name.startsWith(signature)) {
              toRemove.add(signature);
              signature = name.substring(name.lastIndexOf(".") + 1);
              toAdd.add(0, signature);
            }
          }
        }
        suggestedSignatures.removeAll(toRemove);
        suggestedSignatures.addAll(0, toAdd);
      }
    }

    return suggestedSignatures;
  }
Beispiel #29
0
 public static Map<TemplateParameter, ParameterableElement> getAllTemplateParametersAsBindings(
     EObject eObject) {
   if (eObject instanceof Type) {
     eObject = getUnspecializedTemplateableElement((Type) eObject);
   }
   Map<TemplateParameter, ParameterableElement> result = null;
   EObject eContainer = eObject.eContainer();
   if (eContainer != null) {
     result = getAllTemplateParametersAsBindings(eContainer);
   }
   if (eObject instanceof TemplateableElement) {
     //			TemplateableElement unspecializedTemplateableElement =
     // getUnspecializedTemplateableElement((TemplateableElement)eObject);
     TemplateSignature templateSignature =
         ((TemplateableElement) eObject).getOwnedTemplateSignature();
     if (templateSignature != null) {
       List<TemplateParameter> templateParameters = templateSignature.getParameter();
       if (templateParameters.size() > 0) {
         if (result == null) {
           result = new HashMap<TemplateParameter, ParameterableElement>();
         }
         for (TemplateParameter templateParameter : templateSignature.getParameter()) {
           result.put(templateParameter, null);
         }
       }
     }
   }
   return result;
 }
Beispiel #30
0
 public static Map<TemplateParameter, ParameterableElement> getAllTemplateParameterSubstitutions(
     Map<TemplateParameter, ParameterableElement> map, TemplateableElement templateableElement) {
   for (EObject eObject = templateableElement; eObject != null; eObject = eObject.eContainer()) {
     if (eObject instanceof TemplateableElement) {
       for (TemplateBinding templateBinding :
           ((TemplateableElement) eObject).getTemplateBinding()) {
         for (TemplateParameterSubstitution templateParameterSubstitution :
             templateBinding.getParameterSubstitution()) {
           if (map == null) {
             map = new HashMap<TemplateParameter, ParameterableElement>();
           }
           map.put(
               templateParameterSubstitution.getFormal(),
               templateParameterSubstitution.getActual());
         }
       }
     }
     if (eObject instanceof Type) {
       for (Type superType : ((Type) eObject).getSuperClass()) {
         map = getAllTemplateParameterSubstitutions(map, superType);
       }
     }
   }
   return map;
 }