public boolean isInPDomain(PowerDomain pdomain, InstanceDBNode inst) {

    if (instanceOfPDomainMap == null)
      instanceOfPDomainMap = new HashMap<PowerDomain, ArrayList<InstanceDBNode>>();

    ArrayList<InstanceDBNode> insts = instanceOfPDomainMap.get(pdomain);

    if (insts == null) {
      ArrayList<InstanceDBNode> leafInsts = getLeafPMInstances(pdomain);

      insts = new ArrayList<InstanceDBNode>();

      // all instance above the PM leaf instance also "belong"  to the power domain
      ElementDBNode parent;
      for (InstanceDBNode i : leafInsts) {
        parent = i;
        while (parent instanceof InstanceDBNode) {
          insts.add((InstanceDBNode) parent);
          parent = parent.parentDBNode();
        }
      }

      instanceOfPDomainMap.put(pdomain, insts);
    }

    return insts.contains(inst);
  }
Пример #2
0
  public void processSelection(IWorkbenchPart targetPart, ISelection selection) {
    this.activeTargetPart = targetPart;

    if (targetPart != null) {
      ISelectionProvider selectionProvider =
          ((WorkbenchPart) targetPart).getSite().getSelectionProvider();

      if (selectionProvider != null
          && selectionProvider.getSelection() != null
          && !selectionProvider.getSelection().isEmpty())
        selection = selectionProvider.getSelection();

      if (selection == null || selection.isEmpty()) return;
    }

    treePaths = null;
    treePath = null;
    sel = null;
    sels = null;
    model = null;

    if (selection instanceof ITreeSelection) {
      treePaths = ((ITreeSelection) selection).getPaths();
      treePath = ((ITreeSelection) selection).getPaths()[0];
      sel = DBNodeFactory.dbNode(treePath);
      sels = DBNodeFactory.dbNodes(treePaths);
    } else if (selection instanceof IStructuredSelection) {
      Object firstElement = ((IStructuredSelection) selection).getFirstElement();
      if (firstElement instanceof ElementDB)
        sel = DBNodeFactory.dbNode(new ElementDB[] {(ElementDB) firstElement});
      else if (firstElement instanceof ElementDBNode) sel = (ElementDBNode) firstElement;
      else if (firstElement instanceof ISelectionElementDBNode) {
        sels = ((ISelectionElementDBNode) firstElement).getSelectedDBNode();
        sel = sels[0];
      }

      if (sel != null) sels = new ElementDBNode[] {sel};
    }

    if (sel != null) model = sel.model();
  }