/** @see Alignment#getTypeCells(Cell) */ @Override public Collection<? extends Cell> getTypeCells(Cell queryCell) { Set<TypeEntityDefinition> sources = new HashSet<TypeEntityDefinition>(); if (queryCell.getSource() != null) { Iterator<? extends Entity> it = queryCell.getSource().values().iterator(); while (it.hasNext()) sources.add(AlignmentUtil.getTypeEntity(it.next().getDefinition())); } Entity targetEntity = CellUtil.getFirstEntity(queryCell.getTarget()); TypeDefinition target = targetEntity == null ? null : targetEntity.getDefinition().getType(); if (sources.isEmpty() && target == null) return getTypeCells(); List<Cell> result = new ArrayList<Cell>(); for (Cell typeCell : typeCells) { TypeDefinition typeCellTarget = CellUtil.getFirstEntity(typeCell.getTarget()).getDefinition().getType(); if (target == null || DefinitionUtil.isSuperType(target, typeCellTarget)) { // target matches if (sources.isEmpty() || matchesSources(typeCell.getSource(), sources)) { // source matches, too result.add(typeCell); } } } return result; }
/** @see Alignment#getPropertyCells(Cell, boolean, boolean) */ @Override public Collection<? extends Cell> getPropertyCells( Cell typeCell, boolean includeDisabled, boolean ignoreEmptySource) { if (CellUtil.getFirstEntity(typeCell.getTarget()) == null) { if (CellUtil.getFirstEntity(typeCell.getSource()) == null) return Collections.emptySet(); else if (!(typeCell.getSource().values().iterator().next() instanceof Type)) throw new IllegalArgumentException("Given cell is not a type cell."); // query with sources only Collection<TypeEntityDefinition> sourceTypes = new ArrayList<TypeEntityDefinition>(); Iterator<? extends Entity> it = typeCell.getSource().values().iterator(); while (it.hasNext()) sourceTypes.add((TypeEntityDefinition) it.next().getDefinition()); List<Cell> result = new ArrayList<Cell>(); for (Cell cell : cells) if (!AlignmentUtil.isTypeCell(cell) && matchesSources(cell.getSource(), sourceTypes)) result.add(cell); return result; } if (!AlignmentUtil.isTypeCell(typeCell)) throw new IllegalArgumentException("Given cell is not a type cell."); List<Cell> result = new ArrayList<Cell>(); TypeDefinition typeCellType = typeCell.getTarget().values().iterator().next().getDefinition().getType(); // collect source entity definitions Collection<TypeEntityDefinition> sourceTypes = new ArrayList<TypeEntityDefinition>(); // null check in case only target type is in question if (typeCell.getSource() != null) { Iterator<? extends Entity> it = typeCell.getSource().values().iterator(); while (it.hasNext()) sourceTypes.add((TypeEntityDefinition) it.next().getDefinition()); } while (typeCellType != null) { // select all cells of the target type for (Cell cell : cellsPerTargetType.get(typeCellType)) { // check all cells associated to the target type if (!AlignmentUtil.isTypeCell(cell) && (includeDisabled || !cell.getDisabledFor().contains(typeCell.getId()))) { // cell is a property cell that isn't disabled // the target type matches, too if (AlignmentUtil.isAugmentation(cell) || (ignoreEmptySource && sourceTypes.isEmpty()) || matchesSources(cell.getSource(), sourceTypes)) { // cell matches on the source side, too result.add(cell); } } } // continue with super type for inheritance typeCellType = typeCellType.getSuperType(); } return result; }
/** @see LabelProvider#getText(Object) */ @Override public String getText(Object element) { if (element instanceof IStructuredSelection) { element = ((IStructuredSelection) element).getFirstElement(); } element = TransformationTreeUtil.extractObject(element); if (element instanceof Entity) { element = ((Entity) element).getDefinition(); } if ((element instanceof EntityDefinition && ((EntityDefinition) element).getDefinition() instanceof TypeDefinition) || element instanceof TypeDefinition) { if (element instanceof EntityDefinition) { element = ((EntityDefinition) element).getDefinition(); } // return the local name of the type instead of the display name // XXX as it may be masked by an XML element name return ((TypeDefinition) element).getName().getLocalPart(); } if (element instanceof EntityDefinition || element instanceof Definition<?>) { return definitionLabels.getText(element); } if (element instanceof Function) { return functionLabels.getText(element); } if (element instanceof Cell) { return CellUtil.getCellDescription((Cell) element); } return super.getText(element); }